linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set.
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-03-02 23:15   ` Grant Likely
  2013-03-03 10:27   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-02-26  6:47 ` [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register Wenyou Yang
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

if the spi property "cs-gpios" is set as below:

	cs-gpios = <0>, <&pioC 11 0>, <0>, <0>;

the master->num_chipselect will wrongly be set to 0,
and the spi fail to probe.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
---
 drivers/spi/spi-atmel.c |    2 +-
 drivers/spi/spi.c       |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index ab34497..5bf3786 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -944,7 +944,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 
 	master->dev.of_node = pdev->dev.of_node;
 	master->bus_num = pdev->id;
-	master->num_chipselect = master->dev.of_node ? 0 : 4;
+	master->num_chipselect = 4;
 	master->setup = atmel_spi_setup;
 	master->transfer = atmel_spi_transfer;
 	master->cleanup = atmel_spi_cleanup;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 19ee901..d88cbef 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1070,7 +1070,7 @@ static int of_spi_register_master(struct spi_master *master)
 	master->num_chipselect = max(nb, master->num_chipselect);
 
 	if (nb < 1)
-		return 0;
+		nb = master->num_chipselect;
 
 	cs = devm_kzalloc(&master->dev,
 			  sizeof(int) * master->num_chipselect,
-- 
1.7.9.5

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

* [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register.
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
  2013-02-26  6:47 ` [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set Wenyou Yang
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-03-03 10:28   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-02-26  6:47 ` [PATCH v5 03/16] spi/spi-atmel: add support transfer on CS1,2,3, not only on CS0 Wenyou Yang
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

the "has_dma_support" needed for future use with dmaengine driver.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
---
 drivers/spi/spi-atmel.c |   70 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 57 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 5bf3786..a8e091b 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -39,6 +39,7 @@
 #define SPI_CSR1				0x0034
 #define SPI_CSR2				0x0038
 #define SPI_CSR3				0x003c
+#define SPI_VERSION				0x00fc
 #define SPI_RPR					0x0100
 #define SPI_RCR					0x0104
 #define SPI_TPR					0x0108
@@ -71,6 +72,8 @@
 #define SPI_FDIV_SIZE				1
 #define SPI_MODFDIS_OFFSET			4
 #define SPI_MODFDIS_SIZE			1
+#define SPI_WDRBT_OFFSET			5
+#define SPI_WDRBT_SIZE				1
 #define SPI_LLB_OFFSET				7
 #define SPI_LLB_SIZE				1
 #define SPI_PCS_OFFSET				16
@@ -180,6 +183,11 @@
 #define spi_writel(port,reg,value) \
 	__raw_writel((value), (port)->regs + SPI_##reg)
 
+struct atmel_spi_caps {
+	bool	is_spi2;
+	bool	has_wdrbt;
+	bool	has_dma_support;
+};
 
 /*
  * The core SPI transfer engine just talks to a register bank to set up
@@ -204,6 +212,8 @@ struct atmel_spi {
 
 	void			*buffer;
 	dma_addr_t		buffer_dma;
+
+	struct atmel_spi_caps	caps;
 };
 
 /* Controller-specific per-slave state */
@@ -222,14 +232,10 @@ struct atmel_spi_device {
  *  - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
  *  - SPI_CSRx.CSAAT
  *  - SPI_CSRx.SBCR allows faster clocking
- *
- * We can determine the controller version by reading the VERSION
- * register, but I haven't checked that it exists on all chips, and
- * this is cheaper anyway.
  */
-static bool atmel_spi_is_v2(void)
+static bool atmel_spi_is_v2(struct atmel_spi *as)
 {
-	return !cpu_is_at91rm9200();
+	return as->caps.is_spi2;
 }
 
 /*
@@ -263,15 +269,20 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
 	unsigned active = spi->mode & SPI_CS_HIGH;
 	u32 mr;
 
-	if (atmel_spi_is_v2()) {
+	if (atmel_spi_is_v2(as)) {
 		/*
 		 * Always use CSR0. This ensures that the clock
 		 * switches to the correct idle polarity before we
 		 * toggle the CS.
 		 */
 		spi_writel(as, CSR0, asd->csr);
-		spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(MODFDIS)
+		if (as->caps.has_wdrbt) {
+			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(WDRBT)
+				| SPI_BIT(MODFDIS) | SPI_BIT(MSTR));
+		} else {
+			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(MODFDIS)
 				| SPI_BIT(MSTR));
+		}
 		mr = spi_readl(as, MR);
 		gpio_set_value(asd->npcs_pin, active);
 	} else {
@@ -318,7 +329,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
 			asd->npcs_pin, active ? " (low)" : "",
 			mr);
 
-	if (atmel_spi_is_v2() || spi->chip_select != 0)
+	if (atmel_spi_is_v2(as) || spi->chip_select != 0)
 		gpio_set_value(asd->npcs_pin, !active);
 }
 
@@ -719,7 +730,7 @@ static int atmel_spi_setup(struct spi_device *spi)
 	}
 
 	/* see notes above re chipselect */
