board-mtx1.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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/gpio-au1000.h>
  35. #include <asm/mach-au1x00/au1xxx_eth.h>
  36. #include <prom.h>
  37. const char *get_system_type(void)
  38. {
  39. return "MTX-1";
  40. }
  41. void __init prom_init(void)
  42. {
  43. unsigned char *memsize_str;
  44. unsigned long memsize;
  45. prom_argc = fw_arg0;
  46. prom_argv = (char **)fw_arg1;
  47. prom_envp = (char **)fw_arg2;
  48. prom_init_cmdline();
  49. memsize_str = prom_getenv("memsize");
  50. if (!memsize_str || kstrtoul(memsize_str, 0, &memsize))
  51. memsize = 0x04000000;
  52. add_memory_region(0, memsize, BOOT_MEM_RAM);
  53. }
  54. void prom_putchar(unsigned char c)
  55. {
  56. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  57. }
  58. static void mtx1_reset(char *c)
  59. {
  60. /* Jump to the reset vector */
  61. __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
  62. }
  63. static void mtx1_power_off(void)
  64. {
  65. while (1)
  66. asm volatile (
  67. " .set mips32 \n"
  68. " wait \n"
  69. " .set mips0 \n");
  70. }
  71. void __init board_setup(void)
  72. {
  73. #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
  74. /* Enable USB power switch */
  75. alchemy_gpio_direction_output(204, 0);
  76. #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
  77. /* Initialize sys_pinfunc */
  78. alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC);
  79. /* Initialize GPIO */
  80. alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR);
  81. alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
  82. alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
  83. alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
  84. alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
  85. /* Enable LED and set it to green */
  86. alchemy_gpio_direction_output(211, 1); /* green on */
  87. alchemy_gpio_direction_output(212, 0); /* red off */
  88. pm_power_off = mtx1_power_off;
  89. _machine_halt = mtx1_power_off;
  90. _machine_restart = mtx1_reset;
  91. printk(KERN_INFO "4G Systems MTX-1 Board\n");
  92. }
  93. /******************************************************************************/
  94. static struct gpio_keys_button mtx1_gpio_button[] = {
  95. {
  96. .gpio = 207,
  97. .code = BTN_0,
  98. .desc = "System button",
  99. }
  100. };
  101. static struct gpio_keys_platform_data mtx1_buttons_data = {
  102. .buttons = mtx1_gpio_button,
  103. .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
  104. };
  105. static struct platform_device mtx1_button = {
  106. .name = "gpio-keys",
  107. .id = -1,
  108. .dev = {
  109. .platform_data = &mtx1_buttons_data,
  110. }
  111. };
  112. static struct resource mtx1_wdt_res[] = {
  113. [0] = {
  114. .start = 215,
  115. .end = 215,
  116. .name = "mtx1-wdt-gpio",
  117. .flags = IORESOURCE_IRQ,
  118. }
  119. };
  120. static struct platform_device mtx1_wdt = {
  121. .name = "mtx1-wdt",
  122. .id = 0,
  123. .num_resources = ARRAY_SIZE(mtx1_wdt_res),
  124. .resource = mtx1_wdt_res,
  125. };
  126. static struct gpio_led default_leds[] = {
  127. {
  128. .name = "mtx1:green",
  129. .gpio = 211,
  130. }, {
  131. .name = "mtx1:red",
  132. .gpio = 212,
  133. },
  134. };
  135. static struct gpio_led_platform_data mtx1_led_data = {
  136. .num_leds = ARRAY_SIZE(default_leds),
  137. .leds = default_leds,
  138. };
  139. static struct platform_device mtx1_gpio_leds = {
  140. .name = "leds-gpio",
  141. .id = -1,
  142. .dev = {
  143. .platform_data = &mtx1_led_data,
  144. }
  145. };
  146. static struct mtd_partition mtx1_mtd_partitions[] = {
  147. {
  148. .name = "filesystem",
  149. .size = 0x01C00000,
  150. .offset = 0,
  151. },
  152. {
  153. .name = "yamon",
  154. .size = 0x00100000,
  155. .offset = MTDPART_OFS_APPEND,
  156. .mask_flags = MTD_WRITEABLE,
  157. },
  158. {
  159. .name = "kernel",
  160. .size = 0x002c0000,
  161. .offset = MTDPART_OFS_APPEND,
  162. },
  163. {
  164. .name = "yamon env",
  165. .size = 0x00040000,
  166. .offset = MTDPART_OFS_APPEND,
  167. },
  168. };
  169. static struct physmap_flash_data mtx1_flash_data = {
  170. .width = 4,
  171. .nr_parts = 4,
  172. .parts = mtx1_mtd_partitions,
  173. };
  174. static struct resource mtx1_mtd_resource = {
  175. .start = 0x1e000000,
  176. .end = 0x1fffffff,
  177. .flags = IORESOURCE_MEM,
  178. };
  179. static struct platform_device mtx1_mtd = {
  180. .name = "physmap-flash",
  181. .dev = {
  182. .platform_data = &mtx1_flash_data,
  183. },
  184. .num_resources = 1,
  185. .resource = &mtx1_mtd_resource,
  186. };
  187. static struct resource alchemy_pci_host_res[] = {
  188. [0] = {
  189. .start = AU1500_PCI_PHYS_ADDR,
  190. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  191. .flags = IORESOURCE_MEM,
  192. },
  193. };
  194. static int mtx1_pci_idsel(unsigned int devsel, int assert)
  195. {
  196. /* This function is only necessary to support a proprietary Cardbus
  197. * adapter on the mtx-1 "singleboard" variant. It triggers a custom
  198. * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
  199. */
  200. udelay(1);
  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 platform_device *mtx1_devs[] __initdata = {
  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);