[U-Boot] [U-Boot 6/7] dm: spi: xilinx_spi: Convert to driver model

Simon Glass sjg at chromium.org
Thu Apr 23 20:24:19 CEST 2015


Hi Jagan,

On 23 April 2015 at 08:15, Jagannadha Sutradharudu Teki
<jagannadh.teki at gmail.com> wrote:
> This converts the xilinx spi driver to use the driver model.
>
> Signed-off-by: Jagannadha Sutradharudu Teki <jagannadh.teki at gmail.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Michal Simek <michal.simek at xilinx.com>
> ---
> Note: Michal, can you test this, I don't have hardware.
>
>  drivers/spi/xilinx_spi.c | 212 +++++++++++++++++++++++++++--------------------
>  1 file changed, 124 insertions(+), 88 deletions(-)

Acked-by: Simon Glass <sjg at chromium.org>

>
> diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
> index 3803c4c..4acade4 100644
> --- a/drivers/spi/xilinx_spi.c
> +++ b/drivers/spi/xilinx_spi.c
> @@ -4,6 +4,7 @@
>   * Supports 8 bit SPI transfers only, with or w/o FIFO
>   *
>   * Based on bfin_spi.c, by way of altera_spi.c
> + * Copyright (c) 2015 Jagannadha Sutradharudu Teki <jagannadh.teki at gmail.com>
>   * Copyright (c) 2012 Stephan Linz <linz at li-pro.net>
>   * Copyright (c) 2010 Graeme Smecher <graeme.smecher at mail.mcgill.ca>
>   * Copyright (c) 2010 Thomas Chou <thomas at wytron.com.tw>
> @@ -14,6 +15,8 @@
>
>  #include <config.h>
>  #include <common.h>
> +#include <dm.h>
> +#include <errno.h>
>  #include <malloc.h>
>  #include <spi.h>
>
> @@ -79,7 +82,7 @@
>  #endif
>
>  /* xilinx spi register set */
> -struct xilinx_spi_reg {
> +struct xilinx_spi_regs {
>         u32 __space0__[7];
>         u32 dgier;      /* Device Global Interrupt Enable Register (DGIER) */
>         u32 ipisr;      /* IP Interrupt Status Register (IPISR) */
> @@ -97,113 +100,76 @@ struct xilinx_spi_reg {
>         u32 spirfor;    /* SPI Receive FIFO Occupancy Register (SPIRFOR) */
>  };
>
> -/* xilinx spi slave */
> -struct xilinx_spi_slave {
> -       struct spi_slave slave;
> -       struct xilinx_spi_reg *regs;
> +/* xilinx spi priv */
> +struct xilinx_spi_priv {
> +       struct xilinx_spi_regs *regs;
>         unsigned int freq;
>         unsigned int mode;
> +       unsigned int cs;
>  };
>
> -static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
> -                       struct spi_slave *slave)
> -{
> -       return container_of(slave, struct xilinx_spi_slave, slave);
> -}
> -
>  static unsigned long xilinx_spi_base_list[] = CONFIG_SYS_XILINX_SPI_LIST;
> -int spi_cs_is_valid(unsigned int bus, unsigned int cs)
> +static int xilinx_spi_probe(struct udevice *bus)
>  {
> -       return bus < ARRAY_SIZE(xilinx_spi_base_list) && cs < 32;
> -}
> +       struct xilinx_spi_priv *priv = dev_get_priv(bus);
> +       struct xilinx_spi_regs *regs = priv->regs;
>
> -void spi_cs_activate(struct spi_slave *slave)
> -{
> -       struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
> +       priv->regs = (struct xilinx_spi_regs *)xilinx_spi_base_list[bus->seq];
> +       priv->cs = spi_chip_select(bus);
>
> -       writel(SPISSR_ACT(slave->cs), &xilspi->regs->spissr);
> -}
> +       writel(SPISSR_RESET_VALUE, &regs->srr);
>
> -void spi_cs_deactivate(struct spi_slave *slave)
> -{
> -       struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
> -
> -       writel(SPISSR_OFF, &xilspi->regs->spissr);
> -}
> -
> -void spi_init(void)
> -{
> -       /* do nothing */
> +       return 0;
>  }
>
> -struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
> -                                 unsigned int max_hz, unsigned int mode)
> +static void spi_cs_activate(struct udevice *dev)
>  {
> -       struct xilinx_spi_slave *xilspi;
> -
> -       if (!spi_cs_is_valid(bus, cs)) {
> -               printf("XILSPI error: unsupported bus %d / cs %d\n", bus, cs);
> -               return NULL;
> -       }
> -
> -       xilspi = spi_alloc_slave(struct xilinx_spi_slave, bus, cs);
> -       if (!xilspi) {
> -               printf("XILSPI error: malloc of SPI structure failed\n");
> -               return NULL;
> -       }
> -       xilspi->regs = (struct xilinx_spi_reg *)xilinx_spi_base_list[bus];
> -       xilspi->freq = max_hz;
> -       xilspi->mode = mode;
> -       debug("spi_setup_slave: bus:%i cs:%i base:%p mode:%x max_hz:%d\n",
> -             bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
> -
> -       writel(SPISSR_RESET_VALUE, &xilspi->regs->srr);
> +       struct udevice *bus = dev->parent;
> +       struct xilinx_spi_priv *priv = dev_get_priv(bus);
> +       struct xilinx_spi_regs *regs = priv->regs;
>
> -       return &xilspi->slave;
> +       writel(SPISSR_ACT(priv->cs), &regs->spissr);
>  }
>
> -void spi_free_slave(struct spi_slave *slave)
> +static void spi_cs_deactivate(struct udevice *dev)
>  {
> -       struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
> +       struct udevice *bus = dev->parent;

dev_get_parent() so we can add pointer checking later perhaps.

> +       struct xilinx_spi_priv *priv = dev_get_priv(bus);
> +       struct xilinx_spi_regs *regs = priv->regs;
>
> -       free(xilspi);
> +       writel(SPISSR_OFF, &regs->spissr);
>  }
>

[snip]

Regards,
Simon


More information about the U-Boot mailing list