From patchwork Fri Jan 11 13:13:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 1966091 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id DF1E03FF0F for ; Fri, 11 Jan 2013 13:25:06 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TteXV-0006Gv-1M; Fri, 11 Jan 2013 13:20:53 +0000 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TteQh-0001Us-MW for linux-arm-kernel@lists.infradead.org; Fri, 11 Jan 2013 13:13:55 +0000 Received: by mail-wi0-f170.google.com with SMTP id hq7so1969182wib.3 for ; Fri, 11 Jan 2013 05:13:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=C5uXZCJF9zN5zR8dG/z1xriIu0PUe44krdFq6wOxggg=; b=Tw2PfIqzrDNg9QSk4ILfU4P4Gw0QiJojMxyWzeIJEiJGA2ztUhtrCLw0LZyITzoMMa qewPIV96MlkcFizV6hdu4f0M6xUnWIcdpxUZafEG0FbWDwLjyLNXjTaufj6WPuXAH/pa v3Jx5SEEQ/wp3T6JeELMJa1rVg5hQLr9v+5P00mfjVLJDy63sDu4+l+uneJp6uGP7hqD SrETlpWbrkkj8UuM09M2kwCiKMqxTSYR3ZVaqH4jK4GRcgTqrQjdOqg9QtCKts5XzyLU LaEK5+LmsRJba9aZWxiE2jSXPfdYZ0DrZH1avDcV9DMRruysM6M3oJDZOmWhS2F2zEm7 eFxQ== X-Received: by 10.180.86.36 with SMTP id m4mr15293177wiz.5.1357910030360; Fri, 11 Jan 2013 05:13:50 -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 p2sm7204515wic.7.2013.01.11.05.13.48 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 05:13:49 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 16/18] power: ab8500_charger: Adds support for legacy USB chargers Date: Fri, 11 Jan 2013 13:13:04 +0000 Message-Id: <1357909986-9262-17-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357909986-9262-1-git-send-email-lee.jones@linaro.org> References: <1357909986-9262-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQk+f/b3kD2LD5nIKMdciBeD8zNCvJ4BEdpUlVBO2HOHQD2DOuN8eRvkqlUl+bw+R+d+XoQv X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130111_081352_367862_4C340AEA X-CRM114-Status: GOOD ( 19.38 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Marcus Cooper , Lee Jones , linus.walleij@stericsson.com, arnd@arndb.de, cbouatmailru@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 | 79 ++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c index 2769e91..0957240 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; @@ -1912,6 +1927,29 @@ 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) +{ + struct ab8500_charger *di = + container_of(work, struct ab8500_charger, attach_work.work); + int ret; + + /* 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 * @@ -1937,23 +1975,29 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work) di->vbus_detected = 0; ab8500_charger_set_usb_connected(di, false); ab8500_power_supply_changed(di, &di->usb_chg.psy); - } else { - 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; + return; + } - ab8500_charger_set_usb_connected(di, true); - ab8500_power_supply_changed(di, &di->usb_chg.psy); - } else if (ret == -ENXIO) { - /* No valid charger type detected */ - ab8500_charger_set_usb_connected(di, false); - ab8500_power_supply_changed(di, &di->usb_chg.psy); + di->vbus_detected = 1; + ret = ab8500_charger_read_usb_type(di); + if (!ret) { + 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); + ab8500_power_supply_changed(di, &di->usb_chg.psy); } } @@ -2916,6 +2960,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);