dsmg600-setup.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * DSM-G600 board-setup
  4. *
  5. * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
  6. * Copyright (C) 2006 Tower Technologies
  7. *
  8. * based on ixdp425-setup.c:
  9. * Copyright (C) 2003-2004 MontaVista Software, Inc.
  10. * based on nslu2-power.c:
  11. * Copyright (C) 2005 Tower Technologies
  12. * based on nslu2-io.c:
  13. * Copyright (C) 2004 Karen Spearel
  14. *
  15. * Author: Alessandro Zummo <a.zummo@towertech.it>
  16. * Author: Michael Westerhof <mwester@dls.net>
  17. * Author: Rod Whitby <rod@whitby.id.au>
  18. * Maintainers: http://www.nslu2-linux.org/
  19. */
  20. #include <linux/gpio.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/gpio/machine.h>
  30. #include <mach/hardware.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/flash.h>
  34. #include <asm/mach/time.h>
  35. #include "irqs.h"
  36. #define DSMG600_SDA_PIN 5
  37. #define DSMG600_SCL_PIN 4
  38. /* DSM-G600 Timer Setting */
  39. #define DSMG600_FREQ 66000000
  40. /* Buttons */
  41. #define DSMG600_PB_GPIO 15 /* power button */
  42. #define DSMG600_RB_GPIO 3 /* reset button */
  43. /* Power control */
  44. #define DSMG600_PO_GPIO 2 /* power off */
  45. /* LEDs */
  46. #define DSMG600_LED_PWR_GPIO 0
  47. #define DSMG600_LED_WLAN_GPIO 14
  48. static struct flash_platform_data dsmg600_flash_data = {
  49. .map_name = "cfi_probe",
  50. .width = 2,
  51. };
  52. static struct resource dsmg600_flash_resource = {
  53. .flags = IORESOURCE_MEM,
  54. };
  55. static struct platform_device dsmg600_flash = {
  56. .name = "IXP4XX-Flash",
  57. .id = 0,
  58. .dev.platform_data = &dsmg600_flash_data,
  59. .num_resources = 1,
  60. .resource = &dsmg600_flash_resource,
  61. };
  62. static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = {
  63. .dev_id = "i2c-gpio.0",
  64. .table = {
  65. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN,
  66. NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  67. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN,
  68. NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  69. },
  70. };
  71. static struct platform_device dsmg600_i2c_gpio = {
  72. .name = "i2c-gpio",
  73. .id = 0,
  74. .dev = {
  75. .platform_data = NULL,
  76. },
  77. };
  78. static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
  79. {
  80. I2C_BOARD_INFO("pcf8563", 0x51),
  81. },
  82. };
  83. static struct gpio_led dsmg600_led_pins[] = {
  84. {
  85. .name = "dsmg600:green:power",
  86. .gpio = DSMG600_LED_PWR_GPIO,
  87. },
  88. {
  89. .name = "dsmg600:green:wlan",
  90. .gpio = DSMG600_LED_WLAN_GPIO,
  91. .active_low = true,
  92. },
  93. };
  94. static struct gpio_led_platform_data dsmg600_led_data = {
  95. .num_leds = ARRAY_SIZE(dsmg600_led_pins),
  96. .leds = dsmg600_led_pins,
  97. };
  98. static struct platform_device dsmg600_leds = {
  99. .name = "leds-gpio",
  100. .id = -1,
  101. .dev.platform_data = &dsmg600_led_data,
  102. };
  103. static struct resource dsmg600_uart_resources[] = {
  104. {
  105. .start = IXP4XX_UART1_BASE_PHYS,
  106. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  107. .flags = IORESOURCE_MEM,
  108. },
  109. {
  110. .start = IXP4XX_UART2_BASE_PHYS,
  111. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  112. .flags = IORESOURCE_MEM,
  113. }
  114. };
  115. static struct plat_serial8250_port dsmg600_uart_data[] = {
  116. {
  117. .mapbase = IXP4XX_UART1_BASE_PHYS,
  118. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  119. .irq = IRQ_IXP4XX_UART1,
  120. .flags = UPF_BOOT_AUTOCONF,
  121. .iotype = UPIO_MEM,
  122. .regshift = 2,
  123. .uartclk = IXP4XX_UART_XTAL,
  124. },
  125. {
  126. .mapbase = IXP4XX_UART2_BASE_PHYS,
  127. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  128. .irq = IRQ_IXP4XX_UART2,
  129. .flags = UPF_BOOT_AUTOCONF,
  130. .iotype = UPIO_MEM,
  131. .regshift = 2,
  132. .uartclk = IXP4XX_UART_XTAL,
  133. },
  134. { }
  135. };
  136. static struct platform_device dsmg600_uart = {
  137. .name = "serial8250",
  138. .id = PLAT8250_DEV_PLATFORM,
  139. .dev.platform_data = dsmg600_uart_data,
  140. .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
  141. .resource = dsmg600_uart_resources,
  142. };
  143. static struct platform_device *dsmg600_devices[] __initdata = {
  144. &dsmg600_i2c_gpio,
  145. &dsmg600_flash,
  146. &dsmg600_leds,
  147. };
  148. static void dsmg600_power_off(void)
  149. {
  150. /* enable the pwr cntl and drive it high */
  151. gpio_direction_output(DSMG600_PO_GPIO, 1);
  152. }
  153. /* This is used to make sure the power-button pusher is serious. The button
  154. * must be held until the value of this counter reaches zero.
  155. */
  156. static int power_button_countdown;
  157. /* Must hold the button down for at least this many counts to be processed */
  158. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  159. static void dsmg600_power_handler(struct timer_list *unused);
  160. static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler);
  161. static void dsmg600_power_handler(struct timer_list *unused)
  162. {
  163. /* This routine is called twice per second to check the
  164. * state of the power button.
  165. */
  166. if (gpio_get_value(DSMG600_PB_GPIO)) {
  167. /* IO Pin is 1 (button pushed) */
  168. if (power_button_countdown > 0)
  169. power_button_countdown--;
  170. } else {
  171. /* Done on button release, to allow for auto-power-on mods. */
  172. if (power_button_countdown == 0) {
  173. /* Signal init to do the ctrlaltdel action,
  174. * this will bypass init if it hasn't started
  175. * and do a kernel_restart.
  176. */
  177. ctrl_alt_del();
  178. /* Change the state of the power LED to "blink" */
  179. gpio_set_value(DSMG600_LED_PWR_GPIO, 0);
  180. } else {
  181. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  182. }
  183. }
  184. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  185. }
  186. static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
  187. {
  188. /* This is the paper-clip reset, it shuts the machine down directly. */
  189. machine_power_off();
  190. return IRQ_HANDLED;
  191. }
  192. static void __init dsmg600_timer_init(void)
  193. {
  194. /* The xtal on this machine is non-standard. */
  195. ixp4xx_timer_freq = DSMG600_FREQ;
  196. /* Call standard timer_init function. */
  197. ixp4xx_timer_init();
  198. }
  199. static int __init dsmg600_gpio_init(void)
  200. {
  201. if (!machine_is_dsmg600())
  202. return 0;
  203. gpio_request(DSMG600_RB_GPIO, "reset button");
  204. if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
  205. IRQF_TRIGGER_LOW, "DSM-G600 reset button", NULL) < 0) {
  206. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  207. gpio_to_irq(DSMG600_RB_GPIO));
  208. }
  209. /*
  210. * The power button on the D-Link DSM-G600 is on GPIO 15, but
  211. * it cannot handle interrupts on that GPIO line. So we'll
  212. * have to poll it with a kernel timer.
  213. */
  214. /* Make sure that the power button GPIO is set up as an input */
  215. gpio_request(DSMG600_PB_GPIO, "power button");
  216. gpio_direction_input(DSMG600_PB_GPIO);
  217. /* Request poweroff GPIO line */
  218. gpio_request(DSMG600_PO_GPIO, "power off button");
  219. /* Set the initial value for the power button IRQ handler */
  220. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  221. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  222. return 0;
  223. }
  224. device_initcall(dsmg600_gpio_init);
  225. static void __init dsmg600_init(void)
  226. {
  227. ixp4xx_sys_init();
  228. dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  229. dsmg600_flash_resource.end =
  230. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  231. gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table);
  232. i2c_register_board_info(0, dsmg600_i2c_board_info,
  233. ARRAY_SIZE(dsmg600_i2c_board_info));
  234. /* The UART is required on the DSM-G600 (Redboot cannot use the
  235. * NIC) -- do it here so that it does *not* get removed if
  236. * platform_add_devices fails!
  237. */
  238. (void)platform_device_register(&dsmg600_uart);
  239. platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
  240. pm_power_off = dsmg600_power_off;
  241. }
  242. MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
  243. /* Maintainer: www.nslu2-linux.org */
  244. .atag_offset = 0x100,
  245. .map_io = ixp4xx_map_io,
  246. .init_early = ixp4xx_init_early,
  247. .init_irq = ixp4xx_init_irq,
  248. .init_time = dsmg600_timer_init,
  249. .init_machine = dsmg600_init,
  250. #if defined(CONFIG_PCI)
  251. .dma_zone_size = SZ_64M,
  252. #endif
  253. .restart = ixp4xx_restart,
  254. MACHINE_END