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> |
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 | |
| 19 | /* GPLL0 clock control registers */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 20 | #define GPLL0_STATUS_ACTIVE BIT(17) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 21 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 22 | static const struct bcr_regs sdc_regs[] = { |
| 23 | { |
| 24 | .cfg_rcgr = SDCC_CFG_RCGR(1), |
| 25 | .cmd_rcgr = SDCC_CMD_RCGR(1), |
| 26 | .M = SDCC_M(1), |
| 27 | .N = SDCC_N(1), |
| 28 | .D = SDCC_D(1), |
| 29 | }, |
| 30 | { |
| 31 | .cfg_rcgr = SDCC_CFG_RCGR(2), |
| 32 | .cmd_rcgr = SDCC_CMD_RCGR(2), |
| 33 | .M = SDCC_M(2), |
| 34 | .N = SDCC_N(2), |
| 35 | .D = SDCC_D(2), |
| 36 | } |
| 37 | }; |
| 38 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 39 | static struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 40 | .status = GPLL0_STATUS, |
| 41 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 42 | .ena_vote = APCS_GPLL_ENA_VOTE, |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 43 | .vote_bit = BIT(0), |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 46 | static struct vote_clk gcc_blsp1_ahb_clk = { |
| 47 | .cbcr_reg = BLSP1_AHB_CBCR, |
| 48 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 49 | .vote_bit = BIT(10), |
| 50 | }; |
| 51 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 52 | /* SDHCI */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 53 | static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate) |
| 54 | { |
| 55 | int div = 8; /* 100MHz default */ |
| 56 | |
| 57 | if (rate == 200000000) |
| 58 | div = 4; |
| 59 | |
| 60 | clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot)); |
| 61 | /* 800Mhz/div, gpll0 */ |
| 62 | clk_rcg_set_rate_mnd(priv->base, &sdc_regs[slot], div, 0, 0, |
| 63 | CFG_CLK_SRC_GPLL0); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 64 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 65 | clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot)); |
| 66 | |
| 67 | return rate; |
| 68 | } |
| 69 | |
| 70 | static const struct bcr_regs uart2_regs = { |
| 71 | .cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR, |
| 72 | .cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR, |
| 73 | .M = BLSP1_UART2_APPS_M, |
| 74 | .N = BLSP1_UART2_APPS_N, |
| 75 | .D = BLSP1_UART2_APPS_D, |
| 76 | }; |
| 77 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 78 | /* UART: 115200 */ |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 79 | static int clk_init_uart(struct msm_clk_priv *priv) |
| 80 | { |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 81 | /* Enable AHB clock */ |
| 82 | clk_enable_vote_clk(priv->base, &gcc_blsp1_ahb_clk); |
| 83 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 84 | /* 7372800 uart block clock @ GPLL0 */ |
| 85 | clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 144, 15625, |
| 86 | CFG_CLK_SRC_GPLL0); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 87 | |
| 88 | /* Vote for gpll0 clock */ |
| 89 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
| 90 | |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 91 | /* Enable core clk */ |
| 92 | clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 97 | ulong msm_set_rate(struct clk *clk, ulong rate) |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 98 | { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 99 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 100 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 101 | switch (clk->id) { |
Mateusz Kulikowski | 2507d82 | 2016-03-31 23:12:32 +0200 | [diff] [blame] | 102 | case 0: /* SDC1 */ |
| 103 | return clk_init_sdc(priv, 0, rate); |
| 104 | break; |
| 105 | case 1: /* SDC2 */ |
| 106 | return clk_init_sdc(priv, 1, rate); |
| 107 | break; |
| 108 | case 4: /* UART2 */ |
| 109 | return clk_init_uart(priv); |
| 110 | break; |
| 111 | default: |
| 112 | return 0; |
| 113 | } |
| 114 | } |
Sumit Garg | 1d1ca6e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 115 | |
| 116 | int msm_enable(struct clk *clk) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 120 | |
| 121 | static const struct udevice_id gcc_apq8016_of_match[] = { |
| 122 | { |
| 123 | .compatible = "qcom,gcc-apq8016", |
| 124 | /* TODO: add reset map */ |
| 125 | }, |
| 126 | { } |
| 127 | }; |
| 128 | |
| 129 | U_BOOT_DRIVER(gcc_apq8016) = { |
| 130 | .name = "gcc_apq8016", |
| 131 | .id = UCLASS_NOP, |
| 132 | .of_match = gcc_apq8016_of_match, |
| 133 | .bind = qcom_cc_bind, |
| 134 | .flags = DM_FLAG_PRE_RELOC, |
| 135 | }; |