gpu: nvgpu: Increase PBDMA timeout
[linux-3.10.git] / drivers / spi / spi-ep93xx.c
index 0afd87d..d7bac60 100644 (file)
 #include <linux/dmaengine.h>
 #include <linux/bitops.h>
 #include <linux/interrupt.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/workqueue.h>
 #include <linux/sched.h>
 #include <linux/scatterlist.h>
 #include <linux/spi/spi.h>
 
-#include <mach/dma.h>
-#include <mach/ep93xx_spi.h>
+#include <linux/platform_data/dma-ep93xx.h>
+#include <linux/platform_data/spi-ep93xx.h>
 
 #define SSPCR0                 0x0000
 #define SSPCR0_MODE_SHIFT      6
@@ -75,7 +76,6 @@
  * @clk: clock for the controller
  * @regs_base: pointer to ioremap()'d registers
  * @sspdr_phys: physical address of the SSPDR register
- * @irq: IRQ number used by the driver
  * @min_rate: minimum clock rate (in Hz) supported by the controller
  * @max_rate: maximum clock rate (in Hz) supported by the controller
  * @running: is the queue running
@@ -113,7 +113,6 @@ struct ep93xx_spi {
        struct clk                      *clk;
        void __iomem                    *regs_base;
        unsigned long                   sspdr_phys;
-       int                             irq;
        unsigned long                   min_rate;
        unsigned long                   max_rate;
        bool                            running;
@@ -447,7 +446,7 @@ static inline int bits_per_word(const struct ep93xx_spi *espi)
        struct spi_message *msg = espi->current_msg;
        struct spi_transfer *t = msg->state;
 
-       return t->bits_per_word ? t->bits_per_word : msg->spi->bits_per_word;
+       return t->bits_per_word;
 }
 
 static void ep93xx_do_write(struct ep93xx_spi *espi, struct spi_transfer *t)
@@ -544,13 +543,12 @@ static void ep93xx_spi_pio_transfer(struct ep93xx_spi *espi)
  * in case of failure.
  */
 static struct dma_async_tx_descriptor *
-ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
+ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir)
 {
        struct spi_transfer *t = espi->current_msg->state;
        struct dma_async_tx_descriptor *txd;
        enum dma_slave_buswidth buswidth;
        struct dma_slave_config conf;
-       enum dma_transfer_direction slave_dirn;
        struct scatterlist *sg;
        struct sg_table *sgt;
        struct dma_chan *chan;
@@ -566,14 +564,13 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
        memset(&conf, 0, sizeof(conf));
        conf.direction = dir;
 
-       if (dir == DMA_FROM_DEVICE) {
+       if (dir == DMA_DEV_TO_MEM) {
                chan = espi->dma_rx;
                buf = t->rx_buf;
                sgt = &espi->rx_sgt;
 
                conf.src_addr = espi->sspdr_phys;
                conf.src_addr_width = buswidth;
-               slave_dirn = DMA_DEV_TO_MEM;
        } else {
                chan = espi->dma_tx;
                buf = t->tx_buf;
@@ -581,7 +578,6 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
 
                conf.dst_addr = espi->sspdr_phys;
                conf.dst_addr_width = buswidth;
-               slave_dirn = DMA_MEM_TO_DEV;
        }
 
        ret = dmaengine_slave_config(chan, &conf);
@@ -632,8 +628,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
        if (!nents)
                return ERR_PTR(-ENOMEM);
 
-       txd = chan->device->device_prep_slave_sg(chan, sgt->sgl, nents,
-                                                slave_dirn, DMA_CTRL_ACK);
+       txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, dir, DMA_CTRL_ACK);
        if (!txd) {
                dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir);
                return ERR_PTR(-ENOMEM);
@@ -650,12 +645,12 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_data_direction dir)
  * unmapped.
  */
 static void ep93xx_spi_dma_finish(struct ep93xx_spi *espi,
-                                 enum dma_data_direction dir)
+                                 enum dma_transfer_direction dir)
 {
        struct dma_chan *chan;
        struct sg_table *sgt;
 
-       if (dir == DMA_FROM_DEVICE) {
+       if (dir == DMA_DEV_TO_MEM) {
                chan = espi->dma_rx;
                sgt = &espi->rx_sgt;
        } else {
@@ -676,16 +671,16 @@ static void ep93xx_spi_dma_transfer(struct ep93xx_spi *espi)
        struct spi_message *msg = espi->current_msg;
        struct dma_async_tx_descriptor *rxd, *txd;
 
-       rxd = ep93xx_spi_dma_prepare(espi, DMA_FROM_DEVICE);
+       rxd = ep93xx_spi_dma_prepare(espi, DMA_DEV_TO_MEM);
        if (IS_ERR(rxd)) {
                dev_err(&espi->pdev->dev, "DMA RX failed: %ld\n", PTR_ERR(rxd));
                msg->status = PTR_ERR(rxd);
                return;
        }
 
-       txd = ep93xx_spi_dma_prepare(espi, DMA_TO_DEVICE);
+       txd = ep93xx_spi_dma_prepare(espi, DMA_MEM_TO_DEV);
        if (IS_ERR(txd)) {
-               ep93xx_spi_dma_finish(espi, DMA_FROM_DEVICE);
+               ep93xx_spi_dma_finish(espi, DMA_DEV_TO_MEM);
                dev_err(&espi->pdev->dev, "DMA TX failed: %ld\n", PTR_ERR(rxd));
                msg->status = PTR_ERR(txd);
                return;
@@ -704,8 +699,8 @@ static void ep93xx_spi_dma_transfer(struct ep93xx_spi *espi)
 
        wait_for_completion(&espi->wait);
 
-       ep93xx_spi_dma_finish(espi, DMA_TO_DEVICE);
-       ep93xx_spi_dma_finish(espi, DMA_FROM_DEVICE);
+       ep93xx_spi_dma_finish(espi, DMA_MEM_TO_DEV);
+       ep93xx_spi_dma_finish(espi, DMA_DEV_TO_MEM);
 }
 
 /**
@@ -1028,12 +1023,13 @@ static void ep93xx_spi_release_dma(struct ep93xx_spi *espi)
                free_page((unsigned long)espi->zeropage);
 }
 
-static int __init ep93xx_spi_probe(struct platform_device *pdev)
+static int ep93xx_spi_probe(struct platform_device *pdev)
 {
        struct spi_master *master;
        struct ep93xx_spi_info *info;
        struct ep93xx_spi *espi;
        struct resource *res;
+       int irq;
        int error;
 
        info = pdev->dev.platform_data;
@@ -1073,8 +1069,8 @@ static int __init ep93xx_spi_probe(struct platform_device *pdev)
        espi->min_rate = clk_get_rate(espi->clk) / (254 * 256);
        espi->pdev = pdev;
 
-       espi->irq = platform_get_irq(pdev, 0);
-       if (espi->irq < 0) {
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
                error = -EBUSY;
                dev_err(&pdev->dev, "failed to get irq resources\n");
                goto fail_put_clock;
@@ -1087,26 +1083,19 @@ static int __init ep93xx_spi_probe(struct platform_device *pdev)
                goto fail_put_clock;
        }
 
-       res = request_mem_region(res->start, resource_size(res), pdev->name);
-       if (!res) {
-               dev_err(&pdev->dev, "unable to request iomem resources\n");
-               error = -EBUSY;
-               goto fail_put_clock;
-       }
-
        espi->sspdr_phys = res->start + SSPDR;
-       espi->regs_base = ioremap(res->start, resource_size(res));
-       if (!espi->regs_base) {
-               dev_err(&pdev->dev, "failed to map resources\n");
-               error = -ENODEV;
-               goto fail_free_mem;
+
+       espi->regs_base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(espi->regs_base)) {
+               error = PTR_ERR(espi->regs_base);
+               goto fail_put_clock;
        }
 
-       error = request_irq(espi->irq, ep93xx_spi_interrupt, 0,
-                           "ep93xx-spi", espi);
+       error = devm_request_irq(&pdev->dev, irq, ep93xx_spi_interrupt,
+                               0, "ep93xx-spi", espi);
        if (error) {
                dev_err(&pdev->dev, "failed to request irq\n");
-               goto fail_unmap_regs;
+               goto fail_put_clock;
        }
 
        if (info->use_dma && ep93xx_spi_setup_dma(espi))
@@ -1131,7 +1120,7 @@ static int __init ep93xx_spi_probe(struct platform_device *pdev)
        }
 
        dev_info(&pdev->dev, "EP93xx SPI Controller at 0x%08lx irq %d\n",
-                (unsigned long)res->start, espi->irq);
+                (unsigned long)res->start, irq);
 
        return 0;
 
@@ -1139,11 +1128,6 @@ fail_free_queue:
        destroy_workqueue(espi->wq);
 fail_free_dma:
        ep93xx_spi_release_dma(espi);
-       free_irq(espi->irq, espi);
-fail_unmap_regs:
-       iounmap(espi->regs_base);
-fail_free_mem:
-       release_mem_region(res->start, resource_size(res));
 fail_put_clock:
        clk_put(espi->clk);
 fail_release_master:
@@ -1153,11 +1137,10 @@ fail_release_master:
        return error;
 }
 
-static int __exit ep93xx_spi_remove(struct platform_device *pdev)
+static int ep93xx_spi_remove(struct platform_device *pdev)
 {
        struct spi_master *master = platform_get_drvdata(pdev);
        struct ep93xx_spi *espi = spi_master_get_devdata(master);
-       struct resource *res;
 
        spin_lock_irq(&espi->lock);
        espi->running = false;
@@ -1183,10 +1166,6 @@ static int __exit ep93xx_spi_remove(struct platform_device *pdev)
        spin_unlock_irq(&espi->lock);
 
        ep93xx_spi_release_dma(espi);
-       free_irq(espi->irq, espi);
-       iounmap(espi->regs_base);
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       release_mem_region(res->start, resource_size(res));
        clk_put(espi->clk);
        platform_set_drvdata(pdev, NULL);
 
@@ -1199,20 +1178,10 @@ static struct platform_driver ep93xx_spi_driver = {
                .name   = "ep93xx-spi",
                .owner  = THIS_MODULE,
        },
-       .remove         = __exit_p(ep93xx_spi_remove),
+       .probe          = ep93xx_spi_probe,
+       .remove         = ep93xx_spi_remove,
 };
-
-static int __init ep93xx_spi_init(void)
-{
-       return platform_driver_probe(&ep93xx_spi_driver, ep93xx_spi_probe);
-}
-module_init(ep93xx_spi_init);
-
-static void __exit ep93xx_spi_exit(void)
-{
-       platform_driver_unregister(&ep93xx_spi_driver);
-}
-module_exit(ep93xx_spi_exit);
+module_platform_driver(ep93xx_spi_driver);
 
 MODULE_DESCRIPTION("EP93xx SPI Controller driver");
 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@iki.fi>");