Caleb Connolly | d3114b3 | 2024-08-21 15:41:46 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Clock drivers for Qualcomm sc7280 |
| 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,gcc-sc7280.h> |
| 16 | |
| 17 | #include "clock-qcom.h" |
| 18 | |
| 19 | #define USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR 0xf038 |
| 20 | #define USB30_PRIM_MASTER_CLK_CMD_RCGR 0xf020 |
| 21 | |
| 22 | static ulong sc7280_set_rate(struct clk *clk, ulong rate) |
| 23 | { |
| 24 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 25 | |
| 26 | if (clk->id < priv->data->num_clks) |
| 27 | debug("%s: %s, requested rate=%ld\n", __func__, 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_MASTER_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 sc7280_clks[] = { |
| 46 | GATE_CLK(GCC_CFG_NOC_USB3_PRIM_AXI_CLK, 0xf07c, 1), |
| 47 | GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0xf010, 1), |
| 48 | GATE_CLK(GCC_AGGRE_USB3_PRIM_AXI_CLK, 0xf080, 1), |
| 49 | GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0xf018, 1), |
| 50 | GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0xf01c, 1), |
| 51 | GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0xf054, 1), |
| 52 | GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0xf058, 1), |
| 53 | }; |
| 54 | |
| 55 | static int sc7280_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, sc7280_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 | |
| 76 | qcom_gate_clk_en(priv, clk->id); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static const struct qcom_reset_map sc7280_gcc_resets[] = { |
| 82 | [GCC_PCIE_0_BCR] = { 0x6b000 }, |
| 83 | [GCC_PCIE_0_PHY_BCR] = { 0x6c01c }, |
| 84 | [GCC_PCIE_1_BCR] = { 0x8d000 }, |
| 85 | [GCC_PCIE_1_PHY_BCR] = { 0x8e01c }, |
| 86 | [GCC_QUSB2PHY_PRIM_BCR] = { 0x12000 }, |
| 87 | [GCC_QUSB2PHY_SEC_BCR] = { 0x12004 }, |
| 88 | [GCC_SDCC1_BCR] = { 0x75000 }, |
| 89 | [GCC_SDCC2_BCR] = { 0x14000 }, |
| 90 | [GCC_SDCC4_BCR] = { 0x16000 }, |
| 91 | [GCC_UFS_PHY_BCR] = { 0x77000 }, |
| 92 | [GCC_USB30_PRIM_BCR] = { 0xf000 }, |
| 93 | [GCC_USB30_SEC_BCR] = { 0x9e000 }, |
| 94 | [GCC_USB3_DP_PHY_PRIM_BCR] = { 0x50008 }, |
| 95 | [GCC_USB3_PHY_PRIM_BCR] = { 0x50000 }, |
| 96 | [GCC_USB3PHY_PHY_PRIM_BCR] = { 0x50004 }, |
| 97 | [GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 }, |
| 98 | }; |
| 99 | |
| 100 | static const struct qcom_power_map sc7280_gdscs[] = { |
| 101 | [GCC_UFS_PHY_GDSC] = { 0x77004 }, |
| 102 | [GCC_USB30_PRIM_GDSC] = { 0xf004 }, |
| 103 | }; |
| 104 | |
| 105 | static struct msm_clk_data qcs404_gcc_data = { |
| 106 | .resets = sc7280_gcc_resets, |
| 107 | .num_resets = ARRAY_SIZE(sc7280_gcc_resets), |
| 108 | .clks = sc7280_clks, |
| 109 | .num_clks = ARRAY_SIZE(sc7280_clks), |
| 110 | |
| 111 | .power_domains = sc7280_gdscs, |
| 112 | .num_power_domains = ARRAY_SIZE(sc7280_gdscs), |
| 113 | |
| 114 | .enable = sc7280_enable, |
| 115 | .set_rate = sc7280_set_rate, |
| 116 | }; |
| 117 | |
| 118 | static const struct udevice_id gcc_sc7280_of_match[] = { |
| 119 | { |
| 120 | .compatible = "qcom,gcc-sc7280", |
| 121 | .data = (ulong)&qcs404_gcc_data, |
| 122 | }, |
| 123 | { } |
| 124 | }; |
| 125 | |
| 126 | U_BOOT_DRIVER(gcc_sc7280) = { |
| 127 | .name = "gcc_sc7280", |
| 128 | .id = UCLASS_NOP, |
| 129 | .of_match = gcc_sc7280_of_match, |
| 130 | .bind = qcom_cc_bind, |
| 131 | .flags = DM_FLAG_PRE_RELOC | DM_FLAG_DEFAULT_PD_CTRL_OFF, |
| 132 | }; |