dns323-setup.c 12 KB

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