From patchwork Fri Jun 26 04:20:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 6678251 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CC9079F39B for ; Fri, 26 Jun 2015 04:19:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CD738206B1 for ; Fri, 26 Jun 2015 04:19:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7C00206E8 for ; Fri, 26 Jun 2015 04:19:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbbFZETX (ORCPT ); Fri, 26 Jun 2015 00:19:23 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:35142 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751999AbbFZETW (ORCPT ); Fri, 26 Jun 2015 00:19:22 -0400 Received: by pactm7 with SMTP id tm7so61419750pac.2; Thu, 25 Jun 2015 21:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AwbYgnUBd4tJhRbRQh8UOuX8WYCyLGSneUTpsEmSbEM=; b=kRloSmfG/TUD875kjXff8eXXG9s53YLl5G/Tvq8eSalbXFlXmm135LEWkDuOyoqQJL HqO/i3oAQByowbYqJh8f1zls8ABJ/D61+hcCu13Aip5hhsEjgPqcvPNqMC5k4bwdsCNz 9HE/NgR/S8h8B2oEhDcbPlT3xBixvsRzfuVN2NCAEOuCMBTUqg9USAb0aj7IX48HbhqA qdNQHR9zqHl0ogGdf12UUb6T4OUQh2/qgz9jD3b2HOiWLCruw+BOHswRgaXfMSSGxDyN o4R+DJvHE6wG7qAbfuXt7MoTzJ+vy0qefgyT4mIm4Z1j+dfYQTWR1pKWCN1O0Ep9+9FL X7Jg== X-Received: by 10.70.20.5 with SMTP id j5mr98081766pde.40.1435292361632; Thu, 25 Jun 2015 21:19:21 -0700 (PDT) Received: from localhost.localdomain (c-76-105-208-73.hsd1.or.comcast.net. [76.105.208.73]) by mx.google.com with ESMTPSA id oa14sm31688240pdb.47.2015.06.25.21.19.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jun 2015 21:19:21 -0700 (PDT) From: Matt Ranostay To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-pm@vger.kernel.org, Matt Ranostay Subject: [PATCH v2 1/1] cap11xx: add runtime PM support Date: Thu, 25 Jun 2015 21:20:23 -0700 Message-Id: <1435292423-20895-2-git-send-email-mranostay@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435292423-20895-1-git-send-email-mranostay@gmail.com> References: <1435292423-20895-1-git-send-email-mranostay@gmail.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=-8.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Puts device into DEEP SLEEP when no LEDs are in in the on-state, and no input_handlers are in use. Also uses *_autosuspend to prevent a LED trigger from constantly suspending and resuming device. Signed-off-by: Matt Ranostay --- drivers/input/keyboard/cap11xx.c | 84 +++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index b983b5a..51aad6d 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -84,9 +85,9 @@ struct cap11xx_led { struct cap11xx_priv { struct regmap *regmap; struct input_dev *idev; + struct i2c_client *i2c_client; struct cap11xx_led *leds; - int num_leds; /* config */ u32 keycodes[]; @@ -205,32 +206,34 @@ out: return IRQ_HANDLED; } +#ifdef CONFIG_PM static int cap11xx_set_sleep(struct cap11xx_priv *priv, bool sleep) { -#ifdef CONFIG_LEDS_CLASS - /* - * DLSEEP mode will turn off all LEDS, prevent this - */ - if (priv->num_leds) - return 0; -#endif return regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, CAP11XX_REG_MAIN_CONTROL_DLSEEP, sleep ? CAP11XX_REG_MAIN_CONTROL_DLSEEP : 0); } +#else +static int cap11xx_set_sleep(struct cap11xx_priv *priv, bool sleep) +{ + return 0; +} +#endif static int cap11xx_input_open(struct input_dev *idev) { struct cap11xx_priv *priv = input_get_drvdata(idev); - return cap11xx_set_sleep(priv, false); + pm_runtime_get(&priv->i2c_client->dev); + + return 0; } static void cap11xx_input_close(struct input_dev *idev) { struct cap11xx_priv *priv = input_get_drvdata(idev); - cap11xx_set_sleep(priv, true); + pm_runtime_put_autosuspend(&priv->i2c_client->dev); } #ifdef CONFIG_LEDS_CLASS @@ -252,10 +255,16 @@ static void cap11xx_led_set(struct led_classdev *cdev, enum led_brightness value) { struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev); + struct cap11xx_priv *priv = led->priv; if (led->new_brightness == value) return; + if (value) + pm_runtime_get(&priv->i2c_client->dev); + else + pm_runtime_put_autosuspend(&priv->i2c_client->dev); + led->new_brightness = value; schedule_work(&led->work); } @@ -312,7 +321,6 @@ static int cap11xx_init_leds(struct device *dev, error = devm_led_classdev_register(dev, &led->cdev); if (error < 0) return -EINVAL; - priv->num_leds++; led++; }; @@ -446,17 +454,23 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client, priv->idev->open = cap11xx_input_open; priv->idev->close = cap11xx_input_close; - error = cap11xx_init_leds(dev, priv, cap->num_leds); + error = cap11xx_set_sleep(priv, true); if (error) return error; - input_set_drvdata(priv->idev, priv); + error = pm_runtime_set_active(dev); + if (error) + return error; - /* - * Put the device in deep sleep mode for now. - * ->open() will bring it back once the it is actually needed. - */ - cap11xx_set_sleep(priv, true); + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); + + error = cap11xx_init_leds(dev, priv, cap->num_leds); + if (error) + return error; + priv->i2c_client = i2c_client; + input_set_drvdata(priv->idev, priv); error = input_register_device(priv->idev); if (error) @@ -476,6 +490,17 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client, return 0; } +static int cap11xx_i2c_remove(struct i2c_client *i2c_client) +{ + struct cap11xx_priv *priv = i2c_get_clientdata(i2c_client); + + pm_runtime_disable(&i2c_client->dev); + pm_runtime_set_suspended(&i2c_client->dev); + cap11xx_set_sleep(priv, true); + + return 0; +} + static const struct of_device_id cap11xx_dt_ids[] = { { .compatible = "microchip,cap1106", }, { .compatible = "microchip,cap1126", }, @@ -492,14 +517,37 @@ static const struct i2c_device_id cap11xx_i2c_ids[] = { }; MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids); +#ifdef CONFIG_PM +static int cap11xx_runtime_suspend(struct device *dev) +{ + struct cap11xx_priv *priv = i2c_get_clientdata(to_i2c_client(dev)); + + return cap11xx_set_sleep(priv, true); +} + +static int cap11xx_runtime_resume(struct device *dev) +{ + struct cap11xx_priv *priv = i2c_get_clientdata(to_i2c_client(dev)); + + return cap11xx_set_sleep(priv, false); +} +#endif + +static const struct dev_pm_ops cap11xx_pm_ops = { + SET_RUNTIME_PM_OPS(cap11xx_runtime_suspend, + cap11xx_runtime_resume, NULL) +}; + static struct i2c_driver cap11xx_i2c_driver = { .driver = { .name = "cap11xx", .owner = THIS_MODULE, .of_match_table = cap11xx_dt_ids, + .pm = &cap11xx_pm_ops, }, .id_table = cap11xx_i2c_ids, .probe = cap11xx_i2c_probe, + .remove = cap11xx_i2c_remove, }; module_i2c_driver(cap11xx_i2c_driver);