mach-arduino-yun.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Arduino Yun support
  3. *
  4. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de>
  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 "dev-eth.h"
  12. #include "dev-gpio-buttons.h"
  13. #include "dev-leds-gpio.h"
  14. #include "dev-m25p80.h"
  15. #include "dev-spi.h"
  16. #include "dev-usb.h"
  17. #include "dev-wmac.h"
  18. #include "machtypes.h"
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <linux/gpio.h>
  22. #include "common.h"
  23. // Uncomment to have reset on gpio18 instead of gipo7
  24. #define DS2_B
  25. #define DS_GPIO_LED_WLAN 0
  26. #define DS_GPIO_LED_USB 1
  27. #define DS_GPIO_OE 21
  28. #define DS_GPIO_AVR_RESET 18
  29. // Maintained to have the console in the previous version of DS2 working
  30. #define DS_GPIO_AVR_RESET_DS2 7
  31. #define DS_GPIO_OE2 22
  32. #define DS_GPIO_UART_ENA 23
  33. #define DS_GPIO_CONF_BTN 20
  34. #define DS_KEYS_POLL_INTERVAL 20 /* msecs */
  35. #define DS_KEYS_DEBOUNCE_INTERVAL (3 * DS_KEYS_POLL_INTERVAL)
  36. #define DS_MAC0_OFFSET 0x0000
  37. #define DS_MAC1_OFFSET 0x0006
  38. #define DS_CALDATA_OFFSET 0x1000
  39. #define DS_WMAC_MAC_OFFSET 0x1002
  40. static struct gpio_led ds_leds_gpio[] __initdata = {
  41. {
  42. .name = "arduino:white:usb",
  43. .gpio = DS_GPIO_LED_USB,
  44. .active_low = 0,
  45. },
  46. {
  47. .name = "arduino:blue:wlan",
  48. .gpio = DS_GPIO_LED_WLAN,
  49. .active_low = 0,
  50. },
  51. };
  52. static struct gpio_keys_button ds_gpio_keys[] __initdata = {
  53. {
  54. .desc = "configuration button",
  55. .type = EV_KEY,
  56. .code = KEY_WPS_BUTTON,
  57. .debounce_interval = DS_KEYS_DEBOUNCE_INTERVAL,
  58. .gpio = DS_GPIO_CONF_BTN,
  59. .active_low = 1,
  60. },
  61. };
  62. static void __init ds_common_setup(void)
  63. {
  64. static u8 mac[6];
  65. u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
  66. ath79_register_m25p80(NULL);
  67. if (ar93xx_wmac_read_mac_address(mac)) {
  68. ath79_register_wmac(NULL, NULL);
  69. } else {
  70. ath79_register_wmac(art + DS_CALDATA_OFFSET,
  71. art + DS_WMAC_MAC_OFFSET);
  72. memcpy(mac, art + DS_WMAC_MAC_OFFSET, sizeof(mac));
  73. }
  74. mac[3] |= 0x08;
  75. ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
  76. mac[3] &= 0xF7;
  77. ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
  78. ath79_register_mdio(0, 0x0);
  79. /* LAN ports */
  80. ath79_register_eth(1);
  81. /* WAN port */
  82. ath79_register_eth(0);
  83. }
  84. static void __init ds_setup(void)
  85. {
  86. u32 t;
  87. ds_common_setup();
  88. ath79_register_leds_gpio(-1, ARRAY_SIZE(ds_leds_gpio),
  89. ds_leds_gpio);
  90. ath79_register_gpio_keys_polled(-1, DS_KEYS_POLL_INTERVAL,
  91. ARRAY_SIZE(ds_gpio_keys),
  92. ds_gpio_keys);
  93. ath79_register_usb();
  94. /* use the swtich_led directly form sysfs */
  95. ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN |
  96. AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN |
  97. AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN |
  98. AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN |
  99. AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN);
  100. //Disable the Function for some pins to have GPIO functionality active
  101. // GPIO6-7-8 and GPIO11
  102. ath79_gpio_function_setup(AR933X_GPIO_FUNC_JTAG_DISABLE | AR933X_GPIO_FUNC_I2S_MCK_EN, 0);
  103. ath79_gpio_function2_setup(AR933X_GPIO_FUNC2_JUMPSTART_DISABLE, 0);
  104. printk("Setting DogStick2 GPIO\n");
  105. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  106. t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN;
  107. ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t);
  108. // Put the avr reset to high
  109. if (gpio_request_one(DS_GPIO_AVR_RESET_DS2,
  110. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0)
  111. printk("Error setting GPIO OE\n");
  112. gpio_unexport(DS_GPIO_AVR_RESET_DS2);
  113. gpio_free(DS_GPIO_AVR_RESET_DS2);
  114. // enable OE of level shifter
  115. if (gpio_request_one(DS_GPIO_OE,
  116. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0)
  117. printk("Error setting GPIO OE\n");
  118. if (gpio_request_one(DS_GPIO_UART_ENA,
  119. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "UART-ENA") != 0)
  120. printk("Error setting GPIO Uart Enable\n");
  121. // enable OE of level shifter
  122. if (gpio_request_one(DS_GPIO_OE2,
  123. GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-2") != 0)
  124. printk("Error setting GPIO OE2\n");
  125. }
  126. MIPS_MACHINE(ATH79_MACH_ARDUINO_YUN, "Yun", "Arduino Yun", ds_setup);