blob: 78d9b1d81ece1b3dd96b7bd0ab1a69fa016523b6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01002/*
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01003 * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01004 */
Konrad Dybcio6c0b8442023-11-07 12:41:01 +00005#ifndef _CLOCK_QCOM_H
6#define _CLOCK_QCOM_H
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +01007
Caleb Connolly7a632942023-11-07 12:41:02 +00008#include <asm/io.h>
9
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010010#define CFG_CLK_SRC_CXO (0 << 8)
11#define CFG_CLK_SRC_GPLL0 (1 << 8)
Caleb Connollye55fb902024-04-08 15:06:49 +020012#define CFG_CLK_SRC_GPLL0_AUX2 (2 << 8)
Caleb Connolly78672c62024-04-08 15:06:51 +020013#define CFG_CLK_SRC_GPLL9 (2 << 8)
Caleb Connollyd3114b32024-08-21 15:41:46 +020014#define CFG_CLK_SRC_GPLL0_ODD (3 << 8)
Caleb Connollye55fb902024-04-08 15:06:49 +020015#define CFG_CLK_SRC_GPLL6 (4 << 8)
16#define CFG_CLK_SRC_GPLL7 (3 << 8)
Caleb Connolly97268102024-04-09 20:03:04 +020017#define CFG_CLK_SRC_GPLL4 (5 << 8)
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +030018#define CFG_CLK_SRC_GPLL0_EVEN (6 << 8)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010019#define CFG_CLK_SRC_MASK (7 << 8)
20
Caleb Connollycbdad442024-04-03 14:07:40 +020021#define RCG_CFG_REG 0x4
22#define RCG_M_REG 0x8
23#define RCG_N_REG 0xc
24#define RCG_D_REG 0x10
25
Ramon Friedae299772018-05-16 12:13:39 +030026struct pll_vote_clk {
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010027 uintptr_t status;
28 int status_bit;
29 uintptr_t ena_vote;
30 int vote_bit;
31};
32
Ramon Friedae299772018-05-16 12:13:39 +030033struct vote_clk {
34 uintptr_t cbcr_reg;
35 uintptr_t ena_vote;
36 int vote_bit;
37};
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010038
Caleb Connolly397c84f2023-11-07 12:41:05 +000039struct freq_tbl {
40 uint freq;
41 uint src;
42 u8 pre_div;
43 u16 m;
44 u16 n;
45};
46
47#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
48
Caleb Connolly7a632942023-11-07 12:41:02 +000049struct gate_clk {
50 uintptr_t reg;
51 u32 en_val;
52 const char *name;
53};
54
55#ifdef DEBUG
56#define GATE_CLK(clk, reg, val) [clk] = { reg, val, #clk }
57#else
58#define GATE_CLK(clk, reg, val) [clk] = { reg, val, NULL }
59#endif
60
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000061struct qcom_reset_map {
62 unsigned int reg;
63 u8 bit;
64};
65
Volodymyr Babchukaae46492024-03-11 21:33:45 +000066struct qcom_power_map {
67 unsigned int reg;
68};
69
Caleb Connolly10a0abb2023-11-07 12:41:03 +000070struct clk;
71
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000072struct msm_clk_data {
Volodymyr Babchukaae46492024-03-11 21:33:45 +000073 const struct qcom_power_map *power_domains;
74 unsigned long num_power_domains;
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000075 const struct qcom_reset_map *resets;
76 unsigned long num_resets;
Caleb Connolly7a632942023-11-07 12:41:02 +000077 const struct gate_clk *clks;
78 unsigned long num_clks;
Caleb Connolly10a0abb2023-11-07 12:41:03 +000079
Caleb Connolly86d28392024-08-19 21:34:17 +020080 const phys_addr_t *dbg_pll_addrs;
81 unsigned long num_plls;
82 const phys_addr_t *dbg_rcg_addrs;
83 unsigned long num_rcgs;
84 const char * const *dbg_rcg_names;
85
Caleb Connolly10a0abb2023-11-07 12:41:03 +000086 int (*enable)(struct clk *clk);
87 unsigned long (*set_rate)(struct clk *clk, unsigned long rate);
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000088};
89
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010090struct msm_clk_priv {
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000091 phys_addr_t base;
92 struct msm_clk_data *data;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010093};
94
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000095int qcom_cc_bind(struct udevice *parent);
Ramon Friedae299772018-05-16 12:13:39 +030096void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010097void clk_bcr_update(phys_addr_t apps_cmd_rgcr);
98void clk_enable_cbc(phys_addr_t cbcr);
Ramon Friedae299772018-05-16 12:13:39 +030099void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk);
Caleb Connolly397c84f2023-11-07 12:41:05 +0000100const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate);
Caleb Connollycbdad442024-04-03 14:07:40 +0200101void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr,
Caleb Connollyfbacc672023-11-07 12:41:04 +0000102 int div, int m, int n, int source, u8 mnd_width);
Caleb Connollycbdad442024-04-03 14:07:40 +0200103void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div,
Sumit Garga3e804d2023-02-01 19:28:57 +0530104 int source);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100105
Caleb Connolly7a632942023-11-07 12:41:02 +0000106static inline void qcom_gate_clk_en(const struct msm_clk_priv *priv, unsigned long id)
107{
108 u32 val;
109 if (id >= priv->data->num_clks || priv->data->clks[id].reg == 0)
110 return;
111
112 val = readl(priv->base + priv->data->clks[id].reg);
113 writel(val | priv->data->clks[id].en_val, priv->base + priv->data->clks[id].reg);
114}
115
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100116#endif