mt7621.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 <linux/module.h>
  12. #include <asm/mipsregs.h>
  13. #include <asm/smp-ops.h>
  14. #include <asm/mips-cm.h>
  15. #include <asm/mips-cpc.h>
  16. #include <asm/mach-ralink/ralink_regs.h>
  17. #include <asm/mach-ralink/mt7621.h>
  18. #include <pinmux.h>
  19. #include "common.h"
  20. #define SYSC_REG_SYSCFG 0x10
  21. #define SYSC_REG_CPLL_CLKCFG0 0x2c
  22. #define SYSC_REG_CUR_CLK_STS 0x44
  23. #define CPU_CLK_SEL (BIT(30) | BIT(31))
  24. #define MT7621_GPIO_MODE_UART1 1
  25. #define MT7621_GPIO_MODE_I2C 2
  26. #define MT7621_GPIO_MODE_UART3_MASK 0x3
  27. #define MT7621_GPIO_MODE_UART3_SHIFT 3
  28. #define MT7621_GPIO_MODE_UART3_GPIO 1
  29. #define MT7621_GPIO_MODE_UART2_MASK 0x3
  30. #define MT7621_GPIO_MODE_UART2_SHIFT 5
  31. #define MT7621_GPIO_MODE_UART2_GPIO 1
  32. #define MT7621_GPIO_MODE_JTAG 7
  33. #define MT7621_GPIO_MODE_WDT_MASK 0x3
  34. #define MT7621_GPIO_MODE_WDT_SHIFT 8
  35. #define MT7621_GPIO_MODE_WDT_GPIO 1
  36. #define MT7621_GPIO_MODE_PCIE_RST 0
  37. #define MT7621_GPIO_MODE_PCIE_REF 2
  38. #define MT7621_GPIO_MODE_PCIE_MASK 0x3
  39. #define MT7621_GPIO_MODE_PCIE_SHIFT 10
  40. #define MT7621_GPIO_MODE_PCIE_GPIO 1
  41. #define MT7621_GPIO_MODE_MDIO_MASK 0x3
  42. #define MT7621_GPIO_MODE_MDIO_SHIFT 12
  43. #define MT7621_GPIO_MODE_MDIO_GPIO 1
  44. #define MT7621_GPIO_MODE_RGMII1 14
  45. #define MT7621_GPIO_MODE_RGMII2 15
  46. #define MT7621_GPIO_MODE_SPI_MASK 0x3
  47. #define MT7621_GPIO_MODE_SPI_SHIFT 16
  48. #define MT7621_GPIO_MODE_SPI_GPIO 1
  49. #define MT7621_GPIO_MODE_SDHCI_MASK 0x3
  50. #define MT7621_GPIO_MODE_SDHCI_SHIFT 18
  51. #define MT7621_GPIO_MODE_SDHCI_GPIO 1
  52. static struct rt2880_pmx_func uart1_grp[] = { FUNC("uart1", 0, 1, 2) };
  53. static struct rt2880_pmx_func i2c_grp[] = { FUNC("i2c", 0, 3, 2) };
  54. static struct rt2880_pmx_func uart3_grp[] = {
  55. FUNC("uart3", 0, 5, 4),
  56. FUNC("i2s", 2, 5, 4),
  57. FUNC("spdif3", 3, 5, 4),
  58. };
  59. static struct rt2880_pmx_func uart2_grp[] = {
  60. FUNC("uart2", 0, 9, 4),
  61. FUNC("pcm", 2, 9, 4),
  62. FUNC("spdif2", 3, 9, 4),
  63. };
  64. static struct rt2880_pmx_func jtag_grp[] = { FUNC("jtag", 0, 13, 5) };
  65. static struct rt2880_pmx_func wdt_grp[] = {
  66. FUNC("wdt rst", 0, 18, 1),
  67. FUNC("wdt refclk", 2, 18, 1),
  68. };
  69. static struct rt2880_pmx_func pcie_rst_grp[] = {
  70. FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1),
  71. FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1)
  72. };
  73. static struct rt2880_pmx_func mdio_grp[] = { FUNC("mdio", 0, 20, 2) };
  74. static struct rt2880_pmx_func rgmii2_grp[] = { FUNC("rgmii2", 0, 22, 12) };
  75. static struct rt2880_pmx_func spi_grp[] = {
  76. FUNC("spi", 0, 34, 7),
  77. FUNC("nand1", 2, 34, 7),
  78. };
  79. static struct rt2880_pmx_func sdhci_grp[] = {
  80. FUNC("sdhci", 0, 41, 8),
  81. FUNC("nand2", 2, 41, 8),
  82. };
  83. static struct rt2880_pmx_func rgmii1_grp[] = { FUNC("rgmii1", 0, 49, 12) };
  84. static struct rt2880_pmx_group mt7621_pinmux_data[] = {
  85. GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1),
  86. GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C),
  87. GRP_G("uart3", uart3_grp, MT7621_GPIO_MODE_UART3_MASK,
  88. MT7621_GPIO_MODE_UART3_GPIO, MT7621_GPIO_MODE_UART3_SHIFT),
  89. GRP_G("uart2", uart2_grp, MT7621_GPIO_MODE_UART2_MASK,
  90. MT7621_GPIO_MODE_UART2_GPIO, MT7621_GPIO_MODE_UART2_SHIFT),
  91. GRP("jtag", jtag_grp, 1, MT7621_GPIO_MODE_JTAG),
  92. GRP_G("wdt", wdt_grp, MT7621_GPIO_MODE_WDT_MASK,
  93. MT7621_GPIO_MODE_WDT_GPIO, MT7621_GPIO_MODE_WDT_SHIFT),
  94. GRP_G("pcie", pcie_rst_grp, MT7621_GPIO_MODE_PCIE_MASK,
  95. MT7621_GPIO_MODE_PCIE_GPIO, MT7621_GPIO_MODE_PCIE_SHIFT),
  96. GRP_G("mdio", mdio_grp, MT7621_GPIO_MODE_MDIO_MASK,
  97. MT7621_GPIO_MODE_MDIO_GPIO, MT7621_GPIO_MODE_MDIO_SHIFT),
  98. GRP("rgmii2", rgmii2_grp, 1, MT7621_GPIO_MODE_RGMII2),
  99. GRP_G("spi", spi_grp, MT7621_GPIO_MODE_SPI_MASK,
  100. MT7621_GPIO_MODE_SPI_GPIO, MT7621_GPIO_MODE_SPI_SHIFT),
  101. GRP_G("sdhci", sdhci_grp, MT7621_GPIO_MODE_SDHCI_MASK,
  102. MT7621_GPIO_MODE_SDHCI_GPIO, MT7621_GPIO_MODE_SDHCI_SHIFT),
  103. GRP("rgmii1", rgmii1_grp, 1, MT7621_GPIO_MODE_RGMII1),
  104. { 0 }
  105. };
  106. phys_addr_t mips_cpc_default_phys_base(void)
  107. {
  108. panic("Cannot detect cpc address");
  109. }
  110. void __init ralink_clk_init(void)
  111. {
  112. int cpu_fdiv = 0;
  113. int cpu_ffrac = 0;
  114. int fbdiv = 0;
  115. u32 clk_sts, syscfg;
  116. u8 clk_sel = 0, xtal_mode;
  117. u32 cpu_clk;
  118. if ((rt_sysc_r32(SYSC_REG_CPLL_CLKCFG0) & CPU_CLK_SEL) != 0)
  119. clk_sel = 1;
  120. switch (clk_sel) {
  121. case 0:
  122. clk_sts = rt_sysc_r32(SYSC_REG_CUR_CLK_STS);
  123. cpu_fdiv = ((clk_sts >> 8) & 0x1F);
  124. cpu_ffrac = (clk_sts & 0x1F);
  125. cpu_clk = (500 * cpu_ffrac / cpu_fdiv) * 1000 * 1000;
  126. break;
  127. case 1:
  128. fbdiv = ((rt_sysc_r32(0x648) >> 4) & 0x7F) + 1;
  129. syscfg = rt_sysc_r32(SYSC_REG_SYSCFG);
  130. xtal_mode = (syscfg >> 6) & 0x7;
  131. if (xtal_mode >= 6) {
  132. /* 25Mhz Xtal */
  133. cpu_clk = 25 * fbdiv * 1000 * 1000;
  134. } else if (xtal_mode >= 3) {
  135. /* 40Mhz Xtal */
  136. cpu_clk = 40 * fbdiv * 1000 * 1000;
  137. } else {
  138. /* 20Mhz Xtal */
  139. cpu_clk = 20 * fbdiv * 1000 * 1000;
  140. }
  141. break;
  142. }
  143. }
  144. void __init ralink_of_remap(void)
  145. {
  146. rt_sysc_membase = plat_of_remap_node("mtk,mt7621-sysc");
  147. rt_memc_membase = plat_of_remap_node("mtk,mt7621-memc");
  148. if (!rt_sysc_membase || !rt_memc_membase)
  149. panic("Failed to remap core resources");
  150. }
  151. void prom_soc_init(struct ralink_soc_info *soc_info)
  152. {
  153. void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE);
  154. unsigned char *name = NULL;
  155. u32 n0;
  156. u32 n1;
  157. u32 rev;
  158. n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
  159. n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
  160. if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) {
  161. name = "MT7621";
  162. soc_info->compatible = "mtk,mt7621-soc";
  163. } else {
  164. panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
  165. }
  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. }