[PATCH 5/5] USB: msm72k_udc: Add charging notification support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <lockwood@xxxxxxxxxxx>
CC: Brian Swetland <swetland@xxxxxxxxxx>
Signed-off-by: Pavankumar Kondeti <pkondeti@xxxxxxxxxxxxxx>
---
 drivers/usb/gadget/msm72k_udc.c |   16 ++++++++++++++++
 include/linux/usb/msm_hsusb.h   |    8 ++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/msm72k_udc.c b/drivers/usb/gadget/msm72k_udc.c
index dadb7c2..e048b6a 100644
--- a/drivers/usb/gadget/msm72k_udc.c
+++ b/drivers/usb/gadget/msm72k_udc.c
@@ -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);
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 534db4e..4d75a3d 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -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;
 };
-- 
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.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux