regmap-i3c.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
  3. #include <linux/array_size.h>
  4. #include <linux/regmap.h>
  5. #include <linux/i3c/device.h>
  6. #include <linux/i3c/master.h>
  7. #include <linux/module.h>
  8. static int regmap_i3c_write(void *context, const void *data, size_t count)
  9. {
  10. struct device *dev = context;
  11. struct i3c_device *i3c = dev_to_i3cdev(dev);
  12. struct i3c_xfer xfers[] = {
  13. {
  14. .rnw = false,
  15. .len = count,
  16. .data.out = data,
  17. },
  18. };
  19. return i3c_device_do_xfers(i3c, xfers, ARRAY_SIZE(xfers), I3C_SDR);
  20. }
  21. static int regmap_i3c_read(void *context,
  22. const void *reg, size_t reg_size,
  23. void *val, size_t val_size)
  24. {
  25. struct device *dev = context;
  26. struct i3c_device *i3c = dev_to_i3cdev(dev);
  27. struct i3c_xfer xfers[2];
  28. xfers[0].rnw = false;
  29. xfers[0].len = reg_size;
  30. xfers[0].data.out = reg;
  31. xfers[1].rnw = true;
  32. xfers[1].len = val_size;
  33. xfers[1].data.in = val;
  34. return i3c_device_do_xfers(i3c, xfers, ARRAY_SIZE(xfers), I3C_SDR);
  35. }
  36. static const struct regmap_bus regmap_i3c = {
  37. .write = regmap_i3c_write,
  38. .read = regmap_i3c_read,
  39. };
  40. struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
  41. const struct regmap_config *config,
  42. struct lock_class_key *lock_key,
  43. const char *lock_name)
  44. {
  45. return __devm_regmap_init(&i3c->dev, &regmap_i3c, &i3c->dev, config,
  46. lock_key, lock_name);
  47. }
  48. EXPORT_SYMBOL_GPL(__devm_regmap_init_i3c);
  49. MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>");
  50. MODULE_DESCRIPTION("regmap I3C Module");
  51. MODULE_LICENSE("GPL v2");