mach-nbg6716.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * ZyXEL NBG6716/NBG6616 board support
  3. *
  4. * Based on the Qualcomm Atheros AP135/AP136 reference board support code
  5. * Copyright (c) 2012 Qualcomm Atheros
  6. * Copyright (c) 2012-2013 Gabor Juhos <juhosg@openwrt.org>
  7. * Copyright (c) 2013 Andre Valentin <avalentin@marcant.net>
  8. *
  9. * Permission to use, copy, modify, and/or distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. #include <linux/platform_device.h>
  23. #include <linux/ar8216_platform.h>
  24. #include <linux/gpio.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/nand.h>
  27. #include <linux/platform/ar934x_nfc.h>
  28. #include <asm/mach-ath79/ar71xx_regs.h>
  29. #include "common.h"
  30. #include "pci.h"
  31. #include "dev-ap9x-pci.h"
  32. #include "dev-gpio-buttons.h"
  33. #include "dev-eth.h"
  34. #include "dev-leds-gpio.h"
  35. #include "dev-nfc.h"
  36. #include "dev-m25p80.h"
  37. #include "dev-usb.h"
  38. #include "dev-wmac.h"
  39. #include "machtypes.h"
  40. #include "nvram.h"
  41. #define NBG6716_GPIO_LED_INTERNET 18
  42. #define NBG6716_GPIO_LED_POWER 15
  43. #define NBG6716_GPIO_LED_USB1 4
  44. #define NBG6716_GPIO_LED_USB2 13
  45. #define NBG6716_GPIO_LED_WIFI2G 19
  46. #define NBG6716_GPIO_LED_WIFI5G 17
  47. #define NBG6716_GPIO_LED_WPS 21
  48. #define NBG6716_GPIO_BTN_RESET 23
  49. #define NBG6716_GPIO_BTN_RFKILL 1
  50. #define NBG6716_GPIO_BTN_USB1 0
  51. #define NBG6716_GPIO_BTN_USB2 14
  52. #define NBG6716_GPIO_BTN_WPS 22
  53. #define NBG6716_GPIO_USB_POWER 16
  54. #define NBG6716_KEYS_POLL_INTERVAL 20 /* msecs */
  55. #define NBG6716_KEYS_DEBOUNCE_INTERVAL (3 * NBG6716_KEYS_POLL_INTERVAL)
  56. #define NBG6716_MAC0_OFFSET 0
  57. #define NBG6716_MAC1_OFFSET 6
  58. #define NBG6716_WMAC_CALDATA_OFFSET 0x1000
  59. #define NBG6716_PCIE_CALDATA_OFFSET 0x5000
  60. /* NBG6616 has a different GPIO usage as it does not have USB Buttons */
  61. #define NBG6616_GPIO_LED_USB0 14
  62. #define NBG6616_GPIO_LED_USB1 21
  63. #define NBG6616_GPIO_LED_WPS 0
  64. static struct gpio_led nbg6716_leds_gpio[] __initdata = {
  65. {
  66. .name = "nbg6716:white:internet",
  67. .gpio = NBG6716_GPIO_LED_INTERNET,
  68. .active_low = 1,
  69. },
  70. {
  71. .name = "nbg6716:white:power",
  72. .gpio = NBG6716_GPIO_LED_POWER,
  73. .active_low = 1,
  74. },
  75. {
  76. .name = "nbg6716:white:usb1",
  77. .gpio = NBG6716_GPIO_LED_USB1,
  78. .active_low = 1,
  79. },
  80. {
  81. .name = "nbg6716:white:usb2",
  82. .gpio = NBG6716_GPIO_LED_USB2,
  83. .active_low = 1,
  84. },
  85. {
  86. .name = "nbg6716:white:wifi2g",
  87. .gpio = NBG6716_GPIO_LED_WIFI2G,
  88. .active_low = 1,
  89. },
  90. {
  91. .name = "nbg6716:white:wifi5g",
  92. .gpio = NBG6716_GPIO_LED_WIFI5G,
  93. .active_low = 1,
  94. },
  95. {
  96. .name = "nbg6716:white:wps",
  97. .gpio = NBG6716_GPIO_LED_WPS,
  98. .active_low = 1,
  99. }
  100. };
  101. static struct gpio_keys_button nbg6716_gpio_keys[] __initdata = {
  102. {
  103. .desc = "RESET button",
  104. .type = EV_KEY,
  105. .code = KEY_RESTART,
  106. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  107. .gpio = NBG6716_GPIO_BTN_RESET,
  108. .active_low = 1,
  109. },
  110. {
  111. .desc = "RFKILL button",
  112. .type = EV_SW,
  113. .code = KEY_RFKILL,
  114. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  115. .gpio = NBG6716_GPIO_BTN_RFKILL,
  116. .active_low = 0,
  117. },
  118. {
  119. .desc = "USB1 eject button",
  120. .type = EV_KEY,
  121. .code = BTN_1,
  122. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  123. .gpio = NBG6716_GPIO_BTN_USB1,
  124. .active_low = 1,
  125. },
  126. {
  127. .desc = "USB2 eject button",
  128. .type = EV_KEY,
  129. .code = BTN_2,
  130. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  131. .gpio = NBG6716_GPIO_BTN_USB2,
  132. .active_low = 1,
  133. },
  134. {
  135. .desc = "WPS button",
  136. .type = EV_KEY,
  137. .code = KEY_WPS_BUTTON,
  138. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  139. .gpio = NBG6716_GPIO_BTN_WPS,
  140. .active_low = 1,
  141. },
  142. };
  143. static struct gpio_led nbg6616_leds_gpio[] __initdata = {
  144. {
  145. .name = "nbg6616:green:power",
  146. .gpio = NBG6716_GPIO_LED_POWER,
  147. .active_low = 1,
  148. },
  149. {
  150. .name = "nbg6616:green:usb2",
  151. .gpio = NBG6616_GPIO_LED_USB0,
  152. .active_low = 1,
  153. },
  154. {
  155. .name = "nbg6616:green:usb1",
  156. .gpio = NBG6616_GPIO_LED_USB1,
  157. .active_low = 1,
  158. },
  159. {
  160. .name = "nbg6616:green:wifi2g",
  161. .gpio = NBG6716_GPIO_LED_WIFI2G,
  162. .active_low = 1,
  163. },
  164. {
  165. .name = "nbg6616:green:wifi5g",
  166. .gpio = NBG6716_GPIO_LED_WIFI5G,
  167. .active_low = 1,
  168. },
  169. {
  170. .name = "nbg6616:green:wps",
  171. .gpio = NBG6616_GPIO_LED_WPS,
  172. .active_low = 1,
  173. }
  174. };
  175. static struct gpio_keys_button nbg6616_gpio_keys[] __initdata = {
  176. {
  177. .desc = "RESET button",
  178. .type = EV_KEY,
  179. .code = KEY_RESTART,
  180. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  181. .gpio = NBG6716_GPIO_BTN_RESET,
  182. .active_low = 1,
  183. },
  184. {
  185. .desc = "RFKILL button",
  186. .type = EV_KEY,
  187. .code = KEY_RFKILL,
  188. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  189. .gpio = NBG6716_GPIO_BTN_RFKILL,
  190. .active_low = 1,
  191. },
  192. {
  193. .desc = "WPS button",
  194. .type = EV_KEY,
  195. .code = KEY_WPS_BUTTON,
  196. .debounce_interval = NBG6716_KEYS_DEBOUNCE_INTERVAL,
  197. .gpio = NBG6716_GPIO_BTN_WPS,
  198. .active_low = 1,
  199. },
  200. };
  201. static struct ar8327_pad_cfg nbg6716_ar8327_pad0_cfg;
  202. static struct ar8327_pad_cfg nbg6716_ar8327_pad6_cfg;
  203. static struct ar8327_led_cfg nbg6716_ar8327_led_cfg;
  204. static struct ar8327_platform_data nbg6716_ar8327_data = {
  205. .pad0_cfg = &nbg6716_ar8327_pad0_cfg,
  206. .pad6_cfg = &nbg6716_ar8327_pad6_cfg,
  207. .port0_cfg = {
  208. .force_link = 1,
  209. .speed = AR8327_PORT_SPEED_1000,
  210. .duplex = 1,
  211. .txpause = 1,
  212. .rxpause = 1,
  213. },
  214. .port6_cfg = {
  215. .force_link = 1,
  216. .speed = AR8327_PORT_SPEED_1000,
  217. .duplex = 1,
  218. .txpause = 1,
  219. .rxpause = 1,
  220. },
  221. .led_cfg = &nbg6716_ar8327_led_cfg
  222. };
  223. static struct mdio_board_info nbg6716_mdio0_info[] = {
  224. {
  225. .bus_id = "ag71xx-mdio.0",
  226. .phy_addr = 0,
  227. .platform_data = &nbg6716_ar8327_data,
  228. },
  229. };
  230. static void nbg6716_get_mac(void* nvram_addr, const char *name, char *mac)
  231. {
  232. u8 *nvram = (u8 *) KSEG1ADDR(nvram_addr);
  233. int err;
  234. err = ath79_nvram_parse_mac_addr(nvram, 0x10000,
  235. name, mac);
  236. if (err)
  237. pr_err("no MAC address found for %s\n", name);
  238. }
  239. static void __init nbg6716_common_setup(u32 leds_num, struct gpio_led* leds,
  240. u32 keys_num,
  241. struct gpio_keys_button* keys,
  242. void* art_addr, void* nvram)
  243. {
  244. u8 *art = (u8 *) KSEG1ADDR(art_addr);
  245. u8 tmpmac[ETH_ALEN];
  246. ath79_register_m25p80(NULL);
  247. ath79_register_leds_gpio(-1, leds_num, leds);
  248. ath79_register_gpio_keys_polled(-1, NBG6716_KEYS_POLL_INTERVAL,
  249. keys_num, keys);
  250. ath79_nfc_set_ecc_mode(AR934X_NFC_ECC_HW);
  251. ath79_register_nfc();
  252. gpio_request_one(NBG6716_GPIO_USB_POWER,
  253. GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
  254. "USB power");
  255. ath79_register_usb();
  256. nbg6716_get_mac(nvram, "ethaddr=", tmpmac);
  257. ath79_register_pci();
  258. ath79_register_wmac(art + NBG6716_WMAC_CALDATA_OFFSET, tmpmac);
  259. ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN);
  260. ath79_register_mdio(0, 0x0);
  261. ath79_init_mac(ath79_eth0_data.mac_addr, tmpmac, 2);
  262. ath79_init_mac(ath79_eth1_data.mac_addr, tmpmac, 3);
  263. mdiobus_register_board_info(nbg6716_mdio0_info,
  264. ARRAY_SIZE(nbg6716_mdio0_info));
  265. /* GMAC0 is connected to the RMGII interface */
  266. ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
  267. ath79_eth0_data.phy_mask = BIT(0);
  268. ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev;
  269. ath79_register_eth(0);
  270. /* GMAC1 is connected to the SGMII interface */
  271. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII;
  272. ath79_eth1_data.speed = SPEED_1000;
  273. ath79_eth1_data.duplex = DUPLEX_FULL;
  274. ath79_register_eth(1);
  275. }
  276. static void __init nbg6716_010_setup(void)
  277. {
  278. /* GMAC0 of the AR8337 switch is connected to GMAC0 via RGMII */
  279. nbg6716_ar8327_pad0_cfg.mode = AR8327_PAD_MAC_RGMII;
  280. nbg6716_ar8327_pad0_cfg.txclk_delay_en = true;
  281. nbg6716_ar8327_pad0_cfg.rxclk_delay_en = true;
  282. nbg6716_ar8327_pad0_cfg.txclk_delay_sel = AR8327_CLK_DELAY_SEL1;
  283. nbg6716_ar8327_pad0_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL2;
  284. /* GMAC6 of the AR8337 switch is connected to GMAC1 via SGMII */
  285. nbg6716_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
  286. nbg6716_ar8327_pad6_cfg.rxclk_delay_en = true;
  287. nbg6716_ar8327_pad6_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0;
  288. ath79_eth0_pll_data.pll_1000 = 0xa6000000;
  289. ath79_eth1_pll_data.pll_1000 = 0x03000101;
  290. nbg6716_ar8327_led_cfg.open_drain = 0;
  291. nbg6716_ar8327_led_cfg.led_ctrl0 = 0xffb7ffb7;
  292. nbg6716_ar8327_led_cfg.led_ctrl1 = 0xffb7ffb7;
  293. nbg6716_ar8327_led_cfg.led_ctrl2 = 0xffb7ffb7;
  294. nbg6716_ar8327_led_cfg.led_ctrl3 = 0x03ffff00;
  295. nbg6716_common_setup(ARRAY_SIZE(nbg6716_leds_gpio), nbg6716_leds_gpio,
  296. ARRAY_SIZE(nbg6716_gpio_keys), nbg6716_gpio_keys,
  297. (void*) 0x1f050000, (void*) 0x1f040000);
  298. }
  299. static void __init nbg6616_010_setup(void)
  300. {
  301. /* GMAC0 of the AR8337 switch is connected to GMAC0 via RGMII */
  302. nbg6716_ar8327_pad0_cfg.mode = AR8327_PAD_MAC_RGMII;
  303. nbg6716_ar8327_pad0_cfg.txclk_delay_en = true;
  304. nbg6716_ar8327_pad0_cfg.rxclk_delay_en = true;
  305. nbg6716_ar8327_pad0_cfg.txclk_delay_sel = AR8327_CLK_DELAY_SEL1;
  306. nbg6716_ar8327_pad0_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL2;
  307. /* GMAC6 of the AR8337 switch is connected to GMAC1 via SGMII */
  308. nbg6716_ar8327_pad6_cfg.mode = AR8327_PAD_MAC_SGMII;
  309. nbg6716_ar8327_pad6_cfg.rxclk_delay_en = true;
  310. nbg6716_ar8327_pad6_cfg.rxclk_delay_sel = AR8327_CLK_DELAY_SEL0;
  311. ath79_eth0_pll_data.pll_1000 = 0xa6000000;
  312. ath79_eth1_pll_data.pll_1000 = 0x03000101;
  313. nbg6716_ar8327_led_cfg.open_drain = 0;
  314. nbg6716_ar8327_led_cfg.led_ctrl0 = 0xffb7ffb7;
  315. nbg6716_ar8327_led_cfg.led_ctrl1 = 0xffb7ffb7;
  316. nbg6716_ar8327_led_cfg.led_ctrl2 = 0xffb7ffb7;
  317. nbg6716_ar8327_led_cfg.led_ctrl3 = 0x03ffff00;
  318. nbg6716_common_setup(ARRAY_SIZE(nbg6616_leds_gpio), nbg6616_leds_gpio,
  319. ARRAY_SIZE(nbg6616_gpio_keys), nbg6616_gpio_keys,
  320. (void*) 0x1f040000, (void*) 0x1f030000);
  321. }
  322. MIPS_MACHINE(ATH79_MACH_NBG6716, "NBG6716",
  323. "Zyxel NBG6716",
  324. nbg6716_010_setup);
  325. MIPS_MACHINE(ATH79_MACH_NBG6616, "NBG6616",
  326. "Zyxel NBG6616",
  327. nbg6616_010_setup);