Skip to contentSkip to conversation

Add MSM USB controller driver

PATCH In review Pavankumar Kondeti 1 participant 13 messages Dec 7, 2010 – Dec 9, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Add MSM USB controller driver

This patch series adds USB peripheral, host and OTG (role switch based on Id pin status) support for MSM SoC. The peripheral controller driver patches include splitting ci13xxx_udc into core and bus glue layers. Peripheral and Host controller drivers depend on Transceiver driver for clock management and low power mode. Peripheral and Host devices are made children of OTG device when devices are registered. Runtime PM functions are used by Peripheral and Host controller drivers to tell their state to transceiver driver which actually takes care of putting hardware into low power mode.

Change from V2:
1. Added core_clock in transceiver driver. This clock is introduced from MSM7x30 onwards to remove dependency on AXI bus frequency.
2. Use debugfs instead of sysfs for role switching option.
3. pm_runtime_nocallbacks() is used instead for nop runtime PM methods.
4. Peripheral controller driver makes use of ci13xxx_udc core.

Pavankumar Kondeti (11):
USB: Add MSM OTG Controller driver
USB: EHCI: Add MSM Host Controller driver
USB: EHCI: msm: Add support for power management
USB: OTG: msm: Add support for power management
USB: gadget: Separate out PCI bus code from ci13xxx_udc
USB: gadget: Fix "scheduling while atomic" bugs in ci13xxx_udc
USB: gadget: Initialize ci13xxx gadget device's coherent DMA mask
USB: gadget: Introduce ci13xxx_udc_driver struct
USB: gadget: Add USB controller driver for MSM SoC
USB: gadget: Implement runtime PM for ci13xxx gadget
USB: gadget: Implement runtime PM for MSM bus glue driver

 drivers/usb/Kconfig               |    1 +
 drivers/usb/gadget/Kconfig        |   29 +-
 drivers/usb/gadget/Makefile       |    3 +-
 drivers/usb/gadget/ci13xxx_msm.c  |  134 +++++
 drivers/usb/gadget/ci13xxx_pci.c  |  176 ++++++
 drivers/usb/gadget/ci13xxx_udc.c  |  384 ++++++-------
 drivers/usb/gadget/ci13xxx_udc.h  |   19 +
 drivers/usb/gadget/gadget_chips.h |   16 +-
 drivers/usb/host/Kconfig          |   11 +
 drivers/usb/host/ehci-hcd.c       |    5 +
 drivers/usb/host/ehci-msm.c       |  345 ++++++++++++
 drivers/usb/otg/Kconfig           |   11 +
 drivers/usb/otg/Makefile          |    1 +
 drivers/usb/otg/msm72k_otg.c      | 1125 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/msm_hsusb.h     |  112 ++++
 include/linux/usb/msm_hsusb_hw.h  |   59 ++
 16 files changed, 2203 insertions(+), 228 deletions(-)
 create mode 100644 drivers/usb/gadget/ci13xxx_msm.c
 create mode 100644 drivers/usb/gadget/ci13xxx_pci.c
 create mode 100644 drivers/usb/host/ehci-msm.c
 create mode 100644 drivers/usb/otg/msm72k_otg.c
 create mode 100644 include/linux/usb/msm_hsusb.h
 create mode 100644 include/linux/usb/msm_hsusb_hw.h
#1 lore raw

PATCH v3 1/11 USB: Add MSM OTG Controller driver

This driver implements PHY initialization, clock management, ULPI IO ops and simple OTG state machine to kick host/peripheral based on Id/VBUS line status. VBUS/Id lines are tied to a reference voltage on some boards. Hence provide debugfs interface to select host/peripheral mode.

---
 drivers/usb/otg/Kconfig          |   10 +
 drivers/usb/otg/Makefile         |    1 +
 drivers/usb/otg/msm72k_otg.c     |  850 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/msm_hsusb.h    |  108 +++++
 include/linux/usb/msm_hsusb_hw.h |   56 +++
 5 files changed, 1025 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/msm72k_otg.c
 create mode 100644 include/linux/usb/msm_hsusb.h
 create mode 100644 include/linux/usb/msm_hsusb_hw.h
drivers/usb/otg/Kconfig +10 -0
index 5ce0752..915c729 100644
@@ -81,4 +81,14 @@ config USB_LANGWELL_OTG
 	  To compile this driver as a module, choose M here: the
 	  module will be called langwell_otg.
 
+config USB_MSM_OTG_72K
+	tristate "OTG support for Qualcomm on-chip USB controller"
+	depends on (USB || USB_GADGET) && ARCH_MSM
+	select USB_OTG_UTILS
+	help
+	  Enable this to support the USB OTG transceiver on MSM chips. It
+	  handles PHY initialization, clock management, and workarounds
+	  required after resetting the hardware. This driver is required
+	  even for peripheral only or host only mode configuration.
+
 endif # USB || OTG
drivers/usb/otg/Makefile +1 -0
index 66f1b83..3b1b096 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_TWL4030_USB)	+= twl4030-usb.o
 obj-$(CONFIG_USB_LANGWELL_OTG)	+= langwell_otg.o
 obj-$(CONFIG_NOP_USB_XCEIV)	+= nop-usb-xceiv.o
 obj-$(CONFIG_USB_ULPI)		+= ulpi.o
+obj-$(CONFIG_USB_MSM_OTG_72K)	+= msm72k_otg.o
drivers/usb/otg/msm72k_otg.c new file +850 -0

850 lines not on this page · raw message

include/linux/usb/msm_hsusb.h new file +108 -0

108 lines not on this page · raw message

include/linux/usb/msm_hsusb_hw.h new file +56 -0

56 lines not on this page · raw message

Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#2 lore raw

PATCH v3 2/11 USB: EHCI: Add MSM Host Controller driver

In reply to Pavankumar Kondeti

This patch adds support for EHCI compliant HSUSB Host controller found on MSM chips. The root hub has a single port and TT is built into it. This driver depends on OTG driver for PHY initialization, clock management and powering up VBUS.

---
 drivers/usb/Kconfig         |    1 +
 drivers/usb/host/Kconfig    |   11 ++
 drivers/usb/host/ehci-hcd.c |    5 +
 drivers/usb/host/ehci-msm.c |  290 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 307 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-msm.c
drivers/usb/Kconfig +1 -0
index 6585f0b..b8e70a9 100644
@@ -64,6 +64,7 @@ config USB_ARCH_HAS_EHCI
 	default y if ARCH_OMAP3
 	default y if ARCH_VT8500
 	default y if PLAT_SPEAR
+	default y if ARCH_MSM
 	default PCI
 
 # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
drivers/usb/host/Kconfig +11 -0
index 6a7c688..d8665ec 100644
@@ -141,6 +141,17 @@ config USB_EHCI_HCD_OMAP
 	  Enables support for the on-chip EHCI controller on
 	  OMAP3 and later chips.
 
+config USB_EHCI_MSM
+	bool "Support for MSM on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MSM
+	select USB_EHCI_ROOT_HUB_TT
+	select USB_MSM_OTG_72K
+	---help---
+	  Enables support for the USB Host controller present on the
+	  Qualcomm chipsets. Root Hub has inbuilt TT.
+	  This driver depends on OTG driver for PHY initialization,
+	  clock management, powering up VBUS.
+
 config USB_EHCI_HCD_PPC_OF
 	bool "EHCI support for PPC USB controller on OF platform bus"
 	depends on USB_EHCI_HCD && PPC_OF
drivers/usb/host/ehci-hcd.c +5 -0
index abe8336..cdd3ef8 100644
@@ -1231,6 +1231,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		spear_ehci_hcd_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MSM
+#include "ehci-msm.c"
+#define PLATFORM_DRIVER		ehci_msm_driver
+#endif
+
 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
     !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
     !defined(XILINX_OF_PLATFORM_DRIVER)
drivers/usb/host/ehci-msm.c new file +290 -0

290 lines not on this page · raw message

Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#3 lore raw

PATCH v3 3/11 USB: EHCI: msm: Add support for power management

In reply to Pavankumar Kondeti

Enable runtime PM and mark no_callbacks flag. OTG device, parent of HCD takes care of putting hardware into low power mode. Adjust port power wakeup flags during system suspend and resume.

---
 drivers/usb/host/Kconfig    |    2 +-
 drivers/usb/host/ehci-msm.c |   57 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 2 deletions(-)
drivers/usb/host/Kconfig +1 -1
index d8665ec..b9cc311 100644
@@ -150,7 +150,7 @@ config USB_EHCI_MSM
 	  Enables support for the USB Host controller present on the
 	  Qualcomm chipsets. Root Hub has inbuilt TT.
 	  This driver depends on OTG driver for PHY initialization,
-	  clock management, powering up VBUS.
+	  clock management, powering up VBUS, and power management.
 
 config USB_EHCI_HCD_PPC_OF
 	bool "EHCI support for PPC USB controller on OF platform bus"
drivers/usb/host/ehci-msm.c +56 -1

91 lines not on this page · raw message

Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#4 lore raw

PATCH v3 4/11 USB: OTG: msm: Add support for power management

In reply to Pavankumar Kondeti

Implement runtime and system pm ops to put hardware into low power mode (LPM). As part of LPM, USB clocks are turned off, PHY is put into suspend state and PHY comparators are turned off if VBUS/Id notifications are not required from PHY.

---
 drivers/usb/otg/Kconfig          |    5 +-
 drivers/usb/otg/msm72k_otg.c     |  283 +++++++++++++++++++++++++++++++++++++-
 include/linux/usb/msm_hsusb.h    |    4 +
 include/linux/usb/msm_hsusb_hw.h |    3 +
 4 files changed, 289 insertions(+), 6 deletions(-)
drivers/usb/otg/Kconfig +3 -2
index 915c729..2810c2a 100644
@@ -88,7 +88,8 @@ config USB_MSM_OTG_72K
 	help
 	  Enable this to support the USB OTG transceiver on MSM chips. It
 	  handles PHY initialization, clock management, and workarounds
-	  required after resetting the hardware. This driver is required
-	  even for peripheral only or host only mode configuration.
+	  required after resetting the hardware and power management.
+	  This driver is required even for peripheral only or host only
+	  mode configurations.
 
 endif # USB || OTG
drivers/usb/otg/msm72k_otg.c +279 -4

391 lines not on this page · raw message

include/linux/usb/msm_hsusb.h +4 -0
index b796df9..3675e03 100644
@@ -88,6 +88,8 @@ struct msm_otg_platform_data {
  * @regs: ioremapped register base address.
  * @inputs: OTG state machine inputs(Id, SessValid etc).
  * @sm_work: OTG state machine work.
+ * @in_lpm: indicates low power mode (LPM) state.
+ * @async_int: Async interrupt arrived.
  *
  */
 struct msm_otg {
@@ -103,6 +105,8 @@ struct msm_otg {
 #define B_SESS_VLD	1
 	unsigned long inputs;
 	struct work_struct sm_work;
+	atomic_t in_lpm;
+	int async_int;
 };
 
 #endif
include/linux/usb/msm_hsusb_hw.h +3 -0
index b061cff..b92e173 100644
@@ -44,6 +44,9 @@
 #define ULPI_DATA(n)          ((n) & 255)
 #define ULPI_DATA_READ(n)     (((n) >> 8) & 255)
 
+#define ASYNC_INTR_CTRL         (1 << 29) /* Enable async interrupt */
+#define ULPI_STP_CTRL           (1 << 30) /* Block communication with PHY */
+
 /* OTG definitions */
 #define OTGSC_INTSTS_MASK	(0x7f << 16)
 #define OTGSC_ID		(1 << 8)
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#5 lore raw

PATCH v3 5/11 USB: gadget: Separate out PCI bus code from ci13xxx_udc

In reply to Pavankumar Kondeti

Move PCI bus code from ci13xxx_udc to a new file ci13xxx_pci. SoC's which has MIPS USB core can include the ci13xxx_udc and keep bus glue code in their respective gadget controller drivers.

---
 drivers/usb/gadget/Kconfig        |    8 +-
 drivers/usb/gadget/Makefile       |    2 +-
 drivers/usb/gadget/ci13xxx_pci.c  |  172 +++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/ci13xxx_udc.c  |  159 ----------------------------------
 drivers/usb/gadget/gadget_chips.h |    8 +-
 5 files changed, 181 insertions(+), 168 deletions(-)
 create mode 100644 drivers/usb/gadget/ci13xxx_pci.c
drivers/usb/gadget/Kconfig +4 -4
index 23fac38..6bcbcb0 100644
@@ -427,8 +427,8 @@ config USB_FSL_QE
 	default USB_GADGET
 	select USB_GADGET_SELECTED
 
-config USB_GADGET_CI13XXX
-	boolean "MIPS USB CI13xxx"
+config USB_GADGET_CI13XXX_PCI
+	boolean "MIPS USB CI13xxx PCI UDC"
 	depends on PCI
 	select USB_GADGET_DUALSPEED
 	help
@@ -439,9 +439,9 @@ config USB_GADGET_CI13XXX
 	  dynamically linked module called "ci13xxx_udc" and force all
 	  gadget drivers to also be dynamically linked.
 
-config USB_CI13XXX
+config USB_CI13XXX_PCI
 	tristate
-	depends on USB_GADGET_CI13XXX
+	depends on USB_GADGET_CI13XXX_PCI
 	default USB_GADGET
 	select USB_GADGET_SELECTED
 
drivers/usb/gadget/Makefile +1 -1
index a3e6b90..f53fda7 100644
@@ -21,7 +21,7 @@ fsl_usb2_udc-$(CONFIG_ARCH_MXC)	+= fsl_mxc_udc.o
 obj-$(CONFIG_USB_M66592)	+= m66592-udc.o
 obj-$(CONFIG_USB_R8A66597)	+= r8a66597-udc.o
 obj-$(CONFIG_USB_FSL_QE)	+= fsl_qe_udc.o
-obj-$(CONFIG_USB_CI13XXX)	+= ci13xxx_udc.o
+obj-$(CONFIG_USB_CI13XXX_PCI)	+= ci13xxx_pci.o
 obj-$(CONFIG_USB_S3C_HSOTG)	+= s3c-hsotg.o
 obj-$(CONFIG_USB_LANGWELL)	+= langwell_udc.o
 obj-$(CONFIG_USB_EG20T)		+= pch_udc.o
drivers/usb/gadget/ci13xxx_pci.c new file +172 -0

172 lines not on this page · raw message

drivers/usb/gadget/ci13xxx_udc.c +0 -159

180 lines not on this page · raw message

drivers/usb/gadget/gadget_chips.h +4 -4
index d7b3bbe..3093ebb 100644
@@ -120,10 +120,10 @@
 #define gadget_is_fsl_qe(g)	0
 #endif
 
-#ifdef CONFIG_USB_GADGET_CI13XXX
-#define gadget_is_ci13xxx(g)	(!strcmp("ci13xxx_udc", (g)->name))
+#ifdef CONFIG_USB_GADGET_CI13XXX_PCI
+#define gadget_is_ci13xxx_pci(g)	(!strcmp("ci13xxx_pci", (g)->name))
 #else
-#define gadget_is_ci13xxx(g)	0
+#define gadget_is_ci13xxx_pci(g)	0
 #endif
 
 // CONFIG_USB_GADGET_SX2
@@ -197,7 +197,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
 		return 0x21;
 	else if (gadget_is_fsl_qe(gadget))
 		return 0x22;
-	else if (gadget_is_ci13xxx(gadget))
+	else if (gadget_is_ci13xxx_pci(gadget))
 		return 0x23;
 	else if (gadget_is_langwell(gadget))
 		return 0x24;
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#6 lore raw

PATCH v3 6/11 USB: gadget: Fix "scheduling while atomic" bugs in ci13xxx_udc

In reply to Pavankumar Kondeti

dma_pool_alloc() require sleeping context when called with GFP_KERNEL argument. Hence release the spin lock before calling dma_pool_alloc().

usb_ep_alloc_request can also be called with non-atomic GFP flags. Hence get rid off spin lock while allocation request memory.

Use GFP_ATOMIC flag for allocating request for ep0 in interrupt handler.

---
 drivers/usb/gadget/ci13xxx_udc.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/usb/gadget/ci13xxx_udc.c +3 -6
index 4e9ec7d..d19537a 100644
@@ -1626,7 +1626,7 @@ __acquires(udc->lock)
 	spin_unlock(udc->lock);
 	retval = usb_ep_enable(&mEp->ep, &ctrl_endpt_desc);
 	if (!retval) {
-		mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_KERNEL);
+		mEp->status = usb_ep_alloc_request(&mEp->ep, GFP_ATOMIC);
 		if (mEp->status == NULL) {
 			usb_ep_disable(&mEp->ep);
 			retval = -ENOMEM;
@@ -2055,7 +2055,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
 {
 	struct ci13xxx_ep  *mEp  = container_of(ep, struct ci13xxx_ep, ep);
 	struct ci13xxx_req *mReq = NULL;
-	unsigned long flags;
 
 	trace("%p, %i", ep, gfp_flags);
 
@@ -2064,8 +2063,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
 		return NULL;
 	}
 
-	spin_lock_irqsave(mEp->lock, flags);
-
 	mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags);
 	if (mReq != NULL) {
 		INIT_LIST_HEAD(&mReq->queue);
@@ -2080,8 +2077,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
 
 	dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL);
 
-	spin_unlock_irqrestore(mEp->lock, flags);
-
 	return (mReq == NULL) ? NULL : &mReq->req;
 }
 
@@ -2404,9 +2399,11 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
 		/* this allocation cannot be random */
 		for (k = RX; k <= TX; k++) {
 			INIT_LIST_HEAD(&mEp->qh[k].queue);
+			spin_unlock_irqrestore(udc->lock, flags);
 			mEp->qh[k].ptr = dma_pool_alloc(udc->qh_pool,
 							GFP_KERNEL,
 							&mEp->qh[k].dma);
+			spin_lock_irqsave(udc->lock, flags);
 			if (mEp->qh[k].ptr == NULL)
 				retval = -ENOMEM;
 			else
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#7 lore raw

PATCH v3 7/11 USB: gadget: Initialize ci13xxx gadget device's coherent DMA mask

In reply to Pavankumar Kondeti

dma_alloc_coherent() which is internally called by dma_pool_alloc() flags a warning if device's coherent DMA mask. Hence initialize gadget device's coherent DMA mask to it's parent mask.

---
 drivers/usb/gadget/ci13xxx_udc.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/usb/gadget/ci13xxx_udc.c +1 -0
index d19537a..956fa64 100644
@@ -2624,6 +2624,7 @@ static int udc_probe(struct device *dev, void __iomem *regs, const char *name)
 
 	dev_set_name(&udc->gadget.dev, "gadget");
 	udc->gadget.dev.dma_mask = dev->dma_mask;
+	udc->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask;
 	udc->gadget.dev.parent   = dev;
 	udc->gadget.dev.release  = udc_release;
 
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#8 lore raw

PATCH v3 8/11 USB: gadget: Introduce ci13xxx_udc_driver struct

In reply to Pavankumar Kondeti

Introduces ci13xxx_udc_driver struct for bus glue drivers to hint ci13xxx_udc core about their special requirements. The flags include avoiding hardware register access when controller is not in peripheral mode, enabling pull-up upon VBUS, disabling streaming mode and dependency on transceiver driver.

Initialize gadget_ops in udc_probe so that transceiver can notify VBUS presence even when no gadget driver is bounded.

A notify_event callback is embedded in the same struct. This patch implements two events called CONTROLLER_RESET_EVENT and CONTROLLER_STOPPED_EVENT to notify the bus glue driver after resetting and stopping the controller for performing SoC specific quirks.

---
 drivers/usb/gadget/ci13xxx_pci.c |    6 +-
 drivers/usb/gadget/ci13xxx_udc.c |  205 ++++++++++++++++++++++++++++----------
 drivers/usb/gadget/ci13xxx_udc.h |   19 ++++
 3 files changed, 175 insertions(+), 55 deletions(-)
drivers/usb/gadget/ci13xxx_pci.c +5 -1
index 7a0f153..883ab5e 100644
@@ -38,6 +38,10 @@ static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev)
 	return udc_irq();
 }
 
+static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver = {
+	.name		= UDC_DRIVER_NAME,
+};
+
 /**
  * ci13xxx_pci_probe: PCI probe
  * @pdev: USB device controller being probed
@@ -82,7 +86,7 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_try_set_mwi(pdev);
 
-	retval = udc_probe(&pdev->dev, regs, UDC_DRIVER_NAME);
+	retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs);
 	if (retval)
 		goto iounmap;
 
drivers/usb/gadget/ci13xxx_udc.c +151 -54

364 lines not on this page · raw message

drivers/usb/gadget/ci13xxx_udc.h +19 -0
index 4026e9c..4fd1931 100644
@@ -97,9 +97,24 @@ struct ci13xxx_ep {
 	struct dma_pool                       *td_pool;
 };
 
+struct ci13xxx;
+struct ci13xxx_udc_driver {
+	const char	*name;
+	unsigned long	 flags;
+#define CI13XXX_REGS_SHARED		BIT(0)
+#define CI13XXX_REQUIRE_TRANSCEIVER	BIT(1)
+#define CI13XXX_PULLUP_ON_VBUS		BIT(2)
+#define CI13XXX_DISABLE_STREAMING	BIT(3)
+
+#define CI13XXX_CONTROLLER_RESET_EVENT		0
+#define CI13XXX_CONTROLLER_STOPPED_EVENT	1
+	void	(*notify_event) (struct ci13xxx *udc, unsigned event);
+};
+
 /* CI13XXX UDC descriptor & global resources */
 struct ci13xxx {
 	spinlock_t		  *lock;      /* ctrl register bank access */
+	void __iomem              *regs;      /* registers address space */
 
 	struct dma_pool           *qh_pool;   /* DMA pool for queue heads */
 	struct dma_pool           *td_pool;   /* DMA pool for transfer descs */
@@ -108,6 +123,9 @@ struct ci13xxx {
 	struct ci13xxx_ep          ci13xxx_ep[ENDPT_MAX]; /* extended endpts */
 
 	struct usb_gadget_driver  *driver;     /* 3rd party gadget driver */
+	struct ci13xxx_udc_driver *udc_driver; /* device controller driver */
+	int                        vbus_active; /* is VBUS active */
+	struct otg_transceiver    *transceiver; /* Transceiver struct */
 };
 
 /******************************************************************************
@@ -157,6 +175,7 @@ struct ci13xxx {
 #define    USBMODE_CM_DEVICE  (0x02UL <<  0)
 #define    USBMODE_CM_HOST    (0x03UL <<  0)
 #define USBMODE_SLOM          BIT(3)
+#define USBMODE_SDIS          BIT(4)
 
 /* ENDPTCTRL */
 #define ENDPTCTRL_RXS         BIT(0)
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#9 lore raw

PATCH v3 9/11 USB: gadget: Add USB controller driver for MSM SoC

In reply to Pavankumar Kondeti

MSM SoC has chipidea USB controller. So use ci13xxx_udc core. This driver depends on transceiver driver for clock control, PHY initialization, VBUS detection. Register for notify_event callback to perform MSM specific quirks after controller is reset and stopped.

---
 drivers/usb/gadget/Kconfig        |   21 ++++++
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/ci13xxx_msm.c  |  130 +++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/gadget_chips.h |    8 ++
 4 files changed, 160 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/ci13xxx_msm.c
drivers/usb/gadget/Kconfig +21 -0
index 6bcbcb0..7201b4e 100644
@@ -531,6 +531,27 @@ config USB_EG20T
 	default USB_GADGET
 	select USB_GADGET_SELECTED
 
+config USB_GADGET_CI13XXX_MSM
+	boolean "MIPS USB CI13xxx for MSM"
+	depends on ARCH_MSM
+	select USB_GADGET_DUALSPEED
+	select USB_MSM_OTG_72K
+	help
+	  MSM SoC has chipidea USB controller.  This driver uses
+	  ci13xxx_udc core.
+	  This driver depends on OTG driver for PHY initialization,
+	  clock management, powering up VBUS, and power management.
+
+	  Say "y" to link the driver statically, or "m" to build a
+	  dynamically linked module called "ci13xxx_msm" and force all
+	  gadget drivers to also be dynamically linked.
+
+config USB_CI13XXX_MSM
+	tristate
+	depends on USB_GADGET_CI13XXX_MSM
+	default USB_GADGET
+	select USB_GADGET_SELECTED
+
 #
 # LAST -- dummy/emulated controller
 #
drivers/usb/gadget/Makefile +1 -0
index f53fda7..fbf5db4 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_USB_LANGWELL)	+= langwell_udc.o
 obj-$(CONFIG_USB_EG20T)		+= pch_udc.o
 obj-$(CONFIG_USB_PXA_U2O)	+= mv_udc.o
 mv_udc-y			:= mv_udc_core.o mv_udc_phy.o
+obj-$(CONFIG_USB_CI13XXX_MSM)	+= ci13xxx_msm.o
 
 #
 # USB gadget drivers
drivers/usb/gadget/ci13xxx_msm.c new file +130 -0

130 lines not on this page · raw message

drivers/usb/gadget/gadget_chips.h +8 -0
index 3093ebb..ad2114e 100644
@@ -148,6 +148,12 @@
 #define	gadget_is_pch(g)	0
 #endif
 
+#ifdef CONFIG_USB_GADGET_CI13XXX_MSM
+#define gadget_is_ci13xxx_msm(g)	(!strcmp("ci13xxx_msm", (g)->name))
+#else
+#define gadget_is_ci13xxx_msm(g)	0
+#endif
+
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -207,6 +213,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
 		return 0x26;
 	else if (gadget_is_pch(gadget))
 		return 0x27;
+	else if (gadget_is_ci13xxx_msm(gadget))
+		return 0x28;
 	return -ENOENT;
 }
 
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#10 lore raw

PATCH v3 10/11 USB: gadget: Implement runtime PM for ci13xxx gadget

In reply to Pavankumar Kondeti

The actual suspend/resume work is delegated to bus glue driver, which is responsible for putting hardware in low power mode.

---
 drivers/usb/gadget/ci13xxx_udc.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/usb/gadget/ci13xxx_udc.c +10 -0
index c10d1ae..f200e47 100644
@@ -60,6 +60,7 @@
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/otg.h>
@@ -2348,6 +2349,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
 
 	if (gadget_ready) {
 		if (is_active) {
+			pm_runtime_get_sync(&_gadget->dev);
 			hw_device_reset(udc);
 			hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma);
 		} else {
@@ -2356,6 +2358,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
 				udc->udc_driver->notify_event(udc,
 				CI13XXX_CONTROLLER_STOPPED_EVENT);
 			_gadget_stop_activity(&udc->gadget);
+			pm_runtime_put_sync(&_gadget->dev);
 		}
 	}
 
@@ -2473,16 +2476,20 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
 		goto done;
 	}
 
+	pm_runtime_get_sync(&udc->gadget.dev);
 	if (udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) {
 		if (udc->vbus_active) {
 			if (udc->udc_driver->flags & CI13XXX_REGS_SHARED)
 				hw_device_reset(udc);
 		} else {
+			pm_runtime_put_sync(&udc->gadget.dev);
 			goto done;
 		}
 	}
 
 	retval = hw_device_state(udc->ci13xxx_ep[0].qh[RX].dma);
+	if (retval)
+		pm_runtime_put_sync(&udc->gadget.dev);
 
  done:
 	spin_unlock_irqrestore(udc->lock, flags);
@@ -2522,6 +2529,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 			udc->udc_driver->notify_event(udc,
 			CI13XXX_CONTROLLER_STOPPED_EVENT);
 		_gadget_stop_activity(&udc->gadget);
+		pm_runtime_put(&udc->gadget.dev);
 	}
 
 	/* unbind gadget */
@@ -2723,6 +2731,8 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
 		if (retval)
 			goto remove_dbg;
 	}
+	pm_runtime_no_callbacks(&udc->gadget.dev);
+	pm_runtime_enable(&udc->gadget.dev);
 
 	_udc = udc;
 	return retval;
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#11 lore raw

PATCH v3 11/11 USB: gadget: Implement runtime PM for MSM bus glue driver

In reply to Pavankumar Kondeti

OTG driver takes care of putting hardware in low power mode. Hence not registered for any runtime PM callbacks.

---
 drivers/usb/gadget/ci13xxx_msm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/usb/gadget/ci13xxx_msm.c +4 -0
index c497337..139ac94 100644
@@ -18,6 +18,7 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/usb/msm_hsusb_hw.h>
 #include <linux/usb/ulpi.h>
 
@@ -108,6 +109,9 @@ static int ci13xxx_msm_probe(struct platform_device *pdev)
 		goto udc_remove;
 	}
 
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
 	return 0;
 
 udc_remove:
Signature · 4 lines
1.7.1
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#12 lore raw
In reply to Pavankumar Kondeti

Hi All,

Quoted 16 lines · Pavankumar Kondeti

This patch series adds USB peripheral, host and OTG (role switch based on Id pin status) support for MSM SoC. The peripheral controller driver patches include splitting ci13xxx_udc into core and bus glue layers. Peripheral and Host controller drivers depend on Transceiver driver for clock management and low power mode. Peripheral and Host devices are made children of OTG device when devices are registered. Runtime PM functions are used by Peripheral and Host controller drivers to tell their state to transceiver driver which actually takes care of putting hardware into low power mode.

Change from V2:
1. Added core_clock in transceiver driver. This clock is introduced from MSM7x30 onwards to remove dependency on AXI bus frequency.
2. Use debugfs instead of sysfs for role switching option.
3. pm_runtime_nocallbacks() is used instead for nop runtime PM methods.
4. Peripheral controller driver makes use of ci13xxx_udc core.

Quoted 13 lines

Pavankumar Kondeti (11):
USB: Add MSM OTG Controller driver
USB: EHCI: Add MSM Host Controller driver
USB: EHCI: msm: Add support for power management
USB: OTG: msm: Add support for power management
USB: gadget: Separate out PCI bus code from ci13xxx_udc
USB: gadget: Fix "scheduling while atomic" bugs in ci13xxx_udc
USB: gadget: Initialize ci13xxx gadget device's coherent DMA mask
USB: gadget: Introduce ci13xxx_udc_driver struct
USB: gadget: Add USB controller driver for MSM SoC
USB: gadget: Implement runtime PM for ci13xxx gadget
USB: gadget: Implement runtime PM for MSM bus glue driver

I have received feedback to re-use the ci13xxx_udc driver when I submitted a new device controller driver (msm72k_udc.c) for MSM SoC.
http://www.mail-archive.com/[email protected]/msg01111.html

I have split ci13xxx_udc into generic ci13xxx_udc core and PCI bus glue driver. I have added a new bus glue driver for MSM. We need this bus glue driver to perform MSM specific quirks after controller is reset and stopped (i.e after disabling pull-up in device mode). I have verified ci13xxx_udc driver on MSM SoC. I don't have PCI ci13xxx hardware to test ci13xxx on PCI. I have not made any changes in PCI driver. So in theory, these patches should not break PCI driver. It would be really nice if any one can test 5-11 patches of this series
on PCI ci13xxx hardware.

Thanks in advance,
Pavan

Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.