Sumit Garg | a4a9d9e | 2022-07-12 12:42:11 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
| 2 | /* |
| 3 | * Clock drivers for Qualcomm QCS404 |
| 4 | * |
| 5 | * (C) Copyright 2022 Sumit Garg <sumit.garg@linaro.org> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <linux/bitops.h> |
| 14 | #include "clock-snapdragon.h" |
| 15 | |
| 16 | #include <dt-bindings/clock/qcom,gcc-qcs404.h> |
| 17 | |
| 18 | /* GPLL0 clock control registers */ |
| 19 | #define GPLL0_STATUS_ACTIVE BIT(31) |
| 20 | |
Sumit Garg | 71ffa23 | 2023-02-01 19:28:50 +0530 | [diff] [blame^] | 21 | #define CFG_CLK_SRC_GPLL1 BIT(8) |
| 22 | #define GPLL1_STATUS_ACTIVE BIT(31) |
| 23 | |
Sumit Garg | a4a9d9e | 2022-07-12 12:42:11 +0530 | [diff] [blame] | 24 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 25 | .cbcr_reg = BLSP1_AHB_CBCR, |
| 26 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 27 | .vote_bit = BIT(10) | BIT(5) | BIT(4), |
| 28 | }; |
| 29 | |
| 30 | static const struct bcr_regs uart2_regs = { |
| 31 | .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR, |
| 32 | .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR, |
| 33 | .M = BLSP1_UART2_APPS_M, |
| 34 | .N = BLSP1_UART2_APPS_N, |
| 35 | .D = BLSP1_UART2_APPS_D, |
| 36 | }; |
| 37 | |
| 38 | static const struct bcr_regs sdc_regs = { |
| 39 | .cfg_rcgr = SDCC_CFG_RCGR(1), |
| 40 | .cmd_rcgr = SDCC_CMD_RCGR(1), |
| 41 | .M = SDCC_M(1), |
| 42 | .N = SDCC_N(1), |
| 43 | .D = SDCC_D(1), |
| 44 | }; |
| 45 | |
| 46 | static struct pll_vote_clk gpll0_vote_clk = { |
| 47 | .status = GPLL0_STATUS, |
| 48 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 49 | .ena_vote = APCS_GPLL_ENA_VOTE, |
| 50 | .vote_bit = BIT(0), |
| 51 | }; |
| 52 | |
Sumit Garg | 71ffa23 | 2023-02-01 19:28:50 +0530 | [diff] [blame^] | 53 | static struct pll_vote_clk gpll1_vote_clk = { |
| 54 | .status = GPLL1_STATUS, |
| 55 | .status_bit = GPLL1_STATUS_ACTIVE, |
| 56 | .ena_vote = APCS_GPLL_ENA_VOTE, |
| 57 | .vote_bit = BIT(1), |
| 58 | }; |
| 59 | |
Sumit Garg | 968597b | 2022-08-04 19:57:15 +0530 | [diff] [blame] | 60 | static const struct bcr_regs usb30_master_regs = { |
| 61 | .cfg_rcgr = USB30_MASTER_CFG_RCGR, |
| 62 | .cmd_rcgr = USB30_MASTER_CMD_RCGR, |
| 63 | .M = USB30_MASTER_M, |
| 64 | .N = USB30_MASTER_N, |
| 65 | .D = USB30_MASTER_D, |
| 66 | }; |
| 67 | |
Sumit Garg | 71ffa23 | 2023-02-01 19:28:50 +0530 | [diff] [blame^] | 68 | static const struct bcr_regs emac_regs = { |
| 69 | .cfg_rcgr = EMAC_CFG_RCGR, |
| 70 | .cmd_rcgr = EMAC_CMD_RCGR, |
| 71 | .M = EMAC_M, |
| 72 | .N = EMAC_N, |
| 73 | .D = EMAC_D, |
| 74 | }; |
| 75 | |
| 76 | static const struct bcr_regs emac_ptp_regs = { |
| 77 | .cfg_rcgr = EMAC_PTP_CFG_RCGR, |
| 78 | .cmd_rcgr = EMAC_PTP_CMD_RCGR, |
| 79 | .M = EMAC_M, |
| 80 | .N = EMAC_N, |
| 81 | .D = EMAC_D, |
| 82 | }; |
| 83 | |
Sumit Garg | a4a9d9e | 2022-07-12 12:42:11 +0530 | [diff] [blame] | 84 | ulong msm_set_rate(struct clk *clk, ulong rate) |
| 85 | { |
| 86 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 87 | |
| 88 | switch (clk->id) { |
| 89 | case GCC_BLSP1_UART2_APPS_CLK: |
| 90 | /* UART: 115200 */ |
| 91 | clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 0, 12, 125, |
| 92 | CFG_CLK_SRC_CXO); |
| 93 | clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR); |
| 94 | break; |
| 95 | case GCC_BLSP1_AHB_CLK: |
| 96 | clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk); |
| 97 | break; |
| 98 | case GCC_SDCC1_APPS_CLK: |
| 99 | /* SDCC1: 200MHz */ |
| 100 | clk_rcg_set_rate_mnd(priv->base, &sdc_regs, 4, 0, 0, |
| 101 | CFG_CLK_SRC_GPLL0); |
| 102 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
| 103 | clk_enable_cbc(priv->base + SDCC_APPS_CBCR(1)); |
| 104 | break; |
| 105 | case GCC_SDCC1_AHB_CLK: |
| 106 | clk_enable_cbc(priv->base + SDCC_AHB_CBCR(1)); |
| 107 | break; |
Sumit Garg | 71ffa23 | 2023-02-01 19:28:50 +0530 | [diff] [blame^] | 108 | case GCC_ETH_RGMII_CLK: |
| 109 | if (rate == 250000000) |
| 110 | clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 0, 0, |
| 111 | CFG_CLK_SRC_GPLL1); |
| 112 | else if (rate == 125000000) |
| 113 | clk_rcg_set_rate_mnd(priv->base, &emac_regs, 4, 0, 0, |
| 114 | CFG_CLK_SRC_GPLL1); |
| 115 | else if (rate == 50000000) |
| 116 | clk_rcg_set_rate_mnd(priv->base, &emac_regs, 10, 0, 0, |
| 117 | CFG_CLK_SRC_GPLL1); |
| 118 | else if (rate == 5000000) |
| 119 | clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 1, 50, |
| 120 | CFG_CLK_SRC_GPLL1); |
| 121 | break; |
Sumit Garg | a4a9d9e | 2022-07-12 12:42:11 +0530 | [diff] [blame] | 122 | default: |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 128 | |
| 129 | int msm_enable(struct clk *clk) |
| 130 | { |
Sumit Garg | 968597b | 2022-08-04 19:57:15 +0530 | [diff] [blame] | 131 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 132 | |
| 133 | switch (clk->id) { |
| 134 | case GCC_USB30_MASTER_CLK: |
| 135 | clk_enable_cbc(priv->base + USB30_MASTER_CBCR); |
| 136 | clk_rcg_set_rate_mnd(priv->base, &usb30_master_regs, 4, 0, 0, |
| 137 | CFG_CLK_SRC_GPLL0); |
| 138 | break; |
| 139 | case GCC_SYS_NOC_USB3_CLK: |
| 140 | clk_enable_cbc(priv->base + SYS_NOC_USB3_CBCR); |
| 141 | break; |
| 142 | case GCC_USB30_SLEEP_CLK: |
| 143 | clk_enable_cbc(priv->base + USB30_SLEEP_CBCR); |
| 144 | break; |
| 145 | case GCC_USB30_MOCK_UTMI_CLK: |
| 146 | clk_enable_cbc(priv->base + USB30_MOCK_UTMI_CBCR); |
| 147 | break; |
| 148 | case GCC_USB_HS_PHY_CFG_AHB_CLK: |
| 149 | clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR); |
| 150 | break; |
| 151 | case GCC_USB2A_PHY_SLEEP_CLK: |
| 152 | clk_enable_cbc(priv->base + USB_HS_PHY_CFG_AHB_CBCR); |
| 153 | break; |
Sumit Garg | 71ffa23 | 2023-02-01 19:28:50 +0530 | [diff] [blame^] | 154 | case GCC_ETH_PTP_CLK: |
| 155 | /* SPEED_1000: freq -> 250MHz */ |
| 156 | clk_enable_cbc(priv->base + ETH_PTP_CBCR); |
| 157 | clk_enable_gpll0(priv->base, &gpll1_vote_clk); |
| 158 | clk_rcg_set_rate_mnd(priv->base, &emac_ptp_regs, 2, 0, 0, |
| 159 | CFG_CLK_SRC_GPLL1); |
| 160 | break; |
| 161 | case GCC_ETH_RGMII_CLK: |
| 162 | /* SPEED_1000: freq -> 250MHz */ |
| 163 | clk_enable_cbc(priv->base + ETH_RGMII_CBCR); |
| 164 | clk_enable_gpll0(priv->base, &gpll1_vote_clk); |
| 165 | clk_rcg_set_rate_mnd(priv->base, &emac_regs, 2, 0, 0, |
| 166 | CFG_CLK_SRC_GPLL1); |
| 167 | break; |
| 168 | case GCC_ETH_SLAVE_AHB_CLK: |
| 169 | clk_enable_cbc(priv->base + ETH_SLAVE_AHB_CBCR); |
| 170 | break; |
| 171 | case GCC_ETH_AXI_CLK: |
| 172 | clk_enable_cbc(priv->base + ETH_AXI_CBCR); |
| 173 | break; |
Sumit Garg | 968597b | 2022-08-04 19:57:15 +0530 | [diff] [blame] | 174 | default: |
| 175 | return 0; |
| 176 | } |
| 177 | |
Sumit Garg | c9e384e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 178 | return 0; |
| 179 | } |