mach-rut9xx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Teltonika RUT900 series boards support
  3. *
  4. * Copyright (C) 2018 Piotr Dymacz <pepe2k@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <linux/i2c.h>
  12. #include <linux/i2c-algo-bit.h>
  13. #include <linux/i2c-gpio.h>
  14. #include <linux/platform_data/pca953x.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/mach-ath79/ath79.h>
  17. #include <asm/mach-ath79/ar71xx_regs.h>
  18. #include "common.h"
  19. #include "dev-eth.h"
  20. #include "dev-gpio-buttons.h"
  21. #include "dev-leds-gpio.h"
  22. #include "dev-m25p80.h"
  23. #include "dev-usb.h"
  24. #include "dev-wmac.h"
  25. #include "machtypes.h"
  26. #define RUT9XX_GPIO_LED_LAN1 14
  27. #define RUT9XX_GPIO_LED_LAN2 13
  28. #define RUT9XX_GPIO_LED_LAN3 22
  29. #define RUT9XX_GPIO_LED_WAN 1
  30. #define RUT9XX_PCA9539_GPIO_BASE 32
  31. #define RUT9XX_PCA9539_GPIO_SIGNAL1 (0 + RUT9XX_PCA9539_GPIO_BASE)
  32. #define RUT9XX_PCA9539_GPIO_SIGNAL2 (1 + RUT9XX_PCA9539_GPIO_BASE)
  33. #define RUT9XX_PCA9539_GPIO_SIGNAL3 (2 + RUT9XX_PCA9539_GPIO_BASE)
  34. #define RUT9XX_PCA9539_GPIO_SIGNAL4 (3 + RUT9XX_PCA9539_GPIO_BASE)
  35. #define RUT9XX_PCA9539_GPIO_SIGNAL5 (4 + RUT9XX_PCA9539_GPIO_BASE)
  36. #define RUT9XX_PCA9539_GPIO_STATUS_R (5 + RUT9XX_PCA9539_GPIO_BASE)
  37. #define RUT9XX_PCA9539_GPIO_STATUS_G (6 + RUT9XX_PCA9539_GPIO_BASE)
  38. #define RUT9XX_GPIO_BTN_RESET 15
  39. #define RUT9XX_GPIO_I2C_SCK 16
  40. #define RUT9XX_GPIO_I2C_SDA 17
  41. #define RUT9XX_GPIO_EXT_LNA0 2
  42. #define RUT9XX_WMAC_CALDATA_OFFSET 0x1000
  43. #define RUT9XX_KEYS_POLL_INTERVAL 20
  44. #define RUT9XX_KEYS_DEBOUNCE_INTERVAL (3 * RUT9XX_KEYS_POLL_INTERVAL)
  45. static struct gpio_led rut900_leds_gpio[] __initdata = {
  46. {
  47. .name = "rut900:green:lan1",
  48. .gpio = RUT9XX_GPIO_LED_LAN1,
  49. .active_low = 1,
  50. }, {
  51. .name = "rut900:green:lan2",
  52. .gpio = RUT9XX_GPIO_LED_LAN2,
  53. .active_low = 1,
  54. }, {
  55. .name = "rut900:green:lan3",
  56. .gpio = RUT9XX_GPIO_LED_LAN3,
  57. .active_low = 1,
  58. }, {
  59. .name = "rut900:green:signal1",
  60. .gpio = RUT9XX_PCA9539_GPIO_SIGNAL1,
  61. .active_low = 0,
  62. }, {
  63. .name = "rut900:green:signal2",
  64. .gpio = RUT9XX_PCA9539_GPIO_SIGNAL2,
  65. .active_low = 0,
  66. }, {
  67. .name = "rut900:green:signal3",
  68. .gpio = RUT9XX_PCA9539_GPIO_SIGNAL3,
  69. .active_low = 0,
  70. }, {
  71. .name = "rut900:green:signal4",
  72. .gpio = RUT9XX_PCA9539_GPIO_SIGNAL4,
  73. .active_low = 0,
  74. }, {
  75. .name = "rut900:green:signal5",
  76. .gpio = RUT9XX_PCA9539_GPIO_SIGNAL5,
  77. .active_low = 0,
  78. }, {
  79. .name = "rut900:green:status",
  80. .gpio = RUT9XX_PCA9539_GPIO_STATUS_G,
  81. .active_low = 0,
  82. }, {
  83. .name = "rut900:green:wan",
  84. .gpio = RUT9XX_GPIO_LED_WAN,
  85. .active_low = 1,
  86. }, {
  87. .name = "rut900:red:status",
  88. .gpio = RUT9XX_PCA9539_GPIO_STATUS_R,
  89. .active_low = 0,
  90. },
  91. };
  92. static struct gpio_keys_button rut900_gpio_keys[] __initdata = {
  93. {
  94. .desc = "reset",
  95. .type = EV_KEY,
  96. .code = KEY_RESTART,
  97. .debounce_interval = RUT9XX_KEYS_DEBOUNCE_INTERVAL,
  98. .gpio = RUT9XX_GPIO_BTN_RESET,
  99. .active_low = 1,
  100. },
  101. };
  102. static struct i2c_gpio_platform_data rut900_i2c_gpio_data = {
  103. .sda_pin = RUT9XX_GPIO_I2C_SDA,
  104. .scl_pin = RUT9XX_GPIO_I2C_SCK,
  105. .udelay = 10,
  106. };
  107. static struct platform_device rut900_i2c_device = {
  108. .name = "i2c-gpio",
  109. .id = 0,
  110. .dev = {
  111. .platform_data = &rut900_i2c_gpio_data,
  112. },
  113. };
  114. static struct pca953x_platform_data rut9xx_pca9539_data = {
  115. .gpio_base = RUT9XX_PCA9539_GPIO_BASE,
  116. .irq_base = -1,
  117. };
  118. static struct i2c_board_info rut900_i2c_devs[] __initdata = {
  119. {
  120. I2C_BOARD_INFO("pca9539", 0x74),
  121. .platform_data = &rut9xx_pca9539_data,
  122. },
  123. };
  124. static void __init rut900_setup(void)
  125. {
  126. u8 *art = (u8 *) KSEG1ADDR(0x1f030000);
  127. u8 *mac = (u8 *) KSEG1ADDR(0x1f020000);
  128. u8 wlan_mac[ETH_ALEN];
  129. ath79_register_m25p80(NULL);
  130. ath79_register_mdio(1, 0x0);
  131. ath79_switch_data.phy4_mii_en = 1;
  132. ath79_switch_data.phy_poll_mask = 0xf1;
  133. /* LAN */
  134. ath79_eth1_data.duplex = DUPLEX_FULL;
  135. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  136. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  137. ath79_register_eth(1);
  138. /* WAN */
  139. ath79_eth0_data.duplex = DUPLEX_FULL;
  140. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  141. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  142. ath79_eth0_data.phy_mask = BIT(4);
  143. ath79_eth0_data.speed = SPEED_100;
  144. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
  145. ath79_register_eth(0);
  146. platform_device_register(&rut900_i2c_device);
  147. i2c_register_board_info(0, rut900_i2c_devs,
  148. ARRAY_SIZE(rut900_i2c_devs));
  149. /* Disable JTAG (enables GPIO0-3) */
  150. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  151. ath79_register_leds_gpio(-1, ARRAY_SIZE(rut900_leds_gpio),
  152. rut900_leds_gpio);
  153. ath79_register_gpio_keys_polled(-1, RUT9XX_KEYS_POLL_INTERVAL,
  154. ARRAY_SIZE(rut900_gpio_keys),
  155. rut900_gpio_keys);
  156. ath79_wmac_set_ext_lna_gpio(0, RUT9XX_GPIO_EXT_LNA0);
  157. ath79_init_mac(wlan_mac, mac, 2);
  158. ath79_register_wmac(art + RUT9XX_WMAC_CALDATA_OFFSET, wlan_mac);
  159. ath79_register_usb();
  160. }
  161. MIPS_MACHINE(ATH79_MACH_RUT9XX, "RUT900", "Teltonika RUT900", rut900_setup);