From patchwork Mon Jul 3 06:07:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 106875 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp5397826qge; Sun, 2 Jul 2017 23:08:17 -0700 (PDT) X-Received: by 10.98.68.156 with SMTP id m28mr8143024pfi.159.1499062097157; Sun, 02 Jul 2017 23:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499062097; cv=none; d=google.com; s=arc-20160816; b=lFfVa6JTW1XyDQ+MoiZ6lbPSV6oi9Qy8HbA7pCUsLuoBg4/SgljVezx3sT1aZ4LnmX n/KZ39JrpuR4XbhsqfklPkbsczfKExNWqXgzhoVNi6kJ9gKa2RB9WR53mmosVlCpKmAo LuZtgTE+s2Q1xXatWXp6vx0zrecnQ3umiZ4a466Tg7w2LA4W+trDYdiYQepKV/yyT08+ I0KxBEfuoSlpUAtgqj5CAhQLQqWIojjp5JTv/xeSLZkTkBXIFedVjUv0/KhQ8avRYGNo LSGbPqBHmaDuY4KDeX/uuITog3bJ1TJMinuzJslW8E+VEMWafeYaSQVqe/edjcmzFi7y dKNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=sTSIvAmJ+8+Iz+yFrja8kxZHyZrRJBGU67lZtBIhk7w=; b=fY7LC2onJ1wbm0+R3yC8DHL5qF+yrwK+WhwrjBxiu2WCU+/iXe7K9HZDTyN/oNdp1p y2efpuXxqn/ECioJK3ds02A9HZ0X1X1MHJzvm8UCXkoajyFkwjZDvYlKnxZ12qrQ6HNR oLt8V7DCjSNbnEb/IJR8ikzL7+3lxoET3D3pSuoqnmueqrr5dyZKyKkbl7czCdb59CUs psdcLFmXb/Rl6kCy7cKJbeU21xgHG+0yzIRbS9MsgdaFwyZm4Muz7XYMVEJG5pW4/Vrg krdc1eoPgawDXXsfL1p+obVUgVk1YDd3LZqJvDn8z76J/4fKkPIMZZ9zPkWfsr632OkO /08Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=SbTBBPc1; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si12403050ple.505.2017.07.02.23.08.16; Sun, 02 Jul 2017 23:08:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=SbTBBPc1; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752089AbdGCGIB (ORCPT + 4 others); Mon, 3 Jul 2017 02:08:01 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:33995 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752130AbdGCGIA (ORCPT ); Mon, 3 Jul 2017 02:08:00 -0400 Received: by mail-pg0-f41.google.com with SMTP id t186so90370625pgb.1 for ; Sun, 02 Jul 2017 23:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=N9r5VEQXKz5m+Eensbdev1yPt9+TbahPK+INcDIqZFE=; b=SbTBBPc1qAxaUb6DqLi9+6OJRUBIXcAqABopcv+C8W7sVBOnc2wXDbJa/GAvvlSqhw IAtzIq/NbLTPmjDg4XQIyYCIfsqSH1vR8EY1Pg1lh6xOis93h9uSumuvtulDFY+SHMKd a5Aj/03tWfXUVSWxjUvDyBi4y6EBBk36Hk/Wc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=N9r5VEQXKz5m+Eensbdev1yPt9+TbahPK+INcDIqZFE=; b=n0AssebHfcJxquVwd81Owd7gknLeAJC0VvlfIFmzhRmi9u7wtSTxfTMJHV6qloWUzm 2MIuOmfh5v0c7meU+RE6SIH5g0mc5rW4obTKrhWUHIrftswEdl1cZpDsX/pRNnpN85Tb 0v09nkPCcD5VyA9yB1/AmRBMdkU8RC1vhd2X8fXqi1ZfWc3CNASR8+EF/ojLzlT8CUFX jrgqeZm3bsgf6aWrE88M/s7kvybEjqSJBzucv/qywt+795YuLtaDQ2SooapyawKs8fh6 zPmH7FaxE3LJQgsCZkOQs04hPWM4WXrckB1obrJ/H1Nw+d2OCmJRwerMpow6lm9f3gYK JBmA== X-Gm-Message-State: AIVw113OAeK6BYDfPOpEF/qxtdneAlEegVmx8+S9l8lBNAvIv4JYnbrK N+fSNCAUz1IOTBl8 X-Received: by 10.99.147.19 with SMTP id b19mr8700494pge.154.1499062079286; Sun, 02 Jul 2017 23:07:59 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id x64sm33177577pfk.20.2017.07.02.23.07.54 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Jul 2017 23:07:58 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, sre@kernel.org Cc: jun.li@nxp.com, peter.chen@freescale.com, broonie@kernel.org, john.stultz@linaro.org, neilb@suse.com, patches@opensource.wolfsonmicro.com, baolin.wang@linaro.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] include: uapi: usb: Introduce USB charger type and state definition Date: Mon, 3 Jul 2017 14:07:13 +0800 Message-Id: <54d4a3ae584900a74e04b5cd27157dced44fdfef.1499061617.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Introducing USB charger type and state definition can help to support USB charging which will be added in USB phy core. Signed-off-by: Baolin Wang --- include/uapi/linux/usb/charger.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 include/uapi/linux/usb/charger.h -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/uapi/linux/usb/charger.h b/include/uapi/linux/usb/charger.h new file mode 100644 index 0000000..5f72af3 --- /dev/null +++ b/include/uapi/linux/usb/charger.h @@ -0,0 +1,31 @@ +/* + * This file defines the USB charger type and state that are needed for + * USB device APIs. + */ + +#ifndef _UAPI__LINUX_USB_CHARGER_H +#define _UAPI__LINUX_USB_CHARGER_H + +/* + * USB charger type: + * SDP (Standard Downstream Port) + * DCP (Dedicated Charging Port) + * CDP (Charging Downstream Port) + * ACA (Accessory Charger Adapters) + */ +enum usb_charger_type { + UNKNOWN_TYPE, + SDP_TYPE, + DCP_TYPE, + CDP_TYPE, + ACA_TYPE, +}; + +/* USB charger state */ +enum usb_charger_state { + USB_CHARGER_DEFAULT, + USB_CHARGER_PRESENT, + USB_CHARGER_ABSENT, +}; + +#endif /* _UAPI__LINUX_USB_CHARGER_H */ From patchwork Mon Jul 3 06:07:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 106877 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp5397851qge; Sun, 2 Jul 2017 23:08:18 -0700 (PDT) X-Received: by 10.98.64.7 with SMTP id n7mr8090503pfa.76.1499062098699; Sun, 02 Jul 2017 23:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499062098; cv=none; d=google.com; s=arc-20160816; b=pNsvvUzWkML2/CsMmtsp0M+SHC9uNXQqOSN7DIEV1cfh316qbBIw8B0almyUTS4usB S7O9eUbRodNLt8hqKAW7xRuUYs1z7ABsCnHvGzkei5Ti7uwaQx3QeDQqU0tpVBzIFwvE Q80Crb1WNwtqWOykvEul4lZQN8uG1NEdZa4HLNcYZbMSoClXBXlCl7G/63Kgqs2p9JBJ hbHEn8/ZmprfjFW6X7Fk9HCJE/E4F1d5iv0gBLGJSisPLQWKzF7f4dRya/CIQNz73XO+ T7WI6os/0m7k5gl48S1pZ7OswVP+TPUnjVfw4LkW0x3ZcFJzBjNNR1qjaru3CNAypLKg aAvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=bM7WrtNbs4vogs+DPbfB6XUbFxqjdN8sBfbv/yRf3W8=; b=tJGilAhgW67S57zbRmx7jqLtpd4xbBsTFtyW3NKzQnq9Z6dMzresHcWkHCPm+zj+T/ /Ehu7yzoc6JgbjsmdxeR/2iHjt7zGkTUHzRHsn573KacSjwF0uAXUyTn76Yh0FlTqYga Qg3hBTnQ9wW1+L3LKExlrVao7svgp7aZCHUEfh0A0GN2gqEhtE/6j2aeGlzD9AxUUhzP Tszu4hJFqTu9dHD6tm5CiSt0+o0qhrF41HiFs13E6vZPFDIrwDI0w4pyMz0rIfWdoVka zYQowQ9q5+TdSDlwjSLr2FCUzOxgavvyC/9zjLj+HFdgtKDdfwi71A+GD2yeQVEKD53C oYgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=MC/3bQFs; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si12403050ple.505.2017.07.02.23.08.18; Sun, 02 Jul 2017 23:08:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=MC/3bQFs; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752296AbdGCGIQ (ORCPT + 4 others); Mon, 3 Jul 2017 02:08:16 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:32861 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073AbdGCGIO (ORCPT ); Mon, 3 Jul 2017 02:08:14 -0400 Received: by mail-pg0-f53.google.com with SMTP id k14so14189751pgr.0 for ; Sun, 02 Jul 2017 23:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=g2MtqLNe5Zrv7Rq/SA/5+RCNBw5JP4jhnMkGdIR/TKI=; b=MC/3bQFstOP9W21eo9nZg15W2r/ezMTFDu2sOg55LceurnIgX9+76P7yxWsaIlzRKT 2FP4pHoF3C4JSYLYcLs8S712YppYXmp8V5wYr4bYE7xzrtE85jen9qsmf4J0JcL+oxZI 5DzFOMRZn6xqJ0xK35XVs6xWg5bqM2w85Tws4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=g2MtqLNe5Zrv7Rq/SA/5+RCNBw5JP4jhnMkGdIR/TKI=; b=r8rNzZFtCWHFW7N8u9iMI9/VPnL/dlTASMZHOilAv2RVSxOiZ/8o7JjbrM7hs1Dqmo v+MQUR2C0svNN1s8Mvg0sq536AUJM3zOUcIefEtZ8PRBCE7Y7CmOWXHTTCR6lt3rc4o0 GpMuFNsPxs0TswaFj4vwVCyyFHmfjqQf7VACToMVQT/dbix1uYL0ugta9OXkvGLDCbgi Q5Xd1UFfkopcDy9hRuJQH1Q62l3rlu4FFnvHtiNi9T1OQ8u2NI7IU+EUOEOo+GCSjirC Ja0xWINWXvHhVCCx7yXooKRtgCCWycRwlnCKjDO9vfugexKMVhIyOOpMsA+G7i0LGc+L e/og== X-Gm-Message-State: AIVw112me5swbervcJnGswOx2+5LsCFPBwE62SnetwfJy+2kFmuYsJqk /mCpF0L/uXAPakhy X-Received: by 10.84.232.207 with SMTP id x15mr9107809plm.173.1499062088806; Sun, 02 Jul 2017 23:08:08 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id x64sm33177577pfk.20.2017.07.02.23.08.04 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 02 Jul 2017 23:08:08 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, sre@kernel.org Cc: jun.li@nxp.com, peter.chen@freescale.com, broonie@kernel.org, john.stultz@linaro.org, neilb@suse.com, patches@opensource.wolfsonmicro.com, baolin.wang@linaro.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] power: wm831x_power: Support USB charger current limit management Date: Mon, 3 Jul 2017 14:07:15 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 --- drivers/power/supply/wm831x_power.c | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/power/supply/wm831x_power.c b/drivers/power/supply/wm831x_power.c index 7082301..3e3480708 100644 --- a/drivers/power/supply/wm831x_power.c +++ b/drivers/power/supply/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_phy *usb_phy; + struct notifier_block usb_notify; }; static int wm831x_power_check_online(struct wm831x *wm831x, int supply, @@ -125,6 +128,43 @@ static int wm831x_usb_get_prop(struct power_supply *psy, POWER_SUPPLY_PROP_VOLTAGE_NOW, }; +/* In milliamps */ +static const 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); + unsigned 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 %umA", wm831x_usb_limits[best]); + + wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE, + WM831X_USB_ILIM_MASK, best); + + return 0; +} + /********************************************************************* * Battery properties *********************************************************************/ @@ -607,6 +647,22 @@ static int wm831x_power_probe(struct platform_device *pdev) } } + power->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, + "usb-phy", 0); + if (IS_ERR(power->usb_phy)) { + ret = PTR_ERR(power->usb_phy); + dev_err(&pdev->dev, "Failed to find USB phy: %d\n", ret); + goto err_bat_irq; + } + + power->usb_notify.notifier_call = wm831x_usb_limit_change; + ret = usb_register_notifier(power->usb_phy, + &power->usb_notify); + if (ret) { + dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret); + goto err_bat_irq; + } + return ret; err_bat_irq: @@ -637,6 +693,11 @@ static int wm831x_power_remove(struct platform_device *pdev) struct wm831x *wm831x = wm831x_power->wm831x; int irq, i; + if (wm831x_power->usb_phy) { + usb_unregister_notifier(wm831x_power->usb_phy, + &wm831x_power->usb_notify); + } + for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) { irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev,