From patchwork Thu Sep 27 20:08:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11793 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3A5DF24140 for ; Thu, 27 Sep 2012 20:09:47 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id E6332A18B42 for ; Thu, 27 Sep 2012 20:09:46 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5234801iej.11 for ; Thu, 27 Sep 2012 13:09:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XIxTvMl8Owf9NNr3Lsw96a7/14bVaHDKqxKzpPmMvkk=; b=jS8BzCmisWQby9Eohl5XGJps5iPE93qJGlE1FSYG6LgVGA00bHQ318a3PmKZKhor04 2WJFGtFS0LvC+uBmJzBZyAKcgh6PzTmtxvwGIoB7ZxTv+9l3m6funSGZlItuGNSFKj9u J47Ic4mjyzL0pFKc8gLDTZDSD7n/UUFJgYIjIAWGicJKeCDclet30ny7h84SgAYxKyR6 GJu43uNNEBotLAMVmYugGRa4YXGUB1GLuQ+x0rzULpZRU+GRNIrEEk3b4uyd0G9YdXpN EKrc3UU4O0cWG6ILNSYhf0Id01CtpVSgLjAw+1y5iS3I+GxzWMB81OBXOBvbD5QJ4Cd3 t9FA== Received: by 10.42.84.69 with SMTP id k5mr3974877icl.5.1348776586716; Thu, 27 Sep 2012 13:09:46 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp436306igc; Thu, 27 Sep 2012 13:09:46 -0700 (PDT) Received: by 10.68.233.198 with SMTP id ty6mr14310379pbc.107.1348776585989; Thu, 27 Sep 2012 13:09:45 -0700 (PDT) Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by mx.google.com with ESMTPS id vn9si8390651pbc.17.2012.09.27.13.09.45 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:45 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) client-ip=209.85.220.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) smtp.mail=mathieu.poirier@linaro.org Received: by mail-pa0-f50.google.com with SMTP id hz11so1847989pad.37 for ; Thu, 27 Sep 2012 13:09:45 -0700 (PDT) Received: by 10.66.74.74 with SMTP id r10mr12151370pav.57.1348776585752; Thu, 27 Sep 2012 13:09:45 -0700 (PDT) Received: from localhost.localdomain (S0106002369de4dac.cg.shawcable.net. [70.73.24.112]) by mx.google.com with ESMTPS id sa2sm1587890pbc.4.2012.09.27.13.09.44 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:45 -0700 (PDT) From: mathieu.poirier@linaro.org To: patches@linaro.org Subject: [PATCH 20/57] power: Adds support for legacy USB chargers Date: Thu, 27 Sep 2012 14:08:37 -0600 Message-Id: <1348776554-10019-21-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> References: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> X-Gm-Message-State: ALoCoQlz8JPwMqDanVGGny9PRUG7rlvf4KiASN8U1YAekifIWBOvYB4T35UfVHqEpsFUdsnSEmyZ From: Marcus Cooper A Legacy USB charger should be handled directly by the charger driver. Signed-off-by: Marcus Cooper Signed-off-by: Mathieu Poirier Reviewed-by: Karl KOMIEROWSKI Reviewed-by: Jonas ABERG --- drivers/power/ab8500_charger.c | 66 ++++++++++++++++++++++++++++++++++----- 1 files changed, 57 insertions(+), 9 deletions(-) diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index 4155feb..7cd4165 100644 --- a/drivers/power/ab8500_charger.c +++ b/drivers/power/ab8500_charger.c @@ -85,6 +85,9 @@ /* Step up/down delay in us */ #define STEP_UDELAY 1000 +/* Wait for enumeration before charging in ms */ +#define WAIT_FOR_USB_ENUMERATION (5 * 1000) + #define CHARGER_STATUS_POLL 10 /* in ms */ /* UsbLineStatus register - usb types */ @@ -198,6 +201,7 @@ struct ab8500_charger_usb_state { * charger is enabled * @vbat Battery voltage * @old_vbat Previously measured battery voltage + * @usb_device_is_unrecognised USB device is unrecognised by the hardware * @autopower Indicate if we should have automatic pwron after pwrloss * @parent: Pointer to the struct ab8500 * @gpadc: Pointer to the struct gpadc @@ -216,6 +220,7 @@ struct ab8500_charger_usb_state { * @check_usbchgnotok_work: Work for checking USB charger not ok status * @kick_wd_work: Work for kicking the charger watchdog in case * of ABB rev 1.* due to the watchog logic bug + * @attach_work: Work for checking the usb enumeration * @ac_charger_attached_work: Work for checking if AC charger is still * connected * @usb_charger_attached_work: Work for checking if USB charger is still @@ -239,6 +244,7 @@ struct ab8500_charger { bool vddadc_en_usb; int vbat; int old_vbat; + bool usb_device_is_unrecognised; bool autopower; struct ab8500 *parent; struct ab8500_gpadc *gpadc; @@ -256,6 +262,7 @@ struct ab8500_charger { struct delayed_work check_hw_failure_work; struct delayed_work check_usbchgnotok_work; struct delayed_work kick_wd_work; + struct delayed_work attach_work; struct delayed_work ac_charger_attached_work; struct delayed_work usb_charger_attached_work; struct work_struct ac_work; @@ -588,6 +595,8 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di, { int ret = 0; + di->usb_device_is_unrecognised = false; + switch (link_status) { case USB_STAT_STD_HOST_NC: case USB_STAT_STD_HOST_C_NS: @@ -633,9 +642,15 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di, dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, di->max_usb_in_curr); break; + case USB_STAT_NOT_CONFIGURED: + if (di->vbus_detected) { + di->usb_device_is_unrecognised = true; + dev_dbg(di->dev, "USB Type - Legacy charger.\n"); + di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5; + break; + } case USB_STAT_HM_IDGND: case USB_STAT_NOT_VALID_LINK: - case USB_STAT_NOT_CONFIGURED: dev_err(di->dev, "USB Type - Charging not allowed\n"); di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05; ret = -ENXIO; @@ -1899,6 +1914,30 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work) } /** + * ab8500_charger_usb_link_attach_work() - delayd work to detect USB type + * @work: pointer to the work_struct structure + * + * Detect the type of USB plugged + */ +static void ab8500_charger_usb_link_attach_work(struct work_struct *work) +{ + int ret; + + struct ab8500_charger *di = container_of(work, + struct ab8500_charger, attach_work.work); + + /* Update maximum input current if USB enumeration is not detected */ + if (!di->usb.charger_online) { + ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr); + if (ret) + return; + } + + ab8500_charger_set_usb_connected(di, true); + ab8500_power_supply_changed(di, &di->usb_chg.psy); +} + +/** * ab8500_charger_usb_link_status_work() - work to detect USB type * @work: pointer to the work_struct structure * @@ -1928,14 +1967,20 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work) di->vbus_detected = 1; ret = ab8500_charger_read_usb_type(di); if (!ret) { - /* Update maximum input current */ - ret = ab8500_charger_set_vbus_in_curr(di, - di->max_usb_in_curr); - if (ret) - return; - - ab8500_charger_set_usb_connected(di, true); - ab8500_power_supply_changed(di, &di->usb_chg.psy); + if (di->usb_device_is_unrecognised) { + dev_dbg(di->dev, + "Potential Legacy Charger device. " + "Delay work for %d msec for USB enum " + "to finish", + WAIT_FOR_USB_ENUMERATION); + queue_delayed_work(di->charger_wq, + &di->attach_work, + msecs_to_jiffies + (WAIT_FOR_USB_ENUMERATION)); + } else { + queue_delayed_work(di->charger_wq, + &di->attach_work, 0); + } } else if (ret == -ENXIO) { /* No valid charger type detected */ ab8500_charger_set_usb_connected(di, false); @@ -2886,6 +2931,9 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev) INIT_DELAYED_WORK_DEFERRABLE(&di->kick_wd_work, ab8500_charger_kick_watchdog_work); + INIT_DELAYED_WORK(&di->attach_work, + ab8500_charger_usb_link_attach_work); + INIT_DELAYED_WORK_DEFERRABLE(&di->check_vbat_work, ab8500_charger_check_vbat_work);