Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1 | /* |
| 2 | * omap_hwmod implementation for OMAP2/3/4 |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Paul Walmsley |
| 6 | * With fixes and testing from Kevin Hilman |
| 7 | * |
| 8 | * Created in collaboration with (alphabetical order): Benoit Cousson, |
| 9 | * Kevin Hilman, Tony Lindgren, Rajendra Nayak, Vikram Pandita, Sakari |
| 10 | * Poussa, Anand Sawant, Santosh Shilimkar, Richard Woodruff |
| 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 | * |
| 16 | * This code manages "OMAP modules" (on-chip devices) and their |
| 17 | * integration with Linux device driver and bus code. |
| 18 | * |
| 19 | * References: |
| 20 | * - OMAP2420 Multimedia Processor Silicon Revision 2.1.1, 2.2 (SWPU064) |
| 21 | * - OMAP2430 Multimedia Device POP Silicon Revision 2.1 (SWPU090) |
| 22 | * - OMAP34xx Multimedia Device Silicon Revision 3.1 (SWPU108) |
| 23 | * - OMAP4430 Multimedia Device Silicon Revision 1.0 (SWPU140) |
| 24 | * - Open Core Protocol Specification 2.2 |
| 25 | * |
| 26 | * To do: |
| 27 | * - pin mux handling |
| 28 | * - handle IO mapping |
| 29 | * - bus throughput & module latency measurement code |
| 30 | * |
| 31 | * XXX add tests at the beginning of each function to ensure the hwmod is |
| 32 | * in the appropriate state |
| 33 | * XXX error return values should be checked to ensure that they are |
| 34 | * appropriate |
| 35 | */ |
| 36 | #undef DEBUG |
| 37 | |
| 38 | #include <linux/kernel.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/io.h> |
| 41 | #include <linux/clk.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/err.h> |
| 44 | #include <linux/list.h> |
| 45 | #include <linux/mutex.h> |
| 46 | #include <linux/bootmem.h> |
| 47 | |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 48 | #include <plat/common.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 49 | #include <plat/cpu.h> |
| 50 | #include <plat/clockdomain.h> |
| 51 | #include <plat/powerdomain.h> |
| 52 | #include <plat/clock.h> |
| 53 | #include <plat/omap_hwmod.h> |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 54 | |
| 55 | #include "cm.h" |
| 56 | |
| 57 | /* Maximum microseconds to wait for OMAP module to reset */ |
| 58 | #define MAX_MODULE_RESET_WAIT 10000 |
| 59 | |
| 60 | /* Name of the OMAP hwmod for the MPU */ |
| 61 | #define MPU_INITIATOR_NAME "mpu_hwmod" |
| 62 | |
| 63 | /* omap_hwmod_list contains all registered struct omap_hwmods */ |
| 64 | static LIST_HEAD(omap_hwmod_list); |
| 65 | |
| 66 | static DEFINE_MUTEX(omap_hwmod_mutex); |
| 67 | |
| 68 | /* mpu_oh: used to add/remove MPU initiator from sleepdep list */ |
| 69 | static struct omap_hwmod *mpu_oh; |
| 70 | |
| 71 | /* inited: 0 if omap_hwmod_init() has not yet been called; 1 otherwise */ |
| 72 | static u8 inited; |
| 73 | |
| 74 | |
| 75 | /* Private functions */ |
| 76 | |
| 77 | /** |
| 78 | * _update_sysc_cache - return the module OCP_SYSCONFIG register, keep copy |
| 79 | * @oh: struct omap_hwmod * |
| 80 | * |
| 81 | * Load the current value of the hwmod OCP_SYSCONFIG register into the |
| 82 | * struct omap_hwmod for later use. Returns -EINVAL if the hwmod has no |
| 83 | * OCP_SYSCONFIG register or 0 upon success. |
| 84 | */ |
| 85 | static int _update_sysc_cache(struct omap_hwmod *oh) |
| 86 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 87 | if (!oh->class->sysc) { |
| 88 | 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] | 89 | return -EINVAL; |
| 90 | } |
| 91 | |
| 92 | /* XXX ensure module interface clock is up */ |
| 93 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 94 | oh->_sysc_cache = omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 95 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 96 | if (!(oh->class->sysc->sysc_flags & SYSC_NO_CACHE)) |
Thara Gopinath | 883edfd | 2010-01-19 17:30:51 -0700 | [diff] [blame] | 97 | oh->_int_flags |= _HWMOD_SYSCONFIG_LOADED; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * _write_sysconfig - write a value to the module's OCP_SYSCONFIG register |
| 104 | * @v: OCP_SYSCONFIG value to write |
| 105 | * @oh: struct omap_hwmod * |
| 106 | * |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 107 | * Write @v into the module class' OCP_SYSCONFIG register, if it has |
| 108 | * one. No return value. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 109 | */ |
| 110 | static void _write_sysconfig(u32 v, struct omap_hwmod *oh) |
| 111 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 112 | if (!oh->class->sysc) { |
| 113 | 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] | 114 | return; |
| 115 | } |
| 116 | |
| 117 | /* XXX ensure module interface clock is up */ |
| 118 | |
| 119 | if (oh->_sysc_cache != v) { |
| 120 | oh->_sysc_cache = v; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 121 | omap_hwmod_writel(v, oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * _set_master_standbymode: set the OCP_SYSCONFIG MIDLEMODE field in @v |
| 127 | * @oh: struct omap_hwmod * |
| 128 | * @standbymode: MIDLEMODE field bits |
| 129 | * @v: pointer to register contents to modify |
| 130 | * |
| 131 | * Update the master standby mode bits in @v to be @standbymode for |
| 132 | * the @oh hwmod. Does not write to the hardware. Returns -EINVAL |
| 133 | * upon error or 0 upon success. |
| 134 | */ |
| 135 | static int _set_master_standbymode(struct omap_hwmod *oh, u8 standbymode, |
| 136 | u32 *v) |
| 137 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 138 | u32 mstandby_mask; |
| 139 | u8 mstandby_shift; |
| 140 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 141 | if (!oh->class->sysc || |
| 142 | !(oh->class->sysc->sysc_flags & SYSC_HAS_MIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 145 | if (!oh->class->sysc->sysc_fields) { |
| 146 | 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] | 147 | return -EINVAL; |
| 148 | } |
| 149 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 150 | mstandby_shift = oh->class->sysc->sysc_fields->midle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 151 | mstandby_mask = (0x3 << mstandby_shift); |
| 152 | |
| 153 | *v &= ~mstandby_mask; |
| 154 | *v |= __ffs(standbymode) << mstandby_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * _set_slave_idlemode: set the OCP_SYSCONFIG SIDLEMODE field in @v |
| 161 | * @oh: struct omap_hwmod * |
| 162 | * @idlemode: SIDLEMODE field bits |
| 163 | * @v: pointer to register contents to modify |
| 164 | * |
| 165 | * Update the slave idle mode bits in @v to be @idlemode for the @oh |
| 166 | * hwmod. Does not write to the hardware. Returns -EINVAL upon error |
| 167 | * or 0 upon success. |
| 168 | */ |
| 169 | static int _set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode, u32 *v) |
| 170 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 171 | u32 sidle_mask; |
| 172 | u8 sidle_shift; |
| 173 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 174 | if (!oh->class->sysc || |
| 175 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SIDLEMODE)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 176 | return -EINVAL; |
| 177 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 178 | if (!oh->class->sysc->sysc_fields) { |
| 179 | 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] | 180 | return -EINVAL; |
| 181 | } |
| 182 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 183 | sidle_shift = oh->class->sysc->sysc_fields->sidle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 184 | sidle_mask = (0x3 << sidle_shift); |
| 185 | |
| 186 | *v &= ~sidle_mask; |
| 187 | *v |= __ffs(idlemode) << sidle_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * _set_clockactivity: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v |
| 194 | * @oh: struct omap_hwmod * |
| 195 | * @clockact: CLOCKACTIVITY field bits |
| 196 | * @v: pointer to register contents to modify |
| 197 | * |
| 198 | * Update the clockactivity mode bits in @v to be @clockact for the |
| 199 | * @oh hwmod. Used for additional powersaving on some modules. Does |
| 200 | * not write to the hardware. Returns -EINVAL upon error or 0 upon |
| 201 | * success. |
| 202 | */ |
| 203 | static int _set_clockactivity(struct omap_hwmod *oh, u8 clockact, u32 *v) |
| 204 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 205 | u32 clkact_mask; |
| 206 | u8 clkact_shift; |
| 207 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 208 | if (!oh->class->sysc || |
| 209 | !(oh->class->sysc->sysc_flags & SYSC_HAS_CLOCKACTIVITY)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 210 | return -EINVAL; |
| 211 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 212 | if (!oh->class->sysc->sysc_fields) { |
| 213 | 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] | 214 | return -EINVAL; |
| 215 | } |
| 216 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 217 | clkact_shift = oh->class->sysc->sysc_fields->clkact_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 218 | clkact_mask = (0x3 << clkact_shift); |
| 219 | |
| 220 | *v &= ~clkact_mask; |
| 221 | *v |= clockact << clkact_shift; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * _set_softreset: set OCP_SYSCONFIG.CLOCKACTIVITY bits in @v |
| 228 | * @oh: struct omap_hwmod * |
| 229 | * @v: pointer to register contents to modify |
| 230 | * |
| 231 | * Set the SOFTRESET bit in @v for hwmod @oh. Returns -EINVAL upon |
| 232 | * error or 0 upon success. |
| 233 | */ |
| 234 | static int _set_softreset(struct omap_hwmod *oh, u32 *v) |
| 235 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 236 | u32 softrst_mask; |
| 237 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 238 | if (!oh->class->sysc || |
| 239 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 240 | return -EINVAL; |
| 241 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 242 | if (!oh->class->sysc->sysc_fields) { |
| 243 | 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] | 244 | return -EINVAL; |
| 245 | } |
| 246 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 247 | softrst_mask = (0x1 << oh->class->sysc->sysc_fields->srst_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 248 | |
| 249 | *v |= softrst_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /** |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 255 | * _set_module_autoidle: set the OCP_SYSCONFIG AUTOIDLE field in @v |
| 256 | * @oh: struct omap_hwmod * |
| 257 | * @autoidle: desired AUTOIDLE bitfield value (0 or 1) |
| 258 | * @v: pointer to register contents to modify |
| 259 | * |
| 260 | * Update the module autoidle bit in @v to be @autoidle for the @oh |
| 261 | * hwmod. The autoidle bit controls whether the module can gate |
| 262 | * internal clocks automatically when it isn't doing anything; the |
| 263 | * exact function of this bit varies on a per-module basis. This |
| 264 | * function does not write to the hardware. Returns -EINVAL upon |
| 265 | * error or 0 upon success. |
| 266 | */ |
| 267 | static int _set_module_autoidle(struct omap_hwmod *oh, u8 autoidle, |
| 268 | u32 *v) |
| 269 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 270 | u32 autoidle_mask; |
| 271 | u8 autoidle_shift; |
| 272 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 273 | if (!oh->class->sysc || |
| 274 | !(oh->class->sysc->sysc_flags & SYSC_HAS_AUTOIDLE)) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 275 | return -EINVAL; |
| 276 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 277 | if (!oh->class->sysc->sysc_fields) { |
| 278 | 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] | 279 | return -EINVAL; |
| 280 | } |
| 281 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 282 | autoidle_shift = oh->class->sysc->sysc_fields->autoidle_shift; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 283 | autoidle_mask = (0x3 << autoidle_shift); |
| 284 | |
| 285 | *v &= ~autoidle_mask; |
| 286 | *v |= autoidle << autoidle_shift; |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 292 | * _enable_wakeup: set OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 293 | * @oh: struct omap_hwmod * |
| 294 | * |
| 295 | * Allow the hardware module @oh to send wakeups. Returns -EINVAL |
| 296 | * upon error or 0 upon success. |
| 297 | */ |
| 298 | static int _enable_wakeup(struct omap_hwmod *oh) |
| 299 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 300 | u32 v, wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 301 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 302 | if (!oh->class->sysc || |
| 303 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 304 | return -EINVAL; |
| 305 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 306 | if (!oh->class->sysc->sysc_fields) { |
| 307 | 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] | 308 | return -EINVAL; |
| 309 | } |
| 310 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 311 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 312 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 313 | v = oh->_sysc_cache; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 314 | v |= wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 315 | _write_sysconfig(v, oh); |
| 316 | |
| 317 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 318 | |
| 319 | oh->_int_flags |= _HWMOD_WAKEUP_ENABLED; |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * _disable_wakeup: clear OCP_SYSCONFIG.ENAWAKEUP bit in the hardware |
| 326 | * @oh: struct omap_hwmod * |
| 327 | * |
| 328 | * Prevent the hardware module @oh to send wakeups. Returns -EINVAL |
| 329 | * upon error or 0 upon success. |
| 330 | */ |
| 331 | static int _disable_wakeup(struct omap_hwmod *oh) |
| 332 | { |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 333 | u32 v, wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 334 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 335 | if (!oh->class->sysc || |
| 336 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 337 | return -EINVAL; |
| 338 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 339 | if (!oh->class->sysc->sysc_fields) { |
| 340 | 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] | 341 | return -EINVAL; |
| 342 | } |
| 343 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 344 | wakeup_mask = (0x1 << oh->class->sysc->sysc_fields->enwkup_shift); |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 345 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 346 | v = oh->_sysc_cache; |
Thara Gopinath | 358f0e6 | 2010-02-24 12:05:58 -0700 | [diff] [blame] | 347 | v &= ~wakeup_mask; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 348 | _write_sysconfig(v, oh); |
| 349 | |
| 350 | /* XXX test pwrdm_get_wken for this hwmod's subsystem */ |
| 351 | |
| 352 | oh->_int_flags &= ~_HWMOD_WAKEUP_ENABLED; |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * _add_initiator_dep: prevent @oh from smart-idling while @init_oh is active |
| 359 | * @oh: struct omap_hwmod * |
| 360 | * |
| 361 | * Prevent the hardware module @oh from entering idle while the |
| 362 | * hardare module initiator @init_oh is active. Useful when a module |
| 363 | * will be accessed by a particular initiator (e.g., if a module will |
| 364 | * be accessed by the IVA, there should be a sleepdep between the IVA |
| 365 | * initiator and the module). Only applies to modules in smart-idle |
| 366 | * mode. Returns -EINVAL upon error or passes along |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 367 | * clkdm_add_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 368 | */ |
| 369 | static int _add_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 370 | { |
| 371 | if (!oh->_clk) |
| 372 | return -EINVAL; |
| 373 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 374 | return clkdm_add_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /** |
| 378 | * _del_initiator_dep: allow @oh to smart-idle even if @init_oh is active |
| 379 | * @oh: struct omap_hwmod * |
| 380 | * |
| 381 | * Allow the hardware module @oh to enter idle while the hardare |
| 382 | * module initiator @init_oh is active. Useful when a module will not |
| 383 | * be accessed by a particular initiator (e.g., if a module will not |
| 384 | * be accessed by the IVA, there should be no sleepdep between the IVA |
| 385 | * initiator and the module). Only applies to modules in smart-idle |
| 386 | * mode. Returns -EINVAL upon error or passes along |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 387 | * clkdm_del_sleepdep() value upon success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 388 | */ |
| 389 | static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh) |
| 390 | { |
| 391 | if (!oh->_clk) |
| 392 | return -EINVAL; |
| 393 | |
Paul Walmsley | 55ed969 | 2010-01-26 20:12:59 -0700 | [diff] [blame] | 394 | return clkdm_del_sleepdep(oh->_clk->clkdm, init_oh->_clk->clkdm); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /** |
| 398 | * _init_main_clk - get a struct clk * for the the hwmod's main functional clk |
| 399 | * @oh: struct omap_hwmod * |
| 400 | * |
| 401 | * Called from _init_clocks(). Populates the @oh _clk (main |
| 402 | * functional clock pointer) if a main_clk is present. Returns 0 on |
| 403 | * success or -EINVAL on error. |
| 404 | */ |
| 405 | static int _init_main_clk(struct omap_hwmod *oh) |
| 406 | { |
| 407 | struct clk *c; |
| 408 | int ret = 0; |
| 409 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 410 | if (!oh->main_clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 411 | return 0; |
| 412 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 413 | c = omap_clk_get_by_name(oh->main_clk); |
| 414 | WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get main_clk %s\n", |
| 415 | oh->name, oh->main_clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 416 | if (IS_ERR(c)) |
| 417 | ret = -EINVAL; |
| 418 | oh->_clk = c; |
| 419 | |
Kevin Hilman | 81d7c6f | 2009-12-08 16:34:24 -0700 | [diff] [blame] | 420 | WARN(!c->clkdm, "omap_hwmod: %s: missing clockdomain for %s.\n", |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 421 | oh->main_clk, c->name); |
Kevin Hilman | 81d7c6f | 2009-12-08 16:34:24 -0700 | [diff] [blame] | 422 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * _init_interface_clk - get a struct clk * for the the hwmod's interface clks |
| 428 | * @oh: struct omap_hwmod * |
| 429 | * |
| 430 | * Called from _init_clocks(). Populates the @oh OCP slave interface |
| 431 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 432 | */ |
| 433 | static int _init_interface_clks(struct omap_hwmod *oh) |
| 434 | { |
| 435 | struct omap_hwmod_ocp_if *os; |
| 436 | struct clk *c; |
| 437 | int i; |
| 438 | int ret = 0; |
| 439 | |
| 440 | if (oh->slaves_cnt == 0) |
| 441 | return 0; |
| 442 | |
| 443 | for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) { |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 444 | if (!os->clk) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 445 | continue; |
| 446 | |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 447 | c = omap_clk_get_by_name(os->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 448 | WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get " |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 449 | "interface_clk %s\n", oh->name, os->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 450 | if (IS_ERR(c)) |
| 451 | ret = -EINVAL; |
| 452 | os->_clk = c; |
| 453 | } |
| 454 | |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * _init_opt_clk - get a struct clk * for the the hwmod's optional clocks |
| 460 | * @oh: struct omap_hwmod * |
| 461 | * |
| 462 | * Called from _init_clocks(). Populates the @oh omap_hwmod_opt_clk |
| 463 | * clock pointers. Returns 0 on success or -EINVAL on error. |
| 464 | */ |
| 465 | static int _init_opt_clks(struct omap_hwmod *oh) |
| 466 | { |
| 467 | struct omap_hwmod_opt_clk *oc; |
| 468 | struct clk *c; |
| 469 | int i; |
| 470 | int ret = 0; |
| 471 | |
| 472 | 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] | 473 | c = omap_clk_get_by_name(oc->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 474 | WARN(IS_ERR(c), "omap_hwmod: %s: cannot clk_get opt_clk " |
Paul Walmsley | 50ebdac | 2010-02-22 22:09:31 -0700 | [diff] [blame] | 475 | "%s\n", oh->name, oc->clk); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 476 | if (IS_ERR(c)) |
| 477 | ret = -EINVAL; |
| 478 | oc->_clk = c; |
| 479 | } |
| 480 | |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * _enable_clocks - enable hwmod main clock and interface clocks |
| 486 | * @oh: struct omap_hwmod * |
| 487 | * |
| 488 | * Enables all clocks necessary for register reads and writes to succeed |
| 489 | * on the hwmod @oh. Returns 0. |
| 490 | */ |
| 491 | static int _enable_clocks(struct omap_hwmod *oh) |
| 492 | { |
| 493 | struct omap_hwmod_ocp_if *os; |
| 494 | int i; |
| 495 | |
| 496 | pr_debug("omap_hwmod: %s: enabling clocks\n", oh->name); |
| 497 | |
| 498 | if (oh->_clk && !IS_ERR(oh->_clk)) |
| 499 | clk_enable(oh->_clk); |
| 500 | |
| 501 | if (oh->slaves_cnt > 0) { |
| 502 | for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) { |
| 503 | struct clk *c = os->_clk; |
| 504 | |
| 505 | if (c && !IS_ERR(c) && (os->flags & OCPIF_SWSUP_IDLE)) |
| 506 | clk_enable(c); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /* The opt clocks are controlled by the device driver. */ |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * _disable_clocks - disable hwmod main clock and interface clocks |
| 517 | * @oh: struct omap_hwmod * |
| 518 | * |
| 519 | * Disables the hwmod @oh main functional and interface clocks. Returns 0. |
| 520 | */ |
| 521 | static int _disable_clocks(struct omap_hwmod *oh) |
| 522 | { |
| 523 | struct omap_hwmod_ocp_if *os; |
| 524 | int i; |
| 525 | |
| 526 | pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name); |
| 527 | |
| 528 | if (oh->_clk && !IS_ERR(oh->_clk)) |
| 529 | clk_disable(oh->_clk); |
| 530 | |
| 531 | if (oh->slaves_cnt > 0) { |
| 532 | for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) { |
| 533 | struct clk *c = os->_clk; |
| 534 | |
| 535 | if (c && !IS_ERR(c) && (os->flags & OCPIF_SWSUP_IDLE)) |
| 536 | clk_disable(c); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /* The opt clocks are controlled by the device driver. */ |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * _find_mpu_port_index - find hwmod OCP slave port ID intended for MPU use |
| 547 | * @oh: struct omap_hwmod * |
| 548 | * |
| 549 | * Returns the array index of the OCP slave port that the MPU |
| 550 | * addresses the device on, or -EINVAL upon error or not found. |
| 551 | */ |
| 552 | static int _find_mpu_port_index(struct omap_hwmod *oh) |
| 553 | { |
| 554 | struct omap_hwmod_ocp_if *os; |
| 555 | int i; |
| 556 | int found = 0; |
| 557 | |
| 558 | if (!oh || oh->slaves_cnt == 0) |
| 559 | return -EINVAL; |
| 560 | |
| 561 | for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) { |
| 562 | if (os->user & OCP_USER_MPU) { |
| 563 | found = 1; |
| 564 | break; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | if (found) |
| 569 | pr_debug("omap_hwmod: %s: MPU OCP slave port ID %d\n", |
| 570 | oh->name, i); |
| 571 | else |
| 572 | pr_debug("omap_hwmod: %s: no MPU OCP slave port found\n", |
| 573 | oh->name); |
| 574 | |
| 575 | return (found) ? i : -EINVAL; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * _find_mpu_rt_base - find hwmod register target base addr accessible by MPU |
| 580 | * @oh: struct omap_hwmod * |
| 581 | * |
| 582 | * Return the virtual address of the base of the register target of |
| 583 | * device @oh, or NULL on error. |
| 584 | */ |
| 585 | static void __iomem *_find_mpu_rt_base(struct omap_hwmod *oh, u8 index) |
| 586 | { |
| 587 | struct omap_hwmod_ocp_if *os; |
| 588 | struct omap_hwmod_addr_space *mem; |
| 589 | int i; |
| 590 | int found = 0; |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 591 | void __iomem *va_start; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 592 | |
| 593 | if (!oh || oh->slaves_cnt == 0) |
| 594 | return NULL; |
| 595 | |
| 596 | os = *oh->slaves + index; |
| 597 | |
| 598 | for (i = 0, mem = os->addr; i < os->addr_cnt; i++, mem++) { |
| 599 | if (mem->flags & ADDR_TYPE_RT) { |
| 600 | found = 1; |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 605 | if (found) { |
| 606 | va_start = ioremap(mem->pa_start, mem->pa_end - mem->pa_start); |
| 607 | if (!va_start) { |
| 608 | pr_err("omap_hwmod: %s: Could not ioremap\n", oh->name); |
| 609 | return NULL; |
| 610 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 611 | pr_debug("omap_hwmod: %s: MPU register target at va %p\n", |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 612 | oh->name, va_start); |
| 613 | } else { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 614 | pr_debug("omap_hwmod: %s: no MPU register target found\n", |
| 615 | oh->name); |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 616 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 617 | |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 618 | return (found) ? va_start : NULL; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * _sysc_enable - try to bring a module out of idle via OCP_SYSCONFIG |
| 623 | * @oh: struct omap_hwmod * |
| 624 | * |
| 625 | * If module is marked as SWSUP_SIDLE, force the module out of slave |
| 626 | * idle; otherwise, configure it for smart-idle. If module is marked |
| 627 | * as SWSUP_MSUSPEND, force the module out of master standby; |
| 628 | * otherwise, configure it for smart-standby. No return value. |
| 629 | */ |
| 630 | static void _sysc_enable(struct omap_hwmod *oh) |
| 631 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 632 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 633 | u32 v; |
| 634 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 635 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 636 | return; |
| 637 | |
| 638 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 639 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 640 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 641 | if (sf & SYSC_HAS_SIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 642 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
| 643 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; |
| 644 | _set_slave_idlemode(oh, idlemode, &v); |
| 645 | } |
| 646 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 647 | if (sf & SYSC_HAS_MIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 648 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
| 649 | HWMOD_IDLEMODE_NO : HWMOD_IDLEMODE_SMART; |
| 650 | _set_master_standbymode(oh, idlemode, &v); |
| 651 | } |
| 652 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 653 | if (sf & SYSC_HAS_AUTOIDLE) { |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 654 | idlemode = (oh->flags & HWMOD_NO_OCP_AUTOIDLE) ? |
| 655 | 0 : 1; |
| 656 | _set_module_autoidle(oh, idlemode, &v); |
| 657 | } |
| 658 | |
| 659 | /* XXX OCP ENAWAKEUP bit? */ |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 660 | |
Paul Walmsley | a16b1f7 | 2009-12-08 16:34:17 -0700 | [diff] [blame] | 661 | /* |
| 662 | * XXX The clock framework should handle this, by |
| 663 | * calling into this code. But this must wait until the |
| 664 | * clock structures are tagged with omap_hwmod entries |
| 665 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 666 | if ((oh->flags & HWMOD_SET_DEFAULT_CLOCKACT) && |
| 667 | (sf & SYSC_HAS_CLOCKACTIVITY)) |
| 668 | _set_clockactivity(oh, oh->class->sysc->clockact, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 669 | |
| 670 | _write_sysconfig(v, oh); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * _sysc_idle - try to put a module into idle via OCP_SYSCONFIG |
| 675 | * @oh: struct omap_hwmod * |
| 676 | * |
| 677 | * If module is marked as SWSUP_SIDLE, force the module into slave |
| 678 | * idle; otherwise, configure it for smart-idle. If module is marked |
| 679 | * as SWSUP_MSUSPEND, force the module into master standby; otherwise, |
| 680 | * configure it for smart-standby. No return value. |
| 681 | */ |
| 682 | static void _sysc_idle(struct omap_hwmod *oh) |
| 683 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 684 | u8 idlemode, sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 685 | u32 v; |
| 686 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 687 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 688 | return; |
| 689 | |
| 690 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 691 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 692 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 693 | if (sf & SYSC_HAS_SIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 694 | idlemode = (oh->flags & HWMOD_SWSUP_SIDLE) ? |
| 695 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; |
| 696 | _set_slave_idlemode(oh, idlemode, &v); |
| 697 | } |
| 698 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 699 | if (sf & SYSC_HAS_MIDLEMODE) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 700 | idlemode = (oh->flags & HWMOD_SWSUP_MSTANDBY) ? |
| 701 | HWMOD_IDLEMODE_FORCE : HWMOD_IDLEMODE_SMART; |
| 702 | _set_master_standbymode(oh, idlemode, &v); |
| 703 | } |
| 704 | |
| 705 | _write_sysconfig(v, oh); |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * _sysc_shutdown - force a module into idle via OCP_SYSCONFIG |
| 710 | * @oh: struct omap_hwmod * |
| 711 | * |
| 712 | * Force the module into slave idle and master suspend. No return |
| 713 | * value. |
| 714 | */ |
| 715 | static void _sysc_shutdown(struct omap_hwmod *oh) |
| 716 | { |
| 717 | u32 v; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 718 | u8 sf; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 719 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 720 | if (!oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 721 | return; |
| 722 | |
| 723 | v = oh->_sysc_cache; |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 724 | sf = oh->class->sysc->sysc_flags; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 725 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 726 | if (sf & SYSC_HAS_SIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 727 | _set_slave_idlemode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 728 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 729 | if (sf & SYSC_HAS_MIDLEMODE) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 730 | _set_master_standbymode(oh, HWMOD_IDLEMODE_FORCE, &v); |
| 731 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 732 | if (sf & SYSC_HAS_AUTOIDLE) |
Paul Walmsley | 726072e | 2009-12-08 16:34:15 -0700 | [diff] [blame] | 733 | _set_module_autoidle(oh, 1, &v); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 734 | |
| 735 | _write_sysconfig(v, oh); |
| 736 | } |
| 737 | |
| 738 | /** |
| 739 | * _lookup - find an omap_hwmod by name |
| 740 | * @name: find an omap_hwmod by name |
| 741 | * |
| 742 | * Return a pointer to an omap_hwmod by name, or NULL if not found. |
| 743 | * Caller must hold omap_hwmod_mutex. |
| 744 | */ |
| 745 | static struct omap_hwmod *_lookup(const char *name) |
| 746 | { |
| 747 | struct omap_hwmod *oh, *temp_oh; |
| 748 | |
| 749 | oh = NULL; |
| 750 | |
| 751 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 752 | if (!strcmp(name, temp_oh->name)) { |
| 753 | oh = temp_oh; |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | return oh; |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * _init_clocks - clk_get() all clocks associated with this hwmod |
| 763 | * @oh: struct omap_hwmod * |
| 764 | * |
| 765 | * Called by omap_hwmod_late_init() (after omap2_clk_init()). |
| 766 | * Resolves all clock names embedded in the hwmod. Must be called |
| 767 | * with omap_hwmod_mutex held. Returns -EINVAL if the omap_hwmod |
| 768 | * has not yet been registered or if the clocks have already been |
| 769 | * initialized, 0 on success, or a non-zero error on failure. |
| 770 | */ |
| 771 | static int _init_clocks(struct omap_hwmod *oh) |
| 772 | { |
| 773 | int ret = 0; |
| 774 | |
| 775 | if (!oh || (oh->_state != _HWMOD_STATE_REGISTERED)) |
| 776 | return -EINVAL; |
| 777 | |
| 778 | pr_debug("omap_hwmod: %s: looking up clocks\n", oh->name); |
| 779 | |
| 780 | ret |= _init_main_clk(oh); |
| 781 | ret |= _init_interface_clks(oh); |
| 782 | ret |= _init_opt_clks(oh); |
| 783 | |
| 784 | oh->_state = _HWMOD_STATE_CLKS_INITED; |
| 785 | |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * _wait_target_ready - wait for a module to leave slave idle |
| 791 | * @oh: struct omap_hwmod * |
| 792 | * |
| 793 | * Wait for a module @oh to leave slave idle. Returns 0 if the module |
| 794 | * does not have an IDLEST bit or if the module successfully leaves |
| 795 | * slave idle; otherwise, pass along the return value of the |
| 796 | * appropriate *_cm_wait_module_ready() function. |
| 797 | */ |
| 798 | static int _wait_target_ready(struct omap_hwmod *oh) |
| 799 | { |
| 800 | struct omap_hwmod_ocp_if *os; |
| 801 | int ret; |
| 802 | |
| 803 | if (!oh) |
| 804 | return -EINVAL; |
| 805 | |
| 806 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 807 | return 0; |
| 808 | |
| 809 | os = *oh->slaves + oh->_mpu_port_index; |
| 810 | |
| 811 | if (!(os->flags & OCPIF_HAS_IDLEST)) |
| 812 | return 0; |
| 813 | |
| 814 | /* XXX check module SIDLEMODE */ |
| 815 | |
| 816 | /* XXX check clock enable states */ |
| 817 | |
| 818 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 819 | ret = omap2_cm_wait_module_ready(oh->prcm.omap2.module_offs, |
| 820 | oh->prcm.omap2.idlest_reg_id, |
| 821 | oh->prcm.omap2.idlest_idle_bit); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 822 | } else if (cpu_is_omap44xx()) { |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame^] | 823 | ret = omap4_cm_wait_module_ready(oh->prcm.omap4.clkctrl_reg); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 824 | } else { |
| 825 | BUG(); |
| 826 | }; |
| 827 | |
| 828 | return ret; |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * _reset - reset an omap_hwmod |
| 833 | * @oh: struct omap_hwmod * |
| 834 | * |
| 835 | * Resets an omap_hwmod @oh via the OCP_SYSCONFIG bit. hwmod must be |
| 836 | * enabled for this to work. Must be called with omap_hwmod_mutex |
| 837 | * held. Returns -EINVAL if the hwmod cannot be reset this way or if |
| 838 | * the hwmod is in the wrong state, -ETIMEDOUT if the module did not |
| 839 | * reset in time, or 0 upon success. |
| 840 | */ |
| 841 | static int _reset(struct omap_hwmod *oh) |
| 842 | { |
| 843 | u32 r, v; |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 844 | int c = 0; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 845 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 846 | if (!oh->class->sysc || |
| 847 | !(oh->class->sysc->sysc_flags & SYSC_HAS_SOFTRESET) || |
| 848 | (oh->class->sysc->sysc_flags & SYSS_MISSING)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 849 | return -EINVAL; |
| 850 | |
| 851 | /* clocks must be on for this operation */ |
| 852 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
| 853 | WARN(1, "omap_hwmod: %s: reset can only be entered from " |
| 854 | "enabled state\n", oh->name); |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | pr_debug("omap_hwmod: %s: resetting\n", oh->name); |
| 859 | |
| 860 | v = oh->_sysc_cache; |
| 861 | r = _set_softreset(oh, &v); |
| 862 | if (r) |
| 863 | return r; |
| 864 | _write_sysconfig(v, oh); |
| 865 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 866 | omap_test_timeout((omap_hwmod_readl(oh, oh->class->sysc->syss_offs) & |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 867 | SYSS_RESETDONE_MASK), |
| 868 | MAX_MODULE_RESET_WAIT, c); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 869 | |
| 870 | if (c == MAX_MODULE_RESET_WAIT) |
| 871 | WARN(1, "omap_hwmod: %s: failed to reset in %d usec\n", |
| 872 | oh->name, MAX_MODULE_RESET_WAIT); |
| 873 | else |
Paul Walmsley | 02bfc030 | 2009-09-03 20:14:05 +0300 | [diff] [blame] | 874 | pr_debug("omap_hwmod: %s: reset in %d usec\n", oh->name, c); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * XXX add _HWMOD_STATE_WEDGED for modules that don't come back from |
| 878 | * _wait_target_ready() or _reset() |
| 879 | */ |
| 880 | |
| 881 | return (c == MAX_MODULE_RESET_WAIT) ? -ETIMEDOUT : 0; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * _enable - enable an omap_hwmod |
| 886 | * @oh: struct omap_hwmod * |
| 887 | * |
| 888 | * Enables an omap_hwmod @oh such that the MPU can access the hwmod's |
| 889 | * register target. Must be called with omap_hwmod_mutex held. |
| 890 | * Returns -EINVAL if the hwmod is in the wrong state or passes along |
| 891 | * the return value of _wait_target_ready(). |
| 892 | */ |
| 893 | static int _enable(struct omap_hwmod *oh) |
| 894 | { |
| 895 | int r; |
| 896 | |
| 897 | if (oh->_state != _HWMOD_STATE_INITIALIZED && |
| 898 | oh->_state != _HWMOD_STATE_IDLE && |
| 899 | oh->_state != _HWMOD_STATE_DISABLED) { |
| 900 | WARN(1, "omap_hwmod: %s: enabled state can only be entered " |
| 901 | "from initialized, idle, or disabled state\n", oh->name); |
| 902 | return -EINVAL; |
| 903 | } |
| 904 | |
| 905 | pr_debug("omap_hwmod: %s: enabling\n", oh->name); |
| 906 | |
| 907 | /* XXX mux balls */ |
| 908 | |
| 909 | _add_initiator_dep(oh, mpu_oh); |
| 910 | _enable_clocks(oh); |
| 911 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 912 | r = _wait_target_ready(oh); |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame^] | 913 | if (!r) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 914 | oh->_state = _HWMOD_STATE_ENABLED; |
| 915 | |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame^] | 916 | /* Access the sysconfig only if the target is ready */ |
| 917 | if (oh->class->sysc) { |
| 918 | if (!(oh->_int_flags & _HWMOD_SYSCONFIG_LOADED)) |
| 919 | _update_sysc_cache(oh); |
| 920 | _sysc_enable(oh); |
| 921 | } |
| 922 | } else { |
| 923 | pr_debug("omap_hwmod: %s: _wait_target_ready: %d\n", |
| 924 | oh->name, r); |
| 925 | } |
| 926 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 927 | return r; |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * _idle - idle an omap_hwmod |
| 932 | * @oh: struct omap_hwmod * |
| 933 | * |
| 934 | * Idles an omap_hwmod @oh. This should be called once the hwmod has |
| 935 | * no further work. Returns -EINVAL if the hwmod is in the wrong |
| 936 | * state or returns 0. |
| 937 | */ |
| 938 | static int _idle(struct omap_hwmod *oh) |
| 939 | { |
| 940 | if (oh->_state != _HWMOD_STATE_ENABLED) { |
| 941 | WARN(1, "omap_hwmod: %s: idle state can only be entered from " |
| 942 | "enabled state\n", oh->name); |
| 943 | return -EINVAL; |
| 944 | } |
| 945 | |
| 946 | pr_debug("omap_hwmod: %s: idling\n", oh->name); |
| 947 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 948 | if (oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 949 | _sysc_idle(oh); |
| 950 | _del_initiator_dep(oh, mpu_oh); |
| 951 | _disable_clocks(oh); |
| 952 | |
| 953 | oh->_state = _HWMOD_STATE_IDLE; |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * _shutdown - shutdown an omap_hwmod |
| 960 | * @oh: struct omap_hwmod * |
| 961 | * |
| 962 | * Shut down an omap_hwmod @oh. This should be called when the driver |
| 963 | * used for the hwmod is removed or unloaded or if the driver is not |
| 964 | * used by the system. Returns -EINVAL if the hwmod is in the wrong |
| 965 | * state or returns 0. |
| 966 | */ |
| 967 | static int _shutdown(struct omap_hwmod *oh) |
| 968 | { |
| 969 | if (oh->_state != _HWMOD_STATE_IDLE && |
| 970 | oh->_state != _HWMOD_STATE_ENABLED) { |
| 971 | WARN(1, "omap_hwmod: %s: disabled state can only be entered " |
| 972 | "from idle, or enabled state\n", oh->name); |
| 973 | return -EINVAL; |
| 974 | } |
| 975 | |
| 976 | pr_debug("omap_hwmod: %s: disabling\n", oh->name); |
| 977 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 978 | if (oh->class->sysc) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 979 | _sysc_shutdown(oh); |
| 980 | _del_initiator_dep(oh, mpu_oh); |
| 981 | /* XXX what about the other system initiators here? DMA, tesla, d2d */ |
| 982 | _disable_clocks(oh); |
| 983 | /* XXX Should this code also force-disable the optional clocks? */ |
| 984 | |
| 985 | /* XXX mux any associated balls to safe mode */ |
| 986 | |
| 987 | oh->_state = _HWMOD_STATE_DISABLED; |
| 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
| 992 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 993 | * _setup - do initial configuration of omap_hwmod |
| 994 | * @oh: struct omap_hwmod * |
| 995 | * |
| 996 | * Writes the CLOCKACTIVITY bits @clockact to the hwmod @oh |
| 997 | * OCP_SYSCONFIG register. Must be called with omap_hwmod_mutex |
| 998 | * held. Returns -EINVAL if the hwmod is in the wrong state or returns |
| 999 | * 0. |
| 1000 | */ |
| 1001 | static int _setup(struct omap_hwmod *oh) |
| 1002 | { |
| 1003 | struct omap_hwmod_ocp_if *os; |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame^] | 1004 | int i, r; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1005 | |
| 1006 | if (!oh) |
| 1007 | return -EINVAL; |
| 1008 | |
| 1009 | /* Set iclk autoidle mode */ |
| 1010 | if (oh->slaves_cnt > 0) { |
| 1011 | for (i = 0, os = *oh->slaves; i < oh->slaves_cnt; i++, os++) { |
| 1012 | struct clk *c = os->_clk; |
| 1013 | |
| 1014 | if (!c || IS_ERR(c)) |
| 1015 | continue; |
| 1016 | |
| 1017 | if (os->flags & OCPIF_SWSUP_IDLE) { |
| 1018 | /* XXX omap_iclk_deny_idle(c); */ |
| 1019 | } else { |
| 1020 | /* XXX omap_iclk_allow_idle(c); */ |
| 1021 | clk_enable(c); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | oh->_state = _HWMOD_STATE_INITIALIZED; |
| 1027 | |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame^] | 1028 | r = _enable(oh); |
| 1029 | if (r) { |
| 1030 | pr_warning("omap_hwmod: %s: cannot be enabled (%d)\n", |
| 1031 | oh->name, oh->_state); |
| 1032 | return 0; |
| 1033 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1034 | |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1035 | if (!(oh->flags & HWMOD_INIT_NO_RESET)) { |
| 1036 | /* |
| 1037 | * XXX Do the OCP_SYSCONFIG bits need to be |
| 1038 | * reprogrammed after a reset? If not, then this can |
| 1039 | * be removed. If they do, then probably the |
| 1040 | * _enable() function should be split to avoid the |
| 1041 | * rewrite of the OCP_SYSCONFIG register. |
| 1042 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1043 | if (oh->class->sysc) { |
Paul Walmsley | b835d01 | 2009-12-08 16:34:14 -0700 | [diff] [blame] | 1044 | _update_sysc_cache(oh); |
| 1045 | _sysc_enable(oh); |
| 1046 | } |
| 1047 | } |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1048 | |
| 1049 | if (!(oh->flags & HWMOD_INIT_NO_IDLE)) |
| 1050 | _idle(oh); |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | /* Public functions */ |
| 1058 | |
| 1059 | u32 omap_hwmod_readl(struct omap_hwmod *oh, u16 reg_offs) |
| 1060 | { |
| 1061 | return __raw_readl(oh->_rt_va + reg_offs); |
| 1062 | } |
| 1063 | |
| 1064 | void omap_hwmod_writel(u32 v, struct omap_hwmod *oh, u16 reg_offs) |
| 1065 | { |
| 1066 | __raw_writel(v, oh->_rt_va + reg_offs); |
| 1067 | } |
| 1068 | |
Kevin Hilman | 46273e6 | 2010-01-26 20:13:03 -0700 | [diff] [blame] | 1069 | int omap_hwmod_set_slave_idlemode(struct omap_hwmod *oh, u8 idlemode) |
| 1070 | { |
| 1071 | u32 v; |
| 1072 | int retval = 0; |
| 1073 | |
| 1074 | if (!oh) |
| 1075 | return -EINVAL; |
| 1076 | |
| 1077 | v = oh->_sysc_cache; |
| 1078 | |
| 1079 | retval = _set_slave_idlemode(oh, idlemode, &v); |
| 1080 | if (!retval) |
| 1081 | _write_sysconfig(v, oh); |
| 1082 | |
| 1083 | return retval; |
| 1084 | } |
| 1085 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1086 | /** |
| 1087 | * omap_hwmod_register - register a struct omap_hwmod |
| 1088 | * @oh: struct omap_hwmod * |
| 1089 | * |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1090 | * Registers the omap_hwmod @oh. Returns -EEXIST if an omap_hwmod |
| 1091 | * already has been registered by the same name; -EINVAL if the |
| 1092 | * omap_hwmod is in the wrong state, if @oh is NULL, if the |
| 1093 | * omap_hwmod's class field is NULL; if the omap_hwmod is missing a |
| 1094 | * name, or if the omap_hwmod's class is missing a name; or 0 upon |
| 1095 | * success. |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1096 | * |
| 1097 | * XXX The data should be copied into bootmem, so the original data |
| 1098 | * should be marked __initdata and freed after init. This would allow |
| 1099 | * unneeded omap_hwmods to be freed on multi-OMAP configurations. Note |
| 1100 | * that the copy process would be relatively complex due to the large number |
| 1101 | * of substructures. |
| 1102 | */ |
| 1103 | int omap_hwmod_register(struct omap_hwmod *oh) |
| 1104 | { |
| 1105 | int ret, ms_id; |
| 1106 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1107 | if (!oh || !oh->name || !oh->class || !oh->class->name || |
| 1108 | (oh->_state != _HWMOD_STATE_UNKNOWN)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1109 | return -EINVAL; |
| 1110 | |
| 1111 | mutex_lock(&omap_hwmod_mutex); |
| 1112 | |
| 1113 | pr_debug("omap_hwmod: %s: registering\n", oh->name); |
| 1114 | |
| 1115 | if (_lookup(oh->name)) { |
| 1116 | ret = -EEXIST; |
| 1117 | goto ohr_unlock; |
| 1118 | } |
| 1119 | |
| 1120 | ms_id = _find_mpu_port_index(oh); |
| 1121 | if (!IS_ERR_VALUE(ms_id)) { |
| 1122 | oh->_mpu_port_index = ms_id; |
| 1123 | oh->_rt_va = _find_mpu_rt_base(oh, oh->_mpu_port_index); |
| 1124 | } else { |
| 1125 | oh->_int_flags |= _HWMOD_NO_MPU_PORT; |
| 1126 | } |
| 1127 | |
| 1128 | list_add_tail(&oh->node, &omap_hwmod_list); |
| 1129 | |
| 1130 | oh->_state = _HWMOD_STATE_REGISTERED; |
| 1131 | |
| 1132 | ret = 0; |
| 1133 | |
| 1134 | ohr_unlock: |
| 1135 | mutex_unlock(&omap_hwmod_mutex); |
| 1136 | return ret; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * omap_hwmod_lookup - look up a registered omap_hwmod by name |
| 1141 | * @name: name of the omap_hwmod to look up |
| 1142 | * |
| 1143 | * Given a @name of an omap_hwmod, return a pointer to the registered |
| 1144 | * struct omap_hwmod *, or NULL upon error. |
| 1145 | */ |
| 1146 | struct omap_hwmod *omap_hwmod_lookup(const char *name) |
| 1147 | { |
| 1148 | struct omap_hwmod *oh; |
| 1149 | |
| 1150 | if (!name) |
| 1151 | return NULL; |
| 1152 | |
| 1153 | mutex_lock(&omap_hwmod_mutex); |
| 1154 | oh = _lookup(name); |
| 1155 | mutex_unlock(&omap_hwmod_mutex); |
| 1156 | |
| 1157 | return oh; |
| 1158 | } |
| 1159 | |
| 1160 | /** |
| 1161 | * omap_hwmod_for_each - call function for each registered omap_hwmod |
| 1162 | * @fn: pointer to a callback function |
| 1163 | * |
| 1164 | * Call @fn for each registered omap_hwmod, passing @data to each |
| 1165 | * function. @fn must return 0 for success or any other value for |
| 1166 | * failure. If @fn returns non-zero, the iteration across omap_hwmods |
| 1167 | * will stop and the non-zero return value will be passed to the |
| 1168 | * caller of omap_hwmod_for_each(). @fn is called with |
| 1169 | * omap_hwmod_for_each() held. |
| 1170 | */ |
| 1171 | int omap_hwmod_for_each(int (*fn)(struct omap_hwmod *oh)) |
| 1172 | { |
| 1173 | struct omap_hwmod *temp_oh; |
| 1174 | int ret; |
| 1175 | |
| 1176 | if (!fn) |
| 1177 | return -EINVAL; |
| 1178 | |
| 1179 | mutex_lock(&omap_hwmod_mutex); |
| 1180 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 1181 | ret = (*fn)(temp_oh); |
| 1182 | if (ret) |
| 1183 | break; |
| 1184 | } |
| 1185 | mutex_unlock(&omap_hwmod_mutex); |
| 1186 | |
| 1187 | return ret; |
| 1188 | } |
| 1189 | |
| 1190 | |
| 1191 | /** |
| 1192 | * omap_hwmod_init - init omap_hwmod code and register hwmods |
| 1193 | * @ohs: pointer to an array of omap_hwmods to register |
| 1194 | * |
| 1195 | * Intended to be called early in boot before the clock framework is |
| 1196 | * initialized. If @ohs is not null, will register all omap_hwmods |
| 1197 | * listed in @ohs that are valid for this chip. Returns -EINVAL if |
| 1198 | * omap_hwmod_init() has already been called or 0 otherwise. |
| 1199 | */ |
| 1200 | int omap_hwmod_init(struct omap_hwmod **ohs) |
| 1201 | { |
| 1202 | struct omap_hwmod *oh; |
| 1203 | int r; |
| 1204 | |
| 1205 | if (inited) |
| 1206 | return -EINVAL; |
| 1207 | |
| 1208 | inited = 1; |
| 1209 | |
| 1210 | if (!ohs) |
| 1211 | return 0; |
| 1212 | |
| 1213 | oh = *ohs; |
| 1214 | while (oh) { |
| 1215 | if (omap_chip_is(oh->omap_chip)) { |
| 1216 | r = omap_hwmod_register(oh); |
| 1217 | WARN(r, "omap_hwmod: %s: omap_hwmod_register returned " |
| 1218 | "%d\n", oh->name, r); |
| 1219 | } |
| 1220 | oh = *++ohs; |
| 1221 | } |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * omap_hwmod_late_init - do some post-clock framework initialization |
| 1228 | * |
| 1229 | * Must be called after omap2_clk_init(). Resolves the struct clk names |
| 1230 | * to struct clk pointers for each registered omap_hwmod. Also calls |
| 1231 | * _setup() on each hwmod. Returns 0. |
| 1232 | */ |
| 1233 | int omap_hwmod_late_init(void) |
| 1234 | { |
| 1235 | int r; |
| 1236 | |
| 1237 | /* XXX check return value */ |
| 1238 | r = omap_hwmod_for_each(_init_clocks); |
| 1239 | WARN(r, "omap_hwmod: omap_hwmod_late_init(): _init_clocks failed\n"); |
| 1240 | |
| 1241 | mpu_oh = omap_hwmod_lookup(MPU_INITIATOR_NAME); |
| 1242 | WARN(!mpu_oh, "omap_hwmod: could not find MPU initiator hwmod %s\n", |
| 1243 | MPU_INITIATOR_NAME); |
| 1244 | |
| 1245 | omap_hwmod_for_each(_setup); |
| 1246 | |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * omap_hwmod_unregister - unregister an omap_hwmod |
| 1252 | * @oh: struct omap_hwmod * |
| 1253 | * |
| 1254 | * Unregisters a previously-registered omap_hwmod @oh. There's probably |
| 1255 | * no use case for this, so it is likely to be removed in a later version. |
| 1256 | * |
| 1257 | * XXX Free all of the bootmem-allocated structures here when that is |
| 1258 | * implemented. Make it clear that core code is the only code that is |
| 1259 | * expected to unregister modules. |
| 1260 | */ |
| 1261 | int omap_hwmod_unregister(struct omap_hwmod *oh) |
| 1262 | { |
| 1263 | if (!oh) |
| 1264 | return -EINVAL; |
| 1265 | |
| 1266 | pr_debug("omap_hwmod: %s: unregistering\n", oh->name); |
| 1267 | |
| 1268 | mutex_lock(&omap_hwmod_mutex); |
Tony Lindgren | 986a13f | 2009-10-19 15:25:22 -0700 | [diff] [blame] | 1269 | iounmap(oh->_rt_va); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1270 | list_del(&oh->node); |
| 1271 | mutex_unlock(&omap_hwmod_mutex); |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | /** |
| 1277 | * omap_hwmod_enable - enable an omap_hwmod |
| 1278 | * @oh: struct omap_hwmod * |
| 1279 | * |
| 1280 | * Enable an omap_hwomd @oh. Intended to be called by omap_device_enable(). |
| 1281 | * Returns -EINVAL on error or passes along the return value from _enable(). |
| 1282 | */ |
| 1283 | int omap_hwmod_enable(struct omap_hwmod *oh) |
| 1284 | { |
| 1285 | int r; |
| 1286 | |
| 1287 | if (!oh) |
| 1288 | return -EINVAL; |
| 1289 | |
| 1290 | mutex_lock(&omap_hwmod_mutex); |
| 1291 | r = _enable(oh); |
| 1292 | mutex_unlock(&omap_hwmod_mutex); |
| 1293 | |
| 1294 | return r; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * omap_hwmod_idle - idle an omap_hwmod |
| 1299 | * @oh: struct omap_hwmod * |
| 1300 | * |
| 1301 | * Idle an omap_hwomd @oh. Intended to be called by omap_device_idle(). |
| 1302 | * Returns -EINVAL on error or passes along the return value from _idle(). |
| 1303 | */ |
| 1304 | int omap_hwmod_idle(struct omap_hwmod *oh) |
| 1305 | { |
| 1306 | if (!oh) |
| 1307 | return -EINVAL; |
| 1308 | |
| 1309 | mutex_lock(&omap_hwmod_mutex); |
| 1310 | _idle(oh); |
| 1311 | mutex_unlock(&omap_hwmod_mutex); |
| 1312 | |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * omap_hwmod_shutdown - shutdown an omap_hwmod |
| 1318 | * @oh: struct omap_hwmod * |
| 1319 | * |
| 1320 | * Shutdown an omap_hwomd @oh. Intended to be called by |
| 1321 | * omap_device_shutdown(). Returns -EINVAL on error or passes along |
| 1322 | * the return value from _shutdown(). |
| 1323 | */ |
| 1324 | int omap_hwmod_shutdown(struct omap_hwmod *oh) |
| 1325 | { |
| 1326 | if (!oh) |
| 1327 | return -EINVAL; |
| 1328 | |
| 1329 | mutex_lock(&omap_hwmod_mutex); |
| 1330 | _shutdown(oh); |
| 1331 | mutex_unlock(&omap_hwmod_mutex); |
| 1332 | |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
| 1336 | /** |
| 1337 | * omap_hwmod_enable_clocks - enable main_clk, all interface clocks |
| 1338 | * @oh: struct omap_hwmod *oh |
| 1339 | * |
| 1340 | * Intended to be called by the omap_device code. |
| 1341 | */ |
| 1342 | int omap_hwmod_enable_clocks(struct omap_hwmod *oh) |
| 1343 | { |
| 1344 | mutex_lock(&omap_hwmod_mutex); |
| 1345 | _enable_clocks(oh); |
| 1346 | mutex_unlock(&omap_hwmod_mutex); |
| 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
| 1352 | * omap_hwmod_disable_clocks - disable main_clk, all interface clocks |
| 1353 | * @oh: struct omap_hwmod *oh |
| 1354 | * |
| 1355 | * Intended to be called by the omap_device code. |
| 1356 | */ |
| 1357 | int omap_hwmod_disable_clocks(struct omap_hwmod *oh) |
| 1358 | { |
| 1359 | mutex_lock(&omap_hwmod_mutex); |
| 1360 | _disable_clocks(oh); |
| 1361 | mutex_unlock(&omap_hwmod_mutex); |
| 1362 | |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * omap_hwmod_ocp_barrier - wait for posted writes against the hwmod to complete |
| 1368 | * @oh: struct omap_hwmod *oh |
| 1369 | * |
| 1370 | * Intended to be called by drivers and core code when all posted |
| 1371 | * writes to a device must complete before continuing further |
| 1372 | * execution (for example, after clearing some device IRQSTATUS |
| 1373 | * register bits) |
| 1374 | * |
| 1375 | * XXX what about targets with multiple OCP threads? |
| 1376 | */ |
| 1377 | void omap_hwmod_ocp_barrier(struct omap_hwmod *oh) |
| 1378 | { |
| 1379 | BUG_ON(!oh); |
| 1380 | |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1381 | if (!oh->class->sysc || !oh->class->sysc->sysc_flags) { |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1382 | WARN(1, "omap_device: %s: OCP barrier impossible due to " |
| 1383 | "device configuration\n", oh->name); |
| 1384 | return; |
| 1385 | } |
| 1386 | |
| 1387 | /* |
| 1388 | * Forces posted writes to complete on the OCP thread handling |
| 1389 | * register writes |
| 1390 | */ |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1391 | omap_hwmod_readl(oh, oh->class->sysc->sysc_offs); |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
| 1395 | * omap_hwmod_reset - reset the hwmod |
| 1396 | * @oh: struct omap_hwmod * |
| 1397 | * |
| 1398 | * Under some conditions, a driver may wish to reset the entire device. |
| 1399 | * Called from omap_device code. Returns -EINVAL on error or passes along |
| 1400 | * the return value from _reset()/_enable(). |
| 1401 | */ |
| 1402 | int omap_hwmod_reset(struct omap_hwmod *oh) |
| 1403 | { |
| 1404 | int r; |
| 1405 | |
| 1406 | if (!oh || !(oh->_state & _HWMOD_STATE_ENABLED)) |
| 1407 | return -EINVAL; |
| 1408 | |
| 1409 | mutex_lock(&omap_hwmod_mutex); |
| 1410 | r = _reset(oh); |
| 1411 | if (!r) |
| 1412 | r = _enable(oh); |
| 1413 | mutex_unlock(&omap_hwmod_mutex); |
| 1414 | |
| 1415 | return r; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * omap_hwmod_count_resources - count number of struct resources needed by hwmod |
| 1420 | * @oh: struct omap_hwmod * |
| 1421 | * @res: pointer to the first element of an array of struct resource to fill |
| 1422 | * |
| 1423 | * Count the number of struct resource array elements necessary to |
| 1424 | * contain omap_hwmod @oh resources. Intended to be called by code |
| 1425 | * that registers omap_devices. Intended to be used to determine the |
| 1426 | * size of a dynamically-allocated struct resource array, before |
| 1427 | * calling omap_hwmod_fill_resources(). Returns the number of struct |
| 1428 | * resource array elements needed. |
| 1429 | * |
| 1430 | * XXX This code is not optimized. It could attempt to merge adjacent |
| 1431 | * resource IDs. |
| 1432 | * |
| 1433 | */ |
| 1434 | int omap_hwmod_count_resources(struct omap_hwmod *oh) |
| 1435 | { |
| 1436 | int ret, i; |
| 1437 | |
| 1438 | ret = oh->mpu_irqs_cnt + oh->sdma_chs_cnt; |
| 1439 | |
| 1440 | for (i = 0; i < oh->slaves_cnt; i++) |
| 1441 | ret += (*oh->slaves + i)->addr_cnt; |
| 1442 | |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | /** |
| 1447 | * omap_hwmod_fill_resources - fill struct resource array with hwmod data |
| 1448 | * @oh: struct omap_hwmod * |
| 1449 | * @res: pointer to the first element of an array of struct resource to fill |
| 1450 | * |
| 1451 | * Fill the struct resource array @res with resource data from the |
| 1452 | * omap_hwmod @oh. Intended to be called by code that registers |
| 1453 | * omap_devices. See also omap_hwmod_count_resources(). Returns the |
| 1454 | * number of array elements filled. |
| 1455 | */ |
| 1456 | int omap_hwmod_fill_resources(struct omap_hwmod *oh, struct resource *res) |
| 1457 | { |
| 1458 | int i, j; |
| 1459 | int r = 0; |
| 1460 | |
| 1461 | /* For each IRQ, DMA, memory area, fill in array.*/ |
| 1462 | |
| 1463 | for (i = 0; i < oh->mpu_irqs_cnt; i++) { |
Paul Walmsley | 718bfd7 | 2009-12-08 16:34:16 -0700 | [diff] [blame] | 1464 | (res + r)->name = (oh->mpu_irqs + i)->name; |
| 1465 | (res + r)->start = (oh->mpu_irqs + i)->irq; |
| 1466 | (res + r)->end = (oh->mpu_irqs + i)->irq; |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1467 | (res + r)->flags = IORESOURCE_IRQ; |
| 1468 | r++; |
| 1469 | } |
| 1470 | |
| 1471 | for (i = 0; i < oh->sdma_chs_cnt; i++) { |
| 1472 | (res + r)->name = (oh->sdma_chs + i)->name; |
| 1473 | (res + r)->start = (oh->sdma_chs + i)->dma_ch; |
| 1474 | (res + r)->end = (oh->sdma_chs + i)->dma_ch; |
| 1475 | (res + r)->flags = IORESOURCE_DMA; |
| 1476 | r++; |
| 1477 | } |
| 1478 | |
| 1479 | for (i = 0; i < oh->slaves_cnt; i++) { |
| 1480 | struct omap_hwmod_ocp_if *os; |
| 1481 | |
| 1482 | os = *oh->slaves + i; |
| 1483 | |
| 1484 | for (j = 0; j < os->addr_cnt; j++) { |
| 1485 | (res + r)->start = (os->addr + j)->pa_start; |
| 1486 | (res + r)->end = (os->addr + j)->pa_end; |
| 1487 | (res + r)->flags = IORESOURCE_MEM; |
| 1488 | r++; |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | return r; |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * omap_hwmod_get_pwrdm - return pointer to this module's main powerdomain |
| 1497 | * @oh: struct omap_hwmod * |
| 1498 | * |
| 1499 | * Return the powerdomain pointer associated with the OMAP module |
| 1500 | * @oh's main clock. If @oh does not have a main clk, return the |
| 1501 | * powerdomain associated with the interface clock associated with the |
| 1502 | * module's MPU port. (XXX Perhaps this should use the SDMA port |
| 1503 | * instead?) Returns NULL on error, or a struct powerdomain * on |
| 1504 | * success. |
| 1505 | */ |
| 1506 | struct powerdomain *omap_hwmod_get_pwrdm(struct omap_hwmod *oh) |
| 1507 | { |
| 1508 | struct clk *c; |
| 1509 | |
| 1510 | if (!oh) |
| 1511 | return NULL; |
| 1512 | |
| 1513 | if (oh->_clk) { |
| 1514 | c = oh->_clk; |
| 1515 | } else { |
| 1516 | if (oh->_int_flags & _HWMOD_NO_MPU_PORT) |
| 1517 | return NULL; |
| 1518 | c = oh->slaves[oh->_mpu_port_index]->_clk; |
| 1519 | } |
| 1520 | |
Thara Gopinath | d5647c1 | 2010-03-31 04:16:29 -0600 | [diff] [blame] | 1521 | if (!c->clkdm) |
| 1522 | return NULL; |
| 1523 | |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1524 | return c->clkdm->pwrdm.ptr; |
| 1525 | |
| 1526 | } |
| 1527 | |
| 1528 | /** |
| 1529 | * omap_hwmod_add_initiator_dep - add sleepdep from @init_oh to @oh |
| 1530 | * @oh: struct omap_hwmod * |
| 1531 | * @init_oh: struct omap_hwmod * (initiator) |
| 1532 | * |
| 1533 | * Add a sleep dependency between the initiator @init_oh and @oh. |
| 1534 | * Intended to be called by DSP/Bridge code via platform_data for the |
| 1535 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge |
| 1536 | * code needs to add/del initiator dependencies dynamically |
| 1537 | * before/after accessing a device. Returns the return value from |
| 1538 | * _add_initiator_dep(). |
| 1539 | * |
| 1540 | * XXX Keep a usecount in the clockdomain code |
| 1541 | */ |
| 1542 | int omap_hwmod_add_initiator_dep(struct omap_hwmod *oh, |
| 1543 | struct omap_hwmod *init_oh) |
| 1544 | { |
| 1545 | return _add_initiator_dep(oh, init_oh); |
| 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * XXX what about functions for drivers to save/restore ocp_sysconfig |
| 1550 | * for context save/restore operations? |
| 1551 | */ |
| 1552 | |
| 1553 | /** |
| 1554 | * omap_hwmod_del_initiator_dep - remove sleepdep from @init_oh to @oh |
| 1555 | * @oh: struct omap_hwmod * |
| 1556 | * @init_oh: struct omap_hwmod * (initiator) |
| 1557 | * |
| 1558 | * Remove a sleep dependency between the initiator @init_oh and @oh. |
| 1559 | * Intended to be called by DSP/Bridge code via platform_data for the |
| 1560 | * DSP case; and by the DMA code in the sDMA case. DMA code, *Bridge |
| 1561 | * code needs to add/del initiator dependencies dynamically |
| 1562 | * before/after accessing a device. Returns the return value from |
| 1563 | * _del_initiator_dep(). |
| 1564 | * |
| 1565 | * XXX Keep a usecount in the clockdomain code |
| 1566 | */ |
| 1567 | int omap_hwmod_del_initiator_dep(struct omap_hwmod *oh, |
| 1568 | struct omap_hwmod *init_oh) |
| 1569 | { |
| 1570 | return _del_initiator_dep(oh, init_oh); |
| 1571 | } |
| 1572 | |
| 1573 | /** |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1574 | * omap_hwmod_enable_wakeup - allow device to wake up the system |
| 1575 | * @oh: struct omap_hwmod * |
| 1576 | * |
| 1577 | * Sets the module OCP socket ENAWAKEUP bit to allow the module to |
| 1578 | * send wakeups to the PRCM. Eventually this should sets PRCM wakeup |
| 1579 | * registers to cause the PRCM to receive wakeup events from the |
| 1580 | * module. Does not set any wakeup routing registers beyond this |
| 1581 | * point - if the module is to wake up any other module or subsystem, |
| 1582 | * that must be set separately. Called by omap_device code. Returns |
| 1583 | * -EINVAL on error or 0 upon success. |
| 1584 | */ |
| 1585 | int omap_hwmod_enable_wakeup(struct omap_hwmod *oh) |
| 1586 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1587 | if (!oh->class->sysc || |
| 1588 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1589 | return -EINVAL; |
| 1590 | |
| 1591 | mutex_lock(&omap_hwmod_mutex); |
| 1592 | _enable_wakeup(oh); |
| 1593 | mutex_unlock(&omap_hwmod_mutex); |
| 1594 | |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * omap_hwmod_disable_wakeup - prevent device from waking the system |
| 1600 | * @oh: struct omap_hwmod * |
| 1601 | * |
| 1602 | * Clears the module OCP socket ENAWAKEUP bit to prevent the module |
| 1603 | * from sending wakeups to the PRCM. Eventually this should clear |
| 1604 | * PRCM wakeup registers to cause the PRCM to ignore wakeup events |
| 1605 | * from the module. Does not set any wakeup routing registers beyond |
| 1606 | * this point - if the module is to wake up any other module or |
| 1607 | * subsystem, that must be set separately. Called by omap_device |
| 1608 | * code. Returns -EINVAL on error or 0 upon success. |
| 1609 | */ |
| 1610 | int omap_hwmod_disable_wakeup(struct omap_hwmod *oh) |
| 1611 | { |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1612 | if (!oh->class->sysc || |
| 1613 | !(oh->class->sysc->sysc_flags & SYSC_HAS_ENAWAKEUP)) |
Paul Walmsley | 63c8523 | 2009-09-03 20:14:03 +0300 | [diff] [blame] | 1614 | return -EINVAL; |
| 1615 | |
| 1616 | mutex_lock(&omap_hwmod_mutex); |
| 1617 | _disable_wakeup(oh); |
| 1618 | mutex_unlock(&omap_hwmod_mutex); |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
Paul Walmsley | 43b4099 | 2010-02-22 22:09:34 -0700 | [diff] [blame] | 1622 | |
| 1623 | /** |
| 1624 | * omap_hwmod_for_each_by_class - call @fn for each hwmod of class @classname |
| 1625 | * @classname: struct omap_hwmod_class name to search for |
| 1626 | * @fn: callback function pointer to call for each hwmod in class @classname |
| 1627 | * @user: arbitrary context data to pass to the callback function |
| 1628 | * |
| 1629 | * For each omap_hwmod of class @classname, call @fn. Takes |
| 1630 | * omap_hwmod_mutex to prevent the hwmod list from changing during the |
| 1631 | * iteration. If the callback function returns something other than |
| 1632 | * zero, the iterator is terminated, and the callback function's return |
| 1633 | * value is passed back to the caller. Returns 0 upon success, -EINVAL |
| 1634 | * if @classname or @fn are NULL, or passes back the error code from @fn. |
| 1635 | */ |
| 1636 | int omap_hwmod_for_each_by_class(const char *classname, |
| 1637 | int (*fn)(struct omap_hwmod *oh, |
| 1638 | void *user), |
| 1639 | void *user) |
| 1640 | { |
| 1641 | struct omap_hwmod *temp_oh; |
| 1642 | int ret = 0; |
| 1643 | |
| 1644 | if (!classname || !fn) |
| 1645 | return -EINVAL; |
| 1646 | |
| 1647 | pr_debug("omap_hwmod: %s: looking for modules of class %s\n", |
| 1648 | __func__, classname); |
| 1649 | |
| 1650 | mutex_lock(&omap_hwmod_mutex); |
| 1651 | |
| 1652 | list_for_each_entry(temp_oh, &omap_hwmod_list, node) { |
| 1653 | if (!strcmp(temp_oh->class->name, classname)) { |
| 1654 | pr_debug("omap_hwmod: %s: %s: calling callback fn\n", |
| 1655 | __func__, temp_oh->name); |
| 1656 | ret = (*fn)(temp_oh, user); |
| 1657 | if (ret) |
| 1658 | break; |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | mutex_unlock(&omap_hwmod_mutex); |
| 1663 | |
| 1664 | if (ret) |
| 1665 | pr_debug("omap_hwmod: %s: iterator terminated early: %d\n", |
| 1666 | __func__, ret); |
| 1667 | |
| 1668 | return ret; |
| 1669 | } |
| 1670 | |