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