1 From 0eda4c5c7704363f665f4ccf0327349faad245a4 Mon Sep 17 00:00:00 2001
2 From: Caleb Connolly <caleb.connolly@linaro.org>
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
7 The helper function spmi_device_from_of() takes a device node and
8 returns the SPMI device associated with it.
9 This is like of_find_device_by_node but for SPMI devices.
11 Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
12 Acked-by: Stephen Boyd <sboyd@kernel.org>
13 Link: https://lore.kernel.org/r/20220429220904.137297-2-caleb.connolly@linaro.org
14 Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
16 drivers/spmi/spmi.c | 17 +++++++++++++++++
17 include/linux/spmi.h | 3 +++
18 2 files changed, 20 insertions(+)
20 --- a/drivers/spmi/spmi.c
21 +++ b/drivers/spmi/spmi.c
22 @@ -387,6 +387,23 @@ static struct bus_type spmi_bus_type = {
26 + * spmi_device_from_of() - get the associated SPMI device from a device node
30 + * Returns the struct spmi_device associated with a device node or NULL.
32 +struct spmi_device *spmi_device_from_of(struct device_node *np)
34 + struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np);
37 + return to_spmi_device(dev);
40 +EXPORT_SYMBOL_GPL(spmi_device_from_of);
43 * spmi_controller_alloc() - Allocate a new SPMI device
44 * @ctrl: associated controller
46 --- a/include/linux/spmi.h
47 +++ b/include/linux/spmi.h
48 @@ -164,6 +164,9 @@ static inline void spmi_driver_unregiste
49 module_driver(__spmi_driver, spmi_driver_register, \
50 spmi_driver_unregister)
54 +struct spmi_device *spmi_device_from_of(struct device_node *np);
55 int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf);
56 int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,