Merge tag 'riscv-for-linus-4.15-rc2_cleanups' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / nvmem / uniphier-efuse.c
blob9d278b4e1dc70552d62de529a0ee79002a22f965
1 /*
2 * UniPhier eFuse driver
4 * Copyright (C) 2017 Socionext Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/device.h>
17 #include <linux/io.h>
18 #include <linux/module.h>
19 #include <linux/nvmem-provider.h>
20 #include <linux/platform_device.h>
22 struct uniphier_efuse_priv {
23 void __iomem *base;
26 static int uniphier_reg_read(void *context,
27 unsigned int reg, void *_val, size_t bytes)
29 struct uniphier_efuse_priv *priv = context;
30 u32 *val = _val;
31 int offs;
33 for (offs = 0; offs < bytes; offs += sizeof(u32))
34 *val++ = readl(priv->base + reg + offs);
36 return 0;
39 static int uniphier_efuse_probe(struct platform_device *pdev)
41 struct device *dev = &pdev->dev;
42 struct resource *res;
43 struct nvmem_device *nvmem;
44 struct nvmem_config econfig = {};
45 struct uniphier_efuse_priv *priv;
47 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
48 if (!priv)
49 return -ENOMEM;
51 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52 priv->base = devm_ioremap_resource(dev, res);
53 if (IS_ERR(priv->base))
54 return PTR_ERR(priv->base);
56 econfig.stride = 4;
57 econfig.word_size = 4;
58 econfig.read_only = true;
59 econfig.reg_read = uniphier_reg_read;
60 econfig.size = resource_size(res);
61 econfig.priv = priv;
62 econfig.dev = dev;
63 nvmem = nvmem_register(&econfig);
64 if (IS_ERR(nvmem))
65 return PTR_ERR(nvmem);
67 platform_set_drvdata(pdev, nvmem);
69 return 0;
72 static int uniphier_efuse_remove(struct platform_device *pdev)
74 struct nvmem_device *nvmem = platform_get_drvdata(pdev);
76 return nvmem_unregister(nvmem);
79 static const struct of_device_id uniphier_efuse_of_match[] = {
80 { .compatible = "socionext,uniphier-efuse",},
81 {/* sentinel */},
83 MODULE_DEVICE_TABLE(of, uniphier_efuse_of_match);
85 static struct platform_driver uniphier_efuse_driver = {
86 .probe = uniphier_efuse_probe,
87 .remove = uniphier_efuse_remove,
88 .driver = {
89 .name = "uniphier-efuse",
90 .of_match_table = uniphier_efuse_of_match,
93 module_platform_driver(uniphier_efuse_driver);
95 MODULE_AUTHOR("Keiji Hayashibara <hayashibara.keiji@socionext.com>");
96 MODULE_DESCRIPTION("UniPhier eFuse driver");
97 MODULE_LICENSE("GPL v2");