Lines Matching +full:ctrl +full:- +full:module
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org>
6 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
13 #include <linux/module.h>
31 len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1); in modalias_show()
32 if (len != -ENODEV) in modalias_show()
52 if (rc != -ENODEV) in serdev_device_uevent()
72 return dev->type == &serdev_device_type; in is_serdev_device()
77 struct serdev_controller *ctrl = to_serdev_controller(dev); in serdev_ctrl_release() local
78 ida_simple_remove(&ctrl_ida, ctrl->nr); in serdev_ctrl_release()
79 kfree(ctrl); in serdev_ctrl_release()
99 * serdev_device_add() - add a device previously constructed via serdev_device_alloc()
104 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_add() local
105 struct device *parent = serdev->dev.parent; in serdev_device_add()
108 dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr); in serdev_device_add()
111 if (ctrl->serdev) { in serdev_device_add()
112 dev_err(&serdev->dev, "controller busy\n"); in serdev_device_add()
113 return -EBUSY; in serdev_device_add()
115 ctrl->serdev = serdev; in serdev_device_add()
117 err = device_add(&serdev->dev); in serdev_device_add()
119 dev_err(&serdev->dev, "Can't add %s, status %pe\n", in serdev_device_add()
120 dev_name(&serdev->dev), ERR_PTR(err)); in serdev_device_add()
124 dev_dbg(&serdev->dev, "device %s registered\n", dev_name(&serdev->dev)); in serdev_device_add()
129 ctrl->serdev = NULL; in serdev_device_add()
140 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_remove() local
142 device_unregister(&serdev->dev); in serdev_device_remove()
143 ctrl->serdev = NULL; in serdev_device_remove()
149 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_open() local
152 if (!ctrl || !ctrl->ops->open) in serdev_device_open()
153 return -EINVAL; in serdev_device_open()
155 ret = ctrl->ops->open(ctrl); in serdev_device_open()
159 ret = pm_runtime_get_sync(&ctrl->dev); in serdev_device_open()
161 pm_runtime_put_noidle(&ctrl->dev); in serdev_device_open()
168 if (ctrl->ops->close) in serdev_device_open()
169 ctrl->ops->close(ctrl); in serdev_device_open()
177 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_close() local
179 if (!ctrl || !ctrl->ops->close) in serdev_device_close()
182 pm_runtime_put(&ctrl->dev); in serdev_device_close()
184 ctrl->ops->close(ctrl); in serdev_device_close()
200 return -ENOMEM; in devm_serdev_device_open()
217 complete(&serdev->write_comp); in serdev_device_write_wakeup()
222 * serdev_device_write_buf() - write data asynchronously
239 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_buf() local
241 if (!ctrl || !ctrl->ops->write_buf) in serdev_device_write_buf()
242 return -EINVAL; in serdev_device_write_buf()
244 return ctrl->ops->write_buf(ctrl, buf, count); in serdev_device_write_buf()
249 * serdev_device_write() - write data synchronously
267 * -ETIMEDOUT or -ERESTARTSYS if interrupted before any bytes were written, or
274 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write() local
278 if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup) in serdev_device_write()
279 return -EINVAL; in serdev_device_write()
284 mutex_lock(&serdev->write_lock); in serdev_device_write()
286 reinit_completion(&serdev->write_comp); in serdev_device_write()
288 ret = ctrl->ops->write_buf(ctrl, buf, count); in serdev_device_write()
294 count -= ret; in serdev_device_write()
299 timeout = wait_for_completion_interruptible_timeout(&serdev->write_comp, in serdev_device_write()
302 mutex_unlock(&serdev->write_lock); in serdev_device_write()
308 if (timeout == -ERESTARTSYS) in serdev_device_write()
309 return -ERESTARTSYS; in serdev_device_write()
311 return -ETIMEDOUT; in serdev_device_write()
320 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_flush() local
322 if (!ctrl || !ctrl->ops->write_flush) in serdev_device_write_flush()
325 ctrl->ops->write_flush(ctrl); in serdev_device_write_flush()
331 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_room() local
333 if (!ctrl || !ctrl->ops->write_room) in serdev_device_write_room()
336 return serdev->ctrl->ops->write_room(ctrl); in serdev_device_write_room()
342 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_baudrate() local
344 if (!ctrl || !ctrl->ops->set_baudrate) in serdev_device_set_baudrate()
347 return ctrl->ops->set_baudrate(ctrl, speed); in serdev_device_set_baudrate()
354 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_flow_control() local
356 if (!ctrl || !ctrl->ops->set_flow_control) in serdev_device_set_flow_control()
359 ctrl->ops->set_flow_control(ctrl, enable); in serdev_device_set_flow_control()
366 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_parity() local
368 if (!ctrl || !ctrl->ops->set_parity) in serdev_device_set_parity()
369 return -EOPNOTSUPP; in serdev_device_set_parity()
371 return ctrl->ops->set_parity(ctrl, parity); in serdev_device_set_parity()
377 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_wait_until_sent() local
379 if (!ctrl || !ctrl->ops->wait_until_sent) in serdev_device_wait_until_sent()
382 ctrl->ops->wait_until_sent(ctrl, timeout); in serdev_device_wait_until_sent()
388 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_get_tiocm() local
390 if (!ctrl || !ctrl->ops->get_tiocm) in serdev_device_get_tiocm()
391 return -EOPNOTSUPP; in serdev_device_get_tiocm()
393 return ctrl->ops->get_tiocm(ctrl); in serdev_device_get_tiocm()
399 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_tiocm() local
401 if (!ctrl || !ctrl->ops->set_tiocm) in serdev_device_set_tiocm()
402 return -EOPNOTSUPP; in serdev_device_set_tiocm()
404 return ctrl->ops->set_tiocm(ctrl, set, clear); in serdev_device_set_tiocm()
410 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_break_ctl() local
412 if (!ctrl || !ctrl->ops->break_ctl) in serdev_device_break_ctl()
413 return -EOPNOTSUPP; in serdev_device_break_ctl()
415 return ctrl->ops->break_ctl(ctrl, break_state); in serdev_device_break_ctl()
421 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_probe()
428 ret = sdrv->probe(to_serdev_device(dev)); in serdev_drv_probe()
437 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_remove()
438 if (sdrv->remove) in serdev_drv_remove()
439 sdrv->remove(to_serdev_device(dev)); in serdev_drv_remove()
452 * serdev_device_alloc() - Allocate a new serdev device
453 * @ctrl: associated controller
458 struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl) in serdev_device_alloc() argument
466 serdev->ctrl = ctrl; in serdev_device_alloc()
467 device_initialize(&serdev->dev); in serdev_device_alloc()
468 serdev->dev.parent = &ctrl->dev; in serdev_device_alloc()
469 serdev->dev.bus = &serdev_bus_type; in serdev_device_alloc()
470 serdev->dev.type = &serdev_device_type; in serdev_device_alloc()
471 init_completion(&serdev->write_comp); in serdev_device_alloc()
472 mutex_init(&serdev->write_lock); in serdev_device_alloc()
478 * serdev_controller_alloc() - Allocate a new serdev controller
490 struct serdev_controller *ctrl; in serdev_controller_alloc() local
496 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); in serdev_controller_alloc()
497 if (!ctrl) in serdev_controller_alloc()
507 ctrl->nr = id; in serdev_controller_alloc()
509 device_initialize(&ctrl->dev); in serdev_controller_alloc()
510 ctrl->dev.type = &serdev_ctrl_type; in serdev_controller_alloc()
511 ctrl->dev.bus = &serdev_bus_type; in serdev_controller_alloc()
512 ctrl->dev.parent = parent; in serdev_controller_alloc()
513 ctrl->dev.of_node = parent->of_node; in serdev_controller_alloc()
514 serdev_controller_set_drvdata(ctrl, &ctrl[1]); in serdev_controller_alloc()
516 dev_set_name(&ctrl->dev, "serial%d", id); in serdev_controller_alloc()
518 pm_runtime_no_callbacks(&ctrl->dev); in serdev_controller_alloc()
519 pm_suspend_ignore_children(&ctrl->dev, true); in serdev_controller_alloc()
521 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in serdev_controller_alloc()
522 return ctrl; in serdev_controller_alloc()
525 kfree(ctrl); in serdev_controller_alloc()
531 static int of_serdev_register_devices(struct serdev_controller *ctrl) in of_serdev_register_devices() argument
538 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_serdev_register_devices()
542 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_serdev_register_devices()
544 serdev = serdev_device_alloc(ctrl); in of_serdev_register_devices()
548 device_set_node(&serdev->dev, of_fwnode_handle(node)); in of_serdev_register_devices()
552 dev_err(&serdev->dev, in of_serdev_register_devices()
560 return -ENODEV; in of_serdev_register_devices()
577 * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches
591 if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) in serdev_acpi_get_uart_resource()
594 sb = &ares->data.uart_serial_bus; in serdev_acpi_get_uart_resource()
595 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART) in serdev_acpi_get_uart_resource()
612 if (lookup->index != -1 && lookup->n++ != lookup->index) in acpi_serdev_parse_resource()
615 status = acpi_get_handle(lookup->device_handle, in acpi_serdev_parse_resource()
616 sb->resource_source.string_ptr, in acpi_serdev_parse_resource()
617 &lookup->controller_handle); in acpi_serdev_parse_resource()
635 lookup->device_handle = acpi_device_handle(adev); in acpi_serdev_do_lookup()
636 lookup->controller_handle = NULL; in acpi_serdev_do_lookup()
637 lookup->n = 0; in acpi_serdev_do_lookup()
645 return -EINVAL; in acpi_serdev_do_lookup()
650 static int acpi_serdev_check_resources(struct serdev_controller *ctrl, in acpi_serdev_check_resources() argument
656 if (acpi_bus_get_status(adev) || !adev->status.present) in acpi_serdev_check_resources()
657 return -EINVAL; in acpi_serdev_check_resources()
660 lookup.index = -1; // we only care for the last device in acpi_serdev_check_resources()
673 acpi_get_parent(adev->handle, &lookup.controller_handle); in acpi_serdev_check_resources()
676 if (ACPI_HANDLE(ctrl->dev.parent) != lookup.controller_handle) in acpi_serdev_check_resources()
677 return -ENODEV; in acpi_serdev_check_resources()
682 static acpi_status acpi_serdev_register_device(struct serdev_controller *ctrl, in acpi_serdev_register_device() argument
688 serdev = serdev_device_alloc(ctrl); in acpi_serdev_register_device()
690 dev_err(&ctrl->dev, "failed to allocate serdev device for %s\n", in acpi_serdev_register_device()
691 dev_name(&adev->dev)); in acpi_serdev_register_device()
695 ACPI_COMPANION_SET(&serdev->dev, adev); in acpi_serdev_register_device()
700 dev_err(&serdev->dev, in acpi_serdev_register_device()
719 struct serdev_controller *ctrl = data; in acpi_serdev_add_device() local
728 if (acpi_serdev_check_resources(ctrl, adev)) in acpi_serdev_add_device()
731 return acpi_serdev_register_device(ctrl, adev); in acpi_serdev_add_device()
735 static int acpi_serdev_register_devices(struct serdev_controller *ctrl) in acpi_serdev_register_devices() argument
741 if (!has_acpi_companion(ctrl->dev.parent)) in acpi_serdev_register_devices()
742 return -ENODEV; in acpi_serdev_register_devices()
750 ret = acpi_quirk_skip_serdev_enumeration(ctrl->dev.parent, &skip); in acpi_serdev_register_devices()
758 acpi_serdev_add_device, NULL, ctrl, NULL); in acpi_serdev_register_devices()
760 dev_warn(&ctrl->dev, "failed to enumerate serdev slaves\n"); in acpi_serdev_register_devices()
762 if (!ctrl->serdev) in acpi_serdev_register_devices()
763 return -ENODEV; in acpi_serdev_register_devices()
768 static inline int acpi_serdev_register_devices(struct serdev_controller *ctrl) in acpi_serdev_register_devices() argument
770 return -ENODEV; in acpi_serdev_register_devices()
775 * serdev_controller_add() - Add an serdev controller
776 * @ctrl: controller to be registered.
781 int serdev_controller_add(struct serdev_controller *ctrl) in serdev_controller_add() argument
787 return -EAGAIN; in serdev_controller_add()
789 ret = device_add(&ctrl->dev); in serdev_controller_add()
793 pm_runtime_enable(&ctrl->dev); in serdev_controller_add()
795 ret_of = of_serdev_register_devices(ctrl); in serdev_controller_add()
796 ret_acpi = acpi_serdev_register_devices(ctrl); in serdev_controller_add()
798 dev_dbg(&ctrl->dev, "no devices registered: of:%pe acpi:%pe\n", in serdev_controller_add()
800 ret = -ENODEV; in serdev_controller_add()
804 dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", in serdev_controller_add()
805 ctrl->nr, &ctrl->dev); in serdev_controller_add()
809 pm_runtime_disable(&ctrl->dev); in serdev_controller_add()
810 device_del(&ctrl->dev); in serdev_controller_add()
819 if (dev->type == &serdev_device_type) in serdev_remove_device()
826 * @ctrl: controller to remove
831 void serdev_controller_remove(struct serdev_controller *ctrl) in serdev_controller_remove() argument
833 if (!ctrl) in serdev_controller_remove()
836 device_for_each_child(&ctrl->dev, NULL, serdev_remove_device); in serdev_controller_remove()
837 pm_runtime_disable(&ctrl->dev); in serdev_controller_remove()
838 device_del(&ctrl->dev); in serdev_controller_remove()
843 * __serdev_device_driver_register() - Register client driver with serdev core
844 * @sdrv: client driver to be associated with client-device.
848 * It is typically called from the driver's module-init function.
850 int __serdev_device_driver_register(struct serdev_device_driver *sdrv, struct module *owner) in __serdev_device_driver_register()
852 sdrv->driver.bus = &serdev_bus_type; in __serdev_device_driver_register()
853 sdrv->driver.owner = owner; in __serdev_device_driver_register()
856 sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS; in __serdev_device_driver_register()
858 return driver_register(&sdrv->driver); in __serdev_device_driver_register()