2 * linux/arch/arm/mach-omap2/prcm.c
4 * OMAP 24xx Power Reset and Clock Management (PRCM) functions
6 * Copyright (C) 2005 Nokia Corporation
8 * Written by Tony Lindgren <tony.lindgren@nokia.com>
10 * Some pieces of code Copyright (C) 2005 Texas Instruments, Inc.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/clk.h>
20 #include <linux/delay.h>
22 #include <mach/common.h>
23 #include <mach/prcm.h>
27 #include "prm-regbits-24xx.h"
29 static void __iomem
*prm_base
;
30 static void __iomem
*cm_base
;
32 #define MAX_MODULE_ENABLE_WAIT 100000
34 u32
omap_prcm_get_reset_sources(void)
36 /* XXX This presumably needs modification for 34XX */
37 return prm_read_mod_reg(WKUP_MOD
, RM_RSTST
) & 0x7f;
39 EXPORT_SYMBOL(omap_prcm_get_reset_sources
);
41 /* Resets clock rates and reboots the system. Only called from system.h */
42 void omap_prcm_arch_reset(char mode
)
45 omap2_clk_prepare_for_reboot();
47 if (cpu_is_omap24xx())
49 else if (cpu_is_omap34xx())
50 prcm_offs
= OMAP3430_GR_MOD
;
54 prm_set_mod_reg_bits(OMAP_RST_DPLL3
, prcm_offs
, RM_RSTCTRL
);
57 static inline u32
__omap_prcm_read(void __iomem
*base
, s16 module
, u16 reg
)
60 return __raw_readl(base
+ module
+ reg
);
63 static inline void __omap_prcm_write(u32 value
, void __iomem
*base
,
67 __raw_writel(value
, base
+ module
+ reg
);
70 /* Read a register in a PRM module */
71 u32
prm_read_mod_reg(s16 module
, u16 idx
)
73 return __omap_prcm_read(prm_base
, module
, idx
);
75 EXPORT_SYMBOL(prm_read_mod_reg
);
77 /* Write into a register in a PRM module */
78 void prm_write_mod_reg(u32 val
, s16 module
, u16 idx
)
80 __omap_prcm_write(val
, prm_base
, module
, idx
);
82 EXPORT_SYMBOL(prm_write_mod_reg
);
84 /* Read-modify-write a register in a PRM module. Caller must lock */
85 u32
prm_rmw_mod_reg_bits(u32 mask
, u32 bits
, s16 module
, s16 idx
)
89 v
= prm_read_mod_reg(module
, idx
);
92 prm_write_mod_reg(v
, module
, idx
);
96 EXPORT_SYMBOL(prm_rmw_mod_reg_bits
);
98 /* Read a register in a CM module */
99 u32
cm_read_mod_reg(s16 module
, u16 idx
)
101 return __omap_prcm_read(cm_base
, module
, idx
);
103 EXPORT_SYMBOL(cm_read_mod_reg
);
105 /* Write into a register in a CM module */
106 void cm_write_mod_reg(u32 val
, s16 module
, u16 idx
)
108 __omap_prcm_write(val
, cm_base
, module
, idx
);
110 EXPORT_SYMBOL(cm_write_mod_reg
);
112 /* Read-modify-write a register in a CM module. Caller must lock */
113 u32
cm_rmw_mod_reg_bits(u32 mask
, u32 bits
, s16 module
, s16 idx
)
117 v
= cm_read_mod_reg(module
, idx
);
120 cm_write_mod_reg(v
, module
, idx
);
124 EXPORT_SYMBOL(cm_rmw_mod_reg_bits
);
127 * omap2_cm_wait_idlest - wait for IDLEST bit to indicate module readiness
128 * @reg: physical address of module IDLEST register
129 * @mask: value to mask against to determine if the module is active
130 * @name: name of the clock (for printk)
132 * Returns 1 if the module indicated readiness in time, or 0 if it
133 * failed to enable in roughly MAX_MODULE_ENABLE_WAIT microseconds.
135 int omap2_cm_wait_idlest(void __iomem
*reg
, u32 mask
, const char *name
)
141 * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
142 * 34xx reverses this, just to keep us on our toes
144 if (cpu_is_omap24xx())
146 else if (cpu_is_omap34xx())
152 while (((__raw_readl(reg
) & mask
) != ena
) &&
153 (i
++ < MAX_MODULE_ENABLE_WAIT
))
156 if (i
< MAX_MODULE_ENABLE_WAIT
)
157 pr_debug("cm: Module associated with clock %s ready after %d "
160 pr_err("cm: Module associated with clock %s didn't enable in "
161 "%d tries\n", name
, MAX_MODULE_ENABLE_WAIT
);
163 return (i
< MAX_MODULE_ENABLE_WAIT
) ? 1 : 0;
166 void __init
omap2_set_globals_prcm(struct omap_globals
*omap2_globals
)
168 prm_base
= omap2_globals
->prm
;
169 cm_base
= omap2_globals
->cm
;