soc: at91: Add Atmel SFR SN (Serial Number) support
PATCH v2 1/1 soc: at91: Add Atmel SFR SN (Serial Number) support
Add support to read SFR's read-only registers providing the SoC Serial Numbers (SN0+SN1) to userspace.
~ # hexdump -n 8 -e'"%d\n"' /sys/bus/nvmem/devices/atmel-sfr0/nvmem 959527243
371539274
---
Changes in v2:
- updated atmel-sfr.c to sfr.c in Makefile
- fixed missing drvdata struct definition
- added missing syscon header
drivers/soc/atmel/Kconfig | 11 ++++ drivers/soc/atmel/Makefile | 1 + drivers/soc/atmel/sfr.c | 116 +++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 drivers/soc/atmel/sfr.c
drivers/soc/atmel/Kconfig +11 -0
@@ -5,3 +5,14 @@ config AT91_SOC_ID default ARCH_AT91 help Include support for the SoC bus on the Atmel ARM SoCs. + +config AT91_SOC_SFR + tristate "Special Function Registers support" + depends on ARCH_AT91 || COMPILE_TEST + help + This is a driver for the Special Function Registers available on + Atmel SAMA5Dx SoCs, providing access to specific aspects of the + integrated memory, bridge implementations, proccessor etc. + + This driver can also be built as a module. If so, the module + will be called sfr.
drivers/soc/atmel/Makefile +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_AT91_SOC_ID) += soc.o +obj-$(CONFIG_AT91_SOC_SFR) += sfr.o
drivers/soc/atmel/sfr.c new file +116 -0
116 lines not on this page · raw message
--
2.23.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi, Kamel,
Quoted 29 lines · Kamel Bouhara
External E-Mail
Add support to read SFR's read-only registers providing the SoC Serial Numbers (SN0+SN1) to userspace.
~ # hexdump -n 8 -e'"%d\n"'
/sys/bus/nvmem/devices/atmel-sfr0/nvmem959527243
371539274Signed-off-by Kamel Bouhara <[email protected]>---
Changes in v2:
- updatedatmel-sfr.ctosfr.cinMakefile
- fixed missing drvdata struct definition
- added missing syscon headerdrivers/soc/atmel/Kconfig | 11 ++++ drivers/soc/atmel/Makefile | 1 + drivers/soc/atmel/sfr.c | 116 +++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 drivers/soc/atmel/sfr.cdrivers/soc/atmel/Kconfig +0
-0@@ -5,3 +5,14 @@ config AT91_SOC_ID default ARCH_AT91
drivers/soc/atmel/Kconfig config AT91_SOC_ID · line 15
Quoted 10 lines
drivers/soc/atmel/Kconfig +8
-0help Include support for the SoC bus on the Atmel ARM SoCs. + +config AT91_SOC_SFR + tristate "Special Function Registers support" + depends on ARCH_AT91 || COMPILE_TEST + help + This is a driver for the Special Function Registers available on + Atmel SAMA5Dx SoCs, providing access to specific aspects of the + integrated memory, bridge implementations, proccessor etc.
typo: processor.
Quoted 26 lines
drivers/soc/atmel/Kconfig +3
-0+ + This driver can also be built as a module. If so, the module + will be called sfr.drivers/soc/atmel/Makefile +1
-0@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_AT91_SOC_ID) += soc.o +obj-$(CONFIG_AT91_SOC_SFR) += sfr.odrivers/soc/atmel/sfr.c new file +9
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* sfr.c - driver for special function registers +* +* Copyright (C) 2019 Bootlin. +* +*/ +#include <linux/device.h> +#include <linux/mfd/syscon.h>
drivers/soc/atmel/sfr.c line 19
Quoted 10 lines
drivers/soc/atmel/sfr.c new file +10
-0+#include <linux/module.h> +#include <linux/nvmem-provider.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define SFR_SN0 0x4c + +struct sfr_priv {
how about renaming this to struct atmel_sfr_priv?
drivers/soc/atmel/sfr.c line 20
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct device *dev;
this is not used, maybe you can drop it?
drivers/soc/atmel/sfr.c line 23
Quoted 3 lines
drivers/soc/atmel/sfr.c new file +3
-0+struct regmap *regmap; +struct nvmem_config *config; +struct atmel_sfr_drvdata *drvdata;
this is not used, maybe you can drop it?
drivers/soc/atmel/sfr.c line 34
Quoted 11 lines
drivers/soc/atmel/sfr.c new file +11
-0+}; + +struct atmel_sfr_drvdata { +unsigned int nregs; +}; + +static int atmel_sfr_read (void *context,unsigned int offset, +void *buf,size_t bytes) +{ +struct sfr_priv *priv = context; +struct atmel_sfr_drvdata *drvdata = priv->drvdata;
looks like you can drop the *drvdata local variable.
Quoted 12 lines
drivers/soc/atmel/sfr.c new file +12
-0+ +return regmap_bulk_read (priv->regmap,SFR_SN0 + offset, + buf, bytes /4 ); +} + +static struct nvmem_config atmel_sfr_nvmem_config = { + .name ="atmel-sfr" , + .read_only = true, + .word_size =4 , + .stride =4 , + .reg_read = atmel_sfr_read, +};
drivers/soc/atmel/sfr.c line 56
Quoted 10 lines
drivers/soc/atmel/sfr.c new file +10
-0+ +static int atmel_sfr_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct sfr_priv *priv; +struct nvmem_device *nvmem; +const struct atmel_sfr_drvdata *drvdata; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
zeroing should not be needed since you update all the priv fields below.
Quoted 4 lines
drivers/soc/atmel/sfr.c new file +4
-0+if (!priv) +return -ENOMEM ; + + drvdata =of_device_get_match_data (dev);
drivers/soc/atmel/sfr.c line 70
Quoted 10 lines
drivers/soc/atmel/sfr.c new file +10
-0+if (!drvdata) +return -EINVAL ; + + priv->regmap =syscon_node_to_regmap (np); +if (IS_ERR (priv->regmap)) { +dev_err (dev,"cannot get parent's regmap\n" ); +return PTR_ERR (priv->regmap); + } + + priv->drvdata = drvdata;
not needed?
Cheers,
ta
Quoted 50 lines
drivers/soc/atmel/sfr.c new file +46
-1+ + atmel_sfr_nvmem_config.size = drvdata->nregs; + atmel_sfr_nvmem_config.dev = dev; + atmel_sfr_nvmem_config.priv = priv; + + priv->config = &atmel_sfr_nvmem_config; + + nvmem =devm_nvmem_register (dev, &atmel_sfr_nvmem_config); +if (IS_ERR (nvmem)) { +dev_err (dev,"error registering nvmem config\n" ); +return PTR_ERR (nvmem); + } + +return 0 ; +} + +static struct atmel_sfr_drvdata sama5d2_sama5d4_drvdata = { + .nregs =2 *4 , +}; + +static const struct of_device_id atmel_sfr_dt_ids[] = { + { + .compatible ="atmel,sama5d2-sfr" , + .data = &sama5d2_sama5d4_drvdata, + }, { + .compatible ="atmel,sama5d4-sfr" , + .data = &sama5d2_sama5d4_drvdata, + }, { +/* sentinel */ + }, +}; +MODULE_DEVICE_TABLE (of, atmel_sfr_dt_ids); + +static struct platform_driver atmel_sfr_driver = { + .probe = atmel_sfr_probe, + .driver = { + .name ="atmel-sfr" , + .of_match_table = atmel_sfr_dt_ids, + }, +}; +module_platform_driver (atmel_sfr_driver); + +MODULE_AUTHOR ("Kamel Bouhara <[email protected]>" ); +MODULE_DESCRIPTION ("Atmel SFR SN driver for SAMA5D2/4 SoC family" ); +MODULE_LICENSE ("GPL v2" ); + --2.23.0
Quoted 6 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On 10/03/2019 12:40 PM, [email protected] wrote:
cut
Quoted 9 lines
how about renaming this to struct
atmel_sfr_priv?drivers/soc/atmel/sfr.c line 20
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct device *dev;this is not used, maybe you can drop it?
drivers/soc/atmel/sfr.c line 22
Quoted 2 lines
drivers/soc/atmel/sfr.c new file +2
-0+struct regmap *regmap; +struct nvmem_config *config;
where is priv->config used?
Quoted 5 lines
drivers/soc/atmel/sfr.c line 23
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct atmel_sfr_drvdata *drvdata;this is not used, maybe you can drop it?
Quoted 1 line
+};
cut
Quoted 1 line
Quoted 1 line
+static struct
atmel_sfr_drvdatasama5d2_sama5d4_drvdata= {
struct should be const. And I'm not sure about the sama5d2_sama5d4 naming. Maybe choose "5d4_drvdata" and use it for 5d2 too? Maybe Nicolas has a preference here.
Thanks,
ta
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ .nregs = 2 * 4, +};
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
[email protected]
maintainerQuoted 21 lines · On 03/10/2019 at 11:50, Tudor Ambarus - M18064 wrote:
On 10/03/2019 12:40 PM, [email protected] wrote:
cutQuoted 9 lines
how about renaming this to struct
atmel_sfr_priv?drivers/soc/atmel/sfr.c line 20
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct device *dev;this is not used, maybe you can drop it?
drivers/soc/atmel/sfr.c line 22
Quoted 2 lines
drivers/soc/atmel/sfr.c new file +2
-0+struct regmap *regmap; +struct nvmem_config *config;where is
priv->configused?Quoted 4 lines
drivers/soc/atmel/sfr.c line 23
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct atmel_sfr_drvdata *drvdata;this is not used, maybe you can drop it?
Quoted 8 lines
Quoted 1 line
Quoted 1 line
+};
cut
Quoted 1 line
Quoted 1 line
+static struct
atmel_sfr_drvdatasama5d2_sama5d4_drvdata= {struct should be const. And I'm not sure about the
sama5d2_sama5d4naming. Maybe choose "5d4_drvdata" and use it for 5d2 too? Maybe Nicolas has a preference here.
I'm not a big fan of "5d3/5d2/5d4" type of naming. If it appeared first in sama5d4, then this name ca be taken to describe sama5d2 reality as well => sama5d4_drvdata.
Now it's dropped in v3: so we're good...
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ .nregs = 2 * 4, +};
Signature · 5 lines
Nicolas Ferre _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hello,
Quoted 20 lines · On 10/3/19 2:06 PM, [email protected] wrote:
Quoted 19 lines · On 03/10/2019 at 11:50, Tudor Ambarus - M18064 wrote:
On 10/03/2019 12:40 PM, [email protected] wrote:
cutQuoted 7 lines
how about renaming this to struct
atmel_sfr_priv?drivers/soc/atmel/sfr.c line 20
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct device *dev;this is not used, maybe you can drop it?
drivers/soc/atmel/sfr.c line 22
Quoted 2 lines
drivers/soc/atmel/sfr.c new file +2
-0+struct regmap *regmap; +struct nvmem_config *config;where is
priv->configused?Quoted 4 lines
drivers/soc/atmel/sfr.c line 23
Quoted 1 line
drivers/soc/atmel/sfr.c new file +1
-0+struct atmel_sfr_drvdata *drvdata;this is not used, maybe you can drop it?
Quoted 1 line
+};
cut
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
+static struct
atmel_sfr_drvdatasama5d2_sama5d4_drvdata= {struct should be const. And I'm not sure about the
sama5d2_sama5d4naming. Maybe choose "5d4_drvdata" and use it for 5d2 too? Maybe Nicolas has a preference here.I'm not a big fan of "5d3/5d2/5d4" type of naming. If it appeared first in sama5d4, then this name ca be taken to describe sama5d2 reality as well =>
sama5d4_drvdata.Now it's dropped in v3: so we're good...
Yes, thanks for the review.
Kamel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel