blob: 1c954c90b0f43920a5422669feccf5d1a95198c4 [file] [log] [blame]
Thomas Gleixner45051532019-05-29 16:57:47 -07001// SPDX-License-Identifier: GPL-2.0-only
Olof Johansson11999192007-02-04 16:36:51 -06002/*
3 * Copyright (C) 2006-2007 PA Semi, Inc
4 *
5 * Maintained by: Olof Johansson <olof@lixom.net>
Olof Johansson11999192007-02-04 16:36:51 -06006 */
7
8#undef DEBUG
9
10#include <linux/kernel.h>
11#include <linux/string.h>
Stephen Rothwellbff8dde2007-05-11 15:40:36 +100012#include <linux/irq.h>
Olof Johansson11999192007-02-04 16:36:51 -060013
14#include <asm/machdep.h>
15#include <asm/reg.h>
Stephen Rothwell18456d012007-05-28 10:20:45 +100016#include <asm/smp.h>
Olof Johansson11999192007-02-04 16:36:51 -060017
18#include "pasemi.h"
19
20struct sleep_mode {
21 char *name;
22 void (*entry)(void);
23};
24
25static struct sleep_mode modes[] = {
26 { .name = "spin", .entry = &idle_spin },
27 { .name = "doze", .entry = &idle_doze },
28};
29
30static int current_mode = 0;
31
32static 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 Johansson11999192007-02-04 16:36:51 -060043 case SRR1_WAKEDEC:
Nicholas Piggin461e96a2017-03-20 16:31:48 +100044 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 Johansson11999192007-02-04 16:36:51 -060051 break;
52 default:
53 /* do system reset */
54 return 0;
55 }
Olof Johansson2e0c3372007-04-27 15:46:01 +100056
57 /* Set higher astate since we come out of power savings at 0 */
58 restore_astate(hard_smp_processor_id());
59
Olof Johansson11999192007-02-04 16:36:51 -060060 /* everything handled */
61 regs->msr |= MSR_RI;
62 return 1;
63}
64
Olof Johansson38501692007-09-05 12:09:45 +100065static int __init pasemi_idle_init(void)
Olof Johansson11999192007-02-04 16:36:51 -060066{
Olof Johansson2e0c3372007-04-27 15:46:01 +100067#ifndef CONFIG_PPC_PASEMI_CPUFREQ
Darren Stevense13606d2018-08-03 21:15:10 +100068 pr_warn("No cpufreq driver, powersavings modes disabled\n");
Olof Johansson2e0c3372007-04-27 15:46:01 +100069 current_mode = 0;
70#endif
71
Olof Johansson11999192007-02-04 16:36:51 -060072 ppc_md.system_reset_exception = pasemi_system_reset_exception;
73 ppc_md.power_save = modes[current_mode].entry;
Darren Stevense13606d2018-08-03 21:15:10 +100074 pr_info("Using PA6T idle loop (%s)\n", modes[current_mode].name);
Olof Johansson38501692007-09-05 12:09:45 +100075
76 return 0;
Olof Johansson11999192007-02-04 16:36:51 -060077}
Grant Likelybdddec42008-01-02 12:32:28 -070078machine_late_initcall(pasemi, pasemi_idle_init);
Olof Johansson11999192007-02-04 16:36:51 -060079
80static int __init idle_param(char *p)
81{
82 int i;
Stoyan Gaydarova888ad42009-07-21 17:02:31 +000083 for (i = 0; i < ARRAY_SIZE(modes); i++) {
Olof Johansson11999192007-02-04 16:36:51 -060084 if (!strcmp(modes[i].name, p)) {
85 current_mode = i;
86 break;
87 }
88 }
89 return 0;
90}
91
92early_param("idle", idle_param);