Commit 078f3f64 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Alexandre Belloni

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: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent c4f07ece
...@@ -297,7 +297,7 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id) ...@@ -297,7 +297,7 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id)
{ {
struct ds1307 *ds1307 = dev_id; struct ds1307 *ds1307 = dev_id;
struct mutex *lock = &ds1307->rtc->ops_lock; struct mutex *lock = &ds1307->rtc->ops_lock;
int stat, control, ret; int stat, ret;
mutex_lock(lock); mutex_lock(lock);
ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat); ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat);
...@@ -308,13 +308,11 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id) ...@@ -308,13 +308,11 @@ static irqreturn_t ds1307_irq(int irq, void *dev_id)
stat &= ~DS1337_BIT_A1I; stat &= ~DS1337_BIT_A1I;
regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat); 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) if (ret)
goto out; goto out;
control &= ~DS1337_BIT_A1IE;
regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); 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) ...@@ -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) static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct ds1307 *ds1307 = dev_get_drvdata(dev); struct ds1307 *ds1307 = dev_get_drvdata(dev);
int control, ret;
if (!test_bit(HAS_ALARM, &ds1307->flags)) if (!test_bit(HAS_ALARM, &ds1307->flags))
return -ENOTTY; return -ENOTTY;
ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL,
if (ret) DS1337_BIT_A1IE,
return ret; enabled ? DS1337_BIT_A1IE : 0);
if (enabled)
control |= DS1337_BIT_A1IE;
else
control &= ~DS1337_BIT_A1IE;
return regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
} }
static const struct rtc_class_ops ds13xx_rtc_ops = { static const struct rtc_class_ops ds13xx_rtc_ops = {
...@@ -795,11 +785,8 @@ static irqreturn_t mcp794xx_irq(int irq, void *dev_id) ...@@ -795,11 +785,8 @@ static irqreturn_t mcp794xx_irq(int irq, void *dev_id)
goto out; goto out;
/* Disable alarm 0. */ /* Disable alarm 0. */
ret = regmap_read(ds1307->regmap, MCP794XX_REG_CONTROL, &reg); ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL,
if (ret) MCP794XX_BIT_ALM0_EN, 0);
goto out;
reg &= ~MCP794XX_BIT_ALM0_EN;
ret = regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, reg);
if (ret) if (ret)
goto out; goto out;
...@@ -897,21 +884,13 @@ static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t) ...@@ -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) static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct ds1307 *ds1307 = dev_get_drvdata(dev); struct ds1307 *ds1307 = dev_get_drvdata(dev);
int reg, ret;
if (!test_bit(HAS_ALARM, &ds1307->flags)) if (!test_bit(HAS_ALARM, &ds1307->flags))
return -EINVAL; return -EINVAL;
ret = regmap_read(ds1307->regmap, MCP794XX_REG_CONTROL, &reg); return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL,
if (ret) MCP794XX_BIT_ALM0_EN,
return ret; enabled ? MCP794XX_BIT_ALM0_EN : 0);
if (enabled)
reg |= MCP794XX_BIT_ALM0_EN;
else
reg &= ~MCP794XX_BIT_ALM0_EN;
return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, reg);
} }
static const struct rtc_class_ops mcp794xx_rtc_ops = { static const struct rtc_class_ops mcp794xx_rtc_ops = {
...@@ -1114,20 +1093,11 @@ static int ds3231_clk_sqw_rates[] = { ...@@ -1114,20 +1093,11 @@ static int ds3231_clk_sqw_rates[] = {
static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value) static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value)
{ {
struct mutex *lock = &ds1307->rtc->ops_lock; struct mutex *lock = &ds1307->rtc->ops_lock;
int control;
int ret; int ret;
mutex_lock(lock); mutex_lock(lock);
ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL,
ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); mask, value);
if (ret)
goto out;
control &= ~mask;
control |= value;
ret = regmap_write(ds1307->regmap, DS1337_REG_CONTROL, control);
out:
mutex_unlock(lock); mutex_unlock(lock);
return ret; return ret;
...@@ -1233,22 +1203,12 @@ static unsigned long ds3231_clk_32khz_recalc_rate(struct clk_hw *hw, ...@@ -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) static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable)
{ {
struct mutex *lock = &ds1307->rtc->ops_lock; struct mutex *lock = &ds1307->rtc->ops_lock;
int status;
int ret; int ret;
mutex_lock(lock); mutex_lock(lock);
ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS,
ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); DS3231_BIT_EN32KHZ,
if (ret) enable ? DS3231_BIT_EN32KHZ : 0);
goto out;
if (enable)
status |= DS3231_BIT_EN32KHZ;
else
status &= ~DS3231_BIT_EN32KHZ;
ret = regmap_write(ds1307->regmap, DS1337_REG_STATUS, status);
out:
mutex_unlock(lock); mutex_unlock(lock);
return ret; return ret;
...@@ -1712,12 +1672,10 @@ static int ds1307_probe(struct i2c_client *client, ...@@ -1712,12 +1672,10 @@ static int ds1307_probe(struct i2c_client *client,
* If different then set the wday which we computed using * If different then set the wday which we computed using
* timestamp * timestamp
*/ */
if (wday != tm.tm_wday) { if (wday != tm.tm_wday)
regmap_read(ds1307->regmap, MCP794XX_REG_WEEKDAY, &wday); regmap_update_bits(ds1307->regmap, MCP794XX_REG_WEEKDAY,
wday = wday & ~MCP794XX_REG_WEEKDAY_WDAY_MASK; MCP794XX_REG_WEEKDAY_WDAY_MASK,
wday = wday | (tm.tm_wday + 1); tm.tm_wday + 1);
regmap_write(ds1307->regmap, MCP794XX_REG_WEEKDAY, wday);
}
if (want_irq) { if (want_irq) {
device_set_wakeup_capable(ds1307->dev, true); device_set_wakeup_capable(ds1307->dev, true);
......
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