blob: c3d3e62a5ac245311b72da067f0db25050e1fb7b [file] [log] [blame]
Paul Walmsley63c85232009-09-03 20:14:03 +03001/*
2 * omap_hwmod implementation for OMAP2/3/4
3 *
Paul Walmsley550c8092011-02-28 11:58:14 -07004 * Copyright (C) 2009-2011 Nokia Corporation
Paul Walmsley30e105c2012-04-19 00:49:09 -06005 * Copyright (C) 2011-2012 Texas Instruments, Inc.
Paul Walmsley63c85232009-09-03 20:14:03 +03006 *
Paul Walmsley4788da22010-05-18 20:24:05 -06007 * 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
Paul Walmsley63c85232009-09-03 20:14:03 +030012 *
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 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -060017 * 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.
Paul Walmsley63c85232009-09-03 20:14:03 +030027 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -060028 * 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 * | (__raw_{read,write}l, 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.
Paul Walmsley63c85232009-09-03 20:14:03 +0300113 * - 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:
Paul Walmsley63c85232009-09-03 20:14:03 +0300120 * - 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>
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700133#ifdef CONFIG_COMMON_CLK
134#include <linux/clk-provider.h>
135#else
Paul Walmsley63c85232009-09-03 20:14:03 +0300136#include <linux/clk.h>
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700137#endif
Paul Walmsley63c85232009-09-03 20:14:03 +0300138#include <linux/delay.h>
139#include <linux/err.h>
140#include <linux/list.h>
141#include <linux/mutex.h>
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -0700142#include <linux/spinlock.h>
Tero Kristoabc2d542011-12-16 14:36:59 -0700143#include <linux/slab.h>
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600144#include <linux/bootmem.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300145
Paul Walmsleya135eaa2012-09-27 10:33:34 -0600146#include "clock.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -0700147#include "omap_hwmod.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300148
Tony Lindgrendbc04162012-08-31 10:59:07 -0700149#include "soc.h"
150#include "common.h"
151#include "clockdomain.h"
152#include "powerdomain.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -0600153#include "cm2xxx.h"
154#include "cm3xxx.h"
Benoit Coussond0f06312011-07-10 05:56:30 -0600155#include "cminst44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600156#include "cm33xx.h"
Paul Walmsleyb13159a2012-10-29 20:57:44 -0600157#include "prm.h"
Paul Walmsley139563a2012-10-21 01:01:10 -0600158#include "prm3xxx.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -0700159#include "prm44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600160#include "prm33xx.h"
Benoit Coussoneaac3292011-07-10 05:56:31 -0600161#include "prminst44xx.h"
Tony Lindgren8d9af882010-12-22 18:42:35 -0800162#include "mux.h"
Vishwanath BS51658822012-06-22 08:40:04 -0600163#include "pm.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300164
Paul Walmsley63c85232009-09-03 20:14:03 +0300165/* Name of the OMAP hwmod for the MPU */
Benoit Cousson5c2c0292010-05-20 12:31:10 -0600166#define MPU_INITIATOR_NAME "mpu"
Paul Walmsley63c85232009-09-03 20:14:03 +0300167
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600168/*
169 * Number of struct omap_hwmod_link records per struct
170 * omap_hwmod_ocp_if record (master->slave and slave->master)
171 */
172#define LINKS_PER_OCP_IF 2
173
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600174/**
175 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
176 * @enable_module: function to enable a module (via MODULEMODE)
177 * @disable_module: function to disable a module (via MODULEMODE)
178 *
179 * XXX Eventually this functionality will be hidden inside the PRM/CM
180 * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
181 * conditionals in this code.
182 */
183struct omap_hwmod_soc_ops {
184 void (*enable_module)(struct omap_hwmod *oh);
185 int (*disable_module)(struct omap_hwmod *oh);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -0600186 int (*wait_target_ready)(struct omap_hwmod *oh);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -0600187 int (*assert_hardreset)(struct omap_hwmod *oh,
188 struct omap_hwmod_rst_info *ohri);
189 int (*deassert_hardreset)(struct omap_hwmod *oh,
190 struct omap_hwmod_rst_info *ohri);
191 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
192 struct omap_hwmod_rst_info *ohri);
Kevin Hilman0a179ea2012-06-18 12:12:25 -0600193 int (*init_clkdm)(struct omap_hwmod *oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600194};
195
196/* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
197static struct omap_hwmod_soc_ops soc_ops;
198
Paul Walmsley63c85232009-09-03 20:14:03 +0300199/* omap_hwmod_list contains all registered struct omap_hwmods */
200static LIST_HEAD(omap_hwmod_list);
201
Paul Walmsley63c85232009-09-03 20:14:03 +0300202/* mpu_oh: used to add/remove MPU initiator from sleepdep list */
203static struct omap_hwmod *mpu_oh;
204
Vishwanath BS51658822012-06-22 08:40:04 -0600205/* io_chain_lock: used to serialize reconfigurations of the I/O chain */
206static DEFINE_SPINLOCK(io_chain_lock);
207
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600208/*
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600209 * linkspace: ptr to a buffer that struct omap_hwmod_link records are
210 * allocated from - used to reduce the number of small memory
211 * allocations, which has a significant impact on performance
212 */
213static struct omap_hwmod_link *linkspace;
214
215/*
216 * free_ls, max_ls: array indexes into linkspace; representing the
217 * next free struct omap_hwmod_link index, and the maximum number of
218 * struct omap_hwmod_link records allocated (respectively)
219 */
220static unsigned short free_ls, max_ls, ls_supp;
Paul Walmsley63c85232009-09-03 20:14:03 +0300221
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600222/* inited: set to true once the hwmod code is initialized */
223static bool inited;
224
Paul Walmsley63c85232009-09-03 20:14:03 +0300225/* Private functions */
226
227/**
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600228 * _fetch_next_ocp_if - return the next OCP interface in a list
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600229 * @p: ptr to a ptr to the list_head inside the ocp_if to return
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600230 * @i: pointer to the index of the element pointed to by @p in the list
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600231 *
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600232 * Return a pointer to the struct omap_hwmod_ocp_if record
233 * containing the struct list_head pointed to by @p, and increment
234 * @p such that a future call to this routine will return the next
235 * record.
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600236 */
237static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600238 int *i)
239{
240 struct omap_hwmod_ocp_if *oi;
241
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600242 oi = list_entry(*p, struct omap_hwmod_link, node)->ocp_if;
243 *p = (*p)->next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600244
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600245 *i = *i + 1;
246
247 return oi;
248}
249
250/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300251 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
252 * @oh: struct omap_hwmod *
253 *
254 * Load the current value of the hwmod OCP_SYSCONFIG register into the
255 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
256 * OCP_SYSCONFIG register or 0 upon success.
257 */
258static int _update_sysc_cache(struct omap_hwmod *oh)
259{
Paul Walmsley43b40992010-02-22 22:09:34 -0700260 if (!oh->class->sysc) {
261 WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +0300262 return -EINVAL;
263 }
264
265 /* XXX ensure module interface clock is up */
266
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -0700267 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300268
Paul Walmsley43b40992010-02-22 22:09:34 -0700269 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
Thara Gopinath883edfd2010-01-19 17:30:51 -0700270 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
Paul Walmsley63c85232009-09-03 20:14:03 +0300271
272 return 0;
273}
274
275/**
276 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
277 * @v: OCP_SYSCONFIG value to write
278 * @oh: struct omap_hwmod *
279 *
Paul Walmsley43b40992010-02-22 22:09:34 -0700280 * Write @v into the module class' OCP_SYSCONFIG register, if it has
281 * one. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +0300282 */
283static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
284{
Paul Walmsley43b40992010-02-22 22:09:34 -0700285 if (!oh->class->sysc) {
286 WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +0300287 return;
288 }
289
290 /* XXX ensure module interface clock is up */
291
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700292 /* Module might have lost context, always update cache and register */
293 oh->_sysc_cache = v;
294 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300295}
296
297/**
298 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
299 * @oh: struct omap_hwmod *
300 * @standbymode: MIDLEMODE field bits
301 * @v: pointer to register contents to modify
302 *
303 * Update the master standby mode bits in @v to be @standbymode for
304 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
305 * upon error or 0 upon success.
306 */
307static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
308 u32 *v)
309{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700310 u32 mstandby_mask;
311 u8 mstandby_shift;
312
Paul Walmsley43b40992010-02-22 22:09:34 -0700313 if (!oh->class->sysc ||
314 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300315 return -EINVAL;
316
Paul Walmsley43b40992010-02-22 22:09:34 -0700317 if (!oh->class->sysc->sysc_fields) {
318 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700319 return -EINVAL;
320 }
321
Paul Walmsley43b40992010-02-22 22:09:34 -0700322 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700323 mstandby_mask = (0x3 << mstandby_shift);
324
325 *v &= ~mstandby_mask;
326 *v |= __ffs(standbymode) << mstandby_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300327
328 return 0;
329}
330
331/**
332 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
333 * @oh: struct omap_hwmod *
334 * @idlemode: SIDLEMODE field bits
335 * @v: pointer to register contents to modify
336 *
337 * Update the slave idle mode bits in @v to be @idlemode for the @oh
338 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
339 * or 0 upon success.
340 */
341static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
342{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700343 u32 sidle_mask;
344 u8 sidle_shift;
345
Paul Walmsley43b40992010-02-22 22:09:34 -0700346 if (!oh->class->sysc ||
347 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300348 return -EINVAL;
349
Paul Walmsley43b40992010-02-22 22:09:34 -0700350 if (!oh->class->sysc->sysc_fields) {
351 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700352 return -EINVAL;
353 }
354
Paul Walmsley43b40992010-02-22 22:09:34 -0700355 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700356 sidle_mask = (0x3 << sidle_shift);
357
358 *v &= ~sidle_mask;
359 *v |= __ffs(idlemode) << sidle_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300360
361 return 0;
362}
363
364/**
365 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
366 * @oh: struct omap_hwmod *
367 * @clockact: CLOCKACTIVITY field bits
368 * @v: pointer to register contents to modify
369 *
370 * Update the clockactivity mode bits in @v to be @clockact for the
371 * @oh hwmod. Used for additional powersaving on some modules. Does
372 * not write to the hardware. Returns -EINVAL upon error or 0 upon
373 * success.
374 */
375static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
376{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700377 u32 clkact_mask;
378 u8 clkact_shift;
379
Paul Walmsley43b40992010-02-22 22:09:34 -0700380 if (!oh->class->sysc ||
381 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
Paul Walmsley63c85232009-09-03 20:14:03 +0300382 return -EINVAL;
383
Paul Walmsley43b40992010-02-22 22:09:34 -0700384 if (!oh->class->sysc->sysc_fields) {
385 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700386 return -EINVAL;
387 }
388
Paul Walmsley43b40992010-02-22 22:09:34 -0700389 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700390 clkact_mask = (0x3 << clkact_shift);
391
392 *v &= ~clkact_mask;
393 *v |= clockact << clkact_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300394
395 return 0;
396}
397
398/**
399 * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
400 * @oh: struct omap_hwmod *
401 * @v: pointer to register contents to modify
402 *
403 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
404 * error or 0 upon success.
405 */
406static int _set_softreset(struct omap_hwmod *oh, u32 *v)
407{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700408 u32 softrst_mask;
409
Paul Walmsley43b40992010-02-22 22:09:34 -0700410 if (!oh->class->sysc ||
411 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley63c85232009-09-03 20:14:03 +0300412 return -EINVAL;
413
Paul Walmsley43b40992010-02-22 22:09:34 -0700414 if (!oh->class->sysc->sysc_fields) {
415 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700416 return -EINVAL;
417 }
418
Paul Walmsley43b40992010-02-22 22:09:34 -0700419 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700420
421 *v |= softrst_mask;
Paul Walmsley63c85232009-09-03 20:14:03 +0300422
423 return 0;
424}
425
426/**
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -0600427 * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
428 * @oh: struct omap_hwmod *
429 *
430 * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
431 * of some modules. When the DMA must perform read/write accesses, the
432 * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
433 * for power management, software must set the DMADISABLE bit back to 1.
434 *
435 * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
436 * error or 0 upon success.
437 */
438static int _set_dmadisable(struct omap_hwmod *oh)
439{
440 u32 v;
441 u32 dmadisable_mask;
442
443 if (!oh->class->sysc ||
444 !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
445 return -EINVAL;
446
447 if (!oh->class->sysc->sysc_fields) {
448 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
449 return -EINVAL;
450 }
451
452 /* clocks must be on for this operation */
453 if (oh->_state != _HWMOD_STATE_ENABLED) {
454 pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
455 return -EINVAL;
456 }
457
458 pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
459
460 v = oh->_sysc_cache;
461 dmadisable_mask =
462 (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
463 v |= dmadisable_mask;
464 _write_sysconfig(v, oh);
465
466 return 0;
467}
468
469/**
Paul Walmsley726072e2009-12-08 16:34:15 -0700470 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
471 * @oh: struct omap_hwmod *
472 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
473 * @v: pointer to register contents to modify
474 *
475 * Update the module autoidle bit in @v to be @autoidle for the @oh
476 * hwmod. The autoidle bit controls whether the module can gate
477 * internal clocks automatically when it isn't doing anything; the
478 * exact function of this bit varies on a per-module basis. This
479 * function does not write to the hardware. Returns -EINVAL upon
480 * error or 0 upon success.
481 */
482static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
483 u32 *v)
484{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700485 u32 autoidle_mask;
486 u8 autoidle_shift;
487
Paul Walmsley43b40992010-02-22 22:09:34 -0700488 if (!oh->class->sysc ||
489 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
Paul Walmsley726072e2009-12-08 16:34:15 -0700490 return -EINVAL;
491
Paul Walmsley43b40992010-02-22 22:09:34 -0700492 if (!oh->class->sysc->sysc_fields) {
493 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700494 return -EINVAL;
495 }
496
Paul Walmsley43b40992010-02-22 22:09:34 -0700497 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
Tarun Kanti DebBarma8985b632011-03-03 14:22:46 -0700498 autoidle_mask = (0x1 << autoidle_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700499
500 *v &= ~autoidle_mask;
501 *v |= autoidle << autoidle_shift;
Paul Walmsley726072e2009-12-08 16:34:15 -0700502
503 return 0;
504}
505
506/**
Govindraj Receec002011-12-16 14:36:58 -0700507 * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
508 * @oh: struct omap_hwmod *
509 * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
510 *
511 * Set or clear the I/O pad wakeup flag in the mux entries for the
512 * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
513 * in memory. If the hwmod is currently idled, and the new idle
514 * values don't match the previous ones, this function will also
515 * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
516 * currently idled, this function won't touch the hardware: the new
517 * mux settings are written to the SCM PADCTRL registers when the
518 * hwmod is idled. No return value.
519 */
520static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
521{
522 struct omap_device_pad *pad;
523 bool change = false;
524 u16 prev_idle;
525 int j;
526
527 if (!oh->mux || !oh->mux->enabled)
528 return;
529
530 for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
531 pad = oh->mux->pads_dynamic[j];
532
533 if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
534 continue;
535
536 prev_idle = pad->idle;
537
538 if (set_wake)
539 pad->idle |= OMAP_WAKEUP_EN;
540 else
541 pad->idle &= ~OMAP_WAKEUP_EN;
542
543 if (prev_idle != pad->idle)
544 change = true;
545 }
546
547 if (change && oh->_state == _HWMOD_STATE_IDLE)
548 omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
549}
550
551/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300552 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
553 * @oh: struct omap_hwmod *
554 *
555 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
556 * upon error or 0 upon success.
557 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700558static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300559{
Paul Walmsley43b40992010-02-22 22:09:34 -0700560 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700561 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200562 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
563 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300564 return -EINVAL;
565
Paul Walmsley43b40992010-02-22 22:09:34 -0700566 if (!oh->class->sysc->sysc_fields) {
567 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700568 return -EINVAL;
569 }
570
Benoit Cousson1fe74112011-07-01 22:54:03 +0200571 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
572 *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300573
Benoit Cousson86009eb2010-12-21 21:31:28 -0700574 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
575 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200576 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
577 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700578
Paul Walmsley63c85232009-09-03 20:14:03 +0300579 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
580
581 oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
582
583 return 0;
584}
585
586/**
587 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
588 * @oh: struct omap_hwmod *
589 *
590 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
591 * upon error or 0 upon success.
592 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700593static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300594{
Paul Walmsley43b40992010-02-22 22:09:34 -0700595 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700596 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200597 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
598 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300599 return -EINVAL;
600
Paul Walmsley43b40992010-02-22 22:09:34 -0700601 if (!oh->class->sysc->sysc_fields) {
602 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700603 return -EINVAL;
604 }
605
Benoit Cousson1fe74112011-07-01 22:54:03 +0200606 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
607 *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
Paul Walmsley63c85232009-09-03 20:14:03 +0300608
Benoit Cousson86009eb2010-12-21 21:31:28 -0700609 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
610 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200611 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
Djamil Elaidi561038f2012-06-17 11:57:51 -0600612 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700613
Paul Walmsley63c85232009-09-03 20:14:03 +0300614 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
615
616 oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
617
618 return 0;
619}
620
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700621static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
622{
623 if (oh->clkdm) {
624 return oh->clkdm;
625 } else if (oh->_clk) {
626#ifdef CONFIG_COMMON_CLK
627 struct clk_hw_omap *clk;
628
629 clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
630 return clk->clkdm;
631#else
632 return oh->_clk->clkdm;
633#endif
634 }
635 return NULL;
636}
637
Paul Walmsley63c85232009-09-03 20:14:03 +0300638/**
639 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
640 * @oh: struct omap_hwmod *
641 *
642 * Prevent the hardware module @oh from entering idle while the
643 * hardare module initiator @init_oh is active. Useful when a module
644 * will be accessed by a particular initiator (e.g., if a module will
645 * be accessed by the IVA, there should be a sleepdep between the IVA
646 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700647 * mode. If the clockdomain is marked as not needing autodeps, return
648 * 0 without doing anything. Otherwise, returns -EINVAL upon error or
649 * passes along clkdm_add_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300650 */
651static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
652{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700653 struct clockdomain *clkdm, *init_clkdm;
654
655 clkdm = _get_clkdm(oh);
656 init_clkdm = _get_clkdm(init_oh);
657
658 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300659 return -EINVAL;
660
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700661 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700662 return 0;
663
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700664 return clkdm_add_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300665}
666
667/**
668 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
669 * @oh: struct omap_hwmod *
670 *
671 * Allow the hardware module @oh to enter idle while the hardare
672 * module initiator @init_oh is active. Useful when a module will not
673 * be accessed by a particular initiator (e.g., if a module will not
674 * be accessed by the IVA, there should be no sleepdep between the IVA
675 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700676 * mode. If the clockdomain is marked as not needing autodeps, return
677 * 0 without doing anything. Returns -EINVAL upon error or passes
678 * along clkdm_del_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300679 */
680static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
681{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700682 struct clockdomain *clkdm, *init_clkdm;
683
684 clkdm = _get_clkdm(oh);
685 init_clkdm = _get_clkdm(init_oh);
686
687 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300688 return -EINVAL;
689
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700690 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700691 return 0;
692
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700693 return clkdm_del_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300694}
695
696/**
697 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
698 * @oh: struct omap_hwmod *
699 *
700 * Called from _init_clocks(). Populates the @oh _clk (main
701 * functional clock pointer) if a main_clk is present. Returns 0 on
702 * success or -EINVAL on error.
703 */
704static int _init_main_clk(struct omap_hwmod *oh)
705{
Paul Walmsley63c85232009-09-03 20:14:03 +0300706 int ret = 0;
707
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700708 if (!oh->main_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300709 return 0;
710
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600711 oh->_clk = clk_get(NULL, oh->main_clk);
712 if (IS_ERR(oh->_clk)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600713 pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
714 oh->name, oh->main_clk);
Benoit Cousson63403382010-05-20 12:31:10 -0600715 return -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600716 }
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600717 /*
718 * HACK: This needs a re-visit once clk_prepare() is implemented
719 * to do something meaningful. Today its just a no-op.
720 * If clk_prepare() is used at some point to do things like
721 * voltage scaling etc, then this would have to be moved to
722 * some point where subsystems like i2c and pmic become
723 * available.
724 */
725 clk_prepare(oh->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300726
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700727 if (!_get_clkdm(oh))
Paul Walmsley3bb05db2012-09-23 17:28:18 -0600728 pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600729 oh->name, oh->main_clk);
Kevin Hilman81d7c6f2009-12-08 16:34:24 -0700730
Paul Walmsley63c85232009-09-03 20:14:03 +0300731 return ret;
732}
733
734/**
Paul Walmsley887adea2010-07-26 16:34:33 -0600735 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
Paul Walmsley63c85232009-09-03 20:14:03 +0300736 * @oh: struct omap_hwmod *
737 *
738 * Called from _init_clocks(). Populates the @oh OCP slave interface
739 * clock pointers. Returns 0 on success or -EINVAL on error.
740 */
741static int _init_interface_clks(struct omap_hwmod *oh)
742{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600743 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600744 struct list_head *p;
Paul Walmsley63c85232009-09-03 20:14:03 +0300745 struct clk *c;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600746 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300747 int ret = 0;
748
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600749 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600750
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600751 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600752 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700753 if (!os->clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300754 continue;
755
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600756 c = clk_get(NULL, os->clk);
757 if (IS_ERR(c)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600758 pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
759 oh->name, os->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300760 ret = -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600761 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300762 os->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600763 /*
764 * HACK: This needs a re-visit once clk_prepare() is implemented
765 * to do something meaningful. Today its just a no-op.
766 * If clk_prepare() is used at some point to do things like
767 * voltage scaling etc, then this would have to be moved to
768 * some point where subsystems like i2c and pmic become
769 * available.
770 */
771 clk_prepare(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300772 }
773
774 return ret;
775}
776
777/**
778 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
779 * @oh: struct omap_hwmod *
780 *
781 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
782 * clock pointers. Returns 0 on success or -EINVAL on error.
783 */
784static int _init_opt_clks(struct omap_hwmod *oh)
785{
786 struct omap_hwmod_opt_clk *oc;
787 struct clk *c;
788 int i;
789 int ret = 0;
790
791 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600792 c = clk_get(NULL, oc->clk);
793 if (IS_ERR(c)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600794 pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
795 oh->name, oc->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300796 ret = -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600797 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300798 oc->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600799 /*
800 * HACK: This needs a re-visit once clk_prepare() is implemented
801 * to do something meaningful. Today its just a no-op.
802 * If clk_prepare() is used at some point to do things like
803 * voltage scaling etc, then this would have to be moved to
804 * some point where subsystems like i2c and pmic become
805 * available.
806 */
807 clk_prepare(oc->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300808 }
809
810 return ret;
811}
812
813/**
814 * _enable_clocks - enable hwmod main clock and interface clocks
815 * @oh: struct omap_hwmod *
816 *
817 * Enables all clocks necessary for register reads and writes to succeed
818 * on the hwmod @oh. Returns 0.
819 */
820static int _enable_clocks(struct omap_hwmod *oh)
821{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600822 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600823 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600824 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300825
826 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
827
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600828 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300829 clk_enable(oh->_clk);
830
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600831 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600832
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600833 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600834 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +0300835
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600836 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
837 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300838 }
839
840 /* The opt clocks are controlled by the device driver. */
841
842 return 0;
843}
844
845/**
846 * _disable_clocks - disable hwmod main clock and interface clocks
847 * @oh: struct omap_hwmod *
848 *
849 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
850 */
851static int _disable_clocks(struct omap_hwmod *oh)
852{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600853 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600854 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600855 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300856
857 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
858
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600859 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300860 clk_disable(oh->_clk);
861
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600862 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600863
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600864 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600865 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +0300866
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600867 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
868 clk_disable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300869 }
870
871 /* The opt clocks are controlled by the device driver. */
872
873 return 0;
874}
875
Benoit Cousson96835af2010-09-21 18:57:58 +0200876static void _enable_optional_clocks(struct omap_hwmod *oh)
877{
878 struct omap_hwmod_opt_clk *oc;
879 int i;
880
881 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
882
883 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
884 if (oc->_clk) {
885 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600886 __clk_get_name(oc->_clk));
Benoit Cousson96835af2010-09-21 18:57:58 +0200887 clk_enable(oc->_clk);
888 }
889}
890
891static void _disable_optional_clocks(struct omap_hwmod *oh)
892{
893 struct omap_hwmod_opt_clk *oc;
894 int i;
895
896 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
897
898 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
899 if (oc->_clk) {
900 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600901 __clk_get_name(oc->_clk));
Benoit Cousson96835af2010-09-21 18:57:58 +0200902 clk_disable(oc->_clk);
903 }
904}
905
Paul Walmsley63c85232009-09-03 20:14:03 +0300906/**
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600907 * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
Benoit Cousson45c38252011-07-10 05:56:33 -0600908 * @oh: struct omap_hwmod *
909 *
910 * Enables the PRCM module mode related to the hwmod @oh.
911 * No return value.
912 */
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600913static void _omap4_enable_module(struct omap_hwmod *oh)
Benoit Cousson45c38252011-07-10 05:56:33 -0600914{
Benoit Cousson45c38252011-07-10 05:56:33 -0600915 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
916 return;
917
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600918 pr_debug("omap_hwmod: %s: %s: %d\n",
919 oh->name, __func__, oh->prcm.omap4.modulemode);
Benoit Cousson45c38252011-07-10 05:56:33 -0600920
921 omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
922 oh->clkdm->prcm_partition,
923 oh->clkdm->cm_inst,
924 oh->clkdm->clkdm_offs,
925 oh->prcm.omap4.clkctrl_offs);
926}
927
928/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600929 * _am33xx_enable_module - enable CLKCTRL modulemode on AM33XX
930 * @oh: struct omap_hwmod *
931 *
932 * Enables the PRCM module mode related to the hwmod @oh.
933 * No return value.
934 */
935static void _am33xx_enable_module(struct omap_hwmod *oh)
936{
937 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
938 return;
939
940 pr_debug("omap_hwmod: %s: %s: %d\n",
941 oh->name, __func__, oh->prcm.omap4.modulemode);
942
943 am33xx_cm_module_enable(oh->prcm.omap4.modulemode, oh->clkdm->cm_inst,
944 oh->clkdm->clkdm_offs,
945 oh->prcm.omap4.clkctrl_offs);
946}
947
948/**
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800949 * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
950 * @oh: struct omap_hwmod *
951 *
952 * Wait for a module @oh to enter slave idle. Returns 0 if the module
953 * does not have an IDLEST bit or if the module successfully enters
954 * slave idle; otherwise, pass along the return value of the
955 * appropriate *_cm*_wait_module_idle() function.
956 */
957static int _omap4_wait_target_disable(struct omap_hwmod *oh)
958{
Paul Walmsley2b026d12012-09-23 17:28:18 -0600959 if (!oh)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800960 return -EINVAL;
961
Paul Walmsley2b026d12012-09-23 17:28:18 -0600962 if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800963 return 0;
964
965 if (oh->flags & HWMOD_NO_IDLEST)
966 return 0;
967
968 return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
969 oh->clkdm->cm_inst,
970 oh->clkdm->clkdm_offs,
971 oh->prcm.omap4.clkctrl_offs);
972}
973
974/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600975 * _am33xx_wait_target_disable - wait for a module to be disabled on AM33XX
976 * @oh: struct omap_hwmod *
977 *
978 * Wait for a module @oh to enter slave idle. Returns 0 if the module
979 * does not have an IDLEST bit or if the module successfully enters
980 * slave idle; otherwise, pass along the return value of the
981 * appropriate *_cm*_wait_module_idle() function.
982 */
983static int _am33xx_wait_target_disable(struct omap_hwmod *oh)
984{
985 if (!oh)
986 return -EINVAL;
987
988 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
989 return 0;
990
991 if (oh->flags & HWMOD_NO_IDLEST)
992 return 0;
993
994 return am33xx_cm_wait_module_idle(oh->clkdm->cm_inst,
995 oh->clkdm->clkdm_offs,
996 oh->prcm.omap4.clkctrl_offs);
997}
998
999/**
Paul Walmsley212738a2011-07-09 19:14:06 -06001000 * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
1001 * @oh: struct omap_hwmod *oh
1002 *
1003 * Count and return the number of MPU IRQs associated with the hwmod
1004 * @oh. Used to allocate struct resource data. Returns 0 if @oh is
1005 * NULL.
1006 */
1007static int _count_mpu_irqs(struct omap_hwmod *oh)
1008{
1009 struct omap_hwmod_irq_info *ohii;
1010 int i = 0;
1011
1012 if (!oh || !oh->mpu_irqs)
1013 return 0;
1014
1015 do {
1016 ohii = &oh->mpu_irqs[i++];
1017 } while (ohii->irq != -1);
1018
sricharancc1b0762011-11-23 14:35:07 -08001019 return i-1;
Paul Walmsley212738a2011-07-09 19:14:06 -06001020}
1021
1022/**
Paul Walmsleybc614952011-07-09 19:14:07 -06001023 * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
1024 * @oh: struct omap_hwmod *oh
1025 *
1026 * Count and return the number of SDMA request lines associated with
1027 * the hwmod @oh. Used to allocate struct resource data. Returns 0
1028 * if @oh is NULL.
1029 */
1030static int _count_sdma_reqs(struct omap_hwmod *oh)
1031{
1032 struct omap_hwmod_dma_info *ohdi;
1033 int i = 0;
1034
1035 if (!oh || !oh->sdma_reqs)
1036 return 0;
1037
1038 do {
1039 ohdi = &oh->sdma_reqs[i++];
1040 } while (ohdi->dma_req != -1);
1041
sricharancc1b0762011-11-23 14:35:07 -08001042 return i-1;
Paul Walmsleybc614952011-07-09 19:14:07 -06001043}
1044
1045/**
Paul Walmsley78183f32011-07-09 19:14:05 -06001046 * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
1047 * @oh: struct omap_hwmod *oh
1048 *
1049 * Count and return the number of address space ranges associated with
1050 * the hwmod @oh. Used to allocate struct resource data. Returns 0
1051 * if @oh is NULL.
1052 */
1053static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
1054{
1055 struct omap_hwmod_addr_space *mem;
1056 int i = 0;
1057
1058 if (!os || !os->addr)
1059 return 0;
1060
1061 do {
1062 mem = &os->addr[i++];
1063 } while (mem->pa_start != mem->pa_end);
1064
sricharancc1b0762011-11-23 14:35:07 -08001065 return i-1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001066}
1067
1068/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001069 * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
1070 * @oh: struct omap_hwmod * to operate on
1071 * @name: pointer to the name of the MPU interrupt number to fetch (optional)
1072 * @irq: pointer to an unsigned int to store the MPU IRQ number to
1073 *
1074 * Retrieve a MPU hardware IRQ line number named by @name associated
1075 * with the IP block pointed to by @oh. The IRQ number will be filled
1076 * into the address pointed to by @dma. When @name is non-null, the
1077 * IRQ line number associated with the named entry will be returned.
1078 * If @name is null, the first matching entry will be returned. Data
1079 * order is not meaningful in hwmod data, so callers are strongly
1080 * encouraged to use a non-null @name whenever possible to avoid
1081 * unpredictable effects if hwmod data is later added that causes data
1082 * ordering to change. Returns 0 upon success or a negative error
1083 * code upon error.
1084 */
1085static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
1086 unsigned int *irq)
1087{
1088 int i;
1089 bool found = false;
1090
1091 if (!oh->mpu_irqs)
1092 return -ENOENT;
1093
1094 i = 0;
1095 while (oh->mpu_irqs[i].irq != -1) {
1096 if (name == oh->mpu_irqs[i].name ||
1097 !strcmp(name, oh->mpu_irqs[i].name)) {
1098 found = true;
1099 break;
1100 }
1101 i++;
1102 }
1103
1104 if (!found)
1105 return -ENOENT;
1106
1107 *irq = oh->mpu_irqs[i].irq;
1108
1109 return 0;
1110}
1111
1112/**
1113 * _get_sdma_req_by_name - fetch SDMA request line ID by name
1114 * @oh: struct omap_hwmod * to operate on
1115 * @name: pointer to the name of the SDMA request line to fetch (optional)
1116 * @dma: pointer to an unsigned int to store the request line ID to
1117 *
1118 * Retrieve an SDMA request line ID named by @name on the IP block
1119 * pointed to by @oh. The ID will be filled into the address pointed
1120 * to by @dma. When @name is non-null, the request line ID associated
1121 * with the named entry will be returned. If @name is null, the first
1122 * matching entry will be returned. Data order is not meaningful in
1123 * hwmod data, so callers are strongly encouraged to use a non-null
1124 * @name whenever possible to avoid unpredictable effects if hwmod
1125 * data is later added that causes data ordering to change. Returns 0
1126 * upon success or a negative error code upon error.
1127 */
1128static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
1129 unsigned int *dma)
1130{
1131 int i;
1132 bool found = false;
1133
1134 if (!oh->sdma_reqs)
1135 return -ENOENT;
1136
1137 i = 0;
1138 while (oh->sdma_reqs[i].dma_req != -1) {
1139 if (name == oh->sdma_reqs[i].name ||
1140 !strcmp(name, oh->sdma_reqs[i].name)) {
1141 found = true;
1142 break;
1143 }
1144 i++;
1145 }
1146
1147 if (!found)
1148 return -ENOENT;
1149
1150 *dma = oh->sdma_reqs[i].dma_req;
1151
1152 return 0;
1153}
1154
1155/**
1156 * _get_addr_space_by_name - fetch address space start & end by name
1157 * @oh: struct omap_hwmod * to operate on
1158 * @name: pointer to the name of the address space to fetch (optional)
1159 * @pa_start: pointer to a u32 to store the starting address to
1160 * @pa_end: pointer to a u32 to store the ending address to
1161 *
1162 * Retrieve address space start and end addresses for the IP block
1163 * pointed to by @oh. The data will be filled into the addresses
1164 * pointed to by @pa_start and @pa_end. When @name is non-null, the
1165 * address space data associated with the named entry will be
1166 * returned. If @name is null, the first matching entry will be
1167 * returned. Data order is not meaningful in hwmod data, so callers
1168 * are strongly encouraged to use a non-null @name whenever possible
1169 * to avoid unpredictable effects if hwmod data is later added that
1170 * causes data ordering to change. Returns 0 upon success or a
1171 * negative error code upon error.
1172 */
1173static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1174 u32 *pa_start, u32 *pa_end)
1175{
1176 int i, j;
1177 struct omap_hwmod_ocp_if *os;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001178 struct list_head *p = NULL;
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001179 bool found = false;
1180
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001181 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001182
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001183 i = 0;
1184 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001185 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001186
1187 if (!os->addr)
1188 return -ENOENT;
1189
1190 j = 0;
1191 while (os->addr[j].pa_start != os->addr[j].pa_end) {
1192 if (name == os->addr[j].name ||
1193 !strcmp(name, os->addr[j].name)) {
1194 found = true;
1195 break;
1196 }
1197 j++;
1198 }
1199
1200 if (found)
1201 break;
1202 }
1203
1204 if (!found)
1205 return -ENOENT;
1206
1207 *pa_start = os->addr[j].pa_start;
1208 *pa_end = os->addr[j].pa_end;
1209
1210 return 0;
1211}
1212
1213/**
Paul Walmsley24dbc212012-04-19 04:04:29 -06001214 * _save_mpu_port_index - find and save the index to @oh's MPU port
Paul Walmsley63c85232009-09-03 20:14:03 +03001215 * @oh: struct omap_hwmod *
1216 *
Paul Walmsley24dbc212012-04-19 04:04:29 -06001217 * Determines the array index of the OCP slave port that the MPU uses
1218 * to address the device, and saves it into the struct omap_hwmod.
1219 * Intended to be called during hwmod registration only. No return
1220 * value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001221 */
Paul Walmsley24dbc212012-04-19 04:04:29 -06001222static void __init _save_mpu_port_index(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001223{
Paul Walmsley24dbc212012-04-19 04:04:29 -06001224 struct omap_hwmod_ocp_if *os = NULL;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001225 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001226 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001227
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001228 if (!oh)
Paul Walmsley24dbc212012-04-19 04:04:29 -06001229 return;
1230
1231 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001232
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001233 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001234
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001235 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001236 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +03001237 if (os->user & OCP_USER_MPU) {
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001238 oh->_mpu_port = os;
Paul Walmsley24dbc212012-04-19 04:04:29 -06001239 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001240 break;
1241 }
1242 }
1243
Paul Walmsley24dbc212012-04-19 04:04:29 -06001244 return;
Paul Walmsley63c85232009-09-03 20:14:03 +03001245}
1246
1247/**
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001248 * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
1249 * @oh: struct omap_hwmod *
1250 *
1251 * Given a pointer to a struct omap_hwmod record @oh, return a pointer
1252 * to the struct omap_hwmod_ocp_if record that is used by the MPU to
1253 * communicate with the IP block. This interface need not be directly
1254 * connected to the MPU (and almost certainly is not), but is directly
1255 * connected to the IP block represented by @oh. Returns a pointer
1256 * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
1257 * error or if there does not appear to be a path from the MPU to this
1258 * IP block.
1259 */
1260static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
1261{
1262 if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
1263 return NULL;
1264
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001265 return oh->_mpu_port;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001266};
1267
1268/**
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001269 * _find_mpu_rt_addr_space - return MPU register target address space for @oh
Paul Walmsley63c85232009-09-03 20:14:03 +03001270 * @oh: struct omap_hwmod *
1271 *
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001272 * Returns a pointer to the struct omap_hwmod_addr_space record representing
1273 * the register target MPU address space; or returns NULL upon error.
Paul Walmsley63c85232009-09-03 20:14:03 +03001274 */
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001275static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001276{
1277 struct omap_hwmod_ocp_if *os;
1278 struct omap_hwmod_addr_space *mem;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001279 int found = 0, i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001280
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001281 os = _find_mpu_rt_port(oh);
Paul Walmsley24dbc212012-04-19 04:04:29 -06001282 if (!os || !os->addr)
Paul Walmsley78183f32011-07-09 19:14:05 -06001283 return NULL;
1284
1285 do {
1286 mem = &os->addr[i++];
1287 if (mem->flags & ADDR_TYPE_RT)
Paul Walmsley63c85232009-09-03 20:14:03 +03001288 found = 1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001289 } while (!found && mem->pa_start != mem->pa_end);
Paul Walmsley63c85232009-09-03 20:14:03 +03001290
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001291 return (found) ? mem : NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +03001292}
1293
1294/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001295 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001296 * @oh: struct omap_hwmod *
1297 *
Paul Walmsley006c7f12012-07-04 05:22:53 -06001298 * Ensure that the OCP_SYSCONFIG register for the IP block represented
1299 * by @oh is set to indicate to the PRCM that the IP block is active.
1300 * Usually this means placing the module into smart-idle mode and
1301 * smart-standby, but if there is a bug in the automatic idle handling
1302 * for the IP block, it may need to be placed into the force-idle or
1303 * no-idle variants of these modes. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001304 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001305static void _enable_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001306{
Paul Walmsley43b40992010-02-22 22:09:34 -07001307 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001308 u32 v;
Paul Walmsley006c7f12012-07-04 05:22:53 -06001309 bool clkdm_act;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001310 struct clockdomain *clkdm;
Paul Walmsley63c85232009-09-03 20:14:03 +03001311
Paul Walmsley43b40992010-02-22 22:09:34 -07001312 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001313 return;
1314
1315 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001316 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001317
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001318 clkdm = _get_clkdm(oh);
Paul Walmsley43b40992010-02-22 22:09:34 -07001319 if (sf & SYSC_HAS_SIDLEMODE) {
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001320 clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
Paul Walmsley006c7f12012-07-04 05:22:53 -06001321 if (clkdm_act && !(oh->class->sysc->idlemodes &
1322 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1323 idlemode = HWMOD_IDLEMODE_FORCE;
1324 else
1325 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
1326 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
Paul Walmsley63c85232009-09-03 20:14:03 +03001327 _set_slave_idlemode(oh, idlemode, &v);
1328 }
1329
Paul Walmsley43b40992010-02-22 22:09:34 -07001330 if (sf & SYSC_HAS_MIDLEMODE) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001331 if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
1332 idlemode = HWMOD_IDLEMODE_NO;
1333 } else {
1334 if (sf & SYSC_HAS_ENAWAKEUP)
1335 _enable_wakeup(oh, &v);
1336 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1337 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1338 else
1339 idlemode = HWMOD_IDLEMODE_SMART;
1340 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001341 _set_master_standbymode(oh, idlemode, &v);
1342 }
1343
Paul Walmsleya16b1f72009-12-08 16:34:17 -07001344 /*
1345 * XXX The clock framework should handle this, by
1346 * calling into this code. But this must wait until the
1347 * clock structures are tagged with omap_hwmod entries
1348 */
Paul Walmsley43b40992010-02-22 22:09:34 -07001349 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1350 (sf & SYSC_HAS_CLOCKACTIVITY))
1351 _set_clockactivity(oh, oh->class->sysc->clockact, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001352
Rajendra Nayak9980ce52010-09-21 19:58:30 +05301353 /* If slave is in SMARTIDLE, also enable wakeup */
1354 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07001355 _enable_wakeup(oh, &v);
1356
1357 _write_sysconfig(v, oh);
Hema HK78f26e82010-09-24 10:23:19 -06001358
1359 /*
1360 * Set the autoidle bit only after setting the smartidle bit
1361 * Setting this will not have any impact on the other modules.
1362 */
1363 if (sf & SYSC_HAS_AUTOIDLE) {
1364 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
1365 0 : 1;
1366 _set_module_autoidle(oh, idlemode, &v);
1367 _write_sysconfig(v, oh);
1368 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001369}
1370
1371/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001372 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001373 * @oh: struct omap_hwmod *
1374 *
1375 * If module is marked as SWSUP_SIDLE, force the module into slave
1376 * idle; otherwise, configure it for smart-idle. If module is marked
1377 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
1378 * configure it for smart-standby. No return value.
1379 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001380static void _idle_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001381{
Paul Walmsley43b40992010-02-22 22:09:34 -07001382 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001383 u32 v;
1384
Paul Walmsley43b40992010-02-22 22:09:34 -07001385 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001386 return;
1387
1388 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001389 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001390
Paul Walmsley43b40992010-02-22 22:09:34 -07001391 if (sf & SYSC_HAS_SIDLEMODE) {
Paul Walmsley006c7f12012-07-04 05:22:53 -06001392 /* XXX What about HWMOD_IDLEMODE_SMART_WKUP? */
1393 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1394 !(oh->class->sysc->idlemodes &
1395 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1396 idlemode = HWMOD_IDLEMODE_FORCE;
1397 else
1398 idlemode = HWMOD_IDLEMODE_SMART;
Paul Walmsley63c85232009-09-03 20:14:03 +03001399 _set_slave_idlemode(oh, idlemode, &v);
1400 }
1401
Paul Walmsley43b40992010-02-22 22:09:34 -07001402 if (sf & SYSC_HAS_MIDLEMODE) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001403 if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
1404 idlemode = HWMOD_IDLEMODE_FORCE;
1405 } else {
1406 if (sf & SYSC_HAS_ENAWAKEUP)
1407 _enable_wakeup(oh, &v);
1408 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1409 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1410 else
1411 idlemode = HWMOD_IDLEMODE_SMART;
1412 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001413 _set_master_standbymode(oh, idlemode, &v);
1414 }
1415
Benoit Cousson86009eb2010-12-21 21:31:28 -07001416 /* If slave is in SMARTIDLE, also enable wakeup */
1417 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
1418 _enable_wakeup(oh, &v);
1419
Paul Walmsley63c85232009-09-03 20:14:03 +03001420 _write_sysconfig(v, oh);
1421}
1422
1423/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001424 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001425 * @oh: struct omap_hwmod *
1426 *
1427 * Force the module into slave idle and master suspend. No return
1428 * value.
1429 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001430static void _shutdown_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001431{
1432 u32 v;
Paul Walmsley43b40992010-02-22 22:09:34 -07001433 u8 sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001434
Paul Walmsley43b40992010-02-22 22:09:34 -07001435 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001436 return;
1437
1438 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001439 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001440
Paul Walmsley43b40992010-02-22 22:09:34 -07001441 if (sf & SYSC_HAS_SIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001442 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
1443
Paul Walmsley43b40992010-02-22 22:09:34 -07001444 if (sf & SYSC_HAS_MIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001445 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
1446
Paul Walmsley43b40992010-02-22 22:09:34 -07001447 if (sf & SYSC_HAS_AUTOIDLE)
Paul Walmsley726072e2009-12-08 16:34:15 -07001448 _set_module_autoidle(oh, 1, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001449
1450 _write_sysconfig(v, oh);
1451}
1452
1453/**
1454 * _lookup - find an omap_hwmod by name
1455 * @name: find an omap_hwmod by name
1456 *
1457 * Return a pointer to an omap_hwmod by name, or NULL if not found.
Paul Walmsley63c85232009-09-03 20:14:03 +03001458 */
1459static struct omap_hwmod *_lookup(const char *name)
1460{
1461 struct omap_hwmod *oh, *temp_oh;
1462
1463 oh = NULL;
1464
1465 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1466 if (!strcmp(name, temp_oh->name)) {
1467 oh = temp_oh;
1468 break;
1469 }
1470 }
1471
1472 return oh;
1473}
Paul Walmsley868c1572012-06-19 15:01:02 -06001474
Benoit Cousson6ae76992011-07-10 05:56:30 -06001475/**
1476 * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
1477 * @oh: struct omap_hwmod *
1478 *
1479 * Convert a clockdomain name stored in a struct omap_hwmod into a
1480 * clockdomain pointer, and save it into the struct omap_hwmod.
Paul Walmsley868c1572012-06-19 15:01:02 -06001481 * Return -EINVAL if the clkdm_name lookup failed.
Benoit Cousson6ae76992011-07-10 05:56:30 -06001482 */
1483static int _init_clkdm(struct omap_hwmod *oh)
1484{
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001485 if (!oh->clkdm_name) {
1486 pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
Benoit Cousson6ae76992011-07-10 05:56:30 -06001487 return 0;
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001488 }
Benoit Cousson6ae76992011-07-10 05:56:30 -06001489
Benoit Cousson6ae76992011-07-10 05:56:30 -06001490 oh->clkdm = clkdm_lookup(oh->clkdm_name);
1491 if (!oh->clkdm) {
1492 pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
1493 oh->name, oh->clkdm_name);
1494 return -EINVAL;
1495 }
1496
1497 pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
1498 oh->name, oh->clkdm_name);
1499
1500 return 0;
1501}
Paul Walmsley63c85232009-09-03 20:14:03 +03001502
1503/**
Benoit Cousson6ae76992011-07-10 05:56:30 -06001504 * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
1505 * well the clockdomain.
Paul Walmsley63c85232009-09-03 20:14:03 +03001506 * @oh: struct omap_hwmod *
Paul Walmsley97d601622010-07-26 16:34:30 -06001507 * @data: not used; pass NULL
Paul Walmsley63c85232009-09-03 20:14:03 +03001508 *
Paul Walmsleya2debdb2011-02-23 00:14:07 -07001509 * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
Paul Walmsley48d54f32011-02-23 00:14:07 -07001510 * Resolves all clock names embedded in the hwmod. Returns 0 on
1511 * success, or a negative error code on failure.
Paul Walmsley63c85232009-09-03 20:14:03 +03001512 */
Paul Walmsley97d601622010-07-26 16:34:30 -06001513static int _init_clocks(struct omap_hwmod *oh, void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03001514{
1515 int ret = 0;
1516
Paul Walmsley48d54f32011-02-23 00:14:07 -07001517 if (oh->_state != _HWMOD_STATE_REGISTERED)
1518 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001519
1520 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
1521
Vaibhav Hiremathb797be1d2012-07-09 18:24:30 +05301522 if (soc_ops.init_clkdm)
1523 ret |= soc_ops.init_clkdm(oh);
1524
Paul Walmsley63c85232009-09-03 20:14:03 +03001525 ret |= _init_main_clk(oh);
1526 ret |= _init_interface_clks(oh);
1527 ret |= _init_opt_clks(oh);
1528
Benoit Coussonf5c1f842010-05-20 12:31:10 -06001529 if (!ret)
1530 oh->_state = _HWMOD_STATE_CLKS_INITED;
Benoit Cousson66522712011-07-01 22:54:06 +02001531 else
1532 pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001533
Rajendra Nayak09c35f22011-02-16 12:11:24 +00001534 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001535}
1536
1537/**
omar ramirezcc1226e2011-03-04 13:32:44 -07001538 * _lookup_hardreset - fill register bit info for this hwmod/reset line
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001539 * @oh: struct omap_hwmod *
1540 * @name: name of the reset line in the context of this hwmod
omar ramirezcc1226e2011-03-04 13:32:44 -07001541 * @ohri: struct omap_hwmod_rst_info * that this function will fill in
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001542 *
1543 * Return the bit position of the reset line that match the
1544 * input name. Return -ENOENT if not found.
1545 */
Paul Walmsleya032d332012-08-03 09:21:10 -06001546static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
1547 struct omap_hwmod_rst_info *ohri)
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001548{
1549 int i;
1550
1551 for (i = 0; i < oh->rst_lines_cnt; i++) {
1552 const char *rst_line = oh->rst_lines[i].name;
1553 if (!strcmp(rst_line, name)) {
omar ramirezcc1226e2011-03-04 13:32:44 -07001554 ohri->rst_shift = oh->rst_lines[i].rst_shift;
1555 ohri->st_shift = oh->rst_lines[i].st_shift;
1556 pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
1557 oh->name, __func__, rst_line, ohri->rst_shift,
1558 ohri->st_shift);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001559
omar ramirezcc1226e2011-03-04 13:32:44 -07001560 return 0;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001561 }
1562 }
1563
1564 return -ENOENT;
1565}
1566
1567/**
1568 * _assert_hardreset - assert the HW reset line of submodules
1569 * contained in the hwmod module.
1570 * @oh: struct omap_hwmod *
1571 * @name: name of the reset line to lookup and assert
1572 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001573 * Some IP like dsp, ipu or iva contain processor that require an HW
1574 * reset line to be assert / deassert in order to enable fully the IP.
1575 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1576 * asserting the hardreset line on the currently-booted SoC, or passes
1577 * along the return value from _lookup_hardreset() or the SoC's
1578 * assert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001579 */
1580static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1581{
omar ramirezcc1226e2011-03-04 13:32:44 -07001582 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001583 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001584
1585 if (!oh)
1586 return -EINVAL;
1587
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001588 if (!soc_ops.assert_hardreset)
1589 return -ENOSYS;
1590
omar ramirezcc1226e2011-03-04 13:32:44 -07001591 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001592 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001593 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001594
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001595 ret = soc_ops.assert_hardreset(oh, &ohri);
1596
1597 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001598}
1599
1600/**
1601 * _deassert_hardreset - deassert the HW reset line of submodules contained
1602 * in the hwmod module.
1603 * @oh: struct omap_hwmod *
1604 * @name: name of the reset line to look up and deassert
1605 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001606 * Some IP like dsp, ipu or iva contain processor that require an HW
1607 * reset line to be assert / deassert in order to enable fully the IP.
1608 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1609 * deasserting the hardreset line on the currently-booted SoC, or passes
1610 * along the return value from _lookup_hardreset() or the SoC's
1611 * deassert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001612 */
1613static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1614{
omar ramirezcc1226e2011-03-04 13:32:44 -07001615 struct omap_hwmod_rst_info ohri;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001616 int ret = -EINVAL;
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001617 int hwsup = 0;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001618
1619 if (!oh)
1620 return -EINVAL;
1621
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001622 if (!soc_ops.deassert_hardreset)
1623 return -ENOSYS;
1624
omar ramirezcc1226e2011-03-04 13:32:44 -07001625 ret = _lookup_hardreset(oh, name, &ohri);
1626 if (IS_ERR_VALUE(ret))
1627 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001628
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001629 if (oh->clkdm) {
1630 /*
1631 * A clockdomain must be in SW_SUP otherwise reset
1632 * might not be completed. The clockdomain can be set
1633 * in HW_AUTO only when the module become ready.
1634 */
1635 hwsup = clkdm_in_hwsup(oh->clkdm);
1636 ret = clkdm_hwmod_enable(oh->clkdm, oh);
1637 if (ret) {
1638 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1639 oh->name, oh->clkdm->name, ret);
1640 return ret;
1641 }
1642 }
1643
1644 _enable_clocks(oh);
1645 if (soc_ops.enable_module)
1646 soc_ops.enable_module(oh);
1647
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001648 ret = soc_ops.deassert_hardreset(oh, &ohri);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001649
1650 if (soc_ops.disable_module)
1651 soc_ops.disable_module(oh);
1652 _disable_clocks(oh);
1653
omar ramirezcc1226e2011-03-04 13:32:44 -07001654 if (ret == -EBUSY)
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001655 pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
1656
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001657 if (!ret) {
1658 /*
1659 * Set the clockdomain to HW_AUTO, assuming that the
1660 * previous state was HW_AUTO.
1661 */
1662 if (oh->clkdm && hwsup)
1663 clkdm_allow_idle(oh->clkdm);
1664 } else {
1665 if (oh->clkdm)
1666 clkdm_hwmod_disable(oh->clkdm, oh);
1667 }
1668
omar ramirezcc1226e2011-03-04 13:32:44 -07001669 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001670}
1671
1672/**
1673 * _read_hardreset - read the HW reset line state of submodules
1674 * contained in the hwmod module
1675 * @oh: struct omap_hwmod *
1676 * @name: name of the reset line to look up and read
1677 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001678 * Return the state of the reset line. Returns -EINVAL if @oh is
1679 * null, -ENOSYS if we have no way of reading the hardreset line
1680 * status on the currently-booted SoC, or passes along the return
1681 * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
1682 * code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001683 */
1684static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1685{
omar ramirezcc1226e2011-03-04 13:32:44 -07001686 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001687 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001688
1689 if (!oh)
1690 return -EINVAL;
1691
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001692 if (!soc_ops.is_hardreset_asserted)
1693 return -ENOSYS;
1694
omar ramirezcc1226e2011-03-04 13:32:44 -07001695 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001696 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001697 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001698
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001699 return soc_ops.is_hardreset_asserted(oh, &ohri);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001700}
1701
1702/**
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001703 * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
Paul Walmsley747834a2012-04-18 19:10:04 -06001704 * @oh: struct omap_hwmod *
1705 *
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001706 * If all hardreset lines associated with @oh are asserted, then return true.
1707 * Otherwise, if part of @oh is out hardreset or if no hardreset lines
1708 * associated with @oh are asserted, then return false.
Paul Walmsley747834a2012-04-18 19:10:04 -06001709 * This function is used to avoid executing some parts of the IP block
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001710 * enable/disable sequence if its hardreset line is set.
Paul Walmsley747834a2012-04-18 19:10:04 -06001711 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001712static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
Paul Walmsley747834a2012-04-18 19:10:04 -06001713{
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001714 int i, rst_cnt = 0;
Paul Walmsley747834a2012-04-18 19:10:04 -06001715
1716 if (oh->rst_lines_cnt == 0)
1717 return false;
1718
1719 for (i = 0; i < oh->rst_lines_cnt; i++)
1720 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001721 rst_cnt++;
1722
1723 if (oh->rst_lines_cnt == rst_cnt)
1724 return true;
Paul Walmsley747834a2012-04-18 19:10:04 -06001725
1726 return false;
1727}
1728
1729/**
Paul Walmsleye9332b62012-10-08 23:08:15 -06001730 * _are_any_hardreset_lines_asserted - return true if any part of @oh is
1731 * hard-reset
1732 * @oh: struct omap_hwmod *
1733 *
1734 * If any hardreset lines associated with @oh are asserted, then
1735 * return true. Otherwise, if no hardreset lines associated with @oh
1736 * are asserted, or if @oh has no hardreset lines, then return false.
1737 * This function is used to avoid executing some parts of the IP block
1738 * enable/disable sequence if any hardreset line is set.
1739 */
1740static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
1741{
1742 int rst_cnt = 0;
1743 int i;
1744
1745 for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
1746 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1747 rst_cnt++;
1748
1749 return (rst_cnt) ? true : false;
1750}
1751
1752/**
Paul Walmsley747834a2012-04-18 19:10:04 -06001753 * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
1754 * @oh: struct omap_hwmod *
1755 *
1756 * Disable the PRCM module mode related to the hwmod @oh.
1757 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1758 */
1759static int _omap4_disable_module(struct omap_hwmod *oh)
1760{
1761 int v;
1762
Paul Walmsley747834a2012-04-18 19:10:04 -06001763 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1764 return -EINVAL;
1765
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001766 /*
1767 * Since integration code might still be doing something, only
1768 * disable if all lines are under hardreset.
1769 */
Paul Walmsleye9332b62012-10-08 23:08:15 -06001770 if (_are_any_hardreset_lines_asserted(oh))
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001771 return 0;
1772
Paul Walmsley747834a2012-04-18 19:10:04 -06001773 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1774
1775 omap4_cminst_module_disable(oh->clkdm->prcm_partition,
1776 oh->clkdm->cm_inst,
1777 oh->clkdm->clkdm_offs,
1778 oh->prcm.omap4.clkctrl_offs);
1779
Paul Walmsley747834a2012-04-18 19:10:04 -06001780 v = _omap4_wait_target_disable(oh);
1781 if (v)
1782 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1783 oh->name);
1784
1785 return 0;
1786}
1787
1788/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001789 * _am33xx_disable_module - enable CLKCTRL modulemode on AM33XX
1790 * @oh: struct omap_hwmod *
1791 *
1792 * Disable the PRCM module mode related to the hwmod @oh.
1793 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1794 */
1795static int _am33xx_disable_module(struct omap_hwmod *oh)
1796{
1797 int v;
1798
1799 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1800 return -EINVAL;
1801
1802 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1803
Paul Walmsleye9332b62012-10-08 23:08:15 -06001804 if (_are_any_hardreset_lines_asserted(oh))
1805 return 0;
1806
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001807 am33xx_cm_module_disable(oh->clkdm->cm_inst, oh->clkdm->clkdm_offs,
1808 oh->prcm.omap4.clkctrl_offs);
1809
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001810 v = _am33xx_wait_target_disable(oh);
1811 if (v)
1812 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1813 oh->name);
1814
1815 return 0;
1816}
1817
1818/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001819 * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
Paul Walmsley63c85232009-09-03 20:14:03 +03001820 * @oh: struct omap_hwmod *
1821 *
1822 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
Paul Walmsley30e105c2012-04-19 00:49:09 -06001823 * enabled for this to work. Returns -ENOENT if the hwmod cannot be
1824 * reset this way, -EINVAL if the hwmod is in the wrong state,
1825 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Benoit Cousson2cb06812010-09-21 18:57:59 +02001826 *
1827 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
Paul Walmsleybd361792010-12-14 12:42:35 -07001828 * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
Benoit Cousson2cb06812010-09-21 18:57:59 +02001829 * use the SYSCONFIG softreset bit to provide the status.
1830 *
Paul Walmsleybd361792010-12-14 12:42:35 -07001831 * Note that some IP like McBSP do have reset control but don't have
1832 * reset status.
Paul Walmsley63c85232009-09-03 20:14:03 +03001833 */
Paul Walmsleybd361792010-12-14 12:42:35 -07001834static int _ocp_softreset(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001835{
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001836 u32 v, softrst_mask;
Paul Walmsley6f8b7ff2009-12-08 16:33:16 -07001837 int c = 0;
Benoit Cousson96835af2010-09-21 18:57:58 +02001838 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001839
Paul Walmsley43b40992010-02-22 22:09:34 -07001840 if (!oh->class->sysc ||
Benoit Cousson2cb06812010-09-21 18:57:59 +02001841 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley30e105c2012-04-19 00:49:09 -06001842 return -ENOENT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001843
1844 /* clocks must be on for this operation */
1845 if (oh->_state != _HWMOD_STATE_ENABLED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001846 pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
1847 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001848 return -EINVAL;
1849 }
1850
Benoit Cousson96835af2010-09-21 18:57:58 +02001851 /* For some modules, all optionnal clocks need to be enabled as well */
1852 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1853 _enable_optional_clocks(oh);
1854
Paul Walmsleybd361792010-12-14 12:42:35 -07001855 pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001856
1857 v = oh->_sysc_cache;
Benoit Cousson96835af2010-09-21 18:57:58 +02001858 ret = _set_softreset(oh, &v);
1859 if (ret)
1860 goto dis_opt_clks;
Paul Walmsley63c85232009-09-03 20:14:03 +03001861 _write_sysconfig(v, oh);
1862
Fernando Guzman Lugod99de7f2012-04-13 05:08:03 -06001863 if (oh->class->sysc->srst_udelay)
1864 udelay(oh->class->sysc->srst_udelay);
1865
Benoit Cousson2cb06812010-09-21 18:57:59 +02001866 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07001867 omap_test_timeout((omap_hwmod_read(oh,
Benoit Cousson2cb06812010-09-21 18:57:59 +02001868 oh->class->sysc->syss_offs)
1869 & SYSS_RESETDONE_MASK),
1870 MAX_MODULE_SOFTRESET_WAIT, c);
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001871 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
1872 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07001873 omap_test_timeout(!(omap_hwmod_read(oh,
Benoit Cousson2cb06812010-09-21 18:57:59 +02001874 oh->class->sysc->sysc_offs)
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001875 & softrst_mask),
Benoit Cousson2cb06812010-09-21 18:57:59 +02001876 MAX_MODULE_SOFTRESET_WAIT, c);
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001877 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001878
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001879 if (c == MAX_MODULE_SOFTRESET_WAIT)
Benoit Cousson76e55892010-09-21 10:34:11 -06001880 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1881 oh->name, MAX_MODULE_SOFTRESET_WAIT);
Paul Walmsley63c85232009-09-03 20:14:03 +03001882 else
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001883 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
Paul Walmsley63c85232009-09-03 20:14:03 +03001884
1885 /*
1886 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1887 * _wait_target_ready() or _reset()
1888 */
1889
Benoit Cousson96835af2010-09-21 18:57:58 +02001890 ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1891
1892dis_opt_clks:
1893 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1894 _disable_optional_clocks(oh);
1895
1896 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001897}
1898
1899/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001900 * _reset - reset an omap_hwmod
1901 * @oh: struct omap_hwmod *
1902 *
Paul Walmsley30e105c2012-04-19 00:49:09 -06001903 * Resets an omap_hwmod @oh. If the module has a custom reset
1904 * function pointer defined, then call it to reset the IP block, and
1905 * pass along its return value to the caller. Otherwise, if the IP
1906 * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
1907 * associated with it, call a function to reset the IP block via that
1908 * method, and pass along the return value to the caller. Finally, if
1909 * the IP block has some hardreset lines associated with it, assert
1910 * all of those, but do _not_ deassert them. (This is because driver
1911 * authors have expressed an apparent requirement to control the
1912 * deassertion of the hardreset lines themselves.)
1913 *
1914 * The default software reset mechanism for most OMAP IP blocks is
1915 * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
1916 * hwmods cannot be reset via this method. Some are not targets and
1917 * therefore have no OCP header registers to access. Others (like the
1918 * IVA) have idiosyncratic reset sequences. So for these relatively
1919 * rare cases, custom reset code can be supplied in the struct
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001920 * omap_hwmod_class .reset function pointer.
1921 *
1922 * _set_dmadisable() is called to set the DMADISABLE bit so that it
1923 * does not prevent idling of the system. This is necessary for cases
1924 * where ROMCODE/BOOTLOADER uses dma and transfers control to the
1925 * kernel without disabling dma.
1926 *
1927 * Passes along the return value from either _ocp_softreset() or the
1928 * custom reset function - these must return -EINVAL if the hwmod
1929 * cannot be reset this way or if the hwmod is in the wrong state,
1930 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Paul Walmsleybd361792010-12-14 12:42:35 -07001931 */
1932static int _reset(struct omap_hwmod *oh)
1933{
Paul Walmsley30e105c2012-04-19 00:49:09 -06001934 int i, r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001935
1936 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1937
Paul Walmsley30e105c2012-04-19 00:49:09 -06001938 if (oh->class->reset) {
1939 r = oh->class->reset(oh);
1940 } else {
1941 if (oh->rst_lines_cnt > 0) {
1942 for (i = 0; i < oh->rst_lines_cnt; i++)
1943 _assert_hardreset(oh, oh->rst_lines[i].name);
1944 return 0;
1945 } else {
1946 r = _ocp_softreset(oh);
1947 if (r == -ENOENT)
1948 r = 0;
1949 }
1950 }
Paul Walmsleybd361792010-12-14 12:42:35 -07001951
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001952 _set_dmadisable(oh);
1953
Paul Walmsley30e105c2012-04-19 00:49:09 -06001954 /*
1955 * OCP_SYSCONFIG bits need to be reprogrammed after a
1956 * softreset. The _enable() function should be split to avoid
1957 * the rewrite of the OCP_SYSCONFIG register.
1958 */
Rajendra Nayak28008522012-03-13 22:55:23 +05301959 if (oh->class->sysc) {
1960 _update_sysc_cache(oh);
1961 _enable_sysc(oh);
1962 }
1963
Paul Walmsley30e105c2012-04-19 00:49:09 -06001964 return r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001965}
1966
1967/**
Vishwanath BS51658822012-06-22 08:40:04 -06001968 * _reconfigure_io_chain - clear any I/O chain wakeups and reconfigure chain
1969 *
1970 * Call the appropriate PRM function to clear any logged I/O chain
1971 * wakeups and to reconfigure the chain. This apparently needs to be
1972 * done upon every mux change. Since hwmods can be concurrently
1973 * enabled and idled, hold a spinlock around the I/O chain
1974 * reconfiguration sequence. No return value.
1975 *
1976 * XXX When the PRM code is moved to drivers, this function can be removed,
1977 * as the PRM infrastructure should abstract this.
1978 */
1979static void _reconfigure_io_chain(void)
1980{
1981 unsigned long flags;
1982
1983 spin_lock_irqsave(&io_chain_lock, flags);
1984
1985 if (cpu_is_omap34xx() && omap3_has_io_chain_ctrl())
1986 omap3xxx_prm_reconfigure_io_chain();
1987 else if (cpu_is_omap44xx())
1988 omap44xx_prm_reconfigure_io_chain();
1989
1990 spin_unlock_irqrestore(&io_chain_lock, flags);
1991}
1992
1993/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001994 * _enable - enable an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001995 * @oh: struct omap_hwmod *
1996 *
1997 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001998 * register target. Returns -EINVAL if the hwmod is in the wrong
1999 * state or passes along the return value of _wait_target_ready().
Paul Walmsley63c85232009-09-03 20:14:03 +03002000 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002001static int _enable(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002002{
Paul Walmsley747834a2012-04-18 19:10:04 -06002003 int r;
Rajendra Nayak665d0012011-07-10 05:57:07 -06002004 int hwsup = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03002005
Benoit Cousson34617e22011-07-01 22:54:07 +02002006 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
2007
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002008 /*
Paul Walmsley64813c32012-04-18 19:10:03 -06002009 * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
2010 * state at init. Now that someone is really trying to enable
2011 * them, just ensure that the hwmod mux is set.
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002012 */
2013 if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
2014 /*
2015 * If the caller has mux data populated, do the mux'ing
2016 * which wouldn't have been done as part of the _enable()
2017 * done during setup.
2018 */
2019 if (oh->mux)
2020 omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
2021
2022 oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
2023 return 0;
2024 }
2025
Paul Walmsley63c85232009-09-03 20:14:03 +03002026 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
2027 oh->_state != _HWMOD_STATE_IDLE &&
2028 oh->_state != _HWMOD_STATE_DISABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002029 WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
2030 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002031 return -EINVAL;
2032 }
2033
Benoit Cousson31f62862011-07-01 22:54:05 +02002034 /*
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002035 * If an IP block contains HW reset lines and all of them are
Paul Walmsley747834a2012-04-18 19:10:04 -06002036 * asserted, we let integration code associated with that
2037 * block handle the enable. We've received very little
2038 * information on what those driver authors need, and until
2039 * detailed information is provided and the driver code is
2040 * posted to the public lists, this is probably the best we
2041 * can do.
Benoit Cousson31f62862011-07-01 22:54:05 +02002042 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002043 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002044 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03002045
Rajendra Nayak665d0012011-07-10 05:57:07 -06002046 /* Mux pins for device runtime if populated */
2047 if (oh->mux && (!oh->mux->enabled ||
2048 ((oh->_state == _HWMOD_STATE_IDLE) &&
Vishwanath BS51658822012-06-22 08:40:04 -06002049 oh->mux->pads_dynamic))) {
Rajendra Nayak665d0012011-07-10 05:57:07 -06002050 omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
Vishwanath BS51658822012-06-22 08:40:04 -06002051 _reconfigure_io_chain();
2052 }
Benoit Cousson34617e22011-07-01 22:54:07 +02002053
Rajendra Nayak665d0012011-07-10 05:57:07 -06002054 _add_initiator_dep(oh, mpu_oh);
2055
2056 if (oh->clkdm) {
2057 /*
2058 * A clockdomain must be in SW_SUP before enabling
2059 * completely the module. The clockdomain can be set
2060 * in HW_AUTO only when the module become ready.
2061 */
Paul Walmsleyb71c7212012-09-23 17:28:28 -06002062 hwsup = clkdm_in_hwsup(oh->clkdm) &&
2063 !clkdm_missing_idle_reporting(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002064 r = clkdm_hwmod_enable(oh->clkdm, oh);
2065 if (r) {
2066 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
2067 oh->name, oh->clkdm->name, r);
2068 return r;
2069 }
Benoit Cousson34617e22011-07-01 22:54:07 +02002070 }
Rajendra Nayak665d0012011-07-10 05:57:07 -06002071
2072 _enable_clocks(oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002073 if (soc_ops.enable_module)
2074 soc_ops.enable_module(oh);
Benoit Cousson34617e22011-07-01 22:54:07 +02002075
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002076 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
2077 -EINVAL;
Rajendra Nayak665d0012011-07-10 05:57:07 -06002078 if (!r) {
2079 /*
2080 * Set the clockdomain to HW_AUTO only if the target is ready,
2081 * assuming that the previous state was HW_AUTO
2082 */
2083 if (oh->clkdm && hwsup)
2084 clkdm_allow_idle(oh->clkdm);
Benoit Cousson34617e22011-07-01 22:54:07 +02002085
Rajendra Nayak665d0012011-07-10 05:57:07 -06002086 oh->_state = _HWMOD_STATE_ENABLED;
2087
2088 /* Access the sysconfig only if the target is ready */
2089 if (oh->class->sysc) {
2090 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
2091 _update_sysc_cache(oh);
2092 _enable_sysc(oh);
2093 }
2094 } else {
Paul Walmsley2577a4a2012-10-29 20:57:55 -06002095 if (soc_ops.disable_module)
2096 soc_ops.disable_module(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002097 _disable_clocks(oh);
2098 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
2099 oh->name, r);
2100
2101 if (oh->clkdm)
2102 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002103 }
2104
Paul Walmsley63c85232009-09-03 20:14:03 +03002105 return r;
2106}
2107
2108/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002109 * _idle - idle an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03002110 * @oh: struct omap_hwmod *
2111 *
2112 * Idles an omap_hwmod @oh. This should be called once the hwmod has
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002113 * no further work. Returns -EINVAL if the hwmod is in the wrong
2114 * state or returns 0.
Paul Walmsley63c85232009-09-03 20:14:03 +03002115 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002116static int _idle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002117{
Benoit Cousson34617e22011-07-01 22:54:07 +02002118 pr_debug("omap_hwmod: %s: idling\n", oh->name);
2119
Paul Walmsley63c85232009-09-03 20:14:03 +03002120 if (oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002121 WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
2122 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002123 return -EINVAL;
2124 }
2125
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002126 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002127 return 0;
2128
Paul Walmsley43b40992010-02-22 22:09:34 -07002129 if (oh->class->sysc)
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002130 _idle_sysc(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002131 _del_initiator_dep(oh, mpu_oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002132
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002133 if (soc_ops.disable_module)
2134 soc_ops.disable_module(oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002135
Benoit Cousson45c38252011-07-10 05:56:33 -06002136 /*
2137 * The module must be in idle mode before disabling any parents
2138 * clocks. Otherwise, the parent clock might be disabled before
2139 * the module transition is done, and thus will prevent the
2140 * transition to complete properly.
2141 */
2142 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002143 if (oh->clkdm)
2144 clkdm_hwmod_disable(oh->clkdm, oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002145
Tony Lindgren8d9af882010-12-22 18:42:35 -08002146 /* Mux pins for device idle if populated */
Vishwanath BS51658822012-06-22 08:40:04 -06002147 if (oh->mux && oh->mux->pads_dynamic) {
Tony Lindgren8d9af882010-12-22 18:42:35 -08002148 omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
Vishwanath BS51658822012-06-22 08:40:04 -06002149 _reconfigure_io_chain();
2150 }
Tony Lindgren8d9af882010-12-22 18:42:35 -08002151
Paul Walmsley63c85232009-09-03 20:14:03 +03002152 oh->_state = _HWMOD_STATE_IDLE;
2153
2154 return 0;
2155}
2156
2157/**
Kishon Vijay Abraham I95992172011-03-10 03:50:08 -07002158 * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
2159 * @oh: struct omap_hwmod *
2160 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
2161 *
2162 * Sets the IP block's OCP autoidle bit in hardware, and updates our
2163 * local copy. Intended to be used by drivers that require
2164 * direct manipulation of the AUTOIDLE bits.
2165 * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
2166 * along the return value from _set_module_autoidle().
2167 *
2168 * Any users of this function should be scrutinized carefully.
2169 */
2170int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
2171{
2172 u32 v;
2173 int retval = 0;
2174 unsigned long flags;
2175
2176 if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
2177 return -EINVAL;
2178
2179 spin_lock_irqsave(&oh->_lock, flags);
2180
2181 v = oh->_sysc_cache;
2182
2183 retval = _set_module_autoidle(oh, autoidle, &v);
2184
2185 if (!retval)
2186 _write_sysconfig(v, oh);
2187
2188 spin_unlock_irqrestore(&oh->_lock, flags);
2189
2190 return retval;
2191}
2192
2193/**
Paul Walmsley63c85232009-09-03 20:14:03 +03002194 * _shutdown - shutdown an omap_hwmod
2195 * @oh: struct omap_hwmod *
2196 *
2197 * Shut down an omap_hwmod @oh. This should be called when the driver
2198 * used for the hwmod is removed or unloaded or if the driver is not
2199 * used by the system. Returns -EINVAL if the hwmod is in the wrong
2200 * state or returns 0.
2201 */
2202static int _shutdown(struct omap_hwmod *oh)
2203{
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002204 int ret, i;
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002205 u8 prev_state;
2206
Paul Walmsley63c85232009-09-03 20:14:03 +03002207 if (oh->_state != _HWMOD_STATE_IDLE &&
2208 oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002209 WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
2210 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002211 return -EINVAL;
2212 }
2213
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002214 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002215 return 0;
2216
Paul Walmsley63c85232009-09-03 20:14:03 +03002217 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
2218
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002219 if (oh->class->pre_shutdown) {
2220 prev_state = oh->_state;
2221 if (oh->_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002222 _enable(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002223 ret = oh->class->pre_shutdown(oh);
2224 if (ret) {
2225 if (prev_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002226 _idle(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002227 return ret;
2228 }
2229 }
2230
Miguel Vadillo6481c732011-07-01 22:54:02 +02002231 if (oh->class->sysc) {
2232 if (oh->_state == _HWMOD_STATE_IDLE)
2233 _enable(oh);
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002234 _shutdown_sysc(oh);
Miguel Vadillo6481c732011-07-01 22:54:02 +02002235 }
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06002236
Benoit Cousson3827f942010-09-21 10:34:08 -06002237 /* clocks and deps are already disabled in idle */
2238 if (oh->_state == _HWMOD_STATE_ENABLED) {
2239 _del_initiator_dep(oh, mpu_oh);
2240 /* XXX what about the other system initiators here? dma, dsp */
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002241 if (soc_ops.disable_module)
2242 soc_ops.disable_module(oh);
Benoit Cousson45c38252011-07-10 05:56:33 -06002243 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002244 if (oh->clkdm)
2245 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson3827f942010-09-21 10:34:08 -06002246 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002247 /* XXX Should this code also force-disable the optional clocks? */
2248
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002249 for (i = 0; i < oh->rst_lines_cnt; i++)
2250 _assert_hardreset(oh, oh->rst_lines[i].name);
Benoit Cousson31f62862011-07-01 22:54:05 +02002251
Tony Lindgren8d9af882010-12-22 18:42:35 -08002252 /* Mux pins to safe mode or use populated off mode values */
2253 if (oh->mux)
2254 omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
Paul Walmsley63c85232009-09-03 20:14:03 +03002255
2256 oh->_state = _HWMOD_STATE_DISABLED;
2257
2258 return 0;
2259}
2260
2261/**
Paul Walmsley381d0332012-04-19 00:58:22 -06002262 * _init_mpu_rt_base - populate the virtual address for a hwmod
2263 * @oh: struct omap_hwmod * to locate the virtual address
2264 *
2265 * Cache the virtual address used by the MPU to access this IP block's
2266 * registers. This address is needed early so the OCP registers that
2267 * are part of the device's address space can be ioremapped properly.
2268 * No return value.
2269 */
2270static void __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data)
2271{
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002272 struct omap_hwmod_addr_space *mem;
2273 void __iomem *va_start;
2274
2275 if (!oh)
2276 return;
2277
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002278 _save_mpu_port_index(oh);
2279
Paul Walmsley381d0332012-04-19 00:58:22 -06002280 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
2281 return;
2282
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002283 mem = _find_mpu_rt_addr_space(oh);
2284 if (!mem) {
2285 pr_debug("omap_hwmod: %s: no MPU register target found\n",
2286 oh->name);
2287 return;
2288 }
2289
2290 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
2291 if (!va_start) {
2292 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
2293 return;
2294 }
2295
2296 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
2297 oh->name, va_start);
2298
2299 oh->_mpu_rt_va = va_start;
Paul Walmsley381d0332012-04-19 00:58:22 -06002300}
2301
2302/**
2303 * _init - initialize internal data for the hwmod @oh
2304 * @oh: struct omap_hwmod *
2305 * @n: (unused)
2306 *
2307 * Look up the clocks and the address space used by the MPU to access
2308 * registers belonging to the hwmod @oh. @oh must already be
2309 * registered at this point. This is the first of two phases for
2310 * hwmod initialization. Code called here does not touch any hardware
2311 * registers, it simply prepares internal data structures. Returns 0
2312 * upon success or if the hwmod isn't registered, or -EINVAL upon
2313 * failure.
2314 */
2315static int __init _init(struct omap_hwmod *oh, void *data)
2316{
2317 int r;
2318
2319 if (oh->_state != _HWMOD_STATE_REGISTERED)
2320 return 0;
2321
2322 _init_mpu_rt_base(oh, NULL);
2323
2324 r = _init_clocks(oh, NULL);
2325 if (IS_ERR_VALUE(r)) {
2326 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2327 return -EINVAL;
2328 }
2329
2330 oh->_state = _HWMOD_STATE_INITIALIZED;
2331
2332 return 0;
2333}
2334
2335/**
Paul Walmsley64813c32012-04-18 19:10:03 -06002336 * _setup_iclk_autoidle - configure an IP block's interface clocks
Paul Walmsley63c85232009-09-03 20:14:03 +03002337 * @oh: struct omap_hwmod *
2338 *
Paul Walmsley64813c32012-04-18 19:10:03 -06002339 * Set up the module's interface clocks. XXX This function is still mostly
2340 * a stub; implementing this properly requires iclk autoidle usecounting in
2341 * the clock code. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03002342 */
Paul Walmsley64813c32012-04-18 19:10:03 -06002343static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002344{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002345 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002346 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002347 int i = 0;
Paul Walmsley381d0332012-04-19 00:58:22 -06002348 if (oh->_state != _HWMOD_STATE_INITIALIZED)
Paul Walmsley64813c32012-04-18 19:10:03 -06002349 return;
Paul Walmsley48d54f32011-02-23 00:14:07 -07002350
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002351 p = oh->slave_ports.next;
Paul Walmsley63c85232009-09-03 20:14:03 +03002352
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002353 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002354 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002355 if (!os->_clk)
Paul Walmsley64813c32012-04-18 19:10:03 -06002356 continue;
Paul Walmsley63c85232009-09-03 20:14:03 +03002357
Paul Walmsley64813c32012-04-18 19:10:03 -06002358 if (os->flags & OCPIF_SWSUP_IDLE) {
2359 /* XXX omap_iclk_deny_idle(c); */
2360 } else {
2361 /* XXX omap_iclk_allow_idle(c); */
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002362 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +03002363 }
2364 }
2365
Paul Walmsley64813c32012-04-18 19:10:03 -06002366 return;
2367}
2368
2369/**
2370 * _setup_reset - reset an IP block during the setup process
2371 * @oh: struct omap_hwmod *
2372 *
2373 * Reset the IP block corresponding to the hwmod @oh during the setup
2374 * process. The IP block is first enabled so it can be successfully
2375 * reset. Returns 0 upon success or a negative error code upon
2376 * failure.
2377 */
2378static int __init _setup_reset(struct omap_hwmod *oh)
2379{
2380 int r;
2381
2382 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2383 return -EINVAL;
Paul Walmsley63c85232009-09-03 20:14:03 +03002384
Paul Walmsley747834a2012-04-18 19:10:04 -06002385 if (oh->rst_lines_cnt == 0) {
2386 r = _enable(oh);
2387 if (r) {
2388 pr_warning("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2389 oh->name, oh->_state);
2390 return -EINVAL;
2391 }
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002392 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002393
Rajendra Nayak28008522012-03-13 22:55:23 +05302394 if (!(oh->flags & HWMOD_INIT_NO_RESET))
Paul Walmsley64813c32012-04-18 19:10:03 -06002395 r = _reset(oh);
2396
2397 return r;
2398}
2399
2400/**
2401 * _setup_postsetup - transition to the appropriate state after _setup
2402 * @oh: struct omap_hwmod *
2403 *
2404 * Place an IP block represented by @oh into a "post-setup" state --
2405 * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that
2406 * this function is called at the end of _setup().) The postsetup
2407 * state for an IP block can be changed by calling
2408 * omap_hwmod_enter_postsetup_state() early in the boot process,
2409 * before one of the omap_hwmod_setup*() functions are called for the
2410 * IP block.
2411 *
2412 * The IP block stays in this state until a PM runtime-based driver is
2413 * loaded for that IP block. A post-setup state of IDLE is
2414 * appropriate for almost all IP blocks with runtime PM-enabled
2415 * drivers, since those drivers are able to enable the IP block. A
2416 * post-setup state of ENABLED is appropriate for kernels with PM
2417 * runtime disabled. The DISABLED state is appropriate for unusual IP
2418 * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2419 * included, since the WDTIMER starts running on reset and will reset
2420 * the MPU if left active.
2421 *
2422 * This post-setup mechanism is deprecated. Once all of the OMAP
2423 * drivers have been converted to use PM runtime, and all of the IP
2424 * block data and interconnect data is available to the hwmod code, it
2425 * should be possible to replace this mechanism with a "lazy reset"
2426 * arrangement. In a "lazy reset" setup, each IP block is enabled
2427 * when the driver first probes, then all remaining IP blocks without
2428 * drivers are either shut down or enabled after the drivers have
2429 * loaded. However, this cannot take place until the above
2430 * preconditions have been met, since otherwise the late reset code
2431 * has no way of knowing which IP blocks are in use by drivers, and
2432 * which ones are unused.
2433 *
2434 * No return value.
2435 */
2436static void __init _setup_postsetup(struct omap_hwmod *oh)
2437{
2438 u8 postsetup_state;
2439
2440 if (oh->rst_lines_cnt > 0)
2441 return;
Benoit Cousson76e55892010-09-21 10:34:11 -06002442
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002443 postsetup_state = oh->_postsetup_state;
2444 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2445 postsetup_state = _HWMOD_STATE_ENABLED;
2446
2447 /*
2448 * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2449 * it should be set by the core code as a runtime flag during startup
2450 */
2451 if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002452 (postsetup_state == _HWMOD_STATE_IDLE)) {
2453 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002454 postsetup_state = _HWMOD_STATE_ENABLED;
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002455 }
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002456
2457 if (postsetup_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002458 _idle(oh);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002459 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2460 _shutdown(oh);
2461 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2462 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2463 oh->name, postsetup_state);
Paul Walmsley63c85232009-09-03 20:14:03 +03002464
Paul Walmsley64813c32012-04-18 19:10:03 -06002465 return;
2466}
2467
2468/**
2469 * _setup - prepare IP block hardware for use
2470 * @oh: struct omap_hwmod *
2471 * @n: (unused, pass NULL)
2472 *
2473 * Configure the IP block represented by @oh. This may include
2474 * enabling the IP block, resetting it, and placing it into a
2475 * post-setup state, depending on the type of IP block and applicable
2476 * flags. IP blocks are reset to prevent any previous configuration
2477 * by the bootloader or previous operating system from interfering
2478 * with power management or other parts of the system. The reset can
2479 * be avoided; see omap_hwmod_no_setup_reset(). This is the second of
2480 * two phases for hwmod initialization. Code called here generally
2481 * affects the IP block hardware, or system integration hardware
2482 * associated with the IP block. Returns 0.
2483 */
2484static int __init _setup(struct omap_hwmod *oh, void *data)
2485{
2486 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2487 return 0;
2488
2489 _setup_iclk_autoidle(oh);
2490
2491 if (!_setup_reset(oh))
2492 _setup_postsetup(oh);
2493
Paul Walmsley63c85232009-09-03 20:14:03 +03002494 return 0;
2495}
2496
Benoit Cousson0102b622010-12-21 21:31:27 -07002497/**
2498 * _register - register a struct omap_hwmod
2499 * @oh: struct omap_hwmod *
2500 *
2501 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
2502 * already has been registered by the same name; -EINVAL if the
2503 * omap_hwmod is in the wrong state, if @oh is NULL, if the
2504 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2505 * name, or if the omap_hwmod's class is missing a name; or 0 upon
2506 * success.
2507 *
2508 * XXX The data should be copied into bootmem, so the original data
2509 * should be marked __initdata and freed after init. This would allow
2510 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
2511 * that the copy process would be relatively complex due to the large number
2512 * of substructures.
2513 */
Benoit Cousson01592df2010-12-21 21:31:28 -07002514static int __init _register(struct omap_hwmod *oh)
Benoit Cousson0102b622010-12-21 21:31:27 -07002515{
Benoit Cousson0102b622010-12-21 21:31:27 -07002516 if (!oh || !oh->name || !oh->class || !oh->class->name ||
2517 (oh->_state != _HWMOD_STATE_UNKNOWN))
2518 return -EINVAL;
2519
Benoit Cousson0102b622010-12-21 21:31:27 -07002520 pr_debug("omap_hwmod: %s: registering\n", oh->name);
2521
Benoit Coussonce35b242010-12-21 21:31:28 -07002522 if (_lookup(oh->name))
2523 return -EEXIST;
Benoit Cousson0102b622010-12-21 21:31:27 -07002524
Benoit Cousson0102b622010-12-21 21:31:27 -07002525 list_add_tail(&oh->node, &omap_hwmod_list);
2526
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002527 INIT_LIST_HEAD(&oh->master_ports);
2528 INIT_LIST_HEAD(&oh->slave_ports);
Benoit Cousson0102b622010-12-21 21:31:27 -07002529 spin_lock_init(&oh->_lock);
2530
2531 oh->_state = _HWMOD_STATE_REGISTERED;
2532
Paul Walmsley569edd702011-02-23 00:14:06 -07002533 /*
2534 * XXX Rather than doing a strcmp(), this should test a flag
2535 * set in the hwmod data, inserted by the autogenerator code.
2536 */
2537 if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2538 mpu_oh = oh;
Benoit Cousson0102b622010-12-21 21:31:27 -07002539
Paul Walmsley569edd702011-02-23 00:14:06 -07002540 return 0;
Benoit Cousson0102b622010-12-21 21:31:27 -07002541}
Paul Walmsley63c85232009-09-03 20:14:03 +03002542
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002543/**
2544 * _alloc_links - return allocated memory for hwmod links
2545 * @ml: pointer to a struct omap_hwmod_link * for the master link
2546 * @sl: pointer to a struct omap_hwmod_link * for the slave link
2547 *
2548 * Return pointers to two struct omap_hwmod_link records, via the
2549 * addresses pointed to by @ml and @sl. Will first attempt to return
2550 * memory allocated as part of a large initial block, but if that has
2551 * been exhausted, will allocate memory itself. Since ideally this
2552 * second allocation path will never occur, the number of these
2553 * 'supplemental' allocations will be logged when debugging is
2554 * enabled. Returns 0.
2555 */
2556static int __init _alloc_links(struct omap_hwmod_link **ml,
2557 struct omap_hwmod_link **sl)
2558{
2559 unsigned int sz;
2560
2561 if ((free_ls + LINKS_PER_OCP_IF) <= max_ls) {
2562 *ml = &linkspace[free_ls++];
2563 *sl = &linkspace[free_ls++];
2564 return 0;
2565 }
2566
2567 sz = sizeof(struct omap_hwmod_link) * LINKS_PER_OCP_IF;
2568
2569 *sl = NULL;
2570 *ml = alloc_bootmem(sz);
2571
2572 memset(*ml, 0, sz);
2573
2574 *sl = (void *)(*ml) + sizeof(struct omap_hwmod_link);
2575
2576 ls_supp++;
2577 pr_debug("omap_hwmod: supplemental link allocations needed: %d\n",
2578 ls_supp * LINKS_PER_OCP_IF);
2579
2580 return 0;
2581};
2582
2583/**
2584 * _add_link - add an interconnect between two IP blocks
2585 * @oi: pointer to a struct omap_hwmod_ocp_if record
2586 *
2587 * Add struct omap_hwmod_link records connecting the master IP block
2588 * specified in @oi->master to @oi, and connecting the slave IP block
2589 * specified in @oi->slave to @oi. This code is assumed to run before
2590 * preemption or SMP has been enabled, thus avoiding the need for
2591 * locking in this code. Changes to this assumption will require
2592 * additional locking. Returns 0.
2593 */
2594static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2595{
2596 struct omap_hwmod_link *ml, *sl;
2597
2598 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2599 oi->slave->name);
2600
2601 _alloc_links(&ml, &sl);
2602
2603 ml->ocp_if = oi;
2604 INIT_LIST_HEAD(&ml->node);
2605 list_add(&ml->node, &oi->master->master_ports);
2606 oi->master->masters_cnt++;
2607
2608 sl->ocp_if = oi;
2609 INIT_LIST_HEAD(&sl->node);
2610 list_add(&sl->node, &oi->slave->slave_ports);
2611 oi->slave->slaves_cnt++;
2612
2613 return 0;
2614}
2615
2616/**
2617 * _register_link - register a struct omap_hwmod_ocp_if
2618 * @oi: struct omap_hwmod_ocp_if *
2619 *
2620 * Registers the omap_hwmod_ocp_if record @oi. Returns -EEXIST if it
2621 * has already been registered; -EINVAL if @oi is NULL or if the
2622 * record pointed to by @oi is missing required fields; or 0 upon
2623 * success.
2624 *
2625 * XXX The data should be copied into bootmem, so the original data
2626 * should be marked __initdata and freed after init. This would allow
2627 * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2628 */
2629static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2630{
2631 if (!oi || !oi->master || !oi->slave || !oi->user)
2632 return -EINVAL;
2633
2634 if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2635 return -EEXIST;
2636
2637 pr_debug("omap_hwmod: registering link from %s to %s\n",
2638 oi->master->name, oi->slave->name);
2639
2640 /*
2641 * Register the connected hwmods, if they haven't been
2642 * registered already
2643 */
2644 if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2645 _register(oi->master);
2646
2647 if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2648 _register(oi->slave);
2649
2650 _add_link(oi);
2651
2652 oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2653
2654 return 0;
2655}
2656
2657/**
2658 * _alloc_linkspace - allocate large block of hwmod links
2659 * @ois: pointer to an array of struct omap_hwmod_ocp_if records to count
2660 *
2661 * Allocate a large block of struct omap_hwmod_link records. This
2662 * improves boot time significantly by avoiding the need to allocate
2663 * individual records one by one. If the number of records to
2664 * allocate in the block hasn't been manually specified, this function
2665 * will count the number of struct omap_hwmod_ocp_if records in @ois
2666 * and use that to determine the allocation size. For SoC families
2667 * that require multiple list registrations, such as OMAP3xxx, this
2668 * estimation process isn't optimal, so manual estimation is advised
2669 * in those cases. Returns -EEXIST if the allocation has already occurred
2670 * or 0 upon success.
2671 */
2672static int __init _alloc_linkspace(struct omap_hwmod_ocp_if **ois)
2673{
2674 unsigned int i = 0;
2675 unsigned int sz;
2676
2677 if (linkspace) {
2678 WARN(1, "linkspace already allocated\n");
2679 return -EEXIST;
2680 }
2681
2682 if (max_ls == 0)
2683 while (ois[i++])
2684 max_ls += LINKS_PER_OCP_IF;
2685
2686 sz = sizeof(struct omap_hwmod_link) * max_ls;
2687
2688 pr_debug("omap_hwmod: %s: allocating %d byte linkspace (%d links)\n",
2689 __func__, sz, max_ls);
2690
2691 linkspace = alloc_bootmem(sz);
2692
2693 memset(linkspace, 0, sz);
2694
2695 return 0;
2696}
Paul Walmsley63c85232009-09-03 20:14:03 +03002697
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002698/* Static functions intended only for use in soc_ops field function pointers */
2699
2700/**
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002701 * _omap2xxx_wait_target_ready - wait for a module to leave slave idle
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002702 * @oh: struct omap_hwmod *
2703 *
2704 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2705 * does not have an IDLEST bit or if the module successfully leaves
2706 * slave idle; otherwise, pass along the return value of the
2707 * appropriate *_cm*_wait_module_ready() function.
2708 */
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002709static int _omap2xxx_wait_target_ready(struct omap_hwmod *oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002710{
2711 if (!oh)
2712 return -EINVAL;
2713
2714 if (oh->flags & HWMOD_NO_IDLEST)
2715 return 0;
2716
2717 if (!_find_mpu_rt_port(oh))
2718 return 0;
2719
2720 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2721
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002722 return omap2xxx_cm_wait_module_ready(oh->prcm.omap2.module_offs,
2723 oh->prcm.omap2.idlest_reg_id,
2724 oh->prcm.omap2.idlest_idle_bit);
2725}
2726
2727/**
2728 * _omap3xxx_wait_target_ready - wait for a module to leave slave idle
2729 * @oh: struct omap_hwmod *
2730 *
2731 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2732 * does not have an IDLEST bit or if the module successfully leaves
2733 * slave idle; otherwise, pass along the return value of the
2734 * appropriate *_cm*_wait_module_ready() function.
2735 */
2736static int _omap3xxx_wait_target_ready(struct omap_hwmod *oh)
2737{
2738 if (!oh)
2739 return -EINVAL;
2740
2741 if (oh->flags & HWMOD_NO_IDLEST)
2742 return 0;
2743
2744 if (!_find_mpu_rt_port(oh))
2745 return 0;
2746
2747 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2748
2749 return omap3xxx_cm_wait_module_ready(oh->prcm.omap2.module_offs,
2750 oh->prcm.omap2.idlest_reg_id,
2751 oh->prcm.omap2.idlest_idle_bit);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002752}
2753
2754/**
2755 * _omap4_wait_target_ready - wait for a module to leave slave idle
2756 * @oh: struct omap_hwmod *
2757 *
2758 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2759 * does not have an IDLEST bit or if the module successfully leaves
2760 * slave idle; otherwise, pass along the return value of the
2761 * appropriate *_cm*_wait_module_ready() function.
2762 */
2763static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2764{
Paul Walmsley2b026d12012-09-23 17:28:18 -06002765 if (!oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002766 return -EINVAL;
2767
Paul Walmsley2b026d12012-09-23 17:28:18 -06002768 if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002769 return 0;
2770
2771 if (!_find_mpu_rt_port(oh))
2772 return 0;
2773
2774 /* XXX check module SIDLEMODE, hardreset status */
2775
2776 return omap4_cminst_wait_module_ready(oh->clkdm->prcm_partition,
2777 oh->clkdm->cm_inst,
2778 oh->clkdm->clkdm_offs,
2779 oh->prcm.omap4.clkctrl_offs);
2780}
2781
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002782/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002783 * _am33xx_wait_target_ready - wait for a module to leave slave idle
2784 * @oh: struct omap_hwmod *
2785 *
2786 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2787 * does not have an IDLEST bit or if the module successfully leaves
2788 * slave idle; otherwise, pass along the return value of the
2789 * appropriate *_cm*_wait_module_ready() function.
2790 */
2791static int _am33xx_wait_target_ready(struct omap_hwmod *oh)
2792{
2793 if (!oh || !oh->clkdm)
2794 return -EINVAL;
2795
2796 if (oh->flags & HWMOD_NO_IDLEST)
2797 return 0;
2798
2799 if (!_find_mpu_rt_port(oh))
2800 return 0;
2801
2802 /* XXX check module SIDLEMODE, hardreset status */
2803
2804 return am33xx_cm_wait_module_ready(oh->clkdm->cm_inst,
2805 oh->clkdm->clkdm_offs,
2806 oh->prcm.omap4.clkctrl_offs);
2807}
2808
2809/**
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002810 * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2811 * @oh: struct omap_hwmod * to assert hardreset
2812 * @ohri: hardreset line data
2813 *
2814 * Call omap2_prm_assert_hardreset() with parameters extracted from
2815 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2816 * use as an soc_ops function pointer. Passes along the return value
2817 * from omap2_prm_assert_hardreset(). XXX This function is scheduled
2818 * for removal when the PRM code is moved into drivers/.
2819 */
2820static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2821 struct omap_hwmod_rst_info *ohri)
2822{
2823 return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
2824 ohri->rst_shift);
2825}
2826
2827/**
2828 * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2829 * @oh: struct omap_hwmod * to deassert hardreset
2830 * @ohri: hardreset line data
2831 *
2832 * Call omap2_prm_deassert_hardreset() with parameters extracted from
2833 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2834 * use as an soc_ops function pointer. Passes along the return value
2835 * from omap2_prm_deassert_hardreset(). XXX This function is
2836 * scheduled for removal when the PRM code is moved into drivers/.
2837 */
2838static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2839 struct omap_hwmod_rst_info *ohri)
2840{
2841 return omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
2842 ohri->rst_shift,
2843 ohri->st_shift);
2844}
2845
2846/**
2847 * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2848 * @oh: struct omap_hwmod * to test hardreset
2849 * @ohri: hardreset line data
2850 *
2851 * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2852 * from the hwmod @oh and the hardreset line data @ohri. Only
2853 * intended for use as an soc_ops function pointer. Passes along the
2854 * return value from omap2_prm_is_hardreset_asserted(). XXX This
2855 * function is scheduled for removal when the PRM code is moved into
2856 * drivers/.
2857 */
2858static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2859 struct omap_hwmod_rst_info *ohri)
2860{
2861 return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
2862 ohri->st_shift);
2863}
2864
2865/**
2866 * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2867 * @oh: struct omap_hwmod * to assert hardreset
2868 * @ohri: hardreset line data
2869 *
2870 * Call omap4_prminst_assert_hardreset() with parameters extracted
2871 * from the hwmod @oh and the hardreset line data @ohri. Only
2872 * intended for use as an soc_ops function pointer. Passes along the
2873 * return value from omap4_prminst_assert_hardreset(). XXX This
2874 * function is scheduled for removal when the PRM code is moved into
2875 * drivers/.
2876 */
2877static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2878 struct omap_hwmod_rst_info *ohri)
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002879{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002880 if (!oh->clkdm)
2881 return -EINVAL;
2882
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002883 return omap4_prminst_assert_hardreset(ohri->rst_shift,
2884 oh->clkdm->pwrdm.ptr->prcm_partition,
2885 oh->clkdm->pwrdm.ptr->prcm_offs,
2886 oh->prcm.omap4.rstctrl_offs);
2887}
2888
2889/**
2890 * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2891 * @oh: struct omap_hwmod * to deassert hardreset
2892 * @ohri: hardreset line data
2893 *
2894 * Call omap4_prminst_deassert_hardreset() with parameters extracted
2895 * from the hwmod @oh and the hardreset line data @ohri. Only
2896 * intended for use as an soc_ops function pointer. Passes along the
2897 * return value from omap4_prminst_deassert_hardreset(). XXX This
2898 * function is scheduled for removal when the PRM code is moved into
2899 * drivers/.
2900 */
2901static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2902 struct omap_hwmod_rst_info *ohri)
2903{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002904 if (!oh->clkdm)
2905 return -EINVAL;
2906
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002907 if (ohri->st_shift)
2908 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2909 oh->name, ohri->name);
2910 return omap4_prminst_deassert_hardreset(ohri->rst_shift,
2911 oh->clkdm->pwrdm.ptr->prcm_partition,
2912 oh->clkdm->pwrdm.ptr->prcm_offs,
2913 oh->prcm.omap4.rstctrl_offs);
2914}
2915
2916/**
2917 * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2918 * @oh: struct omap_hwmod * to test hardreset
2919 * @ohri: hardreset line data
2920 *
2921 * Call omap4_prminst_is_hardreset_asserted() with parameters
2922 * extracted from the hwmod @oh and the hardreset line data @ohri.
2923 * Only intended for use as an soc_ops function pointer. Passes along
2924 * the return value from omap4_prminst_is_hardreset_asserted(). XXX
2925 * This function is scheduled for removal when the PRM code is moved
2926 * into drivers/.
2927 */
2928static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2929 struct omap_hwmod_rst_info *ohri)
2930{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002931 if (!oh->clkdm)
2932 return -EINVAL;
2933
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002934 return omap4_prminst_is_hardreset_asserted(ohri->rst_shift,
2935 oh->clkdm->pwrdm.ptr->prcm_partition,
2936 oh->clkdm->pwrdm.ptr->prcm_offs,
2937 oh->prcm.omap4.rstctrl_offs);
2938}
2939
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002940/**
2941 * _am33xx_assert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2942 * @oh: struct omap_hwmod * to assert hardreset
2943 * @ohri: hardreset line data
2944 *
2945 * Call am33xx_prminst_assert_hardreset() with parameters extracted
2946 * from the hwmod @oh and the hardreset line data @ohri. Only
2947 * intended for use as an soc_ops function pointer. Passes along the
2948 * return value from am33xx_prminst_assert_hardreset(). XXX This
2949 * function is scheduled for removal when the PRM code is moved into
2950 * drivers/.
2951 */
2952static int _am33xx_assert_hardreset(struct omap_hwmod *oh,
2953 struct omap_hwmod_rst_info *ohri)
2954
2955{
2956 return am33xx_prm_assert_hardreset(ohri->rst_shift,
2957 oh->clkdm->pwrdm.ptr->prcm_offs,
2958 oh->prcm.omap4.rstctrl_offs);
2959}
2960
2961/**
2962 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2963 * @oh: struct omap_hwmod * to deassert hardreset
2964 * @ohri: hardreset line data
2965 *
2966 * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2967 * from the hwmod @oh and the hardreset line data @ohri. Only
2968 * intended for use as an soc_ops function pointer. Passes along the
2969 * return value from am33xx_prminst_deassert_hardreset(). XXX This
2970 * function is scheduled for removal when the PRM code is moved into
2971 * drivers/.
2972 */
2973static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2974 struct omap_hwmod_rst_info *ohri)
2975{
2976 if (ohri->st_shift)
2977 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2978 oh->name, ohri->name);
2979
2980 return am33xx_prm_deassert_hardreset(ohri->rst_shift,
2981 oh->clkdm->pwrdm.ptr->prcm_offs,
2982 oh->prcm.omap4.rstctrl_offs,
2983 oh->prcm.omap4.rstst_offs);
2984}
2985
2986/**
2987 * _am33xx_is_hardreset_asserted - call AM33XX PRM hardreset fn with hwmod args
2988 * @oh: struct omap_hwmod * to test hardreset
2989 * @ohri: hardreset line data
2990 *
2991 * Call am33xx_prminst_is_hardreset_asserted() with parameters
2992 * extracted from the hwmod @oh and the hardreset line data @ohri.
2993 * Only intended for use as an soc_ops function pointer. Passes along
2994 * the return value from am33xx_prminst_is_hardreset_asserted(). XXX
2995 * This function is scheduled for removal when the PRM code is moved
2996 * into drivers/.
2997 */
2998static int _am33xx_is_hardreset_asserted(struct omap_hwmod *oh,
2999 struct omap_hwmod_rst_info *ohri)
3000{
3001 return am33xx_prm_is_hardreset_asserted(ohri->rst_shift,
3002 oh->clkdm->pwrdm.ptr->prcm_offs,
3003 oh->prcm.omap4.rstctrl_offs);
3004}
3005
Paul Walmsley63c85232009-09-03 20:14:03 +03003006/* Public functions */
3007
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003008u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03003009{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003010 if (oh->flags & HWMOD_16BIT_REG)
3011 return __raw_readw(oh->_mpu_rt_va + reg_offs);
3012 else
3013 return __raw_readl(oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03003014}
3015
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003016void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03003017{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003018 if (oh->flags & HWMOD_16BIT_REG)
3019 __raw_writew(v, oh->_mpu_rt_va + reg_offs);
3020 else
3021 __raw_writel(v, oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03003022}
3023
Paul Walmsley887adea2010-07-26 16:34:33 -06003024/**
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003025 * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
3026 * @oh: struct omap_hwmod *
3027 *
3028 * This is a public function exposed to drivers. Some drivers may need to do
3029 * some settings before and after resetting the device. Those drivers after
3030 * doing the necessary settings could use this function to start a reset by
3031 * setting the SYSCONFIG.SOFTRESET bit.
3032 */
3033int omap_hwmod_softreset(struct omap_hwmod *oh)
3034{
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06003035 u32 v;
3036 int ret;
3037
3038 if (!oh || !(oh->_sysc_cache))
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003039 return -EINVAL;
3040
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06003041 v = oh->_sysc_cache;
3042 ret = _set_softreset(oh, &v);
3043 if (ret)
3044 goto error;
3045 _write_sysconfig(v, oh);
3046
3047error:
3048 return ret;
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003049}
3050
3051/**
Paul Walmsley887adea2010-07-26 16:34:33 -06003052 * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
3053 * @oh: struct omap_hwmod *
3054 * @idlemode: SIDLEMODE field bits (shifted to bit 0)
3055 *
3056 * Sets the IP block's OCP slave idlemode in hardware, and updates our
3057 * local copy. Intended to be used by drivers that have some erratum
3058 * that requires direct manipulation of the SIDLEMODE bits. Returns
3059 * -EINVAL if @oh is null, or passes along the return value from
3060 * _set_slave_idlemode().
3061 *
3062 * XXX Does this function have any current users? If not, we should
3063 * remove it; it is better to let the rest of the hwmod code handle this.
3064 * Any users of this function should be scrutinized carefully.
3065 */
Kevin Hilman46273e62010-01-26 20:13:03 -07003066int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
3067{
3068 u32 v;
3069 int retval = 0;
3070
3071 if (!oh)
3072 return -EINVAL;
3073
3074 v = oh->_sysc_cache;
3075
3076 retval = _set_slave_idlemode(oh, idlemode, &v);
3077 if (!retval)
3078 _write_sysconfig(v, oh);
3079
3080 return retval;
3081}
3082
Paul Walmsley63c85232009-09-03 20:14:03 +03003083/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003084 * omap_hwmod_lookup - look up a registered omap_hwmod by name
3085 * @name: name of the omap_hwmod to look up
3086 *
3087 * Given a @name of an omap_hwmod, return a pointer to the registered
3088 * struct omap_hwmod *, or NULL upon error.
3089 */
3090struct omap_hwmod *omap_hwmod_lookup(const char *name)
3091{
3092 struct omap_hwmod *oh;
3093
3094 if (!name)
3095 return NULL;
3096
Paul Walmsley63c85232009-09-03 20:14:03 +03003097 oh = _lookup(name);
Paul Walmsley63c85232009-09-03 20:14:03 +03003098
3099 return oh;
3100}
3101
3102/**
3103 * omap_hwmod_for_each - call function for each registered omap_hwmod
3104 * @fn: pointer to a callback function
Paul Walmsley97d601622010-07-26 16:34:30 -06003105 * @data: void * data to pass to callback function
Paul Walmsley63c85232009-09-03 20:14:03 +03003106 *
3107 * Call @fn for each registered omap_hwmod, passing @data to each
3108 * function. @fn must return 0 for success or any other value for
3109 * failure. If @fn returns non-zero, the iteration across omap_hwmods
3110 * will stop and the non-zero return value will be passed to the
3111 * caller of omap_hwmod_for_each(). @fn is called with
3112 * omap_hwmod_for_each() held.
3113 */
Paul Walmsley97d601622010-07-26 16:34:30 -06003114int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
3115 void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03003116{
3117 struct omap_hwmod *temp_oh;
Govindraj.R30ebad92011-06-01 11:28:56 +05303118 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003119
3120 if (!fn)
3121 return -EINVAL;
3122
Paul Walmsley63c85232009-09-03 20:14:03 +03003123 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
Paul Walmsley97d601622010-07-26 16:34:30 -06003124 ret = (*fn)(temp_oh, data);
Paul Walmsley63c85232009-09-03 20:14:03 +03003125 if (ret)
3126 break;
3127 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003128
3129 return ret;
3130}
3131
Paul Walmsley63c85232009-09-03 20:14:03 +03003132/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003133 * omap_hwmod_register_links - register an array of hwmod links
3134 * @ois: pointer to an array of omap_hwmod_ocp_if to register
3135 *
3136 * Intended to be called early in boot before the clock framework is
3137 * initialized. If @ois is not null, will register all omap_hwmods
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003138 * listed in @ois that are valid for this chip. Returns -EINVAL if
3139 * omap_hwmod_init() hasn't been called before calling this function,
3140 * -ENOMEM if the link memory area can't be allocated, or 0 upon
3141 * success.
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003142 */
3143int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3144{
3145 int r, i;
3146
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003147 if (!inited)
3148 return -EINVAL;
3149
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003150 if (!ois)
3151 return 0;
3152
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003153 if (!linkspace) {
3154 if (_alloc_linkspace(ois)) {
3155 pr_err("omap_hwmod: could not allocate link space\n");
3156 return -ENOMEM;
3157 }
3158 }
3159
3160 i = 0;
3161 do {
3162 r = _register_link(ois[i]);
3163 WARN(r && r != -EEXIST,
3164 "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3165 ois[i]->master->name, ois[i]->slave->name, r);
3166 } while (ois[++i]);
3167
3168 return 0;
3169}
3170
3171/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003172 * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3173 * @oh: pointer to the hwmod currently being set up (usually not the MPU)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003174 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003175 * If the hwmod data corresponding to the MPU subsystem IP block
3176 * hasn't been initialized and set up yet, do so now. This must be
3177 * done first since sleep dependencies may be added from other hwmods
3178 * to the MPU. Intended to be called only by omap_hwmod_setup*(). No
3179 * return value.
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003180 */
Paul Walmsley381d0332012-04-19 00:58:22 -06003181static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003182{
Paul Walmsley381d0332012-04-19 00:58:22 -06003183 if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3184 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3185 __func__, MPU_INITIATOR_NAME);
3186 else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3187 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
Paul Walmsley63c85232009-09-03 20:14:03 +03003188}
3189
3190/**
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003191 * omap_hwmod_setup_one - set up a single hwmod
3192 * @oh_name: const char * name of the already-registered hwmod to set up
3193 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003194 * Initialize and set up a single hwmod. Intended to be used for a
3195 * small number of early devices, such as the timer IP blocks used for
3196 * the scheduler clock. Must be called after omap2_clk_init().
3197 * Resolves the struct clk names to struct clk pointers for each
3198 * registered omap_hwmod. Also calls _setup() on each hwmod. Returns
3199 * -EINVAL upon error or 0 upon success.
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003200 */
3201int __init omap_hwmod_setup_one(const char *oh_name)
3202{
3203 struct omap_hwmod *oh;
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003204
3205 pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3206
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003207 oh = _lookup(oh_name);
3208 if (!oh) {
3209 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3210 return -EINVAL;
3211 }
3212
Paul Walmsley381d0332012-04-19 00:58:22 -06003213 _ensure_mpu_hwmod_is_setup(oh);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003214
Paul Walmsley381d0332012-04-19 00:58:22 -06003215 _init(oh, NULL);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003216 _setup(oh, NULL);
3217
3218 return 0;
3219}
3220
3221/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003222 * omap_hwmod_setup_all - set up all registered IP blocks
Paul Walmsley63c85232009-09-03 20:14:03 +03003223 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003224 * Initialize and set up all IP blocks registered with the hwmod code.
3225 * Must be called after omap2_clk_init(). Resolves the struct clk
3226 * names to struct clk pointers for each registered omap_hwmod. Also
3227 * calls _setup() on each hwmod. Returns 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003228 */
Paul Walmsley550c8092011-02-28 11:58:14 -07003229static int __init omap_hwmod_setup_all(void)
Paul Walmsley63c85232009-09-03 20:14:03 +03003230{
Paul Walmsley381d0332012-04-19 00:58:22 -06003231 _ensure_mpu_hwmod_is_setup(NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003232
Paul Walmsley381d0332012-04-19 00:58:22 -06003233 omap_hwmod_for_each(_init, NULL);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003234 omap_hwmod_for_each(_setup, NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003235
3236 return 0;
3237}
Paul Walmsley550c8092011-02-28 11:58:14 -07003238core_initcall(omap_hwmod_setup_all);
Paul Walmsley63c85232009-09-03 20:14:03 +03003239
3240/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003241 * omap_hwmod_enable - enable an omap_hwmod
3242 * @oh: struct omap_hwmod *
3243 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003244 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
Paul Walmsley63c85232009-09-03 20:14:03 +03003245 * Returns -EINVAL on error or passes along the return value from _enable().
3246 */
3247int omap_hwmod_enable(struct omap_hwmod *oh)
3248{
3249 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003250 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003251
3252 if (!oh)
3253 return -EINVAL;
3254
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003255 spin_lock_irqsave(&oh->_lock, flags);
3256 r = _enable(oh);
3257 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003258
3259 return r;
3260}
3261
3262/**
3263 * omap_hwmod_idle - idle an omap_hwmod
3264 * @oh: struct omap_hwmod *
3265 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003266 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
Paul Walmsley63c85232009-09-03 20:14:03 +03003267 * Returns -EINVAL on error or passes along the return value from _idle().
3268 */
3269int omap_hwmod_idle(struct omap_hwmod *oh)
3270{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003271 unsigned long flags;
3272
Paul Walmsley63c85232009-09-03 20:14:03 +03003273 if (!oh)
3274 return -EINVAL;
3275
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003276 spin_lock_irqsave(&oh->_lock, flags);
3277 _idle(oh);
3278 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003279
3280 return 0;
3281}
3282
3283/**
3284 * omap_hwmod_shutdown - shutdown an omap_hwmod
3285 * @oh: struct omap_hwmod *
3286 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003287 * Shutdown an omap_hwmod @oh. Intended to be called by
Paul Walmsley63c85232009-09-03 20:14:03 +03003288 * omap_device_shutdown(). Returns -EINVAL on error or passes along
3289 * the return value from _shutdown().
3290 */
3291int omap_hwmod_shutdown(struct omap_hwmod *oh)
3292{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003293 unsigned long flags;
3294
Paul Walmsley63c85232009-09-03 20:14:03 +03003295 if (!oh)
3296 return -EINVAL;
3297
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003298 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003299 _shutdown(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003300 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003301
3302 return 0;
3303}
3304
3305/**
3306 * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
3307 * @oh: struct omap_hwmod *oh
3308 *
3309 * Intended to be called by the omap_device code.
3310 */
3311int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
3312{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003313 unsigned long flags;
3314
3315 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003316 _enable_clocks(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003317 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003318
3319 return 0;
3320}
3321
3322/**
3323 * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
3324 * @oh: struct omap_hwmod *oh
3325 *
3326 * Intended to be called by the omap_device code.
3327 */
3328int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
3329{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003330 unsigned long flags;
3331
3332 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003333 _disable_clocks(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003334 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003335
3336 return 0;
3337}
3338
3339/**
3340 * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
3341 * @oh: struct omap_hwmod *oh
3342 *
3343 * Intended to be called by drivers and core code when all posted
3344 * writes to a device must complete before continuing further
3345 * execution (for example, after clearing some device IRQSTATUS
3346 * register bits)
3347 *
3348 * XXX what about targets with multiple OCP threads?
3349 */
3350void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
3351{
3352 BUG_ON(!oh);
3353
Paul Walmsley43b40992010-02-22 22:09:34 -07003354 if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
Russell King4f8a4282012-02-07 10:59:37 +00003355 WARN(1, "omap_device: %s: OCP barrier impossible due to device configuration\n",
3356 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03003357 return;
3358 }
3359
3360 /*
3361 * Forces posted writes to complete on the OCP thread handling
3362 * register writes
3363 */
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003364 omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03003365}
3366
3367/**
3368 * omap_hwmod_reset - reset the hwmod
3369 * @oh: struct omap_hwmod *
3370 *
3371 * Under some conditions, a driver may wish to reset the entire device.
3372 * Called from omap_device code. Returns -EINVAL on error or passes along
Liam Girdwood9b579112010-09-21 10:34:09 -06003373 * the return value from _reset().
Paul Walmsley63c85232009-09-03 20:14:03 +03003374 */
3375int omap_hwmod_reset(struct omap_hwmod *oh)
3376{
3377 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003378 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003379
Liam Girdwood9b579112010-09-21 10:34:09 -06003380 if (!oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03003381 return -EINVAL;
3382
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003383 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003384 r = _reset(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003385 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003386
3387 return r;
3388}
3389
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003390/*
3391 * IP block data retrieval functions
3392 */
3393
Paul Walmsley63c85232009-09-03 20:14:03 +03003394/**
3395 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
3396 * @oh: struct omap_hwmod *
3397 * @res: pointer to the first element of an array of struct resource to fill
3398 *
3399 * Count the number of struct resource array elements necessary to
3400 * contain omap_hwmod @oh resources. Intended to be called by code
3401 * that registers omap_devices. Intended to be used to determine the
3402 * size of a dynamically-allocated struct resource array, before
3403 * calling omap_hwmod_fill_resources(). Returns the number of struct
3404 * resource array elements needed.
3405 *
3406 * XXX This code is not optimized. It could attempt to merge adjacent
3407 * resource IDs.
3408 *
3409 */
3410int omap_hwmod_count_resources(struct omap_hwmod *oh)
3411{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003412 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003413 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003414 int ret;
3415 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003416
Paul Walmsleybc614952011-07-09 19:14:07 -06003417 ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03003418
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003419 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003420
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003421 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003422 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003423 ret += _count_ocp_if_addr_spaces(os);
3424 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003425
3426 return ret;
3427}
3428
3429/**
3430 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
3431 * @oh: struct omap_hwmod *
3432 * @res: pointer to the first element of an array of struct resource to fill
3433 *
3434 * Fill the struct resource array @res with resource data from the
3435 * omap_hwmod @oh. Intended to be called by code that registers
3436 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3437 * number of array elements filled.
3438 */
3439int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3440{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003441 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003442 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003443 int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
Paul Walmsley63c85232009-09-03 20:14:03 +03003444 int r = 0;
3445
3446 /* For each IRQ, DMA, memory area, fill in array.*/
3447
Paul Walmsley212738a2011-07-09 19:14:06 -06003448 mpu_irqs_cnt = _count_mpu_irqs(oh);
3449 for (i = 0; i < mpu_irqs_cnt; i++) {
Paul Walmsley718bfd72009-12-08 16:34:16 -07003450 (res + r)->name = (oh->mpu_irqs + i)->name;
3451 (res + r)->start = (oh->mpu_irqs + i)->irq;
3452 (res + r)->end = (oh->mpu_irqs + i)->irq;
Paul Walmsley63c85232009-09-03 20:14:03 +03003453 (res + r)->flags = IORESOURCE_IRQ;
3454 r++;
3455 }
3456
Paul Walmsleybc614952011-07-09 19:14:07 -06003457 sdma_reqs_cnt = _count_sdma_reqs(oh);
3458 for (i = 0; i < sdma_reqs_cnt; i++) {
Benoit Cousson9ee9fff2010-09-21 10:34:08 -06003459 (res + r)->name = (oh->sdma_reqs + i)->name;
3460 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3461 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
Paul Walmsley63c85232009-09-03 20:14:03 +03003462 (res + r)->flags = IORESOURCE_DMA;
3463 r++;
3464 }
3465
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003466 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003467
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003468 i = 0;
3469 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003470 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley78183f32011-07-09 19:14:05 -06003471 addr_cnt = _count_ocp_if_addr_spaces(os);
Paul Walmsley63c85232009-09-03 20:14:03 +03003472
Paul Walmsley78183f32011-07-09 19:14:05 -06003473 for (j = 0; j < addr_cnt; j++) {
Kishon Vijay Abraham Icd503802011-02-24 12:51:45 -08003474 (res + r)->name = (os->addr + j)->name;
Paul Walmsley63c85232009-09-03 20:14:03 +03003475 (res + r)->start = (os->addr + j)->pa_start;
3476 (res + r)->end = (os->addr + j)->pa_end;
3477 (res + r)->flags = IORESOURCE_MEM;
3478 r++;
3479 }
3480 }
3481
3482 return r;
3483}
3484
3485/**
Vaibhav Hiremathb82b04e2012-08-29 15:18:11 +05303486 * omap_hwmod_fill_dma_resources - fill struct resource array with dma data
3487 * @oh: struct omap_hwmod *
3488 * @res: pointer to the array of struct resource to fill
3489 *
3490 * Fill the struct resource array @res with dma resource data from the
3491 * omap_hwmod @oh. Intended to be called by code that registers
3492 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3493 * number of array elements filled.
3494 */
3495int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res)
3496{
3497 int i, sdma_reqs_cnt;
3498 int r = 0;
3499
3500 sdma_reqs_cnt = _count_sdma_reqs(oh);
3501 for (i = 0; i < sdma_reqs_cnt; i++) {
3502 (res + r)->name = (oh->sdma_reqs + i)->name;
3503 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3504 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3505 (res + r)->flags = IORESOURCE_DMA;
3506 r++;
3507 }
3508
3509 return r;
3510}
3511
3512/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003513 * omap_hwmod_get_resource_byname - fetch IP block integration data by name
3514 * @oh: struct omap_hwmod * to operate on
3515 * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
3516 * @name: pointer to the name of the data to fetch (optional)
3517 * @rsrc: pointer to a struct resource, allocated by the caller
3518 *
3519 * Retrieve MPU IRQ, SDMA request line, or address space start/end
3520 * data for the IP block pointed to by @oh. The data will be filled
3521 * into a struct resource record pointed to by @rsrc. The struct
3522 * resource must be allocated by the caller. When @name is non-null,
3523 * the data associated with the matching entry in the IRQ/SDMA/address
3524 * space hwmod data arrays will be returned. If @name is null, the
3525 * first array entry will be returned. Data order is not meaningful
3526 * in hwmod data, so callers are strongly encouraged to use a non-null
3527 * @name whenever possible to avoid unpredictable effects if hwmod
3528 * data is later added that causes data ordering to change. This
3529 * function is only intended for use by OMAP core code. Device
3530 * drivers should not call this function - the appropriate bus-related
3531 * data accessor functions should be used instead. Returns 0 upon
3532 * success or a negative error code upon error.
3533 */
3534int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
3535 const char *name, struct resource *rsrc)
3536{
3537 int r;
3538 unsigned int irq, dma;
3539 u32 pa_start, pa_end;
3540
3541 if (!oh || !rsrc)
3542 return -EINVAL;
3543
3544 if (type == IORESOURCE_IRQ) {
3545 r = _get_mpu_irq_by_name(oh, name, &irq);
3546 if (r)
3547 return r;
3548
3549 rsrc->start = irq;
3550 rsrc->end = irq;
3551 } else if (type == IORESOURCE_DMA) {
3552 r = _get_sdma_req_by_name(oh, name, &dma);
3553 if (r)
3554 return r;
3555
3556 rsrc->start = dma;
3557 rsrc->end = dma;
3558 } else if (type == IORESOURCE_MEM) {
3559 r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
3560 if (r)
3561 return r;
3562
3563 rsrc->start = pa_start;
3564 rsrc->end = pa_end;
3565 } else {
3566 return -EINVAL;
3567 }
3568
3569 rsrc->flags = type;
3570 rsrc->name = name;
3571
3572 return 0;
3573}
3574
3575/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003576 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3577 * @oh: struct omap_hwmod *
3578 *
3579 * Return the powerdomain pointer associated with the OMAP module
3580 * @oh's main clock. If @oh does not have a main clk, return the
3581 * powerdomain associated with the interface clock associated with the
3582 * module's MPU port. (XXX Perhaps this should use the SDMA port
3583 * instead?) Returns NULL on error, or a struct powerdomain * on
3584 * success.
3585 */
3586struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3587{
3588 struct clk *c;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003589 struct omap_hwmod_ocp_if *oi;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003590 struct clockdomain *clkdm;
3591#ifdef CONFIG_COMMON_CLK
3592 struct clk_hw_omap *clk;
3593#endif
Paul Walmsley63c85232009-09-03 20:14:03 +03003594
3595 if (!oh)
3596 return NULL;
3597
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003598 if (oh->clkdm)
3599 return oh->clkdm->pwrdm.ptr;
3600
Paul Walmsley63c85232009-09-03 20:14:03 +03003601 if (oh->_clk) {
3602 c = oh->_clk;
3603 } else {
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003604 oi = _find_mpu_rt_port(oh);
3605 if (!oi)
Paul Walmsley63c85232009-09-03 20:14:03 +03003606 return NULL;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003607 c = oi->_clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003608 }
3609
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003610#ifdef CONFIG_COMMON_CLK
3611 clk = to_clk_hw_omap(__clk_get_hw(c));
3612 clkdm = clk->clkdm;
3613#else
3614 clkdm = c->clkdm;
3615#endif
3616 if (!clkdm)
Thara Gopinathd5647c12010-03-31 04:16:29 -06003617 return NULL;
3618
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003619 return clkdm->pwrdm.ptr;
Paul Walmsley63c85232009-09-03 20:14:03 +03003620}
3621
3622/**
Paul Walmsleydb2a60b2010-07-26 16:34:33 -06003623 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3624 * @oh: struct omap_hwmod *
3625 *
3626 * Returns the virtual address corresponding to the beginning of the
3627 * module's register target, in the address range that is intended to
3628 * be used by the MPU. Returns the virtual address upon success or NULL
3629 * upon error.
3630 */
3631void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3632{
3633 if (!oh)
3634 return NULL;
3635
3636 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3637 return NULL;
3638
3639 if (oh->_state == _HWMOD_STATE_UNKNOWN)
3640 return NULL;
3641
3642 return oh->_mpu_rt_va;
3643}
3644
3645/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003646 * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
3647 * @oh: struct omap_hwmod *
3648 * @init_oh: struct omap_hwmod * (initiator)
3649 *
3650 * Add a sleep dependency between the initiator @init_oh and @oh.
3651 * Intended to be called by DSP/Bridge code via platform_data for the
3652 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
3653 * code needs to add/del initiator dependencies dynamically
3654 * before/after accessing a device. Returns the return value from
3655 * _add_initiator_dep().
3656 *
3657 * XXX Keep a usecount in the clockdomain code
3658 */
3659int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
3660 struct omap_hwmod *init_oh)
3661{
3662 return _add_initiator_dep(oh, init_oh);
3663}
3664
3665/*
3666 * XXX what about functions for drivers to save/restore ocp_sysconfig
3667 * for context save/restore operations?
3668 */
3669
3670/**
3671 * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
3672 * @oh: struct omap_hwmod *
3673 * @init_oh: struct omap_hwmod * (initiator)
3674 *
3675 * Remove a sleep dependency between the initiator @init_oh and @oh.
3676 * Intended to be called by DSP/Bridge code via platform_data for the
3677 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
3678 * code needs to add/del initiator dependencies dynamically
3679 * before/after accessing a device. Returns the return value from
3680 * _del_initiator_dep().
3681 *
3682 * XXX Keep a usecount in the clockdomain code
3683 */
3684int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
3685 struct omap_hwmod *init_oh)
3686{
3687 return _del_initiator_dep(oh, init_oh);
3688}
3689
3690/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003691 * omap_hwmod_enable_wakeup - allow device to wake up the system
3692 * @oh: struct omap_hwmod *
3693 *
3694 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
Govindraj.R2a1cc142012-04-05 02:59:32 -06003695 * send wakeups to the PRCM, and enable I/O ring wakeup events for
3696 * this IP block if it has dynamic mux entries. Eventually this
3697 * should set PRCM wakeup registers to cause the PRCM to receive
3698 * wakeup events from the module. Does not set any wakeup routing
3699 * registers beyond this point - if the module is to wake up any other
3700 * module or subsystem, that must be set separately. Called by
3701 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003702 */
3703int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3704{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003705 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003706 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003707
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003708 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003709
3710 if (oh->class->sysc &&
3711 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3712 v = oh->_sysc_cache;
3713 _enable_wakeup(oh, &v);
3714 _write_sysconfig(v, oh);
3715 }
3716
Govindraj Receec002011-12-16 14:36:58 -07003717 _set_idle_ioring_wakeup(oh, true);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003718 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003719
3720 return 0;
3721}
3722
3723/**
3724 * omap_hwmod_disable_wakeup - prevent device from waking the system
3725 * @oh: struct omap_hwmod *
3726 *
3727 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
Govindraj.R2a1cc142012-04-05 02:59:32 -06003728 * from sending wakeups to the PRCM, and disable I/O ring wakeup
3729 * events for this IP block if it has dynamic mux entries. Eventually
3730 * this should clear PRCM wakeup registers to cause the PRCM to ignore
3731 * wakeup events from the module. Does not set any wakeup routing
3732 * registers beyond this point - if the module is to wake up any other
3733 * module or subsystem, that must be set separately. Called by
3734 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003735 */
3736int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3737{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003738 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003739 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003740
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003741 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003742
3743 if (oh->class->sysc &&
3744 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3745 v = oh->_sysc_cache;
3746 _disable_wakeup(oh, &v);
3747 _write_sysconfig(v, oh);
3748 }
3749
Govindraj Receec002011-12-16 14:36:58 -07003750 _set_idle_ioring_wakeup(oh, false);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003751 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003752
3753 return 0;
3754}
Paul Walmsley43b40992010-02-22 22:09:34 -07003755
3756/**
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003757 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3758 * contained in the hwmod module.
3759 * @oh: struct omap_hwmod *
3760 * @name: name of the reset line to lookup and assert
3761 *
3762 * Some IP like dsp, ipu or iva contain processor that require
3763 * an HW reset line to be assert / deassert in order to enable fully
3764 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3765 * yet supported on this OMAP; otherwise, passes along the return value
3766 * from _assert_hardreset().
3767 */
3768int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3769{
3770 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003771 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003772
3773 if (!oh)
3774 return -EINVAL;
3775
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003776 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003777 ret = _assert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003778 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003779
3780 return ret;
3781}
3782
3783/**
3784 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3785 * contained in the hwmod module.
3786 * @oh: struct omap_hwmod *
3787 * @name: name of the reset line to look up and deassert
3788 *
3789 * Some IP like dsp, ipu or iva contain processor that require
3790 * an HW reset line to be assert / deassert in order to enable fully
3791 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3792 * yet supported on this OMAP; otherwise, passes along the return value
3793 * from _deassert_hardreset().
3794 */
3795int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3796{
3797 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003798 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003799
3800 if (!oh)
3801 return -EINVAL;
3802
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003803 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003804 ret = _deassert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003805 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003806
3807 return ret;
3808}
3809
3810/**
3811 * omap_hwmod_read_hardreset - read the HW reset line state of submodules
3812 * contained in the hwmod module
3813 * @oh: struct omap_hwmod *
3814 * @name: name of the reset line to look up and read
3815 *
3816 * Return the current state of the hwmod @oh's reset line named @name:
3817 * returns -EINVAL upon parameter error or if this operation
3818 * is unsupported on the current OMAP; otherwise, passes along the return
3819 * value from _read_hardreset().
3820 */
3821int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
3822{
3823 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003824 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003825
3826 if (!oh)
3827 return -EINVAL;
3828
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003829 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003830 ret = _read_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003831 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003832
3833 return ret;
3834}
3835
3836
3837/**
Paul Walmsley43b40992010-02-22 22:09:34 -07003838 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3839 * @classname: struct omap_hwmod_class name to search for
3840 * @fn: callback function pointer to call for each hwmod in class @classname
3841 * @user: arbitrary context data to pass to the callback function
3842 *
Benoit Coussonce35b242010-12-21 21:31:28 -07003843 * For each omap_hwmod of class @classname, call @fn.
3844 * If the callback function returns something other than
Paul Walmsley43b40992010-02-22 22:09:34 -07003845 * zero, the iterator is terminated, and the callback function's return
3846 * value is passed back to the caller. Returns 0 upon success, -EINVAL
3847 * if @classname or @fn are NULL, or passes back the error code from @fn.
3848 */
3849int omap_hwmod_for_each_by_class(const char *classname,
3850 int (*fn)(struct omap_hwmod *oh,
3851 void *user),
3852 void *user)
3853{
3854 struct omap_hwmod *temp_oh;
3855 int ret = 0;
3856
3857 if (!classname || !fn)
3858 return -EINVAL;
3859
3860 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3861 __func__, classname);
3862
Paul Walmsley43b40992010-02-22 22:09:34 -07003863 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3864 if (!strcmp(temp_oh->class->name, classname)) {
3865 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3866 __func__, temp_oh->name);
3867 ret = (*fn)(temp_oh, user);
3868 if (ret)
3869 break;
3870 }
3871 }
3872
Paul Walmsley43b40992010-02-22 22:09:34 -07003873 if (ret)
3874 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3875 __func__, ret);
3876
3877 return ret;
3878}
3879
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003880/**
3881 * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3882 * @oh: struct omap_hwmod *
3883 * @state: state that _setup() should leave the hwmod in
3884 *
Paul Walmsley550c8092011-02-28 11:58:14 -07003885 * Sets the hwmod state that @oh will enter at the end of _setup()
Paul Walmsley64813c32012-04-18 19:10:03 -06003886 * (called by omap_hwmod_setup_*()). See also the documentation
3887 * for _setup_postsetup(), above. Returns 0 upon success or
3888 * -EINVAL if there is a problem with the arguments or if the hwmod is
3889 * in the wrong state.
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003890 */
3891int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3892{
3893 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003894 unsigned long flags;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003895
3896 if (!oh)
3897 return -EINVAL;
3898
3899 if (state != _HWMOD_STATE_DISABLED &&
3900 state != _HWMOD_STATE_ENABLED &&
3901 state != _HWMOD_STATE_IDLE)
3902 return -EINVAL;
3903
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003904 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003905
3906 if (oh->_state != _HWMOD_STATE_REGISTERED) {
3907 ret = -EINVAL;
3908 goto ohsps_unlock;
3909 }
3910
3911 oh->_postsetup_state = state;
3912 ret = 0;
3913
3914ohsps_unlock:
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003915 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003916
3917 return ret;
3918}
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003919
3920/**
3921 * omap_hwmod_get_context_loss_count - get lost context count
3922 * @oh: struct omap_hwmod *
3923 *
3924 * Query the powerdomain of of @oh to get the context loss
3925 * count for this device.
3926 *
3927 * Returns the context loss count of the powerdomain assocated with @oh
3928 * upon success, or zero if no powerdomain exists for @oh.
3929 */
Tomi Valkeinenfc013872011-06-09 16:56:23 +03003930int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003931{
3932 struct powerdomain *pwrdm;
3933 int ret = 0;
3934
3935 pwrdm = omap_hwmod_get_pwrdm(oh);
3936 if (pwrdm)
3937 ret = pwrdm_get_context_loss_count(pwrdm);
3938
3939 return ret;
3940}
Paul Walmsley43b01642011-03-10 03:50:07 -07003941
3942/**
3943 * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
3944 * @oh: struct omap_hwmod *
3945 *
3946 * Prevent the hwmod @oh from being reset during the setup process.
3947 * Intended for use by board-*.c files on boards with devices that
3948 * cannot tolerate being reset. Must be called before the hwmod has
3949 * been set up. Returns 0 upon success or negative error code upon
3950 * failure.
3951 */
3952int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
3953{
3954 if (!oh)
3955 return -EINVAL;
3956
3957 if (oh->_state != _HWMOD_STATE_REGISTERED) {
3958 pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
3959 oh->name);
3960 return -EINVAL;
3961 }
3962
3963 oh->flags |= HWMOD_INIT_NO_RESET;
3964
3965 return 0;
3966}
Tero Kristoabc2d542011-12-16 14:36:59 -07003967
3968/**
3969 * omap_hwmod_pad_route_irq - route an I/O pad wakeup to a particular MPU IRQ
3970 * @oh: struct omap_hwmod * containing hwmod mux entries
3971 * @pad_idx: array index in oh->mux of the hwmod mux entry to route wakeup
3972 * @irq_idx: the hwmod mpu_irqs array index of the IRQ to trigger on wakeup
3973 *
3974 * When an I/O pad wakeup arrives for the dynamic or wakeup hwmod mux
3975 * entry number @pad_idx for the hwmod @oh, trigger the interrupt
3976 * service routine for the hwmod's mpu_irqs array index @irq_idx. If
3977 * this function is not called for a given pad_idx, then the ISR
3978 * associated with @oh's first MPU IRQ will be triggered when an I/O
3979 * pad wakeup occurs on that pad. Note that @pad_idx is the index of
3980 * the _dynamic or wakeup_ entry: if there are other entries not
3981 * marked with OMAP_DEVICE_PAD_WAKEUP or OMAP_DEVICE_PAD_REMUX, these
3982 * entries are NOT COUNTED in the dynamic pad index. This function
3983 * must be called separately for each pad that requires its interrupt
3984 * to be re-routed this way. Returns -EINVAL if there is an argument
3985 * problem or if @oh does not have hwmod mux entries or MPU IRQs;
3986 * returns -ENOMEM if memory cannot be allocated; or 0 upon success.
3987 *
3988 * XXX This function interface is fragile. Rather than using array
3989 * indexes, which are subject to unpredictable change, it should be
3990 * using hwmod IRQ names, and some other stable key for the hwmod mux
3991 * pad records.
3992 */
3993int omap_hwmod_pad_route_irq(struct omap_hwmod *oh, int pad_idx, int irq_idx)
3994{
3995 int nr_irqs;
3996
3997 might_sleep();
3998
3999 if (!oh || !oh->mux || !oh->mpu_irqs || pad_idx < 0 ||
4000 pad_idx >= oh->mux->nr_pads_dynamic)
4001 return -EINVAL;
4002
4003 /* Check the number of available mpu_irqs */
4004 for (nr_irqs = 0; oh->mpu_irqs[nr_irqs].irq >= 0; nr_irqs++)
4005 ;
4006
4007 if (irq_idx >= nr_irqs)
4008 return -EINVAL;
4009
4010 if (!oh->mux->irqs) {
4011 /* XXX What frees this? */
4012 oh->mux->irqs = kzalloc(sizeof(int) * oh->mux->nr_pads_dynamic,
4013 GFP_KERNEL);
4014 if (!oh->mux->irqs)
4015 return -ENOMEM;
4016 }
4017 oh->mux->irqs[pad_idx] = irq_idx;
4018
4019 return 0;
4020}
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004021
4022/**
4023 * omap_hwmod_init - initialize the hwmod code
4024 *
4025 * Sets up some function pointers needed by the hwmod code to operate on the
4026 * currently-booted SoC. Intended to be called once during kernel init
4027 * before any hwmods are registered. No return value.
4028 */
4029void __init omap_hwmod_init(void)
4030{
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06004031 if (cpu_is_omap24xx()) {
4032 soc_ops.wait_target_ready = _omap2xxx_wait_target_ready;
4033 soc_ops.assert_hardreset = _omap2_assert_hardreset;
4034 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
4035 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
4036 } else if (cpu_is_omap34xx()) {
4037 soc_ops.wait_target_ready = _omap3xxx_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06004038 soc_ops.assert_hardreset = _omap2_assert_hardreset;
4039 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
4040 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
R Sricharan05e152c2012-06-05 16:21:32 +05304041 } else if (cpu_is_omap44xx() || soc_is_omap54xx()) {
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004042 soc_ops.enable_module = _omap4_enable_module;
4043 soc_ops.disable_module = _omap4_disable_module;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004044 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06004045 soc_ops.assert_hardreset = _omap4_assert_hardreset;
4046 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
4047 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Kevin Hilman0a179ea2012-06-18 12:12:25 -06004048 soc_ops.init_clkdm = _init_clkdm;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06004049 } else if (soc_is_am33xx()) {
4050 soc_ops.enable_module = _am33xx_enable_module;
4051 soc_ops.disable_module = _am33xx_disable_module;
4052 soc_ops.wait_target_ready = _am33xx_wait_target_ready;
4053 soc_ops.assert_hardreset = _am33xx_assert_hardreset;
4054 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
4055 soc_ops.is_hardreset_asserted = _am33xx_is_hardreset_asserted;
4056 soc_ops.init_clkdm = _init_clkdm;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004057 } else {
4058 WARN(1, "omap_hwmod: unknown SoC type\n");
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004059 }
4060
4061 inited = true;
4062}
Tony Lindgren68c9a952012-07-06 00:58:43 -07004063
4064/**
4065 * omap_hwmod_get_main_clk - get pointer to main clock name
4066 * @oh: struct omap_hwmod *
4067 *
4068 * Returns the main clock name assocated with @oh upon success,
4069 * or NULL if @oh is NULL.
4070 */
4071const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
4072{
4073 if (!oh)
4074 return NULL;
4075
4076 return oh->main_clk;
4077}