dsmg600-setup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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/irq.h>
  20. #include <linux/jiffies.h>
  21. #include <linux/timer.h>
  22. #include <linux/serial.h>
  23. #include <linux/serial_8250.h>
  24. #include <linux/leds.h>
  25. #include <linux/reboot.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c-gpio.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/flash.h>
  31. #include <asm/mach/time.h>
  32. #include <asm/gpio.h>
  33. #define DSMG600_SDA_PIN 5
  34. #define DSMG600_SCL_PIN 4
  35. /* DSM-G600 Timer Setting */
  36. #define DSMG600_FREQ 66000000
  37. /* Buttons */
  38. #define DSMG600_PB_GPIO 15 /* power button */
  39. #define DSMG600_RB_GPIO 3 /* reset button */
  40. /* Power control */
  41. #define DSMG600_PO_GPIO 2 /* power off */
  42. /* LEDs */
  43. #define DSMG600_LED_PWR_GPIO 0
  44. #define DSMG600_LED_WLAN_GPIO 14
  45. static struct flash_platform_data dsmg600_flash_data = {
  46. .map_name = "cfi_probe",
  47. .width = 2,
  48. };
  49. static struct resource dsmg600_flash_resource = {
  50. .flags = IORESOURCE_MEM,
  51. };
  52. static struct platform_device dsmg600_flash = {
  53. .name = "IXP4XX-Flash",
  54. .id = 0,
  55. .dev.platform_data = &dsmg600_flash_data,
  56. .num_resources = 1,
  57. .resource = &dsmg600_flash_resource,
  58. };
  59. static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
  60. .sda_pin = DSMG600_SDA_PIN,
  61. .scl_pin = DSMG600_SCL_PIN,
  62. };
  63. static struct platform_device dsmg600_i2c_gpio = {
  64. .name = "i2c-gpio",
  65. .id = 0,
  66. .dev = {
  67. .platform_data = &dsmg600_i2c_gpio_data,
  68. },
  69. };
  70. static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
  71. {
  72. I2C_BOARD_INFO("pcf8563", 0x51),
  73. },
  74. };
  75. static struct gpio_led dsmg600_led_pins[] = {
  76. {
  77. .name = "dsmg600:green:power",
  78. .gpio = DSMG600_LED_PWR_GPIO,
  79. },
  80. {
  81. .name = "dsmg600:green:wlan",
  82. .gpio = DSMG600_LED_WLAN_GPIO,
  83. .active_low = true,
  84. },
  85. };
  86. static struct gpio_led_platform_data dsmg600_led_data = {
  87. .num_leds = ARRAY_SIZE(dsmg600_led_pins),
  88. .leds = dsmg600_led_pins,
  89. };
  90. static struct platform_device dsmg600_leds = {
  91. .name = "leds-gpio",
  92. .id = -1,
  93. .dev.platform_data = &dsmg600_led_data,
  94. };
  95. static struct resource dsmg600_uart_resources[] = {
  96. {
  97. .start = IXP4XX_UART1_BASE_PHYS,
  98. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  99. .flags = IORESOURCE_MEM,
  100. },
  101. {
  102. .start = IXP4XX_UART2_BASE_PHYS,
  103. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  104. .flags = IORESOURCE_MEM,
  105. }
  106. };
  107. static struct plat_serial8250_port dsmg600_uart_data[] = {
  108. {
  109. .mapbase = IXP4XX_UART1_BASE_PHYS,
  110. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  111. .irq = IRQ_IXP4XX_UART1,
  112. .flags = UPF_BOOT_AUTOCONF,
  113. .iotype = UPIO_MEM,
  114. .regshift = 2,
  115. .uartclk = IXP4XX_UART_XTAL,
  116. },
  117. {
  118. .mapbase = IXP4XX_UART2_BASE_PHYS,
  119. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  120. .irq = IRQ_IXP4XX_UART2,
  121. .flags = UPF_BOOT_AUTOCONF,
  122. .iotype = UPIO_MEM,
  123. .regshift = 2,
  124. .uartclk = IXP4XX_UART_XTAL,
  125. },
  126. { }
  127. };
  128. static struct platform_device dsmg600_uart = {
  129. .name = "serial8250",
  130. .id = PLAT8250_DEV_PLATFORM,
  131. .dev.platform_data = dsmg600_uart_data,
  132. .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
  133. .resource = dsmg600_uart_resources,
  134. };
  135. static struct platform_device *dsmg600_devices[] __initdata = {
  136. &dsmg600_i2c_gpio,
  137. &dsmg600_flash,
  138. &dsmg600_leds,
  139. };
  140. static void dsmg600_power_off(void)
  141. {
  142. /* enable the pwr cntl gpio */
  143. gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
  144. /* poweroff */
  145. gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
  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_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
  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 struct sys_timer dsmg600_timer = {
  194. .init = dsmg600_timer_init,
  195. };
  196. static void __init dsmg600_init(void)
  197. {
  198. ixp4xx_sys_init();
  199. /* Make sure that GPIO14 and GPIO15 are not used as clocks */
  200. *IXP4XX_GPIO_GPCLKR = 0;
  201. dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  202. dsmg600_flash_resource.end =
  203. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  204. i2c_register_board_info(0, dsmg600_i2c_board_info,
  205. ARRAY_SIZE(dsmg600_i2c_board_info));
  206. /* The UART is required on the DSM-G600 (Redboot cannot use the
  207. * NIC) -- do it here so that it does *not* get removed if
  208. * platform_add_devices fails!
  209. */
  210. (void)platform_device_register(&dsmg600_uart);
  211. platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
  212. pm_power_off = dsmg600_power_off;
  213. if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
  214. IRQF_DISABLED | IRQF_TRIGGER_LOW,
  215. "DSM-G600 reset button", NULL) < 0) {
  216. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  217. gpio_to_irq(DSMG600_RB_GPIO));
  218. }
  219. /* The power button on the D-Link DSM-G600 is on GPIO 15, but
  220. * it cannot handle interrupts on that GPIO line. So we'll
  221. * have to poll it with a kernel timer.
  222. */
  223. /* Make sure that the power button GPIO is set up as an input */
  224. gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
  225. /* Set the initial value for the power button IRQ handler */
  226. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  227. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  228. }
  229. MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
  230. /* Maintainer: www.nslu2-linux.org */
  231. .boot_params = 0x00000100,
  232. .map_io = ixp4xx_map_io,
  233. .init_irq = ixp4xx_init_irq,
  234. .timer = &dsmg600_timer,
  235. .init_machine = dsmg600_init,
  236. MACHINE_END