{
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);
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);
}
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 = {
goto out;
/* Disable alarm 0. */
- ret = regmap_read(ds1307->regmap, MCP794XX_REG_CONTROL, ®);
- 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;
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, ®);
- 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 = {
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;
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;
* 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);