linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] Add device tree support for imx spi driver
@ 2011-07-09 17:16 Shawn Guo
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	patches-QSEj5FYQhm4dnm+yROfE0A

The patch set makes some cleanups on imx spi driver to get it ready
for adding device tree probe and then add the support.

Changes since v1:
 * Split the big patch into small ones per Sascha's comment
 * Drop the patch cleaning mxc/mach/gpio.h from the series.  Will
   post it separately later.
 * Drop dt helper patches, as they are on Grant's tree

Shawn Guo (7):
      spi/imx: do not make copy of spi_imx_devtype_data
      spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro
      spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 function and macro
      spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4
      spi/imx: use soc name in spi device type naming scheme
      spi/imx: copy gpio number passed by platform data into driver private data
      spi/imx: add device tree probe support

 .../devicetree/bindings/spi/fsl-imx-cspi.txt       |   22 +
 arch/arm/mach-imx/clock-imx25.c                    |    7 +-
 arch/arm/mach-mx5/clock-mx51-mx53.c                |   11 +-
 arch/arm/plat-mxc/devices/platform-spi_imx.c       |   12 +-
 drivers/spi/Kconfig                                |   15 -
 drivers/spi/spi-imx.c                              |  468 ++++++++++----------
 6 files changed, 277 insertions(+), 258 deletions(-)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-09 17:16   ` Shawn Guo
  2011-07-11  7:15     ` Lothar Waßmann
       [not found]     ` <1310231801-18761-2-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro Shawn Guo
                     ` (5 subsequent siblings)
  6 siblings, 2 replies; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

spi_imx_devtype_data has already been driver private data.  There is
really no need to make a copy in spi_imx_data.  Instead, a reference
pointer works perfectly fine.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/spi/spi-imx.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 69d6dba..1c55dc9 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -96,7 +96,7 @@ struct spi_imx_data {
 	const void *tx_buf;
 	unsigned int txfifo; /* number of words pushed in tx FIFO */
 
-	struct spi_imx_devtype_data devtype_data;
+	struct spi_imx_devtype_data *devtype_data;
 };
 
 #define MXC_SPI_BUF_RX(type)						\
