rds: tcp: allow progress of rds_conn_shutdown if the rds_connection is marked ERROR...
[linux-2.6/btrfs-unstable.git] / drivers / nvmem / qfprom.c
blob2bdb6c3893281c65d12a3916c037c07acba8480d
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/io.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;
24 u8 *val = _val;
25 int i = 0, words = bytes;
27 while (words--)
28 *val++ = readb(base + reg + i++);
30 return 0;
33 static int qfprom_reg_write(void *context,
34 unsigned int reg, void *_val, size_t bytes)
36 void __iomem *base = context;
37 u8 *val = _val;
38 int i = 0, words = bytes;
40 while (words--)
41 writeb(*val++, base + reg + i++);
43 return 0;
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 = {
54 .name = "qfprom",
55 .owner = THIS_MODULE,
56 .stride = 1,
57 .word_size = 1,
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;
65 struct resource *res;
66 struct nvmem_device *nvmem;
67 void __iomem *base;
69 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70 base = devm_ioremap_resource(dev, res);
71 if (IS_ERR(base))
72 return PTR_ERR(base);
74 econfig.size = resource_size(res);
75 econfig.dev = dev;
76 econfig.priv = base;
78 nvmem = nvmem_register(&econfig);
79 if (IS_ERR(nvmem))
80 return PTR_ERR(nvmem);
82 platform_set_drvdata(pdev, nvmem);
84 return 0;
87 static const struct of_device_id qfprom_of_match[] = {
88 { .compatible = "qcom,qfprom",},
89 {/* sentinel */},
91 MODULE_DEVICE_TABLE(of, qfprom_of_match);
93 static struct platform_driver qfprom_driver = {
94 .probe = qfprom_probe,
95 .remove = qfprom_remove,
96 .driver = {
97 .name = "qcom,qfprom",
98 .of_match_table = qfprom_of_match,
101 module_platform_driver(qfprom_driver);
102 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
103 MODULE_DESCRIPTION("Qualcomm QFPROM driver");
104 MODULE_LICENSE("GPL v2");