diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/console.h | 27 | ||||
-rw-r--r-- | include/serdev.h | 36 |
2 files changed, 63 insertions, 0 deletions
diff --git a/include/console.h b/include/console.h index da867e70a6..673921331d 100644 --- a/include/console.h +++ b/include/console.h @@ -23,6 +23,7 @@ #include <param.h> #include <linux/list.h> #include <driver.h> +#include <serdev.h> #include <clock.h> #include <kfifo.h> @@ -66,8 +67,34 @@ struct console_device { struct cdev devfs; struct cdev_operations fops; + + struct serdev_device serdev; }; +static inline struct serdev_device *to_serdev_device(struct device_d *d) +{ + struct console_device *cdev = + container_of(d, struct console_device, class_dev); + return &cdev->serdev; +} + +static inline struct console_device * +to_console_device(struct serdev_device *serdev) +{ + return container_of(serdev, struct console_device, serdev); +} + +static inline struct device_node * +console_is_serdev_node(struct console_device *cdev) +{ + struct device_d *dev = cdev->dev; + if (dev && dev->device_node && + of_get_child_count(dev->device_node)) + return dev->device_node; + + return NULL; +} + int console_register(struct console_device *cdev); int console_unregister(struct console_device *cdev); diff --git a/include/serdev.h b/include/serdev.h new file mode 100644 index 0000000000..efc735fedf --- /dev/null +++ b/include/serdev.h @@ -0,0 +1,36 @@ +#ifndef _SERDEV_H_ +#define _SERDEV_H_ + +#include <driver.h> +#include <poller.h> +#include <kfifo.h> + +/** + * struct serdev_device - Basic representation of an serdev device + * + * @dev: Corresponding device + * @fifo: Circular buffer used for console draining + * @buf: Buffer used to pass Rx data to consumers + * @poller Async poller used to poll this serdev + * @polling_interval: Async poller periodicity + * @polling_window: Duration of a single busy loop poll + * @receive_buf: Function called with data received from device; + * returns number of bytes accepted; + */ +struct serdev_device { + struct device_d *dev; + struct kfifo *fifo; + unsigned char *buf; + struct poller_async poller; + uint64_t polling_interval; + uint64_t polling_window; + + int (*receive_buf)(struct serdev_device *, const unsigned char *, + size_t); +}; + +int serdev_device_open(struct serdev_device *); +unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int); +int serdev_device_write(struct serdev_device *, const unsigned char *, + size_t, unsigned long); +#endif |