From 34934c183b2880340c9ee8f7f36da5a77bffea46 Mon Sep 17 00:00:00 2001 From: Sebastian Hesselbarth Date: Tue, 2 Jul 2013 20:30:47 +0200 Subject: LED: add support for device tree parsing of gpio-leds This adds a driver option to probe GPIO LEDs from device tree compatible with "gpio-leds" device tree nodes. Signed-off-by: Sebastian Hesselbarth Signed-off-by: Sascha Hauer --- drivers/led/Kconfig | 4 ++++ drivers/led/led-gpio.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'drivers') diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index 8ca6ab8e44..3ead82e031 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -7,6 +7,10 @@ config LED_GPIO bool "gpio LED support" depends on GENERIC_GPIO +config LED_GPIO_OF + bool "support parsing gpio LEDs from device tree" + depends on LED_GPIO && OFTREE + config LED_GPIO_RGB bool "gpio rgb LED support" depends on LED_GPIO diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c index 08dc9bad0d..54f9264d44 100644 --- a/drivers/led/led-gpio.c +++ b/drivers/led/led-gpio.c @@ -18,8 +18,10 @@ * */ #include +#include #include #include +#include static void led_gpio_set(struct led *led, unsigned int value) { @@ -194,3 +196,46 @@ void led_gpio_rgb_unregister(struct gpio_led *led) led_unregister(&led->led); } #endif /* CONFIG_LED_GPIO_RGB */ + +#ifdef CONFIG_LED_GPIO_OF + +static int led_gpio_of_probe(struct device_d *dev) +{ + struct device_node *child; + + for_each_child_of_node(dev->device_node, child) { + struct gpio_led *gled; + enum of_gpio_flags flags; + int gpio; + + gpio = of_get_named_gpio_flags(child, "gpios", 0, &flags); + if (gpio < 0) + continue; + + gled = xzalloc(sizeof(*gled)); + gled->led.name = xstrdup(child->name); + gled->gpio = gpio; + gled->active_low = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0; + + dev_dbg(dev, "register led %s on gpio%d, active_low = %d\n", + gled->led.name, gled->gpio, gled->active_low); + + led_gpio_register(gled); + } + + return 0; +} + +static struct of_device_id led_gpio_of_ids[] = { + { .compatible = "gpio-leds", }, + { } +}; + +static struct driver_d led_gpio_of_driver = { + .name = "gpio-leds", + .probe = led_gpio_of_probe, + .of_compatible = DRV_OF_COMPAT(led_gpio_of_ids), +}; +device_platform_driver(led_gpio_of_driver); + +#endif /* CONFIG LED_GPIO_OF */ -- cgit v1.2.3 From 98df44ee7d6db3919a4dd11e227d1e0caedbfe86 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 8 Jul 2013 09:40:17 +0200 Subject: led: gpio: Add trigger support Signed-off-by: Sascha Hauer --- Documentation/devicetree/bindings/leds/common.txt | 8 ++++++ drivers/led/led-gpio.c | 33 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/common.txt (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/leds/common.txt b/Documentation/devicetree/bindings/leds/common.txt new file mode 100644 index 0000000000..db264b332f --- /dev/null +++ b/Documentation/devicetree/bindings/leds/common.txt @@ -0,0 +1,8 @@ +Common leds properties. + +- linux,default-trigger barebox,default-trigger: This parameter, if present, is a + string defining the trigger assigned to the LED. Current triggers are: + "heartbeat" - LED flashes at a constant rate + "panic" - LED turns on when barebox panics + "net" - LED indicates network activity + diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c index 54f9264d44..69db70fab8 100644 --- a/drivers/led/led-gpio.c +++ b/drivers/led/led-gpio.c @@ -199,6 +199,38 @@ void led_gpio_rgb_unregister(struct gpio_led *led) #ifdef CONFIG_LED_GPIO_OF +struct led_trg { + const char *str; + enum led_trigger trg; +}; + +static struct led_trg triggers[] = { + { .str = "heartbeat", LED_TRIGGER_HEARTBEAT, }, + { .str = "panic", LED_TRIGGER_PANIC, }, + { .str = "net", LED_TRIGGER_NET_TXRX, }, +}; + +static void led_of_parse_trigger(struct led *led, struct device_node *np) +{ + const char *trigger; + int i; + + trigger = of_get_property(np, "linux,default-trigger", NULL); + if (!trigger) + trigger = of_get_property(np, "barebox,default-trigger", NULL); + + if (!trigger) + return; + + for (i = 0; i < ARRAY_SIZE(triggers); i++) { + struct led_trg *trg = &triggers[i]; + if (!strcmp(trg->str, trigger)) { + led_set_trigger(trg->trg, led); + return; + } + } +} + static int led_gpio_of_probe(struct device_d *dev) { struct device_node *child; @@ -220,6 +252,7 @@ static int led_gpio_of_probe(struct device_d *dev) dev_dbg(dev, "register led %s on gpio%d, active_low = %d\n", gled->led.name, gled->gpio, gled->active_low); + led_of_parse_trigger(&gled->led, child); led_gpio_register(gled); } -- cgit v1.2.3 From abf95154f5d139f2e54559955e80e1752989cc88 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 24 May 2013 23:31:29 +0200 Subject: of: partitions: factor out function to parse a single partition To make it usable for other code. Signed-off-by: Sascha Hauer --- drivers/of/partition.c | 58 ++++++++++++++++++++++++++++---------------------- include/of.h | 1 + 2 files changed, 34 insertions(+), 25 deletions(-) (limited to 'drivers') diff --git a/drivers/of/partition.c b/drivers/of/partition.c index e4b7d1e66b..d69251e666 100644 --- a/drivers/of/partition.c +++ b/drivers/of/partition.c @@ -23,44 +23,52 @@ #include #include -int of_parse_partitions(struct cdev *cdev, struct device_node *node) +struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node) { - struct device_node *n; const char *partname; char *filename; + struct cdev *new; + const __be32 *reg; + unsigned long offset, size; + const char *name; + int len; + unsigned long flags = 0; - for_each_child_of_node(node, n) { - const __be32 *reg; - unsigned long offset, size; - const char *name; - int len; - unsigned long flags = 0; + reg = of_get_property(node, "reg", &len); + if (!reg) + return NULL; + + offset = be32_to_cpu(reg[0]); + size = be32_to_cpu(reg[1]); + + partname = of_get_property(node, "label", &len); + if (!partname) + partname = of_get_property(node, "name", &len); + name = (char *)partname; - reg = of_get_property(n, "reg", &len); - if (!reg) - continue; + debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size); - offset = be32_to_cpu(reg[0]); - size = be32_to_cpu(reg[1]); + if (of_get_property(node, "read-only", &len)) + flags = DEVFS_PARTITION_READONLY; - partname = of_get_property(n, "label", &len); - if (!partname) - partname = of_get_property(n, "name", &len); - name = (char *)partname; + filename = asprintf("%s.%s", cdev->name, partname); - debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size); + new = devfs_add_partition(cdev->name, offset, size, flags, filename); - if (of_get_property(n, "read-only", &len)) - flags = DEVFS_PARTITION_READONLY; + if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH) + dev_add_bb_dev(filename, NULL); - filename = asprintf("%s.%s", cdev->name, partname); + free(filename); - devfs_add_partition(cdev->name, offset, size, flags, filename); + return new; +} - if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH) - dev_add_bb_dev(filename, NULL); +int of_parse_partitions(struct cdev *cdev, struct device_node *node) +{ + struct device_node *n; - free(filename); + for_each_child_of_node(node, n) { + of_parse_partition(cdev, n); } return 0; diff --git a/include/of.h b/include/of.h index 0d8f6b3c67..710383c30f 100644 --- a/include/of.h +++ b/include/of.h @@ -221,6 +221,7 @@ extern int of_platform_populate(struct device_node *root, struct device_d *parent); extern struct device_d *of_find_device_by_node(struct device_node *np); +struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node); int of_parse_partitions(struct cdev *cdev, struct device_node *node); int of_device_is_stdout_path(struct device_d *dev); const char *of_get_model(void); -- cgit v1.2.3 From b2968cc8af06bfa851cf40fd5e4c845634a0caa4 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 10 Jul 2013 08:50:59 +0200 Subject: mci: set partnames of eMMC boot partitions Signed-off-by: Sascha Hauer --- drivers/mci/mci-core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 67668d53f0..02e6216caf 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -406,7 +406,7 @@ static int mci_calc_blk_cnt(uint64_t cap, unsigned shift) } static void mci_part_add(struct mci *mci, uint64_t size, - unsigned int part_cfg, char *name, int idx, bool ro, + unsigned int part_cfg, char *name, char *partname, int idx, bool ro, int area_type) { struct mci_part *part = &mci->part[mci->nr_parts]; @@ -414,6 +414,7 @@ static void mci_part_add(struct mci *mci, uint64_t size, part->mci = mci; part->size = size; part->blk.cdev.name = name; + part->blk.cdev.partname = partname; part->blk.blockbits = SECTOR_SHIFT; part->blk.num_blocks = mci_calc_blk_cnt(size, part->blk.blockbits); part->area_type = area_type; @@ -482,13 +483,14 @@ static int mmc_change_freq(struct mci *mci) unsigned int part_size; for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { - char *name; + char *name, *partname; part_size = mci->ext_csd[EXT_CSD_BOOT_MULT] << 17; - name = asprintf("%s.boot%d", mci->cdevname, idx); + partname = asprintf("boot%d", idx); + name = asprintf("%s.%s", mci->cdevname, partname); mci_part_add(mci, part_size, EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, - name, idx, true, + name, partname, idx, true, MMC_BLK_DATA_AREA_BOOT); } @@ -1104,7 +1106,7 @@ static int mci_startup(struct mci *mci) err = mci_set_blocklen(mci, mci->read_bl_len); mci_part_add(mci, mci->capacity, 0, - mci->cdevname, 0, true, + mci->cdevname, NULL, 0, true, MMC_BLK_DATA_AREA_MAIN); return err; -- cgit v1.2.3 From c7b4d3669c64ab13e0b35ef0329b8354713c05c5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 11 Jul 2013 18:57:29 +0200 Subject: bus: Add imx-weim support Mostly taken from the kernel with support for other SoCs from Alexander Shiyan. Signed-off-by: Sascha Hauer Cc: Alexander Shiyan --- drivers/Kconfig | 1 + drivers/Makefile | 1 + drivers/bus/Kconfig | 7 ++ drivers/bus/Makefile | 1 + drivers/bus/imx-weim.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+) create mode 100644 drivers/bus/Kconfig create mode 100644 drivers/bus/Makefile create mode 100644 drivers/bus/imx-weim.c (limited to 'drivers') diff --git a/drivers/Kconfig b/drivers/Kconfig index 3a95e5140d..d34d2c7443 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -24,5 +24,6 @@ source "drivers/dma/Kconfig" source "drivers/gpio/Kconfig" source "drivers/w1/Kconfig" source "drivers/pinctrl/Kconfig" +source "drivers/bus/Kconfig" endmenu diff --git a/drivers/Makefile b/drivers/Makefile index daf821c83c..ba1dc6df76 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -23,3 +23,4 @@ obj-y += gpio/ obj-$(CONFIG_OFTREE) += of/ obj-$(CONFIG_W1) += w1/ obj-y += pinctrl/ +obj-y += bus/ diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig new file mode 100644 index 0000000000..5938d3f2dc --- /dev/null +++ b/drivers/bus/Kconfig @@ -0,0 +1,7 @@ +menu "Bus devices" + +config IMX_WEIM + depends on ARCH_IMX + bool "i.MX WEIM driver" + +endmenu diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile new file mode 100644 index 0000000000..42a8d49479 --- /dev/null +++ b/drivers/bus/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_IMX_WEIM) += imx-weim.o diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c new file mode 100644 index 0000000000..78bccda15a --- /dev/null +++ b/drivers/bus/imx-weim.c @@ -0,0 +1,171 @@ +/* + * EIM driver for Freescale's i.MX chips + * + * Copyright (C) 2013 Freescale Semiconductor, Inc. + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#include +#include +#include +#include +#include + +struct imx_weim_devtype { + unsigned int cs_count; + unsigned int cs_regs_count; + unsigned int cs_stride; +}; + +static const struct imx_weim_devtype imx1_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 2, + .cs_stride = 0x08, +}; + +static const struct imx_weim_devtype imx27_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 3, + .cs_stride = 0x10, +}; + +static const struct imx_weim_devtype imx50_weim_devtype = { + .cs_count = 4, + .cs_regs_count = 6, + .cs_stride = 0x18, +}; + +static const struct imx_weim_devtype imx51_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 6, + .cs_stride = 0x18, +}; + +static struct of_device_id weim_id_table[] = { + { + /* i.MX1/21 */ + .compatible = "fsl,imx1-weim", + .data = (unsigned long)&imx1_weim_devtype, + }, { + /* i.MX25/27/31/35 */ + .compatible = "fsl,imx27-weim", + .data = (unsigned long)&imx27_weim_devtype, + }, { + /* i.MX50/53/6Q */ + .compatible = "fsl,imx50-weim", + .data = (unsigned long)&imx50_weim_devtype, + }, { + /* i.MX51 */ + .compatible = "fsl,imx51-weim", + .data = (unsigned long)&imx51_weim_devtype, + }, { + .compatible = "fsl,imx6q-weim", + .data = (unsigned long)&imx50_weim_devtype, + }, { + } +}; + +struct imx_weim { + struct device_d *dev; + void __iomem *base; + struct imx_weim_devtype *devtype; +}; + +/* Parse and set the timing for this device. */ +static int +weim_timing_setup(struct imx_weim *weim, struct device_node *np) +{ + struct imx_weim_devtype *devtype = weim->devtype; + u32 cs_idx, value[devtype->cs_regs_count]; + int i, ret; + + /* get the CS index from this child node's "reg" property. */ + ret = of_property_read_u32(np, "reg", &cs_idx); + if (ret) + return ret; + + if (cs_idx >= devtype->cs_count) + return -EINVAL; + + ret = of_property_read_u32_array(np, "fsl,weim-cs-timing", + value, devtype->cs_regs_count); + if (ret) + return ret; + + dev_dbg(weim->dev, "setting up cs for %s\n", np->name); + + /* set the timing for WEIM */ + for (i = 0; i < devtype->cs_regs_count; i++) + writel(value[i], weim->base + cs_idx * devtype->cs_stride + i * 4); + + return 0; +} + +static int weim_parse_dt(struct imx_weim *weim) +{ + struct device_node *child; + int ret; + + for_each_child_of_node(weim->dev->device_node, child) { + if (!child->name) + continue; + + ret = weim_timing_setup(weim, child); + if (ret) { + dev_err(weim->dev, "%s set timing failed.\n", + child->full_name); + return ret; + } + } + + ret = of_platform_populate(weim->dev->device_node, NULL, weim->dev); + if (ret) + dev_err(weim->dev, "%s fail to create devices.\n", + weim->dev->device_node->full_name); + return ret; +} + +static int weim_probe(struct device_d *dev) +{ + struct imx_weim_devtype *devtype; + struct imx_weim *weim; + int ret; + + ret = dev_get_drvdata(dev, (unsigned long *)&devtype); + if (ret) + return ret; + + weim = xzalloc(sizeof(*weim)); + + weim->dev = dev; + weim->devtype = devtype; + + /* get the resource */ + weim->base = dev_request_mem_region(dev, 0); + if (!weim->base) { + ret = -EBUSY; + goto weim_err; + } + + /* parse the device node */ + ret = weim_parse_dt(weim); + if (ret) { + goto weim_err; + } + + dev_info(dev, "WEIM driver registered.\n"); + + return 0; + +weim_err: + return ret; +} + +static struct driver_d weim_driver = { + .name = "imx-weim", + .of_compatible = DRV_OF_COMPAT(weim_id_table), + .probe = weim_probe, +}; +device_platform_driver(weim_driver); -- cgit v1.2.3 From 9cb5f51d0aeca9b2f18019d05b7b09884809037d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 16 Jul 2013 14:36:26 +0200 Subject: of: partition: check for valid node So that users can call the of partition parsers without checking if they are probed from the devicetree. Signed-off-by: Sascha Hauer --- drivers/of/partition.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers') diff --git a/drivers/of/partition.c b/drivers/of/partition.c index d69251e666..7199eff875 100644 --- a/drivers/of/partition.c +++ b/drivers/of/partition.c @@ -34,6 +34,9 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node) int len; unsigned long flags = 0; + if (!node) + return NULL; + reg = of_get_property(node, "reg", &len); if (!reg) return NULL; @@ -67,6 +70,9 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node) { struct device_node *n; + if (!node) + return -EINVAL; + for_each_child_of_node(node, n) { of_parse_partition(cdev, n); } -- cgit v1.2.3 From 3ae902ed7f06e9392624dad1ed23fd4f0dc9c38b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 16 Jul 2013 15:36:40 +0200 Subject: of: Add convenience functions to en/disable devicenodes These functions allow to manipulate the "status" property of devicenodes effectively enabling/disabling devices. Signed-off-by: Sascha Hauer --- drivers/of/base.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/of.h | 5 +++++ 2 files changed, 70 insertions(+) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index e9f1f79324..0b1a8a2fa8 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1739,3 +1739,68 @@ int of_add_initrd(struct device_node *root, resource_size_t start, return 0; } + +/** + * of_device_enable - enable a devicenode device + * @node - the node to enable + * + * This deletes the status property of a devicenode effectively + * enabling the device. + */ +int of_device_enable(struct device_node *node) +{ + struct property *pp; + + pp = of_find_property(node, "status", NULL); + if (!pp) + return 0; + + of_delete_property(pp); + + return 0; +} + +/** + * of_device_enable_path - enable a devicenode + * @path - the nodepath to enable + * + * wrapper around of_device_enable taking the nodepath as argument + */ +int of_device_enable_path(const char *path) +{ + struct device_node *node; + + node = of_find_node_by_path(path); + if (!node) + return -ENODEV; + + return of_device_enable(node); +} + +/** + * of_device_enable - disable a devicenode device + * @node - the node to disable + * + * This sets the status of a devicenode to "disabled" + */ +int of_device_disable(struct device_node *node) +{ + return of_set_property(node, "status", "disabled", sizeof("disabled"), 1); +} + +/** + * of_device_disable_path - disable a devicenode + * @path - the nodepath to disable + * + * wrapper around of_device_disable taking the nodepath as argument + */ +int of_device_disable_path(const char *path) +{ + struct device_node *node; + + node = of_find_node_by_path(path); + if (!node) + return -ENODEV; + + return of_device_disable(node); +} diff --git a/include/of.h b/include/of.h index 710383c30f..7b600f038b 100644 --- a/include/of.h +++ b/include/of.h @@ -682,4 +682,9 @@ static inline int of_property_write_u64(struct device_node *np, extern const struct of_device_id of_default_bus_match_table[]; +int of_device_enable(struct device_node *node); +int of_device_enable_path(const char *path); +int of_device_disable(struct device_node *node); +int of_device_disable_path(const char *path); + #endif /* __OF_H */ -- cgit v1.2.3 From 309504327491b2f72c7b870d881f15c62fd95ed5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 16 Jul 2013 13:00:29 +0200 Subject: mtd: Add devicetree partition parsing Signed-off-by: Sascha Hauer --- drivers/mtd/core.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index 37f4428dc3..f46ab4692d 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -365,6 +365,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname) } devfs_create(&mtd->cdev); + of_parse_partitions(&mtd->cdev, mtd->parent->device_node); list_for_each_entry(hook, &mtd_register_hooks, hook) if (hook->add_mtd_device) -- cgit v1.2.3 From da6c4b21a856139b709e466823e4e6ccaf5e195b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 16 Jul 2013 14:38:05 +0200 Subject: mci: Add devicetree partition parsing MMC/SD cards normally have a DOS/GPT partition table, but sometimes barebox uses the unpartitioned area to store its environment. Add devicetree partition parsing also for SD/MMC cards so that we have a way to describe the partition in the devicetree. Signed-off-by: Sascha Hauer --- drivers/mci/mci-core.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 02e6216caf..66ddb5b4ff 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -1558,6 +1558,7 @@ static int mci_card_probe(struct mci *mci) dev_warn(&mci->dev, "No partition table found\n"); rc = 0; /* it's not a failure */ } + of_parse_partitions(&part->blk.cdev, host->hw_dev->device_node); } if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) && -- cgit v1.2.3 From 874f318037b6941ad7261e398a03d177f3383eb1 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 10 Jul 2013 08:54:44 +0200 Subject: 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 --- Documentation/devicetree/bindings/barebox.txt | 10 ++ .../bindings/barebox/barebox,environment.txt | 25 ++++ drivers/of/Kconfig | 9 ++ drivers/of/Makefile | 1 + drivers/of/barebox.c | 99 +++++++++++++ drivers/of/of_path.c | 155 +++++++++++++++++++++ include/of.h | 2 + 7 files changed, 301 insertions(+) create mode 100644 Documentation/devicetree/bindings/barebox.txt create mode 100644 Documentation/devicetree/bindings/barebox/barebox,environment.txt create mode 100644 drivers/of/barebox.c create mode 100644 drivers/of/of_path.c (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/barebox.txt b/Documentation/devicetree/bindings/barebox.txt new file mode 100644 index 0000000000..5e8d461733 --- /dev/null +++ b/Documentation/devicetree/bindings/barebox.txt @@ -0,0 +1,10 @@ +barebox specific devicetree bindings +==================================== + +barebox uses some barebox specific devicetree bindings. All of these +are under the /chosen/ hierarchy in the devicetree. + +The bindings have the form of a device with regular 'compatible' properties. +drivers matching these devices do not handle physical devices but instead +influence / configure certain behaviours of barebox like the place where to +find the persistent environment. diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.txt b/Documentation/devicetree/bindings/barebox/barebox,environment.txt new file mode 100644 index 0000000000..5a8bf9c13b --- /dev/null +++ b/Documentation/devicetree/bindings/barebox/barebox,environment.txt @@ -0,0 +1,25 @@ +barebox environment +=================== + +This driver provides an environment for barebox from the devicetree. + +Required properties: +- compatible: should be "barebox,environment" +- device-path: path to the environment + +The device-path is a multistring property. The first string should be a +nodepath to the node containing the physical device of the environment. +The subsequent strings are of the form : to further describe +the path to the environment. Supported values for : + +partname: This describes a partition on a device. can + be the label for mtd partitions, the number for DOS + partitions (beginning with 0) or the name for GPT + partitions + +Example: + +environment@0 { + compatible = "barebox,environment"; + device-path = &flash, "partname:barebox-environment"; +}; diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 03ae599279..ab5eac8442 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -18,3 +18,12 @@ config OFDEVICE config OF_NET depends on NET def_bool y + +config OF_BAREBOX_DRIVERS + depends on OFDEVICE + bool "Enable barebox specific devicetree configuration drivers" + help + barebox supports being configured from devicetree. This enables + support for this feature. This currently allows to configure the + environment path from devicetree and to partition devices. See + Documentation/devicetree/bindings/barebox/ for more information. diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e7d07334b0..97fea9d419 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o obj-$(CONFIG_GPIOLIB) += of_gpio.o obj-y += partition.o obj-y += of_net.o +obj-$(CONFIG_OF_BAREBOX_DRIVERS) += barebox.o of_path.o 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 , 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 +#include +#include +#include +#include +#include +#include + +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); diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c new file mode 100644 index 0000000000..ab8618e23d --- /dev/null +++ b/drivers/of/of_path.c @@ -0,0 +1,155 @@ +/* + * of_path.c + * + * Copyright (c) 2013 Sascha Hauer , 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 +#include +#include + +struct of_path { + struct cdev *cdev; + struct device_d *dev; +}; + +struct of_path_type { + const char *name; + int (*parse)(struct of_path *op, const char *str); +}; + +/** + * of_path_type_partname - find a partition based on physical device and + * partition name + * @op: of_path context + * @name: the partition name to find + */ +static int of_path_type_partname(struct of_path *op, const char *name) +{ + if (!op->dev) + return -EINVAL; + + op->cdev = device_find_partition(op->dev, name); + if (op->cdev) { + pr_debug("%s: found part '%s'\n", __func__, name); + return 0; + } else { + pr_debug("%s: cannot find part '%s'\n", __func__, name); + return -ENODEV; + } +} + +static struct of_path_type of_path_types[] = { + { + .name = "partname", + .parse = of_path_type_partname, + }, +}; + +static int of_path_parse_one(struct of_path *op, const char *str) +{ + int i, ret; + char *name, *desc; + + pr_debug("parsing: %s\n", str); + + name = xstrdup(str); + desc = strchr(name, ':'); + if (!desc) { + free(name); + return -EINVAL; + } + + *desc = 0; + desc++; + + for (i = 0; i < ARRAY_SIZE(of_path_types); i++) { + if (!strcmp(of_path_types[i].name, name)) { + ret = of_path_types[i].parse(op, desc); + goto out; + } + } + + ret = -EINVAL; +out: + free(name); + + return ret; +} + +/** + * of_find_path - translate a path description in the devicetree to a barebox + * path + * + * @node: the node containing the property with the path description + * @propname: the property name of the path description + * @outpath: if this function returns 0 outpath will contain the path belonging + * to the input path description. Must be freed with free(). + * + * pathes in the devicetree have the form of a multistring property. The first + * string contains the full path to the physical device containing the path. + * The remaining strings have the form ":". Currently supported + * for are: + * + * partname: - find a partition by its partition name. For mtd + * partitions this is the label. For DOS partitions + * this is the number beginning with 0. + * + * examples: + * + * device-path = &mmc0, "partname:0"; + * device-path = &norflash, "partname:barebox-environment"; + */ +int of_find_path(struct device_node *node, const char *propname, char **outpath) +{ + struct of_path op = {}; + struct device_node *rnode; + const char *path, *str; + int i, len, ret; + + path = of_get_property(node, propname, &len); + if (!path) + return -EINVAL; + + rnode = of_find_node_by_path(path); + if (!rnode) + return -ENODEV; + + op.dev = of_find_device_by_node_path(rnode->full_name); + if (!op.dev) + return -ENODEV; + + device_detect(op.dev); + + i = 1; + + while (1) { + ret = of_property_read_string_index(node, propname, i++, &str); + if (ret) + break; + + ret = of_path_parse_one(&op, str); + if (ret) + return ret; + } + + if (!op.cdev) + return -ENOENT; + + *outpath = asprintf("/dev/%s", op.cdev->name); + + return 0; +} diff --git a/include/of.h b/include/of.h index 7b600f038b..b99f0b2dae 100644 --- a/include/of.h +++ b/include/of.h @@ -229,6 +229,8 @@ void *of_flatten_dtb(struct device_node *node); int of_add_memory(struct device_node *node, bool dump); void of_add_memory_bank(struct device_node *node, bool dump, int r, u64 base, u64 size); +struct device_d *of_find_device_by_node_path(const char *path); +int of_find_path(struct device_node *node, const char *propname, char **outpath); #else static inline int of_parse_partitions(struct cdev *cdev, struct device_node *node) -- cgit v1.2.3