1
0

mach-rbsxtlite.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * MikroTik RouterBOARD SXT Lite support
  3. *
  4. * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
  5. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2013 Vyacheslav Adamanov <adamanov@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) "sxtlite: " fmt
  13. #include <linux/phy.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/ath9k_platform.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/nand.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/flash.h>
  22. #include <linux/rle.h>
  23. #include <linux/routerboot.h>
  24. #include <linux/gpio.h>
  25. #include <asm/mach-ath79/ath79.h>
  26. #include <asm/mach-ath79/ar71xx_regs.h>
  27. #include "common.h"
  28. #include "dev-ap9x-pci.h"
  29. #include "dev-gpio-buttons.h"
  30. #include "dev-leds-gpio.h"
  31. #include "dev-eth.h"
  32. #include "dev-m25p80.h"
  33. #include "dev-nfc.h"
  34. #include "dev-wmac.h"
  35. #include "dev-usb.h"
  36. #include "machtypes.h"
  37. #include "routerboot.h"
  38. #include <linux/ar8216_platform.h>
  39. #define SXTLITE_GPIO_NAND_NCE 14
  40. #define SXTLITE_GPIO_LED_USER 3
  41. #define SXTLITE_GPIO_LED_1 13
  42. #define SXTLITE_GPIO_LED_2 12
  43. #define SXTLITE_GPIO_LED_3 4
  44. #define SXTLITE_GPIO_LED_4 21
  45. #define SXTLITE_GPIO_LED_5 18
  46. #define SXTLITE_GPIO_LED_POWER 11
  47. #define SXTLITE_GPIO_BUZZER 19
  48. #define SXTLITE_GPIO_BTN_RESET 15
  49. #define SXTLITE_KEYS_POLL_INTERVAL 20
  50. #define SXTLITE_KEYS_DEBOUNCE_INTERVAL (3 * SXTLITE_KEYS_POLL_INTERVAL)
  51. static struct mtd_partition rbsxtlite_nand_partitions[] = {
  52. {
  53. .name = "booter",
  54. .offset = 0,
  55. .size = (256 * 1024),
  56. .mask_flags = MTD_WRITEABLE,
  57. },
  58. {
  59. .name = "kernel",
  60. .offset = (256 * 1024),
  61. .size = (4 * 1024 * 1024) - (256 * 1024),
  62. },
  63. {
  64. .name = "ubi",
  65. .offset = MTDPART_OFS_NXTBLK,
  66. .size = MTDPART_SIZ_FULL,
  67. },
  68. };
  69. static struct gpio_led rbsxtlite_leds_gpio[] __initdata = {
  70. {
  71. .name = "rb:green:user",
  72. .gpio = SXTLITE_GPIO_LED_USER,
  73. .active_low = 1,
  74. },
  75. {
  76. .name = "rb:green:led1",
  77. .gpio = SXTLITE_GPIO_LED_1,
  78. .active_low = 1,
  79. },
  80. {
  81. .name = "rb:green:led2",
  82. .gpio = SXTLITE_GPIO_LED_2,
  83. .active_low = 1,
  84. },
  85. {
  86. .name = "rb:green:led3",
  87. .gpio = SXTLITE_GPIO_LED_3,
  88. .active_low = 1,
  89. },
  90. {
  91. .name = "rb:green:led4",
  92. .gpio = SXTLITE_GPIO_LED_4,
  93. .active_low = 1,
  94. },
  95. {
  96. .name = "rb:green:led5",
  97. .gpio = SXTLITE_GPIO_LED_5,
  98. .active_low = 1,
  99. },
  100. {
  101. .name = "rb:green:power",
  102. .gpio = SXTLITE_GPIO_LED_POWER,
  103. },
  104. };
  105. static struct gpio_keys_button rbsxtlite_gpio_keys[] __initdata = {
  106. {
  107. .desc = "Reset button",
  108. .type = EV_KEY,
  109. .code = KEY_RESTART,
  110. .debounce_interval = SXTLITE_KEYS_DEBOUNCE_INTERVAL,
  111. .gpio = SXTLITE_GPIO_BTN_RESET,
  112. .active_low = 0,
  113. },
  114. };
  115. static int __init rbsxtlite_rbinfo_init(void)
  116. {
  117. const struct rb_info *info;
  118. info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
  119. if (!info)
  120. return -EINVAL;
  121. return 0;
  122. }
  123. void __init rbsxtlite_wlan_init(void)
  124. {
  125. char *art_buf;
  126. u8 wlan_mac[ETH_ALEN];
  127. art_buf = rb_get_wlan_data();
  128. if (art_buf == NULL)
  129. return;
  130. ath79_init_mac(wlan_mac, ath79_mac_base, 1);
  131. ath79_register_wmac(art_buf + 0x1000, wlan_mac);
  132. kfree(art_buf);
  133. }
  134. static void rbsxtlite_nand_select_chip(int chip_no)
  135. {
  136. switch (chip_no) {
  137. case 0:
  138. gpio_set_value(SXTLITE_GPIO_NAND_NCE, 0);
  139. break;
  140. default:
  141. gpio_set_value(SXTLITE_GPIO_NAND_NCE, 1);
  142. break;
  143. }
  144. ndelay(500);
  145. }
  146. static struct nand_ecclayout rbsxtlite_nand_ecclayout = {
  147. .eccbytes = 6,
  148. .eccpos = { 8, 9, 10, 13, 14, 15 },
  149. .oobavail = 9,
  150. .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
  151. };
  152. static int rbsxtlite_nand_scan_fixup(struct mtd_info *mtd)
  153. {
  154. struct nand_chip *chip = mtd->priv;
  155. if (mtd->writesize == 512) {
  156. /*
  157. * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
  158. * will not be able to find the kernel that we load.
  159. */
  160. chip->ecc.layout = &rbsxtlite_nand_ecclayout;
  161. }
  162. return 0;
  163. }
  164. void __init rbsxtlite_gpio_init(void)
  165. {
  166. gpio_request_one(SXTLITE_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
  167. }
  168. void __init rbsxtlite_nand_init(void)
  169. {
  170. ath79_nfc_set_scan_fixup(rbsxtlite_nand_scan_fixup);
  171. ath79_nfc_set_parts(rbsxtlite_nand_partitions,
  172. ARRAY_SIZE(rbsxtlite_nand_partitions));
  173. ath79_nfc_set_select_chip(rbsxtlite_nand_select_chip);
  174. ath79_nfc_set_swap_dma(true);
  175. ath79_register_nfc();
  176. }
  177. static void __init rbsxtlite_setup(void)
  178. {
  179. if(rbsxtlite_rbinfo_init())
  180. return;
  181. rbsxtlite_nand_init();
  182. rbsxtlite_wlan_init();
  183. ath79_register_leds_gpio(-1, ARRAY_SIZE(rbsxtlite_leds_gpio),
  184. rbsxtlite_leds_gpio);
  185. ath79_register_gpio_keys_polled(-1, SXTLITE_KEYS_POLL_INTERVAL,
  186. ARRAY_SIZE(rbsxtlite_gpio_keys),
  187. rbsxtlite_gpio_keys);
  188. ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
  189. ath79_register_mdio(1, 0x0);
  190. /* GMAC0 is left unused */
  191. /* GMAC1 is connected to MAC0 on the internal switch */
  192. /* The ethernet port connects to PHY P0, which connects to MAC1
  193. on the internal switch */
  194. ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
  195. ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
  196. ath79_register_eth(1);
  197. }
  198. MIPS_MACHINE(ATH79_MACH_RB_SXTLITE2ND, "sxt2n", "Mikrotik RouterBOARD SXT Lite2",
  199. rbsxtlite_setup);
  200. MIPS_MACHINE(ATH79_MACH_RB_SXTLITE5ND, "sxt5n", "Mikrotik RouterBOARD SXT Lite5",
  201. rbsxtlite_setup);