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.
33 len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1); in modalias_show()
34 if (len != -ENODEV) in modalias_show()
54 if (rc != -ENODEV) in serdev_device_uevent()
74 return dev->type == &serdev_device_type; in is_serdev_device()
80 ida_free(&ctrl_ida, ctrl->nr); in serdev_ctrl_release()
101 * serdev_device_add() - add a device previously constructed via serdev_device_alloc()
106 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_add()
107 struct device *parent = serdev->dev.parent; in serdev_device_add()
110 dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr); in serdev_device_add()
113 if (ctrl->serdev) { in serdev_device_add()
114 dev_err(&serdev->dev, "controller busy\n"); in serdev_device_add()
115 return -EBUSY; in serdev_device_add()
117 ctrl->serdev = serdev; in serdev_device_add()
119 err = device_add(&serdev->dev); in serdev_device_add()
121 dev_err(&serdev->dev, "Can't add %s, status %pe\n", in serdev_device_add()
122 dev_name(&serdev->dev), ERR_PTR(err)); in serdev_device_add()
126 dev_dbg(&serdev->dev, "device %s registered\n", dev_name(&serdev->dev)); in serdev_device_add()
131 ctrl->serdev = NULL; in serdev_device_add()
142 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_remove()
144 device_unregister(&serdev->dev); in serdev_device_remove()
145 ctrl->serdev = NULL; in serdev_device_remove()
151 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_open()
154 if (!ctrl || !ctrl->ops->open) in serdev_device_open()
155 return -EINVAL; in serdev_device_open()
157 ret = ctrl->ops->open(ctrl); in serdev_device_open()
161 ret = pm_runtime_get_sync(&ctrl->dev); in serdev_device_open()
163 pm_runtime_put_noidle(&ctrl->dev); in serdev_device_open()
170 if (ctrl->ops->close) in serdev_device_open()
171 ctrl->ops->close(ctrl); in serdev_device_open()
179 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_close()
181 if (!ctrl || !ctrl->ops->close) in serdev_device_close()
184 pm_runtime_put(&ctrl->dev); in serdev_device_close()
186 ctrl->ops->close(ctrl); in serdev_device_close()
209 complete(&serdev->write_comp); in serdev_device_write_wakeup()
214 * serdev_device_write_buf() - write data asynchronously
221 * Note that any accepted data has only been buffered by the controller; use
226 * the write buffer), or a negative errno on errors.
230 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_buf()
232 if (!ctrl || !ctrl->ops->write_buf) in serdev_device_write_buf()
233 return -EINVAL; in serdev_device_write_buf()
235 return ctrl->ops->write_buf(ctrl, buf, count); in serdev_device_write_buf()
240 * serdev_device_write() - write data synchronously
250 * Note that any accepted data has only been buffered by the controller; use
258 * -ETIMEDOUT or -ERESTARTSYS if interrupted before any bytes were written, or
259 * a negative errno on errors.
264 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write()
268 if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup) in serdev_device_write()
269 return -EINVAL; in serdev_device_write()
274 mutex_lock(&serdev->write_lock); in serdev_device_write()
276 reinit_completion(&serdev->write_comp); in serdev_device_write()
278 ret = ctrl->ops->write_buf(ctrl, buf, count); in serdev_device_write()
284 count -= ret; in serdev_device_write()
289 timeout = wait_for_completion_interruptible_timeout(&serdev->write_comp, in serdev_device_write()
292 mutex_unlock(&serdev->write_lock); in serdev_device_write()
298 if (timeout == -ERESTARTSYS) in serdev_device_write()
299 return -ERESTARTSYS; in serdev_device_write()
301 return -ETIMEDOUT; in serdev_device_write()
310 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_flush()
312 if (!ctrl || !ctrl->ops->write_flush) in serdev_device_write_flush()
315 ctrl->ops->write_flush(ctrl); in serdev_device_write_flush()
321 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_write_room()
323 if (!ctrl || !ctrl->ops->write_room) in serdev_device_write_room()
326 return serdev->ctrl->ops->write_room(ctrl); in serdev_device_write_room()
332 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_baudrate()
334 if (!ctrl || !ctrl->ops->set_baudrate) in serdev_device_set_baudrate()
337 return ctrl->ops->set_baudrate(ctrl, speed); in serdev_device_set_baudrate()
344 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_flow_control()
346 if (!ctrl || !ctrl->ops->set_flow_control) in serdev_device_set_flow_control()
349 ctrl->ops->set_flow_control(ctrl, enable); in serdev_device_set_flow_control()
356 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_parity()
358 if (!ctrl || !ctrl->ops->set_parity) in serdev_device_set_parity()
359 return -EOPNOTSUPP; in serdev_device_set_parity()
361 return ctrl->ops->set_parity(ctrl, parity); in serdev_device_set_parity()
367 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_wait_until_sent()
369 if (!ctrl || !ctrl->ops->wait_until_sent) in serdev_device_wait_until_sent()
372 ctrl->ops->wait_until_sent(ctrl, timeout); in serdev_device_wait_until_sent()
378 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_get_tiocm()
380 if (!ctrl || !ctrl->ops->get_tiocm) in serdev_device_get_tiocm()
381 return -EOPNOTSUPP; in serdev_device_get_tiocm()
383 return ctrl->ops->get_tiocm(ctrl); in serdev_device_get_tiocm()
389 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_set_tiocm()
391 if (!ctrl || !ctrl->ops->set_tiocm) in serdev_device_set_tiocm()
392 return -EOPNOTSUPP; in serdev_device_set_tiocm()
394 return ctrl->ops->set_tiocm(ctrl, set, clear); in serdev_device_set_tiocm()
400 struct serdev_controller *ctrl = serdev->ctrl; in serdev_device_break_ctl()
402 if (!ctrl || !ctrl->ops->break_ctl) in serdev_device_break_ctl()
403 return -EOPNOTSUPP; in serdev_device_break_ctl()
405 return ctrl->ops->break_ctl(ctrl, break_state); in serdev_device_break_ctl()
411 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_probe()
418 ret = sdrv->probe(to_serdev_device(dev)); in serdev_drv_probe()
427 const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); in serdev_drv_remove()
428 if (sdrv->remove) in serdev_drv_remove()
429 sdrv->remove(to_serdev_device(dev)); in serdev_drv_remove()
442 * serdev_device_alloc() - Allocate a new serdev device
456 serdev->ctrl = ctrl; in serdev_device_alloc()
457 device_initialize(&serdev->dev); in serdev_device_alloc()
458 serdev->dev.parent = &ctrl->dev; in serdev_device_alloc()
459 serdev->dev.bus = &serdev_bus_type; in serdev_device_alloc()
460 serdev->dev.type = &serdev_device_type; in serdev_device_alloc()
461 init_completion(&serdev->write_comp); in serdev_device_alloc()
462 mutex_init(&serdev->write_lock); in serdev_device_alloc()
468 * serdev_controller_alloc() - Allocate a new serdev controller
499 ctrl->nr = id; in serdev_controller_alloc()
501 device_initialize(&ctrl->dev); in serdev_controller_alloc()
502 ctrl->dev.type = &serdev_ctrl_type; in serdev_controller_alloc()
503 ctrl->dev.bus = &serdev_bus_type; in serdev_controller_alloc()
504 ctrl->dev.parent = parent; in serdev_controller_alloc()
505 ctrl->host = host; in serdev_controller_alloc()
506 device_set_node(&ctrl->dev, dev_fwnode(host)); in serdev_controller_alloc()
509 dev_set_name(&ctrl->dev, "serial%d", id); in serdev_controller_alloc()
511 pm_runtime_no_callbacks(&ctrl->dev); in serdev_controller_alloc()
512 pm_suspend_ignore_children(&ctrl->dev, true); in serdev_controller_alloc()
514 dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); in serdev_controller_alloc()
531 for_each_available_child_of_node(ctrl->dev.of_node, node) { in of_serdev_register_devices()
535 dev_dbg(&ctrl->dev, "adding child %pOF\n", node); in of_serdev_register_devices()
541 device_set_node(&serdev->dev, of_fwnode_handle(node)); in of_serdev_register_devices()
545 dev_err(&serdev->dev, in of_serdev_register_devices()
553 return -ENODEV; in of_serdev_register_devices()
570 * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches
584 if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) in serdev_acpi_get_uart_resource()
587 sb = &ares->data.uart_serial_bus; in serdev_acpi_get_uart_resource()
588 if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART) in serdev_acpi_get_uart_resource()
605 if (lookup->index != -1 && lookup->n++ != lookup->index) in acpi_serdev_parse_resource()
608 status = acpi_get_handle(lookup->device_handle, in acpi_serdev_parse_resource()
609 sb->resource_source.string_ptr, in acpi_serdev_parse_resource()
610 &lookup->controller_handle); in acpi_serdev_parse_resource()
628 lookup->device_handle = acpi_device_handle(adev); in acpi_serdev_do_lookup()
629 lookup->controller_handle = NULL; in acpi_serdev_do_lookup()
630 lookup->n = 0; in acpi_serdev_do_lookup()
638 return -EINVAL; in acpi_serdev_do_lookup()
649 if (acpi_bus_get_status(adev) || !adev->status.present) in acpi_serdev_check_resources()
650 return -EINVAL; in acpi_serdev_check_resources()
653 lookup.index = -1; // we only care for the last device in acpi_serdev_check_resources()
666 acpi_get_parent(adev->handle, &lookup.controller_handle); in acpi_serdev_check_resources()
669 if (!device_match_acpi_handle(ctrl->host, lookup.controller_handle)) in acpi_serdev_check_resources()
670 return -ENODEV; in acpi_serdev_check_resources()
683 dev_err(&ctrl->dev, "failed to allocate serdev device for %s\n", in acpi_serdev_register_device()
684 dev_name(&adev->dev)); in acpi_serdev_register_device()
688 ACPI_COMPANION_SET(&serdev->dev, adev); in acpi_serdev_register_device()
693 dev_err(&serdev->dev, in acpi_serdev_register_device()
734 if (!has_acpi_companion(ctrl->host)) in acpi_serdev_register_devices()
735 return -ENODEV; in acpi_serdev_register_devices()
743 ret = acpi_quirk_skip_serdev_enumeration(ctrl->host, &skip); in acpi_serdev_register_devices()
753 dev_warn(&ctrl->dev, "failed to enumerate serdev slaves\n"); in acpi_serdev_register_devices()
755 if (!ctrl->serdev) in acpi_serdev_register_devices()
756 return -ENODEV; in acpi_serdev_register_devices()
763 return -ENODEV; in acpi_serdev_register_devices()
768 * serdev_controller_add() - Add an serdev controller
780 return -EAGAIN; in serdev_controller_add()
782 ret = device_add(&ctrl->dev); in serdev_controller_add()
786 pm_runtime_enable(&ctrl->dev); in serdev_controller_add()
791 dev_dbg(&ctrl->dev, "no devices registered: of:%pe acpi:%pe\n", in serdev_controller_add()
793 ret = -ENODEV; in serdev_controller_add()
797 dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", in serdev_controller_add()
798 ctrl->nr, &ctrl->dev); in serdev_controller_add()
802 pm_runtime_disable(&ctrl->dev); in serdev_controller_add()
803 device_del(&ctrl->dev); in serdev_controller_add()
812 if (dev->type == &serdev_device_type) in serdev_remove_device()
829 device_for_each_child(&ctrl->dev, NULL, serdev_remove_device); in serdev_controller_remove()
830 pm_runtime_disable(&ctrl->dev); in serdev_controller_remove()
831 device_del(&ctrl->dev); in serdev_controller_remove()
836 * __serdev_device_driver_register() - Register client driver with serdev core
837 * @sdrv: client driver to be associated with client-device.
841 * It is typically called from the driver's module-init function.
845 sdrv->driver.bus = &serdev_bus_type; in __serdev_device_driver_register()
846 sdrv->driver.owner = owner; in __serdev_device_driver_register()
849 sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS; in __serdev_device_driver_register()
851 return driver_register(&sdrv->driver); in __serdev_device_driver_register()