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.
16 * This code manages "OMAP modules" (on-chip devices) and their
17 * integration with Linux device driver and bus code.
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
29 * - bus throughput & module latency measurement code
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
38 #include <linux/kernel.h>
39 #include <linux/errno.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>
47 #include <plat/common.h>
49 #include <plat/clockdomain.h>
50 #include <plat/powerdomain.h>
51 #include <plat/clock.h>
52 #include <plat/omap_hwmod.h>
53 #include <plat/prcm.h>
58 /* Maximum microseconds to wait for OMAP module to softreset */
59 #define MAX_MODULE_SOFTRESET_WAIT 10000
61 /* Name of the OMAP hwmod for the MPU */
62 #define MPU_INITIATOR_NAME "mpu"
64 /* omap_hwmod_list contains all registered struct omap_hwmods */
65 static LIST_HEAD(omap_hwmod_list);
67 static DEFINE_MUTEX(omap_hwmod_mutex);
69 /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
70 static struct omap_hwmod *mpu_oh;
72 /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */
76 /* Private functions */
79 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
80 * @oh: struct omap_hwmod *
82 * Load the current value of the hwmod OCP_SYSCONFIG register into the
83 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
84 * OCP_SYSCONFIG register or 0 upon success.
86 static int _update_sysc_cache(struct omap_hwmod *oh)
88 if (!oh->class->sysc) {
89 WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
93 /* XXX ensure module interface clock is up */
95 oh->_sysc_cache = omap_hwmod_readl(oh, oh->class->sysc->sysc_offs);
97 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
98 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
104 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
105 * @v: OCP_SYSCONFIG value to write
106 * @oh: struct omap_hwmod *
108 * Write @v into the module class' OCP_SYSCONFIG register, if it has
109 * one. No return value.
111 static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
113 if (!oh->class->sysc) {
114 WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
118 /* XXX ensure module interface clock is up */
120 if (oh->_sysc_cache != v) {
122 omap_hwmod_writel(v, oh, oh->class->sysc->sysc_offs);
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
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.
136 static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
142 if (!oh->class->sysc ||
143 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
146 if (!oh->class->sysc->sysc_fields) {
147 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
151 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
152 mstandby_mask = (0x3 << mstandby_shift);
154 *v &= ~mstandby_mask;
155 *v |= __ffs(standbymode) << mstandby_shift;
161 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
162 * @oh: struct omap_hwmod *
163 * @idlemode: SIDLEMODE field bits
164 * @v: pointer to register contents to modify
166 * Update the slave idle mode bits in @v to be @idlemode for the @oh
167 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
170 static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
175 if (!oh->class->sysc ||
176 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
179 if (!oh->class->sysc->sysc_fields) {
180 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
184 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
185 sidle_mask = (0x3 << sidle_shift);
188 *v |= __ffs(idlemode) << sidle_shift;
194 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
195 * @oh: struct omap_hwmod *
196 * @clockact: CLOCKACTIVITY field bits
197 * @v: pointer to register contents to modify
199 * Update the clockactivity mode bits in @v to be @clockact for the
200 * @oh hwmod. Used for additional powersaving on some modules. Does
201 * not write to the hardware. Returns -EINVAL upon error or 0 upon
204 static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
209 if (!oh->class->sysc ||
210 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
213 if (!oh->class->sysc->sysc_fields) {
214 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
218 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
219 clkact_mask = (0x3 << clkact_shift);
222 *v |= clockact << clkact_shift;
228 * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
229 * @oh: struct omap_hwmod *
230 * @v: pointer to register contents to modify
232 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
233 * error or 0 upon success.
235 static int _set_softreset(struct omap_hwmod *oh, u32 *v)
239 if (!oh->class->sysc ||
240 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
243 if (!oh->class->sysc->sysc_fields) {
244 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
248 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
256 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
257 * @oh: struct omap_hwmod *
258 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
259 * @v: pointer to register contents to modify
261 * Update the module autoidle bit in @v to be @autoidle for the @oh
262 * hwmod. The autoidle bit controls whether the module can gate
263 * internal clocks automatically when it isn't doing anything; the
264 * exact function of this bit varies on a per-module basis. This
265 * function does not write to the hardware. Returns -EINVAL upon
266 * error or 0 upon success.
268 static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
274 if (!oh->class->sysc ||
275 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
278 if (!oh->class->sysc->sysc_fields) {
279 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
283 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
284 autoidle_mask = (0x3 << autoidle_shift);
286 *v &= ~autoidle_mask;
287 *v |= autoidle << autoidle_shift;
293 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
294 * @oh: struct omap_hwmod *
296 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
297 * upon error or 0 upon success.
299 static int _enable_wakeup(struct omap_hwmod *oh)
303 if (!oh->class->sysc ||
304 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
307 if (!oh->class->sysc->sysc_fields) {
308 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
312 wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
316 _write_sysconfig(v, oh);
318 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
320 oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
326 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
327 * @oh: struct omap_hwmod *
329 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
330 * upon error or 0 upon success.
332 static int _disable_wakeup(struct omap_hwmod *oh)
336 if (!oh->class->sysc ||
337 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
340 if (!oh->class->sysc->sysc_fields) {
341 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
345 wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
349 _write_sysconfig(v, oh);
351 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
353 oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
359 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
360 * @oh: struct omap_hwmod *
362 * Prevent the hardware module @oh from entering idle while the
363 * hardare module initiator @init_oh is active. Useful when a module
364 * will be accessed by a particular initiator (e.g., if a module will
365 * be accessed by the IVA, there should be a sleepdep between the IVA
366 * initiator and the module). Only applies to modules in smart-idle
367 * mode. Returns -EINVAL upon error or passes along
368 * clkdm_add_sleepdep() value upon success.
370 static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
375 return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
379 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
380 * @oh: struct omap_hwmod *
382 * Allow the hardware module @oh to enter idle while the hardare
383 * module initiator @init_oh is active. Useful when a module will not
384 * be accessed by a particular initiator (e.g., if a module will not
385 * be accessed by the IVA, there should be no sleepdep between the IVA
386 * initiator and the module). Only applies to modules in smart-idle
387 * mode. Returns -EINVAL upon error or passes along
388 * clkdm_del_sleepdep() value upon success.
390 static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
395 return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
399 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
400 * @oh: struct omap_hwmod *
402 * Called from _init_clocks(). Populates the @oh _clk (main
403 * functional clock pointer) if a main_clk is present. Returns 0 on
404 * success or -EINVAL on error.
406 static int _init_main_clk(struct omap_hwmod *oh)
413 oh->_clk = omap_clk_get_by_name(oh->main_clk);
415 pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
416 oh->name, oh->main_clk);
420 if (!oh->_clk->clkdm)
421 pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n",
422 oh->main_clk, oh->_clk->name);
428 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
429 * @oh: struct omap_hwmod *
431 * Called from _init_clocks(). Populates the @oh OCP slave interface
432 * clock pointers. Returns 0 on success or -EINVAL on error.
434 static int _init_interface_clks(struct omap_hwmod *oh)
440 if (oh->slaves_cnt == 0)
443 for (i = 0; i < oh->slaves_cnt; i++) {
444 struct omap_hwmod_ocp_if *os = oh->slaves[i];
449 c = omap_clk_get_by_name(os->clk);
451 pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
462 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
463 * @oh: struct omap_hwmod *
465 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
466 * clock pointers. Returns 0 on success or -EINVAL on error.
468 static int _init_opt_clks(struct omap_hwmod *oh)
470 struct omap_hwmod_opt_clk *oc;
475 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
476 c = omap_clk_get_by_name(oc->clk);
478 pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
489 * _enable_clocks - enable hwmod main clock and interface clocks
490 * @oh: struct omap_hwmod *
492 * Enables all clocks necessary for register reads and writes to succeed
493 * on the hwmod @oh. Returns 0.
495 static int _enable_clocks(struct omap_hwmod *oh)
499 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
502 clk_enable(oh->_clk);
504 if (oh->slaves_cnt > 0) {
505 for (i = 0; i < oh->slaves_cnt; i++) {
506 struct omap_hwmod_ocp_if *os = oh->slaves[i];
507 struct clk *c = os->_clk;
509 if (c && (os->flags & OCPIF_SWSUP_IDLE))
514 /* The opt clocks are controlled by the device driver. */
520 * _disable_clocks - disable hwmod main clock and interface clocks
521 * @oh: struct omap_hwmod *
523 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
525 static int _disable_clocks(struct omap_hwmod *oh)
529 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
532 clk_disable(oh->_clk);
534 if (oh->slaves_cnt > 0) {
535 for (i = 0; i < oh->slaves_cnt; i++) {
536 struct omap_hwmod_ocp_if *os = oh->slaves[i];
537 struct clk *c = os->_clk;
539 if (c && (os->flags & OCPIF_SWSUP_IDLE))
544 /* The opt clocks are controlled by the device driver. */
550 * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
551 * @oh: struct omap_hwmod *
553 * Returns the array index of the OCP slave port that the MPU
554 * addresses the device on, or -EINVAL upon error or not found.
556 static int _find_mpu_port_index(struct omap_hwmod *oh)
561 if (!oh || oh->slaves_cnt == 0)
564 for (i = 0; i < oh->slaves_cnt; i++) {
565 struct omap_hwmod_ocp_if *os = oh->slaves[i];
567 if (os->user & OCP_USER_MPU) {
574 pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
577 pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
580 return (found) ? i : -EINVAL;
584 * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
585 * @oh: struct omap_hwmod *
587 * Return the virtual address of the base of the register target of
588 * device @oh, or NULL on error.
590 static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
592 struct omap_hwmod_ocp_if *os;
593 struct omap_hwmod_addr_space *mem;
596 void __iomem *va_start;
598 if (!oh || oh->slaves_cnt == 0)
601 os = oh->slaves[index];
603 for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) {
604 if (mem->flags & ADDR_TYPE_RT) {
611 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
613 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
616 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
619 pr_debug("omap_hwmod: %s: no MPU register target found\n",
623 return (found) ? va_start : NULL;
627 * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG
628 * @oh: struct omap_hwmod *
630 * If module is marked as SWSUP_SIDLE, force the module out of slave
631 * idle; otherwise, configure it for smart-idle. If module is marked
632 * as SWSUP_MSUSPEND, force the module out of master standby;
633 * otherwise, configure it for smart-standby. No return value.
635 static void _sysc_enable(struct omap_hwmod *oh)
640 if (!oh->class->sysc)
644 sf = oh->class->sysc->sysc_flags;
646 if (sf & SYSC_HAS_SIDLEMODE) {
647 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
648 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
649 _set_slave_idlemode(oh, idlemode, &v);
652 if (sf & SYSC_HAS_MIDLEMODE) {
653 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
654 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
655 _set_master_standbymode(oh, idlemode, &v);
658 if (sf & SYSC_HAS_AUTOIDLE) {
659 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
661 _set_module_autoidle(oh, idlemode, &v);
664 /* XXX OCP ENAWAKEUP bit? */
667 * XXX The clock framework should handle this, by
668 * calling into this code. But this must wait until the
669 * clock structures are tagged with omap_hwmod entries
671 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
672 (sf & SYSC_HAS_CLOCKACTIVITY))
673 _set_clockactivity(oh, oh->class->sysc->clockact, &v);
675 _write_sysconfig(v, oh);
679 * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG
680 * @oh: struct omap_hwmod *
682 * If module is marked as SWSUP_SIDLE, force the module into slave
683 * idle; otherwise, configure it for smart-idle. If module is marked
684 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
685 * configure it for smart-standby. No return value.
687 static void _sysc_idle(struct omap_hwmod *oh)
692 if (!oh->class->sysc)
696 sf = oh->class->sysc->sysc_flags;
698 if (sf & SYSC_HAS_SIDLEMODE) {
699 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
700 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
701 _set_slave_idlemode(oh, idlemode, &v);
704 if (sf & SYSC_HAS_MIDLEMODE) {
705 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
706 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
707 _set_master_standbymode(oh, idlemode, &v);
710 _write_sysconfig(v, oh);
714 * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG
715 * @oh: struct omap_hwmod *
717 * Force the module into slave idle and master suspend. No return
720 static void _sysc_shutdown(struct omap_hwmod *oh)
725 if (!oh->class->sysc)
729 sf = oh->class->sysc->sysc_flags;
731 if (sf & SYSC_HAS_SIDLEMODE)
732 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
734 if (sf & SYSC_HAS_MIDLEMODE)
735 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
737 if (sf & SYSC_HAS_AUTOIDLE)
738 _set_module_autoidle(oh, 1, &v);
740 _write_sysconfig(v, oh);
744 * _lookup - find an omap_hwmod by name
745 * @name: find an omap_hwmod by name
747 * Return a pointer to an omap_hwmod by name, or NULL if not found.
748 * Caller must hold omap_hwmod_mutex.
750 static struct omap_hwmod *_lookup(const char *name)
752 struct omap_hwmod *oh, *temp_oh;
756 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
757 if (!strcmp(name, temp_oh->name)) {
767 * _init_clocks - clk_get() all clocks associated with this hwmod
768 * @oh: struct omap_hwmod *
769 * @data: not used; pass NULL
771 * Called by omap_hwmod_late_init() (after omap2_clk_init()).
772 * Resolves all clock names embedded in the hwmod. Returns -EINVAL if
773 * the omap_hwmod has not yet been registered or if the clocks have
774 * already been initialized, 0 on success, or a non-zero error on
777 static int _init_clocks(struct omap_hwmod *oh, void *data)
781 if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED))
784 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
786 ret |= _init_main_clk(oh);
787 ret |= _init_interface_clks(oh);
788 ret |= _init_opt_clks(oh);
791 oh->_state = _HWMOD_STATE_CLKS_INITED;
797 * _wait_target_ready - wait for a module to leave slave idle
798 * @oh: struct omap_hwmod *
800 * Wait for a module @oh to leave slave idle. Returns 0 if the module
801 * does not have an IDLEST bit or if the module successfully leaves
802 * slave idle; otherwise, pass along the return value of the
803 * appropriate *_cm_wait_module_ready() function.
805 static int _wait_target_ready(struct omap_hwmod *oh)
807 struct omap_hwmod_ocp_if *os;
813 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
816 os = oh->slaves[oh->_mpu_port_index];
818 if (oh->flags & HWMOD_NO_IDLEST)
821 /* XXX check module SIDLEMODE */
823 /* XXX check clock enable states */
825 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
826 ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
827 oh->prcm.omap2.idlest_reg_id,
828 oh->prcm.omap2.idlest_idle_bit);
829 } else if (cpu_is_omap44xx()) {
830 ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg);
839 * _lookup_hardreset - return the register bit shift for this hwmod/reset line
840 * @oh: struct omap_hwmod *
841 * @name: name of the reset line in the context of this hwmod
843 * Return the bit position of the reset line that match the
844 * input name. Return -ENOENT if not found.
846 static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name)
850 for (i = 0; i < oh->rst_lines_cnt; i++) {
851 const char *rst_line = oh->rst_lines[i].name;
852 if (!strcmp(rst_line, name)) {
853 u8 shift = oh->rst_lines[i].rst_shift;
854 pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n",
855 oh->name, rst_line, shift);
865 * _assert_hardreset - assert the HW reset line of submodules
866 * contained in the hwmod module.
867 * @oh: struct omap_hwmod *
868 * @name: name of the reset line to lookup and assert
870 * Some IP like dsp, ipu or iva contain processor that require
871 * an HW reset line to be assert / deassert in order to enable fully
874 static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
881 shift = _lookup_hardreset(oh, name);
882 if (IS_ERR_VALUE(shift))
885 if (cpu_is_omap24xx() || cpu_is_omap34xx())
886 return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
888 else if (cpu_is_omap44xx())
889 return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg,
896 * _deassert_hardreset - deassert the HW reset line of submodules contained
897 * in the hwmod module.
898 * @oh: struct omap_hwmod *
899 * @name: name of the reset line to look up and deassert
901 * Some IP like dsp, ipu or iva contain processor that require
902 * an HW reset line to be assert / deassert in order to enable fully
905 static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
913 shift = _lookup_hardreset(oh, name);
914 if (IS_ERR_VALUE(shift))
917 if (cpu_is_omap24xx() || cpu_is_omap34xx())
918 r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
920 else if (cpu_is_omap44xx())
921 r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg,
927 pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
933 * _read_hardreset - read the HW reset line state of submodules
934 * contained in the hwmod module
935 * @oh: struct omap_hwmod *
936 * @name: name of the reset line to look up and read
938 * Return the state of the reset line.
940 static int _read_hardreset(struct omap_hwmod *oh, const char *name)
947 shift = _lookup_hardreset(oh, name);
948 if (IS_ERR_VALUE(shift))
951 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
952 return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
954 } else if (cpu_is_omap44xx()) {
955 return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg,
963 * _reset - reset an omap_hwmod
964 * @oh: struct omap_hwmod *
966 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
967 * enabled for this to work. Returns -EINVAL if the hwmod cannot be
968 * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if
969 * the module did not reset in time, or 0 upon success.
971 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
972 * Starting in OMAP4, some IPs does not have SYSSTATUS register and instead
973 * use the SYSCONFIG softreset bit to provide the status.
975 * Note that some IP like McBSP does have a reset control but no reset status.
977 static int _reset(struct omap_hwmod *oh)
982 if (!oh->class->sysc ||
983 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
986 /* clocks must be on for this operation */
987 if (oh->_state != _HWMOD_STATE_ENABLED) {
988 pr_warning("omap_hwmod: %s: reset can only be entered from "
989 "enabled state\n", oh->name);
993 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
996 r = _set_softreset(oh, &v);
999 _write_sysconfig(v, oh);
1001 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
1002 omap_test_timeout((omap_hwmod_readl(oh,
1003 oh->class->sysc->syss_offs)
1004 & SYSS_RESETDONE_MASK),
1005 MAX_MODULE_SOFTRESET_WAIT, c);
1006 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS)
1007 omap_test_timeout(!(omap_hwmod_readl(oh,
1008 oh->class->sysc->sysc_offs)
1009 & SYSC_TYPE2_SOFTRESET_MASK),
1010 MAX_MODULE_SOFTRESET_WAIT, c);
1012 if (c == MAX_MODULE_SOFTRESET_WAIT)
1013 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1014 oh->name, MAX_MODULE_SOFTRESET_WAIT);
1016 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1019 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1020 * _wait_target_ready() or _reset()
1023 return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1027 * _omap_hwmod_enable - enable an omap_hwmod
1028 * @oh: struct omap_hwmod *
1030 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
1031 * register target. Returns -EINVAL if the hwmod is in the wrong
1032 * state or passes along the return value of _wait_target_ready().
1034 int _omap_hwmod_enable(struct omap_hwmod *oh)
1038 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1039 oh->_state != _HWMOD_STATE_IDLE &&
1040 oh->_state != _HWMOD_STATE_DISABLED) {
1041 WARN(1, "omap_hwmod: %s: enabled state can only be entered "
1042 "from initialized, idle, or disabled state\n", oh->name);
1046 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1049 * If an IP contains only one HW reset line, then de-assert it in order
1050 * to allow to enable the clocks. Otherwise the PRCM will return
1051 * Intransition status, and the init will failed.
1053 if ((oh->_state == _HWMOD_STATE_INITIALIZED ||
1054 oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1)
1055 _deassert_hardreset(oh, oh->rst_lines[0].name);
1059 _add_initiator_dep(oh, mpu_oh);
1062 r = _wait_target_ready(oh);
1064 oh->_state = _HWMOD_STATE_ENABLED;
1066 /* Access the sysconfig only if the target is ready */
1067 if (oh->class->sysc) {
1068 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
1069 _update_sysc_cache(oh);
1073 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
1081 * _idle - idle an omap_hwmod
1082 * @oh: struct omap_hwmod *
1084 * Idles an omap_hwmod @oh. This should be called once the hwmod has
1085 * no further work. Returns -EINVAL if the hwmod is in the wrong
1086 * state or returns 0.
1088 int _omap_hwmod_idle(struct omap_hwmod *oh)
1090 if (oh->_state != _HWMOD_STATE_ENABLED) {
1091 WARN(1, "omap_hwmod: %s: idle state can only be entered from "
1092 "enabled state\n", oh->name);
1096 pr_debug("omap_hwmod: %s: idling\n", oh->name);
1098 if (oh->class->sysc)
1100 _del_initiator_dep(oh, mpu_oh);
1101 _disable_clocks(oh);
1103 oh->_state = _HWMOD_STATE_IDLE;
1109 * _shutdown - shutdown an omap_hwmod
1110 * @oh: struct omap_hwmod *
1112 * Shut down an omap_hwmod @oh. This should be called when the driver
1113 * used for the hwmod is removed or unloaded or if the driver is not
1114 * used by the system. Returns -EINVAL if the hwmod is in the wrong
1115 * state or returns 0.
1117 static int _shutdown(struct omap_hwmod *oh)
1119 if (oh->_state != _HWMOD_STATE_IDLE &&
1120 oh->_state != _HWMOD_STATE_ENABLED) {
1121 WARN(1, "omap_hwmod: %s: disabled state can only be entered "
1122 "from idle, or enabled state\n", oh->name);
1126 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
1128 if (oh->class->sysc)
1132 * If an IP contains only one HW reset line, then assert it
1133 * before disabling the clocks and shutting down the IP.
1135 if (oh->rst_lines_cnt == 1)
1136 _assert_hardreset(oh, oh->rst_lines[0].name);
1138 /* clocks and deps are already disabled in idle */
1139 if (oh->_state == _HWMOD_STATE_ENABLED) {
1140 _del_initiator_dep(oh, mpu_oh);
1141 /* XXX what about the other system initiators here? dma, dsp */
1142 _disable_clocks(oh);
1144 /* XXX Should this code also force-disable the optional clocks? */
1146 /* XXX mux any associated balls to safe mode */
1148 oh->_state = _HWMOD_STATE_DISABLED;
1154 * _setup - do initial configuration of omap_hwmod
1155 * @oh: struct omap_hwmod *
1156 * @skip_setup_idle_p: do not idle hwmods at the end of the fn if 1
1158 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
1159 * OCP_SYSCONFIG register. @skip_setup_idle is intended to be used on
1160 * a system that will not call omap_hwmod_enable() to enable devices
1161 * (e.g., a system without PM runtime). Returns -EINVAL if the hwmod
1162 * is in the wrong state or returns 0.
1164 static int _setup(struct omap_hwmod *oh, void *data)
1172 skip_setup_idle = *(u8 *)data;
1174 /* Set iclk autoidle mode */
1175 if (oh->slaves_cnt > 0) {
1176 for (i = 0; i < oh->slaves_cnt; i++) {
1177 struct omap_hwmod_ocp_if *os = oh->slaves[i];
1178 struct clk *c = os->_clk;
1183 if (os->flags & OCPIF_SWSUP_IDLE) {
1184 /* XXX omap_iclk_deny_idle(c); */
1186 /* XXX omap_iclk_allow_idle(c); */
1192 mutex_init(&oh->_mutex);
1193 oh->_state = _HWMOD_STATE_INITIALIZED;
1196 * In the case of hwmod with hardreset that should not be
1197 * de-assert at boot time, we have to keep the module
1198 * initialized, because we cannot enable it properly with the
1199 * reset asserted. Exit without warning because that behavior is
1202 if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1)
1205 r = _omap_hwmod_enable(oh);
1207 pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n",
1208 oh->name, oh->_state);
1212 if (!(oh->flags & HWMOD_INIT_NO_RESET)) {
1216 * OCP_SYSCONFIG bits need to be reprogrammed after a softreset.
1217 * The _omap_hwmod_enable() function should be split to
1218 * avoid the rewrite of the OCP_SYSCONFIG register.
1220 if (oh->class->sysc) {
1221 _update_sysc_cache(oh);
1226 if (!(oh->flags & HWMOD_INIT_NO_IDLE) && !skip_setup_idle)
1227 _omap_hwmod_idle(oh);
1234 /* Public functions */
1236 u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs)
1238 return __raw_readl(oh->_mpu_rt_va + reg_offs);
1241 void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs)
1243 __raw_writel(v, oh->_mpu_rt_va + reg_offs);
1247 * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
1248 * @oh: struct omap_hwmod *
1249 * @idlemode: SIDLEMODE field bits (shifted to bit 0)
1251 * Sets the IP block's OCP slave idlemode in hardware, and updates our
1252 * local copy. Intended to be used by drivers that have some erratum
1253 * that requires direct manipulation of the SIDLEMODE bits. Returns
1254 * -EINVAL if @oh is null, or passes along the return value from
1255 * _set_slave_idlemode().
1257 * XXX Does this function have any current users? If not, we should
1258 * remove it; it is better to let the rest of the hwmod code handle this.
1259 * Any users of this function should be scrutinized carefully.
1261 int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
1269 v = oh->_sysc_cache;
1271 retval = _set_slave_idlemode(oh, idlemode, &v);
1273 _write_sysconfig(v, oh);
1279 * omap_hwmod_register - register a struct omap_hwmod
1280 * @oh: struct omap_hwmod *
1282 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
1283 * already has been registered by the same name; -EINVAL if the
1284 * omap_hwmod is in the wrong state, if @oh is NULL, if the
1285 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
1286 * name, or if the omap_hwmod's class is missing a name; or 0 upon
1289 * XXX The data should be copied into bootmem, so the original data
1290 * should be marked __initdata and freed after init. This would allow
1291 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
1292 * that the copy process would be relatively complex due to the large number
1295 int omap_hwmod_register(struct omap_hwmod *oh)
1299 if (!oh || !oh->name || !oh->class || !oh->class->name ||
1300 (oh->_state != _HWMOD_STATE_UNKNOWN))
1303 mutex_lock(&omap_hwmod_mutex);
1305 pr_debug("omap_hwmod: %s: registering\n", oh->name);
1307 if (_lookup(oh->name)) {
1312 ms_id = _find_mpu_port_index(oh);
1313 if (!IS_ERR_VALUE(ms_id)) {
1314 oh->_mpu_port_index = ms_id;
1315 oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
1317 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
1320 list_add_tail(&oh->node, &omap_hwmod_list);
1322 oh->_state = _HWMOD_STATE_REGISTERED;
1327 mutex_unlock(&omap_hwmod_mutex);
1332 * omap_hwmod_lookup - look up a registered omap_hwmod by name
1333 * @name: name of the omap_hwmod to look up
1335 * Given a @name of an omap_hwmod, return a pointer to the registered
1336 * struct omap_hwmod *, or NULL upon error.
1338 struct omap_hwmod *omap_hwmod_lookup(const char *name)
1340 struct omap_hwmod *oh;
1345 mutex_lock(&omap_hwmod_mutex);
1347 mutex_unlock(&omap_hwmod_mutex);
1353 * omap_hwmod_for_each - call function for each registered omap_hwmod
1354 * @fn: pointer to a callback function
1355 * @data: void * data to pass to callback function
1357 * Call @fn for each registered omap_hwmod, passing @data to each
1358 * function. @fn must return 0 for success or any other value for
1359 * failure. If @fn returns non-zero, the iteration across omap_hwmods
1360 * will stop and the non-zero return value will be passed to the
1361 * caller of omap_hwmod_for_each(). @fn is called with
1362 * omap_hwmod_for_each() held.
1364 int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
1367 struct omap_hwmod *temp_oh;
1373 mutex_lock(&omap_hwmod_mutex);
1374 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1375 ret = (*fn)(temp_oh, data);
1379 mutex_unlock(&omap_hwmod_mutex);
1386 * omap_hwmod_init - init omap_hwmod code and register hwmods
1387 * @ohs: pointer to an array of omap_hwmods to register
1389 * Intended to be called early in boot before the clock framework is
1390 * initialized. If @ohs is not null, will register all omap_hwmods
1391 * listed in @ohs that are valid for this chip. Returns -EINVAL if
1392 * omap_hwmod_init() has already been called or 0 otherwise.
1394 int omap_hwmod_init(struct omap_hwmod **ohs)
1396 struct omap_hwmod *oh;
1409 if (omap_chip_is(oh->omap_chip)) {
1410 r = omap_hwmod_register(oh);
1411 WARN(r, "omap_hwmod: %s: omap_hwmod_register returned "
1412 "%d\n", oh->name, r);
1421 * omap_hwmod_late_init - do some post-clock framework initialization
1422 * @skip_setup_idle: if 1, do not idle hwmods in _setup()
1424 * Must be called after omap2_clk_init(). Resolves the struct clk names
1425 * to struct clk pointers for each registered omap_hwmod. Also calls
1426 * _setup() on each hwmod. Returns 0.
1428 int omap_hwmod_late_init(u8 skip_setup_idle)
1432 /* XXX check return value */
1433 r = omap_hwmod_for_each(_init_clocks, NULL);
1434 WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n");
1436 mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME);
1437 WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n",
1438 MPU_INITIATOR_NAME);
1440 if (skip_setup_idle)
1441 pr_debug("omap_hwmod: will leave hwmods enabled during setup\n");
1443 omap_hwmod_for_each(_setup, &skip_setup_idle);
1449 * omap_hwmod_unregister - unregister an omap_hwmod
1450 * @oh: struct omap_hwmod *
1452 * Unregisters a previously-registered omap_hwmod @oh. There's probably
1453 * no use case for this, so it is likely to be removed in a later version.
1455 * XXX Free all of the bootmem-allocated structures here when that is
1456 * implemented. Make it clear that core code is the only code that is
1457 * expected to unregister modules.
1459 int omap_hwmod_unregister(struct omap_hwmod *oh)
1464 pr_debug("omap_hwmod: %s: unregistering\n", oh->name);
1466 mutex_lock(&omap_hwmod_mutex);
1467 iounmap(oh->_mpu_rt_va);
1468 list_del(&oh->node);
1469 mutex_unlock(&omap_hwmod_mutex);
1475 * omap_hwmod_enable - enable an omap_hwmod
1476 * @oh: struct omap_hwmod *
1478 * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable().
1479 * Returns -EINVAL on error or passes along the return value from _enable().
1481 int omap_hwmod_enable(struct omap_hwmod *oh)
1488 mutex_lock(&oh->_mutex);
1489 r = _omap_hwmod_enable(oh);
1490 mutex_unlock(&oh->_mutex);
1497 * omap_hwmod_idle - idle an omap_hwmod
1498 * @oh: struct omap_hwmod *
1500 * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle().
1501 * Returns -EINVAL on error or passes along the return value from _idle().
1503 int omap_hwmod_idle(struct omap_hwmod *oh)
1508 mutex_lock(&oh->_mutex);
1509 _omap_hwmod_idle(oh);
1510 mutex_unlock(&oh->_mutex);
1516 * omap_hwmod_shutdown - shutdown an omap_hwmod
1517 * @oh: struct omap_hwmod *
1519 * Shutdown an omap_hwomd @oh. Intended to be called by
1520 * omap_device_shutdown(). Returns -EINVAL on error or passes along
1521 * the return value from _shutdown().
1523 int omap_hwmod_shutdown(struct omap_hwmod *oh)
1528 mutex_lock(&oh->_mutex);
1530 mutex_unlock(&oh->_mutex);
1536 * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
1537 * @oh: struct omap_hwmod *oh
1539 * Intended to be called by the omap_device code.
1541 int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
1543 mutex_lock(&oh->_mutex);
1545 mutex_unlock(&oh->_mutex);
1551 * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
1552 * @oh: struct omap_hwmod *oh
1554 * Intended to be called by the omap_device code.
1556 int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
1558 mutex_lock(&oh->_mutex);
1559 _disable_clocks(oh);
1560 mutex_unlock(&oh->_mutex);
1566 * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
1567 * @oh: struct omap_hwmod *oh
1569 * Intended to be called by drivers and core code when all posted
1570 * writes to a device must complete before continuing further
1571 * execution (for example, after clearing some device IRQSTATUS
1574 * XXX what about targets with multiple OCP threads?
1576 void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
1580 if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
1581 WARN(1, "omap_device: %s: OCP barrier impossible due to "
1582 "device configuration\n", oh->name);
1587 * Forces posted writes to complete on the OCP thread handling
1590 omap_hwmod_readl(oh, oh->class->sysc->sysc_offs);
1594 * omap_hwmod_reset - reset the hwmod
1595 * @oh: struct omap_hwmod *
1597 * Under some conditions, a driver may wish to reset the entire device.
1598 * Called from omap_device code. Returns -EINVAL on error or passes along
1599 * the return value from _reset().
1601 int omap_hwmod_reset(struct omap_hwmod *oh)
1608 mutex_lock(&oh->_mutex);
1610 mutex_unlock(&oh->_mutex);
1616 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
1617 * @oh: struct omap_hwmod *
1618 * @res: pointer to the first element of an array of struct resource to fill
1620 * Count the number of struct resource array elements necessary to
1621 * contain omap_hwmod @oh resources. Intended to be called by code
1622 * that registers omap_devices. Intended to be used to determine the
1623 * size of a dynamically-allocated struct resource array, before
1624 * calling omap_hwmod_fill_resources(). Returns the number of struct
1625 * resource array elements needed.
1627 * XXX This code is not optimized. It could attempt to merge adjacent
1631 int omap_hwmod_count_resources(struct omap_hwmod *oh)
1635 ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt;
1637 for (i = 0; i < oh->slaves_cnt; i++)
1638 ret += oh->slaves[i]->addr_cnt;
1644 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
1645 * @oh: struct omap_hwmod *
1646 * @res: pointer to the first element of an array of struct resource to fill
1648 * Fill the struct resource array @res with resource data from the
1649 * omap_hwmod @oh. Intended to be called by code that registers
1650 * omap_devices. See also omap_hwmod_count_resources(). Returns the
1651 * number of array elements filled.
1653 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
1658 /* For each IRQ, DMA, memory area, fill in array.*/
1660 for (i = 0; i < oh->mpu_irqs_cnt; i++) {
1661 (res + r)->name = (oh->mpu_irqs + i)->name;
1662 (res + r)->start = (oh->mpu_irqs + i)->irq;
1663 (res + r)->end = (oh->mpu_irqs + i)->irq;
1664 (res + r)->flags = IORESOURCE_IRQ;
1668 for (i = 0; i < oh->sdma_reqs_cnt; i++) {
1669 (res + r)->name = (oh->sdma_reqs + i)->name;
1670 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
1671 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
1672 (res + r)->flags = IORESOURCE_DMA;
1676 for (i = 0; i < oh->slaves_cnt; i++) {
1677 struct omap_hwmod_ocp_if *os;
1681 for (j = 0; j < os->addr_cnt; j++) {
1682 (res + r)->start = (os->addr + j)->pa_start;
1683 (res + r)->end = (os->addr + j)->pa_end;
1684 (res + r)->flags = IORESOURCE_MEM;
1693 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
1694 * @oh: struct omap_hwmod *
1696 * Return the powerdomain pointer associated with the OMAP module
1697 * @oh's main clock. If @oh does not have a main clk, return the
1698 * powerdomain associated with the interface clock associated with the
1699 * module's MPU port. (XXX Perhaps this should use the SDMA port
1700 * instead?) Returns NULL on error, or a struct powerdomain * on
1703 struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
1713 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
1715 c = oh->slaves[oh->_mpu_port_index]->_clk;
1721 return c->clkdm->pwrdm.ptr;
1726 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
1727 * @oh: struct omap_hwmod *
1729 * Returns the virtual address corresponding to the beginning of the
1730 * module's register target, in the address range that is intended to
1731 * be used by the MPU. Returns the virtual address upon success or NULL
1734 void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
1739 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
1742 if (oh->_state == _HWMOD_STATE_UNKNOWN)
1745 return oh->_mpu_rt_va;
1749 * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
1750 * @oh: struct omap_hwmod *
1751 * @init_oh: struct omap_hwmod * (initiator)
1753 * Add a sleep dependency between the initiator @init_oh and @oh.
1754 * Intended to be called by DSP/Bridge code via platform_data for the
1755 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
1756 * code needs to add/del initiator dependencies dynamically
1757 * before/after accessing a device. Returns the return value from
1758 * _add_initiator_dep().
1760 * XXX Keep a usecount in the clockdomain code
1762 int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
1763 struct omap_hwmod *init_oh)
1765 return _add_initiator_dep(oh, init_oh);
1769 * XXX what about functions for drivers to save/restore ocp_sysconfig
1770 * for context save/restore operations?
1774 * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
1775 * @oh: struct omap_hwmod *
1776 * @init_oh: struct omap_hwmod * (initiator)
1778 * Remove a sleep dependency between the initiator @init_oh and @oh.
1779 * Intended to be called by DSP/Bridge code via platform_data for the
1780 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
1781 * code needs to add/del initiator dependencies dynamically
1782 * before/after accessing a device. Returns the return value from
1783 * _del_initiator_dep().
1785 * XXX Keep a usecount in the clockdomain code
1787 int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
1788 struct omap_hwmod *init_oh)
1790 return _del_initiator_dep(oh, init_oh);
1794 * omap_hwmod_enable_wakeup - allow device to wake up the system
1795 * @oh: struct omap_hwmod *
1797 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
1798 * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
1799 * registers to cause the PRCM to receive wakeup events from the
1800 * module. Does not set any wakeup routing registers beyond this
1801 * point - if the module is to wake up any other module or subsystem,
1802 * that must be set separately. Called by omap_device code. Returns
1803 * -EINVAL on error or 0 upon success.
1805 int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
1807 if (!oh->class->sysc ||
1808 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
1811 mutex_lock(&oh->_mutex);
1813 mutex_unlock(&oh->_mutex);
1819 * omap_hwmod_disable_wakeup - prevent device from waking the system
1820 * @oh: struct omap_hwmod *
1822 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
1823 * from sending wakeups to the PRCM. Eventually this should clear
1824 * PRCM wakeup registers to cause the PRCM to ignore wakeup events
1825 * from the module. Does not set any wakeup routing registers beyond
1826 * this point - if the module is to wake up any other module or
1827 * subsystem, that must be set separately. Called by omap_device
1828 * code. Returns -EINVAL on error or 0 upon success.
1830 int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
1832 if (!oh->class->sysc ||
1833 !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP))
1836 mutex_lock(&oh->_mutex);
1837 _disable_wakeup(oh);
1838 mutex_unlock(&oh->_mutex);
1844 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
1845 * contained in the hwmod module.
1846 * @oh: struct omap_hwmod *
1847 * @name: name of the reset line to lookup and assert
1849 * Some IP like dsp, ipu or iva contain processor that require
1850 * an HW reset line to be assert / deassert in order to enable fully
1851 * the IP. Returns -EINVAL if @oh is null or if the operation is not
1852 * yet supported on this OMAP; otherwise, passes along the return value
1853 * from _assert_hardreset().
1855 int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
1862 mutex_lock(&oh->_mutex);
1863 ret = _assert_hardreset(oh, name);
1864 mutex_unlock(&oh->_mutex);
1870 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
1871 * contained in the hwmod module.
1872 * @oh: struct omap_hwmod *
1873 * @name: name of the reset line to look up and deassert
1875 * Some IP like dsp, ipu or iva contain processor that require
1876 * an HW reset line to be assert / deassert in order to enable fully
1877 * the IP. Returns -EINVAL if @oh is null or if the operation is not
1878 * yet supported on this OMAP; otherwise, passes along the return value
1879 * from _deassert_hardreset().
1881 int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
1888 mutex_lock(&oh->_mutex);
1889 ret = _deassert_hardreset(oh, name);
1890 mutex_unlock(&oh->_mutex);
1896 * omap_hwmod_read_hardreset - read the HW reset line state of submodules
1897 * contained in the hwmod module
1898 * @oh: struct omap_hwmod *
1899 * @name: name of the reset line to look up and read
1901 * Return the current state of the hwmod @oh's reset line named @name:
1902 * returns -EINVAL upon parameter error or if this operation
1903 * is unsupported on the current OMAP; otherwise, passes along the return
1904 * value from _read_hardreset().
1906 int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
1913 mutex_lock(&oh->_mutex);
1914 ret = _read_hardreset(oh, name);
1915 mutex_unlock(&oh->_mutex);
1922 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
1923 * @classname: struct omap_hwmod_class name to search for
1924 * @fn: callback function pointer to call for each hwmod in class @classname
1925 * @user: arbitrary context data to pass to the callback function
1927 * For each omap_hwmod of class @classname, call @fn. Takes
1928 * omap_hwmod_mutex to prevent the hwmod list from changing during the
1929 * iteration. If the callback function returns something other than
1930 * zero, the iterator is terminated, and the callback function's return
1931 * value is passed back to the caller. Returns 0 upon success, -EINVAL
1932 * if @classname or @fn are NULL, or passes back the error code from @fn.
1934 int omap_hwmod_for_each_by_class(const char *classname,
1935 int (*fn)(struct omap_hwmod *oh,
1939 struct omap_hwmod *temp_oh;
1942 if (!classname || !fn)
1945 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
1946 __func__, classname);
1948 mutex_lock(&omap_hwmod_mutex);
1950 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1951 if (!strcmp(temp_oh->class->name, classname)) {
1952 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
1953 __func__, temp_oh->name);
1954 ret = (*fn)(temp_oh, user);
1960 mutex_unlock(&omap_hwmod_mutex);
1963 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",