@@ -539,7 +539,7 @@ static void __maybe_unused mx1_reset(struct spi_imx_data *spi_imx)
  * These version numbers are taken from the Freescale driver.  Unfortunately it
  * doesn't support i.MX1, so this entry doesn't match the scheme. :-(
  */
-static struct spi_imx_devtype_data spi_imx_devtype_data[] __devinitdata = {
+static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
 #ifdef CONFIG_SPI_IMX_VER_IMX1
 	[SPI_IMX_VER_IMX1] = {
 		.intctrl = mx1_intctrl,
@@ -607,21 +607,21 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active)
 
 static void spi_imx_push(struct spi_imx_data *spi_imx)
 {
-	while (spi_imx->txfifo < spi_imx->devtype_data.fifosize) {
+	while (spi_imx->txfifo < spi_imx->devtype_data->fifosize) {
 		if (!spi_imx->count)
 			break;
 		spi_imx->tx(spi_imx);
 		spi_imx->txfifo++;
 	}
 
-	spi_imx->devtype_data.trigger(spi_imx);
+	spi_imx->devtype_data->trigger(spi_imx);
 }
 
 static irqreturn_t spi_imx_isr(int irq, void *dev_id)
 {
 	struct spi_imx_data *spi_imx = dev_id;
 
-	while (spi_imx->devtype_data.rx_available(spi_imx)) {
+	while (spi_imx->devtype_data->rx_available(spi_imx)) {
 		spi_imx->rx(spi_imx);
 		spi_imx->txfifo--;
 	}
@@ -635,12 +635,12 @@ static irqreturn_t spi_imx_isr(int irq, void *dev_id)
 		/* No data left to push, but still waiting for rx data,
 		 * enable receive data available interrupt.
 		 */
-		spi_imx->devtype_data.intctrl(
+		spi_imx->devtype_data->intctrl(
 				spi_imx, MXC_INT_RR);
 		return IRQ_HANDLED;
 	}
 
-	spi_imx->devtype_data.intctrl(spi_imx, 0);
+	spi_imx->devtype_data->intctrl(spi_imx, 0);
 	complete(&spi_imx->xfer_done);
 
 	return IRQ_HANDLED;
@@ -677,7 +677,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
 	} else
 		BUG();
 
-	spi_imx->devtype_data.config(spi_imx, &config);
+	spi_imx->devtype_data->config(spi_imx, &config);
 
 	return 0;
 }
@@ -696,7 +696,7 @@ static int spi_imx_transfer(struct spi_device *spi,
 
 	spi_imx_push(spi_imx);
 
-	spi_imx->devtype_data.intctrl(spi_imx, MXC_INT_TE);
+	spi_imx->devtype_data->intctrl(spi_imx, MXC_INT_TE);
 
 	wait_for_completion(&spi_imx->xfer_done);
 
@@ -811,7 +811,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 	init_completion(&spi_imx->xfer_done);
 
 	spi_imx->devtype_data =
-		spi_imx_devtype_data[pdev->id_entry->driver_data];
+		&spi_imx_devtype_data[pdev->id_entry->driver_data];
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
@@ -854,9 +854,9 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 	clk_enable(spi_imx->clk);
 	spi_imx->spi_clk = clk_get_rate(spi_imx->clk);
 
-	spi_imx->devtype_data.reset(spi_imx);
+	spi_imx->devtype_data->reset(spi_imx);
 
-	spi_imx->devtype_data.intctrl(spi_imx, 0);
+	spi_imx->devtype_data->intctrl(spi_imx, 0);
 
 	ret = spi_bitbang_start(&spi_imx->bitbang);
 	if (ret) {
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-3-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 3/7] spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 " Shawn Guo
                     ` (4 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

SPI_IMX_VER_0_0 covers i.mx21 and i.mx27.  It makes more sense to
use mx21 rather than mx27 to name SPI_IMX_VER_0_0 function and
macro, since i.mx21 comes out ealier than i.mx27.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/spi/spi-imx.c |   67 +++++++++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 1c55dc9..ad928b1 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -406,70 +406,71 @@ static void __maybe_unused spi_imx0_4_reset(struct spi_imx_data *spi_imx)
 		readl(spi_imx->base + MXC_CSPIRXDATA);
 }
 
-#define MX27_INTREG_RR		(1 << 4)
-#define MX27_INTREG_TEEN	(1 << 9)
-#define MX27_INTREG_RREN	(1 << 13)
-
-#define MX27_CSPICTRL_POL	(1 << 5)
-#define MX27_CSPICTRL_PHA	(1 << 6)
-#define MX27_CSPICTRL_SSPOL	(1 << 8)
-#define MX27_CSPICTRL_XCH	(1 << 9)
-#define MX27_CSPICTRL_ENABLE	(1 << 10)
-#define MX27_CSPICTRL_MASTER	(1 << 11)
-#define MX27_CSPICTRL_DR_SHIFT	14
-#define MX27_CSPICTRL_CS_SHIFT	19
-
-static void __maybe_unused mx27_intctrl(struct spi_imx_data *spi_imx, int enable)
+#define MX21_INTREG_RR		(1 << 4)
+#define MX21_INTREG_TEEN	(1 << 9)
+#define MX21_INTREG_RREN	(1 << 13)
+
+#define MX21_CSPICTRL_POL	(1 << 5)
+#define MX21_CSPICTRL_PHA	(1 << 6)
+#define MX21_CSPICTRL_SSPOL	(1 << 8)
+#define MX21_CSPICTRL_XCH	(1 << 9)
+#define MX21_CSPICTRL_ENABLE	(1 << 10)
+#define MX21_CSPICTRL_MASTER	(1 << 11)
+#define MX21_CSPICTRL_DR_SHIFT	14
+#define MX21_CSPICTRL_CS_SHIFT	19
+
+static void __maybe_unused
+mx21_intctrl(struct spi_imx_data *spi_imx, int enable)
 {
 	unsigned int val = 0;
 
 	if (enable & MXC_INT_TE)
-		val |= MX27_INTREG_TEEN;
+		val |= MX21_INTREG_TEEN;
 	if (enable & MXC_INT_RR)
-		val |= MX27_INTREG_RREN;
+		val |= MX21_INTREG_RREN;
 
 	writel(val, spi_imx->base + MXC_CSPIINT);
 }
 
-static void __maybe_unused mx27_trigger(struct spi_imx_data *spi_imx)
+static void __maybe_unused mx21_trigger(struct spi_imx_data *spi_imx)
 {
 	unsigned int reg;
 
 	reg = readl(spi_imx->base + MXC_CSPICTRL);
-	reg |= MX27_CSPICTRL_XCH;
+	reg |= MX21_CSPICTRL_XCH;
 	writel(reg, spi_imx->base + MXC_CSPICTRL);
 }
 
-static int __maybe_unused mx27_config(struct spi_imx_data *spi_imx,
+static int __maybe_unused mx21_config(struct spi_imx_data *spi_imx,
 		struct spi_imx_config *config)
 {
-	unsigned int reg = MX27_CSPICTRL_ENABLE | MX27_CSPICTRL_MASTER;
+	unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER;
 	int cs = spi_imx->chipselect[config->cs];
 
 	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
-		MX27_CSPICTRL_DR_SHIFT;
+		MX21_CSPICTRL_DR_SHIFT;
 	reg |= config->bpw - 1;
 
 	if (config->mode & SPI_CPHA)
-		reg |= MX27_CSPICTRL_PHA;
+		reg |= MX21_CSPICTRL_PHA;
 	if (config->mode & SPI_CPOL)
-		reg |= MX27_CSPICTRL_POL;
+		reg |= MX21_CSPICTRL_POL;
 	if (config->mode & SPI_CS_HIGH)
-		reg |= MX27_CSPICTRL_SSPOL;
+		reg |= MX21_CSPICTRL_SSPOL;
 	if (cs < 0)
-		reg |= (cs + 32) << MX27_CSPICTRL_CS_SHIFT;
+		reg |= (cs + 32) << MX21_CSPICTRL_CS_SHIFT;
 
 	writel(reg, spi_imx->base + MXC_CSPICTRL);
 
 	return 0;
 }
 
-static int __maybe_unused mx27_rx_available(struct spi_imx_data *spi_imx)
+static int __maybe_unused mx21_rx_available(struct spi_imx_data *spi_imx)
 {
-	return readl(spi_imx->base + MXC_CSPIINT) & MX27_INTREG_RR;
+	return readl(spi_imx->base + MXC_CSPIINT) & MX21_INTREG_RR;
 }
 
-static void __maybe_unused spi_imx0_0_reset(struct spi_imx_data *spi_imx)
+static void __maybe_unused mx21_reset(struct spi_imx_data *spi_imx)
 {
 	writel(1, spi_imx->base + MXC_RESET);
 }
@@ -552,11 +553,11 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
 #endif
 #ifdef CONFIG_SPI_IMX_VER_0_0
 	[SPI_IMX_VER_0_0] = {
-		.intctrl = mx27_intctrl,
-		.config = mx27_config,
-		.trigger = mx27_trigger,
-		.rx_available = mx27_rx_available,
-		.reset = spi_imx0_0_reset,
+		.intctrl = mx21_intctrl,
+		.config = mx21_config,
+		.trigger = mx21_trigger,
+		.rx_available = mx21_rx_available,
+		.reset = mx21_reset,
 		.fifosize = 8,
 	},
 #endif
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 3/7] spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 function and macro
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data Shawn Guo
  2011-07-09 17:16   ` [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-4-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 4/7] spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4 Shawn Guo
                     ` (3 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

It's confusing to use spi_imx2_3 to name SPI_IMX_VER_2_3 function
and macro, as it easily make people think of imx2 and imx3.  It's
better to use specific soc name just like what other SPI_IMX_VER
do.  For SPI_IMX_VER_2_3 case, it will be mx51.  To distinguish it
from CSPI on mx51, mx51_ecspi might be a good choice.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/spi/spi-imx.c |  107 +++++++++++++++++++++++++------------------------
 1 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index ad928b1..052959df 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -171,30 +171,30 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
 	return 7;
 }
 
-#define SPI_IMX2_3_CTRL		0x08
-#define SPI_IMX2_3_CTRL_ENABLE		(1 <<  0)
-#define SPI_IMX2_3_CTRL_XCH		(1 <<  2)
-#define SPI_IMX2_3_CTRL_MODE_MASK	(0xf << 4)
-#define SPI_IMX2_3_CTRL_POSTDIV_OFFSET	8
-#define SPI_IMX2_3_CTRL_PREDIV_OFFSET	12
-#define SPI_IMX2_3_CTRL_CS(cs)		((cs) << 18)
-#define SPI_IMX2_3_CTRL_BL_OFFSET	20
-
-#define SPI_IMX2_3_CONFIG	0x0c
-#define SPI_IMX2_3_CONFIG_SCLKPHA(cs)	(1 << ((cs) +  0))
-#define SPI_IMX2_3_CONFIG_SCLKPOL(cs)	(1 << ((cs) +  4))
-#define SPI_IMX2_3_CONFIG_SBBCTRL(cs)	(1 << ((cs) +  8))
-#define SPI_IMX2_3_CONFIG_SSBPOL(cs)	(1 << ((cs) + 12))
-
-#define SPI_IMX2_3_INT		0x10
-#define SPI_IMX2_3_INT_TEEN		(1 <<  0)
-#define SPI_IMX2_3_INT_RREN		(1 <<  3)
-
-#define SPI_IMX2_3_STAT		0x18
-#define SPI_IMX2_3_STAT_RR		(1 <<  3)
+#define MX51_ECSPI_CTRL		0x08
+#define MX51_ECSPI_CTRL_ENABLE		(1 <<  0)
+#define MX51_ECSPI_CTRL_XCH		(1 <<  2)
+#define MX51_ECSPI_CTRL_MODE_MASK	(0xf << 4)
+#define MX51_ECSPI_CTRL_POSTDIV_OFFSET	8
+#define MX51_ECSPI_CTRL_PREDIV_OFFSET	12
+#define MX51_ECSPI_CTRL_CS(cs)		((cs) << 18)
+#define MX51_ECSPI_CTRL_BL_OFFSET	20
+
+#define MX51_ECSPI_CONFIG	0x0c
+#define MX51_ECSPI_CONFIG_SCLKPHA(cs)	(1 << ((cs) +  0))
+#define MX51_ECSPI_CONFIG_SCLKPOL(cs)	(1 << ((cs) +  4))
+#define MX51_ECSPI_CONFIG_SBBCTRL(cs)	(1 << ((cs) +  8))
+#define MX51_ECSPI_CONFIG_SSBPOL(cs)	(1 << ((cs) + 12))
+
+#define MX51_ECSPI_INT		0x10
+#define MX51_ECSPI_INT_TEEN		(1 <<  0)
+#define MX51_ECSPI_INT_RREN		(1 <<  3)
+
+#define MX51_ECSPI_STAT		0x18
+#define MX51_ECSPI_STAT_RR		(1 <<  3)
 
 /* MX51 eCSPI */
-static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
+static unsigned int mx51_ecspi_clkdiv(unsigned int fin, unsigned int fspi)
 {
 	/*
 	 * there are two 4-bit dividers, the pre-divider divides by
@@ -222,36 +222,37 @@ static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
 
 	pr_debug("%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
 			__func__, fin, fspi, post, pre);
-	return (pre << SPI_IMX2_3_CTRL_PREDIV_OFFSET) |
-		(post << SPI_IMX2_3_CTRL_POSTDIV_OFFSET);
+	return (pre << MX51_ECSPI_CTRL_PREDIV_OFFSET) |
+		(post << MX51_ECSPI_CTRL_POSTDIV_OFFSET);
 }
 
-static void __maybe_unused spi_imx2_3_intctrl(struct spi_imx_data *spi_imx, int enable)
+static void __maybe_unused
+mx51_ecspi_intctrl(struct spi_imx_data *spi_imx, int enable)
 {
 	unsigned val = 0;
 
 	if (enable & MXC_INT_TE)
-		val |= SPI_IMX2_3_INT_TEEN;
+		val |= MX51_ECSPI_INT_TEEN;
 
 	if (enable & MXC_INT_RR)
-		val |= SPI_IMX2_3_INT_RREN;
+		val |= MX51_ECSPI_INT_RREN;
 
-	writel(val, spi_imx->base + SPI_IMX2_3_INT);
+	writel(val, spi_imx->base + MX51_ECSPI_INT);
 }
 
-static void __maybe_unused spi_imx2_3_trigger(struct spi_imx_data *spi_imx)
+static void __maybe_unused mx51_ecspi_trigger(struct spi_imx_data *spi_imx)
 {
 	u32 reg;
 
-	reg = readl(spi_imx->base + SPI_IMX2_3_CTRL);
-	reg |= SPI_IMX2_3_CTRL_XCH;
-	writel(reg, spi_imx->base + SPI_IMX2_3_CTRL);
+	reg = readl(spi_imx->base + MX51_ECSPI_CTRL);
+	reg |= MX51_ECSPI_CTRL_XCH;
+	writel(reg, spi_imx->base + MX51_ECSPI_CTRL);
 }
 
-static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
+static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx,
 		struct spi_imx_config *config)
 {
-	u32 ctrl = SPI_IMX2_3_CTRL_ENABLE, cfg = 0;
+	u32 ctrl = MX51_ECSPI_CTRL_ENABLE, cfg = 0;
 
 	/*
 	 * The hardware seems to have a race condition when changing modes. The
@@ -260,42 +261,42 @@ static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
 	 * the same time.
 	 * So set master mode for all channels as we do not support slave mode.
 	 */
-	ctrl |= SPI_IMX2_3_CTRL_MODE_MASK;
+	ctrl |= MX51_ECSPI_CTRL_MODE_MASK;
 
 	/* set clock speed */
-	ctrl |= spi_imx2_3_clkdiv(spi_imx->spi_clk, config->speed_hz);
+	ctrl |= mx51_ecspi_clkdiv(spi_imx->spi_clk, config->speed_hz);
 
 	/* set chip select to use */
-	ctrl |= SPI_IMX2_3_CTRL_CS(config->cs);
+	ctrl |= MX51_ECSPI_CTRL_CS(config->cs);
 
-	ctrl |= (config->bpw - 1) << SPI_IMX2_3_CTRL_BL_OFFSET;
+	ctrl |= (config->bpw - 1) << MX51_ECSPI_CTRL_BL_OFFSET;
 
-	cfg |= SPI_IMX2_3_CONFIG_SBBCTRL(config->cs);
+	cfg |= MX51_ECSPI_CONFIG_SBBCTRL(config->cs);
 
 	if (config->mode & SPI_CPHA)
-		cfg |= SPI_IMX2_3_CONFIG_SCLKPHA(config->cs);
+		cfg |= MX51_ECSPI_CONFIG_SCLKPHA(config->cs);
 
 	if (config->mode & SPI_CPOL)
-		cfg |= SPI_IMX2_3_CONFIG_SCLKPOL(config->cs);
+		cfg |= MX51_ECSPI_CONFIG_SCLKPOL(config->cs);
 
 	if (config->mode & SPI_CS_HIGH)
-		cfg |= SPI_IMX2_3_CONFIG_SSBPOL(config->cs);
+		cfg |= MX51_ECSPI_CONFIG_SSBPOL(config->cs);
 
-	writel(ctrl, spi_imx->base + SPI_IMX2_3_CTRL);
-	writel(cfg, spi_imx->base + SPI_IMX2_3_CONFIG);
+	writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
+	writel(cfg, spi_imx->base + MX51_ECSPI_CONFIG);
 
 	return 0;
 }
 
-static int __maybe_unused spi_imx2_3_rx_available(struct spi_imx_data *spi_imx)
+static int __maybe_unused mx51_ecspi_rx_available(struct spi_imx_data *spi_imx)
 {
-	return readl(spi_imx->base + SPI_IMX2_3_STAT) & SPI_IMX2_3_STAT_RR;
+	return readl(spi_imx->base + MX51_ECSPI_STAT) & MX51_ECSPI_STAT_RR;
 }
 
-static void __maybe_unused spi_imx2_3_reset(struct spi_imx_data *spi_imx)
+static void __maybe_unused mx51_ecspi_reset(struct spi_imx_data *spi_imx)
 {
 	/* drain receive buffer */
-	while (spi_imx2_3_rx_available(spi_imx))
+	while (mx51_ecspi_rx_available(spi_imx))
 		readl(spi_imx->base + MXC_CSPIRXDATA);
 }
 
@@ -583,11 +584,11 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
 #endif
 #ifdef CONFIG_SPI_IMX_VER_2_3
 	[SPI_IMX_VER_2_3] = {
-		.intctrl = spi_imx2_3_intctrl,
-		.config = spi_imx2_3_config,
-		.trigger = spi_imx2_3_trigger,
-		.rx_available = spi_imx2_3_rx_available,
-		.reset = spi_imx2_3_reset,
+		.intctrl = mx51_ecspi_intctrl,
+		.config = mx51_ecspi_config,
+		.trigger = mx51_ecspi_trigger,
+		.rx_available = mx51_ecspi_rx_available,
+		.reset = mx51_ecspi_reset,
 		.fifosize = 64,
 	},
 #endif
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 4/7] spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
                     ` (2 preceding siblings ...)
  2011-07-09 17:16   ` [PATCH v2 3/7] spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 " Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-5-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 5/7] spi/imx: use soc name in spi device type naming scheme Shawn Guo
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

The only difference between SPI_IMX_VER_0_7 and SPI_IMX_VER_0_4 is
.config function.  The patch uses cpu_is_mx35 (to be removed) as the
temporary solution to consolidate functions spi_imx0_4_config and
spi_imx0_7_config into mx31_config.  As a result, type SPI_IMX_VER_0_7
can be merged into SPI_IMX_VER_0_4.

It also renames function spi_imx0_4_reset to mx31_reset to keep
consistency with other function naming.

A couple of redundant macros, MX3_CSPISTAT and MX3_CSPISTAT_RR,
together with the useless type SPI_IMX_VER_0_5 also get cleaned up.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/spi/Kconfig   |    5 +---
 drivers/spi/spi-imx.c |   70 ++++++++++++------------------------------------
 2 files changed, 19 insertions(+), 56 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 9aafa98..c327cf3 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -161,10 +161,7 @@ config SPI_IMX_VER_0_0
 	def_bool y if SOC_IMX21 || SOC_IMX27
 
 config SPI_IMX_VER_0_4
-	def_bool y if SOC_IMX31
-
-config SPI_IMX_VER_0_7
-	def_bool y if ARCH_MX25 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
+	def_bool y if ARCH_MX25 || SOC_IMX31 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
 
 config SPI_IMX_VER_2_3
 	def_bool y if SOC_IMX51 || SOC_IMX53
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 052959df..b282351 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -45,9 +45,6 @@
 #define MXC_CSPIINT		0x0c
 #define MXC_RESET		0x1c
 
-#define MX3_CSPISTAT		0x14
-#define MX3_CSPISTAT_RR		(1 << 3)
-
 /* generic defines to abstract from the different register layouts */
 #define MXC_INT_RR	(1 << 0) /* Receive data ready interrupt */
 #define MXC_INT_TE	(1 << 1) /* Transmit FIFO empty interrupt */
@@ -63,8 +60,6 @@ enum spi_imx_devtype {
 	SPI_IMX_VER_IMX1,
 	SPI_IMX_VER_0_0,
 	SPI_IMX_VER_0_4,
-	SPI_IMX_VER_0_5,
-	SPI_IMX_VER_0_7,
 	SPI_IMX_VER_2_3,
 };
 
@@ -344,32 +339,7 @@ static void __maybe_unused mx31_trigger(struct spi_imx_data *spi_imx)
 	writel(reg, spi_imx->base + MXC_CSPICTRL);
 }
 
-static int __maybe_unused spi_imx0_4_config(struct spi_imx_data *spi_imx,
-		struct spi_imx_config *config)
-{
-	unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER;
-	int cs = spi_imx->chipselect[config->cs];
-
-	reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
-		MX31_CSPICTRL_DR_SHIFT;
-
-	reg |= (config->bpw - 1) << MX31_CSPICTRL_BC_SHIFT;
-
-	if (config->mode & SPI_CPHA)
-		reg |= MX31_CSPICTRL_PHA;
-	if (config->mode & SPI_CPOL)
-		reg |= MX31_CSPICTRL_POL;
-	if (config->mode & SPI_CS_HIGH)
-		reg |= MX31_CSPICTRL_SSPOL;
-	if (cs < 0)
-		reg |= (cs + 32) << MX31_CSPICTRL_CS_SHIFT;
-
-	writel(reg, spi_imx->base + MXC_CSPICTRL);
-
-	return 0;
-}
-
-static int __maybe_unused spi_imx0_7_config(struct spi_imx_data *spi_imx,
+static int __maybe_unused mx31_config(struct spi_imx_data *spi_imx,
 		struct spi_imx_config *config)
 {
 	unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER;
@@ -378,8 +348,12 @@ static int __maybe_unused spi_imx0_7_config(struct spi_imx_data *spi_imx,
 	reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
 		MX31_CSPICTRL_DR_SHIFT;
 
-	reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
-	reg |= MX31_CSPICTRL_SSCTL;
+	if (cpu_is_mx35()) {
+		reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
+		reg |= MX31_CSPICTRL_SSCTL;
+	} else {
+		reg |= (config->bpw - 1) << MX31_CSPICTRL_BC_SHIFT;
+	}
 
 	if (config->mode & SPI_CPHA)
 		reg |= MX31_CSPICTRL_PHA;
@@ -388,7 +362,9 @@ static int __maybe_unused spi_imx0_7_config(struct spi_imx_data *spi_imx,
 	if (config->mode & SPI_CS_HIGH)
 		reg |= MX31_CSPICTRL_SSPOL;
 	if (cs < 0)
-		reg |= (cs + 32) << MX35_CSPICTRL_CS_SHIFT;
+		reg |= (cs + 32) <<
+			(cpu_is_mx35() ? MX35_CSPICTRL_CS_SHIFT :
+					 MX31_CSPICTRL_CS_SHIFT);
 
 	writel(reg, spi_imx->base + MXC_CSPICTRL);
 
@@ -400,10 +376,10 @@ static int __maybe_unused mx31_rx_available(struct spi_imx_data *spi_imx)
 	return readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR;
 }
 
-static void __maybe_unused spi_imx0_4_reset(struct spi_imx_data *spi_imx)
+static void __maybe_unused mx31_reset(struct spi_imx_data *spi_imx)
 {
 	/* drain receive buffer */
-	while (readl(spi_imx->base + MX3_CSPISTAT) & MX3_CSPISTAT_RR)
+	while (readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR)
 		readl(spi_imx->base + MXC_CSPIRXDATA);
 }
 
@@ -565,20 +541,10 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
 #ifdef CONFIG_SPI_IMX_VER_0_4
 	[SPI_IMX_VER_0_4] = {
 		.intctrl = mx31_intctrl,
-		.config = spi_imx0_4_config,
+		.config = mx31_config,
 		.trigger = mx31_trigger,
 		.rx_available = mx31_rx_available,
-		.reset = spi_imx0_4_reset,
-		.fifosize = 8,
-	},
-#endif
-#ifdef CONFIG_SPI_IMX_VER_0_7
-	[SPI_IMX_VER_0_7] = {
-		.intctrl = mx31_intctrl,
-		.config = spi_imx0_7_config,
-		.trigger = mx31_trigger,
-		.rx_available = mx31_rx_available,
-		.reset = spi_imx0_4_reset,
+		.reset = mx31_reset,
 		.fifosize = 8,
 	},
 #endif
@@ -734,7 +700,7 @@ static struct platform_device_id spi_imx_devtype[] = {
 		.driver_data = SPI_IMX_VER_0_0,
 	}, {
 		.name = "imx25-cspi",
-		.driver_data = SPI_IMX_VER_0_7,
+		.driver_data = SPI_IMX_VER_0_4,
 	}, {
 		.name = "imx27-cspi",
 		.driver_data = SPI_IMX_VER_0_0,
@@ -743,16 +709,16 @@ static struct platform_device_id spi_imx_devtype[] = {
 		.driver_data = SPI_IMX_VER_0_4,
 	}, {
 		.name = "imx35-cspi",
-		.driver_data = SPI_IMX_VER_0_7,
+		.driver_data = SPI_IMX_VER_0_4,
 	}, {
 		.name = "imx51-cspi",
-		.driver_data = SPI_IMX_VER_0_7,
+		.driver_data = SPI_IMX_VER_0_4,
 	}, {
 		.name = "imx51-ecspi",
 		.driver_data = SPI_IMX_VER_2_3,
 	}, {
 		.name = "imx53-cspi",
-		.driver_data = SPI_IMX_VER_0_7,
+		.driver_data = SPI_IMX_VER_0_4,
 	}, {
 		.name = "imx53-ecspi",
 		.driver_data = SPI_IMX_VER_2_3,
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 5/7] spi/imx: use soc name in spi device type naming scheme
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
                     ` (3 preceding siblings ...)
  2011-07-09 17:16   ` [PATCH v2 4/7] spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4 Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-6-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 6/7] spi/imx: copy gpio number passed by platform data into driver private data Shawn Guo
  2011-07-09 17:16   ` [PATCH v2 7/7] spi/imx: add device tree probe support Shawn Guo
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Software defined version number is not stable enough to be used
in device type naming scheme.  The patch changes it to use implicit
soc name for spi device type definition.  In this way, we can easily
align the naming scheme with device tree binding, which comes later.

It removes fifosize from spi_imx_data and adds devtype there, so that
fifosize can be set in an inline function according to devtype.
Also, cpu_is_mx can be replaced by inline functions checking devtype.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 arch/arm/mach-imx/clock-imx25.c              |    7 +-
 arch/arm/mach-mx5/clock-mx51-mx53.c          |   11 +-
 arch/arm/plat-mxc/devices/platform-spi_imx.c |   12 +-
 drivers/spi/Kconfig                          |   12 --
 drivers/spi/spi-imx.c                        |  208 ++++++++++++++------------
 5 files changed, 128 insertions(+), 122 deletions(-)

diff --git a/arch/arm/mach-imx/clock-imx25.c b/arch/arm/mach-imx/clock-imx25.c
index 9bb9062..17d6d1b 100644
--- a/arch/arm/mach-imx/clock-imx25.c
+++ b/arch/arm/mach-imx/clock-imx25.c
@@ -283,9 +283,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxc-ehci.2", "usb", usbotg_clk)
 	_REGISTER_CLOCK("fsl-usb2-udc", "usb", usbotg_clk)
 	_REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
-	_REGISTER_CLOCK("imx25-cspi.0", NULL, cspi1_clk)
-	_REGISTER_CLOCK("imx25-cspi.1", NULL, cspi2_clk)
-	_REGISTER_CLOCK("imx25-cspi.2", NULL, cspi3_clk)
+	/* i.mx25 has the i.mx35 type cspi */
+	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi1_clk)
+	_REGISTER_CLOCK("imx35-cspi.1", NULL, cspi2_clk)
+	_REGISTER_CLOCK("imx35-cspi.2", NULL, cspi3_clk)
 	_REGISTER_CLOCK("mxc_pwm.0", NULL, pwm1_clk)
 	_REGISTER_CLOCK("mxc_pwm.1", NULL, pwm2_clk)
 	_REGISTER_CLOCK("mxc_pwm.2", NULL, pwm3_clk)
diff --git a/arch/arm/mach-mx5/clock-mx51-mx53.c b/arch/arm/mach-mx5/clock-mx51-mx53.c
index e00c427..31d904c 100644
--- a/arch/arm/mach-mx5/clock-mx51-mx53.c
+++ b/arch/arm/mach-mx5/clock-mx51-mx53.c
@@ -1453,7 +1453,8 @@ static struct clk_lookup mx51_lookups[] = {
 	_REGISTER_CLOCK(NULL, "gpt_32k", gpt_32k_clk)
 	_REGISTER_CLOCK("imx51-ecspi.0", NULL, ecspi1_clk)
 	_REGISTER_CLOCK("imx51-ecspi.1", NULL, ecspi2_clk)
-	_REGISTER_CLOCK("imx51-cspi.0", NULL, cspi_clk)
+	/* i.mx51 has the i.mx35 type cspi */
+	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi_clk)
 	_REGISTER_CLOCK("sdhci-esdhc-imx51.0", NULL, esdhc1_clk)
 	_REGISTER_CLOCK("sdhci-esdhc-imx51.1", NULL, esdhc2_clk)
 	_REGISTER_CLOCK("sdhci-esdhc-imx51.2", NULL, esdhc3_clk)
@@ -1486,9 +1487,11 @@ static struct clk_lookup mx53_lookups[] = {
 	_REGISTER_CLOCK("sdhci-esdhc-imx53.1", NULL, esdhc2_mx53_clk)
 	_REGISTER_CLOCK("sdhci-esdhc-imx53.2", NULL, esdhc3_mx53_clk)
 	_REGISTER_CLOCK("sdhci-esdhc-imx53.3", NULL, esdhc4_mx53_clk)
-	_REGISTER_CLOCK("imx53-ecspi.0", NULL, ecspi1_clk)
-	_REGISTER_CLOCK("imx53-ecspi.1", NULL, ecspi2_clk)
-	_REGISTER_CLOCK("imx53-cspi.0", NULL, cspi_clk)
+	/* i.mx53 has the i.mx51 type ecspi */
+	_REGISTER_CLOCK("imx51-ecspi.0", NULL, ecspi1_clk)
+	_REGISTER_CLOCK("imx51-ecspi.1", NULL, ecspi2_clk)
+	/* i.mx53 has the i.mx35 type cspi */
+	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi_clk)
 	_REGISTER_CLOCK("imx2-wdt.0", NULL, dummy_clk)
 	_REGISTER_CLOCK("imx2-wdt.1", NULL, dummy_clk)
 	_REGISTER_CLOCK("imx-sdma", NULL, sdma_clk)
diff --git a/arch/arm/plat-mxc/devices/platform-spi_imx.c b/arch/arm/plat-mxc/devices/platform-spi_imx.c
index f97eb36..9bfae8b 100644
--- a/arch/arm/plat-mxc/devices/platform-spi_imx.c
+++ b/arch/arm/plat-mxc/devices/platform-spi_imx.c
@@ -40,9 +40,10 @@ const struct imx_spi_imx_data imx21_cspi_data[] __initconst = {
 #endif
 
 #ifdef CONFIG_SOC_IMX25
+/* i.mx25 has the i.mx35 type cspi */
 const struct imx_spi_imx_data imx25_cspi_data[] __initconst = {
 #define imx25_cspi_data_entry(_id, _hwid)				\
-	imx_spi_imx_data_entry(MX25, CSPI, "imx25-cspi", _id, _hwid, SZ_16K)
+	imx_spi_imx_data_entry(MX25, CSPI, "imx35-cspi", _id, _hwid, SZ_16K)
 	imx25_cspi_data_entry(0, 1),
 	imx25_cspi_data_entry(1, 2),
 	imx25_cspi_data_entry(2, 3),
@@ -79,8 +80,9 @@ const struct imx_spi_imx_data imx35_cspi_data[] __initconst = {
 #endif /* ifdef CONFIG_SOC_IMX35 */
 
 #ifdef CONFIG_SOC_IMX51
+/* i.mx51 has the i.mx35 type cspi */
 const struct imx_spi_imx_data imx51_cspi_data __initconst =
-	imx_spi_imx_data_entry_single(MX51, CSPI, "imx51-cspi", 2, , SZ_4K);
+	imx_spi_imx_data_entry_single(MX51, CSPI, "imx35-cspi", 2, , SZ_4K);
 
 const struct imx_spi_imx_data imx51_ecspi_data[] __initconst = {
 #define imx51_ecspi_data_entry(_id, _hwid)				\
@@ -91,12 +93,14 @@ const struct imx_spi_imx_data imx51_ecspi_data[] __initconst = {
 #endif /* ifdef CONFIG_SOC_IMX51 */
 
 #ifdef CONFIG_SOC_IMX53
+/* i.mx53 has the i.mx35 type cspi */
 const struct imx_spi_imx_data imx53_cspi_data __initconst =
-	imx_spi_imx_data_entry_single(MX53, CSPI, "imx53-cspi", 0, , SZ_4K);
+	imx_spi_imx_data_entry_single(MX53, CSPI, "imx35-cspi", 0, , SZ_4K);
 
+/* i.mx53 has the i.mx51 type ecspi */
 const struct imx_spi_imx_data imx53_ecspi_data[] __initconst = {
 #define imx53_ecspi_data_entry(_id, _hwid)				\
-	imx_spi_imx_data_entry(MX53, ECSPI, "imx53-ecspi", _id, _hwid, SZ_4K)
+	imx_spi_imx_data_entry(MX53, ECSPI, "imx51-ecspi", _id, _hwid, SZ_4K)
 	imx53_ecspi_data_entry(0, 1),
 	imx53_ecspi_data_entry(1, 2),
 };
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index c327cf3..52e2900 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -154,18 +154,6 @@ config SPI_GPIO
 	  GPIO operations, you should be able to leverage that for better
 	  speed with a custom version of this driver; see the source code.
 
-config SPI_IMX_VER_IMX1
-	def_bool y if SOC_IMX1
-
-config SPI_IMX_VER_0_0
-	def_bool y if SOC_IMX21 || SOC_IMX27
-
-config SPI_IMX_VER_0_4
-	def_bool y if ARCH_MX25 || SOC_IMX31 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
-
-config SPI_IMX_VER_2_3
-	def_bool y if SOC_IMX51 || SOC_IMX53
-
 config SPI_IMX
 	tristate "Freescale i.MX SPI controllers"
 	depends on ARCH_MXC
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index b282351..2ed9c32 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -57,10 +57,12 @@ struct spi_imx_config {
 };
 
 enum spi_imx_devtype {
-	SPI_IMX_VER_IMX1,
-	SPI_IMX_VER_0_0,
-	SPI_IMX_VER_0_4,
-	SPI_IMX_VER_2_3,
+	IMX1_CSPI,
+	IMX21_CSPI,
+	IMX27_CSPI,
+	IMX31_CSPI,
+	IMX35_CSPI,	/* CSPI on all i.mx except above */
+	IMX51_ECSPI,	/* ECSPI on i.mx51 and later */
 };
 
 struct spi_imx_data;
@@ -71,7 +73,7 @@ struct spi_imx_devtype_data {
 	void (*trigger)(struct spi_imx_data *);
 	int (*rx_available)(struct spi_imx_data *);
 	void (*reset)(struct spi_imx_data *);
-	unsigned int fifosize;
+	enum spi_imx_devtype devtype;
 };
 
 struct spi_imx_data {
@@ -94,6 +96,21 @@ struct spi_imx_data {
 	struct spi_imx_devtype_data *devtype_data;
 };
 
+static inline int is_imx27_cspi(struct spi_imx_data *d)
+{
+	return d->devtype_data->devtype == IMX27_CSPI;
+}
+
+static inline int is_imx35_cspi(struct spi_imx_data *d)
+{
+	return d->devtype_data->devtype == IMX35_CSPI;
+}
+
+static inline unsigned spi_imx_get_fifosize(struct spi_imx_data *d)
+{
+	return (d->devtype_data->devtype == IMX51_ECSPI) ? 64 : 8;
+}
+
 #define MXC_SPI_BUF_RX(type)						\
 static void spi_imx_buf_rx_##type(struct spi_imx_data *spi_imx)		\
 {									\
@@ -135,14 +152,9 @@ static int mxc_clkdivs[] = {0, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192,
 
 /* MX21, MX27 */
 static unsigned int spi_imx_clkdiv_1(unsigned int fin,
-		unsigned int fspi)
+		unsigned int fspi, unsigned int max)
 {
-	int i, max;
-
-	if (cpu_is_mx21())
-		max = 18;
-	else
-		max = 16;
+	int i;
 
 	for (i = 2; i < max; i++)
 		if (fspi * mxc_clkdivs[i] >= fin)
@@ -348,7 +360,7 @@ static int __maybe_unused mx31_config(struct spi_imx_data *spi_imx,
 	reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
 		MX31_CSPICTRL_DR_SHIFT;
 
-	if (cpu_is_mx35()) {
+	if (is_imx35_cspi(spi_imx)) {
 		reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
 		reg |= MX31_CSPICTRL_SSCTL;
 	} else {
@@ -363,8 +375,8 @@ static int __maybe_unused mx31_config(struct spi_imx_data *spi_imx,
 		reg |= MX31_CSPICTRL_SSPOL;
 	if (cs < 0)
 		reg |= (cs + 32) <<
-			(cpu_is_mx35() ? MX35_CSPICTRL_CS_SHIFT :
-					 MX31_CSPICTRL_CS_SHIFT);
+			(is_imx35_cspi(spi_imx) ? MX35_CSPICTRL_CS_SHIFT :
+						  MX31_CSPICTRL_CS_SHIFT);
 
 	writel(reg, spi_imx->base + MXC_CSPICTRL);
 
@@ -423,8 +435,9 @@ static int __maybe_unused mx21_config(struct spi_imx_data *spi_imx,
 {
 	unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER;
 	int cs = spi_imx->chipselect[config->cs];
+	unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18;
 
-	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
+	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz, max) <<
 		MX21_CSPICTRL_DR_SHIFT;
 	reg |= config->bpw - 1;
 
@@ -513,51 +526,84 @@ static void __maybe_unused mx1_reset(struct spi_imx_data *spi_imx)
 	writel(1, spi_imx->base + MXC_RESET);
 }
 
-/*
- * These version numbers are taken from the Freescale driver.  Unfortunately it
- * doesn't support i.MX1, so this entry doesn't match the scheme. :-(
- */
-static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
-#ifdef CONFIG_SPI_IMX_VER_IMX1
-	[SPI_IMX_VER_IMX1] = {
-		.intctrl = mx1_intctrl,
-		.config = mx1_config,
-		.trigger = mx1_trigger,
-		.rx_available = mx1_rx_available,
-		.reset = mx1_reset,
-		.fifosize = 8,
-	},
-#endif
-#ifdef CONFIG_SPI_IMX_VER_0_0
-	[SPI_IMX_VER_0_0] = {
-		.intctrl = mx21_intctrl,
-		.config = mx21_config,
-		.trigger = mx21_trigger,
-		.rx_available = mx21_rx_available,
-		.reset = mx21_reset,
-		.fifosize = 8,
-	},
-#endif
-#ifdef CONFIG_SPI_IMX_VER_0_4
-	[SPI_IMX_VER_0_4] = {
-		.intctrl = mx31_intctrl,
-		.config = mx31_config,
-		.trigger = mx31_trigger,
-		.rx_available = mx31_rx_available,
-		.reset = mx31_reset,
-		.fifosize = 8,
-	},
-#endif
-#ifdef CONFIG_SPI_IMX_VER_2_3
-	[SPI_IMX_VER_2_3] = {
-		.intctrl = mx51_ecspi_intctrl,
-		.config = mx51_ecspi_config,
-		.trigger = mx51_ecspi_trigger,
-		.rx_available = mx51_ecspi_rx_available,
-		.reset = mx51_ecspi_reset,
-		.fifosize = 64,
-	},
-#endif
+static struct spi_imx_devtype_data imx1_cspi_devtype_data = {
+	.intctrl = mx1_intctrl,
+	.config = mx1_config,
+	.trigger = mx1_trigger,
+	.rx_available = mx1_rx_available,
+	.reset = mx1_reset,
+	.devtype = IMX1_CSPI,
+};
+
+static struct spi_imx_devtype_data imx21_cspi_devtype_data = {
+	.intctrl = mx21_intctrl,
+	.config = mx21_config,
+	.trigger = mx21_trigger,
+	.rx_available = mx21_rx_available,
+	.reset = mx21_reset,
+	.devtype = IMX21_CSPI,
+};
+
+static struct spi_imx_devtype_data imx27_cspi_devtype_data = {
+	/* i.mx27 cspi shares the functions with i.mx21 one */
+	.intctrl = mx21_intctrl,
+	.config = mx21_config,
+	.trigger = mx21_trigger,
+	.rx_available = mx21_rx_available,
+	.reset = mx21_reset,
+	.devtype = IMX27_CSPI,
+};
+
+static struct spi_imx_devtype_data imx31_cspi_devtype_data = {
+	.intctrl = mx31_intctrl,
+	.config = mx31_config,
+	.trigger = mx31_trigger,
+	.rx_available = mx31_rx_available,
+	.reset = mx31_reset,
+	.devtype = IMX31_CSPI,
+};
+
+static struct spi_imx_devtype_data imx35_cspi_devtype_data = {
+	/* i.mx35 and later cspi shares the functions with i.mx31 one */
+	.intctrl = mx31_intctrl,
+	.config = mx31_config,
+	.trigger = mx31_trigger,
+	.rx_available = mx31_rx_available,
+	.reset = mx31_reset,
+	.devtype = IMX35_CSPI,
+};
+
+static struct spi_imx_devtype_data imx51_ecspi_devtype_data = {
+	.intctrl = mx51_ecspi_intctrl,
+	.config = mx51_ecspi_config,
+	.trigger = mx51_ecspi_trigger,
+	.rx_available = mx51_ecspi_rx_available,
+	.reset = mx51_ecspi_reset,
+	.devtype = IMX51_ECSPI,
+};
+
+static struct platform_device_id spi_imx_devtype[] = {
+	{
+		.name = "imx1-cspi",
+		.driver_data = (kernel_ulong_t) &imx1_cspi_devtype_data,
+	}, {
+		.name = "imx21-cspi",
+		.driver_data = (kernel_ulong_t) &imx21_cspi_devtype_data,
+	}, {
+		.name = "imx27-cspi",
+		.driver_data = (kernel_ulong_t) &imx27_cspi_devtype_data,
+	}, {
+		.name = "imx31-cspi",
+		.driver_data = (kernel_ulong_t) &imx31_cspi_devtype_data,
+	}, {
+		.name = "imx35-cspi",
+		.driver_data = (kernel_ulong_t) &imx35_cspi_devtype_data,
+	}, {
+		.name = "imx51-ecspi",
+		.driver_data = (kernel_ulong_t) &imx51_ecspi_devtype_data,
+	}, {
+		/* sentinel */
+	}
 };
 
 static void spi_imx_chipselect(struct spi_device *spi, int is_active)
@@ -575,7 +621,7 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active)
 
 static void spi_imx_push(struct spi_imx_data *spi_imx)
 {
-	while (spi_imx->txfifo < spi_imx->devtype_data->fifosize) {
+	while (spi_imx->txfifo < spi_imx_get_fifosize(spi_imx)) {
 		if (!spi_imx->count)
 			break;
 		spi_imx->tx(spi_imx);
@@ -691,42 +737,6 @@ static void spi_imx_cleanup(struct spi_device *spi)
 {
 }
 
-static struct platform_device_id spi_imx_devtype[] = {
-	{
-		.name = "imx1-cspi",
-		.driver_data = SPI_IMX_VER_IMX1,
-	}, {
-		.name = "imx21-cspi",
-		.driver_data = SPI_IMX_VER_0_0,
-	}, {
-		.name = "imx25-cspi",
-		.driver_data = SPI_IMX_VER_0_4,
-	}, {
-		.name = "imx27-cspi",
-		.driver_data = SPI_IMX_VER_0_0,
-	}, {
-		.name = "imx31-cspi",
-		.driver_data = SPI_IMX_VER_0_4,
-	}, {
-		.name = "imx35-cspi",
-		.driver_data = SPI_IMX_VER_0_4,
-	}, {
-		.name = "imx51-cspi",
-		.driver_data = SPI_IMX_VER_0_4,
-	}, {
-		.name = "imx51-ecspi",
-		.driver_data = SPI_IMX_VER_2_3,
-	}, {
-		.name = "imx53-cspi",
-		.driver_data = SPI_IMX_VER_0_4,
-	}, {
-		.name = "imx53-ecspi",
-		.driver_data = SPI_IMX_VER_2_3,
-	}, {
-		/* sentinel */
-	}
-};
-
 static int __devinit spi_imx_probe(struct platform_device *pdev)
 {
 	struct spi_imx_master *mxc_platform_info;
@@ -779,7 +789,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 	init_completion(&spi_imx->xfer_done);
 
 	spi_imx->devtype_data =
-		&spi_imx_devtype_data[pdev->id_entry->driver_data];
+		(struct spi_imx_devtype_data *) pdev->id_entry->driver_data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 6/7] spi/imx: copy gpio number passed by platform data into driver private data
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
                     ` (4 preceding siblings ...)
  2011-07-09 17:16   ` [PATCH v2 5/7] spi/imx: use soc name in spi device type naming scheme Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-7-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  2011-07-09 17:16   ` [PATCH v2 7/7] spi/imx: add device tree probe support Shawn Guo
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

It copies gpio number passed via platform data embedded pointer into
driver private data, so that we do not need to refer to this embedded
pointer passed by platform data after probe function exits.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/spi/spi-imx.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 2ed9c32..ad61828 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -84,7 +84,6 @@ struct spi_imx_data {
 	int irq;
 	struct clk *clk;
 	unsigned long spi_clk;
-	int *chipselect;
 
 	unsigned int count;
 	void (*tx)(struct spi_imx_data *);
@@ -94,6 +93,7 @@ struct spi_imx_data {
 	unsigned int txfifo; /* number of words pushed in tx FIFO */
 
 	struct spi_imx_devtype_data *devtype_data;
+	int chipselect[0];
 };
 
 static inline int is_imx27_cspi(struct spi_imx_data *d)
@@ -743,7 +743,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 	struct spi_master *master;
 	struct spi_imx_data *spi_imx;
 	struct resource *res;
-	int i, ret;
+	int i, ret, num_cs;
 
 	mxc_platform_info = dev_get_platdata(&pdev->dev);
 	if (!mxc_platform_info) {
@@ -751,20 +751,22 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	master = spi_alloc_master(&pdev->dev, sizeof(struct spi_imx_data));
+	num_cs = mxc_platform_info->num_chipselect;
+	master = spi_alloc_master(&pdev->dev,
+			sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
 	if (!master)
 		return -ENOMEM;
 
 	platform_set_drvdata(pdev, master);
 
 	master->bus_num = pdev->id;
-	master->num_chipselect = mxc_platform_info->num_chipselect;
+	master->num_chipselect = num_cs;
 
 	spi_imx = spi_master_get_devdata(master);
 	spi_imx->bitbang.master = spi_master_get(master);
-	spi_imx->chipselect = mxc_platform_info->chipselect;
 
 	for (i = 0; i < master->num_chipselect; i++) {
+		spi_imx->chipselect[i] = mxc_platform_info->chipselect[i];
 		if (spi_imx->chipselect[i] < 0)
 			continue;
 		ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME);
-- 
1.7.4.1

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 7/7] spi/imx: add device tree probe support
       [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
                     ` (5 preceding siblings ...)
  2011-07-09 17:16   ` [PATCH v2 6/7] spi/imx: copy gpio number passed by platform data into driver private data Shawn Guo
@ 2011-07-09 17:16   ` Shawn Guo
       [not found]     ` <1310231801-18761-8-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  6 siblings, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-09 17:16 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	patches-QSEj5FYQhm4dnm+yROfE0A

It adds device tree probe support for spi-imx driver.

Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 .../devicetree/bindings/spi/fsl-imx-cspi.txt       |   22 +++++++++++
 drivers/spi/spi-imx.c                              |   38 ++++++++++++++++----
 2 files changed, 53 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt

diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
new file mode 100644
index 0000000..9841057
--- /dev/null
+++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
@@ -0,0 +1,22 @@
+* Freescale (Enhanced) Configurable Serial Peripheral Interface
+  (CSPI/eCSPI) for i.MX
+
+Required properties:
+- compatible : Should be "fsl,<soc>-cspi" or "fsl,<soc>-ecspi"
+- reg : Offset and length of the register set for the device
+- interrupts : Should contain CSPI/eCSPI interrupt
+- fsl,spi-num-chipselects : Contains the number of the chipselect
+- cs-gpios : Specifies the gpio pins to be used for chipselects.
+
+Example:
+
+ecspi@70010000 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	compatible = "fsl,imx51-ecspi";
+	reg = <0x70010000 0x4000>;
+	interrupts = <36>;
+	fsl,spi-num-chipselects = <2>;
+	cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */
+		   <&gpio3 25 0>; /* GPIO4_25 */
+};
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index ad61828..5456bcc 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -34,6 +34,9 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/types.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
 
 #include <mach/spi.h>
 
@@ -606,6 +609,16 @@ static struct platform_device_id spi_imx_devtype[] = {
 	}
 };
 
+static const struct of_device_id spi_imx_dt_ids[] = {
+	{ .compatible = "fsl,imx1-cspi", .data = &imx1_cspi_devtype_data, },
+	{ .compatible = "fsl,imx21-cspi", .data = &imx21_cspi_devtype_data, },
+	{ .compatible = "fsl,imx27-cspi", .data = &imx27_cspi_devtype_data, },
+	{ .compatible = "fsl,imx31-cspi", .data = &imx31_cspi_devtype_data, },
+	{ .compatible = "fsl,imx35-cspi", .data = &imx35_cspi_devtype_data, },
+	{ .compatible = "fsl,imx51-ecspi", .data = &imx51_ecspi_devtype_data, },
+	{ /* sentinel */ }
+};
+
 static void spi_imx_chipselect(struct spi_device *spi, int is_active)
 {
 	struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
@@ -739,19 +752,25 @@ static void spi_imx_cleanup(struct spi_device *spi)
 
 static int __devinit spi_imx_probe(struct platform_device *pdev)
 {
-	struct spi_imx_master *mxc_platform_info;
+	struct device_node *np = pdev->dev.of_node;
+	const struct of_device_id *of_id =
+			of_match_device(spi_imx_dt_ids, &pdev->dev);
+	struct spi_imx_master *mxc_platform_info =
+			dev_get_platdata(&pdev->dev);
 	struct spi_master *master;
 	struct spi_imx_data *spi_imx;
 	struct resource *res;
 	int i, ret, num_cs;
 
-	mxc_platform_info = dev_get_platdata(&pdev->dev);
-	if (!mxc_platform_info) {
+	if (!np && !mxc_platform_info) {
 		dev_err(&pdev->dev, "can't get the platform data\n");
 		return -EINVAL;
 	}
 
-	num_cs = mxc_platform_info->num_chipselect;
+	ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
+	if (ret < 0)
+		num_cs = mxc_platform_info->num_chipselect;
+
 	master = spi_alloc_master(&pdev->dev,
 			sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
 	if (!master)
@@ -766,9 +785,12 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 	spi_imx->bitbang.master = spi_master_get(master);
 
 	for (i = 0; i < master->num_chipselect; i++) {
-		spi_imx->chipselect[i] = mxc_platform_info->chipselect[i];
-		if (spi_imx->chipselect[i] < 0)
+		int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
+		if (cs_gpio < 0)
+			cs_gpio = mxc_platform_info->chipselect[i];
+		if (cs_gpio < 0)
 			continue;
+		spi_imx->chipselect[i] = cs_gpio;
 		ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME);
 		if (ret) {
 			while (i > 0) {
@@ -790,7 +812,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 
 	init_completion(&spi_imx->xfer_done);
 
-	spi_imx->devtype_data =
+	spi_imx->devtype_data = of_id ? of_id->data :
 		(struct spi_imx_devtype_data *) pdev->id_entry->driver_data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -838,6 +860,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
 
 	spi_imx->devtype_data->intctrl(spi_imx, 0);
 
+	master->dev.of_node = pdev->dev.of_node;
 	ret = spi_bitbang_start(&spi_imx->bitbang);
 	if (ret) {
 		dev_err(&pdev->dev, "bitbang start failed with %d\n", ret);
@@ -900,6 +923,7 @@ static struct platform_driver spi_imx_driver = {
 	.driver = {
 		   .name = DRIVER_NAME,
 		   .owner = THIS_MODULE,
+		   .of_match_table = spi_imx_dt_ids,
 		   },
 	.id_table = spi_imx_devtype,
 	.probe = spi_imx_probe,
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
  2011-07-09 17:16   ` [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data Shawn Guo
@ 2011-07-11  7:15     ` Lothar Waßmann
       [not found]       ` <19994.41750.920408.162356-VjFSrY7JcPWvSplVBqRQBQ@public.gmane.org>
  2011-07-11  7:35       ` Shawn Guo
       [not found]     ` <1310231801-18761-2-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
  1 sibling, 2 replies; 21+ messages in thread
From: Lothar Waßmann @ 2011-07-11  7:15 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches, devicetree-discuss, Grant Likely, Uwe Kleine-König,
	spi-devel-general, Sascha Hauer, linux-arm-kernel

Hi,

Shawn Guo writes:
> spi_imx_devtype_data has already been driver private data.  There is
> really no need to make a copy in spi_imx_data.  Instead, a reference
> pointer works perfectly fine.
> 
You obviously overlooked, that the copy is done on purpose to keep
only the data that is actually needed and discard everything else
after initialisation.


Lothar Waßmann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info@karo-electronics.de
___________________________________________________________

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
       [not found]       ` <19994.41750.920408.162356-VjFSrY7JcPWvSplVBqRQBQ@public.gmane.org>
@ 2011-07-11  7:31         ` Uwe Kleine-König
  2011-07-11  7:49           ` Lothar Waßmann
  0 siblings, 1 reply; 21+ messages in thread
From: Uwe Kleine-König @ 2011-07-11  7:31 UTC (permalink / raw)
  To: Lothar Waßmann
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Mon, Jul 11, 2011 at 09:15:34AM +0200, Lothar Waßmann wrote:
> Hi,
> 
> Shawn Guo writes:
> > spi_imx_devtype_data has already been driver private data.  There is
> > really no need to make a copy in spi_imx_data.  Instead, a reference
> > pointer works perfectly fine.
> > 
> You obviously overlooked, that the copy is done on purpose to keep
> only the data that is actually needed and discard everything else
> after initialisation.
though you could argue that __devinitdata isn't discarded on modern
systems anyhow (and Shawn's patch takes care of removing that
annotation).

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
       [not found]         ` <20110711073523.GA19105-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
@ 2011-07-11  7:32           ` Lothar Waßmann
  0 siblings, 0 replies; 21+ messages in thread
From: Lothar Waßmann @ 2011-07-11  7:32 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Shawn Guo,
	Sascha Hauer, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi,

Shawn Guo writes:
> On Mon, Jul 11, 2011 at 09:15:34AM +0200, Lothar Waßmann wrote:
> > Hi,
> > 
> > Shawn Guo writes:
> > > spi_imx_devtype_data has already been driver private data.  There is
> > > really no need to make a copy in spi_imx_data.  Instead, a reference
> > > pointer works perfectly fine.
> > > 
> > You obviously overlooked, that the copy is done on purpose to keep
> > only the data that is actually needed and discard everything else
> > after initialisation.
> > 
> I did not overlook that, as I removed __devinitdata there.
> 
But now you keep the whole array of which only one entry is being
used instead of only the used entry.


Lothar Waßmann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info@karo-electronics.de
___________________________________________________________

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro
       [not found]     ` <1310231801-18761-3-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-11  7:35       ` Uwe Kleine-König
       [not found]         ` <20110711073523.GB13840-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  0 siblings, 1 reply; 21+ messages in thread
From: Uwe Kleine-König @ 2011-07-11  7:35 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:36AM +0800, Shawn Guo wrote:
> SPI_IMX_VER_0_0 covers i.mx21 and i.mx27.  It makes more sense to
> use mx21 rather than mx27 to name SPI_IMX_VER_0_0 function and
> macro, since i.mx21 comes out ealier than i.mx27.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> ---
>  drivers/spi/spi-imx.c |   67 +++++++++++++++++++++++++------------------------
>  1 files changed, 34 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 1c55dc9..ad928b1 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -406,70 +406,71 @@ static void __maybe_unused spi_imx0_4_reset(struct spi_imx_data *spi_imx)
>  		readl(spi_imx->base + MXC_CSPIRXDATA);
>  }
>  
> -#define MX27_INTREG_RR		(1 << 4)
> -#define MX27_INTREG_TEEN	(1 << 9)
> -#define MX27_INTREG_RREN	(1 << 13)
> -
> -#define MX27_CSPICTRL_POL	(1 << 5)
> -#define MX27_CSPICTRL_PHA	(1 << 6)
> -#define MX27_CSPICTRL_SSPOL	(1 << 8)
> -#define MX27_CSPICTRL_XCH	(1 << 9)
> -#define MX27_CSPICTRL_ENABLE	(1 << 10)
> -#define MX27_CSPICTRL_MASTER	(1 << 11)
> -#define MX27_CSPICTRL_DR_SHIFT	14
> -#define MX27_CSPICTRL_CS_SHIFT	19
> -
> -static void __maybe_unused mx27_intctrl(struct spi_imx_data *spi_imx, int enable)
> +#define MX21_INTREG_RR		(1 << 4)
> +#define MX21_INTREG_TEEN	(1 << 9)
> +#define MX21_INTREG_RREN	(1 << 13)
> +
> +#define MX21_CSPICTRL_POL	(1 << 5)
> +#define MX21_CSPICTRL_PHA	(1 << 6)
> +#define MX21_CSPICTRL_SSPOL	(1 << 8)
> +#define MX21_CSPICTRL_XCH	(1 << 9)
> +#define MX21_CSPICTRL_ENABLE	(1 << 10)
> +#define MX21_CSPICTRL_MASTER	(1 << 11)
> +#define MX21_CSPICTRL_DR_SHIFT	14
> +#define MX21_CSPICTRL_CS_SHIFT	19
> +
> +static void __maybe_unused
> +mx21_intctrl(struct spi_imx_data *spi_imx, int enable)
this needs to be intended. I usually use 2 tabs (and I'm quite annoyed
that vim doesn't do that for me).

>  {
>  	unsigned int val = 0;
>  
>  	if (enable & MXC_INT_TE)
> -		val |= MX27_INTREG_TEEN;
> +		val |= MX21_INTREG_TEEN;
>  	if (enable & MXC_INT_RR)
> -		val |= MX27_INTREG_RREN;
> +		val |= MX21_INTREG_RREN;
>  
>  	writel(val, spi_imx->base + MXC_CSPIINT);
>  }
>  
> -static void __maybe_unused mx27_trigger(struct spi_imx_data *spi_imx)
> +static void __maybe_unused mx21_trigger(struct spi_imx_data *spi_imx)
>  {
>  	unsigned int reg;
>  
>  	reg = readl(spi_imx->base + MXC_CSPICTRL);
> -	reg |= MX27_CSPICTRL_XCH;
> +	reg |= MX21_CSPICTRL_XCH;
>  	writel(reg, spi_imx->base + MXC_CSPICTRL);
>  }
>  
> -static int __maybe_unused mx27_config(struct spi_imx_data *spi_imx,
> +static int __maybe_unused mx21_config(struct spi_imx_data *spi_imx,
>  		struct spi_imx_config *config)
>  {
> -	unsigned int reg = MX27_CSPICTRL_ENABLE | MX27_CSPICTRL_MASTER;
> +	unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER;
>  	int cs = spi_imx->chipselect[config->cs];
>  
>  	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
> -		MX27_CSPICTRL_DR_SHIFT;
> +		MX21_CSPICTRL_DR_SHIFT;
>  	reg |= config->bpw - 1;
>  
>  	if (config->mode & SPI_CPHA)
> -		reg |= MX27_CSPICTRL_PHA;
> +		reg |= MX21_CSPICTRL_PHA;
>  	if (config->mode & SPI_CPOL)
> -		reg |= MX27_CSPICTRL_POL;
> +		reg |= MX21_CSPICTRL_POL;
>  	if (config->mode & SPI_CS_HIGH)
> -		reg |= MX27_CSPICTRL_SSPOL;
> +		reg |= MX21_CSPICTRL_SSPOL;
>  	if (cs < 0)
> -		reg |= (cs + 32) << MX27_CSPICTRL_CS_SHIFT;
> +		reg |= (cs + 32) << MX21_CSPICTRL_CS_SHIFT;
>  
>  	writel(reg, spi_imx->base + MXC_CSPICTRL);
>  
>  	return 0;
>  }
>  
> -static int __maybe_unused mx27_rx_available(struct spi_imx_data *spi_imx)
> +static int __maybe_unused mx21_rx_available(struct spi_imx_data *spi_imx)
>  {
> -	return readl(spi_imx->base + MXC_CSPIINT) & MX27_INTREG_RR;
> +	return readl(spi_imx->base + MXC_CSPIINT) & MX21_INTREG_RR;
>  }
>  
> -static void __maybe_unused spi_imx0_0_reset(struct spi_imx_data *spi_imx)
> +static void __maybe_unused mx21_reset(struct spi_imx_data *spi_imx)
>  {
>  	writel(1, spi_imx->base + MXC_RESET);
>  }
> @@ -552,11 +553,11 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
>  #endif
>  #ifdef CONFIG_SPI_IMX_VER_0_0
>  	[SPI_IMX_VER_0_0] = {
> -		.intctrl = mx27_intctrl,
> -		.config = mx27_config,
> -		.trigger = mx27_trigger,
> -		.rx_available = mx27_rx_available,
> -		.reset = spi_imx0_0_reset,
> +		.intctrl = mx21_intctrl,
> +		.config = mx21_config,
> +		.trigger = mx21_trigger,
> +		.rx_available = mx21_rx_available,
> +		.reset = mx21_reset,
>  		.fifosize = 8,
>  	},
>  #endif
> -- 
> 1.7.4.1
> 
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
  2011-07-11  7:15     ` Lothar Waßmann
       [not found]       ` <19994.41750.920408.162356-VjFSrY7JcPWvSplVBqRQBQ@public.gmane.org>
@ 2011-07-11  7:35       ` Shawn Guo
       [not found]         ` <20110711073523.GA19105-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
  1 sibling, 1 reply; 21+ messages in thread
From: Shawn Guo @ 2011-07-11  7:35 UTC (permalink / raw)
  To: Lothar Waßmann
  Cc: patches, devicetree-discuss, Grant Likely, Uwe Kleine-König,
	spi-devel-general, Shawn Guo, Sascha Hauer, linux-arm-kernel

On Mon, Jul 11, 2011 at 09:15:34AM +0200, Lothar Waßmann wrote:
> Hi,
> 
> Shawn Guo writes:
> > spi_imx_devtype_data has already been driver private data.  There is
> > really no need to make a copy in spi_imx_data.  Instead, a reference
> > pointer works perfectly fine.
> > 
> You obviously overlooked, that the copy is done on purpose to keep
> only the data that is actually needed and discard everything else
> after initialisation.
> 
I did not overlook that, as I removed __devinitdata there.

-- 
Regards,
Shawn

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 4/7] spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4
       [not found]     ` <1310231801-18761-5-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-11  7:38       ` Uwe Kleine-König
  0 siblings, 0 replies; 21+ messages in thread
From: Uwe Kleine-König @ 2011-07-11  7:38 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:38AM +0800, Shawn Guo wrote:
> The only difference between SPI_IMX_VER_0_7 and SPI_IMX_VER_0_4 is
> .config function.  The patch uses cpu_is_mx35 (to be removed) as the
> temporary solution to consolidate functions spi_imx0_4_config and
> spi_imx0_7_config into mx31_config.  As a result, type SPI_IMX_VER_0_7
> can be merged into SPI_IMX_VER_0_4.
> 
> It also renames function spi_imx0_4_reset to mx31_reset to keep
> consistency with other function naming.
> 
> A couple of redundant macros, MX3_CSPISTAT and MX3_CSPISTAT_RR,
> together with the useless type SPI_IMX_VER_0_5 also get cleaned up.
s/useless/unused/?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 6/7] spi/imx: copy gpio number passed by platform data into driver private data
       [not found]     ` <1310231801-18761-7-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-11  7:45       ` Uwe Kleine-König
  0 siblings, 0 replies; 21+ messages in thread
From: Uwe Kleine-König @ 2011-07-11  7:45 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:40AM +0800, Shawn Guo wrote:
> It copies gpio number passed via platform data embedded pointer into
> driver private data, so that we do not need to refer to this embedded
> pointer passed by platform data after probe function exits.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> ---
>  drivers/spi/spi-imx.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 2ed9c32..ad61828 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -84,7 +84,6 @@ struct spi_imx_data {
>  	int irq;
>  	struct clk *clk;
>  	unsigned long spi_clk;
> -	int *chipselect;
>  
>  	unsigned int count;
>  	void (*tx)(struct spi_imx_data *);
> @@ -94,6 +93,7 @@ struct spi_imx_data {
>  	unsigned int txfifo; /* number of words pushed in tx FIFO */
>  
>  	struct spi_imx_devtype_data *devtype_data;
> +	int chipselect[0];
It's not needed to use a zero-length array here (which is a gcc
extension). A (C99) flexible array member should be fine.
Long words short: s/0//

>  };
>  
>  static inline int is_imx27_cspi(struct spi_imx_data *d)
> @@ -743,7 +743,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  	struct spi_master *master;
>  	struct spi_imx_data *spi_imx;
>  	struct resource *res;
> -	int i, ret;
> +	int i, ret, num_cs;
>  
>  	mxc_platform_info = dev_get_platdata(&pdev->dev);
>  	if (!mxc_platform_info) {
> @@ -751,20 +751,22 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	master = spi_alloc_master(&pdev->dev, sizeof(struct spi_imx_data));
> +	num_cs = mxc_platform_info->num_chipselect;
> +	master = spi_alloc_master(&pdev->dev,
> +			sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
>  	if (!master)
>  		return -ENOMEM;
>  
>  	platform_set_drvdata(pdev, master);
>  
>  	master->bus_num = pdev->id;
> -	master->num_chipselect = mxc_platform_info->num_chipselect;
> +	master->num_chipselect = num_cs;
>  
>  	spi_imx = spi_master_get_devdata(master);
>  	spi_imx->bitbang.master = spi_master_get(master);
> -	spi_imx->chipselect = mxc_platform_info->chipselect;
>  
>  	for (i = 0; i < master->num_chipselect; i++) {
> +		spi_imx->chipselect[i] = mxc_platform_info->chipselect[i];
>  		if (spi_imx->chipselect[i] < 0)
>  			continue;
>  		ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME);
> -- 
> 1.7.4.1
> 
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
  2011-07-11  7:31         ` Uwe Kleine-König
@ 2011-07-11  7:49           ` Lothar Waßmann
  0 siblings, 0 replies; 21+ messages in thread
From: Lothar Waßmann @ 2011-07-11  7:49 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: patches, devicetree-discuss, Grant Likely, spi-devel-general,
	Shawn Guo, Sascha Hauer, linux-arm-kernel

Uwe Kleine-König writes:
> On Mon, Jul 11, 2011 at 09:15:34AM +0200, Lothar Waßmann wrote:
> > Hi,
> > 
> > Shawn Guo writes:
> > > spi_imx_devtype_data has already been driver private data.  There is
> > > really no need to make a copy in spi_imx_data.  Instead, a reference
> > > pointer works perfectly fine.
> > > 
> > You obviously overlooked, that the copy is done on purpose to keep
> > only the data that is actually needed and discard everything else
> > after initialisation.
> though you could argue that __devinitdata isn't discarded on modern
> systems anyhow (and Shawn's patch takes care of removing that
> annotation).
> 
Shawn's comment should probably have reflected that...


Lothar Waßmann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info@karo-electronics.de
___________________________________________________________

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data
       [not found]     ` <1310231801-18761-2-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-15  2:53       ` Grant Likely
  0 siblings, 0 replies; 21+ messages in thread
From: Grant Likely @ 2011-07-15  2:53 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:35AM +0800, Shawn Guo wrote:
> spi_imx_devtype_data has already been driver private data.  There is
> really no need to make a copy in spi_imx_data.  Instead, a reference
> pointer works perfectly fine.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

Applied, thanks.

g.

> ---
>  drivers/spi/spi-imx.c |   24 ++++++++++++------------
>  1 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 69d6dba..1c55dc9 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -96,7 +96,7 @@ struct spi_imx_data {
>  	const void *tx_buf;
>  	unsigned int txfifo; /* number of words pushed in tx FIFO */
>  
> -	struct spi_imx_devtype_data devtype_data;
> +	struct spi_imx_devtype_data *devtype_data;
>  };
>  
>  #define MXC_SPI_BUF_RX(type)						\
> @@ -539,7 +539,7 @@ static void __maybe_unused mx1_reset(struct spi_imx_data *spi_imx)
>   * These version numbers are taken from the Freescale driver.  Unfortunately it
>   * doesn't support i.MX1, so this entry doesn't match the scheme. :-(
>   */
> -static struct spi_imx_devtype_data spi_imx_devtype_data[] __devinitdata = {
> +static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
>  #ifdef CONFIG_SPI_IMX_VER_IMX1
>  	[SPI_IMX_VER_IMX1] = {
>  		.intctrl = mx1_intctrl,
> @@ -607,21 +607,21 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active)
>  
>  static void spi_imx_push(struct spi_imx_data *spi_imx)
>  {
> -	while (spi_imx->txfifo < spi_imx->devtype_data.fifosize) {
> +	while (spi_imx->txfifo < spi_imx->devtype_data->fifosize) {
>  		if (!spi_imx->count)
>  			break;
>  		spi_imx->tx(spi_imx);
>  		spi_imx->txfifo++;
>  	}
>  
> -	spi_imx->devtype_data.trigger(spi_imx);
> +	spi_imx->devtype_data->trigger(spi_imx);
>  }
>  
>  static irqreturn_t spi_imx_isr(int irq, void *dev_id)
>  {
>  	struct spi_imx_data *spi_imx = dev_id;
>  
> -	while (spi_imx->devtype_data.rx_available(spi_imx)) {
> +	while (spi_imx->devtype_data->rx_available(spi_imx)) {
>  		spi_imx->rx(spi_imx);
>  		spi_imx->txfifo--;
>  	}
> @@ -635,12 +635,12 @@ static irqreturn_t spi_imx_isr(int irq, void *dev_id)
>  		/* No data left to push, but still waiting for rx data,
>  		 * enable receive data available interrupt.
>  		 */
> -		spi_imx->devtype_data.intctrl(
> +		spi_imx->devtype_data->intctrl(
>  				spi_imx, MXC_INT_RR);
>  		return IRQ_HANDLED;
>  	}
>  
> -	spi_imx->devtype_data.intctrl(spi_imx, 0);
> +	spi_imx->devtype_data->intctrl(spi_imx, 0);
>  	complete(&spi_imx->xfer_done);
>  
>  	return IRQ_HANDLED;
> @@ -677,7 +677,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
>  	} else
>  		BUG();
>  
> -	spi_imx->devtype_data.config(spi_imx, &config);
> +	spi_imx->devtype_data->config(spi_imx, &config);
>  
>  	return 0;
>  }
> @@ -696,7 +696,7 @@ static int spi_imx_transfer(struct spi_device *spi,
>  
>  	spi_imx_push(spi_imx);
>  
> -	spi_imx->devtype_data.intctrl(spi_imx, MXC_INT_TE);
> +	spi_imx->devtype_data->intctrl(spi_imx, MXC_INT_TE);
>  
>  	wait_for_completion(&spi_imx->xfer_done);
>  
> @@ -811,7 +811,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  	init_completion(&spi_imx->xfer_done);
>  
>  	spi_imx->devtype_data =
> -		spi_imx_devtype_data[pdev->id_entry->driver_data];
> +		&spi_imx_devtype_data[pdev->id_entry->driver_data];
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!res) {
> @@ -854,9 +854,9 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  	clk_enable(spi_imx->clk);
>  	spi_imx->spi_clk = clk_get_rate(spi_imx->clk);
>  
> -	spi_imx->devtype_data.reset(spi_imx);
> +	spi_imx->devtype_data->reset(spi_imx);
>  
> -	spi_imx->devtype_data.intctrl(spi_imx, 0);
> +	spi_imx->devtype_data->intctrl(spi_imx, 0);
>  
>  	ret = spi_bitbang_start(&spi_imx->bitbang);
>  	if (ret) {
> -- 
> 1.7.4.1
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro
       [not found]         ` <20110711073523.GB13840-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2011-07-15  2:53           ` Grant Likely
  0 siblings, 0 replies; 21+ messages in thread
From: Grant Likely @ 2011-07-15  2:53 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Mon, Jul 11, 2011 at 09:35:23AM +0200, Uwe Kleine-König wrote:
> On Sun, Jul 10, 2011 at 01:16:36AM +0800, Shawn Guo wrote:
> > SPI_IMX_VER_0_0 covers i.mx21 and i.mx27.  It makes more sense to
> > use mx21 rather than mx27 to name SPI_IMX_VER_0_0 function and
> > macro, since i.mx21 comes out ealier than i.mx27.
> > 
> > Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> > Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> > ---
> >  drivers/spi/spi-imx.c |   67 +++++++++++++++++++++++++------------------------
> >  1 files changed, 34 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> > index 1c55dc9..ad928b1 100644
> > --- a/drivers/spi/spi-imx.c
> > +++ b/drivers/spi/spi-imx.c
> > @@ -406,70 +406,71 @@ static void __maybe_unused spi_imx0_4_reset(struct spi_imx_data *spi_imx)
> >  		readl(spi_imx->base + MXC_CSPIRXDATA);
> >  }
> >  
> > -#define MX27_INTREG_RR		(1 << 4)
> > -#define MX27_INTREG_TEEN	(1 << 9)
> > -#define MX27_INTREG_RREN	(1 << 13)
> > -
> > -#define MX27_CSPICTRL_POL	(1 << 5)
> > -#define MX27_CSPICTRL_PHA	(1 << 6)
> > -#define MX27_CSPICTRL_SSPOL	(1 << 8)
> > -#define MX27_CSPICTRL_XCH	(1 << 9)
> > -#define MX27_CSPICTRL_ENABLE	(1 << 10)
> > -#define MX27_CSPICTRL_MASTER	(1 << 11)
> > -#define MX27_CSPICTRL_DR_SHIFT	14
> > -#define MX27_CSPICTRL_CS_SHIFT	19
> > -
> > -static void __maybe_unused mx27_intctrl(struct spi_imx_data *spi_imx, int enable)
> > +#define MX21_INTREG_RR		(1 << 4)
> > +#define MX21_INTREG_TEEN	(1 << 9)
> > +#define MX21_INTREG_RREN	(1 << 13)
> > +
> > +#define MX21_CSPICTRL_POL	(1 << 5)
> > +#define MX21_CSPICTRL_PHA	(1 << 6)
> > +#define MX21_CSPICTRL_SSPOL	(1 << 8)
> > +#define MX21_CSPICTRL_XCH	(1 << 9)
> > +#define MX21_CSPICTRL_ENABLE	(1 << 10)
> > +#define MX21_CSPICTRL_MASTER	(1 << 11)
> > +#define MX21_CSPICTRL_DR_SHIFT	14
> > +#define MX21_CSPICTRL_CS_SHIFT	19
> > +
> > +static void __maybe_unused
> > +mx21_intctrl(struct spi_imx_data *spi_imx, int enable)
> this needs to be intended. I usually use 2 tabs (and I'm quite annoyed
> that vim doesn't do that for me).

More importantly, the function name should be on the same line as the
annotations and return value.  When grepping for function names, it is
more important to see the annotations that the parameters (you can
tell visually if there are parameters on the next line, but you can't
tell if there are extra annotations).

I've fixed it up.

Applied, thanks.

g.

> 
> >  {
> >  	unsigned int val = 0;
> >  
> >  	if (enable & MXC_INT_TE)
> > -		val |= MX27_INTREG_TEEN;
> > +		val |= MX21_INTREG_TEEN;
> >  	if (enable & MXC_INT_RR)
> > -		val |= MX27_INTREG_RREN;
> > +		val |= MX21_INTREG_RREN;
> >  
> >  	writel(val, spi_imx->base + MXC_CSPIINT);
> >  }
> >  
> > -static void __maybe_unused mx27_trigger(struct spi_imx_data *spi_imx)
> > +static void __maybe_unused mx21_trigger(struct spi_imx_data *spi_imx)
> >  {
> >  	unsigned int reg;
> >  
> >  	reg = readl(spi_imx->base + MXC_CSPICTRL);
> > -	reg |= MX27_CSPICTRL_XCH;
> > +	reg |= MX21_CSPICTRL_XCH;
> >  	writel(reg, spi_imx->base + MXC_CSPICTRL);
> >  }
> >  
> > -static int __maybe_unused mx27_config(struct spi_imx_data *spi_imx,
> > +static int __maybe_unused mx21_config(struct spi_imx_data *spi_imx,
> >  		struct spi_imx_config *config)
> >  {
> > -	unsigned int reg = MX27_CSPICTRL_ENABLE | MX27_CSPICTRL_MASTER;
> > +	unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER;
> >  	int cs = spi_imx->chipselect[config->cs];
> >  
> >  	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
> > -		MX27_CSPICTRL_DR_SHIFT;
> > +		MX21_CSPICTRL_DR_SHIFT;
> >  	reg |= config->bpw - 1;
> >  
> >  	if (config->mode & SPI_CPHA)
> > -		reg |= MX27_CSPICTRL_PHA;
> > +		reg |= MX21_CSPICTRL_PHA;
> >  	if (config->mode & SPI_CPOL)
> > -		reg |= MX27_CSPICTRL_POL;
> > +		reg |= MX21_CSPICTRL_POL;
> >  	if (config->mode & SPI_CS_HIGH)
> > -		reg |= MX27_CSPICTRL_SSPOL;
> > +		reg |= MX21_CSPICTRL_SSPOL;
> >  	if (cs < 0)
> > -		reg |= (cs + 32) << MX27_CSPICTRL_CS_SHIFT;
> > +		reg |= (cs + 32) << MX21_CSPICTRL_CS_SHIFT;
> >  
> >  	writel(reg, spi_imx->base + MXC_CSPICTRL);
> >  
> >  	return 0;
> >  }
> >  
> > -static int __maybe_unused mx27_rx_available(struct spi_imx_data *spi_imx)
> > +static int __maybe_unused mx21_rx_available(struct spi_imx_data *spi_imx)
> >  {
> > -	return readl(spi_imx->base + MXC_CSPIINT) & MX27_INTREG_RR;
> > +	return readl(spi_imx->base + MXC_CSPIINT) & MX21_INTREG_RR;
> >  }
> >  
> > -static void __maybe_unused spi_imx0_0_reset(struct spi_imx_data *spi_imx)
> > +static void __maybe_unused mx21_reset(struct spi_imx_data *spi_imx)
> >  {
> >  	writel(1, spi_imx->base + MXC_RESET);
> >  }
> > @@ -552,11 +553,11 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
> >  #endif
> >  #ifdef CONFIG_SPI_IMX_VER_0_0
> >  	[SPI_IMX_VER_0_0] = {
> > -		.intctrl = mx27_intctrl,
> > -		.config = mx27_config,
> > -		.trigger = mx27_trigger,
> > -		.rx_available = mx27_rx_available,
> > -		.reset = spi_imx0_0_reset,
> > +		.intctrl = mx21_intctrl,
> > +		.config = mx21_config,
> > +		.trigger = mx21_trigger,
> > +		.rx_available = mx21_rx_available,
> > +		.reset = mx21_reset,
> >  		.fifosize = 8,
> >  	},
> >  #endif
> > -- 
> > 1.7.4.1
> > 
> > 
> 
> -- 
> Pengutronix e.K.                           | Uwe Kleine-König            |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 5/7] spi/imx: use soc name in spi device type naming scheme
       [not found]     ` <1310231801-18761-6-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-15  2:53       ` Grant Likely
  0 siblings, 0 replies; 21+ messages in thread
From: Grant Likely @ 2011-07-15  2:53 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:39AM +0800, Shawn Guo wrote:
> Software defined version number is not stable enough to be used
> in device type naming scheme.  The patch changes it to use implicit
> soc name for spi device type definition.  In this way, we can easily
> align the naming scheme with device tree binding, which comes later.
> 
> It removes fifosize from spi_imx_data and adds devtype there, so that
> fifosize can be set in an inline function according to devtype.
> Also, cpu_is_mx can be replaced by inline functions checking devtype.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

Applied, thanks.

g.

> ---
>  arch/arm/mach-imx/clock-imx25.c              |    7 +-
>  arch/arm/mach-mx5/clock-mx51-mx53.c          |   11 +-
>  arch/arm/plat-mxc/devices/platform-spi_imx.c |   12 +-
>  drivers/spi/Kconfig                          |   12 --
>  drivers/spi/spi-imx.c                        |  208 ++++++++++++++------------
>  5 files changed, 128 insertions(+), 122 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/clock-imx25.c b/arch/arm/mach-imx/clock-imx25.c
> index 9bb9062..17d6d1b 100644
> --- a/arch/arm/mach-imx/clock-imx25.c
> +++ b/arch/arm/mach-imx/clock-imx25.c
> @@ -283,9 +283,10 @@ static struct clk_lookup lookups[] = {
>  	_REGISTER_CLOCK("mxc-ehci.2", "usb", usbotg_clk)
>  	_REGISTER_CLOCK("fsl-usb2-udc", "usb", usbotg_clk)
>  	_REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk)
> -	_REGISTER_CLOCK("imx25-cspi.0", NULL, cspi1_clk)
> -	_REGISTER_CLOCK("imx25-cspi.1", NULL, cspi2_clk)
> -	_REGISTER_CLOCK("imx25-cspi.2", NULL, cspi3_clk)
> +	/* i.mx25 has the i.mx35 type cspi */
> +	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi1_clk)
> +	_REGISTER_CLOCK("imx35-cspi.1", NULL, cspi2_clk)
> +	_REGISTER_CLOCK("imx35-cspi.2", NULL, cspi3_clk)
>  	_REGISTER_CLOCK("mxc_pwm.0", NULL, pwm1_clk)
>  	_REGISTER_CLOCK("mxc_pwm.1", NULL, pwm2_clk)
>  	_REGISTER_CLOCK("mxc_pwm.2", NULL, pwm3_clk)
> diff --git a/arch/arm/mach-mx5/clock-mx51-mx53.c b/arch/arm/mach-mx5/clock-mx51-mx53.c
> index e00c427..31d904c 100644
> --- a/arch/arm/mach-mx5/clock-mx51-mx53.c
> +++ b/arch/arm/mach-mx5/clock-mx51-mx53.c
> @@ -1453,7 +1453,8 @@ static struct clk_lookup mx51_lookups[] = {
>  	_REGISTER_CLOCK(NULL, "gpt_32k", gpt_32k_clk)
>  	_REGISTER_CLOCK("imx51-ecspi.0", NULL, ecspi1_clk)
>  	_REGISTER_CLOCK("imx51-ecspi.1", NULL, ecspi2_clk)
> -	_REGISTER_CLOCK("imx51-cspi.0", NULL, cspi_clk)
> +	/* i.mx51 has the i.mx35 type cspi */
> +	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi_clk)
>  	_REGISTER_CLOCK("sdhci-esdhc-imx51.0", NULL, esdhc1_clk)
>  	_REGISTER_CLOCK("sdhci-esdhc-imx51.1", NULL, esdhc2_clk)
>  	_REGISTER_CLOCK("sdhci-esdhc-imx51.2", NULL, esdhc3_clk)
> @@ -1486,9 +1487,11 @@ static struct clk_lookup mx53_lookups[] = {
>  	_REGISTER_CLOCK("sdhci-esdhc-imx53.1", NULL, esdhc2_mx53_clk)
>  	_REGISTER_CLOCK("sdhci-esdhc-imx53.2", NULL, esdhc3_mx53_clk)
>  	_REGISTER_CLOCK("sdhci-esdhc-imx53.3", NULL, esdhc4_mx53_clk)
> -	_REGISTER_CLOCK("imx53-ecspi.0", NULL, ecspi1_clk)
> -	_REGISTER_CLOCK("imx53-ecspi.1", NULL, ecspi2_clk)
> -	_REGISTER_CLOCK("imx53-cspi.0", NULL, cspi_clk)
> +	/* i.mx53 has the i.mx51 type ecspi */
> +	_REGISTER_CLOCK("imx51-ecspi.0", NULL, ecspi1_clk)
> +	_REGISTER_CLOCK("imx51-ecspi.1", NULL, ecspi2_clk)
> +	/* i.mx53 has the i.mx35 type cspi */
> +	_REGISTER_CLOCK("imx35-cspi.0", NULL, cspi_clk)
>  	_REGISTER_CLOCK("imx2-wdt.0", NULL, dummy_clk)
>  	_REGISTER_CLOCK("imx2-wdt.1", NULL, dummy_clk)
>  	_REGISTER_CLOCK("imx-sdma", NULL, sdma_clk)
> diff --git a/arch/arm/plat-mxc/devices/platform-spi_imx.c b/arch/arm/plat-mxc/devices/platform-spi_imx.c
> index f97eb36..9bfae8b 100644
> --- a/arch/arm/plat-mxc/devices/platform-spi_imx.c
> +++ b/arch/arm/plat-mxc/devices/platform-spi_imx.c
> @@ -40,9 +40,10 @@ const struct imx_spi_imx_data imx21_cspi_data[] __initconst = {
>  #endif
>  
>  #ifdef CONFIG_SOC_IMX25
> +/* i.mx25 has the i.mx35 type cspi */
>  const struct imx_spi_imx_data imx25_cspi_data[] __initconst = {
>  #define imx25_cspi_data_entry(_id, _hwid)				\
> -	imx_spi_imx_data_entry(MX25, CSPI, "imx25-cspi", _id, _hwid, SZ_16K)
> +	imx_spi_imx_data_entry(MX25, CSPI, "imx35-cspi", _id, _hwid, SZ_16K)
>  	imx25_cspi_data_entry(0, 1),
>  	imx25_cspi_data_entry(1, 2),
>  	imx25_cspi_data_entry(2, 3),
> @@ -79,8 +80,9 @@ const struct imx_spi_imx_data imx35_cspi_data[] __initconst = {
>  #endif /* ifdef CONFIG_SOC_IMX35 */
>  
>  #ifdef CONFIG_SOC_IMX51
> +/* i.mx51 has the i.mx35 type cspi */
>  const struct imx_spi_imx_data imx51_cspi_data __initconst =
> -	imx_spi_imx_data_entry_single(MX51, CSPI, "imx51-cspi", 2, , SZ_4K);
> +	imx_spi_imx_data_entry_single(MX51, CSPI, "imx35-cspi", 2, , SZ_4K);
>  
>  const struct imx_spi_imx_data imx51_ecspi_data[] __initconst = {
>  #define imx51_ecspi_data_entry(_id, _hwid)				\
> @@ -91,12 +93,14 @@ const struct imx_spi_imx_data imx51_ecspi_data[] __initconst = {
>  #endif /* ifdef CONFIG_SOC_IMX51 */
>  
>  #ifdef CONFIG_SOC_IMX53
> +/* i.mx53 has the i.mx35 type cspi */
>  const struct imx_spi_imx_data imx53_cspi_data __initconst =
> -	imx_spi_imx_data_entry_single(MX53, CSPI, "imx53-cspi", 0, , SZ_4K);
> +	imx_spi_imx_data_entry_single(MX53, CSPI, "imx35-cspi", 0, , SZ_4K);
>  
> +/* i.mx53 has the i.mx51 type ecspi */
>  const struct imx_spi_imx_data imx53_ecspi_data[] __initconst = {
>  #define imx53_ecspi_data_entry(_id, _hwid)				\
> -	imx_spi_imx_data_entry(MX53, ECSPI, "imx53-ecspi", _id, _hwid, SZ_4K)
> +	imx_spi_imx_data_entry(MX53, ECSPI, "imx51-ecspi", _id, _hwid, SZ_4K)
>  	imx53_ecspi_data_entry(0, 1),
>  	imx53_ecspi_data_entry(1, 2),
>  };
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index c327cf3..52e2900 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -154,18 +154,6 @@ config SPI_GPIO
>  	  GPIO operations, you should be able to leverage that for better
>  	  speed with a custom version of this driver; see the source code.
>  
> -config SPI_IMX_VER_IMX1
> -	def_bool y if SOC_IMX1
> -
> -config SPI_IMX_VER_0_0
> -	def_bool y if SOC_IMX21 || SOC_IMX27
> -
> -config SPI_IMX_VER_0_4
> -	def_bool y if ARCH_MX25 || SOC_IMX31 || SOC_IMX35 || SOC_IMX51 || SOC_IMX53
> -
> -config SPI_IMX_VER_2_3
> -	def_bool y if SOC_IMX51 || SOC_IMX53
> -
>  config SPI_IMX
>  	tristate "Freescale i.MX SPI controllers"
>  	depends on ARCH_MXC
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index b282351..2ed9c32 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -57,10 +57,12 @@ struct spi_imx_config {
>  };
>  
>  enum spi_imx_devtype {
> -	SPI_IMX_VER_IMX1,
> -	SPI_IMX_VER_0_0,
> -	SPI_IMX_VER_0_4,
> -	SPI_IMX_VER_2_3,
> +	IMX1_CSPI,
> +	IMX21_CSPI,
> +	IMX27_CSPI,
> +	IMX31_CSPI,
> +	IMX35_CSPI,	/* CSPI on all i.mx except above */
> +	IMX51_ECSPI,	/* ECSPI on i.mx51 and later */
>  };
>  
>  struct spi_imx_data;
> @@ -71,7 +73,7 @@ struct spi_imx_devtype_data {
>  	void (*trigger)(struct spi_imx_data *);
>  	int (*rx_available)(struct spi_imx_data *);
>  	void (*reset)(struct spi_imx_data *);
> -	unsigned int fifosize;
> +	enum spi_imx_devtype devtype;
>  };
>  
>  struct spi_imx_data {
> @@ -94,6 +96,21 @@ struct spi_imx_data {
>  	struct spi_imx_devtype_data *devtype_data;
>  };
>  
> +static inline int is_imx27_cspi(struct spi_imx_data *d)
> +{
> +	return d->devtype_data->devtype == IMX27_CSPI;
> +}
> +
> +static inline int is_imx35_cspi(struct spi_imx_data *d)
> +{
> +	return d->devtype_data->devtype == IMX35_CSPI;
> +}
> +
> +static inline unsigned spi_imx_get_fifosize(struct spi_imx_data *d)
> +{
> +	return (d->devtype_data->devtype == IMX51_ECSPI) ? 64 : 8;
> +}
> +
>  #define MXC_SPI_BUF_RX(type)						\
>  static void spi_imx_buf_rx_##type(struct spi_imx_data *spi_imx)		\
>  {									\
> @@ -135,14 +152,9 @@ static int mxc_clkdivs[] = {0, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192,
>  
>  /* MX21, MX27 */
>  static unsigned int spi_imx_clkdiv_1(unsigned int fin,
> -		unsigned int fspi)
> +		unsigned int fspi, unsigned int max)
>  {
> -	int i, max;
> -
> -	if (cpu_is_mx21())
> -		max = 18;
> -	else
> -		max = 16;
> +	int i;
>  
>  	for (i = 2; i < max; i++)
>  		if (fspi * mxc_clkdivs[i] >= fin)
> @@ -348,7 +360,7 @@ static int __maybe_unused mx31_config(struct spi_imx_data *spi_imx,
>  	reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
>  		MX31_CSPICTRL_DR_SHIFT;
>  
> -	if (cpu_is_mx35()) {
> +	if (is_imx35_cspi(spi_imx)) {
>  		reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
>  		reg |= MX31_CSPICTRL_SSCTL;
>  	} else {
> @@ -363,8 +375,8 @@ static int __maybe_unused mx31_config(struct spi_imx_data *spi_imx,
>  		reg |= MX31_CSPICTRL_SSPOL;
>  	if (cs < 0)
>  		reg |= (cs + 32) <<
> -			(cpu_is_mx35() ? MX35_CSPICTRL_CS_SHIFT :
> -					 MX31_CSPICTRL_CS_SHIFT);
> +			(is_imx35_cspi(spi_imx) ? MX35_CSPICTRL_CS_SHIFT :
> +						  MX31_CSPICTRL_CS_SHIFT);
>  
>  	writel(reg, spi_imx->base + MXC_CSPICTRL);
>  
> @@ -423,8 +435,9 @@ static int __maybe_unused mx21_config(struct spi_imx_data *spi_imx,
>  {
>  	unsigned int reg = MX21_CSPICTRL_ENABLE | MX21_CSPICTRL_MASTER;
>  	int cs = spi_imx->chipselect[config->cs];
> +	unsigned int max = is_imx27_cspi(spi_imx) ? 16 : 18;
>  
> -	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
> +	reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz, max) <<
>  		MX21_CSPICTRL_DR_SHIFT;
>  	reg |= config->bpw - 1;
>  
> @@ -513,51 +526,84 @@ static void __maybe_unused mx1_reset(struct spi_imx_data *spi_imx)
>  	writel(1, spi_imx->base + MXC_RESET);
>  }
>  
> -/*
> - * These version numbers are taken from the Freescale driver.  Unfortunately it
> - * doesn't support i.MX1, so this entry doesn't match the scheme. :-(
> - */
> -static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
> -#ifdef CONFIG_SPI_IMX_VER_IMX1
> -	[SPI_IMX_VER_IMX1] = {
> -		.intctrl = mx1_intctrl,
> -		.config = mx1_config,
> -		.trigger = mx1_trigger,
> -		.rx_available = mx1_rx_available,
> -		.reset = mx1_reset,
> -		.fifosize = 8,
> -	},
> -#endif
> -#ifdef CONFIG_SPI_IMX_VER_0_0
> -	[SPI_IMX_VER_0_0] = {
> -		.intctrl = mx21_intctrl,
> -		.config = mx21_config,
> -		.trigger = mx21_trigger,
> -		.rx_available = mx21_rx_available,
> -		.reset = mx21_reset,
> -		.fifosize = 8,
> -	},
> -#endif
> -#ifdef CONFIG_SPI_IMX_VER_0_4
> -	[SPI_IMX_VER_0_4] = {
> -		.intctrl = mx31_intctrl,
> -		.config = mx31_config,
> -		.trigger = mx31_trigger,
> -		.rx_available = mx31_rx_available,
> -		.reset = mx31_reset,
> -		.fifosize = 8,
> -	},
> -#endif
> -#ifdef CONFIG_SPI_IMX_VER_2_3
> -	[SPI_IMX_VER_2_3] = {
> -		.intctrl = mx51_ecspi_intctrl,
> -		.config = mx51_ecspi_config,
> -		.trigger = mx51_ecspi_trigger,
> -		.rx_available = mx51_ecspi_rx_available,
> -		.reset = mx51_ecspi_reset,
> -		.fifosize = 64,
> -	},
> -#endif
> +static struct spi_imx_devtype_data imx1_cspi_devtype_data = {
> +	.intctrl = mx1_intctrl,
> +	.config = mx1_config,
> +	.trigger = mx1_trigger,
> +	.rx_available = mx1_rx_available,
> +	.reset = mx1_reset,
> +	.devtype = IMX1_CSPI,
> +};
> +
> +static struct spi_imx_devtype_data imx21_cspi_devtype_data = {
> +	.intctrl = mx21_intctrl,
> +	.config = mx21_config,
> +	.trigger = mx21_trigger,
> +	.rx_available = mx21_rx_available,
> +	.reset = mx21_reset,
> +	.devtype = IMX21_CSPI,
> +};
> +
> +static struct spi_imx_devtype_data imx27_cspi_devtype_data = {
> +	/* i.mx27 cspi shares the functions with i.mx21 one */
> +	.intctrl = mx21_intctrl,
> +	.config = mx21_config,
> +	.trigger = mx21_trigger,
> +	.rx_available = mx21_rx_available,
> +	.reset = mx21_reset,
> +	.devtype = IMX27_CSPI,
> +};
> +
> +static struct spi_imx_devtype_data imx31_cspi_devtype_data = {
> +	.intctrl = mx31_intctrl,
> +	.config = mx31_config,
> +	.trigger = mx31_trigger,
> +	.rx_available = mx31_rx_available,
> +	.reset = mx31_reset,
> +	.devtype = IMX31_CSPI,
> +};
> +
> +static struct spi_imx_devtype_data imx35_cspi_devtype_data = {
> +	/* i.mx35 and later cspi shares the functions with i.mx31 one */
> +	.intctrl = mx31_intctrl,
> +	.config = mx31_config,
> +	.trigger = mx31_trigger,
> +	.rx_available = mx31_rx_available,
> +	.reset = mx31_reset,
> +	.devtype = IMX35_CSPI,
> +};
> +
> +static struct spi_imx_devtype_data imx51_ecspi_devtype_data = {
> +	.intctrl = mx51_ecspi_intctrl,
> +	.config = mx51_ecspi_config,
> +	.trigger = mx51_ecspi_trigger,
> +	.rx_available = mx51_ecspi_rx_available,
> +	.reset = mx51_ecspi_reset,
> +	.devtype = IMX51_ECSPI,
> +};
> +
> +static struct platform_device_id spi_imx_devtype[] = {
> +	{
> +		.name = "imx1-cspi",
> +		.driver_data = (kernel_ulong_t) &imx1_cspi_devtype_data,
> +	}, {
> +		.name = "imx21-cspi",
> +		.driver_data = (kernel_ulong_t) &imx21_cspi_devtype_data,
> +	}, {
> +		.name = "imx27-cspi",
> +		.driver_data = (kernel_ulong_t) &imx27_cspi_devtype_data,
> +	}, {
> +		.name = "imx31-cspi",
> +		.driver_data = (kernel_ulong_t) &imx31_cspi_devtype_data,
> +	}, {
> +		.name = "imx35-cspi",
> +		.driver_data = (kernel_ulong_t) &imx35_cspi_devtype_data,
> +	}, {
> +		.name = "imx51-ecspi",
> +		.driver_data = (kernel_ulong_t) &imx51_ecspi_devtype_data,
> +	}, {
> +		/* sentinel */
> +	}
>  };
>  
>  static void spi_imx_chipselect(struct spi_device *spi, int is_active)
> @@ -575,7 +621,7 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active)
>  
>  static void spi_imx_push(struct spi_imx_data *spi_imx)
>  {
> -	while (spi_imx->txfifo < spi_imx->devtype_data->fifosize) {
> +	while (spi_imx->txfifo < spi_imx_get_fifosize(spi_imx)) {
>  		if (!spi_imx->count)
>  			break;
>  		spi_imx->tx(spi_imx);
> @@ -691,42 +737,6 @@ static void spi_imx_cleanup(struct spi_device *spi)
>  {
>  }
>  
> -static struct platform_device_id spi_imx_devtype[] = {
> -	{
> -		.name = "imx1-cspi",
> -		.driver_data = SPI_IMX_VER_IMX1,
> -	}, {
> -		.name = "imx21-cspi",
> -		.driver_data = SPI_IMX_VER_0_0,
> -	}, {
> -		.name = "imx25-cspi",
> -		.driver_data = SPI_IMX_VER_0_4,
> -	}, {
> -		.name = "imx27-cspi",
> -		.driver_data = SPI_IMX_VER_0_0,
> -	}, {
> -		.name = "imx31-cspi",
> -		.driver_data = SPI_IMX_VER_0_4,
> -	}, {
> -		.name = "imx35-cspi",
> -		.driver_data = SPI_IMX_VER_0_4,
> -	}, {
> -		.name = "imx51-cspi",
> -		.driver_data = SPI_IMX_VER_0_4,
> -	}, {
> -		.name = "imx51-ecspi",
> -		.driver_data = SPI_IMX_VER_2_3,
> -	}, {
> -		.name = "imx53-cspi",
> -		.driver_data = SPI_IMX_VER_0_4,
> -	}, {
> -		.name = "imx53-ecspi",
> -		.driver_data = SPI_IMX_VER_2_3,
> -	}, {
> -		/* sentinel */
> -	}
> -};
> -
>  static int __devinit spi_imx_probe(struct platform_device *pdev)
>  {
>  	struct spi_imx_master *mxc_platform_info;
> @@ -779,7 +789,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  	init_completion(&spi_imx->xfer_done);
>  
>  	spi_imx->devtype_data =
> -		&spi_imx_devtype_data[pdev->id_entry->driver_data];
> +		(struct spi_imx_devtype_data *) pdev->id_entry->driver_data;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!res) {
> -- 
> 1.7.4.1
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 3/7] spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 function and macro
       [not found]     ` <1310231801-18761-4-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-15  2:53       ` Grant Likely
  0 siblings, 0 replies; 21+ messages in thread
From: Grant Likely @ 2011-07-15  2:53 UTC (permalink / raw)
  To: Shawn Guo
  Cc: patches-QSEj5FYQhm4dnm+yROfE0A,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Uwe Kleine-König,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sascha Hauer,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Sun, Jul 10, 2011 at 01:16:37AM +0800, Shawn Guo wrote:
> It's confusing to use spi_imx2_3 to name SPI_IMX_VER_2_3 function
> and macro, as it easily make people think of imx2 and imx3.  It's
> better to use specific soc name just like what other SPI_IMX_VER
> do.  For SPI_IMX_VER_2_3 case, it will be mx51.  To distinguish it
> from CSPI on mx51, mx51_ecspi might be a good choice.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

Applied, thanks.

g.

> ---
>  drivers/spi/spi-imx.c |  107 +++++++++++++++++++++++++------------------------
>  1 files changed, 54 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index ad928b1..052959df 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -171,30 +171,30 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
>  	return 7;
>  }
>  
> -#define SPI_IMX2_3_CTRL		0x08
> -#define SPI_IMX2_3_CTRL_ENABLE		(1 <<  0)
> -#define SPI_IMX2_3_CTRL_XCH		(1 <<  2)
> -#define SPI_IMX2_3_CTRL_MODE_MASK	(0xf << 4)
> -#define SPI_IMX2_3_CTRL_POSTDIV_OFFSET	8
> -#define SPI_IMX2_3_CTRL_PREDIV_OFFSET	12
> -#define SPI_IMX2_3_CTRL_CS(cs)		((cs) << 18)
> -#define SPI_IMX2_3_CTRL_BL_OFFSET	20
> -
> -#define SPI_IMX2_3_CONFIG	0x0c
> -#define SPI_IMX2_3_CONFIG_SCLKPHA(cs)	(1 << ((cs) +  0))
> -#define SPI_IMX2_3_CONFIG_SCLKPOL(cs)	(1 << ((cs) +  4))
> -#define SPI_IMX2_3_CONFIG_SBBCTRL(cs)	(1 << ((cs) +  8))
> -#define SPI_IMX2_3_CONFIG_SSBPOL(cs)	(1 << ((cs) + 12))
> -
> -#define SPI_IMX2_3_INT		0x10
> -#define SPI_IMX2_3_INT_TEEN		(1 <<  0)
> -#define SPI_IMX2_3_INT_RREN		(1 <<  3)
> -
> -#define SPI_IMX2_3_STAT		0x18
> -#define SPI_IMX2_3_STAT_RR		(1 <<  3)
> +#define MX51_ECSPI_CTRL		0x08
> +#define MX51_ECSPI_CTRL_ENABLE		(1 <<  0)
> +#define MX51_ECSPI_CTRL_XCH		(1 <<  2)
> +#define MX51_ECSPI_CTRL_MODE_MASK	(0xf << 4)
> +#define MX51_ECSPI_CTRL_POSTDIV_OFFSET	8
> +#define MX51_ECSPI_CTRL_PREDIV_OFFSET	12
> +#define MX51_ECSPI_CTRL_CS(cs)		((cs) << 18)
> +#define MX51_ECSPI_CTRL_BL_OFFSET	20
> +
> +#define MX51_ECSPI_CONFIG	0x0c
> +#define MX51_ECSPI_CONFIG_SCLKPHA(cs)	(1 << ((cs) +  0))
> +#define MX51_ECSPI_CONFIG_SCLKPOL(cs)	(1 << ((cs) +  4))
> +#define MX51_ECSPI_CONFIG_SBBCTRL(cs)	(1 << ((cs) +  8))
> +#define MX51_ECSPI_CONFIG_SSBPOL(cs)	(1 << ((cs) + 12))
> +
> +#define MX51_ECSPI_INT		0x10
> +#define MX51_ECSPI_INT_TEEN		(1 <<  0)
> +#define MX51_ECSPI_INT_RREN		(1 <<  3)
> +
> +#define MX51_ECSPI_STAT		0x18
> +#define MX51_ECSPI_STAT_RR		(1 <<  3)
>  
>  /* MX51 eCSPI */
> -static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
> +static unsigned int mx51_ecspi_clkdiv(unsigned int fin, unsigned int fspi)
>  {
>  	/*
>  	 * there are two 4-bit dividers, the pre-divider divides by
> @@ -222,36 +222,37 @@ static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
>  
>  	pr_debug("%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
>  			__func__, fin, fspi, post, pre);
> -	return (pre << SPI_IMX2_3_CTRL_PREDIV_OFFSET) |
> -		(post << SPI_IMX2_3_CTRL_POSTDIV_OFFSET);
> +	return (pre << MX51_ECSPI_CTRL_PREDIV_OFFSET) |
> +		(post << MX51_ECSPI_CTRL_POSTDIV_OFFSET);
>  }
>  
> -static void __maybe_unused spi_imx2_3_intctrl(struct spi_imx_data *spi_imx, int enable)
> +static void __maybe_unused
> +mx51_ecspi_intctrl(struct spi_imx_data *spi_imx, int enable)
>  {
>  	unsigned val = 0;
>  
>  	if (enable & MXC_INT_TE)
> -		val |= SPI_IMX2_3_INT_TEEN;
> +		val |= MX51_ECSPI_INT_TEEN;
>  
>  	if (enable & MXC_INT_RR)
> -		val |= SPI_IMX2_3_INT_RREN;
> +		val |= MX51_ECSPI_INT_RREN;
>  
> -	writel(val, spi_imx->base + SPI_IMX2_3_INT);
> +	writel(val, spi_imx->base + MX51_ECSPI_INT);
>  }
>  
> -static void __maybe_unused spi_imx2_3_trigger(struct spi_imx_data *spi_imx)
> +static void __maybe_unused mx51_ecspi_trigger(struct spi_imx_data *spi_imx)
>  {
>  	u32 reg;
>  
> -	reg = readl(spi_imx->base + SPI_IMX2_3_CTRL);
> -	reg |= SPI_IMX2_3_CTRL_XCH;
> -	writel(reg, spi_imx->base + SPI_IMX2_3_CTRL);
> +	reg = readl(spi_imx->base + MX51_ECSPI_CTRL);
> +	reg |= MX51_ECSPI_CTRL_XCH;
> +	writel(reg, spi_imx->base + MX51_ECSPI_CTRL);
>  }
>  
> -static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
> +static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx,
>  		struct spi_imx_config *config)
>  {
> -	u32 ctrl = SPI_IMX2_3_CTRL_ENABLE, cfg = 0;
> +	u32 ctrl = MX51_ECSPI_CTRL_ENABLE, cfg = 0;
>  
>  	/*
>  	 * The hardware seems to have a race condition when changing modes. The
> @@ -260,42 +261,42 @@ static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
>  	 * the same time.
>  	 * So set master mode for all channels as we do not support slave mode.
>  	 */
> -	ctrl |= SPI_IMX2_3_CTRL_MODE_MASK;
> +	ctrl |= MX51_ECSPI_CTRL_MODE_MASK;
>  
>  	/* set clock speed */
> -	ctrl |= spi_imx2_3_clkdiv(spi_imx->spi_clk, config->speed_hz);
> +	ctrl |= mx51_ecspi_clkdiv(spi_imx->spi_clk, config->speed_hz);
>  
>  	/* set chip select to use */
> -	ctrl |= SPI_IMX2_3_CTRL_CS(config->cs);
> +	ctrl |= MX51_ECSPI_CTRL_CS(config->cs);
>  
> -	ctrl |= (config->bpw - 1) << SPI_IMX2_3_CTRL_BL_OFFSET;
> +	ctrl |= (config->bpw - 1) << MX51_ECSPI_CTRL_BL_OFFSET;
>  
> -	cfg |= SPI_IMX2_3_CONFIG_SBBCTRL(config->cs);
> +	cfg |= MX51_ECSPI_CONFIG_SBBCTRL(config->cs);
>  
>  	if (config->mode & SPI_CPHA)
> -		cfg |= SPI_IMX2_3_CONFIG_SCLKPHA(config->cs);
> +		cfg |= MX51_ECSPI_CONFIG_SCLKPHA(config->cs);
>  
>  	if (config->mode & SPI_CPOL)
> -		cfg |= SPI_IMX2_3_CONFIG_SCLKPOL(config->cs);
> +		cfg |= MX51_ECSPI_CONFIG_SCLKPOL(config->cs);
>  
>  	if (config->mode & SPI_CS_HIGH)
> -		cfg |= SPI_IMX2_3_CONFIG_SSBPOL(config->cs);
> +		cfg |= MX51_ECSPI_CONFIG_SSBPOL(config->cs);
>  
> -	writel(ctrl, spi_imx->base + SPI_IMX2_3_CTRL);
> -	writel(cfg, spi_imx->base + SPI_IMX2_3_CONFIG);
> +	writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
> +	writel(cfg, spi_imx->base + MX51_ECSPI_CONFIG);
>  
>  	return 0;
>  }
>  
> -static int __maybe_unused spi_imx2_3_rx_available(struct spi_imx_data *spi_imx)
> +static int __maybe_unused mx51_ecspi_rx_available(struct spi_imx_data *spi_imx)
>  {
> -	return readl(spi_imx->base + SPI_IMX2_3_STAT) & SPI_IMX2_3_STAT_RR;
> +	return readl(spi_imx->base + MX51_ECSPI_STAT) & MX51_ECSPI_STAT_RR;
>  }
>  
> -static void __maybe_unused spi_imx2_3_reset(struct spi_imx_data *spi_imx)
> +static void __maybe_unused mx51_ecspi_reset(struct spi_imx_data *spi_imx)
>  {
>  	/* drain receive buffer */
> -	while (spi_imx2_3_rx_available(spi_imx))
> +	while (mx51_ecspi_rx_available(spi_imx))
>  		readl(spi_imx->base + MXC_CSPIRXDATA);
>  }
>  
> @@ -583,11 +584,11 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
>  #endif
>  #ifdef CONFIG_SPI_IMX_VER_2_3
>  	[SPI_IMX_VER_2_3] = {
> -		.intctrl = spi_imx2_3_intctrl,
> -		.config = spi_imx2_3_config,
> -		.trigger = spi_imx2_3_trigger,
> -		.rx_available = spi_imx2_3_rx_available,
> -		.reset = spi_imx2_3_reset,
> +		.intctrl = mx51_ecspi_intctrl,
> +		.config = mx51_ecspi_config,
> +		.trigger = mx51_ecspi_trigger,
> +		.rx_available = mx51_ecspi_rx_available,
> +		.reset = mx51_ecspi_reset,
>  		.fifosize = 64,
>  	},
>  #endif
> -- 
> 1.7.4.1
> 

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2 7/7] spi/imx: add device tree probe support
       [not found]     ` <1310231801-18761-8-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
@ 2011-07-15  2:53       ` Grant Likely
  0 siblings, 0 replies; 21+ messages in thread
From: Grant Likely @ 2011-07-15  2:53 UTC (permalink / raw)
  To: Shawn Guo
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	patches-QSEj5FYQhm4dnm+yROfE0A

On Sun, Jul 10, 2011 at 01:16:41AM +0800, Shawn Guo wrote:
> It adds device tree probe support for spi-imx driver.
> 
> Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>

Applied, thanks.

g.

> ---
>  .../devicetree/bindings/spi/fsl-imx-cspi.txt       |   22 +++++++++++
>  drivers/spi/spi-imx.c                              |   38 ++++++++++++++++----
>  2 files changed, 53 insertions(+), 7 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
> 
> diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
> new file mode 100644
> index 0000000..9841057
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
> @@ -0,0 +1,22 @@
> +* Freescale (Enhanced) Configurable Serial Peripheral Interface
> +  (CSPI/eCSPI) for i.MX
> +
> +Required properties:
> +- compatible : Should be "fsl,<soc>-cspi" or "fsl,<soc>-ecspi"
> +- reg : Offset and length of the register set for the device
> +- interrupts : Should contain CSPI/eCSPI interrupt
> +- fsl,spi-num-chipselects : Contains the number of the chipselect
> +- cs-gpios : Specifies the gpio pins to be used for chipselects.
> +
> +Example:
> +
> +ecspi@70010000 {
> +	#address-cells = <1>;
> +	#size-cells = <0>;
> +	compatible = "fsl,imx51-ecspi";
> +	reg = <0x70010000 0x4000>;
> +	interrupts = <36>;
> +	fsl,spi-num-chipselects = <2>;
> +	cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */
> +		   <&gpio3 25 0>; /* GPIO4_25 */
> +};
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index ad61828..5456bcc 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -34,6 +34,9 @@
>  #include <linux/spi/spi.h>
>  #include <linux/spi/spi_bitbang.h>
>  #include <linux/types.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/of_gpio.h>
>  
>  #include <mach/spi.h>
>  
> @@ -606,6 +609,16 @@ static struct platform_device_id spi_imx_devtype[] = {
>  	}
>  };
>  
> +static const struct of_device_id spi_imx_dt_ids[] = {
> +	{ .compatible = "fsl,imx1-cspi", .data = &imx1_cspi_devtype_data, },
> +	{ .compatible = "fsl,imx21-cspi", .data = &imx21_cspi_devtype_data, },
> +	{ .compatible = "fsl,imx27-cspi", .data = &imx27_cspi_devtype_data, },
> +	{ .compatible = "fsl,imx31-cspi", .data = &imx31_cspi_devtype_data, },
> +	{ .compatible = "fsl,imx35-cspi", .data = &imx35_cspi_devtype_data, },
> +	{ .compatible = "fsl,imx51-ecspi", .data = &imx51_ecspi_devtype_data, },
> +	{ /* sentinel */ }
> +};
> +
>  static void spi_imx_chipselect(struct spi_device *spi, int is_active)
>  {
>  	struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
> @@ -739,19 +752,25 @@ static void spi_imx_cleanup(struct spi_device *spi)
>  
>  static int __devinit spi_imx_probe(struct platform_device *pdev)
>  {
> -	struct spi_imx_master *mxc_platform_info;
> +	struct device_node *np = pdev->dev.of_node;
> +	const struct of_device_id *of_id =
> +			of_match_device(spi_imx_dt_ids, &pdev->dev);
> +	struct spi_imx_master *mxc_platform_info =
> +			dev_get_platdata(&pdev->dev);
>  	struct spi_master *master;
>  	struct spi_imx_data *spi_imx;
>  	struct resource *res;
>  	int i, ret, num_cs;
>  
> -	mxc_platform_info = dev_get_platdata(&pdev->dev);
> -	if (!mxc_platform_info) {
> +	if (!np && !mxc_platform_info) {
>  		dev_err(&pdev->dev, "can't get the platform data\n");
>  		return -EINVAL;
>  	}
>  
> -	num_cs = mxc_platform_info->num_chipselect;
> +	ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs);
> +	if (ret < 0)
> +		num_cs = mxc_platform_info->num_chipselect;
> +
>  	master = spi_alloc_master(&pdev->dev,
>  			sizeof(struct spi_imx_data) + sizeof(int) * num_cs);
>  	if (!master)
> @@ -766,9 +785,12 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  	spi_imx->bitbang.master = spi_master_get(master);
>  
>  	for (i = 0; i < master->num_chipselect; i++) {
> -		spi_imx->chipselect[i] = mxc_platform_info->chipselect[i];
> -		if (spi_imx->chipselect[i] < 0)
> +		int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +		if (cs_gpio < 0)
> +			cs_gpio = mxc_platform_info->chipselect[i];
> +		if (cs_gpio < 0)
>  			continue;
> +		spi_imx->chipselect[i] = cs_gpio;
>  		ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME);
>  		if (ret) {
>  			while (i > 0) {
> @@ -790,7 +812,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  
>  	init_completion(&spi_imx->xfer_done);
>  
> -	spi_imx->devtype_data =
> +	spi_imx->devtype_data = of_id ? of_id->data :
>  		(struct spi_imx_devtype_data *) pdev->id_entry->driver_data;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> @@ -838,6 +860,7 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
>  
>  	spi_imx->devtype_data->intctrl(spi_imx, 0);
>  
> +	master->dev.of_node = pdev->dev.of_node;
>  	ret = spi_bitbang_start(&spi_imx->bitbang);
>  	if (ret) {
>  		dev_err(&pdev->dev, "bitbang start failed with %d\n", ret);
> @@ -900,6 +923,7 @@ static struct platform_driver spi_imx_driver = {
>  	.driver = {
>  		   .name = DRIVER_NAME,
>  		   .owner = THIS_MODULE,
> +		   .of_match_table = spi_imx_dt_ids,
>  		   },
>  	.id_table = spi_imx_devtype,
>  	.probe = spi_imx_probe,
> -- 
> 1.7.4.1
> 

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2011-07-15  2:53 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-09 17:16 [PATCH v2 0/7] Add device tree support for imx spi driver Shawn Guo
     [not found] ` <1310231801-18761-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-09 17:16   ` [PATCH v2 1/7] spi/imx: do not make copy of spi_imx_devtype_data Shawn Guo
2011-07-11  7:15     ` Lothar Waßmann
     [not found]       ` <19994.41750.920408.162356-VjFSrY7JcPWvSplVBqRQBQ@public.gmane.org>
2011-07-11  7:31         ` Uwe Kleine-König
2011-07-11  7:49           ` Lothar Waßmann
2011-07-11  7:35       ` Shawn Guo
     [not found]         ` <20110711073523.GA19105-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-11  7:32           ` Lothar Waßmann
     [not found]     ` <1310231801-18761-2-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-15  2:53       ` Grant Likely
2011-07-09 17:16   ` [PATCH v2 2/7] spi/imx: use mx21 to name SPI_IMX_VER_0_0 function and macro Shawn Guo
     [not found]     ` <1310231801-18761-3-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-11  7:35       ` Uwe Kleine-König
     [not found]         ` <20110711073523.GB13840-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-07-15  2:53           ` Grant Likely
2011-07-09 17:16   ` [PATCH v2 3/7] spi/imx: do not use spi_imx2_3 to name SPI_IMX_VER_2_3 " Shawn Guo
     [not found]     ` <1310231801-18761-4-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-15  2:53       ` Grant Likely
2011-07-09 17:16   ` [PATCH v2 4/7] spi/imx: merge type SPI_IMX_VER_0_7 into SPI_IMX_VER_0_4 Shawn Guo
     [not found]     ` <1310231801-18761-5-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-11  7:38       ` Uwe Kleine-König
2011-07-09 17:16   ` [PATCH v2 5/7] spi/imx: use soc name in spi device type naming scheme Shawn Guo
     [not found]     ` <1310231801-18761-6-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-15  2:53       ` Grant Likely
2011-07-09 17:16   ` [PATCH v2 6/7] spi/imx: copy gpio number passed by platform data into driver private data Shawn Guo
     [not found]     ` <1310231801-18761-7-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-11  7:45       ` Uwe Kleine-König
2011-07-09 17:16   ` [PATCH v2 7/7] spi/imx: add device tree probe support Shawn Guo
     [not found]     ` <1310231801-18761-8-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-15  2:53       ` Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).