Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2993308rdb; Tue, 12 Sep 2023 20:39:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGutScdVheLSYUPsAlHO+VUmObFrclgboBCv9JmQE5F+babbiIEX+KCRpWU60ctV0WaxfM2 X-Received: by 2002:a17:902:8693:b0:1c0:cbaf:6930 with SMTP id g19-20020a170902869300b001c0cbaf6930mr1425129plo.54.1694576352478; Tue, 12 Sep 2023 20:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694576352; cv=none; d=google.com; s=arc-20160816; b=r+iM5OMJo13ELKHx8pdMk63292koFEK3co+XBODenaeOrtl7D2yyB8JJUMap3Q7AvJ F9YLazeDwEIUXHYC6w1E5Xc7uGN0KhYp7dyOQmy5VxQxvZQ+emy0c1p6MuTbyfWfFJPu yhmDlTTobWCPQvkthrgRkT1eBOlOytH+q9VEmUXiOf6xDcLmM4NdzO4T9xHI8jzisLOw to6goj55y4C+RARKLWSzIOmaNdrl6uOoSnoOMdyRjIQvrRZXqnxYQo9lwzOAHldNnvnD Yj6FgZe9xCizJ/ToDfM0LmcV2XxeJ+ft+I4TjZL9STQANp4g864d0jM96yBs/qYcpHYI BFXg== 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=2Qr8W+YNZxo/PHrt3cm26F+6wvNKcFBceX5yhtm3BlE=; fh=MHZUaeFq95kkvn/7p9n6z9dHu56OZa+n+tpiojw9Qvc=; b=SnbH0glgMi580nFAmRtoHINSqJzlY1V8/yRlar2JPqtz2cgCmlshrXbHnZ3BdC0Kfc CwP6mVLlXtooQVCiyZKGusgSc3VEl5sEZC026SKzpstQ/SEUb8LWGuEShYREGdnqvA2r psVibjXpvE5ZYgiIVRUS/hsolsYIWgptEFW3pNjtgyIGSukPepvQNqvault807MsAj5u JrP5/6BXExyCisv2THVl3wFMSNtZqJALAuyN3yGgG/k3oszI6PAeLMbIa5aBb4Ecn97Z jBHQbPrV6u7xuHg5DlU3VVci/5U6Q7Mv4/GYBG+GPNonjq30bGNfbq/L7+CfdEXFQmtt Xphw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gplgE2NY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ku11-20020a170903288b00b001bbab2e5a27si9167656plb.290.2023.09.12.20.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 20:39:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gplgE2NY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9A7F5822CB0E; Tue, 12 Sep 2023 18:37:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238066AbjIMBhj (ORCPT + 99 others); Tue, 12 Sep 2023 21:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230113AbjIMBhd (ORCPT ); Tue, 12 Sep 2023 21:37:33 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9DCC115; Tue, 12 Sep 2023 18:37:29 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68fe2470d81so1671436b3a.1; Tue, 12 Sep 2023 18:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694569049; x=1695173849; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=2Qr8W+YNZxo/PHrt3cm26F+6wvNKcFBceX5yhtm3BlE=; b=gplgE2NYc29wVpvu6Z9/jlSlWIVqxZ5lR/poNJ0KUCZqj6rSkcst7sH15KbtcbhM+B mrsuOIUPdk+MvP12N1rf17JojTUBDky+Dhnnajybd9CnmtdtwyG0or1lqn3JN+v5Y9Nd gr6akl/I2e9IzTdpwZgkmpwHIutNIS4n7Zodf89m78Y8ctXNCUZYUoOOdis9URYCeyMo 8sfA4GJ4W3RMPHb3zXMme7NKOsVkMQqBlL11kcNrJ8AvVtJ8lCm6vFMcUlEAvVDhj2zr //USXaue2/jnBz6dD5hDzTZ+RQRB8TxKH1u8q1yZVSI5720F2bod9lhMVChAxiDVybhU zewg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694569049; x=1695173849; 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=2Qr8W+YNZxo/PHrt3cm26F+6wvNKcFBceX5yhtm3BlE=; b=case/Ox42GqZ+OmX/0GdN/hunb8xMuPxuvqQyseVjS6uo9KzFyOlcAUIb9h6t4+DFB E77vE8LYcMFZs1nOPMb3tTScXOsqBRHc24O/GyS/DQM40U6aAH6Dn+6VyhfdvEChcuBD jfB/01aNtChNZss2YzzEHbTUEp1y+S7LDFO+MYzPa8fsIXtW+oUKd1LjBA8+eyaOg+AN nKRTse0xwr80Jy/LLlnR7wfZNGsAQWesCkTAemlqj/wMMQh7wmyn8kvvf6MjVqfaH5Fg CNyvs3thr2Xv7M7LsWBRxP1WkD3yNviAjJvyGxtZnLPp583+/NskOyD2EN6takb501Lh LDJA== X-Gm-Message-State: AOJu0YwJfMryKc5Bj6Ap98zPRTLaIarheZhHIIYfu3AJP4SgxRymhGPV UMyO/gqYHqtlmMl5jqP/gyI= X-Received: by 2002:a05:6a00:1a11:b0:68f:b5cb:ced0 with SMTP id g17-20020a056a001a1100b0068fb5cbced0mr1439599pfv.34.1694569049094; Tue, 12 Sep 2023 18:37:29 -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 l20-20020a62be14000000b0068a0c403636sm7874648pff.192.2023.09.12.18.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:37:28 -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 v6 1/1] rtc: nuvoton: Compatible with NCT3015Y-R and NCT3018Y-R Date: Wed, 13 Sep 2023 09:37:19 +0800 Message-Id: <20230913013719.8342-2-mimi05633@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230913013719.8342-1-mimi05633@gmail.com> References: <20230913013719.8342-1-mimi05633@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Sep 2023 18:37:42 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email The NCT3015Y-R and NCT3018Y-R use the same datasheet but have different topologies as follows. - Topology (Only 1st i2c can set TWO bit and HF bit) In NCT3015Y-R, rtc 1st i2c is connected to a host CPU rtc 2nd i2c is connected to a BMC In NCT3018Y-R, rtc 1st i2c is connected to a BMC rtc 2nd i2c is connected to a host CPU In order to be compatible with NCT3015Y-R and NCT3018Y-R, - 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 | 52 +++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c index ed4e606be8e5..b006b58e15e2 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,10 +38,12 @@ #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; struct i2c_client *client; + int part_num; #ifdef CONFIG_COMMON_CLK struct clk_hw clkout_hw; #endif @@ -177,8 +180,27 @@ static int nct3018y_rtc_read_time(struct device *dev, struct rtc_time *tm) static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm) { struct i2c_client *client = to_i2c_client(dev); + struct nct3018y *nct3018y = dev_get_drvdata(dev); unsigned char buf[4] = {0}; - int err; + int err, flags; + int restore_flags = 0; + + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); + if (flags < 0) { + dev_dbg(&client->dev, "Failed to read NCT3018Y_REG_CTRL.\n"); + return flags; + } + + /* Check and set TWO bit */ + if ((nct3018y->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 +234,18 @@ static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm) return -EIO; } + /* Restore TWO bit */ + if (restore_flags) { + if (nct3018y->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 +513,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; + nct3018y->part_num = i2c_smbus_read_byte_data(client, NCT3018Y_REG_PART); + if (nct3018y->part_num < 0) { + dev_dbg(&client->dev, "Failed to read NCT3018Y_REG_PART.\n"); + return nct3018y->part_num; + } else if (nct3018y->part_num & 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