blob: 0f7afdaf80d3c11a51edc753a38d4b8fee57aafb [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 |
Victor Kamenskyedfaf052014-04-15 20:37:46 +030075 * | ({read,write}l_relaxed, clk*) |
Paul Walmsley74ff3a62010-09-21 15:02:23 -060076 * +-------------------------------+
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>
Stephen Boydf5b00f62015-06-22 17:05:21 -0700133#include <linux/clk.h>
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700134#include <linux/clk-provider.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300135#include <linux/delay.h>
136#include <linux/err.h>
137#include <linux/list.h>
138#include <linux/mutex.h>
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -0700139#include <linux/spinlock.h>
Tero Kristoabc2d542011-12-16 14:36:59 -0700140#include <linux/slab.h>
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +0100141#include <linux/cpu.h>
Santosh Shilimkar079abad2013-01-21 18:40:57 +0530142#include <linux/of.h>
143#include <linux/of_address.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300144
Paul Walmsleyfa200222013-01-26 00:48:56 -0700145#include <asm/system_misc.h>
146
Paul Walmsleya135eaa2012-09-27 10:33:34 -0600147#include "clock.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -0700148#include "omap_hwmod.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300149
Tony Lindgrendbc04162012-08-31 10:59:07 -0700150#include "soc.h"
151#include "common.h"
152#include "clockdomain.h"
153#include "powerdomain.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -0600154#include "cm2xxx.h"
155#include "cm3xxx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600156#include "cm33xx.h"
Paul Walmsleyb13159a2012-10-29 20:57:44 -0600157#include "prm.h"
Paul Walmsley139563a2012-10-21 01:01:10 -0600158#include "prm3xxx.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -0700159#include "prm44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600160#include "prm33xx.h"
Benoit Coussoneaac3292011-07-10 05:56:31 -0600161#include "prminst44xx.h"
Vishwanath BS51658822012-06-22 08:40:04 -0600162#include "pm.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300163
Paul Walmsley63c85232009-09-03 20:14:03 +0300164/* Name of the OMAP hwmod for the MPU */
Benoit Cousson5c2c0292010-05-20 12:31:10 -0600165#define MPU_INITIATOR_NAME "mpu"
Paul Walmsley63c85232009-09-03 20:14:03 +0300166
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600167/*
168 * Number of struct omap_hwmod_link records per struct
169 * omap_hwmod_ocp_if record (master->slave and slave->master)
170 */
171#define LINKS_PER_OCP_IF 2
172
Tero Kristo4ebf5b22015-05-05 16:33:04 +0300173/*
174 * Address offset (in bytes) between the reset control and the reset
175 * status registers: 4 bytes on OMAP4
176 */
177#define OMAP4_RST_CTRL_ST_OFFSET 4
178
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300179/*
180 * Maximum length for module clock handle names
181 */
182#define MOD_CLK_MAX_NAME_LEN 32
183
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600184/**
185 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
186 * @enable_module: function to enable a module (via MODULEMODE)
187 * @disable_module: function to disable a module (via MODULEMODE)
188 *
189 * XXX Eventually this functionality will be hidden inside the PRM/CM
190 * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
191 * conditionals in this code.
192 */
193struct omap_hwmod_soc_ops {
194 void (*enable_module)(struct omap_hwmod *oh);
195 int (*disable_module)(struct omap_hwmod *oh);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -0600196 int (*wait_target_ready)(struct omap_hwmod *oh);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -0600197 int (*assert_hardreset)(struct omap_hwmod *oh,
198 struct omap_hwmod_rst_info *ohri);
199 int (*deassert_hardreset)(struct omap_hwmod *oh,
200 struct omap_hwmod_rst_info *ohri);
201 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
202 struct omap_hwmod_rst_info *ohri);
Kevin Hilman0a179ea2012-06-18 12:12:25 -0600203 int (*init_clkdm)(struct omap_hwmod *oh);
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700204 void (*update_context_lost)(struct omap_hwmod *oh);
205 int (*get_context_lost)(struct omap_hwmod *oh);
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300206 int (*disable_direct_prcm)(struct omap_hwmod *oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600207};
208
209/* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
210static struct omap_hwmod_soc_ops soc_ops;
211
Paul Walmsley63c85232009-09-03 20:14:03 +0300212/* omap_hwmod_list contains all registered struct omap_hwmods */
213static LIST_HEAD(omap_hwmod_list);
214
Paul Walmsley63c85232009-09-03 20:14:03 +0300215/* mpu_oh: used to add/remove MPU initiator from sleepdep list */
216static struct omap_hwmod *mpu_oh;
217
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600218/* inited: set to true once the hwmod code is initialized */
219static bool inited;
220
Paul Walmsley63c85232009-09-03 20:14:03 +0300221/* Private functions */
222
223/**
224 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
225 * @oh: struct omap_hwmod *
226 *
227 * Load the current value of the hwmod OCP_SYSCONFIG register into the
228 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
229 * OCP_SYSCONFIG register or 0 upon success.
230 */
231static int _update_sysc_cache(struct omap_hwmod *oh)
232{
Paul Walmsley43b40992010-02-22 22:09:34 -0700233 if (!oh->class->sysc) {
234 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 +0300235 return -EINVAL;
236 }
237
238 /* XXX ensure module interface clock is up */
239
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -0700240 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300241
Paul Walmsley43b40992010-02-22 22:09:34 -0700242 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
Thara Gopinath883edfd2010-01-19 17:30:51 -0700243 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
Paul Walmsley63c85232009-09-03 20:14:03 +0300244
245 return 0;
246}
247
248/**
249 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
250 * @v: OCP_SYSCONFIG value to write
251 * @oh: struct omap_hwmod *
252 *
Paul Walmsley43b40992010-02-22 22:09:34 -0700253 * Write @v into the module class' OCP_SYSCONFIG register, if it has
254 * one. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +0300255 */
256static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
257{
Paul Walmsley43b40992010-02-22 22:09:34 -0700258 if (!oh->class->sysc) {
259 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 +0300260 return;
261 }
262
263 /* XXX ensure module interface clock is up */
264
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700265 /* Module might have lost context, always update cache and register */
266 oh->_sysc_cache = v;
Lokesh Vutlaaaf2c0f2015-06-10 14:56:24 +0530267
268 /*
269 * Some IP blocks (such as RTC) require unlocking of IP before
270 * accessing its registers. If a function pointer is present
271 * to unlock, then call it before accessing sysconfig and
272 * call lock after writing sysconfig.
273 */
274 if (oh->class->unlock)
275 oh->class->unlock(oh);
276
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700277 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
Lokesh Vutlaaaf2c0f2015-06-10 14:56:24 +0530278
279 if (oh->class->lock)
280 oh->class->lock(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +0300281}
282
283/**
284 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
285 * @oh: struct omap_hwmod *
286 * @standbymode: MIDLEMODE field bits
287 * @v: pointer to register contents to modify
288 *
289 * Update the master standby mode bits in @v to be @standbymode for
290 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
291 * upon error or 0 upon success.
292 */
293static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
294 u32 *v)
295{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700296 u32 mstandby_mask;
297 u8 mstandby_shift;
298
Paul Walmsley43b40992010-02-22 22:09:34 -0700299 if (!oh->class->sysc ||
300 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300301 return -EINVAL;
302
Paul Walmsley43b40992010-02-22 22:09:34 -0700303 if (!oh->class->sysc->sysc_fields) {
304 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700305 return -EINVAL;
306 }
307
Paul Walmsley43b40992010-02-22 22:09:34 -0700308 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700309 mstandby_mask = (0x3 << mstandby_shift);
310
311 *v &= ~mstandby_mask;
312 *v |= __ffs(standbymode) << mstandby_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300313
314 return 0;
315}
316
317/**
318 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
319 * @oh: struct omap_hwmod *
320 * @idlemode: SIDLEMODE field bits
321 * @v: pointer to register contents to modify
322 *
323 * Update the slave idle mode bits in @v to be @idlemode for the @oh
324 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
325 * or 0 upon success.
326 */
327static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
328{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700329 u32 sidle_mask;
330 u8 sidle_shift;
331
Paul Walmsley43b40992010-02-22 22:09:34 -0700332 if (!oh->class->sysc ||
333 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300334 return -EINVAL;
335
Paul Walmsley43b40992010-02-22 22:09:34 -0700336 if (!oh->class->sysc->sysc_fields) {
337 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700338 return -EINVAL;
339 }
340
Paul Walmsley43b40992010-02-22 22:09:34 -0700341 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700342 sidle_mask = (0x3 << sidle_shift);
343
344 *v &= ~sidle_mask;
345 *v |= __ffs(idlemode) << sidle_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300346
347 return 0;
348}
349
350/**
351 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
352 * @oh: struct omap_hwmod *
353 * @clockact: CLOCKACTIVITY field bits
354 * @v: pointer to register contents to modify
355 *
356 * Update the clockactivity mode bits in @v to be @clockact for the
357 * @oh hwmod. Used for additional powersaving on some modules. Does
358 * not write to the hardware. Returns -EINVAL upon error or 0 upon
359 * success.
360 */
361static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
362{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700363 u32 clkact_mask;
364 u8 clkact_shift;
365
Paul Walmsley43b40992010-02-22 22:09:34 -0700366 if (!oh->class->sysc ||
367 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
Paul Walmsley63c85232009-09-03 20:14:03 +0300368 return -EINVAL;
369
Paul Walmsley43b40992010-02-22 22:09:34 -0700370 if (!oh->class->sysc->sysc_fields) {
371 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700372 return -EINVAL;
373 }
374
Paul Walmsley43b40992010-02-22 22:09:34 -0700375 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700376 clkact_mask = (0x3 << clkact_shift);
377
378 *v &= ~clkact_mask;
379 *v |= clockact << clkact_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300380
381 return 0;
382}
383
384/**
Roger Quadros313a76e2013-12-08 18:39:02 -0700385 * _set_softreset: set OCP_SYSCONFIG.SOFTRESET bit in @v
Paul Walmsley63c85232009-09-03 20:14:03 +0300386 * @oh: struct omap_hwmod *
387 * @v: pointer to register contents to modify
388 *
389 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
390 * error or 0 upon success.
391 */
392static int _set_softreset(struct omap_hwmod *oh, u32 *v)
393{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700394 u32 softrst_mask;
395
Paul Walmsley43b40992010-02-22 22:09:34 -0700396 if (!oh->class->sysc ||
397 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley63c85232009-09-03 20:14:03 +0300398 return -EINVAL;
399
Paul Walmsley43b40992010-02-22 22:09:34 -0700400 if (!oh->class->sysc->sysc_fields) {
401 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700402 return -EINVAL;
403 }
404
Paul Walmsley43b40992010-02-22 22:09:34 -0700405 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700406
407 *v |= softrst_mask;
Paul Walmsley63c85232009-09-03 20:14:03 +0300408
409 return 0;
410}
411
412/**
Roger Quadros313a76e2013-12-08 18:39:02 -0700413 * _clear_softreset: clear OCP_SYSCONFIG.SOFTRESET bit in @v
414 * @oh: struct omap_hwmod *
415 * @v: pointer to register contents to modify
416 *
417 * Clear the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
418 * error or 0 upon success.
419 */
420static int _clear_softreset(struct omap_hwmod *oh, u32 *v)
421{
422 u32 softrst_mask;
423
424 if (!oh->class->sysc ||
425 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
426 return -EINVAL;
427
428 if (!oh->class->sysc->sysc_fields) {
429 WARN(1,
430 "omap_hwmod: %s: sysc_fields absent for sysconfig class\n",
431 oh->name);
432 return -EINVAL;
433 }
434
435 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
436
437 *v &= ~softrst_mask;
438
439 return 0;
440}
441
442/**
Tero Kristo613ad0e2012-10-29 22:02:13 -0600443 * _wait_softreset_complete - wait for an OCP softreset to complete
444 * @oh: struct omap_hwmod * to wait on
445 *
446 * Wait until the IP block represented by @oh reports that its OCP
447 * softreset is complete. This can be triggered by software (see
448 * _ocp_softreset()) or by hardware upon returning from off-mode (one
449 * example is HSMMC). Waits for up to MAX_MODULE_SOFTRESET_WAIT
450 * microseconds. Returns the number of microseconds waited.
451 */
452static int _wait_softreset_complete(struct omap_hwmod *oh)
453{
454 struct omap_hwmod_class_sysconfig *sysc;
455 u32 softrst_mask;
456 int c = 0;
457
458 sysc = oh->class->sysc;
459
460 if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS)
461 omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs)
462 & SYSS_RESETDONE_MASK),
463 MAX_MODULE_SOFTRESET_WAIT, c);
464 else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
465 softrst_mask = (0x1 << sysc->sysc_fields->srst_shift);
466 omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs)
467 & softrst_mask),
468 MAX_MODULE_SOFTRESET_WAIT, c);
469 }
470
471 return c;
472}
473
474/**
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -0600475 * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
476 * @oh: struct omap_hwmod *
477 *
478 * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
479 * of some modules. When the DMA must perform read/write accesses, the
480 * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
481 * for power management, software must set the DMADISABLE bit back to 1.
482 *
483 * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
484 * error or 0 upon success.
485 */
486static int _set_dmadisable(struct omap_hwmod *oh)
487{
488 u32 v;
489 u32 dmadisable_mask;
490
491 if (!oh->class->sysc ||
492 !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
493 return -EINVAL;
494
495 if (!oh->class->sysc->sysc_fields) {
496 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
497 return -EINVAL;
498 }
499
500 /* clocks must be on for this operation */
501 if (oh->_state != _HWMOD_STATE_ENABLED) {
502 pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
503 return -EINVAL;
504 }
505
506 pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
507
508 v = oh->_sysc_cache;
509 dmadisable_mask =
510 (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
511 v |= dmadisable_mask;
512 _write_sysconfig(v, oh);
513
514 return 0;
515}
516
517/**
Paul Walmsley726072e2009-12-08 16:34:15 -0700518 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
519 * @oh: struct omap_hwmod *
520 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
521 * @v: pointer to register contents to modify
522 *
523 * Update the module autoidle bit in @v to be @autoidle for the @oh
524 * hwmod. The autoidle bit controls whether the module can gate
525 * internal clocks automatically when it isn't doing anything; the
526 * exact function of this bit varies on a per-module basis. This
527 * function does not write to the hardware. Returns -EINVAL upon
528 * error or 0 upon success.
529 */
530static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
531 u32 *v)
532{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700533 u32 autoidle_mask;
534 u8 autoidle_shift;
535
Paul Walmsley43b40992010-02-22 22:09:34 -0700536 if (!oh->class->sysc ||
537 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
Paul Walmsley726072e2009-12-08 16:34:15 -0700538 return -EINVAL;
539
Paul Walmsley43b40992010-02-22 22:09:34 -0700540 if (!oh->class->sysc->sysc_fields) {
541 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700542 return -EINVAL;
543 }
544
Paul Walmsley43b40992010-02-22 22:09:34 -0700545 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
Tarun Kanti DebBarma8985b632011-03-03 14:22:46 -0700546 autoidle_mask = (0x1 << autoidle_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700547
548 *v &= ~autoidle_mask;
549 *v |= autoidle << autoidle_shift;
Paul Walmsley726072e2009-12-08 16:34:15 -0700550
551 return 0;
552}
553
554/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300555 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
556 * @oh: struct omap_hwmod *
557 *
558 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
559 * upon error or 0 upon success.
560 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700561static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300562{
Paul Walmsley43b40992010-02-22 22:09:34 -0700563 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700564 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200565 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
566 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300567 return -EINVAL;
568
Paul Walmsley43b40992010-02-22 22:09:34 -0700569 if (!oh->class->sysc->sysc_fields) {
570 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700571 return -EINVAL;
572 }
573
Benoit Cousson1fe74112011-07-01 22:54:03 +0200574 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
575 *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300576
Benoit Cousson86009eb2010-12-21 21:31:28 -0700577 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
578 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200579 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
580 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700581
Paul Walmsley63c85232009-09-03 20:14:03 +0300582 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
583
Paul Walmsley63c85232009-09-03 20:14:03 +0300584 return 0;
585}
586
587/**
588 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
589 * @oh: struct omap_hwmod *
590 *
591 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
592 * upon error or 0 upon success.
593 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700594static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300595{
Paul Walmsley43b40992010-02-22 22:09:34 -0700596 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700597 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200598 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
599 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300600 return -EINVAL;
601
Paul Walmsley43b40992010-02-22 22:09:34 -0700602 if (!oh->class->sysc->sysc_fields) {
603 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700604 return -EINVAL;
605 }
606
Benoit Cousson1fe74112011-07-01 22:54:03 +0200607 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
608 *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
Paul Walmsley63c85232009-09-03 20:14:03 +0300609
Benoit Cousson86009eb2010-12-21 21:31:28 -0700610 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
611 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200612 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
Djamil Elaidi561038f2012-06-17 11:57:51 -0600613 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700614
Paul Walmsley63c85232009-09-03 20:14:03 +0300615 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
616
Paul Walmsley63c85232009-09-03 20:14:03 +0300617 return 0;
618}
619
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700620static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
621{
Rajendra Nayakc4a1ea22012-04-27 16:32:53 +0530622 struct clk_hw_omap *clk;
623
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700624 if (oh->clkdm) {
625 return oh->clkdm;
626 } else if (oh->_clk) {
Tero Kristo924f9492013-07-12 12:26:41 +0300627 if (__clk_get_flags(oh->_clk) & CLK_IS_BASIC)
628 return NULL;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700629 clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
630 return clk->clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700631 }
632 return NULL;
633}
634
Paul Walmsley63c85232009-09-03 20:14:03 +0300635/**
636 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
637 * @oh: struct omap_hwmod *
638 *
639 * Prevent the hardware module @oh from entering idle while the
640 * hardare module initiator @init_oh is active. Useful when a module
641 * will be accessed by a particular initiator (e.g., if a module will
642 * be accessed by the IVA, there should be a sleepdep between the IVA
643 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700644 * mode. If the clockdomain is marked as not needing autodeps, return
645 * 0 without doing anything. Otherwise, returns -EINVAL upon error or
646 * passes along clkdm_add_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300647 */
648static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
649{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700650 struct clockdomain *clkdm, *init_clkdm;
651
652 clkdm = _get_clkdm(oh);
653 init_clkdm = _get_clkdm(init_oh);
654
655 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300656 return -EINVAL;
657
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700658 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700659 return 0;
660
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700661 return clkdm_add_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300662}
663
664/**
665 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
666 * @oh: struct omap_hwmod *
667 *
668 * Allow the hardware module @oh to enter idle while the hardare
669 * module initiator @init_oh is active. Useful when a module will not
670 * be accessed by a particular initiator (e.g., if a module will not
671 * be accessed by the IVA, there should be no sleepdep between the IVA
672 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700673 * mode. If the clockdomain is marked as not needing autodeps, return
674 * 0 without doing anything. Returns -EINVAL upon error or passes
675 * along clkdm_del_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300676 */
677static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
678{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700679 struct clockdomain *clkdm, *init_clkdm;
680
681 clkdm = _get_clkdm(oh);
682 init_clkdm = _get_clkdm(init_oh);
683
684 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300685 return -EINVAL;
686
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700687 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700688 return 0;
689
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700690 return clkdm_del_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300691}
692
693/**
694 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
695 * @oh: struct omap_hwmod *
696 *
697 * Called from _init_clocks(). Populates the @oh _clk (main
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300698 * functional clock pointer) if a clock matching the hwmod name is found,
699 * or a main_clk is present. Returns 0 on success or -EINVAL on error.
Paul Walmsley63c85232009-09-03 20:14:03 +0300700 */
701static int _init_main_clk(struct omap_hwmod *oh)
702{
Paul Walmsley63c85232009-09-03 20:14:03 +0300703 int ret = 0;
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300704 char name[MOD_CLK_MAX_NAME_LEN];
705 struct clk *clk;
Maninder Singh5066d522016-12-08 09:40:30 +0530706 static const char modck[] = "_mod_ck";
Paul Walmsley63c85232009-09-03 20:14:03 +0300707
Maninder Singh5066d522016-12-08 09:40:30 +0530708 if (strlen(oh->name) >= MOD_CLK_MAX_NAME_LEN - strlen(modck))
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300709 pr_warn("%s: warning: cropping name for %s\n", __func__,
710 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +0300711
Maninder Singh5066d522016-12-08 09:40:30 +0530712 strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - strlen(modck));
713 strlcat(name, modck, MOD_CLK_MAX_NAME_LEN);
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300714
715 clk = clk_get(NULL, name);
716 if (!IS_ERR(clk)) {
717 oh->_clk = clk;
718 soc_ops.disable_direct_prcm(oh);
719 oh->main_clk = kstrdup(name, GFP_KERNEL);
720 } else {
721 if (!oh->main_clk)
722 return 0;
723
724 oh->_clk = clk_get(NULL, oh->main_clk);
725 }
726
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600727 if (IS_ERR(oh->_clk)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700728 pr_warn("omap_hwmod: %s: cannot clk_get main_clk %s\n",
729 oh->name, oh->main_clk);
Benoit Cousson63403382010-05-20 12:31:10 -0600730 return -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600731 }
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600732 /*
733 * HACK: This needs a re-visit once clk_prepare() is implemented
734 * to do something meaningful. Today its just a no-op.
735 * If clk_prepare() is used at some point to do things like
736 * voltage scaling etc, then this would have to be moved to
737 * some point where subsystems like i2c and pmic become
738 * available.
739 */
740 clk_prepare(oh->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300741
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700742 if (!_get_clkdm(oh))
Paul Walmsley3bb05db2012-09-23 17:28:18 -0600743 pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600744 oh->name, oh->main_clk);
Kevin Hilman81d7c6f2009-12-08 16:34:24 -0700745
Paul Walmsley63c85232009-09-03 20:14:03 +0300746 return ret;
747}
748
749/**
Paul Walmsley887adea2010-07-26 16:34:33 -0600750 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
Paul Walmsley63c85232009-09-03 20:14:03 +0300751 * @oh: struct omap_hwmod *
752 *
753 * Called from _init_clocks(). Populates the @oh OCP slave interface
754 * clock pointers. Returns 0 on success or -EINVAL on error.
755 */
756static int _init_interface_clks(struct omap_hwmod *oh)
757{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600758 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +0300759 struct clk *c;
Paul Walmsley63c85232009-09-03 20:14:03 +0300760 int ret = 0;
761
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -0700762 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700763 if (!os->clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300764 continue;
765
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600766 c = clk_get(NULL, os->clk);
767 if (IS_ERR(c)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700768 pr_warn("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
769 oh->name, os->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300770 ret = -EINVAL;
Nishanth Menon0e7dc862013-12-08 18:39:03 -0700771 continue;
Benoit Coussondc759252010-06-23 18:15:12 -0600772 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300773 os->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600774 /*
775 * HACK: This needs a re-visit once clk_prepare() is implemented
776 * to do something meaningful. Today its just a no-op.
777 * If clk_prepare() is used at some point to do things like
778 * voltage scaling etc, then this would have to be moved to
779 * some point where subsystems like i2c and pmic become
780 * available.
781 */
782 clk_prepare(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300783 }
784
785 return ret;
786}
787
788/**
789 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
790 * @oh: struct omap_hwmod *
791 *
792 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
793 * clock pointers. Returns 0 on success or -EINVAL on error.
794 */
795static int _init_opt_clks(struct omap_hwmod *oh)
796{
797 struct omap_hwmod_opt_clk *oc;
798 struct clk *c;
799 int i;
800 int ret = 0;
801
802 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600803 c = clk_get(NULL, oc->clk);
804 if (IS_ERR(c)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700805 pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
806 oh->name, oc->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300807 ret = -EINVAL;
Nishanth Menon0e7dc862013-12-08 18:39:03 -0700808 continue;
Benoit Coussondc759252010-06-23 18:15:12 -0600809 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300810 oc->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600811 /*
812 * HACK: This needs a re-visit once clk_prepare() is implemented
813 * to do something meaningful. Today its just a no-op.
814 * If clk_prepare() is used at some point to do things like
815 * voltage scaling etc, then this would have to be moved to
816 * some point where subsystems like i2c and pmic become
817 * available.
818 */
819 clk_prepare(oc->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300820 }
821
822 return ret;
823}
824
Peter Ujfalusic12ba8c2015-11-12 09:32:58 +0200825static void _enable_optional_clocks(struct omap_hwmod *oh)
826{
827 struct omap_hwmod_opt_clk *oc;
828 int i;
829
830 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
831
832 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
833 if (oc->_clk) {
834 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
835 __clk_get_name(oc->_clk));
836 clk_enable(oc->_clk);
837 }
838}
839
840static void _disable_optional_clocks(struct omap_hwmod *oh)
841{
842 struct omap_hwmod_opt_clk *oc;
843 int i;
844
845 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
846
847 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
848 if (oc->_clk) {
849 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
850 __clk_get_name(oc->_clk));
851 clk_disable(oc->_clk);
852 }
853}
854
Paul Walmsley63c85232009-09-03 20:14:03 +0300855/**
856 * _enable_clocks - enable hwmod main clock and interface clocks
857 * @oh: struct omap_hwmod *
858 *
859 * Enables all clocks necessary for register reads and writes to succeed
860 * on the hwmod @oh. Returns 0.
861 */
862static int _enable_clocks(struct omap_hwmod *oh)
863{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600864 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +0300865
866 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
867
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600868 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300869 clk_enable(oh->_clk);
870
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -0700871 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600872 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
873 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300874 }
875
Peter Ujfalusic12ba8c2015-11-12 09:32:58 +0200876 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
877 _enable_optional_clocks(oh);
878
Paul Walmsley63c85232009-09-03 20:14:03 +0300879 /* The opt clocks are controlled by the device driver. */
880
881 return 0;
882}
883
884/**
885 * _disable_clocks - disable hwmod main clock and interface clocks
886 * @oh: struct omap_hwmod *
887 *
888 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
889 */
890static int _disable_clocks(struct omap_hwmod *oh)
891{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600892 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +0300893
894 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
895
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -0600896 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300897 clk_disable(oh->_clk);
898
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -0700899 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600900 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE))
901 clk_disable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300902 }
903
Peter Ujfalusic12ba8c2015-11-12 09:32:58 +0200904 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
905 _disable_optional_clocks(oh);
906
Paul Walmsley63c85232009-09-03 20:14:03 +0300907 /* The opt clocks are controlled by the device driver. */
908
909 return 0;
910}
911
912/**
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600913 * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
Benoit Cousson45c38252011-07-10 05:56:33 -0600914 * @oh: struct omap_hwmod *
915 *
916 * Enables the PRCM module mode related to the hwmod @oh.
917 * No return value.
918 */
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600919static void _omap4_enable_module(struct omap_hwmod *oh)
Benoit Cousson45c38252011-07-10 05:56:33 -0600920{
Benoit Cousson45c38252011-07-10 05:56:33 -0600921 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
922 return;
923
Kevin Hilman3d9f0322012-06-18 12:12:23 -0600924 pr_debug("omap_hwmod: %s: %s: %d\n",
925 oh->name, __func__, oh->prcm.omap4.modulemode);
Benoit Cousson45c38252011-07-10 05:56:33 -0600926
Tero Kristo128603f2014-10-27 08:39:24 -0700927 omap_cm_module_enable(oh->prcm.omap4.modulemode,
928 oh->clkdm->prcm_partition,
929 oh->clkdm->cm_inst, oh->prcm.omap4.clkctrl_offs);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600930}
931
932/**
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800933 * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
934 * @oh: struct omap_hwmod *
935 *
936 * Wait for a module @oh to enter slave idle. Returns 0 if the module
937 * does not have an IDLEST bit or if the module successfully enters
938 * slave idle; otherwise, pass along the return value of the
939 * appropriate *_cm*_wait_module_idle() function.
940 */
941static int _omap4_wait_target_disable(struct omap_hwmod *oh)
942{
Paul Walmsley2b026d12012-09-23 17:28:18 -0600943 if (!oh)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800944 return -EINVAL;
945
Paul Walmsley2b026d12012-09-23 17:28:18 -0600946 if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
Benoit Coussonbfc141e2011-12-16 16:09:11 -0800947 return 0;
948
949 if (oh->flags & HWMOD_NO_IDLEST)
950 return 0;
951
Dave Gerlach428929c2016-07-12 12:50:33 -0500952 if (!oh->prcm.omap4.clkctrl_offs &&
953 !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
954 return 0;
955
Tero Kristoa8ae5af2014-10-27 08:39:23 -0700956 return omap_cm_wait_module_idle(oh->clkdm->prcm_partition,
957 oh->clkdm->cm_inst,
958 oh->prcm.omap4.clkctrl_offs, 0);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600959}
960
961/**
Paul Walmsley212738a2011-07-09 19:14:06 -0600962 * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh
963 * @oh: struct omap_hwmod *oh
964 *
965 * Count and return the number of MPU IRQs associated with the hwmod
966 * @oh. Used to allocate struct resource data. Returns 0 if @oh is
967 * NULL.
968 */
969static int _count_mpu_irqs(struct omap_hwmod *oh)
970{
971 struct omap_hwmod_irq_info *ohii;
972 int i = 0;
973
974 if (!oh || !oh->mpu_irqs)
975 return 0;
976
977 do {
978 ohii = &oh->mpu_irqs[i++];
979 } while (ohii->irq != -1);
980
sricharancc1b0762011-11-23 14:35:07 -0800981 return i-1;
Paul Walmsley212738a2011-07-09 19:14:06 -0600982}
983
984/**
Paul Walmsleybc614952011-07-09 19:14:07 -0600985 * _count_sdma_reqs - count the number of SDMA request lines associated with @oh
986 * @oh: struct omap_hwmod *oh
987 *
988 * Count and return the number of SDMA request lines associated with
989 * the hwmod @oh. Used to allocate struct resource data. Returns 0
990 * if @oh is NULL.
991 */
992static int _count_sdma_reqs(struct omap_hwmod *oh)
993{
994 struct omap_hwmod_dma_info *ohdi;
995 int i = 0;
996
997 if (!oh || !oh->sdma_reqs)
998 return 0;
999
1000 do {
1001 ohdi = &oh->sdma_reqs[i++];
1002 } while (ohdi->dma_req != -1);
1003
sricharancc1b0762011-11-23 14:35:07 -08001004 return i-1;
Paul Walmsleybc614952011-07-09 19:14:07 -06001005}
1006
1007/**
Paul Walmsley78183f32011-07-09 19:14:05 -06001008 * _count_ocp_if_addr_spaces - count the number of address space entries for @oh
1009 * @oh: struct omap_hwmod *oh
1010 *
1011 * Count and return the number of address space ranges associated with
1012 * the hwmod @oh. Used to allocate struct resource data. Returns 0
1013 * if @oh is NULL.
1014 */
1015static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os)
1016{
1017 struct omap_hwmod_addr_space *mem;
1018 int i = 0;
1019
1020 if (!os || !os->addr)
1021 return 0;
1022
1023 do {
1024 mem = &os->addr[i++];
1025 } while (mem->pa_start != mem->pa_end);
1026
sricharancc1b0762011-11-23 14:35:07 -08001027 return i-1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001028}
1029
1030/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001031 * _get_mpu_irq_by_name - fetch MPU interrupt line number by name
1032 * @oh: struct omap_hwmod * to operate on
1033 * @name: pointer to the name of the MPU interrupt number to fetch (optional)
1034 * @irq: pointer to an unsigned int to store the MPU IRQ number to
1035 *
1036 * Retrieve a MPU hardware IRQ line number named by @name associated
1037 * with the IP block pointed to by @oh. The IRQ number will be filled
1038 * into the address pointed to by @dma. When @name is non-null, the
1039 * IRQ line number associated with the named entry will be returned.
1040 * If @name is null, the first matching entry will be returned. Data
1041 * order is not meaningful in hwmod data, so callers are strongly
1042 * encouraged to use a non-null @name whenever possible to avoid
1043 * unpredictable effects if hwmod data is later added that causes data
1044 * ordering to change. Returns 0 upon success or a negative error
1045 * code upon error.
1046 */
1047static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name,
1048 unsigned int *irq)
1049{
1050 int i;
1051 bool found = false;
1052
1053 if (!oh->mpu_irqs)
1054 return -ENOENT;
1055
1056 i = 0;
1057 while (oh->mpu_irqs[i].irq != -1) {
1058 if (name == oh->mpu_irqs[i].name ||
1059 !strcmp(name, oh->mpu_irqs[i].name)) {
1060 found = true;
1061 break;
1062 }
1063 i++;
1064 }
1065
1066 if (!found)
1067 return -ENOENT;
1068
1069 *irq = oh->mpu_irqs[i].irq;
1070
1071 return 0;
1072}
1073
1074/**
1075 * _get_sdma_req_by_name - fetch SDMA request line ID by name
1076 * @oh: struct omap_hwmod * to operate on
1077 * @name: pointer to the name of the SDMA request line to fetch (optional)
1078 * @dma: pointer to an unsigned int to store the request line ID to
1079 *
1080 * Retrieve an SDMA request line ID named by @name on the IP block
1081 * pointed to by @oh. The ID will be filled into the address pointed
1082 * to by @dma. When @name is non-null, the request line ID associated
1083 * with the named entry will be returned. If @name is null, the first
1084 * matching entry will be returned. Data order is not meaningful in
1085 * hwmod data, so callers are strongly encouraged to use a non-null
1086 * @name whenever possible to avoid unpredictable effects if hwmod
1087 * data is later added that causes data ordering to change. Returns 0
1088 * upon success or a negative error code upon error.
1089 */
1090static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name,
1091 unsigned int *dma)
1092{
1093 int i;
1094 bool found = false;
1095
1096 if (!oh->sdma_reqs)
1097 return -ENOENT;
1098
1099 i = 0;
1100 while (oh->sdma_reqs[i].dma_req != -1) {
1101 if (name == oh->sdma_reqs[i].name ||
1102 !strcmp(name, oh->sdma_reqs[i].name)) {
1103 found = true;
1104 break;
1105 }
1106 i++;
1107 }
1108
1109 if (!found)
1110 return -ENOENT;
1111
1112 *dma = oh->sdma_reqs[i].dma_req;
1113
1114 return 0;
1115}
1116
1117/**
1118 * _get_addr_space_by_name - fetch address space start & end by name
1119 * @oh: struct omap_hwmod * to operate on
1120 * @name: pointer to the name of the address space to fetch (optional)
1121 * @pa_start: pointer to a u32 to store the starting address to
1122 * @pa_end: pointer to a u32 to store the ending address to
1123 *
1124 * Retrieve address space start and end addresses for the IP block
1125 * pointed to by @oh. The data will be filled into the addresses
1126 * pointed to by @pa_start and @pa_end. When @name is non-null, the
1127 * address space data associated with the named entry will be
1128 * returned. If @name is null, the first matching entry will be
1129 * returned. Data order is not meaningful in hwmod data, so callers
1130 * are strongly encouraged to use a non-null @name whenever possible
1131 * to avoid unpredictable effects if hwmod data is later added that
1132 * causes data ordering to change. Returns 0 upon success or a
1133 * negative error code upon error.
1134 */
1135static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name,
1136 u32 *pa_start, u32 *pa_end)
1137{
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001138 int j;
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001139 struct omap_hwmod_ocp_if *os;
1140 bool found = false;
1141
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001142 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley5e8370f2012-04-18 19:10:06 -06001143
1144 if (!os->addr)
1145 return -ENOENT;
1146
1147 j = 0;
1148 while (os->addr[j].pa_start != os->addr[j].pa_end) {
1149 if (name == os->addr[j].name ||
1150 !strcmp(name, os->addr[j].name)) {
1151 found = true;
1152 break;
1153 }
1154 j++;
1155 }
1156
1157 if (found)
1158 break;
1159 }
1160
1161 if (!found)
1162 return -ENOENT;
1163
1164 *pa_start = os->addr[j].pa_start;
1165 *pa_end = os->addr[j].pa_end;
1166
1167 return 0;
1168}
1169
1170/**
Paul Walmsley24dbc212012-04-19 04:04:29 -06001171 * _save_mpu_port_index - find and save the index to @oh's MPU port
Paul Walmsley63c85232009-09-03 20:14:03 +03001172 * @oh: struct omap_hwmod *
1173 *
Paul Walmsley24dbc212012-04-19 04:04:29 -06001174 * Determines the array index of the OCP slave port that the MPU uses
1175 * to address the device, and saves it into the struct omap_hwmod.
1176 * Intended to be called during hwmod registration only. No return
1177 * value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001178 */
Paul Walmsley24dbc212012-04-19 04:04:29 -06001179static void __init _save_mpu_port_index(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001180{
Paul Walmsley24dbc212012-04-19 04:04:29 -06001181 struct omap_hwmod_ocp_if *os = NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +03001182
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001183 if (!oh)
Paul Walmsley24dbc212012-04-19 04:04:29 -06001184 return;
1185
1186 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001187
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001188 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley63c85232009-09-03 20:14:03 +03001189 if (os->user & OCP_USER_MPU) {
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001190 oh->_mpu_port = os;
Paul Walmsley24dbc212012-04-19 04:04:29 -06001191 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001192 break;
1193 }
1194 }
1195
Paul Walmsley24dbc212012-04-19 04:04:29 -06001196 return;
Paul Walmsley63c85232009-09-03 20:14:03 +03001197}
1198
1199/**
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001200 * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
1201 * @oh: struct omap_hwmod *
1202 *
1203 * Given a pointer to a struct omap_hwmod record @oh, return a pointer
1204 * to the struct omap_hwmod_ocp_if record that is used by the MPU to
1205 * communicate with the IP block. This interface need not be directly
1206 * connected to the MPU (and almost certainly is not), but is directly
1207 * connected to the IP block represented by @oh. Returns a pointer
1208 * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
1209 * error or if there does not appear to be a path from the MPU to this
1210 * IP block.
1211 */
1212static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
1213{
1214 if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
1215 return NULL;
1216
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001217 return oh->_mpu_port;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001218};
1219
1220/**
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001221 * _find_mpu_rt_addr_space - return MPU register target address space for @oh
Paul Walmsley63c85232009-09-03 20:14:03 +03001222 * @oh: struct omap_hwmod *
1223 *
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001224 * Returns a pointer to the struct omap_hwmod_addr_space record representing
1225 * the register target MPU address space; or returns NULL upon error.
Paul Walmsley63c85232009-09-03 20:14:03 +03001226 */
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001227static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001228{
1229 struct omap_hwmod_ocp_if *os;
1230 struct omap_hwmod_addr_space *mem;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001231 int found = 0, i = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001232
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001233 os = _find_mpu_rt_port(oh);
Paul Walmsley24dbc212012-04-19 04:04:29 -06001234 if (!os || !os->addr)
Paul Walmsley78183f32011-07-09 19:14:05 -06001235 return NULL;
1236
1237 do {
1238 mem = &os->addr[i++];
1239 if (mem->flags & ADDR_TYPE_RT)
Paul Walmsley63c85232009-09-03 20:14:03 +03001240 found = 1;
Paul Walmsley78183f32011-07-09 19:14:05 -06001241 } while (!found && mem->pa_start != mem->pa_end);
Paul Walmsley63c85232009-09-03 20:14:03 +03001242
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06001243 return (found) ? mem : NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +03001244}
1245
1246/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001247 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001248 * @oh: struct omap_hwmod *
1249 *
Paul Walmsley006c7f12012-07-04 05:22:53 -06001250 * Ensure that the OCP_SYSCONFIG register for the IP block represented
1251 * by @oh is set to indicate to the PRCM that the IP block is active.
1252 * Usually this means placing the module into smart-idle mode and
1253 * smart-standby, but if there is a bug in the automatic idle handling
1254 * for the IP block, it may need to be placed into the force-idle or
1255 * no-idle variants of these modes. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001256 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001257static void _enable_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001258{
Paul Walmsley43b40992010-02-22 22:09:34 -07001259 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001260 u32 v;
Paul Walmsley006c7f12012-07-04 05:22:53 -06001261 bool clkdm_act;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001262 struct clockdomain *clkdm;
Paul Walmsley63c85232009-09-03 20:14:03 +03001263
Paul Walmsley43b40992010-02-22 22:09:34 -07001264 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001265 return;
1266
Tero Kristo613ad0e2012-10-29 22:02:13 -06001267 /*
1268 * Wait until reset has completed, this is needed as the IP
1269 * block is reset automatically by hardware in some cases
1270 * (off-mode for example), and the drivers require the
1271 * IP to be ready when they access it
1272 */
1273 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1274 _enable_optional_clocks(oh);
1275 _wait_softreset_complete(oh);
1276 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1277 _disable_optional_clocks(oh);
1278
Paul Walmsley63c85232009-09-03 20:14:03 +03001279 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001280 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001281
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001282 clkdm = _get_clkdm(oh);
Paul Walmsley43b40992010-02-22 22:09:34 -07001283 if (sf & SYSC_HAS_SIDLEMODE) {
Rajendra Nayakca43ea32013-05-15 20:18:38 +05301284 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1285 oh->flags & HWMOD_SWSUP_SIDLE_ACT) {
Rajendra Nayak35513172013-05-15 20:18:37 +05301286 idlemode = HWMOD_IDLEMODE_NO;
1287 } else {
1288 if (sf & SYSC_HAS_ENAWAKEUP)
1289 _enable_wakeup(oh, &v);
1290 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1291 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1292 else
1293 idlemode = HWMOD_IDLEMODE_SMART;
1294 }
1295
1296 /*
1297 * This is special handling for some IPs like
1298 * 32k sync timer. Force them to idle!
1299 */
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001300 clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
Paul Walmsley006c7f12012-07-04 05:22:53 -06001301 if (clkdm_act && !(oh->class->sysc->idlemodes &
1302 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1303 idlemode = HWMOD_IDLEMODE_FORCE;
Rajendra Nayak35513172013-05-15 20:18:37 +05301304
Paul Walmsley63c85232009-09-03 20:14:03 +03001305 _set_slave_idlemode(oh, idlemode, &v);
1306 }
1307
Paul Walmsley43b40992010-02-22 22:09:34 -07001308 if (sf & SYSC_HAS_MIDLEMODE) {
Grazvydas Ignotas092bc082013-03-11 21:49:00 +02001309 if (oh->flags & HWMOD_FORCE_MSTANDBY) {
1310 idlemode = HWMOD_IDLEMODE_FORCE;
1311 } else if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001312 idlemode = HWMOD_IDLEMODE_NO;
1313 } else {
1314 if (sf & SYSC_HAS_ENAWAKEUP)
1315 _enable_wakeup(oh, &v);
1316 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1317 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1318 else
1319 idlemode = HWMOD_IDLEMODE_SMART;
1320 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001321 _set_master_standbymode(oh, idlemode, &v);
1322 }
1323
Paul Walmsleya16b1f72009-12-08 16:34:17 -07001324 /*
1325 * XXX The clock framework should handle this, by
1326 * calling into this code. But this must wait until the
1327 * clock structures are tagged with omap_hwmod entries
1328 */
Paul Walmsley43b40992010-02-22 22:09:34 -07001329 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1330 (sf & SYSC_HAS_CLOCKACTIVITY))
Tony Lindgrenca5339b2017-03-14 13:13:19 -07001331 _set_clockactivity(oh, CLOCKACT_TEST_ICLK, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001332
Lokesh Vutla3ca4a232016-03-26 23:08:55 -06001333 _write_sysconfig(v, oh);
Hema HK78f26e82010-09-24 10:23:19 -06001334
1335 /*
1336 * Set the autoidle bit only after setting the smartidle bit
1337 * Setting this will not have any impact on the other modules.
1338 */
1339 if (sf & SYSC_HAS_AUTOIDLE) {
1340 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
1341 0 : 1;
1342 _set_module_autoidle(oh, idlemode, &v);
1343 _write_sysconfig(v, oh);
1344 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001345}
1346
1347/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001348 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001349 * @oh: struct omap_hwmod *
1350 *
1351 * If module is marked as SWSUP_SIDLE, force the module into slave
1352 * idle; otherwise, configure it for smart-idle. If module is marked
1353 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
1354 * configure it for smart-standby. No return value.
1355 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001356static void _idle_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001357{
Paul Walmsley43b40992010-02-22 22:09:34 -07001358 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001359 u32 v;
1360
Paul Walmsley43b40992010-02-22 22:09:34 -07001361 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001362 return;
1363
1364 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001365 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001366
Paul Walmsley43b40992010-02-22 22:09:34 -07001367 if (sf & SYSC_HAS_SIDLEMODE) {
Rajendra Nayak35513172013-05-15 20:18:37 +05301368 if (oh->flags & HWMOD_SWSUP_SIDLE) {
Paul Walmsley006c7f12012-07-04 05:22:53 -06001369 idlemode = HWMOD_IDLEMODE_FORCE;
Rajendra Nayak35513172013-05-15 20:18:37 +05301370 } else {
1371 if (sf & SYSC_HAS_ENAWAKEUP)
1372 _enable_wakeup(oh, &v);
1373 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1374 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1375 else
1376 idlemode = HWMOD_IDLEMODE_SMART;
1377 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001378 _set_slave_idlemode(oh, idlemode, &v);
1379 }
1380
Paul Walmsley43b40992010-02-22 22:09:34 -07001381 if (sf & SYSC_HAS_MIDLEMODE) {
Grazvydas Ignotas092bc082013-03-11 21:49:00 +02001382 if ((oh->flags & HWMOD_SWSUP_MSTANDBY) ||
1383 (oh->flags & HWMOD_FORCE_MSTANDBY)) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001384 idlemode = HWMOD_IDLEMODE_FORCE;
1385 } else {
1386 if (sf & SYSC_HAS_ENAWAKEUP)
1387 _enable_wakeup(oh, &v);
1388 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1389 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1390 else
1391 idlemode = HWMOD_IDLEMODE_SMART;
1392 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001393 _set_master_standbymode(oh, idlemode, &v);
1394 }
1395
Lokesh Vutla3ca4a232016-03-26 23:08:55 -06001396 /* If the cached value is the same as the new value, skip the write */
1397 if (oh->_sysc_cache != v)
1398 _write_sysconfig(v, oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03001399}
1400
1401/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001402 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001403 * @oh: struct omap_hwmod *
1404 *
1405 * Force the module into slave idle and master suspend. No return
1406 * value.
1407 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001408static void _shutdown_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001409{
1410 u32 v;
Paul Walmsley43b40992010-02-22 22:09:34 -07001411 u8 sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001412
Paul Walmsley43b40992010-02-22 22:09:34 -07001413 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001414 return;
1415
1416 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001417 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001418
Paul Walmsley43b40992010-02-22 22:09:34 -07001419 if (sf & SYSC_HAS_SIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001420 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
1421
Paul Walmsley43b40992010-02-22 22:09:34 -07001422 if (sf & SYSC_HAS_MIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001423 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
1424
Paul Walmsley43b40992010-02-22 22:09:34 -07001425 if (sf & SYSC_HAS_AUTOIDLE)
Paul Walmsley726072e2009-12-08 16:34:15 -07001426 _set_module_autoidle(oh, 1, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001427
1428 _write_sysconfig(v, oh);
1429}
1430
1431/**
1432 * _lookup - find an omap_hwmod by name
1433 * @name: find an omap_hwmod by name
1434 *
1435 * Return a pointer to an omap_hwmod by name, or NULL if not found.
Paul Walmsley63c85232009-09-03 20:14:03 +03001436 */
1437static struct omap_hwmod *_lookup(const char *name)
1438{
1439 struct omap_hwmod *oh, *temp_oh;
1440
1441 oh = NULL;
1442
1443 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1444 if (!strcmp(name, temp_oh->name)) {
1445 oh = temp_oh;
1446 break;
1447 }
1448 }
1449
1450 return oh;
1451}
Paul Walmsley868c1572012-06-19 15:01:02 -06001452
Benoit Cousson6ae76992011-07-10 05:56:30 -06001453/**
1454 * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
1455 * @oh: struct omap_hwmod *
1456 *
1457 * Convert a clockdomain name stored in a struct omap_hwmod into a
1458 * clockdomain pointer, and save it into the struct omap_hwmod.
Paul Walmsley868c1572012-06-19 15:01:02 -06001459 * Return -EINVAL if the clkdm_name lookup failed.
Benoit Cousson6ae76992011-07-10 05:56:30 -06001460 */
1461static int _init_clkdm(struct omap_hwmod *oh)
1462{
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001463 if (!oh->clkdm_name) {
1464 pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
Benoit Cousson6ae76992011-07-10 05:56:30 -06001465 return 0;
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001466 }
Benoit Cousson6ae76992011-07-10 05:56:30 -06001467
Benoit Cousson6ae76992011-07-10 05:56:30 -06001468 oh->clkdm = clkdm_lookup(oh->clkdm_name);
1469 if (!oh->clkdm) {
Joe Perches3d0cb732014-09-13 11:31:16 -07001470 pr_warn("omap_hwmod: %s: could not associate to clkdm %s\n",
Benoit Cousson6ae76992011-07-10 05:56:30 -06001471 oh->name, oh->clkdm_name);
Tero Kristo0385c582013-07-17 18:03:25 +03001472 return 0;
Benoit Cousson6ae76992011-07-10 05:56:30 -06001473 }
1474
1475 pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
1476 oh->name, oh->clkdm_name);
1477
1478 return 0;
1479}
Paul Walmsley63c85232009-09-03 20:14:03 +03001480
1481/**
Benoit Cousson6ae76992011-07-10 05:56:30 -06001482 * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
1483 * well the clockdomain.
Paul Walmsley63c85232009-09-03 20:14:03 +03001484 * @oh: struct omap_hwmod *
Paul Walmsley97d60162010-07-26 16:34:30 -06001485 * @data: not used; pass NULL
Paul Walmsley63c85232009-09-03 20:14:03 +03001486 *
Paul Walmsleya2debdb2011-02-23 00:14:07 -07001487 * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
Paul Walmsley48d54f32011-02-23 00:14:07 -07001488 * Resolves all clock names embedded in the hwmod. Returns 0 on
1489 * success, or a negative error code on failure.
Paul Walmsley63c85232009-09-03 20:14:03 +03001490 */
Paul Walmsley97d60162010-07-26 16:34:30 -06001491static int _init_clocks(struct omap_hwmod *oh, void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03001492{
1493 int ret = 0;
1494
Paul Walmsley48d54f32011-02-23 00:14:07 -07001495 if (oh->_state != _HWMOD_STATE_REGISTERED)
1496 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001497
1498 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
1499
Vaibhav Hiremathb797be12012-07-09 18:24:30 +05301500 if (soc_ops.init_clkdm)
1501 ret |= soc_ops.init_clkdm(oh);
1502
Paul Walmsley63c85232009-09-03 20:14:03 +03001503 ret |= _init_main_clk(oh);
1504 ret |= _init_interface_clks(oh);
1505 ret |= _init_opt_clks(oh);
1506
Benoit Coussonf5c1f842010-05-20 12:31:10 -06001507 if (!ret)
1508 oh->_state = _HWMOD_STATE_CLKS_INITED;
Benoit Cousson66522712011-07-01 22:54:06 +02001509 else
Joe Perches3d0cb732014-09-13 11:31:16 -07001510 pr_warn("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001511
Rajendra Nayak09c35f22011-02-16 12:11:24 +00001512 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001513}
1514
1515/**
omar ramirezcc1226e2011-03-04 13:32:44 -07001516 * _lookup_hardreset - fill register bit info for this hwmod/reset line
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001517 * @oh: struct omap_hwmod *
1518 * @name: name of the reset line in the context of this hwmod
omar ramirezcc1226e2011-03-04 13:32:44 -07001519 * @ohri: struct omap_hwmod_rst_info * that this function will fill in
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001520 *
1521 * Return the bit position of the reset line that match the
1522 * input name. Return -ENOENT if not found.
1523 */
Paul Walmsleya032d332012-08-03 09:21:10 -06001524static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
1525 struct omap_hwmod_rst_info *ohri)
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001526{
1527 int i;
1528
1529 for (i = 0; i < oh->rst_lines_cnt; i++) {
1530 const char *rst_line = oh->rst_lines[i].name;
1531 if (!strcmp(rst_line, name)) {
omar ramirezcc1226e2011-03-04 13:32:44 -07001532 ohri->rst_shift = oh->rst_lines[i].rst_shift;
1533 ohri->st_shift = oh->rst_lines[i].st_shift;
1534 pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
1535 oh->name, __func__, rst_line, ohri->rst_shift,
1536 ohri->st_shift);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001537
omar ramirezcc1226e2011-03-04 13:32:44 -07001538 return 0;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001539 }
1540 }
1541
1542 return -ENOENT;
1543}
1544
1545/**
1546 * _assert_hardreset - assert the HW reset line of submodules
1547 * contained in the hwmod module.
1548 * @oh: struct omap_hwmod *
1549 * @name: name of the reset line to lookup and assert
1550 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001551 * Some IP like dsp, ipu or iva contain processor that require an HW
1552 * reset line to be assert / deassert in order to enable fully the IP.
1553 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1554 * asserting the hardreset line on the currently-booted SoC, or passes
1555 * along the return value from _lookup_hardreset() or the SoC's
1556 * assert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001557 */
1558static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1559{
omar ramirezcc1226e2011-03-04 13:32:44 -07001560 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001561 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001562
1563 if (!oh)
1564 return -EINVAL;
1565
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001566 if (!soc_ops.assert_hardreset)
1567 return -ENOSYS;
1568
omar ramirezcc1226e2011-03-04 13:32:44 -07001569 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001570 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001571 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001572
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001573 ret = soc_ops.assert_hardreset(oh, &ohri);
1574
1575 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001576}
1577
1578/**
1579 * _deassert_hardreset - deassert the HW reset line of submodules contained
1580 * in the hwmod module.
1581 * @oh: struct omap_hwmod *
1582 * @name: name of the reset line to look up and deassert
1583 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001584 * Some IP like dsp, ipu or iva contain processor that require an HW
1585 * reset line to be assert / deassert in order to enable fully the IP.
1586 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1587 * deasserting the hardreset line on the currently-booted SoC, or passes
1588 * along the return value from _lookup_hardreset() or the SoC's
1589 * deassert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001590 */
1591static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1592{
omar ramirezcc1226e2011-03-04 13:32:44 -07001593 struct omap_hwmod_rst_info ohri;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001594 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001595
1596 if (!oh)
1597 return -EINVAL;
1598
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001599 if (!soc_ops.deassert_hardreset)
1600 return -ENOSYS;
1601
omar ramirezcc1226e2011-03-04 13:32:44 -07001602 ret = _lookup_hardreset(oh, name, &ohri);
Russell Kingc48cd652013-03-13 20:44:21 +00001603 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001604 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001605
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001606 if (oh->clkdm) {
1607 /*
1608 * A clockdomain must be in SW_SUP otherwise reset
1609 * might not be completed. The clockdomain can be set
1610 * in HW_AUTO only when the module become ready.
1611 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03001612 clkdm_deny_idle(oh->clkdm);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001613 ret = clkdm_hwmod_enable(oh->clkdm, oh);
1614 if (ret) {
1615 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1616 oh->name, oh->clkdm->name, ret);
1617 return ret;
1618 }
1619 }
1620
1621 _enable_clocks(oh);
1622 if (soc_ops.enable_module)
1623 soc_ops.enable_module(oh);
1624
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001625 ret = soc_ops.deassert_hardreset(oh, &ohri);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001626
1627 if (soc_ops.disable_module)
1628 soc_ops.disable_module(oh);
1629 _disable_clocks(oh);
1630
omar ramirezcc1226e2011-03-04 13:32:44 -07001631 if (ret == -EBUSY)
Joe Perches3d0cb732014-09-13 11:31:16 -07001632 pr_warn("omap_hwmod: %s: failed to hardreset\n", oh->name);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001633
Tero Kristo80d25182015-02-26 18:06:00 +02001634 if (oh->clkdm) {
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001635 /*
1636 * Set the clockdomain to HW_AUTO, assuming that the
1637 * previous state was HW_AUTO.
1638 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03001639 clkdm_allow_idle(oh->clkdm);
Tero Kristo80d25182015-02-26 18:06:00 +02001640
1641 clkdm_hwmod_disable(oh->clkdm, oh);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001642 }
1643
omar ramirezcc1226e2011-03-04 13:32:44 -07001644 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001645}
1646
1647/**
1648 * _read_hardreset - read the HW reset line state of submodules
1649 * contained in the hwmod module
1650 * @oh: struct omap_hwmod *
1651 * @name: name of the reset line to look up and read
1652 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001653 * Return the state of the reset line. Returns -EINVAL if @oh is
1654 * null, -ENOSYS if we have no way of reading the hardreset line
1655 * status on the currently-booted SoC, or passes along the return
1656 * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
1657 * code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001658 */
1659static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1660{
omar ramirezcc1226e2011-03-04 13:32:44 -07001661 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001662 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001663
1664 if (!oh)
1665 return -EINVAL;
1666
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001667 if (!soc_ops.is_hardreset_asserted)
1668 return -ENOSYS;
1669
omar ramirezcc1226e2011-03-04 13:32:44 -07001670 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001671 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001672 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001673
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001674 return soc_ops.is_hardreset_asserted(oh, &ohri);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001675}
1676
1677/**
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001678 * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
Paul Walmsley747834a2012-04-18 19:10:04 -06001679 * @oh: struct omap_hwmod *
1680 *
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001681 * If all hardreset lines associated with @oh are asserted, then return true.
1682 * Otherwise, if part of @oh is out hardreset or if no hardreset lines
1683 * associated with @oh are asserted, then return false.
Paul Walmsley747834a2012-04-18 19:10:04 -06001684 * This function is used to avoid executing some parts of the IP block
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001685 * enable/disable sequence if its hardreset line is set.
Paul Walmsley747834a2012-04-18 19:10:04 -06001686 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001687static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
Paul Walmsley747834a2012-04-18 19:10:04 -06001688{
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001689 int i, rst_cnt = 0;
Paul Walmsley747834a2012-04-18 19:10:04 -06001690
1691 if (oh->rst_lines_cnt == 0)
1692 return false;
1693
1694 for (i = 0; i < oh->rst_lines_cnt; i++)
1695 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001696 rst_cnt++;
1697
1698 if (oh->rst_lines_cnt == rst_cnt)
1699 return true;
Paul Walmsley747834a2012-04-18 19:10:04 -06001700
1701 return false;
1702}
1703
1704/**
Paul Walmsleye9332b62012-10-08 23:08:15 -06001705 * _are_any_hardreset_lines_asserted - return true if any part of @oh is
1706 * hard-reset
1707 * @oh: struct omap_hwmod *
1708 *
1709 * If any hardreset lines associated with @oh are asserted, then
1710 * return true. Otherwise, if no hardreset lines associated with @oh
1711 * are asserted, or if @oh has no hardreset lines, then return false.
1712 * This function is used to avoid executing some parts of the IP block
1713 * enable/disable sequence if any hardreset line is set.
1714 */
1715static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
1716{
1717 int rst_cnt = 0;
1718 int i;
1719
1720 for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
1721 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1722 rst_cnt++;
1723
1724 return (rst_cnt) ? true : false;
1725}
1726
1727/**
Paul Walmsley747834a2012-04-18 19:10:04 -06001728 * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
1729 * @oh: struct omap_hwmod *
1730 *
1731 * Disable the PRCM module mode related to the hwmod @oh.
1732 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1733 */
1734static int _omap4_disable_module(struct omap_hwmod *oh)
1735{
1736 int v;
1737
Paul Walmsley747834a2012-04-18 19:10:04 -06001738 if (!oh->clkdm || !oh->prcm.omap4.modulemode)
1739 return -EINVAL;
1740
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001741 /*
1742 * Since integration code might still be doing something, only
1743 * disable if all lines are under hardreset.
1744 */
Paul Walmsleye9332b62012-10-08 23:08:15 -06001745 if (_are_any_hardreset_lines_asserted(oh))
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001746 return 0;
1747
Paul Walmsley747834a2012-04-18 19:10:04 -06001748 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1749
Tero Kristo128603f2014-10-27 08:39:24 -07001750 omap_cm_module_disable(oh->clkdm->prcm_partition, oh->clkdm->cm_inst,
1751 oh->prcm.omap4.clkctrl_offs);
Paul Walmsley747834a2012-04-18 19:10:04 -06001752
Paul Walmsley747834a2012-04-18 19:10:04 -06001753 v = _omap4_wait_target_disable(oh);
1754 if (v)
1755 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1756 oh->name);
1757
1758 return 0;
1759}
1760
1761/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001762 * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
Paul Walmsley63c85232009-09-03 20:14:03 +03001763 * @oh: struct omap_hwmod *
1764 *
1765 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
Paul Walmsley30e105c2012-04-19 00:49:09 -06001766 * enabled for this to work. Returns -ENOENT if the hwmod cannot be
1767 * reset this way, -EINVAL if the hwmod is in the wrong state,
1768 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Benoit Cousson2cb06812010-09-21 18:57:59 +02001769 *
1770 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
Paul Walmsleybd361792010-12-14 12:42:35 -07001771 * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
Benoit Cousson2cb06812010-09-21 18:57:59 +02001772 * use the SYSCONFIG softreset bit to provide the status.
1773 *
Paul Walmsleybd361792010-12-14 12:42:35 -07001774 * Note that some IP like McBSP do have reset control but don't have
1775 * reset status.
Paul Walmsley63c85232009-09-03 20:14:03 +03001776 */
Paul Walmsleybd361792010-12-14 12:42:35 -07001777static int _ocp_softreset(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001778{
Tero Kristo613ad0e2012-10-29 22:02:13 -06001779 u32 v;
Paul Walmsley6f8b7ff2009-12-08 16:33:16 -07001780 int c = 0;
Benoit Cousson96835af2010-09-21 18:57:58 +02001781 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001782
Paul Walmsley43b40992010-02-22 22:09:34 -07001783 if (!oh->class->sysc ||
Benoit Cousson2cb06812010-09-21 18:57:59 +02001784 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley30e105c2012-04-19 00:49:09 -06001785 return -ENOENT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001786
1787 /* clocks must be on for this operation */
1788 if (oh->_state != _HWMOD_STATE_ENABLED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001789 pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
1790 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001791 return -EINVAL;
1792 }
1793
Benoit Cousson96835af2010-09-21 18:57:58 +02001794 /* For some modules, all optionnal clocks need to be enabled as well */
1795 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1796 _enable_optional_clocks(oh);
1797
Paul Walmsleybd361792010-12-14 12:42:35 -07001798 pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001799
1800 v = oh->_sysc_cache;
Benoit Cousson96835af2010-09-21 18:57:58 +02001801 ret = _set_softreset(oh, &v);
1802 if (ret)
1803 goto dis_opt_clks;
Roger Quadros313a76e2013-12-08 18:39:02 -07001804
1805 _write_sysconfig(v, oh);
Illia Smyrnov01142512014-02-05 17:06:09 +02001806
1807 if (oh->class->sysc->srst_udelay)
1808 udelay(oh->class->sysc->srst_udelay);
1809
1810 c = _wait_softreset_complete(oh);
1811 if (c == MAX_MODULE_SOFTRESET_WAIT) {
Joe Perches3d0cb732014-09-13 11:31:16 -07001812 pr_warn("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1813 oh->name, MAX_MODULE_SOFTRESET_WAIT);
Illia Smyrnov01142512014-02-05 17:06:09 +02001814 ret = -ETIMEDOUT;
1815 goto dis_opt_clks;
1816 } else {
1817 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1818 }
1819
Roger Quadros313a76e2013-12-08 18:39:02 -07001820 ret = _clear_softreset(oh, &v);
1821 if (ret)
1822 goto dis_opt_clks;
1823
Paul Walmsley63c85232009-09-03 20:14:03 +03001824 _write_sysconfig(v, oh);
1825
Paul Walmsley63c85232009-09-03 20:14:03 +03001826 /*
1827 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1828 * _wait_target_ready() or _reset()
1829 */
1830
Benoit Cousson96835af2010-09-21 18:57:58 +02001831dis_opt_clks:
1832 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1833 _disable_optional_clocks(oh);
1834
1835 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001836}
1837
1838/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001839 * _reset - reset an omap_hwmod
1840 * @oh: struct omap_hwmod *
1841 *
Paul Walmsley30e105c2012-04-19 00:49:09 -06001842 * Resets an omap_hwmod @oh. If the module has a custom reset
1843 * function pointer defined, then call it to reset the IP block, and
1844 * pass along its return value to the caller. Otherwise, if the IP
1845 * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
1846 * associated with it, call a function to reset the IP block via that
1847 * method, and pass along the return value to the caller. Finally, if
1848 * the IP block has some hardreset lines associated with it, assert
1849 * all of those, but do _not_ deassert them. (This is because driver
1850 * authors have expressed an apparent requirement to control the
1851 * deassertion of the hardreset lines themselves.)
1852 *
1853 * The default software reset mechanism for most OMAP IP blocks is
1854 * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
1855 * hwmods cannot be reset via this method. Some are not targets and
1856 * therefore have no OCP header registers to access. Others (like the
1857 * IVA) have idiosyncratic reset sequences. So for these relatively
1858 * rare cases, custom reset code can be supplied in the struct
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001859 * omap_hwmod_class .reset function pointer.
1860 *
1861 * _set_dmadisable() is called to set the DMADISABLE bit so that it
1862 * does not prevent idling of the system. This is necessary for cases
1863 * where ROMCODE/BOOTLOADER uses dma and transfers control to the
1864 * kernel without disabling dma.
1865 *
1866 * Passes along the return value from either _ocp_softreset() or the
1867 * custom reset function - these must return -EINVAL if the hwmod
1868 * cannot be reset this way or if the hwmod is in the wrong state,
1869 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Paul Walmsleybd361792010-12-14 12:42:35 -07001870 */
1871static int _reset(struct omap_hwmod *oh)
1872{
Paul Walmsley30e105c2012-04-19 00:49:09 -06001873 int i, r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001874
1875 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1876
Paul Walmsley30e105c2012-04-19 00:49:09 -06001877 if (oh->class->reset) {
1878 r = oh->class->reset(oh);
1879 } else {
1880 if (oh->rst_lines_cnt > 0) {
1881 for (i = 0; i < oh->rst_lines_cnt; i++)
1882 _assert_hardreset(oh, oh->rst_lines[i].name);
1883 return 0;
1884 } else {
1885 r = _ocp_softreset(oh);
1886 if (r == -ENOENT)
1887 r = 0;
1888 }
1889 }
Paul Walmsleybd361792010-12-14 12:42:35 -07001890
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001891 _set_dmadisable(oh);
1892
Paul Walmsley30e105c2012-04-19 00:49:09 -06001893 /*
1894 * OCP_SYSCONFIG bits need to be reprogrammed after a
1895 * softreset. The _enable() function should be split to avoid
1896 * the rewrite of the OCP_SYSCONFIG register.
1897 */
Rajendra Nayak28008522012-03-13 22:55:23 +05301898 if (oh->class->sysc) {
1899 _update_sysc_cache(oh);
1900 _enable_sysc(oh);
1901 }
1902
Paul Walmsley30e105c2012-04-19 00:49:09 -06001903 return r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001904}
1905
1906/**
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07001907 * _omap4_update_context_lost - increment hwmod context loss counter if
1908 * hwmod context was lost, and clear hardware context loss reg
1909 * @oh: hwmod to check for context loss
1910 *
1911 * If the PRCM indicates that the hwmod @oh lost context, increment
1912 * our in-memory context loss counter, and clear the RM_*_CONTEXT
1913 * bits. No return value.
1914 */
1915static void _omap4_update_context_lost(struct omap_hwmod *oh)
1916{
1917 if (oh->prcm.omap4.flags & HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT)
1918 return;
1919
1920 if (!prm_was_any_context_lost_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1921 oh->clkdm->pwrdm.ptr->prcm_offs,
1922 oh->prcm.omap4.context_offs))
1923 return;
1924
1925 oh->prcm.omap4.context_lost_counter++;
1926 prm_clear_context_loss_flags_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1927 oh->clkdm->pwrdm.ptr->prcm_offs,
1928 oh->prcm.omap4.context_offs);
1929}
1930
1931/**
1932 * _omap4_get_context_lost - get context loss counter for a hwmod
1933 * @oh: hwmod to get context loss counter for
1934 *
1935 * Returns the in-memory context loss counter for a hwmod.
1936 */
1937static int _omap4_get_context_lost(struct omap_hwmod *oh)
1938{
1939 return oh->prcm.omap4.context_lost_counter;
1940}
1941
1942/**
Paul Walmsley6d266f62013-02-10 11:22:22 -07001943 * _enable_preprogram - Pre-program an IP block during the _enable() process
1944 * @oh: struct omap_hwmod *
1945 *
1946 * Some IP blocks (such as AESS) require some additional programming
1947 * after enable before they can enter idle. If a function pointer to
1948 * do so is present in the hwmod data, then call it and pass along the
1949 * return value; otherwise, return 0.
1950 */
jean-philippe francois0f497032013-05-16 11:25:07 -07001951static int _enable_preprogram(struct omap_hwmod *oh)
Paul Walmsley6d266f62013-02-10 11:22:22 -07001952{
1953 if (!oh->class->enable_preprogram)
1954 return 0;
1955
1956 return oh->class->enable_preprogram(oh);
1957}
1958
1959/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001960 * _enable - enable an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001961 * @oh: struct omap_hwmod *
1962 *
1963 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001964 * register target. Returns -EINVAL if the hwmod is in the wrong
1965 * state or passes along the return value of _wait_target_ready().
Paul Walmsley63c85232009-09-03 20:14:03 +03001966 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001967static int _enable(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001968{
Paul Walmsley747834a2012-04-18 19:10:04 -06001969 int r;
Paul Walmsley63c85232009-09-03 20:14:03 +03001970
Benoit Cousson34617e22011-07-01 22:54:07 +02001971 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1972
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001973 /*
Paul Walmsley64813c32012-04-18 19:10:03 -06001974 * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
Tony Lindgrenb4281452016-10-20 06:35:21 -07001975 * state at init.
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001976 */
1977 if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001978 oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
1979 return 0;
1980 }
1981
Paul Walmsley63c85232009-09-03 20:14:03 +03001982 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1983 oh->_state != _HWMOD_STATE_IDLE &&
1984 oh->_state != _HWMOD_STATE_DISABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00001985 WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
1986 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001987 return -EINVAL;
1988 }
1989
Benoit Cousson31f62862011-07-01 22:54:05 +02001990 /*
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001991 * If an IP block contains HW reset lines and all of them are
Paul Walmsley747834a2012-04-18 19:10:04 -06001992 * asserted, we let integration code associated with that
1993 * block handle the enable. We've received very little
1994 * information on what those driver authors need, and until
1995 * detailed information is provided and the driver code is
1996 * posted to the public lists, this is probably the best we
1997 * can do.
Benoit Cousson31f62862011-07-01 22:54:05 +02001998 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001999 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06002000 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03002001
Rajendra Nayak665d0012011-07-10 05:57:07 -06002002 _add_initiator_dep(oh, mpu_oh);
2003
2004 if (oh->clkdm) {
2005 /*
2006 * A clockdomain must be in SW_SUP before enabling
2007 * completely the module. The clockdomain can be set
2008 * in HW_AUTO only when the module become ready.
2009 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03002010 clkdm_deny_idle(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002011 r = clkdm_hwmod_enable(oh->clkdm, oh);
2012 if (r) {
2013 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
2014 oh->name, oh->clkdm->name, r);
2015 return r;
2016 }
Benoit Cousson34617e22011-07-01 22:54:07 +02002017 }
Rajendra Nayak665d0012011-07-10 05:57:07 -06002018
2019 _enable_clocks(oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002020 if (soc_ops.enable_module)
2021 soc_ops.enable_module(oh);
Paul Walmsleyfa200222013-01-26 00:48:56 -07002022 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01002023 cpu_idle_poll_ctrl(true);
Benoit Cousson34617e22011-07-01 22:54:07 +02002024
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07002025 if (soc_ops.update_context_lost)
2026 soc_ops.update_context_lost(oh);
2027
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002028 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
2029 -EINVAL;
Roger Quadros8ff42da2017-03-17 10:58:18 +02002030 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
Tero Kristo1d9a5422016-06-30 16:15:02 +03002031 clkdm_allow_idle(oh->clkdm);
Benoit Cousson34617e22011-07-01 22:54:07 +02002032
Tero Kristo1d9a5422016-06-30 16:15:02 +03002033 if (!r) {
Rajendra Nayak665d0012011-07-10 05:57:07 -06002034 oh->_state = _HWMOD_STATE_ENABLED;
2035
2036 /* Access the sysconfig only if the target is ready */
2037 if (oh->class->sysc) {
2038 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
2039 _update_sysc_cache(oh);
2040 _enable_sysc(oh);
2041 }
Paul Walmsley6d266f62013-02-10 11:22:22 -07002042 r = _enable_preprogram(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002043 } else {
Paul Walmsley2577a4a2012-10-29 20:57:55 -06002044 if (soc_ops.disable_module)
2045 soc_ops.disable_module(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002046 _disable_clocks(oh);
Lokesh Vutla812ce9d2014-12-19 18:04:50 +05302047 pr_err("omap_hwmod: %s: _wait_target_ready failed: %d\n",
2048 oh->name, r);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002049
2050 if (oh->clkdm)
2051 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002052 }
2053
Paul Walmsley63c85232009-09-03 20:14:03 +03002054 return r;
2055}
2056
2057/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002058 * _idle - idle an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03002059 * @oh: struct omap_hwmod *
2060 *
2061 * Idles an omap_hwmod @oh. This should be called once the hwmod has
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002062 * no further work. Returns -EINVAL if the hwmod is in the wrong
2063 * state or returns 0.
Paul Walmsley63c85232009-09-03 20:14:03 +03002064 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002065static int _idle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002066{
Lokesh Vutla2e18f5a2016-03-07 01:41:21 -07002067 if (oh->flags & HWMOD_NO_IDLE) {
2068 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
2069 return 0;
2070 }
2071
Benoit Cousson34617e22011-07-01 22:54:07 +02002072 pr_debug("omap_hwmod: %s: idling\n", oh->name);
2073
Suman Annac20c8f72016-04-10 13:20:11 -06002074 if (_are_all_hardreset_lines_asserted(oh))
2075 return 0;
2076
Paul Walmsley63c85232009-09-03 20:14:03 +03002077 if (oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002078 WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
2079 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002080 return -EINVAL;
2081 }
2082
Paul Walmsley43b40992010-02-22 22:09:34 -07002083 if (oh->class->sysc)
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002084 _idle_sysc(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002085 _del_initiator_dep(oh, mpu_oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002086
Roger Quadros8ff42da2017-03-17 10:58:18 +02002087 /*
2088 * If HWMOD_CLKDM_NOAUTO is set then we don't
2089 * deny idle the clkdm again since idle was already denied
2090 * in _enable()
2091 */
2092 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
Tero Kristo1d9a5422016-06-30 16:15:02 +03002093 clkdm_deny_idle(oh->clkdm);
2094
Paul Walmsleyfa200222013-01-26 00:48:56 -07002095 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01002096 cpu_idle_poll_ctrl(false);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002097 if (soc_ops.disable_module)
2098 soc_ops.disable_module(oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002099
Benoit Cousson45c38252011-07-10 05:56:33 -06002100 /*
2101 * The module must be in idle mode before disabling any parents
2102 * clocks. Otherwise, the parent clock might be disabled before
2103 * the module transition is done, and thus will prevent the
2104 * transition to complete properly.
2105 */
2106 _disable_clocks(oh);
Tero Kristo1d9a5422016-06-30 16:15:02 +03002107 if (oh->clkdm) {
2108 clkdm_allow_idle(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002109 clkdm_hwmod_disable(oh->clkdm, oh);
Tero Kristo1d9a5422016-06-30 16:15:02 +03002110 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002111
2112 oh->_state = _HWMOD_STATE_IDLE;
2113
2114 return 0;
2115}
2116
2117/**
2118 * _shutdown - shutdown an omap_hwmod
2119 * @oh: struct omap_hwmod *
2120 *
2121 * Shut down an omap_hwmod @oh. This should be called when the driver
2122 * used for the hwmod is removed or unloaded or if the driver is not
2123 * used by the system. Returns -EINVAL if the hwmod is in the wrong
2124 * state or returns 0.
2125 */
2126static int _shutdown(struct omap_hwmod *oh)
2127{
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002128 int ret, i;
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002129 u8 prev_state;
2130
Suman Annac20c8f72016-04-10 13:20:11 -06002131 if (_are_all_hardreset_lines_asserted(oh))
2132 return 0;
2133
Paul Walmsley63c85232009-09-03 20:14:03 +03002134 if (oh->_state != _HWMOD_STATE_IDLE &&
2135 oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002136 WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
2137 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002138 return -EINVAL;
2139 }
2140
2141 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
2142
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002143 if (oh->class->pre_shutdown) {
2144 prev_state = oh->_state;
2145 if (oh->_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002146 _enable(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002147 ret = oh->class->pre_shutdown(oh);
2148 if (ret) {
2149 if (prev_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002150 _idle(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002151 return ret;
2152 }
2153 }
2154
Miguel Vadillo6481c732011-07-01 22:54:02 +02002155 if (oh->class->sysc) {
2156 if (oh->_state == _HWMOD_STATE_IDLE)
2157 _enable(oh);
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002158 _shutdown_sysc(oh);
Miguel Vadillo6481c732011-07-01 22:54:02 +02002159 }
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06002160
Benoit Cousson3827f942010-09-21 10:34:08 -06002161 /* clocks and deps are already disabled in idle */
2162 if (oh->_state == _HWMOD_STATE_ENABLED) {
2163 _del_initiator_dep(oh, mpu_oh);
2164 /* XXX what about the other system initiators here? dma, dsp */
Paul Walmsleyfa200222013-01-26 00:48:56 -07002165 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01002166 cpu_idle_poll_ctrl(false);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002167 if (soc_ops.disable_module)
2168 soc_ops.disable_module(oh);
Benoit Cousson45c38252011-07-10 05:56:33 -06002169 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002170 if (oh->clkdm)
2171 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson3827f942010-09-21 10:34:08 -06002172 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002173 /* XXX Should this code also force-disable the optional clocks? */
2174
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002175 for (i = 0; i < oh->rst_lines_cnt; i++)
2176 _assert_hardreset(oh, oh->rst_lines[i].name);
Benoit Cousson31f62862011-07-01 22:54:05 +02002177
Paul Walmsley63c85232009-09-03 20:14:03 +03002178 oh->_state = _HWMOD_STATE_DISABLED;
2179
2180 return 0;
2181}
2182
Tony Lindgren5e863c52013-12-06 14:20:16 -08002183static int of_dev_find_hwmod(struct device_node *np,
2184 struct omap_hwmod *oh)
2185{
2186 int count, i, res;
2187 const char *p;
2188
2189 count = of_property_count_strings(np, "ti,hwmods");
2190 if (count < 1)
2191 return -ENODEV;
2192
2193 for (i = 0; i < count; i++) {
2194 res = of_property_read_string_index(np, "ti,hwmods",
2195 i, &p);
2196 if (res)
2197 continue;
2198 if (!strcmp(p, oh->name)) {
2199 pr_debug("omap_hwmod: dt %s[%i] uses hwmod %s\n",
2200 np->name, i, oh->name);
2201 return i;
2202 }
2203 }
2204
2205 return -ENODEV;
2206}
2207
Paul Walmsley63c85232009-09-03 20:14:03 +03002208/**
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302209 * of_dev_hwmod_lookup - look up needed hwmod from dt blob
2210 * @np: struct device_node *
2211 * @oh: struct omap_hwmod *
Tony Lindgren5e863c52013-12-06 14:20:16 -08002212 * @index: index of the entry found
2213 * @found: struct device_node * found or NULL
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302214 *
2215 * Parse the dt blob and find out needed hwmod. Recursive function is
2216 * implemented to take care hierarchical dt blob parsing.
Tony Lindgren5e863c52013-12-06 14:20:16 -08002217 * Return: Returns 0 on success, -ENODEV when not found.
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302218 */
Tony Lindgren5e863c52013-12-06 14:20:16 -08002219static int of_dev_hwmod_lookup(struct device_node *np,
2220 struct omap_hwmod *oh,
2221 int *index,
2222 struct device_node **found)
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302223{
Tony Lindgren5e863c52013-12-06 14:20:16 -08002224 struct device_node *np0 = NULL;
2225 int res;
2226
2227 res = of_dev_find_hwmod(np, oh);
2228 if (res >= 0) {
2229 *found = np;
2230 *index = res;
2231 return 0;
2232 }
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302233
2234 for_each_child_of_node(np, np0) {
Tony Lindgren5e863c52013-12-06 14:20:16 -08002235 struct device_node *fc;
2236 int i;
2237
2238 res = of_dev_hwmod_lookup(np0, oh, &i, &fc);
2239 if (res == 0) {
2240 *found = fc;
2241 *index = i;
2242 return 0;
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302243 }
2244 }
Tony Lindgren5e863c52013-12-06 14:20:16 -08002245
2246 *found = NULL;
2247 *index = 0;
2248
2249 return -ENODEV;
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302250}
2251
2252/**
Paul Walmsley381d0332012-04-19 00:58:22 -06002253 * _init_mpu_rt_base - populate the virtual address for a hwmod
2254 * @oh: struct omap_hwmod * to locate the virtual address
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002255 * @data: (unused, caller should pass NULL)
Tony Lindgren5e863c52013-12-06 14:20:16 -08002256 * @index: index of the reg entry iospace in device tree
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002257 * @np: struct device_node * of the IP block's device node in the DT data
Paul Walmsley381d0332012-04-19 00:58:22 -06002258 *
2259 * Cache the virtual address used by the MPU to access this IP block's
2260 * registers. This address is needed early so the OCP registers that
2261 * are part of the device's address space can be ioremapped properly.
Suman Anna6423d6d2013-10-08 23:46:49 -06002262 *
Roger Quadros9a258af2015-07-16 16:16:44 +03002263 * If SYSC access is not needed, the registers will not be remapped
2264 * and non-availability of MPU access is not treated as an error.
2265 *
Suman Anna6423d6d2013-10-08 23:46:49 -06002266 * Returns 0 on success, -EINVAL if an invalid hwmod is passed, and
2267 * -ENXIO on absent or invalid register target address space.
Paul Walmsley381d0332012-04-19 00:58:22 -06002268 */
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002269static int __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data,
Tony Lindgren5e863c52013-12-06 14:20:16 -08002270 int index, struct device_node *np)
Paul Walmsley381d0332012-04-19 00:58:22 -06002271{
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002272 struct omap_hwmod_addr_space *mem;
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302273 void __iomem *va_start = NULL;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002274
2275 if (!oh)
Suman Anna6423d6d2013-10-08 23:46:49 -06002276 return -EINVAL;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002277
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002278 _save_mpu_port_index(oh);
2279
Roger Quadros9a258af2015-07-16 16:16:44 +03002280 /* if we don't need sysc access we don't need to ioremap */
2281 if (!oh->class->sysc)
2282 return 0;
2283
2284 /* we can't continue without MPU PORT if we need sysc access */
Paul Walmsley381d0332012-04-19 00:58:22 -06002285 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
Suman Anna6423d6d2013-10-08 23:46:49 -06002286 return -ENXIO;
Paul Walmsley381d0332012-04-19 00:58:22 -06002287
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002288 mem = _find_mpu_rt_addr_space(oh);
2289 if (!mem) {
2290 pr_debug("omap_hwmod: %s: no MPU register target found\n",
2291 oh->name);
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302292
2293 /* Extract the IO space from device tree blob */
Roger Quadros9a258af2015-07-16 16:16:44 +03002294 if (!np) {
2295 pr_err("omap_hwmod: %s: no dt node\n", oh->name);
Suman Anna6423d6d2013-10-08 23:46:49 -06002296 return -ENXIO;
Roger Quadros9a258af2015-07-16 16:16:44 +03002297 }
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302298
Tony Lindgren5e863c52013-12-06 14:20:16 -08002299 va_start = of_iomap(np, index + oh->mpu_rt_idx);
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302300 } else {
2301 va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start);
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002302 }
2303
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002304 if (!va_start) {
Tony Lindgren5e863c52013-12-06 14:20:16 -08002305 if (mem)
2306 pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name);
2307 else
2308 pr_err("omap_hwmod: %s: Missing dt reg%i for %s\n",
2309 oh->name, index, np->full_name);
Suman Anna6423d6d2013-10-08 23:46:49 -06002310 return -ENXIO;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002311 }
2312
2313 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
2314 oh->name, va_start);
2315
2316 oh->_mpu_rt_va = va_start;
Suman Anna6423d6d2013-10-08 23:46:49 -06002317 return 0;
Paul Walmsley381d0332012-04-19 00:58:22 -06002318}
2319
2320/**
2321 * _init - initialize internal data for the hwmod @oh
2322 * @oh: struct omap_hwmod *
2323 * @n: (unused)
2324 *
2325 * Look up the clocks and the address space used by the MPU to access
2326 * registers belonging to the hwmod @oh. @oh must already be
2327 * registered at this point. This is the first of two phases for
2328 * hwmod initialization. Code called here does not touch any hardware
2329 * registers, it simply prepares internal data structures. Returns 0
Suman Anna6423d6d2013-10-08 23:46:49 -06002330 * upon success or if the hwmod isn't registered or if the hwmod's
2331 * address space is not defined, or -EINVAL upon failure.
Paul Walmsley381d0332012-04-19 00:58:22 -06002332 */
2333static int __init _init(struct omap_hwmod *oh, void *data)
2334{
Tony Lindgren5e863c52013-12-06 14:20:16 -08002335 int r, index;
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002336 struct device_node *np = NULL;
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002337 struct device_node *bus;
Paul Walmsley381d0332012-04-19 00:58:22 -06002338
2339 if (oh->_state != _HWMOD_STATE_REGISTERED)
2340 return 0;
2341
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002342 bus = of_find_node_by_name(NULL, "ocp");
2343 if (!bus)
2344 return -ENODEV;
Tony Lindgren5e863c52013-12-06 14:20:16 -08002345
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002346 r = of_dev_hwmod_lookup(bus, oh, &index, &np);
2347 if (r)
2348 pr_debug("omap_hwmod: %s missing dt data\n", oh->name);
2349 else if (np && index)
2350 pr_warn("omap_hwmod: %s using broken dt data from %s\n",
2351 oh->name, np->name);
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002352
Roger Quadros9a258af2015-07-16 16:16:44 +03002353 r = _init_mpu_rt_base(oh, NULL, index, np);
2354 if (r < 0) {
2355 WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n",
2356 oh->name);
2357 return 0;
Suman Anna6423d6d2013-10-08 23:46:49 -06002358 }
Paul Walmsley381d0332012-04-19 00:58:22 -06002359
2360 r = _init_clocks(oh, NULL);
Russell Kingc48cd652013-03-13 20:44:21 +00002361 if (r < 0) {
Paul Walmsley381d0332012-04-19 00:58:22 -06002362 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2363 return -EINVAL;
2364 }
2365
Suman Anna3d36ad72014-03-14 14:45:17 +05302366 if (np) {
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002367 if (of_find_property(np, "ti,no-reset-on-init", NULL))
2368 oh->flags |= HWMOD_INIT_NO_RESET;
2369 if (of_find_property(np, "ti,no-idle-on-init", NULL))
2370 oh->flags |= HWMOD_INIT_NO_IDLE;
Lokesh Vutla2e18f5a2016-03-07 01:41:21 -07002371 if (of_find_property(np, "ti,no-idle", NULL))
2372 oh->flags |= HWMOD_NO_IDLE;
Suman Anna3d36ad72014-03-14 14:45:17 +05302373 }
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002374
Paul Walmsley381d0332012-04-19 00:58:22 -06002375 oh->_state = _HWMOD_STATE_INITIALIZED;
2376
2377 return 0;
2378}
2379
2380/**
Paul Walmsley64813c32012-04-18 19:10:03 -06002381 * _setup_iclk_autoidle - configure an IP block's interface clocks
Paul Walmsley63c85232009-09-03 20:14:03 +03002382 * @oh: struct omap_hwmod *
2383 *
Paul Walmsley64813c32012-04-18 19:10:03 -06002384 * Set up the module's interface clocks. XXX This function is still mostly
2385 * a stub; implementing this properly requires iclk autoidle usecounting in
2386 * the clock code. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03002387 */
Paul Walmsley64813c32012-04-18 19:10:03 -06002388static void __init _setup_iclk_autoidle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002389{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002390 struct omap_hwmod_ocp_if *os;
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07002391
Paul Walmsley381d0332012-04-19 00:58:22 -06002392 if (oh->_state != _HWMOD_STATE_INITIALIZED)
Paul Walmsley64813c32012-04-18 19:10:03 -06002393 return;
Paul Walmsley48d54f32011-02-23 00:14:07 -07002394
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07002395 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002396 if (!os->_clk)
Paul Walmsley64813c32012-04-18 19:10:03 -06002397 continue;
Paul Walmsley63c85232009-09-03 20:14:03 +03002398
Paul Walmsley64813c32012-04-18 19:10:03 -06002399 if (os->flags & OCPIF_SWSUP_IDLE) {
2400 /* XXX omap_iclk_deny_idle(c); */
2401 } else {
2402 /* XXX omap_iclk_allow_idle(c); */
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002403 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +03002404 }
2405 }
2406
Paul Walmsley64813c32012-04-18 19:10:03 -06002407 return;
2408}
2409
2410/**
2411 * _setup_reset - reset an IP block during the setup process
2412 * @oh: struct omap_hwmod *
2413 *
2414 * Reset the IP block corresponding to the hwmod @oh during the setup
2415 * process. The IP block is first enabled so it can be successfully
2416 * reset. Returns 0 upon success or a negative error code upon
2417 * failure.
2418 */
2419static int __init _setup_reset(struct omap_hwmod *oh)
2420{
2421 int r;
2422
2423 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2424 return -EINVAL;
Paul Walmsley63c85232009-09-03 20:14:03 +03002425
Paul Walmsley5fb3d522012-10-29 22:11:50 -06002426 if (oh->flags & HWMOD_EXT_OPT_MAIN_CLK)
2427 return -EPERM;
2428
Paul Walmsley747834a2012-04-18 19:10:04 -06002429 if (oh->rst_lines_cnt == 0) {
2430 r = _enable(oh);
2431 if (r) {
Joe Perches3d0cb732014-09-13 11:31:16 -07002432 pr_warn("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2433 oh->name, oh->_state);
Paul Walmsley747834a2012-04-18 19:10:04 -06002434 return -EINVAL;
2435 }
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002436 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002437
Rajendra Nayak28008522012-03-13 22:55:23 +05302438 if (!(oh->flags & HWMOD_INIT_NO_RESET))
Paul Walmsley64813c32012-04-18 19:10:03 -06002439 r = _reset(oh);
2440
2441 return r;
2442}
2443
2444/**
2445 * _setup_postsetup - transition to the appropriate state after _setup
2446 * @oh: struct omap_hwmod *
2447 *
2448 * Place an IP block represented by @oh into a "post-setup" state --
2449 * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that
2450 * this function is called at the end of _setup().) The postsetup
2451 * state for an IP block can be changed by calling
2452 * omap_hwmod_enter_postsetup_state() early in the boot process,
2453 * before one of the omap_hwmod_setup*() functions are called for the
2454 * IP block.
2455 *
2456 * The IP block stays in this state until a PM runtime-based driver is
2457 * loaded for that IP block. A post-setup state of IDLE is
2458 * appropriate for almost all IP blocks with runtime PM-enabled
2459 * drivers, since those drivers are able to enable the IP block. A
2460 * post-setup state of ENABLED is appropriate for kernels with PM
2461 * runtime disabled. The DISABLED state is appropriate for unusual IP
2462 * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2463 * included, since the WDTIMER starts running on reset and will reset
2464 * the MPU if left active.
2465 *
2466 * This post-setup mechanism is deprecated. Once all of the OMAP
2467 * drivers have been converted to use PM runtime, and all of the IP
2468 * block data and interconnect data is available to the hwmod code, it
2469 * should be possible to replace this mechanism with a "lazy reset"
2470 * arrangement. In a "lazy reset" setup, each IP block is enabled
2471 * when the driver first probes, then all remaining IP blocks without
2472 * drivers are either shut down or enabled after the drivers have
2473 * loaded. However, this cannot take place until the above
2474 * preconditions have been met, since otherwise the late reset code
2475 * has no way of knowing which IP blocks are in use by drivers, and
2476 * which ones are unused.
2477 *
2478 * No return value.
2479 */
2480static void __init _setup_postsetup(struct omap_hwmod *oh)
2481{
2482 u8 postsetup_state;
2483
2484 if (oh->rst_lines_cnt > 0)
2485 return;
Benoit Cousson76e55892010-09-21 10:34:11 -06002486
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002487 postsetup_state = oh->_postsetup_state;
2488 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2489 postsetup_state = _HWMOD_STATE_ENABLED;
2490
2491 /*
2492 * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2493 * it should be set by the core code as a runtime flag during startup
2494 */
Lokesh Vutla2e18f5a2016-03-07 01:41:21 -07002495 if ((oh->flags & (HWMOD_INIT_NO_IDLE | HWMOD_NO_IDLE)) &&
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002496 (postsetup_state == _HWMOD_STATE_IDLE)) {
2497 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002498 postsetup_state = _HWMOD_STATE_ENABLED;
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002499 }
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002500
2501 if (postsetup_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002502 _idle(oh);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002503 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2504 _shutdown(oh);
2505 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2506 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2507 oh->name, postsetup_state);
Paul Walmsley63c85232009-09-03 20:14:03 +03002508
Paul Walmsley64813c32012-04-18 19:10:03 -06002509 return;
2510}
2511
2512/**
2513 * _setup - prepare IP block hardware for use
2514 * @oh: struct omap_hwmod *
2515 * @n: (unused, pass NULL)
2516 *
2517 * Configure the IP block represented by @oh. This may include
2518 * enabling the IP block, resetting it, and placing it into a
2519 * post-setup state, depending on the type of IP block and applicable
2520 * flags. IP blocks are reset to prevent any previous configuration
2521 * by the bootloader or previous operating system from interfering
2522 * with power management or other parts of the system. The reset can
2523 * be avoided; see omap_hwmod_no_setup_reset(). This is the second of
2524 * two phases for hwmod initialization. Code called here generally
2525 * affects the IP block hardware, or system integration hardware
2526 * associated with the IP block. Returns 0.
2527 */
2528static int __init _setup(struct omap_hwmod *oh, void *data)
2529{
2530 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2531 return 0;
2532
Tomi Valkeinenf22d2542014-10-09 17:03:14 +03002533 if (oh->parent_hwmod) {
2534 int r;
2535
2536 r = _enable(oh->parent_hwmod);
2537 WARN(r, "hwmod: %s: setup: failed to enable parent hwmod %s\n",
2538 oh->name, oh->parent_hwmod->name);
2539 }
2540
Paul Walmsley64813c32012-04-18 19:10:03 -06002541 _setup_iclk_autoidle(oh);
2542
2543 if (!_setup_reset(oh))
2544 _setup_postsetup(oh);
2545
Tomi Valkeinenf22d2542014-10-09 17:03:14 +03002546 if (oh->parent_hwmod) {
2547 u8 postsetup_state;
2548
2549 postsetup_state = oh->parent_hwmod->_postsetup_state;
2550
2551 if (postsetup_state == _HWMOD_STATE_IDLE)
2552 _idle(oh->parent_hwmod);
2553 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2554 _shutdown(oh->parent_hwmod);
2555 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2556 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2557 oh->parent_hwmod->name, postsetup_state);
2558 }
2559
Paul Walmsley63c85232009-09-03 20:14:03 +03002560 return 0;
2561}
2562
Benoit Cousson0102b622010-12-21 21:31:27 -07002563/**
2564 * _register - register a struct omap_hwmod
2565 * @oh: struct omap_hwmod *
2566 *
2567 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
2568 * already has been registered by the same name; -EINVAL if the
2569 * omap_hwmod is in the wrong state, if @oh is NULL, if the
2570 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2571 * name, or if the omap_hwmod's class is missing a name; or 0 upon
2572 * success.
2573 *
2574 * XXX The data should be copied into bootmem, so the original data
2575 * should be marked __initdata and freed after init. This would allow
2576 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
2577 * that the copy process would be relatively complex due to the large number
2578 * of substructures.
2579 */
Benoit Cousson01592df2010-12-21 21:31:28 -07002580static int __init _register(struct omap_hwmod *oh)
Benoit Cousson0102b622010-12-21 21:31:27 -07002581{
Benoit Cousson0102b622010-12-21 21:31:27 -07002582 if (!oh || !oh->name || !oh->class || !oh->class->name ||
2583 (oh->_state != _HWMOD_STATE_UNKNOWN))
2584 return -EINVAL;
2585
Benoit Cousson0102b622010-12-21 21:31:27 -07002586 pr_debug("omap_hwmod: %s: registering\n", oh->name);
2587
Benoit Coussonce35b242010-12-21 21:31:28 -07002588 if (_lookup(oh->name))
2589 return -EEXIST;
Benoit Cousson0102b622010-12-21 21:31:27 -07002590
Benoit Cousson0102b622010-12-21 21:31:27 -07002591 list_add_tail(&oh->node, &omap_hwmod_list);
2592
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002593 INIT_LIST_HEAD(&oh->slave_ports);
Benoit Cousson0102b622010-12-21 21:31:27 -07002594 spin_lock_init(&oh->_lock);
Peter Ujfalusi69317952015-02-26 00:00:51 -07002595 lockdep_set_class(&oh->_lock, &oh->hwmod_key);
Benoit Cousson0102b622010-12-21 21:31:27 -07002596
2597 oh->_state = _HWMOD_STATE_REGISTERED;
2598
Paul Walmsley569edd702011-02-23 00:14:06 -07002599 /*
2600 * XXX Rather than doing a strcmp(), this should test a flag
2601 * set in the hwmod data, inserted by the autogenerator code.
2602 */
2603 if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2604 mpu_oh = oh;
Benoit Cousson0102b622010-12-21 21:31:27 -07002605
Paul Walmsley569edd702011-02-23 00:14:06 -07002606 return 0;
Benoit Cousson0102b622010-12-21 21:31:27 -07002607}
Paul Walmsley63c85232009-09-03 20:14:03 +03002608
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002609/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002610 * _add_link - add an interconnect between two IP blocks
2611 * @oi: pointer to a struct omap_hwmod_ocp_if record
2612 *
Tony Lindgrena1e31232017-03-14 13:13:19 -07002613 * Add struct omap_hwmod_link records connecting the slave IP block
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002614 * specified in @oi->slave to @oi. This code is assumed to run before
2615 * preemption or SMP has been enabled, thus avoiding the need for
2616 * locking in this code. Changes to this assumption will require
2617 * additional locking. Returns 0.
2618 */
2619static int __init _add_link(struct omap_hwmod_ocp_if *oi)
2620{
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002621 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2622 oi->slave->name);
2623
Tony Lindgrena1e31232017-03-14 13:13:19 -07002624 list_add(&oi->node, &oi->slave->slave_ports);
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002625 oi->slave->slaves_cnt++;
2626
2627 return 0;
2628}
2629
2630/**
2631 * _register_link - register a struct omap_hwmod_ocp_if
2632 * @oi: struct omap_hwmod_ocp_if *
2633 *
2634 * Registers the omap_hwmod_ocp_if record @oi. Returns -EEXIST if it
2635 * has already been registered; -EINVAL if @oi is NULL or if the
2636 * record pointed to by @oi is missing required fields; or 0 upon
2637 * success.
2638 *
2639 * XXX The data should be copied into bootmem, so the original data
2640 * should be marked __initdata and freed after init. This would allow
2641 * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2642 */
2643static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2644{
2645 if (!oi || !oi->master || !oi->slave || !oi->user)
2646 return -EINVAL;
2647
2648 if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2649 return -EEXIST;
2650
2651 pr_debug("omap_hwmod: registering link from %s to %s\n",
2652 oi->master->name, oi->slave->name);
2653
2654 /*
2655 * Register the connected hwmods, if they haven't been
2656 * registered already
2657 */
2658 if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2659 _register(oi->master);
2660
2661 if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2662 _register(oi->slave);
2663
2664 _add_link(oi);
2665
2666 oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2667
2668 return 0;
2669}
2670
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002671/* Static functions intended only for use in soc_ops field function pointers */
2672
2673/**
Tero Kristo9002e9212014-10-27 08:39:23 -07002674 * _omap2xxx_3xxx_wait_target_ready - wait for a module to leave slave idle
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002675 * @oh: struct omap_hwmod *
2676 *
2677 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2678 * does not have an IDLEST bit or if the module successfully leaves
2679 * slave idle; otherwise, pass along the return value of the
2680 * appropriate *_cm*_wait_module_ready() function.
2681 */
Tero Kristo9002e9212014-10-27 08:39:23 -07002682static int _omap2xxx_3xxx_wait_target_ready(struct omap_hwmod *oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002683{
2684 if (!oh)
2685 return -EINVAL;
2686
2687 if (oh->flags & HWMOD_NO_IDLEST)
2688 return 0;
2689
2690 if (!_find_mpu_rt_port(oh))
2691 return 0;
2692
2693 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2694
Tero Kristo021b6ff2014-10-27 08:39:23 -07002695 return omap_cm_wait_module_ready(0, oh->prcm.omap2.module_offs,
2696 oh->prcm.omap2.idlest_reg_id,
2697 oh->prcm.omap2.idlest_idle_bit);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002698}
2699
2700/**
2701 * _omap4_wait_target_ready - wait for a module to leave slave idle
2702 * @oh: struct omap_hwmod *
2703 *
2704 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2705 * does not have an IDLEST bit or if the module successfully leaves
2706 * slave idle; otherwise, pass along the return value of the
2707 * appropriate *_cm*_wait_module_ready() function.
2708 */
2709static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2710{
Paul Walmsley2b026d12012-09-23 17:28:18 -06002711 if (!oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002712 return -EINVAL;
2713
Paul Walmsley2b026d12012-09-23 17:28:18 -06002714 if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002715 return 0;
2716
2717 if (!_find_mpu_rt_port(oh))
2718 return 0;
2719
Dave Gerlach428929c2016-07-12 12:50:33 -05002720 if (!oh->prcm.omap4.clkctrl_offs &&
2721 !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
2722 return 0;
2723
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002724 /* XXX check module SIDLEMODE, hardreset status */
2725
Tero Kristo021b6ff2014-10-27 08:39:23 -07002726 return omap_cm_wait_module_ready(oh->clkdm->prcm_partition,
2727 oh->clkdm->cm_inst,
2728 oh->prcm.omap4.clkctrl_offs, 0);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002729}
2730
2731/**
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002732 * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2733 * @oh: struct omap_hwmod * to assert hardreset
2734 * @ohri: hardreset line data
2735 *
2736 * Call omap2_prm_assert_hardreset() with parameters extracted from
2737 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2738 * use as an soc_ops function pointer. Passes along the return value
2739 * from omap2_prm_assert_hardreset(). XXX This function is scheduled
2740 * for removal when the PRM code is moved into drivers/.
2741 */
2742static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2743 struct omap_hwmod_rst_info *ohri)
2744{
Tero Kristoefd44dc2014-10-27 08:39:24 -07002745 return omap_prm_assert_hardreset(ohri->rst_shift, 0,
2746 oh->prcm.omap2.module_offs, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002747}
2748
2749/**
2750 * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2751 * @oh: struct omap_hwmod * to deassert hardreset
2752 * @ohri: hardreset line data
2753 *
2754 * Call omap2_prm_deassert_hardreset() with parameters extracted from
2755 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2756 * use as an soc_ops function pointer. Passes along the return value
2757 * from omap2_prm_deassert_hardreset(). XXX This function is
2758 * scheduled for removal when the PRM code is moved into drivers/.
2759 */
2760static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2761 struct omap_hwmod_rst_info *ohri)
2762{
Tero Kristo37fb59d2014-10-27 08:39:25 -07002763 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0,
2764 oh->prcm.omap2.module_offs, 0, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002765}
2766
2767/**
2768 * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2769 * @oh: struct omap_hwmod * to test hardreset
2770 * @ohri: hardreset line data
2771 *
2772 * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2773 * from the hwmod @oh and the hardreset line data @ohri. Only
2774 * intended for use as an soc_ops function pointer. Passes along the
2775 * return value from omap2_prm_is_hardreset_asserted(). XXX This
2776 * function is scheduled for removal when the PRM code is moved into
2777 * drivers/.
2778 */
2779static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2780 struct omap_hwmod_rst_info *ohri)
2781{
Tero Kristo1bc28b32014-10-27 08:39:25 -07002782 return omap_prm_is_hardreset_asserted(ohri->st_shift, 0,
2783 oh->prcm.omap2.module_offs, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002784}
2785
2786/**
2787 * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2788 * @oh: struct omap_hwmod * to assert hardreset
2789 * @ohri: hardreset line data
2790 *
2791 * Call omap4_prminst_assert_hardreset() with parameters extracted
2792 * from the hwmod @oh and the hardreset line data @ohri. Only
2793 * intended for use as an soc_ops function pointer. Passes along the
2794 * return value from omap4_prminst_assert_hardreset(). XXX This
2795 * function is scheduled for removal when the PRM code is moved into
2796 * drivers/.
2797 */
2798static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2799 struct omap_hwmod_rst_info *ohri)
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002800{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002801 if (!oh->clkdm)
2802 return -EINVAL;
2803
Tero Kristoefd44dc2014-10-27 08:39:24 -07002804 return omap_prm_assert_hardreset(ohri->rst_shift,
2805 oh->clkdm->pwrdm.ptr->prcm_partition,
2806 oh->clkdm->pwrdm.ptr->prcm_offs,
2807 oh->prcm.omap4.rstctrl_offs);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002808}
2809
2810/**
2811 * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2812 * @oh: struct omap_hwmod * to deassert hardreset
2813 * @ohri: hardreset line data
2814 *
2815 * Call omap4_prminst_deassert_hardreset() with parameters extracted
2816 * from the hwmod @oh and the hardreset line data @ohri. Only
2817 * intended for use as an soc_ops function pointer. Passes along the
2818 * return value from omap4_prminst_deassert_hardreset(). XXX This
2819 * function is scheduled for removal when the PRM code is moved into
2820 * drivers/.
2821 */
2822static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2823 struct omap_hwmod_rst_info *ohri)
2824{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002825 if (!oh->clkdm)
2826 return -EINVAL;
2827
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002828 if (ohri->st_shift)
2829 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2830 oh->name, ohri->name);
Tero Kristo4ebf5b22015-05-05 16:33:04 +03002831 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift,
Tero Kristo37fb59d2014-10-27 08:39:25 -07002832 oh->clkdm->pwrdm.ptr->prcm_partition,
2833 oh->clkdm->pwrdm.ptr->prcm_offs,
Tero Kristo4ebf5b22015-05-05 16:33:04 +03002834 oh->prcm.omap4.rstctrl_offs,
2835 oh->prcm.omap4.rstctrl_offs +
2836 OMAP4_RST_CTRL_ST_OFFSET);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002837}
2838
2839/**
2840 * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2841 * @oh: struct omap_hwmod * to test hardreset
2842 * @ohri: hardreset line data
2843 *
2844 * Call omap4_prminst_is_hardreset_asserted() with parameters
2845 * extracted from the hwmod @oh and the hardreset line data @ohri.
2846 * Only intended for use as an soc_ops function pointer. Passes along
2847 * the return value from omap4_prminst_is_hardreset_asserted(). XXX
2848 * This function is scheduled for removal when the PRM code is moved
2849 * into drivers/.
2850 */
2851static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2852 struct omap_hwmod_rst_info *ohri)
2853{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002854 if (!oh->clkdm)
2855 return -EINVAL;
2856
Tero Kristo1bc28b32014-10-27 08:39:25 -07002857 return omap_prm_is_hardreset_asserted(ohri->rst_shift,
2858 oh->clkdm->pwrdm.ptr->
2859 prcm_partition,
2860 oh->clkdm->pwrdm.ptr->prcm_offs,
2861 oh->prcm.omap4.rstctrl_offs);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002862}
2863
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002864/**
Tero Kristo9fabc1a2016-07-04 14:11:48 +03002865 * _omap4_disable_direct_prcm - disable direct PRCM control for hwmod
2866 * @oh: struct omap_hwmod * to disable control for
2867 *
2868 * Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod
2869 * will be using its main_clk to enable/disable the module. Returns
2870 * 0 if successful.
2871 */
2872static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
2873{
2874 if (!oh)
2875 return -EINVAL;
2876
2877 oh->prcm.omap4.clkctrl_offs = 0;
2878 oh->prcm.omap4.modulemode = 0;
2879
2880 return 0;
2881}
2882
2883/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002884 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2885 * @oh: struct omap_hwmod * to deassert hardreset
2886 * @ohri: hardreset line data
2887 *
2888 * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2889 * from the hwmod @oh and the hardreset line data @ohri. Only
2890 * intended for use as an soc_ops function pointer. Passes along the
2891 * return value from am33xx_prminst_deassert_hardreset(). XXX This
2892 * function is scheduled for removal when the PRM code is moved into
2893 * drivers/.
2894 */
2895static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2896 struct omap_hwmod_rst_info *ohri)
2897{
Tero Kristoa5bf00c2015-05-05 16:33:05 +03002898 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift,
2899 oh->clkdm->pwrdm.ptr->prcm_partition,
Tero Kristo37fb59d2014-10-27 08:39:25 -07002900 oh->clkdm->pwrdm.ptr->prcm_offs,
2901 oh->prcm.omap4.rstctrl_offs,
2902 oh->prcm.omap4.rstst_offs);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002903}
2904
Paul Walmsley63c85232009-09-03 20:14:03 +03002905/* Public functions */
2906
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002907u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002908{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002909 if (oh->flags & HWMOD_16BIT_REG)
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002910 return readw_relaxed(oh->_mpu_rt_va + reg_offs);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002911 else
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002912 return readl_relaxed(oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002913}
2914
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002915void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002916{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002917 if (oh->flags & HWMOD_16BIT_REG)
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002918 writew_relaxed(v, oh->_mpu_rt_va + reg_offs);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002919 else
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002920 writel_relaxed(v, oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002921}
2922
Paul Walmsley887adea2010-07-26 16:34:33 -06002923/**
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002924 * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
2925 * @oh: struct omap_hwmod *
2926 *
2927 * This is a public function exposed to drivers. Some drivers may need to do
2928 * some settings before and after resetting the device. Those drivers after
2929 * doing the necessary settings could use this function to start a reset by
2930 * setting the SYSCONFIG.SOFTRESET bit.
2931 */
2932int omap_hwmod_softreset(struct omap_hwmod *oh)
2933{
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06002934 u32 v;
2935 int ret;
2936
2937 if (!oh || !(oh->_sysc_cache))
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002938 return -EINVAL;
2939
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06002940 v = oh->_sysc_cache;
2941 ret = _set_softreset(oh, &v);
2942 if (ret)
2943 goto error;
2944 _write_sysconfig(v, oh);
2945
Roger Quadros313a76e2013-12-08 18:39:02 -07002946 ret = _clear_softreset(oh, &v);
2947 if (ret)
2948 goto error;
2949 _write_sysconfig(v, oh);
2950
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06002951error:
2952 return ret;
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002953}
2954
2955/**
Paul Walmsley63c85232009-09-03 20:14:03 +03002956 * omap_hwmod_lookup - look up a registered omap_hwmod by name
2957 * @name: name of the omap_hwmod to look up
2958 *
2959 * Given a @name of an omap_hwmod, return a pointer to the registered
2960 * struct omap_hwmod *, or NULL upon error.
2961 */
2962struct omap_hwmod *omap_hwmod_lookup(const char *name)
2963{
2964 struct omap_hwmod *oh;
2965
2966 if (!name)
2967 return NULL;
2968
Paul Walmsley63c85232009-09-03 20:14:03 +03002969 oh = _lookup(name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002970
2971 return oh;
2972}
2973
2974/**
2975 * omap_hwmod_for_each - call function for each registered omap_hwmod
2976 * @fn: pointer to a callback function
Paul Walmsley97d60162010-07-26 16:34:30 -06002977 * @data: void * data to pass to callback function
Paul Walmsley63c85232009-09-03 20:14:03 +03002978 *
2979 * Call @fn for each registered omap_hwmod, passing @data to each
2980 * function. @fn must return 0 for success or any other value for
2981 * failure. If @fn returns non-zero, the iteration across omap_hwmods
2982 * will stop and the non-zero return value will be passed to the
2983 * caller of omap_hwmod_for_each(). @fn is called with
2984 * omap_hwmod_for_each() held.
2985 */
Paul Walmsley97d60162010-07-26 16:34:30 -06002986int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
2987 void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03002988{
2989 struct omap_hwmod *temp_oh;
Govindraj.R30ebad92011-06-01 11:28:56 +05302990 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03002991
2992 if (!fn)
2993 return -EINVAL;
2994
Paul Walmsley63c85232009-09-03 20:14:03 +03002995 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
Paul Walmsley97d60162010-07-26 16:34:30 -06002996 ret = (*fn)(temp_oh, data);
Paul Walmsley63c85232009-09-03 20:14:03 +03002997 if (ret)
2998 break;
2999 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003000
3001 return ret;
3002}
3003
Paul Walmsley63c85232009-09-03 20:14:03 +03003004/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003005 * omap_hwmod_register_links - register an array of hwmod links
3006 * @ois: pointer to an array of omap_hwmod_ocp_if to register
3007 *
3008 * Intended to be called early in boot before the clock framework is
3009 * initialized. If @ois is not null, will register all omap_hwmods
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003010 * listed in @ois that are valid for this chip. Returns -EINVAL if
3011 * omap_hwmod_init() hasn't been called before calling this function,
3012 * -ENOMEM if the link memory area can't be allocated, or 0 upon
3013 * success.
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003014 */
3015int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3016{
3017 int r, i;
3018
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003019 if (!inited)
3020 return -EINVAL;
3021
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003022 if (!ois)
3023 return 0;
3024
Rajendra Nayakf7f7a292014-08-27 19:38:23 -06003025 if (ois[0] == NULL) /* Empty list */
3026 return 0;
3027
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003028 i = 0;
3029 do {
3030 r = _register_link(ois[i]);
3031 WARN(r && r != -EEXIST,
3032 "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3033 ois[i]->master->name, ois[i]->slave->name, r);
3034 } while (ois[++i]);
3035
3036 return 0;
3037}
3038
3039/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003040 * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3041 * @oh: pointer to the hwmod currently being set up (usually not the MPU)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003042 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003043 * If the hwmod data corresponding to the MPU subsystem IP block
3044 * hasn't been initialized and set up yet, do so now. This must be
3045 * done first since sleep dependencies may be added from other hwmods
3046 * to the MPU. Intended to be called only by omap_hwmod_setup*(). No
3047 * return value.
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003048 */
Paul Walmsley381d0332012-04-19 00:58:22 -06003049static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003050{
Paul Walmsley381d0332012-04-19 00:58:22 -06003051 if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3052 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3053 __func__, MPU_INITIATOR_NAME);
3054 else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3055 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
Paul Walmsley63c85232009-09-03 20:14:03 +03003056}
3057
3058/**
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003059 * omap_hwmod_setup_one - set up a single hwmod
3060 * @oh_name: const char * name of the already-registered hwmod to set up
3061 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003062 * Initialize and set up a single hwmod. Intended to be used for a
3063 * small number of early devices, such as the timer IP blocks used for
3064 * the scheduler clock. Must be called after omap2_clk_init().
3065 * Resolves the struct clk names to struct clk pointers for each
3066 * registered omap_hwmod. Also calls _setup() on each hwmod. Returns
3067 * -EINVAL upon error or 0 upon success.
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003068 */
3069int __init omap_hwmod_setup_one(const char *oh_name)
3070{
3071 struct omap_hwmod *oh;
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003072
3073 pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3074
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003075 oh = _lookup(oh_name);
3076 if (!oh) {
3077 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3078 return -EINVAL;
3079 }
3080
Paul Walmsley381d0332012-04-19 00:58:22 -06003081 _ensure_mpu_hwmod_is_setup(oh);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003082
Paul Walmsley381d0332012-04-19 00:58:22 -06003083 _init(oh, NULL);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003084 _setup(oh, NULL);
3085
3086 return 0;
3087}
3088
3089/**
Lokesh Vutla8dd66662017-01-20 10:39:10 -08003090 * omap_hwmod_setup_earlycon_flags - set up flags for early console
3091 *
3092 * Enable DEBUG_OMAPUART_FLAGS for uart hwmod that is being used as
3093 * early concole so that hwmod core doesn't reset and keep it in idle
3094 * that specific uart.
3095 */
3096#ifdef CONFIG_SERIAL_EARLYCON
3097static void __init omap_hwmod_setup_earlycon_flags(void)
3098{
3099 struct device_node *np;
3100 struct omap_hwmod *oh;
3101 const char *uart;
3102
3103 np = of_find_node_by_path("/chosen");
3104 if (np) {
3105 uart = of_get_property(np, "stdout-path", NULL);
3106 if (uart) {
3107 np = of_find_node_by_path(uart);
3108 if (np) {
3109 uart = of_get_property(np, "ti,hwmods", NULL);
3110 oh = omap_hwmod_lookup(uart);
3111 if (oh)
3112 oh->flags |= DEBUG_OMAPUART_FLAGS;
3113 }
3114 }
3115 }
3116}
3117#endif
3118
3119/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003120 * omap_hwmod_setup_all - set up all registered IP blocks
Paul Walmsley63c85232009-09-03 20:14:03 +03003121 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003122 * Initialize and set up all IP blocks registered with the hwmod code.
3123 * Must be called after omap2_clk_init(). Resolves the struct clk
3124 * names to struct clk pointers for each registered omap_hwmod. Also
3125 * calls _setup() on each hwmod. Returns 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003126 */
Paul Walmsley550c8092011-02-28 11:58:14 -07003127static int __init omap_hwmod_setup_all(void)
Paul Walmsley63c85232009-09-03 20:14:03 +03003128{
Paul Walmsley381d0332012-04-19 00:58:22 -06003129 _ensure_mpu_hwmod_is_setup(NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003130
Paul Walmsley381d0332012-04-19 00:58:22 -06003131 omap_hwmod_for_each(_init, NULL);
Lokesh Vutla8dd66662017-01-20 10:39:10 -08003132#ifdef CONFIG_SERIAL_EARLYCON
3133 omap_hwmod_setup_earlycon_flags();
3134#endif
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003135 omap_hwmod_for_each(_setup, NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003136
3137 return 0;
3138}
Tony Lindgren8dd5ea72015-12-03 11:38:09 -08003139omap_postcore_initcall(omap_hwmod_setup_all);
Paul Walmsley63c85232009-09-03 20:14:03 +03003140
3141/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003142 * omap_hwmod_enable - enable an omap_hwmod
3143 * @oh: struct omap_hwmod *
3144 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003145 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
Paul Walmsley63c85232009-09-03 20:14:03 +03003146 * Returns -EINVAL on error or passes along the return value from _enable().
3147 */
3148int omap_hwmod_enable(struct omap_hwmod *oh)
3149{
3150 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003151 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003152
3153 if (!oh)
3154 return -EINVAL;
3155
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003156 spin_lock_irqsave(&oh->_lock, flags);
3157 r = _enable(oh);
3158 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003159
3160 return r;
3161}
3162
3163/**
3164 * omap_hwmod_idle - idle an omap_hwmod
3165 * @oh: struct omap_hwmod *
3166 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003167 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
Paul Walmsley63c85232009-09-03 20:14:03 +03003168 * Returns -EINVAL on error or passes along the return value from _idle().
3169 */
3170int omap_hwmod_idle(struct omap_hwmod *oh)
3171{
Pali RohƔr6da23352015-02-26 14:49:51 +01003172 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003173 unsigned long flags;
3174
Paul Walmsley63c85232009-09-03 20:14:03 +03003175 if (!oh)
3176 return -EINVAL;
3177
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003178 spin_lock_irqsave(&oh->_lock, flags);
Pali RohƔr6da23352015-02-26 14:49:51 +01003179 r = _idle(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003180 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003181
Pali RohƔr6da23352015-02-26 14:49:51 +01003182 return r;
Paul Walmsley63c85232009-09-03 20:14:03 +03003183}
3184
3185/**
3186 * omap_hwmod_shutdown - shutdown an omap_hwmod
3187 * @oh: struct omap_hwmod *
3188 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003189 * Shutdown an omap_hwmod @oh. Intended to be called by
Paul Walmsley63c85232009-09-03 20:14:03 +03003190 * omap_device_shutdown(). Returns -EINVAL on error or passes along
3191 * the return value from _shutdown().
3192 */
3193int omap_hwmod_shutdown(struct omap_hwmod *oh)
3194{
Pali RohƔr6da23352015-02-26 14:49:51 +01003195 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003196 unsigned long flags;
3197
Paul Walmsley63c85232009-09-03 20:14:03 +03003198 if (!oh)
3199 return -EINVAL;
3200
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003201 spin_lock_irqsave(&oh->_lock, flags);
Pali RohƔr6da23352015-02-26 14:49:51 +01003202 r = _shutdown(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003203 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003204
Pali RohƔr6da23352015-02-26 14:49:51 +01003205 return r;
Paul Walmsley63c85232009-09-03 20:14:03 +03003206}
3207
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003208/*
3209 * IP block data retrieval functions
3210 */
3211
Paul Walmsley63c85232009-09-03 20:14:03 +03003212/**
3213 * omap_hwmod_count_resources - count number of struct resources needed by hwmod
3214 * @oh: struct omap_hwmod *
Peter Ujfalusidad41912012-11-21 16:15:17 -07003215 * @flags: Type of resources to include when counting (IRQ/DMA/MEM)
Paul Walmsley63c85232009-09-03 20:14:03 +03003216 *
3217 * Count the number of struct resource array elements necessary to
3218 * contain omap_hwmod @oh resources. Intended to be called by code
3219 * that registers omap_devices. Intended to be used to determine the
3220 * size of a dynamically-allocated struct resource array, before
3221 * calling omap_hwmod_fill_resources(). Returns the number of struct
3222 * resource array elements needed.
3223 *
3224 * XXX This code is not optimized. It could attempt to merge adjacent
3225 * resource IDs.
3226 *
3227 */
Peter Ujfalusidad41912012-11-21 16:15:17 -07003228int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags)
Paul Walmsley63c85232009-09-03 20:14:03 +03003229{
Peter Ujfalusidad41912012-11-21 16:15:17 -07003230 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003231
Peter Ujfalusidad41912012-11-21 16:15:17 -07003232 if (flags & IORESOURCE_IRQ)
3233 ret += _count_mpu_irqs(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03003234
Peter Ujfalusidad41912012-11-21 16:15:17 -07003235 if (flags & IORESOURCE_DMA)
3236 ret += _count_sdma_reqs(oh);
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003237
Peter Ujfalusidad41912012-11-21 16:15:17 -07003238 if (flags & IORESOURCE_MEM) {
Peter Ujfalusidad41912012-11-21 16:15:17 -07003239 struct omap_hwmod_ocp_if *os;
Peter Ujfalusidad41912012-11-21 16:15:17 -07003240
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07003241 list_for_each_entry(os, &oh->slave_ports, node)
Peter Ujfalusidad41912012-11-21 16:15:17 -07003242 ret += _count_ocp_if_addr_spaces(os);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003243 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003244
3245 return ret;
3246}
3247
3248/**
3249 * omap_hwmod_fill_resources - fill struct resource array with hwmod data
3250 * @oh: struct omap_hwmod *
3251 * @res: pointer to the first element of an array of struct resource to fill
3252 *
3253 * Fill the struct resource array @res with resource data from the
3254 * omap_hwmod @oh. Intended to be called by code that registers
3255 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3256 * number of array elements filled.
3257 */
3258int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res)
3259{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06003260 struct omap_hwmod_ocp_if *os;
3261 int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt;
Paul Walmsley63c85232009-09-03 20:14:03 +03003262 int r = 0;
3263
3264 /* For each IRQ, DMA, memory area, fill in array.*/
3265
Paul Walmsley212738a2011-07-09 19:14:06 -06003266 mpu_irqs_cnt = _count_mpu_irqs(oh);
3267 for (i = 0; i < mpu_irqs_cnt; i++) {
Marc Zyngier0fb22a82015-01-17 10:21:08 +00003268 unsigned int irq;
3269
3270 if (oh->xlate_irq)
3271 irq = oh->xlate_irq((oh->mpu_irqs + i)->irq);
3272 else
3273 irq = (oh->mpu_irqs + i)->irq;
Paul Walmsley718bfd72009-12-08 16:34:16 -07003274 (res + r)->name = (oh->mpu_irqs + i)->name;
Marc Zyngier0fb22a82015-01-17 10:21:08 +00003275 (res + r)->start = irq;
3276 (res + r)->end = irq;
Paul Walmsley63c85232009-09-03 20:14:03 +03003277 (res + r)->flags = IORESOURCE_IRQ;
3278 r++;
3279 }
3280
Paul Walmsleybc614952011-07-09 19:14:07 -06003281 sdma_reqs_cnt = _count_sdma_reqs(oh);
3282 for (i = 0; i < sdma_reqs_cnt; i++) {
Benoit Cousson9ee9fff2010-09-21 10:34:08 -06003283 (res + r)->name = (oh->sdma_reqs + i)->name;
3284 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3285 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
Paul Walmsley63c85232009-09-03 20:14:03 +03003286 (res + r)->flags = IORESOURCE_DMA;
3287 r++;
3288 }
3289
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07003290 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley78183f32011-07-09 19:14:05 -06003291 addr_cnt = _count_ocp_if_addr_spaces(os);
Paul Walmsley63c85232009-09-03 20:14:03 +03003292
Paul Walmsley78183f32011-07-09 19:14:05 -06003293 for (j = 0; j < addr_cnt; j++) {
Kishon Vijay Abraham Icd503802011-02-24 12:51:45 -08003294 (res + r)->name = (os->addr + j)->name;
Paul Walmsley63c85232009-09-03 20:14:03 +03003295 (res + r)->start = (os->addr + j)->pa_start;
3296 (res + r)->end = (os->addr + j)->pa_end;
3297 (res + r)->flags = IORESOURCE_MEM;
3298 r++;
3299 }
3300 }
3301
3302 return r;
3303}
3304
3305/**
Vaibhav Hiremathb82b04e2012-08-29 15:18:11 +05303306 * omap_hwmod_fill_dma_resources - fill struct resource array with dma data
3307 * @oh: struct omap_hwmod *
3308 * @res: pointer to the array of struct resource to fill
3309 *
3310 * Fill the struct resource array @res with dma resource data from the
3311 * omap_hwmod @oh. Intended to be called by code that registers
3312 * omap_devices. See also omap_hwmod_count_resources(). Returns the
3313 * number of array elements filled.
3314 */
3315int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res)
3316{
3317 int i, sdma_reqs_cnt;
3318 int r = 0;
3319
3320 sdma_reqs_cnt = _count_sdma_reqs(oh);
3321 for (i = 0; i < sdma_reqs_cnt; i++) {
3322 (res + r)->name = (oh->sdma_reqs + i)->name;
3323 (res + r)->start = (oh->sdma_reqs + i)->dma_req;
3324 (res + r)->end = (oh->sdma_reqs + i)->dma_req;
3325 (res + r)->flags = IORESOURCE_DMA;
3326 r++;
3327 }
3328
3329 return r;
3330}
3331
3332/**
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003333 * omap_hwmod_get_resource_byname - fetch IP block integration data by name
3334 * @oh: struct omap_hwmod * to operate on
3335 * @type: one of the IORESOURCE_* constants from include/linux/ioport.h
3336 * @name: pointer to the name of the data to fetch (optional)
3337 * @rsrc: pointer to a struct resource, allocated by the caller
3338 *
3339 * Retrieve MPU IRQ, SDMA request line, or address space start/end
3340 * data for the IP block pointed to by @oh. The data will be filled
3341 * into a struct resource record pointed to by @rsrc. The struct
3342 * resource must be allocated by the caller. When @name is non-null,
3343 * the data associated with the matching entry in the IRQ/SDMA/address
3344 * space hwmod data arrays will be returned. If @name is null, the
3345 * first array entry will be returned. Data order is not meaningful
3346 * in hwmod data, so callers are strongly encouraged to use a non-null
3347 * @name whenever possible to avoid unpredictable effects if hwmod
3348 * data is later added that causes data ordering to change. This
3349 * function is only intended for use by OMAP core code. Device
3350 * drivers should not call this function - the appropriate bus-related
3351 * data accessor functions should be used instead. Returns 0 upon
3352 * success or a negative error code upon error.
3353 */
3354int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type,
3355 const char *name, struct resource *rsrc)
3356{
3357 int r;
3358 unsigned int irq, dma;
3359 u32 pa_start, pa_end;
3360
3361 if (!oh || !rsrc)
3362 return -EINVAL;
3363
3364 if (type == IORESOURCE_IRQ) {
3365 r = _get_mpu_irq_by_name(oh, name, &irq);
3366 if (r)
3367 return r;
3368
3369 rsrc->start = irq;
3370 rsrc->end = irq;
3371 } else if (type == IORESOURCE_DMA) {
3372 r = _get_sdma_req_by_name(oh, name, &dma);
3373 if (r)
3374 return r;
3375
3376 rsrc->start = dma;
3377 rsrc->end = dma;
3378 } else if (type == IORESOURCE_MEM) {
3379 r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end);
3380 if (r)
3381 return r;
3382
3383 rsrc->start = pa_start;
3384 rsrc->end = pa_end;
3385 } else {
3386 return -EINVAL;
3387 }
3388
3389 rsrc->flags = type;
3390 rsrc->name = name;
3391
3392 return 0;
3393}
3394
3395/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003396 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3397 * @oh: struct omap_hwmod *
3398 *
3399 * Return the powerdomain pointer associated with the OMAP module
3400 * @oh's main clock. If @oh does not have a main clk, return the
3401 * powerdomain associated with the interface clock associated with the
3402 * module's MPU port. (XXX Perhaps this should use the SDMA port
3403 * instead?) Returns NULL on error, or a struct powerdomain * on
3404 * success.
3405 */
3406struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3407{
3408 struct clk *c;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003409 struct omap_hwmod_ocp_if *oi;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003410 struct clockdomain *clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003411 struct clk_hw_omap *clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003412
3413 if (!oh)
3414 return NULL;
3415
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003416 if (oh->clkdm)
3417 return oh->clkdm->pwrdm.ptr;
3418
Paul Walmsley63c85232009-09-03 20:14:03 +03003419 if (oh->_clk) {
3420 c = oh->_clk;
3421 } else {
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003422 oi = _find_mpu_rt_port(oh);
3423 if (!oi)
Paul Walmsley63c85232009-09-03 20:14:03 +03003424 return NULL;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003425 c = oi->_clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003426 }
3427
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003428 clk = to_clk_hw_omap(__clk_get_hw(c));
3429 clkdm = clk->clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003430 if (!clkdm)
Thara Gopinathd5647c12010-03-31 04:16:29 -06003431 return NULL;
3432
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003433 return clkdm->pwrdm.ptr;
Paul Walmsley63c85232009-09-03 20:14:03 +03003434}
3435
3436/**
Paul Walmsleydb2a60b2010-07-26 16:34:33 -06003437 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3438 * @oh: struct omap_hwmod *
3439 *
3440 * Returns the virtual address corresponding to the beginning of the
3441 * module's register target, in the address range that is intended to
3442 * be used by the MPU. Returns the virtual address upon success or NULL
3443 * upon error.
3444 */
3445void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3446{
3447 if (!oh)
3448 return NULL;
3449
3450 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3451 return NULL;
3452
3453 if (oh->_state == _HWMOD_STATE_UNKNOWN)
3454 return NULL;
3455
3456 return oh->_mpu_rt_va;
3457}
3458
Paul Walmsley63c85232009-09-03 20:14:03 +03003459/*
3460 * XXX what about functions for drivers to save/restore ocp_sysconfig
3461 * for context save/restore operations?
3462 */
3463
3464/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003465 * omap_hwmod_enable_wakeup - allow device to wake up the system
3466 * @oh: struct omap_hwmod *
3467 *
3468 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
Govindraj.R2a1cc142012-04-05 02:59:32 -06003469 * send wakeups to the PRCM, and enable I/O ring wakeup events for
3470 * this IP block if it has dynamic mux entries. Eventually this
3471 * should set PRCM wakeup registers to cause the PRCM to receive
3472 * wakeup events from the module. Does not set any wakeup routing
3473 * registers beyond this point - if the module is to wake up any other
3474 * module or subsystem, that must be set separately. Called by
3475 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003476 */
3477int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3478{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003479 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003480 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003481
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003482 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003483
3484 if (oh->class->sysc &&
3485 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3486 v = oh->_sysc_cache;
3487 _enable_wakeup(oh, &v);
3488 _write_sysconfig(v, oh);
3489 }
3490
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003491 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003492
3493 return 0;
3494}
3495
3496/**
3497 * omap_hwmod_disable_wakeup - prevent device from waking the system
3498 * @oh: struct omap_hwmod *
3499 *
3500 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
Govindraj.R2a1cc142012-04-05 02:59:32 -06003501 * from sending wakeups to the PRCM, and disable I/O ring wakeup
3502 * events for this IP block if it has dynamic mux entries. Eventually
3503 * this should clear PRCM wakeup registers to cause the PRCM to ignore
3504 * wakeup events from the module. Does not set any wakeup routing
3505 * registers beyond this point - if the module is to wake up any other
3506 * module or subsystem, that must be set separately. Called by
3507 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003508 */
3509int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3510{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003511 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003512 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003513
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003514 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003515
3516 if (oh->class->sysc &&
3517 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3518 v = oh->_sysc_cache;
3519 _disable_wakeup(oh, &v);
3520 _write_sysconfig(v, oh);
3521 }
3522
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003523 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003524
3525 return 0;
3526}
Paul Walmsley43b40992010-02-22 22:09:34 -07003527
3528/**
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003529 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3530 * contained in the hwmod module.
3531 * @oh: struct omap_hwmod *
3532 * @name: name of the reset line to lookup and assert
3533 *
3534 * Some IP like dsp, ipu or iva contain processor that require
3535 * an HW reset line to be assert / deassert in order to enable fully
3536 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3537 * yet supported on this OMAP; otherwise, passes along the return value
3538 * from _assert_hardreset().
3539 */
3540int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3541{
3542 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003543 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003544
3545 if (!oh)
3546 return -EINVAL;
3547
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003548 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003549 ret = _assert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003550 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003551
3552 return ret;
3553}
3554
3555/**
3556 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3557 * contained in the hwmod module.
3558 * @oh: struct omap_hwmod *
3559 * @name: name of the reset line to look up and deassert
3560 *
3561 * Some IP like dsp, ipu or iva contain processor that require
3562 * an HW reset line to be assert / deassert in order to enable fully
3563 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3564 * yet supported on this OMAP; otherwise, passes along the return value
3565 * from _deassert_hardreset().
3566 */
3567int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3568{
3569 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003570 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003571
3572 if (!oh)
3573 return -EINVAL;
3574
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003575 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003576 ret = _deassert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003577 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003578
3579 return ret;
3580}
3581
3582/**
Paul Walmsley43b40992010-02-22 22:09:34 -07003583 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3584 * @classname: struct omap_hwmod_class name to search for
3585 * @fn: callback function pointer to call for each hwmod in class @classname
3586 * @user: arbitrary context data to pass to the callback function
3587 *
Benoit Coussonce35b242010-12-21 21:31:28 -07003588 * For each omap_hwmod of class @classname, call @fn.
3589 * If the callback function returns something other than
Paul Walmsley43b40992010-02-22 22:09:34 -07003590 * zero, the iterator is terminated, and the callback function's return
3591 * value is passed back to the caller. Returns 0 upon success, -EINVAL
3592 * if @classname or @fn are NULL, or passes back the error code from @fn.
3593 */
3594int omap_hwmod_for_each_by_class(const char *classname,
3595 int (*fn)(struct omap_hwmod *oh,
3596 void *user),
3597 void *user)
3598{
3599 struct omap_hwmod *temp_oh;
3600 int ret = 0;
3601
3602 if (!classname || !fn)
3603 return -EINVAL;
3604
3605 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3606 __func__, classname);
3607
Paul Walmsley43b40992010-02-22 22:09:34 -07003608 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3609 if (!strcmp(temp_oh->class->name, classname)) {
3610 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3611 __func__, temp_oh->name);
3612 ret = (*fn)(temp_oh, user);
3613 if (ret)
3614 break;
3615 }
3616 }
3617
Paul Walmsley43b40992010-02-22 22:09:34 -07003618 if (ret)
3619 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3620 __func__, ret);
3621
3622 return ret;
3623}
3624
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003625/**
3626 * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3627 * @oh: struct omap_hwmod *
3628 * @state: state that _setup() should leave the hwmod in
3629 *
Paul Walmsley550c8092011-02-28 11:58:14 -07003630 * Sets the hwmod state that @oh will enter at the end of _setup()
Paul Walmsley64813c32012-04-18 19:10:03 -06003631 * (called by omap_hwmod_setup_*()). See also the documentation
3632 * for _setup_postsetup(), above. Returns 0 upon success or
3633 * -EINVAL if there is a problem with the arguments or if the hwmod is
3634 * in the wrong state.
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003635 */
3636int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3637{
3638 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003639 unsigned long flags;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003640
3641 if (!oh)
3642 return -EINVAL;
3643
3644 if (state != _HWMOD_STATE_DISABLED &&
3645 state != _HWMOD_STATE_ENABLED &&
3646 state != _HWMOD_STATE_IDLE)
3647 return -EINVAL;
3648
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003649 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003650
3651 if (oh->_state != _HWMOD_STATE_REGISTERED) {
3652 ret = -EINVAL;
3653 goto ohsps_unlock;
3654 }
3655
3656 oh->_postsetup_state = state;
3657 ret = 0;
3658
3659ohsps_unlock:
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003660 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003661
3662 return ret;
3663}
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003664
3665/**
3666 * omap_hwmod_get_context_loss_count - get lost context count
3667 * @oh: struct omap_hwmod *
3668 *
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07003669 * Returns the context loss count of associated @oh
3670 * upon success, or zero if no context loss data is available.
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003671 *
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07003672 * On OMAP4, this queries the per-hwmod context loss register,
3673 * assuming one exists. If not, or on OMAP2/3, this queries the
3674 * enclosing powerdomain context loss count.
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003675 */
Tomi Valkeinenfc013872011-06-09 16:56:23 +03003676int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003677{
3678 struct powerdomain *pwrdm;
3679 int ret = 0;
3680
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07003681 if (soc_ops.get_context_lost)
3682 return soc_ops.get_context_lost(oh);
3683
Kevin Hilmanc80705a2010-12-21 21:31:55 -07003684 pwrdm = omap_hwmod_get_pwrdm(oh);
3685 if (pwrdm)
3686 ret = pwrdm_get_context_loss_count(pwrdm);
3687
3688 return ret;
3689}
Paul Walmsley43b01642011-03-10 03:50:07 -07003690
3691/**
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003692 * omap_hwmod_init - initialize the hwmod code
3693 *
3694 * Sets up some function pointers needed by the hwmod code to operate on the
3695 * currently-booted SoC. Intended to be called once during kernel init
3696 * before any hwmods are registered. No return value.
3697 */
3698void __init omap_hwmod_init(void)
3699{
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06003700 if (cpu_is_omap24xx()) {
Tero Kristo9002e9212014-10-27 08:39:23 -07003701 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06003702 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3703 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3704 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
3705 } else if (cpu_is_omap34xx()) {
Tero Kristo9002e9212014-10-27 08:39:23 -07003706 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06003707 soc_ops.assert_hardreset = _omap2_assert_hardreset;
3708 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
3709 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
Tero Kristo0385c582013-07-17 18:03:25 +03003710 soc_ops.init_clkdm = _init_clkdm;
Rajendra Nayakdebcd1f2013-07-02 18:20:08 +05303711 } else if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx()) {
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003712 soc_ops.enable_module = _omap4_enable_module;
3713 soc_ops.disable_module = _omap4_disable_module;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06003714 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06003715 soc_ops.assert_hardreset = _omap4_assert_hardreset;
3716 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
3717 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Kevin Hilman0a179ea2012-06-18 12:12:25 -06003718 soc_ops.init_clkdm = _init_clkdm;
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07003719 soc_ops.update_context_lost = _omap4_update_context_lost;
3720 soc_ops.get_context_lost = _omap4_get_context_lost;
Tero Kristo9fabc1a2016-07-04 14:11:48 +03003721 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
Tony Lindgren0f3ccb22015-07-16 01:55:58 -07003722 } else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() ||
3723 soc_is_am43xx()) {
Afzal Mohammedc8b428a2013-10-12 15:46:20 +05303724 soc_ops.enable_module = _omap4_enable_module;
3725 soc_ops.disable_module = _omap4_disable_module;
3726 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Tero Kristo409d7062014-10-27 08:39:24 -07003727 soc_ops.assert_hardreset = _omap4_assert_hardreset;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06003728 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
Tero Kristoa5bf00c2015-05-05 16:33:05 +03003729 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06003730 soc_ops.init_clkdm = _init_clkdm;
Tero Kristo9fabc1a2016-07-04 14:11:48 +03003731 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06003732 } else {
3733 WARN(1, "omap_hwmod: unknown SoC type\n");
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003734 }
3735
3736 inited = true;
3737}
Tony Lindgren68c9a952012-07-06 00:58:43 -07003738
3739/**
3740 * omap_hwmod_get_main_clk - get pointer to main clock name
3741 * @oh: struct omap_hwmod *
3742 *
3743 * Returns the main clock name assocated with @oh upon success,
3744 * or NULL if @oh is NULL.
3745 */
3746const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
3747{
3748 if (!oh)
3749 return NULL;
3750
3751 return oh->main_clk;
3752}