Skip to contentSkip to conversation

Add MSM USB Device Controller support

PATCH Superseded Pavankumar Kondeti 4 participants 14 messages Sep 1, 2010 – Sep 2, 2010

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add MSM USB Device Controller support

This patch series adds basic support for USB device controller found in MSM family of SOCs. This driver is already being used in Android devices. This driver is tested with Android(ADB + Mass storage, RNDIS), ethernet, and file storage gadgets. All the USBCV Ch9 Tests and usbtest test cases are passed.

This driver is originally authored by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git

Pavankumar Kondeti (5):
USB: Add MSM USB Device Controller driver
USB: msm72k_udc: Add debugfs support
USB: msm72k_udc: Add Remote wakeup support
USB: msm72k_udc: Add Test Mode support
USB: msm72k_udc: Add charging notification support

 drivers/usb/gadget/Kconfig        |   17 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/gadget_chips.h |    8 +
 drivers/usb/gadget/msm72k_udc.c   | 1846 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/msm_hsusb.h     |   43 +
 include/linux/usb/msm_hsusb_hw.h  |  227 +++++
 6 files changed, 2142 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/msm72k_udc.c
 create mode 100644 include/linux/usb/msm_hsusb.h
 create mode 100644 include/linux/usb/msm_hsusb_hw.h
#1 lore raw

PATCH 1/5 USB: Add MSM USB Device Controller driver

This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.

VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.

This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

CC Mike Lockwood <[email protected]>
CC Brian Swetland <[email protected]>
---
 drivers/usb/gadget/Kconfig        |   17 +
 drivers/usb/gadget/Makefile       |    1 +
 drivers/usb/gadget/gadget_chips.h |    8 +
 drivers/usb/gadget/msm72k_udc.c   | 1591 +++++++++++++++++++++++++++++++++++++
 include/linux/usb/msm_hsusb.h     |   35 +
 include/linux/usb/msm_hsusb_hw.h  |  213 +++++
 6 files changed, 1865 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/msm72k_udc.c
 create mode 100644 include/linux/usb/msm_hsusb.h
 create mode 100644 include/linux/usb/msm_hsusb_hw.h
drivers/usb/gadget/Kconfig +17 -0
index cd27f9b..dbb045b 100644
@@ -505,6 +505,23 @@ config USB_LANGWELL
 	default USB_GADGET
 	select USB_GADGET_SELECTED
 
+config USB_GADGET_MSM_72K
+	boolean "MSM 72K Device Controller"
+	depends on ARCH_MSM
+	select USB_GADGET_SELECTED
+	select USB_GADGET_DUALSPEED
+	help
+	   USB gadget driver for Qualcomm MSM 72K architecture.
+
+	   Say "y" to link the driver statically, or "m" to build a
+	   dynamically linked module called "msm72k" and force all
+	   gadget drivers to also be dynamically linked.
+
+config USB_MSM_72K
+	tristate
+	depends on USB_GADGET_MSM_72K
+	default USB_GADGET
+	select USB_GADGET_SELECTED
 
 #
 # LAST -- dummy/emulated controller
drivers/usb/gadget/Makefile +1 -0
index 27283df..7c46b24 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FSL_QE)	+= fsl_qe_udc.o
 obj-$(CONFIG_USB_CI13XXX)	+= ci13xxx_udc.o
 obj-$(CONFIG_USB_S3C_HSOTG)	+= s3c-hsotg.o
 obj-$(CONFIG_USB_LANGWELL)	+= langwell_udc.o
+obj-$(CONFIG_USB_MSM_72K)	+= msm72k_udc.o
 
 #
 # USB gadget drivers
drivers/usb/gadget/gadget_chips.h +8 -0
index e511fec..a674221 100644
@@ -142,6 +142,12 @@
 #define gadget_is_s3c_hsotg(g)    0
 #endif
 