-	if (!atmel_spi_is_v2()
+	if (!atmel_spi_is_v2(as)
 			&& spi->chip_select == 0
 			&& (spi->mode & SPI_CS_HIGH)) {
 		dev_dbg(&spi->dev, "setup: can't be active-high\n");
@@ -728,7 +739,7 @@ static int atmel_spi_setup(struct spi_device *spi)
 
 	/* v1 chips start out at half the peripheral bus speed. */
 	bus_hz = clk_get_rate(as->clk);
-	if (!atmel_spi_is_v2())
+	if (!atmel_spi_is_v2(as))
 		bus_hz /= 2;
 
 	if (spi->max_speed_hz) {
@@ -804,7 +815,7 @@ static int atmel_spi_setup(struct spi_device *spi)
 		"setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
 		bus_hz / scbr, bits, spi->mode, spi->chip_select, csr);
 
-	if (!atmel_spi_is_v2())
+	if (!atmel_spi_is_v2(as))
 		spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
 
 	return 0;
@@ -910,6 +921,32 @@ static void atmel_spi_cleanup(struct spi_device *spi)
 	kfree(asd);
 }
 
+static inline unsigned int atmel_get_version(struct atmel_spi *as)
+{
+	return spi_readl(as, VERSION) & 0x00000fff;
+}
+
+static void __init atmel_get_caps(struct atmel_spi *as)
+{
+	unsigned int version;
+
+	version = atmel_get_version(as);
+	dev_info(&as->pdev->dev, "version: 0x%x\n", version);
+
+	as->caps.is_spi2 = false;
+	as->caps.has_wdrbt = false;
+	as->caps.has_dma_support = false;
+
+	if (version > 0x121)
+		as->caps.is_spi2 = true;
+
+	if (version >= 0x210)
+		as->caps.has_wdrbt = true;
+
+	if (version >= 0x212)
+		as->caps.has_dma_support = true;
+}
+
 /*-------------------------------------------------------------------------*/
 
 static int atmel_spi_probe(struct platform_device *pdev)
@@ -970,6 +1007,8 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	as->irq = irq;
 	as->clk = clk;
 
+	atmel_get_caps(as);
+
 	ret = request_irq(irq, atmel_spi_interrupt, 0,
 			dev_name(&pdev->dev), master);
 	if (ret)
@@ -979,7 +1018,12 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	clk_enable(clk);
 	spi_writel(as, CR, SPI_BIT(SWRST));
 	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
-	spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
+	if (as->caps.has_wdrbt) {
+		spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
+				| SPI_BIT(MSTR));
+	} else {
+		spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
+	}
 	spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
 	spi_writel(as, CR, SPI_BIT(SPIEN));
 
-- 
1.7.9.5

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

* [PATCH v5 03/16] spi/spi-atmel: add support transfer on CS1,2,3, not only on CS0
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
  2013-02-26  6:47 ` [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set Wenyou Yang
  2013-02-26  6:47 ` [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register Wenyou Yang
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-02-26  6:47 ` [PATCH v5 04/16] spi/spi-atmel: add physical base address Wenyou Yang
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
---
 drivers/spi/spi-atmel.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index a8e091b..9c8f2d5 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -256,11 +256,6 @@ static bool atmel_spi_is_v2(struct atmel_spi *as)
  * Master on Chip Select 0.")  No workaround exists for that ... so for
  * nCS0 on that chip, we (a) don't use the GPIO, (b) can't support CS_HIGH,
  * and (c) will trigger that first erratum in some cases.
- *
- * TODO: Test if the atmel_spi_is_v2() branch below works on
- * AT91RM9200 if we use some other register than CSR0. However, don't
- * do this unconditionally since AP7000 has an errata where the BITS
- * field in CSR0 overrides all other CSRs.
  */
 
 static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
@@ -270,18 +265,22 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
 	u32 mr;
 
 	if (atmel_spi_is_v2(as)) {
-		/*
-		 * Always use CSR0. This ensures that the clock
-		 * switches to the correct idle polarity before we
-		 * toggle the CS.
+		spi_writel(as, CSR0 + 4 * spi->chip_select, asd->csr);
+		/* For the low SPI version, there is a issue that PDC transfer
+		 * on CS1,2,3 needs SPI_CSR0.BITS config as SPI_CSR1,2,3.BITS
 		 */
 		spi_writel(as, CSR0, asd->csr);
 		if (as->caps.has_wdrbt) {
-			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(WDRBT)
-				| SPI_BIT(MODFDIS) | SPI_BIT(MSTR));
+			spi_writel(as, MR,
+					SPI_BF(PCS, ~(0x01 << spi->chip_select))
+					| SPI_BIT(WDRBT)
+					| SPI_BIT(MODFDIS)
+					| SPI_BIT(MSTR));
 		} else {
-			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(MODFDIS)
-				| SPI_BIT(MSTR));
+			spi_writel(as, MR,
+					SPI_BF(PCS, ~(0x01 << spi->chip_select))
+					| SPI_BIT(MODFDIS)
+					| SPI_BIT(MSTR));
 		}
 		mr = spi_readl(as, MR);
 		gpio_set_value(asd->npcs_pin, active);
-- 
1.7.9.5

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

* [PATCH v5 04/16] spi/spi-atmel: add physical base address
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
                   ` (2 preceding siblings ...)
  2013-02-26  6:47 ` [PATCH v5 03/16] spi/spi-atmel: add support transfer on CS1,2,3, not only on CS0 Wenyou Yang
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-02-26  6:47 ` [PATCH v5 05/16] spi/spi-atmel: call unmapping on transfers buffers Wenyou Yang
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

From: Nicolas Ferre <nicolas.ferre@atmel.com>

Needed for future use with dmaengine enabled driver.

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
[wenyou.yang@atmel.com: submit the patch]
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/spi/spi-atmel.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 9c8f2d5..c70142e 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -197,6 +197,7 @@ struct atmel_spi_caps {
 struct atmel_spi {
 	spinlock_t		lock;
 
+	resource_size_t		phybase;
 	void __iomem		*regs;
 	int			irq;
 	struct clk		*clk;
@@ -1003,6 +1004,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
 	as->regs = ioremap(regs->start, resource_size(regs));
 	if (!as->regs)
 		goto out_free_buffer;
+	as->phybase = regs->start;
 	as->irq = irq;
 	as->clk = clk;
 
-- 
1.7.9.5

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

* [PATCH v5 05/16] spi/spi-atmel: call unmapping on transfers buffers
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
                   ` (3 preceding siblings ...)
  2013-02-26  6:47 ` [PATCH v5 04/16] spi/spi-atmel: add physical base address Wenyou Yang
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-02-26  6:47 ` [PATCH v5 06/16] spi/spi-atmel: status information passed through controller data Wenyou Yang
  2013-02-26  6:48 ` [PATCH v5 07/16] spi/spi-atmel: add flag to controller data for lock operations Wenyou Yang
  6 siblings, 0 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

From: Nicolas Ferre <nicolas.ferre@atmel.com>

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
[wenyou.yang@atmel.com: submit the patch]
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/spi/spi-atmel.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index c70142e..6ea41a7 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1059,6 +1059,7 @@ static int atmel_spi_remove(struct platform_device *pdev)
 	struct spi_master	*master = platform_get_drvdata(pdev);
 	struct atmel_spi	*as = spi_master_get_devdata(master);
 	struct spi_message	*msg;
+	struct spi_transfer	*xfer;
 
 	/* reset the hardware and block queue progress */
 	spin_lock_irq(&as->lock);
@@ -1070,9 +1071,10 @@ static int atmel_spi_remove(struct platform_device *pdev)
 
 	/* Terminate remaining queued transfers */
 	list_for_each_entry(msg, &as->queue, queue) {
-		/* REVISIT unmapping the dma is a NOP on ARM and AVR32
-		 * but we shouldn't depend on that...
-		 */
+		list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+			if (!msg->is_dma_mapped)
+				atmel_spi_dma_unmap_xfer(master, xfer);
+		}
 		msg->status = -ESHUTDOWN;
 		msg->complete(msg->context);
 	}
-- 
1.7.9.5

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

* [PATCH v5 06/16] spi/spi-atmel: status information passed through controller data
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
                   ` (4 preceding siblings ...)
  2013-02-26  6:47 ` [PATCH v5 05/16] spi/spi-atmel: call unmapping on transfers buffers Wenyou Yang
@ 2013-02-26  6:47 ` Wenyou Yang
  2013-02-26  6:48 ` [PATCH v5 07/16] spi/spi-atmel: add flag to controller data for lock operations Wenyou Yang
  6 siblings, 0 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:47 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

From: Nicolas Ferre <nicolas.ferre@atmel.com>

The status of transfer is stored in controller data structure
so that it can be used not only by atmel_spi_msg_done() function.
This will be useful for upcoming dmaengine enabled driver.

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
[wenyou.yang@atmel.com: submit the patch]
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/spi/spi-atmel.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 6ea41a7..136ed8f 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -210,6 +210,7 @@ struct atmel_spi {
 	unsigned long		current_remaining_bytes;
 	struct spi_transfer	*next_transfer;
 	unsigned long		next_remaining_bytes;
+	int			done_status;
 
 	void			*buffer;
 	dma_addr_t		buffer_dma;
@@ -555,15 +556,15 @@ static void atmel_spi_dma_unmap_xfer(struct spi_master *master,
 
 static void
 atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
-		struct spi_message *msg, int status, int stay)
+		struct spi_message *msg, int stay)
 {
-	if (!stay || status < 0)
+	if (!stay || as->done_status < 0)
 		cs_deactivate(as, msg->spi);
 	else
 		as->stay = msg->spi;
 
 	list_del(&msg->queue);
-	msg->status = status;
+	msg->status = as->done_status;
 
 	dev_dbg(master->dev.parent,
 		"xfer complete: %u bytes transferred\n",
@@ -575,6 +576,7 @@ atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
 
 	as->current_transfer = NULL;
 	as->next_transfer = NULL;
+	as->done_status = 0;
 
 	/* continue if needed */
 	if (list_empty(&as->queue) || as->stopping)
@@ -652,7 +654,8 @@ atmel_spi_interrupt(int irq, void *dev_id)
 		/* Clear any overrun happening while cleaning up */
 		spi_readl(as, SR);
 
-		atmel_spi_msg_done(master, as, msg, -EIO, 0);
+		as->done_status = -EIO;
+		atmel_spi_msg_done(master, as, msg, 0);
 	} else if (pending & (SPI_BIT(RXBUFF) | SPI_BIT(ENDRX))) {
 		ret = IRQ_HANDLED;
 
@@ -670,7 +673,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
 
 			if (atmel_spi_xfer_is_last(msg, xfer)) {
 				/* report completed message */
-				atmel_spi_msg_done(master, as, msg, 0,
+				atmel_spi_msg_done(master, as, msg,
 						xfer->cs_change);
 			} else {
 				if (xfer->cs_change) {
-- 
1.7.9.5

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

* [PATCH v5 07/16] spi/spi-atmel: add flag to controller data for lock operations
       [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
                   ` (5 preceding siblings ...)
  2013-02-26  6:47 ` [PATCH v5 06/16] spi/spi-atmel: status information passed through controller data Wenyou Yang
@ 2013-02-26  6:48 ` Wenyou Yang
  6 siblings, 0 replies; 11+ messages in thread
From: Wenyou Yang @ 2013-02-26  6:48 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: grant.likely, nicolas.ferre, plagnioj, richard.genoud, JM.Lin,
	wenyou.yang, spi-devel-general, linux-kernel

From: Nicolas Ferre <nicolas.ferre@atmel.com>

Will allow to drop the lock during DMA operations.

Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Cc: spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
[wenyou.yang@atmel.com: submit the patch]
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
---
 drivers/spi/spi-atmel.c |   31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 136ed8f..1c2933a 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -196,6 +196,7 @@ struct atmel_spi_caps {
  */
 struct atmel_spi {
 	spinlock_t		lock;
+	unsigned long		flags;
 
 	resource_size_t		phybase;
 	void __iomem		*regs;
@@ -334,6 +335,16 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
 		gpio_set_value(asd->npcs_pin, !active);
 }
 
+static void atmel_spi_lock(struct atmel_spi *as)
+{
+		spin_lock_irqsave(&as->lock, as->flags);
+}
+
+static void atmel_spi_unlock(struct atmel_spi *as)
+{
+		spin_unlock_irqrestore(&as->lock, as->flags);
+}
+
 static inline int atmel_spi_xfer_is_last(struct spi_message *msg,
 					struct spi_transfer *xfer)
 {
@@ -570,9 +581,9 @@ atmel_spi_msg_done(struct spi_master *master, struct atmel_spi *as,
 		"xfer complete: %u bytes transferred\n",
 		msg->actual_length);
 
-	spin_unlock(&as->lock);
+	atmel_spi_unlock(as);
 	msg->complete(msg->context);
-	spin_lock(&as->lock);
+	atmel_spi_lock(as);
 
 	as->current_transfer = NULL;
 	as->next_transfer = NULL;
@@ -803,13 +814,11 @@ static int atmel_spi_setup(struct spi_device *spi)
 		spi->controller_state = asd;
 		gpio_direction_output(npcs_pin, !(spi->mode & SPI_CS_HIGH));
 	} else {
-		unsigned long		flags;
-
-		spin_lock_irqsave(&as->lock, flags);
+		atmel_spi_lock(as);
 		if (as->stay == spi)
 			as->stay = NULL;
 		cs_deactivate(as, spi);
-		spin_unlock_irqrestore(&as->lock, flags);
+		atmel_spi_unlock(as);
 	}
 
 	asd->csr = csr;
@@ -828,7 +837,6 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
 {
 	struct atmel_spi	*as;
 	struct spi_transfer	*xfer;
-	unsigned long		flags;
 	struct device		*controller = spi->master->dev.parent;
 	u8			bits;
 	struct atmel_spi_device	*asd;
@@ -893,11 +901,11 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
 	msg->status = -EINPROGRESS;
 	msg->actual_length = 0;
 
-	spin_lock_irqsave(&as->lock, flags);
+	atmel_spi_lock(as);
 	list_add_tail(&msg->queue, &as->queue);
 	if (!as->current_transfer)
 		atmel_spi_next_message(spi->master);
-	spin_unlock_irqrestore(&as->lock, flags);
+	atmel_spi_unlock(as);
 
 	return 0;
 }
@@ -907,17 +915,16 @@ static void atmel_spi_cleanup(struct spi_device *spi)
 	struct atmel_spi	*as = spi_master_get_devdata(spi->master);
 	struct atmel_spi_device	*asd = spi->controller_state;
 	unsigned		gpio = (unsigned) spi->controller_data;
-	unsigned long		flags;
 
 	if (!asd)
 		return;
 
-	spin_lock_irqsave(&as->lock, flags);
+	atmel_spi_lock(as);
 	if (as->stay == spi) {
 		as->stay = NULL;
 		cs_deactivate(as, spi);
 	}
-	spin_unlock_irqrestore(&as->lock, flags);
+	atmel_spi_unlock(as);
 
 	spi->controller_state = NULL;
 	gpio_free(gpio);
-- 
1.7.9.5

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

* Re: [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set.
  2013-02-26  6:47 ` [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set Wenyou Yang
@ 2013-03-02 23:15   ` Grant Likely
  2013-03-08  0:59     ` Yang, Wenyou
  2013-03-03 10:27   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 11+ messages in thread
From: Grant Likely @ 2013-03-02 23:15 UTC (permalink / raw)
  To: Wenyou Yang, linux-arm-kernel
  Cc: richard.genoud, JM.Lin, nicolas.ferre, linux-kernel, wenyou.yang,
	spi-devel-general, plagnioj

On Tue, 26 Feb 2013 14:47:54 +0800, Wenyou Yang <wenyou.yang@atmel.com> wrote:
> if the spi property "cs-gpios" is set as below:
> 
> 	cs-gpios = <0>, <&pioC 11 0>, <0>, <0>;
> 
> the master->num_chipselect will wrongly be set to 0,
> and the spi fail to probe.
> 
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> Cc: spi-devel-general@lists.sourceforge.net
> Cc: linux-kernel@vger.kernel.org

I think I've got this bug fixed in the core spi code. Give it a couple
of days and retest with linux-next.

g.

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

* Re: [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set.
  2013-02-26  6:47 ` [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set Wenyou Yang
  2013-03-02 23:15   ` Grant Likely
@ 2013-03-03 10:27   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-03 10:27 UTC (permalink / raw)
  To: Wenyou Yang
  Cc: richard.genoud, JM.Lin, nicolas.ferre, linux-kernel, grant.likely,
	spi-devel-general, linux-arm-kernel

On 14:47 Tue 26 Feb     , Wenyou Yang wrote:
> if the spi property "cs-gpios" is set as below:
> 
> 	cs-gpios = <0>, <&pioC 11 0>, <0>, <0>;
> 
> the master->num_chipselect will wrongly be set to 0,
> and the spi fail to probe.
> 
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> Cc: spi-devel-general@lists.sourceforge.net
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/spi/spi-atmel.c |    2 +-
>  drivers/spi/spi.c       |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index ab34497..5bf3786 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -944,7 +944,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  
>  	master->dev.of_node = pdev->dev.of_node;
>  	master->bus_num = pdev->id;
> -	master->num_chipselect = master->dev.of_node ? 0 : 4;
> +	master->num_chipselect = 4;
Nack

we use 0 hardware gpio we only use the cs-gpio

and you do not follow the binding

it's
	cs-gpios = < 0 0 0
	 	    &pioC 11 0>;

so the code work a expected

Best Regards,
J.
>  	master->setup = atmel_spi_setup;
>  	master->transfer = atmel_spi_transfer;
>  	master->cleanup = atmel_spi_cleanup;
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 19ee901..d88cbef 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1070,7 +1070,7 @@ static int of_spi_register_master(struct spi_master *master)
>  	master->num_chipselect = max(nb, master->num_chipselect);
>  
>  	if (nb < 1)
> -		return 0;
> +		nb = master->num_chipselect;
>  
>  	cs = devm_kzalloc(&master->dev,
>  			  sizeof(int) * master->num_chipselect,
> -- 
> 1.7.9.5
> 

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

* Re: [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register.
  2013-02-26  6:47 ` [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register Wenyou Yang
@ 2013-03-03 10:28   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 11+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-03 10:28 UTC (permalink / raw)
  To: Wenyou Yang
  Cc: richard.genoud, JM.Lin, nicolas.ferre, linux-kernel, grant.likely,
	spi-devel-general, linux-arm-kernel

On 14:47 Tue 26 Feb     , Wenyou Yang wrote:
> the "has_dma_support" needed for future use with dmaengine driver.
> 
> Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> Cc: spi-devel-general@lists.sourceforge.net
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/spi/spi-atmel.c |   70 ++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 57 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index 5bf3786..a8e091b 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -39,6 +39,7 @@
>  #define SPI_CSR1				0x0034
>  #define SPI_CSR2				0x0038
>  #define SPI_CSR3				0x003c
> +#define SPI_VERSION				0x00fc
>  #define SPI_RPR					0x0100
>  #define SPI_RCR					0x0104
>  #define SPI_TPR					0x0108
> @@ -71,6 +72,8 @@
>  #define SPI_FDIV_SIZE				1
>  #define SPI_MODFDIS_OFFSET			4
>  #define SPI_MODFDIS_SIZE			1
> +#define SPI_WDRBT_OFFSET			5
> +#define SPI_WDRBT_SIZE				1
>  #define SPI_LLB_OFFSET				7
>  #define SPI_LLB_SIZE				1
>  #define SPI_PCS_OFFSET				16
> @@ -180,6 +183,11 @@
>  #define spi_writel(port,reg,value) \
>  	__raw_writel((value), (port)->regs + SPI_##reg)
>  
> +struct atmel_spi_caps {
> +	bool	is_spi2;
> +	bool	has_wdrbt;
> +	bool	has_dma_support;
> +};
>  
>  /*
>   * The core SPI transfer engine just talks to a register bank to set up
> @@ -204,6 +212,8 @@ struct atmel_spi {
>  
>  	void			*buffer;
>  	dma_addr_t		buffer_dma;
> +
> +	struct atmel_spi_caps	caps;
>  };
>  
>  /* Controller-specific per-slave state */
> @@ -222,14 +232,10 @@ struct atmel_spi_device {
>   *  - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
>   *  - SPI_CSRx.CSAAT
>   *  - SPI_CSRx.SBCR allows faster clocking
> - *
> - * We can determine the controller version by reading the VERSION
> - * register, but I haven't checked that it exists on all chips, and
> - * this is cheaper anyway.
>   */
> -static bool atmel_spi_is_v2(void)
> +static bool atmel_spi_is_v2(struct atmel_spi *as)
>  {
> -	return !cpu_is_at91rm9200();
> +	return as->caps.is_spi2;
>  }
>  
>  /*
> @@ -263,15 +269,20 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
>  	unsigned active = spi->mode & SPI_CS_HIGH;
>  	u32 mr;
>  
> -	if (atmel_spi_is_v2()) {
> +	if (atmel_spi_is_v2(as)) {
>  		/*
>  		 * Always use CSR0. This ensures that the clock
>  		 * switches to the correct idle polarity before we
>  		 * toggle the CS.
>  		 */
>  		spi_writel(as, CSR0, asd->csr);
> -		spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(MODFDIS)
> +		if (as->caps.has_wdrbt) {
> +			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(WDRBT)
> +				| SPI_BIT(MODFDIS) | SPI_BIT(MSTR));
> +		} else {
> +			spi_writel(as, MR, SPI_BF(PCS, 0x0e) | SPI_BIT(MODFDIS)
>  				| SPI_BIT(MSTR));
> +		}
>  		mr = spi_readl(as, MR);
>  		gpio_set_value(asd->npcs_pin, active);
>  	} else {
> @@ -318,7 +329,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
>  			asd->npcs_pin, active ? " (low)" : "",
>  			mr);
>  
> -	if (atmel_spi_is_v2() || spi->chip_select != 0)
> +	if (atmel_spi_is_v2(as) || spi->chip_select != 0)
>  		gpio_set_value(asd->npcs_pin, !active);
>  }
>  
> @@ -719,7 +730,7 @@ static int atmel_spi_setup(struct spi_device *spi)
>  	}
>  
>  	/* see notes above re chipselect */
> -	if (!atmel_spi_is_v2()
> +	if (!atmel_spi_is_v2(as)
>  			&& spi->chip_select == 0
>  			&& (spi->mode & SPI_CS_HIGH)) {
>  		dev_dbg(&spi->dev, "setup: can't be active-high\n");
> @@ -728,7 +739,7 @@ static int atmel_spi_setup(struct spi_device *spi)
>  
>  	/* v1 chips start out at half the peripheral bus speed. */
>  	bus_hz = clk_get_rate(as->clk);
> -	if (!atmel_spi_is_v2())
> +	if (!atmel_spi_is_v2(as))
>  		bus_hz /= 2;
>  
>  	if (spi->max_speed_hz) {
> @@ -804,7 +815,7 @@ static int atmel_spi_setup(struct spi_device *spi)
>  		"setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
>  		bus_hz / scbr, bits, spi->mode, spi->chip_select, csr);
>  
> -	if (!atmel_spi_is_v2())
> +	if (!atmel_spi_is_v2(as))
>  		spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
>  
>  	return 0;
> @@ -910,6 +921,32 @@ static void atmel_spi_cleanup(struct spi_device *spi)
>  	kfree(asd);
>  }
>  
> +static inline unsigned int atmel_get_version(struct atmel_spi *as)
> +{
> +	return spi_readl(as, VERSION) & 0x00000fff;
> +}
> +
> +static void __init atmel_get_caps(struct atmel_spi *as)
> +{
> +	unsigned int version;
> +
> +	version = atmel_get_version(as);
> +	dev_info(&as->pdev->dev, "version: 0x%x\n", version);
> +
> +	as->caps.is_spi2 = false;
> +	as->caps.has_wdrbt = false;
> +	as->caps.has_dma_support = false;
> +
> +	if (version > 0x121)
> +		as->caps.is_spi2 = true;
> +
> +	if (version >= 0x210)
> +		as->caps.has_wdrbt = true;
> +
> +	if (version >= 0x212)
> +		as->caps.has_dma_support = true;
use switch here

or filled struct
> +}
> +
>  /*-------------------------------------------------------------------------*/
>  
>  static int atmel_spi_probe(struct platform_device *pdev)
> @@ -970,6 +1007,8 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	as->irq = irq;
>  	as->clk = clk;
>  
> +	atmel_get_caps(as);
> +
>  	ret = request_irq(irq, atmel_spi_interrupt, 0,
>  			dev_name(&pdev->dev), master);
>  	if (ret)
> @@ -979,7 +1018,12 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	clk_enable(clk);
>  	spi_writel(as, CR, SPI_BIT(SWRST));
>  	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
> -	spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
> +	if (as->caps.has_wdrbt) {
> +		spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
> +				| SPI_BIT(MSTR));
> +	} else {
> +		spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS));
> +	}
>  	spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
>  	spi_writel(as, CR, SPI_BIT(SPIEN));
>  
> -- 
> 1.7.9.5
> 

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

* RE: [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set.
  2013-03-02 23:15   ` Grant Likely
@ 2013-03-08  0:59     ` Yang, Wenyou
  0 siblings, 0 replies; 11+ messages in thread
From: Yang, Wenyou @ 2013-03-08  0:59 UTC (permalink / raw)
  To: Grant Likely, linux-arm-kernel@lists.infradead.org
  Cc: Ferre, Nicolas, plagnioj@jcrosoft.com, richard.genoud@gmail.com,
	Lin, JM, spi-devel-general@lists.sourceforge.net,
	linux-kernel@vger.kernel.org

> -----Original Message-----
> From: Grant Likely [mailto:glikely@secretlab.ca] On Behalf Of Grant Likely
> Sent: 2013年3月3日 7:16
> To: Yang, Wenyou; linux-arm-kernel@lists.infradead.org
> Cc: Ferre, Nicolas; plagnioj@jcrosoft.com; richard.genoud@gmail.com; Lin, JM;
> Yang, Wenyou; spi-devel-general@lists.sourceforge.net;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect
> wrongly set.
> 
> On Tue, 26 Feb 2013 14:47:54 +0800, Wenyou Yang <wenyou.yang@atmel.com>
> wrote:
> > if the spi property "cs-gpios" is set as below:
> >
> > 	cs-gpios = <0>, <&pioC 11 0>, <0>, <0>;
> >
> > the master->num_chipselect will wrongly be set to 0,
> > and the spi fail to probe.
> >
> > Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
> > Cc: spi-devel-general@lists.sourceforge.net
> > Cc: linux-kernel@vger.kernel.org
> 
> I think I've got this bug fixed in the core spi code. Give it a couple
> of days and retest with linux-next.
Hi Grant,

Yes, in v3.9-rc1 this bug fixed, I retested on v3.9-rc1.
But on "spi/next" git tree, it should to apply this patch.

I sent the patches version 6, could you take a look them? 
Thanks a lot for your work.

> 
> g.

Best Regards,
Wenyou Yang

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

end of thread, other threads:[~2013-03-08  0:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1361861289-30332-1-git-send-email-wenyou.yang@atmel.com>
2013-02-26  6:47 ` [PATCH v5 01/16] spi/spi-atmel: fix master->num_chipselect wrongly set Wenyou Yang
2013-03-02 23:15   ` Grant Likely
2013-03-08  0:59     ` Yang, Wenyou
2013-03-03 10:27   ` Jean-Christophe PLAGNIOL-VILLARD
2013-02-26  6:47 ` [PATCH v5 02/16] spi/spi-atmel: detect the capabilities of SPI core by reading the VERSION register Wenyou Yang
2013-03-03 10:28   ` Jean-Christophe PLAGNIOL-VILLARD
2013-02-26  6:47 ` [PATCH v5 03/16] spi/spi-atmel: add support transfer on CS1,2,3, not only on CS0 Wenyou Yang
2013-02-26  6:47 ` [PATCH v5 04/16] spi/spi-atmel: add physical base address Wenyou Yang
2013-02-26  6:47 ` [PATCH v5 05/16] spi/spi-atmel: call unmapping on transfers buffers Wenyou Yang
2013-02-26  6:47 ` [PATCH v5 06/16] spi/spi-atmel: status information passed through controller data Wenyou Yang
2013-02-26  6:48 ` [PATCH v5 07/16] spi/spi-atmel: add flag to controller data for lock operations Wenyou Yang

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).