Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp940722rwl; Thu, 10 Aug 2023 04:14:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEk86FBO4rfpFQVecJpIddsZZrZ8uNDQA+MLJMvW3EZvJLrIx/r14Xww+dKBKl5aoJ8XoCH X-Received: by 2002:a05:6870:61d0:b0:1bf:1a58:c4f with SMTP id b16-20020a05687061d000b001bf1a580c4fmr2395865oah.55.1691666040552; Thu, 10 Aug 2023 04:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691666040; cv=none; d=google.com; s=arc-20160816; b=Sggpe8aESJ94r/KEYHyYN4I7M9gw0vUhUYlIzEM0Xw+WZxBhfE+1k4nINneHY9JB37 FdUIEA1UqyXB0ixbqrRC6JYTmL0q7HWbTAqq906xeEuj6TvFPX6HXY4eq6pmIKYbEBmo 65obt0jSRcBvwF9oJexfiV+YZIDdvIng742puLP8cyIpP8+uYhNVwyhxcyJysM9ATIvX qMSW4JCsyeOaehgHJdUoXbRw3mnvAMeTTdyGeecQk6NH1zRt0BRpN24HeCxz0Zxfr5xZ eeE9ZSfNtaTb6PeWz58O9Bxm0nzIu5TaP3o/hSRrvqtQ9eCigcsQ2vgnPM+6zq97QhnB HpYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=2ht3VL/Ute0f0NpKuJCr8WI+TjnXswoA7IO1WC8WBAU=; fh=tV74xdZ+BLJcXJ9e2kRzMh3fSv0q5NC0zjbC1XyHqnk=; b=hgC5wX/HFarD2I8CZHTGJiNhsDkjxhg1Wf5c/4p6CYt37BxLjKS9Hg+wELdQpvoS+E JmJl0FnoziknQrJQESwz7IWvC0FrX38BkKBNhsTAcov+/uNlVzDf7V7LdJvp2vVQGjej ojneSAKI4tP7CIoXVvTsD0w+Pq5+qB10SIZqemIBEkQzFCAoATJPRSxFH+SPdIUtkRTD VdzHcvk0Z7ImMPBXXOQ+gxppKW+pKAYPKfA6LAO+bvXyFYs+dLsTspXFJGvlpjl2+Kix ATiMIkDcuaJunjRJS9Qnzvso1wf1Md7+yBP2LS8yeq1Bm529EdHJb2lNBZm9PKaYuDVn snlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Du/F3XNK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a17090acf8500b00262e1adb2c7si3400017pju.51.2023.08.10.04.13.47; Thu, 10 Aug 2023 04:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Du/F3XNK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234497AbjHJJne (ORCPT + 99 others); Thu, 10 Aug 2023 05:43:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjHJJnc (ORCPT ); Thu, 10 Aug 2023 05:43:32 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D2B21BCF; Thu, 10 Aug 2023 02:43:32 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bc0d39b52cso5183385ad.2; Thu, 10 Aug 2023 02:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691660612; x=1692265412; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=2ht3VL/Ute0f0NpKuJCr8WI+TjnXswoA7IO1WC8WBAU=; b=Du/F3XNKyw207VcXml+AY4g3uFJ1aRsJY3WvB/ujeTunAkzJfZ6hJuiWmp4ktzf0mq cU6wRhW2OijJvyigoCR8PhNMtufVeq8Nr14YOlC6tzLg1rYrAmZW7v9Xoj8T11qgNVlQ un7BfkUMf3iQxUscOUPPor5fG/o2zAc+Pz+qqnCLP5Ds0/HRdL5rnvdcnc6JzM06+iw3 PA2xYtiux/7Yaj+EqNmTfekyWN74aJnJOveipih4yfMzBIrM78hd8863FeEq1+El/t8z TGaubqXThoc9zbX4ktmEBIYJlTKSNPlSGmu4pNJ/4H1IyHtarxqun6b0Zbek67OXGgDJ 98qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691660612; x=1692265412; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2ht3VL/Ute0f0NpKuJCr8WI+TjnXswoA7IO1WC8WBAU=; b=d/VEwYVQTrTvF9FnCn5lcyLwaI+N6lVvogz3bde4WSN4YpyMuaFvJeNHowYLL0mQpL qHtcD0XHMeKNeJqS6ZhX79dwYQ4mbDBWSliID+nXGKjUbPJz4veRJbsyk/xojDu3m7W6 TCcVS0qwhAVEmCurABadXXcwIJWTirUo2OLOUrOw7uj8nf+pmlhs074+MpjgcJBk4ZP9 Z6w0kyG1Ts2IrBagAdi7hL5D229won29w8gQFd/N4wGf6tmMODAf7+TuTj3wNJx7w3Va 0L/XdYJ5KS2zRtai4lM3X9Wu1rg64r4s7hApobSTaHVFH7QwW9T3l6Krkl+jcJ3hScg/ 3hpg== X-Gm-Message-State: AOJu0YyILnu693fiqz59TFZNEDeZQOXDGq6f/6bkLxxNZsATR3HzP51v CqqYr64IezEVAIY29MjC8m0= X-Received: by 2002:a17:902:aa0c:b0:1b8:847d:973a with SMTP id be12-20020a170902aa0c00b001b8847d973amr1486435plb.46.1691660611621; Thu, 10 Aug 2023 02:43:31 -0700 (PDT) Received: from localhost.localdomain (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id bi8-20020a170902bf0800b001bba3650448sm1233665plb.258.2023.08.10.02.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 02:43:31 -0700 (PDT) From: Mia Lin To: avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, a.zummo@towertech.it, alexandre.belloni@bootlin.com, KWLIU@nuvoton.com, JJLIU0@nuvoton.com, KFLIN@nuvoton.com, mylin1@nuvoton.com Cc: openbmc@lists.ozlabs.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, Mia Lin Subject: [PATCH v3 1/1] rtc: nuvoton: Compatible with NCT3015Y-R and NCT3018Y-R Date: Thu, 10 Aug 2023 17:43:23 +0800 Message-Id: <20230810094323.20077-2-mimi05633@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230810094323.20077-1-mimi05633@gmail.com> References: <20230810094323.20077-1-mimi05633@gmail.com> X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - In probe, If part number is NCT3018Y-R, only set HF bit to 24-Hour format. Else, do nothing - In set_time, If part number is NCT3018Y-R && TWO bit is 0, change TWO bit to 1, and restore TWO bit after updating time. Signed-off-by: Mia Lin --- drivers/rtc/rtc-nct3018y.c | 63 ++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c index a4e3f924837e..bac1e3fbbbcd 100644 --- a/drivers/rtc/rtc-nct3018y.c +++ b/drivers/rtc/rtc-nct3018y.c @@ -23,6 +23,7 @@ #define NCT3018Y_REG_CTRL 0x0A /* timer control */ #define NCT3018Y_REG_ST 0x0B /* status */ #define NCT3018Y_REG_CLKO 0x0C /* clock out */ +#define NCT3018Y_REG_PART 0x21 /* part info */ #define NCT3018Y_BIT_AF BIT(7) #define NCT3018Y_BIT_ST BIT(7) @@ -37,6 +38,7 @@ #define NCT3018Y_REG_BAT_MASK 0x07 #define NCT3018Y_REG_CLKO_F_MASK 0x03 /* frequenc mask */ #define NCT3018Y_REG_CLKO_CKE 0x80 /* clock out enabled */ +#define NCT3018Y_REG_PART_NCT3018Y 0x02 struct nct3018y { struct rtc_device *rtc; @@ -52,7 +54,7 @@ static int nct3018y_set_alarm_mode(struct i2c_client *client, bool on) dev_dbg(&client->dev, "%s:on:%d\n", __func__, on); - flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); if (flags < 0) { dev_dbg(&client->dev, "Failed to read NCT3018Y_REG_CTRL\n"); @@ -109,8 +111,10 @@ static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *ala *alarm_flag = flags & NCT3018Y_BIT_AF; } - dev_dbg(&client->dev, "%s:alarm_enable:%x alarm_flag:%x\n", - __func__, *alarm_enable, *alarm_flag); + if (alarm_enable && alarm_flag) { + dev_dbg(&client->dev, "%s:alarm_enable:%x alarm_flag:%x\n", + __func__, *alarm_enable, *alarm_flag); + } return 0; } @@ -178,7 +182,30 @@ static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm) { struct i2c_client *client = to_i2c_client(dev); unsigned char buf[4] = {0}; - int err; + int err, part_num, flags, restore_flags = 0; + + part_num = i2c_smbus_read_byte_data(client, NCT3018Y_REG_PART); + if (part_num < 0) { + dev_dbg(&client->dev, "%s: read error\n", __func__); + return part_num; + } + + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); + if (flags < 0) { + dev_dbg(&client->dev, "%s: read error\n", __func__); + return flags; + } + + /* Check and set TWO bit */ + if ((part_num & NCT3018Y_REG_PART_NCT3018Y) && !(flags & NCT3018Y_BIT_TWO)) { + restore_flags = 1; + flags |= NCT3018Y_BIT_TWO; + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); + if (err < 0) { + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); + return err; + } + } buf[0] = bin2bcd(tm->tm_sec); err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SC, buf[0]); @@ -212,6 +239,18 @@ static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm) return -EIO; } + /* Restore TWO bit */ + if (restore_flags) { + if (part_num & NCT3018Y_REG_PART_NCT3018Y) + flags &= ~NCT3018Y_BIT_TWO; + + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); + if (err < 0) { + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); + return err; + } + } + return err; } @@ -479,11 +518,17 @@ static int nct3018y_probe(struct i2c_client *client) dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is set\n", __func__); } - flags = NCT3018Y_BIT_TWO; - err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); - if (err < 0) { - dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); - return err; + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_PART); + if (flags < 0) { + dev_dbg(&client->dev, "%s: read error\n", __func__); + return flags; + } else if (flags & NCT3018Y_REG_PART_NCT3018Y) { + flags = NCT3018Y_BIT_HF; + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); + if (err < 0) { + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); + return err; + } } flags = 0; -- 2.17.1