Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751745AbbHSBNv (ORCPT ); Tue, 18 Aug 2015 21:13:51 -0400 Received: from mail-bn1on0148.outbound.protection.outlook.com ([157.56.110.148]:54040 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750867AbbHSBNt (ORCPT ); Tue, 18 Aug 2015 21:13:49 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Wed, 19 Aug 2015 08:02:37 +0800 From: Peter Chen To: Mark Brown CC: Baolin Wang , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v2 3/3] power: wm831x_power: Support USB charger current limit management Message-ID: <20150819000236.GA23719@shlinux2> References: <20150818052011.GF1864@shlinux2> <20150818161200.GK10748@sirena.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20150818161200.GK10748@sirena.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD003;1:V0WOqFDnB9sY505xMKNCNitIvM7lHQNvyI+3oI9aK0NGbb4X6tUlW1okDyToclYn/slQ4QJY+/xzzGGkTBKbKFl9V+FUSH8fSMrsbjXV7l2IS5tLrU8YA1VEVvcJAUxWl2CuzmU+IaVOYWSgWEvBM1fuIIwkiZXM5O7z5CbwkznSIuvE/GKqJlHBmjQUNFkvPMQX4YPokdkDHkvVsKcDO68xVXZUzQWtKRd4Cbt/quD8yf04raoYnwsCvlsZAviOvU7Zu8UqfYAb5tanOgC7ozYrOYvzijxAjBIR+Snb8x0Kbi0QjvSzlEg9m/Ya4nm1WSXHQXTixkfQDkjM7OvZpMuuHqmLSxf3evPvag19yqdS0KcmGpOoVNOr9hW5zhYB+KixZfPx87LDk2bBYr5cvQ== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(199003)(189002)(24454002)(86362001)(2950100001)(64706001)(47776003)(81156007)(92566002)(6806004)(87936001)(97756001)(68736005)(46102003)(97736004)(5001830100001)(4001350100001)(83506001)(50466002)(104016003)(77096005)(5001860100001)(33656002)(46406003)(85426001)(4001540100001)(62966003)(23726002)(5001960100002)(33716001)(76176999)(50986999)(105606002)(106466001)(77156002)(54356999)(110136002)(189998001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1280;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1280;2:BKT89myZjnSuS8GlT2J4DTl93T8T1QNuJdrnr10tWNBnvwX3Nv7tzANsuFiDQrpnxwC879BeF3pzyNedFiH4CY5LC8r/IyyIwS7LmMSuQfMTJjn5MGRQzls8k8NEX3TgOL6+Ud/TLrgchoI5Lv+OwGlk7itAf0bhlufebHeVGGI=;3:4eHKj/NoOSqX6oCrxNGnFyqMKQuCfuqPmqR2rsTDzVxe7GVDqDMfaFJ1PMx7SRQ+sD6Dx7LhIAGFIVNJrE7ebkMIqzBcbVnMHE4H3cWwQbd/VkQPPjayzEySyByX+aQRbvbvGIkH5VfhmH/ylvVm9ifXHRuhDnTirrS/XN0HdNllIMwajKVRkdMhUkaqhNLkai9akbs4B5EnlcI2ZVZ2T+VLuz6MbpNbIHbQFfF+MZk=;25:rQEGRWOvfhI4wdR1O/PqK2JuLZpNWtzAMhS0ltK2de3Hq0e7IdQyNuO/VE+kBs5IBOrSehqUoJP0/TvxL6CcK1gJ6OE38r8n8DBNS2QOzvcZ2jhtcQIBFWCgsrcZPp5PoE2YbPxTpvK0FL0M5g1F2UtgvvFUsqG7tcR6DdOteqjE6TEXicdthaupslE3dtIW+rEBRTAXR76gR88rnSPW/OLhtLKk3uXMd6vhDvL9XBVsg9NKi9QcjBULzDg4tkAS X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1280;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0783; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1280;20:2iTldXrGtIkLX2Ucyj5FFIGK1W7XANeAQDygOMUjuUwcszvtyrJDZsVc92jBJESjyYyNL/qQWXhUnyQb9VMsYm10DgZ0G4awC1RBo7fQmyFNq19lxrV+pjW+NyzmLsrD6QTCSje5lR1/PUYGUSru6xZg/Mw4V+8jesKDJu64i53mYTda+g3Qm/eU66u1fShCefs9uC0f1EjQN45stjPEVBTGWoXNjWKUpU600azhkgMg/C6NaDQhFQEJ+goSZZON+rSvSa0ShQNxD8QrT77bnTGoQtZtL78oxMG1FWKe/tcW8qezLa7wkfzBrOV2iZDROCmtFgHVW4PE4RENSwgorKxDT8/AERUk0x36aq+Vh7E=;4:N7MrxzQIrr+nFIrhudIVNFv8YKxQFDzdcwMgQcdk/gmT2smcSFxTH8X9YmDzdKCXlzcdKSyIxOUkTso+daSrBT7l/U1cyuiXGWQVzyrSSt6cs73kt/XYcjj10P1gBBZ8DhSowkwHOUGsn5XxCa3MRgzATp8vF6Le7zeVUpTeZ9vkm0+OncOggyAbbfcIBF/i65XiQu4PMl68MIvaetEpRExyVtamFpbJy7vqvzhA5OwuYuMFkSbXKXPo/S4Nis90DOMBpXobPRpMoSJQrLtW2D/09y4o671RWrkzrnuI9OBN13dmCxdMTHTZhRE7fWmu X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:DM2PR0301MB1280;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1280; X-Forefront-PRVS: 0673F5BE31 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2P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9v2xhUuvvscUs?= =?us-ascii?Q?XI0G5VrBf0FzH07ajtcrt3ba8+N6eiZoBxmPyHWXRYHQTAkExYHpFF7vVoTn?= =?us-ascii?Q?GydPTeKmYqhdv8LsgpDLOD+shHVkJvesv9stlot8dYLd61e9bOGdS+llYe95?= =?us-ascii?Q?d7xDnqZKhOr8pVX++fjX8Ti4kxdRqkBsn+EUZQnvIlElEUC03+jZmVKQe2EC?= =?us-ascii?Q?1Vb2umOgUmjOgpKw9e5jcrTyCoCPdVhbr4VJ6D9QjDC++oRhj6aHuBW5sHRz?= =?us-ascii?Q?3wv3u5uJvzoA=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1280;5:sBiJxMuwlC+xMnUlpPXtRVcGear1GklFHQNAZFuw/mjjXblDLMpgdhHtdypWfIvKUatBN4Dv6FMY2AKA7GG+lVrc2/GC93B9Em9b58mEDvGIfi+FSZVGcaq0cCHJgkf3GQ9d5lORMjXa2XkZ2Ziu+A==;24:uEg1Rbvbsiq58+u+JbIx36OUZVZrlg++tGj+lb7vfrvp1DlPly468juYEuMM9b9TLwK0DurlTcyR72UmvQwPkqxzGEp0CPA8bCVo/vLGUnA=;20:7nUrTLnm8Z+29jJTSCldE8EAR7LwaqeYAopEmA8hLHbrgweh4hc1h2N5xrLhD6+gN0aNRmdz2UX6eBTZBMNaQg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2015 01:13:45.5614 (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.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1280 X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB0783;2:WX+UTx1l8MatyDLuyag7uNnyGK2BuEkUxc7XBES8DnZ6VkmKAdFShNv+fQ06Mx6ozSnGX9xarWf8AFmvSuton6EJNH95E1PdZ/DCitY00GNqrnJ8CD6VPC2eBld0Z3aOX0Iw/+ypUOAt0eeHGFKzSAWVHB4SozC2iIdhvHM0IZM=;3:3g6W7thmRWG2RvSeJwvH75lgfpxTgn4ihRbiMyrBdiYt2E11geh7ZQFqONFeEEWC1tPh25gqTfBzzUAgK6CzK5d7NYd8hUuEIUUrgykECGwFvW7hrhn4qPoHScBMZSuuK9y9GEuzw/lGBssZamKbcx/nmJlxPKu5HtkIr9Od3tYZhLv5YFb2Etkb81CoeESnODYluPCYiH6vJTFyhqUjXpCcstCgfjdEdXgA9TlPGYo=;25:grAwZAGC9yvP/9iKylRFP7XieyGiOJWNfoNaFFMbb0lCtDqNHh8VSjEF00ifuthQUlV6Pk3lhaDinjECcuoBwX221tmAc4zctjCMvTZY8qUKfWPPGCzp8ALon9AFNGrgp5gfJlOwUdlXqYZB8K8ImAWLC42cq7ioMvGGRgBnxeg5Ymm45qNTlc/bw7gdymxDykmTc7DV2yX1K+NNLXZ4bIEj9YcB7sJdheqUeFYK+M4Ojl32rNPUL94goU0+kZkt;23:qkXcgIEHH94+Bw9ezVVw50jFgHKMxYU2gDh6Wv3SQdTXqZxAsvTUJnvgn9GWWuIbppSHg+uYqqZ+032WUDvv63Q0rO7OJf6VgnT4BjxdS6z7r5UscLLPsCCmsg6Umk2H/WpMlxgXY0NIyReTrwkFE+YEb/UlxJvQJHCaUleLLq4BqPecExFk8KcCfQ3Q3biL X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2607 Lines: 77 On Tue, Aug 18, 2015 at 09:12:00AM -0700, Mark Brown wrote: > On Tue, Aug 18, 2015 at 01:20:12PM +0800, Peter Chen wrote: > > > ok, I just had suspected below function's correctness, after looking > > it again, it always set 1800 as charging limit, does it be expected? > > > + /* Find the highest supported limit */ > > + best = 0; > > + for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) { > > + if (limit < wm831x_usb_limits[i] && > +/* In miliamps */ +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; +} + > The above check is intended to ensure that we don't go over the limit > that was passed in in the callback. The goal is to select the highest > option that is less than the limit passed in. Please correct me if I was wrong, If there is SDP (PC), the current limit is 500mA, then when the i = 4, (500 < 900) && (0 < 900) is true, the best is 4. When the i goes to 5, (500 < 1500) && (900 < 1500) is true, the best is 5. At last, the best will be 1800, which is not our expectation. Below code may be correct for the goal you expressed. 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; } -- 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/