blob: f945156d55859cbf97e0f70f9f917c7d2630107f [file] [log] [blame]
Tony Lindgrenb824efa2006-04-02 17:46:20 +01001/*
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 */
Tony Lindgrenb824efa2006-04-02 17:46:20 +010016#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/clk.h>
Tony Lindgrena58caad2008-07-03 12:24:44 +030019#include <linux/io.h>
Tony Lindgrenb824efa2006-04-02 17:46:20 +010020
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/common.h>
22#include <mach/prcm.h>
Paul Walmsley44595982008-03-18 10:04:51 +020023
Tony Lindgrena58caad2008-07-03 12:24:44 +030024#include "clock.h"
Paul Walmsley44595982008-03-18 10:04:51 +020025#include "prm.h"
26#include "prm-regbits-24xx.h"
Tony Lindgrenb824efa2006-04-02 17:46:20 +010027
Tony Lindgrena58caad2008-07-03 12:24:44 +030028static void __iomem *prm_base;
29static void __iomem *cm_base;
30
Tony Lindgrenb824efa2006-04-02 17:46:20 +010031u32 omap_prcm_get_reset_sources(void)
32{
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030033 /* XXX This presumably needs modification for 34XX */
Paul Walmsley44595982008-03-18 10:04:51 +020034 return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f;
Tony Lindgrenb824efa2006-04-02 17:46:20 +010035}
36EXPORT_SYMBOL(omap_prcm_get_reset_sources);
37
38/* Resets clock rates and reboots the system. Only called from system.h */
39void omap_prcm_arch_reset(char mode)
40{
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030041 s16 prcm_offs;
Tony Lindgrenae78dcf2006-09-25 12:41:20 +030042 omap2_clk_prepare_for_reboot();
Paul Walmsley44595982008-03-18 10:04:51 +020043
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030044 if (cpu_is_omap24xx())
45 prcm_offs = WKUP_MOD;
46 else if (cpu_is_omap34xx())
47 prcm_offs = OMAP3430_GR_MOD;
48 else
49 WARN_ON(1);
50
51 prm_set_mod_reg_bits(OMAP_RST_DPLL3, prcm_offs, RM_RSTCTRL);
Tony Lindgrenb824efa2006-04-02 17:46:20 +010052}
Tony Lindgrena58caad2008-07-03 12:24:44 +030053
54static inline u32 __omap_prcm_read(void __iomem *base, s16 module, u16 reg)
55{
56 BUG_ON(!base);
57 return __raw_readl(base + module + reg);
58}
59
60static inline void __omap_prcm_write(u32 value, void __iomem *base,
61 s16 module, u16 reg)
62{
63 BUG_ON(!base);
64 __raw_writel(value, base + module + reg);
65}
66
67/* Read a register in a PRM module */
68u32 prm_read_mod_reg(s16 module, u16 idx)
69{
70 return __omap_prcm_read(prm_base, module, idx);
71}
72EXPORT_SYMBOL(prm_read_mod_reg);
73
74/* Write into a register in a PRM module */
75void prm_write_mod_reg(u32 val, s16 module, u16 idx)
76{
77 __omap_prcm_write(val, prm_base, module, idx);
78}
79EXPORT_SYMBOL(prm_write_mod_reg);
80
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030081/* Read-modify-write a register in a PRM module. Caller must lock */
82u32 prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
83{
84 u32 v;
85
86 v = prm_read_mod_reg(module, idx);
87 v &= ~mask;
88 v |= bits;
89 prm_write_mod_reg(v, module, idx);
90
91 return v;
92}
93EXPORT_SYMBOL(prm_rmw_mod_reg_bits);
94
Tony Lindgrena58caad2008-07-03 12:24:44 +030095/* Read a register in a CM module */
96u32 cm_read_mod_reg(s16 module, u16 idx)
97{
98 return __omap_prcm_read(cm_base, module, idx);
99}
100EXPORT_SYMBOL(cm_read_mod_reg);
101
102/* Write into a register in a CM module */
103void cm_write_mod_reg(u32 val, s16 module, u16 idx)
104{
105 __omap_prcm_write(val, cm_base, module, idx);
106}
107EXPORT_SYMBOL(cm_write_mod_reg);
108
Tony Lindgrenff00fcc2008-07-03 12:24:44 +0300109/* Read-modify-write a register in a CM module. Caller must lock */
110u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
111{
112 u32 v;
113
114 v = cm_read_mod_reg(module, idx);
115 v &= ~mask;
116 v |= bits;
117 cm_write_mod_reg(v, module, idx);
118
119 return v;
120}
121EXPORT_SYMBOL(cm_rmw_mod_reg_bits);
122
Tony Lindgrena58caad2008-07-03 12:24:44 +0300123void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
124{
125 prm_base = omap2_globals->prm;
126 cm_base = omap2_globals->cm;
127}