Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 2 | /* |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 3 | * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 4 | */ |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 5 | #ifndef _CLOCK_QCOM_H |
| 6 | #define _CLOCK_QCOM_H |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 7 | |
Caleb Connolly | 7a63294 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | |
Jorge Ramirez-Ortiz | 92c1eff | 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) |
Dzmitry Sankouski | 038f2b9 | 2021-10-17 13:44:30 +0300 | [diff] [blame] | 12 | #define CFG_CLK_SRC_GPLL0_EVEN (6 << 8) |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 13 | #define CFG_CLK_SRC_MASK (7 << 8) |
| 14 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 15 | struct pll_vote_clk { |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 16 | uintptr_t status; |
| 17 | int status_bit; |
| 18 | uintptr_t ena_vote; |
| 19 | int vote_bit; |
| 20 | }; |
| 21 | |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 22 | struct vote_clk { |
| 23 | uintptr_t cbcr_reg; |
| 24 | uintptr_t ena_vote; |
| 25 | int vote_bit; |
| 26 | }; |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 27 | struct bcr_regs { |
| 28 | uintptr_t cfg_rcgr; |
| 29 | uintptr_t cmd_rcgr; |
| 30 | uintptr_t M; |
| 31 | uintptr_t N; |
| 32 | uintptr_t D; |
| 33 | }; |
| 34 | |
Caleb Connolly | 7a63294 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 35 | struct gate_clk { |
| 36 | uintptr_t reg; |
| 37 | u32 en_val; |
| 38 | const char *name; |
| 39 | }; |
| 40 | |
| 41 | #ifdef DEBUG |
| 42 | #define GATE_CLK(clk, reg, val) [clk] = { reg, val, #clk } |
| 43 | #else |
| 44 | #define GATE_CLK(clk, reg, val) [clk] = { reg, val, NULL } |
| 45 | #endif |
| 46 | |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 47 | struct qcom_reset_map { |
| 48 | unsigned int reg; |
| 49 | u8 bit; |
| 50 | }; |
| 51 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 52 | struct clk; |
| 53 | |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 54 | struct msm_clk_data { |
| 55 | const struct qcom_reset_map *resets; |
| 56 | unsigned long num_resets; |
Caleb Connolly | 7a63294 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 57 | const struct gate_clk *clks; |
| 58 | unsigned long num_clks; |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 59 | |
| 60 | int (*enable)(struct clk *clk); |
| 61 | unsigned long (*set_rate)(struct clk *clk, unsigned long rate); |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 64 | struct msm_clk_priv { |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 65 | phys_addr_t base; |
| 66 | struct msm_clk_data *data; |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
Konrad Dybcio | 6c0b844 | 2023-11-07 12:41:01 +0000 | [diff] [blame] | 69 | int qcom_cc_bind(struct udevice *parent); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 70 | void clk_enable_gpll0(phys_addr_t base, const struct pll_vote_clk *gpll0); |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 71 | void clk_bcr_update(phys_addr_t apps_cmd_rgcr); |
| 72 | void clk_enable_cbc(phys_addr_t cbcr); |
Ramon Fried | ae29977 | 2018-05-16 12:13:39 +0300 | [diff] [blame] | 73 | void clk_enable_vote_clk(phys_addr_t base, const struct vote_clk *vclk); |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 74 | void clk_rcg_set_rate_mnd(phys_addr_t base, const struct bcr_regs *regs, |
Caleb Connolly | fbacc67 | 2023-11-07 12:41:04 +0000 | [diff] [blame^] | 75 | int div, int m, int n, int source, u8 mnd_width); |
Sumit Garg | a3e804d | 2023-02-01 19:28:57 +0530 | [diff] [blame] | 76 | void clk_rcg_set_rate(phys_addr_t base, const struct bcr_regs *regs, int div, |
| 77 | int source); |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 78 | |
Caleb Connolly | 7a63294 | 2023-11-07 12:41:02 +0000 | [diff] [blame] | 79 | static inline void qcom_gate_clk_en(const struct msm_clk_priv *priv, unsigned long id) |
| 80 | { |
| 81 | u32 val; |
| 82 | if (id >= priv->data->num_clks || priv->data->clks[id].reg == 0) |
| 83 | return; |
| 84 | |
| 85 | val = readl(priv->base + priv->data->clks[id].reg); |
| 86 | writel(val | priv->data->clks[id].en_val, priv->base + priv->data->clks[id].reg); |
| 87 | } |
| 88 | |
Jorge Ramirez-Ortiz | 92c1eff | 2018-01-10 11:33:49 +0100 | [diff] [blame] | 89 | #endif |