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