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