0071-clk.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. From c3a3617a8c37b43db7ff622a31f171d3ce870173 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Fri, 3 Jul 2015 05:44:57 +0200
  4. Subject: [PATCH 71/76] clk
  5. ---
  6. drivers/clk/mediatek/clk-mt7623.c | 194 ++++++++++++++++---------------------
  7. 1 file changed, 83 insertions(+), 111 deletions(-)
  8. diff --git a/drivers/clk/mediatek/clk-mt7623.c b/drivers/clk/mediatek/clk-mt7623.c
  9. index 07843bb..d46b2ad 100644
  10. --- a/drivers/clk/mediatek/clk-mt7623.c
  11. +++ b/drivers/clk/mediatek/clk-mt7623.c
  12. @@ -20,6 +20,7 @@
  13. #include "clk-mtk.h"
  14. #include "clk-gate.h"
  15. +#include "clk-cpumux.h"
  16. static DEFINE_SPINLOCK(mt7623_clk_lock);
  17. @@ -37,18 +38,11 @@ static void mtk_clk_enable_critical(void)
  18. clk_prepare_enable(mt7623_top_clk_data->clks[CLK_TOP_RTC_SEL]);
  19. }
  20. -static const struct mtk_fixed_factor root_clk_alias[] __initconst = {
  21. - FACTOR(CLK_TOP_DSI0_LNTC_DSICLK, "dsi0_lntc_dsiclk", "clk_null", 1, 1),
  22. - FACTOR(CLK_TOP_HDMITX_CLKDIG_CTS, "hdmitx_clkdig_cts", "clk_null", 1, 1),
  23. - FACTOR(CLK_TOP_CLKPH_MCK, "clkph_mck", "clk_null", 1, 1),
  24. - FACTOR(CLK_TOP_CPUM_TCK_IN, "cpum_tck_in", "clk_null", 1, 1),
  25. -};
  26. -
  27. static const struct mtk_fixed_factor top_divs[] __initconst = {
  28. - FACTOR(CLK_TOP_MAINPLL_806M, "mainpll_650m", "mainpll", 1, 2),
  29. - FACTOR(CLK_TOP_MAINPLL_537P3M, "mainpll_433p3m", "mainpll", 1, 3),
  30. - FACTOR(CLK_TOP_MAINPLL_322P4M, "mainpll_260m", "mainpll", 1, 5),
  31. - FACTOR(CLK_TOP_MAINPLL_230P3M, "mainpll_185p6m", "mainpll", 1, 7),
  32. + FACTOR(CLK_TOP_MAINPLL_650M, "mainpll_650m", "mainpll", 1, 2),
  33. + FACTOR(CLK_TOP_MAINPLL_433P3M, "mainpll_433p3m", "mainpll", 1, 3),
  34. + FACTOR(CLK_TOP_MAINPLL_260M, "mainpll_260m", "mainpll", 1, 5),
  35. + FACTOR(CLK_TOP_MAINPLL_185P6M, "mainpll_185p6m", "mainpll", 1, 7),
  36. FACTOR(CLK_TOP_UNIVPLL_624M, "univpll_624m", "univpll", 1, 2),
  37. FACTOR(CLK_TOP_UNIVPLL_416M, "univpll_416m", "univpll", 1, 3),
  38. @@ -61,13 +55,6 @@ static const struct mtk_fixed_factor top_divs[] __initconst = {
  39. FACTOR(CLK_TOP_AUDPLL_D16, "audpll_d16", "audpll", 1, 16),
  40. FACTOR(CLK_TOP_AUDPLL_24, "audpll_d24", "audpll", 1, 24),
  41. - FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll", 1, 2),
  42. - FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll", 1, 4),
  43. - FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll", 1, 8),
  44. - FACTOR(CLK_TOP_LVDS_ETH, "lvdspll_eth", "lvdspll", 1, 16),
  45. -
  46. - FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
  47. -
  48. FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2),
  49. FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "mainpll_650m", 1, 2),
  50. @@ -85,9 +72,6 @@ static const struct mtk_fixed_factor top_divs[] __initconst = {
  51. FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll_260m", 1, 1),
  52. FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll_185p6m", 1, 1),
  53. - FACTOR(CLK_TOP_TVDPLL_d2, "tvdpll_d2", "tvdpll", 1, 2),
  54. - FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1, 4),
  55. -
  56. FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_624m", 1, 2),
  57. FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_624m", 1, 4),
  58. FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_624m", 1, 8),
  59. @@ -110,9 +94,6 @@ static const struct mtk_fixed_factor top_divs[] __initconst = {
  60. FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_249p6m", 1, 1),
  61. FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_48m", 1, 1),
  62. -
  63. -
  64. - FACTOR(CLK_TOP_MEMPLL_MCK_D4, "mempll_mck_d4", "clkph_mck", 1, 4),
  65. };
  66. static const char * const axi_parents[] __initconst = {
  67. @@ -155,18 +136,6 @@ static const char * const pwm_parents[] __initconst = {
  68. "univpll1_d4",
  69. };
  70. -static const char * const vdec_parents[] __initconst = {
  71. - "clk26m",
  72. - "syspll1_d2",
  73. - "syspll_d5",
  74. - "syspll1_d4",
  75. - "univpll_d5",
  76. - "univpll2_d2",
  77. - "univpll2_d4",
  78. - "msdcpll_d2",
  79. - "mmpll_d2",
  80. -};
  81. -
  82. static const char * const mfg_parents[] __initconst = {
  83. "clk26m",
  84. "mmpll_ck",
  85. @@ -178,17 +147,6 @@ static const char * const mfg_parents[] __initconst = {
  86. "univpll1_d2",
  87. };
  88. -static const char * const cam_parents[] __initconst = {
  89. - "clk26m",
  90. - "univpll_d26",
  91. - "univpll2_d2",
  92. - "syspll3_d2",
  93. - "syspll3_d4",
  94. - "msdcpll_d2",
  95. - "mmpll_d2",
  96. - "clk26m",
  97. -};
  98. -
  99. static const char * const uart_parents[] __initconst = {
  100. "clk26m",
  101. "univpll2_d8",
  102. @@ -277,35 +235,6 @@ static const char * const scp_parents[] __initconst = {
  103. "dmpll_d4",
  104. };
  105. -static const char * const dpi0_parents[] __initconst = {
  106. - "clk26m",
  107. - "mipipll",
  108. - "mipipll_d2",
  109. - "mipipll_d4",
  110. - "lvdspll",
  111. - "lvdspll_d2",
  112. - "lvdspll_d4",
  113. - "lvdspll_d8",
  114. -};
  115. -
  116. -static const char * const dpi1_parents[] __initconst = {
  117. - "clk26m",
  118. - "tvdpll",
  119. - "tvdpll_d2",
  120. - "tvdpll_d4",
  121. -};
  122. -
  123. -static const char * const tve_parents[] __initconst = {
  124. - "clk26m",
  125. - "mipipll",
  126. - "mipipll_d2",
  127. - "mipipll_d4",
  128. - "clk26m",
  129. - "tvdpll",
  130. - "tvdpll_d2",
  131. - "tvdpll_d4",
  132. -};
  133. -
  134. static const char * const apll_parents[] __initconst = {
  135. "clk26m",
  136. "audpll",
  137. @@ -317,17 +246,6 @@ static const char * const apll_parents[] __initconst = {
  138. "clk26m",
  139. };
  140. -static const char * const dpilvds_parents[] __initconst = {
  141. - "clk26m",
  142. - "lvdspll",
  143. - "lvdspll_d2",
  144. - "lvdspll_d4",
  145. - "lvdspll_d8",
  146. - "fpc_ck",
  147. - "clk26m",
  148. - "clk26m",
  149. -};
  150. -
  151. static const char * const rtc_parents[] __initconst = {
  152. "clk32k",
  153. "external_32k",
  154. @@ -367,9 +285,7 @@ static const struct mtk_composite top_muxes[] __initconst = {
  155. 0x0140, 24, 3, INVALID_MUX_GATE_BIT),
  156. /* CLK_CFG_1 */
  157. MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x0050, 0, 2, 7),
  158. - MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel", vdec_parents, 0x0050, 8, 4, 15),
  159. MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents, 0x0050, 16, 3, 23),
  160. - MUX_GATE(CLK_TOP_CAM_SEL, "cam_sel", cam_parents, 0x0050, 24, 3, 31),
  161. /* CLK_CFG_2 */
  162. MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x0060, 0, 1, 7),
  163. MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x0060, 8, 3, 15),
  164. @@ -384,12 +300,8 @@ static const struct mtk_composite top_muxes[] __initconst = {
  165. /* CLK_CFG_4 */
  166. MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmic_spi_parents, 0x0080, 0, 4, 7),
  167. MUX_GATE(CLK_TOP_SCP_SEL, "scp_sel", scp_parents, 0x0080, 8, 2, 15),
  168. - MUX_GATE(CLK_TOP_DPI0_SEL, "dpi0_sel", dpi0_parents, 0x0080, 16, 3, 23),
  169. - MUX_GATE(CLK_TOP_DPI1_SEL, "dpi1_sel", dpi1_parents, 0x0080, 24, 2, 31),
  170. /* CLK_CFG_5 */
  171. - MUX_GATE(CLK_TOP_TVE_SEL, "tve_sel", tve_parents, 0x0090, 0, 3, 7),
  172. MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel", apll_parents, 0x0090, 16, 3, 23),
  173. - MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel", dpilvds_parents, 0x0090, 24, 3, 31),
  174. /* CLK_CFG_6 */
  175. MUX_GATE(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x00a0, 0, 2, 7),
  176. MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel", nfi2x_parents, 0x00a0, 8, 3, 15),
  177. @@ -428,6 +340,17 @@ static const struct mtk_gate infra_clks[] __initconst = {
  178. GATE_ICG(CLK_INFRA_PMIC_WRAP, "pmic_wrap_ck", "axi_sel", 23),
  179. };
  180. +static const char * const ca7_parents[] __initconst = {
  181. + "clk26m",
  182. + "armpll",
  183. + "mainpll",
  184. + "univpll"
  185. +};
  186. +
  187. +static struct mtk_composite cpu_muxes[] __initdata = {
  188. + MUX(CLK_INFRA_CA7SEL, "infra_ca7_sel", ca7_parents, 0x0000, 2, 2),
  189. +};
  190. +
  191. static const struct mtk_gate_regs peri0_cg_regs = {
  192. .set_ofs = 0x0008,
  193. .clr_ofs = 0x0010,
  194. @@ -499,6 +422,29 @@ static const struct mtk_gate peri_gates[] __initconst = {
  195. GATE_PERI1(CLK_PERI_NFI_PAD, "nfi_pad_ck", "axi_sel", 2),
  196. };
  197. +static const struct mtk_gate_regs hifsys_cg_regs = {
  198. + .set_ofs = 0x0034,
  199. + .clr_ofs = 0x0014,
  200. + .sta_ofs = 0x0038,
  201. +};
  202. +
  203. +#define GATE_HIFSYS(_id, _name, _parent, _shift) { \
  204. + .id = _id, \
  205. + .name = _name, \
  206. + .parent_name = _parent, \
  207. + .regs = &hifsys_cg_regs, \
  208. + .shift = _shift, \
  209. + .ops = &mtk_clk_gate_ops_setclr, \
  210. + }
  211. +
  212. +static const struct mtk_gate hifsys_gates[] __initconst = {
  213. + GATE_HIFSYS(CLK_HIFSYS_USB0_PHY, "usb0_phy_ck", "axi_sel", 21),
  214. + GATE_HIFSYS(CLK_HIFSYS_USB1_PHY, "usb1_phy_ck", "axi_sel", 22),
  215. + GATE_HIFSYS(CLK_HIFSYS_PCIE0, "pcie0_ck", "axi_sel", 24),
  216. + GATE_HIFSYS(CLK_HIFSYS_PCIE1, "pcie1_ck", "axi_sel", 25),
  217. + GATE_HIFSYS(CLK_HIFSYS_PCIE2, "pcie2_ck", "axi_sel", 26),
  218. +};
  219. +
  220. static const char * const uart_ck_sel_parents[] __initconst = {
  221. "clk26m",
  222. "uart_sel",
  223. @@ -525,10 +471,9 @@ static void __init mtk_topckgen_init(struct device_node *node)
  224. mt7623_top_clk_data = clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
  225. - mtk_clk_register_factors(root_clk_alias, ARRAY_SIZE(root_clk_alias), clk_data);
  226. mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
  227. mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
  228. - &mt7623_clk_lock, clk_data);
  229. + &mt7623_clk_lock, clk_data);
  230. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  231. if (r)
  232. @@ -547,7 +492,10 @@ static void __init mtk_infrasys_init(struct device_node *node)
  233. clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
  234. mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
  235. - clk_data);
  236. + clk_data);
  237. +
  238. + mtk_clk_register_cpumuxes(node, cpu_muxes, ARRAY_SIZE(cpu_muxes),
  239. + clk_data);
  240. clk_prepare_enable(clk_data->clks[CLK_INFRA_M4U]);
  241. @@ -588,35 +536,59 @@ static void __init mtk_pericfg_init(struct device_node *node)
  242. }
  243. CLK_OF_DECLARE(mtk_pericfg, "mediatek,mt7623-pericfg", mtk_pericfg_init);
  244. -#define MT7623_PLL_FMAX (2000 * MHZ)
  245. -#define CON0_MT7623_RST_BAR BIT(27)
  246. +static void __init mtk_hifsys_init(struct device_node *node)
  247. +{
  248. + struct clk_onecell_data *clk_data;
  249. + int r;
  250. + void __iomem *base;
  251. +
  252. + base = of_iomap(node, 0);
  253. + if (!base) {
  254. + pr_err("%s(): ioremap failed\n", __func__);
  255. + return;
  256. + }
  257. +
  258. + clk_data = mtk_alloc_clk_data(CLK_HIFSYS_NR_CLK);
  259. +
  260. + mtk_clk_register_gates(node, hifsys_gates, ARRAY_SIZE(hifsys_gates),
  261. + clk_data);
  262. +
  263. + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  264. + if (r)
  265. + pr_err("%s(): could not register clock provider: %d\n",
  266. + __func__, r);
  267. +
  268. + mtk_register_reset_controller(node, 1, 0x34);
  269. +}
  270. +CLK_OF_DECLARE(mtk_hifsys, "mediatek,mt7623-hifsys", mtk_hifsys_init);
  271. +
  272. +#define MT7623_PLL_FMAX (1300 * MHZ)
  273. +#define CON0_MT7623_RST_BAR BIT(24)
  274. -#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) { \
  275. +#define PLL(_id, _name, _con0_reg, _con1_reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pcw_shift, _pd_shift) { \
  276. .id = _id, \
  277. .name = _name, \
  278. - .reg = _reg, \
  279. + .reg = _con0_reg, \
  280. .pwr_reg = _pwr_reg, \
  281. .en_mask = _en_mask, \
  282. .flags = _flags, \
  283. .rst_bar_mask = CON0_MT7623_RST_BAR, \
  284. .fmax = MT7623_PLL_FMAX, \
  285. .pcwbits = _pcwbits, \
  286. - .pd_reg = _pd_reg, \
  287. + .pd_reg = _con0_reg, \
  288. .pd_shift = _pd_shift, \
  289. - .tuner_reg = _tuner_reg, \
  290. - .pcw_reg = _pcw_reg, \
  291. + .pcw_reg = _con1_reg, \
  292. .pcw_shift = _pcw_shift, \
  293. }
  294. static const struct mtk_pll_data plls[] = {
  295. - PLL(CLK_APMIXED_ARMPLL, "armpll", 0x200, 0x20c, 0x00000001, 0, 21, 0x204, 24, 0x0, 0x204, 0),
  296. - PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x210, 0x21c, 0x78000001, HAVE_RST_BAR, 21, 0x214, 6, 0x0, 0x214, 0),
  297. - PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x220, 0x22c, 0xFC000001, HAVE_RST_BAR, 7, 0x224, 6, 0x0, 0x224, 0),
  298. - PLL(CLK_APMIXED_MMPLL, "mmpll", 0x230, 0x23c, 0x00000001, 0, 21, 0x254, 6, 0x0, 0x258, 0),
  299. - PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x240, 0x24c, 0x00000001, 0, 21, 0x244, 6, 0x0, 0x244, 0),
  300. - PLL(CLK_APMIXED_AUDPLL, "audpll", 0x250, 0x25c, 0x00000001, 0, 31, 0x2e8, 6, 0x2f8, 0x254, 0),
  301. - PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x260, 0x26c, 0x00000001, 0, 31, 0x294, 6, 0x0, 0x298, 0),
  302. - PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x270, 0x27c, 0x00000001, 0, 21, 0x2b0, 6, 0x0, 0x2b4, 0),
  303. + PLL(CLK_APMIXED_ARMPLL, "armpll", 0x200, 0x204, 0x20c, 0x00000001, 0, 21, 0, 4 ),
  304. + PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x210, 0x214, 0x21c, 0x78000001, HAVE_RST_BAR, 21, 0, 4 ),
  305. + PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x220, 0x224, 0x22c, 0xFC000001, HAVE_RST_BAR, 7, 14, 4 ),
  306. + PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x240, 0x244, 0x24c, 0x00000001, 0, 21, 0, 4 ),
  307. + PLL(CLK_APMIXED_AUDPLL, "audpll", 0x270, 0x274, 0x27c, 0x00000001, 0, 31, 0, 4 ),
  308. + PLL(CLK_APMIXED_TRGPLL, "trgpll", 0x280, 0x284, 0x28c, 0x00000001, 0, 31, 0, 4 ),
  309. + PLL(CLK_APMIXED_ETHPLL, "ethpll", 0x290, 0x294, 0x29c, 0x00000001, 0, 31, 0, 4 ),
  310. };
  311. static void __init mtk_apmixedsys_init(struct device_node *node)
  312. --
  313. 1.7.10.4