Merge remote-tracking branch 'spi/topic/rspi' into spi-pdata
[deliverable/linux.git] / drivers / spi / spi-xilinx.c
index 038e59a8bf0a67abc0bc8d5be3ec73464e00e075..08ea84a6eb3283418484d4012298271ec6ab77ae 100644 (file)
@@ -80,10 +80,9 @@ struct xilinx_spi {
        /* bitbang has to be first */
        struct spi_bitbang bitbang;
        struct completion done;
-       struct resource mem; /* phys mem */
        void __iomem    *regs;  /* virt. address of the control registers */
 
-       u32             irq;
+       int             irq;
 
        u8 *rx_ptr;             /* pointer in the Tx buffer */
        const u8 *tx_ptr;       /* pointer in the Rx buffer */
@@ -233,6 +232,21 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
        return 0;
 }
 
+static int xilinx_spi_setup(struct spi_device *spi)
+{
+       /* always return 0, we can not check the number of bits.
+        * There are cases when SPI setup is called before any driver is
+        * there, in that case the SPI core defaults to 8 bits, which we
+        * do not support in some cases. But if we return an error, the
+        * SPI device would not be registered and no driver can get hold of it
+        * When the driver is there, it will call SPI setup again with the
+        * correct number of bits per transfer.
+        * If a driver setups with the wrong bit number, it will fail when
+        * it tries to do a transfer
+        */
+       return 0;
+}
+
 static void xilinx_spi_fill_tx_fifo(struct xilinx_spi *xspi)
 {
        u8 sr;
@@ -340,49 +354,32 @@ static const struct of_device_id xilinx_spi_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
 
-static int xilinx_spi_probe(struct platform_device *dev)
+static int xilinx_spi_probe(struct platform_device *pdev)
 {
        struct xilinx_spi *xspi;
        struct xspi_platform_data *pdata;
-       struct resource *r;
-       int ret, irq, num_cs = 0, bits_per_word = 8;
+       struct resource *res;
+       int ret, num_cs = 0, bits_per_word = 8;
        struct spi_master *master;
        u32 tmp;
        u8 i;
 
-       pdata = dev->dev.platform_data;
+       pdata = dev_get_platdata(&pdev->dev);
        if (pdata) {
                num_cs = pdata->num_chipselect;
                bits_per_word = pdata->bits_per_word;
+       } else {
+               of_property_read_u32(pdev->dev.of_node, "xlnx,num-ss-bits",
+                                         &num_cs);
        }
 
-#ifdef CONFIG_OF
-       if (dev->dev.of_node) {
-               const __be32 *prop;
-               int len;
-
-               /* number of slave select bits is required */
-               prop = of_get_property(dev->dev.of_node, "xlnx,num-ss-bits",
-                                      &len);
-               if (prop && len >= sizeof(*prop))
-                       num_cs = __be32_to_cpup(prop);
-       }
-#endif
-
        if (!num_cs) {
-               dev_err(&dev->dev, "Missing slave select configuration data\n");
+               dev_err(&pdev->dev,
+                       "Missing slave select configuration data\n");
                return -EINVAL;
        }
 
-       r = platform_get_resource(dev, IORESOURCE_MEM, 0);
-       if (!r)
-               return -ENODEV;
-
-       irq = platform_get_irq(dev, 0);
-       if (irq < 0)
-               return -ENXIO;
-
-       master = spi_alloc_master(&dev->dev, sizeof(struct xilinx_spi));
+       master = spi_alloc_master(&pdev->dev, sizeof(struct xilinx_spi));
        if (!master)
                return -ENODEV;
 
@@ -394,20 +391,19 @@ static int xilinx_spi_probe(struct platform_device *dev)
        xspi->bitbang.chipselect = xilinx_spi_chipselect;
        xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer;
        xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs;
+       xspi->bitbang.master->setup = xilinx_spi_setup;
        init_completion(&xspi->done);
 
-       xspi->regs = devm_ioremap_resource(&dev->dev, r);
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       xspi->regs = devm_ioremap_resource(&pdev->dev, res);
        if (IS_ERR(xspi->regs)) {
                ret = PTR_ERR(xspi->regs);
                goto put_master;
        }
 
-       master->bus_num = dev->dev.id;
+       master->bus_num = pdev->dev.id;
        master->num_chipselect = num_cs;
-       master->dev.of_node = dev->dev.of_node;
-
-       xspi->mem = *r;
-       xspi->irq = irq;
+       master->dev.of_node = pdev->dev.of_node;
 
        /*
         * Detect endianess on the IP via loop bit in CR. Detection
@@ -442,47 +438,56 @@ static int xilinx_spi_probe(struct platform_device *dev)
                goto put_master;
        }
 
-
        /* SPI controller initializations */
        xspi_init_hw(xspi);
 
+       xspi->irq = platform_get_irq(pdev, 0);
+       if (xspi->irq < 0) {
+               ret = xspi->irq;
+               goto put_master;
+       }
+
        /* Register for SPI Interrupt */
-       ret = request_irq(xspi->irq, xilinx_spi_irq, 0, XILINX_SPI_NAME, xspi);
+       ret = devm_request_irq(&pdev->dev, xspi->irq, xilinx_spi_irq, 0,
+                              dev_name(&pdev->dev), xspi);
        if (ret)
                goto put_master;
 
        ret = spi_bitbang_start(&xspi->bitbang);
        if (ret) {
-               dev_err(&dev->dev, "spi_bitbang_start FAILED\n");
-               goto free_irq;
+               dev_err(&pdev->dev, "spi_bitbang_start FAILED\n");
+               goto put_master;
        }
 
-       dev_info(&dev->dev, "at 0x%08llX mapped to 0x%p, irq=%d\n",
-               (unsigned long long)r->start, xspi->regs, xspi->irq);
+       dev_info(&pdev->dev, "at 0x%08llX mapped to 0x%p, irq=%d\n",
+               (unsigned long long)res->start, xspi->regs, xspi->irq);
 
        if (pdata) {
                for (i = 0; i < pdata->num_devices; i++)
                        spi_new_device(master, pdata->devices + i);
        }
 
-       platform_set_drvdata(dev, master);
+       platform_set_drvdata(pdev, master);
        return 0;
 
-free_irq:
-       free_irq(xspi->irq, xspi);
 put_master:
        spi_master_put(master);
 
        return ret;
 }
 
-static int xilinx_spi_remove(struct platform_device *dev)
+static int xilinx_spi_remove(struct platform_device *pdev)
 {
-       struct spi_master *master = platform_get_drvdata(dev);
+       struct spi_master *master = platform_get_drvdata(pdev);
        struct xilinx_spi *xspi = spi_master_get_devdata(master);
+       void __iomem *regs_base = xspi->regs;
 
        spi_bitbang_stop(&xspi->bitbang);
-       free_irq(xspi->irq, xspi);
+
+       /* Disable all the interrupts just in case */
+       xspi->write_fn(0, regs_base + XIPIF_V123B_IIER_OFFSET);
+       /* Disable the global IPIF interrupt */
+       xspi->write_fn(0, regs_base + XIPIF_V123B_DGIER_OFFSET);
 
        spi_master_put(xspi->bitbang.master);
 
This page took 0.026018 seconds and 5 git commands to generate.