Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753792AbbHQCSP (ORCPT ); Sun, 16 Aug 2015 22:18:15 -0400 Received: from mail-by2on0137.outbound.protection.outlook.com ([207.46.100.137]:60604 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752624AbbHQCSK (ORCPT ); Sun, 16 Aug 2015 22:18:10 -0400 X-Greylist: delayed 1616 seconds by postgrey-1.27 at vger.kernel.org; Sun, 16 Aug 2015 22:18:10 EDT Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Mon, 17 Aug 2015 09:07:08 +0800 From: Peter Chen To: Baolin Wang CC: , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v2 3/3] power: wm831x_power: Support USB charger current limit management Message-ID: <20150817010707.GC1864@shlinux2> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD026;1:8idrXWKcBOlhwAdubT2dRL8x/13blfQQgp748JbV7QSnXgHaAVv/1ujNxftGqx1cqXn4HpV5pETuy85hkfennZ8KVOVrxbhtngvJSdNlxvVNyysGzq+ODC/xPoDOfscfCLqX5LsWEs/JVFzYoiFFMZe+JU8Xu52cY46O67ZNoNC/BJMnlLAasfRuLhbYKTJRd0Kvp5phDBEtPpssoPLm64qzpdAc7KXWPFq54l/thbyK3X5CEGViALQTX9syga4GkYbK/of/dUIWVQQSnMDhdAdjT92uKc29gzNI0EL9OvPoTAv1Hvhz8pffrDL88IhfKfOY6EYBJffvVzjyUbyUHCSVNE8d/SbdcPwvkzbGPnHlrViS94jWxwCNTvTR/hSasvtM3rMFdoy6uJqIQV7cgA== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(3050300001)(189002)(24454002)(199003)(87936001)(86362001)(104016003)(46406003)(97756001)(105606002)(77096005)(106466001)(46102003)(19580395003)(83506001)(19580405001)(6806004)(68736005)(69596002)(5001960100002)(85426001)(50466002)(110136002)(2950100001)(64706001)(47776003)(4001540100001)(33716001)(189998001)(4001350100001)(54356999)(33656002)(81156007)(5001830100001)(76176999)(5001860100001)(62966003)(97736004)(23726002)(92566002)(77156002)(5001920100001)(50986999);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB492;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB492;2:+P0XQOvZ5OeOLQOa1ogYzLTzHJw/wO7Ji0UEOoC3bH5U+9Lizzw9wwJlKSXL0ejijDm+uqREE+8AzTRq3iC/e7noL6vDK9LwL4nabQUFzQRBXHiN2CiIYw5uS1J0I+L0Z9tDcGfBusiTvI2UE9oQraxonzuw+AeepozMbjEfgBo=;3:oslp1b13NalPPHK6tXrwYRxK+ImA+6WLLxysrD5KMS5YUT1+pOizwk1ExzQObYF5OSkBRzUSAUcmvst2NsBZ5gTGOzbX28VX8CzsdTROGViHOrom7dspGb3UBJCI1MJ1FKbKWldREbSCF37UjcDM5L8cg9QNADvYRP91zoqY1/QY7JztPhKjBimrjEB1IH2kuKRjtObPnuFM+vymhCrQ8TdCDZICsc2A3/NKhuhvjqg=;25:Y098AQBB3Yii/95XGAqdbkxG6YOnF0o3jhPFiNbSdS4qXZ1k7PnxaSmPLoTqJ6I9lAdYt/uyl90XUSQEea4faWYDoeem+BinYXfNGi3PE8WyGmPrvXWGaofdzpfsNrX/gkflH91fDgwdfaPdBASt6KjX33afL2wH1rm4i4LeMOjhbzYMeZ0LOILKw9yLhgaIUiTH3IPyx6B3BKaeWkq1ka6a2HSbrZLq/nAUjjeeI7JHfqkckcWGcZN1jiHzwAPY X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB492; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB492;20:/YVVH6NDijCZPSGIk7sV3ci9JZkcjJG7rc3OfGpy8UuVAnv+WC1Ea41zGdgxbr9Pq/4nlJUub9TCfdmlQWukAzzwT9xBW3V74jooZVNk+K884R3iSQc94uQ+tN02XChqQSzKl3w5100hxsdYHKt+nzun3X+6Cv8B6gEh4vZKAc3X1W1ZFFUHQRtHPDjffX4GFFAkeCfriqXIW114BM241yJM7HJesHMF+54ZuDdqGCvGNBcZIlcJtzYx/CZD2XfN9Np5uf9yObmzPe5pMV+UwhCOIJkPJJswZE1F1sqoF2vLcJq+DkznujgFic5UjtaTgfbfTNMkpEvsqJhDJLBeOLVpnsisGEh+LYyNfrGHQTM=;4:uv+OBzVLvXu/lsezJyDY5KM6pWgzm+5rxqoNKxIbd47pqhfG61gebcrLFyHCu54+v/NLooQZgJ+5oILGF9Ed3FOeIQjzZLfkdS8hKZ0dLg7XucNAXTPSWouI6JpgXZF4JL5GOmdPKXynIX/4RvCkKH3c+xARmvy7PNVs7pN3gBwRmg/x7Kr6J0khW8ReKnKnmWmhUAHYrW2XS8BCbF8+Dy2aauBXTihWgijPQEY6UtznRCUCKSQym+uOFN+FacW3muAEVdp5cyQryEru3FNAwHneE/EYvolZbz7CiMIQ8hNLhv8V0AXOqCm9/b2ClQxx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(8121501046)(3002001);SRVR:BY2PR03MB492;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB492; X-Forefront-PRVS: 0671F32598 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB492;23:nGNDY/wFdClMtNPh/Lj5HHvQ6VFal0YWGN5ytTCILL?= =?us-ascii?Q?pMwg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?= =?us-ascii?Q?DEOrqzPXjJvW7nkuY/5RprXB6umZUTHjGeslyqNTU4/UdIXODFDK62Q0GdII?= =?us-ascii?Q?Pa5T8Repulh2olOlVoxKEot2MRiTWboswFrPC0P5K6k1zWnZe8E/DYagnHx7?= =?us-ascii?Q?9HmiG/xh35XKM8IFmkWB0xCElMrip2/r4Z3d0+ew/TDQCbgm2W6bFdB0hyD0?= =?us-ascii?Q?iLwI1tzGsFPv5NgYATtt4IaxA/drfRgGzazViHQezGbl1CcoRpHo7VBxo93p?= =?us-ascii?Q?BW79mixRhJsnUY5WtNLCqdlBsyq4qx5iy2Kvn8fYsz7uy9HwgYO71DAg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB492;5:FGMts5Ot2aXb1Wb75/LtoznEOPVJrCln9+KN5RP1iklCM4AlerBypry9l/R60Src8yxvlqjF1cH5Zm4lVGX3aDkQM5J345/Js2XGu61VaGwZ2FlbEDbFvOQGb6qylj9SabIPbHgeY+Jstt5o7GcLHg==;24:GCr3anjeajTk5mln8bb3klXDAqylXZOUFTfAGb0V4pQLWyZuMoB7kFg5GI360UycL5/GA4NMvjk4A5nSH2tMI5XvmYyCaEz6GjNi27IbQLY=;20:9pPGaHc0FmJuC9lFp1cX3uVkJt7QAOxVcpBp61M1KtAC+3wGYl5qL/k6Pv+DPwM5BfBqlGS+c+obbtjVm6Hgag== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2015 02:18:07.1607 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB492 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4738 Lines: 156 On Fri, Aug 14, 2015 at 05:47:46PM +0800, Baolin Wang wrote: > 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/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..72c661f 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 miliamps */ > +static unsigned int wm831x_usb_limits[] = { > + 0, > + 2, > + 100, > + 500, > + 900, > + 1500, > + 1800, > + 550, > +}; Why 550 is the last, but not 1800? > + > +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) { Where the wm831x_pdata->usb_gadget is initialized? > + 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: > + usb_charger_put(power->usb_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); > + usb_charger_put(wm831x_power->usb_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]; > -- > 1.7.9.5 > -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/