| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 | 
							- /*
 
-  * OMAP2 Power Management Routines
 
-  *
 
-  * Copyright (C) 2005 Texas Instruments, Inc.
 
-  * Copyright (C) 2006-2008 Nokia Corporation
 
-  *
 
-  * Written by:
 
-  * Richard Woodruff <r-woodruff2@ti.com>
 
-  * Tony Lindgren
 
-  * Juha Yrjola
 
-  * Amit Kucheria <amit.kucheria@nokia.com>
 
-  * Igor Stoppa <igor.stoppa@nokia.com>
 
-  *
 
-  * Based on pm.c for omap1
 
-  *
 
-  * This program is free software; you can redistribute it and/or modify
 
-  * it under the terms of the GNU General Public License version 2 as
 
-  * published by the Free Software Foundation.
 
-  */
 
- #include <linux/suspend.h>
 
- #include <linux/sched.h>
 
- #include <linux/proc_fs.h>
 
- #include <linux/interrupt.h>
 
- #include <linux/sysfs.h>
 
- #include <linux/module.h>
 
- #include <linux/delay.h>
 
- #include <linux/clk-provider.h>
 
- #include <linux/irq.h>
 
- #include <linux/time.h>
 
- #include <linux/gpio.h>
 
- #include <linux/platform_data/gpio-omap.h>
 
- #include <asm/fncpy.h>
 
- #include <asm/mach/time.h>
 
- #include <asm/mach/irq.h>
 
- #include <asm/mach-types.h>
 
- #include <asm/system_misc.h>
 
- #include <linux/omap-dma.h>
 
- #include "soc.h"
 
- #include "common.h"
 
- #include "clock.h"
 
- #include "prm2xxx.h"
 
- #include "prm-regbits-24xx.h"
 
- #include "cm2xxx.h"
 
- #include "cm-regbits-24xx.h"
 
- #include "sdrc.h"
 
- #include "sram.h"
 
- #include "pm.h"
 
- #include "control.h"
 
- #include "powerdomain.h"
 
- #include "clockdomain.h"
 
- static void (*omap2_sram_idle)(void);
 
- static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
 
- 				  void __iomem *sdrc_power);
 
- static struct powerdomain *mpu_pwrdm, *core_pwrdm;
 
- static struct clockdomain *dsp_clkdm, *mpu_clkdm, *wkup_clkdm, *gfx_clkdm;
 
- static struct clk *osc_ck, *emul_ck;
 
- static int omap2_fclks_active(void)
 
- {
 
- 	u32 f1, f2;
 
- 	f1 = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
 
- 	f2 = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
 
- 	return (f1 | f2) ? 1 : 0;
 
- }
 
- static int omap2_enter_full_retention(void)
 
- {
 
- 	u32 l;
 
- 	/* There is 1 reference hold for all children of the oscillator
 
- 	 * clock, the following will remove it. If no one else uses the
 
- 	 * oscillator itself it will be disabled if/when we enter retention
 
- 	 * mode.
 
- 	 */
 
- 	clk_disable(osc_ck);
 
- 	/* Clear old wake-up events */
 
- 	/* REVISIT: These write to reserved bits? */
 
- 	omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
 
- 	omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
 
- 	omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST);
 
- 	/*
 
- 	 * Set MPU powerdomain's next power state to RETENTION;
 
- 	 * preserve logic state during retention
 
- 	 */
 
- 	pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
 
- 	pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
 
- 	/* Workaround to kill USB */
 
- 	l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL;
 
- 	omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0);
 
- 	omap2_gpio_prepare_for_idle(0);
 
- 	/* One last check for pending IRQs to avoid extra latency due
 
- 	 * to sleeping unnecessarily. */
 
- 	if (omap_irq_pending())
 
- 		goto no_sleep;
 
- 	/* Jump to SRAM suspend code */
 
- 	omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL),
 
- 			   OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL),
 
- 			   OMAP_SDRC_REGADDR(SDRC_POWER));
 
- no_sleep:
 
- 	omap2_gpio_resume_after_idle();
 
- 	clk_enable(osc_ck);
 
- 	/* clear CORE wake-up events */
 
- 	omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
 
- 	omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
 
- 	/* wakeup domain events - bit 1: GPT1, bit5 GPIO */
 
- 	omap2_prm_clear_mod_reg_bits(0x4 | 0x1, WKUP_MOD, PM_WKST);
 
- 	/* MPU domain wake events */
 
- 	l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
 
- 	if (l & 0x01)
 
- 		omap2_prm_write_mod_reg(0x01, OCP_MOD,
 
- 				  OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
 
- 	if (l & 0x20)
 
- 		omap2_prm_write_mod_reg(0x20, OCP_MOD,
 
- 				  OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
 
- 	/* Mask future PRCM-to-MPU interrupts */
 
- 	omap2_prm_write_mod_reg(0x0, OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
 
- 	return 0;
 
- }
 
- static int omap2_i2c_active(void)
 
- {
 
- 	u32 l;
 
- 	l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
 
- 	return l & (OMAP2420_EN_I2C2_MASK | OMAP2420_EN_I2C1_MASK);
 
- }
 
- static int sti_console_enabled;
 
- static int omap2_allow_mpu_retention(void)
 
- {
 
- 	u32 l;
 
- 	/* Check for MMC, UART2, UART1, McSPI2, McSPI1 and DSS1. */
 
- 	l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
 
- 	if (l & (OMAP2420_EN_MMC_MASK | OMAP24XX_EN_UART2_MASK |
 
- 		 OMAP24XX_EN_UART1_MASK | OMAP24XX_EN_MCSPI2_MASK |
 
- 		 OMAP24XX_EN_MCSPI1_MASK | OMAP24XX_EN_DSS1_MASK))
 
- 		return 0;
 
- 	/* Check for UART3. */
 
- 	l = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
 
- 	if (l & OMAP24XX_EN_UART3_MASK)
 
- 		return 0;
 
- 	if (sti_console_enabled)
 
- 		return 0;
 
- 	return 1;
 
- }
 
- static void omap2_enter_mpu_retention(void)
 
- {
 
- 	/* Putting MPU into the WFI state while a transfer is active
 
- 	 * seems to cause the I2C block to timeout. Why? Good question. */
 
- 	if (omap2_i2c_active())
 
- 		return;
 
- 	/* The peripherals seem not to be able to wake up the MPU when
 
- 	 * it is in retention mode. */
 
- 	if (omap2_allow_mpu_retention()) {
 
- 		/* REVISIT: These write to reserved bits? */
 
- 		omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
 
- 		omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
 
 
  |