Commit | Line | Data |
---|---|---|
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> | |
16 | #include <linux/nvmem-provider.h> | |
17 | #include <linux/platform_device.h> | |
18 | #include <linux/regmap.h> | |
19 | ||
20 | static struct regmap_config qfprom_regmap_config = { | |
21 | .reg_bits = 32, | |
22 | .val_bits = 8, | |
23 | .reg_stride = 1, | |
3b2b9ead | 24 | .val_format_endian = REGMAP_ENDIAN_LITTLE, |
4ab11996 SK |
25 | }; |
26 | ||
27 | static struct nvmem_config econfig = { | |
28 | .name = "qfprom", | |
29 | .owner = THIS_MODULE, | |
30 | }; | |
31 | ||
32 | static int qfprom_remove(struct platform_device *pdev) | |
33 | { | |
34 | struct nvmem_device *nvmem = platform_get_drvdata(pdev); | |
35 | ||
36 | return nvmem_unregister(nvmem); | |
37 | } | |
38 | ||
39 | static int qfprom_probe(struct platform_device *pdev) | |
40 | { | |
41 | struct device *dev = &pdev->dev; | |
42 | struct resource *res; | |
43 | struct nvmem_device *nvmem; | |
44 | struct regmap *regmap; | |
45 | void __iomem *base; | |
46 | ||
47 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
48 | base = devm_ioremap_resource(dev, res); | |
49 | if (IS_ERR(base)) | |
50 | return PTR_ERR(base); | |
51 | ||
52 | qfprom_regmap_config.max_register = resource_size(res) - 1; | |
53 | ||
54 | regmap = devm_regmap_init_mmio(dev, base, &qfprom_regmap_config); | |
55 | if (IS_ERR(regmap)) { | |
56 | dev_err(dev, "regmap init failed\n"); | |
57 | return PTR_ERR(regmap); | |
58 | } | |
59 | econfig.dev = dev; | |
60 | nvmem = nvmem_register(&econfig); | |
61 | if (IS_ERR(nvmem)) | |
62 | return PTR_ERR(nvmem); | |
63 | ||
64 | platform_set_drvdata(pdev, nvmem); | |
65 | ||
66 | return 0; | |
67 | } | |
68 | ||
69 | static const struct of_device_id qfprom_of_match[] = { | |
70 | { .compatible = "qcom,qfprom",}, | |
71 | {/* sentinel */}, | |
72 | }; | |
73 | MODULE_DEVICE_TABLE(of, qfprom_of_match); | |
74 | ||
75 | static struct platform_driver qfprom_driver = { | |
76 | .probe = qfprom_probe, | |
77 | .remove = qfprom_remove, | |
78 | .driver = { | |
79 | .name = "qcom,qfprom", | |
80 | .of_match_table = qfprom_of_match, | |
81 | }, | |
82 | }; | |
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"); |