blob: da41ca41d9a1c2dc1530d58efbc959acb06aee8a [file] [log] [blame]
Sean Anderson46b2e5e2022-12-02 11:03:53 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <nvmem.h>
9#include <reboot-mode/reboot-mode.h>
10
11/**
12 * struct nvmem_reboot_mode_priv - Private data for the nvmem reboot mode device
13 * @cell: The nvmem cell to store the mode in
14 */
15struct nvmem_reboot_mode_priv {
16 struct nvmem_cell cell;
17};
18
19static int reboot_mode_get(struct udevice *dev, u32 *mode)
20{
21 struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
22
23 return nvmem_cell_read(&priv->cell, mode, sizeof(*mode));
24}
25
26static int reboot_mode_set(struct udevice *dev, u32 mode)
27{
28 struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
29
30 return nvmem_cell_write(&priv->cell, &mode, sizeof(mode));
31}
32
33static const struct reboot_mode_ops nvmem_reboot_mode_ops = {
34 .get = reboot_mode_get,
35 .set = reboot_mode_set,
36};
37
38static int reboot_mode_probe(struct udevice *dev)
39{
40 struct nvmem_reboot_mode_priv *priv = dev_get_priv(dev);
41
42 return nvmem_cell_get_by_name(dev, "reboot-mode", &priv->cell);
43}
44
45static const struct udevice_id nvmem_reboot_mode_ids[] = {
46 { .compatible = "nvmem-reboot-mode" },
47 { }
48};
49
50U_BOOT_DRIVER(nvmem_reboot_mode) = {
51 .name = "nvmem-reboot-mode",
52 .id = UCLASS_REBOOT_MODE,
53 .of_match = nvmem_reboot_mode_ids,
54 .probe = reboot_mode_probe,
55 .priv_auto = sizeof(struct nvmem_reboot_mode_priv),
56 .ops = &nvmem_reboot_mode_ops,
57};