an8855-efuse.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Airoha AN8855 Switch EFUSE Driver
  4. */
  5. #include <linux/mod_devicetable.h>
  6. #include <linux/module.h>
  7. #include <linux/nvmem-provider.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #define AN8855_EFUSE_CELL 50
  11. #define AN8855_EFUSE_DATA0 0x1000a500
  12. #define AN8855_EFUSE_R50O GENMASK(30, 24)
  13. static int an8855_efuse_read(void *context, unsigned int offset,
  14. void *val, size_t bytes)
  15. {
  16. struct regmap *regmap = context;
  17. return regmap_bulk_read(regmap, AN8855_EFUSE_DATA0 + offset,
  18. val, bytes / sizeof(u32));
  19. }
  20. static int an8855_efuse_probe(struct platform_device *pdev)
  21. {
  22. struct nvmem_config an8855_nvmem_config = {
  23. .name = "an8855-efuse",
  24. .size = AN8855_EFUSE_CELL * sizeof(u32),
  25. .stride = sizeof(u32),
  26. .word_size = sizeof(u32),
  27. .reg_read = an8855_efuse_read,
  28. };
  29. struct device *dev = &pdev->dev;
  30. struct nvmem_device *nvmem;
  31. struct regmap *regmap;
  32. /* Assign NVMEM priv to MFD regmap */
  33. regmap = dev_get_regmap(dev->parent, NULL);
  34. if (!regmap)
  35. return -ENOENT;
  36. an8855_nvmem_config.priv = regmap;
  37. an8855_nvmem_config.dev = dev;
  38. nvmem = devm_nvmem_register(dev, &an8855_nvmem_config);
  39. return PTR_ERR_OR_ZERO(nvmem);
  40. }
  41. static const struct of_device_id an8855_efuse_of_match[] = {
  42. { .compatible = "airoha,an8855-efuse", },
  43. { /* sentinel */ }
  44. };
  45. MODULE_DEVICE_TABLE(of, an8855_efuse_of_match);
  46. static struct platform_driver an8855_efuse_driver = {
  47. .probe = an8855_efuse_probe,
  48. .driver = {
  49. .name = "an8855-efuse",
  50. .of_match_table = an8855_efuse_of_match,
  51. },
  52. };
  53. module_platform_driver(an8855_efuse_driver);
  54. MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
  55. MODULE_DESCRIPTION("Driver for AN8855 Switch EFUSE");
  56. MODULE_LICENSE("GPL");