clk: renesas: cpg-mssr: Add support for fixed rate clocks
[linux-2.6-microblaze.git] / drivers / clk / renesas / renesas-cpg-mssr.h
1 /*
2  * Renesas Clock Pulse Generator / Module Standby and Software Reset
3  *
4  * Copyright (C) 2015 Glider bvba
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  */
10
11 #ifndef __CLK_RENESAS_CPG_MSSR_H__
12 #define __CLK_RENESAS_CPG_MSSR_H__
13
14     /*
15      * Definitions of CPG Core Clocks
16      *
17      * These include:
18      *   - Clock outputs exported to DT
19      *   - External input clocks
20      *   - Internal CPG clocks
21      */
22
23 struct cpg_core_clk {
24         /* Common */
25         const char *name;
26         unsigned int id;
27         unsigned int type;
28         /* Depending on type */
29         unsigned int parent;    /* Core Clocks only */
30         unsigned int div;
31         unsigned int mult;
32         unsigned int offset;
33 };
34
35 enum clk_types {
36         /* Generic */
37         CLK_TYPE_IN,            /* External Clock Input */
38         CLK_TYPE_FF,            /* Fixed Factor Clock */
39         CLK_TYPE_DIV6P1,        /* DIV6 Clock with 1 parent clock */
40         CLK_TYPE_DIV6_RO,       /* DIV6 Clock read only with extra divisor */
41         CLK_TYPE_FR,            /* Fixed Rate Clock */
42
43         /* Custom definitions start here */
44         CLK_TYPE_CUSTOM,
45 };
46
47 #define DEF_TYPE(_name, _id, _type...)  \
48         { .name = _name, .id = _id, .type = _type }
49 #define DEF_BASE(_name, _id, _type, _parent...) \
50         DEF_TYPE(_name, _id, _type, .parent = _parent)
51
52 #define DEF_INPUT(_name, _id) \
53         DEF_TYPE(_name, _id, CLK_TYPE_IN)
54 #define DEF_FIXED(_name, _id, _parent, _div, _mult)     \
55         DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
56 #define DEF_DIV6P1(_name, _id, _parent, _offset)        \
57         DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
58 #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
59         DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
60 #define DEF_RATE(_name, _id, _rate)     \
61         DEF_TYPE(_name, _id, CLK_TYPE_FR, .mult = _rate)
62
63     /*
64      * Definitions of Module Clocks
65      */
66
67 struct mssr_mod_clk {
68         const char *name;
69         unsigned int id;
70         unsigned int parent;    /* Add MOD_CLK_BASE for Module Clocks */
71 };
72
73 /* Convert from sparse base-100 to packed index space */
74 #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
75
76 #define MOD_CLK_ID(x)   (MOD_CLK_BASE + MOD_CLK_PACK(x))
77
78 #define DEF_MOD(_name, _mod, _parent...)        \
79         { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
80
81
82 struct device_node;
83
84     /**
85      * SoC-specific CPG/MSSR Description
86      *
87      * @core_clks: Array of Core Clock definitions
88      * @num_core_clks: Number of entries in core_clks[]
89      * @last_dt_core_clk: ID of the last Core Clock exported to DT
90      * @num_total_core_clks: Total number of Core Clocks (exported + internal)
91      *
92      * @mod_clks: Array of Module Clock definitions
93      * @num_mod_clks: Number of entries in mod_clks[]
94      * @num_hw_mod_clks: Number of Module Clocks supported by the hardware
95      *
96      * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
97      *                 should not be disabled without a knowledgeable driver
98      * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
99      *
100      * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power
101      *                Management, in addition to Module Clocks
102      * @num_core_pm_clks: Number of entries in core_pm_clks[]
103      *
104      * @init: Optional callback to perform SoC-specific initialization
105      * @cpg_clk_register: Optional callback to handle special Core Clock types
106      */
107
108 struct cpg_mssr_info {
109         /* Core Clocks */
110         const struct cpg_core_clk *core_clks;
111         unsigned int num_core_clks;
112         unsigned int last_dt_core_clk;
113         unsigned int num_total_core_clks;
114
115         /* Module Clocks */
116         const struct mssr_mod_clk *mod_clks;
117         unsigned int num_mod_clks;
118         unsigned int num_hw_mod_clks;
119
120         /* Critical Module Clocks that should not be disabled */
121         const unsigned int *crit_mod_clks;
122         unsigned int num_crit_mod_clks;
123
124         /* Core Clocks suitable for PM, in addition to the Module Clocks */
125         const unsigned int *core_pm_clks;
126         unsigned int num_core_pm_clks;
127
128         /* Callbacks */
129         int (*init)(struct device *dev);
130         struct clk *(*cpg_clk_register)(struct device *dev,
131                                         const struct cpg_core_clk *core,
132                                         const struct cpg_mssr_info *info,
133                                         struct clk **clks, void __iomem *base,
134                                         struct raw_notifier_head *notifiers);
135 };
136
137 extern const struct cpg_mssr_info r8a7743_cpg_mssr_info;
138 extern const struct cpg_mssr_info r8a7745_cpg_mssr_info;
139 extern const struct cpg_mssr_info r8a77470_cpg_mssr_info;
140 extern const struct cpg_mssr_info r8a7790_cpg_mssr_info;
141 extern const struct cpg_mssr_info r8a7791_cpg_mssr_info;
142 extern const struct cpg_mssr_info r8a7792_cpg_mssr_info;
143 extern const struct cpg_mssr_info r8a7794_cpg_mssr_info;
144 extern const struct cpg_mssr_info r8a7795_cpg_mssr_info;
145 extern const struct cpg_mssr_info r8a7796_cpg_mssr_info;
146 extern const struct cpg_mssr_info r8a77965_cpg_mssr_info;
147 extern const struct cpg_mssr_info r8a77970_cpg_mssr_info;
148 extern const struct cpg_mssr_info r8a77980_cpg_mssr_info;
149 extern const struct cpg_mssr_info r8a77990_cpg_mssr_info;
150 extern const struct cpg_mssr_info r8a77995_cpg_mssr_info;
151
152
153     /*
154      * Helpers for fixing up clock tables depending on SoC revision
155      */
156
157 struct mssr_mod_reparent {
158         unsigned int clk, parent;
159 };
160
161
162 extern void cpg_core_nullify_range(struct cpg_core_clk *core_clks,
163                                    unsigned int num_core_clks,
164                                    unsigned int first_clk,
165                                    unsigned int last_clk);
166 extern void mssr_mod_nullify(struct mssr_mod_clk *mod_clks,
167                              unsigned int num_mod_clks,
168                              const unsigned int *clks, unsigned int n);
169 extern void mssr_mod_reparent(struct mssr_mod_clk *mod_clks,
170                               unsigned int num_mod_clks,
171                               const struct mssr_mod_reparent *clks,
172                               unsigned int n);
173 #endif