platform.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * MTX-1 platform devices registration
  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/platform_device.h>
  22. #include <linux/leds.h>
  23. #include <linux/gpio.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/input.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/mtd/physmap.h>
  28. #include <mtd/mtd-abi.h>
  29. #include <asm/mach-au1x00/au1xxx_eth.h>
  30. static struct gpio_keys_button mtx1_gpio_button[] = {
  31. {
  32. .gpio = 207,
  33. .code = BTN_0,
  34. .desc = "System button",
  35. }
  36. };
  37. static struct gpio_keys_platform_data mtx1_buttons_data = {
  38. .buttons = mtx1_gpio_button,
  39. .nbuttons = ARRAY_SIZE(mtx1_gpio_button),
  40. };
  41. static struct platform_device mtx1_button = {
  42. .name = "gpio-keys",
  43. .id = -1,
  44. .dev = {
  45. .platform_data = &mtx1_buttons_data,
  46. }
  47. };
  48. static struct resource mtx1_wdt_res[] = {
  49. [0] = {
  50. .start = 215,
  51. .end = 215,
  52. .name = "mtx1-wdt-gpio",
  53. .flags = IORESOURCE_IRQ,
  54. }
  55. };
  56. static struct platform_device mtx1_wdt = {
  57. .name = "mtx1-wdt",
  58. .id = 0,
  59. .num_resources = ARRAY_SIZE(mtx1_wdt_res),
  60. .resource = mtx1_wdt_res,
  61. };
  62. static struct gpio_led default_leds[] = {
  63. {
  64. .name = "mtx1:green",
  65. .gpio = 211,
  66. }, {
  67. .name = "mtx1:red",
  68. .gpio = 212,
  69. },
  70. };
  71. static struct gpio_led_platform_data mtx1_led_data = {
  72. .num_leds = ARRAY_SIZE(default_leds),
  73. .leds = default_leds,
  74. };
  75. static struct platform_device mtx1_gpio_leds = {
  76. .name = "leds-gpio",
  77. .id = -1,
  78. .dev = {
  79. .platform_data = &mtx1_led_data,
  80. }
  81. };
  82. static struct mtd_partition mtx1_mtd_partitions[] = {
  83. {
  84. .name = "filesystem",
  85. .size = 0x01C00000,
  86. .offset = 0,
  87. },
  88. {
  89. .name = "yamon",
  90. .size = 0x00100000,
  91. .offset = MTDPART_OFS_APPEND,
  92. .mask_flags = MTD_WRITEABLE,
  93. },
  94. {
  95. .name = "kernel",
  96. .size = 0x002c0000,
  97. .offset = MTDPART_OFS_APPEND,
  98. },
  99. {
  100. .name = "yamon env",
  101. .size = 0x00040000,
  102. .offset = MTDPART_OFS_APPEND,
  103. },
  104. };
  105. static struct physmap_flash_data mtx1_flash_data = {
  106. .width = 4,
  107. .nr_parts = 4,
  108. .parts = mtx1_mtd_partitions,
  109. };
  110. static struct resource mtx1_mtd_resource = {
  111. .start = 0x1e000000,
  112. .end = 0x1fffffff,
  113. .flags = IORESOURCE_MEM,
  114. };
  115. static struct platform_device mtx1_mtd = {
  116. .name = "physmap-flash",
  117. .dev = {
  118. .platform_data = &mtx1_flash_data,
  119. },
  120. .num_resources = 1,
  121. .resource = &mtx1_mtd_resource,
  122. };
  123. static struct resource alchemy_pci_host_res[] = {
  124. [0] = {
  125. .start = AU1500_PCI_PHYS_ADDR,
  126. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  127. .flags = IORESOURCE_MEM,
  128. },
  129. };
  130. static int mtx1_pci_idsel(unsigned int devsel, int assert)
  131. {
  132. /* This function is only necessary to support a proprietary Cardbus
  133. * adapter on the mtx-1 "singleboard" variant. It triggers a custom
  134. * logic chip connected to EXT_IO3 (GPIO1) to suppress IDSEL signals.
  135. */
  136. if (assert && devsel != 0)
  137. /* Suppress signal to Cardbus */
  138. alchemy_gpio_set_value(1, 0); /* set EXT_IO3 OFF */
  139. else
  140. alchemy_gpio_set_value(1, 1); /* set EXT_IO3 ON */
  141. udelay(1);
  142. return 1;
  143. }
  144. static const char mtx1_irqtab[][5] = {
  145. [0] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 00 - AdapterA-Slot0 (top) */
  146. [1] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 01 - AdapterA-Slot1 (bottom) */
  147. [2] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 02 - AdapterB-Slot0 (top) */
  148. [3] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 03 - AdapterB-Slot1 (bottom) */
  149. [4] = { -1, AU1500_PCI_INTA, AU1500_PCI_INTB, 0xff, 0xff }, /* IDSEL 04 - AdapterC-Slot0 (top) */
  150. [5] = { -1, AU1500_PCI_INTB, AU1500_PCI_INTA, 0xff, 0xff }, /* IDSEL 05 - AdapterC-Slot1 (bottom) */
  151. [6] = { -1, AU1500_PCI_INTC, AU1500_PCI_INTD, 0xff, 0xff }, /* IDSEL 06 - AdapterD-Slot0 (top) */
  152. [7] = { -1, AU1500_PCI_INTD, AU1500_PCI_INTC, 0xff, 0xff }, /* IDSEL 07 - AdapterD-Slot1 (bottom) */
  153. };
  154. static int mtx1_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  155. {
  156. return mtx1_irqtab[slot][pin];
  157. }
  158. static struct alchemy_pci_platdata mtx1_pci_pd = {
  159. .board_map_irq = mtx1_map_pci_irq,
  160. .board_pci_idsel = mtx1_pci_idsel,
  161. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  162. PCI_CONFIG_CH |
  163. #if defined(__MIPSEB__)
  164. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  165. #else
  166. 0,
  167. #endif
  168. };
  169. static struct platform_device mtx1_pci_host = {
  170. .dev.platform_data = &mtx1_pci_pd,
  171. .name = "alchemy-pci",
  172. .id = 0,
  173. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  174. .resource = alchemy_pci_host_res,
  175. };
  176. static struct __initdata platform_device * mtx1_devs[] = {
  177. &mtx1_pci_host,
  178. &mtx1_gpio_leds,
  179. &mtx1_wdt,
  180. &mtx1_button,
  181. &mtx1_mtd,
  182. };
  183. static struct au1000_eth_platform_data mtx1_au1000_eth0_pdata = {
  184. .phy_search_highest_addr = 1,
  185. .phy1_search_mac0 = 1,
  186. };
  187. static int __init mtx1_register_devices(void)
  188. {
  189. int rc;
  190. au1xxx_override_eth_cfg(0, &mtx1_au1000_eth0_pdata);
  191. rc = gpio_request(mtx1_gpio_button[0].gpio,
  192. mtx1_gpio_button[0].desc);
  193. if (rc < 0) {
  194. printk(KERN_INFO "mtx1: failed to request %d\n",
  195. mtx1_gpio_button[0].gpio);
  196. goto out;
  197. }
  198. gpio_direction_input(mtx1_gpio_button[0].gpio);
  199. out:
  200. return platform_add_devices(mtx1_devs, ARRAY_SIZE(mtx1_devs));
  201. }
  202. arch_initcall(mtx1_register_devices);