+#ifdef CONFIG_USB_GADGET_MSM_72K
+#define	gadget_is_msm72k(g)	(!strcmp("msm72k_udc", (g)->name))
+#else
+#define	gadget_is_msm72k(g)	0
+#endif
+
 
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
@@ -200,6 +206,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
 		return 0x25;
 	else if (gadget_is_s3c_hsotg(gadget))
 		return 0x26;
+	else if (gadget_is_msm72k(gadget))
+		return 0x27;
 	return -ENOENT;
 }
 
drivers/usb/gadget/msm72k_udc.c new file +1591 -0

1,591 lines not on this page · raw message

include/linux/usb/msm_hsusb.h new file +35 -0
new file mode 100644
index 0000000..534db4e
@@ -0,0 +1,35 @@
+/* linux/include/asm-arm/arch-msm/hsusb.h
+ *
+ * Copyright (C) 2008 Google, Inc.
+ * Author: Brian Swetland <[email protected]>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_HSUSB_H
+#define __ASM_ARCH_MSM_HSUSB_H
+
+#include <linux/types.h>
+
+/* platform device data for msm_hsusb driver */
+
+struct msm_hsusb_platform_data {
+	/* hard reset the ULPI PHY */
+	void (*phy_reset)(void);
+
+	/* (de)assert the reset to the usb core */
+	void (*hw_reset)(bool enable);
+
+	/* val, reg pairs terminated by -1 */
+	int *phy_init_seq;
+};
+
+#endif
include/linux/usb/msm_hsusb_hw.h new file +213 -0

213 lines not on this page · raw message

Signature · 5 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

Re: [PATCH 1/5] USB: Add MSM USB Device Controller driver

Quoted 10 lines · Pavankumar Kondeti

This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.

VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.

This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

...

drivers/usb/gadget/msm72k_udc.c line 1368

Quoted 13 lines
drivers/usb/gadget/msm72k_udc.c new file +13 -0
+static const struct usb_ep_ops msm72k_ep_ops = {
+	.enable		= msm72k_enable,
+	.disable	= msm72k_disable,
+
+	.alloc_request	= msm72k_alloc_request,
+	.free_request	= msm72k_free_request,
+
+	.queue		= msm72k_queue,
+	.dequeue	= msm72k_dequeue,
+
+	.set_halt	= msm72k_set_halt,
+	.fifo_flush	= msm72k_fifo_flush,
+};

The .set_wedge method is missing.

Alan Stern

#3 lore raw

Re: [PATCH 1/5] USB: Add MSM USB Device Controller driver

Quoted 15 lines · Alan Stern
Quoted 10 lines · Pavankumar Kondeti

This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.

VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.

This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

...

Quoted 15 lines

drivers/usb/gadget/msm72k_udc.c line 1368

Quoted 13 lines
drivers/usb/gadget/msm72k_udc.c new file +13 -0
+static const struct usb_ep_ops msm72k_ep_ops = {
+	.enable		= msm72k_enable,
+	.disable	= msm72k_disable,
+
+	.alloc_request	= msm72k_alloc_request,
+	.free_request	= msm72k_free_request,
+
+	.queue		= msm72k_queue,
+	.dequeue	= msm72k_dequeue,
+
+	.set_halt	= msm72k_set_halt,
+	.fifo_flush	= msm72k_fifo_flush,
+};

The .set_wedge method is missing.

Thanks for pointing this out. I will implement this method.

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.
#4 lore raw

Re: [PATCH 1/5] USB: Add MSM USB Device Controller driver

In reply to Alan Stern
Quoted 18 lines · Pavankumar Kondeti
Quoted 14 lines

This patch adds the basic support for the USB Device Controller on Qualcomm
MSM family of SOCs. The controller supports upto 16 endpoints including the
default endpoint (ep0). All the data transfers are driven by DMA.

VBUS line is also connected to PMIC chip. The module controlling PMIC chip
notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.

This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

...

Quoted 16 lines

drivers/usb/gadget/msm72k_udc.c line 1368

