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