blob: 4a712555ed06f5f5dc52f03c38c9ef4aa55d45ce [file] [log] [blame]
Dzmitry Sankouski90496af2021-10-17 13:44:30 +03001// SPDX-License-Identifier: BSD-3-Clause
2/*
3 * Clock drivers for Qualcomm SDM845
4 *
5 * (C) Copyright 2017 Jorge Ramirez Ortiz <jorge.ramirez-ortiz@linaro.org>
6 * (C) Copyright 2021 Dzmitry Sankouski <dsankouski@gmail.com>
7 *
8 * Based on Little Kernel driver, simplified
9 */
10
11#include <common.h>
12#include <clk-uclass.h>
13#include <dm.h>
Caleb Connolly6985e302023-11-07 12:41:02 +000014#include <linux/delay.h>
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030015#include <errno.h>
16#include <asm/io.h>
17#include <linux/bitops.h>
Sumit Gargffa79282022-07-12 12:42:06 +053018#include <dt-bindings/clock/qcom,gcc-sdm845.h>
Konrad Dybciod9935732023-11-07 12:41:01 +000019
Caleb Connolly5bb0df62023-11-07 12:40:59 +000020#include "clock-qcom.h"
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030021
Caleb Connollyc94f9e92023-11-07 12:41:03 +000022#define SE9_UART_APPS_CMD_RCGR 0x18148
Caleb Connollyc94f9e92023-11-07 12:41:03 +000023
Caleb Connolly4d384602023-10-10 16:55:57 +010024#define USB30_PRIM_MASTER_CLK_CMD_RCGR 0xf018
25#define USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR 0xf030
26#define USB3_PRIM_PHY_AUX_CMD_RCGR 0xf05c
27
28#define USB30_PRIM_GDSCR 0xf004
29#define USB30_SEC_GDSCR 0x10004
30
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030031static const struct freq_tbl ftbl_gcc_qupv3_wrap0_s0_clk_src[] = {
32 F(7372800, CFG_CLK_SRC_GPLL0_EVEN, 1, 384, 15625),
33 F(14745600, CFG_CLK_SRC_GPLL0_EVEN, 1, 768, 15625),
34 F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
35 F(29491200, CFG_CLK_SRC_GPLL0_EVEN, 1, 1536, 15625),
36 F(32000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 75),
37 F(48000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 25),
38 F(64000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 16, 75),
39 F(80000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 15),
40 F(96000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 25),
41 F(100000000, CFG_CLK_SRC_GPLL0_EVEN, 3, 0, 0),
42 F(102400000, CFG_CLK_SRC_GPLL0_EVEN, 1, 128, 375),
43 F(112000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 28, 75),
44 F(117964800, CFG_CLK_SRC_GPLL0_EVEN, 1, 6144, 15625),
45 F(120000000, CFG_CLK_SRC_GPLL0_EVEN, 2.5, 0, 0),
46 F(128000000, CFG_CLK_SRC_GPLL0, 1, 16, 75),
47 { }
48};
49
Caleb Connollyc94f9e92023-11-07 12:41:03 +000050static ulong sdm845_clk_set_rate(struct clk *clk, ulong rate)
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030051{
52 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
Caleb Connolly6985e302023-11-07 12:41:02 +000053 const struct freq_tbl *freq;
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030054
55 switch (clk->id) {
Caleb Connolly6985e302023-11-07 12:41:02 +000056 case GCC_QUPV3_WRAP1_S1_CLK: /* UART9 */
57 freq = qcom_find_freq(ftbl_gcc_qupv3_wrap0_s0_clk_src, rate);
Caleb Connolly422b74b2023-11-21 17:55:53 +000058 clk_rcg_set_rate_mnd(priv->base, SE9_UART_APPS_CMD_RCGR,
Caleb Connolly97d7ed32023-11-07 12:41:04 +000059 freq->pre_div, freq->m, freq->n, freq->src, 16);
Caleb Connolly6985e302023-11-07 12:41:02 +000060 return freq->freq;
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030061 default:
62 return 0;
63 }
64}
Sumit Gargc9e384e2022-08-04 19:57:14 +053065
Caleb Connolly6985e302023-11-07 12:41:02 +000066static const struct gate_clk sdm845_clks[] = {
Caleb Connolly4d384602023-10-10 16:55:57 +010067 GATE_CLK(GCC_AGGRE_USB3_SEC_AXI_CLK, 0x82020, 0x00000001),
68 GATE_CLK(GCC_CFG_NOC_USB3_SEC_AXI_CLK, 0x05030, 0x00000001),
Caleb Connolly6985e302023-11-07 12:41:02 +000069 GATE_CLK(GCC_QUPV3_WRAP0_S0_CLK, 0x5200c, 0x00000400),
70 GATE_CLK(GCC_QUPV3_WRAP0_S1_CLK, 0x5200c, 0x00000800),
71 GATE_CLK(GCC_QUPV3_WRAP0_S2_CLK, 0x5200c, 0x00001000),
72 GATE_CLK(GCC_QUPV3_WRAP0_S3_CLK, 0x5200c, 0x00002000),
73 GATE_CLK(GCC_QUPV3_WRAP0_S4_CLK, 0x5200c, 0x00004000),
74 GATE_CLK(GCC_QUPV3_WRAP0_S5_CLK, 0x5200c, 0x00008000),
75 GATE_CLK(GCC_QUPV3_WRAP0_S6_CLK, 0x5200c, 0x00010000),
76 GATE_CLK(GCC_QUPV3_WRAP0_S7_CLK, 0x5200c, 0x00020000),
77 GATE_CLK(GCC_QUPV3_WRAP1_S0_CLK, 0x5200c, 0x00400000),
78 GATE_CLK(GCC_QUPV3_WRAP1_S1_CLK, 0x5200c, 0x00800000),
79 GATE_CLK(GCC_QUPV3_WRAP1_S3_CLK, 0x5200c, 0x02000000),
80 GATE_CLK(GCC_QUPV3_WRAP1_S4_CLK, 0x5200c, 0x04000000),
81 GATE_CLK(GCC_QUPV3_WRAP1_S5_CLK, 0x5200c, 0x08000000),
82 GATE_CLK(GCC_QUPV3_WRAP1_S6_CLK, 0x5200c, 0x10000000),
83 GATE_CLK(GCC_QUPV3_WRAP1_S7_CLK, 0x5200c, 0x20000000),
84 GATE_CLK(GCC_QUPV3_WRAP_0_M_AHB_CLK, 0x5200c, 0x00000040),
85 GATE_CLK(GCC_QUPV3_WRAP_0_S_AHB_CLK, 0x5200c, 0x00000080),
86 GATE_CLK(GCC_QUPV3_WRAP_1_M_AHB_CLK, 0x5200c, 0x00100000),
87 GATE_CLK(GCC_QUPV3_WRAP_1_S_AHB_CLK, 0x5200c, 0x00200000),
88 GATE_CLK(GCC_SDCC2_AHB_CLK, 0x14008, 0x00000001),
89 GATE_CLK(GCC_SDCC2_APPS_CLK, 0x14004, 0x00000001),
90 GATE_CLK(GCC_SDCC4_AHB_CLK, 0x16008, 0x00000001),
91 GATE_CLK(GCC_SDCC4_APPS_CLK, 0x16004, 0x00000001),
92 GATE_CLK(GCC_UFS_CARD_AHB_CLK, 0x75010, 0x00000001),
93 GATE_CLK(GCC_UFS_CARD_AXI_CLK, 0x7500c, 0x00000001),
94 GATE_CLK(GCC_UFS_CARD_CLKREF_CLK, 0x8c004, 0x00000001),
95 GATE_CLK(GCC_UFS_CARD_ICE_CORE_CLK, 0x75058, 0x00000001),
96 GATE_CLK(GCC_UFS_CARD_PHY_AUX_CLK, 0x7508c, 0x00000001),
97 GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_0_CLK, 0x75018, 0x00000001),
98 GATE_CLK(GCC_UFS_CARD_RX_SYMBOL_1_CLK, 0x750a8, 0x00000001),
99 GATE_CLK(GCC_UFS_CARD_TX_SYMBOL_0_CLK, 0x75014, 0x00000001),
100 GATE_CLK(GCC_UFS_CARD_UNIPRO_CORE_CLK, 0x75054, 0x00000001),
101 GATE_CLK(GCC_UFS_MEM_CLKREF_CLK, 0x8c000, 0x00000001),
102 GATE_CLK(GCC_UFS_PHY_AHB_CLK, 0x77010, 0x00000001),
103 GATE_CLK(GCC_UFS_PHY_AXI_CLK, 0x7700c, 0x00000001),
104 GATE_CLK(GCC_UFS_PHY_ICE_CORE_CLK, 0x77058, 0x00000001),
105 GATE_CLK(GCC_UFS_PHY_PHY_AUX_CLK, 0x7708c, 0x00000001),
106 GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_0_CLK, 0x77018, 0x00000001),
107 GATE_CLK(GCC_UFS_PHY_RX_SYMBOL_1_CLK, 0x770a8, 0x00000001),
108 GATE_CLK(GCC_UFS_PHY_TX_SYMBOL_0_CLK, 0x77014, 0x00000001),
109 GATE_CLK(GCC_UFS_PHY_UNIPRO_CORE_CLK, 0x77054, 0x00000001),
110 GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0x0f00c, 0x00000001),
111 GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0x0f014, 0x00000001),
112 GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0x0f010, 0x00000001),
113 GATE_CLK(GCC_USB30_SEC_MASTER_CLK, 0x1000c, 0x00000001),
114 GATE_CLK(GCC_USB30_SEC_MOCK_UTMI_CLK, 0x10014, 0x00000001),
115 GATE_CLK(GCC_USB30_SEC_SLEEP_CLK, 0x10010, 0x00000001),
116 GATE_CLK(GCC_USB3_PRIM_CLKREF_CLK, 0x8c008, 0x00000001),
117 GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0x0f04c, 0x00000001),
118 GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0x0f050, 0x00000001),
119 GATE_CLK(GCC_USB3_PRIM_PHY_PIPE_CLK, 0x0f054, 0x00000001),
120 GATE_CLK(GCC_USB3_SEC_CLKREF_CLK, 0x8c028, 0x00000001),
121 GATE_CLK(GCC_USB3_SEC_PHY_AUX_CLK, 0x1004c, 0x00000001),
122 GATE_CLK(GCC_USB3_SEC_PHY_PIPE_CLK, 0x10054, 0x00000001),
123 GATE_CLK(GCC_USB3_SEC_PHY_COM_AUX_CLK, 0x10050, 0x00000001),
124 GATE_CLK(GCC_USB_PHY_CFG_AHB2PHY_CLK, 0x6a004, 0x00000001),
125};
126
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000127static int sdm845_clk_enable(struct clk *clk)
Sumit Gargc9e384e2022-08-04 19:57:14 +0530128{
Caleb Connolly6985e302023-11-07 12:41:02 +0000129 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
130
131 debug("%s: clk %s\n", __func__, sdm845_clks[clk->id].name);
132
Caleb Connolly4d384602023-10-10 16:55:57 +0100133 switch (clk->id) {
134 case GCC_USB30_PRIM_MASTER_CLK:
135 gdsc_enable(priv->base + USB30_PRIM_GDSCR);
136 qcom_gate_clk_en(priv, GCC_USB_PHY_CFG_AHB2PHY_CLK);
137 clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MASTER_CLK_CMD_RCGR, (4.5*2)-1, 0, 0, 1 << 8, 8);
138 clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR, 1, 0, 0, 0, 8);
139 clk_rcg_set_rate_mnd(priv->base, USB3_PRIM_PHY_AUX_CMD_RCGR, 1, 0, 0, 0, 8);
140 case GCC_USB30_SEC_MASTER_CLK:
141 gdsc_enable(priv->base + USB30_SEC_GDSCR);
142 qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_AUX_CLK);
143
144 qcom_gate_clk_en(priv, GCC_USB3_SEC_CLKREF_CLK);
145 qcom_gate_clk_en(priv, GCC_USB3_SEC_PHY_COM_AUX_CLK);
146 break;
147 }
148
Caleb Connolly6985e302023-11-07 12:41:02 +0000149 qcom_gate_clk_en(priv, clk->id);
150
Sumit Gargc9e384e2022-08-04 19:57:14 +0530151 return 0;
152}
Konrad Dybciod9935732023-11-07 12:41:01 +0000153
154static const struct qcom_reset_map sdm845_gcc_resets[] = {
155 [GCC_QUPV3_WRAPPER_0_BCR] = { 0x17000 },
156 [GCC_QUPV3_WRAPPER_1_BCR] = { 0x18000 },
157 [GCC_QUSB2PHY_PRIM_BCR] = { 0x12000 },
158 [GCC_QUSB2PHY_SEC_BCR] = { 0x12004 },
159 [GCC_SDCC2_BCR] = { 0x14000 },
160 [GCC_SDCC4_BCR] = { 0x16000 },
161 [GCC_UFS_CARD_BCR] = { 0x75000 },
162 [GCC_UFS_PHY_BCR] = { 0x77000 },
163 [GCC_USB30_PRIM_BCR] = { 0xf000 },
164 [GCC_USB30_SEC_BCR] = { 0x10000 },
165 [GCC_USB3_PHY_PRIM_BCR] = { 0x50000 },
166 [GCC_USB3PHY_PHY_PRIM_BCR] = { 0x50004 },
167 [GCC_USB3_DP_PHY_PRIM_BCR] = { 0x50008 },
168 [GCC_USB3_PHY_SEC_BCR] = { 0x5000c },
169 [GCC_USB3PHY_PHY_SEC_BCR] = { 0x50010 },
170 [GCC_USB3_DP_PHY_SEC_BCR] = { 0x50014 },
171 [GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 },
172};
173
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000174static struct msm_clk_data sdm845_clk_data = {
Konrad Dybciod9935732023-11-07 12:41:01 +0000175 .resets = sdm845_gcc_resets,
176 .num_resets = ARRAY_SIZE(sdm845_gcc_resets),
Caleb Connolly6985e302023-11-07 12:41:02 +0000177 .clks = sdm845_clks,
178 .num_clks = ARRAY_SIZE(sdm845_clks),
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000179
180 .enable = sdm845_clk_enable,
181 .set_rate = sdm845_clk_set_rate,
Konrad Dybciod9935732023-11-07 12:41:01 +0000182};
183
184static const struct udevice_id gcc_sdm845_of_match[] = {
185 {
186 .compatible = "qcom,gcc-sdm845",
Caleb Connollyc94f9e92023-11-07 12:41:03 +0000187 .data = (ulong)&sdm845_clk_data,
Konrad Dybciod9935732023-11-07 12:41:01 +0000188 },
189 { }
190};
191
192U_BOOT_DRIVER(gcc_sdm845) = {
193 .name = "gcc_sdm845",
194 .id = UCLASS_NOP,
195 .of_match = gcc_sdm845_of_match,
196 .bind = qcom_cc_bind,
197 .flags = DM_FLAG_PRE_RELOC,
198};