linux-sunxi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant
@ 2023-01-01 18:33 Samuel Holland
  2023-01-01 18:33 ` [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads Samuel Holland
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Samuel Holland @ 2023-01-01 18:33 UTC (permalink / raw)
  To: Srinivas Kandagatla, Chen-Yu Tsai, Jernej Skrabec
  Cc: Samuel Holland, Greg Kroah-Hartman, linux-arm-kernel,
	linux-kernel, linux-sunxi

This is the first two patches from [1], with the stable CC added.
The first patch fixes a bug causing incorrect values to be read; the
second is a cleanup. I split the series since this bug needs to be
fixed regardless of the DT binding discussion.

[1]: https://lore.kernel.org/lkml/20220814173656.11856-1-samuel@sholland.org/

Changes in v2:
 - Split out the driver fix from the other changes

Samuel Holland (2):
  nvmem: sunxi_sid: Always use 32-bit MMIO reads
  nvmem: sunxi_sid: Drop the workaround on A64

 drivers/nvmem/sunxi_sid.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

-- 
2.37.4


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

* [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads
  2023-01-01 18:33 [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Samuel Holland
@ 2023-01-01 18:33 ` Samuel Holland
  2023-01-08 20:52   ` Jernej Škrabec
  2023-01-01 18:33 ` [PATCH v2 2/2] nvmem: sunxi_sid: Drop the workaround on A64 Samuel Holland
  2023-01-03 11:33 ` [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Srinivas Kandagatla
  2 siblings, 1 reply; 5+ messages in thread
From: Samuel Holland @ 2023-01-01 18:33 UTC (permalink / raw)
  To: Srinivas Kandagatla, Chen-Yu Tsai, Jernej Skrabec
  Cc: Samuel Holland, Greg Kroah-Hartman, linux-arm-kernel,
	linux-kernel, linux-sunxi, stable, Heiko Stuebner

The SID SRAM on at least some SoCs (A64 and D1) returns different values
when read with bus cycles narrower than 32 bits. This is not immediately
obvious, because memcpy_fromio() uses word-size accesses as long as
enough data is being copied.

The vendor driver always uses 32-bit MMIO reads, so do the same here.
This is faster than the register-based method, which is currently used
as a workaround on A64. And it fixes the values returned on D1, where
the SRAM method was being used.

The special case for the last word is needed to maintain .word_size == 1
for sysfs ABI compatibility, as noted previously in commit de2a3eaea552
("nvmem: sunxi_sid: Optimize register read-out method").

Cc: stable@vger.kernel.org
Fixes: 07ae4fde9efa ("nvmem: sunxi_sid: Add support for D1 variant")
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---

(no changes since v1)

 drivers/nvmem/sunxi_sid.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index 5750e1f4bcdb..92dfe4cb10e3 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -41,8 +41,21 @@ static int sunxi_sid_read(void *context, unsigned int offset,
 			  void *val, size_t bytes)
 {
 	struct sunxi_sid *sid = context;
+	u32 word;
+
+	/* .stride = 4 so offset is guaranteed to be aligned */
+	__ioread32_copy(val, sid->base + sid->value_offset + offset, bytes / 4);
 
-	memcpy_fromio(val, sid->base + sid->value_offset + offset, bytes);
+	val += round_down(bytes, 4);
+	offset += round_down(bytes, 4);
+	bytes = bytes % 4;
+
+	if (!bytes)
+		return 0;
+
+	/* Handle any trailing bytes */
+	word = readl_relaxed(sid->base + sid->value_offset + offset);
+	memcpy(val, &word, bytes);
 
 	return 0;
 }
-- 
2.37.4


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

* [PATCH v2 2/2] nvmem: sunxi_sid: Drop the workaround on A64
  2023-01-01 18:33 [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Samuel Holland
  2023-01-01 18:33 ` [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads Samuel Holland
@ 2023-01-01 18:33 ` Samuel Holland
  2023-01-03 11:33 ` [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Srinivas Kandagatla
  2 siblings, 0 replies; 5+ messages in thread
From: Samuel Holland @ 2023-01-01 18:33 UTC (permalink / raw)
  To: Srinivas Kandagatla, Chen-Yu Tsai, Jernej Skrabec
  Cc: Samuel Holland, Greg Kroah-Hartman, linux-arm-kernel,
	linux-kernel, linux-sunxi

Now that the SRAM readout code is fixed by using 32-bit accesses, it
always returns the same values as register readout, so the A64 variant
no longer needs the workaround. This makes the D1 variant structure
redundant, so remove it.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

(no changes since v1)

 drivers/nvmem/sunxi_sid.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index 92dfe4cb10e3..a970f1741cc6 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -197,15 +197,9 @@ static const struct sunxi_sid_cfg sun8i_h3_cfg = {
 	.need_register_readout = true,
 };
 
-static const struct sunxi_sid_cfg sun20i_d1_cfg = {
-	.value_offset = 0x200,
-	.size = 0x100,
-};
-
 static const struct sunxi_sid_cfg sun50i_a64_cfg = {
 	.value_offset = 0x200,
 	.size = 0x100,
-	.need_register_readout = true,
 };
 
 static const struct sunxi_sid_cfg sun50i_h6_cfg = {
@@ -218,7 +212,7 @@ static const struct of_device_id sunxi_sid_of_match[] = {
 	{ .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg },
 	{ .compatible = "allwinner,sun8i-a83t-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun8i-h3-sid", .data = &sun8i_h3_cfg },
-	{ .compatible = "allwinner,sun20i-d1-sid", .data = &sun20i_d1_cfg },
+	{ .compatible = "allwinner,sun20i-d1-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-a64-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-h5-sid", .data = &sun50i_a64_cfg },
 	{ .compatible = "allwinner,sun50i-h6-sid", .data = &sun50i_h6_cfg },
-- 
2.37.4


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

* Re: [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant
  2023-01-01 18:33 [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Samuel Holland
  2023-01-01 18:33 ` [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads Samuel Holland
  2023-01-01 18:33 ` [PATCH v2 2/2] nvmem: sunxi_sid: Drop the workaround on A64 Samuel Holland
@ 2023-01-03 11:33 ` Srinivas Kandagatla
  2 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-01-03 11:33 UTC (permalink / raw)
  To: Samuel Holland, Chen-Yu Tsai, Jernej Skrabec
  Cc: Greg Kroah-Hartman, linux-arm-kernel, linux-kernel, linux-sunxi



On 01/01/2023 18:33, Samuel Holland wrote:
> This is the first two patches from [1], with the stable CC added.
> The first patch fixes a bug causing incorrect values to be read; the
> second is a cleanup. I split the series since this bug needs to be
> fixed regardless of the DT binding discussion.
> 
> [1]: https://lore.kernel.org/lkml/20220814173656.11856-1-samuel@sholland.org/
> 
> Changes in v2:
>   - Split out the driver fix from the other changes
> 
> Samuel Holland (2):
>    nvmem: sunxi_sid: Always use 32-bit MMIO reads
>    nvmem: sunxi_sid: Drop the workaround on A64
> 

Applied thanks,

--srini
>   drivers/nvmem/sunxi_sid.c | 23 +++++++++++++++--------
>   1 file changed, 15 insertions(+), 8 deletions(-)
> 

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

* Re: [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads
  2023-01-01 18:33 ` [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads Samuel Holland
@ 2023-01-08 20:52   ` Jernej Škrabec
  0 siblings, 0 replies; 5+ messages in thread
From: Jernej Škrabec @ 2023-01-08 20:52 UTC (permalink / raw)
  To: Srinivas Kandagatla, Chen-Yu Tsai, Samuel Holland
  Cc: Samuel Holland, Greg Kroah-Hartman, linux-arm-kernel,
	linux-kernel, linux-sunxi, stable, Heiko Stuebner

Dne nedelja, 01. januar 2023 ob 19:33:15 CET je Samuel Holland napisal(a):
> The SID SRAM on at least some SoCs (A64 and D1) returns different values
> when read with bus cycles narrower than 32 bits. This is not immediately
> obvious, because memcpy_fromio() uses word-size accesses as long as
> enough data is being copied.
> 
> The vendor driver always uses 32-bit MMIO reads, so do the same here.
> This is faster than the register-based method, which is currently used
> as a workaround on A64. And it fixes the values returned on D1, where
> the SRAM method was being used.
> 
> The special case for the last word is needed to maintain .word_size == 1
> for sysfs ABI compatibility, as noted previously in commit de2a3eaea552
> ("nvmem: sunxi_sid: Optimize register read-out method").
> 
> Cc: stable@vger.kernel.org
> Fixes: 07ae4fde9efa ("nvmem: sunxi_sid: Add support for D1 variant")
> Tested-by: Heiko Stuebner <heiko@sntech.de>
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej



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

end of thread, other threads:[~2023-01-08 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-01 18:33 [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Samuel Holland
2023-01-01 18:33 ` [PATCH v2 1/2] nvmem: sunxi_sid: Always use 32-bit MMIO reads Samuel Holland
2023-01-08 20:52   ` Jernej Škrabec
2023-01-01 18:33 ` [PATCH v2 2/2] nvmem: sunxi_sid: Drop the workaround on A64 Samuel Holland
2023-01-03 11:33 ` [PATCH v2 0/2] nvmem: sunxi_sid: Fix for D1 variant Srinivas Kandagatla

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).