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

2010-10-12 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 mingkai...@freescale.com
---
v4:
 - Updated to latest kernel base(Linux 2.6.36-rc7).

 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 avoront...@ru.mvista.com
+ *
+ * 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 linux/kernel.h
+#include linux/interrupt.h
+#include linux/fsl_devices.h
+#include linux/dma-mapping.h
+#include linux/mm.h
+#include linux/of_platform.h
+#include linux/of_spi.h
+#include sysdev/fsl_soc.h
+
+#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,
+   

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

2010-10-12 Thread Grant Likely
On Tue, Oct 12, 2010 at 06:18:31PM +0800, Mingkai Hu wrote:
 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 mingkai...@freescale.com

Applied, thanks.

g.

 ---
 v4:
  - Updated to latest kernel base(Linux 2.6.36-rc7).
 
  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 avoront...@ru.mvista.com
 + *
 + * 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 linux/kernel.h
 +#include linux/interrupt.h
 +#include linux/fsl_devices.h
 +#include linux/dma-mapping.h
 +#include linux/mm.h
 +#include linux/of_platform.h
 +#include linux/of_spi.h
 +#include sysdev/fsl_soc.h
 +
 +#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);
 +
 +