reboot-mode: Add NVMEM reboot mode

This adds an NVMEM reboot mode driver, similar to Linux's
implementation. This allows using the same device tree binding for Linux
and U-Boot in most cases.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Sean Anderson 2022-12-02 11:03:53 -05:00 committed by Tom Rini
parent 546795b579
commit 46b2e5e92c
4 changed files with 66 additions and 0 deletions

View File

@ -1198,6 +1198,7 @@ M: Sean Anderson <seanga2@gmail.com>
S: Maintained S: Maintained
F: doc/api/nvmem.rst F: doc/api/nvmem.rst
F: drivers/misc/nvmem.c F: drivers/misc/nvmem.c
F: drivers/reboot-mode/reboot-mode-nvmem.c
F: include/nvmem.h F: include/nvmem.h
NXP C45 TJA11XX PHY DRIVER NXP C45 TJA11XX PHY DRIVER

View File

@ -30,4 +30,11 @@ config DM_REBOOT_MODE_RTC
a device in a specific mode by using a register(s) that can be controlled a device in a specific mode by using a register(s) that can be controlled
outside U-Boot (e.g. Kernel). outside U-Boot (e.g. Kernel).
config REBOOT_MODE_NVMEM
bool "Use NVMEM reboot mode"
depends on DM_REBOOT_MODE && NVMEM
help
Use any kind of non-volatile memory (EEPROM, RTC, etc) to control the
reboot mode.
endmenu endmenu

View File

@ -7,3 +7,4 @@
obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o
obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o
obj-$(CONFIG_DM_REBOOT_MODE_RTC) += reboot-mode-rtc.o obj-$(CONFIG_DM_REBOOT_MODE_RTC) += reboot-mode-rtc.o
obj-$(CONFIG_REBOOT_MODE_NVMEM) += reboot-mode-nvmem.o

View File

@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
*/
#include <common.h>
#include <dm.h>
#include <nvmem.h>
#include <reboot-mode/reboot-mode.h>
/**
* struct nvmem_reboot_mode_priv - Private data for the nvmem reboot mode device
* @cell: The nvmem cell to store the mode in
*/
struct nvmem_reboot_mode_priv {
struct nvmem_cell cell;
};
static int reboot_mode_get(struct udevice *dev, u32 *mode)
{
struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
return nvmem_cell_read(&priv->cell, mode, sizeof(*mode));
}
static int reboot_mode_set(struct udevice *dev, u32 mode)
{
struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
return nvmem_cell_write(&priv->cell, &mode, sizeof(mode));
}
static const struct reboot_mode_ops nvmem_reboot_mode_ops = {
.get = reboot_mode_get,
.set = reboot_mode_set,
};
static int reboot_mode_probe(struct udevice *dev)
{
struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
return nvmem_cell_get_by_name(dev, "reboot-mode", &priv->cell);
}
static const struct udevice_id nvmem_reboot_mode_ids[] = {
{ .compatible = "nvmem-reboot-mode" },
{ }
};
U_BOOT_DRIVER(nvmem_reboot_mode) = {
.name = "nvmem-reboot-mode",
.id = UCLASS_REBOOT_MODE,
.of_match = nvmem_reboot_mode_ids,
.probe = reboot_mode_probe,
.priv_auto = sizeof(struct nvmem_reboot_mode_priv),
.ops = &nvmem_reboot_mode_ops,
};