]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/prcm.c
OMAP: Store reboot mode in scratchpad on OMAP34xx
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / prcm.c
1 /*
2  * linux/arch/arm/mach-omap2/prcm.c
3  *
4  * OMAP 24xx Power Reset and Clock Management (PRCM) functions
5  *
6  * Copyright (C) 2005 Nokia Corporation
7  *
8  * Written by Tony Lindgren <tony.lindgren@nokia.com>
9  *
10  * Some pieces of code Copyright (C) 2005 Texas Instruments, Inc.
11  *
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.
15  */
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/clk.h>
19 #include <linux/io.h>
20
21 #include <mach/common.h>
22 #include <mach/prcm.h>
23
24 #include "clock.h"
25 #include "prm.h"
26 #include "prm-regbits-24xx.h"
27
28 static void __iomem *prm_base;
29 static void __iomem *cm_base;
30
31 u32 omap_prcm_get_reset_sources(void)
32 {
33         /* XXX This presumably needs modification for 34XX */
34         return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f;
35 }
36 EXPORT_SYMBOL(omap_prcm_get_reset_sources);
37
38 /* Resets clock rates and reboots the system. Only called from system.h */
39 void omap_prcm_arch_reset(char mode)
40 {
41         s16 prcm_offs;
42         omap2_clk_prepare_for_reboot();
43
44         if (cpu_is_omap24xx())
45                 prcm_offs = WKUP_MOD;
46         else if (cpu_is_omap34xx()) {
47                 u32 l;
48
49                 prcm_offs = OMAP3430_GR_MOD;
50                 l = ('B' << 24) | ('M' << 16) | mode;
51                 /* Reserve the first word in scratchpad for communicating
52                  * with the boot ROM. A pointer to a data structure
53                  * describing the boot process can be stored there,
54                  * cf. OMAP34xx TRM, Initialization / Software Booting
55                  * Configuration. */
56                 omap_writel(l, OMAP343X_SCRATCHPAD + 4);
57         } else
58                 WARN_ON(1);
59
60         prm_set_mod_reg_bits(OMAP_RST_DPLL3, prcm_offs, RM_RSTCTRL);
61 }
62
63 static inline u32 __omap_prcm_read(void __iomem *base, s16 module, u16 reg)
64 {
65         BUG_ON(!base);
66         return __raw_readl(base + module + reg);
67 }
68
69 static inline void __omap_prcm_write(u32 value, void __iomem *base,
70                                                 s16 module, u16 reg)
71 {
72         BUG_ON(!base);
73         __raw_writel(value, base + module + reg);
74 }
75
76 /* Read a register in a PRM module */
77 u32 prm_read_mod_reg(s16 module, u16 idx)
78 {
79         return __omap_prcm_read(prm_base, module, idx);
80 }
81 EXPORT_SYMBOL(prm_read_mod_reg);
82
83 /* Write into a register in a PRM module */
84 void prm_write_mod_reg(u32 val, s16 module, u16 idx)
85 {
86         __omap_prcm_write(val, prm_base, module, idx);
87 }
88 EXPORT_SYMBOL(prm_write_mod_reg);
89
90 /* Read-modify-write a register in a PRM module. Caller must lock */
91 u32 prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
92 {
93         u32 v;
94
95         v = prm_read_mod_reg(module, idx);
96         v &= ~mask;
97         v |= bits;
98         prm_write_mod_reg(v, module, idx);
99
100         return v;
101 }
102 EXPORT_SYMBOL(prm_rmw_mod_reg_bits);
103
104 /* Read a register in a CM module */
105 u32 cm_read_mod_reg(s16 module, u16 idx)
106 {
107         return __omap_prcm_read(cm_base, module, idx);
108 }
109 EXPORT_SYMBOL(cm_read_mod_reg);
110
111 /* Write into a register in a CM module */
112 void cm_write_mod_reg(u32 val, s16 module, u16 idx)
113 {
114         __omap_prcm_write(val, cm_base, module, idx);
115 }
116 EXPORT_SYMBOL(cm_write_mod_reg);
117
118 /* Read-modify-write a register in a CM module. Caller must lock */
119 u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
120 {
121         u32 v;
122
123         v = cm_read_mod_reg(module, idx);
124         v &= ~mask;
125         v |= bits;
126         cm_write_mod_reg(v, module, idx);
127
128         return v;
129 }
130 EXPORT_SYMBOL(cm_rmw_mod_reg_bits);
131
132 void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
133 {
134         prm_base = omap2_globals->prm;
135         cm_base = omap2_globals->cm;
136 }