Linux 4.19.133
[linux/fpc-iii.git] / drivers / nvmem / qfprom.c
blobe62926b295db25fe1804337f6d797da1f8d238ec
1 /*
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>
16 #include <linux/mod_devicetable.h>
17 #include <linux/io.h>
18 #include <linux/nvmem-provider.h>
19 #include <linux/platform_device.h>
21 struct qfprom_priv {
22 void __iomem *base;
25 static int qfprom_reg_read(void *context,
26 unsigned int reg, void *_val, size_t bytes)
28 struct qfprom_priv *priv = context;
29 u8 *val = _val;
30 int i = 0, words = bytes;
32 while (words--)
33 *val++ = readb(priv->base + reg + i++);
35 return 0;
38 static struct nvmem_config econfig = {
39 .name = "qfprom",
40 .stride = 1,
41 .word_size = 1,
42 .reg_read = qfprom_reg_read,
45 static int qfprom_probe(struct platform_device *pdev)
47 struct device *dev = &pdev->dev;
48 struct resource *res;
49 struct nvmem_device *nvmem;
50 struct qfprom_priv *priv;
52 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
53 if (!priv)
54 return -ENOMEM;
56 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
57 priv->base = devm_ioremap_resource(dev, res);
58 if (IS_ERR(priv->base))
59 return PTR_ERR(priv->base);
61 econfig.size = resource_size(res);
62 econfig.dev = dev;
63 econfig.priv = priv;
65 nvmem = devm_nvmem_register(dev, &econfig);
67 return PTR_ERR_OR_ZERO(nvmem);
70 static const struct of_device_id qfprom_of_match[] = {
71 { .compatible = "qcom,qfprom",},
72 {/* sentinel */},
74 MODULE_DEVICE_TABLE(of, qfprom_of_match);
76 static struct platform_driver qfprom_driver = {
77 .probe = qfprom_probe,
78 .driver = {
79 .name = "qcom,qfprom",
80 .of_match_table = qfprom_of_match,
83 module_platform_driver(qfprom_driver);
84 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
85 MODULE_DESCRIPTION("Qualcomm QFPROM driver");
86 MODULE_LICENSE("GPL v2");