Commit 8d273f33 authored by Johan Hovold's avatar Johan Hovold Committed by Alexandre Belloni

rtc: pm8xxx: drop bogus locking

Since commit c8d523a4 ("drivers/rtc/rtc-pm8xxx.c: rework to support
pm8941 rtc") which removed the shadow control register there is no need
for a driver lock.

Specifically, the rtc ops are serialised by rtc core and the interrupt
handler only unconditionally disables the alarm using the alarm_ctrl
register.

Note that since only the alarm enable bit of alarm_ctrl is used after
enabling the RTC at probe, the locking was not needed when doing open
coded read-modify-write cycles either.
Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
Reviewed-by: default avatarDavid Collins <quic_collinsd@quicinc.com>
Link: https://lore.kernel.org/r/20230202155448.6715-5-johan+linaro@kernel.orgSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 182c23bb
...@@ -53,7 +53,6 @@ struct pm8xxx_rtc_regs { ...@@ -53,7 +53,6 @@ struct pm8xxx_rtc_regs {
* @rtc_alarm_irq: rtc alarm irq number. * @rtc_alarm_irq: rtc alarm irq number.
* @regs: rtc registers description. * @regs: rtc registers description.
* @rtc_dev: device structure. * @rtc_dev: device structure.
* @ctrl_reg_lock: spinlock protecting access to ctrl_reg.
*/ */
struct pm8xxx_rtc { struct pm8xxx_rtc {
struct rtc_device *rtc; struct rtc_device *rtc;
...@@ -62,7 +61,6 @@ struct pm8xxx_rtc { ...@@ -62,7 +61,6 @@ struct pm8xxx_rtc {
int rtc_alarm_irq; int rtc_alarm_irq;
const struct pm8xxx_rtc_regs *regs; const struct pm8xxx_rtc_regs *regs;
struct device *rtc_dev; struct device *rtc_dev;
spinlock_t ctrl_reg_lock;
}; };
/* /*
...@@ -77,11 +75,11 @@ struct pm8xxx_rtc { ...@@ -77,11 +75,11 @@ struct pm8xxx_rtc {
static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
int rc, i; int rc, i;
unsigned long secs, irq_flags;
struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
u8 value[NUM_8_BIT_RTC_REGS]; u8 value[NUM_8_BIT_RTC_REGS];
bool alarm_enabled; bool alarm_enabled;
unsigned long secs;
if (!rtc_dd->allow_set_time) if (!rtc_dd->allow_set_time)
return -ENODEV; return -ENODEV;
...@@ -95,51 +93,46 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -95,51 +93,46 @@ static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
secs >>= 8; secs >>= 8;
} }
spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
rc = regmap_update_bits_check(rtc_dd->regmap, regs->alarm_ctrl, rc = regmap_update_bits_check(rtc_dd->regmap, regs->alarm_ctrl,
regs->alarm_en, 0, &alarm_enabled); regs->alarm_en, 0, &alarm_enabled);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Disable RTC H/w before writing on RTC register */ /* Disable RTC H/w before writing on RTC register */
rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE, 0); rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE, 0);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Write 0 to Byte[0] */ /* Write 0 to Byte[0] */
rc = regmap_write(rtc_dd->regmap, regs->write, 0); rc = regmap_write(rtc_dd->regmap, regs->write, 0);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Write Byte[1], Byte[2], Byte[3] */ /* Write Byte[1], Byte[2], Byte[3] */
rc = regmap_bulk_write(rtc_dd->regmap, regs->write + 1, rc = regmap_bulk_write(rtc_dd->regmap, regs->write + 1,
&value[1], sizeof(value) - 1); &value[1], sizeof(value) - 1);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Write Byte[0] */ /* Write Byte[0] */
rc = regmap_write(rtc_dd->regmap, regs->write, value[0]); rc = regmap_write(rtc_dd->regmap, regs->write, value[0]);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Enable RTC H/w after writing on RTC register */ /* Enable RTC H/w after writing on RTC register */
rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE, rc = regmap_update_bits(rtc_dd->regmap, regs->ctrl, PM8xxx_RTC_ENABLE,
PM8xxx_RTC_ENABLE); PM8xxx_RTC_ENABLE);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
if (alarm_enabled) { if (alarm_enabled) {
rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl,
regs->alarm_en, regs->alarm_en); regs->alarm_en, regs->alarm_en);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
} }
rtc_rw_fail: return 0;
spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
return rc;
} }
static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
...@@ -184,9 +177,9 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -184,9 +177,9 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
int rc, i; int rc, i;
u8 value[NUM_8_BIT_RTC_REGS]; u8 value[NUM_8_BIT_RTC_REGS];
unsigned long secs, irq_flags;
struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
unsigned long secs;
secs = rtc_tm_to_time64(&alarm->time); secs = rtc_tm_to_time64(&alarm->time);
...@@ -200,25 +193,22 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -200,25 +193,22 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (rc) if (rc)
return rc; return rc;
spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value,
sizeof(value)); sizeof(value));
if (rc) if (rc)
goto rtc_rw_fail; return rc;
if (alarm->enabled) { if (alarm->enabled) {
rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl,
regs->alarm_en, regs->alarm_en); regs->alarm_en, regs->alarm_en);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
} }
dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n", dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n",
&alarm->time, &alarm->time); &alarm->time, &alarm->time);
rtc_rw_fail:
spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); return 0;
return rc;
} }
static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
...@@ -255,14 +245,11 @@ static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -255,14 +245,11 @@ static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
{ {
int rc; int rc;
unsigned long irq_flags;
struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
u8 value[NUM_8_BIT_RTC_REGS] = {0}; u8 value[NUM_8_BIT_RTC_REGS] = {0};
unsigned int val; unsigned int val;
spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
if (enable) if (enable)
val = regs->alarm_en; val = regs->alarm_en;
else else
...@@ -271,19 +258,17 @@ static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) ...@@ -271,19 +258,17 @@ static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl,
regs->alarm_en, val); regs->alarm_en, val);
if (rc) if (rc)
goto rtc_rw_fail; return rc;
/* Clear Alarm register */ /* Clear Alarm register */
if (!enable) { if (!enable) {
rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value,
sizeof(value)); sizeof(value));
if (rc) if (rc)
goto rtc_rw_fail; return rc;
} }
rtc_rw_fail: return 0;
spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
return rc;
} }
static const struct rtc_class_ops pm8xxx_rtc_ops = { static const struct rtc_class_ops pm8xxx_rtc_ops = {
...@@ -302,25 +287,18 @@ static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id) ...@@ -302,25 +287,18 @@ static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF); rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
spin_lock(&rtc_dd->ctrl_reg_lock);
/* Clear the alarm enable bit */ /* Clear the alarm enable bit */
rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl, rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl,
regs->alarm_en, 0); regs->alarm_en, 0);
if (rc) { if (rc)
spin_unlock(&rtc_dd->ctrl_reg_lock); goto out;
goto rtc_alarm_handled;
}
spin_unlock(&rtc_dd->ctrl_reg_lock);
/* Clear RTC alarm register */ /* Clear RTC alarm register */
rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl2, rc = regmap_update_bits(rtc_dd->regmap, regs->alarm_ctrl2,
PM8xxx_RTC_ALARM_CLEAR, 0); PM8xxx_RTC_ALARM_CLEAR, 0);
if (rc) if (rc)
goto rtc_alarm_handled; goto out;
out:
rtc_alarm_handled:
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -398,9 +376,6 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev) ...@@ -398,9 +376,6 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
if (rtc_dd == NULL) if (rtc_dd == NULL)
return -ENOMEM; return -ENOMEM;
/* Initialise spinlock to protect RTC control register */
spin_lock_init(&rtc_dd->ctrl_reg_lock);
rtc_dd->regmap = dev_get_regmap(pdev->dev.parent, NULL); rtc_dd->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!rtc_dd->regmap) { if (!rtc_dd->regmap) {
dev_err(&pdev->dev, "Parent regmap unavailable.\n"); dev_err(&pdev->dev, "Parent regmap unavailable.\n");
......
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