drivers/soc/loongson/loongson2_pm.c
Source file repositories/reference/linux-study-clean/drivers/soc/loongson/loongson2_pm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/soc/loongson/loongson2_pm.c- Extension
.c- Size
- 5564 bytes
- Lines
- 221
- Domain
- Driver Families
- Bucket
- drivers/soc
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/io.hlinux/of.hlinux/init.hlinux/input.hlinux/suspend.hlinux/interrupt.hlinux/of_platform.hlinux/pm_wakeirq.hlinux/platform_device.hasm/bootinfo.hasm/suspend.h
Detected Declarations
function loongson2_pm_status_clearfunction loongson2_pm_irq_enablefunction loongson2_suspend_enterfunction loongson2_suspend_beginfunction loongson2_suspend_valid_statefunction loongson2_power_button_initfunction loongson2_pm_irq_handlerfunction loongson2_pm_suspendfunction loongson2_pm_resumefunction loongson2_pm_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Loongson-2 PM Support
*
* Copyright (C) 2023 Loongson Technology Corporation Limited
*/
#include <linux/io.h>
#include <linux/of.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/suspend.h>
#include <linux/interrupt.h>
#include <linux/of_platform.h>
#include <linux/pm_wakeirq.h>
#include <linux/platform_device.h>
#include <asm/bootinfo.h>
#include <asm/suspend.h>
#define LOONGSON2_PM1_CNT_REG 0x14
#define LOONGSON2_PM1_STS_REG 0x0c
#define LOONGSON2_PM1_ENA_REG 0x10
#define LOONGSON2_GPE0_STS_REG 0x28
#define LOONGSON2_GPE0_ENA_REG 0x2c
#define LOONGSON2_PM1_PWRBTN_STS BIT(8)
#define LOONGSON2_PM1_PCIEXP_WAKE_STS BIT(14)
#define LOONGSON2_PM1_WAKE_STS BIT(15)
#define LOONGSON2_PM1_CNT_INT_EN BIT(0)
#define LOONGSON2_PM1_PWRBTN_EN LOONGSON2_PM1_PWRBTN_STS
static struct loongson2_pm {
void __iomem *base;
struct input_dev *dev;
bool suspended;
} loongson2_pm;
#define loongson2_pm_readw(reg) readw(loongson2_pm.base + reg)
#define loongson2_pm_readl(reg) readl(loongson2_pm.base + reg)
#define loongson2_pm_writew(val, reg) writew(val, loongson2_pm.base + reg)
#define loongson2_pm_writel(val, reg) writel(val, loongson2_pm.base + reg)
static void loongson2_pm_status_clear(void)
{
u16 value;
value = loongson2_pm_readw(LOONGSON2_PM1_STS_REG);
value |= (LOONGSON2_PM1_PWRBTN_STS | LOONGSON2_PM1_PCIEXP_WAKE_STS |
LOONGSON2_PM1_WAKE_STS);
loongson2_pm_writew(value, LOONGSON2_PM1_STS_REG);
loongson2_pm_writel(loongson2_pm_readl(LOONGSON2_GPE0_STS_REG), LOONGSON2_GPE0_STS_REG);
}
static void loongson2_pm_irq_enable(void)
{
u16 value;
value = loongson2_pm_readw(LOONGSON2_PM1_CNT_REG);
value |= LOONGSON2_PM1_CNT_INT_EN;
loongson2_pm_writew(value, LOONGSON2_PM1_CNT_REG);
value = loongson2_pm_readw(LOONGSON2_PM1_ENA_REG);
value |= LOONGSON2_PM1_PWRBTN_EN;
loongson2_pm_writew(value, LOONGSON2_PM1_ENA_REG);
}
static int loongson2_suspend_enter(suspend_state_t state)
{
loongson2_pm_status_clear();
loongarch_common_suspend();
loongarch_suspend_enter();
loongarch_common_resume();
loongson2_pm_irq_enable();
pm_set_resume_via_firmware();
return 0;
}
static int loongson2_suspend_begin(suspend_state_t state)
{
pm_set_suspend_via_firmware();
return 0;
}
static int loongson2_suspend_valid_state(suspend_state_t state)
{
return (state == PM_SUSPEND_MEM);
}
Annotation
- Immediate include surface: `linux/io.h`, `linux/of.h`, `linux/init.h`, `linux/input.h`, `linux/suspend.h`, `linux/interrupt.h`, `linux/of_platform.h`, `linux/pm_wakeirq.h`.
- Detected declarations: `function loongson2_pm_status_clear`, `function loongson2_pm_irq_enable`, `function loongson2_suspend_enter`, `function loongson2_suspend_begin`, `function loongson2_suspend_valid_state`, `function loongson2_power_button_init`, `function loongson2_pm_irq_handler`, `function loongson2_pm_suspend`, `function loongson2_pm_resume`, `function loongson2_pm_probe`.
- Atlas domain: Driver Families / drivers/soc.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.