mach-archer-c25-v1.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * TP-Link Archer C25 v1 board support
  3. *
  4. * Copyright (C) 2017 Ludwig Thomeczek <ledesrc@wxorx.net>
  5. * based on mach-archer-c60/C59-v1.c
  6. * Copyright (C) 2016 Henryk Heisig <hyniu@o2.pl>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/ath9k_platform.h>
  14. #include <linux/ar8216_platform.h>
  15. #include <asm/mach-ath79/ar71xx_regs.h>
  16. #include <linux/gpio.h>
  17. #include "common.h"
  18. #include "dev-m25p80.h"
  19. #include "machtypes.h"
  20. #include "pci.h"
  21. #include "dev-ap9x-pci.h"
  22. #include "dev-eth.h"
  23. #include "dev-gpio-buttons.h"
  24. #include "dev-leds-gpio.h"
  25. #include "dev-spi.h"
  26. #include "dev-usb.h"
  27. #include "dev-wmac.h"
  28. #include <linux/spi/spi_gpio.h>
  29. #include <linux/spi/74x164.h>
  30. #define ARCHER_C25_GPIO_SHIFT_OE 21 /* OE, Output Enable */
  31. #define ARCHER_C25_GPIO_SHIFT_SER 14 /* DS, Data Serial Input */
  32. #define ARCHER_C25_GPIO_SHIFT_SRCLK 15 /* SHCP, Shift Reg Clock Input */
  33. #define ARCHER_C25_GPIO_SHIFT_SRCLR 19 /* MR, Master Reset */
  34. #define ARCHER_C25_GPIO_SHIFT_RCLK 16 /* STCP, Storage Reg Clock Input */
  35. #define ARCHER_C25_74HC_GPIO_BASE 32
  36. #define ARCHER_C25_74HC_GPIO_LED_WAN_AMBER (ARCHER_C25_74HC_GPIO_BASE + 4)
  37. #define ARCHER_C25_74HC_GPIO_LED_WAN_GREEN (ARCHER_C25_74HC_GPIO_BASE + 5)
  38. #define ARCHER_C25_74HC_GPIO_LED_WLAN2 (ARCHER_C25_74HC_GPIO_BASE + 6)
  39. #define ARCHER_C25_74HC_GPIO_LED_WLAN5 (ARCHER_C25_74HC_GPIO_BASE + 7)
  40. #define ARCHER_C25_74HC_GPIO_LED_LAN1 (ARCHER_C25_74HC_GPIO_BASE + 0)
  41. #define ARCHER_C25_74HC_GPIO_LED_LAN2 (ARCHER_C25_74HC_GPIO_BASE + 1)
  42. #define ARCHER_C25_74HC_GPIO_LED_LAN3 (ARCHER_C25_74HC_GPIO_BASE + 2)
  43. #define ARCHER_C25_74HC_GPIO_LED_LAN4 (ARCHER_C25_74HC_GPIO_BASE + 3)
  44. #define ARCHER_C25_V1_SSR_BIT_0 0
  45. #define ARCHER_C25_V1_SSR_BIT_1 1
  46. #define ARCHER_C25_V1_SSR_BIT_2 2
  47. #define ARCHER_C25_V1_SSR_BIT_3 3
  48. #define ARCHER_C25_V1_SSR_BIT_4 4
  49. #define ARCHER_C25_V1_SSR_BIT_5 5
  50. #define ARCHER_C25_V1_SSR_BIT_6 6
  51. #define ARCHER_C25_V1_SSR_BIT_7 7
  52. #define ARCHER_C25_V1_KEYS_POLL_INTERVAL 20
  53. #define ARCHER_C25_V1_KEYS_DEBOUNCE_INTERVAL \
  54. (3 * ARCHER_C25_V1_KEYS_POLL_INTERVAL)
  55. #define ARCHER_C25_V1_GPIO_BTN_RESET 1
  56. #define ARCHER_C25_V1_GPIO_BTN_RFKILL 22
  57. #define ARCHER_C25_V1_GPIO_LED_POWER 17
  58. #define ARCHER_C25_V1_GPIO_LED_WPS 2
  59. #define ARCHER_C25_V1_WMAC_CALDATA_OFFSET 0x1000
  60. static struct spi_gpio_platform_data archer_c25_v1_spi_data = {
  61. .sck = ARCHER_C25_GPIO_SHIFT_SRCLK,
  62. .miso = SPI_GPIO_NO_MISO,
  63. .mosi = ARCHER_C25_GPIO_SHIFT_SER,
  64. .num_chipselect = 1,
  65. };
  66. static u8 archer_c25_v1_ssr_initdata[] = {
  67. BIT(ARCHER_C25_V1_SSR_BIT_7) |
  68. BIT(ARCHER_C25_V1_SSR_BIT_6) |
  69. BIT(ARCHER_C25_V1_SSR_BIT_5) |
  70. BIT(ARCHER_C25_V1_SSR_BIT_4) |
  71. BIT(ARCHER_C25_V1_SSR_BIT_3) |
  72. BIT(ARCHER_C25_V1_SSR_BIT_2) |
  73. BIT(ARCHER_C25_V1_SSR_BIT_1)
  74. };
  75. static struct gen_74x164_chip_platform_data archer_c25_v1_ssr_data = {
  76. .base = ARCHER_C25_74HC_GPIO_BASE,
  77. .num_registers = ARRAY_SIZE(archer_c25_v1_ssr_initdata),
  78. .init_data = archer_c25_v1_ssr_initdata,
  79. };
  80. static struct platform_device archer_c25_v1_spi_device = {
  81. .name = "spi_gpio",
  82. .id = 1,
  83. .dev = {
  84. .platform_data = &archer_c25_v1_spi_data,
  85. },
  86. };
  87. static struct spi_board_info archer_c25_v1_spi_info[] = {
  88. {
  89. .bus_num = 1,
  90. .chip_select = 0,
  91. .max_speed_hz = 10000000,
  92. .modalias = "74x164",
  93. .platform_data = &archer_c25_v1_ssr_data,
  94. .controller_data = (void *) ARCHER_C25_GPIO_SHIFT_RCLK,
  95. },
  96. };
  97. static struct gpio_led archer_c25_v1_leds_gpio[] __initdata = {
  98. {
  99. .name = "archer-c25-v1:green:power",
  100. .gpio = ARCHER_C25_V1_GPIO_LED_POWER,
  101. .active_low = 1,
  102. }, {
  103. .name = "archer-c25-v1:green:wps",
  104. .gpio = ARCHER_C25_V1_GPIO_LED_WPS,
  105. .active_low = 1,
  106. }, {
  107. .name = "archer-c25-v1:green:wlan2g",
  108. .gpio = ARCHER_C25_74HC_GPIO_LED_WLAN2,
  109. .active_low = 1,
  110. }, {
  111. .name = "archer-c25-v1:green:wlan5g",
  112. .gpio = ARCHER_C25_74HC_GPIO_LED_WLAN5,
  113. .active_low = 1,
  114. }, {
  115. .name = "archer-c25-v1:green:lan1",
  116. .gpio = ARCHER_C25_74HC_GPIO_LED_LAN1,
  117. .active_low = 1,
  118. }, {
  119. .name = "archer-c25-v1:green:lan2",
  120. .gpio = ARCHER_C25_74HC_GPIO_LED_LAN2,
  121. .active_low = 1,
  122. }, {
  123. .name = "archer-c25-v1:green:lan3",
  124. .gpio = ARCHER_C25_74HC_GPIO_LED_LAN3,
  125. .active_low = 1,
  126. }, {
  127. .name = "archer-c25-v1:green:lan4",
  128. .gpio = ARCHER_C25_74HC_GPIO_LED_LAN4,
  129. .active_low = 1,
  130. }, {
  131. .name = "archer-c25-v1:green:wan",
  132. .gpio = ARCHER_C25_74HC_GPIO_LED_WAN_GREEN,
  133. .active_low = 1,
  134. }, {
  135. .name = "archer-c25-v1:amber:wan",
  136. .gpio = ARCHER_C25_74HC_GPIO_LED_WAN_AMBER,
  137. .active_low = 1,
  138. },
  139. };
  140. static struct gpio_keys_button archer_c25_v1_gpio_keys[] __initdata = {
  141. {
  142. .desc = "Reset button",
  143. .type = EV_KEY,
  144. .code = KEY_RESTART,
  145. .debounce_interval = ARCHER_C25_V1_KEYS_DEBOUNCE_INTERVAL,
  146. .gpio = ARCHER_C25_V1_GPIO_BTN_RESET,
  147. .active_low = 1,
  148. }, {
  149. .desc = "RFKILL button",
  150. .type = EV_KEY,
  151. .code = KEY_RFKILL,
  152. .debounce_interval = ARCHER_C25_V1_KEYS_DEBOUNCE_INTERVAL,
  153. .gpio = ARCHER_C25_V1_GPIO_BTN_RFKILL,
  154. .active_low = 1,
  155. },
  156. };
  157. static void __init archer_c25_v1_setup(void)
  158. {
  159. u8 *mac = (u8 *) KSEG1ADDR(0x1f7e0008);
  160. u8 *art = (u8 *) KSEG1ADDR(0x1f7f0000);
  161. ath79_register_m25p80(NULL);
  162. spi_register_board_info(archer_c25_v1_spi_info,
  163. ARRAY_SIZE(archer_c25_v1_spi_info));
  164. platform_device_register(&archer_c25_v1_spi_device);
  165. gpio_request_one(ARCHER_C25_GPIO_SHIFT_OE,
  166. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
  167. "LED control");
  168. gpio_request_one(ARCHER_C25_GPIO_SHIFT_SRCLR,
  169. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  170. "LED reset");
  171. ath79_register_leds_gpio(-1, ARRAY_SIZE(archer_c25_v1_leds_gpio),
  172. archer_c25_v1_leds_gpio);
  173. ath79_register_gpio_keys_polled(-1, ARCHER_C25_V1_KEYS_POLL_INTERVAL,
  174. ARRAY_SIZE(archer_c25_v1_gpio_keys),
  175. archer_c25_v1_gpio_keys);
  176. ath79_register_mdio(0, 0x0);
  177. ath79_register_mdio(1, 0x0);
  178. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  179. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 1);
  180. /* WAN port */
  181. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  182. ath79_eth0_data.speed = SPEED_100;
  183. ath79_eth0_data.duplex = DUPLEX_FULL;
  184. ath79_eth0_data.phy_mask = BIT(4);
  185. ath79_register_eth(0);
  186. /* LAN ports */
  187. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  188. ath79_eth1_data.speed = SPEED_1000;
  189. ath79_eth1_data.duplex = DUPLEX_FULL;
  190. ath79_switch_data.phy_poll_mask |= BIT(4);
  191. ath79_switch_data.phy4_mii_en = 1;
  192. ath79_register_eth(1);
  193. ath79_register_wmac(art + ARCHER_C25_V1_WMAC_CALDATA_OFFSET, mac);
  194. ap91_pci_init(NULL, NULL);
  195. }
  196. MIPS_MACHINE(ATH79_MACH_ARCHER_C25_V1, "ARCHER-C25-V1", "TP-LINK Archer C25 v1",
  197. archer_c25_v1_setup);