blob: d3b63b9c1ac5b440b32bab0bc9f7b1c9720c1c30 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: BSD-3-Clause
Mateusz Kulikowski2507d822016-03-31 23:12:32 +02002/*
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 Kulikowski2507d822016-03-31 23:12:32 +02008 */
9
10#include <common.h>
Stephen Warrena9622432016-06-17 09:44:00 -060011#include <clk-uclass.h>
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020012#include <dm.h>
13#include <errno.h>
14#include <asm/io.h>
15#include <linux/bitops.h>
Caleb Connolly154ed1d2024-02-26 17:26:21 +000016#include <dt-bindings/clock/qcom,gcc-msm8916.h>
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000017
Caleb Connolly878b26a2023-11-07 12:40:59 +000018#include "clock-qcom.h"
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020019
Caleb Connolly10a0abb2023-11-07 12:41:03 +000020/* 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)
Caleb Connollycbdad442024-04-03 14:07:40 +020026#define SDCC_CMD_RCGR(n) (((n + 1) * 0x1000) + 0x41004)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000027#define SDCC_APPS_CBCR(n) ((n * 0x1000) + 0x41018)
28#define SDCC_AHB_CBCR(n) ((n * 0x1000) + 0x4101C)
29
30/* BLSP1 AHB clock (root clock for BLSP) */
31#define BLSP1_AHB_CBCR 0x1008
32
33/* Uart clock control registers */
Sumit Gargbf06b692024-04-12 15:24:33 +053034#define BLSP1_UART1_APPS_CBCR (0x203C)
35#define BLSP1_UART1_APPS_CMD_RCGR (0x2044)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000036#define BLSP1_UART2_APPS_CBCR (0x302C)
37#define BLSP1_UART2_APPS_CMD_RCGR (0x3034)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000038
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020039/* GPLL0 clock control registers */
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020040#define GPLL0_STATUS_ACTIVE BIT(17)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020041
Ramon Friedae299772018-05-16 12:13:39 +030042static struct pll_vote_clk gpll0_vote_clk = {
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010043 .status = GPLL0_STATUS,
44 .status_bit = GPLL0_STATUS_ACTIVE,
45 .ena_vote = APCS_GPLL_ENA_VOTE,
Ramon Friedae299772018-05-16 12:13:39 +030046 .vote_bit = BIT(0),
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010047};
48
Ramon Friedae299772018-05-16 12:13:39 +030049static struct vote_clk gcc_blsp1_ahb_clk = {
50 .cbcr_reg = BLSP1_AHB_CBCR,
51 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
52 .vote_bit = BIT(10),
53};
54
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010055/* SDHCI */
Sumit Gargbf06b692024-04-12 15:24:33 +053056static int apq8016_clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020057{
Caleb Connolly397c84f2023-11-07 12:41:05 +000058 int div = 15; /* 100MHz default */
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020059
60 if (rate == 200000000)
61 div = 4;
62
63 clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot));
64 /* 800Mhz/div, gpll0 */
Caleb Connollycbdad442024-04-03 14:07:40 +020065 clk_rcg_set_rate_mnd(priv->base, SDCC_CMD_RCGR(slot), div, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +000066 CFG_CLK_SRC_GPLL0, 8);
Ramon Friedae299772018-05-16 12:13:39 +030067 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020068 clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot));
69
70 return rate;
71}
72
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010073/* UART: 115200 */
Sumit Gargbf06b692024-04-12 15:24:33 +053074int apq8016_clk_init_uart(phys_addr_t base, unsigned long id)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020075{
Sumit Gargbf06b692024-04-12 15:24:33 +053076 u32 cmd_rcgr, apps_cbcr;
77
78 switch (id) {
79 case GCC_BLSP1_UART1_APPS_CLK:
80 cmd_rcgr = BLSP1_UART1_APPS_CMD_RCGR;
81 apps_cbcr = BLSP1_UART1_APPS_CBCR;
82 break;
83 case GCC_BLSP1_UART2_APPS_CLK:
84 cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR;
85 apps_cbcr = BLSP1_UART2_APPS_CBCR;
86 break;
87 default:
88 return 0;
89 }
90
Ramon Friedae299772018-05-16 12:13:39 +030091 /* Enable AHB clock */
Caleb Connolly32ca7872024-03-01 15:00:24 +000092 clk_enable_vote_clk(base, &gcc_blsp1_ahb_clk);
Ramon Friedae299772018-05-16 12:13:39 +030093
Mateusz Kulikowski2507d822016-03-31 23:12:32 +020094 /* 7372800 uart block clock @ GPLL0 */
Sumit Gargbf06b692024-04-12 15:24:33 +053095 clk_rcg_set_rate_mnd(base, cmd_rcgr, 1, 144, 15625, CFG_CLK_SRC_GPLL0,
96 16);
Ramon Friedae299772018-05-16 12:13:39 +030097
98 /* Vote for gpll0 clock */
Caleb Connolly32ca7872024-03-01 15:00:24 +000099 clk_enable_gpll0(base, &gpll0_vote_clk);
Ramon Friedae299772018-05-16 12:13:39 +0300100
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200101 /* Enable core clk */
Sumit Gargbf06b692024-04-12 15:24:33 +0530102 clk_enable_cbc(base + apps_cbcr);
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200103
104 return 0;
105}
106
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000107static ulong apq8016_clk_set_rate(struct clk *clk, ulong rate)
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200108{
Stephen Warrena9622432016-06-17 09:44:00 -0600109 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200110
Stephen Warrena9622432016-06-17 09:44:00 -0600111 switch (clk->id) {
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000112 case GCC_SDCC1_APPS_CLK: /* SDC1 */
Sumit Gargbf06b692024-04-12 15:24:33 +0530113 return apq8016_clk_init_sdc(priv, 0, rate);
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000114 case GCC_SDCC2_APPS_CLK: /* SDC2 */
Sumit Gargbf06b692024-04-12 15:24:33 +0530115 return apq8016_clk_init_sdc(priv, 1, rate);
116 case GCC_BLSP1_UART1_APPS_CLK: /* UART1 */
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000117 case GCC_BLSP1_UART2_APPS_CLK: /* UART2 */
Sumit Gargbf06b692024-04-12 15:24:33 +0530118 apq8016_clk_init_uart(priv->base, clk->id);
Caleb Connollybc9348b2024-04-15 16:03:38 +0100119 return 7372800;
Mateusz Kulikowski2507d822016-03-31 23:12:32 +0200120 default:
121 return 0;
122 }
123}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530124
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000125static struct msm_clk_data apq8016_clk_data = {
126 .set_rate = apq8016_clk_set_rate,
127};
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000128
129static const struct udevice_id gcc_apq8016_of_match[] = {
130 {
Caleb Connolly3e88e6e2024-02-26 17:26:09 +0000131 .compatible = "qcom,gcc-msm8916",
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000132 .data = (ulong)&apq8016_clk_data,
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000133 },
134 { }
135};
136
137U_BOOT_DRIVER(gcc_apq8016) = {
138 .name = "gcc_apq8016",
139 .id = UCLASS_NOP,
140 .of_match = gcc_apq8016_of_match,
141 .bind = qcom_cc_bind,
142 .flags = DM_FLAG_PRE_RELOC,
143};