From patchwork Tue Sep 15 14:31:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Irina Tirdea X-Patchwork-Id: 7186121 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3E8F0BEEC1 for ; Tue, 15 Sep 2015 14:35:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 50382203E6 for ; Tue, 15 Sep 2015 14:35:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85A71203F3 for ; Tue, 15 Sep 2015 14:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753498AbbIOOfW (ORCPT ); Tue, 15 Sep 2015 10:35:22 -0400 Received: from mga11.intel.com ([192.55.52.93]:58671 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752043AbbIOOfU (ORCPT ); Tue, 15 Sep 2015 10:35:20 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 15 Sep 2015 07:35:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,536,1437462000"; d="scan'208";a="805620448" Received: from itirdea-desk.rb.intel.com ([10.237.104.230]) by fmsmga002.fm.intel.com with ESMTP; 15 Sep 2015 07:35:17 -0700 From: Irina Tirdea To: Dmitry Torokhov , Bastien Nocera , Aleksei Mamlin , linux-input@vger.kernel.org Cc: Mark Rutland , Octavian Purdila , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Irina Tirdea Subject: [PATCH v6 9/9] Input: goodix - add runtime power management support Date: Tue, 15 Sep 2015 17:31:23 +0300 Message-Id: <1442327483-19407-10-git-send-email-irina.tirdea@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442327483-19407-1-git-send-email-irina.tirdea@intel.com> References: <1442327483-19407-1-git-send-email-irina.tirdea@intel.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for runtime power management so that the device is turned off when not used (when the userspace holds no open handles of the input device). The device uses autosuspend with a default delay of 2 seconds, so the device will suspend if no handles to it are open for 2 seconds. The runtime management support is only available if the gpio pins are properly initialized from ACPI/DT. Signed-off-by: Irina Tirdea --- drivers/input/touchscreen/goodix.c | 63 +++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index 641a9e3..a0b6067 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,8 @@ struct goodix_ts_data { #define MAX_CONTACTS_LOC 5 #define TRIGGER_LOC 6 +#define GOODIX_AUTOSUSPEND_DELAY_MS 2000 + static const unsigned long goodix_irq_flags[] = { IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, @@ -566,6 +569,33 @@ static const struct attribute_group goodix_attr_group = { .attrs = goodix_attrs, }; +static int goodix_open(struct input_dev *input_dev) +{ + struct goodix_ts_data *ts = input_get_drvdata(input_dev); + int error; + + if (!ts->gpiod_int || !ts->gpiod_rst) + return 0; + + error = pm_runtime_get_sync(&ts->client->dev); + if (error < 0) { + pm_runtime_put_noidle(&ts->client->dev); + return error; + } + return 0; +} + +static void goodix_close(struct input_dev *input_dev) +{ + struct goodix_ts_data *ts = input_get_drvdata(input_dev); + + if (!ts->gpiod_int || !ts->gpiod_rst) + return; + + pm_runtime_mark_last_busy(&ts->client->dev); + pm_runtime_put_autosuspend(&ts->client->dev); +} + /** * goodix_get_gpio_config - Get GPIO config from ACPI/DT * @@ -751,6 +781,9 @@ static int goodix_request_input_dev(struct goodix_ts_data *ts) ts->input_dev->id.vendor = 0x0416; ts->input_dev->id.product = ts->id; ts->input_dev->id.version = ts->version; + ts->input_dev->open = goodix_open; + ts->input_dev->close = goodix_close; + input_set_drvdata(ts->input_dev, ts); error = input_register_device(ts->input_dev); if (error) { @@ -798,7 +831,8 @@ static int goodix_configure_dev(struct goodix_ts_data *ts) * @ts: our goodix_ts_data pointer * * request_firmware_wait callback that finishes - * initialization of the device. + * initialization of the device. This will only be called + * when ts->gpiod_int and ts->gpiod_rst are properly initialized. */ static void goodix_config_cb(const struct firmware *cfg, void *ctx) { @@ -811,7 +845,21 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx) if (error) goto err_release_cfg; } - goodix_configure_dev(ts); + error = goodix_configure_dev(ts); + if (error) + goto err_release_cfg; + + error = pm_runtime_set_active(&ts->client->dev); + if (error) { + dev_err(&ts->client->dev, "failed to set active: %d\n", error); + goto err_release_cfg; + } + /* input_dev is a child of client->dev, ignore it for runtime pm */ + pm_suspend_ignore_children(&ts->client->dev, true); + pm_runtime_enable(&ts->client->dev); + pm_runtime_set_autosuspend_delay(&ts->client->dev, + GOODIX_AUTOSUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(&ts->client->dev); err_release_cfg: release_firmware(cfg); @@ -919,8 +967,12 @@ static int goodix_ts_remove(struct i2c_client *client) { struct goodix_ts_data *ts = i2c_get_clientdata(client); - if (ts->gpiod_int && ts->gpiod_rst) + if (ts->gpiod_int && ts->gpiod_rst) { + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + pm_runtime_put_noidle(&client->dev); sysfs_remove_group(&client->dev.kobj, &goodix_attr_group); + } goodix_disable_esd(ts); kfree(ts->cfg_name); return 0; @@ -994,7 +1046,10 @@ static int __maybe_unused goodix_resume(struct device *dev) return goodix_enable_esd(ts); } -static SIMPLE_DEV_PM_OPS(goodix_pm_ops, goodix_suspend, goodix_resume); +static const struct dev_pm_ops goodix_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(goodix_suspend, goodix_resume) + SET_RUNTIME_PM_OPS(goodix_suspend, goodix_resume, NULL) +}; static const struct i2c_device_id goodix_ts_id[] = { { "GDIX1001:00", 0 },