From patchwork Tue Jun 11 07:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q3PDs2vDoXMgQmVuY2U=?= X-Patchwork-Id: 1946150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (4096-bit key; unprotected) header.d=prolan.hu header.i=@prolan.hu header.a=rsa-sha256 header.s=mail header.b=czhZ7nEb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-rtc+bounces-1272-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vz0YV0L9Fz20Tk for ; Tue, 11 Jun 2024 17:24:45 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 51218B22E6F for ; Tue, 11 Jun 2024 07:24:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9ED8B171094; Tue, 11 Jun 2024 07:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="czhZ7nEb" X-Original-To: linux-rtc@vger.kernel.org Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B46C26AF6; Tue, 11 Jun 2024 07:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718090679; cv=none; b=PPpCvFMURIysrXMk4+LJzRQdJr6lKqUd6vlik7T42xU4Hcab3FQV7qNtH1fWcxKCFTQ4iwhDohWsqEAclhNKEwfnjS9UqL5snyiGrgfID39FXIAAKI/g/akaoP2R6rP56CAOSZ4OL473ZZYu+FSkTpjB8XXtWr+zx7Di/vLTLPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718090679; c=relaxed/simple; bh=cNKJBff2JjmgIeBtk0fH5JDTmZVQLoGJcT2ZaD1G5JY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=alTzIIB79AzvkF+YF1HXCciqlBBqs/3knB3MBsPzZ8DABwujkM86ie0MPyar8dlZoHWvJUt/vVc3ztVpSy4gNsrmfl8880QAWkgVQJaFQXiUL3zq3U6J6pxheKUd59Lt/Bqb4NmQFjEoO0HCsi9VHJQulBQrMkZuPsCsoYH+inE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=czhZ7nEb; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 78CA8A09A1; Tue, 11 Jun 2024 09:24:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:message-id:mime-version:reply-to:subject:subject:to :to; s=mail; bh=nxOoWzJj6x8CbfgrQF46F7yU7jRVDYeEowyAEH5Wuic=; b= czhZ7nEbYNkbdkAzdzShMWGTOEKQXzK6nCIoYYe2QXSgjZoZeJlfBYfubbBkyK1X snrHepAgKJ/ZFkkIMtb2nwUJhKgUOYu2+DnhTuA0QfwKI1lTZPmC8XBrqpUcJOgD gTOoNtpnRF9Rd76P4A3wk3OYQ2Rc9YiQegYVmzVB3uNAmB0BIFt3r4wpssZMLwul B0I3AU9D93CcO69WVksqpy8FAzSzeqyfEr3X0e8UA+GfUe+rnSqqdm9ti8eFkvMM XMB4tZ56XArn6gYPjNxf5TR/c4Ke+srmO43ZPoQDZYo6LQbg90c59jQUlKkJW0jF 7hGbG7aCYEQiflfMINuu1XZV6NK2cJjE2DRGrEPK7vvxJ//qQ2y8sad5Pl7/lGAy L/rEpA9OsrKneNnYmhlWTltobTGnMtVI18YlLqvcHTMV1aJoW41hpSFrqWUXMbqf 76dTcup/MErGM1xa9Gbq36HdQH5KimHSXV0Eczbu04EJqZ6tbBDkzd9qWFsTfHBi 9Ug9UDJb0h7zIkVZFDMAmWxqL2I7t2WAFRffYicU8KSlU0lOkgnR6/Xr2ZOy46UZ io/SglhGEHCy/anAfyBvElaMsSlhAADIBZFN/Ds07PafT2jZVzMsDKpm4yGr8/IJ tP3ASMoiVSUqZKnBUMvc5Kn1vTaRsUctdrOePAuofQ4= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , =?utf-8?q?Sze?= =?utf-8?q?ntendrei=2C_Tam=C3=A1s?= , Alexandre Belloni Subject: [PATCH v2 1/2] rtc: ds1307: Detect oscillator fail on mcp794xx Date: Tue, 11 Jun 2024 09:24:08 +0200 Message-ID: <20240611072411.671600-1-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.45.2.437.gf7de8c0566 Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1718090671;VERSION=7972;MC=2743792726;ID=507903;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29916D3B54627C61 This patch enables the detection of the oscillator failure on mcp794xx chips. Co-developed-by: Szentendrei, Tamás Signed-off-by: Szentendrei, Tamás Signed-off-by: Csókás, Bence --- drivers/rtc/rtc-ds1307.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 506b7d1c2397..bdb7b201a160 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -65,6 +65,7 @@ enum ds_type { # define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */ # define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */ #define DS1307_REG_WDAY 0x03 /* 01-07 */ +# define MCP794XX_BIT_OSCRUN BIT(5) # define MCP794XX_BIT_VBATEN 0x08 #define DS1307_REG_MDAY 0x04 /* 01-31 */ #define DS1307_REG_MONTH 0x05 /* 01-12 */ @@ -242,6 +243,10 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t) regs[DS1307_REG_MIN] & M41T0_BIT_OF) { dev_warn_once(dev, "oscillator failed, set time!\n"); return -EINVAL; + } else if (ds1307->type == mcp794xx && + !(regs[DS1307_REG_WDAY] & MCP794XX_BIT_OSCRUN)) { + dev_warn_once(dev, "oscillator failed, set time!\n"); + return -EINVAL; } tmp = regs[DS1307_REG_SECS]; From patchwork Tue Jun 11 07:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q3PDs2vDoXMgQmVuY2U=?= X-Patchwork-Id: 1946149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (4096-bit key; unprotected) header.d=prolan.hu header.i=@prolan.hu header.a=rsa-sha256 header.s=mail header.b=VWxMbzur; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-rtc+bounces-1273-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vz0YT4xRfz20Py for ; Tue, 11 Jun 2024 17:24:45 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CA33628BAD7 for ; Tue, 11 Jun 2024 07:24:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E20AB171E58; Tue, 11 Jun 2024 07:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="VWxMbzur" X-Original-To: linux-rtc@vger.kernel.org Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 239B813D8BA; Tue, 11 Jun 2024 07:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718090679; cv=none; b=bEwCQsxylAvkeC2QFYCJj53wO8EH3jKlIpv6Dt7rgwiGNipOAfut+ONBd1Mxq5XbMqwh/0qbC0/D4dclFxYc2wjNKwF2wjJ788S40nSC3AO08to6DkKlBrII0i13q/uHsAEWd4AULmQXPfWruBEpux6qymNW7u3eZNL8XPOJ/l0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718090679; c=relaxed/simple; bh=/BViwiv7ODDGxwqmgG1UcvqUTvS9SkMogPTYvFA1l/o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NpOfpI5ABbsMTF9+y8w+3CrFNPyqS1m5YtPfn6IXQi14arfp74z7flKrow68cJGS03Fn/YMlDkm2KAaANz40TL+7xIPAs4QrXk/Yhu2biVcvZkntpU6HCSOzQEZcokutza5Ig+Usv7QQLx9tbu2GkK2CJrCymTbfNJYdA3XByss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=VWxMbzur; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 072E8A0A2C; Tue, 11 Jun 2024 09:24:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=mail; bh=Lyr4vKbJDlBYGx7GCBBG E5ECzYDxemWMfM7u2PghLS8=; b=VWxMbzurSef2hfVcbJaRiXq1SAMn+Kma44iI u+MCq2a7ztINQojHBxYyRkWi5Q5YKljbQhs1QiXuc/ceiQDdtcwg9LRndK2FOh+N xjhTBDous4DdKkKXjC65TsP7CcX8gLlj6cMEP9x4qPfj7gikpOaV1S2+mXNIbd20 HTt4qUwUf41KfuWoDUk9398p6rMz+taNcV5nnGRei6tXRBZsD+8lTxP+1Kfoioqg VY8KATsEsVfZYVng+FhVtaBNRe7+ypMaZ5HFoKvK8G5CFkBH8uzBwrVZzw7aArrB LKzgFJ8lv6dbVp0JW5OGWv1I1IcQLwaKjQCn1DGHHEZZypTACMD6dwMuUQCfbkGL DBwoYxHC0kClDIxan2WxjXjOaOKHODqGJkjvs3qfnaiygMYOCIQWa5ZWl83K3lLQ SuoXkSb47Glv1uG2iuln0gkyo1ZF6nabyO9HRlWSg8yTOPWNQgt5yB+wmBTeKA3u I4CoA1rY6cDOAiF206M/tj+2yhmLSyjqjRytanbTUtWUDgaDpKiWokgjNndTgQY3 anRuafDg1YO8lXLQT5uOMWXyV8//1Gbwb8GJ0MGgJupthrNF/rIj/cSSloHW6f8x HVmxbA63YXWdhHYSwFUlyYjnh3bCNnETqSkcwXPignN6tFNMhgp8VsSpxoHwexkx 4kfnyuw= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , =?utf-8?q?Sze?= =?utf-8?q?ntendrei=2C_Tam=C3=A1s?= , Alexandre Belloni Subject: [PATCH v2 2/2] rtc: ds1307: Clamp year to valid BCD (0-99) in `set_time()` Date: Tue, 11 Jun 2024 09:24:09 +0200 Message-ID: <20240611072411.671600-2-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.45.2.437.gf7de8c0566 In-Reply-To: <20240611072411.671600-1-csokas.bence@prolan.hu> References: <20240611072411.671600-1-csokas.bence@prolan.hu> Precedence: bulk X-Mailing-List: linux-rtc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1718090673;VERSION=7972;MC=1998882007;ID=507904;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29916D3B54627C61 `tm_year` may go up to 299 if the device supports the century bit. Therefore, subtracting may not give us a valid 2-digit number, but modulo does. Co-developed-by: Szentendrei, Tamás Signed-off-by: Szentendrei, Tamás Signed-off-by: Csókás, Bence --- drivers/rtc/rtc-ds1307.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index bdb7b201a160..872e0b679be4 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -359,7 +359,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); /* assume 20YY not 19YY */ - tmp = t->tm_year - 100; + tmp = t->tm_year % 100; regs[DS1307_REG_YEAR] = bin2bcd(tmp); if (chip->century_enable_bit)