| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 | 
							- /*
 
-  * OMAP3 Power Management Routines
 
-  *
 
-  * Copyright (C) 2006-2008 Nokia Corporation
 
-  * Tony Lindgren <tony@atomide.com>
 
-  * Jouni Hogander
 
-  *
 
-  * Copyright (C) 2007 Texas Instruments, Inc.
 
-  * Rajendra Nayak <rnayak@ti.com>
 
-  *
 
-  * Copyright (C) 2005 Texas Instruments, Inc.
 
-  * Richard Woodruff <r-woodruff2@ti.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/pm.h>
 
- #include <linux/suspend.h>
 
- #include <linux/interrupt.h>
 
- #include <linux/module.h>
 
- #include <linux/list.h>
 
- #include <linux/err.h>
 
- #include <linux/gpio.h>
 
- #include <linux/clk.h>
 
- #include <linux/delay.h>
 
- #include <linux/slab.h>
 
- #include <linux/omap-dma.h>
 
- #include <linux/platform_data/gpio-omap.h>
 
- #include <trace/events/power.h>
 
- #include <asm/fncpy.h>
 
- #include <asm/suspend.h>
 
- #include <asm/system_misc.h>
 
- #include "clockdomain.h"
 
- #include "powerdomain.h"
 
- #include "soc.h"
 
- #include "common.h"
 
- #include "cm3xxx.h"
 
- #include "cm-regbits-34xx.h"
 
- #include "gpmc.h"
 
- #include "prm-regbits-34xx.h"
 
- #include "prm3xxx.h"
 
- #include "pm.h"
 
- #include "sdrc.h"
 
- #include "sram.h"
 
- #include "control.h"
 
- /* pm34xx errata defined in pm.h */
 
- u16 pm34xx_errata;
 
- struct power_state {
 
- 	struct powerdomain *pwrdm;
 
- 	u32 next_state;
 
- #ifdef CONFIG_SUSPEND
 
- 	u32 saved_state;
 
- #endif
 
- 	struct list_head node;
 
- };
 
- static LIST_HEAD(pwrst_list);
 
- static int (*_omap_save_secure_sram)(u32 *addr);
 
- void (*omap3_do_wfi_sram)(void);
 
- static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
 
- static struct powerdomain *core_pwrdm, *per_pwrdm;
 
- static void omap3_core_save_context(void)
 
- {
 
- 	omap3_ctrl_save_padconf();
 
- 	/*
 
- 	 * Force write last pad into memory, as this can fail in some
 
- 	 * cases according to errata 1.157, 1.185
 
- 	 */
 
- 	omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
 
- 		OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
 
- 	/* Save the Interrupt controller context */
 
- 	omap_intc_save_context();
 
- 	/* Save the GPMC context */
 
- 	omap3_gpmc_save_context();
 
- 	/* Save the system control module context, padconf already save above*/
 
- 	omap3_control_save_context();
 
- 	omap_dma_global_context_save();
 
- }
 
- static void omap3_core_restore_context(void)
 
- {
 
- 	/* Restore the control module context, padconf restored by h/w */
 
- 	omap3_control_restore_context();
 
- 	/* Restore the GPMC context */
 
- 	omap3_gpmc_restore_context();
 
- 	/* Restore the interrupt controller context */
 
- 	omap_intc_restore_context();
 
- 	omap_dma_global_context_restore();
 
- }
 
- /*
 
-  * FIXME: This function should be called before entering off-mode after
 
-  * OMAP3 secure services have been accessed. Currently it is only called
 
-  * once during boot sequence, but this works as we are not using secure
 
-  * services.
 
-  */
 
- static void omap3_save_secure_ram_context(void)
 
- {
 
- 	u32 ret;
 
- 	int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
 
- 	if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
 
- 		/*
 
- 		 * MPU next state must be set to POWER_ON temporarily,
 
- 		 * otherwise the WFI executed inside the ROM code
 
- 		 * will hang the system.
 
- 		 */
 
- 		pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
 
- 		ret = _omap_save_secure_sram((u32 *)
 
- 				__pa(omap3_secure_ram_storage));
 
- 		pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
 
- 		/* Following is for error tracking, it should not happen */
 
- 		if (ret) {
 
- 			pr_err("save_secure_sram() returns %08x\n", ret);
 
- 			while (1)
 
- 				;
 
- 		}
 
- 	}
 
- }
 
- /*
 
-  * PRCM Interrupt Handler Helper Function
 
-  *
 
-  * The purpose of this function is to clear any wake-up events latched
 
-  * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
 
-  * may occur whilst attempting to clear a PM_WKST_x register and thus
 
-  * set another bit in this register. A while loop is used to ensure
 
-  * that any peripheral wake-up events occurring while attempting to
 
-  * clear the PM_WKST_x are detected and cleared.
 
-  */
 
- static int prcm_clear_mod_irqs(s16 module, u8 regs, u32 ignore_bits)
 
- {
 
- 	u32 wkst, fclk, iclk, clken;
 
- 	u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
 
- 	u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
 
- 	u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
 
- 	u16 grpsel_off = (regs == 3) ?
 
- 		OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
 
- 	int c = 0;
 
- 	wkst = omap2_prm_read_mod_reg(module, wkst_off);
 
- 	wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
 
- 	wkst &= ~ignore_bits;
 
- 	if (wkst) {
 
- 		iclk = omap2_cm_read_mod_reg(module, iclk_off);
 
- 		fclk = omap2_cm_read_mod_reg(module, fclk_off);
 
- 		while (wkst) {
 
- 			clken = wkst;
 
- 			omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
 
- 			/*
 
- 			 * For USBHOST, we don't know whether HOST1 or
 
- 			 * HOST2 woke us up, so enable both f-clocks
 
- 			 */
 
- 			if (module == OMAP3430ES2_USBHOST_MOD)
 
- 				clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
 
- 			omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
 
- 			omap2_prm_write_mod_reg(wkst, module, wkst_off);
 
- 			wkst = omap2_prm_read_mod_reg(module, wkst_off);
 
- 			wkst &= ~ignore_bits;
 
- 			c++;
 
- 		}
 
- 		omap2_cm_write_mod_reg(iclk, module, iclk_off);
 
- 		omap2_cm_write_mod_reg(fclk, module, fclk_off);
 
- 	}
 
- 	return c;
 
- }
 
- static irqreturn_t _prcm_int_handle_io(int irq, void *unused)
 
- {
 
- 	int c;
 
- 	c = prcm_clear_mod_irqs(WKUP_MOD, 1,
 
- 		~(OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK));
 
- 	return c ? IRQ_HANDLED : IRQ_NONE;
 
- }
 
- static irqreturn_t _prcm_int_handle_wakeup(int irq, void *unused)
 
- {
 
- 	int c;
 
- 	/*
 
- 	 * Clear all except ST_IO and ST_IO_CHAIN for wkup module,
 
- 	 * these are handled in a separate handler to avoid acking
 
- 	 * IO events before parsing in mux code
 
- 	 */
 
- 	c = prcm_clear_mod_irqs(WKUP_MOD, 1,
 
- 		OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK);
 
- 	c += prcm_clear_mod_irqs(CORE_MOD, 1, 0);
 
- 	c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1, 0);
 
- 	if (omap_rev() > OMAP3430_REV_ES1_0) {
 
- 		c += prcm_clear_mod_irqs(CORE_MOD, 3, 0);
 
- 		c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1, 0);
 
- 	}
 
- 	return c ? IRQ_HANDLED : IRQ_NONE;
 
- }
 
- static void omap34xx_save_context(u32 *save)
 
- {
 
- 	u32 val;
 
- 	/* Read Auxiliary Control Register */
 
- 	asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (val));
 
- 	*save++ = 1;
 
- 	*save++ = val;
 
- 	/* Read L2 AUX ctrl register */
 
- 	asm("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
 
- 	*save++ = 1;
 
- 	*save++ = val;
 
- }
 
- static int omap34xx_do_sram_idle(unsigned long save_state)
 
- {
 
- 	omap34xx_cpu_suspend(save_state);
 
- 	return 0;
 
- }
 
- void omap_sram_idle(void)
 
- {
 
- 	/* Variable to tell what needs to be saved and restored
 
- 	 * in omap_sram_idle*/
 
- 	/* save_state = 0 => Nothing to save and restored */
 
- 	/* save_state = 1 => Only L1 and logic lost */
 
- 	/* save_state = 2 => Only L2 lost */
 
- 	/* save_state = 3 => L1, L2 and logic lost */
 
- 	int save_state = 0;
 
- 	int mpu_next_state = PWRDM_POWER_ON;
 
- 	int per_next_state = PWRDM_POWER_ON;
 
- 	int core_next_state = PWRDM_POWER_ON;
 
- 	int per_going_off;
 
- 	int core_prev_state;
 
- 	u32 sdrc_pwr = 0;
 
- 	mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
 
- 	switch (mpu_next_state) {
 
- 	case PWRDM_POWER_ON:
 
- 	case PWRDM_POWER_RET:
 
- 		/* No need to save context */
 
- 		save_state = 0;
 
- 		break;
 
- 	case PWRDM_POWER_OFF:
 
- 		save_state = 3;
 
- 		break;
 
- 	default:
 
- 		/* Invalid state */
 
- 		pr_err("Invalid mpu state in sram_idle\n");
 
- 		return;
 
- 	}
 
- 	/* NEON control */
 
- 	if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
 
- 		pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
 
- 	/* Enable IO-PAD and IO-CHAIN wakeups */
 
- 	per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
 
- 	core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
 
- 	pwrdm_pre_transition(NULL);
 
- 	/* PER */
 
- 	if (per_next_state < PWRDM_POWER_ON) {
 
- 		per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
 
- 		omap2_gpio_prepare_for_idle(per_going_off);
 
- 	}
 
- 	/* CORE */
 
- 	if (core_next_state < PWRDM_POWER_ON) {
 
- 		if (core_next_state == PWRDM_POWER_OFF) {
 
- 			omap3_core_save_context();
 
- 			omap3_cm_save_context();
 
- 		}
 
- 	}
 
- 	omap3_intc_prepare_idle();
 
- 	/*
 
- 	 * On EMU/HS devices ROM code restores a SRDC value
 
- 	 * from scratchpad which has automatic self refresh on timeout
 
 
  |