dns323-setup.c 18 KB

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