dsmg600-setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. static struct flash_platform_data dsmg600_flash_data = {
  34. .map_name = "cfi_probe",
  35. .width = 2,
  36. };
  37. static struct resource dsmg600_flash_resource = {
  38. .flags = IORESOURCE_MEM,
  39. };
  40. static struct platform_device dsmg600_flash = {
  41. .name = "IXP4XX-Flash",
  42. .id = 0,
  43. .dev.platform_data = &dsmg600_flash_data,
  44. .num_resources = 1,
  45. .resource = &dsmg600_flash_resource,
  46. };
  47. static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
  48. .sda_pin = DSMG600_SDA_PIN,
  49. .scl_pin = DSMG600_SCL_PIN,
  50. };
  51. static struct platform_device dsmg600_i2c_gpio = {
  52. .name = "i2c-gpio",
  53. .id = 0,
  54. .dev = {
  55. .platform_data = &dsmg600_i2c_gpio_data,
  56. },
  57. };
  58. static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
  59. {
  60. I2C_BOARD_INFO("pcf8563", 0x51),
  61. },
  62. };
  63. static struct gpio_led dsmg600_led_pins[] = {
  64. {
  65. .name = "dsmg600:green:power",
  66. .gpio = DSMG600_LED_PWR_GPIO,
  67. },
  68. {
  69. .name = "dsmg600:green:wlan",
  70. .gpio = DSMG600_LED_WLAN_GPIO,
  71. .active_low = true,
  72. },
  73. };
  74. static struct gpio_led_platform_data dsmg600_led_data = {
  75. .num_leds = ARRAY_SIZE(dsmg600_led_pins),
  76. .leds = dsmg600_led_pins,
  77. };
  78. static struct platform_device dsmg600_leds = {
  79. .name = "leds-gpio",
  80. .id = -1,
  81. .dev.platform_data = &dsmg600_led_data,
  82. };
  83. static struct resource dsmg600_uart_resources[] = {
  84. {
  85. .start = IXP4XX_UART1_BASE_PHYS,
  86. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. {
  90. .start = IXP4XX_UART2_BASE_PHYS,
  91. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  92. .flags = IORESOURCE_MEM,
  93. }
  94. };
  95. static struct plat_serial8250_port dsmg600_uart_data[] = {
  96. {
  97. .mapbase = IXP4XX_UART1_BASE_PHYS,
  98. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  99. .irq = IRQ_IXP4XX_UART1,
  100. .flags = UPF_BOOT_AUTOCONF,
  101. .iotype = UPIO_MEM,
  102. .regshift = 2,
  103. .uartclk = IXP4XX_UART_XTAL,
  104. },
  105. {
  106. .mapbase = IXP4XX_UART2_BASE_PHYS,
  107. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  108. .irq = IRQ_IXP4XX_UART2,
  109. .flags = UPF_BOOT_AUTOCONF,
  110. .iotype = UPIO_MEM,
  111. .regshift = 2,
  112. .uartclk = IXP4XX_UART_XTAL,
  113. },
  114. { }
  115. };
  116. static struct platform_device dsmg600_uart = {
  117. .name = "serial8250",
  118. .id = PLAT8250_DEV_PLATFORM,
  119. .dev.platform_data = dsmg600_uart_data,
  120. .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
  121. .resource = dsmg600_uart_resources,
  122. };
  123. static struct platform_device *dsmg600_devices[] __initdata = {
  124. &dsmg600_i2c_gpio,
  125. &dsmg600_flash,
  126. &dsmg600_leds,
  127. };
  128. static void dsmg600_power_off(void)
  129. {
  130. /* enable the pwr cntl gpio */
  131. gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
  132. /* poweroff */
  133. gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
  134. }
  135. /* This is used to make sure the power-button pusher is serious. The button
  136. * must be held until the value of this counter reaches zero.
  137. */
  138. static int power_button_countdown;
  139. /* Must hold the button down for at least this many counts to be processed */
  140. #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
  141. static void dsmg600_power_handler(unsigned long data);
  142. static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
  143. static void dsmg600_power_handler(unsigned long data)
  144. {
  145. /* This routine is called twice per second to check the
  146. * state of the power button.
  147. */
  148. if (gpio_get_value(DSMG600_PB_GPIO)) {
  149. /* IO Pin is 1 (button pushed) */
  150. if (power_button_countdown > 0)
  151. power_button_countdown--;
  152. } else {
  153. /* Done on button release, to allow for auto-power-on mods. */
  154. if (power_button_countdown == 0) {
  155. /* Signal init to do the ctrlaltdel action,
  156. * this will bypass init if it hasn't started
  157. * and do a kernel_restart.
  158. */
  159. ctrl_alt_del();
  160. /* Change the state of the power LED to "blink" */
  161. gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
  162. } else {
  163. power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
  164. }
  165. }
  166. mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
  167. }
  168. static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
  169. {
  170. /* This is the paper-clip reset, it shuts the machine down directly. */
  171. machine_power_off();
  172. return IRQ_HANDLED;
  173. }
  174. static void __init dsmg600_timer_init(void)
  175. {
  176. /* The xtal on this machine is non-standard. */
  177. ixp4xx_timer_freq = DSMG600_FREQ;
  178. /* Call standard timer_init function. */
  179. ixp4xx_timer_init();
  180. }
  181. static struct sys_timer dsmg600_timer = {
  182. .init = dsmg600_timer_init,
  183. };
  184. static void __init dsmg600_init(void)
  185. {
  186. ixp4xx_sys_init();
  187. /* Make sure that GPIO14 and GPIO15 are not used as clocks */
  188. *IXP4XX_GPIO_GPCLKR = 0;
  189. dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  190. dsmg600_flash_resource.end =
  191. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  192. i2c_register_board_info(0, dsmg600_i2c_board_info,
  193. ARRAY_SIZE(dsmg600_i2c_board_info));
  194. /* The UART is required on the DSM-G600 (Redboot cannot use the
  195. * NIC) -- do it here so that it does *not* get removed if
  196. * platform_add_devices fails!
  197. */
  198. (void)platform_device_register(&dsmg600_uart);
  199. platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
  200. pm_power_off = dsmg600_power_off;
  201. if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
  202. IRQF_DISABLED | IRQF_TRIGGER_LOW,
  203. "DSM-G600 reset button", NULL) < 0) {
  204. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  205. gpio_to_irq(DSMG600_RB_GPIO));
  206. }
  207. /* The power button on the D-Link DSM-G600 is on GPIO 15, but
  208. * it cannot handle interrupts on that GPIO line. So we'll
  209. * have to poll it with a kernel timer.
  210. */
  211. /* Make sure that the power button GPIO is set up as an input */
  212. gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
  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. }
  217. MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
  218. /* Maintainer: www.nslu2-linux.org */
  219. .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS,
  220. .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xFFFC,
  221. .boot_params = 0x00000100,
  222. .map_io = ixp4xx_map_io,
  223. .init_irq = ixp4xx_init_irq,
  224. .timer = &dsmg600_timer,
  225. .init_machine = dsmg600_init,
  226. MACHINE_END