Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * loongson-specific suspend support
0004  *
0005  *  Copyright (C) 2009 Lemote Inc.
0006  *  Author: Wu Zhangjin <wuzhangjin@gmail.com>
0007  */
0008 #include <linux/suspend.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/pm.h>
0011 
0012 #include <asm/i8259.h>
0013 #include <asm/mipsregs.h>
0014 
0015 #include <loongson.h>
0016 
0017 static unsigned int __maybe_unused cached_master_mask;  /* i8259A */
0018 static unsigned int __maybe_unused cached_slave_mask;
0019 static unsigned int __maybe_unused cached_bonito_irq_mask; /* bonito */
0020 
0021 void arch_suspend_disable_irqs(void)
0022 {
0023     /* disable all mips events */
0024     local_irq_disable();
0025 
0026 #ifdef CONFIG_I8259
0027     /* disable all events of i8259A */
0028     cached_slave_mask = inb(PIC_SLAVE_IMR);
0029     cached_master_mask = inb(PIC_MASTER_IMR);
0030 
0031     outb(0xff, PIC_SLAVE_IMR);
0032     inb(PIC_SLAVE_IMR);
0033     outb(0xff, PIC_MASTER_IMR);
0034     inb(PIC_MASTER_IMR);
0035 #endif
0036     /* disable all events of bonito */
0037     cached_bonito_irq_mask = LOONGSON_INTEN;
0038     LOONGSON_INTENCLR = 0xffff;
0039     (void)LOONGSON_INTENCLR;
0040 }
0041 
0042 void arch_suspend_enable_irqs(void)
0043 {
0044     /* enable all mips events */
0045     local_irq_enable();
0046 #ifdef CONFIG_I8259
0047     /* only enable the cached events of i8259A */
0048     outb(cached_slave_mask, PIC_SLAVE_IMR);
0049     outb(cached_master_mask, PIC_MASTER_IMR);
0050 #endif
0051     /* enable all cached events of bonito */
0052     LOONGSON_INTENSET = cached_bonito_irq_mask;
0053     (void)LOONGSON_INTENSET;
0054 }
0055 
0056 /*
0057  * Setup the board-specific events for waking up loongson from wait mode
0058  */
0059 void __weak setup_wakeup_events(void)
0060 {
0061 }
0062 
0063 void __weak mach_suspend(void)
0064 {
0065 }
0066 
0067 void __weak mach_resume(void)
0068 {
0069 }
0070 
0071 static int loongson_pm_enter(suspend_state_t state)
0072 {
0073     mach_suspend();
0074 
0075     mach_resume();
0076 
0077     return 0;
0078 }
0079 
0080 static int loongson_pm_valid_state(suspend_state_t state)
0081 {
0082     switch (state) {
0083     case PM_SUSPEND_ON:
0084     case PM_SUSPEND_STANDBY:
0085     case PM_SUSPEND_MEM:
0086         return 1;
0087 
0088     default:
0089         return 0;
0090     }
0091 }
0092 
0093 static const struct platform_suspend_ops loongson_pm_ops = {
0094     .valid  = loongson_pm_valid_state,
0095     .enter  = loongson_pm_enter,
0096 };
0097 
0098 static int __init loongson_pm_init(void)
0099 {
0100     suspend_set_ops(&loongson_pm_ops);
0101 
0102     return 0;
0103 }
0104 arch_initcall(loongson_pm_init);