0026-MIPS-ralink-add-mt7628an-support.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. From a375beba066516ecafddebc765454ac6ec599f3d Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Wed, 6 Aug 2014 18:26:08 +0200
  4. Subject: [PATCH 26/57] MIPS: ralink: add mt7628an support
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. arch/mips/include/asm/mach-ralink/mt7620.h | 11 ++
  8. arch/mips/ralink/Kconfig | 2 +-
  9. arch/mips/ralink/mt7620.c | 266 +++++++++++++++++++++++-----
  10. 3 files changed, 232 insertions(+), 47 deletions(-)
  11. --- a/arch/mips/include/asm/mach-ralink/mt7620.h
  12. +++ b/arch/mips/include/asm/mach-ralink/mt7620.h
  13. @@ -13,6 +13,13 @@
  14. #ifndef _MT7620_REGS_H_
  15. #define _MT7620_REGS_H_
  16. +enum mt762x_soc_type {
  17. + MT762X_SOC_UNKNOWN = 0,
  18. + MT762X_SOC_MT7620A,
  19. + MT762X_SOC_MT7620N,
  20. + MT762X_SOC_MT7628AN,
  21. +};
  22. +
  23. #define MT7620_SYSC_BASE 0x10000000
  24. #define SYSC_REG_CHIP_NAME0 0x00
  25. @@ -27,6 +34,7 @@
  26. #define MT7620_CHIP_NAME0 0x3637544d
  27. #define MT7620_CHIP_NAME1 0x20203032
  28. +#define MT7628_CHIP_NAME1 0x20203832
  29. #define SYSCFG0_XTAL_FREQ_SEL BIT(6)
  30. @@ -71,6 +79,9 @@
  31. #define SYSCFG0_DRAM_TYPE_DDR1 1
  32. #define SYSCFG0_DRAM_TYPE_DDR2 2
  33. +#define SYSCFG0_DRAM_TYPE_DDR2_MT7628 0
  34. +#define SYSCFG0_DRAM_TYPE_DDR1_MT7628 1
  35. +
  36. #define MT7620_DRAM_BASE 0x0
  37. #define MT7620_SDRAM_SIZE_MIN 2
  38. #define MT7620_SDRAM_SIZE_MAX 64
  39. --- a/arch/mips/ralink/Kconfig
  40. +++ b/arch/mips/ralink/Kconfig
  41. @@ -41,7 +41,7 @@ choice
  42. select HW_HAS_PCI
  43. config SOC_MT7620
  44. - bool "MT7620"
  45. + bool "MT7620/8"
  46. config SOC_MT7621
  47. bool "MT7621"
  48. --- a/arch/mips/ralink/mt7620.c
  49. +++ b/arch/mips/ralink/mt7620.c
  50. @@ -42,6 +42,8 @@
  51. #define CLKCFG_FFRAC_MASK 0x001f
  52. #define CLKCFG_FFRAC_USB_VAL 0x0003
  53. +enum mt762x_soc_type mt762x_soc;
  54. +
  55. /* does the board have sdram or ddram */
  56. static int dram_type;
  57. @@ -159,6 +161,125 @@ struct ralink_pinmux rt_gpio_pinmux = {
  58. .uart_mask = MT7620_GPIO_MODE_UART0_MASK,
  59. };
  60. +static struct rt2880_pmx_func pwm1_grp_mt7628[] = {
  61. + FUNC("sdxc", 3, 19, 1),
  62. + FUNC("utif", 2, 19, 1),
  63. + FUNC("gpio", 1, 19, 1),
  64. + FUNC("pwm", 0, 19, 1),
  65. +};
  66. +
  67. +static struct rt2880_pmx_func pwm0_grp_mt7628[] = {
  68. + FUNC("sdxc", 3, 18, 1),
  69. + FUNC("utif", 2, 18, 1),
  70. + FUNC("gpio", 1, 18, 1),
  71. + FUNC("pwm", 0, 18, 1),
  72. +};
  73. +
  74. +static struct rt2880_pmx_func uart2_grp_mt7628[] = {
  75. + FUNC("sdxc", 3, 20, 2),
  76. + FUNC("pwm", 2, 20, 2),
  77. + FUNC("gpio", 1, 20, 2),
  78. + FUNC("uart2", 0, 20, 2),
  79. +};
  80. +
  81. +static struct rt2880_pmx_func uart1_grp_mt7628[] = {
  82. + FUNC("sdxc", 3, 45, 2),
  83. + FUNC("pwm", 2, 45, 2),
  84. + FUNC("gpio", 1, 45, 2),
  85. + FUNC("uart1", 0, 45, 2),
  86. +};
  87. +
  88. +static struct rt2880_pmx_func i2c_grp_mt7628[] = {
  89. + FUNC("-", 3, 4, 2),
  90. + FUNC("debug", 2, 4, 2),
  91. + FUNC("gpio", 1, 4, 2),
  92. + FUNC("i2c", 0, 4, 2),
  93. +};
  94. +
  95. +static struct rt2880_pmx_func refclk_grp_mt7628[] = { FUNC("reclk", 0, 36, 1) };
  96. +static struct rt2880_pmx_func perst_grp_mt7628[] = { FUNC("perst", 0, 37, 1) };
  97. +static struct rt2880_pmx_func wdt_grp_mt7628[] = { FUNC("wdt", 0, 38, 1) };
  98. +static struct rt2880_pmx_func spi_grp_mt7628[] = { FUNC("spi", 0, 7, 4) };
  99. +
  100. +static struct rt2880_pmx_func sd_mode_grp_mt7628[] = {
  101. + FUNC("jtag", 3, 22, 8),
  102. + FUNC("utif", 2, 22, 8),
  103. + FUNC("gpio", 1, 22, 8),
  104. + FUNC("sdxc", 0, 22, 8),
  105. +};
  106. +
  107. +static struct rt2880_pmx_func uart0_grp_mt7628[] = {
  108. + FUNC("-", 3, 12, 2),
  109. + FUNC("-", 2, 12, 2),
  110. + FUNC("gpio", 1, 12, 2),
  111. + FUNC("uart0", 0, 12, 2),
  112. +};
  113. +
  114. +static struct rt2880_pmx_func i2s_grp_mt7628[] = {
  115. + FUNC("antenna", 3, 0, 4),
  116. + FUNC("pcm", 2, 0, 4),
  117. + FUNC("gpio", 1, 0, 4),
  118. + FUNC("i2s", 0, 0, 4),
  119. +};
  120. +
  121. +static struct rt2880_pmx_func spi_cs1_grp_mt7628[] = {
  122. + FUNC("-", 3, 6, 1),
  123. + FUNC("refclk", 2, 6, 1),
  124. + FUNC("gpio", 1, 6, 1),
  125. + FUNC("spi", 0, 6, 1),
  126. +};
  127. +
  128. +static struct rt2880_pmx_func spis_grp_mt7628[] = {
  129. + FUNC("pwm", 3, 14, 4),
  130. + FUNC("util", 2, 14, 4),
  131. + FUNC("gpio", 1, 14, 4),
  132. + FUNC("spis", 0, 14, 4),
  133. +};
  134. +
  135. +static struct rt2880_pmx_func gpio_grp_mt7628[] = {
  136. + FUNC("pcie", 3, 11, 1),
  137. + FUNC("refclk", 2, 11, 1),
  138. + FUNC("gpio", 1, 11, 1),
  139. + FUNC("gpio", 0, 11, 1),
  140. +};
  141. +
  142. +#define MT7628_GPIO_MODE_MASK 0x3
  143. +
  144. +#define MT7628_GPIO_MODE_PWM1 30
  145. +#define MT7628_GPIO_MODE_PWM0 28
  146. +#define MT7628_GPIO_MODE_UART2 26
  147. +#define MT7628_GPIO_MODE_UART1 24
  148. +#define MT7628_GPIO_MODE_I2C 20
  149. +#define MT7628_GPIO_MODE_REFCLK 18
  150. +#define MT7628_GPIO_MODE_PERST 16
  151. +#define MT7628_GPIO_MODE_WDT 14
  152. +#define MT7628_GPIO_MODE_SPI 12
  153. +#define MT7628_GPIO_MODE_SDMODE 10
  154. +#define MT7628_GPIO_MODE_UART0 8
  155. +#define MT7628_GPIO_MODE_I2S 6
  156. +#define MT7628_GPIO_MODE_CS1 4
  157. +#define MT7628_GPIO_MODE_SPIS 2
  158. +#define MT7628_GPIO_MODE_GPIO 0
  159. +
  160. +static struct rt2880_pmx_group mt7628an_pinmux_data[] = {
  161. + GRP_G("pmw1", pwm1_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_PWM1),
  162. + GRP_G("pmw0", pwm0_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_PWM0),
  163. + GRP_G("uart2", uart2_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_UART2),
  164. + GRP_G("uart1", uart1_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_UART1),
  165. + GRP_G("i2c", i2c_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_I2C),
  166. + GRP("refclk", refclk_grp_mt7628, 1, MT7628_GPIO_MODE_REFCLK),
  167. + GRP("perst", perst_grp_mt7628, 1, MT7628_GPIO_MODE_PERST),
  168. + GRP("wdt", wdt_grp_mt7628, 1, MT7628_GPIO_MODE_WDT),
  169. + GRP("spi", spi_grp_mt7628, 1, MT7628_GPIO_MODE_SPI),
  170. + GRP_G("sdmode", sd_mode_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_SDMODE),
  171. + GRP_G("uart0", uart0_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_UART0),
  172. + GRP_G("i2s", i2s_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_I2S),
  173. + GRP_G("spi cs1", spi_cs1_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_CS1),
  174. + GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_SPIS),
  175. + GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK, 1, MT7628_GPIO_MODE_GPIO),
  176. + { 0 }
  177. +};
  178. +
  179. static __init u32
  180. mt7620_calc_rate(u32 ref_rate, u32 mul, u32 div)
  181. {
  182. @@ -309,29 +430,42 @@ void __init ralink_clk_init(void)
  183. xtal_rate = mt7620_get_xtal_rate();
  184. - cpu_pll_rate = mt7620_get_cpu_pll_rate(xtal_rate);
  185. - pll_rate = mt7620_get_pll_rate(xtal_rate, cpu_pll_rate);
  186. -
  187. - cpu_rate = mt7620_get_cpu_rate(pll_rate);
  188. - dram_rate = mt7620_get_dram_rate(pll_rate);
  189. - sys_rate = mt7620_get_sys_rate(cpu_rate);
  190. - periph_rate = mt7620_get_periph_rate(xtal_rate);
  191. -
  192. #define RFMT(label) label ":%lu.%03luMHz "
  193. #define RINT(x) ((x) / 1000000)
  194. #define RFRAC(x) (((x) / 1000) % 1000)
  195. - pr_debug(RFMT("XTAL") RFMT("CPU_PLL") RFMT("PLL"),
  196. - RINT(xtal_rate), RFRAC(xtal_rate),
  197. - RINT(cpu_pll_rate), RFRAC(cpu_pll_rate),
  198. - RINT(pll_rate), RFRAC(pll_rate));
  199. + if (mt762x_soc == MT762X_SOC_MT7628AN) {
  200. + if (xtal_rate == MHZ(40))
  201. + cpu_rate = MHZ(580);
  202. + else
  203. + cpu_rate = MHZ(575);
  204. + dram_rate = sys_rate = cpu_rate / 3;
  205. + periph_rate = MHZ(40);
  206. +
  207. + ralink_clk_add("10000d00.uartlite", periph_rate);
  208. + ralink_clk_add("10000e00.uartlite", periph_rate);
  209. + } else {
  210. + cpu_pll_rate = mt7620_get_cpu_pll_rate(xtal_rate);
  211. + pll_rate = mt7620_get_pll_rate(xtal_rate, cpu_pll_rate);
  212. +
  213. + cpu_rate = mt7620_get_cpu_rate(pll_rate);
  214. + dram_rate = mt7620_get_dram_rate(pll_rate);
  215. + sys_rate = mt7620_get_sys_rate(cpu_rate);
  216. + periph_rate = mt7620_get_periph_rate(xtal_rate);
  217. +
  218. + pr_debug(RFMT("XTAL") RFMT("CPU_PLL") RFMT("PLL"),
  219. + RINT(xtal_rate), RFRAC(xtal_rate),
  220. + RINT(cpu_pll_rate), RFRAC(cpu_pll_rate),
  221. + RINT(pll_rate), RFRAC(pll_rate));
  222. +
  223. + ralink_clk_add("10000500.uart", periph_rate);
  224. + }
  225. pr_debug(RFMT("CPU") RFMT("DRAM") RFMT("SYS") RFMT("PERIPH"),
  226. RINT(cpu_rate), RFRAC(cpu_rate),
  227. RINT(dram_rate), RFRAC(dram_rate),
  228. RINT(sys_rate), RFRAC(sys_rate),
  229. RINT(periph_rate), RFRAC(periph_rate));
  230. -
  231. #undef RFRAC
  232. #undef RINT
  233. #undef RFMT
  234. @@ -339,12 +473,13 @@ void __init ralink_clk_init(void)
  235. ralink_clk_add("cpu", cpu_rate);
  236. ralink_clk_add("10000100.timer", periph_rate);
  237. ralink_clk_add("10000120.watchdog", periph_rate);
  238. - ralink_clk_add("10000500.uart", periph_rate);
  239. ralink_clk_add("10000b00.spi", sys_rate);
  240. ralink_clk_add("10000c00.uartlite", periph_rate);
  241. + ralink_clk_add("10000d00.uart1", periph_rate);
  242. + ralink_clk_add("10000e00.uart2", periph_rate);
  243. ralink_clk_add("10180000.wmac", xtal_rate);
  244. - if (IS_ENABLED(CONFIG_USB)) {
  245. + if (IS_ENABLED(CONFIG_USB) && mt762x_soc != MT762X_SOC_MT7628AN) {
  246. /*
  247. * When the CPU goes into sleep mode, the BUS clock will be too low for
  248. * USB to function properly
  249. @@ -367,6 +502,52 @@ void __init ralink_of_remap(void)
  250. panic("Failed to remap core resources");
  251. }
  252. +static __init void
  253. +mt7620_dram_init(struct ralink_soc_info *soc_info)
  254. +{
  255. + switch (dram_type) {
  256. + case SYSCFG0_DRAM_TYPE_SDRAM:
  257. + pr_info("Board has SDRAM\n");
  258. + soc_info->mem_size_min = MT7620_SDRAM_SIZE_MIN;
  259. + soc_info->mem_size_max = MT7620_SDRAM_SIZE_MAX;
  260. + break;
  261. +
  262. + case SYSCFG0_DRAM_TYPE_DDR1:
  263. + pr_info("Board has DDR1\n");
  264. + soc_info->mem_size_min = MT7620_DDR1_SIZE_MIN;
  265. + soc_info->mem_size_max = MT7620_DDR1_SIZE_MAX;
  266. + break;
  267. +
  268. + case SYSCFG0_DRAM_TYPE_DDR2:
  269. + pr_info("Board has DDR2\n");
  270. + soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN;
  271. + soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX;
  272. + break;
  273. + default:
  274. + BUG();
  275. + }
  276. +}
  277. +
  278. +static __init void
  279. +mt7628_dram_init(struct ralink_soc_info *soc_info)
  280. +{
  281. + switch (dram_type) {
  282. + case SYSCFG0_DRAM_TYPE_DDR1_MT7628:
  283. + pr_info("Board has DDR1\n");
  284. + soc_info->mem_size_min = MT7620_DDR1_SIZE_MIN;
  285. + soc_info->mem_size_max = MT7620_DDR1_SIZE_MAX;
  286. + break;
  287. +
  288. + case SYSCFG0_DRAM_TYPE_DDR2_MT7628:
  289. + pr_info("Board has DDR2\n");
  290. + soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN;
  291. + soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX;
  292. + break;
  293. + default:
  294. + BUG();
  295. + }
  296. +}
  297. +
  298. void prom_soc_init(struct ralink_soc_info *soc_info)
  299. {
  300. void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7620_SYSC_BASE);
  301. @@ -384,18 +565,25 @@ void prom_soc_init(struct ralink_soc_inf
  302. rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
  303. bga = (rev >> CHIP_REV_PKG_SHIFT) & CHIP_REV_PKG_MASK;
  304. - if (n0 != MT7620_CHIP_NAME0 || n1 != MT7620_CHIP_NAME1)
  305. - panic("mt7620: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  306. -
  307. - if (bga) {
  308. - name = "MT7620A";
  309. - soc_info->compatible = "ralink,mt7620a-soc";
  310. - } else {
  311. - name = "MT7620N";
  312. - soc_info->compatible = "ralink,mt7620n-soc";
  313. + if (n0 == MT7620_CHIP_NAME0 && n1 == MT7620_CHIP_NAME1) {
  314. + if (bga) {
  315. + mt762x_soc = MT762X_SOC_MT7620A;
  316. + name = "MT7620A";
  317. + soc_info->compatible = "ralink,mt7620a-soc";
  318. + } else {
  319. + mt762x_soc = MT762X_SOC_MT7620N;
  320. + name = "MT7620N";
  321. + soc_info->compatible = "ralink,mt7620n-soc";
  322. #ifdef CONFIG_PCI
  323. - panic("mt7620n is only supported for non pci kernels");
  324. + panic("mt7620n is only supported for non pci kernels");
  325. #endif
  326. + }
  327. + } else if (n0 == MT7620_CHIP_NAME0 && n1 == MT7628_CHIP_NAME1) {
  328. + mt762x_soc = MT762X_SOC_MT7628AN;
  329. + name = "MT7628AN";
  330. + soc_info->compatible = "ralink,mt7628an-soc";
  331. + } else {
  332. + panic("mt762x: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  333. }
  334. snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  335. @@ -407,28 +595,11 @@ void prom_soc_init(struct ralink_soc_inf
  336. cfg0 = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG0);
  337. dram_type = (cfg0 >> SYSCFG0_DRAM_TYPE_SHIFT) & SYSCFG0_DRAM_TYPE_MASK;
  338. - switch (dram_type) {
  339. - case SYSCFG0_DRAM_TYPE_SDRAM:
  340. - pr_info("Board has SDRAM\n");
  341. - soc_info->mem_size_min = MT7620_SDRAM_SIZE_MIN;
  342. - soc_info->mem_size_max = MT7620_SDRAM_SIZE_MAX;
  343. - break;
  344. -
  345. - case SYSCFG0_DRAM_TYPE_DDR1:
  346. - pr_info("Board has DDR1\n");
  347. - soc_info->mem_size_min = MT7620_DDR1_SIZE_MIN;
  348. - soc_info->mem_size_max = MT7620_DDR1_SIZE_MAX;
  349. - break;
  350. -
  351. - case SYSCFG0_DRAM_TYPE_DDR2:
  352. - pr_info("Board has DDR2\n");
  353. - soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN;
  354. - soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX;
  355. - break;
  356. - default:
  357. - BUG();
  358. - }
  359. soc_info->mem_base = MT7620_DRAM_BASE;
  360. + if (mt762x_soc == MT762X_SOC_MT7628AN)
  361. + mt7628_dram_init(soc_info);
  362. + else
  363. + mt7620_dram_init(soc_info);
  364. pmu0 = __raw_readl(sysc + PMU0_CFG);
  365. pmu1 = __raw_readl(sysc + PMU1_CFG);
  366. @@ -437,4 +608,9 @@ void prom_soc_init(struct ralink_soc_inf
  367. (pmu0 & PMU_SW_SET) ? ("sw") : ("hw"));
  368. pr_info("Digital PMU set to %s control\n",
  369. (pmu1 & DIG_SW_SEL) ? ("sw") : ("hw"));
  370. +
  371. + if (mt762x_soc == MT762X_SOC_MT7628AN)
  372. + rt2880_pinmux_data = mt7628an_pinmux_data;
  373. + else
  374. + rt2880_pinmux_data = mt7620a_pinmux_data;
  375. }