mt7621.c 6.7 KB

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