xref: /openbmc/linux/arch/arm/mach-omap2/control.c (revision f5f9d132d1c212bf3828c7926d95f79e0c20d243)
169d88a00SPaul Walmsley /*
269d88a00SPaul Walmsley  * OMAP2/3 System Control Module register access
369d88a00SPaul Walmsley  *
469d88a00SPaul Walmsley  * Copyright (C) 2007 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>
1769d88a00SPaul Walmsley 
18ce491cf8STony Lindgren #include <plat/common.h>
1980140786SRajendra Nayak #include <plat/sdrc.h>
204814ced5SPaul Walmsley 
2180140786SRajendra Nayak #include "cm-regbits-34xx.h"
2280140786SRajendra Nayak #include "prm-regbits-34xx.h"
2380140786SRajendra Nayak #include "cm.h"
2480140786SRajendra Nayak #include "prm.h"
2580140786SRajendra Nayak #include "sdrc.h"
2638815733SManjunath Kondaiah G #include "pm.h"
274814ced5SPaul Walmsley #include "control.h"
2869d88a00SPaul Walmsley 
29a58caad1STony Lindgren static void __iomem *omap2_ctrl_base;
300c349246SSantosh Shilimkar static void __iomem *omap4_ctrl_pad_base;
3169d88a00SPaul Walmsley 
32c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
3380140786SRajendra Nayak struct omap3_scratchpad {
3480140786SRajendra Nayak 	u32 boot_config_ptr;
3580140786SRajendra Nayak 	u32 public_restore_ptr;
3680140786SRajendra Nayak 	u32 secure_ram_restore_ptr;
3780140786SRajendra Nayak 	u32 sdrc_module_semaphore;
3880140786SRajendra Nayak 	u32 prcm_block_offset;
3980140786SRajendra Nayak 	u32 sdrc_block_offset;
4080140786SRajendra Nayak };
4180140786SRajendra Nayak 
4280140786SRajendra Nayak struct omap3_scratchpad_prcm_block {
4380140786SRajendra Nayak 	u32 prm_clksrc_ctrl;
4480140786SRajendra Nayak 	u32 prm_clksel;
4580140786SRajendra Nayak 	u32 cm_clksel_core;
4680140786SRajendra Nayak 	u32 cm_clksel_wkup;
4780140786SRajendra Nayak 	u32 cm_clken_pll;
4880140786SRajendra Nayak 	u32 cm_autoidle_pll;
4980140786SRajendra Nayak 	u32 cm_clksel1_pll;
5080140786SRajendra Nayak 	u32 cm_clksel2_pll;
5180140786SRajendra Nayak 	u32 cm_clksel3_pll;
5280140786SRajendra Nayak 	u32 cm_clken_pll_mpu;
5380140786SRajendra Nayak 	u32 cm_autoidle_pll_mpu;
5480140786SRajendra Nayak 	u32 cm_clksel1_pll_mpu;
5580140786SRajendra Nayak 	u32 cm_clksel2_pll_mpu;
5680140786SRajendra Nayak 	u32 prcm_block_size;
5780140786SRajendra Nayak };
5880140786SRajendra Nayak 
5980140786SRajendra Nayak struct omap3_scratchpad_sdrc_block {
6080140786SRajendra Nayak 	u16 sysconfig;
6180140786SRajendra Nayak 	u16 cs_cfg;
6280140786SRajendra Nayak 	u16 sharing;
6380140786SRajendra Nayak 	u16 err_type;
6480140786SRajendra Nayak 	u32 dll_a_ctrl;
6580140786SRajendra Nayak 	u32 dll_b_ctrl;
6680140786SRajendra Nayak 	u32 power;
6780140786SRajendra Nayak 	u32 cs_0;
6880140786SRajendra Nayak 	u32 mcfg_0;
6980140786SRajendra Nayak 	u16 mr_0;
7080140786SRajendra Nayak 	u16 emr_1_0;
7180140786SRajendra Nayak 	u16 emr_2_0;
7280140786SRajendra Nayak 	u16 emr_3_0;
7380140786SRajendra Nayak 	u32 actim_ctrla_0;
7480140786SRajendra Nayak 	u32 actim_ctrlb_0;
7580140786SRajendra Nayak 	u32 rfr_ctrl_0;
7680140786SRajendra Nayak 	u32 cs_1;
7780140786SRajendra Nayak 	u32 mcfg_1;
7880140786SRajendra Nayak 	u16 mr_1;
7980140786SRajendra Nayak 	u16 emr_1_1;
8080140786SRajendra Nayak 	u16 emr_2_1;
8180140786SRajendra Nayak 	u16 emr_3_1;
8280140786SRajendra Nayak 	u32 actim_ctrla_1;
8380140786SRajendra Nayak 	u32 actim_ctrlb_1;
8480140786SRajendra Nayak 	u32 rfr_ctrl_1;
8580140786SRajendra Nayak 	u16 dcdl_1_ctrl;
8680140786SRajendra Nayak 	u16 dcdl_2_ctrl;
8780140786SRajendra Nayak 	u32 flags;
8880140786SRajendra Nayak 	u32 block_size;
8980140786SRajendra Nayak };
9080140786SRajendra Nayak 
9127d59a4aSTero Kristo void *omap3_secure_ram_storage;
9227d59a4aSTero Kristo 
9380140786SRajendra Nayak /*
9480140786SRajendra Nayak  * This is used to store ARM registers in SDRAM before attempting
9580140786SRajendra Nayak  * an MPU OFF. The save and restore happens from the SRAM sleep code.
9680140786SRajendra Nayak  * The address is stored in scratchpad, so that it can be used
9780140786SRajendra Nayak  * during the restore path.
9880140786SRajendra Nayak  */
9980140786SRajendra Nayak u32 omap3_arm_context[128];
10080140786SRajendra Nayak 
101c96631e1SRajendra Nayak struct omap3_control_regs {
102c96631e1SRajendra Nayak 	u32 sysconfig;
103c96631e1SRajendra Nayak 	u32 devconf0;
104c96631e1SRajendra Nayak 	u32 mem_dftrw0;
105c96631e1SRajendra Nayak 	u32 mem_dftrw1;
106c96631e1SRajendra Nayak 	u32 msuspendmux_0;
107c96631e1SRajendra Nayak 	u32 msuspendmux_1;
108c96631e1SRajendra Nayak 	u32 msuspendmux_2;
109c96631e1SRajendra Nayak 	u32 msuspendmux_3;
110c96631e1SRajendra Nayak 	u32 msuspendmux_4;
111c96631e1SRajendra Nayak 	u32 msuspendmux_5;
112c96631e1SRajendra Nayak 	u32 sec_ctrl;
113c96631e1SRajendra Nayak 	u32 devconf1;
114c96631e1SRajendra Nayak 	u32 csirxfe;
115c96631e1SRajendra Nayak 	u32 iva2_bootaddr;
116c96631e1SRajendra Nayak 	u32 iva2_bootmod;
117c96631e1SRajendra Nayak 	u32 debobs_0;
118c96631e1SRajendra Nayak 	u32 debobs_1;
119c96631e1SRajendra Nayak 	u32 debobs_2;
120c96631e1SRajendra Nayak 	u32 debobs_3;
121c96631e1SRajendra Nayak 	u32 debobs_4;
122c96631e1SRajendra Nayak 	u32 debobs_5;
123c96631e1SRajendra Nayak 	u32 debobs_6;
124c96631e1SRajendra Nayak 	u32 debobs_7;
125c96631e1SRajendra Nayak 	u32 debobs_8;
126c96631e1SRajendra Nayak 	u32 prog_io0;
127c96631e1SRajendra Nayak 	u32 prog_io1;
128c96631e1SRajendra Nayak 	u32 dss_dpll_spreading;
129c96631e1SRajendra Nayak 	u32 core_dpll_spreading;
130c96631e1SRajendra Nayak 	u32 per_dpll_spreading;
131c96631e1SRajendra Nayak 	u32 usbhost_dpll_spreading;
132c96631e1SRajendra Nayak 	u32 pbias_lite;
133c96631e1SRajendra Nayak 	u32 temp_sensor;
134c96631e1SRajendra Nayak 	u32 sramldo4;
135c96631e1SRajendra Nayak 	u32 sramldo5;
136c96631e1SRajendra Nayak 	u32 csi;
137*f5f9d132SPaul Walmsley 	u32 padconf_sys_nirq;
138c96631e1SRajendra Nayak };
139c96631e1SRajendra Nayak 
140c96631e1SRajendra Nayak static struct omap3_control_regs control_context;
141c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
142c96631e1SRajendra Nayak 
143a58caad1STony Lindgren #define OMAP_CTRL_REGADDR(reg)		(omap2_ctrl_base + (reg))
14470ba71a2SSantosh Shilimkar #define OMAP4_CTRL_PAD_REGADDR(reg)	(omap4_ctrl_pad_base + (reg))
14569d88a00SPaul Walmsley 
146a58caad1STony Lindgren void __init omap2_set_globals_control(struct omap_globals *omap2_globals)
14769d88a00SPaul Walmsley {
148b7ebb10bSSantosh Shilimkar 	/* Static mapping, never released */
149b7ebb10bSSantosh Shilimkar 	if (omap2_globals->ctrl) {
150b7ebb10bSSantosh Shilimkar 		omap2_ctrl_base = ioremap(omap2_globals->ctrl, SZ_4K);
151b7ebb10bSSantosh Shilimkar 		WARN_ON(!omap2_ctrl_base);
152b7ebb10bSSantosh Shilimkar 	}
1530c349246SSantosh Shilimkar 
1540c349246SSantosh Shilimkar 	/* Static mapping, never released */
1550c349246SSantosh Shilimkar 	if (omap2_globals->ctrl_pad) {
1560c349246SSantosh Shilimkar 		omap4_ctrl_pad_base = ioremap(omap2_globals->ctrl_pad, SZ_4K);
1570c349246SSantosh Shilimkar 		WARN_ON(!omap4_ctrl_pad_base);
1580c349246SSantosh Shilimkar 	}
15969d88a00SPaul Walmsley }
16069d88a00SPaul Walmsley 
161a58caad1STony Lindgren void __iomem *omap_ctrl_base_get(void)
16269d88a00SPaul Walmsley {
16369d88a00SPaul Walmsley 	return omap2_ctrl_base;
16469d88a00SPaul Walmsley }
16569d88a00SPaul Walmsley 
16669d88a00SPaul Walmsley u8 omap_ctrl_readb(u16 offset)
16769d88a00SPaul Walmsley {
16869d88a00SPaul Walmsley 	return __raw_readb(OMAP_CTRL_REGADDR(offset));
16969d88a00SPaul Walmsley }
17069d88a00SPaul Walmsley 
17169d88a00SPaul Walmsley u16 omap_ctrl_readw(u16 offset)
17269d88a00SPaul Walmsley {
17369d88a00SPaul Walmsley 	return __raw_readw(OMAP_CTRL_REGADDR(offset));
17469d88a00SPaul Walmsley }
17569d88a00SPaul Walmsley 
17669d88a00SPaul Walmsley u32 omap_ctrl_readl(u16 offset)
17769d88a00SPaul Walmsley {
17869d88a00SPaul Walmsley 	return __raw_readl(OMAP_CTRL_REGADDR(offset));
17969d88a00SPaul Walmsley }
18069d88a00SPaul Walmsley 
18169d88a00SPaul Walmsley void omap_ctrl_writeb(u8 val, u16 offset)
18269d88a00SPaul Walmsley {
18369d88a00SPaul Walmsley 	__raw_writeb(val, OMAP_CTRL_REGADDR(offset));
18469d88a00SPaul Walmsley }
18569d88a00SPaul Walmsley 
18669d88a00SPaul Walmsley void omap_ctrl_writew(u16 val, u16 offset)
18769d88a00SPaul Walmsley {
18869d88a00SPaul Walmsley 	__raw_writew(val, OMAP_CTRL_REGADDR(offset));
18969d88a00SPaul Walmsley }
19069d88a00SPaul Walmsley 
19169d88a00SPaul Walmsley void omap_ctrl_writel(u32 val, u16 offset)
19269d88a00SPaul Walmsley {
19369d88a00SPaul Walmsley 	__raw_writel(val, OMAP_CTRL_REGADDR(offset));
19469d88a00SPaul Walmsley }
19569d88a00SPaul Walmsley 
19670ba71a2SSantosh Shilimkar /*
19770ba71a2SSantosh Shilimkar  * On OMAP4 control pad are not addressable from control
19870ba71a2SSantosh Shilimkar  * core base. So the common omap_ctrl_read/write APIs breaks
19970ba71a2SSantosh Shilimkar  * Hence export separate APIs to manage the omap4 pad control
20070ba71a2SSantosh Shilimkar  * registers. This APIs will work only for OMAP4
20170ba71a2SSantosh Shilimkar  */
20270ba71a2SSantosh Shilimkar 
20370ba71a2SSantosh Shilimkar u32 omap4_ctrl_pad_readl(u16 offset)
20470ba71a2SSantosh Shilimkar {
20570ba71a2SSantosh Shilimkar 	return __raw_readl(OMAP4_CTRL_PAD_REGADDR(offset));
20670ba71a2SSantosh Shilimkar }
20770ba71a2SSantosh Shilimkar 
20870ba71a2SSantosh Shilimkar void omap4_ctrl_pad_writel(u32 val, u16 offset)
20970ba71a2SSantosh Shilimkar {
21070ba71a2SSantosh Shilimkar 	__raw_writel(val, OMAP4_CTRL_PAD_REGADDR(offset));
21170ba71a2SSantosh Shilimkar }
21270ba71a2SSantosh Shilimkar 
213166353bdSPaul Walmsley #ifdef CONFIG_ARCH_OMAP3
214166353bdSPaul Walmsley 
215166353bdSPaul Walmsley /**
216166353bdSPaul Walmsley  * omap3_ctrl_write_boot_mode - set scratchpad boot mode for the next boot
217166353bdSPaul Walmsley  * @bootmode: 8-bit value to pass to some boot code
218166353bdSPaul Walmsley  *
219166353bdSPaul Walmsley  * Set the bootmode in the scratchpad RAM.  This is used after the
220166353bdSPaul Walmsley  * system restarts.  Not sure what actually uses this - it may be the
221166353bdSPaul Walmsley  * bootloader, rather than the boot ROM - contrary to the preserved
222166353bdSPaul Walmsley  * comment below.  No return value.
223166353bdSPaul Walmsley  */
224166353bdSPaul Walmsley void omap3_ctrl_write_boot_mode(u8 bootmode)
225166353bdSPaul Walmsley {
226166353bdSPaul Walmsley 	u32 l;
227166353bdSPaul Walmsley 
228166353bdSPaul Walmsley 	l = ('B' << 24) | ('M' << 16) | bootmode;
229166353bdSPaul Walmsley 
230166353bdSPaul Walmsley 	/*
231166353bdSPaul Walmsley 	 * Reserve the first word in scratchpad for communicating
232166353bdSPaul Walmsley 	 * with the boot ROM. A pointer to a data structure
233166353bdSPaul Walmsley 	 * describing the boot process can be stored there,
234166353bdSPaul Walmsley 	 * cf. OMAP34xx TRM, Initialization / Software Booting
235166353bdSPaul Walmsley 	 * Configuration.
236166353bdSPaul Walmsley 	 *
237166353bdSPaul Walmsley 	 * XXX This should use some omap_ctrl_writel()-type function
238166353bdSPaul Walmsley 	 */
239166353bdSPaul Walmsley 	__raw_writel(l, OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD + 4));
240166353bdSPaul Walmsley }
241166353bdSPaul Walmsley 
242166353bdSPaul Walmsley #endif
243166353bdSPaul Walmsley 
244c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
24580140786SRajendra Nayak /*
24680140786SRajendra Nayak  * Clears the scratchpad contents in case of cold boot-
24780140786SRajendra Nayak  * called during bootup
24880140786SRajendra Nayak  */
24980140786SRajendra Nayak void omap3_clear_scratchpad_contents(void)
25080140786SRajendra Nayak {
25180140786SRajendra Nayak 	u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET;
2524d63bc1dSManjunath Kondaiah G 	void __iomem *v_addr;
25380140786SRajendra Nayak 	u32 offset = 0;
25480140786SRajendra Nayak 	v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM);
25580140786SRajendra Nayak 	if (prm_read_mod_reg(OMAP3430_GR_MOD, OMAP3_PRM_RSTST_OFFSET) &
2562bc4ef71SPaul Walmsley 	    OMAP3430_GLOBAL_COLD_RST_MASK) {
25780140786SRajendra Nayak 		for ( ; offset <= max_offset; offset += 0x4)
25880140786SRajendra Nayak 			__raw_writel(0x0, (v_addr + offset));
2592bc4ef71SPaul Walmsley 		prm_set_mod_reg_bits(OMAP3430_GLOBAL_COLD_RST_MASK,
2602bc4ef71SPaul Walmsley 				     OMAP3430_GR_MOD,
26180140786SRajendra Nayak 				     OMAP3_PRM_RSTST_OFFSET);
26280140786SRajendra Nayak 	}
26380140786SRajendra Nayak }
26480140786SRajendra Nayak 
26580140786SRajendra Nayak /* Populate the scratchpad structure with restore structure */
26680140786SRajendra Nayak void omap3_save_scratchpad_contents(void)
26780140786SRajendra Nayak {
2684d63bc1dSManjunath Kondaiah G 	void  __iomem *scratchpad_address;
26980140786SRajendra Nayak 	u32 arm_context_addr;
27080140786SRajendra Nayak 	struct omap3_scratchpad scratchpad_contents;
27180140786SRajendra Nayak 	struct omap3_scratchpad_prcm_block prcm_block_contents;
27280140786SRajendra Nayak 	struct omap3_scratchpad_sdrc_block sdrc_block_contents;
27380140786SRajendra Nayak 
274f7dfe3d8SJean Pihet 	/*
275f7dfe3d8SJean Pihet 	 * Populate the Scratchpad contents
276f7dfe3d8SJean Pihet 	 *
277f7dfe3d8SJean Pihet 	 * The "get_*restore_pointer" functions are used to provide a
278f7dfe3d8SJean Pihet 	 * physical restore address where the ROM code jumps while waking
279f7dfe3d8SJean Pihet 	 * up from MPU OFF/OSWR state.
280f7dfe3d8SJean Pihet 	 * The restore pointer is stored into the scratchpad.
281f7dfe3d8SJean Pihet 	 */
28280140786SRajendra Nayak 	scratchpad_contents.boot_config_ptr = 0x0;
283458e999eSNishanth Menon 	if (cpu_is_omap3630())
284458e999eSNishanth Menon 		scratchpad_contents.public_restore_ptr =
285458e999eSNishanth Menon 			virt_to_phys(get_omap3630_restore_pointer());
286458e999eSNishanth Menon 	else if (omap_rev() != OMAP3430_REV_ES3_0 &&
2870795a75aSTero Kristo 					omap_rev() != OMAP3430_REV_ES3_1)
28880140786SRajendra Nayak 		scratchpad_contents.public_restore_ptr =
28980140786SRajendra Nayak 			virt_to_phys(get_restore_pointer());
2900795a75aSTero Kristo 	else
2910795a75aSTero Kristo 		scratchpad_contents.public_restore_ptr =
2920795a75aSTero Kristo 			virt_to_phys(get_es3_restore_pointer());
29327d59a4aSTero Kristo 	if (omap_type() == OMAP2_DEVICE_TYPE_GP)
29480140786SRajendra Nayak 		scratchpad_contents.secure_ram_restore_ptr = 0x0;
29527d59a4aSTero Kristo 	else
29627d59a4aSTero Kristo 		scratchpad_contents.secure_ram_restore_ptr =
29727d59a4aSTero Kristo 			(u32) __pa(omap3_secure_ram_storage);
29880140786SRajendra Nayak 	scratchpad_contents.sdrc_module_semaphore = 0x0;
29980140786SRajendra Nayak 	scratchpad_contents.prcm_block_offset = 0x2C;
30080140786SRajendra Nayak 	scratchpad_contents.sdrc_block_offset = 0x64;
30180140786SRajendra Nayak 
30280140786SRajendra Nayak 	/* Populate the PRCM block contents */
30380140786SRajendra Nayak 	prcm_block_contents.prm_clksrc_ctrl = prm_read_mod_reg(OMAP3430_GR_MOD,
30480140786SRajendra Nayak 			OMAP3_PRM_CLKSRC_CTRL_OFFSET);
30580140786SRajendra Nayak 	prcm_block_contents.prm_clksel = prm_read_mod_reg(OMAP3430_CCR_MOD,
30680140786SRajendra Nayak 			OMAP3_PRM_CLKSEL_OFFSET);
30780140786SRajendra Nayak 	prcm_block_contents.cm_clksel_core =
30880140786SRajendra Nayak 			cm_read_mod_reg(CORE_MOD, CM_CLKSEL);
30980140786SRajendra Nayak 	prcm_block_contents.cm_clksel_wkup =
31080140786SRajendra Nayak 			cm_read_mod_reg(WKUP_MOD, CM_CLKSEL);
31180140786SRajendra Nayak 	prcm_block_contents.cm_clken_pll =
312cb0cb2b8SKalle Jokiniemi 			cm_read_mod_reg(PLL_MOD, CM_CLKEN);
31380140786SRajendra Nayak 	prcm_block_contents.cm_autoidle_pll =
31480140786SRajendra Nayak 			cm_read_mod_reg(PLL_MOD, OMAP3430_CM_AUTOIDLE_PLL);
31580140786SRajendra Nayak 	prcm_block_contents.cm_clksel1_pll =
31680140786SRajendra Nayak 			cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL1_PLL);
31780140786SRajendra Nayak 	prcm_block_contents.cm_clksel2_pll =
31880140786SRajendra Nayak 			cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL2_PLL);
31980140786SRajendra Nayak 	prcm_block_contents.cm_clksel3_pll =
32080140786SRajendra Nayak 			cm_read_mod_reg(PLL_MOD, OMAP3430_CM_CLKSEL3);
32180140786SRajendra Nayak 	prcm_block_contents.cm_clken_pll_mpu =
32280140786SRajendra Nayak 			cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKEN_PLL);
32380140786SRajendra Nayak 	prcm_block_contents.cm_autoidle_pll_mpu =
32480140786SRajendra Nayak 			cm_read_mod_reg(MPU_MOD, OMAP3430_CM_AUTOIDLE_PLL);
32580140786SRajendra Nayak 	prcm_block_contents.cm_clksel1_pll_mpu =
32680140786SRajendra Nayak 			cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL);
32780140786SRajendra Nayak 	prcm_block_contents.cm_clksel2_pll_mpu =
32880140786SRajendra Nayak 			cm_read_mod_reg(MPU_MOD, OMAP3430_CM_CLKSEL2_PLL);
32980140786SRajendra Nayak 	prcm_block_contents.prcm_block_size = 0x0;
33080140786SRajendra Nayak 
33180140786SRajendra Nayak 	/* Populate the SDRC block contents */
33280140786SRajendra Nayak 	sdrc_block_contents.sysconfig =
33380140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF);
33480140786SRajendra Nayak 	sdrc_block_contents.cs_cfg =
33580140786SRajendra Nayak 			(sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF);
33680140786SRajendra Nayak 	sdrc_block_contents.sharing =
33780140786SRajendra Nayak 			(sdrc_read_reg(SDRC_SHARING) & 0xFFFF);
33880140786SRajendra Nayak 	sdrc_block_contents.err_type =
33980140786SRajendra Nayak 			(sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF);
34080140786SRajendra Nayak 	sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL);
34180140786SRajendra Nayak 	sdrc_block_contents.dll_b_ctrl = 0x0;
342f265dc4cSRajendra Nayak 	/*
343f265dc4cSRajendra Nayak 	 * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should
344f265dc4cSRajendra Nayak 	 * be programed to issue automatic self refresh on timeout
345f265dc4cSRajendra Nayak 	 * of AUTO_CNT = 1 prior to any transition to OFF mode.
346f265dc4cSRajendra Nayak 	 */
347f265dc4cSRajendra Nayak 	if ((omap_type() != OMAP2_DEVICE_TYPE_GP)
348f265dc4cSRajendra Nayak 			&& (omap_rev() >= OMAP3430_REV_ES3_0))
349f265dc4cSRajendra Nayak 		sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) &
350f265dc4cSRajendra Nayak 				~(SDRC_POWER_AUTOCOUNT_MASK|
351f265dc4cSRajendra Nayak 				SDRC_POWER_CLKCTRL_MASK)) |
352f265dc4cSRajendra Nayak 				(1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
353f265dc4cSRajendra Nayak 				SDRC_SELF_REFRESH_ON_AUTOCOUNT;
354f265dc4cSRajendra Nayak 	else
35580140786SRajendra Nayak 		sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER);
356f265dc4cSRajendra Nayak 
35780140786SRajendra Nayak 	sdrc_block_contents.cs_0 = 0x0;
35880140786SRajendra Nayak 	sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0);
35980140786SRajendra Nayak 	sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF);
36080140786SRajendra Nayak 	sdrc_block_contents.emr_1_0 = 0x0;
36180140786SRajendra Nayak 	sdrc_block_contents.emr_2_0 = 0x0;
36280140786SRajendra Nayak 	sdrc_block_contents.emr_3_0 = 0x0;
36380140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_0 =
36480140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_0);
36580140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_0 =
36680140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_0);
36780140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_0 =
36880140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_0);
36980140786SRajendra Nayak 	sdrc_block_contents.cs_1 = 0x0;
37080140786SRajendra Nayak 	sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1);
37180140786SRajendra Nayak 	sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF;
37280140786SRajendra Nayak 	sdrc_block_contents.emr_1_1 = 0x0;
37380140786SRajendra Nayak 	sdrc_block_contents.emr_2_1 = 0x0;
37480140786SRajendra Nayak 	sdrc_block_contents.emr_3_1 = 0x0;
37580140786SRajendra Nayak 	sdrc_block_contents.actim_ctrla_1 =
37680140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_A_1);
37780140786SRajendra Nayak 	sdrc_block_contents.actim_ctrlb_1 =
37880140786SRajendra Nayak 			sdrc_read_reg(SDRC_ACTIM_CTRL_B_1);
37980140786SRajendra Nayak 	sdrc_block_contents.rfr_ctrl_1 =
38080140786SRajendra Nayak 			sdrc_read_reg(SDRC_RFR_CTRL_1);
38180140786SRajendra Nayak 	sdrc_block_contents.dcdl_1_ctrl = 0x0;
38280140786SRajendra Nayak 	sdrc_block_contents.dcdl_2_ctrl = 0x0;
38380140786SRajendra Nayak 	sdrc_block_contents.flags = 0x0;
38480140786SRajendra Nayak 	sdrc_block_contents.block_size = 0x0;
38580140786SRajendra Nayak 
38680140786SRajendra Nayak 	arm_context_addr = virt_to_phys(omap3_arm_context);
38780140786SRajendra Nayak 
38880140786SRajendra Nayak 	/* Copy all the contents to the scratchpad location */
38980140786SRajendra Nayak 	scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
39080140786SRajendra Nayak 	memcpy_toio(scratchpad_address, &scratchpad_contents,
39180140786SRajendra Nayak 		 sizeof(scratchpad_contents));
39280140786SRajendra Nayak 	/* Scratchpad contents being 32 bits, a divide by 4 done here */
39380140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
39480140786SRajendra Nayak 		scratchpad_contents.prcm_block_offset,
39580140786SRajendra Nayak 		&prcm_block_contents, sizeof(prcm_block_contents));
39680140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
39780140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset,
39880140786SRajendra Nayak 		&sdrc_block_contents, sizeof(sdrc_block_contents));
39980140786SRajendra Nayak 	/*
40080140786SRajendra Nayak 	 * Copies the address of the location in SDRAM where ARM
40180140786SRajendra Nayak 	 * registers get saved during a MPU OFF transition.
40280140786SRajendra Nayak 	 */
40380140786SRajendra Nayak 	memcpy_toio(scratchpad_address +
40480140786SRajendra Nayak 		scratchpad_contents.sdrc_block_offset +
40580140786SRajendra Nayak 		sizeof(sdrc_block_contents), &arm_context_addr, 4);
40680140786SRajendra Nayak }
40780140786SRajendra Nayak 
408c96631e1SRajendra Nayak void omap3_control_save_context(void)
409c96631e1SRajendra Nayak {
410c96631e1SRajendra Nayak 	control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG);
411c96631e1SRajendra Nayak 	control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
412c96631e1SRajendra Nayak 	control_context.mem_dftrw0 =
413c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0);
414c96631e1SRajendra Nayak 	control_context.mem_dftrw1 =
415c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1);
416c96631e1SRajendra Nayak 	control_context.msuspendmux_0 =
417c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0);
418c96631e1SRajendra Nayak 	control_context.msuspendmux_1 =
419c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1);
420c96631e1SRajendra Nayak 	control_context.msuspendmux_2 =
421c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2);
422c96631e1SRajendra Nayak 	control_context.msuspendmux_3 =
423c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3);
424c96631e1SRajendra Nayak 	control_context.msuspendmux_4 =
425c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4);
426c96631e1SRajendra Nayak 	control_context.msuspendmux_5 =
427c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5);
428c96631e1SRajendra Nayak 	control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL);
429c96631e1SRajendra Nayak 	control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
430c96631e1SRajendra Nayak 	control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE);
431c96631e1SRajendra Nayak 	control_context.iva2_bootaddr =
432c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR);
433c96631e1SRajendra Nayak 	control_context.iva2_bootmod =
434c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD);
435c96631e1SRajendra Nayak 	control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0));
436c96631e1SRajendra Nayak 	control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1));
437c96631e1SRajendra Nayak 	control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2));
438c96631e1SRajendra Nayak 	control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3));
439c96631e1SRajendra Nayak 	control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4));
440c96631e1SRajendra Nayak 	control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5));
441c96631e1SRajendra Nayak 	control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6));
442c96631e1SRajendra Nayak 	control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7));
443c96631e1SRajendra Nayak 	control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8));
444c96631e1SRajendra Nayak 	control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0);
445c96631e1SRajendra Nayak 	control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
446c96631e1SRajendra Nayak 	control_context.dss_dpll_spreading =
447c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING);
448c96631e1SRajendra Nayak 	control_context.core_dpll_spreading =
449c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING);
450c96631e1SRajendra Nayak 	control_context.per_dpll_spreading =
451c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING);
452c96631e1SRajendra Nayak 	control_context.usbhost_dpll_spreading =
453c96631e1SRajendra Nayak 		omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
454c96631e1SRajendra Nayak 	control_context.pbias_lite =
455c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE);
456c96631e1SRajendra Nayak 	control_context.temp_sensor =
457c96631e1SRajendra Nayak 			omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR);
458c96631e1SRajendra Nayak 	control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4);
459c96631e1SRajendra Nayak 	control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5);
460c96631e1SRajendra Nayak 	control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI);
461*f5f9d132SPaul Walmsley 	control_context.padconf_sys_nirq =
462*f5f9d132SPaul Walmsley 		omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ);
463c96631e1SRajendra Nayak 	return;
464c96631e1SRajendra Nayak }
465c96631e1SRajendra Nayak 
466c96631e1SRajendra Nayak void omap3_control_restore_context(void)
467c96631e1SRajendra Nayak {
468c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG);
469c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0);
470c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw0,
471c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW0);
472c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.mem_dftrw1,
473c96631e1SRajendra Nayak 					OMAP343X_CONTROL_MEM_DFTRW1);
474c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_0,
475c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_0);
476c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_1,
477c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_1);
478c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_2,
479c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_2);
480c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_3,
481c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_3);
482c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_4,
483c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_4);
484c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.msuspendmux_5,
485c96631e1SRajendra Nayak 					OMAP2_CONTROL_MSUSPENDMUX_5);
486c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL);
487c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1);
488c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE);
489c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootaddr,
490c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTADDR);
491c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.iva2_bootmod,
492c96631e1SRajendra Nayak 					OMAP343X_CONTROL_IVA2_BOOTMOD);
493c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0));
494c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1));
495c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2));
496c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3));
497c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4));
498c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5));
499c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6));
500c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7));
501c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8));
502c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0);
503c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1);
504c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.dss_dpll_spreading,
505c96631e1SRajendra Nayak 					OMAP343X_CONTROL_DSS_DPLL_SPREADING);
506c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.core_dpll_spreading,
507c96631e1SRajendra Nayak 					OMAP343X_CONTROL_CORE_DPLL_SPREADING);
508c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.per_dpll_spreading,
509c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PER_DPLL_SPREADING);
510c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.usbhost_dpll_spreading,
511c96631e1SRajendra Nayak 				OMAP343X_CONTROL_USBHOST_DPLL_SPREADING);
512c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.pbias_lite,
513c96631e1SRajendra Nayak 					OMAP343X_CONTROL_PBIAS_LITE);
514c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.temp_sensor,
515c96631e1SRajendra Nayak 					OMAP343X_CONTROL_TEMP_SENSOR);
516c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4);
517c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5);
518c96631e1SRajendra Nayak 	omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI);
519*f5f9d132SPaul Walmsley 	omap_ctrl_writel(control_context.padconf_sys_nirq,
520*f5f9d132SPaul Walmsley 			 OMAP343X_CONTROL_PADCONF_SYSNIRQ);
521c96631e1SRajendra Nayak 	return;
522c96631e1SRajendra Nayak }
523458e999eSNishanth Menon 
524458e999eSNishanth Menon void omap3630_ctrl_disable_rta(void)
525458e999eSNishanth Menon {
526458e999eSNishanth Menon 	if (!cpu_is_omap3630())
527458e999eSNishanth Menon 		return;
528458e999eSNishanth Menon 	omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL);
529458e999eSNishanth Menon }
530458e999eSNishanth Menon 
531c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
532