Commit | Line | Data |
---|---|---|
63c85238 PW |
1 | /* |
2 | * omap_hwmod implementation for OMAP2/3/4 | |
3 | * | |
4 | * Copyright (C) 2009 Nokia Corporation | |
5 | * Paul Walmsley | |
6 | * With fixes and testing from Kevin Hilman | |
7 | * | |
8 | * Created in collaboration with (alphabetical order): Benoit Cousson, | |
9 | * Kevin Hilman, Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari | |
10 | * Poussa, Anand Sawant, Santosh Shilimkar, Richard Woodruff | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License version 2 as | |
14 | * published by the Free Software Foundation. | |
15 | * | |
16 | * This code manages "OMAP modules" (on-chip devices) and their | |
17 | * integration with Linux device driver and bus code. | |
18 | * | |
19 | * References: | |
20 | * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064) | |
21 | * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090) | |
22 | * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108) | |
23 | * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140) | |
24 | * - Open Core Protocol Specification 2.2 | |
25 | * | |
26 | * To do: | |
27 | * - pin mux handling | |
28 | * - handle IO mapping | |
29 | * - bus throughput & module latency measurement code | |
30 | * | |
31 | * XXX add tests at the beginning of each function to ensure the hwmod is | |
32 | * in the appropriate state | |
33 | * XXX error return values should be checked to ensure that they are | |
34 | * appropriate | |
35 | */ | |
36 | #undef DEBUG | |
37 | ||
38 | #include <linux/kernel.h> | |
39 | #include <linux/errno.h> | |
40 | #include <linux/io.h> | |
41 | #include <linux/clk.h> | |
42 | #include <linux/delay.h> | |
43 | #include <linux/err.h> | |
44 | #include <linux/list.h> | |
45 | #include <linux/mutex.h> | |
46 | #include <linux/bootmem.h> | |
47 | ||
6f8b7ff5 | 48 | #include <plat/common.h> |
ce491cf8 TL |
49 | #include <plat/cpu.h> |
50 | #include <plat/clockdomain.h> | |
51 | #include <plat/powerdomain.h> | |
52 | #include <plat/clock.h> | |
53 | #include <plat/omap_hwmod.h> | |
63c85238 PW |
54 | |
55 | #include "cm.h" | |
56 | ||
57 | /* Maximum microseconds to wait for OMAP module to reset */ | |
58 | #define MAX_MODULE_RESET_WAIT 10000 | |
59 | ||
60 | /* Name of the OMAP hwmod for the MPU */ | |
61 | #define MPU_INITIATOR_NAME "mpu_hwmod" | |
62 | ||
63 | /* omap_hwmod_list contains all registered struct omap_hwmods */ | |
64 | static LIST_HEAD(omap_hwmod_list); | |
65 | ||
66 | static DEFINE_MUTEX(omap_hwmod_mutex); | |
67 | ||
68 | /* mpu_oh: used to add/remove MPU initiator from sleepdep list */ | |
69 | static struct omap_hwmod *mpu_oh; | |
70 | ||
71 | /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */ | |
72 | static u8 inited; | |
73 | ||
74 | ||
75 | /* Private functions */ | |
76 | ||
77 | /** | |
78 | * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy | |
79 | * @oh: struct omap_hwmod * | |
80 | * | |
81 | * Load the current value of the hwmod OCP_SYSCONFIG register into the | |
82 | * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no | |
83 | * OCP_SYSCONFIG register or 0 upon success. | |
84 | */ | |
85 | static int _update_sysc_cache(struct omap_hwmod *oh) | |
86 | { | |
43b40992 PW |
87 | if (!oh->class->sysc) { |
88 | WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name); | |
63c85238 PW |
89 | return -EINVAL; |
90 | } | |
91 | ||
92 | /* XXX ensure module interface clock is up */ | |
93 | ||
43b40992 | 94 | oh->_sysc_cache = omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); |
63c85238 | 95 | |
43b40992 | 96 | if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE)) |
883edfdd | 97 | oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED; |
63c85238 PW |
98 | |
99 | return 0; | |
100 | } | |
101 | ||
102 | /** | |
103 | * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register | |
104 | * @v: OCP_SYSCONFIG value to write | |
105 | * @oh: struct omap_hwmod * | |
106 | * | |
43b40992 PW |
107 | * Write @v into the module class' OCP_SYSCONFIG register, if it has |
108 | * one. No return value. | |
63c85238 PW |
109 | */ |
110 | static void _write_sysconfig(u32 v, struct omap_hwmod *oh) | |
111 | { | |
43b40992 PW |
112 | if (!oh->class->sysc) { |
113 | WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name); | |
63c85238 PW |
114 | return; |
115 | } | |
116 | ||
117 | /* XXX ensure module interface clock is up */ | |
118 | ||
119 | if (oh->_sysc_cache != v) { | |
120 | oh->_sysc_cache = v; | |
43b40992 | 121 | omap_hwmod_writel(v, oh, oh->class->sysc->sysc_offs); |
63c85238 PW |
122 | } |
123 | } | |
124 | ||
125 | /** | |
126 | * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v | |
127 | * @oh: struct omap_hwmod * | |
128 | * @standbymode: MIDLEMODE field bits | |
129 | * @v: pointer to register contents to modify | |
130 | * | |
131 | * Update the master standby mode bits in @v to be @standbymode for | |
132 | * the @oh hwmod. Does not write to the hardware. Returns -EINVAL | |
133 | * upon error or 0 upon success. | |
134 | */ | |
135 | static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode, | |
136 | u32 *v) | |
137 | { | |
358f0e63 TG |
138 | u32 mstandby_mask; |
139 | u8 mstandby_shift; | |
140 | ||
43b40992 PW |
141 | if (!oh->class->sysc || |
142 | !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE)) | |
63c85238 PW |
143 | return -EINVAL; |
144 | ||
43b40992 PW |
145 | if (!oh->class->sysc->sysc_fields) { |
146 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
147 | return -EINVAL; |
148 | } | |
149 | ||
43b40992 | 150 | mstandby_shift = oh->class->sysc->sysc_fields->midle_shift; |
358f0e63 TG |
151 | mstandby_mask = (0x3 << mstandby_shift); |
152 | ||
153 | *v &= ~mstandby_mask; | |
154 | *v |= __ffs(standbymode) << mstandby_shift; | |
63c85238 PW |
155 | |
156 | return 0; | |
157 | } | |
158 | ||
159 | /** | |
160 | * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v | |
161 | * @oh: struct omap_hwmod * | |
162 | * @idlemode: SIDLEMODE field bits | |
163 | * @v: pointer to register contents to modify | |
164 | * | |
165 | * Update the slave idle mode bits in @v to be @idlemode for the @oh | |
166 | * hwmod. Does not write to the hardware. Returns -EINVAL upon error | |
167 | * or 0 upon success. | |
168 | */ | |
169 | static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v) | |
170 | { | |
358f0e63 TG |
171 | u32 sidle_mask; |
172 | u8 sidle_shift; | |
173 | ||
43b40992 PW |
174 | if (!oh->class->sysc || |
175 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE)) | |
63c85238 PW |
176 | return -EINVAL; |
177 | ||
43b40992 PW |
178 | if (!oh->class->sysc->sysc_fields) { |
179 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
180 | return -EINVAL; |
181 | } | |
182 | ||
43b40992 | 183 | sidle_shift = oh->class->sysc->sysc_fields->sidle_shift; |
358f0e63 TG |
184 | sidle_mask = (0x3 << sidle_shift); |
185 | ||
186 | *v &= ~sidle_mask; | |
187 | *v |= __ffs(idlemode) << sidle_shift; | |
63c85238 PW |
188 | |
189 | return 0; | |
190 | } | |
191 | ||
192 | /** | |
193 | * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v | |
194 | * @oh: struct omap_hwmod * | |
195 | * @clockact: CLOCKACTIVITY field bits | |
196 | * @v: pointer to register contents to modify | |
197 | * | |
198 | * Update the clockactivity mode bits in @v to be @clockact for the | |
199 | * @oh hwmod. Used for additional powersaving on some modules. Does | |
200 | * not write to the hardware. Returns -EINVAL upon error or 0 upon | |
201 | * success. | |
202 | */ | |
203 | static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v) | |
204 | { | |
358f0e63 TG |
205 | u32 clkact_mask; |
206 | u8 clkact_shift; | |
207 | ||
43b40992 PW |
208 | if (!oh->class->sysc || |
209 | !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY)) | |
63c85238 PW |
210 | return -EINVAL; |
211 | ||
43b40992 PW |
212 | if (!oh->class->sysc->sysc_fields) { |
213 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
214 | return -EINVAL; |
215 | } | |
216 | ||
43b40992 | 217 | clkact_shift = oh->class->sysc->sysc_fields->clkact_shift; |
358f0e63 TG |
218 | clkact_mask = (0x3 << clkact_shift); |
219 | ||
220 | *v &= ~clkact_mask; | |
221 | *v |= clockact << clkact_shift; | |
63c85238 PW |
222 | |
223 | return 0; | |
224 | } | |
225 | ||
226 | /** | |
227 | * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v | |
228 | * @oh: struct omap_hwmod * | |
229 | * @v: pointer to register contents to modify | |
230 | * | |
231 | * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon | |
232 | * error or 0 upon success. | |
233 | */ | |
234 | static int _set_softreset(struct omap_hwmod *oh, u32 *v) | |
235 | { | |
358f0e63 TG |
236 | u32 softrst_mask; |
237 | ||
43b40992 PW |
238 | if (!oh->class->sysc || |
239 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) | |
63c85238 PW |
240 | return -EINVAL; |
241 | ||
43b40992 PW |
242 | if (!oh->class->sysc->sysc_fields) { |
243 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
244 | return -EINVAL; |
245 | } | |
246 | ||
43b40992 | 247 | softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift); |
358f0e63 TG |
248 | |
249 | *v |= softrst_mask; | |
63c85238 PW |
250 | |
251 | return 0; | |
252 | } | |
253 | ||
726072e5 PW |
254 | /** |
255 | * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v | |
256 | * @oh: struct omap_hwmod * | |
257 | * @autoidle: desired AUTOIDLE bitfield value (0 or 1) | |
258 | * @v: pointer to register contents to modify | |
259 | * | |
260 | * Update the module autoidle bit in @v to be @autoidle for the @oh | |
261 | * hwmod. The autoidle bit controls whether the module can gate | |
262 | * internal clocks automatically when it isn't doing anything; the | |
263 | * exact function of this bit varies on a per-module basis. This | |
264 | * function does not write to the hardware. Returns -EINVAL upon | |
265 | * error or 0 upon success. | |
266 | */ | |
267 | static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle, | |
268 | u32 *v) | |
269 | { | |
358f0e63 TG |
270 | u32 autoidle_mask; |
271 | u8 autoidle_shift; | |
272 | ||
43b40992 PW |
273 | if (!oh->class->sysc || |
274 | !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE)) | |
726072e5 PW |
275 | return -EINVAL; |
276 | ||
43b40992 PW |
277 | if (!oh->class->sysc->sysc_fields) { |
278 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
279 | return -EINVAL; |
280 | } | |
281 | ||
43b40992 | 282 | autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift; |
358f0e63 TG |
283 | autoidle_mask = (0x3 << autoidle_shift); |
284 | ||
285 | *v &= ~autoidle_mask; | |
286 | *v |= autoidle << autoidle_shift; | |
726072e5 PW |
287 | |
288 | return 0; | |
289 | } | |
290 | ||
63c85238 PW |
291 | /** |
292 | * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware | |
293 | * @oh: struct omap_hwmod * | |
294 | * | |
295 | * Allow the hardware module @oh to send wakeups. Returns -EINVAL | |
296 | * upon error or 0 upon success. | |
297 | */ | |
298 | static int _enable_wakeup(struct omap_hwmod *oh) | |
299 | { | |
358f0e63 | 300 | u32 v, wakeup_mask; |
63c85238 | 301 | |
43b40992 PW |
302 | if (!oh->class->sysc || |
303 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) | |
63c85238 PW |
304 | return -EINVAL; |
305 | ||
43b40992 PW |
306 | if (!oh->class->sysc->sysc_fields) { |
307 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
308 | return -EINVAL; |
309 | } | |
310 | ||
43b40992 | 311 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
358f0e63 | 312 | |
63c85238 | 313 | v = oh->_sysc_cache; |
358f0e63 | 314 | v |= wakeup_mask; |
63c85238 PW |
315 | _write_sysconfig(v, oh); |
316 | ||
317 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ | |
318 | ||
319 | oh->_int_flags |= _HWMOD_WAKEUP_ENABLED; | |
320 | ||
321 | return 0; | |
322 | } | |
323 | ||
324 | /** | |
325 | * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware | |
326 | * @oh: struct omap_hwmod * | |
327 | * | |
328 | * Prevent the hardware module @oh to send wakeups. Returns -EINVAL | |
329 | * upon error or 0 upon success. | |
330 | */ | |
331 | static int _disable_wakeup(struct omap_hwmod *oh) | |
332 | { | |
358f0e63 | 333 | u32 v, wakeup_mask; |
63c85238 | 334 | |
43b40992 PW |
335 | if (!oh->class->sysc || |
336 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) | |
63c85238 PW |
337 | return -EINVAL; |
338 | ||
43b40992 PW |
339 | if (!oh->class->sysc->sysc_fields) { |
340 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); | |
358f0e63 TG |
341 | return -EINVAL; |
342 | } | |
343 | ||
43b40992 | 344 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
358f0e63 | 345 | |
63c85238 | 346 | v = oh->_sysc_cache; |
358f0e63 | 347 | v &= ~wakeup_mask; |
63c85238 PW |
348 | _write_sysconfig(v, oh); |
349 | ||
350 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ | |
351 | ||
352 | oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED; | |
353 | ||
354 | return 0; | |
355 | } | |
356 | ||
357 | /** | |
358 | * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active | |
359 | * @oh: struct omap_hwmod * | |
360 | * | |
361 | * Prevent the hardware module @oh from entering idle while the | |
362 | * hardare module initiator @init_oh is active. Useful when a module | |
363 | * will be accessed by a particular initiator (e.g., if a module will | |
364 | * be accessed by the IVA, there should be a sleepdep between the IVA | |
365 | * initiator and the module). Only applies to modules in smart-idle | |
366 | * mode. Returns -EINVAL upon error or passes along | |
55ed9694 | 367 | * clkdm_add_sleepdep() value upon success. |
63c85238 PW |
368 | */ |
369 | static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) | |
370 | { | |
371 | if (!oh->_clk) | |
372 | return -EINVAL; | |
373 | ||
55ed9694 | 374 | return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
63c85238 PW |
375 | } |
376 | ||
377 | /** | |
378 | * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active | |
379 | * @oh: struct omap_hwmod * | |
380 | * | |
381 | * Allow the hardware module @oh to enter idle while the hardare | |
382 | * module initiator @init_oh is active. Useful when a module will not | |
383 | * be accessed by a particular initiator (e.g., if a module will not | |
384 | * be accessed by the IVA, there should be no sleepdep between the IVA | |
385 | * initiator and the module). Only applies to modules in smart-idle | |
386 | * mode. Returns -EINVAL upon error or passes along | |
55ed9694 | 387 | * clkdm_del_sleepdep() value upon success. |
63c85238 PW |
388 | */ |
389 | static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) | |
390 | { | |
391 | if (!oh->_clk) | |
392 | return -EINVAL; | |
393 | ||
55ed9694 | 394 | return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
63c85238 PW |
395 | } |
396 | ||
397 | /** | |
398 | * _init_main_clk - get a struct clk * for the the hwmod's main functional clk | |
399 | * @oh: struct omap_hwmod * | |
400 | * | |
401 | * Called from _init_clocks(). Populates the @oh _clk (main | |
402 | * functional clock pointer) if a main_clk is present. Returns 0 on | |
403 | * success or -EINVAL on error. | |
404 | */ | |
405 | static int _init_main_clk(struct omap_hwmod *oh) | |
406 | { | |
407 | struct clk *c; | |
408 | int ret = 0; | |
409 | ||
50ebdac2 | 410 | if (!oh->main_clk) |
63c85238 PW |
411 | return 0; |
412 | ||
50ebdac2 | 413 | c = omap_clk_get_by_name(oh->main_clk); |
4d3ae5a9 | 414 | if (!c) |
20383d82 BC |
415 | pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n", |
416 | oh->name, oh->main_clk); | |
63c85238 PW |
417 | ret = -EINVAL; |
418 | oh->_clk = c; | |
419 | ||
81d7c6ff | 420 | WARN(!c->clkdm, "omap_hwmod: %s: missing clockdomain for %s.\n", |
50ebdac2 | 421 | oh->main_clk, c->name); |
81d7c6ff | 422 | |
63c85238 PW |
423 | return ret; |
424 | } | |
425 | ||
426 | /** | |
427 | * _init_interface_clk - get a struct clk * for the the hwmod's interface clks | |
428 | * @oh: struct omap_hwmod * | |
429 | * | |
430 | * Called from _init_clocks(). Populates the @oh OCP slave interface | |
431 | * clock pointers. Returns 0 on success or -EINVAL on error. | |
432 | */ | |
433 | static int _init_interface_clks(struct omap_hwmod *oh) | |
434 | { | |
63c85238 PW |
435 | struct clk *c; |
436 | int i; | |
437 | int ret = 0; | |
438 | ||
439 | if (oh->slaves_cnt == 0) | |
440 | return 0; | |
441 | ||
682fdc96 BC |
442 | for (i = 0; i < oh->slaves_cnt; i++) { |
443 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; | |
444 | ||
50ebdac2 | 445 | if (!os->clk) |
63c85238 PW |
446 | continue; |
447 | ||
50ebdac2 | 448 | c = omap_clk_get_by_name(os->clk); |
4d3ae5a9 | 449 | if (!c) |
20383d82 BC |
450 | pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n", |
451 | oh->name, os->clk); | |
63c85238 PW |
452 | ret = -EINVAL; |
453 | os->_clk = c; | |
454 | } | |
455 | ||
456 | return ret; | |
457 | } | |
458 | ||
459 | /** | |
460 | * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks | |
461 | * @oh: struct omap_hwmod * | |
462 | * | |
463 | * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk | |
464 | * clock pointers. Returns 0 on success or -EINVAL on error. | |
465 | */ | |
466 | static int _init_opt_clks(struct omap_hwmod *oh) | |
467 | { | |
468 | struct omap_hwmod_opt_clk *oc; | |
469 | struct clk *c; | |
470 | int i; | |
471 | int ret = 0; | |
472 | ||
473 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) { | |
50ebdac2 | 474 | c = omap_clk_get_by_name(oc->clk); |
4d3ae5a9 | 475 | if (!c) |
20383d82 BC |
476 | pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n", |
477 | oh->name, oc->clk); | |
63c85238 PW |
478 | ret = -EINVAL; |
479 | oc->_clk = c; | |
480 | } | |
481 | ||
482 | return ret; | |
483 | } | |
484 | ||
485 | /** | |
486 | * _enable_clocks - enable hwmod main clock and interface clocks | |
487 | * @oh: struct omap_hwmod * | |
488 | * | |
489 | * Enables all clocks necessary for register reads and writes to succeed | |
490 | * on the hwmod @oh. Returns 0. | |
491 | */ | |
492 | static int _enable_clocks(struct omap_hwmod *oh) | |
493 | { | |
63c85238 PW |
494 | int i; |
495 | ||
496 | pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); | |
497 | ||
4d3ae5a9 | 498 | if (oh->_clk) |
63c85238 PW |
499 | clk_enable(oh->_clk); |
500 | ||
501 | if (oh->slaves_cnt > 0) { | |
682fdc96 BC |
502 | for (i = 0; i < oh->slaves_cnt; i++) { |
503 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; | |
63c85238 PW |
504 | struct clk *c = os->_clk; |
505 | ||
4d3ae5a9 | 506 | if (c && (os->flags & OCPIF_SWSUP_IDLE)) |
63c85238 PW |
507 | clk_enable(c); |
508 | } | |
509 | } | |
510 | ||
511 | /* The opt clocks are controlled by the device driver. */ | |
512 | ||
513 | return 0; | |
514 | } | |
515 | ||
516 | /** | |
517 | * _disable_clocks - disable hwmod main clock and interface clocks | |
518 | * @oh: struct omap_hwmod * | |
519 | * | |
520 | * Disables the hwmod @oh main functional and interface clocks. Returns 0. | |
521 | */ | |
522 | static int _disable_clocks(struct omap_hwmod *oh) | |
523 | { | |
63c85238 PW |
524 | int i; |
525 | ||
526 | pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); | |
527 | ||
4d3ae5a9 | 528 | if (oh->_clk) |
63c85238 PW |
529 | clk_disable(oh->_clk); |
530 | ||
531 | if (oh->slaves_cnt > 0) { | |
682fdc96 BC |
532 | for (i = 0; i < oh->slaves_cnt; i++) { |
533 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; | |
63c85238 PW |
534 | struct clk *c = os->_clk; |
535 | ||
4d3ae5a9 | 536 | if (c && (os->flags & OCPIF_SWSUP_IDLE)) |
63c85238 PW |
537 | clk_disable(c); |
538 | } | |
539 | } | |
540 | ||
541 | /* The opt clocks are controlled by the device driver. */ | |
542 | ||
543 | return 0; | |
544 | } | |
545 | ||
546 | /** | |
547 | * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use | |
548 | * @oh: struct omap_hwmod * | |
549 | * | |
550 | * Returns the array index of the OCP slave port that the MPU | |
551 | * addresses the device on, or -EINVAL upon error or not found. | |
552 | */ | |
553 | static int _find_mpu_port_index(struct omap_hwmod *oh) | |
554 | { | |
63c85238 PW |
555 | int i; |
556 | int found = 0; | |
557 | ||
558 | if (!oh || oh->slaves_cnt == 0) | |
559 | return -EINVAL; | |
560 | ||
682fdc96 BC |
561 | for (i = 0; i < oh->slaves_cnt; i++) { |
562 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; | |
563 | ||
63c85238 PW |
564 | if (os->user & OCP_USER_MPU) { |
565 | found = 1; | |
566 | break; | |
567 | } | |
568 | } | |
569 | ||
570 | if (found) | |
571 | pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n", | |
572 | oh->name, i); | |
573 | else | |
574 | pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n", | |
575 | oh->name); | |
576 | ||
577 | return (found) ? i : -EINVAL; | |
578 | } | |
579 | ||
580 | /** | |
581 | * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU | |
582 | * @oh: struct omap_hwmod * | |
583 | * | |
584 | * Return the virtual address of the base of the register target of | |
585 | * device @oh, or NULL on error. | |
586 | */ | |
587 | static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index) | |
588 | { | |
589 | struct omap_hwmod_ocp_if *os; | |
590 | struct omap_hwmod_addr_space *mem; | |
591 | int i; | |
592 | int found = 0; | |
986a13f5 | 593 | void __iomem *va_start; |
63c85238 PW |
594 | |
595 | if (!oh || oh->slaves_cnt == 0) | |
596 | return NULL; | |
597 | ||
682fdc96 | 598 | os = oh->slaves[index]; |
63c85238 PW |
599 | |
600 | for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) { | |
601 | if (mem->flags & ADDR_TYPE_RT) { | |
602 | found = 1; | |
603 | break; | |
604 | } | |
605 | } | |
606 | ||
986a13f5 TL |
607 | if (found) { |
608 | va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start); | |
609 | if (!va_start) { | |
610 | pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name); | |
611 | return NULL; | |
612 | } | |
63c85238 | 613 | pr_debug("omap_hwmod: %s: MPU register target at va %p\n", |
986a13f5 TL |
614 | oh->name, va_start); |
615 | } else { | |
63c85238 PW |
616 | pr_debug("omap_hwmod: %s: no MPU register target found\n", |
617 | oh->name); | |
986a13f5 | 618 | } |
63c85238 | 619 | |
986a13f5 | 620 | return (found) ? va_start : NULL; |
63c85238 PW |
621 | } |
622 | ||
623 | /** | |
624 | * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG | |
625 | * @oh: struct omap_hwmod * | |
626 | * | |
627 | * If module is marked as SWSUP_SIDLE, force the module out of slave | |
628 | * idle; otherwise, configure it for smart-idle. If module is marked | |
629 | * as SWSUP_MSUSPEND, force the module out of master standby; | |
630 | * otherwise, configure it for smart-standby. No return value. | |
631 | */ | |
632 | static void _sysc_enable(struct omap_hwmod *oh) | |
633 | { | |
43b40992 | 634 | u8 idlemode, sf; |
63c85238 PW |
635 | u32 v; |
636 | ||
43b40992 | 637 | if (!oh->class->sysc) |
63c85238 PW |
638 | return; |
639 | ||
640 | v = oh->_sysc_cache; | |
43b40992 | 641 | sf = oh->class->sysc->sysc_flags; |
63c85238 | 642 | |
43b40992 | 643 | if (sf & SYSC_HAS_SIDLEMODE) { |
63c85238 PW |
644 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
645 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; | |
646 | _set_slave_idlemode(oh, idlemode, &v); | |
647 | } | |
648 | ||
43b40992 | 649 | if (sf & SYSC_HAS_MIDLEMODE) { |
63c85238 PW |
650 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
651 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; | |
652 | _set_master_standbymode(oh, idlemode, &v); | |
653 | } | |
654 | ||
43b40992 | 655 | if (sf & SYSC_HAS_AUTOIDLE) { |
726072e5 PW |
656 | idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ? |
657 | 0 : 1; | |
658 | _set_module_autoidle(oh, idlemode, &v); | |
659 | } | |
660 | ||
661 | /* XXX OCP ENAWAKEUP bit? */ | |
63c85238 | 662 | |
a16b1f7f PW |
663 | /* |
664 | * XXX The clock framework should handle this, by | |
665 | * calling into this code. But this must wait until the | |
666 | * clock structures are tagged with omap_hwmod entries | |
667 | */ | |
43b40992 PW |
668 | if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) && |
669 | (sf & SYSC_HAS_CLOCKACTIVITY)) | |
670 | _set_clockactivity(oh, oh->class->sysc->clockact, &v); | |
63c85238 PW |
671 | |
672 | _write_sysconfig(v, oh); | |
673 | } | |
674 | ||
675 | /** | |
676 | * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG | |
677 | * @oh: struct omap_hwmod * | |
678 | * | |
679 | * If module is marked as SWSUP_SIDLE, force the module into slave | |
680 | * idle; otherwise, configure it for smart-idle. If module is marked | |
681 | * as SWSUP_MSUSPEND, force the module into master standby; otherwise, | |
682 | * configure it for smart-standby. No return value. | |
683 | */ | |
684 | static void _sysc_idle(struct omap_hwmod *oh) | |
685 | { | |
43b40992 | 686 | u8 idlemode, sf; |
63c85238 PW |
687 | u32 v; |
688 | ||
43b40992 | 689 | if (!oh->class->sysc) |
63c85238 PW |
690 | return; |
691 | ||
692 | v = oh->_sysc_cache; | |
43b40992 | 693 | sf = oh->class->sysc->sysc_flags; |
63c85238 | 694 | |
43b40992 | 695 | if (sf & SYSC_HAS_SIDLEMODE) { |
63c85238 PW |
696 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
697 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; | |
698 | _set_slave_idlemode(oh, idlemode, &v); | |
699 | } | |
700 | ||
43b40992 | 701 | if (sf & SYSC_HAS_MIDLEMODE) { |
63c85238 PW |
702 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
703 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; | |
704 | _set_master_standbymode(oh, idlemode, &v); | |
705 | } | |
706 | ||
707 | _write_sysconfig(v, oh); | |
708 | } | |
709 | ||
710 | /** | |
711 | * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG | |
712 | * @oh: struct omap_hwmod * | |
713 | * | |
714 | * Force the module into slave idle and master suspend. No return | |
715 | * value. | |
716 | */ | |
717 | static void _sysc_shutdown(struct omap_hwmod *oh) | |
718 | { | |
719 | u32 v; | |
43b40992 | 720 | u8 sf; |
63c85238 | 721 | |
43b40992 | 722 | if (!oh->class->sysc) |
63c85238 PW |
723 | return; |
724 | ||
725 | v = oh->_sysc_cache; | |
43b40992 | 726 | sf = oh->class->sysc->sysc_flags; |
63c85238 | 727 | |
43b40992 | 728 | if (sf & SYSC_HAS_SIDLEMODE) |
63c85238 PW |
729 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v); |
730 | ||
43b40992 | 731 | if (sf & SYSC_HAS_MIDLEMODE) |
63c85238 PW |
732 | _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v); |
733 | ||
43b40992 | 734 | if (sf & SYSC_HAS_AUTOIDLE) |
726072e5 | 735 | _set_module_autoidle(oh, 1, &v); |
63c85238 PW |
736 | |
737 | _write_sysconfig(v, oh); | |
738 | } | |
739 | ||
740 | /** | |
741 | * _lookup - find an omap_hwmod by name | |
742 | * @name: find an omap_hwmod by name | |
743 | * | |
744 | * Return a pointer to an omap_hwmod by name, or NULL if not found. | |
745 | * Caller must hold omap_hwmod_mutex. | |
746 | */ | |
747 | static struct omap_hwmod *_lookup(const char *name) | |
748 | { | |
749 | struct omap_hwmod *oh, *temp_oh; | |
750 | ||
751 | oh = NULL; | |
752 | ||
753 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { | |
754 | if (!strcmp(name, temp_oh->name)) { | |
755 | oh = temp_oh; | |
756 | break; | |
757 | } | |
758 | } | |
759 | ||
760 | return oh; | |
761 | } | |
762 | ||
763 | /** | |
764 | * _init_clocks - clk_get() all clocks associated with this hwmod | |
765 | * @oh: struct omap_hwmod * | |
766 | * | |
767 | * Called by omap_hwmod_late_init() (after omap2_clk_init()). | |
768 | * Resolves all clock names embedded in the hwmod. Must be called | |
769 | * with omap_hwmod_mutex held. Returns -EINVAL if the omap_hwmod | |
770 | * has not yet been registered or if the clocks have already been | |
771 | * initialized, 0 on success, or a non-zero error on failure. | |
772 | */ | |
773 | static int _init_clocks(struct omap_hwmod *oh) | |
774 | { | |
775 | int ret = 0; | |
776 | ||
777 | if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED)) | |
778 | return -EINVAL; | |
779 | ||
780 | pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name); | |
781 | ||
782 | ret |= _init_main_clk(oh); | |
783 | ret |= _init_interface_clks(oh); | |
784 | ret |= _init_opt_clks(oh); | |
785 | ||
f5c1f84b BC |
786 | if (!ret) |
787 | oh->_state = _HWMOD_STATE_CLKS_INITED; | |
63c85238 | 788 | |
f5c1f84b | 789 | return 0; |
63c85238 PW |
790 | } |
791 | ||
792 | /** | |
793 | * _wait_target_ready - wait for a module to leave slave idle | |
794 | * @oh: struct omap_hwmod * | |
795 | * | |
796 | * Wait for a module @oh to leave slave idle. Returns 0 if the module | |
797 | * does not have an IDLEST bit or if the module successfully leaves | |
798 | * slave idle; otherwise, pass along the return value of the | |
799 | * appropriate *_cm_wait_module_ready() function. | |
800 | */ | |
801 | static int _wait_target_ready(struct omap_hwmod *oh) | |
802 | { | |
803 | struct omap_hwmod_ocp_if *os; | |
804 | int ret; | |
805 | ||
806 | if (!oh) | |
807 | return -EINVAL; | |
808 | ||
809 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) | |
810 | return 0; | |
811 | ||
682fdc96 | 812 | os = oh->slaves[oh->_mpu_port_index]; |
63c85238 | 813 | |
33f7ec81 | 814 | if (oh->flags & HWMOD_NO_IDLEST) |
63c85238 PW |
815 | return 0; |
816 | ||
817 | /* XXX check module SIDLEMODE */ | |
818 | ||
819 | /* XXX check clock enable states */ | |
820 | ||
821 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { | |
822 | ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs, | |
823 | oh->prcm.omap2.idlest_reg_id, | |
824 | oh->prcm.omap2.idlest_idle_bit); | |
63c85238 | 825 | } else if (cpu_is_omap44xx()) { |
9a23dfe1 | 826 | ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg); |
63c85238 PW |
827 | } else { |
828 | BUG(); | |
829 | }; | |
830 | ||
831 | return ret; | |
832 | } | |
833 | ||
834 | /** | |
835 | * _reset - reset an omap_hwmod | |
836 | * @oh: struct omap_hwmod * | |
837 | * | |
838 | * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be | |
839 | * enabled for this to work. Must be called with omap_hwmod_mutex | |
840 | * held. Returns -EINVAL if the hwmod cannot be reset this way or if | |
841 | * the hwmod is in the wrong state, -ETIMEDOUT if the module did not | |
842 | * reset in time, or 0 upon success. | |
843 | */ | |
844 | static int _reset(struct omap_hwmod *oh) | |
845 | { | |
846 | u32 r, v; | |
6f8b7ff5 | 847 | int c = 0; |
63c85238 | 848 | |
43b40992 PW |
849 | if (!oh->class->sysc || |
850 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET) || | |
851 | (oh->class->sysc->sysc_flags & SYSS_MISSING)) | |
63c85238 PW |
852 | return -EINVAL; |
853 | ||
854 | /* clocks must be on for this operation */ | |
855 | if (oh->_state != _HWMOD_STATE_ENABLED) { | |
856 | WARN(1, "omap_hwmod: %s: reset can only be entered from " | |
857 | "enabled state\n", oh->name); | |
858 | return -EINVAL; | |
859 | } | |
860 | ||
861 | pr_debug("omap_hwmod: %s: resetting\n", oh->name); | |
862 | ||
863 | v = oh->_sysc_cache; | |
864 | r = _set_softreset(oh, &v); | |
865 | if (r) | |
866 | return r; | |
867 | _write_sysconfig(v, oh); | |
868 | ||
43b40992 | 869 | omap_test_timeout((omap_hwmod_readl(oh, oh->class->sysc->syss_offs) & |
6f8b7ff5 PW |
870 | SYSS_RESETDONE_MASK), |
871 | MAX_MODULE_RESET_WAIT, c); | |
63c85238 PW |
872 | |
873 | if (c == MAX_MODULE_RESET_WAIT) | |
874 | WARN(1, "omap_hwmod: %s: failed to reset in %d usec\n", | |
875 | oh->name, MAX_MODULE_RESET_WAIT); | |
876 | else | |
02bfc030 | 877 | pr_debug("omap_hwmod: %s: reset in %d usec\n", oh->name, c); |
63c85238 PW |
878 | |
879 | /* | |
880 | * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from | |
881 | * _wait_target_ready() or _reset() | |
882 | */ | |
883 | ||
884 | return (c == MAX_MODULE_RESET_WAIT) ? -ETIMEDOUT : 0; | |
885 | } | |
886 | ||
887 | /** | |
888 | * _enable - enable an omap_hwmod | |
889 | * @oh: struct omap_hwmod * | |
890 | * | |
891 | * Enables an omap_hwmod @oh such that the MPU can access the hwmod's | |
892 | * register target. Must be called with omap_hwmod_mutex held. | |
893 | * Returns -EINVAL if the hwmod is in the wrong state or passes along | |
894 | * the return value of _wait_target_ready(). | |
895 | */ | |
896 | static int _enable(struct omap_hwmod *oh) | |
897 | { | |
898 | int r; | |
899 | ||
900 | if (oh->_state != _HWMOD_STATE_INITIALIZED && | |
901 | oh->_state != _HWMOD_STATE_IDLE && | |
902 | oh->_state != _HWMOD_STATE_DISABLED) { | |
903 | WARN(1, "omap_hwmod: %s: enabled state can only be entered " | |
904 | "from initialized, idle, or disabled state\n", oh->name); | |
905 | return -EINVAL; | |
906 | } | |
907 | ||
908 | pr_debug("omap_hwmod: %s: enabling\n", oh->name); | |
909 | ||
910 | /* XXX mux balls */ | |
911 | ||
912 | _add_initiator_dep(oh, mpu_oh); | |
913 | _enable_clocks(oh); | |
914 | ||
63c85238 | 915 | r = _wait_target_ready(oh); |
9a23dfe1 | 916 | if (!r) { |
63c85238 PW |
917 | oh->_state = _HWMOD_STATE_ENABLED; |
918 | ||
9a23dfe1 BC |
919 | /* Access the sysconfig only if the target is ready */ |
920 | if (oh->class->sysc) { | |
921 | if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED)) | |
922 | _update_sysc_cache(oh); | |
923 | _sysc_enable(oh); | |
924 | } | |
925 | } else { | |
926 | pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n", | |
927 | oh->name, r); | |
928 | } | |
929 | ||
63c85238 PW |
930 | return r; |
931 | } | |
932 | ||
933 | /** | |
934 | * _idle - idle an omap_hwmod | |
935 | * @oh: struct omap_hwmod * | |
936 | * | |
937 | * Idles an omap_hwmod @oh. This should be called once the hwmod has | |
938 | * no further work. Returns -EINVAL if the hwmod is in the wrong | |
939 | * state or returns 0. | |
940 | */ | |
941 | static int _idle(struct omap_hwmod *oh) | |
942 | { | |
943 | if (oh->_state != _HWMOD_STATE_ENABLED) { | |
944 | WARN(1, "omap_hwmod: %s: idle state can only be entered from " | |
945 | "enabled state\n", oh->name); | |
946 | return -EINVAL; | |
947 | } | |
948 | ||
949 | pr_debug("omap_hwmod: %s: idling\n", oh->name); | |
950 | ||
43b40992 | 951 | if (oh->class->sysc) |
63c85238 PW |
952 | _sysc_idle(oh); |
953 | _del_initiator_dep(oh, mpu_oh); | |
954 | _disable_clocks(oh); | |
955 | ||
956 | oh->_state = _HWMOD_STATE_IDLE; | |
957 | ||
958 | return 0; | |
959 | } | |
960 | ||
961 | /** | |
962 | * _shutdown - shutdown an omap_hwmod | |
963 | * @oh: struct omap_hwmod * | |
964 | * | |
965 | * Shut down an omap_hwmod @oh. This should be called when the driver | |
966 | * used for the hwmod is removed or unloaded or if the driver is not | |
967 | * used by the system. Returns -EINVAL if the hwmod is in the wrong | |
968 | * state or returns 0. | |
969 | */ | |
970 | static int _shutdown(struct omap_hwmod *oh) | |
971 | { | |
972 | if (oh->_state != _HWMOD_STATE_IDLE && | |
973 | oh->_state != _HWMOD_STATE_ENABLED) { | |
974 | WARN(1, "omap_hwmod: %s: disabled state can only be entered " | |
975 | "from idle, or enabled state\n", oh->name); | |
976 | return -EINVAL; | |
977 | } | |
978 | ||
979 | pr_debug("omap_hwmod: %s: disabling\n", oh->name); | |
980 | ||
43b40992 | 981 | if (oh->class->sysc) |
63c85238 PW |
982 | _sysc_shutdown(oh); |
983 | _del_initiator_dep(oh, mpu_oh); | |
984 | /* XXX what about the other system initiators here? DMA, tesla, d2d */ | |
985 | _disable_clocks(oh); | |
986 | /* XXX Should this code also force-disable the optional clocks? */ | |
987 | ||
988 | /* XXX mux any associated balls to safe mode */ | |
989 | ||
990 | oh->_state = _HWMOD_STATE_DISABLED; | |
991 | ||
992 | return 0; | |
993 | } | |
994 | ||
63c85238 PW |
995 | /** |
996 | * _setup - do initial configuration of omap_hwmod | |
997 | * @oh: struct omap_hwmod * | |
998 | * | |
999 | * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh | |
1000 | * OCP_SYSCONFIG register. Must be called with omap_hwmod_mutex | |
1001 | * held. Returns -EINVAL if the hwmod is in the wrong state or returns | |
1002 | * 0. | |
1003 | */ | |
1004 | static int _setup(struct omap_hwmod *oh) | |
1005 | { | |
9a23dfe1 | 1006 | int i, r; |
63c85238 PW |
1007 | |
1008 | if (!oh) | |
1009 | return -EINVAL; | |
1010 | ||
1011 | /* Set iclk autoidle mode */ | |
1012 | if (oh->slaves_cnt > 0) { | |
682fdc96 BC |
1013 | for (i = 0; i < oh->slaves_cnt; i++) { |
1014 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; | |
63c85238 PW |
1015 | struct clk *c = os->_clk; |
1016 | ||
4d3ae5a9 | 1017 | if (!c) |
63c85238 PW |
1018 | continue; |
1019 | ||
1020 | if (os->flags & OCPIF_SWSUP_IDLE) { | |
1021 | /* XXX omap_iclk_deny_idle(c); */ | |
1022 | } else { | |
1023 | /* XXX omap_iclk_allow_idle(c); */ | |
1024 | clk_enable(c); | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | ||
1029 | oh->_state = _HWMOD_STATE_INITIALIZED; | |
1030 | ||
9a23dfe1 BC |
1031 | r = _enable(oh); |
1032 | if (r) { | |
1033 | pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n", | |
1034 | oh->name, oh->_state); | |
1035 | return 0; | |
1036 | } | |
63c85238 | 1037 | |
b835d014 PW |
1038 | if (!(oh->flags & HWMOD_INIT_NO_RESET)) { |
1039 | /* | |
1040 | * XXX Do the OCP_SYSCONFIG bits need to be | |
1041 | * reprogrammed after a reset? If not, then this can | |
1042 | * be removed. If they do, then probably the | |
1043 | * _enable() function should be split to avoid the | |
1044 | * rewrite of the OCP_SYSCONFIG register. | |
1045 | */ | |
43b40992 | 1046 | if (oh->class->sysc) { |
b835d014 PW |
1047 | _update_sysc_cache(oh); |
1048 | _sysc_enable(oh); | |
1049 | } | |
1050 | } | |
63c85238 PW |
1051 | |
1052 | if (!(oh->flags & HWMOD_INIT_NO_IDLE)) | |
1053 | _idle(oh); | |
1054 | ||
1055 | return 0; | |
1056 | } | |
1057 | ||
1058 | ||
1059 | ||
1060 | /* Public functions */ | |
1061 | ||
1062 | u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs) | |
1063 | { | |
1064 | return __raw_readl(oh->_rt_va + reg_offs); | |
1065 | } | |
1066 | ||
1067 | void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs) | |
1068 | { | |
1069 | __raw_writel(v, oh->_rt_va + reg_offs); | |
1070 | } | |
1071 | ||
46273e6f KH |
1072 | int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode) |
1073 | { | |
1074 | u32 v; | |
1075 | int retval = 0; | |
1076 | ||
1077 | if (!oh) | |
1078 | return -EINVAL; | |
1079 | ||
1080 | v = oh->_sysc_cache; | |
1081 | ||
1082 | retval = _set_slave_idlemode(oh, idlemode, &v); | |
1083 | if (!retval) | |
1084 | _write_sysconfig(v, oh); | |
1085 | ||
1086 | return retval; | |
1087 | } | |
1088 | ||
63c85238 PW |
1089 | /** |
1090 | * omap_hwmod_register - register a struct omap_hwmod | |
1091 | * @oh: struct omap_hwmod * | |
1092 | * | |
43b40992 PW |
1093 | * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod |
1094 | * already has been registered by the same name; -EINVAL if the | |
1095 | * omap_hwmod is in the wrong state, if @oh is NULL, if the | |
1096 | * omap_hwmod's class field is NULL; if the omap_hwmod is missing a | |
1097 | * name, or if the omap_hwmod's class is missing a name; or 0 upon | |
1098 | * success. | |
63c85238 PW |
1099 | * |
1100 | * XXX The data should be copied into bootmem, so the original data | |
1101 | * should be marked __initdata and freed after init. This would allow | |
1102 | * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note | |
1103 | * that the copy process would be relatively complex due to the large number | |
1104 | * of substructures. | |
1105 | */ | |
1106 | int omap_hwmod_register(struct omap_hwmod *oh) | |
1107 | { | |
1108 | int ret, ms_id; | |
1109 | ||
43b40992 PW |
1110 | if (!oh || !oh->name || !oh->class || !oh->class->name || |
1111 | (oh->_state != _HWMOD_STATE_UNKNOWN)) | |
63c85238 PW |
1112 | return -EINVAL; |
1113 | ||
1114 | mutex_lock(&omap_hwmod_mutex); | |
1115 | ||
1116 | pr_debug("omap_hwmod: %s: registering\n", oh->name); | |
1117 | ||
1118 | if (_lookup(oh->name)) { | |
1119 | ret = -EEXIST; | |
1120 | goto ohr_unlock; | |
1121 | } | |
1122 | ||
1123 | ms_id = _find_mpu_port_index(oh); | |
1124 | if (!IS_ERR_VALUE(ms_id)) { | |
1125 | oh->_mpu_port_index = ms_id; | |
1126 | oh->_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index); | |
1127 | } else { | |
1128 | oh->_int_flags |= _HWMOD_NO_MPU_PORT; | |
1129 | } | |
1130 | ||
1131 | list_add_tail(&oh->node, &omap_hwmod_list); | |
1132 | ||
1133 | oh->_state = _HWMOD_STATE_REGISTERED; | |
1134 | ||
1135 | ret = 0; | |
1136 | ||
1137 | ohr_unlock: | |
1138 | mutex_unlock(&omap_hwmod_mutex); | |
1139 | return ret; | |
1140 | } | |
1141 | ||
1142 | /** | |
1143 | * omap_hwmod_lookup - look up a registered omap_hwmod by name | |
1144 | * @name: name of the omap_hwmod to look up | |
1145 | * | |
1146 | * Given a @name of an omap_hwmod, return a pointer to the registered | |
1147 | * struct omap_hwmod *, or NULL upon error. | |
1148 | */ | |
1149 | struct omap_hwmod *omap_hwmod_lookup(const char *name) | |
1150 | { | |
1151 | struct omap_hwmod *oh; | |
1152 | ||
1153 | if (!name) | |
1154 | return NULL; | |
1155 | ||
1156 | mutex_lock(&omap_hwmod_mutex); | |
1157 | oh = _lookup(name); | |
1158 | mutex_unlock(&omap_hwmod_mutex); | |
1159 | ||
1160 | return oh; | |
1161 | } | |
1162 | ||
1163 | /** | |
1164 | * omap_hwmod_for_each - call function for each registered omap_hwmod | |
1165 | * @fn: pointer to a callback function | |
1166 | * | |
1167 | * Call @fn for each registered omap_hwmod, passing @data to each | |
1168 | * function. @fn must return 0 for success or any other value for | |
1169 | * failure. If @fn returns non-zero, the iteration across omap_hwmods | |
1170 | * will stop and the non-zero return value will be passed to the | |
1171 | * caller of omap_hwmod_for_each(). @fn is called with | |
1172 | * omap_hwmod_for_each() held. | |
1173 | */ | |
1174 | int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh)) | |
1175 | { | |
1176 | struct omap_hwmod *temp_oh; | |
1177 | int ret; | |
1178 | ||
1179 | if (!fn) | |
1180 | return -EINVAL; | |
1181 | ||
1182 | mutex_lock(&omap_hwmod_mutex); | |
1183 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { | |
1184 | ret = (*fn)(temp_oh); | |
1185 | if (ret) | |
1186 | break; | |
1187 | } | |
1188 | mutex_unlock(&omap_hwmod_mutex); | |
1189 | ||
1190 | return ret; | |
1191 | } | |
1192 | ||
1193 | ||
1194 | /** | |
1195 | * omap_hwmod_init - init omap_hwmod code and register hwmods | |
1196 | * @ohs: pointer to an array of omap_hwmods to register | |
1197 | * | |
1198 | * Intended to be called early in boot before the clock framework is | |
1199 | * initialized. If @ohs is not null, will register all omap_hwmods | |
1200 | * listed in @ohs that are valid for this chip. Returns -EINVAL if | |
1201 | * omap_hwmod_init() has already been called or 0 otherwise. | |
1202 | */ | |
1203 | int omap_hwmod_init(struct omap_hwmod **ohs) | |
1204 | { | |
1205 | struct omap_hwmod *oh; | |
1206 | int r; | |
1207 | ||
1208 | if (inited) | |
1209 | return -EINVAL; | |
1210 | ||
1211 | inited = 1; | |
1212 | ||
1213 | if (!ohs) | |
1214 | return 0; | |
1215 | ||
1216 | oh = *ohs; | |
1217 | while (oh) { | |
1218 | if (omap_chip_is(oh->omap_chip)) { | |
1219 | r = omap_hwmod_register(oh); | |
1220 | WARN(r, "omap_hwmod: %s: omap_hwmod_register returned " | |
1221 | "%d\n", oh->name, r); | |
1222 | } | |
1223 | oh = *++ohs; | |
1224 | } | |
1225 | ||
1226 | return 0; | |
1227 | } | |
1228 | ||
1229 | /** | |
1230 | * omap_hwmod_late_init - do some post-clock framework initialization | |
1231 | * | |
1232 | * Must be called after omap2_clk_init(). Resolves the struct clk names | |
1233 | * to struct clk pointers for each registered omap_hwmod. Also calls | |
1234 | * _setup() on each hwmod. Returns 0. | |
1235 | */ | |
1236 | int omap_hwmod_late_init(void) | |
1237 | { | |
1238 | int r; | |
1239 | ||
1240 | /* XXX check return value */ | |
1241 | r = omap_hwmod_for_each(_init_clocks); | |
1242 | WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n"); | |
1243 | ||
1244 | mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME); | |
1245 | WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n", | |
1246 | MPU_INITIATOR_NAME); | |
1247 | ||
1248 | omap_hwmod_for_each(_setup); | |
1249 | ||
1250 | return 0; | |
1251 | } | |
1252 | ||
1253 | /** | |
1254 | * omap_hwmod_unregister - unregister an omap_hwmod | |
1255 | * @oh: struct omap_hwmod * | |
1256 | * | |
1257 | * Unregisters a previously-registered omap_hwmod @oh. There's probably | |
1258 | * no use case for this, so it is likely to be removed in a later version. | |
1259 | * | |
1260 | * XXX Free all of the bootmem-allocated structures here when that is | |
1261 | * implemented. Make it clear that core code is the only code that is | |
1262 | * expected to unregister modules. | |
1263 | */ | |
1264 | int omap_hwmod_unregister(struct omap_hwmod *oh) | |
1265 | { | |
1266 | if (!oh) | |
1267 | return -EINVAL; | |
1268 | ||
1269 | pr_debug("omap_hwmod: %s: unregistering\n", oh->name); | |
1270 | ||
1271 | mutex_lock(&omap_hwmod_mutex); | |
986a13f5 | 1272 | iounmap(oh->_rt_va); |
63c85238 PW |
1273 | list_del(&oh->node); |
1274 | mutex_unlock(&omap_hwmod_mutex); | |
1275 | ||
1276 | return 0; | |
1277 | } | |
1278 | ||
1279 | /** | |
1280 | * omap_hwmod_enable - enable an omap_hwmod | |
1281 | * @oh: struct omap_hwmod * | |
1282 | * | |
1283 | * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable(). | |
1284 | * Returns -EINVAL on error or passes along the return value from _enable(). | |
1285 | */ | |
1286 | int omap_hwmod_enable(struct omap_hwmod *oh) | |
1287 | { | |
1288 | int r; | |
1289 | ||
1290 | if (!oh) | |
1291 | return -EINVAL; | |
1292 | ||
1293 | mutex_lock(&omap_hwmod_mutex); | |
1294 | r = _enable(oh); | |
1295 | mutex_unlock(&omap_hwmod_mutex); | |
1296 | ||
1297 | return r; | |
1298 | } | |
1299 | ||
1300 | /** | |
1301 | * omap_hwmod_idle - idle an omap_hwmod | |
1302 | * @oh: struct omap_hwmod * | |
1303 | * | |
1304 | * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle(). | |
1305 | * Returns -EINVAL on error or passes along the return value from _idle(). | |
1306 | */ | |
1307 | int omap_hwmod_idle(struct omap_hwmod *oh) | |
1308 | { | |
1309 | if (!oh) | |
1310 | return -EINVAL; | |
1311 | ||
1312 | mutex_lock(&omap_hwmod_mutex); | |
1313 | _idle(oh); | |
1314 | mutex_unlock(&omap_hwmod_mutex); | |
1315 | ||
1316 | return 0; | |
1317 | } | |
1318 | ||
1319 | /** | |
1320 | * omap_hwmod_shutdown - shutdown an omap_hwmod | |
1321 | * @oh: struct omap_hwmod * | |
1322 | * | |
1323 | * Shutdown an omap_hwomd @oh. Intended to be called by | |
1324 | * omap_device_shutdown(). Returns -EINVAL on error or passes along | |
1325 | * the return value from _shutdown(). | |
1326 | */ | |
1327 | int omap_hwmod_shutdown(struct omap_hwmod *oh) | |
1328 | { | |
1329 | if (!oh) | |
1330 | return -EINVAL; | |
1331 | ||
1332 | mutex_lock(&omap_hwmod_mutex); | |
1333 | _shutdown(oh); | |
1334 | mutex_unlock(&omap_hwmod_mutex); | |
1335 | ||
1336 | return 0; | |
1337 | } | |
1338 | ||
1339 | /** | |
1340 | * omap_hwmod_enable_clocks - enable main_clk, all interface clocks | |
1341 | * @oh: struct omap_hwmod *oh | |
1342 | * | |
1343 | * Intended to be called by the omap_device code. | |
1344 | */ | |
1345 | int omap_hwmod_enable_clocks(struct omap_hwmod *oh) | |
1346 | { | |
1347 | mutex_lock(&omap_hwmod_mutex); | |
1348 | _enable_clocks(oh); | |
1349 | mutex_unlock(&omap_hwmod_mutex); | |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | /** | |
1355 | * omap_hwmod_disable_clocks - disable main_clk, all interface clocks | |
1356 | * @oh: struct omap_hwmod *oh | |
1357 | * | |
1358 | * Intended to be called by the omap_device code. | |
1359 | */ | |
1360 | int omap_hwmod_disable_clocks(struct omap_hwmod *oh) | |
1361 | { | |
1362 | mutex_lock(&omap_hwmod_mutex); | |
1363 | _disable_clocks(oh); | |
1364 | mutex_unlock(&omap_hwmod_mutex); | |
1365 | ||
1366 | return 0; | |
1367 | } | |
1368 | ||
1369 | /** | |
1370 | * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete | |
1371 | * @oh: struct omap_hwmod *oh | |
1372 | * | |
1373 | * Intended to be called by drivers and core code when all posted | |
1374 | * writes to a device must complete before continuing further | |
1375 | * execution (for example, after clearing some device IRQSTATUS | |
1376 | * register bits) | |
1377 | * | |
1378 | * XXX what about targets with multiple OCP threads? | |
1379 | */ | |
1380 | void omap_hwmod_ocp_barrier(struct omap_hwmod *oh) | |
1381 | { | |
1382 | BUG_ON(!oh); | |
1383 | ||
43b40992 | 1384 | if (!oh->class->sysc || !oh->class->sysc->sysc_flags) { |
63c85238 PW |
1385 | WARN(1, "omap_device: %s: OCP barrier impossible due to " |
1386 | "device configuration\n", oh->name); | |
1387 | return; | |
1388 | } | |
1389 | ||
1390 | /* | |
1391 | * Forces posted writes to complete on the OCP thread handling | |
1392 | * register writes | |
1393 | */ | |
43b40992 | 1394 | omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); |
63c85238 PW |
1395 | } |
1396 | ||
1397 | /** | |
1398 | * omap_hwmod_reset - reset the hwmod | |
1399 | * @oh: struct omap_hwmod * | |
1400 | * | |
1401 | * Under some conditions, a driver may wish to reset the entire device. | |
1402 | * Called from omap_device code. Returns -EINVAL on error or passes along | |
1403 | * the return value from _reset()/_enable(). | |
1404 | */ | |
1405 | int omap_hwmod_reset(struct omap_hwmod *oh) | |
1406 | { | |
1407 | int r; | |
1408 | ||
1409 | if (!oh || !(oh->_state & _HWMOD_STATE_ENABLED)) | |
1410 | return -EINVAL; | |
1411 | ||
1412 | mutex_lock(&omap_hwmod_mutex); | |
1413 | r = _reset(oh); | |
1414 | if (!r) | |
1415 | r = _enable(oh); | |
1416 | mutex_unlock(&omap_hwmod_mutex); | |
1417 | ||
1418 | return r; | |
1419 | } | |
1420 | ||
1421 | /** | |
1422 | * omap_hwmod_count_resources - count number of struct resources needed by hwmod | |
1423 | * @oh: struct omap_hwmod * | |
1424 | * @res: pointer to the first element of an array of struct resource to fill | |
1425 | * | |
1426 | * Count the number of struct resource array elements necessary to | |
1427 | * contain omap_hwmod @oh resources. Intended to be called by code | |
1428 | * that registers omap_devices. Intended to be used to determine the | |
1429 | * size of a dynamically-allocated struct resource array, before | |
1430 | * calling omap_hwmod_fill_resources(). Returns the number of struct | |
1431 | * resource array elements needed. | |
1432 | * | |
1433 | * XXX This code is not optimized. It could attempt to merge adjacent | |
1434 | * resource IDs. | |
1435 | * | |
1436 | */ | |
1437 | int omap_hwmod_count_resources(struct omap_hwmod *oh) | |
1438 | { | |
1439 | int ret, i; | |
1440 | ||
1441 | ret = oh->mpu_irqs_cnt + oh->sdma_chs_cnt; | |
1442 | ||
1443 | for (i = 0; i < oh->slaves_cnt; i++) | |
682fdc96 | 1444 | ret += oh->slaves[i]->addr_cnt; |
63c85238 PW |
1445 | |
1446 | return ret; | |
1447 | } | |
1448 | ||
1449 | /** | |
1450 | * omap_hwmod_fill_resources - fill struct resource array with hwmod data | |
1451 | * @oh: struct omap_hwmod * | |
1452 | * @res: pointer to the first element of an array of struct resource to fill | |
1453 | * | |
1454 | * Fill the struct resource array @res with resource data from the | |
1455 | * omap_hwmod @oh. Intended to be called by code that registers | |
1456 | * omap_devices. See also omap_hwmod_count_resources(). Returns the | |
1457 | * number of array elements filled. | |
1458 | */ | |
1459 | int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) | |
1460 | { | |
1461 | int i, j; | |
1462 | int r = 0; | |
1463 | ||
1464 | /* For each IRQ, DMA, memory area, fill in array.*/ | |
1465 | ||
1466 | for (i = 0; i < oh->mpu_irqs_cnt; i++) { | |
718bfd76 PW |
1467 | (res + r)->name = (oh->mpu_irqs + i)->name; |
1468 | (res + r)->start = (oh->mpu_irqs + i)->irq; | |
1469 | (res + r)->end = (oh->mpu_irqs + i)->irq; | |
63c85238 PW |
1470 | (res + r)->flags = IORESOURCE_IRQ; |
1471 | r++; | |
1472 | } | |
1473 | ||
1474 | for (i = 0; i < oh->sdma_chs_cnt; i++) { | |
1475 | (res + r)->name = (oh->sdma_chs + i)->name; | |
1476 | (res + r)->start = (oh->sdma_chs + i)->dma_ch; | |
1477 | (res + r)->end = (oh->sdma_chs + i)->dma_ch; | |
1478 | (res + r)->flags = IORESOURCE_DMA; | |
1479 | r++; | |
1480 | } | |
1481 | ||
1482 | for (i = 0; i < oh->slaves_cnt; i++) { | |
1483 | struct omap_hwmod_ocp_if *os; | |
1484 | ||
682fdc96 | 1485 | os = oh->slaves[i]; |
63c85238 PW |
1486 | |
1487 | for (j = 0; j < os->addr_cnt; j++) { | |
1488 | (res + r)->start = (os->addr + j)->pa_start; | |
1489 | (res + r)->end = (os->addr + j)->pa_end; | |
1490 | (res + r)->flags = IORESOURCE_MEM; | |
1491 | r++; | |
1492 | } | |
1493 | } | |
1494 | ||
1495 | return r; | |
1496 | } | |
1497 | ||
1498 | /** | |
1499 | * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain | |
1500 | * @oh: struct omap_hwmod * | |
1501 | * | |
1502 | * Return the powerdomain pointer associated with the OMAP module | |
1503 | * @oh's main clock. If @oh does not have a main clk, return the | |
1504 | * powerdomain associated with the interface clock associated with the | |
1505 | * module's MPU port. (XXX Perhaps this should use the SDMA port | |
1506 | * instead?) Returns NULL on error, or a struct powerdomain * on | |
1507 | * success. | |
1508 | */ | |
1509 | struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh) | |
1510 | { | |
1511 | struct clk *c; | |
1512 | ||
1513 | if (!oh) | |
1514 | return NULL; | |
1515 | ||
1516 | if (oh->_clk) { | |
1517 | c = oh->_clk; | |
1518 | } else { | |
1519 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) | |
1520 | return NULL; | |
1521 | c = oh->slaves[oh->_mpu_port_index]->_clk; | |
1522 | } | |
1523 | ||
d5647c18 TG |
1524 | if (!c->clkdm) |
1525 | return NULL; | |
1526 | ||
63c85238 PW |
1527 | return c->clkdm->pwrdm.ptr; |
1528 | ||
1529 | } | |
1530 | ||
1531 | /** | |
1532 | * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh | |
1533 | * @oh: struct omap_hwmod * | |
1534 | * @init_oh: struct omap_hwmod * (initiator) | |
1535 | * | |
1536 | * Add a sleep dependency between the initiator @init_oh and @oh. | |
1537 | * Intended to be called by DSP/Bridge code via platform_data for the | |
1538 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge | |
1539 | * code needs to add/del initiator dependencies dynamically | |
1540 | * before/after accessing a device. Returns the return value from | |
1541 | * _add_initiator_dep(). | |
1542 | * | |
1543 | * XXX Keep a usecount in the clockdomain code | |
1544 | */ | |
1545 | int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh, | |
1546 | struct omap_hwmod *init_oh) | |
1547 | { | |
1548 | return _add_initiator_dep(oh, init_oh); | |
1549 | } | |
1550 | ||
1551 | /* | |
1552 | * XXX what about functions for drivers to save/restore ocp_sysconfig | |
1553 | * for context save/restore operations? | |
1554 | */ | |
1555 | ||
1556 | /** | |
1557 | * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh | |
1558 | * @oh: struct omap_hwmod * | |
1559 | * @init_oh: struct omap_hwmod * (initiator) | |
1560 | * | |
1561 | * Remove a sleep dependency between the initiator @init_oh and @oh. | |
1562 | * Intended to be called by DSP/Bridge code via platform_data for the | |
1563 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge | |
1564 | * code needs to add/del initiator dependencies dynamically | |
1565 | * before/after accessing a device. Returns the return value from | |
1566 | * _del_initiator_dep(). | |
1567 | * | |
1568 | * XXX Keep a usecount in the clockdomain code | |
1569 | */ | |
1570 | int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh, | |
1571 | struct omap_hwmod *init_oh) | |
1572 | { | |
1573 | return _del_initiator_dep(oh, init_oh); | |
1574 | } | |
1575 | ||
63c85238 PW |
1576 | /** |
1577 | * omap_hwmod_enable_wakeup - allow device to wake up the system | |
1578 | * @oh: struct omap_hwmod * | |
1579 | * | |
1580 | * Sets the module OCP socket ENAWAKEUP bit to allow the module to | |
1581 | * send wakeups to the PRCM. Eventually this should sets PRCM wakeup | |
1582 | * registers to cause the PRCM to receive wakeup events from the | |
1583 | * module. Does not set any wakeup routing registers beyond this | |
1584 | * point - if the module is to wake up any other module or subsystem, | |
1585 | * that must be set separately. Called by omap_device code. Returns | |
1586 | * -EINVAL on error or 0 upon success. | |
1587 | */ | |
1588 | int omap_hwmod_enable_wakeup(struct omap_hwmod *oh) | |
1589 | { | |
43b40992 PW |
1590 | if (!oh->class->sysc || |
1591 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) | |
63c85238 PW |
1592 | return -EINVAL; |
1593 | ||
1594 | mutex_lock(&omap_hwmod_mutex); | |
1595 | _enable_wakeup(oh); | |
1596 | mutex_unlock(&omap_hwmod_mutex); | |
1597 | ||
1598 | return 0; | |
1599 | } | |
1600 | ||
1601 | /** | |
1602 | * omap_hwmod_disable_wakeup - prevent device from waking the system | |
1603 | * @oh: struct omap_hwmod * | |
1604 | * | |
1605 | * Clears the module OCP socket ENAWAKEUP bit to prevent the module | |
1606 | * from sending wakeups to the PRCM. Eventually this should clear | |
1607 | * PRCM wakeup registers to cause the PRCM to ignore wakeup events | |
1608 | * from the module. Does not set any wakeup routing registers beyond | |
1609 | * this point - if the module is to wake up any other module or | |
1610 | * subsystem, that must be set separately. Called by omap_device | |
1611 | * code. Returns -EINVAL on error or 0 upon success. | |
1612 | */ | |
1613 | int omap_hwmod_disable_wakeup(struct omap_hwmod *oh) | |
1614 | { | |
43b40992 PW |
1615 | if (!oh->class->sysc || |
1616 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) | |
63c85238 PW |
1617 | return -EINVAL; |
1618 | ||
1619 | mutex_lock(&omap_hwmod_mutex); | |
1620 | _disable_wakeup(oh); | |
1621 | mutex_unlock(&omap_hwmod_mutex); | |
1622 | ||
1623 | return 0; | |
1624 | } | |
43b40992 PW |
1625 | |
1626 | /** | |
1627 | * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname | |
1628 | * @classname: struct omap_hwmod_class name to search for | |
1629 | * @fn: callback function pointer to call for each hwmod in class @classname | |
1630 | * @user: arbitrary context data to pass to the callback function | |
1631 | * | |
1632 | * For each omap_hwmod of class @classname, call @fn. Takes | |
1633 | * omap_hwmod_mutex to prevent the hwmod list from changing during the | |
1634 | * iteration. If the callback function returns something other than | |
1635 | * zero, the iterator is terminated, and the callback function's return | |
1636 | * value is passed back to the caller. Returns 0 upon success, -EINVAL | |
1637 | * if @classname or @fn are NULL, or passes back the error code from @fn. | |
1638 | */ | |
1639 | int omap_hwmod_for_each_by_class(const char *classname, | |
1640 | int (*fn)(struct omap_hwmod *oh, | |
1641 | void *user), | |
1642 | void *user) | |
1643 | { | |
1644 | struct omap_hwmod *temp_oh; | |
1645 | int ret = 0; | |
1646 | ||
1647 | if (!classname || !fn) | |
1648 | return -EINVAL; | |
1649 | ||
1650 | pr_debug("omap_hwmod: %s: looking for modules of class %s\n", | |
1651 | __func__, classname); | |
1652 | ||
1653 | mutex_lock(&omap_hwmod_mutex); | |
1654 | ||
1655 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { | |
1656 | if (!strcmp(temp_oh->class->name, classname)) { | |
1657 | pr_debug("omap_hwmod: %s: %s: calling callback fn\n", | |
1658 | __func__, temp_oh->name); | |
1659 | ret = (*fn)(temp_oh, user); | |
1660 | if (ret) | |
1661 | break; | |
1662 | } | |
1663 | } | |
1664 | ||
1665 | mutex_unlock(&omap_hwmod_mutex); | |
1666 | ||
1667 | if (ret) | |
1668 | pr_debug("omap_hwmod: %s: iterator terminated early: %d\n", | |
1669 | __func__, ret); | |
1670 | ||
1671 | return ret; | |
1672 | } | |
1673 |