drivers/power/reset/sc27xx-poweroff.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/sc27xx-poweroff.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/sc27xx-poweroff.c- Extension
.c- Size
- 2290 bytes
- Lines
- 92
- Domain
- Driver Families
- Bucket
- drivers/power
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/pm.hlinux/regmap.hlinux/syscore_ops.h
Detected Declarations
function sc27xx_poweroff_shutdownfunction for_each_online_cpufunction sc27xx_poweroff_do_powerofffunction sc27xx_poweroff_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2018 Spreadtrum Communications Inc.
* Copyright (C) 2018 Linaro Ltd.
*/
#include <linux/cpu.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/syscore_ops.h>
#define SC27XX_PWR_PD_HW 0xc2c
#define SC27XX_PWR_OFF_EN BIT(0)
#define SC27XX_SLP_CTRL 0xdf0
#define SC27XX_LDO_XTL_EN BIT(3)
static struct regmap *regmap;
/*
* On Spreadtrum platform, we need power off system through external SC27xx
* series PMICs, and it is one similar SPI bus mapped by regmap to access PMIC,
* which is not fast io access.
*
* So before stopping other cores, we need release other cores' resource by
* taking cpus down to avoid racing regmap or spi mutex lock when poweroff
* system through PMIC.
*/
static void sc27xx_poweroff_shutdown(void *data)
{
#ifdef CONFIG_HOTPLUG_CPU
int cpu;
for_each_online_cpu(cpu) {
if (cpu != smp_processor_id())
remove_cpu(cpu);
}
#endif
}
static const struct syscore_ops poweroff_syscore_ops = {
.shutdown = sc27xx_poweroff_shutdown,
};
static struct syscore poweroff_syscore = {
.ops = &poweroff_syscore_ops,
};
static void sc27xx_poweroff_do_poweroff(void)
{
/* Disable the external subsys connection's power firstly */
regmap_write(regmap, SC27XX_SLP_CTRL, SC27XX_LDO_XTL_EN);
regmap_write(regmap, SC27XX_PWR_PD_HW, SC27XX_PWR_OFF_EN);
}
static int sc27xx_poweroff_probe(struct platform_device *pdev)
{
if (regmap)
return -EINVAL;
regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!regmap)
return -ENODEV;
pm_power_off = sc27xx_poweroff_do_poweroff;
register_syscore(&poweroff_syscore);
return 0;
}
static const struct platform_device_id sc27xx_poweroff_id_table[] = {
{ "sc2731-poweroff" },
{ }
};
MODULE_DEVICE_TABLE(platform, sc27xx_poweroff_id_table);
static struct platform_driver sc27xx_poweroff_driver = {
.probe = sc27xx_poweroff_probe,
.driver = {
.name = "sc27xx-poweroff",
},
.id_table = sc27xx_poweroff_id_table,
};
module_platform_driver(sc27xx_poweroff_driver);
MODULE_DESCRIPTION("Power off driver for SC27XX PMIC Device");
MODULE_AUTHOR("Baolin Wang <baolin.wang@unisoc.com>");
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/pm.h`, `linux/regmap.h`, `linux/syscore_ops.h`.
- Detected declarations: `function sc27xx_poweroff_shutdown`, `function for_each_online_cpu`, `function sc27xx_poweroff_do_poweroff`, `function sc27xx_poweroff_probe`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
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.