fsg-setup.c 6.6 KB

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