xref: /openbmc/linux/arch/arm/mach-omap2/control.c (revision 38c4b121b0fb6b3a861345bad8d4d3db621f1829)
169d88a00SPaul Walmsley /*
269d88a00SPaul Walmsley  * OMAP2/3 System Control Module register access
369d88a00SPaul Walmsley  *
43e6ece13SPaul Walmsley  * Copyright (C) 2007, 2012 Texas Instruments, Inc.
569d88a00SPaul Walmsley  * Copyright (C) 2007 Nokia Corporation
669d88a00SPaul Walmsley  *
769d88a00SPaul Walmsley  * Written by Paul Walmsley
869d88a00SPaul Walmsley  *
969d88a00SPaul Walmsley  * This program is free software; you can redistribute it and/or modify
1069d88a00SPaul Walmsley  * it under the terms of the GNU General Public License version 2 as
1169d88a00SPaul Walmsley  * published by the Free Software Foundation.
1269d88a00SPaul Walmsley  */
1369d88a00SPaul Walmsley #undef DEBUG
1469d88a00SPaul Walmsley 
1569d88a00SPaul Walmsley #include <linux/kernel.h>
16a58caad1STony Lindgren #include <linux/io.h>
17fe87414fSTero Kristo #include <linux/of_address.h>
18e5b63574STero Kristo #include <linux/regmap.h>
19e5b63574STero Kristo #include <linux/mfd/syscon.h>
20*38c4b121STero Kristo #include <linux/cpu_pm.h>
2169d88a00SPaul Walmsley 
22dbc04161STony Lindgren #include "soc.h"
23ee0839c2STony Lindgren #include "iomap.h"
24ee0839c2STony Lindgren #include "common.h"
2580140786SRajendra Nayak #include "cm-regbits-34xx.h"
2680140786SRajendra Nayak #include "prm-regbits-34xx.h"
27139563adSPaul Walmsley #include "prm3xxx.h"
28ff4ae5d9SPaul Walmsley #include "cm3xxx.h"
2980140786SRajendra Nayak #include "sdrc.h"
3038815733SManjunath Kondaiah G #include "pm.h"
314814ced5SPaul Walmsley #include "control.h"
32fe87414fSTero Kristo #include "clock.h"
3369d88a00SPaul Walmsley 
34596efe47SPaul Walmsley /* Used by omap3_ctrl_save_padconf() */
35596efe47SPaul Walmsley #define START_PADCONF_SAVE		0x2
36596efe47SPaul Walmsley #define PADCONF_SAVE_DONE		0x1
37596efe47SPaul Walmsley 
38a58caad1STony Lindgren static void __iomem *omap2_ctrl_base;
39e5b63574STero Kristo static s16 omap2_ctrl_offset;
4069d88a00SPaul Walmsley 
41c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
4280140786SRajendra Nayak struct omap3_scratchpad {
4380140786SRajendra Nayak 	u32 boot_config_ptr;
4480140786SRajendra Nayak 	u32 public_restore_ptr;
4580140786SRajendra Nayak 	u32 secure_ram_restore_ptr;
4680140786SRajendra Nayak 	u32 sdrc_module_semaphore;
4780140786SRajendra Nayak 	u32 prcm_block_offset;
4880140786SRajendra Nayak 	u32 sdrc_block_offset;
4980140786SRajendra Nayak };
5080140786SRajendra Nayak 
5180140786SRajendra Nayak struct omap3_scratchpad_prcm_block {
527e28b465STero Kristo 	u32 prm_contents[2];
53c6a2d839STero Kristo 	u32 cm_contents[11];
5480140786SRajendra Nayak 	u32 prcm_block_size;
5580140786SRajendra Nayak };
5680140786SRajendra Nayak 
5780140786SRajendra Nayak struct omap3_scratchpad_sdrc_block {
5880140786SRajendra Nayak 	u16 sysconfig;
5980140786SRajendra Nayak 	u16 cs_cfg;
6080140786SRajendra Nayak 	u16 sharing;
6180140786SRajendra Nayak 	u16 err_type;
6280140786SRajendra Nayak 	u32 dll_a_ctrl;
6380140786SRajendra Nayak 	u32 dll_b_ctrl;
6480140786SRajendra Nayak 	u32 power;
6580140786SRajendra Nayak 	u32 cs_0;
6680140786SRajendra Nayak 	u32 mcfg_0;
6780140786SRajendra Nayak 	u16 mr_0;
6880140786SRajendra Nayak 	u16 emr_1_0;
6980140786SRajendra Nayak 	u16 emr_2_0;
7080140786SRajendra Nayak 	u16 emr_3_0;
7180140786SRajendra Nayak 	u32 actim_ctrla_0;
7280140786SRajendra Nayak 	u32 actim_ctrlb_0;
7380140786SRajendra Nayak 	u32 rfr_ctrl_0;
7480140786SRajendra Nayak 	u32 cs_1;
7580140786SRajendra Nayak 	u32 mcfg_1;
7680140786SRajendra Nayak 	u16 mr_1;
7780140786SRajendra Nayak 	u16 emr_1_1;
7880140786SRajendra Nayak 	u16 emr_2_1;
7980140786SRajendra Nayak 	u16 emr_3_1;
8080140786SRajendra Nayak 	u32 actim_ctrla_1;
8180140786SRajendra Nayak 	u32 actim_ctrlb_1;
8280140786SRajendra Nayak 	u32 rfr_ctrl_1;
8380140786SRajendra Nayak 	u16 dcdl_1_ctrl;
8480140786SRajendra Nayak 	u16 dcdl_2_ctrl;
8580140786SRajendra Nayak 	u32 flags;
8680140786SRajendra Nayak 	u32 block_size;
8780140786SRajendra Nayak };
8880140786SRajendra Nayak 
8927d59a4aSTero Kristo void *omap3_secure_ram_storage;
9027d59a4aSTero Kristo 
9180140786SRajendra Nayak /*
9280140786SRajendra Nayak  * This is used to store ARM registers in SDRAM before attempting
9380140786SRajendra Nayak  * an MPU OFF. The save and restore happens from the SRAM sleep code.
9480140786SRajendra Nayak  * The address is stored in scratchpad, so that it can be used
9580140786SRajendra Nayak  * during the restore path.
9680140786SRajendra Nayak  */
9780140786SRajendra Nayak u32 omap3_arm_context[128];
9880140786SRajendra Nayak 
99c96631e1SRajendra Nayak struct omap3_control_regs {
100c96631e1SRajendra Nayak 	u32 sysconfig;
101c96631e1SRajendra Nayak 	u32 devconf0;
102c96631e1SRajendra Nayak 	u32 mem_dftrw0;
103c96631e1SRajendra Nayak 	u32 mem_dftrw1;
104c96631e1SRajendra Nayak 	u32 msuspendmux_0;
105c96631e1SRajendra Nayak 	u32 msuspendmux_1;
106c96631e1SRajendra Nayak 	u32 msuspendmux_2;
107c96631e1SRajendra Nayak 	u32 msuspendmux_3;
108c96631e1SRajendra Nayak 	u32 msuspendmux_4;
109c96631e1SRajendra Nayak 	u32 msuspendmux_5;
110c96631e1SRajendra Nayak 	u32 sec_ctrl;
111c96631e1SRajendra Nayak 	u32 devconf1;
112c96631e1SRajendra Nayak 	u32 csirxfe;
113c96631e1SRajendra Nayak 	u32 iva2_bootaddr;
114c96631e1SRajendra Nayak 	u32 iva2_bootmod;
115b96b332fSTony Lindgren 	u32 wkup_ctrl;
116c96631e1SRajendra Nayak 	u32 debobs_0;
117c96631e1SRajendra Nayak 	u32 debobs_1;
118c96631e1SRajendra Nayak 	u32 debobs_2;
119c96631e1SRajendra Nayak 	u32 debobs_3;
120c96631e1SRajendra Nayak 	u32 debobs_4;
121c96631e1SRajendra Nayak 	u32 debobs_5;
122c96631e1SRajendra Nayak 	u32 debobs_6;
123c96631e1SRajendra Nayak 	u32 debobs_7;
124c96631e1SRajendra Nayak 	u32 debobs_8;
125c96631e1SRajendra Nayak 	u32 prog_io0;
126c96631e1SRajendra Nayak 	u32 prog_io1;
127c96631e1SRajendra Nayak 	u32 dss_dpll_spreading;
128c96631e1SRajendra Nayak 	u32 core_dpll_spreading;
129c96631e1SRajendra Nayak 	u32 per_dpll_spreading;
130c96631e1SRajendra Nayak 	u32 usbhost_dpll_spreading;
131c96631e1SRajendra Nayak 	u32 pbias_lite;
132c96631e1SRajendra Nayak 	u32 temp_sensor;
133c96631e1SRajendra Nayak 	u32 sramldo4;
134c96631e1SRajendra Nayak 	u32 sramldo5;
135c96631e1SRajendra Nayak 	u32 csi;
136f5f9d132SPaul Walmsley 	u32 padconf_sys_nirq;
137c96631e1SRajendra Nayak };
138c96631e1SRajendra Nayak 
139c96631e1SRajendra Nayak static struct omap3_control_regs control_context;
140c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
141c96631e1SRajendra Nayak 
142efde2346STero Kristo void __init omap2_set_globals_control(void __iomem *ctrl)
14369d88a00SPaul Walmsley {
144b6a4226cSPaul Walmsley 	omap2_ctrl_base = ctrl;
14569d88a00SPaul Walmsley }
14669d88a00SPaul Walmsley 
14769d88a00SPaul Walmsley u8 omap_ctrl_readb(u16 offset)
14869d88a00SPaul Walmsley {
149e5b63574STero Kristo 	u32 val;
150e5b63574STero Kristo 	u8 byte_offset = offset & 0x3;
151e5b63574STero Kristo 
152e5b63574STero Kristo 	val = omap_ctrl_readl(offset);
153e5b63574STero Kristo 
154e5b63574STero Kristo 	return (val >> (byte_offset * 8)) & 0xff;
15569d88a00SPaul Walmsley }
15669d88a00SPaul Walmsley 
15769d88a00SPaul Walmsley u16 omap_ctrl_readw(u16 offset)
15869d88a00SPaul Walmsley {
159e5b63574STero Kristo 	u32 val;
160e5b63574STero Kristo 	u16 byte_offset = offset & 0x2;
161e5b63574STero Kristo 
162e5b63574STero Kristo 	val = omap_ctrl_readl(offset);
163e5b63574STero Kristo 
164e5b63574STero Kristo 	return (val >> (byte_offset * 8)) & 0xffff;
16569d88a00SPaul Walmsley }
16669d88a00SPaul Walmsley 
16769d88a00SPaul Walmsley u32 omap_ctrl_readl(u16 offset)
16869d88a00SPaul Walmsley {
169e5b63574STero Kristo 	offset &= 0xfffc;
170e5b63574STero Kristo 
171d9d806b9STony Lindgren 	return readl_relaxed(omap2_ctrl_base + offset);
17269d88a00SPaul Walmsley }
17369d88a00SPaul Walmsley 
17469d88a00SPaul Walmsley void omap_ctrl_writeb(u8 val, u16 offset)
17569d88a00SPaul Walmsley {
176e5b63574STero Kristo 	u32 tmp;
177e5b63574STero Kristo 	u8 byte_offset = offset & 0x3;
178e5b63574STero Kristo 
179e5b63574STero Kristo 	tmp = omap_ctrl_readl(offset);
180e5b63574STero Kristo 
181e5b63574STero Kristo 	tmp &= 0xffffffff ^ (0xff << (byte_offset * 8));
182e5b63574STero Kristo 	tmp |= val << (byte_offset * 8);
183e5b63574STero Kristo 
184e5b63574STero Kristo 	omap_ctrl_writel(tmp, offset);
18569d88a00SPaul Walmsley }
18669d88a00SPaul Walmsley 
18769d88a00SPaul Walmsley void omap_ctrl_writew(u16 val, u16 offset)
18869d88a00SPaul Walmsley {
189e5b63574STero Kristo 	u32 tmp;
190e5b63574STero Kristo 	u8 byte_offset = offset & 0x2;
191e5b63574STero Kristo 
192e5b63574STero Kristo 	tmp = omap_ctrl_readl(offset);
193e5b63574STero Kristo 
194e5b63574STero Kristo 	tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8));
195e5b63574STero Kristo 	tmp |= val << (byte_offset * 8);
196e5b63574STero Kristo 
197e5b63574STero Kristo 	omap_ctrl_writel(tmp, offset);
19869d88a00SPaul Walmsley }
19969d88a00SPaul Walmsley 
20069d88a00SPaul Walmsley void omap_ctrl_writel(u32 val, u16 offset)
20169d88a00SPaul Walmsley {
202e5b63574STero Kristo 	offset &= 0xfffc;
203e5b63574STero Kristo 	writel_relaxed(val, omap2_ctrl_base + offset);
20469d88a00SPaul Walmsley }
20569d88a00SPaul Walmsley 
206166353bdSPaul Walmsley #ifdef CONFIG_ARCH_OMAP3
207166353bdSPaul Walmsley 
208166353bdSPaul Walmsley /**
209166353bdSPaul Walmsley  * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot
210166353bdSPaul Walmsley  * @bootmode: 8-bit value to pass to some boot code
211166353bdSPaul Walmsley  *
212166353bdSPaul Walmsley  * Set the bootmode in the scratchpad RAM.  This is used after the
213166353bdSPaul Walmsley  * system restarts.  Not sure what actually uses this - it may be the
214166353bdSPaul Walmsley  * bootloader, rather than the boot ROM - contrary to the preserved
215166353bdSPaul Walmsley  * comment below.  No return value.
216166353bdSPaul Walmsley  */
217166353bdSPaul Walmsley void omap3_ctrl_write_boot_mode(u8 bootmode)
218166353bdSPaul Walmsley {
219166353bdSPaul Walmsley 	u32 l;
220166353bdSPaul Walmsley 
221166353bdSPaul Walmsley 	l = ('B' << 24) | ('M' << 16) | bootmode;
222166353bdSPaul Walmsley 
223166353bdSPaul Walmsley 	/*
224166353bdSPaul Walmsley 	 * Reserve the first word in scratchpad for communicating
225166353bdSPaul Walmsley 	 * with the boot ROM. A pointer to a data structure
226166353bdSPaul Walmsley 	 * describing the boot process can be stored there,
227166353bdSPaul Walmsley 	 * cf. OMAP34xx TRM, Initialization / Software Booting
228166353bdSPaul Walmsley 	 * Configuration.
229166353bdSPaul Walmsley 	 *
230166353bdSPaul Walmsley 	 * XXX This should use some omap_ctrl_writel()-type function
231166353bdSPaul Walmsley 	 */
232edfaf05cSVictor Kamensky 	writel_relaxed(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4));
233166353bdSPaul Walmsley }
234166353bdSPaul Walmsley 
235166353bdSPaul Walmsley #endif
236166353bdSPaul Walmsley 
23790f1380eSOmar Ramirez Luna /**
23890f1380eSOmar Ramirez Luna  * omap_ctrl_write_dsp_boot_addr - set boot address for a remote processor
23990f1380eSOmar Ramirez Luna  * @bootaddr: physical address of the boot loader
24090f1380eSOmar Ramirez Luna  *
24190f1380eSOmar Ramirez Luna  * Set boot address for the boot loader of a supported processor
24290f1380eSOmar Ramirez Luna  * when a power ON sequence occurs.
24390f1380eSOmar Ramirez Luna  */
24490f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_addr(u32 bootaddr)
24590f1380eSOmar Ramirez Luna {
24690f1380eSOmar Ramirez Luna 	u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTADDR :
24790f1380eSOmar Ramirez Luna 		     cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTADDR :
24890f1380eSOmar Ramirez Luna 		     cpu_is_omap44xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR :
249668468b1SSuman Anna 		     soc_is_omap54xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR :
25090f1380eSOmar Ramirez Luna 		     0;
25190f1380eSOmar Ramirez Luna 
25290f1380eSOmar Ramirez Luna 	if (!offset) {
25390f1380eSOmar Ramirez Luna 		pr_err("%s: unsupported omap type\n", __func__);
25490f1380eSOmar Ramirez Luna 		return;
25590f1380eSOmar Ramirez Luna 	}
25690f1380eSOmar Ramirez Luna 
25790f1380eSOmar Ramirez Luna 	omap_ctrl_writel(bootaddr, offset);
25890f1380eSOmar Ramirez Luna }
25990f1380eSOmar Ramirez Luna 
26090f1380eSOmar Ramirez Luna /**
26190f1380eSOmar Ramirez Luna  * omap_ctrl_write_dsp_boot_mode - set boot mode for a remote processor
26290f1380eSOmar Ramirez Luna  * @bootmode: 8-bit value to pass to some boot code
26390f1380eSOmar Ramirez Luna  *
26490f1380eSOmar Ramirez Luna  * Sets boot mode for the boot loader of a supported processor
26590f1380eSOmar Ramirez Luna  * when a power ON sequence occurs.
26690f1380eSOmar Ramirez Luna  */
26790f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_mode(u8 bootmode)
26890f1380eSOmar Ramirez Luna {
26990f1380eSOmar Ramirez Luna 	u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTMOD :
27090f1380eSOmar Ramirez Luna 		     cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTMOD :
27190f1380eSOmar Ramirez Luna 		     0;
27290f1380eSOmar Ramirez Luna 
27390f1380eSOmar Ramirez Luna 	if (!offset) {
27490f1380eSOmar Ramirez Luna 		pr_err("%s: unsupported omap type\n", __func__);
27590f1380eSOmar Ramirez Luna 		return;
27690f1380eSOmar Ramirez Luna 	}
27790f1380eSOmar Ramirez Luna 
27890f1380eSOmar Ramirez Luna 	omap_ctrl_writel(bootmode, offset);
27990f1380eSOmar Ramirez Luna }
28090f1380eSOmar Ramirez Luna 
281c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
28280140786SRajendra Nayak /*
28380140786SRajendra Nayak  * Clears the scratchpad contents in case of cold boot-
28480140786SRajendra Nayak  * called during bootup
28580140786SRajendra Nayak  */
28680140786SRajendra Nayak void omap3_clear_scratchpad_contents(void)
28780140786SRajendra Nayak {
28880140786SRajendra Nayak 	u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET;
2894d63bc1dSManjunath Kondaiah G 	void __iomem *v_addr;
29080140786SRajendra Nayak 	u32 offset = 0;
291ae21e618SJeremy Vial 
29280140786SRajendra Nayak 	v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM);
2939efcea09STero Kristo 	if (omap3xxx_prm_clear_global_cold_reset()) {
29480140786SRajendra Nayak 		for ( ; offset <= max_offset; offset += 0x4)
295edfaf05cSVictor Kamensky 			writel_relaxed(0x0, (v_addr + offset));
29680140786SRajendra Nayak 	}
29780140786SRajendra Nayak }
29880140786SRajendra Nayak 
29980140786SRajendra Nayak /* Populate the scratchpad structure with restore structure */
30080140786SRajendra Nayak void omap3_save_scratchpad_contents(void)
30180140786SRajendra Nayak {
3024d63bc1dSManjunath Kondaiah G 	void  __iomem *scratchpad_address;
30380140786SRajendra Nayak 	u32 arm_context_addr;
30480140786SRajendra Nayak 	struct omap3_scratchpad scratchpad_contents;
30580140786SRajendra Nayak 	struct omap3_scratchpad_prcm_block prcm_block_contents;
30680140786SRajendra Nayak 	struct omap3_scratchpad_sdrc_block sdrc_block_contents;
30780140786SRajendra Nayak 
308f7dfe3d8SJean Pihet 	/*
309f7dfe3d8SJean Pihet 	 * Populate the Scratchpad contents
310f7dfe3d8SJean Pihet 	 *
311f7dfe3d8SJean Pihet 	 * The "get_*restore_pointer" functions are used to provide a
312f7dfe3d8SJean Pihet 	 * physical restore address where the ROM code jumps while waking
313f7dfe3d8SJean Pihet 	 * up from MPU OFF/OSWR state.
314f7dfe3d8SJean Pihet 	 * The restore pointer is stored into the scratchpad.
315f7dfe3d8SJean Pihet 	 */
31680140786SRajendra Nayak 	scratchpad_contents.boot_config_ptr = 0x0;
317458e999eSNishanth Menon 	if (cpu_is_omap3630())
318458e999eSNishanth Menon 		scratchpad_contents.public_restore_ptr =
31964fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore_3630);
320458e999eSNishanth Menon 	else if (omap_rev() != OMAP3430_REV_ES3_0 &&
3219b5f7428SJeremy Vial 					omap_rev() != OMAP3430_REV_ES3_1 &&
3229b5f7428SJeremy Vial 					omap_rev() != OMAP3430_REV_ES3_1_2)
32380140786SRajendra Nayak 		scratchpad_contents.public_restore_ptr =
32464fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore);
3250795a75aSTero Kristo 	else
3260795a75aSTero Kristo 		scratchpad_contents.public_restore_ptr =
32764fc2a94SFlorian Fainelli 			__pa_symbol(omap3_restore_es3);
32814c79bbeSKevin Hilman 
32927d59a4aSTero Kristo 	if (omap_type() == OMAP2_DEVICE_TYPE_GP)
33080140786SRajendra Nayak 		scratchpad_contents.secure_ram_restore_ptr = 0x0;
33127d59a4aSTero Kristo 	else
33227d59a4aSTero Kristo 		scratchpad_contents.secure_ram_restore_ptr =
33327d59a4aSTero Kristo 			(u32) __pa(omap3_secure_ram_storage);
33480140786SRajendra Nayak 	scratchpad_contents.sdrc_module_semaphore = 0x0;
33580140786SRajendra Nayak 	scratchpad_contents.prcm_block_offset = 0x2C;
33680140786SRajendra Nayak 	scratchpad_contents.sdrc_block_offset = 0x64;
33780140786SRajendra Nayak 
33880140786SRajendra Nayak 	/* Populate the PRCM block contents */
3397e28b465STero Kristo 	omap3_prm_save_scratchpad_contents(prcm_block_contents.prm_contents);
340c6a2d839STero Kristo 	omap3_cm_save_scratchpad_contents(prcm_block_contents.cm_contents);
341c6a2d839STero Kristo 
34280140786SRajendra Nayak 	prcm_block_contents.prcm_block_size = 0x0;
34380140786SRajendra Nayak 
34480140786SRajendra Nayak 	/* Populate the SDRC block contents */
34580140786SRajendra Nayak 	sdrc_block_contents.sysconfig =
34680140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF);
34780140786SRajendra Nayak 	sdrc_block_contents.cs_cfg =
34880140786SRajendra Nayak 			(sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF);
34980140786SRajendra Nayak 	sdrc_block_contents.sharing =
35080140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SHARING) & 0xFFFF);
35180140786SRajendra Nayak 	sdrc_block_contents.err_type =
35280140786SRajendra Nayak 			(sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF);
35380140786SRajendra Nayak 	sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL);
35480140786SRajendra Nayak 	sdrc_block_contents.dll_b_ctrl = 0x0;
355f265dc4cSRajendra Nayak 	/*
356f265dc4cSRajendra Nayak 	 * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should
357f265dc4cSRajendra Nayak 	 * be programed to issue automatic self refresh on timeout
358f265dc4cSRajendra Nayak 	 * of AUTO_CNT = 1 prior to any transition to OFF mode.
359f265dc4cSRajendra Nayak 	 */
360f265dc4cSRajendra Nayak 	if ((omap_type() != OMAP2_DEVICE_TYPE_GP)
361f265dc4cSRajendra Nayak 			&& (omap_rev() >= OMAP3430_REV_ES3_0))
362f265dc4cSRajendra Nayak 		sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) &
363f265dc4cSRajendra Nayak 				~(SDRC_POWER_AUTOCOUNT_MASK|
364f265dc4cSRajendra Nayak 				SDRC_POWER_CLKCTRL_MASK)) |
365f265dc4cSRajendra Nayak 				(1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
366f265dc4cSRajendra Nayak 				SDRC_SELF_REFRESH_ON_AUTOCOUNT;
367f265dc4cSRajendra Nayak 	else
36880140786SRajendra Nayak 		sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER);
369f265dc4cSRajendra Nayak 
37080140786SRajendra Nayak 	sdrc_block_contents.cs_0 = 0x0;
37180140786SRajendra Nayak 	sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0);
37280140786SRajendra Nayak 	sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF);
37380140786SRajendra Nayak 	sdrc_block_contents.emr_1_0 = 0x0;
37480140786SRajendra Nayak 	sdrc_block_contents.emr_2_0 = 0x0;
37580140786SRajendra Nayak 	sdrc_block_contents.emr_3_0 = 0x0;
37680140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_0 =
37780140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_0);
37880140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_0 =
37980140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_0);
38080140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_0 =
38180140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_0);
38280140786SRajendra Nayak 	sdrc_block_contents.cs_1 = 0x0;
38380140786SRajendra Nayak 	sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1);
38480140786SRajendra Nayak 	sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF;
38580140786SRajendra Nayak 	sdrc_block_contents.emr_1_1 = 0x0;
38680140786SRajendra Nayak 	sdrc_block_contents.emr_2_1 = 0x0;
38780140786SRajendra Nayak 	sdrc_block_contents.emr_3_1 = 0x0;
38880140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_1 =
38980140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_1);
39080140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_1 =
39180140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_1);
39280140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_1 =
39380140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_1);
39480140786SRajendra Nayak 	sdrc_block_contents.dcdl_1_ctrl = 0x0;
39580140786SRajendra Nayak 	sdrc_block_contents.dcdl_2_ctrl = 0x0;
39680140786SRajendra Nayak 	sdrc_block_contents.flags = 0x0;
39780140786SRajendra Nayak 	sdrc_block_contents.block_size = 0x0;
39880140786SRajendra Nayak 
39964fc2a94SFlorian Fainelli 	arm_context_addr = __pa_symbol(omap3_arm_context);
40080140786SRajendra Nayak 
40180140786SRajendra Nayak 	/* Copy all the contents to the scratchpad location */
40280140786SRajendra Nayak 	scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
40380140786SRajendra Nayak 	memcpy_toio(scratchpad_address, &scratchpad_contents,
40480140786SRajendra Nayak 		 sizeof(scratchpad_contents));
40580140786SRajendra Nayak 	/* Scratchpad contents being 32 bits, a divide by 4 done here */
40680140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
40780140786SRajendra Nayak 		scratchpad_contents.prcm_block_offset,
40880140786SRajendra Nayak 		&prcm_block_contents, sizeof(prcm_block_contents));
40980140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
41080140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset,
41180140786SRajendra Nayak 		&sdrc_block_contents, sizeof(sdrc_block_contents));
41280140786SRajendra Nayak 	/*
41380140786SRajendra Nayak 	 * Copies the address of the location in SDRAM where ARM
41480140786SRajendra Nayak 	 * registers get saved during a MPU OFF transition.
41580140786SRajendra Nayak 	 */
41680140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
41780140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset +
41880140786SRajendra Nayak 		sizeof(sdrc_block_contents), &arm_context_addr, 4);
41980140786SRajendra Nayak }
42080140786SRajendra Nayak 
421c96631e1SRajendra Nayak void omap3_control_save_context(void)
422c96631e1SRajendra Nayak {
423c96631e1SRajendra Nayak 	control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG);
424c96631e1SRajendra Nayak 	control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
425c96631e1SRajendra Nayak 	control_context.mem_dftrw0 =
426c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0);
427c96631e1SRajendra Nayak 	control_context.mem_dftrw1 =
428c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1);
429c96631e1SRajendra Nayak 	control_context.msuspendmux_0 =
430c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0);
431c96631e1SRajendra Nayak 	control_context.msuspendmux_1 =
432c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1);
433c96631e1SRajendra Nayak 	control_context.msuspendmux_2 =
434c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2);
435c96631e1SRajendra Nayak 	control_context.msuspendmux_3 =
436c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3);
437c96631e1SRajendra Nayak 	control_context.msuspendmux_4 =
438c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4);
439c96631e1SRajendra Nayak 	control_context.msuspendmux_5 =
440c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5);
441c96631e1SRajendra Nayak 	control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL);
442c96631e1SRajendra Nayak 	control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
443c96631e1SRajendra Nayak 	control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE);
444c96631e1SRajendra Nayak 	control_context.iva2_bootaddr =
445c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR);
446c96631e1SRajendra Nayak 	control_context.iva2_bootmod =
447c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD);
448b96b332fSTony Lindgren 	control_context.wkup_ctrl = omap_ctrl_readl(OMAP34XX_CONTROL_WKUP_CTRL);
449c96631e1SRajendra Nayak 	control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0));
450c96631e1SRajendra Nayak 	control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1));
451c96631e1SRajendra Nayak 	control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2));
452c96631e1SRajendra Nayak 	control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3));
453c96631e1SRajendra Nayak 	control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4));
454c96631e1SRajendra Nayak 	control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5));
455c96631e1SRajendra Nayak 	control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6));
456c96631e1SRajendra Nayak 	control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7));
457c96631e1SRajendra Nayak 	control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8));
458c96631e1SRajendra Nayak 	control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0);
459c96631e1SRajendra Nayak 	control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
460c96631e1SRajendra Nayak 	control_context.dss_dpll_spreading =
461c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING);
462c96631e1SRajendra Nayak 	control_context.core_dpll_spreading =
463c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING);
464c96631e1SRajendra Nayak 	control_context.per_dpll_spreading =
465c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING);
466c96631e1SRajendra Nayak 	control_context.usbhost_dpll_spreading =
467c96631e1SRajendra Nayak 		omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
468c96631e1SRajendra Nayak 	control_context.pbias_lite =
469c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE);
470c96631e1SRajendra Nayak 	control_context.temp_sensor =
471c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR);
472c96631e1SRajendra Nayak 	control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4);
473c96631e1SRajendra Nayak 	control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5);
474c96631e1SRajendra Nayak 	control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI);
475f5f9d132SPaul Walmsley 	control_context.padconf_sys_nirq =
476f5f9d132SPaul Walmsley 		omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ);
477c96631e1SRajendra Nayak }
478c96631e1SRajendra Nayak 
479c96631e1SRajendra Nayak void omap3_control_restore_context(void)
480c96631e1SRajendra Nayak {
481c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG);
482c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0);
483c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw0,
484c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW0);
485c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw1,
486c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW1);
487c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_0,
488c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_0);
489c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_1,
490c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_1);
491c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_2,
492c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_2);
493c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_3,
494c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_3);
495c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_4,
496c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_4);
497c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_5,
498c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_5);
499c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL);
500c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1);
501c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE);
502c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootaddr,
503c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTADDR);
504c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootmod,
505c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTMOD);
506b96b332fSTony Lindgren 	omap_ctrl_writel(control_context.wkup_ctrl, OMAP34XX_CONTROL_WKUP_CTRL);
507c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0));
508c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1));
509c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2));
510c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3));
511c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4));
512c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5));
513c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6));
514c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7));
515c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8));
516c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0);
517c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1);
518c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.dss_dpll_spreading,
519c96631e1SRajendra Nayak 					OMAP343X_CONTROL_DSS_DPLL_SPREADING);
520c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.core_dpll_spreading,
521c96631e1SRajendra Nayak 					OMAP343X_CONTROL_CORE_DPLL_SPREADING);
522c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.per_dpll_spreading,
523c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PER_DPLL_SPREADING);
524c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.usbhost_dpll_spreading,
525c96631e1SRajendra Nayak 				OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
526c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.pbias_lite,
527c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PBIAS_LITE);
528c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.temp_sensor,
529c96631e1SRajendra Nayak 					OMAP343X_CONTROL_TEMP_SENSOR);
530c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4);
531c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5);
532c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI);
533f5f9d132SPaul Walmsley 	omap_ctrl_writel(control_context.padconf_sys_nirq,
534f5f9d132SPaul Walmsley 			 OMAP343X_CONTROL_PADCONF_SYSNIRQ);
535c96631e1SRajendra Nayak }
536458e999eSNishanth Menon 
537458e999eSNishanth Menon void omap3630_ctrl_disable_rta(void)
538458e999eSNishanth Menon {
539458e999eSNishanth Menon 	if (!cpu_is_omap3630())
540458e999eSNishanth Menon 		return;
541458e999eSNishanth Menon 	omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL);
542458e999eSNishanth Menon }
543458e999eSNishanth Menon 
544596efe47SPaul Walmsley /**
545596efe47SPaul Walmsley  * omap3_ctrl_save_padconf - save padconf registers to scratchpad RAM
546596efe47SPaul Walmsley  *
547596efe47SPaul Walmsley  * Tell the SCM to start saving the padconf registers, then wait for
548596efe47SPaul Walmsley  * the process to complete.  Returns 0 unconditionally, although it
549596efe47SPaul Walmsley  * should also eventually be able to return -ETIMEDOUT, if the save
550596efe47SPaul Walmsley  * does not complete.
551596efe47SPaul Walmsley  *
552596efe47SPaul Walmsley  * XXX This function is missing a timeout.  What should it be?
553596efe47SPaul Walmsley  */
554596efe47SPaul Walmsley int omap3_ctrl_save_padconf(void)
555596efe47SPaul Walmsley {
556596efe47SPaul Walmsley 	u32 cpo;
557596efe47SPaul Walmsley 
558596efe47SPaul Walmsley 	/* Save the padconf registers */
559596efe47SPaul Walmsley 	cpo = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
560596efe47SPaul Walmsley 	cpo |= START_PADCONF_SAVE;
561596efe47SPaul Walmsley 	omap_ctrl_writel(cpo, OMAP343X_CONTROL_PADCONF_OFF);
562596efe47SPaul Walmsley 
563596efe47SPaul Walmsley 	/* wait for the save to complete */
564596efe47SPaul Walmsley 	while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
565596efe47SPaul Walmsley 		 & PADCONF_SAVE_DONE))
566596efe47SPaul Walmsley 		udelay(1);
567596efe47SPaul Walmsley 
568596efe47SPaul Walmsley 	return 0;
569596efe47SPaul Walmsley }
570596efe47SPaul Walmsley 
57149e03402STero Kristo /**
57249e03402STero Kristo  * omap3_ctrl_set_iva_bootmode_idle - sets the IVA2 bootmode to idle
57349e03402STero Kristo  *
57449e03402STero Kristo  * Sets the bootmode for IVA2 to idle. This is needed by the PM code to
57549e03402STero Kristo  * force disable IVA2 so that it does not prevent any low-power states.
57649e03402STero Kristo  */
577ba12c242STero Kristo static void __init omap3_ctrl_set_iva_bootmode_idle(void)
57849e03402STero Kristo {
57949e03402STero Kristo 	omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
58049e03402STero Kristo 			 OMAP343X_CONTROL_IVA2_BOOTMOD);
58149e03402STero Kristo }
582bbd36f9fSTero Kristo 
583bbd36f9fSTero Kristo /**
584bbd36f9fSTero Kristo  * omap3_ctrl_setup_d2d_padconf - setup stacked modem pads for idle
585bbd36f9fSTero Kristo  *
586bbd36f9fSTero Kristo  * Sets up the pads controlling the stacked modem in such way that the
587bbd36f9fSTero Kristo  * device can enter idle.
588bbd36f9fSTero Kristo  */
589ba12c242STero Kristo static void __init omap3_ctrl_setup_d2d_padconf(void)
590bbd36f9fSTero Kristo {
591bbd36f9fSTero Kristo 	u16 mask, padconf;
592bbd36f9fSTero Kristo 
593bbd36f9fSTero Kristo 	/*
594bbd36f9fSTero Kristo 	 * In a stand alone OMAP3430 where there is not a stacked
595bbd36f9fSTero Kristo 	 * modem for the D2D Idle Ack and D2D MStandby must be pulled
596bbd36f9fSTero Kristo 	 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
597bbd36f9fSTero Kristo 	 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up.
598bbd36f9fSTero Kristo 	 */
599bbd36f9fSTero Kristo 	mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
600bbd36f9fSTero Kristo 	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
601bbd36f9fSTero Kristo 	padconf |= mask;
602bbd36f9fSTero Kristo 	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
603bbd36f9fSTero Kristo 
604bbd36f9fSTero Kristo 	padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
605bbd36f9fSTero Kristo 	padconf |= mask;
606bbd36f9fSTero Kristo 	omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
607bbd36f9fSTero Kristo }
608ba12c242STero Kristo 
609ba12c242STero Kristo /**
610ba12c242STero Kristo  * omap3_ctrl_init - does static initializations for control module
611ba12c242STero Kristo  *
612ba12c242STero Kristo  * Initializes system control module. This sets up the sysconfig autoidle,
613ba12c242STero Kristo  * and sets up modem and iva2 so that they can be idled properly.
614ba12c242STero Kristo  */
615ba12c242STero Kristo void __init omap3_ctrl_init(void)
616ba12c242STero Kristo {
617ba12c242STero Kristo 	omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
618ba12c242STero Kristo 
619ba12c242STero Kristo 	omap3_ctrl_set_iva_bootmode_idle();
620ba12c242STero Kristo 
621ba12c242STero Kristo 	omap3_ctrl_setup_d2d_padconf();
622ba12c242STero Kristo }
623c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
624fe87414fSTero Kristo 
625*38c4b121STero Kristo static unsigned long am43xx_control_reg_offsets[] = {
626*38c4b121STero Kristo 	AM33XX_CONTROL_SYSCONFIG_OFFSET,
627*38c4b121STero Kristo 	AM33XX_CONTROL_STATUS_OFFSET,
628*38c4b121STero Kristo 	AM43XX_CONTROL_MPU_L2_CTRL_OFFSET,
629*38c4b121STero Kristo 	AM33XX_CONTROL_CORE_SLDO_CTRL_OFFSET,
630*38c4b121STero Kristo 	AM33XX_CONTROL_MPU_SLDO_CTRL_OFFSET,
631*38c4b121STero Kristo 	AM33XX_CONTROL_CLK32KDIVRATIO_CTRL_OFFSET,
632*38c4b121STero Kristo 	AM33XX_CONTROL_BANDGAP_CTRL_OFFSET,
633*38c4b121STero Kristo 	AM33XX_CONTROL_BANDGAP_TRIM_OFFSET,
634*38c4b121STero Kristo 	AM33XX_CONTROL_PLL_CLKINPULOW_CTRL_OFFSET,
635*38c4b121STero Kristo 	AM33XX_CONTROL_MOSC_CTRL_OFFSET,
636*38c4b121STero Kristo 	AM33XX_CONTROL_DEEPSLEEP_CTRL_OFFSET,
637*38c4b121STero Kristo 	AM43XX_CONTROL_DISPLAY_PLL_SEL_OFFSET,
638*38c4b121STero Kristo 	AM33XX_CONTROL_INIT_PRIORITY_0_OFFSET,
639*38c4b121STero Kristo 	AM33XX_CONTROL_INIT_PRIORITY_1_OFFSET,
640*38c4b121STero Kristo 	AM33XX_CONTROL_TPTC_CFG_OFFSET,
641*38c4b121STero Kristo 	AM33XX_CONTROL_USB_CTRL0_OFFSET,
642*38c4b121STero Kristo 	AM33XX_CONTROL_USB_CTRL1_OFFSET,
643*38c4b121STero Kristo 	AM43XX_CONTROL_USB_CTRL2_OFFSET,
644*38c4b121STero Kristo 	AM43XX_CONTROL_GMII_SEL_OFFSET,
645*38c4b121STero Kristo 	AM43XX_CONTROL_MPUSS_CTRL_OFFSET,
646*38c4b121STero Kristo 	AM43XX_CONTROL_TIMER_CASCADE_CTRL_OFFSET,
647*38c4b121STero Kristo 	AM43XX_CONTROL_PWMSS_CTRL_OFFSET,
648*38c4b121STero Kristo 	AM33XX_CONTROL_MREQPRIO_0_OFFSET,
649*38c4b121STero Kristo 	AM33XX_CONTROL_MREQPRIO_1_OFFSET,
650*38c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP1_OFFSET,
651*38c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP2_OFFSET,
652*38c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP3_OFFSET,
653*38c4b121STero Kristo 	AM33XX_CONTROL_HW_EVENT_SEL_GRP4_OFFSET,
654*38c4b121STero Kristo 	AM33XX_CONTROL_SMRT_CTRL_OFFSET,
655*38c4b121STero Kristo 	AM33XX_CONTROL_MPUSS_HW_DEBUG_SEL_OFFSET,
656*38c4b121STero Kristo 	AM43XX_CONTROL_CQDETECT_STS_OFFSET,
657*38c4b121STero Kristo 	AM43XX_CONTROL_CQDETECT_STS2_OFFSET,
658*38c4b121STero Kristo 	AM43XX_CONTROL_VTP_CTRL_OFFSET,
659*38c4b121STero Kristo 	AM33XX_CONTROL_VREF_CTRL_OFFSET,
660*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_0_3_OFFSET,
661*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_4_7_OFFSET,
662*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_8_11_OFFSET,
663*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_12_15_OFFSET,
664*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_16_19_OFFSET,
665*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_20_23_OFFSET,
666*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_24_27_OFFSET,
667*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_28_31_OFFSET,
668*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_32_35_OFFSET,
669*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_36_39_OFFSET,
670*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_40_43_OFFSET,
671*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_44_47_OFFSET,
672*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_48_51_OFFSET,
673*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_52_55_OFFSET,
674*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_56_59_OFFSET,
675*38c4b121STero Kristo 	AM33XX_CONTROL_TPCC_EVT_MUX_60_63_OFFSET,
676*38c4b121STero Kristo 	AM33XX_CONTROL_TIMER_EVT_CAPT_OFFSET,
677*38c4b121STero Kristo 	AM33XX_CONTROL_ECAP_EVT_CAPT_OFFSET,
678*38c4b121STero Kristo 	AM33XX_CONTROL_ADC_EVT_CAPT_OFFSET,
679*38c4b121STero Kristo 	AM43XX_CONTROL_ADC1_EVT_CAPT_OFFSET,
680*38c4b121STero Kristo 	AM33XX_CONTROL_RESET_ISO_OFFSET,
681*38c4b121STero Kristo };
682*38c4b121STero Kristo 
683*38c4b121STero Kristo static u32 am33xx_control_vals[ARRAY_SIZE(am43xx_control_reg_offsets)];
684*38c4b121STero Kristo 
685*38c4b121STero Kristo /**
686*38c4b121STero Kristo  * am43xx_control_save_context - Save the wakeup domain registers
687*38c4b121STero Kristo  *
688*38c4b121STero Kristo  * Save the wkup domain registers
689*38c4b121STero Kristo  */
690*38c4b121STero Kristo void am43xx_control_save_context(void)
691*38c4b121STero Kristo {
692*38c4b121STero Kristo 	int i;
693*38c4b121STero Kristo 
694*38c4b121STero Kristo 	for (i = 0; i < ARRAY_SIZE(am43xx_control_reg_offsets); i++)
695*38c4b121STero Kristo 		am33xx_control_vals[i] =
696*38c4b121STero Kristo 				omap_ctrl_readl(am43xx_control_reg_offsets[i]);
697*38c4b121STero Kristo }
698*38c4b121STero Kristo 
699*38c4b121STero Kristo /**
700*38c4b121STero Kristo  * am43xx_control_restore_context - Restore the wakeup domain registers
701*38c4b121STero Kristo  *
702*38c4b121STero Kristo  * Restore the wkup domain registers
703*38c4b121STero Kristo  */
704*38c4b121STero Kristo void am43xx_control_restore_context(void)
705*38c4b121STero Kristo {
706*38c4b121STero Kristo 	int i;
707*38c4b121STero Kristo 
708*38c4b121STero Kristo 	for (i = 0; i < ARRAY_SIZE(am43xx_control_reg_offsets); i++)
709*38c4b121STero Kristo 		omap_ctrl_writel(am33xx_control_vals[i],
710*38c4b121STero Kristo 				 am43xx_control_reg_offsets[i]);
711*38c4b121STero Kristo }
712*38c4b121STero Kristo 
713*38c4b121STero Kristo static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
714*38c4b121STero Kristo {
715*38c4b121STero Kristo 	switch (cmd) {
716*38c4b121STero Kristo 	case CPU_CLUSTER_PM_ENTER:
717*38c4b121STero Kristo 		if (enable_off_mode)
718*38c4b121STero Kristo 			am43xx_control_save_context();
719*38c4b121STero Kristo 		break;
720*38c4b121STero Kristo 	case CPU_CLUSTER_PM_EXIT:
721*38c4b121STero Kristo 		if (enable_off_mode)
722*38c4b121STero Kristo 			am43xx_control_restore_context();
723*38c4b121STero Kristo 		break;
724*38c4b121STero Kristo 	}
725*38c4b121STero Kristo 
726*38c4b121STero Kristo 	return NOTIFY_OK;
727*38c4b121STero Kristo }
728*38c4b121STero Kristo 
729fe87414fSTero Kristo struct control_init_data {
730fe87414fSTero Kristo 	int index;
73104dfac09STero Kristo 	void __iomem *mem;
732e5b63574STero Kristo 	s16 offset;
733fe87414fSTero Kristo };
734fe87414fSTero Kristo 
735fe87414fSTero Kristo static struct control_init_data ctrl_data = {
736fe87414fSTero Kristo 	.index = TI_CLKM_CTRL,
737fe87414fSTero Kristo };
738fe87414fSTero Kristo 
73972b10ac0STero Kristo static const struct control_init_data omap2_ctrl_data = {
74072b10ac0STero Kristo 	.index = TI_CLKM_CTRL,
74172b10ac0STero Kristo 	.offset = -OMAP2_CONTROL_GENERAL,
74272b10ac0STero Kristo };
74372b10ac0STero Kristo 
7445aa6d806STero Kristo static const struct control_init_data ctrl_aux_data = {
7455aa6d806STero Kristo 	.index = TI_CLKM_CTRL_AUX,
7465aa6d806STero Kristo };
7475aa6d806STero Kristo 
748fe87414fSTero Kristo static const struct of_device_id omap_scrm_dt_match_table[] = {
749e3bc5358STero Kristo 	{ .compatible = "ti,am3-scm", .data = &ctrl_data },
75083a5d6c9STero Kristo 	{ .compatible = "ti,am4-scm", .data = &ctrl_data },
75172b10ac0STero Kristo 	{ .compatible = "ti,omap2-scm", .data = &omap2_ctrl_data },
752b8845074STero Kristo 	{ .compatible = "ti,omap3-scm", .data = &omap2_ctrl_data },
7539444f103STony Lindgren 	{ .compatible = "ti,dm814-scm", .data = &ctrl_data },
7542208bf11STero Kristo 	{ .compatible = "ti,dm816-scrm", .data = &ctrl_data },
755ca125b5eSTero Kristo 	{ .compatible = "ti,omap4-scm-core", .data = &ctrl_data },
756ca125b5eSTero Kristo 	{ .compatible = "ti,omap5-scm-core", .data = &ctrl_data },
7575aa6d806STero Kristo 	{ .compatible = "ti,omap5-scm-wkup-pad-conf", .data = &ctrl_aux_data },
758ca125b5eSTero Kristo 	{ .compatible = "ti,dra7-scm-core", .data = &ctrl_data },
759fe87414fSTero Kristo 	{ }
760fe87414fSTero Kristo };
761fe87414fSTero Kristo 
762fe87414fSTero Kristo /**
7632208bf11STero Kristo  * omap2_control_base_init - initialize iomappings for the control driver
7642208bf11STero Kristo  *
7652208bf11STero Kristo  * Detects and initializes the iomappings for the control driver, based
7662208bf11STero Kristo  * on the DT data. Returns 0 in success, negative error value
7672208bf11STero Kristo  * otherwise.
7682208bf11STero Kristo  */
7692208bf11STero Kristo int __init omap2_control_base_init(void)
7702208bf11STero Kristo {
7712208bf11STero Kristo 	struct device_node *np;
7722208bf11STero Kristo 	const struct of_device_id *match;
7732208bf11STero Kristo 	struct control_init_data *data;
77404dfac09STero Kristo 	void __iomem *mem;
7752208bf11STero Kristo 
7762208bf11STero Kristo 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
7772208bf11STero Kristo 		data = (struct control_init_data *)match->data;
7782208bf11STero Kristo 
77904dfac09STero Kristo 		mem = of_iomap(np, 0);
78004dfac09STero Kristo 		if (!mem)
7812208bf11STero Kristo 			return -ENOMEM;
7822208bf11STero Kristo 
78304dfac09STero Kristo 		if (data->index == TI_CLKM_CTRL) {
78404dfac09STero Kristo 			omap2_ctrl_base = mem;
785e5b63574STero Kristo 			omap2_ctrl_offset = data->offset;
7862208bf11STero Kristo 		}
7872208bf11STero Kristo 
78804dfac09STero Kristo 		data->mem = mem;
78904dfac09STero Kristo 	}
79004dfac09STero Kristo 
7912208bf11STero Kristo 	return 0;
7922208bf11STero Kristo }
7932208bf11STero Kristo 
7942208bf11STero Kristo /**
795fe87414fSTero Kristo  * omap_control_init - low level init for the control driver
796fe87414fSTero Kristo  *
797fe87414fSTero Kristo  * Initializes the low level clock infrastructure for control driver.
798fe87414fSTero Kristo  * Returns 0 in success, negative error value in failure.
799fe87414fSTero Kristo  */
800fe87414fSTero Kristo int __init omap_control_init(void)
801fe87414fSTero Kristo {
802e5b63574STero Kristo 	struct device_node *np, *scm_conf;
803fe87414fSTero Kristo 	const struct of_device_id *match;
804fe87414fSTero Kristo 	const struct omap_prcm_init_data *data;
805fe87414fSTero Kristo 	int ret;
806e5b63574STero Kristo 	struct regmap *syscon;
807*38c4b121STero Kristo 	static struct notifier_block nb;
808fe87414fSTero Kristo 
809fe87414fSTero Kristo 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
810fe87414fSTero Kristo 		data = match->data;
811fe87414fSTero Kristo 
812e5b63574STero Kristo 		/*
813e5b63574STero Kristo 		 * Check if we have scm_conf node, if yes, use this to
814e5b63574STero Kristo 		 * access clock registers.
815e5b63574STero Kristo 		 */
816e5b63574STero Kristo 		scm_conf = of_get_child_by_name(np, "scm_conf");
817e5b63574STero Kristo 
818e5b63574STero Kristo 		if (scm_conf) {
819e5b63574STero Kristo 			syscon = syscon_node_to_regmap(scm_conf);
820e5b63574STero Kristo 
821e5b63574STero Kristo 			if (IS_ERR(syscon))
822e5b63574STero Kristo 				return PTR_ERR(syscon);
823e5b63574STero Kristo 
824e5b63574STero Kristo 			if (of_get_child_by_name(scm_conf, "clocks")) {
825e5b63574STero Kristo 				ret = omap2_clk_provider_init(scm_conf,
826e5b63574STero Kristo 							      data->index,
827e5b63574STero Kristo 							      syscon, NULL);
828fe87414fSTero Kristo 				if (ret)
829fe87414fSTero Kristo 					return ret;
830fe87414fSTero Kristo 			}
831e5b63574STero Kristo 		} else {
832e5b63574STero Kristo 			/* No scm_conf found, direct access */
833e5b63574STero Kristo 			ret = omap2_clk_provider_init(np, data->index, NULL,
83404dfac09STero Kristo 						      data->mem);
835e5b63574STero Kristo 			if (ret)
836e5b63574STero Kristo 				return ret;
837e5b63574STero Kristo 		}
838e5b63574STero Kristo 	}
839e5b63574STero Kristo 
840*38c4b121STero Kristo 	/* Only AM43XX can lose ctrl registers context during rtc-ddr suspend */
841*38c4b121STero Kristo 	if (soc_is_am43xx()) {
842*38c4b121STero Kristo 		nb.notifier_call = cpu_notifier;
843*38c4b121STero Kristo 		cpu_pm_register_notifier(&nb);
844*38c4b121STero Kristo 	}
845*38c4b121STero Kristo 
846fe87414fSTero Kristo 	return 0;
847fe87414fSTero Kristo }
8482208bf11STero Kristo 
8492208bf11STero Kristo /**
8502208bf11STero Kristo  * omap3_control_legacy_iomap_init - legacy iomap init for clock providers
8512208bf11STero Kristo  *
8522208bf11STero Kristo  * Legacy iomap init for clock provider. Needed only by legacy boot mode,
8532208bf11STero Kristo  * where the base addresses are not parsed from DT, but still required
8542208bf11STero Kristo  * by the clock driver to be setup properly.
8552208bf11STero Kristo  */
8562208bf11STero Kristo void __init omap3_control_legacy_iomap_init(void)
8572208bf11STero Kristo {
8582208bf11STero Kristo 	omap2_clk_legacy_provider_init(TI_CLKM_SCRM, omap2_ctrl_base);
8592208bf11STero Kristo }
860