1 /*
2  * Copyright (c) 2021, Thomas Stranger
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This is not a real serial driver. It is used to instantiate struct
9  * devices for the "vnd,serial" devicetree compatible used in test code.
10  */
11 
12 #include <zephyr.h>
13 #include <drivers/uart.h>
14 
15 #define DT_DRV_COMPAT vnd_serial
16 
serial_vnd_poll_in(const struct device * dev,unsigned char * c)17 static int serial_vnd_poll_in(const struct device *dev, unsigned char *c)
18 {
19 	return -ENOTSUP;
20 }
21 
serial_vnd_poll_out(const struct device * dev,unsigned char c)22 static void serial_vnd_poll_out(const struct device *dev, unsigned char c)
23 {
24 }
25 
serial_vnd_err_check(const struct device * dev)26 static int serial_vnd_err_check(const struct device *dev)
27 {
28 	return -ENOTSUP;
29 }
30 
31 #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
serial_vnd_configure(const struct device * dev,const struct uart_config * cfg)32 static int serial_vnd_configure(const struct device *dev,
33 				const struct uart_config *cfg)
34 {
35 	return -ENOTSUP;
36 }
37 
serial_vnd_config_get(const struct device * dev,struct uart_config * cfg)38 static int serial_vnd_config_get(const struct device *dev,
39 				 struct uart_config *cfg)
40 {
41 	return -ENOTSUP;
42 }
43 #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
44 
45 
46 static const struct uart_driver_api serial_vnd_api = {
47 	.poll_in = serial_vnd_poll_in,
48 	.poll_out = serial_vnd_poll_out,
49 	.err_check = serial_vnd_err_check,
50 #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
51 	.configure = serial_vnd_configure,
52 	.config_get = serial_vnd_config_get,
53 #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
54 };
55 
serial_vnd_init(const struct device * dev)56 static int serial_vnd_init(const struct device *dev)
57 {
58 	return 0;
59 }
60 
61 #define VND_SERIAL_INIT(n)						\
62 	DEVICE_DT_INST_DEFINE(n, &serial_vnd_init, NULL,		\
63 			      NULL, NULL, POST_KERNEL,			\
64 			      CONFIG_SERIAL_INIT_PRIORITY,		\
65 			      &serial_vnd_api);
66 
67 DT_INST_FOREACH_STATUS_OKAY(VND_SERIAL_INIT)
68