Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * UniPhier eFuse driver |
| 3 | * |
| 4 | * Copyright (C) 2017 Socionext Inc. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | */ |
| 15 | |
| 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> |
| 21 | |
| 22 | struct uniphier_efuse_priv { |
| 23 | void __iomem *base; |
| 24 | }; |
| 25 | |
| 26 | static int uniphier_reg_read(void *context, |
| 27 | unsigned int reg, void *_val, size_t bytes) |
| 28 | { |
| 29 | struct uniphier_efuse_priv *priv = context; |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 30 | u8 *val = _val; |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 31 | int offs; |
| 32 | |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 33 | for (offs = 0; offs < bytes; offs += sizeof(u8)) |
| 34 | *val++ = readb(priv->base + reg + offs); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static int uniphier_efuse_probe(struct platform_device *pdev) |
| 40 | { |
| 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; |
| 46 | |
| 47 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 48 | if (!priv) |
| 49 | return -ENOMEM; |
| 50 | |
| 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); |
| 55 | |
Kunihiko Hayashi | 683618b | 2017-12-15 14:06:07 +0000 | [diff] [blame] | 56 | econfig.stride = 1; |
| 57 | econfig.word_size = 1; |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 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; |
Andrey Smirnov | 45ff8ef | 2018-03-09 14:47:00 +0000 | [diff] [blame] | 63 | nvmem = devm_nvmem_register(dev, &econfig); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 64 | |
Andrey Smirnov | 45ff8ef | 2018-03-09 14:47:00 +0000 | [diff] [blame] | 65 | return PTR_ERR_OR_ZERO(nvmem); |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static const struct of_device_id uniphier_efuse_of_match[] = { |
| 69 | { .compatible = "socionext,uniphier-efuse",}, |
| 70 | {/* sentinel */}, |
| 71 | }; |
| 72 | MODULE_DEVICE_TABLE(of, uniphier_efuse_of_match); |
| 73 | |
| 74 | static struct platform_driver uniphier_efuse_driver = { |
| 75 | .probe = uniphier_efuse_probe, |
Keiji Hayashibara | 71c5dd5 | 2017-10-24 10:54:26 +0100 | [diff] [blame] | 76 | .driver = { |
| 77 | .name = "uniphier-efuse", |
| 78 | .of_match_table = uniphier_efuse_of_match, |
| 79 | }, |
| 80 | }; |
| 81 | module_platform_driver(uniphier_efuse_driver); |
| 82 | |
| 83 | MODULE_AUTHOR("Keiji Hayashibara <hayashibara.keiji@socionext.com>"); |
| 84 | MODULE_DESCRIPTION("UniPhier eFuse driver"); |
| 85 | MODULE_LICENSE("GPL v2"); |