From: Pavankumar Kondeti <pkondeti@codeaurora.org>
To: greg@kroah.com
Cc: linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org,
Pavankumar Kondeti <pkondeti@codeaurora.org>,
Mike Lockwood <lockwood@android.com>,
Brian Swetland <swetland@google.com>
Subject: [PATCH v2] USB: msm72k_udc: Add debugfs support
Date: Tue, 9 Nov 2010 16:48:11 +0530 [thread overview]
Message-ID: <1289301494-26150-3-git-send-email-pkondeti@codeaurora.org> (raw)
In-Reply-To: <1289301494-26150-1-git-send-email-pkondeti@codeaurora.org>
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 <lockwood@android.com>
CC: Brian Swetland <swetland@google.com>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
---
drivers/usb/gadget/msm72k_udc.c | 164 +++++++++++++++++++++++++++++++++++++++
1 files changed, 164 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/gadget/msm72k_udc.c b/drivers/usb/gadget/msm72k_udc.c
index 3fa4192..6ec1a32 100644
--- a/drivers/usb/gadget/msm72k_udc.c
+++ b/drivers/usb/gadget/msm72k_udc.c
@@ -27,8 +27,10 @@
#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>
+#include <linux/uaccess.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
@@ -138,6 +140,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: privated data of this driver.
@@ -155,6 +158,7 @@ static void usb_do_work(struct work_struct *w);
* USB_FLAG_START: set upon gadget driver registration.
* USB_FLAG_VBUS_ONLINE: set upon VBUS presence.
* USB_FLAG_VBUS_OFFLINE: set upon VBUS absence.
+ * USB_FLAG_RESET: set upon reset request from debug file.
* @online: indicates USB configured state. set upon set_config request.
* @running: indicates pull-up state.
* @pool: DMA pool for allocating endpoint queue items (dTD).
@@ -1216,6 +1220,12 @@ static void usb_do_work(struct work_struct *w)
usb_do_work_check_vbus(ui);
break;
}
+ if (flags & USB_FLAG_RESET) {
+ dev_info(&ui->pdev->dev, "ONLINE -> RESET\n");
+ usb_reset(ui);
+ dev_info(&ui->pdev->dev, "RESET -> ONLINE\n");
+ break;
+ }
break;
case USB_STATE_OFFLINE:
/* If we were signaled to go online and vbus is still
@@ -1269,6 +1279,158 @@ 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 ssize_t debug_write_vbus(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ char kbuf[8];
+ size_t len;
+
+ len = min(count, sizeof(kbuf) - 1);
+ if (copy_from_user(kbuf, buf, len))
+ return -EFAULT;
+ kbuf[len] = '\0';
+
+ if (strncmp(kbuf, "on", 2) == 0)
+ msm_hsusb_set_vbus_state(1);
+ else if (strncmp(kbuf, "off", 3) == 0)
+ msm_hsusb_set_vbus_state(0);
+ else
+ return -EINVAL;
+
+ 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,
+};
+
+const struct file_operations debug_vbus_ops = {
+ .open = debug_open,
+ .write = debug_write_vbus,
+};
+
+static void usb_debugfs_init(struct usb_info *ui)
+{
+ struct dentry *dent;
+ dent = debugfs_create_dir(dev_name(&ui->pdev->dev), 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);
+ debugfs_create_file("vbus", 0220, dent, ui, &debug_vbus_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)
{
@@ -1576,6 +1738,8 @@ static int msm72k_probe(struct platform_device *pdev)
the_usb_info = ui;
+ usb_debugfs_init(ui);
+
usb_prepare(ui);
return 0;
--
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.
next prev parent reply other threads:[~2010-11-09 11:18 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-09 11:18 [PATCH v2] Add MSM USB Device Controller support Pavankumar Kondeti
2010-11-09 11:18 ` [PATCH v2] USB: Add MSM USB Device Controller driver Pavankumar Kondeti
2010-11-09 11:40 ` Matthieu CASTET
2010-11-09 12:16 ` Pavan Kondeti
2010-11-09 13:36 ` Matthieu CASTET
2010-11-10 2:12 ` Pavan Kondeti
2010-11-10 2:54 ` David Brownell
2010-11-10 6:22 ` Brian Swetland
2010-11-19 17:16 ` Matthieu CASTET
2010-11-27 14:00 ` Pavan Kondeti
2010-11-28 6:30 ` David Brownell
2010-11-28 12:09 ` Pavan Kondeti
2010-12-07 12:44 ` Pavan Kondeti
2010-11-09 13:25 ` Heikki Krogerus
2010-11-09 13:52 ` Matthieu CASTET
2010-11-09 15:36 ` Igor Grinberg
2010-11-10 2:19 ` Pavan Kondeti
2010-11-10 6:47 ` Igor Grinberg
2010-11-11 2:10 ` Pavan Kondeti
2010-11-19 5:50 ` Pavan Kondeti
2010-11-21 8:09 ` Igor Grinberg
2010-11-10 2:17 ` Pavan Kondeti
2010-11-09 11:18 ` Pavankumar Kondeti [this message]
2010-11-09 11:18 ` [PATCH v2] USB: msm72k_udc: Add Remote wakeup support Pavankumar Kondeti
2010-11-09 11:18 ` [PATCH v2] USB: msm72k_udc: Add Test Mode support Pavankumar Kondeti
2010-11-09 11:18 ` [PATCH] USB: msm72k_udc: Add charging notification support Pavankumar Kondeti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1289301494-26150-3-git-send-email-pkondeti@codeaurora.org \
--to=pkondeti@codeaurora.org \
--cc=greg@kroah.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lockwood@android.com \
--cc=swetland@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).