dns323-setup.c 19 KB

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