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