Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP4 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 | |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 24 | #include <plat/common.h> |
| 25 | |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 26 | #include "cm.h" |
Benoit Cousson | d9e6625 | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 27 | #include "cm-regbits-44xx.h" |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 28 | |
| 29 | /** |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 30 | * omap4_cm_wait_module_ready - wait for a module to be in 'func' state |
| 31 | * @clkctrl_reg: CLKCTRL module address |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 32 | * |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 33 | * Wait for the module IDLEST to be functional. If the idle state is in any |
| 34 | * the non functional state (trans, idle or disabled), module and thus the |
| 35 | * sysconfig cannot be accessed and will probably lead to an "imprecise |
| 36 | * external abort" |
| 37 | * |
| 38 | * Module idle state: |
| 39 | * 0x0 func: Module is fully functional, including OCP |
| 40 | * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep |
| 41 | * abortion |
| 42 | * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if |
| 43 | * using separate functional clock |
| 44 | * 0x3 disabled: Module is disabled and cannot be accessed |
| 45 | * |
| 46 | * TODO: Need to handle module accessible in idle state |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 47 | */ |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 48 | int omap4_cm_wait_module_ready(void __iomem *clkctrl_reg) |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 49 | { |
Benoit Cousson | 9a23dfe | 2010-05-20 12:31:08 -0600 | [diff] [blame] | 50 | int i = 0; |
| 51 | |
| 52 | if (!clkctrl_reg) |
| 53 | return 0; |
| 54 | |
| 55 | omap_test_timeout(((__raw_readl(clkctrl_reg) & |
| 56 | OMAP4430_IDLEST_MASK) == 0), |
| 57 | MAX_MODULE_READY_TIME, i); |
| 58 | |
| 59 | return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY; |
Paul Walmsley | 71348bc | 2009-09-03 20:14:02 +0300 | [diff] [blame] | 60 | } |
| 61 | |