drm/nv50: fix iommu errors caused by device reading from address 0
[safe/jmp/linux-2.6] / drivers / spi / pxa2xx_spi.c
index c1688c7..e76b1af 100644 (file)
 #include <linux/delay.h>
 #include <linux/clk.h>
 #include <linux/gpio.h>
+#include <linux/slab.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/delay.h>
 
 #include <mach/dma.h>
-#include <mach/regs-ssp.h>
-#include <mach/ssp.h>
+#include <plat/ssp.h>
 #include <mach/pxa2xx_spi.h>
 
 MODULE_AUTHOR("Stephen Street");
@@ -195,7 +195,7 @@ static void cs_deassert(struct driver_data *drv_data)
        struct chip_data *chip = drv_data->cur_chip;
 
        if (chip->cs_control) {
-               chip->cs_control(PXA2XX_CS_ASSERT);
+               chip->cs_control(PXA2XX_CS_DEASSERT);
                return;
        }
 
@@ -213,7 +213,7 @@ static int flush(struct driver_data *drv_data)
                while (read_SSSR(reg) & SSSR_RNE) {
                        read_SSDR(reg);
                }
-       } while ((read_SSSR(reg) & SSSR_BSY) && limit--);
+       } while ((read_SSSR(reg) & SSSR_BSY) && --limit);
        write_SSSR(SSSR_ROR, reg);
 
        return limit;
@@ -484,7 +484,7 @@ static int wait_ssp_rx_stall(void const __iomem *ioaddr)
 {
        unsigned long limit = loops_per_jiffy << 1;
 
-       while ((read_SSSR(ioaddr) & SSSR_BSY) && limit--)
+       while ((read_SSSR(ioaddr) & SSSR_BSY) && --limit)
                cpu_relax();
 
        return limit;
@@ -494,7 +494,7 @@ static int wait_dma_channel_stop(int channel)
 {
        unsigned long limit = loops_per_jiffy << 1;
 
-       while (!(DCSR(channel) & DCSR_STOPSTATE) && limit--)
+       while (!(DCSR(channel) & DCSR_STOPSTATE) && --limit)
                cpu_relax();
 
        return limit;
@@ -1185,9 +1185,6 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
        return 0;
 }
 
-/* the spi->mode bits understood by this driver: */
-#define MODEBITS (SPI_CPOL | SPI_CPHA)
-
 static int setup_cs(struct spi_device *spi, struct chip_data *chip,
                    struct pxa2xx_spi_chip *chip_info)
 {
@@ -1236,9 +1233,6 @@ static int setup(struct spi_device *spi)
        uint tx_thres = TX_THRESH_DFLT;
        uint rx_thres = RX_THRESH_DFLT;
 
-       if (!spi->bits_per_word)
-               spi->bits_per_word = 8;
-
        if (drv_data->ssp_type != PXA25x_SSP
                && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
                dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
@@ -1255,12 +1249,6 @@ static int setup(struct spi_device *spi)
                return -EINVAL;
        }
 
-       if (spi->mode & ~MODEBITS) {
-               dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
-                       spi->mode & ~MODEBITS);
-               return -EINVAL;
-       }
-
        /* Only alloc on first setup */
        chip = spi_get_ctldata(spi);
        if (!chip) {
@@ -1328,19 +1316,15 @@ static int setup(struct spi_device *spi)
 
        /* NOTE:  PXA25x_SSP _could_ use external clocking ... */
        if (drv_data->ssp_type != PXA25x_SSP)
-               dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n",
-                               spi->bits_per_word,
-                               clk_get_rate(ssp->clk)
-                                       / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
-                               spi->mode & 0x3,
-                               chip->enable_dma ? "DMA" : "PIO");
+               dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
+                       clk_get_rate(ssp->clk)
+                               / (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
+                       chip->enable_dma ? "DMA" : "PIO");
        else
-               dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n",
-                               spi->bits_per_word,
-                               clk_get_rate(ssp->clk) / 2
-                                       / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
-                               spi->mode & 0x3,
-                               chip->enable_dma ? "DMA" : "PIO");
+               dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
+                       clk_get_rate(ssp->clk) / 2
+                               / (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
+                       chip->enable_dma ? "DMA" : "PIO");
 
        if (spi->bits_per_word <= 8) {
                chip->n_bytes = 1;
@@ -1373,6 +1357,9 @@ static void cleanup(struct spi_device *spi)
 {
        struct chip_data *chip = spi_get_ctldata(spi);
 
+       if (!chip)
+               return;
+
        if (gpio_is_valid(chip->gpio_cs))
                gpio_free(chip->gpio_cs);
 
@@ -1478,7 +1465,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
 
        platform_info = dev->platform_data;
 
-       ssp = ssp_request(pdev->id, pdev->name);
+       ssp = pxa_ssp_request(pdev->id, pdev->name);
        if (ssp == NULL) {
                dev_err(&pdev->dev, "failed to request SSP%d\n", pdev->id);
                return -ENODEV;
@@ -1488,7 +1475,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
        master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
        if (!master) {
                dev_err(&pdev->dev, "cannot alloc spi_master\n");
-               ssp_free(ssp);
+               pxa_ssp_free(ssp);
                return -ENOMEM;
        }
        drv_data = spi_master_get_devdata(master);
@@ -1497,6 +1484,9 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
        drv_data->pdev = pdev;
        drv_data->ssp = ssp;
 
+       /* the spi->mode bits understood by this driver: */
+       master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+
        master->bus_num = pdev->id;
        master->num_chipselect = platform_info->num_chipselect;
        master->dma_alignment = DMA_ALIGNMENT;
@@ -1567,7 +1557,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
        write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
                                SSCR1_TxTresh(TX_THRESH_DFLT),
                                drv_data->ioaddr);
-       write_SSCR0(SSCR0_SerClkDiv(2)
+       write_SSCR0(SSCR0_SCR(2)
                        | SSCR0_Motorola
                        | SSCR0_DataSize(8),
                        drv_data->ioaddr);
@@ -1614,7 +1604,7 @@ out_error_irq_alloc:
 
 out_error_master_alloc:
        spi_master_put(master);
-       ssp_free(ssp);
+       pxa_ssp_free(ssp);
        return status;
 }
 
@@ -1658,7 +1648,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
        free_irq(ssp->irq, drv_data);
 
        /* Release SSP */
-       ssp_free(ssp);
+       pxa_ssp_free(ssp);
 
        /* Disconnect from the SPI framework */
        spi_unregister_master(drv_data->master);
@@ -1678,10 +1668,9 @@ static void pxa2xx_spi_shutdown(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM
-
-static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
+static int pxa2xx_spi_suspend(struct device *dev)
 {
-       struct driver_data *drv_data = platform_get_drvdata(pdev);
+       struct driver_data *drv_data = dev_get_drvdata(dev);
        struct ssp_device *ssp = drv_data->ssp;
        int status = 0;
 
@@ -1694,45 +1683,55 @@ static int pxa2xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
        return 0;
 }
 
-static int pxa2xx_spi_resume(struct platform_device *pdev)
+static int pxa2xx_spi_resume(struct device *dev)
 {
-       struct driver_data *drv_data = platform_get_drvdata(pdev);
+       struct driver_data *drv_data = dev_get_drvdata(dev);
        struct ssp_device *ssp = drv_data->ssp;
        int status = 0;
 
+       if (drv_data->rx_channel != -1)
+               DRCMR(drv_data->ssp->drcmr_rx) =
+                       DRCMR_MAPVLD | drv_data->rx_channel;
+       if (drv_data->tx_channel != -1)
+               DRCMR(drv_data->ssp->drcmr_tx) =
+                       DRCMR_MAPVLD | drv_data->tx_channel;
+
        /* Enable the SSP clock */
        clk_enable(ssp->clk);
 
        /* Start the queue running */
        status = start_queue(drv_data);
        if (status != 0) {
-               dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
+               dev_err(dev, "problem starting queue (%d)\n", status);
                return status;
        }
 
        return 0;
 }
-#else
-#define pxa2xx_spi_suspend NULL
-#define pxa2xx_spi_resume NULL
-#endif /* CONFIG_PM */
+
+static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
+       .suspend        = pxa2xx_spi_suspend,
+       .resume         = pxa2xx_spi_resume,
+};
+#endif
 
 static struct platform_driver driver = {
        .driver = {
-               .name = "pxa2xx-spi",
-               .owner = THIS_MODULE,
+               .name   = "pxa2xx-spi",
+               .owner  = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm     = &pxa2xx_spi_pm_ops,
+#endif
        },
        .remove = pxa2xx_spi_remove,
        .shutdown = pxa2xx_spi_shutdown,
-       .suspend = pxa2xx_spi_suspend,
-       .resume = pxa2xx_spi_resume,
 };
 
 static int __init pxa2xx_spi_init(void)
 {
        return platform_driver_probe(&driver, pxa2xx_spi_probe);
 }
-module_init(pxa2xx_spi_init);
+subsys_initcall(pxa2xx_spi_init);
 
 static void __exit pxa2xx_spi_exit(void)
 {