blob: f20c0bd62a47fb4d34af81fa7bd521ef4b392eb1 [file] [log] [blame]
Maxime Ripard2a65ed42016-06-29 21:05:26 +02001#ifndef _CCU_MUX_H_
2#define _CCU_MUX_H_
3
4#include <linux/clk-provider.h>
5
6#include "ccu_common.h"
7
Chen-Yu Tsaiff5294d2016-08-25 14:21:57 +08008struct ccu_mux_fixed_prediv {
9 u8 index;
10 u16 div;
11};
12
Chen-Yu Tsai13e0dde2017-05-19 15:06:08 +080013struct ccu_mux_var_prediv {
14 u8 index;
15 u8 shift;
16 u8 width;
17};
18
Maxime Ripard2a65ed42016-06-29 21:05:26 +020019struct ccu_mux_internal {
Chen-Yu Tsai2b9c8752016-08-25 14:21:56 +080020 u8 shift;
21 u8 width;
22 const u8 *table;
Maxime Ripard2a65ed42016-06-29 21:05:26 +020023
Chen-Yu Tsaiff5294d2016-08-25 14:21:57 +080024 const struct ccu_mux_fixed_prediv *fixed_predivs;
25 u8 n_predivs;
Maxime Ripard2a65ed42016-06-29 21:05:26 +020026
Chen-Yu Tsai13e0dde2017-05-19 15:06:08 +080027 const struct ccu_mux_var_prediv *var_predivs;
28 u8 n_var_predivs;
Maxime Ripard2a65ed42016-06-29 21:05:26 +020029};
30
Chen-Yu Tsai2b9c8752016-08-25 14:21:56 +080031#define _SUNXI_CCU_MUX_TABLE(_shift, _width, _table) \
32 { \
33 .shift = _shift, \
34 .width = _width, \
35 .table = _table, \
Maxime Ripard2a65ed42016-06-29 21:05:26 +020036 }
37
Chen-Yu Tsai2b9c8752016-08-25 14:21:56 +080038#define _SUNXI_CCU_MUX(_shift, _width) \
39 _SUNXI_CCU_MUX_TABLE(_shift, _width, NULL)
40
Maxime Ripard2a65ed42016-06-29 21:05:26 +020041struct ccu_mux {
42 u16 reg;
43 u32 enable;
44
45 struct ccu_mux_internal mux;
46 struct ccu_common common;
47};
48
Maxime Ripard13e91e42016-08-30 10:38:51 +020049#define SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, _table, \
50 _reg, _shift, _width, _gate, \
51 _flags) \
Maxime Ripard2a65ed42016-06-29 21:05:26 +020052 struct ccu_mux _struct = { \
Maxime Ripard13e91e42016-08-30 10:38:51 +020053 .enable = _gate, \
54 .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \
Maxime Ripard2a65ed42016-06-29 21:05:26 +020055 .common = { \
56 .reg = _reg, \
57 .hw.init = CLK_HW_INIT_PARENTS(_name, \
58 _parents, \
59 &ccu_mux_ops, \
60 _flags), \
61 } \
62 }
63
64#define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \
65 _shift, _width, _gate, _flags) \
Maxime Ripard13e91e42016-08-30 10:38:51 +020066 SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, NULL, \
67 _reg, _shift, _width, _gate, \
68 _flags)
69
70#define SUNXI_CCU_MUX(_struct, _name, _parents, _reg, _shift, _width, \
71 _flags) \
72 SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, NULL, \
73 _reg, _shift, _width, 0, _flags)
Maxime Ripard2a65ed42016-06-29 21:05:26 +020074
75static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
76{
77 struct ccu_common *common = hw_to_ccu_common(hw);
78
79 return container_of(common, struct ccu_mux, common);
80}
81
82extern const struct clk_ops ccu_mux_ops;
83
Maxime Ripardd754b152017-05-17 09:40:35 +020084unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common,
85 struct ccu_mux_internal *cm,
86 int parent_index,
87 unsigned long parent_rate);
Maxime Ripard2a65ed42016-06-29 21:05:26 +020088int ccu_mux_helper_determine_rate(struct ccu_common *common,
89 struct ccu_mux_internal *cm,
90 struct clk_rate_request *req,
91 unsigned long (*round)(struct ccu_mux_internal *,
Maxime Ripard10a8d9b2017-05-17 09:40:31 +020092 struct clk_hw *,
93 unsigned long *,
Maxime Ripard2a65ed42016-06-29 21:05:26 +020094 unsigned long,
95 void *),
96 void *data);
97u8 ccu_mux_helper_get_parent(struct ccu_common *common,
98 struct ccu_mux_internal *cm);
99int ccu_mux_helper_set_parent(struct ccu_common *common,
100 struct ccu_mux_internal *cm,
101 u8 index);
102
Chen-Yu Tsai8adfb082016-08-25 14:21:58 +0800103struct ccu_mux_nb {
104 struct notifier_block clk_nb;
105 struct ccu_common *common;
106 struct ccu_mux_internal *cm;
107
108 u32 delay_us; /* How many us to wait after reparenting */
109 u8 bypass_index; /* Which parent to temporarily use */
110 u8 original_index; /* This is set by the notifier callback */
111};
112
113#define to_ccu_mux_nb(_nb) container_of(_nb, struct ccu_mux_nb, clk_nb)
114
115int ccu_mux_notifier_register(struct clk *clk, struct ccu_mux_nb *mux_nb);
116
Maxime Ripard2a65ed42016-06-29 21:05:26 +0200117#endif /* _CCU_MUX_H_ */