board-mtx1.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * MTX-1 platform devices registration (Au1500)
  3. *
  4. * Copyright (C) 2007-2009, Florian Fainelli <florian@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/kernel.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/leds.h>
  25. #include <linux/gpio.h>
  26. #include <linux/gpio_keys.h>
  27. #include <linux/input.h>
  28. #include <linux/mtd/partitions.h>
  29. #include <linux/mtd/physmap.h>
  30. #include <mtd/mtd-abi.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/reboot.h>
  33. #include <asm/mach-au1x00/au1000.h>
  34. #include <asm/mach-au1x00/au1xxx_eth.h>
  35. #include <prom.h>
  36. const char *get_system_type(void)
  37. {
  38. return "MTX-1";
  39. }
  40. void __init prom_init(void)
  41. {
  42. unsigned char *memsize_str;
  43. unsigned long memsize;
  44. prom_argc = fw_arg0;
  45. prom_argv = (char **)fw_arg1;
  46. prom_envp = (char **)fw_arg2;
  47. prom_init_cmdline();
  48. memsize_str = prom_getenv("memsize");
  49. if (!memsize_str)
  50. memsize = 0x04000000;
  51. else
  52. strict_strtoul(memsize_str, 0, &memsize);
  53. add_memory_region(0, memsize, BOOT_MEM_RAM);
  54. }
  55. void prom_putchar(unsigned char c)
  56. {
  57. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  58. }
  59. static void mtx1_reset(char *c)
  60. {
  61. /* Jump to the reset vector */
  62. __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
  63. }
  64. static void mtx1_power_off(void)
  65. {
  66. while (1)
  67. asm volatile (
  68. " .set mips32 \n"
  69. " wait \n"
  70. " .set mips0 \n");
  71. }
  72. void __init board_setup(void)
  73. {
  74. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  75. /* Enable USB power switch */
  76. alchemy_gpio_direction_output(204, 0);
  77. #endif /* defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) */
  78. /* Initialize sys_pinfunc */
  79. au_writel(SYS_PF_NI2, SYS_PINFUNC);
  80. /* Initialize GPIO */
  81. au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR);
  82. alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
  83. alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
  84. alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
  85. alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
  86. /* Enable LED and set it to green */
  87. alchemy_gpio_direction_output(211, 1); /* green on */
  88. alchemy_gpio_direction_output(212, 0); /* red off */
  89. pm_power_off = mtx1_power_off;
  90. _machine_halt = mtx1_power_off;
  91. _machine_restart = mtx1_reset;
  92. printk(KERN_INFO "4G Systems MTX-1 Board\n");
  93. }
  94. /******************************************************************************/
  95. static struct gpio_keys_button mtx1_gpio_button[] = {
  96. {
  97. .gpio = 207,
  98. .code = BTN_0,
  99. .desc = "System button",
  100. }
  101. };
  102. static struct gpio_keys_platform_data mtx1_buttons_data = {
  103. .buttons = mtx1_gpio_button,
  104. .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
  105. };
  106. static struct platform_device mtx1_button = {
  107. .name = "gpio-keys",
  108. .id = -1,
  109. .dev = {
  110. .platform_data = &mtx1_buttons_data,
  111. }
  112. };
  113. static struct resource mtx1_wdt_res[] = {
  114. [0] = {
  115. .start = 215,
  116. .end = 215,
  117. .name = "mtx1-wdt-gpio",
  118. .flags = IORESOURCE_IRQ,
  119. }
  120. };
  121. static struct platform_device mtx1_wdt = {
  122. .name = "mtx1-wdt",
  123. .id = 0,
  124. .num_resources = ARRAY_SIZE(mtx1_wdt_res),
  125. .resource = mtx1_wdt_res,
  126. };
  127. static struct gpio_led default_leds[] = {
  128. {
  129. .name = "mtx1:green",
  130. .gpio = 211,
  131. }, {
  132. .name = "mtx1:red",
  133. .gpio = 212,
  134. },
  135. };
  136. static struct gpio_led_platform_data mtx1_led_data = {
  137. .num_leds = ARRAY_SIZE(default_leds),
  138. .leds = default_leds,
  139. };
  140. static struct platform_device mtx1_gpio_leds = {
  141. .name = "leds-gpio",
  142. .id = -1,
  143. .dev = {
  144. .platform_data = &mtx1_led_data,
  145. }
  146. };
  147. static struct mtd_partition mtx1_mtd_partitions[] = {
  148. {
  149. .name = "filesystem",
  150. .size = 0x01C00000,
  151. .offset = 0,
  152. },
  153. {
  154. .name = "yamon",
  155. .size = 0x00100000,
  156. .offset = MTDPART_OFS_APPEND,
  157. .mask_flags = MTD_WRITEABLE,
  158. },
  159. {
  160. .name = "kernel",
  161. .size = 0x002c0000,
  162. .offset = MTDPART_OFS_APPEND,
  163. },
  164. {
  165. .name = "yamon env",
  166. .size = 0x00040000,
  167. .offset = MTDPART_OFS_APPEND,
  168. },
  169. };
  170. static struct physmap_flash_data mtx1_flash_data = {
  171. .width = 4,
  172. .nr_parts = 4,
  173. .parts = mtx1_mtd_partitions,
  174. };
  175. static struct resource mtx1_mtd_resource = {
  176. .start = 0x1e000000,
  177. .end = 0x1fffffff,
  178. .flags = IORESOURCE_MEM,
  179. };
  180. static struct platform_device mtx1_mtd = {
  181. .name = "physmap-flash",
  182. .dev = {
  183. .platform_data = &mtx1_flash_data,
  184. },
  185. .num_resources = 1,
  186. .resource = &mtx1_mtd_resource,
  187. };
  188. static struct resource alchemy_pci_host_res[] = {
  189. [0] = {
  190. .start = AU1500_PCI_PHYS_ADDR,
  191. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  192. .flags = IORESOURCE_MEM,
  193. },
  194. };
  195. static int mtx1_pci_idsel(unsigned int devsel, int assert)
  196. {
  197. /* This function is only necessary to support a proprietary Cardbus
  198. * adapter on the mtx-1 "singleboard" variant. It triggers a custom
  199. * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
  200. */
  201. if (assert && devsel != 0)
  202. /* Suppress signal to Cardbus */
  203. alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
  204. else
  205. alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
  206. udelay(1);
  207. return 1;
  208. }
  209. static const char mtx1_irqtab[][5] = {
  210. [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
  211. [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
  212. [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
  213. [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
  214. [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
  215. [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
  216. [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
  217. [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
  218. };
  219. static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  220. {
  221. return mtx1_irqtab[slot][pin];
  222. }
  223. static struct alchemy_pci_platdata mtx1_pci_pd = {
  224. .board_map_irq = mtx1_map_pci_irq,
  225. .board_pci_idsel = mtx1_pci_idsel,
  226. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  227. PCI_CONFIG_CH |
  228. #if defined(__MIPSEB__)
  229. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  230. #else
  231. 0,
  232. #endif
  233. };
  234. static struct platform_device mtx1_pci_host = {
  235. .dev.platform_data = &mtx1_pci_pd,
  236. .name = "alchemy-pci",
  237. .id = 0,
  238. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  239. .resource = alchemy_pci_host_res,
  240. };
  241. static struct __initdata platform_device * mtx1_devs[] = {
  242. &mtx1_pci_host,
  243. &mtx1_gpio_leds,
  244. &mtx1_wdt,
  245. &mtx1_button,
  246. &mtx1_mtd,
  247. };
  248. static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
  249. .phy_search_highest_addr = 1,
  250. .phy1_search_mac0 = 1,
  251. };
  252. static int __init mtx1_register_devices(void)
  253. {
  254. int rc;
  255. irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
  256. irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
  257. irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
  258. irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
  259. irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
  260. au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
  261. rc = gpio_request(mtx1_gpio_button[0].gpio,
  262. mtx1_gpio_button[0].desc);
  263. if (rc < 0) {
  264. printk(KERN_INFO "mtx1: failed to request %d\n",
  265. mtx1_gpio_button[0].gpio);
  266. goto out;
  267. }
  268. gpio_direction_input(mtx1_gpio_button[0].gpio);
  269. out:
  270. return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
  271. }
  272. arch_initcall(mtx1_register_devices);