From nobody Tue Oct 7 03:46:23 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70B0B24729F; Mon, 14 Jul 2025 21:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752529186; cv=none; b=MGLXpais1oeseINSnGQey4y9Xyx5AuDTynRzO24TJ9/TMHeNXoss/9huvR57+uxYQPHlb0nOA3B5NPbHn2LZXbP6werUyQYuGHFmZs7Qz3IRx59ZwEfrxmm9cYcSUxwTjElPs1TMg4vfbirDo6F+NTVttFMvuHNbpGpxKqO+MJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752529186; c=relaxed/simple; bh=+79Edwp/qYLvCGVhl6Z3Em+GmrxKyS+U+fc1Np6rWIo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=cNuuLZj+l3/fVLvpL5U7gMtKJcLunEvs1+3fWEJmSbJ1t/E5nOP9ciIx4n0n5ycf8cDR/8RiFEhozw94OuBx0ssxfG16evflO9tbYP7tv1fkds9hvwaI6sw4SmcjFhDenMsAJwp6SSncb2wKslQWAIALk6qZ0A9wRylYPUI/QrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=aoRmbDEq; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="aoRmbDEq" Received: by linux.microsoft.com (Postfix, from userid 1223) id 184BB201656A; Mon, 14 Jul 2025 14:39:45 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 184BB201656A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752529185; bh=cgM3cNFp900zGPUD8KYNP/L/K+MPUgDC4h8lo07VzRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aoRmbDEqQeLiKW5RVvFLYJoqDr9AZWsfvxAOFI6dbiSQjGoKmVj4/73rPlJVup76I le6nAJR+WGELysG7CJhghPe/LTmLFTgNO0iXZmvXEXIbNRAbF51tR1pavD6JzrSLW4 AYjAYGiofVbyK2DHUE4gcSvS9ipEktm81Qqv0jq0= From: Meagan Lloyd To: alexandre.belloni@bootlin.com Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, code@tyhicks.com, giometti@enneenne.com, Meagan Lloyd Subject: [PATCH RESEND 1/2] rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe Date: Mon, 14 Jul 2025 14:39:36 -0700 Message-Id: <1752529177-8154-2-git-send-email-meaganlloyd@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1752529177-8154-1-git-send-email-meaganlloyd@linux.microsoft.com> References: <1752529177-8154-1-git-send-email-meaganlloyd@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In using CONFIG_RTC_HCTOSYS, rtc_hctosys() will sync the RTC time to the kernel time as long as rtc_read_time() succeeds. In some power loss situations, our supercapacitor-backed DS1342 RTC comes up with either an unpredictable future time or the default 01/01/00 from the datasheet. The oscillator stop flag (OSF) is set in these scenarios due to the power loss and can be used to determine the validity of the RTC data. Some chip types in the ds1307 driver already have OSF handling to determine whether .read_time provides valid RTC data or returns -EINVAL. This change removes the clear of the OSF in .probe as the OSF needs to be preserved to expand the OSF handling to the ds1341 chip type (note that DS1341 and DS1342 share a datasheet). Signed-off-by: Meagan Lloyd Acked-by: Rodolfo Giometti Reviewed-by: Tyler Hicks --- Compile tested on rtc-next. Tested on an older kernel with ds1342 which has the same datasheet as ds1341. --- drivers/rtc/rtc-ds1307.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 5efbe69bf5ca8..65beb7067e3f5 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -1813,10 +1813,8 @@ static int ds1307_probe(struct i2c_client *client) regmap_write(ds1307->regmap, DS1337_REG_CONTROL, regs[0]); =20 - /* oscillator fault? clear flag, and warn */ + /* oscillator fault? warn */ if (regs[1] & DS1337_BIT_OSF) { - regmap_write(ds1307->regmap, DS1337_REG_STATUS, - regs[1] & ~DS1337_BIT_OSF); dev_warn(ds1307->dev, "SET TIME!\n"); } break; --=20 2.49.0 From nobody Tue Oct 7 03:46:23 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70A2624169E; Mon, 14 Jul 2025 21:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752529187; cv=none; b=f9BB+BumIIxpjM8MhUKMYkhwpY1XsjMSzKPLH912eDf8pLaGmLpwKsBnrrao5yf7jz0m2BAsQoMo5oTlMt26oYncFgq4oAUTFY4pTbbZ0Vf0h9Hl7wZilrt09KO6g4Rdaoz19dYBgKMjYKhpi2USPqNjcl2hgwjI4H/KpX9tAeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752529187; c=relaxed/simple; bh=lQHiDRm3P3P3+F4qTi3UQxbsulVGbiDymJqk+dqb0GQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=uNWdcEnaEI0Vcr3MZskSUe9NFVi6J97MaDBbT3BELyHor8+7XKGHLJHXiY8I1K97e54X9hZwOnaUOCHhhGYe8JS3w0y1YeSgWuSi3ZV2puVcm+KAZL7VHcBnxBFpb1JdXX4jcRXcUbhPyDs+80xDNcJSHELnNXCW1quFkmIfWaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Bb24q3VG; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Bb24q3VG" Received: by linux.microsoft.com (Postfix, from userid 1223) id 24DFA201656C; Mon, 14 Jul 2025 14:39:45 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 24DFA201656C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752529185; bh=c8JzThbzDRuG5s5PT5aamV4xZ70pe8DGsXYZyspNS10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bb24q3VGYJ6Qj1UcOgnIUZz49DRqwEAMEU+KcmWUpKAtMIp7jgZgJWgT7VScPsTdh za86tSifUOjW9oLXA1MEPbnYqEx1IIzI+x5hcb5woxM7MOjrAE3iCAKLgmvMzXXlD6 SM833h71YAlUJfRfYwzoWxr3Yj64Fazj/zjC7s88= From: Meagan Lloyd To: alexandre.belloni@bootlin.com Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, code@tyhicks.com, giometti@enneenne.com, Meagan Lloyd Subject: [PATCH RESEND 2/2] rtc: ds1307: handle oscillator stop flag (OSF) for ds1341 Date: Mon, 14 Jul 2025 14:39:37 -0700 Message-Id: <1752529177-8154-3-git-send-email-meaganlloyd@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1752529177-8154-1-git-send-email-meaganlloyd@linux.microsoft.com> References: <1752529177-8154-1-git-send-email-meaganlloyd@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In using CONFIG_RTC_HCTOSYS, rtc_hctosys() will sync the RTC time to the kernel time as long as rtc_read_time() succeeds. In some power loss situations, our supercapacitor-backed DS1342 RTC comes up with either an unpredictable future time or the default 01/01/00 from the datasheet. The oscillator stop flag (OSF) is set in these scenarios due to the power loss and can be used to determine the validity of the RTC data. This change expands the oscillator stop flag (OSF) handling that has already been implemented for some chips to the ds1341 chip (DS1341 and DS1342 share a datasheet). This handling manages the validity of the RTC data in .read_time and .set_time based on the OSF. Signed-off-by: Meagan Lloyd Acked-by: Rodolfo Giometti Reviewed-by: Tyler Hicks --- Compile tested on rtc-next. Tested on an older kernel with ds1342 which has the same datasheet as ds1341. --- drivers/rtc/rtc-ds1307.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 65beb7067e3f5..ce0994d9219a2 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -279,6 +279,13 @@ static int ds1307_get_time(struct device *dev, struct = rtc_time *t) if (tmp & DS1340_BIT_OSF) return -EINVAL; break; + case ds_1341: + ret =3D regmap_read(ds1307->regmap, DS1337_REG_STATUS, &tmp); + if (ret) + return ret; + if (tmp & DS1337_BIT_OSF) + return -EINVAL; + break; case ds_1388: ret =3D regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); if (ret) @@ -377,6 +384,10 @@ static int ds1307_set_time(struct device *dev, struct = rtc_time *t) regmap_update_bits(ds1307->regmap, DS1340_REG_FLAG, DS1340_BIT_OSF, 0); break; + case ds_1341: + regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, + DS1337_BIT_OSF, 0); + break; case ds_1388: regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, DS1388_BIT_OSF, 0); --=20 2.49.0