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