Commit | Line | Data |
---|---|---|
555a3656 | 1 | /* |
9dd0b194 | 2 | * arch/arm/mach-orion5x/dns323-setup.c |
555a3656 HVR |
3 | * |
4 | * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org> | |
5 | * | |
6e2daa49 BH |
6 | * Support for HW Rev C1: |
7 | * | |
8 | * Copyright (C) 2010 Benjamin Herrenschmidt <benh@kernel.crashing.org> | |
9 | * | |
555a3656 HVR |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU Lesser General Public License as | |
12 | * published by the Free Software Foundation; either version 2 of the | |
13 | * License, or (at your option) any later version. | |
14 | * | |
15 | */ | |
2f8163ba | 16 | #include <linux/gpio.h> |
555a3656 HVR |
17 | #include <linux/kernel.h> |
18 | #include <linux/init.h> | |
cf11052a | 19 | #include <linux/delay.h> |
555a3656 HVR |
20 | #include <linux/platform_device.h> |
21 | #include <linux/pci.h> | |
22 | #include <linux/irq.h> | |
23 | #include <linux/mtd/physmap.h> | |
24 | #include <linux/mv643xx_eth.h> | |
25 | #include <linux/leds.h> | |
26 | #include <linux/gpio_keys.h> | |
27 | #include <linux/input.h> | |
28 | #include <linux/i2c.h> | |
f93e4159 | 29 | #include <linux/ata_platform.h> |
6e2daa49 BH |
30 | #include <linux/phy.h> |
31 | #include <linux/marvell_phy.h> | |
555a3656 | 32 | #include <asm/mach-types.h> |
555a3656 HVR |
33 | #include <asm/mach/arch.h> |
34 | #include <asm/mach/pci.h> | |
9f97da78 | 35 | #include <asm/system_info.h> |
a09e64fb | 36 | #include <mach/orion5x.h> |
555a3656 | 37 | #include "common.h" |
19cfd5c0 | 38 | #include "mpp.h" |
555a3656 | 39 | |
6e2daa49 | 40 | /* Rev A1 and B1 */ |
555a3656 HVR |
41 | #define DNS323_GPIO_LED_RIGHT_AMBER 1 |
42 | #define DNS323_GPIO_LED_LEFT_AMBER 2 | |
cf11052a | 43 | #define DNS323_GPIO_SYSTEM_UP 3 |
b2a731aa LB |
44 | #define DNS323_GPIO_LED_POWER1 4 |
45 | #define DNS323_GPIO_LED_POWER2 5 | |
555a3656 HVR |
46 | #define DNS323_GPIO_OVERTEMP 6 |
47 | #define DNS323_GPIO_RTC 7 | |
48 | #define DNS323_GPIO_POWER_OFF 8 | |
49 | #define DNS323_GPIO_KEY_POWER 9 | |
50 | #define DNS323_GPIO_KEY_RESET 10 | |
51 | ||
6e2daa49 BH |
52 | /* Rev C1 */ |
53 | #define DNS323C_GPIO_KEY_POWER 1 | |
54 | #define DNS323C_GPIO_POWER_OFF 2 | |
55 | #define DNS323C_GPIO_LED_RIGHT_AMBER 8 | |
56 | #define DNS323C_GPIO_LED_LEFT_AMBER 9 | |
57 | #define DNS323C_GPIO_LED_POWER 17 | |
58 | #define DNS323C_GPIO_FAN_BIT1 18 | |
59 | #define DNS323C_GPIO_FAN_BIT0 19 | |
60 | ||
61 | /* Exposed to userspace, do not change */ | |
62 | enum { | |
63 | DNS323_REV_A1, /* 0 */ | |
64 | DNS323_REV_B1, /* 1 */ | |
65 | DNS323_REV_C1, /* 2 */ | |
66 | }; | |
67 | ||
68 | ||
555a3656 HVR |
69 | /**************************************************************************** |
70 | * PCI setup | |
71 | */ | |
72 | ||
d5341942 | 73 | static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
555a3656 | 74 | { |
92b913b0 | 75 | int irq; |
555a3656 | 76 | |
92b913b0 LB |
77 | /* |
78 | * Check for devices with hard-wired IRQs. | |
79 | */ | |
5166793f | 80 | irq = orion5x_pci_map_irq(dev, slot, pin); |
92b913b0 LB |
81 | if (irq != -1) |
82 | return irq; | |
83 | ||
555a3656 HVR |
84 | return -1; |
85 | } | |
86 | ||
87 | static struct hw_pci dns323_pci __initdata = { | |
bbdf1c1e | 88 | .nr_controllers = 2, |
9dd0b194 LB |
89 | .setup = orion5x_pci_sys_setup, |
90 | .scan = orion5x_pci_sys_scan_bus, | |
555a3656 HVR |
91 | .map_irq = dns323_pci_map_irq, |
92 | }; | |
93 | ||
94 | static int __init dns323_pci_init(void) | |
95 | { | |
6e2daa49 | 96 | /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI |
f93e4159 MP |
97 | * gets in the way of initialising the SATA controller. |
98 | */ | |
6e2daa49 | 99 | if (machine_is_dns323() && system_rev == DNS323_REV_A1) |
555a3656 HVR |
100 | pci_common_init(&dns323_pci); |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | subsys_initcall(dns323_pci_init); | |
106 | ||
555a3656 HVR |
107 | /**************************************************************************** |
108 | * 8MiB NOR flash (Spansion S29GL064M90TFIR4) | |
109 | * | |
110 | * Layout as used by D-Link: | |
111 | * 0x00000000-0x00010000 : "MTD1" | |
112 | * 0x00010000-0x00020000 : "MTD2" | |
113 | * 0x00020000-0x001a0000 : "Linux Kernel" | |
114 | * 0x001a0000-0x007d0000 : "File System" | |
115 | * 0x007d0000-0x00800000 : "u-boot" | |
116 | */ | |
117 | ||
118 | #define DNS323_NOR_BOOT_BASE 0xf4000000 | |
119 | #define DNS323_NOR_BOOT_SIZE SZ_8M | |
120 | ||
121 | static struct mtd_partition dns323_partitions[] = { | |
122 | { | |
123 | .name = "MTD1", | |
124 | .size = 0x00010000, | |
125 | .offset = 0, | |
126 | }, { | |
127 | .name = "MTD2", | |
128 | .size = 0x00010000, | |
129 | .offset = 0x00010000, | |
130 | }, { | |
131 | .name = "Linux Kernel", | |
132 | .size = 0x00180000, | |
133 | .offset = 0x00020000, | |
134 | }, { | |
135 | .name = "File System", | |
136 | .size = 0x00630000, | |
137 | .offset = 0x001A0000, | |
138 | }, { | |
139 | .name = "u-boot", | |
140 | .size = 0x00030000, | |
141 | .offset = 0x007d0000, | |
e7068ad3 | 142 | }, |
555a3656 HVR |
143 | }; |
144 | ||
145 | static struct physmap_flash_data dns323_nor_flash_data = { | |
146 | .width = 1, | |
147 | .parts = dns323_partitions, | |
148 | .nr_parts = ARRAY_SIZE(dns323_partitions) | |
149 | }; | |
150 | ||
151 | static struct resource dns323_nor_flash_resource = { | |
152 | .flags = IORESOURCE_MEM, | |
153 | .start = DNS323_NOR_BOOT_BASE, | |
154 | .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1, | |
155 | }; | |
156 | ||
157 | static struct platform_device dns323_nor_flash = { | |
158 | .name = "physmap-flash", | |
159 | .id = 0, | |
e7068ad3 LB |
160 | .dev = { |
161 | .platform_data = &dns323_nor_flash_data, | |
162 | }, | |
555a3656 HVR |
163 | .resource = &dns323_nor_flash_resource, |
164 | .num_resources = 1, | |
165 | }; | |
166 | ||
a93f44c1 MP |
167 | /**************************************************************************** |
168 | * Ethernet | |
169 | */ | |
170 | ||
171 | static struct mv643xx_eth_platform_data dns323_eth_data = { | |
172 | .phy_addr = MV643XX_ETH_PHY_ADDR(8), | |
173 | }; | |
174 | ||
175 | /* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these | |
176 | * functions be kept somewhere? | |
177 | */ | |
178 | static int __init dns323_parse_hex_nibble(char n) | |
179 | { | |
180 | if (n >= '0' && n <= '9') | |
181 | return n - '0'; | |
182 | ||
183 | if (n >= 'A' && n <= 'F') | |
184 | return n - 'A' + 10; | |
185 | ||
186 | if (n >= 'a' && n <= 'f') | |
187 | return n - 'a' + 10; | |
188 | ||
189 | return -1; | |
190 | } | |
191 | ||
192 | static int __init dns323_parse_hex_byte(const char *b) | |
193 | { | |
194 | int hi; | |
195 | int lo; | |
196 | ||
197 | hi = dns323_parse_hex_nibble(b[0]); | |
198 | lo = dns323_parse_hex_nibble(b[1]); | |
199 | ||
200 | if (hi < 0 || lo < 0) | |
201 | return -1; | |
202 | ||
203 | return (hi << 4) | lo; | |
204 | } | |
205 | ||
206 | static int __init dns323_read_mac_addr(void) | |
207 | { | |
208 | u_int8_t addr[6]; | |
209 | int i; | |
210 | char *mac_page; | |
211 | ||
212 | /* MAC address is stored as a regular ol' string in /dev/mtdblock4 | |
213 | * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80). | |
214 | */ | |
215 | mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024); | |
216 | if (!mac_page) | |
217 | return -ENOMEM; | |
218 | ||
219 | /* Sanity check the string we're looking at */ | |
220 | for (i = 0; i < 5; i++) { | |
221 | if (*(mac_page + (i * 3) + 2) != ':') { | |
222 | goto error_fail; | |
223 | } | |
224 | } | |
225 | ||
226 | for (i = 0; i < 6; i++) { | |
227 | int byte; | |
228 | ||
229 | byte = dns323_parse_hex_byte(mac_page + (i * 3)); | |
230 | if (byte < 0) { | |
231 | goto error_fail; | |
232 | } | |
233 | ||
234 | addr[i] = byte; | |
235 | } | |
236 | ||
237 | iounmap(mac_page); | |
6e2daa49 | 238 | printk("DNS-323: Found ethernet MAC address: "); |
a93f44c1 MP |
239 | for (i = 0; i < 6; i++) |
240 | printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n"); | |
241 | ||
242 | memcpy(dns323_eth_data.mac_addr, addr, 6); | |
243 | ||
244 | return 0; | |
245 | ||
246 | error_fail: | |
247 | iounmap(mac_page); | |
248 | return -EINVAL; | |
249 | } | |
250 | ||
555a3656 HVR |
251 | /**************************************************************************** |
252 | * GPIO LEDs (simple - doesn't use hardware blinking support) | |
253 | */ | |
254 | ||
6e2daa49 | 255 | static struct gpio_led dns323ab_leds[] = { |
555a3656 HVR |
256 | { |
257 | .name = "power:blue", | |
b2a731aa | 258 | .gpio = DNS323_GPIO_LED_POWER2, |
f8e00530 | 259 | .default_trigger = "default-on", |
555a3656 HVR |
260 | }, { |
261 | .name = "right:amber", | |
262 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, | |
263 | .active_low = 1, | |
264 | }, { | |
265 | .name = "left:amber", | |
266 | .gpio = DNS323_GPIO_LED_LEFT_AMBER, | |
267 | .active_low = 1, | |
268 | }, | |
269 | }; | |
270 | ||
6e2daa49 BH |
271 | |
272 | static struct gpio_led dns323c_leds[] = { | |
273 | { | |
274 | .name = "power:blue", | |
275 | .gpio = DNS323C_GPIO_LED_POWER, | |
276 | .default_trigger = "timer", | |
277 | .active_low = 1, | |
278 | }, { | |
279 | .name = "right:amber", | |
280 | .gpio = DNS323C_GPIO_LED_RIGHT_AMBER, | |
281 | .active_low = 1, | |
282 | }, { | |
283 | .name = "left:amber", | |
284 | .gpio = DNS323C_GPIO_LED_LEFT_AMBER, | |
285 | .active_low = 1, | |
286 | }, | |
287 | }; | |
288 | ||
289 | ||
290 | static struct gpio_led_platform_data dns323ab_led_data = { | |
291 | .num_leds = ARRAY_SIZE(dns323ab_leds), | |
292 | .leds = dns323ab_leds, | |
ff3e660b | 293 | .gpio_blink_set = orion_gpio_led_blink_set, |
6e2daa49 BH |
294 | }; |
295 | ||
296 | static struct gpio_led_platform_data dns323c_led_data = { | |
297 | .num_leds = ARRAY_SIZE(dns323c_leds), | |
298 | .leds = dns323c_leds, | |
ff3e660b | 299 | .gpio_blink_set = orion_gpio_led_blink_set, |
555a3656 HVR |
300 | }; |
301 | ||
302 | static struct platform_device dns323_gpio_leds = { | |
303 | .name = "leds-gpio", | |
304 | .id = -1, | |
e7068ad3 | 305 | .dev = { |
6e2daa49 | 306 | .platform_data = &dns323ab_led_data, |
e7068ad3 | 307 | }, |
555a3656 HVR |
308 | }; |
309 | ||
310 | /**************************************************************************** | |
311 | * GPIO Attached Keys | |
312 | */ | |
313 | ||
6e2daa49 | 314 | static struct gpio_keys_button dns323ab_buttons[] = { |
555a3656 HVR |
315 | { |
316 | .code = KEY_RESTART, | |
317 | .gpio = DNS323_GPIO_KEY_RESET, | |
318 | .desc = "Reset Button", | |
319 | .active_low = 1, | |
e7068ad3 | 320 | }, { |
555a3656 HVR |
321 | .code = KEY_POWER, |
322 | .gpio = DNS323_GPIO_KEY_POWER, | |
323 | .desc = "Power Button", | |
324 | .active_low = 1, | |
e7068ad3 | 325 | }, |
555a3656 HVR |
326 | }; |
327 | ||
6e2daa49 BH |
328 | static struct gpio_keys_platform_data dns323ab_button_data = { |
329 | .buttons = dns323ab_buttons, | |
330 | .nbuttons = ARRAY_SIZE(dns323ab_buttons), | |
331 | }; | |
332 | ||
333 | static struct gpio_keys_button dns323c_buttons[] = { | |
334 | { | |
335 | .code = KEY_POWER, | |
336 | .gpio = DNS323C_GPIO_KEY_POWER, | |
337 | .desc = "Power Button", | |
338 | .active_low = 1, | |
339 | }, | |
340 | }; | |
341 | ||
342 | static struct gpio_keys_platform_data dns323c_button_data = { | |
343 | .buttons = dns323c_buttons, | |
344 | .nbuttons = ARRAY_SIZE(dns323c_buttons), | |
555a3656 HVR |
345 | }; |
346 | ||
347 | static struct platform_device dns323_button_device = { | |
348 | .name = "gpio-keys", | |
349 | .id = -1, | |
350 | .num_resources = 0, | |
e7068ad3 | 351 | .dev = { |
6e2daa49 | 352 | .platform_data = &dns323ab_button_data, |
e7068ad3 | 353 | }, |
555a3656 HVR |
354 | }; |
355 | ||
f93e4159 MP |
356 | /***************************************************************************** |
357 | * SATA | |
358 | */ | |
359 | static struct mv_sata_platform_data dns323_sata_data = { | |
360 | .n_ports = 2, | |
361 | }; | |
362 | ||
555a3656 HVR |
363 | /**************************************************************************** |
364 | * General Setup | |
365 | */ | |
554cdaef AL |
366 | static unsigned int dns323a_mpp_modes[] __initdata = { |
367 | MPP0_PCIE_RST_OUTn, | |
368 | MPP1_GPIO, /* right amber LED (sata ch0) */ | |
369 | MPP2_GPIO, /* left amber LED (sata ch1) */ | |
370 | MPP3_UNUSED, | |
371 | MPP4_GPIO, /* power button LED */ | |
372 | MPP5_GPIO, /* power button LED */ | |
373 | MPP6_GPIO, /* GMT G751-2f overtemp */ | |
374 | MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */ | |
375 | MPP8_GPIO, /* triggers power off */ | |
376 | MPP9_GPIO, /* power button switch */ | |
377 | MPP10_GPIO, /* reset button switch */ | |
378 | MPP11_UNUSED, | |
379 | MPP12_UNUSED, | |
380 | MPP13_UNUSED, | |
381 | MPP14_UNUSED, | |
382 | MPP15_UNUSED, | |
383 | MPP16_UNUSED, | |
384 | MPP17_UNUSED, | |
385 | MPP18_UNUSED, | |
386 | MPP19_UNUSED, | |
387 | 0, | |
19cfd5c0 | 388 | }; |
555a3656 | 389 | |
554cdaef AL |
390 | static unsigned int dns323b_mpp_modes[] __initdata = { |
391 | MPP0_UNUSED, | |
392 | MPP1_GPIO, /* right amber LED (sata ch0) */ | |
393 | MPP2_GPIO, /* left amber LED (sata ch1) */ | |
394 | MPP3_GPIO, /* system up flag */ | |
395 | MPP4_GPIO, /* power button LED */ | |
396 | MPP5_GPIO, /* power button LED */ | |
397 | MPP6_GPIO, /* GMT G751-2f overtemp */ | |
398 | MPP7_GPIO, /* M41T80 nIRQ/OUT/SQW */ | |
399 | MPP8_GPIO, /* triggers power off */ | |
400 | MPP9_GPIO, /* power button switch */ | |
401 | MPP10_GPIO, /* reset button switch */ | |
402 | MPP11_UNUSED, | |
403 | MPP12_SATA_LED, | |
404 | MPP13_SATA_LED, | |
405 | MPP14_SATA_LED, | |
406 | MPP15_SATA_LED, | |
407 | MPP16_UNUSED, | |
408 | MPP17_UNUSED, | |
409 | MPP18_UNUSED, | |
410 | MPP19_UNUSED, | |
411 | 0, | |
f93e4159 MP |
412 | }; |
413 | ||
554cdaef AL |
414 | static unsigned int dns323c_mpp_modes[] __initdata = { |
415 | MPP0_GPIO, /* ? input */ | |
416 | MPP1_GPIO, /* input power switch (0 = pressed) */ | |
417 | MPP2_GPIO, /* output power off */ | |
418 | MPP3_UNUSED, /* ? output */ | |
419 | MPP4_UNUSED, /* ? output */ | |
420 | MPP5_UNUSED, /* ? output */ | |
421 | MPP6_UNUSED, /* ? output */ | |
422 | MPP7_UNUSED, /* ? output */ | |
423 | MPP8_GPIO, /* i/o right amber LED */ | |
424 | MPP9_GPIO, /* i/o left amber LED */ | |
425 | MPP10_GPIO, /* input */ | |
426 | MPP11_UNUSED, | |
427 | MPP12_SATA_LED, | |
428 | MPP13_SATA_LED, | |
429 | MPP14_SATA_LED, | |
430 | MPP15_SATA_LED, | |
431 | MPP16_UNUSED, | |
432 | MPP17_GPIO, /* power button LED */ | |
433 | MPP18_GPIO, /* fan speed bit 0 */ | |
434 | MPP19_GPIO, /* fan speed bit 1 */ | |
435 | 0, | |
6e2daa49 BH |
436 | }; |
437 | ||
438 | /* Rev C1 Fan speed notes: | |
439 | * | |
440 | * The fan is controlled by 2 GPIOs on this board. The settings | |
441 | * of the bits is as follow: | |
442 | * | |
443 | * GPIO 18 GPIO 19 Fan | |
444 | * | |
445 | * 0 0 stopped | |
446 | * 0 1 low speed | |
447 | * 1 0 high speed | |
448 | * 1 1 don't do that (*) | |
449 | * | |
450 | * (*) I think the two bits control two feed-in resistors into a fixed | |
451 | * PWN circuit, setting both bits will basically go a 'bit' faster | |
452 | * than high speed, but d-link doesn't do it and you may get out of | |
453 | * HW spec so don't do it. | |
454 | */ | |
455 | ||
555a3656 | 456 | /* |
6e2daa49 | 457 | * On the DNS-323 A1 and B1 the following devices are attached via I2C: |
555a3656 HVR |
458 | * |
459 | * i2c addr | chip | description | |
460 | * 0x3e | GMT G760Af | fan speed PWM controller | |
461 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) | |
462 | * 0x68 | ST M41T80 | RTC w/ alarm | |
463 | */ | |
6e2daa49 | 464 | static struct i2c_board_info __initdata dns323ab_i2c_devices[] = { |
555a3656 HVR |
465 | { |
466 | I2C_BOARD_INFO("g760a", 0x3e), | |
e7068ad3 | 467 | }, { |
c0fe819b | 468 | I2C_BOARD_INFO("lm75", 0x48), |
e7068ad3 | 469 | }, { |
3760f736 | 470 | I2C_BOARD_INFO("m41t80", 0x68), |
e7068ad3 | 471 | }, |
555a3656 HVR |
472 | }; |
473 | ||
6e2daa49 BH |
474 | /* |
475 | * On the DNS-323 C1 the following devices are attached via I2C: | |
476 | * | |
477 | * i2c addr | chip | description | |
478 | * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible) | |
479 | * 0x68 | ST M41T80 | RTC w/ alarm | |
480 | */ | |
481 | static struct i2c_board_info __initdata dns323c_i2c_devices[] = { | |
482 | { | |
483 | I2C_BOARD_INFO("lm75", 0x48), | |
484 | }, { | |
485 | I2C_BOARD_INFO("m41t80", 0x68), | |
486 | }, | |
487 | }; | |
488 | ||
cf11052a EB |
489 | /* DNS-323 rev. A specific power off method */ |
490 | static void dns323a_power_off(void) | |
555a3656 | 491 | { |
6e2daa49 | 492 | pr_info("DNS-323: Triggering power-off...\n"); |
555a3656 HVR |
493 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); |
494 | } | |
495 | ||
cf11052a EB |
496 | /* DNS-323 rev B specific power off method */ |
497 | static void dns323b_power_off(void) | |
498 | { | |
6e2daa49 | 499 | pr_info("DNS-323: Triggering power-off...\n"); |
cf11052a EB |
500 | /* Pin has to be changed to 1 and back to 0 to do actual power off. */ |
501 | gpio_set_value(DNS323_GPIO_POWER_OFF, 1); | |
502 | mdelay(100); | |
503 | gpio_set_value(DNS323_GPIO_POWER_OFF, 0); | |
504 | } | |
505 | ||
6e2daa49 BH |
506 | /* DNS-323 rev. C specific power off method */ |
507 | static void dns323c_power_off(void) | |
508 | { | |
509 | pr_info("DNS-323: Triggering power-off...\n"); | |
510 | gpio_set_value(DNS323C_GPIO_POWER_OFF, 1); | |
511 | } | |
512 | ||
513 | static int dns323c_phy_fixup(struct phy_device *phy) | |
514 | { | |
515 | phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS; | |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
520 | static int __init dns323_identify_rev(void) | |
521 | { | |
522 | u32 dev, rev, i, reg; | |
523 | ||
524 | pr_debug("DNS-323: Identifying board ... \n"); | |
525 | ||
526 | /* Rev A1 has a 5181 */ | |
527 | orion5x_pcie_id(&dev, &rev); | |
528 | if (dev == MV88F5181_DEV_ID) { | |
529 | pr_debug("DNS-323: 5181 found, board is A1\n"); | |
530 | return DNS323_REV_A1; | |
531 | } | |
532 | pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n"); | |
533 | ||
534 | /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is | |
535 | * a bit gross but we want to do that without links into the eth | |
536 | * driver so let's poke at it directly. We default to rev B1 in | |
537 | * case the accesses fail | |
538 | */ | |
539 | ||
540 | #define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004) | |
541 | #define SMI_BUSY 0x10000000 | |
542 | #define SMI_READ_VALID 0x08000000 | |
543 | #define SMI_OPCODE_READ 0x04000000 | |
544 | #define SMI_OPCODE_WRITE 0x00000000 | |
545 | ||
546 | for (i = 0; i < 1000; i++) { | |
547 | reg = readl(ETH_SMI_REG); | |
548 | if (!(reg & SMI_BUSY)) | |
549 | break; | |
550 | } | |
551 | if (i >= 1000) { | |
552 | pr_warning("DNS-323: Timeout accessing PHY, assuming rev B1\n"); | |
553 | return DNS323_REV_B1; | |
554 | } | |
555 | writel((3 << 21) /* phy ID reg */ | | |
556 | (8 << 16) /* phy addr */ | | |
557 | SMI_OPCODE_READ, ETH_SMI_REG); | |
558 | for (i = 0; i < 1000; i++) { | |
559 | reg = readl(ETH_SMI_REG); | |
560 | if (reg & SMI_READ_VALID) | |
561 | break; | |
562 | } | |
563 | if (i >= 1000) { | |
564 | pr_warning("DNS-323: Timeout reading PHY, assuming rev B1\n"); | |
565 | return DNS323_REV_B1; | |
566 | } | |
567 | pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff); | |
568 | ||
569 | /* Note: the Marvell tools mask the ID with 0x3f0 before comparison | |
570 | * but I don't see that making a difference here, at least with | |
571 | * any known Marvell PHY ID | |
572 | */ | |
573 | switch(reg & 0xfff0) { | |
574 | case 0x0cc0: /* MV88E1111 */ | |
575 | return DNS323_REV_B1; | |
576 | case 0x0e10: /* MV88E1118 */ | |
577 | return DNS323_REV_C1; | |
578 | default: | |
579 | pr_warning("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n", | |
580 | reg & 0xffff); | |
581 | } | |
582 | return DNS323_REV_B1; | |
583 | } | |
584 | ||
555a3656 HVR |
585 | static void __init dns323_init(void) |
586 | { | |
587 | /* Setup basic Orion functions. Need to be called early. */ | |
9dd0b194 | 588 | orion5x_init(); |
555a3656 | 589 | |
6e2daa49 BH |
590 | /* Identify revision */ |
591 | system_rev = dns323_identify_rev(); | |
592 | pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev); | |
593 | ||
f93e4159 MP |
594 | /* Just to be tricky, the 5182 has a completely different |
595 | * set of MPP modes to the 5181. | |
596 | */ | |
6e2daa49 BH |
597 | switch(system_rev) { |
598 | case DNS323_REV_A1: | |
599 | orion5x_mpp_conf(dns323a_mpp_modes); | |
f93e4159 | 600 | writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */ |
6e2daa49 BH |
601 | break; |
602 | case DNS323_REV_B1: | |
603 | orion5x_mpp_conf(dns323b_mpp_modes); | |
604 | break; | |
605 | case DNS323_REV_C1: | |
606 | orion5x_mpp_conf(dns323c_mpp_modes); | |
607 | break; | |
f93e4159 | 608 | } |
555a3656 | 609 | |
044f6c7c LB |
610 | /* setup flash mapping |
611 | * CS3 holds a 8 MB Spansion S29GL064M90TFIR4 | |
612 | */ | |
613 | orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE); | |
614 | platform_device_register(&dns323_nor_flash); | |
615 | ||
6e2daa49 BH |
616 | /* Sort out LEDs, Buttons and i2c devices */ |
617 | switch(system_rev) { | |
618 | case DNS323_REV_A1: | |
619 | /* The 5181 power LED is active low and requires | |
620 | * DNS323_GPIO_LED_POWER1 to also be low. | |
621 | */ | |
622 | dns323ab_leds[0].active_low = 1; | |
623 | gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable"); | |
624 | gpio_direction_output(DNS323_GPIO_LED_POWER1, 0); | |
625 | /* Fall through */ | |
626 | case DNS323_REV_B1: | |
627 | i2c_register_board_info(0, dns323ab_i2c_devices, | |
628 | ARRAY_SIZE(dns323ab_i2c_devices)); | |
629 | break; | |
630 | case DNS323_REV_C1: | |
631 | /* Hookup LEDs & Buttons */ | |
632 | dns323_gpio_leds.dev.platform_data = &dns323c_led_data; | |
633 | dns323_button_device.dev.platform_data = &dns323c_button_data; | |
634 | ||
635 | /* Hookup i2c devices and fan driver */ | |
636 | i2c_register_board_info(0, dns323c_i2c_devices, | |
637 | ARRAY_SIZE(dns323c_i2c_devices)); | |
638 | platform_device_register_simple("dns323c-fan", 0, NULL, 0); | |
639 | ||
640 | /* Register fixup for the PHY LEDs */ | |
641 | phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118, | |
642 | MARVELL_PHY_ID_MASK, | |
643 | dns323c_phy_fixup); | |
b2a731aa LB |
644 | } |
645 | ||
044f6c7c | 646 | platform_device_register(&dns323_gpio_leds); |
044f6c7c | 647 | platform_device_register(&dns323_button_device); |
555a3656 | 648 | |
a93f44c1 MP |
649 | /* |
650 | * Configure peripherals. | |
651 | */ | |
652 | if (dns323_read_mac_addr() < 0) | |
6e2daa49 | 653 | printk("DNS-323: Failed to read MAC address\n"); |
a93f44c1 MP |
654 | orion5x_ehci0_init(); |
655 | orion5x_eth_init(&dns323_eth_data); | |
656 | orion5x_i2c_init(); | |
657 | orion5x_uart0_init(); | |
658 | ||
6e2daa49 BH |
659 | /* Remaining GPIOs */ |
660 | switch(system_rev) { | |
661 | case DNS323_REV_A1: | |
662 | /* Poweroff GPIO */ | |
663 | if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 || | |
664 | gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0) | |
665 | pr_err("DNS-323: failed to setup power-off GPIO\n"); | |
666 | pm_power_off = dns323a_power_off; | |
667 | break; | |
668 | case DNS323_REV_B1: | |
669 | /* 5182 built-in SATA init */ | |
f93e4159 MP |
670 | orion5x_sata_init(&dns323_sata_data); |
671 | ||
6e2daa49 BH |
672 | /* The DNS323 rev B1 has flag to indicate the system is up. |
673 | * Without this flag set, power LED will flash and cannot be | |
674 | * controlled via leds-gpio. | |
675 | */ | |
676 | if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0) | |
677 | gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1); | |
678 | ||
679 | /* Poweroff GPIO */ | |
680 | if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 || | |
681 | gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0) | |
682 | pr_err("DNS-323: failed to setup power-off GPIO\n"); | |
cf11052a | 683 | pm_power_off = dns323b_power_off; |
6e2daa49 BH |
684 | break; |
685 | case DNS323_REV_C1: | |
686 | /* 5182 built-in SATA init */ | |
687 | orion5x_sata_init(&dns323_sata_data); | |
688 | ||
689 | /* Poweroff GPIO */ | |
690 | if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 || | |
691 | gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0) | |
692 | pr_err("DNS-323: failed to setup power-off GPIO\n"); | |
693 | pm_power_off = dns323c_power_off; | |
694 | ||
695 | /* Now, -this- should theorically be done by the sata_mv driver | |
696 | * once I figure out what's going on there. Maybe the behaviour | |
697 | * of the LEDs should be somewhat passed via the platform_data. | |
698 | * for now, just whack the register and make the LEDs happy | |
699 | * | |
700 | * Note: AFAIK, rev B1 needs the same treatement but I'll let | |
701 | * somebody else test it. | |
702 | */ | |
703 | writel(0x5, ORION5X_SATA_VIRT_BASE | 0x2c); | |
704 | break; | |
705 | } | |
555a3656 HVR |
706 | } |
707 | ||
708 | /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */ | |
709 | MACHINE_START(DNS323, "D-Link DNS-323") | |
710 | /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */ | |
65aa1b1e | 711 | .atag_offset = 0x100, |
555a3656 | 712 | .init_machine = dns323_init, |
9dd0b194 | 713 | .map_io = orion5x_map_io, |
4ee1f6b5 | 714 | .init_early = orion5x_init_early, |
9dd0b194 LB |
715 | .init_irq = orion5x_init_irq, |
716 | .timer = &orion5x_timer, | |
be73a347 | 717 | .fixup = tag_fixup_mem32, |
764cbcc2 | 718 | .restart = orion5x_restart, |
555a3656 | 719 | MACHINE_END |