board-mtx1.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * MTX-1 platform devices registration (Au1500)
  4. *
  5. * Copyright (C) 2007-2009, Florian Fainelli <[email protected]>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/kernel.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/leds.h>
  12. #include <linux/gpio.h>
  13. #include <linux/gpio/machine.h>
  14. #include <linux/gpio_keys.h>
  15. #include <linux/input.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/mtd/physmap.h>
  18. #include <mtd/mtd-abi.h>
  19. #include <asm/bootinfo.h>
  20. #include <asm/reboot.h>
  21. #include <asm/setup.h>
  22. #include <asm/mach-au1x00/au1000.h>
  23. #include <asm/mach-au1x00/gpio-au1000.h>
  24. #include <asm/mach-au1x00/au1xxx_eth.h>
  25. #include <prom.h>
  26. const char *get_system_type(void)
  27. {
  28. return "MTX-1";
  29. }
  30. void prom_putchar(char c)
  31. {
  32. alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c);
  33. }
  34. static void mtx1_reset(char *c)
  35. {
  36. /* Jump to the reset vector */
  37. __asm__ __volatile__("jr\t%0" : : "r"(0xbfc00000));
  38. }
  39. static void mtx1_power_off(void)
  40. {
  41. while (1)
  42. asm volatile (
  43. " .set mips32 \n"
  44. " wait \n"
  45. " .set mips0 \n");
  46. }
  47. void __init board_setup(void)
  48. {
  49. #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
  50. /* Enable USB power switch */
  51. alchemy_gpio_direction_output(204, 0);
  52. #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
  53. /* Initialize sys_pinfunc */
  54. alchemy_wrsys(SYS_PF_NI2, AU1000_SYS_PINFUNC);
  55. /* Initialize GPIO */
  56. alchemy_wrsys(~0, AU1000_SYS_TRIOUTCLR);
  57. alchemy_gpio_direction_output(0, 0); /* Disable M66EN (PCI 66MHz) */
  58. alchemy_gpio_direction_output(3, 1); /* Disable PCI CLKRUN# */
  59. alchemy_gpio_direction_output(1, 1); /* Enable EXT_IO3 */
  60. alchemy_gpio_direction_output(5, 0); /* Disable eth PHY TX_ER */
  61. /* Enable LED and set it to green */
  62. alchemy_gpio_direction_output(211, 1); /* green on */
  63. alchemy_gpio_direction_output(212, 0); /* red off */
  64. pm_power_off = mtx1_power_off;
  65. _machine_halt = mtx1_power_off;
  66. _machine_restart = mtx1_reset;
  67. printk(KERN_INFO "4G Systems MTX-1 Board\n");
  68. }
  69. /******************************************************************************/
  70. static struct gpio_keys_button mtx1_gpio_button[] = {
  71. {
  72. .gpio = 207,
  73. .code = BTN_0,
  74. .desc = "System button",
  75. }
  76. };
  77. static struct gpio_keys_platform_data mtx1_buttons_data = {
  78. .buttons = mtx1_gpio_button,
  79. .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
  80. };
  81. static struct platform_device mtx1_button = {
  82. .name = "gpio-keys",
  83. .id = -1,
  84. .dev = {
  85. .platform_data = &mtx1_buttons_data,
  86. }
  87. };
  88. static struct gpiod_lookup_table mtx1_wdt_gpio_table = {
  89. .dev_id = "mtx1-wdt.0",
  90. .table = {
  91. /* Global number 215 is offset 15 on Alchemy GPIO 2 */
  92. GPIO_LOOKUP("alchemy-gpio2", 15, NULL, GPIO_ACTIVE_HIGH),
  93. { },
  94. },
  95. };
  96. static struct platform_device mtx1_wdt = {
  97. .name = "mtx1-wdt",
  98. .id = 0,
  99. };
  100. static const struct gpio_led default_leds[] = {
  101. {
  102. .name = "mtx1:green",
  103. .gpio = 211,
  104. }, {
  105. .name = "mtx1:red",
  106. .gpio = 212,
  107. },
  108. };
  109. static struct gpio_led_platform_data mtx1_led_data = {
  110. .num_leds = ARRAY_SIZE(default_leds),
  111. .leds = default_leds,
  112. };
  113. static struct platform_device mtx1_gpio_leds = {
  114. .name = "leds-gpio",
  115. .id = -1,
  116. .dev = {
  117. .platform_data = &mtx1_led_data,
  118. }
  119. };
  120. static struct mtd_partition mtx1_mtd_partitions[] = {
  121. {
  122. .name = "filesystem",
  123. .size = 0x01C00000,
  124. .offset = 0,
  125. },
  126. {
  127. .name = "yamon",
  128. .size = 0x00100000,
  129. .offset = MTDPART_OFS_APPEND,
  130. .mask_flags = MTD_WRITEABLE,
  131. },
  132. {
  133. .name = "kernel",
  134. .size = 0x002c0000,
  135. .offset = MTDPART_OFS_APPEND,
  136. },
  137. {
  138. .name = "yamon env",
  139. .size = 0x00040000,
  140. .offset = MTDPART_OFS_APPEND,
  141. },
  142. };
  143. static struct physmap_flash_data mtx1_flash_data = {
  144. .width = 4,
  145. .nr_parts = 4,
  146. .parts = mtx1_mtd_partitions,
  147. };
  148. static struct resource mtx1_mtd_resource = {
  149. .start = 0x1e000000,
  150. .end = 0x1fffffff,
  151. .flags = IORESOURCE_MEM,
  152. };
  153. static struct platform_device mtx1_mtd = {
  154. .name = "physmap-flash",
  155. .dev = {
  156. .platform_data = &mtx1_flash_data,
  157. },
  158. .num_resources = 1,
  159. .resource = &mtx1_mtd_resource,
  160. };
  161. static struct resource alchemy_pci_host_res[] = {
  162. [0] = {
  163. .start = AU1500_PCI_PHYS_ADDR,
  164. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. };
  168. static int mtx1_pci_idsel(unsigned int devsel, int assert)
  169. {
  170. /* This function is only necessary to support a proprietary Cardbus
  171. * adapter on the mtx-1 "singleboard" variant. It triggers a custom
  172. * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
  173. */
  174. udelay(1);
  175. if (assert && devsel != 0)
  176. /* Suppress signal to Cardbus */
  177. alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
  178. else
  179. alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
  180. udelay(1);
  181. return 1;
  182. }
  183. static const char mtx1_irqtab[][5] = {
  184. [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
  185. [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
  186. [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
  187. [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
  188. [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
  189. [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
  190. [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
  191. [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
  192. };
  193. static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  194. {
  195. return mtx1_irqtab[slot][pin];
  196. }
  197. static struct alchemy_pci_platdata mtx1_pci_pd = {
  198. .board_map_irq = mtx1_map_pci_irq,
  199. .board_pci_idsel = mtx1_pci_idsel,
  200. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  201. PCI_CONFIG_CH |
  202. #if defined(__MIPSEB__)
  203. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  204. #else
  205. 0,
  206. #endif
  207. };
  208. static struct platform_device mtx1_pci_host = {
  209. .dev.platform_data = &mtx1_pci_pd,
  210. .name = "alchemy-pci",
  211. .id = 0,
  212. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  213. .resource = alchemy_pci_host_res,
  214. };
  215. static struct platform_device *mtx1_devs[] __initdata = {
  216. &mtx1_pci_host,
  217. &mtx1_gpio_leds,
  218. &mtx1_wdt,
  219. &mtx1_button,
  220. &mtx1_mtd,
  221. };
  222. static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
  223. .phy_search_highest_addr = 1,
  224. .phy1_search_mac0 = 1,
  225. };
  226. static int __init mtx1_register_devices(void)
  227. {
  228. int rc;
  229. irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_HIGH);
  230. irq_set_irq_type(AU1500_GPIO201_INT, IRQ_TYPE_LEVEL_LOW);
  231. irq_set_irq_type(AU1500_GPIO202_INT, IRQ_TYPE_LEVEL_LOW);
  232. irq_set_irq_type(AU1500_GPIO203_INT, IRQ_TYPE_LEVEL_LOW);
  233. irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
  234. au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
  235. rc = gpio_request(mtx1_gpio_button[0].gpio,
  236. mtx1_gpio_button[0].desc);
  237. if (rc < 0) {
  238. printk(KERN_INFO "mtx1: failed to request %d\n",
  239. mtx1_gpio_button[0].gpio);
  240. goto out;
  241. }
  242. gpio_direction_input(mtx1_gpio_button[0].gpio);
  243. out:
  244. gpiod_add_lookup_table(&mtx1_wdt_gpio_table);
  245. return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
  246. }
  247. arch_initcall(mtx1_register_devices);