Skip to contentSkip to conversation

Update MUSB CPPI 4.1 driver to correctly manage the DA8xx

PATCH Superseded Alexandre Bailon 4 participants 11 messages Aug 13, 2017 – Sep 12, 2017 8 messages not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Update MUSB CPPI 4.1 driver to correctly manage the DA8xx

A couple of weeks ago, Sekhar reported a warning issue happening in CPPI 4.1. The teardown sequence was not correctly programmed. The caused was a couple of difference between the DSPS and the DA8xx. These differences are the way to program the autoreq, the teardown and the DMA mode.
This series intends to fix the teardown and to correctly program the DMA mode.

This series has been roughly tested.
I have only tried it on the DA580 LCK and the BeagleBone Black. Only the device mode (msc and ecm) have been tested.

Alexandre Bailon (2):
usb: musb: musb_cppi41: Fix the address of teardown and autoreq
registers
usb: musb: musb_cppi41: Fix cppi41_set_dma_mode() for DA8xx

 drivers/usb/musb/musb_cppi41.c | 63 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 56 insertions(+), 7 deletions(-)
Signature · 6 lines
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH 1/2 usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

---
 drivers/usb/musb/musb_cppi41.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_cppi41.c +19 -4
index ba255280a624..dbff0e0a4ff5 100644
@@ -26,6 +26,9 @@
 
 #define MUSB_DMA_NUM_CHANNELS 15
 
