dsmg600-setup.c 7.2 KB

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