nslu2-setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 and assert power off */
  178. gpio_direction_output(NSLU2_PO_GPIO, 1);
  179. }
  180. static irqreturn_t nslu2_power_handler(int irq, void *dev_id)
  181. {
  182. /* Signal init to do the ctrlaltdel action, this will bypass init if
  183. * it hasn't started and do a kernel_restart.
  184. */
  185. ctrl_alt_del();
  186. return IRQ_HANDLED;
  187. }
  188. static irqreturn_t nslu2_reset_handler(int irq, void *dev_id)
  189. {
  190. /* This is the paper-clip reset, it shuts the machine down directly.
  191. */
  192. machine_power_off();
  193. return IRQ_HANDLED;
  194. }
  195. static int __init nslu2_gpio_init(void)
  196. {
  197. if (!machine_is_nslu2())
  198. return 0;
  199. /* Request the power off GPIO */
  200. return gpio_request(NSLU2_PO_GPIO, "power off");
  201. }
  202. device_initcall(nslu2_gpio_init);
  203. static void __init nslu2_timer_init(void)
  204. {
  205. /* The xtal on this machine is non-standard. */
  206. ixp4xx_timer_freq = NSLU2_FREQ;
  207. /* Call standard timer_init function. */
  208. ixp4xx_timer_init();
  209. }
  210. static void __init nslu2_init(void)
  211. {
  212. uint8_t __iomem *f;
  213. int i;
  214. ixp4xx_sys_init();
  215. nslu2_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  216. nslu2_flash_resource.end =
  217. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  218. i2c_register_board_info(0, nslu2_i2c_board_info,
  219. ARRAY_SIZE(nslu2_i2c_board_info));
  220. /*
  221. * This is only useful on a modified machine, but it is valuable
  222. * to have it first in order to see debug messages, and so that
  223. * it does *not* get removed if platform_add_devices fails!
  224. */
  225. (void)platform_device_register(&nslu2_uart);
  226. platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
  227. pm_power_off = nslu2_power_off;
  228. if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
  229. IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
  230. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  231. gpio_to_irq(NSLU2_RB_GPIO));
  232. }
  233. if (request_irq(gpio_to_irq(NSLU2_PB_GPIO), &nslu2_power_handler,
  234. IRQF_TRIGGER_HIGH, "NSLU2 power button", NULL) < 0) {
  235. printk(KERN_DEBUG "Power Button IRQ %d not available\n",
  236. gpio_to_irq(NSLU2_PB_GPIO));
  237. }
  238. /*
  239. * Map in a portion of the flash and read the MAC address.
  240. * Since it is stored in BE in the flash itself, we need to
  241. * byteswap it if we're in LE mode.
  242. */
  243. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x40000);
  244. if (f) {
  245. for (i = 0; i < 6; i++)
  246. #ifdef __ARMEB__
  247. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + i);
  248. #else
  249. nslu2_plat_eth[0].hwaddr[i] = readb(f + 0x3FFB0 + (i^3));
  250. #endif
  251. iounmap(f);
  252. }
  253. printk(KERN_INFO "NSLU2: Using MAC address %pM for port 0\n",
  254. nslu2_plat_eth[0].hwaddr);
  255. }
  256. MACHINE_START(NSLU2, "Linksys NSLU2")
  257. /* Maintainer: www.nslu2-linux.org */
  258. .atag_offset = 0x100,
  259. .map_io = ixp4xx_map_io,
  260. .init_early = ixp4xx_init_early,
  261. .init_irq = ixp4xx_init_irq,
  262. .init_time = nslu2_timer_init,
  263. .init_machine = nslu2_init,
  264. #if defined(CONFIG_PCI)
  265. .dma_zone_size = SZ_64M,
  266. #endif
  267. .restart = ixp4xx_restart,
  268. MACHINE_END