mt7621.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * Copyright (C) 2015 Nikolay Martynov <mar.kolya@gmail.com>
  7. * Copyright (C) 2015 John Crispin <john@phrozen.org>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <asm/mipsregs.h>
  12. #include <asm/smp-ops.h>
  13. #include <asm/mips-cps.h>
  14. #include <asm/mach-ralink/ralink_regs.h>
  15. #include <asm/mach-ralink/mt7621.h>
  16. #include <pinmux.h>
  17. #include "common.h"
  18. #define SYSC_REG_SYSCFG 0x10
  19. #define SYSC_REG_CPLL_CLKCFG0 0x2c
  20. #define SYSC_REG_CUR_CLK_STS 0x44
  21. #define CPU_CLK_SEL (BIT(30) | BIT(31))
  22. #define MT7621_GPIO_MODE_UART1 1
  23. #define MT7621_GPIO_MODE_I2C 2
  24. #define MT7621_GPIO_MODE_UART3_MASK 0x3
  25. #define MT7621_GPIO_MODE_UART3_SHIFT 3
  26. #define MT7621_GPIO_MODE_UART3_GPIO 1
  27. #define MT7621_GPIO_MODE_UART2_MASK 0x3
  28. #define MT7621_GPIO_MODE_UART2_SHIFT 5
  29. #define MT7621_GPIO_MODE_UART2_GPIO 1
  30. #define MT7621_GPIO_MODE_JTAG 7
  31. #define MT7621_GPIO_MODE_WDT_MASK 0x3
  32. #define MT7621_GPIO_MODE_WDT_SHIFT 8
  33. #define MT7621_GPIO_MODE_WDT_GPIO 1
  34. #define MT7621_GPIO_MODE_PCIE_RST 0
  35. #define MT7621_GPIO_MODE_PCIE_REF 2
  36. #define MT7621_GPIO_MODE_PCIE_MASK 0x3
  37. #define MT7621_GPIO_MODE_PCIE_SHIFT 10
  38. #define MT7621_GPIO_MODE_PCIE_GPIO 1
  39. #define MT7621_GPIO_MODE_MDIO_MASK 0x3
  40. #define MT7621_GPIO_MODE_MDIO_SHIFT 12
  41. #define MT7621_GPIO_MODE_MDIO_GPIO 1
  42. #define MT7621_GPIO_MODE_RGMII1 14
  43. #define MT7621_GPIO_MODE_RGMII2 15
  44. #define MT7621_GPIO_MODE_SPI_MASK 0x3
  45. #define MT7621_GPIO_MODE_SPI_SHIFT 16
  46. #define MT7621_GPIO_MODE_SPI_GPIO 1
  47. #define MT7621_GPIO_MODE_SDHCI_MASK 0x3
  48. #define MT7621_GPIO_MODE_SDHCI_SHIFT 18
  49. #define MT7621_GPIO_MODE_SDHCI_GPIO 1
  50. static struct rt2880_pmx_func uart1_grp[] = { FUNC("uart1", 0, 1, 2) };
  51. static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 3, 2) };
  52. static struct rt2880_pmx_func uart3_grp[] = {
  53. FUNC("uart3", 0, 5, 4),
  54. FUNC("i2s", 2, 5, 4),
  55. FUNC("spdif3", 3, 5, 4),
  56. };
  57. static struct rt2880_pmx_func uart2_grp[] = {
  58. FUNC("uart2", 0, 9, 4),
  59. FUNC("pcm", 2, 9, 4),
  60. FUNC("spdif2", 3, 9, 4),
  61. };
  62. static struct rt2880_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) };
  63. static struct rt2880_pmx_func wdt_grp[] = {
  64. FUNC("wdt rst", 0, 18, 1),
  65. FUNC("wdt refclk", 2, 18, 1),
  66. };
  67. static struct rt2880_pmx_func pcie_rst_grp[] = {
  68. FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
  69. FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
  70. };
  71. static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) };
  72. static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 22, 12) };
  73. static struct rt2880_pmx_func spi_grp[] = {
  74. FUNC("spi", 0, 34, 7),
  75. FUNC("nand1", 2, 34, 7),
  76. };
  77. static struct rt2880_pmx_func sdhci_grp[] = {
  78. FUNC("sdhci", 0, 41, 8),
  79. FUNC("nand2", 2, 41, 8),
  80. };
  81. static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 49, 12) };
  82. static struct rt2880_pmx_group mt7621_pinmux_data[] = {
  83. GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1),
  84. GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C),
  85. GRP_G("uart3", uart3_grp, MT7621_GPIO_MODE_UART3_MASK,
  86. MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT),
  87. GRP_G("uart2", uart2_grp, MT7621_GPIO_MODE_UART2_MASK,
  88. MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT),
  89. GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG),
  90. GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK,
  91. MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
  92. GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK,
  93. MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
  94. GRP_G("mdio", mdio_grp, MT7621_GPIO_MODE_MDIO_MASK,
  95. MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT),
  96. GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2),
  97. GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK,
  98. MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
  99. GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK,
  100. MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
  101. GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1),
  102. { 0 }
  103. };
  104. phys_addr_t mips_cpc_default_phys_base(void)
  105. {
  106. panic("Cannot detect cpc address");
  107. }
  108. void __init ralink_clk_init(void)
  109. {
  110. int cpu_fdiv = 0;
  111. int cpu_ffrac = 0;
  112. int fbdiv = 0;
  113. u32 clk_sts, syscfg;
  114. u8 clk_sel = 0, xtal_mode;
  115. u32 cpu_clk;
  116. if ((rt_sysc_r32(SYSC_REG_CPLL_CLKCFG0) & CPU_CLK_SEL) != 0)
  117. clk_sel = 1;
  118. switch (clk_sel) {
  119. case 0:
  120. clk_sts = rt_sysc_r32(SYSC_REG_CUR_CLK_STS);
  121. cpu_fdiv = ((clk_sts >> 8) & 0x1F);
  122. cpu_ffrac = (clk_sts & 0x1F);
  123. cpu_clk = (500 * cpu_ffrac / cpu_fdiv) * 1000 * 1000;
  124. break;
  125. case 1:
  126. fbdiv = ((rt_sysc_r32(0x648) >> 4) & 0x7F) + 1;
  127. syscfg = rt_sysc_r32(SYSC_REG_SYSCFG);
  128. xtal_mode = (syscfg >> 6) & 0x7;
  129. if (xtal_mode >= 6) {
  130. /* 25Mhz Xtal */
  131. cpu_clk = 25 * fbdiv * 1000 * 1000;
  132. } else if (xtal_mode >= 3) {
  133. /* 40Mhz Xtal */
  134. cpu_clk = 40 * fbdiv * 1000 * 1000;
  135. } else {
  136. /* 20Mhz Xtal */
  137. cpu_clk = 20 * fbdiv * 1000 * 1000;
  138. }
  139. break;
  140. }
  141. }
  142. void __init ralink_of_remap(void)
  143. {
  144. rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc");
  145. rt_memc_membase = plat_of_remap_node("mtk,mt7621-memc");
  146. if (!rt_sysc_membase || !rt_memc_membase)
  147. panic("Failed to remap core resources");
  148. }
  149. void prom_soc_init(struct ralink_soc_info *soc_info)
  150. {
  151. void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE);
  152. unsigned char *name = NULL;
  153. u32 n0;
  154. u32 n1;
  155. u32 rev;
  156. /* Early detection of CMP support */
  157. mips_cm_probe();
  158. mips_cpc_probe();
  159. if (mips_cps_numiocu(0)) {
  160. /*
  161. * mips_cm_probe() wipes out bootloader
  162. * config for CM regions and we have to configure them
  163. * again. This SoC cannot talk to pamlbus devices
  164. * witout proper iocu region set up.
  165. *
  166. * FIXME: it would be better to do this with values
  167. * from DT, but we need this very early because
  168. * without this we cannot talk to pretty much anything
  169. * including serial.
  170. */
  171. write_gcr_reg0_base(MT7621_PALMBUS_BASE);
  172. write_gcr_reg0_mask(~MT7621_PALMBUS_SIZE |
  173. CM_GCR_REGn_MASK_CMTGT_IOCU0);
  174. __sync();
  175. }
  176. n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
  177. n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
  178. if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) {
  179. name = "MT7621";
  180. soc_info->compatible = "mtk,mt7621-soc";
  181. } else {
  182. panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  183. }
  184. ralink_soc = MT762X_SOC_MT7621AT;
  185. rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
  186. snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
  187. "MediaTek %s ver:%u eco:%u",
  188. name,
  189. (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
  190. (rev & CHIP_REV_ECO_MASK));
  191. soc_info->mem_size_min = MT7621_DDR2_SIZE_MIN;
  192. soc_info->mem_size_max = MT7621_DDR2_SIZE_MAX;
  193. soc_info->mem_base = MT7621_DRAM_BASE;
  194. rt2880_pinmux_data = mt7621_pinmux_data;
  195. if (!register_cps_smp_ops())
  196. return;
  197. if (!register_cmp_smp_ops())
  198. return;
  199. if (!register_vsmp_smp_ops())
  200. return;
  201. }