Quoted 13 lines
drivers/usb/gadget/msm72k_udc.c new file +13 -0
+static const struct usb_ep_ops msm72k_ep_ops = {
+	.enable		= msm72k_enable,
+	.disable	= msm72k_disable,
+
+	.alloc_request	= msm72k_alloc_request,
+	.free_request	= msm72k_free_request,
+
+	.queue		= msm72k_queue,
+	.dequeue	= msm72k_dequeue,
+
+	.set_halt	= msm72k_set_halt,
+	.fifo_flush	= msm72k_fifo_flush,
+};

The .set_wedge method is missing.

Thanks for pointing this out. I will implement this method.

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.
#5 lore raw

Re: [PATCH 1/5] USB: Add MSM USB Device Controller driver

In reply to Pavankumar Kondeti
Quoted 19 lines · Pavankumar Kondeti

This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs.  The controller supports upto 16 endpoints including the default endpoint (ep0).  All the data transfers are driven by DMA.

VBUS line is also connected to PMIC chip.  The module controlling PMIC chip notifies about cable connect/disconnect events.  Hence, PHY comparators are turned off in low power mode.

This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

CC Mike Lockwood <[email protected]>
CC Brian Swetland <[email protected]>

+++ b/drivers/usb/gadget/msm72k_udc.c

drivers/usb/gadget/msm72k_udc.c line 6

Quoted 6 lines
drivers/usb/gadget/msm72k_udc.c new file +6 -0
@@ -0,0 +1,1591 @@
+/*
+ * Driver for HighSpeed USB Client Controller in MSM7K
+ *
+ * Copyright (C) 2008 Google, Inc.
+ * Author: Mike Lockwood <[email protected]>
+ *         Brian Swetland <[email protected]>

Given that you guys have done a bunch of work on this, it might make sense to slap a codeaurora/quicinc copyright on there as well. Might also make sense to drop the old Author: lines and/or update them.

Quoted 12 lines
drivers/usb/gadget/msm72k_udc.c new file +12 -0
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
#6 lore raw

PATCH 2/5 USB: msm72k_udc: Add debugfs support

In reply to Pavankumar Kondeti

Provide debugfs files for reading endpoint registers and associated requests info, re-enumeration and resetting the hardware.

This patch was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

CC Mike Lockwood <[email protected]>
CC Brian Swetland <[email protected]>
---
 drivers/usb/gadget/msm72k_udc.c |  135 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 135 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +135 -0
index e405dc4..84315a2 100644
@@ -26,6 +26,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
 #include <linux/platform_device.h>
+#include <linux/debugfs.h>
 #include <linux/workqueue.h>
 #include <linux/clk.h>
 
@@ -118,6 +119,7 @@ static void usb_do_work(struct work_struct *w);
 #define USB_FLAG_START          0x0001
 #define USB_FLAG_VBUS_ONLINE    0x0002
 #define USB_FLAG_VBUS_OFFLINE   0x0004
+#define USB_FLAG_RESET          0x0008
 
 struct usb_info {
 	/* lock for register/queue/device state changes */
@@ -1152,6 +1154,12 @@ static void usb_do_work(struct work_struct *w)
 				usb_do_work_check_vbus(ui);
 				break;
 			}
+			if (flags & USB_FLAG_RESET) {
+				INFO("ONLINE -> RESET\n");
+				usb_reset(ui);
+				INFO("RESET -> ONLINE\n");
+				break;
+			}
 			break;
 		case USB_STATE_OFFLINE:
 			/* If we were signaled to go online and vbus is still
@@ -1196,6 +1204,131 @@ void msm_hsusb_set_vbus_state(int online)
 		spin_unlock_irqrestore(&ui->lock, flags);
 }
 
+#if defined(CONFIG_DEBUG_FS)
+void usb_function_reenumerate(void)
+{
+	struct usb_info *ui = the_usb_info;
+
+	/* disable and re-enable the D+ pullup */
+	msm72k_pullup(&ui->gadget, false);
+	usleep_range(10000, 12000);
+	msm72k_pullup(&ui->gadget, true);
+}
+
+static char debug_buffer[PAGE_SIZE];
+
+static ssize_t debug_read_status(struct file *file, char __user *ubuf,
+				 size_t count, loff_t *ppos)
+{
+	struct usb_info *ui = file->private_data;
+	char *buf = debug_buffer;
+	unsigned long flags;
+	struct msm_endpoint *ept;
+	struct msm_request *req;
+	int n;
+	int i = 0;
+
+	spin_lock_irqsave(&ui->lock, flags);
+
+	i += scnprintf(buf + i, PAGE_SIZE - i,
+		       "regs: setup=%08x prime=%08x stat=%08x done=%08x\n",
+		       readl(USB_ENDPTSETUPSTAT),
+		       readl(USB_ENDPTPRIME),
+		       readl(USB_ENDPTSTAT),
+		       readl(USB_ENDPTCOMPLETE));
+	i += scnprintf(buf + i, PAGE_SIZE - i,
+		       "regs:   cmd=%08x   sts=%08x intr=%08x port=%08x\n\n",
+		       readl(USB_USBCMD),
+		       readl(USB_USBSTS),
+		       readl(USB_USBINTR),
+		       readl(USB_PORTSC));
+
+
+	for (n = 0; n < 32; n++) {
+		ept = ui->ept + n;
+		if (ept->ep.maxpacket == 0)
+			continue;
+
+		i += scnprintf(buf + i, PAGE_SIZE - i,
+			       "ept%d %s cfg=%08x active=%08x next=%08x"
+			       "info=%08x\n", ept->num,
+			       (ept->flags & EPT_FLAG_IN) ? "in " : "out",
+			       ept->head->config, ept->head->active,
+			       ept->head->next, ept->head->info);
+
+		for (req = ept->req; req; req = req->next)
+			i += scnprintf(buf + i, PAGE_SIZE - i,
+				       "  req @%08x next=%08x info=%08x"
+				       "page0=%08x %c %c\n",
+				       req->item_dma, req->item->next,
+				       req->item->info, req->item->page0,
+				       req->busy ? 'B' : ' ',
+				       req->live ? 'L' : ' '
+				);
+	}
+
+	spin_unlock_irqrestore(&ui->lock, flags);
+
+	return simple_read_from_buffer(ubuf, count, ppos, buf, i);
+}
+
+static ssize_t debug_write_reset(struct file *file, const char __user *buf,
+				 size_t count, loff_t *ppos)
+{
+	struct usb_info *ui = file->private_data;
+	unsigned long flags;
+
+	spin_lock_irqsave(&ui->lock, flags);
+	ui->flags |= USB_FLAG_RESET;
+	schedule_work(&ui->work);
+	spin_unlock_irqrestore(&ui->lock, flags);
+
+	return count;
+}
+
+static ssize_t debug_write_cycle(struct file *file, const char __user *buf,
+				 size_t count, loff_t *ppos)
+{
+	usb_function_reenumerate();
+	return count;
+}
+
+static int debug_open(struct inode *inode, struct file *file)
+{
+	file->private_data = inode->i_private;
+	return 0;
+}
+
+const struct file_operations debug_stat_ops = {
+	.open = debug_open,
+	.read = debug_read_status,
+};
+
+const struct file_operations debug_reset_ops = {
+	.open = debug_open,
+	.write = debug_write_reset,
+};
+
+const struct file_operations debug_cycle_ops = {
+	.open = debug_open,
+	.write = debug_write_cycle,
+};
+
+static void usb_debugfs_init(struct usb_info *ui)
+{
+	struct dentry *dent;
+	dent = debugfs_create_dir("usb", 0);
+	if (IS_ERR(dent))
+		return;
+
+	debugfs_create_file("status", 0444, dent, ui, &debug_stat_ops);
+	debugfs_create_file("reset", 0220, dent, ui, &debug_reset_ops);
+	debugfs_create_file("cycle", 0220, dent, ui, &debug_cycle_ops);
+}
+#else
+static void usb_debugfs_init(struct usb_info *ui) {}
+#endif			/* CONFIG_DEBUG_FS */
+
 static int
 msm72k_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
 {
@@ -1483,6 +1616,8 @@ static int msm72k_probe(struct platform_device *pdev)
 
 	the_usb_info = ui;
 
+	usb_debugfs_init(ui);
+
 	usb_prepare(ui);
 
 	return 0;
Signature · 5 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 3/5 USB: msm72k_udc: Add Remote wakeup support

In reply to Pavankumar Kondeti

Process device remote wakeup set/clear feature requests and implement wakeup method of usb_gadget_ops. This patch also provides a sysfs file to initiate remote wakeup from user space. Remote wakeup can be generated by poking into /sys/devices/platform/msm_hsusb/gadget/wakeup file.

---
 drivers/usb/gadget/msm72k_udc.c  |   57 ++++++++++++++++++++++++++++++++++++++
 include/linux/usb/msm_hsusb_hw.h |    3 ++
 2 files changed, 60 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +57 -0
index 84315a2..9922d3d 100644
@@ -167,6 +167,7 @@ struct usb_info {
 	struct clk *pclk;
 
 	unsigned int ep0_dir;
+	u8 remote_wakeup;
 };
 
 static const struct usb_ep_ops msm72k_ep_ops;
@@ -585,6 +586,8 @@ static void handle_setup(struct usb_info *ui)
 				u16 temp = 0;
 
 				temp = 1 << USB_DEVICE_SELF_POWERED;
+				temp |= (ui->remote_wakeup <<
+						USB_DEVICE_REMOTE_WAKEUP);
 				memcpy(req->buf, &temp, 2);
 				break;
 			}
@@ -630,6 +633,16 @@ static void handle_setup(struct usb_info *ui)
 			*/
 			writel((ctl.wValue << 25) | (1 << 24), USB_DEVICEADDR);
 			goto ack;
+		} else if (ctl.bRequest == USB_REQ_SET_FEATURE) {
+			switch (ctl.wValue) {
+			case USB_DEVICE_REMOTE_WAKEUP:
+				ui->remote_wakeup = 1;
+				goto ack;
+			}
+		} else if ((ctl.bRequest == USB_REQ_CLEAR_FEATURE) &&
+				(ctl.wValue == USB_DEVICE_REMOTE_WAKEUP)) {
+			ui->remote_wakeup = 0;
+			goto ack;
 		}
 	}
 
@@ -1538,12 +1551,49 @@ static int msm72k_pullup(struct usb_gadget *_gadget, int is_active)
 	return 0;
 }
 
+static int msm72k_wakeup(struct usb_gadget *_gadget)
+{
+	struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
+	unsigned long flags;
+
+	if (!ui->remote_wakeup) {
+		ERROR("%s: remote wakeup not supported\n", __func__);
+		return -ENOTSUPP;
+	}
+
+	if (!ui->online) {
+		ERROR("%s: device is not configured\n", __func__);
+		return -ENODEV;
+	}
+
+	spin_lock_irqsave(&ui->lock, flags);
+	if ((readl(USB_PORTSC) & PORTSC_SUSP) == PORTSC_SUSP) {
+		INFO("%s: enabling force resume\n", __func__);
+		writel(readl(USB_PORTSC) | PORTSC_FPR, USB_PORTSC);
+	}
+	spin_unlock_irqrestore(&ui->lock, flags);
+
+	return 0;
+}
+
 static const struct usb_gadget_ops msm72k_ops = {
 	.get_frame	= msm72k_get_frame,
 	.vbus_session	= msm72k_udc_vbus_session,
 	.pullup		= msm72k_pullup,
+	.wakeup		= msm72k_wakeup,
 };
 
+static ssize_t usb_remote_wakeup(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t count)
+{
+	struct usb_info *ui = the_usb_info;
+
+	msm72k_wakeup(&ui->gadget);
+
+	return count;
+}
+static DEVICE_ATTR(wakeup, S_IWUSR, 0, usb_remote_wakeup);
+
 static int msm72k_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -1673,6 +1723,12 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
 
 	INFO("registered gadget driver '%s'\n", driver->driver.name);
 
