From patchwork Mon Dec 12 11:00:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 9470743 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 AC8BD60573 for ; Mon, 12 Dec 2016 13:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB31C28113 for ; Mon, 12 Dec 2016 13:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FF0028480; Mon, 12 Dec 2016 13:33:50 +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 0C3D128113 for ; Mon, 12 Dec 2016 13:33:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752684AbcLLNdt (ORCPT ); Mon, 12 Dec 2016 08:33:49 -0500 Received: from mail-db5eur01on0096.outbound.protection.outlook.com ([104.47.2.96]:37191 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752674AbcLLNds (ORCPT ); Mon, 12 Dec 2016 08:33:48 -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=pfHxiVp253WdFaLnCGAn9M3W3mAJYEBefgqsesu1mcc=; b=VTubizFM/sluDbu5Dq1V1iblvqvdL1u54ovrP+hroFlEuLqSDW+2cQjXlxFIRg+qtAkYr+U+nVhoaZTilWA5AgJgveKdcZ5P+UN6/TBi3Ge7oRQ7N5v6HpZg+OkbACqUqSwrvPwlZ2rhW19gT2kRsAmK4zz5XGXwDlvZWRdm3wA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Received: from localhost.localdomain (217.210.101.82) by DB6PR0201MB2309.eurprd02.prod.outlook.com (10.169.222.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Mon, 12 Dec 2016 11:01:04 +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 2/3] power: supply: bq24735-charger: optionally poll the ac-detect gpio Date: Mon, 12 Dec 2016 12:00:23 +0100 Message-Id: <1481540424-19293-3-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481540424-19293-1-git-send-email-peda@axentia.se> References: <1481540424-19293-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB6PR0701CA0027.eurprd07.prod.outlook.com (10.168.7.165) To DB6PR0201MB2309.eurprd02.prod.outlook.com (10.169.222.148) X-MS-Office365-Filtering-Correlation-Id: fcfb606a-c27b-4b4b-571b-08d4227e2b59 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB6PR0201MB2309; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2309; 3:7dloKpOuhQKPpaGUlZ6ZrxVcMIIjVEkt77QceQyFiVcpCQHeeSrC5Wi23IbSDbrATEMIwlurielITWQBB2Yp4GUSJ8dtbnA4ZOD5wMei+V5ZtuJzrTN5EFP6TCk6qjH9YxJe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nAedA+CWveJFdrVFChC6ZL9sqaNVm4eymR7+YjzQfbxLHmkIxqsQrR7IgqFzECGvit+4od5AEgJLQp28NgqPwGCP2rFJHYMM2QnYnz9Iw9j1+5rCPtXFYp3odubUOCL+stt39/V6gGN6u2mhi40zqCqE22CTuhBD1cPRsqa6+dKEPqH1N4utWgWNC0I05tZa+FarfY1WqqUEbP+XCIkYvVTZbBergEnHdZHaIutdfdfmV6PRVr61HA7nIrpzlo+7LJ7wDg4mNH0RmlxHOeVlXjYlD2XSpz28FhqgtrSHNkgVOYEvcM8wQhMZHfsxPlJAZ/2kuSQUZHq/ByGMV3bEs30ILnpRdGcGUjBEOfw3OLEWvYWEyCnJnj0GejMt5qkTSzFjvbSLyF6irxIpHnGPy0bi9QRz8xLIQuxt8637ZVChEO8I6HLDy35BA/IFabga6nYKcSdfrp1IXUOXEsZxG0fYHn0j5Amtt6Gg X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(2016111802025)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(6043046)(6072148); SRVR:DB6PR0201MB2309; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0201MB2309; X-Forefront-PRVS: 0154C61618 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(39830400002)(39410400002)(189002)(199003)(36756003)(2950100002)(5660300001)(48376002)(97736004)(50466002)(2361001)(7736002)(575784001)(68736007)(106356001)(86362001)(305945005)(76176999)(105586002)(2906002)(92566002)(50986999)(74482002)(50226002)(5003940100001)(6916009)(8676002)(6512006)(42186005)(33646002)(189998001)(2351001)(81166006)(4326007)(6506006)(81156014)(6486002)(110136003)(3846002)(6116002)(66066001)(38730400001)(47776003)(101416001)(6666003)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0201MB2309; 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; DB6PR0201MB2309; 23:WDuDAlYdihm8lrz9xdC/RA29WlnezxtSwWn6www?= =?us-ascii?Q?hFPwU6rPJTwvz82vRC8LvKOIbMH9IyIgk+DL/uKRZ67PGMHSRGSgfYIGQMx/?= =?us-ascii?Q?H29Hx9q8xvzESCRmY52fwBtmkeb5FRzGPhTe4QHiQGKifX9O0matNt3NzjdB?= =?us-ascii?Q?URYGj0CWcXzIM5L65ahMp71cBBOjqTtARB2oWm7tAbPBlPKbfHJtmy6KT+I2?= =?us-ascii?Q?Lf3OwvV1FD2HXcD5grtgPis9BvwzXo+Glwx9XUft4nTFliZChRcbtcZjFCuy?= =?us-ascii?Q?rraFnq8AxfIbDMe9nhWGlpn2E77HiwiYO0gMPTBRIxmYKNDWtq9EdIhrysfz?= =?us-ascii?Q?/RsB4F974vfhcXUhJFIH04OFvhCh3PmRt5WHV2neqENv5GF7doIxp3seUXEB?= =?us-ascii?Q?6YJUbD0kGAIzLIe5yyJOe4TsGUPcXZMiP3H2eJPE1Coyx/mP5bc9yKhIMdTq?= =?us-ascii?Q?kU6n5YANE/P/q+QdlDlIXdujT6dpRNRZax3KNRArgDYr91Yq6GfrYs1SVsZ9?= =?us-ascii?Q?n9ruo0M09cj3punm26X1Fs2AySIpzmYjCgB3DXnlTEtRXooEAXjfUNF9ojCW?= =?us-ascii?Q?v1Eo3JnHAfsSPXK0b4gI52sBhvE/WxQf+NpEZ7eSVAdzQhWWxTGOdLGMKfLY?= =?us-ascii?Q?E2QJj4mPB7K3G1A9p/dyTQz60OtTuVWvi8s3pLC3ArSSKcDy3h4s4ryj7sRJ?= =?us-ascii?Q?/XKei0AaLCcSUziRzqu1nMXjR/JHTXT+u/b+IF8R3Lcnkpc3MKpaEoX3wssk?= =?us-ascii?Q?xqiX4I9pS9FVFxcppYAxJW+YLB3aU+iBU05rCrSJtMGXdFCS2porYFtDT0VJ?= =?us-ascii?Q?IrPLeE3ncgHGLzDRcarLYVDSDMp+W+aRoTJpFVSzEFUNyFXLBSvkUzu0qU9v?= =?us-ascii?Q?U93GdLiDfAERjyeKA+o6Zat5eznu6t1YDr/8F4lB7/iK7B6fSzLjYHd3mSk4?= =?us-ascii?Q?miQQd/2xlhi+eveXQ3uS50lhzCVkjLYiZPveg9rDv9kK8QGzo4tIZsnwY60v?= =?us-ascii?Q?3pOFE0FpIFbuTORK7T5tfDzUJnivxWtQloJsYdQIUjcoVaMigJ+c8LySjaNa?= =?us-ascii?Q?cFayN1NPQ33wIpadqadYmYWmcD+LaDeAiSPkoVHQWiVoDEfDTR7i8WivH52x?= =?us-ascii?Q?fvH828DFMO609H+B6EM74V2MfsXhIgs/2h5JcJUpOVHggAvpvDass4OEZUni?= =?us-ascii?Q?LRJrvp1pgcoaKTfaQQuQcsDQbagdije8IdanGTkOMI+vSbYnmjhJanYo0rQ?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2309; 6:8o3kUHUq4Lg3mVJKECvwFwNFTv/U22zweIvMngQs3sIqkCh+l+VW4u/EusZFmWNerRS1l4ICIA4wY4l5K0Vtc9egVE3Jt1vAU2QIqFhunIkjfpNLVlPMP911aH7tU5qGmw4DqSiFmXoF7/ajq2/DnEIv/2Q64wtgFaFcKGwc4bvmSIHj43YUgsUiGb8pVd+mVh+S/Xx+TUzVA7ANzQWGjEfE8WdqZfMpolHNO8glsPQWX5iyuDY40Z5b2r0jnB39P6igp/3juH1lrW8epZffzbqtJlRNEFE2LOhDwoSJUGpwVz63iTcnqRDDOb5+A+7gIJpjm3sG5tcgpPmkYzwO2v18KHBYvO1MmBcXz1etRPjh985DZpgUo0WsLXGWKSECta1SX822FY6ozcTt5xRW75htF7UPB13SgKF7fRHD1lcyrLAalgQ/ZW064+XklRqX; 5:wotyDzy2NQx3YRuq4/9BHRUtQHhnXwxouTSGdKve8xsfROnDSlkY/kfHHLhNmmtReFhIhKpcCG9v9v7UnAvXseIUVVN4cVSnFYNZUJwfSmLeDyf1bps6j3E/0XUFYSWJKhFuK2EeITS6bD6/zDENb2s/kytGz/7VFOP8PLt/Vbc=; 24:lbUG6soHUMdAIjzRpw9UrHnL7gBLXh12RPnIkVxihC9QJjo4qlw+whhxMxkIjTBpxg8vY2fbMg4GaMeiVwYYqv1iaflGO+8gZdQx5tmeUi0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0201MB2309; 7:CsBeMT2pP4uAyAvz9/1n2dn9bgC7WPeSQ5Sot0wvBrdeYKbQBysySX1SXTV132Eg8PldsrJFnOTAyj8q5yVdUa4gNb1TOLhE57XAxMkrGbsmbjHjOkY2A3YJCDUrOUBRax05UinWsRVn0LrkKvNqsZ7byDGdqrQENcajEdeyeQ2J4a9XLBkptrWf9sNjOpw9S1e/+wyfpXaDcnlzEssrlnBqAnDayNg9xDMUZc2QIJ6V1hBbZRw8Q01czemqGqiNkllwbifSas9Lc/gYvPpZxBojgejvYjJD5Jh4jI/tHsyyihyoJv2ASV8MxypowZJQG/Yqm7I1wwPL9fYafNv4GKXG5x7Jn5C4vU3jXqFaNPrm1QU8MkoyxDwuiHccbyAwprKszmZCsQbTgQIrcmjTSfrbarICZ8z/TrOEioWdj0hah+SzEKDfKL32AIElRd7qSY5zvMEmsq5NTzoxuw0Lpw== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2016 11:01:04.5804 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0201MB2309 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 --- .../bindings/power/supply/ti,bq24735.txt | 2 + drivers/power/supply/bq24735-charger.c | 50 +++++++++++++++++++--- 2 files changed, 47 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..59c4dde589cf 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. + - ti,poll-interval-ms : In case there is no interrupts specified, poll AC + presense on the ti,ac-detect-gpios GPIO with this interval. Example: diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index 1d5c9206e0ed..3765806d5d46 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,33 @@ static int bq24735_charger_probe(struct i2c_client *client, client->irq, ret); return ret; } + } else if (charger->status_gpio) { + ret = of_property_read_u32(client->dev.of_node, + "ti,poll-interval-ms", + &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 +517,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, };