Lines Matching +full:buffered +full:- +full:negative

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.
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()
78 ida_simple_remove(&ctrl_ida, ctrl->nr); 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()
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()
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()
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()
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
229 * Note that any accepted data has only been buffered by the controller; use
234 * the write buffer), or a negative errno on errors.
239 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_buf()
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
259 * Note that any accepted data has only been buffered by the controller; use
267 * -ETIMEDOUT or -ERESTARTSYS if interrupted before any bytes were written, or
268 * a negative errno on errors.
274 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write()
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()
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()
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()
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()
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()
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()
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()
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()
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()
441 * serdev_device_alloc() - Allocate a new serdev device
455 serdev->ctrl = ctrl; in serdev_device_alloc()
456 device_initialize(&serdev->dev); in serdev_device_alloc()
457 serdev->dev.parent = &ctrl->dev; in serdev_device_alloc()
458 serdev->dev.bus = &serdev_bus_type; in serdev_device_alloc()
459 serdev->dev.type = &serdev_device_type; in serdev_device_alloc()
460 init_completion(&serdev->write_comp); in serdev_device_alloc()
461 mutex_init(&serdev->write_lock); in serdev_device_alloc()
467 * serdev_controller_alloc() - Allocate a new serdev controller
496 ctrl->nr = id; in serdev_controller_alloc()
498 device_initialize(&ctrl->dev); in serdev_controller_alloc()
499 ctrl->dev.type = &serdev_ctrl_type; in serdev_controller_alloc()
500 ctrl->dev.bus = &serdev_bus_type; in serdev_controller_alloc()
501 ctrl->dev.parent = parent; in serdev_controller_alloc()
502 ctrl->dev.of_node = parent->of_node; in serdev_controller_alloc()
505 dev_set_name(&ctrl->dev, "serial%d", id); in serdev_controller_alloc()
507 pm_runtime_no_callbacks(&ctrl->dev); in serdev_controller_alloc()
508 pm_suspend_ignore_children(&ctrl->dev, true); in serdev_controller_alloc()
510 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in serdev_controller_alloc()
527 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_serdev_register_devices()
531 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_serdev_register_devices()
537 serdev->dev.of_node = node; in of_serdev_register_devices()
541 dev_err(&serdev->dev, in of_serdev_register_devices()
549 return -ENODEV; in of_serdev_register_devices()
566 * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches
580 if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) in serdev_acpi_get_uart_resource()
583 sb = &ares->data.uart_serial_bus; in serdev_acpi_get_uart_resource()
584 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART) in serdev_acpi_get_uart_resource()
601 if (lookup->index != -1 && lookup->n++ != lookup->index) in acpi_serdev_parse_resource()
604 status = acpi_get_handle(lookup->device_handle, in acpi_serdev_parse_resource()
605 sb->resource_source.string_ptr, in acpi_serdev_parse_resource()
606 &lookup->controller_handle); in acpi_serdev_parse_resource()
624 lookup->device_handle = acpi_device_handle(adev); in acpi_serdev_do_lookup()
625 lookup->controller_handle = NULL; in acpi_serdev_do_lookup()
626 lookup->n = 0; in acpi_serdev_do_lookup()
634 return -EINVAL; in acpi_serdev_do_lookup()
645 if (acpi_bus_get_status(adev) || !adev->status.present) in acpi_serdev_check_resources()
646 return -EINVAL; in acpi_serdev_check_resources()
649 lookup.index = -1; // we only care for the last device in acpi_serdev_check_resources()
662 acpi_get_parent(adev->handle, &lookup.controller_handle); in acpi_serdev_check_resources()
665 if (ACPI_HANDLE(ctrl->dev.parent) != lookup.controller_handle) in acpi_serdev_check_resources()
666 return -ENODEV; in acpi_serdev_check_resources()
679 dev_err(&ctrl->dev, "failed to allocate serdev device for %s\n", in acpi_serdev_register_device()
680 dev_name(&adev->dev)); in acpi_serdev_register_device()
684 ACPI_COMPANION_SET(&serdev->dev, adev); in acpi_serdev_register_device()
689 dev_err(&serdev->dev, in acpi_serdev_register_device()
731 if (!has_acpi_companion(ctrl->dev.parent)) in acpi_serdev_register_devices()
732 return -ENODEV; in acpi_serdev_register_devices()
738 dev_warn(&ctrl->dev, "failed to enumerate serdev slaves\n"); in acpi_serdev_register_devices()
740 if (!ctrl->serdev) in acpi_serdev_register_devices()
741 return -ENODEV; in acpi_serdev_register_devices()
748 return -ENODEV; in acpi_serdev_register_devices()
753 * serdev_controller_add() - Add an serdev controller
765 return -EAGAIN; in serdev_controller_add()
767 ret = device_add(&ctrl->dev); in serdev_controller_add()
771 pm_runtime_enable(&ctrl->dev); in serdev_controller_add()
776 dev_dbg(&ctrl->dev, "no devices registered: of:%pe acpi:%pe\n", in serdev_controller_add()
778 ret = -ENODEV; in serdev_controller_add()
782 dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", in serdev_controller_add()
783 ctrl->nr, &ctrl->dev); in serdev_controller_add()
787 pm_runtime_disable(&ctrl->dev); in serdev_controller_add()
788 device_del(&ctrl->dev); in serdev_controller_add()
797 if (dev->type == &serdev_device_type) in serdev_remove_device()
814 device_for_each_child(&ctrl->dev, NULL, serdev_remove_device); in serdev_controller_remove()
815 pm_runtime_disable(&ctrl->dev); in serdev_controller_remove()
816 device_del(&ctrl->dev); in serdev_controller_remove()
821 * __serdev_device_driver_register() - Register client driver with serdev core
822 * @sdrv: client driver to be associated with client-device.
826 * It is typically called from the driver's module-init function.
830 sdrv->driver.bus = &serdev_bus_type; in __serdev_device_driver_register()
831 sdrv->driver.owner = owner; in __serdev_device_driver_register()
834 sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS; in __serdev_device_driver_register()
836 return driver_register(&sdrv->driver); in __serdev_device_driver_register()