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()
102 return add_uevent_var(env, "MODALIAS=slim:%s", dev_name(&sbdev->dev)); in slim_device_uevent()
115 * __slim_driver_register() - Client driver registration with SLIMbus
117 * @drv:Client driver to be associated with client-device.
118 * @owner: owning module/driver
121 * It is called from the driver's module-init function.
123 int __slim_driver_register(struct slim_driver *drv, struct module *owner) in __slim_driver_register()
126 if (!(drv->driver.of_match_table || drv->id_table) || !drv->probe) in __slim_driver_register()
127 return -EINVAL; in __slim_driver_register()
129 drv->driver.bus = &slimbus_bus; in __slim_driver_register()
130 drv->driver.owner = owner; in __slim_driver_register()
132 return driver_register(&drv->driver); in __slim_driver_register()
137 * slim_driver_unregister() - Undo effect of slim_driver_register
143 driver_unregister(&drv->driver); in slim_driver_unregister()
154 static int slim_add_device(struct slim_controller *ctrl, in slim_add_device() argument
158 sbdev->dev.bus = &slimbus_bus; in slim_add_device()
159 sbdev->dev.parent = ctrl->dev; in slim_add_device()
160 sbdev->dev.release = slim_dev_release; in slim_add_device()
161 sbdev->dev.driver = NULL; in slim_add_device()
162 sbdev->ctrl = ctrl; in slim_add_device()
163 INIT_LIST_HEAD(&sbdev->stream_list); in slim_add_device()
164 spin_lock_init(&sbdev->stream_list_lock); in slim_add_device()
165 sbdev->dev.of_node = of_node_get(node); in slim_add_device()
166 sbdev->dev.fwnode = of_fwnode_handle(node); in slim_add_device()
168 dev_set_name(&sbdev->dev, "%x:%x:%x:%x", in slim_add_device()
169 sbdev->e_addr.manf_id, in slim_add_device()
170 sbdev->e_addr.prod_code, in slim_add_device()
171 sbdev->e_addr.dev_index, in slim_add_device()
172 sbdev->e_addr.instance); in slim_add_device()
174 return device_register(&sbdev->dev); in slim_add_device()
177 static struct slim_device *slim_alloc_device(struct slim_controller *ctrl, in slim_alloc_device() argument
188 sbdev->e_addr = *eaddr; in slim_alloc_device()
189 ret = slim_add_device(ctrl, sbdev, node); in slim_alloc_device()
191 put_device(&sbdev->dev); in slim_alloc_device()
198 static void of_register_slim_devices(struct slim_controller *ctrl) in of_register_slim_devices() argument
200 struct device *dev = ctrl->dev; in of_register_slim_devices()
203 if (!ctrl->dev->of_node) in of_register_slim_devices()
206 for_each_child_of_node(ctrl->dev->of_node, node) { in of_register_slim_devices()
236 sbdev = slim_alloc_device(ctrl, &e_addr, node); in of_register_slim_devices()
243 * slim_register_controller() - Controller bring-up and registration.
245 * @ctrl: Controller to be registered.
251 int slim_register_controller(struct slim_controller *ctrl) in slim_register_controller() argument
259 ctrl->id = id; in slim_register_controller()
261 if (!ctrl->min_cg) in slim_register_controller()
262 ctrl->min_cg = SLIM_MIN_CLK_GEAR; in slim_register_controller()
263 if (!ctrl->max_cg) in slim_register_controller()
264 ctrl->max_cg = SLIM_MAX_CLK_GEAR; in slim_register_controller()
266 ida_init(&ctrl->laddr_ida); in slim_register_controller()
267 idr_init(&ctrl->tid_idr); in slim_register_controller()
268 mutex_init(&ctrl->lock); in slim_register_controller()
269 mutex_init(&ctrl->sched.m_reconf); in slim_register_controller()
270 init_completion(&ctrl->sched.pause_comp); in slim_register_controller()
271 spin_lock_init(&ctrl->txn_lock); in slim_register_controller()
273 dev_dbg(ctrl->dev, "Bus [%s] registered:dev:%p\n", in slim_register_controller()
274 ctrl->name, ctrl->dev); in slim_register_controller()
276 of_register_slim_devices(ctrl); in slim_register_controller()
285 of_node_put(sbdev->dev.of_node); in slim_remove_device()
286 device_unregister(&sbdev->dev); in slim_remove_device()
296 * slim_unregister_controller() - Controller tear-down.
298 * @ctrl: Controller to tear-down.
300 int slim_unregister_controller(struct slim_controller *ctrl) in slim_unregister_controller() argument
303 device_for_each_child(ctrl->dev, NULL, slim_ctrl_remove_device); in slim_unregister_controller()
304 ida_simple_remove(&ctrl_ida, ctrl->id); in slim_unregister_controller()
311 * slim_report_absent() - Controller calls this function when a device
318 struct slim_controller *ctrl = sbdev->ctrl; in slim_report_absent() local
320 if (!ctrl) in slim_report_absent()
324 mutex_lock(&ctrl->lock); in slim_report_absent()
325 sbdev->is_laddr_valid = false; in slim_report_absent()
326 mutex_unlock(&ctrl->lock); in slim_report_absent()
327 if (!ctrl->get_laddr) in slim_report_absent()
328 ida_simple_remove(&ctrl->laddr_ida, sbdev->laddr); in slim_report_absent()
335 return (a->manf_id == b->manf_id && in slim_eaddr_equal()
336 a->prod_code == b->prod_code && in slim_eaddr_equal()
337 a->dev_index == b->dev_index && in slim_eaddr_equal()
338 a->instance == b->instance); in slim_eaddr_equal()
346 return slim_eaddr_equal(&sbdev->e_addr, e_addr); in slim_match_dev()
349 static struct slim_device *find_slim_device(struct slim_controller *ctrl, in find_slim_device() argument
355 dev = device_find_child(ctrl->dev, eaddr, slim_match_dev); in find_slim_device()
365 * slim_get_device() - get handle to a device.
367 * @ctrl: Controller on which this device will be added/queried
373 struct slim_device *slim_get_device(struct slim_controller *ctrl, in slim_get_device() argument
378 sbdev = find_slim_device(ctrl, e_addr); in slim_get_device()
380 sbdev = slim_alloc_device(ctrl, e_addr, NULL); in slim_get_device()
382 return ERR_PTR(-ENOMEM); in slim_get_device()
394 return (sbdev->dev.of_node == np); in of_slim_match_dev()
397 static struct slim_device *of_find_slim_device(struct slim_controller *ctrl, in of_find_slim_device() argument
403 dev = device_find_child(ctrl->dev, np, of_slim_match_dev); in of_find_slim_device()
413 * of_slim_get_device() - get handle to a device using dt node.
415 * @ctrl: Controller on which this device will be added/queried
421 struct slim_device *of_slim_get_device(struct slim_controller *ctrl, in of_slim_get_device() argument
424 return of_find_slim_device(ctrl, np); in of_slim_get_device()
431 struct slim_controller *ctrl = sbdev->ctrl; in slim_device_alloc_laddr() local
435 mutex_lock(&ctrl->lock); in slim_device_alloc_laddr()
436 if (ctrl->get_laddr) { in slim_device_alloc_laddr()
437 ret = ctrl->get_laddr(ctrl, &sbdev->e_addr, &laddr); in slim_device_alloc_laddr()
441 ret = ida_simple_get(&ctrl->laddr_ida, in slim_device_alloc_laddr()
442 0, SLIM_LA_MANAGER - 1, GFP_KERNEL); in slim_device_alloc_laddr()
448 ret = -EINVAL; in slim_device_alloc_laddr()
452 if (ctrl->set_laddr) { in slim_device_alloc_laddr()
453 ret = ctrl->set_laddr(ctrl, &sbdev->e_addr, laddr); in slim_device_alloc_laddr()
455 ret = -EINVAL; in slim_device_alloc_laddr()
460 sbdev->laddr = laddr; in slim_device_alloc_laddr()
461 sbdev->is_laddr_valid = true; in slim_device_alloc_laddr()
462 mutex_unlock(&ctrl->lock); in slim_device_alloc_laddr()
466 dev_dbg(ctrl->dev, "setting slimbus l-addr:%x, ea:%x,%x,%x,%x\n", in slim_device_alloc_laddr()
467 laddr, sbdev->e_addr.manf_id, sbdev->e_addr.prod_code, in slim_device_alloc_laddr()
468 sbdev->e_addr.dev_index, sbdev->e_addr.instance); in slim_device_alloc_laddr()
473 mutex_unlock(&ctrl->lock); in slim_device_alloc_laddr()
479 * slim_device_report_present() - Report enumerated device.
481 * @ctrl: Controller with which device is enumerated.
487 * Function returns -EXFULL to indicate that all logical addresses are already
490 int slim_device_report_present(struct slim_controller *ctrl, in slim_device_report_present() argument
496 ret = pm_runtime_get_sync(ctrl->dev); in slim_device_report_present()
498 if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { in slim_device_report_present()
499 dev_err(ctrl->dev, "slim ctrl not active,state:%d, ret:%d\n", in slim_device_report_present()
500 ctrl->sched.clk_state, ret); in slim_device_report_present()
504 sbdev = slim_get_device(ctrl, e_addr); in slim_device_report_present()
506 return -ENODEV; in slim_device_report_present()
508 if (sbdev->is_laddr_valid) { in slim_device_report_present()
509 *laddr = sbdev->laddr; in slim_device_report_present()
516 pm_runtime_mark_last_busy(ctrl->dev); in slim_device_report_present()
517 pm_runtime_put_autosuspend(ctrl->dev); in slim_device_report_present()
523 * slim_get_logical_addr() - get/allocate logical address of a SLIMbus device.
532 if (!sbdev->is_laddr_valid) in slim_get_logical_addr()