1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
6 #include <linux/device.h>
7 #include <linux/module.h>
8 #include <linux/mod_devicetable.h>
10 #include <linux/nvmem-provider.h>
11 #include <linux/platform_device.h>
17 static int qfprom_reg_read(void *context
,
18 unsigned int reg
, void *_val
, size_t bytes
)
20 struct qfprom_priv
*priv
= context
;
22 int i
= 0, words
= bytes
;
25 *val
++ = readb(priv
->base
+ reg
+ i
++);
30 static int qfprom_reg_write(void *context
,
31 unsigned int reg
, void *_val
, size_t bytes
)
33 struct qfprom_priv
*priv
= context
;
35 int i
= 0, words
= bytes
;
38 writeb(*val
++, priv
->base
+ reg
+ i
++);
43 static struct nvmem_config econfig
= {
47 .reg_read
= qfprom_reg_read
,
48 .reg_write
= qfprom_reg_write
,
51 static int qfprom_probe(struct platform_device
*pdev
)
53 struct device
*dev
= &pdev
->dev
;
55 struct nvmem_device
*nvmem
;
56 struct qfprom_priv
*priv
;
58 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
62 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
63 priv
->base
= devm_ioremap_resource(dev
, res
);
64 if (IS_ERR(priv
->base
))
65 return PTR_ERR(priv
->base
);
67 econfig
.size
= resource_size(res
);
71 nvmem
= devm_nvmem_register(dev
, &econfig
);
73 return PTR_ERR_OR_ZERO(nvmem
);
76 static const struct of_device_id qfprom_of_match
[] = {
77 { .compatible
= "qcom,qfprom",},
80 MODULE_DEVICE_TABLE(of
, qfprom_of_match
);
82 static struct platform_driver qfprom_driver
= {
83 .probe
= qfprom_probe
,
85 .name
= "qcom,qfprom",
86 .of_match_table
= qfprom_of_match
,
89 module_platform_driver(qfprom_driver
);
90 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
91 MODULE_DESCRIPTION("Qualcomm QFPROM driver");
92 MODULE_LICENSE("GPL v2");