All of lore.kernel.org
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <20200720112401.4620-3-miguelborgesdefreitas@gmail.com> (raw)
In-Reply-To: <20200720112401.4620-1-miguelborgesdefreitas@gmail.com>

From: Miguel Borges de Freitas <miguelborgesdefreitas@gmail.com>

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 <miguelborgesdefreitas@gmail.com>
---
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


WARNING: multiple messages have this Message-ID (diff)
From: miguelborgesdefreitas@gmail.com
To: a.zummo@towertech.it
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
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	[thread overview]
Message-ID: <20200720112401.4620-3-miguelborgesdefreitas@gmail.com> (raw)
In-Reply-To: <20200720112401.4620-1-miguelborgesdefreitas@gmail.com>

From: Miguel Borges de Freitas <miguelborgesdefreitas@gmail.com>

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 <miguelborgesdefreitas@gmail.com>
---
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

  parent reply	other threads:[~2020-07-20 11:24 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-19 14:50 [PATCH 0/2] rtc: pcf8523: Make DSM for battery switch-over configurable from DT and enable it for the cubox-i miguelborgesdefreitas
2020-07-19 14:50 ` miguelborgesdefreitas
2020-07-19 14:50 ` [PATCH 1/2] rtc: pcf8523: Make DSM for battery switch-over configurable from DT miguelborgesdefreitas
2020-07-19 14:50   ` miguelborgesdefreitas
2020-07-19 14:50 ` [PATCH 2/2] ARM: dts: imx6qdl-cubox-i: enable DSM for the RTC miguelborgesdefreitas
2020-07-19 14:50   ` miguelborgesdefreitas
2020-07-19 15:00   ` Baruch Siach
2020-07-19 15:00     ` Baruch Siach
2020-07-20 11:23   ` [PATCH v2 0/3] rtc: pcf8523: imx6qdl-cubox-i: Make DSM for battery switch-over configurable from DT and enable it for the cubox-i miguelborgesdefreitas
2020-07-20 11:23     ` miguelborgesdefreitas
2020-07-20 11:23     ` [PATCH v2 1/3] dt-bindings: rtc: pcf8523: add DSM pm option for battery switch-over miguelborgesdefreitas
2020-07-20 11:23       ` miguelborgesdefreitas
2020-07-23 17:49       ` Rob Herring
2020-07-23 17:49         ` Rob Herring
2020-07-23 19:57         ` Alexandre Belloni
2020-07-23 19:57           ` Alexandre Belloni
2020-07-23 20:41           ` Miguel Borges de Freitas
2020-07-23 20:41             ` Miguel Borges de Freitas
2020-07-27  9:19             ` Jon Nettleton
2020-07-27  9:19               ` Jon Nettleton
2020-07-27  9:45           ` Russell King - ARM Linux admin
2020-07-27  9:45             ` Russell King - ARM Linux admin
2020-07-27 13:33             ` Jon Nettleton
2020-07-27 13:33               ` Jon Nettleton
2020-07-27 14:17               ` Russell King - ARM Linux admin
2020-07-27 14:17                 ` Russell King - ARM Linux admin
2020-07-27 14:52                 ` Jon Nettleton
2020-07-27 14:52                   ` Jon Nettleton
2020-07-27 14:49             ` Alexandre Belloni
2020-07-27 14:49               ` Alexandre Belloni
2020-07-27 15:24               ` Russell King - ARM Linux admin
2020-07-27 15:24                 ` Russell King - ARM Linux admin
2020-07-27 15:41                 ` Alexandre Belloni
2020-07-27 15:41                   ` Alexandre Belloni
2020-07-27 15:43                   ` Russell King - ARM Linux admin
2020-07-27 15:43                     ` Russell King - ARM Linux admin
2020-07-27 15:55                     ` Jon Nettleton
2020-07-27 15:55                       ` Jon Nettleton
2020-07-27 16:16                       ` Alexandre Belloni
2020-07-27 16:16                         ` Alexandre Belloni
2020-07-27 17:04                         ` Jon Nettleton
2020-07-27 17:04                           ` Jon Nettleton
2020-07-27 17:30                         ` Russell King - ARM Linux admin
2020-07-27 17:30                           ` Russell King - ARM Linux admin
2020-07-27 21:13                           ` Miguel Borges de Freitas
2020-07-27 21:13                             ` Miguel Borges de Freitas
2020-08-25 20:08                             ` Alexandre Belloni
2020-08-25 20:08                               ` Alexandre Belloni
2020-07-20 11:24     ` miguelborgesdefreitas [this message]
2020-07-20 11:24       ` [PATCH v2 2/3] rtc: pcf8523: Make DSM for battery switch-over configurable from DT miguelborgesdefreitas
2020-07-20 11:24     ` [PATCH v2 3/3] ARM: dts: imx6qdl-cubox-i: enable DSM for the RTC miguelborgesdefreitas
2020-07-20 11:24       ` miguelborgesdefreitas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200720112401.4620-3-miguelborgesdefreitas@gmail.com \
    --to=miguelborgesdefreitas@gmail.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=baruch@tkos.co.il \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.