meson-efuse.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. return meson_sm_call_read((u8 *)val, bytes, SM_EFUSE_READ, offset,
  25. bytes, 0, 0, 0);
  26. }
  27. static int meson_efuse_write(void *context, unsigned int offset,
  28. void *val, size_t bytes)
  29. {
  30. return meson_sm_call_write((u8 *)val, bytes, SM_EFUSE_WRITE, offset,
  31. bytes, 0, 0, 0);
  32. }
  33. static const struct of_device_id meson_efuse_match[] = {
  34. { .compatible = "amlogic,meson-gxbb-efuse", },
  35. { /* sentinel */ },
  36. };
  37. MODULE_DEVICE_TABLE(of, meson_efuse_match);
  38. static int meson_efuse_probe(struct platform_device *pdev)
  39. {
  40. struct device *dev = &pdev->dev;
  41. struct nvmem_device *nvmem;
  42. struct nvmem_config *econfig;
  43. unsigned int size;
  44. if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
  45. return -EINVAL;
  46. econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
  47. if (!econfig)
  48. return -ENOMEM;
  49. econfig->dev = dev;
  50. econfig->name = dev_name(dev);
  51. econfig->stride = 1;
  52. econfig->word_size = 1;
  53. econfig->reg_read = meson_efuse_read;
  54. econfig->reg_write = meson_efuse_write;
  55. econfig->size = size;
  56. nvmem = devm_nvmem_register(&pdev->dev, econfig);
  57. return PTR_ERR_OR_ZERO(nvmem);
  58. }
  59. static struct platform_driver meson_efuse_driver = {
  60. .probe = meson_efuse_probe,
  61. .driver = {
  62. .name = "meson-efuse",
  63. .of_match_table = meson_efuse_match,
  64. },
  65. };
  66. module_platform_driver(meson_efuse_driver);
  67. MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
  68. MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
  69. MODULE_LICENSE("GPL v2");