1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2015 Endless Mobile, Inc.
10 #include <linux/clk-provider.h>
11 #include "clk-regmap.h"
13 #define PMASK(width) GENMASK(width - 1, 0)
14 #define SETPMASK(width, shift) GENMASK(shift + width - 1, shift)
15 #define CLRPMASK(width, shift) (~SETPMASK(width, shift))
17 #define PARM_GET(width, shift, reg) \
18 (((reg) & SETPMASK(width, shift)) >> (shift))
19 #define PARM_SET(width, shift, reg, val) \
20 (((reg) & CLRPMASK(width, shift)) | ((val) << (shift)))
22 #define MESON_PARM_APPLICABLE(p) (!!((p)->width))
30 static inline unsigned int meson_parm_read(struct regmap *map, struct parm *p)
34 regmap_read(map, p->reg_off, &val);
35 return PARM_GET(p->width, p->shift, val);
38 static inline void meson_parm_write(struct regmap *map, struct parm *p,
41 regmap_update_bits(map, p->reg_off, SETPMASK(p->width, p->shift),
46 struct pll_params_table {
51 #define PLL_PARAMS(_m, _n) \
57 #define CLK_MESON_PLL_ROUND_CLOSEST BIT(0)
59 struct meson_clk_pll_data {
66 const struct reg_sequence *init_regs;
67 unsigned int init_count;
68 const struct pll_params_table *table;
72 #define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw)
74 struct meson_clk_mpll_data {
84 #define CLK_MESON_MPLL_ROUND_CLOSEST BIT(0)
86 struct meson_clk_phase_data {
90 int meson_clk_degrees_from_val(unsigned int val, unsigned int width);
91 unsigned int meson_clk_degrees_to_val(int degrees, unsigned int width);
93 #define MESON_GATE(_name, _reg, _bit) \
94 struct clk_regmap _name = { \
95 .data = &(struct clk_regmap_gate_data){ \
99 .hw.init = &(struct clk_init_data) { \
101 .ops = &clk_regmap_gate_ops, \
102 .parent_names = (const char *[]){ "clk81" }, \
104 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
109 extern const struct clk_ops meson_clk_pll_ro_ops;
110 extern const struct clk_ops meson_clk_pll_ops;
111 extern const struct clk_ops meson_clk_cpu_ops;
112 extern const struct clk_ops meson_clk_mpll_ro_ops;
113 extern const struct clk_ops meson_clk_mpll_ops;
114 extern const struct clk_ops meson_clk_phase_ops;
116 #endif /* __CLKC_H */