GNU Linux-libre 4.14.254-gnu1
[releases.git] / drivers / clk / sunxi-ng / ccu_nkmp.h
1 /*
2  * Copyright (c) 2016 Maxime Ripard. All rights reserved.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef _CCU_NKMP_H_
15 #define _CCU_NKMP_H_
16
17 #include <linux/clk-provider.h>
18
19 #include "ccu_common.h"
20 #include "ccu_div.h"
21 #include "ccu_mult.h"
22
23 /*
24  * struct ccu_nkmp - Definition of an N-K-M-P clock
25  *
26  * Clocks based on the formula parent * N * K >> P / M
27  */
28 struct ccu_nkmp {
29         u32                     enable;
30         u32                     lock;
31
32         struct ccu_mult_internal        n;
33         struct ccu_mult_internal        k;
34         struct ccu_div_internal         m;
35         struct ccu_div_internal         p;
36
37         struct ccu_common       common;
38 };
39
40 #define SUNXI_CCU_NKMP_WITH_GATE_LOCK(_struct, _name, _parent, _reg,    \
41                                       _nshift, _nwidth,                 \
42                                       _kshift, _kwidth,                 \
43                                       _mshift, _mwidth,                 \
44                                       _pshift, _pwidth,                 \
45                                       _gate, _lock, _flags)             \
46         struct ccu_nkmp _struct = {                                     \
47                 .enable         = _gate,                                \
48                 .lock           = _lock,                                \
49                 .n              = _SUNXI_CCU_MULT(_nshift, _nwidth),    \
50                 .k              = _SUNXI_CCU_MULT(_kshift, _kwidth),    \
51                 .m              = _SUNXI_CCU_DIV(_mshift, _mwidth),     \
52                 .p              = _SUNXI_CCU_DIV(_pshift, _pwidth),     \
53                 .common         = {                                     \
54                         .reg            = _reg,                         \
55                         .hw.init        = CLK_HW_INIT(_name,            \
56                                                       _parent,          \
57                                                       &ccu_nkmp_ops,    \
58                                                       _flags),          \
59                 },                                                      \
60         }
61
62 static inline struct ccu_nkmp *hw_to_ccu_nkmp(struct clk_hw *hw)
63 {
64         struct ccu_common *common = hw_to_ccu_common(hw);
65
66         return container_of(common, struct ccu_nkmp, common);
67 }
68
69 extern const struct clk_ops ccu_nkmp_ops;
70
71 #endif /* _CCU_NKMP_H_ */