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