summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1307.c
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2017-06-05 17:57:29 +0200
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2017-07-05 23:12:34 +0200
commit078f3f6452c8be74fd406733f99f2cb0d9c50efc (patch)
tree68bccefc767ca5b2c5da3b0735c4c4ebbdf11743 /drivers/rtc/rtc-ds1307.c
parentc4f07ecee22ec720936eb58e7c63b89a1e86bf32 (diff)
downloadlinux-078f3f6452c8be74fd406733f99f2cb0d9c50efc.tar.bz2
rtc: ds1307: use regmap_update_bits where applicable
After the switch to regmap we can now make use of regmap_update_bits to simplify read/modify/write ops. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
-rw-r--r--drivers/rtc/rtc-ds1307.c82
1 files changed, 20 insertions, 62 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 3cbb7636b405..9b4106a7e8e4 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -297,7 +297,7 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id)
{
struct ds1307 *ds1307 = dev_id;
struct mutex *lock = &ds1307->rtc->ops_lock;
- int stat, control, ret;
+ int stat, ret;
mutex_lock(lock);
ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat);
@@ -308,13 +308,11 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id)
stat &= ~DS1337_BIT_A1I;
regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat);
- ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control);
+ ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL,
+ DS1337_BIT_A1IE, 0);
if (ret)
goto out;
- control &= ~DS1337_BIT_A1IE;
- regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
-
rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
}
@@ -567,21 +565,13 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t)
static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
- int control, ret;
if (!test_bit(HAS_ALARM, &ds1307->flags))
return -ENOTTY;
- ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control);
- if (ret)
- return ret;
-
- if (enabled)
- control |= DS1337_BIT_A1IE;
- else
- control &= ~DS1337_BIT_A1IE;
-
- return regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
+ return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL,
+ DS1337_BIT_A1IE,
+ enabled ? DS1337_BIT_A1IE : 0);
}
static const struct rtc_class_ops ds13xx_rtc_ops = {
@@ -795,11 +785,8 @@ static irqreturn_t mcp794xx_irq(int irq, void *dev_id)
goto out;
/* Disable alarm 0. */
- ret = regmap_read(ds1307->regmap, MCP794XX_REG_CONTROL, &reg);
- if (ret)
- goto out;
- reg &= ~MCP794XX_BIT_ALM0_EN;
- ret = regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, reg);
+ ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL,
+ MCP794XX_BIT_ALM0_EN, 0);
if (ret)
goto out;
@@ -897,21 +884,13 @@ static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t)
static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
- int reg, ret;
if (!test_bit(HAS_ALARM, &ds1307->flags))
return -EINVAL;
- ret = regmap_read(ds1307->regmap, MCP794XX_REG_CONTROL, &reg);
- if (ret)
- return ret;
-
- if (enabled)
- reg |= MCP794XX_BIT_ALM0_EN;
- else
- reg &= ~MCP794XX_BIT_ALM0_EN;
-
- return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, reg);
+ return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL,
+ MCP794XX_BIT_ALM0_EN,
+ enabled ? MCP794XX_BIT_ALM0_EN : 0);
}
static const struct rtc_class_ops mcp794xx_rtc_ops = {
@@ -1114,20 +1093,11 @@ static int ds3231_clk_sqw_rates[] = {
static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
{
struct mutex *lock = &ds1307->rtc->ops_lock;
- int control;
int ret;
mutex_lock(lock);
-
- ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control);
- if (ret)
- goto out;
-
- control &= ~mask;
- control |= value;
-
- ret = regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
-out:
+ ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL,
+ mask, value);
mutex_unlock(lock);
return ret;
@@ -1233,22 +1203,12 @@ static unsigned long ds3231_clk_32khz_recalc_rate(struct clk_hw *hw,
static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable)
{
struct mutex *lock = &ds1307->rtc->ops_lock;
- int status;
int ret;
mutex_lock(lock);
-
- ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status);
- if (ret)
- goto out;
-
- if (enable)
- status |= DS3231_BIT_EN32KHZ;
- else
- status &= ~DS3231_BIT_EN32KHZ;
-
- ret = regmap_write(ds1307->regmap, DS1337_REG_STATUS, status);
-out:
+ ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS,
+ DS3231_BIT_EN32KHZ,
+ enable ? DS3231_BIT_EN32KHZ : 0);
mutex_unlock(lock);
return ret;
@@ -1712,12 +1672,10 @@ read_rtc:
* If different then set the wday which we computed using
* timestamp
*/
- if (wday != tm.tm_wday) {
- regmap_read(ds1307->regmap, MCP794XX_REG_WEEKDAY, &wday);
- wday = wday & ~MCP794XX_REG_WEEKDAY_WDAY_MASK;
- wday = wday | (tm.tm_wday + 1);
- regmap_write(ds1307->regmap, MCP794XX_REG_WEEKDAY, wday);
- }
+ if (wday != tm.tm_wday)
+ regmap_update_bits(ds1307->regmap, MCP794XX_REG_WEEKDAY,
+ MCP794XX_REG_WEEKDAY_WDAY_MASK,
+ tm.tm_wday + 1);
if (want_irq) {
device_set_wakeup_capable(ds1307->dev, true);