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