blob: 9658e6b8ed846691831f341e7abcb2daa0ef56e6 [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>
133#include <linux/clk.h>
134#include <linux/delay.h>
135#include <linux/err.h>
136#include <linux/list.h>
137#include <linux/mutex.h>
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -0700138#include <linux/spinlock.h>
Tero Kristoabc2d542011-12-16 14:36:59 -0700139#include <linux/slab.h>
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600140#include <linux/bootmem.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300141
Paul Walmsleya135eaa2012-09-27 10:33:34 -0600142#include "clock.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -0700143#include "omap_hwmod.h"
Benoît Cousson5365efb2010-09-21 10:34:11 -0600144#include <plat/prcm.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300145
Tony Lindgrendbc04162012-08-31 10:59:07 -0700146#include "soc.h"
147#include "common.h"
148#include "clockdomain.h"
149#include "powerdomain.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -0600150#include "cm2xxx.h"
151#include "cm3xxx.h"
Benoit Coussond0f06312011-07-10 05:56:30 -0600152#include "cminst44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600153#include "cm33xx.h"
Paul Walmsleyb13159a2012-10-29 20:57:44 -0600154#include "prm.h"
Paul Walmsley139563a2012-10-21 01:01:10 -0600155#include "prm3xxx.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -0700156#include "prm44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600157#include "prm33xx.h"
Benoit Coussoneaac3292011-07-10 05:56:31 -0600158#include "prminst44xx.h"
Tony Lindgren8d9af882010-12-22 18:42:35 -0800159#include "mux.h"
Vishwanath BS51658822012-06-22 08:40:04 -0600160#include "pm.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300161
Paul Walmsley63c85232009-09-03 20:14:03 +0300162/* Name of the OMAP hwmod for the MPU */
Benoit Cousson5c2c0292010-05-20 12:31:10 -0600163#define MPU_INITIATOR_NAME "mpu"
Paul Walmsley63c85232009-09-03 20:14:03 +0300164
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600165/*
166 * Number of struct omap_hwmod_link records per struct
167 * omap_hwmod_ocp_if record (master->slave and slave->master)
168 */
169#define LINKS_PER_OCP_IF 2
170
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600171/**
172 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
173 * @enable_module: function to enable a module (via MODULEMODE)
174 * @disable_module: function to disable a module (via MODULEMODE)
175 *
176 * XXX Eventually this functionality will be hidden inside the PRM/CM
177 * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
178 * conditionals in this code.
179 */
180struct omap_hwmod_soc_ops {
181 void (*enable_module)(struct omap_hwmod *oh);
182 int (*disable_module)(struct omap_hwmod *oh);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -0600183 int (*wait_target_ready)(struct omap_hwmod *oh);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -0600184 int (*assert_hardreset)(struct omap_hwmod *oh,
185 struct omap_hwmod_rst_info *ohri);
186 int (*deassert_hardreset)(struct omap_hwmod *oh,
187 struct omap_hwmod_rst_info *ohri);
188 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
189 struct omap_hwmod_rst_info *ohri);
Kevin Hilman0a179ea2012-06-18 12:12:25 -0600190 int (*init_clkdm)(struct omap_hwmod *oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600191};
192
193/* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
194static struct omap_hwmod_soc_ops soc_ops;
195
Paul Walmsley63c85232009-09-03 20:14:03 +0300196/* omap_hwmod_list contains all registered struct omap_hwmods */
197static LIST_HEAD(omap_hwmod_list);
198
Paul Walmsley63c85232009-09-03 20:14:03 +0300199/* mpu_oh: used to add/remove MPU initiator from sleepdep list */
200static struct omap_hwmod *mpu_oh;
201
Vishwanath BS51658822012-06-22 08:40:04 -0600202/* io_chain_lock: used to serialize reconfigurations of the I/O chain */
203static DEFINE_SPINLOCK(io_chain_lock);
204
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600205/*
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600206 * linkspace: ptr to a buffer that struct omap_hwmod_link records are
207 * allocated from - used to reduce the number of small memory
208 * allocations, which has a significant impact on performance
209 */
210static struct omap_hwmod_link *linkspace;
211
212/*
213 * free_ls, max_ls: array indexes into linkspace; representing the
214 * next free struct omap_hwmod_link index, and the maximum number of
215 * struct omap_hwmod_link records allocated (respectively)
216 */
217static unsigned short free_ls, max_ls, ls_supp;
Paul Walmsley63c85232009-09-03 20:14:03 +0300218
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600219/* inited: set to true once the hwmod code is initialized */
220static bool inited;
221
Paul Walmsley63c85232009-09-03 20:14:03 +0300222/* Private functions */
223
224/**
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600225 * _fetch_next_ocp_if - return the next OCP interface in a list
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600226 * @p: ptr to a ptr to the list_head inside the ocp_if to return
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600227 * @i: pointer to the index of the element pointed to by @p in the list
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600228 *
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600229 * Return a pointer to the struct omap_hwmod_ocp_if record
230 * containing the struct list_head pointed to by @p, and increment
231 * @p such that a future call to this routine will return the next
232 * record.
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600233 */
234static struct omap_hwmod_ocp_if *_fetch_next_ocp_if(struct list_head **p,
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600235 int *i)
236{
237 struct omap_hwmod_ocp_if *oi;
238
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600239 oi = list_entry(*p, struct omap_hwmod_link, node)->ocp_if;
240 *p = (*p)->next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600241
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600242 *i = *i + 1;
243
244 return oi;
245}
246
247/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300248 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
249 * @oh: struct omap_hwmod *
250 *
251 * Load the current value of the hwmod OCP_SYSCONFIG register into the
252 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
253 * OCP_SYSCONFIG register or 0 upon success.
254 */
255static int _update_sysc_cache(struct omap_hwmod *oh)
256{
Paul Walmsley43b40992010-02-22 22:09:34 -0700257 if (!oh->class->sysc) {
258 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 +0300259 return -EINVAL;
260 }
261
262 /* XXX ensure module interface clock is up */
263
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -0700264 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300265
Paul Walmsley43b40992010-02-22 22:09:34 -0700266 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
Thara Gopinath883edfd2010-01-19 17:30:51 -0700267 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
Paul Walmsley63c85232009-09-03 20:14:03 +0300268
269 return 0;
270}
271
272/**
273 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
274 * @v: OCP_SYSCONFIG value to write
275 * @oh: struct omap_hwmod *
276 *
Paul Walmsley43b40992010-02-22 22:09:34 -0700277 * Write @v into the module class' OCP_SYSCONFIG register, if it has
278 * one. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +0300279 */
280static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
281{
Paul Walmsley43b40992010-02-22 22:09:34 -0700282 if (!oh->class->sysc) {
283 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 +0300284 return;
285 }
286
287 /* XXX ensure module interface clock is up */
288
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700289 /* Module might have lost context, always update cache and register */
290 oh->_sysc_cache = v;
291 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300292}
293
294/**
295 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
296 * @oh: struct omap_hwmod *
297 * @standbymode: MIDLEMODE field bits
298 * @v: pointer to register contents to modify
299 *
300 * Update the master standby mode bits in @v to be @standbymode for
301 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
302 * upon error or 0 upon success.
303 */
304static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
305 u32 *v)
306{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700307 u32 mstandby_mask;
308 u8 mstandby_shift;
309
Paul Walmsley43b40992010-02-22 22:09:34 -0700310 if (!oh->class->sysc ||
311 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300312 return -EINVAL;
313
Paul Walmsley43b40992010-02-22 22:09:34 -0700314 if (!oh->class->sysc->sysc_fields) {
315 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700316 return -EINVAL;
317 }
318
Paul Walmsley43b40992010-02-22 22:09:34 -0700319 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700320 mstandby_mask = (0x3 << mstandby_shift);
321
322 *v &= ~mstandby_mask;
323 *v |= __ffs(standbymode) << mstandby_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300324
325 return 0;
326}
327
328/**
329 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
330 * @oh: struct omap_hwmod *
331 * @idlemode: SIDLEMODE field bits
332 * @v: pointer to register contents to modify
333 *
334 * Update the slave idle mode bits in @v to be @idlemode for the @oh
335 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
336 * or 0 upon success.
337 */
338static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
339{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700340 u32 sidle_mask;
341 u8 sidle_shift;
342
Paul Walmsley43b40992010-02-22 22:09:34 -0700343 if (!oh->class->sysc ||
344 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300345 return -EINVAL;
346
Paul Walmsley43b40992010-02-22 22:09:34 -0700347 if (!oh->class->sysc->sysc_fields) {
348 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700349 return -EINVAL;
350 }
351
Paul Walmsley43b40992010-02-22 22:09:34 -0700352 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700353 sidle_mask = (0x3 << sidle_shift);
354
355 *v &= ~sidle_mask;
356 *v |= __ffs(idlemode) << sidle_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300357
358 return 0;
359}
360
361/**
362 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
363 * @oh: struct omap_hwmod *
364 * @clockact: CLOCKACTIVITY field bits
365 * @v: pointer to register contents to modify
366 *
367 * Update the clockactivity mode bits in @v to be @clockact for the
368 * @oh hwmod. Used for additional powersaving on some modules. Does
369 * not write to the hardware. Returns -EINVAL upon error or 0 upon
370 * success.
371 */
372static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
373{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700374 u32 clkact_mask;
375 u8 clkact_shift;
376
Paul Walmsley43b40992010-02-22 22:09:34 -0700377 if (!oh->class->sysc ||
378 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
Paul Walmsley63c85232009-09-03 20:14:03 +0300379 return -EINVAL;
380
Paul Walmsley43b40992010-02-22 22:09:34 -0700381 if (!oh->class->sysc->sysc_fields) {
382 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700383 return -EINVAL;
384 }
385
Paul Walmsley43b40992010-02-22 22:09:34 -0700386 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700387 clkact_mask = (0x3 << clkact_shift);
388
389 *v &= ~clkact_mask;
390 *v |= clockact << clkact_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300391
392 return 0;
393}
394
395/**
396 * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
397 * @oh: struct omap_hwmod *
398 * @v: pointer to register contents to modify
399 *
400 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
401 * error or 0 upon success.
402 */
403static int _set_softreset(struct omap_hwmod *oh, u32 *v)
404{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700405 u32 softrst_mask;
406
Paul Walmsley43b40992010-02-22 22:09:34 -0700407 if (!oh->class->sysc ||
408 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley63c85232009-09-03 20:14:03 +0300409 return -EINVAL;
410
Paul Walmsley43b40992010-02-22 22:09:34 -0700411 if (!oh->class->sysc->sysc_fields) {
412 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700413 return -EINVAL;
414 }
415
Paul Walmsley43b40992010-02-22 22:09:34 -0700416 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700417
418 *v |= softrst_mask;
Paul Walmsley63c85232009-09-03 20:14:03 +0300419
420 return 0;
421}
422
423/**
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -0600424 * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
425 * @oh: struct omap_hwmod *
426 *
427 * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
428 * of some modules. When the DMA must perform read/write accesses, the
429 * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
430 * for power management, software must set the DMADISABLE bit back to 1.
431 *
432 * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
433 * error or 0 upon success.
434 */
435static int _set_dmadisable(struct omap_hwmod *oh)
436{
437 u32 v;
438 u32 dmadisable_mask;
439
440 if (!oh->class->sysc ||
441 !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
442 return -EINVAL;
443
444 if (!oh->class->sysc->sysc_fields) {
445 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
446 return -EINVAL;
447 }
448
449 /* clocks must be on for this operation */
450 if (oh->_state != _HWMOD_STATE_ENABLED) {
451 pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
452 return -EINVAL;
453 }
454
455 pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
456
457 v = oh->_sysc_cache;
458 dmadisable_mask =
459 (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
460 v |= dmadisable_mask;
461 _write_sysconfig(v, oh);
462
463 return 0;
464}
465
466/**
Paul Walmsley726072e2009-12-08 16:34:15 -0700467 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
468 * @oh: struct omap_hwmod *
469 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
470 * @v: pointer to register contents to modify
471 *
472 * Update the module autoidle bit in @v to be @autoidle for the @oh
473 * hwmod. The autoidle bit controls whether the module can gate
474 * internal clocks automatically when it isn't doing anything; the
475 * exact function of this bit varies on a per-module basis. This
476 * function does not write to the hardware. Returns -EINVAL upon
477 * error or 0 upon success.
478 */
479static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
480 u32 *v)
481{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700482 u32 autoidle_mask;
483 u8 autoidle_shift;
484
Paul Walmsley43b40992010-02-22 22:09:34 -0700485 if (!oh->class->sysc ||
486 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
Paul Walmsley726072e2009-12-08 16:34:15 -0700487 return -EINVAL;
488
Paul Walmsley43b40992010-02-22 22:09:34 -0700489 if (!oh->class->sysc->sysc_fields) {
490 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700491 return -EINVAL;
492 }
493
Paul Walmsley43b40992010-02-22 22:09:34 -0700494 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
Tarun Kanti DebBarma8985b632011-03-03 14:22:46 -0700495 autoidle_mask = (0x1 << autoidle_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700496
497 *v &= ~autoidle_mask;
498 *v |= autoidle << autoidle_shift;
Paul Walmsley726072e2009-12-08 16:34:15 -0700499
500 return 0;
501}
502
503/**
Govindraj Receec002011-12-16 14:36:58 -0700504 * _set_idle_ioring_wakeup - enable/disable IO pad wakeup on hwmod idle for mux
505 * @oh: struct omap_hwmod *
506 * @set_wake: bool value indicating to set (true) or clear (false) wakeup enable
507 *
508 * Set or clear the I/O pad wakeup flag in the mux entries for the
509 * hwmod @oh. This function changes the @oh->mux->pads_dynamic array
510 * in memory. If the hwmod is currently idled, and the new idle
511 * values don't match the previous ones, this function will also
512 * update the SCM PADCTRL registers. Otherwise, if the hwmod is not
513 * currently idled, this function won't touch the hardware: the new
514 * mux settings are written to the SCM PADCTRL registers when the
515 * hwmod is idled. No return value.
516 */
517static void _set_idle_ioring_wakeup(struct omap_hwmod *oh, bool set_wake)
518{
519 struct omap_device_pad *pad;
520 bool change = false;
521 u16 prev_idle;
522 int j;
523
524 if (!oh->mux || !oh->mux->enabled)
525 return;
526
527 for (j = 0; j < oh->mux->nr_pads_dynamic; j++) {
528 pad = oh->mux->pads_dynamic[j];
529
530 if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP))
531 continue;
532
533 prev_idle = pad->idle;
534
535 if (set_wake)
536 pad->idle |= OMAP_WAKEUP_EN;
537 else
538 pad->idle &= ~OMAP_WAKEUP_EN;
539
540 if (prev_idle != pad->idle)
541 change = true;
542 }
543
544 if (change && oh->_state == _HWMOD_STATE_IDLE)
545 omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
546}
547
548/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300549 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
550 * @oh: struct omap_hwmod *
551 *
552 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
553 * upon error or 0 upon success.
554 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700555static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300556{
Paul Walmsley43b40992010-02-22 22:09:34 -0700557 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700558 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200559 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
560 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300561 return -EINVAL;
562
Paul Walmsley43b40992010-02-22 22:09:34 -0700563 if (!oh->class->sysc->sysc_fields) {
564 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700565 return -EINVAL;
566 }
567
Benoit Cousson1fe74112011-07-01 22:54:03 +0200568 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
569 *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300570
Benoit Cousson86009eb2010-12-21 21:31:28 -0700571 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
572 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200573 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
574 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700575
Paul Walmsley63c85232009-09-03 20:14:03 +0300576 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
577
578 oh->_int_flags |= _HWMOD_WAKEUP_ENABLED;
579
580 return 0;
581}
582
583/**
584 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
585 * @oh: struct omap_hwmod *
586 *
587 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
588 * upon error or 0 upon success.
589 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700590static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300591{
Paul Walmsley43b40992010-02-22 22:09:34 -0700592 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700593 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200594 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
595 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300596 return -EINVAL;
597
Paul Walmsley43b40992010-02-22 22:09:34 -0700598 if (!oh->class->sysc->sysc_fields) {
599 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700600 return -EINVAL;
601 }
602
Benoit Cousson1fe74112011-07-01 22:54:03 +0200603 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
604 *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
Paul Walmsley63c85232009-09-03 20:14:03 +0300605
Benoit Cousson86009eb2010-12-21 21:31:28 -0700606 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
607 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200608 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
Djamil Elaidi561038f2012-06-17 11:57:51 -0600609 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700610
Paul Walmsley63c85232009-09-03 20:14:03 +0300611 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
612
613 oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED;
614
615 return 0;
616}
617
618/**
619 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
620 * @oh: struct omap_hwmod *
621 *
622 * Prevent the hardware module @oh from entering idle while the
623 * hardare module initiator @init_oh is active. Useful when a module
624 * will be accessed by a particular initiator (e.g., if a module will
625 * be accessed by the IVA, there should be a sleepdep between the IVA
626 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700627 * mode. If the clockdomain is marked as not needing autodeps, return
628 * 0 without doing anything. Otherwise, returns -EINVAL upon error or
629 * passes along clkdm_add_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300630 */
631static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
632{
633 if (!oh->_clk)
634 return -EINVAL;
635
Paul Walmsley570b54c2011-03-10 03:50:09 -0700636 if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
637 return 0;
638
Paul Walmsley55ed9692010-01-26 20:12:59 -0700639 return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300640}
641
642/**
643 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
644 * @oh: struct omap_hwmod *
645 *
646 * Allow the hardware module @oh to enter idle while the hardare
647 * module initiator @init_oh is active. Useful when a module will not
648 * be accessed by a particular initiator (e.g., if a module will not
649 * be accessed by the IVA, there should be no sleepdep between the IVA
650 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700651 * mode. If the clockdomain is marked as not needing autodeps, return
652 * 0 without doing anything. Returns -EINVAL upon error or passes
653 * along clkdm_del_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300654 */
655static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
656{
657 if (!oh->_clk)
658 return -EINVAL;
659
Paul Walmsley570b54c2011-03-10 03:50:09 -0700660 if (oh->_clk->clkdm && oh->_clk->clkdm->flags & CLKDM_NO_AUTODEPS)
661 return 0;
662
Paul Walmsley55ed9692010-01-26 20:12:59 -0700663 return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300664}
665
666/**
667 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
668 * @oh: struct omap_hwmod *
669 *
670 * Called from _init_clocks(). Populates the @oh _clk (main
671 * functional clock pointer) if a main_clk is present. Returns 0 on
672 * success or -EINVAL on error.
673 */
674static int _init_main_clk(struct omap_hwmod *oh)
675{
Paul Walmsley63c85232009-09-03 20:14:03 +0300676 int ret = 0;
677
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700678 if (!oh->main_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300679 return 0;
680
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600681 oh->_clk = clk_get(NULL, oh->main_clk);
682 if (IS_ERR(oh->_clk)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600683 pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n",
684 oh->name, oh->main_clk);
Benoit Cousson63403382010-05-20 12:31:10 -0600685 return -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600686 }
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600687 /*
688 * HACK: This needs a re-visit once clk_prepare() is implemented
689 * to do something meaningful. Today its just a no-op.
690 * If clk_prepare() is used at some point to do things like
691 * voltage scaling etc, then this would have to be moved to
692 * some point where subsystems like i2c and pmic become
693 * available.
694 */
695 clk_prepare(oh->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300696
Benoit Cousson63403382010-05-20 12:31:10 -0600697 if (!oh->_clk->clkdm)
Paul Walmsley3bb05db2012-09-23 17:28:18 -0600698 pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600699 oh->name, oh->main_clk);
Kevin Hilman81d7c6f2009-12-08 16:34:24 -0700700
Paul Walmsley63c85232009-09-03 20:14:03 +0300701 return ret;
702}
703
704/**
Paul Walmsley887adea2010-07-26 16:34:33 -0600705 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
Paul Walmsley63c85232009-09-03 20:14:03 +0300706 * @oh: struct omap_hwmod *
707 *
708 * Called from _init_clocks(). Populates the @oh OCP slave interface
709 * clock pointers. Returns 0 on success or -EINVAL on error.
710 */
711static int _init_interface_clks(struct omap_hwmod *oh)
712{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600713 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600714 struct list_head *p;
Paul Walmsley63c85232009-09-03 20:14:03 +0300715 struct clk *c;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600716 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300717 int ret = 0;
718
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600719 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600720
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600721 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600722 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700723 if (!os->clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300724 continue;
725
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600726 c = clk_get(NULL, os->clk);
727 if (IS_ERR(c)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600728 pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
729 oh->name, os->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300730 ret = -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600731 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300732 os->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600733 /*
734 * HACK: This needs a re-visit once clk_prepare() is implemented
735 * to do something meaningful. Today its just a no-op.
736 * If clk_prepare() is used at some point to do things like
737 * voltage scaling etc, then this would have to be moved to
738 * some point where subsystems like i2c and pmic become
739 * available.
740 */
741 clk_prepare(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300742 }
743
744 return ret;
745}
746
747/**
748 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
749 * @oh: struct omap_hwmod *
750 *
751 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
752 * clock pointers. Returns 0 on success or -EINVAL on error.
753 */
754static int _init_opt_clks(struct omap_hwmod *oh)
755{
756 struct omap_hwmod_opt_clk *oc;
757 struct clk *c;
758 int i;
759 int ret = 0;
760
761 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600762 c = clk_get(NULL, oc->clk);
763 if (IS_ERR(c)) {
Benoit Cousson20383d82010-05-20 12:31:09 -0600764 pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
765 oh->name, oc->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300766 ret = -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600767 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300768 oc->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600769 /*
770 * HACK: This needs a re-visit once clk_prepare() is implemented
771 * to do something meaningful. Today its just a no-op.
772 * If clk_prepare() is used at some point to do things like
773 * voltage scaling etc, then this would have to be moved to
774 * some point where subsystems like i2c and pmic become
775 * available.
776 */
777 clk_prepare(oc->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300778 }
779
780 return ret;
781}
782
783/**
784 * _enable_clocks - enable hwmod main clock and interface clocks
785 * @oh: struct omap_hwmod *
786 *
787 * Enables all clocks necessary for register reads and writes to succeed
788 * on the hwmod @oh. Returns 0.
789 */
790static int _enable_clocks(struct omap_hwmod *oh)
791{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600792 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600793 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600794 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300795
796 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
797
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600798 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300799 clk_enable(oh->_clk);
800
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600801 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600802
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600803 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600804 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +0300805
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600806 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
807 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300808 }
809
810 /* The opt clocks are controlled by the device driver. */
811
812 return 0;
813}
814
815/**
816 * _disable_clocks - disable hwmod main clock and interface clocks
817 * @oh: struct omap_hwmod *
818 *
819 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
820 */
821static int _disable_clocks(struct omap_hwmod *oh)
822{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600823 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600824 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600825 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +0300826
827 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
828
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600829 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300830 clk_disable(oh->_clk);
831
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600832 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600833
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600834 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -0600835 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +0300836
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600837 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
838 clk_disable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300839 }
840
841 /* The opt clocks are controlled by the device driver. */
842
843 return 0;
844}
845
Benoit Cousson96835af2010-09-21 18:57:58 +0200846static void _enable_optional_clocks(struct omap_hwmod *oh)
847{
848 struct omap_hwmod_opt_clk *oc;
849 int i;
850
851 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
852
853 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
854 if (oc->_clk) {
855 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600856 __clk_get_name(oc->_clk));
Benoit Cousson96835af2010-09-21 18:57:58 +0200857 clk_enable(oc->_clk);
858 }
859}
860
861static void _disable_optional_clocks(struct omap_hwmod *oh)
862{
863 struct omap_hwmod_opt_clk *oc;
864 int i;
865
866 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
867
868 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
869 if (oc->_clk) {
870 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600871 __clk_get_name(oc->_clk));
Benoit Cousson96835af2010-09-21 18:57:58 +0200872 clk_disable(oc->_clk);
873 }
874}
875
Paul Walmsley63c85232009-09-03 20:14:03 +0300876/**
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600877 * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
Benoit Cousson45c38252011-07-10 05:56:33 -0600878 * @oh: struct omap_hwmod *
879 *
880 * Enables the PRCM module mode related to the hwmod @oh.
881 * No return value.
882 */
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600883static void _omap4_enable_module(struct omap_hwmod *oh)
Benoit Cousson45c38252011-07-10 05:56:33 -0600884{
Benoit Cousson45c38252011-07-10 05:56:33 -0600885 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
886 return;
887
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600888 pr_debug("omap_hwmod: %s: %s: %d\n",
889 oh->name, __func__, oh->prcm.omap4.modulemode);
Benoit Cousson45c38252011-07-10 05:56:33 -0600890
891 omap4_cminst_module_enable(oh->prcm.omap4.modulemode,
892 oh->clkdm->prcm_partition,
893 oh->clkdm->cm_inst,
894 oh->clkdm->clkdm_offs,
895 oh->prcm.omap4.clkctrl_offs);
896}
897
898/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600899 * _am33xx_enable_module - enable CLKCTRL modulemode on AM33XX
900 * @oh: struct omap_hwmod *
901 *
902 * Enables the PRCM module mode related to the hwmod @oh.
903 * No return value.
904 */
905static void _am33xx_enable_module(struct omap_hwmod *oh)
906{
907 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
908 return;
909
910 pr_debug("omap_hwmod: %s: %s: %d\n",
911 oh->name, __func__, oh->prcm.omap4.modulemode);
912
913 am33xx_cm_module_enable(oh->prcm.omap4.modulemode, oh->clkdm->cm_inst,
914 oh->clkdm->clkdm_offs,
915 oh->prcm.omap4.clkctrl_offs);
916}
917
918/**
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800919 * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
920 * @oh: struct omap_hwmod *
921 *
922 * Wait for a module @oh to enter slave idle. Returns 0 if the module
923 * does not have an IDLEST bit or if the module successfully enters
924 * slave idle; otherwise, pass along the return value of the
925 * appropriate *_cm*_wait_module_idle() function.
926 */
927static int _omap4_wait_target_disable(struct omap_hwmod *oh)
928{
Paul Walmsley2b026d12012-09-23 17:28:18 -0600929 if (!oh)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800930 return -EINVAL;
931
Paul Walmsley2b026d12012-09-23 17:28:18 -0600932 if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800933 return 0;
934
935 if (oh->flags & HWMOD_NO_IDLEST)
936 return 0;
937
938 return omap4_cminst_wait_module_idle(oh->clkdm->prcm_partition,
939 oh->clkdm->cm_inst,
940 oh->clkdm->clkdm_offs,
941 oh->prcm.omap4.clkctrl_offs);
942}
943
944/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600945 * _am33xx_wait_target_disable - wait for a module to be disabled on AM33XX
946 * @oh: struct omap_hwmod *
947 *
948 * Wait for a module @oh to enter slave idle. Returns 0 if the module
949 * does not have an IDLEST bit or if the module successfully enters
950 * slave idle; otherwise, pass along the return value of the
951 * appropriate *_cm*_wait_module_idle() function.
952 */
953static int _am33xx_wait_target_disable(struct omap_hwmod *oh)
954{
955 if (!oh)
956 return -EINVAL;
957
958 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
959 return 0;
960
961 if (oh->flags & HWMOD_NO_IDLEST)
962 return 0;
963
964 return am33xx_cm_wait_module_idle(oh->clkdm->cm_inst,
965 oh->clkdm->clkdm_offs,
966 oh->prcm.omap4.clkctrl_offs);
967}
968
969/**
Paul Walmsley212738a2011-07-09 19:14:06 -0600970 * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
971 * @oh: struct omap_hwmod *oh
972 *
973 * Count and return the number of MPU IRQs associated with the hwmod
974 * @oh. Used to allocate struct resource data. Returns 0 if @oh is
975 * NULL.
976 */
977static int _count_mpu_irqs(struct omap_hwmod *oh)
978{
979 struct omap_hwmod_irq_info *ohii;
980 int i = 0;
981
982 if (!oh || !oh->mpu_irqs)
983 return 0;
984
985 do {
986 ohii = &oh->mpu_irqs[i++];
987 } while (ohii->irq != -1);
988
sricharancc1b0762011-11-23 14:35:07 -0800989 return i-1;
Paul Walmsley212738a2011-07-09 19:14:06 -0600990}
991
992/**
Paul Walmsleybc614952011-07-09 19:14:07 -0600993 * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
994 * @oh: struct omap_hwmod *oh
995 *
996 * Count and return the number of SDMA request lines associated with
997 * the hwmod @oh. Used to allocate struct resource data. Returns 0
998 * if @oh is NULL.
999 */
1000static int _count_sdma_reqs(struct omap_hwmod *oh)
1001{
1002 struct omap_hwmod_dma_info *ohdi;
1003 int i = 0;
1004
1005 if (!oh || !oh->sdma_reqs)
1006 return 0;
1007
1008 do {
1009 ohdi = &oh->sdma_reqs[i++];
1010 } while (ohdi->dma_req != -1);
1011
sricharancc1b0762011-11-23 14:35:07 -08001012 return i-1;
Paul Walmsleybc614952011-07-09 19:14:07 -06001013}
1014
1015/**
Paul Walmsley78183f32011-07-09 19:14:05 -06001016 * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
1017 * @oh: struct omap_hwmod *oh
1018 *
1019 * Count and return the number of address space ranges associated with
1020 * the hwmod @oh. Used to allocate struct resource data. Returns 0
1021 * if @oh is NULL.
1022 */
1023static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
1024{
1025 struct omap_hwmod_addr_space *mem;
1026 int i = 0;
1027
1028 if (!os || !os->addr)
1029 return 0;
1030
1031 do {
1032 mem = &os->addr[i++];
1033 } while (mem->pa_start != mem->pa_end);
1034
sricharancc1b0762011-11-23 14:35:07 -08001035 return i-1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001036}
1037
1038/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001039 * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
1040 * @oh: struct omap_hwmod * to operate on
1041 * @name: pointer to the name of the MPU interrupt number to fetch (optional)
1042 * @irq: pointer to an unsigned int to store the MPU IRQ number to
1043 *
1044 * Retrieve a MPU hardware IRQ line number named by @name associated
1045 * with the IP block pointed to by @oh. The IRQ number will be filled
1046 * into the address pointed to by @dma. When @name is non-null, the
1047 * IRQ line number associated with the named entry will be returned.
1048 * If @name is null, the first matching entry will be returned. Data
1049 * order is not meaningful in hwmod data, so callers are strongly
1050 * encouraged to use a non-null @name whenever possible to avoid
1051 * unpredictable effects if hwmod data is later added that causes data
1052 * ordering to change. Returns 0 upon success or a negative error
1053 * code upon error.
1054 */
1055static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
1056 unsigned int *irq)
1057{
1058 int i;
1059 bool found = false;
1060
1061 if (!oh->mpu_irqs)
1062 return -ENOENT;
1063
1064 i = 0;
1065 while (oh->mpu_irqs[i].irq != -1) {
1066 if (name == oh->mpu_irqs[i].name ||
1067 !strcmp(name, oh->mpu_irqs[i].name)) {
1068 found = true;
1069 break;
1070 }
1071 i++;
1072 }
1073
1074 if (!found)
1075 return -ENOENT;
1076
1077 *irq = oh->mpu_irqs[i].irq;
1078
1079 return 0;
1080}
1081
1082/**
1083 * _get_sdma_req_by_name - fetch SDMA request line ID by name
1084 * @oh: struct omap_hwmod * to operate on
1085 * @name: pointer to the name of the SDMA request line to fetch (optional)
1086 * @dma: pointer to an unsigned int to store the request line ID to
1087 *
1088 * Retrieve an SDMA request line ID named by @name on the IP block
1089 * pointed to by @oh. The ID will be filled into the address pointed
1090 * to by @dma. When @name is non-null, the request line ID associated
1091 * with the named entry will be returned. If @name is null, the first
1092 * matching entry will be returned. Data order is not meaningful in
1093 * hwmod data, so callers are strongly encouraged to use a non-null
1094 * @name whenever possible to avoid unpredictable effects if hwmod
1095 * data is later added that causes data ordering to change. Returns 0
1096 * upon success or a negative error code upon error.
1097 */
1098static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
1099 unsigned int *dma)
1100{
1101 int i;
1102 bool found = false;
1103
1104 if (!oh->sdma_reqs)
1105 return -ENOENT;
1106
1107 i = 0;
1108 while (oh->sdma_reqs[i].dma_req != -1) {
1109 if (name == oh->sdma_reqs[i].name ||
1110 !strcmp(name, oh->sdma_reqs[i].name)) {
1111 found = true;
1112 break;
1113 }
1114 i++;
1115 }
1116
1117 if (!found)
1118 return -ENOENT;
1119
1120 *dma = oh->sdma_reqs[i].dma_req;
1121
1122 return 0;
1123}
1124
1125/**
1126 * _get_addr_space_by_name - fetch address space start & end by name
1127 * @oh: struct omap_hwmod * to operate on
1128 * @name: pointer to the name of the address space to fetch (optional)
1129 * @pa_start: pointer to a u32 to store the starting address to
1130 * @pa_end: pointer to a u32 to store the ending address to
1131 *
1132 * Retrieve address space start and end addresses for the IP block
1133 * pointed to by @oh. The data will be filled into the addresses
1134 * pointed to by @pa_start and @pa_end. When @name is non-null, the
1135 * address space data associated with the named entry will be
1136 * returned. If @name is null, the first matching entry will be
1137 * returned. Data order is not meaningful in hwmod data, so callers
1138 * are strongly encouraged to use a non-null @name whenever possible
1139 * to avoid unpredictable effects if hwmod data is later added that
1140 * causes data ordering to change. Returns 0 upon success or a
1141 * negative error code upon error.
1142 */
1143static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1144 u32 *pa_start, u32 *pa_end)
1145{
1146 int i, j;
1147 struct omap_hwmod_ocp_if *os;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001148 struct list_head *p = NULL;
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001149 bool found = false;
1150
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001151 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001152
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001153 i = 0;
1154 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001155 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001156
1157 if (!os->addr)
1158 return -ENOENT;
1159
1160 j = 0;
1161 while (os->addr[j].pa_start != os->addr[j].pa_end) {
1162 if (name == os->addr[j].name ||
1163 !strcmp(name, os->addr[j].name)) {
1164 found = true;
1165 break;
1166 }
1167 j++;
1168 }
1169
1170 if (found)
1171 break;
1172 }
1173
1174 if (!found)
1175 return -ENOENT;
1176
1177 *pa_start = os->addr[j].pa_start;
1178 *pa_end = os->addr[j].pa_end;
1179
1180 return 0;
1181}
1182
1183/**
Paul Walmsley24dbc212012-04-19 04:04:29 -06001184 * _save_mpu_port_index - find and save the index to @oh's MPU port
Paul Walmsley63c85232009-09-03 20:14:03 +03001185 * @oh: struct omap_hwmod *
1186 *
Paul Walmsley24dbc212012-04-19 04:04:29 -06001187 * Determines the array index of the OCP slave port that the MPU uses
1188 * to address the device, and saves it into the struct omap_hwmod.
1189 * Intended to be called during hwmod registration only. No return
1190 * value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001191 */
Paul Walmsley24dbc212012-04-19 04:04:29 -06001192static void __init _save_mpu_port_index(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001193{
Paul Walmsley24dbc212012-04-19 04:04:29 -06001194 struct omap_hwmod_ocp_if *os = NULL;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001195 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001196 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001197
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001198 if (!oh)
Paul Walmsley24dbc212012-04-19 04:04:29 -06001199 return;
1200
1201 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001202
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001203 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001204
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001205 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001206 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley63c85232009-09-03 20:14:03 +03001207 if (os->user & OCP_USER_MPU) {
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001208 oh->_mpu_port = os;
Paul Walmsley24dbc212012-04-19 04:04:29 -06001209 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001210 break;
1211 }
1212 }
1213
Paul Walmsley24dbc212012-04-19 04:04:29 -06001214 return;
Paul Walmsley63c85232009-09-03 20:14:03 +03001215}
1216
1217/**
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001218 * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
1219 * @oh: struct omap_hwmod *
1220 *
1221 * Given a pointer to a struct omap_hwmod record @oh, return a pointer
1222 * to the struct omap_hwmod_ocp_if record that is used by the MPU to
1223 * communicate with the IP block. This interface need not be directly
1224 * connected to the MPU (and almost certainly is not), but is directly
1225 * connected to the IP block represented by @oh. Returns a pointer
1226 * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
1227 * error or if there does not appear to be a path from the MPU to this
1228 * IP block.
1229 */
1230static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
1231{
1232 if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
1233 return NULL;
1234
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001235 return oh->_mpu_port;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001236};
1237
1238/**
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001239 * _find_mpu_rt_addr_space - return MPU register target address space for @oh
Paul Walmsley63c85232009-09-03 20:14:03 +03001240 * @oh: struct omap_hwmod *
1241 *
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001242 * Returns a pointer to the struct omap_hwmod_addr_space record representing
1243 * the register target MPU address space; or returns NULL upon error.
Paul Walmsley63c85232009-09-03 20:14:03 +03001244 */
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001245static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001246{
1247 struct omap_hwmod_ocp_if *os;
1248 struct omap_hwmod_addr_space *mem;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001249 int found = 0, i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001250
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001251 os = _find_mpu_rt_port(oh);
Paul Walmsley24dbc212012-04-19 04:04:29 -06001252 if (!os || !os->addr)
Paul Walmsley78183f32011-07-09 19:14:05 -06001253 return NULL;
1254
1255 do {
1256 mem = &os->addr[i++];
1257 if (mem->flags & ADDR_TYPE_RT)
Paul Walmsley63c85232009-09-03 20:14:03 +03001258 found = 1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001259 } while (!found && mem->pa_start != mem->pa_end);
Paul Walmsley63c85232009-09-03 20:14:03 +03001260
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001261 return (found) ? mem : NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +03001262}
1263
1264/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001265 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001266 * @oh: struct omap_hwmod *
1267 *
Paul Walmsley006c7f12012-07-04 05:22:53 -06001268 * Ensure that the OCP_SYSCONFIG register for the IP block represented
1269 * by @oh is set to indicate to the PRCM that the IP block is active.
1270 * Usually this means placing the module into smart-idle mode and
1271 * smart-standby, but if there is a bug in the automatic idle handling
1272 * for the IP block, it may need to be placed into the force-idle or
1273 * no-idle variants of these modes. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001274 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001275static void _enable_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001276{
Paul Walmsley43b40992010-02-22 22:09:34 -07001277 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001278 u32 v;
Paul Walmsley006c7f12012-07-04 05:22:53 -06001279 bool clkdm_act;
Paul Walmsley63c85232009-09-03 20:14:03 +03001280
Paul Walmsley43b40992010-02-22 22:09:34 -07001281 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001282 return;
1283
1284 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001285 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001286
Paul Walmsley43b40992010-02-22 22:09:34 -07001287 if (sf & SYSC_HAS_SIDLEMODE) {
Paul Walmsley006c7f12012-07-04 05:22:53 -06001288 clkdm_act = ((oh->clkdm &&
1289 oh->clkdm->flags & CLKDM_ACTIVE_WITH_MPU) ||
1290 (oh->_clk && oh->_clk->clkdm &&
1291 oh->_clk->clkdm->flags & CLKDM_ACTIVE_WITH_MPU));
1292 if (clkdm_act && !(oh->class->sysc->idlemodes &
1293 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1294 idlemode = HWMOD_IDLEMODE_FORCE;
1295 else
1296 idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ?
1297 HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART;
Paul Walmsley63c85232009-09-03 20:14:03 +03001298 _set_slave_idlemode(oh, idlemode, &v);
1299 }
1300
Paul Walmsley43b40992010-02-22 22:09:34 -07001301 if (sf & SYSC_HAS_MIDLEMODE) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001302 if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
1303 idlemode = HWMOD_IDLEMODE_NO;
1304 } else {
1305 if (sf & SYSC_HAS_ENAWAKEUP)
1306 _enable_wakeup(oh, &v);
1307 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1308 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1309 else
1310 idlemode = HWMOD_IDLEMODE_SMART;
1311 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001312 _set_master_standbymode(oh, idlemode, &v);
1313 }
1314
Paul Walmsleya16b1f72009-12-08 16:34:17 -07001315 /*
1316 * XXX The clock framework should handle this, by
1317 * calling into this code. But this must wait until the
1318 * clock structures are tagged with omap_hwmod entries
1319 */
Paul Walmsley43b40992010-02-22 22:09:34 -07001320 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1321 (sf & SYSC_HAS_CLOCKACTIVITY))
1322 _set_clockactivity(oh, oh->class->sysc->clockact, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001323
Rajendra Nayak9980ce52010-09-21 19:58:30 +05301324 /* If slave is in SMARTIDLE, also enable wakeup */
1325 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07001326 _enable_wakeup(oh, &v);
1327
1328 _write_sysconfig(v, oh);
Hema HK78f26e82010-09-24 10:23:19 -06001329
1330 /*
1331 * Set the autoidle bit only after setting the smartidle bit
1332 * Setting this will not have any impact on the other modules.
1333 */
1334 if (sf & SYSC_HAS_AUTOIDLE) {
1335 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
1336 0 : 1;
1337 _set_module_autoidle(oh, idlemode, &v);
1338 _write_sysconfig(v, oh);
1339 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001340}
1341
1342/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001343 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001344 * @oh: struct omap_hwmod *
1345 *
1346 * If module is marked as SWSUP_SIDLE, force the module into slave
1347 * idle; otherwise, configure it for smart-idle. If module is marked
1348 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
1349 * configure it for smart-standby. No return value.
1350 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001351static void _idle_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001352{
Paul Walmsley43b40992010-02-22 22:09:34 -07001353 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001354 u32 v;
1355
Paul Walmsley43b40992010-02-22 22:09:34 -07001356 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001357 return;
1358
1359 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001360 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001361
Paul Walmsley43b40992010-02-22 22:09:34 -07001362 if (sf & SYSC_HAS_SIDLEMODE) {
Paul Walmsley006c7f12012-07-04 05:22:53 -06001363 /* XXX What about HWMOD_IDLEMODE_SMART_WKUP? */
1364 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1365 !(oh->class->sysc->idlemodes &
1366 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1367 idlemode = HWMOD_IDLEMODE_FORCE;
1368 else
1369 idlemode = HWMOD_IDLEMODE_SMART;
Paul Walmsley63c85232009-09-03 20:14:03 +03001370 _set_slave_idlemode(oh, idlemode, &v);
1371 }
1372
Paul Walmsley43b40992010-02-22 22:09:34 -07001373 if (sf & SYSC_HAS_MIDLEMODE) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001374 if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
1375 idlemode = HWMOD_IDLEMODE_FORCE;
1376 } else {
1377 if (sf & SYSC_HAS_ENAWAKEUP)
1378 _enable_wakeup(oh, &v);
1379 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1380 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1381 else
1382 idlemode = HWMOD_IDLEMODE_SMART;
1383 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001384 _set_master_standbymode(oh, idlemode, &v);
1385 }
1386
Benoit Cousson86009eb2010-12-21 21:31:28 -07001387 /* If slave is in SMARTIDLE, also enable wakeup */
1388 if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE))
1389 _enable_wakeup(oh, &v);
1390
Paul Walmsley63c85232009-09-03 20:14:03 +03001391 _write_sysconfig(v, oh);
1392}
1393
1394/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001395 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001396 * @oh: struct omap_hwmod *
1397 *
1398 * Force the module into slave idle and master suspend. No return
1399 * value.
1400 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001401static void _shutdown_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001402{
1403 u32 v;
Paul Walmsley43b40992010-02-22 22:09:34 -07001404 u8 sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001405
Paul Walmsley43b40992010-02-22 22:09:34 -07001406 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001407 return;
1408
1409 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001410 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001411
Paul Walmsley43b40992010-02-22 22:09:34 -07001412 if (sf & SYSC_HAS_SIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001413 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
1414
Paul Walmsley43b40992010-02-22 22:09:34 -07001415 if (sf & SYSC_HAS_MIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001416 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
1417
Paul Walmsley43b40992010-02-22 22:09:34 -07001418 if (sf & SYSC_HAS_AUTOIDLE)
Paul Walmsley726072e2009-12-08 16:34:15 -07001419 _set_module_autoidle(oh, 1, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001420
1421 _write_sysconfig(v, oh);
1422}
1423
1424/**
1425 * _lookup - find an omap_hwmod by name
1426 * @name: find an omap_hwmod by name
1427 *
1428 * Return a pointer to an omap_hwmod by name, or NULL if not found.
Paul Walmsley63c85232009-09-03 20:14:03 +03001429 */
1430static struct omap_hwmod *_lookup(const char *name)
1431{
1432 struct omap_hwmod *oh, *temp_oh;
1433
1434 oh = NULL;
1435
1436 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1437 if (!strcmp(name, temp_oh->name)) {
1438 oh = temp_oh;
1439 break;
1440 }
1441 }
1442
1443 return oh;
1444}
Paul Walmsley868c1572012-06-19 15:01:02 -06001445
Benoit Cousson6ae76992011-07-10 05:56:30 -06001446/**
1447 * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
1448 * @oh: struct omap_hwmod *
1449 *
1450 * Convert a clockdomain name stored in a struct omap_hwmod into a
1451 * clockdomain pointer, and save it into the struct omap_hwmod.
Paul Walmsley868c1572012-06-19 15:01:02 -06001452 * Return -EINVAL if the clkdm_name lookup failed.
Benoit Cousson6ae76992011-07-10 05:56:30 -06001453 */
1454static int _init_clkdm(struct omap_hwmod *oh)
1455{
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001456 if (!oh->clkdm_name) {
1457 pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
Benoit Cousson6ae76992011-07-10 05:56:30 -06001458 return 0;
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001459 }
Benoit Cousson6ae76992011-07-10 05:56:30 -06001460
Benoit Cousson6ae76992011-07-10 05:56:30 -06001461 oh->clkdm = clkdm_lookup(oh->clkdm_name);
1462 if (!oh->clkdm) {
1463 pr_warning("omap_hwmod: %s: could not associate to clkdm %s\n",
1464 oh->name, oh->clkdm_name);
1465 return -EINVAL;
1466 }
1467
1468 pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
1469 oh->name, oh->clkdm_name);
1470
1471 return 0;
1472}
Paul Walmsley63c85232009-09-03 20:14:03 +03001473
1474/**
Benoit Cousson6ae76992011-07-10 05:56:30 -06001475 * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
1476 * well the clockdomain.
Paul Walmsley63c85232009-09-03 20:14:03 +03001477 * @oh: struct omap_hwmod *
Paul Walmsley97d60162010-07-26 16:34:30 -06001478 * @data: not used; pass NULL
Paul Walmsley63c85232009-09-03 20:14:03 +03001479 *
Paul Walmsleya2debdb2011-02-23 00:14:07 -07001480 * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
Paul Walmsley48d54f32011-02-23 00:14:07 -07001481 * Resolves all clock names embedded in the hwmod. Returns 0 on
1482 * success, or a negative error code on failure.
Paul Walmsley63c85232009-09-03 20:14:03 +03001483 */
Paul Walmsley97d60162010-07-26 16:34:30 -06001484static int _init_clocks(struct omap_hwmod *oh, void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03001485{
1486 int ret = 0;
1487
Paul Walmsley48d54f32011-02-23 00:14:07 -07001488 if (oh->_state != _HWMOD_STATE_REGISTERED)
1489 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001490
1491 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
1492
1493 ret |= _init_main_clk(oh);
1494 ret |= _init_interface_clks(oh);
1495 ret |= _init_opt_clks(oh);
Kevin Hilman0a179ea2012-06-18 12:12:25 -06001496 if (soc_ops.init_clkdm)
1497 ret |= soc_ops.init_clkdm(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03001498
Benoit Coussonf5c1f842010-05-20 12:31:10 -06001499 if (!ret)
1500 oh->_state = _HWMOD_STATE_CLKS_INITED;
Benoit Cousson66522712011-07-01 22:54:06 +02001501 else
1502 pr_warning("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001503
Rajendra Nayak09c35f22011-02-16 12:11:24 +00001504 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001505}
1506
1507/**
omar ramirezcc1226e2011-03-04 13:32:44 -07001508 * _lookup_hardreset - fill register bit info for this hwmod/reset line
Benoît Cousson5365efb2010-09-21 10:34:11 -06001509 * @oh: struct omap_hwmod *
1510 * @name: name of the reset line in the context of this hwmod
omar ramirezcc1226e2011-03-04 13:32:44 -07001511 * @ohri: struct omap_hwmod_rst_info * that this function will fill in
Benoît Cousson5365efb2010-09-21 10:34:11 -06001512 *
1513 * Return the bit position of the reset line that match the
1514 * input name. Return -ENOENT if not found.
1515 */
Paul Walmsleya032d332012-08-03 09:21:10 -06001516static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
1517 struct omap_hwmod_rst_info *ohri)
Benoît Cousson5365efb2010-09-21 10:34:11 -06001518{
1519 int i;
1520
1521 for (i = 0; i < oh->rst_lines_cnt; i++) {
1522 const char *rst_line = oh->rst_lines[i].name;
1523 if (!strcmp(rst_line, name)) {
omar ramirezcc1226e2011-03-04 13:32:44 -07001524 ohri->rst_shift = oh->rst_lines[i].rst_shift;
1525 ohri->st_shift = oh->rst_lines[i].st_shift;
1526 pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
1527 oh->name, __func__, rst_line, ohri->rst_shift,
1528 ohri->st_shift);
Benoît Cousson5365efb2010-09-21 10:34:11 -06001529
omar ramirezcc1226e2011-03-04 13:32:44 -07001530 return 0;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001531 }
1532 }
1533
1534 return -ENOENT;
1535}
1536
1537/**
1538 * _assert_hardreset - assert the HW reset line of submodules
1539 * contained in the hwmod module.
1540 * @oh: struct omap_hwmod *
1541 * @name: name of the reset line to lookup and assert
1542 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001543 * Some IP like dsp, ipu or iva contain processor that require an HW
1544 * reset line to be assert / deassert in order to enable fully the IP.
1545 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1546 * asserting the hardreset line on the currently-booted SoC, or passes
1547 * along the return value from _lookup_hardreset() or the SoC's
1548 * assert_hardreset code.
Benoît Cousson5365efb2010-09-21 10:34:11 -06001549 */
1550static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1551{
omar ramirezcc1226e2011-03-04 13:32:44 -07001552 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001553 int ret = -EINVAL;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001554
1555 if (!oh)
1556 return -EINVAL;
1557
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001558 if (!soc_ops.assert_hardreset)
1559 return -ENOSYS;
1560
omar ramirezcc1226e2011-03-04 13:32:44 -07001561 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001562 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001563 return ret;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001564
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001565 ret = soc_ops.assert_hardreset(oh, &ohri);
1566
1567 return ret;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001568}
1569
1570/**
1571 * _deassert_hardreset - deassert the HW reset line of submodules contained
1572 * in the hwmod module.
1573 * @oh: struct omap_hwmod *
1574 * @name: name of the reset line to look up and deassert
1575 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001576 * Some IP like dsp, ipu or iva contain processor that require an HW
1577 * reset line to be assert / deassert in order to enable fully the IP.
1578 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1579 * deasserting the hardreset line on the currently-booted SoC, or passes
1580 * along the return value from _lookup_hardreset() or the SoC's
1581 * deassert_hardreset code.
Benoît Cousson5365efb2010-09-21 10:34:11 -06001582 */
1583static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1584{
omar ramirezcc1226e2011-03-04 13:32:44 -07001585 struct omap_hwmod_rst_info ohri;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001586 int ret = -EINVAL;
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001587 int hwsup = 0;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001588
1589 if (!oh)
1590 return -EINVAL;
1591
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001592 if (!soc_ops.deassert_hardreset)
1593 return -ENOSYS;
1594
omar ramirezcc1226e2011-03-04 13:32:44 -07001595 ret = _lookup_hardreset(oh, name, &ohri);
1596 if (IS_ERR_VALUE(ret))
1597 return ret;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001598
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001599 if (oh->clkdm) {
1600 /*
1601 * A clockdomain must be in SW_SUP otherwise reset
1602 * might not be completed. The clockdomain can be set
1603 * in HW_AUTO only when the module become ready.
1604 */
1605 hwsup = clkdm_in_hwsup(oh->clkdm);
1606 ret = clkdm_hwmod_enable(oh->clkdm, oh);
1607 if (ret) {
1608 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1609 oh->name, oh->clkdm->name, ret);
1610 return ret;
1611 }
1612 }
1613
1614 _enable_clocks(oh);
1615 if (soc_ops.enable_module)
1616 soc_ops.enable_module(oh);
1617
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001618 ret = soc_ops.deassert_hardreset(oh, &ohri);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001619
1620 if (soc_ops.disable_module)
1621 soc_ops.disable_module(oh);
1622 _disable_clocks(oh);
1623
omar ramirezcc1226e2011-03-04 13:32:44 -07001624 if (ret == -EBUSY)
Benoît Cousson5365efb2010-09-21 10:34:11 -06001625 pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name);
1626
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001627 if (!ret) {
1628 /*
1629 * Set the clockdomain to HW_AUTO, assuming that the
1630 * previous state was HW_AUTO.
1631 */
1632 if (oh->clkdm && hwsup)
1633 clkdm_allow_idle(oh->clkdm);
1634 } else {
1635 if (oh->clkdm)
1636 clkdm_hwmod_disable(oh->clkdm, oh);
1637 }
1638
omar ramirezcc1226e2011-03-04 13:32:44 -07001639 return ret;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001640}
1641
1642/**
1643 * _read_hardreset - read the HW reset line state of submodules
1644 * contained in the hwmod module
1645 * @oh: struct omap_hwmod *
1646 * @name: name of the reset line to look up and read
1647 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001648 * Return the state of the reset line. Returns -EINVAL if @oh is
1649 * null, -ENOSYS if we have no way of reading the hardreset line
1650 * status on the currently-booted SoC, or passes along the return
1651 * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
1652 * code.
Benoît Cousson5365efb2010-09-21 10:34:11 -06001653 */
1654static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1655{
omar ramirezcc1226e2011-03-04 13:32:44 -07001656 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001657 int ret = -EINVAL;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001658
1659 if (!oh)
1660 return -EINVAL;
1661
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001662 if (!soc_ops.is_hardreset_asserted)
1663 return -ENOSYS;
1664
omar ramirezcc1226e2011-03-04 13:32:44 -07001665 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001666 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001667 return ret;
Benoît Cousson5365efb2010-09-21 10:34:11 -06001668
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001669 return soc_ops.is_hardreset_asserted(oh, &ohri);
Benoît Cousson5365efb2010-09-21 10:34:11 -06001670}
1671
1672/**
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001673 * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
Paul Walmsley747834a2012-04-18 19:10:04 -06001674 * @oh: struct omap_hwmod *
1675 *
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001676 * If all hardreset lines associated with @oh are asserted, then return true.
1677 * Otherwise, if part of @oh is out hardreset or if no hardreset lines
1678 * associated with @oh are asserted, then return false.
Paul Walmsley747834a2012-04-18 19:10:04 -06001679 * This function is used to avoid executing some parts of the IP block
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001680 * enable/disable sequence if its hardreset line is set.
Paul Walmsley747834a2012-04-18 19:10:04 -06001681 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001682static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
Paul Walmsley747834a2012-04-18 19:10:04 -06001683{
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001684 int i, rst_cnt = 0;
Paul Walmsley747834a2012-04-18 19:10:04 -06001685
1686 if (oh->rst_lines_cnt == 0)
1687 return false;
1688
1689 for (i = 0; i < oh->rst_lines_cnt; i++)
1690 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001691 rst_cnt++;
1692
1693 if (oh->rst_lines_cnt == rst_cnt)
1694 return true;
Paul Walmsley747834a2012-04-18 19:10:04 -06001695
1696 return false;
1697}
1698
1699/**
Paul Walmsleye9332b62012-10-08 23:08:15 -06001700 * _are_any_hardreset_lines_asserted - return true if any part of @oh is
1701 * hard-reset
1702 * @oh: struct omap_hwmod *
1703 *
1704 * If any hardreset lines associated with @oh are asserted, then
1705 * return true. Otherwise, if no hardreset lines associated with @oh
1706 * are asserted, or if @oh has no hardreset lines, then return false.
1707 * This function is used to avoid executing some parts of the IP block
1708 * enable/disable sequence if any hardreset line is set.
1709 */
1710static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
1711{
1712 int rst_cnt = 0;
1713 int i;
1714
1715 for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
1716 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1717 rst_cnt++;
1718
1719 return (rst_cnt) ? true : false;
1720}
1721
1722/**
Paul Walmsley747834a2012-04-18 19:10:04 -06001723 * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
1724 * @oh: struct omap_hwmod *
1725 *
1726 * Disable the PRCM module mode related to the hwmod @oh.
1727 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1728 */
1729static int _omap4_disable_module(struct omap_hwmod *oh)
1730{
1731 int v;
1732
Paul Walmsley747834a2012-04-18 19:10:04 -06001733 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1734 return -EINVAL;
1735
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001736 /*
1737 * Since integration code might still be doing something, only
1738 * disable if all lines are under hardreset.
1739 */
Paul Walmsleye9332b62012-10-08 23:08:15 -06001740 if (_are_any_hardreset_lines_asserted(oh))
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001741 return 0;
1742
Paul Walmsley747834a2012-04-18 19:10:04 -06001743 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1744
1745 omap4_cminst_module_disable(oh->clkdm->prcm_partition,
1746 oh->clkdm->cm_inst,
1747 oh->clkdm->clkdm_offs,
1748 oh->prcm.omap4.clkctrl_offs);
1749
Paul Walmsley747834a2012-04-18 19:10:04 -06001750 v = _omap4_wait_target_disable(oh);
1751 if (v)
1752 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1753 oh->name);
1754
1755 return 0;
1756}
1757
1758/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001759 * _am33xx_disable_module - enable CLKCTRL modulemode on AM33XX
1760 * @oh: struct omap_hwmod *
1761 *
1762 * Disable the PRCM module mode related to the hwmod @oh.
1763 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1764 */
1765static int _am33xx_disable_module(struct omap_hwmod *oh)
1766{
1767 int v;
1768
1769 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1770 return -EINVAL;
1771
1772 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1773
Paul Walmsleye9332b62012-10-08 23:08:15 -06001774 if (_are_any_hardreset_lines_asserted(oh))
1775 return 0;
1776
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001777 am33xx_cm_module_disable(oh->clkdm->cm_inst, oh->clkdm->clkdm_offs,
1778 oh->prcm.omap4.clkctrl_offs);
1779
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001780 v = _am33xx_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/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001789 * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
Paul Walmsley63c85232009-09-03 20:14:03 +03001790 * @oh: struct omap_hwmod *
1791 *
1792 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
Paul Walmsley30e105c2012-04-19 00:49:09 -06001793 * enabled for this to work. Returns -ENOENT if the hwmod cannot be
1794 * reset this way, -EINVAL if the hwmod is in the wrong state,
1795 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Benoit Cousson2cb06812010-09-21 18:57:59 +02001796 *
1797 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
Paul Walmsleybd361792010-12-14 12:42:35 -07001798 * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
Benoit Cousson2cb06812010-09-21 18:57:59 +02001799 * use the SYSCONFIG softreset bit to provide the status.
1800 *
Paul Walmsleybd361792010-12-14 12:42:35 -07001801 * Note that some IP like McBSP do have reset control but don't have
1802 * reset status.
Paul Walmsley63c85232009-09-03 20:14:03 +03001803 */
Paul Walmsleybd361792010-12-14 12:42:35 -07001804static int _ocp_softreset(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001805{
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001806 u32 v, softrst_mask;
Paul Walmsley6f8b7ff2009-12-08 16:33:16 -07001807 int c = 0;
Benoit Cousson96835af2010-09-21 18:57:58 +02001808 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001809
Paul Walmsley43b40992010-02-22 22:09:34 -07001810 if (!oh->class->sysc ||
Benoit Cousson2cb06812010-09-21 18:57:59 +02001811 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley30e105c2012-04-19 00:49:09 -06001812 return -ENOENT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001813
1814 /* clocks must be on for this operation */
1815 if (oh->_state != _HWMOD_STATE_ENABLED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001816 pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
1817 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001818 return -EINVAL;
1819 }
1820
Benoit Cousson96835af2010-09-21 18:57:58 +02001821 /* For some modules, all optionnal clocks need to be enabled as well */
1822 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1823 _enable_optional_clocks(oh);
1824
Paul Walmsleybd361792010-12-14 12:42:35 -07001825 pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001826
1827 v = oh->_sysc_cache;
Benoit Cousson96835af2010-09-21 18:57:58 +02001828 ret = _set_softreset(oh, &v);
1829 if (ret)
1830 goto dis_opt_clks;
Paul Walmsley63c85232009-09-03 20:14:03 +03001831 _write_sysconfig(v, oh);
1832
Fernando Guzman Lugod99de7f2012-04-13 05:08:03 -06001833 if (oh->class->sysc->srst_udelay)
1834 udelay(oh->class->sysc->srst_udelay);
1835
Benoit Cousson2cb06812010-09-21 18:57:59 +02001836 if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07001837 omap_test_timeout((omap_hwmod_read(oh,
Benoit Cousson2cb06812010-09-21 18:57:59 +02001838 oh->class->sysc->syss_offs)
1839 & SYSS_RESETDONE_MASK),
1840 MAX_MODULE_SOFTRESET_WAIT, c);
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001841 else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
1842 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07001843 omap_test_timeout(!(omap_hwmod_read(oh,
Benoit Cousson2cb06812010-09-21 18:57:59 +02001844 oh->class->sysc->sysc_offs)
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001845 & softrst_mask),
Benoit Cousson2cb06812010-09-21 18:57:59 +02001846 MAX_MODULE_SOFTRESET_WAIT, c);
Rajendra Nayak387ca5b2012-03-12 04:29:58 -06001847 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001848
Benoît Cousson5365efb2010-09-21 10:34:11 -06001849 if (c == MAX_MODULE_SOFTRESET_WAIT)
Benoit Cousson76e55892010-09-21 10:34:11 -06001850 pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1851 oh->name, MAX_MODULE_SOFTRESET_WAIT);
Paul Walmsley63c85232009-09-03 20:14:03 +03001852 else
Benoît Cousson5365efb2010-09-21 10:34:11 -06001853 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
Paul Walmsley63c85232009-09-03 20:14:03 +03001854
1855 /*
1856 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1857 * _wait_target_ready() or _reset()
1858 */
1859
Benoit Cousson96835af2010-09-21 18:57:58 +02001860 ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
1861
1862dis_opt_clks:
1863 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1864 _disable_optional_clocks(oh);
1865
1866 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001867}
1868
1869/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001870 * _reset - reset an omap_hwmod
1871 * @oh: struct omap_hwmod *
1872 *
Paul Walmsley30e105c2012-04-19 00:49:09 -06001873 * Resets an omap_hwmod @oh. If the module has a custom reset
1874 * function pointer defined, then call it to reset the IP block, and
1875 * pass along its return value to the caller. Otherwise, if the IP
1876 * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
1877 * associated with it, call a function to reset the IP block via that
1878 * method, and pass along the return value to the caller. Finally, if
1879 * the IP block has some hardreset lines associated with it, assert
1880 * all of those, but do _not_ deassert them. (This is because driver
1881 * authors have expressed an apparent requirement to control the
1882 * deassertion of the hardreset lines themselves.)
1883 *
1884 * The default software reset mechanism for most OMAP IP blocks is
1885 * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
1886 * hwmods cannot be reset via this method. Some are not targets and
1887 * therefore have no OCP header registers to access. Others (like the
1888 * IVA) have idiosyncratic reset sequences. So for these relatively
1889 * rare cases, custom reset code can be supplied in the struct
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001890 * omap_hwmod_class .reset function pointer.
1891 *
1892 * _set_dmadisable() is called to set the DMADISABLE bit so that it
1893 * does not prevent idling of the system. This is necessary for cases
1894 * where ROMCODE/BOOTLOADER uses dma and transfers control to the
1895 * kernel without disabling dma.
1896 *
1897 * Passes along the return value from either _ocp_softreset() or the
1898 * custom reset function - these must return -EINVAL if the hwmod
1899 * cannot be reset this way or if the hwmod is in the wrong state,
1900 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Paul Walmsleybd361792010-12-14 12:42:35 -07001901 */
1902static int _reset(struct omap_hwmod *oh)
1903{
Paul Walmsley30e105c2012-04-19 00:49:09 -06001904 int i, r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001905
1906 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1907
Paul Walmsley30e105c2012-04-19 00:49:09 -06001908 if (oh->class->reset) {
1909 r = oh->class->reset(oh);
1910 } else {
1911 if (oh->rst_lines_cnt > 0) {
1912 for (i = 0; i < oh->rst_lines_cnt; i++)
1913 _assert_hardreset(oh, oh->rst_lines[i].name);
1914 return 0;
1915 } else {
1916 r = _ocp_softreset(oh);
1917 if (r == -ENOENT)
1918 r = 0;
1919 }
1920 }
Paul Walmsleybd361792010-12-14 12:42:35 -07001921
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001922 _set_dmadisable(oh);
1923
Paul Walmsley30e105c2012-04-19 00:49:09 -06001924 /*
1925 * OCP_SYSCONFIG bits need to be reprogrammed after a
1926 * softreset. The _enable() function should be split to avoid
1927 * the rewrite of the OCP_SYSCONFIG register.
1928 */
Rajendra Nayak28008522012-03-13 22:55:23 +05301929 if (oh->class->sysc) {
1930 _update_sysc_cache(oh);
1931 _enable_sysc(oh);
1932 }
1933
Paul Walmsley30e105c2012-04-19 00:49:09 -06001934 return r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001935}
1936
1937/**
Vishwanath BS51658822012-06-22 08:40:04 -06001938 * _reconfigure_io_chain - clear any I/O chain wakeups and reconfigure chain
1939 *
1940 * Call the appropriate PRM function to clear any logged I/O chain
1941 * wakeups and to reconfigure the chain. This apparently needs to be
1942 * done upon every mux change. Since hwmods can be concurrently
1943 * enabled and idled, hold a spinlock around the I/O chain
1944 * reconfiguration sequence. No return value.
1945 *
1946 * XXX When the PRM code is moved to drivers, this function can be removed,
1947 * as the PRM infrastructure should abstract this.
1948 */
1949static void _reconfigure_io_chain(void)
1950{
1951 unsigned long flags;
1952
1953 spin_lock_irqsave(&io_chain_lock, flags);
1954
1955 if (cpu_is_omap34xx() && omap3_has_io_chain_ctrl())
1956 omap3xxx_prm_reconfigure_io_chain();
1957 else if (cpu_is_omap44xx())
1958 omap44xx_prm_reconfigure_io_chain();
1959
1960 spin_unlock_irqrestore(&io_chain_lock, flags);
1961}
1962
1963/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001964 * _enable - enable an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001965 * @oh: struct omap_hwmod *
1966 *
1967 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001968 * register target. Returns -EINVAL if the hwmod is in the wrong
1969 * state or passes along the return value of _wait_target_ready().
Paul Walmsley63c85232009-09-03 20:14:03 +03001970 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001971static int _enable(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001972{
Paul Walmsley747834a2012-04-18 19:10:04 -06001973 int r;
Rajendra Nayak665d0012011-07-10 05:57:07 -06001974 int hwsup = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001975
Benoit Cousson34617e22011-07-01 22:54:07 +02001976 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1977
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001978 /*
Paul Walmsley64813c32012-04-18 19:10:03 -06001979 * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
1980 * state at init. Now that someone is really trying to enable
1981 * them, just ensure that the hwmod mux is set.
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001982 */
1983 if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
1984 /*
1985 * If the caller has mux data populated, do the mux'ing
1986 * which wouldn't have been done as part of the _enable()
1987 * done during setup.
1988 */
1989 if (oh->mux)
1990 omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
1991
1992 oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
1993 return 0;
1994 }
1995
Paul Walmsley63c85232009-09-03 20:14:03 +03001996 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1997 oh->_state != _HWMOD_STATE_IDLE &&
1998 oh->_state != _HWMOD_STATE_DISABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00001999 WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
2000 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002001 return -EINVAL;
2002 }
2003
Benoit Cousson31f62862011-07-01 22:54:05 +02002004 /*
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002005 * If an IP block contains HW reset lines and all of them are
Paul Walmsley747834a2012-04-18 19:10:04 -06002006 * asserted, we let integration code associated with that
2007 * block handle the enable. We've received very little
2008 * information on what those driver authors need, and until
2009 * detailed information is provided and the driver code is
2010 * posted to the public lists, this is probably the best we
2011 * can do.
Benoit Cousson31f62862011-07-01 22:54:05 +02002012 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002013 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002014 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03002015
Rajendra Nayak665d0012011-07-10 05:57:07 -06002016 /* Mux pins for device runtime if populated */
2017 if (oh->mux && (!oh->mux->enabled ||
2018 ((oh->_state == _HWMOD_STATE_IDLE) &&
Vishwanath BS51658822012-06-22 08:40:04 -06002019 oh->mux->pads_dynamic))) {
Rajendra Nayak665d0012011-07-10 05:57:07 -06002020 omap_hwmod_mux(oh->mux, _HWMOD_STATE_ENABLED);
Vishwanath BS51658822012-06-22 08:40:04 -06002021 _reconfigure_io_chain();
2022 }
Benoit Cousson34617e22011-07-01 22:54:07 +02002023
Rajendra Nayak665d0012011-07-10 05:57:07 -06002024 _add_initiator_dep(oh, mpu_oh);
2025
2026 if (oh->clkdm) {
2027 /*
2028 * A clockdomain must be in SW_SUP before enabling
2029 * completely the module. The clockdomain can be set
2030 * in HW_AUTO only when the module become ready.
2031 */
Paul Walmsleyb71c7212012-09-23 17:28:28 -06002032 hwsup = clkdm_in_hwsup(oh->clkdm) &&
2033 !clkdm_missing_idle_reporting(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002034 r = clkdm_hwmod_enable(oh->clkdm, oh);
2035 if (r) {
2036 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
2037 oh->name, oh->clkdm->name, r);
2038 return r;
2039 }
Benoit Cousson34617e22011-07-01 22:54:07 +02002040 }
Rajendra Nayak665d0012011-07-10 05:57:07 -06002041
2042 _enable_clocks(oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002043 if (soc_ops.enable_module)
2044 soc_ops.enable_module(oh);
Benoit Cousson34617e22011-07-01 22:54:07 +02002045
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002046 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
2047 -EINVAL;
Rajendra Nayak665d0012011-07-10 05:57:07 -06002048 if (!r) {
2049 /*
2050 * Set the clockdomain to HW_AUTO only if the target is ready,
2051 * assuming that the previous state was HW_AUTO
2052 */
2053 if (oh->clkdm && hwsup)
2054 clkdm_allow_idle(oh->clkdm);
Benoit Cousson34617e22011-07-01 22:54:07 +02002055
Rajendra Nayak665d0012011-07-10 05:57:07 -06002056 oh->_state = _HWMOD_STATE_ENABLED;
2057
2058 /* Access the sysconfig only if the target is ready */
2059 if (oh->class->sysc) {
2060 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
2061 _update_sysc_cache(oh);
2062 _enable_sysc(oh);
2063 }
2064 } else {
Paul Walmsley2577a4a2012-10-29 20:57:55 -06002065 if (soc_ops.disable_module)
2066 soc_ops.disable_module(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002067 _disable_clocks(oh);
2068 pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n",
2069 oh->name, r);
2070
2071 if (oh->clkdm)
2072 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002073 }
2074
Paul Walmsley63c85232009-09-03 20:14:03 +03002075 return r;
2076}
2077
2078/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002079 * _idle - idle an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03002080 * @oh: struct omap_hwmod *
2081 *
2082 * Idles an omap_hwmod @oh. This should be called once the hwmod has
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002083 * no further work. Returns -EINVAL if the hwmod is in the wrong
2084 * state or returns 0.
Paul Walmsley63c85232009-09-03 20:14:03 +03002085 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002086static int _idle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002087{
Benoit Cousson34617e22011-07-01 22:54:07 +02002088 pr_debug("omap_hwmod: %s: idling\n", oh->name);
2089
Paul Walmsley63c85232009-09-03 20:14:03 +03002090 if (oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002091 WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
2092 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002093 return -EINVAL;
2094 }
2095
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002096 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002097 return 0;
2098
Paul Walmsley43b40992010-02-22 22:09:34 -07002099 if (oh->class->sysc)
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002100 _idle_sysc(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002101 _del_initiator_dep(oh, mpu_oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002102
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002103 if (soc_ops.disable_module)
2104 soc_ops.disable_module(oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002105
Benoit Cousson45c38252011-07-10 05:56:33 -06002106 /*
2107 * The module must be in idle mode before disabling any parents
2108 * clocks. Otherwise, the parent clock might be disabled before
2109 * the module transition is done, and thus will prevent the
2110 * transition to complete properly.
2111 */
2112 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002113 if (oh->clkdm)
2114 clkdm_hwmod_disable(oh->clkdm, oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002115
Tony Lindgren8d9af882010-12-22 18:42:35 -08002116 /* Mux pins for device idle if populated */
Vishwanath BS51658822012-06-22 08:40:04 -06002117 if (oh->mux && oh->mux->pads_dynamic) {
Tony Lindgren8d9af882010-12-22 18:42:35 -08002118 omap_hwmod_mux(oh->mux, _HWMOD_STATE_IDLE);
Vishwanath BS51658822012-06-22 08:40:04 -06002119 _reconfigure_io_chain();
2120 }
Tony Lindgren8d9af882010-12-22 18:42:35 -08002121
Paul Walmsley63c85232009-09-03 20:14:03 +03002122 oh->_state = _HWMOD_STATE_IDLE;
2123
2124 return 0;
2125}
2126
2127/**
Kishon Vijay Abraham I95992172011-03-10 03:50:08 -07002128 * omap_hwmod_set_ocp_autoidle - set the hwmod's OCP autoidle bit
2129 * @oh: struct omap_hwmod *
2130 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
2131 *
2132 * Sets the IP block's OCP autoidle bit in hardware, and updates our
2133 * local copy. Intended to be used by drivers that require
2134 * direct manipulation of the AUTOIDLE bits.
2135 * Returns -EINVAL if @oh is null or is not in the ENABLED state, or passes
2136 * along the return value from _set_module_autoidle().
2137 *
2138 * Any users of this function should be scrutinized carefully.
2139 */
2140int omap_hwmod_set_ocp_autoidle(struct omap_hwmod *oh, u8 autoidle)
2141{
2142 u32 v;
2143 int retval = 0;
2144 unsigned long flags;
2145
2146 if (!oh || oh->_state != _HWMOD_STATE_ENABLED)
2147 return -EINVAL;
2148
2149 spin_lock_irqsave(&oh->_lock, flags);
2150
2151 v = oh->_sysc_cache;
2152
2153 retval = _set_module_autoidle(oh, autoidle, &v);
2154
2155 if (!retval)
2156 _write_sysconfig(v, oh);
2157
2158 spin_unlock_irqrestore(&oh->_lock, flags);
2159
2160 return retval;
2161}
2162
2163/**
Paul Walmsley63c85232009-09-03 20:14:03 +03002164 * _shutdown - shutdown an omap_hwmod
2165 * @oh: struct omap_hwmod *
2166 *
2167 * Shut down an omap_hwmod @oh. This should be called when the driver
2168 * used for the hwmod is removed or unloaded or if the driver is not
2169 * used by the system. Returns -EINVAL if the hwmod is in the wrong
2170 * state or returns 0.
2171 */
2172static int _shutdown(struct omap_hwmod *oh)
2173{
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002174 int ret, i;
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002175 u8 prev_state;
2176
Paul Walmsley63c85232009-09-03 20:14:03 +03002177 if (oh->_state != _HWMOD_STATE_IDLE &&
2178 oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002179 WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
2180 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002181 return -EINVAL;
2182 }
2183
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06002184 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002185 return 0;
2186
Paul Walmsley63c85232009-09-03 20:14:03 +03002187 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
2188
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002189 if (oh->class->pre_shutdown) {
2190 prev_state = oh->_state;
2191 if (oh->_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002192 _enable(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002193 ret = oh->class->pre_shutdown(oh);
2194 if (ret) {
2195 if (prev_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002196 _idle(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002197 return ret;
2198 }
2199 }
2200
Miguel Vadillo6481c732011-07-01 22:54:02 +02002201 if (oh->class->sysc) {
2202 if (oh->_state == _HWMOD_STATE_IDLE)
2203 _enable(oh);
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002204 _shutdown_sysc(oh);
Miguel Vadillo6481c732011-07-01 22:54:02 +02002205 }
Benoît Cousson5365efb2010-09-21 10:34:11 -06002206
Benoit Cousson3827f942010-09-21 10:34:08 -06002207 /* clocks and deps are already disabled in idle */
2208 if (oh->_state == _HWMOD_STATE_ENABLED) {
2209 _del_initiator_dep(oh, mpu_oh);
2210 /* XXX what about the other system initiators here? dma, dsp */
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002211 if (soc_ops.disable_module)
2212 soc_ops.disable_module(oh);
Benoit Cousson45c38252011-07-10 05:56:33 -06002213 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002214 if (oh->clkdm)
2215 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson3827f942010-09-21 10:34:08 -06002216 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002217 /* XXX Should this code also force-disable the optional clocks? */
2218
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002219 for (i = 0; i < oh->rst_lines_cnt; i++)
2220 _assert_hardreset(oh, oh->rst_lines[i].name);
Benoit Cousson31f62862011-07-01 22:54:05 +02002221
Tony Lindgren8d9af882010-12-22 18:42:35 -08002222 /* Mux pins to safe mode or use populated off mode values */
2223 if (oh->mux)
2224 omap_hwmod_mux(oh->mux, _HWMOD_STATE_DISABLED);
Paul Walmsley63c85232009-09-03 20:14:03 +03002225
2226 oh->_state = _HWMOD_STATE_DISABLED;
2227
2228 return 0;
2229}
2230
2231/**
Paul Walmsley381d0332012-04-19 00:58:22 -06002232 * _init_mpu_rt_base - populate the virtual address for a hwmod
2233 * @oh: struct omap_hwmod * to locate the virtual address
2234 *
2235 * Cache the virtual address used by the MPU to access this IP block's
2236 * registers. This address is needed early so the OCP registers that
2237 * are part of the device's address space can be ioremapped properly.
2238 * No return value.
2239 */
2240static void __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data)
2241{
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002242 struct omap_hwmod_addr_space *mem;
2243 void __iomem *va_start;
2244
2245 if (!oh)
2246 return;
2247
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002248 _save_mpu_port_index(oh);
2249
Paul Walmsley381d0332012-04-19 00:58:22 -06002250 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
2251 return;
2252
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002253 mem = _find_mpu_rt_addr_space(oh);
2254 if (!mem) {
2255 pr_debug("omap_hwmod: %s: no MPU register target found\n",
2256 oh->name);
2257 return;
2258 }
2259
2260 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
2261 if (!va_start) {
2262 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
2263 return;
2264 }
2265
2266 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
2267 oh->name, va_start);
2268
2269 oh->_mpu_rt_va = va_start;
Paul Walmsley381d0332012-04-19 00:58:22 -06002270}
2271
2272/**
2273 * _init - initialize internal data for the hwmod @oh
2274 * @oh: struct omap_hwmod *
2275 * @n: (unused)
2276 *
2277 * Look up the clocks and the address space used by the MPU to access
2278 * registers belonging to the hwmod @oh. @oh must already be
2279 * registered at this point. This is the first of two phases for
2280 * hwmod initialization. Code called here does not touch any hardware
2281 * registers, it simply prepares internal data structures. Returns 0
2282 * upon success or if the hwmod isn't registered, or -EINVAL upon
2283 * failure.
2284 */
2285static int __init _init(struct omap_hwmod *oh, void *data)
2286{
2287 int r;
2288
2289 if (oh->_state != _HWMOD_STATE_REGISTERED)
2290 return 0;
2291
2292 _init_mpu_rt_base(oh, NULL);
2293
2294 r = _init_clocks(oh, NULL);
2295 if (IS_ERR_VALUE(r)) {
2296 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2297 return -EINVAL;
2298 }
2299
2300 oh->_state = _HWMOD_STATE_INITIALIZED;
2301
2302 return 0;
2303}
2304
2305/**
Paul Walmsley64813c32012-04-18 19:10:03 -06002306 * _setup_iclk_autoidle - configure an IP block's interface clocks
Paul Walmsley63c85232009-09-03 20:14:03 +03002307 * @oh: struct omap_hwmod *
2308 *
Paul Walmsley64813c32012-04-18 19:10:03 -06002309 * Set up the module's interface clocks. XXX This function is still mostly
2310 * a stub; implementing this properly requires iclk autoidle usecounting in
2311 * the clock code. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03002312 */
Paul Walmsley64813c32012-04-18 19:10:03 -06002313static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002314{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002315 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002316 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002317 int i = 0;
Paul Walmsley381d0332012-04-19 00:58:22 -06002318 if (oh->_state != _HWMOD_STATE_INITIALIZED)
Paul Walmsley64813c32012-04-18 19:10:03 -06002319 return;
Paul Walmsley48d54f32011-02-23 00:14:07 -07002320
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002321 p = oh->slave_ports.next;
Paul Walmsley63c85232009-09-03 20:14:03 +03002322
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002323 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06002324 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002325 if (!os->_clk)
Paul Walmsley64813c32012-04-18 19:10:03 -06002326 continue;
Paul Walmsley63c85232009-09-03 20:14:03 +03002327
Paul Walmsley64813c32012-04-18 19:10:03 -06002328 if (os->flags & OCPIF_SWSUP_IDLE) {
2329 /* XXX omap_iclk_deny_idle(c); */
2330 } else {
2331 /* XXX omap_iclk_allow_idle(c); */
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002332 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +03002333 }
2334 }
2335
Paul Walmsley64813c32012-04-18 19:10:03 -06002336 return;
2337}
2338
2339/**
2340 * _setup_reset - reset an IP block during the setup process
2341 * @oh: struct omap_hwmod *
2342 *
2343 * Reset the IP block corresponding to the hwmod @oh during the setup
2344 * process. The IP block is first enabled so it can be successfully
2345 * reset. Returns 0 upon success or a negative error code upon
2346 * failure.
2347 */
2348static int __init _setup_reset(struct omap_hwmod *oh)
2349{
2350 int r;
2351
2352 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2353 return -EINVAL;
Paul Walmsley63c85232009-09-03 20:14:03 +03002354
Paul Walmsley747834a2012-04-18 19:10:04 -06002355 if (oh->rst_lines_cnt == 0) {
2356 r = _enable(oh);
2357 if (r) {
2358 pr_warning("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2359 oh->name, oh->_state);
2360 return -EINVAL;
2361 }
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002362 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002363
Rajendra Nayak28008522012-03-13 22:55:23 +05302364 if (!(oh->flags & HWMOD_INIT_NO_RESET))
Paul Walmsley64813c32012-04-18 19:10:03 -06002365 r = _reset(oh);
2366
2367 return r;
2368}
2369
2370/**
2371 * _setup_postsetup - transition to the appropriate state after _setup
2372 * @oh: struct omap_hwmod *
2373 *
2374 * Place an IP block represented by @oh into a "post-setup" state --
2375 * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that
2376 * this function is called at the end of _setup().) The postsetup
2377 * state for an IP block can be changed by calling
2378 * omap_hwmod_enter_postsetup_state() early in the boot process,
2379 * before one of the omap_hwmod_setup*() functions are called for the
2380 * IP block.
2381 *
2382 * The IP block stays in this state until a PM runtime-based driver is
2383 * loaded for that IP block. A post-setup state of IDLE is
2384 * appropriate for almost all IP blocks with runtime PM-enabled
2385 * drivers, since those drivers are able to enable the IP block. A
2386 * post-setup state of ENABLED is appropriate for kernels with PM
2387 * runtime disabled. The DISABLED state is appropriate for unusual IP
2388 * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2389 * included, since the WDTIMER starts running on reset and will reset
2390 * the MPU if left active.
2391 *
2392 * This post-setup mechanism is deprecated. Once all of the OMAP
2393 * drivers have been converted to use PM runtime, and all of the IP
2394 * block data and interconnect data is available to the hwmod code, it
2395 * should be possible to replace this mechanism with a "lazy reset"
2396 * arrangement. In a "lazy reset" setup, each IP block is enabled
2397 * when the driver first probes, then all remaining IP blocks without
2398 * drivers are either shut down or enabled after the drivers have
2399 * loaded. However, this cannot take place until the above
2400 * preconditions have been met, since otherwise the late reset code
2401 * has no way of knowing which IP blocks are in use by drivers, and
2402 * which ones are unused.
2403 *
2404 * No return value.
2405 */
2406static void __init _setup_postsetup(struct omap_hwmod *oh)
2407{
2408 u8 postsetup_state;
2409
2410 if (oh->rst_lines_cnt > 0)
2411 return;
Benoit Cousson76e55892010-09-21 10:34:11 -06002412
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002413 postsetup_state = oh->_postsetup_state;
2414 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2415 postsetup_state = _HWMOD_STATE_ENABLED;
2416
2417 /*
2418 * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2419 * it should be set by the core code as a runtime flag during startup
2420 */
2421 if ((oh->flags & HWMOD_INIT_NO_IDLE) &&
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002422 (postsetup_state == _HWMOD_STATE_IDLE)) {
2423 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002424 postsetup_state = _HWMOD_STATE_ENABLED;
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002425 }
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002426
2427 if (postsetup_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002428 _idle(oh);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002429 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2430 _shutdown(oh);
2431 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2432 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2433 oh->name, postsetup_state);
Paul Walmsley63c85232009-09-03 20:14:03 +03002434
Paul Walmsley64813c32012-04-18 19:10:03 -06002435 return;
2436}
2437
2438/**
2439 * _setup - prepare IP block hardware for use
2440 * @oh: struct omap_hwmod *
2441 * @n: (unused, pass NULL)
2442 *
2443 * Configure the IP block represented by @oh. This may include
2444 * enabling the IP block, resetting it, and placing it into a
2445 * post-setup state, depending on the type of IP block and applicable
2446 * flags. IP blocks are reset to prevent any previous configuration
2447 * by the bootloader or previous operating system from interfering
2448 * with power management or other parts of the system. The reset can
2449 * be avoided; see omap_hwmod_no_setup_reset(). This is the second of
2450 * two phases for hwmod initialization. Code called here generally
2451 * affects the IP block hardware, or system integration hardware
2452 * associated with the IP block. Returns 0.
2453 */
2454static int __init _setup(struct omap_hwmod *oh, void *data)
2455{
2456 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2457 return 0;
2458
2459 _setup_iclk_autoidle(oh);
2460
2461 if (!_setup_reset(oh))
2462 _setup_postsetup(oh);
2463
Paul Walmsley63c85232009-09-03 20:14:03 +03002464 return 0;
2465}
2466
Benoit Cousson0102b622010-12-21 21:31:27 -07002467/**
2468 * _register - register a struct omap_hwmod
2469 * @oh: struct omap_hwmod *
2470 *
2471 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
2472 * already has been registered by the same name; -EINVAL if the
2473 * omap_hwmod is in the wrong state, if @oh is NULL, if the
2474 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2475 * name, or if the omap_hwmod's class is missing a name; or 0 upon
2476 * success.
2477 *
2478 * XXX The data should be copied into bootmem, so the original data
2479 * should be marked __initdata and freed after init. This would allow
2480 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
2481 * that the copy process would be relatively complex due to the large number
2482 * of substructures.
2483 */
Benoit Cousson01592df92010-12-21 21:31:28 -07002484static int __init _register(struct omap_hwmod *oh)
Benoit Cousson0102b622010-12-21 21:31:27 -07002485{
Benoit Cousson0102b622010-12-21 21:31:27 -07002486 if (!oh || !oh->name || !oh->class || !oh->class->name ||
2487 (oh->_state != _HWMOD_STATE_UNKNOWN))
2488 return -EINVAL;
2489
Benoit Cousson0102b622010-12-21 21:31:27 -07002490 pr_debug("omap_hwmod: %s: registering\n", oh->name);
2491
Benoit Coussonce35b242010-12-21 21:31:28 -07002492 if (_lookup(oh->name))
2493 return -EEXIST;
Benoit Cousson0102b622010-12-21 21:31:27 -07002494
Benoit Cousson0102b622010-12-21 21:31:27 -07002495 list_add_tail(&oh->node, &omap_hwmod_list);
2496
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002497 INIT_LIST_HEAD(&oh->master_ports);
2498 INIT_LIST_HEAD(&oh->slave_ports);
Benoit Cousson0102b622010-12-21 21:31:27 -07002499 spin_lock_init(&oh->_lock);
2500
2501 oh->_state = _HWMOD_STATE_REGISTERED;
2502
Paul Walmsley569edd702011-02-23 00:14:06 -07002503 /*
2504 * XXX Rather than doing a strcmp(), this should test a flag
2505 * set in the hwmod data, inserted by the autogenerator code.
2506 */
2507 if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2508 mpu_oh = oh;
Benoit Cousson0102b622010-12-21 21:31:27 -07002509
Paul Walmsley569edd702011-02-23 00:14:06 -07002510 return 0;
Benoit Cousson0102b622010-12-21 21:31:27 -07002511}
Paul Walmsley63c85232009-09-03 20:14:03 +03002512
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002513/**
2514 * _alloc_links - return allocated memory for hwmod links
2515 * @ml: pointer to a struct omap_hwmod_link * for the master link
2516 * @sl: pointer to a struct omap_hwmod_link * for the slave link
2517 *
2518 * Return pointers to two struct omap_hwmod_link records, via the
2519 * addresses pointed to by @ml and @sl. Will first attempt to return
2520 * memory allocated as part of a large initial block, but if that has
2521 * been exhausted, will allocate memory itself. Since ideally this
2522 * second allocation path will never occur, the number of these
2523 * 'supplemental' allocations will be logged when debugging is
2524 * enabled. Returns 0.
2525 */
2526static int __init _alloc_links(struct omap_hwmod_link **ml,
2527 struct omap_hwmod_link **sl)
2528{
2529 unsigned int sz;
2530
2531 if ((free_ls + LINKS_PER_OCP_IF) <= max_ls) {
2532 *ml = &linkspace[free_ls++];
2533 *sl = &linkspace[free_ls++];
2534 return 0;
2535 }
2536
2537 sz = sizeof(struct omap_hwmod_link) * LINKS_PER_OCP_IF;
2538
2539 *sl = NULL;
2540 *ml = alloc_bootmem(sz);
2541
2542 memset(*ml, 0, sz);
2543
2544 *sl = (void *)(*ml) + sizeof(struct omap_hwmod_link);
2545
2546 ls_supp++;
2547 pr_debug("omap_hwmod: supplemental link allocations needed: %d\n",
2548 ls_supp * LINKS_PER_OCP_IF);
2549
2550 return 0;
2551};
2552
2553/**
2554 * _add_link - add an interconnect between two IP blocks
2555 * @oi: pointer to a struct omap_hwmod_ocp_if record
2556 *
2557 * Add struct omap_hwmod_link records connecting the master IP block
2558 * specified in @oi->master to @oi, and connecting the slave IP block
2559 * specified in @oi->slave to @oi. This code is assumed to run before
2560 * preemption or SMP has been enabled, thus avoiding the need for
2561 * locking in this code. Changes to this assumption will require
2562 * additional locking. Returns 0.
2563 */
2564static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2565{
2566 struct omap_hwmod_link *ml, *sl;
2567
2568 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2569 oi->slave->name);
2570
2571 _alloc_links(&ml, &sl);
2572
2573 ml->ocp_if = oi;
2574 INIT_LIST_HEAD(&ml->node);
2575 list_add(&ml->node, &oi->master->master_ports);
2576 oi->master->masters_cnt++;
2577
2578 sl->ocp_if = oi;
2579 INIT_LIST_HEAD(&sl->node);
2580 list_add(&sl->node, &oi->slave->slave_ports);
2581 oi->slave->slaves_cnt++;
2582
2583 return 0;
2584}
2585
2586/**
2587 * _register_link - register a struct omap_hwmod_ocp_if
2588 * @oi: struct omap_hwmod_ocp_if *
2589 *
2590 * Registers the omap_hwmod_ocp_if record @oi. Returns -EEXIST if it
2591 * has already been registered; -EINVAL if @oi is NULL or if the
2592 * record pointed to by @oi is missing required fields; or 0 upon
2593 * success.
2594 *
2595 * XXX The data should be copied into bootmem, so the original data
2596 * should be marked __initdata and freed after init. This would allow
2597 * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2598 */
2599static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2600{
2601 if (!oi || !oi->master || !oi->slave || !oi->user)
2602 return -EINVAL;
2603
2604 if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2605 return -EEXIST;
2606
2607 pr_debug("omap_hwmod: registering link from %s to %s\n",
2608 oi->master->name, oi->slave->name);
2609
2610 /*
2611 * Register the connected hwmods, if they haven't been
2612 * registered already
2613 */
2614 if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2615 _register(oi->master);
2616
2617 if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2618 _register(oi->slave);
2619
2620 _add_link(oi);
2621
2622 oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2623
2624 return 0;
2625}
2626
2627/**
2628 * _alloc_linkspace - allocate large block of hwmod links
2629 * @ois: pointer to an array of struct omap_hwmod_ocp_if records to count
2630 *
2631 * Allocate a large block of struct omap_hwmod_link records. This
2632 * improves boot time significantly by avoiding the need to allocate
2633 * individual records one by one. If the number of records to
2634 * allocate in the block hasn't been manually specified, this function
2635 * will count the number of struct omap_hwmod_ocp_if records in @ois
2636 * and use that to determine the allocation size. For SoC families
2637 * that require multiple list registrations, such as OMAP3xxx, this
2638 * estimation process isn't optimal, so manual estimation is advised
2639 * in those cases. Returns -EEXIST if the allocation has already occurred
2640 * or 0 upon success.
2641 */
2642static int __init _alloc_linkspace(struct omap_hwmod_ocp_if **ois)
2643{
2644 unsigned int i = 0;
2645 unsigned int sz;
2646
2647 if (linkspace) {
2648 WARN(1, "linkspace already allocated\n");
2649 return -EEXIST;
2650 }
2651
2652 if (max_ls == 0)
2653 while (ois[i++])
2654 max_ls += LINKS_PER_OCP_IF;
2655
2656 sz = sizeof(struct omap_hwmod_link) * max_ls;
2657
2658 pr_debug("omap_hwmod: %s: allocating %d byte linkspace (%d links)\n",
2659 __func__, sz, max_ls);
2660
2661 linkspace = alloc_bootmem(sz);
2662
2663 memset(linkspace, 0, sz);
2664
2665 return 0;
2666}
Paul Walmsley63c85232009-09-03 20:14:03 +03002667
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002668/* Static functions intended only for use in soc_ops field function pointers */
2669
2670/**
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002671 * _omap2xxx_wait_target_ready - wait for a module to leave slave idle
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002672 * @oh: struct omap_hwmod *
2673 *
2674 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2675 * does not have an IDLEST bit or if the module successfully leaves
2676 * slave idle; otherwise, pass along the return value of the
2677 * appropriate *_cm*_wait_module_ready() function.
2678 */
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002679static int _omap2xxx_wait_target_ready(struct omap_hwmod *oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002680{
2681 if (!oh)
2682 return -EINVAL;
2683
2684 if (oh->flags & HWMOD_NO_IDLEST)
2685 return 0;
2686
2687 if (!_find_mpu_rt_port(oh))
2688 return 0;
2689
2690 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2691
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06002692 return omap2xxx_cm_wait_module_ready(oh->prcm.omap2.module_offs,
2693 oh->prcm.omap2.idlest_reg_id,
2694 oh->prcm.omap2.idlest_idle_bit);
2695}
2696
2697/**
2698 * _omap3xxx_wait_target_ready - wait for a module to leave slave idle
2699 * @oh: struct omap_hwmod *
2700 *
2701 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2702 * does not have an IDLEST bit or if the module successfully leaves
2703 * slave idle; otherwise, pass along the return value of the
2704 * appropriate *_cm*_wait_module_ready() function.
2705 */
2706static int _omap3xxx_wait_target_ready(struct omap_hwmod *oh)
2707{
2708 if (!oh)
2709 return -EINVAL;
2710
2711 if (oh->flags & HWMOD_NO_IDLEST)
2712 return 0;
2713
2714 if (!_find_mpu_rt_port(oh))
2715 return 0;
2716
2717 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2718
2719 return omap3xxx_cm_wait_module_ready(oh->prcm.omap2.module_offs,
2720 oh->prcm.omap2.idlest_reg_id,
2721 oh->prcm.omap2.idlest_idle_bit);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002722}
2723
2724/**
2725 * _omap4_wait_target_ready - wait for a module to leave slave idle
2726 * @oh: struct omap_hwmod *
2727 *
2728 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2729 * does not have an IDLEST bit or if the module successfully leaves
2730 * slave idle; otherwise, pass along the return value of the
2731 * appropriate *_cm*_wait_module_ready() function.
2732 */
2733static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2734{
Paul Walmsley2b026d12012-09-23 17:28:18 -06002735 if (!oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002736 return -EINVAL;
2737
Paul Walmsley2b026d12012-09-23 17:28:18 -06002738 if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002739 return 0;
2740
2741 if (!_find_mpu_rt_port(oh))
2742 return 0;
2743
2744 /* XXX check module SIDLEMODE, hardreset status */
2745
2746 return omap4_cminst_wait_module_ready(oh->clkdm->prcm_partition,
2747 oh->clkdm->cm_inst,
2748 oh->clkdm->clkdm_offs,
2749 oh->prcm.omap4.clkctrl_offs);
2750}
2751
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002752/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002753 * _am33xx_wait_target_ready - wait for a module to leave slave idle
2754 * @oh: struct omap_hwmod *
2755 *
2756 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2757 * does not have an IDLEST bit or if the module successfully leaves
2758 * slave idle; otherwise, pass along the return value of the
2759 * appropriate *_cm*_wait_module_ready() function.
2760 */
2761static int _am33xx_wait_target_ready(struct omap_hwmod *oh)
2762{
2763 if (!oh || !oh->clkdm)
2764 return -EINVAL;
2765
2766 if (oh->flags & HWMOD_NO_IDLEST)
2767 return 0;
2768
2769 if (!_find_mpu_rt_port(oh))
2770 return 0;
2771
2772 /* XXX check module SIDLEMODE, hardreset status */
2773
2774 return am33xx_cm_wait_module_ready(oh->clkdm->cm_inst,
2775 oh->clkdm->clkdm_offs,
2776 oh->prcm.omap4.clkctrl_offs);
2777}
2778
2779/**
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002780 * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2781 * @oh: struct omap_hwmod * to assert hardreset
2782 * @ohri: hardreset line data
2783 *
2784 * Call omap2_prm_assert_hardreset() with parameters extracted from
2785 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2786 * use as an soc_ops function pointer. Passes along the return value
2787 * from omap2_prm_assert_hardreset(). XXX This function is scheduled
2788 * for removal when the PRM code is moved into drivers/.
2789 */
2790static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2791 struct omap_hwmod_rst_info *ohri)
2792{
2793 return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs,
2794 ohri->rst_shift);
2795}
2796
2797/**
2798 * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2799 * @oh: struct omap_hwmod * to deassert hardreset
2800 * @ohri: hardreset line data
2801 *
2802 * Call omap2_prm_deassert_hardreset() with parameters extracted from
2803 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2804 * use as an soc_ops function pointer. Passes along the return value
2805 * from omap2_prm_deassert_hardreset(). XXX This function is
2806 * scheduled for removal when the PRM code is moved into drivers/.
2807 */
2808static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2809 struct omap_hwmod_rst_info *ohri)
2810{
2811 return omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs,
2812 ohri->rst_shift,
2813 ohri->st_shift);
2814}
2815
2816/**
2817 * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2818 * @oh: struct omap_hwmod * to test hardreset
2819 * @ohri: hardreset line data
2820 *
2821 * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2822 * from the hwmod @oh and the hardreset line data @ohri. Only
2823 * intended for use as an soc_ops function pointer. Passes along the
2824 * return value from omap2_prm_is_hardreset_asserted(). XXX This
2825 * function is scheduled for removal when the PRM code is moved into
2826 * drivers/.
2827 */
2828static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2829 struct omap_hwmod_rst_info *ohri)
2830{
2831 return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs,
2832 ohri->st_shift);
2833}
2834
2835/**
2836 * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2837 * @oh: struct omap_hwmod * to assert hardreset
2838 * @ohri: hardreset line data
2839 *
2840 * Call omap4_prminst_assert_hardreset() with parameters extracted
2841 * from the hwmod @oh and the hardreset line data @ohri. Only
2842 * intended for use as an soc_ops function pointer. Passes along the
2843 * return value from omap4_prminst_assert_hardreset(). XXX This
2844 * function is scheduled for removal when the PRM code is moved into
2845 * drivers/.
2846 */
2847static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2848 struct omap_hwmod_rst_info *ohri)
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002849{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002850 if (!oh->clkdm)
2851 return -EINVAL;
2852
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002853 return omap4_prminst_assert_hardreset(ohri->rst_shift,
2854 oh->clkdm->pwrdm.ptr->prcm_partition,
2855 oh->clkdm->pwrdm.ptr->prcm_offs,
2856 oh->prcm.omap4.rstctrl_offs);
2857}
2858
2859/**
2860 * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2861 * @oh: struct omap_hwmod * to deassert hardreset
2862 * @ohri: hardreset line data
2863 *
2864 * Call omap4_prminst_deassert_hardreset() with parameters extracted
2865 * from the hwmod @oh and the hardreset line data @ohri. Only
2866 * intended for use as an soc_ops function pointer. Passes along the
2867 * return value from omap4_prminst_deassert_hardreset(). XXX This
2868 * function is scheduled for removal when the PRM code is moved into
2869 * drivers/.
2870 */
2871static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2872 struct omap_hwmod_rst_info *ohri)
2873{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002874 if (!oh->clkdm)
2875 return -EINVAL;
2876
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002877 if (ohri->st_shift)
2878 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2879 oh->name, ohri->name);
2880 return omap4_prminst_deassert_hardreset(ohri->rst_shift,
2881 oh->clkdm->pwrdm.ptr->prcm_partition,
2882 oh->clkdm->pwrdm.ptr->prcm_offs,
2883 oh->prcm.omap4.rstctrl_offs);
2884}
2885
2886/**
2887 * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2888 * @oh: struct omap_hwmod * to test hardreset
2889 * @ohri: hardreset line data
2890 *
2891 * Call omap4_prminst_is_hardreset_asserted() with parameters
2892 * extracted from the hwmod @oh and the hardreset line data @ohri.
2893 * Only intended for use as an soc_ops function pointer. Passes along
2894 * the return value from omap4_prminst_is_hardreset_asserted(). XXX
2895 * This function is scheduled for removal when the PRM code is moved
2896 * into drivers/.
2897 */
2898static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2899 struct omap_hwmod_rst_info *ohri)
2900{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002901 if (!oh->clkdm)
2902 return -EINVAL;
2903
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002904 return omap4_prminst_is_hardreset_asserted(ohri->rst_shift,
2905 oh->clkdm->pwrdm.ptr->prcm_partition,
2906 oh->clkdm->pwrdm.ptr->prcm_offs,
2907 oh->prcm.omap4.rstctrl_offs);
2908}
2909
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002910/**
2911 * _am33xx_assert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2912 * @oh: struct omap_hwmod * to assert hardreset
2913 * @ohri: hardreset line data
2914 *
2915 * Call am33xx_prminst_assert_hardreset() with parameters extracted
2916 * from the hwmod @oh and the hardreset line data @ohri. Only
2917 * intended for use as an soc_ops function pointer. Passes along the
2918 * return value from am33xx_prminst_assert_hardreset(). XXX This
2919 * function is scheduled for removal when the PRM code is moved into
2920 * drivers/.
2921 */
2922static int _am33xx_assert_hardreset(struct omap_hwmod *oh,
2923 struct omap_hwmod_rst_info *ohri)
2924
2925{
2926 return am33xx_prm_assert_hardreset(ohri->rst_shift,
2927 oh->clkdm->pwrdm.ptr->prcm_offs,
2928 oh->prcm.omap4.rstctrl_offs);
2929}
2930
2931/**
2932 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2933 * @oh: struct omap_hwmod * to deassert hardreset
2934 * @ohri: hardreset line data
2935 *
2936 * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2937 * from the hwmod @oh and the hardreset line data @ohri. Only
2938 * intended for use as an soc_ops function pointer. Passes along the
2939 * return value from am33xx_prminst_deassert_hardreset(). XXX This
2940 * function is scheduled for removal when the PRM code is moved into
2941 * drivers/.
2942 */
2943static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2944 struct omap_hwmod_rst_info *ohri)
2945{
2946 if (ohri->st_shift)
2947 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2948 oh->name, ohri->name);
2949
2950 return am33xx_prm_deassert_hardreset(ohri->rst_shift,
2951 oh->clkdm->pwrdm.ptr->prcm_offs,
2952 oh->prcm.omap4.rstctrl_offs,
2953 oh->prcm.omap4.rstst_offs);
2954}
2955
2956/**
2957 * _am33xx_is_hardreset_asserted - call AM33XX PRM hardreset fn with hwmod args
2958 * @oh: struct omap_hwmod * to test hardreset
2959 * @ohri: hardreset line data
2960 *
2961 * Call am33xx_prminst_is_hardreset_asserted() with parameters
2962 * extracted from the hwmod @oh and the hardreset line data @ohri.
2963 * Only intended for use as an soc_ops function pointer. Passes along
2964 * the return value from am33xx_prminst_is_hardreset_asserted(). XXX
2965 * This function is scheduled for removal when the PRM code is moved
2966 * into drivers/.
2967 */
2968static int _am33xx_is_hardreset_asserted(struct omap_hwmod *oh,
2969 struct omap_hwmod_rst_info *ohri)
2970{
2971 return am33xx_prm_is_hardreset_asserted(ohri->rst_shift,
2972 oh->clkdm->pwrdm.ptr->prcm_offs,
2973 oh->prcm.omap4.rstctrl_offs);
2974}
2975
Paul Walmsley63c85232009-09-03 20:14:03 +03002976/* Public functions */
2977
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002978u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002979{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002980 if (oh->flags & HWMOD_16BIT_REG)
2981 return __raw_readw(oh->_mpu_rt_va + reg_offs);
2982 else
2983 return __raw_readl(oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002984}
2985
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002986void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002987{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002988 if (oh->flags & HWMOD_16BIT_REG)
2989 __raw_writew(v, oh->_mpu_rt_va + reg_offs);
2990 else
2991 __raw_writel(v, oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002992}
2993
Paul Walmsley887adea2010-07-26 16:34:33 -06002994/**
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002995 * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
2996 * @oh: struct omap_hwmod *
2997 *
2998 * This is a public function exposed to drivers. Some drivers may need to do
2999 * some settings before and after resetting the device. Those drivers after
3000 * doing the necessary settings could use this function to start a reset by
3001 * setting the SYSCONFIG.SOFTRESET bit.
3002 */
3003int omap_hwmod_softreset(struct omap_hwmod *oh)
3004{
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06003005 u32 v;
3006 int ret;
3007
3008 if (!oh || !(oh->_sysc_cache))
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003009 return -EINVAL;
3010
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06003011 v = oh->_sysc_cache;
3012 ret = _set_softreset(oh, &v);
3013 if (ret)
3014 goto error;
3015 _write_sysconfig(v, oh);
3016
3017error:
3018 return ret;
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003019}
3020
3021/**
Paul Walmsley887adea2010-07-26 16:34:33 -06003022 * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode
3023 * @oh: struct omap_hwmod *
3024 * @idlemode: SIDLEMODE field bits (shifted to bit 0)
3025 *
3026 * Sets the IP block's OCP slave idlemode in hardware, and updates our
3027 * local copy. Intended to be used by drivers that have some erratum
3028 * that requires direct manipulation of the SIDLEMODE bits. Returns
3029 * -EINVAL if @oh is null, or passes along the return value from
3030 * _set_slave_idlemode().
3031 *
3032 * XXX Does this function have any current users? If not, we should
3033 * remove it; it is better to let the rest of the hwmod code handle this.
3034 * Any users of this function should be scrutinized carefully.
3035 */
Kevin Hilman46273e62010-01-26 20:13:03 -07003036int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode)
3037{
3038 u32 v;
3039 int retval = 0;
3040
3041 if (!oh)
3042 return -EINVAL;
3043
3044 v = oh->_sysc_cache;
3045
3046 retval = _set_slave_idlemode(oh, idlemode, &v);
3047 if (!retval)
3048 _write_sysconfig(v, oh);
3049
3050 return retval;
3051}
3052
Paul Walmsley63c85232009-09-03 20:14:03 +03003053/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003054 * omap_hwmod_lookup - look up a registered omap_hwmod by name
3055 * @name: name of the omap_hwmod to look up
3056 *
3057 * Given a @name of an omap_hwmod, return a pointer to the registered
3058 * struct omap_hwmod *, or NULL upon error.
3059 */
3060struct omap_hwmod *omap_hwmod_lookup(const char *name)
3061{
3062 struct omap_hwmod *oh;
3063
3064 if (!name)
3065 return NULL;
3066
Paul Walmsley63c85232009-09-03 20:14:03 +03003067 oh = _lookup(name);
Paul Walmsley63c85232009-09-03 20:14:03 +03003068
3069 return oh;
3070}
3071
3072/**
3073 * omap_hwmod_for_each - call function for each registered omap_hwmod
3074 * @fn: pointer to a callback function
Paul Walmsley97d60162010-07-26 16:34:30 -06003075 * @data: void * data to pass to callback function
Paul Walmsley63c85232009-09-03 20:14:03 +03003076 *
3077 * Call @fn for each registered omap_hwmod, passing @data to each
3078 * function. @fn must return 0 for success or any other value for
3079 * failure. If @fn returns non-zero, the iteration across omap_hwmods
3080 * will stop and the non-zero return value will be passed to the
3081 * caller of omap_hwmod_for_each(). @fn is called with
3082 * omap_hwmod_for_each() held.
3083 */
Paul Walmsley97d60162010-07-26 16:34:30 -06003084int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
3085 void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03003086{
3087 struct omap_hwmod *temp_oh;
Govindraj.R30ebad92011-06-01 11:28:56 +05303088 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003089
3090 if (!fn)
3091 return -EINVAL;
3092
Paul Walmsley63c85232009-09-03 20:14:03 +03003093 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
Paul Walmsley97d60162010-07-26 16:34:30 -06003094 ret = (*fn)(temp_oh, data);
Paul Walmsley63c85232009-09-03 20:14:03 +03003095 if (ret)
3096 break;
3097 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003098
3099 return ret;
3100}
3101
Paul Walmsley63c85232009-09-03 20:14:03 +03003102/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003103 * omap_hwmod_register_links - register an array of hwmod links
3104 * @ois: pointer to an array of omap_hwmod_ocp_if to register
3105 *
3106 * Intended to be called early in boot before the clock framework is
3107 * initialized. If @ois is not null, will register all omap_hwmods
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003108 * listed in @ois that are valid for this chip. Returns -EINVAL if
3109 * omap_hwmod_init() hasn't been called before calling this function,
3110 * -ENOMEM if the link memory area can't be allocated, or 0 upon
3111 * success.
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003112 */
3113int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3114{
3115 int r, i;
3116
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003117 if (!inited)
3118 return -EINVAL;
3119
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003120 if (!ois)
3121 return 0;
3122
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003123 if (!linkspace) {
3124 if (_alloc_linkspace(ois)) {
3125 pr_err("omap_hwmod: could not allocate link space\n");
3126 return -ENOMEM;
3127 }
3128 }
3129
3130 i = 0;
3131 do {
3132 r = _register_link(ois[i]);
3133 WARN(r && r != -EEXIST,
3134 "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3135 ois[i]->master->name, ois[i]->slave->name, r);
3136 } while (ois[++i]);
3137
3138 return 0;
3139}
3140
3141/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003142 * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3143 * @oh: pointer to the hwmod currently being set up (usually not the MPU)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003144 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003145 * If the hwmod data corresponding to the MPU subsystem IP block
3146 * hasn't been initialized and set up yet, do so now. This must be
3147 * done first since sleep dependencies may be added from other hwmods
3148 * to the MPU. Intended to be called only by omap_hwmod_setup*(). No
3149 * return value.
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003150 */
Paul Walmsley381d0332012-04-19 00:58:22 -06003151static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003152{
Paul Walmsley381d0332012-04-19 00:58:22 -06003153 if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3154 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3155 __func__, MPU_INITIATOR_NAME);
3156 else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3157 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
Paul Walmsley63c85232009-09-03 20:14:03 +03003158}
3159
3160/**
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003161 * omap_hwmod_setup_one - set up a single hwmod
3162 * @oh_name: const char * name of the already-registered hwmod to set up
3163 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003164 * Initialize and set up a single hwmod. Intended to be used for a
3165 * small number of early devices, such as the timer IP blocks used for
3166 * the scheduler clock. Must be called after omap2_clk_init().
3167 * Resolves the struct clk names to struct clk pointers for each
3168 * registered omap_hwmod. Also calls _setup() on each hwmod. Returns
3169 * -EINVAL upon error or 0 upon success.
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003170 */
3171int __init omap_hwmod_setup_one(const char *oh_name)
3172{
3173 struct omap_hwmod *oh;
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003174
3175 pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3176
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003177 oh = _lookup(oh_name);
3178 if (!oh) {
3179 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3180 return -EINVAL;
3181 }
3182
Paul Walmsley381d0332012-04-19 00:58:22 -06003183 _ensure_mpu_hwmod_is_setup(oh);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003184
Paul Walmsley381d0332012-04-19 00:58:22 -06003185 _init(oh, NULL);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003186 _setup(oh, NULL);
3187
3188 return 0;
3189}
3190
3191/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003192 * omap_hwmod_setup_all - set up all registered IP blocks
Paul Walmsley63c85232009-09-03 20:14:03 +03003193 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003194 * Initialize and set up all IP blocks registered with the hwmod code.
3195 * Must be called after omap2_clk_init(). Resolves the struct clk
3196 * names to struct clk pointers for each registered omap_hwmod. Also
3197 * calls _setup() on each hwmod. Returns 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003198 */
Paul Walmsley550c8092011-02-28 11:58:14 -07003199static int __init omap_hwmod_setup_all(void)
Paul Walmsley63c85232009-09-03 20:14:03 +03003200{
Paul Walmsley381d0332012-04-19 00:58:22 -06003201 _ensure_mpu_hwmod_is_setup(NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003202
Paul Walmsley381d0332012-04-19 00:58:22 -06003203 omap_hwmod_for_each(_init, NULL);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003204 omap_hwmod_for_each(_setup, NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003205
3206 return 0;
3207}
Paul Walmsley550c8092011-02-28 11:58:14 -07003208core_initcall(omap_hwmod_setup_all);
Paul Walmsley63c85232009-09-03 20:14:03 +03003209
3210/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003211 * omap_hwmod_enable - enable an omap_hwmod
3212 * @oh: struct omap_hwmod *
3213 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003214 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
Paul Walmsley63c85232009-09-03 20:14:03 +03003215 * Returns -EINVAL on error or passes along the return value from _enable().
3216 */
3217int omap_hwmod_enable(struct omap_hwmod *oh)
3218{
3219 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003220 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003221
3222 if (!oh)
3223 return -EINVAL;
3224
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003225 spin_lock_irqsave(&oh->_lock, flags);
3226 r = _enable(oh);
3227 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003228
3229 return r;
3230}
3231
3232/**
3233 * omap_hwmod_idle - idle an omap_hwmod
3234 * @oh: struct omap_hwmod *
3235 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003236 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
Paul Walmsley63c85232009-09-03 20:14:03 +03003237 * Returns -EINVAL on error or passes along the return value from _idle().
3238 */
3239int omap_hwmod_idle(struct omap_hwmod *oh)
3240{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003241 unsigned long flags;
3242
Paul Walmsley63c85232009-09-03 20:14:03 +03003243 if (!oh)
3244 return -EINVAL;
3245
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003246 spin_lock_irqsave(&oh->_lock, flags);
3247 _idle(oh);
3248 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003249
3250 return 0;
3251}
3252
3253/**
3254 * omap_hwmod_shutdown - shutdown an omap_hwmod
3255 * @oh: struct omap_hwmod *
3256 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003257 * Shutdown an omap_hwmod @oh. Intended to be called by
Paul Walmsley63c85232009-09-03 20:14:03 +03003258 * omap_device_shutdown(). Returns -EINVAL on error or passes along
3259 * the return value from _shutdown().
3260 */
3261int omap_hwmod_shutdown(struct omap_hwmod *oh)
3262{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003263 unsigned long flags;
3264
Paul Walmsley63c85232009-09-03 20:14:03 +03003265 if (!oh)
3266 return -EINVAL;
3267
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003268 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003269 _shutdown(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003270 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003271
3272 return 0;
3273}
3274
3275/**
3276 * omap_hwmod_enable_clocks - enable main_clk, all interface clocks
3277 * @oh: struct omap_hwmod *oh
3278 *
3279 * Intended to be called by the omap_device code.
3280 */
3281int omap_hwmod_enable_clocks(struct omap_hwmod *oh)
3282{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003283 unsigned long flags;
3284
3285 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003286 _enable_clocks(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003287 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003288
3289 return 0;
3290}
3291
3292/**
3293 * omap_hwmod_disable_clocks - disable main_clk, all interface clocks
3294 * @oh: struct omap_hwmod *oh
3295 *
3296 * Intended to be called by the omap_device code.
3297 */
3298int omap_hwmod_disable_clocks(struct omap_hwmod *oh)
3299{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003300 unsigned long flags;
3301
3302 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003303 _disable_clocks(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003304 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003305
3306 return 0;
3307}
3308
3309/**
3310 * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete
3311 * @oh: struct omap_hwmod *oh
3312 *
3313 * Intended to be called by drivers and core code when all posted
3314 * writes to a device must complete before continuing further
3315 * execution (for example, after clearing some device IRQSTATUS
3316 * register bits)
3317 *
3318 * XXX what about targets with multiple OCP threads?
3319 */
3320void omap_hwmod_ocp_barrier(struct omap_hwmod *oh)
3321{
3322 BUG_ON(!oh);
3323
Paul Walmsley43b40992010-02-22 22:09:34 -07003324 if (!oh->class->sysc || !oh->class->sysc->sysc_flags) {
Russell King4f8a4282012-02-07 10:59:37 +00003325 WARN(1, "omap_device: %s: OCP barrier impossible due to device configuration\n",
3326 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03003327 return;
3328 }
3329
3330 /*
3331 * Forces posted writes to complete on the OCP thread handling
3332 * register writes
3333 */
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07003334 omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03003335}
3336
3337/**
3338 * omap_hwmod_reset - reset the hwmod
3339 * @oh: struct omap_hwmod *
3340 *
3341 * Under some conditions, a driver may wish to reset the entire device.
3342 * Called from omap_device code. Returns -EINVAL on error or passes along
Liam Girdwood9b579112010-09-21 10:34:09 -06003343 * the return value from _reset().
Paul Walmsley63c85232009-09-03 20:14:03 +03003344 */
3345int omap_hwmod_reset(struct omap_hwmod *oh)
3346{
3347 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003348 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003349
Liam Girdwood9b579112010-09-21 10:34:09 -06003350 if (!oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03003351 return -EINVAL;
3352
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003353 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003354 r = _reset(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003355 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003356
3357 return r;
3358}
3359
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003360/*
3361 * IP block data retrieval functions
3362 */
3363
Paul Walmsley63c85232009-09-03 20:14:03 +03003364/**
3365 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
3366 * @oh: struct omap_hwmod *
3367 * @res: pointer to the first element of an array of struct resource to fill
3368 *
3369 * Count the number of struct resource array elements necessary to
3370 * contain omap_hwmod @oh resources. Intended to be called by code
3371 * that registers omap_devices. Intended to be used to determine the
3372 * size of a dynamically-allocated struct resource array, before
3373 * calling omap_hwmod_fill_resources(). Returns the number of struct
3374 * resource array elements needed.
3375 *
3376 * XXX This code is not optimized. It could attempt to merge adjacent
3377 * resource IDs.
3378 *
3379 */
3380int omap_hwmod_count_resources(struct omap_hwmod *oh)
3381{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003382 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003383 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003384 int ret;
3385 int i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003386
Paul Walmsleybc614952011-07-09 19:14:07 -06003387 ret = _count_mpu_irqs(oh) + _count_sdma_reqs(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03003388
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003389 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003390
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003391 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003392 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003393 ret += _count_ocp_if_addr_spaces(os);
3394 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003395
3396 return ret;
3397}
3398
3399/**
3400 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
3401 * @oh: struct omap_hwmod *
3402 * @res: pointer to the first element of an array of struct resource to fill
3403 *
3404 * Fill the struct resource array @res with resource data from the
3405 * omap_hwmod @oh. Intended to be called by code that registers
3406 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3407 * number of array elements filled.
3408 */
3409int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3410{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003411 struct omap_hwmod_ocp_if *os;
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003412 struct list_head *p;
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003413 int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
Paul Walmsley63c85232009-09-03 20:14:03 +03003414 int r = 0;
3415
3416 /* For each IRQ, DMA, memory area, fill in array.*/
3417
Paul Walmsley212738a2011-07-09 19:14:06 -06003418 mpu_irqs_cnt = _count_mpu_irqs(oh);
3419 for (i = 0; i < mpu_irqs_cnt; i++) {
Paul Walmsley718bfd72009-12-08 16:34:16 -07003420 (res + r)->name = (oh->mpu_irqs + i)->name;
3421 (res + r)->start = (oh->mpu_irqs + i)->irq;
3422 (res + r)->end = (oh->mpu_irqs + i)->irq;
Paul Walmsley63c85232009-09-03 20:14:03 +03003423 (res + r)->flags = IORESOURCE_IRQ;
3424 r++;
3425 }
3426
Paul Walmsleybc614952011-07-09 19:14:07 -06003427 sdma_reqs_cnt = _count_sdma_reqs(oh);
3428 for (i = 0; i < sdma_reqs_cnt; i++) {
Benoit Cousson9ee9fff2010-09-21 10:34:08 -06003429 (res + r)->name = (oh->sdma_reqs + i)->name;
3430 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3431 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
Paul Walmsley63c85232009-09-03 20:14:03 +03003432 (res + r)->flags = IORESOURCE_DMA;
3433 r++;
3434 }
3435
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003436 p = oh->slave_ports.next;
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003437
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003438 i = 0;
3439 while (i < oh->slaves_cnt) {
Paul Walmsley11cd4b92012-04-19 04:04:32 -06003440 os = _fetch_next_ocp_if(&p, &i);
Paul Walmsley78183f32011-07-09 19:14:05 -06003441 addr_cnt = _count_ocp_if_addr_spaces(os);
Paul Walmsley63c85232009-09-03 20:14:03 +03003442
Paul Walmsley78183f32011-07-09 19:14:05 -06003443 for (j = 0; j < addr_cnt; j++) {
Kishon Vijay Abraham Icd503802011-02-24 12:51:45 -08003444 (res + r)->name = (os->addr + j)->name;
Paul Walmsley63c85232009-09-03 20:14:03 +03003445 (res + r)->start = (os->addr + j)->pa_start;
3446 (res + r)->end = (os->addr + j)->pa_end;
3447 (res + r)->flags = IORESOURCE_MEM;
3448 r++;
3449 }
3450 }
3451
3452 return r;
3453}
3454
3455/**
Vaibhav Hiremathb82b04e2012-08-29 15:18:11 +05303456 * omap_hwmod_fill_dma_resources - fill struct resource array with dma data
3457 * @oh: struct omap_hwmod *
3458 * @res: pointer to the array of struct resource to fill
3459 *
3460 * Fill the struct resource array @res with dma resource data from the
3461 * omap_hwmod @oh. Intended to be called by code that registers
3462 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3463 * number of array elements filled.
3464 */
3465int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res)
3466{
3467 int i, sdma_reqs_cnt;
3468 int r = 0;
3469
3470 sdma_reqs_cnt = _count_sdma_reqs(oh);
3471 for (i = 0; i < sdma_reqs_cnt; i++) {
3472 (res + r)->name = (oh->sdma_reqs + i)->name;
3473 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3474 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3475 (res + r)->flags = IORESOURCE_DMA;
3476 r++;
3477 }
3478
3479 return r;
3480}
3481
3482/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003483 * omap_hwmod_get_resource_byname - fetch IP block integration data by name
3484 * @oh: struct omap_hwmod * to operate on
3485 * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
3486 * @name: pointer to the name of the data to fetch (optional)
3487 * @rsrc: pointer to a struct resource, allocated by the caller
3488 *
3489 * Retrieve MPU IRQ, SDMA request line, or address space start/end
3490 * data for the IP block pointed to by @oh. The data will be filled
3491 * into a struct resource record pointed to by @rsrc. The struct
3492 * resource must be allocated by the caller. When @name is non-null,
3493 * the data associated with the matching entry in the IRQ/SDMA/address
3494 * space hwmod data arrays will be returned. If @name is null, the
3495 * first array entry will be returned. Data order is not meaningful
3496 * in hwmod data, so callers are strongly encouraged to use a non-null
3497 * @name whenever possible to avoid unpredictable effects if hwmod
3498 * data is later added that causes data ordering to change. This
3499 * function is only intended for use by OMAP core code. Device
3500 * drivers should not call this function - the appropriate bus-related
3501 * data accessor functions should be used instead. Returns 0 upon
3502 * success or a negative error code upon error.
3503 */
3504int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
3505 const char *name, struct resource *rsrc)
3506{
3507 int r;
3508 unsigned int irq, dma;
3509 u32 pa_start, pa_end;
3510
3511 if (!oh || !rsrc)
3512 return -EINVAL;
3513
3514 if (type == IORESOURCE_IRQ) {
3515 r = _get_mpu_irq_by_name(oh, name, &irq);
3516 if (r)
3517 return r;
3518
3519 rsrc->start = irq;
3520 rsrc->end = irq;
3521 } else if (type == IORESOURCE_DMA) {
3522 r = _get_sdma_req_by_name(oh, name, &dma);
3523 if (r)
3524 return r;
3525
3526 rsrc->start = dma;
3527 rsrc->end = dma;
3528 } else if (type == IORESOURCE_MEM) {
3529 r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
3530 if (r)
3531 return r;
3532
3533 rsrc->start = pa_start;
3534 rsrc->end = pa_end;
3535 } else {
3536 return -EINVAL;
3537 }
3538
3539 rsrc->flags = type;
3540 rsrc->name = name;
3541
3542 return 0;
3543}
3544
3545/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003546 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3547 * @oh: struct omap_hwmod *
3548 *
3549 * Return the powerdomain pointer associated with the OMAP module
3550 * @oh's main clock. If @oh does not have a main clk, return the
3551 * powerdomain associated with the interface clock associated with the
3552 * module's MPU port. (XXX Perhaps this should use the SDMA port
3553 * instead?) Returns NULL on error, or a struct powerdomain * on
3554 * success.
3555 */
3556struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3557{
3558 struct clk *c;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003559 struct omap_hwmod_ocp_if *oi;
Paul Walmsley63c85232009-09-03 20:14:03 +03003560
3561 if (!oh)
3562 return NULL;
3563
3564 if (oh->_clk) {
3565 c = oh->_clk;
3566 } else {
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003567 oi = _find_mpu_rt_port(oh);
3568 if (!oi)
Paul Walmsley63c85232009-09-03 20:14:03 +03003569 return NULL;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003570 c = oi->_clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003571 }
3572
Thara Gopinathd5647c12010-03-31 04:16:29 -06003573 if (!c->clkdm)
3574 return NULL;
3575
Paul Walmsley63c85232009-09-03 20:14:03 +03003576 return c->clkdm->pwrdm.ptr;
3577
3578}
3579
3580/**
Paul Walmsleydb2a60b2010-07-26 16:34:33 -06003581 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3582 * @oh: struct omap_hwmod *
3583 *
3584 * Returns the virtual address corresponding to the beginning of the
3585 * module's register target, in the address range that is intended to
3586 * be used by the MPU. Returns the virtual address upon success or NULL
3587 * upon error.
3588 */
3589void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3590{
3591 if (!oh)
3592 return NULL;
3593
3594 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3595 return NULL;
3596
3597 if (oh->_state == _HWMOD_STATE_UNKNOWN)
3598 return NULL;
3599
3600 return oh->_mpu_rt_va;
3601}
3602
3603/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003604 * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh
3605 * @oh: struct omap_hwmod *
3606 * @init_oh: struct omap_hwmod * (initiator)
3607 *
3608 * Add a sleep dependency between the initiator @init_oh and @oh.
3609 * Intended to be called by DSP/Bridge code via platform_data for the
3610 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
3611 * code needs to add/del initiator dependencies dynamically
3612 * before/after accessing a device. Returns the return value from
3613 * _add_initiator_dep().
3614 *
3615 * XXX Keep a usecount in the clockdomain code
3616 */
3617int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh,
3618 struct omap_hwmod *init_oh)
3619{
3620 return _add_initiator_dep(oh, init_oh);
3621}
3622
3623/*
3624 * XXX what about functions for drivers to save/restore ocp_sysconfig
3625 * for context save/restore operations?
3626 */
3627
3628/**
3629 * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh
3630 * @oh: struct omap_hwmod *
3631 * @init_oh: struct omap_hwmod * (initiator)
3632 *
3633 * Remove a sleep dependency between the initiator @init_oh and @oh.
3634 * Intended to be called by DSP/Bridge code via platform_data for the
3635 * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge
3636 * code needs to add/del initiator dependencies dynamically
3637 * before/after accessing a device. Returns the return value from
3638 * _del_initiator_dep().
3639 *
3640 * XXX Keep a usecount in the clockdomain code
3641 */
3642int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh,
3643 struct omap_hwmod *init_oh)
3644{
3645 return _del_initiator_dep(oh, init_oh);
3646}
3647
3648/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003649 * omap_hwmod_enable_wakeup - allow device to wake up the system
3650 * @oh: struct omap_hwmod *
3651 *
3652 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
Govindraj.R2a1cc142012-04-05 02:59:32 -06003653 * send wakeups to the PRCM, and enable I/O ring wakeup events for
3654 * this IP block if it has dynamic mux entries. Eventually this
3655 * should set PRCM wakeup registers to cause the PRCM to receive
3656 * wakeup events from the module. Does not set any wakeup routing
3657 * registers beyond this point - if the module is to wake up any other
3658 * module or subsystem, that must be set separately. Called by
3659 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003660 */
3661int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3662{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003663 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003664 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003665
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003666 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003667
3668 if (oh->class->sysc &&
3669 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3670 v = oh->_sysc_cache;
3671 _enable_wakeup(oh, &v);
3672 _write_sysconfig(v, oh);
3673 }
3674
Govindraj Receec002011-12-16 14:36:58 -07003675 _set_idle_ioring_wakeup(oh, true);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003676 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003677
3678 return 0;
3679}
3680
3681/**
3682 * omap_hwmod_disable_wakeup - prevent device from waking the system
3683 * @oh: struct omap_hwmod *
3684 *
3685 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
Govindraj.R2a1cc142012-04-05 02:59:32 -06003686 * from sending wakeups to the PRCM, and disable I/O ring wakeup
3687 * events for this IP block if it has dynamic mux entries. Eventually
3688 * this should clear PRCM wakeup registers to cause the PRCM to ignore
3689 * wakeup events from the module. Does not set any wakeup routing
3690 * registers beyond this point - if the module is to wake up any other
3691 * module or subsystem, that must be set separately. Called by
3692 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003693 */
3694int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3695{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003696 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003697 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003698
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003699 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003700
3701 if (oh->class->sysc &&
3702 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3703 v = oh->_sysc_cache;
3704 _disable_wakeup(oh, &v);
3705 _write_sysconfig(v, oh);
3706 }
3707
Govindraj Receec002011-12-16 14:36:58 -07003708 _set_idle_ioring_wakeup(oh, false);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003709 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003710
3711 return 0;
3712}
Paul Walmsley43b40992010-02-22 22:09:34 -07003713
3714/**
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003715 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3716 * contained in the hwmod module.
3717 * @oh: struct omap_hwmod *
3718 * @name: name of the reset line to lookup and assert
3719 *
3720 * Some IP like dsp, ipu or iva contain processor that require
3721 * an HW reset line to be assert / deassert in order to enable fully
3722 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3723 * yet supported on this OMAP; otherwise, passes along the return value
3724 * from _assert_hardreset().
3725 */
3726int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3727{
3728 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003729 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003730
3731 if (!oh)
3732 return -EINVAL;
3733
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003734 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003735 ret = _assert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003736 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003737
3738 return ret;
3739}
3740
3741/**
3742 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3743 * contained in the hwmod module.
3744 * @oh: struct omap_hwmod *
3745 * @name: name of the reset line to look up and deassert
3746 *
3747 * Some IP like dsp, ipu or iva contain processor that require
3748 * an HW reset line to be assert / deassert in order to enable fully
3749 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3750 * yet supported on this OMAP; otherwise, passes along the return value
3751 * from _deassert_hardreset().
3752 */
3753int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3754{
3755 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003756 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003757
3758 if (!oh)
3759 return -EINVAL;
3760
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003761 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003762 ret = _deassert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003763 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003764
3765 return ret;
3766}
3767
3768/**
3769 * omap_hwmod_read_hardreset - read the HW reset line state of submodules
3770 * contained in the hwmod module
3771 * @oh: struct omap_hwmod *
3772 * @name: name of the reset line to look up and read
3773 *
3774 * Return the current state of the hwmod @oh's reset line named @name:
3775 * returns -EINVAL upon parameter error or if this operation
3776 * is unsupported on the current OMAP; otherwise, passes along the return
3777 * value from _read_hardreset().
3778 */
3779int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name)
3780{
3781 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003782 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003783
3784 if (!oh)
3785 return -EINVAL;
3786
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003787 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003788 ret = _read_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003789 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003790
3791 return ret;
3792}
3793
3794
3795/**
Paul Walmsley43b40992010-02-22 22:09:34 -07003796 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3797 * @classname: struct omap_hwmod_class name to search for
3798 * @fn: callback function pointer to call for each hwmod in class @classname
3799 * @user: arbitrary context data to pass to the callback function
3800 *
Benoit Coussonce35b242010-12-21 21:31:28 -07003801 * For each omap_hwmod of class @classname, call @fn.
3802 * If the callback function returns something other than
Paul Walmsley43b40992010-02-22 22:09:34 -07003803 * zero, the iterator is terminated, and the callback function's return
3804 * value is passed back to the caller. Returns 0 upon success, -EINVAL
3805 * if @classname or @fn are NULL, or passes back the error code from @fn.
3806 */
3807int omap_hwmod_for_each_by_class(const char *classname,
3808 int (*fn)(struct omap_hwmod *oh,
3809 void *user),
3810 void *user)
3811{
3812 struct omap_hwmod *temp_oh;
3813 int ret = 0;
3814
3815 if (!classname || !fn)
3816 return -EINVAL;
3817
3818 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3819 __func__, classname);
3820
Paul Walmsley43b40992010-02-22 22:09:34 -07003821 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3822 if (!strcmp(temp_oh->class->name, classname)) {
3823 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3824 __func__, temp_oh->name);
3825 ret = (*fn)(temp_oh, user);
3826 if (ret)
3827 break;
3828 }
3829 }
3830
Paul Walmsley43b40992010-02-22 22:09:34 -07003831 if (ret)
3832 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3833 __func__, ret);
3834
3835 return ret;
3836}
3837
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003838/**
3839 * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3840 * @oh: struct omap_hwmod *
3841 * @state: state that _setup() should leave the hwmod in
3842 *
Paul Walmsley550c8092011-02-28 11:58:14 -07003843 * Sets the hwmod state that @oh will enter at the end of _setup()
Paul Walmsley64813c32012-04-18 19:10:03 -06003844 * (called by omap_hwmod_setup_*()). See also the documentation
3845 * for _setup_postsetup(), above. Returns 0 upon success or
3846 * -EINVAL if there is a problem with the arguments or if the hwmod is
3847 * in the wrong state.
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003848 */
3849int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3850{
3851 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003852 unsigned long flags;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003853
3854 if (!oh)
3855 return -EINVAL;
3856
3857 if (state != _HWMOD_STATE_DISABLED &&
3858 state != _HWMOD_STATE_ENABLED &&
3859 state != _HWMOD_STATE_IDLE)
3860 return -EINVAL;
3861
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003862 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003863
3864 if (oh->_state != _HWMOD_STATE_REGISTERED) {
3865 ret = -EINVAL;
3866 goto ohsps_unlock;
3867 }
3868
3869 oh->_postsetup_state = state;
3870 ret = 0;
3871
3872ohsps_unlock:
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003873 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003874
3875 return ret;
3876}
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003877
3878/**
3879 * omap_hwmod_get_context_loss_count - get lost context count
3880 * @oh: struct omap_hwmod *
3881 *
3882 * Query the powerdomain of of @oh to get the context loss
3883 * count for this device.
3884 *
3885 * Returns the context loss count of the powerdomain assocated with @oh
3886 * upon success, or zero if no powerdomain exists for @oh.
3887 */
Tomi Valkeinenfc013872011-06-09 16:56:23 +03003888int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003889{
3890 struct powerdomain *pwrdm;
3891 int ret = 0;
3892
3893 pwrdm = omap_hwmod_get_pwrdm(oh);
3894 if (pwrdm)
3895 ret = pwrdm_get_context_loss_count(pwrdm);
3896
3897 return ret;
3898}
Paul Walmsley43b01642011-03-10 03:50:07 -07003899
3900/**
3901 * omap_hwmod_no_setup_reset - prevent a hwmod from being reset upon setup
3902 * @oh: struct omap_hwmod *
3903 *
3904 * Prevent the hwmod @oh from being reset during the setup process.
3905 * Intended for use by board-*.c files on boards with devices that
3906 * cannot tolerate being reset. Must be called before the hwmod has
3907 * been set up. Returns 0 upon success or negative error code upon
3908 * failure.
3909 */
3910int omap_hwmod_no_setup_reset(struct omap_hwmod *oh)
3911{
3912 if (!oh)
3913 return -EINVAL;
3914
3915 if (oh->_state != _HWMOD_STATE_REGISTERED) {
3916 pr_err("omap_hwmod: %s: cannot prevent setup reset; in wrong state\n",
3917 oh->name);
3918 return -EINVAL;
3919 }
3920
3921 oh->flags |= HWMOD_INIT_NO_RESET;
3922
3923 return 0;
3924}
Tero Kristoabc2d542011-12-16 14:36:59 -07003925
3926/**
3927 * omap_hwmod_pad_route_irq - route an I/O pad wakeup to a particular MPU IRQ
3928 * @oh: struct omap_hwmod * containing hwmod mux entries
3929 * @pad_idx: array index in oh->mux of the hwmod mux entry to route wakeup
3930 * @irq_idx: the hwmod mpu_irqs array index of the IRQ to trigger on wakeup
3931 *
3932 * When an I/O pad wakeup arrives for the dynamic or wakeup hwmod mux
3933 * entry number @pad_idx for the hwmod @oh, trigger the interrupt
3934 * service routine for the hwmod's mpu_irqs array index @irq_idx. If
3935 * this function is not called for a given pad_idx, then the ISR
3936 * associated with @oh's first MPU IRQ will be triggered when an I/O
3937 * pad wakeup occurs on that pad. Note that @pad_idx is the index of
3938 * the _dynamic or wakeup_ entry: if there are other entries not
3939 * marked with OMAP_DEVICE_PAD_WAKEUP or OMAP_DEVICE_PAD_REMUX, these
3940 * entries are NOT COUNTED in the dynamic pad index. This function
3941 * must be called separately for each pad that requires its interrupt
3942 * to be re-routed this way. Returns -EINVAL if there is an argument
3943 * problem or if @oh does not have hwmod mux entries or MPU IRQs;
3944 * returns -ENOMEM if memory cannot be allocated; or 0 upon success.
3945 *
3946 * XXX This function interface is fragile. Rather than using array
3947 * indexes, which are subject to unpredictable change, it should be
3948 * using hwmod IRQ names, and some other stable key for the hwmod mux
3949 * pad records.
3950 */
3951int omap_hwmod_pad_route_irq(struct omap_hwmod *oh, int pad_idx, int irq_idx)
3952{
3953 int nr_irqs;
3954
3955 might_sleep();
3956
3957 if (!oh || !oh->mux || !oh->mpu_irqs || pad_idx < 0 ||
3958 pad_idx >= oh->mux->nr_pads_dynamic)
3959 return -EINVAL;
3960
3961 /* Check the number of available mpu_irqs */
3962 for (nr_irqs = 0; oh->mpu_irqs[nr_irqs].irq >= 0; nr_irqs++)
3963 ;
3964
3965 if (irq_idx >= nr_irqs)
3966 return -EINVAL;
3967
3968 if (!oh->mux->irqs) {
3969 /* XXX What frees this? */
3970 oh->mux->irqs = kzalloc(sizeof(int) * oh->mux->nr_pads_dynamic,
3971 GFP_KERNEL);
3972 if (!oh->mux->irqs)
3973 return -ENOMEM;
3974 }
3975 oh->mux->irqs[pad_idx] = irq_idx;
3976
3977 return 0;
3978}
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003979
3980/**
3981 * omap_hwmod_init - initialize the hwmod code
3982 *
3983 * Sets up some function pointers needed by the hwmod code to operate on the
3984 * currently-booted SoC. Intended to be called once during kernel init
3985 * before any hwmods are registered. No return value.
3986 */
3987void __init omap_hwmod_init(void)
3988{
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06003989 if (cpu_is_omap24xx()) {
3990 soc_ops.wait_target_ready = _omap2xxx_wait_target_ready;
3991 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3992 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3993 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3994 } else if (cpu_is_omap34xx()) {
3995 soc_ops.wait_target_ready = _omap3xxx_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06003996 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3997 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3998 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
R Sricharan05e152c2012-06-05 16:21:32 +05303999 } else if (cpu_is_omap44xx() || soc_is_omap54xx()) {
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004000 soc_ops.enable_module = _omap4_enable_module;
4001 soc_ops.disable_module = _omap4_disable_module;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004002 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06004003 soc_ops.assert_hardreset = _omap4_assert_hardreset;
4004 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
4005 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Kevin Hilman0a179ea2012-06-18 12:12:25 -06004006 soc_ops.init_clkdm = _init_clkdm;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06004007 } else if (soc_is_am33xx()) {
4008 soc_ops.enable_module = _am33xx_enable_module;
4009 soc_ops.disable_module = _am33xx_disable_module;
4010 soc_ops.wait_target_ready = _am33xx_wait_target_ready;
4011 soc_ops.assert_hardreset = _am33xx_assert_hardreset;
4012 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
4013 soc_ops.is_hardreset_asserted = _am33xx_is_hardreset_asserted;
4014 soc_ops.init_clkdm = _init_clkdm;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004015 } else {
4016 WARN(1, "omap_hwmod: unknown SoC type\n");
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004017 }
4018
4019 inited = true;
4020}
Tony Lindgren68c9a952012-07-06 00:58:43 -07004021
4022/**
4023 * omap_hwmod_get_main_clk - get pointer to main clock name
4024 * @oh: struct omap_hwmod *
4025 *
4026 * Returns the main clock name assocated with @oh upon success,
4027 * or NULL if @oh is NULL.
4028 */
4029const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
4030{
4031 if (!oh)
4032 return NULL;
4033
4034 return oh->main_clk;
4035}