Path: blob/master/arch/powerpc/platforms/52xx/mpc52xx_pm.c
10818 views
#include <linux/init.h>1#include <linux/suspend.h>2#include <linux/io.h>3#include <asm/time.h>4#include <asm/cacheflush.h>5#include <asm/mpc52xx.h>67/* these are defined in mpc52xx_sleep.S, and only used here */8extern void mpc52xx_deep_sleep(void __iomem *sram, void __iomem *sdram_regs,9struct mpc52xx_cdm __iomem *, struct mpc52xx_intr __iomem*);10extern void mpc52xx_ds_sram(void);11extern const long mpc52xx_ds_sram_size;12extern void mpc52xx_ds_cached(void);13extern const long mpc52xx_ds_cached_size;1415static void __iomem *mbar;16static void __iomem *sdram;17static struct mpc52xx_cdm __iomem *cdm;18static struct mpc52xx_intr __iomem *intr;19static struct mpc52xx_gpio_wkup __iomem *gpiow;20static void __iomem *sram;21static int sram_size;2223struct mpc52xx_suspend mpc52xx_suspend;2425static int mpc52xx_pm_valid(suspend_state_t state)26{27switch (state) {28case PM_SUSPEND_STANDBY:29return 1;30default:31return 0;32}33}3435int mpc52xx_set_wakeup_gpio(u8 pin, u8 level)36{37u16 tmp;3839/* enable gpio */40out_8(&gpiow->wkup_gpioe, in_8(&gpiow->wkup_gpioe) | (1 << pin));41/* set as input */42out_8(&gpiow->wkup_ddr, in_8(&gpiow->wkup_ddr) & ~(1 << pin));43/* enable deep sleep interrupt */44out_8(&gpiow->wkup_inten, in_8(&gpiow->wkup_inten) | (1 << pin));45/* low/high level creates wakeup interrupt */46tmp = in_be16(&gpiow->wkup_itype);47tmp &= ~(0x3 << (pin * 2));48tmp |= (!level + 1) << (pin * 2);49out_be16(&gpiow->wkup_itype, tmp);50/* master enable */51out_8(&gpiow->wkup_maste, 1);5253return 0;54}5556int mpc52xx_pm_prepare(void)57{58struct device_node *np;59const struct of_device_id immr_ids[] = {60{ .compatible = "fsl,mpc5200-immr", },61{ .compatible = "fsl,mpc5200b-immr", },62{ .type = "soc", .compatible = "mpc5200", }, /* lite5200 */63{ .type = "builtin", .compatible = "mpc5200", }, /* efika */64{}65};66struct resource res;6768/* map the whole register space */69np = of_find_matching_node(NULL, immr_ids);7071if (of_address_to_resource(np, 0, &res)) {72pr_err("mpc52xx_pm_prepare(): could not get IMMR address\n");73of_node_put(np);74return -ENOSYS;75}7677mbar = ioremap(res.start, 0xc000); /* we should map whole region including SRAM */7879of_node_put(np);80if (!mbar) {81pr_err("mpc52xx_pm_prepare(): could not map registers\n");82return -ENOSYS;83}84/* these offsets are from mpc5200 users manual */85sdram = mbar + 0x100;86cdm = mbar + 0x200;87intr = mbar + 0x500;88gpiow = mbar + 0xc00;89sram = mbar + 0x8000; /* Those will be handled by the */90sram_size = 0x4000; /* bestcomm driver soon */9192/* call board suspend code, if applicable */93if (mpc52xx_suspend.board_suspend_prepare)94mpc52xx_suspend.board_suspend_prepare(mbar);95else {96printk(KERN_ALERT "%s: %i don't know how to wake up the board\n",97__func__, __LINE__);98goto out_unmap;99}100101return 0;102103out_unmap:104iounmap(mbar);105return -ENOSYS;106}107108109char saved_sram[0x4000];110111int mpc52xx_pm_enter(suspend_state_t state)112{113u32 clk_enables;114u32 msr, hid0;115u32 intr_main_mask;116void __iomem * irq_0x500 = (void __iomem *)CONFIG_KERNEL_START + 0x500;117unsigned long irq_0x500_stop = (unsigned long)irq_0x500 + mpc52xx_ds_cached_size;118char saved_0x500[mpc52xx_ds_cached_size];119120/* disable all interrupts in PIC */121intr_main_mask = in_be32(&intr->main_mask);122out_be32(&intr->main_mask, intr_main_mask | 0x1ffff);123124/* don't let DEC expire any time soon */125mtspr(SPRN_DEC, 0x7fffffff);126127/* save SRAM */128memcpy(saved_sram, sram, sram_size);129130/* copy low level suspend code to sram */131memcpy(sram, mpc52xx_ds_sram, mpc52xx_ds_sram_size);132133out_8(&cdm->ccs_sleep_enable, 1);134out_8(&cdm->osc_sleep_enable, 1);135out_8(&cdm->ccs_qreq_test, 1);136137/* disable all but SDRAM and bestcomm (SRAM) clocks */138clk_enables = in_be32(&cdm->clk_enables);139out_be32(&cdm->clk_enables, clk_enables & 0x00088000);140141/* disable power management */142msr = mfmsr();143mtmsr(msr & ~MSR_POW);144145/* enable sleep mode, disable others */146hid0 = mfspr(SPRN_HID0);147mtspr(SPRN_HID0, (hid0 & ~(HID0_DOZE | HID0_NAP | HID0_DPM)) | HID0_SLEEP);148149/* save original, copy our irq handler, flush from dcache and invalidate icache */150memcpy(saved_0x500, irq_0x500, mpc52xx_ds_cached_size);151memcpy(irq_0x500, mpc52xx_ds_cached, mpc52xx_ds_cached_size);152flush_icache_range((unsigned long)irq_0x500, irq_0x500_stop);153154/* call low-level sleep code */155mpc52xx_deep_sleep(sram, sdram, cdm, intr);156157/* restore original irq handler */158memcpy(irq_0x500, saved_0x500, mpc52xx_ds_cached_size);159flush_icache_range((unsigned long)irq_0x500, irq_0x500_stop);160161/* restore old power mode */162mtmsr(msr & ~MSR_POW);163mtspr(SPRN_HID0, hid0);164mtmsr(msr);165166out_be32(&cdm->clk_enables, clk_enables);167out_8(&cdm->ccs_sleep_enable, 0);168out_8(&cdm->osc_sleep_enable, 0);169170/* restore SRAM */171memcpy(sram, saved_sram, sram_size);172173/* reenable interrupts in PIC */174out_be32(&intr->main_mask, intr_main_mask);175176return 0;177}178179void mpc52xx_pm_finish(void)180{181/* call board resume code */182if (mpc52xx_suspend.board_resume_finish)183mpc52xx_suspend.board_resume_finish(mbar);184185iounmap(mbar);186}187188static const struct platform_suspend_ops mpc52xx_pm_ops = {189.valid = mpc52xx_pm_valid,190.prepare = mpc52xx_pm_prepare,191.enter = mpc52xx_pm_enter,192.finish = mpc52xx_pm_finish,193};194195int __init mpc52xx_pm_init(void)196{197suspend_set_ops(&mpc52xx_pm_ops);198return 0;199}200201202