summaryrefslogtreecommitdiff
path: root/drivers/spmi/spmi.c
diff options
context:
space:
mode:
authorCaleb Connolly <caleb.connolly@linaro.org>2022-04-29 23:08:56 +0100
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2022-06-18 13:48:19 +0100
commit9a2139c2912ea64e288749c21452930dc752d4fd (patch)
tree909b1e94cac85cdb1a7860d1cf080d04a44ba610 /drivers/spmi/spmi.c
parentf2906aa863381afb0015a9eb7fefad885d4e5a56 (diff)
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: Caleb Connolly <caleb.connolly@linaro.org> Acked-by: Stephen Boyd <sboyd@kernel.org> Link: https://lore.kernel.org/r/20220429220904.137297-2-caleb.connolly@linaro.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/spmi/spmi.c')
-rw-r--r--drivers/spmi/spmi.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
index b37ead9e2fad..a456ce5141e1 100644
--- a/drivers/spmi/spmi.c
+++ b/drivers/spmi/spmi.c
@@ -387,6 +387,23 @@ static struct bus_type spmi_bus_type = {
};
/**
+ * 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
* @ctrl: associated controller
*