From patchwork Thu May 18 11:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 1783204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QMSfr6gmZz20dg for ; Thu, 18 May 2023 21:39:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231570AbjERLjA (ORCPT ); Thu, 18 May 2023 07:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjERLit (ORCPT ); Thu, 18 May 2023 07:38:49 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 607CD3A9D; Thu, 18 May 2023 04:37:43 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.99,285,1677510000"; d="scan'208";a="163369252" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 18 May 2023 20:37:19 +0900 Received: from localhost.localdomain (unknown [10.226.92.79]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id F26EB4005B2A; Thu, 18 May 2023 20:37:16 +0900 (JST) From: Biju Das To: Alessandro Zummo , Alexandre Belloni Cc: Biju Das , linux-rtc@vger.kernel.org, Geert Uytterhoeven , Fabrizio Castro , linux-renesas-soc@vger.kernel.org Subject: [PATCH v4 07/11] rtc: isl1208: Add isl1208_set_xtoscb() Date: Thu, 18 May 2023 12:36:39 +0100 Message-Id: <20230518113643.420806-8-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230518113643.420806-1-biju.das.jz@bp.renesas.com> References: <20230518113643.420806-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-rtc@vger.kernel.org As per the HW manual, setting of XTOSCB bit as follws If using an external clock signal, set the XTOSCB bit as 1 to disable the crystal oscillator. If using an external crystal, the XTOSCB bit needs to be set at 0 to enable the crystal oscillator. Add isl1208_set_xtoscb() to set XTOSCB bit based on the clock-names property. Fallback is enabling the internal crystal oscillator. While at it, introduce a variable "sr" for reading status register in probe() as it is reused for writing. Signed-off-by: Biju Das --- v4: * New patch. --- drivers/rtc/rtc-isl1208.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c index 916e7d44c96f..5f91a3ca5920 100644 --- a/drivers/rtc/rtc-isl1208.c +++ b/drivers/rtc/rtc-isl1208.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -175,6 +176,16 @@ isl1208_i2c_validate_client(struct i2c_client *client) return 0; } +static int isl1208_set_xtoscb(struct i2c_client *client, int sr, bool int_osc_en) +{ + if (int_osc_en) + sr &= ~ISL1208_REG_SR_XTOSCB; + else + sr |= ISL1208_REG_SR_XTOSCB; + + return i2c_smbus_write_byte_data(client, ISL1208_REG_SR, sr); +} + static int isl1208_i2c_get_sr(struct i2c_client *client) { @@ -808,9 +819,13 @@ static int isl1208_setup_irq(struct i2c_client *client, int irq) static int isl1208_probe(struct i2c_client *client) { - int rc = 0; struct isl1208_state *isl1208; + bool int_osc_en = true; int evdet_irq = -1; + struct clk *clkin; + struct clk *xin; + int rc = 0; + int sr; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) return -ENODEV; @@ -837,6 +852,13 @@ isl1208_probe(struct i2c_client *client) isl1208->config = (struct isl1208_config *)id->driver_data; } + xin = devm_clk_get(&client->dev, "xin"); + if (IS_ERR(xin)) { + clkin = devm_clk_get(&client->dev, "clkin"); + if (!IS_ERR(clkin)) + int_osc_en = false; + } + isl1208->rtc = devm_rtc_allocate_device(&client->dev); if (IS_ERR(isl1208->rtc)) return PTR_ERR(isl1208->rtc); @@ -848,13 +870,17 @@ isl1208_probe(struct i2c_client *client) isl1208->nvmem_config.size = isl1208->config->nvmem_length; isl1208->nvmem_config.priv = isl1208; - rc = isl1208_i2c_get_sr(client); - if (rc < 0) { + sr = isl1208_i2c_get_sr(client); + if (sr < 0) { dev_err(&client->dev, "reading status failed\n"); - return rc; + return sr; } - if (rc & ISL1208_REG_SR_RTCF) + rc = isl1208_set_xtoscb(client, sr, int_osc_en); + if (rc) + return rc; + + if (sr & ISL1208_REG_SR_RTCF) dev_warn(&client->dev, "rtc power failure detected, " "please set clock.\n");