mach-wi2a-ac200i.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Nokia WI2A-AC200i support
  3. *
  4. * Copyright (c) 2012 Qualcomm Atheros
  5. * Copyright (c) 2012-2013 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (c) 2017 Felix Fietkau <nbd@nbd.name>
  7. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. *
  20. */
  21. #include <linux/platform_device.h>
  22. #include <linux/mtd/mtd.h>
  23. #include <linux/mtd/partitions.h>
  24. #include <linux/platform/ar934x_nfc.h>
  25. #include <asm/mach-ath79/ar71xx_regs.h>
  26. #include <asm/fw/fw.h>
  27. #include "common.h"
  28. #include "pci.h"
  29. #include "dev-ap9x-pci.h"
  30. #include "dev-gpio-buttons.h"
  31. #include "dev-eth.h"
  32. #include "dev-leds-gpio.h"
  33. #include "dev-m25p80.h"
  34. #include "dev-nfc.h"
  35. #include "dev-usb.h"
  36. #include "dev-wmac.h"
  37. #include "machtypes.h"
  38. #define AC200I_GPIO_BTN_RESET 17
  39. #define AC200I_KEYS_POLL_INTERVAL 20 /* msecs */
  40. #define AC200I_KEYS_DEBOUNCE_INTERVAL (3 * AC200I_KEYS_POLL_INTERVAL)
  41. #define AC200I_MAC_ADDR 0x1f040249
  42. #define AC200I_MAC1_OFFSET 6
  43. #define AC200I_WMAC_CALDATA_ADDR 0x1f061000
  44. static struct gpio_led ac200i_leds_gpio[] __initdata = {
  45. {
  46. .name = "nokia:red:wlan-2g",
  47. .gpio = 0,
  48. .active_low = 1,
  49. },
  50. {
  51. .name = "nokia:green:power",
  52. .gpio = 1,
  53. .active_low = 1,
  54. },
  55. {
  56. .name = "nokia:green:wlan-2g",
  57. .gpio = 2,
  58. .active_low = 1,
  59. },
  60. {
  61. .name = "nokia:green:ctrl",
  62. .gpio = 3,
  63. .active_low = 1,
  64. },
  65. {
  66. .name = "nokia:green:eth",
  67. .gpio = 4,
  68. .active_low = 1,
  69. },
  70. {
  71. .name = "nokia:red:power",
  72. .gpio = 13,
  73. .active_low = 1,
  74. },
  75. {
  76. .name = "nokia:red:eth",
  77. .gpio = 14,
  78. .active_low = 1,
  79. },
  80. {
  81. .name = "nokia:red:wlan-5g",
  82. .gpio = 18,
  83. .active_low = 1,
  84. },
  85. {
  86. .name = "nokia:green:wlan-5g",
  87. .gpio = 19,
  88. .active_low = 1,
  89. },
  90. {
  91. .name = "nokia:red:ctrl",
  92. .gpio = 20,
  93. .active_low = 1,
  94. },
  95. };
  96. static struct gpio_keys_button ac200i_gpio_keys[] __initdata = {
  97. {
  98. .desc = "Reset button",
  99. .type = EV_KEY,
  100. .code = KEY_RESTART,
  101. .debounce_interval = AC200I_KEYS_DEBOUNCE_INTERVAL,
  102. .gpio = AC200I_GPIO_BTN_RESET,
  103. .active_low = 1,
  104. },
  105. };
  106. static struct mtd_partition ac200i_nand_partitions[] = {
  107. {
  108. .name = "cfg",
  109. .offset = 0x0100000,
  110. .size = 0x1800000,
  111. .mask_flags = MTD_WRITEABLE,
  112. },
  113. {
  114. .name = "kernel",
  115. .offset = 0x2000000,
  116. .size = 0x0400000,
  117. },
  118. {
  119. .name = "ubi",
  120. .offset = 0x2400000,
  121. .size = 0x2000000,
  122. },
  123. {
  124. .name = "kernel",
  125. .offset = 0x5000000,
  126. .size = 0x0400000,
  127. },
  128. {
  129. .name = "ubi",
  130. .offset = 0x5400000,
  131. .size = 0x2000000,
  132. },
  133. };
  134. static const char *boot_getenv(const char *key)
  135. {
  136. const char *start = (const char *) KSEG1ADDR(0x1f070000);
  137. const char *end = start + 0x20000;
  138. const char *addr;
  139. for (addr = start + 4;
  140. *addr && *addr != 0xff && addr < end &&
  141. strnlen(addr, end - addr) < end - addr;
  142. addr += strnlen(addr, end - addr) + 1) {
  143. const char *val;
  144. val = strchr(addr, '=');
  145. if (!val)
  146. continue;
  147. if (strncmp(addr, key, val - addr))
  148. continue;
  149. return val + 1;
  150. }
  151. return NULL;
  152. }
  153. static void __init ac200i_setup(void)
  154. {
  155. const char *img;
  156. u8 *wmac = (u8 *) KSEG1ADDR(AC200I_WMAC_CALDATA_ADDR);
  157. u8 *mac_addr = (u8 *) KSEG1ADDR(AC200I_MAC_ADDR);
  158. ath79_register_m25p80(NULL);
  159. ath79_register_leds_gpio(-1, ARRAY_SIZE(ac200i_leds_gpio),
  160. ac200i_leds_gpio);
  161. ath79_register_gpio_keys_polled(-1, AC200I_KEYS_POLL_INTERVAL,
  162. ARRAY_SIZE(ac200i_gpio_keys),
  163. ac200i_gpio_keys);
  164. ath79_register_usb();
  165. ath79_nfc_set_parts(ac200i_nand_partitions,
  166. ARRAY_SIZE(ac200i_nand_partitions));
  167. ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
  168. ath79_register_nfc();
  169. ath79_register_wmac(wmac, NULL);
  170. ath79_register_mdio(0, 0x0);
  171. ath79_init_mac(ath79_eth0_data.mac_addr, mac_addr, 0);
  172. /* GMAC0 is connected to the SGMII interface */
  173. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  174. ath79_eth0_data.phy_mask = BIT(4);
  175. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  176. ath79_eth0_pll_data.pll_1000 = 0x03000101;
  177. ath79_eth0_pll_data.pll_100 = 0x80000101;
  178. ath79_eth0_pll_data.pll_10 = 0x80001313;
  179. img = boot_getenv("dualPartition");
  180. if (img && !strcmp(img, "imgA")) {
  181. ac200i_nand_partitions[3].name = "kernel_alt";
  182. ac200i_nand_partitions[4].name = "ubi_alt";
  183. } else {
  184. ac200i_nand_partitions[1].name = "kernel_alt";
  185. ac200i_nand_partitions[2].name = "ubi_alt";
  186. }
  187. ath79_register_eth(0);
  188. ath79_register_pci();
  189. }
  190. MIPS_MACHINE(ATH79_MACH_WI2A_AC200I, "WI2A-AC200i",
  191. "Nokia WI2A-AC200i",
  192. ac200i_setup);