Varadarajan Narayanan | dea9e2c | 2025-01-10 10:38:14 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Clock drivers for Qualcomm sa8775p |
| 4 | * |
| 5 | * (C) Copyright 2024 Linaro Ltd. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <linux/bug.h> |
| 14 | #include <linux/bitops.h> |
| 15 | #include <dt-bindings/clock/qcom,sa8775p-gcc.h> |
| 16 | #include "clock-qcom.h" |
| 17 | |
| 18 | #define USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR 0xf038 |
| 19 | #define USB30_PRIM_MASTER_CLK_CMD_RCGR 0xf020 |
| 20 | |
| 21 | static ulong sa8775p_set_rate(struct clk *clk, ulong rate) |
| 22 | { |
| 23 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 24 | |
| 25 | if (clk->id < priv->data->num_clks) |
| 26 | debug("%s: %s, requested rate=%ld\n", __func__, |
| 27 | priv->data->clks[clk->id].name, rate); |
| 28 | |
| 29 | switch (clk->id) { |
| 30 | case GCC_USB30_PRIM_MOCK_UTMI_CLK: |
| 31 | WARN(rate != 19200000, "Unexpected rate for USB30_PRIM_MOCK_UTMI_CLK: %lu\n", rate); |
| 32 | clk_rcg_set_rate(priv->base, USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR, 0, CFG_CLK_SRC_CXO); |
| 33 | return rate; |
| 34 | case GCC_USB30_PRIM_MASTER_CLK: |
| 35 | WARN(rate != 200000000, "Unexpected rate for USB30_PRIM_MASTER_CLK: %lu\n", rate); |
| 36 | clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MASTER_CLK_CMD_RCGR, |
| 37 | 1, 0, 0, CFG_CLK_SRC_GPLL0_ODD, 8); |
| 38 | clk_rcg_set_rate(priv->base, 0xf064, 0, 0); |
| 39 | return rate; |
| 40 | default: |
| 41 | return 0; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | static const struct gate_clk sa8775p_clks[] = { |
| 46 | GATE_CLK(GCC_CFG_NOC_USB3_PRIM_AXI_CLK, 0x1b088, 1), |
| 47 | GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0x1b018, 1), |
| 48 | GATE_CLK(GCC_AGGRE_USB3_PRIM_AXI_CLK, 0x1b084, 1), |
| 49 | GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0x1b020, 1), |
| 50 | GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0x1b024, 1), |
| 51 | GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0x1b05c, 1), |
| 52 | GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0x1b060, 1), |
| 53 | }; |
| 54 | |
| 55 | static int sa8775p_enable(struct clk *clk) |
| 56 | { |
| 57 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 58 | |
| 59 | if (priv->data->num_clks < clk->id) { |
| 60 | debug("%s: unknown clk id %lu\n", __func__, clk->id); |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | debug("%s: clk %ld: %s\n", __func__, clk->id, sa8775p_clks[clk->id].name); |
| 65 | |
| 66 | switch (clk->id) { |
| 67 | case GCC_AGGRE_USB3_PRIM_AXI_CLK: |
| 68 | qcom_gate_clk_en(priv, GCC_USB30_PRIM_MASTER_CLK); |
| 69 | fallthrough; |
| 70 | case GCC_USB30_PRIM_MASTER_CLK: |
| 71 | qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_AUX_CLK); |
| 72 | qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_COM_AUX_CLK); |
| 73 | break; |
| 74 | } |
| 75 | |
Caleb Connolly | cb1b297 | 2025-03-14 15:31:19 +0000 | [diff] [blame] | 76 | return qcom_gate_clk_en(priv, clk->id); |
Varadarajan Narayanan | dea9e2c | 2025-01-10 10:38:14 +0530 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static const struct qcom_reset_map sa8775p_gcc_resets[] = { |
| 80 | [GCC_CAMERA_BCR] = { 0x32000 }, |
| 81 | [GCC_DISPLAY1_BCR] = { 0xC7000 }, |
| 82 | [GCC_DISPLAY_BCR] = { 0x33000 }, |
| 83 | [GCC_EMAC0_BCR] = { 0xB6000 }, |
| 84 | [GCC_EMAC1_BCR] = { 0xB4000 }, |
| 85 | [GCC_GPU_BCR] = { 0x7D000 }, |
| 86 | [GCC_MMSS_BCR] = { 0x17000 }, |
| 87 | [GCC_PCIE_0_BCR] = { 0xa9000 }, |
| 88 | [GCC_PCIE_0_LINK_DOWN_BCR] = { 0xBF000 }, |
| 89 | [GCC_PCIE_0_NOCSR_COM_PHY_BCR] = { 0xBF008 }, |
| 90 | [GCC_PCIE_0_PHY_BCR] = { 0xAD144 }, |
| 91 | [GCC_PCIE_0_PHY_NOCSR_COM_PHY_BCR] = { 0xBF00C }, |
| 92 | [GCC_PCIE_1_BCR] = { 0x77000 }, |
| 93 | [GCC_PCIE_1_LINK_DOWN_BCR] = { 0xAE084 }, |
| 94 | [GCC_PCIE_1_NOCSR_COM_PHY_BCR] = { 0xAE090 }, |
| 95 | [GCC_PCIE_1_PHY_BCR] = { 0xAE08C }, |
| 96 | [GCC_PCIE_1_PHY_NOCSR_COM_PHY_BCR] = { 0xAE094 }, |
| 97 | [GCC_PDM_BCR] = { 0x3F000 }, |
| 98 | [GCC_QUPV3_WRAPPER_0_BCR] = { 0x23000 }, |
| 99 | [GCC_QUPV3_WRAPPER_1_BCR] = { 0x24000 }, |
| 100 | [GCC_QUPV3_WRAPPER_2_BCR] = { 0x2A000 }, |
| 101 | [GCC_QUPV3_WRAPPER_3_BCR] = { 0xC4000 }, |
| 102 | [GCC_SDCC1_BCR] = { 0x20000 }, |
| 103 | [GCC_TSCSS_BCR] = { 0x21000 }, |
| 104 | [GCC_UFS_CARD_BCR] = { 0x81000 }, |
| 105 | [GCC_UFS_PHY_BCR] = { 0x83000 }, |
| 106 | }; |
| 107 | |
| 108 | static const struct qcom_power_map sa8775p_gdscs[] = { |
| 109 | [UFS_PHY_GDSC] = { 0x83004 }, |
| 110 | [USB30_PRIM_GDSC] = { 0x1B004 }, |
| 111 | }; |
| 112 | |
| 113 | static struct msm_clk_data sa8775_gcc_data = { |
| 114 | .resets = sa8775p_gcc_resets, |
| 115 | .num_resets = ARRAY_SIZE(sa8775p_gcc_resets), |
| 116 | .clks = sa8775p_clks, |
| 117 | .num_clks = ARRAY_SIZE(sa8775p_clks), |
| 118 | |
| 119 | .power_domains = sa8775p_gdscs, |
| 120 | .num_power_domains = ARRAY_SIZE(sa8775p_gdscs), |
| 121 | |
| 122 | .enable = sa8775p_enable, |
| 123 | .set_rate = sa8775p_set_rate, |
| 124 | }; |
| 125 | |
| 126 | static const struct udevice_id gcc_sa8775p_of_match[] = { |
| 127 | { |
| 128 | .compatible = "qcom,sa8775p-gcc", |
| 129 | .data = (ulong)&sa8775_gcc_data, |
| 130 | }, |
| 131 | { } |
| 132 | }; |
| 133 | |
| 134 | U_BOOT_DRIVER(gcc_sa8775p) = { |
| 135 | .name = "gcc_sa8775p", |
| 136 | .id = UCLASS_NOP, |
| 137 | .of_match = gcc_sa8775p_of_match, |
| 138 | .bind = qcom_cc_bind, |
| 139 | .flags = DM_FLAG_PRE_RELOC | DM_FLAG_DEFAULT_PD_CTRL_OFF, |
| 140 | }; |