blob: 479f9771a46445e92aee194325193d403eb4f1a3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: BSD-3-Clause
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01002/*
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-Ortiz9f2d1b22018-01-10 11:33:50 +01008 */
9
10#include <common.h>
11#include <clk-uclass.h>
12#include <dm.h>
13#include <errno.h>
14#include <asm/io.h>
15#include <linux/bitops.h>
Caleb Connolly42f4aff2024-02-26 17:26:39 +000016#include <dt-bindings/clock/qcom,gcc-msm8996.h>
Caleb Connolly878b26a2023-11-07 12:40:59 +000017
18#include "clock-qcom.h"
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010019
Caleb Connolly10a0abb2023-11-07 12:41:03 +000020/* Clocks: (from CLK_CTL_BASE) */
21#define GPLL0_STATUS (0x0000)
22#define APCS_GPLL_ENA_VOTE (0x52000)
23#define APCS_CLOCK_BRANCH_ENA_VOTE (0x52004)
24
25#define SDCC2_BCR (0x14000) /* block reset */
26#define SDCC2_APPS_CBCR (0x14004) /* branch control */
27#define SDCC2_AHB_CBCR (0x14008)
28#define SDCC2_CMD_RCGR (0x14010)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000029
30#define BLSP2_AHB_CBCR (0x25004)
31#define BLSP2_UART2_APPS_CBCR (0x29004)
32#define BLSP2_UART2_APPS_CMD_RCGR (0x2900C)
Caleb Connolly10a0abb2023-11-07 12:41:03 +000033
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010034/* GPLL0 clock control registers */
35#define GPLL0_STATUS_ACTIVE BIT(30)
36#define APCS_GPLL_ENA_VOTE_GPLL0 BIT(0)
37
Ramon Friedae299772018-05-16 12:13:39 +030038static const struct pll_vote_clk gpll0_vote_clk = {
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010039 .status = GPLL0_STATUS,
40 .status_bit = GPLL0_STATUS_ACTIVE,
41 .ena_vote = APCS_GPLL_ENA_VOTE,
42 .vote_bit = APCS_GPLL_ENA_VOTE_GPLL0,
43};
44
Ramon Frieded09eef2019-01-12 11:47:24 +020045static struct vote_clk gcc_blsp2_ahb_clk = {
46 .cbcr_reg = BLSP2_AHB_CBCR,
47 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
48 .vote_bit = BIT(15),
49};
50
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010051static int clk_init_sdc(struct msm_clk_priv *priv, uint rate)
52{
Caleb Connolly397c84f2023-11-07 12:41:05 +000053 int div = 5;
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010054
55 clk_enable_cbc(priv->base + SDCC2_AHB_CBCR);
Caleb Connollycbdad442024-04-03 14:07:40 +020056 clk_rcg_set_rate_mnd(priv->base, SDCC2_CMD_RCGR, div, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +000057 CFG_CLK_SRC_GPLL0, 8);
Ramon Friedae299772018-05-16 12:13:39 +030058 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010059 clk_enable_cbc(priv->base + SDCC2_APPS_CBCR);
60
61 return rate;
62}
63
Ramon Frieded09eef2019-01-12 11:47:24 +020064static int clk_init_uart(struct msm_clk_priv *priv)
65{
66 /* Enable AHB clock */
67 clk_enable_vote_clk(priv->base, &gcc_blsp2_ahb_clk);
68
69 /* 7372800 uart block clock @ GPLL0 */
Caleb Connollycbdad442024-04-03 14:07:40 +020070 clk_rcg_set_rate_mnd(priv->base, BLSP2_UART2_APPS_CMD_RCGR, 1, 192, 15625,
Caleb Connollyfbacc672023-11-07 12:41:04 +000071 CFG_CLK_SRC_GPLL0, 16);
Ramon Frieded09eef2019-01-12 11:47:24 +020072
73 /* Vote for gpll0 clock */
74 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
75
76 /* Enable core clk */
77 clk_enable_cbc(priv->base + BLSP2_UART2_APPS_CBCR);
78
79 return 0;
80}
81
Caleb Connolly10a0abb2023-11-07 12:41:03 +000082static ulong apq8096_clk_set_rate(struct clk *clk, ulong rate)
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010083{
84 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
85
86 switch (clk->id) {
Caleb Connolly42f4aff2024-02-26 17:26:39 +000087 case GCC_SDCC1_APPS_CLK: /* SDC1 */
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010088 return clk_init_sdc(priv, rate);
89 break;
Caleb Connolly42f4aff2024-02-26 17:26:39 +000090 case GCC_BLSP2_UART2_APPS_CLK: /*UART2*/
Ramon Frieded09eef2019-01-12 11:47:24 +020091 return clk_init_uart(priv);
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010092 default:
93 return 0;
94 }
95}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +053096
Caleb Connolly10a0abb2023-11-07 12:41:03 +000097static struct msm_clk_data apq8096_clk_data = {
98 .set_rate = apq8096_clk_set_rate,
99};
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000100
101static const struct udevice_id gcc_apq8096_of_match[] = {
102 {
Caleb Connolly3e88e6e2024-02-26 17:26:09 +0000103 .compatible = "qcom,gcc-msm8996",
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000104 .data = (ulong)&apq8096_clk_data,
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000105 },
106 { }
107};
108
109U_BOOT_DRIVER(gcc_apq8096) = {
110 .name = "gcc_apq8096",
111 .id = UCLASS_NOP,
112 .of_match = gcc_apq8096_of_match,
113 .bind = qcom_cc_bind,
114 .flags = DM_FLAG_PRE_RELOC,
115};