mach-hiwifi-hc6361.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * HiWiFi HC6361 board support
  3. *
  4. * Copyright (C) 2012-2013 eric
  5. * Copyright (C) 2014 Yousong Zhou <yszhou4tech@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/gpio.h>
  12. #include <linux/proc_fs.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. #include <asm/mach-ath79/ar71xx_regs.h>
  15. #include "common.h"
  16. #include "dev-eth.h"
  17. #include "dev-gpio-buttons.h"
  18. #include "dev-leds-gpio.h"
  19. #include "dev-m25p80.h"
  20. #include "dev-usb.h"
  21. #include "dev-wmac.h"
  22. #include "machtypes.h"
  23. #define HIWIFI_HC6361_GPIO_LED_WLAN_2P4 0 /* 2.4G WLAN LED */
  24. #define HIWIFI_HC6361_GPIO_LED_SYSTEM 1 /* System LED */
  25. #define HIWIFI_HC6361_GPIO_LED_INTERNET 27 /* Internet LED */
  26. #define HIWIFI_HC6361_GPIO_USBPOWER 20 /* USB power control */
  27. #define HIWIFI_HC6361_GPIO_BTN_RST 11 /* Reset button */
  28. #define HIWIFI_HC6361_KEYS_POLL_INTERVAL 20 /* msecs */
  29. #define HIWIFI_HC6361_KEYS_DEBOUNCE_INTERVAL \
  30. (3 * HIWIFI_HC6361_KEYS_POLL_INTERVAL)
  31. static struct gpio_led hiwifi_leds_gpio[] __initdata = {
  32. {
  33. .name = "hiwifi:blue:wlan-2p4",
  34. .gpio = HIWIFI_HC6361_GPIO_LED_WLAN_2P4,
  35. .active_low = 1,
  36. }, {
  37. .name = "hiwifi:blue:system",
  38. .gpio = HIWIFI_HC6361_GPIO_LED_SYSTEM,
  39. .active_low = 1,
  40. }, {
  41. .name = "hiwifi:blue:internet",
  42. .gpio = HIWIFI_HC6361_GPIO_LED_INTERNET,
  43. .active_low = 1,
  44. }
  45. };
  46. static struct gpio_keys_button hiwifi_gpio_keys[] __initdata = {
  47. {
  48. .desc = "reset",
  49. .type = EV_KEY,
  50. .code = KEY_RESTART,
  51. .debounce_interval = HIWIFI_HC6361_KEYS_DEBOUNCE_INTERVAL,
  52. .gpio = HIWIFI_HC6361_GPIO_BTN_RST,
  53. .active_low = 1,
  54. }
  55. };
  56. static void __init get_mac_from_bdinfo(u8 *mac, void *bdinfo)
  57. {
  58. if (sscanf(bdinfo, "fac_mac = %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
  59. &mac[0], &mac[1], &mac[2], &mac[3],
  60. &mac[4], &mac[5]) == 6) {
  61. return;
  62. }
  63. printk(KERN_WARNING "Parsing MAC address failed.\n");
  64. memcpy(mac, "\x00\xba\xbe\x00\x00\x00", 6);
  65. }
  66. static void __init hiwifi_hc6361_setup(void)
  67. {
  68. u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
  69. u8 mac[6];
  70. ath79_setup_ar933x_phy4_switch(false, false);
  71. ath79_register_m25p80(NULL);
  72. ath79_gpio_function_enable(
  73. AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  74. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  75. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  76. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  77. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  78. ath79_register_leds_gpio(-1, ARRAY_SIZE(hiwifi_leds_gpio),
  79. hiwifi_leds_gpio);
  80. ath79_register_gpio_keys_polled(-1, HIWIFI_HC6361_KEYS_POLL_INTERVAL,
  81. ARRAY_SIZE(hiwifi_gpio_keys),
  82. hiwifi_gpio_keys);
  83. gpio_request_one(HIWIFI_HC6361_GPIO_USBPOWER,
  84. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  85. "USB power");
  86. ath79_register_usb();
  87. get_mac_from_bdinfo(mac, (void *) KSEG1ADDR(0x1f010180));
  88. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
  89. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  90. ath79_register_mdio(0, 0x0);
  91. ath79_register_eth(1);
  92. ath79_register_eth(0);
  93. ath79_register_wmac(ee, mac);
  94. }
  95. MIPS_MACHINE(ATH79_MACH_HIWIFI_HC6361, "HiWiFi-HC6361",
  96. "HiWiFi HC6361", hiwifi_hc6361_setup);