blob: a7f833a4b6dd06bfbb4750ebe8101896fd7f34d9 [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)
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +030012#define CFG_CLK_SRC_GPLL0_EVEN (6 << 8)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010013#define CFG_CLK_SRC_MASK (7 << 8)
14
Caleb Connollycbdad442024-04-03 14:07:40 +020015#define RCG_CFG_REG 0x4
16#define RCG_M_REG 0x8
17#define RCG_N_REG 0xc
18#define RCG_D_REG 0x10
19
Ramon Friedae299772018-05-16 12:13:39 +030020struct pll_vote_clk {
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010021 uintptr_t status;
22 int status_bit;
23 uintptr_t ena_vote;
24 int vote_bit;
25};
26
Ramon Friedae299772018-05-16 12:13:39 +030027struct vote_clk {
28 uintptr_t cbcr_reg;
29 uintptr_t ena_vote;
30 int vote_bit;
31};
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010032
Caleb Connolly397c84f2023-11-07 12:41:05 +000033struct freq_tbl {
34 uint freq;
35 uint src;
36 u8 pre_div;
37 u16 m;
38 u16 n;
39};
40
41#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
42
Caleb Connolly7a632942023-11-07 12:41:02 +000043struct gate_clk {
44 uintptr_t reg;
45 u32 en_val;
46 const char *name;
47};
48
49#ifdef DEBUG
50#define GATE_CLK(clk, reg, val) [clk] = { reg, val, #clk }
51#else
52#define GATE_CLK(clk, reg, val) [clk] = { reg, val, NULL }
53#endif
54
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000055struct qcom_reset_map {
56 unsigned int reg;
57 u8 bit;
58};
59
Volodymyr Babchukaae46492024-03-11 21:33:45 +000060struct qcom_power_map {
61 unsigned int reg;
62};
63
Caleb Connolly10a0abb2023-11-07 12:41:03 +000064struct clk;
65
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000066struct msm_clk_data {
Volodymyr Babchukaae46492024-03-11 21:33:45 +000067 const struct qcom_power_map *power_domains;
68 unsigned long num_power_domains;
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000069 const struct qcom_reset_map *resets;
70 unsigned long num_resets;
Caleb Connolly7a632942023-11-07 12:41:02 +000071 const struct gate_clk *clks;
72 unsigned long num_clks;
Caleb Connolly10a0abb2023-11-07 12:41:03 +000073
74 int (*enable)(struct clk *clk);
75 unsigned long (*set_rate)(struct clk *clk, unsigned long rate);
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000076};
77
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010078struct msm_clk_priv {
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000079 phys_addr_t base;
80 struct msm_clk_data *data;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010081};
82
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000083int qcom_cc_bind(struct udevice *parent);
Ramon Friedae299772018-05-16 12:13:39 +030084void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010085void clk_bcr_update(phys_addr_t apps_cmd_rgcr);
86void clk_enable_cbc(phys_addr_t cbcr);
Ramon Friedae299772018-05-16 12:13:39 +030087void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk);
Caleb Connolly397c84f2023-11-07 12:41:05 +000088const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate);
Caleb Connollycbdad442024-04-03 14:07:40 +020089void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr,
Caleb Connollyfbacc672023-11-07 12:41:04 +000090 int div, int m, int n, int source, u8 mnd_width);
Caleb Connollycbdad442024-04-03 14:07:40 +020091void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div,
Sumit Garga3e804d2023-02-01 19:28:57 +053092 int source);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010093
Caleb Connolly7a632942023-11-07 12:41:02 +000094static inline void qcom_gate_clk_en(const struct msm_clk_priv *priv, unsigned long id)
95{
96 u32 val;
97 if (id >= priv->data->num_clks || priv->data->clks[id].reg == 0)
98 return;
99
100 val = readl(priv->base + priv->data->clks[id].reg);
101 writel(val | priv->data->clks[id].en_val, priv->base + priv->data->clks[id].reg);
102}
103
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100104#endif