meson-efuse.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Amlogic Meson GX 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, bytes, 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. .stride = 1,
  35. .word_size = 1,
  36. .read_only = true,
  37. };
  38. static const struct of_device_id meson_efuse_match[] = {
  39. { .compatible = "amlogic,meson-gxbb-efuse", },
  40. { /* sentinel */ },
  41. };
  42. MODULE_DEVICE_TABLE(of, meson_efuse_match);
  43. static int meson_efuse_probe(struct platform_device *pdev)
  44. {
  45. struct nvmem_device *nvmem;
  46. unsigned int size;
  47. if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
  48. return -EINVAL;
  49. econfig.dev = &pdev->dev;
  50. econfig.reg_read = meson_efuse_read;
  51. econfig.size = size;
  52. nvmem = devm_nvmem_register(&pdev->dev, &econfig);
  53. return PTR_ERR_OR_ZERO(nvmem);
  54. }
  55. static struct platform_driver meson_efuse_driver = {
  56. .probe = meson_efuse_probe,
  57. .driver = {
  58. .name = "meson-efuse",
  59. .of_match_table = meson_efuse_match,
  60. },
  61. };
  62. module_platform_driver(meson_efuse_driver);
  63. MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
  64. MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
  65. MODULE_LICENSE("GPL v2");