Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 2015, Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This software file (the "File") is distributed by Marvell International
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * (the "License").  You may use, redistribute and/or modify this File in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * accordance with the terms and conditions of the License, a copy of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * is available on the worldwide web at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * this warranty disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* Inspired (hugely) by HCI LDISC implementation in Bluetooth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  Copyright (C) 2000-2001  Qualcomm Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <net/nfc/nci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <net/nfc/nci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* TX states  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define NCI_UART_SENDING	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define NCI_UART_TX_WAKEUP	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static struct nci_uart *nci_uart_drivers[NCI_UART_DRIVER_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline struct sk_buff *nci_uart_dequeue(struct nci_uart *nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct sk_buff *skb = nu->tx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		skb = skb_dequeue(&nu->tx_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		nu->tx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static inline int nci_uart_queue_empty(struct nci_uart *nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (nu->tx_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return skb_queue_empty(&nu->tx_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int nci_uart_tx_wakeup(struct nci_uart *nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (test_and_set_bit(NCI_UART_SENDING, &nu->tx_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		set_bit(NCI_UART_TX_WAKEUP, &nu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	schedule_work(&nu->write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static void nci_uart_write_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct nci_uart *nu = container_of(work, struct nci_uart, write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct tty_struct *tty = nu->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	clear_bit(NCI_UART_TX_WAKEUP, &nu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (nu->ops.tx_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		nu->ops.tx_start(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	while ((skb = nci_uart_dequeue(nu))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		len = tty->ops->write(tty, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		skb_pull(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			nu->tx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (test_bit(NCI_UART_TX_WAKEUP, &nu->tx_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (nu->ops.tx_done && nci_uart_queue_empty(nu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		nu->ops.tx_done(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	clear_bit(NCI_UART_SENDING, &nu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int nci_uart_set_driver(struct tty_struct *tty, unsigned int driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct nci_uart *nu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (driver >= NCI_UART_DRIVER_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!nci_uart_drivers[driver])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	nu = kzalloc(sizeof(*nu), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	memcpy(nu, nci_uart_drivers[driver], sizeof(struct nci_uart));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	nu->tty = tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	tty->disc_data = nu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	skb_queue_head_init(&nu->tx_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	INIT_WORK(&nu->write_work, nci_uart_write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	spin_lock_init(&nu->rx_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ret = nu->ops.open(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		tty->disc_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		kfree(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	} else if (!try_module_get(nu->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		nu->ops.close(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		tty->disc_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		kfree(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* ------ LDISC part ------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* nci_uart_tty_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  *     Called when line discipline changed to NCI_UART.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *     tty    pointer to tty info structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Return Value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *     0 if success, otherwise error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int nci_uart_tty_open(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* Error if the tty has no write op instead of leaving an exploitable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * hole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!tty->ops->write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	tty->disc_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	tty->receive_room = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Flush any pending characters in the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	tty_driver_flush_buffer(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* nci_uart_tty_close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *    Called when the line discipline is changed to something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *    else, the tty is closed, or the tty detects a hangup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void nci_uart_tty_close(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct nci_uart *nu = (void *)tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* Detach from the tty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	tty->disc_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	kfree_skb(nu->tx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	kfree_skb(nu->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	skb_queue_purge(&nu->tx_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	nu->ops.close(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	nu->tty = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	module_put(nu->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	cancel_work_sync(&nu->write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	kfree(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* nci_uart_tty_wakeup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  *    Callback for transmit wakeup. Called when low level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  *    device driver can accept more send data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * Arguments:        tty    pointer to associated tty instance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * Return Value:    None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static void nci_uart_tty_wakeup(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct nci_uart *nu = (void *)tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (tty != nu->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	nci_uart_tx_wakeup(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* nci_uart_tty_receive()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *     Called by tty low level driver when receive data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *     available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * Arguments:  tty          pointer to tty isntance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  *             data         pointer to received data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *             flags        pointer to flags for data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  *             count        count of received data in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * Return Value:    None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void nci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				 char *flags, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct nci_uart *nu = (void *)tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!nu || tty != nu->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	spin_lock(&nu->rx_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	nu->ops.recv_buf(nu, (void *)data, flags, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	spin_unlock(&nu->rx_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	tty_unthrottle(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* nci_uart_tty_ioctl()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  *    Process IOCTL system call for the tty device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *    tty        pointer to tty instance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *    file       pointer to open file object for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  *    cmd        IOCTL command code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  *    arg        argument for IOCTL call (cmd dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * Return Value:    Command dependent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int nci_uart_tty_ioctl(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			      unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct nci_uart *nu = (void *)tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	case NCIUARTSETDRIVER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (!nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			return nci_uart_set_driver(tty, (unsigned int)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		err = n_tty_ioctl_helper(tty, file, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* We don't provide read/write/poll interface for user space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static ssize_t nci_uart_tty_read(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				 unsigned char *buf, size_t nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				 void **cookie, unsigned long offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static ssize_t nci_uart_tty_write(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				  const unsigned char *data, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static __poll_t nci_uart_tty_poll(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				      struct file *filp, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static int nci_uart_send(struct nci_uart *nu, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* Queue TX packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	skb_queue_tail(&nu->tx_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* Try to start TX (if possible) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	nci_uart_tx_wakeup(nu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* -- Default recv_buf handler --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * This handler supposes that NCI frames are sent over UART link without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * framing. It reads NCI header, retrieve the packet size and once all packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * bytes are received it passes it to nci_uart driver for processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 				     char *flags, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int chunk_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!nu->ndev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		nfc_err(nu->tty->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			"receive data from tty but no NCI dev is attached yet, drop buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/* Decode all incoming data in packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 * and enqueue then for processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	while (count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		/* If this is the first data of a packet, allocate a buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		if (!nu->rx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			nu->rx_packet_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			nu->rx_skb = nci_skb_alloc(nu->ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						   NCI_MAX_PACKET_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 						   GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			if (!nu->rx_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		/* Eat byte after byte till full packet header is received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (nu->rx_skb->len < NCI_CTRL_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			skb_put_u8(nu->rx_skb, *data++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			--count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		/* Header was received but packet len was not read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (nu->rx_packet_len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			nu->rx_packet_len = NCI_CTRL_HDR_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				nci_plen(nu->rx_skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		/* Compute how many bytes are missing and how many bytes can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		 * be consumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		chunk_len = nu->rx_packet_len - nu->rx_skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		if (count < chunk_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			chunk_len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		skb_put_data(nu->rx_skb, data, chunk_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		data += chunk_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		count -= chunk_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		/* Chcek if packet is fully received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (nu->rx_packet_len == nu->rx_skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			/* Pass RX packet to driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			if (nu->ops.recv(nu, nu->rx_skb) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				nfc_err(nu->tty->dev, "corrupted RX packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			/* Next packet will be a new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			nu->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /* -- Default recv handler -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int nci_uart_default_recv(struct nci_uart *nu, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return nci_recv_frame(nu->ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int nci_uart_register(struct nci_uart *nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (!nu || !nu->ops.open ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	    !nu->ops.recv || !nu->ops.close)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/* Set the send callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	nu->ops.send = nci_uart_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	/* Install default handlers if not overridden */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (!nu->ops.recv_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		nu->ops.recv_buf = nci_uart_default_recv_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (!nu->ops.recv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		nu->ops.recv = nci_uart_default_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	/* Add this driver in the driver list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (nci_uart_drivers[nu->driver]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		pr_err("driver %d is already registered\n", nu->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	nci_uart_drivers[nu->driver] = nu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	pr_info("NCI uart driver '%s [%d]' registered\n", nu->name, nu->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) EXPORT_SYMBOL_GPL(nci_uart_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) void nci_uart_unregister(struct nci_uart *nu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	pr_info("NCI uart driver '%s [%d]' unregistered\n", nu->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		nu->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	/* Remove this driver from the driver list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	nci_uart_drivers[nu->driver] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) EXPORT_SYMBOL_GPL(nci_uart_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) void nci_uart_set_config(struct nci_uart *nu, int baudrate, int flow_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct ktermios new_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (!nu->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	down_read(&nu->tty->termios_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	new_termios = nu->tty->termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	up_read(&nu->tty->termios_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	tty_termios_encode_baud_rate(&new_termios, baudrate, baudrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	if (flow_ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		new_termios.c_cflag |= CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		new_termios.c_cflag &= ~CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	tty_set_termios(nu->tty, &new_termios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) EXPORT_SYMBOL_GPL(nci_uart_set_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static struct tty_ldisc_ops nci_uart_ldisc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.magic		= TTY_LDISC_MAGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.name		= "n_nci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.open		= nci_uart_tty_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.close		= nci_uart_tty_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	.read		= nci_uart_tty_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	.write		= nci_uart_tty_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	.poll		= nci_uart_tty_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	.receive_buf	= nci_uart_tty_receive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	.write_wakeup	= nci_uart_tty_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.ioctl		= nci_uart_tty_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	.compat_ioctl	= nci_uart_tty_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int __init nci_uart_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	memset(nci_uart_drivers, 0, sizeof(nci_uart_drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	return tty_register_ldisc(N_NCI, &nci_uart_ldisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static void __exit nci_uart_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	tty_unregister_ldisc(N_NCI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) module_init(nci_uart_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) module_exit(nci_uart_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) MODULE_AUTHOR("Marvell International Ltd.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) MODULE_DESCRIPTION("NFC NCI UART driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) MODULE_ALIAS_LDISC(N_NCI);