Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1 | /* |
| 2 | * omap_hwmod implementation for OMAP2/3/4 |
| 3 | * |
Paul Walmsley | 550c809 | 2011-02-28 11:58:14 -0700 | [diff] [blame] | 4 | * Copyright (C) 2009-2011 Nokia Corporation |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 5 | * Copyright (C) 2011-2012 Texas Instruments, Inc. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 6 | * |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 7 | * Paul Walmsley, BenoƮt Cousson, Kevin Hilman |
| 8 | * |
| 9 | * Created in collaboration with (alphabetical order): Thara Gopinath, |
| 10 | * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand |
| 11 | * Sawant, Santosh Shilimkar, Richard Woodruff |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 17 | * Introduction |
| 18 | * ------------ |
| 19 | * One way to view an OMAP SoC is as a collection of largely unrelated |
| 20 | * IP blocks connected by interconnects. The IP blocks include |
| 21 | * devices such as ARM processors, audio serial interfaces, UARTs, |
| 22 | * etc. Some of these devices, like the DSP, are created by TI; |
| 23 | * others, like the SGX, largely originate from external vendors. In |
| 24 | * TI's documentation, on-chip devices are referred to as "OMAP |
| 25 | * modules." Some of these IP blocks are identical across several |
| 26 | * OMAP versions. Others are revised frequently. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 27 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 28 | * These OMAP modules are tied together by various interconnects. |
| 29 | * Most of the address and data flow between modules is via OCP-based |
| 30 | * interconnects such as the L3 and L4 buses; but there are other |
| 31 | * interconnects that distribute the hardware clock tree, handle idle |
| 32 | * and reset signaling, supply power, and connect the modules to |
| 33 | * various pads or balls on the OMAP package. |
| 34 | * |
| 35 | * OMAP hwmod provides a consistent way to describe the on-chip |
| 36 | * hardware blocks and their integration into the rest of the chip. |
| 37 | * This description can be automatically generated from the TI |
| 38 | * hardware database. OMAP hwmod provides a standard, consistent API |
| 39 | * to reset, enable, idle, and disable these hardware blocks. And |
| 40 | * hwmod provides a way for other core code, such as the Linux device |
| 41 | * code or the OMAP power management and address space mapping code, |
| 42 | * to query the hardware database. |
| 43 | * |
| 44 | * Using hwmod |
| 45 | * ----------- |
| 46 | * Drivers won't call hwmod functions directly. That is done by the |
| 47 | * omap_device code, and in rare occasions, by custom integration code |
| 48 | * in arch/arm/ *omap*. The omap_device code includes functions to |
| 49 | * build a struct platform_device using omap_hwmod data, and that is |
| 50 | * currently how hwmod data is communicated to drivers and to the |
| 51 | * Linux driver model. Most drivers will call omap_hwmod functions only |
| 52 | * indirectly, via pm_runtime*() functions. |
| 53 | * |
| 54 | * From a layering perspective, here is where the OMAP hwmod code |
| 55 | * fits into the kernel software stack: |
| 56 | * |
| 57 | * +-------------------------------+ |
| 58 | * | Device driver code | |
| 59 | * | (e.g., drivers/) | |
| 60 | * +-------------------------------+ |
| 61 | * | Linux driver model | |
| 62 | * | (platform_device / | |
| 63 | * | platform_driver data/code) | |
| 64 | * +-------------------------------+ |
| 65 | * | OMAP core-driver integration | |
| 66 | * |(arch/arm/mach-omap2/devices.c)| |
| 67 | * +-------------------------------+ |
| 68 | * | omap_device code | |
| 69 | * | (../plat-omap/omap_device.c) | |
| 70 | * +-------------------------------+ |
| 71 | * ----> | omap_hwmod code/data | <----- |
| 72 | * | (../mach-omap2/omap_hwmod*) | |
| 73 | * +-------------------------------+ |
| 74 | * | OMAP clock/PRCM/register fns | |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 75 | * | ({read,write}l_relaxed, clk*) | |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 76 | * +-------------------------------+ |
| 77 | * |
| 78 | * Device drivers should not contain any OMAP-specific code or data in |
| 79 | * them. They should only contain code to operate the IP block that |
| 80 | * the driver is responsible for. This is because these IP blocks can |
| 81 | * also appear in other SoCs, either from TI (such as DaVinci) or from |
| 82 | * other manufacturers; and drivers should be reusable across other |
| 83 | * platforms. |
| 84 | * |
| 85 | * The OMAP hwmod code also will attempt to reset and idle all on-chip |
| 86 | * devices upon boot. The goal here is for the kernel to be |
| 87 | * completely self-reliant and independent from bootloaders. This is |
| 88 | * to ensure a repeatable configuration, both to ensure consistent |
| 89 | * runtime behavior, and to make it easier for others to reproduce |
| 90 | * bugs. |
| 91 | * |
| 92 | * OMAP module activity states |
| 93 | * --------------------------- |
| 94 | * The hwmod code considers modules to be in one of several activity |
| 95 | * states. IP blocks start out in an UNKNOWN state, then once they |
| 96 | * are registered via the hwmod code, proceed to the REGISTERED state. |
| 97 | * Once their clock names are resolved to clock pointers, the module |
| 98 | * enters the CLKS_INITED state; and finally, once the module has been |
| 99 | * reset and the integration registers programmed, the INITIALIZED state |
| 100 | * is entered. The hwmod code will then place the module into either |
| 101 | * the IDLE state to save power, or in the case of a critical system |
| 102 | * module, the ENABLED state. |
| 103 | * |
| 104 | * OMAP core integration code can then call omap_hwmod*() functions |
| 105 | * directly to move the module between the IDLE, ENABLED, and DISABLED |
| 106 | * states, as needed. This is done during both the PM idle loop, and |
| 107 | * in the OMAP core integration code's implementation of the PM runtime |
| 108 | * functions. |
| 109 | * |
| 110 | * References |
| 111 | * ---------- |
| 112 | * This is a partial list. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 113 | * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064) |
| 114 | * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090) |
| 115 | * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108) |
| 116 | * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140) |
| 117 | * - Open Core Protocol Specification 2.2 |
| 118 | * |
| 119 | * To do: |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 120 | * - handle IO mapping |
| 121 | * - bus throughput & module latency measurement code |
| 122 | * |
| 123 | * XXX add tests at the beginning of each function to ensure the hwmod is |
| 124 | * in the appropriate state |
| 125 | * XXX error return values should be checked to ensure that they are |
| 126 | * appropriate |
| 127 | */ |
| 128 | #undef DEBUG |
| 129 | |
| 130 | #include <linux/kernel.h> |
| 131 | #include <linux/errno.h> |
| 132 | #include <linux/io.h> |
Stephen Boyd | f5b00f6 | 2015-06-22 17:05:21 -0700 | [diff] [blame] | 133 | #include <linux/clk.h> |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 134 | #include <linux/clk-provider.h> |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 135 | #include <linux/delay.h> |
| 136 | #include <linux/err.h> |
| 137 | #include <linux/list.h> |
| 138 | #include <linux/mutex.h> |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 139 | #include <linux/spinlock.h> |
Tero Kristo | abc2d54 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 140 | #include <linux/slab.h> |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 141 | #include <linux/cpu.h> |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 142 | #include <linux/of.h> |
| 143 | #include <linux/of_address.h> |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 144 | |
Paul Walmsley | fa20022 | 2013-01-26 00:48:56 -0700 | [diff] [blame] | 145 | #include <asm/system_misc.h> |
| 146 | |
Paul Walmsley | a135eaa | 2012-09-27 10:33:34 -0600 | [diff] [blame] | 147 | #include "clock.h" |
Tony Lindgren | 2a296c8 | 2012-10-02 17:41:35 -0700 | [diff] [blame] | 148 | #include "omap_hwmod.h" |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 149 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 150 | #include "soc.h" |
| 151 | #include "common.h" |
| 152 | #include "clockdomain.h" |
| 153 | #include "powerdomain.h" |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 154 | #include "cm2xxx.h" |
| 155 | #include "cm3xxx.h" |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 156 | #include "cm33xx.h" |
Paul Walmsley | b13159a | 2012-10-29 20:57:44 -0600 | [diff] [blame] | 157 | #include "prm.h" |
Paul Walmsley | 139563a | 2012-10-21 01:01:10 -0600 | [diff] [blame] | 158 | #include "prm3xxx.h" |
Paul Walmsley | d198b51 | 2010-12-21 15:30:54 -0700 | [diff] [blame] | 159 | #include "prm44xx.h" |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 160 | #include "prm33xx.h" |
Benoit Cousson | eaac329 | 2011-07-10 05:56:31 -0600 | [diff] [blame] | 161 | #include "prminst44xx.h" |
Vishwanath BS | 5165882 | 2012-06-22 08:40:04 -0600 | [diff] [blame] | 162 | #include "pm.h" |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 163 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 164 | /* Name of the OMAP hwmod for the MPU */ |
Benoit Cousson | 5c2c029 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 165 | #define MPU_INITIATOR_NAME "mpu" |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 166 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 167 | /* |
| 168 | * Number of struct omap_hwmod_link records per struct |
| 169 | * omap_hwmod_ocp_if record (master->slave and slave->master) |
| 170 | */ |
| 171 | #define LINKS_PER_OCP_IF 2 |
| 172 | |
Tero Kristo | 4ebf5b2 | 2015-05-05 16:33:04 +0300 | [diff] [blame] | 173 | /* |
| 174 | * Address offset (in bytes) between the reset control and the reset |
| 175 | * status registers: 4 bytes on OMAP4 |
| 176 | */ |
| 177 | #define OMAP4_RST_CTRL_ST_OFFSET 4 |
| 178 | |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 179 | /* |
| 180 | * Maximum length for module clock handle names |
| 181 | */ |
| 182 | #define MOD_CLK_MAX_NAME_LEN 32 |
| 183 | |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 184 | /** |
| 185 | * struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations |
| 186 | * @enable_module: function to enable a module (via MODULEMODE) |
| 187 | * @disable_module: function to disable a module (via MODULEMODE) |
| 188 | * |
| 189 | * XXX Eventually this functionality will be hidden inside the PRM/CM |
| 190 | * device drivers. Until then, this should avoid huge blocks of cpu_is_*() |
| 191 | * conditionals in this code. |
| 192 | */ |
| 193 | struct omap_hwmod_soc_ops { |
| 194 | void (*enable_module)(struct omap_hwmod *oh); |
| 195 | int (*disable_module)(struct omap_hwmod *oh); |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 196 | int (*wait_target_ready)(struct omap_hwmod *oh); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 197 | int (*assert_hardreset)(struct omap_hwmod *oh, |
| 198 | struct omap_hwmod_rst_info *ohri); |
| 199 | int (*deassert_hardreset)(struct omap_hwmod *oh, |
| 200 | struct omap_hwmod_rst_info *ohri); |
| 201 | int (*is_hardreset_asserted)(struct omap_hwmod *oh, |
| 202 | struct omap_hwmod_rst_info *ohri); |
Kevin Hilman | 0a179ea | 2012-06-18 12:12:25 -0600 | [diff] [blame] | 203 | int (*init_clkdm)(struct omap_hwmod *oh); |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 204 | void (*update_context_lost)(struct omap_hwmod *oh); |
| 205 | int (*get_context_lost)(struct omap_hwmod *oh); |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 206 | int (*disable_direct_prcm)(struct omap_hwmod *oh); |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */ |
| 210 | static struct omap_hwmod_soc_ops soc_ops; |
| 211 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 212 | /* omap_hwmod_list contains all registered struct omap_hwmods */ |
| 213 | static LIST_HEAD(omap_hwmod_list); |
| 214 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 215 | /* mpu_oh: used to add/remove MPU initiator from sleepdep list */ |
| 216 | static struct omap_hwmod *mpu_oh; |
| 217 | |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 218 | /* inited: set to true once the hwmod code is initialized */ |
| 219 | static bool inited; |
| 220 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 221 | /* Private functions */ |
| 222 | |
| 223 | /** |
| 224 | * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy |
| 225 | * @oh: struct omap_hwmod * |
| 226 | * |
| 227 | * Load the current value of the hwmod OCP_SYSCONFIG register into the |
| 228 | * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no |
| 229 | * OCP_SYSCONFIG register or 0 upon success. |
| 230 | */ |
| 231 | static int _update_sysc_cache(struct omap_hwmod *oh) |
| 232 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 233 | if (!oh->class->sysc) { |
| 234 | WARN(1, "omap_hwmod: %s: cannot read OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 235 | return -EINVAL; |
| 236 | } |
| 237 | |
| 238 | /* XXX ensure module interface clock is up */ |
| 239 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 240 | oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 241 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 242 | if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE)) |
Thara Gopinath | 883edfd | 2010-01-19 17:30:51 -0700 | [diff] [blame] | 243 | oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register |
| 250 | * @v: OCP_SYSCONFIG value to write |
| 251 | * @oh: struct omap_hwmod * |
| 252 | * |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 253 | * Write @v into the module class' OCP_SYSCONFIG register, if it has |
| 254 | * one. No return value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 255 | */ |
| 256 | static void _write_sysconfig(u32 v, struct omap_hwmod *oh) |
| 257 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 258 | if (!oh->class->sysc) { |
| 259 | WARN(1, "omap_hwmod: %s: cannot write OCP_SYSCONFIG: not defined on hwmod's class\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
| 263 | /* XXX ensure module interface clock is up */ |
| 264 | |
Rajendra Nayak | 233cbe5 | 2010-12-14 12:42:36 -0700 | [diff] [blame] | 265 | /* Module might have lost context, always update cache and register */ |
| 266 | oh->_sysc_cache = v; |
Lokesh Vutla | aaf2c0f | 2015-06-10 14:56:24 +0530 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Some IP blocks (such as RTC) require unlocking of IP before |
| 270 | * accessing its registers. If a function pointer is present |
| 271 | * to unlock, then call it before accessing sysconfig and |
| 272 | * call lock after writing sysconfig. |
| 273 | */ |
| 274 | if (oh->class->unlock) |
| 275 | oh->class->unlock(oh); |
| 276 | |
Rajendra Nayak | 233cbe5 | 2010-12-14 12:42:36 -0700 | [diff] [blame] | 277 | omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs); |
Lokesh Vutla | aaf2c0f | 2015-06-10 14:56:24 +0530 | [diff] [blame] | 278 | |
| 279 | if (oh->class->lock) |
| 280 | oh->class->lock(oh); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v |
| 285 | * @oh: struct omap_hwmod * |
| 286 | * @standbymode: MIDLEMODE field bits |
| 287 | * @v: pointer to register contents to modify |
| 288 | * |
| 289 | * Update the master standby mode bits in @v to be @standbymode for |
| 290 | * the @oh hwmod. Does not write to the hardware. Returns -EINVAL |
| 291 | * upon error or 0 upon success. |
| 292 | */ |
| 293 | static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode, |
| 294 | u32 *v) |
| 295 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 296 | u32 mstandby_mask; |
| 297 | u8 mstandby_shift; |
| 298 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 299 | if (!oh->class->sysc || |
| 300 | !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 301 | return -EINVAL; |
| 302 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 303 | if (!oh->class->sysc->sysc_fields) { |
| 304 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | } |
| 307 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 308 | mstandby_shift = oh->class->sysc->sysc_fields->midle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 309 | mstandby_mask = (0x3 << mstandby_shift); |
| 310 | |
| 311 | *v &= ~mstandby_mask; |
| 312 | *v |= __ffs(standbymode) << mstandby_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v |
| 319 | * @oh: struct omap_hwmod * |
| 320 | * @idlemode: SIDLEMODE field bits |
| 321 | * @v: pointer to register contents to modify |
| 322 | * |
| 323 | * Update the slave idle mode bits in @v to be @idlemode for the @oh |
| 324 | * hwmod. Does not write to the hardware. Returns -EINVAL upon error |
| 325 | * or 0 upon success. |
| 326 | */ |
| 327 | static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v) |
| 328 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 329 | u32 sidle_mask; |
| 330 | u8 sidle_shift; |
| 331 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 332 | if (!oh->class->sysc || |
| 333 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 334 | return -EINVAL; |
| 335 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 336 | if (!oh->class->sysc->sysc_fields) { |
| 337 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 338 | return -EINVAL; |
| 339 | } |
| 340 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 341 | sidle_shift = oh->class->sysc->sysc_fields->sidle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 342 | sidle_mask = (0x3 << sidle_shift); |
| 343 | |
| 344 | *v &= ~sidle_mask; |
| 345 | *v |= __ffs(idlemode) << sidle_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v |
| 352 | * @oh: struct omap_hwmod * |
| 353 | * @clockact: CLOCKACTIVITY field bits |
| 354 | * @v: pointer to register contents to modify |
| 355 | * |
| 356 | * Update the clockactivity mode bits in @v to be @clockact for the |
| 357 | * @oh hwmod. Used for additional powersaving on some modules. Does |
| 358 | * not write to the hardware. Returns -EINVAL upon error or 0 upon |
| 359 | * success. |
| 360 | */ |
| 361 | static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v) |
| 362 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 363 | u32 clkact_mask; |
| 364 | u8 clkact_shift; |
| 365 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 366 | if (!oh->class->sysc || |
| 367 | !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 368 | return -EINVAL; |
| 369 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 370 | if (!oh->class->sysc->sysc_fields) { |
| 371 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 372 | return -EINVAL; |
| 373 | } |
| 374 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 375 | clkact_shift = oh->class->sysc->sysc_fields->clkact_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 376 | clkact_mask = (0x3 << clkact_shift); |
| 377 | |
| 378 | *v &= ~clkact_mask; |
| 379 | *v |= clockact << clkact_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /** |
Roger Quadros | 313a76e | 2013-12-08 18:39:02 -0700 | [diff] [blame] | 385 | * _set_softreset: set OCP_SYSCONFIG.SOFTRESET bit in @v |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 386 | * @oh: struct omap_hwmod * |
| 387 | * @v: pointer to register contents to modify |
| 388 | * |
| 389 | * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon |
| 390 | * error or 0 upon success. |
| 391 | */ |
| 392 | static int _set_softreset(struct omap_hwmod *oh, u32 *v) |
| 393 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 394 | u32 softrst_mask; |
| 395 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 396 | if (!oh->class->sysc || |
| 397 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 398 | return -EINVAL; |
| 399 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 400 | if (!oh->class->sysc->sysc_fields) { |
| 401 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
| 404 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 405 | softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 406 | |
| 407 | *v |= softrst_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | /** |
Roger Quadros | 313a76e | 2013-12-08 18:39:02 -0700 | [diff] [blame] | 413 | * _clear_softreset: clear OCP_SYSCONFIG.SOFTRESET bit in @v |
| 414 | * @oh: struct omap_hwmod * |
| 415 | * @v: pointer to register contents to modify |
| 416 | * |
| 417 | * Clear the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon |
| 418 | * error or 0 upon success. |
| 419 | */ |
| 420 | static int _clear_softreset(struct omap_hwmod *oh, u32 *v) |
| 421 | { |
| 422 | u32 softrst_mask; |
| 423 | |
| 424 | if (!oh->class->sysc || |
| 425 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
| 426 | return -EINVAL; |
| 427 | |
| 428 | if (!oh->class->sysc->sysc_fields) { |
| 429 | WARN(1, |
| 430 | "omap_hwmod: %s: sysc_fields absent for sysconfig class\n", |
| 431 | oh->name); |
| 432 | return -EINVAL; |
| 433 | } |
| 434 | |
| 435 | softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift); |
| 436 | |
| 437 | *v &= ~softrst_mask; |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /** |
Tero Kristo | 613ad0e | 2012-10-29 22:02:13 -0600 | [diff] [blame] | 443 | * _wait_softreset_complete - wait for an OCP softreset to complete |
| 444 | * @oh: struct omap_hwmod * to wait on |
| 445 | * |
| 446 | * Wait until the IP block represented by @oh reports that its OCP |
| 447 | * softreset is complete. This can be triggered by software (see |
| 448 | * _ocp_softreset()) or by hardware upon returning from off-mode (one |
| 449 | * example is HSMMC). Waits for up to MAX_MODULE_SOFTRESET_WAIT |
| 450 | * microseconds. Returns the number of microseconds waited. |
| 451 | */ |
| 452 | static int _wait_softreset_complete(struct omap_hwmod *oh) |
| 453 | { |
| 454 | struct omap_hwmod_class_sysconfig *sysc; |
| 455 | u32 softrst_mask; |
| 456 | int c = 0; |
| 457 | |
| 458 | sysc = oh->class->sysc; |
| 459 | |
| 460 | if (sysc->sysc_flags & SYSS_HAS_RESET_STATUS) |
| 461 | omap_test_timeout((omap_hwmod_read(oh, sysc->syss_offs) |
| 462 | & SYSS_RESETDONE_MASK), |
| 463 | MAX_MODULE_SOFTRESET_WAIT, c); |
| 464 | else if (sysc->sysc_flags & SYSC_HAS_RESET_STATUS) { |
| 465 | softrst_mask = (0x1 << sysc->sysc_fields->srst_shift); |
| 466 | omap_test_timeout(!(omap_hwmod_read(oh, sysc->sysc_offs) |
| 467 | & softrst_mask), |
| 468 | MAX_MODULE_SOFTRESET_WAIT, c); |
| 469 | } |
| 470 | |
| 471 | return c; |
| 472 | } |
| 473 | |
| 474 | /** |
Kishon Vijay Abraham I | 6668546 | 2012-07-04 05:09:21 -0600 | [diff] [blame] | 475 | * _set_dmadisable: set OCP_SYSCONFIG.DMADISABLE bit in @v |
| 476 | * @oh: struct omap_hwmod * |
| 477 | * |
| 478 | * The DMADISABLE bit is a semi-automatic bit present in sysconfig register |
| 479 | * of some modules. When the DMA must perform read/write accesses, the |
| 480 | * DMADISABLE bit is cleared by the hardware. But when the DMA must stop |
| 481 | * for power management, software must set the DMADISABLE bit back to 1. |
| 482 | * |
| 483 | * Set the DMADISABLE bit in @v for hwmod @oh. Returns -EINVAL upon |
| 484 | * error or 0 upon success. |
| 485 | */ |
| 486 | static int _set_dmadisable(struct omap_hwmod *oh) |
| 487 | { |
| 488 | u32 v; |
| 489 | u32 dmadisable_mask; |
| 490 | |
| 491 | if (!oh->class->sysc || |
| 492 | !(oh->class->sysc->sysc_flags & SYSC_HAS_DMADISABLE)) |
| 493 | return -EINVAL; |
| 494 | |
| 495 | if (!oh->class->sysc->sysc_fields) { |
| 496 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
| 500 | /* clocks must be on for this operation */ |
| 501 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
| 502 | pr_warn("omap_hwmod: %s: dma can be disabled only from enabled state\n", oh->name); |
| 503 | return -EINVAL; |
| 504 | } |
| 505 | |
| 506 | pr_debug("omap_hwmod: %s: setting DMADISABLE\n", oh->name); |
| 507 | |
| 508 | v = oh->_sysc_cache; |
| 509 | dmadisable_mask = |
| 510 | (0x1 << oh->class->sysc->sysc_fields->dmadisable_shift); |
| 511 | v |= dmadisable_mask; |
| 512 | _write_sysconfig(v, oh); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | /** |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 518 | * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v |
| 519 | * @oh: struct omap_hwmod * |
| 520 | * @autoidle: desired AUTOIDLE bitfield value (0 or 1) |
| 521 | * @v: pointer to register contents to modify |
| 522 | * |
| 523 | * Update the module autoidle bit in @v to be @autoidle for the @oh |
| 524 | * hwmod. The autoidle bit controls whether the module can gate |
| 525 | * internal clocks automatically when it isn't doing anything; the |
| 526 | * exact function of this bit varies on a per-module basis. This |
| 527 | * function does not write to the hardware. Returns -EINVAL upon |
| 528 | * error or 0 upon success. |
| 529 | */ |
| 530 | static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle, |
| 531 | u32 *v) |
| 532 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 533 | u32 autoidle_mask; |
| 534 | u8 autoidle_shift; |
| 535 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 536 | if (!oh->class->sysc || |
| 537 | !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE)) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 538 | return -EINVAL; |
| 539 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 540 | if (!oh->class->sysc->sysc_fields) { |
| 541 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 542 | return -EINVAL; |
| 543 | } |
| 544 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 545 | autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift; |
Tarun Kanti DebBarma | 8985b63 | 2011-03-03 14:22:46 -0700 | [diff] [blame] | 546 | autoidle_mask = (0x1 << autoidle_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 547 | |
| 548 | *v &= ~autoidle_mask; |
| 549 | *v |= autoidle << autoidle_shift; |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 555 | * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 556 | * @oh: struct omap_hwmod * |
| 557 | * |
| 558 | * Allow the hardware module @oh to send wakeups. Returns -EINVAL |
| 559 | * upon error or 0 upon success. |
| 560 | */ |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 561 | static int _enable_wakeup(struct omap_hwmod *oh, u32 *v) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 562 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 563 | if (!oh->class->sysc || |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 564 | !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) || |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 565 | (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) || |
| 566 | (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP))) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 567 | return -EINVAL; |
| 568 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 569 | if (!oh->class->sysc->sysc_fields) { |
| 570 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 571 | return -EINVAL; |
| 572 | } |
| 573 | |
Benoit Cousson | 1fe7411 | 2011-07-01 22:54:03 +0200 | [diff] [blame] | 574 | if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) |
| 575 | *v |= 0x1 << oh->class->sysc->sysc_fields->enwkup_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 576 | |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 577 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 578 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v); |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 579 | if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP) |
| 580 | _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART_WKUP, v); |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 581 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 582 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 583 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 589 | * @oh: struct omap_hwmod * |
| 590 | * |
| 591 | * Prevent the hardware module @oh to send wakeups. Returns -EINVAL |
| 592 | * upon error or 0 upon success. |
| 593 | */ |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 594 | static int _disable_wakeup(struct omap_hwmod *oh, u32 *v) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 595 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 596 | if (!oh->class->sysc || |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 597 | !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) || |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 598 | (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) || |
| 599 | (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP))) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 600 | return -EINVAL; |
| 601 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 602 | if (!oh->class->sysc->sysc_fields) { |
| 603 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
| 606 | |
Benoit Cousson | 1fe7411 | 2011-07-01 22:54:03 +0200 | [diff] [blame] | 607 | if (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) |
| 608 | *v &= ~(0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 609 | |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 610 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 611 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v); |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 612 | if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP) |
Djamil Elaidi | 561038f | 2012-06-17 11:57:51 -0600 | [diff] [blame] | 613 | _set_master_standbymode(oh, HWMOD_IDLEMODE_SMART, v); |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 614 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 615 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 616 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 617 | return 0; |
| 618 | } |
| 619 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 620 | static struct clockdomain *_get_clkdm(struct omap_hwmod *oh) |
| 621 | { |
Rajendra Nayak | c4a1ea2 | 2012-04-27 16:32:53 +0530 | [diff] [blame] | 622 | struct clk_hw_omap *clk; |
| 623 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 624 | if (oh->clkdm) { |
| 625 | return oh->clkdm; |
| 626 | } else if (oh->_clk) { |
Tero Kristo | 924f949 | 2013-07-12 12:26:41 +0300 | [diff] [blame] | 627 | if (__clk_get_flags(oh->_clk) & CLK_IS_BASIC) |
| 628 | return NULL; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 629 | clk = to_clk_hw_omap(__clk_get_hw(oh->_clk)); |
| 630 | return clk->clkdm; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 631 | } |
| 632 | return NULL; |
| 633 | } |
| 634 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 635 | /** |
| 636 | * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active |
| 637 | * @oh: struct omap_hwmod * |
| 638 | * |
| 639 | * Prevent the hardware module @oh from entering idle while the |
| 640 | * hardare module initiator @init_oh is active. Useful when a module |
| 641 | * will be accessed by a particular initiator (e.g., if a module will |
| 642 | * be accessed by the IVA, there should be a sleepdep between the IVA |
| 643 | * initiator and the module). Only applies to modules in smart-idle |
Paul Walmsley | 570b54c | 2011-03-10 03:50:09 -0700 | [diff] [blame] | 644 | * mode. If the clockdomain is marked as not needing autodeps, return |
| 645 | * 0 without doing anything. Otherwise, returns -EINVAL upon error or |
| 646 | * passes along clkdm_add_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 647 | */ |
| 648 | static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 649 | { |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 650 | struct clockdomain *clkdm, *init_clkdm; |
| 651 | |
| 652 | clkdm = _get_clkdm(oh); |
| 653 | init_clkdm = _get_clkdm(init_oh); |
| 654 | |
| 655 | if (!clkdm || !init_clkdm) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 656 | return -EINVAL; |
| 657 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 658 | if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS) |
Paul Walmsley | 570b54c | 2011-03-10 03:50:09 -0700 | [diff] [blame] | 659 | return 0; |
| 660 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 661 | return clkdm_add_sleepdep(clkdm, init_clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /** |
| 665 | * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active |
| 666 | * @oh: struct omap_hwmod * |
| 667 | * |
| 668 | * Allow the hardware module @oh to enter idle while the hardare |
| 669 | * module initiator @init_oh is active. Useful when a module will not |
| 670 | * be accessed by a particular initiator (e.g., if a module will not |
| 671 | * be accessed by the IVA, there should be no sleepdep between the IVA |
| 672 | * initiator and the module). Only applies to modules in smart-idle |
Paul Walmsley | 570b54c | 2011-03-10 03:50:09 -0700 | [diff] [blame] | 673 | * mode. If the clockdomain is marked as not needing autodeps, return |
| 674 | * 0 without doing anything. Returns -EINVAL upon error or passes |
| 675 | * along clkdm_del_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 676 | */ |
| 677 | static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 678 | { |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 679 | struct clockdomain *clkdm, *init_clkdm; |
| 680 | |
| 681 | clkdm = _get_clkdm(oh); |
| 682 | init_clkdm = _get_clkdm(init_oh); |
| 683 | |
| 684 | if (!clkdm || !init_clkdm) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 685 | return -EINVAL; |
| 686 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 687 | if (clkdm && clkdm->flags & CLKDM_NO_AUTODEPS) |
Paul Walmsley | 570b54c | 2011-03-10 03:50:09 -0700 | [diff] [blame] | 688 | return 0; |
| 689 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 690 | return clkdm_del_sleepdep(clkdm, init_clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /** |
| 694 | * _init_main_clk - get a struct clk * for the the hwmod's main functional clk |
| 695 | * @oh: struct omap_hwmod * |
| 696 | * |
| 697 | * Called from _init_clocks(). Populates the @oh _clk (main |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 698 | * functional clock pointer) if a clock matching the hwmod name is found, |
| 699 | * or a main_clk is present. Returns 0 on success or -EINVAL on error. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 700 | */ |
| 701 | static int _init_main_clk(struct omap_hwmod *oh) |
| 702 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 703 | int ret = 0; |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 704 | char name[MOD_CLK_MAX_NAME_LEN]; |
| 705 | struct clk *clk; |
Maninder Singh | 5066d52 | 2016-12-08 09:40:30 +0530 | [diff] [blame] | 706 | static const char modck[] = "_mod_ck"; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 707 | |
Maninder Singh | 5066d52 | 2016-12-08 09:40:30 +0530 | [diff] [blame] | 708 | if (strlen(oh->name) >= MOD_CLK_MAX_NAME_LEN - strlen(modck)) |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 709 | pr_warn("%s: warning: cropping name for %s\n", __func__, |
| 710 | oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 711 | |
Maninder Singh | 5066d52 | 2016-12-08 09:40:30 +0530 | [diff] [blame] | 712 | strlcpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - strlen(modck)); |
| 713 | strlcat(name, modck, MOD_CLK_MAX_NAME_LEN); |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 714 | |
| 715 | clk = clk_get(NULL, name); |
| 716 | if (!IS_ERR(clk)) { |
| 717 | oh->_clk = clk; |
| 718 | soc_ops.disable_direct_prcm(oh); |
| 719 | oh->main_clk = kstrdup(name, GFP_KERNEL); |
| 720 | } else { |
| 721 | if (!oh->main_clk) |
| 722 | return 0; |
| 723 | |
| 724 | oh->_clk = clk_get(NULL, oh->main_clk); |
| 725 | } |
| 726 | |
Rajendra Nayak | 6ea74cb | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 727 | if (IS_ERR(oh->_clk)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 728 | pr_warn("omap_hwmod: %s: cannot clk_get main_clk %s\n", |
| 729 | oh->name, oh->main_clk); |
Benoit Cousson | 6340338 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 730 | return -EINVAL; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 731 | } |
Rajendra Nayak | 4d7cb45 | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 732 | /* |
| 733 | * HACK: This needs a re-visit once clk_prepare() is implemented |
| 734 | * to do something meaningful. Today its just a no-op. |
| 735 | * If clk_prepare() is used at some point to do things like |
| 736 | * voltage scaling etc, then this would have to be moved to |
| 737 | * some point where subsystems like i2c and pmic become |
| 738 | * available. |
| 739 | */ |
| 740 | clk_prepare(oh->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 741 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 742 | if (!_get_clkdm(oh)) |
Paul Walmsley | 3bb05db | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 743 | pr_debug("omap_hwmod: %s: missing clockdomain for %s.\n", |
Rajendra Nayak | 5dcc3b9 | 2012-09-22 02:24:17 -0600 | [diff] [blame] | 744 | oh->name, oh->main_clk); |
Kevin Hilman | 81d7c6f | 2009-12-08 16:34:24 -0700 | [diff] [blame] | 745 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | /** |
Paul Walmsley | 887adea | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 750 | * _init_interface_clks - get a struct clk * for the the hwmod's interface clks |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 751 | * @oh: struct omap_hwmod * |
| 752 | * |
| 753 | * Called from _init_clocks(). Populates the @oh OCP slave interface |
| 754 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 755 | */ |
| 756 | static int _init_interface_clks(struct omap_hwmod *oh) |
| 757 | { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 758 | struct omap_hwmod_ocp_if *os; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 759 | struct clk *c; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 760 | int ret = 0; |
| 761 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 762 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 763 | if (!os->clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 764 | continue; |
| 765 | |
Rajendra Nayak | 6ea74cb | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 766 | c = clk_get(NULL, os->clk); |
| 767 | if (IS_ERR(c)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 768 | pr_warn("omap_hwmod: %s: cannot clk_get interface_clk %s\n", |
| 769 | oh->name, os->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 770 | ret = -EINVAL; |
Nishanth Menon | 0e7dc86 | 2013-12-08 18:39:03 -0700 | [diff] [blame] | 771 | continue; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 772 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 773 | os->_clk = c; |
Rajendra Nayak | 4d7cb45 | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 774 | /* |
| 775 | * HACK: This needs a re-visit once clk_prepare() is implemented |
| 776 | * to do something meaningful. Today its just a no-op. |
| 777 | * If clk_prepare() is used at some point to do things like |
| 778 | * voltage scaling etc, then this would have to be moved to |
| 779 | * some point where subsystems like i2c and pmic become |
| 780 | * available. |
| 781 | */ |
| 782 | clk_prepare(os->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | return ret; |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks |
| 790 | * @oh: struct omap_hwmod * |
| 791 | * |
| 792 | * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk |
| 793 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 794 | */ |
| 795 | static int _init_opt_clks(struct omap_hwmod *oh) |
| 796 | { |
| 797 | struct omap_hwmod_opt_clk *oc; |
| 798 | struct clk *c; |
| 799 | int i; |
| 800 | int ret = 0; |
| 801 | |
| 802 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) { |
Rajendra Nayak | 6ea74cb | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 803 | c = clk_get(NULL, oc->clk); |
| 804 | if (IS_ERR(c)) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 805 | pr_warn("omap_hwmod: %s: cannot clk_get opt_clk %s\n", |
| 806 | oh->name, oc->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 807 | ret = -EINVAL; |
Nishanth Menon | 0e7dc86 | 2013-12-08 18:39:03 -0700 | [diff] [blame] | 808 | continue; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 809 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 810 | oc->_clk = c; |
Rajendra Nayak | 4d7cb45 | 2012-09-22 02:24:16 -0600 | [diff] [blame] | 811 | /* |
| 812 | * HACK: This needs a re-visit once clk_prepare() is implemented |
| 813 | * to do something meaningful. Today its just a no-op. |
| 814 | * If clk_prepare() is used at some point to do things like |
| 815 | * voltage scaling etc, then this would have to be moved to |
| 816 | * some point where subsystems like i2c and pmic become |
| 817 | * available. |
| 818 | */ |
| 819 | clk_prepare(oc->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | return ret; |
| 823 | } |
| 824 | |
Peter Ujfalusi | c12ba8c | 2015-11-12 09:32:58 +0200 | [diff] [blame] | 825 | static void _enable_optional_clocks(struct omap_hwmod *oh) |
| 826 | { |
| 827 | struct omap_hwmod_opt_clk *oc; |
| 828 | int i; |
| 829 | |
| 830 | pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name); |
| 831 | |
| 832 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 833 | if (oc->_clk) { |
| 834 | pr_debug("omap_hwmod: enable %s:%s\n", oc->role, |
| 835 | __clk_get_name(oc->_clk)); |
| 836 | clk_enable(oc->_clk); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static void _disable_optional_clocks(struct omap_hwmod *oh) |
| 841 | { |
| 842 | struct omap_hwmod_opt_clk *oc; |
| 843 | int i; |
| 844 | |
| 845 | pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name); |
| 846 | |
| 847 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 848 | if (oc->_clk) { |
| 849 | pr_debug("omap_hwmod: disable %s:%s\n", oc->role, |
| 850 | __clk_get_name(oc->_clk)); |
| 851 | clk_disable(oc->_clk); |
| 852 | } |
| 853 | } |
| 854 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 855 | /** |
| 856 | * _enable_clocks - enable hwmod main clock and interface clocks |
| 857 | * @oh: struct omap_hwmod * |
| 858 | * |
| 859 | * Enables all clocks necessary for register reads and writes to succeed |
| 860 | * on the hwmod @oh. Returns 0. |
| 861 | */ |
| 862 | static int _enable_clocks(struct omap_hwmod *oh) |
| 863 | { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 864 | struct omap_hwmod_ocp_if *os; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 865 | |
| 866 | pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); |
| 867 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 868 | if (oh->_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 869 | clk_enable(oh->_clk); |
| 870 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 871 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 872 | if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) |
| 873 | clk_enable(os->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 874 | } |
| 875 | |
Peter Ujfalusi | c12ba8c | 2015-11-12 09:32:58 +0200 | [diff] [blame] | 876 | if (oh->flags & HWMOD_OPT_CLKS_NEEDED) |
| 877 | _enable_optional_clocks(oh); |
| 878 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 879 | /* The opt clocks are controlled by the device driver. */ |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * _disable_clocks - disable hwmod main clock and interface clocks |
| 886 | * @oh: struct omap_hwmod * |
| 887 | * |
| 888 | * Disables the hwmod @oh main functional and interface clocks. Returns 0. |
| 889 | */ |
| 890 | static int _disable_clocks(struct omap_hwmod *oh) |
| 891 | { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 892 | struct omap_hwmod_ocp_if *os; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 893 | |
| 894 | pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); |
| 895 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 896 | if (oh->_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 897 | clk_disable(oh->_clk); |
| 898 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 899 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 900 | if (os->_clk && (os->flags & OCPIF_SWSUP_IDLE)) |
| 901 | clk_disable(os->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 902 | } |
| 903 | |
Peter Ujfalusi | c12ba8c | 2015-11-12 09:32:58 +0200 | [diff] [blame] | 904 | if (oh->flags & HWMOD_OPT_CLKS_NEEDED) |
| 905 | _disable_optional_clocks(oh); |
| 906 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 907 | /* The opt clocks are controlled by the device driver. */ |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | /** |
Kevin Hilman | 3d9f032 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 913 | * _omap4_enable_module - enable CLKCTRL modulemode on OMAP4 |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 914 | * @oh: struct omap_hwmod * |
| 915 | * |
| 916 | * Enables the PRCM module mode related to the hwmod @oh. |
| 917 | * No return value. |
| 918 | */ |
Kevin Hilman | 3d9f032 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 919 | static void _omap4_enable_module(struct omap_hwmod *oh) |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 920 | { |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 921 | if (!oh->clkdm || !oh->prcm.omap4.modulemode) |
| 922 | return; |
| 923 | |
Kevin Hilman | 3d9f032 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 924 | pr_debug("omap_hwmod: %s: %s: %d\n", |
| 925 | oh->name, __func__, oh->prcm.omap4.modulemode); |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 926 | |
Tero Kristo | 128603f | 2014-10-27 08:39:24 -0700 | [diff] [blame] | 927 | omap_cm_module_enable(oh->prcm.omap4.modulemode, |
| 928 | oh->clkdm->prcm_partition, |
| 929 | oh->clkdm->cm_inst, oh->prcm.omap4.clkctrl_offs); |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
Benoit Cousson | bfc141e | 2011-12-16 16:09:11 -0800 | [diff] [blame] | 933 | * _omap4_wait_target_disable - wait for a module to be disabled on OMAP4 |
| 934 | * @oh: struct omap_hwmod * |
| 935 | * |
| 936 | * Wait for a module @oh to enter slave idle. Returns 0 if the module |
| 937 | * does not have an IDLEST bit or if the module successfully enters |
| 938 | * slave idle; otherwise, pass along the return value of the |
| 939 | * appropriate *_cm*_wait_module_idle() function. |
| 940 | */ |
| 941 | static int _omap4_wait_target_disable(struct omap_hwmod *oh) |
| 942 | { |
Paul Walmsley | 2b026d1 | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 943 | if (!oh) |
Benoit Cousson | bfc141e | 2011-12-16 16:09:11 -0800 | [diff] [blame] | 944 | return -EINVAL; |
| 945 | |
Paul Walmsley | 2b026d1 | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 946 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT || !oh->clkdm) |
Benoit Cousson | bfc141e | 2011-12-16 16:09:11 -0800 | [diff] [blame] | 947 | return 0; |
| 948 | |
| 949 | if (oh->flags & HWMOD_NO_IDLEST) |
| 950 | return 0; |
| 951 | |
Dave Gerlach | 428929c | 2016-07-12 12:50:33 -0500 | [diff] [blame] | 952 | if (!oh->prcm.omap4.clkctrl_offs && |
| 953 | !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET)) |
| 954 | return 0; |
| 955 | |
Tero Kristo | a8ae5af | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 956 | return omap_cm_wait_module_idle(oh->clkdm->prcm_partition, |
| 957 | oh->clkdm->cm_inst, |
| 958 | oh->prcm.omap4.clkctrl_offs, 0); |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /** |
Paul Walmsley | 212738a | 2011-07-09 19:14:06 -0600 | [diff] [blame] | 962 | * _count_mpu_irqs - count the number of MPU IRQ lines associated with @oh |
| 963 | * @oh: struct omap_hwmod *oh |
| 964 | * |
| 965 | * Count and return the number of MPU IRQs associated with the hwmod |
| 966 | * @oh. Used to allocate struct resource data. Returns 0 if @oh is |
| 967 | * NULL. |
| 968 | */ |
| 969 | static int _count_mpu_irqs(struct omap_hwmod *oh) |
| 970 | { |
| 971 | struct omap_hwmod_irq_info *ohii; |
| 972 | int i = 0; |
| 973 | |
| 974 | if (!oh || !oh->mpu_irqs) |
| 975 | return 0; |
| 976 | |
| 977 | do { |
| 978 | ohii = &oh->mpu_irqs[i++]; |
| 979 | } while (ohii->irq != -1); |
| 980 | |
sricharan | cc1b076 | 2011-11-23 14:35:07 -0800 | [diff] [blame] | 981 | return i-1; |
Paul Walmsley | 212738a | 2011-07-09 19:14:06 -0600 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /** |
Paul Walmsley | bc61495 | 2011-07-09 19:14:07 -0600 | [diff] [blame] | 985 | * _count_sdma_reqs - count the number of SDMA request lines associated with @oh |
| 986 | * @oh: struct omap_hwmod *oh |
| 987 | * |
| 988 | * Count and return the number of SDMA request lines associated with |
| 989 | * the hwmod @oh. Used to allocate struct resource data. Returns 0 |
| 990 | * if @oh is NULL. |
| 991 | */ |
| 992 | static int _count_sdma_reqs(struct omap_hwmod *oh) |
| 993 | { |
| 994 | struct omap_hwmod_dma_info *ohdi; |
| 995 | int i = 0; |
| 996 | |
| 997 | if (!oh || !oh->sdma_reqs) |
| 998 | return 0; |
| 999 | |
| 1000 | do { |
| 1001 | ohdi = &oh->sdma_reqs[i++]; |
| 1002 | } while (ohdi->dma_req != -1); |
| 1003 | |
sricharan | cc1b076 | 2011-11-23 14:35:07 -0800 | [diff] [blame] | 1004 | return i-1; |
Paul Walmsley | bc61495 | 2011-07-09 19:14:07 -0600 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /** |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 1008 | * _count_ocp_if_addr_spaces - count the number of address space entries for @oh |
| 1009 | * @oh: struct omap_hwmod *oh |
| 1010 | * |
| 1011 | * Count and return the number of address space ranges associated with |
| 1012 | * the hwmod @oh. Used to allocate struct resource data. Returns 0 |
| 1013 | * if @oh is NULL. |
| 1014 | */ |
| 1015 | static int _count_ocp_if_addr_spaces(struct omap_hwmod_ocp_if *os) |
| 1016 | { |
| 1017 | struct omap_hwmod_addr_space *mem; |
| 1018 | int i = 0; |
| 1019 | |
| 1020 | if (!os || !os->addr) |
| 1021 | return 0; |
| 1022 | |
| 1023 | do { |
| 1024 | mem = &os->addr[i++]; |
| 1025 | } while (mem->pa_start != mem->pa_end); |
| 1026 | |
sricharan | cc1b076 | 2011-11-23 14:35:07 -0800 | [diff] [blame] | 1027 | return i-1; |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /** |
Paul Walmsley | 5e8370f | 2012-04-18 19:10:06 -0600 | [diff] [blame] | 1031 | * _get_mpu_irq_by_name - fetch MPU interrupt line number by name |
| 1032 | * @oh: struct omap_hwmod * to operate on |
| 1033 | * @name: pointer to the name of the MPU interrupt number to fetch (optional) |
| 1034 | * @irq: pointer to an unsigned int to store the MPU IRQ number to |
| 1035 | * |
| 1036 | * Retrieve a MPU hardware IRQ line number named by @name associated |
| 1037 | * with the IP block pointed to by @oh. The IRQ number will be filled |
| 1038 | * into the address pointed to by @dma. When @name is non-null, the |
| 1039 | * IRQ line number associated with the named entry will be returned. |
| 1040 | * If @name is null, the first matching entry will be returned. Data |
| 1041 | * order is not meaningful in hwmod data, so callers are strongly |
| 1042 | * encouraged to use a non-null @name whenever possible to avoid |
| 1043 | * unpredictable effects if hwmod data is later added that causes data |
| 1044 | * ordering to change. Returns 0 upon success or a negative error |
| 1045 | * code upon error. |
| 1046 | */ |
| 1047 | static int _get_mpu_irq_by_name(struct omap_hwmod *oh, const char *name, |
| 1048 | unsigned int *irq) |
| 1049 | { |
| 1050 | int i; |
| 1051 | bool found = false; |
| 1052 | |
| 1053 | if (!oh->mpu_irqs) |
| 1054 | return -ENOENT; |
| 1055 | |
| 1056 | i = 0; |
| 1057 | while (oh->mpu_irqs[i].irq != -1) { |
| 1058 | if (name == oh->mpu_irqs[i].name || |
| 1059 | !strcmp(name, oh->mpu_irqs[i].name)) { |
| 1060 | found = true; |
| 1061 | break; |
| 1062 | } |
| 1063 | i++; |
| 1064 | } |
| 1065 | |
| 1066 | if (!found) |
| 1067 | return -ENOENT; |
| 1068 | |
| 1069 | *irq = oh->mpu_irqs[i].irq; |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * _get_sdma_req_by_name - fetch SDMA request line ID by name |
| 1076 | * @oh: struct omap_hwmod * to operate on |
| 1077 | * @name: pointer to the name of the SDMA request line to fetch (optional) |
| 1078 | * @dma: pointer to an unsigned int to store the request line ID to |
| 1079 | * |
| 1080 | * Retrieve an SDMA request line ID named by @name on the IP block |
| 1081 | * pointed to by @oh. The ID will be filled into the address pointed |
| 1082 | * to by @dma. When @name is non-null, the request line ID associated |
| 1083 | * with the named entry will be returned. If @name is null, the first |
| 1084 | * matching entry will be returned. Data order is not meaningful in |
| 1085 | * hwmod data, so callers are strongly encouraged to use a non-null |
| 1086 | * @name whenever possible to avoid unpredictable effects if hwmod |
| 1087 | * data is later added that causes data ordering to change. Returns 0 |
| 1088 | * upon success or a negative error code upon error. |
| 1089 | */ |
| 1090 | static int _get_sdma_req_by_name(struct omap_hwmod *oh, const char *name, |
| 1091 | unsigned int *dma) |
| 1092 | { |
| 1093 | int i; |
| 1094 | bool found = false; |
| 1095 | |
| 1096 | if (!oh->sdma_reqs) |
| 1097 | return -ENOENT; |
| 1098 | |
| 1099 | i = 0; |
| 1100 | while (oh->sdma_reqs[i].dma_req != -1) { |
| 1101 | if (name == oh->sdma_reqs[i].name || |
| 1102 | !strcmp(name, oh->sdma_reqs[i].name)) { |
| 1103 | found = true; |
| 1104 | break; |
| 1105 | } |
| 1106 | i++; |
| 1107 | } |
| 1108 | |
| 1109 | if (!found) |
| 1110 | return -ENOENT; |
| 1111 | |
| 1112 | *dma = oh->sdma_reqs[i].dma_req; |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * _get_addr_space_by_name - fetch address space start & end by name |
| 1119 | * @oh: struct omap_hwmod * to operate on |
| 1120 | * @name: pointer to the name of the address space to fetch (optional) |
| 1121 | * @pa_start: pointer to a u32 to store the starting address to |
| 1122 | * @pa_end: pointer to a u32 to store the ending address to |
| 1123 | * |
| 1124 | * Retrieve address space start and end addresses for the IP block |
| 1125 | * pointed to by @oh. The data will be filled into the addresses |
| 1126 | * pointed to by @pa_start and @pa_end. When @name is non-null, the |
| 1127 | * address space data associated with the named entry will be |
| 1128 | * returned. If @name is null, the first matching entry will be |
| 1129 | * returned. Data order is not meaningful in hwmod data, so callers |
| 1130 | * are strongly encouraged to use a non-null @name whenever possible |
| 1131 | * to avoid unpredictable effects if hwmod data is later added that |
| 1132 | * causes data ordering to change. Returns 0 upon success or a |
| 1133 | * negative error code upon error. |
| 1134 | */ |
| 1135 | static int _get_addr_space_by_name(struct omap_hwmod *oh, const char *name, |
| 1136 | u32 *pa_start, u32 *pa_end) |
| 1137 | { |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 1138 | int j; |
Paul Walmsley | 5e8370f | 2012-04-18 19:10:06 -0600 | [diff] [blame] | 1139 | struct omap_hwmod_ocp_if *os; |
| 1140 | bool found = false; |
| 1141 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 1142 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 5e8370f | 2012-04-18 19:10:06 -0600 | [diff] [blame] | 1143 | |
| 1144 | if (!os->addr) |
| 1145 | return -ENOENT; |
| 1146 | |
| 1147 | j = 0; |
| 1148 | while (os->addr[j].pa_start != os->addr[j].pa_end) { |
| 1149 | if (name == os->addr[j].name || |
| 1150 | !strcmp(name, os->addr[j].name)) { |
| 1151 | found = true; |
| 1152 | break; |
| 1153 | } |
| 1154 | j++; |
| 1155 | } |
| 1156 | |
| 1157 | if (found) |
| 1158 | break; |
| 1159 | } |
| 1160 | |
| 1161 | if (!found) |
| 1162 | return -ENOENT; |
| 1163 | |
| 1164 | *pa_start = os->addr[j].pa_start; |
| 1165 | *pa_end = os->addr[j].pa_end; |
| 1166 | |
| 1167 | return 0; |
| 1168 | } |
| 1169 | |
| 1170 | /** |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1171 | * _save_mpu_port_index - find and save the index to @oh's MPU port |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1172 | * @oh: struct omap_hwmod * |
| 1173 | * |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1174 | * Determines the array index of the OCP slave port that the MPU uses |
| 1175 | * to address the device, and saves it into the struct omap_hwmod. |
| 1176 | * Intended to be called during hwmod registration only. No return |
| 1177 | * value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1178 | */ |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1179 | static void __init _save_mpu_port_index(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1180 | { |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1181 | struct omap_hwmod_ocp_if *os = NULL; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1182 | |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 1183 | if (!oh) |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1184 | return; |
| 1185 | |
| 1186 | oh->_int_flags |= _HWMOD_NO_MPU_PORT; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1187 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 1188 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1189 | if (os->user & OCP_USER_MPU) { |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 1190 | oh->_mpu_port = os; |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1191 | oh->_int_flags &= ~_HWMOD_NO_MPU_PORT; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1192 | break; |
| 1193 | } |
| 1194 | } |
| 1195 | |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1196 | return; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | /** |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 1200 | * _find_mpu_rt_port - return omap_hwmod_ocp_if accessible by the MPU |
| 1201 | * @oh: struct omap_hwmod * |
| 1202 | * |
| 1203 | * Given a pointer to a struct omap_hwmod record @oh, return a pointer |
| 1204 | * to the struct omap_hwmod_ocp_if record that is used by the MPU to |
| 1205 | * communicate with the IP block. This interface need not be directly |
| 1206 | * connected to the MPU (and almost certainly is not), but is directly |
| 1207 | * connected to the IP block represented by @oh. Returns a pointer |
| 1208 | * to the struct omap_hwmod_ocp_if * upon success, or returns NULL upon |
| 1209 | * error or if there does not appear to be a path from the MPU to this |
| 1210 | * IP block. |
| 1211 | */ |
| 1212 | static struct omap_hwmod_ocp_if *_find_mpu_rt_port(struct omap_hwmod *oh) |
| 1213 | { |
| 1214 | if (!oh || oh->_int_flags & _HWMOD_NO_MPU_PORT || oh->slaves_cnt == 0) |
| 1215 | return NULL; |
| 1216 | |
Paul Walmsley | 11cd4b9 | 2012-04-19 04:04:32 -0600 | [diff] [blame] | 1217 | return oh->_mpu_port; |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 1218 | }; |
| 1219 | |
| 1220 | /** |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 1221 | * _find_mpu_rt_addr_space - return MPU register target address space for @oh |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1222 | * @oh: struct omap_hwmod * |
| 1223 | * |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 1224 | * Returns a pointer to the struct omap_hwmod_addr_space record representing |
| 1225 | * the register target MPU address space; or returns NULL upon error. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1226 | */ |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 1227 | static struct omap_hwmod_addr_space * __init _find_mpu_rt_addr_space(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1228 | { |
| 1229 | struct omap_hwmod_ocp_if *os; |
| 1230 | struct omap_hwmod_addr_space *mem; |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 1231 | int found = 0, i = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1232 | |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 1233 | os = _find_mpu_rt_port(oh); |
Paul Walmsley | 24dbc21 | 2012-04-19 04:04:29 -0600 | [diff] [blame] | 1234 | if (!os || !os->addr) |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 1235 | return NULL; |
| 1236 | |
| 1237 | do { |
| 1238 | mem = &os->addr[i++]; |
| 1239 | if (mem->flags & ADDR_TYPE_RT) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1240 | found = 1; |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 1241 | } while (!found && mem->pa_start != mem->pa_end); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1242 | |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 1243 | return (found) ? mem : NULL; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1247 | * _enable_sysc - try to bring a module out of idle via OCP_SYSCONFIG |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1248 | * @oh: struct omap_hwmod * |
| 1249 | * |
Paul Walmsley | 006c7f1 | 2012-07-04 05:22:53 -0600 | [diff] [blame] | 1250 | * Ensure that the OCP_SYSCONFIG register for the IP block represented |
| 1251 | * by @oh is set to indicate to the PRCM that the IP block is active. |
| 1252 | * Usually this means placing the module into smart-idle mode and |
| 1253 | * smart-standby, but if there is a bug in the automatic idle handling |
| 1254 | * for the IP block, it may need to be placed into the force-idle or |
| 1255 | * no-idle variants of these modes. No return value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1256 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1257 | static void _enable_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1258 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1259 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1260 | u32 v; |
Paul Walmsley | 006c7f1 | 2012-07-04 05:22:53 -0600 | [diff] [blame] | 1261 | bool clkdm_act; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 1262 | struct clockdomain *clkdm; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1263 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1264 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1265 | return; |
| 1266 | |
Tero Kristo | 613ad0e | 2012-10-29 22:02:13 -0600 | [diff] [blame] | 1267 | /* |
| 1268 | * Wait until reset has completed, this is needed as the IP |
| 1269 | * block is reset automatically by hardware in some cases |
| 1270 | * (off-mode for example), and the drivers require the |
| 1271 | * IP to be ready when they access it |
| 1272 | */ |
| 1273 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1274 | _enable_optional_clocks(oh); |
| 1275 | _wait_softreset_complete(oh); |
| 1276 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1277 | _disable_optional_clocks(oh); |
| 1278 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1279 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1280 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1281 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 1282 | clkdm = _get_clkdm(oh); |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1283 | if (sf & SYSC_HAS_SIDLEMODE) { |
Rajendra Nayak | ca43ea3 | 2013-05-15 20:18:38 +0530 | [diff] [blame] | 1284 | if (oh->flags & HWMOD_SWSUP_SIDLE || |
| 1285 | oh->flags & HWMOD_SWSUP_SIDLE_ACT) { |
Rajendra Nayak | 35513171 | 2013-05-15 20:18:37 +0530 | [diff] [blame] | 1286 | idlemode = HWMOD_IDLEMODE_NO; |
| 1287 | } else { |
| 1288 | if (sf & SYSC_HAS_ENAWAKEUP) |
| 1289 | _enable_wakeup(oh, &v); |
| 1290 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 1291 | idlemode = HWMOD_IDLEMODE_SMART_WKUP; |
| 1292 | else |
| 1293 | idlemode = HWMOD_IDLEMODE_SMART; |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * This is special handling for some IPs like |
| 1298 | * 32k sync timer. Force them to idle! |
| 1299 | */ |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 1300 | clkdm_act = (clkdm && clkdm->flags & CLKDM_ACTIVE_WITH_MPU); |
Paul Walmsley | 006c7f1 | 2012-07-04 05:22:53 -0600 | [diff] [blame] | 1301 | if (clkdm_act && !(oh->class->sysc->idlemodes & |
| 1302 | (SIDLE_SMART | SIDLE_SMART_WKUP))) |
| 1303 | idlemode = HWMOD_IDLEMODE_FORCE; |
Rajendra Nayak | 35513171 | 2013-05-15 20:18:37 +0530 | [diff] [blame] | 1304 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1305 | _set_slave_idlemode(oh, idlemode, &v); |
| 1306 | } |
| 1307 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1308 | if (sf & SYSC_HAS_MIDLEMODE) { |
Grazvydas Ignotas | 092bc08 | 2013-03-11 21:49:00 +0200 | [diff] [blame] | 1309 | if (oh->flags & HWMOD_FORCE_MSTANDBY) { |
| 1310 | idlemode = HWMOD_IDLEMODE_FORCE; |
| 1311 | } else if (oh->flags & HWMOD_SWSUP_MSTANDBY) { |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 1312 | idlemode = HWMOD_IDLEMODE_NO; |
| 1313 | } else { |
| 1314 | if (sf & SYSC_HAS_ENAWAKEUP) |
| 1315 | _enable_wakeup(oh, &v); |
| 1316 | if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP) |
| 1317 | idlemode = HWMOD_IDLEMODE_SMART_WKUP; |
| 1318 | else |
| 1319 | idlemode = HWMOD_IDLEMODE_SMART; |
| 1320 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1321 | _set_master_standbymode(oh, idlemode, &v); |
| 1322 | } |
| 1323 | |
Paul Walmsley | a16b1f7 | 2009-12-08 16:34:17 -0700 | [diff] [blame] | 1324 | /* |
| 1325 | * XXX The clock framework should handle this, by |
| 1326 | * calling into this code. But this must wait until the |
| 1327 | * clock structures are tagged with omap_hwmod entries |
| 1328 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1329 | if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) && |
| 1330 | (sf & SYSC_HAS_CLOCKACTIVITY)) |
Tony Lindgren | ca5339b | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 1331 | _set_clockactivity(oh, CLOCKACT_TEST_ICLK, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1332 | |
Lokesh Vutla | 3ca4a23 | 2016-03-26 23:08:55 -0600 | [diff] [blame] | 1333 | _write_sysconfig(v, oh); |
Hema HK | 78f26e8 | 2010-09-24 10:23:19 -0600 | [diff] [blame] | 1334 | |
| 1335 | /* |
| 1336 | * Set the autoidle bit only after setting the smartidle bit |
| 1337 | * Setting this will not have any impact on the other modules. |
| 1338 | */ |
| 1339 | if (sf & SYSC_HAS_AUTOIDLE) { |
| 1340 | idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ? |
| 1341 | 0 : 1; |
| 1342 | _set_module_autoidle(oh, idlemode, &v); |
| 1343 | _write_sysconfig(v, oh); |
| 1344 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1348 | * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1349 | * @oh: struct omap_hwmod * |
| 1350 | * |
| 1351 | * If module is marked as SWSUP_SIDLE, force the module into slave |
| 1352 | * idle; otherwise, configure it for smart-idle. If module is marked |
| 1353 | * as SWSUP_MSUSPEND, force the module into master standby; otherwise, |
| 1354 | * configure it for smart-standby. No return value. |
| 1355 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1356 | static void _idle_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1357 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1358 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1359 | u32 v; |
| 1360 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1361 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1362 | return; |
| 1363 | |
| 1364 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1365 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1366 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1367 | if (sf & SYSC_HAS_SIDLEMODE) { |
Rajendra Nayak | 35513171 | 2013-05-15 20:18:37 +0530 | [diff] [blame] | 1368 | if (oh->flags & HWMOD_SWSUP_SIDLE) { |
Paul Walmsley | 006c7f1 | 2012-07-04 05:22:53 -0600 | [diff] [blame] | 1369 | idlemode = HWMOD_IDLEMODE_FORCE; |
Rajendra Nayak | 35513171 | 2013-05-15 20:18:37 +0530 | [diff] [blame] | 1370 | } else { |
| 1371 | if (sf & SYSC_HAS_ENAWAKEUP) |
| 1372 | _enable_wakeup(oh, &v); |
| 1373 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 1374 | idlemode = HWMOD_IDLEMODE_SMART_WKUP; |
| 1375 | else |
| 1376 | idlemode = HWMOD_IDLEMODE_SMART; |
| 1377 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1378 | _set_slave_idlemode(oh, idlemode, &v); |
| 1379 | } |
| 1380 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1381 | if (sf & SYSC_HAS_MIDLEMODE) { |
Grazvydas Ignotas | 092bc08 | 2013-03-11 21:49:00 +0200 | [diff] [blame] | 1382 | if ((oh->flags & HWMOD_SWSUP_MSTANDBY) || |
| 1383 | (oh->flags & HWMOD_FORCE_MSTANDBY)) { |
Benoit Cousson | 724019b | 2011-07-01 22:54:00 +0200 | [diff] [blame] | 1384 | idlemode = HWMOD_IDLEMODE_FORCE; |
| 1385 | } else { |
| 1386 | if (sf & SYSC_HAS_ENAWAKEUP) |
| 1387 | _enable_wakeup(oh, &v); |
| 1388 | if (oh->class->sysc->idlemodes & MSTANDBY_SMART_WKUP) |
| 1389 | idlemode = HWMOD_IDLEMODE_SMART_WKUP; |
| 1390 | else |
| 1391 | idlemode = HWMOD_IDLEMODE_SMART; |
| 1392 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1393 | _set_master_standbymode(oh, idlemode, &v); |
| 1394 | } |
| 1395 | |
Lokesh Vutla | 3ca4a23 | 2016-03-26 23:08:55 -0600 | [diff] [blame] | 1396 | /* If the cached value is the same as the new value, skip the write */ |
| 1397 | if (oh->_sysc_cache != v) |
| 1398 | _write_sysconfig(v, oh); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1402 | * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1403 | * @oh: struct omap_hwmod * |
| 1404 | * |
| 1405 | * Force the module into slave idle and master suspend. No return |
| 1406 | * value. |
| 1407 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1408 | static void _shutdown_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1409 | { |
| 1410 | u32 v; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1411 | u8 sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1412 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1413 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1414 | return; |
| 1415 | |
| 1416 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1417 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1418 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1419 | if (sf & SYSC_HAS_SIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1420 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 1421 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1422 | if (sf & SYSC_HAS_MIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1423 | _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 1424 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1425 | if (sf & SYSC_HAS_AUTOIDLE) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 1426 | _set_module_autoidle(oh, 1, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1427 | |
| 1428 | _write_sysconfig(v, oh); |
| 1429 | } |
| 1430 | |
| 1431 | /** |
| 1432 | * _lookup - find an omap_hwmod by name |
| 1433 | * @name: find an omap_hwmod by name |
| 1434 | * |
| 1435 | * Return a pointer to an omap_hwmod by name, or NULL if not found. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1436 | */ |
| 1437 | static struct omap_hwmod *_lookup(const char *name) |
| 1438 | { |
| 1439 | struct omap_hwmod *oh, *temp_oh; |
| 1440 | |
| 1441 | oh = NULL; |
| 1442 | |
| 1443 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 1444 | if (!strcmp(name, temp_oh->name)) { |
| 1445 | oh = temp_oh; |
| 1446 | break; |
| 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | return oh; |
| 1451 | } |
Paul Walmsley | 868c157 | 2012-06-19 15:01:02 -0600 | [diff] [blame] | 1452 | |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1453 | /** |
| 1454 | * _init_clkdm - look up a clockdomain name, store pointer in omap_hwmod |
| 1455 | * @oh: struct omap_hwmod * |
| 1456 | * |
| 1457 | * Convert a clockdomain name stored in a struct omap_hwmod into a |
| 1458 | * clockdomain pointer, and save it into the struct omap_hwmod. |
Paul Walmsley | 868c157 | 2012-06-19 15:01:02 -0600 | [diff] [blame] | 1459 | * Return -EINVAL if the clkdm_name lookup failed. |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1460 | */ |
| 1461 | static int _init_clkdm(struct omap_hwmod *oh) |
| 1462 | { |
Paul Walmsley | 3bb05db | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 1463 | if (!oh->clkdm_name) { |
| 1464 | pr_debug("omap_hwmod: %s: missing clockdomain\n", oh->name); |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1465 | return 0; |
Paul Walmsley | 3bb05db | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 1466 | } |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1467 | |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1468 | oh->clkdm = clkdm_lookup(oh->clkdm_name); |
| 1469 | if (!oh->clkdm) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 1470 | pr_warn("omap_hwmod: %s: could not associate to clkdm %s\n", |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1471 | oh->name, oh->clkdm_name); |
Tero Kristo | 0385c58 | 2013-07-17 18:03:25 +0300 | [diff] [blame] | 1472 | return 0; |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | pr_debug("omap_hwmod: %s: associated to clkdm %s\n", |
| 1476 | oh->name, oh->clkdm_name); |
| 1477 | |
| 1478 | return 0; |
| 1479 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1480 | |
| 1481 | /** |
Benoit Cousson | 6ae7699 | 2011-07-10 05:56:30 -0600 | [diff] [blame] | 1482 | * _init_clocks - clk_get() all clocks associated with this hwmod. Retrieve as |
| 1483 | * well the clockdomain. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1484 | * @oh: struct omap_hwmod * |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1485 | * @data: not used; pass NULL |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1486 | * |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 1487 | * Called by omap_hwmod_setup_*() (after omap2_clk_init()). |
Paul Walmsley | 48d54f3 | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 1488 | * Resolves all clock names embedded in the hwmod. Returns 0 on |
| 1489 | * success, or a negative error code on failure. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1490 | */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1491 | static int _init_clocks(struct omap_hwmod *oh, void *data) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1492 | { |
| 1493 | int ret = 0; |
| 1494 | |
Paul Walmsley | 48d54f3 | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 1495 | if (oh->_state != _HWMOD_STATE_REGISTERED) |
| 1496 | return 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1497 | |
| 1498 | pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name); |
| 1499 | |
Vaibhav Hiremath | b797be1d | 2012-07-09 18:24:30 +0530 | [diff] [blame] | 1500 | if (soc_ops.init_clkdm) |
| 1501 | ret |= soc_ops.init_clkdm(oh); |
| 1502 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1503 | ret |= _init_main_clk(oh); |
| 1504 | ret |= _init_interface_clks(oh); |
| 1505 | ret |= _init_opt_clks(oh); |
| 1506 | |
Benoit Cousson | f5c1f84 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 1507 | if (!ret) |
| 1508 | oh->_state = _HWMOD_STATE_CLKS_INITED; |
Benoit Cousson | 6652271 | 2011-07-01 22:54:06 +0200 | [diff] [blame] | 1509 | else |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 1510 | pr_warn("omap_hwmod: %s: cannot _init_clocks\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1511 | |
Rajendra Nayak | 09c35f2 | 2011-02-16 12:11:24 +0000 | [diff] [blame] | 1512 | return ret; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /** |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1516 | * _lookup_hardreset - fill register bit info for this hwmod/reset line |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1517 | * @oh: struct omap_hwmod * |
| 1518 | * @name: name of the reset line in the context of this hwmod |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1519 | * @ohri: struct omap_hwmod_rst_info * that this function will fill in |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1520 | * |
| 1521 | * Return the bit position of the reset line that match the |
| 1522 | * input name. Return -ENOENT if not found. |
| 1523 | */ |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 1524 | static int _lookup_hardreset(struct omap_hwmod *oh, const char *name, |
| 1525 | struct omap_hwmod_rst_info *ohri) |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1526 | { |
| 1527 | int i; |
| 1528 | |
| 1529 | for (i = 0; i < oh->rst_lines_cnt; i++) { |
| 1530 | const char *rst_line = oh->rst_lines[i].name; |
| 1531 | if (!strcmp(rst_line, name)) { |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1532 | ohri->rst_shift = oh->rst_lines[i].rst_shift; |
| 1533 | ohri->st_shift = oh->rst_lines[i].st_shift; |
| 1534 | pr_debug("omap_hwmod: %s: %s: %s: rst %d st %d\n", |
| 1535 | oh->name, __func__, rst_line, ohri->rst_shift, |
| 1536 | ohri->st_shift); |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1537 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1538 | return 0; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | return -ENOENT; |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * _assert_hardreset - assert the HW reset line of submodules |
| 1547 | * contained in the hwmod module. |
| 1548 | * @oh: struct omap_hwmod * |
| 1549 | * @name: name of the reset line to lookup and assert |
| 1550 | * |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1551 | * Some IP like dsp, ipu or iva contain processor that require an HW |
| 1552 | * reset line to be assert / deassert in order to enable fully the IP. |
| 1553 | * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of |
| 1554 | * asserting the hardreset line on the currently-booted SoC, or passes |
| 1555 | * along the return value from _lookup_hardreset() or the SoC's |
| 1556 | * assert_hardreset code. |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1557 | */ |
| 1558 | static int _assert_hardreset(struct omap_hwmod *oh, const char *name) |
| 1559 | { |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1560 | struct omap_hwmod_rst_info ohri; |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 1561 | int ret = -EINVAL; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1562 | |
| 1563 | if (!oh) |
| 1564 | return -EINVAL; |
| 1565 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1566 | if (!soc_ops.assert_hardreset) |
| 1567 | return -ENOSYS; |
| 1568 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1569 | ret = _lookup_hardreset(oh, name, &ohri); |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 1570 | if (ret < 0) |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1571 | return ret; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1572 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1573 | ret = soc_ops.assert_hardreset(oh, &ohri); |
| 1574 | |
| 1575 | return ret; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * _deassert_hardreset - deassert the HW reset line of submodules contained |
| 1580 | * in the hwmod module. |
| 1581 | * @oh: struct omap_hwmod * |
| 1582 | * @name: name of the reset line to look up and deassert |
| 1583 | * |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1584 | * Some IP like dsp, ipu or iva contain processor that require an HW |
| 1585 | * reset line to be assert / deassert in order to enable fully the IP. |
| 1586 | * Returns -EINVAL if @oh is null, -ENOSYS if we have no way of |
| 1587 | * deasserting the hardreset line on the currently-booted SoC, or passes |
| 1588 | * along the return value from _lookup_hardreset() or the SoC's |
| 1589 | * deassert_hardreset code. |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1590 | */ |
| 1591 | static int _deassert_hardreset(struct omap_hwmod *oh, const char *name) |
| 1592 | { |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1593 | struct omap_hwmod_rst_info ohri; |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1594 | int ret = -EINVAL; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1595 | |
| 1596 | if (!oh) |
| 1597 | return -EINVAL; |
| 1598 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1599 | if (!soc_ops.deassert_hardreset) |
| 1600 | return -ENOSYS; |
| 1601 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1602 | ret = _lookup_hardreset(oh, name, &ohri); |
Russell King | c48cd65 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 1603 | if (ret < 0) |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1604 | return ret; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1605 | |
Omar Ramirez Luna | e8e96df | 2012-09-23 17:28:21 -0600 | [diff] [blame] | 1606 | if (oh->clkdm) { |
| 1607 | /* |
| 1608 | * A clockdomain must be in SW_SUP otherwise reset |
| 1609 | * might not be completed. The clockdomain can be set |
| 1610 | * in HW_AUTO only when the module become ready. |
| 1611 | */ |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 1612 | clkdm_deny_idle(oh->clkdm); |
Omar Ramirez Luna | e8e96df | 2012-09-23 17:28:21 -0600 | [diff] [blame] | 1613 | ret = clkdm_hwmod_enable(oh->clkdm, oh); |
| 1614 | if (ret) { |
| 1615 | WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n", |
| 1616 | oh->name, oh->clkdm->name, ret); |
| 1617 | return ret; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | _enable_clocks(oh); |
| 1622 | if (soc_ops.enable_module) |
| 1623 | soc_ops.enable_module(oh); |
| 1624 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1625 | ret = soc_ops.deassert_hardreset(oh, &ohri); |
Omar Ramirez Luna | e8e96df | 2012-09-23 17:28:21 -0600 | [diff] [blame] | 1626 | |
| 1627 | if (soc_ops.disable_module) |
| 1628 | soc_ops.disable_module(oh); |
| 1629 | _disable_clocks(oh); |
| 1630 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1631 | if (ret == -EBUSY) |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 1632 | pr_warn("omap_hwmod: %s: failed to hardreset\n", oh->name); |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1633 | |
Tero Kristo | 80d2518 | 2015-02-26 18:06:00 +0200 | [diff] [blame] | 1634 | if (oh->clkdm) { |
Omar Ramirez Luna | e8e96df | 2012-09-23 17:28:21 -0600 | [diff] [blame] | 1635 | /* |
| 1636 | * Set the clockdomain to HW_AUTO, assuming that the |
| 1637 | * previous state was HW_AUTO. |
| 1638 | */ |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 1639 | clkdm_allow_idle(oh->clkdm); |
Tero Kristo | 80d2518 | 2015-02-26 18:06:00 +0200 | [diff] [blame] | 1640 | |
| 1641 | clkdm_hwmod_disable(oh->clkdm, oh); |
Omar Ramirez Luna | e8e96df | 2012-09-23 17:28:21 -0600 | [diff] [blame] | 1642 | } |
| 1643 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1644 | return ret; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /** |
| 1648 | * _read_hardreset - read the HW reset line state of submodules |
| 1649 | * contained in the hwmod module |
| 1650 | * @oh: struct omap_hwmod * |
| 1651 | * @name: name of the reset line to look up and read |
| 1652 | * |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1653 | * Return the state of the reset line. Returns -EINVAL if @oh is |
| 1654 | * null, -ENOSYS if we have no way of reading the hardreset line |
| 1655 | * status on the currently-booted SoC, or passes along the return |
| 1656 | * value from _lookup_hardreset() or the SoC's is_hardreset_asserted |
| 1657 | * code. |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1658 | */ |
| 1659 | static int _read_hardreset(struct omap_hwmod *oh, const char *name) |
| 1660 | { |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1661 | struct omap_hwmod_rst_info ohri; |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 1662 | int ret = -EINVAL; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1663 | |
| 1664 | if (!oh) |
| 1665 | return -EINVAL; |
| 1666 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1667 | if (!soc_ops.is_hardreset_asserted) |
| 1668 | return -ENOSYS; |
| 1669 | |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1670 | ret = _lookup_hardreset(oh, name, &ohri); |
Paul Walmsley | a032d33 | 2012-08-03 09:21:10 -0600 | [diff] [blame] | 1671 | if (ret < 0) |
omar ramirez | cc1226e | 2011-03-04 13:32:44 -0700 | [diff] [blame] | 1672 | return ret; |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1673 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 1674 | return soc_ops.is_hardreset_asserted(oh, &ohri); |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1678 | * _are_all_hardreset_lines_asserted - return true if the @oh is hard-reset |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1679 | * @oh: struct omap_hwmod * |
| 1680 | * |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1681 | * If all hardreset lines associated with @oh are asserted, then return true. |
| 1682 | * Otherwise, if part of @oh is out hardreset or if no hardreset lines |
| 1683 | * associated with @oh are asserted, then return false. |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1684 | * This function is used to avoid executing some parts of the IP block |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1685 | * enable/disable sequence if its hardreset line is set. |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1686 | */ |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1687 | static bool _are_all_hardreset_lines_asserted(struct omap_hwmod *oh) |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1688 | { |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1689 | int i, rst_cnt = 0; |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1690 | |
| 1691 | if (oh->rst_lines_cnt == 0) |
| 1692 | return false; |
| 1693 | |
| 1694 | for (i = 0; i < oh->rst_lines_cnt; i++) |
| 1695 | if (_read_hardreset(oh, oh->rst_lines[i].name) > 0) |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1696 | rst_cnt++; |
| 1697 | |
| 1698 | if (oh->rst_lines_cnt == rst_cnt) |
| 1699 | return true; |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1700 | |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | /** |
Paul Walmsley | e9332b6 | 2012-10-08 23:08:15 -0600 | [diff] [blame] | 1705 | * _are_any_hardreset_lines_asserted - return true if any part of @oh is |
| 1706 | * hard-reset |
| 1707 | * @oh: struct omap_hwmod * |
| 1708 | * |
| 1709 | * If any hardreset lines associated with @oh are asserted, then |
| 1710 | * return true. Otherwise, if no hardreset lines associated with @oh |
| 1711 | * are asserted, or if @oh has no hardreset lines, then return false. |
| 1712 | * This function is used to avoid executing some parts of the IP block |
| 1713 | * enable/disable sequence if any hardreset line is set. |
| 1714 | */ |
| 1715 | static bool _are_any_hardreset_lines_asserted(struct omap_hwmod *oh) |
| 1716 | { |
| 1717 | int rst_cnt = 0; |
| 1718 | int i; |
| 1719 | |
| 1720 | for (i = 0; i < oh->rst_lines_cnt && rst_cnt == 0; i++) |
| 1721 | if (_read_hardreset(oh, oh->rst_lines[i].name) > 0) |
| 1722 | rst_cnt++; |
| 1723 | |
| 1724 | return (rst_cnt) ? true : false; |
| 1725 | } |
| 1726 | |
| 1727 | /** |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1728 | * _omap4_disable_module - enable CLKCTRL modulemode on OMAP4 |
| 1729 | * @oh: struct omap_hwmod * |
| 1730 | * |
| 1731 | * Disable the PRCM module mode related to the hwmod @oh. |
| 1732 | * Return EINVAL if the modulemode is not supported and 0 in case of success. |
| 1733 | */ |
| 1734 | static int _omap4_disable_module(struct omap_hwmod *oh) |
| 1735 | { |
| 1736 | int v; |
| 1737 | |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1738 | if (!oh->clkdm || !oh->prcm.omap4.modulemode) |
| 1739 | return -EINVAL; |
| 1740 | |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1741 | /* |
| 1742 | * Since integration code might still be doing something, only |
| 1743 | * disable if all lines are under hardreset. |
| 1744 | */ |
Paul Walmsley | e9332b6 | 2012-10-08 23:08:15 -0600 | [diff] [blame] | 1745 | if (_are_any_hardreset_lines_asserted(oh)) |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1746 | return 0; |
| 1747 | |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1748 | pr_debug("omap_hwmod: %s: %s\n", oh->name, __func__); |
| 1749 | |
Tero Kristo | 128603f | 2014-10-27 08:39:24 -0700 | [diff] [blame] | 1750 | omap_cm_module_disable(oh->clkdm->prcm_partition, oh->clkdm->cm_inst, |
| 1751 | oh->prcm.omap4.clkctrl_offs); |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1752 | |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1753 | v = _omap4_wait_target_disable(oh); |
| 1754 | if (v) |
| 1755 | pr_warn("omap_hwmod: %s: _wait_target_disable failed\n", |
| 1756 | oh->name); |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
| 1761 | /** |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1762 | * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1763 | * @oh: struct omap_hwmod * |
| 1764 | * |
| 1765 | * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1766 | * enabled for this to work. Returns -ENOENT if the hwmod cannot be |
| 1767 | * reset this way, -EINVAL if the hwmod is in the wrong state, |
| 1768 | * -ETIMEDOUT if the module did not reset in time, or 0 upon success. |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1769 | * |
| 1770 | * In OMAP3 a specific SYSSTATUS register is used to get the reset status. |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1771 | * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1772 | * use the SYSCONFIG softreset bit to provide the status. |
| 1773 | * |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1774 | * Note that some IP like McBSP do have reset control but don't have |
| 1775 | * reset status. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1776 | */ |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1777 | static int _ocp_softreset(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1778 | { |
Tero Kristo | 613ad0e | 2012-10-29 22:02:13 -0600 | [diff] [blame] | 1779 | u32 v; |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 1780 | int c = 0; |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1781 | int ret = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1782 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1783 | if (!oh->class->sysc || |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1784 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1785 | return -ENOENT; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1786 | |
| 1787 | /* clocks must be on for this operation */ |
| 1788 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 1789 | pr_warn("omap_hwmod: %s: reset can only be entered from enabled state\n", |
| 1790 | oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1791 | return -EINVAL; |
| 1792 | } |
| 1793 | |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1794 | /* For some modules, all optionnal clocks need to be enabled as well */ |
| 1795 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1796 | _enable_optional_clocks(oh); |
| 1797 | |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1798 | pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1799 | |
| 1800 | v = oh->_sysc_cache; |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1801 | ret = _set_softreset(oh, &v); |
| 1802 | if (ret) |
| 1803 | goto dis_opt_clks; |
Roger Quadros | 313a76e | 2013-12-08 18:39:02 -0700 | [diff] [blame] | 1804 | |
| 1805 | _write_sysconfig(v, oh); |
Illia Smyrnov | 0114251 | 2014-02-05 17:06:09 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (oh->class->sysc->srst_udelay) |
| 1808 | udelay(oh->class->sysc->srst_udelay); |
| 1809 | |
| 1810 | c = _wait_softreset_complete(oh); |
| 1811 | if (c == MAX_MODULE_SOFTRESET_WAIT) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 1812 | pr_warn("omap_hwmod: %s: softreset failed (waited %d usec)\n", |
| 1813 | oh->name, MAX_MODULE_SOFTRESET_WAIT); |
Illia Smyrnov | 0114251 | 2014-02-05 17:06:09 +0200 | [diff] [blame] | 1814 | ret = -ETIMEDOUT; |
| 1815 | goto dis_opt_clks; |
| 1816 | } else { |
| 1817 | pr_debug("omap_hwmod: %s: softreset in %d usec\n", oh->name, c); |
| 1818 | } |
| 1819 | |
Roger Quadros | 313a76e | 2013-12-08 18:39:02 -0700 | [diff] [blame] | 1820 | ret = _clear_softreset(oh, &v); |
| 1821 | if (ret) |
| 1822 | goto dis_opt_clks; |
| 1823 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1824 | _write_sysconfig(v, oh); |
| 1825 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1826 | /* |
| 1827 | * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from |
| 1828 | * _wait_target_ready() or _reset() |
| 1829 | */ |
| 1830 | |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1831 | dis_opt_clks: |
| 1832 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1833 | _disable_optional_clocks(oh); |
| 1834 | |
| 1835 | return ret; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /** |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1839 | * _reset - reset an omap_hwmod |
| 1840 | * @oh: struct omap_hwmod * |
| 1841 | * |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1842 | * Resets an omap_hwmod @oh. If the module has a custom reset |
| 1843 | * function pointer defined, then call it to reset the IP block, and |
| 1844 | * pass along its return value to the caller. Otherwise, if the IP |
| 1845 | * block has an OCP_SYSCONFIG register with a SOFTRESET bitfield |
| 1846 | * associated with it, call a function to reset the IP block via that |
| 1847 | * method, and pass along the return value to the caller. Finally, if |
| 1848 | * the IP block has some hardreset lines associated with it, assert |
| 1849 | * all of those, but do _not_ deassert them. (This is because driver |
| 1850 | * authors have expressed an apparent requirement to control the |
| 1851 | * deassertion of the hardreset lines themselves.) |
| 1852 | * |
| 1853 | * The default software reset mechanism for most OMAP IP blocks is |
| 1854 | * triggered via the OCP_SYSCONFIG.SOFTRESET bit. However, some |
| 1855 | * hwmods cannot be reset via this method. Some are not targets and |
| 1856 | * therefore have no OCP header registers to access. Others (like the |
| 1857 | * IVA) have idiosyncratic reset sequences. So for these relatively |
| 1858 | * rare cases, custom reset code can be supplied in the struct |
Kishon Vijay Abraham I | 6668546 | 2012-07-04 05:09:21 -0600 | [diff] [blame] | 1859 | * omap_hwmod_class .reset function pointer. |
| 1860 | * |
| 1861 | * _set_dmadisable() is called to set the DMADISABLE bit so that it |
| 1862 | * does not prevent idling of the system. This is necessary for cases |
| 1863 | * where ROMCODE/BOOTLOADER uses dma and transfers control to the |
| 1864 | * kernel without disabling dma. |
| 1865 | * |
| 1866 | * Passes along the return value from either _ocp_softreset() or the |
| 1867 | * custom reset function - these must return -EINVAL if the hwmod |
| 1868 | * cannot be reset this way or if the hwmod is in the wrong state, |
| 1869 | * -ETIMEDOUT if the module did not reset in time, or 0 upon success. |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1870 | */ |
| 1871 | static int _reset(struct omap_hwmod *oh) |
| 1872 | { |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1873 | int i, r; |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1874 | |
| 1875 | pr_debug("omap_hwmod: %s: resetting\n", oh->name); |
| 1876 | |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1877 | if (oh->class->reset) { |
| 1878 | r = oh->class->reset(oh); |
| 1879 | } else { |
| 1880 | if (oh->rst_lines_cnt > 0) { |
| 1881 | for (i = 0; i < oh->rst_lines_cnt; i++) |
| 1882 | _assert_hardreset(oh, oh->rst_lines[i].name); |
| 1883 | return 0; |
| 1884 | } else { |
| 1885 | r = _ocp_softreset(oh); |
| 1886 | if (r == -ENOENT) |
| 1887 | r = 0; |
| 1888 | } |
| 1889 | } |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1890 | |
Kishon Vijay Abraham I | 6668546 | 2012-07-04 05:09:21 -0600 | [diff] [blame] | 1891 | _set_dmadisable(oh); |
| 1892 | |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1893 | /* |
| 1894 | * OCP_SYSCONFIG bits need to be reprogrammed after a |
| 1895 | * softreset. The _enable() function should be split to avoid |
| 1896 | * the rewrite of the OCP_SYSCONFIG register. |
| 1897 | */ |
Rajendra Nayak | 2800852 | 2012-03-13 22:55:23 +0530 | [diff] [blame] | 1898 | if (oh->class->sysc) { |
| 1899 | _update_sysc_cache(oh); |
| 1900 | _enable_sysc(oh); |
| 1901 | } |
| 1902 | |
Paul Walmsley | 30e105c | 2012-04-19 00:49:09 -0600 | [diff] [blame] | 1903 | return r; |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /** |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 1907 | * _omap4_update_context_lost - increment hwmod context loss counter if |
| 1908 | * hwmod context was lost, and clear hardware context loss reg |
| 1909 | * @oh: hwmod to check for context loss |
| 1910 | * |
| 1911 | * If the PRCM indicates that the hwmod @oh lost context, increment |
| 1912 | * our in-memory context loss counter, and clear the RM_*_CONTEXT |
| 1913 | * bits. No return value. |
| 1914 | */ |
| 1915 | static void _omap4_update_context_lost(struct omap_hwmod *oh) |
| 1916 | { |
| 1917 | if (oh->prcm.omap4.flags & HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT) |
| 1918 | return; |
| 1919 | |
| 1920 | if (!prm_was_any_context_lost_old(oh->clkdm->pwrdm.ptr->prcm_partition, |
| 1921 | oh->clkdm->pwrdm.ptr->prcm_offs, |
| 1922 | oh->prcm.omap4.context_offs)) |
| 1923 | return; |
| 1924 | |
| 1925 | oh->prcm.omap4.context_lost_counter++; |
| 1926 | prm_clear_context_loss_flags_old(oh->clkdm->pwrdm.ptr->prcm_partition, |
| 1927 | oh->clkdm->pwrdm.ptr->prcm_offs, |
| 1928 | oh->prcm.omap4.context_offs); |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * _omap4_get_context_lost - get context loss counter for a hwmod |
| 1933 | * @oh: hwmod to get context loss counter for |
| 1934 | * |
| 1935 | * Returns the in-memory context loss counter for a hwmod. |
| 1936 | */ |
| 1937 | static int _omap4_get_context_lost(struct omap_hwmod *oh) |
| 1938 | { |
| 1939 | return oh->prcm.omap4.context_lost_counter; |
| 1940 | } |
| 1941 | |
| 1942 | /** |
Paul Walmsley | 6d266f6 | 2013-02-10 11:22:22 -0700 | [diff] [blame] | 1943 | * _enable_preprogram - Pre-program an IP block during the _enable() process |
| 1944 | * @oh: struct omap_hwmod * |
| 1945 | * |
| 1946 | * Some IP blocks (such as AESS) require some additional programming |
| 1947 | * after enable before they can enter idle. If a function pointer to |
| 1948 | * do so is present in the hwmod data, then call it and pass along the |
| 1949 | * return value; otherwise, return 0. |
| 1950 | */ |
jean-philippe francois | 0f49703 | 2013-05-16 11:25:07 -0700 | [diff] [blame] | 1951 | static int _enable_preprogram(struct omap_hwmod *oh) |
Paul Walmsley | 6d266f6 | 2013-02-10 11:22:22 -0700 | [diff] [blame] | 1952 | { |
| 1953 | if (!oh->class->enable_preprogram) |
| 1954 | return 0; |
| 1955 | |
| 1956 | return oh->class->enable_preprogram(oh); |
| 1957 | } |
| 1958 | |
| 1959 | /** |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1960 | * _enable - enable an omap_hwmod |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1961 | * @oh: struct omap_hwmod * |
| 1962 | * |
| 1963 | * Enables an omap_hwmod @oh such that the MPU can access the hwmod's |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1964 | * register target. Returns -EINVAL if the hwmod is in the wrong |
| 1965 | * state or passes along the return value of _wait_target_ready(). |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1966 | */ |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1967 | static int _enable(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1968 | { |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1969 | int r; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1970 | |
Benoit Cousson | 34617e2 | 2011-07-01 22:54:07 +0200 | [diff] [blame] | 1971 | pr_debug("omap_hwmod: %s: enabling\n", oh->name); |
| 1972 | |
Rajendra Nayak | aacf094 | 2011-12-16 05:50:12 -0700 | [diff] [blame] | 1973 | /* |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 1974 | * hwmods with HWMOD_INIT_NO_IDLE flag set are left in enabled |
Tony Lindgren | b428145 | 2016-10-20 06:35:21 -0700 | [diff] [blame] | 1975 | * state at init. |
Rajendra Nayak | aacf094 | 2011-12-16 05:50:12 -0700 | [diff] [blame] | 1976 | */ |
| 1977 | if (oh->_int_flags & _HWMOD_SKIP_ENABLE) { |
Rajendra Nayak | aacf094 | 2011-12-16 05:50:12 -0700 | [diff] [blame] | 1978 | oh->_int_flags &= ~_HWMOD_SKIP_ENABLE; |
| 1979 | return 0; |
| 1980 | } |
| 1981 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1982 | if (oh->_state != _HWMOD_STATE_INITIALIZED && |
| 1983 | oh->_state != _HWMOD_STATE_IDLE && |
| 1984 | oh->_state != _HWMOD_STATE_DISABLED) { |
Russell King | 4f8a428 | 2012-02-07 10:59:37 +0000 | [diff] [blame] | 1985 | WARN(1, "omap_hwmod: %s: enabled state can only be entered from initialized, idle, or disabled state\n", |
| 1986 | oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1987 | return -EINVAL; |
| 1988 | } |
| 1989 | |
Benoit Cousson | 31f6286 | 2011-07-01 22:54:05 +0200 | [diff] [blame] | 1990 | /* |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1991 | * If an IP block contains HW reset lines and all of them are |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 1992 | * asserted, we let integration code associated with that |
| 1993 | * block handle the enable. We've received very little |
| 1994 | * information on what those driver authors need, and until |
| 1995 | * detailed information is provided and the driver code is |
| 1996 | * posted to the public lists, this is probably the best we |
| 1997 | * can do. |
Benoit Cousson | 31f6286 | 2011-07-01 22:54:05 +0200 | [diff] [blame] | 1998 | */ |
Omar Ramirez Luna | eb05f69 | 2012-09-23 17:28:20 -0600 | [diff] [blame] | 1999 | if (_are_all_hardreset_lines_asserted(oh)) |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 2000 | return 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2001 | |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2002 | _add_initiator_dep(oh, mpu_oh); |
| 2003 | |
| 2004 | if (oh->clkdm) { |
| 2005 | /* |
| 2006 | * A clockdomain must be in SW_SUP before enabling |
| 2007 | * completely the module. The clockdomain can be set |
| 2008 | * in HW_AUTO only when the module become ready. |
| 2009 | */ |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2010 | clkdm_deny_idle(oh->clkdm); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2011 | r = clkdm_hwmod_enable(oh->clkdm, oh); |
| 2012 | if (r) { |
| 2013 | WARN(1, "omap_hwmod: %s: could not enable clockdomain %s: %d\n", |
| 2014 | oh->name, oh->clkdm->name, r); |
| 2015 | return r; |
| 2016 | } |
Benoit Cousson | 34617e2 | 2011-07-01 22:54:07 +0200 | [diff] [blame] | 2017 | } |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2018 | |
| 2019 | _enable_clocks(oh); |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 2020 | if (soc_ops.enable_module) |
| 2021 | soc_ops.enable_module(oh); |
Paul Walmsley | fa20022 | 2013-01-26 00:48:56 -0700 | [diff] [blame] | 2022 | if (oh->flags & HWMOD_BLOCK_WFI) |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 2023 | cpu_idle_poll_ctrl(true); |
Benoit Cousson | 34617e2 | 2011-07-01 22:54:07 +0200 | [diff] [blame] | 2024 | |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 2025 | if (soc_ops.update_context_lost) |
| 2026 | soc_ops.update_context_lost(oh); |
| 2027 | |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2028 | r = (soc_ops.wait_target_ready) ? soc_ops.wait_target_ready(oh) : |
| 2029 | -EINVAL; |
Roger Quadros | 8ff42da | 2017-03-17 10:58:18 +0200 | [diff] [blame] | 2030 | if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO)) |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2031 | clkdm_allow_idle(oh->clkdm); |
Benoit Cousson | 34617e2 | 2011-07-01 22:54:07 +0200 | [diff] [blame] | 2032 | |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2033 | if (!r) { |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2034 | oh->_state = _HWMOD_STATE_ENABLED; |
| 2035 | |
| 2036 | /* Access the sysconfig only if the target is ready */ |
| 2037 | if (oh->class->sysc) { |
| 2038 | if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED)) |
| 2039 | _update_sysc_cache(oh); |
| 2040 | _enable_sysc(oh); |
| 2041 | } |
Paul Walmsley | 6d266f6 | 2013-02-10 11:22:22 -0700 | [diff] [blame] | 2042 | r = _enable_preprogram(oh); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2043 | } else { |
Paul Walmsley | 2577a4a | 2012-10-29 20:57:55 -0600 | [diff] [blame] | 2044 | if (soc_ops.disable_module) |
| 2045 | soc_ops.disable_module(oh); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2046 | _disable_clocks(oh); |
Lokesh Vutla | 812ce9d | 2014-12-19 18:04:50 +0530 | [diff] [blame] | 2047 | pr_err("omap_hwmod: %s: _wait_target_ready failed: %d\n", |
| 2048 | oh->name, r); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2049 | |
| 2050 | if (oh->clkdm) |
| 2051 | clkdm_hwmod_disable(oh->clkdm, oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 2052 | } |
| 2053 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2054 | return r; |
| 2055 | } |
| 2056 | |
| 2057 | /** |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2058 | * _idle - idle an omap_hwmod |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2059 | * @oh: struct omap_hwmod * |
| 2060 | * |
| 2061 | * Idles an omap_hwmod @oh. This should be called once the hwmod has |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2062 | * no further work. Returns -EINVAL if the hwmod is in the wrong |
| 2063 | * state or returns 0. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2064 | */ |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2065 | static int _idle(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2066 | { |
Lokesh Vutla | 2e18f5a | 2016-03-07 01:41:21 -0700 | [diff] [blame] | 2067 | if (oh->flags & HWMOD_NO_IDLE) { |
| 2068 | oh->_int_flags |= _HWMOD_SKIP_ENABLE; |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
Benoit Cousson | 34617e2 | 2011-07-01 22:54:07 +0200 | [diff] [blame] | 2072 | pr_debug("omap_hwmod: %s: idling\n", oh->name); |
| 2073 | |
Suman Anna | c20c8f7 | 2016-04-10 13:20:11 -0600 | [diff] [blame] | 2074 | if (_are_all_hardreset_lines_asserted(oh)) |
| 2075 | return 0; |
| 2076 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2077 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
Russell King | 4f8a428 | 2012-02-07 10:59:37 +0000 | [diff] [blame] | 2078 | WARN(1, "omap_hwmod: %s: idle state can only be entered from enabled state\n", |
| 2079 | oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2080 | return -EINVAL; |
| 2081 | } |
| 2082 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2083 | if (oh->class->sysc) |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 2084 | _idle_sysc(oh); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2085 | _del_initiator_dep(oh, mpu_oh); |
Benoit Cousson | bfc141e | 2011-12-16 16:09:11 -0800 | [diff] [blame] | 2086 | |
Roger Quadros | 8ff42da | 2017-03-17 10:58:18 +0200 | [diff] [blame] | 2087 | /* |
| 2088 | * If HWMOD_CLKDM_NOAUTO is set then we don't |
| 2089 | * deny idle the clkdm again since idle was already denied |
| 2090 | * in _enable() |
| 2091 | */ |
| 2092 | if (oh->clkdm && !(oh->flags & HWMOD_CLKDM_NOAUTO)) |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2093 | clkdm_deny_idle(oh->clkdm); |
| 2094 | |
Paul Walmsley | fa20022 | 2013-01-26 00:48:56 -0700 | [diff] [blame] | 2095 | if (oh->flags & HWMOD_BLOCK_WFI) |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 2096 | cpu_idle_poll_ctrl(false); |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 2097 | if (soc_ops.disable_module) |
| 2098 | soc_ops.disable_module(oh); |
Benoit Cousson | bfc141e | 2011-12-16 16:09:11 -0800 | [diff] [blame] | 2099 | |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 2100 | /* |
| 2101 | * The module must be in idle mode before disabling any parents |
| 2102 | * clocks. Otherwise, the parent clock might be disabled before |
| 2103 | * the module transition is done, and thus will prevent the |
| 2104 | * transition to complete properly. |
| 2105 | */ |
| 2106 | _disable_clocks(oh); |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2107 | if (oh->clkdm) { |
| 2108 | clkdm_allow_idle(oh->clkdm); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2109 | clkdm_hwmod_disable(oh->clkdm, oh); |
Tero Kristo | 1d9a542 | 2016-06-30 16:15:02 +0300 | [diff] [blame] | 2110 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2111 | |
| 2112 | oh->_state = _HWMOD_STATE_IDLE; |
| 2113 | |
| 2114 | return 0; |
| 2115 | } |
| 2116 | |
| 2117 | /** |
| 2118 | * _shutdown - shutdown an omap_hwmod |
| 2119 | * @oh: struct omap_hwmod * |
| 2120 | * |
| 2121 | * Shut down an omap_hwmod @oh. This should be called when the driver |
| 2122 | * used for the hwmod is removed or unloaded or if the driver is not |
| 2123 | * used by the system. Returns -EINVAL if the hwmod is in the wrong |
| 2124 | * state or returns 0. |
| 2125 | */ |
| 2126 | static int _shutdown(struct omap_hwmod *oh) |
| 2127 | { |
Paul Walmsley | 9c8b0ec | 2012-04-18 19:10:02 -0600 | [diff] [blame] | 2128 | int ret, i; |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 2129 | u8 prev_state; |
| 2130 | |
Suman Anna | c20c8f7 | 2016-04-10 13:20:11 -0600 | [diff] [blame] | 2131 | if (_are_all_hardreset_lines_asserted(oh)) |
| 2132 | return 0; |
| 2133 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2134 | if (oh->_state != _HWMOD_STATE_IDLE && |
| 2135 | oh->_state != _HWMOD_STATE_ENABLED) { |
Russell King | 4f8a428 | 2012-02-07 10:59:37 +0000 | [diff] [blame] | 2136 | WARN(1, "omap_hwmod: %s: disabled state can only be entered from idle, or enabled state\n", |
| 2137 | oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2138 | return -EINVAL; |
| 2139 | } |
| 2140 | |
| 2141 | pr_debug("omap_hwmod: %s: disabling\n", oh->name); |
| 2142 | |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 2143 | if (oh->class->pre_shutdown) { |
| 2144 | prev_state = oh->_state; |
| 2145 | if (oh->_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2146 | _enable(oh); |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 2147 | ret = oh->class->pre_shutdown(oh); |
| 2148 | if (ret) { |
| 2149 | if (prev_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2150 | _idle(oh); |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 2151 | return ret; |
| 2152 | } |
| 2153 | } |
| 2154 | |
Miguel Vadillo | 6481c73 | 2011-07-01 22:54:02 +0200 | [diff] [blame] | 2155 | if (oh->class->sysc) { |
| 2156 | if (oh->_state == _HWMOD_STATE_IDLE) |
| 2157 | _enable(oh); |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 2158 | _shutdown_sysc(oh); |
Miguel Vadillo | 6481c73 | 2011-07-01 22:54:02 +0200 | [diff] [blame] | 2159 | } |
BenoƮt Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2160 | |
Benoit Cousson | 3827f94 | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 2161 | /* clocks and deps are already disabled in idle */ |
| 2162 | if (oh->_state == _HWMOD_STATE_ENABLED) { |
| 2163 | _del_initiator_dep(oh, mpu_oh); |
| 2164 | /* XXX what about the other system initiators here? dma, dsp */ |
Paul Walmsley | fa20022 | 2013-01-26 00:48:56 -0700 | [diff] [blame] | 2165 | if (oh->flags & HWMOD_BLOCK_WFI) |
Thomas Gleixner | f7b861b | 2013-03-21 22:49:38 +0100 | [diff] [blame] | 2166 | cpu_idle_poll_ctrl(false); |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 2167 | if (soc_ops.disable_module) |
| 2168 | soc_ops.disable_module(oh); |
Benoit Cousson | 45c3825 | 2011-07-10 05:56:33 -0600 | [diff] [blame] | 2169 | _disable_clocks(oh); |
Rajendra Nayak | 665d001 | 2011-07-10 05:57:07 -0600 | [diff] [blame] | 2170 | if (oh->clkdm) |
| 2171 | clkdm_hwmod_disable(oh->clkdm, oh); |
Benoit Cousson | 3827f94 | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 2172 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2173 | /* XXX Should this code also force-disable the optional clocks? */ |
| 2174 | |
Paul Walmsley | 9c8b0ec | 2012-04-18 19:10:02 -0600 | [diff] [blame] | 2175 | for (i = 0; i < oh->rst_lines_cnt; i++) |
| 2176 | _assert_hardreset(oh, oh->rst_lines[i].name); |
Benoit Cousson | 31f6286 | 2011-07-01 22:54:05 +0200 | [diff] [blame] | 2177 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2178 | oh->_state = _HWMOD_STATE_DISABLED; |
| 2179 | |
| 2180 | return 0; |
| 2181 | } |
| 2182 | |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2183 | static int of_dev_find_hwmod(struct device_node *np, |
| 2184 | struct omap_hwmod *oh) |
| 2185 | { |
| 2186 | int count, i, res; |
| 2187 | const char *p; |
| 2188 | |
| 2189 | count = of_property_count_strings(np, "ti,hwmods"); |
| 2190 | if (count < 1) |
| 2191 | return -ENODEV; |
| 2192 | |
| 2193 | for (i = 0; i < count; i++) { |
| 2194 | res = of_property_read_string_index(np, "ti,hwmods", |
| 2195 | i, &p); |
| 2196 | if (res) |
| 2197 | continue; |
| 2198 | if (!strcmp(p, oh->name)) { |
| 2199 | pr_debug("omap_hwmod: dt %s[%i] uses hwmod %s\n", |
| 2200 | np->name, i, oh->name); |
| 2201 | return i; |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | return -ENODEV; |
| 2206 | } |
| 2207 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2208 | /** |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2209 | * of_dev_hwmod_lookup - look up needed hwmod from dt blob |
| 2210 | * @np: struct device_node * |
| 2211 | * @oh: struct omap_hwmod * |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2212 | * @index: index of the entry found |
| 2213 | * @found: struct device_node * found or NULL |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2214 | * |
| 2215 | * Parse the dt blob and find out needed hwmod. Recursive function is |
| 2216 | * implemented to take care hierarchical dt blob parsing. |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2217 | * Return: Returns 0 on success, -ENODEV when not found. |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2218 | */ |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2219 | static int of_dev_hwmod_lookup(struct device_node *np, |
| 2220 | struct omap_hwmod *oh, |
| 2221 | int *index, |
| 2222 | struct device_node **found) |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2223 | { |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2224 | struct device_node *np0 = NULL; |
| 2225 | int res; |
| 2226 | |
| 2227 | res = of_dev_find_hwmod(np, oh); |
| 2228 | if (res >= 0) { |
| 2229 | *found = np; |
| 2230 | *index = res; |
| 2231 | return 0; |
| 2232 | } |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2233 | |
| 2234 | for_each_child_of_node(np, np0) { |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2235 | struct device_node *fc; |
| 2236 | int i; |
| 2237 | |
| 2238 | res = of_dev_hwmod_lookup(np0, oh, &i, &fc); |
| 2239 | if (res == 0) { |
| 2240 | *found = fc; |
| 2241 | *index = i; |
| 2242 | return 0; |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2243 | } |
| 2244 | } |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2245 | |
| 2246 | *found = NULL; |
| 2247 | *index = 0; |
| 2248 | |
| 2249 | return -ENODEV; |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /** |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2253 | * _init_mpu_rt_base - populate the virtual address for a hwmod |
| 2254 | * @oh: struct omap_hwmod * to locate the virtual address |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2255 | * @data: (unused, caller should pass NULL) |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2256 | * @index: index of the reg entry iospace in device tree |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2257 | * @np: struct device_node * of the IP block's device node in the DT data |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2258 | * |
| 2259 | * Cache the virtual address used by the MPU to access this IP block's |
| 2260 | * registers. This address is needed early so the OCP registers that |
| 2261 | * are part of the device's address space can be ioremapped properly. |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2262 | * |
Roger Quadros | 9a258af | 2015-07-16 16:16:44 +0300 | [diff] [blame] | 2263 | * If SYSC access is not needed, the registers will not be remapped |
| 2264 | * and non-availability of MPU access is not treated as an error. |
| 2265 | * |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2266 | * Returns 0 on success, -EINVAL if an invalid hwmod is passed, and |
| 2267 | * -ENXIO on absent or invalid register target address space. |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2268 | */ |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2269 | static int __init _init_mpu_rt_base(struct omap_hwmod *oh, void *data, |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2270 | int index, struct device_node *np) |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2271 | { |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2272 | struct omap_hwmod_addr_space *mem; |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2273 | void __iomem *va_start = NULL; |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2274 | |
| 2275 | if (!oh) |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2276 | return -EINVAL; |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2277 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2278 | _save_mpu_port_index(oh); |
| 2279 | |
Roger Quadros | 9a258af | 2015-07-16 16:16:44 +0300 | [diff] [blame] | 2280 | /* if we don't need sysc access we don't need to ioremap */ |
| 2281 | if (!oh->class->sysc) |
| 2282 | return 0; |
| 2283 | |
| 2284 | /* we can't continue without MPU PORT if we need sysc access */ |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2285 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2286 | return -ENXIO; |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2287 | |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2288 | mem = _find_mpu_rt_addr_space(oh); |
| 2289 | if (!mem) { |
| 2290 | pr_debug("omap_hwmod: %s: no MPU register target found\n", |
| 2291 | oh->name); |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2292 | |
| 2293 | /* Extract the IO space from device tree blob */ |
Roger Quadros | 9a258af | 2015-07-16 16:16:44 +0300 | [diff] [blame] | 2294 | if (!np) { |
| 2295 | pr_err("omap_hwmod: %s: no dt node\n", oh->name); |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2296 | return -ENXIO; |
Roger Quadros | 9a258af | 2015-07-16 16:16:44 +0300 | [diff] [blame] | 2297 | } |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2298 | |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2299 | va_start = of_iomap(np, index + oh->mpu_rt_idx); |
Santosh Shilimkar | 079abad | 2013-01-21 18:40:57 +0530 | [diff] [blame] | 2300 | } else { |
| 2301 | va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start); |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2302 | } |
| 2303 | |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2304 | if (!va_start) { |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2305 | if (mem) |
| 2306 | pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name); |
| 2307 | else |
| 2308 | pr_err("omap_hwmod: %s: Missing dt reg%i for %s\n", |
| 2309 | oh->name, index, np->full_name); |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2310 | return -ENXIO; |
Paul Walmsley | c9aafd2 | 2012-04-18 19:10:05 -0600 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | pr_debug("omap_hwmod: %s: MPU register target at va %p\n", |
| 2314 | oh->name, va_start); |
| 2315 | |
| 2316 | oh->_mpu_rt_va = va_start; |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2317 | return 0; |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * _init - initialize internal data for the hwmod @oh |
| 2322 | * @oh: struct omap_hwmod * |
| 2323 | * @n: (unused) |
| 2324 | * |
| 2325 | * Look up the clocks and the address space used by the MPU to access |
| 2326 | * registers belonging to the hwmod @oh. @oh must already be |
| 2327 | * registered at this point. This is the first of two phases for |
| 2328 | * hwmod initialization. Code called here does not touch any hardware |
| 2329 | * registers, it simply prepares internal data structures. Returns 0 |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2330 | * upon success or if the hwmod isn't registered or if the hwmod's |
| 2331 | * address space is not defined, or -EINVAL upon failure. |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2332 | */ |
| 2333 | static int __init _init(struct omap_hwmod *oh, void *data) |
| 2334 | { |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2335 | int r, index; |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2336 | struct device_node *np = NULL; |
Tony Lindgren | 1aa8f0c | 2017-05-31 15:51:37 -0700 | [diff] [blame^] | 2337 | struct device_node *bus; |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2338 | |
| 2339 | if (oh->_state != _HWMOD_STATE_REGISTERED) |
| 2340 | return 0; |
| 2341 | |
Tony Lindgren | 1aa8f0c | 2017-05-31 15:51:37 -0700 | [diff] [blame^] | 2342 | bus = of_find_node_by_name(NULL, "ocp"); |
| 2343 | if (!bus) |
| 2344 | return -ENODEV; |
Tony Lindgren | 5e863c5 | 2013-12-06 14:20:16 -0800 | [diff] [blame] | 2345 | |
Tony Lindgren | 1aa8f0c | 2017-05-31 15:51:37 -0700 | [diff] [blame^] | 2346 | r = of_dev_hwmod_lookup(bus, oh, &index, &np); |
| 2347 | if (r) |
| 2348 | pr_debug("omap_hwmod: %s missing dt data\n", oh->name); |
| 2349 | else if (np && index) |
| 2350 | pr_warn("omap_hwmod: %s using broken dt data from %s\n", |
| 2351 | oh->name, np->name); |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2352 | |
Roger Quadros | 9a258af | 2015-07-16 16:16:44 +0300 | [diff] [blame] | 2353 | r = _init_mpu_rt_base(oh, NULL, index, np); |
| 2354 | if (r < 0) { |
| 2355 | WARN(1, "omap_hwmod: %s: doesn't have mpu register target base\n", |
| 2356 | oh->name); |
| 2357 | return 0; |
Suman Anna | 6423d6d | 2013-10-08 23:46:49 -0600 | [diff] [blame] | 2358 | } |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2359 | |
| 2360 | r = _init_clocks(oh, NULL); |
Russell King | c48cd65 | 2013-03-13 20:44:21 +0000 | [diff] [blame] | 2361 | if (r < 0) { |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2362 | WARN(1, "omap_hwmod: %s: couldn't init clocks\n", oh->name); |
| 2363 | return -EINVAL; |
| 2364 | } |
| 2365 | |
Suman Anna | 3d36ad7 | 2014-03-14 14:45:17 +0530 | [diff] [blame] | 2366 | if (np) { |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2367 | if (of_find_property(np, "ti,no-reset-on-init", NULL)) |
| 2368 | oh->flags |= HWMOD_INIT_NO_RESET; |
| 2369 | if (of_find_property(np, "ti,no-idle-on-init", NULL)) |
| 2370 | oh->flags |= HWMOD_INIT_NO_IDLE; |
Lokesh Vutla | 2e18f5a | 2016-03-07 01:41:21 -0700 | [diff] [blame] | 2371 | if (of_find_property(np, "ti,no-idle", NULL)) |
| 2372 | oh->flags |= HWMOD_NO_IDLE; |
Suman Anna | 3d36ad7 | 2014-03-14 14:45:17 +0530 | [diff] [blame] | 2373 | } |
Rajendra Nayak | f92d959 | 2013-10-09 01:26:55 -0600 | [diff] [blame] | 2374 | |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2375 | oh->_state = _HWMOD_STATE_INITIALIZED; |
| 2376 | |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | /** |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2381 | * _setup_iclk_autoidle - configure an IP block's interface clocks |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2382 | * @oh: struct omap_hwmod * |
| 2383 | * |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2384 | * Set up the module's interface clocks. XXX This function is still mostly |
| 2385 | * a stub; implementing this properly requires iclk autoidle usecounting in |
| 2386 | * the clock code. No return value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2387 | */ |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2388 | static void __init _setup_iclk_autoidle(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2389 | { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 2390 | struct omap_hwmod_ocp_if *os; |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 2391 | |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 2392 | if (oh->_state != _HWMOD_STATE_INITIALIZED) |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2393 | return; |
Paul Walmsley | 48d54f3 | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 2394 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 2395 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 2396 | if (!os->_clk) |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2397 | continue; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2398 | |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2399 | if (os->flags & OCPIF_SWSUP_IDLE) { |
| 2400 | /* XXX omap_iclk_deny_idle(c); */ |
| 2401 | } else { |
| 2402 | /* XXX omap_iclk_allow_idle(c); */ |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 2403 | clk_enable(os->_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2407 | return; |
| 2408 | } |
| 2409 | |
| 2410 | /** |
| 2411 | * _setup_reset - reset an IP block during the setup process |
| 2412 | * @oh: struct omap_hwmod * |
| 2413 | * |
| 2414 | * Reset the IP block corresponding to the hwmod @oh during the setup |
| 2415 | * process. The IP block is first enabled so it can be successfully |
| 2416 | * reset. Returns 0 upon success or a negative error code upon |
| 2417 | * failure. |
| 2418 | */ |
| 2419 | static int __init _setup_reset(struct omap_hwmod *oh) |
| 2420 | { |
| 2421 | int r; |
| 2422 | |
| 2423 | if (oh->_state != _HWMOD_STATE_INITIALIZED) |
| 2424 | return -EINVAL; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2425 | |
Paul Walmsley | 5fb3d52 | 2012-10-29 22:11:50 -0600 | [diff] [blame] | 2426 | if (oh->flags & HWMOD_EXT_OPT_MAIN_CLK) |
| 2427 | return -EPERM; |
| 2428 | |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 2429 | if (oh->rst_lines_cnt == 0) { |
| 2430 | r = _enable(oh); |
| 2431 | if (r) { |
Joe Perches | 3d0cb73 | 2014-09-13 11:31:16 -0700 | [diff] [blame] | 2432 | pr_warn("omap_hwmod: %s: cannot be enabled for reset (%d)\n", |
| 2433 | oh->name, oh->_state); |
Paul Walmsley | 747834a | 2012-04-18 19:10:04 -0600 | [diff] [blame] | 2434 | return -EINVAL; |
| 2435 | } |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 2436 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2437 | |
Rajendra Nayak | 2800852 | 2012-03-13 22:55:23 +0530 | [diff] [blame] | 2438 | if (!(oh->flags & HWMOD_INIT_NO_RESET)) |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2439 | r = _reset(oh); |
| 2440 | |
| 2441 | return r; |
| 2442 | } |
| 2443 | |
| 2444 | /** |
| 2445 | * _setup_postsetup - transition to the appropriate state after _setup |
| 2446 | * @oh: struct omap_hwmod * |
| 2447 | * |
| 2448 | * Place an IP block represented by @oh into a "post-setup" state -- |
| 2449 | * either IDLE, ENABLED, or DISABLED. ("post-setup" simply means that |
| 2450 | * this function is called at the end of _setup().) The postsetup |
| 2451 | * state for an IP block can be changed by calling |
| 2452 | * omap_hwmod_enter_postsetup_state() early in the boot process, |
| 2453 | * before one of the omap_hwmod_setup*() functions are called for the |
| 2454 | * IP block. |
| 2455 | * |
| 2456 | * The IP block stays in this state until a PM runtime-based driver is |
| 2457 | * loaded for that IP block. A post-setup state of IDLE is |
| 2458 | * appropriate for almost all IP blocks with runtime PM-enabled |
| 2459 | * drivers, since those drivers are able to enable the IP block. A |
| 2460 | * post-setup state of ENABLED is appropriate for kernels with PM |
| 2461 | * runtime disabled. The DISABLED state is appropriate for unusual IP |
| 2462 | * blocks such as the MPU WDTIMER on kernels without WDTIMER drivers |
| 2463 | * included, since the WDTIMER starts running on reset and will reset |
| 2464 | * the MPU if left active. |
| 2465 | * |
| 2466 | * This post-setup mechanism is deprecated. Once all of the OMAP |
| 2467 | * drivers have been converted to use PM runtime, and all of the IP |
| 2468 | * block data and interconnect data is available to the hwmod code, it |
| 2469 | * should be possible to replace this mechanism with a "lazy reset" |
| 2470 | * arrangement. In a "lazy reset" setup, each IP block is enabled |
| 2471 | * when the driver first probes, then all remaining IP blocks without |
| 2472 | * drivers are either shut down or enabled after the drivers have |
| 2473 | * loaded. However, this cannot take place until the above |
| 2474 | * preconditions have been met, since otherwise the late reset code |
| 2475 | * has no way of knowing which IP blocks are in use by drivers, and |
| 2476 | * which ones are unused. |
| 2477 | * |
| 2478 | * No return value. |
| 2479 | */ |
| 2480 | static void __init _setup_postsetup(struct omap_hwmod *oh) |
| 2481 | { |
| 2482 | u8 postsetup_state; |
| 2483 | |
| 2484 | if (oh->rst_lines_cnt > 0) |
| 2485 | return; |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2486 | |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2487 | postsetup_state = oh->_postsetup_state; |
| 2488 | if (postsetup_state == _HWMOD_STATE_UNKNOWN) |
| 2489 | postsetup_state = _HWMOD_STATE_ENABLED; |
| 2490 | |
| 2491 | /* |
| 2492 | * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data - |
| 2493 | * it should be set by the core code as a runtime flag during startup |
| 2494 | */ |
Lokesh Vutla | 2e18f5a | 2016-03-07 01:41:21 -0700 | [diff] [blame] | 2495 | if ((oh->flags & (HWMOD_INIT_NO_IDLE | HWMOD_NO_IDLE)) && |
Rajendra Nayak | aacf094 | 2011-12-16 05:50:12 -0700 | [diff] [blame] | 2496 | (postsetup_state == _HWMOD_STATE_IDLE)) { |
| 2497 | oh->_int_flags |= _HWMOD_SKIP_ENABLE; |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2498 | postsetup_state = _HWMOD_STATE_ENABLED; |
Rajendra Nayak | aacf094 | 2011-12-16 05:50:12 -0700 | [diff] [blame] | 2499 | } |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2500 | |
| 2501 | if (postsetup_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2502 | _idle(oh); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2503 | else if (postsetup_state == _HWMOD_STATE_DISABLED) |
| 2504 | _shutdown(oh); |
| 2505 | else if (postsetup_state != _HWMOD_STATE_ENABLED) |
| 2506 | WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n", |
| 2507 | oh->name, postsetup_state); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2508 | |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2509 | return; |
| 2510 | } |
| 2511 | |
| 2512 | /** |
| 2513 | * _setup - prepare IP block hardware for use |
| 2514 | * @oh: struct omap_hwmod * |
| 2515 | * @n: (unused, pass NULL) |
| 2516 | * |
| 2517 | * Configure the IP block represented by @oh. This may include |
| 2518 | * enabling the IP block, resetting it, and placing it into a |
| 2519 | * post-setup state, depending on the type of IP block and applicable |
| 2520 | * flags. IP blocks are reset to prevent any previous configuration |
| 2521 | * by the bootloader or previous operating system from interfering |
| 2522 | * with power management or other parts of the system. The reset can |
| 2523 | * be avoided; see omap_hwmod_no_setup_reset(). This is the second of |
| 2524 | * two phases for hwmod initialization. Code called here generally |
| 2525 | * affects the IP block hardware, or system integration hardware |
| 2526 | * associated with the IP block. Returns 0. |
| 2527 | */ |
| 2528 | static int __init _setup(struct omap_hwmod *oh, void *data) |
| 2529 | { |
| 2530 | if (oh->_state != _HWMOD_STATE_INITIALIZED) |
| 2531 | return 0; |
| 2532 | |
Tomi Valkeinen | f22d254 | 2014-10-09 17:03:14 +0300 | [diff] [blame] | 2533 | if (oh->parent_hwmod) { |
| 2534 | int r; |
| 2535 | |
| 2536 | r = _enable(oh->parent_hwmod); |
| 2537 | WARN(r, "hwmod: %s: setup: failed to enable parent hwmod %s\n", |
| 2538 | oh->name, oh->parent_hwmod->name); |
| 2539 | } |
| 2540 | |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 2541 | _setup_iclk_autoidle(oh); |
| 2542 | |
| 2543 | if (!_setup_reset(oh)) |
| 2544 | _setup_postsetup(oh); |
| 2545 | |
Tomi Valkeinen | f22d254 | 2014-10-09 17:03:14 +0300 | [diff] [blame] | 2546 | if (oh->parent_hwmod) { |
| 2547 | u8 postsetup_state; |
| 2548 | |
| 2549 | postsetup_state = oh->parent_hwmod->_postsetup_state; |
| 2550 | |
| 2551 | if (postsetup_state == _HWMOD_STATE_IDLE) |
| 2552 | _idle(oh->parent_hwmod); |
| 2553 | else if (postsetup_state == _HWMOD_STATE_DISABLED) |
| 2554 | _shutdown(oh->parent_hwmod); |
| 2555 | else if (postsetup_state != _HWMOD_STATE_ENABLED) |
| 2556 | WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n", |
| 2557 | oh->parent_hwmod->name, postsetup_state); |
| 2558 | } |
| 2559 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2560 | return 0; |
| 2561 | } |
| 2562 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2563 | /** |
| 2564 | * _register - register a struct omap_hwmod |
| 2565 | * @oh: struct omap_hwmod * |
| 2566 | * |
| 2567 | * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod |
| 2568 | * already has been registered by the same name; -EINVAL if the |
| 2569 | * omap_hwmod is in the wrong state, if @oh is NULL, if the |
| 2570 | * omap_hwmod's class field is NULL; if the omap_hwmod is missing a |
| 2571 | * name, or if the omap_hwmod's class is missing a name; or 0 upon |
| 2572 | * success. |
| 2573 | * |
| 2574 | * XXX The data should be copied into bootmem, so the original data |
| 2575 | * should be marked __initdata and freed after init. This would allow |
| 2576 | * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note |
| 2577 | * that the copy process would be relatively complex due to the large number |
| 2578 | * of substructures. |
| 2579 | */ |
Benoit Cousson | 01592df | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 2580 | static int __init _register(struct omap_hwmod *oh) |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2581 | { |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2582 | if (!oh || !oh->name || !oh->class || !oh->class->name || |
| 2583 | (oh->_state != _HWMOD_STATE_UNKNOWN)) |
| 2584 | return -EINVAL; |
| 2585 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2586 | pr_debug("omap_hwmod: %s: registering\n", oh->name); |
| 2587 | |
Benoit Cousson | ce35b24 | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 2588 | if (_lookup(oh->name)) |
| 2589 | return -EEXIST; |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2590 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2591 | list_add_tail(&oh->node, &omap_hwmod_list); |
| 2592 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2593 | INIT_LIST_HEAD(&oh->slave_ports); |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2594 | spin_lock_init(&oh->_lock); |
Peter Ujfalusi | 6931795 | 2015-02-26 00:00:51 -0700 | [diff] [blame] | 2595 | lockdep_set_class(&oh->_lock, &oh->hwmod_key); |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2596 | |
| 2597 | oh->_state = _HWMOD_STATE_REGISTERED; |
| 2598 | |
Paul Walmsley | 569edd70 | 2011-02-23 00:14:06 -0700 | [diff] [blame] | 2599 | /* |
| 2600 | * XXX Rather than doing a strcmp(), this should test a flag |
| 2601 | * set in the hwmod data, inserted by the autogenerator code. |
| 2602 | */ |
| 2603 | if (!strcmp(oh->name, MPU_INITIATOR_NAME)) |
| 2604 | mpu_oh = oh; |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2605 | |
Paul Walmsley | 569edd70 | 2011-02-23 00:14:06 -0700 | [diff] [blame] | 2606 | return 0; |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 2607 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2608 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2609 | /** |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2610 | * _add_link - add an interconnect between two IP blocks |
| 2611 | * @oi: pointer to a struct omap_hwmod_ocp_if record |
| 2612 | * |
Tony Lindgren | a1e3123 | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 2613 | * Add struct omap_hwmod_link records connecting the slave IP block |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2614 | * specified in @oi->slave to @oi. This code is assumed to run before |
| 2615 | * preemption or SMP has been enabled, thus avoiding the need for |
| 2616 | * locking in this code. Changes to this assumption will require |
| 2617 | * additional locking. Returns 0. |
| 2618 | */ |
| 2619 | static int __init _add_link(struct omap_hwmod_ocp_if *oi) |
| 2620 | { |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2621 | pr_debug("omap_hwmod: %s -> %s: adding link\n", oi->master->name, |
| 2622 | oi->slave->name); |
| 2623 | |
Tony Lindgren | a1e3123 | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 2624 | list_add(&oi->node, &oi->slave->slave_ports); |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 2625 | oi->slave->slaves_cnt++; |
| 2626 | |
| 2627 | return 0; |
| 2628 | } |
| 2629 | |
| 2630 | /** |
| 2631 | * _register_link - register a struct omap_hwmod_ocp_if |
| 2632 | * @oi: struct omap_hwmod_ocp_if * |
| 2633 | * |
| 2634 | * Registers the omap_hwmod_ocp_if record @oi. Returns -EEXIST if it |
| 2635 | * has already been registered; -EINVAL if @oi is NULL or if the |
| 2636 | * record pointed to by @oi is missing required fields; or 0 upon |
| 2637 | * success. |
| 2638 | * |
| 2639 | * XXX The data should be copied into bootmem, so the original data |
| 2640 | * should be marked __initdata and freed after init. This would allow |
| 2641 | * unneeded omap_hwmods to be freed on multi-OMAP configurations. |
| 2642 | */ |
| 2643 | static int __init _register_link(struct omap_hwmod_ocp_if *oi) |
| 2644 | { |
| 2645 | if (!oi || !oi->master || !oi->slave || !oi->user) |
| 2646 | return -EINVAL; |
| 2647 | |
| 2648 | if (oi->_int_flags & _OCPIF_INT_FLAGS_REGISTERED) |
| 2649 | return -EEXIST; |
| 2650 | |
| 2651 | pr_debug("omap_hwmod: registering link from %s to %s\n", |
| 2652 | oi->master->name, oi->slave->name); |
| 2653 | |
| 2654 | /* |
| 2655 | * Register the connected hwmods, if they haven't been |
| 2656 | * registered already |
| 2657 | */ |
| 2658 | if (oi->master->_state != _HWMOD_STATE_REGISTERED) |
| 2659 | _register(oi->master); |
| 2660 | |
| 2661 | if (oi->slave->_state != _HWMOD_STATE_REGISTERED) |
| 2662 | _register(oi->slave); |
| 2663 | |
| 2664 | _add_link(oi); |
| 2665 | |
| 2666 | oi->_int_flags |= _OCPIF_INT_FLAGS_REGISTERED; |
| 2667 | |
| 2668 | return 0; |
| 2669 | } |
| 2670 | |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2671 | /* Static functions intended only for use in soc_ops field function pointers */ |
| 2672 | |
| 2673 | /** |
Tero Kristo | 9002e921 | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 2674 | * _omap2xxx_3xxx_wait_target_ready - wait for a module to leave slave idle |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2675 | * @oh: struct omap_hwmod * |
| 2676 | * |
| 2677 | * Wait for a module @oh to leave slave idle. Returns 0 if the module |
| 2678 | * does not have an IDLEST bit or if the module successfully leaves |
| 2679 | * slave idle; otherwise, pass along the return value of the |
| 2680 | * appropriate *_cm*_wait_module_ready() function. |
| 2681 | */ |
Tero Kristo | 9002e921 | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 2682 | static int _omap2xxx_3xxx_wait_target_ready(struct omap_hwmod *oh) |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2683 | { |
| 2684 | if (!oh) |
| 2685 | return -EINVAL; |
| 2686 | |
| 2687 | if (oh->flags & HWMOD_NO_IDLEST) |
| 2688 | return 0; |
| 2689 | |
| 2690 | if (!_find_mpu_rt_port(oh)) |
| 2691 | return 0; |
| 2692 | |
| 2693 | /* XXX check module SIDLEMODE, hardreset status, enabled clocks */ |
| 2694 | |
Tero Kristo | 021b6ff | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 2695 | return omap_cm_wait_module_ready(0, oh->prcm.omap2.module_offs, |
| 2696 | oh->prcm.omap2.idlest_reg_id, |
| 2697 | oh->prcm.omap2.idlest_idle_bit); |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | /** |
| 2701 | * _omap4_wait_target_ready - wait for a module to leave slave idle |
| 2702 | * @oh: struct omap_hwmod * |
| 2703 | * |
| 2704 | * Wait for a module @oh to leave slave idle. Returns 0 if the module |
| 2705 | * does not have an IDLEST bit or if the module successfully leaves |
| 2706 | * slave idle; otherwise, pass along the return value of the |
| 2707 | * appropriate *_cm*_wait_module_ready() function. |
| 2708 | */ |
| 2709 | static int _omap4_wait_target_ready(struct omap_hwmod *oh) |
| 2710 | { |
Paul Walmsley | 2b026d1 | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 2711 | if (!oh) |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2712 | return -EINVAL; |
| 2713 | |
Paul Walmsley | 2b026d1 | 2012-09-23 17:28:18 -0600 | [diff] [blame] | 2714 | if (oh->flags & HWMOD_NO_IDLEST || !oh->clkdm) |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2715 | return 0; |
| 2716 | |
| 2717 | if (!_find_mpu_rt_port(oh)) |
| 2718 | return 0; |
| 2719 | |
Dave Gerlach | 428929c | 2016-07-12 12:50:33 -0500 | [diff] [blame] | 2720 | if (!oh->prcm.omap4.clkctrl_offs && |
| 2721 | !(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET)) |
| 2722 | return 0; |
| 2723 | |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2724 | /* XXX check module SIDLEMODE, hardreset status */ |
| 2725 | |
Tero Kristo | 021b6ff | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 2726 | return omap_cm_wait_module_ready(oh->clkdm->prcm_partition, |
| 2727 | oh->clkdm->cm_inst, |
| 2728 | oh->prcm.omap4.clkctrl_offs, 0); |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | /** |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2732 | * _omap2_assert_hardreset - call OMAP2 PRM hardreset fn with hwmod args |
| 2733 | * @oh: struct omap_hwmod * to assert hardreset |
| 2734 | * @ohri: hardreset line data |
| 2735 | * |
| 2736 | * Call omap2_prm_assert_hardreset() with parameters extracted from |
| 2737 | * the hwmod @oh and the hardreset line data @ohri. Only intended for |
| 2738 | * use as an soc_ops function pointer. Passes along the return value |
| 2739 | * from omap2_prm_assert_hardreset(). XXX This function is scheduled |
| 2740 | * for removal when the PRM code is moved into drivers/. |
| 2741 | */ |
| 2742 | static int _omap2_assert_hardreset(struct omap_hwmod *oh, |
| 2743 | struct omap_hwmod_rst_info *ohri) |
| 2744 | { |
Tero Kristo | efd44dc | 2014-10-27 08:39:24 -0700 | [diff] [blame] | 2745 | return omap_prm_assert_hardreset(ohri->rst_shift, 0, |
| 2746 | oh->prcm.omap2.module_offs, 0); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | /** |
| 2750 | * _omap2_deassert_hardreset - call OMAP2 PRM hardreset fn with hwmod args |
| 2751 | * @oh: struct omap_hwmod * to deassert hardreset |
| 2752 | * @ohri: hardreset line data |
| 2753 | * |
| 2754 | * Call omap2_prm_deassert_hardreset() with parameters extracted from |
| 2755 | * the hwmod @oh and the hardreset line data @ohri. Only intended for |
| 2756 | * use as an soc_ops function pointer. Passes along the return value |
| 2757 | * from omap2_prm_deassert_hardreset(). XXX This function is |
| 2758 | * scheduled for removal when the PRM code is moved into drivers/. |
| 2759 | */ |
| 2760 | static int _omap2_deassert_hardreset(struct omap_hwmod *oh, |
| 2761 | struct omap_hwmod_rst_info *ohri) |
| 2762 | { |
Tero Kristo | 37fb59d | 2014-10-27 08:39:25 -0700 | [diff] [blame] | 2763 | return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, 0, |
| 2764 | oh->prcm.omap2.module_offs, 0, 0); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | /** |
| 2768 | * _omap2_is_hardreset_asserted - call OMAP2 PRM hardreset fn with hwmod args |
| 2769 | * @oh: struct omap_hwmod * to test hardreset |
| 2770 | * @ohri: hardreset line data |
| 2771 | * |
| 2772 | * Call omap2_prm_is_hardreset_asserted() with parameters extracted |
| 2773 | * from the hwmod @oh and the hardreset line data @ohri. Only |
| 2774 | * intended for use as an soc_ops function pointer. Passes along the |
| 2775 | * return value from omap2_prm_is_hardreset_asserted(). XXX This |
| 2776 | * function is scheduled for removal when the PRM code is moved into |
| 2777 | * drivers/. |
| 2778 | */ |
| 2779 | static int _omap2_is_hardreset_asserted(struct omap_hwmod *oh, |
| 2780 | struct omap_hwmod_rst_info *ohri) |
| 2781 | { |
Tero Kristo | 1bc28b3 | 2014-10-27 08:39:25 -0700 | [diff] [blame] | 2782 | return omap_prm_is_hardreset_asserted(ohri->st_shift, 0, |
| 2783 | oh->prcm.omap2.module_offs, 0); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * _omap4_assert_hardreset - call OMAP4 PRM hardreset fn with hwmod args |
| 2788 | * @oh: struct omap_hwmod * to assert hardreset |
| 2789 | * @ohri: hardreset line data |
| 2790 | * |
| 2791 | * Call omap4_prminst_assert_hardreset() with parameters extracted |
| 2792 | * from the hwmod @oh and the hardreset line data @ohri. Only |
| 2793 | * intended for use as an soc_ops function pointer. Passes along the |
| 2794 | * return value from omap4_prminst_assert_hardreset(). XXX This |
| 2795 | * function is scheduled for removal when the PRM code is moved into |
| 2796 | * drivers/. |
| 2797 | */ |
| 2798 | static int _omap4_assert_hardreset(struct omap_hwmod *oh, |
| 2799 | struct omap_hwmod_rst_info *ohri) |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2800 | { |
Paul Walmsley | 07b3a13 | 2012-06-20 20:11:36 -0600 | [diff] [blame] | 2801 | if (!oh->clkdm) |
| 2802 | return -EINVAL; |
| 2803 | |
Tero Kristo | efd44dc | 2014-10-27 08:39:24 -0700 | [diff] [blame] | 2804 | return omap_prm_assert_hardreset(ohri->rst_shift, |
| 2805 | oh->clkdm->pwrdm.ptr->prcm_partition, |
| 2806 | oh->clkdm->pwrdm.ptr->prcm_offs, |
| 2807 | oh->prcm.omap4.rstctrl_offs); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | /** |
| 2811 | * _omap4_deassert_hardreset - call OMAP4 PRM hardreset fn with hwmod args |
| 2812 | * @oh: struct omap_hwmod * to deassert hardreset |
| 2813 | * @ohri: hardreset line data |
| 2814 | * |
| 2815 | * Call omap4_prminst_deassert_hardreset() with parameters extracted |
| 2816 | * from the hwmod @oh and the hardreset line data @ohri. Only |
| 2817 | * intended for use as an soc_ops function pointer. Passes along the |
| 2818 | * return value from omap4_prminst_deassert_hardreset(). XXX This |
| 2819 | * function is scheduled for removal when the PRM code is moved into |
| 2820 | * drivers/. |
| 2821 | */ |
| 2822 | static int _omap4_deassert_hardreset(struct omap_hwmod *oh, |
| 2823 | struct omap_hwmod_rst_info *ohri) |
| 2824 | { |
Paul Walmsley | 07b3a13 | 2012-06-20 20:11:36 -0600 | [diff] [blame] | 2825 | if (!oh->clkdm) |
| 2826 | return -EINVAL; |
| 2827 | |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2828 | if (ohri->st_shift) |
| 2829 | pr_err("omap_hwmod: %s: %s: hwmod data error: OMAP4 does not support st_shift\n", |
| 2830 | oh->name, ohri->name); |
Tero Kristo | 4ebf5b2 | 2015-05-05 16:33:04 +0300 | [diff] [blame] | 2831 | return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->rst_shift, |
Tero Kristo | 37fb59d | 2014-10-27 08:39:25 -0700 | [diff] [blame] | 2832 | oh->clkdm->pwrdm.ptr->prcm_partition, |
| 2833 | oh->clkdm->pwrdm.ptr->prcm_offs, |
Tero Kristo | 4ebf5b2 | 2015-05-05 16:33:04 +0300 | [diff] [blame] | 2834 | oh->prcm.omap4.rstctrl_offs, |
| 2835 | oh->prcm.omap4.rstctrl_offs + |
| 2836 | OMAP4_RST_CTRL_ST_OFFSET); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | /** |
| 2840 | * _omap4_is_hardreset_asserted - call OMAP4 PRM hardreset fn with hwmod args |
| 2841 | * @oh: struct omap_hwmod * to test hardreset |
| 2842 | * @ohri: hardreset line data |
| 2843 | * |
| 2844 | * Call omap4_prminst_is_hardreset_asserted() with parameters |
| 2845 | * extracted from the hwmod @oh and the hardreset line data @ohri. |
| 2846 | * Only intended for use as an soc_ops function pointer. Passes along |
| 2847 | * the return value from omap4_prminst_is_hardreset_asserted(). XXX |
| 2848 | * This function is scheduled for removal when the PRM code is moved |
| 2849 | * into drivers/. |
| 2850 | */ |
| 2851 | static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh, |
| 2852 | struct omap_hwmod_rst_info *ohri) |
| 2853 | { |
Paul Walmsley | 07b3a13 | 2012-06-20 20:11:36 -0600 | [diff] [blame] | 2854 | if (!oh->clkdm) |
| 2855 | return -EINVAL; |
| 2856 | |
Tero Kristo | 1bc28b3 | 2014-10-27 08:39:25 -0700 | [diff] [blame] | 2857 | return omap_prm_is_hardreset_asserted(ohri->rst_shift, |
| 2858 | oh->clkdm->pwrdm.ptr-> |
| 2859 | prcm_partition, |
| 2860 | oh->clkdm->pwrdm.ptr->prcm_offs, |
| 2861 | oh->prcm.omap4.rstctrl_offs); |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 2862 | } |
| 2863 | |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 2864 | /** |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 2865 | * _omap4_disable_direct_prcm - disable direct PRCM control for hwmod |
| 2866 | * @oh: struct omap_hwmod * to disable control for |
| 2867 | * |
| 2868 | * Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod |
| 2869 | * will be using its main_clk to enable/disable the module. Returns |
| 2870 | * 0 if successful. |
| 2871 | */ |
| 2872 | static int _omap4_disable_direct_prcm(struct omap_hwmod *oh) |
| 2873 | { |
| 2874 | if (!oh) |
| 2875 | return -EINVAL; |
| 2876 | |
| 2877 | oh->prcm.omap4.clkctrl_offs = 0; |
| 2878 | oh->prcm.omap4.modulemode = 0; |
| 2879 | |
| 2880 | return 0; |
| 2881 | } |
| 2882 | |
| 2883 | /** |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 2884 | * _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args |
| 2885 | * @oh: struct omap_hwmod * to deassert hardreset |
| 2886 | * @ohri: hardreset line data |
| 2887 | * |
| 2888 | * Call am33xx_prminst_deassert_hardreset() with parameters extracted |
| 2889 | * from the hwmod @oh and the hardreset line data @ohri. Only |
| 2890 | * intended for use as an soc_ops function pointer. Passes along the |
| 2891 | * return value from am33xx_prminst_deassert_hardreset(). XXX This |
| 2892 | * function is scheduled for removal when the PRM code is moved into |
| 2893 | * drivers/. |
| 2894 | */ |
| 2895 | static int _am33xx_deassert_hardreset(struct omap_hwmod *oh, |
| 2896 | struct omap_hwmod_rst_info *ohri) |
| 2897 | { |
Tero Kristo | a5bf00c | 2015-05-05 16:33:05 +0300 | [diff] [blame] | 2898 | return omap_prm_deassert_hardreset(ohri->rst_shift, ohri->st_shift, |
| 2899 | oh->clkdm->pwrdm.ptr->prcm_partition, |
Tero Kristo | 37fb59d | 2014-10-27 08:39:25 -0700 | [diff] [blame] | 2900 | oh->clkdm->pwrdm.ptr->prcm_offs, |
| 2901 | oh->prcm.omap4.rstctrl_offs, |
| 2902 | oh->prcm.omap4.rstst_offs); |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 2903 | } |
| 2904 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2905 | /* Public functions */ |
| 2906 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2907 | u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2908 | { |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2909 | if (oh->flags & HWMOD_16BIT_REG) |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 2910 | return readw_relaxed(oh->_mpu_rt_va + reg_offs); |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2911 | else |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 2912 | return readl_relaxed(oh->_mpu_rt_va + reg_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2913 | } |
| 2914 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2915 | void omap_hwmod_write(u32 v, struct omap_hwmod *oh, u16 reg_offs) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2916 | { |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2917 | if (oh->flags & HWMOD_16BIT_REG) |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 2918 | writew_relaxed(v, oh->_mpu_rt_va + reg_offs); |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 2919 | else |
Victor Kamensky | edfaf05 | 2014-04-15 20:37:46 +0300 | [diff] [blame] | 2920 | writel_relaxed(v, oh->_mpu_rt_va + reg_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2921 | } |
| 2922 | |
Paul Walmsley | 887adea | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 2923 | /** |
Avinash.H.M | 6d3c55f | 2011-07-10 05:27:16 -0600 | [diff] [blame] | 2924 | * omap_hwmod_softreset - reset a module via SYSCONFIG.SOFTRESET bit |
| 2925 | * @oh: struct omap_hwmod * |
| 2926 | * |
| 2927 | * This is a public function exposed to drivers. Some drivers may need to do |
| 2928 | * some settings before and after resetting the device. Those drivers after |
| 2929 | * doing the necessary settings could use this function to start a reset by |
| 2930 | * setting the SYSCONFIG.SOFTRESET bit. |
| 2931 | */ |
| 2932 | int omap_hwmod_softreset(struct omap_hwmod *oh) |
| 2933 | { |
Paul Walmsley | 3c55c1b | 2012-04-13 05:08:43 -0600 | [diff] [blame] | 2934 | u32 v; |
| 2935 | int ret; |
| 2936 | |
| 2937 | if (!oh || !(oh->_sysc_cache)) |
Avinash.H.M | 6d3c55f | 2011-07-10 05:27:16 -0600 | [diff] [blame] | 2938 | return -EINVAL; |
| 2939 | |
Paul Walmsley | 3c55c1b | 2012-04-13 05:08:43 -0600 | [diff] [blame] | 2940 | v = oh->_sysc_cache; |
| 2941 | ret = _set_softreset(oh, &v); |
| 2942 | if (ret) |
| 2943 | goto error; |
| 2944 | _write_sysconfig(v, oh); |
| 2945 | |
Roger Quadros | 313a76e | 2013-12-08 18:39:02 -0700 | [diff] [blame] | 2946 | ret = _clear_softreset(oh, &v); |
| 2947 | if (ret) |
| 2948 | goto error; |
| 2949 | _write_sysconfig(v, oh); |
| 2950 | |
Paul Walmsley | 3c55c1b | 2012-04-13 05:08:43 -0600 | [diff] [blame] | 2951 | error: |
| 2952 | return ret; |
Avinash.H.M | 6d3c55f | 2011-07-10 05:27:16 -0600 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2956 | * omap_hwmod_lookup - look up a registered omap_hwmod by name |
| 2957 | * @name: name of the omap_hwmod to look up |
| 2958 | * |
| 2959 | * Given a @name of an omap_hwmod, return a pointer to the registered |
| 2960 | * struct omap_hwmod *, or NULL upon error. |
| 2961 | */ |
| 2962 | struct omap_hwmod *omap_hwmod_lookup(const char *name) |
| 2963 | { |
| 2964 | struct omap_hwmod *oh; |
| 2965 | |
| 2966 | if (!name) |
| 2967 | return NULL; |
| 2968 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2969 | oh = _lookup(name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2970 | |
| 2971 | return oh; |
| 2972 | } |
| 2973 | |
| 2974 | /** |
| 2975 | * omap_hwmod_for_each - call function for each registered omap_hwmod |
| 2976 | * @fn: pointer to a callback function |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 2977 | * @data: void * data to pass to callback function |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2978 | * |
| 2979 | * Call @fn for each registered omap_hwmod, passing @data to each |
| 2980 | * function. @fn must return 0 for success or any other value for |
| 2981 | * failure. If @fn returns non-zero, the iteration across omap_hwmods |
| 2982 | * will stop and the non-zero return value will be passed to the |
| 2983 | * caller of omap_hwmod_for_each(). @fn is called with |
| 2984 | * omap_hwmod_for_each() held. |
| 2985 | */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 2986 | int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data), |
| 2987 | void *data) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2988 | { |
| 2989 | struct omap_hwmod *temp_oh; |
Govindraj.R | 30ebad9 | 2011-06-01 11:28:56 +0530 | [diff] [blame] | 2990 | int ret = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2991 | |
| 2992 | if (!fn) |
| 2993 | return -EINVAL; |
| 2994 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2995 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 2996 | ret = (*fn)(temp_oh, data); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2997 | if (ret) |
| 2998 | break; |
| 2999 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3000 | |
| 3001 | return ret; |
| 3002 | } |
| 3003 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3004 | /** |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 3005 | * omap_hwmod_register_links - register an array of hwmod links |
| 3006 | * @ois: pointer to an array of omap_hwmod_ocp_if to register |
| 3007 | * |
| 3008 | * Intended to be called early in boot before the clock framework is |
| 3009 | * initialized. If @ois is not null, will register all omap_hwmods |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 3010 | * listed in @ois that are valid for this chip. Returns -EINVAL if |
| 3011 | * omap_hwmod_init() hasn't been called before calling this function, |
| 3012 | * -ENOMEM if the link memory area can't be allocated, or 0 upon |
| 3013 | * success. |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 3014 | */ |
| 3015 | int __init omap_hwmod_register_links(struct omap_hwmod_ocp_if **ois) |
| 3016 | { |
| 3017 | int r, i; |
| 3018 | |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 3019 | if (!inited) |
| 3020 | return -EINVAL; |
| 3021 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 3022 | if (!ois) |
| 3023 | return 0; |
| 3024 | |
Rajendra Nayak | f7f7a29 | 2014-08-27 19:38:23 -0600 | [diff] [blame] | 3025 | if (ois[0] == NULL) /* Empty list */ |
| 3026 | return 0; |
| 3027 | |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 3028 | i = 0; |
| 3029 | do { |
| 3030 | r = _register_link(ois[i]); |
| 3031 | WARN(r && r != -EEXIST, |
| 3032 | "omap_hwmod: _register_link(%s -> %s) returned %d\n", |
| 3033 | ois[i]->master->name, ois[i]->slave->name, r); |
| 3034 | } while (ois[++i]); |
| 3035 | |
| 3036 | return 0; |
| 3037 | } |
| 3038 | |
| 3039 | /** |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3040 | * _ensure_mpu_hwmod_is_setup - ensure the MPU SS hwmod is init'ed and set up |
| 3041 | * @oh: pointer to the hwmod currently being set up (usually not the MPU) |
Tony Lindgren | e7c7d76 | 2011-02-14 15:40:21 -0800 | [diff] [blame] | 3042 | * |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3043 | * If the hwmod data corresponding to the MPU subsystem IP block |
| 3044 | * hasn't been initialized and set up yet, do so now. This must be |
| 3045 | * done first since sleep dependencies may be added from other hwmods |
| 3046 | * to the MPU. Intended to be called only by omap_hwmod_setup*(). No |
| 3047 | * return value. |
Tony Lindgren | e7c7d76 | 2011-02-14 15:40:21 -0800 | [diff] [blame] | 3048 | */ |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3049 | static void __init _ensure_mpu_hwmod_is_setup(struct omap_hwmod *oh) |
Tony Lindgren | e7c7d76 | 2011-02-14 15:40:21 -0800 | [diff] [blame] | 3050 | { |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3051 | if (!mpu_oh || mpu_oh->_state == _HWMOD_STATE_UNKNOWN) |
| 3052 | pr_err("omap_hwmod: %s: MPU initiator hwmod %s not yet registered\n", |
| 3053 | __func__, MPU_INITIATOR_NAME); |
| 3054 | else if (mpu_oh->_state == _HWMOD_STATE_REGISTERED && oh != mpu_oh) |
| 3055 | omap_hwmod_setup_one(MPU_INITIATOR_NAME); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | /** |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3059 | * omap_hwmod_setup_one - set up a single hwmod |
| 3060 | * @oh_name: const char * name of the already-registered hwmod to set up |
| 3061 | * |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3062 | * Initialize and set up a single hwmod. Intended to be used for a |
| 3063 | * small number of early devices, such as the timer IP blocks used for |
| 3064 | * the scheduler clock. Must be called after omap2_clk_init(). |
| 3065 | * Resolves the struct clk names to struct clk pointers for each |
| 3066 | * registered omap_hwmod. Also calls _setup() on each hwmod. Returns |
| 3067 | * -EINVAL upon error or 0 upon success. |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3068 | */ |
| 3069 | int __init omap_hwmod_setup_one(const char *oh_name) |
| 3070 | { |
| 3071 | struct omap_hwmod *oh; |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3072 | |
| 3073 | pr_debug("omap_hwmod: %s: %s\n", oh_name, __func__); |
| 3074 | |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3075 | oh = _lookup(oh_name); |
| 3076 | if (!oh) { |
| 3077 | WARN(1, "omap_hwmod: %s: hwmod not yet registered\n", oh_name); |
| 3078 | return -EINVAL; |
| 3079 | } |
| 3080 | |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3081 | _ensure_mpu_hwmod_is_setup(oh); |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3082 | |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3083 | _init(oh, NULL); |
Paul Walmsley | a2debdb | 2011-02-23 00:14:07 -0700 | [diff] [blame] | 3084 | _setup(oh, NULL); |
| 3085 | |
| 3086 | return 0; |
| 3087 | } |
| 3088 | |
| 3089 | /** |
Lokesh Vutla | 8dd6666 | 2017-01-20 10:39:10 -0800 | [diff] [blame] | 3090 | * omap_hwmod_setup_earlycon_flags - set up flags for early console |
| 3091 | * |
| 3092 | * Enable DEBUG_OMAPUART_FLAGS for uart hwmod that is being used as |
| 3093 | * early concole so that hwmod core doesn't reset and keep it in idle |
| 3094 | * that specific uart. |
| 3095 | */ |
| 3096 | #ifdef CONFIG_SERIAL_EARLYCON |
| 3097 | static void __init omap_hwmod_setup_earlycon_flags(void) |
| 3098 | { |
| 3099 | struct device_node *np; |
| 3100 | struct omap_hwmod *oh; |
| 3101 | const char *uart; |
| 3102 | |
| 3103 | np = of_find_node_by_path("/chosen"); |
| 3104 | if (np) { |
| 3105 | uart = of_get_property(np, "stdout-path", NULL); |
| 3106 | if (uart) { |
| 3107 | np = of_find_node_by_path(uart); |
| 3108 | if (np) { |
| 3109 | uart = of_get_property(np, "ti,hwmods", NULL); |
| 3110 | oh = omap_hwmod_lookup(uart); |
| 3111 | if (oh) |
| 3112 | oh->flags |= DEBUG_OMAPUART_FLAGS; |
| 3113 | } |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | #endif |
| 3118 | |
| 3119 | /** |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3120 | * omap_hwmod_setup_all - set up all registered IP blocks |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3121 | * |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3122 | * Initialize and set up all IP blocks registered with the hwmod code. |
| 3123 | * Must be called after omap2_clk_init(). Resolves the struct clk |
| 3124 | * names to struct clk pointers for each registered omap_hwmod. Also |
| 3125 | * calls _setup() on each hwmod. Returns 0 upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3126 | */ |
Paul Walmsley | 550c809 | 2011-02-28 11:58:14 -0700 | [diff] [blame] | 3127 | static int __init omap_hwmod_setup_all(void) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3128 | { |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3129 | _ensure_mpu_hwmod_is_setup(NULL); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3130 | |
Paul Walmsley | 381d033 | 2012-04-19 00:58:22 -0600 | [diff] [blame] | 3131 | omap_hwmod_for_each(_init, NULL); |
Lokesh Vutla | 8dd6666 | 2017-01-20 10:39:10 -0800 | [diff] [blame] | 3132 | #ifdef CONFIG_SERIAL_EARLYCON |
| 3133 | omap_hwmod_setup_earlycon_flags(); |
| 3134 | #endif |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3135 | omap_hwmod_for_each(_setup, NULL); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3136 | |
| 3137 | return 0; |
| 3138 | } |
Tony Lindgren | 8dd5ea7 | 2015-12-03 11:38:09 -0800 | [diff] [blame] | 3139 | omap_postcore_initcall(omap_hwmod_setup_all); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3140 | |
| 3141 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3142 | * omap_hwmod_enable - enable an omap_hwmod |
| 3143 | * @oh: struct omap_hwmod * |
| 3144 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 3145 | * Enable an omap_hwmod @oh. Intended to be called by omap_device_enable(). |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3146 | * Returns -EINVAL on error or passes along the return value from _enable(). |
| 3147 | */ |
| 3148 | int omap_hwmod_enable(struct omap_hwmod *oh) |
| 3149 | { |
| 3150 | int r; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3151 | unsigned long flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3152 | |
| 3153 | if (!oh) |
| 3154 | return -EINVAL; |
| 3155 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3156 | spin_lock_irqsave(&oh->_lock, flags); |
| 3157 | r = _enable(oh); |
| 3158 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3159 | |
| 3160 | return r; |
| 3161 | } |
| 3162 | |
| 3163 | /** |
| 3164 | * omap_hwmod_idle - idle an omap_hwmod |
| 3165 | * @oh: struct omap_hwmod * |
| 3166 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 3167 | * Idle an omap_hwmod @oh. Intended to be called by omap_device_idle(). |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3168 | * Returns -EINVAL on error or passes along the return value from _idle(). |
| 3169 | */ |
| 3170 | int omap_hwmod_idle(struct omap_hwmod *oh) |
| 3171 | { |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3172 | int r; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3173 | unsigned long flags; |
| 3174 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3175 | if (!oh) |
| 3176 | return -EINVAL; |
| 3177 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3178 | spin_lock_irqsave(&oh->_lock, flags); |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3179 | r = _idle(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3180 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3181 | |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3182 | return r; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | /** |
| 3186 | * omap_hwmod_shutdown - shutdown an omap_hwmod |
| 3187 | * @oh: struct omap_hwmod * |
| 3188 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 3189 | * Shutdown an omap_hwmod @oh. Intended to be called by |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3190 | * omap_device_shutdown(). Returns -EINVAL on error or passes along |
| 3191 | * the return value from _shutdown(). |
| 3192 | */ |
| 3193 | int omap_hwmod_shutdown(struct omap_hwmod *oh) |
| 3194 | { |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3195 | int r; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3196 | unsigned long flags; |
| 3197 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3198 | if (!oh) |
| 3199 | return -EINVAL; |
| 3200 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3201 | spin_lock_irqsave(&oh->_lock, flags); |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3202 | r = _shutdown(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3203 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3204 | |
Pali RohƔr | 6da2335 | 2015-02-26 14:49:51 +0100 | [diff] [blame] | 3205 | return r; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3206 | } |
| 3207 | |
Paul Walmsley | 5e8370f | 2012-04-18 19:10:06 -0600 | [diff] [blame] | 3208 | /* |
| 3209 | * IP block data retrieval functions |
| 3210 | */ |
| 3211 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3212 | /** |
| 3213 | * omap_hwmod_count_resources - count number of struct resources needed by hwmod |
| 3214 | * @oh: struct omap_hwmod * |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3215 | * @flags: Type of resources to include when counting (IRQ/DMA/MEM) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3216 | * |
| 3217 | * Count the number of struct resource array elements necessary to |
| 3218 | * contain omap_hwmod @oh resources. Intended to be called by code |
| 3219 | * that registers omap_devices. Intended to be used to determine the |
| 3220 | * size of a dynamically-allocated struct resource array, before |
| 3221 | * calling omap_hwmod_fill_resources(). Returns the number of struct |
| 3222 | * resource array elements needed. |
| 3223 | * |
| 3224 | * XXX This code is not optimized. It could attempt to merge adjacent |
| 3225 | * resource IDs. |
| 3226 | * |
| 3227 | */ |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3228 | int omap_hwmod_count_resources(struct omap_hwmod *oh, unsigned long flags) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3229 | { |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3230 | int ret = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3231 | |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3232 | if (flags & IORESOURCE_IRQ) |
| 3233 | ret += _count_mpu_irqs(oh); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3234 | |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3235 | if (flags & IORESOURCE_DMA) |
| 3236 | ret += _count_sdma_reqs(oh); |
Paul Walmsley | 2221b5c | 2012-04-19 04:04:30 -0600 | [diff] [blame] | 3237 | |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3238 | if (flags & IORESOURCE_MEM) { |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3239 | struct omap_hwmod_ocp_if *os; |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3240 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 3241 | list_for_each_entry(os, &oh->slave_ports, node) |
Peter Ujfalusi | dad4191 | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3242 | ret += _count_ocp_if_addr_spaces(os); |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 3243 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3244 | |
| 3245 | return ret; |
| 3246 | } |
| 3247 | |
| 3248 | /** |
| 3249 | * omap_hwmod_fill_resources - fill struct resource array with hwmod data |
| 3250 | * @oh: struct omap_hwmod * |
| 3251 | * @res: pointer to the first element of an array of struct resource to fill |
| 3252 | * |
| 3253 | * Fill the struct resource array @res with resource data from the |
| 3254 | * omap_hwmod @oh. Intended to be called by code that registers |
| 3255 | * omap_devices. See also omap_hwmod_count_resources(). Returns the |
| 3256 | * number of array elements filled. |
| 3257 | */ |
| 3258 | int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) |
| 3259 | { |
Paul Walmsley | 5d95dde | 2012-04-19 04:04:28 -0600 | [diff] [blame] | 3260 | struct omap_hwmod_ocp_if *os; |
| 3261 | int i, j, mpu_irqs_cnt, sdma_reqs_cnt, addr_cnt; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3262 | int r = 0; |
| 3263 | |
| 3264 | /* For each IRQ, DMA, memory area, fill in array.*/ |
| 3265 | |
Paul Walmsley | 212738a | 2011-07-09 19:14:06 -0600 | [diff] [blame] | 3266 | mpu_irqs_cnt = _count_mpu_irqs(oh); |
| 3267 | for (i = 0; i < mpu_irqs_cnt; i++) { |
Marc Zyngier | 0fb22a8 | 2015-01-17 10:21:08 +0000 | [diff] [blame] | 3268 | unsigned int irq; |
| 3269 | |
| 3270 | if (oh->xlate_irq) |
| 3271 | irq = oh->xlate_irq((oh->mpu_irqs + i)->irq); |
| 3272 | else |
| 3273 | irq = (oh->mpu_irqs + i)->irq; |
Paul Walmsley | 718bfd7 | 2009-12-08 16:34:16 -0700 | [diff] [blame] | 3274 | (res + r)->name = (oh->mpu_irqs + i)->name; |
Marc Zyngier | 0fb22a8 | 2015-01-17 10:21:08 +0000 | [diff] [blame] | 3275 | (res + r)->start = irq; |
| 3276 | (res + r)->end = irq; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3277 | (res + r)->flags = IORESOURCE_IRQ; |
| 3278 | r++; |
| 3279 | } |
| 3280 | |
Paul Walmsley | bc61495 | 2011-07-09 19:14:07 -0600 | [diff] [blame] | 3281 | sdma_reqs_cnt = _count_sdma_reqs(oh); |
| 3282 | for (i = 0; i < sdma_reqs_cnt; i++) { |
Benoit Cousson | 9ee9fff | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 3283 | (res + r)->name = (oh->sdma_reqs + i)->name; |
| 3284 | (res + r)->start = (oh->sdma_reqs + i)->dma_req; |
| 3285 | (res + r)->end = (oh->sdma_reqs + i)->dma_req; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3286 | (res + r)->flags = IORESOURCE_DMA; |
| 3287 | r++; |
| 3288 | } |
| 3289 | |
Tony Lindgren | b8e1bdd | 2017-03-14 13:13:19 -0700 | [diff] [blame] | 3290 | list_for_each_entry(os, &oh->slave_ports, node) { |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 3291 | addr_cnt = _count_ocp_if_addr_spaces(os); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3292 | |
Paul Walmsley | 78183f3 | 2011-07-09 19:14:05 -0600 | [diff] [blame] | 3293 | for (j = 0; j < addr_cnt; j++) { |
Kishon Vijay Abraham I | cd50380 | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 3294 | (res + r)->name = (os->addr + j)->name; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3295 | (res + r)->start = (os->addr + j)->pa_start; |
| 3296 | (res + r)->end = (os->addr + j)->pa_end; |
| 3297 | (res + r)->flags = IORESOURCE_MEM; |
| 3298 | r++; |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | return r; |
| 3303 | } |
| 3304 | |
| 3305 | /** |
Vaibhav Hiremath | b82b04e | 2012-08-29 15:18:11 +0530 | [diff] [blame] | 3306 | * omap_hwmod_fill_dma_resources - fill struct resource array with dma data |
| 3307 | * @oh: struct omap_hwmod * |
| 3308 | * @res: pointer to the array of struct resource to fill |
| 3309 | * |
| 3310 | * Fill the struct resource array @res with dma resource data from the |
| 3311 | * omap_hwmod @oh. Intended to be called by code that registers |
| 3312 | * omap_devices. See also omap_hwmod_count_resources(). Returns the |
| 3313 | * number of array elements filled. |
| 3314 | */ |
| 3315 | int omap_hwmod_fill_dma_resources(struct omap_hwmod *oh, struct resource *res) |
| 3316 | { |
| 3317 | int i, sdma_reqs_cnt; |
| 3318 | int r = 0; |
| 3319 | |
| 3320 | sdma_reqs_cnt = _count_sdma_reqs(oh); |
| 3321 | for (i = 0; i < sdma_reqs_cnt; i++) { |
| 3322 | (res + r)->name = (oh->sdma_reqs + i)->name; |
| 3323 | (res + r)->start = (oh->sdma_reqs + i)->dma_req; |
| 3324 | (res + r)->end = (oh->sdma_reqs + i)->dma_req; |
| 3325 | (res + r)->flags = IORESOURCE_DMA; |
| 3326 | r++; |
| 3327 | } |
| 3328 | |
| 3329 | return r; |
| 3330 | } |
| 3331 | |
| 3332 | /** |
Paul Walmsley | 5e8370f | 2012-04-18 19:10:06 -0600 | [diff] [blame] | 3333 | * omap_hwmod_get_resource_byname - fetch IP block integration data by name |
| 3334 | * @oh: struct omap_hwmod * to operate on |
| 3335 | * @type: one of the IORESOURCE_* constants from include/linux/ioport.h |
| 3336 | * @name: pointer to the name of the data to fetch (optional) |
| 3337 | * @rsrc: pointer to a struct resource, allocated by the caller |
| 3338 | * |
| 3339 | * Retrieve MPU IRQ, SDMA request line, or address space start/end |
| 3340 | * data for the IP block pointed to by @oh. The data will be filled |
| 3341 | * into a struct resource record pointed to by @rsrc. The struct |
| 3342 | * resource must be allocated by the caller. When @name is non-null, |
| 3343 | * the data associated with the matching entry in the IRQ/SDMA/address |
| 3344 | * space hwmod data arrays will be returned. If @name is null, the |
| 3345 | * first array entry will be returned. Data order is not meaningful |
| 3346 | * in hwmod data, so callers are strongly encouraged to use a non-null |
| 3347 | * @name whenever possible to avoid unpredictable effects if hwmod |
| 3348 | * data is later added that causes data ordering to change. This |
| 3349 | * function is only intended for use by OMAP core code. Device |
| 3350 | * drivers should not call this function - the appropriate bus-related |
| 3351 | * data accessor functions should be used instead. Returns 0 upon |
| 3352 | * success or a negative error code upon error. |
| 3353 | */ |
| 3354 | int omap_hwmod_get_resource_byname(struct omap_hwmod *oh, unsigned int type, |
| 3355 | const char *name, struct resource *rsrc) |
| 3356 | { |
| 3357 | int r; |
| 3358 | unsigned int irq, dma; |
| 3359 | u32 pa_start, pa_end; |
| 3360 | |
| 3361 | if (!oh || !rsrc) |
| 3362 | return -EINVAL; |
| 3363 | |
| 3364 | if (type == IORESOURCE_IRQ) { |
| 3365 | r = _get_mpu_irq_by_name(oh, name, &irq); |
| 3366 | if (r) |
| 3367 | return r; |
| 3368 | |
| 3369 | rsrc->start = irq; |
| 3370 | rsrc->end = irq; |
| 3371 | } else if (type == IORESOURCE_DMA) { |
| 3372 | r = _get_sdma_req_by_name(oh, name, &dma); |
| 3373 | if (r) |
| 3374 | return r; |
| 3375 | |
| 3376 | rsrc->start = dma; |
| 3377 | rsrc->end = dma; |
| 3378 | } else if (type == IORESOURCE_MEM) { |
| 3379 | r = _get_addr_space_by_name(oh, name, &pa_start, &pa_end); |
| 3380 | if (r) |
| 3381 | return r; |
| 3382 | |
| 3383 | rsrc->start = pa_start; |
| 3384 | rsrc->end = pa_end; |
| 3385 | } else { |
| 3386 | return -EINVAL; |
| 3387 | } |
| 3388 | |
| 3389 | rsrc->flags = type; |
| 3390 | rsrc->name = name; |
| 3391 | |
| 3392 | return 0; |
| 3393 | } |
| 3394 | |
| 3395 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3396 | * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain |
| 3397 | * @oh: struct omap_hwmod * |
| 3398 | * |
| 3399 | * Return the powerdomain pointer associated with the OMAP module |
| 3400 | * @oh's main clock. If @oh does not have a main clk, return the |
| 3401 | * powerdomain associated with the interface clock associated with the |
| 3402 | * module's MPU port. (XXX Perhaps this should use the SDMA port |
| 3403 | * instead?) Returns NULL on error, or a struct powerdomain * on |
| 3404 | * success. |
| 3405 | */ |
| 3406 | struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh) |
| 3407 | { |
| 3408 | struct clk *c; |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 3409 | struct omap_hwmod_ocp_if *oi; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3410 | struct clockdomain *clkdm; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3411 | struct clk_hw_omap *clk; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3412 | |
| 3413 | if (!oh) |
| 3414 | return NULL; |
| 3415 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3416 | if (oh->clkdm) |
| 3417 | return oh->clkdm->pwrdm.ptr; |
| 3418 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3419 | if (oh->_clk) { |
| 3420 | c = oh->_clk; |
| 3421 | } else { |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 3422 | oi = _find_mpu_rt_port(oh); |
| 3423 | if (!oi) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3424 | return NULL; |
Paul Walmsley | 2d6141b | 2012-04-19 04:04:27 -0600 | [diff] [blame] | 3425 | c = oi->_clk; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3426 | } |
| 3427 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3428 | clk = to_clk_hw_omap(__clk_get_hw(c)); |
| 3429 | clkdm = clk->clkdm; |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3430 | if (!clkdm) |
Thara Gopinath | d5647c1 | 2010-03-31 04:16:29 -0600 | [diff] [blame] | 3431 | return NULL; |
| 3432 | |
Rajendra Nayak | f5dd3bb | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 3433 | return clkdm->pwrdm.ptr; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | /** |
Paul Walmsley | db2a60b | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 3437 | * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU) |
| 3438 | * @oh: struct omap_hwmod * |
| 3439 | * |
| 3440 | * Returns the virtual address corresponding to the beginning of the |
| 3441 | * module's register target, in the address range that is intended to |
| 3442 | * be used by the MPU. Returns the virtual address upon success or NULL |
| 3443 | * upon error. |
| 3444 | */ |
| 3445 | void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh) |
| 3446 | { |
| 3447 | if (!oh) |
| 3448 | return NULL; |
| 3449 | |
| 3450 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 3451 | return NULL; |
| 3452 | |
| 3453 | if (oh->_state == _HWMOD_STATE_UNKNOWN) |
| 3454 | return NULL; |
| 3455 | |
| 3456 | return oh->_mpu_rt_va; |
| 3457 | } |
| 3458 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3459 | /* |
| 3460 | * XXX what about functions for drivers to save/restore ocp_sysconfig |
| 3461 | * for context save/restore operations? |
| 3462 | */ |
| 3463 | |
| 3464 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3465 | * omap_hwmod_enable_wakeup - allow device to wake up the system |
| 3466 | * @oh: struct omap_hwmod * |
| 3467 | * |
| 3468 | * Sets the module OCP socket ENAWAKEUP bit to allow the module to |
Govindraj.R | 2a1cc14 | 2012-04-05 02:59:32 -0600 | [diff] [blame] | 3469 | * send wakeups to the PRCM, and enable I/O ring wakeup events for |
| 3470 | * this IP block if it has dynamic mux entries. Eventually this |
| 3471 | * should set PRCM wakeup registers to cause the PRCM to receive |
| 3472 | * wakeup events from the module. Does not set any wakeup routing |
| 3473 | * registers beyond this point - if the module is to wake up any other |
| 3474 | * module or subsystem, that must be set separately. Called by |
| 3475 | * omap_device code. Returns -EINVAL on error or 0 upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3476 | */ |
| 3477 | int omap_hwmod_enable_wakeup(struct omap_hwmod *oh) |
| 3478 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3479 | unsigned long flags; |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 3480 | u32 v; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3481 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3482 | spin_lock_irqsave(&oh->_lock, flags); |
Govindraj.R | 2a1cc14 | 2012-04-05 02:59:32 -0600 | [diff] [blame] | 3483 | |
| 3484 | if (oh->class->sysc && |
| 3485 | (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) { |
| 3486 | v = oh->_sysc_cache; |
| 3487 | _enable_wakeup(oh, &v); |
| 3488 | _write_sysconfig(v, oh); |
| 3489 | } |
| 3490 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3491 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3492 | |
| 3493 | return 0; |
| 3494 | } |
| 3495 | |
| 3496 | /** |
| 3497 | * omap_hwmod_disable_wakeup - prevent device from waking the system |
| 3498 | * @oh: struct omap_hwmod * |
| 3499 | * |
| 3500 | * Clears the module OCP socket ENAWAKEUP bit to prevent the module |
Govindraj.R | 2a1cc14 | 2012-04-05 02:59:32 -0600 | [diff] [blame] | 3501 | * from sending wakeups to the PRCM, and disable I/O ring wakeup |
| 3502 | * events for this IP block if it has dynamic mux entries. Eventually |
| 3503 | * this should clear PRCM wakeup registers to cause the PRCM to ignore |
| 3504 | * wakeup events from the module. Does not set any wakeup routing |
| 3505 | * registers beyond this point - if the module is to wake up any other |
| 3506 | * module or subsystem, that must be set separately. Called by |
| 3507 | * omap_device code. Returns -EINVAL on error or 0 upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3508 | */ |
| 3509 | int omap_hwmod_disable_wakeup(struct omap_hwmod *oh) |
| 3510 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3511 | unsigned long flags; |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 3512 | u32 v; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3513 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3514 | spin_lock_irqsave(&oh->_lock, flags); |
Govindraj.R | 2a1cc14 | 2012-04-05 02:59:32 -0600 | [diff] [blame] | 3515 | |
| 3516 | if (oh->class->sysc && |
| 3517 | (oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) { |
| 3518 | v = oh->_sysc_cache; |
| 3519 | _disable_wakeup(oh, &v); |
| 3520 | _write_sysconfig(v, oh); |
| 3521 | } |
| 3522 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3523 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 3524 | |
| 3525 | return 0; |
| 3526 | } |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 3527 | |
| 3528 | /** |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3529 | * omap_hwmod_assert_hardreset - assert the HW reset line of submodules |
| 3530 | * contained in the hwmod module. |
| 3531 | * @oh: struct omap_hwmod * |
| 3532 | * @name: name of the reset line to lookup and assert |
| 3533 | * |
| 3534 | * Some IP like dsp, ipu or iva contain processor that require |
| 3535 | * an HW reset line to be assert / deassert in order to enable fully |
| 3536 | * the IP. Returns -EINVAL if @oh is null or if the operation is not |
| 3537 | * yet supported on this OMAP; otherwise, passes along the return value |
| 3538 | * from _assert_hardreset(). |
| 3539 | */ |
| 3540 | int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name) |
| 3541 | { |
| 3542 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3543 | unsigned long flags; |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3544 | |
| 3545 | if (!oh) |
| 3546 | return -EINVAL; |
| 3547 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3548 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3549 | ret = _assert_hardreset(oh, name); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3550 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3551 | |
| 3552 | return ret; |
| 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules |
| 3557 | * contained in the hwmod module. |
| 3558 | * @oh: struct omap_hwmod * |
| 3559 | * @name: name of the reset line to look up and deassert |
| 3560 | * |
| 3561 | * Some IP like dsp, ipu or iva contain processor that require |
| 3562 | * an HW reset line to be assert / deassert in order to enable fully |
| 3563 | * the IP. Returns -EINVAL if @oh is null or if the operation is not |
| 3564 | * yet supported on this OMAP; otherwise, passes along the return value |
| 3565 | * from _deassert_hardreset(). |
| 3566 | */ |
| 3567 | int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name) |
| 3568 | { |
| 3569 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3570 | unsigned long flags; |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3571 | |
| 3572 | if (!oh) |
| 3573 | return -EINVAL; |
| 3574 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3575 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3576 | ret = _deassert_hardreset(oh, name); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3577 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 3578 | |
| 3579 | return ret; |
| 3580 | } |
| 3581 | |
| 3582 | /** |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 3583 | * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname |
| 3584 | * @classname: struct omap_hwmod_class name to search for |
| 3585 | * @fn: callback function pointer to call for each hwmod in class @classname |
| 3586 | * @user: arbitrary context data to pass to the callback function |
| 3587 | * |
Benoit Cousson | ce35b24 | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 3588 | * For each omap_hwmod of class @classname, call @fn. |
| 3589 | * If the callback function returns something other than |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 3590 | * zero, the iterator is terminated, and the callback function's return |
| 3591 | * value is passed back to the caller. Returns 0 upon success, -EINVAL |
| 3592 | * if @classname or @fn are NULL, or passes back the error code from @fn. |
| 3593 | */ |
| 3594 | int omap_hwmod_for_each_by_class(const char *classname, |
| 3595 | int (*fn)(struct omap_hwmod *oh, |
| 3596 | void *user), |
| 3597 | void *user) |
| 3598 | { |
| 3599 | struct omap_hwmod *temp_oh; |
| 3600 | int ret = 0; |
| 3601 | |
| 3602 | if (!classname || !fn) |
| 3603 | return -EINVAL; |
| 3604 | |
| 3605 | pr_debug("omap_hwmod: %s: looking for modules of class %s\n", |
| 3606 | __func__, classname); |
| 3607 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 3608 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 3609 | if (!strcmp(temp_oh->class->name, classname)) { |
| 3610 | pr_debug("omap_hwmod: %s: %s: calling callback fn\n", |
| 3611 | __func__, temp_oh->name); |
| 3612 | ret = (*fn)(temp_oh, user); |
| 3613 | if (ret) |
| 3614 | break; |
| 3615 | } |
| 3616 | } |
| 3617 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 3618 | if (ret) |
| 3619 | pr_debug("omap_hwmod: %s: iterator terminated early: %d\n", |
| 3620 | __func__, ret); |
| 3621 | |
| 3622 | return ret; |
| 3623 | } |
| 3624 | |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3625 | /** |
| 3626 | * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod |
| 3627 | * @oh: struct omap_hwmod * |
| 3628 | * @state: state that _setup() should leave the hwmod in |
| 3629 | * |
Paul Walmsley | 550c809 | 2011-02-28 11:58:14 -0700 | [diff] [blame] | 3630 | * Sets the hwmod state that @oh will enter at the end of _setup() |
Paul Walmsley | 64813c3 | 2012-04-18 19:10:03 -0600 | [diff] [blame] | 3631 | * (called by omap_hwmod_setup_*()). See also the documentation |
| 3632 | * for _setup_postsetup(), above. Returns 0 upon success or |
| 3633 | * -EINVAL if there is a problem with the arguments or if the hwmod is |
| 3634 | * in the wrong state. |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3635 | */ |
| 3636 | int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state) |
| 3637 | { |
| 3638 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3639 | unsigned long flags; |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3640 | |
| 3641 | if (!oh) |
| 3642 | return -EINVAL; |
| 3643 | |
| 3644 | if (state != _HWMOD_STATE_DISABLED && |
| 3645 | state != _HWMOD_STATE_ENABLED && |
| 3646 | state != _HWMOD_STATE_IDLE) |
| 3647 | return -EINVAL; |
| 3648 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3649 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3650 | |
| 3651 | if (oh->_state != _HWMOD_STATE_REGISTERED) { |
| 3652 | ret = -EINVAL; |
| 3653 | goto ohsps_unlock; |
| 3654 | } |
| 3655 | |
| 3656 | oh->_postsetup_state = state; |
| 3657 | ret = 0; |
| 3658 | |
| 3659 | ohsps_unlock: |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3660 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 3661 | |
| 3662 | return ret; |
| 3663 | } |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 3664 | |
| 3665 | /** |
| 3666 | * omap_hwmod_get_context_loss_count - get lost context count |
| 3667 | * @oh: struct omap_hwmod * |
| 3668 | * |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3669 | * Returns the context loss count of associated @oh |
| 3670 | * upon success, or zero if no context loss data is available. |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 3671 | * |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3672 | * On OMAP4, this queries the per-hwmod context loss register, |
| 3673 | * assuming one exists. If not, or on OMAP2/3, this queries the |
| 3674 | * enclosing powerdomain context loss count. |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 3675 | */ |
Tomi Valkeinen | fc01387 | 2011-06-09 16:56:23 +0300 | [diff] [blame] | 3676 | int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh) |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 3677 | { |
| 3678 | struct powerdomain *pwrdm; |
| 3679 | int ret = 0; |
| 3680 | |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3681 | if (soc_ops.get_context_lost) |
| 3682 | return soc_ops.get_context_lost(oh); |
| 3683 | |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 3684 | pwrdm = omap_hwmod_get_pwrdm(oh); |
| 3685 | if (pwrdm) |
| 3686 | ret = pwrdm_get_context_loss_count(pwrdm); |
| 3687 | |
| 3688 | return ret; |
| 3689 | } |
Paul Walmsley | 43b0164 | 2011-03-10 03:50:07 -0700 | [diff] [blame] | 3690 | |
| 3691 | /** |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 3692 | * omap_hwmod_init - initialize the hwmod code |
| 3693 | * |
| 3694 | * Sets up some function pointers needed by the hwmod code to operate on the |
| 3695 | * currently-booted SoC. Intended to be called once during kernel init |
| 3696 | * before any hwmods are registered. No return value. |
| 3697 | */ |
| 3698 | void __init omap_hwmod_init(void) |
| 3699 | { |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 3700 | if (cpu_is_omap24xx()) { |
Tero Kristo | 9002e921 | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 3701 | soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready; |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 3702 | soc_ops.assert_hardreset = _omap2_assert_hardreset; |
| 3703 | soc_ops.deassert_hardreset = _omap2_deassert_hardreset; |
| 3704 | soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted; |
| 3705 | } else if (cpu_is_omap34xx()) { |
Tero Kristo | 9002e921 | 2014-10-27 08:39:23 -0700 | [diff] [blame] | 3706 | soc_ops.wait_target_ready = _omap2xxx_3xxx_wait_target_ready; |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 3707 | soc_ops.assert_hardreset = _omap2_assert_hardreset; |
| 3708 | soc_ops.deassert_hardreset = _omap2_deassert_hardreset; |
| 3709 | soc_ops.is_hardreset_asserted = _omap2_is_hardreset_asserted; |
Tero Kristo | 0385c58 | 2013-07-17 18:03:25 +0300 | [diff] [blame] | 3710 | soc_ops.init_clkdm = _init_clkdm; |
Rajendra Nayak | debcd1f | 2013-07-02 18:20:08 +0530 | [diff] [blame] | 3711 | } else if (cpu_is_omap44xx() || soc_is_omap54xx() || soc_is_dra7xx()) { |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 3712 | soc_ops.enable_module = _omap4_enable_module; |
| 3713 | soc_ops.disable_module = _omap4_disable_module; |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 3714 | soc_ops.wait_target_ready = _omap4_wait_target_ready; |
Kevin Hilman | b8249cf | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 3715 | soc_ops.assert_hardreset = _omap4_assert_hardreset; |
| 3716 | soc_ops.deassert_hardreset = _omap4_deassert_hardreset; |
| 3717 | soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted; |
Kevin Hilman | 0a179ea | 2012-06-18 12:12:25 -0600 | [diff] [blame] | 3718 | soc_ops.init_clkdm = _init_clkdm; |
Rajendra Nayak | e6d3a8b | 2012-11-21 16:15:17 -0700 | [diff] [blame] | 3719 | soc_ops.update_context_lost = _omap4_update_context_lost; |
| 3720 | soc_ops.get_context_lost = _omap4_get_context_lost; |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 3721 | soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm; |
Tony Lindgren | 0f3ccb2 | 2015-07-16 01:55:58 -0700 | [diff] [blame] | 3722 | } else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() || |
| 3723 | soc_is_am43xx()) { |
Afzal Mohammed | c8b428a | 2013-10-12 15:46:20 +0530 | [diff] [blame] | 3724 | soc_ops.enable_module = _omap4_enable_module; |
| 3725 | soc_ops.disable_module = _omap4_disable_module; |
| 3726 | soc_ops.wait_target_ready = _omap4_wait_target_ready; |
Tero Kristo | 409d706 | 2014-10-27 08:39:24 -0700 | [diff] [blame] | 3727 | soc_ops.assert_hardreset = _omap4_assert_hardreset; |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 3728 | soc_ops.deassert_hardreset = _am33xx_deassert_hardreset; |
Tero Kristo | a5bf00c | 2015-05-05 16:33:05 +0300 | [diff] [blame] | 3729 | soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted; |
Vaibhav Hiremath | 1688bf1 | 2012-09-11 17:18:53 -0600 | [diff] [blame] | 3730 | soc_ops.init_clkdm = _init_clkdm; |
Tero Kristo | 9fabc1a | 2016-07-04 14:11:48 +0300 | [diff] [blame] | 3731 | soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm; |
Kevin Hilman | 8f6aa8e | 2012-06-18 12:12:24 -0600 | [diff] [blame] | 3732 | } else { |
| 3733 | WARN(1, "omap_hwmod: unknown SoC type\n"); |
Kevin Hilman | 9ebfd28 | 2012-06-18 12:12:23 -0600 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | inited = true; |
| 3737 | } |
Tony Lindgren | 68c9a95 | 2012-07-06 00:58:43 -0700 | [diff] [blame] | 3738 | |
| 3739 | /** |
| 3740 | * omap_hwmod_get_main_clk - get pointer to main clock name |
| 3741 | * @oh: struct omap_hwmod * |
| 3742 | * |
| 3743 | * Returns the main clock name assocated with @oh upon success, |
| 3744 | * or NULL if @oh is NULL. |
| 3745 | */ |
| 3746 | const char *omap_hwmod_get_main_clk(struct omap_hwmod *oh) |
| 3747 | { |
| 3748 | if (!oh) |
| 3749 | return NULL; |
| 3750 | |
| 3751 | return oh->main_clk; |
| 3752 | } |