From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Hennerich, Michael" <Michael.Hennerich@analog.com>
Cc: Mike Frysinger <vapier@gentoo.org>,
"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
"uclinux-dist-devel@blackfin.uclinux.org"
<uclinux-dist-devel@blackfin.uclinux.org>,
Chris Verges <chrisv@cyberswitching.com>,
Luotao Fu <l.fu@pengutronix.de>,
"Song, Barry" <Barry.Song@analog.com>
Subject: Re: [PATCH v3] input/misc: new ADXL345/346 driver
Date: Thu, 1 Jul 2010 00:53:16 -0700 [thread overview]
Message-ID: <20100701075316.GA14696@core.coreip.homeip.net> (raw)
In-Reply-To: <544AC56F16B56944AEC3BD4E3D5917712E66DFEF69@LIMKCMBX1.ad.analog.com>
On Fri, Jun 25, 2010 at 02:59:24PM +0100, Hennerich, Michael wrote:
> Dmitry Torokhov wrote on 2010-06-25:
> > Hi Mike, Michael,
> >
> > On Tue, Oct 20, 2009 at 04:40:39AM -0400, Mike Frysinger wrote:
> >> From: Michael Hennerich <michael.hennerich@analog.com>
> >>
> >> This is a driver for the ADXL345/346 Three-Axis Digital Accelerometers.
> >>
> >
> > As I mentioned in one of the threads I decided to pull 3-axis
> > acceleromenetrs into input and I am finally getting around to apply
> > the patch... However I messed a bit with it so I was wondering if
> > someone could give it a short spin to see if I broke it or not.
> >
> > Thanks!
> >
>
> Hi Dmitry,
>
> Thanks for merging this driver.
> I gave it a quick spin. And there is one issue.
> There is a code path that is taken with the mutex held,
> which is also trying to acquire the mutex.
>
> Take a look at
>
> adxl34x_input_close() -> __adxl34x_disable()
> or
> adxl34x_disable() -> __adxl34x_disable()
>
> I think __adxl34x_disable() should not acquire the mutex!
>
Yes, indeed it shoudl not have. I fixed it up and applied the patch.
Could you also please try the following patch - hopefully it also works
;)
Thank you in advance.
--
Dmitry
Input: adxl34 - make enable/disable separate from suspend/resume
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Suspending and resuming the device should be separate from enabling
and disabling it through sysfs attribute and thus should not alter
ac->disabled flag.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
drivers/input/misc/adxl34x-i2c.c | 16 ++++----
drivers/input/misc/adxl34x-spi.c | 16 ++++----
drivers/input/misc/adxl34x.c | 77 ++++++++++++++++++++++++--------------
drivers/input/misc/adxl34x.h | 4 +-
4 files changed, 67 insertions(+), 46 deletions(-)
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);
next prev parent reply other threads:[~2010-07-01 7:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 10:27 [PATCH] input/misc: new ADXL345/346 driver Mike Frysinger
[not found] ` <1255516029-30023-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-10-14 10:54 ` [PATCH v2] " Mike Frysinger
2009-10-16 4:36 ` Dmitry Torokhov
[not found] ` <20091016043627.GC11582-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2009-10-16 5:39 ` Mike Frysinger
[not found] ` <8bd0f97a0910152239v3c889a95rd9b100e3e7204e98-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-10-16 5:44 ` Dmitry Torokhov
[not found] ` <20091016054414.GE11582-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2009-10-16 5:53 ` Mike Frysinger
2009-10-16 6:57 ` [Uclinux-dist-devel] " Mike Frysinger
2009-10-16 7:22 ` Dmitry Torokhov
[not found] ` <20091016072216.GH11582-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2009-10-16 8:20 ` Mike Frysinger
2009-10-16 9:06 ` Hennerich, Michael
2009-10-20 8:40 ` [PATCH v3] " Mike Frysinger
2009-10-20 18:46 ` Chris Verges
2009-10-21 2:32 ` [Uclinux-dist-devel] " Mike Frysinger
2010-06-25 7:14 ` Dmitry Torokhov
[not found] ` <20100625071425.GA631-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2010-06-25 13:59 ` Hennerich, Michael
2010-07-01 7:53 ` Dmitry Torokhov [this message]
2010-07-01 9:15 ` Hennerich, Michael
2010-07-01 16:08 ` Dmitry Torokhov
2010-07-21 13:50 ` [Uclinux-dist-devel] " Mike Frysinger
2010-07-23 6:44 ` Dmitry Torokhov
2010-08-05 12:30 ` Hennerich, Michael
2010-08-06 5:37 ` Dmitry Torokhov
-- strict thread matches above, loose matches on Subject: below --
2009-10-21 3:14 Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100701075316.GA14696@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=Barry.Song@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=chrisv@cyberswitching.com \
--cc=l.fu@pengutronix.de \
--cc=linux-input@vger.kernel.org \
--cc=uclinux-dist-devel@blackfin.uclinux.org \
--cc=vapier@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).