summaryrefslogtreecommitdiff
path: root/drivers/reboot-mode/reboot-mode-nvmem.c
blob: da41ca41d9a1c2dc1530d58efbc959acb06aee8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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,
};