From nobody Sun May 3 19:11:56 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g7vXX5Pdtz6bv2V for ; Sun, 03 May 2026 19:11:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g7vXX3bMVz3pZm for ; Sun, 03 May 2026 19:11:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777835516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QMHBsmiaTjISfdjSUxDuZKQkRhYODwyehD7PXmv/CpI=; b=PYCULErfLtOf6TzgrDwLDFBaB2u11LHmMWU2OjDMfMnSRgbB/lcibeblaPN+hrMJI9Dnz7 FYhbi3lp6ZpjHgqhHc97GgBPVl45KqXVh7igT1zaXuVVuACHmH4MgM3Djb/MOXpLZWeTN5 b0Viefq/Anqh8X7zhBi55wpcGTef4t9Pf7msU38SGAu+MK4xxEpzb+VoHFDHwe3JkWMllN uYhHjDuLkRCmwrsbdozlNvfRrkASMZIXk1ahwUqXyMnSurByZM5CKOuRx1uWZYb5lg1K9g Vfp1KOIkTRAJ/AS66R6ecpRIbElYWXcNQelnBWjb6HNzo+IxrAJBRlHLWKbyxQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777835516; a=rsa-sha256; cv=none; b=kXD+BXwlxMBObZbHKiSlyx5mRsW8I/Gn/Toh+zJZvy7Px6gX4NyGUiqMWOu5KY40Qjlnn0 N/t16x0IY89hsHVZQu3WybF0+4lE31BytiFQrTB8IKaZU2H1gfR+40ft6Mg104LbDYfqSP aHkPp0kdH4PXE2PXKX6Lo78U2Yo+okJiy2v81neZiJkG0TR625OzCXi0NiFrXs0dty+qrK YGxbqQFeHRscUmwjYzOIktREiVNhju4Lq7vMsH04upUQoX26ikgXlSG3Z9s4qbMQ7W+vqc 1NkMXqGpkuP8HEzcA643erBL3aV/aEl+bVL2Y/FiOAbSCZH7yD7ur0fN9sCaEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777835516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QMHBsmiaTjISfdjSUxDuZKQkRhYODwyehD7PXmv/CpI=; b=y4LeH2e0lQtA/pzabzeL0BLB5wCj/W+5iwDLE/b7VnXUv8JUjlnzk3JVTo0OpiWnJqKcHp x0myp3WBh6vspblxuyVxkOIUsB4Gpy9wC0hjZLHU0JNglSvPUGzF93B2kd5KLQVzuk3UJi QO4DPB24h8fFJbcoKZunH7XNAoAC32AZknp8it5Mb4AkHOrXoMFtWi1hqj8tcx1KHc4Y3X q6R6NoicjhEwuioxR9YuZiP5JSFYK4VvowFfIspOI/u9qsphyp29gIDNvG6C7X9xdR90uY 1Addc6I9+mDrbbe3q7q21qh+URi1PK1ugP6BIIfiPHB2Nsa48T303j3GIgpHQQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g7vXX37bBzmJZ for ; Sun, 03 May 2026 19:11:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ce8c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 03 May 2026 19:11:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: d22051b18e9b - main - iicbus/rtc: Add driver for the Ricoh rs5c372 RTC List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d22051b18e9b7512c5cf033d7b6eee2df03c985b Auto-Submitted: auto-generated Date: Sun, 03 May 2026 19:11:56 +0000 Message-Id: <69f79dfc.3ce8c.5b950eca@gitrepo.freebsd.org> The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=d22051b18e9b7512c5cf033d7b6eee2df03c985b commit d22051b18e9b7512c5cf033d7b6eee2df03c985b Author: Justin Hibbits AuthorDate: 2026-04-22 02:15:02 +0000 Commit: Justin Hibbits CommitDate: 2026-05-03 19:09:28 +0000 iicbus/rtc: Add driver for the Ricoh rs5c372 RTC This RTC chip supports 2 alarm timers in addition to RTC functionality, but this driver only supports the RTC at this time. --- sys/conf/files | 1 + sys/dev/iicbus/rtc/rs5c372a.c | 182 ++++++++++++++++++++++++++++++++++++++ sys/modules/i2c/Makefile | 1 + sys/modules/i2c/rs5c372a/Makefile | 14 +++ 4 files changed, 198 insertions(+) diff --git a/sys/conf/files b/sys/conf/files index 2b4a453ca556..6804c9c81c69 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1858,6 +1858,7 @@ dev/iicbus/rtc/hym8563.c optional hym8563 iicbus fdt dev/iicbus/rtc/isl12xx.c optional isl12xx dev/iicbus/rtc/nxprtc.c optional nxprtc | pcf8563 dev/iicbus/rtc/pcf85063.c optional pcf85063 iicbus fdt +dev/iicbus/rtc/rs5c372a.c optional rs5c372a iicbus fdt dev/iicbus/rtc/rtc8583.c optional rtc8583 dev/iicbus/rtc/rv3032.c optional rv3032 iicbus fdt dev/iicbus/rtc/rx8803.c optional rx8803 iicbus fdt diff --git a/sys/dev/iicbus/rtc/rs5c372a.c b/sys/dev/iicbus/rtc/rs5c372a.c new file mode 100644 index 000000000000..c5743e840d25 --- /dev/null +++ b/sys/dev/iicbus/rtc/rs5c372a.c @@ -0,0 +1,182 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Justin Hibbits + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "clock_if.h" +#include "iicbus_if.h" + +/* + * Driver for the Richo rs5c372a RTC. The chip itself includes 2 alarm clocks + * in addition to the clock component, but this driver offers only the RTC + * component. + * + * Like many other RTCs, this reports the date and time in BCD. + * + * The `Hour' register uses bit 5 in a dual role: In 24-hour time, it's a part + * of the first digit (0, 1, 2). In 12-hour time it denotes PM, so 12PM is + * reported as 0x32, 1PM is 0x21, etc. + */ +#define RS5C372_REG_SEC 0x0 +#define RS5C372_REG_MIN 0x1 +#define RS5C372_REG_HOUR 0x2 +#define HOUR_HR_M 0x1f +#define HOUR_PM 0x20 +#define RS5C372_REG_DOW 0x3 +#define RS5C372_REG_DAY 0x4 +#define RS5C372_REG_MON 0x5 +#define RS5C372_REG_YEAR 0x6 +#define RS5C372_REG_CTRL1 0xe +#define RS5C372_REG_CTRL2 0xf +#define CTRL_PM 0x20 + +static struct ofw_compat_data compat_data[] = { + { "ricoh,rs5c372a", 1 }, + { NULL, 0 } +}; + +static int +rs5c372a_gettime(device_t dev, struct timespec *ts) +{ + struct bcd_clocktime ct = {}; + uint8_t clock_regs[7]; + int err; + uint8_t ctrl2; + bool is_12hr = true; + + err = iicdev_readfrom(dev, RS5C372_REG_CTRL2, &ctrl2, + sizeof(ctrl2), IIC_WAIT); + if (err != 0) + return (err); + err = iicdev_readfrom(dev, RS5C372_REG_SEC, clock_regs, + sizeof(clock_regs), IIC_WAIT); + if (err != 0) + return (err); + + if (ctrl2 & CTRL_PM) + is_12hr = false; + ct.sec = clock_regs[RS5C372_REG_SEC]; + ct.min = clock_regs[RS5C372_REG_MIN]; + ct.hour = clock_regs[RS5C372_REG_HOUR]; + ct.dow = clock_regs[RS5C372_REG_DOW]; + ct.day = clock_regs[RS5C372_REG_DAY]; + ct.mon = clock_regs[RS5C372_REG_MON]; + ct.year = clock_regs[RS5C372_REG_YEAR]; + + if (is_12hr) { + ct.ispm = ct.hour & HOUR_PM; + ct.hour &= HOUR_HR_M; + } + clock_bcd_to_ts(&ct, ts, ct.ispm); + + return (0); +} + +static int +rs5c372a_settime(device_t dev, struct timespec *ts) +{ + struct bcd_clocktime ct; + uint8_t clock_regs[7]; + uint8_t ctrl2; + int err; + bool is_12hr = true; + + err = iicdev_readfrom(dev, RS5C372_REG_CTRL2, &ctrl2, + sizeof(ctrl2), IIC_WAIT); + if (err != 0) + return (err); + if (ctrl2 & CTRL_PM) + is_12hr = false; + clock_ts_to_bcd(ts, &ct, is_12hr); + clock_regs[RS5C372_REG_SEC] = ct.sec; + clock_regs[RS5C372_REG_MIN] = ct.min; + clock_regs[RS5C372_REG_HOUR] = ct.hour; + clock_regs[RS5C372_REG_DAY] = ct.day; + clock_regs[RS5C372_REG_DOW] = ct.dow; + clock_regs[RS5C372_REG_MON] = ct.mon; + clock_regs[RS5C372_REG_YEAR] = ct.year & 0xff; + + if (is_12hr) { + if (ct.ispm) + clock_regs[RS5C372_REG_HOUR] |= HOUR_PM; + } + + err = iicdev_writeto(dev, RS5C372_REG_SEC, clock_regs, + sizeof(clock_regs), IIC_WAIT); + + return (err); +} + +static int +rs5c372a_probe(device_t dev) +{ + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "Richo RS5C372A RTC"); + + return (BUS_PROBE_DEFAULT); +} + +static int +rs5c372a_attach(device_t dev) +{ + + /* Register with 1s resolution */ + clock_register(dev, 1000000); + clock_schedule(dev, 1); + return (0); +} + +static device_method_t rs5c372a_methods[] = { + /* Device methods */ + DEVMETHOD(device_probe, rs5c372a_probe), + DEVMETHOD(device_attach, rs5c372a_attach), + + /* Clock methods */ + DEVMETHOD(clock_gettime, rs5c372a_gettime), + DEVMETHOD(clock_settime, rs5c372a_settime), + DEVMETHOD_END +}; + + +DEFINE_CLASS_0(rs5c372a, rs5c372a_driver, rs5c372a_methods, 0); +DRIVER_MODULE(rs5c372a, iicbus, rs5c372a_driver, NULL, NULL); +MODULE_VERSION(rs5c372a, 1); +MODULE_DEPEND(rs5c372a, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER); +IICBUS_FDT_PNP_INFO(compat_data); diff --git a/sys/modules/i2c/Makefile b/sys/modules/i2c/Makefile index 6561327abfca..ff4536694dfc 100644 --- a/sys/modules/i2c/Makefile +++ b/sys/modules/i2c/Makefile @@ -28,6 +28,7 @@ SUBDIR = \ .if !empty(OPT_FDT) SUBDIR += hym8563 \ + rs5c372a \ rv3032 \ rx8803 \ tca64xx \ diff --git a/sys/modules/i2c/rs5c372a/Makefile b/sys/modules/i2c/rs5c372a/Makefile new file mode 100644 index 000000000000..3bd387115a8a --- /dev/null +++ b/sys/modules/i2c/rs5c372a/Makefile @@ -0,0 +1,14 @@ +.PATH: ${SRCTOP}/sys/dev/iicbus/rtc/ +KMOD = rs5c372a +SRCS = rs5c372a.c + +# Generated files... +SRCS+= \ + bus_if.h \ + clock_if.h \ + device_if.h \ + iicbus_if.h \ + opt_platform.h \ + ofw_bus_if.h \ + +.include