mach-r36a.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * ALFA Network R36A board 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/platform_device.h>
  12. #include <asm/mach-ath79/ath79.h>
  13. #include <asm/mach-ath79/ar71xx_regs.h>
  14. #include "common.h"
  15. #include "dev-eth.h"
  16. #include "dev-gpio-buttons.h"
  17. #include "dev-leds-gpio.h"
  18. #include "dev-m25p80.h"
  19. #include "dev-usb.h"
  20. #include "dev-wmac.h"
  21. #include "machtypes.h"
  22. #define R36A_GPIO_LED_LAN 4
  23. #define R36A_GPIO_LED_STATUS 14
  24. #define R36A_GPIO_LED_USB 12
  25. #define R36A_GPIO_LED_WAN 16
  26. #define R36A_GPIO_LED_WLAN 15
  27. #define R36A_GPIO_WDT_EN 1
  28. #define R36A_GPIO_WDT_IN 0
  29. #define R36A_GPIO_USB_PWR 3
  30. #define R36A_GPIO_BTN_RESET 2
  31. #define R36A_GPIO_BTN_RFKILL 17
  32. #define R36A_KEYS_POLL_INTERVAL 20
  33. #define R36A_KEYS_DEBOUNCE_INTERVAL (3 * R36A_KEYS_POLL_INTERVAL)
  34. #define R36A_WMAC_CALDATA_OFFSET 0x1000
  35. static struct gpio_led r36a_leds_gpio[] __initdata = {
  36. {
  37. .name = "r36a:blue:lan",
  38. .gpio = R36A_GPIO_LED_LAN,
  39. .active_low = 1,
  40. }, {
  41. .name = "r36a:blue:status",
  42. .gpio = R36A_GPIO_LED_STATUS,
  43. .active_low = 1,
  44. }, {
  45. .name = "r36a:blue:usb",
  46. .gpio = R36A_GPIO_LED_USB,
  47. .active_low = 1,
  48. }, {
  49. .name = "r36a:blue:wan",
  50. .gpio = R36A_GPIO_LED_WAN,
  51. .active_low = 1,
  52. }, {
  53. .name = "r36a:blue:wlan",
  54. .gpio = R36A_GPIO_LED_WLAN,
  55. .active_low = 1,
  56. },
  57. };
  58. static struct gpio_keys_button r36a_gpio_keys[] __initdata = {
  59. {
  60. .desc = "reset",
  61. .type = EV_KEY,
  62. .code = KEY_RESTART,
  63. .debounce_interval = R36A_KEYS_DEBOUNCE_INTERVAL,
  64. .gpio = R36A_GPIO_BTN_RESET,
  65. .active_low = 1,
  66. }, {
  67. .desc = "rfkill",
  68. .type = EV_KEY,
  69. .code = KEY_RFKILL,
  70. .debounce_interval = R36A_KEYS_DEBOUNCE_INTERVAL,
  71. .gpio = R36A_GPIO_BTN_RFKILL,
  72. .active_low = 1,
  73. },
  74. };
  75. static void __init r36a_setup(void)
  76. {
  77. u8 *art = (u8 *) KSEG1ADDR(0x1f070000);
  78. ath79_register_m25p80(NULL);
  79. ath79_setup_ar933x_phy4_switch(false, false);
  80. ath79_register_mdio(0, 0x0);
  81. ath79_switch_data.phy4_mii_en = 1;
  82. ath79_switch_data.phy_poll_mask = 0xf7;
  83. /* LAN */
  84. ath79_eth0_data.duplex = DUPLEX_FULL;
  85. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  86. ath79_eth0_data.phy_mask = BIT(4);
  87. ath79_eth0_data.speed = SPEED_100;
  88. ath79_init_mac(ath79_eth0_data.mac_addr, art, 0);
  89. ath79_register_eth(0);
  90. /* WAN */
  91. ath79_eth1_data.duplex = DUPLEX_FULL;
  92. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  93. ath79_init_mac(ath79_eth1_data.mac_addr, art, 1);
  94. ath79_register_eth(1);
  95. /* Disable JTAG (enables GPIO0-3) */
  96. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  97. ath79_register_leds_gpio(-1, ARRAY_SIZE(r36a_leds_gpio),
  98. r36a_leds_gpio);
  99. ath79_register_gpio_keys_polled(-1, R36A_KEYS_POLL_INTERVAL,
  100. ARRAY_SIZE(r36a_gpio_keys),
  101. r36a_gpio_keys);
  102. gpio_request_one(R36A_GPIO_WDT_IN,
  103. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
  104. "WDT input");
  105. gpio_request_one(R36A_GPIO_WDT_EN,
  106. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
  107. "WDT enable");
  108. gpio_request_one(R36A_GPIO_USB_PWR,
  109. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  110. "USB power");
  111. ath79_register_wmac(art + R36A_WMAC_CALDATA_OFFSET, NULL);
  112. ath79_register_usb();
  113. }
  114. MIPS_MACHINE(ATH79_MACH_R36A, "R36A", "ALFA Network R36A", r36a_setup);