nvmem: add QTI SDAM driver
Subsystems (2)
PATCH 1/1 nvmem: add QTI SDAM driver
QTI SDAM driver allows PMIC peripherals to access the shared memory that is available on QTI PMICs.
--- drivers/nvmem/Kconfig | 8 ++ drivers/nvmem/Makefile | 1 + drivers/nvmem/qcom-spmi-sdam.c | 197 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 drivers/nvmem/qcom-spmi-sdam.c
drivers/nvmem/Kconfig +8 -0
@@ -109,6 +109,14 @@ config QCOM_QFPROM This driver can also be built as a module. If so, the module will be called nvmem_qfprom. +config NVMEM_SPMI_SDAM + tristate "SPMI SDAM Support" + depends on SPMI + help + This driver supports the Shared Direct Access Memory Module on + Qualcomm Technologies, Inc. PMICs. It provides the clients + an interface to read/write to the SDAM module's shared memory. + config ROCKCHIP_EFUSE tristate "Rockchip eFuse Support" depends on ARCH_ROCKCHIP || COMPILE_TEST
drivers/nvmem/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_MTK_EFUSE) += nvmem_mtk-efuse.o nvmem_mtk-efuse-y := mtk-efuse.o obj-$(CONFIG_QCOM_QFPROM) += nvmem_qfprom.o nvmem_qfprom-y := qfprom.o +obj-$(CONFIG_NVMEM_SPMI_SDAM) += qcom-spmi-sdam.o obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o nvmem_rockchip_efuse-y := rockchip-efuse.o obj-$(CONFIG_ROCKCHIP_OTP) += nvmem-rockchip-otp.o
drivers/nvmem/qcom-spmi-sdam.c new file +197 -0
197 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 4 lines · Shyam Kumar Thella
QTI SDAM driver allows PMIC peripherals to access the shared memory that is available on QTI PMICs.
Change-Id: I40005646ab1fbba9e0e4aa68e0a61cfbc7b51ba6
No Change-Id upstream please.
Quoted 1 line
Signed-off-by Shyam Kumar Thella <[email protected]>
[..]
Quoted 17 lines
drivers/nvmem/qcom-spmi-sdam.c new file +11
-0@@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2017 The Linux Foundation. All rights reserved. +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/nvmem-provider.h> +#include <linux/regmap.h>
drivers/nvmem/qcom-spmi-sdam.c line 21
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ +#define SDAM_MEM_START 0x40 +#define REGISTER_MAP_ID 0x40 +#define REGISTER_MAP_VERSION 0x41 +#define SDAM_SIZE 0x44 +#define SDAM_PBS_TRIG_SET 0xE5 +#define SDAM_PBS_TRIG_CLR 0xE6 + +struct sdam_chip { +struct platform_device *pdev;
As written right now, pdev is unused. But if you stash struct device * here instead you can replace your pr_err() with dev_err() using this, for better error messages.
drivers/nvmem/qcom-spmi-sdam.c line 23
Quoted 2 lines
drivers/nvmem/qcom-spmi-sdam.c new file +2
-0+struct regmap *regmap; +int base;
This would look better as a unsigned int.
drivers/nvmem/qcom-spmi-sdam.c line 24
Quoted 1 line
drivers/nvmem/qcom-spmi-sdam.c new file +1
-0+int size;
Ditto, or perhaps even size_t.
drivers/nvmem/qcom-spmi-sdam.c line 34
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+}; + +/* read only register offsets */ +static const u8 sdam_ro_map[] = { +REGISTER_MAP_ID , +REGISTER_MAP_VERSION , +SDAM_SIZE +}; + +static bool is_valid (struct sdam_chip *sdam,unsigned int offset,size_t len)
Please do prefix this with "sdam_"
Quoted 7 lines
drivers/nvmem/qcom-spmi-sdam.c new file +7
-0+{ +int sdam_mem_end =SDAM_MEM_START + sdam->size -1 ; + +if (!len) +return false; + + if (offset >= SDAM_MEM_START && offset <= sdam_mem_end
drivers/nvmem/qcom-spmi-sdam.c line 51
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ && (offset + len - 1) <= sdam_mem_end) +return true; + else if ((offset == SDAM_PBS_TRIG_SET || offset == SDAM_PBS_TRIG_CLR) + && (len == 1)) +return true; + +return false; +} + +static bool is_ro (unsigned int offset,size_t len)
Ditto
Quoted 7 lines
drivers/nvmem/qcom-spmi-sdam.c new file +7
-0+{ +int i; + +for (i =0 ; i <ARRAY_SIZE (sdam_ro_map); i++) +if (offset <= sdam_ro_map[i] && (offset + len) > sdam_ro_map[i]) +return true; +
drivers/nvmem/qcom-spmi-sdam.c line 68
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+return false; +} + +static int sdam_read (void *priv,unsigned int offset,void *val,size_t bytes) +{ +struct sdam_chip *sdam = priv; +int rc; + +if (!is_valid (sdam, offset, bytes)) { +pr_err ("Invalid SDAM offset 0x%02x len=%zd\n" , offset, bytes);
Use %#x instead of 0x%02x
Quoted 30 lines
drivers/nvmem/qcom-spmi-sdam.c new file +30
-0+return -EINVAL ; + } + + rc =regmap_bulk_read (sdam->regmap, sdam->base + offset, val, bytes); +if (rc <0 ) +pr_err ("Failed to read SDAM offset 0x%02x len=%zd, rc=%d\n" , + offset, bytes, rc); + +return rc; +} + +static int sdam_write (void *priv,unsigned int offset,void *val,size_t bytes) +{ +struct sdam_chip *sdam = priv; +int rc; + +if (!is_valid (sdam, offset, bytes)) { +pr_err ("Invalid SDAM offset 0x%02x len=%zd\n" , offset, bytes); +return -EINVAL ; + } + +if (is_ro (offset, bytes)) { +pr_err ("Invalid write offset 0x%02x len=%zd\n" , offset, bytes); +return -EINVAL ; + } + + rc =regmap_bulk_write (sdam->regmap, sdam->base + offset, val, bytes); +if (rc <0 ) +pr_err ("Failed to write SDAM offset 0x%02x len=%zd, rc=%d\n" , + offset, bytes, rc);
drivers/nvmem/qcom-spmi-sdam.c line 108
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ +return rc; +} + +static int sdam_probe (struct platform_device *pdev) +{ +struct sdam_chip *sdam; +struct nvmem_device *nvmem; +struct nvmem_config *sdam_config; +unsigned int val =0 ;
No need to initialize this.
drivers/nvmem/qcom-spmi-sdam.c line 116
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c new file +8
-0+int rc; + + sdam =devm_kzalloc (&pdev->dev,sizeof (*sdam),GFP_KERNEL ); +if (!sdam) +return -ENOMEM ; + + sdam_config =devm_kzalloc (&pdev->dev,sizeof (*sdam_config), +GFP_KERNEL );
Can't this be included in struct sdam_chip, for a single allocation?
drivers/nvmem/qcom-spmi-sdam.c line 122
Quoted 6 lines
drivers/nvmem/qcom-spmi-sdam.c new file +6
-0+if (!sdam_config) +return -ENOMEM ; + + sdam->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!sdam->regmap) { +pr_err ("Failed to get regmap handle\n" );
dev_err(&pdev->dev, ...);
drivers/nvmem/qcom-spmi-sdam.c line 126
Quoted 4 lines
drivers/nvmem/qcom-spmi-sdam.c new file +4
-0+return -ENXIO ; + } + + rc =of_property_read_u32 (pdev->dev.of_node,"reg" , &sdam->base);
In other words, base must be u32.
Quoted 22 lines
drivers/nvmem/qcom-spmi-sdam.c new file +22
-0+if (rc <0 ) { +pr_err ("Failed to get SDAM base, rc=%d\n" , rc); +return -EINVAL ; + } + + rc =regmap_read (sdam->regmap, sdam->base +SDAM_SIZE , &val); +if (rc <0 ) { +pr_err ("Failed to read SDAM_SIZE rc=%d\n" , rc); +return -EINVAL ; + } + sdam->size = val *32 ; + + sdam_config->dev = &pdev->dev; + sdam_config->name ="spmi_sdam" ; + sdam_config->id = pdev->id; + sdam_config->owner =THIS_MODULE , + sdam_config->stride =1 ; + sdam_config->word_size =1 ; + sdam_config->reg_read = sdam_read; + sdam_config->reg_write = sdam_write; + sdam_config->priv = sdam; +
drivers/nvmem/qcom-spmi-sdam.c line 158
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ nvmem =nvmem_register (sdam_config); +if (IS_ERR (nvmem)) { +pr_err ("Failed to register SDAM nvmem device rc=%ld\n" , +PTR_ERR (nvmem)); +return -ENXIO ; + } +platform_set_drvdata (pdev, nvmem); + +pr_info ("SDAM base=0x%04x size=%d registered successfully\n" , + sdam->base, sdam->size);
Please don't print notifications in the kernel log. You can possibly use dev_dbg(). Or just look for devices in /sys/bus/platform/drivers/qcom,spmi-sdam/
drivers/nvmem/qcom-spmi-sdam.c line 163
Quoted 5 lines
drivers/nvmem/qcom-spmi-sdam.c new file +5
-0+ +return 0 ; +} + +static int sdam_remove (struct platform_device *pdev)
Instead of using nvmem_register(), use devm_nvmem_register() and just omit the remote function completely - which also allows you to drop the platform_set_drvdata() above.
drivers/nvmem/qcom-spmi-sdam.c line 171
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c new file +8
-0+{ +struct nvmem_device *nvmem =platform_get_drvdata (pdev); + +return nvmem_unregister (nvmem); +} + +static const struct of_device_id sdam_match_table[] = { + {.compatible ="qcom,spmi-sdam" },
Please add a space after { and before }.
Quoted 7 lines
drivers/nvmem/qcom-spmi-sdam.c new file +7
-0+ {}, +}; + +static struct platform_driver sdam_driver = { + .driver = { + .name ="qcom,spmi-sdam" , + .of_match_table = sdam_match_table,
drivers/nvmem/qcom-spmi-sdam.c line 188
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ }, + .probe = sdam_probe, + .remove = sdam_remove, +}; + +static int __init sdam_init (void ) +{ +return platform_driver_register (&sdam_driver); +} +subsys_initcall (sdam_init);
module_platform_driver(sdam_driver), unless you have some strong arguments for why this needs to be subsys_initcall
Regards,
Bjorn
Quoted 12 lines
drivers/nvmem/qcom-spmi-sdam.c new file +9
-0+ +static void __exit sdam_exit(void) +{ +return platform_driver_unregister (&sdam_driver); +} +module_exit (sdam_exit); + +MODULE_DESCRIPTION ("QCOM SPMI SDAM driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 8 lines · Bjorn Andersson
Quoted 4 lines · Shyam Kumar Thella
QTI SDAM driver allows PMIC peripherals to access the shared memory that is available on QTI PMICs.
Change-Id: I40005646ab1fbba9e0e4aa68e0a61cfbc7b51ba6
No Change-Id upstream please.
OK. I will remove it in next patch set.
Quoted 26 lines
Quoted 2 lines
Signed-off-by Shyam Kumar Thella <[email protected]>[..]
Quoted 23 lines
drivers/nvmem/qcom-spmi-sdam.c new file +17
-0@@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2017 The Linux Foundation. All rights reserved. +*/ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/nvmem-provider.h> +#include <linux/regmap.h> + +#define SDAM_MEM_START 0x40 +#define REGISTER_MAP_ID 0x40 +#define REGISTER_MAP_VERSION 0x41 +#define SDAM_SIZE 0x44 +#define SDAM_PBS_TRIG_SET 0xE5
Quoted 9 lines
drivers/nvmem/qcom-spmi-sdam.c line 21
Quoted 4 lines
drivers/nvmem/qcom-spmi-sdam.c new file +4
-0+#define SDAM_PBS_TRIG_CLR 0xE6 + +struct sdam_chip { +struct platform_device *pdev;As written right now, pdev is unused. But if you stash struct device * here instead you can replace your
pr_err()withdev_err()using this, for better error messages.
I will use dev_err messages in next patchset.
Quoted 4 lines
drivers/nvmem/qcom-spmi-sdam.c line 23
Quoted 2 lines
drivers/nvmem/qcom-spmi-sdam.c new file +2
-0+struct regmap *regmap; +int base;This would look better as a unsigned int.
OK. I will do it in next patch set.
Quoted 4 lines
drivers/nvmem/qcom-spmi-sdam.c line 24
Quoted 2 lines
drivers/nvmem/qcom-spmi-sdam.c new file +1
-0+int size;Ditto, or perhaps even
size_t.
OK. I will do it.
Quoted 14 lines
Quoted 11 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+}; + +/* read only register offsets */ +static const u8 sdam_ro_map[] = { +REGISTER_MAP_ID , +REGISTER_MAP_VERSION , +SDAM_SIZE +}; + +static bool is_valid(struct sdam_chip *sdam, unsigned int offset,Quoted 1 line
size_tlen)Please do prefix this with "
sdam_"
OK. I will prefix is_valid and is_ro with "sdam_".
Quoted 13 lines
Quoted 13 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+{ + int sdam_mem_end = SDAM_MEM_START + sdam->size - 1; + + if (!len) + return false; + + if (offset >= SDAM_MEM_START && offset <= sdam_mem_end + && (offset + len - 1) <= sdam_mem_end) + return true; + else if ((offset == SDAM_PBS_TRIG_SET || offset ==
SDAM_PBS_TRIG_CLR)drivers/nvmem/qcom-spmi-sdam.c new file +1
-0+ && (len == 1))
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c line 51
Quoted 6 lines
drivers/nvmem/qcom-spmi-sdam.c new file +6
-0+return true; + +return false; +} + +static bool is_ro (unsigned int offset,size_t len)Ditto
OK.
Quoted 13 lines
Quoted 13 lines
drivers/nvmem/qcom-spmi-sdam.c new file +11
-0+{ +int i; + +for (i =0 ; i <ARRAY_SIZE (sdam_ro_map); i++) +if (offset <= sdam_ro_map[i] && (offset + len) > sdam_ro_map[i]) +return true; + +return false; +} + +static int sdam_read(void *priv, unsigned int offset, void *val,
size_tbytes)
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c line 68
Quoted 6 lines
drivers/nvmem/qcom-spmi-sdam.c new file +6
-0+{ +struct sdam_chip *sdam = priv; +int rc; + +if (!is_valid (sdam, offset, bytes)) { +pr_err ("Invalid SDAM offset 0x%02x len=%zd\n" , offset, bytes);Use %#x instead of 0x%02x
OK. Will do it in next patch set.
Quoted 38 lines
Quoted 38 lines
drivers/nvmem/qcom-spmi-sdam.c new file +4
-0+return -EINVAL ; + } + + rc = regmap_bulk_read(sdam->regmap, sdam->base + offset, val,bytes);
drivers/nvmem/qcom-spmi-sdam.c new file +8
-0+if (rc <0 ) +pr_err ("Failed to read SDAM offset 0x%02x len=%zd, rc=%d\n" , + offset, bytes, rc); + +return rc; +} + +static int sdam_write(void *priv, unsigned int offset, void *val,
size_tbytes)drivers/nvmem/qcom-spmi-sdam.c new file +15
-0+{ +struct sdam_chip *sdam = priv; +int rc; + +if (!is_valid (sdam, offset, bytes)) { +pr_err ("Invalid SDAM offset 0x%02x len=%zd\n" , offset, bytes); +return -EINVAL ; + } + +if (is_ro (offset, bytes)) { +pr_err ("Invalid write offset 0x%02x len=%zd\n" , offset, bytes); +return -EINVAL ; + } + + rc = regmap_bulk_write(sdam->regmap, sdam->base + offset, val,bytes);
drivers/nvmem/qcom-spmi-sdam.c new file +7
-0+if (rc <0 ) +pr_err ("Failed to write SDAM offset 0x%02x len=%zd, rc=%d\n" , + offset, bytes, rc); + +return rc; +} +
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c line 108
Quoted 6 lines
drivers/nvmem/qcom-spmi-sdam.c new file +6
-0+static int sdam_probe (struct platform_device *pdev) +{ +struct sdam_chip *sdam; +struct nvmem_device *nvmem; +struct nvmem_config *sdam_config; +unsigned int val =0 ;No need to initialize this.
OK. I will remove initialization in next patch set.
Quoted 11 lines
drivers/nvmem/qcom-spmi-sdam.c line 116
Quoted 9 lines
drivers/nvmem/qcom-spmi-sdam.c new file +8
-0+int rc; + + sdam =devm_kzalloc (&pdev->dev,sizeof (*sdam),GFP_KERNEL ); +if (!sdam) +return -ENOMEM ; + + sdam_config =devm_kzalloc (&pdev->dev,sizeof (*sdam_config), +GFP_KERNEL );Can't this be included in struct
sdam_chip, for a single allocation?
OK. I will make this a member in struct sdam_chip and eliminate need for dynamic allocation.
Quoted 9 lines
drivers/nvmem/qcom-spmi-sdam.c line 122
Quoted 7 lines
drivers/nvmem/qcom-spmi-sdam.c new file +6
-0+if (!sdam_config) +return -ENOMEM ; + + sdam->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!sdam->regmap) { +pr_err ("Failed to get regmap handle\n" );
dev_err(&pdev->dev, ...);
OK. I will change all pr_err()... to dev_err().
Quoted 7 lines
drivers/nvmem/qcom-spmi-sdam.c line 126
Quoted 5 lines
drivers/nvmem/qcom-spmi-sdam.c new file +4
-0+return -ENXIO ; + } + + rc =of_property_read_u32 (pdev->dev.of_node,"reg" , &sdam->base);In other words, base must be u32.
OK. This will be changed to u32 in next patchs et.
Quoted 29 lines
Quoted 29 lines
drivers/nvmem/qcom-spmi-sdam.c new file +28
-0+if (rc <0 ) { +pr_err ("Failed to get SDAM base, rc=%d\n" , rc); +return -EINVAL ; + } + + rc =regmap_read (sdam->regmap, sdam->base +SDAM_SIZE , &val); +if (rc <0 ) { +pr_err ("Failed to read SDAM_SIZE rc=%d\n" , rc); +return -EINVAL ; + } + sdam->size = val *32 ; + + sdam_config->dev = &pdev->dev; + sdam_config->name ="spmi_sdam" ; + sdam_config->id = pdev->id; + sdam_config->owner =THIS_MODULE , + sdam_config->stride =1 ; + sdam_config->word_size =1 ; + sdam_config->reg_read = sdam_read; + sdam_config->reg_write = sdam_write; + sdam_config->priv = sdam; + + nvmem =nvmem_register (sdam_config); +if (IS_ERR (nvmem)) { +pr_err ("Failed to register SDAM nvmem device rc=%ld\n" , +PTR_ERR (nvmem)); +return -ENXIO ; + }
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c line 158
Quoted 4 lines
drivers/nvmem/qcom-spmi-sdam.c new file +4
-0+platform_set_drvdata (pdev, nvmem); + +pr_info ("SDAM base=0x%04x size=%d registered successfully\n" , + sdam->base, sdam->size);Please don't print notifications in the kernel log. You can possibly use
dev_dbg(). Or just look for devices in/sys/bus/platform/drivers/qcom,spmi-sdam/
OK. I would usedev_dbg() to serve the purpose.
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c line 163
Quoted 6 lines
drivers/nvmem/qcom-spmi-sdam.c new file +5
-0+ +return 0 ; +} + +static int sdam_remove (struct platform_device *pdev)Instead of using
nvmem_register(), usedevm_nvmem_register()and just omit the remote function completely - which also allows you to drop theplatform_set_drvdata()above.
Yes. You are right. That will help omit remove and platform_set_drvdata().
Quoted 11 lines
drivers/nvmem/qcom-spmi-sdam.c line 171
Quoted 9 lines
drivers/nvmem/qcom-spmi-sdam.c new file +8
-0+{ +struct nvmem_device *nvmem =platform_get_drvdata (pdev); + +return nvmem_unregister (nvmem); +} + +static const struct of_device_id sdam_match_table[] = { + {.compatible ="qcom,spmi-sdam" },Please add a space after { and before }.
OK. I will add spaces.
Quoted 13 lines
Quoted 13 lines
drivers/nvmem/qcom-spmi-sdam.c new file +12
-0+ {}, +}; + +static struct platform_driver sdam_driver = { + .driver = { + .name ="qcom,spmi-sdam" , + .of_match_table = sdam_match_table, + }, + .probe = sdam_probe, + .remove = sdam_remove, +}; +
Quoted 8 lines
drivers/nvmem/qcom-spmi-sdam.c line 188
Quoted 5 lines
drivers/nvmem/qcom-spmi-sdam.c new file +5
-0+static int __init sdam_init (void ) +{ +return platform_driver_register (&sdam_driver); +} +subsys_initcall (sdam_init);
module_platform_driver(sdam_driver), unless you have some strong arguments for why this needs to besubsys_initcall
There are some critical sybsystems which depend on nvmem data. So I would prefer using subsys_initcall().
Quoted 16 lines
Regards,
BjornQuoted 12 lines
drivers/nvmem/qcom-spmi-sdam.c new file +9
-1+ +static void __exit sdam_exit(void) +{ +return platform_driver_unregister (&sdam_driver); +} +module_exit (sdam_exit); + +MODULE_DESCRIPTION ("QCOM SPMI SDAM driver" ); +MODULE_LICENSE ("GPL v2" ); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Quoted 10 lines · Shyam Kumar Thella
QTI SDAM driver allows PMIC peripherals to access the shared memory that is available on QTI PMICs.
Change-Id I40005646ab1fbba9e0e4aa68e0a61cfbc7b51ba6Signed-off-by Shyam Kumar Thella <[email protected]>--- drivers/nvmem/Kconfig | 8 ++ drivers/nvmem/Makefile | 1 + drivers/nvmem/qcom-spmi-sdam.c | 197 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+)
Not repeating comments from Bjorn,
Apart from that I have twos comment.
1>
Any reason why there is no Device tree bindings documented for this driver?
Quoted 39 lines
create mode 100644
drivers/nvmem/qcom-spmi-sdam.cdrivers/nvmem/Kconfig +8
-0@@ -109,6 +109,14 @@ config QCOM_QFPROM This driver can also be built as a module. If so, the module will be called nvmem_qfprom. +config NVMEM_SPMI_SDAM + tristate "SPMI SDAM Support" + depends on SPMI + help + This driver supports the Shared Direct Access Memory Module on + Qualcomm Technologies, Inc. PMICs. It provides the clients + an interface to read/write to the SDAM module's shared memory. + config ROCKCHIP_EFUSE tristate "Rockchip eFuse Support" depends on ARCH_ROCKCHIP || COMPILE_TESTdrivers/nvmem/Makefile +1
-0@@ -28,6 +28,7 @@ obj-$(CONFIG_MTK_EFUSE) += nvmem_mtk-efuse.o nvmem_mtk-efuse-y := mtk-efuse.o obj-$(CONFIG_QCOM_QFPROM) += nvmem_qfprom.o nvmem_qfprom-y := qfprom.o +obj-$(CONFIG_NVMEM_SPMI_SDAM) += qcom-spmi-sdam.o obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o nvmem_rockchip_efuse-y := rockchip-efuse.o obj-$(CONFIG_ROCKCHIP_OTP) += nvmem-rockchip-otp.odrivers/nvmem/qcom-spmi-sdam.c new file +0
-0@@ -0,0 +1,197 @@
...
Quoted 38 lines
drivers/nvmem/qcom-spmi-sdam.c new file +38
-0+ +static int sdam_probe (struct platform_device *pdev) +{ +struct sdam_chip *sdam; +struct nvmem_device *nvmem; +struct nvmem_config *sdam_config; +unsigned int val =0 ; +int rc; + + sdam =devm_kzalloc (&pdev->dev,sizeof (*sdam),GFP_KERNEL ); +if (!sdam) +return -ENOMEM ; + + sdam_config =devm_kzalloc (&pdev->dev,sizeof (*sdam_config), +GFP_KERNEL ); +if (!sdam_config) +return -ENOMEM ; + + sdam->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!sdam->regmap) { +pr_err ("Failed to get regmap handle\n" ); +return -ENXIO ; + } + + rc =of_property_read_u32 (pdev->dev.of_node,"reg" , &sdam->base); +if (rc <0 ) { +pr_err ("Failed to get SDAM base, rc=%d\n" , rc); +return -EINVAL ; + } + + rc =regmap_read (sdam->regmap, sdam->base +SDAM_SIZE , &val); +if (rc <0 ) { +pr_err ("Failed to read SDAM_SIZE rc=%d\n" , rc); +return -EINVAL ; + } + sdam->size = val *32 ; + + sdam_config->dev = &pdev->dev;
drivers/nvmem/qcom-spmi-sdam.c line 149
Quoted 10 lines
drivers/nvmem/qcom-spmi-sdam.c new file +10
-0+ sdam_config->name ="spmi_sdam" ; + sdam_config->id = pdev->id; + sdam_config->owner =THIS_MODULE , + sdam_config->stride =1 ; + sdam_config->word_size =1 ; + sdam_config->reg_read = sdam_read; + sdam_config->reg_write = sdam_write; + sdam_config->priv = sdam; + + nvmem =nvmem_register (sdam_config);
2>
May be devm_nvmem_register() here would be better.
--srini
Quoted 2 lines · On Thu 19 Dec 02:29 PST 2019, [email protected] wrote:
Quoted 1 line · Bjorn Andersson
On Tue 17 Dec 01:20 PST 2019, Shyam Kumar Thella wrote:
[..]
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+subsys_initcall(sdam_init);
module_platform_driver(sdam_driver), unless you have some strong arguments for why this needs to besubsys_initcallThere are some critical sybsystems which depend on nvmem data. So I would prefer using
subsys_initcall().
How critical? Needed to kernel module loading?
Can you please document this need somehow? (either a comment here or something in the commit message). Be specific.
THanks,
Bjorn
Quoted 9 lines · Bjorn Andersson
Quoted 2 lines · On Thu 19 Dec 02:29 PST 2019, [email protected] wrote:
Quoted 1 line · Bjorn Andersson
On Tue 17 Dec 01:20 PST 2019, Shyam Kumar Thella wrote:
[..]
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+subsys_initcall(sdam_init);
module_platform_driver(sdam_driver), unless you have some strong arguments for why this needs to besubsys_initcall
Quoted 7 lines
Quoted 2 lines
There are some critical sybsystems which depend on nvmem data. So I would prefer using
subsys_initcall().How critical? Needed to kernel module loading?
Can you please document this need somehow? (either a comment here or something in the commit message). Be specific.
Sure. I will add the need in commit message in its next patch.
Quoted 3 lines
THanks,
Bjorn