bc9b6f662538c53624cb174699a38d1796489435
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / include / asm-mips / mach-adm5120 / adm5120_switch.h
1 /*
2 * $Id$
3 *
4 * ADM5120 ethernet switch definitions
5 *
6 * This header file defines the hardware registers of the ADM5120 SoC
7 * built-in Ethernet switch.
8 *
9 * Copyright (C) 2007 OpenWrt.org
10 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
15 *
16 */
17
18 #ifndef _ADM5120_SWITCH_H_
19 #define _ADM5120_SWITCH_H_
20
21 #define BIT(at) (1 << (at))
22 #define BITMASK(len) ((1 << (len))-1)
23
24 #define SW_READ_REG(r) __raw_readl( \
25 (void __iomem *)KSEG1ADDR(ADM5120_SWITCH_BASE) + r)
26 #define SW_WRITE_REG(r, v) __raw_writel((v), \
27 (void __iomem *)KSEG1ADDR(ADM5120_SWITCH_BASE) + r)
28
29 /* Switch register offsets */
30 #define SWITCH_REG_CODE 0x0000
31 #define SWITCH_REG_SOFT_RESET 0x0004 /* Soft Reset */
32 #define SWITCH_REG_BOOT_DONE 0x0008 /* Boot Done */
33 #define SWITCH_REG_SW_RESET 0x000C /* Switch Reset */
34 #define SWITCH_REG_PHY_STATUS 0x0014 /* PHY Status */
35 #define SWITCH_REG_MEMCTRL 0x001C /* Memory Control */
36 #define SWITCH_REG_CPUP_CONF 0x0024 /* CPU Port Configuration */
37 #define SWITCH_REG_PORT_CONF0 0x0028 /* Port Configuration 0 */
38 #define SWITCH_REG_PORT_CONF1 0x002C /* Port Configuration 1 */
39 #define SWITCH_REG_PORT_CONF2 0x0030 /* Port Configuration 2 */
40 #define SWITCH_REG_VLAN_G1 0x0040 /* VLAN group 1 */
41 #define SWITCH_REG_VLAN_G2 0x0044 /* VLAN group 2 */
42 #define SWITCH_REG_SEND_TRIG 0x0048 /* Send Trigger */
43 #define SWITCH_REG_MAC_WT0 0x0058 /* MAC Write Address 0 */
44 #define SWITCH_REG_MAC_WT1 0x005C /* MAC Write Address 1 */
45 #define SWITCH_REG_BW_CNTL0 0x0060 /* Bandwidth Control 0 */
46 #define SWITCH_REG_BW_CNTL1 0x0064 /* Bandwidth Control 1 */
47 #define SWITCH_REG_PHY_CNTL0 0x0068 /* PHY Control 0 */
48 #define SWITCH_REG_PHY_CNTL1 0x006C /* PHY Control 1 */
49 #define SWITCH_REG_PORT_TH 0x0078 /* Port Threshold */
50 #define SWITCH_REG_PHY_CNTL2 0x007C /* PHY Control 2 */
51 #define SWITCH_REG_PHY_CNTL3 0x0080 /* PHY Control 3 */
52 #define SWITCH_REG_PRI_CNTL 0x0084 /* Priority Control */
53 #define SWITCH_REG_PHY_CNTL4 0x00A0 /* PHY Control 4 */
54 #define SWITCH_REG_EMPTY_CNT 0x00A4 /* Empty Count */
55 #define SWITCH_REG_PORT_CNTLS 0x00A8 /* Port Control Select */
56 #define SWITCH_REG_PORT_CNTL 0x00AC /* Port Control */
57 #define SWITCH_REG_INT_STATUS 0x00B0 /* Interrupt Status */
58 #define SWITCH_REG_INT_MASK 0x00B4 /* Interrupt Mask */
59 #define SWITCH_REG_GPIO_CONF0 0x00B8 /* GPIO Configuration 0 */
60 #define SWITCH_REG_GPIO_CONF2 0x00BC /* GPIO Configuration 1 */
61 #define SWITCH_REG_WDOG0 0x00C0 /* Watchdog 0 */
62 #define SWITCH_REG_WDOG1 0x00C4 /* Watchdog 1 */
63
64 #define SWITCH_REG_SHDA 0x00D0 /* Send High Descriptors Address */
65 #define SWITCH_REG_SLDA 0x00D4 /* Send Low Descriptors Address */
66 #define SWITCH_REG_RHDA 0x00D8 /* Receive High Descriptor Address */
67 #define SWITCH_REG_RLDA 0x00DC /* Receive Low Descriptor Address */
68 #define SWITCH_REG_SHWA 0x00E0 /* Send High Working Address */
69 #define SWITCH_REG_SLWA 0x00E4 /* Send Low Working Address */
70 #define SWITCH_REG_RHWA 0x00E8 /* Receive High Working Address */
71 #define SWITCH_REG_RLWA 0x00EC /* Receive Low Working Address */
72
73 #define SWITCH_REG_TIMER_INT 0x00F0 /* Timer */
74 #define SWITCH_REG_TIMER 0x00F4 /* Timer Interrupt */
75
76 #define SWITCH_REG_PORT0_LED 0x0100
77 #define SWITCH_REG_PORT1_LED 0x0104
78 #define SWITCH_REG_PORT2_LED 0x0108
79 #define SWITCH_REG_PORT3_LED 0x010C
80 #define SWITCH_REG_PORT4_LED 0x0110
81
82 /* CODE register bits */
83 #define CODE_PC_MASK BITMASK(16) /* Product Code */
84 #define CODE_REV_SHIFT 16
85 #define CODE_REV_MASK BITMASK(4) /* Product Revision */
86 #define CODE_CLKS_SHIFT 20
87 #define CODE_CLKS_MASK BITMASK(2) /* Clock Speed */
88 #define CODE_CLKS_175 0 /* 175 MHz */
89 #define CODE_CLKS_200 1 /* 200 MHz */
90 #define CODE_CLKS_225 2 /* 225 MHz */
91 #define CODE_CLKS_250 3 /* 250 MHz */
92 #define CODE_NAB BIT(24) /* NAND boot */
93 #define CODE_PK_MASK BITMASK(1) /* Package type */
94 #define CODE_PK_SHIFT 29
95 #define CODE_PK_BGA 0 /* BGA package */
96 #define CODE_PK_PQFP 1 /* PQFP package */
97
98 /* MEMCTRL register bits */
99 #define MEMCTRL_SDRS_MASK BITMASK(3) /* SDRAM bank size */
100 #define MEMCTRL_SDRS_4M 0x01
101 #define MEMCTRL_SDRS_8M 0x02
102 #define MEMCTRL_SDRS_16M 0x03
103 #define MEMCTRL_SDRS_64M 0x04
104 #define MEMCTRL_SDRS_128M 0x05
105 #define MEMCTRL_SDR1_ENABLE BIT(5) /* enable SDRAM bank 1 */
106
107 #define MEMCTRL_SRS0_SHIFT 8 /* shift for SRAM0 size */
108 #define MEMCTRL_SRS1_SHIFT 16 /* shift for SRAM1 size */
109 #define MEMCTRL_SRS_MASK BITMASK(3) /* SRAM size mask */
110 #define MEMCTRL_SRS_DISABLED 0x00 /* Disabled */
111 #define MEMCTRL_SRS_512K 0x01 /* 512KB*/
112 #define MEMCTRL_SRS_1M 0x02 /* 1MB */
113 #define MEMCTRL_SRS_2M 0x03 /* 2MB */
114 #define MEMCTRL_SRS_4M 0x04 /* 4MB */
115
116 /* Port bits used in various registers */
117 #define SWITCH_PORT_PHY0 BIT(0)
118 #define SWITCH_PORT_PHY1 BIT(1)
119 #define SWITCH_PORT_PHY2 BIT(2)
120 #define SWITCH_PORT_PHY3 BIT(3)
121 #define SWITCH_PORT_PHY4 BIT(4)
122 #define SWITCH_PORT_MII BIT(5)
123 #define SWITCH_PORT_CPU BIT(6)
124
125 /* Port bit shorthands */
126 #define SWITCH_PORTS_PHY 0x1F /* phy ports */
127 #define SWITCH_PORTS_NOCPU 0x3F /* physical ports */
128 #define SWITCH_PORTS_ALL 0x7F /* all ports */
129
130 /* CPUP_CONF register bits */
131 #define CPUP_CONF_DCPUP BIT(0) /* Disable CPU port */
132 #define CPUP_CONF_CRCP BIT(1) /* CRC padding from CPU */
133 #define CPUP_CONF_BTM BIT(2) /* Bridge Testing Mode */
134 #define CPUP_CONF_DUNP_SHIFT 9 /* Disable Unknown Packets for portX */
135 #define CPUP_CONF_DMCP_SHIFT 16 /* Disable Mcast Packets form portX */
136 #define CPUP_CONF_DBCP_SHIFT 24 /* Disable Bcast Packets form portX */
137
138 /* PORT_CONF0 register bits */
139 #define PORT_CONF0_DP_SHIFT 0 /* Disable Port */
140 #define PORT_CONF0_EMCP_SHIFT 8 /* Enable All MC Packets */
141 #define PORT_CONF0_BP_SHIFT 16 /* Enable Back Pressure */
142
143 /* PORT_CONF1 register bits */
144 #define PORT_CONF1_DISL_SHIFT 0 /* Disable Learning */
145 #define PORT_CONF1_BS_SHIFT 6 /* Blocking State */
146 #define PORT_CONF1_BM_SHIFT 12 /* Blocking Mode */
147
148 /* SEND_TRIG register bits */
149 #define SEND_TRIG_STL BIT(0) /* Send Trigger Low */
150 #define SEND_TRIG_STH BIT(1) /* Send Trigger High */
151
152 /* MAC_WT0 register bits */
153 #define MAC_WT0_MAWC BIT(0) /* MAC address write command */
154 #define MAC_WT0_MWD_SHIFT 1
155 #define MAC_WT0_MWD BIT(1) /* MAC write done */
156 #define MAC_WT0_WFB BIT(2) /* Write Filter Bit */
157 #define MAC_WT0_WVN_SHIFT 3 /* Write Vlan Number shift */
158 #define MAC_WT0_WVE BIT(6) /* Write VLAN enable */
159 #define MAC_WT0_WPMN_SHIFT 7
160 #define MAC_WT0_WAF_SHIFT 13 /* Write Age Field shift */
161 #define MAC_WT0_WAF_EMPTY 0
162 #define MAC_WT0_WAF_STATIC 7 /* age: static */
163 #define MAC_WT0_MAC0_SHIFT 16
164 #define MAC_WT0_MAC1_SHIFT 24
165
166 /* MAC_WT1 register bits */
167 #define MAC_WT1_MAC2_SHIFT 0
168 #define MAC_WT1_MAC3_SHIFT 8
169 #define MAC_WT1_MAC4_SHIFT 16
170 #define MAC_WT1_MAC5_SHIFT 24
171
172 /* BW_CNTL0/BW_CNTL1 register bits */
173 #define BW_CNTL_DISABLE 0x00
174 #define BW_CNTL_64K 0x01
175 #define BW_CNTL_128K 0x02
176 #define BW_CNTL_256K 0x03
177 #define BW_CNTL_512K 0x04
178 #define BW_CNTL_1M 0x05
179 #define BW_CNTL_4M 0x06
180 #define BW_CNTL_10M 0x07
181
182 #define P4TBC_SHIFT 0
183 #define P4RBC_SHIFT 4
184 #define P5TBC_SHIFT 8
185 #define P5RBC_SHIFT 12
186
187 #define BW_CNTL1_NAND_ENABLE 0x100
188
189 /* PHY_CNTL0 register bits */
190 #define PHY_CNTL0_PHYA_MASK BITMASK(5)
191 #define PHY_CNTL0_PHYR_MASK BITMASK(5)
192 #define PHY_CNTL0_PHYR_SHIFT 8
193 #define PHY_CNTL0_WC BIT(13) /* Write Command */
194 #define PHY_CNTL0_RC BIT(14) /* Read Command */
195 #define PHY_CNTL0_WTD_MASK BIT(16) /* Read Command */
196 #define PHY_CNTL0_WTD_SHIFT 16
197
198 /* PHY_CNTL1 register bits */
199 #define PHY_CNTL1_WOD BIT(0) /* Write Operation Done */
200 #define PHY_CNTL1_ROD BIT(1) /* Read Operation Done */
201 #define PHY_CNTL1_RD_MASK BITMASK(16)
202 #define PHY_CNTL1_RD_SHIFT 16
203
204 /* PHY_CNTL2 register bits */
205 #define PHY_CNTL2_ANE_SHIFT 0 /* Auto Negotiation Enable */
206 #define PHY_CNTL2_SC_SHIFT 5 /* Speed Control */
207 #define PHY_CNTL2_DC_SHIFT 10 /* Duplex Control */
208 #define PHY_CNTL2_FNCV_SHIFT 15 /* Recommended FC Value */
209 #define PHY_CNTL2_PHYR_SHIFT 20 /* PHY reset */
210 #define PHY_CNTL2_AMDIX_SHIFT 25 /* Auto MDIX enable */
211 /* PHY_CNTL2_RMAE is bad in datasheet */
212 #define PHY_CNTL2_RMAE BIT(31) /* Recommended MCC Average enable */
213
214 /* PHY_CNTL3 register bits */
215 #define PHY_CNTL3_RNT BIT(10) /* Recommend Normal Threshold */
216
217 /* PORT_TH register bits */
218 #define PORT_TH_PPT_MASK BITMASK(8) /* Per Port Threshold */
219 #define PORT_TH_CPUT_SHIFT 8 /* CPU Port Buffer Threshold */
220 #define PORT_TH_CPUT_MASK BITMASK(8)
221 #define PORT_TH_CPUHT_SHIFT 16 /* CPU Hold Threshold */
222 #define PORT_TH_CPUHT_MASK BITMASK(8)
223 #define PORT_TH_CPURT_SHIFT 24 /* CPU Release Threshold */
224 #define PORT_TH_CPURT_MASK BITMASK(8)
225
226 /* EMPTY_CNT register bits */
227 #define EMPTY_CNT_EBGB_MASK BITMASK(9) /* Empty Blocks in the Global Buffer */
228
229 /* GPIO_CONF0 register bits */
230 #define GPIO_CONF0_MASK BITMASK(8)
231 #define GPIO_CONF0_IM_SHIFT 0
232 #define GPIO_CONF0_IV_SHIFT 8
233 #define GPIO_CONF0_OE_SHIFT 16
234 #define GPIO_CONF0_OV_SHIFT 24
235 #define GPIO_CONF0_IM_MASK (0xFF << GPIO_CONF0_IM_SHIFT)
236 #define GPIO_CONF0_IV_MASK (0xFF << GPIO_CONF0_IV_SHIFT)
237 #define GPIO_CONF0_OE_MASK (0xFF << GPIO_CONF0_OE_SHIFT)
238 #define GPIO_CONF0_OV_MASK (0xFF << GPIO_CONF0_OV_SHIFT)
239
240 /* GPIO_CONF2 register bits */
241 #define GPIO_CONF2_CSX0 BIT(4) /* enable CSX0:INTX0 on GPIO 1:2 */
242 #define GPIO_CONF2_CSX1 BIT(5) /* enable CSX1:INTX1 on GPIO 3:4 */
243 #define GPIO_CONF2_EW BIT(6) /* enable wait state pin for CSX0/1 */
244
245 /* INT_STATUS/INT_MASK register bits */
246 #define SWITCH_INT_SHD BIT(0) /* Send High Done */
247 #define SWITCH_INT_SLD BIT(1) /* Send Low Done */
248 #define SWITCH_INT_RHD BIT(2) /* Receive High Done */
249 #define SWITCH_INT_RLD BIT(3) /* Receive Low Done */
250 #define SWITCH_INT_HDF BIT(4) /* High Descriptor Full */
251 #define SWITCH_INT_LDF BIT(5) /* Low Descriptor Full */
252 #define SWITCH_INT_P0QF BIT(6) /* Port0 Queue Full */
253 #define SWITCH_INT_P1QF BIT(7) /* Port1 Queue Full */
254 #define SWITCH_INT_P2QF BIT(8) /* Port2 Queue Full */
255 #define SWITCH_INT_P3QF BIT(9) /* Port3 Queue Full */
256 #define SWITCH_INT_P4QF BIT(10) /* Port4 Queue Full */
257 #define SWITCH_INT_P5QF BIT(11) /* Port5 Queue Full */
258 #define SWITCH_INT_CPQF BIT(13) /* CPU Queue Full */
259 #define SWITCH_INT_GQF BIT(14) /* Global Queue Full */
260 #define SWITCH_INT_MD BIT(15) /* Must Drop */
261 #define SWITCH_INT_BCS BIT(16) /* BC Storm */
262 #define SWITCH_INT_PSC BIT(18) /* Port Status Change */
263 #define SWITCH_INT_ID BIT(19) /* Intruder Detected */
264 #define SWITCH_INT_W0TE BIT(20) /* Watchdog 0 Timer Expired */
265 #define SWITCH_INT_W1TE BIT(21) /* Watchdog 1 Timer Expired */
266 #define SWITCH_INT_RDE BIT(22) /* Receive Descriptor Error */
267 #define SWITCH_INT_SDE BIT(23) /* Send Descriptor Error */
268 #define SWITCH_INT_CPUH BIT(24) /* CPU Hold */
269
270 /* TIMER_INT register bits */
271 #define TIMER_INT_TOS BIT(0) /* time-out status */
272 #define TIMER_INT_TOM BIT(16) /* mask time-out interrupt */
273
274 /* TIMER register bits */
275 #define TIMER_PERIOD_MASK BITMASK(16) /* mask for timer period */
276 #define TIMER_PERIOD_DEFAULT 0xFFFF /* default timer period */
277 #define TIMER_TE BIT(16) /* timer enable bit */
278
279 /* PORTx_LED register bits */
280 #define LED_MODE_MASK BITMASK(4)
281 #define LED_MODE_INPUT 0
282 #define LED_MODE_FLASH 1
283 #define LED_MODE_OUT_HIGH 2
284 #define LED_MODE_OUT_LOW 3
285 #define LED_MODE_LINK 4
286 #define LED_MODE_SPEED 5
287 #define LED_MODE_DUPLEX 6
288 #define LED_MODE_ACT 7
289 #define LED_MODE_COLL 8
290 #define LED_MODE_LINK_ACT 9
291 #define LED_MODE_DUPLEX_COLL 10
292 #define LED_MODE_10M_ACT 11
293 #define LED_MODE_100M_ACT 12
294 #define LED0_MODE_SHIFT 0 /* LED0 mode shift */
295 #define LED1_MODE_SHIFT 4 /* LED1 mode shift */
296 #define LED2_MODE_SHIFT 8 /* LED2 mode shift */
297 #define LED0_IV_SHIFT 12 /* LED0 input value shift */
298 #define LED1_IV_SHIFT 13 /* LED1 input value shift */
299 #define LED2_IV_SHIFT 14 /* LED2 input value shift */
300
301 #endif /* _ADM5120_SWITCH_H_ */