All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <felipe.balbi@nokia.com>
To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>,
	Grazvydas Ignotas <notasas@gmail.com>,
	Madhusudhan Chikkature <madhu.cr@ti.com>,
	linux-omap@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>,
	David Brownell <dbrownell@users.sourceforge.net>,
	Felipe Balbi <felipe.balbi@nokia.com>
Subject: [RFC/PATCH 5/5] usb: musb: musb supports otg notifier
Date: Fri, 11 Dec 2009 13:31:26 +0200	[thread overview]
Message-ID: <1260531086-23857-6-git-send-email-felipe.balbi@nokia.com> (raw)
In-Reply-To: <6ed0b2680912101251jeec28e6i216dfc51caab13aa@mail.gmail.com>

we use the notifier to kick the charger detection.
Needed on RX-51 board. Later on we will notify
also the bMaxPower field from usb_configuration.

Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/usb/musb/musb_core.c |   72 ++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/musb/musb_core.h |    5 +++
 2 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 55e185a..c7c60df 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -98,6 +98,7 @@
 #include <linux/kobject.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/notifier.h>
 
 #ifdef	CONFIG_ARM
 #include <mach/hardware.h>
@@ -144,6 +145,74 @@ MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
 
 /*-------------------------------------------------------------------------*/
 
+#include "isp1704.h"
+
+static int musb_detect_charger(struct musb *musb)
+{
+	unsigned long		timeout;
+	u8			vdat = 0;
+	u8			power;
+	u8			r;
+
+	/* first we disable data pullups */
+	power = musb_readb(musb->mregs, MUSB_POWER);
+	power &= ~MUSB_POWER_SOFTCONN;
+	musb_writeb(musb->mregs, MUSB_POWER, power);
+
+	/* now we set SW control bit in PWR_CTRL register */
+	r = musb_ulpi_readb(musb->mregs, ISP1704_PWR_CTRL);
+	r |= ISP1704_PWR_CTRL_SWCTRL;
+	musb_ulpi_writeb(musb->mregs, ISP1704_PWR_CTRL, r);
+
+	/* and finally enable manual charger detection */
+	r |= ISP1704_PWR_CTRL_DPVSRC_EN;
+	musb_ulpi_writeb(musb->mregs, ISP1704_PWR_CTRL, r);
+	msleep(10);
+
+	timeout = jiffies + msecs_to_jiffies(300);
+	while (!time_after(jiffies, timeout)) {
+		/* Check if there is a charger */
+		vdat = !!(musb_ulpi_readb(musb->mregs, ISP1704_PWR_CTRL)
+				& ISP1704_PWR_CTRL_VDAT_DET);
+		if (vdat)
+			break;
+	}
+
+	/* clear DPVSRC_EN, otherwise usb communication doesn't work */
+	r &= ~ISP1704_PWR_CTRL_DPVSRC_EN;
+	musb_ulpi_writeb(musb->mregs, ISP1704_PWR_CTRL, r);
+
+	if (vdat)
+		blocking_notifier_call_chain(&musb->xceiv->notifier,
+				USB_EVENT_CHARGER, &musb->g);
+
+	/*
+	 * re-enable data pullups, we might have been connected
+	 * to a host/hub charger
+	 */
+	power |= MUSB_POWER_SOFTCONN;
+	musb_writeb(musb->mregs, MUSB_POWER, power);
+
+	return vdat;
+}
+
+static int musb_notifier_call(struct notifier_block *nb, unsigned long event,
+		void *_gadget)
+{
+	struct usb_gadget	*g = _gadget;
+	struct musb		*musb = container_of(g, struct musb, g);
+
+	switch (event) {
+	case USB_EVENT_VBUS:
+		musb->is_charger = musb_detect_charger(musb);
+		break;
+	default:
+		return NOTIFY_DONE;
+	}
+
+	return NOTIFY_OK;
+}
+
 static inline struct musb *dev_to_musb(struct device *dev)
 {
 #ifdef CONFIG_USB_MUSB_HDRC_HCD
@@ -1961,6 +2030,9 @@ bad_config:
 		goto fail2;
 	}
 
