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>
20 static int qfprom_reg_read(void *context,
21 unsigned int reg, void *_val, size_t bytes)
23 void __iomem *base = context;
25 int i = 0, words = bytes / 4;
28 *val++ = readl(base + reg + (i++ * 4));
33 static int qfprom_reg_write(void *context,
34 unsigned int reg, void *_val, size_t bytes)
36 void __iomem *base = context;
38 int i = 0, words = bytes / 4;
41 writel(*val++, base + reg + (i++ * 4));
46 static int qfprom_remove(struct platform_device *pdev)
48 struct nvmem_device *nvmem = platform_get_drvdata(pdev);
50 return nvmem_unregister(nvmem);
53 static struct nvmem_config econfig = {
58 .reg_read = qfprom_reg_read,
59 .reg_write = qfprom_reg_write,
62 static int qfprom_probe(struct platform_device *pdev)
64 struct device *dev = &pdev->dev;
66 struct nvmem_device *nvmem;
69 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70 base = devm_ioremap_resource(dev, res);
74 econfig.size = resource_size(res);
78 nvmem = nvmem_register(&econfig);
80 return PTR_ERR(nvmem);
82 platform_set_drvdata(pdev, nvmem);
87 static const struct of_device_id qfprom_of_match[] = {
88 { .compatible = "qcom,qfprom",},
91 MODULE_DEVICE_TABLE(of, qfprom_of_match);
93 static struct platform_driver qfprom_driver = {
94 .probe = qfprom_probe,
95 .remove = qfprom_remove,
97 .name = "qcom,qfprom",
98 .of_match_table = qfprom_of_match,
101 module_platform_driver(qfprom_driver);
103 MODULE_DESCRIPTION("Qualcomm QFPROM driver");
104 MODULE_LICENSE("GPL v2");