+	/* create sysfs node for remote wakeup */
+	retval = device_create_file(&ui->gadget.dev, &dev_attr_wakeup);
+	if (retval != 0)
+		INFO("failed to create sysfs entry: (wakeup) error: (%d)\n",
+					retval);
+
 	usb_start(ui);
 
 	return 0;
@@ -1693,6 +1749,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 	if (!driver || driver != dev->driver || !driver->unbind)
 		return -EINVAL;
 
+	device_remove_file(&dev->gadget.dev, &dev_attr_wakeup);
 	driver->unbind(&dev->gadget);
 	dev->gadget.dev.driver = NULL;
 	dev->driver = NULL;
include/linux/usb/msm_hsusb_hw.h +3 -0
index ab28be6..ae13342 100644
@@ -200,6 +200,9 @@ struct ept_queue_item {
 #define PORTSC_PSPD_LS        (1 << 26)
 #define PORTSC_PSPD_HS        (2 << 26)
 #define PORTSC_PSPD_MASK      (3 << 26)
+/* suspend and remote wakeup */
+#define PORTSC_FPR             (1 << 6)
+#define PORTSC_SUSP            (1 << 7)
 
 #define PORTSC_PTS_MASK       (3 << 30)
 #define PORTSC_PTS_ULPI       (2 << 30)
Signature · 5 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 4/5 USB: msm72k_udc: Add Test Mode support

In reply to Pavankumar Kondeti

Implement the test modes mentioned in 7.1.20 section of USB 2.0 specification. High-speed capable devices must support these test modes to facilitate compliance testing.

---
 drivers/usb/gadget/msm72k_udc.c  |   49 +++++++++++++++++++++++++++++++++++++-
 include/linux/usb/msm_hsusb_hw.h |   11 ++++++++
 2 files changed, 59 insertions(+), 1 deletions(-)
drivers/usb/gadget/msm72k_udc.c +48 -1
index 9922d3d..dadb7c2 100644
@@ -168,6 +168,7 @@ struct usb_info {
 
 	unsigned int ep0_dir;
 	u8 remote_wakeup;
+	u16 test_mode;
 };
 
 static const struct usb_ep_ops msm72k_ep_ops;
@@ -509,11 +510,47 @@ static void ep0_queue_ack_complete(struct usb_ep *ep, struct usb_request *req)
 		ep0_complete(ep, req);
 }
 
+static void ep0_setup_ack_complete(struct usb_ep *ep, struct usb_request *req)
+{
+	struct msm_endpoint *ept = to_msm_endpoint(ep);
+	struct usb_info *ui = ept->ui;
+	unsigned int temp;
+
+	if (!ui->test_mode)
+		return;
+
+	switch (ui->test_mode) {
+	case J_TEST:
+		INFO("usb electrical test mode: (J)\n");
+		temp = readl(USB_PORTSC) & (~PORTSC_PTC);
+		writel(temp | PORTSC_PTC_J_STATE, USB_PORTSC);
+		break;
+
+	case K_TEST:
+		INFO("usb electrical test mode: (K)\n");
+		temp = readl(USB_PORTSC) & (~PORTSC_PTC);
+		writel(temp | PORTSC_PTC_K_STATE, USB_PORTSC);
+		break;
+
+	case SE0_NAK_TEST:
+		INFO("usb electrical test mode: (SE0-NAK)\n");
+		temp = readl(USB_PORTSC) & (~PORTSC_PTC);
+		writel(temp | PORTSC_PTC_SE0_NAK, USB_PORTSC);
+		break;
+
+	case TST_PKT_TEST:
+		INFO("usb electrical test mode: (TEST_PKT)\n");
+		temp = readl(USB_PORTSC) & (~PORTSC_PTC);
+		writel(temp | PORTSC_PTC_TST_PKT, USB_PORTSC);
+		break;
+	}
+}
+
 static void ep0_setup_ack(struct usb_info *ui)
 {
 	struct usb_request *req = ui->setup_req;
 	req->length = 0;
-	req->complete = 0;
+	req->complete = ep0_setup_ack_complete;
 	usb_ept_queue_xfer(&ui->ep0in, req);
 }
 
@@ -635,6 +672,16 @@ static void handle_setup(struct usb_info *ui)
 			goto ack;
 		} else if (ctl.bRequest == USB_REQ_SET_FEATURE) {
 			switch (ctl.wValue) {
+			case USB_DEVICE_TEST_MODE:
+				switch (ctl.wIndex) {
+				case J_TEST:
+				case K_TEST:
+				case SE0_NAK_TEST:
+				case TST_PKT_TEST:
+					ui->test_mode = ctl.wIndex;
+					goto ack;
+				}
+				goto stall;
 			case USB_DEVICE_REMOTE_WAKEUP:
 				ui->remote_wakeup = 1;
 				goto ack;
include/linux/usb/msm_hsusb_hw.h +11 -0
index ae13342..22360c2 100644
@@ -204,6 +204,17 @@ struct ept_queue_item {
 #define PORTSC_FPR             (1 << 6)
 #define PORTSC_SUSP            (1 << 7)
 
+/* test mode support */
+#define J_TEST			(0x0100)
+#define K_TEST			(0x0200)
+#define SE0_NAK_TEST		(0x0300)
+#define TST_PKT_TEST		(0x0400)
+#define PORTSC_PTC		(0xf << 16)
+#define PORTSC_PTC_J_STATE	(0x01 << 16)
+#define PORTSC_PTC_K_STATE	(0x02 << 16)
+#define PORTSC_PTC_SE0_NAK	(0x03 << 16)
+#define PORTSC_PTC_TST_PKT	(0x04 << 16)
+
 #define PORTSC_PTS_MASK       (3 << 30)
 #define PORTSC_PTS_ULPI       (2 << 30)
 #define PORTSC_PTS_SERIAL     (3 << 30)
Signature · 5 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 5/5 USB: msm72k_udc: Add charging notification support

In reply to Pavankumar Kondeti

Provide Host PC (after configured), Wall charger notifications. Typically Battery/Charger driver is subscribed to these notifications and responsible for notifying user space and drawing the current.

This patch was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.

CC Mike Lockwood <[email protected]>
CC Brian Swetland <[email protected]>
---
 drivers/usb/gadget/msm72k_udc.c |   16 ++++++++++++++++
 include/linux/usb/msm_hsusb.h   |    8 ++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +16 -0
index dadb7c2..e048b6a 100644
@@ -155,6 +155,9 @@ struct usb_info {
 	void (*phy_reset)(void);
 	void (*hw_reset)(bool en);
 
+	/* for notification when USB is connected or disconnected */
+	void (*usb_connected)(int);
+
 	struct work_struct work;
 
 	struct usb_gadget		gadget;
@@ -664,6 +667,8 @@ static void handle_setup(struct usb_info *ui)
 	if (ctl.bRequestType == (USB_DIR_OUT | USB_TYPE_STANDARD)) {
 		if (ctl.bRequest == USB_REQ_SET_CONFIGURATION) {
 			ui->online = !!ctl.wValue;
+			if (ui->online && ui->usb_connected)
+				ui->usb_connected(USB_CHG_HOST);
 		} else if (ctl.bRequest == USB_REQ_SET_ADDRESS) {
 			/* write address delayed (will take effect
 			** after the next IN txn)
@@ -1193,6 +1198,9 @@ static void usb_do_work(struct work_struct *w)
 				msm72k_pullup(&ui->gadget, 0);
 				spin_unlock_irqrestore(&ui->lock, iflags);
 
+				if (ui->usb_connected)
+					ui->usb_connected(USB_CHG_NONE);
+
 				/* terminate any transactions, etc */
 				flush_all_endpoints(ui);
 
@@ -1231,6 +1239,13 @@ static void usb_do_work(struct work_struct *w)
 				clk_enable(ui->pclk);
 				usb_reset(ui);
 
+				/* detect shorted D+/D-, indicating AC power */
+				usleep_range(10000, 12000);
+				if ((readl(USB_PORTSC) & PORTSC_LS) ==
+						PORTSC_LS)
+					if (ui->usb_connected)
+						ui->usb_connected(USB_CHG_WALL);
+
 				ui->state = USB_STATE_ONLINE;
 				usb_do_work_check_vbus(ui);
 			}
@@ -1660,6 +1675,7 @@ static int msm72k_probe(struct platform_device *pdev)
 		struct msm_hsusb_platform_data *pdata = pdev->dev.platform_data;
 		ui->phy_reset = pdata->phy_reset;
 		ui->phy_init_seq = pdata->phy_init_seq;
+		ui->usb_connected = pdata->usb_connected;
 	}
 
 	irq = platform_get_irq(pdev, 0);
include/linux/usb/msm_hsusb.h +8 -0
index 534db4e..4d75a3d 100644
@@ -19,6 +19,11 @@
 
 #include <linux/types.h>
 
+/* USB charger types */
+#define USB_CHG_NONE	0
+#define USB_CHG_HOST	1
+#define USB_CHG_WALL	2
+
 /* platform device data for msm_hsusb driver */
 
 struct msm_hsusb_platform_data {
@@ -28,6 +33,9 @@ struct msm_hsusb_platform_data {
 	/* (de)assert the reset to the usb core */
 	void (*hw_reset)(bool enable);
 
+	/* for notification when USB is connected or disconnected */
+	void (*usb_connected)(int);
+
 	/* val, reg pairs terminated by -1 */
 	int *phy_init_seq;
 };
Signature · 5 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
Quoted 6 lines · David Lanzendörfer

Hi
I tried your patchset with https://www.codeaurora.org/gitweb/quic/kernel/?p=dwalker/linux-msm.git;a=shortlog;h=refs/heads/for-next
But somehow, usb networking doesnt seem to come up? O_o
I'm sure, if you have tested it, the mistake has to be on my side.
Could I try /your/ kernel config? (With leviathan-incoming [htc-msm-2.6.32-fork for GNU/Linux] the device comes up on bootup)

Do you know which chipset(7x01/7x27/8x50) is used in your device? We have to setup the platform data and device in the respective board file. I have tested USB on 8x50 and it works fine. I will post a patch to add usb support for 8x50 today. Which gadget (android/ethernet) are you using? Also VBUS detection happens on Peripheral processor and Apps processor gets a RPC notification. But RPC infrastructure is not present in upstream msm. So you need to call msm_hsusb_vbus_state(1) after adding your platform device. I will see if I can add a debugfs file in the driver to manipulate vbus state.

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.
#12 lore raw
Quoted 1 line

Do you know which chipset(7x01/7x27/8x50) is used in your device?

Yes. Of course.
Its the htcdream, so chipset MSM7201A.

Quoted 1 line

We have to setup the platform data and device in the respective board file.

I tried that, but I've got overlooked something...

Quoted 1 line

I have tested USB on 8x50 and it works fine.

Wonderfull! ^_^

Quoted 1 line

I will post a patch to add usb support for 8x50 today.

Hmm. Ok.

Quoted 1 line

Which gadget (android/ethernet) are you using?

Ethernet (I'm developing for SHR - GNU/Linux)

Quoted 1 line

Also VBUS detection happens on Peripheral processor and Apps processor gets a RPC notification.

I'm not that fan of RPC but if its required...

Quoted 1 line

But RPC infrastructure is not present in upstream msm.

Yes. I've already tried to port it, but gave up and decided to wait, until someone does it, who understands more of it. :-)

Quoted 2 lines

So you need to call msm_hsusb_vbus_state(1) after adding your platform device. I will see if I can add a debugfs file in the driver to manipulate vbus state.

I would be very glad about cooperation.
ATM only GNUtoo, mickey and me are working on making GNU/Linux running on HTC-Dream.
http://gitorious.org/htc-msm-2-6-32/leviathan-incoming/commits/msm-gnuconform
Would be cool, if upstream - with its much cleaner codebase - would fully support htcdream. :-D

best regards
leviathan