From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 160F2C433E3 for ; Mon, 20 Jul 2020 11:26:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC52522B4D for ; Mon, 20 Jul 2020 11:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pMT+yeXZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="giKWfMOz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC52522B4D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qih+4OTwbWwV5Y//wlmecJOsXUWh7iBfdkdcq/cBnE8=; b=pMT+yeXZAZL4YLtOuB+HPQyb1 uC9x2m9ui7kSX0jwqn8tnVC8HjXpcNnMilLKzDvK7WrwGAjRAdzeJW1fLM1UBi/NvPu7c5qC4+oqz /I1FqdYg5X5bE135B7FIL/MMSFg6ppr55HLXLniki9vx1m8o4KcDiJv3DQ6YcOPTw0x58Uyihf92l EQd+3ySNaUE/A+cIiFFUlvWyk+VXSm24FO9dAVt4PY6RPPqYjO30k+bRmFaXUkB9qIzogPrGU7nGV U8QO5fZnl0r7ss2XrOJsP6B/Am5XTzOYWoGruVpeEot+GX+jwND4ZXd4/0TTLE63xjq+dRPIitMB8 pWe4OsfAA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxTuc-0001NE-EG; Mon, 20 Jul 2020 11:24:50 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxTuW-0001Ll-Nn for linux-arm-kernel@lists.infradead.org; Mon, 20 Jul 2020 11:24:45 +0000 Received: by mail-wr1-x444.google.com with SMTP id z2so17494164wrp.2 for ; 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=Ki6Lqo3fqaBCGk95AUz76mfDnLspFWFfVpV/GpwQax7SBXe4fK8iwMSU0DYcFFZPxp qrUwfj4NZAP6V/J63VS8DGbYeXlhFUnTaOakQ8FS+dF8WQ8O/V63O4ozjL0UQfmSAmKJ 9n6Ag6ZCjXZl6OaqYa25G62lEispI6mHeGGzObeIbqLF2Dbii9fXRBKhurFqe18L9xw7 bsf2ULQalGXJ9+5VfVjTko5J2qdnHiZHCMkNYDCaxdz51HTzB/ZaCcGfRZHl1h5UnuKP EHLkoVNDq5QUfkxijsinaSkgfHqHYBh9RqLx6JlgDeJFNf3SVDvJ3c2/E7v0HwjpLiJa Fu+Q== X-Gm-Message-State: AOAM530ieDHvZutmfUmlpbt3kx3Fo83cRnRaIwF18LwV/+3YbbQtX2fF Dus5uboFTua0ULEaUXzqn30= X-Google-Smtp-Source: ABdhPJyx6KTL+INmrZ51MClTIJqi7ESS3U/5hPBpiOQNB3YRei+BK9LcYlxgNLvcARTeMfWOa8AaEg== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200720_072444_846618_D54CA967 X-CRM114-Status: GOOD ( 16.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, baruch@tkos.co.il, miguelborgesdefreitas@gmail.com, alexandre.belloni@bootlin.com, festevam@gmail.com, s.hauer@pengutronix.de, linux@armlinux.org.uk, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-imx@nxp.com, kernel@pengutronix.de, shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel