wrt350n-v2-setup.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // arch/arm/mach-orion5x/wrt350n-v2-setup.c
  3. #include <linux/gpio.h>
  4. #include <linux/kernel.h>
  5. #include <linux/init.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/pci.h>
  8. #include <linux/irq.h>
  9. #include <linux/delay.h>
  10. #include <linux/mtd/physmap.h>
  11. #include <linux/mv643xx_eth.h>
  12. #include <linux/ethtool.h>
  13. #include <linux/leds.h>
  14. #include <linux/gpio_keys.h>
  15. #include <linux/input.h>
  16. #include <linux/platform_data/dsa.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/mach/arch.h>
  19. #include <asm/mach/pci.h>
  20. #include "orion5x.h"
  21. #include "common.h"
  22. #include "mpp.h"
  23. /*
  24. * LEDs attached to GPIO
  25. */
  26. static struct gpio_led wrt350n_v2_led_pins[] = {
  27. {
  28. .name = "wrt350nv2:green:power",
  29. .gpio = 0,
  30. .active_low = 1,
  31. }, {
  32. .name = "wrt350nv2:green:security",
  33. .gpio = 1,
  34. .active_low = 1,
  35. }, {
  36. .name = "wrt350nv2:orange:power",
  37. .gpio = 5,
  38. .active_low = 1,
  39. }, {
  40. .name = "wrt350nv2:green:usb",
  41. .gpio = 6,
  42. .active_low = 1,
  43. }, {
  44. .name = "wrt350nv2:green:wireless",
  45. .gpio = 7,
  46. .active_low = 1,
  47. },
  48. };
  49. static struct gpio_led_platform_data wrt350n_v2_led_data = {
  50. .leds = wrt350n_v2_led_pins,
  51. .num_leds = ARRAY_SIZE(wrt350n_v2_led_pins),
  52. };
  53. static struct platform_device wrt350n_v2_leds = {
  54. .name = "leds-gpio",
  55. .id = -1,
  56. .dev = {
  57. .platform_data = &wrt350n_v2_led_data,
  58. },
  59. };
  60. /*
  61. * Buttons attached to GPIO
  62. */
  63. static struct gpio_keys_button wrt350n_v2_buttons[] = {
  64. {
  65. .code = KEY_RESTART,
  66. .gpio = 3,
  67. .desc = "Reset Button",
  68. .active_low = 1,
  69. }, {
  70. .code = KEY_WPS_BUTTON,
  71. .gpio = 2,
  72. .desc = "WPS Button",
  73. .active_low = 1,
  74. },
  75. };
  76. static struct gpio_keys_platform_data wrt350n_v2_button_data = {
  77. .buttons = wrt350n_v2_buttons,
  78. .nbuttons = ARRAY_SIZE(wrt350n_v2_buttons),
  79. };
  80. static struct platform_device wrt350n_v2_button_device = {
  81. .name = "gpio-keys",
  82. .id = -1,
  83. .num_resources = 0,
  84. .dev = {
  85. .platform_data = &wrt350n_v2_button_data,
  86. },
  87. };
  88. /*
  89. * General setup
  90. */
  91. static unsigned int wrt350n_v2_mpp_modes[] __initdata = {
  92. MPP0_GPIO, /* Power LED green (0=on) */
  93. MPP1_GPIO, /* Security LED (0=on) */
  94. MPP2_GPIO, /* Internal Button (0=on) */
  95. MPP3_GPIO, /* Reset Button (0=on) */
  96. MPP4_GPIO, /* PCI int */
  97. MPP5_GPIO, /* Power LED orange (0=on) */
  98. MPP6_GPIO, /* USB LED (0=on) */
  99. MPP7_GPIO, /* Wireless LED (0=on) */
  100. MPP8_UNUSED, /* ??? */
  101. MPP9_GIGE, /* GE_RXERR */
  102. MPP10_UNUSED, /* ??? */
  103. MPP11_UNUSED, /* ??? */
  104. MPP12_GIGE, /* GE_TXD[4] */
  105. MPP13_GIGE, /* GE_TXD[5] */
  106. MPP14_GIGE, /* GE_TXD[6] */
  107. MPP15_GIGE, /* GE_TXD[7] */
  108. MPP16_GIGE, /* GE_RXD[4] */
  109. MPP17_GIGE, /* GE_RXD[5] */
  110. MPP18_GIGE, /* GE_RXD[6] */
  111. MPP19_GIGE, /* GE_RXD[7] */
  112. 0,
  113. };
  114. /*
  115. * 8M NOR flash Device bus boot chip select
  116. */
  117. #define WRT350N_V2_NOR_BOOT_BASE 0xf4000000
  118. #define WRT350N_V2_NOR_BOOT_SIZE SZ_8M
  119. static struct mtd_partition wrt350n_v2_nor_flash_partitions[] = {
  120. {
  121. .name = "kernel",
  122. .offset = 0x00000000,
  123. .size = 0x00760000,
  124. }, {
  125. .name = "rootfs",
  126. .offset = 0x001a0000,
  127. .size = 0x005c0000,
  128. }, {
  129. .name = "lang",
  130. .offset = 0x00760000,
  131. .size = 0x00040000,
  132. }, {
  133. .name = "nvram",
  134. .offset = 0x007a0000,
  135. .size = 0x00020000,
  136. }, {
  137. .name = "u-boot",
  138. .offset = 0x007c0000,
  139. .size = 0x00040000,
  140. },
  141. };
  142. static struct physmap_flash_data wrt350n_v2_nor_flash_data = {
  143. .width = 1,
  144. .parts = wrt350n_v2_nor_flash_partitions,
  145. .nr_parts = ARRAY_SIZE(wrt350n_v2_nor_flash_partitions),
  146. };
  147. static struct resource wrt350n_v2_nor_flash_resource = {
  148. .flags = IORESOURCE_MEM,
  149. .start = WRT350N_V2_NOR_BOOT_BASE,
  150. .end = WRT350N_V2_NOR_BOOT_BASE + WRT350N_V2_NOR_BOOT_SIZE - 1,
  151. };
  152. static struct platform_device wrt350n_v2_nor_flash = {
  153. .name = "physmap-flash",
  154. .id = 0,
  155. .dev = {
  156. .platform_data = &wrt350n_v2_nor_flash_data,
  157. },
  158. .num_resources = 1,
  159. .resource = &wrt350n_v2_nor_flash_resource,
  160. };
  161. static struct mv643xx_eth_platform_data wrt350n_v2_eth_data = {
  162. .phy_addr = MV643XX_ETH_PHY_NONE,
  163. .speed = SPEED_1000,
  164. .duplex = DUPLEX_FULL,
  165. };
  166. static struct dsa_chip_data wrt350n_v2_switch_chip_data = {
  167. .port_names[0] = "lan2",
  168. .port_names[1] = "lan1",
  169. .port_names[2] = "wan",
  170. .port_names[3] = "cpu",
  171. .port_names[5] = "lan3",
  172. .port_names[7] = "lan4",
  173. };
  174. static void __init wrt350n_v2_init(void)
  175. {
  176. /*
  177. * Setup basic Orion functions. Need to be called early.
  178. */
  179. orion5x_init();
  180. orion5x_mpp_conf(wrt350n_v2_mpp_modes);
  181. /*
  182. * Configure peripherals.
  183. */
  184. orion5x_ehci0_init();
  185. orion5x_eth_init(&wrt350n_v2_eth_data);
  186. orion5x_eth_switch_init(&wrt350n_v2_switch_chip_data);
  187. orion5x_uart0_init();
  188. mvebu_mbus_add_window_by_id(ORION_MBUS_DEVBUS_BOOT_TARGET,
  189. ORION_MBUS_DEVBUS_BOOT_ATTR,
  190. WRT350N_V2_NOR_BOOT_BASE,
  191. WRT350N_V2_NOR_BOOT_SIZE);
  192. platform_device_register(&wrt350n_v2_nor_flash);
  193. platform_device_register(&wrt350n_v2_leds);
  194. platform_device_register(&wrt350n_v2_button_device);
  195. }
  196. static int __init wrt350n_v2_pci_map_irq(const struct pci_dev *dev, u8 slot,
  197. u8 pin)
  198. {
  199. int irq;
  200. /*
  201. * Check for devices with hard-wired IRQs.
  202. */
  203. irq = orion5x_pci_map_irq(dev, slot, pin);
  204. if (irq != -1)
  205. return irq;
  206. /*
  207. * Mini-PCI slot.
  208. */
  209. if (slot == 7)
  210. return gpio_to_irq(4);
  211. return -1;
  212. }
  213. static struct hw_pci wrt350n_v2_pci __initdata = {
  214. .nr_controllers = 2,
  215. .setup = orion5x_pci_sys_setup,
  216. .scan = orion5x_pci_sys_scan_bus,
  217. .map_irq = wrt350n_v2_pci_map_irq,
  218. };
  219. static int __init wrt350n_v2_pci_init(void)
  220. {
  221. if (machine_is_wrt350n_v2())
  222. pci_common_init(&wrt350n_v2_pci);
  223. return 0;
  224. }
  225. subsys_initcall(wrt350n_v2_pci_init);
  226. MACHINE_START(WRT350N_V2, "Linksys WRT350N v2")
  227. /* Maintainer: Lennert Buytenhek <[email protected]> */
  228. .atag_offset = 0x100,
  229. .nr_irqs = ORION5X_NR_IRQS,
  230. .init_machine = wrt350n_v2_init,
  231. .map_io = orion5x_map_io,
  232. .init_early = orion5x_init_early,
  233. .init_irq = orion5x_init_irq,
  234. .init_time = orion5x_timer_init,
  235. .fixup = tag_fixup_mem32,
  236. .restart = orion5x_restart,
  237. MACHINE_END