board-mtx1.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 || kstrtoul(memsize_str, 0, &memsize))
  50. memsize = 0x04000000;
  51. add_memory_region(0, memsize, BOOT_MEM_RAM);
  52. }
  53. void prom_putchar(unsigned char c)
  54. {
  55. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  56. }
  57. static void mtx1_reset(char *c)
  58. {
  59. /* Jump to the reset vector */
  60. __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
  61. }
  62. static void mtx1_power_off(void)
  63. {
  64. while (1)
  65. asm volatile (
  66. " .set mips32 \n"
  67. " wait \n"
  68. " .set mips0 \n");
  69. }
  70. void __init board_setup(void)
  71. {
  72. #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
  73. /* Enable USB power switch */
  74. alchemy_gpio_direction_output(204, 0);
  75. #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
  76. /* Initialize sys_pinfunc */
  77. au_writel(SYS_PF_NI2, SYS_PINFUNC);
  78. /* Initialize GPIO */
  79. au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR);
  80. alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
  81. alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
  82. alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
  83. alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
  84. /* Enable LED and set it to green */
  85. alchemy_gpio_direction_output(211, 1); /* green on */
  86. alchemy_gpio_direction_output(212, 0); /* red off */
  87. pm_power_off = mtx1_power_off;
  88. _machine_halt = mtx1_power_off;
  89. _machine_restart = mtx1_reset;
  90. printk(KERN_INFO "4G Systems MTX-1 Board\n");
  91. }
  92. /******************************************************************************/
  93. static struct gpio_keys_button mtx1_gpio_button[] = {
  94. {
  95. .gpio = 207,
  96. .code = BTN_0,
  97. .desc = "System button",
  98. }
  99. };
  100. static struct gpio_keys_platform_data mtx1_buttons_data = {
  101. .buttons = mtx1_gpio_button,
  102. .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
  103. };
  104. static struct platform_device mtx1_button = {
  105. .name = "gpio-keys",
  106. .id = -1,
  107. .dev = {
  108. .platform_data = &mtx1_buttons_data,
  109. }
  110. };
  111. static struct resource mtx1_wdt_res[] = {
  112. [0] = {
  113. .start = 215,
  114. .end = 215,
  115. .name = "mtx1-wdt-gpio",
  116. .flags = IORESOURCE_IRQ,
  117. }
  118. };
  119. static struct platform_device mtx1_wdt = {
  120. .name = "mtx1-wdt",
  121. .id = 0,
  122. .num_resources = ARRAY_SIZE(mtx1_wdt_res),
  123. .resource = mtx1_wdt_res,
  124. };
  125. static struct gpio_led default_leds[] = {
  126. {
  127. .name = "mtx1:green",
  128. .gpio = 211,
  129. }, {
  130. .name = "mtx1:red",
  131. .gpio = 212,
  132. },
  133. };
  134. static struct gpio_led_platform_data mtx1_led_data = {
  135. .num_leds = ARRAY_SIZE(default_leds),
  136. .leds = default_leds,
  137. };
  138. static struct platform_device mtx1_gpio_leds = {
  139. .name = "leds-gpio",
  140. .id = -1,
  141. .dev = {
  142. .platform_data = &mtx1_led_data,
  143. }
  144. };
  145. static struct mtd_partition mtx1_mtd_partitions[] = {
  146. {
  147. .name = "filesystem",
  148. .size = 0x01C00000,
  149. .offset = 0,
  150. },
  151. {
  152. .name = "yamon",
  153. .size = 0x00100000,
  154. .offset = MTDPART_OFS_APPEND,
  155. .mask_flags = MTD_WRITEABLE,
  156. },
  157. {
  158. .name = "kernel",
  159. .size = 0x002c0000,
  160. .offset = MTDPART_OFS_APPEND,
  161. },
  162. {
  163. .name = "yamon env",
  164. .size = 0x00040000,
  165. .offset = MTDPART_OFS_APPEND,
  166. },
  167. };
  168. static struct physmap_flash_data mtx1_flash_data = {
  169. .width = 4,
  170. .nr_parts = 4,
  171. .parts = mtx1_mtd_partitions,
  172. };
  173. static struct resource mtx1_mtd_resource = {
  174. .start = 0x1e000000,
  175. .end = 0x1fffffff,
  176. .flags = IORESOURCE_MEM,
  177. };
  178. static struct platform_device mtx1_mtd = {
  179. .name = "physmap-flash",
  180. .dev = {
  181. .platform_data = &mtx1_flash_data,
  182. },
  183. .num_resources = 1,
  184. .resource = &mtx1_mtd_resource,
  185. };
  186. static struct resource alchemy_pci_host_res[] = {
  187. [0] = {
  188. .start = AU1500_PCI_PHYS_ADDR,
  189. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  190. .flags = IORESOURCE_MEM,
  191. },
  192. };
  193. static int mtx1_pci_idsel(unsigned int devsel, int assert)
  194. {
  195. /* This function is only necessary to support a proprietary Cardbus
  196. * adapter on the mtx-1 "singleboard" variant. It triggers a custom
  197. * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
  198. */
  199. udelay(1);
  200. if (assert && devsel != 0)
  201. /* Suppress signal to Cardbus */
  202. alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
  203. else
  204. alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
  205. udelay(1);
  206. return 1;
  207. }
  208. static const char mtx1_irqtab[][5] = {
  209. [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
  210. [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
  211. [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
  212. [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
  213. [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
  214. [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
  215. [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
  216. [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
  217. };
  218. static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  219. {
  220. return mtx1_irqtab[slot][pin];
  221. }
  222. static struct alchemy_pci_platdata mtx1_pci_pd = {
  223. .board_map_irq = mtx1_map_pci_irq,
  224. .board_pci_idsel = mtx1_pci_idsel,
  225. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  226. PCI_CONFIG_CH |
  227. #if defined(__MIPSEB__)
  228. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  229. #else
  230. 0,
  231. #endif
  232. };
  233. static struct platform_device mtx1_pci_host = {
  234. .dev.platform_data = &mtx1_pci_pd,
  235. .name = "alchemy-pci",
  236. .id = 0,
  237. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  238. .resource = alchemy_pci_host_res,
  239. };
  240. static struct platform_device *mtx1_devs[] __initdata = {
  241. &mtx1_pci_host,
  242. &mtx1_gpio_leds,
  243. &mtx1_wdt,
  244. &mtx1_button,
  245. &mtx1_mtd,
  246. };
  247. static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
  248. .phy_search_highest_addr = 1,
  249. .phy1_search_mac0 = 1,
  250. };
  251. static int __init mtx1_register_devices(void)
  252. {
  253. int rc;
  254. irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
  255. irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
  256. irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
  257. irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
  258. irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
  259. au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
  260. rc = gpio_request(mtx1_gpio_button[0].gpio,
  261. mtx1_gpio_button[0].desc);
  262. if (rc < 0) {
  263. printk(KERN_INFO "mtx1: failed to request %d\n",
  264. mtx1_gpio_button[0].gpio);
  265. goto out;
  266. }
  267. gpio_direction_input(mtx1_gpio_button[0].gpio);
  268. out:
  269. return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
  270. }
  271. arch_initcall(mtx1_register_devices);