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