[U-Boot] [PATCH 18/19] spi: mpc8xxx: Prepare DM conversion
Mario Six
mario.six at gdsys.cc
Tue Apr 10 11:01:47 UTC 2018
To prepare DM conversion, move all driver functionality into separate
functions, and call them from the driver functions; these functions will
also be called from the DM-driver functions, so that we can keep the
legacy functions for the boards that still need them.
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
drivers/spi/mpc8xxx_spi.c | 120 +++++++++++++++++++++++++++++-----------------
1 file changed, 75 insertions(+), 45 deletions(-)
diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
index 4aa5db8821..5724a00585 100644
--- a/drivers/spi/mpc8xxx_spi.c
+++ b/drivers/spi/mpc8xxx_spi.c
@@ -43,41 +43,27 @@ static void set_char_len(spi8xxx_t *spi, u32 val)
#define SPI_TIMEOUT 1000
-struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode)
+static void __spi_init_head(spi8xxx_t *spi)
{
- struct spi_slave *slave;
-
- 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.
+ * SPI pins on the MPC83xx are not muxed, so all we do is initialize
+ * some registers
*/
-
- return slave;
-}
-
-void spi_free_slave(struct spi_slave *slave)
-{
- free(slave);
+ out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN);
}
-void spi_init(void)
+static int __spi_set_speed(spi8xxx_t *spi, uint speed)
{
- spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi;
+ /* TODO: This only ever sets one fixed speed */
- /*
- * SPI pins on the MPC83xx are not muxed, so all we do is initialize
- * some registers
- */
- out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN);
/* Use SYSCLK / 8 (16.67MHz typ.) */
clrsetbits_be32(&spi->mode, SPI_MODE_PM_MASK, to_prescale_mod(1));
+
+ return 0;
+}
+
+static void __spi_init_tail(spi8xxx_t *spi)
+{
/* Clear all SPI events */
setbits_be32(&spi->event, 0xffffffff);
/* Mask all SPI interrupts */
@@ -86,28 +72,12 @@ void spi_init(void)
out_be32(&spi->com, 0);
}
-int spi_claim_bus(struct spi_slave *slave)
+static int __spi_xfer(spi8xxx_t *spi, uint bitlen, const u8 *dout, u8 *din,
+ ulong flags)
{
- return 0;
-}
-
-void spi_release_bus(struct spi_slave *slave)
-{
-}
-
-int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
- ulong flags)
-{
- spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi;
u32 tmpdin;
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);
-
- if (flags & SPI_XFER_BEGIN)
- spi_cs_activate(slave);
-
/* Clear all SPI events */
setbits_be32(&spi->event, 0xffffffff);
@@ -186,8 +156,68 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
debug("*** %s: transfer ended. Value=%08x\n", __func__, tmpdin);
}
+ return 0;
+}
+
+struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode)
+{
+ struct spi_slave *slave;
+
+ 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.
+ */
+
+ return slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+ free(slave);
+}
+
+void spi_init(void)
+{
+ spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi;
+
+ out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN);
+ __spi_init_head(spi);
+ __spi_set_speed(spi, 16666667);
+ __spi_init_tail(spi);
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+ return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+}
+
+int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
+ ulong flags)
+{
+ spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi;
+ int ret;
+
+ debug("%s: slave %u:%u dout %08X din %08X bitlen %u\n", __func__,
+ slave->bus, slave->cs, *(uint *)dout, *(uint *)din, bitlen);
+
+ if (flags & SPI_XFER_BEGIN)
+ spi_cs_activate(slave);
+
+ ret = __spi_xfer(spi, bitlen, dout, din, flags);
+
if (flags & SPI_XFER_END)
spi_cs_deactivate(slave);
- return 0;
+ return ret;
}
--
2.11.0
More information about the U-Boot
mailing list