dns323-setup.c 11 KB

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