Skip to content

Commit 9961127

Browse files
Vincent CuissardSamuel Ortiz
authored andcommitted
NFC: nci: add generic uart support
Some NFC controller supports UART as host interface. As with SPI, a lot of code can be shared between vendor drivers. This patch add the generic support of UART and provides some extension API for vendor specific needs. This code is strongly inspired by the Bluetooth HCI ldisc implementation. NCI UART vendor drivers will have to register themselves to this layer via nci_uart_register. Underlying tty will have to be configured from user land thanks to an ioctl. Signed-off-by: Vincent Cuissard <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 4a2b947 commit 9961127

File tree

6 files changed

+554
-0
lines changed

6 files changed

+554
-0
lines changed

include/net/nfc/nci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define NCI_MAX_NUM_RF_CONFIGS 10
3636
#define NCI_MAX_NUM_CONN 10
3737
#define NCI_MAX_PARAM_LEN 251
38+
#define NCI_MAX_PACKET_SIZE 258
3839

3940
/* NCI Status Codes */
4041
#define NCI_STATUS_OK 0x00

include/net/nfc/nci_core.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <linux/interrupt.h>
3333
#include <linux/skbuff.h>
34+
#include <linux/tty.h>
3435

3536
#include <net/nfc/nfc.h>
3637
#include <net/nfc/nci.h>
@@ -391,4 +392,50 @@ int nci_spi_send(struct nci_spi *nspi,
391392
struct sk_buff *skb);
392393
struct sk_buff *nci_spi_read(struct nci_spi *nspi);
393394

395+
/* ----- NCI UART ---- */
396+
397+
/* Ioctl */
398+
#define NCIUARTSETDRIVER _IOW('U', 0, char *)
399+
400+
enum nci_uart_driver {
401+
NCI_UART_DRIVER_MARVELL = 0,
402+
NCI_UART_DRIVER_MAX
403+
};
404+
405+
struct nci_uart;
406+
407+
struct nci_uart_ops {
408+
int (*open)(struct nci_uart *nci_uart);
409+
void (*close)(struct nci_uart *nci_uart);
410+
int (*recv)(struct nci_uart *nci_uart, struct sk_buff *skb);
411+
int (*recv_buf)(struct nci_uart *nci_uart, const u8 *data, char *flags,
412+
int count);
413+
int (*send)(struct nci_uart *nci_uart, struct sk_buff *skb);
414+
void (*tx_start)(struct nci_uart *nci_uart);
415+
void (*tx_done)(struct nci_uart *nci_uart);
416+
};
417+
418+
struct nci_uart {
419+
struct module *owner;
420+
struct nci_uart_ops ops;
421+
const char *name;
422+
enum nci_uart_driver driver;
423+
424+
/* Dynamic data */
425+
struct nci_dev *ndev;
426+
spinlock_t rx_lock;
427+
struct work_struct write_work;
428+
struct tty_struct *tty;
429+
unsigned long tx_state;
430+
struct sk_buff_head tx_q;
431+
struct sk_buff *tx_skb;
432+
struct sk_buff *rx_skb;
433+
int rx_packet_len;
434+
void *drv_data;
435+
};
436+
437+
int nci_uart_register(struct nci_uart *nu);
438+
void nci_uart_unregister(struct nci_uart *nu);
439+
void nci_uart_set_config(struct nci_uart *nu, int baudrate, int flow_ctrl);
440+
394441
#endif /* __NCI_CORE_H */

include/uapi/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
#define N_TI_WL 22 /* for TI's WL BT, FM, GPS combo chips */
3535
#define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */
3636
#define N_TRACEROUTER 24 /* Trace data routing for MIPI P1149.7 */
37+
#define N_NCI 25 /* NFC NCI UART */
3738

3839
#endif /* _UAPI_LINUX_TTY_H */

net/nfc/nci/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ config NFC_NCI_SPI
1919
an NFC Controller (NFCC) and a Device Host (DH).
2020

2121
Say yes if you use an NCI driver that requires SPI link layer.
22+
23+
config NFC_NCI_UART
24+
depends on NFC_NCI && TTY
25+
tristate "NCI over UART protocol support"
26+
default n
27+
help
28+
Say yes if you use an NCI driver that requires UART link layer.

net/nfc/nci/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ obj-$(CONFIG_NFC_NCI) += nci.o
77
nci-objs := core.o data.o lib.o ntf.o rsp.o hci.o
88

99
nci-$(CONFIG_NFC_NCI_SPI) += spi.o
10+
11+
nci_uart-y += uart.o
12+
obj-$(CONFIG_NFC_NCI_UART) += nci_uart.o

0 commit comments

Comments
 (0)