[U-Boot] [PATCH 04/13] drivers: spi: spi-uclass: fix spi slave device register

Simon Glass sjg at chromium.org
Thu Oct 29 18:17:54 CET 2015


Hi Muganthan,

On 27 October 2015 at 05:12, Mugunthan V N <mugunthanvnm at ti.com> wrote:
> when a device registered with device_bind_driver(), its fdt node
> is not added to the device. Due to this, in spi_child_post_bind()
> dev->of_offset is -1 and spi device fdt is never parsed. So
> changing the device register by device_bind_driver_to_node() so
> that the spi slave device is registered with of_offset and its
> fdt is parsed properly.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm at ti.com>
> ---
>  drivers/spi/spi-uclass.c | 38 ++++++++++++++++++++++++++++++++------
>  1 file changed, 32 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index 9a32b6c..cfd14b1 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -138,6 +138,7 @@ static int spi_child_pre_probe(struct udevice *dev)
>         slave->max_hz = plat->max_hz;
>         slave->mode = plat->mode;
>
> +
>         return 0;
>  }
>
> @@ -258,17 +259,42 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
>          * SPI flash chip - we will bind to the correct driver.
>          */
>         if (ret == -ENODEV && drv_name) {
> -               struct dm_spi_slave_platdata *plat;
> +               const void *fdt = gd->fdt_blob;
> +               int node = bus->of_offset;
> +               int subnode = -1;
> +               int slave_cs = -1;
>
>                 debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n",
>                       __func__, dev_name, busnum, cs, drv_name);
> -               ret = device_bind_driver(bus, drv_name, dev_name, &dev);
> +

Please see the comment above:

/*
* If there is no such device, create one automatically. This means
* that we don't need a device tree node or platform data for the
* SPI flash chip - we will bind to the correct driver.
*/

This code is used when there is no device attached. It should not
happen that you have a device tree node which is ignored when the SPI
bus is bound. spi_post_bind() should pick up these node and create
drivers for them.

> +               fdt_for_each_subnode(fdt, subnode, node) {
> +                       slave_cs = fdtdec_get_int(fdt, subnode, "reg", -1);
> +                       if(cs == slave_cs)
> +                               break;
> +               }
> +
> +               if(cs != slave_cs) {
> +                       printf("%s: device not found in device tree blob\n",
> +                              __func__);
> +                       subnode = -1;
> +               }
> +
> +               ret = device_bind_driver_to_node(bus, drv_name, dev_name,
> +                                                subnode, &dev);
>                 if (ret)
>                         return ret;
> -               plat = dev_get_parent_platdata(dev);
> -               plat->cs = cs;
> -               plat->max_hz = speed;
> -               plat->mode = mode;
> +               /*
> +                * If a Device tree spi slave is found, then use settings
> +                * from Device tree.
> +                */
> +               if (subnode < 0) {
> +                       struct dm_spi_slave_platdata *plat;
> +
> +                       plat = dev_get_parent_platdata(dev);
> +                       plat->cs = cs;
> +                       plat->max_hz = speed;
> +                       plat->mode = mode;
> +               }
>                 created = true;
>         } else if (ret) {
>                 printf("Invalid chip select %d:%d (err=%d)\n", busnum, cs,
> --
> 2.6.2.280.g74301d6
>

Regards,
Simon


More information about the U-Boot mailing list