All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
@ 2016-05-11 17:47 Moritz Fischer
  2016-05-16  7:55 ` Boris Brezillon
  0 siblings, 1 reply; 5+ messages in thread
From: Moritz Fischer @ 2016-05-11 17:47 UTC (permalink / raw)
  To: dwmw2
  Cc: computersforpeace, linux-mtd, linux-kernel,
	moritz.fischer.private, Moritz Fischer

This allows for getting a struct mtd_info from a node pointer,
allowing mtd devices to e.g. store serial numbers or MAC addresses.

Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
---
 drivers/mtd/mtdcore.c   | 21 +++++++++++++++++++++
 include/linux/mtd/mtd.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 3096251..3d0ae65 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -363,6 +363,27 @@ unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
 EXPORT_SYMBOL_GPL(mtd_mmap_capabilities);
 #endif
 
+static int mtd_of_node_match(struct device *dev, const void *data)
+{
+	return dev->of_node == data;
+}
+
+struct mtd_info *of_mtd_info_get(struct device_node *node)
+{
+	struct mtd_info *mtd;
+	struct device *d;
+	int ret = -ENODEV;
+
+	d = class_find_device(&mtd_class, NULL, node, mtd_of_node_match);
+	if (!d)
+		return ERR_PTR(-ENODEV);
+
+	mtd = container_of(d, struct mtd_info, dev);
+
+	return mtd;
+}
+EXPORT_SYMBOL_GPL(of_mtd_info_get);
+
 static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
 			       void *cmd)
 {
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 7712721..cce6cc7 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -264,6 +264,8 @@ static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
 	return mtd->dev.of_node;
 }
 
+struct mtd_info *of_mtd_info_get(struct device_node *node);
+
 static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
 {
 	return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
  2016-05-11 17:47 [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree Moritz Fischer
@ 2016-05-16  7:55 ` Boris Brezillon
  2016-05-16  8:05   ` Boris Brezillon
  0 siblings, 1 reply; 5+ messages in thread
From: Boris Brezillon @ 2016-05-16  7:55 UTC (permalink / raw)
  To: Moritz Fischer
  Cc: dwmw2, computersforpeace, linux-mtd, linux-kernel,
	moritz.fischer.private

Hi Moritz,

On Wed, 11 May 2016 10:47:39 -0700
Moritz Fischer <moritz.fischer@ettus.com> wrote:

> This allows for getting a struct mtd_info from a node pointer,
> allowing mtd devices to e.g. store serial numbers or MAC addresses.

Can you detail a bit what you'll do next. I guess you need to provide
this information to in-kernel users, and those users will just call
mtd_read() after retrieving the mtd_info pointer.

Here are a few questions (I'm assuming the netdev + MAC address case):
- how would you link the net/PHY device to the MTD partition storing
  the MAC address

> 
> Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
> ---
>  drivers/mtd/mtdcore.c   | 21 +++++++++++++++++++++
>  include/linux/mtd/mtd.h |  2 ++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 3096251..3d0ae65 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -363,6 +363,27 @@ unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
>  EXPORT_SYMBOL_GPL(mtd_mmap_capabilities);
>  #endif
>  
> +static int mtd_of_node_match(struct device *dev, const void *data)
> +{
> +	return dev->of_node == data;
> +}
> +
> +struct mtd_info *of_mtd_info_get(struct device_node *node)
> +{
> +	struct mtd_info *mtd;
> +	struct device *d;
> +	int ret = -ENODEV;
> +
> +	d = class_find_device(&mtd_class, NULL, node, mtd_of_node_match);
> +	if (!d)
> +		return ERR_PTR(-ENODEV);
> +
> +	mtd = container_of(d, struct mtd_info, dev);
> +
> +	return mtd;
> +}
> +EXPORT_SYMBOL_GPL(of_mtd_info_get);
> +
>  static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
>  			       void *cmd)
>  {
> diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
> index 7712721..cce6cc7 100644
> --- a/include/linux/mtd/mtd.h
> +++ b/include/linux/mtd/mtd.h
> @@ -264,6 +264,8 @@ static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd)
>  	return mtd->dev.of_node;
>  }
>  
> +struct mtd_info *of_mtd_info_get(struct device_node *node);
> +
>  static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
>  {
>  	return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
  2016-05-16  7:55 ` Boris Brezillon
@ 2016-05-16  8:05   ` Boris Brezillon
  2016-05-16 16:30     ` Moritz Fischer
  0 siblings, 1 reply; 5+ messages in thread
