fsg-setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/arm/mach-ixp4xx/fsg-setup.c
  4. *
  5. * FSG 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: Rod Whitby <rod@whitby.id.au>
  15. * Maintainers: http://www.nslu2-linux.org/
  16. *
  17. */
  18. #include <linux/gpio.h>
  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/gpio/machine.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. #define FSG_SDA_PIN 12
  32. #define FSG_SCL_PIN 13
  33. #define FSG_SB_GPIO 4 /* sync button */
  34. #define FSG_RB_GPIO 9 /* reset button */
  35. #define FSG_UB_GPIO 10 /* usb button */
  36. static struct flash_platform_data fsg_flash_data = {
  37. .map_name = "cfi_probe",
  38. .width = 2,
  39. };
  40. static struct resource fsg_flash_resource = {
  41. .flags = IORESOURCE_MEM,
  42. };
  43. static struct platform_device fsg_flash = {
  44. .name = "IXP4XX-Flash",
  45. .id = 0,
  46. .dev = {
  47. .platform_data = &fsg_flash_data,
  48. },
  49. .num_resources = 1,
  50. .resource = &fsg_flash_resource,
  51. };
  52. static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
  53. .dev_id = "i2c-gpio.0",
  54. .table = {
  55. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN,
  56. NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  57. GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN,
  58. NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  59. },
  60. };
  61. static struct platform_device fsg_i2c_gpio = {
  62. .name = "i2c-gpio",
  63. .id = 0,
  64. .dev = {
  65. .platform_data = NULL,
  66. },
  67. };
  68. static struct i2c_board_info __initdata fsg_i2c_board_info [] = {
  69. {
  70. I2C_BOARD_INFO("isl1208", 0x6f),
  71. },
  72. };
  73. static struct resource fsg_uart_resources[] = {
  74. {
  75. .start = IXP4XX_UART1_BASE_PHYS,
  76. .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. {
  80. .start = IXP4XX_UART2_BASE_PHYS,
  81. .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
  82. .flags = IORESOURCE_MEM,
  83. }
  84. };
  85. static struct plat_serial8250_port fsg_uart_data[] = {
  86. {
  87. .mapbase = IXP4XX_UART1_BASE_PHYS,
  88. .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
  89. .irq = IRQ_IXP4XX_UART1,
  90. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  91. .iotype = UPIO_MEM,
  92. .regshift = 2,
  93. .uartclk = IXP4XX_UART_XTAL,
  94. },
  95. {
  96. .mapbase = IXP4XX_UART2_BASE_PHYS,
  97. .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
  98. .irq = IRQ_IXP4XX_UART2,
  99. .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
  100. .iotype = UPIO_MEM,
  101. .regshift = 2,
  102. .uartclk = IXP4XX_UART_XTAL,
  103. },
  104. { }
  105. };
  106. static struct platform_device fsg_uart = {
  107. .name = "serial8250",
  108. .id = PLAT8250_DEV_PLATFORM,
  109. .dev = {
  110. .platform_data = fsg_uart_data,
  111. },
  112. .num_resources = ARRAY_SIZE(fsg_uart_resources),
  113. .resource = fsg_uart_resources,
  114. };
  115. static struct platform_device fsg_leds = {
  116. .name = "fsg-led",
  117. .id = -1,
  118. };
  119. /* Built-in 10/100 Ethernet MAC interfaces */
  120. static struct eth_plat_info fsg_plat_eth[] = {
  121. {
  122. .phy = 5,
  123. .rxq = 3,
  124. .txreadyq = 20,
  125. }, {
  126. .phy = 4,
  127. .rxq = 4,
  128. .txreadyq = 21,
  129. }
  130. };
  131. static struct platform_device fsg_eth[] = {
  132. {
  133. .name = "ixp4xx_eth",
  134. .id = IXP4XX_ETH_NPEB,
  135. .dev = {
  136. .platform_data = fsg_plat_eth,
  137. },
  138. }, {
  139. .name = "ixp4xx_eth",
  140. .id = IXP4XX_ETH_NPEC,
  141. .dev = {
  142. .platform_data = fsg_plat_eth + 1,
  143. },
  144. }
  145. };
  146. static struct platform_device *fsg_devices[] __initdata = {
  147. &fsg_i2c_gpio,
  148. &fsg_flash,
  149. &fsg_leds,
  150. &fsg_eth[0],
  151. &fsg_eth[1],
  152. };
  153. static irqreturn_t fsg_power_handler(int irq, void *dev_id)
  154. {
  155. /* Signal init to do the ctrlaltdel action, this will bypass init if
  156. * it hasn't started and do a kernel_restart.
  157. */
  158. ctrl_alt_del();
  159. return IRQ_HANDLED;
  160. }
  161. static irqreturn_t fsg_reset_handler(int irq, void *dev_id)
  162. {
  163. /* This is the paper-clip reset which does an emergency reboot. */
  164. printk(KERN_INFO "Restarting system.\n");
  165. machine_restart(NULL);
  166. /* This should never be reached. */
  167. return IRQ_HANDLED;
  168. }
  169. static void __init fsg_init(void)
  170. {
  171. uint8_t __iomem *f;
  172. ixp4xx_sys_init();
  173. fsg_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
  174. fsg_flash_resource.end =
  175. IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
  176. *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
  177. *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
  178. /* Configure CS2 for operation, 8bit and writable */
  179. *IXP4XX_EXP_CS2 = 0xbfff0002;
  180. gpiod_add_lookup_table(&fsg_i2c_gpiod_table);
  181. i2c_register_board_info(0, fsg_i2c_board_info,
  182. ARRAY_SIZE(fsg_i2c_board_info));
  183. /* This is only useful on a modified machine, but it is valuable
  184. * to have it first in order to see debug messages, and so that
  185. * it does *not* get removed if platform_add_devices fails!
  186. */
  187. (void)platform_device_register(&fsg_uart);
  188. platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices));
  189. if (request_irq(gpio_to_irq(FSG_RB_GPIO), &fsg_reset_handler,
  190. IRQF_TRIGGER_LOW, "FSG reset button", NULL) < 0) {
  191. printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
  192. gpio_to_irq(FSG_RB_GPIO));
  193. }
  194. if (request_irq(gpio_to_irq(FSG_SB_GPIO), &fsg_power_handler,
  195. IRQF_TRIGGER_LOW, "FSG power button", NULL) < 0) {
  196. printk(KERN_DEBUG "Power Button IRQ %d not available\n",
  197. gpio_to_irq(FSG_SB_GPIO));
  198. }
  199. /*
  200. * Map in a portion of the flash and read the MAC addresses.
  201. * Since it is stored in BE in the flash itself, we need to
  202. * byteswap it if we're in LE mode.
  203. */
  204. f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x400000);
  205. if (f) {
  206. #ifdef __ARMEB__
  207. int i;
  208. for (i = 0; i < 6; i++) {
  209. fsg_plat_eth[0].hwaddr[i] = readb(f + 0x3C0422 + i);
  210. fsg_plat_eth[1].hwaddr[i] = readb(f + 0x3C043B + i);
  211. }
  212. #else
  213. /*
  214. Endian-swapped reads from unaligned addresses are
  215. required to extract the two MACs from the big-endian
  216. Redboot config area in flash.
  217. */
  218. fsg_plat_eth[0].hwaddr[0] = readb(f + 0x3C0421);
  219. fsg_plat_eth[0].hwaddr[1] = readb(f + 0x3C0420);
  220. fsg_plat_eth[0].hwaddr[2] = readb(f + 0x3C0427);
  221. fsg_plat_eth[0].hwaddr[3] = readb(f + 0x3C0426);
  222. fsg_plat_eth[0].hwaddr[4] = readb(f + 0x3C0425);
  223. fsg_plat_eth[0].hwaddr[5] = readb(f + 0x3C0424);
  224. fsg_plat_eth[1].hwaddr[0] = readb(f + 0x3C0439);
  225. fsg_plat_eth[1].hwaddr[1] = readb(f + 0x3C043F);
  226. fsg_plat_eth[1].hwaddr[2] = readb(f + 0x3C043E);
  227. fsg_plat_eth[1].hwaddr[3] = readb(f + 0x3C043D);
  228. fsg_plat_eth[1].hwaddr[4] = readb(f + 0x3C043C);
  229. fsg_plat_eth[1].hwaddr[5] = readb(f + 0x3C0443);
  230. #endif
  231. iounmap(f);
  232. }
  233. printk(KERN_INFO "FSG: Using MAC address %pM for port 0\n",
  234. fsg_plat_eth[0].hwaddr);
  235. printk(KERN_INFO "FSG: Using MAC address %pM for port 1\n",
  236. fsg_plat_eth[1].hwaddr);
  237. }
  238. MACHINE_START(FSG, "Freecom FSG-3")
  239. /* Maintainer: www.nslu2-linux.org */
  240. .map_io = ixp4xx_map_io,
  241. .init_early = ixp4xx_init_early,
  242. .init_irq = ixp4xx_init_irq,
  243. .init_time = ixp4xx_timer_init,
  244. .atag_offset = 0x100,
  245. .init_machine = fsg_init,
  246. #if defined(CONFIG_PCI)
  247. .dma_zone_size = SZ_64M,
  248. #endif
  249. .restart = ixp4xx_restart,
  250. MACHINE_END