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