hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/slimbus/core.c
....@@ -9,6 +9,7 @@
99 #include <linux/init.h>
1010 #include <linux/idr.h>
1111 #include <linux/of.h>
12
+#include <linux/of_device.h>
1213 #include <linux/pm_runtime.h>
1314 #include <linux/slimbus.h>
1415 #include "slimbus.h"
....@@ -20,7 +21,9 @@
2021 {
2122 while (id->manf_id != 0 || id->prod_code != 0) {
2223 if (id->manf_id == sbdev->e_addr.manf_id &&
23
- id->prod_code == sbdev->e_addr.prod_code)
24
+ id->prod_code == sbdev->e_addr.prod_code &&
25
+ id->dev_index == sbdev->e_addr.dev_index &&
26
+ id->instance == sbdev->e_addr.instance)
2427 return id;
2528 id++;
2629 }
....@@ -32,15 +35,50 @@
3235 struct slim_device *sbdev = to_slim_device(dev);
3336 struct slim_driver *sbdrv = to_slim_driver(drv);
3437
38
+ /* Attempt an OF style match first */
39
+ if (of_driver_match_device(dev, drv))
40
+ return 1;
41
+
3542 return !!slim_match(sbdrv->id_table, sbdev);
43
+}
44
+
45
+static void slim_device_update_status(struct slim_device *sbdev,
46
+ enum slim_device_status status)
47
+{
48
+ struct slim_driver *sbdrv;
49
+
50
+ if (sbdev->status == status)
51
+ return;
52
+
53
+ sbdev->status = status;
54
+ if (!sbdev->dev.driver)
55
+ return;
56
+
57
+ sbdrv = to_slim_driver(sbdev->dev.driver);
58
+ if (sbdrv->device_status)
59
+ sbdrv->device_status(sbdev, sbdev->status);
3660 }
3761
3862 static int slim_device_probe(struct device *dev)
3963 {
4064 struct slim_device *sbdev = to_slim_device(dev);
4165 struct slim_driver *sbdrv = to_slim_driver(dev->driver);
66
+ int ret;
4267
43
- return sbdrv->probe(sbdev);
68
+ ret = sbdrv->probe(sbdev);
69
+ if (ret)
70
+ return ret;
71
+
72
+ /* try getting the logical address after probe */
73
+ ret = slim_get_logical_addr(sbdev);
74
+ if (!ret) {
75
+ slim_device_update_status(sbdev, SLIM_DEVICE_STATUS_UP);
76
+ } else {
77
+ dev_err(&sbdev->dev, "Failed to get logical address\n");
78
+ ret = -EPROBE_DEFER;
79
+ }
80
+
81
+ return ret;
4482 }
4583
4684 static int slim_device_remove(struct device *dev)
....@@ -57,11 +95,19 @@
5795 return 0;
5896 }
5997
98
+static int slim_device_uevent(struct device *dev, struct kobj_uevent_env *env)
99
+{
100
+ struct slim_device *sbdev = to_slim_device(dev);
101
+
102
+ return add_uevent_var(env, "MODALIAS=slim:%s", dev_name(&sbdev->dev));
103
+}
104
+
60105 struct bus_type slimbus_bus = {
61106 .name = "slimbus",
62107 .match = slim_device_match,
63108 .probe = slim_device_probe,
64109 .remove = slim_device_remove,
110
+ .uevent = slim_device_uevent,
65111 };
66112 EXPORT_SYMBOL_GPL(slimbus_bus);
67113
....@@ -77,7 +123,7 @@
77123 int __slim_driver_register(struct slim_driver *drv, struct module *owner)
78124 {
79125 /* ID table and probe are mandatory */
80
- if (!drv->id_table || !drv->probe)
126
+ if (!(drv->driver.of_match_table || drv->id_table) || !drv->probe)
81127 return -EINVAL;
82128
83129 drv->driver.bus = &slimbus_bus;
....@@ -116,9 +162,8 @@
116162 sbdev->ctrl = ctrl;
117163 INIT_LIST_HEAD(&sbdev->stream_list);
118164 spin_lock_init(&sbdev->stream_list_lock);
119
-
120
- if (node)
121
- sbdev->dev.of_node = of_node_get(node);
165
+ sbdev->dev.of_node = of_node_get(node);
166
+ sbdev->dev.fwnode = of_fwnode_handle(node);
122167
123168 dev_set_name(&sbdev->dev, "%x:%x:%x:%x",
124169 sbdev->e_addr.manf_id,
....@@ -223,6 +268,7 @@
223268 mutex_init(&ctrl->lock);
224269 mutex_init(&ctrl->sched.m_reconf);
225270 init_completion(&ctrl->sched.pause_comp);
271
+ spin_lock_init(&ctrl->txn_lock);
226272
227273 dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n",
228274 ctrl->name, ctrl->dev);
....@@ -260,23 +306,6 @@
260306 return 0;
261307 }
262308 EXPORT_SYMBOL_GPL(slim_unregister_controller);
263
-
264
-static void slim_device_update_status(struct slim_device *sbdev,
265
- enum slim_device_status status)
266
-{
267
- struct slim_driver *sbdrv;
268
-
269
- if (sbdev->status == status)
270
- return;
271
-
272
- sbdev->status = status;
273
- if (!sbdev->dev.driver)
274
- return;
275
-
276
- sbdrv = to_slim_driver(sbdev->dev.driver);
277
- if (sbdrv->device_status)
278
- sbdrv->device_status(sbdev, sbdev->status);
279
-}
280309
281310 /**
282311 * slim_report_absent() - Controller calls this function when a device
....@@ -430,6 +459,7 @@
430459
431460 sbdev->laddr = laddr;
432461 sbdev->is_laddr_valid = true;
462
+ mutex_unlock(&ctrl->lock);
433463
434464 slim_device_update_status(sbdev, SLIM_DEVICE_STATUS_UP);
435465
....@@ -437,6 +467,8 @@
437467 laddr, sbdev->e_addr.manf_id, sbdev->e_addr.prod_code,
438468 sbdev->e_addr.dev_index, sbdev->e_addr.instance);
439469
470
+ return 0;
471
+
440472 err:
441473 mutex_unlock(&ctrl->lock);
442474 return ret;