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> 1769d88a00SPaul Walmsley 18dbc04161STony Lindgren #include "soc.h" 19ee0839c2STony Lindgren #include "iomap.h" 20ee0839c2STony Lindgren #include "common.h" 2180140786SRajendra Nayak #include "cm-regbits-34xx.h" 2280140786SRajendra Nayak #include "prm-regbits-34xx.h" 23139563adSPaul Walmsley #include "prm3xxx.h" 24ff4ae5d9SPaul Walmsley #include "cm3xxx.h" 2580140786SRajendra Nayak #include "sdrc.h" 2638815733SManjunath Kondaiah G #include "pm.h" 274814ced5SPaul Walmsley #include "control.h" 2869d88a00SPaul Walmsley 29596efe47SPaul Walmsley /* Used by omap3_ctrl_save_padconf() */ 30596efe47SPaul Walmsley #define START_PADCONF_SAVE 0x2 31596efe47SPaul Walmsley #define PADCONF_SAVE_DONE 0x1 32596efe47SPaul Walmsley 33a58caad1STony Lindgren static void __iomem *omap2_ctrl_base; 340c349246SSantosh Shilimkar static void __iomem *omap4_ctrl_pad_base; 3569d88a00SPaul Walmsley 36c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) 3780140786SRajendra Nayak struct omap3_scratchpad { 3880140786SRajendra Nayak u32 boot_config_ptr; 3980140786SRajendra Nayak u32 public_restore_ptr; 4080140786SRajendra Nayak u32 secure_ram_restore_ptr; 4180140786SRajendra Nayak u32 sdrc_module_semaphore; 4280140786SRajendra Nayak u32 prcm_block_offset; 4380140786SRajendra Nayak u32 sdrc_block_offset; 4480140786SRajendra Nayak }; 4580140786SRajendra Nayak 4680140786SRajendra Nayak struct omap3_scratchpad_prcm_block { 477e28b465STero Kristo u32 prm_contents[2]; 48c6a2d839STero Kristo u32 cm_contents[11]; 4980140786SRajendra Nayak u32 prcm_block_size; 5080140786SRajendra Nayak }; 5180140786SRajendra Nayak 5280140786SRajendra Nayak struct omap3_scratchpad_sdrc_block { 5380140786SRajendra Nayak u16 sysconfig; 5480140786SRajendra Nayak u16 cs_cfg; 5580140786SRajendra Nayak u16 sharing; 5680140786SRajendra Nayak u16 err_type; 5780140786SRajendra Nayak u32 dll_a_ctrl; 5880140786SRajendra Nayak u32 dll_b_ctrl; 5980140786SRajendra Nayak u32 power; 6080140786SRajendra Nayak u32 cs_0; 6180140786SRajendra Nayak u32 mcfg_0; 6280140786SRajendra Nayak u16 mr_0; 6380140786SRajendra Nayak u16 emr_1_0; 6480140786SRajendra Nayak u16 emr_2_0; 6580140786SRajendra Nayak u16 emr_3_0; 6680140786SRajendra Nayak u32 actim_ctrla_0; 6780140786SRajendra Nayak u32 actim_ctrlb_0; 6880140786SRajendra Nayak u32 rfr_ctrl_0; 6980140786SRajendra Nayak u32 cs_1; 7080140786SRajendra Nayak u32 mcfg_1; 7180140786SRajendra Nayak u16 mr_1; 7280140786SRajendra Nayak u16 emr_1_1; 7380140786SRajendra Nayak u16 emr_2_1; 7480140786SRajendra Nayak u16 emr_3_1; 7580140786SRajendra Nayak u32 actim_ctrla_1; 7680140786SRajendra Nayak u32 actim_ctrlb_1; 7780140786SRajendra Nayak u32 rfr_ctrl_1; 7880140786SRajendra Nayak u16 dcdl_1_ctrl; 7980140786SRajendra Nayak u16 dcdl_2_ctrl; 8080140786SRajendra Nayak u32 flags; 8180140786SRajendra Nayak u32 block_size; 8280140786SRajendra Nayak }; 8380140786SRajendra Nayak 8427d59a4aSTero Kristo void *omap3_secure_ram_storage; 8527d59a4aSTero Kristo 8680140786SRajendra Nayak /* 8780140786SRajendra Nayak * This is used to store ARM registers in SDRAM before attempting 8880140786SRajendra Nayak * an MPU OFF. The save and restore happens from the SRAM sleep code. 8980140786SRajendra Nayak * The address is stored in scratchpad, so that it can be used 9080140786SRajendra Nayak * during the restore path. 9180140786SRajendra Nayak */ 9280140786SRajendra Nayak u32 omap3_arm_context[128]; 9380140786SRajendra Nayak 94c96631e1SRajendra Nayak struct omap3_control_regs { 95c96631e1SRajendra Nayak u32 sysconfig; 96c96631e1SRajendra Nayak u32 devconf0; 97c96631e1SRajendra Nayak u32 mem_dftrw0; 98c96631e1SRajendra Nayak u32 mem_dftrw1; 99c96631e1SRajendra Nayak u32 msuspendmux_0; 100c96631e1SRajendra Nayak u32 msuspendmux_1; 101c96631e1SRajendra Nayak u32 msuspendmux_2; 102c96631e1SRajendra Nayak u32 msuspendmux_3; 103c96631e1SRajendra Nayak u32 msuspendmux_4; 104c96631e1SRajendra Nayak u32 msuspendmux_5; 105c96631e1SRajendra Nayak u32 sec_ctrl; 106c96631e1SRajendra Nayak u32 devconf1; 107c96631e1SRajendra Nayak u32 csirxfe; 108c96631e1SRajendra Nayak u32 iva2_bootaddr; 109c96631e1SRajendra Nayak u32 iva2_bootmod; 110c96631e1SRajendra Nayak u32 debobs_0; 111c96631e1SRajendra Nayak u32 debobs_1; 112c96631e1SRajendra Nayak u32 debobs_2; 113c96631e1SRajendra Nayak u32 debobs_3; 114c96631e1SRajendra Nayak u32 debobs_4; 115c96631e1SRajendra Nayak u32 debobs_5; 116c96631e1SRajendra Nayak u32 debobs_6; 117c96631e1SRajendra Nayak u32 debobs_7; 118c96631e1SRajendra Nayak u32 debobs_8; 119c96631e1SRajendra Nayak u32 prog_io0; 120c96631e1SRajendra Nayak u32 prog_io1; 121c96631e1SRajendra Nayak u32 dss_dpll_spreading; 122c96631e1SRajendra Nayak u32 core_dpll_spreading; 123c96631e1SRajendra Nayak u32 per_dpll_spreading; 124c96631e1SRajendra Nayak u32 usbhost_dpll_spreading; 125c96631e1SRajendra Nayak u32 pbias_lite; 126c96631e1SRajendra Nayak u32 temp_sensor; 127c96631e1SRajendra Nayak u32 sramldo4; 128c96631e1SRajendra Nayak u32 sramldo5; 129c96631e1SRajendra Nayak u32 csi; 130f5f9d132SPaul Walmsley u32 padconf_sys_nirq; 131c96631e1SRajendra Nayak }; 132c96631e1SRajendra Nayak 133c96631e1SRajendra Nayak static struct omap3_control_regs control_context; 134c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */ 135c96631e1SRajendra Nayak 136a58caad1STony Lindgren #define OMAP_CTRL_REGADDR(reg) (omap2_ctrl_base + (reg)) 13770ba71a2SSantosh Shilimkar #define OMAP4_CTRL_PAD_REGADDR(reg) (omap4_ctrl_pad_base + (reg)) 13869d88a00SPaul Walmsley 139b6a4226cSPaul Walmsley void __init omap2_set_globals_control(void __iomem *ctrl, 140b6a4226cSPaul Walmsley void __iomem *ctrl_pad) 14169d88a00SPaul Walmsley { 142b6a4226cSPaul Walmsley omap2_ctrl_base = ctrl; 143b6a4226cSPaul Walmsley omap4_ctrl_pad_base = ctrl_pad; 14469d88a00SPaul Walmsley } 14569d88a00SPaul Walmsley 146a58caad1STony Lindgren void __iomem *omap_ctrl_base_get(void) 14769d88a00SPaul Walmsley { 14869d88a00SPaul Walmsley return omap2_ctrl_base; 14969d88a00SPaul Walmsley } 15069d88a00SPaul Walmsley 15169d88a00SPaul Walmsley u8 omap_ctrl_readb(u16 offset) 15269d88a00SPaul Walmsley { 153edfaf05cSVictor Kamensky return readb_relaxed(OMAP_CTRL_REGADDR(offset)); 15469d88a00SPaul Walmsley } 15569d88a00SPaul Walmsley 15669d88a00SPaul Walmsley u16 omap_ctrl_readw(u16 offset) 15769d88a00SPaul Walmsley { 158edfaf05cSVictor Kamensky return readw_relaxed(OMAP_CTRL_REGADDR(offset)); 15969d88a00SPaul Walmsley } 16069d88a00SPaul Walmsley 16169d88a00SPaul Walmsley u32 omap_ctrl_readl(u16 offset) 16269d88a00SPaul Walmsley { 163edfaf05cSVictor Kamensky return readl_relaxed(OMAP_CTRL_REGADDR(offset)); 16469d88a00SPaul Walmsley } 16569d88a00SPaul Walmsley 16669d88a00SPaul Walmsley void omap_ctrl_writeb(u8 val, u16 offset) 16769d88a00SPaul Walmsley { 168edfaf05cSVictor Kamensky writeb_relaxed(val, OMAP_CTRL_REGADDR(offset)); 16969d88a00SPaul Walmsley } 17069d88a00SPaul Walmsley 17169d88a00SPaul Walmsley void omap_ctrl_writew(u16 val, u16 offset) 17269d88a00SPaul Walmsley { 173edfaf05cSVictor Kamensky writew_relaxed(val, OMAP_CTRL_REGADDR(offset)); 17469d88a00SPaul Walmsley } 17569d88a00SPaul Walmsley 17669d88a00SPaul Walmsley void omap_ctrl_writel(u32 val, u16 offset) 17769d88a00SPaul Walmsley { 178edfaf05cSVictor Kamensky writel_relaxed(val, OMAP_CTRL_REGADDR(offset)); 17969d88a00SPaul Walmsley } 18069d88a00SPaul Walmsley 18170ba71a2SSantosh Shilimkar /* 18270ba71a2SSantosh Shilimkar * On OMAP4 control pad are not addressable from control 18370ba71a2SSantosh Shilimkar * core base. So the common omap_ctrl_read/write APIs breaks 18470ba71a2SSantosh Shilimkar * Hence export separate APIs to manage the omap4 pad control 18570ba71a2SSantosh Shilimkar * registers. This APIs will work only for OMAP4 18670ba71a2SSantosh Shilimkar */ 18770ba71a2SSantosh Shilimkar 18870ba71a2SSantosh Shilimkar u32 omap4_ctrl_pad_readl(u16 offset) 18970ba71a2SSantosh Shilimkar { 190edfaf05cSVictor Kamensky return readl_relaxed(OMAP4_CTRL_PAD_REGADDR(offset)); 19170ba71a2SSantosh Shilimkar } 19270ba71a2SSantosh Shilimkar 19370ba71a2SSantosh Shilimkar void omap4_ctrl_pad_writel(u32 val, u16 offset) 19470ba71a2SSantosh Shilimkar { 195edfaf05cSVictor Kamensky writel_relaxed(val, OMAP4_CTRL_PAD_REGADDR(offset)); 19670ba71a2SSantosh Shilimkar } 19770ba71a2SSantosh Shilimkar 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 */ 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 22990f1380eSOmar Ramirez Luna /** 23090f1380eSOmar Ramirez Luna * omap_ctrl_write_dsp_boot_addr - set boot address for a remote processor 23190f1380eSOmar Ramirez Luna * @bootaddr: physical address of the boot loader 23290f1380eSOmar Ramirez Luna * 23390f1380eSOmar Ramirez Luna * Set boot address for the boot loader of a supported processor 23490f1380eSOmar Ramirez Luna * when a power ON sequence occurs. 23590f1380eSOmar Ramirez Luna */ 23690f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_addr(u32 bootaddr) 23790f1380eSOmar Ramirez Luna { 23890f1380eSOmar Ramirez Luna u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTADDR : 23990f1380eSOmar Ramirez Luna cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTADDR : 24090f1380eSOmar Ramirez Luna cpu_is_omap44xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR : 241668468b1SSuman Anna soc_is_omap54xx() ? OMAP4_CTRL_MODULE_CORE_DSP_BOOTADDR : 24290f1380eSOmar Ramirez Luna 0; 24390f1380eSOmar Ramirez Luna 24490f1380eSOmar Ramirez Luna if (!offset) { 24590f1380eSOmar Ramirez Luna pr_err("%s: unsupported omap type\n", __func__); 24690f1380eSOmar Ramirez Luna return; 24790f1380eSOmar Ramirez Luna } 24890f1380eSOmar Ramirez Luna 24990f1380eSOmar Ramirez Luna omap_ctrl_writel(bootaddr, offset); 25090f1380eSOmar Ramirez Luna } 25190f1380eSOmar Ramirez Luna 25290f1380eSOmar Ramirez Luna /** 25390f1380eSOmar Ramirez Luna * omap_ctrl_write_dsp_boot_mode - set boot mode for a remote processor 25490f1380eSOmar Ramirez Luna * @bootmode: 8-bit value to pass to some boot code 25590f1380eSOmar Ramirez Luna * 25690f1380eSOmar Ramirez Luna * Sets boot mode for the boot loader of a supported processor 25790f1380eSOmar Ramirez Luna * when a power ON sequence occurs. 25890f1380eSOmar Ramirez Luna */ 25990f1380eSOmar Ramirez Luna void omap_ctrl_write_dsp_boot_mode(u8 bootmode) 26090f1380eSOmar Ramirez Luna { 26190f1380eSOmar Ramirez Luna u32 offset = cpu_is_omap243x() ? OMAP243X_CONTROL_IVA2_BOOTMOD : 26290f1380eSOmar Ramirez Luna cpu_is_omap34xx() ? OMAP343X_CONTROL_IVA2_BOOTMOD : 26390f1380eSOmar Ramirez Luna 0; 26490f1380eSOmar Ramirez Luna 26590f1380eSOmar Ramirez Luna if (!offset) { 26690f1380eSOmar Ramirez Luna pr_err("%s: unsupported omap type\n", __func__); 26790f1380eSOmar Ramirez Luna return; 26890f1380eSOmar Ramirez Luna } 26990f1380eSOmar Ramirez Luna 27090f1380eSOmar Ramirez Luna omap_ctrl_writel(bootmode, offset); 27190f1380eSOmar Ramirez Luna } 27290f1380eSOmar Ramirez Luna 273c96631e1SRajendra Nayak #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) 27480140786SRajendra Nayak /* 27580140786SRajendra Nayak * Clears the scratchpad contents in case of cold boot- 27680140786SRajendra Nayak * called during bootup 27780140786SRajendra Nayak */ 27880140786SRajendra Nayak void omap3_clear_scratchpad_contents(void) 27980140786SRajendra Nayak { 28080140786SRajendra Nayak u32 max_offset = OMAP343X_SCRATCHPAD_ROM_OFFSET; 2814d63bc1dSManjunath Kondaiah G void __iomem *v_addr; 28280140786SRajendra Nayak u32 offset = 0; 28380140786SRajendra Nayak v_addr = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD_ROM); 2849efcea09STero Kristo if (omap3xxx_prm_clear_global_cold_reset()) { 28580140786SRajendra Nayak for ( ; offset <= max_offset; offset += 0x4) 286edfaf05cSVictor Kamensky writel_relaxed(0x0, (v_addr + offset)); 28780140786SRajendra Nayak } 28880140786SRajendra Nayak } 28980140786SRajendra Nayak 29080140786SRajendra Nayak /* Populate the scratchpad structure with restore structure */ 29180140786SRajendra Nayak void omap3_save_scratchpad_contents(void) 29280140786SRajendra Nayak { 2934d63bc1dSManjunath Kondaiah G void __iomem *scratchpad_address; 29480140786SRajendra Nayak u32 arm_context_addr; 29580140786SRajendra Nayak struct omap3_scratchpad scratchpad_contents; 29680140786SRajendra Nayak struct omap3_scratchpad_prcm_block prcm_block_contents; 29780140786SRajendra Nayak struct omap3_scratchpad_sdrc_block sdrc_block_contents; 29880140786SRajendra Nayak 299f7dfe3d8SJean Pihet /* 300f7dfe3d8SJean Pihet * Populate the Scratchpad contents 301f7dfe3d8SJean Pihet * 302f7dfe3d8SJean Pihet * The "get_*restore_pointer" functions are used to provide a 303f7dfe3d8SJean Pihet * physical restore address where the ROM code jumps while waking 304f7dfe3d8SJean Pihet * up from MPU OFF/OSWR state. 305f7dfe3d8SJean Pihet * The restore pointer is stored into the scratchpad. 306f7dfe3d8SJean Pihet */ 30780140786SRajendra Nayak scratchpad_contents.boot_config_ptr = 0x0; 308458e999eSNishanth Menon if (cpu_is_omap3630()) 309458e999eSNishanth Menon scratchpad_contents.public_restore_ptr = 31014c79bbeSKevin Hilman virt_to_phys(omap3_restore_3630); 311458e999eSNishanth Menon else if (omap_rev() != OMAP3430_REV_ES3_0 && 3120795a75aSTero Kristo omap_rev() != OMAP3430_REV_ES3_1) 31380140786SRajendra Nayak scratchpad_contents.public_restore_ptr = 31414c79bbeSKevin Hilman virt_to_phys(omap3_restore); 3150795a75aSTero Kristo else 3160795a75aSTero Kristo scratchpad_contents.public_restore_ptr = 31714c79bbeSKevin Hilman virt_to_phys(omap3_restore_es3); 31814c79bbeSKevin Hilman 31927d59a4aSTero Kristo if (omap_type() == OMAP2_DEVICE_TYPE_GP) 32080140786SRajendra Nayak scratchpad_contents.secure_ram_restore_ptr = 0x0; 32127d59a4aSTero Kristo else 32227d59a4aSTero Kristo scratchpad_contents.secure_ram_restore_ptr = 32327d59a4aSTero Kristo (u32) __pa(omap3_secure_ram_storage); 32480140786SRajendra Nayak scratchpad_contents.sdrc_module_semaphore = 0x0; 32580140786SRajendra Nayak scratchpad_contents.prcm_block_offset = 0x2C; 32680140786SRajendra Nayak scratchpad_contents.sdrc_block_offset = 0x64; 32780140786SRajendra Nayak 32880140786SRajendra Nayak /* Populate the PRCM block contents */ 3297e28b465STero Kristo omap3_prm_save_scratchpad_contents(prcm_block_contents.prm_contents); 330c6a2d839STero Kristo omap3_cm_save_scratchpad_contents(prcm_block_contents.cm_contents); 331c6a2d839STero Kristo 33280140786SRajendra Nayak prcm_block_contents.prcm_block_size = 0x0; 33380140786SRajendra Nayak 33480140786SRajendra Nayak /* Populate the SDRC block contents */ 33580140786SRajendra Nayak sdrc_block_contents.sysconfig = 33680140786SRajendra Nayak (sdrc_read_reg(SDRC_SYSCONFIG) & 0xFFFF); 33780140786SRajendra Nayak sdrc_block_contents.cs_cfg = 33880140786SRajendra Nayak (sdrc_read_reg(SDRC_CS_CFG) & 0xFFFF); 33980140786SRajendra Nayak sdrc_block_contents.sharing = 34080140786SRajendra Nayak (sdrc_read_reg(SDRC_SHARING) & 0xFFFF); 34180140786SRajendra Nayak sdrc_block_contents.err_type = 34280140786SRajendra Nayak (sdrc_read_reg(SDRC_ERR_TYPE) & 0xFFFF); 34380140786SRajendra Nayak sdrc_block_contents.dll_a_ctrl = sdrc_read_reg(SDRC_DLLA_CTRL); 34480140786SRajendra Nayak sdrc_block_contents.dll_b_ctrl = 0x0; 345f265dc4cSRajendra Nayak /* 346f265dc4cSRajendra Nayak * Due to a OMAP3 errata (1.142), on EMU/HS devices SRDC should 347f265dc4cSRajendra Nayak * be programed to issue automatic self refresh on timeout 348f265dc4cSRajendra Nayak * of AUTO_CNT = 1 prior to any transition to OFF mode. 349f265dc4cSRajendra Nayak */ 350f265dc4cSRajendra Nayak if ((omap_type() != OMAP2_DEVICE_TYPE_GP) 351f265dc4cSRajendra Nayak && (omap_rev() >= OMAP3430_REV_ES3_0)) 352f265dc4cSRajendra Nayak sdrc_block_contents.power = (sdrc_read_reg(SDRC_POWER) & 353f265dc4cSRajendra Nayak ~(SDRC_POWER_AUTOCOUNT_MASK| 354f265dc4cSRajendra Nayak SDRC_POWER_CLKCTRL_MASK)) | 355f265dc4cSRajendra Nayak (1 << SDRC_POWER_AUTOCOUNT_SHIFT) | 356f265dc4cSRajendra Nayak SDRC_SELF_REFRESH_ON_AUTOCOUNT; 357f265dc4cSRajendra Nayak else 35880140786SRajendra Nayak sdrc_block_contents.power = sdrc_read_reg(SDRC_POWER); 359f265dc4cSRajendra Nayak 36080140786SRajendra Nayak sdrc_block_contents.cs_0 = 0x0; 36180140786SRajendra Nayak sdrc_block_contents.mcfg_0 = sdrc_read_reg(SDRC_MCFG_0); 36280140786SRajendra Nayak sdrc_block_contents.mr_0 = (sdrc_read_reg(SDRC_MR_0) & 0xFFFF); 36380140786SRajendra Nayak sdrc_block_contents.emr_1_0 = 0x0; 36480140786SRajendra Nayak sdrc_block_contents.emr_2_0 = 0x0; 36580140786SRajendra Nayak sdrc_block_contents.emr_3_0 = 0x0; 36680140786SRajendra Nayak sdrc_block_contents.actim_ctrla_0 = 36780140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_A_0); 36880140786SRajendra Nayak sdrc_block_contents.actim_ctrlb_0 = 36980140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_B_0); 37080140786SRajendra Nayak sdrc_block_contents.rfr_ctrl_0 = 37180140786SRajendra Nayak sdrc_read_reg(SDRC_RFR_CTRL_0); 37280140786SRajendra Nayak sdrc_block_contents.cs_1 = 0x0; 37380140786SRajendra Nayak sdrc_block_contents.mcfg_1 = sdrc_read_reg(SDRC_MCFG_1); 37480140786SRajendra Nayak sdrc_block_contents.mr_1 = sdrc_read_reg(SDRC_MR_1) & 0xFFFF; 37580140786SRajendra Nayak sdrc_block_contents.emr_1_1 = 0x0; 37680140786SRajendra Nayak sdrc_block_contents.emr_2_1 = 0x0; 37780140786SRajendra Nayak sdrc_block_contents.emr_3_1 = 0x0; 37880140786SRajendra Nayak sdrc_block_contents.actim_ctrla_1 = 37980140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_A_1); 38080140786SRajendra Nayak sdrc_block_contents.actim_ctrlb_1 = 38180140786SRajendra Nayak sdrc_read_reg(SDRC_ACTIM_CTRL_B_1); 38280140786SRajendra Nayak sdrc_block_contents.rfr_ctrl_1 = 38380140786SRajendra Nayak sdrc_read_reg(SDRC_RFR_CTRL_1); 38480140786SRajendra Nayak sdrc_block_contents.dcdl_1_ctrl = 0x0; 38580140786SRajendra Nayak sdrc_block_contents.dcdl_2_ctrl = 0x0; 38680140786SRajendra Nayak sdrc_block_contents.flags = 0x0; 38780140786SRajendra Nayak sdrc_block_contents.block_size = 0x0; 38880140786SRajendra Nayak 38980140786SRajendra Nayak arm_context_addr = virt_to_phys(omap3_arm_context); 39080140786SRajendra Nayak 39180140786SRajendra Nayak /* Copy all the contents to the scratchpad location */ 39280140786SRajendra Nayak scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD); 39380140786SRajendra Nayak memcpy_toio(scratchpad_address, &scratchpad_contents, 39480140786SRajendra Nayak sizeof(scratchpad_contents)); 39580140786SRajendra Nayak /* Scratchpad contents being 32 bits, a divide by 4 done here */ 39680140786SRajendra Nayak memcpy_toio(scratchpad_address + 39780140786SRajendra Nayak scratchpad_contents.prcm_block_offset, 39880140786SRajendra Nayak &prcm_block_contents, sizeof(prcm_block_contents)); 39980140786SRajendra Nayak memcpy_toio(scratchpad_address + 40080140786SRajendra Nayak scratchpad_contents.sdrc_block_offset, 40180140786SRajendra Nayak &sdrc_block_contents, sizeof(sdrc_block_contents)); 40280140786SRajendra Nayak /* 40380140786SRajendra Nayak * Copies the address of the location in SDRAM where ARM 40480140786SRajendra Nayak * registers get saved during a MPU OFF transition. 40580140786SRajendra Nayak */ 40680140786SRajendra Nayak memcpy_toio(scratchpad_address + 40780140786SRajendra Nayak scratchpad_contents.sdrc_block_offset + 40880140786SRajendra Nayak sizeof(sdrc_block_contents), &arm_context_addr, 4); 40980140786SRajendra Nayak } 41080140786SRajendra Nayak 411c96631e1SRajendra Nayak void omap3_control_save_context(void) 412c96631e1SRajendra Nayak { 413c96631e1SRajendra Nayak control_context.sysconfig = omap_ctrl_readl(OMAP2_CONTROL_SYSCONFIG); 414c96631e1SRajendra Nayak control_context.devconf0 = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); 415c96631e1SRajendra Nayak control_context.mem_dftrw0 = 416c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW0); 417c96631e1SRajendra Nayak control_context.mem_dftrw1 = 418c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_MEM_DFTRW1); 419c96631e1SRajendra Nayak control_context.msuspendmux_0 = 420c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_0); 421c96631e1SRajendra Nayak control_context.msuspendmux_1 = 422c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_1); 423c96631e1SRajendra Nayak control_context.msuspendmux_2 = 424c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_2); 425c96631e1SRajendra Nayak control_context.msuspendmux_3 = 426c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_3); 427c96631e1SRajendra Nayak control_context.msuspendmux_4 = 428c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_4); 429c96631e1SRajendra Nayak control_context.msuspendmux_5 = 430c96631e1SRajendra Nayak omap_ctrl_readl(OMAP2_CONTROL_MSUSPENDMUX_5); 431c96631e1SRajendra Nayak control_context.sec_ctrl = omap_ctrl_readl(OMAP2_CONTROL_SEC_CTRL); 432c96631e1SRajendra Nayak control_context.devconf1 = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1); 433c96631e1SRajendra Nayak control_context.csirxfe = omap_ctrl_readl(OMAP343X_CONTROL_CSIRXFE); 434c96631e1SRajendra Nayak control_context.iva2_bootaddr = 435c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTADDR); 436c96631e1SRajendra Nayak control_context.iva2_bootmod = 437c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_IVA2_BOOTMOD); 438c96631e1SRajendra Nayak control_context.debobs_0 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(0)); 439c96631e1SRajendra Nayak control_context.debobs_1 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(1)); 440c96631e1SRajendra Nayak control_context.debobs_2 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(2)); 441c96631e1SRajendra Nayak control_context.debobs_3 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(3)); 442c96631e1SRajendra Nayak control_context.debobs_4 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(4)); 443c96631e1SRajendra Nayak control_context.debobs_5 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(5)); 444c96631e1SRajendra Nayak control_context.debobs_6 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(6)); 445c96631e1SRajendra Nayak control_context.debobs_7 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(7)); 446c96631e1SRajendra Nayak control_context.debobs_8 = omap_ctrl_readl(OMAP343X_CONTROL_DEBOBS(8)); 447c96631e1SRajendra Nayak control_context.prog_io0 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO0); 448c96631e1SRajendra Nayak control_context.prog_io1 = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1); 449c96631e1SRajendra Nayak control_context.dss_dpll_spreading = 450c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_DSS_DPLL_SPREADING); 451c96631e1SRajendra Nayak control_context.core_dpll_spreading = 452c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_CORE_DPLL_SPREADING); 453c96631e1SRajendra Nayak control_context.per_dpll_spreading = 454c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_PER_DPLL_SPREADING); 455c96631e1SRajendra Nayak control_context.usbhost_dpll_spreading = 456c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_USBHOST_DPLL_SPREADING); 457c96631e1SRajendra Nayak control_context.pbias_lite = 458c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE); 459c96631e1SRajendra Nayak control_context.temp_sensor = 460c96631e1SRajendra Nayak omap_ctrl_readl(OMAP343X_CONTROL_TEMP_SENSOR); 461c96631e1SRajendra Nayak control_context.sramldo4 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO4); 462c96631e1SRajendra Nayak control_context.sramldo5 = omap_ctrl_readl(OMAP343X_CONTROL_SRAMLDO5); 463c96631e1SRajendra Nayak control_context.csi = omap_ctrl_readl(OMAP343X_CONTROL_CSI); 464f5f9d132SPaul Walmsley control_context.padconf_sys_nirq = 465f5f9d132SPaul Walmsley omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_SYSNIRQ); 466c96631e1SRajendra Nayak return; 467c96631e1SRajendra Nayak } 468c96631e1SRajendra Nayak 469c96631e1SRajendra Nayak void omap3_control_restore_context(void) 470c96631e1SRajendra Nayak { 471c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sysconfig, OMAP2_CONTROL_SYSCONFIG); 472c96631e1SRajendra Nayak omap_ctrl_writel(control_context.devconf0, OMAP2_CONTROL_DEVCONF0); 473c96631e1SRajendra Nayak omap_ctrl_writel(control_context.mem_dftrw0, 474c96631e1SRajendra Nayak OMAP343X_CONTROL_MEM_DFTRW0); 475c96631e1SRajendra Nayak omap_ctrl_writel(control_context.mem_dftrw1, 476c96631e1SRajendra Nayak OMAP343X_CONTROL_MEM_DFTRW1); 477c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_0, 478c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_0); 479c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_1, 480c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_1); 481c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_2, 482c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_2); 483c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_3, 484c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_3); 485c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_4, 486c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_4); 487c96631e1SRajendra Nayak omap_ctrl_writel(control_context.msuspendmux_5, 488c96631e1SRajendra Nayak OMAP2_CONTROL_MSUSPENDMUX_5); 489c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sec_ctrl, OMAP2_CONTROL_SEC_CTRL); 490c96631e1SRajendra Nayak omap_ctrl_writel(control_context.devconf1, OMAP343X_CONTROL_DEVCONF1); 491c96631e1SRajendra Nayak omap_ctrl_writel(control_context.csirxfe, OMAP343X_CONTROL_CSIRXFE); 492c96631e1SRajendra Nayak omap_ctrl_writel(control_context.iva2_bootaddr, 493c96631e1SRajendra Nayak OMAP343X_CONTROL_IVA2_BOOTADDR); 494c96631e1SRajendra Nayak omap_ctrl_writel(control_context.iva2_bootmod, 495c96631e1SRajendra Nayak OMAP343X_CONTROL_IVA2_BOOTMOD); 496c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_0, OMAP343X_CONTROL_DEBOBS(0)); 497c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_1, OMAP343X_CONTROL_DEBOBS(1)); 498c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_2, OMAP343X_CONTROL_DEBOBS(2)); 499c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_3, OMAP343X_CONTROL_DEBOBS(3)); 500c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_4, OMAP343X_CONTROL_DEBOBS(4)); 501c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_5, OMAP343X_CONTROL_DEBOBS(5)); 502c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_6, OMAP343X_CONTROL_DEBOBS(6)); 503c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_7, OMAP343X_CONTROL_DEBOBS(7)); 504c96631e1SRajendra Nayak omap_ctrl_writel(control_context.debobs_8, OMAP343X_CONTROL_DEBOBS(8)); 505c96631e1SRajendra Nayak omap_ctrl_writel(control_context.prog_io0, OMAP343X_CONTROL_PROG_IO0); 506c96631e1SRajendra Nayak omap_ctrl_writel(control_context.prog_io1, OMAP343X_CONTROL_PROG_IO1); 507c96631e1SRajendra Nayak omap_ctrl_writel(control_context.dss_dpll_spreading, 508c96631e1SRajendra Nayak OMAP343X_CONTROL_DSS_DPLL_SPREADING); 509c96631e1SRajendra Nayak omap_ctrl_writel(control_context.core_dpll_spreading, 510c96631e1SRajendra Nayak OMAP343X_CONTROL_CORE_DPLL_SPREADING); 511c96631e1SRajendra Nayak omap_ctrl_writel(control_context.per_dpll_spreading, 512c96631e1SRajendra Nayak OMAP343X_CONTROL_PER_DPLL_SPREADING); 513c96631e1SRajendra Nayak omap_ctrl_writel(control_context.usbhost_dpll_spreading, 514c96631e1SRajendra Nayak OMAP343X_CONTROL_USBHOST_DPLL_SPREADING); 515c96631e1SRajendra Nayak omap_ctrl_writel(control_context.pbias_lite, 516c96631e1SRajendra Nayak OMAP343X_CONTROL_PBIAS_LITE); 517c96631e1SRajendra Nayak omap_ctrl_writel(control_context.temp_sensor, 518c96631e1SRajendra Nayak OMAP343X_CONTROL_TEMP_SENSOR); 519c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sramldo4, OMAP343X_CONTROL_SRAMLDO4); 520c96631e1SRajendra Nayak omap_ctrl_writel(control_context.sramldo5, OMAP343X_CONTROL_SRAMLDO5); 521c96631e1SRajendra Nayak omap_ctrl_writel(control_context.csi, OMAP343X_CONTROL_CSI); 522f5f9d132SPaul Walmsley omap_ctrl_writel(control_context.padconf_sys_nirq, 523f5f9d132SPaul Walmsley OMAP343X_CONTROL_PADCONF_SYSNIRQ); 524c96631e1SRajendra Nayak return; 525c96631e1SRajendra Nayak } 526458e999eSNishanth Menon 527458e999eSNishanth Menon void omap3630_ctrl_disable_rta(void) 528458e999eSNishanth Menon { 529458e999eSNishanth Menon if (!cpu_is_omap3630()) 530458e999eSNishanth Menon return; 531458e999eSNishanth Menon omap_ctrl_writel(OMAP36XX_RTA_DISABLE, OMAP36XX_CONTROL_MEM_RTA_CTRL); 532458e999eSNishanth Menon } 533458e999eSNishanth Menon 534596efe47SPaul Walmsley /** 535596efe47SPaul Walmsley * omap3_ctrl_save_padconf - save padconf registers to scratchpad RAM 536596efe47SPaul Walmsley * 537596efe47SPaul Walmsley * Tell the SCM to start saving the padconf registers, then wait for 538596efe47SPaul Walmsley * the process to complete. Returns 0 unconditionally, although it 539596efe47SPaul Walmsley * should also eventually be able to return -ETIMEDOUT, if the save 540596efe47SPaul Walmsley * does not complete. 541596efe47SPaul Walmsley * 542596efe47SPaul Walmsley * XXX This function is missing a timeout. What should it be? 543596efe47SPaul Walmsley */ 544596efe47SPaul Walmsley int omap3_ctrl_save_padconf(void) 545596efe47SPaul Walmsley { 546596efe47SPaul Walmsley u32 cpo; 547596efe47SPaul Walmsley 548596efe47SPaul Walmsley /* Save the padconf registers */ 549596efe47SPaul Walmsley cpo = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF); 550596efe47SPaul Walmsley cpo |= START_PADCONF_SAVE; 551596efe47SPaul Walmsley omap_ctrl_writel(cpo, OMAP343X_CONTROL_PADCONF_OFF); 552596efe47SPaul Walmsley 553596efe47SPaul Walmsley /* wait for the save to complete */ 554596efe47SPaul Walmsley while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS) 555596efe47SPaul Walmsley & PADCONF_SAVE_DONE)) 556596efe47SPaul Walmsley udelay(1); 557596efe47SPaul Walmsley 558596efe47SPaul Walmsley return 0; 559596efe47SPaul Walmsley } 560596efe47SPaul Walmsley 56149e03402STero Kristo /** 56249e03402STero Kristo * omap3_ctrl_set_iva_bootmode_idle - sets the IVA2 bootmode to idle 56349e03402STero Kristo * 56449e03402STero Kristo * Sets the bootmode for IVA2 to idle. This is needed by the PM code to 56549e03402STero Kristo * force disable IVA2 so that it does not prevent any low-power states. 56649e03402STero Kristo */ 56749e03402STero Kristo void omap3_ctrl_set_iva_bootmode_idle(void) 56849e03402STero Kristo { 56949e03402STero Kristo omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE, 57049e03402STero Kristo OMAP343X_CONTROL_IVA2_BOOTMOD); 57149e03402STero Kristo } 572*bbd36f9fSTero Kristo 573*bbd36f9fSTero Kristo /** 574*bbd36f9fSTero Kristo * omap3_ctrl_setup_d2d_padconf - setup stacked modem pads for idle 575*bbd36f9fSTero Kristo * 576*bbd36f9fSTero Kristo * Sets up the pads controlling the stacked modem in such way that the 577*bbd36f9fSTero Kristo * device can enter idle. 578*bbd36f9fSTero Kristo */ 579*bbd36f9fSTero Kristo void omap3_ctrl_setup_d2d_padconf(void) 580*bbd36f9fSTero Kristo { 581*bbd36f9fSTero Kristo u16 mask, padconf; 582*bbd36f9fSTero Kristo 583*bbd36f9fSTero Kristo /* 584*bbd36f9fSTero Kristo * In a stand alone OMAP3430 where there is not a stacked 585*bbd36f9fSTero Kristo * modem for the D2D Idle Ack and D2D MStandby must be pulled 586*bbd36f9fSTero Kristo * high. S CONTROL_PADCONF_SAD2D_IDLEACK and 587*bbd36f9fSTero Kristo * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. 588*bbd36f9fSTero Kristo */ 589*bbd36f9fSTero Kristo mask = (1 << 4) | (1 << 3); /* pull-up, enabled */ 590*bbd36f9fSTero Kristo padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY); 591*bbd36f9fSTero Kristo padconf |= mask; 592*bbd36f9fSTero Kristo omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY); 593*bbd36f9fSTero Kristo 594*bbd36f9fSTero Kristo padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK); 595*bbd36f9fSTero Kristo padconf |= mask; 596*bbd36f9fSTero Kristo omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK); 597*bbd36f9fSTero Kristo } 598c96631e1SRajendra Nayak #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */ 599