fsg-setup.c 6.5 KB

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