+	musb->nb.notifier_call = musb_notifier_call;
+	otg_register_notifier(musb->xceiv, &musb->nb);
+
 #ifndef CONFIG_MUSB_PIO_ONLY
 	if (use_dma && dev->dma_mask) {
 		struct dma_controller	*c;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 644fcd8..3de6eb8 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -322,6 +322,9 @@ struct musb {
 	struct clk		*clock;
 	irqreturn_t		(*isr)(int, void *);
 	struct work_struct	irq_work;
+
+	struct notifier_block	nb;
+
 #define MUSB_HWVERS_MAJOR(x)	((x >> 10) & 0x1f)
 #define MUSB_HWVERS_MINOR(x)	(x & 0x3ff)
 #define MUSB_HWVERS_RC		0x8000
@@ -432,6 +435,8 @@ struct musb {
 	unsigned		is_self_powered:1;
 	unsigned		is_bus_powered:1;
 
+	unsigned		is_charger:1;
+
 	unsigned		set_address:1;
 	unsigned		test_mode:1;
 	unsigned		softconnect:1;
-- 
1.6.6.rc0


  parent reply	other threads:[~2009-12-11 11:33 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 14:44 [PATCH] power_supply: Add driver for TWL4030/TPS65950 BCI charger Grazvydas Ignotas
2009-11-27 14:44 ` Grazvydas Ignotas
2009-11-27 14:54 ` Anton Vorontsov
2009-11-27 15:47   ` Grazvydas Ignotas
2009-11-27 16:23     ` Mark Brown
2009-11-30 18:45 ` Madhusudhan
2009-11-30 18:45   ` Madhusudhan
2009-11-30 18:58   ` Anton Vorontsov
2009-12-02 20:38     ` Grazvydas Ignotas
2009-12-02 20:38       ` Grazvydas Ignotas
2009-12-02 21:27       ` Anton Vorontsov
2009-12-02 21:27         ` Anton Vorontsov
2009-12-02 21:32         ` Grazvydas Ignotas
2009-11-30 21:33   ` Grazvydas Ignotas
2009-12-02 16:59     ` Madhusudhan
2009-12-02 16:59       ` Madhusudhan
2009-12-02 17:33 ` Felipe Balbi
2009-12-02 20:34   ` Grazvydas Ignotas
2009-12-02 20:49     ` Felipe Balbi
2009-12-02 20:49       ` Felipe Balbi
2009-12-02 21:29       ` Grazvydas Ignotas
2009-12-02 21:29         ` Grazvydas Ignotas
2009-12-02 21:54         ` Anton Vorontsov
2009-12-02 22:31           ` Felipe Balbi
2009-12-02 22:59             ` Anton Vorontsov
2009-12-03  8:39               ` Felipe Balbi
2009-12-03 10:55                 ` Grazvydas Ignotas
2009-12-03 11:03                   ` Felipe Balbi
2009-12-10 14:09                     ` Grazvydas Ignotas
2009-12-10 14:18                       ` Anton Vorontsov
2009-12-10 14:21                         ` Felipe Balbi
2009-12-10 14:44                           ` Anton Vorontsov
2009-12-10 16:51                             ` Felipe Balbi
2009-12-10 20:51                               ` Grazvydas Ignotas
2009-12-11 11:31                                 ` [RFC/PATCH 0/5] usb transceiver notifier Felipe Balbi
2009-12-11 11:31                                   ` Felipe Balbi
2009-12-11 11:31                                 ` [RFC/PATCH 1/5] usb: otg: add notifier support Felipe Balbi
2009-12-11 11:55                                   ` Mark Brown
2009-12-11 11:55                                     ` Mark Brown
2009-12-11 11:58                                     ` Felipe Balbi
2010-01-26 11:16                                   ` David Brownell
2010-01-26 13:11                                     ` Mark Brown
2010-01-26 13:35                                       ` David Brownell
2010-01-26 14:14                                         ` Felipe Balbi
2010-01-26 14:24                                           ` Oliver Neukum
2010-01-26 14:30                                             ` Felipe Balbi
2010-01-26 14:30                                               ` Felipe Balbi
2010-01-26 15:16                                               ` David Brownell
2010-01-26 15:21                                           ` David Brownell
2010-01-26 18:50                                             ` Felipe Balbi
2010-01-26 14:21                                         ` Mark Brown
2010-01-26 14:21                                           ` Mark Brown
2010-01-26 15:44                                           ` David Brownell
2010-01-26 16:13                                             ` Mark Brown
2010-01-26 14:10                                     ` Felipe Balbi
2010-01-26 14:19                                       ` Felipe Balbi
2010-01-26 15:33                                         ` David Brownell
2010-01-26 15:33                                           ` David Brownell
2010-01-26 15:07                                       ` David Brownell
2010-01-26 15:07                                         ` David Brownell
2010-01-26 19:09                                         ` Felipe Balbi
2010-01-26 19:15                                           ` Felipe Balbi
2010-01-26 19:15                                             ` Felipe Balbi
2009-12-11 11:31                                 ` [RFC/PATCH 2/5] usb: otg: twl4030: add support for notifier Felipe Balbi
2009-12-11 17:22                                   ` sai pavan
2009-12-11 17:22                                     ` sai pavan
2009-12-11 20:40                                     ` Felipe Balbi
2009-12-11 20:40                                       ` Felipe Balbi
2009-12-12 18:34                                       ` Mark Brown
2009-12-14 10:30                                         ` [RFC/PATCH 0/4] twl4030 threaded_irq support Felipe Balbi
2010-01-26  7:06                                           ` David Brownell
2010-01-26  7:06                                             ` David Brownell
2010-01-26  7:36                                             ` David Brownell
2010-01-26  7:36                                               ` David Brownell
2010-01-26 10:07                                             ` Mark Brown
2010-01-26 11:02                                             ` Felipe Balbi
2010-01-26 12:18                                               ` David Brownell
2010-01-26 12:18                                                 ` David Brownell
2009-12-14 10:30                                         ` [RFC/PATCH 1/4] input: keyboard: twl4030: move to request_threaded_irq Felipe Balbi
2009-12-14 10:30                                           ` Felipe Balbi
2009-12-14 10:30                                         ` [RFC/PATCH 2/4] input: misc: " Felipe Balbi
2009-12-14 10:30                                           ` Felipe Balbi
2009-12-14 11:31                                           ` Shilimkar, Santosh
2009-12-14 11:40                                             ` Felipe Balbi
2009-12-14 13:16                                               ` Shilimkar, Santosh
2009-12-14 10:30                                         ` [RFC/PATCH 3/4] rtc: " Felipe Balbi
2009-12-14 10:30                                         ` [RFC/PATCH 4/4] usb: otg: " Felipe Balbi
2009-12-14 10:30                                           ` Felipe Balbi
2009-12-11 11:31                                 ` [RFC/PATCH 3/5] usb: musb: add support for ulpi block Felipe Balbi
2009-12-11 11:31                                   ` Felipe Balbi
2009-12-11 11:31                                 ` [RFC/PATCH 4/5] usb: musb: isp1704: add registers from isp1704 Felipe Balbi
2009-12-11 11:31                                   ` Felipe Balbi
2009-12-11 12:35                                   ` Krogerus Heikki (EXT-Teleca/Helsinki)
2009-12-11 12:35                                     ` Krogerus Heikki (EXT-Teleca/Helsinki)
2009-12-11 12:57                                     ` Felipe Balbi
2009-12-11 12:57                                       ` Felipe Balbi
2009-12-11 11:31                                 ` Felipe Balbi [this message]
2009-12-11 11:40                                   ` [RFC/PATCH 5/5] usb: musb: musb supports otg notifier Felipe Balbi
2009-12-11 11:40                                     ` Felipe Balbi
2009-12-30 19:07                             ` [PATCH] power_supply: Add driver for TWL4030/TPS65950 BCI charger Madhusudhan
2009-12-30 19:07                               ` Madhusudhan
2009-12-10 14:19                       ` Felipe Balbi

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=1260531086-23857-6-git-send-email-felipe.balbi@nokia.com \
    --to=felipe.balbi@nokia.com \
    --cc=avorontsov@ru.mvista.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=madhu.cr@ti.com \
    --cc=notasas@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.