blob: 053e24ed3c48275b56dff00645a40602b1d8fb0d [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 *
Rajendra Nayakc171a252008-09-26 17:48:31 +053010 * Copyright (C) 2007 Texas Instruments, Inc.
11 * Rajendra Nayak <rnayak@ti.com>
12 *
Tony Lindgrenb824efa2006-04-02 17:46:20 +010013 * Some pieces of code Copyright (C) 2005 Texas Instruments, Inc.
Abhijit Pagare37903002010-01-26 20:12:51 -070014 * Upgraded with OMAP4 support by Abhijit Pagare <abhijitpagare@ti.com>
Tony Lindgrenb824efa2006-04-02 17:46:20 +010015 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
19 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070020
21#include <linux/kernel.h>
Tony Lindgrenb824efa2006-04-02 17:46:20 +010022#include <linux/init.h>
23#include <linux/clk.h>
Tony Lindgrena58caad2008-07-03 12:24:44 +030024#include <linux/io.h>
Paul Walmsley72350b22009-07-24 19:44:03 -060025#include <linux/delay.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040026#include <linux/export.h>
Tony Lindgrenb824efa2006-04-02 17:46:20 +010027
Tony Lindgren4e653312011-11-10 22:45:17 +010028#include "common.h"
Tony Lindgrence491cf2009-10-20 09:40:47 -070029#include <plat/prcm.h>
Rajendra Nayakc171a252008-09-26 17:48:31 +053030#include <plat/irqs.h>
Paul Walmsley44595982008-03-18 10:04:51 +020031
Tony Lindgrena58caad2008-07-03 12:24:44 +030032#include "clock.h"
Paul Walmsleyfeec1272010-01-26 20:13:11 -070033#include "clock2xxx.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070034#include "cm2xxx_3xxx.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070035#include "prm2xxx_3xxx.h"
Paul Walmsleyd198b512010-12-21 15:30:54 -070036#include "prm44xx.h"
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070037#include "prminst44xx.h"
R Sricharan3f4990f2012-07-04 05:04:00 -060038#include "cminst44xx.h"
Paul Walmsley44595982008-03-18 10:04:51 +020039#include "prm-regbits-24xx.h"
Rajeev Kulkarniff4d3e12010-09-21 10:34:09 -060040#include "prm-regbits-44xx.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060041#include "control.h"
Tony Lindgrenb824efa2006-04-02 17:46:20 +010042
Paul Walmsley59fb6592010-12-21 15:30:55 -070043void __iomem *prm_base;
44void __iomem *cm_base;
45void __iomem *cm2_base;
R Sricharan610eb8c2012-05-07 23:55:22 -060046void __iomem *prcm_mpu_base;
Tony Lindgrena58caad2008-07-03 12:24:44 +030047
Paul Walmsley72350b22009-07-24 19:44:03 -060048#define MAX_MODULE_ENABLE_WAIT 100000
49
Tony Lindgrenb824efa2006-04-02 17:46:20 +010050u32 omap_prcm_get_reset_sources(void)
51{
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030052 /* XXX This presumably needs modification for 34XX */
Rajendra Nayak766d3052010-03-31 04:16:30 -060053 if (cpu_is_omap24xx() || cpu_is_omap34xx())
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070054 return omap2_prm_read_mod_reg(WKUP_MOD, OMAP2_RM_RSTST) & 0x7f;
Abhijit Pagare37903002010-01-26 20:12:51 -070055 if (cpu_is_omap44xx())
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070056 return omap2_prm_read_mod_reg(WKUP_MOD, OMAP4_RM_RSTST) & 0x7f;
Kevin Hilman0cc93142010-02-24 12:05:56 -070057
58 return 0;
Tony Lindgrenb824efa2006-04-02 17:46:20 +010059}
60EXPORT_SYMBOL(omap_prcm_get_reset_sources);
61
62/* Resets clock rates and reboots the system. Only called from system.h */
Russell Kingbaa95882011-11-05 17:06:28 +000063void omap_prcm_restart(char mode, const char *cmd)
Tony Lindgrenb824efa2006-04-02 17:46:20 +010064{
Kevin Hilman0cc93142010-02-24 12:05:56 -070065 s16 prcm_offs = 0;
Paul Walmsley44595982008-03-18 10:04:51 +020066
Paul Walmsleyfeec1272010-01-26 20:13:11 -070067 if (cpu_is_omap24xx()) {
68 omap2xxx_clk_prepare_for_reboot();
69
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030070 prcm_offs = WKUP_MOD;
Paul Walmsleyfeec1272010-01-26 20:13:11 -070071 } else if (cpu_is_omap34xx()) {
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030072 prcm_offs = OMAP3430_GR_MOD;
Paul Walmsley166353b2010-12-21 20:01:21 -070073 omap3_ctrl_write_boot_mode((cmd ? (u8)*cmd : 0));
Paul Walmsleydac9a772010-12-21 21:05:14 -070074 } else if (cpu_is_omap44xx()) {
Benoit Coussone54433f2011-07-10 05:56:31 -060075 omap4_prminst_global_warm_sw_reset(); /* never returns */
Paul Walmsleydac9a772010-12-21 21:05:14 -070076 } else {
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030077 WARN_ON(1);
Paul Walmsleydac9a772010-12-21 21:05:14 -070078 }
Tony Lindgrenff00fcc2008-07-03 12:24:44 +030079
Vishwanath BS9bf83912010-10-05 19:35:34 +053080 /*
81 * As per Errata i520, in some cases, user will not be able to
82 * access DDR memory after warm-reset.
83 * This situation occurs while the warm-reset happens during a read
84 * access to DDR memory. In that particular condition, DDR memory
85 * does not respond to a corrupted read command due to the warm
86 * reset occurrence but SDRC is waiting for read completion.
87 * SDRC is not sensitive to the warm reset, but the interconnect is
88 * reset on the fly, thus causing a misalignment between SDRC logic,
89 * interconnect logic and DDR memory state.
90 * WORKAROUND:
91 * Steps to perform before a Warm reset is trigged:
92 * 1. enable self-refresh on idle request
93 * 2. put SDRC in idle
94 * 3. wait until SDRC goes to idle
95 * 4. generate SW reset (Global SW reset)
96 *
97 * Steps to be performed after warm reset occurs (in bootloader):
98 * if HW warm reset is the source, apply below steps before any
99 * accesses to SDRAM:
100 * 1. Reset SMS and SDRC and wait till reset is complete
101 * 2. Re-initialize SMS, SDRC and memory
102 *
103 * NOTE: Above work around is required only if arch reset is implemented
104 * using Global SW reset(GLOBAL_SW_RST). DPLL3 reset does not need
105 * the WA since it resets SDRC as well as part of cold reset.
106 */
107
Paul Walmsleydac9a772010-12-21 21:05:14 -0700108 /* XXX should be moved to some OMAP2/3 specific code */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700109 omap2_prm_set_mod_reg_bits(OMAP_RST_DPLL3_MASK, prcm_offs,
110 OMAP2_RM_RSTCTRL);
111 omap2_prm_read_mod_reg(prcm_offs, OMAP2_RM_RSTCTRL); /* OCP barrier */
Tony Lindgrenb824efa2006-04-02 17:46:20 +0100112}
Tony Lindgrena58caad2008-07-03 12:24:44 +0300113
Paul Walmsley72350b22009-07-24 19:44:03 -0600114/**
115 * omap2_cm_wait_idlest - wait for IDLEST bit to indicate module readiness
116 * @reg: physical address of module IDLEST register
117 * @mask: value to mask against to determine if the module is active
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -0700118 * @idlest: idle state indicator (0 or 1) for the clock
Paul Walmsley72350b22009-07-24 19:44:03 -0600119 * @name: name of the clock (for printk)
120 *
121 * Returns 1 if the module indicated readiness in time, or 0 if it
122 * failed to enable in roughly MAX_MODULE_ENABLE_WAIT microseconds.
Paul Walmsley59fb6592010-12-21 15:30:55 -0700123 *
124 * XXX This function is deprecated. It should be removed once the
125 * hwmod conversion is complete.
Paul Walmsley72350b22009-07-24 19:44:03 -0600126 */
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -0700127int omap2_cm_wait_idlest(void __iomem *reg, u32 mask, u8 idlest,
128 const char *name)
Paul Walmsley72350b22009-07-24 19:44:03 -0600129{
130 int i = 0;
131 int ena = 0;
132
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -0700133 if (idlest)
Paul Walmsley72350b22009-07-24 19:44:03 -0600134 ena = 0;
135 else
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -0700136 ena = mask;
Paul Walmsley72350b22009-07-24 19:44:03 -0600137
138 /* Wait for lock */
Paul Walmsley6f8b7ff2009-12-08 16:33:16 -0700139 omap_test_timeout(((__raw_readl(reg) & mask) == ena),
140 MAX_MODULE_ENABLE_WAIT, i);
Paul Walmsley72350b22009-07-24 19:44:03 -0600141
142 if (i < MAX_MODULE_ENABLE_WAIT)
143 pr_debug("cm: Module associated with clock %s ready after %d "
144 "loops\n", name, i);
145 else
146 pr_err("cm: Module associated with clock %s didn't enable in "
147 "%d tries\n", name, MAX_MODULE_ENABLE_WAIT);
148
149 return (i < MAX_MODULE_ENABLE_WAIT) ? 1 : 0;
150};
151
Tony Lindgrena58caad2008-07-03 12:24:44 +0300152void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
153{
Tony Lindgren4c3cf902011-10-04 18:17:41 -0700154 if (omap2_globals->prm)
155 prm_base = omap2_globals->prm;
156 if (omap2_globals->cm)
157 cm_base = omap2_globals->cm;
158 if (omap2_globals->cm2)
159 cm2_base = omap2_globals->cm2;
R Sricharan610eb8c2012-05-07 23:55:22 -0600160 if (omap2_globals->prcm_mpu)
161 prcm_mpu_base = omap2_globals->prcm_mpu;
162
R Sricharan05e152c2012-06-05 16:21:32 +0530163 if (cpu_is_omap44xx() || soc_is_omap54xx()) {
R Sricharan610eb8c2012-05-07 23:55:22 -0600164 omap_prm_base_init();
165 omap_cm_base_init();
166 }
Tony Lindgrena58caad2008-07-03 12:24:44 +0300167}
R Sricharan3f4990f2012-07-04 05:04:00 -0600168
169/*
170 * Stubbed functions so that common files continue to build when
171 * custom builds are used
172 * XXX These are temporary and should be removed at the earliest possible
173 * opportunity
174 */
175int __weak omap4_cminst_wait_module_idle(u8 part, u16 inst, s16 cdoffs,
176 u16 clkctrl_offs)
177{
178 return 0;
179}
180
181void __weak omap4_cminst_module_enable(u8 mode, u8 part, u16 inst,
182 s16 cdoffs, u16 clkctrl_offs)
183{
184}
185
186void __weak omap4_cminst_module_disable(u8 part, u16 inst, s16 cdoffs,
187 u16 clkctrl_offs)
188{
189}