aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch
diff options
context:
space:
mode:
authorBernhard Frauendienst <openwrt@nospam.obeliks.de>2018-08-25 12:48:54 +0200
committerJohn Crispin <john@phrozen.org>2018-09-10 09:35:07 +0200
commit3370e104954191eeab97df7cd07146d7c48e180d (patch)
tree9842041d2c8d95e78d2b40a7803518ba3440d26f /target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch
parent7768f115349da48f44478f0c5b79f89ffa54c3f4 (diff)
downloadupstream-3370e104954191eeab97df7cd07146d7c48e180d.tar.gz
upstream-3370e104954191eeab97df7cd07146d7c48e180d.tar.bz2
upstream-3370e104954191eeab97df7cd07146d7c48e180d.zip
kernel: add driver for virtual mtd_concat devices
Some systems require multiple flash chips to be concatenated and read as a single mtd device. The ar71xx target provides custom code to create such mtdconcat devices. When porting devices to ath79, however, there is no way to create such devices from within the device tree. This commit adds a driver for creating virtual mtd-concat devices to the ath79 target. Nodes must have a compatible = "virtual,mtd-concat" line, and define a list of devices to concat in the 'devices' property, for example: flash { compatible = "virtual,mtd-concat"; devices = <&flash0 &flash1>; }; The driver is added to the very end of the mtd Makefile to increase the likelyhood of all child devices already being loaded at the time of probing, preventing unnecessary deferred probes which might in turn cause other problems (like failure to load MAC addresses from art because the partitions are not loaded yet). Signed-off-by: Bernhard Frauendienst <openwrt@nospam.obeliks.de>
Diffstat (limited to 'target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch')
-rw-r--r--target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch82
1 files changed, 82 insertions, 0 deletions
diff --git a/target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch b/target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch
new file mode 100644
index 0000000000..32a87d34d5
--- /dev/null
+++ b/target/linux/generic/pending-4.14/495-mtd-core-add-get_mtd_device_by_node.patch
@@ -0,0 +1,82 @@
+From 1bd1b740f208d1cf4071932cc51860d37266c402 Mon Sep 17 00:00:00 2001
+From: Bernhard Frauendienst <kernel@nospam.obeliks.de>
+Date: Sat, 1 Sep 2018 00:30:11 +0200
+Subject: [PATCH 495/497] mtd: core: add get_mtd_device_by_node
+
+Add function to retrieve a mtd device by its OF node. Since drivers can
+assign arbitrary names to mtd devices in the absence of a label
+property, there is no other reliable way to retrieve a mtd device for a
+given OF node.
+
+Signed-off-by: Bernhard Frauendienst <kernel@nospam.obeliks.de>
+Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
+---
+ drivers/mtd/mtdcore.c | 38 ++++++++++++++++++++++++++++++++++++++
+ include/linux/mtd/mtd.h | 2 ++
+ 2 files changed, 40 insertions(+)
+
+diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
+index e7ea842ba3db..1134bb81d2e5 100644
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -936,6 +936,44 @@ struct mtd_info *get_mtd_device_nm(const char *name)
+ }
+ EXPORT_SYMBOL_GPL(get_mtd_device_nm);
+
++/**
++ * get_mtd_device_by_node - obtain a validated handle for an MTD device
++ * by of_node
++ * @of_node: OF node of MTD device to open
++ *
++ * This function returns MTD device description structure in case of
++ * success and an error code in case of failure.
++ */
++struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node)
++{
++ int err = -ENODEV;
++ struct mtd_info *mtd = NULL, *other;
++
++ mutex_lock(&mtd_table_mutex);
++
++ mtd_for_each_device(other) {
++ if (of_node == other->dev.of_node) {
++ mtd = other;
++ break;
++ }
++ }
++
++ if (!mtd)
++ goto out_unlock;
++
++ err = __get_mtd_device(mtd);
++ if (err)
++ goto out_unlock;
++
++ mutex_unlock(&mtd_table_mutex);
++ return mtd;
++
++out_unlock:
++ mutex_unlock(&mtd_table_mutex);
++ return ERR_PTR(err);
++}
++EXPORT_SYMBOL_GPL(get_mtd_device_by_node);
++
+ void put_mtd_device(struct mtd_info *mtd)
+ {
+ mutex_lock(&mtd_table_mutex);
+diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
+index 6cd0f6b7658b..cf7c8030cd8e 100644
+--- a/include/linux/mtd/mtd.h
++++ b/include/linux/mtd/mtd.h
+@@ -557,6 +557,8 @@ extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
+ extern int __get_mtd_device(struct mtd_info *mtd);
+ extern void __put_mtd_device(struct mtd_info *mtd);
+ extern struct mtd_info *get_mtd_device_nm(const char *name);
++extern struct mtd_info *get_mtd_device_by_node(
++ const struct device_node *of_node);
+ extern void put_mtd_device(struct mtd_info *mtd);
+
+
+--
+2.18.0
+