]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
slimbus: core: add of_slim_device_get() helper
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tue, 19 Jun 2018 16:12:57 +0000 (17:12 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 7 Jul 2018 15:24:32 +0000 (17:24 +0200)
On SLIMBus controllers like Qcom NGD(non ported device), controller
can request logical address once the remote side is powered, having a
helper function like this to explicitly enumerate the bus is helpful.
Also codec drivers which are taking to interface device would need
such a helper too.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/slimbus/core.c
include/linux/slimbus.h

index 7ddfc675b131fba29bb9419541d58169cba5aa22..88248a4ecad9db8ee74068351f260b8f7959cffb 100644 (file)
@@ -356,6 +356,45 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
 }
 EXPORT_SYMBOL_GPL(slim_get_device);
 
+static int of_slim_match_dev(struct device *dev, void *data)
+{
+       struct device_node *np = data;
+       struct slim_device *sbdev = to_slim_device(dev);
+
+       return (sbdev->dev.of_node == np);
+}
+
+static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
+                                              struct device_node *np)
+{
+       struct slim_device *sbdev;
+       struct device *dev;
+
+       dev = device_find_child(ctrl->dev, np, of_slim_match_dev);
+       if (dev) {
+               sbdev = to_slim_device(dev);
+               return sbdev;
+       }
+
+       return NULL;
+}
+
+/**
+ * of_slim_get_device() - get handle to a device using dt node.
+ *
+ * @ctrl: Controller on which this device will be added/queried
+ * @np: node pointer to device
+ *
+ * Return: pointer to a device if it has already reported. Creates a new
+ * device and returns pointer to it if the device has not yet enumerated.
+ */
+struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
+                                      struct device_node *np)
+{
+       return of_find_slim_device(ctrl, np);
+}
+EXPORT_SYMBOL_GPL(of_slim_get_device);
+
 static int slim_device_alloc_laddr(struct slim_device *sbdev,
                                   bool report_present)
 {
index c36cf121d2cd2b14dcd053ff58b404de3705015f..efa36a852dc3708112f84e9e7c45e55c420f1149 100644 (file)
@@ -138,6 +138,8 @@ static inline void slim_set_devicedata(struct slim_device *dev, void *data)
        dev_set_drvdata(&dev->dev, data);
 }
 
+struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
+                                      struct device_node *np);
 struct slim_device *slim_get_device(struct slim_controller *ctrl,
                                    struct slim_eaddr *e_addr);
 int slim_get_logical_addr(struct slim_device *sbdev);