diff mbox

Documentation: dt: mtd: replace "nor-jedec" binding with "jedec,spi-nor"

Message ID 20150515195541.GL11598@ld-irv-0074
State Accepted
Headers show

Commit Message

Brian Norris May 15, 2015, 7:55 p.m. UTC
It really helps if I test patches...

On Thu, May 14, 2015 at 10:32:53AM -0700, Brian Norris wrote:
> In commit 8ff16cf77ce3 ("Documentation: devicetree: m25p80: add "nor-jedec"
> binding"), we added a generic "nor-jedec" binding to catch all
> mostly-compatible SPI NOR flash which can be detected via the READ ID
> opcode (0x9F). This was discussed and reviewed at the time, however
> objections have come up since then as part of this discussion:
> 
>   http://lkml.kernel.org/g/20150511224646.GJ32500@ld-irv-0074
> 
> It seems the parties involved agree that "jedec,spi-nor" does a better
> job of capturing the fact that this is SPI-specific, not just any NOR
> flash.
> 
> This binding was only merged for v4.1-rc1, so it's still OK to change
> the naming.
> 
> At the same time, let's move the documentation to a better name.
> 
> Next up: prune the m25p_ids[] table to the minimal necessary listing, so
> we can stop referring to code (drivers/mtd/devices/m25p80.c) from the
> documentation.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> Cc: Stephen Warren <swarren@wwwdotorg.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Rafał Miłecki <zajec5@gmail.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Pawel Moll <pawel.moll@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Ian Campbell <ijc+devicetree@hellion.org.uk>
> Cc: Kumar Gala <galak@codeaurora.org>
> Cc: devicetree@vger.kernel.org
> ---
> I'd *really* like to get an 'ack' from a DT maintainer for this, those those
> are apparently very hard to come by. And I'd really not like to have to revisit
> this again in a few weeks. We have patches getting queued up for 4.2 that are
> using the "nor-jedec" binding, and I'd like to nip those in the bud ASAP.
> 
>  .../devicetree/bindings/mtd/{m25p80.txt => jedec,spi-nor.txt}       | 6 +++---
>  drivers/mtd/devices/m25p80.c                                        | 6 +++---
>  2 files changed, 6 insertions(+), 6 deletions(-)
>  rename Documentation/devicetree/bindings/mtd/{m25p80.txt => jedec,spi-nor.txt} (85%)
> 
...
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 7c8b1694a134..3d59ebc16b6e 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -223,7 +223,7 @@ static int m25p_probe(struct spi_device *spi)
>  	 */
>  	if (data && data->type)
>  		flash_name = data->type;
> -	else if (!strcmp(spi->modalias, "nor-jedec"))
> +	else if (!strcmp(spi->modalias, "jedec,spi-nor"))
>  		flash_name = NULL; /* auto-detect */
>  	else
>  		flash_name = spi->modalias;
> @@ -255,7 +255,7 @@ static int m25p_remove(struct spi_device *spi)
>   * since most of these flash are compatible to some extent, and their
>   * differences can often be differentiated by the JEDEC read-ID command, we
>   * encourage new users to add support to the spi-nor library, and simply bind
> - * against a generic string here (e.g., "nor-jedec").
> + * against a generic string here (e.g., "jedec,spi-nor").
>   *
>   * Many flash names are kept here in this list (as well as in spi-nor.c) to
>   * keep them available as module aliases for existing platforms.
> @@ -305,7 +305,7 @@ static const struct spi_device_id m25p_ids[] = {
>  	 * Generic support for SPI NOR that can be identified by the JEDEC READ
>  	 * ID opcode (0x9F). Use this, if possible.
>  	 */
> -	{"nor-jedec"},
> +	{"jedec,spi-nor"},

So I forgot (again; we hit this before) that the SPI/OF framework strips
everything before the first comma before binding devices. See
of_modalias_node(). So I'll have to squash in the patch below to get a
usable binding.

>  	{ },
>  };
>  MODULE_DEVICE_TABLE(spi, m25p_ids);

This patch will make the code bind against anything like
"<foo>,spi-nor", but we'll leave the comment to recommend
using "jedec,spi-nor".

Signed-off-by: Brian Norris <computersforpeace@gmail.com>

Comments

Mark Rutland May 18, 2015, 10:45 a.m. UTC | #1
On Fri, May 15, 2015 at 08:55:41PM +0100, Brian Norris wrote:
> It really helps if I test patches...
> 
> On Thu, May 14, 2015 at 10:32:53AM -0700, Brian Norris wrote:
> > In commit 8ff16cf77ce3 ("Documentation: devicetree: m25p80: add "nor-jedec"
> > binding"), we added a generic "nor-jedec" binding to catch all
> > mostly-compatible SPI NOR flash which can be detected via the READ ID
> > opcode (0x9F). This was discussed and reviewed at the time, however
> > objections have come up since then as part of this discussion:
> > 
> >   http://lkml.kernel.org/g/20150511224646.GJ32500@ld-irv-0074
> > 
> > It seems the parties involved agree that "jedec,spi-nor" does a better
> > job of capturing the fact that this is SPI-specific, not just any NOR
> > flash.
> > 
> > This binding was only merged for v4.1-rc1, so it's still OK to change
> > the naming.
> > 
> > At the same time, let's move the documentation to a better name.
> > 
> > Next up: prune the m25p_ids[] table to the minimal necessary listing, so
> > we can stop referring to code (drivers/mtd/devices/m25p80.c) from the
> > documentation.
> > 
> > Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> > Cc: Stephen Warren <swarren@wwwdotorg.org>
> > Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> > Cc: Marek Vasut <marex@denx.de>
> > Cc: Rafał Miłecki <zajec5@gmail.com>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Pawel Moll <pawel.moll@arm.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Ian Campbell <ijc+devicetree@hellion.org.uk>
> > Cc: Kumar Gala <galak@codeaurora.org>
> > Cc: devicetree@vger.kernel.org
> > ---
> > I'd *really* like to get an 'ack' from a DT maintainer for this, those those
> > are apparently very hard to come by. And I'd really not like to have to revisit
> > this again in a few weeks. We have patches getting queued up for 4.2 that are
> > using the "nor-jedec" binding, and I'd like to nip those in the bud ASAP.
> > 
> >  .../devicetree/bindings/mtd/{m25p80.txt => jedec,spi-nor.txt}       | 6 +++---
> >  drivers/mtd/devices/m25p80.c                                        | 6 +++---
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> >  rename Documentation/devicetree/bindings/mtd/{m25p80.txt => jedec,spi-nor.txt} (85%)
> > 
> ...
> > diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> > index 7c8b1694a134..3d59ebc16b6e 100644
> > --- a/drivers/mtd/devices/m25p80.c
> > +++ b/drivers/mtd/devices/m25p80.c
> > @@ -223,7 +223,7 @@ static int m25p_probe(struct spi_device *spi)
> >  	 */
> >  	if (data && data->type)
> >  		flash_name = data->type;
> > -	else if (!strcmp(spi->modalias, "nor-jedec"))
> > +	else if (!strcmp(spi->modalias, "jedec,spi-nor"))
> >  		flash_name = NULL; /* auto-detect */
> >  	else
> >  		flash_name = spi->modalias;
> > @@ -255,7 +255,7 @@ static int m25p_remove(struct spi_device *spi)
> >   * since most of these flash are compatible to some extent, and their
> >   * differences can often be differentiated by the JEDEC read-ID command, we
> >   * encourage new users to add support to the spi-nor library, and simply bind
> > - * against a generic string here (e.g., "nor-jedec").
> > + * against a generic string here (e.g., "jedec,spi-nor").
> >   *
> >   * Many flash names are kept here in this list (as well as in spi-nor.c) to
> >   * keep them available as module aliases for existing platforms.
> > @@ -305,7 +305,7 @@ static const struct spi_device_id m25p_ids[] = {
> >  	 * Generic support for SPI NOR that can be identified by the JEDEC READ
> >  	 * ID opcode (0x9F). Use this, if possible.
> >  	 */
> > -	{"nor-jedec"},
> > +	{"jedec,spi-nor"},
> 
> So I forgot (again; we hit this before) that the SPI/OF framework strips
> everything before the first comma before binding devices. See
> of_modalias_node(). So I'll have to squash in the patch below to get a
> usable binding.

Is it not possible to use the of_match_table on spi_driver::driver? If
not, we really should make it so.

Mark.
Brian Norris May 18, 2015, 6:34 p.m. UTC | #2
+ linux-spi

On Mon, May 18, 2015 at 11:45:01AM +0100, Mark Rutland wrote:
> On Fri, May 15, 2015 at 08:55:41PM +0100, Brian Norris wrote:
> > It really helps if I test patches...
> > 
> > On Thu, May 14, 2015 at 10:32:53AM -0700, Brian Norris wrote:
[...]
> > > @@ -305,7 +305,7 @@ static const struct spi_device_id m25p_ids[] = {
> > >  	 * Generic support for SPI NOR that can be identified by the JEDEC READ
> > >  	 * ID opcode (0x9F). Use this, if possible.
> > >  	 */
> > > -	{"nor-jedec"},
> > > +	{"jedec,spi-nor"},
> > 
> > So I forgot (again; we hit this before) that the SPI/OF framework strips
> > everything before the first comma before binding devices. See
> > of_modalias_node(). So I'll have to squash in the patch below to get a
> > usable binding.
> 
> Is it not possible to use the of_match_table on spi_driver::driver? If
> not, we really should make it so.

Hmm, it does look like spi.c supports multiple matching mechanisms, so I
guess m25p80.c could match some with of_match_table and some with
modalias/spi_driver.id_table. See:

static int spi_match_device(struct device *dev, struct device_driver *drv)
{
	const struct spi_device *spi = to_spi_device(dev);
	const struct spi_driver *sdrv = to_spi_driver(drv);

	/* Attempt an OF style match */
	if (of_driver_match_device(dev, drv))
		return 1;
	// ^^^^ we aren't yet (but could be) using this

	/* Then try ACPI */
	if (acpi_driver_match_device(dev, drv))
		return 1;

	if (sdrv->id_table)
		return !!spi_match_id(sdrv->id_table, spi);
	// ^^^^ we're currently only using this

	return strcmp(spi->modalias, drv->name) == 0;
}

I'll see about patching this for 4.2. We have a working solution for
4.1 at least.

Brian
Geert Uytterhoeven May 18, 2015, 6:51 p.m. UTC | #3
Hi Brian,

On Mon, May 18, 2015 at 8:34 PM, Brian Norris
<computersforpeace@gmail.com> wrote:
> On Mon, May 18, 2015 at 11:45:01AM +0100, Mark Rutland wrote:
>> On Fri, May 15, 2015 at 08:55:41PM +0100, Brian Norris wrote:
>> > It really helps if I test patches...
>> >
>> > On Thu, May 14, 2015 at 10:32:53AM -0700, Brian Norris wrote:
> [...]
>> > > @@ -305,7 +305,7 @@ static const struct spi_device_id m25p_ids[] = {
>> > >    * Generic support for SPI NOR that can be identified by the JEDEC READ
>> > >    * ID opcode (0x9F). Use this, if possible.
>> > >    */
>> > > - {"nor-jedec"},
>> > > + {"jedec,spi-nor"},
>> >
>> > So I forgot (again; we hit this before) that the SPI/OF framework strips
>> > everything before the first comma before binding devices. See
>> > of_modalias_node(). So I'll have to squash in the patch below to get a
>> > usable binding.
>>
>> Is it not possible to use the of_match_table on spi_driver::driver? If
>> not, we really should make it so.
>
> Hmm, it does look like spi.c supports multiple matching mechanisms, so I
> guess m25p80.c could match some with of_match_table and some with
> modalias/spi_driver.id_table. See:
>
> static int spi_match_device(struct device *dev, struct device_driver *drv)
> {
>         const struct spi_device *spi = to_spi_device(dev);
>         const struct spi_driver *sdrv = to_spi_driver(drv);
>
>         /* Attempt an OF style match */
>         if (of_driver_match_device(dev, drv))
>                 return 1;
>         // ^^^^ we aren't yet (but could be) using this
>
>         /* Then try ACPI */
>         if (acpi_driver_match_device(dev, drv))
>                 return 1;
>
>         if (sdrv->id_table)
>                 return !!spi_match_id(sdrv->id_table, spi);
>         // ^^^^ we're currently only using this
>
>         return strcmp(spi->modalias, drv->name) == 0;
> }
>
> I'll see about patching this for 4.2. We have a working solution for
> 4.1 at least.

When using DT:
  - spi_driver.id_table is used to match with vendor-stripped DT "compatible"
    entries.
  - spi_driver.driver.of_match_table is used to match with full DT "compatible"
    entries.

Note that stripping of vendor names from DT "compatible" entries is done
for the _first_ "compatible" entry in the device node only!
Hence

        compatible = "myvendor,m25p80";

will match against "m25p80" in m25p_ids[], while

        compatible = "myvendor,shinynewdevice", "st,m25p80";

will _not_ match against "m25p80" in m25p_ids[], and fail to probe in
the absence of a driver entry for the first (real) "compatible" entry.

I2c behaves similarly.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox

Patch

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 3d59ebc16b6e..3af137f49ac9 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -223,7 +223,7 @@  static int m25p_probe(struct spi_device *spi)
 	 */
 	if (data && data->type)
 		flash_name = data->type;
-	else if (!strcmp(spi->modalias, "jedec,spi-nor"))
+	else if (!strcmp(spi->modalias, "spi-nor"))
 		flash_name = NULL; /* auto-detect */
 	else
 		flash_name = spi->modalias;
@@ -305,7 +305,7 @@  static const struct spi_device_id m25p_ids[] = {
 	 * Generic support for SPI NOR that can be identified by the JEDEC READ
 	 * ID opcode (0x9F). Use this, if possible.
 	 */
-	{"jedec,spi-nor"},
+	{"spi-nor"},
 	{ },
 };
 MODULE_DEVICE_TABLE(spi, m25p_ids);