dsmg600-setup.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. #define DSMG600_SDA_PIN 5
  36. #define DSMG600_SCL_PIN 4
  37. /* DSM-G600 Timer Setting */
  38. #define DSMG600_FREQ 66000000
  39. /* Buttons */
  40. #define DSMG600_PB_GPIO 15 /* power button */
  41. #define DSMG600_RB_GPIO 3 /* reset button */
  42. /* Power control */
  43. #define DSMG600_PO_GPIO 2 /* power off */
  44. /* LEDs */
  45. #define DSMG600_LED_PWR_GPIO 0
  46. #define DSMG600_LED_WLAN_GPIO 14
  47. static struct flash_platform_data dsmg600_flash_data = {
  48. .map_name = "cfi_probe",
  49. .width = 2,
  50. };
  51. static struct resource dsmg600_flash_resource = {
  52. .flags = IORESOURCE_MEM,
  53. };
  54. static struct platform_device dsmg600_flash = {
  55. .name = "IXP4XX-Flash",
  56. .id = 0,
  57. .dev.platform_data = &dsmg600_flash_data,
  58. .num_resources = 1,
  59. .resource = &dsmg600_flash_resource,
  60. };
  61. static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = {
  62. .dev_id = "i2c-gpio.0",
  63. .table = {
  64. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN,
  65. NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  66. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN,
  67. NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  68. },
  69. };
  70. static struct platform_device dsmg600_i2c_gpio = {
  71. .name = "i2c-gpio",
  72. .id = 0,
  73. .dev = {
  74. .platform_data = NULL,
  75. },
  76. };
  77. static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
  78. {
  79. I2C_BOARD_INFO("pcf8563", 0x51),
  80. },
  81. };
  82. static struct gpio_led dsmg600_led_pins[] = {
  83. {
  84. .name = "dsmg600:green:power",
  85. .gpio = DSMG600_LED_PWR_GPIO,
  86. },
  87. {
  88. .name = "dsmg600:green:wlan",
  89. .gpio = DSMG600_LED_WLAN_GPIO,
  90. .active_low = true,
  91. },
  92. };
  93. static struct gpio_led_platform_data dsmg600_led_data = {
  94. .num_leds = ARRAY_SIZE(dsmg600_led_pins),
  95. .leds = dsmg600_led_pins,
  96. };
  97. static struct platform_device dsmg600_leds = {
  98. .name = "leds-gpio",
  99. .id = -1,
  100. .dev.platform_data = &dsmg600_led_data,
  101. };
  102. static struct resource dsmg600_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 dsmg600_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 dsmg600_uart = {
  136. .name = "serial8250",
  137. .id = PLAT8250_DEV_PLATFORM,
  138. .dev.platform_data = dsmg600_uart_data,
  139. .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
  140. .resource = dsmg600_uart_resources,
  141. };
  142. static struct platform_device *dsmg600_devices[] __initdata = {
  143. &dsmg600_i2c_gpio,
  144. &dsmg600_flash,
  145. &dsmg600_leds,
  146. };
  147. static void dsmg600_power_off(void)
  148. {
  149. /* enable the pwr cntl and drive it high */
  150. gpio_direction_output(DSMG600_PO_GPIO, 1);
  151. }
  152. /* This is used to make sure the power-button pusher is serious. The button
  153. * must be held until the value of this counter reaches zero.
  154. */
  155. static int power_button_countdown;
  156. /* Must hold the button down for at least this many counts to be processed */
  157. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  158. static void dsmg600_power_handler(struct timer_list *unused);
  159. static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler);
  160. static void dsmg600_power_handler(struct timer_list *unused)
  161. {
  162. /* This routine is called twice per second to check the
  163. * state of the power button.
  164. */
  165. if (gpio_get_value(DSMG600_PB_GPIO)) {
  166. /* IO Pin is 1 (button pushed) */
  167. if (power_button_countdown > 0)
  168. power_button_countdown--;
  169. } else {
  170. /* Done on button release, to allow for auto-power-on mods. */
  171. if (power_button_countdown == 0) {
  172. /* Signal init to do the ctrlaltdel action,
  173. * this will bypass init if it hasn't started
  174. * and do a kernel_restart.
  175. */
  176. ctrl_alt_del();
  177. /* Change the state of the power LED to "blink" */
  178. gpio_set_value(DSMG600_LED_PWR_GPIO, 0);
  179. } else {
  180. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  181. }
  182. }
  183. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  184. }
  185. static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
  186. {
  187. /* This is the paper-clip reset, it shuts the machine down directly. */
  188. machine_power_off();
  189. return IRQ_HANDLED;
  190. }
  191. static void __init dsmg600_timer_init(void)
  192. {
  193. /* The xtal on this machine is non-standard. */
  194. ixp4xx_timer_freq = DSMG600_FREQ;
  195. /* Call standard timer_init function. */
  196. ixp4xx_timer_init();
  197. }
  198. static int __init dsmg600_gpio_init(void)
  199. {
  200. if (!machine_is_dsmg600())
  201. return 0;
  202. gpio_request(DSMG600_RB_GPIO, "reset button");
  203. if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
  204. IRQF_TRIGGER_LOW, "DSM-G600 reset button", NULL) < 0) {
  205. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  206. gpio_to_irq(DSMG600_RB_GPIO));
  207. }
  208. /*
  209. * The power button on the D-Link DSM-G600 is on GPIO 15, but
  210. * it cannot handle interrupts on that GPIO line. So we'll
  211. * have to poll it with a kernel timer.
  212. */
  213. /* Make sure that the power button GPIO is set up as an input */
  214. gpio_request(DSMG600_PB_GPIO, "power button");
  215. gpio_direction_input(DSMG600_PB_GPIO);
  216. /* Request poweroff GPIO line */
  217. gpio_request(DSMG600_PO_GPIO, "power off button");
  218. /* Set the initial value for the power button IRQ handler */
  219. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  220. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  221. return 0;
  222. }
  223. device_initcall(dsmg600_gpio_init);
  224. static void __init dsmg600_init(void)
  225. {
  226. ixp4xx_sys_init();
  227. /* Make sure that GPIO14 and GPIO15 are not used as clocks */
  228. *IXP4XX_GPIO_GPCLKR = 0;
  229. dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  230. dsmg600_flash_resource.end =
  231. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  232. gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table);
  233. i2c_register_board_info(0, dsmg600_i2c_board_info,
  234. ARRAY_SIZE(dsmg600_i2c_board_info));
  235. /* The UART is required on the DSM-G600 (Redboot cannot use the
  236. * NIC) -- do it here so that it does *not* get removed if
  237. * platform_add_devices fails!
  238. */
  239. (void)platform_device_register(&dsmg600_uart);
  240. platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
  241. pm_power_off = dsmg600_power_off;
  242. }
  243. MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
  244. /* Maintainer: www.nslu2-linux.org */
  245. .atag_offset = 0x100,
  246. .map_io = ixp4xx_map_io,
  247. .init_early = ixp4xx_init_early,
  248. .init_irq = ixp4xx_init_irq,
  249. .init_time = dsmg600_timer_init,
  250. .init_machine = dsmg600_init,
  251. #if defined(CONFIG_PCI)
  252. .dma_zone_size = SZ_64M,
  253. #endif
  254. .restart = ixp4xx_restart,
  255. MACHINE_END