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