From: pali.rohar@gmail.com (Pali Rohár)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/4] power: isp1704_charger: Fix driver to work with changes introduced in v3.5
Date: Sun, 8 Sep 2013 10:50:37 +0200 [thread overview]
Message-ID: <1378630239-10006-3-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1378630239-10006-1-git-send-email-pali.rohar@gmail.com>
* omap musb driver does not report USB_EVENT_ENUMERATED event anymore
* omap musb driver reporting USB_EVENT_VBUS when charger is connected
* read last event from phy->last_event (instead from ulpi register)
* do not call wall charger detection more times
Signed-off-by: Pali Roh?r <pali.rohar@gmail.com>
---
drivers/power/isp1704_charger.c | 91 +++++++++++++++++----------------------
1 file changed, 40 insertions(+), 51 deletions(-)
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index fc04d19..f726cb6 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -2,6 +2,7 @@
* ISP1704 USB Charger Detection driver
*
* Copyright (C) 2010 Nokia Corporation
+ * Copyright (C) 2012 - 2013 Pali Roh?r <pali.rohar@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,10 +66,6 @@ struct isp1704_charger {
unsigned present:1;
unsigned online:1;
unsigned current_max;
-
- /* temp storage variables */
- unsigned long event;
- unsigned max_power;
};
static inline int isp1704_read(struct isp1704_charger *isp, u32 reg)
@@ -231,56 +228,59 @@ static inline int isp1704_charger_detect(struct isp1704_charger *isp)
return ret;
}
+static inline int isp1704_charger_detect_dcp(struct isp1704_charger *isp)
+{
+ if (isp1704_charger_detect(isp) &&
+ isp1704_charger_type(isp) == POWER_SUPPLY_TYPE_USB_DCP)
+ return true;
+ else
+ return false;
+}
+
static void isp1704_charger_work(struct work_struct *data)
{
- int detect;
- unsigned long event;
- unsigned power;
struct isp1704_charger *isp =
container_of(data, struct isp1704_charger, work);
static DEFINE_MUTEX(lock);
- event = isp->event;
- power = isp->max_power;
-
mutex_lock(&lock);
- if (event != USB_EVENT_NONE)
- isp1704_charger_set_power(isp, 1);
-
- switch (event) {
+ switch (isp->phy->last_event) {
case USB_EVENT_VBUS:
- isp->online = true;
+ /* do not call wall charger detection more times */
+ if (!isp->present) {
+ isp->online = true;
+ isp->present = 1;
+ isp1704_charger_set_power(isp, 1);
+
+ /* detect wall charger */
+ if (isp1704_charger_detect_dcp(isp)) {
+ isp->psy.type = POWER_SUPPLY_TYPE_USB_DCP;
+ isp->current_max = 1800;
+ } else {
+ isp->psy.type = POWER_SUPPLY_TYPE_USB;
+ isp->current_max = 500;
+ }
- /* detect charger */
- detect = isp1704_charger_detect(isp);
-
- if (detect) {
- isp->present = detect;
- isp->psy.type = isp1704_charger_type(isp);
+ /* enable data pullups */
+ if (isp->phy->otg->gadget)
+ usb_gadget_connect(isp->phy->otg->gadget);
}
- switch (isp->psy.type) {
- case POWER_SUPPLY_TYPE_USB_DCP:
- isp->current_max = 1800;
- break;
- case POWER_SUPPLY_TYPE_USB_CDP:
+ if (isp->psy.type != POWER_SUPPLY_TYPE_USB_DCP) {
/*
* Only 500mA here or high speed chirp
* handshaking may break
*/
- isp->current_max = 500;
- /* FALLTHROUGH */
- case POWER_SUPPLY_TYPE_USB:
- default:
- /* enable data pullups */
- if (isp->phy->otg->gadget)
- usb_gadget_connect(isp->phy->otg->gadget);
+ if (isp->current_max > 500)
+ isp->current_max = 500;
+
+ if (isp->current_max > 100)
+ isp->psy.type = POWER_SUPPLY_TYPE_USB_CDP;
}
break;
case USB_EVENT_NONE:
isp->online = false;
- isp->current_max = 0;
isp->present = 0;
isp->current_max = 0;
isp->psy.type = POWER_SUPPLY_TYPE_USB;
@@ -298,12 +298,6 @@ static void isp1704_charger_work(struct work_struct *data)
isp1704_charger_set_power(isp, 0);
break;
- case USB_EVENT_ENUMERATED:
- if (isp->present)
- isp->current_max = 1800;
- else
- isp->current_max = power;
- break;
default:
goto out;
}
@@ -314,16 +308,11 @@ out:
}
static int isp1704_notifier_call(struct notifier_block *nb,
- unsigned long event, void *power)
+ unsigned long val, void *v)
{
struct isp1704_charger *isp =
container_of(nb, struct isp1704_charger, nb);
- isp->event = event;
-
- if (power)
- isp->max_power = *((unsigned *)power);
-
schedule_work(&isp->work);
return NOTIFY_OK;
@@ -462,13 +451,13 @@ static int isp1704_charger_probe(struct platform_device *pdev)
if (isp->phy->otg->gadget)
usb_gadget_disconnect(isp->phy->otg->gadget);
+ if (isp->phy->last_event == USB_EVENT_NONE)
+ isp1704_charger_set_power(isp, 0);
+
/* Detect charger if VBUS is valid (the cable was already plugged). */
- ret = isp1704_read(isp, ULPI_USB_INT_STS);
- isp1704_charger_set_power(isp, 0);
- if ((ret & ULPI_INT_VBUS_VALID) && !isp->phy->otg->default_a) {
- isp->event = USB_EVENT_VBUS;
+ if (isp->phy->last_event == USB_EVENT_VBUS &&
+ !isp->phy->otg->default_a)
schedule_work(&isp->work);
- }
return 0;
fail2:
--
1.7.10.4
next prev parent reply other threads:[~2013-09-08 8:50 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-08 8:50 [PATCH 0/4] Add support for charging battery in Nokia RX-51 Pali Rohár
2013-09-08 8:50 ` [PATCH 1/4] usb: musb: Call atomic_notifier_call_chain when status is changed Pali Rohár
2013-09-17 15:48 ` Felipe Balbi
2013-09-17 15:49 ` Felipe Balbi
2013-09-17 16:05 ` Pali Rohár
2013-09-17 16:08 ` Felipe Balbi
2013-09-17 19:28 ` Pali Rohár
2013-09-18 1:49 ` Felipe Balbi
2013-09-18 8:20 ` Pali Rohár
2013-09-18 9:04 ` Javier Martinez Canillas
2013-09-18 13:30 ` Pavel Machek
2013-09-18 13:57 ` Javier Martinez Canillas
2013-09-18 14:22 ` Pavel Machek
2013-09-18 14:35 ` Pavel Machek
2013-09-18 16:25 ` Felipe Balbi
2013-09-18 14:53 ` Javier Martinez Canillas
2013-09-18 15:56 ` Pali Rohár
2013-09-18 16:36 ` Felipe Balbi
2013-09-18 16:43 ` Pali Rohár
2013-09-18 16:48 ` Felipe Balbi
2013-09-18 17:03 ` [PATCH usb 1/2] usb: musb: Add missing ATOMIC_INIT_NOTIFIER_HEAD Pali Rohár
2013-09-25 8:17 ` Pali Rohár
2013-09-25 20:33 ` Felipe Balbi
2013-09-26 0:00 ` Pavel Machek
2013-10-01 14:22 ` Felipe Balbi
2013-09-18 17:03 ` [PATCH usb 2/2] usb: musb: Call atomic_notifier_call_chain when status is changed Pali Rohár
2013-09-08 8:50 ` Pali Rohár [this message]
2013-10-22 21:03 ` [PATCH 2/4] power: isp1704_charger: Fix driver to work with changes introduced in v3.5 Anton Vorontsov
2013-09-08 8:50 ` [PATCH 3/4] power: isp1704_charger: Add callback function set_current Pali Rohár
2013-09-08 8:50 ` [PATCH 4/4] RX-51: Add platform function and data for bq24150a charger Pali Rohár
2013-09-09 13:39 ` Sebastian Reichel
2013-09-20 19:22 ` Pali Rohár
2013-09-23 18:03 ` Tony Lindgren
2013-09-23 19:16 ` Pali Rohár
2013-09-23 20:00 ` Sebastian Reichel
2013-09-23 20:06 ` Pali Rohár
2013-09-23 20:47 ` Sebastian Reichel
2013-09-23 23:11 ` Tony Lindgren
2013-09-24 0:05 ` Pavel Machek
2013-09-24 17:05 ` Pali Rohár
2013-09-24 20:50 ` Sebastian Reichel
2013-09-14 9:38 ` [PATCH 0/4] Add support for charging battery in Nokia RX-51 Pali Rohár
2013-09-21 13:42 ` Pali Rohár
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=1378630239-10006-3-git-send-email-pali.rohar@gmail.com \
--to=pali.rohar@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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).