Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / clk / meson / clk-regmap.h
blobe365312da54ece08098293b1a831c803415db814
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2018 BayLibre, SAS.
4 * Author: Jerome Brunet <jbrunet@baylibre.com>
5 */
7 #ifndef __CLK_REGMAP_H
8 #define __CLK_REGMAP_H
10 #include <linux/clk-provider.h>
11 #include <linux/regmap.h>
13 /**
14 * struct clk_regmap - regmap backed clock
16 * @hw: handle between common and hardware-specific interfaces
17 * @map: pointer to the regmap structure controlling the clock
18 * @data: data specific to the clock type
20 * Clock which is controlled by regmap backed registers. The actual type of
21 * of the clock is controlled by the clock_ops and data.
23 struct clk_regmap {
24 struct clk_hw hw;
25 struct regmap *map;
26 void *data;
29 static inline struct clk_regmap *to_clk_regmap(struct clk_hw *hw)
31 return container_of(hw, struct clk_regmap, hw);
34 /**
35 * struct clk_regmap_gate_data - regmap backed gate specific data
37 * @offset: offset of the register controlling gate
38 * @bit_idx: single bit controlling gate
39 * @flags: hardware-specific flags
41 * Flags:
42 * Same as clk_gate except CLK_GATE_HIWORD_MASK which is ignored
44 struct clk_regmap_gate_data {
45 unsigned int offset;
46 u8 bit_idx;
47 u8 flags;
50 static inline struct clk_regmap_gate_data *
51 clk_get_regmap_gate_data(struct clk_regmap *clk)
53 return (struct clk_regmap_gate_data *)clk->data;
56 extern const struct clk_ops clk_regmap_gate_ops;
57 extern const struct clk_ops clk_regmap_gate_ro_ops;
59 /**
60 * struct clk_regmap_div_data - regmap backed adjustable divider specific data
62 * @offset: offset of the register controlling the divider
63 * @shift: shift to the divider bit field
64 * @width: width of the divider bit field
65 * @table: array of value/divider pairs, last entry should have div = 0
67 * Flags:
68 * Same as clk_divider except CLK_DIVIDER_HIWORD_MASK which is ignored
70 struct clk_regmap_div_data {
71 unsigned int offset;
72 u8 shift;
73 u8 width;
74 u8 flags;
75 const struct clk_div_table *table;
78 static inline struct clk_regmap_div_data *
79 clk_get_regmap_div_data(struct clk_regmap *clk)
81 return (struct clk_regmap_div_data *)clk->data;
84 extern const struct clk_ops clk_regmap_divider_ops;
85 extern const struct clk_ops clk_regmap_divider_ro_ops;
87 /**
88 * struct clk_regmap_mux_data - regmap backed multiplexer clock specific data
90 * @hw: handle between common and hardware-specific interfaces
91 * @offset: offset of theregister controlling multiplexer
92 * @table: array of parent indexed register values
93 * @shift: shift to multiplexer bit field
94 * @mask: mask of mutliplexer bit field
95 * @flags: hardware-specific flags
97 * Flags:
98 * Same as clk_divider except CLK_MUX_HIWORD_MASK which is ignored
100 struct clk_regmap_mux_data {
101 unsigned int offset;
102 u32 *table;
103 u32 mask;
104 u8 shift;
105 u8 flags;
108 static inline struct clk_regmap_mux_data *
109 clk_get_regmap_mux_data(struct clk_regmap *clk)
111 return (struct clk_regmap_mux_data *)clk->data;
114 extern const struct clk_ops clk_regmap_mux_ops;
115 extern const struct clk_ops clk_regmap_mux_ro_ops;
117 #define __MESON_PCLK(_name, _reg, _bit, _ops, _pname) \
118 struct 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 }, \
132 #define MESON_PCLK(_name, _reg, _bit, _pname) \
133 __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ops, _pname)
135 #define MESON_PCLK_RO(_name, _reg, _bit, _pname) \
136 __MESON_PCLK(_name, _reg, _bit, &clk_regmap_gate_ro_ops, _pname)
137 #endif /* __CLK_REGMAP_H */