From patchwork Fri Feb 15 12:44:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14872 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A1E2723E2E for ; Fri, 15 Feb 2013 12:46:51 +0000 (UTC) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by fiordland.canonical.com (Postfix) with ESMTP id 44CB2A18715 for ; Fri, 15 Feb 2013 12:46:51 +0000 (UTC) Received: by mail-vc0-f179.google.com with SMTP id gb23so2079752vcb.38 for ; Fri, 15 Feb 2013 04:46:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=T90RYck8/Q6PZg6kFc3yJC1gtJdc5w/VPWwPeDBgugw=; b=XpbnXHARsCTYnITkTBsFToUfACVZKh21CbrhaUN6Rnn1ygINCyYVfrg58kbfSOugrP 9v5TsTop9rnRTnJlANrVP9xaBt3h588jSvVMc9XqHWBh9Ih1pNLDjXNb6OcOj+axp9Fo kKTz9Yjjcwb80p60/Y9vMKfDpre/j1bOcWGcKZXbCGiVWHe16+D5L8JA8td4Yrv54IGz h0Zk+fpQaM0OAa6tKSr46txxmDkCSN+zg0mo9+DNba8h+pOleQrrp0N2Oq4W9SXWE1+V Oj9NmVo0y+f8wuuTuPQIO3J+WM1v91VrLAU5ukbZCSXF2AUTt6p6+w+p4YERL61fM1B9 Qv6Q== X-Received: by 10.58.186.241 with SMTP id fn17mr3021611vec.8.1360932410772; Fri, 15 Feb 2013 04:46:50 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp10889vcb; Fri, 15 Feb 2013 04:46:46 -0800 (PST) X-Received: by 10.194.238.226 with SMTP id vn2mr3975404wjc.23.1360932405870; Fri, 15 Feb 2013 04:46:45 -0800 (PST) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by mx.google.com with ESMTPS id k10si19385695wjb.118.2013.02.15.04.46.45 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.182 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.182; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.182 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f182.google.com with SMTP id hi18so1103357wib.9 for ; Fri, 15 Feb 2013 04:46:45 -0800 (PST) X-Received: by 10.194.77.129 with SMTP id s1mr4042150wjw.17.1360932403494; Fri, 15 Feb 2013 04:46:43 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id bs6sm5133904wib.4.2013.02.15.04.46.41 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:42 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, linus.walleij@stericsson.com, cbouatmailru@gmail.com, sameo@linux.intel.com, M BenZoubeir , Lee Jones Subject: [PATCH 28/40] pm2301-charger: Add pm_runtime_resume & pm_runtime_suspend Date: Fri, 15 Feb 2013 12:44:58 +0000 Message-Id: <1360932310-30065-29-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> References: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQmCMQKMZlqPyoHGmg4ZJTJ6S5hF+hvheBkf/O53DjJt7KjW6oY17k27OkqgHng4x8aeinxM From: M BenZoubeir To optimize the current consumption we use pm_runtime autosuspend functions which execute the pm_runtime_suspend after a delay of inactivity on the other hand we use pm_runtime_resume every time we receive an interruption to wake up the pm2301. Signed-off-by: M BenZoubeir Signed-off-by: Lee Jones Reviewed-by: Philippe LANGLAIS --- drivers/power/pm2301_charger.c | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c index 98e27a8..2cc92ec 100644 --- a/drivers/power/pm2301_charger.c +++ b/drivers/power/pm2301_charger.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "pm2301_charger.h" @@ -36,6 +37,7 @@ struct pm2xxx_charger, ac_chg) #define SLEEP_MIN 50 #define SLEEP_MAX 100 +#define PM2XXX_AUTOSUSPEND_DELAY 500 static int pm2xxx_interrupt_registers[] = { PM2XXX_REG_INT1, @@ -493,6 +495,9 @@ static irqreturn_t pm2xxx_irq_int(int irq, void *data) struct pm2xxx_interrupts *interrupt = pm2->pm2_int; int i; + /* wake up the device */ + pm_runtime_get_sync(pm2->dev); + do { for (i = 0; i < PM2XXX_NUM_INT_REG; i++) { pm2xxx_reg_read(pm2, @@ -504,6 +509,9 @@ static irqreturn_t pm2xxx_irq_int(int irq, void *data) } } while (gpio_get_value(pm2->pdata->gpio_irq_number) == 0); + pm_runtime_mark_last_busy(pm2->dev); + pm_runtime_put_autosuspend(pm2->dev); + return IRQ_HANDLED; } @@ -946,6 +954,53 @@ static int pm2xxx_wall_charger_suspend(struct i2c_client *i2c_client, return 0; } +#ifdef CONFIG_PM +static int pm2xxx_runtime_suspend(struct device *dev) +{ + struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); + struct pm2xxx_charger *pm2; + int ret = 0; + + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); + if (!pm2) { + dev_err(pm2->dev, "no pm2xxx_charger data supplied\n"); + ret = -EINVAL; + return ret; + } + + clear_lpn_pin(pm2); + + return ret; +} + +static int pm2xxx_runtime_resume(struct device *dev) +{ + struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev); + struct pm2xxx_charger *pm2; + int ret = 0; + + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client); + if (!pm2) { + dev_err(pm2->dev, "no pm2xxx_charger data supplied\n"); + ret = -EINVAL; + return ret; + } + + if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0) + set_lpn_pin(pm2); + + return ret; +} + +static const struct dev_pm_ops pm2xxx_pm_ops = { + .runtime_suspend = pm2xxx_runtime_suspend, + .runtime_resume = pm2xxx_runtime_resume, +}; +#define PM2XXX_PM_OPS (&pm2xxx_pm_ops) +#else +#define PM2XXX_PM_OPS NULL +#endif + static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, const struct i2c_device_id *id) { @@ -1077,6 +1132,16 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, gpio_to_irq(pm2->pdata->gpio_irq_number), ret); goto unregister_pm2xxx_charger; } + + ret = pm_runtime_set_active(pm2->dev); + if (ret) + dev_err(pm2->dev, "set active Error\n"); + + pm_runtime_enable(pm2->dev); + pm_runtime_set_autosuspend_delay(pm2->dev, PM2XXX_AUTOSUSPEND_DELAY); + pm_runtime_use_autosuspend(pm2->dev); + pm_runtime_resume(pm2->dev); + /* pm interrupt can wake up system */ ret = enable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number)); if (ret) { @@ -1148,6 +1213,8 @@ static int __devexit pm2xxx_wall_charger_remove(struct i2c_client *i2c_client) { struct pm2xxx_charger *pm2 = i2c_get_clientdata(i2c_client); + /* Disable pm_runtime */ + pm_runtime_disable(pm2->dev); /* Disable AC charging */ pm2xxx_charger_ac_en(&pm2->ac_chg, false, 0, 0); @@ -1189,6 +1256,7 @@ static struct i2c_driver pm2xxx_charger_driver = { .driver = { .name = "pm2xxx-wall_charger", .owner = THIS_MODULE, + .pm = PM2XXX_PM_OPS, }, .id_table = pm2xxx_id, };