dns323-setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * arch/arm/mach-orion5x/dns323-setup.c
  3. *
  4. * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pci.h>
  17. #include <linux/irq.h>
  18. #include <linux/mtd/physmap.h>
  19. #include <linux/mv643xx_eth.h>
  20. #include <linux/leds.h>
  21. #include <linux/gpio_keys.h>
  22. #include <linux/input.h>
  23. #include <linux/i2c.h>
  24. #include <linux/ata_platform.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/gpio.h>
  27. #include <asm/mach/arch.h>
  28. #include <asm/mach/pci.h>
  29. #include <mach/orion5x.h>
  30. #include "common.h"
  31. #include "mpp.h"
  32. #define DNS323_GPIO_LED_RIGHT_AMBER 1
  33. #define DNS323_GPIO_LED_LEFT_AMBER 2
  34. #define DNS323_GPIO_SYSTEM_UP 3
  35. #define DNS323_GPIO_LED_POWER 5
  36. #define DNS323_GPIO_OVERTEMP 6
  37. #define DNS323_GPIO_RTC 7
  38. #define DNS323_GPIO_POWER_OFF 8
  39. #define DNS323_GPIO_KEY_POWER 9
  40. #define DNS323_GPIO_KEY_RESET 10
  41. /****************************************************************************
  42. * PCI setup
  43. */
  44. static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  45. {
  46. int irq;
  47. /*
  48. * Check for devices with hard-wired IRQs.
  49. */
  50. irq = orion5x_pci_map_irq(dev, slot, pin);
  51. if (irq != -1)
  52. return irq;
  53. return -1;
  54. }
  55. static struct hw_pci dns323_pci __initdata = {
  56. .nr_controllers = 2,
  57. .swizzle = pci_std_swizzle,
  58. .setup = orion5x_pci_sys_setup,
  59. .scan = orion5x_pci_sys_scan_bus,
  60. .map_irq = dns323_pci_map_irq,
  61. };
  62. static int __init dns323_dev_id(void)
  63. {
  64. u32 dev, rev;
  65. orion5x_pcie_id(&dev, &rev);
  66. return dev;
  67. }
  68. static int __init dns323_pci_init(void)
  69. {
  70. /* The 5182 doesn't really use its PCI bus, and initialising PCI
  71. * gets in the way of initialising the SATA controller.
  72. */
  73. if (machine_is_dns323() && dns323_dev_id() != MV88F5182_DEV_ID)
  74. pci_common_init(&dns323_pci);
  75. return 0;
  76. }
  77. subsys_initcall(dns323_pci_init);
  78. /****************************************************************************
  79. * 8MiB NOR flash (Spansion S29GL064M90TFIR4)
  80. *
  81. * Layout as used by D-Link:
  82. * 0x00000000-0x00010000 : "MTD1"
  83. * 0x00010000-0x00020000 : "MTD2"
  84. * 0x00020000-0x001a0000 : "Linux Kernel"
  85. * 0x001a0000-0x007d0000 : "File System"
  86. * 0x007d0000-0x00800000 : "u-boot"
  87. */
  88. #define DNS323_NOR_BOOT_BASE 0xf4000000
  89. #define DNS323_NOR_BOOT_SIZE SZ_8M
  90. static struct mtd_partition dns323_partitions[] = {
  91. {
  92. .name = "MTD1",
  93. .size = 0x00010000,
  94. .offset = 0,
  95. }, {
  96. .name = "MTD2",
  97. .size = 0x00010000,
  98. .offset = 0x00010000,
  99. }, {
  100. .name = "Linux Kernel",
  101. .size = 0x00180000,
  102. .offset = 0x00020000,
  103. }, {
  104. .name = "File System",
  105. .size = 0x00630000,
  106. .offset = 0x001A0000,
  107. }, {
  108. .name = "u-boot",
  109. .size = 0x00030000,
  110. .offset = 0x007d0000,
  111. },
  112. };
  113. static struct physmap_flash_data dns323_nor_flash_data = {
  114. .width = 1,
  115. .parts = dns323_partitions,
  116. .nr_parts = ARRAY_SIZE(dns323_partitions)
  117. };
  118. static struct resource dns323_nor_flash_resource = {
  119. .flags = IORESOURCE_MEM,
  120. .start = DNS323_NOR_BOOT_BASE,
  121. .end = DNS323_NOR_BOOT_BASE + DNS323_NOR_BOOT_SIZE - 1,
  122. };
  123. static struct platform_device dns323_nor_flash = {
  124. .name = "physmap-flash",
  125. .id = 0,
  126. .dev = {
  127. .platform_data = &dns323_nor_flash_data,
  128. },
  129. .resource = &dns323_nor_flash_resource,
  130. .num_resources = 1,
  131. };
  132. /****************************************************************************
  133. * Ethernet
  134. */
  135. static struct mv643xx_eth_platform_data dns323_eth_data = {
  136. .phy_addr = MV643XX_ETH_PHY_ADDR(8),
  137. };
  138. /* dns323_parse_hex_*() taken from tsx09-common.c; should a common copy of these
  139. * functions be kept somewhere?
  140. */
  141. static int __init dns323_parse_hex_nibble(char n)
  142. {
  143. if (n >= '0' && n <= '9')
  144. return n - '0';
  145. if (n >= 'A' && n <= 'F')
  146. return n - 'A' + 10;
  147. if (n >= 'a' && n <= 'f')
  148. return n - 'a' + 10;
  149. return -1;
  150. }
  151. static int __init dns323_parse_hex_byte(const char *b)
  152. {
  153. int hi;
  154. int lo;
  155. hi = dns323_parse_hex_nibble(b[0]);
  156. lo = dns323_parse_hex_nibble(b[1]);
  157. if (hi < 0 || lo < 0)
  158. return -1;
  159. return (hi << 4) | lo;
  160. }
  161. static int __init dns323_read_mac_addr(void)
  162. {
  163. u_int8_t addr[6];
  164. int i;
  165. char *mac_page;
  166. /* MAC address is stored as a regular ol' string in /dev/mtdblock4
  167. * (0x007d0000-0x00800000) starting at offset 196480 (0x2ff80).
  168. */
  169. mac_page = ioremap(DNS323_NOR_BOOT_BASE + 0x7d0000 + 196480, 1024);
  170. if (!mac_page)
  171. return -ENOMEM;
  172. /* Sanity check the string we're looking at */
  173. for (i = 0; i < 5; i++) {
  174. if (*(mac_page + (i * 3) + 2) != ':') {
  175. goto error_fail;
  176. }
  177. }
  178. for (i = 0; i < 6; i++) {
  179. int byte;
  180. byte = dns323_parse_hex_byte(mac_page + (i * 3));
  181. if (byte < 0) {
  182. goto error_fail;
  183. }
  184. addr[i] = byte;
  185. }
  186. iounmap(mac_page);
  187. printk("DNS323: Found ethernet MAC address: ");
  188. for (i = 0; i < 6; i++)
  189. printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
  190. memcpy(dns323_eth_data.mac_addr, addr, 6);
  191. return 0;
  192. error_fail:
  193. iounmap(mac_page);
  194. return -EINVAL;
  195. }
  196. /****************************************************************************
  197. * GPIO LEDs (simple - doesn't use hardware blinking support)
  198. */
  199. static struct gpio_led dns323_leds[] = {
  200. {
  201. .name = "power:blue",
  202. .gpio = DNS323_GPIO_LED_POWER,
  203. .default_state = LEDS_GPIO_DEFSTATE_ON,
  204. }, {
  205. .name = "right:amber",
  206. .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
  207. .active_low = 1,
  208. }, {
  209. .name = "left:amber",
  210. .gpio = DNS323_GPIO_LED_LEFT_AMBER,
  211. .active_low = 1,
  212. },
  213. };
  214. static struct gpio_led_platform_data dns323_led_data = {
  215. .num_leds = ARRAY_SIZE(dns323_leds),
  216. .leds = dns323_leds,
  217. };
  218. static struct platform_device dns323_gpio_leds = {
  219. .name = "leds-gpio",
  220. .id = -1,
  221. .dev = {
  222. .platform_data = &dns323_led_data,
  223. },
  224. };
  225. /****************************************************************************
  226. * GPIO Attached Keys
  227. */
  228. static struct gpio_keys_button dns323_buttons[] = {
  229. {
  230. .code = KEY_RESTART,
  231. .gpio = DNS323_GPIO_KEY_RESET,
  232. .desc = "Reset Button",
  233. .active_low = 1,
  234. }, {
  235. .code = KEY_POWER,
  236. .gpio = DNS323_GPIO_KEY_POWER,
  237. .desc = "Power Button",
  238. .active_low = 1,
  239. },
  240. };
  241. static struct gpio_keys_platform_data dns323_button_data = {
  242. .buttons = dns323_buttons,
  243. .nbuttons = ARRAY_SIZE(dns323_buttons),
  244. };
  245. static struct platform_device dns323_button_device = {
  246. .name = "gpio-keys",
  247. .id = -1,
  248. .num_resources = 0,
  249. .dev = {
  250. .platform_data = &dns323_button_data,
  251. },
  252. };
  253. /*****************************************************************************
  254. * SATA
  255. */
  256. static struct mv_sata_platform_data dns323_sata_data = {
  257. .n_ports = 2,
  258. };
  259. /****************************************************************************
  260. * General Setup
  261. */
  262. static struct orion5x_mpp_mode dns323_mv88f5181_mpp_modes[] __initdata = {
  263. { 0, MPP_PCIE_RST_OUTn },
  264. { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
  265. { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
  266. { 3, MPP_UNUSED },
  267. { 4, MPP_GPIO }, /* power button LED */
  268. { 5, MPP_GPIO }, /* power button LED */
  269. { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
  270. { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
  271. { 8, MPP_GPIO }, /* triggers power off */
  272. { 9, MPP_GPIO }, /* power button switch */
  273. { 10, MPP_GPIO }, /* reset button switch */
  274. { 11, MPP_UNUSED },
  275. { 12, MPP_UNUSED },
  276. { 13, MPP_UNUSED },
  277. { 14, MPP_UNUSED },
  278. { 15, MPP_UNUSED },
  279. { 16, MPP_UNUSED },
  280. { 17, MPP_UNUSED },
  281. { 18, MPP_UNUSED },
  282. { 19, MPP_UNUSED },
  283. { -1 },
  284. };
  285. static struct orion5x_mpp_mode dns323_mv88f5182_mpp_modes[] __initdata = {
  286. { 0, MPP_UNUSED },
  287. { 1, MPP_GPIO }, /* right amber LED (sata ch0) */
  288. { 2, MPP_GPIO }, /* left amber LED (sata ch1) */
  289. { 3, MPP_GPIO }, /* system up flag */
  290. { 4, MPP_GPIO }, /* power button LED */
  291. { 5, MPP_GPIO }, /* power button LED */
  292. { 6, MPP_GPIO }, /* GMT G751-2f overtemp */
  293. { 7, MPP_GPIO }, /* M41T80 nIRQ/OUT/SQW */
  294. { 8, MPP_GPIO }, /* triggers power off */
  295. { 9, MPP_GPIO }, /* power button switch */
  296. { 10, MPP_GPIO }, /* reset button switch */
  297. { 11, MPP_UNUSED },
  298. { 12, MPP_SATA_LED },
  299. { 13, MPP_SATA_LED },
  300. { 14, MPP_SATA_LED },
  301. { 15, MPP_SATA_LED },
  302. { 16, MPP_UNUSED },
  303. { 17, MPP_UNUSED },
  304. { 18, MPP_UNUSED },
  305. { 19, MPP_UNUSED },
  306. { -1 },
  307. };
  308. /*
  309. * On the DNS-323 the following devices are attached via I2C:
  310. *
  311. * i2c addr | chip | description
  312. * 0x3e | GMT G760Af | fan speed PWM controller
  313. * 0x48 | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
  314. * 0x68 | ST M41T80 | RTC w/ alarm
  315. */
  316. static struct i2c_board_info __initdata dns323_i2c_devices[] = {
  317. {
  318. I2C_BOARD_INFO("g760a", 0x3e),
  319. }, {
  320. I2C_BOARD_INFO("lm75", 0x48),
  321. }, {
  322. I2C_BOARD_INFO("m41t80", 0x68),
  323. },
  324. };
  325. /* DNS-323 rev. A specific power off method */
  326. static void dns323a_power_off(void)
  327. {
  328. pr_info("%s: triggering power-off...\n", __func__);
  329. gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
  330. }
  331. /* DNS-323 rev B specific power off method */
  332. static void dns323b_power_off(void)
  333. {
  334. pr_info("%s: triggering power-off...\n", __func__);
  335. /* Pin has to be changed to 1 and back to 0 to do actual power off. */
  336. gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
  337. mdelay(100);
  338. gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
  339. }
  340. static void __init dns323_init(void)
  341. {
  342. /* Setup basic Orion functions. Need to be called early. */
  343. orion5x_init();
  344. /* Just to be tricky, the 5182 has a completely different
  345. * set of MPP modes to the 5181.
  346. */
  347. if (dns323_dev_id() == MV88F5182_DEV_ID)
  348. orion5x_mpp_conf(dns323_mv88f5182_mpp_modes);
  349. else {
  350. orion5x_mpp_conf(dns323_mv88f5181_mpp_modes);
  351. writel(0, MPP_DEV_CTRL); /* DEV_D[31:16] */
  352. }
  353. /* setup flash mapping
  354. * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
  355. */
  356. orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
  357. platform_device_register(&dns323_nor_flash);
  358. platform_device_register(&dns323_gpio_leds);
  359. platform_device_register(&dns323_button_device);
  360. i2c_register_board_info(0, dns323_i2c_devices,
  361. ARRAY_SIZE(dns323_i2c_devices));
  362. /*
  363. * Configure peripherals.
  364. */
  365. if (dns323_read_mac_addr() < 0)
  366. printk("DNS323: Failed to read MAC address\n");
  367. orion5x_ehci0_init();
  368. orion5x_eth_init(&dns323_eth_data);
  369. orion5x_i2c_init();
  370. orion5x_uart0_init();
  371. /* The 5182 has its SATA controller on-chip, and needs its own little
  372. * init routine.
  373. */
  374. if (dns323_dev_id() == MV88F5182_DEV_ID)
  375. orion5x_sata_init(&dns323_sata_data);
  376. /* The 5182 has flag to indicate the system is up. Without this flag
  377. * set, power LED will flash and cannot be controlled via leds-gpio.
  378. */
  379. if (dns323_dev_id() == MV88F5182_DEV_ID)
  380. gpio_set_value(DNS323_GPIO_SYSTEM_UP, 1);
  381. /* Register dns323 specific power-off method */
  382. if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
  383. gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
  384. pr_err("DNS323: failed to setup power-off GPIO\n");
  385. if (dns323_dev_id() == MV88F5182_DEV_ID)
  386. pm_power_off = dns323b_power_off;
  387. else
  388. pm_power_off = dns323a_power_off;
  389. }
  390. /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
  391. MACHINE_START(DNS323, "D-Link DNS-323")
  392. /* Maintainer: Herbert Valerio Riedel <hvr@gnu.org> */
  393. .phys_io = ORION5X_REGS_PHYS_BASE,
  394. .io_pg_offst = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
  395. .boot_params = 0x00000100,
  396. .init_machine = dns323_init,
  397. .map_io = orion5x_map_io,
  398. .init_irq = orion5x_init_irq,
  399. .timer = &orion5x_timer,
  400. .fixup = tag_fixup_mem32,
  401. MACHINE_END