nas100d-setup.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * arch/arm/mach-ixp4xx/nas100d-setup.c
  3. *
  4. * NAS 100d board-setup
  5. *
  6. * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
  7. *
  8. * based on ixdp425-setup.c:
  9. * Copyright (C) 2003-2004 MontaVista Software, Inc.
  10. * based on nas100d-power.c:
  11. * Copyright (C) 2005 Tower Technologies
  12. * based on nas100d-io.c
  13. * Copyright (C) 2004 Karen Spearel
  14. *
  15. * Author: Alessandro Zummo <a.zummo@towertech.it>
  16. * Author: Rod Whitby <rod@whitby.id.au>
  17. * Maintainers: http://www.nslu2-linux.org/
  18. *
  19. */
  20. #include <linux/gpio.h>
  21. #include <linux/if_ether.h>
  22. #include <linux/irq.h>
  23. #include <linux/jiffies.h>
  24. #include <linux/timer.h>
  25. #include <linux/serial.h>
  26. #include <linux/serial_8250.h>
  27. #include <linux/leds.h>
  28. #include <linux/reboot.h>
  29. #include <linux/i2c.h>
  30. #include <linux/i2c-gpio.h>
  31. #include <linux/io.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/flash.h>
  35. #define NAS100D_SDA_PIN 5
  36. #define NAS100D_SCL_PIN 6
  37. /* Buttons */
  38. #define NAS100D_PB_GPIO 14 /* power button */
  39. #define NAS100D_RB_GPIO 4 /* reset button */
  40. /* Power control */
  41. #define NAS100D_PO_GPIO 12 /* power off */
  42. /* LEDs */
  43. #define NAS100D_LED_WLAN_GPIO 0
  44. #define NAS100D_LED_DISK_GPIO 3
  45. #define NAS100D_LED_PWR_GPIO 15
  46. static struct flash_platform_data nas100d_flash_data = {
  47. .map_name = "cfi_probe",
  48. .width = 2,
  49. };
  50. static struct resource nas100d_flash_resource = {
  51. .flags = IORESOURCE_MEM,
  52. };
  53. static struct platform_device nas100d_flash = {
  54. .name = "IXP4XX-Flash",
  55. .id = 0,
  56. .dev.platform_data = &nas100d_flash_data,
  57. .num_resources = 1,
  58. .resource = &nas100d_flash_resource,
  59. };
  60. static struct i2c_board_info __initdata nas100d_i2c_board_info [] = {
  61. {
  62. I2C_BOARD_INFO("pcf8563", 0x51),
  63. },
  64. };
  65. static struct gpio_led nas100d_led_pins[] = {
  66. {
  67. .name = "nas100d:green:wlan",
  68. .gpio = NAS100D_LED_WLAN_GPIO,
  69. .active_low = true,
  70. },
  71. {
  72. .name = "nas100d:blue:power", /* (off=flashing) */
  73. .gpio = NAS100D_LED_PWR_GPIO,
  74. .active_low = true,
  75. },
  76. {
  77. .name = "nas100d:yellow:disk",
  78. .gpio = NAS100D_LED_DISK_GPIO,
  79. .active_low = true,
  80. },
  81. };
  82. static struct gpio_led_platform_data nas100d_led_data = {
  83. .num_leds = ARRAY_SIZE(nas100d_led_pins),
  84. .leds = nas100d_led_pins,
  85. };
  86. static struct platform_device nas100d_leds = {
  87. .name = "leds-gpio",
  88. .id = -1,
  89. .dev.platform_data = &nas100d_led_data,
  90. };
  91. static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = {
  92. .sda_pin = NAS100D_SDA_PIN,
  93. .scl_pin = NAS100D_SCL_PIN,
  94. };
  95. static struct platform_device nas100d_i2c_gpio = {
  96. .name = "i2c-gpio",
  97. .id = 0,
  98. .dev = {
  99. .platform_data = &nas100d_i2c_gpio_data,
  100. },
  101. };
  102. static struct resource nas100d_uart_resources[] = {
  103. {
  104. .start = IXP4XX_UART1_BASE_PHYS,
  105. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  106. .flags = IORESOURCE_MEM,
  107. },
  108. {
  109. .start = IXP4XX_UART2_BASE_PHYS,
  110. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  111. .flags = IORESOURCE_MEM,
  112. }
  113. };
  114. static struct plat_serial8250_port nas100d_uart_data[] = {
  115. {
  116. .mapbase = IXP4XX_UART1_BASE_PHYS,
  117. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  118. .irq = IRQ_IXP4XX_UART1,
  119. .flags = UPF_BOOT_AUTOCONF,
  120. .iotype = UPIO_MEM,
  121. .regshift = 2,
  122. .uartclk = IXP4XX_UART_XTAL,
  123. },
  124. {
  125. .mapbase = IXP4XX_UART2_BASE_PHYS,
  126. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  127. .irq = IRQ_IXP4XX_UART2,
  128. .flags = UPF_BOOT_AUTOCONF,
  129. .iotype = UPIO_MEM,
  130. .regshift = 2,
  131. .uartclk = IXP4XX_UART_XTAL,
  132. },
  133. { }
  134. };
  135. static struct platform_device nas100d_uart = {
  136. .name = "serial8250",
  137. .id = PLAT8250_DEV_PLATFORM,
  138. .dev.platform_data = nas100d_uart_data,
  139. .num_resources = 2,
  140. .resource = nas100d_uart_resources,
  141. };
  142. /* Built-in 10/100 Ethernet MAC interfaces */
  143. static struct eth_plat_info nas100d_plat_eth[] = {
  144. {
  145. .phy = 0,
  146. .rxq = 3,
  147. .txreadyq = 20,
  148. }
  149. };
  150. static struct platform_device nas100d_eth[] = {
  151. {
  152. .name = "ixp4xx_eth",
  153. .id = IXP4XX_ETH_NPEB,
  154. .dev.platform_data = nas100d_plat_eth,
  155. }
  156. };
  157. static struct platform_device *nas100d_devices[] __initdata = {
  158. &nas100d_i2c_gpio,
  159. &nas100d_flash,
  160. &nas100d_leds,
  161. &nas100d_eth[0],
  162. };
  163. static void nas100d_power_off(void)
  164. {
  165. /* This causes the box to drop the power and go dead. */
  166. /* enable the pwr cntl gpio and assert power off */
  167. gpio_direction_output(NAS100D_PO_GPIO, 1);
  168. }
  169. /* This is used to make sure the power-button pusher is serious. The button
  170. * must be held until the value of this counter reaches zero.
  171. */
  172. static int power_button_countdown;
  173. /* Must hold the button down for at least this many counts to be processed */
  174. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  175. static void nas100d_power_handler(unsigned long data);
  176. static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
  177. static void nas100d_power_handler(unsigned long data)
  178. {
  179. /* This routine is called twice per second to check the
  180. * state of the power button.
  181. */
  182. if (gpio_get_value(NAS100D_PB_GPIO)) {
  183. /* IO Pin is 1 (button pushed) */
  184. if (power_button_countdown > 0)
  185. power_button_countdown--;
  186. } else {
  187. /* Done on button release, to allow for auto-power-on mods. */
  188. if (power_button_countdown == 0) {
  189. /* Signal init to do the ctrlaltdel action,
  190. * this will bypass init if it hasn't started
  191. * and do a kernel_restart.
  192. */
  193. ctrl_alt_del();
  194. /* Change the state of the power LED to "blink" */
  195. gpio_set_value(NAS100D_LED_PWR_GPIO, 0);
  196. } else {
  197. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  198. }
  199. }
  200. mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
  201. }
  202. static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
  203. {
  204. /* This is the paper-clip reset, it shuts the machine down directly. */
  205. machine_power_off();
  206. return IRQ_HANDLED;
  207. }
  208. static int __init nas100d_gpio_init(void)
  209. {
  210. if (!machine_is_nas100d())
  211. return 0;
  212. /*
  213. * The power button on the Iomega NAS100d is on GPIO 14, but
  214. * it cannot handle interrupts on that GPIO line. So we'll
  215. * have to poll it with a kernel timer.
  216. */
  217. /* Request the power off GPIO */
  218. gpio_request(NAS100D_PO_GPIO, "power off");
  219. /* Make sure that the power button GPIO is set up as an input */
  220. gpio_request(NAS100D_PB_GPIO, "power button");
  221. gpio_direction_input(NAS100D_PB_GPIO);
  222. /* Set the initial value for the power button IRQ handler */
  223. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  224. mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
  225. return 0;
  226. }
  227. device_initcall(nas100d_gpio_init);
  228. static void __init nas100d_init(void)
  229. {
  230. uint8_t __iomem *f;
  231. int i;
  232. ixp4xx_sys_init();
  233. /* gpio 14 and 15 are _not_ clocks */
  234. *IXP4XX_GPIO_GPCLKR = 0;
  235. nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  236. nas100d_flash_resource.end =
  237. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  238. i2c_register_board_info(0, nas100d_i2c_board_info,
  239. ARRAY_SIZE(nas100d_i2c_board_info));
  240. /*
  241. * This is only useful on a modified machine, but it is valuable
  242. * to have it first in order to see debug messages, and so that
  243. * it does *not* get removed if platform_add_devices fails!
  244. */
  245. (void)platform_device_register(&nas100d_uart);
  246. platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
  247. pm_power_off = nas100d_power_off;
  248. if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
  249. IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
  250. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  251. gpio_to_irq(NAS100D_RB_GPIO));
  252. }
  253. /*
  254. * Map in a portion of the flash and read the MAC address.
  255. * Since it is stored in BE in the flash itself, we need to
  256. * byteswap it if we're in LE mode.
  257. */
  258. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
  259. if (f) {
  260. for (i = 0; i < 6; i++)
  261. #ifdef __ARMEB__
  262. nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
  263. #else
  264. nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
  265. #endif
  266. iounmap(f);
  267. }
  268. printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",
  269. nas100d_plat_eth[0].hwaddr);
  270. }
  271. MACHINE_START(NAS100D, "Iomega NAS 100d")
  272. /* Maintainer: www.nslu2-linux.org */
  273. .atag_offset = 0x100,
  274. .map_io = ixp4xx_map_io,
  275. .init_early = ixp4xx_init_early,
  276. .init_irq = ixp4xx_init_irq,
  277. .init_time = ixp4xx_timer_init,
  278. .init_machine = nas100d_init,
  279. #if defined(CONFIG_PCI)
  280. .dma_zone_size = SZ_64M,
  281. #endif
  282. .restart = ixp4xx_restart,
  283. MACHINE_END