sunxi: video: Add lvds support
[oweals/u-boot.git] / drivers / spi / altera_spi.c
index 8e898b99c05cdafb06780dd8b3792b21ec4bc2b4..a4d03d97cfcff6aff2d20718f40ec83090384545 100644 (file)
 #include <malloc.h>
 #include <spi.h>
 
+#ifndef CONFIG_ALTERA_SPI_IDLE_VAL
+#define CONFIG_ALTERA_SPI_IDLE_VAL 0xff
+#endif
+
+#ifndef CONFIG_SYS_ALTERA_SPI_LIST
+#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE }
+#endif
+
 struct altera_spi_regs {
        u32     rxdata;
        u32     txdata;
@@ -35,10 +43,6 @@ struct altera_spi_regs {
 #define ALTERA_SPI_CONTROL_IE_MSK      (1 << 8)
 #define ALTERA_SPI_CONTROL_SSO_MSK     (1 << 10)
 
-#ifndef CONFIG_SYS_ALTERA_SPI_LIST
-#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE }
-#endif
-
 static ulong altera_spi_base_list[] = CONFIG_SYS_ALTERA_SPI_LIST;
 
 struct altera_spi_slave {
@@ -117,19 +121,15 @@ void spi_release_bus(struct spi_slave *slave)
        writel(0, &altspi->regs->slave_sel);
 }
 
-#ifndef CONFIG_ALTERA_SPI_IDLE_VAL
-# define CONFIG_ALTERA_SPI_IDLE_VAL 0xff
-#endif
-
 int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
             void *din, unsigned long flags)
 {
        struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
        /* assume spi core configured to do 8 bit transfers */
-       uint bytes = bitlen / 8;
-       const uchar *txp = dout;
-       uchar *rxp = din;
-       uint32_t reg, start;
+       unsigned int bytes = bitlen / 8;
+       const unsigned char *txp = dout;
+       unsigned char *rxp = din;
+       uint32_t reg, data, start;
 
        debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
              slave->bus, slave->cs, bitlen, bytes, flags);
@@ -150,10 +150,13 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                spi_cs_activate(slave);
 
        while (bytes--) {
-               uchar d = txp ? *txp++ : CONFIG_ALTERA_SPI_IDLE_VAL;
+               if (txp)
+                       data = *txp++;
+               else
+                       data = CONFIG_ALTERA_SPI_IDLE_VAL;
 
-               debug("%s: tx:%x ", __func__, d);
-               writel(d, &altspi->regs->txdata);
+               debug("%s: tx:%x ", __func__, data);
+               writel(data, &altspi->regs->txdata);
 
                start = get_timer(0);
                while (1) {
@@ -166,11 +169,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                        }
                }
 
-               d = readl(&altspi->regs->rxdata);
+               data = readl(&altspi->regs->rxdata);
                if (rxp)
-                       *rxp++ = d;
+                       *rxp++ = data & 0xff;
 
-               debug("rx:%x\n", d);
+               debug("rx:%x\n", data);
        }
 
 done: