diff mbox

[v4,2/7] usb: chipidea: add otg file

Message ID 1356591603-23323-3-git-send-email-peter.chen@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Chen Dec. 27, 2012, 6:59 a.m. UTC
Implement struct usb_otg, In that way, calling otg_set_peripheral
will not be failed at udc.c.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
---
Changes for v4:
- Some tiny changes, like delete unused header files

 drivers/usb/chipidea/Makefile |    2 +-
 drivers/usb/chipidea/ci.h     |    2 +
 drivers/usb/chipidea/otg.c    |   60 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/chipidea/otg.h    |    6 ++++
 4 files changed, 69 insertions(+), 1 deletions(-)

Comments

Sascha Hauer Dec. 27, 2012, 10:47 a.m. UTC | #1
On Thu, Dec 27, 2012 at 02:59:58PM +0800, Peter Chen wrote:
> Implement struct usb_otg, In that way, calling otg_set_peripheral
> will not be failed at udc.c.
> 
> Signed-off-by: Peter Chen <peter.chen@freescale.com>
> ---
> Changes for v4:
> - Some tiny changes, like delete unused header files
> 
>  drivers/usb/chipidea/Makefile |    2 +-
>  drivers/usb/chipidea/ci.h     |    2 +
>  drivers/usb/chipidea/otg.c    |   60 +++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/chipidea/otg.h    |    6 ++++
>  4 files changed, 69 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index d92ca32..11f513c 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -2,7 +2,7 @@ ccflags-$(CONFIG_USB_CHIPIDEA_DEBUG) := -DDEBUG
>  
>  obj-$(CONFIG_USB_CHIPIDEA)		+= ci_hdrc.o
>  
> -ci_hdrc-y				:= core.o
> +ci_hdrc-y				:= core.o otg.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC)	+= udc.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST)	+= host.o
>  ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG)	+= debug.o
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index d738603..8702871 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -129,6 +129,7 @@ struct hw_bank {
>   * @vbus_active: is VBUS active
>   * @transceiver: pointer to USB PHY, if any
>   * @hcd: pointer to usb_hcd for ehci host driver
> + * @otg: for otg support
>   */
>  struct ci13xxx {
>  	struct device			*dev;
> @@ -164,6 +165,7 @@ struct ci13xxx {
>  	bool				global_phy;
>  	struct usb_phy			*transceiver;
>  	struct usb_hcd			*hcd;
> +	struct usb_otg      otg;

I'd really like to know how this is going to proceed.

The ULPI driver currently allocates a struct usb_otg and sets
otg->set_host and otg->set_vbus. Since now the chipidea driver uses its
own struct usb_otg, this will not work with ULPI support.

I see some ways out of this:

- Use a pointer above instead of an own struct usb_otg in the ci driver.
- move the set_host and set_vbus callbacks to struct usb_phy.

I'd like to have this solved before we merge this patch.

Sascha
Peter Chen Dec. 28, 2012, 2:14 a.m. UTC | #2
On Thu, Dec 27, 2012 at 11:47:58AM +0100, Sascha Hauer wrote:
> On Thu, Dec 27, 2012 at 02:59:58PM +0800, Peter Chen wrote:
> >  struct ci13xxx {
> >  	struct device			*dev;
> > @@ -164,6 +165,7 @@ struct ci13xxx {
> >  	bool				global_phy;
> >  	struct usb_phy			*transceiver;
> >  	struct usb_hcd			*hcd;
> > +	struct usb_otg      otg;
> 
> I'd really like to know how this is going to proceed.
> 
> The ULPI driver currently allocates a struct usb_otg and sets
> otg->set_host and otg->set_vbus. Since now the chipidea driver uses its
> own struct usb_otg, this will not work with ULPI support.
We discussed before that the otg is not related to phy.
The struct usb_otg is better allocated at the otg driver, not phy driver.

I have a look at other phy drivers(drivers/usb/phy), now, there
is no one to create struct usb_otg at their phy drivers. To solve this
problem, we may need to modify ulpi phy driver.

To integrate ULPI phy, we may need to do:
- Make ulpi as a platform driver
- Override otg.set_host, and otg.set_vbus with ulpi's at
otg_ulpi_create or what else.
- Call otg_ulpi_create at the end of ci13xxx_imx_probe (before
pm_runtime_no_callbacks) if the phy is ulpi.

> 
> I see some ways out of this:
> 
> - Use a pointer above instead of an own struct usb_otg in the ci driver.
> - move the set_host and set_vbus callbacks to struct usb_phy.
> 
> I'd like to have this solved before we merge this patch.
> 
> Sascha
> 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>
diff mbox

Patch

diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index d92ca32..11f513c 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -2,7 +2,7 @@  ccflags-$(CONFIG_USB_CHIPIDEA_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_USB_CHIPIDEA)		+= ci_hdrc.o
 
-ci_hdrc-y				:= core.o
+ci_hdrc-y				:= core.o otg.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC)	+= udc.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST)	+= host.o
 ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG)	+= debug.o
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index d738603..8702871 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -129,6 +129,7 @@  struct hw_bank {
  * @vbus_active: is VBUS active
  * @transceiver: pointer to USB PHY, if any
  * @hcd: pointer to usb_hcd for ehci host driver
+ * @otg: for otg support
  */
 struct ci13xxx {
 	struct device			*dev;
@@ -164,6 +165,7 @@  struct ci13xxx {
 	bool				global_phy;
 	struct usb_phy			*transceiver;
 	struct usb_hcd			*hcd;
+	struct usb_otg      otg;
 };
 
 static inline struct ci_role_driver *ci_role(struct ci13xxx *ci)
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
new file mode 100644
index 0000000..7dea3b3
--- /dev/null
+++ b/drivers/usb/chipidea/otg.c
@@ -0,0 +1,60 @@ 
+/*
+ * otg.c - ChipIdea USB IP core OTG driver
+ *
+ * Copyright (C) 2012 Freescale Semiconductor, Inc.
+ *
+ * Author: Peter Chen
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/chipidea.h>
+
+#include "ci.h"
+#include "udc.h"
+#include "bits.h"
+#include "host.h"
+#include "debug.h"
+
+static int ci_otg_set_peripheral(struct usb_otg *otg,
+		struct usb_gadget *periph)
+{
+	otg->gadget = periph;
+
+	return 0;
+}
+
+static int ci_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	otg->host = host;
+
+	return 0;
+}
+
+/**
+ * ci_hdrc_otg_init - initialize device related bits
+ * ci: the controller
+ *
+ * This function create otg struct, if the device can switch between
+ * device and host.
+ */
+int ci_hdrc_otg_init(struct ci13xxx *ci)
+{
+	/* Useless at current */
+	ci->otg.set_peripheral = ci_otg_set_peripheral;
+	ci->otg.set_host = ci_otg_set_host;
+	if (!IS_ERR_OR_NULL(ci->transceiver))
+		ci->transceiver->otg = &ci->otg;
+
+	return 0;
+}
diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h
new file mode 100644
index 0000000..b4c6b3e
--- /dev/null
+++ b/drivers/usb/chipidea/otg.h
@@ -0,0 +1,6 @@ 
+#ifndef __DRIVERS_USB_CHIPIDEA_OTG_H
+#define __DRIVERS_USB_CHIPIDEA_OTG_H
+
+int ci_hdrc_otg_init(struct ci13xxx *ci);
+
+#endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */