Commit 9a2139c2 authored by Caleb Connolly's avatar Caleb Connolly Committed by Jonathan Cameron

spmi: add a helper to look up an SPMI device from a device node

The helper function spmi_device_from_of() takes a device node and
returns the SPMI device associated with it.
This is like of_find_device_by_node but for SPMI devices.
Signed-off-by: default avatarCaleb Connolly <caleb.connolly@linaro.org>
Acked-by: default avatarStephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20220429220904.137297-2-caleb.connolly@linaro.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent f2906aa8
...@@ -386,6 +386,23 @@ static struct bus_type spmi_bus_type = { ...@@ -386,6 +386,23 @@ static struct bus_type spmi_bus_type = {
.uevent = spmi_drv_uevent, .uevent = spmi_drv_uevent,
}; };
/**
* spmi_device_from_of() - get the associated SPMI device from a device node
*
* @np: device node
*
* Returns the struct spmi_device associated with a device node or NULL.
*/
struct spmi_device *spmi_device_from_of(struct device_node *np)
{
struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np);
if (dev)
return to_spmi_device(dev);
return NULL;
}
EXPORT_SYMBOL_GPL(spmi_device_from_of);
/** /**
* spmi_controller_alloc() - Allocate a new SPMI device * spmi_controller_alloc() - Allocate a new SPMI device
* @ctrl: associated controller * @ctrl: associated controller
......
...@@ -164,6 +164,9 @@ static inline void spmi_driver_unregister(struct spmi_driver *sdrv) ...@@ -164,6 +164,9 @@ static inline void spmi_driver_unregister(struct spmi_driver *sdrv)
module_driver(__spmi_driver, spmi_driver_register, \ module_driver(__spmi_driver, spmi_driver_register, \
spmi_driver_unregister) spmi_driver_unregister)
struct device_node;
struct spmi_device *spmi_device_from_of(struct device_node *np);
int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf); int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
size_t len); size_t len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment