public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <felipebalbi@users.sourceforge.net>
To: linux-omap-open-source@linux.omap.com
Subject: [PATCH] musb_hdrc: Add SRP Interface and control it through sysfs
Date: Tue, 29 May 2007 15:02:34 +0300	[thread overview]
Message-ID: <11804401722783-git-send-email-felipebalbi@users.sourceforge.net> (raw)
In-Reply-To: <11804401662563-git-send-email-felipebalbi@users.sourceforge.net>

From: Felipe Balbi <felipe.lima@indt.org.br>

	This patch adds a method to start SRP and a userspace
	interface to control it through sysfs.

Signed-off-by: Felipe Balbi <felipe.lima@indt.org.br>
---

Index: linux-omap-2.6/drivers/usb/musb/musb_gadget.c
===================================================================
--- linux-omap-2.6.orig/drivers/usb/musb/musb_gadget.c	2007-05-28 01:40:16.000000000 +0300
+++ linux-omap-2.6/drivers/usb/musb/musb_gadget.c	2007-05-28 13:18:47.000000000 +0300
@@ -2056,3 +2056,29 @@
 	(void) musb_gadget_vbus_draw(&musb->g,
 			is_otg_enabled(musb) ? 8 : 100);
 }
+
+/* called when we want to send a Session Request. Caller must hold the lock */
+void musb_g_srp(struct musb *musb)
+{
+	void __iomem	*base = musb->pRegs;
+	u8	devctl = musb_readb(base, MGC_O_HDRC_DEVCTL);
+
+	DBG(3, "Starting SRP\n");
+
+	musb_writeb(base, MGC_O_HDRC_DEVCTL, devctl | MGC_M_DEVCTL_BDEVICE);
+
+	/* In order to start SRP we need to ensure that Vbus is below the
+	 * Session Valid Threshold.
+	 * On MUSB this means that  MGC_M_DEVCTL_VBUS and MGC_S_DEVCTL_VBUS
+	 * are set to 00.
+	 */
+	devctl &= MGC_M_DEVCTL_VBUS & MGC_S_DEVCTL_VBUS;
+
+	if (!devctl) {
+		devctl = musb_readb(base, MGC_O_HDRC_DEVCTL);
+		devctl |= MGC_M_DEVCTL_SESSION | MGC_M_DEVCTL_BDEVICE;
+
+		musb_writeb(base, MGC_O_HDRC_DEVCTL, devctl);
+	} else
+		DBG(7, "Cannot Start SRP: devctl = %02x\n" , devctl);
+}
Index: linux-omap-2.6/drivers/usb/musb/musbdefs.h
===================================================================
--- linux-omap-2.6.orig/drivers/usb/musb/musbdefs.h	2007-05-28 01:40:16.000000000 +0300
+++ linux-omap-2.6/drivers/usb/musb/musbdefs.h	2007-05-28 13:18:47.000000000 +0300
@@ -124,6 +124,7 @@
 extern void musb_g_reset(struct musb *);
 extern void musb_g_suspend(struct musb *);
 extern void musb_g_resume(struct musb *);
+extern void musb_g_srp(struct musb *);
 extern void musb_g_disconnect(struct musb *);
 
 #else
@@ -134,6 +135,7 @@
 static inline void musb_g_reset(struct musb *m) {}
 static inline void musb_g_suspend(struct musb *m) {}
 static inline void musb_g_resume(struct musb *m) {}
+static inline void musb_g_srp(struct musb *m) {}
 static inline void musb_g_disconnect(struct musb *m) {}
 
 #endif
Index: linux-omap-2.6/drivers/usb/musb/plat_uds.c
===================================================================
--- linux-omap-2.6.orig/drivers/usb/musb/plat_uds.c	2007-05-28 01:40:16.000000000 +0300
+++ linux-omap-2.6/drivers/usb/musb/plat_uds.c	2007-05-28 13:18:47.000000000 +0300
@@ -1579,6 +1579,32 @@
 }
 static DEVICE_ATTR(cable, S_IRUGO, musb_cable_show, NULL);
 
+#ifdef CONFIG_USB_MUSB_OTG
+static ssize_t
+musb_srp_store(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t n)
+{
+	struct musb	*musb=dev_to_musb(dev);
+	unsigned long	flags;
+	unsigned short	srp;
+
+	if (sscanf(buf, "%hu", &srp) != 1
+			|| (srp != 1)) {
+		printk (KERN_ERR "SRP: Value must be 1\n");
+		return -EINVAL;
+	}
+
+	spin_lock_irqsave(&musb->Lock, flags);
+	if (srp == 1){
+		musb_g_srp(musb);
+	}
+	spin_unlock_irqrestore(&musb->Lock, flags);
+
+	return n;
+}
+static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
+#endif /* CONFIG_USB_MUSB_OTG */
+
 #endif
 
 /* Only used to provide cable state change events */
@@ -1648,6 +1674,9 @@
 #ifdef CONFIG_SYSFS
 	device_remove_file(musb->controller, &dev_attr_mode);
 	device_remove_file(musb->controller, &dev_attr_cable);
+#ifdef CONFIG_USB_MUSB_OTG
+	device_remove_file(musb->controller, &dev_attr_srp);
+#endif
 #endif
 
 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
@@ -1876,6 +1905,9 @@
 #ifdef CONFIG_SYSFS
 	status = device_create_file(dev, &dev_attr_mode);
 	status = device_create_file(dev, &dev_attr_cable);
+#ifdef CONFIG_USB_MUSB_OTG
+	status = device_create_file(dev, &dev_attr_srp);
+#endif /* CONFIG_USB_MUSB_OTG */
 	status = 0;
 #endif
 

  reply	other threads:[~2007-05-29 12:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-29 12:02 RFC PATCH Felipe Balbi
2007-05-29 12:02 ` [PATCH] USB: Disable file_storage USB_CONFIG_ATT_WAKEUP Felipe Balbi
2007-05-29 12:02   ` [PATCH] musb_hdrc: Implement workaround for tusb3.0 wbus bug rev2 Felipe Balbi
2007-05-29 12:02     ` Felipe Balbi [this message]
2007-05-29 12:02       ` [PATCH] Add Sysfs Interface to Control Vbus states Felipe Balbi
2007-05-29 12:02         ` [PATCH] Add more Test Modes Felipe Balbi
2007-05-29 12:02           ` [PATCH] musb_hdrc: Make HNP work Felipe Balbi
2007-05-29 12:02             ` [PATCH] USB: Fix OTG HNP for hub.c Felipe Balbi
2007-05-29 12:02               ` [PATCH] HSET tool for the MUSB Controler Felipe Balbi
2007-05-29 12:02                 ` [PATCH] Leave GPIO[7:6] pullups enabled Felipe Balbi
     [not found]                   ` <11804401803413-git-send-email-felipebalbi@users.sourceforge.net>
2007-05-29 12:02                     ` [PATCH] Make SRP passes in all Electrical Tests Felipe Balbi
2007-05-29 14:39                       ` Dirk Behme
2007-06-05 11:02                   ` [PATCH] Leave GPIO[7:6] pullups enabled Tony Lindgren
2007-05-29 19:21               ` [PATCH] USB: Fix OTG HNP for hub.c David Brownell
2007-05-29 19:24                 ` Felipe Balbi
2007-05-29 20:34                   ` Tony Lindgren
2007-05-29 21:11                     ` David Brownell
2007-05-29 21:26                       ` Tony Lindgren
2007-05-29 17:16           ` [PATCH] Add more Test Modes David Brownell
2007-05-29 17:07       ` [PATCH] musb_hdrc: Add SRP Interface and control it through sysfs David Brownell

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=11804401722783-git-send-email-felipebalbi@users.sourceforge.net \
    --to=felipebalbi@users.sourceforge.net \
    --cc=linux-omap-open-source@linux.omap.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