nslu2-setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * arch/arm/mach-ixp4xx/nslu2-setup.c
  3. *
  4. * NSLU2 board-setup
  5. *
  6. * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
  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. *
  13. * Author: Mark Rakes <mrakes at mac.com>
  14. * Author: Rod Whitby <rod@whitby.id.au>
  15. * Author: Alessandro Zummo <a.zummo@towertech.it>
  16. * Maintainers: http://www.nslu2-linux.org/
  17. *
  18. */
  19. #include <linux/gpio.h>
  20. #include <linux/if_ether.h>
  21. #include <linux/irq.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 <linux/io.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/flash.h>
  32. #include <asm/mach/time.h>
  33. #define NSLU2_SDA_PIN 7
  34. #define NSLU2_SCL_PIN 6
  35. /* NSLU2 Timer */
  36. #define NSLU2_FREQ 66000000
  37. /* Buttons */
  38. #define NSLU2_PB_GPIO 5 /* power button */
  39. #define NSLU2_PO_GPIO 8 /* power off */
  40. #define NSLU2_RB_GPIO 12 /* reset button */
  41. /* Buzzer */
  42. #define NSLU2_GPIO_BUZZ 4
  43. /* LEDs */
  44. #define NSLU2_LED_RED_GPIO 0
  45. #define NSLU2_LED_GRN_GPIO 1
  46. #define NSLU2_LED_DISK1_GPIO 3
  47. #define NSLU2_LED_DISK2_GPIO 2
  48. static struct flash_platform_data nslu2_flash_data = {
  49. .map_name = "cfi_probe",
  50. .width = 2,
  51. };
  52. static struct resource nslu2_flash_resource = {
  53. .flags = IORESOURCE_MEM,
  54. };
  55. static struct platform_device nslu2_flash = {
  56. .name = "IXP4XX-Flash",
  57. .id = 0,
  58. .dev.platform_data = &nslu2_flash_data,
  59. .num_resources = 1,
  60. .resource = &nslu2_flash_resource,
  61. };
  62. static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
  63. .sda_pin = NSLU2_SDA_PIN,
  64. .scl_pin = NSLU2_SCL_PIN,
  65. };
  66. static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
  67. {
  68. I2C_BOARD_INFO("x1205", 0x6f),
  69. },
  70. };
  71. static struct gpio_led nslu2_led_pins[] = {
  72. {
  73. .name = "nslu2:green:ready",
  74. .gpio = NSLU2_LED_GRN_GPIO,
  75. },
  76. {
  77. .name = "nslu2:red:status",
  78. .gpio = NSLU2_LED_RED_GPIO,
  79. },
  80. {
  81. .name = "nslu2:green:disk-1",
  82. .gpio = NSLU2_LED_DISK1_GPIO,
  83. .active_low = true,
  84. },
  85. {
  86. .name = "nslu2:green:disk-2",
  87. .gpio = NSLU2_LED_DISK2_GPIO,
  88. .active_low = true,
  89. },
  90. };
  91. static struct gpio_led_platform_data nslu2_led_data = {
  92. .num_leds = ARRAY_SIZE(nslu2_led_pins),
  93. .leds = nslu2_led_pins,
  94. };
  95. static struct platform_device nslu2_leds = {
  96. .name = "leds-gpio",
  97. .id = -1,
  98. .dev.platform_data = &nslu2_led_data,
  99. };
  100. static struct platform_device nslu2_i2c_gpio = {
  101. .name = "i2c-gpio",
  102. .id = 0,
  103. .dev = {
  104. .platform_data = &nslu2_i2c_gpio_data,
  105. },
  106. };
  107. static struct platform_device nslu2_beeper = {
  108. .name = "ixp4xx-beeper",
  109. .id = NSLU2_GPIO_BUZZ,
  110. .num_resources = 0,
  111. };
  112. static struct resource nslu2_uart_resources[] = {
  113. {
  114. .start = IXP4XX_UART1_BASE_PHYS,
  115. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  116. .flags = IORESOURCE_MEM,
  117. },
  118. {
  119. .start = IXP4XX_UART2_BASE_PHYS,
  120. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  121. .flags = IORESOURCE_MEM,
  122. }
  123. };
  124. static struct plat_serial8250_port nslu2_uart_data[] = {
  125. {
  126. .mapbase = IXP4XX_UART1_BASE_PHYS,
  127. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  128. .irq = IRQ_IXP4XX_UART1,
  129. .flags = UPF_BOOT_AUTOCONF,
  130. .iotype = UPIO_MEM,
  131. .regshift = 2,
  132. .uartclk = IXP4XX_UART_XTAL,
  133. },
  134. {
  135. .mapbase = IXP4XX_UART2_BASE_PHYS,
  136. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  137. .irq = IRQ_IXP4XX_UART2,
  138. .flags = UPF_BOOT_AUTOCONF,
  139. .iotype = UPIO_MEM,
  140. .regshift = 2,
  141. .uartclk = IXP4XX_UART_XTAL,
  142. },
  143. { }
  144. };
  145. static struct platform_device nslu2_uart = {
  146. .name = "serial8250",
  147. .id = PLAT8250_DEV_PLATFORM,
  148. .dev.platform_data = nslu2_uart_data,
  149. .num_resources = 2,
  150. .resource = nslu2_uart_resources,
  151. };
  152. /* Built-in 10/100 Ethernet MAC interfaces */
  153. static struct eth_plat_info nslu2_plat_eth[] = {
  154. {
  155. .phy = 1,
  156. .rxq = 3,
  157. .txreadyq = 20,
  158. }
  159. };
  160. static struct platform_device nslu2_eth[] = {
  161. {
  162. .name = "ixp4xx_eth",
  163. .id = IXP4XX_ETH_NPEB,
  164. .dev.platform_data = nslu2_plat_eth,
  165. }
  166. };
  167. static struct platform_device *nslu2_devices[] __initdata = {
  168. &nslu2_i2c_gpio,
  169. &nslu2_flash,
  170. &nslu2_beeper,
  171. &nslu2_leds,
  172. &nslu2_eth[0],
  173. };
  174. static void nslu2_power_off(void)
  175. {
  176. /* This causes the box to drop the power and go dead. */
  177. /* enable the pwr cntl gpio */
  178. gpio_line_config(NSLU2_PO_GPIO, IXP4XX_GPIO_OUT);
  179. /* do the deed */
  180. gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
  181. }
  182. static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
  183. {
  184. /* Signal init to do the ctrlaltdel action, this will bypass init if
  185. * it hasn't started and do a kernel_restart.
  186. */
  187. ctrl_alt_del();
  188. return IRQ_HANDLED;
  189. }
  190. static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
  191. {
  192. /* This is the paper-clip reset, it shuts the machine down directly.
  193. */
  194. machine_power_off();
  195. return IRQ_HANDLED;
  196. }
  197. static void __init nslu2_timer_init(void)
  198. {
  199. /* The xtal on this machine is non-standard. */
  200. ixp4xx_timer_freq = NSLU2_FREQ;
  201. /* Call standard timer_init function. */
  202. ixp4xx_timer_init();
  203. }
  204. static struct sys_timer nslu2_timer = {
  205. .init = nslu2_timer_init,
  206. };
  207. static void __init nslu2_init(void)
  208. {
  209. uint8_t __iomem *f;
  210. int i;
  211. ixp4xx_sys_init();
  212. nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  213. nslu2_flash_resource.end =
  214. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  215. i2c_register_board_info(0, nslu2_i2c_board_info,
  216. ARRAY_SIZE(nslu2_i2c_board_info));
  217. /*
  218. * This is only useful on a modified machine, but it is valuable
  219. * to have it first in order to see debug messages, and so that
  220. * it does *not* get removed if platform_add_devices fails!
  221. */
  222. (void)platform_device_register(&nslu2_uart);
  223. platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
  224. pm_power_off = nslu2_power_off;
  225. if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
  226. IRQF_DISABLED | IRQF_TRIGGER_LOW,
  227. "NSLU2 reset button", NULL) < 0) {
  228. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  229. gpio_to_irq(NSLU2_RB_GPIO));
  230. }
  231. if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
  232. IRQF_DISABLED | IRQF_TRIGGER_HIGH,
  233. "NSLU2 power button", NULL) < 0) {
  234. printk(KERN_DEBUG "Power Button IRQ %d not available\n",
  235. gpio_to_irq(NSLU2_PB_GPIO));
  236. }
  237. /*
  238. * Map in a portion of the flash and read the MAC address.
  239. * Since it is stored in BE in the flash itself, we need to
  240. * byteswap it if we're in LE mode.
  241. */
  242. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
  243. if (f) {
  244. for (i = 0; i < 6; i++)
  245. #ifdef __ARMEB__
  246. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
  247. #else
  248. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
  249. #endif
  250. iounmap(f);
  251. }
  252. printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
  253. nslu2_plat_eth[0].hwaddr);
  254. }
  255. MACHINE_START(NSLU2, "Linksys NSLU2")
  256. /* Maintainer: www.nslu2-linux.org */
  257. .atag_offset = 0x100,
  258. .map_io = ixp4xx_map_io,
  259. .init_early = ixp4xx_init_early,
  260. .init_irq = ixp4xx_init_irq,
  261. .timer = &nslu2_timer,
  262. .init_machine = nslu2_init,
  263. #if defined(CONFIG_PCI)
  264. .dma_zone_size = SZ_64M,
  265. #endif
  266. .restart = ixp4xx_restart,
  267. MACHINE_END