+static int rtc_mc146818_write8(struct udevice *dev, unsigned int reg, int val)
+{
+ mc146818_write8(reg, val);
+
+ return 0;
+}
+
+static int rtc_mc146818_probe(struct udevice *dev)
+{
+ mc146818_init();
+
+ return 0;
+}
+
+static const struct rtc_ops rtc_mc146818_ops = {
+ .get = rtc_mc146818_get,
+ .set = rtc_mc146818_set,
+ .reset = rtc_mc146818_reset,
+ .read8 = rtc_mc146818_read8,
+ .write8 = rtc_mc146818_write8,
+};
+
+static const struct udevice_id rtc_mc146818_ids[] = {
+ { .compatible = "motorola,mc146818" },
+ { }
+};
+
+U_BOOT_DRIVER(rtc_mc146818) = {
+ .name = "rtc_mc146818",
+ .id = UCLASS_RTC,
+ .of_match = rtc_mc146818_ids,
+ .probe = rtc_mc146818_probe,
+ .ops = &rtc_mc146818_ops,
+};
+
+#else /* !CONFIG_DM_RTC */
+
+int rtc_get(struct rtc_time *tmp)
+{
+ return mc146818_get(tmp);
+}
+
+int rtc_set(struct rtc_time *tmp)
+{
+ return mc146818_set(tmp);
+}
+
+void rtc_reset(void)
+{
+ mc146818_reset();
+}
+
+int rtc_read8(int reg)
+{
+ return mc146818_read8(reg);
+}
+
+void rtc_write8(int reg, uchar val)
+{
+ mc146818_write8(reg, val);
+}
+
+u32 rtc_read32(int reg)
+{
+ u32 value = 0;
+ int i;
+
+ for (i = 0; i < sizeof(value); i++)
+ value |= rtc_read8(reg + i) << (i << 3);
+
+ return value;
+}
+
+void rtc_write32(int reg, u32 value)
+{
+ int i;
+
+ for (i = 0; i < sizeof(value); i++)
+ rtc_write8(reg + i, (value >> (i << 3)) & 0xff);
+}
+
+void rtc_init(void)
+{
+ mc146818_init();
+}
+
+#endif /* CONFIG_DM_RTC */