diff mbox series

[v2,1/2] usb: musb: cppi41: Add new functions for platform driver

Message ID 20170117131511.7252-2-abailon@baylibre.com
State New
Headers show
Series usb: musb: cppi41: Add a way to manage DMA irq | expand

Commit Message

Alexandre Bailon Jan. 17, 2017, 1:15 p.m. UTC
Currently, the CPPI 4.1 driver is not completely generic and
only work on dsps.
Add two functions which will help to move platform code from CPPI 4.1 to
MUSB glue driver:
- cppi41_register_dma_callback() to register a platform dma_callback
  (e.g to acknowledge interrupt on DMA completion).
- cppi41_dma_controller_to_musb() to convert a dma_controller pointer to
  a musb pointer. This is required to get a musb pointer from DMA callbacks.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>

---
 drivers/usb/musb/musb_cppi41.c | 27 +++++++++++++++++++++++++--
 drivers/usb/musb/musb_dma.h    |  4 ++++
 2 files changed, 29 insertions(+), 2 deletions(-)

-- 
2.10.2

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

Comments

Tony Lindgren Jan. 17, 2017, 11:29 p.m. UTC | #1
* Alexandre Bailon <abailon@baylibre.com> [170117 05:16]:
> Currently, the CPPI 4.1 driver is not completely generic and

> only work on dsps.

> Add two functions which will help to move platform code from CPPI 4.1 to

> MUSB glue driver:

> - cppi41_register_dma_callback() to register a platform dma_callback

>   (e.g to acknowledge interrupt on DMA completion).

> - cppi41_dma_controller_to_musb() to convert a dma_controller pointer to

>   a musb pointer. This is required to get a musb pointer from DMA callbacks.


Can't you just add a new function to struct dma_controller in musb_dma.h?

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Bailon Jan. 18, 2017, 2:53 p.m. UTC | #2
On 01/18/2017 12:29 AM, Tony Lindgren wrote:
> * Alexandre Bailon <abailon@baylibre.com> [170117 05:16]:

>> Currently, the CPPI 4.1 driver is not completely generic and

>> only work on dsps.

>> Add two functions which will help to move platform code from CPPI 4.1 to

>> MUSB glue driver:

>> - cppi41_register_dma_callback() to register a platform dma_callback

>>   (e.g to acknowledge interrupt on DMA completion).

>> - cppi41_dma_controller_to_musb() to convert a dma_controller pointer to

>>   a musb pointer. This is required to get a musb pointer from DMA callbacks.

> 

> Can't you just add a new function to struct dma_controller in musb_dma.h?

Yes, I can add the dma_callback function to dma_controller and then
remove cppi41_register_dma_callback().
But I still to define cppi41_dma_controller_to_musb() except if I add a
musb pointer to dma_controller.

Regards,
Alexandre
> 

> Regards,

> 

> Tony

> 


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tony Lindgren Jan. 18, 2017, 5:43 p.m. UTC | #3
* Alexandre Bailon <abailon@baylibre.com> [170118 06:54]:
> On 01/18/2017 12:29 AM, Tony Lindgren wrote:

> > * Alexandre Bailon <abailon@baylibre.com> [170117 05:16]:

> >> Currently, the CPPI 4.1 driver is not completely generic and

> >> only work on dsps.

> >> Add two functions which will help to move platform code from CPPI 4.1 to

> >> MUSB glue driver:

> >> - cppi41_register_dma_callback() to register a platform dma_callback

> >>   (e.g to acknowledge interrupt on DMA completion).

> >> - cppi41_dma_controller_to_musb() to convert a dma_controller pointer to

> >>   a musb pointer. This is required to get a musb pointer from DMA callbacks.

> > 

> > Can't you just add a new function to struct dma_controller in musb_dma.h?

> Yes, I can add the dma_callback function to dma_controller and then

> remove cppi41_register_dma_callback().


OK

> But I still to define cppi41_dma_controller_to_musb() except if I add a

> musb pointer to dma_controller.


Yeah makes sense to me. Or get it from the hw_ep that already has it?

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexandre Bailon Jan. 18, 2017, 5:50 p.m. UTC | #4
On 01/18/2017 06:43 PM, Tony Lindgren wrote:
> * Alexandre Bailon <abailon@baylibre.com> [170118 06:54]:

>> On 01/18/2017 12:29 AM, Tony Lindgren wrote:

>>> * Alexandre Bailon <abailon@baylibre.com> [170117 05:16]:

>>>> Currently, the CPPI 4.1 driver is not completely generic and

>>>> only work on dsps.

>>>> Add two functions which will help to move platform code from CPPI 4.1 to

>>>> MUSB glue driver:

>>>> - cppi41_register_dma_callback() to register a platform dma_callback

>>>>   (e.g to acknowledge interrupt on DMA completion).

>>>> - cppi41_dma_controller_to_musb() to convert a dma_controller pointer to

>>>>   a musb pointer. This is required to get a musb pointer from DMA callbacks.

>>>

>>> Can't you just add a new function to struct dma_controller in musb_dma.h?

>> Yes, I can add the dma_callback function to dma_controller and then

>> remove cppi41_register_dma_callback().

> 

> OK

> 

>> But I still to define cppi41_dma_controller_to_musb() except if I add a

>> musb pointer to dma_controller.

> 

> Yeah makes sense to me. Or get it from the hw_ep that already has it?

