summaryrefslogtreecommitdiffstats
path: root/drivers/misc/state.c
blob: 5da8e4ef915a26ea0b6abfebb2db86e4ef176af7 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2013 Sascha Hauer <s.hauer@pengutronix.de>
 */

#include <common.h>
#include <driver.h>
#include <init.h>
#include <malloc.h>
#include <of.h>
#include <state.h>

#include <linux/err.h>

static int state_probe(struct device_d *dev)
{
	struct device_node *np = dev->device_node;
	struct state *state;
	bool readonly = false;
	int ret;

	state = state_new_from_node(np, readonly);
	if (IS_ERR(state)) {
		int ret = PTR_ERR(state);
		if (ret == -ENODEV)
			ret = -EPROBE_DEFER;
		return ret;
	}

	ret = state_load(state);
	if (ret)
		dev_warn(dev, "Failed to load persistent state, continuing with defaults, %d\n",
			 ret);

	return 0;
}

static __maybe_unused struct of_device_id state_ids[] = {
	{
		.compatible = "barebox,state",
	}, {
		/* sentinel */
	}
};

static struct driver_d state_driver = {
	.name = "state",
	.probe = state_probe,
	.of_compatible = DRV_OF_COMPAT(state_ids),
};
device_platform_driver(state_driver);