Skip to contentSkip to conversation

mpc52xx_psc_spi: Convert to cs_control callback

PATCH In review Anton Vorontsov 3 participants 3 messages Apr 30, 2009 – May 22, 2009 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mpc52xx_psc_spi: Convert to cs_control callback

mpc52xx_psc_spi driver is the last user of the legacy activate_cs and deactivate_cs callbacks, so convert the driver to the cs_control hook and remove the legacy callbacks from fsl_spi_platform_data struct.

---
 drivers/spi/mpc52xx_psc_spi.c |   22 +++++++++-------------
 include/linux/fsl_devices.h   |    4 ----
 2 files changed, 9 insertions(+), 17 deletions(-)
drivers/spi/mpc52xx_psc_spi.c +9 -13
index 68c77a9..e1901fd 100644
@@ -13,6 +13,7 @@
 
 #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>
@@ -30,8 +31,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 +111,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)
@@ -388,15 +386,13 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
 	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;
include/linux/fsl_devices.h +0 -4
index 244677c..43fc95d 100644
@@ -79,10 +79,6 @@ struct fsl_spi_platform_data {
 	u16	max_chipselect;
 	void	(*cs_control)(struct spi_device *spi, bool on);
 	u32	sysclk;
-
-	/* Legacy hooks, used by mpc52xx_psc_spi driver. */
-	void	(*activate_cs)(u8 cs, u8 polarity);
-	void	(*deactivate_cs)(u8 cs, u8 polarity);
 };
 
 struct mpc8xx_pcmcia_ops {
Signature · 1 line
1.6.2.2
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Anton Vorontsov

mpc52xx_psc_spi driver is the last user of the legacy activate_cs and deactivate_cs callbacks, so convert the driver to the cs_control hook and remove the legacy callbacks from fsl_spi_platform_data struct.

David, will you pick this one up, or can I put it into Ben's powerpc -next tree (since it is a powerpc-only device driver).

g.

Quoted 87 lines

---
 drivers/spi/mpc52xx_psc_spi.c |   22 +++++++++------------- include/linux/fsl_devices.h   |    4 ----

 2 files changed, 9 insertions(+), 17 deletions(-)
drivers/spi/mpc52xx_psc_spi.c +6 -8
index 68c77a9..e1901fd 100644
@@ -13,6 +13,7 @@
 
  #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>
@@ -30,8 +31,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 +111,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)
@@ -388,15 +386,13 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
        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;

include/linux/fsl_devices.h +0 -5
index 244677c..43fc95d 100644
@@ -79,10 +79,6 @@ struct fsl_spi_platform_data {
        u16     max_chipselect;
        void    (*cs_control)(struct spi_device *spi, bool on);
        u32     sysclk;
-
-       /* Legacy hooks, used by mpc52xx_psc_spi driver. */
-       void    (*activate_cs)(u8 cs, u8 polarity);
-       void    (*deactivate_cs)(u8 cs, u8 polarity);
  };
 
  struct mpc8xx_pcmcia_ops {
--

1.6.2.2

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#2 lore raw
In reply to Anton Vorontsov
Quoted 2 lines · Anton Vorontsov

mpc52xx_psc_spi driver is the last user of the legacy activate_cs and deactivate_cs callbacks, so convert the driver to the cs_control

This driver is missing a call to of_register_spi_devices(master, op->node);

Here's how I added it, but it could be done more cleanly.

drivers/spi/mpc52xx_psc_spi.c +1 -0
index 68c77a9..fe0658a 100644
@@ -22,6 +22,7 @@
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_spi.h>
 
 #include <asm/mpc52xx.h>
 #include <asm/mpc52xx_psc.h>
@@ -370,24 +371,24 @@ static irqreturn_t mpc52xx_psc_spi_isr(int irq,

void *dev_id)
}

/* bus_num is used only for the case dev->platform_data == NULL */
-static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, +static int __init mpc52xx_psc_spi_do_probe(struct of_device *op, u32 regaddr,
u32 size, unsigned int irq, s16 bus_num)
{
- struct fsl_spi_platform_data *pdata = dev->platform_data;
+ struct fsl_spi_platform_data *pdata = op->dev.platform_data;
struct mpc52xx_psc_spi *mps;
struct spi_master *master;
int ret;

- master = spi_alloc_master(dev, sizeof *mps);
+ master = spi_alloc_master(&op->dev, sizeof *mps);
if (master == NULL)
return -ENOMEM;

- dev_set_drvdata(dev, master);
+ dev_set_drvdata(&op->dev, master);
mps = spi_master_get_devdata(master);

mps->irq = irq;
if (pdata == NULL) {
- dev_warn(dev, "probe called without platform data, no "
+ dev_warn(&op->dev, "probe called without platform data, no "
"(de)activate_cs function will be called\n");
mps->activate_cs = NULL;
mps->deactivate_cs = NULL;
@@ -407,7 +408,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,

mps->psc = ioremap(regaddr, size);
if (!mps->psc) {
- dev_err(dev, "could not ioremap I/O port range\n");
+ dev_err(&op->dev, "could not ioremap I/O port range\n");
ret = -EFAULT;
goto free_master;
}
@@ -439,6 +440,8 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
if (ret < 0)
goto unreg_master;

+ of_register_spi_devices(master, op->node);
+
return ret;

unreg_master:
@@ -495,7 +498,7 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
id = *psc_nump + 1;
}

- return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
+ return mpc52xx_psc_spi_do_probe(op, (u32)regaddr64, (u32)size64,
irq_of_parse_and_map(op->node, 0), id);
}

Signature · 2 lines
Jon Smirl
[email protected]