1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_RTC
15 int dm_rtc_get(struct udevice *dev, struct rtc_time *time)
17 struct rtc_ops *ops = rtc_get_ops(dev);
22 return ops->get(dev, time);
25 int dm_rtc_set(struct udevice *dev, struct rtc_time *time)
27 struct rtc_ops *ops = rtc_get_ops(dev);
32 return ops->set(dev, time);
35 int dm_rtc_reset(struct udevice *dev)
37 struct rtc_ops *ops = rtc_get_ops(dev);
42 return ops->reset(dev);
45 int dm_rtc_read(struct udevice *dev, unsigned int reg, u8 *buf, unsigned int len)
47 struct rtc_ops *ops = rtc_get_ops(dev);
51 return ops->read(dev, reg, buf, len);
55 int ret = ops->read8(dev, reg++);
64 int dm_rtc_write(struct udevice *dev, unsigned int reg,
65 const u8 *buf, unsigned int len)
67 struct rtc_ops *ops = rtc_get_ops(dev);
71 return ops->write(dev, reg, buf, len);
75 int ret = ops->write8(dev, reg++, *buf++);
83 int rtc_read8(struct udevice *dev, unsigned int reg)
85 struct rtc_ops *ops = rtc_get_ops(dev);
89 return ops->read8(dev, reg);
92 int ret = ops->read(dev, reg, buf, 1);
101 int rtc_write8(struct udevice *dev, unsigned int reg, int val)
103 struct rtc_ops *ops = rtc_get_ops(dev);
107 return ops->write8(dev, reg, val);
111 return ops->write(dev, reg, buf, 1);
116 int rtc_read16(struct udevice *dev, unsigned int reg, u16 *valuep)
122 for (i = 0; i < sizeof(value); i++) {
123 ret = rtc_read8(dev, reg + i);
126 value |= ret << (i << 3);
133 int rtc_write16(struct udevice *dev, unsigned int reg, u16 value)
137 for (i = 0; i < sizeof(value); i++) {
138 ret = rtc_write8(dev, reg + i, (value >> (i << 3)) & 0xff);
146 int rtc_read32(struct udevice *dev, unsigned int reg, u32 *valuep)
152 for (i = 0; i < sizeof(value); i++) {
153 ret = rtc_read8(dev, reg + i);
156 value |= ret << (i << 3);
163 int rtc_write32(struct udevice *dev, unsigned int reg, u32 value)
167 for (i = 0; i < sizeof(value); i++) {
168 ret = rtc_write8(dev, reg + i, (value >> (i << 3)) & 0xff);
176 UCLASS_DRIVER(rtc) = {
179 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
180 .post_bind = dm_scan_fdt_dev,