linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc: k3: wait until the unlock field is not zero
@ 2022-08-16 17:33 Bryan Brattlof
  2022-08-16 17:33 ` [PATCH 2/2] rtc: k3: detect SoC to determine erratum fix Bryan Brattlof
  2022-08-23 20:26 ` [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Bryan Brattlof @ 2022-08-16 17:33 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Linux RTC, Linux Kernel Mailing List, Nishanth Menon, Bryan Brattlof

After writing the magic words to the KICK0 and KICK1 registers, we must
wait for a 1 in the unlock field of the general control register to
signify when the rtc device is in an unlocked state.

Signed-off-by: Bryan Brattlof <bb@ti.com>
---
 drivers/rtc/rtc-ti-k3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ti-k3.c b/drivers/rtc/rtc-ti-k3.c
index 7a0f181d3fefe..fd26be7868d25 100644
--- a/drivers/rtc/rtc-ti-k3.c
+++ b/drivers/rtc/rtc-ti-k3.c
@@ -190,7 +190,7 @@ static int k3rtc_unlock_rtc(struct ti_k3_rtc *priv)
 
 	/* Skip fence since we are going to check the unlock bit as fence */
 	ret = regmap_field_read_poll_timeout(priv->r_fields[K3RTC_UNLOCK], ret,
-					     !ret, 2, priv->sync_timeout_us);
+					     ret, 2, priv->sync_timeout_us);
 
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] rtc: k3: detect SoC to determine erratum fix
  2022-08-16 17:33 [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Bryan Brattlof
@ 2022-08-16 17:33 ` Bryan Brattlof
  2022-08-23 20:26 ` [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Bryan Brattlof @ 2022-08-16 17:33 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Linux RTC, Linux Kernel Mailing List, Nishanth Menon, Bryan Brattlof

To allow new SoCs to use this device without a new compatible string,
use a soc_device_attribute list to define all SoCs affected by the TI
i2327 erratum and require help from their bootloaders to unlock this
device.

Signed-off-by: Bryan Brattlof <bb@ti.com>
---
 drivers/rtc/rtc-ti-k3.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/rtc/rtc-ti-k3.c b/drivers/rtc/rtc-ti-k3.c
index fd26be7868d25..68e50c6a72f1d 100644
--- a/drivers/rtc/rtc-ti-k3.c
+++ b/drivers/rtc/rtc-ti-k3.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/sys_soc.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
@@ -45,14 +46,6 @@
 #define K3RTC_MIN_OFFSET		(-277761)
 #define K3RTC_MAX_OFFSET		(277778)
 
-/**
- * struct ti_k3_rtc_soc_data - Private of compatible data for ti-k3-rtc
- * @unlock_irq_erratum:	Has erratum for unlock infinite IRQs (erratum i2327)
- */
-struct ti_k3_rtc_soc_data {
-	const bool unlock_irq_erratum;
-};
-
 static const struct regmap_config ti_k3_rtc_regmap_config = {
 	.name = "peripheral-registers",
 	.reg_bits = 32,
@@ -118,7 +111,6 @@ static const struct reg_field ti_rtc_reg_fields[] = {
  * @rtc_dev:		rtc device
  * @regmap:		rtc mmio regmap
  * @r_fields:		rtc register fields
- * @soc:		SoC compatible match data
  */
 struct ti_k3_rtc {
 	unsigned int irq;
@@ -127,7 +119,6 @@ struct ti_k3_rtc {
 	struct rtc_device *rtc_dev;
 	struct regmap *regmap;
 	struct regmap_field *r_fields[K3_RTC_MAX_FIELDS];
-	const struct ti_k3_rtc_soc_data *soc;
 };
 
 static int k3rtc_field_read(struct ti_k3_rtc *priv, enum ti_k3_rtc_fields f)
@@ -195,6 +186,17 @@ static int k3rtc_unlock_rtc(struct ti_k3_rtc *priv)
 	return ret;
 }
 
+/*
+ * This is the list of SoCs affected by TI's i2327 errata causing the RTC
+ * state-machine to break if not unlocked fast enough during boot. These
+ * SoCs must have the bootloader unlock this device very early in the
+ * boot-flow before we (Linux) can use this device.
+ */
+static const struct soc_device_attribute has_erratum_i2327[] = {
+	{ .family = "AM62X", .revision = "SR1.0" },
+	{ /* sentinel */ }
+};
+
 static int k3rtc_configure(struct device *dev)
 {
 	int ret;
@@ -208,7 +210,7 @@ static int k3rtc_configure(struct device *dev)
 	 *
 	 * In such occurrence, it is assumed that the RTC module is unusable
 	 */
-	if (priv->soc->unlock_irq_erratum) {
+	if (soc_device_match(has_erratum_i2327)) {
 		ret = k3rtc_check_unlocked(priv);
 		/* If there is an error OR if we are locked, return error */
 		if (ret) {
@@ -602,8 +604,6 @@ static int ti_k3_rtc_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->rtc_dev))
 		return PTR_ERR(priv->rtc_dev);
 
-	priv->soc = of_device_get_match_data(dev);
-
 	priv->rtc_dev->ops = &ti_k3_rtc_ops;
 	priv->rtc_dev->range_max = (1ULL << 48) - 1;	/* 48Bit seconds */
 	ti_k3_rtc_nvmem_config.priv = priv;
@@ -635,12 +635,8 @@ static int ti_k3_rtc_probe(struct platform_device *pdev)
 	return devm_rtc_nvmem_register(priv->rtc_dev, &ti_k3_rtc_nvmem_config);
 }
 
-static const struct ti_k3_rtc_soc_data ti_k3_am62_data = {
-	.unlock_irq_erratum = true,
-};
-
 static const struct of_device_id ti_k3_rtc_of_match_table[] = {
-	{.compatible = "ti,am62-rtc", .data = &ti_k3_am62_data},
+	{.compatible = "ti,am62-rtc" },
 	{}
 };
 MODULE_DEVICE_TABLE(of, ti_k3_rtc_of_match_table);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] rtc: k3: wait until the unlock field is not zero
  2022-08-16 17:33 [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Bryan Brattlof
  2022-08-16 17:33 ` [PATCH 2/2] rtc: k3: detect SoC to determine erratum fix Bryan Brattlof
@ 2022-08-23 20:26 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2022-08-23 20:26 UTC (permalink / raw)
  To: a.zummo, bb; +Cc: linux-kernel, linux-rtc, nm

On Tue, 16 Aug 2022 12:33:11 -0500, Bryan Brattlof wrote:
> After writing the magic words to the KICK0 and KICK1 registers, we must
> wait for a 1 in the unlock field of the general control register to
> signify when the rtc device is in an unlocked state.
> 
> 

Applied, thanks!

[1/2] rtc: k3: wait until the unlock field is not zero
      commit: f2c5671a64d2a79341e8ee45d5933f6a76960189
[2/2] rtc: k3: detect SoC to determine erratum fix
      commit: 1e2585b49d849196f359bbf86677943fe2d80afe

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-23 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 17:33 [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Bryan Brattlof
2022-08-16 17:33 ` [PATCH 2/2] rtc: k3: detect SoC to determine erratum fix Bryan Brattlof
2022-08-23 20:26 ` [PATCH 1/2] rtc: k3: wait until the unlock field is not zero Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).