Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2006-2007 PA Semi, Inc |
| 4 | * |
| 5 | * Maintained by: Olof Johansson <olof@lixom.net> |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #undef DEBUG |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/string.h> |
Stephen Rothwell | bff8dde | 2007-05-11 15:40:36 +1000 | [diff] [blame] | 12 | #include <linux/irq.h> |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 13 | |
| 14 | #include <asm/machdep.h> |
| 15 | #include <asm/reg.h> |
Stephen Rothwell | 18456d01 | 2007-05-28 10:20:45 +1000 | [diff] [blame] | 16 | #include <asm/smp.h> |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 17 | |
| 18 | #include "pasemi.h" |
| 19 | |
| 20 | struct sleep_mode { |
| 21 | char *name; |
| 22 | void (*entry)(void); |
| 23 | }; |
| 24 | |
| 25 | static struct sleep_mode modes[] = { |
| 26 | { .name = "spin", .entry = &idle_spin }, |
| 27 | { .name = "doze", .entry = &idle_doze }, |
| 28 | }; |
| 29 | |
| 30 | static int current_mode = 0; |
| 31 | |
| 32 | static int pasemi_system_reset_exception(struct pt_regs *regs) |
| 33 | { |
| 34 | /* If we were woken up from power savings, we need to return |
| 35 | * to the calling function, since nip is not saved across |
| 36 | * all modes. |
| 37 | */ |
| 38 | |
| 39 | if (regs->msr & SRR1_WAKEMASK) |
| 40 | regs->nip = regs->link; |
| 41 | |
| 42 | switch (regs->msr & SRR1_WAKEMASK) { |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 43 | case SRR1_WAKEDEC: |
Nicholas Piggin | 461e96a | 2017-03-20 16:31:48 +1000 | [diff] [blame] | 44 | set_dec(1); |
| 45 | case SRR1_WAKEEE: |
| 46 | /* |
| 47 | * Handle these when interrupts get re-enabled and we take |
| 48 | * them as regular exceptions. We are in an NMI context |
| 49 | * and can't handle these here. |
| 50 | */ |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 51 | break; |
| 52 | default: |
| 53 | /* do system reset */ |
| 54 | return 0; |
| 55 | } |
Olof Johansson | 2e0c337 | 2007-04-27 15:46:01 +1000 | [diff] [blame] | 56 | |
| 57 | /* Set higher astate since we come out of power savings at 0 */ |
| 58 | restore_astate(hard_smp_processor_id()); |
| 59 | |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 60 | /* everything handled */ |
| 61 | regs->msr |= MSR_RI; |
| 62 | return 1; |
| 63 | } |
| 64 | |
Olof Johansson | 3850169 | 2007-09-05 12:09:45 +1000 | [diff] [blame] | 65 | static int __init pasemi_idle_init(void) |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 66 | { |
Olof Johansson | 2e0c337 | 2007-04-27 15:46:01 +1000 | [diff] [blame] | 67 | #ifndef CONFIG_PPC_PASEMI_CPUFREQ |
Darren Stevens | e13606d | 2018-08-03 21:15:10 +1000 | [diff] [blame] | 68 | pr_warn("No cpufreq driver, powersavings modes disabled\n"); |
Olof Johansson | 2e0c337 | 2007-04-27 15:46:01 +1000 | [diff] [blame] | 69 | current_mode = 0; |
| 70 | #endif |
| 71 | |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 72 | ppc_md.system_reset_exception = pasemi_system_reset_exception; |
| 73 | ppc_md.power_save = modes[current_mode].entry; |
Darren Stevens | e13606d | 2018-08-03 21:15:10 +1000 | [diff] [blame] | 74 | pr_info("Using PA6T idle loop (%s)\n", modes[current_mode].name); |
Olof Johansson | 3850169 | 2007-09-05 12:09:45 +1000 | [diff] [blame] | 75 | |
| 76 | return 0; |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 77 | } |
Grant Likely | bdddec4 | 2008-01-02 12:32:28 -0700 | [diff] [blame] | 78 | machine_late_initcall(pasemi, pasemi_idle_init); |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 79 | |
| 80 | static int __init idle_param(char *p) |
| 81 | { |
| 82 | int i; |
Stoyan Gaydarov | a888ad4 | 2009-07-21 17:02:31 +0000 | [diff] [blame] | 83 | for (i = 0; i < ARRAY_SIZE(modes); i++) { |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 84 | if (!strcmp(modes[i].name, p)) { |
| 85 | current_mode = i; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | early_param("idle", idle_param); |