* [PATCH 1/2] nvmem: meson-efuse: remove econfig global
2018-03-16 15:01 [PATCH 0/2] nvmem: meson-efuse: add write support Jerome Brunet
@ 2018-03-16 15:01 ` Jerome Brunet
2018-03-16 15:01 ` [PATCH 2/2] nvmem: meson-efuse: add write support Jerome Brunet
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jerome Brunet @ 2018-03-16 15:01 UTC (permalink / raw)
To: Srinivas Kandagatla, Carlo Caione, Kevin Hilman
Cc: Jerome Brunet, linux-amlogic, linux-kernel
Having a global structure holding a reference to the device
structure is not very nice. Allocate the econfig instead and fill
the nvmem information as before
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
drivers/nvmem/meson-efuse.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index a43c68f90937..7ad80b80b293 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -35,13 +35,6 @@ static int meson_efuse_read(void *context, unsigned int offset,
return 0;
}
-static struct nvmem_config econfig = {
- .name = "meson-efuse",
- .stride = 1,
- .word_size = 1,
- .read_only = true,
-};
-
static const struct of_device_id meson_efuse_match[] = {
{ .compatible = "amlogic,meson-gxbb-efuse", },
{ /* sentinel */ },
@@ -50,17 +43,27 @@ MODULE_DEVICE_TABLE(of, meson_efuse_match);
static int meson_efuse_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct nvmem_device *nvmem;
+ struct nvmem_config *econfig;
unsigned int size;
if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
return -EINVAL;
- econfig.dev = &pdev->dev;
- econfig.reg_read = meson_efuse_read;
- econfig.size = size;
+ econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
+ if (!econfig)
+ return -ENOMEM;
+
+ econfig->dev = dev;
+ econfig->name = dev_name(dev);
+ econfig->stride = 1;
+ econfig->word_size = 1;
+ econfig->read_only = true;
+ econfig->reg_read = meson_efuse_read;
+ econfig->size = size;
- nvmem = nvmem_register(&econfig);
+ nvmem = nvmem_register(econfig);
if (IS_ERR(nvmem))
return PTR_ERR(nvmem);
--
2.14.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] nvmem: meson-efuse: add write support
2018-03-16 15:01 [PATCH 0/2] nvmem: meson-efuse: add write support Jerome Brunet
2018-03-16 15:01 ` [PATCH 1/2] nvmem: meson-efuse: remove econfig global Jerome Brunet
@ 2018-03-16 15:01 ` Jerome Brunet
2018-04-19 14:13 ` [PATCH 0/2] " Jerome Brunet
2018-04-19 17:42 ` Kevin Hilman
3 siblings, 0 replies; 6+ messages in thread
From: Jerome Brunet @ 2018-03-16 15:01 UTC (permalink / raw)
To: Srinivas Kandagatla, Carlo Caione, Kevin Hilman
Cc: Jerome Brunet, linux-amlogic, linux-kernel
Add write support to the meson-gx efuse driver.
Beware, this efuse is one time programmable !
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
drivers/nvmem/meson-efuse.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index 7ad80b80b293..30da5e1abf84 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -35,6 +35,20 @@ static int meson_efuse_read(void *context, unsigned int offset,
return 0;
}
+static int meson_efuse_write(void *context, unsigned int offset,
+ void *val, size_t bytes)
+{
+ u8 *buf = val;
+ int ret;
+
+ ret = meson_sm_call_write(buf, bytes, SM_EFUSE_WRITE, offset,
+ bytes, 0, 0, 0);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
static const struct of_device_id meson_efuse_match[] = {
{ .compatible = "amlogic,meson-gxbb-efuse", },
{ /* sentinel */ },
@@ -59,8 +73,8 @@ static int meson_efuse_probe(struct platform_device *pdev)
econfig->name = dev_name(dev);
econfig->stride = 1;
econfig->word_size = 1;
- econfig->read_only = true;
econfig->reg_read = meson_efuse_read;
+ econfig->reg_write = meson_efuse_write;
econfig->size = size;
nvmem = nvmem_register(econfig);
--
2.14.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvmem: meson-efuse: add write support
2018-03-16 15:01 [PATCH 0/2] nvmem: meson-efuse: add write support Jerome Brunet
2018-03-16 15:01 ` [PATCH 1/2] nvmem: meson-efuse: remove econfig global Jerome Brunet
2018-03-16 15:01 ` [PATCH 2/2] nvmem: meson-efuse: add write support Jerome Brunet
@ 2018-04-19 14:13 ` Jerome Brunet
2018-04-19 14:29 ` Srinivas Kandagatla
2018-04-19 17:42 ` Kevin Hilman
3 siblings, 1 reply; 6+ messages in thread
From: Jerome Brunet @ 2018-04-19 14:13 UTC (permalink / raw)
To: Srinivas Kandagatla, Carlo Caione, Kevin Hilman
Cc: linux-amlogic, linux-kernel
On Fri, 2018-03-16 at 16:01 +0100, Jerome Brunet wrote:
> This changeset adds write support to meson efuse driver.
> The first patch just changes the way the nvmem data are allocated w/o
> any functional changes. The second patches actually adds write support.
>
> The memory being an OTP, it is safer if it remains read-only by default,
> which is why I also submitted this DT patch [0].
>
> If a user knows what he is doing, it should be easy to remove the
> read-only property from the board DT. This can be done in u-boot, before
> starting linux:
>
> > fdt rm /efuse read-only
>
> Tested on the gxl libretech-cc
Hi Srinivas,
Is this patchset ok with you ? Do you want to me to change something ?
Regards
Jerome
>
> [0]: https://lkml.kernel.org/r/20180316145021.8517-1-jbrunet@baylibre.com
>
> Jerome Brunet (2):
> nvmem: meson-efuse: remove econfig global
> nvmem: meson-efuse: add write support
>
> drivers/nvmem/meson-efuse.c | 37 +++++++++++++++++++++++++++----------
> 1 file changed, 27 insertions(+), 10 deletions(-)
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvmem: meson-efuse: add write support
2018-04-19 14:13 ` [PATCH 0/2] " Jerome Brunet
@ 2018-04-19 14:29 ` Srinivas Kandagatla
0 siblings, 0 replies; 6+ messages in thread
From: Srinivas Kandagatla @ 2018-04-19 14:29 UTC (permalink / raw)
To: Jerome Brunet, Carlo Caione, Kevin Hilman; +Cc: linux-amlogic, linux-kernel
On 19/04/18 15:13, Jerome Brunet wrote:
> On Fri, 2018-03-16 at 16:01 +0100, Jerome Brunet wrote:
>> This changeset adds write support to meson efuse driver.
>> The first patch just changes the way the nvmem data are allocated w/o
>> any functional changes. The second patches actually adds write support.
>>
>> The memory being an OTP, it is safer if it remains read-only by default,
>> which is why I also submitted this DT patch [0].
>>
>> If a user knows what he is doing, it should be easy to remove the
>> read-only property from the board DT. This can be done in u-boot, before
>> starting linux:
>>
>> > fdt rm /efuse read-only
>>
>> Tested on the gxl libretech-cc
>
> Hi Srinivas,
>
> Is this patchset ok with you ? Do you want to me to change something ?
>
Patches look good to me, Can you rebase them on top of 4.17, I will send
it to Greg once rc4 is out.
thanks,
srini
> Regards
> Jerome
>
>>
>> [0]: https://lkml.kernel.org/r/20180316145021.8517-1-jbrunet@baylibre.com
>>
>> Jerome Brunet (2):
>> nvmem: meson-efuse: remove econfig global
>> nvmem: meson-efuse: add write support
>>
>> drivers/nvmem/meson-efuse.c | 37 +++++++++++++++++++++++++++----------
>> 1 file changed, 27 insertions(+), 10 deletions(-)
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] nvmem: meson-efuse: add write support
2018-03-16 15:01 [PATCH 0/2] nvmem: meson-efuse: add write support Jerome Brunet
` (2 preceding siblings ...)
2018-04-19 14:13 ` [PATCH 0/2] " Jerome Brunet
@ 2018-04-19 17:42 ` Kevin Hilman
3 siblings, 0 replies; 6+ messages in thread
From: Kevin Hilman @ 2018-04-19 17:42 UTC (permalink / raw)
To: Jerome Brunet
Cc: Srinivas Kandagatla, Carlo Caione, linux-amlogic, linux-kernel
Jerome Brunet <jbrunet@baylibre.com> writes:
> This changeset adds write support to meson efuse driver.
> The first patch just changes the way the nvmem data are allocated w/o
> any functional changes. The second patches actually adds write support.
>
> The memory being an OTP, it is safer if it remains read-only by default,
> which is why I also submitted this DT patch [0].
>
> If a user knows what he is doing, it should be easy to remove the
> read-only property from the board DT. This can be done in u-boot, before
> starting linux:
>
> > fdt rm /efuse read-only
>
> Tested on the gxl libretech-cc
For the series,
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
^ permalink raw reply [flat|nested] 6+ messages in thread