All of lore.kernel.org
 help / color / mirror / Atom feed
From: srinivas.kandagatla@linaro.org
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org,
	Icenowy Zheng <icenowy@aosc.io>
Subject: [PATCH 23/25] nvmem: sunxi-sid: fix H3 SID controller support
Date: Fri,  9 Mar 2018 14:47:17 +0000	[thread overview]
Message-ID: <20180309144719.29904-24-srinivas.kandagatla@linaro.org> (raw)
In-Reply-To: <20180309144719.29904-1-srinivas.kandagatla@linaro.org>

From: Icenowy Zheng <icenowy@aosc.io>

It seems that doing some operation will make the value pre-read on H3
SID controller wrong again, so all operation should be performed by
register.

Change the SID reading to use register only.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/sunxi_sid.c | 71 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index 99bd54d85fcb..26bb637afe92 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -85,13 +85,14 @@ static int sunxi_sid_read(void *context, unsigned int offset,
 }
 
 static int sun8i_sid_register_readout(const struct sunxi_sid *sid,
-				      const unsigned int word)
+				      const unsigned int offset,
+				      u32 *out)
 {
 	u32 reg_val;
 	int ret;
 
 	/* Set word, lock access, and set read command */
-	reg_val = (word & SUN8I_SID_OFFSET_MASK)
+	reg_val = (offset & SUN8I_SID_OFFSET_MASK)
 		  << SUN8I_SID_OFFSET_SHIFT;
 	reg_val |= SUN8I_SID_OP_LOCK | SUN8I_SID_READ;
 	writel(reg_val, sid->base + SUN8I_SID_PRCTL);
@@ -101,7 +102,49 @@ static int sun8i_sid_register_readout(const struct sunxi_sid *sid,
 	if (ret)
 		return ret;
 
+	if (out)
+		*out = readl(sid->base + SUN8I_SID_RDKEY);
+
 	writel(0, sid->base + SUN8I_SID_PRCTL);
+
+	return 0;
+}
+
+/*
+ * On Allwinner H3, the value on the 0x200 offset of the SID controller seems
+ * to be not reliable at all.
+ * Read by the registers instead.
+ */
+static int sun8i_sid_read_byte_by_reg(const struct sunxi_sid *sid,
+				      const unsigned int offset,
+				      u8 *out)
+{
+	u32 word;
+	int ret;
+
+	ret = sun8i_sid_register_readout(sid, offset & ~0x03, &word);
+
+	if (ret)
+		return ret;
+
+	*out = (word >> ((offset & 0x3) * 8)) & 0xff;
+
+	return 0;
+}
+
+static int sun8i_sid_read_by_reg(void *context, unsigned int offset,
+				 void *val, size_t bytes)
+{
+	struct sunxi_sid *sid = context;
+	u8 *buf = val;
+	int ret;
+
+	while (bytes--) {
+		ret = sun8i_sid_read_byte_by_reg(sid, offset++, buf++);
+		if (ret)
+			return ret;
+	}
+
 	return 0;
 }
 
@@ -131,26 +174,12 @@ static int sunxi_sid_probe(struct platform_device *pdev)
 
 	size = cfg->size;
 
-	if (cfg->need_register_readout) {
-		/*
-		 * H3's SID controller have a bug that the value at 0x200
-		 * offset is not the correct value when the hardware is reseted.
-		 * However, after doing a register-based read operation, the
-		 * value become right.
-		 * Do a full read operation here, but ignore its value
-		 * (as it's more fast to read by direct MMIO value than
-		 * with registers)
-		 */
-		for (i = 0; i < (size >> 2); i++) {
-			ret = sun8i_sid_register_readout(sid, i);
-			if (ret)
-				return ret;
-		}
-	}
-
 	econfig.size = size;
 	econfig.dev = dev;
-	econfig.reg_read = sunxi_sid_read;
+	if (cfg->need_register_readout)
+		econfig.reg_read = sun8i_sid_read_by_reg;
+	else
+		econfig.reg_read = sunxi_sid_read;
 	econfig.priv = sid;
 	nvmem = nvmem_register(&econfig);
 	if (IS_ERR(nvmem))
@@ -163,7 +192,7 @@ static int sunxi_sid_probe(struct platform_device *pdev)
 	}
 
 	for (i = 0; i < size; i++)
-		randomness[i] = sunxi_sid_read_byte(sid, i);
+		econfig.reg_read(sid, i, &randomness[i], 1);
 
 	add_device_randomness(randomness, size);
 	kfree(randomness);
-- 
2.15.1

  parent reply	other threads:[~2018-03-09 14:47 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 14:46 [PATCH 00/25] nvmem: patches for v4.17 srinivas.kandagatla
2018-03-09 14:46 ` [PATCH 01/25] nvmem: Document struct nvmem_config srinivas.kandagatla
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-03-09 14:46 ` [PATCH 02/25] nvmem: core: Allow specifying device name verbatim srinivas.kandagatla
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-03-09 14:46 ` [PATCH 03/25] nvmem: Introduce devm_nvmem_(un)register() srinivas.kandagatla
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-03-09 14:46 ` [PATCH 04/25] nvmem: vf610-ocotp: Convert to use devm_nvmem_register() srinivas.kandagatla
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla-QSEj5FYQhm4dnm+yROfE0A
2018-03-09 14:46 ` [PATCH 05/25] nvmem: imx-ocotp: " srinivas.kandagatla
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla at linaro.org
2018-03-09 14:46   ` srinivas.kandagatla
2018-03-09 14:47 ` [PATCH 06/25] nvmem: uniphier-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 07/25] nvmem: snvs_lgpr: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 08/25] nvmem: rockchip-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 09/25] nvmem: mtk-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 10/25] nvmem: meson-mx-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 11/25] nvmem: meson-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 12/25] nvmem: lpc18xx_otp: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 13/25] nvmem: imx-iim: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 14/25] nvmem: bcm-ocotp: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 15/25] nvmem: qfprom: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 16/25] nvmem: snvs_lpgpr: Convert commas to semicolons srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 17/25] nvmem: rockchip-efuse: Make use of of_device_get_match_data() srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 18/25] nvmem: vf610-ocotp: Do not use "&pdev->dev" explicitly srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 19/25] nvmem: rockchip-efuse: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 20/25] nvmem: imx-iim: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 21/25] nvmem: bcm-ocotp: " srinivas.kandagatla
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47   ` srinivas.kandagatla at linaro.org
2018-03-09 14:47 ` [PATCH 22/25] nvmem: add i.MX7 support to snvs-lpgpr srinivas.kandagatla
2018-03-09 14:47 ` srinivas.kandagatla [this message]
2018-03-09 14:47 ` [PATCH 24/25] dt-bindings: nvmem: imx-ocotp: update the binding to reflect data cells srinivas.kandagatla
2018-03-09 14:47 ` [PATCH 25/25] nvmem: imx-ocotp: remove unused dead code srinivas.kandagatla

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=20180309144719.29904-24-srinivas.kandagatla@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=icenowy@aosc.io \
    --cc=linux-kernel@vger.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.