1
1
/*
2
- * Copyright (c) 2015, Freescale Semiconductor, Inc.
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without modification,
6
- * are permitted provided that the following conditions are met:
7
- *
8
- * o Redistributions of source code must retain the above copyright notice, this list
9
- * of conditions and the following disclaimer.
10
- *
11
- * o Redistributions in binary form must reproduce the above copyright notice, this
12
- * list of conditions and the following disclaimer in the documentation and/or
13
- * other materials provided with the distribution.
14
- *
15
- * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16
- * contributors may be used to endorse or promote products derived from this
17
- * software without specific prior written permission.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */
2
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
3
+ * Copyright 2016-2017 NXP
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ *
8
+ * o Redistributions of source code must retain the above copyright notice, this list
9
+ * of conditions and the following disclaimer.
10
+ *
11
+ * o Redistributions in binary form must reproduce the above copyright notice, this
12
+ * list of conditions and the following disclaimer in the documentation and/or
13
+ * other materials provided with the distribution.
14
+ *
15
+ * o Neither the name of the copyright holder nor the names of its
16
+ * contributors may be used to endorse or promote products derived from this
17
+ * software without specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
30
31
31
#include "fsl_phy.h"
32
32
@@ -53,54 +53,77 @@ extern uint32_t ENET_GetInstance(ENET_Type *base);
53
53
* Variables
54
54
******************************************************************************/
55
55
56
+ #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
56
57
/*! @brief Pointers to enet clocks for each instance. */
57
58
extern clock_ip_name_t s_enetClock [FSL_FEATURE_SOC_ENET_COUNT ];
59
+ #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
58
60
59
61
/*******************************************************************************
60
62
* Code
61
63
******************************************************************************/
62
64
63
65
status_t PHY_Init (ENET_Type * base , uint32_t phyAddr , uint32_t srcClock_Hz )
64
66
{
65
- uint32_t bssReg ;
66
67
uint32_t counter = PHY_TIMEOUT_COUNT ;
68
+ uint32_t idReg = 0 ;
67
69
status_t result = kStatus_Success ;
68
70
uint32_t instance = ENET_GetInstance (base );
69
71
72
+ #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
70
73
/* Set SMI first. */
71
74
CLOCK_EnableClock (s_enetClock [instance ]);
75
+ #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
72
76
ENET_SetSMI (base , srcClock_Hz , false);
73
77
78
+ /* Initialization after PHY stars to work. */
79
+ while ((idReg != PHY_CONTROL_ID1 ) && (counter != 0 ))
80
+ {
81
+ PHY_Read (base , phyAddr , PHY_ID1_REG , & idReg );
82
+ counter -- ;
83
+ }
84
+
85
+ if (!counter )
86
+ {
87
+ return kStatus_Fail ;
88
+ }
89
+
74
90
/* Reset PHY. */
75
91
result = PHY_Write (base , phyAddr , PHY_BASICCONTROL_REG , PHY_BCTL_RESET_MASK );
92
+
93
+ return result ;
94
+ }
95
+
96
+ status_t PHY_AutoNegotiation (ENET_Type * base , uint32_t phyAddr )
97
+ {
98
+ status_t result = kStatus_Success ;
99
+ uint32_t bssReg ;
100
+ uint32_t counter = PHY_TIMEOUT_COUNT ;
101
+
102
+ /* Set the negotiation. */
103
+ result = PHY_Write (base , phyAddr , PHY_AUTONEG_ADVERTISE_REG ,
104
+ (PHY_100BASETX_FULLDUPLEX_MASK | PHY_100BASETX_HALFDUPLEX_MASK |
105
+ PHY_10BASETX_FULLDUPLEX_MASK | PHY_10BASETX_HALFDUPLEX_MASK | 0x1U ));
76
106
if (result == kStatus_Success )
77
107
{
78
- /* Set the negotiation. */
79
- result = PHY_Write (base , phyAddr , PHY_AUTONEG_ADVERTISE_REG ,
80
- (PHY_100BASETX_FULLDUPLEX_MASK | PHY_100BASETX_HALFDUPLEX_MASK |
81
- PHY_10BASETX_FULLDUPLEX_MASK | PHY_10BASETX_HALFDUPLEX_MASK | 0x1U ));
108
+ result = PHY_Write (base , phyAddr , PHY_BASICCONTROL_REG ,
109
+ (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK ));
82
110
if (result == kStatus_Success )
83
111
{
84
- result = PHY_Write (base , phyAddr , PHY_BASICCONTROL_REG ,
85
- (PHY_BCTL_AUTONEG_MASK | PHY_BCTL_RESTART_AUTONEG_MASK ));
86
- if (result == kStatus_Success )
112
+ /* Check auto negotiation complete. */
113
+ while (counter -- )
87
114
{
88
- /* Check auto negotiation complete. */
89
- while ( counter -- )
115
+ result = PHY_Read ( base , phyAddr , PHY_BASICSTATUS_REG , & bssReg );
116
+ if ( result == kStatus_Success )
90
117
{
91
- result = PHY_Read (base , phyAddr , PHY_BASICSTATUS_REG , & bssReg );
92
- if ( result == kStatus_Success )
118
+ if ((bssReg & PHY_BSTATUS_AUTONEGCOMP_MASK ) != 0 )
93
119
{
94
- if ((bssReg & PHY_BSTATUS_AUTONEGCOMP_MASK ) != 0 )
95
- {
96
- break ;
97
- }
120
+ break ;
98
121
}
122
+ }
99
123
100
- if (!counter )
101
- {
102
- return kStatus_PHY_AutoNegotiateFail ;
103
- }
124
+ if (!counter )
125
+ {
126
+ return kStatus_PHY_AutoNegotiateFail ;
104
127
}
105
128
}
106
129
}
0 commit comments