Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2/3 CM module functions |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Paul Walmsley |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/io.h> |
| 21 | |
| 22 | #include <asm/atomic.h> |
| 23 | |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 24 | #include <plat/common.h> |
| 25 | |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 26 | #include "cm.h" |
| 27 | #include "cm-regbits-24xx.h" |
| 28 | #include "cm-regbits-34xx.h" |
| 29 | |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 30 | static const u8 cm_idlest_offs[] = { |
| 31 | CM_IDLEST1, CM_IDLEST2, OMAP2430_CM_IDLEST3 |
| 32 | }; |
| 33 | |
| 34 | /** |
| 35 | * omap2_cm_wait_idlest_ready - wait for a module to leave idle or standby |
| 36 | * @prcm_mod: PRCM module offset |
| 37 | * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3) |
| 38 | * @idlest_shift: shift of the bit in the CM_IDLEST* register to check |
| 39 | * |
| 40 | * XXX document |
| 41 | */ |
| 42 | int omap2_cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift) |
| 43 | { |
| 44 | int ena = 0, i = 0; |
| 45 | u8 cm_idlest_reg; |
| 46 | u32 mask; |
| 47 | |
| 48 | if (!idlest_id || (idlest_id > ARRAY_SIZE(cm_idlest_offs))) |
| 49 | return -EINVAL; |
| 50 | |
| 51 | cm_idlest_reg = cm_idlest_offs[idlest_id - 1]; |
| 52 | |
Kevin Hilman | 6405616 | 2010-07-26 16:34:28 -0600 | [diff] [blame^] | 53 | mask = 1 << idlest_shift; |
| 54 | |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 55 | if (cpu_is_omap24xx()) |
Kevin Hilman | 6405616 | 2010-07-26 16:34:28 -0600 | [diff] [blame^] | 56 | ena = mask; |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 57 | else if (cpu_is_omap34xx()) |
| 58 | ena = 0; |
| 59 | else |
| 60 | BUG(); |
| 61 | |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 62 | /* XXX should be OMAP2 CM */ |
Paul Walmsley | 6f8b7ff | 2009-12-08 16:33:16 -0700 | [diff] [blame] | 63 | omap_test_timeout(((cm_read_mod_reg(prcm_mod, cm_idlest_reg) & mask) == ena), |
| 64 | MAX_MODULE_READY_TIME, i); |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 65 | |
| 66 | return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY; |
| 67 | } |
| 68 | |