drivers/power/reset/gpio-restart.c
Source file repositories/reference/linux-study-clean/drivers/power/reset/gpio-restart.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/reset/gpio-restart.c- Extension
.c- Size
- 3065 bytes
- Lines
- 123
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/reboot.hlinux/kernel.hlinux/init.hlinux/delay.hlinux/platform_device.hlinux/gpio/consumer.hlinux/module.hlinux/of.h
Detected Declarations
struct gpio_restartfunction gpio_restart_notifyfunction gpio_restart_probe
Annotated Snippet
struct gpio_restart {
struct gpio_desc *reset_gpio;
u32 active_delay_ms;
u32 inactive_delay_ms;
u32 wait_delay_ms;
};
static int gpio_restart_notify(struct sys_off_data *data)
{
struct gpio_restart *gpio_restart = data->cb_data;
/* drive it active, also inactive->active edge */
gpiod_direction_output(gpio_restart->reset_gpio, 1);
mdelay(gpio_restart->active_delay_ms);
/* drive inactive, also active->inactive edge */
gpiod_set_value(gpio_restart->reset_gpio, 0);
mdelay(gpio_restart->inactive_delay_ms);
/* drive it active, also inactive->active edge */
gpiod_set_value(gpio_restart->reset_gpio, 1);
/* give it some time */
mdelay(gpio_restart->wait_delay_ms);
WARN_ON(1);
return NOTIFY_DONE;
}
static int gpio_restart_probe(struct platform_device *pdev)
{
struct gpio_restart *gpio_restart;
bool open_source = false;
int priority = 129;
u32 property;
int ret;
gpio_restart = devm_kzalloc(&pdev->dev, sizeof(*gpio_restart),
GFP_KERNEL);
if (!gpio_restart)
return -ENOMEM;
open_source = of_property_read_bool(pdev->dev.of_node, "open-source");
gpio_restart->reset_gpio = devm_gpiod_get(&pdev->dev, NULL,
open_source ? GPIOD_IN : GPIOD_OUT_LOW);
ret = PTR_ERR_OR_ZERO(gpio_restart->reset_gpio);
if (ret) {
if (ret != -EPROBE_DEFER)
dev_err(&pdev->dev, "Could not get reset GPIO\n");
return ret;
}
gpio_restart->active_delay_ms = 100;
gpio_restart->inactive_delay_ms = 100;
gpio_restart->wait_delay_ms = 3000;
ret = of_property_read_u32(pdev->dev.of_node, "priority", &property);
if (!ret) {
if (property > 255)
dev_err(&pdev->dev, "Invalid priority property: %u\n",
property);
else
priority = property;
}
of_property_read_u32(pdev->dev.of_node, "active-delay",
&gpio_restart->active_delay_ms);
of_property_read_u32(pdev->dev.of_node, "inactive-delay",
&gpio_restart->inactive_delay_ms);
of_property_read_u32(pdev->dev.of_node, "wait-delay",
&gpio_restart->wait_delay_ms);
ret = devm_register_sys_off_handler(&pdev->dev,
SYS_OFF_MODE_RESTART,
priority,
gpio_restart_notify,
gpio_restart);
if (ret) {
dev_err(&pdev->dev, "%s: cannot register restart handler, %d\n",
__func__, ret);
return -ENODEV;
}
return 0;
}
static const struct of_device_id of_gpio_restart_match[] = {
{ .compatible = "gpio-restart", },
Annotation
- Immediate include surface: `linux/reboot.h`, `linux/kernel.h`, `linux/init.h`, `linux/delay.h`, `linux/platform_device.h`, `linux/gpio/consumer.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct gpio_restart`, `function gpio_restart_notify`, `function gpio_restart_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.