1
2
3
4
5
6
7#ifndef __CLK_REGMAP_H
8#define __CLK_REGMAP_H
9
10#include <linux/clk-provider.h>
11#include <linux/regmap.h>
12
13
14
15
16
17
18
19
20
21
22
23struct clk_regmap {
24 struct clk_hw hw;
25 struct regmap *map;
26 void *data;
27};
28
29static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
30{
31 return container_of(hw, struct clk_regmap, hw);
32}
33
34
35
36
37
38
39
40
41
42
43
44struct clk_regmap_gate_data {
45 unsigned int offset;
46 u8 bit_idx;
47 u8 flags;
48};
49
50static inline struct clk_regmap_gate_data *
51clk_get_regmap_gate_data(struct clk_regmap *clk)
52{
53 return (struct clk_regmap_gate_data *)clk->data;
54}
55
56extern const struct clk_ops clk_regmap_gate_ops;
57extern const struct clk_ops clk_regmap_gate_ro_ops;
58
59
60
61
62
63
64
65
66
67
68
69
70struct clk_regmap_div_data {
71 unsigned int offset;
72 u8 shift;
73 u8 width;
74 u8 flags;
75 const struct clk_div_table *table;
76};
77
78static inline struct clk_regmap_div_data *
79clk_get_regmap_div_data(struct clk_regmap *clk)
80{
81 return (struct clk_regmap_div_data *)clk->data;
82}
83
84extern const struct clk_ops clk_regmap_divider_ops;
85extern const struct clk_ops clk_regmap_divider_ro_ops;
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100struct clk_regmap_mux_data {
101 unsigned int offset;
102 u32 *table;
103 u32 mask;
104 u8 shift;
105 u8 flags;
106};
107
108static inline struct clk_regmap_mux_data *
109clk_get_regmap_mux_data(struct clk_regmap *clk)
110{
111 return (struct clk_regmap_mux_data *)clk->data;
112}
113
114extern const struct clk_ops clk_regmap_mux_ops;
115extern const struct clk_ops clk_regmap_mux_ro_ops;
116
117#define __MESON_PCLK(_name, _reg, _bit, _ops, _pname) \
118struct clk_regmap _name = { \
119 .data = &(struct clk_regmap_gate_data){ \
120 .offset = (_reg), \
121 .bit_idx = (_bit), \
122 }, \
123 .hw.init = &(struct clk_init_data) { \
124 .name = #_name, \
125 .ops = _ops, \
126 .parent_hws = (const struct clk_hw *[]) { _pname }, \
127 .num_parents = 1, \
128 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
129 }, \
130}
131
132#define MESON_PCLK(_name, _reg, _bit, _pname) \
133 __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ops, _pname)
134
135#define MESON_PCLK_RO(_name, _reg, _bit, _pname) \
136 __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ro_ops, _pname)
137#endif
138