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 -ENOTSUPP; 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 -ENOTSUPP; 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 -ENOTSUPP; in serdev_device_set_tiocm()
404 return ctrl->ops->set_tiocm(ctrl, set, clear); in serdev_device_set_tiocm()
410 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_probe()
417 ret = sdrv->probe(to_serdev_device(dev)); in serdev_drv_probe()
426 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_remove()
427 if (sdrv->remove) in serdev_drv_remove()
428 sdrv->remove(to_serdev_device(dev)); in serdev_drv_remove()
443 * serdev_device_alloc() - Allocate a new serdev device
444 * @ctrl: associated controller
449 struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl) in serdev_device_alloc() argument
457 serdev->ctrl = ctrl; in serdev_device_alloc()
458 device_initialize(&serdev->dev); in serdev_device_alloc()
459 serdev->dev.parent = &ctrl->dev; in serdev_device_alloc()
460 serdev->dev.bus = &serdev_bus_type; in serdev_device_alloc()
461 serdev->dev.type = &serdev_device_type; in serdev_device_alloc()
462 init_completion(&serdev->write_comp); in serdev_device_alloc()
463 mutex_init(&serdev->write_lock); in serdev_device_alloc()
469 * serdev_controller_alloc() - Allocate a new serdev controller
481 struct serdev_controller *ctrl; in serdev_controller_alloc() local
487 ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); in serdev_controller_alloc()
488 if (!ctrl) in serdev_controller_alloc()
498 ctrl->nr = id; in serdev_controller_alloc()
500 device_initialize(&ctrl->dev); in serdev_controller_alloc()
501 ctrl->dev.type = &serdev_ctrl_type; in serdev_controller_alloc()
502 ctrl->dev.bus = &serdev_bus_type; in serdev_controller_alloc()
503 ctrl->dev.parent = parent; in serdev_controller_alloc()
504 ctrl->dev.of_node = parent->of_node; in serdev_controller_alloc()
505 serdev_controller_set_drvdata(ctrl, &ctrl[1]); in serdev_controller_alloc()
507 dev_set_name(&ctrl->dev, "serial%d", id); in serdev_controller_alloc()
509 pm_runtime_no_callbacks(&ctrl->dev); in serdev_controller_alloc()
510 pm_suspend_ignore_children(&ctrl->dev, true); in serdev_controller_alloc()
512 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in serdev_controller_alloc()
513 return ctrl; in serdev_controller_alloc()
516 kfree(ctrl); in serdev_controller_alloc()
522 static int of_serdev_register_devices(struct serdev_controller *ctrl) in of_serdev_register_devices() argument
529 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_serdev_register_devices()
533 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_serdev_register_devices()
535 serdev = serdev_device_alloc(ctrl); in of_serdev_register_devices()
539 serdev->dev.of_node = node; in of_serdev_register_devices()
543 dev_err(&serdev->dev, in of_serdev_register_devices()
551 return -ENODEV; in of_serdev_register_devices()
573 if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) in acpi_serdev_parse_resource()
576 if (ares->data.common_serial_bus.type != ACPI_RESOURCE_SERIAL_TYPE_UART) in acpi_serdev_parse_resource()
579 if (lookup->index != -1 && lookup->n++ != lookup->index) in acpi_serdev_parse_resource()
582 sb = &ares->data.uart_serial_bus; in acpi_serdev_parse_resource()
584 status = acpi_get_handle(lookup->device_handle, in acpi_serdev_parse_resource()
585 sb->resource_source.string_ptr, in acpi_serdev_parse_resource()
586 &lookup->controller_handle); in acpi_serdev_parse_resource()
604 lookup->device_handle = acpi_device_handle(adev); in acpi_serdev_do_lookup()
605 lookup->controller_handle = NULL; in acpi_serdev_do_lookup()
606 lookup->n = 0; in acpi_serdev_do_lookup()
614 return -EINVAL; in acpi_serdev_do_lookup()
619 static int acpi_serdev_check_resources(struct serdev_controller *ctrl, in acpi_serdev_check_resources() argument
625 if (acpi_bus_get_status(adev) || !adev->status.present) in acpi_serdev_check_resources()
626 return -EINVAL; in acpi_serdev_check_resources()
629 lookup.index = -1; // we only care for the last device in acpi_serdev_check_resources()
642 acpi_get_parent(adev->handle, &lookup.controller_handle); in acpi_serdev_check_resources()
645 if (ACPI_HANDLE(ctrl->dev.parent) != lookup.controller_handle) in acpi_serdev_check_resources()
646 return -ENODEV; in acpi_serdev_check_resources()
651 static acpi_status acpi_serdev_register_device(struct serdev_controller *ctrl, in acpi_serdev_register_device() argument
657 serdev = serdev_device_alloc(ctrl); in acpi_serdev_register_device()
659 dev_err(&ctrl->dev, "failed to allocate serdev device for %s\n", in acpi_serdev_register_device()
660 dev_name(&adev->dev)); in acpi_serdev_register_device()
664 ACPI_COMPANION_SET(&serdev->dev, adev); in acpi_serdev_register_device()
669 dev_err(&serdev->dev, in acpi_serdev_register_device()
687 struct serdev_controller *ctrl = data; in acpi_serdev_add_device() local
700 if (acpi_serdev_check_resources(ctrl, adev)) in acpi_serdev_add_device()
703 return acpi_serdev_register_device(ctrl, adev); in acpi_serdev_add_device()
707 static int acpi_serdev_register_devices(struct serdev_controller *ctrl) in acpi_serdev_register_devices() argument
711 if (!has_acpi_companion(ctrl->dev.parent)) in acpi_serdev_register_devices()
712 return -ENODEV; in acpi_serdev_register_devices()
716 acpi_serdev_add_device, NULL, ctrl, NULL); in acpi_serdev_register_devices()
718 dev_warn(&ctrl->dev, "failed to enumerate serdev slaves\n"); in acpi_serdev_register_devices()
720 if (!ctrl->serdev) in acpi_serdev_register_devices()
721 return -ENODEV; in acpi_serdev_register_devices()
726 static inline int acpi_serdev_register_devices(struct serdev_controller *ctrl) in acpi_serdev_register_devices() argument
728 return -ENODEV; in acpi_serdev_register_devices()
733 * serdev_controller_add() - Add an serdev controller
734 * @ctrl: controller to be registered.
739 int serdev_controller_add(struct serdev_controller *ctrl) in serdev_controller_add() argument
745 return -EAGAIN; in serdev_controller_add()
747 ret = device_add(&ctrl->dev); in serdev_controller_add()
751 pm_runtime_enable(&ctrl->dev); in serdev_controller_add()
753 ret_of = of_serdev_register_devices(ctrl); in serdev_controller_add()
754 ret_acpi = acpi_serdev_register_devices(ctrl); in serdev_controller_add()
756 dev_dbg(&ctrl->dev, "no devices registered: of:%pe acpi:%pe\n", in serdev_controller_add()
758 ret = -ENODEV; in serdev_controller_add()
762 dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", in serdev_controller_add()
763 ctrl->nr, &ctrl->dev); in serdev_controller_add()
767 pm_runtime_disable(&ctrl->dev); in serdev_controller_add()
768 device_del(&ctrl->dev); in serdev_controller_add()
777 if (dev->type == &serdev_device_type) in serdev_remove_device()
784 * @ctrl: controller to remove
789 void serdev_controller_remove(struct serdev_controller *ctrl) in serdev_controller_remove() argument
793 if (!ctrl) in serdev_controller_remove()
796 dummy = device_for_each_child(&ctrl->dev, NULL, in serdev_controller_remove()
798 pm_runtime_disable(&ctrl->dev); in serdev_controller_remove()
799 device_del(&ctrl->dev); in serdev_controller_remove()
804 * serdev_driver_register() - Register client driver with serdev core
805 * @sdrv: client driver to be associated with client-device.
808 * It is typically called from the driver's module-init function.
810 int __serdev_device_driver_register(struct serdev_device_driver *sdrv, struct module *owner) in __serdev_device_driver_register()
812 sdrv->driver.bus = &serdev_bus_type; in __serdev_device_driver_register()
813 sdrv->driver.owner = owner; in __serdev_device_driver_register()
816 sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS; in __serdev_device_driver_register()
818 return driver_register(&sdrv->driver); in __serdev_device_driver_register()