mediatek: add patches for 5.15 and kernel config for mt7622
[openwrt/openwrt.git] / target / linux / mediatek / files / drivers / net / phy / rtk / rtl8367c / rtl8367c_asicdrv_interrupt.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: 76306 $
11 * $Date: 2017-03-08 15:13:58 +0800 (週三, 08 三月 2017) $
12 *
13 * Purpose : RTL8367C switch high-level API for RTL8367C
14 * Feature : Interrupt related functions
15 *
16 */
17 #include <rtl8367c_asicdrv_interrupt.h>
18 /* Function Name:
19 * rtl8367c_setAsicInterruptPolarity
20 * Description:
21 * Set interrupt trigger polarity
22 * Input:
23 * polarity - 0:pull high 1: pull low
24 * Output:
25 * None
26 * Return:
27 * RT_ERR_OK - Success
28 * RT_ERR_SMI - SMI access error
29 * Note:
30 * None
31 */
32 ret_t rtl8367c_setAsicInterruptPolarity(rtk_uint32 polarity)
33 {
34 return rtl8367c_setAsicRegBit(RTL8367C_REG_INTR_CTRL, RTL8367C_INTR_CTRL_OFFSET, polarity);
35 }
36 /* Function Name:
37 * rtl8367c_getAsicInterruptPolarity
38 * Description:
39 * Get interrupt trigger polarity
40 * Input:
41 * pPolarity - 0:pull high 1: pull low
42 * Output:
43 * None
44 * Return:
45 * RT_ERR_OK - Success
46 * RT_ERR_SMI - SMI access error
47 * Note:
48 * None
49 */
50 ret_t rtl8367c_getAsicInterruptPolarity(rtk_uint32* pPolarity)
51 {
52 return rtl8367c_getAsicRegBit(RTL8367C_REG_INTR_CTRL, RTL8367C_INTR_CTRL_OFFSET, pPolarity);
53 }
54 /* Function Name:
55 * rtl8367c_setAsicInterruptMask
56 * Description:
57 * Set interrupt enable mask
58 * Input:
59 * imr - Interrupt mask
60 * Output:
61 * None
62 * Return:
63 * RT_ERR_OK - Success
64 * RT_ERR_SMI - SMI access error
65 * Note:
66 * None
67 */
68 ret_t rtl8367c_setAsicInterruptMask(rtk_uint32 imr)
69 {
70 return rtl8367c_setAsicReg(RTL8367C_REG_INTR_IMR, imr);
71 }
72 /* Function Name:
73 * rtl8367c_getAsicInterruptMask
74 * Description:
75 * Get interrupt enable mask
76 * Input:
77 * pImr - Interrupt mask
78 * Output:
79 * None
80 * Return:
81 * RT_ERR_OK - Success
82 * RT_ERR_SMI - SMI access error
83 * Note:
84 * None
85 */
86 ret_t rtl8367c_getAsicInterruptMask(rtk_uint32* pImr)
87 {
88 return rtl8367c_getAsicReg(RTL8367C_REG_INTR_IMR, pImr);
89 }
90 /* Function Name:
91 * rtl8367c_setAsicInterruptMask
92 * Description:
93 * Clear interrupt enable mask
94 * Input:
95 * ims - Interrupt status mask
96 * Output:
97 * None
98 * Return:
99 * RT_ERR_OK - Success
100 * RT_ERR_SMI - SMI access error
101 * Note:
102 * This API can be used to clear ASIC interrupt status and register will be cleared by writting 1.
103 * [0]:Link change,
104 * [1]:Share meter exceed,
105 * [2]:Learn number overed,
106 * [3]:Speed Change,
107 * [4]:Tx special congestion
108 * [5]:1 second green feature
109 * [6]:loop detection
110 * [7]:interrupt from 8051
111 * [8]:Cable diagnostic finish
112 * [9]:ACL action interrupt trigger
113 * [11]: Silent Start
114 */
115 ret_t rtl8367c_setAsicInterruptStatus(rtk_uint32 ims)
116 {
117 return rtl8367c_setAsicReg(RTL8367C_REG_INTR_IMS, ims);
118 }
119 /* Function Name:
120 * rtl8367c_getAsicInterruptStatus
121 * Description:
122 * Get interrupt enable mask
123 * Input:
124 * pIms - Interrupt status mask
125 * Output:
126 * None
127 * Return:
128 * RT_ERR_OK - Success
129 * RT_ERR_SMI - SMI access error
130 * Note:
131 * None
132 */
133 ret_t rtl8367c_getAsicInterruptStatus(rtk_uint32* pIms)
134 {
135 return rtl8367c_getAsicReg(RTL8367C_REG_INTR_IMS, pIms);
136 }
137 /* Function Name:
138 * rtl8367c_setAsicInterruptRelatedStatus
139 * Description:
140 * Clear interrupt status
141 * Input:
142 * type - per port Learn over, per-port speed change, per-port special congest, share meter exceed status
143 * status - exceed status, write 1 to clear
144 * Output:
145 * None
146 * Return:
147 * RT_ERR_OK - Success
148 * RT_ERR_SMI - SMI access error
149 * RT_ERR_OUT_OF_RANGE - input parameter out of range
150 * Note:
151 * None
152 */
153 ret_t rtl8367c_setAsicInterruptRelatedStatus(rtk_uint32 type, rtk_uint32 status)
154 {
155 CONST rtk_uint32 indicatorAddress[INTRST_END] = {RTL8367C_REG_LEARN_OVER_INDICATOR,
156 RTL8367C_REG_SPEED_CHANGE_INDICATOR,
157 RTL8367C_REG_SPECIAL_CONGEST_INDICATOR,
158 RTL8367C_REG_PORT_LINKDOWN_INDICATOR,
159 RTL8367C_REG_PORT_LINKUP_INDICATOR,
160 RTL8367C_REG_METER_OVERRATE_INDICATOR0,
161 RTL8367C_REG_METER_OVERRATE_INDICATOR1,
162 RTL8367C_REG_RLDP_LOOPED_INDICATOR,
163 RTL8367C_REG_RLDP_RELEASED_INDICATOR,
164 RTL8367C_REG_SYSTEM_LEARN_OVER_INDICATOR};
165
166 if(type >= INTRST_END )
167 return RT_ERR_OUT_OF_RANGE;
168
169 return rtl8367c_setAsicReg(indicatorAddress[type], status);
170 }
171 /* Function Name:
172 * rtl8367c_getAsicInterruptRelatedStatus
173 * Description:
174 * Get interrupt status
175 * Input:
176 * type - per port Learn over, per-port speed change, per-port special congest, share meter exceed status
177 * pStatus - exceed status, write 1 to clear
178 * Output:
179 * None
180 * Return:
181 * RT_ERR_OK - Success
182 * RT_ERR_SMI - SMI access error
183 * RT_ERR_OUT_OF_RANGE - input parameter out of range
184 * Note:
185 * None
186 */
187 ret_t rtl8367c_getAsicInterruptRelatedStatus(rtk_uint32 type, rtk_uint32* pStatus)
188 {
189 CONST rtk_uint32 indicatorAddress[INTRST_END] = {RTL8367C_REG_LEARN_OVER_INDICATOR,
190 RTL8367C_REG_SPEED_CHANGE_INDICATOR,
191 RTL8367C_REG_SPECIAL_CONGEST_INDICATOR,
192 RTL8367C_REG_PORT_LINKDOWN_INDICATOR,
193 RTL8367C_REG_PORT_LINKUP_INDICATOR,
194 RTL8367C_REG_METER_OVERRATE_INDICATOR0,
195 RTL8367C_REG_METER_OVERRATE_INDICATOR1,
196 RTL8367C_REG_RLDP_LOOPED_INDICATOR,
197 RTL8367C_REG_RLDP_RELEASED_INDICATOR,
198 RTL8367C_REG_SYSTEM_LEARN_OVER_INDICATOR};
199
200 if(type >= INTRST_END )
201 return RT_ERR_OUT_OF_RANGE;
202
203 return rtl8367c_getAsicReg(indicatorAddress[type], pStatus);
204 }
205