From patchwork Thu Dec 13 15:21:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13553 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 98EAA23E2A for ; Thu, 13 Dec 2012 15:22:25 +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 31892A185E5 for ; Thu, 13 Dec 2012 15:22:25 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so4139889ieb.11 for ; Thu, 13 Dec 2012 07:22:24 -0800 (PST) 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:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=YNVkcZLIWyQ17LZKS/6GH64lhdxPxFYlln/qDfuJiG8=; b=pIy9EwszZfwphffKNn4KiPtEJ1hHzrAy9smrjZ99uxPKtrsAijV6U9+rerwB1veHbJ zttKtTwIK9dT+6BAQUSRPL+05Bzzsq4tirrfewid/WA13JNpD7n7g4JYwLWwu/XZzA7t RItUmuFxt1JnEgtPucag4wBV+4j8+t3ipCOAgks9wP6Qym5C+kOvkbrUVYHVALXzBABI SifvHtnftcpJ7oZW2nazLyw2SO92pAU5A8ahqKi5Q6rEJKcpSUSWfKJt5IXK23gNFWhG L58fiwKSC6pYgeqOc8AyB0+tMt7PonjlOkuCjS5jY+4VgyftHjEZTAO8EbDXhy8oGwdI V6eA== Received: by 10.50.185.166 with SMTP id fd6mr1877237igc.62.1355412144628; Thu, 13 Dec 2012 07:22:24 -0800 (PST) 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.67.148 with SMTP id n20csp16280igt; Thu, 13 Dec 2012 07:22:23 -0800 (PST) Received: by 10.180.106.34 with SMTP id gr2mr4008885wib.18.1355412143212; Thu, 13 Dec 2012 07:22:23 -0800 (PST) Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com [74.125.82.43]) by mx.google.com with ESMTPS id u8si10214069wiw.9.2012.12.13.07.22.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:23 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.43 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.43; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.43 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wg0-f43.google.com with SMTP id e12so834595wge.34 for ; Thu, 13 Dec 2012 07:22:22 -0800 (PST) Received: by 10.194.93.40 with SMTP id cr8mr9082674wjb.16.1355412142717; Thu, 13 Dec 2012 07:22:22 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id i6sm8200894wix.5.2012.12.13.07.22.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:21 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: cbou@mail.ru, Marcus Cooper , Lee Jones Subject: [PATCH 17/18] power: ab8500_charger: Adds support for legacy USB chargers Date: Thu, 13 Dec 2012 15:21:40 +0000 Message-Id: <1355412102-14265-18-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> References: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQnYi8aeHzQgAQra3zdJfzfYz/LVFUZtjLVC/L3A5mJ7os/XcydU6gn86I8xjmubZqM09Vcg From: Marcus Cooper A Legacy USB charger should be handled directly by the charger driver. Signed-off-by: Lee Jones Signed-off-by: Marcus Cooper Reviewed-by: Karl KOMIEROWSKI Reviewed-by: Jonas ABERG --- drivers/power/ab8500_charger.c | 65 ++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index 0ada459..6e4ed4f 100644 --- a/drivers/power/ab8500_charger.c +++ b/drivers/power/ab8500_charger.c @@ -88,6 +88,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 */ @@ -201,6 +204,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 * @autopower_cfg platform specific power config support for "pwron after pwrloss" * @parent: Pointer to the struct ab8500 @@ -219,6 +223,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 @@ -243,6 +248,7 @@ struct ab8500_charger { bool vddadc_en_usb; int vbat; int old_vbat; + bool usb_device_is_unrecognised; bool autopower; bool autopower_cfg; struct ab8500 *parent; @@ -260,6 +266,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; @@ -597,6 +604,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: @@ -642,9 +651,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; @@ -1915,6 +1930,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 * @@ -1944,14 +1983,19 @@ 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); @@ -2919,6 +2963,9 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev) INIT_DEFERRABLE_WORK(&di->check_vbat_work, ab8500_charger_check_vbat_work); + INIT_DELAYED_WORK(&di->attach_work, + ab8500_charger_usb_link_attach_work); + /* Init work for charger detection */ INIT_WORK(&di->usb_link_status_work, ab8500_charger_usb_link_status_work);