Commit | Line | Data |
---|---|---|
21325b25 PW |
1 | /* |
2 | * OMAP2+ common Clock Management (CM) IP block functions | |
3 | * | |
4 | * Copyright (C) 2012 Texas Instruments, Inc. | |
d9a16f9a | 5 | * Paul Walmsley |
21325b25 PW |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * XXX This code should eventually be moved to a CM driver. | |
12 | */ | |
13 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/init.h> | |
cc4b1e24 | 16 | #include <linux/errno.h> |
4794208c | 17 | #include <linux/bug.h> |
21325b25 PW |
18 | |
19 | #include "cm2xxx.h" | |
20 | #include "cm3xxx.h" | |
21 | #include "cm44xx.h" | |
22 | ||
23 | /* | |
24 | * cm_ll_data: function pointers to SoC-specific implementations of | |
25 | * common CM functions | |
26 | */ | |
27 | static struct cm_ll_data null_cm_ll_data; | |
28 | static struct cm_ll_data *cm_ll_data = &null_cm_ll_data; | |
29 | ||
d9a16f9a PW |
30 | /* cm_base: base virtual address of the CM IP block */ |
31 | void __iomem *cm_base; | |
32 | ||
33 | /* cm2_base: base virtual address of the CM2 IP block (OMAP44xx only) */ | |
34 | void __iomem *cm2_base; | |
35 | ||
36 | /** | |
37 | * omap2_set_globals_cm - set the CM/CM2 base addresses (for early use) | |
38 | * @cm: CM base virtual address | |
39 | * @cm2: CM2 base virtual address (if present on the booted SoC) | |
40 | * | |
41 | * XXX Will be replaced when the PRM/CM drivers are completed. | |
42 | */ | |
43 | void __init omap2_set_globals_cm(void __iomem *cm, void __iomem *cm2) | |
44 | { | |
45 | cm_base = cm; | |
46 | cm2_base = cm2; | |
47 | } | |
48 | ||
c4ceedcb PW |
49 | /** |
50 | * cm_split_idlest_reg - split CM_IDLEST reg addr into its components | |
51 | * @idlest_reg: CM_IDLEST* virtual address | |
52 | * @prcm_inst: pointer to an s16 to return the PRCM instance offset | |
53 | * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID | |
54 | * | |
55 | * Given an absolute CM_IDLEST register address @idlest_reg, passes | |
56 | * the PRCM instance offset and IDLEST register ID back to the caller | |
57 | * via the @prcm_inst and @idlest_reg_id. Returns -EINVAL upon error, | |
58 | * or 0 upon success. XXX This function is only needed until absolute | |
59 | * register addresses are removed from the OMAP struct clk records. | |
60 | */ | |
61 | int cm_split_idlest_reg(void __iomem *idlest_reg, s16 *prcm_inst, | |
62 | u8 *idlest_reg_id) | |
63 | { | |
64 | if (!cm_ll_data->split_idlest_reg) { | |
65 | WARN_ONCE(1, "cm: %s: no low-level function defined\n", | |
66 | __func__); | |
67 | return -EINVAL; | |
68 | } | |
69 | ||
70 | return cm_ll_data->split_idlest_reg(idlest_reg, prcm_inst, | |
71 | idlest_reg_id); | |
72 | } | |
73 | ||
74 | /** | |
021b6ff0 TK |
75 | * omap_cm_wait_module_ready - wait for a module to leave idle or standby |
76 | * @part: PRCM partition | |
c4ceedcb | 77 | * @prcm_mod: PRCM module offset |
021b6ff0 | 78 | * @idlest_reg: CM_IDLESTx register |
c4ceedcb PW |
79 | * @idlest_shift: shift of the bit in the CM_IDLEST* register to check |
80 | * | |
81 | * Wait for the PRCM to indicate that the module identified by | |
82 | * (@prcm_mod, @idlest_id, @idlest_shift) is clocked. Return 0 upon | |
83 | * success, -EBUSY if the module doesn't enable in time, or -EINVAL if | |
84 | * no per-SoC wait_module_ready() function pointer has been registered | |
85 | * or if the idlest register is unknown on the SoC. | |
86 | */ | |
021b6ff0 TK |
87 | int omap_cm_wait_module_ready(u8 part, s16 prcm_mod, u16 idlest_reg, |
88 | u8 idlest_shift) | |
c4ceedcb PW |
89 | { |
90 | if (!cm_ll_data->wait_module_ready) { | |
91 | WARN_ONCE(1, "cm: %s: no low-level function defined\n", | |
92 | __func__); | |
93 | return -EINVAL; | |
94 | } | |
95 | ||
021b6ff0 TK |
96 | return cm_ll_data->wait_module_ready(part, prcm_mod, idlest_reg, |
97 | idlest_shift); | |
c4ceedcb PW |
98 | } |
99 | ||
a8ae5afa TK |
100 | /** |
101 | * omap_cm_wait_module_idle - wait for a module to enter idle or standby | |
102 | * @part: PRCM partition | |
103 | * @prcm_mod: PRCM module offset | |
104 | * @idlest_reg: CM_IDLESTx register | |
105 | * @idlest_shift: shift of the bit in the CM_IDLEST* register to check | |
106 | * | |
107 | * Wait for the PRCM to indicate that the module identified by | |
108 | * (@prcm_mod, @idlest_id, @idlest_shift) is no longer clocked. Return | |
109 | * 0 upon success, -EBUSY if the module doesn't enable in time, or | |
110 | * -EINVAL if no per-SoC wait_module_idle() function pointer has been | |
111 | * registered or if the idlest register is unknown on the SoC. | |
112 | */ | |
113 | int omap_cm_wait_module_idle(u8 part, s16 prcm_mod, u16 idlest_reg, | |
114 | u8 idlest_shift) | |
115 | { | |
116 | if (!cm_ll_data->wait_module_idle) { | |
117 | WARN_ONCE(1, "cm: %s: no low-level function defined\n", | |
118 | __func__); | |
119 | return -EINVAL; | |
120 | } | |
121 | ||
122 | return cm_ll_data->wait_module_idle(part, prcm_mod, idlest_reg, | |
123 | idlest_shift); | |
124 | } | |
125 | ||
128603f0 TK |
126 | /** |
127 | * omap_cm_module_enable - enable a module | |
128 | * @mode: target mode for the module | |
129 | * @part: PRCM partition | |
130 | * @inst: PRCM instance | |
131 | * @clkctrl_offs: CM_CLKCTRL register offset for the module | |
132 | * | |
133 | * Enables clocks for a module identified by (@part, @inst, @clkctrl_offs) | |
134 | * making its IO space accessible. Return 0 upon success, -EINVAL if no | |
135 | * per-SoC module_enable() function pointer has been registered. | |
136 | */ | |
137 | int omap_cm_module_enable(u8 mode, u8 part, u16 inst, u16 clkctrl_offs) | |
138 | { | |
139 | if (!cm_ll_data->module_enable) { | |
140 | WARN_ONCE(1, "cm: %s: no low-level function defined\n", | |
141 | __func__); | |
142 | return -EINVAL; | |
143 | } | |
144 | ||
145 | cm_ll_data->module_enable(mode, part, inst, clkctrl_offs); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | /** | |
150 | * omap_cm_module_disable - disable a module | |
151 | * @part: PRCM partition | |
152 | * @inst: PRCM instance | |
153 | * @clkctrl_offs: CM_CLKCTRL register offset for the module | |
154 | * | |
155 | * Disables clocks for a module identified by (@part, @inst, @clkctrl_offs) | |
156 | * makings its IO space inaccessible. Return 0 upon success, -EINVAL if | |
157 | * no per-SoC module_disable() function pointer has been registered. | |
158 | */ | |
159 | int omap_cm_module_disable(u8 part, u16 inst, u16 clkctrl_offs) | |
160 | { | |
161 | if (!cm_ll_data->module_disable) { | |
162 | WARN_ONCE(1, "cm: %s: no low-level function defined\n", | |
163 | __func__); | |
164 | return -EINVAL; | |
165 | } | |
166 | ||
167 | cm_ll_data->module_disable(part, inst, clkctrl_offs); | |
168 | return 0; | |
169 | } | |
170 | ||
21325b25 PW |
171 | /** |
172 | * cm_register - register per-SoC low-level data with the CM | |
173 | * @cld: low-level per-SoC OMAP CM data & function pointers to register | |
174 | * | |
175 | * Register per-SoC low-level OMAP CM data and function pointers with | |
176 | * the OMAP CM common interface. The caller must keep the data | |
177 | * pointed to by @cld valid until it calls cm_unregister() and | |
178 | * it returns successfully. Returns 0 upon success, -EINVAL if @cld | |
179 | * is NULL, or -EEXIST if cm_register() has already been called | |
180 | * without an intervening cm_unregister(). | |
181 | */ | |
182 | int cm_register(struct cm_ll_data *cld) | |
183 | { | |
184 | if (!cld) | |
185 | return -EINVAL; | |
186 | ||
187 | if (cm_ll_data != &null_cm_ll_data) | |
188 | return -EEXIST; | |
189 | ||
190 | cm_ll_data = cld; | |
191 | ||
192 | return 0; | |
193 | } | |
194 | ||
195 | /** | |
196 | * cm_unregister - unregister per-SoC low-level data & function pointers | |
197 | * @cld: low-level per-SoC OMAP CM data & function pointers to unregister | |
198 | * | |
199 | * Unregister per-SoC low-level OMAP CM data and function pointers | |
200 | * that were previously registered with cm_register(). The | |
201 | * caller may not destroy any of the data pointed to by @cld until | |
202 | * this function returns successfully. Returns 0 upon success, or | |
203 | * -EINVAL if @cld is NULL or if @cld does not match the struct | |
204 | * cm_ll_data * previously registered by cm_register(). | |
205 | */ | |
206 | int cm_unregister(struct cm_ll_data *cld) | |
207 | { | |
208 | if (!cld || cm_ll_data != cld) | |
209 | return -EINVAL; | |
210 | ||
211 | cm_ll_data = &null_cm_ll_data; | |
212 | ||
213 | return 0; | |
214 | } |