"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtc: add ds1672 driver

Add support for Dallas/Maxim ds1672 32bit counter RTC.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>

authored by

Tim Harvey and committed by
Tom Rini
e63e088b 29cb98d5

+125
+7
drivers/rtc/Kconfig
··· 94 94 Support for Dallas Semiconductor (now Maxim) DS1374 and compatible 95 95 Real Time Clock devices. 96 96 97 + config RTC_DS1672 98 + bool "Enable DS1672 driver" 99 + depends on DM_RTC 100 + help 101 + Support for Dallas Semiconductor (now Maxim) DS1672 compatible 102 + Real Time Clock devices. 103 + 97 104 config RTC_DS3231 98 105 bool "Enable DS3231 driver" 99 106 help
+1
drivers/rtc/Makefile
··· 12 12 obj-$(CONFIG_RTC_DS1338) += ds1307.o 13 13 obj-$(CONFIG_RTC_DS1337) += ds1337.o 14 14 obj-$(CONFIG_RTC_DS1374) += ds1374.o 15 + obj-$(CONFIG_RTC_DS1672) += ds1672.o 15 16 obj-$(CONFIG_RTC_DS3231) += ds3231.o 16 17 obj-$(CONFIG_RTC_DS3232) += ds3232.o 17 18 obj-$(CONFIG_RTC_EMULATION) += emul_rtc.o
+117
drivers/rtc/ds1672.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Analog Devices DS1672 I2C RTC driver 4 + * 5 + * Copyright 2025 Gateworks Corporation. 6 + */ 7 + #include <dm.h> 8 + #include <i2c.h> 9 + #include <rtc.h> 10 + #include <dm/device_compat.h> 11 + 12 + /* Registers */ 13 + #define DS1672_REG_CNT_BASE 0 14 + #define DS1672_REG_CONTROL 4 15 + #define DS1672_REG_TRICKLE 5 16 + 17 + #define DS1672_REG_CONTROL_EOSC 0x80 18 + 19 + static int ds1672_read_time(struct udevice *dev, struct rtc_time *tm) 20 + { 21 + time64_t secs; 22 + u8 regs[4]; 23 + int ret; 24 + 25 + ret = dm_i2c_read(dev, DS1672_REG_CONTROL, regs, 1); 26 + if (ret) 27 + return ret; 28 + 29 + if (regs[0] & DS1672_REG_CONTROL_EOSC) { 30 + dev_err(dev, "Oscillator not enabled. Set time to enable.\n"); 31 + return -EINVAL; 32 + } 33 + 34 + ret = dm_i2c_read(dev, DS1672_REG_CNT_BASE, regs, 4); 35 + if (ret) 36 + return ret; 37 + dev_dbg(dev, "raw read: 0x%02x 0x%02x 0x%02x 0x%02x\n", 38 + regs[0], regs[1], regs[2], regs[3]); 39 + secs = ((unsigned long)regs[3] << 24) | (regs[2] << 16) | (regs[1] << 8) | regs[0]; 40 + rtc_to_tm(secs, tm); 41 + 42 + dev_dbg(dev, "read %lld %4d-%02d-%02d (wday=%d) %2d:%02d:%02d\n", secs, 43 + tm->tm_year, tm->tm_mon, tm->tm_mday, 44 + tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec); 45 + 46 + return 0; 47 + } 48 + 49 + static int ds1672_set_time(struct udevice *dev, const struct rtc_time *tm) 50 + { 51 + time64_t secs = rtc_mktime(tm); 52 + u8 regs[5]; 53 + 54 + dev_dbg(dev, "set %4d-%02d-%02d (wday=%d) %2d:%02d:%02d %lld\n", 55 + tm->tm_year, tm->tm_mon, tm->tm_mday, 56 + tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec, 57 + secs); 58 + 59 + if (tm->tm_year < 2000) { 60 + dev_err(dev, "year %d (before 2000) not supported\n", 61 + tm->tm_year); 62 + return -EINVAL; 63 + } 64 + 65 + regs[0] = secs & 0x000000ff; 66 + regs[1] = (secs & 0x0000ff00) >> 8; 67 + regs[2] = (secs & 0x00ff0000) >> 16; 68 + regs[3] = (secs & 0xff000000) >> 24; 69 + regs[4] = 0; /* set control reg to enable counting */ 70 + 71 + return dm_i2c_write(dev, DS1672_REG_CNT_BASE, regs, 5); 72 + } 73 + 74 + static int ds1672_reset(struct udevice *dev) 75 + { 76 + u8 regs[5] = { 0 }; 77 + 78 + return dm_i2c_write(dev, DS1672_REG_CNT_BASE, regs, 5); 79 + } 80 + 81 + static int ds1672_read8(struct udevice *dev, unsigned int reg) 82 + { 83 + return dm_i2c_reg_read(dev, reg); 84 + } 85 + 86 + static int ds1672_write8(struct udevice *dev, unsigned int reg, int val) 87 + { 88 + return dm_i2c_reg_write(dev, reg, val); 89 + } 90 + 91 + static const struct rtc_ops ds1672_rtc_ops = { 92 + .get = ds1672_read_time, 93 + .set = ds1672_set_time, 94 + .reset = ds1672_reset, 95 + .read8 = ds1672_read8, 96 + .write8 = ds1672_write8, 97 + }; 98 + 99 + static int ds1672_probe(struct udevice *dev) 100 + { 101 + i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS); 102 + 103 + return 0; 104 + } 105 + 106 + static const struct udevice_id ds1672_of_id[] = { 107 + { .compatible = "dallas,ds1672" }, 108 + { } 109 + }; 110 + 111 + U_BOOT_DRIVER(rtc_max313xx) = { 112 + .name = "rtc-ds1672", 113 + .id = UCLASS_RTC, 114 + .probe = ds1672_probe, 115 + .of_match = ds1672_of_id, 116 + .ops = &ds1672_rtc_ops, 117 + };