nas100d-setup.c 8.4 KB

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