2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef __CLK_UNIPHIER_H__
17 #define __CLK_UNIPHIER_H__
23 #define UNIPHIER_CLK_CPUGEAR_MAX_PARENTS 16
24 #define UNIPHIER_CLK_MUX_MAX_PARENTS 8
26 enum uniphier_clk_type
{
27 UNIPHIER_CLK_TYPE_CPUGEAR
,
28 UNIPHIER_CLK_TYPE_FIXED_FACTOR
,
29 UNIPHIER_CLK_TYPE_FIXED_RATE
,
30 UNIPHIER_CLK_TYPE_GATE
,
31 UNIPHIER_CLK_TYPE_MUX
,
34 struct uniphier_clk_cpugear_data
{
35 const char *parent_names
[UNIPHIER_CLK_CPUGEAR_MAX_PARENTS
];
36 unsigned int num_parents
;
41 struct uniphier_clk_fixed_factor_data
{
42 const char *parent_name
;
47 struct uniphier_clk_fixed_rate_data
{
48 unsigned long fixed_rate
;
51 struct uniphier_clk_gate_data
{
52 const char *parent_name
;
57 struct uniphier_clk_mux_data
{
58 const char *parent_names
[UNIPHIER_CLK_MUX_MAX_PARENTS
];
59 unsigned int num_parents
;
61 unsigned int masks
[UNIPHIER_CLK_MUX_MAX_PARENTS
];
62 unsigned int vals
[UNIPHIER_CLK_MUX_MAX_PARENTS
];
65 struct uniphier_clk_data
{
67 enum uniphier_clk_type type
;
70 struct uniphier_clk_cpugear_data cpugear
;
71 struct uniphier_clk_fixed_factor_data factor
;
72 struct uniphier_clk_fixed_rate_data rate
;
73 struct uniphier_clk_gate_data gate
;
74 struct uniphier_clk_mux_data mux
;
78 #define UNIPHIER_CLK_CPUGEAR(_name, _idx, _regbase, _mask, \
82 .type = UNIPHIER_CLK_TYPE_CPUGEAR, \
85 .parent_names = { __VA_ARGS__ }, \
86 .num_parents = (_num_parents), \
87 .regbase = (_regbase), \
92 #define UNIPHIER_CLK_FACTOR(_name, _idx, _parent, _mult, _div) \
95 .type = UNIPHIER_CLK_TYPE_FIXED_FACTOR, \
98 .parent_name = (_parent), \
104 #define UNIPHIER_CLK_GATE(_name, _idx, _parent, _reg, _bit) \
107 .type = UNIPHIER_CLK_TYPE_GATE, \
110 .parent_name = (_parent), \
116 #define UNIPHIER_CLK_DIV(parent, div) \
117 UNIPHIER_CLK_FACTOR(parent "/" #div, -1, parent, 1, div)
119 #define UNIPHIER_CLK_DIV2(parent, div0, div1) \
120 UNIPHIER_CLK_DIV(parent, div0), \
121 UNIPHIER_CLK_DIV(parent, div1)
123 #define UNIPHIER_CLK_DIV3(parent, div0, div1, div2) \
124 UNIPHIER_CLK_DIV2(parent, div0, div1), \
125 UNIPHIER_CLK_DIV(parent, div2)
127 #define UNIPHIER_CLK_DIV4(parent, div0, div1, div2, div3) \
128 UNIPHIER_CLK_DIV2(parent, div0, div1), \
129 UNIPHIER_CLK_DIV2(parent, div2, div3)
131 struct clk_hw
*uniphier_clk_register_cpugear(struct device
*dev
,
132 struct regmap
*regmap
,
134 const struct uniphier_clk_cpugear_data
*data
);
135 struct clk_hw
*uniphier_clk_register_fixed_factor(struct device
*dev
,
137 const struct uniphier_clk_fixed_factor_data
*data
);
138 struct clk_hw
*uniphier_clk_register_fixed_rate(struct device
*dev
,
140 const struct uniphier_clk_fixed_rate_data
*data
);
141 struct clk_hw
*uniphier_clk_register_gate(struct device
*dev
,
142 struct regmap
*regmap
,
144 const struct uniphier_clk_gate_data
*data
);
145 struct clk_hw
*uniphier_clk_register_mux(struct device
*dev
,
146 struct regmap
*regmap
,
148 const struct uniphier_clk_mux_data
*data
);
150 extern const struct uniphier_clk_data uniphier_ld4_sys_clk_data
[];
151 extern const struct uniphier_clk_data uniphier_pro4_sys_clk_data
[];
152 extern const struct uniphier_clk_data uniphier_sld8_sys_clk_data
[];
153 extern const struct uniphier_clk_data uniphier_pro5_sys_clk_data
[];
154 extern const struct uniphier_clk_data uniphier_pxs2_sys_clk_data
[];
155 extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data
[];
156 extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data
[];
157 extern const struct uniphier_clk_data uniphier_pxs3_sys_clk_data
[];
158 extern const struct uniphier_clk_data uniphier_ld4_mio_clk_data
[];
159 extern const struct uniphier_clk_data uniphier_pro5_sd_clk_data
[];
160 extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data
[];
161 extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data
[];
163 #endif /* __CLK_UNIPHIER_H__ */