aboutsummaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
authorRasmus Villemoes <rasmus.villemoes@prevas.dk>2020-07-06 22:01:12 +0200
committerHeiko Schocher <hs@denx.de>2020-07-09 06:02:45 +0200
commit5113f0b65a6a1ce79f4befa4e99f3e8e4a1eb9b0 (patch)
treef87aa93d71e07bccd91cd1e07d9becfe63e2f901 /drivers/rtc
parent09381829a231f5d2b95568f3178c2bd125a93fac (diff)
downloadu-boot-5113f0b65a6a1ce79f4befa4e99f3e8e4a1eb9b0.zip
u-boot-5113f0b65a6a1ce79f4befa4e99f3e8e4a1eb9b0.tar.gz
u-boot-5113f0b65a6a1ce79f4befa4e99f3e8e4a1eb9b0.tar.bz2
rtc: fall back to ->{read, write} if ->{read, write}8 are not provided
Similar to how the dm_rtc_{read,write} functions fall back to using the {read,write}8 methods, do the opposite in the rtc_{read,write}8 functions. This way, each driver only needs to provide either ->read8 or ->read to make both rtc_read8() and dm_rtc_read() work - without this, a driver that provides ->read() would most likely just duplicate the logic here for implementing a ->read8() method in term of its ->read() method. The same remarks of course apply to the write case. Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heiko Schocher <hs@denx.de> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-uclass.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/drivers/rtc/rtc-uclass.c b/drivers/rtc/rtc-uclass.c
index 44da500..8035f7f 100644
--- a/drivers/rtc/rtc-uclass.c
+++ b/drivers/rtc/rtc-uclass.c
@@ -83,9 +83,17 @@ int rtc_read8(struct udevice *dev, unsigned int reg)
struct rtc_ops *ops = rtc_get_ops(dev);
assert(ops);
- if (!ops->read8)
- return -ENOSYS;
- return ops->read8(dev, reg);
+ if (ops->read8)
+ return ops->read8(dev, reg);
+ if (ops->read) {
+ u8 buf[1];
+ int ret = ops->read(dev, reg, buf, 1);
+
+ if (ret < 0)
+ return ret;
+ return buf[0];
+ }
+ return -ENOSYS;
}
int rtc_write8(struct udevice *dev, unsigned int reg, int val)
@@ -93,9 +101,14 @@ int rtc_write8(struct udevice *dev, unsigned int reg, int val)
struct rtc_ops *ops = rtc_get_ops(dev);
assert(ops);
- if (!ops->write8)
- return -ENOSYS;
- return ops->write8(dev, reg, val);
+ if (ops->write8)
+ return ops->write8(dev, reg, val);
+ if (ops->write) {
+ u8 buf[1] = { val };
+
+ return ops->write(dev, reg, buf, 1);
+ }
+ return -ENOSYS;
}
int rtc_read16(struct udevice *dev, unsigned int reg, u16 *valuep)