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.

Dependency Surface

Detected Declarations

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

Implementation Notes