From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 7/9] rtc: ds1343: remove unnecessary mutex
Date: Sat, 19 Oct 2019 22:49:39 +0200 [thread overview]
Message-ID: <20191019204941.6203-7-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20191019204941.6203-1-alexandre.belloni@bootlin.com>
Use rtc_lock and rtc_unlock to lock the rtc from the interrupt handler.
This removes the need for a driver specific lock.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-ds1343.c | 36 +++++++-----------------------------
1 file changed, 7 insertions(+), 29 deletions(-)
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index c96a505972e6..867187325d41 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -78,7 +78,6 @@ struct ds1343_priv {
struct spi_device *spi;
struct rtc_device *rtc;
struct regmap *map;
- struct mutex mutex;
unsigned int irqen;
int irq;
int alarm_sec;
@@ -290,17 +289,15 @@ static int ds1343_update_alarm(struct device *dev)
static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
struct ds1343_priv *priv = dev_get_drvdata(dev);
- int res = 0;
+ int res;
unsigned int stat;
if (priv->irq <= 0)
return -EINVAL;
- mutex_lock(&priv->mutex);
-
res = regmap_read(priv->map, DS1343_STATUS_REG, &stat);
if (res)
- goto out;
+ return res;
alarm->enabled = !!(priv->irqen & RTC_AF);
alarm->pending = !!(stat & DS1343_IRQF0);
@@ -310,21 +307,16 @@ static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
alarm->time.tm_hour = priv->alarm_hour < 0 ? 0 : priv->alarm_hour;
alarm->time.tm_mday = priv->alarm_mday < 0 ? 0 : priv->alarm_mday;
-out:
- mutex_unlock(&priv->mutex);
- return res;
+ return 0;
}
static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
struct ds1343_priv *priv = dev_get_drvdata(dev);
- int res = 0;
if (priv->irq <= 0)
return -EINVAL;
- mutex_lock(&priv->mutex);
-
priv->alarm_sec = alarm->time.tm_sec;
priv->alarm_min = alarm->time.tm_min;
priv->alarm_hour = alarm->time.tm_hour;
@@ -333,33 +325,22 @@ static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (alarm->enabled)
priv->irqen |= RTC_AF;
- res = ds1343_update_alarm(dev);
-
- mutex_unlock(&priv->mutex);
-
- return res;
+ return ds1343_update_alarm(dev);
}
static int ds1343_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct ds1343_priv *priv = dev_get_drvdata(dev);
- int res = 0;
if (priv->irq <= 0)
return -EINVAL;
- mutex_lock(&priv->mutex);
-
if (enabled)
priv->irqen |= RTC_AF;
else
priv->irqen &= ~RTC_AF;
- res = ds1343_update_alarm(dev);
-
- mutex_unlock(&priv->mutex);
-
- return res;
+ return ds1343_update_alarm(dev);
}
static irqreturn_t ds1343_thread(int irq, void *dev_id)
@@ -368,7 +349,7 @@ static irqreturn_t ds1343_thread(int irq, void *dev_id)
unsigned int stat, control;
int res = 0;
- mutex_lock(&priv->mutex);
+ rtc_lock(priv->rtc);
res = regmap_read(priv->map, DS1343_STATUS_REG, &stat);
if (res)
@@ -389,7 +370,7 @@ static irqreturn_t ds1343_thread(int irq, void *dev_id)
}
out:
- mutex_unlock(&priv->mutex);
+ rtc_unlock(priv->rtc);
return IRQ_HANDLED;
}
@@ -422,7 +403,6 @@ static int ds1343_probe(struct spi_device *spi)
return -ENOMEM;
priv->spi = spi;
- mutex_init(&priv->mutex);
/* RTC DS1347 works in spi mode 3 and
* its chip select is active high
@@ -500,9 +480,7 @@ static int ds1343_remove(struct spi_device *spi)
struct ds1343_priv *priv = spi_get_drvdata(spi);
if (spi->irq) {
- mutex_lock(&priv->mutex);
priv->irqen &= ~RTC_AF;
- mutex_unlock(&priv->mutex);
dev_pm_clear_wake_irq(&spi->dev);
device_init_wakeup(&spi->dev, false);
--
2.21.0
next prev parent reply other threads:[~2019-10-19 20:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-19 20:49 [PATCH 1/9] rtc: ds1343: set range Alexandre Belloni
2019-10-19 20:49 ` [PATCH 2/9] rtc: ds1343: remove dead code Alexandre Belloni
2019-10-19 20:49 ` [PATCH 3/9] rtc: ds1343: use burst write to set time Alexandre Belloni
2019-10-19 20:49 ` [PATCH 4/9] rtc: ds1343: use rtc_add_group Alexandre Belloni
2019-10-19 20:49 ` [PATCH 5/9] rtc: ds1343: use regmap_update_bits for glitch filter Alexandre Belloni
2019-10-19 20:49 ` [PATCH 6/9] rtc: ds1343: check regmap_read return value Alexandre Belloni
2019-10-19 20:49 ` Alexandre Belloni [this message]
2019-10-19 20:49 ` [PATCH 8/9] rtc: ds1343: rework interrupt handling Alexandre Belloni
2019-10-19 20:49 ` [PATCH 9/9] rtc: ds1343: cleanup .remove Alexandre Belloni
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=20191019204941.6203-7-alexandre.belloni@bootlin.com \
--to=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.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).