1 // SPDX-License-Identifier: GPL-2.0-only
3 * sfr.c - driver for special function registers
5 * Copyright (C) 2019 Bootlin.
8 #include <linux/mfd/syscon.h>
9 #include <linux/module.h>
10 #include <linux/nvmem-provider.h>
11 #include <linux/random.h>
13 #include <linux/of_device.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
20 struct atmel_sfr_priv
{
21 struct regmap
*regmap
;
24 static int atmel_sfr_read(void *context
, unsigned int offset
,
25 void *buf
, size_t bytes
)
27 struct atmel_sfr_priv
*priv
= context
;
29 return regmap_bulk_read(priv
->regmap
, SFR_SN0
+ offset
,
33 static struct nvmem_config atmel_sfr_nvmem_config
= {
39 .reg_read
= atmel_sfr_read
,
42 static int atmel_sfr_probe(struct platform_device
*pdev
)
44 struct device
*dev
= &pdev
->dev
;
45 struct device_node
*np
= dev
->of_node
;
46 struct nvmem_device
*nvmem
;
47 struct atmel_sfr_priv
*priv
;
51 priv
= devm_kmalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
55 priv
->regmap
= syscon_node_to_regmap(np
);
56 if (IS_ERR(priv
->regmap
)) {
57 dev_err(dev
, "cannot get parent's regmap\n");
58 return PTR_ERR(priv
->regmap
);
61 atmel_sfr_nvmem_config
.dev
= dev
;
62 atmel_sfr_nvmem_config
.priv
= priv
;
64 nvmem
= devm_nvmem_register(dev
, &atmel_sfr_nvmem_config
);
66 dev_err(dev
, "error registering nvmem config\n");
67 return PTR_ERR(nvmem
);
70 ret
= atmel_sfr_read(priv
, 0, sn
, SFR_SN_SIZE
);
72 add_device_randomness(sn
, SFR_SN_SIZE
);
77 static const struct of_device_id atmel_sfr_dt_ids
[] = {
79 .compatible
= "atmel,sama5d2-sfr",
81 .compatible
= "atmel,sama5d4-sfr",
86 MODULE_DEVICE_TABLE(of
, atmel_sfr_dt_ids
);
88 static struct platform_driver atmel_sfr_driver
= {
89 .probe
= atmel_sfr_probe
,
92 .of_match_table
= atmel_sfr_dt_ids
,
95 module_platform_driver(atmel_sfr_driver
);
97 MODULE_AUTHOR("Kamel Bouhara <kamel.bouhara@bootlin.com>");
98 MODULE_DESCRIPTION("Atmel SFR SN driver for SAMA5D2/4 SoC family");
99 MODULE_LICENSE("GPL v2");