pm.c 2.6 KB

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