@@ -14,55 +14,38 @@
static int sandbox_rtc_get(struct udevice *dev, struct rtc_time *time)
{
- time->tm_sec = dm_i2c_reg_read(dev, REG_SEC);
- if (time->tm_sec < 0)
- return time->tm_sec;
- time->tm_min = dm_i2c_reg_read(dev, REG_MIN);
- if (time->tm_min < 0)
- return time->tm_min;
- time->tm_hour = dm_i2c_reg_read(dev, REG_HOUR);
- if (time->tm_hour < 0)
- return time->tm_hour;
- time->tm_mday = dm_i2c_reg_read(dev, REG_MDAY);
- if (time->tm_mday < 0)
- return time->tm_mday;
- time->tm_mon = dm_i2c_reg_read(dev, REG_MON);
- if (time->tm_mon < 0)
- return time->tm_mon;
- time->tm_year = dm_i2c_reg_read(dev, REG_YEAR);
- if (time->tm_year < 0)
- return time->tm_year;
- time->tm_year += 1900;
- time->tm_wday = dm_i2c_reg_read(dev, REG_WDAY);
- if (time->tm_wday < 0)
- return time->tm_wday;
+ u8 buf[7];
+ int ret;
+
+ ret = dm_i2c_read(dev, REG_SEC, buf, sizeof(buf));
+ if (ret < 0)
+ return ret;
+
+ time->tm_sec = buf[REG_SEC - REG_SEC];
+ time->tm_min = buf[REG_MIN - REG_SEC];
+ time->tm_hour = buf[REG_HOUR - REG_SEC];
+ time->tm_mday = buf[REG_MDAY - REG_SEC];
+ time->tm_mon = buf[REG_MON - REG_SEC];
+ time->tm_year = buf[REG_YEAR - REG_SEC] + 1900;
+ time->tm_wday = buf[REG_WDAY - REG_SEC];
return 0;
}
static int sandbox_rtc_set(struct udevice *dev, const struct rtc_time *time)
{
+ u8 buf[7];
int ret;
- ret = dm_i2c_reg_write(dev, REG_SEC, time->tm_sec);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_MIN, time->tm_min);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_HOUR, time->tm_hour);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_MDAY, time->tm_mday);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_MON, time->tm_mon);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_YEAR, time->tm_year - 1900);
- if (ret < 0)
- return ret;
- ret = dm_i2c_reg_write(dev, REG_WDAY, time->tm_wday);
+ buf[REG_SEC - REG_SEC] = time->tm_sec;
+ buf[REG_MIN - REG_SEC] = time->tm_min;
+ buf[REG_HOUR - REG_SEC] = time->tm_hour;
+ buf[REG_MDAY - REG_SEC] = time->tm_mday;
+ buf[REG_MON - REG_SEC] = time->tm_mon;
+ buf[REG_YEAR - REG_SEC] = time->tm_year - 1900;
+ buf[REG_WDAY - REG_SEC] = time->tm_wday;
+
+ ret = dm_i2c_write(dev, REG_SEC, buf, sizeof(buf));
if (ret < 0)
return ret;
@@ -70,7 +70,20 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts)
old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
memset(&time, '\0', sizeof(time));
- time.tm_mday = 25;
+ time.tm_mday = 3;
+ time.tm_mon = 6;
+ time.tm_year = 2004;
+ time.tm_sec = 0;
+ time.tm_min = 18;
+ time.tm_hour = 18;
+ ut_assertok(dm_rtc_set(dev, &time));
+
+ memset(&cmp, '\0', sizeof(cmp));
+ ut_assertok(dm_rtc_get(dev, &cmp));
+ ut_assertok(cmp_times(&time, &cmp, true));
+
+ memset(&time, '\0', sizeof(time));
+ time.tm_mday = 31;
time.tm_mon = 8;
time.tm_year = 2004;
time.tm_sec = 0;