Commit fc1dcb0b authored by Akinobu Mita's avatar Akinobu Mita Committed by Alexandre Belloni

rtc: ds3232: use rtc->ops_lock to protect alarm operations

ds3232->mutex is used to protect for alarm operations which
need to access status and control registers.

But we can use rtc->ops_lock instead.  rtc->ops_lock is held when most
of rtc_class_ops methods are called, so we only need to explicitly
acquire it from irq handler in order to protect form concurrent
accesses.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 95c60c1c
...@@ -52,11 +52,6 @@ struct ds3232 { ...@@ -52,11 +52,6 @@ struct ds3232 {
int irq; int irq;
struct rtc_device *rtc; struct rtc_device *rtc;
/* The mutex protects alarm operations, and prevents a race
* between the enable_irq() in the workqueue and the free_irq()
* in the remove function.
*/
struct mutex mutex;
bool suspended; bool suspended;
}; };
...@@ -187,8 +182,6 @@ static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -187,8 +182,6 @@ static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
int ret; int ret;
u8 buf[4]; u8 buf[4];
mutex_lock(&ds3232->mutex);
ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat);
if (ret) if (ret)
goto out; goto out;
...@@ -215,7 +208,6 @@ static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -215,7 +208,6 @@ static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
ret = 0; ret = 0;
out: out:
mutex_unlock(&ds3232->mutex);
return ret; return ret;
} }
...@@ -233,8 +225,6 @@ static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -233,8 +225,6 @@ static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (ds3232->irq <= 0) if (ds3232->irq <= 0)
return -EINVAL; return -EINVAL;
mutex_lock(&ds3232->mutex);
buf[0] = bin2bcd(alarm->time.tm_sec); buf[0] = bin2bcd(alarm->time.tm_sec);
buf[1] = bin2bcd(alarm->time.tm_min); buf[1] = bin2bcd(alarm->time.tm_min);
buf[2] = bin2bcd(alarm->time.tm_hour); buf[2] = bin2bcd(alarm->time.tm_hour);
...@@ -267,7 +257,6 @@ static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -267,7 +257,6 @@ static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control); ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control);
} }
out: out:
mutex_unlock(&ds3232->mutex);
return ret; return ret;
} }
...@@ -277,11 +266,9 @@ static int ds3232_update_alarm(struct device *dev, unsigned int enabled) ...@@ -277,11 +266,9 @@ static int ds3232_update_alarm(struct device *dev, unsigned int enabled)
int control; int control;
int ret; int ret;
mutex_lock(&ds3232->mutex);
ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control);
if (ret) if (ret)
goto unlock; return ret;
if (enabled) if (enabled)
/* enable alarm1 interrupt */ /* enable alarm1 interrupt */
...@@ -291,9 +278,6 @@ static int ds3232_update_alarm(struct device *dev, unsigned int enabled) ...@@ -291,9 +278,6 @@ static int ds3232_update_alarm(struct device *dev, unsigned int enabled)
control &= ~(DS3232_REG_CR_A1IE); control &= ~(DS3232_REG_CR_A1IE);
ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control); ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control);
unlock:
mutex_unlock(&ds3232->mutex);
return ret; return ret;
} }
...@@ -311,10 +295,11 @@ static irqreturn_t ds3232_irq(int irq, void *dev_id) ...@@ -311,10 +295,11 @@ static irqreturn_t ds3232_irq(int irq, void *dev_id)
{ {
struct device *dev = dev_id; struct device *dev = dev_id;
struct ds3232 *ds3232 = dev_get_drvdata(dev); struct ds3232 *ds3232 = dev_get_drvdata(dev);
struct mutex *lock = &ds3232->rtc->ops_lock;
int ret; int ret;
int stat, control; int stat, control;
mutex_lock(&ds3232->mutex); mutex_lock(lock);
ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat);
if (ret) if (ret)
...@@ -352,7 +337,7 @@ static irqreturn_t ds3232_irq(int irq, void *dev_id) ...@@ -352,7 +337,7 @@ static irqreturn_t ds3232_irq(int irq, void *dev_id)
} }
unlock: unlock:
mutex_unlock(&ds3232->mutex); mutex_unlock(lock);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -380,8 +365,6 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, ...@@ -380,8 +365,6 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
ds3232->dev = dev; ds3232->dev = dev;
dev_set_drvdata(dev, ds3232); dev_set_drvdata(dev, ds3232);
mutex_init(&ds3232->mutex);
ret = ds3232_check_rtc_status(dev); ret = ds3232_check_rtc_status(dev);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment