162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * linux/arch/arm/mach-omap1/pm.c 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * OMAP Power Management Routines 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Original code for the SA11x0: 762306a36Sopenharmony_ci * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com> 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Modified for the PXA250 by Nicolas Pitre: 1062306a36Sopenharmony_ci * Copyright (c) 2002 Monta Vista Software, Inc. 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Modified for the OMAP1510 by David Singleton: 1362306a36Sopenharmony_ci * Copyright (c) 2002 Monta Vista Software, Inc. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * Cleanup 2004 for OMAP1510/1610 by Dirk Behme <dirk.behme@de.bosch.com> 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it 1862306a36Sopenharmony_ci * under the terms of the GNU General Public License as published by the 1962306a36Sopenharmony_ci * Free Software Foundation; either version 2 of the License, or (at your 2062306a36Sopenharmony_ci * option) any later version. 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 2362306a36Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 2462306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 2562306a36Sopenharmony_ci * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2662306a36Sopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2762306a36Sopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2862306a36Sopenharmony_ci * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 2962306a36Sopenharmony_ci * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3062306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3162306a36Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License along 3462306a36Sopenharmony_ci * with this program; if not, write to the Free Software Foundation, Inc., 3562306a36Sopenharmony_ci * 675 Mass Ave, Cambridge, MA 02139, USA. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#include <linux/suspend.h> 3962306a36Sopenharmony_ci#include <linux/sched.h> 4062306a36Sopenharmony_ci#include <linux/debugfs.h> 4162306a36Sopenharmony_ci#include <linux/seq_file.h> 4262306a36Sopenharmony_ci#include <linux/interrupt.h> 4362306a36Sopenharmony_ci#include <linux/sysfs.h> 4462306a36Sopenharmony_ci#include <linux/module.h> 4562306a36Sopenharmony_ci#include <linux/io.h> 4662306a36Sopenharmony_ci#include <linux/atomic.h> 4762306a36Sopenharmony_ci#include <linux/cpu.h> 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#include <asm/fncpy.h> 5062306a36Sopenharmony_ci#include <asm/system_misc.h> 5162306a36Sopenharmony_ci#include <asm/irq.h> 5262306a36Sopenharmony_ci#include <asm/mach/time.h> 5362306a36Sopenharmony_ci#include <asm/mach/irq.h> 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#include <linux/soc/ti/omap1-io.h> 5662306a36Sopenharmony_ci#include "tc.h" 5762306a36Sopenharmony_ci#include <linux/omap-dma.h> 5862306a36Sopenharmony_ci#include <clocksource/timer-ti-dm.h> 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#include "hardware.h" 6162306a36Sopenharmony_ci#include "mux.h" 6262306a36Sopenharmony_ci#include "irqs.h" 6362306a36Sopenharmony_ci#include "iomap.h" 6462306a36Sopenharmony_ci#include "clock.h" 6562306a36Sopenharmony_ci#include "pm.h" 6662306a36Sopenharmony_ci#include "soc.h" 6762306a36Sopenharmony_ci#include "sram.h" 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic unsigned int arm_sleep_save[ARM_SLEEP_SAVE_SIZE]; 7062306a36Sopenharmony_cistatic unsigned short dsp_sleep_save[DSP_SLEEP_SAVE_SIZE]; 7162306a36Sopenharmony_cistatic unsigned short ulpd_sleep_save[ULPD_SLEEP_SAVE_SIZE]; 7262306a36Sopenharmony_cistatic unsigned int mpui1510_sleep_save[MPUI1510_SLEEP_SAVE_SIZE]; 7362306a36Sopenharmony_cistatic unsigned int mpui1610_sleep_save[MPUI1610_SLEEP_SAVE_SIZE]; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_cistatic unsigned short enable_dyn_sleep; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistatic ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr, 7862306a36Sopenharmony_ci char *buf) 7962306a36Sopenharmony_ci{ 8062306a36Sopenharmony_ci return sprintf(buf, "%hu\n", enable_dyn_sleep); 8162306a36Sopenharmony_ci} 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistatic ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr, 8462306a36Sopenharmony_ci const char * buf, size_t n) 8562306a36Sopenharmony_ci{ 8662306a36Sopenharmony_ci unsigned short value; 8762306a36Sopenharmony_ci if (sscanf(buf, "%hu", &value) != 1 || 8862306a36Sopenharmony_ci (value != 0 && value != 1) || 8962306a36Sopenharmony_ci (value != 0 && !IS_ENABLED(CONFIG_OMAP_32K_TIMER))) { 9062306a36Sopenharmony_ci pr_err("idle_sleep_store: Invalid value\n"); 9162306a36Sopenharmony_ci return -EINVAL; 9262306a36Sopenharmony_ci } 9362306a36Sopenharmony_ci enable_dyn_sleep = value; 9462306a36Sopenharmony_ci return n; 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistatic struct kobj_attribute sleep_while_idle_attr = 9862306a36Sopenharmony_ci __ATTR(sleep_while_idle, 0644, idle_show, idle_store); 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistatic void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* 10462306a36Sopenharmony_ci * Let's power down on idle, but only if we are really 10562306a36Sopenharmony_ci * idle, because once we start down the path of 10662306a36Sopenharmony_ci * going idle we continue to do idle even if we get 10762306a36Sopenharmony_ci * a clock tick interrupt . . 10862306a36Sopenharmony_ci */ 10962306a36Sopenharmony_civoid omap1_pm_idle(void) 11062306a36Sopenharmony_ci{ 11162306a36Sopenharmony_ci extern __u32 arm_idlect1_mask; 11262306a36Sopenharmony_ci __u32 use_idlect1 = arm_idlect1_mask; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci local_fiq_disable(); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#if defined(CONFIG_OMAP_MPU_TIMER) && !defined(CONFIG_OMAP_DM_TIMER) 11762306a36Sopenharmony_ci use_idlect1 = use_idlect1 & ~(1 << 9); 11862306a36Sopenharmony_ci#endif 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci#ifdef CONFIG_OMAP_DM_TIMER 12162306a36Sopenharmony_ci use_idlect1 = omap_dm_timer_modify_idlect_mask(use_idlect1); 12262306a36Sopenharmony_ci#endif 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci if (omap_dma_running()) 12562306a36Sopenharmony_ci use_idlect1 &= ~(1 << 6); 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci /* 12862306a36Sopenharmony_ci * We should be able to remove the do_sleep variable and multiple 12962306a36Sopenharmony_ci * tests above as soon as drivers, timer and DMA code have been fixed. 13062306a36Sopenharmony_ci * Even the sleep block count should become obsolete. 13162306a36Sopenharmony_ci */ 13262306a36Sopenharmony_ci if ((use_idlect1 != ~0) || !enable_dyn_sleep) { 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci __u32 saved_idlect1 = omap_readl(ARM_IDLECT1); 13562306a36Sopenharmony_ci if (cpu_is_omap15xx()) 13662306a36Sopenharmony_ci use_idlect1 &= OMAP1510_BIG_SLEEP_REQUEST; 13762306a36Sopenharmony_ci else 13862306a36Sopenharmony_ci use_idlect1 &= OMAP1610_IDLECT1_SLEEP_VAL; 13962306a36Sopenharmony_ci omap_writel(use_idlect1, ARM_IDLECT1); 14062306a36Sopenharmony_ci __asm__ volatile ("mcr p15, 0, r0, c7, c0, 4"); 14162306a36Sopenharmony_ci omap_writel(saved_idlect1, ARM_IDLECT1); 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci local_fiq_enable(); 14462306a36Sopenharmony_ci return; 14562306a36Sopenharmony_ci } 14662306a36Sopenharmony_ci omap_sram_suspend(omap_readl(ARM_IDLECT1), 14762306a36Sopenharmony_ci omap_readl(ARM_IDLECT2)); 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci local_fiq_enable(); 15062306a36Sopenharmony_ci} 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci/* 15362306a36Sopenharmony_ci * Configuration of the wakeup event is board specific. For the 15462306a36Sopenharmony_ci * moment we put it into this helper function. Later it may move 15562306a36Sopenharmony_ci * to board specific files. 15662306a36Sopenharmony_ci */ 15762306a36Sopenharmony_cistatic void omap_pm_wakeup_setup(void) 15862306a36Sopenharmony_ci{ 15962306a36Sopenharmony_ci u32 level1_wake = 0; 16062306a36Sopenharmony_ci u32 level2_wake = OMAP_IRQ_BIT(INT_UART2); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci /* 16362306a36Sopenharmony_ci * Turn off all interrupts except GPIO bank 1, L1-2nd level cascade, 16462306a36Sopenharmony_ci * and the L2 wakeup interrupts: keypad and UART2. Note that the 16562306a36Sopenharmony_ci * drivers must still separately call omap_set_gpio_wakeup() to 16662306a36Sopenharmony_ci * wake up to a GPIO interrupt. 16762306a36Sopenharmony_ci */ 16862306a36Sopenharmony_ci if (cpu_is_omap15xx()) 16962306a36Sopenharmony_ci level1_wake = OMAP_IRQ_BIT(INT_GPIO_BANK1) | 17062306a36Sopenharmony_ci OMAP_IRQ_BIT(INT_1510_IH2_IRQ); 17162306a36Sopenharmony_ci else if (cpu_is_omap16xx()) 17262306a36Sopenharmony_ci level1_wake = OMAP_IRQ_BIT(INT_GPIO_BANK1) | 17362306a36Sopenharmony_ci OMAP_IRQ_BIT(INT_1610_IH2_IRQ); 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci omap_writel(~level1_wake, OMAP_IH1_MIR); 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 17862306a36Sopenharmony_ci level2_wake |= OMAP_IRQ_BIT(INT_KEYBOARD); 17962306a36Sopenharmony_ci omap_writel(~level2_wake, OMAP_IH2_MIR); 18062306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 18162306a36Sopenharmony_ci level2_wake |= OMAP_IRQ_BIT(INT_KEYBOARD); 18262306a36Sopenharmony_ci omap_writel(~level2_wake, OMAP_IH2_0_MIR); 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci /* INT_1610_WAKE_UP_REQ is needed for GPIO wakeup... */ 18562306a36Sopenharmony_ci omap_writel(~OMAP_IRQ_BIT(INT_1610_WAKE_UP_REQ), 18662306a36Sopenharmony_ci OMAP_IH2_1_MIR); 18762306a36Sopenharmony_ci omap_writel(~0x0, OMAP_IH2_2_MIR); 18862306a36Sopenharmony_ci omap_writel(~0x0, OMAP_IH2_3_MIR); 18962306a36Sopenharmony_ci } 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci /* New IRQ agreement, recalculate in cascade order */ 19262306a36Sopenharmony_ci omap_writel(1, OMAP_IH2_CONTROL); 19362306a36Sopenharmony_ci omap_writel(1, OMAP_IH1_CONTROL); 19462306a36Sopenharmony_ci} 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci#define EN_DSPCK 13 /* ARM_CKCTL */ 19762306a36Sopenharmony_ci#define EN_APICK 6 /* ARM_IDLECT2 */ 19862306a36Sopenharmony_ci#define DSP_EN 1 /* ARM_RSTCT1 */ 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_civoid omap1_pm_suspend(void) 20162306a36Sopenharmony_ci{ 20262306a36Sopenharmony_ci unsigned long arg0 = 0, arg1 = 0; 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci printk(KERN_INFO "PM: OMAP%x is trying to enter deep sleep...\n", 20562306a36Sopenharmony_ci omap_rev()); 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci omap_serial_wake_trigger(1); 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci if (!cpu_is_omap15xx()) 21062306a36Sopenharmony_ci omap_writew(0xffff, ULPD_SOFT_DISABLE_REQ_REG); 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci /* 21362306a36Sopenharmony_ci * Step 1: turn off interrupts (FIXME: NOTE: already disabled) 21462306a36Sopenharmony_ci */ 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci local_irq_disable(); 21762306a36Sopenharmony_ci local_fiq_disable(); 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci /* 22062306a36Sopenharmony_ci * Step 2: save registers 22162306a36Sopenharmony_ci * 22262306a36Sopenharmony_ci * The omap is a strange/beautiful device. The caches, memory 22362306a36Sopenharmony_ci * and register state are preserved across power saves. 22462306a36Sopenharmony_ci * We have to save and restore very little register state to 22562306a36Sopenharmony_ci * idle the omap. 22662306a36Sopenharmony_ci * 22762306a36Sopenharmony_ci * Save interrupt, MPUI, ARM and UPLD control registers. 22862306a36Sopenharmony_ci */ 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 23162306a36Sopenharmony_ci MPUI1510_SAVE(OMAP_IH1_MIR); 23262306a36Sopenharmony_ci MPUI1510_SAVE(OMAP_IH2_MIR); 23362306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_CTRL); 23462306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_DSP_BOOT_CONFIG); 23562306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_DSP_API_CONFIG); 23662306a36Sopenharmony_ci MPUI1510_SAVE(EMIFS_CONFIG); 23762306a36Sopenharmony_ci MPUI1510_SAVE(EMIFF_SDRAM_CONFIG); 23862306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 23962306a36Sopenharmony_ci MPUI1610_SAVE(OMAP_IH1_MIR); 24062306a36Sopenharmony_ci MPUI1610_SAVE(OMAP_IH2_0_MIR); 24162306a36Sopenharmony_ci MPUI1610_SAVE(OMAP_IH2_1_MIR); 24262306a36Sopenharmony_ci MPUI1610_SAVE(OMAP_IH2_2_MIR); 24362306a36Sopenharmony_ci MPUI1610_SAVE(OMAP_IH2_3_MIR); 24462306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_CTRL); 24562306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_DSP_BOOT_CONFIG); 24662306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_DSP_API_CONFIG); 24762306a36Sopenharmony_ci MPUI1610_SAVE(EMIFS_CONFIG); 24862306a36Sopenharmony_ci MPUI1610_SAVE(EMIFF_SDRAM_CONFIG); 24962306a36Sopenharmony_ci } 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_ci ARM_SAVE(ARM_CKCTL); 25262306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT1); 25362306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT2); 25462306a36Sopenharmony_ci if (!(cpu_is_omap15xx())) 25562306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT3); 25662306a36Sopenharmony_ci ARM_SAVE(ARM_EWUPCT); 25762306a36Sopenharmony_ci ARM_SAVE(ARM_RSTCT1); 25862306a36Sopenharmony_ci ARM_SAVE(ARM_RSTCT2); 25962306a36Sopenharmony_ci ARM_SAVE(ARM_SYSST); 26062306a36Sopenharmony_ci ULPD_SAVE(ULPD_CLOCK_CTRL); 26162306a36Sopenharmony_ci ULPD_SAVE(ULPD_STATUS_REQ); 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci /* (Step 3 removed - we now allow deep sleep by default) */ 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci /* 26662306a36Sopenharmony_ci * Step 4: OMAP DSP Shutdown 26762306a36Sopenharmony_ci */ 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci /* stop DSP */ 27062306a36Sopenharmony_ci omap_writew(omap_readw(ARM_RSTCT1) & ~(1 << DSP_EN), ARM_RSTCT1); 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci /* shut down dsp_ck */ 27362306a36Sopenharmony_ci omap_writew(omap_readw(ARM_CKCTL) & ~(1 << EN_DSPCK), ARM_CKCTL); 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci /* temporarily enabling api_ck to access DSP registers */ 27662306a36Sopenharmony_ci omap_writew(omap_readw(ARM_IDLECT2) | 1 << EN_APICK, ARM_IDLECT2); 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci /* save DSP registers */ 27962306a36Sopenharmony_ci DSP_SAVE(DSP_IDLECT2); 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci /* Stop all DSP domain clocks */ 28262306a36Sopenharmony_ci __raw_writew(0, DSP_IDLECT2); 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci /* 28562306a36Sopenharmony_ci * Step 5: Wakeup Event Setup 28662306a36Sopenharmony_ci */ 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci omap_pm_wakeup_setup(); 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci /* 29162306a36Sopenharmony_ci * Step 6: ARM and Traffic controller shutdown 29262306a36Sopenharmony_ci */ 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci /* disable ARM watchdog */ 29562306a36Sopenharmony_ci omap_writel(0x00F5, OMAP_WDT_TIMER_MODE); 29662306a36Sopenharmony_ci omap_writel(0x00A0, OMAP_WDT_TIMER_MODE); 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci /* 29962306a36Sopenharmony_ci * Step 6b: ARM and Traffic controller shutdown 30062306a36Sopenharmony_ci * 30162306a36Sopenharmony_ci * Step 6 continues here. Prepare jump to power management 30262306a36Sopenharmony_ci * assembly code in internal SRAM. 30362306a36Sopenharmony_ci * 30462306a36Sopenharmony_ci * Since the omap_cpu_suspend routine has been copied to 30562306a36Sopenharmony_ci * SRAM, we'll do an indirect procedure call to it and pass the 30662306a36Sopenharmony_ci * contents of arm_idlect1 and arm_idlect2 so it can restore 30762306a36Sopenharmony_ci * them when it wakes up and it will return. 30862306a36Sopenharmony_ci */ 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ci arg0 = arm_sleep_save[ARM_SLEEP_SAVE_ARM_IDLECT1]; 31162306a36Sopenharmony_ci arg1 = arm_sleep_save[ARM_SLEEP_SAVE_ARM_IDLECT2]; 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_ci /* 31462306a36Sopenharmony_ci * Step 6c: ARM and Traffic controller shutdown 31562306a36Sopenharmony_ci * 31662306a36Sopenharmony_ci * Jump to assembly code. The processor will stay there 31762306a36Sopenharmony_ci * until wake up. 31862306a36Sopenharmony_ci */ 31962306a36Sopenharmony_ci omap_sram_suspend(arg0, arg1); 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci /* 32262306a36Sopenharmony_ci * If we are here, processor is woken up! 32362306a36Sopenharmony_ci */ 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci /* 32662306a36Sopenharmony_ci * Restore DSP clocks 32762306a36Sopenharmony_ci */ 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci /* again temporarily enabling api_ck to access DSP registers */ 33062306a36Sopenharmony_ci omap_writew(omap_readw(ARM_IDLECT2) | 1 << EN_APICK, ARM_IDLECT2); 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci /* Restore DSP domain clocks */ 33362306a36Sopenharmony_ci DSP_RESTORE(DSP_IDLECT2); 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci /* 33662306a36Sopenharmony_ci * Restore ARM state, except ARM_IDLECT1/2 which omap_cpu_suspend did 33762306a36Sopenharmony_ci */ 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci if (!(cpu_is_omap15xx())) 34062306a36Sopenharmony_ci ARM_RESTORE(ARM_IDLECT3); 34162306a36Sopenharmony_ci ARM_RESTORE(ARM_CKCTL); 34262306a36Sopenharmony_ci ARM_RESTORE(ARM_EWUPCT); 34362306a36Sopenharmony_ci ARM_RESTORE(ARM_RSTCT1); 34462306a36Sopenharmony_ci ARM_RESTORE(ARM_RSTCT2); 34562306a36Sopenharmony_ci ARM_RESTORE(ARM_SYSST); 34662306a36Sopenharmony_ci ULPD_RESTORE(ULPD_CLOCK_CTRL); 34762306a36Sopenharmony_ci ULPD_RESTORE(ULPD_STATUS_REQ); 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 35062306a36Sopenharmony_ci MPUI1510_RESTORE(MPUI_CTRL); 35162306a36Sopenharmony_ci MPUI1510_RESTORE(MPUI_DSP_BOOT_CONFIG); 35262306a36Sopenharmony_ci MPUI1510_RESTORE(MPUI_DSP_API_CONFIG); 35362306a36Sopenharmony_ci MPUI1510_RESTORE(EMIFS_CONFIG); 35462306a36Sopenharmony_ci MPUI1510_RESTORE(EMIFF_SDRAM_CONFIG); 35562306a36Sopenharmony_ci MPUI1510_RESTORE(OMAP_IH1_MIR); 35662306a36Sopenharmony_ci MPUI1510_RESTORE(OMAP_IH2_MIR); 35762306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 35862306a36Sopenharmony_ci MPUI1610_RESTORE(MPUI_CTRL); 35962306a36Sopenharmony_ci MPUI1610_RESTORE(MPUI_DSP_BOOT_CONFIG); 36062306a36Sopenharmony_ci MPUI1610_RESTORE(MPUI_DSP_API_CONFIG); 36162306a36Sopenharmony_ci MPUI1610_RESTORE(EMIFS_CONFIG); 36262306a36Sopenharmony_ci MPUI1610_RESTORE(EMIFF_SDRAM_CONFIG); 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ci MPUI1610_RESTORE(OMAP_IH1_MIR); 36562306a36Sopenharmony_ci MPUI1610_RESTORE(OMAP_IH2_0_MIR); 36662306a36Sopenharmony_ci MPUI1610_RESTORE(OMAP_IH2_1_MIR); 36762306a36Sopenharmony_ci MPUI1610_RESTORE(OMAP_IH2_2_MIR); 36862306a36Sopenharmony_ci MPUI1610_RESTORE(OMAP_IH2_3_MIR); 36962306a36Sopenharmony_ci } 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci if (!cpu_is_omap15xx()) 37262306a36Sopenharmony_ci omap_writew(0, ULPD_SOFT_DISABLE_REQ_REG); 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci /* 37562306a36Sopenharmony_ci * Re-enable interrupts 37662306a36Sopenharmony_ci */ 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ci local_irq_enable(); 37962306a36Sopenharmony_ci local_fiq_enable(); 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci omap_serial_wake_trigger(0); 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci printk(KERN_INFO "PM: OMAP%x is re-starting from deep sleep...\n", 38462306a36Sopenharmony_ci omap_rev()); 38562306a36Sopenharmony_ci} 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 38862306a36Sopenharmony_ci/* 38962306a36Sopenharmony_ci * Read system PM registers for debugging 39062306a36Sopenharmony_ci */ 39162306a36Sopenharmony_cistatic int omap_pm_debug_show(struct seq_file *m, void *v) 39262306a36Sopenharmony_ci{ 39362306a36Sopenharmony_ci ARM_SAVE(ARM_CKCTL); 39462306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT1); 39562306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT2); 39662306a36Sopenharmony_ci if (!(cpu_is_omap15xx())) 39762306a36Sopenharmony_ci ARM_SAVE(ARM_IDLECT3); 39862306a36Sopenharmony_ci ARM_SAVE(ARM_EWUPCT); 39962306a36Sopenharmony_ci ARM_SAVE(ARM_RSTCT1); 40062306a36Sopenharmony_ci ARM_SAVE(ARM_RSTCT2); 40162306a36Sopenharmony_ci ARM_SAVE(ARM_SYSST); 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci ULPD_SAVE(ULPD_IT_STATUS); 40462306a36Sopenharmony_ci ULPD_SAVE(ULPD_CLOCK_CTRL); 40562306a36Sopenharmony_ci ULPD_SAVE(ULPD_SOFT_REQ); 40662306a36Sopenharmony_ci ULPD_SAVE(ULPD_STATUS_REQ); 40762306a36Sopenharmony_ci ULPD_SAVE(ULPD_DPLL_CTRL); 40862306a36Sopenharmony_ci ULPD_SAVE(ULPD_POWER_CTRL); 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 41162306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_CTRL); 41262306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_DSP_STATUS); 41362306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_DSP_BOOT_CONFIG); 41462306a36Sopenharmony_ci MPUI1510_SAVE(MPUI_DSP_API_CONFIG); 41562306a36Sopenharmony_ci MPUI1510_SAVE(EMIFF_SDRAM_CONFIG); 41662306a36Sopenharmony_ci MPUI1510_SAVE(EMIFS_CONFIG); 41762306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 41862306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_CTRL); 41962306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_DSP_STATUS); 42062306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_DSP_BOOT_CONFIG); 42162306a36Sopenharmony_ci MPUI1610_SAVE(MPUI_DSP_API_CONFIG); 42262306a36Sopenharmony_ci MPUI1610_SAVE(EMIFF_SDRAM_CONFIG); 42362306a36Sopenharmony_ci MPUI1610_SAVE(EMIFS_CONFIG); 42462306a36Sopenharmony_ci } 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci seq_printf(m, 42762306a36Sopenharmony_ci "ARM_CKCTL_REG: 0x%-8x \n" 42862306a36Sopenharmony_ci "ARM_IDLECT1_REG: 0x%-8x \n" 42962306a36Sopenharmony_ci "ARM_IDLECT2_REG: 0x%-8x \n" 43062306a36Sopenharmony_ci "ARM_IDLECT3_REG: 0x%-8x \n" 43162306a36Sopenharmony_ci "ARM_EWUPCT_REG: 0x%-8x \n" 43262306a36Sopenharmony_ci "ARM_RSTCT1_REG: 0x%-8x \n" 43362306a36Sopenharmony_ci "ARM_RSTCT2_REG: 0x%-8x \n" 43462306a36Sopenharmony_ci "ARM_SYSST_REG: 0x%-8x \n" 43562306a36Sopenharmony_ci "ULPD_IT_STATUS_REG: 0x%-4x \n" 43662306a36Sopenharmony_ci "ULPD_CLOCK_CTRL_REG: 0x%-4x \n" 43762306a36Sopenharmony_ci "ULPD_SOFT_REQ_REG: 0x%-4x \n" 43862306a36Sopenharmony_ci "ULPD_DPLL_CTRL_REG: 0x%-4x \n" 43962306a36Sopenharmony_ci "ULPD_STATUS_REQ_REG: 0x%-4x \n" 44062306a36Sopenharmony_ci "ULPD_POWER_CTRL_REG: 0x%-4x \n", 44162306a36Sopenharmony_ci ARM_SHOW(ARM_CKCTL), 44262306a36Sopenharmony_ci ARM_SHOW(ARM_IDLECT1), 44362306a36Sopenharmony_ci ARM_SHOW(ARM_IDLECT2), 44462306a36Sopenharmony_ci ARM_SHOW(ARM_IDLECT3), 44562306a36Sopenharmony_ci ARM_SHOW(ARM_EWUPCT), 44662306a36Sopenharmony_ci ARM_SHOW(ARM_RSTCT1), 44762306a36Sopenharmony_ci ARM_SHOW(ARM_RSTCT2), 44862306a36Sopenharmony_ci ARM_SHOW(ARM_SYSST), 44962306a36Sopenharmony_ci ULPD_SHOW(ULPD_IT_STATUS), 45062306a36Sopenharmony_ci ULPD_SHOW(ULPD_CLOCK_CTRL), 45162306a36Sopenharmony_ci ULPD_SHOW(ULPD_SOFT_REQ), 45262306a36Sopenharmony_ci ULPD_SHOW(ULPD_DPLL_CTRL), 45362306a36Sopenharmony_ci ULPD_SHOW(ULPD_STATUS_REQ), 45462306a36Sopenharmony_ci ULPD_SHOW(ULPD_POWER_CTRL)); 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 45762306a36Sopenharmony_ci seq_printf(m, 45862306a36Sopenharmony_ci "MPUI1510_CTRL_REG 0x%-8x \n" 45962306a36Sopenharmony_ci "MPUI1510_DSP_STATUS_REG: 0x%-8x \n" 46062306a36Sopenharmony_ci "MPUI1510_DSP_BOOT_CONFIG_REG: 0x%-8x \n" 46162306a36Sopenharmony_ci "MPUI1510_DSP_API_CONFIG_REG: 0x%-8x \n" 46262306a36Sopenharmony_ci "MPUI1510_SDRAM_CONFIG_REG: 0x%-8x \n" 46362306a36Sopenharmony_ci "MPUI1510_EMIFS_CONFIG_REG: 0x%-8x \n", 46462306a36Sopenharmony_ci MPUI1510_SHOW(MPUI_CTRL), 46562306a36Sopenharmony_ci MPUI1510_SHOW(MPUI_DSP_STATUS), 46662306a36Sopenharmony_ci MPUI1510_SHOW(MPUI_DSP_BOOT_CONFIG), 46762306a36Sopenharmony_ci MPUI1510_SHOW(MPUI_DSP_API_CONFIG), 46862306a36Sopenharmony_ci MPUI1510_SHOW(EMIFF_SDRAM_CONFIG), 46962306a36Sopenharmony_ci MPUI1510_SHOW(EMIFS_CONFIG)); 47062306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 47162306a36Sopenharmony_ci seq_printf(m, 47262306a36Sopenharmony_ci "MPUI1610_CTRL_REG 0x%-8x \n" 47362306a36Sopenharmony_ci "MPUI1610_DSP_STATUS_REG: 0x%-8x \n" 47462306a36Sopenharmony_ci "MPUI1610_DSP_BOOT_CONFIG_REG: 0x%-8x \n" 47562306a36Sopenharmony_ci "MPUI1610_DSP_API_CONFIG_REG: 0x%-8x \n" 47662306a36Sopenharmony_ci "MPUI1610_SDRAM_CONFIG_REG: 0x%-8x \n" 47762306a36Sopenharmony_ci "MPUI1610_EMIFS_CONFIG_REG: 0x%-8x \n", 47862306a36Sopenharmony_ci MPUI1610_SHOW(MPUI_CTRL), 47962306a36Sopenharmony_ci MPUI1610_SHOW(MPUI_DSP_STATUS), 48062306a36Sopenharmony_ci MPUI1610_SHOW(MPUI_DSP_BOOT_CONFIG), 48162306a36Sopenharmony_ci MPUI1610_SHOW(MPUI_DSP_API_CONFIG), 48262306a36Sopenharmony_ci MPUI1610_SHOW(EMIFF_SDRAM_CONFIG), 48362306a36Sopenharmony_ci MPUI1610_SHOW(EMIFS_CONFIG)); 48462306a36Sopenharmony_ci } 48562306a36Sopenharmony_ci 48662306a36Sopenharmony_ci return 0; 48762306a36Sopenharmony_ci} 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ciDEFINE_SHOW_ATTRIBUTE(omap_pm_debug); 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_cistatic void omap_pm_init_debugfs(void) 49262306a36Sopenharmony_ci{ 49362306a36Sopenharmony_ci struct dentry *d; 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci d = debugfs_create_dir("pm_debug", NULL); 49662306a36Sopenharmony_ci debugfs_create_file("omap_pm", S_IWUSR | S_IRUGO, d, NULL, 49762306a36Sopenharmony_ci &omap_pm_debug_fops); 49862306a36Sopenharmony_ci} 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci#endif /* CONFIG_DEBUG_FS */ 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_ci/* 50362306a36Sopenharmony_ci * omap_pm_prepare - Do preliminary suspend work. 50462306a36Sopenharmony_ci * 50562306a36Sopenharmony_ci */ 50662306a36Sopenharmony_cistatic int omap_pm_prepare(void) 50762306a36Sopenharmony_ci{ 50862306a36Sopenharmony_ci /* We cannot sleep in idle until we have resumed */ 50962306a36Sopenharmony_ci cpu_idle_poll_ctrl(true); 51062306a36Sopenharmony_ci return 0; 51162306a36Sopenharmony_ci} 51262306a36Sopenharmony_ci 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci/* 51562306a36Sopenharmony_ci * omap_pm_enter - Actually enter a sleep state. 51662306a36Sopenharmony_ci * @state: State we're entering. 51762306a36Sopenharmony_ci * 51862306a36Sopenharmony_ci */ 51962306a36Sopenharmony_ci 52062306a36Sopenharmony_cistatic int omap_pm_enter(suspend_state_t state) 52162306a36Sopenharmony_ci{ 52262306a36Sopenharmony_ci switch (state) 52362306a36Sopenharmony_ci { 52462306a36Sopenharmony_ci case PM_SUSPEND_MEM: 52562306a36Sopenharmony_ci omap1_pm_suspend(); 52662306a36Sopenharmony_ci break; 52762306a36Sopenharmony_ci default: 52862306a36Sopenharmony_ci return -EINVAL; 52962306a36Sopenharmony_ci } 53062306a36Sopenharmony_ci 53162306a36Sopenharmony_ci return 0; 53262306a36Sopenharmony_ci} 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_ci/** 53662306a36Sopenharmony_ci * omap_pm_finish - Finish up suspend sequence. 53762306a36Sopenharmony_ci * 53862306a36Sopenharmony_ci * This is called after we wake back up (or if entering the sleep state 53962306a36Sopenharmony_ci * failed). 54062306a36Sopenharmony_ci */ 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_cistatic void omap_pm_finish(void) 54362306a36Sopenharmony_ci{ 54462306a36Sopenharmony_ci cpu_idle_poll_ctrl(false); 54562306a36Sopenharmony_ci} 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_cistatic irqreturn_t omap_wakeup_interrupt(int irq, void *dev) 54962306a36Sopenharmony_ci{ 55062306a36Sopenharmony_ci return IRQ_HANDLED; 55162306a36Sopenharmony_ci} 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_ci 55562306a36Sopenharmony_cistatic const struct platform_suspend_ops omap_pm_ops = { 55662306a36Sopenharmony_ci .prepare = omap_pm_prepare, 55762306a36Sopenharmony_ci .enter = omap_pm_enter, 55862306a36Sopenharmony_ci .finish = omap_pm_finish, 55962306a36Sopenharmony_ci .valid = suspend_valid_only_mem, 56062306a36Sopenharmony_ci}; 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_cistatic int __init omap_pm_init(void) 56362306a36Sopenharmony_ci{ 56462306a36Sopenharmony_ci int error = 0; 56562306a36Sopenharmony_ci int irq; 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci if (!cpu_class_is_omap1()) 56862306a36Sopenharmony_ci return -ENODEV; 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci pr_info("Power Management for TI OMAP.\n"); 57162306a36Sopenharmony_ci 57262306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_OMAP_32K_TIMER)) 57362306a36Sopenharmony_ci pr_info("OMAP1 PM: sleep states in idle disabled due to no 32KiHz timer\n"); 57462306a36Sopenharmony_ci 57562306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_OMAP_DM_TIMER)) 57662306a36Sopenharmony_ci pr_info("OMAP1 PM: sleep states in idle disabled due to no DMTIMER support\n"); 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_ci if (IS_ENABLED(CONFIG_OMAP_32K_TIMER) && 57962306a36Sopenharmony_ci IS_ENABLED(CONFIG_OMAP_DM_TIMER)) { 58062306a36Sopenharmony_ci /* OMAP16xx only */ 58162306a36Sopenharmony_ci pr_info("OMAP1 PM: sleep states in idle enabled\n"); 58262306a36Sopenharmony_ci enable_dyn_sleep = 1; 58362306a36Sopenharmony_ci } 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci /* 58662306a36Sopenharmony_ci * We copy the assembler sleep/wakeup routines to SRAM. 58762306a36Sopenharmony_ci * These routines need to be in SRAM as that's the only 58862306a36Sopenharmony_ci * memory the MPU can see when it wakes up. 58962306a36Sopenharmony_ci */ 59062306a36Sopenharmony_ci if (cpu_is_omap15xx()) { 59162306a36Sopenharmony_ci omap_sram_suspend = omap_sram_push(omap1510_cpu_suspend, 59262306a36Sopenharmony_ci omap1510_cpu_suspend_sz); 59362306a36Sopenharmony_ci } else if (cpu_is_omap16xx()) { 59462306a36Sopenharmony_ci omap_sram_suspend = omap_sram_push(omap1610_cpu_suspend, 59562306a36Sopenharmony_ci omap1610_cpu_suspend_sz); 59662306a36Sopenharmony_ci } 59762306a36Sopenharmony_ci 59862306a36Sopenharmony_ci if (omap_sram_suspend == NULL) { 59962306a36Sopenharmony_ci printk(KERN_ERR "PM not initialized: Missing SRAM support\n"); 60062306a36Sopenharmony_ci return -ENODEV; 60162306a36Sopenharmony_ci } 60262306a36Sopenharmony_ci 60362306a36Sopenharmony_ci arm_pm_idle = omap1_pm_idle; 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_ci if (cpu_is_omap16xx()) 60662306a36Sopenharmony_ci irq = INT_1610_WAKE_UP_REQ; 60762306a36Sopenharmony_ci else 60862306a36Sopenharmony_ci irq = -1; 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci if (irq >= 0) { 61162306a36Sopenharmony_ci if (request_irq(irq, omap_wakeup_interrupt, 0, "peripheral wakeup", NULL)) 61262306a36Sopenharmony_ci pr_err("Failed to request irq %d (peripheral wakeup)\n", irq); 61362306a36Sopenharmony_ci } 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci /* Program new power ramp-up time 61662306a36Sopenharmony_ci * (0 for most boards since we don't lower voltage when in deep sleep) 61762306a36Sopenharmony_ci */ 61862306a36Sopenharmony_ci omap_writew(ULPD_SETUP_ANALOG_CELL_3_VAL, ULPD_SETUP_ANALOG_CELL_3); 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ci /* Setup ULPD POWER_CTRL_REG - enter deep sleep whenever possible */ 62162306a36Sopenharmony_ci omap_writew(ULPD_POWER_CTRL_REG_VAL, ULPD_POWER_CTRL); 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ci /* Configure IDLECT3 */ 62462306a36Sopenharmony_ci if (cpu_is_omap16xx()) 62562306a36Sopenharmony_ci omap_writel(OMAP1610_IDLECT3_VAL, OMAP1610_IDLECT3); 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci suspend_set_ops(&omap_pm_ops); 62862306a36Sopenharmony_ci 62962306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 63062306a36Sopenharmony_ci omap_pm_init_debugfs(); 63162306a36Sopenharmony_ci#endif 63262306a36Sopenharmony_ci 63362306a36Sopenharmony_ci error = sysfs_create_file(power_kobj, &sleep_while_idle_attr.attr); 63462306a36Sopenharmony_ci if (error) 63562306a36Sopenharmony_ci pr_err("sysfs_create_file failed: %d\n", error); 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_ci if (cpu_is_omap16xx()) { 63862306a36Sopenharmony_ci /* configure LOW_PWR pin */ 63962306a36Sopenharmony_ci omap_cfg_reg(T20_1610_LOW_PWR); 64062306a36Sopenharmony_ci } 64162306a36Sopenharmony_ci 64262306a36Sopenharmony_ci return error; 64362306a36Sopenharmony_ci} 64462306a36Sopenharmony_ci__initcall(omap_pm_init); 645