Yes hw_ep has it but it only available in cppi41_dma_callback().
I also need to get the musb pointer from dma_exit() callback
(defined in musb_platform_ops).
dma_exit only have one argument: struct dma_controller.
Having musb in dma_controller make thing more easier.
The other solution is to add a new argument to dma_exit().

Regards,
Alexandre
> 

> Regards,

> 

> Tony

> 


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tony Lindgren Jan. 18, 2017, 6:08 p.m. UTC | #5
* Alexandre Bailon <abailon@baylibre.com> [170118 09:51]:
> On 01/18/2017 06:43 PM, Tony Lindgren wrote:

> > * Alexandre Bailon <abailon@baylibre.com> [170118 06:54]:

> >> On 01/18/2017 12:29 AM, Tony Lindgren wrote:

> >>> * Alexandre Bailon <abailon@baylibre.com> [170117 05:16]:

> >>>> Currently, the CPPI 4.1 driver is not completely generic and

> >>>> only work on dsps.

> >>>> Add two functions which will help to move platform code from CPPI 4.1 to

> >>>> MUSB glue driver:

> >>>> - cppi41_register_dma_callback() to register a platform dma_callback

> >>>>   (e.g to acknowledge interrupt on DMA completion).

> >>>> - cppi41_dma_controller_to_musb() to convert a dma_controller pointer to

> >>>>   a musb pointer. This is required to get a musb pointer from DMA callbacks.

> >>>

> >>> Can't you just add a new function to struct dma_controller in musb_dma.h?

> >> Yes, I can add the dma_callback function to dma_controller and then

> >> remove cppi41_register_dma_callback().

> > 

> > OK

> > 

> >> But I still to define cppi41_dma_controller_to_musb() except if I add a

> >> musb pointer to dma_controller.

> > 

> > Yeah makes sense to me. Or get it from the hw_ep that already has it?

> Yes hw_ep has it but it only available in cppi41_dma_callback().

> I also need to get the musb pointer from dma_exit() callback

> (defined in musb_platform_ops).

> dma_exit only have one argument: struct dma_controller.

> Having musb in dma_controller make thing more easier.

> The other solution is to add a new argument to dma_exit().


Seems like adding to struct dma_controller is less changes.
Bin might have some preference here though.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
index 1636385..d76022b 100644
--- a/drivers/usb/musb/musb_cppi41.c
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -36,6 +36,8 @@  struct cppi41_dma_controller {
 	u32 rx_mode;
 	u32 tx_mode;
 	u32 auto_req;
+
+	cppi41_platform_dma_callback dma_callback;
 };
 
 static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
@@ -217,6 +219,10 @@  static void cppi41_dma_callback(void *private_data)
 	int is_hs = 0;
 	bool empty;
 
+	controller = cppi41_channel->controller;
+	if (controller->dma_callback)
+		controller->dma_callback(musb);
+
 	spin_lock_irqsave(&musb->lock, flags);
 
 	dmaengine_tx_status(cppi41_channel->dc, cppi41_channel->cookie,
@@ -249,8 +255,6 @@  static void cppi41_dma_callback(void *private_data)
 	 * We spin on HS (no longer than than 25us and setup a timer on
 	 * FS to check for the bit and complete the transfer.
 	 */
-	controller = cppi41_channel->controller;
-
 	if (is_host_active(musb)) {
 		if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED)
 			is_hs = 1;
@@ -288,6 +292,16 @@  static void cppi41_dma_callback(void *private_data)
 	spin_unlock_irqrestore(&musb->lock, flags);
 }
 
+void cppi41_register_dma_callback(struct dma_controller *c,
+				  cppi41_platform_dma_callback callback)
+{
+	struct cppi41_dma_controller *controller = container_of(c,
+			struct cppi41_dma_controller, controller);
+
+	controller->dma_callback = callback;
+}
+EXPORT_SYMBOL_GPL(cppi41_register_dma_callback);
+
 static u32 update_ep_mode(unsigned ep, unsigned mode, u32 old)
 {
 	unsigned shift;
@@ -709,3 +723,12 @@  cppi41_dma_controller_create(struct musb *musb, void __iomem *base)
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(cppi41_dma_controller_create);
+
+struct musb *cppi41_dma_controller_to_musb(struct dma_controller *c)
+{
+	struct cppi41_dma_controller *controller = container_of(c,
+			struct cppi41_dma_controller, controller);
+
+	return controller->musb;
+}
+EXPORT_SYMBOL_GPL(cppi41_dma_controller_to_musb);
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 46357e1..7f3c585 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -231,9 +231,13 @@  extern struct dma_controller *
 cppi_dma_controller_create(struct musb *musb, void __iomem *base);
 extern void cppi_dma_controller_destroy(struct dma_controller *c);
 
+typedef void (*cppi41_platform_dma_callback)(struct musb *musb);
 extern struct dma_controller *
 cppi41_dma_controller_create(struct musb *musb, void __iomem *base);
 extern void cppi41_dma_controller_destroy(struct dma_controller *c);
+extern struct musb *cppi41_dma_controller_to_musb(struct dma_controller *c);
+extern void cppi41_register_dma_callback(struct dma_controller *c,
+					 cppi41_platform_dma_callback callback);
 
 extern struct dma_controller *
 ux500_dma_controller_create(struct musb *musb, void __iomem *base);