mfd: kempld-core: Constify variables that point to const structure
[linux-2.6-block.git] / drivers / nvmem / qfprom.c
CommitLineData
4ab11996
SK
1/*
2 * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3 *
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.
7 *
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.
12 */
13
14#include <linux/device.h>
15#include <linux/module.h>
382c62f7 16#include <linux/io.h>
4ab11996
SK
17#include <linux/nvmem-provider.h>
18#include <linux/platform_device.h>
4ab11996 19
ec3672b8
MY
20struct qfprom_priv {
21 void __iomem *base;
22};
23
382c62f7
SK
24static int qfprom_reg_read(void *context,
25 unsigned int reg, void *_val, size_t bytes)
26{
ec3672b8 27 struct qfprom_priv *priv = context;
01d0d2c4
VG
28 u8 *val = _val;
29 int i = 0, words = bytes;
4ab11996 30
382c62f7 31 while (words--)
ec3672b8 32 *val++ = readb(priv->base + reg + i++);
382c62f7
SK
33
34 return 0;
35}
36
37static int qfprom_reg_write(void *context,
38 unsigned int reg, void *_val, size_t bytes)
39{
ec3672b8 40 struct qfprom_priv *priv = context;
01d0d2c4
VG
41 u8 *val = _val;
42 int i = 0, words = bytes;
382c62f7
SK
43
44 while (words--)
ec3672b8 45 writeb(*val++, priv->base + reg + i++);
382c62f7
SK
46
47 return 0;
48}
4ab11996 49
382c62f7
SK
50static struct nvmem_config econfig = {
51 .name = "qfprom",
01d0d2c4 52 .stride = 1,
382c62f7
SK
53 .word_size = 1,
54 .reg_read = qfprom_reg_read,
55 .reg_write = qfprom_reg_write,
56};
57
4ab11996
SK
58static int qfprom_probe(struct platform_device *pdev)
59{
60 struct device *dev = &pdev->dev;
61 struct resource *res;
62 struct nvmem_device *nvmem;
ec3672b8
MY
63 struct qfprom_priv *priv;
64
65 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
66 if (!priv)
67 return -ENOMEM;
4ab11996
SK
68
69 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ec3672b8
MY
70 priv->base = devm_ioremap_resource(dev, res);
71 if (IS_ERR(priv->base))
72 return PTR_ERR(priv->base);
4ab11996 73
382c62f7 74 econfig.size = resource_size(res);
4ab11996 75 econfig.dev = dev;
ec3672b8 76 econfig.priv = priv;
382c62f7 77
e5692efe 78 nvmem = devm_nvmem_register(dev, &econfig);
4ab11996 79
e5692efe 80 return PTR_ERR_OR_ZERO(nvmem);
4ab11996
SK
81}
82
83static const struct of_device_id qfprom_of_match[] = {
84 { .compatible = "qcom,qfprom",},
85 {/* sentinel */},
86};
87MODULE_DEVICE_TABLE(of, qfprom_of_match);
88
89static struct platform_driver qfprom_driver = {
90 .probe = qfprom_probe,
4ab11996
SK
91 .driver = {
92 .name = "qcom,qfprom",
93 .of_match_table = qfprom_of_match,
94 },
95};
96module_platform_driver(qfprom_driver);
97MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
98MODULE_DESCRIPTION("Qualcomm QFPROM driver");
99MODULE_LICENSE("GPL v2");