From patchwork Thu Jul 1 07:53:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 109013 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o617rTkR025862 for ; Thu, 1 Jul 2010 07:53:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751180Ab0GAHx2 (ORCPT ); Thu, 1 Jul 2010 03:53:28 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:63511 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456Ab0GAHx1 (ORCPT ); Thu, 1 Jul 2010 03:53:27 -0400 Received: by pvc7 with SMTP id 7so703730pvc.19 for ; Thu, 01 Jul 2010 00:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=IuF8fgnJMHdWOFkL/sw2pSPS+AVVMBmdkoQwvCQgXfg=; b=u9roWtwxwZW0NqOVvb/ktCL/qyIuzzGbAkWdfDJwnWzkPG5lw1DPnj9pi38X0agvvJ U/BE6erEjD/iBlgfwW2H/LBsqCiOKP/3VwcovrWQTZ5S7v20r7gfgvT0U/GjXks3KOFS 3gi4vy5yeMp7XkNYCJlnPSZpnsmaOgekqkBJQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=sosXQ6qdjXbuVus4HpahwiMWcrhRGipuquX4J7w6E+l7ugO8vdrQlqnY4Z3ateVIXk pyTTsmhHBGZpQqZeyoCZVfWF836TlaxKTrihjqyyjt8sug0hf9K8JxMkrVN+bKMRBZ5f 852K4vDDKqY71owoYoKrPu6pRAgO/cBqvw6DU= Received: by 10.143.85.4 with SMTP id n4mr11553909wfl.312.1277970805488; Thu, 01 Jul 2010 00:53:25 -0700 (PDT) Received: from mailhub.coreip.homeip.net (c-24-6-153-206.hsd1.ca.comcast.net [24.6.153.206]) by mx.google.com with ESMTPS id i19sm6775426rvn.4.2010.07.01.00.53.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 01 Jul 2010 00:53:20 -0700 (PDT) Date: Thu, 1 Jul 2010 00:53:16 -0700 From: Dmitry Torokhov To: "Hennerich, Michael" Cc: Mike Frysinger , "linux-input@vger.kernel.org" , "uclinux-dist-devel@blackfin.uclinux.org" , Chris Verges , Luotao Fu , "Song, Barry" Subject: Re: [PATCH v3] input/misc: new ADXL345/346 driver Message-ID: <20100701075316.GA14696@core.coreip.homeip.net> References: <1255517680-30733-1-git-send-email-vapier@gentoo.org> <1256028039-15044-1-git-send-email-vapier@gentoo.org> <20100625071425.GA631@core.coreip.homeip.net> <544AC56F16B56944AEC3BD4E3D5917712E66DFEF69@LIMKCMBX1.ad.analog.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <544AC56F16B56944AEC3BD4E3D5917712E66DFEF69@LIMKCMBX1.ad.analog.com> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 01 Jul 2010 07:53:31 +0000 (UTC) diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c index 76194b5..b1b8df3 100644 --- a/drivers/input/misc/adxl34x-i2c.c +++ b/drivers/input/misc/adxl34x-i2c.c @@ -105,26 +105,26 @@ static int __devexit adxl34x_i2c_remove(struct i2c_client *client) } #ifdef CONFIG_PM -static int adxl34x_suspend(struct i2c_client *client, pm_message_t message) +static int adxl34x_i2c_suspend(struct i2c_client *client, pm_message_t message) { struct adxl34x *ac = i2c_get_clientdata(client); - adxl34x_disable(ac); + adxl34x_suspend(ac); return 0; } -static int adxl34x_resume(struct i2c_client *client) +static int adxl34x_i2c_resume(struct i2c_client *client) { struct adxl34x *ac = i2c_get_clientdata(client); - adxl34x_enable(ac); + adxl34x_resume(ac); return 0; } #else -# define adxl34x_suspend NULL -# define adxl34x_resume NULL +# define adxl34x_i2c_suspend NULL +# define adxl34x_i2c_resume NULL #endif static const struct i2c_device_id adxl34x_id[] = { @@ -141,8 +141,8 @@ static struct i2c_driver adxl34x_driver = { }, .probe = adxl34x_i2c_probe, .remove = __devexit_p(adxl34x_i2c_remove), - .suspend = adxl34x_suspend, - .resume = adxl34x_resume, + .suspend = adxl34x_i2c_suspend, + .resume = adxl34x_i2c_resume, .id_table = adxl34x_id, }; diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c index 7f99235..782de9e 100644 --- a/drivers/input/misc/adxl34x-spi.c +++ b/drivers/input/misc/adxl34x-spi.c @@ -94,26 +94,26 @@ static int __devexit adxl34x_spi_remove(struct spi_device *spi) } #ifdef CONFIG_PM -static int adxl34x_suspend(struct spi_device *spi, pm_message_t message) +static int adxl34x_spi_suspend(struct spi_device *spi, pm_message_t message) { struct adxl34x *ac = dev_get_drvdata(&spi->dev); - adxl34x_disable(ac); + adxl34x_suspend(ac); return 0; } -static int adxl34x_resume(struct spi_device *spi) +static int adxl34x_spi_resume(struct spi_device *spi) { struct adxl34x *ac = dev_get_drvdata(&spi->dev); - adxl34x_enable(ac); + adxl34x_resume(ac); return 0; } #else -# define adxl34x_suspend NULL -# define adxl34x_resume NULL +# define adxl34x_spi_suspend NULL +# define adxl34x_spi_resume NULL #endif static struct spi_driver adxl34x_driver = { @@ -124,8 +124,8 @@ static struct spi_driver adxl34x_driver = { }, .probe = adxl34x_spi_probe, .remove = __devexit_p(adxl34x_spi_remove), - .suspend = adxl34x_suspend, - .resume = adxl34x_resume, + .suspend = adxl34x_spi_suspend, + .resume = adxl34x_spi_resume, }; static int __init adxl34x_spi_init(void) diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c index 77fb409..2706ea0 100644 --- a/drivers/input/misc/adxl34x.c +++ b/drivers/input/misc/adxl34x.c @@ -200,6 +200,7 @@ struct adxl34x { unsigned orient3d_saved; bool disabled; /* P: mutex */ bool opened; /* P: mutex */ + bool suspended; /* P: mutex */ bool fifo_delay; int irq; unsigned model; @@ -399,41 +400,44 @@ static irqreturn_t adxl34x_irq(int irq, void *handle) static void __adxl34x_disable(struct adxl34x *ac) { - if (!ac->disabled && ac->opened) { - /* - * A '0' places the ADXL34x into standby mode - * with minimum power consumption. - */ - AC_WRITE(ac, POWER_CTL, 0); - - ac->disabled = true; - } + /* + * A '0' places the ADXL34x into standby mode + * with minimum power consumption. + */ + AC_WRITE(ac, POWER_CTL, 0); } static void __adxl34x_enable(struct adxl34x *ac) { - if (ac->disabled && ac->opened) { - AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); - ac->disabled = false; - } + AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); } -void adxl34x_disable(struct adxl34x *ac) +void adxl34x_suspend(struct adxl34x *ac) { mutex_lock(&ac->mutex); - __adxl34x_disable(ac); + + if (!ac->suspended && !ac->disabled && ac->opened) + __adxl34x_disable(ac); + + ac->suspended = true; + mutex_unlock(&ac->mutex); } -EXPORT_SYMBOL_GPL(adxl34x_disable); +EXPORT_SYMBOL_GPL(adxl34x_suspend); -void adxl34x_enable(struct adxl34x *ac) +void adxl34x_resume(struct adxl34x *ac) { mutex_lock(&ac->mutex); - __adxl34x_enable(ac); + + if (ac->suspended && !ac->disabled && ac->opened) + __adxl34x_enable(ac); + + ac->suspended= false; + mutex_unlock(&ac->mutex); } -EXPORT_SYMBOL_GPL(adxl34x_enable); +EXPORT_SYMBOL_GPL(adxl34x_resume); static ssize_t adxl34x_disable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -455,10 +459,21 @@ static ssize_t adxl34x_disable_store(struct device *dev, if (error) return error; - if (val) - adxl34x_disable(ac); - else - adxl34x_enable(ac); + mutex_lock(&ac->mutex); + + if (!ac->suspended && ac->opened) { + if (val) { + if (!ac->disabled) + __adxl34x_disable(ac); + } else { + if (ac->disabled) + __adxl34x_enable(ac); + } + } + + ac->disabled = !!val; + + mutex_unlock(&ac->mutex); return count; } @@ -499,7 +514,6 @@ static ssize_t adxl34x_calibrate_store(struct device *dev, ac->hwcal.y -= (ac->saved.y / 4); ac->swcal.y = ac->saved.y % 4; - ac->hwcal.z -= (ac->saved.z / 4); ac->swcal.z = ac->saved.z % 4; AC_WRITE(ac, OFSX, (s8) ac->hwcal.x); @@ -575,7 +589,7 @@ static ssize_t adxl34x_autosleep_store(struct device *dev, else ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK); - if (!ac->disabled && ac->opened) + if (!ac->disabled && !ac->suspended && ac->opened) AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE); mutex_unlock(&ac->mutex); @@ -649,8 +663,12 @@ static int adxl34x_input_open(struct input_dev *input) struct adxl34x *ac = input_get_drvdata(input); mutex_lock(&ac->mutex); + + if (!ac->suspended && !ac->disabled) + __adxl34x_enable(ac); + ac->opened = true; - __adxl34x_enable(ac); + mutex_unlock(&ac->mutex); return 0; @@ -661,8 +679,12 @@ static void adxl34x_input_close(struct input_dev *input) struct adxl34x *ac = input_get_drvdata(input); mutex_lock(&ac->mutex); - __adxl34x_disable(ac); + + if (!ac->suspended && !ac->disabled) + __adxl34x_disable(ac); + ac->opened = false; + mutex_unlock(&ac->mutex); } @@ -878,7 +900,6 @@ EXPORT_SYMBOL_GPL(adxl34x_probe); int adxl34x_remove(struct adxl34x *ac) { - adxl34x_disable(ac); sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group); free_irq(ac->irq, ac); input_unregister_device(ac->input); diff --git a/drivers/input/misc/adxl34x.h b/drivers/input/misc/adxl34x.h index ea9093c..bbbc80f 100644 --- a/drivers/input/misc/adxl34x.h +++ b/drivers/input/misc/adxl34x.h @@ -20,8 +20,8 @@ struct adxl34x_bus_ops { int (*write)(struct device *, unsigned char, unsigned char); }; -void adxl34x_disable(struct adxl34x *ac); -void adxl34x_enable(struct adxl34x *ac); +void adxl34x_suspend(struct adxl34x *ac); +void adxl34x_resume(struct adxl34x *ac); struct adxl34x *adxl34x_probe(struct device *dev, int irq, bool fifo_delay_default, const struct adxl34x_bus_ops *bops);