diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-10 08:54:44 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-18 13:54:38 +0200 |
commit | 874f318037b6941ad7261e398a03d177f3383eb1 (patch) | |
tree | 5901171cade532a2056103102a34d83ee3cc5114 /drivers/of/barebox.c | |
parent | da6c4b21a856139b709e466823e4e6ccaf5e195b (diff) | |
download | barebox-874f318037b6941ad7261e398a03d177f3383eb1.tar.gz barebox-874f318037b6941ad7261e398a03d177f3383eb1.tar.xz |
Add configurability via devicetree
This adds the possibility to configure the place for the environment
from the devicetree and to partition devices from the devicetree.
Configuration has the general form of devices with a regular compatible
property. This allows to later add additional drivers or drivers with
different behaviour (for example to add support for redundant environment).
The configuration is all in the /chosen/barebox/ hierarchy of the
devicetree. This separates the configuration from the hardware
description. Also it makes it possible to store the configuration
in a completely separate devicetree (or devicetree overlay). For
the same reason all configuration is done using nodepathes rather
than phandles.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of/barebox.c')
-rw-r--r-- | drivers/of/barebox.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c new file mode 100644 index 0000000000..8977158992 --- /dev/null +++ b/drivers/of/barebox.c @@ -0,0 +1,99 @@ +/* + * barebox.c + * + * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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 <init.h> +#include <io.h> +#include <of.h> +#include <malloc.h> +#include <partition.h> +#include <envfs.h> + +struct of_partition { + struct list_head list; + char *nodepath; + struct device_d *dev; + struct device_node *of_partitions; +}; + +static LIST_HEAD(of_partition_list); + +struct device_d *of_find_device_by_node_path(const char *path) +{ + struct device_d *dev; + + for_each_device(dev) { + if (!dev->device_node) + continue; + if (!strcmp(path, dev->device_node->full_name)) + return dev; + } + + return NULL; +} + +static int environment_probe(struct device_d *dev) +{ + char *path; + int ret; + + ret = of_find_path(dev->device_node, "device-path", &path); + if (ret) + return ret; + + dev_info(dev, "setting default environment path to %s\n", path); + + default_environment_path = path; + + return 0; +} + +static struct of_device_id environment_dt_ids[] = { + { + .compatible = "barebox,environment", + }, { + /* sentinel */ + } +}; + +static struct driver_d environment_driver = { + .name = "barebox-environment", + .probe = environment_probe, + .of_compatible = environment_dt_ids, +}; + +static int barebox_of_driver_init(void) +{ + struct device_node *node; + + node = of_get_root_node(); + if (!node) + return 0; + + node = of_find_node_by_path("/chosen"); + if (!node) + return 0; + + of_platform_populate(node, of_default_bus_match_table, NULL); + + platform_driver_register(&environment_driver); + + return 0; +} +late_initcall(barebox_of_driver_init); |