xref: /openbmc/linux/arch/arm/mach-omap2/control.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
269d88a00SPaul Walmsley /*
369d88a00SPaul Walmsley  * OMAP2/3 System Control Module register access
469d88a00SPaul Walmsley  *
53e6ece13SPaul Walmsley  * Copyright (C) 2007, 2012 Texas Instruments, Inc.
669d88a00SPaul Walmsley  * Copyright (C) 2007 Nokia Corporation
769d88a00SPaul Walmsley  *
869d88a00SPaul Walmsley  * Written by Paul Walmsley
969d88a00SPaul Walmsley  */
1069d88a00SPaul Walmsley #undef DEBUG
1169d88a00SPaul Walmsley 
1269d88a00SPaul Walmsley #include <linux/kernel.h>
13a58caad1STony Lindgren #include <linux/io.h>
14fe87414fSTero Kristo #include <linux/of_address.h>
15e5b63574STero Kristo #include <linux/regmap.h>
16e5b63574STero Kristo #include <linux/mfd/syscon.h>
1738c4b121STero Kristo #include <linux/cpu_pm.h>
1869d88a00SPaul Walmsley 
19dbc04161STony Lindgren #include "soc.h"
20ee0839c2STony Lindgren #include "iomap.h"
21ee0839c2STony Lindgren #include "common.h"
2280140786SRajendra Nayak #include "cm-regbits-34xx.h"
2380140786SRajendra Nayak #include "prm-regbits-34xx.h"
24139563adSPaul Walmsley #include "prm3xxx.h"
25ff4ae5d9SPaul Walmsley #include "cm3xxx.h"
2680140786SRajendra Nayak #include "sdrc.h"
2738815733SManjunath Kondaiah G #include "pm.h"
284814ced5SPaul Walmsley #include "control.h"
29fe87414fSTero Kristo #include "clock.h"
3069d88a00SPaul Walmsley 
31596efe47SPaul Walmsley /* Used by omap3_ctrl_save_padconf() */
32596efe47SPaul Walmsley #define START_PADCONF_SAVE		0x2
33596efe47SPaul Walmsley #define PADCONF_SAVE_DONE		0x1
34596efe47SPaul Walmsley 
35a58caad1STony Lindgren static void __iomem *omap2_ctrl_base;
36e5b63574STero Kristo static s16 omap2_ctrl_offset;
3769d88a00SPaul Walmsley 
38c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
3980140786SRajendra Nayak struct omap3_scratchpad {
4080140786SRajendra Nayak 	u32 boot_config_ptr;
4180140786SRajendra Nayak 	u32 public_restore_ptr;
4280140786SRajendra Nayak 	u32 secure_ram_restore_ptr;
4380140786SRajendra Nayak 	u32 sdrc_module_semaphore;
4480140786SRajendra Nayak 	u32 prcm_block_offset;
4580140786SRajendra Nayak 	u32 sdrc_block_offset;
4680140786SRajendra Nayak };
4780140786SRajendra Nayak 
4880140786SRajendra Nayak struct omap3_scratchpad_prcm_block {
497e28b465STero Kristo 	u32 prm_contents[2];
50c6a2d839STero Kristo 	u32 cm_contents[11];
5180140786SRajendra Nayak 	u32 prcm_block_size;
5280140786SRajendra Nayak };
5380140786SRajendra Nayak 
5480140786SRajendra Nayak struct omap3_scratchpad_sdrc_block {
5580140786SRajendra Nayak 	u16 sysconfig;
5680140786SRajendra Nayak 	u16 cs_cfg;
5780140786SRajendra Nayak 	u16 sharing;
5880140786SRajendra Nayak 	u16 err_type;
5980140786SRajendra Nayak 	u32 dll_a_ctrl;
6080140786SRajendra Nayak 	u32 dll_b_ctrl;
6180140786SRajendra Nayak 	u32 power;
6280140786SRajendra Nayak 	u32 cs_0;
6380140786SRajendra Nayak 	u32 mcfg_0;
6480140786SRajendra Nayak 	u16 mr_0;
6580140786SRajendra Nayak 	u16 emr_1_0;
6680140786SRajendra Nayak 	u16 emr_2_0;
6780140786SRajendra Nayak 	u16 emr_3_0;
6880140786SRajendra Nayak 	u32 actim_ctrla_0;
6980140786SRajendra Nayak 	u32 actim_ctrlb_0;
7080140786SRajendra Nayak 	u32 rfr_ctrl_0;
7180140786SRajendra Nayak 	u32 cs_1;
7280140786SRajendra Nayak 	u32 mcfg_1;
7380140786SRajendra Nayak 	u16 mr_1;
7480140786SRajendra Nayak 	u16 emr_1_1;
7580140786SRajendra Nayak 	u16 emr_2_1;
7680140786SRajendra Nayak 	u16 emr_3_1;
7780140786SRajendra Nayak 	u32 actim_ctrla_1;
7880140786SRajendra Nayak 	u32 actim_ctrlb_1;
7980140786SRajendra Nayak 	u32 rfr_ctrl_1;
8080140786SRajendra Nayak 	u16 dcdl_1_ctrl;
8180140786SRajendra Nayak 	u16 dcdl_2_ctrl;
8280140786SRajendra Nayak 	u32 flags;
8380140786SRajendra Nayak 	u32 block_size;
8480140786SRajendra Nayak };
8580140786SRajendra Nayak 
8627d59a4aSTero Kristo void *omap3_secure_ram_storage;
8727d59a4aSTero Kristo 
8880140786SRajendra Nayak /*
8980140786SRajendra Nayak  * This is used to store ARM registers in SDRAM before attempting
9080140786SRajendra Nayak  * an MPU OFF. The save and restore happens from the SRAM sleep code.
9180140786SRajendra Nayak  * The address is stored in scratchpad, so that it can be used
9280140786SRajendra Nayak  * during the restore path.
9380140786SRajendra Nayak  */
9480140786SRajendra Nayak u32 omap3_arm_context[128];
9580140786SRajendra Nayak 
96c96631e1SRajendra Nayak struct omap3_control_regs {
97c96631e1SRajendra Nayak 	u32 sysconfig;
98c96631e1SRajendra Nayak 	u32 devconf0;
99c96631e1SRajendra Nayak 	u32 mem_dftrw0;
100c96631e1SRajendra Nayak 	u32 mem_dftrw1;
101c96631e1SRajendra Nayak 	u32 msuspendmux_0;
102c96631e1SRajendra Nayak 	u32 msuspendmux_1;
103c96631e1SRajendra Nayak 	u32 msuspendmux_2;
104c96631e1SRajendra Nayak 	u32 msuspendmux_3;
105c96631e1SRajendra Nayak 	u32 msuspendmux_4;
106c96631e1SRajendra Nayak 	u32 msuspendmux_5;
107c96631e1SRajendra Nayak 	u32 sec_ctrl;
108c96631e1SRajendra Nayak 	u32 devconf1;
109c96631e1SRajendra Nayak 	u32 csirxfe;
110c96631e1SRajendra Nayak 	u32 iva2_bootaddr;
111c96631e1SRajendra Nayak 	u32 iva2_bootmod;
112b96b332fSTony Lindgren 	u32 wkup_ctrl;
113c96631e1SRajendra Nayak 	u32 debobs_0;
114c96631e1SRajendra Nayak 	u32 debobs_1;
115c96631e1SRajendra Nayak 	u32 debobs_2;
116c96631e1SRajendra Nayak 	u32 debobs_3;
117c96631e1SRajendra Nayak 	u32 debobs_4;
118c96631e1SRajendra Nayak 	u32 debobs_5;
119c96631e1SRajendra Nayak 	u32 debobs_6;
120c96631e1SRajendra Nayak 	u32 debobs_7;
121c96631e1SRajendra Nayak 	u32 debobs_8;
122c96631e1SRajendra Nayak 	u32 prog_io0;
123c96631e1SRajendra Nayak 	u32 prog_io1;
124c96631e1SRajendra Nayak 	u32 dss_dpll_spreading;
125c96631e1SRajendra Nayak 	u32 core_dpll_spreading;
126c96631e1SRajendra Nayak 	u32 per_dpll_spreading;
127c96631e1SRajendra Nayak 	u32 usbhost_dpll_spreading;
128c96631e1SRajendra Nayak 	u32 pbias_lite;
129c96631e1SRajendra Nayak 	u32 temp_sensor;
130c96631e1SRajendra Nayak 	u32 sramldo4;
131c96631e1SRajendra Nayak 	u32 sramldo5;
132c96631e1SRajendra Nayak 	u32 csi;
133f5f9d132SPaul Walmsley 	u32 padconf_sys_nirq;
134c96631e1SRajendra Nayak };
135c96631e1SRajendra Nayak 
136c96631e1SRajendra Nayak static struct omap3_control_regs control_context;
137c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
138c96631e1SRajendra Nayak 
omap_ctrl_readb(u16 offset)13969d88a00SPaul Walmsley u8 omap_ctrl_readb(u16 offset)
14069d88a00SPaul Walmsley {
141e5b63574STero Kristo 	u32 val;
142e5b63574STero Kristo 	u8 byte_offset = offset & 0x3;
143e5b63574STero Kristo 
144e5b63574STero Kristo 	val = omap_ctrl_readl(offset);
145e5b63574STero Kristo 
146e5b63574STero Kristo 	return (val >> (byte_offset * 8)) & 0xff;
14769d88a00SPaul Walmsley }
14869d88a00SPaul Walmsley 
omap_ctrl_readw(u16 offset)14969d88a00SPaul Walmsley u16 omap_ctrl_readw(u16 offset)
15069d88a00SPaul Walmsley {
151e5b63574STero Kristo 	u32 val;
152e5b63574STero Kristo 	u16 byte_offset = offset & 0x2;
153e5b63574STero Kristo 
154e5b63574STero Kristo 	val = omap_ctrl_readl(offset);
155e5b63574STero Kristo 
156e5b63574STero Kristo 	return (val >> (byte_offset * 8)) & 0xffff;
15769d88a00SPaul Walmsley }
15869d88a00SPaul Walmsley 
omap_ctrl_readl(u16 offset)15969d88a00SPaul Walmsley u32 omap_ctrl_readl(u16 offset)
16069d88a00SPaul Walmsley {
161e5b63574STero Kristo 	offset &= 0xfffc;
162e5b63574STero Kristo 
163d9d806b9STony Lindgren 	return readl_relaxed(omap2_ctrl_base + offset);
16469d88a00SPaul Walmsley }
16569d88a00SPaul Walmsley 
omap_ctrl_writeb(u8 val,u16 offset)16669d88a00SPaul Walmsley void omap_ctrl_writeb(u8 val, u16 offset)
16769d88a00SPaul Walmsley {
168e5b63574STero Kristo 	u32 tmp;
169e5b63574STero Kristo 	u8 byte_offset = offset & 0x3;
170e5b63574STero Kristo 
171e5b63574STero Kristo 	tmp = omap_ctrl_readl(offset);
172e5b63574STero Kristo 
173e5b63574STero Kristo 	tmp &= 0xffffffff ^ (0xff << (byte_offset * 8));
174e5b63574STero Kristo 	tmp |= val << (byte_offset * 8);
175e5b63574STero Kristo 
176e5b63574STero Kristo 	omap_ctrl_writel(tmp, offset);
17769d88a00SPaul Walmsley }
17869d88a00SPaul Walmsley 
omap_ctrl_writew(u16 val,u16 offset)17969d88a00SPaul Walmsley void omap_ctrl_writew(u16 val, u16 offset)
18069d88a00SPaul Walmsley {
181e5b63574STero Kristo 	u32 tmp;
182e5b63574STero Kristo 	u8 byte_offset = offset & 0x2;
183e5b63574STero Kristo 
184e5b63574STero Kristo 	tmp = omap_ctrl_readl(offset);
185e5b63574STero Kristo 
186e5b63574STero Kristo 	tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8));
187e5b63574STero Kristo 	tmp |= val << (byte_offset * 8);
188e5b63574STero Kristo 
189e5b63574STero Kristo 	omap_ctrl_writel(tmp, offset);
19069d88a00SPaul Walmsley }
19169d88a00SPaul Walmsley 
omap_ctrl_writel(u32 val,u16 offset)19269d88a00SPaul Walmsley void omap_ctrl_writel(u32 val, u16 offset)
19369d88a00SPaul Walmsley {
194e5b63574STero Kristo 	offset &= 0xfffc;
195e5b63574STero Kristo 	writel_relaxed(val, omap2_ctrl_base + offset);
19669d88a00SPaul Walmsley }
19769d88a00SPaul Walmsley 
198166353bdSPaul Walmsley #ifdef CONFIG_ARCH_OMAP3
199166353bdSPaul Walmsley 
200166353bdSPaul Walmsley /**
201166353bdSPaul Walmsley  * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot
202166353bdSPaul Walmsley  * @bootmode: 8-bit value to pass to some boot code
203166353bdSPaul Walmsley  *
204166353bdSPaul Walmsley  * Set the bootmode in the scratchpad RAM.  This is used after the
205166353bdSPaul Walmsley  * system restarts.  Not sure what actually uses this - it may be the
206166353bdSPaul Walmsley  * bootloader, rather than the boot ROM - contrary to the preserved
207166353bdSPaul Walmsley  * comment below.  No return value.
208166353bdSPaul Walmsley  */
omap3_ctrl_write_boot_mode(u8 bootmode)209166353bdSPaul Walmsley void omap3_ctrl_write_boot_mode(u8 bootmode)
210166353bdSPaul Walmsley {
211166353bdSPaul Walmsley 	u32 l;
212166353bdSPaul Walmsley 
213166353bdSPaul Walmsley 	l = ('B' << 24) | ('M' << 16) | bootmode;
214166353bdSPaul Walmsley 
215166353bdSPaul Walmsley 	/*
216166353bdSPaul Walmsley 	 * Reserve the first word in scratchpad for communicating
217166353bdSPaul Walmsley 	 * with the boot ROM. A pointer to a data structure
218166353bdSPaul Walmsley 	 * describing the boot process can be stored there,
219166353bdSPaul Walmsley 	 * cf. OMAP34xx TRM, Initialization / Software Booting
220166353bdSPaul Walmsley 	 * Configuration.
221166353bdSPaul Walmsley 	 *
222166353bdSPaul Walmsley 	 * XXX This should use some omap_ctrl_writel()-type function
223166353bdSPaul Walmsley 	 */
224edfaf05cSVictor Kamensky 	writel_relaxed(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4));
225166353bdSPaul Walmsley }
226166353bdSPaul Walmsley 
227166353bdSPaul Walmsley #endif
228166353bdSPaul Walmsley 
229c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
23080140786SRajendra Nayak /* Populate the scratchpad structure with restore structure */
omap3_save_scratchpad_contents(void)23180140786SRajendra Nayak void omap3_save_scratchpad_contents(void)
23280140786SRajendra Nayak {
2334d63bc1dSManjunath Kondaiah G 	void  __iomem *scratchpad_address;
23480140786SRajendra Nayak 	u32 arm_context_addr;
23580140786SRajendra Nayak 	struct omap3_scratchpad scratchpad_contents;
23680140786SRajendra Nayak 	struct omap3_scratchpad_prcm_block prcm_block_contents;
23780140786SRajendra Nayak 	struct omap3_scratchpad_sdrc_block sdrc_block_contents;
23880140786SRajendra Nayak 
239f7dfe3d8SJean Pihet 	/*
240f7dfe3d8SJean Pihet 	 * Populate the Scratchpad contents
241f7dfe3d8SJean Pihet 	 *
242f7dfe3d8SJean Pihet 	 * The "get_*restore_pointer" functions are used to provide a
243f7dfe3d8SJean Pihet 	 * physical restore address where the ROM code jumps while waking
244f7dfe3d8SJean Pihet 	 * up from MPU OFF/OSWR state.
245f7dfe3d8SJean Pihet 	 * The restore pointer is stored into the scratchpad.
246f7dfe3d8SJean Pihet 	 */
24780140786SRajendra Nayak 	scratchpad_contents.boot_config_ptr = 0x0;
248458e999eSNishanth Menon 	if (cpu_is_omap3630())
249458e999eSNishanth Menon 		scratchpad_contents.public_restore_ptr =
25064fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore_3630);
251458e999eSNishanth Menon 	else if (omap_rev() != OMAP3430_REV_ES3_0 &&
2529b5f7428SJeremy Vial 					omap_rev() != OMAP3430_REV_ES3_1 &&
2539b5f7428SJeremy Vial 					omap_rev() != OMAP3430_REV_ES3_1_2)
25480140786SRajendra Nayak 		scratchpad_contents.public_restore_ptr =
25564fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore);
2560795a75aSTero Kristo 	else
2570795a75aSTero Kristo 		scratchpad_contents.public_restore_ptr =
25864fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore_es3);
25914c79bbeSKevin Hilman 
26027d59a4aSTero Kristo 	if (omap_type() == OMAP2_DEVICE_TYPE_GP)
26180140786SRajendra Nayak 		scratchpad_contents.secure_ram_restore_ptr = 0x0;
26227d59a4aSTero Kristo 	else
26327d59a4aSTero Kristo 		scratchpad_contents.secure_ram_restore_ptr =
26427d59a4aSTero Kristo 			(u32) __pa(omap3_secure_ram_storage);
26580140786SRajendra Nayak 	scratchpad_contents.sdrc_module_semaphore = 0x0;
26680140786SRajendra Nayak 	scratchpad_contents.prcm_block_offset = 0x2C;
26780140786SRajendra Nayak 	scratchpad_contents.sdrc_block_offset = 0x64;
26880140786SRajendra Nayak 
26980140786SRajendra Nayak 	/* Populate the PRCM block contents */
2707e28b465STero Kristo 	omap3_prm_save_scratchpad_contents(prcm_block_contents.prm_contents);
271c6a2d839STero Kristo 	omap3_cm_save_scratchpad_contents(prcm_block_contents.cm_contents);
272c6a2d839STero Kristo 
27380140786SRajendra Nayak 	prcm_block_contents.prcm_block_size = 0x0;
27480140786SRajendra Nayak 
27580140786SRajendra Nayak 	/* Populate the SDRC block contents */
27680140786SRajendra Nayak 	sdrc_block_contents.sysconfig =
27780140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF);
27880140786SRajendra Nayak 	sdrc_block_contents.cs_cfg =
27980140786SRajendra Nayak 			(sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF);
28080140786SRajendra Nayak 	sdrc_block_contents.sharing =
28180140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SHARING) & 0xFFFF);
28280140786SRajendra Nayak 	sdrc_block_contents.err_type =
28380140786SRajendra Nayak 			(sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF);
28480140786SRajendra Nayak 	sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL);
28580140786SRajendra Nayak 	sdrc_block_contents.dll_b_ctrl = 0x0;
286f265dc4cSRajendra Nayak 	/*
287f265dc4cSRajendra Nayak 	 * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should
288f265dc4cSRajendra Nayak 	 * be programed to issue automatic self refresh on timeout
289f265dc4cSRajendra Nayak 	 * of AUTO_CNT = 1 prior to any transition to OFF mode.
290f265dc4cSRajendra Nayak 	 */
291f265dc4cSRajendra Nayak 	if ((omap_type() != OMAP2_DEVICE_TYPE_GP)
292f265dc4cSRajendra Nayak 			&& (omap_rev() >= OMAP3430_REV_ES3_0))
293f265dc4cSRajendra Nayak 		sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) &
294f265dc4cSRajendra Nayak 				~(SDRC_POWER_AUTOCOUNT_MASK|
295f265dc4cSRajendra Nayak 				SDRC_POWER_CLKCTRL_MASK)) |
296f265dc4cSRajendra Nayak 				(1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
297f265dc4cSRajendra Nayak 				SDRC_SELF_REFRESH_ON_AUTOCOUNT;
298f265dc4cSRajendra Nayak 	else
29980140786SRajendra Nayak 		sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER);
300f265dc4cSRajendra Nayak 
30180140786SRajendra Nayak 	sdrc_block_contents.cs_0 = 0x0;
30280140786SRajendra Nayak 	sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0);
30380140786SRajendra Nayak 	sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF);
30480140786SRajendra Nayak 	sdrc_block_contents.emr_1_0 = 0x0;
30580140786SRajendra Nayak 	sdrc_block_contents.emr_2_0 = 0x0;
30680140786SRajendra Nayak 	sdrc_block_contents.emr_3_0 = 0x0;
30780140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_0 =
30880140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_0);
30980140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_0 =
31080140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_0);
31180140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_0 =
31280140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_0);
31380140786SRajendra Nayak 	sdrc_block_contents.cs_1 = 0x0;
31480140786SRajendra Nayak 	sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1);
31580140786SRajendra Nayak 	sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF;
31680140786SRajendra Nayak 	sdrc_block_contents.emr_1_1 = 0x0;
31780140786SRajendra Nayak 	sdrc_block_contents.emr_2_1 = 0x0;
31880140786SRajendra Nayak 	sdrc_block_contents.emr_3_1 = 0x0;
31980140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_1 =
32080140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_1);
32180140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_1 =
32280140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_1);
32380140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_1 =
32480140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_1);
32580140786SRajendra Nayak 	sdrc_block_contents.dcdl_1_ctrl = 0x0;
32680140786SRajendra Nayak 	sdrc_block_contents.dcdl_2_ctrl = 0x0;
32780140786SRajendra Nayak 	sdrc_block_contents.flags = 0x0;
32880140786SRajendra Nayak 	sdrc_block_contents.block_size = 0x0;
32980140786SRajendra Nayak 
33064fc2a94SFlorian Fainelli 	arm_context_addr = __pa_symbol(omap3_arm_context);
33180140786SRajendra Nayak 
33280140786SRajendra Nayak 	/* Copy all the contents to the scratchpad location */
33380140786SRajendra Nayak 	scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
33480140786SRajendra Nayak 	memcpy_toio(scratchpad_address, &scratchpad_contents,
33580140786SRajendra Nayak 		 sizeof(scratchpad_contents));
33680140786SRajendra Nayak 	/* Scratchpad contents being 32 bits, a divide by 4 done here */
33780140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
33880140786SRajendra Nayak 		scratchpad_contents.prcm_block_offset,
33980140786SRajendra Nayak 		&prcm_block_contents, sizeof(prcm_block_contents));
34080140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
34180140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset,
34280140786SRajendra Nayak 		&sdrc_block_contents, sizeof(sdrc_block_contents));
34380140786SRajendra Nayak 	/*
34480140786SRajendra Nayak 	 * Copies the address of the location in SDRAM where ARM
34580140786SRajendra Nayak 	 * registers get saved during a MPU OFF transition.
34680140786SRajendra Nayak 	 */
34780140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
34880140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset +
34980140786SRajendra Nayak 		sizeof(sdrc_block_contents), &arm_context_addr, 4);
35080140786SRajendra Nayak }
35180140786SRajendra Nayak 
omap3_control_save_context(void)352c96631e1SRajendra Nayak void omap3_control_save_context(void)
353c96631e1SRajendra Nayak {
354c96631e1SRajendra Nayak 	control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG);
355c96631e1SRajendra Nayak 	control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
356c96631e1SRajendra Nayak 	control_context.mem_dftrw0 =
357c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0);
358c96631e1SRajendra Nayak 	control_context.mem_dftrw1 =
359c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1);
360c96631e1SRajendra Nayak 	control_context.msuspendmux_0 =
361c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0);
362c96631e1SRajendra Nayak 	control_context.msuspendmux_1 =
363c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1);
364c96631e1SRajendra Nayak 	control_context.msuspendmux_2 =
365c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2);
366c96631e1SRajendra Nayak 	control_context.msuspendmux_3 =
367c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3);
368c96631e1SRajendra Nayak 	control_context.msuspendmux_4 =
369c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4);
370c96631e1SRajendra Nayak 	control_context.msuspendmux_5 =
371c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5);
372c96631e1SRajendra Nayak 	control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL);
373c96631e1SRajendra Nayak 	control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
374c96631e1SRajendra Nayak 	control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE);
375c96631e1SRajendra Nayak 	control_context.iva2_bootaddr =
376c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR);
377c96631e1SRajendra Nayak 	control_context.iva2_bootmod =
378c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD);
379b96b332fSTony Lindgren 	control_context.wkup_ctrl = omap_ctrl_readl(OMAP34XX_CONTROL_WKUP_CTRL);
380c96631e1SRajendra Nayak 	control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0));
381c96631e1SRajendra Nayak 	control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1));
382c96631e1SRajendra Nayak 	control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2));
383c96631e1SRajendra Nayak 	control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3));
384c96631e1SRajendra Nayak 	control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4));
385c96631e1SRajendra Nayak 	control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5));
386c96631e1SRajendra Nayak 	control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6));
387c96631e1SRajendra Nayak 	control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7));
388c96631e1SRajendra Nayak 	control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8));
389c96631e1SRajendra Nayak 	control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0);
390c96631e1SRajendra Nayak 	control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
391c96631e1SRajendra Nayak 	control_context.dss_dpll_spreading =
392c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING);
393c96631e1SRajendra Nayak 	control_context.core_dpll_spreading =
394c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING);
395c96631e1SRajendra Nayak 	control_context.per_dpll_spreading =
396c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING);
397c96631e1SRajendra Nayak 	control_context.usbhost_dpll_spreading =
398c96631e1SRajendra Nayak 		omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
399c96631e1SRajendra Nayak 	control_context.pbias_lite =
400c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE);
401c96631e1SRajendra Nayak 	control_context.temp_sensor =
402c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR);
403c96631e1SRajendra Nayak 	control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4);
404c96631e1SRajendra Nayak 	control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5);
405c96631e1SRajendra Nayak 	control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI);
406f5f9d132SPaul Walmsley 	control_context.padconf_sys_nirq =
407f5f9d132SPaul Walmsley 		omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ);
408c96631e1SRajendra Nayak }
409c96631e1SRajendra Nayak 
omap3_control_restore_context(void)410c96631e1SRajendra Nayak void omap3_control_restore_context(void)
411c96631e1SRajendra Nayak {
412c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG);
413c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0);
414c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw0,
415c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW0);
416c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw1,
417c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW1);
418c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_0,
419c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_0);
420c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_1,
421c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_1);
422c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_2,
423c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_2);
424c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_3,
425c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_3);
426c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_4,
427c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_4);
428c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_5,
429c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_5);
430c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL);
431c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1);
432c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE);
433c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootaddr,
434c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTADDR);
435c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootmod,
436c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTMOD);
437b96b332fSTony Lindgren 	omap_ctrl_writel(control_context.wkup_ctrl, OMAP34XX_CONTROL_WKUP_CTRL);
438c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0));
439c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1));
440c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2));
441c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3));
442c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4));
443c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5));
444c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6));
445c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7));
446c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8));
447c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0);
448c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1);
449c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.dss_dpll_spreading,
450c96631e1SRajendra Nayak 					OMAP343X_CONTROL_DSS_DPLL_SPREADING);
451c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.core_dpll_spreading,
452c96631e1SRajendra Nayak 					OMAP343X_CONTROL_CORE_DPLL_SPREADING);
453c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.per_dpll_spreading,
454c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PER_DPLL_SPREADING);
455c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.usbhost_dpll_spreading,
456c96631e1SRajendra Nayak 				OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
457c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.pbias_lite,
458c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PBIAS_LITE);
459c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.temp_sensor,
460c96631e1SRajendra Nayak 					OMAP343X_CONTROL_TEMP_SENSOR);
461c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4);
462c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5);
463c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI);
464f5f9d132SPaul Walmsley 	omap_ctrl_writel(control_context.padconf_sys_nirq,
465f5f9d132SPaul Walmsley 			 OMAP343X_CONTROL_PADCONF_SYSNIRQ);
466c96631e1SRajendra Nayak }
467458e999eSNishanth Menon 
omap3630_ctrl_disable_rta(void)468458e999eSNishanth Menon void omap3630_ctrl_disable_rta(void)
469458e999eSNishanth Menon {
470458e999eSNishanth Menon 	if (!cpu_is_omap3630())
471458e999eSNishanth Menon 		return;
472458e999eSNishanth Menon 	omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL);
473458e999eSNishanth Menon }
474458e999eSNishanth Menon 
475596efe47SPaul Walmsley /**
476596efe47SPaul Walmsley  * omap3_ctrl_save_padconf - save padconf registers to scratchpad RAM
477596efe47SPaul Walmsley  *
478596efe47SPaul Walmsley  * Tell the SCM to start saving the padconf registers, then wait for
479596efe47SPaul Walmsley  * the process to complete.  Returns 0 unconditionally, although it
480596efe47SPaul Walmsley  * should also eventually be able to return -ETIMEDOUT, if the save
481596efe47SPaul Walmsley  * does not complete.
482596efe47SPaul Walmsley  *
483596efe47SPaul Walmsley  * XXX This function is missing a timeout.  What should it be?
484596efe47SPaul Walmsley  */
omap3_ctrl_save_padconf(void)485596efe47SPaul Walmsley int omap3_ctrl_save_padconf(void)
486596efe47SPaul Walmsley {
487596efe47SPaul Walmsley 	u32 cpo;
488596efe47SPaul Walmsley 
489596efe47SPaul Walmsley 	/* Save the padconf registers */
490596efe47SPaul Walmsley 	cpo = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
491596efe47SPaul Walmsley 	cpo |= START_PADCONF_SAVE;
492596efe47SPaul Walmsley 	omap_ctrl_writel(cpo, OMAP343X_CONTROL_PADCONF_OFF);
493596efe47SPaul Walmsley 
494596efe47SPaul Walmsley 	/* wait for the save to complete */
495596efe47SPaul Walmsley 	while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
496596efe47SPaul Walmsley 		 & PADCONF_SAVE_DONE))
497596efe47SPaul Walmsley 		udelay(1);
498596efe47SPaul Walmsley 
499596efe47SPaul Walmsley 	return 0;
500596efe47SPaul Walmsley }
501596efe47SPaul Walmsley 
50249e03402STero Kristo /**
50349e03402STero Kristo  * omap3_ctrl_set_iva_bootmode_idle - sets the IVA2 bootmode to idle
50449e03402STero Kristo  *
50549e03402STero Kristo  * Sets the bootmode for IVA2 to idle. This is needed by the PM code to
50649e03402STero Kristo  * force disable IVA2 so that it does not prevent any low-power states.
50749e03402STero Kristo  */
omap3_ctrl_set_iva_bootmode_idle(void)508ba12c242STero Kristo static void __init omap3_ctrl_set_iva_bootmode_idle(void)
50949e03402STero Kristo {
51049e03402STero Kristo 	omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
51149e03402STero Kristo 			 OMAP343X_CONTROL_IVA2_BOOTMOD);
51249e03402STero Kristo }
513bbd36f9fSTero Kristo 
514bbd36f9fSTero Kristo /**
515bbd36f9fSTero Kristo  * omap3_ctrl_setup_d2d_padconf - setup stacked modem pads for idle
516bbd36f9fSTero Kristo  *
517bbd36f9fSTero Kristo  * Sets up the pads controlling the stacked modem in such way that the
518bbd36f9fSTero Kristo  * device can enter idle.
519bbd36f9fSTero Kristo  */
omap3_ctrl_setup_d2d_padconf(void)520ba12c242STero Kristo static void __init omap3_ctrl_setup_d2d_padconf(void)
521bbd36f9fSTero Kristo {
522bbd36f9fSTero Kristo 	u16 mask, padconf;
523bbd36f9fSTero Kristo 
524bbd36f9fSTero Kristo 	/*
525bbd36f9fSTero Kristo 	 * In a stand alone OMAP3430 where there is not a stacked
526bbd36f9fSTero Kristo 	 * modem for the D2D Idle Ack and D2D MStandby must be pulled
527bbd36f9fSTero Kristo 	 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
528bbd36f9fSTero Kristo 	 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up.
529bbd36f9fSTero Kristo 	 */
530bbd36f9fSTero Kristo 	mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
531bbd36f9fSTero Kristo 	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
532bbd36f9fSTero Kristo 	padconf |= mask;
533bbd36f9fSTero Kristo 	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
534bbd36f9fSTero Kristo 
535bbd36f9fSTero Kristo 	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
536bbd36f9fSTero Kristo 	padconf |= mask;
537bbd36f9fSTero Kristo 	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
538bbd36f9fSTero Kristo }
539ba12c242STero Kristo 
540ba12c242STero Kristo /**
541ba12c242STero Kristo  * omap3_ctrl_init - does static initializations for control module
542ba12c242STero Kristo  *
543ba12c242STero Kristo  * Initializes system control module. This sets up the sysconfig autoidle,
544ba12c242STero Kristo  * and sets up modem and iva2 so that they can be idled properly.
545ba12c242STero Kristo  */
omap3_ctrl_init(void)546ba12c242STero Kristo void __init omap3_ctrl_init(void)
547ba12c242STero Kristo {
548ba12c242STero Kristo 	omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
549ba12c242STero Kristo 
550ba12c242STero Kristo 	omap3_ctrl_set_iva_bootmode_idle();
551ba12c242STero Kristo 
552ba12c242STero Kristo 	omap3_ctrl_setup_d2d_padconf();
553ba12c242STero Kristo }
554c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
555fe87414fSTero Kristo 
55638c4b121STero Kristo static unsigned long am43xx_control_reg_offsets[] = {
55738c4b121STero Kristo 	AM33XX_CONTROL_SYSCONFIG_OFFSET,
55838c4b121STero Kristo 	AM33XX_CONTROL_STATUS_OFFSET,
55938c4b121STero Kristo 	AM43XX_CONTROL_MPU_L2_CTRL_OFFSET,
56038c4b121STero Kristo 	AM33XX_CONTROL_CORE_SLDO_CTRL_OFFSET,
56138c4b121STero Kristo 	AM33XX_CONTROL_MPU_SLDO_CTRL_OFFSET,
56238c4b121STero Kristo 	AM33XX_CONTROL_CLK32KDIVRATIO_CTRL_OFFSET,
56338c4b121STero Kristo 	AM33XX_CONTROL_BANDGAP_CTRL_OFFSET,
56438c4b121STero Kristo 	AM33XX_CONTROL_BANDGAP_TRIM_OFFSET,
56538c4b121STero Kristo 	AM33XX_CONTROL_PLL_CLKINPULOW_CTRL_OFFSET,
56638c4b121STero Kristo 	AM33XX_CONTROL_MOSC_CTRL_OFFSET,
56738c4b121STero Kristo 	AM33XX_CONTROL_DEEPSLEEP_CTRL_OFFSET,
56838c4b121STero Kristo 	AM43XX_CONTROL_DISPLAY_PLL_SEL_OFFSET,
56938c4b121STero Kristo 	AM33XX_CONTROL_INIT_PRIORITY_0_OFFSET,
57038c4b121STero Kristo 	AM33XX_CONTROL_INIT_PRIORITY_1_OFFSET,
57138c4b121STero Kristo 	AM33XX_CONTROL_TPTC_CFG_OFFSET,
57238c4b121STero Kristo 	AM33XX_CONTROL_USB_CTRL0_OFFSET,
57338c4b121STero Kristo 	AM33XX_CONTROL_USB_CTRL1_OFFSET,
57438c4b121STero Kristo 	AM43XX_CONTROL_USB_CTRL2_OFFSET,
57538c4b121STero Kristo 	AM43XX_CONTROL_GMII_SEL_OFFSET,
57638c4b121STero Kristo 	AM43XX_CONTROL_MPUSS_CTRL_OFFSET,
57738c4b121STero Kristo 	AM43XX_CONTROL_TIMER_CASCADE_CTRL_OFFSET,
57838c4b121STero Kristo 	AM43XX_CONTROL_PWMSS_CTRL_OFFSET,
57938c4b121STero Kristo 	AM33XX_CONTROL_MREQPRIO_0_OFFSET,
58038c4b121STero Kristo 	AM33XX_CONTROL_MREQPRIO_1_OFFSET,
58138c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP1_OFFSET,
58238c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP2_OFFSET,
58338c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP3_OFFSET,
58438c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP4_OFFSET,
58538c4b121STero Kristo 	AM33XX_CONTROL_SMRT_CTRL_OFFSET,
58638c4b121STero Kristo 	AM33XX_CONTROL_MPUSS_HW_DEBUG_SEL_OFFSET,
58738c4b121STero Kristo 	AM43XX_CONTROL_CQDETECT_STS_OFFSET,
58838c4b121STero Kristo 	AM43XX_CONTROL_CQDETECT_STS2_OFFSET,
58938c4b121STero Kristo 	AM43XX_CONTROL_VTP_CTRL_OFFSET,
59038c4b121STero Kristo 	AM33XX_CONTROL_VREF_CTRL_OFFSET,
59138c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_0_3_OFFSET,
59238c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_4_7_OFFSET,
59338c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_8_11_OFFSET,
59438c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_12_15_OFFSET,
59538c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_16_19_OFFSET,
59638c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_20_23_OFFSET,
59738c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_24_27_OFFSET,
59838c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_28_31_OFFSET,
59938c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_32_35_OFFSET,
60038c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_36_39_OFFSET,
60138c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_40_43_OFFSET,
60238c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_44_47_OFFSET,
60338c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_48_51_OFFSET,
60438c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_52_55_OFFSET,
60538c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_56_59_OFFSET,
60638c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_60_63_OFFSET,
60738c4b121STero Kristo 	AM33XX_CONTROL_TIMER_EVT_CAPT_OFFSET,
60838c4b121STero Kristo 	AM33XX_CONTROL_ECAP_EVT_CAPT_OFFSET,
60938c4b121STero Kristo 	AM33XX_CONTROL_ADC_EVT_CAPT_OFFSET,
61038c4b121STero Kristo 	AM43XX_CONTROL_ADC1_EVT_CAPT_OFFSET,
61138c4b121STero Kristo 	AM33XX_CONTROL_RESET_ISO_OFFSET,
61238c4b121STero Kristo };
61338c4b121STero Kristo 
61438c4b121STero Kristo static u32 am33xx_control_vals[ARRAY_SIZE(am43xx_control_reg_offsets)];
61538c4b121STero Kristo 
61638c4b121STero Kristo /**
61738c4b121STero Kristo  * am43xx_control_save_context - Save the wakeup domain registers
61838c4b121STero Kristo  *
61938c4b121STero Kristo  * Save the wkup domain registers
62038c4b121STero Kristo  */
am43xx_control_save_context(void)62187c59ca2SBen Dooks static void am43xx_control_save_context(void)
62238c4b121STero Kristo {
62338c4b121STero Kristo 	int i;
62438c4b121STero Kristo 
62538c4b121STero Kristo 	for (i = 0; i < ARRAY_SIZE(am43xx_control_reg_offsets); i++)
62638c4b121STero Kristo 		am33xx_control_vals[i] =
62738c4b121STero Kristo 				omap_ctrl_readl(am43xx_control_reg_offsets[i]);
62838c4b121STero Kristo }
62938c4b121STero Kristo 
63038c4b121STero Kristo /**
63138c4b121STero Kristo  * am43xx_control_restore_context - Restore the wakeup domain registers
63238c4b121STero Kristo  *
63338c4b121STero Kristo  * Restore the wkup domain registers
63438c4b121STero Kristo  */
am43xx_control_restore_context(void)63587c59ca2SBen Dooks static void am43xx_control_restore_context(void)
63638c4b121STero Kristo {
63738c4b121STero Kristo 	int i;
63838c4b121STero Kristo 
63938c4b121STero Kristo 	for (i = 0; i < ARRAY_SIZE(am43xx_control_reg_offsets); i++)
64038c4b121STero Kristo 		omap_ctrl_writel(am33xx_control_vals[i],
64138c4b121STero Kristo 				 am43xx_control_reg_offsets[i]);
64238c4b121STero Kristo }
64338c4b121STero Kristo 
cpu_notifier(struct notifier_block * nb,unsigned long cmd,void * v)64438c4b121STero Kristo static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
64538c4b121STero Kristo {
64638c4b121STero Kristo 	switch (cmd) {
64738c4b121STero Kristo 	case CPU_CLUSTER_PM_ENTER:
64838c4b121STero Kristo 		if (enable_off_mode)
64938c4b121STero Kristo 			am43xx_control_save_context();
65038c4b121STero Kristo 		break;
65138c4b121STero Kristo 	case CPU_CLUSTER_PM_EXIT:
65238c4b121STero Kristo 		if (enable_off_mode)
65338c4b121STero Kristo 			am43xx_control_restore_context();
65438c4b121STero Kristo 		break;
65538c4b121STero Kristo 	}
65638c4b121STero Kristo 
65738c4b121STero Kristo 	return NOTIFY_OK;
65838c4b121STero Kristo }
65938c4b121STero Kristo 
660fe87414fSTero Kristo struct control_init_data {
661fe87414fSTero Kristo 	int index;
66204dfac09STero Kristo 	void __iomem *mem;
663e5b63574STero Kristo 	s16 offset;
664fe87414fSTero Kristo };
665fe87414fSTero Kristo 
666fe87414fSTero Kristo static struct control_init_data ctrl_data = {
667fe87414fSTero Kristo 	.index = TI_CLKM_CTRL,
668fe87414fSTero Kristo };
669fe87414fSTero Kristo 
67072b10ac0STero Kristo static const struct control_init_data omap2_ctrl_data = {
67172b10ac0STero Kristo 	.index = TI_CLKM_CTRL,
67272b10ac0STero Kristo 	.offset = -OMAP2_CONTROL_GENERAL,
67372b10ac0STero Kristo };
67472b10ac0STero Kristo 
6755aa6d806STero Kristo static const struct control_init_data ctrl_aux_data = {
6765aa6d806STero Kristo 	.index = TI_CLKM_CTRL_AUX,
6775aa6d806STero Kristo };
6785aa6d806STero Kristo 
679fe87414fSTero Kristo static const struct of_device_id omap_scrm_dt_match_table[] = {
680e3bc5358STero Kristo 	{ .compatible = "ti,am3-scm", .data = &ctrl_data },
68183a5d6c9STero Kristo 	{ .compatible = "ti,am4-scm", .data = &ctrl_data },
68272b10ac0STero Kristo 	{ .compatible = "ti,omap2-scm", .data = &omap2_ctrl_data },
683b8845074STero Kristo 	{ .compatible = "ti,omap3-scm", .data = &omap2_ctrl_data },
6849444f103STony Lindgren 	{ .compatible = "ti,dm814-scm", .data = &ctrl_data },
6852208bf11STero Kristo 	{ .compatible = "ti,dm816-scrm", .data = &ctrl_data },
686ca125b5eSTero Kristo 	{ .compatible = "ti,omap4-scm-core", .data = &ctrl_data },
687ca125b5eSTero Kristo 	{ .compatible = "ti,omap5-scm-core", .data = &ctrl_data },
6885aa6d806STero Kristo 	{ .compatible = "ti,omap5-scm-wkup-pad-conf", .data = &ctrl_aux_data },
689ca125b5eSTero Kristo 	{ .compatible = "ti,dra7-scm-core", .data = &ctrl_data },
690fe87414fSTero Kristo 	{ }
691fe87414fSTero Kristo };
692fe87414fSTero Kristo 
693fe87414fSTero Kristo /**
6942208bf11STero Kristo  * omap2_control_base_init - initialize iomappings for the control driver
6952208bf11STero Kristo  *
6962208bf11STero Kristo  * Detects and initializes the iomappings for the control driver, based
6972208bf11STero Kristo  * on the DT data. Returns 0 in success, negative error value
6982208bf11STero Kristo  * otherwise.
6992208bf11STero Kristo  */
omap2_control_base_init(void)7002208bf11STero Kristo int __init omap2_control_base_init(void)
7012208bf11STero Kristo {
7022208bf11STero Kristo 	struct device_node *np;
7032208bf11STero Kristo 	const struct of_device_id *match;
7042208bf11STero Kristo 	struct control_init_data *data;
70504dfac09STero Kristo 	void __iomem *mem;
7062208bf11STero Kristo 
7072208bf11STero Kristo 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
7082208bf11STero Kristo 		data = (struct control_init_data *)match->data;
7092208bf11STero Kristo 
71004dfac09STero Kristo 		mem = of_iomap(np, 0);
711*883f464cSWang Qing 		if (!mem) {
712*883f464cSWang Qing 			of_node_put(np);
7132208bf11STero Kristo 			return -ENOMEM;
714*883f464cSWang Qing 		}
7152208bf11STero Kristo 
71604dfac09STero Kristo 		if (data->index == TI_CLKM_CTRL) {
71704dfac09STero Kristo 			omap2_ctrl_base = mem;
718e5b63574STero Kristo 			omap2_ctrl_offset = data->offset;
7192208bf11STero Kristo 		}
7202208bf11STero Kristo 
72104dfac09STero Kristo 		data->mem = mem;
72204dfac09STero Kristo 	}
72304dfac09STero Kristo 
7242208bf11STero Kristo 	return 0;
7252208bf11STero Kristo }
7262208bf11STero Kristo 
7272208bf11STero Kristo /**
728fe87414fSTero Kristo  * omap_control_init - low level init for the control driver
729fe87414fSTero Kristo  *
730fe87414fSTero Kristo  * Initializes the low level clock infrastructure for control driver.
731fe87414fSTero Kristo  * Returns 0 in success, negative error value in failure.
732fe87414fSTero Kristo  */
omap_control_init(void)733fe87414fSTero Kristo int __init omap_control_init(void)
734fe87414fSTero Kristo {
735e5b63574STero Kristo 	struct device_node *np, *scm_conf;
736fe87414fSTero Kristo 	const struct of_device_id *match;
737fe87414fSTero Kristo 	const struct omap_prcm_init_data *data;
738fe87414fSTero Kristo 	int ret;
739e5b63574STero Kristo 	struct regmap *syscon;
74038c4b121STero Kristo 	static struct notifier_block nb;
741fe87414fSTero Kristo 
742fe87414fSTero Kristo 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
743fe87414fSTero Kristo 		data = match->data;
744fe87414fSTero Kristo 
745e5b63574STero Kristo 		/*
746e5b63574STero Kristo 		 * Check if we have scm_conf node, if yes, use this to
747e5b63574STero Kristo 		 * access clock registers.
748e5b63574STero Kristo 		 */
749e5b63574STero Kristo 		scm_conf = of_get_child_by_name(np, "scm_conf");
750e5b63574STero Kristo 
751e5b63574STero Kristo 		if (scm_conf) {
752e5b63574STero Kristo 			syscon = syscon_node_to_regmap(scm_conf);
753e5b63574STero Kristo 
754*883f464cSWang Qing 			if (IS_ERR(syscon)) {
755*883f464cSWang Qing 				ret = PTR_ERR(syscon);
756*883f464cSWang Qing 				goto of_node_put;
757*883f464cSWang Qing 			}
758e5b63574STero Kristo 
759e5b63574STero Kristo 			if (of_get_child_by_name(scm_conf, "clocks")) {
760e5b63574STero Kristo 				ret = omap2_clk_provider_init(scm_conf,
761e5b63574STero Kristo 							      data->index,
762e5b63574STero Kristo 							      syscon, NULL);
763fe87414fSTero Kristo 				if (ret)
764*883f464cSWang Qing 					goto of_node_put;
765fe87414fSTero Kristo 			}
766e5b63574STero Kristo 		} else {
767e5b63574STero Kristo 			/* No scm_conf found, direct access */
768e5b63574STero Kristo 			ret = omap2_clk_provider_init(np, data->index, NULL,
76904dfac09STero Kristo 						      data->mem);
770e5b63574STero Kristo 			if (ret)
771*883f464cSWang Qing 				goto of_node_put;
772e5b63574STero Kristo 		}
773e5b63574STero Kristo 	}
774e5b63574STero Kristo 
77538c4b121STero Kristo 	/* Only AM43XX can lose ctrl registers context during rtc-ddr suspend */
77638c4b121STero Kristo 	if (soc_is_am43xx()) {
77738c4b121STero Kristo 		nb.notifier_call = cpu_notifier;
77838c4b121STero Kristo 		cpu_pm_register_notifier(&nb);
77938c4b121STero Kristo 	}
78038c4b121STero Kristo 
781fe87414fSTero Kristo 	return 0;
782*883f464cSWang Qing 
783*883f464cSWang Qing of_node_put:
784*883f464cSWang Qing 	of_node_put(np);
785*883f464cSWang Qing 	return ret;
786*883f464cSWang Qing 
787fe87414fSTero Kristo }
788