Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1952677ybm; Thu, 23 May 2019 09:06:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqydX0TNPpwnV+fnPojovX2eg5RCKx23uuhiag1XAswlPteXBfVnYZUveoNRIRgpuoh8/vmK X-Received: by 2002:a17:902:304:: with SMTP id 4mr59597330pld.120.1558627586426; Thu, 23 May 2019 09:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558627586; cv=none; d=google.com; s=arc-20160816; b=fynieZG6uVAtOo6nxURHT/H3CB2IR8DGCh9g2hyGoSmDy/Xt/tbZp/3naLEq0tvieM 37LA5jj19QDkkCGhD4YWNdUFSLd2sIbU8ackAc1RiDuS5K3CVZvDC0UcinetWxbxOJj+ 3LmkpejQmox2YTDTDoWoaRsP9lSz90MbTOn64ljN0q9BEggd8NYBXfH0KFXwoVtP12W3 36CpTIdwKOzpFRl+CKdChdE9bv1kRinucLF2VhbRGGXvIUNb7VzUAGHXQDflFaTgKVnZ m0bgp8uuwQP/4Ljyv/XnfZt4iQmmjAW4pezR+UWgxvRJfO9cLSovCG8BZJHGhis6k3OV 1tZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=5hI8e6ZPQsGWd16AXQZ48E8SF9A1eKHn+PFkt0sf6cI=; b=VYbDCY1MThEx7YPMagHP0sz6b1V/SNCS7dR8r6ylGYo9agqs/uqtgewMX8bU4QSvPj DwFXAVHeNJfrB9GRYEfHGhQHREdNp5t2NVI0/fJeMjW7LWI6el5DaYYpBRH0e9SKqyjg yKp3EnDHQCrtkrxRQdBHFMsw5DOu9335beRGpInqMY9jlIH1+T8GmzN7gN0L1eNmTVkS nDrWqVNMW5kgBHS8k8uDl98mGuRTYV72Sj8goKOqI3nw9G7MkrmEPy3exI149qryn3LO U7qjno5qFdGRQvjQz6ySD5dAU1wZcBrD984uxw9s3lqFcV3CPaRyxTU+owbOoHA8eWso U08Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=Qk1cKxAE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ch10si14165851plb.207.2019.05.23.09.06.08; Thu, 23 May 2019 09:06:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=Qk1cKxAE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731089AbfEWQEL (ORCPT + 99 others); Thu, 23 May 2019 12:04:11 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:27274 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730987AbfEWQEK (ORCPT ); Thu, 23 May 2019 12:04:10 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4NG0qiD026668; Thu, 23 May 2019 18:03:58 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=5hI8e6ZPQsGWd16AXQZ48E8SF9A1eKHn+PFkt0sf6cI=; b=Qk1cKxAEtru+kBs84o6iSy0uIp98tJ5AmYS5Z5hhoeNx7+TO7l+Qa8G8TivAzde2H8E5 xCs/RVAhVaggfr79Abew2wMF5n2WpnO6Bm5M1dLN+C3r7G//z4tQNvmK3yc6yK5upjWU 8KAlwfNZQaXF3dAvT8f5NMB/FvU3OCWHXRj8iUXq5XkiZ5GEzyFd+Ergtdz7+sEhaxmM QT1rH38tlCEDTxl0O4FrVhzJfwJoVw0RRO0S7vMyXiUUMoEx3pr8xUmCTEtWJ+2z1Jf+ CiFtOlJGc9nJA6yX0gs3ZK8nAPuNF6zOsNDKmp6H0VEu+9eFTNa1ax31Jsrl33u2MT+H vA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2snrve289m-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 23 May 2019 18:03:58 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EFC5034; Thu, 23 May 2019 16:03:57 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 772364E9A; Thu, 23 May 2019 16:03:57 +0000 (GMT) Received: from SAFEX1HUBCAS21.st.com (10.75.90.44) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 18:03:57 +0200 Received: from localhost (10.48.0.131) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 23 May 2019 18:03:56 +0200 From: Arnaud Pouliquen To: Ohad Ben-Cohen , Bjorn Andersson , Greg Kroah-Hartman , Jiri Slaby , xiang xiao , CC: , Fabien DESSENNE , , Alan Cox Subject: [PATCH v4 2/2] tty: add rpmsg driver Date: Thu, 23 May 2019 18:03:21 +0200 Message-ID: <1558627401-1090-3-git-send-email-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558627401-1090-1-git-send-email-arnaud.pouliquen@st.com> References: <1558627401-1090-1-git-send-email-arnaud.pouliquen@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.48.0.131] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-23_13:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver exposes a standard tty interface on top of the rpmsg framework through the "rpmsg-tty-channel" rpmsg service. This driver supports multi-instances, offering a /dev/ttyRPMSGx entry per rpmsg endpoint. Signed-off-by: Arnaud Pouliquen Signed-off-by: Fabien Dessenne --- Documentation/serial/tty_rpmsg.rst | 43 ++++ drivers/tty/Kconfig | 9 + drivers/tty/Makefile | 1 + drivers/tty/rpmsg_tty.c | 455 +++++++++++++++++++++++++++++++++++++ 4 files changed, 508 insertions(+) create mode 100644 Documentation/serial/tty_rpmsg.rst create mode 100644 drivers/tty/rpmsg_tty.c diff --git a/Documentation/serial/tty_rpmsg.rst b/Documentation/serial/tty_rpmsg.rst new file mode 100644 index 000000000000..b65345cc82e8 --- /dev/null +++ b/Documentation/serial/tty_rpmsg.rst @@ -0,0 +1,43 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +The rpmsg TTY +============= + +The rpmsg tty driver implements a serial communication on the rpmsg bus, +to communicate with a remote processor devices in asymmetric multiprocessing +(AMP) configurations. + +The remote processor can instantiate a new tty by requesting a new "rpmsg-tty-channel" RPMsg service. Information related to the RPMsg and +associated tty device is available in /sys/bus/rpmsg/devices/virtio0.rpmsg-tty-channel.-1., with + corresponding to the ttyRPMSG instance. + +RPMsg data/control structure +---------------------------- + +The RPMsg is used to send data or control messages. Differentiation between the +stream and the control messages is done thanks to the first byte of the +RPMsg payload: + + +- RPMSG_DATA - rest of messages contains data + +- RPMSG_CTRL - message contains control. + + +To be compliant with this driver, the remote firmware has to respect this RPMsg +payload structure. At least the RPMSG_DATA type has to be supported. The +RPMSG_CTRL is optional. + +Flow control type +----------------- + +A minimum flow control can be implemented to allow/block communication with the remote processor. + +- DATA_TERM_READY + one asocated parameter: + + - u8 state: + + - Set to indicate to remote side that terminal is ready for communication. + - Reset to block communication with remote side. diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index e0a04bfc873e..d7b426939f69 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -442,6 +442,15 @@ config VCC help Support for Sun logical domain consoles. +config RPMSG_TTY + tristate "RPMSG tty driver" + depends on RPMSG + help + Say y here to export rpmsg endpoints as tty devices, usually found + in /dev/ttyRPMSGx. + This makes it possible for user-space programs to send and receive + rpmsg messages as a standard tty protocol. + config LDISC_AUTOLOAD bool "Automatically load TTY Line Disciplines" default y diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile index c72cafdf32b4..90a98a20714d 100644 --- a/drivers/tty/Makefile +++ b/drivers/tty/Makefile @@ -33,5 +33,6 @@ obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o obj-$(CONFIG_VCC) += vcc.o +obj-$(CONFIG_RPMSG_TTY) += rpmsg_tty.o obj-y += ipwireless/ diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c new file mode 100644 index 000000000000..f5894438536f --- /dev/null +++ b/drivers/tty/rpmsg_tty.c @@ -0,0 +1,455 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2019 - All Rights Reserved + * Authors: Arnaud Pouliquen for STMicroelectronics. + * Fabien Dessenne for STMicroelectronics. + */ + +#include +#include +#include +#include +#include + +#define MAX_TTY_RPMSG 32 + +static DEFINE_IDR(tty_idr); /* tty instance id */ +static DEFINE_MUTEX(idr_lock); /* protects tty_idr */ + +static struct tty_driver *rpmsg_tty_driver; + +enum rpmsg_tty_type_t { + RPMSG_DATA, + RPMSG_CTRL, + NUM_RPMSG_TTY_TYPE +}; + +enum rpmsg_tty_ctrl_t { + DATA_TERM_READY, /* ready to accept data */ + NUM_RPMSG_TTY_CTRL_TYPE +}; + +struct rpmsg_tty_payload { + u8 cmd; + u8 data[0]; +}; + +struct rpmsg_tty_ctrl { + u8 ctrl; + u8 values[0]; +}; + +struct rpmsg_tty_port { + struct tty_port port; /* TTY port data */ + int id; /* TTY rpmsg index */ + int cts; /* remote reception status */ + struct rpmsg_device *rpdev; /* rpmsg device */ +}; + +typedef void (*rpmsg_tty_rx_cb_t)(struct rpmsg_device *, void *, int, void *, + u32); + +static void rpmsg_tty_data_handler(struct rpmsg_device *rpdev, void *data, + int len, void *priv, u32 src) +{ + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); + int copied; + + dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len); + + if (!len) + return; + + copied = tty_insert_flip_string_fixed_flag(&cport->port, data, + TTY_NORMAL, len); + if (copied != len) + dev_dbg(&rpdev->dev, "trunc buffer: available space is %d\n", + copied); + tty_flip_buffer_push(&cport->port); +} + +static void rpmsg_tty_ctrl_handler(struct rpmsg_device *rpdev, void *data, + int len, void *priv, u32 src) +{ + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); + struct rpmsg_tty_ctrl *ctrl = data; + + dev_dbg(&rpdev->dev, "%s: ctrl received %d\n", __func__, ctrl->ctrl); + print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len, + true); + + if (len <= sizeof(*ctrl)) { + dev_err(&rpdev->dev, "%s: ctrl message invalid\n", __func__); + return; + } + + if (ctrl->ctrl == DATA_TERM_READY) { + /* Update the CTS according to remote RTS */ + if (!ctrl->values[0]) { + cport->cts = 0; + } else { + cport->cts = 1; + tty_port_tty_wakeup(&cport->port); + } + } else { + dev_err(&rpdev->dev, "unknown control ID %d\n", ctrl->ctrl); + } +} + +static const rpmsg_tty_rx_cb_t rpmsg_tty_handler[] = { + [RPMSG_DATA] = rpmsg_tty_data_handler, + [RPMSG_CTRL] = rpmsg_tty_ctrl_handler, +}; + +static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, + void *priv, u32 src) +{ + struct rpmsg_tty_payload *rbuf = data; + + if (len <= sizeof(*rbuf) || rbuf->cmd >= NUM_RPMSG_TTY_TYPE) { + dev_err(&rpdev->dev, "Invalid message: size %d, type %d\n", + len, rbuf->cmd); + return -EINVAL; + } + + rpmsg_tty_handler[rbuf->cmd](rpdev, &rbuf->data, + len - sizeof(rbuf->cmd), priv, src); + + return 0; +} + +static int rpmsg_tty_write_control(struct tty_struct *tty, u8 ctrl, u8 *values, + unsigned int n_value) +{ + struct rpmsg_tty_port *cport = tty->driver_data; + struct rpmsg_tty_payload *msg; + struct rpmsg_tty_ctrl *m_ctrl; + struct rpmsg_device *rpdev; + unsigned int msg_size; + int ret; + + rpdev = cport->rpdev; + + msg_size = sizeof(*msg) + sizeof(*m_ctrl) + n_value; + msg = kzalloc(msg_size, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + msg->cmd = RPMSG_CTRL; + m_ctrl = (struct rpmsg_tty_ctrl *)&msg->data[0]; + m_ctrl->ctrl = DATA_TERM_READY; + memcpy(m_ctrl->values, values, n_value); + + ret = rpmsg_trysend(rpdev->ept, msg, msg_size); + if (ret < 0) { + dev_dbg(tty->dev, "cannot send control (%d)\n", ret); + ret = 0; + } + kfree(msg); + + return ret; +}; + +static void rpmsg_tty_throttle(struct tty_struct *tty) +{ + u8 rts = 0; + + /* Disable remote transmission */ + rpmsg_tty_write_control(tty, DATA_TERM_READY, &rts, 1); +}; + +static void rpmsg_tty_unthrottle(struct tty_struct *tty) +{ + u8 rts = 1; + + /* Enable remote transmission */ + rpmsg_tty_write_control(tty, DATA_TERM_READY, &rts, 1); +}; + +static int rpmsg_tty_install(struct tty_driver *driver, struct tty_struct *tty) +{ + struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index); + + if (!cport) { + dev_err(tty->dev, "cannot get cport\n"); + return -ENODEV; + } + + tty->driver_data = cport; + return tty_port_install(&cport->port, driver, tty); +} + +static int rpmsg_tty_open(struct tty_struct *tty, struct file *filp) +{ + return tty_port_open(tty->port, tty, filp); +} + +static void rpmsg_tty_close(struct tty_struct *tty, struct file *filp) +{ + return tty_port_close(tty->port, tty, filp); +} + +static int rpmsg_tty_write(struct tty_struct *tty, const u8 *buf, int len) +{ + struct rpmsg_tty_port *cport = tty->driver_data; + struct rpmsg_device *rpdev; + int msg_max_size, ret = 0; + unsigned int msg_size; + int cmd_sz = sizeof(struct rpmsg_tty_payload); + u8 *tmpbuf; + + /* If cts not set, the message is not sent*/ + if (!cport->cts) + return 0; + + rpdev = cport->rpdev; + + dev_dbg(&rpdev->dev, "%s: send msg from tty->index = %d, len = %d\n", + __func__, tty->index, len); + + msg_max_size = rpmsg_get_buf_payload_size(rpdev->ept); + if (msg_max_size < 0) + return msg_max_size; + + msg_size = min(len + cmd_sz, msg_max_size); + tmpbuf = kzalloc(msg_size, GFP_KERNEL); + if (!tmpbuf) + return -ENOMEM; + + tmpbuf[0] = RPMSG_DATA; + memcpy(&tmpbuf[cmd_sz], buf, msg_size - cmd_sz); + + /* + * Try to send the message to remote processor, if failed return 0 as + * no data sent + */ + ret = rpmsg_trysend(rpdev->ept, tmpbuf, msg_size); + kfree(tmpbuf); + if (ret) { + dev_dbg(&rpdev->dev, "rpmsg_send failed: %d\n", ret); + return 0; + } + + return msg_size - cmd_sz; +} + +static int rpmsg_tty_write_room(struct tty_struct *tty) +{ + struct rpmsg_tty_port *cport = tty->driver_data; + int space = 0; + + /* + * Report the space in the rpmsg buffer, first byte is reserved to + * define the buffer type. + */ + if (cport->cts) { + space = rpmsg_get_buf_payload_size(cport->rpdev->ept); + space -= sizeof(struct rpmsg_tty_payload); + } + + return space; +} + +static const struct tty_operations rpmsg_tty_ops = { + .install = rpmsg_tty_install, + .open = rpmsg_tty_open, + .close = rpmsg_tty_close, + .write = rpmsg_tty_write, + .write_room = rpmsg_tty_write_room, + .throttle = rpmsg_tty_throttle, + .unthrottle = rpmsg_tty_unthrottle, +}; + +static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void) +{ + struct rpmsg_tty_port *cport; + + cport = kzalloc(sizeof(*cport), GFP_KERNEL); + if (!cport) + return ERR_PTR(-ENOMEM); + + mutex_lock(&idr_lock); + cport->id = idr_alloc(&tty_idr, cport, 0, MAX_TTY_RPMSG, GFP_KERNEL); + mutex_unlock(&idr_lock); + + if (cport->id < 0) { + kfree(cport); + return ERR_PTR(-ENOSPC); + } + + return cport; +} + +static void rpmsg_tty_release_cport(struct rpmsg_tty_port *cport) +{ + mutex_lock(&idr_lock); + idr_remove(&tty_idr, cport->id); + mutex_unlock(&idr_lock); + + kfree(cport); +} + +static int rpmsg_tty_port_activate(struct tty_port *p, struct tty_struct *tty) +{ + p->low_latency = (p->flags & ASYNC_LOW_LATENCY) ? 1 : 0; + + /* Allocate the buffer we use for writing data */ + return tty_port_alloc_xmit_buf(p); +} + +static void rpmsg_tty_port_shutdown(struct tty_port *p) +{ + /* Free the write buffer */ + tty_port_free_xmit_buf(p); +} + +static void rpmsg_tty_dtr_rts(struct tty_port *port, int raise) +{ + struct rpmsg_tty_port *cport = + container_of(port, struct rpmsg_tty_port, port); + + pr_debug("%s: dtr_rts state %d\n", __func__, raise); + + cport->cts = raise; + + if (raise) + rpmsg_tty_unthrottle(port->tty); + else + rpmsg_tty_throttle(port->tty); +} + +static const struct tty_port_operations rpmsg_tty_port_ops = { + .activate = rpmsg_tty_port_activate, + .shutdown = rpmsg_tty_port_shutdown, + .dtr_rts = rpmsg_tty_dtr_rts, +}; + +static int rpmsg_tty_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_tty_port *cport; + struct device *dev = &rpdev->dev; + struct device *tty_dev; + int ret; + + cport = rpmsg_tty_alloc_cport(); + if (IS_ERR(cport)) { + dev_err(dev, "failed to alloc tty port\n"); + return PTR_ERR(cport); + } + + tty_port_init(&cport->port); + cport->port.ops = &rpmsg_tty_port_ops; + + tty_dev = tty_port_register_device(&cport->port, rpmsg_tty_driver, + cport->id, dev); + if (IS_ERR(tty_dev)) { + dev_err(dev, "failed to register tty port\n"); + ret = PTR_ERR(tty_dev); + goto err_destroy; + } + + cport->rpdev = rpdev; + + dev_set_drvdata(dev, cport); + + dev_dbg(dev, "new channel: 0x%x -> 0x%x : ttyRPMSG%d\n", + rpdev->src, rpdev->dst, cport->id); + + return 0; + +err_destroy: + tty_port_destroy(&cport->port); + rpmsg_tty_release_cport(cport); + + return ret; +} + +static void rpmsg_tty_remove(struct rpmsg_device *rpdev) +{ + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); + + dev_dbg(&rpdev->dev, "removing rpmsg tty device %d\n", cport->id); + + /* User hang up to release the tty */ + if (tty_port_initialized(&cport->port)) + tty_port_tty_hangup(&cport->port, false); + + tty_unregister_device(rpmsg_tty_driver, cport->id); + + tty_port_destroy(&cport->port); + rpmsg_tty_release_cport(cport); +} + +static struct rpmsg_device_id rpmsg_driver_tty_id_table[] = { + { .name = "rpmsg-tty-channel" }, + { }, +}; +MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_tty_id_table); + +static struct rpmsg_driver rpmsg_tty_rpmsg_drv = { + .drv.name = KBUILD_MODNAME, + .id_table = rpmsg_driver_tty_id_table, + .probe = rpmsg_tty_probe, + .callback = rpmsg_tty_cb, + .remove = rpmsg_tty_remove, +}; + +static int __init rpmsg_tty_init(void) +{ + int err; + + rpmsg_tty_driver = tty_alloc_driver(MAX_TTY_RPMSG, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(rpmsg_tty_driver)) + return PTR_ERR(rpmsg_tty_driver); + + rpmsg_tty_driver->driver_name = "rpmsg_tty"; + rpmsg_tty_driver->name = "ttyRPMSG"; + rpmsg_tty_driver->major = 0; + rpmsg_tty_driver->type = TTY_DRIVER_TYPE_CONSOLE; + + /* Disable unused mode by default */ + rpmsg_tty_driver->init_termios = tty_std_termios; + rpmsg_tty_driver->init_termios.c_lflag &= ~(ECHO | ICANON); + rpmsg_tty_driver->init_termios.c_oflag &= ~(OPOST | ONLCR); + + tty_set_operations(rpmsg_tty_driver, &rpmsg_tty_ops); + + err = tty_register_driver(rpmsg_tty_driver); + if (err < 0) { + pr_err("Couldn't install rpmsg tty driver: err %d\n", err); + goto error_put; + } + + err = register_rpmsg_driver(&rpmsg_tty_rpmsg_drv); + if (err < 0) { + pr_err("Couldn't register rpmsg tty driver: err %d\n", err); + goto error_unregister; + } + + return 0; + +error_unregister: + tty_unregister_driver(rpmsg_tty_driver); + +error_put: + put_tty_driver(rpmsg_tty_driver); + + return err; +} + +static void __exit rpmsg_tty_exit(void) +{ + unregister_rpmsg_driver(&rpmsg_tty_rpmsg_drv); + tty_unregister_driver(rpmsg_tty_driver); + put_tty_driver(rpmsg_tty_driver); + idr_destroy(&tty_idr); +} + +module_init(rpmsg_tty_init); +module_exit(rpmsg_tty_exit); + +MODULE_AUTHOR("Arnaud Pouliquen "); +MODULE_AUTHOR("Fabien Dessenne "); +MODULE_DESCRIPTION("virtio remote processor messaging tty driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4