Re: [U-Boot] [PATCH v2 18/18] spi: mpc8xxx: Convert to DM
Hi Jagan, On Thu, Apr 26, 2018 at 7:49 AM, Jagan Tekiwrote: > On Thu, Apr 26, 2018 at 11:13 AM, Mario Six wrote: >> Hi Jagan, >> >> On Thu, Apr 26, 2018 at 7:34 AM, Jagan Teki wrote: >>> On Thu, Apr 19, 2018 at 6:06 PM, Mario Six wrote: Support DM in the MPC8xxx SPI driver, and remove the legacy SPI interface. Signed-off-by: Mario Six --- drivers/spi/mpc8xxx_spi.c | 144 ++ 1 file changed, 107 insertions(+), 37 deletions(-) --- Changes v1 -> v2: * Removed legacy layer * Sorted includes * Now return -ETIMEDOUT on timeout during transfer --- diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 4aa5db8821..9c9dd67ec2 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -6,10 +6,12 @@ */ #include - +#include +#include #include #include #include +#include >>> >>> [snip] >>> +}; + +static const struct udevice_id mpc8xxx_spi_ids[] = { + { .compatible = "fsl,spi" }, >>> >>> Look like new binding right? don't we have suitable binding for this >>> driver? or what is the equivalent driver for this in Linux? >>> >> >> I took that compatible string from the Linux kernel, actually. See for >> example >> >> https://raw.githubusercontent.com/torvalds/linux/master/arch/powerpc/boot/dts/mpc8379_mds.dts >> >> There are more specific ones, like "fsl,mpc8610-spi", but "fsl,spi" is >> the most generic. > > So this driver is same as drivers/spi/spi-fsl-spi.c from Linux, is it? > Yes, with reduced functionality, of course, but compatible to the same devices. Best regards, Mario ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v2 18/18] spi: mpc8xxx: Convert to DM
On Thu, Apr 26, 2018 at 11:13 AM, Mario Sixwrote: > Hi Jagan, > > On Thu, Apr 26, 2018 at 7:34 AM, Jagan Teki wrote: >> On Thu, Apr 19, 2018 at 6:06 PM, Mario Six wrote: >>> Support DM in the MPC8xxx SPI driver, and remove the legacy SPI >>> interface. >>> >>> Signed-off-by: Mario Six >>> --- >>> drivers/spi/mpc8xxx_spi.c | 144 >>> ++ >>> 1 file changed, 107 insertions(+), 37 deletions(-) >>> --- >>> >>> Changes v1 -> v2: >>> * Removed legacy layer >>> * Sorted includes >>> * Now return -ETIMEDOUT on timeout during transfer >>> >>> --- >>> >>> diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c >>> index 4aa5db8821..9c9dd67ec2 100644 >>> --- a/drivers/spi/mpc8xxx_spi.c >>> +++ b/drivers/spi/mpc8xxx_spi.c >>> @@ -6,10 +6,12 @@ >>> */ >>> >>> #include >>> - >>> +#include >>> +#include >>> #include >>> #include >>> #include >>> +#include >> >> [snip] >> >>> +}; >>> + >>> +static const struct udevice_id mpc8xxx_spi_ids[] = { >>> + { .compatible = "fsl,spi" }, >> >> Look like new binding right? don't we have suitable binding for this >> driver? or what is the equivalent driver for this in Linux? >> > > I took that compatible string from the Linux kernel, actually. See for example > > https://raw.githubusercontent.com/torvalds/linux/master/arch/powerpc/boot/dts/mpc8379_mds.dts > > There are more specific ones, like "fsl,mpc8610-spi", but "fsl,spi" is > the most generic. So this driver is same as drivers/spi/spi-fsl-spi.c from Linux, is it? ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v2 18/18] spi: mpc8xxx: Convert to DM
Hi Jagan, On Thu, Apr 26, 2018 at 7:34 AM, Jagan Tekiwrote: > On Thu, Apr 19, 2018 at 6:06 PM, Mario Six wrote: >> Support DM in the MPC8xxx SPI driver, and remove the legacy SPI >> interface. >> >> Signed-off-by: Mario Six >> --- >> drivers/spi/mpc8xxx_spi.c | 144 >> ++ >> 1 file changed, 107 insertions(+), 37 deletions(-) >> --- >> >> Changes v1 -> v2: >> * Removed legacy layer >> * Sorted includes >> * Now return -ETIMEDOUT on timeout during transfer >> >> --- >> >> diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c >> index 4aa5db8821..9c9dd67ec2 100644 >> --- a/drivers/spi/mpc8xxx_spi.c >> +++ b/drivers/spi/mpc8xxx_spi.c >> @@ -6,10 +6,12 @@ >> */ >> >> #include >> - >> +#include >> +#include >> #include >> #include >> #include >> +#include > > [snip] > >> +}; >> + >> +static const struct udevice_id mpc8xxx_spi_ids[] = { >> + { .compatible = "fsl,spi" }, > > Look like new binding right? don't we have suitable binding for this > driver? or what is the equivalent driver for this in Linux? > I took that compatible string from the Linux kernel, actually. See for example https://raw.githubusercontent.com/torvalds/linux/master/arch/powerpc/boot/dts/mpc8379_mds.dts There are more specific ones, like "fsl,mpc8610-spi", but "fsl,spi" is the most generic. > Jagan. > Best regards, Mario ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v2 18/18] spi: mpc8xxx: Convert to DM
On Thu, Apr 19, 2018 at 6:06 PM, Mario Sixwrote: > Support DM in the MPC8xxx SPI driver, and remove the legacy SPI > interface. > > Signed-off-by: Mario Six > --- > drivers/spi/mpc8xxx_spi.c | 144 > ++ > 1 file changed, 107 insertions(+), 37 deletions(-) > --- > > Changes v1 -> v2: > * Removed legacy layer > * Sorted includes > * Now return -ETIMEDOUT on timeout during transfer > > --- > > diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c > index 4aa5db8821..9c9dd67ec2 100644 > --- a/drivers/spi/mpc8xxx_spi.c > +++ b/drivers/spi/mpc8xxx_spi.c > @@ -6,10 +6,12 @@ > */ > > #include > - > +#include > +#include > #include > #include > #include > +#include [snip] > +}; > + > +static const struct udevice_id mpc8xxx_spi_ids[] = { > + { .compatible = "fsl,spi" }, Look like new binding right? don't we have suitable binding for this driver? or what is the equivalent driver for this in Linux? Jagan. -- Jagan Teki Free Software Engineer | www.openedev.com U-Boot, Linux | Upstream Maintainer Hyderabad, India. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v2 18/18] spi: mpc8xxx: Convert to DM
Support DM in the MPC8xxx SPI driver, and remove the legacy SPI interface. Signed-off-by: Mario Six--- drivers/spi/mpc8xxx_spi.c | 144 ++ 1 file changed, 107 insertions(+), 37 deletions(-) --- Changes v1 -> v2: * Removed legacy layer * Sorted includes * Now return -ETIMEDOUT on timeout during transfer --- diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 4aa5db8821..9c9dd67ec2 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -6,10 +6,12 @@ */ #include - +#include +#include #include #include #include +#include enum { SPI_EV_NE = BIT(31 - 22), /* Receiver Not Empty */ @@ -31,6 +33,12 @@ enum { SPI_COM_LST = BIT(31 - 9), }; +struct mpc8xxx_priv { + spi8xxx_t *spi; + struct gpio_desc gpios[16]; + int max_cs; +}; + static inline u32 to_prescale_mod(u32 val) { return (min(val, (u32)15) << 16); @@ -43,70 +51,90 @@ static void set_char_len(spi8xxx_t *spi, u32 val) #define SPI_TIMEOUT1000 -struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode) +static int __spi_set_speed(spi8xxx_t *spi, uint speed) { - struct spi_slave *slave; + /* TODO(mario@gdsys.cc): This only ever sets one fixed speed */ - if (!spi_cs_is_valid(bus, cs)) - return NULL; - - slave = spi_alloc_slave_base(bus, cs); - if (!slave) - return NULL; - - /* -* TODO: Some of the code in spi_init() should probably move -* here, or into spi_claim_bus() below. -*/ + /* Use SYSCLK / 8 (16.67MHz typ.) */ + clrsetbits_be32(>mode, SPI_MODE_PM_MASK, to_prescale_mod(1)); - return slave; + return 0; } -void spi_free_slave(struct spi_slave *slave) +static int mpc8xxx_spi_ofdata_to_platdata(struct udevice *dev) { - free(slave); + struct mpc8xxx_priv *priv = dev_get_priv(dev); + int ret; + + priv->spi = (spi8xxx_t *)dev_read_addr(dev); + + /* TODO(mario@gdsys.cc): Read clock and save the value */ + + ret = gpio_request_list_by_name(dev, "gpios", priv->gpios, + ARRAY_SIZE(priv->gpios), GPIOD_IS_OUT | GPIOD_ACTIVE_LOW); + if (ret < 0) + return -EINVAL; + + priv->max_cs = ret; + + return 0; } -void spi_init(void) +static int mpc8xxx_spi_probe(struct udevice *dev) { - spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi; + struct mpc8xxx_priv *priv = dev_get_priv(dev); /* * SPI pins on the MPC83xx are not muxed, so all we do is initialize * some registers */ - out_be32(>mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN); - /* Use SYSCLK / 8 (16.67MHz typ.) */ - clrsetbits_be32(>mode, SPI_MODE_PM_MASK, to_prescale_mod(1)); + out_be32(>spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN); + + __spi_set_speed(priv->spi, 1667); + /* Clear all SPI events */ - setbits_be32(>event, 0x); + setbits_be32(>spi->event, 0x); /* Mask all SPI interrupts */ - clrbits_be32(>mask, 0x); + clrbits_be32(>spi->mask, 0x); /* LST bit doesn't do anything, so disregard */ - out_be32(>com, 0); + out_be32(>spi->com, 0); + + return 0; } -int spi_claim_bus(struct spi_slave *slave) +static void mpc8xxx_spi_cs_activate(struct udevice *dev) { - return 0; + struct mpc8xxx_priv *priv = dev_get_priv(dev->parent); + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + + dm_gpio_set_dir_flags(>gpios[platdata->cs], GPIOD_IS_OUT); + dm_gpio_set_value(>gpios[platdata->cs], 0); } -void spi_release_bus(struct spi_slave *slave) +static void mpc8xxx_spi_cs_deactivate(struct udevice *dev) { + struct mpc8xxx_priv *priv = dev_get_priv(dev->parent); + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + + dm_gpio_set_dir_flags(>gpios[platdata->cs], GPIOD_IS_OUT); + dm_gpio_set_value(>gpios[platdata->cs], 1); } -int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, -ulong flags) +static int mpc8xxx_spi_xfer(struct udevice *dev, uint bitlen, + const void *dout, void *din, ulong flags) { - spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi; - u32 tmpdin; + struct udevice *bus = dev->parent; + struct mpc8xxx_priv *priv = dev_get_priv(bus); + spi8xxx_t *spi = priv->spi; + struct dm_spi_slave_platdata *platdata = dev_get_parent_platdata(dev); + u32 tmpdin = 0; int num_blks = DIV_ROUND_UP(bitlen, 32); - debug("%s: slave %u:%u dout %08X din %08X bitlen %u\n", __func__, - slave->bus, slave->cs, *(uint *)dout, *(uint *)din, bitlen); + debug("%s: slave %s:%u dout %08X din