Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Clock drivers for Qualcomm APQ8096 |
| 4 | * |
| 5 | * (C) Copyright 2017 Jorge Ramirez Ortiz <jorge.ramirez-ortiz@linaro.org> |
| 6 | * |
| 7 | * Based on Little Kernel driver, simplified |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 10 | #include <clk-uclass.h> |
| 11 | #include <dm.h> |
| 12 | #include <errno.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <linux/bitops.h> |
Caleb Connolly | 42f4aff | 2024-02-26 17:26:39 +0000 | [diff] [blame] | 15 | #include <dt-bindings/clock/qcom,gcc-msm8996.h> |
Caleb Connolly | 878b26a | 2023-11-07 12:40:59 +0000 | [diff] [blame] | 16 | |
| 17 | #include "clock-qcom.h" |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 18 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 19 | /* Clocks: (from CLK_CTL_BASE) */ |
| 20 | #define GPLL0_STATUS (0x0000) |
| 21 | #define APCS_GPLL_ENA_VOTE (0x52000) |
| 22 | #define APCS_CLOCK_BRANCH_ENA_VOTE (0x52004) |
| 23 | |
| 24 | #define SDCC2_BCR (0x14000) /* block reset */ |
| 25 | #define SDCC2_APPS_CBCR (0x14004) /* branch control */ |
| 26 | #define SDCC2_AHB_CBCR (0x14008) |
| 27 | #define SDCC2_CMD_RCGR (0x14010) |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 28 | |
| 29 | #define BLSP2_AHB_CBCR (0x25004) |
| 30 | #define BLSP2_UART2_APPS_CBCR (0x29004) |
| 31 | #define BLSP2_UART2_APPS_CMD_RCGR (0x2900C) |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 32 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 33 | /* GPLL0 clock control registers */ |
| 34 | #define GPLL0_STATUS_ACTIVE BIT(30) |
| 35 | #define APCS_GPLL_ENA_VOTE_GPLL0 BIT(0) |
| 36 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 37 | static const struct pll_vote_clk gpll0_vote_clk = { |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 38 | .status = GPLL0_STATUS, |
| 39 | .status_bit = GPLL0_STATUS_ACTIVE, |
| 40 | .ena_vote = APCS_GPLL_ENA_VOTE, |
| 41 | .vote_bit = APCS_GPLL_ENA_VOTE_GPLL0, |
| 42 | }; |
| 43 | |
Ramon Fried | ed09eef | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 44 | static struct vote_clk gcc_blsp2_ahb_clk = { |
| 45 | .cbcr_reg = BLSP2_AHB_CBCR, |
| 46 | .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE, |
| 47 | .vote_bit = BIT(15), |
| 48 | }; |
| 49 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 50 | static int clk_init_sdc(struct msm_clk_priv *priv, uint rate) |
| 51 | { |
Caleb Connolly | 397c84f | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 52 | int div = 5; |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 53 | |
| 54 | clk_enable_cbc(priv->base + SDCC2_AHB_CBCR); |
Caleb Connolly | cbdad44 | 2024-04-03 14:07:40 +0200 | [diff] [blame] | 55 | clk_rcg_set_rate_mnd(priv->base, SDCC2_CMD_RCGR, div, 0, 0, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 56 | CFG_CLK_SRC_GPLL0, 8); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 57 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 58 | clk_enable_cbc(priv->base + SDCC2_APPS_CBCR); |
| 59 | |
| 60 | return rate; |
| 61 | } |
| 62 | |
Ramon Fried | ed09eef | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 63 | static int clk_init_uart(struct msm_clk_priv *priv) |
| 64 | { |
| 65 | /* Enable AHB clock */ |
| 66 | clk_enable_vote_clk(priv->base, &gcc_blsp2_ahb_clk); |
| 67 | |
| 68 | /* 7372800 uart block clock @ GPLL0 */ |
Caleb Connolly | cbdad44 | 2024-04-03 14:07:40 +0200 | [diff] [blame] | 69 | clk_rcg_set_rate_mnd(priv->base, BLSP2_UART2_APPS_CMD_RCGR, 1, 192, 15625, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 70 | CFG_CLK_SRC_GPLL0, 16); |
Ramon Fried | ed09eef | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 71 | |
| 72 | /* Vote for gpll0 clock */ |
| 73 | clk_enable_gpll0(priv->base, &gpll0_vote_clk); |
| 74 | |
| 75 | /* Enable core clk */ |
| 76 | clk_enable_cbc(priv->base + BLSP2_UART2_APPS_CBCR); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 81 | static ulong apq8096_clk_set_rate(struct clk *clk, ulong rate) |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 82 | { |
| 83 | struct msm_clk_priv *priv = dev_get_priv(clk->dev); |
| 84 | |
| 85 | switch (clk->id) { |
Caleb Connolly | 42f4aff | 2024-02-26 17:26:39 +0000 | [diff] [blame] | 86 | case GCC_SDCC1_APPS_CLK: /* SDC1 */ |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 87 | return clk_init_sdc(priv, rate); |
| 88 | break; |
Caleb Connolly | 42f4aff | 2024-02-26 17:26:39 +0000 | [diff] [blame] | 89 | case GCC_BLSP2_UART2_APPS_CLK: /*UART2*/ |
Ramon Fried | ed09eef | 2019-01-12 11:47:24 +0200 | [diff] [blame] | 90 | return clk_init_uart(priv); |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 91 | default: |
| 92 | return 0; |
| 93 | } |
| 94 | } |
Sumit Garg | 1d1ca6e | 2022-08-04 19:57:14 +0530 | [diff] [blame] | 95 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 96 | static struct msm_clk_data apq8096_clk_data = { |
| 97 | .set_rate = apq8096_clk_set_rate, |
| 98 | }; |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 99 | |
| 100 | static const struct udevice_id gcc_apq8096_of_match[] = { |
| 101 | { |
Caleb Connolly | 3e88e6e | 2024-02-26 17:26:09 +0000 | [diff] [blame] | 102 | .compatible = "qcom,gcc-msm8996", |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 103 | .data = (ulong)&apq8096_clk_data, |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 104 | }, |
| 105 | { } |
| 106 | }; |
| 107 | |
| 108 | U_BOOT_DRIVER(gcc_apq8096) = { |
| 109 | .name = "gcc_apq8096", |
| 110 | .id = UCLASS_NOP, |
| 111 | .of_match = gcc_apq8096_of_match, |
| 112 | .bind = qcom_cc_bind, |
| 113 | .flags = DM_FLAG_PRE_RELOC, |
| 114 | }; |