diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-04-13 12:57:14 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-04-13 12:57:14 +0200 |
commit | ee0035e5ccee0056e23b2dda2cade0c5ca756713 (patch) | |
tree | 9e02a89c11c7574bace93f2c3731c4175e0ea649 /drivers | |
parent | a76a6bc8fd62bc26140d421d09e71624ee13aa47 (diff) | |
parent | 1487e6b9ad2ec0fafb0a2a35c921a33fb6c37fec (diff) | |
download | barebox-ee0035e5ccee0056e23b2dda2cade0c5ca756713.tar.gz barebox-ee0035e5ccee0056e23b2dda2cade0c5ca756713.tar.xz |
Merge branch 'for-next/state'
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/misc/Kconfig | 4 | ||||
-rw-r--r-- | drivers/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/misc/state.c | 81 |
3 files changed, 86 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index c34a4af512..7a5b14697e 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -15,4 +15,8 @@ config SRAM help This driver adds support for memory mapped SRAM. +config STATE_DRV + tristate "state driver" + depends on STATE + endmenu diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 908c8cb708..487e4b8ba2 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_JTAG) += jtag.o obj-$(CONFIG_SRAM) += sram.o +obj-$(CONFIG_STATE_DRV) += state.o diff --git a/drivers/misc/state.c b/drivers/misc/state.c new file mode 100644 index 0000000000..f066a836cb --- /dev/null +++ b/drivers/misc/state.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2013 Sascha Hauer <s.hauer@pengutronix.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#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; + const char *alias; + const char *backend_type = NULL; + int ret; + char *path; + + if (!np) + return -EINVAL; + + alias = of_alias_get(np); + if (!alias) + alias = "state"; + + state = state_new_from_node(alias, np); + if (IS_ERR(state)) + return PTR_ERR(state); + + ret = of_find_path(np, "backend", &path); + if (ret) + return ret; + + dev_info(dev, "outpath: %s\n", path); + + ret = of_property_read_string(np, "backend-type", &backend_type); + if (ret) + return ret; + else if (!strcmp(backend_type, "raw")) + ret = state_backend_raw_file(state, path, 0, 0); + else if (!strcmp(backend_type, "dtb")) + ret = state_backend_dtb_file(state, path); + else + dev_warn(dev, "invalid backend type: %s\n", backend_type); + + if (ret) + return ret; + + state_load(state); + + 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); |