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 | |
| 10 | #include <common.h> |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 11 | #include <clk-uclass.h> |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <errno.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <linux/bitops.h> |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 16 | #include <dt-bindings/clock/qcom,gcc-msm8916.h> |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 17 | |
Caleb Connolly | 878b26a | 2023-11-07 12:40:59 +0000 | [diff] [blame] | 18 | #include "clock-qcom.h" |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 19 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 20 | /* Clocks: (from CLK_CTL_BASE) */ |
| 21 | #define GPLL0_STATUS (0x2101C) |
| 22 | #define APCS_GPLL_ENA_VOTE (0x45000) |
| 23 | #define APCS_CLOCK_BRANCH_ENA_VOTE (0x45004) |
| 24 | |
| 25 | #define SDCC_BCR(n) ((n * 0x1000) + 0x41000) |
| 26 | #define SDCC_CMD_RCGR(n) ((n * 0x1000) + 0x41004) |
| 27 | #define SDCC_CFG_RCGR(n) ((n * 0x1000) + 0x41008) |
| 28 | #define SDCC_M(n) ((n * 0x1000) + 0x4100C) |
| 29 | #define SDCC_N(n) ((n * 0x1000) + 0x41010) |
| 30 | #define SDCC_D(n) ((n * 0x1000) + 0x41014) |
| 31 | #define SDCC_APPS_CBCR(n) ((n * 0x1000) + 0x41018) |
| 32 | #define SDCC_AHB_CBCR(n) ((n * 0x1000) + 0x4101C) |
| 33 | |
| 34 | /* BLSP1 AHB clock (root clock for BLSP) */ |
| 35 | #define BLSP1_AHB_CBCR 0x1008 |
| 36 | |
| 37 | /* Uart clock control registers */ |
| 38 | #define BLSP1_UART2_BCR (0x3028) |
| 39 | #define BLSP1_UART2_APPS_CBCR (0x302C) |
| 40 | #define BLSP1_UART2_APPS_CMD_RCGR (0x3034) |
| 41 | #define BLSP1_UART2_APPS_CFG_RCGR (0x3038) |
| 42 | #define BLSP1_UART2_APPS_M (0x303C) |
| 43 | #define BLSP1_UART2_APPS_N (0x3040) |
| 44 | #define BLSP1_UART2_APPS_D (0x3044) |
| 45 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 46 | /* GPLL0 clock control registers */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 47 | #define GPLL0_STATUS_ACTIVE BIT(17) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 48 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 49 | static const struct bcr_regs sdc_regs[] = { |
| 50 | { |
| 51 | .cfg_rcgr = SDCC_CFG_RCGR(1), |
| 52 | .cmd_rcgr = SDCC_CMD_RCGR(1), |
| 53 | .M = SDCC_M(1), |
| 54 | .N = SDCC_N(1), |
| 55 | .D = SDCC_D(1), |
| 56 | }, |
| 57 | { |
| 58 | .cfg_rcgr = SDCC_CFG_RCGR(2), |
| 59 | .cmd_rcgr = SDCC_CMD_RCGR(2), |
| 60 | .M = SDCC_M(2), |
| 61 | .N = SDCC_N(2), |
| 62 | .D = SDCC_D(2), |
| 63 | } |
| 64 | }; |
| 65 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 66 | static struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 67 | .status = GPLL0_STATUS, |
| 68 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 69 | .ena_vote = APCS_GPLL_ENA_VOTE, |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 70 | .vote_bit = BIT(0), |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 73 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 74 | .cbcr_reg = BLSP1_AHB_CBCR, |
| 75 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 76 | .vote_bit = BIT(10), |
| 77 | }; |
| 78 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 79 | /* SDHCI */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 80 | static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate) |
| 81 | { |
Caleb Connolly | 397c84f | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 82 | int div = 15; /* 100MHz default */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 83 | |
| 84 | if (rate == 200000000) |
| 85 | div = 4; |
| 86 | |
| 87 | clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot)); |
| 88 | /* 800Mhz/div, gpll0 */ |
| 89 | clk_rcg_set_rate_mnd(priv->base, &sdc_regs[slot], div, 0, 0, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 90 | CFG_CLK_SRC_GPLL0, 8); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 91 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 92 | clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot)); |
| 93 | |
| 94 | return rate; |
| 95 | } |
| 96 | |
| 97 | static const struct bcr_regs uart2_regs = { |
| 98 | .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR, |
| 99 | .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR, |
| 100 | .M = BLSP1_UART2_APPS_M, |
| 101 | .N = BLSP1_UART2_APPS_N, |
| 102 | .D = BLSP1_UART2_APPS_D, |
| 103 | }; |
| 104 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 105 | /* UART: 115200 */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 106 | int apq8016_clk_init_uart(phys_addr_t base) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 107 | { |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 108 | /* Enable AHB clock */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 109 | clk_enable_vote_clk(base, &gcc_blsp1_ahb_clk); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 110 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 111 | /* 7372800 uart block clock @ GPLL0 */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 112 | clk_rcg_set_rate_mnd(base, &uart2_regs, 1, 144, 15625, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 113 | CFG_CLK_SRC_GPLL0, 16); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 114 | |
| 115 | /* Vote for gpll0 clock */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 116 | clk_enable_gpll0(base, &gpll0_vote_clk); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 117 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 118 | /* Enable core clk */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 119 | clk_enable_cbc(base + BLSP1_UART2_APPS_CBCR); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 124 | static ulong apq8016_clk_set_rate(struct clk *clk, ulong rate) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 125 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 126 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 127 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 128 | switch (clk->id) { |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 129 | case GCC_SDCC1_APPS_CLK: /* SDC1 */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 130 | return clk_init_sdc(priv, 0, rate); |
| 131 | break; |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 132 | case GCC_SDCC2_APPS_CLK: /* SDC2 */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 133 | return clk_init_sdc(priv, 1, rate); |
| 134 | break; |
Caleb Connolly | 154ed1d | 2024-02-26 17:26:21 +0000 | [diff] [blame] | 135 | case GCC_BLSP1_UART2_APPS_CLK: /* UART2 */ |
Caleb Connolly | 32ca787 | 2024-03-01 15:00:24 +0000 | [diff] [blame^] | 136 | return apq8016_clk_init_uart(priv->base); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 137 | break; |
| 138 | default: |
| 139 | return 0; |
| 140 | } |
| 141 | } |
Sumit Garg | 1d1ca6e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 142 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 143 | static struct msm_clk_data apq8016_clk_data = { |
| 144 | .set_rate = apq8016_clk_set_rate, |
| 145 | }; |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 146 | |
| 147 | static const struct udevice_id gcc_apq8016_of_match[] = { |
| 148 | { |
Caleb Connolly | 3e88e6e | 2024-02-26 17:26:09 +0000 | [diff] [blame] | 149 | .compatible = "qcom,gcc-msm8916", |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 150 | .data = (ulong)&apq8016_clk_data, |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 151 | }, |
| 152 | { } |
| 153 | }; |
| 154 | |
| 155 | U_BOOT_DRIVER(gcc_apq8016) = { |
| 156 | .name = "gcc_apq8016", |
| 157 | .id = UCLASS_NOP, |
| 158 | .of_match = gcc_apq8016_of_match, |
| 159 | .bind = qcom_cc_bind, |
| 160 | .flags = DM_FLAG_PRE_RELOC, |
| 161 | }; |