2 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/device.h>
15 #include <linux/module.h>
17 #include <linux/nvmem-provider.h>
18 #include <linux/platform_device.h>
24 static int qfprom_reg_read(void *context
,
25 unsigned int reg
, void *_val
, size_t bytes
)
27 struct qfprom_priv
*priv
= context
;
29 int i
= 0, words
= bytes
;
32 *val
++ = readb(priv
->base
+ reg
+ i
++);
37 static int qfprom_reg_write(void *context
,
38 unsigned int reg
, void *_val
, size_t bytes
)
40 struct qfprom_priv
*priv
= context
;
42 int i
= 0, words
= bytes
;
45 writeb(*val
++, priv
->base
+ reg
+ i
++);
50 static int qfprom_remove(struct platform_device
*pdev
)
52 struct nvmem_device
*nvmem
= platform_get_drvdata(pdev
);
54 return nvmem_unregister(nvmem
);
57 static struct nvmem_config econfig
= {
61 .reg_read
= qfprom_reg_read
,
62 .reg_write
= qfprom_reg_write
,
65 static int qfprom_probe(struct platform_device
*pdev
)
67 struct device
*dev
= &pdev
->dev
;
69 struct nvmem_device
*nvmem
;
70 struct qfprom_priv
*priv
;
72 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
76 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
77 priv
->base
= devm_ioremap_resource(dev
, res
);
78 if (IS_ERR(priv
->base
))
79 return PTR_ERR(priv
->base
);
81 econfig
.size
= resource_size(res
);
85 nvmem
= nvmem_register(&econfig
);
87 return PTR_ERR(nvmem
);
89 platform_set_drvdata(pdev
, nvmem
);
94 static const struct of_device_id qfprom_of_match
[] = {
95 { .compatible
= "qcom,qfprom",},
98 MODULE_DEVICE_TABLE(of
, qfprom_of_match
);
100 static struct platform_driver qfprom_driver
= {
101 .probe
= qfprom_probe
,
102 .remove
= qfprom_remove
,
104 .name
= "qcom,qfprom",
105 .of_match_table
= qfprom_of_match
,
108 module_platform_driver(qfprom_driver
);
109 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
110 MODULE_DESCRIPTION("Qualcomm QFPROM driver");
111 MODULE_LICENSE("GPL v2");