Lines Matching +full:ctrl +full:- +full:module
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2017, The Linux Foundation
22 while (id->manf_id != 0 || id->prod_code != 0) { in slim_match()
23 if (id->manf_id == sbdev->e_addr.manf_id && in slim_match()
24 id->prod_code == sbdev->e_addr.prod_code && in slim_match()
25 id->dev_index == sbdev->e_addr.dev_index && in slim_match()
26 id->instance == sbdev->e_addr.instance) in slim_match()
42 return !!slim_match(sbdrv->id_table, sbdev); in slim_device_match()
50 if (sbdev->status == status) in slim_device_update_status()
53 sbdev->status = status; in slim_device_update_status()
54 if (!sbdev->dev.driver) in slim_device_update_status()
57 sbdrv = to_slim_driver(sbdev->dev.driver); in slim_device_update_status()
58 if (sbdrv->device_status) in slim_device_update_status()
59 sbdrv->device_status(sbdev, sbdev->status); in slim_device_update_status()
65 struct slim_driver *sbdrv = to_slim_driver(dev->driver); in slim_device_probe()
68 ret = sbdrv->probe(sbdev); in slim_device_probe()
77 dev_err(&sbdev->dev, "Failed to get logical address\n"); in slim_device_probe()
78 ret = -EPROBE_DEFER; in slim_device_probe()
89 if (dev->driver) { in slim_device_remove()
90 sbdrv = to_slim_driver(dev->driver); in slim_device_remove()
91 if (sbdrv->remove) in slim_device_remove()
92 sbdrv->remove(sbdev); in slim_device_remove()
100 return add_uevent_var(env, "MODALIAS=slim:%s", dev_name(&sbdev->dev)); in slim_device_uevent()
113 * __slim_driver_register() - Client driver registration with SLIMbus
115 * @drv:Client driver to be associated with client-device.
116 * @owner: owning module/driver
119 * It is called from the driver's module-init function.
121 int __slim_driver_register(struct slim_driver *drv, struct module *owner) in __slim_driver_register()
124 if (!(drv->driver.of_match_table || drv->id_table) || !drv->probe) in __slim_driver_register()
125 return -EINVAL; in __slim_driver_register()
127 drv->driver.bus = &slimbus_bus; in __slim_driver_register()
128 drv->driver.owner = owner; in __slim_driver_register()
130 return driver_register(&drv->driver); in __slim_driver_register()
135 * slim_driver_unregister() - Undo effect of slim_driver_register
141 driver_unregister(&drv->driver); in slim_driver_unregister()
152 static int slim_add_device(struct slim_controller *ctrl, in slim_add_device() argument
156 sbdev->dev.bus = &slimbus_bus; in slim_add_device()
157 sbdev->dev.parent = ctrl->dev; in slim_add_device()
158 sbdev->dev.release = slim_dev_release; in slim_add_device()
159 sbdev->dev.driver = NULL; in slim_add_device()
160 sbdev->ctrl = ctrl; in slim_add_device()
161 INIT_LIST_HEAD(&sbdev->stream_list); in slim_add_device()
162 spin_lock_init(&sbdev->stream_list_lock); in slim_add_device()
163 sbdev->dev.of_node = of_node_get(node); in slim_add_device()
164 sbdev->dev.fwnode = of_fwnode_handle(node); in slim_add_device()
166 dev_set_name(&sbdev->dev, "%x:%x:%x:%x", in slim_add_device()
167 sbdev->e_addr.manf_id, in slim_add_device()
168 sbdev->e_addr.prod_code, in slim_add_device()
169 sbdev->e_addr.dev_index, in slim_add_device()
170 sbdev->e_addr.instance); in slim_add_device()
172 return device_register(&sbdev->dev); in slim_add_device()
175 static struct slim_device *slim_alloc_device(struct slim_controller *ctrl, in slim_alloc_device() argument
186 sbdev->e_addr = *eaddr; in slim_alloc_device()
187 ret = slim_add_device(ctrl, sbdev, node); in slim_alloc_device()
189 put_device(&sbdev->dev); in slim_alloc_device()
196 static void of_register_slim_devices(struct slim_controller *ctrl) in of_register_slim_devices() argument
198 struct device *dev = ctrl->dev; in of_register_slim_devices()
201 if (!ctrl->dev->of_node) in of_register_slim_devices()
204 for_each_child_of_node(ctrl->dev->of_node, node) { in of_register_slim_devices()
234 sbdev = slim_alloc_device(ctrl, &e_addr, node); in of_register_slim_devices()
241 * slim_register_controller() - Controller bring-up and registration.
243 * @ctrl: Controller to be registered.
249 int slim_register_controller(struct slim_controller *ctrl) in slim_register_controller() argument
257 ctrl->id = id; in slim_register_controller()
259 if (!ctrl->min_cg) in slim_register_controller()
260 ctrl->min_cg = SLIM_MIN_CLK_GEAR; in slim_register_controller()
261 if (!ctrl->max_cg) in slim_register_controller()
262 ctrl->max_cg = SLIM_MAX_CLK_GEAR; in slim_register_controller()
264 ida_init(&ctrl->laddr_ida); in slim_register_controller()
265 idr_init(&ctrl->tid_idr); in slim_register_controller()
266 mutex_init(&ctrl->lock); in slim_register_controller()
267 mutex_init(&ctrl->sched.m_reconf); in slim_register_controller()
268 init_completion(&ctrl->sched.pause_comp); in slim_register_controller()
269 spin_lock_init(&ctrl->txn_lock); in slim_register_controller()
271 dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", in slim_register_controller()
272 ctrl->name, ctrl->dev); in slim_register_controller()
274 of_register_slim_devices(ctrl); in slim_register_controller()
283 of_node_put(sbdev->dev.of_node); in slim_remove_device()
284 device_unregister(&sbdev->dev); in slim_remove_device()
294 * slim_unregister_controller() - Controller tear-down.
296 * @ctrl: Controller to tear-down.
298 int slim_unregister_controller(struct slim_controller *ctrl) in slim_unregister_controller() argument
301 device_for_each_child(ctrl->dev, NULL, slim_ctrl_remove_device); in slim_unregister_controller()
302 ida_free(&ctrl_ida, ctrl->id); in slim_unregister_controller()
309 * slim_report_absent() - Controller calls this function when a device
316 struct slim_controller *ctrl = sbdev->ctrl; in slim_report_absent() local
318 if (!ctrl) in slim_report_absent()
322 mutex_lock(&ctrl->lock); in slim_report_absent()
323 sbdev->is_laddr_valid = false; in slim_report_absent()
324 mutex_unlock(&ctrl->lock); in slim_report_absent()
325 if (!ctrl->get_laddr) in slim_report_absent()
326 ida_free(&ctrl->laddr_ida, sbdev->laddr); in slim_report_absent()
333 return (a->manf_id == b->manf_id && in slim_eaddr_equal()
334 a->prod_code == b->prod_code && in slim_eaddr_equal()
335 a->dev_index == b->dev_index && in slim_eaddr_equal()
336 a->instance == b->instance); in slim_eaddr_equal()
344 return slim_eaddr_equal(&sbdev->e_addr, e_addr); in slim_match_dev()
347 static struct slim_device *find_slim_device(struct slim_controller *ctrl, in find_slim_device() argument
353 dev = device_find_child(ctrl->dev, eaddr, slim_match_dev); in find_slim_device()
363 * slim_get_device() - get handle to a device.
365 * @ctrl: Controller on which this device will be added/queried
371 struct slim_device *slim_get_device(struct slim_controller *ctrl, in slim_get_device() argument
376 sbdev = find_slim_device(ctrl, e_addr); in slim_get_device()
378 sbdev = slim_alloc_device(ctrl, e_addr, NULL); in slim_get_device()
380 return ERR_PTR(-ENOMEM); in slim_get_device()
392 return (sbdev->dev.of_node == np); in of_slim_match_dev()
395 static struct slim_device *of_find_slim_device(struct slim_controller *ctrl, in of_find_slim_device() argument
401 dev = device_find_child(ctrl->dev, np, of_slim_match_dev); in of_find_slim_device()
411 * of_slim_get_device() - get handle to a device using dt node.
413 * @ctrl: Controller on which this device will be added/queried
419 struct slim_device *of_slim_get_device(struct slim_controller *ctrl, in of_slim_get_device() argument
422 return of_find_slim_device(ctrl, np); in of_slim_get_device()
429 struct slim_controller *ctrl = sbdev->ctrl; in slim_device_alloc_laddr() local
433 mutex_lock(&ctrl->lock); in slim_device_alloc_laddr()
434 if (ctrl->get_laddr) { in slim_device_alloc_laddr()
435 ret = ctrl->get_laddr(ctrl, &sbdev->e_addr, &laddr); in slim_device_alloc_laddr()
439 ret = ida_alloc_max(&ctrl->laddr_ida, in slim_device_alloc_laddr()
440 SLIM_LA_MANAGER - 1, GFP_KERNEL); in slim_device_alloc_laddr()
446 ret = -EINVAL; in slim_device_alloc_laddr()
450 if (ctrl->set_laddr) { in slim_device_alloc_laddr()
451 ret = ctrl->set_laddr(ctrl, &sbdev->e_addr, laddr); in slim_device_alloc_laddr()
453 ret = -EINVAL; in slim_device_alloc_laddr()
458 sbdev->laddr = laddr; in slim_device_alloc_laddr()
459 sbdev->is_laddr_valid = true; in slim_device_alloc_laddr()
460 mutex_unlock(&ctrl->lock); in slim_device_alloc_laddr()
464 dev_dbg(ctrl->dev, "setting slimbus l-addr:%x, ea:%x,%x,%x,%x\n", in slim_device_alloc_laddr()
465 laddr, sbdev->e_addr.manf_id, sbdev->e_addr.prod_code, in slim_device_alloc_laddr()
466 sbdev->e_addr.dev_index, sbdev->e_addr.instance); in slim_device_alloc_laddr()
471 mutex_unlock(&ctrl->lock); in slim_device_alloc_laddr()
477 * slim_device_report_present() - Report enumerated device.
479 * @ctrl: Controller with which device is enumerated.
485 * Function returns -EXFULL to indicate that all logical addresses are already
488 int slim_device_report_present(struct slim_controller *ctrl, in slim_device_report_present() argument
494 ret = pm_runtime_get_sync(ctrl->dev); in slim_device_report_present()
496 if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { in slim_device_report_present()
497 dev_err(ctrl->dev, "slim ctrl not active,state:%d, ret:%d\n", in slim_device_report_present()
498 ctrl->sched.clk_state, ret); in slim_device_report_present()
502 sbdev = slim_get_device(ctrl, e_addr); in slim_device_report_present()
504 return -ENODEV; in slim_device_report_present()
506 if (sbdev->is_laddr_valid) { in slim_device_report_present()
507 *laddr = sbdev->laddr; in slim_device_report_present()
514 pm_runtime_mark_last_busy(ctrl->dev); in slim_device_report_present()
515 pm_runtime_put_autosuspend(ctrl->dev); in slim_device_report_present()
521 * slim_get_logical_addr() - get/allocate logical address of a SLIMbus device.
530 if (!sbdev->is_laddr_valid) in slim_get_logical_addr()