RE: [PATCH v3 2/7] spi/mpc8xxx: refactor the common code for SPI/eSPI controller

2010-10-07 Thread Hu Mingkai-B21284


> -Original Message-
> From: Anton Vorontsov [mailto:cbouatmai...@gmail.com]
> Sent: Friday, October 01, 2010 7:22 PM
> To: Hu Mingkai-B21284
> Cc: linuxppc-...@ozlabs.org; spi-devel-gene...@lists.sourceforge.net; linux-
> m...@lists.infradead.org; Gala Kumar-B11780; Zang Roy-R61911
> Subject: Re: [PATCH v3 2/7] spi/mpc8xxx: refactor the common code for SPI/eSPI
> controller
> 
> On Thu, Sep 30, 2010 at 04:00:41PM +0800, Mingkai Hu wrote:
> [...]
> > -static void mpc8xxx_spi_change_mode(struct spi_device *spi)
> > +static void fsl_spi_change_mode(struct spi_device *spi)
> >  {
> > struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
> > struct spi_mpc8xxx_cs *cs = spi->controller_state;
> > -   __be32 __iomem *mode = &mspi->base->mode;
> > +   struct fsl_spi_reg *reg_base = (struct fsl_spi_reg *)mspi->reg_base;
> 
> No need for these type casts (the same is for the whole patch).
> 

Fix it.

Thanks,
Mingkai
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v3 2/7] spi/mpc8xxx: refactor the common code for SPI/eSPI controller

2010-10-01 Thread Anton Vorontsov
On Thu, Sep 30, 2010 at 04:00:41PM +0800, Mingkai Hu wrote:
[...]
> -static void mpc8xxx_spi_change_mode(struct spi_device *spi)
> +static void fsl_spi_change_mode(struct spi_device *spi)
>  {
>   struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
>   struct spi_mpc8xxx_cs *cs = spi->controller_state;
> - __be32 __iomem *mode = &mspi->base->mode;
> + struct fsl_spi_reg *reg_base = (struct fsl_spi_reg *)mspi->reg_base;

No need for these type casts (the same is for the whole patch).

-- 
Anton Vorontsov
email: cbouatmai...@gmail.com
irc://irc.freenode.net/bd2
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v3 2/7] spi/mpc8xxx: refactor the common code for SPI/eSPI controller

2010-09-30 Thread Mingkai Hu
Refactor the common code in file spi_fsl_spi.c to spi_fsl_lib.c used
by SPI/eSPI controller driver as a library, and leave the QE/CPM SPI
controller code in the SPI controller driver spi_fsl_spi.c.

Because the register map of the SPI controller and eSPI controller
is so different, also leave the code operated the register to the
driver code, not the common code.

Signed-off-by: Mingkai Hu 
---

v3:
 - Update to the latest kernel base.
 - Add a void *reg_base to compatible for SPI and eSPI register base.

 drivers/spi/Kconfig   |5 +
 drivers/spi/Makefile  |1 +
 drivers/spi/spi_fsl_lib.c |  237 +++
 drivers/spi/spi_fsl_lib.h |  119 ++
 drivers/spi/spi_fsl_spi.c |  552 +
 5 files changed, 522 insertions(+), 392 deletions(-)
 create mode 100644 drivers/spi/spi_fsl_lib.c
 create mode 100644 drivers/spi/spi_fsl_lib.h

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 6af34c6..79ad06f 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -182,9 +182,14 @@ config SPI_MPC512x_PSC
  This enables using the Freescale MPC5121 Programmable Serial
  Controller in SPI master mode.
 
+config SPI_FSL_LIB
+   tristate
+   depends on FSL_SOC
+
 config SPI_FSL_SPI
tristate "Freescale SPI controller"
depends on FSL_SOC
+   select SPI_FSL_LIB
help
  This enables using the Freescale SPI controllers in master mode.
  MPC83xx platform uses the controller in cpu mode or CPM/QE mode.
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 770817c..7974c21 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_SPI_PL022)   += amba-pl022.o
 obj-$(CONFIG_SPI_MPC512x_PSC)  += mpc512x_psc_spi.o
 obj-$(CONFIG_SPI_MPC52xx_PSC)  += mpc52xx_psc_spi.o
 obj-$(CONFIG_SPI_MPC52xx)  += mpc52xx_spi.o
+obj-$(CONFIG_SPI_FSL_LIB)  += spi_fsl_lib.o
 obj-$(CONFIG_SPI_FSL_SPI)  += spi_fsl_spi.o
 obj-$(CONFIG_SPI_PPC4xx)   += spi_ppc4xx.o
 obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
diff --git a/drivers/spi/spi_fsl_lib.c b/drivers/spi/spi_fsl_lib.c
new file mode 100644
index 000..5cd741f
--- /dev/null
+++ b/drivers/spi/spi_fsl_lib.c
@@ -0,0 +1,237 @@
+/*
+ * Freescale SPI/eSPI controller driver library.
+ *
+ * Maintainer: Kumar Gala
+ *
+ * Copyright (C) 2006 Polycom, Inc.
+ *
+ * CPM SPI and QE buffer descriptors mode support:
+ * Copyright (c) 2009  MontaVista Software, Inc.
+ * Author: Anton Vorontsov 
+ *
+ * Copyright 2010 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "spi_fsl_lib.h"
+
+#define MPC8XXX_SPI_RX_BUF(type) \
+void mpc8xxx_spi_rx_buf_##type(u32 data, struct mpc8xxx_spi *mpc8xxx_spi) \
+{\
+   type *rx = mpc8xxx_spi->rx;   \
+   *rx++ = (type)(data >> mpc8xxx_spi->rx_shift);\
+   mpc8xxx_spi->rx = rx; \
+}
+
+#define MPC8XXX_SPI_TX_BUF(type)   \
+u32 mpc8xxx_spi_tx_buf_##type(struct mpc8xxx_spi *mpc8xxx_spi) \
+{  \
+   u32 data;   \
+   const type *tx = mpc8xxx_spi->tx;   \
+   if (!tx)\
+   return 0;   \
+   data = *tx++ << mpc8xxx_spi->tx_shift;  \
+   mpc8xxx_spi->tx = tx;   \
+   return data;\
+}
+
+MPC8XXX_SPI_RX_BUF(u8)
+MPC8XXX_SPI_RX_BUF(u16)
+MPC8XXX_SPI_RX_BUF(u32)
+MPC8XXX_SPI_TX_BUF(u8)
+MPC8XXX_SPI_TX_BUF(u16)
+MPC8XXX_SPI_TX_BUF(u32)
+
+struct mpc8xxx_spi_probe_info *to_of_pinfo(struct fsl_spi_platform_data *pdata)
+{
+   return container_of(pdata, struct mpc8xxx_spi_probe_info, pdata);
+}
+
+void mpc8xxx_spi_work(struct work_struct *work)
+{
+   struct mpc8xxx_spi *mpc8xxx_spi = container_of(work, struct mpc8xxx_spi,
+  work);
+
+   spin_lock_irq(&mpc8xxx_spi->lock);
+   while (!list_empty(&mpc8xxx_spi->queue)) {
+   struct spi_message *m = container_of(mpc8xxx_spi->queue.next,
+  struct spi_message, queue);
+
+   list_del_init(&m->queue);
+