dsmg600-setup.c 7.4 KB

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