Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Clock drivers for Qualcomm APQ8016 |
| 4 | * |
| 5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
| 6 | * |
| 7 | * Based on Little Kernel driver, simplified |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 10 | #include <clk-uclass.h> |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <errno.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <linux/bitops.h> |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 15 | #include <dt-bindings/clock/qcom,gcc-msm8916.h> |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 16 | |
Caleb Connolly | 878b26a | 2023-11-07 12:40:59 +0000 | [diff] [blame] | 17 | #include "clock-qcom.h" |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 18 | |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 19 | #define USB_HS_SYSTEM_CLK_CMD_RCGR 0x41010 |
| 20 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 21 | /* Clocks: (from CLK_CTL_BASE) */ |
| 22 | #define GPLL0_STATUS (0x2101C) |
| 23 | #define APCS_GPLL_ENA_VOTE (0x45000) |
| 24 | #define APCS_CLOCK_BRANCH_ENA_VOTE (0x45004) |
| 25 | |
| 26 | #define SDCC_BCR(n) ((n * 0x1000) + 0x41000) |
Caleb Connolly | cbdad44 | 2024-04-03 14:07:40 +0200 | [diff] [blame] | 27 | #define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004) |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 28 | #define SDCC_APPS_CBCR(n) ((n * 0x1000) + 0x41018) |
| 29 | #define SDCC_AHB_CBCR(n) ((n * 0x1000) + 0x4101C) |
| 30 | |
| 31 | /* BLSP1 AHB clock (root clock for BLSP) */ |
| 32 | #define BLSP1_AHB_CBCR 0x1008 |
| 33 | |
| 34 | /* Uart clock control registers */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 35 | #define BLSP1_UART1_APPS_CBCR (0x203C) |
| 36 | #define BLSP1_UART1_APPS_CMD_RCGR (0x2044) |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 37 | #define BLSP1_UART2_APPS_CBCR (0x302C) |
| 38 | #define BLSP1_UART2_APPS_CMD_RCGR (0x3034) |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 39 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 40 | /* GPLL0 clock control registers */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 41 | #define GPLL0_STATUS_ACTIVE BIT(17) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 42 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 43 | static struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 44 | .status = GPLL0_STATUS, |
| 45 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 46 | .ena_vote = APCS_GPLL_ENA_VOTE, |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 47 | .vote_bit = BIT(0), |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 50 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 51 | .cbcr_reg = BLSP1_AHB_CBCR, |
| 52 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 53 | .vote_bit = BIT(10), |
| 54 | }; |
| 55 | |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 56 | static const struct gate_clk apq8016_clks[] = { |
| 57 | GATE_CLK(GCC_USB_HS_AHB_CLK, 0x41008, 0x00000001), |
| 58 | GATE_CLK(GCC_USB_HS_SYSTEM_CLK, 0x41004, 0x00000001), |
| 59 | }; |
| 60 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 61 | /* SDHCI */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 62 | static int apq8016_clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 63 | { |
Caleb Connolly | 397c84f | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 64 | int div = 15; /* 100MHz default */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 65 | |
| 66 | if (rate == 200000000) |
| 67 | div = 4; |
| 68 | |
| 69 | clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot)); |
| 70 | /* 800Mhz/div, gpll0 */ |
Caleb Connolly | cbdad44 | 2024-04-03 14:07:40 +0200 | [diff] [blame] | 71 | clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(slot), div, 0, 0, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 72 | CFG_CLK_SRC_GPLL0, 8); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 73 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 74 | clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot)); |
| 75 | |
| 76 | return rate; |
| 77 | } |
| 78 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 79 | /* UART: 115200 */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 80 | int apq8016_clk_init_uart(phys_addr_t base, unsigned long id) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 81 | { |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 82 | u32 cmd_rcgr, apps_cbcr; |
| 83 | |
| 84 | switch (id) { |
| 85 | case GCC_BLSP1_UART1_APPS_CLK: |
| 86 | cmd_rcgr = BLSP1_UART1_APPS_CMD_RCGR; |
| 87 | apps_cbcr = BLSP1_UART1_APPS_CBCR; |
| 88 | break; |
| 89 | case GCC_BLSP1_UART2_APPS_CLK: |
| 90 | cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR; |
| 91 | apps_cbcr = BLSP1_UART2_APPS_CBCR; |
| 92 | break; |
| 93 | default: |
| 94 | return 0; |
| 95 | } |
| 96 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 97 | /* Enable AHB clock */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame] | 98 | clk_enable_vote_clk(base, &gcc_blsp1_ahb_clk); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 99 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 100 | /* 7372800 uart block clock @ GPLL0 */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 101 | clk_rcg_set_rate_mnd(base, cmd_rcgr, 1, 144, 15625, CFG_CLK_SRC_GPLL0, |
| 102 | 16); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 103 | |
| 104 | /* Vote for gpll0 clock */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame] | 105 | clk_enable_gpll0(base, &gpll0_vote_clk); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 106 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 107 | /* Enable core clk */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 108 | clk_enable_cbc(base + apps_cbcr); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 113 | static ulong apq8016_clk_set_rate(struct clk *clk, ulong rate) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 114 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 115 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 116 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 117 | switch (clk->id) { |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 118 | case GCC_SDCC1_APPS_CLK: /* SDC1 */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 119 | return apq8016_clk_init_sdc(priv, 0, rate); |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 120 | case GCC_SDCC2_APPS_CLK: /* SDC2 */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 121 | return apq8016_clk_init_sdc(priv, 1, rate); |
| 122 | case GCC_BLSP1_UART1_APPS_CLK: /* UART1 */ |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 123 | case GCC_BLSP1_UART2_APPS_CLK: /* UART2 */ |
Sumit Garg | bf06b69 | 2024-04-12 15:24:33 +0530 | [diff] [blame] | 124 | apq8016_clk_init_uart(priv->base, clk->id); |
Caleb Connolly | bc9348b | 2024-04-15 16:03:38 +0100 | [diff] [blame] | 125 | return 7372800; |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 126 | case GCC_USB_HS_SYSTEM_CLK: |
| 127 | if (rate != 80000000) |
| 128 | log_warning("Unexpected rate %ld requested for USB_HS_SYSTEM_CLK\n", |
Tom Rini | b85896e | 2024-07-05 10:22:53 -0600 | [diff] [blame] | 129 | rate); |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 130 | clk_rcg_set_rate_mnd(priv->base, USB_HS_SYSTEM_CLK_CMD_RCGR, |
Tom Rini | b85896e | 2024-07-05 10:22:53 -0600 | [diff] [blame] | 131 | 10, 0, 0, CFG_CLK_SRC_GPLL0, 0); |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 132 | return rate; |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 133 | default: |
| 134 | return 0; |
| 135 | } |
| 136 | } |
Sumit Garg | 1d1ca6e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 137 | |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 138 | static int apq8016_clk_enable(struct clk *clk) |
| 139 | { |
| 140 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 141 | |
| 142 | if (priv->data->num_clks < clk->id) { |
| 143 | log_warning("%s: unknown clk id %lu\n", __func__, clk->id); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | debug("%s: clk %s\n", __func__, apq8016_clks[clk->id].name); |
| 148 | qcom_gate_clk_en(priv, clk->id); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 153 | static struct msm_clk_data apq8016_clk_data = { |
| 154 | .set_rate = apq8016_clk_set_rate, |
Sam Day | fbda2a1 | 2024-05-06 10:26:54 +0000 | [diff] [blame] | 155 | .clks = apq8016_clks, |
| 156 | .num_clks = ARRAY_SIZE(apq8016_clks), |
| 157 | .enable = apq8016_clk_enable, |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 158 | }; |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 159 | |
| 160 | static const struct udevice_id gcc_apq8016_of_match[] = { |
| 161 | { |
Caleb Connolly | 3e88e6e | 2024-02-26 17:26:09 +0000 | [diff] [blame] | 162 | .compatible = "qcom,gcc-msm8916", |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 163 | .data = (ulong)&apq8016_clk_data, |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 164 | }, |
| 165 | { } |
| 166 | }; |
| 167 | |
| 168 | U_BOOT_DRIVER(gcc_apq8016) = { |
| 169 | .name = "gcc_apq8016", |
| 170 | .id = UCLASS_NOP, |
| 171 | .of_match = gcc_apq8016_of_match, |
| 172 | .bind = qcom_cc_bind, |
| 173 | .flags = DM_FLAG_PRE_RELOC, |
| 174 | }; |