diff mbox

[RFC,4/7] mtd: add of_match_mtd_parser() and of_mtd_match_mtd_parser() helpers

Message ID 1449292763-129421-5-git-send-email-computersforpeace@gmail.com
State Superseded
Delegated to: Brian Norris
Headers show

Commit Message

Brian Norris Dec. 5, 2015, 5:19 a.m. UTC
Like the corresponding OF-based device/driver matching infrascture,
let's begin to support a mtd/partition-parser matching infrastructure.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/of/of_mtd.c            | 33 +++++++++++++++++++++++++++++++++
 include/linux/mtd/partitions.h |  2 ++
 include/linux/of_mtd.h         | 13 +++++++++++++
 3 files changed, 48 insertions(+)

Comments

Rob Herring Dec. 7, 2015, 2:45 a.m. UTC | #1
On Fri, Dec 4, 2015 at 11:19 PM, Brian Norris
<computersforpeace@gmail.com> wrote:
> Like the corresponding OF-based device/driver matching infrascture,

typo.

> let's begin to support a mtd/partition-parser matching infrastructure.
>
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> ---
>  drivers/of/of_mtd.c            | 33 +++++++++++++++++++++++++++++++++

BTW, this file should be moved to drivers/mtd/ at some point.

>  include/linux/mtd/partitions.h |  2 ++
>  include/linux/of_mtd.h         | 13 +++++++++++++
>  3 files changed, 48 insertions(+)
>
> diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
> index b7361ed70537..169d7500af5d 100644
> --- a/drivers/of/of_mtd.c
> +++ b/drivers/of/of_mtd.c
> @@ -9,6 +9,7 @@
>  #include <linux/kernel.h>
>  #include <linux/of_mtd.h>
>  #include <linux/mtd/nand.h>
> +#include <linux/mtd/partitions.h>
>  #include <linux/export.h>
>
>  /**
> @@ -117,3 +118,35 @@ bool of_get_nand_on_flash_bbt(struct device_node *np)
>         return of_property_read_bool(np, "nand-on-flash-bbt");
>  }
>  EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
> +
> +static const struct of_device_id *of_match_mtd_parser(

This function name and the only caller's function name are very
similar. Why not just move this function inline.

> +               struct mtd_part_parser *parser, struct device_node *np)
> +{
> +       if (!parser || !np)
> +               return NULL;
> +
> +       return of_match_node(parser->of_match_table, np);
> +}
> +
> +static struct device_node *mtd_get_partitions_of_node(struct mtd_info *master)
> +{
> +       struct device_node *np = mtd_get_of_node(master);
> +
> +       if (!np)
> +               return NULL;
> +
> +       return of_get_child_by_name(np, "partitions");
> +}
> +
> +bool of_mtd_match_mtd_parser(struct mtd_info *mtd,
> +                            struct mtd_part_parser *parser)
> +{
> +       struct device_node *np = mtd_get_partitions_of_node(mtd);
> +       bool ret;
> +
> +       ret = of_match_mtd_parser(parser, np) != NULL;
> +       of_node_put(np);
> +
> +       return ret;
> +}
Brian Norris Dec. 7, 2015, 6:13 p.m. UTC | #2
On Sun, Dec 06, 2015 at 08:45:40PM -0600, Rob Herring wrote:
> On Fri, Dec 4, 2015 at 11:19 PM, Brian Norris
> <computersforpeace@gmail.com> wrote:
> >  drivers/of/of_mtd.c            | 33 +++++++++++++++++++++++++++++++++
> 
> BTW, this file should be moved to drivers/mtd/ at some point.

How about s/at some point/now/ ? I can send a separate patch. It also
seems like these should just get linked into the 'mtd' module (when
CONFIG_OF=y) instead of having a tiny module for just a few functions.

Why did files like this get placed here anyway? Is there a reason that
there are things like of_net and of_pci here too?

Brian
Rob Herring Dec. 7, 2015, 7 p.m. UTC | #3
On Mon, Dec 7, 2015 at 12:13 PM, Brian Norris
<computersforpeace@gmail.com> wrote:
> On Sun, Dec 06, 2015 at 08:45:40PM -0600, Rob Herring wrote:
>> On Fri, Dec 4, 2015 at 11:19 PM, Brian Norris
>> <computersforpeace@gmail.com> wrote:
>> >  drivers/of/of_mtd.c            | 33 +++++++++++++++++++++++++++++++++
>>
>> BTW, this file should be moved to drivers/mtd/ at some point.
>
> How about s/at some point/now/ ?

Great.

> I can send a separate patch. It also
> seems like these should just get linked into the 'mtd' module (when
> CONFIG_OF=y) instead of having a tiny module for just a few functions.

Agreed.

> Why did files like this get placed here anyway? Is there a reason that
> there are things like of_net and of_pci here too?

Things started out here, but as the number of subsystems and
associated bindings grew it became evident that binding specific
things should go with the subsystems. I also have a secret goal to
eliminate drivers/of. Don't tell anyone.

of_net should probably move, just no one has had the itch to do it.
PCI is a bit special and somewhat tied into the rest of the core.

Rob
diff mbox

Patch

diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
index b7361ed70537..169d7500af5d 100644
--- a/drivers/of/of_mtd.c
+++ b/drivers/of/of_mtd.c
@@ -9,6 +9,7 @@ 
 #include <linux/kernel.h>
 #include <linux/of_mtd.h>
 #include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
 #include <linux/export.h>
 
 /**
@@ -117,3 +118,35 @@  bool of_get_nand_on_flash_bbt(struct device_node *np)
 	return of_property_read_bool(np, "nand-on-flash-bbt");
 }
 EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
+
+static const struct of_device_id *of_match_mtd_parser(
+		struct mtd_part_parser *parser, struct device_node *np)
+{
+	if (!parser || !np)
+		return NULL;
+
+	return of_match_node(parser->of_match_table, np);
+}
+
+static struct device_node *mtd_get_partitions_of_node(struct mtd_info *master)
+{
+	struct device_node *np = mtd_get_of_node(master);
+
+	if (!np)
+		return NULL;
+
+	return of_get_child_by_name(np, "partitions");
+}
+
+bool of_mtd_match_mtd_parser(struct mtd_info *mtd,
+			     struct mtd_part_parser *parser)
+{
+	struct device_node *np = mtd_get_partitions_of_node(mtd);
+	bool ret;
+
+	ret = of_match_mtd_parser(parser, np) != NULL;
+	of_node_put(np);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_mtd_match_mtd_parser);
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 70736e1e6c8f..2e68ef561a40 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -51,6 +51,7 @@  struct mtd_partition {
 
 struct mtd_info;
 struct device_node;
+struct of_device_id;
 
 /**
  * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
@@ -69,6 +70,7 @@  struct mtd_part_parser {
 	struct list_head list;
 	struct module *owner;
 	const char *name;
+	const struct of_device_id *of_match_table;
 	int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
 			struct mtd_part_parser_data *);
 	void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
index e266caa36402..781362d0be0c 100644
--- a/include/linux/of_mtd.h
+++ b/include/linux/of_mtd.h
@@ -9,6 +9,10 @@ 
 #ifndef __LINUX_OF_MTD_H
 #define __LINUX_OF_MTD_H
 
+#include <linux/mtd/mtd.h>
+
+struct mtd_part_parser;
+
 #ifdef CONFIG_OF_MTD
 
 #include <linux/of.h>
@@ -18,6 +22,9 @@  int of_get_nand_ecc_strength(struct device_node *np);
 int of_get_nand_bus_width(struct device_node *np);
 bool of_get_nand_on_flash_bbt(struct device_node *np);
 
+bool of_mtd_match_mtd_parser(struct mtd_info *mtd,
+			     struct mtd_part_parser *parser);
+
 #else /* CONFIG_OF_MTD */
 
 static inline int of_get_nand_ecc_mode(struct device_node *np)
@@ -45,6 +52,12 @@  static inline bool of_get_nand_on_flash_bbt(struct device_node *np)
 	return false;
 }
 
+static inline bool of_mtd_match_mtd_parser(struct mtd_info *mtd,
+					   struct mtd_part_parser *parser)
+{
+	return false;
+}
+
 #endif /* CONFIG_OF_MTD */
 
 #endif /* __LINUX_OF_MTD_H */