From patchwork Wed Jul 7 07:16:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathew McBride X-Patchwork-Id: 470786 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5731912jao; Wed, 7 Jul 2021 00:17:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/65IOJ04eS1SvlyW0Q0FfgxvQK3lzYj+cXRM820wlcC+9owDBPkqY+1XCBCRxldnEiBxn X-Received: by 2002:a50:ee98:: with SMTP id f24mr3999583edr.72.1625642245826; Wed, 07 Jul 2021 00:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625642245; cv=none; d=google.com; s=arc-20160816; b=brSV5l4Di5ukRXX1mid6aoKBivBIV3nImNhjWp8ZB0B8gS7KspNJDcu1DZYDcCf6lV f/81bTkFRYKjRnyqwHb3M/ABlWKVR9Ee9RAIoVKg91ngN2qFf6xmgIqmdWWoZc51xXO5 NOH7j1hXUx5z/Dwp0JbOk42WDur0Ta/nW3tT2CIaIUmMO7iyd+PwmAtaCJTAut7Nc7bG KQkWbL5cX8Wbhts8xU95XBn4TmRFpmcV7HruLZ9IcVUnVeu3bbT/tXdWzl0ksJF25UpE th1gbP5xl+YKdLUGuEOBrXvPrNmniB2RR2DLQXT6j2U/okVrFC2G9mylTBLGYG2gtUWR Dc3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=MktD/xXCqcqj8q7cUFe+PwgxPjObZLIa/Eh89OVde9Q=; b=Rkqg3wlqNBBhct9lU6zMEpl0LTmqKvRTe1dKMwMnz/ObOrLbOyUHo3COPFfyXAtslI IqahsloVXUfO2p2xluVVCn7h7CdPtZ8VEJ2sCwNG76tmB7yzcQ18Dw4lBySK+B3Ap7cw 7bjai50eXLTVNv7AqqtiC7gFV6ZywcxvZIeCdos5/l5Fmiez1YL5S4sW7K6XdoP28k8a /Qn9wuqtx/xd6HauK0vm9e+Y2x5mwRxG4RFITnvm/irLW72cbBGPIsfLBOUnG+4Z4xln vjfkIYpt2lMTK1ibVU+SiKLXnB9ZbZ6kW5z8pfmuEWLQLOgnaPQagAuA2Hp7IlxcPY6n ekng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=sYLNoiuH; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=mGOq4beE; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si20509554ejd.407.2021.07.07.00.17.25; Wed, 07 Jul 2021 00:17:25 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=sYLNoiuH; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=mGOq4beE; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbhGGHUE (ORCPT + 7 others); Wed, 7 Jul 2021 03:20:04 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:51451 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbhGGHUE (ORCPT ); Wed, 7 Jul 2021 03:20:04 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4267D5C0148; Wed, 7 Jul 2021 03:17:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 07 Jul 2021 03:17:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=traverse.com.au; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=MktD/xXCqcqj8 q7cUFe+PwgxPjObZLIa/Eh89OVde9Q=; b=sYLNoiuHXpQLaFI3cW0h6VQDKYDCm 5g+QsxN8MyIjx85AQjUl3nsMQVwKGabRgJqvdIYgiXPTaimRtSxoi11xh8woWlyb ciEgZUSc+kaXWewa0iND9WUSv+cpoGtn66RTbRu0Ziodazx6R5w3OKiLXORC9zag BqydI15MeJxCsxt0jSCJePaBLEoAnjP+TZxoKuLEets8R4Pwhll8VRdJyO8TMeF0 K338pc4DvE0t09wUgv+sH8adVYU3C3fbFST2CZqkEUygY3YKw5J75NZi8cDDykw5 C7T9D7A5vYawSixN4T79S+na6OUalJDPmHkqqhE42OzFPpK3NnX8DK8fQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=MktD/xXCqcqj8q7cUFe+PwgxPjObZLIa/Eh89OVde9Q=; b=mGOq4beE cJZfyQNqCxJl3LBLjekddmL0guoJHp5xm+0gQ8JPN5TDcVv37B05w1s8UrYpCSHz Psm29xnmcfkdFDu2vxj7QwK1lzLaYJnUGiZEroNXxZyMcpm/L5hEhcOm6P49rlP5 NCK7uaVXcMq0gKernbF3sAv5nvHKgSjSRZ0VBLoNn/7uFpq3KOVgha28tTJBWEVd SzLOomCbhGzVnFfl3Hhper2GUCQB5wf2nR5bpZaNcRwqRE+9CyaBVqDoIrX+CJ9d HU5uHHo7bIoGIuAKadvCDLECaiaycofieIm649GUaTqt/JBldo4A2l1x2ZeXYIcS D9F5aFo7NXzmqw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrtddugdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrthhhvgif ucfotgeurhhiuggvuceomhgrthhtsehtrhgrvhgvrhhsvgdrtghomhdrrghuqeenucggtf frrghtthgvrhhnpeekleevteelvdduheetgfdvfeelueekffeggeethedtteeljeeivedv gfehjeejheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmrghtthesthhrrghvvghrshgvrdgtohhmrdgruh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Jul 2021 03:17:22 -0400 (EDT) From: Mathew McBride To: linux-rtc@vger.kernel.org, Alessandro Zummo , Alexandre Belloni , Rob Herring , devicetree@vger.kernel.org Cc: Mathew McBride Subject: [PATCH 1/2] rtc: rx8025: implement RX-8035 support Date: Wed, 7 Jul 2021 07:16:15 +0000 Message-Id: <20210707071616.28976-2-matt@traverse.com.au> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210707071616.28976-1-matt@traverse.com.au> References: <20210707071616.28976-1-matt@traverse.com.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The RX-8035 is a newer RTC from EPSON that is very similar to the RX-8025. The key difference is in the oscillation stop (XSTP) bit which is inverted on the RX-8035. Signed-off-by: Mathew McBride --- drivers/rtc/rtc-rx8025.c | 59 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 6 deletions(-) -- 2.30.1 diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c index c914091819ba..1a33ec402f4a 100644 --- a/drivers/rtc/rtc-rx8025.c +++ b/drivers/rtc/rtc-rx8025.c @@ -60,14 +60,24 @@ #define RX8025_ADJ_DATA_MAX 62 #define RX8025_ADJ_DATA_MIN -62 +enum rx_model { + model_rx_unknown, + model_rx_8025, + model_rx_8035, + model_last +}; + static const struct i2c_device_id rx8025_id[] = { - { "rx8025", 0 }, + { "rx8025", model_rx_8025 }, + { "rx8035", model_rx_8035 }, { } }; + MODULE_DEVICE_TABLE(i2c, rx8025_id); struct rx8025_data { struct rtc_device *rtc; + enum rx_model type; u8 ctrl1; }; @@ -100,10 +110,26 @@ static s32 rx8025_write_regs(const struct i2c_client *client, length, values); } +static int rx8025_is_osc_stopped(enum rx_model model, int ctrl2) +{ + int xstp = ctrl2 & RX8025_BIT_CTRL2_XST; + /* XSTP bit has different polarity on RX-8025 vs RX-8035. + * RX-8025: 0 == oscillator stopped + * RX-8035: 1 == oscillator stopped + */ + + if (model == model_rx_8025) + xstp = !xstp; + + return xstp; +} + static int rx8025_check_validity(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); + struct rx8025_data *drvdata = dev_get_drvdata(dev); int ctrl2; + int xstp; ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); if (ctrl2 < 0) @@ -117,7 +143,8 @@ static int rx8025_check_validity(struct device *dev) return -EINVAL; } - if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) { + xstp = rx8025_is_osc_stopped(drvdata->type, ctrl2); + if (xstp) { dev_warn(dev, "crystal stopped, date is invalid\n"); return -EINVAL; } @@ -125,7 +152,7 @@ static int rx8025_check_validity(struct device *dev) return 0; } -static int rx8025_reset_validity(struct i2c_client *client) +static int rx8025_reset_validity(enum rx_model model, struct i2c_client *client) { int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); @@ -134,8 +161,13 @@ static int rx8025_reset_validity(struct i2c_client *client) ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET); + if (model == model_rx_8025) + ctrl2 |= RX8025_BIT_CTRL2_XST; + else + ctrl2 &= ~(RX8025_BIT_CTRL2_XST); + return rx8025_write_reg(client, RX8025_REG_CTRL2, - ctrl2 | RX8025_BIT_CTRL2_XST); + ctrl2); } static irqreturn_t rx8025_handle_irq(int irq, void *dev_id) @@ -149,7 +181,7 @@ static irqreturn_t rx8025_handle_irq(int irq, void *dev_id) if (status < 0) goto out; - if (!(status & RX8025_BIT_CTRL2_XST)) + if (rx8025_is_osc_stopped(rx8025->type, status)) dev_warn(&client->dev, "Oscillation stop was detected," "you may have to readjust the clock\n"); @@ -241,7 +273,7 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) if (ret < 0) return ret; - return rx8025_reset_validity(client); + return rx8025_reset_validity(rx8025->type, client); } static int rx8025_init_client(struct i2c_client *client) @@ -519,6 +551,21 @@ static int rx8025_probe(struct i2c_client *client, i2c_set_clientdata(client, rx8025); + if (id) { + rx8025->type = id->driver_data; + switch (rx8025->type) { + case model_rx_8025: + dev_info(&client->dev, "Type RX-8025"); + break; + case model_rx_8035: + dev_info(&client->dev, "Type RX-8035"); + break; + default: + dev_warn(&client->dev, "Unknown type: %d\n", rx8025->type); + break; + } + } + err = rx8025_init_client(client); if (err) return err;