uniphier-efuse.c 2.3 KB

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