mach-gl-ar300m.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * GLI AR300M(D) board support
  3. *
  4. * Copyright (C) 2011 dongyuqi <729650915@qq.com>
  5. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2013 alzhao <alzhao@gmail.com>
  7. * Copyright (C) 2014 Michel Stempin <michel.stempin@wanadoo.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/gpio.h>
  14. #include <linux/pci.h>
  15. #include <asm/mach-ath79/ath79.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include "common.h"
  18. #include "dev-ap9x-pci.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-spi.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. #include "pci.h"
  28. #define GL_AR300M_GPIO_LED_USB 2
  29. #define GL_AR300M_GPIO_LED_WLAN 14
  30. #define GL_AR300M_GPIO_LED_LAN 13
  31. #define GL_AR300M_GPIO_LED_SYSTEM 12
  32. #define GL_AR300M_GPIO_BTN_RESET 3
  33. #define GL_AR300M_GPIO_BTN_LEFT 0
  34. #define GL_AR300M_GPIO_BTN_RIGHT 1
  35. #define GL_AR300M_KEYS_POLL_INTERVAL 20 /* msecs */
  36. #define GL_AR300M_KEYS_DEBOUNCE_INTERVAL (3 * GL_AR300M_KEYS_POLL_INTERVAL)
  37. #define GL_AR300M_MAC0_OFFSET 0
  38. #define GL_AR300M_MAC1_OFFSET 6
  39. #define GL_AR300M_WMAC_CALDATA_OFFSET 0x1000
  40. #define GL_AR300M_PCIE_CALDATA_OFFSET 0x5000
  41. static struct gpio_led gl_ar300m_leds_gpio[] __initdata = {
  42. {
  43. .name = "gl-ar300m:usb",
  44. .gpio = GL_AR300M_GPIO_LED_USB,
  45. .active_low = 0,
  46. .default_state = 1,
  47. },
  48. {
  49. .name = "gl-ar300m:wlan",
  50. .gpio = GL_AR300M_GPIO_LED_WLAN,
  51. .active_low = 1,
  52. },
  53. {
  54. .name = "gl-ar300m:lan",
  55. .gpio = GL_AR300M_GPIO_LED_LAN,
  56. .active_low = 1,
  57. },
  58. {
  59. .name = "gl-ar300m:system",
  60. .gpio = GL_AR300M_GPIO_LED_SYSTEM,
  61. .active_low = 1,
  62. .default_state = 1,
  63. },
  64. };
  65. static struct gpio_keys_button gl_ar300m_gpio_keys[] __initdata = {
  66. {
  67. .desc = "reset",
  68. .type = EV_KEY,
  69. .code = KEY_RESTART,
  70. .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
  71. .gpio = GL_AR300M_GPIO_BTN_RESET,
  72. .active_low = 1,
  73. },
  74. {
  75. .desc = "button right",
  76. .type = EV_KEY,
  77. .code = BTN_0,
  78. .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
  79. .gpio = GL_AR300M_GPIO_BTN_LEFT,
  80. .active_low = 0,
  81. },
  82. {
  83. .desc = "button left",
  84. .type = EV_KEY,
  85. .code = BTN_1,
  86. .debounce_interval = GL_AR300M_KEYS_DEBOUNCE_INTERVAL,
  87. .gpio = GL_AR300M_GPIO_BTN_RIGHT,
  88. .active_low = 0,
  89. },
  90. };
  91. static struct spi_board_info gl_ar300m_spi_info[] = {
  92. {
  93. .bus_num = 0,
  94. .chip_select = 0,
  95. .max_speed_hz = 25000000,
  96. .modalias = "m25p80",
  97. .platform_data = NULL,
  98. },
  99. {
  100. .bus_num = 0,
  101. .chip_select = 1,
  102. .max_speed_hz = 25000000,
  103. .modalias = "ath79-spinand",
  104. .platform_data = NULL,
  105. }
  106. };
  107. static struct ath79_spi_platform_data gl_ar300m_spi_data = {
  108. .bus_num = 0,
  109. .num_chipselect = 2,
  110. };
  111. static void __init gl_ar300m_setup(void)
  112. {
  113. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  114. u8 tmpmac[ETH_ALEN];
  115. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  116. ath79_register_spi(&gl_ar300m_spi_data, gl_ar300m_spi_info, 2);
  117. /* register gpio LEDs and keys */
  118. ath79_register_leds_gpio(-1, ARRAY_SIZE(gl_ar300m_leds_gpio),
  119. gl_ar300m_leds_gpio);
  120. ath79_register_gpio_keys_polled(-1, GL_AR300M_KEYS_POLL_INTERVAL,
  121. ARRAY_SIZE(gl_ar300m_gpio_keys),
  122. gl_ar300m_gpio_keys);
  123. ath79_register_mdio(0, 0x0);
  124. /* WAN */
  125. ath79_init_mac(ath79_eth0_data.mac_addr, art + GL_AR300M_MAC0_OFFSET, 0);
  126. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  127. ath79_eth0_data.speed = SPEED_100;
  128. ath79_eth0_data.duplex = DUPLEX_FULL;
  129. ath79_eth0_data.phy_mask = BIT(4);
  130. ath79_register_eth(0);
  131. /* LAN */
  132. ath79_init_mac(ath79_eth1_data.mac_addr, art + GL_AR300M_MAC1_OFFSET, 0);
  133. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  134. ath79_eth1_data.speed = SPEED_1000;
  135. ath79_eth1_data.duplex = DUPLEX_FULL;
  136. ath79_switch_data.phy_poll_mask |= BIT(4);
  137. ath79_switch_data.phy4_mii_en = 1;
  138. ath79_register_eth(1);
  139. ath79_init_mac(tmpmac, art + GL_AR300M_WMAC_CALDATA_OFFSET + 2, 0);
  140. ath79_register_wmac(art + GL_AR300M_WMAC_CALDATA_OFFSET, tmpmac);
  141. /* enable usb */
  142. ath79_register_usb();
  143. /* enable pci */
  144. ath79_register_pci();
  145. }
  146. MIPS_MACHINE(ATH79_MACH_GL_AR300M, "GL-AR300M", "GL-AR300M",
  147. gl_ar300m_setup);