blob: 0685cdcb510d300c707abebcf03598d7f04a0d1f [file] [log] [blame]
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +08001/*
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +08002 * UART driver for the Greybus "generic" UART module.
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +08003 *
4 * Copyright 2014 Google Inc.
Alex Eldera46e9672014-12-12 12:08:42 -06005 * Copyright 2014 Linaro Ltd.
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +08006 *
7 * Released under the GPLv2 only.
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +08008 *
9 * Heavily based on drivers/usb/class/cdc-acm.c and
10 * drivers/usb/serial/usb-serial.c.
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080011 */
Greg Kroah-Hartman168db1c2014-09-13 16:15:52 -070012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080013
14#include <linux/kernel.h>
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080015#include <linux/errno.h>
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080016#include <linux/module.h>
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080017#include <linux/sched.h>
18#include <linux/wait.h>
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080019#include <linux/slab.h>
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080020#include <linux/uaccess.h>
21#include <linux/mutex.h>
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080022#include <linux/tty.h>
23#include <linux/serial.h>
24#include <linux/tty_driver.h>
25#include <linux/tty_flip.h>
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080026#include <linux/serial.h>
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +080027#include <linux/idr.h>
Marti Bolivar7fabc882014-09-05 23:56:10 -040028#include <linux/fs.h>
29#include <linux/kdev_t.h>
Alex Eldere1e9dbd2014-10-01 21:54:11 -050030
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080031#include "greybus.h"
32
Bryan O'Donoghuef5537d42015-06-02 13:40:46 +010033#define GB_NUM_MINORS 16 /* 16 is is more than enough */
Marti Bolivar7fabc882014-09-05 23:56:10 -040034#define GB_NAME "ttyGB"
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080035
Bryan O'Donoghue11fca142015-06-02 13:40:45 +010036struct gb_tty_line_coding {
37 __le32 rate;
38 __u8 format;
39 __u8 parity;
40 __u8 data_bits;
41};
42
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080043struct gb_tty {
44 struct tty_port port;
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +010045 void *buffer;
Greg Kroah-Hartman7f29ade2016-02-22 18:14:46 -080046 size_t buffer_payload_max;
Greg Kroah-Hartmanaed0bc62014-10-27 17:32:34 +080047 struct gb_connection *connection;
Alex Elder1cfc6672014-09-30 19:25:21 -050048 u16 cport_id;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080049 unsigned int minor;
50 unsigned char clocal;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080051 bool disconnected;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +080052 spinlock_t read_lock;
53 spinlock_t write_lock;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +080054 struct async_icount iocount;
55 struct async_icount oldcount;
56 wait_queue_head_t wioctl;
57 struct mutex mutex;
Bryan O'Donoghueba4b0992015-06-29 18:09:15 +010058 u8 ctrlin; /* input control lines */
59 u8 ctrlout; /* output control lines */
Bryan O'Donoghue11fca142015-06-02 13:40:45 +010060 struct gb_tty_line_coding line_coding;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +080061};
62
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +080063static struct tty_driver *gb_tty_driver;
64static DEFINE_IDR(tty_minors);
65static DEFINE_MUTEX(table_lock);
Greg Kroah-Hartman4d980982014-10-27 17:42:45 +080066static atomic_t reference_count = ATOMIC_INIT(0);
67
Johan Hovoldc5f338c2016-02-24 16:11:51 +010068static int gb_uart_receive_data_handler(struct gb_operation *op)
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +010069{
Johan Hovoldc5f338c2016-02-24 16:11:51 +010070 struct gb_connection *connection = op->connection;
71 struct gb_tty *gb_tty = connection->private;
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +010072 struct tty_port *port = &gb_tty->port;
Johan Hovoldc5f338c2016-02-24 16:11:51 +010073 struct gb_message *request = op->request;
74 struct gb_uart_recv_data_request *receive_data;
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +010075 u16 recv_data_size;
76 int count;
77 unsigned long tty_flags = TTY_NORMAL;
78
Johan Hovoldc5f338c2016-02-24 16:11:51 +010079 if (request->payload_size < sizeof(*receive_data)) {
80 dev_err(&connection->bundle->dev,
81 "short receive-data request received (%zu < %zu)\n",
82 request->payload_size, sizeof(*receive_data));
83 return -EINVAL;
84 }
85
86 receive_data = op->request->payload;
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +010087 recv_data_size = le16_to_cpu(receive_data->size);
Johan Hovoldc5f338c2016-02-24 16:11:51 +010088
89 if (recv_data_size != request->payload_size - sizeof(*receive_data)) {
90 dev_err(&connection->bundle->dev,
91 "malformed receive-data request received (%u != %zu)\n",
92 recv_data_size,
93 request->payload_size - sizeof(*receive_data));
94 return -EINVAL;
95 }
96
97 if (!recv_data_size)
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +010098 return -EINVAL;
99
100 if (receive_data->flags) {
101 if (receive_data->flags & GB_UART_RECV_FLAG_BREAK)
102 tty_flags = TTY_BREAK;
103 else if (receive_data->flags & GB_UART_RECV_FLAG_PARITY)
104 tty_flags = TTY_PARITY;
105 else if (receive_data->flags & GB_UART_RECV_FLAG_FRAMING)
106 tty_flags = TTY_FRAME;
107
108 /* overrun is special, not associated with a char */
109 if (receive_data->flags & GB_UART_RECV_FLAG_OVERRUN)
110 tty_insert_flip_char(port, 0, TTY_OVERRUN);
111 }
112 count = tty_insert_flip_string_fixed_flag(port, receive_data->data,
113 tty_flags, recv_data_size);
114 if (count != recv_data_size) {
Greg Kroah-Hartman4f30bf32015-10-14 11:15:12 -0700115 dev_err(&connection->bundle->dev,
Bryan O'Donoghue4c025cf2015-06-29 18:09:14 +0100116 "UART: RX 0x%08x bytes only wrote 0x%08x\n",
117 recv_data_size, count);
118 }
119 if (count)
120 tty_flip_buffer_push(port);
121 return 0;
122}
123
Johan Hovoldcb7f00b2016-02-24 16:11:50 +0100124static int gb_uart_serial_state_handler(struct gb_operation *op)
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100125{
126 struct gb_connection *connection = op->connection;
127 struct gb_tty *gb_tty = connection->private;
128 struct gb_message *request = op->request;
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100129 struct gb_uart_serial_state_request *serial_state;
Johan Hovoldcb7f00b2016-02-24 16:11:50 +0100130
131 if (request->payload_size < sizeof(*serial_state)) {
132 dev_err(&connection->bundle->dev,
133 "short serial-state event received (%zu < %zu)\n",
134 request->payload_size, sizeof(*serial_state));
135 return -EINVAL;
136 }
137
138 serial_state = request->payload;
139 gb_tty->ctrlin = serial_state->control;
140
141 return 0;
142}
143
144static int gb_uart_request_recv(u8 type, struct gb_operation *op)
145{
146 struct gb_connection *connection = op->connection;
Johan Hovoldcb7f00b2016-02-24 16:11:50 +0100147 int ret;
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100148
149 switch (type) {
150 case GB_UART_TYPE_RECEIVE_DATA:
Johan Hovoldc5f338c2016-02-24 16:11:51 +0100151 ret = gb_uart_receive_data_handler(op);
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100152 break;
153 case GB_UART_TYPE_SERIAL_STATE:
Johan Hovoldcb7f00b2016-02-24 16:11:50 +0100154 ret = gb_uart_serial_state_handler(op);
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100155 break;
156 default:
Greg Kroah-Hartman4f30bf32015-10-14 11:15:12 -0700157 dev_err(&connection->bundle->dev,
Viresh Kumarb933fa42015-12-04 21:30:10 +0530158 "unsupported unsolicited request: 0x%02x\n", type);
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100159 ret = -EINVAL;
160 }
161
162 return ret;
163}
164
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800165static int send_data(struct gb_tty *tty, u16 size, const u8 *data)
166{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800167 struct gb_uart_send_data_request *request;
Bryan O'Donoghue563bd792015-06-02 13:40:48 +0100168 int ret;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800169
170 if (!data || !size)
171 return 0;
172
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100173 if (size > tty->buffer_payload_max)
174 size = tty->buffer_payload_max;
175 request = tty->buffer;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800176 request->size = cpu_to_le16(size);
177 memcpy(&request->data[0], data, size);
Bryan O'Donoghue563bd792015-06-02 13:40:48 +0100178 ret = gb_operation_sync(tty->connection, GB_UART_TYPE_SEND_DATA,
179 request, sizeof(*request) + size, NULL, 0);
Bryan O'Donoghue563bd792015-06-02 13:40:48 +0100180 if (ret)
181 return ret;
182 else
183 return size;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800184}
185
Greg Kroah-Hartman9f240f22014-11-24 13:52:25 -0800186static int send_line_coding(struct gb_tty *tty)
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800187{
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800188 struct gb_uart_set_line_coding_request request;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800189
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100190 memcpy(&request, &tty->line_coding,
Greg Kroah-Hartman9f240f22014-11-24 13:52:25 -0800191 sizeof(tty->line_coding));
Viresh Kumar530430b2015-01-21 18:12:35 +0530192 return gb_operation_sync(tty->connection, GB_UART_TYPE_SET_LINE_CODING,
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800193 &request, sizeof(request), NULL, 0);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800194}
195
Bryan O'Donoghueba4b0992015-06-29 18:09:15 +0100196static int send_control(struct gb_tty *gb_tty, u8 control)
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800197{
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800198 struct gb_uart_set_control_line_state_request request;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800199
Bryan O'Donoghueba4b0992015-06-29 18:09:15 +0100200 request.control = control;
Bryan O'Donoghue62229a12015-06-02 13:40:51 +0100201 return gb_operation_sync(gb_tty->connection,
Viresh Kumar530430b2015-01-21 18:12:35 +0530202 GB_UART_TYPE_SET_CONTROL_LINE_STATE,
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800203 &request, sizeof(request), NULL, 0);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800204}
205
Bryan O'Donoghue62229a12015-06-02 13:40:51 +0100206static int send_break(struct gb_tty *gb_tty, u8 state)
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800207{
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800208 struct gb_uart_set_break_request request;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800209
210 if ((state != 0) && (state != 1)) {
Greg Kroah-Hartman4f30bf32015-10-14 11:15:12 -0700211 dev_err(&gb_tty->connection->bundle->dev,
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800212 "invalid break state of %d\n", state);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800213 return -EINVAL;
214 }
215
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800216 request.state = state;
Bryan O'Donoghuea5192032015-07-14 02:10:18 +0100217 return gb_operation_sync(gb_tty->connection, GB_UART_TYPE_SEND_BREAK,
Greg Kroah-Hartmane51f1d12014-11-23 17:45:21 -0800218 &request, sizeof(request), NULL, 0);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800219}
220
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800221
222static struct gb_tty *get_gb_by_minor(unsigned minor)
223{
224 struct gb_tty *gb_tty;
225
226 mutex_lock(&table_lock);
227 gb_tty = idr_find(&tty_minors, minor);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800228 if (gb_tty) {
229 mutex_lock(&gb_tty->mutex);
230 if (gb_tty->disconnected) {
231 mutex_unlock(&gb_tty->mutex);
232 gb_tty = NULL;
233 } else {
234 tty_port_get(&gb_tty->port);
235 mutex_unlock(&gb_tty->mutex);
236 }
237 }
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800238 mutex_unlock(&table_lock);
239 return gb_tty;
240}
241
242static int alloc_minor(struct gb_tty *gb_tty)
243{
244 int minor;
245
246 mutex_lock(&table_lock);
Alex Elderff5f0b32014-08-18 18:25:11 -0500247 minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800248 mutex_unlock(&table_lock);
Alex Elderff5f0b32014-08-18 18:25:11 -0500249 if (minor >= 0)
250 gb_tty->minor = minor;
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800251 return minor;
252}
253
254static void release_minor(struct gb_tty *gb_tty)
255{
Alex Elderff5f0b32014-08-18 18:25:11 -0500256 int minor = gb_tty->minor;
257
258 gb_tty->minor = 0; /* Maybe should use an invalid value instead */
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800259 mutex_lock(&table_lock);
Alex Elderff5f0b32014-08-18 18:25:11 -0500260 idr_remove(&tty_minors, minor);
Greg Kroah-Hartmanff45c262014-08-15 18:33:33 +0800261 mutex_unlock(&table_lock);
262}
263
264static int gb_tty_install(struct tty_driver *driver, struct tty_struct *tty)
265{
266 struct gb_tty *gb_tty;
267 int retval;
268
269 gb_tty = get_gb_by_minor(tty->index);
270 if (!gb_tty)
271 return -ENODEV;
272
273 retval = tty_standard_install(driver, tty);
274 if (retval)
275 goto error;
276
277 tty->driver_data = gb_tty;
278 return 0;
279error:
280 tty_port_put(&gb_tty->port);
281 return retval;
282}
283
284static int gb_tty_open(struct tty_struct *tty, struct file *file)
285{
286 struct gb_tty *gb_tty = tty->driver_data;
287
288 return tty_port_open(&gb_tty->port, tty, file);
289}
290
291static void gb_tty_close(struct tty_struct *tty, struct file *file)
292{
293 struct gb_tty *gb_tty = tty->driver_data;
294
295 tty_port_close(&gb_tty->port, tty, file);
296}
297
298static void gb_tty_cleanup(struct tty_struct *tty)
299{
300 struct gb_tty *gb_tty = tty->driver_data;
301
302 tty_port_put(&gb_tty->port);
303}
304
305static void gb_tty_hangup(struct tty_struct *tty)
306{
307 struct gb_tty *gb_tty = tty->driver_data;
308
309 tty_port_hangup(&gb_tty->port);
310}
311
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800312static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
313 int count)
314{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800315 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800316
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800317 return send_data(gb_tty, count, buf);
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800318}
319
320static int gb_tty_write_room(struct tty_struct *tty)
321{
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100322 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800323
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100324 return gb_tty->buffer_payload_max;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800325}
326
327static int gb_tty_chars_in_buffer(struct tty_struct *tty)
328{
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800329 return 0;
330}
331
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800332static int gb_tty_break_ctl(struct tty_struct *tty, int state)
333{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800334 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800335
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800336 return send_break(gb_tty, state ? 1 : 0);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800337}
338
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800339static void gb_tty_set_termios(struct tty_struct *tty,
340 struct ktermios *termios_old)
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800341{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800342 struct gb_tty *gb_tty = tty->driver_data;
343 struct ktermios *termios = &tty->termios;
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100344 struct gb_tty_line_coding newline;
Bryan O'Donoghueba4b0992015-06-29 18:09:15 +0100345 u8 newctrl = gb_tty->ctrlout;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800346
347 newline.rate = cpu_to_le32(tty_get_baud_rate(tty));
Bryan O'Donoghue62229a12015-06-02 13:40:51 +0100348 newline.format = termios->c_cflag & CSTOPB ?
349 GB_SERIAL_2_STOP_BITS : GB_SERIAL_1_STOP_BITS;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800350 newline.parity = termios->c_cflag & PARENB ?
351 (termios->c_cflag & PARODD ? 1 : 2) +
352 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
353
354 switch (termios->c_cflag & CSIZE) {
355 case CS5:
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100356 newline.data_bits = 5;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800357 break;
358 case CS6:
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100359 newline.data_bits = 6;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800360 break;
361 case CS7:
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100362 newline.data_bits = 7;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800363 break;
364 case CS8:
365 default:
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100366 newline.data_bits = 8;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800367 break;
368 }
369
370 /* FIXME: needs to clear unsupported bits in the termios */
371 gb_tty->clocal = ((termios->c_cflag & CLOCAL) != 0);
372
373 if (C_BAUD(tty) == B0) {
374 newline.rate = gb_tty->line_coding.rate;
375 newctrl &= GB_UART_CTRL_DTR;
376 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) {
377 newctrl |= GB_UART_CTRL_DTR;
378 }
379
380 if (newctrl != gb_tty->ctrlout) {
381 gb_tty->ctrlout = newctrl;
382 send_control(gb_tty, newctrl);
383 }
384
385 if (memcpy(&gb_tty->line_coding, &newline, sizeof(newline))) {
386 memcpy(&gb_tty->line_coding, &newline, sizeof(newline));
Greg Kroah-Hartman9f240f22014-11-24 13:52:25 -0800387 send_line_coding(gb_tty);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800388 }
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800389}
390
391static int gb_tty_tiocmget(struct tty_struct *tty)
392{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800393 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800394
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800395 return (gb_tty->ctrlout & GB_UART_CTRL_DTR ? TIOCM_DTR : 0) |
396 (gb_tty->ctrlout & GB_UART_CTRL_RTS ? TIOCM_RTS : 0) |
397 (gb_tty->ctrlin & GB_UART_CTRL_DSR ? TIOCM_DSR : 0) |
398 (gb_tty->ctrlin & GB_UART_CTRL_RI ? TIOCM_RI : 0) |
399 (gb_tty->ctrlin & GB_UART_CTRL_DCD ? TIOCM_CD : 0) |
400 TIOCM_CTS;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800401}
402
403static int gb_tty_tiocmset(struct tty_struct *tty, unsigned int set,
404 unsigned int clear)
405{
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800406 struct gb_tty *gb_tty = tty->driver_data;
Bryan O'Donoghueba4b0992015-06-29 18:09:15 +0100407 u8 newctrl = gb_tty->ctrlout;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800408
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800409 set = (set & TIOCM_DTR ? GB_UART_CTRL_DTR : 0) |
410 (set & TIOCM_RTS ? GB_UART_CTRL_RTS : 0);
411 clear = (clear & TIOCM_DTR ? GB_UART_CTRL_DTR : 0) |
412 (clear & TIOCM_RTS ? GB_UART_CTRL_RTS : 0);
413
414 newctrl = (newctrl & ~clear) | set;
415 if (gb_tty->ctrlout == newctrl)
416 return 0;
417
418 gb_tty->ctrlout = newctrl;
419 return send_control(gb_tty, newctrl);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800420}
421
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800422static void gb_tty_throttle(struct tty_struct *tty)
423{
424 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800425 unsigned char stop_char;
426 int retval;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800427
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800428 if (I_IXOFF(tty)) {
429 stop_char = STOP_CHAR(tty);
430 retval = gb_tty_write(tty, &stop_char, 1);
431 if (retval <= 0)
432 return;
433 }
434
435 if (tty->termios.c_cflag & CRTSCTS) {
436 gb_tty->ctrlout &= ~GB_UART_CTRL_RTS;
437 retval = send_control(gb_tty, gb_tty->ctrlout);
438 }
439
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800440}
441
442static void gb_tty_unthrottle(struct tty_struct *tty)
443{
444 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800445 unsigned char start_char;
446 int retval;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800447
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800448 if (I_IXOFF(tty)) {
449 start_char = START_CHAR(tty);
450 retval = gb_tty_write(tty, &start_char, 1);
451 if (retval <= 0)
452 return;
453 }
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800454
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800455 if (tty->termios.c_cflag & CRTSCTS) {
456 gb_tty->ctrlout |= GB_UART_CTRL_RTS;
457 retval = send_control(gb_tty, gb_tty->ctrlout);
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800458 }
459}
460
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800461static int get_serial_info(struct gb_tty *gb_tty,
462 struct serial_struct __user *info)
463{
464 struct serial_struct tmp;
465
466 if (!info)
467 return -EINVAL;
468
469 memset(&tmp, 0, sizeof(tmp));
Greg Kroah-Hartman980c7c52014-11-19 14:23:00 -0800470 tmp.flags = ASYNC_LOW_LATENCY | ASYNC_SKIP_TEST;
471 tmp.type = PORT_16550A;
472 tmp.line = gb_tty->minor;
473 tmp.xmit_fifo_size = 16;
474 tmp.baud_base = 9600;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800475 tmp.close_delay = gb_tty->port.close_delay / 10;
476 tmp.closing_wait = gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
477 ASYNC_CLOSING_WAIT_NONE : gb_tty->port.closing_wait / 10;
478
479 if (copy_to_user(info, &tmp, sizeof(tmp)))
480 return -EFAULT;
Greg Kroah-Hartman3be03d42014-09-01 19:10:06 -0700481 return 0;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800482}
483
484static int set_serial_info(struct gb_tty *gb_tty,
485 struct serial_struct __user *newinfo)
486{
487 struct serial_struct new_serial;
488 unsigned int closing_wait;
489 unsigned int close_delay;
Alex Elder69f93ab2014-09-22 18:53:02 -0500490 int retval = 0;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800491
492 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
493 return -EFAULT;
494
495 close_delay = new_serial.close_delay * 10;
496 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
497 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
498
499 mutex_lock(&gb_tty->port.mutex);
500 if (!capable(CAP_SYS_ADMIN)) {
501 if ((close_delay != gb_tty->port.close_delay) ||
502 (closing_wait != gb_tty->port.closing_wait))
503 retval = -EPERM;
504 else
505 retval = -EOPNOTSUPP;
506 } else {
507 gb_tty->port.close_delay = close_delay;
508 gb_tty->port.closing_wait = closing_wait;
509 }
510 mutex_unlock(&gb_tty->port.mutex);
511 return retval;
512}
513
514static int wait_serial_change(struct gb_tty *gb_tty, unsigned long arg)
515{
516 int retval = 0;
517 DECLARE_WAITQUEUE(wait, current);
518 struct async_icount old;
519 struct async_icount new;
520
Alex Eldercaaa8a82014-08-18 18:25:12 -0500521 if (!(arg & (TIOCM_DSR | TIOCM_RI | TIOCM_CD)))
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800522 return -EINVAL;
523
524 do {
525 spin_lock_irq(&gb_tty->read_lock);
526 old = gb_tty->oldcount;
527 new = gb_tty->iocount;
528 gb_tty->oldcount = new;
Alex Eldercaaa8a82014-08-18 18:25:12 -0500529 spin_unlock_irq(&gb_tty->read_lock);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800530
531 if ((arg & TIOCM_DSR) && (old.dsr != new.dsr))
532 break;
533 if ((arg & TIOCM_CD) && (old.dcd != new.dcd))
534 break;
535 if ((arg & TIOCM_RI) && (old.rng != new.rng))
536 break;
537
538 add_wait_queue(&gb_tty->wioctl, &wait);
539 set_current_state(TASK_INTERRUPTIBLE);
540 schedule();
541 remove_wait_queue(&gb_tty->wioctl, &wait);
542 if (gb_tty->disconnected) {
543 if (arg & TIOCM_CD)
544 break;
Alex Eldercaaa8a82014-08-18 18:25:12 -0500545 retval = -ENODEV;
546 } else if (signal_pending(current)) {
547 retval = -ERESTARTSYS;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800548 }
549 } while (!retval);
550
551 return retval;
552}
553
554static int get_serial_usage(struct gb_tty *gb_tty,
555 struct serial_icounter_struct __user *count)
556{
557 struct serial_icounter_struct icount;
558 int retval = 0;
559
560 memset(&icount, 0, sizeof(icount));
561 icount.dsr = gb_tty->iocount.dsr;
562 icount.rng = gb_tty->iocount.rng;
563 icount.dcd = gb_tty->iocount.dcd;
564 icount.frame = gb_tty->iocount.frame;
565 icount.overrun = gb_tty->iocount.overrun;
566 icount.parity = gb_tty->iocount.parity;
567 icount.brk = gb_tty->iocount.brk;
568
569 if (copy_to_user(count, &icount, sizeof(icount)) > 0)
570 retval = -EFAULT;
571
572 return retval;
573}
574
575static int gb_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
576 unsigned long arg)
577{
578 struct gb_tty *gb_tty = tty->driver_data;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800579
580 switch (cmd) {
581 case TIOCGSERIAL:
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700582 return get_serial_info(gb_tty,
583 (struct serial_struct __user *)arg);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800584 case TIOCSSERIAL:
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700585 return set_serial_info(gb_tty,
586 (struct serial_struct __user *)arg);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800587 case TIOCMIWAIT:
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700588 return wait_serial_change(gb_tty, arg);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800589 case TIOCGICOUNT:
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700590 return get_serial_usage(gb_tty,
591 (struct serial_icounter_struct __user *)arg);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800592 }
593
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -0700594 return -ENOIOCTLCMD;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800595}
596
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800597
598static const struct tty_operations gb_ops = {
599 .install = gb_tty_install,
600 .open = gb_tty_open,
601 .close = gb_tty_close,
602 .cleanup = gb_tty_cleanup,
603 .hangup = gb_tty_hangup,
604 .write = gb_tty_write,
605 .write_room = gb_tty_write_room,
606 .ioctl = gb_tty_ioctl,
607 .throttle = gb_tty_throttle,
608 .unthrottle = gb_tty_unthrottle,
609 .chars_in_buffer = gb_tty_chars_in_buffer,
610 .break_ctl = gb_tty_break_ctl,
611 .set_termios = gb_tty_set_termios,
612 .tiocmget = gb_tty_tiocmget,
613 .tiocmset = gb_tty_tiocmset,
614};
615
Bryan O'Donoghuef95ad782015-06-02 13:40:47 +0100616static struct tty_port_operations null_ops = { };
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800617
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800618static int gb_tty_init(void);
619static void gb_tty_exit(void);
620
Greg Kroah-Hartman059b0932014-10-28 09:49:33 +0800621static int gb_uart_connection_init(struct gb_connection *connection)
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800622{
Johan Hovold066f9502016-02-24 16:11:49 +0100623 size_t max_payload;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800624 struct gb_tty *gb_tty;
625 struct device *tty_dev;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800626 int retval;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800627 int minor;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800628
Greg Kroah-Hartman4d980982014-10-27 17:42:45 +0800629 /* First time here, initialize the tty structures */
630 if (atomic_inc_return(&reference_count) == 1) {
631 retval = gb_tty_init();
632 if (retval) {
633 atomic_dec(&reference_count);
634 return retval;
635 }
636 }
637
Greg Kroah-Hartman8bf23e82014-08-30 17:18:04 -0700638 gb_tty = kzalloc(sizeof(*gb_tty), GFP_KERNEL);
Phong Tran55a8e352015-06-10 21:03:17 +0700639 if (!gb_tty) {
640 retval = -ENOMEM;
641 goto error_alloc;
642 }
Bryan O'Donoghuef95ad782015-06-02 13:40:47 +0100643
Johan Hovold066f9502016-02-24 16:11:49 +0100644 max_payload = gb_operation_get_payload_size_max(connection);
645 if (max_payload < sizeof(struct gb_uart_send_data_request)) {
646 retval = -EINVAL;
647 goto error_payload;
648 }
649
650 gb_tty->buffer_payload_max = max_payload -
Greg Kroah-Hartman7f29ade2016-02-22 18:14:46 -0800651 sizeof(struct gb_uart_send_data_request);
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100652
653 gb_tty->buffer = kzalloc(gb_tty->buffer_payload_max, GFP_KERNEL);
654 if (!gb_tty->buffer) {
Phong Tran55a8e352015-06-10 21:03:17 +0700655 retval = -ENOMEM;
656 goto error_payload;
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100657 }
658
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800659 gb_tty->connection = connection;
Alex Elder93bbe852014-12-03 12:27:42 -0600660 connection->private = gb_tty;
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800661
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800662 minor = alloc_minor(gb_tty);
Alex Elderff5f0b32014-08-18 18:25:11 -0500663 if (minor < 0) {
664 if (minor == -ENOSPC) {
Greg Kroah-Hartman4f30bf32015-10-14 11:15:12 -0700665 dev_err(&connection->bundle->dev,
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800666 "no more free minor numbers\n");
Phong Tran55f22912015-06-01 22:19:45 +0700667 retval = -ENODEV;
Viresh Kumara94e1442015-08-11 07:36:11 +0530668 goto error_minor;
Alex Elderff5f0b32014-08-18 18:25:11 -0500669 }
Phong Tran55f22912015-06-01 22:19:45 +0700670 retval = minor;
Viresh Kumara94e1442015-08-11 07:36:11 +0530671 goto error_minor;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800672 }
673
674 gb_tty->minor = minor;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800675 spin_lock_init(&gb_tty->write_lock);
676 spin_lock_init(&gb_tty->read_lock);
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800677 init_waitqueue_head(&gb_tty->wioctl);
678 mutex_init(&gb_tty->mutex);
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800679
Bryan O'Donoghuef95ad782015-06-02 13:40:47 +0100680 tty_port_init(&gb_tty->port);
681 gb_tty->port.ops = &null_ops;
682
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800683 send_control(gb_tty, gb_tty->ctrlout);
684
685 /* initialize the uart to be 9600n81 */
686 gb_tty->line_coding.rate = cpu_to_le32(9600);
687 gb_tty->line_coding.format = GB_SERIAL_1_STOP_BITS;
688 gb_tty->line_coding.parity = GB_SERIAL_NO_PARITY;
Bryan O'Donoghue11fca142015-06-02 13:40:45 +0100689 gb_tty->line_coding.data_bits = 8;
Greg Kroah-Hartman9f240f22014-11-24 13:52:25 -0800690 send_line_coding(gb_tty);
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800691
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800692 tty_dev = tty_port_register_device(&gb_tty->port, gb_tty_driver, minor,
Greg Kroah-Hartman4f30bf32015-10-14 11:15:12 -0700693 &connection->bundle->dev);
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800694 if (IS_ERR(tty_dev)) {
695 retval = PTR_ERR(tty_dev);
696 goto error;
697 }
698
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800699 return 0;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800700error:
Bryan O'Donoghuef95ad782015-06-02 13:40:47 +0100701 tty_port_destroy(&gb_tty->port);
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800702 release_minor(gb_tty);
Viresh Kumara94e1442015-08-11 07:36:11 +0530703error_minor:
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800704 connection->private = NULL;
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100705 kfree(gb_tty->buffer);
Phong Tran55a8e352015-06-10 21:03:17 +0700706error_payload:
Greg Kroah-Hartmanb4be4042014-11-15 18:30:00 -0800707 kfree(gb_tty);
Phong Tran55a8e352015-06-10 21:03:17 +0700708error_alloc:
709 if (atomic_dec_return(&reference_count) == 0)
710 gb_tty_exit();
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800711 return retval;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800712}
713
Greg Kroah-Hartman059b0932014-10-28 09:49:33 +0800714static void gb_uart_connection_exit(struct gb_connection *connection)
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800715{
Greg Kroah-Hartmanaed0bc62014-10-27 17:32:34 +0800716 struct gb_tty *gb_tty = connection->private;
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800717 struct tty_struct *tty;
718
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800719 if (!gb_tty)
720 return;
721
722 mutex_lock(&gb_tty->mutex);
723 gb_tty->disconnected = true;
724
725 wake_up_all(&gb_tty->wioctl);
Greg Kroah-Hartmanaed0bc62014-10-27 17:32:34 +0800726 connection->private = NULL;
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800727 mutex_unlock(&gb_tty->mutex);
728
Greg Kroah-Hartmana18e1512014-08-15 18:54:11 +0800729 tty = tty_port_tty_get(&gb_tty->port);
730 if (tty) {
731 tty_vhangup(tty);
732 tty_kref_put(tty);
733 }
734 /* FIXME - stop all traffic */
735
736 tty_unregister_device(gb_tty_driver, gb_tty->minor);
737
Viresh Kumar696e0cc2014-11-21 11:26:30 +0530738 /* FIXME - free transmit / receive buffers */
Greg Kroah-Hartmane68453e2014-08-15 19:44:32 +0800739
Bryan O'Donoghuef95ad782015-06-02 13:40:47 +0100740 tty_port_destroy(&gb_tty->port);
Bryan O'Donoghuedd1c64e2015-06-02 13:40:49 +0100741 kfree(gb_tty->buffer);
Greg Kroah-Hartmane5f167f2014-08-30 17:11:41 -0700742 kfree(gb_tty);
Greg Kroah-Hartman4d980982014-10-27 17:42:45 +0800743
744 /* If last device is gone, tear down the tty structures */
745 if (atomic_dec_return(&reference_count) == 0)
746 gb_tty_exit();
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800747}
748
Greg Kroah-Hartman4d980982014-10-27 17:42:45 +0800749static int gb_tty_init(void)
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800750{
Marti Bolivar7fabc882014-09-05 23:56:10 -0400751 int retval = 0;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800752
Marti Bolivarf8089c02014-09-05 23:56:09 -0400753 gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, 0);
Marti Bolivar7fabc882014-09-05 23:56:10 -0400754 if (IS_ERR(gb_tty_driver)) {
Greg Kroah-Hartman168db1c2014-09-13 16:15:52 -0700755 pr_err("Can not allocate tty driver\n");
Marti Bolivar7fabc882014-09-05 23:56:10 -0400756 retval = -ENOMEM;
757 goto fail_unregister_dev;
758 }
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800759
760 gb_tty_driver->driver_name = "gb";
Marti Bolivar7fabc882014-09-05 23:56:10 -0400761 gb_tty_driver->name = GB_NAME;
Greg Kroah-Hartman168db1c2014-09-13 16:15:52 -0700762 gb_tty_driver->major = 0;
763 gb_tty_driver->minor_start = 0;
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800764 gb_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
765 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL;
766 gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
767 gb_tty_driver->init_termios = tty_std_termios;
768 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
769 tty_set_operations(gb_tty_driver, &gb_ops);
770
771 retval = tty_register_driver(gb_tty_driver);
Greg Kroah-Hartman168db1c2014-09-13 16:15:52 -0700772 if (retval) {
773 pr_err("Can not register tty driver: %d\n", retval);
Marti Bolivar7fabc882014-09-05 23:56:10 -0400774 goto fail_put_gb_tty;
Greg Kroah-Hartman168db1c2014-09-13 16:15:52 -0700775 }
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800776
Marti Bolivar7fabc882014-09-05 23:56:10 -0400777 return 0;
778
Greg Kroah-Hartman543b8ed2014-09-13 17:02:47 -0700779fail_put_gb_tty:
Marti Bolivar7fabc882014-09-05 23:56:10 -0400780 put_tty_driver(gb_tty_driver);
Greg Kroah-Hartman543b8ed2014-09-13 17:02:47 -0700781fail_unregister_dev:
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800782 return retval;
783}
784
Greg Kroah-Hartman4d980982014-10-27 17:42:45 +0800785static void gb_tty_exit(void)
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800786{
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800787 tty_unregister_driver(gb_tty_driver);
788 put_tty_driver(gb_tty_driver);
Greg Kroah-Hartman5c1ac692015-07-08 10:44:09 -0700789 idr_destroy(&tty_minors);
Greg Kroah-Hartman79c822b2014-08-15 16:01:23 +0800790}
Alex Elder3689f972014-10-27 06:04:30 -0500791
Alex Elder19d03de2014-11-05 16:12:53 -0600792static struct gb_protocol uart_protocol = {
Greg Kroah-Hartman7422a1e2014-12-24 13:01:45 -0800793 .name = "uart",
Alex Elder19d03de2014-11-05 16:12:53 -0600794 .id = GREYBUS_PROTOCOL_UART,
Viresh Kumar9475fb52015-08-08 10:25:39 +0530795 .major = GB_UART_VERSION_MAJOR,
796 .minor = GB_UART_VERSION_MINOR,
Alex Elder5d9fd7e2014-11-05 16:12:54 -0600797 .connection_init = gb_uart_connection_init,
798 .connection_exit = gb_uart_connection_exit,
Bryan O'Donoghue1c087012015-06-02 13:40:50 +0100799 .request_recv = gb_uart_request_recv,
Alex Elder19d03de2014-11-05 16:12:53 -0600800};
801
Viresh Kumare18822e2015-07-01 12:13:52 +0530802gb_builtin_protocol_driver(uart_protocol);