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