pm.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/time.h>
  18. #include <mach/hardware.h>
  19. #include <asm/memory.h>
  20. #include <asm/system.h>
  21. #include <mach/pm.h>
  22. #include <mach/pxa-regs.h>
  23. #include <mach/lubbock.h>
  24. #include <asm/mach/time.h>
  25. struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
  26. static unsigned long *sleep_save;
  27. int pxa_pm_enter(suspend_state_t state)
  28. {
  29. unsigned long sleep_save_checksum = 0, checksum = 0;
  30. int i;
  31. #ifdef CONFIG_IWMMXT
  32. /* force any iWMMXt context to ram **/
  33. if (elf_hwcap & HWCAP_IWMMXT)
  34. iwmmxt_task_disable(NULL);
  35. #endif
  36. /* skip registers saving for standby */
  37. if (state != PM_SUSPEND_STANDBY) {
  38. pxa_cpu_pm_fns->save(sleep_save);
  39. /* before sleeping, calculate and save a checksum */
  40. for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
  41. sleep_save_checksum += sleep_save[i];
  42. }
  43. /* *** go zzz *** */
  44. pxa_cpu_pm_fns->enter(state);
  45. cpu_init();
  46. if (state != PM_SUSPEND_STANDBY) {
  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. /* if invalid, display message and wait for a hardware reset */
  51. if (checksum != sleep_save_checksum) {
  52. #ifdef CONFIG_ARCH_LUBBOCK
  53. LUB_HEXLED = 0xbadbadc5;
  54. #endif
  55. while (1)
  56. pxa_cpu_pm_fns->enter(state);
  57. }
  58. pxa_cpu_pm_fns->restore(sleep_save);
  59. }
  60. pr_debug("*** made it back from resume\n");
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_GPL(pxa_pm_enter);
  64. unsigned long sleep_phys_sp(void *sp)
  65. {
  66. return virt_to_phys(sp);
  67. }
  68. static int pxa_pm_valid(suspend_state_t state)
  69. {
  70. if (pxa_cpu_pm_fns)
  71. return pxa_cpu_pm_fns->valid(state);
  72. return -EINVAL;
  73. }
  74. static int pxa_pm_prepare(void)
  75. {
  76. int ret = 0;
  77. if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
  78. ret = pxa_cpu_pm_fns->prepare();
  79. return ret;
  80. }
  81. static void pxa_pm_finish(void)
  82. {
  83. if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
  84. pxa_cpu_pm_fns->finish();
  85. }
  86. static struct platform_suspend_ops pxa_pm_ops = {
  87. .valid = pxa_pm_valid,
  88. .enter = pxa_pm_enter,
  89. .prepare = pxa_pm_prepare,
  90. .finish = pxa_pm_finish,
  91. };
  92. static int __init pxa_pm_init(void)
  93. {
  94. if (!pxa_cpu_pm_fns) {
  95. printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
  96. return -EINVAL;
  97. }
  98. sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
  99. GFP_KERNEL);
  100. if (!sleep_save) {
  101. printk(KERN_ERR "failed to alloc memory for pm save\n");
  102. return -ENOMEM;
  103. }
  104. suspend_set_ops(&pxa_pm_ops);
  105. return 0;
  106. }
  107. device_initcall(pxa_pm_init);