blob: cf1a347309a5048d024769ee9f84f2de408b9dda [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 Connolly878b26a2023-11-07 12:40:59 +000016
17#include "clock-qcom.h"
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010018
Caleb Connolly10a0abb2023-11-07 12:41:03 +000019/* 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)
28#define SDCC2_CFG_RCGR (0x14014)
29#define SDCC2_M (0x14018)
30#define SDCC2_N (0x1401C)
31#define SDCC2_D (0x14020)
32
33#define BLSP2_AHB_CBCR (0x25004)
34#define BLSP2_UART2_APPS_CBCR (0x29004)
35#define BLSP2_UART2_APPS_CMD_RCGR (0x2900C)
36#define BLSP2_UART2_APPS_CFG_RCGR (0x29010)
37#define BLSP2_UART2_APPS_M (0x29014)
38#define BLSP2_UART2_APPS_N (0x29018)
39#define BLSP2_UART2_APPS_D (0x2901C)
40
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010041/* GPLL0 clock control registers */
42#define GPLL0_STATUS_ACTIVE BIT(30)
43#define APCS_GPLL_ENA_VOTE_GPLL0 BIT(0)
44
45static const struct bcr_regs sdc_regs = {
46 .cfg_rcgr = SDCC2_CFG_RCGR,
47 .cmd_rcgr = SDCC2_CMD_RCGR,
48 .M = SDCC2_M,
49 .N = SDCC2_N,
50 .D = SDCC2_D,
51};
52
Ramon Friedae299772018-05-16 12:13:39 +030053static const struct pll_vote_clk gpll0_vote_clk = {
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010054 .status = GPLL0_STATUS,
55 .status_bit = GPLL0_STATUS_ACTIVE,
56 .ena_vote = APCS_GPLL_ENA_VOTE,
57 .vote_bit = APCS_GPLL_ENA_VOTE_GPLL0,
58};
59
Ramon Frieded09eef2019-01-12 11:47:24 +020060static struct vote_clk gcc_blsp2_ahb_clk = {
61 .cbcr_reg = BLSP2_AHB_CBCR,
62 .ena_vote = APCS_CLOCK_BRANCH_ENA_VOTE,
63 .vote_bit = BIT(15),
64};
65
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010066static int clk_init_sdc(struct msm_clk_priv *priv, uint rate)
67{
Caleb Connolly397c84f2023-11-07 12:41:05 +000068 int div = 5;
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010069
70 clk_enable_cbc(priv->base + SDCC2_AHB_CBCR);
71 clk_rcg_set_rate_mnd(priv->base, &sdc_regs, div, 0, 0,
Caleb Connollyfbacc672023-11-07 12:41:04 +000072 CFG_CLK_SRC_GPLL0, 8);
Ramon Friedae299772018-05-16 12:13:39 +030073 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010074 clk_enable_cbc(priv->base + SDCC2_APPS_CBCR);
75
76 return rate;
77}
78
Ramon Frieded09eef2019-01-12 11:47:24 +020079static const struct bcr_regs uart2_regs = {
80 .cfg_rcgr = BLSP2_UART2_APPS_CFG_RCGR,
81 .cmd_rcgr = BLSP2_UART2_APPS_CMD_RCGR,
82 .M = BLSP2_UART2_APPS_M,
83 .N = BLSP2_UART2_APPS_N,
84 .D = BLSP2_UART2_APPS_D,
85};
86
87static int clk_init_uart(struct msm_clk_priv *priv)
88{
89 /* Enable AHB clock */
90 clk_enable_vote_clk(priv->base, &gcc_blsp2_ahb_clk);
91
92 /* 7372800 uart block clock @ GPLL0 */
93 clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 192, 15625,
Caleb Connollyfbacc672023-11-07 12:41:04 +000094 CFG_CLK_SRC_GPLL0, 16);
Ramon Frieded09eef2019-01-12 11:47:24 +020095
96 /* Vote for gpll0 clock */
97 clk_enable_gpll0(priv->base, &gpll0_vote_clk);
98
99 /* Enable core clk */
100 clk_enable_cbc(priv->base + BLSP2_UART2_APPS_CBCR);
101
102 return 0;
103}
104
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000105static ulong apq8096_clk_set_rate(struct clk *clk, ulong rate)
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +0100106{
107 struct msm_clk_priv *priv = dev_get_priv(clk->dev);
108
109 switch (clk->id) {
110 case 0: /* SDC1 */
111 return clk_init_sdc(priv, rate);
112 break;
Ramon Frieded09eef2019-01-12 11:47:24 +0200113 case 4: /*UART2*/
114 return clk_init_uart(priv);
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +0100115 default:
116 return 0;
117 }
118}
Sumit Garg1d1ca6e2022-08-04 19:57:14 +0530119
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000120static struct msm_clk_data apq8096_clk_data = {
121 .set_rate = apq8096_clk_set_rate,
122};
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000123
124static const struct udevice_id gcc_apq8096_of_match[] = {
125 {
126 .compatible = "qcom,gcc-apq8096",
Caleb Connolly10a0abb2023-11-07 12:41:03 +0000127 .data = (ulong)&apq8096_clk_data,
Konrad Dybcio6c0b8442023-11-07 12:41:01 +0000128 },
129 { }
130};
131
132U_BOOT_DRIVER(gcc_apq8096) = {
133 .name = "gcc_apq8096",
134 .id = UCLASS_NOP,
135 .of_match = gcc_apq8096_of_match,
136 .bind = qcom_cc_bind,
137 .flags = DM_FLAG_PRE_RELOC,
138};