]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/spi/mpc8xxx_spi.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / drivers / spi / mpc8xxx_spi.c
index 9eaf9860b4f83d720cffa7661c5c24a3fdc397d7..6b0e3b46ec8fead7db89daf64e67422dc9fe50bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2006 Ben Warren, Qstreams Networks Inc.
- * With help from the common/soft_spi and cpu/mpc8260 drivers
+ * With help from the common/soft_spi and arch/powerpc/cpu/mpc8260 drivers
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -45,13 +45,10 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        if (!spi_cs_is_valid(bus, cs))
                return NULL;
 
-       slave = malloc(sizeof(struct spi_slave));
+       slave = spi_alloc_slave_base(bus, cs);
        if (!slave)
                return NULL;
 
-       slave->bus = bus;
-       slave->cs = cs;
-
        /*
         * TODO: Some of the code in spi_init() should probably move
         * here, or into spi_claim_bus() below.
@@ -67,7 +64,7 @@ void spi_free_slave(struct spi_slave *slave)
 
 void spi_init(void)
 {
-       volatile spi8xxx_t *spi = &((immap_t *) (CFG_IMMR))->spi;
+       volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
 
        /*
         * SPI pins on the MPC83xx are not muxed, so all we do is initialize
@@ -94,7 +91,7 @@ void spi_release_bus(struct spi_slave *slave)
 int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                void *din, unsigned long flags)
 {
-       volatile spi8xxx_t *spi = &((immap_t *) (CFG_IMMR))->spi;
+       volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
        unsigned int tmpdout, tmpdin, event;
        int numBlks = bitlen / 32 + (bitlen % 32 ? 1 : 0);
        int tm, isRead = 0;
@@ -124,6 +121,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                 * len > 16               0
                 */
 
+               spi->mode &= ~SPI_MODE_EN;
+
                if (bitlen <= 16) {
                        if (bitlen <= 4)
                                spi->mode = (spi->mode & 0xff0fffff) |
@@ -138,6 +137,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                        dout += 4;
                }
 
+               spi->mode |= SPI_MODE_EN;
+
                spi->tx = tmpdout;      /* Write the data out */
                debug("*** spi_xfer: ... %08x written\n", tmpdout);