Skip to content

Commit c151d5e

Browse files
smaeulgregkh
authored andcommitted
nvmem: sunxi_sid: Always use 32-bit MMIO reads
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 de2a3ea ("nvmem: sunxi_sid: Optimize register read-out method"). Fixes: 07ae4fd ("nvmem: sunxi_sid: Add support for D1 variant") Cc: [email protected] Tested-by: Heiko Stuebner <[email protected]> Signed-off-by: Samuel Holland <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b0576ad commit c151d5e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/nvmem/sunxi_sid.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,21 @@ static int sunxi_sid_read(void *context, unsigned int offset,
4141
void *val, size_t bytes)
4242
{
4343
struct sunxi_sid *sid = context;
44+
u32 word;
45+
46+
/* .stride = 4 so offset is guaranteed to be aligned */
47+
__ioread32_copy(val, sid->base + sid->value_offset + offset, bytes / 4);
4448

45-
memcpy_fromio(val, sid->base + sid->value_offset + offset, bytes);
49+
val += round_down(bytes, 4);
50+
offset += round_down(bytes, 4);
51+
bytes = bytes % 4;
52+
53+
if (!bytes)
54+
return 0;
55+
56+
/* Handle any trailing bytes */
57+
word = readl_relaxed(sid->base + sid->value_offset + offset);
58+
memcpy(val, &word, bytes);
4659

4760
return 0;
4861
}

0 commit comments

Comments
 (0)