]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-omap2/omap_hwmod.c
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[karo-tx-linux.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
2338         if (oh->_state != _HWMOD_STATE_REGISTERED)
2339                 return 0;
2340
2341         if (of_have_populated_dt()) {
2342                 struct device_node *bus;
2343
2344                 bus = of_find_node_by_name(NULL, "ocp");
2345                 if (!bus)
2346                         return -ENODEV;
2347
2348                 r = of_dev_hwmod_lookup(bus, oh, &index, &np);
2349                 if (r)
2350                         pr_debug("omap_hwmod: %s missing dt data\n", oh->name);
2351                 else if (np && index)
2352                         pr_warn("omap_hwmod: %s using broken dt data from %s\n",
2353                                 oh->name, np->name);
2354         }
2355
2356         r = _init_mpu_rt_base(oh, NULL, index, np);
2357         if (r < 0) {
2358                 WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n",
2359                      oh->name);
2360                 return 0;
2361         }
2362
2363         r = _init_clocks(oh, NULL);
2364         if (r < 0) {
2365                 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2366                 return -EINVAL;
2367         }
2368
2369         if (np) {
2370                 if (of_find_property(np, "ti,no-reset-on-init", NULL))
2371                         oh->flags |= HWMOD_INIT_NO_RESET;
2372                 if (of_find_property(np, "ti,no-idle-on-init", NULL))
2373                         oh->flags |= HWMOD_INIT_NO_IDLE;
2374                 if (of_find_property(np, "ti,no-idle", NULL))
2375                         oh->flags |= HWMOD_NO_IDLE;
2376         }
2377
2378         oh->_state = _HWMOD_STATE_INITIALIZED;
2379
2380         return 0;
2381 }
2382
2383 /**
2384  * _setup_iclk_autoidle - configure an IP block's interface clocks
2385  * @oh: struct omap_hwmod *
2386  *
2387  * Set up the module's interface clocks.  XXX This function is still mostly
2388  * a stub; implementing this properly requires iclk autoidle usecounting in
2389  * the clock code.   No return value.
2390  */
2391 static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
2392 {
2393         struct omap_hwmod_ocp_if *os;
2394
2395         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2396                 return;
2397
2398         list_for_each_entry(os, &oh->slave_ports, node) {
2399                 if (!os->_clk)
2400                         continue;
2401
2402                 if (os->flags & OCPIF_SWSUP_IDLE) {
2403                         /* XXX omap_iclk_deny_idle(c); */
2404                 } else {
2405                         /* XXX omap_iclk_allow_idle(c); */
2406                         clk_enable(os->_clk);
2407                 }
2408         }
2409
2410         return;
2411 }
2412
2413 /**
2414  * _setup_reset - reset an IP block during the setup process
2415  * @oh: struct omap_hwmod *
2416  *
2417  * Reset the IP block corresponding to the hwmod @oh during the setup
2418  * process.  The IP block is first enabled so it can be successfully
2419  * reset.  Returns 0 upon success or a negative error code upon
2420  * failure.
2421  */
2422 static int __init _setup_reset(struct omap_hwmod *oh)
2423 {
2424         int r;
2425
2426         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2427                 return -EINVAL;
2428
2429         if (oh->flags & HWMOD_EXT_OPT_MAIN_CLK)
2430                 return -EPERM;
2431
2432         if (oh->rst_lines_cnt == 0) {
2433                 r = _enable(oh);
2434                 if (r) {
2435                         pr_warn("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2436                                 oh->name, oh->_state);
2437                         return -EINVAL;
2438                 }
2439         }
2440
2441         if (!(oh->flags & HWMOD_INIT_NO_RESET))
2442                 r = _reset(oh);
2443
2444         return r;
2445 }
2446
2447 /**
2448  * _setup_postsetup - transition to the appropriate state after _setup
2449  * @oh: struct omap_hwmod *
2450  *
2451  * Place an IP block represented by @oh into a "post-setup" state --
2452  * either IDLE, ENABLED, or DISABLED.  ("post-setup" simply means that
2453  * this function is called at the end of _setup().)  The postsetup
2454  * state for an IP block can be changed by calling
2455  * omap_hwmod_enter_postsetup_state() early in the boot process,
2456  * before one of the omap_hwmod_setup*() functions are called for the
2457  * IP block.
2458  *
2459  * The IP block stays in this state until a PM runtime-based driver is
2460  * loaded for that IP block.  A post-setup state of IDLE is
2461  * appropriate for almost all IP blocks with runtime PM-enabled
2462  * drivers, since those drivers are able to enable the IP block.  A
2463  * post-setup state of ENABLED is appropriate for kernels with PM
2464  * runtime disabled.  The DISABLED state is appropriate for unusual IP
2465  * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2466  * included, since the WDTIMER starts running on reset and will reset
2467  * the MPU if left active.
2468  *
2469  * This post-setup mechanism is deprecated.  Once all of the OMAP
2470  * drivers have been converted to use PM runtime, and all of the IP
2471  * block data and interconnect data is available to the hwmod code, it
2472  * should be possible to replace this mechanism with a "lazy reset"
2473  * arrangement.  In a "lazy reset" setup, each IP block is enabled
2474  * when the driver first probes, then all remaining IP blocks without
2475  * drivers are either shut down or enabled after the drivers have
2476  * loaded.  However, this cannot take place until the above
2477  * preconditions have been met, since otherwise the late reset code
2478  * has no way of knowing which IP blocks are in use by drivers, and
2479  * which ones are unused.
2480  *
2481  * No return value.
2482  */
2483 static void __init _setup_postsetup(struct omap_hwmod *oh)
2484 {
2485         u8 postsetup_state;
2486
2487         if (oh->rst_lines_cnt > 0)
2488                 return;
2489
2490         postsetup_state = oh->_postsetup_state;
2491         if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2492                 postsetup_state = _HWMOD_STATE_ENABLED;
2493
2494         /*
2495          * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2496          * it should be set by the core code as a runtime flag during startup
2497          */
2498         if ((oh->flags & (HWMOD_INIT_NO_IDLE | HWMOD_NO_IDLE)) &&
2499             (postsetup_state == _HWMOD_STATE_IDLE)) {
2500                 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
2501                 postsetup_state = _HWMOD_STATE_ENABLED;
2502         }
2503
2504         if (postsetup_state == _HWMOD_STATE_IDLE)
2505                 _idle(oh);
2506         else if (postsetup_state == _HWMOD_STATE_DISABLED)
2507                 _shutdown(oh);
2508         else if (postsetup_state != _HWMOD_STATE_ENABLED)
2509                 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2510                      oh->name, postsetup_state);
2511
2512         return;
2513 }
2514
2515 /**
2516  * _setup - prepare IP block hardware for use
2517  * @oh: struct omap_hwmod *
2518  * @n: (unused, pass NULL)
2519  *
2520  * Configure the IP block represented by @oh.  This may include
2521  * enabling the IP block, resetting it, and placing it into a
2522  * post-setup state, depending on the type of IP block and applicable
2523  * flags.  IP blocks are reset to prevent any previous configuration
2524  * by the bootloader or previous operating system from interfering
2525  * with power management or other parts of the system.  The reset can
2526  * be avoided; see omap_hwmod_no_setup_reset().  This is the second of
2527  * two phases for hwmod initialization.  Code called here generally
2528  * affects the IP block hardware, or system integration hardware
2529  * associated with the IP block.  Returns 0.
2530  */
2531 static int __init _setup(struct omap_hwmod *oh, void *data)
2532 {
2533         if (oh->_state != _HWMOD_STATE_INITIALIZED)
2534                 return 0;
2535
2536         if (oh->parent_hwmod) {
2537                 int r;
2538
2539                 r = _enable(oh->parent_hwmod);
2540                 WARN(r, "hwmod: %s: setup: failed to enable parent hwmod %s\n",
2541                      oh->name, oh->parent_hwmod->name);
2542         }
2543
2544         _setup_iclk_autoidle(oh);
2545
2546         if (!_setup_reset(oh))
2547                 _setup_postsetup(oh);
2548
2549         if (oh->parent_hwmod) {
2550                 u8 postsetup_state;
2551
2552                 postsetup_state = oh->parent_hwmod->_postsetup_state;
2553
2554                 if (postsetup_state == _HWMOD_STATE_IDLE)
2555                         _idle(oh->parent_hwmod);
2556                 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2557                         _shutdown(oh->parent_hwmod);
2558                 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2559                         WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2560                              oh->parent_hwmod->name, postsetup_state);
2561         }
2562
2563         return 0;
2564 }
2565
2566 /**
2567  * _register - register a struct omap_hwmod
2568  * @oh: struct omap_hwmod *
2569  *
2570  * Registers the omap_hwmod @oh.  Returns -EEXIST if an omap_hwmod
2571  * already has been registered by the same name; -EINVAL if the
2572  * omap_hwmod is in the wrong state, if @oh is NULL, if the
2573  * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2574  * name, or if the omap_hwmod's class is missing a name; or 0 upon
2575  * success.
2576  *
2577  * XXX The data should be copied into bootmem, so the original data
2578  * should be marked __initdata and freed after init.  This would allow
2579  * unneeded omap_hwmods to be freed on multi-OMAP configurations.  Note
2580  * that the copy process would be relatively complex due to the large number
2581  * of substructures.
2582  */
2583 static int __init _register(struct omap_hwmod *oh)
2584 {
2585         if (!oh || !oh->name || !oh->class || !oh->class->name ||
2586             (oh->_state != _HWMOD_STATE_UNKNOWN))
2587                 return -EINVAL;
2588
2589         pr_debug("omap_hwmod: %s: registering\n", oh->name);
2590
2591         if (_lookup(oh->name))
2592                 return -EEXIST;
2593
2594         list_add_tail(&oh->node, &omap_hwmod_list);
2595
2596         INIT_LIST_HEAD(&oh->slave_ports);
2597         spin_lock_init(&oh->_lock);
2598         lockdep_set_class(&oh->_lock, &oh->hwmod_key);
2599
2600         oh->_state = _HWMOD_STATE_REGISTERED;
2601
2602         /*
2603          * XXX Rather than doing a strcmp(), this should test a flag
2604          * set in the hwmod data, inserted by the autogenerator code.
2605          */
2606         if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2607                 mpu_oh = oh;
2608
2609         return 0;
2610 }
2611
2612 /**
2613  * _add_link - add an interconnect between two IP blocks
2614  * @oi: pointer to a struct omap_hwmod_ocp_if record
2615  *
2616  * Add struct omap_hwmod_link records connecting the slave IP block
2617  * specified in @oi->slave to @oi.  This code is assumed to run before
2618  * preemption or SMP has been enabled, thus avoiding the need for
2619  * locking in this code.  Changes to this assumption will require
2620  * additional locking.  Returns 0.
2621  */
2622 static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2623 {
2624         pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2625                  oi->slave->name);
2626
2627         list_add(&oi->node, &oi->slave->slave_ports);
2628         oi->slave->slaves_cnt++;
2629
2630         return 0;
2631 }
2632
2633 /**
2634  * _register_link - register a struct omap_hwmod_ocp_if
2635  * @oi: struct omap_hwmod_ocp_if *
2636  *
2637  * Registers the omap_hwmod_ocp_if record @oi.  Returns -EEXIST if it
2638  * has already been registered; -EINVAL if @oi is NULL or if the
2639  * record pointed to by @oi is missing required fields; or 0 upon
2640  * success.
2641  *
2642  * XXX The data should be copied into bootmem, so the original data
2643  * should be marked __initdata and freed after init.  This would allow
2644  * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2645  */
2646 static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2647 {
2648         if (!oi || !oi->master || !oi->slave || !oi->user)
2649                 return -EINVAL;
2650
2651         if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2652                 return -EEXIST;
2653
2654         pr_debug("omap_hwmod: registering link from %s to %s\n",
2655                  oi->master->name, oi->slave->name);
2656
2657         /*
2658          * Register the connected hwmods, if they haven't been
2659          * registered already
2660          */
2661         if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2662                 _register(oi->master);
2663
2664         if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2665                 _register(oi->slave);
2666
2667         _add_link(oi);
2668
2669         oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2670
2671         return 0;
2672 }
2673
2674 /* Static functions intended only for use in soc_ops field function pointers */
2675
2676 /**
2677  * _omap2xxx_3xxx_wait_target_ready - wait for a module to leave slave idle
2678  * @oh: struct omap_hwmod *
2679  *
2680  * Wait for a module @oh to leave slave idle.  Returns 0 if the module
2681  * does not have an IDLEST bit or if the module successfully leaves
2682  * slave idle; otherwise, pass along the return value of the
2683  * appropriate *_cm*_wait_module_ready() function.
2684  */
2685 static int _omap2xxx_3xxx_wait_target_ready(struct omap_hwmod *oh)
2686 {
2687         if (!oh)
2688                 return -EINVAL;
2689
2690         if (oh->flags & HWMOD_NO_IDLEST)
2691                 return 0;
2692
2693         if (!_find_mpu_rt_port(oh))
2694                 return 0;
2695
2696         /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2697
2698         return omap_cm_wait_module_ready(0, oh->prcm.omap2.module_offs,
2699                                          oh->prcm.omap2.idlest_reg_id,
2700                                          oh->prcm.omap2.idlest_idle_bit);
2701 }
2702
2703 /**
2704  * _omap4_wait_target_ready - wait for a module to leave slave idle
2705  * @oh: struct omap_hwmod *
2706  *
2707  * Wait for a module @oh to leave slave idle.  Returns 0 if the module
2708  * does not have an IDLEST bit or if the module successfully leaves
2709  * slave idle; otherwise, pass along the return value of the
2710  * appropriate *_cm*_wait_module_ready() function.
2711  */
2712 static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2713 {
2714         if (!oh)
2715                 return -EINVAL;
2716
2717         if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
2718                 return 0;
2719
2720         if (!_find_mpu_rt_port(oh))
2721                 return 0;
2722
2723         if (!oh->prcm.omap4.clkctrl_offs &&
2724             !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
2725                 return 0;
2726
2727         /* XXX check module SIDLEMODE, hardreset status */
2728
2729         return omap_cm_wait_module_ready(oh->clkdm->prcm_partition,
2730                                          oh->clkdm->cm_inst,
2731                                          oh->prcm.omap4.clkctrl_offs, 0);
2732 }
2733
2734 /**
2735  * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2736  * @oh: struct omap_hwmod * to assert hardreset
2737  * @ohri: hardreset line data
2738  *
2739  * Call omap2_prm_assert_hardreset() with parameters extracted from
2740  * the hwmod @oh and the hardreset line data @ohri.  Only intended for
2741  * use as an soc_ops function pointer.  Passes along the return value
2742  * from omap2_prm_assert_hardreset().  XXX This function is scheduled
2743  * for removal when the PRM code is moved into drivers/.
2744  */
2745 static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2746                                    struct omap_hwmod_rst_info *ohri)
2747 {
2748         return omap_prm_assert_hardreset(ohri->rst_shift, 0,
2749                                          oh->prcm.omap2.module_offs, 0);
2750 }
2751
2752 /**
2753  * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2754  * @oh: struct omap_hwmod * to deassert hardreset
2755  * @ohri: hardreset line data
2756  *
2757  * Call omap2_prm_deassert_hardreset() with parameters extracted from
2758  * the hwmod @oh and the hardreset line data @ohri.  Only intended for
2759  * use as an soc_ops function pointer.  Passes along the return value
2760  * from omap2_prm_deassert_hardreset().  XXX This function is
2761  * scheduled for removal when the PRM code is moved into drivers/.
2762  */
2763 static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2764                                      struct omap_hwmod_rst_info *ohri)
2765 {
2766         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0,
2767                                            oh->prcm.omap2.module_offs, 0, 0);
2768 }
2769
2770 /**
2771  * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2772  * @oh: struct omap_hwmod * to test hardreset
2773  * @ohri: hardreset line data
2774  *
2775  * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2776  * from the hwmod @oh and the hardreset line data @ohri.  Only
2777  * intended for use as an soc_ops function pointer.  Passes along the
2778  * return value from omap2_prm_is_hardreset_asserted().  XXX This
2779  * function is scheduled for removal when the PRM code is moved into
2780  * drivers/.
2781  */
2782 static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2783                                         struct omap_hwmod_rst_info *ohri)
2784 {
2785         return omap_prm_is_hardreset_asserted(ohri->st_shift, 0,
2786                                               oh->prcm.omap2.module_offs, 0);
2787 }
2788
2789 /**
2790  * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2791  * @oh: struct omap_hwmod * to assert hardreset
2792  * @ohri: hardreset line data
2793  *
2794  * Call omap4_prminst_assert_hardreset() with parameters extracted
2795  * from the hwmod @oh and the hardreset line data @ohri.  Only
2796  * intended for use as an soc_ops function pointer.  Passes along the
2797  * return value from omap4_prminst_assert_hardreset().  XXX This
2798  * function is scheduled for removal when the PRM code is moved into
2799  * drivers/.
2800  */
2801 static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2802                                    struct omap_hwmod_rst_info *ohri)
2803 {
2804         if (!oh->clkdm)
2805                 return -EINVAL;
2806
2807         return omap_prm_assert_hardreset(ohri->rst_shift,
2808                                          oh->clkdm->pwrdm.ptr->prcm_partition,
2809                                          oh->clkdm->pwrdm.ptr->prcm_offs,
2810                                          oh->prcm.omap4.rstctrl_offs);
2811 }
2812
2813 /**
2814  * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2815  * @oh: struct omap_hwmod * to deassert hardreset
2816  * @ohri: hardreset line data
2817  *
2818  * Call omap4_prminst_deassert_hardreset() with parameters extracted
2819  * from the hwmod @oh and the hardreset line data @ohri.  Only
2820  * intended for use as an soc_ops function pointer.  Passes along the
2821  * return value from omap4_prminst_deassert_hardreset().  XXX This
2822  * function is scheduled for removal when the PRM code is moved into
2823  * drivers/.
2824  */
2825 static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2826                                      struct omap_hwmod_rst_info *ohri)
2827 {
2828         if (!oh->clkdm)
2829                 return -EINVAL;
2830
2831         if (ohri->st_shift)
2832                 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2833                        oh->name, ohri->name);
2834         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift,
2835                                            oh->clkdm->pwrdm.ptr->prcm_partition,
2836                                            oh->clkdm->pwrdm.ptr->prcm_offs,
2837                                            oh->prcm.omap4.rstctrl_offs,
2838                                            oh->prcm.omap4.rstctrl_offs +
2839                                            OMAP4_RST_CTRL_ST_OFFSET);
2840 }
2841
2842 /**
2843  * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2844  * @oh: struct omap_hwmod * to test hardreset
2845  * @ohri: hardreset line data
2846  *
2847  * Call omap4_prminst_is_hardreset_asserted() with parameters
2848  * extracted from the hwmod @oh and the hardreset line data @ohri.
2849  * Only intended for use as an soc_ops function pointer.  Passes along
2850  * the return value from omap4_prminst_is_hardreset_asserted().  XXX
2851  * This function is scheduled for removal when the PRM code is moved
2852  * into drivers/.
2853  */
2854 static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2855                                         struct omap_hwmod_rst_info *ohri)
2856 {
2857         if (!oh->clkdm)
2858                 return -EINVAL;
2859
2860         return omap_prm_is_hardreset_asserted(ohri->rst_shift,
2861                                               oh->clkdm->pwrdm.ptr->
2862                                               prcm_partition,
2863                                               oh->clkdm->pwrdm.ptr->prcm_offs,
2864                                               oh->prcm.omap4.rstctrl_offs);
2865 }
2866
2867 /**
2868  * _omap4_disable_direct_prcm - disable direct PRCM control for hwmod
2869  * @oh: struct omap_hwmod * to disable control for
2870  *
2871  * Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod
2872  * will be using its main_clk to enable/disable the module. Returns
2873  * 0 if successful.
2874  */
2875 static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
2876 {
2877         if (!oh)
2878                 return -EINVAL;
2879
2880         oh->prcm.omap4.clkctrl_offs = 0;
2881         oh->prcm.omap4.modulemode = 0;
2882
2883         return 0;
2884 }
2885
2886 /**
2887  * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2888  * @oh: struct omap_hwmod * to deassert hardreset
2889  * @ohri: hardreset line data
2890  *
2891  * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2892  * from the hwmod @oh and the hardreset line data @ohri.  Only
2893  * intended for use as an soc_ops function pointer.  Passes along the
2894  * return value from am33xx_prminst_deassert_hardreset().  XXX This
2895  * function is scheduled for removal when the PRM code is moved into
2896  * drivers/.
2897  */
2898 static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2899                                      struct omap_hwmod_rst_info *ohri)
2900 {
2901         return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift,
2902                                            oh->clkdm->pwrdm.ptr->prcm_partition,
2903                                            oh->clkdm->pwrdm.ptr->prcm_offs,
2904                                            oh->prcm.omap4.rstctrl_offs,
2905                                            oh->prcm.omap4.rstst_offs);
2906 }
2907
2908 /* Public functions */
2909
2910 u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
2911 {
2912         if (oh->flags & HWMOD_16BIT_REG)
2913                 return readw_relaxed(oh->_mpu_rt_va + reg_offs);
2914         else
2915                 return readl_relaxed(oh->_mpu_rt_va + reg_offs);
2916 }
2917
2918 void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
2919 {
2920         if (oh->flags & HWMOD_16BIT_REG)
2921                 writew_relaxed(v, oh->_mpu_rt_va + reg_offs);
2922         else
2923                 writel_relaxed(v, oh->_mpu_rt_va + reg_offs);
2924 }
2925
2926 /**
2927  * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
2928  * @oh: struct omap_hwmod *
2929  *
2930  * This is a public function exposed to drivers. Some drivers may need to do
2931  * some settings before and after resetting the device.  Those drivers after
2932  * doing the necessary settings could use this function to start a reset by
2933  * setting the SYSCONFIG.SOFTRESET bit.
2934  */
2935 int omap_hwmod_softreset(struct omap_hwmod *oh)
2936 {
2937         u32 v;
2938         int ret;
2939
2940         if (!oh || !(oh->_sysc_cache))
2941                 return -EINVAL;
2942
2943         v = oh->_sysc_cache;
2944         ret = _set_softreset(oh, &v);
2945         if (ret)
2946                 goto error;
2947         _write_sysconfig(v, oh);
2948
2949         ret = _clear_softreset(oh, &v);
2950         if (ret)
2951                 goto error;
2952         _write_sysconfig(v, oh);
2953
2954 error:
2955         return ret;
2956 }
2957
2958 /**
2959  * omap_hwmod_lookup - look up a registered omap_hwmod by name
2960  * @name: name of the omap_hwmod to look up
2961  *
2962  * Given a @name of an omap_hwmod, return a pointer to the registered
2963  * struct omap_hwmod *, or NULL upon error.
2964  */
2965 struct omap_hwmod *omap_hwmod_lookup(const char *name)
2966 {
2967         struct omap_hwmod *oh;
2968
2969         if (!name)
2970                 return NULL;
2971
2972         oh = _lookup(name);
2973
2974         return oh;
2975 }
2976
2977 /**
2978  * omap_hwmod_for_each - call function for each registered omap_hwmod
2979  * @fn: pointer to a callback function
2980  * @data: void * data to pass to callback function
2981  *
2982  * Call @fn for each registered omap_hwmod, passing @data to each
2983  * function.  @fn must return 0 for success or any other value for
2984  * failure.  If @fn returns non-zero, the iteration across omap_hwmods
2985  * will stop and the non-zero return value will be passed to the
2986  * caller of omap_hwmod_for_each().  @fn is called with
2987  * omap_hwmod_for_each() held.
2988  */
2989 int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
2990                         void *data)
2991 {
2992         struct omap_hwmod *temp_oh;
2993         int ret = 0;
2994
2995         if (!fn)
2996                 return -EINVAL;
2997
2998         list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
2999                 ret = (*fn)(temp_oh, data);
3000                 if (ret)
3001                         break;
3002         }
3003
3004         return ret;
3005 }
3006
3007 /**
3008  * omap_hwmod_register_links - register an array of hwmod links
3009  * @ois: pointer to an array of omap_hwmod_ocp_if to register
3010  *
3011  * Intended to be called early in boot before the clock framework is
3012  * initialized.  If @ois is not null, will register all omap_hwmods
3013  * listed in @ois that are valid for this chip.  Returns -EINVAL if
3014  * omap_hwmod_init() hasn't been called before calling this function,
3015  * -ENOMEM if the link memory area can't be allocated, or 0 upon
3016  * success.
3017  */
3018 int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3019 {
3020         int r, i;
3021
3022         if (!inited)
3023                 return -EINVAL;
3024
3025         if (!ois)
3026                 return 0;
3027
3028         if (ois[0] == NULL) /* Empty list */
3029                 return 0;
3030
3031         i = 0;
3032         do {
3033                 r = _register_link(ois[i]);
3034                 WARN(r && r != -EEXIST,
3035                      "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3036                      ois[i]->master->name, ois[i]->slave->name, r);
3037         } while (ois[++i]);
3038
3039         return 0;
3040 }
3041
3042 /**
3043  * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3044  * @oh: pointer to the hwmod currently being set up (usually not the MPU)
3045  *
3046  * If the hwmod data corresponding to the MPU subsystem IP block
3047  * hasn't been initialized and set up yet, do so now.  This must be
3048  * done first since sleep dependencies may be added from other hwmods
3049  * to the MPU.  Intended to be called only by omap_hwmod_setup*().  No
3050  * return value.
3051  */
3052 static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
3053 {
3054         if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3055                 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3056                        __func__, MPU_INITIATOR_NAME);
3057         else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3058                 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
3059 }
3060
3061 /**
3062  * omap_hwmod_setup_one - set up a single hwmod
3063  * @oh_name: const char * name of the already-registered hwmod to set up
3064  *
3065  * Initialize and set up a single hwmod.  Intended to be used for a
3066  * small number of early devices, such as the timer IP blocks used for
3067  * the scheduler clock.  Must be called after omap2_clk_init().
3068  * Resolves the struct clk names to struct clk pointers for each
3069  * registered omap_hwmod.  Also calls _setup() on each hwmod.  Returns
3070  * -EINVAL upon error or 0 upon success.
3071  */
3072 int __init omap_hwmod_setup_one(const char *oh_name)
3073 {
3074         struct omap_hwmod *oh;
3075
3076         pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3077
3078         oh = _lookup(oh_name);
3079         if (!oh) {
3080                 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3081                 return -EINVAL;
3082         }
3083
3084         _ensure_mpu_hwmod_is_setup(oh);
3085
3086         _init(oh, NULL);
3087         _setup(oh, NULL);
3088
3089         return 0;
3090 }
3091
3092 /**
3093  * omap_hwmod_setup_earlycon_flags - set up flags for early console
3094  *
3095  * Enable DEBUG_OMAPUART_FLAGS for uart hwmod that is being used as
3096  * early concole so that hwmod core doesn't reset and keep it in idle
3097  * that specific uart.
3098  */
3099 #ifdef CONFIG_SERIAL_EARLYCON
3100 static void __init omap_hwmod_setup_earlycon_flags(void)
3101 {
3102         struct device_node *np;
3103         struct omap_hwmod *oh;
3104         const char *uart;
3105
3106         np = of_find_node_by_path("/chosen");
3107         if (np) {
3108                 uart = of_get_property(np, "stdout-path", NULL);
3109                 if (uart) {
3110                         np = of_find_node_by_path(uart);
3111                         if (np) {
3112                                 uart = of_get_property(np, "ti,hwmods", NULL);
3113                                 oh = omap_hwmod_lookup(uart);
3114                                 if (oh)
3115                                         oh->flags |= DEBUG_OMAPUART_FLAGS;
3116                         }
3117                 }
3118         }
3119 }
3120 #endif
3121
3122 /**
3123  * omap_hwmod_setup_all - set up all registered IP blocks
3124  *
3125  * Initialize and set up all IP blocks registered with the hwmod code.
3126  * Must be called after omap2_clk_init().  Resolves the struct clk
3127  * names to struct clk pointers for each registered omap_hwmod.  Also
3128  * calls _setup() on each hwmod.  Returns 0 upon success.
3129  */
3130 static int __init omap_hwmod_setup_all(void)
3131 {
3132         _ensure_mpu_hwmod_is_setup(NULL);
3133
3134         omap_hwmod_for_each(_init, NULL);
3135 #ifdef CONFIG_SERIAL_EARLYCON
3136         omap_hwmod_setup_earlycon_flags();
3137 #endif
3138         omap_hwmod_for_each(_setup, NULL);
3139
3140         return 0;
3141 }
3142 omap_postcore_initcall(omap_hwmod_setup_all);
3143
3144 /**
3145  * omap_hwmod_enable - enable an omap_hwmod
3146  * @oh: struct omap_hwmod *
3147  *
3148  * Enable an omap_hwmod @oh.  Intended to be called by omap_device_enable().
3149  * Returns -EINVAL on error or passes along the return value from _enable().
3150  */
3151 int omap_hwmod_enable(struct omap_hwmod *oh)
3152 {
3153         int r;
3154         unsigned long flags;
3155
3156         if (!oh)
3157                 return -EINVAL;
3158
3159         spin_lock_irqsave(&oh->_lock, flags);
3160         r = _enable(oh);
3161         spin_unlock_irqrestore(&oh->_lock, flags);
3162
3163         return r;
3164 }
3165
3166 /**
3167  * omap_hwmod_idle - idle an omap_hwmod
3168  * @oh: struct omap_hwmod *
3169  *
3170  * Idle an omap_hwmod @oh.  Intended to be called by omap_device_idle().
3171  * Returns -EINVAL on error or passes along the return value from _idle().
3172  */
3173 int omap_hwmod_idle(struct omap_hwmod *oh)
3174 {
3175         int r;
3176         unsigned long flags;
3177
3178         if (!oh)
3179                 return -EINVAL;
3180
3181         spin_lock_irqsave(&oh->_lock, flags);
3182         r = _idle(oh);
3183         spin_unlock_irqrestore(&oh->_lock, flags);
3184
3185         return r;
3186 }
3187
3188 /**
3189  * omap_hwmod_shutdown - shutdown an omap_hwmod
3190  * @oh: struct omap_hwmod *
3191  *
3192  * Shutdown an omap_hwmod @oh.  Intended to be called by
3193  * omap_device_shutdown().  Returns -EINVAL on error or passes along
3194  * the return value from _shutdown().
3195  */
3196 int omap_hwmod_shutdown(struct omap_hwmod *oh)
3197 {
3198         int r;
3199         unsigned long flags;
3200
3201         if (!oh)
3202                 return -EINVAL;
3203
3204         spin_lock_irqsave(&oh->_lock, flags);
3205         r = _shutdown(oh);
3206         spin_unlock_irqrestore(&oh->_lock, flags);
3207
3208         return r;
3209 }
3210
3211 /*
3212  * IP block data retrieval functions
3213  */
3214
3215 /**
3216  * omap_hwmod_count_resources - count number of struct resources needed by hwmod
3217  * @oh: struct omap_hwmod *
3218  * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
3219  *
3220  * Count the number of struct resource array elements necessary to
3221  * contain omap_hwmod @oh resources.  Intended to be called by code
3222  * that registers omap_devices.  Intended to be used to determine the
3223  * size of a dynamically-allocated struct resource array, before
3224  * calling omap_hwmod_fill_resources().  Returns the number of struct
3225  * resource array elements needed.
3226  *
3227  * XXX This code is not optimized.  It could attempt to merge adjacent
3228  * resource IDs.
3229  *
3230  */
3231 int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
3232 {
3233         int ret = 0;
3234
3235         if (flags & IORESOURCE_IRQ)
3236                 ret += _count_mpu_irqs(oh);
3237
3238         if (flags & IORESOURCE_DMA)
3239                 ret += _count_sdma_reqs(oh);
3240
3241         if (flags & IORESOURCE_MEM) {
3242                 struct omap_hwmod_ocp_if *os;
3243
3244                 list_for_each_entry(os, &oh->slave_ports, node)
3245                         ret += _count_ocp_if_addr_spaces(os);
3246         }
3247
3248         return ret;
3249 }
3250
3251 /**
3252  * omap_hwmod_fill_resources - fill struct resource array with hwmod data
3253  * @oh: struct omap_hwmod *
3254  * @res: pointer to the first element of an array of struct resource to fill
3255  *
3256  * Fill the struct resource array @res with resource data from the
3257  * omap_hwmod @oh.  Intended to be called by code that registers
3258  * omap_devices.  See also omap_hwmod_count_resources().  Returns the
3259  * number of array elements filled.
3260  */
3261 int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3262 {
3263         struct omap_hwmod_ocp_if *os;
3264         int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
3265         int r = 0;
3266
3267         /* For each IRQ, DMA, memory area, fill in array.*/
3268
3269         mpu_irqs_cnt = _count_mpu_irqs(oh);
3270         for (i = 0; i < mpu_irqs_cnt; i++) {
3271                 unsigned int irq;
3272
3273                 if (oh->xlate_irq)
3274                         irq = oh->xlate_irq((oh->mpu_irqs + i)->irq);
3275                 else
3276                         irq = (oh->mpu_irqs + i)->irq;
3277                 (res + r)->name = (oh->mpu_irqs + i)->name;
3278                 (res + r)->start = irq;
3279                 (res + r)->end = irq;
3280                 (res + r)->flags = IORESOURCE_IRQ;
3281                 r++;
3282         }
3283
3284         sdma_reqs_cnt = _count_sdma_reqs(oh);
3285         for (i = 0; i < sdma_reqs_cnt; i++) {
3286                 (res + r)->name = (oh->sdma_reqs + i)->name;
3287                 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3288                 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3289                 (res + r)->flags = IORESOURCE_DMA;
3290                 r++;
3291         }
3292
3293         list_for_each_entry(os, &oh->slave_ports, node) {
3294                 addr_cnt = _count_ocp_if_addr_spaces(os);
3295
3296                 for (j = 0; j < addr_cnt; j++) {
3297                         (res + r)->name = (os->addr + j)->name;
3298                         (res + r)->start = (os->addr + j)->pa_start;
3299                         (res + r)->end = (os->addr + j)->pa_end;
3300                         (res + r)->flags = IORESOURCE_MEM;
3301                         r++;
3302                 }
3303         }
3304
3305         return r;
3306 }
3307
3308 /**
3309  * omap_hwmod_fill_dma_resources - fill struct resource array with dma data
3310  * @oh: struct omap_hwmod *
3311  * @res: pointer to the array of struct resource to fill
3312  *
3313  * Fill the struct resource array @res with dma resource data from the
3314  * omap_hwmod @oh.  Intended to be called by code that registers
3315  * omap_devices.  See also omap_hwmod_count_resources().  Returns the
3316  * number of array elements filled.
3317  */
3318 int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res)
3319 {
3320         int i, sdma_reqs_cnt;
3321         int r = 0;
3322
3323         sdma_reqs_cnt = _count_sdma_reqs(oh);
3324         for (i = 0; i < sdma_reqs_cnt; i++) {
3325                 (res + r)->name = (oh->sdma_reqs + i)->name;
3326                 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3327                 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3328                 (res + r)->flags = IORESOURCE_DMA;
3329                 r++;
3330         }
3331
3332         return r;
3333 }
3334
3335 /**
3336  * omap_hwmod_get_resource_byname - fetch IP block integration data by name
3337  * @oh: struct omap_hwmod * to operate on
3338  * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
3339  * @name: pointer to the name of the data to fetch (optional)
3340  * @rsrc: pointer to a struct resource, allocated by the caller
3341  *
3342  * Retrieve MPU IRQ, SDMA request line, or address space start/end
3343  * data for the IP block pointed to by @oh.  The data will be filled
3344  * into a struct resource record pointed to by @rsrc.  The struct
3345  * resource must be allocated by the caller.  When @name is non-null,
3346  * the data associated with the matching entry in the IRQ/SDMA/address
3347  * space hwmod data arrays will be returned.  If @name is null, the
3348  * first array entry will be returned.  Data order is not meaningful
3349  * in hwmod data, so callers are strongly encouraged to use a non-null
3350  * @name whenever possible to avoid unpredictable effects if hwmod
3351  * data is later added that causes data ordering to change.  This
3352  * function is only intended for use by OMAP core code.  Device
3353  * drivers should not call this function - the appropriate bus-related
3354  * data accessor functions should be used instead.  Returns 0 upon
3355  * success or a negative error code upon error.
3356  */
3357 int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
3358                                    const char *name, struct resource *rsrc)
3359 {
3360         int r;
3361         unsigned int irq, dma;
3362         u32 pa_start, pa_end;
3363
3364         if (!oh || !rsrc)
3365                 return -EINVAL;
3366
3367         if (type == IORESOURCE_IRQ) {
3368                 r = _get_mpu_irq_by_name(oh, name, &irq);
3369                 if (r)
3370                         return r;
3371
3372                 rsrc->start = irq;
3373                 rsrc->end = irq;
3374         } else if (type == IORESOURCE_DMA) {
3375                 r = _get_sdma_req_by_name(oh, name, &dma);
3376                 if (r)
3377                         return r;
3378
3379                 rsrc->start = dma;
3380                 rsrc->end = dma;
3381         } else if (type == IORESOURCE_MEM) {
3382                 r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
3383                 if (r)
3384                         return r;
3385
3386                 rsrc->start = pa_start;
3387                 rsrc->end = pa_end;
3388         } else {
3389                 return -EINVAL;
3390         }
3391
3392         rsrc->flags = type;
3393         rsrc->name = name;
3394
3395         return 0;
3396 }
3397
3398 /**
3399  * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3400  * @oh: struct omap_hwmod *
3401  *
3402  * Return the powerdomain pointer associated with the OMAP module
3403  * @oh's main clock.  If @oh does not have a main clk, return the
3404  * powerdomain associated with the interface clock associated with the
3405  * module's MPU port. (XXX Perhaps this should use the SDMA port
3406  * instead?)  Returns NULL on error, or a struct powerdomain * on
3407  * success.
3408  */
3409 struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3410 {
3411         struct clk *c;
3412         struct omap_hwmod_ocp_if *oi;
3413         struct clockdomain *clkdm;
3414         struct clk_hw_omap *clk;
3415
3416         if (!oh)
3417                 return NULL;
3418
3419         if (oh->clkdm)
3420                 return oh->clkdm->pwrdm.ptr;
3421
3422         if (oh->_clk) {
3423                 c = oh->_clk;
3424         } else {
3425                 oi = _find_mpu_rt_port(oh);
3426                 if (!oi)
3427                         return NULL;
3428                 c = oi->_clk;
3429         }
3430
3431         clk = to_clk_hw_omap(__clk_get_hw(c));
3432         clkdm = clk->clkdm;
3433         if (!clkdm)
3434                 return NULL;
3435
3436         return clkdm->pwrdm.ptr;
3437 }
3438
3439 /**
3440  * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3441  * @oh: struct omap_hwmod *
3442  *
3443  * Returns the virtual address corresponding to the beginning of the
3444  * module's register target, in the address range that is intended to
3445  * be used by the MPU.  Returns the virtual address upon success or NULL
3446  * upon error.
3447  */
3448 void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3449 {
3450         if (!oh)
3451                 return NULL;
3452
3453         if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3454                 return NULL;
3455
3456         if (oh->_state == _HWMOD_STATE_UNKNOWN)
3457                 return NULL;
3458
3459         return oh->_mpu_rt_va;
3460 }
3461
3462 /*
3463  * XXX what about functions for drivers to save/restore ocp_sysconfig
3464  * for context save/restore operations?
3465  */
3466
3467 /**
3468  * omap_hwmod_enable_wakeup - allow device to wake up the system
3469  * @oh: struct omap_hwmod *
3470  *
3471  * Sets the module OCP socket ENAWAKEUP bit to allow the module to
3472  * send wakeups to the PRCM, and enable I/O ring wakeup events for
3473  * this IP block if it has dynamic mux entries.  Eventually this
3474  * should set PRCM wakeup registers to cause the PRCM to receive
3475  * wakeup events from the module.  Does not set any wakeup routing
3476  * registers beyond this point - if the module is to wake up any other
3477  * module or subsystem, that must be set separately.  Called by
3478  * omap_device code.  Returns -EINVAL on error or 0 upon success.
3479  */
3480 int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3481 {
3482         unsigned long flags;
3483         u32 v;
3484
3485         spin_lock_irqsave(&oh->_lock, flags);
3486
3487         if (oh->class->sysc &&
3488             (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3489                 v = oh->_sysc_cache;
3490                 _enable_wakeup(oh, &v);
3491                 _write_sysconfig(v, oh);
3492         }
3493
3494         spin_unlock_irqrestore(&oh->_lock, flags);
3495
3496         return 0;
3497 }
3498
3499 /**
3500  * omap_hwmod_disable_wakeup - prevent device from waking the system
3501  * @oh: struct omap_hwmod *
3502  *
3503  * Clears the module OCP socket ENAWAKEUP bit to prevent the module
3504  * from sending wakeups to the PRCM, and disable I/O ring wakeup
3505  * events for this IP block if it has dynamic mux entries.  Eventually
3506  * this should clear PRCM wakeup registers to cause the PRCM to ignore
3507  * wakeup events from the module.  Does not set any wakeup routing
3508  * registers beyond this point - if the module is to wake up any other
3509  * module or subsystem, that must be set separately.  Called by
3510  * omap_device code.  Returns -EINVAL on error or 0 upon success.
3511  */
3512 int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3513 {
3514         unsigned long flags;
3515         u32 v;
3516
3517         spin_lock_irqsave(&oh->_lock, flags);
3518
3519         if (oh->class->sysc &&
3520             (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3521                 v = oh->_sysc_cache;
3522                 _disable_wakeup(oh, &v);
3523                 _write_sysconfig(v, oh);
3524         }
3525
3526         spin_unlock_irqrestore(&oh->_lock, flags);
3527
3528         return 0;
3529 }
3530
3531 /**
3532  * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3533  * contained in the hwmod module.
3534  * @oh: struct omap_hwmod *
3535  * @name: name of the reset line to lookup and assert
3536  *
3537  * Some IP like dsp, ipu or iva contain processor that require
3538  * an HW reset line to be assert / deassert in order to enable fully
3539  * the IP.  Returns -EINVAL if @oh is null or if the operation is not
3540  * yet supported on this OMAP; otherwise, passes along the return value
3541  * from _assert_hardreset().
3542  */
3543 int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3544 {
3545         int ret;
3546         unsigned long flags;
3547
3548         if (!oh)
3549                 return -EINVAL;
3550
3551         spin_lock_irqsave(&oh->_lock, flags);
3552         ret = _assert_hardreset(oh, name);
3553         spin_unlock_irqrestore(&oh->_lock, flags);
3554
3555         return ret;
3556 }
3557
3558 /**
3559  * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3560  * contained in the hwmod module.
3561  * @oh: struct omap_hwmod *
3562  * @name: name of the reset line to look up and deassert
3563  *
3564  * Some IP like dsp, ipu or iva contain processor that require
3565  * an HW reset line to be assert / deassert in order to enable fully
3566  * the IP.  Returns -EINVAL if @oh is null or if the operation is not
3567  * yet supported on this OMAP; otherwise, passes along the return value
3568  * from _deassert_hardreset().
3569  */
3570 int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3571 {
3572         int ret;
3573         unsigned long flags;
3574
3575         if (!oh)
3576                 return -EINVAL;
3577
3578         spin_lock_irqsave(&oh->_lock, flags);
3579         ret = _deassert_hardreset(oh, name);
3580         spin_unlock_irqrestore(&oh->_lock, flags);
3581
3582         return ret;
3583 }
3584
3585 /**
3586  * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3587  * @classname: struct omap_hwmod_class name to search for
3588  * @fn: callback function pointer to call for each hwmod in class @classname
3589  * @user: arbitrary context data to pass to the callback function
3590  *
3591  * For each omap_hwmod of class @classname, call @fn.
3592  * If the callback function returns something other than
3593  * zero, the iterator is terminated, and the callback function's return
3594  * value is passed back to the caller.  Returns 0 upon success, -EINVAL
3595  * if @classname or @fn are NULL, or passes back the error code from @fn.
3596  */
3597 int omap_hwmod_for_each_by_class(const char *classname,
3598                                  int (*fn)(struct omap_hwmod *oh,
3599                                            void *user),
3600                                  void *user)
3601 {
3602         struct omap_hwmod *temp_oh;
3603         int ret = 0;
3604
3605         if (!classname || !fn)
3606                 return -EINVAL;
3607
3608         pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3609                  __func__, classname);
3610
3611         list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3612                 if (!strcmp(temp_oh->class->name, classname)) {
3613                         pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3614                                  __func__, temp_oh->name);
3615                         ret = (*fn)(temp_oh, user);
3616                         if (ret)
3617                                 break;
3618                 }
3619         }
3620
3621         if (ret)
3622                 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3623                          __func__, ret);
3624
3625         return ret;
3626 }
3627
3628 /**
3629  * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3630  * @oh: struct omap_hwmod *
3631  * @state: state that _setup() should leave the hwmod in
3632  *
3633  * Sets the hwmod state that @oh will enter at the end of _setup()
3634  * (called by omap_hwmod_setup_*()).  See also the documentation
3635  * for _setup_postsetup(), above.  Returns 0 upon success or
3636  * -EINVAL if there is a problem with the arguments or if the hwmod is
3637  * in the wrong state.
3638  */
3639 int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3640 {
3641         int ret;
3642         unsigned long flags;
3643
3644         if (!oh)
3645                 return -EINVAL;
3646
3647         if (state != _HWMOD_STATE_DISABLED &&
3648             state != _HWMOD_STATE_ENABLED &&
3649             state != _HWMOD_STATE_IDLE)
3650                 return -EINVAL;
3651
3652         spin_lock_irqsave(&oh->_lock, flags);
3653
3654         if (oh->_state != _HWMOD_STATE_REGISTERED) {
3655                 ret = -EINVAL;
3656                 goto ohsps_unlock;
3657         }
3658
3659         oh->_postsetup_state = state;
3660         ret = 0;
3661
3662 ohsps_unlock:
3663         spin_unlock_irqrestore(&oh->_lock, flags);
3664
3665         return ret;
3666 }
3667
3668 /**
3669  * omap_hwmod_get_context_loss_count - get lost context count
3670  * @oh: struct omap_hwmod *
3671  *
3672  * Returns the context loss count of associated @oh
3673  * upon success, or zero if no context loss data is available.
3674  *
3675  * On OMAP4, this queries the per-hwmod context loss register,
3676  * assuming one exists.  If not, or on OMAP2/3, this queries the
3677  * enclosing powerdomain context loss count.
3678  */
3679 int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
3680 {
3681         struct powerdomain *pwrdm;
3682         int ret = 0;
3683
3684         if (soc_ops.get_context_lost)
3685                 return soc_ops.get_context_lost(oh);
3686
3687         pwrdm = omap_hwmod_get_pwrdm(oh);
3688         if (pwrdm)
3689                 ret = pwrdm_get_context_loss_count(pwrdm);
3690
3691         return ret;
3692 }
3693
3694 /**
3695  * omap_hwmod_init - initialize the hwmod code
3696  *
3697  * Sets up some function pointers needed by the hwmod code to operate on the
3698  * currently-booted SoC.  Intended to be called once during kernel init
3699  * before any hwmods are registered.  No return value.
3700  */
3701 void __init omap_hwmod_init(void)
3702 {
3703         if (cpu_is_omap24xx()) {
3704                 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
3705                 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3706                 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3707                 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3708         } else if (cpu_is_omap34xx()) {
3709                 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
3710                 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3711                 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3712                 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3713                 soc_ops.init_clkdm = _init_clkdm;
3714         } else if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx()) {
3715                 soc_ops.enable_module = _omap4_enable_module;
3716                 soc_ops.disable_module = _omap4_disable_module;
3717                 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3718                 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3719                 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
3720                 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3721                 soc_ops.init_clkdm = _init_clkdm;
3722                 soc_ops.update_context_lost = _omap4_update_context_lost;
3723                 soc_ops.get_context_lost = _omap4_get_context_lost;
3724                 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
3725         } else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() ||
3726                    soc_is_am43xx()) {
3727                 soc_ops.enable_module = _omap4_enable_module;
3728                 soc_ops.disable_module = _omap4_disable_module;
3729                 soc_ops.wait_target_ready = _omap4_wait_target_ready;
3730                 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3731                 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
3732                 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
3733                 soc_ops.init_clkdm = _init_clkdm;
3734                 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
3735         } else {
3736                 WARN(1, "omap_hwmod: unknown SoC type\n");
3737         }
3738
3739         inited = true;
3740 }
3741
3742 /**
3743  * omap_hwmod_get_main_clk - get pointer to main clock name
3744  * @oh: struct omap_hwmod *
3745  *
3746  * Returns the main clock name assocated with @oh upon success,
3747  * or NULL if @oh is NULL.
3748  */
3749 const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
3750 {
3751         if (!oh)
3752                 return NULL;
3753
3754         return oh->main_clk;
3755 }