From patchwork Fri Aug 21 05:34:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 52607 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 3395C20AF6 for ; Fri, 21 Aug 2015 05:35:47 +0000 (UTC) Received: by wijp15 with SMTP id p15sf2789607wij.3 for ; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=0GLxlhYn+7CFMVHZzuHvxCWpSsF3aM9zJMQFabbWJ1c=; b=ISswgPzBqL2ejrr8e/8JNKTcTpz22MDprnc39z9TPHWA3WybrkrbJ18odMgnrqKlcV kiCzPc7LYnX+I+ZNDKEmgzb5sCPIBSfVytUmO+zUnzUpfPw254SJ+pM7y6qp9YV98aqN kOG2OoJDD4DlDyo5/ulBhc1C450lQZS8f2d8ix8PdBjAVhAbQ/LLoo1dRji3oPWIEHF1 d0zZk6kwZ9jN0cDb50TwBgAMfO00/sZISq7RQ5j8xUFDFTNNXnxLUYvmf55oIHJrtFXz CWT/b2rumjds23TiNFxD4+jUGjL0DTtK9JnLQ+q7NYV0PE1VuWe1m4r6uSl+lM598EwK nV6Q== X-Gm-Message-State: ALoCoQlqj/pdPWlo2HCsjFULFpn3c9y3F5ecRbc6+ejU9FjFDfomIvhra3B3gY4WONpNH6wJlE5j X-Received: by 10.180.186.36 with SMTP id fh4mr468018wic.7.1440135346556; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.133 with SMTP id k5ls246149lah.42.gmail; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) X-Received: by 10.112.51.133 with SMTP id k5mr6035891lbo.107.1440135346294; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id l7si5448659lbo.54.2015.08.20.22.35.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2015 22:35:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lahi9 with SMTP id i9so34905029lah.2 for ; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) X-Received: by 10.152.44.196 with SMTP id g4mr6337744lam.56.1440135346139; Thu, 20 Aug 2015 22:35:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp431881lbb; Thu, 20 Aug 2015 22:35:44 -0700 (PDT) X-Received: by 10.68.114.196 with SMTP id ji4mr13902665pbb.46.1440135343631; Thu, 20 Aug 2015 22:35:43 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ms3si11081295pbb.202.2015.08.20.22.35.42; Thu, 20 Aug 2015 22:35:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753176AbbHUFfl (ORCPT + 28 others); Fri, 21 Aug 2015 01:35:41 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33367 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752695AbbHUFfU (ORCPT ); Fri, 21 Aug 2015 01:35:20 -0400 Received: by pacgr6 with SMTP id gr6so1410798pac.0 for ; Thu, 20 Aug 2015 22:35:19 -0700 (PDT) X-Received: by 10.68.116.176 with SMTP id jx16mr13712844pbb.3.1440135319586; Thu, 20 Aug 2015 22:35:19 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id mj1sm4763158pab.29.2015.08.20.22.35.14 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Aug 2015 22:35:18 -0700 (PDT) From: Baolin Wang To: balbi@ti.com Cc: broonie@kernel.org, linus.walleij@linaro.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, gregkh@linuxfoundation.org, peter.chen@freescale.com, sojka@merica.cz, stern@rowland.harvard.edu, r.baldyga@samsung.com, yoshihiro.shimoda.uh@renesas.com, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, sameo@linux.intel.com, lee.jones@linaro.org, patches@opensource.wolfsonmicro.com, linux-pm@vger.kernel.org Subject: [PATCH v4 5/5] power: wm831x_power: Support USB charger current limit management Date: Fri, 21 Aug 2015 13:34:52 +0800 Message-Id: <6e7ee1181bf16ee3680cb25225089cfb4a2a72f7.1440135007.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: baolin.wang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Integrate with the newly added USB charger interface to limit the current we draw from the USB input based on the input device configuration identified by the USB stack, allowing us to charge more quickly from high current inputs without drawing more current than specified from others. Signed-off-by: Mark Brown Signed-off-by: Baolin Wang Acked-by: Lee Jones Acked-by: Charles Keepax Acked-by: Peter Chen Acked-by: Sebastian Reichel --- drivers/power/wm831x_power.c | 69 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/wm831x/pdata.h | 3 ++ 2 files changed, 72 insertions(+) diff --git a/drivers/power/wm831x_power.c b/drivers/power/wm831x_power.c index db11ae6..33ae27a 100644 --- a/drivers/power/wm831x_power.c +++ b/drivers/power/wm831x_power.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,8 @@ struct wm831x_power { char usb_name[20]; char battery_name[20]; bool have_battery; + struct usb_charger *usb_charger; + struct notifier_block usb_notify; }; static int wm831x_power_check_online(struct wm831x *wm831x, int supply, @@ -125,6 +128,43 @@ static enum power_supply_property wm831x_usb_props[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, }; +/* In milliamps */ +static unsigned int wm831x_usb_limits[] = { + 0, + 2, + 100, + 500, + 900, + 1500, + 1800, + 550, +}; + +static int wm831x_usb_limit_change(struct notifier_block *nb, + unsigned long limit, void *data) +{ + struct wm831x_power *wm831x_power = container_of(nb, + struct wm831x_power, + usb_notify); + int i, best; + + /* Find the highest supported limit */ + best = 0; + for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) { + if (limit >= wm831x_usb_limits[i] && + wm831x_usb_limits[best] < wm831x_usb_limits[i]) + best = i; + } + + dev_dbg(wm831x_power->wm831x->dev, + "Limiting USB current to %dmA", wm831x_usb_limits[best]); + + wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE, + WM831X_USB_ILIM_MASK, best); + + return 0; +} + /********************************************************************* * Battery properties *********************************************************************/ @@ -606,8 +646,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } + if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = + usb_charger_find_by_name(wm831x_pdata->usb_gadget); + if (IS_ERR(power->usb_charger)) { + ret = PTR_ERR(power->usb_charger); + dev_err(&pdev->dev, + "Failed to find USB gadget: %d\n", ret); + goto err_bat_irq; + } + + power->usb_notify.notifier_call = wm831x_usb_limit_change; + + ret = usb_charger_register_notify(power->usb_charger, + &power->usb_notify); + if (ret != 0) { + dev_err(&pdev->dev, + "Failed to register notifier: %d\n", ret); + goto err_usb_charger; + } + } + return ret; +err_usb_charger: + /* put_device on charger */ err_bat_irq: --i; for (; i >= 0; i--) { @@ -637,6 +700,12 @@ static int wm831x_power_remove(struct platform_device *pdev) struct wm831x *wm831x = wm831x_power->wm831x; int irq, i; + if (wm831x_power->usb_charger) { + usb_charger_unregister_notify(wm831x_power->usb_charger, + &wm831x_power->usb_notify); + /* Free charger */ + } + for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) { irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, diff --git a/include/linux/mfd/wm831x/pdata.h b/include/linux/mfd/wm831x/pdata.h index dcc9631..5af8399 100644 --- a/include/linux/mfd/wm831x/pdata.h +++ b/include/linux/mfd/wm831x/pdata.h @@ -126,6 +126,9 @@ struct wm831x_pdata { /** The driver should initiate a power off sequence during shutdown */ bool soft_shutdown; + /** dev_name of USB charger gadget to integrate with */ + const char *usb_gadget; + int irq_base; int gpio_base; int gpio_defaults[WM831X_GPIO_NUM];