0055-v6.0-spmi-add-a-helper-to-look-up-an-SPMI-device-from-a-d.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 0eda4c5c7704363f665f4ccf0327349faad245a4 Mon Sep 17 00:00:00 2001
  2. From: Caleb Connolly <[email protected]>
  3. Date: Fri, 29 Apr 2022 23:08:56 +0100
  4. Subject: [PATCH] spmi: add a helper to look up an SPMI device from a device
  5. node
  6. The helper function spmi_device_from_of() takes a device node and
  7. returns the SPMI device associated with it.
  8. This is like of_find_device_by_node but for SPMI devices.
  9. Signed-off-by: Caleb Connolly <[email protected]>
  10. Acked-by: Stephen Boyd <[email protected]>
  11. Link: https://lore.kernel.org/r/[email protected]
  12. Signed-off-by: Jonathan Cameron <[email protected]>
  13. ---
  14. drivers/spmi/spmi.c | 17 +++++++++++++++++
  15. include/linux/spmi.h | 3 +++
  16. 2 files changed, 20 insertions(+)
  17. --- a/drivers/spmi/spmi.c
  18. +++ b/drivers/spmi/spmi.c
  19. @@ -388,6 +388,23 @@ static struct bus_type spmi_bus_type = {
  20. };
  21. /**
  22. + * spmi_device_from_of() - get the associated SPMI device from a device node
  23. + *
  24. + * @np: device node
  25. + *
  26. + * Returns the struct spmi_device associated with a device node or NULL.
  27. + */
  28. +struct spmi_device *spmi_device_from_of(struct device_node *np)
  29. +{
  30. + struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np);
  31. +
  32. + if (dev)
  33. + return to_spmi_device(dev);
  34. + return NULL;
  35. +}
  36. +EXPORT_SYMBOL_GPL(spmi_device_from_of);
  37. +
  38. +/**
  39. * spmi_controller_alloc() - Allocate a new SPMI device
  40. * @ctrl: associated controller
  41. *
  42. --- a/include/linux/spmi.h
  43. +++ b/include/linux/spmi.h
  44. @@ -164,6 +164,9 @@ static inline void spmi_driver_unregiste
  45. module_driver(__spmi_driver, spmi_driver_register, \
  46. spmi_driver_unregister)
  47. +struct device_node;
  48. +
  49. +struct spmi_device *spmi_device_from_of(struct device_node *np);
  50. int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
  51. int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
  52. size_t len);