* [PATCH] nvmem: sc27xx: Convert nvmem offset to block index
@ 2019-01-15 7:12 Baolin Wang
2019-01-15 12:16 ` Srinivas Kandagatla
0 siblings, 1 reply; 2+ messages in thread
From: Baolin Wang @ 2019-01-15 7:12 UTC (permalink / raw)
To: srinivas.kandagatla; +Cc: broonie, freeman.liu, baolin.wang, linux-kernel
From: Freeman Liu <freeman.liu@unisoc.com>
The Spreadtrum SC27XX efuse data are organized by blocks and each block
contains 2 bytes data. Moreover the nvmem core always pass the offset
in byte to the controller, so we should change the offset in byte to
the correct block index and block offset to read the data.
Signed-off-by: Freeman Liu <freeman.liu@unisoc.com>
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/nvmem/sc27xx-efuse.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/nvmem/sc27xx-efuse.c b/drivers/nvmem/sc27xx-efuse.c
index 33185d8..c6ee210 100644
--- a/drivers/nvmem/sc27xx-efuse.c
+++ b/drivers/nvmem/sc27xx-efuse.c
@@ -106,10 +106,12 @@ static int sc27xx_efuse_poll_status(struct sc27xx_efuse *efuse, u32 bits)
static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
{
struct sc27xx_efuse *efuse = context;
- u32 buf;
+ u32 buf, blk_index = offset / SC27XX_EFUSE_BLOCK_WIDTH;
+ u32 blk_offset = (offset % SC27XX_EFUSE_BLOCK_WIDTH) * BITS_PER_BYTE;
int ret;
- if (offset > SC27XX_EFUSE_BLOCK_MAX || bytes > SC27XX_EFUSE_BLOCK_WIDTH)
+ if (blk_index > SC27XX_EFUSE_BLOCK_MAX ||
+ bytes > SC27XX_EFUSE_BLOCK_WIDTH)
return -EINVAL;
ret = sc27xx_efuse_lock(efuse);
@@ -133,7 +135,7 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
/* Set the block address to be read. */
ret = regmap_write(efuse->regmap,
efuse->base + SC27XX_EFUSE_BLOCK_INDEX,
- offset & SC27XX_EFUSE_BLOCK_MASK);
+ blk_index & SC27XX_EFUSE_BLOCK_MASK);
if (ret)
goto disable_efuse;
@@ -171,8 +173,10 @@ static int sc27xx_efuse_read(void *context, u32 offset, void *val, size_t bytes)
unlock_efuse:
sc27xx_efuse_unlock(efuse);
- if (!ret)
+ if (!ret) {
+ buf >>= blk_offset;
memcpy(val, &buf, bytes);
+ }
return ret;
}
--
1.7.9.5
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] nvmem: sc27xx: Convert nvmem offset to block index
2019-01-15 7:12 [PATCH] nvmem: sc27xx: Convert nvmem offset to block index Baolin Wang
@ 2019-01-15 12:16 ` Srinivas Kandagatla
0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2019-01-15 12:16 UTC (permalink / raw)
To: Baolin Wang; +Cc: broonie, freeman.liu, linux-kernel
On 15/01/2019 07:12, Baolin Wang wrote:
> From: Freeman Liu <freeman.liu@unisoc.com>
>
> The Spreadtrum SC27XX efuse data are organized by blocks and each block
> contains 2 bytes data. Moreover the nvmem core always pass the offset
> in byte to the controller, so we should change the offset in byte to
> the correct block index and block offset to read the data.
>
> Signed-off-by: Freeman Liu <freeman.liu@unisoc.com>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
Applied!
Thanks,
srini
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-15 12:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 7:12 [PATCH] nvmem: sc27xx: Convert nvmem offset to block index Baolin Wang
2019-01-15 12:16 ` Srinivas Kandagatla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®