+#define DA8XX_USB_AUTOREQ_REG	0x14
+#define DA8XX_USB_TEARDOWN_REG	0x1c
+
 struct cppi41_dma_controller {
 	struct dma_controller controller;
 	struct cppi41_dma_channel rx_channel[MUSB_DMA_NUM_CHANNELS];
@@ -35,6 +38,9 @@ struct cppi41_dma_controller {
 	u32 rx_mode;
 	u32 tx_mode;
 	u32 auto_req;
+
+	u32 tdown_reg;
+	u32 autoreq_reg;
 };
 
 static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
@@ -364,8 +370,8 @@ static void cppi41_set_autoreq_mode(struct cppi41_dma_channel *cppi41_channel,
 	if (new_mode == old_mode)
 		return;
 	controller->auto_req = new_mode;
-	musb_writel(controller->controller.musb->ctrl_base, USB_CTRL_AUTOREQ,
-		    new_mode);
+	musb_writel(controller->controller.musb->ctrl_base,
+		    controller->autoreq_reg, new_mode);
 }
 
 static bool cppi41_configure_channel(struct dma_channel *channel,
@@ -581,12 +587,13 @@ static int cppi41_dma_channel_abort(struct dma_channel *channel)
 
 	do {
 		if (is_tx)
-			musb_writel(musb->ctrl_base, USB_TDOWN, tdbit);
+			musb_writel(musb->ctrl_base, controller->tdown_reg,
+				    tdbit);
 		ret = dmaengine_terminate_all(cppi41_channel->dc);
 	} while (ret == -EAGAIN);
 
 	if (is_tx) {
-		musb_writel(musb->ctrl_base, USB_TDOWN, tdbit);
+		musb_writel(musb->ctrl_base, controller->tdown_reg, tdbit);
 
 		csr = musb_readw(epio, MUSB_TXCSR);
 		if (csr & MUSB_TXCSR_TXPKTRDY) {
@@ -727,6 +734,14 @@ cppi41_dma_controller_create(struct musb *musb, void __iomem *base)
 	controller->controller.is_compatible = cppi41_is_compatible;
 	controller->controller.musb = musb;
 
+	if (musb->io.quirks & MUSB_DA8XX) {
+		controller->tdown_reg = DA8XX_USB_TEARDOWN_REG;
+		controller->autoreq_reg = DA8XX_USB_AUTOREQ_REG;
+	} else {
+		controller->tdown_reg = USB_TDOWN;
+		controller->autoreq_reg = USB_CTRL_AUTOREQ;
+	}
+
 	ret = cppi41_dma_controller_start(controller);
 	if (ret)
 		goto plat_get_fail;
Signature · 6 lines
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

PATCH 2/2 usb: musb: musb_cppi41: Fix cppi41_set_dma_mode() for DA8xx

In reply to a message not in the archive

The way to configure the DMA mode on DA8xx is different from DSPS. Add a new function to configure DMA mode on DA8xx and use a callback to call the right function based on the platform.

---
 drivers/usb/musb/musb_cppi41.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)
drivers/usb/musb/musb_cppi41.c +37 -3
index dbff0e0a4ff5..7284ec7ecff7 100644
@@ -26,6 +26,7 @@
 
 #define MUSB_DMA_NUM_CHANNELS 15
 
+#define DA8XX_USB_MODE_REG	0x10
 #define DA8XX_USB_AUTOREQ_REG	0x14
 #define DA8XX_USB_TEARDOWN_REG	0x1c
 
@@ -41,6 +42,9 @@ struct cppi41_dma_controller {
 
 	u32 tdown_reg;
 	u32 autoreq_reg;
+
+	void (*set_dma_mode)(struct cppi41_dma_channel *cppi41_channel,
+			     unsigned int mode);
 };
 
 static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
@@ -355,6 +359,32 @@ static void cppi41_set_dma_mode(struct cppi41_dma_channel *cppi41_channel,
 	}
 }
 
+static void da8xx_set_dma_mode(struct cppi41_dma_channel *cppi41_channel,
+		unsigned int mode)
+{
+	struct cppi41_dma_controller *controller = cppi41_channel->controller;
+	struct musb *musb = controller->controller.musb;
+	unsigned int shift;
+	u32 port;
+	u32 new_mode;
+	u32 old_mode;
+
+	old_mode = controller->tx_mode;
+	port = cppi41_channel->port_num;
+
+	shift = (port - 1) * 4;
+	if (!cppi41_channel->is_tx)
+		shift += 16;
+	new_mode = old_mode & ~(3 << shift);
+	new_mode |= mode << shift;
+
+	if (new_mode == old_mode)
+		return;
+	controller->tx_mode = new_mode;
+	musb_writel(musb->ctrl_base, DA8XX_USB_MODE_REG, new_mode);
+}
+
+
 static void cppi41_set_autoreq_mode(struct cppi41_dma_channel *cppi41_channel,
 		unsigned mode)
 {
@@ -379,6 +409,7 @@ static bool cppi41_configure_channel(struct dma_channel *channel,
 				dma_addr_t dma_addr, u32 len)
 {
 	struct cppi41_dma_channel *cppi41_channel = channel->private_data;
+	struct cppi41_dma_controller *controller = cppi41_channel->controller;
 	struct dma_chan *dc = cppi41_channel->dc;
 	struct dma_async_tx_descriptor *dma_desc;
 	enum dma_transfer_direction direction;
@@ -404,7 +435,7 @@ static bool cppi41_configure_channel(struct dma_channel *channel,
 			musb_writel(musb->ctrl_base,
 				RNDIS_REG(cppi41_channel->port_num), len);
 			/* gen rndis */
-			cppi41_set_dma_mode(cppi41_channel,
+			controller->set_dma_mode(cppi41_channel,
 					EP_MODE_DMA_GEN_RNDIS);
 
 			/* auto req */
@@ -413,14 +444,15 @@ static bool cppi41_configure_channel(struct dma_channel *channel,
 		} else {
 			musb_writel(musb->ctrl_base,
 					RNDIS_REG(cppi41_channel->port_num), 0);
-			cppi41_set_dma_mode(cppi41_channel,
+			controller->set_dma_mode(cppi41_channel,
 					EP_MODE_DMA_TRANSPARENT);
 			cppi41_set_autoreq_mode(cppi41_channel,
 					EP_MODE_AUTOREQ_NONE);
 		}
 	} else {
 		/* fallback mode */
-		cppi41_set_dma_mode(cppi41_channel, EP_MODE_DMA_TRANSPARENT);
+		controller->set_dma_mode(cppi41_channel,
+					EP_MODE_DMA_TRANSPARENT);
 		cppi41_set_autoreq_mode(cppi41_channel, EP_MODE_AUTOREQ_NONE);
 		len = min_t(u32, packet_sz, len);
 	}
@@ -737,9 +769,11 @@ cppi41_dma_controller_create(struct musb *musb, void __iomem *base)
 	if (musb->io.quirks & MUSB_DA8XX) {
 		controller->tdown_reg = DA8XX_USB_TEARDOWN_REG;
 		controller->autoreq_reg = DA8XX_USB_AUTOREQ_REG;
+		controller->set_dma_mode = da8xx_set_dma_mode;
 	} else {
 		controller->tdown_reg = USB_TDOWN;
 		controller->autoreq_reg = USB_CTRL_AUTOREQ;
+		controller->set_dma_mode = cppi41_set_dma_mode;
 	}
 
 	ret = cppi41_dma_controller_start(controller);
Signature · 6 lines
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive

Hi,

Quoted 16 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

---
 drivers/usb/musb/musb_cppi41.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_cppi41.c +0 -0
index ba255280a624..dbff0e0a4ff5 100644

drivers/usb/musb/musb_cppi41.c line 30

Quoted 5 lines
drivers/usb/musb/musb_cppi41.c +2 -0
@@ -26,6 +26,9 @@
 
 #define MUSB_DMA_NUM_CHANNELS 15
 
+#define DA8XX_USB_AUTOREQ_REG	0x14
+#define DA8XX_USB_TEARDOWN_REG	0x1c

Nice catch. I noticed that the USB_CTRL_TX_MODE and USB_CTRL_RX_MODE are incorrect for DA8xx too. Perhaps those should be fixed too.

Also, since the original code does not use the _REG suffix for register offsets, perhaps the new defines should avoid those as well for consistency.

Thanks,
Sekhar
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive
Quoted 9 lines · Sekhar Nori

Hi,

Quoted 6 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

Reported-by [email protected]
Quoted 11 lines
Quoted 11 lines
---
 drivers/usb/musb/musb_cppi41.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_cppi41.c +0 -0
index ba255280a624..dbff0e0a4ff5 100644
@@ -26,6 +26,9 @@
 
Quoted 7 lines

drivers/usb/musb/musb_cppi41.c line 30

Quoted 4 lines
drivers/usb/musb/musb_cppi41.c +2 -0
 #define MUSB_DMA_NUM_CHANNELS 15
 
+#define DA8XX_USB_AUTOREQ_REG	0x14
+#define DA8XX_USB_TEARDOWN_REG	0x1c

Nice catch. I noticed that the USB_CTRL_TX_MODE and USB_CTRL_RX_MODE are incorrect for DA8xx too. Perhaps those should be fixed too.

Ah, just read 2/2 now, and seems like thats exactly what you are handling there.

Thanks,
Sekhar
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive

Hello!

Quoted 16 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

---
  drivers/usb/musb/musb_cppi41.c | 23 +++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_cppi41.c +0 -0
index ba255280a624..dbff0e0a4ff5 100644

drivers/usb/musb/musb_cppi41.c line 30

Quoted 5 lines
drivers/usb/musb/musb_cppi41.c +2 -0
@@ -26,6 +26,9 @@
 
  #define MUSB_DMA_NUM_CHANNELS 15
 
+#define DA8XX_USB_AUTOREQ_REG	0x14
+#define DA8XX_USB_TEARDOWN_REG	0x1c

Why these _REG suffixes suddenly?

[...]

Other than that looks sane. Need my ACK?

WBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

Re: [PATCH 2/2] usb: musb: musb_cppi41: Fix cppi41_set_dma_mode() for DA8xx

In reply to a message not in the archive
Quoted 14 lines · Alexandre Bailon

The way to configure the DMA mode on DA8xx is different from DSPS. Add a new function to configure DMA mode on DA8xx and use a callback to call the right function based on the platform.

---
  drivers/usb/musb/musb_cppi41.c | 40 +++++++++++++++++++++++++++++++++++++---
  1 file changed, 37 insertions(+), 3 deletions(-)
drivers/usb/musb/musb_cppi41.c +0 -0
index dbff0e0a4ff5..7284ec7ecff7 100644

drivers/usb/musb/musb_cppi41.c line 27

Quoted 2 lines
drivers/usb/musb/musb_cppi41.c +0 -0
@@ -26,6 +26,7 @@
 
  #define MUSB_DMA_NUM_CHANNELS 15

Perhaps this needs parametrizing too? DA8xx only has 4 channels IIRC...

drivers/usb/musb/musb_cppi41.c line 29

Quoted 1 line
drivers/usb/musb/musb_cppi41.c +1 -0
+#define DA8XX_USB_MODE_REG	0x10

Drop this _REG suffix please.

Quoted 3 lines
drivers/usb/musb/musb_cppi41.c +0 -0
  #define DA8XX_USB_AUTOREQ_REG	0x14
  #define DA8XX_USB_TEARDOWN_REG	0x1c
 

[...]

Quoted 5 lines
drivers/usb/musb/musb_cppi41.c +0 -1
@@ -413,14 +444,15 @@ static bool cppi41_configure_channel(struct dma_channel *channel,
  		} else {
  			musb_writel(musb->ctrl_base,
  					RNDIS_REG(cppi41_channel->port_num), 0);
-			cppi41_set_dma_mode(cppi41_channel,

drivers/usb/musb/musb_cppi41.c static bool cppi41_configure_channel(struct dma_channel *channel, · line 455

Quoted 10 lines
drivers/usb/musb/musb_cppi41.c +3 -1
+			controller->set_dma_mode(cppi41_channel,
  					EP_MODE_DMA_TRANSPARENT);
  			cppi41_set_autoreq_mode(cppi41_channel,
  					EP_MODE_AUTOREQ_NONE);
  		}
  	} else {
  		/* fallback mode */
-		cppi41_set_dma_mode(cppi41_channel, EP_MODE_DMA_TRANSPARENT);
+		controller->set_dma_mode(cppi41_channel,
+					EP_MODE_DMA_TRANSPARENT);

Inconsistent indentation -- you used 2 extra tabs above and 3 here.

[...]

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Tested-by
#8 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive
Quoted 4 lines · Sekhar Nori
Quoted 3 lines · Sekhar Nori

Hi,

On Sunday 13 August 2017 05:34 PM, Alexandre Bailon wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

Reported-by [email protected]

Hi Bin,

Do you have any additional comments on this series or are you waiting for v2 to be posted?

Thanks,
Sekhar
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive
Quoted 12 lines · Sekhar Nori
Quoted 11 lines · Sekhar Nori
Quoted 9 lines · Sekhar Nori

Hi,

Quoted 6 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

Reported-by [email protected]
Quoted 8 lines
Quoted 1 line

Hi Bin,

Do you have any additional comments on this series or are you waiting for v2 to be posted?

I don't have other comments, just am waiting for v2.

Regards,
-Bin.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive

Hi Bin, Sekhar

Quoted 12 lines · Bin Liu
Quoted 11 lines · Sekhar Nori
Quoted 10 lines · Sekhar Nori
Quoted 9 lines · Sekhar Nori

Hi,

Quoted 6 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers. On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead of constants.

Reported-by [email protected]
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Hi Bin,

Do you have any additional comments on this series or are you waiting for v2 to be posted?

I don't have other comments, just am waiting for v2.

My apologize. I was in vacation. I will send the v2 soon.

Best Regards,
Alexandre

Quoted 4 lines

Regards,
-Bin.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH 1/2] usb: musb: musb_cppi41: Fix the address of teardown and autoreq registers

In reply to a message not in the archive
Quoted 17 lines · Sergei Shtylyov

Hello!

Quoted 13 lines · Alexandre Bailon

The DA8xx and DSPS platforms don't use the same address for few registers.
On Da8xx, this is causing some issues (e.g. teardown that doesn't work). Configure the address of the register during the init and use them instead
of constants.

---
  drivers/usb/musb/musb_cppi41.c | 23 +++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
Quoted 11 lines

drivers/usb/musb/musb_cppi41.c line 28

Quoted 9 lines
drivers/usb/musb/musb_cppi41.c +1 -0
index ba255280a624..dbff0e0a4ff5 100644
@@ -26,6 +26,9 @@
    #define MUSB_DMA_NUM_CHANNELS 15
  +#define DA8XX_USB_AUTOREQ_REG    0x14
+#define DA8XX_USB_TEARDOWN_REG    0x1c

Why these _REG suffixes suddenly?

I took these defines in da8xx.c.
Actually, I think I should make a third patch to remove them from da8xx.c because they are not even used.

Quoted 4 lines

[...]

Other than that looks sane. Need my ACK?

I don't know if that is needed but I guess it would be appreciated.

Best Regards,
Alexandre

Quoted 2 lines

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html