Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serdev: Introduce new bus for serial attached devices

The serdev bus is designed for devices such as Bluetooth, WiFi, GPS
and NFC connected to UARTs on host processors. Tradionally these have
been handled with tty line disciplines, rfkill, and userspace glue such
as hciattach. This approach has many drawbacks since it doesn't fit
into the Linux driver model. Handling of sideband signals, power control
and firmware loading are the main issues.

This creates a serdev bus with controllers (i.e. host serial ports) and
attached devices. Typically, these are point to point connections, but
some devices have muxing protocols or a h/w mux is conceivable. Any
muxing is not yet supported with the serdev bus.

Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-By: Sebastian Reichel <sre@kernel.org>
Tested-By: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rob Herring and committed by
Greg Kroah-Hartman
cd6484e1 c1c98dad

+683
+8
MAINTAINERS
··· 10831 10831 F: Documentation/devicetree/bindings/serial/ 10832 10832 F: drivers/tty/serial/ 10833 10833 10834 + SERIAL DEVICE BUS 10835 + M: Rob Herring <robh@kernel.org> 10836 + L: linux-serial@vger.kernel.org 10837 + S: Maintained 10838 + F: Documentation/devicetree/bindings/serial/slave-device.txt 10839 + F: drivers/tty/serdev/ 10840 + F: include/linux/serdev.h 10841 + 10834 10842 SERIAL IR RECEIVER 10835 10843 M: Sean Young <sean@mess.org> 10836 10844 L: linux-media@vger.kernel.org
+1
drivers/char/Kconfig
··· 46 46 say Y or M here, otherwise say N. 47 47 48 48 source "drivers/tty/serial/Kconfig" 49 + source "drivers/tty/serdev/Kconfig" 49 50 50 51 config TTY_PRINTK 51 52 tristate "TTY driver to output user messages via printk"
+1
drivers/tty/Makefile
··· 13 13 obj-y += vt/ 14 14 obj-$(CONFIG_HVC_DRIVER) += hvc/ 15 15 obj-y += serial/ 16 + obj-$(CONFIG_SERIAL_DEV_BUS) += serdev/ 16 17 17 18 # tty drivers 18 19 obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
+8
drivers/tty/serdev/Kconfig
··· 1 + # 2 + # Serial bus device driver configuration 3 + # 4 + menuconfig SERIAL_DEV_BUS 5 + tristate "Serial device bus" 6 + help 7 + Core support for devices connected via a serial port. 8 +
+3
drivers/tty/serdev/Makefile
··· 1 + serdev-objs := core.o 2 + 3 + obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o
+421
drivers/tty/serdev/core.c
··· 1 + /* 2 + * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org> 3 + * 4 + * Based on drivers/spmi/spmi.c: 5 + * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 and 9 + * only version 2 as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/errno.h> 18 + #include <linux/idr.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/of_device.h> 23 + #include <linux/serdev.h> 24 + #include <linux/slab.h> 25 + 26 + static bool is_registered; 27 + static DEFINE_IDA(ctrl_ida); 28 + 29 + static void serdev_device_release(struct device *dev) 30 + { 31 + struct serdev_device *serdev = to_serdev_device(dev); 32 + kfree(serdev); 33 + } 34 + 35 + static const struct device_type serdev_device_type = { 36 + .release = serdev_device_release, 37 + }; 38 + 39 + static void serdev_ctrl_release(struct device *dev) 40 + { 41 + struct serdev_controller *ctrl = to_serdev_controller(dev); 42 + ida_simple_remove(&ctrl_ida, ctrl->nr); 43 + kfree(ctrl); 44 + } 45 + 46 + static const struct device_type serdev_ctrl_type = { 47 + .release = serdev_ctrl_release, 48 + }; 49 + 50 + static int serdev_device_match(struct device *dev, struct device_driver *drv) 51 + { 52 + /* TODO: ACPI and platform matching */ 53 + return of_driver_match_device(dev, drv); 54 + } 55 + 56 + static int serdev_uevent(struct device *dev, struct kobj_uevent_env *env) 57 + { 58 + /* TODO: ACPI and platform modalias */ 59 + return of_device_uevent_modalias(dev, env); 60 + } 61 + 62 + /** 63 + * serdev_device_add() - add a device previously constructed via serdev_device_alloc() 64 + * @serdev: serdev_device to be added 65 + */ 66 + int serdev_device_add(struct serdev_device *serdev) 67 + { 68 + struct device *parent = serdev->dev.parent; 69 + int err; 70 + 71 + dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr); 72 + 73 + err = device_add(&serdev->dev); 74 + if (err < 0) { 75 + dev_err(&serdev->dev, "Can't add %s, status %d\n", 76 + dev_name(&serdev->dev), err); 77 + goto err_device_add; 78 + } 79 + 80 + dev_dbg(&serdev->dev, "device %s registered\n", dev_name(&serdev->dev)); 81 + 82 + err_device_add: 83 + return err; 84 + } 85 + EXPORT_SYMBOL_GPL(serdev_device_add); 86 + 87 + /** 88 + * serdev_device_remove(): remove an serdev device 89 + * @serdev: serdev_device to be removed 90 + */ 91 + void serdev_device_remove(struct serdev_device *serdev) 92 + { 93 + device_unregister(&serdev->dev); 94 + } 95 + EXPORT_SYMBOL_GPL(serdev_device_remove); 96 + 97 + int serdev_device_open(struct serdev_device *serdev) 98 + { 99 + struct serdev_controller *ctrl = serdev->ctrl; 100 + 101 + if (!ctrl || !ctrl->ops->open) 102 + return -EINVAL; 103 + 104 + return ctrl->ops->open(ctrl); 105 + } 106 + EXPORT_SYMBOL_GPL(serdev_device_open); 107 + 108 + void serdev_device_close(struct serdev_device *serdev) 109 + { 110 + struct serdev_controller *ctrl = serdev->ctrl; 111 + 112 + if (!ctrl || !ctrl->ops->close) 113 + return; 114 + 115 + ctrl->ops->close(ctrl); 116 + } 117 + EXPORT_SYMBOL_GPL(serdev_device_close); 118 + 119 + int serdev_device_write_buf(struct serdev_device *serdev, 120 + const unsigned char *buf, size_t count) 121 + { 122 + struct serdev_controller *ctrl = serdev->ctrl; 123 + 124 + if (!ctrl || !ctrl->ops->write_buf) 125 + return -EINVAL; 126 + 127 + return ctrl->ops->write_buf(ctrl, buf, count); 128 + } 129 + EXPORT_SYMBOL_GPL(serdev_device_write_buf); 130 + 131 + void serdev_device_write_flush(struct serdev_device *serdev) 132 + { 133 + struct serdev_controller *ctrl = serdev->ctrl; 134 + 135 + if (!ctrl || !ctrl->ops->write_flush) 136 + return; 137 + 138 + ctrl->ops->write_flush(ctrl); 139 + } 140 + EXPORT_SYMBOL_GPL(serdev_device_write_flush); 141 + 142 + int serdev_device_write_room(struct serdev_device *serdev) 143 + { 144 + struct serdev_controller *ctrl = serdev->ctrl; 145 + 146 + if (!ctrl || !ctrl->ops->write_room) 147 + return 0; 148 + 149 + return serdev->ctrl->ops->write_room(ctrl); 150 + } 151 + EXPORT_SYMBOL_GPL(serdev_device_write_room); 152 + 153 + unsigned int serdev_device_set_baudrate(struct serdev_device *serdev, unsigned int speed) 154 + { 155 + struct serdev_controller *ctrl = serdev->ctrl; 156 + 157 + if (!ctrl || !ctrl->ops->set_baudrate) 158 + return 0; 159 + 160 + return ctrl->ops->set_baudrate(ctrl, speed); 161 + 162 + } 163 + EXPORT_SYMBOL_GPL(serdev_device_set_baudrate); 164 + 165 + void serdev_device_set_flow_control(struct serdev_device *serdev, bool enable) 166 + { 167 + struct serdev_controller *ctrl = serdev->ctrl; 168 + 169 + if (!ctrl || !ctrl->ops->set_flow_control) 170 + return; 171 + 172 + ctrl->ops->set_flow_control(ctrl, enable); 173 + } 174 + EXPORT_SYMBOL_GPL(serdev_device_set_flow_control); 175 + 176 + static int serdev_drv_probe(struct device *dev) 177 + { 178 + const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); 179 + 180 + return sdrv->probe(to_serdev_device(dev)); 181 + } 182 + 183 + static int serdev_drv_remove(struct device *dev) 184 + { 185 + const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); 186 + 187 + sdrv->remove(to_serdev_device(dev)); 188 + return 0; 189 + } 190 + 191 + static ssize_t modalias_show(struct device *dev, 192 + struct device_attribute *attr, char *buf) 193 + { 194 + ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2); 195 + buf[len] = '\n'; 196 + buf[len+1] = 0; 197 + return len+1; 198 + } 199 + 200 + static struct device_attribute serdev_device_attrs[] = { 201 + __ATTR_RO(modalias), 202 + __ATTR_NULL 203 + }; 204 + 205 + static struct bus_type serdev_bus_type = { 206 + .name = "serial", 207 + .match = serdev_device_match, 208 + .probe = serdev_drv_probe, 209 + .remove = serdev_drv_remove, 210 + .uevent = serdev_uevent, 211 + .dev_attrs = serdev_device_attrs, 212 + }; 213 + 214 + /** 215 + * serdev_controller_alloc() - Allocate a new serdev device 216 + * @ctrl: associated controller 217 + * 218 + * Caller is responsible for either calling serdev_device_add() to add the 219 + * newly allocated controller, or calling serdev_device_put() to discard it. 220 + */ 221 + struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl) 222 + { 223 + struct serdev_device *serdev; 224 + 225 + serdev = kzalloc(sizeof(*serdev), GFP_KERNEL); 226 + if (!serdev) 227 + return NULL; 228 + 229 + serdev->ctrl = ctrl; 230 + ctrl->serdev = serdev; 231 + device_initialize(&serdev->dev); 232 + serdev->dev.parent = &ctrl->dev; 233 + serdev->dev.bus = &serdev_bus_type; 234 + serdev->dev.type = &serdev_device_type; 235 + return serdev; 236 + } 237 + EXPORT_SYMBOL_GPL(serdev_device_alloc); 238 + 239 + /** 240 + * serdev_controller_alloc() - Allocate a new serdev controller 241 + * @parent: parent device 242 + * @size: size of private data 243 + * 244 + * Caller is responsible for either calling serdev_controller_add() to add the 245 + * newly allocated controller, or calling serdev_controller_put() to discard it. 246 + * The allocated private data region may be accessed via 247 + * serdev_controller_get_drvdata() 248 + */ 249 + struct serdev_controller *serdev_controller_alloc(struct device *parent, 250 + size_t size) 251 + { 252 + struct serdev_controller *ctrl; 253 + int id; 254 + 255 + if (WARN_ON(!parent)) 256 + return NULL; 257 + 258 + ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); 259 + if (!ctrl) 260 + return NULL; 261 + 262 + device_initialize(&ctrl->dev); 263 + ctrl->dev.type = &serdev_ctrl_type; 264 + ctrl->dev.bus = &serdev_bus_type; 265 + ctrl->dev.parent = parent; 266 + ctrl->dev.of_node = parent->of_node; 267 + serdev_controller_set_drvdata(ctrl, &ctrl[1]); 268 + 269 + id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL); 270 + if (id < 0) { 271 + dev_err(parent, 272 + "unable to allocate serdev controller identifier.\n"); 273 + serdev_controller_put(ctrl); 274 + return NULL; 275 + } 276 + 277 + ctrl->nr = id; 278 + dev_set_name(&ctrl->dev, "serial%d", id); 279 + 280 + dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); 281 + return ctrl; 282 + } 283 + EXPORT_SYMBOL_GPL(serdev_controller_alloc); 284 + 285 + static int of_serdev_register_devices(struct serdev_controller *ctrl) 286 + { 287 + struct device_node *node; 288 + struct serdev_device *serdev = NULL; 289 + int err; 290 + bool found = false; 291 + 292 + for_each_available_child_of_node(ctrl->dev.of_node, node) { 293 + if (!of_get_property(node, "compatible", NULL)) 294 + continue; 295 + 296 + dev_dbg(&ctrl->dev, "adding child %s\n", node->full_name); 297 + 298 + serdev = serdev_device_alloc(ctrl); 299 + if (!serdev) 300 + continue; 301 + 302 + serdev->dev.of_node = node; 303 + 304 + err = serdev_device_add(serdev); 305 + if (err) { 306 + dev_err(&serdev->dev, 307 + "failure adding device. status %d\n", err); 308 + serdev_device_put(serdev); 309 + } else 310 + found = true; 311 + } 312 + if (!found) 313 + return -ENODEV; 314 + 315 + return 0; 316 + } 317 + 318 + /** 319 + * serdev_controller_add() - Add an serdev controller 320 + * @ctrl: controller to be registered. 321 + * 322 + * Register a controller previously allocated via serdev_controller_alloc() with 323 + * the serdev core. 324 + */ 325 + int serdev_controller_add(struct serdev_controller *ctrl) 326 + { 327 + int ret; 328 + 329 + /* Can't register until after driver model init */ 330 + if (WARN_ON(!is_registered)) 331 + return -EAGAIN; 332 + 333 + ret = device_add(&ctrl->dev); 334 + if (ret) 335 + return ret; 336 + 337 + ret = of_serdev_register_devices(ctrl); 338 + if (ret) 339 + goto out_dev_del; 340 + 341 + dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n", 342 + ctrl->nr, &ctrl->dev); 343 + return 0; 344 + 345 + out_dev_del: 346 + device_del(&ctrl->dev); 347 + return ret; 348 + }; 349 + EXPORT_SYMBOL_GPL(serdev_controller_add); 350 + 351 + /* Remove a device associated with a controller */ 352 + static int serdev_remove_device(struct device *dev, void *data) 353 + { 354 + struct serdev_device *serdev = to_serdev_device(dev); 355 + if (dev->type == &serdev_device_type) 356 + serdev_device_remove(serdev); 357 + return 0; 358 + } 359 + 360 + /** 361 + * serdev_controller_remove(): remove an serdev controller 362 + * @ctrl: controller to remove 363 + * 364 + * Remove a serdev controller. Caller is responsible for calling 365 + * serdev_controller_put() to discard the allocated controller. 366 + */ 367 + void serdev_controller_remove(struct serdev_controller *ctrl) 368 + { 369 + int dummy; 370 + 371 + if (!ctrl) 372 + return; 373 + 374 + dummy = device_for_each_child(&ctrl->dev, NULL, 375 + serdev_remove_device); 376 + device_del(&ctrl->dev); 377 + } 378 + EXPORT_SYMBOL_GPL(serdev_controller_remove); 379 + 380 + /** 381 + * serdev_driver_register() - Register client driver with serdev core 382 + * @sdrv: client driver to be associated with client-device. 383 + * 384 + * This API will register the client driver with the serdev framework. 385 + * It is typically called from the driver's module-init function. 386 + */ 387 + int __serdev_device_driver_register(struct serdev_device_driver *sdrv, struct module *owner) 388 + { 389 + sdrv->driver.bus = &serdev_bus_type; 390 + sdrv->driver.owner = owner; 391 + 392 + /* force drivers to async probe so I/O is possible in probe */ 393 + sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS; 394 + 395 + return driver_register(&sdrv->driver); 396 + } 397 + EXPORT_SYMBOL_GPL(__serdev_device_driver_register); 398 + 399 + static void __exit serdev_exit(void) 400 + { 401 + bus_unregister(&serdev_bus_type); 402 + } 403 + module_exit(serdev_exit); 404 + 405 + static int __init serdev_init(void) 406 + { 407 + int ret; 408 + 409 + ret = bus_register(&serdev_bus_type); 410 + if (ret) 411 + return ret; 412 + 413 + is_registered = true; 414 + return 0; 415 + } 416 + /* Must be before serial drivers register */ 417 + postcore_initcall(serdev_init); 418 + 419 + MODULE_AUTHOR("Rob Herring <robh@kernel.org>"); 420 + MODULE_LICENSE("GPL v2"); 421 + MODULE_DESCRIPTION("Serial attached device bus");
+241
include/linux/serdev.h
··· 1 + /* 2 + * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 and 6 + * only version 2 as published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + #ifndef _LINUX_SERDEV_H 14 + #define _LINUX_SERDEV_H 15 + 16 + #include <linux/types.h> 17 + #include <linux/device.h> 18 + 19 + struct serdev_controller; 20 + struct serdev_device; 21 + 22 + /* 23 + * serdev device structures 24 + */ 25 + 26 + /** 27 + * struct serdev_device_ops - Callback operations for a serdev device 28 + * @receive_buf: Function called with data received from device. 29 + * @write_wakeup: Function called when ready to transmit more data. 30 + */ 31 + struct serdev_device_ops { 32 + int (*receive_buf)(struct serdev_device *, const unsigned char *, size_t); 33 + void (*write_wakeup)(struct serdev_device *); 34 + }; 35 + 36 + /** 37 + * struct serdev_device - Basic representation of an serdev device 38 + * @dev: Driver model representation of the device. 39 + * @nr: Device number on serdev bus. 40 + * @ctrl: serdev controller managing this device. 41 + * @ops: Device operations. 42 + */ 43 + struct serdev_device { 44 + struct device dev; 45 + int nr; 46 + struct serdev_controller *ctrl; 47 + const struct serdev_device_ops *ops; 48 + }; 49 + 50 + static inline struct serdev_device *to_serdev_device(struct device *d) 51 + { 52 + return container_of(d, struct serdev_device, dev); 53 + } 54 + 55 + /** 56 + * struct serdev_device_driver - serdev slave device driver 57 + * @driver: serdev device drivers should initialize name field of this 58 + * structure. 59 + * @probe: binds this driver to a serdev device. 60 + * @remove: unbinds this driver from the serdev device. 61 + */ 62 + struct serdev_device_driver { 63 + struct device_driver driver; 64 + int (*probe)(struct serdev_device *); 65 + void (*remove)(struct serdev_device *); 66 + }; 67 + 68 + static inline struct serdev_device_driver *to_serdev_device_driver(struct device_driver *d) 69 + { 70 + return container_of(d, struct serdev_device_driver, driver); 71 + } 72 + 73 + /* 74 + * serdev controller structures 75 + */ 76 + struct serdev_controller_ops { 77 + int (*write_buf)(struct serdev_controller *, const unsigned char *, size_t); 78 + void (*write_flush)(struct serdev_controller *); 79 + int (*write_room)(struct serdev_controller *); 80 + int (*open)(struct serdev_controller *); 81 + void (*close)(struct serdev_controller *); 82 + void (*set_flow_control)(struct serdev_controller *, bool); 83 + unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int); 84 + }; 85 + 86 + /** 87 + * struct serdev_controller - interface to the serdev controller 88 + * @dev: Driver model representation of the device. 89 + * @nr: number identifier for this controller/bus. 90 + * @serdev: Pointer to slave device for this controller. 91 + * @ops: Controller operations. 92 + */ 93 + struct serdev_controller { 94 + struct device dev; 95 + unsigned int nr; 96 + struct serdev_device *serdev; 97 + const struct serdev_controller_ops *ops; 98 + }; 99 + 100 + static inline struct serdev_controller *to_serdev_controller(struct device *d) 101 + { 102 + return container_of(d, struct serdev_controller, dev); 103 + } 104 + 105 + static inline void *serdev_device_get_drvdata(const struct serdev_device *serdev) 106 + { 107 + return dev_get_drvdata(&serdev->dev); 108 + } 109 + 110 + static inline void serdev_device_set_drvdata(struct serdev_device *serdev, void *data) 111 + { 112 + dev_set_drvdata(&serdev->dev, data); 113 + } 114 + 115 + /** 116 + * serdev_device_put() - decrement serdev device refcount 117 + * @serdev serdev device. 118 + */ 119 + static inline void serdev_device_put(struct serdev_device *serdev) 120 + { 121 + if (serdev) 122 + put_device(&serdev->dev); 123 + } 124 + 125 + static inline void serdev_device_set_client_ops(struct serdev_device *serdev, 126 + const struct serdev_device_ops *ops) 127 + { 128 + serdev->ops = ops; 129 + } 130 + 131 + static inline 132 + void *serdev_controller_get_drvdata(const struct serdev_controller *ctrl) 133 + { 134 + return ctrl ? dev_get_drvdata(&ctrl->dev) : NULL; 135 + } 136 + 137 + static inline void serdev_controller_set_drvdata(struct serdev_controller *ctrl, 138 + void *data) 139 + { 140 + dev_set_drvdata(&ctrl->dev, data); 141 + } 142 + 143 + /** 144 + * serdev_controller_put() - decrement controller refcount 145 + * @ctrl serdev controller. 146 + */ 147 + static inline void serdev_controller_put(struct serdev_controller *ctrl) 148 + { 149 + if (ctrl) 150 + put_device(&ctrl->dev); 151 + } 152 + 153 + struct serdev_device *serdev_device_alloc(struct serdev_controller *); 154 + int serdev_device_add(struct serdev_device *); 155 + void serdev_device_remove(struct serdev_device *); 156 + 157 + struct serdev_controller *serdev_controller_alloc(struct device *, size_t); 158 + int serdev_controller_add(struct serdev_controller *); 159 + void serdev_controller_remove(struct serdev_controller *); 160 + 161 + static inline void serdev_controller_write_wakeup(struct serdev_controller *ctrl) 162 + { 163 + struct serdev_device *serdev = ctrl->serdev; 164 + 165 + if (!serdev || !serdev->ops->write_wakeup) 166 + return; 167 + 168 + serdev->ops->write_wakeup(ctrl->serdev); 169 + } 170 + 171 + static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl, 172 + const unsigned char *data, 173 + size_t count) 174 + { 175 + struct serdev_device *serdev = ctrl->serdev; 176 + 177 + if (!serdev || !serdev->ops->receive_buf) 178 + return -EINVAL; 179 + 180 + return serdev->ops->receive_buf(ctrl->serdev, data, count); 181 + } 182 + 183 + #if IS_ENABLED(CONFIG_SERIAL_DEV_BUS) 184 + 185 + int serdev_device_open(struct serdev_device *); 186 + void serdev_device_close(struct serdev_device *); 187 + unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int); 188 + void serdev_device_set_flow_control(struct serdev_device *, bool); 189 + int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t); 190 + void serdev_device_write_flush(struct serdev_device *); 191 + int serdev_device_write_room(struct serdev_device *); 192 + 193 + /* 194 + * serdev device driver functions 195 + */ 196 + int __serdev_device_driver_register(struct serdev_device_driver *, struct module *); 197 + #define serdev_device_driver_register(sdrv) \ 198 + __serdev_device_driver_register(sdrv, THIS_MODULE) 199 + 200 + /** 201 + * serdev_device_driver_unregister() - unregister an serdev client driver 202 + * @sdrv: the driver to unregister 203 + */ 204 + static inline void serdev_device_driver_unregister(struct serdev_device_driver *sdrv) 205 + { 206 + if (sdrv) 207 + driver_unregister(&sdrv->driver); 208 + } 209 + 210 + #define module_serdev_device_driver(__serdev_device_driver) \ 211 + module_driver(__serdev_device_driver, serdev_device_driver_register, \ 212 + serdev_device_driver_unregister) 213 + 214 + #else 215 + 216 + static inline int serdev_device_open(struct serdev_device *sdev) 217 + { 218 + return -ENODEV; 219 + } 220 + static inline void serdev_device_close(struct serdev_device *sdev) {} 221 + static inline unsigned int serdev_device_set_baudrate(struct serdev_device *sdev, unsigned int baudrate) 222 + { 223 + return 0; 224 + } 225 + static inline void serdev_device_set_flow_control(struct serdev_device *sdev, bool enable) {} 226 + static inline int serdev_device_write_buf(struct serdev_device *sdev, const unsigned char *buf, size_t count) 227 + { 228 + return -ENODEV; 229 + } 230 + static inline void serdev_device_write_flush(struct serdev_device *sdev) {} 231 + static inline int serdev_device_write_room(struct serdev_device *sdev) 232 + { 233 + return 0; 234 + } 235 + 236 + #define serdev_device_driver_register(x) 237 + #define serdev_device_driver_unregister(x) 238 + 239 + #endif /* CONFIG_SERIAL_DEV_BUS */ 240 + 241 + #endif /*_LINUX_SERDEV_H */