From: Jason Wang <jason77.wang@gmail.com>
To: Jason Wang <jason77.wang@gmail.com>
Cc: dmitry.torokhov@gmail.com, dtor@mail.ru, notasas@gmail.com,
vapier@gentoo.org, linux-input@vger.kernel.org
Subject: Re: [PATCH v2] Input: ads7846 - Replace spinlock by mutex to wrap disable()/enable()
Date: Wed, 25 Aug 2010 11:45:27 +0800 [thread overview]
Message-ID: <4C7491D7.1030801@gmail.com> (raw)
In-Reply-To: <1282370340-3157-1-git-send-email-jason77.wang@gmail.com>
Hi dmitry and others,
could you please to help me review this patch?
Thanks,
Jason.
Jason Wang wrote:
> The commit 9114337 introduces regulator operations in the ads7846
> touchscreen driver. Among these operations, some are called in the
> spinlock protected context.
> On most platforms, the regulator operation is achieved through
> i2c/spi bus transfer operations, some bus transfer operations will
> call wait_for_completion function. It isn't allowable to call
> sleepable function in the atomic context. So replace the spinlock with
> mutex to protect ads7846_disable()/ads7846_enable().
>
> [tested on TI OMAP3530EVM board]
>
> Signed-off-by: Jason Wang <jason77.wang@gmail.com>
> ---
> Diff vs V1:
> Don't move regualtor_disable/enable out from ads7846_disable/enable,
> but use mutext to replace spinlock.
>
> I think this replace is safe because ads7846_disable/enable is called
> in process context, it won't race with ads7846_irq/timer(irq&softirq).
> While it is possible for ads7846_irq/timer to race with
> ads7846_disable, but ads7846_diable can handle this situation already.
>
> drivers/input/touchscreen/ads7846.c | 19 +++++++++----------
> 1 files changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
> index 1603193..0b875fa 100644
> --- a/drivers/input/touchscreen/ads7846.c
> +++ b/drivers/input/touchscreen/ads7846.c
> @@ -130,6 +130,7 @@ struct ads7846 {
> unsigned irq_disabled:1; /* P: lock */
> unsigned disabled:1;
> unsigned is_suspended:1;
> + struct mutex mutex;
>
> int (*filter)(void *data, int data_idx, int *val);
> void *filter_data;
> @@ -531,14 +532,14 @@ static ssize_t ads7846_disable_store(struct device *dev,
> if (strict_strtoul(buf, 10, &i))
> return -EINVAL;
>
> - spin_lock_irq(&ts->lock);
> + mutex_lock(&ts->mutex);
>
> if (i)
> ads7846_disable(ts);
> else
> ads7846_enable(ts);
>
> - spin_unlock_irq(&ts->lock);
> + mutex_unlock(&ts->mutex);
>
> return count;
> }
> @@ -848,11 +849,8 @@ static void ads7846_disable(struct ads7846 *ts)
> /* the timer will run at least once more, and
> * leave everything in a clean state, IRQ disabled
> */
> - while (ts->pending) {
> - spin_unlock_irq(&ts->lock);
> + while (ts->pending)
> msleep(1);
> - spin_lock_irq(&ts->lock);
> - }
> }
>
> regulator_disable(ts->reg);
> @@ -879,12 +877,12 @@ static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
> {
> struct ads7846 *ts = dev_get_drvdata(&spi->dev);
>
> - spin_lock_irq(&ts->lock);
> + mutex_lock(&ts->mutex);
>
> ts->is_suspended = 1;
> ads7846_disable(ts);
>
> - spin_unlock_irq(&ts->lock);
> + mutex_unlock(&ts->mutex);
>
> if (device_may_wakeup(&ts->spi->dev))
> enable_irq_wake(ts->spi->irq);
> @@ -900,12 +898,12 @@ static int ads7846_resume(struct spi_device *spi)
> if (device_may_wakeup(&ts->spi->dev))
> disable_irq_wake(ts->spi->irq);
>
> - spin_lock_irq(&ts->lock);
> + mutex_lock(&ts->mutex);
>
> ts->is_suspended = 0;
> ads7846_enable(ts);
>
> - spin_unlock_irq(&ts->lock);
> + mutex_unlock(&ts->mutex);
>
> return 0;
> }
> @@ -999,6 +997,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
> ts->timer.function = ads7846_timer;
>
> spin_lock_init(&ts->lock);
> + mutex_init(&ts->mutex);
>
> ts->model = pdata->model ? : 7846;
> ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
>
next prev parent reply other threads:[~2010-08-25 3:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-21 5:59 [PATCH v2] Input: ads7846 - Replace spinlock by mutex to wrap disable()/enable() Jason Wang
2010-08-25 3:45 ` Jason Wang [this message]
2010-09-01 6:48 ` Dmitry Torokhov
2010-09-01 10:07 ` Jason Wang
2010-09-01 16:48 ` Dmitry Torokhov
2010-09-02 16:01 ` Dmitry Torokhov
2010-09-03 2:47 ` Jason Wang
2010-09-08 3:07 ` Jason Wang
2010-09-08 4:43 ` 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=4C7491D7.1030801@gmail.com \
--to=jason77.wang@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dtor@mail.ru \
--cc=linux-input@vger.kernel.org \
--cc=notasas@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.