nslu2-setup.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/if_ether.h>
  20. #include <linux/irq.h>
  21. #include <linux/serial.h>
  22. #include <linux/serial_8250.h>
  23. #include <linux/leds.h>
  24. #include <linux/reboot.h>
  25. #include <linux/i2c.h>
  26. #include <linux/i2c-gpio.h>
  27. #include <linux/io.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 nslu2_flash_data = {
  34. .map_name = "cfi_probe",
  35. .width = 2,
  36. };
  37. static struct resource nslu2_flash_resource = {
  38. .flags = IORESOURCE_MEM,
  39. };
  40. static struct platform_device nslu2_flash = {
  41. .name = "IXP4XX-Flash",
  42. .id = 0,
  43. .dev.platform_data = &nslu2_flash_data,
  44. .num_resources = 1,
  45. .resource = &nslu2_flash_resource,
  46. };
  47. static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = {
  48. .sda_pin = NSLU2_SDA_PIN,
  49. .scl_pin = NSLU2_SCL_PIN,
  50. };
  51. static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
  52. {
  53. I2C_BOARD_INFO("x1205", 0x6f),
  54. },
  55. };
  56. static struct gpio_led nslu2_led_pins[] = {
  57. {
  58. .name = "nslu2:green:ready",
  59. .gpio = NSLU2_LED_GRN_GPIO,
  60. },
  61. {
  62. .name = "nslu2:red:status",
  63. .gpio = NSLU2_LED_RED_GPIO,
  64. },
  65. {
  66. .name = "nslu2:green:disk-1",
  67. .gpio = NSLU2_LED_DISK1_GPIO,
  68. .active_low = true,
  69. },
  70. {
  71. .name = "nslu2:green:disk-2",
  72. .gpio = NSLU2_LED_DISK2_GPIO,
  73. .active_low = true,
  74. },
  75. };
  76. static struct gpio_led_platform_data nslu2_led_data = {
  77. .num_leds = ARRAY_SIZE(nslu2_led_pins),
  78. .leds = nslu2_led_pins,
  79. };
  80. static struct platform_device nslu2_leds = {
  81. .name = "leds-gpio",
  82. .id = -1,
  83. .dev.platform_data = &nslu2_led_data,
  84. };
  85. static struct platform_device nslu2_i2c_gpio = {
  86. .name = "i2c-gpio",
  87. .id = 0,
  88. .dev = {
  89. .platform_data = &nslu2_i2c_gpio_data,
  90. },
  91. };
  92. static struct platform_device nslu2_beeper = {
  93. .name = "ixp4xx-beeper",
  94. .id = NSLU2_GPIO_BUZZ,
  95. .num_resources = 0,
  96. };
  97. static struct resource nslu2_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 nslu2_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 nslu2_uart = {
  131. .name = "serial8250",
  132. .id = PLAT8250_DEV_PLATFORM,
  133. .dev.platform_data = nslu2_uart_data,
  134. .num_resources = 2,
  135. .resource = nslu2_uart_resources,
  136. };
  137. /* Built-in 10/100 Ethernet MAC interfaces */
  138. static struct eth_plat_info nslu2_plat_eth[] = {
  139. {
  140. .phy = 1,
  141. .rxq = 3,
  142. .txreadyq = 20,
  143. }
  144. };
  145. static struct platform_device nslu2_eth[] = {
  146. {
  147. .name = "ixp4xx_eth",
  148. .id = IXP4XX_ETH_NPEB,
  149. .dev.platform_data = nslu2_plat_eth,
  150. }
  151. };
  152. static struct platform_device *nslu2_devices[] __initdata = {
  153. &nslu2_i2c_gpio,
  154. &nslu2_flash,
  155. &nslu2_beeper,
  156. &nslu2_leds,
  157. &nslu2_eth[0],
  158. };
  159. static void nslu2_power_off(void)
  160. {
  161. /* This causes the box to drop the power and go dead. */
  162. /* enable the pwr cntl gpio */
  163. gpio_line_config(NSLU2_PO_GPIO, IXP4XX_GPIO_OUT);
  164. /* do the deed */
  165. gpio_line_set(NSLU2_PO_GPIO, IXP4XX_GPIO_HIGH);
  166. }
  167. static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
  168. {
  169. /* Signal init to do the ctrlaltdel action, this will bypass init if
  170. * it hasn't started and do a kernel_restart.
  171. */
  172. ctrl_alt_del();
  173. return IRQ_HANDLED;
  174. }
  175. static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
  176. {
  177. /* This is the paper-clip reset, it shuts the machine down directly.
  178. */
  179. machine_power_off();
  180. return IRQ_HANDLED;
  181. }
  182. static void __init nslu2_timer_init(void)
  183. {
  184. /* The xtal on this machine is non-standard. */
  185. ixp4xx_timer_freq = NSLU2_FREQ;
  186. /* Call standard timer_init function. */
  187. ixp4xx_timer_init();
  188. }
  189. static struct sys_timer nslu2_timer = {
  190. .init = nslu2_timer_init,
  191. };
  192. static void __init nslu2_init(void)
  193. {
  194. uint8_t __iomem *f;
  195. int i;
  196. ixp4xx_sys_init();
  197. nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  198. nslu2_flash_resource.end =
  199. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  200. i2c_register_board_info(0, nslu2_i2c_board_info,
  201. ARRAY_SIZE(nslu2_i2c_board_info));
  202. /*
  203. * This is only useful on a modified machine, but it is valuable
  204. * to have it first in order to see debug messages, and so that
  205. * it does *not* get removed if platform_add_devices fails!
  206. */
  207. (void)platform_device_register(&nslu2_uart);
  208. platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
  209. pm_power_off = nslu2_power_off;
  210. if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
  211. IRQF_DISABLED | IRQF_TRIGGER_LOW,
  212. "NSLU2 reset button", NULL) < 0) {
  213. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  214. gpio_to_irq(NSLU2_RB_GPIO));
  215. }
  216. if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
  217. IRQF_DISABLED | IRQF_TRIGGER_HIGH,
  218. "NSLU2 power button", NULL) < 0) {
  219. printk(KERN_DEBUG "Power Button IRQ %d not available\n",
  220. gpio_to_irq(NSLU2_PB_GPIO));
  221. }
  222. /*
  223. * Map in a portion of the flash and read the MAC address.
  224. * Since it is stored in BE in the flash itself, we need to
  225. * byteswap it if we're in LE mode.
  226. */
  227. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
  228. if (f) {
  229. for (i = 0; i < 6; i++)
  230. #ifdef __ARMEB__
  231. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
  232. #else
  233. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
  234. #endif
  235. iounmap(f);
  236. }
  237. printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
  238. nslu2_plat_eth[0].hwaddr);
  239. }
  240. MACHINE_START(NSLU2, "Linksys NSLU2")
  241. /* Maintainer: www.nslu2-linux.org */
  242. .phys_io = IXP4XX_PERIPHERAL_BASE_PHYS,
  243. .io_pg_offst = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xFFFC,
  244. .boot_params = 0x00000100,
  245. .map_io = ixp4xx_map_io,
  246. .init_irq = ixp4xx_init_irq,
  247. .timer = &nslu2_timer,
  248. .init_machine = nslu2_init,
  249. MACHINE_END