Commit f308b682 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: ds1343: use burst write to set time

To avoid possible race condition, use regmap_bulk_write to write all the
date/time registers at once instead of sequentially.

Link: https://lore.kernel.org/r/20191019204941.6203-3-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 8c9a88fa
...@@ -236,46 +236,18 @@ static int ds1343_read_time(struct device *dev, struct rtc_time *dt) ...@@ -236,46 +236,18 @@ static int ds1343_read_time(struct device *dev, struct rtc_time *dt)
static int ds1343_set_time(struct device *dev, struct rtc_time *dt) static int ds1343_set_time(struct device *dev, struct rtc_time *dt)
{ {
struct ds1343_priv *priv = dev_get_drvdata(dev); struct ds1343_priv *priv = dev_get_drvdata(dev);
int res; u8 buf[7];
res = regmap_write(priv->map, DS1343_SECONDS_REG, buf[0] = bin2bcd(dt->tm_sec);
bin2bcd(dt->tm_sec)); buf[1] = bin2bcd(dt->tm_min);
if (res) buf[2] = bin2bcd(dt->tm_hour) & 0x3F;
return res; buf[3] = bin2bcd(dt->tm_wday + 1);
buf[4] = bin2bcd(dt->tm_mday);
res = regmap_write(priv->map, DS1343_MINUTES_REG, buf[5] = bin2bcd(dt->tm_mon + 1);
bin2bcd(dt->tm_min)); buf[6] = bin2bcd(dt->tm_year - 100);
if (res)
return res; return regmap_bulk_write(priv->map, DS1343_SECONDS_REG,
buf, sizeof(buf));
res = regmap_write(priv->map, DS1343_HOURS_REG,
bin2bcd(dt->tm_hour) & 0x3F);
if (res)
return res;
res = regmap_write(priv->map, DS1343_DAY_REG,
bin2bcd(dt->tm_wday + 1));
if (res)
return res;
res = regmap_write(priv->map, DS1343_DATE_REG,
bin2bcd(dt->tm_mday));
if (res)
return res;
res = regmap_write(priv->map, DS1343_MONTH_REG,
bin2bcd(dt->tm_mon + 1));
if (res)
return res;
dt->tm_year %= 100;
res = regmap_write(priv->map, DS1343_YEAR_REG,
bin2bcd(dt->tm_year));
if (res)
return res;
return 0;
} }
static int ds1343_update_alarm(struct device *dev) static int ds1343_update_alarm(struct device *dev)
......
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