1 /*
2 * Copyright (c) 2013 Corey Tabaka
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8
9 #include <lk/err.h>
10 #include <dev/class/uart.h>
11
class_uart_read(struct device * dev,void * buf,size_t len)12 ssize_t class_uart_read(struct device *dev, void *buf, size_t len) {
13 struct uart_ops *ops = device_get_driver_ops(dev, struct uart_ops, std);
14
15 if (!ops)
16 return ERR_NOT_CONFIGURED;
17
18 if (ops->read)
19 return ops->read(dev, buf, len);
20 else
21 return ERR_NOT_SUPPORTED;
22 }
23
class_uart_write(struct device * dev,const void * buf,size_t len)24 ssize_t class_uart_write(struct device *dev, const void *buf, size_t len) {
25 struct uart_ops *ops = device_get_driver_ops(dev, struct uart_ops, std);
26
27 if (!ops)
28 return ERR_NOT_CONFIGURED;
29
30 if (ops->write)
31 return ops->write(dev, buf, len);
32 else
33 return ERR_NOT_SUPPORTED;
34 }
35
36