From: Boris Brezillon @ 2016-05-16  8:05 UTC (permalink / raw)
  To: Moritz Fischer
  Cc: dwmw2, computersforpeace, linux-mtd, linux-kernel,
	moritz.fischer.private

On Mon, 16 May 2016 09:55:34 +0200
Boris Brezillon <boris.brezillon@free-electrons.com> wrote:

> Hi Moritz,
> 
> On Wed, 11 May 2016 10:47:39 -0700
> Moritz Fischer <moritz.fischer@ettus.com> wrote:
> 
> > This allows for getting a struct mtd_info from a node pointer,
> > allowing mtd devices to e.g. store serial numbers or MAC addresses.  
> 
> Can you detail a bit what you'll do next. I guess you need to provide
> this information to in-kernel users, and those users will just call
> mtd_read() after retrieving the mtd_info pointer.
> 
> Here are a few questions (I'm assuming the netdev + MAC address case):
> - how would you link the net/PHY device to the MTD partition storing
>   the MAC address

Sorry, I sent it before asking all my questions :).

- it seems quite specific to MTD devices to me. What if the MAC address
  is stored in something that is not exposed as an MTD device. I wonder
  if we shouldn't add an nvmem wrapper around MTD devices.


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
  2016-05-16  8:05   ` Boris Brezillon
@ 2016-05-16 16:30     ` Moritz Fischer
  2016-05-16 17:14       ` Boris Brezillon
  0 siblings, 1 reply; 5+ messages in thread
From: Moritz Fischer @ 2016-05-16 16:30 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: David Woodhouse, Brian Norris, linux-mtd,
	Linux Kernel Mailing List, moritz.fischer.private

Hi Boris,

On Mon, May 16, 2016 at 1:05 AM, Boris Brezillon
<boris.brezillon@free-electrons.com> wrote:

>> Here are a few questions (I'm assuming the netdev + MAC address case):
>> - how would you link the net/PHY device to the MTD partition storing
>>   the MAC address

Well in my case I actually planned to use it with the OTP partition of my QSPI
device using spi_nor_read_usr_prot_reg and friends and I just needed a way
to get to the struct mtd_info from a child of my network device.

Right now the OTP 'partitions' are not really exposed to device tree afaik.
Maybe that would be worthwhile to further look into? Maybe exposing
(wrapping) that as nvmem
would be the way to go?

> Sorry, I sent it before asking all my questions :).
;-) (as you can see from this email, you're not the only one that
fails at email today, forgot to CC list ...)

> - it seems quite specific to MTD devices to me. What if the MAC address
>   is stored in something that is not exposed as an MTD device. I wonder
>   if we shouldn't add an nvmem wrapper around MTD devices.

That looks certainly worthwhile investigating for the general case.

Cheers,

Moritz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree
  2016-05-16 16:30     ` Moritz Fischer
@ 2016-05-16 17:14       ` Boris Brezillon
  0 siblings, 0 replies; 5+ messages in thread
From: Boris Brezillon @ 2016-05-16 17:14 UTC (permalink / raw)
  To: Moritz Fischer
  Cc: David Woodhouse, Brian Norris, linux-mtd,
	Linux Kernel Mailing List, moritz.fischer.private

On Mon, 16 May 2016 09:30:10 -0700
Moritz Fischer <moritz.fischer@ettus.com> wrote:

> Hi Boris,
> 
> On Mon, May 16, 2016 at 1:05 AM, Boris Brezillon
> <boris.brezillon@free-electrons.com> wrote:
> 
> >> Here are a few questions (I'm assuming the netdev + MAC address case):
> >> - how would you link the net/PHY device to the MTD partition storing
> >>   the MAC address  
> 
> Well in my case I actually planned to use it with the OTP partition of my QSPI
> device using spi_nor_read_usr_prot_reg and friends and I just needed a way
> to get to the struct mtd_info from a child of my network device.
> 
> Right now the OTP 'partitions' are not really exposed to device tree afaik.
> Maybe that would be worthwhile to further look into? Maybe exposing
> (wrapping) that as nvmem
> would be the way to go?

I think so. Now that MTD partitions are defined in a 'partitions'
subnode (see MTD binding doc), we can define an 'otp-partitions'
subnode and define nvmem cells in there.


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-16 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 17:47 [PATCH] mtd: Adding of_mtd_info_get to get mtd_info from devicetree Moritz Fischer
2016-05-16  7:55 ` Boris Brezillon
2016-05-16  8:05   ` Boris Brezillon
2016-05-16 16:30     ` Moritz Fischer
2016-05-16 17:14       ` Boris Brezillon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.