Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 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 | */ |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/clk.h> |
Tony Lindgren | a58caad | 2008-07-03 12:24:44 +0300 | [diff] [blame^] | 19 | #include <linux/io.h> |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 20 | |
Tony Lindgren | a58caad | 2008-07-03 12:24:44 +0300 | [diff] [blame^] | 21 | #include <asm/arch/common.h> |
| 22 | #include <asm/arch/prcm.h> |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 23 | |
Tony Lindgren | a58caad | 2008-07-03 12:24:44 +0300 | [diff] [blame^] | 24 | #include "clock.h" |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 25 | #include "prm.h" |
| 26 | #include "prm-regbits-24xx.h" |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 27 | |
Tony Lindgren | a58caad | 2008-07-03 12:24:44 +0300 | [diff] [blame^] | 28 | static void __iomem *prm_base; |
| 29 | static void __iomem *cm_base; |
| 30 | |
Tony Lindgren | ae78dcf | 2006-09-25 12:41:20 +0300 | [diff] [blame] | 31 | extern void omap2_clk_prepare_for_reboot(void); |
| 32 | |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 33 | u32 omap_prcm_get_reset_sources(void) |
| 34 | { |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 35 | return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f; |
Tony Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 36 | } |
| 37 | EXPORT_SYMBOL(omap_prcm_get_reset_sources); |
| 38 | |
| 39 | /* Resets clock rates and reboots the system. Only called from system.h */ |
| 40 | void omap_prcm_arch_reset(char mode) |
| 41 | { |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 42 | u32 wkup; |
Tony Lindgren | ae78dcf | 2006-09-25 12:41:20 +0300 | [diff] [blame] | 43 | omap2_clk_prepare_for_reboot(); |
Paul Walmsley | 4459598 | 2008-03-18 10:04:51 +0200 | [diff] [blame] | 44 | |
| 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 Lindgren | b824efa | 2006-04-02 17:46:20 +0100 | [diff] [blame] | 49 | } |
Tony Lindgren | a58caad | 2008-07-03 12:24:44 +0300 | [diff] [blame^] | 50 | |
| 51 | static 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 | |
| 57 | static 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 */ |
| 65 | u32 prm_read_mod_reg(s16 module, u16 idx) |
| 66 | { |
| 67 | return __omap_prcm_read(prm_base, module, idx); |
| 68 | } |
| 69 | EXPORT_SYMBOL(prm_read_mod_reg); |
| 70 | |
| 71 | /* Write into a register in a PRM module */ |
| 72 | void prm_write_mod_reg(u32 val, s16 module, u16 idx) |
| 73 | { |
| 74 | __omap_prcm_write(val, prm_base, module, idx); |
| 75 | } |
| 76 | EXPORT_SYMBOL(prm_write_mod_reg); |
| 77 | |
| 78 | /* Read a register in a CM module */ |
| 79 | u32 cm_read_mod_reg(s16 module, u16 idx) |
| 80 | { |
| 81 | return __omap_prcm_read(cm_base, module, idx); |
| 82 | } |
| 83 | EXPORT_SYMBOL(cm_read_mod_reg); |
| 84 | |
| 85 | /* Write into a register in a CM module */ |
| 86 | void cm_write_mod_reg(u32 val, s16 module, u16 idx) |
| 87 | { |
| 88 | __omap_prcm_write(val, cm_base, module, idx); |
| 89 | } |
| 90 | EXPORT_SYMBOL(cm_write_mod_reg); |
| 91 | |
| 92 | void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals) |
| 93 | { |
| 94 | prm_base = omap2_globals->prm; |
| 95 | cm_base = omap2_globals->cm; |
| 96 | } |