nas100d-setup.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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/if_ether.h>
  21. #include <linux/irq.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/timer.h>
  24. #include <linux/serial.h>
  25. #include <linux/serial_8250.h>
  26. #include <linux/leds.h>
  27. #include <linux/reboot.h>
  28. #include <linux/i2c.h>
  29. #include <linux/i2c-gpio.h>
  30. #include <linux/io.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/flash.h>
  34. #include <asm/gpio.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 */
  167. gpio_line_config(NAS100D_PO_GPIO, IXP4XX_GPIO_OUT);
  168. /* do the deed */
  169. gpio_line_set(NAS100D_PO_GPIO, IXP4XX_GPIO_HIGH);
  170. }
  171. /* This is used to make sure the power-button pusher is serious. The button
  172. * must be held until the value of this counter reaches zero.
  173. */
  174. static int power_button_countdown;
  175. /* Must hold the button down for at least this many counts to be processed */
  176. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  177. static void nas100d_power_handler(unsigned long data);
  178. static DEFINE_TIMER(nas100d_power_timer, nas100d_power_handler, 0, 0);
  179. static void nas100d_power_handler(unsigned long data)
  180. {
  181. /* This routine is called twice per second to check the
  182. * state of the power button.
  183. */
  184. if (gpio_get_value(NAS100D_PB_GPIO)) {
  185. /* IO Pin is 1 (button pushed) */
  186. if (power_button_countdown > 0)
  187. power_button_countdown--;
  188. } else {
  189. /* Done on button release, to allow for auto-power-on mods. */
  190. if (power_button_countdown == 0) {
  191. /* Signal init to do the ctrlaltdel action,
  192. * this will bypass init if it hasn't started
  193. * and do a kernel_restart.
  194. */
  195. ctrl_alt_del();
  196. /* Change the state of the power LED to "blink" */
  197. gpio_line_set(NAS100D_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
  198. } else {
  199. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  200. }
  201. }
  202. mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
  203. }
  204. static irqreturn_t nas100d_reset_handler(int irq, void *dev_id)
  205. {
  206. /* This is the paper-clip reset, it shuts the machine down directly. */
  207. machine_power_off();
  208. return IRQ_HANDLED;
  209. }
  210. static void __init nas100d_init(void)
  211. {
  212. uint8_t __iomem *f;
  213. int i;
  214. ixp4xx_sys_init();
  215. /* gpio 14 and 15 are _not_ clocks */
  216. *IXP4XX_GPIO_GPCLKR = 0;
  217. nas100d_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  218. nas100d_flash_resource.end =
  219. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  220. i2c_register_board_info(0, nas100d_i2c_board_info,
  221. ARRAY_SIZE(nas100d_i2c_board_info));
  222. /*
  223. * This is only useful on a modified machine, but it is valuable
  224. * to have it first in order to see debug messages, and so that
  225. * it does *not* get removed if platform_add_devices fails!
  226. */
  227. (void)platform_device_register(&nas100d_uart);
  228. platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
  229. pm_power_off = nas100d_power_off;
  230. if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
  231. IRQF_DISABLED | IRQF_TRIGGER_LOW,
  232. "NAS100D reset button", NULL) < 0) {
  233. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  234. gpio_to_irq(NAS100D_RB_GPIO));
  235. }
  236. /* The power button on the Iomega NAS100d is on GPIO 14, but
  237. * it cannot handle interrupts on that GPIO line. So we'll
  238. * have to poll it with a kernel timer.
  239. */
  240. /* Make sure that the power button GPIO is set up as an input */
  241. gpio_line_config(NAS100D_PB_GPIO, IXP4XX_GPIO_IN);
  242. /* Set the initial value for the power button IRQ handler */
  243. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  244. mod_timer(&nas100d_power_timer, jiffies + msecs_to_jiffies(500));
  245. /*
  246. * Map in a portion of the flash and read the MAC address.
  247. * Since it is stored in BE in the flash itself, we need to
  248. * byteswap it if we're in LE mode.
  249. */
  250. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x1000000);
  251. if (f) {
  252. for (i = 0; i < 6; i++)
  253. #ifdef __ARMEB__
  254. nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + i);
  255. #else
  256. nas100d_plat_eth[0].hwaddr[i] = readb(f + 0xFC0FD8 + (i^3));
  257. #endif
  258. iounmap(f);
  259. }
  260. printk(KERN_INFO "NAS100D: Using MAC address %pM for port 0\n",
  261. nas100d_plat_eth[0].hwaddr);
  262. }
  263. MACHINE_START(NAS100D, "Iomega NAS 100d")
  264. /* Maintainer: www.nslu2-linux.org */
  265. .boot_params = 0x00000100,
  266. .map_io = ixp4xx_map_io,
  267. .init_irq = ixp4xx_init_irq,
  268. .timer = &ixp4xx_timer,
  269. .init_machine = nas100d_init,
  270. MACHINE_END