blob: 9b8bc6c8f5d7f2bc738b3aa8cf109ffe6edebf56 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +01002/*
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +01003 * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +01004 */
Konrad Dybciod9935732023-11-07 12:41:01 +00005#ifndef _CLOCK_QCOM_H
6#define _CLOCK_QCOM_H
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +01007
Caleb Connolly6985e302023-11-07 12:41:02 +00008#include <asm/io.h>
9
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010010#define CFG_CLK_SRC_CXO (0 << 8)
11#define CFG_CLK_SRC_GPLL0 (1 << 8)
Caleb Connolly51465102023-10-03 11:48:04 +010012#define CFG_CLK_SRC_GPLL0_AUX2 (2 << 8)
Caleb Connolly652a16b2023-10-03 11:52:55 +010013#define CFG_CLK_SRC_GPLL9 (2 << 8)
Caleb Connolly51465102023-10-03 11:48:04 +010014#define CFG_CLK_SRC_GPLL6 (4 << 8)
15#define CFG_CLK_SRC_GPLL7 (3 << 8)
Dzmitry Sankouski90496af2021-10-17 13:44:30 +030016#define CFG_CLK_SRC_GPLL0_EVEN (6 << 8)
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010017#define CFG_CLK_SRC_MASK (7 << 8)
18
Caleb Connolly4b31c6f2023-11-21 18:09:15 +000019#define GDSC_PWR_ON BIT(31)
20#define GDSC_SW_COLLAPSE BIT(0)
21
Caleb Connolly422b74b2023-11-21 17:55:53 +000022#define RCG_CFG_REG 0x4
23#define RCG_M_REG 0x8
24#define RCG_N_REG 0xc
25#define RCG_D_REG 0x10
26
Ramon Fried640dc342018-05-16 12:13:39 +030027struct pll_vote_clk {
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010028 uintptr_t status;
29 int status_bit;
30 uintptr_t ena_vote;
31 int vote_bit;
32};
33
Ramon Fried640dc342018-05-16 12:13:39 +030034struct vote_clk {
35 uintptr_t cbcr_reg;
36 uintptr_t ena_vote;
37 int vote_bit;
38};
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010039
Caleb Connollybe20d622023-11-07 12:41:05 +000040struct freq_tbl {
41 uint freq;
42 uint src;
43 u8 pre_div;
44 u16 m;
45 u16 n;
46};
47
48#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
49
Caleb Connolly6985e302023-11-07 12:41:02 +000050struct gate_clk {
51 uintptr_t reg;
52 u32 en_val;
53 const char *name;
54};
55
56#ifdef DEBUG
57#define GATE_CLK(clk, reg, val) [clk] = { reg, val, #clk }
58#else
59#define GATE_CLK(clk, reg, val) [clk] = { reg, val, NULL }
60#endif
61
Konrad Dybciod9935732023-11-07 12:41:01 +000062struct qcom_reset_map {
63 unsigned int reg;
64 u8 bit;
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010065};
66
Caleb Connollyc94f9e92023-11-07 12:41:03 +000067struct clk;
68
Konrad Dybciod9935732023-11-07 12:41:01 +000069struct msm_clk_data {
70 const struct qcom_reset_map *resets;
71 unsigned long num_resets;
Caleb Connolly6985e302023-11-07 12:41:02 +000072 const struct gate_clk *clks;
73 unsigned long num_clks;
Caleb Connollyc94f9e92023-11-07 12:41:03 +000074
75 int (*enable)(struct clk *clk);
76 unsigned long (*set_rate)(struct clk *clk, unsigned long rate);
Konrad Dybciod9935732023-11-07 12:41:01 +000077};
78
79struct msm_clk_priv {
80 phys_addr_t base;
81 struct msm_clk_data *data;
82};
83
84int qcom_cc_bind(struct udevice *parent);
Ramon Fried640dc342018-05-16 12:13:39 +030085void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0);
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010086void clk_bcr_update(phys_addr_t apps_cmd_rgcr);
87void clk_enable_cbc(phys_addr_t cbcr);
Ramon Fried640dc342018-05-16 12:13:39 +030088void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk);
Caleb Connollybe20d622023-11-07 12:41:05 +000089const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate);
Caleb Connolly422b74b2023-11-21 17:55:53 +000090void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr,
Caleb Connolly97d7ed32023-11-07 12:41:04 +000091 int div, int m, int n, int source, u8 mnd_width);
Caleb Connolly422b74b2023-11-21 17:55:53 +000092void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div,
Sumit Garg22d3fcd2023-02-01 19:28:57 +053093 int source);
Caleb Connolly51465102023-10-03 11:48:04 +010094void gdsc_enable(phys_addr_t gdscr);
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +010095
Caleb Connolly6985e302023-11-07 12:41:02 +000096static inline void qcom_gate_clk_en(const struct msm_clk_priv *priv, unsigned long id)
97{
98 u32 val;
99 if (id >= priv->data->num_clks || priv->data->clks[id].reg == 0)
100 return;
101
102 val = readl(priv->base + priv->data->clks[id].reg);
103 writel(val | priv->data->clks[id].en_val, priv->base + priv->data->clks[id].reg);
104}
105
Jorge Ramirez-Ortiz7c75f7f2018-01-10 11:33:49 +0100106#endif