1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2015 Endless Mobile, Inc.
4 * Author: Carlo Caione <carlo@endlessm.com>
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_rate_table
{
55 #define PLL_RATE(_r, _m, _n, _od) \
63 #define CLK_MESON_PLL_ROUND_CLOSEST BIT(0)
65 struct meson_clk_pll_data
{
74 const struct reg_sequence
*init_regs
;
75 unsigned int init_count
;
76 const struct pll_rate_table
*table
;
80 #define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw)
82 struct meson_clk_mpll_data
{
92 #define CLK_MESON_MPLL_ROUND_CLOSEST BIT(0)
94 struct meson_clk_phase_data
{
98 int meson_clk_degrees_from_val(unsigned int val
, unsigned int width
);
99 unsigned int meson_clk_degrees_to_val(int degrees
, unsigned int width
);
101 #define MESON_GATE(_name, _reg, _bit) \
102 struct clk_regmap _name = { \
103 .data = &(struct clk_regmap_gate_data){ \
107 .hw.init = &(struct clk_init_data) { \
109 .ops = &clk_regmap_gate_ops, \
110 .parent_names = (const char *[]){ "clk81" }, \
112 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
117 extern const struct clk_ops meson_clk_pll_ro_ops
;
118 extern const struct clk_ops meson_clk_pll_ops
;
119 extern const struct clk_ops meson_clk_cpu_ops
;
120 extern const struct clk_ops meson_clk_mpll_ro_ops
;
121 extern const struct clk_ops meson_clk_mpll_ops
;
122 extern const struct clk_ops meson_clk_phase_ops
;
124 #endif /* __CLKC_H */