linux/arch/arm/mach-pxa/pm.c
<<
>>
Prefs
   1/*
   2 * PXA250/210 Power Management Routines
   3 *
   4 * Original code for the SA11x0:
   5 * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
   6 *
   7 * Modified for the PXA250 by Nicolas Pitre:
   8 * Copyright (c) 2002 Monta Vista Software, Inc.
   9 *
  10 * This program is free software; you can redistribute it and/or
  11 * modify it under the terms of the GNU General Public License.
  12 */
  13#include <linux/init.h>
  14#include <linux/module.h>
  15#include <linux/suspend.h>
  16#include <linux/errno.h>
  17#include <linux/slab.h>
  18
  19#include <mach/pm.h>
  20
  21struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
  22static unsigned long *sleep_save;
  23
  24int pxa_pm_enter(suspend_state_t state)
  25{
  26        unsigned long sleep_save_checksum = 0, checksum = 0;
  27        int i;
  28
  29#ifdef CONFIG_IWMMXT
  30        /* force any iWMMXt context to ram **/
  31        if (elf_hwcap & HWCAP_IWMMXT)
  32                iwmmxt_task_disable(NULL);
  33#endif
  34
  35        /* skip registers saving for standby */
  36        if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->save) {
  37                pxa_cpu_pm_fns->save(sleep_save);
  38                /* before sleeping, calculate and save a checksum */
  39                for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
  40                        sleep_save_checksum += sleep_save[i];
  41        }
  42
  43        /* *** go zzz *** */
  44        pxa_cpu_pm_fns->enter(state);
  45
  46        if (state != PM_SUSPEND_STANDBY && pxa_cpu_pm_fns->restore) {
  47                /* after sleeping, validate the checksum */
  48                for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
  49                        checksum += sleep_save[i];
  50
  51                /* if invalid, display message and wait for a hardware reset */
  52                if (checksum != sleep_save_checksum) {
  53
  54                        lubbock_set_hexled(0xbadbadc5);
  55
  56                        while (1)
  57                                pxa_cpu_pm_fns->enter(state);
  58                }
  59                pxa_cpu_pm_fns->restore(sleep_save);
  60        }
  61
  62        pr_debug("*** made it back from resume\n");
  63
  64        return 0;
  65}
  66
  67EXPORT_SYMBOL_GPL(pxa_pm_enter);
  68
  69static int pxa_pm_valid(suspend_state_t state)
  70{
  71        if (pxa_cpu_pm_fns)
  72                return pxa_cpu_pm_fns->valid(state);
  73
  74        return -EINVAL;
  75}
  76
  77int pxa_pm_prepare(void)
  78{
  79        int ret = 0;
  80
  81        if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
  82                ret = pxa_cpu_pm_fns->prepare();
  83
  84        return ret;
  85}
  86
  87void pxa_pm_finish(void)
  88{
  89        if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
  90                pxa_cpu_pm_fns->finish();
  91}
  92
  93static const struct platform_suspend_ops pxa_pm_ops = {
  94        .valid          = pxa_pm_valid,
  95        .enter          = pxa_pm_enter,
  96        .prepare        = pxa_pm_prepare,
  97        .finish         = pxa_pm_finish,
  98};
  99
 100static int __init pxa_pm_init(void)
 101{
 102        if (!pxa_cpu_pm_fns) {
 103                printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
 104                return -EINVAL;
 105        }
 106
 107        sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
 108                             GFP_KERNEL);
 109        if (!sleep_save) {
 110                printk(KERN_ERR "failed to alloc memory for pm save\n");
 111                return -ENOMEM;
 112        }
 113
 114        suspend_set_ops(&pxa_pm_ops);
 115        return 0;
 116}
 117
 118device_initcall(pxa_pm_init);
 119