Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 2 | /* |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 3 | * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 4 | */ |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 5 | #ifndef _CLOCK_QCOM_H |
| 6 | #define _CLOCK_QCOM_H |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 7 | |
Caleb Connolly | 6985e30 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 10 | #define CFG_CLK_SRC_CXO (0 << 8) |
| 11 | #define CFG_CLK_SRC_GPLL0 (1 << 8) |
Caleb Connolly | 5146510 | 2023-10-03 11:48:04 +0100 | [diff] [blame] | 12 | #define CFG_CLK_SRC_GPLL0_AUX2 (2 << 8) |
Caleb Connolly | 652a16b | 2023-10-03 11:52:55 +0100 | [diff] [blame^] | 13 | #define CFG_CLK_SRC_GPLL9 (2 << 8) |
Caleb Connolly | 5146510 | 2023-10-03 11:48:04 +0100 | [diff] [blame] | 14 | #define CFG_CLK_SRC_GPLL6 (4 << 8) |
| 15 | #define CFG_CLK_SRC_GPLL7 (3 << 8) |
Dzmitry Sankouski | 90496af | 2021-10-17 13:44:30 +0300 | [diff] [blame] | 16 | #define CFG_CLK_SRC_GPLL0_EVEN (6 << 8) |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 17 | #define CFG_CLK_SRC_MASK (7 << 8) |
| 18 | |
Caleb Connolly | 4b31c6f | 2023-11-21 18:09:15 +0000 | [diff] [blame] | 19 | #define GDSC_PWR_ON BIT(31) |
| 20 | #define GDSC_SW_COLLAPSE BIT(0) |
| 21 | |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 22 | #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 Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 27 | struct pll_vote_clk { |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 28 | uintptr_t status; |
| 29 | int status_bit; |
| 30 | uintptr_t ena_vote; |
| 31 | int vote_bit; |
| 32 | }; |
| 33 | |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 34 | struct vote_clk { |
| 35 | uintptr_t cbcr_reg; |
| 36 | uintptr_t ena_vote; |
| 37 | int vote_bit; |
| 38 | }; |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 39 | |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 40 | struct 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 Connolly | 6985e30 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 50 | struct 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 Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 62 | struct qcom_reset_map { |
| 63 | unsigned int reg; |
| 64 | u8 bit; |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Caleb Connolly | c94f9e9 | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 67 | struct clk; |
| 68 | |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 69 | struct msm_clk_data { |
| 70 | const struct qcom_reset_map *resets; |
| 71 | unsigned long num_resets; |
Caleb Connolly | 6985e30 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 72 | const struct gate_clk *clks; |
| 73 | unsigned long num_clks; |
Caleb Connolly | c94f9e9 | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 74 | |
| 75 | int (*enable)(struct clk *clk); |
| 76 | unsigned long (*set_rate)(struct clk *clk, unsigned long rate); |
Konrad Dybcio | d993573 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct msm_clk_priv { |
| 80 | phys_addr_t base; |
| 81 | struct msm_clk_data *data; |
| 82 | }; |
| 83 | |
| 84 | int qcom_cc_bind(struct udevice *parent); |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 85 | void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 86 | void clk_bcr_update(phys_addr_t apps_cmd_rgcr); |
| 87 | void clk_enable_cbc(phys_addr_t cbcr); |
Ramon Fried | 640dc34 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 88 | void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk); |
Caleb Connolly | be20d62 | 2023-11-07 12:41:05 +0000 | [diff] [blame] | 89 | const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, uint rate); |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 90 | void clk_rcg_set_rate_mnd(phys_addr_t base, uint32_t cmd_rcgr, |
Caleb Connolly | 97d7ed3 | 2023-11-07 12:41:04 +0000 | [diff] [blame] | 91 | int div, int m, int n, int source, u8 mnd_width); |
Caleb Connolly | 422b74b | 2023-11-21 17:55:53 +0000 | [diff] [blame] | 92 | void clk_rcg_set_rate(phys_addr_t base, uint32_t cmd_rcgr, int div, |
Sumit Garg | 22d3fcd | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 93 | int source); |
Caleb Connolly | 5146510 | 2023-10-03 11:48:04 +0100 | [diff] [blame] | 94 | void gdsc_enable(phys_addr_t gdscr); |
Jorge Ramirez-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 95 | |
Caleb Connolly | 6985e30 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 96 | static 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-Ortiz | 7c75f7f | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 106 | #endif |