[PATCH 4/5] spi: omap3_spi: Read platform data in ofdata_to_platdata()

Vignesh Raghavendra vigneshr at ti.com
Mon Sep 7 14:12:44 CEST 2020



On 9/2/20 4:48 PM, Faiz Abbas wrote:
> Add an ofdata_to_platdata() callback to access dts in U-boot and
> access all platform data in it. This prepares the driver for supporting
> both device tree as well as static platform data structures in SPL.
> 
> Signed-off-by: Faiz Abbas <faiz_abbas at ti.com>
> ---
>  drivers/spi/omap3_spi.c | 37 ++++++++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
> index fbf9575851..08daacf6f0 100644
> --- a/drivers/spi/omap3_spi.c
> +++ b/drivers/spi/omap3_spi.c
> @@ -482,17 +482,10 @@ static int omap3_spi_set_wordlen(struct udevice *dev, unsigned int wordlen)
>  static int omap3_spi_probe(struct udevice *dev)
>  {
>  	struct omap3_spi_priv *priv = dev_get_priv(dev);
> -	const void *blob = gd->fdt_blob;
> -	int node = dev_of_offset(dev);
> +	struct omap3_spi_plat *plat = dev_get_platdata(dev);
>  

Definition of struct omap3_spi_plat is available till 5/5.. Should this
patch come after 5/5?

Regards
Vignesh

> -	struct omap2_mcspi_platform_config* data =
> -		(struct omap2_mcspi_platform_config*)dev_get_driver_data(dev);
> -
> -	priv->regs = (struct mcspi *)(dev_read_addr(dev) + data->regs_offset);
> -	if (fdtdec_get_bool(blob, node, "ti,pindir-d0-out-d1-in"))
> -		priv->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
> -	else
> -		priv->pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT;
> +	priv->regs = plat->regs;
> +	priv->pin_dir = plat->pin_dir;
>  	priv->wordlen = SPI_DEFAULT_WORDLEN;
>  
>  	spi_reset(priv->regs);
> @@ -544,6 +537,7 @@ static const struct dm_spi_ops omap3_spi_ops = {
>  	 */
>  };
>  
> +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
>  static struct omap2_mcspi_platform_config omap2_pdata = {
>  	.regs_offset = 0,
>  };
> @@ -552,16 +546,37 @@ static struct omap2_mcspi_platform_config omap4_pdata = {
>  	.regs_offset = OMAP4_MCSPI_REG_OFFSET,
>  };
>  
> +static int omap3_spi_ofdata_to_platdata(struct udevice *dev)
> +{
> +	struct omap2_mcspi_platform_config *data =
> +		(struct omap2_mcspi_platform_config *)dev_get_driver_data(dev);
> +	struct omap3_spi_plat *plat = dev_get_platdata(dev);
> +
> +	plat->regs = (struct mcspi *)(dev_read_addr(dev) + data->regs_offset);
> +
> +	if (dev_read_bool(dev, "ti,pindir-d0-out-d1-in"))
> +		plat->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
> +	else
> +		plat->pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT;
> +
> +	return 0;
> +}
> +
>  static const struct udevice_id omap3_spi_ids[] = {
>  	{ .compatible = "ti,omap2-mcspi", .data = (ulong)&omap2_pdata },
>  	{ .compatible = "ti,omap4-mcspi", .data = (ulong)&omap4_pdata },
>  	{ }
>  };
> -
> +#endif
>  U_BOOT_DRIVER(omap3_spi) = {
>  	.name   = "omap3_spi",
>  	.id     = UCLASS_SPI,
> +	.flags	= DM_FLAG_PRE_RELOC,
> +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
>  	.of_match = omap3_spi_ids,
> +	.ofdata_to_platdata = omap3_spi_ofdata_to_platdata,
> +	.platdata_auto_alloc_size = sizeof(struct omap3_spi_plat),
> +#endif
>  	.probe = omap3_spi_probe,
>  	.ops    = &omap3_spi_ops,
>  	.priv_auto_alloc_size = sizeof(struct omap3_spi_priv),
> 


More information about the U-Boot mailing list