idle.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2006-2007 PA Semi, Inc
  4. *
  5. * Maintained by: Olof Johansson <[email protected]>
  6. */
  7. #undef DEBUG
  8. #include <linux/kernel.h>
  9. #include <linux/string.h>
  10. #include <linux/irq.h>
  11. #include <asm/machdep.h>
  12. #include <asm/reg.h>
  13. #include <asm/smp.h>
  14. #include "pasemi.h"
  15. struct sleep_mode {
  16. char *name;
  17. void (*entry)(void);
  18. };
  19. static struct sleep_mode modes[] = {
  20. { .name = "spin", .entry = &idle_spin },
  21. { .name = "doze", .entry = &idle_doze },
  22. };
  23. static int current_mode = 0;
  24. static int pasemi_system_reset_exception(struct pt_regs *regs)
  25. {
  26. /* If we were woken up from power savings, we need to return
  27. * to the calling function, since nip is not saved across
  28. * all modes.
  29. */
  30. if (regs->msr & SRR1_WAKEMASK)
  31. regs_set_return_ip(regs, regs->link);
  32. switch (regs->msr & SRR1_WAKEMASK) {
  33. case SRR1_WAKEDEC:
  34. set_dec(1);
  35. break;
  36. case SRR1_WAKEEE:
  37. /*
  38. * Handle these when interrupts get re-enabled and we take
  39. * them as regular exceptions. We are in an NMI context
  40. * and can't handle these here.
  41. */
  42. break;
  43. default:
  44. /* do system reset */
  45. return 0;
  46. }
  47. /* Set higher astate since we come out of power savings at 0 */
  48. restore_astate(hard_smp_processor_id());
  49. /* everything handled */
  50. regs_set_recoverable(regs);
  51. return 1;
  52. }
  53. static int __init pasemi_idle_init(void)
  54. {
  55. #ifndef CONFIG_PPC_PASEMI_CPUFREQ
  56. pr_warn("No cpufreq driver, powersavings modes disabled\n");
  57. current_mode = 0;
  58. #endif
  59. ppc_md.system_reset_exception = pasemi_system_reset_exception;
  60. ppc_md.power_save = modes[current_mode].entry;
  61. pr_info("Using PA6T idle loop (%s)\n", modes[current_mode].name);
  62. return 0;
  63. }
  64. machine_late_initcall(pasemi, pasemi_idle_init);
  65. static int __init idle_param(char *p)
  66. {
  67. int i;
  68. for (i = 0; i < ARRAY_SIZE(modes); i++) {
  69. if (!strcmp(modes[i].name, p)) {
  70. current_mode = i;
  71. break;
  72. }
  73. }
  74. return 0;
  75. }
  76. early_param("idle", idle_param);