1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/gpio.h>
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/delay.h>
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>
29#include <linux/ata_platform.h>
30#include <linux/phy.h>
31#include <linux/marvell_phy.h>
32#include <asm/mach-types.h>
33#include <asm/mach/arch.h>
34#include <asm/mach/pci.h>
35#include <asm/system_info.h>
36#include <mach/orion5x.h>
37#include <plat/orion-gpio.h>
38#include "common.h"
39#include "mpp.h"
40
41
42#define DNS323_GPIO_LED_RIGHT_AMBER 1
43#define DNS323_GPIO_LED_LEFT_AMBER 2
44#define DNS323_GPIO_SYSTEM_UP 3
45#define DNS323_GPIO_LED_POWER1 4
46#define DNS323_GPIO_LED_POWER2 5
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
53
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
63enum {
64 DNS323_REV_A1,
65 DNS323_REV_B1,
66 DNS323_REV_C1,
67};
68
69
70
71
72
73
74static int __init dns323_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
75{
76 int irq;
77
78
79
80
81 irq = orion5x_pci_map_irq(dev, slot, pin);
82 if (irq != -1)
83 return irq;
84
85 return -1;
86}
87
88static struct hw_pci dns323_pci __initdata = {
89 .nr_controllers = 2,
90 .setup = orion5x_pci_sys_setup,
91 .scan = orion5x_pci_sys_scan_bus,
92 .map_irq = dns323_pci_map_irq,
93};
94
95static int __init dns323_pci_init(void)
96{
97
98
99
100 if (machine_is_dns323() && system_rev == DNS323_REV_A1)
101 pci_common_init(&dns323_pci);
102
103 return 0;
104}
105
106subsys_initcall(dns323_pci_init);
107
108
109
110
111
112
113
114
115
116
117
118
119#define DNS323_NOR_BOOT_BASE 0xf4000000
120#define DNS323_NOR_BOOT_SIZE SZ_8M
121
122static 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,
143 },
144};
145
146static struct physmap_flash_data dns323_nor_flash_data = {
147 .width = 1,
148 .parts = dns323_partitions,
149 .nr_parts = ARRAY_SIZE(dns323_partitions)
150};
151
152static 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
158static struct platform_device dns323_nor_flash = {
159 .name = "physmap-flash",
160 .id = 0,
161 .dev = {
162 .platform_data = &dns323_nor_flash_data,
163 },
164 .resource = &dns323_nor_flash_resource,
165 .num_resources = 1,
166};
167
168
169
170
171
172static struct mv643xx_eth_platform_data dns323_eth_data = {
173 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
174};
175
176
177
178
179static int __init dns323_parse_hex_nibble(char n)
180{
181 if (n >= '0' && n <= '9')
182 return n - '0';
183
184 if (n >= 'A' && n <= 'F')
185 return n - 'A' + 10;
186
187 if (n >= 'a' && n <= 'f')
188 return n - 'a' + 10;
189
190 return -1;
191}
192
193static int __init dns323_parse_hex_byte(const char *b)
194{
195 int hi;
196 int lo;
197
198 hi = dns323_parse_hex_nibble(b[0]);
199 lo = dns323_parse_hex_nibble(b[1]);
200
201 if (hi < 0 || lo < 0)
202 return -1;
203
204 return (hi << 4) | lo;
205}
206
207static int __init dns323_read_mac_addr(void)
208{
209 u_int8_t addr[6];
210 int i;
211 char *mac_page;
212
213
214
215
216 mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
217 if (!mac_page)
218 return -ENOMEM;
219
220
221 for (i = 0; i < 5; i++) {
222 if (*(mac_page + (i * 3) + 2) != ':') {
223 goto error_fail;
224 }
225 }
226
227 for (i = 0; i < 6; i++) {
228 int byte;
229
230 byte = dns323_parse_hex_byte(mac_page + (i * 3));
231 if (byte < 0) {
232 goto error_fail;
233 }
234
235 addr[i] = byte;
236 }
237
238 iounmap(mac_page);
239 printk("DNS-323: Found ethernet MAC address: ");
240 for (i = 0; i < 6; i++)
241 printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
242
243 memcpy(dns323_eth_data.mac_addr, addr, 6);
244
245 return 0;
246
247error_fail:
248 iounmap(mac_page);
249 return -EINVAL;
250}
251
252
253
254
255
256static struct gpio_led dns323ab_leds[] = {
257 {
258 .name = "power:blue",
259 .gpio = DNS323_GPIO_LED_POWER2,
260 .default_trigger = "default-on",
261 }, {
262 .name = "right:amber",
263 .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
264 .active_low = 1,
265 }, {
266 .name = "left:amber",
267 .gpio = DNS323_GPIO_LED_LEFT_AMBER,
268 .active_low = 1,
269 },
270};
271
272
273static struct gpio_led dns323c_leds[] = {
274 {
275 .name = "power:blue",
276 .gpio = DNS323C_GPIO_LED_POWER,
277 .default_trigger = "timer",
278 .active_low = 1,
279 }, {
280 .name = "right:amber",
281 .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
282 .active_low = 1,
283 }, {
284 .name = "left:amber",
285 .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
286 .active_low = 1,
287 },
288};
289
290
291static struct gpio_led_platform_data dns323ab_led_data = {
292 .num_leds = ARRAY_SIZE(dns323ab_leds),
293 .leds = dns323ab_leds,
294 .gpio_blink_set = orion_gpio_led_blink_set,
295};
296
297static struct gpio_led_platform_data dns323c_led_data = {
298 .num_leds = ARRAY_SIZE(dns323c_leds),
299 .leds = dns323c_leds,
300 .gpio_blink_set = orion_gpio_led_blink_set,
301};
302
303static struct platform_device dns323_gpio_leds = {
304 .name = "leds-gpio",
305 .id = -1,
306 .dev = {
307 .platform_data = &dns323ab_led_data,
308 },
309};
310
311
312
313
314
315static struct gpio_keys_button dns323ab_buttons[] = {
316 {
317 .code = KEY_RESTART,
318 .gpio = DNS323_GPIO_KEY_RESET,
319 .desc = "Reset Button",
320 .active_low = 1,
321 }, {
322 .code = KEY_POWER,
323 .gpio = DNS323_GPIO_KEY_POWER,
324 .desc = "Power Button",
325 .active_low = 1,
326 },
327};
328
329static struct gpio_keys_platform_data dns323ab_button_data = {
330 .buttons = dns323ab_buttons,
331 .nbuttons = ARRAY_SIZE(dns323ab_buttons),
332};
333
334static struct gpio_keys_button dns323c_buttons[] = {
335 {
336 .code = KEY_POWER,
337 .gpio = DNS323C_GPIO_KEY_POWER,
338 .desc = "Power Button",
339 .active_low = 1,
340 },
341};
342
343static struct gpio_keys_platform_data dns323c_button_data = {
344 .buttons = dns323c_buttons,
345 .nbuttons = ARRAY_SIZE(dns323c_buttons),
346};
347
348static struct platform_device dns323_button_device = {
349 .name = "gpio-keys",
350 .id = -1,
351 .num_resources = 0,
352 .dev = {
353 .platform_data = &dns323ab_button_data,
354 },
355};
356
357
358
359
360static struct mv_sata_platform_data dns323_sata_data = {
361 .n_ports = 2,
362};
363
364
365
366
367static unsigned int dns323a_mpp_modes[] __initdata = {
368 MPP0_PCIE_RST_OUTn,
369 MPP1_GPIO,
370 MPP2_GPIO,
371 MPP3_UNUSED,
372 MPP4_GPIO,
373 MPP5_GPIO,
374 MPP6_GPIO,
375 MPP7_GPIO,
376 MPP8_GPIO,
377 MPP9_GPIO,
378 MPP10_GPIO,
379 MPP11_UNUSED,
380 MPP12_UNUSED,
381 MPP13_UNUSED,
382 MPP14_UNUSED,
383 MPP15_UNUSED,
384 MPP16_UNUSED,
385 MPP17_UNUSED,
386 MPP18_UNUSED,
387 MPP19_UNUSED,
388 0,
389};
390
391static unsigned int dns323b_mpp_modes[] __initdata = {
392 MPP0_UNUSED,
393 MPP1_GPIO,
394 MPP2_GPIO,
395 MPP3_GPIO,
396 MPP4_GPIO,
397 MPP5_GPIO,
398 MPP6_GPIO,
399 MPP7_GPIO,
400 MPP8_GPIO,
401 MPP9_GPIO,
402 MPP10_GPIO,
403 MPP11_UNUSED,
404 MPP12_SATA_LED,
405 MPP13_SATA_LED,
406 MPP14_SATA_LED,
407 MPP15_SATA_LED,
408 MPP16_UNUSED,
409 MPP17_UNUSED,
410 MPP18_UNUSED,
411 MPP19_UNUSED,
412 0,
413};
414
415static unsigned int dns323c_mpp_modes[] __initdata = {
416 MPP0_GPIO,
417 MPP1_GPIO,
418 MPP2_GPIO,
419 MPP3_UNUSED,
420 MPP4_UNUSED,
421 MPP5_UNUSED,
422 MPP6_UNUSED,
423 MPP7_UNUSED,
424 MPP8_GPIO,
425 MPP9_GPIO,
426 MPP10_GPIO,
427 MPP11_UNUSED,
428 MPP12_SATA_LED,
429 MPP13_SATA_LED,
430 MPP14_SATA_LED,
431 MPP15_SATA_LED,
432 MPP16_UNUSED,
433 MPP17_GPIO,
434 MPP18_GPIO,
435 MPP19_GPIO,
436 0,
437};
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465static struct i2c_board_info __initdata dns323ab_i2c_devices[] = {
466 {
467 I2C_BOARD_INFO("g760a", 0x3e),
468 }, {
469 I2C_BOARD_INFO("lm75", 0x48),
470 }, {
471 I2C_BOARD_INFO("m41t80", 0x68),
472 },
473};
474
475
476
477
478
479
480
481
482static struct i2c_board_info __initdata dns323c_i2c_devices[] = {
483 {
484 I2C_BOARD_INFO("lm75", 0x48),
485 }, {
486 I2C_BOARD_INFO("m41t80", 0x68),
487 },
488};
489
490
491static void dns323a_power_off(void)
492{
493 pr_info("DNS-323: Triggering power-off...\n");
494 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
495}
496
497
498static void dns323b_power_off(void)
499{
500 pr_info("DNS-323: Triggering power-off...\n");
501
502 gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
503 mdelay(100);
504 gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
505}
506
507
508static void dns323c_power_off(void)
509{
510 pr_info("DNS-323: Triggering power-off...\n");
511 gpio_set_value(DNS323C_GPIO_POWER_OFF, 1);
512}
513
514static int dns323c_phy_fixup(struct phy_device *phy)
515{
516 phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS;
517
518 return 0;
519}
520
521static int __init dns323_identify_rev(void)
522{
523 u32 dev, rev, i, reg;
524
525 pr_debug("DNS-323: Identifying board ... \n");
526
527
528 orion5x_pcie_id(&dev, &rev);
529 if (dev == MV88F5181_DEV_ID) {
530 pr_debug("DNS-323: 5181 found, board is A1\n");
531 return DNS323_REV_A1;
532 }
533 pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n");
534
535
536
537
538
539
540
541#define ETH_SMI_REG (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004)
542#define SMI_BUSY 0x10000000
543#define SMI_READ_VALID 0x08000000
544#define SMI_OPCODE_READ 0x04000000
545#define SMI_OPCODE_WRITE 0x00000000
546
547 for (i = 0; i < 1000; i++) {
548 reg = readl(ETH_SMI_REG);
549 if (!(reg & SMI_BUSY))
550 break;
551 }
552 if (i >= 1000) {
553 pr_warn("DNS-323: Timeout accessing PHY, assuming rev B1\n");
554 return DNS323_REV_B1;
555 }
556 writel((3 << 21) |
557 (8 << 16) |
558 SMI_OPCODE_READ, ETH_SMI_REG);
559 for (i = 0; i < 1000; i++) {
560 reg = readl(ETH_SMI_REG);
561 if (reg & SMI_READ_VALID)
562 break;
563 }
564 if (i >= 1000) {
565 pr_warn("DNS-323: Timeout reading PHY, assuming rev B1\n");
566 return DNS323_REV_B1;
567 }
568 pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff);
569
570
571
572
573
574 switch(reg & 0xfff0) {
575 case 0x0cc0:
576 return DNS323_REV_B1;
577 case 0x0e10:
578 return DNS323_REV_C1;
579 default:
580 pr_warn("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n",
581 reg & 0xffff);
582 }
583 return DNS323_REV_B1;
584}
585
586static void __init dns323_init(void)
587{
588
589 orion5x_init();
590
591
592 system_rev = dns323_identify_rev();
593 pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev);
594
595
596
597
598 switch(system_rev) {
599 case DNS323_REV_A1:
600 orion5x_mpp_conf(dns323a_mpp_modes);
601 writel(0, MPP_DEV_CTRL);
602 break;
603 case DNS323_REV_B1:
604 orion5x_mpp_conf(dns323b_mpp_modes);
605 break;
606 case DNS323_REV_C1:
607 orion5x_mpp_conf(dns323c_mpp_modes);
608 break;
609 }
610
611
612
613
614 mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
615 ORION_MBUS_DEVBUS_BOOT_ATTR,
616 DNS323_NOR_BOOT_BASE,
617 DNS323_NOR_BOOT_SIZE);
618 platform_device_register(&dns323_nor_flash);
619
620
621 switch(system_rev) {
622 case DNS323_REV_A1:
623
624
625
626 dns323ab_leds[0].active_low = 1;
627 gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
628 gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
629
630 case DNS323_REV_B1:
631 i2c_register_board_info(0, dns323ab_i2c_devices,
632 ARRAY_SIZE(dns323ab_i2c_devices));
633 break;
634 case DNS323_REV_C1:
635
636 dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
637 dns323_button_device.dev.platform_data = &dns323c_button_data;
638
639
640 i2c_register_board_info(0, dns323c_i2c_devices,
641 ARRAY_SIZE(dns323c_i2c_devices));
642 platform_device_register_simple("dns323c-fan", 0, NULL, 0);
643
644
645 if (!IS_BUILTIN(CONFIG_PHYLIB))
646 break;
647 phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118,
648 MARVELL_PHY_ID_MASK,
649 dns323c_phy_fixup);
650 }
651
652 platform_device_register(&dns323_gpio_leds);
653 platform_device_register(&dns323_button_device);
654
655
656
657
658 if (dns323_read_mac_addr() < 0)
659 printk("DNS-323: Failed to read MAC address\n");
660 orion5x_ehci0_init();
661 orion5x_eth_init(&dns323_eth_data);
662 orion5x_i2c_init();
663 orion5x_uart0_init();
664
665
666 switch(system_rev) {
667 case DNS323_REV_A1:
668
669 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
670 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
671 pr_err("DNS-323: failed to setup power-off GPIO\n");
672 pm_power_off = dns323a_power_off;
673 break;
674 case DNS323_REV_B1:
675
676 orion5x_sata_init(&dns323_sata_data);
677
678
679
680
681
682 if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0)
683 gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1);
684
685
686 if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
687 gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
688 pr_err("DNS-323: failed to setup power-off GPIO\n");
689 pm_power_off = dns323b_power_off;
690 break;
691 case DNS323_REV_C1:
692
693 orion5x_sata_init(&dns323_sata_data);
694
695
696 if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
697 gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
698 pr_err("DNS-323: failed to setup power-off GPIO\n");
699 pm_power_off = dns323c_power_off;
700
701
702
703
704
705
706
707
708
709 writel(0x5, ORION5X_SATA_VIRT_BASE + 0x2c);
710 break;
711 }
712}
713
714
715MACHINE_START(DNS323, "D-Link DNS-323")
716
717 .atag_offset = 0x100,
718 .init_machine = dns323_init,
719 .map_io = orion5x_map_io,
720 .init_early = orion5x_init_early,
721 .init_irq = orion5x_init_irq,
722 .init_time = orion5x_timer_init,
723 .fixup = tag_fixup_mem32,
724 .restart = orion5x_restart,
725MACHINE_END
726