omap2_mcspi: small fixes of output data format
[safe/jmp/linux-2.6] / drivers / spi / omap2_mcspi.c
index e96ad27..e0de0d0 100644 (file)
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/slab.h>
 
 #include <linux/spi/spi.h>
 
-#include <mach/dma.h>
-#include <mach/clock.h>
+#include <plat/dma.h>
+#include <plat/clock.h>
 
 
 #define OMAP2_MCSPI_MAX_FREQ           48000000
@@ -134,6 +135,7 @@ struct omap2_mcspi_cs {
        void __iomem            *base;
        unsigned long           phys;
        int                     word_len;
+       struct list_head        node;
        /* Context save and restore shadow register */
        u32                     chconf0;
 };
@@ -145,6 +147,7 @@ struct omap2_mcspi_regs {
        u32 sysconfig;
        u32 modulctrl;
        u32 wakeupenable;
+       struct list_head cs;
 };
 
 static struct omap2_mcspi_regs omap2_mcspi_ctx[OMAP2_MCSPI_MAX_CTRL];
@@ -201,6 +204,7 @@ static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val)
 
        cs->chconf0 = val;
        mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCONF0, val);
+       mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0);
 }
 
 static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
@@ -255,6 +259,7 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master)
 static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
 {
        struct spi_master *spi_cntrl;
+       struct omap2_mcspi_cs *cs;
        spi_cntrl = mcspi->master;
 
        /* McSPI: context restore */
@@ -266,6 +271,10 @@ static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
 
        mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE,
                        omap2_mcspi_ctx[spi_cntrl->bus_num - 1].wakeupenable);
+
+       list_for_each_entry(cs, &omap2_mcspi_ctx[spi_cntrl->bus_num - 1].cs,
+                       node)
+               __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
 }
 static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi)
 {
@@ -524,7 +533,7 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
                                        goto out;
                                }
 #ifdef VERBOSE
-                               dev_dbg(&spi->dev, "write-%d %04x\n",
+                               dev_dbg(&spi->dev, "write-%d %08x\n",
                                                word_len, *tx);
 #endif
                                __raw_writel(*tx++, tx_reg);
@@ -542,7 +551,7 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
                                        mcspi_write_chconf0(spi, l);
                                *rx++ = __raw_readl(rx_reg);
 #ifdef VERBOSE
-                               dev_dbg(&spi->dev, "read-%d %04x\n",
+                               dev_dbg(&spi->dev, "read-%d %08x\n",
                                                word_len, *(rx - 1));
 #endif
                        }
@@ -571,6 +580,7 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi,
        struct spi_master *spi_cntrl;
        u32 l = 0, div = 0;
        u8 word_len = spi->bits_per_word;
+       u32 speed_hz = spi->max_speed_hz;
 
        mcspi = spi_master_get_devdata(spi->master);
        spi_cntrl = mcspi->master;
@@ -580,9 +590,12 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi,
 
        cs->word_len = word_len;
 
-       if (spi->max_speed_hz) {
+       if (t && t->speed_hz)
+               speed_hz = t->speed_hz;
+
+       if (speed_hz) {
                while (div <= 15 && (OMAP2_MCSPI_MAX_FREQ / (1 << div))
-                                       > spi->max_speed_hz)
+                                       > speed_hz)
                        div++;
        } else
                div = 15;
@@ -714,6 +727,9 @@ static int omap2_mcspi_setup(struct spi_device *spi)
                cs->phys = mcspi->phys + spi->chip_select * 0x14;
                cs->chconf0 = 0;
                spi->controller_state = cs;
+               /* Link this to context save list */
+               list_add_tail(&cs->node,
+                       &omap2_mcspi_ctx[mcspi->master->bus_num - 1].cs);
        }
 
        if (mcspi_dma->dma_rx_channel == -1
@@ -736,11 +752,18 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)
 {
        struct omap2_mcspi      *mcspi;
        struct omap2_mcspi_dma  *mcspi_dma;
+       struct omap2_mcspi_cs   *cs;
 
        mcspi = spi_master_get_devdata(spi->master);
        mcspi_dma = &mcspi->dma_channels[spi->chip_select];
 
-       kfree(spi->controller_state);
+       if (spi->controller_state) {
+               /* Unlink controller state from context save list */
+               cs = spi->controller_state;
+               list_del(&cs->node);
+
+               kfree(spi->controller_state);
+       }
 
        if (mcspi_dma->dma_rx_channel != -1) {
                omap_free_dma(mcspi_dma->dma_rx_channel);
@@ -999,7 +1022,8 @@ static u8 __initdata spi2_txdma_id[] = {
        OMAP24XX_DMA_SPI2_TX1,
 };
 
-#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
+#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
+       || defined(CONFIG_ARCH_OMAP4)
 static u8 __initdata spi3_rxdma_id[] = {
        OMAP24XX_DMA_SPI3_RX0,
        OMAP24XX_DMA_SPI3_RX1,
@@ -1011,7 +1035,7 @@ static u8 __initdata spi3_txdma_id[] = {
 };
 #endif
 
-#ifdef CONFIG_ARCH_OMAP3
+#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
 static u8 __initdata spi4_rxdma_id[] = {
        OMAP34XX_DMA_SPI4_RX0,
 };
@@ -1041,14 +1065,15 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
                txdma_id = spi2_txdma_id;
                num_chipselect = 2;
                break;
-#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
+#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
+       || defined(CONFIG_ARCH_OMAP4)
        case 3:
                rxdma_id = spi3_rxdma_id;
                txdma_id = spi3_txdma_id;
                num_chipselect = 2;
                break;
 #endif
-#ifdef CONFIG_ARCH_OMAP3
+#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
        case 4:
                rxdma_id = spi4_rxdma_id;
                txdma_id = spi4_txdma_id;
@@ -1104,6 +1129,7 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
 
        spin_lock_init(&mcspi->lock);
        INIT_LIST_HEAD(&mcspi->msg_queue);
+       INIT_LIST_HEAD(&omap2_mcspi_ctx[master->bus_num - 1].cs);
 
        mcspi->ick = clk_get(&pdev->dev, "ick");
        if (IS_ERR(mcspi->ick)) {