blob: 9584376d055a7a9938269858fda3ee0ba23ce6ea [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
Tony Lindgrena58caad2008-07-03 12:24:44 +030021#include <asm/arch/common.h>
22#include <asm/arch/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 Lindgrenae78dcf2006-09-25 12:41:20 +030031extern void omap2_clk_prepare_for_reboot(void);
32
Tony Lindgrenb824efa2006-04-02 17:46:20 +010033u32 omap_prcm_get_reset_sources(void)
34{
Paul Walmsley44595982008-03-18 10:04:51 +020035 return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f;
Tony Lindgrenb824efa2006-04-02 17:46:20 +010036}
37EXPORT_SYMBOL(omap_prcm_get_reset_sources);
38
39/* Resets clock rates and reboots the system. Only called from system.h */
40void omap_prcm_arch_reset(char mode)
41{
Paul Walmsley44595982008-03-18 10:04:51 +020042 u32 wkup;
Tony Lindgrenae78dcf2006-09-25 12:41:20 +030043 omap2_clk_prepare_for_reboot();
Paul Walmsley44595982008-03-18 10:04:51 +020044
45 if (cpu_is_omap24xx()) {
46 wkup = prm_read_mod_reg(WKUP_MOD, RM_RSTCTRL) | OMAP_RST_DPLL3;
47 prm_write_mod_reg(wkup, WKUP_MOD, RM_RSTCTRL);
48 }
Tony Lindgrenb824efa2006-04-02 17:46:20 +010049}
Tony Lindgrena58caad2008-07-03 12:24:44 +030050
51static inline u32 __omap_prcm_read(void __iomem *base, s16 module, u16 reg)
52{
53 BUG_ON(!base);
54 return __raw_readl(base + module + reg);
55}
56
57static inline void __omap_prcm_write(u32 value, void __iomem *base,
58 s16 module, u16 reg)
59{
60 BUG_ON(!base);
61 __raw_writel(value, base + module + reg);
62}
63
64/* Read a register in a PRM module */
65u32 prm_read_mod_reg(s16 module, u16 idx)
66{
67 return __omap_prcm_read(prm_base, module, idx);
68}
69EXPORT_SYMBOL(prm_read_mod_reg);
70
71/* Write into a register in a PRM module */
72void prm_write_mod_reg(u32 val, s16 module, u16 idx)
73{
74 __omap_prcm_write(val, prm_base, module, idx);
75}
76EXPORT_SYMBOL(prm_write_mod_reg);
77
78/* Read a register in a CM module */
79u32 cm_read_mod_reg(s16 module, u16 idx)
80{
81 return __omap_prcm_read(cm_base, module, idx);
82}
83EXPORT_SYMBOL(cm_read_mod_reg);
84
85/* Write into a register in a CM module */
86void cm_write_mod_reg(u32 val, s16 module, u16 idx)
87{
88 __omap_prcm_write(val, cm_base, module, idx);
89}
90EXPORT_SYMBOL(cm_write_mod_reg);
91
92void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
93{
94 prm_base = omap2_globals->prm;
95 cm_base = omap2_globals->cm;
96}