Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1 | /* |
| 2 | * omap_hwmod implementation for OMAP2/3/4 |
| 3 | * |
Paul Walmsley | db2a60b | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Nokia Corporation |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 5 | * |
Paul Walmsley | 4788da2 | 2010-05-18 20:24:05 -0600 | [diff] [blame] | 6 | * Paul Walmsley, Benoît Cousson, Kevin Hilman |
| 7 | * |
| 8 | * Created in collaboration with (alphabetical order): Thara Gopinath, |
| 9 | * Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari Poussa, Anand |
| 10 | * Sawant, Santosh Shilimkar, Richard Woodruff |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 16 | * Introduction |
| 17 | * ------------ |
| 18 | * One way to view an OMAP SoC is as a collection of largely unrelated |
| 19 | * IP blocks connected by interconnects. The IP blocks include |
| 20 | * devices such as ARM processors, audio serial interfaces, UARTs, |
| 21 | * etc. Some of these devices, like the DSP, are created by TI; |
| 22 | * others, like the SGX, largely originate from external vendors. In |
| 23 | * TI's documentation, on-chip devices are referred to as "OMAP |
| 24 | * modules." Some of these IP blocks are identical across several |
| 25 | * OMAP versions. Others are revised frequently. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 26 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 27 | * These OMAP modules are tied together by various interconnects. |
| 28 | * Most of the address and data flow between modules is via OCP-based |
| 29 | * interconnects such as the L3 and L4 buses; but there are other |
| 30 | * interconnects that distribute the hardware clock tree, handle idle |
| 31 | * and reset signaling, supply power, and connect the modules to |
| 32 | * various pads or balls on the OMAP package. |
| 33 | * |
| 34 | * OMAP hwmod provides a consistent way to describe the on-chip |
| 35 | * hardware blocks and their integration into the rest of the chip. |
| 36 | * This description can be automatically generated from the TI |
| 37 | * hardware database. OMAP hwmod provides a standard, consistent API |
| 38 | * to reset, enable, idle, and disable these hardware blocks. And |
| 39 | * hwmod provides a way for other core code, such as the Linux device |
| 40 | * code or the OMAP power management and address space mapping code, |
| 41 | * to query the hardware database. |
| 42 | * |
| 43 | * Using hwmod |
| 44 | * ----------- |
| 45 | * Drivers won't call hwmod functions directly. That is done by the |
| 46 | * omap_device code, and in rare occasions, by custom integration code |
| 47 | * in arch/arm/ *omap*. The omap_device code includes functions to |
| 48 | * build a struct platform_device using omap_hwmod data, and that is |
| 49 | * currently how hwmod data is communicated to drivers and to the |
| 50 | * Linux driver model. Most drivers will call omap_hwmod functions only |
| 51 | * indirectly, via pm_runtime*() functions. |
| 52 | * |
| 53 | * From a layering perspective, here is where the OMAP hwmod code |
| 54 | * fits into the kernel software stack: |
| 55 | * |
| 56 | * +-------------------------------+ |
| 57 | * | Device driver code | |
| 58 | * | (e.g., drivers/) | |
| 59 | * +-------------------------------+ |
| 60 | * | Linux driver model | |
| 61 | * | (platform_device / | |
| 62 | * | platform_driver data/code) | |
| 63 | * +-------------------------------+ |
| 64 | * | OMAP core-driver integration | |
| 65 | * |(arch/arm/mach-omap2/devices.c)| |
| 66 | * +-------------------------------+ |
| 67 | * | omap_device code | |
| 68 | * | (../plat-omap/omap_device.c) | |
| 69 | * +-------------------------------+ |
| 70 | * ----> | omap_hwmod code/data | <----- |
| 71 | * | (../mach-omap2/omap_hwmod*) | |
| 72 | * +-------------------------------+ |
| 73 | * | OMAP clock/PRCM/register fns | |
| 74 | * | (__raw_{read,write}l, clk*) | |
| 75 | * +-------------------------------+ |
| 76 | * |
| 77 | * Device drivers should not contain any OMAP-specific code or data in |
| 78 | * them. They should only contain code to operate the IP block that |
| 79 | * the driver is responsible for. This is because these IP blocks can |
| 80 | * also appear in other SoCs, either from TI (such as DaVinci) or from |
| 81 | * other manufacturers; and drivers should be reusable across other |
| 82 | * platforms. |
| 83 | * |
| 84 | * The OMAP hwmod code also will attempt to reset and idle all on-chip |
| 85 | * devices upon boot. The goal here is for the kernel to be |
| 86 | * completely self-reliant and independent from bootloaders. This is |
| 87 | * to ensure a repeatable configuration, both to ensure consistent |
| 88 | * runtime behavior, and to make it easier for others to reproduce |
| 89 | * bugs. |
| 90 | * |
| 91 | * OMAP module activity states |
| 92 | * --------------------------- |
| 93 | * The hwmod code considers modules to be in one of several activity |
| 94 | * states. IP blocks start out in an UNKNOWN state, then once they |
| 95 | * are registered via the hwmod code, proceed to the REGISTERED state. |
| 96 | * Once their clock names are resolved to clock pointers, the module |
| 97 | * enters the CLKS_INITED state; and finally, once the module has been |
| 98 | * reset and the integration registers programmed, the INITIALIZED state |
| 99 | * is entered. The hwmod code will then place the module into either |
| 100 | * the IDLE state to save power, or in the case of a critical system |
| 101 | * module, the ENABLED state. |
| 102 | * |
| 103 | * OMAP core integration code can then call omap_hwmod*() functions |
| 104 | * directly to move the module between the IDLE, ENABLED, and DISABLED |
| 105 | * states, as needed. This is done during both the PM idle loop, and |
| 106 | * in the OMAP core integration code's implementation of the PM runtime |
| 107 | * functions. |
| 108 | * |
| 109 | * References |
| 110 | * ---------- |
| 111 | * This is a partial list. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 112 | * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064) |
| 113 | * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090) |
| 114 | * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108) |
| 115 | * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140) |
| 116 | * - Open Core Protocol Specification 2.2 |
| 117 | * |
| 118 | * To do: |
| 119 | * - pin mux handling |
| 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> |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 139 | |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 140 | #include <plat/common.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 141 | #include <plat/cpu.h> |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 142 | #include "clockdomain.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 143 | #include "powerdomain.h" |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 144 | #include <plat/clock.h> |
| 145 | #include <plat/omap_hwmod.h> |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 146 | #include <plat/prcm.h> |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 147 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 148 | #include "cm2xxx_3xxx.h" |
| 149 | #include "cm44xx.h" |
| 150 | #include "prm2xxx_3xxx.h" |
Paul Walmsley | d198b51 | 2010-12-21 15:30:54 -0700 | [diff] [blame] | 151 | #include "prm44xx.h" |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 152 | |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 153 | /* Maximum microseconds to wait for OMAP module to softreset */ |
| 154 | #define MAX_MODULE_SOFTRESET_WAIT 10000 |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 155 | |
| 156 | /* Name of the OMAP hwmod for the MPU */ |
Benoit Cousson | 5c2c029 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 157 | #define MPU_INITIATOR_NAME "mpu" |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 158 | |
| 159 | /* omap_hwmod_list contains all registered struct omap_hwmods */ |
| 160 | static LIST_HEAD(omap_hwmod_list); |
| 161 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 162 | /* mpu_oh: used to add/remove MPU initiator from sleepdep list */ |
| 163 | static struct omap_hwmod *mpu_oh; |
| 164 | |
| 165 | /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */ |
| 166 | static u8 inited; |
| 167 | |
| 168 | |
| 169 | /* Private functions */ |
| 170 | |
| 171 | /** |
| 172 | * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy |
| 173 | * @oh: struct omap_hwmod * |
| 174 | * |
| 175 | * Load the current value of the hwmod OCP_SYSCONFIG register into the |
| 176 | * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no |
| 177 | * OCP_SYSCONFIG register or 0 upon success. |
| 178 | */ |
| 179 | static int _update_sysc_cache(struct omap_hwmod *oh) |
| 180 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 181 | if (!oh->class->sysc) { |
| 182 | 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] | 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | /* XXX ensure module interface clock is up */ |
| 187 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 188 | oh->_sysc_cache = omap_hwmod_read(oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 189 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 190 | if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE)) |
Thara Gopinath | 883edfd | 2010-01-19 17:30:51 -0700 | [diff] [blame] | 191 | oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register |
| 198 | * @v: OCP_SYSCONFIG value to write |
| 199 | * @oh: struct omap_hwmod * |
| 200 | * |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 201 | * Write @v into the module class' OCP_SYSCONFIG register, if it has |
| 202 | * one. No return value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 203 | */ |
| 204 | static void _write_sysconfig(u32 v, struct omap_hwmod *oh) |
| 205 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 206 | if (!oh->class->sysc) { |
| 207 | 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] | 208 | return; |
| 209 | } |
| 210 | |
| 211 | /* XXX ensure module interface clock is up */ |
| 212 | |
Rajendra Nayak | 233cbe5 | 2010-12-14 12:42:36 -0700 | [diff] [blame] | 213 | /* Module might have lost context, always update cache and register */ |
| 214 | oh->_sysc_cache = v; |
| 215 | omap_hwmod_write(v, oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /** |
| 219 | * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v |
| 220 | * @oh: struct omap_hwmod * |
| 221 | * @standbymode: MIDLEMODE field bits |
| 222 | * @v: pointer to register contents to modify |
| 223 | * |
| 224 | * Update the master standby mode bits in @v to be @standbymode for |
| 225 | * the @oh hwmod. Does not write to the hardware. Returns -EINVAL |
| 226 | * upon error or 0 upon success. |
| 227 | */ |
| 228 | static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode, |
| 229 | u32 *v) |
| 230 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 231 | u32 mstandby_mask; |
| 232 | u8 mstandby_shift; |
| 233 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 234 | if (!oh->class->sysc || |
| 235 | !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 238 | if (!oh->class->sysc->sysc_fields) { |
| 239 | 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] | 240 | return -EINVAL; |
| 241 | } |
| 242 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 243 | mstandby_shift = oh->class->sysc->sysc_fields->midle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 244 | mstandby_mask = (0x3 << mstandby_shift); |
| 245 | |
| 246 | *v &= ~mstandby_mask; |
| 247 | *v |= __ffs(standbymode) << mstandby_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v |
| 254 | * @oh: struct omap_hwmod * |
| 255 | * @idlemode: SIDLEMODE field bits |
| 256 | * @v: pointer to register contents to modify |
| 257 | * |
| 258 | * Update the slave idle mode bits in @v to be @idlemode for the @oh |
| 259 | * hwmod. Does not write to the hardware. Returns -EINVAL upon error |
| 260 | * or 0 upon success. |
| 261 | */ |
| 262 | static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v) |
| 263 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 264 | u32 sidle_mask; |
| 265 | u8 sidle_shift; |
| 266 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 267 | if (!oh->class->sysc || |
| 268 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 269 | return -EINVAL; |
| 270 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 271 | if (!oh->class->sysc->sysc_fields) { |
| 272 | 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] | 273 | return -EINVAL; |
| 274 | } |
| 275 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 276 | sidle_shift = oh->class->sysc->sysc_fields->sidle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 277 | sidle_mask = (0x3 << sidle_shift); |
| 278 | |
| 279 | *v &= ~sidle_mask; |
| 280 | *v |= __ffs(idlemode) << sidle_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v |
| 287 | * @oh: struct omap_hwmod * |
| 288 | * @clockact: CLOCKACTIVITY field bits |
| 289 | * @v: pointer to register contents to modify |
| 290 | * |
| 291 | * Update the clockactivity mode bits in @v to be @clockact for the |
| 292 | * @oh hwmod. Used for additional powersaving on some modules. Does |
| 293 | * not write to the hardware. Returns -EINVAL upon error or 0 upon |
| 294 | * success. |
| 295 | */ |
| 296 | static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v) |
| 297 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 298 | u32 clkact_mask; |
| 299 | u8 clkact_shift; |
| 300 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 301 | if (!oh->class->sysc || |
| 302 | !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 303 | return -EINVAL; |
| 304 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 305 | if (!oh->class->sysc->sysc_fields) { |
| 306 | 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] | 307 | return -EINVAL; |
| 308 | } |
| 309 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 310 | clkact_shift = oh->class->sysc->sysc_fields->clkact_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 311 | clkact_mask = (0x3 << clkact_shift); |
| 312 | |
| 313 | *v &= ~clkact_mask; |
| 314 | *v |= clockact << clkact_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v |
| 321 | * @oh: struct omap_hwmod * |
| 322 | * @v: pointer to register contents to modify |
| 323 | * |
| 324 | * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon |
| 325 | * error or 0 upon success. |
| 326 | */ |
| 327 | static int _set_softreset(struct omap_hwmod *oh, u32 *v) |
| 328 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 329 | u32 softrst_mask; |
| 330 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 331 | if (!oh->class->sysc || |
| 332 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 333 | return -EINVAL; |
| 334 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 335 | if (!oh->class->sysc->sysc_fields) { |
| 336 | WARN(1, "omap_hwmod: %s: offset struct for sysconfig not provided in class\n", oh->name); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 337 | return -EINVAL; |
| 338 | } |
| 339 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 340 | softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 341 | |
| 342 | *v |= softrst_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | /** |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 348 | * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v |
| 349 | * @oh: struct omap_hwmod * |
| 350 | * @autoidle: desired AUTOIDLE bitfield value (0 or 1) |
| 351 | * @v: pointer to register contents to modify |
| 352 | * |
| 353 | * Update the module autoidle bit in @v to be @autoidle for the @oh |
| 354 | * hwmod. The autoidle bit controls whether the module can gate |
| 355 | * internal clocks automatically when it isn't doing anything; the |
| 356 | * exact function of this bit varies on a per-module basis. This |
| 357 | * function does not write to the hardware. Returns -EINVAL upon |
| 358 | * error or 0 upon success. |
| 359 | */ |
| 360 | static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle, |
| 361 | u32 *v) |
| 362 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 363 | u32 autoidle_mask; |
| 364 | u8 autoidle_shift; |
| 365 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 366 | if (!oh->class->sysc || |
| 367 | !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE)) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 368 | return -EINVAL; |
| 369 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 370 | if (!oh->class->sysc->sysc_fields) { |
| 371 | 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] | 372 | return -EINVAL; |
| 373 | } |
| 374 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 375 | autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 376 | autoidle_mask = (0x3 << autoidle_shift); |
| 377 | |
| 378 | *v &= ~autoidle_mask; |
| 379 | *v |= autoidle << autoidle_shift; |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 385 | * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 386 | * @oh: struct omap_hwmod * |
| 387 | * |
| 388 | * Allow the hardware module @oh to send wakeups. Returns -EINVAL |
| 389 | * upon error or 0 upon success. |
| 390 | */ |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 391 | static int _enable_wakeup(struct omap_hwmod *oh, u32 *v) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 392 | { |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 393 | u32 wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 394 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 395 | if (!oh->class->sysc || |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 396 | !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) || |
| 397 | (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP))) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 398 | return -EINVAL; |
| 399 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 400 | if (!oh->class->sysc->sysc_fields) { |
| 401 | 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] | 402 | return -EINVAL; |
| 403 | } |
| 404 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 405 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 406 | |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 407 | *v |= wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 408 | |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 409 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 410 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART_WKUP, v); |
| 411 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 412 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 413 | |
| 414 | oh->_int_flags |= _HWMOD_WAKEUP_ENABLED; |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 421 | * @oh: struct omap_hwmod * |
| 422 | * |
| 423 | * Prevent the hardware module @oh to send wakeups. Returns -EINVAL |
| 424 | * upon error or 0 upon success. |
| 425 | */ |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 426 | static int _disable_wakeup(struct omap_hwmod *oh, u32 *v) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 427 | { |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 428 | u32 wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 429 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 430 | if (!oh->class->sysc || |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 431 | !((oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP) || |
| 432 | (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP))) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 433 | return -EINVAL; |
| 434 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 435 | if (!oh->class->sysc->sysc_fields) { |
| 436 | 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] | 437 | return -EINVAL; |
| 438 | } |
| 439 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 440 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 441 | |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 442 | *v &= ~wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 443 | |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 444 | if (oh->class->sysc->idlemodes & SIDLE_SMART_WKUP) |
| 445 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_SMART, v); |
| 446 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 447 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 448 | |
| 449 | oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED; |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active |
| 456 | * @oh: struct omap_hwmod * |
| 457 | * |
| 458 | * Prevent the hardware module @oh from entering idle while the |
| 459 | * hardare module initiator @init_oh is active. Useful when a module |
| 460 | * will be accessed by a particular initiator (e.g., if a module will |
| 461 | * be accessed by the IVA, there should be a sleepdep between the IVA |
| 462 | * initiator and the module). Only applies to modules in smart-idle |
| 463 | * mode. Returns -EINVAL upon error or passes along |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 464 | * clkdm_add_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 465 | */ |
| 466 | static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 467 | { |
| 468 | if (!oh->_clk) |
| 469 | return -EINVAL; |
| 470 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 471 | return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| 475 | * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active |
| 476 | * @oh: struct omap_hwmod * |
| 477 | * |
| 478 | * Allow the hardware module @oh to enter idle while the hardare |
| 479 | * module initiator @init_oh is active. Useful when a module will not |
| 480 | * be accessed by a particular initiator (e.g., if a module will not |
| 481 | * be accessed by the IVA, there should be no sleepdep between the IVA |
| 482 | * initiator and the module). Only applies to modules in smart-idle |
| 483 | * mode. Returns -EINVAL upon error or passes along |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 484 | * clkdm_del_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 485 | */ |
| 486 | static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 487 | { |
| 488 | if (!oh->_clk) |
| 489 | return -EINVAL; |
| 490 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 491 | return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
| 495 | * _init_main_clk - get a struct clk * for the the hwmod's main functional clk |
| 496 | * @oh: struct omap_hwmod * |
| 497 | * |
| 498 | * Called from _init_clocks(). Populates the @oh _clk (main |
| 499 | * functional clock pointer) if a main_clk is present. Returns 0 on |
| 500 | * success or -EINVAL on error. |
| 501 | */ |
| 502 | static int _init_main_clk(struct omap_hwmod *oh) |
| 503 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 504 | int ret = 0; |
| 505 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 506 | if (!oh->main_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 507 | return 0; |
| 508 | |
Benoit Cousson | 6340338 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 509 | oh->_clk = omap_clk_get_by_name(oh->main_clk); |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 510 | if (!oh->_clk) { |
Benoit Cousson | 20383d8 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 511 | pr_warning("omap_hwmod: %s: cannot clk_get main_clk %s\n", |
| 512 | oh->name, oh->main_clk); |
Benoit Cousson | 6340338 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 513 | return -EINVAL; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 514 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 515 | |
Benoit Cousson | 6340338 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 516 | if (!oh->_clk->clkdm) |
| 517 | pr_warning("omap_hwmod: %s: missing clockdomain for %s.\n", |
| 518 | oh->main_clk, oh->_clk->name); |
Kevin Hilman | 81d7c6f | 2009-12-08 16:34:24 -0700 | [diff] [blame] | 519 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | /** |
Paul Walmsley | 887adea | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 524 | * _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] | 525 | * @oh: struct omap_hwmod * |
| 526 | * |
| 527 | * Called from _init_clocks(). Populates the @oh OCP slave interface |
| 528 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 529 | */ |
| 530 | static int _init_interface_clks(struct omap_hwmod *oh) |
| 531 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 532 | struct clk *c; |
| 533 | int i; |
| 534 | int ret = 0; |
| 535 | |
| 536 | if (oh->slaves_cnt == 0) |
| 537 | return 0; |
| 538 | |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 539 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 540 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; |
| 541 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 542 | if (!os->clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 543 | continue; |
| 544 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 545 | c = omap_clk_get_by_name(os->clk); |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 546 | if (!c) { |
Benoit Cousson | 20383d8 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 547 | pr_warning("omap_hwmod: %s: cannot clk_get interface_clk %s\n", |
| 548 | oh->name, os->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 549 | ret = -EINVAL; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 550 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 551 | os->_clk = c; |
| 552 | } |
| 553 | |
| 554 | return ret; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks |
| 559 | * @oh: struct omap_hwmod * |
| 560 | * |
| 561 | * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk |
| 562 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 563 | */ |
| 564 | static int _init_opt_clks(struct omap_hwmod *oh) |
| 565 | { |
| 566 | struct omap_hwmod_opt_clk *oc; |
| 567 | struct clk *c; |
| 568 | int i; |
| 569 | int ret = 0; |
| 570 | |
| 571 | 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] | 572 | c = omap_clk_get_by_name(oc->clk); |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 573 | if (!c) { |
Benoit Cousson | 20383d8 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 574 | pr_warning("omap_hwmod: %s: cannot clk_get opt_clk %s\n", |
| 575 | oh->name, oc->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 576 | ret = -EINVAL; |
Benoit Cousson | dc75925 | 2010-06-23 18:15:12 -0600 | [diff] [blame] | 577 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 578 | oc->_clk = c; |
| 579 | } |
| 580 | |
| 581 | return ret; |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * _enable_clocks - enable hwmod main clock and interface clocks |
| 586 | * @oh: struct omap_hwmod * |
| 587 | * |
| 588 | * Enables all clocks necessary for register reads and writes to succeed |
| 589 | * on the hwmod @oh. Returns 0. |
| 590 | */ |
| 591 | static int _enable_clocks(struct omap_hwmod *oh) |
| 592 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 593 | int i; |
| 594 | |
| 595 | pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); |
| 596 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 597 | if (oh->_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 598 | clk_enable(oh->_clk); |
| 599 | |
| 600 | if (oh->slaves_cnt > 0) { |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 601 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 602 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 603 | struct clk *c = os->_clk; |
| 604 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 605 | if (c && (os->flags & OCPIF_SWSUP_IDLE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 606 | clk_enable(c); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | /* The opt clocks are controlled by the device driver. */ |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * _disable_clocks - disable hwmod main clock and interface clocks |
| 617 | * @oh: struct omap_hwmod * |
| 618 | * |
| 619 | * Disables the hwmod @oh main functional and interface clocks. Returns 0. |
| 620 | */ |
| 621 | static int _disable_clocks(struct omap_hwmod *oh) |
| 622 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 623 | int i; |
| 624 | |
| 625 | pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); |
| 626 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 627 | if (oh->_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 628 | clk_disable(oh->_clk); |
| 629 | |
| 630 | if (oh->slaves_cnt > 0) { |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 631 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 632 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 633 | struct clk *c = os->_clk; |
| 634 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 635 | if (c && (os->flags & OCPIF_SWSUP_IDLE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 636 | clk_disable(c); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /* The opt clocks are controlled by the device driver. */ |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 645 | static void _enable_optional_clocks(struct omap_hwmod *oh) |
| 646 | { |
| 647 | struct omap_hwmod_opt_clk *oc; |
| 648 | int i; |
| 649 | |
| 650 | pr_debug("omap_hwmod: %s: enabling optional clocks\n", oh->name); |
| 651 | |
| 652 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 653 | if (oc->_clk) { |
| 654 | pr_debug("omap_hwmod: enable %s:%s\n", oc->role, |
| 655 | oc->_clk->name); |
| 656 | clk_enable(oc->_clk); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | static void _disable_optional_clocks(struct omap_hwmod *oh) |
| 661 | { |
| 662 | struct omap_hwmod_opt_clk *oc; |
| 663 | int i; |
| 664 | |
| 665 | pr_debug("omap_hwmod: %s: disabling optional clocks\n", oh->name); |
| 666 | |
| 667 | for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++) |
| 668 | if (oc->_clk) { |
| 669 | pr_debug("omap_hwmod: disable %s:%s\n", oc->role, |
| 670 | oc->_clk->name); |
| 671 | clk_disable(oc->_clk); |
| 672 | } |
| 673 | } |
| 674 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 675 | /** |
| 676 | * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use |
| 677 | * @oh: struct omap_hwmod * |
| 678 | * |
| 679 | * Returns the array index of the OCP slave port that the MPU |
| 680 | * addresses the device on, or -EINVAL upon error or not found. |
| 681 | */ |
Benoit Cousson | 01592df | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 682 | static int __init _find_mpu_port_index(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 683 | { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 684 | int i; |
| 685 | int found = 0; |
| 686 | |
| 687 | if (!oh || oh->slaves_cnt == 0) |
| 688 | return -EINVAL; |
| 689 | |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 690 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 691 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; |
| 692 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 693 | if (os->user & OCP_USER_MPU) { |
| 694 | found = 1; |
| 695 | break; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | if (found) |
| 700 | pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n", |
| 701 | oh->name, i); |
| 702 | else |
| 703 | pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n", |
| 704 | oh->name); |
| 705 | |
| 706 | return (found) ? i : -EINVAL; |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU |
| 711 | * @oh: struct omap_hwmod * |
| 712 | * |
| 713 | * Return the virtual address of the base of the register target of |
| 714 | * device @oh, or NULL on error. |
| 715 | */ |
Benoit Cousson | 01592df | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 716 | static void __iomem * __init _find_mpu_rt_base(struct omap_hwmod *oh, u8 index) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 717 | { |
| 718 | struct omap_hwmod_ocp_if *os; |
| 719 | struct omap_hwmod_addr_space *mem; |
| 720 | int i; |
| 721 | int found = 0; |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 722 | void __iomem *va_start; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 723 | |
| 724 | if (!oh || oh->slaves_cnt == 0) |
| 725 | return NULL; |
| 726 | |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 727 | os = oh->slaves[index]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 728 | |
| 729 | for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) { |
| 730 | if (mem->flags & ADDR_TYPE_RT) { |
| 731 | found = 1; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 736 | if (found) { |
| 737 | va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start); |
| 738 | if (!va_start) { |
| 739 | pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name); |
| 740 | return NULL; |
| 741 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 742 | pr_debug("omap_hwmod: %s: MPU register target at va %p\n", |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 743 | oh->name, va_start); |
| 744 | } else { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 745 | pr_debug("omap_hwmod: %s: no MPU register target found\n", |
| 746 | oh->name); |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 747 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 748 | |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 749 | return (found) ? va_start : NULL; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 753 | * _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] | 754 | * @oh: struct omap_hwmod * |
| 755 | * |
| 756 | * If module is marked as SWSUP_SIDLE, force the module out of slave |
| 757 | * idle; otherwise, configure it for smart-idle. If module is marked |
| 758 | * as SWSUP_MSUSPEND, force the module out of master standby; |
| 759 | * otherwise, configure it for smart-standby. No return value. |
| 760 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 761 | static void _enable_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 762 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 763 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 764 | u32 v; |
| 765 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 766 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 767 | return; |
| 768 | |
| 769 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 770 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 771 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 772 | if (sf & SYSC_HAS_SIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 773 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
| 774 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; |
| 775 | _set_slave_idlemode(oh, idlemode, &v); |
| 776 | } |
| 777 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 778 | if (sf & SYSC_HAS_MIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 779 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
| 780 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; |
| 781 | _set_master_standbymode(oh, idlemode, &v); |
| 782 | } |
| 783 | |
Paul Walmsley | a16b1f7 | 2009-12-08 16:34:17 -0700 | [diff] [blame] | 784 | /* |
| 785 | * XXX The clock framework should handle this, by |
| 786 | * calling into this code. But this must wait until the |
| 787 | * clock structures are tagged with omap_hwmod entries |
| 788 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 789 | if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) && |
| 790 | (sf & SYSC_HAS_CLOCKACTIVITY)) |
| 791 | _set_clockactivity(oh, oh->class->sysc->clockact, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 792 | |
Rajendra Nayak | 9980ce5 | 2010-09-21 19:58:30 +0530 | [diff] [blame] | 793 | /* If slave is in SMARTIDLE, also enable wakeup */ |
| 794 | if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE)) |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 795 | _enable_wakeup(oh, &v); |
| 796 | |
| 797 | _write_sysconfig(v, oh); |
Hema HK | 78f26e8 | 2010-09-24 10:23:19 -0600 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Set the autoidle bit only after setting the smartidle bit |
| 801 | * Setting this will not have any impact on the other modules. |
| 802 | */ |
| 803 | if (sf & SYSC_HAS_AUTOIDLE) { |
| 804 | idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ? |
| 805 | 0 : 1; |
| 806 | _set_module_autoidle(oh, idlemode, &v); |
| 807 | _write_sysconfig(v, oh); |
| 808 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 812 | * _idle_sysc - try to put a module into idle via OCP_SYSCONFIG |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 813 | * @oh: struct omap_hwmod * |
| 814 | * |
| 815 | * If module is marked as SWSUP_SIDLE, force the module into slave |
| 816 | * idle; otherwise, configure it for smart-idle. If module is marked |
| 817 | * as SWSUP_MSUSPEND, force the module into master standby; otherwise, |
| 818 | * configure it for smart-standby. No return value. |
| 819 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 820 | static void _idle_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 821 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 822 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 823 | u32 v; |
| 824 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 825 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 826 | return; |
| 827 | |
| 828 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 829 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 830 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 831 | if (sf & SYSC_HAS_SIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 832 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
| 833 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; |
| 834 | _set_slave_idlemode(oh, idlemode, &v); |
| 835 | } |
| 836 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 837 | if (sf & SYSC_HAS_MIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 838 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
| 839 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; |
| 840 | _set_master_standbymode(oh, idlemode, &v); |
| 841 | } |
| 842 | |
Benoit Cousson | 86009eb | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 843 | /* If slave is in SMARTIDLE, also enable wakeup */ |
| 844 | if ((sf & SYSC_HAS_SIDLEMODE) && !(oh->flags & HWMOD_SWSUP_SIDLE)) |
| 845 | _enable_wakeup(oh, &v); |
| 846 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 847 | _write_sysconfig(v, oh); |
| 848 | } |
| 849 | |
| 850 | /** |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 851 | * _shutdown_sysc - force a module into idle via OCP_SYSCONFIG |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 852 | * @oh: struct omap_hwmod * |
| 853 | * |
| 854 | * Force the module into slave idle and master suspend. No return |
| 855 | * value. |
| 856 | */ |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 857 | static void _shutdown_sysc(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 858 | { |
| 859 | u32 v; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 860 | u8 sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 861 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 862 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 863 | return; |
| 864 | |
| 865 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 866 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 867 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 868 | if (sf & SYSC_HAS_SIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 869 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 870 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 871 | if (sf & SYSC_HAS_MIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 872 | _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 873 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 874 | if (sf & SYSC_HAS_AUTOIDLE) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 875 | _set_module_autoidle(oh, 1, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 876 | |
| 877 | _write_sysconfig(v, oh); |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * _lookup - find an omap_hwmod by name |
| 882 | * @name: find an omap_hwmod by name |
| 883 | * |
| 884 | * 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] | 885 | */ |
| 886 | static struct omap_hwmod *_lookup(const char *name) |
| 887 | { |
| 888 | struct omap_hwmod *oh, *temp_oh; |
| 889 | |
| 890 | oh = NULL; |
| 891 | |
| 892 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 893 | if (!strcmp(name, temp_oh->name)) { |
| 894 | oh = temp_oh; |
| 895 | break; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | return oh; |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * _init_clocks - clk_get() all clocks associated with this hwmod |
| 904 | * @oh: struct omap_hwmod * |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 905 | * @data: not used; pass NULL |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 906 | * |
| 907 | * Called by omap_hwmod_late_init() (after omap2_clk_init()). |
Kevin Hilman | 12b1fdb | 2010-09-21 10:34:09 -0600 | [diff] [blame] | 908 | * Resolves all clock names embedded in the hwmod. Returns -EINVAL if |
| 909 | * the omap_hwmod has not yet been registered or if the clocks have |
| 910 | * already been initialized, 0 on success, or a non-zero error on |
| 911 | * failure. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 912 | */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 913 | static int _init_clocks(struct omap_hwmod *oh, void *data) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 914 | { |
| 915 | int ret = 0; |
| 916 | |
| 917 | if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED)) |
| 918 | return -EINVAL; |
| 919 | |
| 920 | pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name); |
| 921 | |
| 922 | ret |= _init_main_clk(oh); |
| 923 | ret |= _init_interface_clks(oh); |
| 924 | ret |= _init_opt_clks(oh); |
| 925 | |
Benoit Cousson | f5c1f84 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 926 | if (!ret) |
| 927 | oh->_state = _HWMOD_STATE_CLKS_INITED; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 928 | |
Benoit Cousson | f5c1f84 | 2010-05-20 12:31:10 -0600 | [diff] [blame] | 929 | return 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | /** |
| 933 | * _wait_target_ready - wait for a module to leave slave idle |
| 934 | * @oh: struct omap_hwmod * |
| 935 | * |
| 936 | * Wait for a module @oh to leave slave idle. Returns 0 if the module |
| 937 | * does not have an IDLEST bit or if the module successfully leaves |
| 938 | * slave idle; otherwise, pass along the return value of the |
| 939 | * appropriate *_cm_wait_module_ready() function. |
| 940 | */ |
| 941 | static int _wait_target_ready(struct omap_hwmod *oh) |
| 942 | { |
| 943 | struct omap_hwmod_ocp_if *os; |
| 944 | int ret; |
| 945 | |
| 946 | if (!oh) |
| 947 | return -EINVAL; |
| 948 | |
| 949 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 950 | return 0; |
| 951 | |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 952 | os = oh->slaves[oh->_mpu_port_index]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 953 | |
Benoit Cousson | 33f7ec8 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 954 | if (oh->flags & HWMOD_NO_IDLEST) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 955 | return 0; |
| 956 | |
| 957 | /* XXX check module SIDLEMODE */ |
| 958 | |
| 959 | /* XXX check clock enable states */ |
| 960 | |
| 961 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 962 | ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs, |
| 963 | oh->prcm.omap2.idlest_reg_id, |
| 964 | oh->prcm.omap2.idlest_idle_bit); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 965 | } else if (cpu_is_omap44xx()) { |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 966 | ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 967 | } else { |
| 968 | BUG(); |
| 969 | }; |
| 970 | |
| 971 | return ret; |
| 972 | } |
| 973 | |
| 974 | /** |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 975 | * _lookup_hardreset - return the register bit shift for this hwmod/reset line |
| 976 | * @oh: struct omap_hwmod * |
| 977 | * @name: name of the reset line in the context of this hwmod |
| 978 | * |
| 979 | * Return the bit position of the reset line that match the |
| 980 | * input name. Return -ENOENT if not found. |
| 981 | */ |
| 982 | static u8 _lookup_hardreset(struct omap_hwmod *oh, const char *name) |
| 983 | { |
| 984 | int i; |
| 985 | |
| 986 | for (i = 0; i < oh->rst_lines_cnt; i++) { |
| 987 | const char *rst_line = oh->rst_lines[i].name; |
| 988 | if (!strcmp(rst_line, name)) { |
| 989 | u8 shift = oh->rst_lines[i].rst_shift; |
| 990 | pr_debug("omap_hwmod: %s: _lookup_hardreset: %s: %d\n", |
| 991 | oh->name, rst_line, shift); |
| 992 | |
| 993 | return shift; |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | return -ENOENT; |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * _assert_hardreset - assert the HW reset line of submodules |
| 1002 | * contained in the hwmod module. |
| 1003 | * @oh: struct omap_hwmod * |
| 1004 | * @name: name of the reset line to lookup and assert |
| 1005 | * |
| 1006 | * Some IP like dsp, ipu or iva contain processor that require |
| 1007 | * an HW reset line to be assert / deassert in order to enable fully |
| 1008 | * the IP. |
| 1009 | */ |
| 1010 | static int _assert_hardreset(struct omap_hwmod *oh, const char *name) |
| 1011 | { |
| 1012 | u8 shift; |
| 1013 | |
| 1014 | if (!oh) |
| 1015 | return -EINVAL; |
| 1016 | |
| 1017 | shift = _lookup_hardreset(oh, name); |
| 1018 | if (IS_ERR_VALUE(shift)) |
| 1019 | return shift; |
| 1020 | |
| 1021 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 1022 | return omap2_prm_assert_hardreset(oh->prcm.omap2.module_offs, |
| 1023 | shift); |
| 1024 | else if (cpu_is_omap44xx()) |
| 1025 | return omap4_prm_assert_hardreset(oh->prcm.omap4.rstctrl_reg, |
| 1026 | shift); |
| 1027 | else |
| 1028 | return -EINVAL; |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * _deassert_hardreset - deassert the HW reset line of submodules contained |
| 1033 | * in the hwmod module. |
| 1034 | * @oh: struct omap_hwmod * |
| 1035 | * @name: name of the reset line to look up and deassert |
| 1036 | * |
| 1037 | * Some IP like dsp, ipu or iva contain processor that require |
| 1038 | * an HW reset line to be assert / deassert in order to enable fully |
| 1039 | * the IP. |
| 1040 | */ |
| 1041 | static int _deassert_hardreset(struct omap_hwmod *oh, const char *name) |
| 1042 | { |
| 1043 | u8 shift; |
| 1044 | int r; |
| 1045 | |
| 1046 | if (!oh) |
| 1047 | return -EINVAL; |
| 1048 | |
| 1049 | shift = _lookup_hardreset(oh, name); |
| 1050 | if (IS_ERR_VALUE(shift)) |
| 1051 | return shift; |
| 1052 | |
| 1053 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 1054 | r = omap2_prm_deassert_hardreset(oh->prcm.omap2.module_offs, |
| 1055 | shift); |
| 1056 | else if (cpu_is_omap44xx()) |
| 1057 | r = omap4_prm_deassert_hardreset(oh->prcm.omap4.rstctrl_reg, |
| 1058 | shift); |
| 1059 | else |
| 1060 | return -EINVAL; |
| 1061 | |
| 1062 | if (r == -EBUSY) |
| 1063 | pr_warning("omap_hwmod: %s: failed to hardreset\n", oh->name); |
| 1064 | |
| 1065 | return r; |
| 1066 | } |
| 1067 | |
| 1068 | /** |
| 1069 | * _read_hardreset - read the HW reset line state of submodules |
| 1070 | * contained in the hwmod module |
| 1071 | * @oh: struct omap_hwmod * |
| 1072 | * @name: name of the reset line to look up and read |
| 1073 | * |
| 1074 | * Return the state of the reset line. |
| 1075 | */ |
| 1076 | static int _read_hardreset(struct omap_hwmod *oh, const char *name) |
| 1077 | { |
| 1078 | u8 shift; |
| 1079 | |
| 1080 | if (!oh) |
| 1081 | return -EINVAL; |
| 1082 | |
| 1083 | shift = _lookup_hardreset(oh, name); |
| 1084 | if (IS_ERR_VALUE(shift)) |
| 1085 | return shift; |
| 1086 | |
| 1087 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 1088 | return omap2_prm_is_hardreset_asserted(oh->prcm.omap2.module_offs, |
| 1089 | shift); |
| 1090 | } else if (cpu_is_omap44xx()) { |
| 1091 | return omap4_prm_is_hardreset_asserted(oh->prcm.omap4.rstctrl_reg, |
| 1092 | shift); |
| 1093 | } else { |
| 1094 | return -EINVAL; |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | /** |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1099 | * _ocp_softreset - reset an omap_hwmod via the OCP_SYSCONFIG bit |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1100 | * @oh: struct omap_hwmod * |
| 1101 | * |
| 1102 | * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be |
Kevin Hilman | 12b1fdb | 2010-09-21 10:34:09 -0600 | [diff] [blame] | 1103 | * enabled for this to work. Returns -EINVAL if the hwmod cannot be |
| 1104 | * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if |
| 1105 | * the module did not reset in time, or 0 upon success. |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1106 | * |
| 1107 | * 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] | 1108 | * Starting in OMAP4, some IPs do not have SYSSTATUS registers and instead |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1109 | * use the SYSCONFIG softreset bit to provide the status. |
| 1110 | * |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1111 | * Note that some IP like McBSP do have reset control but don't have |
| 1112 | * reset status. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1113 | */ |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1114 | static int _ocp_softreset(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1115 | { |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1116 | u32 v; |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 1117 | int c = 0; |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1118 | int ret = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1119 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1120 | if (!oh->class->sysc || |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1121 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1122 | return -EINVAL; |
| 1123 | |
| 1124 | /* clocks must be on for this operation */ |
| 1125 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1126 | pr_warning("omap_hwmod: %s: reset can only be entered from " |
| 1127 | "enabled state\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1128 | return -EINVAL; |
| 1129 | } |
| 1130 | |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1131 | /* For some modules, all optionnal clocks need to be enabled as well */ |
| 1132 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1133 | _enable_optional_clocks(oh); |
| 1134 | |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1135 | pr_debug("omap_hwmod: %s: resetting via OCP SOFTRESET\n", oh->name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1136 | |
| 1137 | v = oh->_sysc_cache; |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1138 | ret = _set_softreset(oh, &v); |
| 1139 | if (ret) |
| 1140 | goto dis_opt_clks; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1141 | _write_sysconfig(v, oh); |
| 1142 | |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1143 | if (oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS) |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1144 | omap_test_timeout((omap_hwmod_read(oh, |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1145 | oh->class->sysc->syss_offs) |
| 1146 | & SYSS_RESETDONE_MASK), |
| 1147 | MAX_MODULE_SOFTRESET_WAIT, c); |
| 1148 | else if (oh->class->sysc->sysc_flags & SYSC_HAS_RESET_STATUS) |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1149 | omap_test_timeout(!(omap_hwmod_read(oh, |
Benoit Cousson | 2cb0681 | 2010-09-21 18:57:59 +0200 | [diff] [blame] | 1150 | oh->class->sysc->sysc_offs) |
| 1151 | & SYSC_TYPE2_SOFTRESET_MASK), |
| 1152 | MAX_MODULE_SOFTRESET_WAIT, c); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1153 | |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1154 | if (c == MAX_MODULE_SOFTRESET_WAIT) |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1155 | pr_warning("omap_hwmod: %s: softreset failed (waited %d usec)\n", |
| 1156 | oh->name, MAX_MODULE_SOFTRESET_WAIT); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1157 | else |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1158 | 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] | 1159 | |
| 1160 | /* |
| 1161 | * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from |
| 1162 | * _wait_target_ready() or _reset() |
| 1163 | */ |
| 1164 | |
Benoit Cousson | 96835af | 2010-09-21 18:57:58 +0200 | [diff] [blame] | 1165 | ret = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0; |
| 1166 | |
| 1167 | dis_opt_clks: |
| 1168 | if (oh->flags & HWMOD_CONTROL_OPT_CLKS_IN_RESET) |
| 1169 | _disable_optional_clocks(oh); |
| 1170 | |
| 1171 | return ret; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
Paul Walmsley | bd36179 | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1175 | * _reset - reset an omap_hwmod |
| 1176 | * @oh: struct omap_hwmod * |
| 1177 | * |
| 1178 | * Resets an omap_hwmod @oh. The default software reset mechanism for |
| 1179 | * most OMAP IP blocks is triggered via the OCP_SYSCONFIG.SOFTRESET |
| 1180 | * bit. However, some hwmods cannot be reset via this method: some |
| 1181 | * are not targets and therefore have no OCP header registers to |
| 1182 | * access; others (like the IVA) have idiosyncratic reset sequences. |
| 1183 | * So for these relatively rare cases, custom reset code can be |
| 1184 | * supplied in the struct omap_hwmod_class .reset function pointer. |
| 1185 | * Passes along the return value from either _reset() or the custom |
| 1186 | * reset function - these must return -EINVAL if the hwmod cannot be |
| 1187 | * reset this way or if the hwmod is in the wrong state, -ETIMEDOUT if |
| 1188 | * the module did not reset in time, or 0 upon success. |
| 1189 | */ |
| 1190 | static int _reset(struct omap_hwmod *oh) |
| 1191 | { |
| 1192 | int ret; |
| 1193 | |
| 1194 | pr_debug("omap_hwmod: %s: resetting\n", oh->name); |
| 1195 | |
| 1196 | ret = (oh->class->reset) ? oh->class->reset(oh) : _ocp_softreset(oh); |
| 1197 | |
| 1198 | return ret; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1202 | * _enable - enable an omap_hwmod |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1203 | * @oh: struct omap_hwmod * |
| 1204 | * |
| 1205 | * 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] | 1206 | * register target. Returns -EINVAL if the hwmod is in the wrong |
| 1207 | * state or passes along the return value of _wait_target_ready(). |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1208 | */ |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1209 | static int _enable(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1210 | { |
| 1211 | int r; |
| 1212 | |
| 1213 | if (oh->_state != _HWMOD_STATE_INITIALIZED && |
| 1214 | oh->_state != _HWMOD_STATE_IDLE && |
| 1215 | oh->_state != _HWMOD_STATE_DISABLED) { |
| 1216 | WARN(1, "omap_hwmod: %s: enabled state can only be entered " |
| 1217 | "from initialized, idle, or disabled state\n", oh->name); |
| 1218 | return -EINVAL; |
| 1219 | } |
| 1220 | |
| 1221 | pr_debug("omap_hwmod: %s: enabling\n", oh->name); |
| 1222 | |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1223 | /* |
| 1224 | * If an IP contains only one HW reset line, then de-assert it in order |
| 1225 | * to allow to enable the clocks. Otherwise the PRCM will return |
| 1226 | * Intransition status, and the init will failed. |
| 1227 | */ |
| 1228 | if ((oh->_state == _HWMOD_STATE_INITIALIZED || |
| 1229 | oh->_state == _HWMOD_STATE_DISABLED) && oh->rst_lines_cnt == 1) |
| 1230 | _deassert_hardreset(oh, oh->rst_lines[0].name); |
| 1231 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1232 | /* XXX mux balls */ |
| 1233 | |
| 1234 | _add_initiator_dep(oh, mpu_oh); |
| 1235 | _enable_clocks(oh); |
| 1236 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1237 | r = _wait_target_ready(oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1238 | if (!r) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1239 | oh->_state = _HWMOD_STATE_ENABLED; |
| 1240 | |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1241 | /* Access the sysconfig only if the target is ready */ |
| 1242 | if (oh->class->sysc) { |
| 1243 | if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED)) |
| 1244 | _update_sysc_cache(oh); |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1245 | _enable_sysc(oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1246 | } |
| 1247 | } else { |
Rajendra Nayak | f2dd7e0 | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 1248 | _disable_clocks(oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1249 | pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n", |
| 1250 | oh->name, r); |
| 1251 | } |
| 1252 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1253 | return r; |
| 1254 | } |
| 1255 | |
| 1256 | /** |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1257 | * _idle - idle an omap_hwmod |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1258 | * @oh: struct omap_hwmod * |
| 1259 | * |
| 1260 | * 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] | 1261 | * no further work. Returns -EINVAL if the hwmod is in the wrong |
| 1262 | * state or returns 0. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1263 | */ |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1264 | static int _idle(struct omap_hwmod *oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1265 | { |
| 1266 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
| 1267 | WARN(1, "omap_hwmod: %s: idle state can only be entered from " |
| 1268 | "enabled state\n", oh->name); |
| 1269 | return -EINVAL; |
| 1270 | } |
| 1271 | |
| 1272 | pr_debug("omap_hwmod: %s: idling\n", oh->name); |
| 1273 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1274 | if (oh->class->sysc) |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1275 | _idle_sysc(oh); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1276 | _del_initiator_dep(oh, mpu_oh); |
| 1277 | _disable_clocks(oh); |
| 1278 | |
| 1279 | oh->_state = _HWMOD_STATE_IDLE; |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * _shutdown - shutdown an omap_hwmod |
| 1286 | * @oh: struct omap_hwmod * |
| 1287 | * |
| 1288 | * Shut down an omap_hwmod @oh. This should be called when the driver |
| 1289 | * used for the hwmod is removed or unloaded or if the driver is not |
| 1290 | * used by the system. Returns -EINVAL if the hwmod is in the wrong |
| 1291 | * state or returns 0. |
| 1292 | */ |
| 1293 | static int _shutdown(struct omap_hwmod *oh) |
| 1294 | { |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 1295 | int ret; |
| 1296 | u8 prev_state; |
| 1297 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1298 | if (oh->_state != _HWMOD_STATE_IDLE && |
| 1299 | oh->_state != _HWMOD_STATE_ENABLED) { |
| 1300 | WARN(1, "omap_hwmod: %s: disabled state can only be entered " |
| 1301 | "from idle, or enabled state\n", oh->name); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | pr_debug("omap_hwmod: %s: disabling\n", oh->name); |
| 1306 | |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 1307 | if (oh->class->pre_shutdown) { |
| 1308 | prev_state = oh->_state; |
| 1309 | if (oh->_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1310 | _enable(oh); |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 1311 | ret = oh->class->pre_shutdown(oh); |
| 1312 | if (ret) { |
| 1313 | if (prev_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1314 | _idle(oh); |
Paul Walmsley | e4dc8f5 | 2010-12-14 12:42:34 -0700 | [diff] [blame] | 1315 | return ret; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1319 | if (oh->class->sysc) |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1320 | _shutdown_sysc(oh); |
Benoit Cousson | 3827f94 | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 1321 | |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1322 | /* |
| 1323 | * If an IP contains only one HW reset line, then assert it |
| 1324 | * before disabling the clocks and shutting down the IP. |
| 1325 | */ |
| 1326 | if (oh->rst_lines_cnt == 1) |
| 1327 | _assert_hardreset(oh, oh->rst_lines[0].name); |
| 1328 | |
Benoit Cousson | 3827f94 | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 1329 | /* clocks and deps are already disabled in idle */ |
| 1330 | if (oh->_state == _HWMOD_STATE_ENABLED) { |
| 1331 | _del_initiator_dep(oh, mpu_oh); |
| 1332 | /* XXX what about the other system initiators here? dma, dsp */ |
| 1333 | _disable_clocks(oh); |
| 1334 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1335 | /* XXX Should this code also force-disable the optional clocks? */ |
| 1336 | |
| 1337 | /* XXX mux any associated balls to safe mode */ |
| 1338 | |
| 1339 | oh->_state = _HWMOD_STATE_DISABLED; |
| 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1345 | * _setup - do initial configuration of omap_hwmod |
| 1346 | * @oh: struct omap_hwmod * |
| 1347 | * |
| 1348 | * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1349 | * OCP_SYSCONFIG register. Returns -EINVAL if the hwmod is in the |
| 1350 | * wrong state or returns 0. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1351 | */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1352 | static int _setup(struct omap_hwmod *oh, void *data) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1353 | { |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1354 | int i, r; |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1355 | u8 postsetup_state; |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1356 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1357 | /* Set iclk autoidle mode */ |
| 1358 | if (oh->slaves_cnt > 0) { |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 1359 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 1360 | struct omap_hwmod_ocp_if *os = oh->slaves[i]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1361 | struct clk *c = os->_clk; |
| 1362 | |
Benoit Cousson | 4d3ae5a | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 1363 | if (!c) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1364 | continue; |
| 1365 | |
| 1366 | if (os->flags & OCPIF_SWSUP_IDLE) { |
| 1367 | /* XXX omap_iclk_deny_idle(c); */ |
| 1368 | } else { |
| 1369 | /* XXX omap_iclk_allow_idle(c); */ |
| 1370 | clk_enable(c); |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | oh->_state = _HWMOD_STATE_INITIALIZED; |
| 1376 | |
Benoît Cousson | 5365efb | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1377 | /* |
| 1378 | * In the case of hwmod with hardreset that should not be |
| 1379 | * de-assert at boot time, we have to keep the module |
| 1380 | * initialized, because we cannot enable it properly with the |
| 1381 | * reset asserted. Exit without warning because that behavior is |
| 1382 | * expected. |
| 1383 | */ |
| 1384 | if ((oh->flags & HWMOD_INIT_NO_RESET) && oh->rst_lines_cnt == 1) |
| 1385 | return 0; |
| 1386 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1387 | r = _enable(oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 1388 | if (r) { |
| 1389 | pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n", |
| 1390 | oh->name, oh->_state); |
| 1391 | return 0; |
| 1392 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1393 | |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1394 | if (!(oh->flags & HWMOD_INIT_NO_RESET)) { |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1395 | _reset(oh); |
| 1396 | |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1397 | /* |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1398 | * OCP_SYSCONFIG bits need to be reprogrammed after a softreset. |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1399 | * The _enable() function should be split to |
Benoit Cousson | 76e5589 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 1400 | * avoid the rewrite of the OCP_SYSCONFIG register. |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1401 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1402 | if (oh->class->sysc) { |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1403 | _update_sysc_cache(oh); |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1404 | _enable_sysc(oh); |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1407 | |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1408 | postsetup_state = oh->_postsetup_state; |
| 1409 | if (postsetup_state == _HWMOD_STATE_UNKNOWN) |
| 1410 | postsetup_state = _HWMOD_STATE_ENABLED; |
| 1411 | |
| 1412 | /* |
| 1413 | * XXX HWMOD_INIT_NO_IDLE does not belong in hwmod data - |
| 1414 | * it should be set by the core code as a runtime flag during startup |
| 1415 | */ |
| 1416 | if ((oh->flags & HWMOD_INIT_NO_IDLE) && |
| 1417 | (postsetup_state == _HWMOD_STATE_IDLE)) |
| 1418 | postsetup_state = _HWMOD_STATE_ENABLED; |
| 1419 | |
| 1420 | if (postsetup_state == _HWMOD_STATE_IDLE) |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1421 | _idle(oh); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1422 | else if (postsetup_state == _HWMOD_STATE_DISABLED) |
| 1423 | _shutdown(oh); |
| 1424 | else if (postsetup_state != _HWMOD_STATE_ENABLED) |
| 1425 | WARN(1, "hwmod: %s: unknown postsetup state %d! defaulting to enabled\n", |
| 1426 | oh->name, postsetup_state); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1427 | |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1431 | /** |
| 1432 | * _register - register a struct omap_hwmod |
| 1433 | * @oh: struct omap_hwmod * |
| 1434 | * |
| 1435 | * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod |
| 1436 | * already has been registered by the same name; -EINVAL if the |
| 1437 | * omap_hwmod is in the wrong state, if @oh is NULL, if the |
| 1438 | * omap_hwmod's class field is NULL; if the omap_hwmod is missing a |
| 1439 | * name, or if the omap_hwmod's class is missing a name; or 0 upon |
| 1440 | * success. |
| 1441 | * |
| 1442 | * XXX The data should be copied into bootmem, so the original data |
| 1443 | * should be marked __initdata and freed after init. This would allow |
| 1444 | * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note |
| 1445 | * that the copy process would be relatively complex due to the large number |
| 1446 | * of substructures. |
| 1447 | */ |
Benoit Cousson | 01592df | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 1448 | static int __init _register(struct omap_hwmod *oh) |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1449 | { |
| 1450 | int ret, ms_id; |
| 1451 | |
| 1452 | if (!oh || !oh->name || !oh->class || !oh->class->name || |
| 1453 | (oh->_state != _HWMOD_STATE_UNKNOWN)) |
| 1454 | return -EINVAL; |
| 1455 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1456 | pr_debug("omap_hwmod: %s: registering\n", oh->name); |
| 1457 | |
Benoit Cousson | ce35b24 | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 1458 | if (_lookup(oh->name)) |
| 1459 | return -EEXIST; |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1460 | |
| 1461 | ms_id = _find_mpu_port_index(oh); |
| 1462 | if (!IS_ERR_VALUE(ms_id)) { |
| 1463 | oh->_mpu_port_index = ms_id; |
| 1464 | oh->_mpu_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index); |
| 1465 | } else { |
| 1466 | oh->_int_flags |= _HWMOD_NO_MPU_PORT; |
| 1467 | } |
| 1468 | |
| 1469 | list_add_tail(&oh->node, &omap_hwmod_list); |
| 1470 | |
| 1471 | spin_lock_init(&oh->_lock); |
| 1472 | |
| 1473 | oh->_state = _HWMOD_STATE_REGISTERED; |
| 1474 | |
| 1475 | ret = 0; |
| 1476 | |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1477 | return ret; |
| 1478 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1479 | |
| 1480 | |
| 1481 | /* Public functions */ |
| 1482 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1483 | u32 omap_hwmod_read(struct omap_hwmod *oh, u16 reg_offs) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1484 | { |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1485 | if (oh->flags & HWMOD_16BIT_REG) |
| 1486 | return __raw_readw(oh->_mpu_rt_va + reg_offs); |
| 1487 | else |
| 1488 | return __raw_readl(oh->_mpu_rt_va + reg_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1489 | } |
| 1490 | |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1491 | 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] | 1492 | { |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1493 | if (oh->flags & HWMOD_16BIT_REG) |
| 1494 | __raw_writew(v, oh->_mpu_rt_va + reg_offs); |
| 1495 | else |
| 1496 | __raw_writel(v, oh->_mpu_rt_va + reg_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1497 | } |
| 1498 | |
Paul Walmsley | 887adea | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 1499 | /** |
| 1500 | * omap_hwmod_set_slave_idlemode - set the hwmod's OCP slave idlemode |
| 1501 | * @oh: struct omap_hwmod * |
| 1502 | * @idlemode: SIDLEMODE field bits (shifted to bit 0) |
| 1503 | * |
| 1504 | * Sets the IP block's OCP slave idlemode in hardware, and updates our |
| 1505 | * local copy. Intended to be used by drivers that have some erratum |
| 1506 | * that requires direct manipulation of the SIDLEMODE bits. Returns |
| 1507 | * -EINVAL if @oh is null, or passes along the return value from |
| 1508 | * _set_slave_idlemode(). |
| 1509 | * |
| 1510 | * XXX Does this function have any current users? If not, we should |
| 1511 | * remove it; it is better to let the rest of the hwmod code handle this. |
| 1512 | * Any users of this function should be scrutinized carefully. |
| 1513 | */ |
Kevin Hilman | 46273e6 | 2010-01-26 20:13:03 -0700 | [diff] [blame] | 1514 | int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode) |
| 1515 | { |
| 1516 | u32 v; |
| 1517 | int retval = 0; |
| 1518 | |
| 1519 | if (!oh) |
| 1520 | return -EINVAL; |
| 1521 | |
| 1522 | v = oh->_sysc_cache; |
| 1523 | |
| 1524 | retval = _set_slave_idlemode(oh, idlemode, &v); |
| 1525 | if (!retval) |
| 1526 | _write_sysconfig(v, oh); |
| 1527 | |
| 1528 | return retval; |
| 1529 | } |
| 1530 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1531 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1532 | * omap_hwmod_lookup - look up a registered omap_hwmod by name |
| 1533 | * @name: name of the omap_hwmod to look up |
| 1534 | * |
| 1535 | * Given a @name of an omap_hwmod, return a pointer to the registered |
| 1536 | * struct omap_hwmod *, or NULL upon error. |
| 1537 | */ |
| 1538 | struct omap_hwmod *omap_hwmod_lookup(const char *name) |
| 1539 | { |
| 1540 | struct omap_hwmod *oh; |
| 1541 | |
| 1542 | if (!name) |
| 1543 | return NULL; |
| 1544 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1545 | oh = _lookup(name); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1546 | |
| 1547 | return oh; |
| 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * omap_hwmod_for_each - call function for each registered omap_hwmod |
| 1552 | * @fn: pointer to a callback function |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1553 | * @data: void * data to pass to callback function |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1554 | * |
| 1555 | * Call @fn for each registered omap_hwmod, passing @data to each |
| 1556 | * function. @fn must return 0 for success or any other value for |
| 1557 | * failure. If @fn returns non-zero, the iteration across omap_hwmods |
| 1558 | * will stop and the non-zero return value will be passed to the |
| 1559 | * caller of omap_hwmod_for_each(). @fn is called with |
| 1560 | * omap_hwmod_for_each() held. |
| 1561 | */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1562 | int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh, void *data), |
| 1563 | void *data) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1564 | { |
| 1565 | struct omap_hwmod *temp_oh; |
| 1566 | int ret; |
| 1567 | |
| 1568 | if (!fn) |
| 1569 | return -EINVAL; |
| 1570 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1571 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1572 | ret = (*fn)(temp_oh, data); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1573 | if (ret) |
| 1574 | break; |
| 1575 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1576 | |
| 1577 | return ret; |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | /** |
| 1582 | * omap_hwmod_init - init omap_hwmod code and register hwmods |
| 1583 | * @ohs: pointer to an array of omap_hwmods to register |
| 1584 | * |
| 1585 | * Intended to be called early in boot before the clock framework is |
| 1586 | * initialized. If @ohs is not null, will register all omap_hwmods |
| 1587 | * listed in @ohs that are valid for this chip. Returns -EINVAL if |
| 1588 | * omap_hwmod_init() has already been called or 0 otherwise. |
| 1589 | */ |
Benoit Cousson | 01592df | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 1590 | int __init omap_hwmod_init(struct omap_hwmod **ohs) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1591 | { |
| 1592 | struct omap_hwmod *oh; |
| 1593 | int r; |
| 1594 | |
| 1595 | if (inited) |
| 1596 | return -EINVAL; |
| 1597 | |
| 1598 | inited = 1; |
| 1599 | |
| 1600 | if (!ohs) |
| 1601 | return 0; |
| 1602 | |
| 1603 | oh = *ohs; |
| 1604 | while (oh) { |
| 1605 | if (omap_chip_is(oh->omap_chip)) { |
Benoit Cousson | 0102b62 | 2010-12-21 21:31:27 -0700 | [diff] [blame] | 1606 | r = _register(oh); |
| 1607 | WARN(r, "omap_hwmod: %s: _register returned " |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1608 | "%d\n", oh->name, r); |
| 1609 | } |
| 1610 | oh = *++ohs; |
| 1611 | } |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * omap_hwmod_late_init - do some post-clock framework initialization |
| 1618 | * |
| 1619 | * Must be called after omap2_clk_init(). Resolves the struct clk names |
| 1620 | * to struct clk pointers for each registered omap_hwmod. Also calls |
| 1621 | * _setup() on each hwmod. Returns 0. |
| 1622 | */ |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1623 | int omap_hwmod_late_init(void) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1624 | { |
| 1625 | int r; |
| 1626 | |
| 1627 | /* XXX check return value */ |
Paul Walmsley | 97d6016 | 2010-07-26 16:34:30 -0600 | [diff] [blame] | 1628 | r = omap_hwmod_for_each(_init_clocks, NULL); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1629 | WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n"); |
| 1630 | |
| 1631 | mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME); |
| 1632 | WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n", |
| 1633 | MPU_INITIATOR_NAME); |
| 1634 | |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1635 | omap_hwmod_for_each(_setup, NULL); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1636 | |
| 1637 | return 0; |
| 1638 | } |
| 1639 | |
| 1640 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1641 | * omap_hwmod_enable - enable an omap_hwmod |
| 1642 | * @oh: struct omap_hwmod * |
| 1643 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1644 | * 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] | 1645 | * Returns -EINVAL on error or passes along the return value from _enable(). |
| 1646 | */ |
| 1647 | int omap_hwmod_enable(struct omap_hwmod *oh) |
| 1648 | { |
| 1649 | int r; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1650 | unsigned long flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1651 | |
| 1652 | if (!oh) |
| 1653 | return -EINVAL; |
| 1654 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1655 | spin_lock_irqsave(&oh->_lock, flags); |
| 1656 | r = _enable(oh); |
| 1657 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1658 | |
| 1659 | return r; |
| 1660 | } |
| 1661 | |
| 1662 | /** |
| 1663 | * omap_hwmod_idle - idle an omap_hwmod |
| 1664 | * @oh: struct omap_hwmod * |
| 1665 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1666 | * 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] | 1667 | * Returns -EINVAL on error or passes along the return value from _idle(). |
| 1668 | */ |
| 1669 | int omap_hwmod_idle(struct omap_hwmod *oh) |
| 1670 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1671 | unsigned long flags; |
| 1672 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1673 | if (!oh) |
| 1674 | return -EINVAL; |
| 1675 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1676 | spin_lock_irqsave(&oh->_lock, flags); |
| 1677 | _idle(oh); |
| 1678 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1679 | |
| 1680 | return 0; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * omap_hwmod_shutdown - shutdown an omap_hwmod |
| 1685 | * @oh: struct omap_hwmod * |
| 1686 | * |
Paul Walmsley | 74ff3a6 | 2010-09-21 15:02:23 -0600 | [diff] [blame] | 1687 | * Shutdown an omap_hwmod @oh. Intended to be called by |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1688 | * omap_device_shutdown(). Returns -EINVAL on error or passes along |
| 1689 | * the return value from _shutdown(). |
| 1690 | */ |
| 1691 | int omap_hwmod_shutdown(struct omap_hwmod *oh) |
| 1692 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1693 | unsigned long flags; |
| 1694 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1695 | if (!oh) |
| 1696 | return -EINVAL; |
| 1697 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1698 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1699 | _shutdown(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1700 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1701 | |
| 1702 | return 0; |
| 1703 | } |
| 1704 | |
| 1705 | /** |
| 1706 | * omap_hwmod_enable_clocks - enable main_clk, all interface clocks |
| 1707 | * @oh: struct omap_hwmod *oh |
| 1708 | * |
| 1709 | * Intended to be called by the omap_device code. |
| 1710 | */ |
| 1711 | int omap_hwmod_enable_clocks(struct omap_hwmod *oh) |
| 1712 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1713 | unsigned long flags; |
| 1714 | |
| 1715 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1716 | _enable_clocks(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1717 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1718 | |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * omap_hwmod_disable_clocks - disable main_clk, all interface clocks |
| 1724 | * @oh: struct omap_hwmod *oh |
| 1725 | * |
| 1726 | * Intended to be called by the omap_device code. |
| 1727 | */ |
| 1728 | int omap_hwmod_disable_clocks(struct omap_hwmod *oh) |
| 1729 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1730 | unsigned long flags; |
| 1731 | |
| 1732 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1733 | _disable_clocks(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1734 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1735 | |
| 1736 | return 0; |
| 1737 | } |
| 1738 | |
| 1739 | /** |
| 1740 | * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete |
| 1741 | * @oh: struct omap_hwmod *oh |
| 1742 | * |
| 1743 | * Intended to be called by drivers and core code when all posted |
| 1744 | * writes to a device must complete before continuing further |
| 1745 | * execution (for example, after clearing some device IRQSTATUS |
| 1746 | * register bits) |
| 1747 | * |
| 1748 | * XXX what about targets with multiple OCP threads? |
| 1749 | */ |
| 1750 | void omap_hwmod_ocp_barrier(struct omap_hwmod *oh) |
| 1751 | { |
| 1752 | BUG_ON(!oh); |
| 1753 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1754 | if (!oh->class->sysc || !oh->class->sysc->sysc_flags) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1755 | WARN(1, "omap_device: %s: OCP barrier impossible due to " |
| 1756 | "device configuration\n", oh->name); |
| 1757 | return; |
| 1758 | } |
| 1759 | |
| 1760 | /* |
| 1761 | * Forces posted writes to complete on the OCP thread handling |
| 1762 | * register writes |
| 1763 | */ |
Rajendra Nayak | cc7a1d2 | 2010-10-08 10:23:22 -0700 | [diff] [blame] | 1764 | omap_hwmod_read(oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * omap_hwmod_reset - reset the hwmod |
| 1769 | * @oh: struct omap_hwmod * |
| 1770 | * |
| 1771 | * Under some conditions, a driver may wish to reset the entire device. |
| 1772 | * Called from omap_device code. Returns -EINVAL on error or passes along |
Liam Girdwood | 9b57911 | 2010-09-21 10:34:09 -0600 | [diff] [blame] | 1773 | * the return value from _reset(). |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1774 | */ |
| 1775 | int omap_hwmod_reset(struct omap_hwmod *oh) |
| 1776 | { |
| 1777 | int r; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1778 | unsigned long flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1779 | |
Liam Girdwood | 9b57911 | 2010-09-21 10:34:09 -0600 | [diff] [blame] | 1780 | if (!oh) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1781 | return -EINVAL; |
| 1782 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1783 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1784 | r = _reset(oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1785 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1786 | |
| 1787 | return r; |
| 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * omap_hwmod_count_resources - count number of struct resources needed by hwmod |
| 1792 | * @oh: struct omap_hwmod * |
| 1793 | * @res: pointer to the first element of an array of struct resource to fill |
| 1794 | * |
| 1795 | * Count the number of struct resource array elements necessary to |
| 1796 | * contain omap_hwmod @oh resources. Intended to be called by code |
| 1797 | * that registers omap_devices. Intended to be used to determine the |
| 1798 | * size of a dynamically-allocated struct resource array, before |
| 1799 | * calling omap_hwmod_fill_resources(). Returns the number of struct |
| 1800 | * resource array elements needed. |
| 1801 | * |
| 1802 | * XXX This code is not optimized. It could attempt to merge adjacent |
| 1803 | * resource IDs. |
| 1804 | * |
| 1805 | */ |
| 1806 | int omap_hwmod_count_resources(struct omap_hwmod *oh) |
| 1807 | { |
| 1808 | int ret, i; |
| 1809 | |
Benoit Cousson | 9ee9fff | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 1810 | ret = oh->mpu_irqs_cnt + oh->sdma_reqs_cnt; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1811 | |
| 1812 | for (i = 0; i < oh->slaves_cnt; i++) |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 1813 | ret += oh->slaves[i]->addr_cnt; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1814 | |
| 1815 | return ret; |
| 1816 | } |
| 1817 | |
| 1818 | /** |
| 1819 | * omap_hwmod_fill_resources - fill struct resource array with hwmod data |
| 1820 | * @oh: struct omap_hwmod * |
| 1821 | * @res: pointer to the first element of an array of struct resource to fill |
| 1822 | * |
| 1823 | * Fill the struct resource array @res with resource data from the |
| 1824 | * omap_hwmod @oh. Intended to be called by code that registers |
| 1825 | * omap_devices. See also omap_hwmod_count_resources(). Returns the |
| 1826 | * number of array elements filled. |
| 1827 | */ |
| 1828 | int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) |
| 1829 | { |
| 1830 | int i, j; |
| 1831 | int r = 0; |
| 1832 | |
| 1833 | /* For each IRQ, DMA, memory area, fill in array.*/ |
| 1834 | |
| 1835 | for (i = 0; i < oh->mpu_irqs_cnt; i++) { |
Paul Walmsley | 718bfd7 | 2009-12-08 16:34:16 -0700 | [diff] [blame] | 1836 | (res + r)->name = (oh->mpu_irqs + i)->name; |
| 1837 | (res + r)->start = (oh->mpu_irqs + i)->irq; |
| 1838 | (res + r)->end = (oh->mpu_irqs + i)->irq; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1839 | (res + r)->flags = IORESOURCE_IRQ; |
| 1840 | r++; |
| 1841 | } |
| 1842 | |
Benoit Cousson | 9ee9fff | 2010-09-21 10:34:08 -0600 | [diff] [blame] | 1843 | for (i = 0; i < oh->sdma_reqs_cnt; i++) { |
| 1844 | (res + r)->name = (oh->sdma_reqs + i)->name; |
| 1845 | (res + r)->start = (oh->sdma_reqs + i)->dma_req; |
| 1846 | (res + r)->end = (oh->sdma_reqs + i)->dma_req; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1847 | (res + r)->flags = IORESOURCE_DMA; |
| 1848 | r++; |
| 1849 | } |
| 1850 | |
| 1851 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 1852 | struct omap_hwmod_ocp_if *os; |
| 1853 | |
Benoit Cousson | 682fdc9 | 2010-05-20 12:31:09 -0600 | [diff] [blame] | 1854 | os = oh->slaves[i]; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1855 | |
| 1856 | for (j = 0; j < os->addr_cnt; j++) { |
| 1857 | (res + r)->start = (os->addr + j)->pa_start; |
| 1858 | (res + r)->end = (os->addr + j)->pa_end; |
| 1859 | (res + r)->flags = IORESOURCE_MEM; |
| 1860 | r++; |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | return r; |
| 1865 | } |
| 1866 | |
| 1867 | /** |
| 1868 | * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain |
| 1869 | * @oh: struct omap_hwmod * |
| 1870 | * |
| 1871 | * Return the powerdomain pointer associated with the OMAP module |
| 1872 | * @oh's main clock. If @oh does not have a main clk, return the |
| 1873 | * powerdomain associated with the interface clock associated with the |
| 1874 | * module's MPU port. (XXX Perhaps this should use the SDMA port |
| 1875 | * instead?) Returns NULL on error, or a struct powerdomain * on |
| 1876 | * success. |
| 1877 | */ |
| 1878 | struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh) |
| 1879 | { |
| 1880 | struct clk *c; |
| 1881 | |
| 1882 | if (!oh) |
| 1883 | return NULL; |
| 1884 | |
| 1885 | if (oh->_clk) { |
| 1886 | c = oh->_clk; |
| 1887 | } else { |
| 1888 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 1889 | return NULL; |
| 1890 | c = oh->slaves[oh->_mpu_port_index]->_clk; |
| 1891 | } |
| 1892 | |
Thara Gopinath | d5647c1 | 2010-03-31 04:16:29 -0600 | [diff] [blame] | 1893 | if (!c->clkdm) |
| 1894 | return NULL; |
| 1895 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1896 | return c->clkdm->pwrdm.ptr; |
| 1897 | |
| 1898 | } |
| 1899 | |
| 1900 | /** |
Paul Walmsley | db2a60b | 2010-07-26 16:34:33 -0600 | [diff] [blame] | 1901 | * omap_hwmod_get_mpu_rt_va - return the module's base address (for the MPU) |
| 1902 | * @oh: struct omap_hwmod * |
| 1903 | * |
| 1904 | * Returns the virtual address corresponding to the beginning of the |
| 1905 | * module's register target, in the address range that is intended to |
| 1906 | * be used by the MPU. Returns the virtual address upon success or NULL |
| 1907 | * upon error. |
| 1908 | */ |
| 1909 | void __iomem *omap_hwmod_get_mpu_rt_va(struct omap_hwmod *oh) |
| 1910 | { |
| 1911 | if (!oh) |
| 1912 | return NULL; |
| 1913 | |
| 1914 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 1915 | return NULL; |
| 1916 | |
| 1917 | if (oh->_state == _HWMOD_STATE_UNKNOWN) |
| 1918 | return NULL; |
| 1919 | |
| 1920 | return oh->_mpu_rt_va; |
| 1921 | } |
| 1922 | |
| 1923 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1924 | * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh |
| 1925 | * @oh: struct omap_hwmod * |
| 1926 | * @init_oh: struct omap_hwmod * (initiator) |
| 1927 | * |
| 1928 | * Add a sleep dependency between the initiator @init_oh and @oh. |
| 1929 | * Intended to be called by DSP/Bridge code via platform_data for the |
| 1930 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge |
| 1931 | * code needs to add/del initiator dependencies dynamically |
| 1932 | * before/after accessing a device. Returns the return value from |
| 1933 | * _add_initiator_dep(). |
| 1934 | * |
| 1935 | * XXX Keep a usecount in the clockdomain code |
| 1936 | */ |
| 1937 | int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh, |
| 1938 | struct omap_hwmod *init_oh) |
| 1939 | { |
| 1940 | return _add_initiator_dep(oh, init_oh); |
| 1941 | } |
| 1942 | |
| 1943 | /* |
| 1944 | * XXX what about functions for drivers to save/restore ocp_sysconfig |
| 1945 | * for context save/restore operations? |
| 1946 | */ |
| 1947 | |
| 1948 | /** |
| 1949 | * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh |
| 1950 | * @oh: struct omap_hwmod * |
| 1951 | * @init_oh: struct omap_hwmod * (initiator) |
| 1952 | * |
| 1953 | * Remove a sleep dependency between the initiator @init_oh and @oh. |
| 1954 | * Intended to be called by DSP/Bridge code via platform_data for the |
| 1955 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge |
| 1956 | * code needs to add/del initiator dependencies dynamically |
| 1957 | * before/after accessing a device. Returns the return value from |
| 1958 | * _del_initiator_dep(). |
| 1959 | * |
| 1960 | * XXX Keep a usecount in the clockdomain code |
| 1961 | */ |
| 1962 | int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh, |
| 1963 | struct omap_hwmod *init_oh) |
| 1964 | { |
| 1965 | return _del_initiator_dep(oh, init_oh); |
| 1966 | } |
| 1967 | |
| 1968 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1969 | * omap_hwmod_enable_wakeup - allow device to wake up the system |
| 1970 | * @oh: struct omap_hwmod * |
| 1971 | * |
| 1972 | * Sets the module OCP socket ENAWAKEUP bit to allow the module to |
| 1973 | * send wakeups to the PRCM. Eventually this should sets PRCM wakeup |
| 1974 | * registers to cause the PRCM to receive wakeup events from the |
| 1975 | * module. Does not set any wakeup routing registers beyond this |
| 1976 | * point - if the module is to wake up any other module or subsystem, |
| 1977 | * that must be set separately. Called by omap_device code. Returns |
| 1978 | * -EINVAL on error or 0 upon success. |
| 1979 | */ |
| 1980 | int omap_hwmod_enable_wakeup(struct omap_hwmod *oh) |
| 1981 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1982 | unsigned long flags; |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 1983 | u32 v; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1984 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1985 | if (!oh->class->sysc || |
| 1986 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1987 | return -EINVAL; |
| 1988 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1989 | spin_lock_irqsave(&oh->_lock, flags); |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 1990 | v = oh->_sysc_cache; |
| 1991 | _enable_wakeup(oh, &v); |
| 1992 | _write_sysconfig(v, oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 1993 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * omap_hwmod_disable_wakeup - prevent device from waking the system |
| 2000 | * @oh: struct omap_hwmod * |
| 2001 | * |
| 2002 | * Clears the module OCP socket ENAWAKEUP bit to prevent the module |
| 2003 | * from sending wakeups to the PRCM. Eventually this should clear |
| 2004 | * PRCM wakeup registers to cause the PRCM to ignore wakeup events |
| 2005 | * from the module. Does not set any wakeup routing registers beyond |
| 2006 | * this point - if the module is to wake up any other module or |
| 2007 | * subsystem, that must be set separately. Called by omap_device |
| 2008 | * code. Returns -EINVAL on error or 0 upon success. |
| 2009 | */ |
| 2010 | int omap_hwmod_disable_wakeup(struct omap_hwmod *oh) |
| 2011 | { |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2012 | unsigned long flags; |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 2013 | u32 v; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2014 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2015 | if (!oh->class->sysc || |
| 2016 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2017 | return -EINVAL; |
| 2018 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2019 | spin_lock_irqsave(&oh->_lock, flags); |
Kevin Hilman | 5a7ddcb | 2010-12-21 21:08:34 -0700 | [diff] [blame] | 2020 | v = oh->_sysc_cache; |
| 2021 | _disable_wakeup(oh, &v); |
| 2022 | _write_sysconfig(v, oh); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2023 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 2024 | |
| 2025 | return 0; |
| 2026 | } |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2027 | |
| 2028 | /** |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2029 | * omap_hwmod_assert_hardreset - assert the HW reset line of submodules |
| 2030 | * contained in the hwmod module. |
| 2031 | * @oh: struct omap_hwmod * |
| 2032 | * @name: name of the reset line to lookup and assert |
| 2033 | * |
| 2034 | * Some IP like dsp, ipu or iva contain processor that require |
| 2035 | * an HW reset line to be assert / deassert in order to enable fully |
| 2036 | * the IP. Returns -EINVAL if @oh is null or if the operation is not |
| 2037 | * yet supported on this OMAP; otherwise, passes along the return value |
| 2038 | * from _assert_hardreset(). |
| 2039 | */ |
| 2040 | int omap_hwmod_assert_hardreset(struct omap_hwmod *oh, const char *name) |
| 2041 | { |
| 2042 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2043 | unsigned long flags; |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2044 | |
| 2045 | if (!oh) |
| 2046 | return -EINVAL; |
| 2047 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2048 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2049 | ret = _assert_hardreset(oh, name); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2050 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2051 | |
| 2052 | return ret; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * omap_hwmod_deassert_hardreset - deassert the HW reset line of submodules |
| 2057 | * contained in the hwmod module. |
| 2058 | * @oh: struct omap_hwmod * |
| 2059 | * @name: name of the reset line to look up and deassert |
| 2060 | * |
| 2061 | * Some IP like dsp, ipu or iva contain processor that require |
| 2062 | * an HW reset line to be assert / deassert in order to enable fully |
| 2063 | * the IP. Returns -EINVAL if @oh is null or if the operation is not |
| 2064 | * yet supported on this OMAP; otherwise, passes along the return value |
| 2065 | * from _deassert_hardreset(). |
| 2066 | */ |
| 2067 | int omap_hwmod_deassert_hardreset(struct omap_hwmod *oh, const char *name) |
| 2068 | { |
| 2069 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2070 | unsigned long flags; |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2071 | |
| 2072 | if (!oh) |
| 2073 | return -EINVAL; |
| 2074 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2075 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2076 | ret = _deassert_hardreset(oh, name); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2077 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2078 | |
| 2079 | return ret; |
| 2080 | } |
| 2081 | |
| 2082 | /** |
| 2083 | * omap_hwmod_read_hardreset - read the HW reset line state of submodules |
| 2084 | * contained in the hwmod module |
| 2085 | * @oh: struct omap_hwmod * |
| 2086 | * @name: name of the reset line to look up and read |
| 2087 | * |
| 2088 | * Return the current state of the hwmod @oh's reset line named @name: |
| 2089 | * returns -EINVAL upon parameter error or if this operation |
| 2090 | * is unsupported on the current OMAP; otherwise, passes along the return |
| 2091 | * value from _read_hardreset(). |
| 2092 | */ |
| 2093 | int omap_hwmod_read_hardreset(struct omap_hwmod *oh, const char *name) |
| 2094 | { |
| 2095 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2096 | unsigned long flags; |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2097 | |
| 2098 | if (!oh) |
| 2099 | return -EINVAL; |
| 2100 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2101 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2102 | ret = _read_hardreset(oh, name); |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2103 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | aee48e3 | 2010-09-21 10:34:11 -0600 | [diff] [blame] | 2104 | |
| 2105 | return ret; |
| 2106 | } |
| 2107 | |
| 2108 | |
| 2109 | /** |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2110 | * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname |
| 2111 | * @classname: struct omap_hwmod_class name to search for |
| 2112 | * @fn: callback function pointer to call for each hwmod in class @classname |
| 2113 | * @user: arbitrary context data to pass to the callback function |
| 2114 | * |
Benoit Cousson | ce35b24 | 2010-12-21 21:31:28 -0700 | [diff] [blame] | 2115 | * For each omap_hwmod of class @classname, call @fn. |
| 2116 | * If the callback function returns something other than |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2117 | * zero, the iterator is terminated, and the callback function's return |
| 2118 | * value is passed back to the caller. Returns 0 upon success, -EINVAL |
| 2119 | * if @classname or @fn are NULL, or passes back the error code from @fn. |
| 2120 | */ |
| 2121 | int omap_hwmod_for_each_by_class(const char *classname, |
| 2122 | int (*fn)(struct omap_hwmod *oh, |
| 2123 | void *user), |
| 2124 | void *user) |
| 2125 | { |
| 2126 | struct omap_hwmod *temp_oh; |
| 2127 | int ret = 0; |
| 2128 | |
| 2129 | if (!classname || !fn) |
| 2130 | return -EINVAL; |
| 2131 | |
| 2132 | pr_debug("omap_hwmod: %s: looking for modules of class %s\n", |
| 2133 | __func__, classname); |
| 2134 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2135 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 2136 | if (!strcmp(temp_oh->class->name, classname)) { |
| 2137 | pr_debug("omap_hwmod: %s: %s: calling callback fn\n", |
| 2138 | __func__, temp_oh->name); |
| 2139 | ret = (*fn)(temp_oh, user); |
| 2140 | if (ret) |
| 2141 | break; |
| 2142 | } |
| 2143 | } |
| 2144 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 2145 | if (ret) |
| 2146 | pr_debug("omap_hwmod: %s: iterator terminated early: %d\n", |
| 2147 | __func__, ret); |
| 2148 | |
| 2149 | return ret; |
| 2150 | } |
| 2151 | |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2152 | /** |
| 2153 | * omap_hwmod_set_postsetup_state - set the post-_setup() state for this hwmod |
| 2154 | * @oh: struct omap_hwmod * |
| 2155 | * @state: state that _setup() should leave the hwmod in |
| 2156 | * |
| 2157 | * Sets the hwmod state that @oh will enter at the end of _setup() (called by |
| 2158 | * omap_hwmod_late_init()). Only valid to call between calls to |
| 2159 | * omap_hwmod_init() and omap_hwmod_late_init(). Returns 0 upon success or |
| 2160 | * -EINVAL if there is a problem with the arguments or if the hwmod is |
| 2161 | * in the wrong state. |
| 2162 | */ |
| 2163 | int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state) |
| 2164 | { |
| 2165 | int ret; |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2166 | unsigned long flags; |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2167 | |
| 2168 | if (!oh) |
| 2169 | return -EINVAL; |
| 2170 | |
| 2171 | if (state != _HWMOD_STATE_DISABLED && |
| 2172 | state != _HWMOD_STATE_ENABLED && |
| 2173 | state != _HWMOD_STATE_IDLE) |
| 2174 | return -EINVAL; |
| 2175 | |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2176 | spin_lock_irqsave(&oh->_lock, flags); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2177 | |
| 2178 | if (oh->_state != _HWMOD_STATE_REGISTERED) { |
| 2179 | ret = -EINVAL; |
| 2180 | goto ohsps_unlock; |
| 2181 | } |
| 2182 | |
| 2183 | oh->_postsetup_state = state; |
| 2184 | ret = 0; |
| 2185 | |
| 2186 | ohsps_unlock: |
Paul Walmsley | dc6d1cd | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2187 | spin_unlock_irqrestore(&oh->_lock, flags); |
Paul Walmsley | 2092e5c | 2010-12-14 12:42:35 -0700 | [diff] [blame] | 2188 | |
| 2189 | return ret; |
| 2190 | } |
Kevin Hilman | c80705a | 2010-12-21 21:31:55 -0700 | [diff] [blame^] | 2191 | |
| 2192 | /** |
| 2193 | * omap_hwmod_get_context_loss_count - get lost context count |
| 2194 | * @oh: struct omap_hwmod * |
| 2195 | * |
| 2196 | * Query the powerdomain of of @oh to get the context loss |
| 2197 | * count for this device. |
| 2198 | * |
| 2199 | * Returns the context loss count of the powerdomain assocated with @oh |
| 2200 | * upon success, or zero if no powerdomain exists for @oh. |
| 2201 | */ |
| 2202 | u32 omap_hwmod_get_context_loss_count(struct omap_hwmod *oh) |
| 2203 | { |
| 2204 | struct powerdomain *pwrdm; |
| 2205 | int ret = 0; |
| 2206 | |
| 2207 | pwrdm = omap_hwmod_get_pwrdm(oh); |
| 2208 | if (pwrdm) |
| 2209 | ret = pwrdm_get_context_loss_count(pwrdm); |
| 2210 | |
| 2211 | return ret; |
| 2212 | } |