Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 2 | /* |
| 3 | * UniPhier eFuse driver |
| 4 | * |
| 5 | * Copyright (C) 2017 Socionext Inc. |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/device.h> |
| 9 | #include <linux/io.h> |
| 10 | #include <linux/module.h> |
Randy Dunlap | ac31672 | 2018-06-19 22:47:28 -0700 | [diff] [blame] | 11 | #include <linux/mod_devicetable.h> |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 12 | #include <linux/nvmem-provider.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | |
| 15 | struct uniphier_efuse_priv { |
| 16 | void __iomem *base; |
| 17 | }; |
| 18 | |
| 19 | static int uniphier_reg_read(void *context, |
| 20 | unsigned int reg, void *_val, size_t bytes) |
| 21 | { |
| 22 | struct uniphier_efuse_priv *priv = context; |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 23 | u8 *val = _val; |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 24 | int offs; |
| 25 | |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 26 | for (offs = 0; offs < bytes; offs += sizeof(u8)) |
| 27 | *val++ = readb(priv->base + reg + offs); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static int uniphier_efuse_probe(struct platform_device *pdev) |
| 33 | { |
| 34 | struct device *dev = &pdev->dev; |
| 35 | struct resource *res; |
| 36 | struct nvmem_device *nvmem; |
| 37 | struct nvmem_config econfig = {}; |
| 38 | struct uniphier_efuse_priv *priv; |
| 39 | |
| 40 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 41 | if (!priv) |
| 42 | return -ENOMEM; |
| 43 | |
| 44 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 45 | priv->base = devm_ioremap_resource(dev, res); |
| 46 | if (IS_ERR(priv->base)) |
| 47 | return PTR_ERR(priv->base); |
| 48 | |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 49 | econfig.stride = 1; |
| 50 | econfig.word_size = 1; |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 51 | econfig.read_only = true; |
| 52 | econfig.reg_read = uniphier_reg_read; |
| 53 | econfig.size = resource_size(res); |
| 54 | econfig.priv = priv; |
| 55 | econfig.dev = dev; |
Andrey Smirnov | 45ff8ef | 2018-03-09 14:47:00 +0000 | [diff] [blame] | 56 | nvmem = devm_nvmem_register(dev, &econfig); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 57 | |
Andrey Smirnov | 45ff8ef | 2018-03-09 14:47:00 +0000 | [diff] [blame] | 58 | return PTR_ERR_OR_ZERO(nvmem); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static const struct of_device_id uniphier_efuse_of_match[] = { |
| 62 | { .compatible = "socionext,uniphier-efuse",}, |
| 63 | {/* sentinel */}, |
| 64 | }; |
| 65 | MODULE_DEVICE_TABLE(of, uniphier_efuse_of_match); |
| 66 | |
| 67 | static struct platform_driver uniphier_efuse_driver = { |
| 68 | .probe = uniphier_efuse_probe, |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 69 | .driver = { |
| 70 | .name = "uniphier-efuse", |
| 71 | .of_match_table = uniphier_efuse_of_match, |
| 72 | }, |
| 73 | }; |
| 74 | module_platform_driver(uniphier_efuse_driver); |
| 75 | |
| 76 | MODULE_AUTHOR("Keiji Hayashibara <hayashibara.keiji@socionext.com>"); |
| 77 | MODULE_DESCRIPTION("UniPhier eFuse driver"); |
| 78 | MODULE_LICENSE("GPL v2"); |