usb: gadget: udc: pch_udc: Fix a plethora of function documentation related issues
[linux/fpc-iii.git] / arch / mips / loongson2ef / common / pm.c
blobbcb7ae9777cf4c5e1e4008a84232412927854956
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * loongson-specific suspend support
5 * Copyright (C) 2009 Lemote Inc.
6 * Author: Wu Zhangjin <wuzhangjin@gmail.com>
7 */
8 #include <linux/suspend.h>
9 #include <linux/interrupt.h>
10 #include <linux/pm.h>
12 #include <asm/i8259.h>
13 #include <asm/mipsregs.h>
15 #include <loongson.h>
17 static unsigned int __maybe_unused cached_master_mask; /* i8259A */
18 static unsigned int __maybe_unused cached_slave_mask;
19 static unsigned int __maybe_unused cached_bonito_irq_mask; /* bonito */
21 void arch_suspend_disable_irqs(void)
23 /* disable all mips events */
24 local_irq_disable();
26 #ifdef CONFIG_I8259
27 /* disable all events of i8259A */
28 cached_slave_mask = inb(PIC_SLAVE_IMR);
29 cached_master_mask = inb(PIC_MASTER_IMR);
31 outb(0xff, PIC_SLAVE_IMR);
32 inb(PIC_SLAVE_IMR);
33 outb(0xff, PIC_MASTER_IMR);
34 inb(PIC_MASTER_IMR);
35 #endif
36 /* disable all events of bonito */
37 cached_bonito_irq_mask = LOONGSON_INTEN;
38 LOONGSON_INTENCLR = 0xffff;
39 (void)LOONGSON_INTENCLR;
42 void arch_suspend_enable_irqs(void)
44 /* enable all mips events */
45 local_irq_enable();
46 #ifdef CONFIG_I8259
47 /* only enable the cached events of i8259A */
48 outb(cached_slave_mask, PIC_SLAVE_IMR);
49 outb(cached_master_mask, PIC_MASTER_IMR);
50 #endif
51 /* enable all cached events of bonito */
52 LOONGSON_INTENSET = cached_bonito_irq_mask;
53 (void)LOONGSON_INTENSET;
57 * Setup the board-specific events for waking up loongson from wait mode
59 void __weak setup_wakeup_events(void)
64 * Check wakeup events
66 int __weak wakeup_loongson(void)
68 return 1;
72 * If the events are really what we want to wakeup the CPU, wake it up
73 * otherwise put the CPU asleep again.
75 static void wait_for_wakeup_events(void)
77 while (!wakeup_loongson())
78 writel(readl(LOONGSON_CHIPCFG) & ~0x7, LOONGSON_CHIPCFG);
82 * Stop all perf counters
84 * $24 is the control register of Loongson perf counter
86 static inline void stop_perf_counters(void)
88 __write_64bit_c0_register($24, 0, 0);
92 static void loongson_suspend_enter(void)
94 unsigned int cached_cpu_freq;
96 /* setup wakeup events via enabling the IRQs */
97 setup_wakeup_events();
99 stop_perf_counters();
101 cached_cpu_freq = readl(LOONGSON_CHIPCFG);
103 /* Put CPU into wait mode */
104 writel(readl(LOONGSON_CHIPCFG) & ~0x7, LOONGSON_CHIPCFG);
106 /* wait for the given events to wakeup cpu from wait mode */
107 wait_for_wakeup_events();
109 writel(cached_cpu_freq, LOONGSON_CHIPCFG);
111 mmiowb();
114 void __weak mach_suspend(void)
118 void __weak mach_resume(void)
122 static int loongson_pm_enter(suspend_state_t state)
124 mach_suspend();
126 /* processor specific suspend */
127 loongson_suspend_enter();
129 mach_resume();
131 return 0;
134 static int loongson_pm_valid_state(suspend_state_t state)
136 switch (state) {
137 case PM_SUSPEND_ON:
138 case PM_SUSPEND_STANDBY:
139 case PM_SUSPEND_MEM:
140 return 1;
142 default:
143 return 0;
147 static const struct platform_suspend_ops loongson_pm_ops = {
148 .valid = loongson_pm_valid_state,
149 .enter = loongson_pm_enter,
152 static int __init loongson_pm_init(void)
154 suspend_set_ops(&loongson_pm_ops);
156 return 0;
158 arch_initcall(loongson_pm_init);