nvmem: meson-efuse: add write support
Subsystems (2)
Jerome Brunet
reviewercover nvmem: meson-efuse: add write support
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:
Quoted 1 line
fdt rm /efuse read-only
Tested on the gxl libretech-cc
[0]: https://lkml.kernel.org/r/20180316145021.8517-1-jbrunet at 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(-)
Signature · 1 line
2.14.3
Jerome Brunet
reviewerPATCH 1/2 nvmem: meson-efuse: remove econfig global
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
--- drivers/nvmem/meson-efuse.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/nvmem/meson-efuse.c +14 -11
@@ -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);
Signature · 1 line
2.14.3
Jerome Brunet
reviewerPATCH 2/2 nvmem: meson-efuse: add write support
In reply to Jerome BrunetAdd write support to the meson-gx efuse driver.
Beware, this efuse is one time programmable !
--- drivers/nvmem/meson-efuse.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/nvmem/meson-efuse.c +15 -1
@@ -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);
Signature · 1 line
2.14.3
Jerome Brunet
reviewerQuoted 7 lines · Jerome Brunet
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].
Quoted 7 lines
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:
Quoted 1 line
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
Quoted 10 lines
[0]: https://lkml.kernel.org/r/20180316145021.8517-1-jbrunet at baylibre.com
Jerome Brunet (2):
nvmem: meson-efuse: remove econfig global
nvmem: meson-efuse: add write supportdrivers/nvmem/meson-efuse.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
Quoted 12 lines · Jerome Brunet
Quoted 11 lines · Jerome Brunet
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:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
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
Quoted 14 lines
Regards
JeromeQuoted 10 lines
[0]: https://lkml.kernel.org/r/20180316145021.8517-1-jbrunet at baylibre.com
Jerome Brunet (2):
nvmem: meson-efuse: remove econfig global
nvmem: meson-efuse: add write supportdrivers/nvmem/meson-efuse.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
Quoted 7 lines · Jerome Brunet
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].
Quoted 7 lines
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:
Quoted 1 line
fdt rm /efuse read-only
Tested on the gxl libretech-cc
For the series,