summaryrefslogtreecommitdiff
path: root/drivers/nvmem/an8855-efuse.c
blob: d1afde6f623f6bc95aef83b0c2184e22b8bea466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: GPL-2.0
/*
 *  Airoha AN8855 Switch EFUSE Driver
 */

#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/nvmem-provider.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>

#define AN8855_EFUSE_CELL		50

#define AN8855_EFUSE_DATA0		0x1000a500
#define   AN8855_EFUSE_R50O		GENMASK(30, 24)

static int an8855_efuse_read(void *context, unsigned int offset,
			     void *val, size_t bytes)
{
	struct regmap *regmap = context;

	return regmap_bulk_read(regmap, AN8855_EFUSE_DATA0 + offset,
				val, bytes / sizeof(u32));
}

static int an8855_efuse_probe(struct platform_device *pdev)
{
	struct nvmem_config an8855_nvmem_config = {
		.name = "an8855-efuse",
		.size = AN8855_EFUSE_CELL * sizeof(u32),
		.stride = sizeof(u32),
		.word_size = sizeof(u32),
		.reg_read = an8855_efuse_read,
	};
	struct device *dev = &pdev->dev;
	struct nvmem_device *nvmem;
	struct regmap *regmap;

	/* Assign NVMEM priv to MFD regmap */
	regmap = dev_get_regmap(dev->parent, NULL);
	if (!regmap)
		return -ENOENT;

	an8855_nvmem_config.priv = regmap;
	an8855_nvmem_config.dev = dev;
	nvmem = devm_nvmem_register(dev, &an8855_nvmem_config);

	return PTR_ERR_OR_ZERO(nvmem);
}

static const struct of_device_id an8855_efuse_of_match[] = {
	{ .compatible = "airoha,an8855-efuse", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, an8855_efuse_of_match);

static struct platform_driver an8855_efuse_driver = {
	.probe = an8855_efuse_probe,
	.driver = {
		.name = "an8855-efuse",
		.of_match_table = an8855_efuse_of_match,
	},
};
module_platform_driver(an8855_efuse_driver);

MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
MODULE_DESCRIPTION("Driver for AN8855 Switch EFUSE");
MODULE_LICENSE("GPL");