cd14c2ce1325ed42d87a9d37c7162633700cefb6
[openwrt/openwrt.git] / target / linux / mediatek / files-5.10 / drivers / net / phy / rtk / rtl8367c / eee.c
1 /*
2 * Copyright (C) 2013 Realtek Semiconductor Corp.
3 * All Rights Reserved.
4 *
5 * Unless you and Realtek execute a separate written software license
6 * agreement governing use of this software, this software is licensed
7 * to you under the terms of the GNU General Public License version 2,
8 * available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 *
10 * $Revision: 48156 $
11 * $Date: 2014-05-29 16:39:06 +0800 (ι€±ε››, 29 δΊ”ζœˆ 2014) $
12 *
13 * Purpose : RTK switch high-level API for RTL8367/RTL8367C
14 * Feature : Here is a list of all functions and variables in EEE module.
15 *
16 */
17
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
20 #include <eee.h>
21 #include <string.h>
22
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_eee.h>
25 #include <rtl8367c_asicdrv_phy.h>
26
27 /* Function Name:
28 * rtk_eee_init
29 * Description:
30 * EEE function initialization.
31 * Input:
32 * None
33 * Output:
34 * None
35 * Return:
36 * RT_ERR_OK - OK
37 * RT_ERR_FAILED - Failed
38 * RT_ERR_SMI - SMI access error
39 * Note:
40 * This API is used to initialize EEE status.
41 */
42 rtk_api_ret_t rtk_eee_init(void)
43 {
44 rtk_api_ret_t retVal;
45
46 /* Check initialization state */
47 RTK_CHK_INIT_STATE();
48
49 if((retVal = rtl8367c_setAsicRegBit(0x0018, 10, 1)) != RT_ERR_OK)
50 return retVal;
51
52 if((retVal = rtl8367c_setAsicRegBit(0x0018, 11, 1)) != RT_ERR_OK)
53 return retVal;
54
55 return RT_ERR_OK;
56 }
57
58 /* Function Name:
59 * rtk_eee_portEnable_set
60 * Description:
61 * Set enable status of EEE function.
62 * Input:
63 * port - port id.
64 * enable - enable EEE status.
65 * Output:
66 * None
67 * Return:
68 * RT_ERR_OK - OK
69 * RT_ERR_FAILED - Failed
70 * RT_ERR_SMI - SMI access error
71 * RT_ERR_PORT_ID - Invalid port number.
72 * RT_ERR_ENABLE - Invalid enable input.
73 * Note:
74 * This API can set EEE function to the specific port.
75 * The configuration of the port is as following:
76 * - DISABLE
77 * - ENABLE
78 */
79 rtk_api_ret_t rtk_eee_portEnable_set(rtk_port_t port, rtk_enable_t enable)
80 {
81 rtk_api_ret_t retVal;
82 rtk_uint32 regData;
83 rtk_uint32 phy_port;
84
85 /* Check initialization state */
86 RTK_CHK_INIT_STATE();
87
88 /* Check port is UTP port */
89 RTK_CHK_PORT_IS_UTP(port);
90
91 if (enable>=RTK_ENABLE_END)
92 return RT_ERR_INPUT;
93
94 phy_port = rtk_switch_port_L2P_get(port);
95
96 if ((retVal = rtl8367c_setAsicEee100M(phy_port,enable))!=RT_ERR_OK)
97 return retVal;
98 if ((retVal = rtl8367c_setAsicEeeGiga(phy_port,enable))!=RT_ERR_OK)
99 return retVal;
100
101 if ((retVal = rtl8367c_setAsicPHYReg(phy_port, RTL8367C_PHY_PAGE_ADDRESS, 0))!=RT_ERR_OK)
102 return retVal;
103 if ((retVal = rtl8367c_getAsicPHYReg(phy_port, 0, &regData))!=RT_ERR_OK)
104 return retVal;
105 regData |= 0x0200;
106 if ((retVal = rtl8367c_setAsicPHYReg(phy_port, 0, regData))!=RT_ERR_OK)
107 return retVal;
108
109 return RT_ERR_OK;
110 }
111
112 /* Function Name:
113 * rtk_eee_portEnable_get
114 * Description:
115 * Get enable status of EEE function
116 * Input:
117 * port - Port id.
118 * Output:
119 * pEnable - Back pressure status.
120 * Return:
121 * RT_ERR_OK - OK
122 * RT_ERR_FAILED - Failed
123 * RT_ERR_SMI - SMI access error
124 * RT_ERR_PORT_ID - Invalid port number.
125 * Note:
126 * This API can get EEE function to the specific port.
127 * The configuration of the port is as following:
128 * - DISABLE
129 * - ENABLE
130 */
131
132 rtk_api_ret_t rtk_eee_portEnable_get(rtk_port_t port, rtk_enable_t *pEnable)
133 {
134 rtk_api_ret_t retVal;
135 rtk_uint32 regData1, regData2;
136 rtk_uint32 phy_port;
137
138 /* Check initialization state */
139 RTK_CHK_INIT_STATE();
140
141 /* Check port is UTP port */
142 RTK_CHK_PORT_IS_UTP(port);
143
144 if(NULL == pEnable)
145 return RT_ERR_NULL_POINTER;
146
147 phy_port = rtk_switch_port_L2P_get(port);
148
149 if ((retVal = rtl8367c_getAsicEee100M(phy_port,&regData1))!=RT_ERR_OK)
150 return retVal;
151 if ((retVal = rtl8367c_getAsicEeeGiga(phy_port,&regData2))!=RT_ERR_OK)
152 return retVal;
153
154 if (regData1==1&&regData2==1)
155 *pEnable = ENABLED;
156 else
157 *pEnable = DISABLED;
158
159 return RT_ERR_OK;
160 }
161
162