uniphier-efuse.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include <linux/device.h>
  16. #include <linux/io.h>
  17. #include <linux/module.h>
  18. #include <linux/nvmem-provider.h>
  19. #include <linux/platform_device.h>
  20. struct uniphier_efuse_priv {
  21. void __iomem *base;
  22. };
  23. static int uniphier_reg_read(void *context,
  24. unsigned int reg, void *_val, size_t bytes)
  25. {
  26. struct uniphier_efuse_priv *priv = context;
  27. u8 *val = _val;
  28. int offs;
  29. for (offs = 0; offs < bytes; offs += sizeof(u8))
  30. *val++ = readb(priv->base + reg + offs);
  31. return 0;
  32. }
  33. static int uniphier_efuse_probe(struct platform_device *pdev)
  34. {
  35. struct device *dev = &pdev->dev;
  36. struct resource *res;
  37. struct nvmem_device *nvmem;
  38. struct nvmem_config econfig = {};
  39. struct uniphier_efuse_priv *priv;
  40. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  41. if (!priv)
  42. return -ENOMEM;
  43. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44. priv->base = devm_ioremap_resource(dev, res);
  45. if (IS_ERR(priv->base))
  46. return PTR_ERR(priv->base);
  47. econfig.stride = 1;
  48. econfig.word_size = 1;
  49. econfig.read_only = true;
  50. econfig.reg_read = uniphier_reg_read;
  51. econfig.size = resource_size(res);
  52. econfig.priv = priv;
  53. econfig.dev = dev;
  54. nvmem = devm_nvmem_register(dev, &econfig);
  55. return PTR_ERR_OR_ZERO(nvmem);
  56. }
  57. static const struct of_device_id uniphier_efuse_of_match[] = {
  58. { .compatible = "socionext,uniphier-efuse",},
  59. {/* sentinel */},
  60. };
  61. MODULE_DEVICE_TABLE(of, uniphier_efuse_of_match);
  62. static struct platform_driver uniphier_efuse_driver = {
  63. .probe = uniphier_efuse_probe,
  64. .driver = {
  65. .name = "uniphier-efuse",
  66. .of_match_table = uniphier_efuse_of_match,
  67. },
  68. };
  69. module_platform_driver(uniphier_efuse_driver);
  70. MODULE_AUTHOR("Keiji Hayashibara <hayashibara.keiji@socionext.com>");
  71. MODULE_DESCRIPTION("UniPhier eFuse driver");
  72. MODULE_LICENSE("GPL v2");