OMAP3: SR: Reset voltage level on SR disable
[linux-ginger.git] / arch / arm / mach-omap2 / omap_hwmod.c
blob633b216a8b26a14ddb33d4f483f1fc624a446b6b
1 /*
2 * omap_hwmod implementation for OMAP2/3/4
4 * Copyright (C) 2009 Nokia Corporation
5 * Paul Walmsley
6 * With fixes and testing from Kevin Hilman
8 * Created in collaboration with (alphabetical order): Benoit Cousson,
9 * Kevin Hilman, Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari
10 * Poussa, Anand Sawant, Santosh Shilimkar, Richard Woodruff
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.
19 * References:
20 * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
21 * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
22 * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
23 * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
24 * - Open Core Protocol Specification 2.2
26 * To do:
27 * - pin mux handling
28 * - handle IO mapping
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
34 * appropriate
36 #undef DEBUG
38 #include <linux/kernel.h>
39 #include <linux/errno.h>
40 #include <linux/io.h>
41 #include <linux/clk.h>
42 #include <linux/delay.h>
43 #include <linux/err.h>
44 #include <linux/list.h>
45 #include <linux/mutex.h>
46 #include <linux/bootmem.h>
48 #include <plat/cpu.h>
49 #include <plat/clockdomain.h>
50 #include <plat/powerdomain.h>
51 #include <plat/clock.h>
52 #include <plat/omap_hwmod.h>
54 #include "cm.h"
56 /* Maximum microseconds to wait for OMAP module to reset */
57 #define MAX_MODULE_RESET_WAIT 10000
59 /* Name of the OMAP hwmod for the MPU */
60 #define MPU_INITIATOR_NAME "mpu_hwmod"
62 /* omap_hwmod_list contains all registered struct omap_hwmods */
63 static LIST_HEAD(omap_hwmod_list);
65 static DEFINE_MUTEX(omap_hwmod_mutex);
67 /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
68 static struct omap_hwmod *mpu_oh;
70 /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */
71 static u8 inited;
74 /* Private functions */
76 /**
77 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
78 * @oh: struct omap_hwmod *
80 * Load the current value of the hwmod OCP_SYSCONFIG register into the
81 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
82 * OCP_SYSCONFIG register or 0 upon success.
84 static int _update_sysc_cache(struct omap_hwmod *oh)
86 if (!oh->sysconfig) {
87 WARN(!oh->sysconfig, "omap_hwmod: %s: cannot read "
88 "OCP_SYSCONFIG: not defined on hwmod\n", oh->name);
89 return -EINVAL;
92 /* XXX ensure module interface clock is up */
94 oh->_sysc_cache = omap_hwmod_readl(oh, oh->sysconfig->sysc_offs);
96 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
98 return 0;
102 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
103 * @v: OCP_SYSCONFIG value to write
104 * @oh: struct omap_hwmod *
106 * Write @v into the module OCP_SYSCONFIG register, if it has one. No
107 * return value.
109 static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
111 if (!oh->sysconfig) {
112 WARN(!oh->sysconfig, "omap_hwmod: %s: cannot write "
113 "OCP_SYSCONFIG: not defined on hwmod\n", oh->name);
114 return;
117 /* XXX ensure module interface clock is up */
119 if (oh->_sysc_cache != v) {
120 oh->_sysc_cache = v;
121 omap_hwmod_writel(v, oh, oh->sysconfig->sysc_offs);
126 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
127 * @oh: struct omap_hwmod *
128 * @standbymode: MIDLEMODE field bits
129 * @v: pointer to register contents to modify
131 * Update the master standby mode bits in @v to be @standbymode for
132 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
133 * upon error or 0 upon success.
135 static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
136 u32 *v)
138 if (!oh->sysconfig ||
139 !(oh->sysconfig->sysc_flags & SYSC_HAS_MIDLEMODE))
140 return -EINVAL;
142 *v &= ~SYSC_MIDLEMODE_MASK;
143 *v |= __ffs(standbymode) << SYSC_MIDLEMODE_SHIFT;
145 return 0;
149 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
150 * @oh: struct omap_hwmod *
151 * @idlemode: SIDLEMODE field bits
152 * @v: pointer to register contents to modify
154 * Update the slave idle mode bits in @v to be @idlemode for the @oh
155 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
156 * or 0 upon success.
158 static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
160 if (!oh->sysconfig ||
161 !(oh->sysconfig->sysc_flags & SYSC_HAS_SIDLEMODE))
162 return -EINVAL;
164 *v &= ~SYSC_SIDLEMODE_MASK;
165 *v |= __ffs(idlemode) << SYSC_SIDLEMODE_SHIFT;
167 return 0;
171 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
172 * @oh: struct omap_hwmod *
173 * @clockact: CLOCKACTIVITY field bits
174 * @v: pointer to register contents to modify
176 * Update the clockactivity mode bits in @v to be @clockact for the
177 * @oh hwmod. Used for additional powersaving on some modules. Does
178 * not write to the hardware. Returns -EINVAL upon error or 0 upon
179 * success.
181 static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
183 if (!oh->sysconfig ||
184 !(oh->sysconfig->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
185 return -EINVAL;
187 *v &= ~SYSC_CLOCKACTIVITY_MASK;
188 *v |= clockact << SYSC_CLOCKACTIVITY_SHIFT;
190 return 0;
194 * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
195 * @oh: struct omap_hwmod *
196 * @v: pointer to register contents to modify
198 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
199 * error or 0 upon success.
201 static int _set_softreset(struct omap_hwmod *oh, u32 *v)
203 if (!oh->sysconfig ||
204 !(oh->sysconfig->sysc_flags & SYSC_HAS_SOFTRESET))
205 return -EINVAL;
207 *v |= SYSC_SOFTRESET_MASK;
209 return 0;
213 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
214 * @oh: struct omap_hwmod *
216 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
217 * upon error or 0 upon success.
219 static int _enable_wakeup(struct omap_hwmod *oh)
221 u32 v;
223 if (!oh->sysconfig ||
224 !(oh->sysconfig->sysc_flags & SYSC_HAS_ENAWAKEUP))
225 return -EINVAL;
227 v = oh->_sysc_cache;
228 v |= SYSC_ENAWAKEUP_MASK;
229 _write_sysconfig(v, oh);
231 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
233 oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
235 return 0;
239 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
240 * @oh: struct omap_hwmod *
242 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
243 * upon error or 0 upon success.
245 static int _disable_wakeup(struct omap_hwmod *oh)
247 u32 v;
249 if (!oh->sysconfig ||
250 !(oh->sysconfig->sysc_flags & SYSC_HAS_ENAWAKEUP))
251 return -EINVAL;
253 v = oh->_sysc_cache;
254 v &= ~SYSC_ENAWAKEUP_MASK;
255 _write_sysconfig(v, oh);
257 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
259 oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
261 return 0;
265 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
266 * @oh: struct omap_hwmod *
268 * Prevent the hardware module @oh from entering idle while the
269 * hardare module initiator @init_oh is active. Useful when a module
270 * will be accessed by a particular initiator (e.g., if a module will
271 * be accessed by the IVA, there should be a sleepdep between the IVA
272 * initiator and the module). Only applies to modules in smart-idle
273 * mode. Returns -EINVAL upon error or passes along
274 * pwrdm_add_sleepdep() value upon success.
276 static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
278 if (!oh->_clk)
279 return -EINVAL;
281 return pwrdm_add_sleepdep(oh->_clk->clkdm->pwrdm.ptr,
282 init_oh->_clk->clkdm->pwrdm.ptr);
286 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
287 * @oh: struct omap_hwmod *
289 * Allow the hardware module @oh to enter idle while the hardare
290 * module initiator @init_oh is active. Useful when a module will not
291 * be accessed by a particular initiator (e.g., if a module will not
292 * be accessed by the IVA, there should be no sleepdep between the IVA
293 * initiator and the module). Only applies to modules in smart-idle
294 * mode. Returns -EINVAL upon error or passes along
295 * pwrdm_add_sleepdep() value upon success.
297 static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
299 if (!oh->_clk)
300 return -EINVAL;
302 return pwrdm_del_sleepdep(oh->_clk->clkdm->pwrdm.ptr,
303 init_oh->_clk->clkdm->pwrdm.ptr);
307 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
308 * @oh: struct omap_hwmod *
310 * Called from _init_clocks(). Populates the @oh _clk (main
311 * functional clock pointer) if a main_clk is present. Returns 0 on
312 * success or -EINVAL on error.
314 static int _init_main_clk(struct omap_hwmod *oh)
316 struct clk *c;
317 int ret = 0;
319 if (!oh->clkdev_con_id)
320 return 0;
322 c = clk_get_sys(oh->clkdev_dev_id, oh->clkdev_con_id);
323 WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get main_clk %s.%s\n",
324 oh->name, oh->clkdev_dev_id, oh->clkdev_con_id);
325 if (IS_ERR(c))
326 ret = -EINVAL;
327 oh->_clk = c;
329 return ret;
333 * _init_interface_clk - get a struct clk * for the the hwmod's interface clks
334 * @oh: struct omap_hwmod *
336 * Called from _init_clocks(). Populates the @oh OCP slave interface
337 * clock pointers. Returns 0 on success or -EINVAL on error.
339 static int _init_interface_clks(struct omap_hwmod *oh)
341 struct omap_hwmod_ocp_if *os;
342 struct clk *c;
343 int i;
344 int ret = 0;
346 if (oh->slaves_cnt == 0)
347 return 0;
349 for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) {
350 if (!os->clkdev_con_id)
351 continue;
353 c = clk_get_sys(os->clkdev_dev_id, os->clkdev_con_id);
354 WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get "
355 "interface_clk %s.%s\n", oh->name,
356 os->clkdev_dev_id, os->clkdev_con_id);
357 if (IS_ERR(c))
358 ret = -EINVAL;
359 os->_clk = c;
362 return ret;
366 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
367 * @oh: struct omap_hwmod *
369 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
370 * clock pointers. Returns 0 on success or -EINVAL on error.
372 static int _init_opt_clks(struct omap_hwmod *oh)
374 struct omap_hwmod_opt_clk *oc;
375 struct clk *c;
376 int i;
377 int ret = 0;
379 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
380 c = clk_get_sys(oc->clkdev_dev_id, oc->clkdev_con_id);
381 WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get opt_clk "
382 "%s.%s\n", oh->name, oc->clkdev_dev_id,
383 oc->clkdev_con_id);
384 if (IS_ERR(c))
385 ret = -EINVAL;
386 oc->_clk = c;
389 return ret;
393 * _enable_clocks - enable hwmod main clock and interface clocks
394 * @oh: struct omap_hwmod *
396 * Enables all clocks necessary for register reads and writes to succeed
397 * on the hwmod @oh. Returns 0.
399 static int _enable_clocks(struct omap_hwmod *oh)
401 struct omap_hwmod_ocp_if *os;
402 int i;
404 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
406 if (oh->_clk && !IS_ERR(oh->_clk))
407 clk_enable(oh->_clk);
409 if (oh->slaves_cnt > 0) {
410 for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) {
411 struct clk *c = os->_clk;
413 if (c && !IS_ERR(c) && (os->flags & OCPIF_SWSUP_IDLE))
414 clk_enable(c);
418 /* The opt clocks are controlled by the device driver. */
420 return 0;
424 * _disable_clocks - disable hwmod main clock and interface clocks
425 * @oh: struct omap_hwmod *
427 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
429 static int _disable_clocks(struct omap_hwmod *oh)
431 struct omap_hwmod_ocp_if *os;
432 int i;
434 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
436 if (oh->_clk && !IS_ERR(oh->_clk))
437 clk_disable(oh->_clk);
439 if (oh->slaves_cnt > 0) {
440 for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) {
441 struct clk *c = os->_clk;
443 if (c && !IS_ERR(c) && (os->flags & OCPIF_SWSUP_IDLE))
444 clk_disable(c);
448 /* The opt clocks are controlled by the device driver. */
450 return 0;
454 * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use
455 * @oh: struct omap_hwmod *
457 * Returns the array index of the OCP slave port that the MPU
458 * addresses the device on, or -EINVAL upon error or not found.
460 static int _find_mpu_port_index(struct omap_hwmod *oh)
462 struct omap_hwmod_ocp_if *os;
463 int i;
464 int found = 0;
466 if (!oh || oh->slaves_cnt == 0)
467 return -EINVAL;
469 for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) {
470 if (os->user & OCP_USER_MPU) {
471 found = 1;
472 break;
476 if (found)
477 pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n",
478 oh->name, i);
479 else
480 pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n",
481 oh->name);
483 return (found) ? i : -EINVAL;
487 * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU
488 * @oh: struct omap_hwmod *
490 * Return the virtual address of the base of the register target of
491 * device @oh, or NULL on error.
493 static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index)
495 struct omap_hwmod_ocp_if *os;
496 struct omap_hwmod_addr_space *mem;
497 int i;
498 int found = 0;
499 void __iomem *va_start;
501 if (!oh || oh->slaves_cnt == 0)
502 return NULL;
504 os = *oh->slaves + index;
506 for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) {
507 if (mem->flags & ADDR_TYPE_RT) {
508 found = 1;
509 break;
513 if (found) {
514 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
515 if (!va_start) {
516 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
517 return NULL;
519 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
520 oh->name, va_start);
521 } else {
522 pr_debug("omap_hwmod: %s: no MPU register target found\n",
523 oh->name);
526 return (found) ? va_start : NULL;
530 * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG
531 * @oh: struct omap_hwmod *
533 * If module is marked as SWSUP_SIDLE, force the module out of slave
534 * idle; otherwise, configure it for smart-idle. If module is marked
535 * as SWSUP_MSUSPEND, force the module out of master standby;
536 * otherwise, configure it for smart-standby. No return value.
538 static void _sysc_enable(struct omap_hwmod *oh)
540 u8 idlemode;
541 u32 v;
543 if (!oh->sysconfig)
544 return;
546 v = oh->_sysc_cache;
548 if (oh->sysconfig->sysc_flags & SYSC_HAS_SIDLEMODE) {
549 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
550 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
551 _set_slave_idlemode(oh, idlemode, &v);
554 if (oh->sysconfig->sysc_flags & SYSC_HAS_MIDLEMODE) {
555 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
556 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
557 _set_master_standbymode(oh, idlemode, &v);
560 /* XXX OCP AUTOIDLE bit? */
562 if (oh->flags & HWMOD_SET_DEFAULT_CLOCKACT &&
563 oh->sysconfig->sysc_flags & SYSC_HAS_CLOCKACTIVITY)
564 _set_clockactivity(oh, oh->sysconfig->clockact, &v);
566 _write_sysconfig(v, oh);
570 * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG
571 * @oh: struct omap_hwmod *
573 * If module is marked as SWSUP_SIDLE, force the module into slave
574 * idle; otherwise, configure it for smart-idle. If module is marked
575 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
576 * configure it for smart-standby. No return value.
578 static void _sysc_idle(struct omap_hwmod *oh)
580 u8 idlemode;
581 u32 v;
583 if (!oh->sysconfig)
584 return;
586 v = oh->_sysc_cache;
588 if (oh->sysconfig->sysc_flags & SYSC_HAS_SIDLEMODE) {
589 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
590 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
591 _set_slave_idlemode(oh, idlemode, &v);
594 if (oh->sysconfig->sysc_flags & SYSC_HAS_MIDLEMODE) {
595 idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ?
596 HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART;
597 _set_master_standbymode(oh, idlemode, &v);
600 _write_sysconfig(v, oh);
604 * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG
605 * @oh: struct omap_hwmod *
607 * Force the module into slave idle and master suspend. No return
608 * value.
610 static void _sysc_shutdown(struct omap_hwmod *oh)
612 u32 v;
614 if (!oh->sysconfig)
615 return;
617 v = oh->_sysc_cache;
619 if (oh->sysconfig->sysc_flags & SYSC_HAS_SIDLEMODE)
620 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
622 if (oh->sysconfig->sysc_flags & SYSC_HAS_MIDLEMODE)
623 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
625 /* XXX clear OCP AUTOIDLE bit? */
627 _write_sysconfig(v, oh);
631 * _lookup - find an omap_hwmod by name
632 * @name: find an omap_hwmod by name
634 * Return a pointer to an omap_hwmod by name, or NULL if not found.
635 * Caller must hold omap_hwmod_mutex.
637 static struct omap_hwmod *_lookup(const char *name)
639 struct omap_hwmod *oh, *temp_oh;
641 oh = NULL;
643 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
644 if (!strcmp(name, temp_oh->name)) {
645 oh = temp_oh;
646 break;
650 return oh;
654 * _init_clocks - clk_get() all clocks associated with this hwmod
655 * @oh: struct omap_hwmod *
657 * Called by omap_hwmod_late_init() (after omap2_clk_init()).
658 * Resolves all clock names embedded in the hwmod. Must be called
659 * with omap_hwmod_mutex held. Returns -EINVAL if the omap_hwmod
660 * has not yet been registered or if the clocks have already been
661 * initialized, 0 on success, or a non-zero error on failure.
663 static int _init_clocks(struct omap_hwmod *oh)
665 int ret = 0;
667 if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED))
668 return -EINVAL;
670 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
672 ret |= _init_main_clk(oh);
673 ret |= _init_interface_clks(oh);
674 ret |= _init_opt_clks(oh);
676 oh->_state = _HWMOD_STATE_CLKS_INITED;
678 return ret;
682 * _wait_target_ready - wait for a module to leave slave idle
683 * @oh: struct omap_hwmod *
685 * Wait for a module @oh to leave slave idle. Returns 0 if the module
686 * does not have an IDLEST bit or if the module successfully leaves
687 * slave idle; otherwise, pass along the return value of the
688 * appropriate *_cm_wait_module_ready() function.
690 static int _wait_target_ready(struct omap_hwmod *oh)
692 struct omap_hwmod_ocp_if *os;
693 int ret;
695 if (!oh)
696 return -EINVAL;
698 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
699 return 0;
701 os = *oh->slaves + oh->_mpu_port_index;
703 if (!(os->flags & OCPIF_HAS_IDLEST))
704 return 0;
706 /* XXX check module SIDLEMODE */
708 /* XXX check clock enable states */
710 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
711 ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs,
712 oh->prcm.omap2.idlest_reg_id,
713 oh->prcm.omap2.idlest_idle_bit);
714 #if 0
715 } else if (cpu_is_omap44xx()) {
716 ret = omap4_cm_wait_module_ready(oh->prcm.omap4.module_offs,
717 oh->prcm.omap4.device_offs);
718 #endif
719 } else {
720 BUG();
723 return ret;
727 * _reset - reset an omap_hwmod
728 * @oh: struct omap_hwmod *
730 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
731 * enabled for this to work. Must be called with omap_hwmod_mutex
732 * held. Returns -EINVAL if the hwmod cannot be reset this way or if
733 * the hwmod is in the wrong state, -ETIMEDOUT if the module did not
734 * reset in time, or 0 upon success.
736 static int _reset(struct omap_hwmod *oh)
738 u32 r, v;
739 int c;
741 if (!oh->sysconfig ||
742 !(oh->sysconfig->sysc_flags & SYSC_HAS_SOFTRESET) ||
743 (oh->sysconfig->sysc_flags & SYSS_MISSING))
744 return -EINVAL;
746 /* clocks must be on for this operation */
747 if (oh->_state != _HWMOD_STATE_ENABLED) {
748 WARN(1, "omap_hwmod: %s: reset can only be entered from "
749 "enabled state\n", oh->name);
750 return -EINVAL;
753 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
755 v = oh->_sysc_cache;
756 r = _set_softreset(oh, &v);
757 if (r)
758 return r;
759 _write_sysconfig(v, oh);
761 c = 0;
762 while (c < MAX_MODULE_RESET_WAIT &&
763 !(omap_hwmod_readl(oh, oh->sysconfig->syss_offs) &
764 SYSS_RESETDONE_MASK)) {
765 udelay(1);
766 c++;
769 if (c == MAX_MODULE_RESET_WAIT)
770 WARN(1, "omap_hwmod: %s: failed to reset in %d usec\n",
771 oh->name, MAX_MODULE_RESET_WAIT);
772 else
773 pr_debug("omap_hwmod: %s: reset in %d usec\n", oh->name, c);
776 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
777 * _wait_target_ready() or _reset()
780 return (c == MAX_MODULE_RESET_WAIT) ? -ETIMEDOUT : 0;
784 * _enable - enable an omap_hwmod
785 * @oh: struct omap_hwmod *
787 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
788 * register target. Must be called with omap_hwmod_mutex held.
789 * Returns -EINVAL if the hwmod is in the wrong state or passes along
790 * the return value of _wait_target_ready().
792 static int _enable(struct omap_hwmod *oh)
794 int r;
796 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
797 oh->_state != _HWMOD_STATE_IDLE &&
798 oh->_state != _HWMOD_STATE_DISABLED) {
799 WARN(1, "omap_hwmod: %s: enabled state can only be entered "
800 "from initialized, idle, or disabled state\n", oh->name);
801 return -EINVAL;
804 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
806 /* XXX mux balls */
808 _add_initiator_dep(oh, mpu_oh);
809 _enable_clocks(oh);
811 if (oh->sysconfig) {
812 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
813 _update_sysc_cache(oh);
814 _sysc_enable(oh);
817 r = _wait_target_ready(oh);
818 if (!r)
819 oh->_state = _HWMOD_STATE_ENABLED;
821 return r;
825 * _idle - idle an omap_hwmod
826 * @oh: struct omap_hwmod *
828 * Idles an omap_hwmod @oh. This should be called once the hwmod has
829 * no further work. Returns -EINVAL if the hwmod is in the wrong
830 * state or returns 0.
832 static int _idle(struct omap_hwmod *oh)
834 if (oh->_state != _HWMOD_STATE_ENABLED) {
835 WARN(1, "omap_hwmod: %s: idle state can only be entered from "
836 "enabled state\n", oh->name);
837 return -EINVAL;
840 pr_debug("omap_hwmod: %s: idling\n", oh->name);
842 if (oh->sysconfig)
843 _sysc_idle(oh);
844 _del_initiator_dep(oh, mpu_oh);
845 _disable_clocks(oh);
847 oh->_state = _HWMOD_STATE_IDLE;
849 return 0;
853 * _shutdown - shutdown an omap_hwmod
854 * @oh: struct omap_hwmod *
856 * Shut down an omap_hwmod @oh. This should be called when the driver
857 * used for the hwmod is removed or unloaded or if the driver is not
858 * used by the system. Returns -EINVAL if the hwmod is in the wrong
859 * state or returns 0.
861 static int _shutdown(struct omap_hwmod *oh)
863 if (oh->_state != _HWMOD_STATE_IDLE &&
864 oh->_state != _HWMOD_STATE_ENABLED) {
865 WARN(1, "omap_hwmod: %s: disabled state can only be entered "
866 "from idle, or enabled state\n", oh->name);
867 return -EINVAL;
870 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
872 if (oh->sysconfig)
873 _sysc_shutdown(oh);
874 _del_initiator_dep(oh, mpu_oh);
875 /* XXX what about the other system initiators here? DMA, tesla, d2d */
876 _disable_clocks(oh);
877 /* XXX Should this code also force-disable the optional clocks? */
879 /* XXX mux any associated balls to safe mode */
881 oh->_state = _HWMOD_STATE_DISABLED;
883 return 0;
887 * _write_clockact_lock - set the module's clockactivity bits
888 * @oh: struct omap_hwmod *
889 * @clockact: CLOCKACTIVITY field bits
891 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
892 * OCP_SYSCONFIG register. Returns -EINVAL if the hwmod is in the
893 * wrong state or returns 0.
895 static int _write_clockact_lock(struct omap_hwmod *oh, u8 clockact)
897 u32 v;
899 if (!oh->sysconfig ||
900 !(oh->sysconfig->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
901 return -EINVAL;
903 mutex_lock(&omap_hwmod_mutex);
904 v = oh->_sysc_cache;
905 _set_clockactivity(oh, clockact, &v);
906 _write_sysconfig(v, oh);
907 mutex_unlock(&omap_hwmod_mutex);
909 return 0;
914 * _setup - do initial configuration of omap_hwmod
915 * @oh: struct omap_hwmod *
917 * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh
918 * OCP_SYSCONFIG register. Must be called with omap_hwmod_mutex
919 * held. Returns -EINVAL if the hwmod is in the wrong state or returns
920 * 0.
922 static int _setup(struct omap_hwmod *oh)
924 struct omap_hwmod_ocp_if *os;
925 int i;
927 if (!oh)
928 return -EINVAL;
930 /* Set iclk autoidle mode */
931 if (oh->slaves_cnt > 0) {
932 for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) {
933 struct clk *c = os->_clk;
935 if (!c || IS_ERR(c))
936 continue;
938 if (os->flags & OCPIF_SWSUP_IDLE) {
939 /* XXX omap_iclk_deny_idle(c); */
940 } else {
941 /* XXX omap_iclk_allow_idle(c); */
942 clk_enable(c);
947 oh->_state = _HWMOD_STATE_INITIALIZED;
949 _enable(oh);
951 if (!(oh->flags & HWMOD_INIT_NO_RESET))
952 _reset(oh);
954 /* XXX OCP AUTOIDLE bit? */
955 /* XXX OCP ENAWAKEUP bit? */
957 if (!(oh->flags & HWMOD_INIT_NO_IDLE))
958 _idle(oh);
960 return 0;
965 /* Public functions */
967 u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs)
969 return __raw_readl(oh->_rt_va + reg_offs);
972 void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs)
974 __raw_writel(v, oh->_rt_va + reg_offs);
978 * omap_hwmod_register - register a struct omap_hwmod
979 * @oh: struct omap_hwmod *
981 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod already
982 * has been registered by the same name; -EINVAL if the omap_hwmod is in the
983 * wrong state, or 0 on success.
985 * XXX The data should be copied into bootmem, so the original data
986 * should be marked __initdata and freed after init. This would allow
987 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
988 * that the copy process would be relatively complex due to the large number
989 * of substructures.
991 int omap_hwmod_register(struct omap_hwmod *oh)
993 int ret, ms_id;
995 if (!oh || (oh->_state != _HWMOD_STATE_UNKNOWN))
996 return -EINVAL;
998 mutex_lock(&omap_hwmod_mutex);
1000 pr_debug("omap_hwmod: %s: registering\n", oh->name);
1002 if (_lookup(oh->name)) {
1003 ret = -EEXIST;
1004 goto ohr_unlock;
1007 ms_id = _find_mpu_port_index(oh);
1008 if (!IS_ERR_VALUE(ms_id)) {
1009 oh->_mpu_port_index = ms_id;
1010 oh->_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index);
1011 } else {
1012 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
1015 list_add_tail(&oh->node, &omap_hwmod_list);
1017 oh->_state = _HWMOD_STATE_REGISTERED;
1019 ret = 0;
1021 ohr_unlock:
1022 mutex_unlock(&omap_hwmod_mutex);
1023 return ret;
1027 * omap_hwmod_lookup - look up a registered omap_hwmod by name
1028 * @name: name of the omap_hwmod to look up
1030 * Given a @name of an omap_hwmod, return a pointer to the registered
1031 * struct omap_hwmod *, or NULL upon error.
1033 struct omap_hwmod *omap_hwmod_lookup(const char *name)
1035 struct omap_hwmod *oh;
1037 if (!name)
1038 return NULL;
1040 mutex_lock(&omap_hwmod_mutex);
1041 oh = _lookup(name);
1042 mutex_unlock(&omap_hwmod_mutex);
1044 return oh;
1048 * omap_hwmod_for_each - call function for each registered omap_hwmod
1049 * @fn: pointer to a callback function
1051 * Call @fn for each registered omap_hwmod, passing @data to each
1052 * function. @fn must return 0 for success or any other value for
1053 * failure. If @fn returns non-zero, the iteration across omap_hwmods
1054 * will stop and the non-zero return value will be passed to the
1055 * caller of omap_hwmod_for_each(). @fn is called with
1056 * omap_hwmod_for_each() held.
1058 int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh))
1060 struct omap_hwmod *temp_oh;
1061 int ret;
1063 if (!fn)
1064 return -EINVAL;
1066 mutex_lock(&omap_hwmod_mutex);
1067 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1068 ret = (*fn)(temp_oh);
1069 if (ret)
1070 break;
1072 mutex_unlock(&omap_hwmod_mutex);
1074 return ret;
1079 * omap_hwmod_init - init omap_hwmod code and register hwmods
1080 * @ohs: pointer to an array of omap_hwmods to register
1082 * Intended to be called early in boot before the clock framework is
1083 * initialized. If @ohs is not null, will register all omap_hwmods
1084 * listed in @ohs that are valid for this chip. Returns -EINVAL if
1085 * omap_hwmod_init() has already been called or 0 otherwise.
1087 int omap_hwmod_init(struct omap_hwmod **ohs)
1089 struct omap_hwmod *oh;
1090 int r;
1092 if (inited)
1093 return -EINVAL;
1095 inited = 1;
1097 if (!ohs)
1098 return 0;
1100 oh = *ohs;
1101 while (oh) {
1102 if (omap_chip_is(oh->omap_chip)) {
1103 r = omap_hwmod_register(oh);
1104 WARN(r, "omap_hwmod: %s: omap_hwmod_register returned "
1105 "%d\n", oh->name, r);
1107 oh = *++ohs;
1110 return 0;
1114 * omap_hwmod_late_init - do some post-clock framework initialization
1116 * Must be called after omap2_clk_init(). Resolves the struct clk names
1117 * to struct clk pointers for each registered omap_hwmod. Also calls
1118 * _setup() on each hwmod. Returns 0.
1120 int omap_hwmod_late_init(void)
1122 int r;
1124 /* XXX check return value */
1125 r = omap_hwmod_for_each(_init_clocks);
1126 WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n");
1128 mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME);
1129 WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n",
1130 MPU_INITIATOR_NAME);
1132 omap_hwmod_for_each(_setup);
1134 return 0;
1138 * omap_hwmod_unregister - unregister an omap_hwmod
1139 * @oh: struct omap_hwmod *
1141 * Unregisters a previously-registered omap_hwmod @oh. There's probably
1142 * no use case for this, so it is likely to be removed in a later version.
1144 * XXX Free all of the bootmem-allocated structures here when that is
1145 * implemented. Make it clear that core code is the only code that is
1146 * expected to unregister modules.
1148 int omap_hwmod_unregister(struct omap_hwmod *oh)
1150 if (!oh)
1151 return -EINVAL;
1153 pr_debug("omap_hwmod: %s: unregistering\n", oh->name);
1155 mutex_lock(&omap_hwmod_mutex);
1156 iounmap(oh->_rt_va);
1157 list_del(&oh->node);
1158 mutex_unlock(&omap_hwmod_mutex);
1160 return 0;
1164 * omap_hwmod_enable - enable an omap_hwmod
1165 * @oh: struct omap_hwmod *
1167 * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable().
1168 * Returns -EINVAL on error or passes along the return value from _enable().
1170 int omap_hwmod_enable(struct omap_hwmod *oh)
1172 int r;
1174 if (!oh)
1175 return -EINVAL;
1177 mutex_lock(&omap_hwmod_mutex);
1178 r = _enable(oh);
1179 mutex_unlock(&omap_hwmod_mutex);
1181 return r;
1185 * omap_hwmod_idle - idle an omap_hwmod
1186 * @oh: struct omap_hwmod *
1188 * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle().
1189 * Returns -EINVAL on error or passes along the return value from _idle().
1191 int omap_hwmod_idle(struct omap_hwmod *oh)
1193 if (!oh)
1194 return -EINVAL;
1196 mutex_lock(&omap_hwmod_mutex);
1197 _idle(oh);
1198 mutex_unlock(&omap_hwmod_mutex);
1200 return 0;
1204 * omap_hwmod_shutdown - shutdown an omap_hwmod
1205 * @oh: struct omap_hwmod *
1207 * Shutdown an omap_hwomd @oh. Intended to be called by
1208 * omap_device_shutdown(). Returns -EINVAL on error or passes along
1209 * the return value from _shutdown().
1211 int omap_hwmod_shutdown(struct omap_hwmod *oh)
1213 if (!oh)
1214 return -EINVAL;
1216 mutex_lock(&omap_hwmod_mutex);
1217 _shutdown(oh);
1218 mutex_unlock(&omap_hwmod_mutex);
1220 return 0;
1224 * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
1225 * @oh: struct omap_hwmod *oh
1227 * Intended to be called by the omap_device code.
1229 int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
1231 mutex_lock(&omap_hwmod_mutex);
1232 _enable_clocks(oh);
1233 mutex_unlock(&omap_hwmod_mutex);
1235 return 0;
1239 * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
1240 * @oh: struct omap_hwmod *oh
1242 * Intended to be called by the omap_device code.
1244 int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
1246 mutex_lock(&omap_hwmod_mutex);
1247 _disable_clocks(oh);
1248 mutex_unlock(&omap_hwmod_mutex);
1250 return 0;
1254 * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
1255 * @oh: struct omap_hwmod *oh
1257 * Intended to be called by drivers and core code when all posted
1258 * writes to a device must complete before continuing further
1259 * execution (for example, after clearing some device IRQSTATUS
1260 * register bits)
1262 * XXX what about targets with multiple OCP threads?
1264 void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
1266 BUG_ON(!oh);
1268 if (!oh->sysconfig || !oh->sysconfig->sysc_flags) {
1269 WARN(1, "omap_device: %s: OCP barrier impossible due to "
1270 "device configuration\n", oh->name);
1271 return;
1275 * Forces posted writes to complete on the OCP thread handling
1276 * register writes
1278 omap_hwmod_readl(oh, oh->sysconfig->sysc_offs);
1282 * omap_hwmod_reset - reset the hwmod
1283 * @oh: struct omap_hwmod *
1285 * Under some conditions, a driver may wish to reset the entire device.
1286 * Called from omap_device code. Returns -EINVAL on error or passes along
1287 * the return value from _reset()/_enable().
1289 int omap_hwmod_reset(struct omap_hwmod *oh)
1291 int r;
1293 if (!oh || !(oh->_state & _HWMOD_STATE_ENABLED))
1294 return -EINVAL;
1296 mutex_lock(&omap_hwmod_mutex);
1297 r = _reset(oh);
1298 if (!r)
1299 r = _enable(oh);
1300 mutex_unlock(&omap_hwmod_mutex);
1302 return r;
1306 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
1307 * @oh: struct omap_hwmod *
1308 * @res: pointer to the first element of an array of struct resource to fill
1310 * Count the number of struct resource array elements necessary to
1311 * contain omap_hwmod @oh resources. Intended to be called by code
1312 * that registers omap_devices. Intended to be used to determine the
1313 * size of a dynamically-allocated struct resource array, before
1314 * calling omap_hwmod_fill_resources(). Returns the number of struct
1315 * resource array elements needed.
1317 * XXX This code is not optimized. It could attempt to merge adjacent
1318 * resource IDs.
1321 int omap_hwmod_count_resources(struct omap_hwmod *oh)
1323 int ret, i;
1325 ret = oh->mpu_irqs_cnt + oh->sdma_chs_cnt;
1327 for (i = 0; i < oh->slaves_cnt; i++)
1328 ret += (*oh->slaves + i)->addr_cnt;
1330 return ret;
1334 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
1335 * @oh: struct omap_hwmod *
1336 * @res: pointer to the first element of an array of struct resource to fill
1338 * Fill the struct resource array @res with resource data from the
1339 * omap_hwmod @oh. Intended to be called by code that registers
1340 * omap_devices. See also omap_hwmod_count_resources(). Returns the
1341 * number of array elements filled.
1343 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
1345 int i, j;
1346 int r = 0;
1348 /* For each IRQ, DMA, memory area, fill in array.*/
1350 for (i = 0; i < oh->mpu_irqs_cnt; i++) {
1351 (res + r)->start = *(oh->mpu_irqs + i);
1352 (res + r)->end = *(oh->mpu_irqs + i);
1353 (res + r)->flags = IORESOURCE_IRQ;
1354 r++;
1357 for (i = 0; i < oh->sdma_chs_cnt; i++) {
1358 (res + r)->name = (oh->sdma_chs + i)->name;
1359 (res + r)->start = (oh->sdma_chs + i)->dma_ch;
1360 (res + r)->end = (oh->sdma_chs + i)->dma_ch;
1361 (res + r)->flags = IORESOURCE_DMA;
1362 r++;
1365 for (i = 0; i < oh->slaves_cnt; i++) {
1366 struct omap_hwmod_ocp_if *os;
1368 os = *oh->slaves + i;
1370 for (j = 0; j < os->addr_cnt; j++) {
1371 (res + r)->start = (os->addr + j)->pa_start;
1372 (res + r)->end = (os->addr + j)->pa_end;
1373 (res + r)->flags = IORESOURCE_MEM;
1374 r++;
1378 return r;
1382 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
1383 * @oh: struct omap_hwmod *
1385 * Return the powerdomain pointer associated with the OMAP module
1386 * @oh's main clock. If @oh does not have a main clk, return the
1387 * powerdomain associated with the interface clock associated with the
1388 * module's MPU port. (XXX Perhaps this should use the SDMA port
1389 * instead?) Returns NULL on error, or a struct powerdomain * on
1390 * success.
1392 struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
1394 struct clk *c;
1396 if (!oh)
1397 return NULL;
1399 if (oh->_clk) {
1400 c = oh->_clk;
1401 } else {
1402 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
1403 return NULL;
1404 c = oh->slaves[oh->_mpu_port_index]->_clk;
1407 return c->clkdm->pwrdm.ptr;
1412 * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
1413 * @oh: struct omap_hwmod *
1414 * @init_oh: struct omap_hwmod * (initiator)
1416 * Add a sleep dependency between the initiator @init_oh and @oh.
1417 * Intended to be called by DSP/Bridge code via platform_data for the
1418 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
1419 * code needs to add/del initiator dependencies dynamically
1420 * before/after accessing a device. Returns the return value from
1421 * _add_initiator_dep().
1423 * XXX Keep a usecount in the clockdomain code
1425 int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
1426 struct omap_hwmod *init_oh)
1428 return _add_initiator_dep(oh, init_oh);
1432 * XXX what about functions for drivers to save/restore ocp_sysconfig
1433 * for context save/restore operations?
1437 * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
1438 * @oh: struct omap_hwmod *
1439 * @init_oh: struct omap_hwmod * (initiator)
1441 * Remove a sleep dependency between the initiator @init_oh and @oh.
1442 * Intended to be called by DSP/Bridge code via platform_data for the
1443 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
1444 * code needs to add/del initiator dependencies dynamically
1445 * before/after accessing a device. Returns the return value from
1446 * _del_initiator_dep().
1448 * XXX Keep a usecount in the clockdomain code
1450 int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
1451 struct omap_hwmod *init_oh)
1453 return _del_initiator_dep(oh, init_oh);
1457 * omap_hwmod_set_clockact_none - set clockactivity test to BOTH
1458 * @oh: struct omap_hwmod *
1460 * On some modules, this function can affect the wakeup latency vs.
1461 * power consumption balance. Intended to be called by the
1462 * omap_device layer. Passes along the return value from
1463 * _write_clockact_lock().
1465 int omap_hwmod_set_clockact_both(struct omap_hwmod *oh)
1467 return _write_clockact_lock(oh, CLOCKACT_TEST_BOTH);
1471 * omap_hwmod_set_clockact_none - set clockactivity test to MAIN
1472 * @oh: struct omap_hwmod *
1474 * On some modules, this function can affect the wakeup latency vs.
1475 * power consumption balance. Intended to be called by the
1476 * omap_device layer. Passes along the return value from
1477 * _write_clockact_lock().
1479 int omap_hwmod_set_clockact_main(struct omap_hwmod *oh)
1481 return _write_clockact_lock(oh, CLOCKACT_TEST_MAIN);
1485 * omap_hwmod_set_clockact_none - set clockactivity test to ICLK
1486 * @oh: struct omap_hwmod *
1488 * On some modules, this function can affect the wakeup latency vs.
1489 * power consumption balance. Intended to be called by the
1490 * omap_device layer. Passes along the return value from
1491 * _write_clockact_lock().
1493 int omap_hwmod_set_clockact_iclk(struct omap_hwmod *oh)
1495 return _write_clockact_lock(oh, CLOCKACT_TEST_ICLK);
1499 * omap_hwmod_set_clockact_none - set clockactivity test to NONE
1500 * @oh: struct omap_hwmod *
1502 * On some modules, this function can affect the wakeup latency vs.
1503 * power consumption balance. Intended to be called by the
1504 * omap_device layer. Passes along the return value from
1505 * _write_clockact_lock().
1507 int omap_hwmod_set_clockact_none(struct omap_hwmod *oh)
1509 return _write_clockact_lock(oh, CLOCKACT_TEST_NONE);
1513 * omap_hwmod_enable_wakeup - allow device to wake up the system
1514 * @oh: struct omap_hwmod *
1516 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
1517 * send wakeups to the PRCM. Eventually this should sets PRCM wakeup
1518 * registers to cause the PRCM to receive wakeup events from the
1519 * module. Does not set any wakeup routing registers beyond this
1520 * point - if the module is to wake up any other module or subsystem,
1521 * that must be set separately. Called by omap_device code. Returns
1522 * -EINVAL on error or 0 upon success.
1524 int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
1526 if (!oh->sysconfig ||
1527 !(oh->sysconfig->sysc_flags & SYSC_HAS_ENAWAKEUP))
1528 return -EINVAL;
1530 mutex_lock(&omap_hwmod_mutex);
1531 _enable_wakeup(oh);
1532 mutex_unlock(&omap_hwmod_mutex);
1534 return 0;
1538 * omap_hwmod_disable_wakeup - prevent device from waking the system
1539 * @oh: struct omap_hwmod *
1541 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
1542 * from sending wakeups to the PRCM. Eventually this should clear
1543 * PRCM wakeup registers to cause the PRCM to ignore wakeup events
1544 * from the module. Does not set any wakeup routing registers beyond
1545 * this point - if the module is to wake up any other module or
1546 * subsystem, that must be set separately. Called by omap_device
1547 * code. Returns -EINVAL on error or 0 upon success.
1549 int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
1551 if (!oh->sysconfig ||
1552 !(oh->sysconfig->sysc_flags & SYSC_HAS_ENAWAKEUP))
1553 return -EINVAL;
1555 mutex_lock(&omap_hwmod_mutex);
1556 _disable_wakeup(oh);
1557 mutex_unlock(&omap_hwmod_mutex);
1559 return 0;