61aeb0b029670c95fa742b573926ace3f9344009
[openwrt/staging/jogo.git] /
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
5 node
6
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.
10
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>
15 ---
16 drivers/spmi/spmi.c | 17 +++++++++++++++++
17 include/linux/spmi.h | 3 +++
18 2 files changed, 20 insertions(+)
19
20 --- a/drivers/spmi/spmi.c
21 +++ b/drivers/spmi/spmi.c
22 @@ -388,6 +388,23 @@ static struct bus_type spmi_bus_type = {
23 };
24
25 /**
26 + * spmi_device_from_of() - get the associated SPMI device from a device node
27 + *
28 + * @np: device node
29 + *
30 + * Returns the struct spmi_device associated with a device node or NULL.
31 + */
32 +struct spmi_device *spmi_device_from_of(struct device_node *np)
33 +{
34 + struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np);
35 +
36 + if (dev)
37 + return to_spmi_device(dev);
38 + return NULL;
39 +}
40 +EXPORT_SYMBOL_GPL(spmi_device_from_of);
41 +
42 +/**
43 * spmi_controller_alloc() - Allocate a new SPMI device
44 * @ctrl: associated controller
45 *
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)
51
52 +struct device_node;
53 +
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,
57 size_t len);