nslu2-setup.c 7.3 KB

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