mt7620.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Parts of this file are based on Ralink's 2.6.21 BSP
  7. *
  8. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  9. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  10. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/mach-ralink/ralink_regs.h>
  17. #include <asm/mach-ralink/mt7620.h>
  18. #include <asm/mach-ralink/pinmux.h>
  19. #include "common.h"
  20. /* analog */
  21. #define PMU0_CFG 0x88
  22. #define PMU_SW_SET BIT(28)
  23. #define A_DCDC_EN BIT(24)
  24. #define A_SSC_PERI BIT(19)
  25. #define A_SSC_GEN BIT(18)
  26. #define A_SSC_M 0x3
  27. #define A_SSC_S 16
  28. #define A_DLY_M 0x7
  29. #define A_DLY_S 8
  30. #define A_VTUNE_M 0xff
  31. /* digital */
  32. #define PMU1_CFG 0x8C
  33. #define DIG_SW_SEL BIT(25)
  34. /* is this a MT7620 or a MT7628 */
  35. enum mt762x_soc_type mt762x_soc;
  36. /* does the board have sdram or ddram */
  37. static int dram_type;
  38. static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 1, 2) };
  39. static struct rt2880_pmx_func spi_grp[] = { FUNC("spi", 0, 3, 4) };
  40. static struct rt2880_pmx_func uartlite_grp[] = { FUNC("uartlite", 0, 15, 2) };
  41. static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 22, 2) };
  42. static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 24, 12) };
  43. static struct rt2880_pmx_func refclk_grp[] = { FUNC("spi refclk", 0, 37, 3) };
  44. static struct rt2880_pmx_func ephy_grp[] = { FUNC("ephy", 0, 40, 5) };
  45. static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 60, 12) };
  46. static struct rt2880_pmx_func wled_grp[] = { FUNC("wled", 0, 72, 1) };
  47. static struct rt2880_pmx_func pa_grp[] = { FUNC("pa", 0, 18, 4) };
  48. static struct rt2880_pmx_func uartf_grp[] = {
  49. FUNC("uartf", MT7620_GPIO_MODE_UARTF, 7, 8),
  50. FUNC("pcm uartf", MT7620_GPIO_MODE_PCM_UARTF, 7, 8),
  51. FUNC("pcm i2s", MT7620_GPIO_MODE_PCM_I2S, 7, 8),
  52. FUNC("i2s uartf", MT7620_GPIO_MODE_I2S_UARTF, 7, 8),
  53. FUNC("pcm gpio", MT7620_GPIO_MODE_PCM_GPIO, 11, 4),
  54. FUNC("gpio uartf", MT7620_GPIO_MODE_GPIO_UARTF, 7, 4),
  55. FUNC("gpio i2s", MT7620_GPIO_MODE_GPIO_I2S, 7, 4),
  56. };
  57. static struct rt2880_pmx_func wdt_grp[] = {
  58. FUNC("wdt rst", 0, 17, 1),
  59. FUNC("wdt refclk", 0, 17, 1),
  60. };
  61. static struct rt2880_pmx_func pcie_rst_grp[] = {
  62. FUNC("pcie rst", MT7620_GPIO_MODE_PCIE_RST, 36, 1),
  63. FUNC("pcie refclk", MT7620_GPIO_MODE_PCIE_REF, 36, 1)
  64. };
  65. static struct rt2880_pmx_func nd_sd_grp[] = {
  66. FUNC("nand", MT7620_GPIO_MODE_NAND, 45, 15),
  67. FUNC("sd", MT7620_GPIO_MODE_SD, 45, 15)
  68. };
  69. static struct rt2880_pmx_group mt7620a_pinmux_data[] = {
  70. GRP("i2c", i2c_grp, 1, MT7620_GPIO_MODE_I2C),
  71. GRP("uartf", uartf_grp, MT7620_GPIO_MODE_UART0_MASK,
  72. MT7620_GPIO_MODE_UART0_SHIFT),
  73. GRP("spi", spi_grp, 1, MT7620_GPIO_MODE_SPI),
  74. GRP("uartlite", uartlite_grp, 1, MT7620_GPIO_MODE_UART1),
  75. GRP_G("wdt", wdt_grp, MT7620_GPIO_MODE_WDT_MASK,
  76. MT7620_GPIO_MODE_WDT_GPIO, MT7620_GPIO_MODE_WDT_SHIFT),
  77. GRP("mdio", mdio_grp, 1, MT7620_GPIO_MODE_MDIO),
  78. GRP("rgmii1", rgmii1_grp, 1, MT7620_GPIO_MODE_RGMII1),
  79. GRP("spi refclk", refclk_grp, 1, MT7620_GPIO_MODE_SPI_REF_CLK),
  80. GRP_G("pcie", pcie_rst_grp, MT7620_GPIO_MODE_PCIE_MASK,
  81. MT7620_GPIO_MODE_PCIE_GPIO, MT7620_GPIO_MODE_PCIE_SHIFT),
  82. GRP_G("nd_sd", nd_sd_grp, MT7620_GPIO_MODE_ND_SD_MASK,
  83. MT7620_GPIO_MODE_ND_SD_GPIO, MT7620_GPIO_MODE_ND_SD_SHIFT),
  84. GRP("rgmii2", rgmii2_grp, 1, MT7620_GPIO_MODE_RGMII2),
  85. GRP("wled", wled_grp, 1, MT7620_GPIO_MODE_WLED),
  86. GRP("ephy", ephy_grp, 1, MT7620_GPIO_MODE_EPHY),
  87. GRP("pa", pa_grp, 1, MT7620_GPIO_MODE_PA),
  88. { 0 }
  89. };
  90. static struct rt2880_pmx_func pwm1_grp_mt7628[] = {
  91. FUNC("sdcx", 3, 19, 1),
  92. FUNC("utif", 2, 19, 1),
  93. FUNC("gpio", 1, 19, 1),
  94. FUNC("pwm", 0, 19, 1),
  95. };
  96. static struct rt2880_pmx_func pwm0_grp_mt7628[] = {
  97. FUNC("sdcx", 3, 18, 1),
  98. FUNC("utif", 2, 18, 1),
  99. FUNC("gpio", 1, 18, 1),
  100. FUNC("pwm", 0, 18, 1),
  101. };
  102. static struct rt2880_pmx_func uart2_grp_mt7628[] = {
  103. FUNC("sdcx", 3, 20, 2),
  104. FUNC("pwm", 2, 20, 2),
  105. FUNC("gpio", 1, 20, 2),
  106. FUNC("uart", 0, 20, 2),
  107. };
  108. static struct rt2880_pmx_func uart1_grp_mt7628[] = {
  109. FUNC("sdcx", 3, 45, 2),
  110. FUNC("pwm", 2, 45, 2),
  111. FUNC("gpio", 1, 45, 2),
  112. FUNC("uart", 0, 45, 2),
  113. };
  114. static struct rt2880_pmx_func i2c_grp_mt7628[] = {
  115. FUNC("-", 3, 4, 2),
  116. FUNC("debug", 2, 4, 2),
  117. FUNC("gpio", 1, 4, 2),
  118. FUNC("i2c", 0, 4, 2),
  119. };
  120. static struct rt2880_pmx_func refclk_grp_mt7628[] = { FUNC("reclk", 0, 36, 1) };
  121. static struct rt2880_pmx_func perst_grp_mt7628[] = { FUNC("perst", 0, 37, 1) };
  122. static struct rt2880_pmx_func wdt_grp_mt7628[] = { FUNC("wdt", 0, 15, 38) };
  123. static struct rt2880_pmx_func spi_grp_mt7628[] = { FUNC("spi", 0, 7, 4) };
  124. static struct rt2880_pmx_func sd_mode_grp_mt7628[] = {
  125. FUNC("jtag", 3, 22, 8),
  126. FUNC("utif", 2, 22, 8),
  127. FUNC("gpio", 1, 22, 8),
  128. FUNC("sdcx", 0, 22, 8),
  129. };
  130. static struct rt2880_pmx_func uart0_grp_mt7628[] = {
  131. FUNC("-", 3, 12, 2),
  132. FUNC("-", 2, 12, 2),
  133. FUNC("gpio", 1, 12, 2),
  134. FUNC("uart", 0, 12, 2),
  135. };
  136. static struct rt2880_pmx_func i2s_grp_mt7628[] = {
  137. FUNC("antenna", 3, 0, 4),
  138. FUNC("pcm", 2, 0, 4),
  139. FUNC("gpio", 1, 0, 4),
  140. FUNC("i2s", 0, 0, 4),
  141. };
  142. static struct rt2880_pmx_func spi_cs1_grp_mt7628[] = {
  143. FUNC("-", 3, 6, 1),
  144. FUNC("refclk", 2, 6, 1),
  145. FUNC("gpio", 1, 6, 1),
  146. FUNC("spi", 0, 6, 1),
  147. };
  148. static struct rt2880_pmx_func spis_grp_mt7628[] = {
  149. FUNC("pwm", 3, 14, 4),
  150. FUNC("util", 2, 14, 4),
  151. FUNC("gpio", 1, 14, 4),
  152. FUNC("spis", 0, 14, 4),
  153. };
  154. static struct rt2880_pmx_func gpio_grp_mt7628[] = {
  155. FUNC("pcie", 3, 11, 1),
  156. FUNC("refclk", 2, 11, 1),
  157. FUNC("gpio", 1, 11, 1),
  158. FUNC("gpio", 0, 11, 1),
  159. };
  160. #define MT7628_GPIO_MODE_MASK 0x3
  161. #define MT7628_GPIO_MODE_PWM1 30
  162. #define MT7628_GPIO_MODE_PWM0 28
  163. #define MT7628_GPIO_MODE_UART2 26
  164. #define MT7628_GPIO_MODE_UART1 24
  165. #define MT7628_GPIO_MODE_I2C 20
  166. #define MT7628_GPIO_MODE_REFCLK 18
  167. #define MT7628_GPIO_MODE_PERST 16
  168. #define MT7628_GPIO_MODE_WDT 14
  169. #define MT7628_GPIO_MODE_SPI 12
  170. #define MT7628_GPIO_MODE_SDMODE 10
  171. #define MT7628_GPIO_MODE_UART0 8
  172. #define MT7628_GPIO_MODE_I2S 6
  173. #define MT7628_GPIO_MODE_CS1 4
  174. #define MT7628_GPIO_MODE_SPIS 2
  175. #define MT7628_GPIO_MODE_GPIO 0
  176. static struct rt2880_pmx_group mt7628an_pinmux_data[] = {
  177. GRP_G("pmw1", pwm1_grp_mt7628, MT7628_GPIO_MODE_MASK,
  178. 1, MT7628_GPIO_MODE_PWM1),
  179. GRP_G("pmw1", pwm0_grp_mt7628, MT7628_GPIO_MODE_MASK,
  180. 1, MT7628_GPIO_MODE_PWM0),
  181. GRP_G("uart2", uart2_grp_mt7628, MT7628_GPIO_MODE_MASK,
  182. 1, MT7628_GPIO_MODE_UART2),
  183. GRP_G("uart1", uart1_grp_mt7628, MT7628_GPIO_MODE_MASK,
  184. 1, MT7628_GPIO_MODE_UART1),
  185. GRP_G("i2c", i2c_grp_mt7628, MT7628_GPIO_MODE_MASK,
  186. 1, MT7628_GPIO_MODE_I2C),
  187. GRP("refclk", refclk_grp_mt7628, 1, MT7628_GPIO_MODE_REFCLK),
  188. GRP("perst", perst_grp_mt7628, 1, MT7628_GPIO_MODE_PERST),
  189. GRP("wdt", wdt_grp_mt7628, 1, MT7628_GPIO_MODE_WDT),
  190. GRP("spi", spi_grp_mt7628, 1, MT7628_GPIO_MODE_SPI),
  191. GRP_G("sdmode", sd_mode_grp_mt7628, MT7628_GPIO_MODE_MASK,
  192. 1, MT7628_GPIO_MODE_SDMODE),
  193. GRP_G("uart0", uart0_grp_mt7628, MT7628_GPIO_MODE_MASK,
  194. 1, MT7628_GPIO_MODE_UART0),
  195. GRP_G("i2s", i2s_grp_mt7628, MT7628_GPIO_MODE_MASK,
  196. 1, MT7628_GPIO_MODE_I2S),
  197. GRP_G("spi cs1", spi_cs1_grp_mt7628, MT7628_GPIO_MODE_MASK,
  198. 1, MT7628_GPIO_MODE_CS1),
  199. GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK,
  200. 1, MT7628_GPIO_MODE_SPIS),
  201. GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK,
  202. 1, MT7628_GPIO_MODE_GPIO),
  203. { 0 }
  204. };
  205. static __init u32
  206. mt7620_calc_rate(u32 ref_rate, u32 mul, u32 div)
  207. {
  208. u64 t;
  209. t = ref_rate;
  210. t *= mul;
  211. do_div(t, div);
  212. return t;
  213. }
  214. #define MHZ(x) ((x) * 1000 * 1000)
  215. static __init unsigned long
  216. mt7620_get_xtal_rate(void)
  217. {
  218. u32 reg;
  219. reg = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0);
  220. if (reg & SYSCFG0_XTAL_FREQ_SEL)
  221. return MHZ(40);
  222. return MHZ(20);
  223. }
  224. static __init unsigned long
  225. mt7620_get_periph_rate(unsigned long xtal_rate)
  226. {
  227. u32 reg;
  228. reg = rt_sysc_r32(SYSC_REG_CLKCFG0);
  229. if (reg & CLKCFG0_PERI_CLK_SEL)
  230. return xtal_rate;
  231. return MHZ(40);
  232. }
  233. static const u32 mt7620_clk_divider[] __initconst = { 2, 3, 4, 8 };
  234. static __init unsigned long
  235. mt7620_get_cpu_pll_rate(unsigned long xtal_rate)
  236. {
  237. u32 reg;
  238. u32 mul;
  239. u32 div;
  240. reg = rt_sysc_r32(SYSC_REG_CPLL_CONFIG0);
  241. if (reg & CPLL_CFG0_BYPASS_REF_CLK)
  242. return xtal_rate;
  243. if ((reg & CPLL_CFG0_SW_CFG) == 0)
  244. return MHZ(600);
  245. mul = (reg >> CPLL_CFG0_PLL_MULT_RATIO_SHIFT) &
  246. CPLL_CFG0_PLL_MULT_RATIO_MASK;
  247. mul += 24;
  248. if (reg & CPLL_CFG0_LC_CURFCK)
  249. mul *= 2;
  250. div = (reg >> CPLL_CFG0_PLL_DIV_RATIO_SHIFT) &
  251. CPLL_CFG0_PLL_DIV_RATIO_MASK;
  252. WARN_ON(div >= ARRAY_SIZE(mt7620_clk_divider));
  253. return mt7620_calc_rate(xtal_rate, mul, mt7620_clk_divider[div]);
  254. }
  255. static __init unsigned long
  256. mt7620_get_pll_rate(unsigned long xtal_rate, unsigned long cpu_pll_rate)
  257. {
  258. u32 reg;
  259. reg = rt_sysc_r32(SYSC_REG_CPLL_CONFIG1);
  260. if (reg & CPLL_CFG1_CPU_AUX1)
  261. return xtal_rate;
  262. if (reg & CPLL_CFG1_CPU_AUX0)
  263. return MHZ(480);
  264. return cpu_pll_rate;
  265. }
  266. static __init unsigned long
  267. mt7620_get_cpu_rate(unsigned long pll_rate)
  268. {
  269. u32 reg;
  270. u32 mul;
  271. u32 div;
  272. reg = rt_sysc_r32(SYSC_REG_CPU_SYS_CLKCFG);
  273. mul = reg & CPU_SYS_CLKCFG_CPU_FFRAC_MASK;
  274. div = (reg >> CPU_SYS_CLKCFG_CPU_FDIV_SHIFT) &
  275. CPU_SYS_CLKCFG_CPU_FDIV_MASK;
  276. return mt7620_calc_rate(pll_rate, mul, div);
  277. }
  278. static const u32 mt7620_ocp_dividers[16] __initconst = {
  279. [CPU_SYS_CLKCFG_OCP_RATIO_2] = 2,
  280. [CPU_SYS_CLKCFG_OCP_RATIO_3] = 3,
  281. [CPU_SYS_CLKCFG_OCP_RATIO_4] = 4,
  282. [CPU_SYS_CLKCFG_OCP_RATIO_5] = 5,
  283. [CPU_SYS_CLKCFG_OCP_RATIO_10] = 10,
  284. };
  285. static __init unsigned long
  286. mt7620_get_dram_rate(unsigned long pll_rate)
  287. {
  288. if (dram_type == SYSCFG0_DRAM_TYPE_SDRAM)
  289. return pll_rate / 4;
  290. return pll_rate / 3;
  291. }
  292. static __init unsigned long
  293. mt7620_get_sys_rate(unsigned long cpu_rate)
  294. {
  295. u32 reg;
  296. u32 ocp_ratio;
  297. u32 div;
  298. reg = rt_sysc_r32(SYSC_REG_CPU_SYS_CLKCFG);
  299. ocp_ratio = (reg >> CPU_SYS_CLKCFG_OCP_RATIO_SHIFT) &
  300. CPU_SYS_CLKCFG_OCP_RATIO_MASK;
  301. if (WARN_ON(ocp_ratio >= ARRAY_SIZE(mt7620_ocp_dividers)))
  302. return cpu_rate;
  303. div = mt7620_ocp_dividers[ocp_ratio];
  304. if (WARN(!div, "invalid divider for OCP ratio %u", ocp_ratio))
  305. return cpu_rate;
  306. return cpu_rate / div;
  307. }
  308. void __init ralink_clk_init(void)
  309. {
  310. unsigned long xtal_rate;
  311. unsigned long cpu_pll_rate;
  312. unsigned long pll_rate;
  313. unsigned long cpu_rate;
  314. unsigned long sys_rate;
  315. unsigned long dram_rate;
  316. unsigned long periph_rate;
  317. xtal_rate = mt7620_get_xtal_rate();
  318. #define RFMT(label) label ":%lu.%03luMHz "
  319. #define RINT(x) ((x) / 1000000)
  320. #define RFRAC(x) (((x) / 1000) % 1000)
  321. if (mt762x_soc == MT762X_SOC_MT7628AN) {
  322. if (xtal_rate == MHZ(40))
  323. cpu_rate = MHZ(580);
  324. else
  325. cpu_rate = MHZ(575);
  326. dram_rate = sys_rate = cpu_rate / 3;
  327. periph_rate = MHZ(40);
  328. ralink_clk_add("10000d00.uartlite", periph_rate);
  329. ralink_clk_add("10000e00.uartlite", periph_rate);
  330. } else {
  331. cpu_pll_rate = mt7620_get_cpu_pll_rate(xtal_rate);
  332. pll_rate = mt7620_get_pll_rate(xtal_rate, cpu_pll_rate);
  333. cpu_rate = mt7620_get_cpu_rate(pll_rate);
  334. dram_rate = mt7620_get_dram_rate(pll_rate);
  335. sys_rate = mt7620_get_sys_rate(cpu_rate);
  336. periph_rate = mt7620_get_periph_rate(xtal_rate);
  337. pr_debug(RFMT("XTAL") RFMT("CPU_PLL") RFMT("PLL"),
  338. RINT(xtal_rate), RFRAC(xtal_rate),
  339. RINT(cpu_pll_rate), RFRAC(cpu_pll_rate),
  340. RINT(pll_rate), RFRAC(pll_rate));
  341. ralink_clk_add("10000500.uart", periph_rate);
  342. }
  343. pr_debug(RFMT("CPU") RFMT("DRAM") RFMT("SYS") RFMT("PERIPH"),
  344. RINT(cpu_rate), RFRAC(cpu_rate),
  345. RINT(dram_rate), RFRAC(dram_rate),
  346. RINT(sys_rate), RFRAC(sys_rate),
  347. RINT(periph_rate), RFRAC(periph_rate));
  348. #undef RFRAC
  349. #undef RINT
  350. #undef RFMT
  351. ralink_clk_add("cpu", cpu_rate);
  352. ralink_clk_add("10000100.timer", periph_rate);
  353. ralink_clk_add("10000120.watchdog", periph_rate);
  354. ralink_clk_add("10000b00.spi", sys_rate);
  355. ralink_clk_add("10000c00.uartlite", periph_rate);
  356. ralink_clk_add("10180000.wmac", xtal_rate);
  357. }
  358. void __init ralink_of_remap(void)
  359. {
  360. rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc");
  361. rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc");
  362. if (!rt_sysc_membase || !rt_memc_membase)
  363. panic("Failed to remap core resources");
  364. }
  365. static __init void
  366. mt7620_dram_init(struct ralink_soc_info *soc_info)
  367. {
  368. switch (dram_type) {
  369. case SYSCFG0_DRAM_TYPE_SDRAM:
  370. pr_info("Board has SDRAM\n");
  371. soc_info->mem_size_min = MT7620_SDRAM_SIZE_MIN;
  372. soc_info->mem_size_max = MT7620_SDRAM_SIZE_MAX;
  373. break;
  374. case SYSCFG0_DRAM_TYPE_DDR1:
  375. pr_info("Board has DDR1\n");
  376. soc_info->mem_size_min = MT7620_DDR1_SIZE_MIN;
  377. soc_info->mem_size_max = MT7620_DDR1_SIZE_MAX;
  378. break;
  379. case SYSCFG0_DRAM_TYPE_DDR2:
  380. pr_info("Board has DDR2\n");
  381. soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN;
  382. soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX;
  383. break;
  384. default:
  385. BUG();
  386. }
  387. }
  388. static __init void
  389. mt7628_dram_init(struct ralink_soc_info *soc_info)
  390. {
  391. switch (dram_type) {
  392. case SYSCFG0_DRAM_TYPE_DDR1_MT7628:
  393. pr_info("Board has DDR1\n");
  394. soc_info->mem_size_min = MT7620_DDR1_SIZE_MIN;
  395. soc_info->mem_size_max = MT7620_DDR1_SIZE_MAX;
  396. break;
  397. case SYSCFG0_DRAM_TYPE_DDR2_MT7628:
  398. pr_info("Board has DDR2\n");
  399. soc_info->mem_size_min = MT7620_DDR2_SIZE_MIN;
  400. soc_info->mem_size_max = MT7620_DDR2_SIZE_MAX;
  401. break;
  402. default:
  403. BUG();
  404. }
  405. }
  406. void prom_soc_init(struct ralink_soc_info *soc_info)
  407. {
  408. void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7620_SYSC_BASE);
  409. unsigned char *name = NULL;
  410. u32 n0;
  411. u32 n1;
  412. u32 rev;
  413. u32 cfg0;
  414. u32 pmu0;
  415. u32 pmu1;
  416. u32 bga;
  417. n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
  418. n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
  419. rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
  420. bga = (rev >> CHIP_REV_PKG_SHIFT) & CHIP_REV_PKG_MASK;
  421. if (n0 == MT7620_CHIP_NAME0 && n1 == MT7620_CHIP_NAME1) {
  422. if (bga) {
  423. mt762x_soc = MT762X_SOC_MT7620A;
  424. name = "MT7620A";
  425. soc_info->compatible = "ralink,mt7620a-soc";
  426. } else {
  427. mt762x_soc = MT762X_SOC_MT7620N;
  428. name = "MT7620N";
  429. soc_info->compatible = "ralink,mt7620n-soc";
  430. #ifdef CONFIG_PCI
  431. panic("mt7620n is only supported for non pci kernels");
  432. #endif
  433. }
  434. } else if (n0 == MT7620_CHIP_NAME0 && n1 == MT7628_CHIP_NAME1) {
  435. mt762x_soc = MT762X_SOC_MT7628AN;
  436. name = "MT7628AN";
  437. soc_info->compatible = "ralink,mt7628an-soc";
  438. } else {
  439. panic("mt762x: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  440. }
  441. snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  442. "Ralink %s ver:%u eco:%u",
  443. name,
  444. (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
  445. (rev & CHIP_REV_ECO_MASK));
  446. cfg0 = __raw_readl(sysc + SYSC_REG_SYSTEM_CONFIG0);
  447. dram_type = (cfg0 >> SYSCFG0_DRAM_TYPE_SHIFT) & SYSCFG0_DRAM_TYPE_MASK;
  448. soc_info->mem_base = MT7620_DRAM_BASE;
  449. if (mt762x_soc == MT762X_SOC_MT7628AN)
  450. mt7628_dram_init(soc_info);
  451. else
  452. mt7620_dram_init(soc_info);
  453. pmu0 = __raw_readl(sysc + PMU0_CFG);
  454. pmu1 = __raw_readl(sysc + PMU1_CFG);
  455. pr_info("Analog PMU set to %s control\n",
  456. (pmu0 & PMU_SW_SET) ? ("sw") : ("hw"));
  457. pr_info("Digital PMU set to %s control\n",
  458. (pmu1 & DIG_SW_SEL) ? ("sw") : ("hw"));
  459. if (mt762x_soc == MT762X_SOC_MT7628AN)
  460. rt2880_pinmux_data = mt7628an_pinmux_data;
  461. else
  462. rt2880_pinmux_data = mt7620a_pinmux_data;
  463. }