1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
7 #define LOG_CATEGORY UCLASS_RTC
14 int dm_rtc_get(struct udevice *dev, struct rtc_time *time)
16 struct rtc_ops *ops = rtc_get_ops(dev);
21 return ops->get(dev, time);
24 int dm_rtc_set(struct udevice *dev, struct rtc_time *time)
26 struct rtc_ops *ops = rtc_get_ops(dev);
31 return ops->set(dev, time);
34 int dm_rtc_reset(struct udevice *dev)
36 struct rtc_ops *ops = rtc_get_ops(dev);
41 return ops->reset(dev);
44 int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len)
46 struct rtc_ops *ops = rtc_get_ops(dev);
50 return ops->read(dev, reg, buf, len);
54 int ret = ops->read8(dev, reg++);
63 int dm_rtc_write(struct udevice *dev, unsigned int reg,
64 const u8 *buf, unsigned int len)
66 struct rtc_ops *ops = rtc_get_ops(dev);
70 return ops->write(dev, reg, buf, len);
74 int ret = ops->write8(dev, reg++, *buf++);
82 int rtc_read8(struct udevice *dev, unsigned int reg)
84 struct rtc_ops *ops = rtc_get_ops(dev);
88 return ops->read8(dev, reg);
91 int ret = ops->read(dev, reg, buf, 1);
100 int rtc_write8(struct udevice *dev, unsigned int reg, int val)
102 struct rtc_ops *ops = rtc_get_ops(dev);
106 return ops->write8(dev, reg, val);
110 return ops->write(dev, reg, buf, 1);
115 int rtc_read16(struct udevice *dev, unsigned int reg, u16 *valuep)
121 for (i = 0; i < sizeof(value); i++) {
122 ret = rtc_read8(dev, reg + i);
125 value |= ret << (i << 3);
132 int rtc_write16(struct udevice *dev, unsigned int reg, u16 value)
136 for (i = 0; i < sizeof(value); i++) {
137 ret = rtc_write8(dev, reg + i, (value >> (i << 3)) & 0xff);
145 int rtc_read32(struct udevice *dev, unsigned int reg, u32 *valuep)
151 for (i = 0; i < sizeof(value); i++) {
152 ret = rtc_read8(dev, reg + i);
155 value |= ret << (i << 3);
162 int rtc_write32(struct udevice *dev, unsigned int reg, u32 value)
166 for (i = 0; i < sizeof(value); i++) {
167 ret = rtc_write8(dev, reg + i, (value >> (i << 3)) & 0xff);
175 UCLASS_DRIVER(rtc) = {
178 .flags = DM_UC_FLAG_SEQ_ALIAS,
179 #if CONFIG_IS_ENABLED(OF_REAL)
180 .post_bind = dm_scan_fdt_dev,