mach-qihoo-c301.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Qihoo 360 C301 board support
  3. *
  4. * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2014 Weijie Gao <hackpascal@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/pci.h>
  12. #include <linux/phy.h>
  13. #include <linux/gpio.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ath9k_platform.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include "common.h"
  18. #include "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-spi.h"
  24. #include "dev-usb.h"
  25. #include "dev-wmac.h"
  26. #include "machtypes.h"
  27. #include "nvram.h"
  28. #define QIHOO_C301_GPIO_LED_STATUS_GREEN 0
  29. #define QIHOO_C301_GPIO_LED_STATUS_RED 11
  30. #define QIHOO_C301_GPIO_LED_WAN 1
  31. #define QIHOO_C301_GPIO_LED_LAN1 2
  32. #define QIHOO_C301_GPIO_LED_LAN2 3
  33. #define QIHOO_C301_GPIO_ETH_LEN_EN 18
  34. #define QIHOO_C301_GPIO_BTN_RESET 16
  35. #define QIHOO_C301_GPIO_USB_POWER 19
  36. #define QIHOO_C301_GPIO_SPI_CS1 12
  37. #define QIHOO_C301_GPIO_EXTERNAL_LNA0 14
  38. #define QIHOO_C301_GPIO_EXTERNAL_LNA1 15
  39. #define QIHOO_C301_KEYS_POLL_INTERVAL 20 /* msecs */
  40. #define QIHOO_C301_KEYS_DEBOUNCE_INTERVAL \
  41. (3 * QIHOO_C301_KEYS_POLL_INTERVAL)
  42. #define QIHOO_C301_WMAC_CALDATA_OFFSET 0x1000
  43. #define QIHOO_C301_NVRAM_ADDR 0x1f058010
  44. #define QIHOO_C301_NVRAM_SIZE 0x7ff0
  45. static struct gpio_led qihoo_c301_leds_gpio[] __initdata = {
  46. {
  47. .name = "qihoo:green:status",
  48. .gpio = QIHOO_C301_GPIO_LED_STATUS_GREEN,
  49. .active_low = 1,
  50. },
  51. {
  52. .name = "qihoo:red:status",
  53. .gpio = QIHOO_C301_GPIO_LED_STATUS_RED,
  54. .active_low = 1,
  55. },
  56. };
  57. static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = {
  58. {
  59. .desc = "reset",
  60. .type = EV_KEY,
  61. .code = KEY_RESTART,
  62. .debounce_interval = QIHOO_C301_KEYS_DEBOUNCE_INTERVAL,
  63. .gpio = QIHOO_C301_GPIO_BTN_RESET,
  64. .active_low = 1,
  65. },
  66. };
  67. static struct flash_platform_data flash __initdata = {NULL, NULL, 0};
  68. static void qihoo_c301_get_mac(const char *name, char *mac)
  69. {
  70. u8 *nvram = (u8 *) KSEG1ADDR(QIHOO_C301_NVRAM_ADDR);
  71. int err;
  72. err = ath79_nvram_parse_mac_addr(nvram, QIHOO_C301_NVRAM_SIZE,
  73. name, mac);
  74. if (err)
  75. pr_err("no MAC address found for %s\n", name);
  76. }
  77. static void __init qihoo_c301_setup(void)
  78. {
  79. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  80. u8 tmpmac[ETH_ALEN];
  81. ath79_register_m25p80_multi(&flash);
  82. ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
  83. ath79_gpio_output_select(QIHOO_C301_GPIO_LED_WAN,
  84. AR934X_GPIO_OUT_LED_LINK4);
  85. ath79_gpio_output_select(QIHOO_C301_GPIO_LED_LAN1,
  86. AR934X_GPIO_OUT_LED_LINK1);
  87. ath79_gpio_output_select(QIHOO_C301_GPIO_LED_LAN2,
  88. AR934X_GPIO_OUT_LED_LINK2);
  89. ath79_gpio_output_select(QIHOO_C301_GPIO_SPI_CS1,
  90. AR934X_GPIO_OUT_SPI_CS1);
  91. gpio_request_one(QIHOO_C301_GPIO_ETH_LEN_EN,
  92. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED,
  93. "Ethernet LED enable");
  94. ath79_register_leds_gpio(-1, ARRAY_SIZE(qihoo_c301_leds_gpio),
  95. qihoo_c301_leds_gpio);
  96. ath79_register_gpio_keys_polled(-1, QIHOO_C301_KEYS_POLL_INTERVAL,
  97. ARRAY_SIZE(qihoo_c301_gpio_keys),
  98. qihoo_c301_gpio_keys);
  99. ath79_wmac_set_ext_lna_gpio(0, QIHOO_C301_GPIO_EXTERNAL_LNA0);
  100. ath79_wmac_set_ext_lna_gpio(1, QIHOO_C301_GPIO_EXTERNAL_LNA1);
  101. qihoo_c301_get_mac("wlan24mac=", tmpmac);
  102. ath79_register_wmac(art + QIHOO_C301_WMAC_CALDATA_OFFSET, tmpmac);
  103. ath79_register_pci();
  104. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE |
  105. AR934X_ETH_CFG_SW_PHY_SWAP);
  106. ath79_register_mdio(1, 0x0);
  107. /* LAN */
  108. qihoo_c301_get_mac("lanmac=", ath79_eth1_data.mac_addr);
  109. /* GMAC1 is connected to the internal switch */
  110. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  111. ath79_register_eth(1);
  112. /* WAN */
  113. qihoo_c301_get_mac("wanmac=", ath79_eth0_data.mac_addr);
  114. /* GMAC0 is connected to the PHY4 of the internal switch */
  115. ath79_switch_data.phy4_mii_en = 1;
  116. ath79_switch_data.phy_poll_mask = BIT(0);
  117. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
  118. ath79_eth0_data.phy_mask = BIT(0);
  119. ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
  120. ath79_register_eth(0);
  121. gpio_request_one(QIHOO_C301_GPIO_USB_POWER,
  122. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  123. "USB power");
  124. ath79_register_usb();
  125. }
  126. MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301",
  127. qihoo_c301_setup);