blob: f6445c8f566f1803f095ca0dd0bfdfdf848d95a0 [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 Connollye55fb902024-04-08 15:06:49 +020014#define CFG_CLK_SRC_GPLL6 (4 << 8)
15#define CFG_CLK_SRC_GPLL7 (3 << 8)
Caleb Connolly97268102024-04-09 20:03:04 +020016#define CFG_CLK_SRC_GPLL4 (5 << 8)
Dzmitry Sankouski038f2b92021-10-17 13:44:30 +030017#define CFG_CLK_SRC_GPLL0_EVEN (6 << 8)
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010018#define CFG_CLK_SRC_MASK (7 << 8)
19
Caleb Connollycbdad442024-04-03 14:07:40 +020020#define RCG_CFG_REG 0x4
21#define RCG_M_REG 0x8
22#define RCG_N_REG 0xc
23#define RCG_D_REG 0x10
24
Ramon Friedae299772018-05-16 12:13:39 +030025struct pll_vote_clk {
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010026 uintptr_t status;
27 int status_bit;
28 uintptr_t ena_vote;
29 int vote_bit;
30};
31
Ramon Friedae299772018-05-16 12:13:39 +030032struct vote_clk {
33 uintptr_t cbcr_reg;
34 uintptr_t ena_vote;
35 int vote_bit;
36};
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010037
Caleb Connolly397c84f2023-11-07 12:41:05 +000038struct freq_tbl {
39 uint freq;
40 uint src;
41 u8 pre_div;
42 u16 m;
43 u16 n;
44};
45
46#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
47
Caleb Connolly7a632942023-11-07 12:41:02 +000048struct gate_clk {
49 uintptr_t reg;
50 u32 en_val;
51 const char *name;
52};
53
54#ifdef DEBUG
55#define GATE_CLK(clk, reg, val) [clk] = { reg, val, #clk }
56#else
57#define GATE_CLK(clk, reg, val) [clk] = { reg, val, NULL }
58#endif
59
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000060struct qcom_reset_map {
61 unsigned int reg;
62 u8 bit;
63};
64
Volodymyr Babchukaae46492024-03-11 21:33:45 +000065struct qcom_power_map {
66 unsigned int reg;
67};
68
Caleb Connolly10a0abb2023-11-07 12:41:03 +000069struct clk;
70
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000071struct msm_clk_data {
Volodymyr Babchukaae46492024-03-11 21:33:45 +000072 const struct qcom_power_map *power_domains;
73 unsigned long num_power_domains;
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000074 const struct qcom_reset_map *resets;
75 unsigned long num_resets;
Caleb Connolly7a632942023-11-07 12:41:02 +000076 const struct gate_clk *clks;
77 unsigned long num_clks;
Caleb Connolly10a0abb2023-11-07 12:41:03 +000078
79 int (*enable)(struct clk *clk);
80 unsigned long (*set_rate)(struct clk *clk, unsigned long rate);
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000081};
82
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010083struct msm_clk_priv {
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000084 phys_addr_t base;
85 struct msm_clk_data *data;
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010086};
87
Konrad Dybcio6c0b8442023-11-07 12:41:01 +000088int qcom_cc_bind(struct udevice *parent);
Ramon Friedae299772018-05-16 12:13:39 +030089void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010090void clk_bcr_update(phys_addr_t apps_cmd_rgcr);
91void clk_enable_cbc(phys_addr_t cbcr);
Ramon Friedae299772018-05-16 12:13:39 +030092void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk);
Caleb Connolly397c84f2023-11-07 12:41:05 +000093const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate);
Caleb Connollycbdad442024-04-03 14:07:40 +020094void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr,
Caleb Connollyfbacc672023-11-07 12:41:04 +000095 int div, int m, int n, int source, u8 mnd_width);
Caleb Connollycbdad442024-04-03 14:07:40 +020096void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div,
Sumit Garga3e804d2023-02-01 19:28:57 +053097 int source);
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +010098
Caleb Connolly7a632942023-11-07 12:41:02 +000099static inline void qcom_gate_clk_en(const struct msm_clk_priv *priv, unsigned long id)
100{
101 u32 val;
102 if (id >= priv->data->num_clks || priv->data->clks[id].reg == 0)
103 return;
104
105 val = readl(priv->base + priv->data->clks[id].reg);
106 writel(val | priv->data->clks[id].en_val, priv->base + priv->data->clks[id].reg);
107}
108
Jorge Ramirez-Ortiz92c1eff2018-01-10 11:33:49 +0100109#endif