blob: ed3d503167f49ab3752d59cafbc0f2681efa62fa [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>
Mike Rapoport57c8a662018-10-30 15:09:49 -0700144#include <linux/memblock.h>
Paul Walmsley63c85232009-09-03 20:14:03 +0300145
Tony Lindgren49a0a3d2017-12-15 09:41:05 -0800146#include <linux/platform_data/ti-sysc.h>
147
Tony Lindgren8c879702018-02-22 14:04:56 -0800148#include <dt-bindings/bus/ti-sysc.h>
149
Paul Walmsleyfa200222013-01-26 00:48:56 -0700150#include <asm/system_misc.h>
151
Paul Walmsleya135eaa2012-09-27 10:33:34 -0600152#include "clock.h"
Tony Lindgren2a296c82012-10-02 17:41:35 -0700153#include "omap_hwmod.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300154
Tony Lindgrendbc04162012-08-31 10:59:07 -0700155#include "soc.h"
156#include "common.h"
157#include "clockdomain.h"
158#include "powerdomain.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -0600159#include "cm2xxx.h"
160#include "cm3xxx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600161#include "cm33xx.h"
Paul Walmsleyb13159a2012-10-29 20:57:44 -0600162#include "prm.h"
Paul Walmsley139563a2012-10-21 01:01:10 -0600163#include "prm3xxx.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -0700164#include "prm44xx.h"
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -0600165#include "prm33xx.h"
Benoit Coussoneaac3292011-07-10 05:56:31 -0600166#include "prminst44xx.h"
Vishwanath BS51658822012-06-22 08:40:04 -0600167#include "pm.h"
Paul Walmsley63c85232009-09-03 20:14:03 +0300168
Paul Walmsley63c85232009-09-03 20:14:03 +0300169/* Name of the OMAP hwmod for the MPU */
Benoit Cousson5c2c0292010-05-20 12:31:10 -0600170#define MPU_INITIATOR_NAME "mpu"
Paul Walmsley63c85232009-09-03 20:14:03 +0300171
Paul Walmsley2221b5c2012-04-19 04:04:30 -0600172/*
173 * Number of struct omap_hwmod_link records per struct
174 * omap_hwmod_ocp_if record (master->slave and slave->master)
175 */
176#define LINKS_PER_OCP_IF 2
177
Tero Kristo4ebf5b22015-05-05 16:33:04 +0300178/*
179 * Address offset (in bytes) between the reset control and the reset
180 * status registers: 4 bytes on OMAP4
181 */
182#define OMAP4_RST_CTRL_ST_OFFSET 4
183
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300184/*
185 * Maximum length for module clock handle names
186 */
187#define MOD_CLK_MAX_NAME_LEN 32
188
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600189/**
Tero Kristo70f05be2017-05-31 18:00:03 +0300190 * struct clkctrl_provider - clkctrl provider mapping data
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300191 * @num_addrs: number of base address ranges for the provider
192 * @addr: base address(es) for the provider
193 * @size: size(s) of the provider address space(s)
Tero Kristo70f05be2017-05-31 18:00:03 +0300194 * @node: device node associated with the provider
195 * @link: list link
196 */
197struct clkctrl_provider {
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300198 int num_addrs;
199 u32 *addr;
200 u32 *size;
Tero Kristo70f05be2017-05-31 18:00:03 +0300201 struct device_node *node;
202 struct list_head link;
203};
204
205static LIST_HEAD(clkctrl_providers);
206
207/**
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600208 * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
209 * @enable_module: function to enable a module (via MODULEMODE)
210 * @disable_module: function to disable a module (via MODULEMODE)
211 *
212 * XXX Eventually this functionality will be hidden inside the PRM/CM
213 * device drivers. Until then, this should avoid huge blocks of cpu_is_*()
214 * conditionals in this code.
215 */
216struct omap_hwmod_soc_ops {
217 void (*enable_module)(struct omap_hwmod *oh);
218 int (*disable_module)(struct omap_hwmod *oh);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -0600219 int (*wait_target_ready)(struct omap_hwmod *oh);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -0600220 int (*assert_hardreset)(struct omap_hwmod *oh,
221 struct omap_hwmod_rst_info *ohri);
222 int (*deassert_hardreset)(struct omap_hwmod *oh,
223 struct omap_hwmod_rst_info *ohri);
224 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
225 struct omap_hwmod_rst_info *ohri);
Kevin Hilman0a179ea2012-06-18 12:12:25 -0600226 int (*init_clkdm)(struct omap_hwmod *oh);
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -0700227 void (*update_context_lost)(struct omap_hwmod *oh);
228 int (*get_context_lost)(struct omap_hwmod *oh);
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300229 int (*disable_direct_prcm)(struct omap_hwmod *oh);
Tero Kristo6e83eca2017-08-04 17:41:50 +0300230 u32 (*xlate_clkctrl)(struct omap_hwmod *oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600231};
232
233/* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
234static struct omap_hwmod_soc_ops soc_ops;
235
Paul Walmsley63c85232009-09-03 20:14:03 +0300236/* omap_hwmod_list contains all registered struct omap_hwmods */
237static LIST_HEAD(omap_hwmod_list);
Tony Lindgrenb57250f2019-03-21 11:00:21 -0700238static DEFINE_MUTEX(list_lock);
Paul Walmsley63c85232009-09-03 20:14:03 +0300239
Paul Walmsley63c85232009-09-03 20:14:03 +0300240/* mpu_oh: used to add/remove MPU initiator from sleepdep list */
241static struct omap_hwmod *mpu_oh;
242
Kevin Hilman9ebfd282012-06-18 12:12:23 -0600243/* inited: set to true once the hwmod code is initialized */
244static bool inited;
245
Paul Walmsley63c85232009-09-03 20:14:03 +0300246/* Private functions */
247
248/**
249 * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy
250 * @oh: struct omap_hwmod *
251 *
252 * Load the current value of the hwmod OCP_SYSCONFIG register into the
253 * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no
254 * OCP_SYSCONFIG register or 0 upon success.
255 */
256static int _update_sysc_cache(struct omap_hwmod *oh)
257{
Paul Walmsley43b40992010-02-22 22:09:34 -0700258 if (!oh->class->sysc) {
259 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 +0300260 return -EINVAL;
261 }
262
263 /* XXX ensure module interface clock is up */
264
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -0700265 oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +0300266
Paul Walmsley43b40992010-02-22 22:09:34 -0700267 if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE))
Thara Gopinath883edfd2010-01-19 17:30:51 -0700268 oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED;
Paul Walmsley63c85232009-09-03 20:14:03 +0300269
270 return 0;
271}
272
273/**
274 * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register
275 * @v: OCP_SYSCONFIG value to write
276 * @oh: struct omap_hwmod *
277 *
Paul Walmsley43b40992010-02-22 22:09:34 -0700278 * Write @v into the module class' OCP_SYSCONFIG register, if it has
279 * one. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +0300280 */
281static void _write_sysconfig(u32 v, struct omap_hwmod *oh)
282{
Paul Walmsley43b40992010-02-22 22:09:34 -0700283 if (!oh->class->sysc) {
284 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 +0300285 return;
286 }
287
288 /* XXX ensure module interface clock is up */
289
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700290 /* Module might have lost context, always update cache and register */
291 oh->_sysc_cache = v;
Lokesh Vutlaaaf2c0f2015-06-10 14:56:24 +0530292
293 /*
294 * Some IP blocks (such as RTC) require unlocking of IP before
295 * accessing its registers. If a function pointer is present
296 * to unlock, then call it before accessing sysconfig and
297 * call lock after writing sysconfig.
298 */
299 if (oh->class->unlock)
300 oh->class->unlock(oh);
301
Rajendra Nayak233cbe52010-12-14 12:42:36 -0700302 omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs);
Lokesh Vutlaaaf2c0f2015-06-10 14:56:24 +0530303
304 if (oh->class->lock)
305 oh->class->lock(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +0300306}
307
308/**
309 * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v
310 * @oh: struct omap_hwmod *
311 * @standbymode: MIDLEMODE field bits
312 * @v: pointer to register contents to modify
313 *
314 * Update the master standby mode bits in @v to be @standbymode for
315 * the @oh hwmod. Does not write to the hardware. Returns -EINVAL
316 * upon error or 0 upon success.
317 */
318static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode,
319 u32 *v)
320{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700321 u32 mstandby_mask;
322 u8 mstandby_shift;
323
Paul Walmsley43b40992010-02-22 22:09:34 -0700324 if (!oh->class->sysc ||
325 !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300326 return -EINVAL;
327
Paul Walmsley43b40992010-02-22 22:09:34 -0700328 if (!oh->class->sysc->sysc_fields) {
329 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700330 return -EINVAL;
331 }
332
Paul Walmsley43b40992010-02-22 22:09:34 -0700333 mstandby_shift = oh->class->sysc->sysc_fields->midle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700334 mstandby_mask = (0x3 << mstandby_shift);
335
336 *v &= ~mstandby_mask;
337 *v |= __ffs(standbymode) << mstandby_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300338
339 return 0;
340}
341
342/**
343 * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v
344 * @oh: struct omap_hwmod *
345 * @idlemode: SIDLEMODE field bits
346 * @v: pointer to register contents to modify
347 *
348 * Update the slave idle mode bits in @v to be @idlemode for the @oh
349 * hwmod. Does not write to the hardware. Returns -EINVAL upon error
350 * or 0 upon success.
351 */
352static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v)
353{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700354 u32 sidle_mask;
355 u8 sidle_shift;
356
Paul Walmsley43b40992010-02-22 22:09:34 -0700357 if (!oh->class->sysc ||
358 !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE))
Paul Walmsley63c85232009-09-03 20:14:03 +0300359 return -EINVAL;
360
Paul Walmsley43b40992010-02-22 22:09:34 -0700361 if (!oh->class->sysc->sysc_fields) {
362 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700363 return -EINVAL;
364 }
365
Paul Walmsley43b40992010-02-22 22:09:34 -0700366 sidle_shift = oh->class->sysc->sysc_fields->sidle_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700367 sidle_mask = (0x3 << sidle_shift);
368
369 *v &= ~sidle_mask;
370 *v |= __ffs(idlemode) << sidle_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300371
372 return 0;
373}
374
375/**
376 * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v
377 * @oh: struct omap_hwmod *
378 * @clockact: CLOCKACTIVITY field bits
379 * @v: pointer to register contents to modify
380 *
381 * Update the clockactivity mode bits in @v to be @clockact for the
382 * @oh hwmod. Used for additional powersaving on some modules. Does
383 * not write to the hardware. Returns -EINVAL upon error or 0 upon
384 * success.
385 */
386static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v)
387{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700388 u32 clkact_mask;
389 u8 clkact_shift;
390
Paul Walmsley43b40992010-02-22 22:09:34 -0700391 if (!oh->class->sysc ||
392 !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY))
Paul Walmsley63c85232009-09-03 20:14:03 +0300393 return -EINVAL;
394
Paul Walmsley43b40992010-02-22 22:09:34 -0700395 if (!oh->class->sysc->sysc_fields) {
396 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700397 return -EINVAL;
398 }
399
Paul Walmsley43b40992010-02-22 22:09:34 -0700400 clkact_shift = oh->class->sysc->sysc_fields->clkact_shift;
Thara Gopinath358f0e62010-02-24 12:05:58 -0700401 clkact_mask = (0x3 << clkact_shift);
402
403 *v &= ~clkact_mask;
404 *v |= clockact << clkact_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300405
406 return 0;
407}
408
409/**
Roger Quadros313a76e2013-12-08 18:39:02 -0700410 * _set_softreset: set OCP_SYSCONFIG.SOFTRESET bit in @v
Paul Walmsley63c85232009-09-03 20:14:03 +0300411 * @oh: struct omap_hwmod *
412 * @v: pointer to register contents to modify
413 *
414 * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
415 * error or 0 upon success.
416 */
417static int _set_softreset(struct omap_hwmod *oh, u32 *v)
418{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700419 u32 softrst_mask;
420
Paul Walmsley43b40992010-02-22 22:09:34 -0700421 if (!oh->class->sysc ||
422 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley63c85232009-09-03 20:14:03 +0300423 return -EINVAL;
424
Paul Walmsley43b40992010-02-22 22:09:34 -0700425 if (!oh->class->sysc->sysc_fields) {
426 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700427 return -EINVAL;
428 }
429
Paul Walmsley43b40992010-02-22 22:09:34 -0700430 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700431
432 *v |= softrst_mask;
Paul Walmsley63c85232009-09-03 20:14:03 +0300433
434 return 0;
435}
436
437/**
Roger Quadros313a76e2013-12-08 18:39:02 -0700438 * _clear_softreset: clear OCP_SYSCONFIG.SOFTRESET bit in @v
439 * @oh: struct omap_hwmod *
440 * @v: pointer to register contents to modify
441 *
442 * Clear the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon
443 * error or 0 upon success.
444 */
445static int _clear_softreset(struct omap_hwmod *oh, u32 *v)
446{
447 u32 softrst_mask;
448
449 if (!oh->class->sysc ||
450 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
451 return -EINVAL;
452
453 if (!oh->class->sysc->sysc_fields) {
454 WARN(1,
455 "omap_hwmod: %s: sysc_fields absent for sysconfig class\n",
456 oh->name);
457 return -EINVAL;
458 }
459
460 softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift);
461
462 *v &= ~softrst_mask;
463
464 return 0;
465}
466
467/**
Tero Kristo613ad0e2012-10-29 22:02:13 -0600468 * _wait_softreset_complete - wait for an OCP softreset to complete
469 * @oh: struct omap_hwmod * to wait on
470 *
471 * Wait until the IP block represented by @oh reports that its OCP
472 * softreset is complete. This can be triggered by software (see
473 * _ocp_softreset()) or by hardware upon returning from off-mode (one
474 * example is HSMMC). Waits for up to MAX_MODULE_SOFTRESET_WAIT
475 * microseconds. Returns the number of microseconds waited.
476 */
477static int _wait_softreset_complete(struct omap_hwmod *oh)
478{
479 struct omap_hwmod_class_sysconfig *sysc;
480 u32 softrst_mask;
481 int c = 0;
482
483 sysc = oh->class->sysc;
484
Tony Lindgren103fd8e2018-04-16 10:21:15 -0700485 if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS && sysc->syss_offs > 0)
Tero Kristo613ad0e2012-10-29 22:02:13 -0600486 omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs)
487 & SYSS_RESETDONE_MASK),
488 MAX_MODULE_SOFTRESET_WAIT, c);
489 else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) {
490 softrst_mask = (0x1 << sysc->sysc_fields->srst_shift);
491 omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs)
492 & softrst_mask),
493 MAX_MODULE_SOFTRESET_WAIT, c);
494 }
495
496 return c;
497}
498
499/**
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -0600500 * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v
501 * @oh: struct omap_hwmod *
502 *
503 * The DMADISABLE bit is a semi-automatic bit present in sysconfig register
504 * of some modules. When the DMA must perform read/write accesses, the
505 * DMADISABLE bit is cleared by the hardware. But when the DMA must stop
506 * for power management, software must set the DMADISABLE bit back to 1.
507 *
508 * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon
509 * error or 0 upon success.
510 */
511static int _set_dmadisable(struct omap_hwmod *oh)
512{
513 u32 v;
514 u32 dmadisable_mask;
515
516 if (!oh->class->sysc ||
517 !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE))
518 return -EINVAL;
519
520 if (!oh->class->sysc->sysc_fields) {
521 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
522 return -EINVAL;
523 }
524
525 /* clocks must be on for this operation */
526 if (oh->_state != _HWMOD_STATE_ENABLED) {
527 pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name);
528 return -EINVAL;
529 }
530
531 pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name);
532
533 v = oh->_sysc_cache;
534 dmadisable_mask =
535 (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift);
536 v |= dmadisable_mask;
537 _write_sysconfig(v, oh);
538
539 return 0;
540}
541
542/**
Paul Walmsley726072e2009-12-08 16:34:15 -0700543 * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v
544 * @oh: struct omap_hwmod *
545 * @autoidle: desired AUTOIDLE bitfield value (0 or 1)
546 * @v: pointer to register contents to modify
547 *
548 * Update the module autoidle bit in @v to be @autoidle for the @oh
549 * hwmod. The autoidle bit controls whether the module can gate
550 * internal clocks automatically when it isn't doing anything; the
551 * exact function of this bit varies on a per-module basis. This
552 * function does not write to the hardware. Returns -EINVAL upon
553 * error or 0 upon success.
554 */
555static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle,
556 u32 *v)
557{
Thara Gopinath358f0e62010-02-24 12:05:58 -0700558 u32 autoidle_mask;
559 u8 autoidle_shift;
560
Paul Walmsley43b40992010-02-22 22:09:34 -0700561 if (!oh->class->sysc ||
562 !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE))
Paul Walmsley726072e2009-12-08 16:34:15 -0700563 return -EINVAL;
564
Paul Walmsley43b40992010-02-22 22:09:34 -0700565 if (!oh->class->sysc->sysc_fields) {
566 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700567 return -EINVAL;
568 }
569
Paul Walmsley43b40992010-02-22 22:09:34 -0700570 autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift;
Tarun Kanti DebBarma8985b632011-03-03 14:22:46 -0700571 autoidle_mask = (0x1 << autoidle_shift);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700572
573 *v &= ~autoidle_mask;
574 *v |= autoidle << autoidle_shift;
Paul Walmsley726072e2009-12-08 16:34:15 -0700575
576 return 0;
577}
578
579/**
Paul Walmsley63c85232009-09-03 20:14:03 +0300580 * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
581 * @oh: struct omap_hwmod *
582 *
583 * Allow the hardware module @oh to send wakeups. Returns -EINVAL
584 * upon error or 0 upon success.
585 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700586static int _enable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300587{
Paul Walmsley43b40992010-02-22 22:09:34 -0700588 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700589 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200590 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
591 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300592 return -EINVAL;
593
Paul Walmsley43b40992010-02-22 22:09:34 -0700594 if (!oh->class->sysc->sysc_fields) {
595 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700596 return -EINVAL;
597 }
598
Benoit Cousson1fe74112011-07-01 22:54:03 +0200599 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
600 *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift;
Paul Walmsley63c85232009-09-03 20:14:03 +0300601
Benoit Cousson86009eb2010-12-21 21:31:28 -0700602 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
603 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200604 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
605 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700606
Paul Walmsley63c85232009-09-03 20:14:03 +0300607 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
608
Paul Walmsley63c85232009-09-03 20:14:03 +0300609 return 0;
610}
611
612/**
613 * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware
614 * @oh: struct omap_hwmod *
615 *
616 * Prevent the hardware module @oh to send wakeups. Returns -EINVAL
617 * upon error or 0 upon success.
618 */
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -0700619static int _disable_wakeup(struct omap_hwmod *oh, u32 *v)
Paul Walmsley63c85232009-09-03 20:14:03 +0300620{
Paul Walmsley43b40992010-02-22 22:09:34 -0700621 if (!oh->class->sysc ||
Benoit Cousson86009eb2010-12-21 21:31:28 -0700622 !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) ||
Benoit Cousson724019b2011-07-01 22:54:00 +0200623 (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) ||
624 (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)))
Paul Walmsley63c85232009-09-03 20:14:03 +0300625 return -EINVAL;
626
Paul Walmsley43b40992010-02-22 22:09:34 -0700627 if (!oh->class->sysc->sysc_fields) {
628 WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name);
Thara Gopinath358f0e62010-02-24 12:05:58 -0700629 return -EINVAL;
630 }
631
Benoit Cousson1fe74112011-07-01 22:54:03 +0200632 if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)
633 *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift);
Paul Walmsley63c85232009-09-03 20:14:03 +0300634
Benoit Cousson86009eb2010-12-21 21:31:28 -0700635 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
636 _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson724019b2011-07-01 22:54:00 +0200637 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
Djamil Elaidi561038f2012-06-17 11:57:51 -0600638 _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v);
Benoit Cousson86009eb2010-12-21 21:31:28 -0700639
Paul Walmsley63c85232009-09-03 20:14:03 +0300640 /* XXX test pwrdm_get_wken for this hwmod's subsystem */
641
Paul Walmsley63c85232009-09-03 20:14:03 +0300642 return 0;
643}
644
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700645static struct clockdomain *_get_clkdm(struct omap_hwmod *oh)
646{
Rajendra Nayakc4a1ea22012-04-27 16:32:53 +0530647 struct clk_hw_omap *clk;
648
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700649 if (oh->clkdm) {
650 return oh->clkdm;
651 } else if (oh->_clk) {
Tero Kristo924f9492013-07-12 12:26:41 +0300652 if (__clk_get_flags(oh->_clk) & CLK_IS_BASIC)
653 return NULL;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700654 clk = to_clk_hw_omap(__clk_get_hw(oh->_clk));
655 return clk->clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700656 }
657 return NULL;
658}
659
Paul Walmsley63c85232009-09-03 20:14:03 +0300660/**
661 * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active
662 * @oh: struct omap_hwmod *
663 *
664 * Prevent the hardware module @oh from entering idle while the
665 * hardare module initiator @init_oh is active. Useful when a module
666 * will be accessed by a particular initiator (e.g., if a module will
667 * be accessed by the IVA, there should be a sleepdep between the IVA
668 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700669 * mode. If the clockdomain is marked as not needing autodeps, return
670 * 0 without doing anything. Otherwise, returns -EINVAL upon error or
671 * passes along clkdm_add_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300672 */
673static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
674{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700675 struct clockdomain *clkdm, *init_clkdm;
676
677 clkdm = _get_clkdm(oh);
678 init_clkdm = _get_clkdm(init_oh);
679
680 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300681 return -EINVAL;
682
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700683 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700684 return 0;
685
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700686 return clkdm_add_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300687}
688
689/**
690 * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active
691 * @oh: struct omap_hwmod *
692 *
693 * Allow the hardware module @oh to enter idle while the hardare
694 * module initiator @init_oh is active. Useful when a module will not
695 * be accessed by a particular initiator (e.g., if a module will not
696 * be accessed by the IVA, there should be no sleepdep between the IVA
697 * initiator and the module). Only applies to modules in smart-idle
Paul Walmsley570b54c2011-03-10 03:50:09 -0700698 * mode. If the clockdomain is marked as not needing autodeps, return
699 * 0 without doing anything. Returns -EINVAL upon error or passes
700 * along clkdm_del_sleepdep() value upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +0300701 */
702static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
703{
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700704 struct clockdomain *clkdm, *init_clkdm;
705
706 clkdm = _get_clkdm(oh);
707 init_clkdm = _get_clkdm(init_oh);
708
709 if (!clkdm || !init_clkdm)
Paul Walmsley63c85232009-09-03 20:14:03 +0300710 return -EINVAL;
711
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700712 if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS)
Paul Walmsley570b54c2011-03-10 03:50:09 -0700713 return 0;
714
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700715 return clkdm_del_sleepdep(clkdm, init_clkdm);
Paul Walmsley63c85232009-09-03 20:14:03 +0300716}
717
Tero Kristo70f05be2017-05-31 18:00:03 +0300718static const struct of_device_id ti_clkctrl_match_table[] __initconst = {
719 { .compatible = "ti,clkctrl" },
720 { }
721};
722
Arnd Bergmann0ca14cd2017-09-14 14:50:58 +0200723static int __init _setup_clkctrl_provider(struct device_node *np)
Tero Kristo70f05be2017-05-31 18:00:03 +0300724{
725 const __be32 *addrp;
726 struct clkctrl_provider *provider;
Tero Kristo6e83eca2017-08-04 17:41:50 +0300727 u64 size;
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300728 int i;
Tero Kristo70f05be2017-05-31 18:00:03 +0300729
Mike Rapoport7e1c4e22018-10-30 15:09:57 -0700730 provider = memblock_alloc(sizeof(*provider), SMP_CACHE_BYTES);
Tero Kristo70f05be2017-05-31 18:00:03 +0300731 if (!provider)
732 return -ENOMEM;
733
Tero Kristo70f05be2017-05-31 18:00:03 +0300734 provider->node = np;
735
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300736 provider->num_addrs =
737 of_property_count_elems_of_size(np, "reg", sizeof(u32)) / 2;
738
739 provider->addr =
Mike Rapoport7e1c4e22018-10-30 15:09:57 -0700740 memblock_alloc(sizeof(void *) * provider->num_addrs,
741 SMP_CACHE_BYTES);
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300742 if (!provider->addr)
743 return -ENOMEM;
744
745 provider->size =
Mike Rapoport7e1c4e22018-10-30 15:09:57 -0700746 memblock_alloc(sizeof(u32) * provider->num_addrs,
747 SMP_CACHE_BYTES);
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300748 if (!provider->size)
749 return -ENOMEM;
750
751 for (i = 0; i < provider->num_addrs; i++) {
752 addrp = of_get_address(np, i, &size, NULL);
753 provider->addr[i] = (u32)of_translate_address(np, addrp);
754 provider->size[i] = size;
755 pr_debug("%s: %pOF: %x...%x\n", __func__, np, provider->addr[i],
756 provider->addr[i] + provider->size[i]);
757 }
Tero Kristo70f05be2017-05-31 18:00:03 +0300758
759 list_add(&provider->link, &clkctrl_providers);
760
761 return 0;
762}
763
Arnd Bergmann0ca14cd2017-09-14 14:50:58 +0200764static int __init _init_clkctrl_providers(void)
Tero Kristo70f05be2017-05-31 18:00:03 +0300765{
766 struct device_node *np;
767 int ret = 0;
768
769 for_each_matching_node(np, ti_clkctrl_match_table) {
770 ret = _setup_clkctrl_provider(np);
771 if (ret)
772 break;
773 }
774
775 return ret;
776}
777
Tero Kristo6e83eca2017-08-04 17:41:50 +0300778static u32 _omap4_xlate_clkctrl(struct omap_hwmod *oh)
Tero Kristo70f05be2017-05-31 18:00:03 +0300779{
Tero Kristo6e83eca2017-08-04 17:41:50 +0300780 if (!oh->prcm.omap4.modulemode)
781 return 0;
782
783 return omap_cm_xlate_clkctrl(oh->clkdm->prcm_partition,
784 oh->clkdm->cm_inst,
785 oh->prcm.omap4.clkctrl_offs);
Tero Kristo70f05be2017-05-31 18:00:03 +0300786}
787
788static struct clk *_lookup_clkctrl_clk(struct omap_hwmod *oh)
789{
790 struct clkctrl_provider *provider;
791 struct clk *clk;
Tero Kristo6e83eca2017-08-04 17:41:50 +0300792 u32 addr;
Tero Kristo70f05be2017-05-31 18:00:03 +0300793
794 if (!soc_ops.xlate_clkctrl)
795 return NULL;
796
Tero Kristo6e83eca2017-08-04 17:41:50 +0300797 addr = soc_ops.xlate_clkctrl(oh);
798 if (!addr)
799 return NULL;
800
801 pr_debug("%s: %s: addr=%x\n", __func__, oh->name, addr);
802
Tero Kristo70f05be2017-05-31 18:00:03 +0300803 list_for_each_entry(provider, &clkctrl_providers, link) {
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300804 int i;
Tero Kristo70f05be2017-05-31 18:00:03 +0300805
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300806 for (i = 0; i < provider->num_addrs; i++) {
807 if (provider->addr[i] <= addr &&
808 provider->addr[i] + provider->size[i] > addr) {
809 struct of_phandle_args clkspec;
Tero Kristo70f05be2017-05-31 18:00:03 +0300810
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300811 clkspec.np = provider->node;
812 clkspec.args_count = 2;
813 clkspec.args[0] = addr - provider->addr[0];
814 clkspec.args[1] = 0;
Tero Kristo70f05be2017-05-31 18:00:03 +0300815
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300816 clk = of_clk_get_from_provider(&clkspec);
Tero Kristo6e83eca2017-08-04 17:41:50 +0300817
Tero Kristo1b9c30f2018-08-31 18:01:23 +0300818 pr_debug("%s: %s got %p (offset=%x, provider=%pOF)\n",
819 __func__, oh->name, clk,
820 clkspec.args[0], provider->node);
821
822 return clk;
823 }
Tero Kristo70f05be2017-05-31 18:00:03 +0300824 }
825 }
826
827 return NULL;
828}
829
Paul Walmsley63c85232009-09-03 20:14:03 +0300830/**
831 * _init_main_clk - get a struct clk * for the the hwmod's main functional clk
832 * @oh: struct omap_hwmod *
833 *
834 * Called from _init_clocks(). Populates the @oh _clk (main
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300835 * functional clock pointer) if a clock matching the hwmod name is found,
836 * or a main_clk is present. Returns 0 on success or -EINVAL on error.
Paul Walmsley63c85232009-09-03 20:14:03 +0300837 */
838static int _init_main_clk(struct omap_hwmod *oh)
839{
Paul Walmsley63c85232009-09-03 20:14:03 +0300840 int ret = 0;
Tero Kristo70f05be2017-05-31 18:00:03 +0300841 struct clk *clk = NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +0300842
Tero Kristo70f05be2017-05-31 18:00:03 +0300843 clk = _lookup_clkctrl_clk(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +0300844
Tero Kristo70f05be2017-05-31 18:00:03 +0300845 if (!IS_ERR_OR_NULL(clk)) {
846 pr_debug("%s: mapped main_clk %s for %s\n", __func__,
847 __clk_get_name(clk), oh->name);
848 oh->main_clk = __clk_get_name(clk);
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300849 oh->_clk = clk;
850 soc_ops.disable_direct_prcm(oh);
Tero Kristo9fabc1a2016-07-04 14:11:48 +0300851 } else {
852 if (!oh->main_clk)
853 return 0;
854
855 oh->_clk = clk_get(NULL, oh->main_clk);
856 }
857
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600858 if (IS_ERR(oh->_clk)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700859 pr_warn("omap_hwmod: %s: cannot clk_get main_clk %s\n",
860 oh->name, oh->main_clk);
Benoit Cousson63403382010-05-20 12:31:10 -0600861 return -EINVAL;
Benoit Coussondc759252010-06-23 18:15:12 -0600862 }
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600863 /*
864 * HACK: This needs a re-visit once clk_prepare() is implemented
865 * to do something meaningful. Today its just a no-op.
866 * If clk_prepare() is used at some point to do things like
867 * voltage scaling etc, then this would have to be moved to
868 * some point where subsystems like i2c and pmic become
869 * available.
870 */
871 clk_prepare(oh->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300872
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -0700873 if (!_get_clkdm(oh))
Paul Walmsley3bb05db2012-09-23 17:28:18 -0600874 pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600875 oh->name, oh->main_clk);
Kevin Hilman81d7c6f2009-12-08 16:34:24 -0700876
Paul Walmsley63c85232009-09-03 20:14:03 +0300877 return ret;
878}
879
880/**
Paul Walmsley887adea2010-07-26 16:34:33 -0600881 * _init_interface_clks - get a struct clk * for the the hwmod's interface clks
Paul Walmsley63c85232009-09-03 20:14:03 +0300882 * @oh: struct omap_hwmod *
883 *
884 * Called from _init_clocks(). Populates the @oh OCP slave interface
885 * clock pointers. Returns 0 on success or -EINVAL on error.
886 */
887static int _init_interface_clks(struct omap_hwmod *oh)
888{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600889 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +0300890 struct clk *c;
Paul Walmsley63c85232009-09-03 20:14:03 +0300891 int ret = 0;
892
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -0700893 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley50ebdac2010-02-22 22:09:31 -0700894 if (!os->clk)
Paul Walmsley63c85232009-09-03 20:14:03 +0300895 continue;
896
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600897 c = clk_get(NULL, os->clk);
898 if (IS_ERR(c)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700899 pr_warn("omap_hwmod: %s: cannot clk_get interface_clk %s\n",
900 oh->name, os->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300901 ret = -EINVAL;
Nishanth Menon0e7dc862013-12-08 18:39:03 -0700902 continue;
Benoit Coussondc759252010-06-23 18:15:12 -0600903 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300904 os->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600905 /*
906 * HACK: This needs a re-visit once clk_prepare() is implemented
907 * to do something meaningful. Today its just a no-op.
908 * If clk_prepare() is used at some point to do things like
909 * voltage scaling etc, then this would have to be moved to
910 * some point where subsystems like i2c and pmic become
911 * available.
912 */
913 clk_prepare(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300914 }
915
916 return ret;
917}
918
919/**
920 * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks
921 * @oh: struct omap_hwmod *
922 *
923 * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk
924 * clock pointers. Returns 0 on success or -EINVAL on error.
925 */
926static int _init_opt_clks(struct omap_hwmod *oh)
927{
928 struct omap_hwmod_opt_clk *oc;
929 struct clk *c;
930 int i;
931 int ret = 0;
932
933 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) {
Rajendra Nayak6ea74cb2012-09-22 02:24:16 -0600934 c = clk_get(NULL, oc->clk);
935 if (IS_ERR(c)) {
Joe Perches3d0cb732014-09-13 11:31:16 -0700936 pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n",
937 oh->name, oc->clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300938 ret = -EINVAL;
Nishanth Menon0e7dc862013-12-08 18:39:03 -0700939 continue;
Benoit Coussondc759252010-06-23 18:15:12 -0600940 }
Paul Walmsley63c85232009-09-03 20:14:03 +0300941 oc->_clk = c;
Rajendra Nayak4d7cb452012-09-22 02:24:16 -0600942 /*
943 * HACK: This needs a re-visit once clk_prepare() is implemented
944 * to do something meaningful. Today its just a no-op.
945 * If clk_prepare() is used at some point to do things like
946 * voltage scaling etc, then this would have to be moved to
947 * some point where subsystems like i2c and pmic become
948 * available.
949 */
950 clk_prepare(oc->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +0300951 }
952
953 return ret;
954}
955
Peter Ujfalusic12ba8c2015-11-12 09:32:58 +0200956static void _enable_optional_clocks(struct omap_hwmod *oh)
957{
958 struct omap_hwmod_opt_clk *oc;
959 int i;
960
961 pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name);
962
963 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
964 if (oc->_clk) {
965 pr_debug("omap_hwmod: enable %s:%s\n", oc->role,
966 __clk_get_name(oc->_clk));
967 clk_enable(oc->_clk);
968 }
969}
970
971static void _disable_optional_clocks(struct omap_hwmod *oh)
972{
973 struct omap_hwmod_opt_clk *oc;
974 int i;
975
976 pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name);
977
978 for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
979 if (oc->_clk) {
980 pr_debug("omap_hwmod: disable %s:%s\n", oc->role,
981 __clk_get_name(oc->_clk));
982 clk_disable(oc->_clk);
983 }
984}
985
Paul Walmsley63c85232009-09-03 20:14:03 +0300986/**
987 * _enable_clocks - enable hwmod main clock and interface clocks
988 * @oh: struct omap_hwmod *
989 *
990 * Enables all clocks necessary for register reads and writes to succeed
991 * on the hwmod @oh. Returns 0.
992 */
993static int _enable_clocks(struct omap_hwmod *oh)
994{
Paul Walmsley5d95dde2012-04-19 04:04:28 -0600995 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +0300996
997 pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name);
998
Tero Kristo392ea5d2017-12-22 11:26:03 +0200999 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
1000 _enable_optional_clocks(oh);
1001
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -06001002 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +03001003 clk_enable(oh->_clk);
1004
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001005 list_for_each_entry(os, &oh->slave_ports, node) {
Andreas Kemnade12af39c2019-01-16 23:04:29 +01001006 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) {
1007 omap2_clk_deny_idle(os->_clk);
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001008 clk_enable(os->_clk);
Andreas Kemnade12af39c2019-01-16 23:04:29 +01001009 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001010 }
1011
1012 /* The opt clocks are controlled by the device driver. */
1013
1014 return 0;
1015}
1016
1017/**
Tony Lindgren8823ddf2017-08-29 10:03:33 -07001018 * _omap4_clkctrl_managed_by_clkfwk - true if clkctrl managed by clock framework
1019 * @oh: struct omap_hwmod *
1020 */
1021static bool _omap4_clkctrl_managed_by_clkfwk(struct omap_hwmod *oh)
1022{
1023 if (oh->prcm.omap4.flags & HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK)
1024 return true;
1025
1026 return false;
1027}
1028
1029/**
1030 * _omap4_has_clkctrl_clock - returns true if a module has clkctrl clock
1031 * @oh: struct omap_hwmod *
1032 */
1033static bool _omap4_has_clkctrl_clock(struct omap_hwmod *oh)
1034{
1035 if (oh->prcm.omap4.clkctrl_offs)
1036 return true;
1037
1038 if (!oh->prcm.omap4.clkctrl_offs &&
1039 oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET)
1040 return true;
1041
1042 return false;
1043}
1044
1045/**
Paul Walmsley63c85232009-09-03 20:14:03 +03001046 * _disable_clocks - disable hwmod main clock and interface clocks
1047 * @oh: struct omap_hwmod *
1048 *
1049 * Disables the hwmod @oh main functional and interface clocks. Returns 0.
1050 */
1051static int _disable_clocks(struct omap_hwmod *oh)
1052{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001053 struct omap_hwmod_ocp_if *os;
Paul Walmsley63c85232009-09-03 20:14:03 +03001054
1055 pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
1056
Benoit Cousson4d3ae5a2010-05-20 12:31:09 -06001057 if (oh->_clk)
Paul Walmsley63c85232009-09-03 20:14:03 +03001058 clk_disable(oh->_clk);
1059
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001060 list_for_each_entry(os, &oh->slave_ports, node) {
Andreas Kemnade12af39c2019-01-16 23:04:29 +01001061 if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) {
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001062 clk_disable(os->_clk);
Andreas Kemnade12af39c2019-01-16 23:04:29 +01001063 omap2_clk_allow_idle(os->_clk);
1064 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001065 }
1066
Peter Ujfalusic12ba8c2015-11-12 09:32:58 +02001067 if (oh->flags & HWMOD_OPT_CLKS_NEEDED)
1068 _disable_optional_clocks(oh);
1069
Paul Walmsley63c85232009-09-03 20:14:03 +03001070 /* The opt clocks are controlled by the device driver. */
1071
1072 return 0;
1073}
1074
1075/**
Kevin Hilman3d9f0322012-06-18 12:12:23 -06001076 * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4
Benoit Cousson45c38252011-07-10 05:56:33 -06001077 * @oh: struct omap_hwmod *
1078 *
1079 * Enables the PRCM module mode related to the hwmod @oh.
1080 * No return value.
1081 */
Kevin Hilman3d9f0322012-06-18 12:12:23 -06001082static void _omap4_enable_module(struct omap_hwmod *oh)
Benoit Cousson45c38252011-07-10 05:56:33 -06001083{
Tony Lindgren8823ddf2017-08-29 10:03:33 -07001084 if (!oh->clkdm || !oh->prcm.omap4.modulemode ||
1085 _omap4_clkctrl_managed_by_clkfwk(oh))
Benoit Cousson45c38252011-07-10 05:56:33 -06001086 return;
1087
Kevin Hilman3d9f0322012-06-18 12:12:23 -06001088 pr_debug("omap_hwmod: %s: %s: %d\n",
1089 oh->name, __func__, oh->prcm.omap4.modulemode);
Benoit Cousson45c38252011-07-10 05:56:33 -06001090
Tero Kristo128603f2014-10-27 08:39:24 -07001091 omap_cm_module_enable(oh->prcm.omap4.modulemode,
1092 oh->clkdm->prcm_partition,
1093 oh->clkdm->cm_inst, oh->prcm.omap4.clkctrl_offs);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001094}
1095
1096/**
Benoit Coussonbfc141e2011-12-16 16:09:11 -08001097 * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4
1098 * @oh: struct omap_hwmod *
1099 *
1100 * Wait for a module @oh to enter slave idle. Returns 0 if the module
1101 * does not have an IDLEST bit or if the module successfully enters
1102 * slave idle; otherwise, pass along the return value of the
1103 * appropriate *_cm*_wait_module_idle() function.
1104 */
1105static int _omap4_wait_target_disable(struct omap_hwmod *oh)
1106{
Paul Walmsley2b026d12012-09-23 17:28:18 -06001107 if (!oh)
Benoit Coussonbfc141e2011-12-16 16:09:11 -08001108 return -EINVAL;
1109
Paul Walmsley2b026d12012-09-23 17:28:18 -06001110 if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm)
Benoit Coussonbfc141e2011-12-16 16:09:11 -08001111 return 0;
1112
1113 if (oh->flags & HWMOD_NO_IDLEST)
1114 return 0;
1115
Tony Lindgren8823ddf2017-08-29 10:03:33 -07001116 if (_omap4_clkctrl_managed_by_clkfwk(oh))
1117 return 0;
1118
1119 if (!_omap4_has_clkctrl_clock(oh))
Dave Gerlach428929c2016-07-12 12:50:33 -05001120 return 0;
1121
Tero Kristoa8ae5af2014-10-27 08:39:23 -07001122 return omap_cm_wait_module_idle(oh->clkdm->prcm_partition,
1123 oh->clkdm->cm_inst,
1124 oh->prcm.omap4.clkctrl_offs, 0);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06001125}
1126
1127/**
Paul Walmsley24dbc212012-04-19 04:04:29 -06001128 * _save_mpu_port_index - find and save the index to @oh's MPU port
Paul Walmsley63c85232009-09-03 20:14:03 +03001129 * @oh: struct omap_hwmod *
1130 *
Paul Walmsley24dbc212012-04-19 04:04:29 -06001131 * Determines the array index of the OCP slave port that the MPU uses
1132 * to address the device, and saves it into the struct omap_hwmod.
1133 * Intended to be called during hwmod registration only. No return
1134 * value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001135 */
Paul Walmsley24dbc212012-04-19 04:04:29 -06001136static void __init _save_mpu_port_index(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001137{
Paul Walmsley24dbc212012-04-19 04:04:29 -06001138 struct omap_hwmod_ocp_if *os = NULL;
Paul Walmsley63c85232009-09-03 20:14:03 +03001139
Paul Walmsley5d95dde2012-04-19 04:04:28 -06001140 if (!oh)
Paul Walmsley24dbc212012-04-19 04:04:29 -06001141 return;
1142
1143 oh->_int_flags |= _HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001144
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07001145 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley63c85232009-09-03 20:14:03 +03001146 if (os->user & OCP_USER_MPU) {
Paul Walmsley2221b5c2012-04-19 04:04:30 -06001147 oh->_mpu_port = os;
Paul Walmsley24dbc212012-04-19 04:04:29 -06001148 oh->_int_flags &= ~_HWMOD_NO_MPU_PORT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001149 break;
1150 }
1151 }
1152
Paul Walmsley24dbc212012-04-19 04:04:29 -06001153 return;
Paul Walmsley63c85232009-09-03 20:14:03 +03001154}
1155
1156/**
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001157 * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU
1158 * @oh: struct omap_hwmod *
1159 *
1160 * Given a pointer to a struct omap_hwmod record @oh, return a pointer
1161 * to the struct omap_hwmod_ocp_if record that is used by the MPU to
1162 * communicate with the IP block. This interface need not be directly
1163 * connected to the MPU (and almost certainly is not), but is directly
1164 * connected to the IP block represented by @oh. Returns a pointer
1165 * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon
1166 * error or if there does not appear to be a path from the MPU to this
1167 * IP block.
1168 */
1169static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh)
1170{
1171 if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0)
1172 return NULL;
1173
Paul Walmsley11cd4b92012-04-19 04:04:32 -06001174 return oh->_mpu_port;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06001175};
1176
1177/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001178 * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001179 * @oh: struct omap_hwmod *
1180 *
Paul Walmsley006c7f12012-07-04 05:22:53 -06001181 * Ensure that the OCP_SYSCONFIG register for the IP block represented
1182 * by @oh is set to indicate to the PRCM that the IP block is active.
1183 * Usually this means placing the module into smart-idle mode and
1184 * smart-standby, but if there is a bug in the automatic idle handling
1185 * for the IP block, it may need to be placed into the force-idle or
1186 * no-idle variants of these modes. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03001187 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001188static void _enable_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001189{
Paul Walmsley43b40992010-02-22 22:09:34 -07001190 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001191 u32 v;
Paul Walmsley006c7f12012-07-04 05:22:53 -06001192 bool clkdm_act;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001193 struct clockdomain *clkdm;
Paul Walmsley63c85232009-09-03 20:14:03 +03001194
Paul Walmsley43b40992010-02-22 22:09:34 -07001195 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001196 return;
1197
Tero Kristo613ad0e2012-10-29 22:02:13 -06001198 /*
1199 * Wait until reset has completed, this is needed as the IP
1200 * block is reset automatically by hardware in some cases
1201 * (off-mode for example), and the drivers require the
1202 * IP to be ready when they access it
1203 */
1204 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1205 _enable_optional_clocks(oh);
1206 _wait_softreset_complete(oh);
1207 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1208 _disable_optional_clocks(oh);
1209
Paul Walmsley63c85232009-09-03 20:14:03 +03001210 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001211 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001212
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001213 clkdm = _get_clkdm(oh);
Paul Walmsley43b40992010-02-22 22:09:34 -07001214 if (sf & SYSC_HAS_SIDLEMODE) {
Rajendra Nayakca43ea32013-05-15 20:18:38 +05301215 if (oh->flags & HWMOD_SWSUP_SIDLE ||
1216 oh->flags & HWMOD_SWSUP_SIDLE_ACT) {
Rajendra Nayak355131712013-05-15 20:18:37 +05301217 idlemode = HWMOD_IDLEMODE_NO;
1218 } else {
1219 if (sf & SYSC_HAS_ENAWAKEUP)
1220 _enable_wakeup(oh, &v);
1221 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1222 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1223 else
1224 idlemode = HWMOD_IDLEMODE_SMART;
1225 }
1226
1227 /*
1228 * This is special handling for some IPs like
1229 * 32k sync timer. Force them to idle!
1230 */
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07001231 clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU);
Paul Walmsley006c7f12012-07-04 05:22:53 -06001232 if (clkdm_act && !(oh->class->sysc->idlemodes &
1233 (SIDLE_SMART | SIDLE_SMART_WKUP)))
1234 idlemode = HWMOD_IDLEMODE_FORCE;
Rajendra Nayak355131712013-05-15 20:18:37 +05301235
Paul Walmsley63c85232009-09-03 20:14:03 +03001236 _set_slave_idlemode(oh, idlemode, &v);
1237 }
1238
Paul Walmsley43b40992010-02-22 22:09:34 -07001239 if (sf & SYSC_HAS_MIDLEMODE) {
Grazvydas Ignotas092bc082013-03-11 21:49:00 +02001240 if (oh->flags & HWMOD_FORCE_MSTANDBY) {
1241 idlemode = HWMOD_IDLEMODE_FORCE;
1242 } else if (oh->flags & HWMOD_SWSUP_MSTANDBY) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001243 idlemode = HWMOD_IDLEMODE_NO;
1244 } else {
1245 if (sf & SYSC_HAS_ENAWAKEUP)
1246 _enable_wakeup(oh, &v);
1247 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1248 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1249 else
1250 idlemode = HWMOD_IDLEMODE_SMART;
1251 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001252 _set_master_standbymode(oh, idlemode, &v);
1253 }
1254
Paul Walmsleya16b1f72009-12-08 16:34:17 -07001255 /*
1256 * XXX The clock framework should handle this, by
1257 * calling into this code. But this must wait until the
1258 * clock structures are tagged with omap_hwmod entries
1259 */
Paul Walmsley43b40992010-02-22 22:09:34 -07001260 if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) &&
1261 (sf & SYSC_HAS_CLOCKACTIVITY))
Tony Lindgrenca5339b2017-03-14 13:13:19 -07001262 _set_clockactivity(oh, CLOCKACT_TEST_ICLK, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001263
Lokesh Vutla3ca4a232016-03-26 23:08:55 -06001264 _write_sysconfig(v, oh);
Hema HK78f26e82010-09-24 10:23:19 -06001265
1266 /*
1267 * Set the autoidle bit only after setting the smartidle bit
1268 * Setting this will not have any impact on the other modules.
1269 */
1270 if (sf & SYSC_HAS_AUTOIDLE) {
1271 idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ?
1272 0 : 1;
1273 _set_module_autoidle(oh, idlemode, &v);
1274 _write_sysconfig(v, oh);
1275 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001276}
1277
1278/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001279 * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001280 * @oh: struct omap_hwmod *
1281 *
1282 * If module is marked as SWSUP_SIDLE, force the module into slave
1283 * idle; otherwise, configure it for smart-idle. If module is marked
1284 * as SWSUP_MSUSPEND, force the module into master standby; otherwise,
1285 * configure it for smart-standby. No return value.
1286 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001287static void _idle_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001288{
Paul Walmsley43b40992010-02-22 22:09:34 -07001289 u8 idlemode, sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001290 u32 v;
1291
Paul Walmsley43b40992010-02-22 22:09:34 -07001292 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001293 return;
1294
1295 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001296 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001297
Paul Walmsley43b40992010-02-22 22:09:34 -07001298 if (sf & SYSC_HAS_SIDLEMODE) {
Rajendra Nayak355131712013-05-15 20:18:37 +05301299 if (oh->flags & HWMOD_SWSUP_SIDLE) {
Paul Walmsley006c7f12012-07-04 05:22:53 -06001300 idlemode = HWMOD_IDLEMODE_FORCE;
Rajendra Nayak355131712013-05-15 20:18:37 +05301301 } else {
1302 if (sf & SYSC_HAS_ENAWAKEUP)
1303 _enable_wakeup(oh, &v);
1304 if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP)
1305 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1306 else
1307 idlemode = HWMOD_IDLEMODE_SMART;
1308 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001309 _set_slave_idlemode(oh, idlemode, &v);
1310 }
1311
Paul Walmsley43b40992010-02-22 22:09:34 -07001312 if (sf & SYSC_HAS_MIDLEMODE) {
Grazvydas Ignotas092bc082013-03-11 21:49:00 +02001313 if ((oh->flags & HWMOD_SWSUP_MSTANDBY) ||
1314 (oh->flags & HWMOD_FORCE_MSTANDBY)) {
Benoit Cousson724019b2011-07-01 22:54:00 +02001315 idlemode = HWMOD_IDLEMODE_FORCE;
1316 } else {
1317 if (sf & SYSC_HAS_ENAWAKEUP)
1318 _enable_wakeup(oh, &v);
1319 if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP)
1320 idlemode = HWMOD_IDLEMODE_SMART_WKUP;
1321 else
1322 idlemode = HWMOD_IDLEMODE_SMART;
1323 }
Paul Walmsley63c85232009-09-03 20:14:03 +03001324 _set_master_standbymode(oh, idlemode, &v);
1325 }
1326
Lokesh Vutla3ca4a232016-03-26 23:08:55 -06001327 /* If the cached value is the same as the new value, skip the write */
1328 if (oh->_sysc_cache != v)
1329 _write_sysconfig(v, oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03001330}
1331
1332/**
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001333 * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG
Paul Walmsley63c85232009-09-03 20:14:03 +03001334 * @oh: struct omap_hwmod *
1335 *
1336 * Force the module into slave idle and master suspend. No return
1337 * value.
1338 */
Paul Walmsley74ff3a62010-09-21 15:02:23 -06001339static void _shutdown_sysc(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001340{
1341 u32 v;
Paul Walmsley43b40992010-02-22 22:09:34 -07001342 u8 sf;
Paul Walmsley63c85232009-09-03 20:14:03 +03001343
Paul Walmsley43b40992010-02-22 22:09:34 -07001344 if (!oh->class->sysc)
Paul Walmsley63c85232009-09-03 20:14:03 +03001345 return;
1346
1347 v = oh->_sysc_cache;
Paul Walmsley43b40992010-02-22 22:09:34 -07001348 sf = oh->class->sysc->sysc_flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03001349
Paul Walmsley43b40992010-02-22 22:09:34 -07001350 if (sf & SYSC_HAS_SIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001351 _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v);
1352
Paul Walmsley43b40992010-02-22 22:09:34 -07001353 if (sf & SYSC_HAS_MIDLEMODE)
Paul Walmsley63c85232009-09-03 20:14:03 +03001354 _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v);
1355
Paul Walmsley43b40992010-02-22 22:09:34 -07001356 if (sf & SYSC_HAS_AUTOIDLE)
Paul Walmsley726072e2009-12-08 16:34:15 -07001357 _set_module_autoidle(oh, 1, &v);
Paul Walmsley63c85232009-09-03 20:14:03 +03001358
1359 _write_sysconfig(v, oh);
1360}
1361
1362/**
1363 * _lookup - find an omap_hwmod by name
1364 * @name: find an omap_hwmod by name
1365 *
1366 * Return a pointer to an omap_hwmod by name, or NULL if not found.
Paul Walmsley63c85232009-09-03 20:14:03 +03001367 */
1368static struct omap_hwmod *_lookup(const char *name)
1369{
1370 struct omap_hwmod *oh, *temp_oh;
1371
1372 oh = NULL;
1373
1374 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
1375 if (!strcmp(name, temp_oh->name)) {
1376 oh = temp_oh;
1377 break;
1378 }
1379 }
1380
1381 return oh;
1382}
Paul Walmsley868c1572012-06-19 15:01:02 -06001383
Benoit Cousson6ae76992011-07-10 05:56:30 -06001384/**
1385 * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod
1386 * @oh: struct omap_hwmod *
1387 *
1388 * Convert a clockdomain name stored in a struct omap_hwmod into a
1389 * clockdomain pointer, and save it into the struct omap_hwmod.
Paul Walmsley868c1572012-06-19 15:01:02 -06001390 * Return -EINVAL if the clkdm_name lookup failed.
Benoit Cousson6ae76992011-07-10 05:56:30 -06001391 */
1392static int _init_clkdm(struct omap_hwmod *oh)
1393{
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001394 if (!oh->clkdm_name) {
1395 pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name);
Benoit Cousson6ae76992011-07-10 05:56:30 -06001396 return 0;
Paul Walmsley3bb05db2012-09-23 17:28:18 -06001397 }
Benoit Cousson6ae76992011-07-10 05:56:30 -06001398
Benoit Cousson6ae76992011-07-10 05:56:30 -06001399 oh->clkdm = clkdm_lookup(oh->clkdm_name);
1400 if (!oh->clkdm) {
Joe Perches3d0cb732014-09-13 11:31:16 -07001401 pr_warn("omap_hwmod: %s: could not associate to clkdm %s\n",
Benoit Cousson6ae76992011-07-10 05:56:30 -06001402 oh->name, oh->clkdm_name);
Tero Kristo0385c582013-07-17 18:03:25 +03001403 return 0;
Benoit Cousson6ae76992011-07-10 05:56:30 -06001404 }
1405
1406 pr_debug("omap_hwmod: %s: associated to clkdm %s\n",
1407 oh->name, oh->clkdm_name);
1408
1409 return 0;
1410}
Paul Walmsley63c85232009-09-03 20:14:03 +03001411
1412/**
Benoit Cousson6ae76992011-07-10 05:56:30 -06001413 * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as
1414 * well the clockdomain.
Paul Walmsley63c85232009-09-03 20:14:03 +03001415 * @oh: struct omap_hwmod *
Tero Kristo70f05be2017-05-31 18:00:03 +03001416 * @np: device_node mapped to this hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001417 *
Paul Walmsleya2debdb2011-02-23 00:14:07 -07001418 * Called by omap_hwmod_setup_*() (after omap2_clk_init()).
Paul Walmsley48d54f32011-02-23 00:14:07 -07001419 * Resolves all clock names embedded in the hwmod. Returns 0 on
1420 * success, or a negative error code on failure.
Paul Walmsley63c85232009-09-03 20:14:03 +03001421 */
Tero Kristo70f05be2017-05-31 18:00:03 +03001422static int _init_clocks(struct omap_hwmod *oh, struct device_node *np)
Paul Walmsley63c85232009-09-03 20:14:03 +03001423{
1424 int ret = 0;
1425
Paul Walmsley48d54f32011-02-23 00:14:07 -07001426 if (oh->_state != _HWMOD_STATE_REGISTERED)
1427 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001428
1429 pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name);
1430
Vaibhav Hiremathb797be1d2012-07-09 18:24:30 +05301431 if (soc_ops.init_clkdm)
1432 ret |= soc_ops.init_clkdm(oh);
1433
Paul Walmsley63c85232009-09-03 20:14:03 +03001434 ret |= _init_main_clk(oh);
1435 ret |= _init_interface_clks(oh);
1436 ret |= _init_opt_clks(oh);
1437
Benoit Coussonf5c1f842010-05-20 12:31:10 -06001438 if (!ret)
1439 oh->_state = _HWMOD_STATE_CLKS_INITED;
Benoit Cousson66522712011-07-01 22:54:06 +02001440 else
Joe Perches3d0cb732014-09-13 11:31:16 -07001441 pr_warn("omap_hwmod: %s: cannot _init_clocks\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001442
Rajendra Nayak09c35f22011-02-16 12:11:24 +00001443 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001444}
1445
1446/**
omar ramirezcc1226e2011-03-04 13:32:44 -07001447 * _lookup_hardreset - fill register bit info for this hwmod/reset line
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001448 * @oh: struct omap_hwmod *
1449 * @name: name of the reset line in the context of this hwmod
omar ramirezcc1226e2011-03-04 13:32:44 -07001450 * @ohri: struct omap_hwmod_rst_info * that this function will fill in
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001451 *
1452 * Return the bit position of the reset line that match the
1453 * input name. Return -ENOENT if not found.
1454 */
Paul Walmsleya032d332012-08-03 09:21:10 -06001455static int _lookup_hardreset(struct omap_hwmod *oh, const char *name,
1456 struct omap_hwmod_rst_info *ohri)
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001457{
1458 int i;
1459
1460 for (i = 0; i < oh->rst_lines_cnt; i++) {
1461 const char *rst_line = oh->rst_lines[i].name;
1462 if (!strcmp(rst_line, name)) {
omar ramirezcc1226e2011-03-04 13:32:44 -07001463 ohri->rst_shift = oh->rst_lines[i].rst_shift;
1464 ohri->st_shift = oh->rst_lines[i].st_shift;
1465 pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n",
1466 oh->name, __func__, rst_line, ohri->rst_shift,
1467 ohri->st_shift);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001468
omar ramirezcc1226e2011-03-04 13:32:44 -07001469 return 0;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001470 }
1471 }
1472
1473 return -ENOENT;
1474}
1475
1476/**
1477 * _assert_hardreset - assert the HW reset line of submodules
1478 * contained in the hwmod module.
1479 * @oh: struct omap_hwmod *
1480 * @name: name of the reset line to lookup and assert
1481 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001482 * Some IP like dsp, ipu or iva contain processor that require an HW
1483 * reset line to be assert / deassert in order to enable fully the IP.
1484 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1485 * asserting the hardreset line on the currently-booted SoC, or passes
1486 * along the return value from _lookup_hardreset() or the SoC's
1487 * assert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001488 */
1489static int _assert_hardreset(struct omap_hwmod *oh, const char *name)
1490{
omar ramirezcc1226e2011-03-04 13:32:44 -07001491 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001492 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001493
1494 if (!oh)
1495 return -EINVAL;
1496
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001497 if (!soc_ops.assert_hardreset)
1498 return -ENOSYS;
1499
omar ramirezcc1226e2011-03-04 13:32:44 -07001500 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001501 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001502 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001503
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001504 ret = soc_ops.assert_hardreset(oh, &ohri);
1505
1506 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001507}
1508
1509/**
1510 * _deassert_hardreset - deassert the HW reset line of submodules contained
1511 * in the hwmod module.
1512 * @oh: struct omap_hwmod *
1513 * @name: name of the reset line to look up and deassert
1514 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001515 * Some IP like dsp, ipu or iva contain processor that require an HW
1516 * reset line to be assert / deassert in order to enable fully the IP.
1517 * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of
1518 * deasserting the hardreset line on the currently-booted SoC, or passes
1519 * along the return value from _lookup_hardreset() or the SoC's
1520 * deassert_hardreset code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001521 */
1522static int _deassert_hardreset(struct omap_hwmod *oh, const char *name)
1523{
omar ramirezcc1226e2011-03-04 13:32:44 -07001524 struct omap_hwmod_rst_info ohri;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001525 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001526
1527 if (!oh)
1528 return -EINVAL;
1529
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001530 if (!soc_ops.deassert_hardreset)
1531 return -ENOSYS;
1532
omar ramirezcc1226e2011-03-04 13:32:44 -07001533 ret = _lookup_hardreset(oh, name, &ohri);
Russell Kingc48cd652013-03-13 20:44:21 +00001534 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001535 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001536
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001537 if (oh->clkdm) {
1538 /*
1539 * A clockdomain must be in SW_SUP otherwise reset
1540 * might not be completed. The clockdomain can be set
1541 * in HW_AUTO only when the module become ready.
1542 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03001543 clkdm_deny_idle(oh->clkdm);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001544 ret = clkdm_hwmod_enable(oh->clkdm, oh);
1545 if (ret) {
1546 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1547 oh->name, oh->clkdm->name, ret);
1548 return ret;
1549 }
1550 }
1551
1552 _enable_clocks(oh);
1553 if (soc_ops.enable_module)
1554 soc_ops.enable_module(oh);
1555
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001556 ret = soc_ops.deassert_hardreset(oh, &ohri);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001557
1558 if (soc_ops.disable_module)
1559 soc_ops.disable_module(oh);
1560 _disable_clocks(oh);
1561
omar ramirezcc1226e2011-03-04 13:32:44 -07001562 if (ret == -EBUSY)
Joe Perches3d0cb732014-09-13 11:31:16 -07001563 pr_warn("omap_hwmod: %s: failed to hardreset\n", oh->name);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001564
Tero Kristo80d25182015-02-26 18:06:00 +02001565 if (oh->clkdm) {
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001566 /*
1567 * Set the clockdomain to HW_AUTO, assuming that the
1568 * previous state was HW_AUTO.
1569 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03001570 clkdm_allow_idle(oh->clkdm);
Tero Kristo80d25182015-02-26 18:06:00 +02001571
1572 clkdm_hwmod_disable(oh->clkdm, oh);
Omar Ramirez Lunae8e96df2012-09-23 17:28:21 -06001573 }
1574
omar ramirezcc1226e2011-03-04 13:32:44 -07001575 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001576}
1577
1578/**
1579 * _read_hardreset - read the HW reset line state of submodules
1580 * contained in the hwmod module
1581 * @oh: struct omap_hwmod *
1582 * @name: name of the reset line to look up and read
1583 *
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001584 * Return the state of the reset line. Returns -EINVAL if @oh is
1585 * null, -ENOSYS if we have no way of reading the hardreset line
1586 * status on the currently-booted SoC, or passes along the return
1587 * value from _lookup_hardreset() or the SoC's is_hardreset_asserted
1588 * code.
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001589 */
1590static int _read_hardreset(struct omap_hwmod *oh, const char *name)
1591{
omar ramirezcc1226e2011-03-04 13:32:44 -07001592 struct omap_hwmod_rst_info ohri;
Paul Walmsleya032d332012-08-03 09:21:10 -06001593 int ret = -EINVAL;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001594
1595 if (!oh)
1596 return -EINVAL;
1597
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001598 if (!soc_ops.is_hardreset_asserted)
1599 return -ENOSYS;
1600
omar ramirezcc1226e2011-03-04 13:32:44 -07001601 ret = _lookup_hardreset(oh, name, &ohri);
Paul Walmsleya032d332012-08-03 09:21:10 -06001602 if (ret < 0)
omar ramirezcc1226e2011-03-04 13:32:44 -07001603 return ret;
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001604
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06001605 return soc_ops.is_hardreset_asserted(oh, &ohri);
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06001606}
1607
1608/**
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001609 * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset
Paul Walmsley747834a2012-04-18 19:10:04 -06001610 * @oh: struct omap_hwmod *
1611 *
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001612 * If all hardreset lines associated with @oh are asserted, then return true.
1613 * Otherwise, if part of @oh is out hardreset or if no hardreset lines
1614 * associated with @oh are asserted, then return false.
Paul Walmsley747834a2012-04-18 19:10:04 -06001615 * This function is used to avoid executing some parts of the IP block
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001616 * enable/disable sequence if its hardreset line is set.
Paul Walmsley747834a2012-04-18 19:10:04 -06001617 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001618static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh)
Paul Walmsley747834a2012-04-18 19:10:04 -06001619{
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001620 int i, rst_cnt = 0;
Paul Walmsley747834a2012-04-18 19:10:04 -06001621
1622 if (oh->rst_lines_cnt == 0)
1623 return false;
1624
1625 for (i = 0; i < oh->rst_lines_cnt; i++)
1626 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001627 rst_cnt++;
1628
1629 if (oh->rst_lines_cnt == rst_cnt)
1630 return true;
Paul Walmsley747834a2012-04-18 19:10:04 -06001631
1632 return false;
1633}
1634
1635/**
Paul Walmsleye9332b62012-10-08 23:08:15 -06001636 * _are_any_hardreset_lines_asserted - return true if any part of @oh is
1637 * hard-reset
1638 * @oh: struct omap_hwmod *
1639 *
1640 * If any hardreset lines associated with @oh are asserted, then
1641 * return true. Otherwise, if no hardreset lines associated with @oh
1642 * are asserted, or if @oh has no hardreset lines, then return false.
1643 * This function is used to avoid executing some parts of the IP block
1644 * enable/disable sequence if any hardreset line is set.
1645 */
1646static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh)
1647{
1648 int rst_cnt = 0;
1649 int i;
1650
1651 for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++)
1652 if (_read_hardreset(oh, oh->rst_lines[i].name) > 0)
1653 rst_cnt++;
1654
1655 return (rst_cnt) ? true : false;
1656}
1657
1658/**
Paul Walmsley747834a2012-04-18 19:10:04 -06001659 * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4
1660 * @oh: struct omap_hwmod *
1661 *
1662 * Disable the PRCM module mode related to the hwmod @oh.
1663 * Return EINVAL if the modulemode is not supported and 0 in case of success.
1664 */
1665static int _omap4_disable_module(struct omap_hwmod *oh)
1666{
1667 int v;
1668
Tony Lindgren8823ddf2017-08-29 10:03:33 -07001669 if (!oh->clkdm || !oh->prcm.omap4.modulemode ||
1670 _omap4_clkctrl_managed_by_clkfwk(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06001671 return -EINVAL;
1672
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001673 /*
1674 * Since integration code might still be doing something, only
1675 * disable if all lines are under hardreset.
1676 */
Paul Walmsleye9332b62012-10-08 23:08:15 -06001677 if (_are_any_hardreset_lines_asserted(oh))
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001678 return 0;
1679
Paul Walmsley747834a2012-04-18 19:10:04 -06001680 pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__);
1681
Tero Kristo128603f2014-10-27 08:39:24 -07001682 omap_cm_module_disable(oh->clkdm->prcm_partition, oh->clkdm->cm_inst,
1683 oh->prcm.omap4.clkctrl_offs);
Paul Walmsley747834a2012-04-18 19:10:04 -06001684
Paul Walmsley747834a2012-04-18 19:10:04 -06001685 v = _omap4_wait_target_disable(oh);
1686 if (v)
1687 pr_warn("omap_hwmod: %s: _wait_target_disable failed\n",
1688 oh->name);
1689
1690 return 0;
1691}
1692
1693/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001694 * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit
Paul Walmsley63c85232009-09-03 20:14:03 +03001695 * @oh: struct omap_hwmod *
1696 *
1697 * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be
Paul Walmsley30e105c2012-04-19 00:49:09 -06001698 * enabled for this to work. Returns -ENOENT if the hwmod cannot be
1699 * reset this way, -EINVAL if the hwmod is in the wrong state,
1700 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Benoit Cousson2cb06812010-09-21 18:57:59 +02001701 *
1702 * In OMAP3 a specific SYSSTATUS register is used to get the reset status.
Paul Walmsleybd361792010-12-14 12:42:35 -07001703 * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead
Benoit Cousson2cb06812010-09-21 18:57:59 +02001704 * use the SYSCONFIG softreset bit to provide the status.
1705 *
Paul Walmsleybd361792010-12-14 12:42:35 -07001706 * Note that some IP like McBSP do have reset control but don't have
1707 * reset status.
Paul Walmsley63c85232009-09-03 20:14:03 +03001708 */
Paul Walmsleybd361792010-12-14 12:42:35 -07001709static int _ocp_softreset(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001710{
Tero Kristo613ad0e2012-10-29 22:02:13 -06001711 u32 v;
Paul Walmsley6f8b7ff2009-12-08 16:33:16 -07001712 int c = 0;
Benoit Cousson96835af2010-09-21 18:57:58 +02001713 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001714
Paul Walmsley43b40992010-02-22 22:09:34 -07001715 if (!oh->class->sysc ||
Benoit Cousson2cb06812010-09-21 18:57:59 +02001716 !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET))
Paul Walmsley30e105c2012-04-19 00:49:09 -06001717 return -ENOENT;
Paul Walmsley63c85232009-09-03 20:14:03 +03001718
1719 /* clocks must be on for this operation */
1720 if (oh->_state != _HWMOD_STATE_ENABLED) {
Paul Walmsley7852ec02012-07-26 00:54:26 -06001721 pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n",
1722 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001723 return -EINVAL;
1724 }
1725
Benoit Cousson96835af2010-09-21 18:57:58 +02001726 /* For some modules, all optionnal clocks need to be enabled as well */
1727 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1728 _enable_optional_clocks(oh);
1729
Paul Walmsleybd361792010-12-14 12:42:35 -07001730 pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001731
1732 v = oh->_sysc_cache;
Benoit Cousson96835af2010-09-21 18:57:58 +02001733 ret = _set_softreset(oh, &v);
1734 if (ret)
1735 goto dis_opt_clks;
Roger Quadros313a76e2013-12-08 18:39:02 -07001736
1737 _write_sysconfig(v, oh);
Illia Smyrnov01142512014-02-05 17:06:09 +02001738
1739 if (oh->class->sysc->srst_udelay)
1740 udelay(oh->class->sysc->srst_udelay);
1741
1742 c = _wait_softreset_complete(oh);
1743 if (c == MAX_MODULE_SOFTRESET_WAIT) {
Joe Perches3d0cb732014-09-13 11:31:16 -07001744 pr_warn("omap_hwmod: %s: softreset failed (waited %d usec)\n",
1745 oh->name, MAX_MODULE_SOFTRESET_WAIT);
Illia Smyrnov01142512014-02-05 17:06:09 +02001746 ret = -ETIMEDOUT;
1747 goto dis_opt_clks;
1748 } else {
1749 pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c);
1750 }
1751
Roger Quadros313a76e2013-12-08 18:39:02 -07001752 ret = _clear_softreset(oh, &v);
1753 if (ret)
1754 goto dis_opt_clks;
1755
Paul Walmsley63c85232009-09-03 20:14:03 +03001756 _write_sysconfig(v, oh);
1757
Paul Walmsley63c85232009-09-03 20:14:03 +03001758 /*
1759 * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from
1760 * _wait_target_ready() or _reset()
1761 */
1762
Benoit Cousson96835af2010-09-21 18:57:58 +02001763dis_opt_clks:
1764 if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET)
1765 _disable_optional_clocks(oh);
1766
1767 return ret;
Paul Walmsley63c85232009-09-03 20:14:03 +03001768}
1769
1770/**
Paul Walmsleybd361792010-12-14 12:42:35 -07001771 * _reset - reset an omap_hwmod
1772 * @oh: struct omap_hwmod *
1773 *
Paul Walmsley30e105c2012-04-19 00:49:09 -06001774 * Resets an omap_hwmod @oh. If the module has a custom reset
1775 * function pointer defined, then call it to reset the IP block, and
1776 * pass along its return value to the caller. Otherwise, if the IP
1777 * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield
1778 * associated with it, call a function to reset the IP block via that
1779 * method, and pass along the return value to the caller. Finally, if
1780 * the IP block has some hardreset lines associated with it, assert
1781 * all of those, but do _not_ deassert them. (This is because driver
1782 * authors have expressed an apparent requirement to control the
1783 * deassertion of the hardreset lines themselves.)
1784 *
1785 * The default software reset mechanism for most OMAP IP blocks is
1786 * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some
1787 * hwmods cannot be reset via this method. Some are not targets and
1788 * therefore have no OCP header registers to access. Others (like the
1789 * IVA) have idiosyncratic reset sequences. So for these relatively
1790 * rare cases, custom reset code can be supplied in the struct
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001791 * omap_hwmod_class .reset function pointer.
1792 *
1793 * _set_dmadisable() is called to set the DMADISABLE bit so that it
1794 * does not prevent idling of the system. This is necessary for cases
1795 * where ROMCODE/BOOTLOADER uses dma and transfers control to the
1796 * kernel without disabling dma.
1797 *
1798 * Passes along the return value from either _ocp_softreset() or the
1799 * custom reset function - these must return -EINVAL if the hwmod
1800 * cannot be reset this way or if the hwmod is in the wrong state,
1801 * -ETIMEDOUT if the module did not reset in time, or 0 upon success.
Paul Walmsleybd361792010-12-14 12:42:35 -07001802 */
1803static int _reset(struct omap_hwmod *oh)
1804{
Paul Walmsley30e105c2012-04-19 00:49:09 -06001805 int i, r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001806
1807 pr_debug("omap_hwmod: %s: resetting\n", oh->name);
1808
Paul Walmsley30e105c2012-04-19 00:49:09 -06001809 if (oh->class->reset) {
1810 r = oh->class->reset(oh);
1811 } else {
1812 if (oh->rst_lines_cnt > 0) {
1813 for (i = 0; i < oh->rst_lines_cnt; i++)
1814 _assert_hardreset(oh, oh->rst_lines[i].name);
1815 return 0;
1816 } else {
1817 r = _ocp_softreset(oh);
1818 if (r == -ENOENT)
1819 r = 0;
1820 }
1821 }
Paul Walmsleybd361792010-12-14 12:42:35 -07001822
Kishon Vijay Abraham I66685462012-07-04 05:09:21 -06001823 _set_dmadisable(oh);
1824
Paul Walmsley30e105c2012-04-19 00:49:09 -06001825 /*
1826 * OCP_SYSCONFIG bits need to be reprogrammed after a
1827 * softreset. The _enable() function should be split to avoid
1828 * the rewrite of the OCP_SYSCONFIG register.
1829 */
Rajendra Nayak28008522012-03-13 22:55:23 +05301830 if (oh->class->sysc) {
1831 _update_sysc_cache(oh);
1832 _enable_sysc(oh);
1833 }
1834
Paul Walmsley30e105c2012-04-19 00:49:09 -06001835 return r;
Paul Walmsleybd361792010-12-14 12:42:35 -07001836}
1837
1838/**
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07001839 * _omap4_update_context_lost - increment hwmod context loss counter if
1840 * hwmod context was lost, and clear hardware context loss reg
1841 * @oh: hwmod to check for context loss
1842 *
1843 * If the PRCM indicates that the hwmod @oh lost context, increment
1844 * our in-memory context loss counter, and clear the RM_*_CONTEXT
1845 * bits. No return value.
1846 */
1847static void _omap4_update_context_lost(struct omap_hwmod *oh)
1848{
1849 if (oh->prcm.omap4.flags & HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT)
1850 return;
1851
1852 if (!prm_was_any_context_lost_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1853 oh->clkdm->pwrdm.ptr->prcm_offs,
1854 oh->prcm.omap4.context_offs))
1855 return;
1856
1857 oh->prcm.omap4.context_lost_counter++;
1858 prm_clear_context_loss_flags_old(oh->clkdm->pwrdm.ptr->prcm_partition,
1859 oh->clkdm->pwrdm.ptr->prcm_offs,
1860 oh->prcm.omap4.context_offs);
1861}
1862
1863/**
1864 * _omap4_get_context_lost - get context loss counter for a hwmod
1865 * @oh: hwmod to get context loss counter for
1866 *
1867 * Returns the in-memory context loss counter for a hwmod.
1868 */
1869static int _omap4_get_context_lost(struct omap_hwmod *oh)
1870{
1871 return oh->prcm.omap4.context_lost_counter;
1872}
1873
1874/**
Paul Walmsley6d266f62013-02-10 11:22:22 -07001875 * _enable_preprogram - Pre-program an IP block during the _enable() process
1876 * @oh: struct omap_hwmod *
1877 *
1878 * Some IP blocks (such as AESS) require some additional programming
1879 * after enable before they can enter idle. If a function pointer to
1880 * do so is present in the hwmod data, then call it and pass along the
1881 * return value; otherwise, return 0.
1882 */
jean-philippe francois0f497032013-05-16 11:25:07 -07001883static int _enable_preprogram(struct omap_hwmod *oh)
Paul Walmsley6d266f62013-02-10 11:22:22 -07001884{
1885 if (!oh->class->enable_preprogram)
1886 return 0;
1887
1888 return oh->class->enable_preprogram(oh);
1889}
1890
1891/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001892 * _enable - enable an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001893 * @oh: struct omap_hwmod *
1894 *
1895 * Enables an omap_hwmod @oh such that the MPU can access the hwmod's
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001896 * register target. Returns -EINVAL if the hwmod is in the wrong
1897 * state or passes along the return value of _wait_target_ready().
Paul Walmsley63c85232009-09-03 20:14:03 +03001898 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001899static int _enable(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001900{
Paul Walmsley747834a2012-04-18 19:10:04 -06001901 int r;
Paul Walmsley63c85232009-09-03 20:14:03 +03001902
Benoit Cousson34617e22011-07-01 22:54:07 +02001903 pr_debug("omap_hwmod: %s: enabling\n", oh->name);
1904
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001905 /*
Paul Walmsley64813c32012-04-18 19:10:03 -06001906 * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled
Tony Lindgrenb4281452016-10-20 06:35:21 -07001907 * state at init.
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001908 */
1909 if (oh->_int_flags & _HWMOD_SKIP_ENABLE) {
Rajendra Nayakaacf0942011-12-16 05:50:12 -07001910 oh->_int_flags &= ~_HWMOD_SKIP_ENABLE;
1911 return 0;
1912 }
1913
Paul Walmsley63c85232009-09-03 20:14:03 +03001914 if (oh->_state != _HWMOD_STATE_INITIALIZED &&
1915 oh->_state != _HWMOD_STATE_IDLE &&
1916 oh->_state != _HWMOD_STATE_DISABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00001917 WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n",
1918 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03001919 return -EINVAL;
1920 }
1921
Benoit Cousson31f62862011-07-01 22:54:05 +02001922 /*
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001923 * If an IP block contains HW reset lines and all of them are
Paul Walmsley747834a2012-04-18 19:10:04 -06001924 * asserted, we let integration code associated with that
1925 * block handle the enable. We've received very little
1926 * information on what those driver authors need, and until
1927 * detailed information is provided and the driver code is
1928 * posted to the public lists, this is probably the best we
1929 * can do.
Benoit Cousson31f62862011-07-01 22:54:05 +02001930 */
Omar Ramirez Lunaeb05f692012-09-23 17:28:20 -06001931 if (_are_all_hardreset_lines_asserted(oh))
Paul Walmsley747834a2012-04-18 19:10:04 -06001932 return 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03001933
Rajendra Nayak665d0012011-07-10 05:57:07 -06001934 _add_initiator_dep(oh, mpu_oh);
1935
1936 if (oh->clkdm) {
1937 /*
1938 * A clockdomain must be in SW_SUP before enabling
1939 * completely the module. The clockdomain can be set
1940 * in HW_AUTO only when the module become ready.
1941 */
Tero Kristo1d9a5422016-06-30 16:15:02 +03001942 clkdm_deny_idle(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06001943 r = clkdm_hwmod_enable(oh->clkdm, oh);
1944 if (r) {
1945 WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n",
1946 oh->name, oh->clkdm->name, r);
1947 return r;
1948 }
Benoit Cousson34617e22011-07-01 22:54:07 +02001949 }
Rajendra Nayak665d0012011-07-10 05:57:07 -06001950
1951 _enable_clocks(oh);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06001952 if (soc_ops.enable_module)
1953 soc_ops.enable_module(oh);
Paul Walmsleyfa200222013-01-26 00:48:56 -07001954 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01001955 cpu_idle_poll_ctrl(true);
Benoit Cousson34617e22011-07-01 22:54:07 +02001956
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07001957 if (soc_ops.update_context_lost)
1958 soc_ops.update_context_lost(oh);
1959
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06001960 r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) :
1961 -EINVAL;
Roger Quadros8ff42da2017-03-17 10:58:18 +02001962 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
Tero Kristo1d9a5422016-06-30 16:15:02 +03001963 clkdm_allow_idle(oh->clkdm);
Benoit Cousson34617e22011-07-01 22:54:07 +02001964
Tero Kristo1d9a5422016-06-30 16:15:02 +03001965 if (!r) {
Rajendra Nayak665d0012011-07-10 05:57:07 -06001966 oh->_state = _HWMOD_STATE_ENABLED;
1967
1968 /* Access the sysconfig only if the target is ready */
1969 if (oh->class->sysc) {
1970 if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED))
1971 _update_sysc_cache(oh);
1972 _enable_sysc(oh);
1973 }
Paul Walmsley6d266f62013-02-10 11:22:22 -07001974 r = _enable_preprogram(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06001975 } else {
Paul Walmsley2577a4a2012-10-29 20:57:55 -06001976 if (soc_ops.disable_module)
1977 soc_ops.disable_module(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06001978 _disable_clocks(oh);
Lokesh Vutla812ce9d2014-12-19 18:04:50 +05301979 pr_err("omap_hwmod: %s: _wait_target_ready failed: %d\n",
1980 oh->name, r);
Rajendra Nayak665d0012011-07-10 05:57:07 -06001981
1982 if (oh->clkdm)
1983 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06001984 }
1985
Paul Walmsley63c85232009-09-03 20:14:03 +03001986 return r;
1987}
1988
1989/**
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001990 * _idle - idle an omap_hwmod
Paul Walmsley63c85232009-09-03 20:14:03 +03001991 * @oh: struct omap_hwmod *
1992 *
1993 * Idles an omap_hwmod @oh. This should be called once the hwmod has
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001994 * no further work. Returns -EINVAL if the hwmod is in the wrong
1995 * state or returns 0.
Paul Walmsley63c85232009-09-03 20:14:03 +03001996 */
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07001997static int _idle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03001998{
Lokesh Vutla2e18f5a2016-03-07 01:41:21 -07001999 if (oh->flags & HWMOD_NO_IDLE) {
2000 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
2001 return 0;
2002 }
2003
Benoit Cousson34617e22011-07-01 22:54:07 +02002004 pr_debug("omap_hwmod: %s: idling\n", oh->name);
2005
Suman Annac20c8f72016-04-10 13:20:11 -06002006 if (_are_all_hardreset_lines_asserted(oh))
2007 return 0;
2008
Paul Walmsley63c85232009-09-03 20:14:03 +03002009 if (oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002010 WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n",
2011 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002012 return -EINVAL;
2013 }
2014
Paul Walmsley43b40992010-02-22 22:09:34 -07002015 if (oh->class->sysc)
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002016 _idle_sysc(oh);
Paul Walmsley63c85232009-09-03 20:14:03 +03002017 _del_initiator_dep(oh, mpu_oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002018
Roger Quadros8ff42da2017-03-17 10:58:18 +02002019 /*
2020 * If HWMOD_CLKDM_NOAUTO is set then we don't
2021 * deny idle the clkdm again since idle was already denied
2022 * in _enable()
2023 */
2024 if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO))
Tero Kristo1d9a5422016-06-30 16:15:02 +03002025 clkdm_deny_idle(oh->clkdm);
2026
Paul Walmsleyfa200222013-01-26 00:48:56 -07002027 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01002028 cpu_idle_poll_ctrl(false);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002029 if (soc_ops.disable_module)
2030 soc_ops.disable_module(oh);
Benoit Coussonbfc141e2011-12-16 16:09:11 -08002031
Benoit Cousson45c38252011-07-10 05:56:33 -06002032 /*
2033 * The module must be in idle mode before disabling any parents
2034 * clocks. Otherwise, the parent clock might be disabled before
2035 * the module transition is done, and thus will prevent the
2036 * transition to complete properly.
2037 */
2038 _disable_clocks(oh);
Tero Kristo1d9a5422016-06-30 16:15:02 +03002039 if (oh->clkdm) {
2040 clkdm_allow_idle(oh->clkdm);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002041 clkdm_hwmod_disable(oh->clkdm, oh);
Tero Kristo1d9a5422016-06-30 16:15:02 +03002042 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002043
2044 oh->_state = _HWMOD_STATE_IDLE;
2045
2046 return 0;
2047}
2048
2049/**
2050 * _shutdown - shutdown an omap_hwmod
2051 * @oh: struct omap_hwmod *
2052 *
2053 * Shut down an omap_hwmod @oh. This should be called when the driver
2054 * used for the hwmod is removed or unloaded or if the driver is not
2055 * used by the system. Returns -EINVAL if the hwmod is in the wrong
2056 * state or returns 0.
2057 */
2058static int _shutdown(struct omap_hwmod *oh)
2059{
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002060 int ret, i;
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002061 u8 prev_state;
2062
Suman Annac20c8f72016-04-10 13:20:11 -06002063 if (_are_all_hardreset_lines_asserted(oh))
2064 return 0;
2065
Paul Walmsley63c85232009-09-03 20:14:03 +03002066 if (oh->_state != _HWMOD_STATE_IDLE &&
2067 oh->_state != _HWMOD_STATE_ENABLED) {
Russell King4f8a4282012-02-07 10:59:37 +00002068 WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n",
2069 oh->name);
Paul Walmsley63c85232009-09-03 20:14:03 +03002070 return -EINVAL;
2071 }
2072
2073 pr_debug("omap_hwmod: %s: disabling\n", oh->name);
2074
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002075 if (oh->class->pre_shutdown) {
2076 prev_state = oh->_state;
2077 if (oh->_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002078 _enable(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002079 ret = oh->class->pre_shutdown(oh);
2080 if (ret) {
2081 if (prev_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002082 _idle(oh);
Paul Walmsleye4dc8f52010-12-14 12:42:34 -07002083 return ret;
2084 }
2085 }
2086
Miguel Vadillo6481c732011-07-01 22:54:02 +02002087 if (oh->class->sysc) {
2088 if (oh->_state == _HWMOD_STATE_IDLE)
2089 _enable(oh);
Paul Walmsley74ff3a62010-09-21 15:02:23 -06002090 _shutdown_sysc(oh);
Miguel Vadillo6481c732011-07-01 22:54:02 +02002091 }
BenoƮt Cousson5365efb2010-09-21 10:34:11 -06002092
Benoit Cousson3827f942010-09-21 10:34:08 -06002093 /* clocks and deps are already disabled in idle */
2094 if (oh->_state == _HWMOD_STATE_ENABLED) {
2095 _del_initiator_dep(oh, mpu_oh);
2096 /* XXX what about the other system initiators here? dma, dsp */
Paul Walmsleyfa200222013-01-26 00:48:56 -07002097 if (oh->flags & HWMOD_BLOCK_WFI)
Thomas Gleixnerf7b861b2013-03-21 22:49:38 +01002098 cpu_idle_poll_ctrl(false);
Kevin Hilman9ebfd282012-06-18 12:12:23 -06002099 if (soc_ops.disable_module)
2100 soc_ops.disable_module(oh);
Benoit Cousson45c38252011-07-10 05:56:33 -06002101 _disable_clocks(oh);
Rajendra Nayak665d0012011-07-10 05:57:07 -06002102 if (oh->clkdm)
2103 clkdm_hwmod_disable(oh->clkdm, oh);
Benoit Cousson3827f942010-09-21 10:34:08 -06002104 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002105 /* XXX Should this code also force-disable the optional clocks? */
2106
Paul Walmsley9c8b0ec2012-04-18 19:10:02 -06002107 for (i = 0; i < oh->rst_lines_cnt; i++)
2108 _assert_hardreset(oh, oh->rst_lines[i].name);
Benoit Cousson31f62862011-07-01 22:54:05 +02002109
Paul Walmsley63c85232009-09-03 20:14:03 +03002110 oh->_state = _HWMOD_STATE_DISABLED;
2111
2112 return 0;
2113}
2114
Tony Lindgren5e863c52013-12-06 14:20:16 -08002115static int of_dev_find_hwmod(struct device_node *np,
2116 struct omap_hwmod *oh)
2117{
2118 int count, i, res;
2119 const char *p;
2120
2121 count = of_property_count_strings(np, "ti,hwmods");
2122 if (count < 1)
2123 return -ENODEV;
2124
2125 for (i = 0; i < count; i++) {
2126 res = of_property_read_string_index(np, "ti,hwmods",
2127 i, &p);
2128 if (res)
2129 continue;
2130 if (!strcmp(p, oh->name)) {
Rob Herring6e7713792018-08-28 10:44:27 -05002131 pr_debug("omap_hwmod: dt %pOFn[%i] uses hwmod %s\n",
2132 np, i, oh->name);
Tony Lindgren5e863c52013-12-06 14:20:16 -08002133 return i;
2134 }
2135 }
2136
2137 return -ENODEV;
2138}
2139
Paul Walmsley63c85232009-09-03 20:14:03 +03002140/**
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302141 * of_dev_hwmod_lookup - look up needed hwmod from dt blob
2142 * @np: struct device_node *
2143 * @oh: struct omap_hwmod *
Tony Lindgren5e863c52013-12-06 14:20:16 -08002144 * @index: index of the entry found
2145 * @found: struct device_node * found or NULL
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302146 *
2147 * Parse the dt blob and find out needed hwmod. Recursive function is
2148 * implemented to take care hierarchical dt blob parsing.
Tony Lindgren5e863c52013-12-06 14:20:16 -08002149 * Return: Returns 0 on success, -ENODEV when not found.
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302150 */
Tony Lindgren5e863c52013-12-06 14:20:16 -08002151static int of_dev_hwmod_lookup(struct device_node *np,
2152 struct omap_hwmod *oh,
2153 int *index,
2154 struct device_node **found)
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302155{
Tony Lindgren5e863c52013-12-06 14:20:16 -08002156 struct device_node *np0 = NULL;
2157 int res;
2158
2159 res = of_dev_find_hwmod(np, oh);
2160 if (res >= 0) {
2161 *found = np;
2162 *index = res;
2163 return 0;
2164 }
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302165
2166 for_each_child_of_node(np, np0) {
Tony Lindgren5e863c52013-12-06 14:20:16 -08002167 struct device_node *fc;
2168 int i;
2169
2170 res = of_dev_hwmod_lookup(np0, oh, &i, &fc);
2171 if (res == 0) {
2172 *found = fc;
2173 *index = i;
2174 return 0;
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302175 }
2176 }
Tony Lindgren5e863c52013-12-06 14:20:16 -08002177
2178 *found = NULL;
2179 *index = 0;
2180
2181 return -ENODEV;
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302182}
2183
2184/**
Tony Lindgren1dbcb972018-08-08 01:07:04 -07002185 * omap_hwmod_fix_mpu_rt_idx - fix up mpu_rt_idx register offsets
2186 *
2187 * @oh: struct omap_hwmod *
2188 * @np: struct device_node *
2189 *
2190 * Fix up module register offsets for modules with mpu_rt_idx.
2191 * Only needed for cpsw with interconnect target module defined
2192 * in device tree while still using legacy hwmod platform data
2193 * for rev, sysc and syss registers.
2194 *
2195 * Can be removed when all cpsw hwmod platform data has been
2196 * dropped.
2197 */
2198static void omap_hwmod_fix_mpu_rt_idx(struct omap_hwmod *oh,
2199 struct device_node *np,
2200 struct resource *res)
2201{
2202 struct device_node *child = NULL;
2203 int error;
2204
2205 child = of_get_next_child(np, child);
2206 if (!child)
2207 return;
2208
2209 error = of_address_to_resource(child, oh->mpu_rt_idx, res);
2210 if (error)
2211 pr_err("%s: error mapping mpu_rt_idx: %i\n",
2212 __func__, error);
2213}
2214
2215/**
Tony Lindgren6c72b352017-10-10 14:23:27 -07002216 * omap_hwmod_parse_module_range - map module IO range from device tree
2217 * @oh: struct omap_hwmod *
2218 * @np: struct device_node *
2219 *
2220 * Parse the device tree range an interconnect target module provides
2221 * for it's child device IP blocks. This way we can support the old
2222 * "ti,hwmods" property with just dts data without a need for platform
2223 * data for IO resources. And we don't need all the child IP device
2224 * nodes available in the dts.
2225 */
2226int omap_hwmod_parse_module_range(struct omap_hwmod *oh,
2227 struct device_node *np,
2228 struct resource *res)
2229{
2230 struct property *prop;
2231 const __be32 *ranges;
2232 const char *name;
2233 u32 nr_addr, nr_size;
2234 u64 base, size;
2235 int len, error;
2236
2237 if (!res)
2238 return -EINVAL;
2239
2240 ranges = of_get_property(np, "ranges", &len);
2241 if (!ranges)
2242 return -ENOENT;
2243
2244 len /= sizeof(*ranges);
2245
2246 if (len < 3)
2247 return -EINVAL;
2248
2249 of_property_for_each_string(np, "compatible", prop, name)
2250 if (!strncmp("ti,sysc-", name, 8))
2251 break;
2252
2253 if (!name)
2254 return -ENOENT;
2255
2256 error = of_property_read_u32(np, "#address-cells", &nr_addr);
2257 if (error)
2258 return -ENOENT;
2259
2260 error = of_property_read_u32(np, "#size-cells", &nr_size);
2261 if (error)
2262 return -ENOENT;
2263
2264 if (nr_addr != 1 || nr_size != 1) {
Rob Herring6e7713792018-08-28 10:44:27 -05002265 pr_err("%s: invalid range for %s->%pOFn\n", __func__,
2266 oh->name, np);
Tony Lindgren6c72b352017-10-10 14:23:27 -07002267 return -EINVAL;
2268 }
2269
2270 ranges++;
2271 base = of_translate_address(np, ranges++);
2272 size = be32_to_cpup(ranges);
2273
Rob Herring6e7713792018-08-28 10:44:27 -05002274 pr_debug("omap_hwmod: %s %pOFn at 0x%llx size 0x%llx\n",
2275 oh->name, np, base, size);
Tony Lindgren6c72b352017-10-10 14:23:27 -07002276
Tony Lindgren1dbcb972018-08-08 01:07:04 -07002277 if (oh && oh->mpu_rt_idx) {
2278 omap_hwmod_fix_mpu_rt_idx(oh, np, res);
2279
2280 return 0;
2281 }
2282
Tony Lindgren6c72b352017-10-10 14:23:27 -07002283 res->start = base;
2284 res->end = base + size - 1;
2285 res->flags = IORESOURCE_MEM;
2286
2287 return 0;
2288}
2289
2290/**
Paul Walmsley381d0332012-04-19 00:58:22 -06002291 * _init_mpu_rt_base - populate the virtual address for a hwmod
2292 * @oh: struct omap_hwmod * to locate the virtual address
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002293 * @data: (unused, caller should pass NULL)
Tony Lindgren5e863c52013-12-06 14:20:16 -08002294 * @index: index of the reg entry iospace in device tree
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002295 * @np: struct device_node * of the IP block's device node in the DT data
Paul Walmsley381d0332012-04-19 00:58:22 -06002296 *
2297 * Cache the virtual address used by the MPU to access this IP block's
2298 * registers. This address is needed early so the OCP registers that
2299 * are part of the device's address space can be ioremapped properly.
Suman Anna6423d6d2013-10-08 23:46:49 -06002300 *
Roger Quadros9a258af2015-07-16 16:16:44 +03002301 * If SYSC access is not needed, the registers will not be remapped
2302 * and non-availability of MPU access is not treated as an error.
2303 *
Suman Anna6423d6d2013-10-08 23:46:49 -06002304 * Returns 0 on success, -EINVAL if an invalid hwmod is passed, and
2305 * -ENXIO on absent or invalid register target address space.
Paul Walmsley381d0332012-04-19 00:58:22 -06002306 */
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002307static int __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data,
Tony Lindgren5e863c52013-12-06 14:20:16 -08002308 int index, struct device_node *np)
Paul Walmsley381d0332012-04-19 00:58:22 -06002309{
Santosh Shilimkar079abad2013-01-21 18:40:57 +05302310 void __iomem *va_start = NULL;
Tony Lindgren6c72b352017-10-10 14:23:27 -07002311 struct resource res;
2312 int error;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002313
2314 if (!oh)
Suman Anna6423d6d2013-10-08 23:46:49 -06002315 return -EINVAL;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002316
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002317 _save_mpu_port_index(oh);
2318
Roger Quadros9a258af2015-07-16 16:16:44 +03002319 /* if we don't need sysc access we don't need to ioremap */
2320 if (!oh->class->sysc)
2321 return 0;
2322
2323 /* we can't continue without MPU PORT if we need sysc access */
Paul Walmsley381d0332012-04-19 00:58:22 -06002324 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
Suman Anna6423d6d2013-10-08 23:46:49 -06002325 return -ENXIO;
Paul Walmsley381d0332012-04-19 00:58:22 -06002326
Tony Lindgren9cffb1a2017-10-10 14:27:33 -07002327 if (!np) {
2328 pr_err("omap_hwmod: %s: no dt node\n", oh->name);
2329 return -ENXIO;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002330 }
2331
Tony Lindgren9cffb1a2017-10-10 14:27:33 -07002332 /* Do we have a dts range for the interconnect target module? */
2333 error = omap_hwmod_parse_module_range(oh, np, &res);
2334 if (!error)
2335 va_start = ioremap(res.start, resource_size(&res));
2336
2337 /* No ranges, rely on device reg entry */
2338 if (!va_start)
2339 va_start = of_iomap(np, index + oh->mpu_rt_idx);
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002340 if (!va_start) {
Tony Lindgren9cffb1a2017-10-10 14:27:33 -07002341 pr_err("omap_hwmod: %s: Missing dt reg%i for %pOF\n",
2342 oh->name, index, np);
Suman Anna6423d6d2013-10-08 23:46:49 -06002343 return -ENXIO;
Paul Walmsleyc9aafd22012-04-18 19:10:05 -06002344 }
2345
2346 pr_debug("omap_hwmod: %s: MPU register target at va %p\n",
2347 oh->name, va_start);
2348
2349 oh->_mpu_rt_va = va_start;
Suman Anna6423d6d2013-10-08 23:46:49 -06002350 return 0;
Paul Walmsley381d0332012-04-19 00:58:22 -06002351}
2352
Tony Lindgren4f212242018-12-10 14:11:10 -08002353static void __init parse_module_flags(struct omap_hwmod *oh,
2354 struct device_node *np)
2355{
2356 if (of_find_property(np, "ti,no-reset-on-init", NULL))
2357 oh->flags |= HWMOD_INIT_NO_RESET;
2358 if (of_find_property(np, "ti,no-idle-on-init", NULL))
2359 oh->flags |= HWMOD_INIT_NO_IDLE;
2360 if (of_find_property(np, "ti,no-idle", NULL))
2361 oh->flags |= HWMOD_NO_IDLE;
2362}
2363
Paul Walmsley381d0332012-04-19 00:58:22 -06002364/**
2365 * _init - initialize internal data for the hwmod @oh
2366 * @oh: struct omap_hwmod *
2367 * @n: (unused)
2368 *
2369 * Look up the clocks and the address space used by the MPU to access
2370 * registers belonging to the hwmod @oh. @oh must already be
2371 * registered at this point. This is the first of two phases for
2372 * hwmod initialization. Code called here does not touch any hardware
2373 * registers, it simply prepares internal data structures. Returns 0
Suman Anna6423d6d2013-10-08 23:46:49 -06002374 * upon success or if the hwmod isn't registered or if the hwmod's
2375 * address space is not defined, or -EINVAL upon failure.
Paul Walmsley381d0332012-04-19 00:58:22 -06002376 */
2377static int __init _init(struct omap_hwmod *oh, void *data)
2378{
Tony Lindgren5e863c52013-12-06 14:20:16 -08002379 int r, index;
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002380 struct device_node *np = NULL;
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002381 struct device_node *bus;
Paul Walmsley381d0332012-04-19 00:58:22 -06002382
2383 if (oh->_state != _HWMOD_STATE_REGISTERED)
2384 return 0;
2385
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002386 bus = of_find_node_by_name(NULL, "ocp");
2387 if (!bus)
2388 return -ENODEV;
Tony Lindgren5e863c52013-12-06 14:20:16 -08002389
Tony Lindgren1aa8f0c2017-05-31 15:51:37 -07002390 r = of_dev_hwmod_lookup(bus, oh, &index, &np);
2391 if (r)
2392 pr_debug("omap_hwmod: %s missing dt data\n", oh->name);
2393 else if (np && index)
Rob Herring6e7713792018-08-28 10:44:27 -05002394 pr_warn("omap_hwmod: %s using broken dt data from %pOFn\n",
2395 oh->name, np);
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002396
Roger Quadros9a258af2015-07-16 16:16:44 +03002397 r = _init_mpu_rt_base(oh, NULL, index, np);
2398 if (r < 0) {
2399 WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n",
2400 oh->name);
2401 return 0;
Suman Anna6423d6d2013-10-08 23:46:49 -06002402 }
Paul Walmsley381d0332012-04-19 00:58:22 -06002403
Tero Kristo70f05be2017-05-31 18:00:03 +03002404 r = _init_clocks(oh, np);
Russell Kingc48cd652013-03-13 20:44:21 +00002405 if (r < 0) {
Paul Walmsley381d0332012-04-19 00:58:22 -06002406 WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name);
2407 return -EINVAL;
2408 }
2409
Suman Anna3d36ad72014-03-14 14:45:17 +05302410 if (np) {
Tony Lindgren4f212242018-12-10 14:11:10 -08002411 struct device_node *child;
2412
2413 parse_module_flags(oh, np);
2414 child = of_get_next_child(np, NULL);
2415 if (child)
2416 parse_module_flags(oh, child);
Suman Anna3d36ad72014-03-14 14:45:17 +05302417 }
Rajendra Nayakf92d9592013-10-09 01:26:55 -06002418
Paul Walmsley381d0332012-04-19 00:58:22 -06002419 oh->_state = _HWMOD_STATE_INITIALIZED;
2420
2421 return 0;
2422}
2423
2424/**
Paul Walmsley64813c32012-04-18 19:10:03 -06002425 * _setup_iclk_autoidle - configure an IP block's interface clocks
Paul Walmsley63c85232009-09-03 20:14:03 +03002426 * @oh: struct omap_hwmod *
2427 *
Paul Walmsley64813c32012-04-18 19:10:03 -06002428 * Set up the module's interface clocks. XXX This function is still mostly
2429 * a stub; implementing this properly requires iclk autoidle usecounting in
2430 * the clock code. No return value.
Paul Walmsley63c85232009-09-03 20:14:03 +03002431 */
Nathan Chancellorc10b26a2018-10-17 17:52:07 -07002432static void _setup_iclk_autoidle(struct omap_hwmod *oh)
Paul Walmsley63c85232009-09-03 20:14:03 +03002433{
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002434 struct omap_hwmod_ocp_if *os;
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07002435
Paul Walmsley381d0332012-04-19 00:58:22 -06002436 if (oh->_state != _HWMOD_STATE_INITIALIZED)
Paul Walmsley64813c32012-04-18 19:10:03 -06002437 return;
Paul Walmsley48d54f32011-02-23 00:14:07 -07002438
Tony Lindgrenb8e1bdd2017-03-14 13:13:19 -07002439 list_for_each_entry(os, &oh->slave_ports, node) {
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002440 if (!os->_clk)
Paul Walmsley64813c32012-04-18 19:10:03 -06002441 continue;
Paul Walmsley63c85232009-09-03 20:14:03 +03002442
Paul Walmsley64813c32012-04-18 19:10:03 -06002443 if (os->flags & OCPIF_SWSUP_IDLE) {
Andreas Kemnade12af39c2019-01-16 23:04:29 +01002444 /*
2445 * we might have multiple users of one iclk with
2446 * different requirements, disable autoidle when
2447 * the module is enabled, e.g. dss iclk
2448 */
Paul Walmsley64813c32012-04-18 19:10:03 -06002449 } else {
Andreas Kemnade12af39c2019-01-16 23:04:29 +01002450 /* we are enabling autoidle afterwards anyways */
Paul Walmsley5d95dde2012-04-19 04:04:28 -06002451 clk_enable(os->_clk);
Paul Walmsley63c85232009-09-03 20:14:03 +03002452 }
2453 }
2454
Paul Walmsley64813c32012-04-18 19:10:03 -06002455 return;
2456}
2457
2458/**
2459 * _setup_reset - reset an IP block during the setup process
2460 * @oh: struct omap_hwmod *
2461 *
2462 * Reset the IP block corresponding to the hwmod @oh during the setup
2463 * process. The IP block is first enabled so it can be successfully
2464 * reset. Returns 0 upon success or a negative error code upon
2465 * failure.
2466 */
Nathan Chancellorc10b26a2018-10-17 17:52:07 -07002467static int _setup_reset(struct omap_hwmod *oh)
Paul Walmsley64813c32012-04-18 19:10:03 -06002468{
Tony Lindgren7f0d0782019-03-21 11:00:21 -07002469 int r = 0;
Paul Walmsley64813c32012-04-18 19:10:03 -06002470
2471 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2472 return -EINVAL;
Paul Walmsley63c85232009-09-03 20:14:03 +03002473
Paul Walmsley5fb3d522012-10-29 22:11:50 -06002474 if (oh->flags & HWMOD_EXT_OPT_MAIN_CLK)
2475 return -EPERM;
2476
Paul Walmsley747834a2012-04-18 19:10:04 -06002477 if (oh->rst_lines_cnt == 0) {
2478 r = _enable(oh);
2479 if (r) {
Joe Perches3d0cb732014-09-13 11:31:16 -07002480 pr_warn("omap_hwmod: %s: cannot be enabled for reset (%d)\n",
2481 oh->name, oh->_state);
Paul Walmsley747834a2012-04-18 19:10:04 -06002482 return -EINVAL;
2483 }
Benoit Cousson9a23dfe2010-05-20 12:31:08 -06002484 }
Paul Walmsley63c85232009-09-03 20:14:03 +03002485
Rajendra Nayak28008522012-03-13 22:55:23 +05302486 if (!(oh->flags & HWMOD_INIT_NO_RESET))
Paul Walmsley64813c32012-04-18 19:10:03 -06002487 r = _reset(oh);
2488
2489 return r;
2490}
2491
2492/**
2493 * _setup_postsetup - transition to the appropriate state after _setup
2494 * @oh: struct omap_hwmod *
2495 *
2496 * Place an IP block represented by @oh into a "post-setup" state --
2497 * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that
2498 * this function is called at the end of _setup().) The postsetup
2499 * state for an IP block can be changed by calling
2500 * omap_hwmod_enter_postsetup_state() early in the boot process,
2501 * before one of the omap_hwmod_setup*() functions are called for the
2502 * IP block.
2503 *
2504 * The IP block stays in this state until a PM runtime-based driver is
2505 * loaded for that IP block. A post-setup state of IDLE is
2506 * appropriate for almost all IP blocks with runtime PM-enabled
2507 * drivers, since those drivers are able to enable the IP block. A
2508 * post-setup state of ENABLED is appropriate for kernels with PM
2509 * runtime disabled. The DISABLED state is appropriate for unusual IP
2510 * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers
2511 * included, since the WDTIMER starts running on reset and will reset
2512 * the MPU if left active.
2513 *
2514 * This post-setup mechanism is deprecated. Once all of the OMAP
2515 * drivers have been converted to use PM runtime, and all of the IP
2516 * block data and interconnect data is available to the hwmod code, it
2517 * should be possible to replace this mechanism with a "lazy reset"
2518 * arrangement. In a "lazy reset" setup, each IP block is enabled
2519 * when the driver first probes, then all remaining IP blocks without
2520 * drivers are either shut down or enabled after the drivers have
2521 * loaded. However, this cannot take place until the above
2522 * preconditions have been met, since otherwise the late reset code
2523 * has no way of knowing which IP blocks are in use by drivers, and
2524 * which ones are unused.
2525 *
2526 * No return value.
2527 */
Nathan Chancellorc10b26a2018-10-17 17:52:07 -07002528static void _setup_postsetup(struct omap_hwmod *oh)
Paul Walmsley64813c32012-04-18 19:10:03 -06002529{
2530 u8 postsetup_state;
2531
2532 if (oh->rst_lines_cnt > 0)
2533 return;
Benoit Cousson76e55892010-09-21 10:34:11 -06002534
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002535 postsetup_state = oh->_postsetup_state;
2536 if (postsetup_state == _HWMOD_STATE_UNKNOWN)
2537 postsetup_state = _HWMOD_STATE_ENABLED;
2538
2539 /*
2540 * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data -
2541 * it should be set by the core code as a runtime flag during startup
2542 */
Lokesh Vutla2e18f5a2016-03-07 01:41:21 -07002543 if ((oh->flags & (HWMOD_INIT_NO_IDLE | HWMOD_NO_IDLE)) &&
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002544 (postsetup_state == _HWMOD_STATE_IDLE)) {
2545 oh->_int_flags |= _HWMOD_SKIP_ENABLE;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002546 postsetup_state = _HWMOD_STATE_ENABLED;
Rajendra Nayakaacf0942011-12-16 05:50:12 -07002547 }
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002548
2549 if (postsetup_state == _HWMOD_STATE_IDLE)
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07002550 _idle(oh);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07002551 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2552 _shutdown(oh);
2553 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2554 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2555 oh->name, postsetup_state);
Paul Walmsley63c85232009-09-03 20:14:03 +03002556
Paul Walmsley64813c32012-04-18 19:10:03 -06002557 return;
2558}
2559
2560/**
2561 * _setup - prepare IP block hardware for use
2562 * @oh: struct omap_hwmod *
2563 * @n: (unused, pass NULL)
2564 *
2565 * Configure the IP block represented by @oh. This may include
2566 * enabling the IP block, resetting it, and placing it into a
2567 * post-setup state, depending on the type of IP block and applicable
2568 * flags. IP blocks are reset to prevent any previous configuration
2569 * by the bootloader or previous operating system from interfering
2570 * with power management or other parts of the system. The reset can
2571 * be avoided; see omap_hwmod_no_setup_reset(). This is the second of
2572 * two phases for hwmod initialization. Code called here generally
2573 * affects the IP block hardware, or system integration hardware
2574 * associated with the IP block. Returns 0.
2575 */
Tony Lindgren8c879702018-02-22 14:04:56 -08002576static int _setup(struct omap_hwmod *oh, void *data)
Paul Walmsley64813c32012-04-18 19:10:03 -06002577{
2578 if (oh->_state != _HWMOD_STATE_INITIALIZED)
2579 return 0;
2580
Tomi Valkeinenf22d2542014-10-09 17:03:14 +03002581 if (oh->parent_hwmod) {
2582 int r;
2583
2584 r = _enable(oh->parent_hwmod);
2585 WARN(r, "hwmod: %s: setup: failed to enable parent hwmod %s\n",
2586 oh->name, oh->parent_hwmod->name);
2587 }
2588
Paul Walmsley64813c32012-04-18 19:10:03 -06002589 _setup_iclk_autoidle(oh);
2590
2591 if (!_setup_reset(oh))
2592 _setup_postsetup(oh);
2593
Tomi Valkeinenf22d2542014-10-09 17:03:14 +03002594 if (oh->parent_hwmod) {
2595 u8 postsetup_state;
2596
2597 postsetup_state = oh->parent_hwmod->_postsetup_state;
2598
2599 if (postsetup_state == _HWMOD_STATE_IDLE)
2600 _idle(oh->parent_hwmod);
2601 else if (postsetup_state == _HWMOD_STATE_DISABLED)
2602 _shutdown(oh->parent_hwmod);
2603 else if (postsetup_state != _HWMOD_STATE_ENABLED)
2604 WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n",
2605 oh->parent_hwmod->name, postsetup_state);
2606 }
2607
Paul Walmsley63c85232009-09-03 20:14:03 +03002608 return 0;
2609}
2610
Benoit Cousson0102b622010-12-21 21:31:27 -07002611/**
2612 * _register - register a struct omap_hwmod
2613 * @oh: struct omap_hwmod *
2614 *
2615 * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod
2616 * already has been registered by the same name; -EINVAL if the
2617 * omap_hwmod is in the wrong state, if @oh is NULL, if the
2618 * omap_hwmod's class field is NULL; if the omap_hwmod is missing a
2619 * name, or if the omap_hwmod's class is missing a name; or 0 upon
2620 * success.
2621 *
2622 * XXX The data should be copied into bootmem, so the original data
2623 * should be marked __initdata and freed after init. This would allow
2624 * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note
2625 * that the copy process would be relatively complex due to the large number
2626 * of substructures.
2627 */
Tony Lindgrenb57250f2019-03-21 11:00:21 -07002628static int _register(struct omap_hwmod *oh)
Benoit Cousson0102b622010-12-21 21:31:27 -07002629{
Benoit Cousson0102b622010-12-21 21:31:27 -07002630 if (!oh || !oh->name || !oh->class || !oh->class->name ||
2631 (oh->_state != _HWMOD_STATE_UNKNOWN))
2632 return -EINVAL;
2633
Benoit Cousson0102b622010-12-21 21:31:27 -07002634 pr_debug("omap_hwmod: %s: registering\n", oh->name);
2635
Benoit Coussonce35b242010-12-21 21:31:28 -07002636 if (_lookup(oh->name))
2637 return -EEXIST;
Benoit Cousson0102b622010-12-21 21:31:27 -07002638
Benoit Cousson0102b622010-12-21 21:31:27 -07002639 list_add_tail(&oh->node, &omap_hwmod_list);
2640
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002641 INIT_LIST_HEAD(&oh->slave_ports);
Benoit Cousson0102b622010-12-21 21:31:27 -07002642 spin_lock_init(&oh->_lock);
Peter Ujfalusi69317952015-02-26 00:00:51 -07002643 lockdep_set_class(&oh->_lock, &oh->hwmod_key);
Benoit Cousson0102b622010-12-21 21:31:27 -07002644
2645 oh->_state = _HWMOD_STATE_REGISTERED;
2646
Paul Walmsley569edd702011-02-23 00:14:06 -07002647 /*
2648 * XXX Rather than doing a strcmp(), this should test a flag
2649 * set in the hwmod data, inserted by the autogenerator code.
2650 */
2651 if (!strcmp(oh->name, MPU_INITIATOR_NAME))
2652 mpu_oh = oh;
Benoit Cousson0102b622010-12-21 21:31:27 -07002653
Paul Walmsley569edd702011-02-23 00:14:06 -07002654 return 0;
Benoit Cousson0102b622010-12-21 21:31:27 -07002655}
Paul Walmsley63c85232009-09-03 20:14:03 +03002656
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002657/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002658 * _add_link - add an interconnect between two IP blocks
2659 * @oi: pointer to a struct omap_hwmod_ocp_if record
2660 *
Tony Lindgrena1e31232017-03-14 13:13:19 -07002661 * Add struct omap_hwmod_link records connecting the slave IP block
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002662 * specified in @oi->slave to @oi. This code is assumed to run before
2663 * preemption or SMP has been enabled, thus avoiding the need for
2664 * locking in this code. Changes to this assumption will require
2665 * additional locking. Returns 0.
2666 */
Tony Lindgrenb57250f2019-03-21 11:00:21 -07002667static int _add_link(struct omap_hwmod_ocp_if *oi)
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002668{
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002669 pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name,
2670 oi->slave->name);
2671
Tony Lindgrena1e31232017-03-14 13:13:19 -07002672 list_add(&oi->node, &oi->slave->slave_ports);
Paul Walmsley2221b5c2012-04-19 04:04:30 -06002673 oi->slave->slaves_cnt++;
2674
2675 return 0;
2676}
2677
2678/**
2679 * _register_link - register a struct omap_hwmod_ocp_if
2680 * @oi: struct omap_hwmod_ocp_if *
2681 *
2682 * Registers the omap_hwmod_ocp_if record @oi. Returns -EEXIST if it
2683 * has already been registered; -EINVAL if @oi is NULL or if the
2684 * record pointed to by @oi is missing required fields; or 0 upon
2685 * success.
2686 *
2687 * XXX The data should be copied into bootmem, so the original data
2688 * should be marked __initdata and freed after init. This would allow
2689 * unneeded omap_hwmods to be freed on multi-OMAP configurations.
2690 */
2691static int __init _register_link(struct omap_hwmod_ocp_if *oi)
2692{
2693 if (!oi || !oi->master || !oi->slave || !oi->user)
2694 return -EINVAL;
2695
2696 if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED)
2697 return -EEXIST;
2698
2699 pr_debug("omap_hwmod: registering link from %s to %s\n",
2700 oi->master->name, oi->slave->name);
2701
2702 /*
2703 * Register the connected hwmods, if they haven't been
2704 * registered already
2705 */
2706 if (oi->master->_state != _HWMOD_STATE_REGISTERED)
2707 _register(oi->master);
2708
2709 if (oi->slave->_state != _HWMOD_STATE_REGISTERED)
2710 _register(oi->slave);
2711
2712 _add_link(oi);
2713
2714 oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED;
2715
2716 return 0;
2717}
2718
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002719/* Static functions intended only for use in soc_ops field function pointers */
2720
2721/**
Tero Kristo9002e9212014-10-27 08:39:23 -07002722 * _omap2xxx_3xxx_wait_target_ready - wait for a module to leave slave idle
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002723 * @oh: struct omap_hwmod *
2724 *
2725 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2726 * does not have an IDLEST bit or if the module successfully leaves
2727 * slave idle; otherwise, pass along the return value of the
2728 * appropriate *_cm*_wait_module_ready() function.
2729 */
Tero Kristo9002e9212014-10-27 08:39:23 -07002730static int _omap2xxx_3xxx_wait_target_ready(struct omap_hwmod *oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002731{
2732 if (!oh)
2733 return -EINVAL;
2734
2735 if (oh->flags & HWMOD_NO_IDLEST)
2736 return 0;
2737
2738 if (!_find_mpu_rt_port(oh))
2739 return 0;
2740
2741 /* XXX check module SIDLEMODE, hardreset status, enabled clocks */
2742
Tero Kristo021b6ff2014-10-27 08:39:23 -07002743 return omap_cm_wait_module_ready(0, oh->prcm.omap2.module_offs,
2744 oh->prcm.omap2.idlest_reg_id,
2745 oh->prcm.omap2.idlest_idle_bit);
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002746}
2747
2748/**
2749 * _omap4_wait_target_ready - wait for a module to leave slave idle
2750 * @oh: struct omap_hwmod *
2751 *
2752 * Wait for a module @oh to leave slave idle. Returns 0 if the module
2753 * does not have an IDLEST bit or if the module successfully leaves
2754 * slave idle; otherwise, pass along the return value of the
2755 * appropriate *_cm*_wait_module_ready() function.
2756 */
2757static int _omap4_wait_target_ready(struct omap_hwmod *oh)
2758{
Paul Walmsley2b026d12012-09-23 17:28:18 -06002759 if (!oh)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002760 return -EINVAL;
2761
Paul Walmsley2b026d12012-09-23 17:28:18 -06002762 if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm)
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002763 return 0;
2764
2765 if (!_find_mpu_rt_port(oh))
2766 return 0;
2767
Tony Lindgren8823ddf2017-08-29 10:03:33 -07002768 if (_omap4_clkctrl_managed_by_clkfwk(oh))
2769 return 0;
2770
2771 if (!_omap4_has_clkctrl_clock(oh))
Dave Gerlach428929c2016-07-12 12:50:33 -05002772 return 0;
2773
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06002774 /* XXX check module SIDLEMODE, hardreset status */
2775
Tero Kristo021b6ff2014-10-27 08:39:23 -07002776 return omap_cm_wait_module_ready(oh->clkdm->prcm_partition,
2777 oh->clkdm->cm_inst,
2778 oh->prcm.omap4.clkctrl_offs, 0);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002779}
2780
2781/**
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002782 * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2783 * @oh: struct omap_hwmod * to assert hardreset
2784 * @ohri: hardreset line data
2785 *
2786 * Call omap2_prm_assert_hardreset() with parameters extracted from
2787 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2788 * use as an soc_ops function pointer. Passes along the return value
2789 * from omap2_prm_assert_hardreset(). XXX This function is scheduled
2790 * for removal when the PRM code is moved into drivers/.
2791 */
2792static int _omap2_assert_hardreset(struct omap_hwmod *oh,
2793 struct omap_hwmod_rst_info *ohri)
2794{
Tero Kristoefd44dc2014-10-27 08:39:24 -07002795 return omap_prm_assert_hardreset(ohri->rst_shift, 0,
2796 oh->prcm.omap2.module_offs, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002797}
2798
2799/**
2800 * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args
2801 * @oh: struct omap_hwmod * to deassert hardreset
2802 * @ohri: hardreset line data
2803 *
2804 * Call omap2_prm_deassert_hardreset() with parameters extracted from
2805 * the hwmod @oh and the hardreset line data @ohri. Only intended for
2806 * use as an soc_ops function pointer. Passes along the return value
2807 * from omap2_prm_deassert_hardreset(). XXX This function is
2808 * scheduled for removal when the PRM code is moved into drivers/.
2809 */
2810static int _omap2_deassert_hardreset(struct omap_hwmod *oh,
2811 struct omap_hwmod_rst_info *ohri)
2812{
Tero Kristo37fb59d2014-10-27 08:39:25 -07002813 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0,
2814 oh->prcm.omap2.module_offs, 0, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002815}
2816
2817/**
2818 * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args
2819 * @oh: struct omap_hwmod * to test hardreset
2820 * @ohri: hardreset line data
2821 *
2822 * Call omap2_prm_is_hardreset_asserted() with parameters extracted
2823 * from the hwmod @oh and the hardreset line data @ohri. Only
2824 * intended for use as an soc_ops function pointer. Passes along the
2825 * return value from omap2_prm_is_hardreset_asserted(). XXX This
2826 * function is scheduled for removal when the PRM code is moved into
2827 * drivers/.
2828 */
2829static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh,
2830 struct omap_hwmod_rst_info *ohri)
2831{
Tero Kristo1bc28b32014-10-27 08:39:25 -07002832 return omap_prm_is_hardreset_asserted(ohri->st_shift, 0,
2833 oh->prcm.omap2.module_offs, 0);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002834}
2835
2836/**
2837 * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2838 * @oh: struct omap_hwmod * to assert hardreset
2839 * @ohri: hardreset line data
2840 *
2841 * Call omap4_prminst_assert_hardreset() with parameters extracted
2842 * from the hwmod @oh and the hardreset line data @ohri. Only
2843 * intended for use as an soc_ops function pointer. Passes along the
2844 * return value from omap4_prminst_assert_hardreset(). XXX This
2845 * function is scheduled for removal when the PRM code is moved into
2846 * drivers/.
2847 */
2848static int _omap4_assert_hardreset(struct omap_hwmod *oh,
2849 struct omap_hwmod_rst_info *ohri)
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002850{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002851 if (!oh->clkdm)
2852 return -EINVAL;
2853
Tero Kristoefd44dc2014-10-27 08:39:24 -07002854 return omap_prm_assert_hardreset(ohri->rst_shift,
2855 oh->clkdm->pwrdm.ptr->prcm_partition,
2856 oh->clkdm->pwrdm.ptr->prcm_offs,
2857 oh->prcm.omap4.rstctrl_offs);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002858}
2859
2860/**
2861 * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args
2862 * @oh: struct omap_hwmod * to deassert hardreset
2863 * @ohri: hardreset line data
2864 *
2865 * Call omap4_prminst_deassert_hardreset() with parameters extracted
2866 * from the hwmod @oh and the hardreset line data @ohri. Only
2867 * intended for use as an soc_ops function pointer. Passes along the
2868 * return value from omap4_prminst_deassert_hardreset(). XXX This
2869 * function is scheduled for removal when the PRM code is moved into
2870 * drivers/.
2871 */
2872static int _omap4_deassert_hardreset(struct omap_hwmod *oh,
2873 struct omap_hwmod_rst_info *ohri)
2874{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002875 if (!oh->clkdm)
2876 return -EINVAL;
2877
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002878 if (ohri->st_shift)
2879 pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n",
2880 oh->name, ohri->name);
Tero Kristo4ebf5b22015-05-05 16:33:04 +03002881 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift,
Tero Kristo37fb59d2014-10-27 08:39:25 -07002882 oh->clkdm->pwrdm.ptr->prcm_partition,
2883 oh->clkdm->pwrdm.ptr->prcm_offs,
Tero Kristo4ebf5b22015-05-05 16:33:04 +03002884 oh->prcm.omap4.rstctrl_offs,
2885 oh->prcm.omap4.rstctrl_offs +
2886 OMAP4_RST_CTRL_ST_OFFSET);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002887}
2888
2889/**
2890 * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args
2891 * @oh: struct omap_hwmod * to test hardreset
2892 * @ohri: hardreset line data
2893 *
2894 * Call omap4_prminst_is_hardreset_asserted() with parameters
2895 * extracted from the hwmod @oh and the hardreset line data @ohri.
2896 * Only intended for use as an soc_ops function pointer. Passes along
2897 * the return value from omap4_prminst_is_hardreset_asserted(). XXX
2898 * This function is scheduled for removal when the PRM code is moved
2899 * into drivers/.
2900 */
2901static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
2902 struct omap_hwmod_rst_info *ohri)
2903{
Paul Walmsley07b3a132012-06-20 20:11:36 -06002904 if (!oh->clkdm)
2905 return -EINVAL;
2906
Tero Kristo1bc28b32014-10-27 08:39:25 -07002907 return omap_prm_is_hardreset_asserted(ohri->rst_shift,
2908 oh->clkdm->pwrdm.ptr->
2909 prcm_partition,
2910 oh->clkdm->pwrdm.ptr->prcm_offs,
2911 oh->prcm.omap4.rstctrl_offs);
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06002912}
2913
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002914/**
Tero Kristo9fabc1a2016-07-04 14:11:48 +03002915 * _omap4_disable_direct_prcm - disable direct PRCM control for hwmod
2916 * @oh: struct omap_hwmod * to disable control for
2917 *
2918 * Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod
2919 * will be using its main_clk to enable/disable the module. Returns
2920 * 0 if successful.
2921 */
2922static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
2923{
2924 if (!oh)
2925 return -EINVAL;
2926
Tony Lindgren8823ddf2017-08-29 10:03:33 -07002927 oh->prcm.omap4.flags |= HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK;
Tero Kristo9fabc1a2016-07-04 14:11:48 +03002928
2929 return 0;
2930}
2931
2932/**
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002933 * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
2934 * @oh: struct omap_hwmod * to deassert hardreset
2935 * @ohri: hardreset line data
2936 *
2937 * Call am33xx_prminst_deassert_hardreset() with parameters extracted
2938 * from the hwmod @oh and the hardreset line data @ohri. Only
2939 * intended for use as an soc_ops function pointer. Passes along the
2940 * return value from am33xx_prminst_deassert_hardreset(). XXX This
2941 * function is scheduled for removal when the PRM code is moved into
2942 * drivers/.
2943 */
2944static int _am33xx_deassert_hardreset(struct omap_hwmod *oh,
2945 struct omap_hwmod_rst_info *ohri)
2946{
Tero Kristoa5bf00c2015-05-05 16:33:05 +03002947 return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift,
2948 oh->clkdm->pwrdm.ptr->prcm_partition,
Tero Kristo37fb59d2014-10-27 08:39:25 -07002949 oh->clkdm->pwrdm.ptr->prcm_offs,
2950 oh->prcm.omap4.rstctrl_offs,
2951 oh->prcm.omap4.rstst_offs);
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06002952}
2953
Paul Walmsley63c85232009-09-03 20:14:03 +03002954/* Public functions */
2955
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002956u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002957{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002958 if (oh->flags & HWMOD_16BIT_REG)
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002959 return readw_relaxed(oh->_mpu_rt_va + reg_offs);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002960 else
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002961 return readl_relaxed(oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002962}
2963
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002964void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs)
Paul Walmsley63c85232009-09-03 20:14:03 +03002965{
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002966 if (oh->flags & HWMOD_16BIT_REG)
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002967 writew_relaxed(v, oh->_mpu_rt_va + reg_offs);
Rajendra Nayakcc7a1d22010-10-08 10:23:22 -07002968 else
Victor Kamenskyedfaf052014-04-15 20:37:46 +03002969 writel_relaxed(v, oh->_mpu_rt_va + reg_offs);
Paul Walmsley63c85232009-09-03 20:14:03 +03002970}
2971
Paul Walmsley887adea2010-07-26 16:34:33 -06002972/**
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002973 * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit
2974 * @oh: struct omap_hwmod *
2975 *
2976 * This is a public function exposed to drivers. Some drivers may need to do
2977 * some settings before and after resetting the device. Those drivers after
2978 * doing the necessary settings could use this function to start a reset by
2979 * setting the SYSCONFIG.SOFTRESET bit.
2980 */
2981int omap_hwmod_softreset(struct omap_hwmod *oh)
2982{
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06002983 u32 v;
2984 int ret;
2985
2986 if (!oh || !(oh->_sysc_cache))
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06002987 return -EINVAL;
2988
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06002989 v = oh->_sysc_cache;
2990 ret = _set_softreset(oh, &v);
2991 if (ret)
2992 goto error;
2993 _write_sysconfig(v, oh);
2994
Roger Quadros313a76e2013-12-08 18:39:02 -07002995 ret = _clear_softreset(oh, &v);
2996 if (ret)
2997 goto error;
2998 _write_sysconfig(v, oh);
2999
Paul Walmsley3c55c1b2012-04-13 05:08:43 -06003000error:
3001 return ret;
Avinash.H.M6d3c55f2011-07-10 05:27:16 -06003002}
3003
3004/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003005 * omap_hwmod_lookup - look up a registered omap_hwmod by name
3006 * @name: name of the omap_hwmod to look up
3007 *
3008 * Given a @name of an omap_hwmod, return a pointer to the registered
3009 * struct omap_hwmod *, or NULL upon error.
3010 */
3011struct omap_hwmod *omap_hwmod_lookup(const char *name)
3012{
3013 struct omap_hwmod *oh;
3014
3015 if (!name)
3016 return NULL;
3017
Paul Walmsley63c85232009-09-03 20:14:03 +03003018 oh = _lookup(name);
Paul Walmsley63c85232009-09-03 20:14:03 +03003019
3020 return oh;
3021}
3022
3023/**
3024 * omap_hwmod_for_each - call function for each registered omap_hwmod
3025 * @fn: pointer to a callback function
Paul Walmsley97d60162010-07-26 16:34:30 -06003026 * @data: void * data to pass to callback function
Paul Walmsley63c85232009-09-03 20:14:03 +03003027 *
3028 * Call @fn for each registered omap_hwmod, passing @data to each
3029 * function. @fn must return 0 for success or any other value for
3030 * failure. If @fn returns non-zero, the iteration across omap_hwmods
3031 * will stop and the non-zero return value will be passed to the
3032 * caller of omap_hwmod_for_each(). @fn is called with
3033 * omap_hwmod_for_each() held.
3034 */
Paul Walmsley97d60162010-07-26 16:34:30 -06003035int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data),
3036 void *data)
Paul Walmsley63c85232009-09-03 20:14:03 +03003037{
3038 struct omap_hwmod *temp_oh;
Govindraj.R30ebad92011-06-01 11:28:56 +05303039 int ret = 0;
Paul Walmsley63c85232009-09-03 20:14:03 +03003040
3041 if (!fn)
3042 return -EINVAL;
3043
Paul Walmsley63c85232009-09-03 20:14:03 +03003044 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
Paul Walmsley97d60162010-07-26 16:34:30 -06003045 ret = (*fn)(temp_oh, data);
Paul Walmsley63c85232009-09-03 20:14:03 +03003046 if (ret)
3047 break;
3048 }
Paul Walmsley63c85232009-09-03 20:14:03 +03003049
3050 return ret;
3051}
3052
Paul Walmsley63c85232009-09-03 20:14:03 +03003053/**
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003054 * omap_hwmod_register_links - register an array of hwmod links
3055 * @ois: pointer to an array of omap_hwmod_ocp_if to register
3056 *
3057 * Intended to be called early in boot before the clock framework is
3058 * initialized. If @ois is not null, will register all omap_hwmods
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003059 * listed in @ois that are valid for this chip. Returns -EINVAL if
3060 * omap_hwmod_init() hasn't been called before calling this function,
3061 * -ENOMEM if the link memory area can't be allocated, or 0 upon
3062 * success.
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003063 */
3064int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois)
3065{
3066 int r, i;
3067
Kevin Hilman9ebfd282012-06-18 12:12:23 -06003068 if (!inited)
3069 return -EINVAL;
3070
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003071 if (!ois)
3072 return 0;
3073
Rajendra Nayakf7f7a292014-08-27 19:38:23 -06003074 if (ois[0] == NULL) /* Empty list */
3075 return 0;
3076
Paul Walmsley2221b5c2012-04-19 04:04:30 -06003077 i = 0;
3078 do {
3079 r = _register_link(ois[i]);
3080 WARN(r && r != -EEXIST,
3081 "omap_hwmod: _register_link(%s -> %s) returned %d\n",
3082 ois[i]->master->name, ois[i]->slave->name, r);
3083 } while (ois[++i]);
3084
3085 return 0;
3086}
3087
3088/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003089 * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up
3090 * @oh: pointer to the hwmod currently being set up (usually not the MPU)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003091 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003092 * If the hwmod data corresponding to the MPU subsystem IP block
3093 * hasn't been initialized and set up yet, do so now. This must be
3094 * done first since sleep dependencies may be added from other hwmods
3095 * to the MPU. Intended to be called only by omap_hwmod_setup*(). No
3096 * return value.
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003097 */
Paul Walmsley381d0332012-04-19 00:58:22 -06003098static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh)
Tony Lindgrene7c7d762011-02-14 15:40:21 -08003099{
Paul Walmsley381d0332012-04-19 00:58:22 -06003100 if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN)
3101 pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n",
3102 __func__, MPU_INITIATOR_NAME);
3103 else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh)
3104 omap_hwmod_setup_one(MPU_INITIATOR_NAME);
Paul Walmsley63c85232009-09-03 20:14:03 +03003105}
3106
3107/**
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003108 * omap_hwmod_setup_one - set up a single hwmod
3109 * @oh_name: const char * name of the already-registered hwmod to set up
3110 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003111 * Initialize and set up a single hwmod. Intended to be used for a
3112 * small number of early devices, such as the timer IP blocks used for
3113 * the scheduler clock. Must be called after omap2_clk_init().
3114 * Resolves the struct clk names to struct clk pointers for each
3115 * registered omap_hwmod. Also calls _setup() on each hwmod. Returns
3116 * -EINVAL upon error or 0 upon success.
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003117 */
3118int __init omap_hwmod_setup_one(const char *oh_name)
3119{
3120 struct omap_hwmod *oh;
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003121
3122 pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__);
3123
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003124 oh = _lookup(oh_name);
3125 if (!oh) {
3126 WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name);
3127 return -EINVAL;
3128 }
3129
Paul Walmsley381d0332012-04-19 00:58:22 -06003130 _ensure_mpu_hwmod_is_setup(oh);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003131
Paul Walmsley381d0332012-04-19 00:58:22 -06003132 _init(oh, NULL);
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003133 _setup(oh, NULL);
3134
3135 return 0;
3136}
3137
Tony Lindgrena8844302018-02-23 08:59:23 -08003138static void omap_hwmod_check_one(struct device *dev,
3139 const char *name, s8 v1, u8 v2)
3140{
3141 if (v1 < 0)
3142 return;
3143
3144 if (v1 != v2)
3145 dev_warn(dev, "%s %d != %d\n", name, v1, v2);
3146}
3147
3148/**
3149 * omap_hwmod_check_sysc - check sysc against platform sysc
3150 * @dev: struct device
3151 * @data: module data
3152 * @sysc_fields: new sysc configuration
3153 */
3154static int omap_hwmod_check_sysc(struct device *dev,
3155 const struct ti_sysc_module_data *data,
3156 struct sysc_regbits *sysc_fields)
3157{
3158 const struct sysc_regbits *regbits = data->cap->regbits;
3159
3160 omap_hwmod_check_one(dev, "dmadisable_shift",
3161 regbits->dmadisable_shift,
3162 sysc_fields->dmadisable_shift);
3163 omap_hwmod_check_one(dev, "midle_shift",
3164 regbits->midle_shift,
3165 sysc_fields->midle_shift);
3166 omap_hwmod_check_one(dev, "sidle_shift",
3167 regbits->sidle_shift,
3168 sysc_fields->sidle_shift);
3169 omap_hwmod_check_one(dev, "clkact_shift",
3170 regbits->clkact_shift,
3171 sysc_fields->clkact_shift);
3172 omap_hwmod_check_one(dev, "enwkup_shift",
3173 regbits->enwkup_shift,
3174 sysc_fields->enwkup_shift);
3175 omap_hwmod_check_one(dev, "srst_shift",
3176 regbits->srst_shift,
3177 sysc_fields->srst_shift);
3178 omap_hwmod_check_one(dev, "autoidle_shift",
3179 regbits->autoidle_shift,
3180 sysc_fields->autoidle_shift);
3181
3182 return 0;
3183}
3184
Paul Walmsleya2debdb2011-02-23 00:14:07 -07003185/**
Tony Lindgren8c879702018-02-22 14:04:56 -08003186 * omap_hwmod_init_regbits - init sysconfig specific register bits
3187 * @dev: struct device
3188 * @data: module data
3189 * @sysc_fields: new sysc configuration
3190 */
3191static int omap_hwmod_init_regbits(struct device *dev,
3192 const struct ti_sysc_module_data *data,
3193 struct sysc_regbits **sysc_fields)
3194{
3195 *sysc_fields = NULL;
3196
3197 switch (data->cap->type) {
3198 case TI_SYSC_OMAP2:
3199 case TI_SYSC_OMAP2_TIMER:
3200 *sysc_fields = &omap_hwmod_sysc_type1;
3201 break;
3202 case TI_SYSC_OMAP3_SHAM:
3203 *sysc_fields = &omap3_sham_sysc_fields;
3204 break;
3205 case TI_SYSC_OMAP3_AES:
3206 *sysc_fields = &omap3xxx_aes_sysc_fields;
3207 break;
3208 case TI_SYSC_OMAP4:
3209 case TI_SYSC_OMAP4_TIMER:
3210 *sysc_fields = &omap_hwmod_sysc_type2;
3211 break;
3212 case TI_SYSC_OMAP4_SIMPLE:
3213 *sysc_fields = &omap_hwmod_sysc_type3;
3214 break;
3215 case TI_SYSC_OMAP34XX_SR:
3216 *sysc_fields = &omap34xx_sr_sysc_fields;
3217 break;
3218 case TI_SYSC_OMAP36XX_SR:
3219 *sysc_fields = &omap36xx_sr_sysc_fields;
3220 break;
3221 case TI_SYSC_OMAP4_SR:
3222 *sysc_fields = &omap36xx_sr_sysc_fields;
3223 break;
3224 case TI_SYSC_OMAP4_MCASP:
3225 *sysc_fields = &omap_hwmod_sysc_type_mcasp;
3226 break;
3227 case TI_SYSC_OMAP4_USB_HOST_FS:
3228 *sysc_fields = &omap_hwmod_sysc_type_usb_host_fs;
3229 break;
3230 default:
3231 return -EINVAL;
3232 }
3233
Tony Lindgrena8844302018-02-23 08:59:23 -08003234 return omap_hwmod_check_sysc(dev, data, *sysc_fields);
Tony Lindgren8c879702018-02-22 14:04:56 -08003235}
3236
3237/**
3238 * omap_hwmod_init_reg_offs - initialize sysconfig register offsets
3239 * @dev: struct device
3240 * @data: module data
3241 * @rev_offs: revision register offset
3242 * @sysc_offs: sysc register offset
3243 * @syss_offs: syss register offset
3244 */
Tony Lindgren798bd172019-03-21 11:00:21 -07003245static int omap_hwmod_init_reg_offs(struct device *dev,
3246 const struct ti_sysc_module_data *data,
3247 s32 *rev_offs, s32 *sysc_offs,
3248 s32 *syss_offs)
Tony Lindgren8c879702018-02-22 14:04:56 -08003249{
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003250 *rev_offs = -ENODEV;
Tony Lindgren8c879702018-02-22 14:04:56 -08003251 *sysc_offs = 0;
3252 *syss_offs = 0;
3253
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003254 if (data->offsets[SYSC_REVISION] >= 0)
Tony Lindgren8c879702018-02-22 14:04:56 -08003255 *rev_offs = data->offsets[SYSC_REVISION];
3256
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003257 if (data->offsets[SYSC_SYSCONFIG] >= 0)
Tony Lindgren8c879702018-02-22 14:04:56 -08003258 *sysc_offs = data->offsets[SYSC_SYSCONFIG];
3259
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003260 if (data->offsets[SYSC_SYSSTATUS] >= 0)
Tony Lindgren8c879702018-02-22 14:04:56 -08003261 *syss_offs = data->offsets[SYSC_SYSSTATUS];
3262
3263 return 0;
3264}
3265
3266/**
3267 * omap_hwmod_init_sysc_flags - initialize sysconfig features
3268 * @dev: struct device
3269 * @data: module data
3270 * @sysc_flags: module configuration
3271 */
Tony Lindgren798bd172019-03-21 11:00:21 -07003272static int omap_hwmod_init_sysc_flags(struct device *dev,
3273 const struct ti_sysc_module_data *data,
3274 u32 *sysc_flags)
Tony Lindgren8c879702018-02-22 14:04:56 -08003275{
3276 *sysc_flags = 0;
3277
3278 switch (data->cap->type) {
3279 case TI_SYSC_OMAP2:
3280 case TI_SYSC_OMAP2_TIMER:
3281 /* See SYSC_OMAP2_* in include/dt-bindings/bus/ti-sysc.h */
3282 if (data->cfg->sysc_val & SYSC_OMAP2_CLOCKACTIVITY)
3283 *sysc_flags |= SYSC_HAS_CLOCKACTIVITY;
3284 if (data->cfg->sysc_val & SYSC_OMAP2_EMUFREE)
3285 *sysc_flags |= SYSC_HAS_EMUFREE;
3286 if (data->cfg->sysc_val & SYSC_OMAP2_ENAWAKEUP)
3287 *sysc_flags |= SYSC_HAS_ENAWAKEUP;
3288 if (data->cfg->sysc_val & SYSC_OMAP2_SOFTRESET)
3289 *sysc_flags |= SYSC_HAS_SOFTRESET;
3290 if (data->cfg->sysc_val & SYSC_OMAP2_AUTOIDLE)
3291 *sysc_flags |= SYSC_HAS_AUTOIDLE;
3292 break;
3293 case TI_SYSC_OMAP4:
3294 case TI_SYSC_OMAP4_TIMER:
3295 /* See SYSC_OMAP4_* in include/dt-bindings/bus/ti-sysc.h */
3296 if (data->cfg->sysc_val & SYSC_OMAP4_DMADISABLE)
3297 *sysc_flags |= SYSC_HAS_DMADISABLE;
3298 if (data->cfg->sysc_val & SYSC_OMAP4_FREEEMU)
3299 *sysc_flags |= SYSC_HAS_EMUFREE;
3300 if (data->cfg->sysc_val & SYSC_OMAP4_SOFTRESET)
3301 *sysc_flags |= SYSC_HAS_SOFTRESET;
3302 break;
3303 case TI_SYSC_OMAP34XX_SR:
3304 case TI_SYSC_OMAP36XX_SR:
3305 /* See SYSC_OMAP3_SR_* in include/dt-bindings/bus/ti-sysc.h */
3306 if (data->cfg->sysc_val & SYSC_OMAP3_SR_ENAWAKEUP)
3307 *sysc_flags |= SYSC_HAS_ENAWAKEUP;
3308 break;
3309 default:
3310 if (data->cap->regbits->emufree_shift >= 0)
3311 *sysc_flags |= SYSC_HAS_EMUFREE;
3312 if (data->cap->regbits->enwkup_shift >= 0)
3313 *sysc_flags |= SYSC_HAS_ENAWAKEUP;
3314 if (data->cap->regbits->srst_shift >= 0)
3315 *sysc_flags |= SYSC_HAS_SOFTRESET;
3316 if (data->cap->regbits->autoidle_shift >= 0)
3317 *sysc_flags |= SYSC_HAS_AUTOIDLE;
3318 break;
3319 }
3320
3321 if (data->cap->regbits->midle_shift >= 0 &&
3322 data->cfg->midlemodes)
3323 *sysc_flags |= SYSC_HAS_MIDLEMODE;
3324
3325 if (data->cap->regbits->sidle_shift >= 0 &&
3326 data->cfg->sidlemodes)
3327 *sysc_flags |= SYSC_HAS_SIDLEMODE;
3328
3329 if (data->cfg->quirks & SYSC_QUIRK_UNCACHED)
3330 *sysc_flags |= SYSC_NO_CACHE;
3331 if (data->cfg->quirks & SYSC_QUIRK_RESET_STATUS)
3332 *sysc_flags |= SYSC_HAS_RESET_STATUS;
3333
3334 if (data->cfg->syss_mask & 1)
3335 *sysc_flags |= SYSS_HAS_RESET_STATUS;
3336
3337 return 0;
3338}
3339
3340/**
3341 * omap_hwmod_init_idlemodes - initialize module idle modes
3342 * @dev: struct device
3343 * @data: module data
3344 * @idlemodes: module supported idle modes
3345 */
Tony Lindgren798bd172019-03-21 11:00:21 -07003346static int omap_hwmod_init_idlemodes(struct device *dev,
3347 const struct ti_sysc_module_data *data,
3348 u32 *idlemodes)
Tony Lindgren8c879702018-02-22 14:04:56 -08003349{
3350 *idlemodes = 0;
3351
3352 if (data->cfg->midlemodes & BIT(SYSC_IDLE_FORCE))
3353 *idlemodes |= MSTANDBY_FORCE;
3354 if (data->cfg->midlemodes & BIT(SYSC_IDLE_NO))
3355 *idlemodes |= MSTANDBY_NO;
3356 if (data->cfg->midlemodes & BIT(SYSC_IDLE_SMART))
3357 *idlemodes |= MSTANDBY_SMART;
3358 if (data->cfg->midlemodes & BIT(SYSC_IDLE_SMART_WKUP))
3359 *idlemodes |= MSTANDBY_SMART_WKUP;
3360
3361 if (data->cfg->sidlemodes & BIT(SYSC_IDLE_FORCE))
3362 *idlemodes |= SIDLE_FORCE;
3363 if (data->cfg->sidlemodes & BIT(SYSC_IDLE_NO))
3364 *idlemodes |= SIDLE_NO;
3365 if (data->cfg->sidlemodes & BIT(SYSC_IDLE_SMART))
3366 *idlemodes |= SIDLE_SMART;
3367 if (data->cfg->sidlemodes & BIT(SYSC_IDLE_SMART_WKUP))
3368 *idlemodes |= SIDLE_SMART_WKUP;
3369
3370 return 0;
3371}
3372
3373/**
Tony Lindgrena8844302018-02-23 08:59:23 -08003374 * omap_hwmod_check_module - check new module against platform data
3375 * @dev: struct device
3376 * @oh: module
3377 * @data: new module data
3378 * @sysc_fields: sysc register bits
3379 * @rev_offs: revision register offset
3380 * @sysc_offs: sysconfig register offset
3381 * @syss_offs: sysstatus register offset
3382 * @sysc_flags: sysc specific flags
3383 * @idlemodes: sysc supported idlemodes
3384 */
3385static int omap_hwmod_check_module(struct device *dev,
3386 struct omap_hwmod *oh,
3387 const struct ti_sysc_module_data *data,
3388 struct sysc_regbits *sysc_fields,
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003389 s32 rev_offs, s32 sysc_offs,
3390 s32 syss_offs, u32 sysc_flags,
Tony Lindgrena8844302018-02-23 08:59:23 -08003391 u32 idlemodes)
3392{
3393 if (!oh->class->sysc)
3394 return -ENODEV;
3395
3396 if (sysc_fields != oh->class->sysc->sysc_fields)
3397 dev_warn(dev, "sysc_fields %p != %p\n", sysc_fields,
3398 oh->class->sysc->sysc_fields);
3399
3400 if (rev_offs != oh->class->sysc->rev_offs)
3401 dev_warn(dev, "rev_offs %08x != %08x\n", rev_offs,
3402 oh->class->sysc->rev_offs);
3403 if (sysc_offs != oh->class->sysc->sysc_offs)
3404 dev_warn(dev, "sysc_offs %08x != %08x\n", sysc_offs,
3405 oh->class->sysc->sysc_offs);
3406 if (syss_offs != oh->class->sysc->syss_offs)
3407 dev_warn(dev, "syss_offs %08x != %08x\n", syss_offs,
3408 oh->class->sysc->syss_offs);
3409
3410 if (sysc_flags != oh->class->sysc->sysc_flags)
3411 dev_warn(dev, "sysc_flags %08x != %08x\n", sysc_flags,
3412 oh->class->sysc->sysc_flags);
3413
3414 if (idlemodes != oh->class->sysc->idlemodes)
3415 dev_warn(dev, "idlemodes %08x != %08x\n", idlemodes,
3416 oh->class->sysc->idlemodes);
3417
3418 if (data->cfg->srst_udelay != oh->class->sysc->srst_udelay)
3419 dev_warn(dev, "srst_udelay %i != %i\n",
3420 data->cfg->srst_udelay,
3421 oh->class->sysc->srst_udelay);
3422
3423 return 0;
3424}
3425
3426/**
Tony Lindgren8c879702018-02-22 14:04:56 -08003427 * omap_hwmod_allocate_module - allocate new module
3428 * @dev: struct device
3429 * @oh: module
3430 * @sysc_fields: sysc register bits
3431 * @rev_offs: revision register offset
3432 * @sysc_offs: sysconfig register offset
3433 * @syss_offs: sysstatus register offset
3434 * @sysc_flags: sysc specific flags
3435 * @idlemodes: sysc supported idlemodes
3436 *
3437 * Note that the allocations here cannot use devm as ti-sysc can rebind.
3438 */
Tony Lindgren798bd172019-03-21 11:00:21 -07003439static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh,
3440 const struct ti_sysc_module_data *data,
3441 struct sysc_regbits *sysc_fields,
3442 s32 rev_offs, s32 sysc_offs,
3443 s32 syss_offs, u32 sysc_flags,
3444 u32 idlemodes)
Tony Lindgren8c879702018-02-22 14:04:56 -08003445{
3446 struct omap_hwmod_class_sysconfig *sysc;
Tony Lindgren513a4ab2019-03-21 11:00:21 -07003447 struct omap_hwmod_class *class = NULL;
Tony Lindgrenb57250f2019-03-21 11:00:21 -07003448 struct omap_hwmod_ocp_if *oi = NULL;
3449 struct clockdomain *clkdm = NULL;
3450 struct clk *clk = NULL;
Tony Lindgren8c879702018-02-22 14:04:56 -08003451 void __iomem *regs = NULL;
3452 unsigned long flags;
3453
3454 sysc = kzalloc(sizeof(*sysc), GFP_KERNEL);
3455 if (!sysc)
3456 return -ENOMEM;
3457
3458 sysc->sysc_fields = sysc_fields;
3459 sysc->rev_offs = rev_offs;
3460 sysc->sysc_offs = sysc_offs;
3461 sysc->syss_offs = syss_offs;
3462 sysc->sysc_flags = sysc_flags;
3463 sysc->idlemodes = idlemodes;
3464 sysc->srst_udelay = data->cfg->srst_udelay;
3465
3466 if (!oh->_mpu_rt_va) {
3467 regs = ioremap(data->module_pa,
3468 data->module_size);
3469 if (!regs)
3470 return -ENOMEM;
3471 }
3472
3473 /*
Tony Lindgren513a4ab2019-03-21 11:00:21 -07003474 * We may need a new oh->class as the other devices in the same class
Tony Lindgren8c879702018-02-22 14:04:56 -08003475 * may not yet have ioremapped their registers.
3476 */
Tony Lindgren513a4ab2019-03-21 11:00:21 -07003477 if (oh->class->name && strcmp(oh->class->name, data->name)) {
3478 class = kmemdup(oh->class, sizeof(*oh->class), GFP_KERNEL);
3479 if (!class)
3480 return -ENOMEM;
3481 }
Tony Lindgren8c879702018-02-22 14:04:56 -08003482
Tony Lindgrenb57250f2019-03-21 11:00:21 -07003483 if (list_empty(&oh->slave_ports)) {
3484 oi = kcalloc(1, sizeof(*oi), GFP_KERNEL);
3485 if (!oi)
3486 return -ENOMEM;
3487
3488 /*
3489 * Note that we assume interconnect interface clocks will be
3490 * managed by the interconnect driver for OCPIF_SWSUP_IDLE case
3491 * on omap24xx and omap3.
3492 */
3493 oi->slave = oh;
3494 oi->user = OCP_USER_MPU | OCP_USER_SDMA;
3495 }
3496
3497 if (!oh->_clk) {
3498 struct clk_hw_omap *hwclk;
3499
3500 clk = of_clk_get_by_name(dev->of_node, "fck");
3501 if (!IS_ERR(clk))
3502 clk_prepare(clk);
3503 else
3504 clk = NULL;
3505
3506 /*
3507 * Populate clockdomain based on dts clock. It is needed for
3508 * clkdm_deny_idle() and clkdm_allow_idle() until we have have
3509 * interconnect driver and reset driver capable of blocking
3510 * clockdomain idle during reset, enable and idle.
3511 */
3512 if (clk) {
3513 hwclk = to_clk_hw_omap(__clk_get_hw(clk));
3514 if (hwclk && hwclk->clkdm_name)
3515 clkdm = clkdm_lookup(hwclk->clkdm_name);
3516 }
3517
3518 /*
3519 * Note that we assume interconnect driver manages the clocks
3520 * and do not need to populate oh->_clk for dynamically
3521 * allocated modules.
3522 */
3523 clk_unprepare(clk);
3524 clk_put(clk);
3525 }
3526
Tony Lindgren8c879702018-02-22 14:04:56 -08003527 spin_lock_irqsave(&oh->_lock, flags);
3528 if (regs)
3529 oh->_mpu_rt_va = regs;
Tony Lindgren513a4ab2019-03-21 11:00:21 -07003530 if (class)
3531 oh->class = class;
3532 oh->class->sysc = sysc;
Tony Lindgrenb57250f2019-03-21 11:00:21 -07003533 if (oi)
3534 _add_link(oi);
3535 if (clkdm)
3536 oh->clkdm = clkdm;
Tony Lindgren8c879702018-02-22 14:04:56 -08003537 oh->_state = _HWMOD_STATE_INITIALIZED;
Tony Lindgrenb57250f2019-03-21 11:00:21 -07003538 oh->_postsetup_state = _HWMOD_STATE_DEFAULT;
Tony Lindgren8c879702018-02-22 14:04:56 -08003539 _setup(oh, NULL);
3540 spin_unlock_irqrestore(&oh->_lock, flags);
3541
3542 return 0;
3543}
3544
3545/**
3546 * omap_hwmod_init_module - initialize new module
3547 * @dev: struct device
3548 * @data: module data
3549 * @cookie: cookie for the caller to use for later calls
3550 */
3551int omap_hwmod_init_module(struct device *dev,
3552 const struct ti_sysc_module_data *data,
3553 struct ti_sysc_cookie *cookie)
3554{
3555 struct omap_hwmod *oh;
3556 struct sysc_regbits *sysc_fields;
Tony Lindgren103fd8e2018-04-16 10:21:15 -07003557 s32 rev_offs, sysc_offs, syss_offs;
3558 u32 sysc_flags, idlemodes;
Tony Lindgren8c879702018-02-22 14:04:56 -08003559 int error;
3560
3561 if (!dev || !data)
3562 return -EINVAL;
3563
3564 oh = _lookup(data->name);
Tony Lindgrenb57250f2019-03-21 11:00:21 -07003565 if (!oh) {
3566 oh = kzalloc(sizeof(*oh), GFP_KERNEL);
3567 if (!oh)
3568 return -ENOMEM;
3569
3570 oh->name = data->name;
3571 oh->_state = _HWMOD_STATE_UNKNOWN;
3572 lockdep_register_key(&oh->hwmod_key);
3573
3574 /* Unused, can be handled by PRM driver handling resets */
3575 oh->prcm.omap4.flags = HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT;
3576
3577 oh->class = kzalloc(sizeof(*oh->class), GFP_KERNEL);
3578 if (!oh->class) {
3579 kfree(oh);
3580 return -ENOMEM;
3581 }
3582
3583 oh->class->name = data->name;
3584 mutex_lock(&list_lock);
3585 error = _register(oh);
3586 mutex_unlock(&list_lock);
3587 }
Tony Lindgren8c879702018-02-22 14:04:56 -08003588
3589 cookie->data = oh;
3590
3591 error = omap_hwmod_init_regbits(dev, data, &sysc_fields);
3592 if (error)
3593 return error;
3594
3595 error = omap_hwmod_init_reg_offs(dev, data, &rev_offs,
3596 &sysc_offs, &syss_offs);
3597 if (error)
3598 return error;
3599
3600 error = omap_hwmod_init_sysc_flags(dev, data, &sysc_flags);
3601 if (error)
3602 return error;
3603
3604 error = omap_hwmod_init_idlemodes(dev, data, &idlemodes);
3605 if (error)
3606 return error;
3607
3608 if (data->cfg->quirks & SYSC_QUIRK_NO_IDLE_ON_INIT)
3609 oh->flags |= HWMOD_INIT_NO_IDLE;
3610 if (data->cfg->quirks & SYSC_QUIRK_NO_RESET_ON_INIT)
3611 oh->flags |= HWMOD_INIT_NO_RESET;
3612
Tony Lindgrena8844302018-02-23 08:59:23 -08003613 error = omap_hwmod_check_module(dev, oh, data, sysc_fields,
3614 rev_offs, sysc_offs, syss_offs,
3615 sysc_flags, idlemodes);
3616 if (!error)
3617 return error;
Tony Lindgren8c879702018-02-22 14:04:56 -08003618
3619 return omap_hwmod_allocate_module(dev, oh, data, sysc_fields,
3620 rev_offs, sysc_offs, syss_offs,
3621 sysc_flags, idlemodes);
3622}
3623
Paul Walmsley63c85232009-09-03 20:14:03 +03003624/**
Lokesh Vutla8dd66662017-01-20 10:39:10 -08003625 * omap_hwmod_setup_earlycon_flags - set up flags for early console
3626 *
3627 * Enable DEBUG_OMAPUART_FLAGS for uart hwmod that is being used as
3628 * early concole so that hwmod core doesn't reset and keep it in idle
3629 * that specific uart.
3630 */
3631#ifdef CONFIG_SERIAL_EARLYCON
3632static void __init omap_hwmod_setup_earlycon_flags(void)
3633{
3634 struct device_node *np;
3635 struct omap_hwmod *oh;
3636 const char *uart;
3637
3638 np = of_find_node_by_path("/chosen");
3639 if (np) {
3640 uart = of_get_property(np, "stdout-path", NULL);
3641 if (uart) {
3642 np = of_find_node_by_path(uart);
3643 if (np) {
3644 uart = of_get_property(np, "ti,hwmods", NULL);
3645 oh = omap_hwmod_lookup(uart);
Tony Lindgren15618252018-02-22 14:04:25 -08003646 if (!oh) {
3647 uart = of_get_property(np->parent,
3648 "ti,hwmods",
3649 NULL);
3650 oh = omap_hwmod_lookup(uart);
3651 }
Lokesh Vutla8dd66662017-01-20 10:39:10 -08003652 if (oh)
3653 oh->flags |= DEBUG_OMAPUART_FLAGS;
3654 }
3655 }
3656 }
3657}
3658#endif
3659
3660/**
Paul Walmsley381d0332012-04-19 00:58:22 -06003661 * omap_hwmod_setup_all - set up all registered IP blocks
Paul Walmsley63c85232009-09-03 20:14:03 +03003662 *
Paul Walmsley381d0332012-04-19 00:58:22 -06003663 * Initialize and set up all IP blocks registered with the hwmod code.
3664 * Must be called after omap2_clk_init(). Resolves the struct clk
3665 * names to struct clk pointers for each registered omap_hwmod. Also
3666 * calls _setup() on each hwmod. Returns 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003667 */
Paul Walmsley550c8092011-02-28 11:58:14 -07003668static int __init omap_hwmod_setup_all(void)
Paul Walmsley63c85232009-09-03 20:14:03 +03003669{
Paul Walmsley381d0332012-04-19 00:58:22 -06003670 _ensure_mpu_hwmod_is_setup(NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003671
Paul Walmsley381d0332012-04-19 00:58:22 -06003672 omap_hwmod_for_each(_init, NULL);
Lokesh Vutla8dd66662017-01-20 10:39:10 -08003673#ifdef CONFIG_SERIAL_EARLYCON
3674 omap_hwmod_setup_earlycon_flags();
3675#endif
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003676 omap_hwmod_for_each(_setup, NULL);
Paul Walmsley63c85232009-09-03 20:14:03 +03003677
3678 return 0;
3679}
Tony Lindgren8dd5ea72015-12-03 11:38:09 -08003680omap_postcore_initcall(omap_hwmod_setup_all);
Paul Walmsley63c85232009-09-03 20:14:03 +03003681
3682/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003683 * omap_hwmod_enable - enable an omap_hwmod
3684 * @oh: struct omap_hwmod *
3685 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003686 * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable().
Paul Walmsley63c85232009-09-03 20:14:03 +03003687 * Returns -EINVAL on error or passes along the return value from _enable().
3688 */
3689int omap_hwmod_enable(struct omap_hwmod *oh)
3690{
3691 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003692 unsigned long flags;
Paul Walmsley63c85232009-09-03 20:14:03 +03003693
3694 if (!oh)
3695 return -EINVAL;
3696
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003697 spin_lock_irqsave(&oh->_lock, flags);
3698 r = _enable(oh);
3699 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003700
3701 return r;
3702}
3703
3704/**
3705 * omap_hwmod_idle - idle an omap_hwmod
3706 * @oh: struct omap_hwmod *
3707 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003708 * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle().
Paul Walmsley63c85232009-09-03 20:14:03 +03003709 * Returns -EINVAL on error or passes along the return value from _idle().
3710 */
3711int omap_hwmod_idle(struct omap_hwmod *oh)
3712{
Pali RohƔr6da23352015-02-26 14:49:51 +01003713 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003714 unsigned long flags;
3715
Paul Walmsley63c85232009-09-03 20:14:03 +03003716 if (!oh)
3717 return -EINVAL;
3718
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003719 spin_lock_irqsave(&oh->_lock, flags);
Pali RohƔr6da23352015-02-26 14:49:51 +01003720 r = _idle(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003721 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003722
Pali RohƔr6da23352015-02-26 14:49:51 +01003723 return r;
Paul Walmsley63c85232009-09-03 20:14:03 +03003724}
3725
3726/**
3727 * omap_hwmod_shutdown - shutdown an omap_hwmod
3728 * @oh: struct omap_hwmod *
3729 *
Paul Walmsley74ff3a62010-09-21 15:02:23 -06003730 * Shutdown an omap_hwmod @oh. Intended to be called by
Paul Walmsley63c85232009-09-03 20:14:03 +03003731 * omap_device_shutdown(). Returns -EINVAL on error or passes along
3732 * the return value from _shutdown().
3733 */
3734int omap_hwmod_shutdown(struct omap_hwmod *oh)
3735{
Pali RohƔr6da23352015-02-26 14:49:51 +01003736 int r;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003737 unsigned long flags;
3738
Paul Walmsley63c85232009-09-03 20:14:03 +03003739 if (!oh)
3740 return -EINVAL;
3741
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003742 spin_lock_irqsave(&oh->_lock, flags);
Pali RohƔr6da23352015-02-26 14:49:51 +01003743 r = _shutdown(oh);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003744 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003745
Pali RohƔr6da23352015-02-26 14:49:51 +01003746 return r;
Paul Walmsley63c85232009-09-03 20:14:03 +03003747}
3748
Paul Walmsley5e8370f2012-04-18 19:10:06 -06003749/*
3750 * IP block data retrieval functions
3751 */
3752
Paul Walmsley63c85232009-09-03 20:14:03 +03003753/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003754 * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain
3755 * @oh: struct omap_hwmod *
3756 *
3757 * Return the powerdomain pointer associated with the OMAP module
3758 * @oh's main clock. If @oh does not have a main clk, return the
3759 * powerdomain associated with the interface clock associated with the
3760 * module's MPU port. (XXX Perhaps this should use the SDMA port
3761 * instead?) Returns NULL on error, or a struct powerdomain * on
3762 * success.
3763 */
3764struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh)
3765{
3766 struct clk *c;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003767 struct omap_hwmod_ocp_if *oi;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003768 struct clockdomain *clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003769 struct clk_hw_omap *clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003770
3771 if (!oh)
3772 return NULL;
3773
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003774 if (oh->clkdm)
3775 return oh->clkdm->pwrdm.ptr;
3776
Paul Walmsley63c85232009-09-03 20:14:03 +03003777 if (oh->_clk) {
3778 c = oh->_clk;
3779 } else {
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003780 oi = _find_mpu_rt_port(oh);
3781 if (!oi)
Paul Walmsley63c85232009-09-03 20:14:03 +03003782 return NULL;
Paul Walmsley2d6141b2012-04-19 04:04:27 -06003783 c = oi->_clk;
Paul Walmsley63c85232009-09-03 20:14:03 +03003784 }
3785
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003786 clk = to_clk_hw_omap(__clk_get_hw(c));
3787 clkdm = clk->clkdm;
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003788 if (!clkdm)
Thara Gopinathd5647c12010-03-31 04:16:29 -06003789 return NULL;
3790
Rajendra Nayakf5dd3bb2012-11-10 16:58:41 -07003791 return clkdm->pwrdm.ptr;
Paul Walmsley63c85232009-09-03 20:14:03 +03003792}
3793
3794/**
Paul Walmsleydb2a60b2010-07-26 16:34:33 -06003795 * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU)
3796 * @oh: struct omap_hwmod *
3797 *
3798 * Returns the virtual address corresponding to the beginning of the
3799 * module's register target, in the address range that is intended to
3800 * be used by the MPU. Returns the virtual address upon success or NULL
3801 * upon error.
3802 */
3803void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh)
3804{
3805 if (!oh)
3806 return NULL;
3807
3808 if (oh->_int_flags & _HWMOD_NO_MPU_PORT)
3809 return NULL;
3810
3811 if (oh->_state == _HWMOD_STATE_UNKNOWN)
3812 return NULL;
3813
3814 return oh->_mpu_rt_va;
3815}
3816
Paul Walmsley63c85232009-09-03 20:14:03 +03003817/*
3818 * XXX what about functions for drivers to save/restore ocp_sysconfig
3819 * for context save/restore operations?
3820 */
3821
3822/**
Paul Walmsley63c85232009-09-03 20:14:03 +03003823 * omap_hwmod_enable_wakeup - allow device to wake up the system
3824 * @oh: struct omap_hwmod *
3825 *
3826 * Sets the module OCP socket ENAWAKEUP bit to allow the module to
Govindraj.R2a1cc142012-04-05 02:59:32 -06003827 * send wakeups to the PRCM, and enable I/O ring wakeup events for
3828 * this IP block if it has dynamic mux entries. Eventually this
3829 * should set PRCM wakeup registers to cause the PRCM to receive
3830 * wakeup events from the module. Does not set any wakeup routing
3831 * registers beyond this point - if the module is to wake up any other
3832 * module or subsystem, that must be set separately. Called by
3833 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003834 */
3835int omap_hwmod_enable_wakeup(struct omap_hwmod *oh)
3836{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003837 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003838 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003839
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003840 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003841
3842 if (oh->class->sysc &&
3843 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3844 v = oh->_sysc_cache;
3845 _enable_wakeup(oh, &v);
3846 _write_sysconfig(v, oh);
3847 }
3848
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003849 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003850
3851 return 0;
3852}
3853
3854/**
3855 * omap_hwmod_disable_wakeup - prevent device from waking the system
3856 * @oh: struct omap_hwmod *
3857 *
3858 * Clears the module OCP socket ENAWAKEUP bit to prevent the module
Govindraj.R2a1cc142012-04-05 02:59:32 -06003859 * from sending wakeups to the PRCM, and disable I/O ring wakeup
3860 * events for this IP block if it has dynamic mux entries. Eventually
3861 * this should clear PRCM wakeup registers to cause the PRCM to ignore
3862 * wakeup events from the module. Does not set any wakeup routing
3863 * registers beyond this point - if the module is to wake up any other
3864 * module or subsystem, that must be set separately. Called by
3865 * omap_device code. Returns -EINVAL on error or 0 upon success.
Paul Walmsley63c85232009-09-03 20:14:03 +03003866 */
3867int omap_hwmod_disable_wakeup(struct omap_hwmod *oh)
3868{
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003869 unsigned long flags;
Kevin Hilman5a7ddcb2010-12-21 21:08:34 -07003870 u32 v;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003871
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003872 spin_lock_irqsave(&oh->_lock, flags);
Govindraj.R2a1cc142012-04-05 02:59:32 -06003873
3874 if (oh->class->sysc &&
3875 (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) {
3876 v = oh->_sysc_cache;
3877 _disable_wakeup(oh, &v);
3878 _write_sysconfig(v, oh);
3879 }
3880
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003881 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley63c85232009-09-03 20:14:03 +03003882
3883 return 0;
3884}
Paul Walmsley43b40992010-02-22 22:09:34 -07003885
3886/**
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003887 * omap_hwmod_assert_hardreset - assert the HW reset line of submodules
3888 * contained in the hwmod module.
3889 * @oh: struct omap_hwmod *
3890 * @name: name of the reset line to lookup and assert
3891 *
3892 * Some IP like dsp, ipu or iva contain processor that require
3893 * an HW reset line to be assert / deassert in order to enable fully
3894 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3895 * yet supported on this OMAP; otherwise, passes along the return value
3896 * from _assert_hardreset().
3897 */
3898int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name)
3899{
3900 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003901 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003902
3903 if (!oh)
3904 return -EINVAL;
3905
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003906 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003907 ret = _assert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003908 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003909
3910 return ret;
3911}
3912
3913/**
3914 * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules
3915 * contained in the hwmod module.
3916 * @oh: struct omap_hwmod *
3917 * @name: name of the reset line to look up and deassert
3918 *
3919 * Some IP like dsp, ipu or iva contain processor that require
3920 * an HW reset line to be assert / deassert in order to enable fully
3921 * the IP. Returns -EINVAL if @oh is null or if the operation is not
3922 * yet supported on this OMAP; otherwise, passes along the return value
3923 * from _deassert_hardreset().
3924 */
3925int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name)
3926{
3927 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003928 unsigned long flags;
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003929
3930 if (!oh)
3931 return -EINVAL;
3932
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003933 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003934 ret = _deassert_hardreset(oh, name);
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003935 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsleyaee48e32010-09-21 10:34:11 -06003936
3937 return ret;
3938}
3939
3940/**
Paul Walmsley43b40992010-02-22 22:09:34 -07003941 * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname
3942 * @classname: struct omap_hwmod_class name to search for
3943 * @fn: callback function pointer to call for each hwmod in class @classname
3944 * @user: arbitrary context data to pass to the callback function
3945 *
Benoit Coussonce35b242010-12-21 21:31:28 -07003946 * For each omap_hwmod of class @classname, call @fn.
3947 * If the callback function returns something other than
Paul Walmsley43b40992010-02-22 22:09:34 -07003948 * zero, the iterator is terminated, and the callback function's return
3949 * value is passed back to the caller. Returns 0 upon success, -EINVAL
3950 * if @classname or @fn are NULL, or passes back the error code from @fn.
3951 */
3952int omap_hwmod_for_each_by_class(const char *classname,
3953 int (*fn)(struct omap_hwmod *oh,
3954 void *user),
3955 void *user)
3956{
3957 struct omap_hwmod *temp_oh;
3958 int ret = 0;
3959
3960 if (!classname || !fn)
3961 return -EINVAL;
3962
3963 pr_debug("omap_hwmod: %s: looking for modules of class %s\n",
3964 __func__, classname);
3965
Paul Walmsley43b40992010-02-22 22:09:34 -07003966 list_for_each_entry(temp_oh, &omap_hwmod_list, node) {
3967 if (!strcmp(temp_oh->class->name, classname)) {
3968 pr_debug("omap_hwmod: %s: %s: calling callback fn\n",
3969 __func__, temp_oh->name);
3970 ret = (*fn)(temp_oh, user);
3971 if (ret)
3972 break;
3973 }
3974 }
3975
Paul Walmsley43b40992010-02-22 22:09:34 -07003976 if (ret)
3977 pr_debug("omap_hwmod: %s: iterator terminated early: %d\n",
3978 __func__, ret);
3979
3980 return ret;
3981}
3982
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003983/**
3984 * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod
3985 * @oh: struct omap_hwmod *
3986 * @state: state that _setup() should leave the hwmod in
3987 *
Paul Walmsley550c8092011-02-28 11:58:14 -07003988 * Sets the hwmod state that @oh will enter at the end of _setup()
Paul Walmsley64813c32012-04-18 19:10:03 -06003989 * (called by omap_hwmod_setup_*()). See also the documentation
3990 * for _setup_postsetup(), above. Returns 0 upon success or
3991 * -EINVAL if there is a problem with the arguments or if the hwmod is
3992 * in the wrong state.
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003993 */
3994int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state)
3995{
3996 int ret;
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07003997 unsigned long flags;
Paul Walmsley2092e5c2010-12-14 12:42:35 -07003998
3999 if (!oh)
4000 return -EINVAL;
4001
4002 if (state != _HWMOD_STATE_DISABLED &&
4003 state != _HWMOD_STATE_ENABLED &&
4004 state != _HWMOD_STATE_IDLE)
4005 return -EINVAL;
4006
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07004007 spin_lock_irqsave(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07004008
4009 if (oh->_state != _HWMOD_STATE_REGISTERED) {
4010 ret = -EINVAL;
4011 goto ohsps_unlock;
4012 }
4013
4014 oh->_postsetup_state = state;
4015 ret = 0;
4016
4017ohsps_unlock:
Paul Walmsleydc6d1cd2010-12-14 12:42:35 -07004018 spin_unlock_irqrestore(&oh->_lock, flags);
Paul Walmsley2092e5c2010-12-14 12:42:35 -07004019
4020 return ret;
4021}
Kevin Hilmanc80705a2010-12-21 21:31:55 -07004022
4023/**
4024 * omap_hwmod_get_context_loss_count - get lost context count
4025 * @oh: struct omap_hwmod *
4026 *
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07004027 * Returns the context loss count of associated @oh
4028 * upon success, or zero if no context loss data is available.
Kevin Hilmanc80705a2010-12-21 21:31:55 -07004029 *
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07004030 * On OMAP4, this queries the per-hwmod context loss register,
4031 * assuming one exists. If not, or on OMAP2/3, this queries the
4032 * enclosing powerdomain context loss count.
Kevin Hilmanc80705a2010-12-21 21:31:55 -07004033 */
Tomi Valkeinenfc013872011-06-09 16:56:23 +03004034int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh)
Kevin Hilmanc80705a2010-12-21 21:31:55 -07004035{
4036 struct powerdomain *pwrdm;
4037 int ret = 0;
4038
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07004039 if (soc_ops.get_context_lost)
4040 return soc_ops.get_context_lost(oh);
4041
Kevin Hilmanc80705a2010-12-21 21:31:55 -07004042 pwrdm = omap_hwmod_get_pwrdm(oh);
4043 if (pwrdm)
4044 ret = pwrdm_get_context_loss_count(pwrdm);
4045
4046 return ret;
4047}
Paul Walmsley43b01642011-03-10 03:50:07 -07004048
4049/**
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004050 * omap_hwmod_init - initialize the hwmod code
4051 *
4052 * Sets up some function pointers needed by the hwmod code to operate on the
4053 * currently-booted SoC. Intended to be called once during kernel init
4054 * before any hwmods are registered. No return value.
4055 */
4056void __init omap_hwmod_init(void)
4057{
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06004058 if (cpu_is_omap24xx()) {
Tero Kristo9002e9212014-10-27 08:39:23 -07004059 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -06004060 soc_ops.assert_hardreset = _omap2_assert_hardreset;
4061 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
4062 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
4063 } else if (cpu_is_omap34xx()) {
Tero Kristo9002e9212014-10-27 08:39:23 -07004064 soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06004065 soc_ops.assert_hardreset = _omap2_assert_hardreset;
4066 soc_ops.deassert_hardreset = _omap2_deassert_hardreset;
4067 soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted;
Tero Kristo0385c582013-07-17 18:03:25 +03004068 soc_ops.init_clkdm = _init_clkdm;
Rajendra Nayakdebcd1f2013-07-02 18:20:08 +05304069 } else if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx()) {
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004070 soc_ops.enable_module = _omap4_enable_module;
4071 soc_ops.disable_module = _omap4_disable_module;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004072 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Kevin Hilmanb8249cf2012-06-18 12:12:24 -06004073 soc_ops.assert_hardreset = _omap4_assert_hardreset;
4074 soc_ops.deassert_hardreset = _omap4_deassert_hardreset;
4075 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Kevin Hilman0a179ea2012-06-18 12:12:25 -06004076 soc_ops.init_clkdm = _init_clkdm;
Rajendra Nayake6d3a8b2012-11-21 16:15:17 -07004077 soc_ops.update_context_lost = _omap4_update_context_lost;
4078 soc_ops.get_context_lost = _omap4_get_context_lost;
Tero Kristo9fabc1a2016-07-04 14:11:48 +03004079 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
Tero Kristo70f05be2017-05-31 18:00:03 +03004080 soc_ops.xlate_clkctrl = _omap4_xlate_clkctrl;
Tony Lindgren0f3ccb22015-07-16 01:55:58 -07004081 } else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() ||
4082 soc_is_am43xx()) {
Afzal Mohammedc8b428a2013-10-12 15:46:20 +05304083 soc_ops.enable_module = _omap4_enable_module;
4084 soc_ops.disable_module = _omap4_disable_module;
4085 soc_ops.wait_target_ready = _omap4_wait_target_ready;
Tero Kristo409d7062014-10-27 08:39:24 -07004086 soc_ops.assert_hardreset = _omap4_assert_hardreset;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06004087 soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
Tero Kristoa5bf00c2015-05-05 16:33:05 +03004088 soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
Vaibhav Hiremath1688bf12012-09-11 17:18:53 -06004089 soc_ops.init_clkdm = _init_clkdm;
Tero Kristo9fabc1a2016-07-04 14:11:48 +03004090 soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
Tero Kristo2b96be32017-08-09 11:57:12 +03004091 soc_ops.xlate_clkctrl = _omap4_xlate_clkctrl;
Kevin Hilman8f6aa8e2012-06-18 12:12:24 -06004092 } else {
4093 WARN(1, "omap_hwmod: unknown SoC type\n");
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004094 }
4095
Tero Kristo70f05be2017-05-31 18:00:03 +03004096 _init_clkctrl_providers();
4097
Kevin Hilman9ebfd282012-06-18 12:12:23 -06004098 inited = true;
4099}
Tony Lindgren68c9a952012-07-06 00:58:43 -07004100
4101/**
4102 * omap_hwmod_get_main_clk - get pointer to main clock name
4103 * @oh: struct omap_hwmod *
4104 *
4105 * Returns the main clock name assocated with @oh upon success,
4106 * or NULL if @oh is NULL.
4107 */
4108const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh)
4109{
4110 if (!oh)
4111 return NULL;
4112
4113 return oh->main_clk;
4114}