From patchwork Thu Dec 15 09:28:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 9475915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 95C8A60571 for ; Thu, 15 Dec 2016 12:04:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C02E28755 for ; Thu, 15 Dec 2016 12:04:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 709352875B; Thu, 15 Dec 2016 12:04:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AA442875C for ; Thu, 15 Dec 2016 12:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753353AbcLOMEa (ORCPT ); Thu, 15 Dec 2016 07:04:30 -0500 Received: from mail-db5eur01on0091.outbound.protection.outlook.com ([104.47.2.91]:12517 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752693AbcLOME2 (ORCPT ); Thu, 15 Dec 2016 07:04:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentiatech.onmicrosoft.com; s=selector1-axentia-se; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=+I3OrfClvVQZ9gtGAHw8BafVkatMUWB6FPhkxkWPDgI=; b=gI35fYdyccQhZwvYuSy6nppNdOR2kdQFF5JvdPeOcVfqE9lwlOPeEGMCo0LpuKWHVzIWbPfuShGxgKO7wvR9jzzHpiTJjPUSBhL9/9FWcD8qh5x+oyRJdHn69rDDYM/xW7QBYADwv2X1aJuXXmr8irQB/x4Cp0ILmCq/VEHx+SI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Received: from localhost.localdomain (217.210.101.82) by DB6PR0201MB2311.eurprd02.prod.outlook.com (10.169.222.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Thu, 15 Dec 2016 09:29:48 +0000 From: Peter Rosin To: linux-kernel@vger.kernel.org Cc: Peter Rosin , Sebastian Reichel , Rob Herring , Mark Rutland , linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3] power: supply: bq24735-charger: optionally poll the ac-detect gpio Date: Thu, 15 Dec 2016 10:28:46 +0100 Message-Id: <1481794126-5670-1-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <20161214151026.5q6goxlfscv53tol@earth> References: <20161214151026.5q6goxlfscv53tol@earth> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: VI1PR0802CA0003.eurprd08.prod.outlook.com (10.172.253.141) To DB6PR0201MB2311.eurprd02.prod.outlook.com (10.169.222.150) X-MS-Office365-Filtering-Correlation-Id: baa4f9e4-ea5a-4bd1-990d-08d424cceadb X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB6PR0201MB2311; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2311; 3:B2H62O6BUrh2tcbYN/6xnQZkPCcyl3iGwH93/u5qX1Y78scnW5sSSK3TexVBfZUeRUNNMUFueTfEaUp4/FfZEptZZ8ieX/Y3we04LePHQwVUVZS/6hyAd9SeZPYkhTb0RPyfYfrzmNIwcFZ2W767wqFwpGLuZFH7fpPe3EKN8bj/jYUTIFBDx4AOy73pB5dcZnbxwSd5agtoUr3XWfionS5d5xMC3E11soQ5zZQrN9Un54ZodnmIcMrJdy/MfPN52zGI23x8WjjyKMBGZX93qQ==; 25:HdrJRzozGaKK3oabOk513Z3JWzhZ4CDUfpyMGkDTuqDgYjYj/MclaIquOoN4T7AObw8emHW6wosIqtDLtvqmEYMqacJ3Fq6VK7xNFcvjHvzlQMy5SydeD5qgZBsHi9XewDRmFahRxKBmd5hUTJ+mWk45oYbXHsv7wnwyS+rfRDP7XnTy1RAYkx5kXtCK/jLd0zNmxsAP+43VVOOcwCCe0mNJ8nfx3C19OpncGZoy2XqHNMS7qroLrjTAMw/KEKmkA32bmALsUvnVcZYjhiTp3D72jX5nB47+gAH7r8Kd46YywsljvnFTbe8hl1EjXoJVuDNaAs2dmTGGo3NqbOPbD7znaZc5xYOHT75OftO3dvIL6Sbvg4Rrl0YeVBZfZVgXTlLZAOuEletONkgBPNVsI++znjDlFfuOIqsCOUCrMSKeq/3APvhjPzhBHHsryijakIz0d+kaTz+5e6cyY35OHw== X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2311; 31:vCDvPVeaOlGzBSbH6S0qGsiOCuKYh88xOjIixmhU4Wa64Re95tgAq5L9FMw39qg1ziz9VUUVPBZrSYE1DMb1yTp+mgiURE2zRgNArWVejupSQW62MIc8EfJZ2GK98E2+CEgwjhrF/palKY3H2NXlnZ1JzuHGmzPf4gPkR4yIaRdNxmF4RuqoQglsLQi0G6FMlKRfJQXgOoQ8PRCkABc/qpVXFwJq6TMzbQsiQv6NRo7TGrl3KuNMqJijHqZMQuiceJuC0BYB3k+pwAYACL2hcg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123558021)(2016111802025)(20161123564025)(6072148)(6043046); SRVR:DB6PR0201MB2311; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0201MB2311; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2311; 4:HrdcletVvCdrulcB0WhcIwfuQitiwjg7OFAWVv6YDud19MlcmOZBPnaET2kodTpZsn6yx49gdGn7LKQf43LjiIQ1jphTWJPX5NpSMpPbgXr593ZiV3SOTNMzdYDbfZbcGmd142VCce2d3IhMCOH2boywcX5UUlFt5kjHXbotiXTSFspyaq/5vYELHsVD87253kFbM+L0rVzjhvGLBtv3JWGayylbxjR3R4n7QZnaf55fTXD/hV1HWt0aeU/o8xStd2Oi/Lav6iQvDeZZAyhNUUUlA0pRrJ9thJCjeitAVhz8O918ptllG6ytl1c4wsIo8K5qzj+1XGBbJetgqLKh4s52QFMGvbdMtN+LJ6u7shtfVu6XrFaGKrNwnYPRYISB46gKtcDW7JyVVL/b4VaA6uqoNrBcRspcbg9XBLNhU0f+ee0Ep34z9XOGd4PGgW0WWDDbkLTPfLhRSCR3LM01dE9/rIji9pMF3VvGffGFEhe0DQ5K1od3Cf3QyqmsUSbcEya/KPw/SGvpyjGG5SQKntv9bfrIYMv7G2EzaRcOnZHgvlzIUT5p/ql9aUnExjlPM1ejQb6lYJnz+KnIdIsMX7DklohUovBJ8O9DQjj6TuaPrGUSfGmvUh4fhKcbLkI0uPi1XeaKOWtGgRoJbEH7pKN8rrIx9wSH33PRhLA9wwg= X-Forefront-PRVS: 0157DEB61B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(39450400003)(189002)(199003)(6506006)(4326007)(110136003)(106356001)(42186005)(305945005)(189998001)(6116002)(5003940100001)(92566002)(575784001)(25786008)(7736002)(36756003)(3846002)(50986999)(2361001)(2351001)(38730400001)(6486002)(50466002)(2950100002)(33646002)(6512006)(86362001)(68736007)(74482002)(105586002)(50226002)(81156014)(81166006)(48376002)(76176999)(2906002)(97736004)(6916009)(66066001)(5660300001)(8676002)(47776003)(101416001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0201MB2311; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0201MB2311; 23:qtYk7PNcRhrMQLocD+tef1aAgFpoy/B80riExyX?= =?us-ascii?Q?UxWAi+n0HPHN9Tqa07/1piEHomRf/B3ctCTJ9sfyWOyPLYcX5bBDA7qt9ckq?= =?us-ascii?Q?cBCyhylIissb33Tq5WCS7aJNSCt7QMUDusJJ4qesaDBkiJwUsmEW6WYBPnK5?= =?us-ascii?Q?nz0TzpJkFqYQIMobNtMJhVAvzN7fShEhz24hidfM0OXmn6A9LP3xrsqv6Jij?= =?us-ascii?Q?3YhcsWHew7Ka2d51f+6KyWH7MvJNzr02hOGSowJZsD19fYhaOyBpsogoO+EQ?= =?us-ascii?Q?uFyNUjCBWnpll0aVd17VvN+7GQUYsFj+L1DP2pjJB7OHlT6S+9D+iD8NFdYg?= =?us-ascii?Q?foUZaMBdOzwWq+6NbsGisnG44CJHsAjQCyIy/KO99kkm3txqWH2akLebpi3i?= =?us-ascii?Q?FSP9JYW0fHOgXcdmsZ44FpEnNWdJpf2/+i4OF/r7vjRiJQTQ38j56TQ+S1yt?= =?us-ascii?Q?X6UKpWQylO4JE7vHJYRE+c3i9YVuo+aR1qv7IhitCeThCdskWR6zHEwK8OW1?= =?us-ascii?Q?NKZ/CZgsh/wZ99rorn99cOUlpYjsU9BzYNe3WtAwbjx01rqLUl4xfKPi1MxL?= =?us-ascii?Q?qGgUBQaLQrHhkDFMv+nzTGyoXWQgPTceBAlzrBsWtlWGQUMN30iX+xO3W6m5?= =?us-ascii?Q?y3MUQBdy01pU2E8VwzeWmaLnmA+pO2Q7CB/lweXIppgWWRZyQsKvOjOKKiUj?= =?us-ascii?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qmpgGX4yF+cqC8ieOh80D3upT45; 5:S64feXbmWz3kLd7dApRM/+zFzWGx6JKmhY4InQTftxTdSvBv/C6o8PyNg+6DQo4L+7U1WU6TzUHP8pjA4yMvOGznjQJtU6Kx8+GgQc4S7Vizg7uyvTTLAS2iVpFTQlEsInuYLowjOkdDkQK6hUl4xw==; 24:sIN/9zj/8hS23pNzqehcrKod3ph2aKU/WntaEg0Kfa7DSL6cI7U449759vCKPgqiWdzGzfAfm4BbblIsSwJ1vEubAt5Qao7P7Rq+iM+I1SM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2311; 7:u/iHIaH9OtDjtzKOJbqNjuk2PnM/IuCKV7wdTBnpmHduBfeIUGMGh+8f8WPg6KXHe8hyIRKYMaDyuvuuksLAoa14Y3fk6OIhfQDSFC1klCPCmcej376RkjjHLkhiTdSItUmWXj/20pNuKZmJ/Xk5Mw8fY4I92qhkuxxEYUUNmQeWv1lO41gmiubCQpZjn25qJc8EthgvLjfVbpmz/dL8Vtgta8sotgdjvRgIvgsttYJFxOuJT/FmtpQZ4mU8uNsriE4Yyr78n+yZfbXolRoy/2V+jtTY6a5etMCo2F73ucfw1G3dWV+8XT93ksnU9YheZJSZzs8wf8myJZ8/joeyCqz8nPwblskcT1zKV4gIg2KvB67+mnSeMpYg8hU4YDhftgvMlbpN52vgzXyrcpd3nLZcCXRI5GTf8qd+toQSWyHcoIwekO0uCT3NNzJhFKXYHE08shpJkwJ3w9psL17FSg== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2016 09:29:48.6791 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0201MB2311 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the ac-detect gpio does not support interrupts, provide a fallback to poll the gpio at a configurable interval. Signed-off-by: Peter Rosin Acked-by: Rob Herring --- v2 -> v3 changes: - use device_property_read_u32 instead of of_property_read_u32 v1 -> v2 changes: - use poll-interval instead of ti,poll-interval-ms in the bindings Cheers, peda .../bindings/power/supply/ti,bq24735.txt | 2 + drivers/power/supply/bq24735-charger.c | 49 +++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/ti,bq24735.txt b/Documentation/devicetree/bindings/power/supply/ti,bq24735.txt index 3bf55757ceec..799d0e5d6f26 100644 --- a/Documentation/devicetree/bindings/power/supply/ti,bq24735.txt +++ b/Documentation/devicetree/bindings/power/supply/ti,bq24735.txt @@ -25,6 +25,8 @@ Optional properties : - ti,external-control : Indicates that the charger is configured externally and that the host should not attempt to enable/disable charging or set the charge voltage/current. + - poll-interval : In case 'interrupts' is not specified, poll AC presence + on the ti,ac-detect-gpios GPIO with this interval (milliseconds). Example: diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index 1d5c9206e0ed..8a0242c13b7e 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c @@ -50,6 +50,8 @@ struct bq24735 { struct bq24735_platform *pdata; struct mutex lock; struct gpio_desc *status_gpio; + struct delayed_work poll; + u32 poll_interval; bool charging; }; @@ -209,11 +211,8 @@ static int bq24735_charger_is_charging(struct bq24735 *charger) return !(ret & BQ24735_CHG_OPT_CHARGE_DISABLE); } -static irqreturn_t bq24735_charger_isr(int irq, void *devid) +static void bq24735_update(struct bq24735 *charger) { - struct power_supply *psy = devid; - struct bq24735 *charger = to_bq24735(psy); - mutex_lock(&charger->lock); if (charger->charging && bq24735_charger_is_present(charger)) @@ -223,11 +222,29 @@ static irqreturn_t bq24735_charger_isr(int irq, void *devid) mutex_unlock(&charger->lock); - power_supply_changed(psy); + power_supply_changed(charger->charger); +} + +static irqreturn_t bq24735_charger_isr(int irq, void *devid) +{ + struct power_supply *psy = devid; + struct bq24735 *charger = to_bq24735(psy); + + bq24735_update(charger); return IRQ_HANDLED; } +static void bq24735_poll(struct work_struct *work) +{ + struct bq24735 *charger = container_of(work, struct bq24735, poll.work); + + bq24735_update(charger); + + schedule_delayed_work(&charger->poll, + msecs_to_jiffies(charger->poll_interval)); +} + static int bq24735_charger_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -455,11 +472,32 @@ static int bq24735_charger_probe(struct i2c_client *client, client->irq, ret); return ret; } + } else if (charger->status_gpio) { + ret = device_property_read_u32(&client->dev, "poll-interval", + &charger->poll_interval); + if (ret) + return 0; + if (!charger->poll_interval) + return 0; + + INIT_DELAYED_WORK(&charger->poll, bq24735_poll); + schedule_delayed_work(&charger->poll, + msecs_to_jiffies(charger->poll_interval)); } return 0; } +static int bq24735_charger_remove(struct i2c_client *client) +{ + struct bq24735 *charger = i2c_get_clientdata(client); + + if (charger->poll_interval) + cancel_delayed_work_sync(&charger->poll); + + return 0; +} + static const struct i2c_device_id bq24735_charger_id[] = { { "bq24735-charger", 0 }, {} @@ -478,6 +516,7 @@ static struct i2c_driver bq24735_charger_driver = { .of_match_table = bq24735_match_ids, }, .probe = bq24735_charger_probe, + .remove = bq24735_charger_remove, .id_table = bq24735_charger_id, };