meson-efuse.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Amlogic eFuse Driver
  3. *
  4. * Copyright (c) 2016 Endless Computers, Inc.
  5. * Author: Carlo Caione <carlo@endlessm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/nvmem-provider.h>
  18. #include <linux/of.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/firmware/meson/meson_sm.h>
  21. static int meson_efuse_read(void *context, unsigned int offset,
  22. void *val, size_t bytes)
  23. {
  24. u8 *buf = val;
  25. int ret;
  26. ret = meson_sm_call_read(buf, SM_EFUSE_READ, offset,
  27. bytes, 0, 0, 0);
  28. if (ret < 0)
  29. return ret;
  30. return 0;
  31. }
  32. static struct nvmem_config econfig = {
  33. .name = "meson-efuse",
  34. .owner = THIS_MODULE,
  35. .stride = 1,
  36. .word_size = 1,
  37. .read_only = true,
  38. };
  39. static const struct of_device_id meson_efuse_match[] = {
  40. { .compatible = "amlogic,meson-gxbb-efuse", },
  41. { /* sentinel */ },
  42. };
  43. MODULE_DEVICE_TABLE(of, meson_efuse_match);
  44. static int meson_efuse_probe(struct platform_device *pdev)
  45. {
  46. struct nvmem_device *nvmem;
  47. unsigned int size;
  48. if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
  49. return -EINVAL;
  50. econfig.dev = &pdev->dev;
  51. econfig.reg_read = meson_efuse_read;
  52. econfig.size = size;
  53. nvmem = nvmem_register(&econfig);
  54. if (IS_ERR(nvmem))
  55. return PTR_ERR(nvmem);
  56. platform_set_drvdata(pdev, nvmem);
  57. return 0;
  58. }
  59. static int meson_efuse_remove(struct platform_device *pdev)
  60. {
  61. struct nvmem_device *nvmem = platform_get_drvdata(pdev);
  62. return nvmem_unregister(nvmem);
  63. }
  64. static struct platform_driver meson_efuse_driver = {
  65. .probe = meson_efuse_probe,
  66. .remove = meson_efuse_remove,
  67. .driver = {
  68. .name = "meson-efuse",
  69. .of_match_table = meson_efuse_match,
  70. },
  71. };
  72. module_platform_driver(meson_efuse_driver);
  73. MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
  74. MODULE_DESCRIPTION("Amlogic Meson NVMEM driver");
  75. MODULE_LICENSE("GPL v2");