2 * omap_hwmod implementation for OMAP2/3/4
4 * Copyright (C) 2009-2010 Nokia Corporation
6 * Paul Walmsley, BenoƮt Cousson, Kevin Hilman
8 * Created in collaboration with (alphabetical order): Thara Gopinath,
9 * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
10 * Sawant, Santosh Shilimkar, Richard Woodruff
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.
18 * One way to view an OMAP SoC is as a collection of largely unrelated
19 * IP blocks connected by interconnects. The IP blocks include
20 * devices such as ARM processors, audio serial interfaces, UARTs,
21 * etc. Some of these devices, like the DSP, are created by TI;
22 * others, like the SGX, largely originate from external vendors. In
23 * TI's documentation, on-chip devices are referred to as "OMAP
24 * modules." Some of these IP blocks are identical across several
25 * OMAP versions. Others are revised frequently.
27 * These OMAP modules are tied together by various interconnects.
28 * Most of the address and data flow between modules is via OCP-based
29 * interconnects such as the L3 and L4 buses; but there are other
30 * interconnects that distribute the hardware clock tree, handle idle
31 * and reset signaling, supply power, and connect the modules to
32 * various pads or balls on the OMAP package.
34 * OMAP hwmod provides a consistent way to describe the on-chip
35 * hardware blocks and their integration into the rest of the chip.
36 * This description can be automatically generated from the TI
37 * hardware database. OMAP hwmod provides a standard, consistent API
38 * to reset, enable, idle, and disable these hardware blocks. And
39 * hwmod provides a way for other core code, such as the Linux device
40 * code or the OMAP power management and address space mapping code,
41 * to query the hardware database.
45 * Drivers won't call hwmod functions directly. That is done by the
46 * omap_device code, and in rare occasions, by custom integration code
47 * in arch/arm/ *omap*. The omap_device code includes functions to
48 * build a struct platform_device using omap_hwmod data, and that is
49 * currently how hwmod data is communicated to drivers and to the
50 * Linux driver model. Most drivers will call omap_hwmod functions only
51 * indirectly, via pm_runtime*() functions.
53 * From a layering perspective, here is where the OMAP hwmod code
54 * fits into the kernel software stack:
56 * +-------------------------------+
57 * | Device driver code |
58 * | (e.g., drivers/) |
59 * +-------------------------------+
60 * | Linux driver model |
61 * | (platform_device / |
62 * | platform_driver data/code) |
63 * +-------------------------------+
64 * | OMAP core-driver integration |
65 * |(arch/arm/mach-omap2/devices.c)|
66 * +-------------------------------+
67 * | omap_device code |
68 * | (../plat-omap/omap_device.c) |
69 * +-------------------------------+
70 * ----> | omap_hwmod code/data | <-----
71 * | (../mach-omap2/omap_hwmod*) |
72 * +-------------------------------+
73 * | OMAP clock/PRCM/register fns |
74 * | (__raw_{read,write}l, clk*) |
75 * +-------------------------------+
77 * Device drivers should not contain any OMAP-specific code or data in
78 * them. They should only contain code to operate the IP block that
79 * the driver is responsible for. This is because these IP blocks can
80 * also appear in other SoCs, either from TI (such as DaVinci) or from
81 * other manufacturers; and drivers should be reusable across other
84 * The OMAP hwmod code also will attempt to reset and idle all on-chip
85 * devices upon boot. The goal here is for the kernel to be
86 * completely self-reliant and independent from bootloaders. This is
87 * to ensure a repeatable configuration, both to ensure consistent
88 * runtime behavior, and to make it easier for others to reproduce
91 * OMAP module activity states
92 * ---------------------------
93 * The hwmod code considers modules to be in one of several activity
94 * states. IP blocks start out in an UNKNOWN state, then once they
95 * are registered via the hwmod code, proceed to the REGISTERED state.
96 * Once their clock names are resolved to clock pointers, the module
97 * enters the CLKS_INITED state; and finally, once the module has been
98 * reset and the integration registers programmed, the INITIALIZED state
99 * is entered. The hwmod code will then place the module into either
100 * the IDLE state to save power, or in the case of a critical system
101 * module, the ENABLED state.
103 * OMAP core integration code can then call omap_hwmod*() functions
104 * directly to move the module between the IDLE, ENABLED, and DISABLED
105 * states, as needed. This is done during both the PM idle loop, and
106 * in the OMAP core integration code's implementation of the PM runtime
111 * This is a partial list.
112 * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
113 * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
114 * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
115 * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
116 * - Open Core Protocol Specification 2.2
119 * - handle IO mapping
120 * - bus throughput & module latency measurement code
122 * XXX add tests at the beginning of each function to ensure the hwmod is
123 * in the appropriate state
124 * XXX error return values should be checked to ensure that they are
129 #include <linux/kernel.h>
130 #include <linux/errno.h>
131 #include <linux/io.h>
132 #include <linux/clk.h>
133 #include <linux/delay.h>
134 #include <linux/err.h>
135 #include <linux/list.h>
136 #include <linux/mutex.h>
137 #include <linux/spinlock.h>
139 #include <plat/common.h>
140 #include <plat/cpu.h>
141 #include "clockdomain.h"
142 #include "powerdomain.h"
143 #include <plat/clock.h>
144 #include <plat/omap_hwmod.h>
145 #include <plat/prcm.h>
147 #include "cm2xxx_3xxx.h"
149 #include "prm2xxx_3xxx.h"
153 /* Maximum microseconds to wait for OMAP module to softreset */
154 #define MAX_MODULE_SOFTRESET_WAIT 10000
156 /* Name of the OMAP hwmod for the MPU */
157 #define MPU_INITIATOR_NAME "mpu"
159 /* omap_hwmod_list contains all registered struct omap_hwmods */
160 static LIST_HEAD(omap_hwmod_list);
162 /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
163 static struct omap_hwmod *mpu_oh;
165 /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */
169 /* Private functions */
172 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
173 * @oh: struct omap_hwmod *
175 * Load the current value of the hwmod OCP_SYSCONFIG register into the
176 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
177 * OCP_SYSCONFIG register or 0 upon success.
179 static int _update_sysc_cache(struct omap_hwmod *oh)
181 if (!oh->class->sysc) {
182 WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
186 /* XXX ensure module interface clock is up */
188 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
190 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
191 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
197 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
198 * @v: OCP_SYSCONFIG value to write
199 * @oh: struct omap_hwmod *
201 * Write @v into the module class' OCP_SYSCONFIG register, if it has
202 * one. No return value.
204 static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
206 if (!oh->class->sysc) {
207 WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
211 /* XXX ensure module interface clock is up */
213 /* Module might have lost context, always update cache and register */
215 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
219 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
220 * @oh: struct omap_hwmod *
221 * @standbymode: MIDLEMODE field bits
222 * @v: pointer to register contents to modify
224 * Update the master standby mode bits in @v to be @standbymode for
225 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
226 * upon error or 0 upon success.
228 static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
234 if (!oh->class->sysc ||
235 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
238 if (!oh->class->sysc->sysc_fields) {
239 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
243 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
244 mstandby_mask = (0x3 << mstandby_shift);
246 *v &= ~mstandby_mask;
247 *v |= __ffs(standbymode) << mstandby_shift;
253 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
254 * @oh: struct omap_hwmod *
255 * @idlemode: SIDLEMODE field bits
256 * @v: pointer to register contents to modify
258 * Update the slave idle mode bits in @v to be @idlemode for the @oh
259 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
262 static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
267 if (!oh->class->sysc ||
268 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
271 if (!oh->class->sysc->sysc_fields) {
272 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
276 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
277 sidle_mask = (0x3 << sidle_shift);
280 *v |= __ffs(idlemode) << sidle_shift;
286 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
287 * @oh: struct omap_hwmod *
288 * @clockact: CLOCKACTIVITY field bits
289 * @v: pointer to register contents to modify
291 * Update the clockactivity mode bits in @v to be @clockact for the
292 * @oh hwmod. Used for additional powersaving on some modules. Does
293 * not write to the hardware. Returns -EINVAL upon error or 0 upon
296 static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
301 if (!oh->class->sysc ||
302 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
305 if (!oh->class->sysc->sysc_fields) {
306 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
310 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
311 clkact_mask = (0x3 << clkact_shift);
314 *v |= clockact << clkact_shift;
320 * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
321 * @oh: struct omap_hwmod *
322 * @v: pointer to register contents to modify
324 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
325 * error or 0 upon success.
327 static int _set_softreset(struct omap_hwmod *oh, u32 *v)
331 if (!oh->class->sysc ||
332 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
335 if (!oh->class->sysc->sysc_fields) {
336 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
340 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
348 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
349 * @oh: struct omap_hwmod *
350 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
351 * @v: pointer to register contents to modify
353 * Update the module autoidle bit in @v to be @autoidle for the @oh
354 * hwmod. The autoidle bit controls whether the module can gate
355 * internal clocks automatically when it isn't doing anything; the
356 * exact function of this bit varies on a per-module basis. This
357 * function does not write to the hardware. Returns -EINVAL upon
358 * error or 0 upon success.
360 static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
366 if (!oh->class->sysc ||
367 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
370 if (!oh->class->sysc->sysc_fields) {
371 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
375 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
376 autoidle_mask = (0x3 << autoidle_shift);
378 *v &= ~autoidle_mask;
379 *v |= autoidle << autoidle_shift;
385 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
386 * @oh: struct omap_hwmod *
388 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
389 * upon error or 0 upon success.
391 static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
395 if (!oh->class->sysc ||
396 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
397 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)))
400 if (!oh->class->sysc->sysc_fields) {
401 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
405 wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
409 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
410 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
412 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
414 oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
420 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
421 * @oh: struct omap_hwmod *
423 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
424 * upon error or 0 upon success.
426 static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
430 if (!oh->class->sysc ||
431 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
432 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)))
435 if (!oh->class->sysc->sysc_fields) {
436 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
440 wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
444 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
445 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
447 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
449 oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
455 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
456 * @oh: struct omap_hwmod *
458 * Prevent the hardware module @oh from entering idle while the
459 * hardare module initiator @init_oh is active. Useful when a module
460 * will be accessed by a particular initiator (e.g., if a module will
461 * be accessed by the IVA, there should be a sleepdep between the IVA
462 * initiator and the module). Only applies to modules in smart-idle
463 * mode. Returns -EINVAL upon error or passes along
464 * clkdm_add_sleepdep() value upon success.
466 static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
471 return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
475 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
476 * @oh: struct omap_hwmod *
478 * Allow the hardware module @oh to enter idle while the hardare
479 * module initiator @init_oh is active. Useful when a module will not
480 * be accessed by a particular initiator (e.g., if a module will not
481 * be accessed by the IVA, there should be no sleepdep between the IVA
482 * initiator and the module). Only applies to modules in smart-idle
483 * mode. Returns -EINVAL upon error or passes along
484 * clkdm_del_sleepdep() value upon success.
486 static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
491 return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
495 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
496 * @oh: struct omap_hwmod *
498 * Called from _init_clocks(). Populates the @oh _clk (main
499 * functional clock pointer) if a main_clk is present. Returns 0 on
500 * success or -EINVAL on error.
502 static int _init_main_clk(struct omap_hwmod *oh)
509 oh->_clk = omap_clk_get_by_name(oh->main_clk);
511 pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
512 oh->name, oh->main_clk);
516 if (!oh->_clk->clkdm)
517 pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
518 oh->main_clk, oh->_clk->name);
524 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
525 * @oh: struct omap_hwmod *
527 * Called from _init_clocks(). Populates the @oh OCP slave interface
528 * clock pointers. Returns 0 on success or -EINVAL on error.
530 static int _init_interface_clks(struct omap_hwmod *oh)
536 if (oh->slaves_cnt == 0)
539 for (i = 0; i < oh->slaves_cnt; i++) {
540 struct omap_hwmod_ocp_if *os = oh->slaves[i];
545 c = omap_clk_get_by_name(os->clk);
547 pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
558 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
559 * @oh: struct omap_hwmod *
561 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
562 * clock pointers. Returns 0 on success or -EINVAL on error.
564 static int _init_opt_clks(struct omap_hwmod *oh)
566 struct omap_hwmod_opt_clk *oc;
571 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
572 c = omap_clk_get_by_name(oc->clk);
574 pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
585 * _enable_clocks - enable hwmod main clock and interface clocks
586 * @oh: struct omap_hwmod *
588 * Enables all clocks necessary for register reads and writes to succeed
589 * on the hwmod @oh. Returns 0.
591 static int _enable_clocks(struct omap_hwmod *oh)
595 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
598 clk_enable(oh->_clk);
600 if (oh->slaves_cnt > 0) {
601 for (i = 0; i < oh->slaves_cnt; i++) {
602 struct omap_hwmod_ocp_if *os = oh->slaves[i];
603 struct clk *c = os->_clk;
605 if (c && (os->flags & OCPIF_SWSUP_IDLE))
610 /* The opt clocks are controlled by the device driver. */
616 * _disable_clocks - disable hwmod main clock and interface clocks
617 * @oh: struct omap_hwmod *
619 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
621 static int _disable_clocks(struct omap_hwmod *oh)
625 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
628 clk_disable(oh->_clk);
630 if (oh->slaves_cnt > 0) {
631 for (i = 0; i < oh->slaves_cnt; i++) {
632 struct omap_hwmod_ocp_if *os = oh->slaves[i];
633 struct clk *c = os->_clk;
635 if (c && (os->flags & OCPIF_SWSUP_IDLE))
640 /* The opt clocks are controlled by the device driver. */
645 static void _enable_optional_clocks(struct omap_hwmod *oh)
647 struct omap_hwmod_opt_clk *oc;
650 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
652 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
654 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
656 clk_enable(oc->_clk);
660 static void _disable_optional_clocks(struct omap_hwmod *oh)
662 struct omap_hwmod_opt_clk *oc;
665 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
667 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
669 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
671 clk_disable(oc->_clk);
676 * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
677 * @oh: struct omap_hwmod *
679 * Returns the array index of the OCP slave port that the MPU
680 * addresses the device on, or -EINVAL upon error or not found.
682 static int __init _find_mpu_port_index(struct omap_hwmod *oh)
687 if (!oh || oh->slaves_cnt == 0)
690 for (i = 0; i < oh->slaves_cnt; i++) {
691 struct omap_hwmod_ocp_if *os = oh->slaves[i];
693 if (os->user & OCP_USER_MPU) {
700 pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
703 pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
706 return (found) ? i : -EINVAL;
710 * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
711 * @oh: struct omap_hwmod *
713 * Return the virtual address of the base of the register target of
714 * device @oh, or NULL on error.
716 static void __iomem * __init _find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
718 struct omap_hwmod_ocp_if *os;
719 struct omap_hwmod_addr_space *mem;
722 void __iomem *va_start;
724 if (!oh || oh->slaves_cnt == 0)
727 os = oh->slaves[index];
729 for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) {
730 if (mem->flags & ADDR_TYPE_RT) {
737 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
739 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
742 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
745 pr_debug("omap_hwmod: %s: no MPU register target found\n",
749 return (found) ? va_start : NULL;
753 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
754 * @oh: struct omap_hwmod *
756 * If module is marked as SWSUP_SIDLE, force the module out of slave
757 * idle; otherwise, configure it for smart-idle. If module is marked
758 * as SWSUP_MSUSPEND, force the module out of master standby;
759 * otherwise, configure it for smart-standby. No return value.
761 static void _enable_sysc(struct omap_hwmod *oh)
766 if (!oh->class->sysc)
770 sf = oh->class->sysc->sysc_flags;
772 if (sf & SYSC_HAS_SIDLEMODE) {
773 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
774 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
775 _set_slave_idlemode(oh, idlemode, &v);
778 if (sf & SYSC_HAS_MIDLEMODE) {
779 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
780 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
781 _set_master_standbymode(oh, idlemode, &v);
785 * XXX The clock framework should handle this, by
786 * calling into this code. But this must wait until the
787 * clock structures are tagged with omap_hwmod entries
789 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
790 (sf & SYSC_HAS_CLOCKACTIVITY))
791 _set_clockactivity(oh, oh->class->sysc->clockact, &v);
793 /* If slave is in SMARTIDLE, also enable wakeup */
794 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
795 _enable_wakeup(oh, &v);
797 _write_sysconfig(v, oh);
800 * Set the autoidle bit only after setting the smartidle bit
801 * Setting this will not have any impact on the other modules.
803 if (sf & SYSC_HAS_AUTOIDLE) {
804 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
806 _set_module_autoidle(oh, idlemode, &v);
807 _write_sysconfig(v, oh);
812 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
813 * @oh: struct omap_hwmod *
815 * If module is marked as SWSUP_SIDLE, force the module into slave
816 * idle; otherwise, configure it for smart-idle. If module is marked
817 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
818 * configure it for smart-standby. No return value.
820 static void _idle_sysc(struct omap_hwmod *oh)
825 if (!oh->class->sysc)
829 sf = oh->class->sysc->sysc_flags;
831 if (sf & SYSC_HAS_SIDLEMODE) {
832 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
833 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
834 _set_slave_idlemode(oh, idlemode, &v);
837 if (sf & SYSC_HAS_MIDLEMODE) {
838 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
839 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
840 _set_master_standbymode(oh, idlemode, &v);
843 /* If slave is in SMARTIDLE, also enable wakeup */
844 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
845 _enable_wakeup(oh, &v);
847 _write_sysconfig(v, oh);
851 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
852 * @oh: struct omap_hwmod *
854 * Force the module into slave idle and master suspend. No return
857 static void _shutdown_sysc(struct omap_hwmod *oh)
862 if (!oh->class->sysc)
866 sf = oh->class->sysc->sysc_flags;
868 if (sf & SYSC_HAS_SIDLEMODE)
869 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
871 if (sf & SYSC_HAS_MIDLEMODE)
872 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
874 if (sf & SYSC_HAS_AUTOIDLE)
875 _set_module_autoidle(oh, 1, &v);
877 _write_sysconfig(v, oh);
881 * _lookup - find an omap_hwmod by name
882 * @name: find an omap_hwmod by name
884 * Return a pointer to an omap_hwmod by name, or NULL if not found.
886 static struct omap_hwmod *_lookup(const char *name)
888 struct omap_hwmod *oh, *temp_oh;
892 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
893 if (!strcmp(name, temp_oh->name)) {
903 * _init_clocks - clk_get() all clocks associated with this hwmod
904 * @oh: struct omap_hwmod *
905 * @data: not used; pass NULL
907 * Called by omap_hwmod_late_init() (after omap2_clk_init()).
908 * Resolves all clock names embedded in the hwmod. Returns -EINVAL if
909 * the omap_hwmod has not yet been registered or if the clocks have
910 * already been initialized, 0 on success, or a non-zero error on
913 static int _init_clocks(struct omap_hwmod *oh, void *data)
917 if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED))
920 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
922 ret |= _init_main_clk(oh);
923 ret |= _init_interface_clks(oh);
924 ret |= _init_opt_clks(oh);
927 oh->_state = _HWMOD_STATE_CLKS_INITED;
933 * _wait_target_ready - wait for a module to leave slave idle
934 * @oh: struct omap_hwmod *
936 * Wait for a module @oh to leave slave idle. Returns 0 if the module
937 * does not have an IDLEST bit or if the module successfully leaves
938 * slave idle; otherwise, pass along the return value of the
939 * appropriate *_cm_wait_module_ready() function.
941 static int _wait_target_ready(struct omap_hwmod *oh)
943 struct omap_hwmod_ocp_if *os;
949 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
952 os = oh->slaves[oh->_mpu_port_index];
954 if (oh->flags & HWMOD_NO_IDLEST)
957 /* XXX check module SIDLEMODE */
959 /* XXX check clock enable states */
961 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
962 ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
963 oh->prcm.omap2.idlest_reg_id,
964 oh->prcm.omap2.idlest_idle_bit);
965 } else if (cpu_is_omap44xx()) {
966 ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg);
975 * _lookup_hardreset - return the register bit shift for this hwmod/reset line
976 * @oh: struct omap_hwmod *
977 * @name: name of the reset line in the context of this hwmod
979 * Return the bit position of the reset line that match the
980 * input name. Return -ENOENT if not found.
982 static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name)
986 for (i = 0; i < oh->rst_lines_cnt; i++) {
987 const char *rst_line = oh->rst_lines[i].name;
988 if (!strcmp(rst_line, name)) {
989 u8 shift = oh->rst_lines[i].rst_shift;
990 pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n",
991 oh->name, rst_line, shift);
1001 * _assert_hardreset - assert the HW reset line of submodules
1002 * contained in the hwmod module.
1003 * @oh: struct omap_hwmod *
1004 * @name: name of the reset line to lookup and assert
1006 * Some IP like dsp, ipu or iva contain processor that require
1007 * an HW reset line to be assert / deassert in order to enable fully
1010 static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1017 shift = _lookup_hardreset(oh, name);
1018 if (IS_ERR_VALUE(shift))
1021 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1022 return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
1024 else if (cpu_is_omap44xx())
1025 return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
1032 * _deassert_hardreset - deassert the HW reset line of submodules contained
1033 * in the hwmod module.
1034 * @oh: struct omap_hwmod *
1035 * @name: name of the reset line to look up and deassert
1037 * Some IP like dsp, ipu or iva contain processor that require
1038 * an HW reset line to be assert / deassert in order to enable fully
1041 static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1049 shift = _lookup_hardreset(oh, name);
1050 if (IS_ERR_VALUE(shift))
1053 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1054 r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
1056 else if (cpu_is_omap44xx())
1057 r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
1063 pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
1069 * _read_hardreset - read the HW reset line state of submodules
1070 * contained in the hwmod module
1071 * @oh: struct omap_hwmod *
1072 * @name: name of the reset line to look up and read
1074 * Return the state of the reset line.
1076 static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1083 shift = _lookup_hardreset(oh, name);
1084 if (IS_ERR_VALUE(shift))
1087 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1088 return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
1090 } else if (cpu_is_omap44xx()) {
1091 return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
1099 * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
1100 * @oh: struct omap_hwmod *
1102 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
1103 * enabled for this to work. Returns -EINVAL if the hwmod cannot be
1104 * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
1105 * the module did not reset in time, or 0 upon success.
1107 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
1108 * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
1109 * use the SYSCONFIG softreset bit to provide the status.
1111 * Note that some IP like McBSP do have reset control but don't have
1114 static int _ocp_softreset(struct omap_hwmod *oh)
1120 if (!oh->class->sysc ||
1121 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
1124 /* clocks must be on for this operation */
1125 if (oh->_state != _HWMOD_STATE_ENABLED) {
1126 pr_warning("omap_hwmod: %s: reset can only be entered from "
1127 "enabled state\n", oh->name);
1131 /* For some modules, all optionnal clocks need to be enabled as well */
1132 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1133 _enable_optional_clocks(oh);
1135 pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
1137 v = oh->_sysc_cache;
1138 ret = _set_softreset(oh, &v);
1141 _write_sysconfig(v, oh);
1143 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
1144 omap_test_timeout((omap_hwmod_read(oh,
1145 oh->class->sysc->syss_offs)
1146 & SYSS_RESETDONE_MASK),
1147 MAX_MODULE_SOFTRESET_WAIT, c);
1148 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
1149 omap_test_timeout(!(omap_hwmod_read(oh,
1150 oh->class->sysc->sysc_offs)
1151 & SYSC_TYPE2_SOFTRESET_MASK),
1152 MAX_MODULE_SOFTRESET_WAIT, c);
1154 if (c == MAX_MODULE_SOFTRESET_WAIT)
1155 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1156 oh->name, MAX_MODULE_SOFTRESET_WAIT);
1158 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1161 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1162 * _wait_target_ready() or _reset()
1165 ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1168 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1169 _disable_optional_clocks(oh);
1175 * _reset - reset an omap_hwmod
1176 * @oh: struct omap_hwmod *
1178 * Resets an omap_hwmod @oh. The default software reset mechanism for
1179 * most OMAP IP blocks is triggered via the OCP_SYSCONFIG.SOFTRESET
1180 * bit. However, some hwmods cannot be reset via this method: some
1181 * are not targets and therefore have no OCP header registers to
1182 * access; others (like the IVA) have idiosyncratic reset sequences.
1183 * So for these relatively rare cases, custom reset code can be
1184 * supplied in the struct omap_hwmod_class .reset function pointer.
1185 * Passes along the return value from either _reset() or the custom
1186 * reset function - these must return -EINVAL if the hwmod cannot be
1187 * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
1188 * the module did not reset in time, or 0 upon success.
1190 static int _reset(struct omap_hwmod *oh)
1194 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1196 ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh);
1202 * _enable - enable an omap_hwmod
1203 * @oh: struct omap_hwmod *
1205 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
1206 * register target. Returns -EINVAL if the hwmod is in the wrong
1207 * state or passes along the return value of _wait_target_ready().
1209 static int _enable(struct omap_hwmod *oh)
1213 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1214 oh->_state != _HWMOD_STATE_IDLE &&
1215 oh->_state != _HWMOD_STATE_DISABLED) {
1216 WARN(1, "omap_hwmod: %s: enabled state can only be entered "
1217 "from initialized, idle, or disabled state\n", oh->name);
1221 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1224 * If an IP contains only one HW reset line, then de-assert it in order
1225 * to allow to enable the clocks. Otherwise the PRCM will return
1226 * Intransition status, and the init will failed.
1228 if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
1229 oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
1230 _deassert_hardreset(oh, oh->rst_lines[0].name);
1232 /* Mux pins for device runtime if populated */
1234 omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
1236 _add_initiator_dep(oh, mpu_oh);
1239 r = _wait_target_ready(oh);
1241 oh->_state = _HWMOD_STATE_ENABLED;
1243 /* Access the sysconfig only if the target is ready */
1244 if (oh->class->sysc) {
1245 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
1246 _update_sysc_cache(oh);
1250 _disable_clocks(oh);
1251 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
1259 * _idle - idle an omap_hwmod
1260 * @oh: struct omap_hwmod *
1262 * Idles an omap_hwmod @oh. This should be called once the hwmod has
1263 * no further work. Returns -EINVAL if the hwmod is in the wrong
1264 * state or returns 0.
1266 static int _idle(struct omap_hwmod *oh)
1268 if (oh->_state != _HWMOD_STATE_ENABLED) {
1269 WARN(1, "omap_hwmod: %s: idle state can only be entered from "
1270 "enabled state\n", oh->name);
1274 pr_debug("omap_hwmod: %s: idling\n", oh->name);
1276 if (oh->class->sysc)
1278 _del_initiator_dep(oh, mpu_oh);
1279 _disable_clocks(oh);
1281 /* Mux pins for device idle if populated */
1283 omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
1285 oh->_state = _HWMOD_STATE_IDLE;
1291 * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
1292 * @oh: struct omap_hwmod *
1293 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
1295 * Sets the IP block's OCP autoidle bit in hardware, and updates our
1296 * local copy. Intended to be used by drivers that require
1297 * direct manipulation of the AUTOIDLE bits.
1298 * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
1299 * along the return value from _set_module_autoidle().
1301 * Any users of this function should be scrutinized carefully.
1303 int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
1307 unsigned long flags;
1309 if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
1312 spin_lock_irqsave(&oh->_lock, flags);
1314 v = oh->_sysc_cache;
1316 retval = _set_module_autoidle(oh, autoidle, &v);
1319 _write_sysconfig(v, oh);
1321 spin_unlock_irqrestore(&oh->_lock, flags);
1327 * _shutdown - shutdown an omap_hwmod
1328 * @oh: struct omap_hwmod *
1330 * Shut down an omap_hwmod @oh. This should be called when the driver
1331 * used for the hwmod is removed or unloaded or if the driver is not
1332 * used by the system. Returns -EINVAL if the hwmod is in the wrong
1333 * state or returns 0.
1335 static int _shutdown(struct omap_hwmod *oh)
1340 if (oh->_state != _HWMOD_STATE_IDLE &&
1341 oh->_state != _HWMOD_STATE_ENABLED) {
1342 WARN(1, "omap_hwmod: %s: disabled state can only be entered "
1343 "from idle, or enabled state\n", oh->name);
1347 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
1349 if (oh->class->pre_shutdown) {
1350 prev_state = oh->_state;
1351 if (oh->_state == _HWMOD_STATE_IDLE)
1353 ret = oh->class->pre_shutdown(oh);
1355 if (prev_state == _HWMOD_STATE_IDLE)
1361 if (oh->class->sysc)
1365 * If an IP contains only one HW reset line, then assert it
1366 * before disabling the clocks and shutting down the IP.
1368 if (oh->rst_lines_cnt == 1)
1369 _assert_hardreset(oh, oh->rst_lines[0].name);
1371 /* clocks and deps are already disabled in idle */
1372 if (oh->_state == _HWMOD_STATE_ENABLED) {
1373 _del_initiator_dep(oh, mpu_oh);
1374 /* XXX what about the other system initiators here? dma, dsp */
1375 _disable_clocks(oh);
1377 /* XXX Should this code also force-disable the optional clocks? */
1379 /* Mux pins to safe mode or use populated off mode values */
1381 omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
1383 oh->_state = _HWMOD_STATE_DISABLED;
1389 * _setup - do initial configuration of omap_hwmod
1390 * @oh: struct omap_hwmod *
1392 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
1393 * OCP_SYSCONFIG register. Returns -EINVAL if the hwmod is in the
1394 * wrong state or returns 0.
1396 static int _setup(struct omap_hwmod *oh, void *data)
1401 /* Set iclk autoidle mode */
1402 if (oh->slaves_cnt > 0) {
1403 for (i = 0; i < oh->slaves_cnt; i++) {
1404 struct omap_hwmod_ocp_if *os = oh->slaves[i];
1405 struct clk *c = os->_clk;
1410 if (os->flags & OCPIF_SWSUP_IDLE) {
1411 /* XXX omap_iclk_deny_idle(c); */
1413 /* XXX omap_iclk_allow_idle(c); */
1419 oh->_state = _HWMOD_STATE_INITIALIZED;
1422 * In the case of hwmod with hardreset that should not be
1423 * de-assert at boot time, we have to keep the module
1424 * initialized, because we cannot enable it properly with the
1425 * reset asserted. Exit without warning because that behavior is
1428 if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
1433 pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
1434 oh->name, oh->_state);
1438 if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
1442 * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
1443 * The _enable() function should be split to
1444 * avoid the rewrite of the OCP_SYSCONFIG register.
1446 if (oh->class->sysc) {
1447 _update_sysc_cache(oh);
1452 postsetup_state = oh->_postsetup_state;
1453 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
1454 postsetup_state = _HWMOD_STATE_ENABLED;
1457 * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
1458 * it should be set by the core code as a runtime flag during startup
1460 if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
1461 (postsetup_state == _HWMOD_STATE_IDLE))
1462 postsetup_state = _HWMOD_STATE_ENABLED;
1464 if (postsetup_state == _HWMOD_STATE_IDLE)
1466 else if (postsetup_state == _HWMOD_STATE_DISABLED)
1468 else if (postsetup_state != _HWMOD_STATE_ENABLED)
1469 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
1470 oh->name, postsetup_state);
1476 * _register - register a struct omap_hwmod
1477 * @oh: struct omap_hwmod *
1479 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
1480 * already has been registered by the same name; -EINVAL if the
1481 * omap_hwmod is in the wrong state, if @oh is NULL, if the
1482 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
1483 * name, or if the omap_hwmod's class is missing a name; or 0 upon
1486 * XXX The data should be copied into bootmem, so the original data
1487 * should be marked __initdata and freed after init. This would allow
1488 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
1489 * that the copy process would be relatively complex due to the large number
1492 static int __init _register(struct omap_hwmod *oh)
1496 if (!oh || !oh->name || !oh->class || !oh->class->name ||
1497 (oh->_state != _HWMOD_STATE_UNKNOWN))
1500 pr_debug("omap_hwmod: %s: registering\n", oh->name);
1502 if (_lookup(oh->name))
1505 ms_id = _find_mpu_port_index(oh);
1506 if (!IS_ERR_VALUE(ms_id)) {
1507 oh->_mpu_port_index = ms_id;
1508 oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
1510 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
1513 list_add_tail(&oh->node, &omap_hwmod_list);
1515 spin_lock_init(&oh->_lock);
1517 oh->_state = _HWMOD_STATE_REGISTERED;
1525 /* Public functions */
1527 u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
1529 if (oh->flags & HWMOD_16BIT_REG)
1530 return __raw_readw(oh->_mpu_rt_va + reg_offs);
1532 return __raw_readl(oh->_mpu_rt_va + reg_offs);
1535 void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
1537 if (oh->flags & HWMOD_16BIT_REG)
1538 __raw_writew(v, oh->_mpu_rt_va + reg_offs);
1540 __raw_writel(v, oh->_mpu_rt_va + reg_offs);
1544 * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
1545 * @oh: struct omap_hwmod *
1546 * @idlemode: SIDLEMODE field bits (shifted to bit 0)
1548 * Sets the IP block's OCP slave idlemode in hardware, and updates our
1549 * local copy. Intended to be used by drivers that have some erratum
1550 * that requires direct manipulation of the SIDLEMODE bits. Returns
1551 * -EINVAL if @oh is null, or passes along the return value from
1552 * _set_slave_idlemode().
1554 * XXX Does this function have any current users? If not, we should
1555 * remove it; it is better to let the rest of the hwmod code handle this.
1556 * Any users of this function should be scrutinized carefully.
1558 int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
1566 v = oh->_sysc_cache;
1568 retval = _set_slave_idlemode(oh, idlemode, &v);
1570 _write_sysconfig(v, oh);
1576 * omap_hwmod_lookup - look up a registered omap_hwmod by name
1577 * @name: name of the omap_hwmod to look up
1579 * Given a @name of an omap_hwmod, return a pointer to the registered
1580 * struct omap_hwmod *, or NULL upon error.
1582 struct omap_hwmod *omap_hwmod_lookup(const char *name)
1584 struct omap_hwmod *oh;
1595 * omap_hwmod_for_each - call function for each registered omap_hwmod
1596 * @fn: pointer to a callback function
1597 * @data: void * data to pass to callback function
1599 * Call @fn for each registered omap_hwmod, passing @data to each
1600 * function. @fn must return 0 for success or any other value for
1601 * failure. If @fn returns non-zero, the iteration across omap_hwmods
1602 * will stop and the non-zero return value will be passed to the
1603 * caller of omap_hwmod_for_each(). @fn is called with
1604 * omap_hwmod_for_each() held.
1606 int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
1609 struct omap_hwmod *temp_oh;
1615 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1616 ret = (*fn)(temp_oh, data);
1626 * omap_hwmod_init - init omap_hwmod code and register hwmods
1627 * @ohs: pointer to an array of omap_hwmods to register
1629 * Intended to be called early in boot before the clock framework is
1630 * initialized. If @ohs is not null, will register all omap_hwmods
1631 * listed in @ohs that are valid for this chip. Returns -EINVAL if
1632 * omap_hwmod_init() has already been called or 0 otherwise.
1634 int __init omap_hwmod_init(struct omap_hwmod **ohs)
1636 struct omap_hwmod *oh;
1649 if (omap_chip_is(oh->omap_chip)) {
1651 WARN(r, "omap_hwmod: %s: _register returned "
1652 "%d\n", oh->name, r);
1661 * omap_hwmod_late_init - do some post-clock framework initialization
1663 * Must be called after omap2_clk_init(). Resolves the struct clk names
1664 * to struct clk pointers for each registered omap_hwmod. Also calls
1665 * _setup() on each hwmod. Returns 0.
1667 int omap_hwmod_late_init(void)
1671 /* XXX check return value */
1672 r = omap_hwmod_for_each(_init_clocks, NULL);
1673 WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n");
1675 mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME);
1676 WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n",
1677 MPU_INITIATOR_NAME);
1679 omap_hwmod_for_each(_setup, NULL);
1685 * omap_hwmod_enable - enable an omap_hwmod
1686 * @oh: struct omap_hwmod *
1688 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
1689 * Returns -EINVAL on error or passes along the return value from _enable().
1691 int omap_hwmod_enable(struct omap_hwmod *oh)
1694 unsigned long flags;
1699 spin_lock_irqsave(&oh->_lock, flags);
1701 spin_unlock_irqrestore(&oh->_lock, flags);
1707 * omap_hwmod_idle - idle an omap_hwmod
1708 * @oh: struct omap_hwmod *
1710 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
1711 * Returns -EINVAL on error or passes along the return value from _idle().
1713 int omap_hwmod_idle(struct omap_hwmod *oh)
1715 unsigned long flags;
1720 spin_lock_irqsave(&oh->_lock, flags);
1722 spin_unlock_irqrestore(&oh->_lock, flags);
1728 * omap_hwmod_shutdown - shutdown an omap_hwmod
1729 * @oh: struct omap_hwmod *
1731 * Shutdown an omap_hwmod @oh. Intended to be called by
1732 * omap_device_shutdown(). Returns -EINVAL on error or passes along
1733 * the return value from _shutdown().
1735 int omap_hwmod_shutdown(struct omap_hwmod *oh)
1737 unsigned long flags;
1742 spin_lock_irqsave(&oh->_lock, flags);
1744 spin_unlock_irqrestore(&oh->_lock, flags);
1750 * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
1751 * @oh: struct omap_hwmod *oh
1753 * Intended to be called by the omap_device code.
1755 int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
1757 unsigned long flags;
1759 spin_lock_irqsave(&oh->_lock, flags);
1761 spin_unlock_irqrestore(&oh->_lock, flags);
1767 * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
1768 * @oh: struct omap_hwmod *oh
1770 * Intended to be called by the omap_device code.
1772 int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
1774 unsigned long flags;
1776 spin_lock_irqsave(&oh->_lock, flags);
1777 _disable_clocks(oh);
1778 spin_unlock_irqrestore(&oh->_lock, flags);
1784 * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
1785 * @oh: struct omap_hwmod *oh
1787 * Intended to be called by drivers and core code when all posted
1788 * writes to a device must complete before continuing further
1789 * execution (for example, after clearing some device IRQSTATUS
1792 * XXX what about targets with multiple OCP threads?
1794 void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
1798 if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
1799 WARN(1, "omap_device: %s: OCP barrier impossible due to "
1800 "device configuration\n", oh->name);
1805 * Forces posted writes to complete on the OCP thread handling
1808 omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
1812 * omap_hwmod_reset - reset the hwmod
1813 * @oh: struct omap_hwmod *
1815 * Under some conditions, a driver may wish to reset the entire device.
1816 * Called from omap_device code. Returns -EINVAL on error or passes along
1817 * the return value from _reset().
1819 int omap_hwmod_reset(struct omap_hwmod *oh)
1822 unsigned long flags;
1827 spin_lock_irqsave(&oh->_lock, flags);
1829 spin_unlock_irqrestore(&oh->_lock, flags);
1835 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
1836 * @oh: struct omap_hwmod *
1837 * @res: pointer to the first element of an array of struct resource to fill
1839 * Count the number of struct resource array elements necessary to
1840 * contain omap_hwmod @oh resources. Intended to be called by code
1841 * that registers omap_devices. Intended to be used to determine the
1842 * size of a dynamically-allocated struct resource array, before
1843 * calling omap_hwmod_fill_resources(). Returns the number of struct
1844 * resource array elements needed.
1846 * XXX This code is not optimized. It could attempt to merge adjacent
1850 int omap_hwmod_count_resources(struct omap_hwmod *oh)
1854 ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
1856 for (i = 0; i < oh->slaves_cnt; i++)
1857 ret += oh->slaves[i]->addr_cnt;
1863 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
1864 * @oh: struct omap_hwmod *
1865 * @res: pointer to the first element of an array of struct resource to fill
1867 * Fill the struct resource array @res with resource data from the
1868 * omap_hwmod @oh. Intended to be called by code that registers
1869 * omap_devices. See also omap_hwmod_count_resources(). Returns the
1870 * number of array elements filled.
1872 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
1877 /* For each IRQ, DMA, memory area, fill in array.*/
1879 for (i = 0; i < oh->mpu_irqs_cnt; i++) {
1880 (res + r)->name = (oh->mpu_irqs + i)->name;
1881 (res + r)->start = (oh->mpu_irqs + i)->irq;
1882 (res + r)->end = (oh->mpu_irqs + i)->irq;
1883 (res + r)->flags = IORESOURCE_IRQ;
1887 for (i = 0; i < oh->sdma_reqs_cnt; i++) {
1888 (res + r)->name = (oh->sdma_reqs + i)->name;
1889 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
1890 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
1891 (res + r)->flags = IORESOURCE_DMA;
1895 for (i = 0; i < oh->slaves_cnt; i++) {
1896 struct omap_hwmod_ocp_if *os;
1900 for (j = 0; j < os->addr_cnt; j++) {
1901 (res + r)->start = (os->addr + j)->pa_start;
1902 (res + r)->end = (os->addr + j)->pa_end;
1903 (res + r)->flags = IORESOURCE_MEM;
1912 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
1913 * @oh: struct omap_hwmod *
1915 * Return the powerdomain pointer associated with the OMAP module
1916 * @oh's main clock. If @oh does not have a main clk, return the
1917 * powerdomain associated with the interface clock associated with the
1918 * module's MPU port. (XXX Perhaps this should use the SDMA port
1919 * instead?) Returns NULL on error, or a struct powerdomain * on
1922 struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
1932 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
1934 c = oh->slaves[oh->_mpu_port_index]->_clk;
1940 return c->clkdm->pwrdm.ptr;
1945 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
1946 * @oh: struct omap_hwmod *
1948 * Returns the virtual address corresponding to the beginning of the
1949 * module's register target, in the address range that is intended to
1950 * be used by the MPU. Returns the virtual address upon success or NULL
1953 void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
1958 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
1961 if (oh->_state == _HWMOD_STATE_UNKNOWN)
1964 return oh->_mpu_rt_va;
1968 * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
1969 * @oh: struct omap_hwmod *
1970 * @init_oh: struct omap_hwmod * (initiator)
1972 * Add a sleep dependency between the initiator @init_oh and @oh.
1973 * Intended to be called by DSP/Bridge code via platform_data for the
1974 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
1975 * code needs to add/del initiator dependencies dynamically
1976 * before/after accessing a device. Returns the return value from
1977 * _add_initiator_dep().
1979 * XXX Keep a usecount in the clockdomain code
1981 int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
1982 struct omap_hwmod *init_oh)
1984 return _add_initiator_dep(oh, init_oh);
1988 * XXX what about functions for drivers to save/restore ocp_sysconfig
1989 * for context save/restore operations?
1993 * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
1994 * @oh: struct omap_hwmod *
1995 * @init_oh: struct omap_hwmod * (initiator)
1997 * Remove a sleep dependency between the initiator @init_oh and @oh.
1998 * Intended to be called by DSP/Bridge code via platform_data for the
1999 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
2000 * code needs to add/del initiator dependencies dynamically
2001 * before/after accessing a device. Returns the return value from
2002 * _del_initiator_dep().
2004 * XXX Keep a usecount in the clockdomain code
2006 int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
2007 struct omap_hwmod *init_oh)
2009 return _del_initiator_dep(oh, init_oh);
2013 * omap_hwmod_enable_wakeup - allow device to wake up the system
2014 * @oh: struct omap_hwmod *
2016 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
2017 * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
2018 * registers to cause the PRCM to receive wakeup events from the
2019 * module. Does not set any wakeup routing registers beyond this
2020 * point - if the module is to wake up any other module or subsystem,
2021 * that must be set separately. Called by omap_device code. Returns
2022 * -EINVAL on error or 0 upon success.
2024 int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
2026 unsigned long flags;
2029 if (!oh->class->sysc ||
2030 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
2033 spin_lock_irqsave(&oh->_lock, flags);
2034 v = oh->_sysc_cache;
2035 _enable_wakeup(oh, &v);
2036 _write_sysconfig(v, oh);
2037 spin_unlock_irqrestore(&oh->_lock, flags);
2043 * omap_hwmod_disable_wakeup - prevent device from waking the system
2044 * @oh: struct omap_hwmod *
2046 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
2047 * from sending wakeups to the PRCM. Eventually this should clear
2048 * PRCM wakeup registers to cause the PRCM to ignore wakeup events
2049 * from the module. Does not set any wakeup routing registers beyond
2050 * this point - if the module is to wake up any other module or
2051 * subsystem, that must be set separately. Called by omap_device
2052 * code. Returns -EINVAL on error or 0 upon success.
2054 int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
2056 unsigned long flags;
2059 if (!oh->class->sysc ||
2060 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
2063 spin_lock_irqsave(&oh->_lock, flags);
2064 v = oh->_sysc_cache;
2065 _disable_wakeup(oh, &v);
2066 _write_sysconfig(v, oh);
2067 spin_unlock_irqrestore(&oh->_lock, flags);
2073 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
2074 * contained in the hwmod module.
2075 * @oh: struct omap_hwmod *
2076 * @name: name of the reset line to lookup and assert
2078 * Some IP like dsp, ipu or iva contain processor that require
2079 * an HW reset line to be assert / deassert in order to enable fully
2080 * the IP. Returns -EINVAL if @oh is null or if the operation is not
2081 * yet supported on this OMAP; otherwise, passes along the return value
2082 * from _assert_hardreset().
2084 int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
2087 unsigned long flags;
2092 spin_lock_irqsave(&oh->_lock, flags);
2093 ret = _assert_hardreset(oh, name);
2094 spin_unlock_irqrestore(&oh->_lock, flags);
2100 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
2101 * contained in the hwmod module.
2102 * @oh: struct omap_hwmod *
2103 * @name: name of the reset line to look up and deassert
2105 * Some IP like dsp, ipu or iva contain processor that require
2106 * an HW reset line to be assert / deassert in order to enable fully
2107 * the IP. Returns -EINVAL if @oh is null or if the operation is not
2108 * yet supported on this OMAP; otherwise, passes along the return value
2109 * from _deassert_hardreset().
2111 int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
2114 unsigned long flags;
2119 spin_lock_irqsave(&oh->_lock, flags);
2120 ret = _deassert_hardreset(oh, name);
2121 spin_unlock_irqrestore(&oh->_lock, flags);
2127 * omap_hwmod_read_hardreset - read the HW reset line state of submodules
2128 * contained in the hwmod module
2129 * @oh: struct omap_hwmod *
2130 * @name: name of the reset line to look up and read
2132 * Return the current state of the hwmod @oh's reset line named @name:
2133 * returns -EINVAL upon parameter error or if this operation
2134 * is unsupported on the current OMAP; otherwise, passes along the return
2135 * value from _read_hardreset().
2137 int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
2140 unsigned long flags;
2145 spin_lock_irqsave(&oh->_lock, flags);
2146 ret = _read_hardreset(oh, name);
2147 spin_unlock_irqrestore(&oh->_lock, flags);
2154 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
2155 * @classname: struct omap_hwmod_class name to search for
2156 * @fn: callback function pointer to call for each hwmod in class @classname
2157 * @user: arbitrary context data to pass to the callback function
2159 * For each omap_hwmod of class @classname, call @fn.
2160 * If the callback function returns something other than
2161 * zero, the iterator is terminated, and the callback function's return
2162 * value is passed back to the caller. Returns 0 upon success, -EINVAL
2163 * if @classname or @fn are NULL, or passes back the error code from @fn.
2165 int omap_hwmod_for_each_by_class(const char *classname,
2166 int (*fn)(struct omap_hwmod *oh,
2170 struct omap_hwmod *temp_oh;
2173 if (!classname || !fn)
2176 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
2177 __func__, classname);
2179 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
2180 if (!strcmp(temp_oh->class->name, classname)) {
2181 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
2182 __func__, temp_oh->name);
2183 ret = (*fn)(temp_oh, user);
2190 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
2197 * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
2198 * @oh: struct omap_hwmod *
2199 * @state: state that _setup() should leave the hwmod in
2201 * Sets the hwmod state that @oh will enter at the end of _setup() (called by
2202 * omap_hwmod_late_init()). Only valid to call between calls to
2203 * omap_hwmod_init() and omap_hwmod_late_init(). Returns 0 upon success or
2204 * -EINVAL if there is a problem with the arguments or if the hwmod is
2205 * in the wrong state.
2207 int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
2210 unsigned long flags;
2215 if (state != _HWMOD_STATE_DISABLED &&
2216 state != _HWMOD_STATE_ENABLED &&
2217 state != _HWMOD_STATE_IDLE)
2220 spin_lock_irqsave(&oh->_lock, flags);
2222 if (oh->_state != _HWMOD_STATE_REGISTERED) {
2227 oh->_postsetup_state = state;
2231 spin_unlock_irqrestore(&oh->_lock, flags);
2237 * omap_hwmod_get_context_loss_count - get lost context count
2238 * @oh: struct omap_hwmod *
2240 * Query the powerdomain of of @oh to get the context loss
2241 * count for this device.
2243 * Returns the context loss count of the powerdomain assocated with @oh
2244 * upon success, or zero if no powerdomain exists for @oh.
2246 u32 omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
2248 struct powerdomain *pwrdm;
2251 pwrdm = omap_hwmod_get_pwrdm(oh);
2253 ret = pwrdm_get_context_loss_count(pwrdm);
2259 * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
2260 * @oh: struct omap_hwmod *
2262 * Prevent the hwmod @oh from being reset during the setup process.
2263 * Intended for use by board-*.c files on boards with devices that
2264 * cannot tolerate being reset. Must be called before the hwmod has
2265 * been set up. Returns 0 upon success or negative error code upon
2268 int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
2273 if (oh->_state != _HWMOD_STATE_REGISTERED) {
2274 pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
2279 oh->flags |= HWMOD_INIT_NO_RESET;