aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMario Six <mario.six@gdsys.cc>2019-04-29 01:58:47 +0530
committerJagan Teki <jagan@amarulasolutions.com>2019-06-10 17:59:48 +0530
commit8dea61da199540abc56e397f811f72debdd53d1c (patch)
tree8c780b506457555b353aa1ab6e54734ab2be9444 /drivers
parent65f88e0408e8ddba827fb9ace1596591365f0b79 (diff)
downloadu-boot-8dea61da199540abc56e397f811f72debdd53d1c.zip
u-boot-8dea61da199540abc56e397f811f72debdd53d1c.tar.gz
u-boot-8dea61da199540abc56e397f811f72debdd53d1c.tar.bz2
spi: mpc8xxx: Make code more readable
Introduce the to_prescale_mod and set_char_len inline functions to make the code more readable. Note that the added "if (bitlen > 16)" check does not change the semantics of the current code, and hence only preserves the current error (this will be fixed in a later patch in the series). Signed-off-by: Mario Six <mario.six@gdsys.cc> Acked-by: Jagan Teki <jagan@amarulasolutions.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/mpc8xxx_spi.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
index 2a0f3cc..83fd8b3 100644
--- a/drivers/spi/mpc8xxx_spi.c
+++ b/drivers/spi/mpc8xxx_spi.c
@@ -30,6 +30,16 @@ enum {
SPI_COM_LST = BIT(31 - 9),
};
+static inline u32 to_prescale_mod(u32 val)
+{
+ return (min(val, (u32)15) << 16);
+}
+
+static void set_char_len(spi8xxx_t *spi, u32 val)
+{
+ clrsetbits_be32(&spi->mode, SPI_MODE_LEN_MASK, (val << 20));
+}
+
#define SPI_TIMEOUT 1000
struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode)
@@ -66,7 +76,7 @@ void spi_init(void)
*/
out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN);
/* Use SYSCLK / 8 (16.67MHz typ.) */
- clrsetbits_be32(&spi->mode, 0x000f0000, BIT(16));
+ clrsetbits_be32(&spi->mode, SPI_MODE_PM_MASK, to_prescale_mod(1));
/* Clear all SPI events */
setbits_be32(&spi->event, 0xffffffff);
/* Mask all SPI interrupts */
@@ -119,13 +129,14 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
clrbits_be32(&spi->mode, SPI_MODE_EN);
- if (bitlen <= 4) {
- clrsetbits_be32(&spi->mode, 0x00f00000, (3 << 20));
- } else if (bitlen <= 16) {
- clrsetbits_be32(&spi->mode, 0x00f00000,
- ((bitlen - 1) << 20));
- } else {
- clrbits_be32(&spi->mode, 0x00f00000);
+ if (bitlen <= 4)
+ set_char_len(spi, 3);
+ else if (bitlen <= 16)
+ set_char_len(spi, bitlen - 1);
+ else
+ set_char_len(spi, 0);
+
+ if (bitlen > 16) {
/* Set up the next iteration if sending > 32 bits */
bitlen -= 32;
dout += 4;