.. | .. |
---|
9 | 9 | #include <linux/init.h> |
---|
10 | 10 | #include <linux/idr.h> |
---|
11 | 11 | #include <linux/of.h> |
---|
| 12 | +#include <linux/of_device.h> |
---|
12 | 13 | #include <linux/pm_runtime.h> |
---|
13 | 14 | #include <linux/slimbus.h> |
---|
14 | 15 | #include "slimbus.h" |
---|
.. | .. |
---|
20 | 21 | { |
---|
21 | 22 | while (id->manf_id != 0 || id->prod_code != 0) { |
---|
22 | 23 | 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) |
---|
24 | 27 | return id; |
---|
25 | 28 | id++; |
---|
26 | 29 | } |
---|
.. | .. |
---|
32 | 35 | struct slim_device *sbdev = to_slim_device(dev); |
---|
33 | 36 | struct slim_driver *sbdrv = to_slim_driver(drv); |
---|
34 | 37 | |
---|
| 38 | + /* Attempt an OF style match first */ |
---|
| 39 | + if (of_driver_match_device(dev, drv)) |
---|
| 40 | + return 1; |
---|
| 41 | + |
---|
35 | 42 | 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); |
---|
36 | 60 | } |
---|
37 | 61 | |
---|
38 | 62 | static int slim_device_probe(struct device *dev) |
---|
39 | 63 | { |
---|
40 | 64 | struct slim_device *sbdev = to_slim_device(dev); |
---|
41 | 65 | struct slim_driver *sbdrv = to_slim_driver(dev->driver); |
---|
| 66 | + int ret; |
---|
42 | 67 | |
---|
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; |
---|
44 | 82 | } |
---|
45 | 83 | |
---|
46 | 84 | static int slim_device_remove(struct device *dev) |
---|
.. | .. |
---|
57 | 95 | return 0; |
---|
58 | 96 | } |
---|
59 | 97 | |
---|
| 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 | + |
---|
60 | 105 | struct bus_type slimbus_bus = { |
---|
61 | 106 | .name = "slimbus", |
---|
62 | 107 | .match = slim_device_match, |
---|
63 | 108 | .probe = slim_device_probe, |
---|
64 | 109 | .remove = slim_device_remove, |
---|
| 110 | + .uevent = slim_device_uevent, |
---|
65 | 111 | }; |
---|
66 | 112 | EXPORT_SYMBOL_GPL(slimbus_bus); |
---|
67 | 113 | |
---|
.. | .. |
---|
77 | 123 | int __slim_driver_register(struct slim_driver *drv, struct module *owner) |
---|
78 | 124 | { |
---|
79 | 125 | /* 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) |
---|
81 | 127 | return -EINVAL; |
---|
82 | 128 | |
---|
83 | 129 | drv->driver.bus = &slimbus_bus; |
---|
.. | .. |
---|
116 | 162 | sbdev->ctrl = ctrl; |
---|
117 | 163 | INIT_LIST_HEAD(&sbdev->stream_list); |
---|
118 | 164 | 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); |
---|
122 | 167 | |
---|
123 | 168 | dev_set_name(&sbdev->dev, "%x:%x:%x:%x", |
---|
124 | 169 | sbdev->e_addr.manf_id, |
---|
.. | .. |
---|
223 | 268 | mutex_init(&ctrl->lock); |
---|
224 | 269 | mutex_init(&ctrl->sched.m_reconf); |
---|
225 | 270 | init_completion(&ctrl->sched.pause_comp); |
---|
| 271 | + spin_lock_init(&ctrl->txn_lock); |
---|
226 | 272 | |
---|
227 | 273 | dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", |
---|
228 | 274 | ctrl->name, ctrl->dev); |
---|
.. | .. |
---|
260 | 306 | return 0; |
---|
261 | 307 | } |
---|
262 | 308 | 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 | | -} |
---|
280 | 309 | |
---|
281 | 310 | /** |
---|
282 | 311 | * slim_report_absent() - Controller calls this function when a device |
---|
.. | .. |
---|
430 | 459 | |
---|
431 | 460 | sbdev->laddr = laddr; |
---|
432 | 461 | sbdev->is_laddr_valid = true; |
---|
| 462 | + mutex_unlock(&ctrl->lock); |
---|
433 | 463 | |
---|
434 | 464 | slim_device_update_status(sbdev, SLIM_DEVICE_STATUS_UP); |
---|
435 | 465 | |
---|
.. | .. |
---|
437 | 467 | laddr, sbdev->e_addr.manf_id, sbdev->e_addr.prod_code, |
---|
438 | 468 | sbdev->e_addr.dev_index, sbdev->e_addr.instance); |
---|
439 | 469 | |
---|
| 470 | + return 0; |
---|
| 471 | + |
---|
440 | 472 | err: |
---|
441 | 473 | mutex_unlock(&ctrl->lock); |
---|
442 | 474 | return ret; |
---|