Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1669687ybh; Mon, 20 Jul 2020 04:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5Yeay6Yo3zVfiawC2C7zTi33LuRxVQL8QYEcJmzx2Oi+bD32FiVkXKPzEMu2zwtPl/9lL X-Received: by 2002:a17:906:7005:: with SMTP id n5mr19177068ejj.130.1595244342761; Mon, 20 Jul 2020 04:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595244342; cv=none; d=google.com; s=arc-20160816; b=X/7z/vGAfwcpnwTZg4YIUhqcJXnVEULIAbq3FdVuq7Z3Qp/tFKFnYW95Wqbdyd7+VJ zPI9nGEnTU6Z+8eP1FgEyUe0g7bmTRQ4SMOwfZHV5bbXOb7thFgR0n2O1k9sU4KEV3aB EHDlAu7bI3RpYeWIb0FSyzbIc+wPPrc5RLuYpqTcIpmR3TpcOhZXl37gUg7/Epd26ENL 0JNe3enq1S6rzmvVGZJkvafd2EM2gT+oBiENpeXIr9u0F1JKnZZNRsWO9BZ6FF6+1jiq AQ8OEFxcWTZSUkhw/ZMqqKIdFmwJAch4g+YA5jnOKwnos3uiadNxDtzwgU1B7usiDMul dNzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G0MpeHu7Qw2UNCkTfTVDcI6OwbuQEk4/Ke+DjLHLk6U=; b=tYWP3h8hl0wSDryg1xPG+L4PL79EvD+yeRcgRwn21sKtbIq/dIxekxDsuUr4KxK9ko y5BhzhYOYEDCv3c+tzAz7+Ez/bvHDoPh6erkgoApk9EWhnN8Jp4DMv81/cBgwMZykoy7 bvuJTeIY7Ldj6B+TF2WqMiTbxcb9oJ+NKWJo9kHv4FOeIi2ZGpCVwaRC7mK4dkscWPYm R8mIyTyTyoYn2ZSoX252V7FTXXboPqfOv4aCbw8iFohSaLAyIM/SVq56zUuAXaW5WTgV WDurroz9KRDInaQF4LmMbvRBOg1zSS1BreiYDklk66QAkUw7eomhEWKCjlGuUBPjtn2B b42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=giKWfMOz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si11051870ejs.400.2020.07.20.04.25.20; Mon, 20 Jul 2020 04:25:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=giKWfMOz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728604AbgGTLYt (ORCPT + 99 others); Mon, 20 Jul 2020 07:24:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728587AbgGTLYp (ORCPT ); Mon, 20 Jul 2020 07:24:45 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB60BC061794; Mon, 20 Jul 2020 04:24:44 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id f18so17497861wrs.0; Mon, 20 Jul 2020 04:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G0MpeHu7Qw2UNCkTfTVDcI6OwbuQEk4/Ke+DjLHLk6U=; b=giKWfMOz19JffrLV3eRuSk3MKIhq6qgF9GyrL8dCuNUA1GCR9tTOJOUenZ+YPwqDR5 IoGsYUyO/8gXe0eplNsnZ+8guo/FVo7zVgkI/e7ZEsIZ8S5cGN23F65Ff++1Zzyx+XYn 11jTfm4byKyawSEw2mgJVRrtUHGEKYdgkfYVZRllOAwlqS2QslhxS1lQicxOir05ypv4 Cu/AN0LEBeeictpebJ5+N6oCy1g6jAzIq9n4DZUp/W4nHhRCvbXw9IJMuEeI9UgZqhXs iTy71l4UwsBxPwIoeq5Mr3YxB1JQTxiJ4uIGgCseNX28Vw43YZy898VKB3tdeJ3oqF9K DYrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G0MpeHu7Qw2UNCkTfTVDcI6OwbuQEk4/Ke+DjLHLk6U=; b=KQ1biI6TkdeTh84wyChnDQWECadJkwqAFVixAF592twSdDoG6Qd58gTulilc3cG1hr LRp1/N4UT9fld+82jfaBFvozIGD4a+D68VPwTCYlfSeV4VwReigSQ5Tok72/Ay+x972v to+Z5PyExMt29iQzODxmFTHQCLLqR5mDibCKTNQH1/p1mvwfMPrIH4VQOq/9973wP1FI ML80PANgaGjFCWsdPMGZTz1hUqOISaDUffylKKkETE7PrO7V0Sp1F8UexOqU8c4AO41X fOw6eCMmiRzx9SG0AKhcb/HjpomzzMY251rX2sWII9ppHs6hcDkHyFBhsKrmYtKrvBtm RYHQ== X-Gm-Message-State: AOAM531GKGFf+fbN2urZuovSvvH9Racu7WHDkADJV5e8DYtwomb7UmhA Cmre9bpHFn0tGCYmtMoZbfw= X-Received: by 2002:adf:dc90:: with SMTP id r16mr21933315wrj.264.1595244283566; Mon, 20 Jul 2020 04:24:43 -0700 (PDT) Received: from localhost.localdomain ([148.63.172.143]) by smtp.gmail.com with ESMTPSA id t4sm33452942wmf.4.2020.07.20.04.24.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jul 2020 04:24:43 -0700 (PDT) From: miguelborgesdefreitas@gmail.com To: a.zummo@towertech.it Cc: baruch@tkos.co.il, linux@armlinux.org.uk, alexandre.belloni@bootlin.com, robh+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, miguelborgesdefreitas@gmail.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] rtc: pcf8523: Make DSM for battery switch-over configurable from DT Date: Mon, 20 Jul 2020 12:24:00 +0100 Message-Id: <20200720112401.4620-3-miguelborgesdefreitas@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200720112401.4620-1-miguelborgesdefreitas@gmail.com> References: <20200719145028.3370-3-miguelborgesdefreitas@gmail.com> <20200720112401.4620-1-miguelborgesdefreitas@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miguel Borges de Freitas The pcf8523 has two configurable modes for the battery switch-over functionality: (i) the default mode and (ii) the direct switching mode - the driver atm only supports (i). For the default mode to work a filtering circuit consisting of a series resistor of 1 kOhm and a capacitor of 3.3 microF must be added to the VDD pin input to guarantee a voltage drop of less 0.7V/ms for the oscillator operation reliability (see pp.54 of the datasheet). Some boards (e.g. the cubox-i) do not include such circuitry and are designed to work only in direct switching mode. According to the datasheet, this is the recommended mode for hw designs where VDD is always expected to be higher than VBAT. After a power cycle, if the voltage drop exceeds the said value, the REG_SECONDS_OS bit will be set (oscillator has stopped or been interrupted) causing userspace applications such as timedatectl and hwclock to fail (RTC_RD_TIME: Invalid argument). Hence, This enables DSM as a device-tree configurable property so that specific boards can make use of it. Note that, if the RTC comes from an inconsistent state (REG_SECONDS_OS defined), the software reset will override any power management options set during the probe phase. Thus, pm is also enforced in pcf8523_start_rtc. Signed-off-by: Miguel Borges de Freitas --- Changes in v2: - Added extended commit message for git history - Separate dt bindings documentation into a single patch drivers/rtc/rtc-pcf8523.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c index 47e0f41..0c08f91 100644 --- a/drivers/rtc/rtc-pcf8523.c +++ b/drivers/rtc/rtc-pcf8523.c @@ -122,7 +122,7 @@ static int pcf8523_load_capacitance(struct i2c_client *client) return err; } -static int pcf8523_set_pm(struct i2c_client *client, u8 pm) +static int pcf8523_set_pm(struct i2c_client *client) { u8 value; int err; @@ -131,7 +131,10 @@ static int pcf8523_set_pm(struct i2c_client *client, u8 pm) if (err < 0) return err; - value = (value & ~REG_CONTROL3_PM_MASK) | pm; + if (of_property_read_bool(client->dev.of_node, "pm-enable-dsm")) + value = (value & ~REG_CONTROL3_PM_MASK) | REG_CONTROL3_PM_DSM; + else + value = (value & ~REG_CONTROL3_PM_MASK) | 0; err = pcf8523_write(client, REG_CONTROL3, value); if (err < 0) @@ -173,6 +176,10 @@ static int pcf8523_start_rtc(struct i2c_client *client) if (err < 0) return err; + err = pcf8523_set_pm(client); + if (err < 0) + return err; + return 0; } @@ -352,7 +359,7 @@ static int pcf8523_probe(struct i2c_client *client, dev_warn(&client->dev, "failed to set xtal load capacitance: %d", err); - err = pcf8523_set_pm(client, 0); + err = pcf8523_set_pm(client); if (err < 0) return err; -- 1.8.3.1