ARM: OMAP2+: Remove unused legacy code for interconnects
[linux-block.git] / arch / arm / mach-omap2 / omap_hwmod.c
1 /*
2  * omap_hwmod implementation for OMAP2/3/4
3  *
4  * Copyright (C) 2009-2011 Nokia Corporation
5  * Copyright (C) 2011-2012 Texas Instruments, Inc.
6  *
7  * Paul Walmsley, BenoĆ®t Cousson, Kevin Hilman
8  *
9  * Created in collaboration with (alphabetical order): Thara Gopinath,
10  * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand
11  * Sawant, Santosh Shilimkar, Richard Woodruff
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License version 2 as
15  * published by the Free Software Foundation.
16  *
17  * Introduction
18  * ------------
19  * One way to view an OMAP SoC is as a collection of largely unrelated
20  * IP blocks connected by interconnects.  The IP blocks include
21  * devices such as ARM processors, audio serial interfaces, UARTs,
22  * etc.  Some of these devices, like the DSP, are created by TI;
23  * others, like the SGX, largely originate from external vendors.  In
24  * TI's documentation, on-chip devices are referred to as "OMAP
25  * modules."  Some of these IP blocks are identical across several
26  * OMAP versions.  Others are revised frequently.
27  *
28  * These OMAP modules are tied together by various interconnects.
29  * Most of the address and data flow between modules is via OCP-based
30  * interconnects such as the L3 and L4 buses; but there are other
31  * interconnects that distribute the hardware clock tree, handle idle
32  * and reset signaling, supply power, and connect the modules to
33  * various pads or balls on the OMAP package.
34  *
35  * OMAP hwmod provides a consistent way to describe the on-chip
36  * hardware blocks and their integration into the rest of the chip.
37  * This description can be automatically generated from the TI
38  * hardware database.  OMAP hwmod provides a standard, consistent API
39  * to reset, enable, idle, and disable these hardware blocks.  And
40  * hwmod provides a way for other core code, such as the Linux device
41  * code or the OMAP power management and address space mapping code,
42  * to query the hardware database.
43  *
44  * Using hwmod
45  * -----------
46  * Drivers won't call hwmod functions directly.  That is done by the
47  * omap_device code, and in rare occasions, by custom integration code
48  * in arch/arm/ *omap*.  The omap_device code includes functions to
49  * build a struct platform_device using omap_hwmod data, and that is
50  * currently how hwmod data is communicated to drivers and to the
51  * Linux driver model.  Most drivers will call omap_hwmod functions only
52  * indirectly, via pm_runtime*() functions.
53  *
54  * From a layering perspective, here is where the OMAP hwmod code
55  * fits into the kernel software stack:
56  *
57  *            +-------------------------------+
58  *            |      Device driver code       |
59  *            |      (e.g., drivers/)         |
60  *            +-------------------------------+
61  *            |      Linux driver model       |
62  *            |     (platform_device /        |
63  *            |  platform_driver data/code)   |
64  *            +-------------------------------+
65  *            | OMAP core-driver integration  |
66  *            |(arch/arm/mach-omap2/devices.c)|
67  *            +-------------------------------+
68  *            |      omap_device code         |
69  *            | (../plat-omap/omap_device.c)  |
70  *            +-------------------------------+
71  *   ---->    |    omap_hwmod code/data       |    <-----
72  *            | (../mach-omap2/omap_hwmod*)   |
73  *            +-------------------------------+
74  *            | OMAP clock/PRCM/register fns  |
75  *            | ({read,write}l_relaxed, clk*) |
76  *            +-------------------------------+
77  *
78  * Device drivers should not contain any OMAP-specific code or data in
79  * them.  They should only contain code to operate the IP block that
80  * the driver is responsible for.  This is because these IP blocks can
81  * also appear in other SoCs, either from TI (such as DaVinci) or from
82  * other manufacturers; and drivers should be reusable across other
83  * platforms.
84  *
85  * The OMAP hwmod code also will attempt to reset and idle all on-chip
86  * devices upon boot.  The goal here is for the kernel to be
87  * completely self-reliant and independent from bootloaders.  This is
88  * to ensure a repeatable configuration, both to ensure consistent
89  * runtime behavior, and to make it easier for others to reproduce
90  * bugs.
91  *
92  * OMAP module activity states
93  * ---------------------------
94  * The hwmod code considers modules to be in one of several activity
95  * states.  IP blocks start out in an UNKNOWN state, then once they
96  * are registered via the hwmod code, proceed to the REGISTERED state.
97  * Once their clock names are resolved to clock pointers, the module
98  * enters the CLKS_INITED state; and finally, once the module has been
99  * reset and the integration registers programmed, the INITIALIZED state
100  * is entered.  The hwmod code will then place the module into either
101  * the IDLE state to save power, or in the case of a critical system
102  * module, the ENABLED state.
103  *
104  * OMAP core integration code can then call omap_hwmod*() functions
105  * directly to move the module between the IDLE, ENABLED, and DISABLED
106  * states, as needed.  This is done during both the PM idle loop, and
107  * in the OMAP core integration code's implementation of the PM runtime
108  * functions.
109  *
110  * References
111  * ----------
112  * This is a partial list.
113  * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064)
114  * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090)
115  * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108)
116  * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140)
117  * - Open Core Protocol Specification 2.2
118  *
119  * To do:
120  * - handle IO mapping
121  * - bus throughput & module latency measurement code
122  *
123  * XXX add tests at the beginning of each function to ensure the hwmod is
124  * in the appropriate state
125  * XXX error return values should be checked to ensure that they are
126  * appropriate
127  */
128 #undef DEBUG
129
130 #include <linux/kernel.h>
131 #include <linux/errno.h>
132 #include <linux/io.h>
133 #include <linux/clk.h>
134 #include <linux/clk-provider.h>
135 #include <linux/delay.h>
136 #include <linux/err.h>
137 #include <linux/list.h>
138 #include <linux/mutex.h>
139 #include <linux/spinlock.h>
140 #include <linux/slab.h>
141 #include <linux/cpu.h>
142 #include <linux/of.h>
143 #include <linux/of_address.h>
144
145 #include <asm/system_misc.h>
146
147 #include "clock.h"
148 #include "omap_hwmod.h"
149
150 #include "soc.h"
151 #include "common.h"
152 #include "clockdomain.h"
153 #include "powerdomain.h"
154 #include "cm2xxx.h"
155 #include "cm3xxx.h"
156 #include "cm33xx.h"
157 #include "prm.h"
158 #include "prm3xxx.h"
159 #include "prm44xx.h"
160 #include "prm33xx.h"
161 #include "prminst44xx.h"
162 #include "pm.h"
163
164 /* Name of the OMAP hwmod for the MPU */
165 #define MPU_INITIATOR_NAME              "mpu"
166
167 /*
168  * Number of struct omap_hwmod_link records per struct
169  * omap_hwmod_ocp_if record (master->slave and slave->master)
170  */
171 #define LINKS_PER_OCP_IF                2
172
173 /*
174  * Address offset (in bytes) between the reset control and the reset
175  * status registers: 4 bytes on OMAP4
176  */
177 #define OMAP4_RST_CTRL_ST_OFFSET        4
178
179 /*
180  * Maximum length for module clock handle names
181  */
182 #define MOD_CLK_MAX_NAME_LEN            32
183
184 /**
185  * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
186  * @enable_module: function to enable a module (via MODULEMODE)
187  * @disable_module: function to disable a module (via MODULEMODE)
188  *
189  * XXX Eventually this functionality will be hidden inside the PRM/CM
190  * device drivers.  Until then, this should avoid huge blocks of cpu_is_*()
191  * conditionals in this code.
192  */
193 struct omap_hwmod_soc_ops {
194         void (*enable_module)(struct omap_hwmod *oh);
195         int (*disable_module)(struct omap_hwmod *oh);
196         int (*wait_target_ready)(struct omap_hwmod *oh);
197         int (*assert_hardreset)(struct omap_hwmod *oh,
198                                 struct omap_hwmod_rst_info *ohri);
199         int (*deassert_hardreset)(struct omap_hwmod *oh,
200                                   struct omap_hwmod_rst_info *ohri);
201         int (*is_hardreset_asserted)(struct omap_hwmod *oh,
202                                      struct omap_hwmod_rst_info *ohri);
203         int (*init_clkdm)(struct omap_hwmod *oh);
204         void (*update_context_lost)(struct omap_hwmod *oh);
205         int (*get_context_lost)(struct omap_hwmod *oh);
206         int (*disable_direct_prcm)(struct omap_hwmod *oh);
207 };
208
209 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
210 static struct omap_hwmod_soc_ops soc_ops;
211
212 /* omap_hwmod_list contains all registered struct omap_hwmods */
213 static LIST_HEAD(omap_hwmod_list);
214
215 /* mpu_oh: used to add/remove MPU initiator from sleepdep list */
216 static struct omap_hwmod *mpu_oh;
217
218 /* inited: set to true once the hwmod code is initialized */
219 static bool inited;
220
221 /* Private functions */
222
223 /**
224  * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
225  * @oh: struct omap_hwmod *
226  *
227  * Load the current value of the hwmod OCP_SYSCONFIG register into the
228  * struct omap_hwmod for later use.  Returns -EINVAL if the hwmod has no
229  * OCP_SYSCONFIG register or 0 upon success.
230  */
231 static int _update_sysc_cache(struct omap_hwmod *oh)
232 {
233         if (!oh->class->sysc) {
234                 WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
235                 return -EINVAL;
236         }
237
238         /* XXX ensure module interface clock is up */
239
240         oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
241
242         if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
243                 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
244
245         return 0;
246 }
247
248 /**
249  * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
250  * @v: OCP_SYSCONFIG value to write
251  * @oh: struct omap_hwmod *
252  *
253  * Write @v into the module class' OCP_SYSCONFIG register, if it has
254  * one.  No return value.
255  */
256 static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
257 {
258         if (!oh->class->sysc) {
259                 WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
260                 return;
261         }
262
263         /* XXX ensure module interface clock is up */
264
265         /* Module might have lost context, always update cache and register */
266         oh->_sysc_cache = v;
267
268         /*
269          * Some IP blocks (such as RTC) require unlocking of IP before
270          * accessing its registers. If a function pointer is present
271          * to unlock, then call it before accessing sysconfig and
272          * call lock after writing sysconfig.
273          */
274         if (oh->class->unlock)
275                 oh->class->unlock(oh);
276
277         omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
278
279         if (oh->class->lock)
280                 oh->class->lock(oh);
281 }
282
283 /**
284  * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
285  * @oh: struct omap_hwmod *
286  * @standbymode: MIDLEMODE field bits
287  * @v: pointer to register contents to modify
288  *
289  * Update the master standby mode bits in @v to be @standbymode for
290  * the @oh hwmod.  Does not write to the hardware.  Returns -EINVAL
291  * upon error or 0 upon success.
292  */
293 static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
294                                    u32 *v)
295 {
296         u32 mstandby_mask;
297         u8 mstandby_shift;
298
299         if (!oh->class->sysc ||
300             !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
301                 return -EINVAL;
302
303         if (!oh->class->sysc->sysc_fields) {
304                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
305                 return -EINVAL;
306         }
307
308         mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
309         mstandby_mask = (0x3 << mstandby_shift);
310
311         *v &= ~mstandby_mask;
312         *v |= __ffs(standbymode) << mstandby_shift;
313
314         return 0;
315 }
316
317 /**
318  * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
319  * @oh: struct omap_hwmod *
320  * @idlemode: SIDLEMODE field bits
321  * @v: pointer to register contents to modify
322  *
323  * Update the slave idle mode bits in @v to be @idlemode for the @oh
324  * hwmod.  Does not write to the hardware.  Returns -EINVAL upon error
325  * or 0 upon success.
326  */
327 static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
328 {
329         u32 sidle_mask;
330         u8 sidle_shift;
331
332         if (!oh->class->sysc ||
333             !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
334                 return -EINVAL;
335
336         if (!oh->class->sysc->sysc_fields) {
337                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
338                 return -EINVAL;
339         }
340
341         sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
342         sidle_mask = (0x3 << sidle_shift);
343
344         *v &= ~sidle_mask;
345         *v |= __ffs(idlemode) << sidle_shift;
346
347         return 0;
348 }
349
350 /**
351  * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
352  * @oh: struct omap_hwmod *
353  * @clockact: CLOCKACTIVITY field bits
354  * @v: pointer to register contents to modify
355  *
356  * Update the clockactivity mode bits in @v to be @clockact for the
357  * @oh hwmod.  Used for additional powersaving on some modules.  Does
358  * not write to the hardware.  Returns -EINVAL upon error or 0 upon
359  * success.
360  */
361 static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
362 {
363         u32 clkact_mask;
364         u8  clkact_shift;
365
366         if (!oh->class->sysc ||
367             !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
368                 return -EINVAL;
369
370         if (!oh->class->sysc->sysc_fields) {
371                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
372                 return -EINVAL;
373         }
374
375         clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
376         clkact_mask = (0x3 << clkact_shift);
377
378         *v &= ~clkact_mask;
379         *v |= clockact << clkact_shift;
380
381         return 0;
382 }
383
384 /**
385  * _set_softreset: set OCP_SYSCONFIG.SOFTRESET bit in @v
386  * @oh: struct omap_hwmod *
387  * @v: pointer to register contents to modify
388  *
389  * Set the SOFTRESET bit in @v for hwmod @oh.  Returns -EINVAL upon
390  * error or 0 upon success.
391  */
392 static int _set_softreset(struct omap_hwmod *oh, u32 *v)
393 {
394         u32 softrst_mask;
395
396         if (!oh->class->sysc ||
397             !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
398                 return -EINVAL;
399
400         if (!oh->class->sysc->sysc_fields) {
401                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
402                 return -EINVAL;
403         }
404
405         softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
406
407         *v |= softrst_mask;
408
409         return 0;
410 }
411
412 /**
413  * _clear_softreset: clear OCP_SYSCONFIG.SOFTRESET bit in @v
414  * @oh: struct omap_hwmod *
415  * @v: pointer to register contents to modify
416  *
417  * Clear the SOFTRESET bit in @v for hwmod @oh.  Returns -EINVAL upon
418  * error or 0 upon success.
419  */
420 static int _clear_softreset(struct omap_hwmod *oh, u32 *v)
421 {
422         u32 softrst_mask;
423
424         if (!oh->class->sysc ||
425             !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
426                 return -EINVAL;
427
428         if (!oh->class->sysc->sysc_fields) {
429                 WARN(1,
430                      "omap_hwmod: %s: sysc_fields absent for sysconfig class\n",
431                      oh->name);
432                 return -EINVAL;
433         }
434
435         softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
436
437         *v &= ~softrst_mask;
438
439         return 0;
440 }
441
442 /**
443  * _wait_softreset_complete - wait for an OCP softreset to complete
444  * @oh: struct omap_hwmod * to wait on
445  *
446  * Wait until the IP block represented by @oh reports that its OCP
447  * softreset is complete.  This can be triggered by software (see
448  * _ocp_softreset()) or by hardware upon returning from off-mode (one
449  * example is HSMMC).  Waits for up to MAX_MODULE_SOFTRESET_WAIT
450  * microseconds.  Returns the number of microseconds waited.
451  */
452 static int _wait_softreset_complete(struct omap_hwmod *oh)
453 {
454         struct omap_hwmod_class_sysconfig *sysc;
455         u32 softrst_mask;
456         int c = 0;
457
458         sysc = oh->class->sysc;
459
460         if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
461                 omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs)
462                                    & SYSS_RESETDONE_MASK),
463                                   MAX_MODULE_SOFTRESET_WAIT, c);
464         else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
465                 softrst_mask = (0x1 << sysc->sysc_fields->srst_shift);
466                 omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs)
467                                     & softrst_mask),
468                                   MAX_MODULE_SOFTRESET_WAIT, c);
469         }
470
471         return c;
472 }
473
474 /**
475  * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
476  * @oh: struct omap_hwmod *
477  *
478  * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
479  * of some modules. When the DMA must perform read/write accesses, the
480  * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
481  * for power management, software must set the DMADISABLE bit back to 1.
482  *
483  * Set the DMADISABLE bit in @v for hwmod @oh.  Returns -EINVAL upon
484  * error or 0 upon success.
485  */
486 static int _set_dmadisable(struct omap_hwmod *oh)
487 {
488         u32 v;
489         u32 dmadisable_mask;
490
491         if (!oh->class->sysc ||
492             !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
493                 return -EINVAL;
494
495         if (!oh->class->sysc->sysc_fields) {
496                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
497                 return -EINVAL;
498         }
499
500         /* clocks must be on for this operation */
501         if (oh->_state != _HWMOD_STATE_ENABLED) {
502                 pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
503                 return -EINVAL;
504         }
505
506         pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
507
508         v = oh->_sysc_cache;
509         dmadisable_mask =
510                 (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
511         v |= dmadisable_mask;
512         _write_sysconfig(v, oh);
513
514         return 0;
515 }
516
517 /**
518  * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
519  * @oh: struct omap_hwmod *
520  * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
521  * @v: pointer to register contents to modify
522  *
523  * Update the module autoidle bit in @v to be @autoidle for the @oh
524  * hwmod.  The autoidle bit controls whether the module can gate
525  * internal clocks automatically when it isn't doing anything; the
526  * exact function of this bit varies on a per-module basis.  This
527  * function does not write to the hardware.  Returns -EINVAL upon
528  * error or 0 upon success.
529  */
530 static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
531                                 u32 *v)
532 {
533         u32 autoidle_mask;
534         u8 autoidle_shift;
535
536         if (!oh->class->sysc ||
537             !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
538                 return -EINVAL;
539
540         if (!oh->class->sysc->sysc_fields) {
541                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
542                 return -EINVAL;
543         }
544
545         autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
546         autoidle_mask = (0x1 << autoidle_shift);
547
548         *v &= ~autoidle_mask;
549         *v |= autoidle << autoidle_shift;
550
551         return 0;
552 }
553
554 /**
555  * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
556  * @oh: struct omap_hwmod *
557  *
558  * Allow the hardware module @oh to send wakeups.  Returns -EINVAL
559  * upon error or 0 upon success.
560  */
561 static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
562 {
563         if (!oh->class->sysc ||
564             !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
565               (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
566               (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
567                 return -EINVAL;
568
569         if (!oh->class->sysc->sysc_fields) {
570                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
571                 return -EINVAL;
572         }
573
574         if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
575                 *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
576
577         if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
578                 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
579         if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
580                 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
581
582         /* XXX test pwrdm_get_wken for this hwmod's subsystem */
583
584         return 0;
585 }
586
587 /**
588  * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
589  * @oh: struct omap_hwmod *
590  *
591  * Prevent the hardware module @oh to send wakeups.  Returns -EINVAL
592  * upon error or 0 upon success.
593  */
594 static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
595 {
596         if (!oh->class->sysc ||
597             !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
598               (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
599               (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
600                 return -EINVAL;
601
602         if (!oh->class->sysc->sysc_fields) {
603                 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
604                 return -EINVAL;
605         }
606
607         if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
608                 *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
609
610         if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
611                 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
612         if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
613                 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
614
615         /* XXX test pwrdm_get_wken for this hwmod's subsystem */
616
617         return 0;
618 }
619
620 static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
621 {
622         struct clk_hw_omap *clk;
623
624         if (oh->clkdm) {
625                 return oh->clkdm;
626         } else if (oh->_clk) {
627                 if (__clk_get_flags(oh->_clk) & CLK_IS_BASIC)
628                         return NULL;
629                 clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
630                 return  clk->clkdm;
631         }
632         return NULL;
633 }
634
635 /**
636  * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
637  * @oh: struct omap_hwmod *
638  *
639  * Prevent the hardware module @oh from entering idle while the
640  * hardare module initiator @init_oh is active.  Useful when a module
641  * will be accessed by a particular initiator (e.g., if a module will
642  * be accessed by the IVA, there should be a sleepdep between the IVA
643  * initiator and the module).  Only applies to modules in smart-idle
644  * mode.  If the clockdomain is marked as not needing autodeps, return
645  * 0 without doing anything.  Otherwise, returns -EINVAL upon error or
646  * passes along clkdm_add_sleepdep() value upon success.
647  */
648 static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
649 {
650         struct clockdomain *clkdm, *init_clkdm;
651
652         clkdm = _get_clkdm(oh);
653         init_clkdm = _get_clkdm(init_oh);
654
655         if (!clkdm || !init_clkdm)
656                 return -EINVAL;
657
658         if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
659                 return 0;
660
661         return clkdm_add_sleepdep(clkdm, init_clkdm);
662 }
663
664 /**
665  * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
666  * @oh: struct omap_hwmod *
667  *
668  * Allow the hardware module @oh to enter idle while the hardare
669  * module initiator @init_oh is active.  Useful when a module will not
670  * be accessed by a particular initiator (e.g., if a module will not
671  * be accessed by the IVA, there should be no sleepdep between the IVA
672  * initiator and the module).  Only applies to modules in smart-idle
673  * mode.  If the clockdomain is marked as not needing autodeps, return
674  * 0 without doing anything.  Returns -EINVAL upon error or passes
675  * along clkdm_del_sleepdep() value upon success.
676  */
677 static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
678 {
679         struct clockdomain *clkdm, *init_clkdm;
680
681         clkdm = _get_clkdm(oh);
682         init_clkdm = _get_clkdm(init_oh);
683
684         if (!clkdm || !init_clkdm)
685                 return -EINVAL;
686
687         if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
688                 return 0;
689
690         return clkdm_del_sleepdep(clkdm, init_clkdm);
691 }
692
693 /**
694  * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
695  * @oh: struct omap_hwmod *
696  *
697  * Called from _init_clocks().  Populates the @oh _clk (main
698  * functional clock pointer) if a clock matching the hwmod name is found,
699  * or a main_clk is present.  Returns 0 on success or -EINVAL on error.
700  */
701 static int _init_main_clk(struct omap_hwmod *oh)
702 {
703         int ret = 0;
704         char name[MOD_CLK_MAX_NAME_LEN];
705         struct clk *clk;
706         static const char modck[] = "_mod_ck";
707
708         if (strlen(oh->name) >= MOD_CLK_MAX_NAME_LEN - strlen(modck))
709                 pr_warn("%s: warning: cropping name for %s\n", __func__,
710                         oh->name);
711
712         strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - strlen(modck));
713         strlcat(name, modck, MOD_CLK_MAX_NAME_LEN);
714
715         clk = clk_get(NULL, name);
716         if (!IS_ERR(clk)) {
717                 oh->_clk = clk;
718                 soc_ops.disable_direct_prcm(oh);
719                 oh->main_clk = kstrdup(name, GFP_KERNEL);
720         } else {
721                 if (!oh->main_clk)
722                         return 0;
723
724                 oh->_clk = clk_get(NULL, oh->main_clk);
725         }
726
727         if (IS_ERR(oh->_clk)) {
728                 pr_warn("omap_hwmod: %s: cannot clk_get main_clk %s\n",
729                         oh->name, oh->main_clk);
730                 return -EINVAL;
731         }
732         /*
733          * HACK: This needs a re-visit once clk_prepare() is implemented
734          * to do something meaningful. Today its just a no-op.
735          * If clk_prepare() is used at some point to do things like
736          * voltage scaling etc, then this would have to be moved to
737          * some point where subsystems like i2c and pmic become
738          * available.
739          */
740         clk_prepare(oh->_clk);
741
742         if (!_get_clkdm(oh))
743                 pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
744                            oh->name, oh->main_clk);
745
746         return ret;
747 }
748
749 /**
750  * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
751  * @oh: struct omap_hwmod *
752  *
753  * Called from _init_clocks().  Populates the @oh OCP slave interface
754  * clock pointers.  Returns 0 on success or -EINVAL on error.
755  */
756 static int _init_interface_clks(struct omap_hwmod *oh)
757 {
758         struct omap_hwmod_ocp_if *os;
759         struct clk *c;
760         int ret = 0;
761
762         list_for_each_entry(os, &oh->slave_ports, node) {
763                 if (!os->clk)
764                         continue;
765
766                 c = clk_get(NULL, os->clk);
767                 if (IS_ERR(c)) {
768                         pr_warn("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
769                                 oh->name, os->clk);
770                         ret = -EINVAL;
771                         continue;
772                 }
773                 os->_clk = c;
774                 /*
775                  * HACK: This needs a re-visit once clk_prepare() is implemented
776                  * to do something meaningful. Today its just a no-op.
777                  * If clk_prepare() is used at some point to do things like
778                  * voltage scaling etc, then this would have to be moved to
779                  * some point where subsystems like i2c and pmic become
780                  * available.
781                  */
782                 clk_prepare(os->_clk);
783         }
784
785         return ret;
786 }
787
788 /**
789  * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
790  * @oh: struct omap_hwmod *
791  *
792  * Called from _init_clocks().  Populates the @oh omap_hwmod_opt_clk
793  * clock pointers.  Returns 0 on success or -EINVAL on error.
794  */
795 static int _init_opt_clks(struct omap_hwmod *oh)
796 {
797         struct omap_hwmod_opt_clk *oc;
798         struct clk *c;
799         int i;
800         int ret = 0;
801
802         for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
803                 c = clk_get(NULL, oc->clk);
804                 if (IS_ERR(c)) {
805                         pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
806                                 oh->name, oc->clk);
807                         ret = -EINVAL;
808                         continue;
809                 }
810                 oc->_clk = c;
811                 /*
812                  * HACK: This needs a re-visit once clk_prepare() is implemented
813                  * to do something meaningful. Today its just a no-op.
814                  * If clk_prepare() is used at some point to do things like
815                  * voltage scaling etc, then this would have to be moved to
816                  * some point where subsystems like i2c and pmic become
817                  * available.
818                  */
819                 clk_prepare(oc->_clk);
820         }
821
822         return ret;
823 }
824
825 static void _enable_optional_clocks(struct omap_hwmod *oh)
826 {
827         struct omap_hwmod_opt_clk *oc;
828         int i;
829
830         pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
831
832         for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
833                 if (oc->_clk) {
834                         pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
835                                  __clk_get_name(oc->_clk));
836                         clk_enable(oc->_clk);
837                 }
838 }
839
840 static void _disable_optional_clocks(struct omap_hwmod *oh)
841 {
842         struct omap_hwmod_opt_clk *oc;
843         int i;
844
845         pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
846
847         for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
848                 if (oc->_clk) {
849                         pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
850                                  __clk_get_name(oc->_clk));
851                         clk_disable(oc->_clk);
852                 }
853 }
854
855 /**
856  * _enable_clocks - enable hwmod main clock and interface clocks
857  * @oh: struct omap_hwmod *
858  *
859  * Enables all clocks necessary for register reads and writes to succeed
860  * on the hwmod @oh.  Returns 0.
861  */
862 static int _enable_clocks(struct omap_hwmod *oh)
863 {
864         struct omap_hwmod_ocp_if *os;
865
866         pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
867
868         if (oh->_clk)
869                 clk_enable(oh->_clk);
870
871         list_for_each_entry(os, &oh->slave_ports, node) {
872                 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
873                         clk_enable(os->_clk);
874         }
875
876         if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
877                 _enable_optional_clocks(oh);
878
879         /* The opt clocks are controlled by the device driver. */
880
881         return 0;
882 }
883
884 /**
885  * _disable_clocks - disable hwmod main clock and interface clocks
886  * @oh: struct omap_hwmod *
887  *
888  * Disables the hwmod @oh main functional and interface clocks.  Returns 0.
889  */
890 static int _disable_clocks(struct omap_hwmod *oh)
891 {
892         struct omap_hwmod_ocp_if *os;
893
894         pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
895
896         if (oh->_clk)
897                 clk_disable(oh->_clk);
898
899         list_for_each_entry(os, &oh->slave_ports, node) {
900                 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
901                         clk_disable(os->_clk);
902         }
903
904         if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
905                 _disable_optional_clocks(oh);
906
907         /* The opt clocks are controlled by the device driver. */
908
909         return 0;
910 }
911
912 /**
913  * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
914  * @oh: struct omap_hwmod *
915  *
916  * Enables the PRCM module mode related to the hwmod @oh.
917  * No return value.
918  */
919 static void _omap4_enable_module(struct omap_hwmod *oh)
920 {
921         if (!oh->clkdm || !oh->prcm.omap4.modulemode)
922                 return;
923
924         pr_debug("omap_hwmod: %s: %s: %d\n",
925                  oh->name, __func__, oh->prcm.omap4.modulemode);
926
927         omap_cm_module_enable(oh->prcm.omap4.modulemode,
928                               oh->clkdm->prcm_partition,
929                               oh->clkdm->cm_inst, oh->prcm.omap4.clkctrl_offs);
930 }
931
932 /**
933  * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
934  * @oh: struct omap_hwmod *
935  *
936  * Wait for a module @oh to enter slave idle.  Returns 0 if the module
937  * does not have an IDLEST bit or if the module successfully enters
938  * slave idle; otherwise, pass along the return value of the
939  * appropriate *_cm*_wait_module_idle() function.
940  */
941 static int _omap4_wait_target_disable(struct omap_hwmod *oh)
942 {
943         if (!oh)
944                 return -EINVAL;
945
946         if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
947                 return 0;
948
949         if (oh->flags & HWMOD_NO_IDLEST)
950                 return 0;
951
952         if (!oh->prcm.omap4.clkctrl_offs &&
953             !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
954                 return 0;
955
956         return omap_cm_wait_module_idle(oh->clkdm->prcm_partition,
957                                         oh->clkdm->cm_inst,
958                                         oh->prcm.omap4.clkctrl_offs, 0);
959 }
960
961 /**
962  * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
963  * @oh: struct omap_hwmod *oh
964  *
965  * Count and return the number of MPU IRQs associated with the hwmod
966  * @oh.  Used to allocate struct resource data.  Returns 0 if @oh is
967  * NULL.
968  */
969 static int _count_mpu_irqs(struct omap_hwmod *oh)
970 {
971         struct omap_hwmod_irq_info *ohii;
972         int i = 0;
973
974         if (!oh || !oh->mpu_irqs)
975                 return 0;
976
977         do {
978                 ohii = &oh->mpu_irqs[i++];
979         } while (ohii->irq != -1);
980
981         return i-1;
982 }
983
984 /**
985  * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
986  * @oh: struct omap_hwmod *oh
987  *
988  * Count and return the number of SDMA request lines associated with
989  * the hwmod @oh.  Used to allocate struct resource data.  Returns 0
990  * if @oh is NULL.
991  */
992 static int _count_sdma_reqs(struct omap_hwmod *oh)
993 {
994         struct omap_hwmod_dma_info *ohdi;
995         int i = 0;
996
997         if (!oh || !oh->sdma_reqs)
998                 return 0;
999
1000         do {
1001                 ohdi = &oh->sdma_reqs[i++];
1002         } while (ohdi->dma_req != -1);
1003
1004         return i-1;
1005 }
1006
1007 /**
1008  * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
1009  * @oh: struct omap_hwmod *oh
1010  *
1011  * Count and return the number of address space ranges associated with
1012  * the hwmod @oh.  Used to allocate struct resource data.  Returns 0
1013  * if @oh is NULL.
1014  */
1015 static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
1016 {
1017         struct omap_hwmod_addr_space *mem;
1018         int i = 0;
1019
1020         if (!os || !os->addr)
1021                 return 0;
1022
1023         do {
1024                 mem = &os->addr[i++];
1025         } while (mem->pa_start != mem->pa_end);
1026
1027         return i-1;
1028 }
1029
1030 /**
1031  * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
1032  * @oh: struct omap_hwmod * to operate on
1033  * @name: pointer to the name of the MPU interrupt number to fetch (optional)
1034  * @irq: pointer to an unsigned int to store the MPU IRQ number to
1035  *
1036  * Retrieve a MPU hardware IRQ line number named by @name associated
1037  * with the IP block pointed to by @oh.  The IRQ number will be filled
1038  * into the address pointed to by @dma.  When @name is non-null, the
1039  * IRQ line number associated with the named entry will be returned.
1040  * If @name is null, the first matching entry will be returned.  Data
1041  * order is not meaningful in hwmod data, so callers are strongly
1042  * encouraged to use a non-null @name whenever possible to avoid
1043  * unpredictable effects if hwmod data is later added that causes data
1044  * ordering to change.  Returns 0 upon success or a negative error
1045  * code upon error.
1046  */
1047 static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
1048                                 unsigned int *irq)
1049 {
1050         int i;
1051         bool found = false;
1052
1053         if (!oh->mpu_irqs)
1054                 return -ENOENT;
1055
1056         i = 0;
1057         while (oh->mpu_irqs[i].irq != -1) {
1058                 if (name == oh->mpu_irqs[i].name ||
1059                     !strcmp(name, oh->mpu_irqs[i].name)) {
1060                         found = true;
1061                         break;
1062                 }
1063                 i++;
1064         }
1065
1066         if (!found)
1067                 return -ENOENT;
1068
1069         *irq = oh->mpu_irqs[i].irq;
1070
1071         return 0;
1072 }
1073
1074 /**
1075  * _get_sdma_req_by_name - fetch SDMA request line ID by name
1076  * @oh: struct omap_hwmod * to operate on
1077  * @name: pointer to the name of the SDMA request line to fetch (optional)
1078  * @dma: pointer to an unsigned int to store the request line ID to
1079  *
1080  * Retrieve an SDMA request line ID named by @name on the IP block
1081  * pointed to by @oh.  The ID will be filled into the address pointed
1082  * to by @dma.  When @name is non-null, the request line ID associated
1083  * with the named entry will be returned.  If @name is null, the first
1084  * matching entry will be returned.  Data order is not meaningful in
1085  * hwmod data, so callers are strongly encouraged to use a non-null
1086  * @name whenever possible to avoid unpredictable effects if hwmod
1087  * data is later added that causes data ordering to change.  Returns 0
1088  * upon success or a negative error code upon error.
1089  */
1090 static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
1091                                  unsigned int *dma)
1092 {
1093         int i;
1094         bool found = false;
1095
1096         if (!oh->sdma_reqs)
1097                 return -ENOENT;
1098
1099         i = 0;
1100         while (oh->sdma_reqs[i].dma_req != -1) {
1101                 if (name == oh->sdma_reqs[i].name ||
1102                     !strcmp(name, oh->sdma_reqs[i].name)) {
1103                         found = true;
1104                         break;
1105                 }
1106                 i++;
1107         }
1108
1109         if (!found)
1110                 return -ENOENT;
1111
1112         *dma = oh->sdma_reqs[i].dma_req;
1113
1114         return 0;
1115 }
1116
1117 /**
1118  * _get_addr_space_by_name - fetch address space start & end by name
1119  * @oh: struct omap_hwmod * to operate on
1120  * @name: pointer to the name of the address space to fetch (optional)
1121  * @pa_start: pointer to a u32 to store the starting address to
1122  * @pa_end: pointer to a u32 to store the ending address to
1123  *
1124  * Retrieve address space start and end addresses for the IP block
1125  * pointed to by @oh.  The data will be filled into the addresses
1126  * pointed to by @pa_start and @pa_end.  When @name is non-null, the
1127  * address space data associated with the named entry will be
1128  * returned.  If @name is null, the first matching entry will be
1129  * returned.  Data order is not meaningful in hwmod data, so callers
1130  * are strongly encouraged to use a non-null @name whenever possible
1131  * to avoid unpredictable effects if hwmod data is later added that
1132  * causes data ordering to change.  Returns 0 upon success or a
1133  * negative error code upon error.
1134  */
1135 static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1136                                    u32 *pa_start, u32 *pa_end)
1137 {
1138         int j;
1139         struct omap_hwmod_ocp_if *os;
1140         bool found = false;
1141
1142         list_for_each_entry(os, &oh->slave_ports, node) {
1143
1144                 if (!os->addr)
1145                         return -ENOENT;
1146
1147                 j = 0;
1148                 while (os->addr[j].pa_start != os->addr[j].pa_end) {
1149                         if (name == os->addr[j].name ||
1150                             !strcmp(name, os->addr[j].name)) {
1151                                 found = true;
1152                                 break;
1153                         }
1154                         j++;
1155                 }
1156
1157                 if (found)
1158                         break;
1159         }
1160
1161         if (!found)
1162                 return -ENOENT;
1163
1164         *pa_start = os->addr[j].pa_start;
1165         *pa_end = os->addr[j].pa_end;
1166
1167         return 0;
1168 }
1169
1170 /**
1171  * _save_mpu_port_index - find and save the index to @oh's MPU port
1172  * @oh: struct omap_hwmod *
1173  *
1174  * Determines the array index of the OCP slave port that the MPU uses
1175  * to address the device, and saves it into the struct omap_hwmod.
1176  * Intended to be called during hwmod registration only. No return
1177  * value.
1178  */
1179 static void __init _save_mpu_port_index(struct omap_hwmod *oh)
1180 {
1181         struct omap_hwmod_ocp_if *os = NULL;
1182
1183         if (!oh)
1184                 return;
1185
1186         oh->_int_flags |= _HWMOD_NO_MPU_PORT;
1187
1188         list_for_each_entry(os, &oh->slave_ports, node) {
1189                 if (os->user & OCP_USER_MPU) {
1190                         oh->_mpu_port = os;
1191                         oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
1192                         break;
1193                 }
1194         }
1195
1196         return;
1197 }
1198
1199 /**
1200  * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
1201  * @oh: struct omap_hwmod *
1202  *
1203  * Given a pointer to a struct omap_hwmod record @oh, return a pointer
1204  * to the struct omap_hwmod_ocp_if record that is used by the MPU to
1205  * communicate with the IP block.  This interface need not be directly
1206  * connected to the MPU (and almost certainly is not), but is directly
1207  * connected to the IP block represented by @oh.  Returns a pointer
1208  * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
1209  * error or if there does not appear to be a path from the MPU to this
1210  * IP block.
1211  */
1212 static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
1213 {
1214         if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
1215                 return NULL;
1216
1217         return oh->_mpu_port;
1218 };
1219
1220 /**
1221  * _find_mpu_rt_addr_space - return MPU register target address space for @oh
1222  * @oh: struct omap_hwmod *
1223  *
1224  * Returns a pointer to the struct omap_hwmod_addr_space record representing
1225  * the register target MPU address space; or returns NULL upon error.
1226  */
1227 static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
1228 {
1229         struct omap_hwmod_ocp_if *os;
1230         struct omap_hwmod_addr_space *mem;
1231         int found = 0, i = 0;
1232
1233         os = _find_mpu_rt_port(oh);
1234         if (!os || !os->addr)
1235                 return NULL;
1236
1237         do {
1238                 mem = &os->addr[i++];
1239                 if (mem->flags & ADDR_TYPE_RT)
1240                         found = 1;
1241         } while (!found && mem->pa_start != mem->pa_end);
1242
1243         return (found) ? mem : NULL;
1244 }
1245
1246 /**
1247  * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
1248  * @oh: struct omap_hwmod *
1249  *
1250  * Ensure that the OCP_SYSCONFIG register for the IP block represented
1251  * by @oh is set to indicate to the PRCM that the IP block is active.
1252  * Usually this means placing the module into smart-idle mode and
1253  * smart-standby, but if there is a bug in the automatic idle handling
1254  * for the IP block, it may need to be placed into the force-idle or
1255  * no-idle variants of these modes.  No return value.
1256  */
1257 static void _enable_sysc(struct omap_hwmod *oh)
1258 {
1259         u8 idlemode, sf;
1260         u32 v;
1261         bool clkdm_act;
1262         struct clockdomain *clkdm;
1263
1264         if (!oh->class->sysc)
1265                 return;
1266
1267         /*
1268          * Wait until reset has completed, this is needed as the IP
1269          * block is reset automatically by hardware in some cases
1270          * (off-mode for example), and the drivers require the
1271          * IP to be ready when they access it
1272          */
1273         if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1274                 _enable_optional_clocks(oh);
1275         _wait_softreset_complete(oh);
1276         if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1277                 _disable_optional_clocks(oh);
1278
1279         v = oh->_sysc_cache;
1280         sf = oh->class->sysc->sysc_flags;
1281
1282         clkdm = _get_clkdm(oh);
1283         if (sf & SYSC_HAS_SIDLEMODE) {
1284                 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1285                     oh->flags & HWMOD_SWSUP_SIDLE_ACT) {
1286                         idlemode = HWMOD_IDLEMODE_NO;
1287                 } else {
1288                         if (sf & SYSC_HAS_ENAWAKEUP)
1289                                 _enable_wakeup(oh, &v);
1290                         if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1291                                 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1292                         else
1293                                 idlemode = HWMOD_IDLEMODE_SMART;
1294                 }
1295
1296                 /*
1297                  * This is special handling for some IPs like
1298                  * 32k sync timer. Force them to idle!
1299                  */
1300                 clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
1301                 if (clkdm_act && !(oh->class->sysc->idlemodes &
1302                                    (SIDLE_SMART | SIDLE_SMART_WKUP)))
1303                         idlemode = HWMOD_IDLEMODE_FORCE;
1304
1305                 _set_slave_idlemode(oh, idlemode, &v);
1306         }
1307
1308         if (sf & SYSC_HAS_MIDLEMODE) {
1309                 if (oh->flags & HWMOD_FORCE_MSTANDBY) {
1310                         idlemode = HWMOD_IDLEMODE_FORCE;
1311                 } else if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
1312                         idlemode = HWMOD_IDLEMODE_NO;
1313                 } else {
1314                         if (sf & SYSC_HAS_ENAWAKEUP)
1315                                 _enable_wakeup(oh, &v);
1316                         if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1317                                 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1318                         else
1319                                 idlemode = HWMOD_IDLEMODE_SMART;
1320                 }
1321                 _set_master_standbymode(oh, idlemode, &v);
1322         }
1323
1324         /*
1325          * XXX The clock framework should handle this, by
1326          * calling into this code.  But this must wait until the
1327          * clock structures are tagged with omap_hwmod entries
1328          */
1329         if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1330             (sf & SYSC_HAS_CLOCKACTIVITY))
1331                 _set_clockactivity(oh, CLOCKACT_TEST_ICLK, &v);
1332
1333         _write_sysconfig(v, oh);
1334
1335         /*
1336          * Set the autoidle bit only after setting the smartidle bit
1337          * Setting this will not have any impact on the other modules.
1338          */
1339         if (sf & SYSC_HAS_AUTOIDLE) {
1340                 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
1341                         0 : 1;
1342                 _set_module_autoidle(oh, idlemode, &v);
1343                 _write_sysconfig(v, oh);
1344         }
1345 }
1346
1347 /**
1348  * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
1349  * @oh: struct omap_hwmod *
1350  *
1351  * If module is marked as SWSUP_SIDLE, force the module into slave
1352  * idle; otherwise, configure it for smart-idle.  If module is marked
1353  * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
1354  * configure it for smart-standby.  No return value.
1355  */
1356 static void _idle_sysc(struct omap_hwmod *oh)
1357 {
1358         u8 idlemode, sf;
1359         u32 v;
1360
1361         if (!oh->class->sysc)
1362                 return;
1363
1364         v = oh->_sysc_cache;
1365         sf = oh->class->sysc->sysc_flags;
1366
1367         if (sf & SYSC_HAS_SIDLEMODE) {
1368                 if (oh->flags & HWMOD_SWSUP_SIDLE) {
1369                         idlemode = HWMOD_IDLEMODE_FORCE;
1370                 } else {
1371                         if (sf & SYSC_HAS_ENAWAKEUP)
1372                                 _enable_wakeup(oh, &v);
1373                         if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1374                                 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1375                         else
1376                                 idlemode = HWMOD_IDLEMODE_SMART;
1377                 }
1378                 _set_slave_idlemode(oh, idlemode, &v);
1379         }
1380
1381         if (sf & SYSC_HAS_MIDLEMODE) {
1382                 if ((oh->flags & HWMOD_SWSUP_MSTANDBY) ||
1383                     (oh->flags & HWMOD_FORCE_MSTANDBY)) {
1384                         idlemode = HWMOD_IDLEMODE_FORCE;
1385                 } else {
1386                         if (sf & SYSC_HAS_ENAWAKEUP)
1387                                 _enable_wakeup(oh, &v);
1388                         if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1389                                 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1390                         else
1391                                 idlemode = HWMOD_IDLEMODE_SMART;
1392                 }
1393                 _set_master_standbymode(oh, idlemode, &v);
1394         }
1395
1396         /* If the cached value is the same as the new value, skip the write */
1397         if (oh->_sysc_cache != v)
1398                 _write_sysconfig(v, oh);
1399 }
1400
1401 /**
1402  * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
1403  * @oh: struct omap_hwmod *
1404  *
1405  * Force the module into slave idle and master suspend. No return
1406  * value.
1407  */
1408 static void _shutdown_sysc(struct omap_hwmod *oh)
1409 {
1410         u32 v;
1411         u8 sf;
1412
1413         if (!oh->class->sysc)
1414                 return;
1415
1416         v = oh->_sysc_cache;
1417         sf = oh->class->sysc->sysc_flags;
1418
1419         if (sf & SYSC_HAS_SIDLEMODE)
1420                 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
1421
1422         if (sf & SYSC_HAS_MIDLEMODE)
1423                 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
1424
1425         if (sf & SYSC_HAS_AUTOIDLE)
1426                 _set_module_autoidle(oh, 1, &v);
1427
1428         _write_sysconfig(v, oh);
1429 }
1430
1431 /**
1432  * _lookup - find an omap_hwmod by name
1433  * @name: find an omap_hwmod by name
1434  *
1435  * Return a pointer to an omap_hwmod by name, or NULL if not found.
1436  */
1437 static struct omap_hwmod *_lookup(const char *name)
1438 {
1439         struct omap_hwmod *oh, *temp_oh;
1440
1441         oh = NULL;
1442
1443         list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1444                 if (!strcmp(name, temp_oh->name)) {
1445                         oh = temp_oh;
1446                         break;
1447                 }
1448         }
1449
1450         return oh;
1451 }
1452
1453 /**
1454  * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
1455  * @oh: struct omap_hwmod *
1456  *
1457  * Convert a clockdomain name stored in a struct omap_hwmod into a
1458  * clockdomain pointer, and save it into the struct omap_hwmod.
1459  * Return -EINVAL if the clkdm_name lookup failed.
1460  */
1461 static int _init_clkdm(struct omap_hwmod *oh)
1462 {
1463         if (!oh->clkdm_name) {
1464                 pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
1465                 return 0;
1466         }
1467
1468         oh->clkdm = clkdm_lookup(oh->clkdm_name);
1469         if (!oh->clkdm) {
1470                 pr_warn("omap_hwmod: %s: could not associate to clkdm %s\n",
1471                         oh->name, oh->clkdm_name);
1472                 return 0;
1473         }
1474
1475         pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
1476                 oh->name, oh->clkdm_name);
1477
1478         return 0;
1479 }
1480
1481 /**
1482  * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
1483  * well the clockdomain.
1484  * @oh: struct omap_hwmod *
1485  * @data: not used; pass NULL
1486  *
1487  * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
1488  * Resolves all clock names embedded in the hwmod.  Returns 0 on
1489  * success, or a negative error code on failure.
1490  */
1491 static int _init_clocks(struct omap_hwmod *oh, void *data)
1492 {
1493         int ret = 0;
1494
1495         if (oh->_state != _HWMOD_STATE_REGISTERED)
1496                 return 0;
1497
1498         pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
1499
1500         if (soc_ops.init_clkdm)
1501                 ret |= soc_ops.init_clkdm(oh);
1502
1503         ret |= _init_main_clk(oh);
1504         ret |= _init_interface_clks(oh);
1505         ret |= _init_opt_clks(oh);
1506
1507         if (!ret)
1508                 oh->_state = _HWMOD_STATE_CLKS_INITED;
1509         else
1510                 pr_warn("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
1511
1512         return ret;
1513 }
1514
1515 /**
1516  * _lookup_hardreset - fill register bit info for this hwmod/reset line
1517  * @oh: struct omap_hwmod *
1518  * @name: name of the reset line in the context of this hwmod
1519  * @ohri: struct omap_hwmod_rst_info * that this function will fill in
1520  *
1521  * Return the bit position of the reset line that match the
1522  * input name. Return -ENOENT if not found.
1523  */
1524 static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
1525                              struct omap_hwmod_rst_info *ohri)
1526 {
1527         int i;
1528
1529         for (i = 0; i < oh->rst_lines_cnt; i++) {
1530                 const char *rst_line = oh->rst_lines[i].name;
1531                 if (!strcmp(rst_line, name)) {
1532                         ohri->rst_shift = oh->rst_lines[i].rst_shift;
1533                         ohri->st_shift = oh->rst_lines[i].st_shift;
1534                         pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
1535                                  oh->name, __func__, rst_line, ohri->rst_shift,
1536                                  ohri->st_shift);
1537
1538                         return 0;
1539                 }
1540         }
1541
1542         return -ENOENT;
1543 }
1544
1545 /**
1546  * _assert_hardreset - assert the HW reset line of submodules
1547  * contained in the hwmod module.
1548  * @oh: struct omap_hwmod *
1549  * @name: name of the reset line to lookup and assert
1550  *
1551  * Some IP like dsp, ipu or iva contain processor that require an HW
1552  * reset line to be assert / deassert in order to enable fully the IP.
1553  * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1554  * asserting the hardreset line on the currently-booted SoC, or passes
1555  * along the return value from _lookup_hardreset() or the SoC's
1556  * assert_hardreset code.
1557  */
1558 static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1559 {
1560         struct omap_hwmod_rst_info ohri;
1561         int ret = -EINVAL;
1562
1563         if (!oh)
1564                 return -EINVAL;
1565
1566         if (!soc_ops.assert_hardreset)
1567                 return -ENOSYS;
1568
1569         ret = _lookup_hardreset(oh, name, &ohri);
1570         if (ret < 0)
1571                 return ret;
1572
1573         ret = soc_ops.assert_hardreset(oh, &ohri);
1574
1575         return ret;
1576 }
1577
1578 /**
1579  * _deassert_hardreset - deassert the HW reset line of submodules contained
1580  * in the hwmod module.
1581  * @oh: struct omap_hwmod *
1582  * @name: name of the reset line to look up and deassert
1583  *
1584  * Some IP like dsp, ipu or iva contain processor that require an HW
1585  * reset line to be assert / deassert in order to enable fully the IP.
1586  * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1587  * deasserting the hardreset line on the currently-booted SoC, or passes
1588  * along the return value from _lookup_hardreset() or the SoC's
1589  * deassert_hardreset code.
1590  */
1591 static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1592 {
1593         struct omap_hwmod_rst_info ohri;
1594         int ret = -EINVAL;
1595
1596         if (!oh)
1597                 return -EINVAL;
1598
1599         if (!soc_ops.deassert_hardreset)
1600                 return -ENOSYS;
1601
1602         ret = _lookup_hardreset(oh, name, &ohri);
1603         if (ret < 0)
1604                 return ret;
1605
1606         if (oh->clkdm) {
1607                 /*
1608                  * A clockdomain must be in SW_SUP otherwise reset
1609                  * might not be completed. The clockdomain can be set
1610                  * in HW_AUTO only when the module become ready.
1611                  */
1612                 clkdm_deny_idle(oh->clkdm);
1613                 ret = clkdm_hwmod_enable(oh->clkdm, oh);
1614                 if (ret) {
1615                         WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1616                              oh->name, oh->clkdm->name, ret);
1617                         return ret;
1618                 }
1619         }
1620
1621         _enable_clocks(oh);
1622         if (soc_ops.enable_module)
1623                 soc_ops.enable_module(oh);
1624
1625         ret = soc_ops.deassert_hardreset(oh, &ohri);
1626
1627         if (soc_ops.disable_module)
1628                 soc_ops.disable_module(oh);
1629         _disable_clocks(oh);
1630
1631         if (ret == -EBUSY)
1632                 pr_warn("omap_hwmod: %s: failed to hardreset\n", oh->name);
1633
1634         if (oh->clkdm) {
1635                 /*
1636                  * Set the clockdomain to HW_AUTO, assuming that the
1637                  * previous state was HW_AUTO.
1638                  */
1639                 clkdm_allow_idle(oh->clkdm);
1640
1641                 clkdm_hwmod_disable(oh->clkdm, oh);
1642         }
1643
1644         return ret;
1645 }
1646
1647 /**
1648  * _read_hardreset - read the HW reset line state of submodules
1649  * contained in the hwmod module
1650  * @oh: struct omap_hwmod *
1651  * @name: name of the reset line to look up and read
1652  *
1653  * Return the state of the reset line.  Returns -EINVAL if @oh is
1654  * null, -ENOSYS if we have no way of reading the hardreset line
1655  * status on the currently-booted SoC, or passes along the return
1656  * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
1657  * code.
1658  */
1659 static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1660 {
1661         struct omap_hwmod_rst_info ohri;
1662         int ret = -EINVAL;
1663
1664         if (!oh)
1665                 return -EINVAL;
1666
1667         if (!soc_ops.is_hardreset_asserted)
1668                 return -ENOSYS;
1669
1670         ret = _lookup_hardreset(oh, name, &ohri);
1671         if (ret < 0)
1672                 return ret;
1673
1674         return soc_ops.is_hardreset_asserted(oh, &ohri);
1675 }
1676
1677 /**
1678  * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
1679  * @oh: struct omap_hwmod *
1680  *
1681  * If all hardreset lines associated with @oh are asserted, then return true.
1682  * Otherwise, if part of @oh is out hardreset or if no hardreset lines
1683  * associated with @oh are asserted, then return false.
1684  * This function is used to avoid executing some parts of the IP block
1685  * enable/disable sequence if its hardreset line is set.
1686  */
1687 static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
1688 {
1689         int i, rst_cnt = 0;
1690
1691         if (oh->rst_lines_cnt == 0)
1692                 return false;
1693
1694         for (i = 0; i < oh->rst_lines_cnt; i++)
1695                 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1696                         rst_cnt++;
1697
1698         if (oh->rst_lines_cnt == rst_cnt)
1699                 return true;
1700
1701         return false;
1702 }
1703
1704 /**
1705  * _are_any_hardreset_lines_asserted - return true if any part of @oh is
1706  * hard-reset
1707  * @oh: struct omap_hwmod *
1708  *
1709  * If any hardreset lines associated with @oh are asserted, then
1710  * return true.  Otherwise, if no hardreset lines associated with @oh
1711  * are asserted, or if @oh has no hardreset lines, then return false.
1712  * This function is used to avoid executing some parts of the IP block
1713  * enable/disable sequence if any hardreset line is set.
1714  */
1715 static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
1716 {
1717         int rst_cnt = 0;
1718         int i;
1719
1720         for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
1721                 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1722                         rst_cnt++;
1723
1724         return (rst_cnt) ? true : false;
1725 }
1726
1727 /**
1728  * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
1729  * @oh: struct omap_hwmod *
1730  *
1731  * Disable the PRCM module mode related to the hwmod @oh.
1732  * Return EINVAL if the modulemode is not supported and 0 in case of success.
1733  */
1734 static int _omap4_disable_module(struct omap_hwmod *oh)
1735 {
1736         int v;
1737
1738         if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1739                 return -EINVAL;
1740
1741         /*
1742          * Since integration code might still be doing something, only
1743          * disable if all lines are under hardreset.
1744          */
1745         if (_are_any_hardreset_lines_asserted(oh))
1746                 return 0;
1747
1748         pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1749
1750         omap_cm_module_disable(oh->clkdm->prcm_partition, oh->clkdm->cm_inst,
1751                                oh->prcm.omap4.clkctrl_offs);
1752
1753         v = _omap4_wait_target_disable(oh);
1754         if (v)
1755                 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1756                         oh->name);
1757
1758         return 0;
1759 }
1760
1761 /**
1762  * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
1763  * @oh: struct omap_hwmod *
1764  *
1765  * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit.  hwmod must be
1766  * enabled for this to work.  Returns -ENOENT if the hwmod cannot be
1767  * reset this way, -EINVAL if the hwmod is in the wrong state,
1768  * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
1769  *
1770  * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
1771  * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
1772  * use the SYSCONFIG softreset bit to provide the status.
1773  *
1774  * Note that some IP like McBSP do have reset control but don't have
1775  * reset status.
1776  */
1777 static int _ocp_softreset(struct omap_hwmod *oh)
1778 {
1779         u32 v;
1780         int c = 0;
1781         int ret = 0;
1782
1783         if (!oh->class->sysc ||
1784             !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
1785                 return -ENOENT;
1786
1787         /* clocks must be on for this operation */
1788         if (oh->_state != _HWMOD_STATE_ENABLED) {
1789                 pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
1790                         oh->name);
1791                 return -EINVAL;
1792         }
1793
1794         /* For some modules, all optionnal clocks need to be enabled as well */
1795         if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1796                 _enable_optional_clocks(oh);
1797
1798         pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
1799
1800         v = oh->_sysc_cache;
1801         ret = _set_softreset(oh, &v);
1802         if (ret)
1803                 goto dis_opt_clks;
1804
1805         _write_sysconfig(v, oh);
1806
1807         if (oh->class->sysc->srst_udelay)
1808                 udelay(oh->class->sysc->srst_udelay);
1809
1810         c = _wait_softreset_complete(oh);
1811         if (c == MAX_MODULE_SOFTRESET_WAIT) {
1812                 pr_warn("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1813                         oh->name, MAX_MODULE_SOFTRESET_WAIT);
1814                 ret = -ETIMEDOUT;
1815                 goto dis_opt_clks;
1816         } else {
1817                 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1818         }
1819
1820         ret = _clear_softreset(oh, &v);
1821         if (ret)
1822                 goto dis_opt_clks;
1823
1824         _write_sysconfig(v, oh);
1825
1826         /*
1827          * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1828          * _wait_target_ready() or _reset()
1829          */
1830
1831 dis_opt_clks:
1832         if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1833                 _disable_optional_clocks(oh);
1834
1835         return ret;
1836 }
1837
1838 /**
1839  * _reset - reset an omap_hwmod
1840  * @oh: struct omap_hwmod *
1841  *
1842  * Resets an omap_hwmod @oh.  If the module has a custom reset
1843  * function pointer defined, then call it to reset the IP block, and
1844  * pass along its return value to the caller.  Otherwise, if the IP
1845  * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
1846  * associated with it, call a function to reset the IP block via that
1847  * method, and pass along the return value to the caller.  Finally, if
1848  * the IP block has some hardreset lines associated with it, assert
1849  * all of those, but do _not_ deassert them. (This is because driver
1850  * authors have expressed an apparent requirement to control the
1851  * deassertion of the hardreset lines themselves.)
1852  *
1853  * The default software reset mechanism for most OMAP IP blocks is
1854  * triggered via the OCP_SYSCONFIG.SOFTRESET bit.  However, some
1855  * hwmods cannot be reset via this method.  Some are not targets and
1856  * therefore have no OCP header registers to access.  Others (like the
1857  * IVA) have idiosyncratic reset sequences.  So for these relatively
1858  * rare cases, custom reset code can be supplied in the struct
1859  * omap_hwmod_class .reset function pointer.
1860  *
1861  * _set_dmadisable() is called to set the DMADISABLE bit so that it
1862  * does not prevent idling of the system. This is necessary for cases
1863  * where ROMCODE/BOOTLOADER uses dma and transfers control to the
1864  * kernel without disabling dma.
1865  *
1866  * Passes along the return value from either _ocp_softreset() or the
1867  * custom reset function - these must return -EINVAL if the hwmod
1868  * cannot be reset this way or if the hwmod is in the wrong state,
1869  * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
1870  */
1871 static int _reset(struct omap_hwmod *oh)
1872 {
1873         int i, r;
1874
1875         pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1876
1877         if (oh->class->reset) {
1878                 r = oh->class->reset(oh);
1879         } else {
1880                 if (oh->rst_lines_cnt > 0) {
1881                         for (i = 0; i < oh->rst_lines_cnt; i++)
1882                                 _assert_hardreset(oh, oh->rst_lines[i].name);
1883                         return 0;
1884                 } else {
1885                         r = _ocp_softreset(oh);
1886                         if (r == -ENOENT)
1887                                 r = 0;
1888                 }
1889         }
1890
1891         _set_dmadisable(oh);
1892
1893         /*
1894          * OCP_SYSCONFIG bits need to be reprogrammed after a
1895          * softreset.  The _enable() function should be split to avoid
1896          * the rewrite of the OCP_SYSCONFIG register.
1897          */
1898         if (oh->class->sysc) {
1899                 _update_sysc_cache(oh);
1900                 _enable_sysc(oh);
1901         }
1902
1903         return r;
1904 }
1905
1906 /**
1907  * _omap4_update_context_lost - increment hwmod context loss counter if
1908  * hwmod context was lost, and clear hardware context loss reg
1909  * @oh: hwmod to check for context loss
1910  *
1911  * If the PRCM indicates that the hwmod @oh lost context, increment
1912  * our in-memory context loss counter, and clear the RM_*_CONTEXT
1913  * bits. No return value.
1914  */
1915 static void _omap4_update_context_lost(struct omap_hwmod *oh)
1916 {
1917         if (oh->prcm.omap4.flags & HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT)
1918                 return;
1919
1920         if (!prm_was_any_context_lost_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1921                                           oh->clkdm->pwrdm.ptr->prcm_offs,
1922                                           oh->prcm.omap4.context_offs))
1923                 return;
1924
1925         oh->prcm.omap4.context_lost_counter++;
1926         prm_clear_context_loss_flags_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1927                                          oh->clkdm->pwrdm.ptr->prcm_offs,
1928                                          oh->prcm.omap4.context_offs);
1929 }
1930
1931 /**
1932  * _omap4_get_context_lost - get context loss counter for a hwmod
1933  * @oh: hwmod to get context loss counter for
1934  *
1935  * Returns the in-memory context loss counter for a hwmod.
1936  */
1937 static int _omap4_get_context_lost(struct omap_hwmod *oh)
1938 {
1939         return oh->prcm.omap4.context_lost_counter;
1940 }
1941
1942 /**
1943  * _enable_preprogram - Pre-program an IP block during the _enable() process
1944  * @oh: struct omap_hwmod *
1945  *
1946  * Some IP blocks (such as AESS) require some additional programming
1947  * after enable before they can enter idle.  If a function pointer to
1948  * do so is present in the hwmod data, then call it and pass along the
1949  * return value; otherwise, return 0.
1950  */
1951 static int _enable_preprogram(struct omap_hwmod *oh)
1952 {
1953         if (!oh->class->enable_preprogram)
1954                 return 0;
1955
1956         return oh->class->enable_preprogram(oh);
1957 }
1958
1959 /**
1960  * _enable - enable an omap_hwmod
1961  * @oh: struct omap_hwmod *
1962  *
1963  * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
1964  * register target.  Returns -EINVAL if the hwmod is in the wrong
1965  * state or passes along the return value of _wait_target_ready().
1966  */
1967 static int _enable(struct omap_hwmod *oh)
1968 {
1969         int r;
1970
1971         pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1972
1973         /*
1974          * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
1975          * state at init.
1976          */
1977         if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
1978                 oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
1979                 return 0;
1980         }
1981
1982         if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1983             oh->_state != _HWMOD_STATE_IDLE &&
1984             oh->_state != _HWMOD_STATE_DISABLED) {
1985                 WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
1986                         oh->name);
1987                 return -EINVAL;
1988         }
1989
1990         /*
1991          * If an IP block contains HW reset lines and all of them are
1992          * asserted, we let integration code associated with that
1993          * block handle the enable.  We've received very little
1994          * information on what those driver authors need, and until
1995          * detailed information is provided and the driver code is
1996          * posted to the public lists, this is probably the best we
1997          * can do.
1998          */
1999         if (_are_all_hardreset_lines_asserted(oh))
2000                 return 0;
2001
2002         _add_initiator_dep(oh, mpu_oh);
2003
2004         if (oh->clkdm) {
2005                 /*
2006                  * A clockdomain must be in SW_SUP before enabling
2007                  * completely the module. The clockdomain can be set
2008                  * in HW_AUTO only when the module become ready.
2009                  */
2010                 clkdm_deny_idle(oh->clkdm);
2011                 r = clkdm_hwmod_enable(oh->clkdm, oh);
2012                 if (r) {
2013                         WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
2014                              oh->name, oh->clkdm->name, r);
2015                         return r;
2016                 }
2017         }
2018
2019         _enable_clocks(oh);
2020         if (soc_ops.enable_module)
2021                 soc_ops.enable_module(oh);
2022         if (oh->flags & HWMOD_BLOCK_WFI)
2023                 cpu_idle_poll_ctrl(true);
2024
2025         if (soc_ops.update_context_lost)
2026                 soc_ops.update_context_lost(oh);
2027
2028         r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
2029                 -EINVAL;
2030         if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
2031                 clkdm_allow_idle(oh->clkdm);
2032
2033         if (!r) {
2034                 oh->_state = _HWMOD_STATE_ENABLED;
2035
2036                 /* Access the sysconfig only if the target is ready */
2037                 if (oh->class->sysc) {
2038                         if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
2039                                 _update_sysc_cache(oh);
2040                         _enable_sysc(oh);
2041                 }
2042                 r = _enable_preprogram(oh);
2043         } else {
2044                 if (soc_ops.disable_module)
2045                         soc_ops.disable_module(oh);
2046                 _disable_clocks(oh);
2047                 pr_err("omap_hwmod: %s: _wait_target_ready failed: %d\n",
2048                        oh->name, r);
2049
2050                 if (oh->clkdm)
2051                         clkdm_hwmod_disable(oh->clkdm, oh);
2052         }
2053
2054         return r;
2055 }
2056
2057 /**
2058  * _idle - idle an omap_hwmod
2059  * @oh: struct omap_hwmod *
2060  *
2061  * Idles an omap_hwmod @oh.  This should be called once the hwmod has
2062  * no further work.  Returns -EINVAL if the hwmod is in the wrong
2063  * state or returns 0.
2064  */
2065 static int _idle(struct omap_hwmod *oh)
2066 {
2067         if (oh->flags & HWMOD_NO_IDLE) {
2068                 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
2069                 return 0;
2070         }
2071
2072         pr_debug("omap_hwmod: %s: idling\n", oh->name);
2073
2074         if (_are_all_hardreset_lines_asserted(oh))
2075                 return 0;
2076
2077         if (oh->_state != _HWMOD_STATE_ENABLED) {
2078                 WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
2079                         oh->name);
2080                 return -EINVAL;
2081         }
2082
2083         if (oh->class->sysc)
2084                 _idle_sysc(oh);
2085         _del_initiator_dep(oh, mpu_oh);
2086
2087         /*
2088          * If HWMOD_CLKDM_NOAUTO is set then we don't
2089          * deny idle the clkdm again since idle was already denied
2090          * in _enable()
2091          */
2092         if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
2093                 clkdm_deny_idle(oh->clkdm);
2094
2095         if (oh->flags & HWMOD_BLOCK_WFI)
2096                 cpu_idle_poll_ctrl(false);
2097         if (soc_ops.disable_module)
2098                 soc_ops.disable_module(oh);
2099
2100         /*
2101          * The module must be in idle mode before disabling any parents
2102          * clocks. Otherwise, the parent clock might be disabled before
2103          * the module transition is done, and thus will prevent the
2104          * transition to complete properly.
2105          */
2106         _disable_clocks(oh);
2107         if (oh->clkdm) {
2108                 clkdm_allow_idle(oh->clkdm);
2109                 clkdm_hwmod_disable(oh->clkdm, oh);
2110         }
2111
2112         oh->_state = _HWMOD_STATE_IDLE;
2113
2114         return 0;
2115 }
2116
2117 /**
2118  * _shutdown - shutdown an omap_hwmod
2119  * @oh: struct omap_hwmod *
2120  *
2121  * Shut down an omap_hwmod @oh.  This should be called when the driver
2122  * used for the hwmod is removed or unloaded or if the driver is not
2123  * used by the system.  Returns -EINVAL if the hwmod is in the wrong
2124  * state or returns 0.
2125  */
2126 static int _shutdown(struct omap_hwmod *oh)
2127 {
2128         int ret, i;
2129         u8 prev_state;
2130
2131         if (_are_all_hardreset_lines_asserted(oh))
2132                 return 0;
2133
2134         if (oh->_state != _HWMOD_STATE_IDLE &&
2135             oh->_state != _HWMOD_STATE_ENABLED) {
2136                 WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
2137                         oh->name);
2138                 return -EINVAL;
2139         }
2140
2141         pr_debug("omap_hwmod: %s: disabling\n", oh->name);
2142
2143         if (oh->class->pre_shutdown) {
2144                 prev_state = oh->_state;
2145                 if (oh->_state == _HWMOD_STATE_IDLE)
2146                         _enable(oh);
2147                 ret = oh->class->pre_shutdown(oh);
2148                 if (ret) {
2149                         if (prev_state == _HWMOD_STATE_IDLE)
2150                                 _idle(oh);
2151                         return ret;
2152                 }
2153         }
2154
2155         if (oh->class->sysc) {
2156                 if (oh->_state == _HWMOD_STATE_IDLE)
2157                         _enable(oh);
2158                 _shutdown_sysc(oh);
2159         }
2160
2161         /* clocks and deps are already disabled in idle */
2162         if (oh->_state == _HWMOD_STATE_ENABLED) {
2163                 _del_initiator_dep(oh, mpu_oh);
2164                 /* XXX what about the other system initiators here? dma, dsp */
2165                 if (oh->flags & HWMOD_BLOCK_WFI)
2166                         cpu_idle_poll_ctrl(false);
2167                 if (soc_ops.disable_module)
2168                         soc_ops.disable_module(oh);
2169                 _disable_clocks(oh);
2170                 if (oh->clkdm)
2171                         clkdm_hwmod_disable(oh->clkdm, oh);
2172         }
2173         /* XXX Should this code also force-disable the optional clocks? */
2174
2175         for (i = 0; i < oh->rst_lines_cnt; i++)
2176                 _assert_hardreset(oh, oh->rst_lines[i].name);
2177
2178         oh->_state = _HWMOD_STATE_DISABLED;
2179
2180         return 0;
2181 }
2182
2183 static int of_dev_find_hwmod(struct device_node *np,
2184                              struct omap_hwmod *oh)
2185 {
2186         int count, i, res;
2187         const char *p;
2188
2189         count = of_property_count_strings(np, "ti,hwmods");
2190         if (count < 1)
2191                 return -ENODEV;
2192
2193         for (i = 0; i < count; i++) {
2194                 res = of_property_read_string_index(np, "ti,hwmods",
2195                                                     i, &p);
2196                 if (res)
2197                         continue;
2198                 if (!strcmp(p, oh->name)) {
2199                         pr_debug("omap_hwmod: dt %s[%i] uses hwmod %s\n",
2200                                  np->name, i, oh->name);
2201                         return i;
2202                 }
2203         }
2204
2205         return -ENODEV;
2206 }
2207
2208 /**
2209  * of_dev_hwmod_lookup - look up needed hwmod from dt blob
2210  * @np: struct device_node *
2211  * @oh: struct omap_hwmod *
2212  * @index: index of the entry found
2213  * @found: struct device_node * found or NULL
2214  *
2215  * Parse the dt blob and find out needed hwmod. Recursive function is
2216  * implemented to take care hierarchical dt blob parsing.
2217  * Return: Returns 0 on success, -ENODEV when not found.
2218  */
2219 static int of_dev_hwmod_lookup(struct device_node *np,
2220                                struct omap_hwmod *oh,
2221                                int *index,
2222                                struct device_node **found)
2223 {
2224         struct device_node *np0 = NULL;
2225         int res;
2226
2227         res = of_dev_find_hwmod(np, oh);
2228         if (res >= 0) {
2229                 *found = np;
2230                 *index = res;
2231                 return 0;
2232         }
2233
2234         for_each_child_of_node(np, np0) {
2235                 struct device_node *fc;
2236                 int i;
2237
2238                 res = of_dev_hwmod_lookup(np0, oh, &i, &fc);
2239                 if (res == 0) {
2240                         *found = fc;
2241                         *index = i;
2242                         return 0;
2243                 }
2244         }
2245
2246         *found = NULL;
2247         *index = 0;
2248
2249         return -ENODEV;
2250 }
2251
2252 /**
2253  * _init_mpu_rt_base - populate the virtual address for a hwmod
2254  * @oh: struct omap_hwmod * to locate the virtual address
2255  * @data: (unused, caller should pass NULL)
2256  * @index: index of the reg entry iospace in device tree
2257  * @np: struct device_node * of the IP block's device node in the DT data
2258  *
2259  * Cache the virtual address used by the MPU to access this IP block's
2260  * registers.  This address is needed early so the OCP registers that
2261  * are part of the device's address space can be ioremapped properly.
2262  *
2263  * If SYSC access is not needed, the registers will not be remapped
2264  * and non-availability of MPU access is not treated as an error.
2265  *
2266  * Returns 0 on success, -EINVAL if an invalid hwmod is passed, and
2267  * -ENXIO on absent or invalid register target address space.
2268  */
2269 static int __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data,
2270                                     int index, struct device_node *np)
2271 {
2272         struct omap_hwmod_addr_space *mem;
2273         void __iomem *va_start = NULL;
2274
2275         if (!oh)
2276                 return -EINVAL;
2277
2278         _save_mpu_port_index(oh);
2279
2280         /* if we don't need sysc access we don't need to ioremap */
2281         if (!oh->class->sysc)
2282                 return 0;
2283
2284         /* we can't continue without MPU PORT if we need sysc access */
2285         if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
2286                 return -ENXIO;
2287
2288         mem = _find_mpu_rt_addr_space(oh);
2289         if (!mem) {
2290                 pr_debug("omap_hwmod: %s: no MPU register target found\n",
2291                          oh->name);
2292
2293                 /* Extract the IO space from device tree blob */
2294                 if (!np) {
2295                         pr_err("omap_hwmod: %s: no dt node\n", oh->name);
2296                         return -ENXIO;
2297                 }
2298
2299                 va_start = of_iomap(np, index + oh->mpu_rt_idx);
2300         } else {
2301                 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
2302         }
2303
2304         if (!va_start) {
2305                 if (mem)
2306                         pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
2307                 else
2308                         pr_err("omap_hwmod: %s: Missing dt reg%i for %s\n",
2309                                oh->name, index, np->full_name);
2310                 return -ENXIO;
2311         }
2312
2313         pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
2314                  oh->name, va_start);
2315
2316         oh->_mpu_rt_va = va_start;
2317         return 0;
2318 }
2319
2320 /**
2321  * _init - initialize internal data for the hwmod @oh
2322  * @oh: struct omap_hwmod *
2323  * @n: (unused)
2324  *
2325  * Look up the clocks and the address space used by the MPU to access
2326  * registers belonging to the hwmod @oh.  @oh must already be
2327  * registered at this point.  This is the first of two phases for
2328  * hwmod initialization.  Code called here does not touch any hardware
2329  * registers, it simply prepares internal data structures.  Returns 0
2330  * upon success or if the hwmod isn't registered or if the hwmod's
2331  * address space is not defined, or -EINVAL upon failure.
2332  */
2333 static int __init _init(struct omap_hwmod *oh, void *data)
2334 {
2335         int r, index;
2336         struct device_node *np = NULL;
2337         struct device_node *bus;
2338
2339         if (oh->_state != _HWMOD_STATE_REGISTERED)
2340                 return 0;
2341
2342         bus = of_find_node_by_name(NULL, "ocp");
2343         if (!bus)
2344                 return -ENODEV;
2345
2346         r = of_dev_hwmod_lookup(bus, oh, &index, &np);
2347         if (r)
2348                 pr_debug("omap_hwmod: %s missing dt data\n", oh->name);
2349         else if (np && index)
2350                 pr_warn("omap_hwmod: %s using broken dt data from %s\n",
2351                         oh->name, np->name);
2352
2353         r = _init_mpu_rt_base(oh, NULL, index, np);
2354         if (r < 0) {
2355                 WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n",
2356                      oh->name);
2357                 return 0;
2358         }
2359
2360         r = _init_clocks(oh, NULL);
2361         if (r < 0) {
2362                 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2363                 return -EINVAL;
2364         }
2365
2366         if (np) {
2367                 if (of_find_property(np, "ti,no-reset-on-init", NULL))
2368                         oh->flags |= HWMOD_INIT_NO_RESET;
2369                 if (of_find_property(np, "ti,no-idle-on-init", NULL))
2370                         oh->flags |= HWMOD_INIT_NO_IDLE;
2371                 if (of_find_property(np, "ti,no-idle", NULL))
2372                         oh->flags |= HWMOD_NO_IDLE;
2373         }
2374
2375         oh->_state = _HWMOD_STATE_INITIALIZED;
2376
2377         return 0;
2378 }
2379
2380 /**
2381  * _setup_iclk_autoidle - configure an IP block's interface clocks
2382  * @oh: struct omap_hwmod *
2383  *
2384  * Set up the module's interface clocks.  XXX This function is still mostly
2385  * a stub; implementing this properly requires iclk autoidle usecounting in
2386  * the clock code.   No return value.
2387  */
2388 static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
2389 {
2390         struct omap_hwmod_ocp_if *os;
2391
2392         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2393                 return;
2394
2395         list_for_each_entry(os, &oh->slave_ports, node) {
2396                 if (!os->_clk)
2397                         continue;
2398
2399                 if (os->flags & OCPIF_SWSUP_IDLE) {
2400                         /* XXX omap_iclk_deny_idle(c); */
2401                 } else {
2402                         /* XXX omap_iclk_allow_idle(c); */
2403                         clk_enable(os->_clk);
2404                 }
2405         }
2406
2407         return;
2408 }
2409
2410 /**
2411  * _setup_reset - reset an IP block during the setup process
2412  * @oh: struct omap_hwmod *
2413  *
2414  * Reset the IP block corresponding to the hwmod @oh during the setup
2415  * process.  The IP block is first enabled so it can be successfully
2416  * reset.  Returns 0 upon success or a negative error code upon
2417  * failure.
2418  */
2419 static int __init _setup_reset(struct omap_hwmod *oh)
2420 {
2421         int r;
2422
2423         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2424                 return -EINVAL;
2425
2426         if (oh->flags & HWMOD_EXT_OPT_MAIN_CLK)
2427                 return -EPERM;
2428
2429         if (oh->rst_lines_cnt == 0) {
2430                 r = _enable(oh);
2431                 if (r) {
2432                         pr_warn("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2433                                 oh->name, oh->_state);
2434                         return -EINVAL;
2435                 }
2436         }
2437
2438         if (!(oh->flags & HWMOD_INIT_NO_RESET))
2439                 r = _reset(oh);
2440
2441         return r;
2442 }
2443
2444 /**
2445  * _setup_postsetup - transition to the appropriate state after _setup
2446  * @oh: struct omap_hwmod *
2447  *
2448  * Place an IP block represented by @oh into a "post-setup" state --
2449  * either IDLE, ENABLED, or DISABLED.  ("post-setup" simply means that
2450  * this function is called at the end of _setup().)  The postsetup
2451  * state for an IP block can be changed by calling
2452  * omap_hwmod_enter_postsetup_state() early in the boot process,
2453  * before one of the omap_hwmod_setup*() functions are called for the
2454  * IP block.
2455  *
2456  * The IP block stays in this state until a PM runtime-based driver is
2457  * loaded for that IP block.  A post-setup state of IDLE is
2458  * appropriate for almost all IP blocks with runtime PM-enabled
2459  * drivers, since those drivers are able to enable the IP block.  A
2460  * post-setup state of ENABLED is appropriate for kernels with PM
2461  * runtime disabled.  The DISABLED state is appropriate for unusual IP
2462  * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2463  * included, since the WDTIMER starts running on reset and will reset
2464  * the MPU if left active.
2465  *
2466  * This post-setup mechanism is deprecated.  Once all of the OMAP
2467  * drivers have been converted to use PM runtime, and all of the IP
2468  * block data and interconnect data is available to the hwmod code, it
2469  * should be possible to replace this mechanism with a "lazy reset"
2470  * arrangement.  In a "lazy reset" setup, each IP block is enabled
2471  * when the driver first probes, then all remaining IP blocks without
2472  * drivers are either shut down or enabled after the drivers have
2473  * loaded.  However, this cannot take place until the above
2474  * preconditions have been met, since otherwise the late reset code
2475  * has no way of knowing which IP blocks are in use by drivers, and
2476  * which ones are unused.
2477  *
2478  * No return value.
2479  */
2480 static void __init _setup_postsetup(struct omap_hwmod *oh)
2481 {
2482         u8 postsetup_state;
2483
2484         if (oh->rst_lines_cnt > 0)
2485                 return;
2486
2487         postsetup_state = oh->_postsetup_state;
2488         if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2489                 postsetup_state = _HWMOD_STATE_ENABLED;
2490
2491         /*
2492          * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2493          * it should be set by the core code as a runtime flag during startup
2494          */
2495         if ((oh->flags & (HWMOD_INIT_NO_IDLE | HWMOD_NO_IDLE)) &&
2496             (postsetup_state == _HWMOD_STATE_IDLE)) {
2497                 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
2498                 postsetup_state = _HWMOD_STATE_ENABLED;
2499         }
2500
2501         if (postsetup_state == _HWMOD_STATE_IDLE)
2502                 _idle(oh);
2503         else if (postsetup_state == _HWMOD_STATE_DISABLED)
2504                 _shutdown(oh);
2505         else if (postsetup_state != _HWMOD_STATE_ENABLED)
2506                 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2507                      oh->name, postsetup_state);
2508
2509         return;
2510 }
2511
2512 /**
2513  * _setup - prepare IP block hardware for use
2514  * @oh: struct omap_hwmod *
2515  * @n: (unused, pass NULL)
2516  *
2517  * Configure the IP block represented by @oh.  This may include
2518  * enabling the IP block, resetting it, and placing it into a
2519  * post-setup state, depending on the type of IP block and applicable
2520  * flags.  IP blocks are reset to prevent any previous configuration
2521  * by the bootloader or previous operating system from interfering
2522  * with power management or other parts of the system.  The reset can
2523  * be avoided; see omap_hwmod_no_setup_reset().  This is the second of
2524  * two phases for hwmod initialization.  Code called here generally
2525  * affects the IP block hardware, or system integration hardware
2526  * associated with the IP block.  Returns 0.
2527  */
2528 static int __init _setup(struct omap_hwmod *oh, void *data)
2529 {
2530         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2531                 return 0;
2532
2533         if (oh->parent_hwmod) {
2534                 int r;
2535
2536                 r = _enable(oh->parent_hwmod);
2537                 WARN(r, "hwmod: %s: setup: failed to enable parent hwmod %s\n",
2538                      oh->name, oh->parent_hwmod->name);
2539         }
2540
2541         _setup_iclk_autoidle(oh);
2542
2543         if (!_setup_reset(oh))
2544                 _setup_postsetup(oh);
2545
2546         if (oh->parent_hwmod) {
2547                 u8 postsetup_state;
2548
2549                 postsetup_state = oh->parent_hwmod->_postsetup_state;
2550
2551                 if (postsetup_state == _HWMOD_STATE_IDLE)
2552                         _idle(oh->parent_hwmod);
2553                 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2554                         _shutdown(oh->parent_hwmod);
2555                 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2556                         WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2557                              oh->parent_hwmod->name, postsetup_state);
2558         }
2559
2560         return 0;
2561 }
2562
2563 /**
2564  * _register - register a struct omap_hwmod
2565  * @oh: struct omap_hwmod *
2566  *
2567  * Registers the omap_hwmod @oh.  Returns -EEXIST if an omap_hwmod
2568  * already has been registered by the same name; -EINVAL if the
2569  * omap_hwmod is in the wrong state, if @oh is NULL, if the
2570  * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2571  * name, or if the omap_hwmod's class is missing a name; or 0 upon
2572  * success.
2573  *
2574  * XXX The data should be copied into bootmem, so the original data
2575  * should be marked __initdata and freed after init.  This would allow
2576  * unneeded omap_hwmods to be freed on multi-OMAP configurations.  Note
2577  * that the copy process would be relatively complex due to the large number
2578  * of substructures.
2579  */
2580 static int __init _register(struct omap_hwmod *oh)
2581 {
2582         if (!oh || !oh->name || !oh->class || !oh->class->name ||
2583             (oh->_state != _HWMOD_STATE_UNKNOWN))
2584                 return -EINVAL;
2585
2586         pr_debug("omap_hwmod: %s: registering\n", oh->name);
2587
2588         if (_lookup(oh->name))
2589                 return -EEXIST;
2590
2591         list_add_tail(&oh->node, &omap_hwmod_list);
2592
2593         INIT_LIST_HEAD(&oh->slave_ports);
2594         spin_lock_init(&oh->_lock);
2595         lockdep_set_class(&oh->_lock, &oh->hwmod_key);
2596
2597         oh->_state = _HWMOD_STATE_REGISTERED;
2598
2599         /*
2600          * XXX Rather than doing a strcmp(), this should test a flag
2601          * set in the hwmod data, inserted by the autogenerator code.
2602          */
2603         if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2604                 mpu_oh = oh;
2605
2606         return 0;
2607 }
2608
2609 /**
2610  * _add_link - add an interconnect between two IP blocks
2611  * @oi: pointer to a struct omap_hwmod_ocp_if record
2612  *
2613  * Add struct omap_hwmod_link records connecting the slave IP block
2614  * specified in @oi->slave to @oi.  This code is assumed to run before
2615  * preemption or SMP has been enabled, thus avoiding the need for
2616  * locking in this code.  Changes to this assumption will require
2617  * additional locking.  Returns 0.
2618  */
2619 static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2620 {
2621         pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2622                  oi->slave->name);
2623
2624         list_add(&oi->node, &oi->slave->slave_ports);
2625         oi->slave->slaves_cnt++;
2626
2627         return 0;
2628 }
2629
2630 /**
2631  * _register_link - register a struct omap_hwmod_ocp_if
2632  * @oi: struct omap_hwmod_ocp_if *
2633  *
2634  * Registers the omap_hwmod_ocp_if record @oi.  Returns -EEXIST if it
2635  * has already been registered; -EINVAL if @oi is NULL or if the
2636  * record pointed to by @oi is missing required fields; or 0 upon
2637  * success.
2638  *
2639  * XXX The data should be copied into bootmem, so the original data
2640  * should be marked __initdata and freed after init.  This would allow
2641  * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2642  */
2643 static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2644 {
2645         if (!oi || !oi->master || !oi->slave || !oi->user)
2646                 return -EINVAL;
2647
2648         if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2649                 return -EEXIST;
2650
2651         pr_debug("omap_hwmod: registering link from %s to %s\n",
2652                  oi->master->name, oi->slave->name);
2653
2654         /*
2655          * Register the connected hwmods, if they haven't been
2656          * registered already
2657          */
2658         if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2659                 _register(oi->master);
2660
2661         if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2662                 _register(oi->slave);
2663
2664         _add_link(oi);
2665
2666         oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2667
2668         return 0;
2669 }
2670
2671 /* Static functions intended only for use in soc_ops field function pointers */
2672
2673 /**
2674  * _omap2xxx_3xxx_wait_target_ready - wait for a module to leave slave idle
2675  * @oh: struct omap_hwmod *
2676  *
2677  * Wait for a module @oh to leave slave idle.  Returns 0 if the module
2678  * does not have an IDLEST bit or if the module successfully leaves
2679  * slave idle; otherwise, pass along the return value of the
2680  * appropriate *_cm*_wait_module_ready() function.
2681  */
2682 static int _omap2xxx_3xxx_wait_target_ready(struct omap_hwmod *oh)
2683 {
2684         if (!oh)
2685                 return -EINVAL;
2686
2687         if (oh->flags & HWMOD_NO_IDLEST)
2688                 return 0;
2689
2690         if (!_find_mpu_rt_port(oh))
2691                 return 0;
2692
2693         /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2694
2695         return omap_cm_wait_module_ready(0, oh->prcm.omap2.module_offs,
2696                                          oh->prcm.omap2.idlest_reg_id,
2697                                          oh->prcm.omap2.idlest_idle_bit);
2698 }
2699
2700 /**
2701  * _omap4_wait_target_ready - wait for a module to leave slave idle
2702  * @oh: struct omap_hwmod *
2703  *
2704  * Wait for a module @oh to leave slave idle.  Returns 0 if the module
2705  * does not have an IDLEST bit or if the module successfully leaves
2706  * slave idle; otherwise, pass along the return value of the
2707  * appropriate *_cm*_wait_module_ready() function.
2708  */
2709 static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2710 {
2711         if (!oh)
2712                 return -EINVAL;
2713
2714         if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
2715                 return 0;
2716
2717         if (!_find_mpu_rt_port(oh))
2718                 return 0;
2719
2720         if (!oh->prcm.omap4.clkctrl_offs &&
2721             !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
2722                 return 0;
2723
2724         /* XXX check module SIDLEMODE, hardreset status */
2725
2726         return omap_cm_wait_module_ready(oh->clkdm->prcm_partition,
2727                                          oh->clkdm->cm_inst,
2728                                          oh->prcm.omap4.clkctrl_offs, 0);
2729 }
2730
2731 /**
2732  * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2733  * @oh: struct omap_hwmod * to assert hardreset
2734  * @ohri: hardreset line data
2735  *
2736  * Call omap2_prm_assert_hardreset() with parameters extracted from
2737  * the hwmod @oh and the hardreset line data @ohri.  Only intended for
2738  * use as an soc_ops function pointer.  Passes along the return value
2739  * from omap2_prm_assert_hardreset().  XXX This function is scheduled
2740  * for removal when the PRM code is moved into drivers/.
2741  */
2742 static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2743                                    struct omap_hwmod_rst_info *ohri)
2744 {
2745         return omap_prm_assert_hardreset(ohri->rst_shift, 0,
2746                                          oh->prcm.omap2.module_offs, 0);
2747 }
2748
2749 /**
2750  * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2751  * @oh: struct omap_hwmod * to deassert hardreset
2752  * @ohri: hardreset line data
2753  *
2754  * Call omap2_prm_deassert_hardreset() with parameters extracted from
2755  * the hwmod @oh and the hardreset line data @ohri.  Only intended for
2756  * use as an soc_ops function pointer.  Passes along the return value
2757  * from omap2_prm_deassert_hardreset().  XXX This function is
2758  * scheduled for removal when the PRM code is moved into drivers/.
2759  */
2760 static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2761                                      struct omap_hwmod_rst_info *ohri)
2762 {
2763         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0,
2764                                            oh->prcm.omap2.module_offs, 0, 0);
2765 }
2766
2767 /**
2768  * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2769  * @oh: struct omap_hwmod * to test hardreset
2770  * @ohri: hardreset line data
2771  *
2772  * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2773  * from the hwmod @oh and the hardreset line data @ohri.  Only
2774  * intended for use as an soc_ops function pointer.  Passes along the
2775  * return value from omap2_prm_is_hardreset_asserted().  XXX This
2776  * function is scheduled for removal when the PRM code is moved into
2777  * drivers/.
2778  */
2779 static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2780                                         struct omap_hwmod_rst_info *ohri)
2781 {
2782         return omap_prm_is_hardreset_asserted(ohri->st_shift, 0,
2783                                               oh->prcm.omap2.module_offs, 0);
2784 }
2785
2786 /**
2787  * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2788  * @oh: struct omap_hwmod * to assert hardreset
2789  * @ohri: hardreset line data
2790  *
2791  * Call omap4_prminst_assert_hardreset() with parameters extracted
2792  * from the hwmod @oh and the hardreset line data @ohri.  Only
2793  * intended for use as an soc_ops function pointer.  Passes along the
2794  * return value from omap4_prminst_assert_hardreset().  XXX This
2795  * function is scheduled for removal when the PRM code is moved into
2796  * drivers/.
2797  */
2798 static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2799                                    struct omap_hwmod_rst_info *ohri)
2800 {
2801         if (!oh->clkdm)
2802                 return -EINVAL;
2803
2804         return omap_prm_assert_hardreset(ohri->rst_shift,
2805                                          oh->clkdm->pwrdm.ptr->prcm_partition,
2806                                          oh->clkdm->pwrdm.ptr->prcm_offs,
2807                                          oh->prcm.omap4.rstctrl_offs);
2808 }
2809
2810 /**
2811  * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2812  * @oh: struct omap_hwmod * to deassert hardreset
2813  * @ohri: hardreset line data
2814  *
2815  * Call omap4_prminst_deassert_hardreset() with parameters extracted
2816  * from the hwmod @oh and the hardreset line data @ohri.  Only
2817  * intended for use as an soc_ops function pointer.  Passes along the
2818  * return value from omap4_prminst_deassert_hardreset().  XXX This
2819  * function is scheduled for removal when the PRM code is moved into
2820  * drivers/.
2821  */
2822 static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2823                                      struct omap_hwmod_rst_info *ohri)
2824 {
2825         if (!oh->clkdm)
2826                 return -EINVAL;
2827
2828         if (ohri->st_shift)
2829                 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2830                        oh->name, ohri->name);
2831         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift,
2832                                            oh->clkdm->pwrdm.ptr->prcm_partition,
2833                                            oh->clkdm->pwrdm.ptr->prcm_offs,
2834                                            oh->prcm.omap4.rstctrl_offs,
2835                                            oh->prcm.omap4.rstctrl_offs +
2836                                            OMAP4_RST_CTRL_ST_OFFSET);
2837 }
2838
2839 /**
2840  * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2841  * @oh: struct omap_hwmod * to test hardreset
2842  * @ohri: hardreset line data
2843  *
2844  * Call omap4_prminst_is_hardreset_asserted() with parameters
2845  * extracted from the hwmod @oh and the hardreset line data @ohri.
2846  * Only intended for use as an soc_ops function pointer.  Passes along
2847  * the return value from omap4_prminst_is_hardreset_asserted().  XXX
2848  * This function is scheduled for removal when the PRM code is moved
2849  * into drivers/.
2850  */
2851 static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2852                                         struct omap_hwmod_rst_info *ohri)
2853 {
2854         if (!oh->clkdm)
2855                 return -EINVAL;
2856
2857         return omap_prm_is_hardreset_asserted(ohri->rst_shift,
2858                                               oh->clkdm->pwrdm.ptr->
2859                                               prcm_partition,
2860                                               oh->clkdm->pwrdm.ptr->prcm_offs,
2861                                               oh->prcm.omap4.rstctrl_offs);
2862 }
2863
2864 /**
2865  * _omap4_disable_direct_prcm - disable direct PRCM control for hwmod
2866  * @oh: struct omap_hwmod * to disable control for
2867  *
2868  * Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod
2869  * will be using its main_clk to enable/disable the module. Returns
2870  * 0 if successful.
2871  */
2872 static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
2873 {
2874         if (!oh)
2875                 return -EINVAL;
2876
2877         oh->prcm.omap4.clkctrl_offs = 0;
2878         oh->prcm.omap4.modulemode = 0;
2879
2880         return 0;
2881 }
2882
2883 /**
2884  * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2885  * @oh: struct omap_hwmod * to deassert hardreset
2886  * @ohri: hardreset line data
2887  *
2888  * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2889  * from the hwmod @oh and the hardreset line data @ohri.  Only
2890  * intended for use as an soc_ops function pointer.  Passes along the
2891  * return value from am33xx_prminst_deassert_hardreset().  XXX This
2892  * function is scheduled for removal when the PRM code is moved into
2893  * drivers/.
2894  */
2895 static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2896                                      struct omap_hwmod_rst_info *ohri)
2897 {
2898         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift,
2899                                            oh->clkdm->pwrdm.ptr->prcm_partition,
2900                                            oh->clkdm->pwrdm.ptr->prcm_offs,
2901                                            oh->prcm.omap4.rstctrl_offs,
2902                                            oh->prcm.omap4.rstst_offs);
2903 }
2904
2905 /* Public functions */
2906
2907 u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
2908 {
2909         if (oh->flags & HWMOD_16BIT_REG)
2910                 return readw_relaxed(oh->_mpu_rt_va + reg_offs);
2911         else
2912                 return readl_relaxed(oh->_mpu_rt_va + reg_offs);
2913 }
2914
2915 void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
2916 {
2917         if (oh->flags & HWMOD_16BIT_REG)
2918                 writew_relaxed(v, oh->_mpu_rt_va + reg_offs);
2919         else
2920                 writel_relaxed(v, oh->_mpu_rt_va + reg_offs);
2921 }
2922
2923 /**
2924  * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
2925  * @oh: struct omap_hwmod *
2926  *
2927  * This is a public function exposed to drivers. Some drivers may need to do
2928  * some settings before and after resetting the device.  Those drivers after
2929  * doing the necessary settings could use this function to start a reset by
2930  * setting the SYSCONFIG.SOFTRESET bit.
2931  */
2932 int omap_hwmod_softreset(struct omap_hwmod *oh)
2933 {
2934         u32 v;
2935         int ret;
2936
2937         if (!oh || !(oh->_sysc_cache))
2938                 return -EINVAL;
2939
2940         v = oh->_sysc_cache;
2941         ret = _set_softreset(oh, &v);
2942         if (ret)
2943                 goto error;
2944         _write_sysconfig(v, oh);
2945
2946         ret = _clear_softreset(oh, &v);
2947         if (ret)
2948                 goto error;
2949         _write_sysconfig(v, oh);
2950
2951 error:
2952         return ret;
2953 }
2954
2955 /**
2956  * omap_hwmod_lookup - look up a registered omap_hwmod by name
2957  * @name: name of the omap_hwmod to look up
2958  *
2959  * Given a @name of an omap_hwmod, return a pointer to the registered
2960  * struct omap_hwmod *, or NULL upon error.
2961  */
2962 struct omap_hwmod *omap_hwmod_lookup(const char *name)
2963 {
2964         struct omap_hwmod *oh;
2965
2966         if (!name)
2967                 return NULL;
2968
2969         oh = _lookup(name);
2970
2971         return oh;
2972 }
2973
2974 /**
2975  * omap_hwmod_for_each - call function for each registered omap_hwmod
2976  * @fn: pointer to a callback function
2977  * @data: void * data to pass to callback function
2978  *
2979  * Call @fn for each registered omap_hwmod, passing @data to each
2980  * function.  @fn must return 0 for success or any other value for
2981  * failure.  If @fn returns non-zero, the iteration across omap_hwmods
2982  * will stop and the non-zero return value will be passed to the
2983  * caller of omap_hwmod_for_each().  @fn is called with
2984  * omap_hwmod_for_each() held.
2985  */
2986 int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
2987                         void *data)
2988 {
2989         struct omap_hwmod *temp_oh;
2990         int ret = 0;
2991
2992         if (!fn)
2993                 return -EINVAL;
2994
2995         list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
2996                 ret = (*fn)(temp_oh, data);
2997                 if (ret)
2998                         break;
2999         }
3000
3001         return ret;
3002 }
3003
3004 /**
3005  * omap_hwmod_register_links - register an array of hwmod links
3006  * @ois: pointer to an array of omap_hwmod_ocp_if to register
3007  *
3008  * Intended to be called early in boot before the clock framework is
3009  * initialized.  If @ois is not null, will register all omap_hwmods
3010  * listed in @ois that are valid for this chip.  Returns -EINVAL if
3011  * omap_hwmod_init() hasn't been called before calling this function,
3012  * -ENOMEM if the link memory area can't be allocated, or 0 upon
3013  * success.
3014  */
3015 int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3016 {
3017         int r, i;
3018
3019         if (!inited)
3020                 return -EINVAL;
3021
3022         if (!ois)
3023                 return 0;
3024
3025         if (ois[0] == NULL) /* Empty list */
3026                 return 0;
3027
3028         i = 0;
3029         do {
3030                 r = _register_link(ois[i]);
3031                 WARN(r && r != -EEXIST,
3032                      "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3033                      ois[i]->master->name, ois[i]->slave->name, r);
3034         } while (ois[++i]);
3035
3036         return 0;
3037 }
3038
3039 /**
3040  * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3041  * @oh: pointer to the hwmod currently being set up (usually not the MPU)
3042  *
3043  * If the hwmod data corresponding to the MPU subsystem IP block
3044  * hasn't been initialized and set up yet, do so now.  This must be
3045  * done first since sleep dependencies may be added from other hwmods
3046  * to the MPU.  Intended to be called only by omap_hwmod_setup*().  No
3047  * return value.
3048  */
3049 static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
3050 {
3051         if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3052                 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3053                        __func__, MPU_INITIATOR_NAME);
3054         else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3055                 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
3056 }
3057
3058 /**
3059  * omap_hwmod_setup_one - set up a single hwmod
3060  * @oh_name: const char * name of the already-registered hwmod to set up
3061  *
3062  * Initialize and set up a single hwmod.  Intended to be used for a
3063  * small number of early devices, such as the timer IP blocks used for
3064  * the scheduler clock.  Must be called after omap2_clk_init().
3065  * Resolves the struct clk names to struct clk pointers for each
3066  * registered omap_hwmod.  Also calls _setup() on each hwmod.  Returns
3067  * -EINVAL upon error or 0 upon success.
3068  */
3069 int __init omap_hwmod_setup_one(const char *oh_name)
3070 {
3071         struct omap_hwmod *oh;
3072
3073         pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3074
3075         oh = _lookup(oh_name);
3076         if (!oh) {
3077                 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3078                 return -EINVAL;
3079         }
3080
3081         _ensure_mpu_hwmod_is_setup(oh);
3082
3083         _init(oh, NULL);
3084         _setup(oh, NULL);
3085
3086         return 0;
3087 }
3088
3089 /**
3090  * omap_hwmod_setup_earlycon_flags - set up flags for early console
3091  *
3092  * Enable DEBUG_OMAPUART_FLAGS for uart hwmod that is being used as
3093  * early concole so that hwmod core doesn't reset and keep it in idle
3094  * that specific uart.
3095  */
3096 #ifdef CONFIG_SERIAL_EARLYCON
3097 static void __init omap_hwmod_setup_earlycon_flags(void)
3098 {
3099         struct device_node *np;
3100         struct omap_hwmod *oh;
3101         const char *uart;
3102
3103         np = of_find_node_by_path("/chosen");
3104         if (np) {
3105                 uart = of_get_property(np, "stdout-path", NULL);
3106                 if (uart) {
3107                         np = of_find_node_by_path(uart);
3108                         if (np) {
3109                                 uart = of_get_property(np, "ti,hwmods", NULL);
3110                                 oh = omap_hwmod_lookup(uart);
3111                                 if (oh)
3112                                         oh->flags |= DEBUG_OMAPUART_FLAGS;
3113                         }
3114                 }
3115         }
3116 }
3117 #endif
3118
3119 /**
3120  * omap_hwmod_setup_all - set up all registered IP blocks
3121  *
3122  * Initialize and set up all IP blocks registered with the hwmod code.
3123  * Must be called after omap2_clk_init().  Resolves the struct clk
3124  * names to struct clk pointers for each registered omap_hwmod.  Also
3125  * calls _setup() on each hwmod.  Returns 0 upon success.
3126  */
3127 static int __init omap_hwmod_setup_all(void)
3128 {
3129         _ensure_mpu_hwmod_is_setup(NULL);
3130
3131         omap_hwmod_for_each(_init, NULL);
3132 #ifdef CONFIG_SERIAL_EARLYCON
3133         omap_hwmod_setup_earlycon_flags();
3134 #endif
3135         omap_hwmod_for_each(_setup, NULL);
3136
3137         return 0;
3138 }
3139 omap_postcore_initcall(omap_hwmod_setup_all);
3140
3141 /**
3142  * omap_hwmod_enable - enable an omap_hwmod
3143  * @oh: struct omap_hwmod *
3144  *
3145  * Enable an omap_hwmod @oh.  Intended to be called by omap_device_enable().
3146  * Returns -EINVAL on error or passes along the return value from _enable().
3147  */
3148 int omap_hwmod_enable(struct omap_hwmod *oh)
3149 {
3150         int r;
3151         unsigned long flags;
3152
3153         if (!oh)
3154                 return -EINVAL;
3155
3156         spin_lock_irqsave(&oh->_lock, flags);
3157         r = _enable(oh);
3158         spin_unlock_irqrestore(&oh->_lock, flags);
3159
3160         return r;
3161 }
3162
3163 /**
3164  * omap_hwmod_idle - idle an omap_hwmod
3165  * @oh: struct omap_hwmod *
3166  *
3167  * Idle an omap_hwmod @oh.  Intended to be called by omap_device_idle().
3168  * Returns -EINVAL on error or passes along the return value from _idle().
3169  */
3170 int omap_hwmod_idle(struct omap_hwmod *oh)
3171 {
3172         int r;
3173         unsigned long flags;
3174
3175         if (!oh)
3176                 return -EINVAL;
3177
3178         spin_lock_irqsave(&oh->_lock, flags);
3179         r = _idle(oh);
3180         spin_unlock_irqrestore(&oh->_lock, flags);
3181
3182         return r;
3183 }
3184
3185 /**
3186  * omap_hwmod_shutdown - shutdown an omap_hwmod
3187  * @oh: struct omap_hwmod *
3188  *
3189  * Shutdown an omap_hwmod @oh.  Intended to be called by
3190  * omap_device_shutdown().  Returns -EINVAL on error or passes along
3191  * the return value from _shutdown().
3192  */
3193 int omap_hwmod_shutdown(struct omap_hwmod *oh)
3194 {
3195         int r;
3196         unsigned long flags;
3197
3198         if (!oh)
3199                 return -EINVAL;
3200
3201         spin_lock_irqsave(&oh->_lock, flags);
3202         r = _shutdown(oh);
3203         spin_unlock_irqrestore(&oh->_lock, flags);
3204
3205         return r;
3206 }
3207
3208 /*
3209  * IP block data retrieval functions
3210  */
3211
3212 /**
3213  * omap_hwmod_count_resources - count number of struct resources needed by hwmod
3214  * @oh: struct omap_hwmod *
3215  * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
3216  *
3217  * Count the number of struct resource array elements necessary to
3218  * contain omap_hwmod @oh resources.  Intended to be called by code
3219  * that registers omap_devices.  Intended to be used to determine the
3220  * size of a dynamically-allocated struct resource array, before
3221  * calling omap_hwmod_fill_resources().  Returns the number of struct
3222  * resource array elements needed.
3223  *
3224  * XXX This code is not optimized.  It could attempt to merge adjacent
3225  * resource IDs.
3226  *
3227  */
3228 int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
3229 {
3230         int ret = 0;
3231
3232         if (flags & IORESOURCE_IRQ)
3233                 ret += _count_mpu_irqs(oh);
3234
3235         if (flags & IORESOURCE_DMA)
3236                 ret += _count_sdma_reqs(oh);
3237
3238         if (flags & IORESOURCE_MEM) {
3239                 struct omap_hwmod_ocp_if *os;
3240
3241                 list_for_each_entry(os, &oh->slave_ports, node)
3242                         ret += _count_ocp_if_addr_spaces(os);
3243         }
3244
3245         return ret;
3246 }
3247
3248 /**
3249  * omap_hwmod_fill_resources - fill struct resource array with hwmod data
3250  * @oh: struct omap_hwmod *
3251  * @res: pointer to the first element of an array of struct resource to fill
3252  *
3253  * Fill the struct resource array @res with resource data from the
3254  * omap_hwmod @oh.  Intended to be called by code that registers
3255  * omap_devices.  See also omap_hwmod_count_resources().  Returns the
3256  * number of array elements filled.
3257  */
3258 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3259 {
3260         struct omap_hwmod_ocp_if *os;
3261         int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
3262         int r = 0;
3263
3264         /* For each IRQ, DMA, memory area, fill in array.*/
3265
3266         mpu_irqs_cnt = _count_mpu_irqs(oh);
3267         for (i = 0; i < mpu_irqs_cnt; i++) {
3268                 unsigned int irq;
3269
3270                 if (oh->xlate_irq)
3271                         irq = oh->xlate_irq((oh->mpu_irqs + i)->irq);
3272                 else
3273                         irq = (oh->mpu_irqs + i)->irq;
3274                 (res + r)->name = (oh->mpu_irqs + i)->name;
3275                 (res + r)->start = irq;
3276                 (res + r)->end = irq;
3277                 (res + r)->flags = IORESOURCE_IRQ;
3278                 r++;
3279         }
3280
3281         sdma_reqs_cnt = _count_sdma_reqs(oh);
3282         for (i = 0; i < sdma_reqs_cnt; i++) {
3283                 (res + r)->name = (oh->sdma_reqs + i)->name;
3284                 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3285                 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3286                 (res + r)->flags = IORESOURCE_DMA;
3287                 r++;
3288         }
3289
3290         list_for_each_entry(os, &oh->slave_ports, node) {
3291                 addr_cnt = _count_ocp_if_addr_spaces(os);
3292
3293                 for (j = 0; j < addr_cnt; j++) {
3294                         (res + r)->name = (os->addr + j)->name;
3295                         (res + r)->start = (os->addr + j)->pa_start;
3296                         (res + r)->end = (os->addr + j)->pa_end;
3297                         (res + r)->flags = IORESOURCE_MEM;
3298                         r++;
3299                 }
3300         }
3301
3302         return r;
3303 }
3304
3305 /**
3306  * omap_hwmod_fill_dma_resources - fill struct resource array with dma data
3307  * @oh: struct omap_hwmod *
3308  * @res: pointer to the array of struct resource to fill
3309  *
3310  * Fill the struct resource array @res with dma resource data from the
3311  * omap_hwmod @oh.  Intended to be called by code that registers
3312  * omap_devices.  See also omap_hwmod_count_resources().  Returns the
3313  * number of array elements filled.
3314  */
3315 int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res)
3316 {
3317         int i, sdma_reqs_cnt;
3318         int r = 0;
3319
3320         sdma_reqs_cnt = _count_sdma_reqs(oh);
3321         for (i = 0; i < sdma_reqs_cnt; i++) {
3322                 (res + r)->name = (oh->sdma_reqs + i)->name;
3323                 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3324                 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3325                 (res + r)->flags = IORESOURCE_DMA;
3326                 r++;
3327         }
3328
3329         return r;
3330 }
3331
3332 /**
3333  * omap_hwmod_get_resource_byname - fetch IP block integration data by name
3334  * @oh: struct omap_hwmod * to operate on
3335  * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
3336  * @name: pointer to the name of the data to fetch (optional)
3337  * @rsrc: pointer to a struct resource, allocated by the caller
3338  *
3339  * Retrieve MPU IRQ, SDMA request line, or address space start/end
3340  * data for the IP block pointed to by @oh.  The data will be filled
3341  * into a struct resource record pointed to by @rsrc.  The struct
3342  * resource must be allocated by the caller.  When @name is non-null,
3343  * the data associated with the matching entry in the IRQ/SDMA/address
3344  * space hwmod data arrays will be returned.  If @name is null, the
3345  * first array entry will be returned.  Data order is not meaningful
3346  * in hwmod data, so callers are strongly encouraged to use a non-null
3347  * @name whenever possible to avoid unpredictable effects if hwmod
3348  * data is later added that causes data ordering to change.  This
3349  * function is only intended for use by OMAP core code.  Device
3350  * drivers should not call this function - the appropriate bus-related
3351  * data accessor functions should be used instead.  Returns 0 upon
3352  * success or a negative error code upon error.
3353  */
3354 int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
3355                                    const char *name, struct resource *rsrc)
3356 {
3357         int r;
3358         unsigned int irq, dma;
3359         u32 pa_start, pa_end;
3360
3361         if (!oh || !rsrc)
3362                 return -EINVAL;
3363
3364         if (type == IORESOURCE_IRQ) {
3365                 r = _get_mpu_irq_by_name(oh, name, &irq);
3366                 if (r)
3367                         return r;
3368
3369                 rsrc->start = irq;
3370                 rsrc->end = irq;
3371         } else if (type == IORESOURCE_DMA) {
3372                 r = _get_sdma_req_by_name(oh, name, &dma);
3373                 if (r)
3374                         return r;
3375
3376                 rsrc->start = dma;
3377                 rsrc->end = dma;
3378         } else if (type == IORESOURCE_MEM) {
3379                 r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
3380                 if (r)
3381                         return r;
3382
3383                 rsrc->start = pa_start;
3384                 rsrc->end = pa_end;
3385         } else {
3386                 return -EINVAL;
3387         }
3388
3389         rsrc->flags = type;
3390         rsrc->name = name;
3391
3392         return 0;
3393 }
3394
3395 /**
3396  * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3397  * @oh: struct omap_hwmod *
3398  *
3399  * Return the powerdomain pointer associated with the OMAP module
3400  * @oh's main clock.  If @oh does not have a main clk, return the
3401  * powerdomain associated with the interface clock associated with the
3402  * module's MPU port. (XXX Perhaps this should use the SDMA port
3403  * instead?)  Returns NULL on error, or a struct powerdomain * on
3404  * success.
3405  */
3406 struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3407 {
3408         struct clk *c;
3409         struct omap_hwmod_ocp_if *oi;
3410         struct clockdomain *clkdm;
3411         struct clk_hw_omap *clk;
3412
3413         if (!oh)
3414                 return NULL;
3415
3416         if (oh->clkdm)
3417                 return oh->clkdm->pwrdm.ptr;
3418
3419         if (oh->_clk) {
3420                 c = oh->_clk;
3421         } else {
3422                 oi = _find_mpu_rt_port(oh);
3423                 if (!oi)
3424                         return NULL;
3425                 c = oi->_clk;
3426         }
3427
3428         clk = to_clk_hw_omap(__clk_get_hw(c));
3429         clkdm = clk->clkdm;
3430         if (!clkdm)
3431                 return NULL;
3432
3433         return clkdm->pwrdm.ptr;
3434 }
3435
3436 /**
3437  * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3438  * @oh: struct omap_hwmod *
3439  *
3440  * Returns the virtual address corresponding to the beginning of the
3441  * module's register target, in the address range that is intended to
3442  * be used by the MPU.  Returns the virtual address upon success or NULL
3443  * upon error.
3444  */
3445 void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3446 {
3447         if (!oh)
3448                 return NULL;
3449
3450         if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3451                 return NULL;
3452
3453         if (oh->_state == _HWMOD_STATE_UNKNOWN)
3454                 return NULL;
3455
3456         return oh->_mpu_rt_va;
3457 }
3458
3459 /*
3460  * XXX what about functions for drivers to save/restore ocp_sysconfig
3461  * for context save/restore operations?
3462  */
3463
3464 /**
3465  * omap_hwmod_enable_wakeup - allow device to wake up the system
3466  * @oh: struct omap_hwmod *
3467  *
3468  * Sets the module OCP socket ENAWAKEUP bit to allow the module to
3469  * send wakeups to the PRCM, and enable I/O ring wakeup events for
3470  * this IP block if it has dynamic mux entries.  Eventually this
3471  * should set PRCM wakeup registers to cause the PRCM to receive
3472  * wakeup events from the module.  Does not set any wakeup routing
3473  * registers beyond this point - if the module is to wake up any other
3474  * module or subsystem, that must be set separately.  Called by
3475  * omap_device code.  Returns -EINVAL on error or 0 upon success.
3476  */
3477 int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3478 {
3479         unsigned long flags;
3480         u32 v;
3481
3482         spin_lock_irqsave(&oh->_lock, flags);
3483
3484         if (oh->class->sysc &&
3485             (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3486                 v = oh->_sysc_cache;
3487                 _enable_wakeup(oh, &v);
3488                 _write_sysconfig(v, oh);
3489         }
3490
3491         spin_unlock_irqrestore(&oh->_lock, flags);
3492
3493         return 0;
3494 }
3495
3496 /**
3497  * omap_hwmod_disable_wakeup - prevent device from waking the system
3498  * @oh: struct omap_hwmod *
3499  *
3500  * Clears the module OCP socket ENAWAKEUP bit to prevent the module
3501  * from sending wakeups to the PRCM, and disable I/O ring wakeup
3502  * events for this IP block if it has dynamic mux entries.  Eventually
3503  * this should clear PRCM wakeup registers to cause the PRCM to ignore
3504  * wakeup events from the module.  Does not set any wakeup routing
3505  * registers beyond this point - if the module is to wake up any other
3506  * module or subsystem, that must be set separately.  Called by
3507  * omap_device code.  Returns -EINVAL on error or 0 upon success.
3508  */
3509 int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3510 {
3511         unsigned long flags;
3512         u32 v;
3513
3514         spin_lock_irqsave(&oh->_lock, flags);
3515
3516         if (oh->class->sysc &&
3517             (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3518                 v = oh->_sysc_cache;
3519                 _disable_wakeup(oh, &v);
3520                 _write_sysconfig(v, oh);
3521         }
3522
3523         spin_unlock_irqrestore(&oh->_lock, flags);
3524
3525         return 0;
3526 }
3527
3528 /**
3529  * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3530  * contained in the hwmod module.
3531  * @oh: struct omap_hwmod *
3532  * @name: name of the reset line to lookup and assert
3533  *
3534  * Some IP like dsp, ipu or iva contain processor that require
3535  * an HW reset line to be assert / deassert in order to enable fully
3536  * the IP.  Returns -EINVAL if @oh is null or if the operation is not
3537  * yet supported on this OMAP; otherwise, passes along the return value
3538  * from _assert_hardreset().
3539  */
3540 int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3541 {
3542         int ret;
3543         unsigned long flags;
3544
3545         if (!oh)
3546                 return -EINVAL;
3547
3548         spin_lock_irqsave(&oh->_lock, flags);
3549         ret = _assert_hardreset(oh, name);
3550         spin_unlock_irqrestore(&oh->_lock, flags);
3551
3552         return ret;
3553 }
3554
3555 /**
3556  * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3557  * contained in the hwmod module.
3558  * @oh: struct omap_hwmod *
3559  * @name: name of the reset line to look up and deassert
3560  *
3561  * Some IP like dsp, ipu or iva contain processor that require
3562  * an HW reset line to be assert / deassert in order to enable fully
3563  * the IP.  Returns -EINVAL if @oh is null or if the operation is not
3564  * yet supported on this OMAP; otherwise, passes along the return value
3565  * from _deassert_hardreset().
3566  */
3567 int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3568 {
3569         int ret;
3570         unsigned long flags;
3571
3572         if (!oh)
3573                 return -EINVAL;
3574
3575         spin_lock_irqsave(&oh->_lock, flags);
3576         ret = _deassert_hardreset(oh, name);
3577         spin_unlock_irqrestore(&oh->_lock, flags);
3578
3579         return ret;
3580 }
3581
3582 /**
3583  * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3584  * @classname: struct omap_hwmod_class name to search for
3585  * @fn: callback function pointer to call for each hwmod in class @classname
3586  * @user: arbitrary context data to pass to the callback function
3587  *
3588  * For each omap_hwmod of class @classname, call @fn.
3589  * If the callback function returns something other than
3590  * zero, the iterator is terminated, and the callback function's return
3591  * value is passed back to the caller.  Returns 0 upon success, -EINVAL
3592  * if @classname or @fn are NULL, or passes back the error code from @fn.
3593  */
3594 int omap_hwmod_for_each_by_class(const char *classname,
3595                                  int (*fn)(struct omap_hwmod *oh,
3596                                            void *user),
3597                                  void *user)
3598 {
3599         struct omap_hwmod *temp_oh;
3600         int ret = 0;
3601
3602         if (!classname || !fn)
3603                 return -EINVAL;
3604
3605         pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3606                  __func__, classname);
3607
3608         list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3609                 if (!strcmp(temp_oh->class->name, classname)) {
3610                         pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3611                                  __func__, temp_oh->name);
3612                         ret = (*fn)(temp_oh, user);
3613                         if (ret)
3614                                 break;
3615                 }
3616         }
3617
3618         if (ret)
3619                 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3620                          __func__, ret);
3621
3622         return ret;
3623 }
3624
3625 /**
3626  * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3627  * @oh: struct omap_hwmod *
3628  * @state: state that _setup() should leave the hwmod in
3629  *
3630  * Sets the hwmod state that @oh will enter at the end of _setup()
3631  * (called by omap_hwmod_setup_*()).  See also the documentation
3632  * for _setup_postsetup(), above.  Returns 0 upon success or
3633  * -EINVAL if there is a problem with the arguments or if the hwmod is
3634  * in the wrong state.
3635  */
3636 int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3637 {
3638         int ret;
3639         unsigned long flags;
3640
3641         if (!oh)
3642                 return -EINVAL;
3643
3644         if (state != _HWMOD_STATE_DISABLED &&
3645             state != _HWMOD_STATE_ENABLED &&
3646             state != _HWMOD_STATE_IDLE)
3647                 return -EINVAL;
3648
3649         spin_lock_irqsave(&oh->_lock, flags);
3650
3651         if (oh->_state != _HWMOD_STATE_REGISTERED) {
3652                 ret = -EINVAL;
3653                 goto ohsps_unlock;
3654         }
3655
3656         oh->_postsetup_state = state;
3657         ret = 0;
3658
3659 ohsps_unlock:
3660         spin_unlock_irqrestore(&oh->_lock, flags);
3661
3662         return ret;
3663 }
3664
3665 /**
3666  * omap_hwmod_get_context_loss_count - get lost context count
3667  * @oh: struct omap_hwmod *
3668  *
3669  * Returns the context loss count of associated @oh
3670  * upon success, or zero if no context loss data is available.
3671  *
3672  * On OMAP4, this queries the per-hwmod context loss register,
3673  * assuming one exists.  If not, or on OMAP2/3, this queries the
3674  * enclosing powerdomain context loss count.
3675  */
3676 int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
3677 {
3678         struct powerdomain *pwrdm;
3679         int ret = 0;
3680
3681         if (soc_ops.get_context_lost)
3682                 return soc_ops.get_context_lost(oh);
3683
3684         pwrdm = omap_hwmod_get_pwrdm(oh);
3685         if (pwrdm)
3686                 ret = pwrdm_get_context_loss_count(pwrdm);
3687
3688         return ret;
3689 }
3690
3691 /**
3692  * omap_hwmod_init - initialize the hwmod code
3693  *
3694  * Sets up some function pointers needed by the hwmod code to operate on the
3695  * currently-booted SoC.  Intended to be called once during kernel init
3696  * before any hwmods are registered.  No return value.
3697  */
3698 void __init omap_hwmod_init(void)
3699 {
3700         if (cpu_is_omap24xx()) {
3701                 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
3702                 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3703                 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3704                 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3705         } else if (cpu_is_omap34xx()) {
3706                 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
3707                 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3708                 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3709                 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3710                 soc_ops.init_clkdm = _init_clkdm;
3711         } else if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx()) {
3712                 soc_ops.enable_module = _omap4_enable_module;
3713                 soc_ops.disable_module = _omap4_disable_module;
3714                 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3715                 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3716                 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
3717                 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3718                 soc_ops.init_clkdm = _init_clkdm;
3719                 soc_ops.update_context_lost = _omap4_update_context_lost;
3720                 soc_ops.get_context_lost = _omap4_get_context_lost;
3721                 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
3722         } else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() ||
3723                    soc_is_am43xx()) {
3724                 soc_ops.enable_module = _omap4_enable_module;
3725                 soc_ops.disable_module = _omap4_disable_module;
3726                 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3727                 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3728                 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
3729                 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3730                 soc_ops.init_clkdm = _init_clkdm;
3731                 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
3732         } else {
3733                 WARN(1, "omap_hwmod: unknown SoC type\n");
3734         }
3735
3736         inited = true;
3737 }
3738
3739 /**
3740  * omap_hwmod_get_main_clk - get pointer to main clock name
3741  * @oh: struct omap_hwmod *
3742  *
3743  * Returns the main clock name assocated with @oh upon success,
3744  * or NULL if @oh is NULL.
3745  */
3746 const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
3747 {
3748         if (!oh)
3749                 return NULL;
3750
3751         return oh->main_clk;
3752 }