]> Pileus Git - ~andy/linux/blobdiff - drivers/spi/mpc52xx_psc_spi.c
Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[~andy/linux] / drivers / spi / mpc52xx_psc_spi.c
index 68c77a9115956cad8e57eb92bde8a1a03ae68a3d..f50c81df336a7831a76cdc85f92a1f3c2a7b7527 100644 (file)
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/of_platform.h>
+#include <linux/of_spi.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
 #include <linux/io.h>
@@ -30,8 +32,7 @@
 
 struct mpc52xx_psc_spi {
        /* fsl_spi_platform data */
-       void (*activate_cs)(u8, u8);
-       void (*deactivate_cs)(u8, u8);
+       void (*cs_control)(struct spi_device *spi, bool on);
        u32 sysclk;
 
        /* driver internal data */
@@ -111,18 +112,16 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
        out_be16((u16 __iomem *)&psc->ccr, ccr);
        mps->bits_per_word = cs->bits_per_word;
 
-       if (mps->activate_cs)
-               mps->activate_cs(spi->chip_select,
-                               (spi->mode & SPI_CS_HIGH) ? 1 : 0);
+       if (mps->cs_control)
+               mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0);
 }
 
 static void mpc52xx_psc_spi_deactivate_cs(struct spi_device *spi)
 {
        struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
 
-       if (mps->deactivate_cs)
-               mps->deactivate_cs(spi->chip_select,
-                               (spi->mode & SPI_CS_HIGH) ? 1 : 0);
+       if (mps->cs_control)
+               mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1);
 }
 
 #define MPC52xx_PSC_BUFSIZE (MPC52xx_PSC_RFNUM_MASK + 1)
@@ -261,9 +260,6 @@ static void mpc52xx_psc_spi_work(struct work_struct *work)
        spin_unlock_irq(&mps->lock);
 }
 
-/* the spi->mode bits understood by this driver: */
-#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST)
-
 static int mpc52xx_psc_spi_setup(struct spi_device *spi)
 {
        struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
@@ -273,12 +269,6 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi)
        if (spi->bits_per_word%8)
                return -EINVAL;
 
-       if (spi->mode & ~MODEBITS) {
-               dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
-                       spi->mode & ~MODEBITS);
-               return -EINVAL;
-       }
-
        if (!cs) {
                cs = kzalloc(sizeof *cs, GFP_KERNEL);
                if (!cs)
@@ -324,11 +314,13 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
        struct mpc52xx_psc __iomem *psc = mps->psc;
        struct mpc52xx_psc_fifo __iomem *fifo = mps->fifo;
        u32 mclken_div;
-       int ret = 0;
+       int ret;
 
        /* default sysclk is 512MHz */
        mclken_div = (mps->sysclk ? mps->sysclk : 512000000) / MCLK;
-       mpc52xx_set_psc_clkdiv(psc_id, mclken_div);
+       ret = mpc52xx_set_psc_clkdiv(psc_id, mclken_div);
+       if (ret)
+               return ret;
 
        /* Reset the PSC into a known state */
        out_8(&psc->command, MPC52xx_PSC_RST_RX);
@@ -352,7 +344,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
 
        mps->bits_per_word = 8;
 
-       return ret;
+       return 0;
 }
 
 static irqreturn_t mpc52xx_psc_spi_isr(int irq, void *dev_id)
@@ -385,18 +377,19 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
        dev_set_drvdata(dev, master);
        mps = spi_master_get_devdata(master);
 
+       /* the spi->mode bits understood by this driver: */
+       master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
+
        mps->irq = irq;
        if (pdata == NULL) {
                dev_warn(dev, "probe called without platform data, no "
-                               "(de)activate_cs function will be called\n");
-               mps->activate_cs = NULL;
-               mps->deactivate_cs = NULL;
+                               "cs_control function will be called\n");
+               mps->cs_control = NULL;
                mps->sysclk = 0;
                master->bus_num = bus_num;
                master->num_chipselect = 255;
        } else {
-               mps->activate_cs = pdata->activate_cs;
-               mps->deactivate_cs = pdata->deactivate_cs;
+               mps->cs_control = pdata->cs_control;
                mps->sysclk = pdata->sysclk;
                master->bus_num = pdata->bus_num;
                master->num_chipselect = pdata->max_chipselect;
@@ -420,8 +413,10 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
                goto free_master;
 
        ret = mpc52xx_psc_spi_port_config(master->bus_num, mps);
-       if (ret < 0)
+       if (ret < 0) {
+               dev_err(dev, "can't configure PSC! Is it capable of SPI?\n");
                goto free_irq;
+       }
 
        spin_lock_init(&mps->lock);
        init_completion(&mps->done);
@@ -474,10 +469,11 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
        const u32 *regaddr_p;
        u64 regaddr64, size64;
        s16 id = -1;
+       int rc;
 
        regaddr_p = of_get_address(op->node, 0, &size64, NULL);
        if (!regaddr_p) {
-               printk(KERN_ERR "Invalid PSC address\n");
+               dev_err(&op->dev, "Invalid PSC address\n");
                return -EINVAL;
        }
        regaddr64 = of_translate_address(op->node, regaddr_p);
@@ -488,15 +484,18 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
 
                psc_nump = of_get_property(op->node, "cell-index", NULL);
                if (!psc_nump || *psc_nump > 5) {
-                       printk(KERN_ERR "mpc52xx_psc_spi: Device node %s has invalid "
-                                       "cell-index property\n", op->node->full_name);
+                       dev_err(&op->dev, "Invalid cell-index property\n");
                        return -EINVAL;
                }
                id = *psc_nump + 1;
        }
 
-       return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+       rc = mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
                                        irq_of_parse_and_map(op->node, 0), id);
+       if (rc == 0)
+               of_register_spi_devices(dev_get_drvdata(&op->dev), op->node);
+
+       return rc;
 }
 
 static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)