2 * Marvell NFC-over-UART driver
4 * Copyright (C) 2015, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available on the worldwide web at
11 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
14 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
15 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
16 * this warranty disclaimer.
19 #include <linux/module.h>
20 #include <linux/delay.h>
21 #include <linux/of_gpio.h>
22 #include <net/nfc/nci.h>
23 #include <net/nfc/nci_core.h>
26 static unsigned int hci_muxed;
27 static unsigned int flow_control;
28 static unsigned int break_control;
29 static unsigned int reset_n_io;
35 static int nfcmrvl_uart_nci_open(struct nfcmrvl_private *priv)
40 static int nfcmrvl_uart_nci_close(struct nfcmrvl_private *priv)
45 static int nfcmrvl_uart_nci_send(struct nfcmrvl_private *priv,
48 struct nci_uart *nu = priv->drv_data;
50 return nu->ops.send(nu, skb);
53 static void nfcmrvl_uart_nci_update_config(struct nfcmrvl_private *priv,
56 struct nci_uart *nu = priv->drv_data;
57 const struct nfcmrvl_fw_uart_config *config = param;
59 nci_uart_set_config(nu, le32_to_cpu(config->baudrate),
60 config->flow_control);
63 static struct nfcmrvl_if_ops uart_ops = {
64 .nci_open = nfcmrvl_uart_nci_open,
65 .nci_close = nfcmrvl_uart_nci_close,
66 .nci_send = nfcmrvl_uart_nci_send,
67 .nci_update_config = nfcmrvl_uart_nci_update_config
72 static int nfcmrvl_uart_parse_dt(struct device_node *node,
73 struct nfcmrvl_platform_data *pdata)
75 struct device_node *matched_node;
78 matched_node = of_find_compatible_node(node, NULL, "marvell,nfc-uart");
80 matched_node = of_find_compatible_node(node, NULL,
86 ret = nfcmrvl_parse_dt(matched_node, pdata);
88 pr_err("Failed to get generic entries\n");
92 if (of_find_property(matched_node, "flow-control", NULL))
93 pdata->flow_control = 1;
95 pdata->flow_control = 0;
97 if (of_find_property(matched_node, "break-control", NULL))
98 pdata->break_control = 1;
100 pdata->break_control = 0;
107 static int nfcmrvl_uart_parse_dt(struct device_node *node,
108 struct nfcmrvl_platform_data *pdata)
119 static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
121 struct nfcmrvl_private *priv;
122 struct nfcmrvl_platform_data *pdata = NULL;
123 struct nfcmrvl_platform_data config;
126 * Platform data cannot be used here since usually it is already used
127 * by low level serial driver. We can try to retrieve serial device
128 * and check if DT entries were added.
131 if (nu->tty->dev->parent && nu->tty->dev->parent->of_node)
132 if (nfcmrvl_uart_parse_dt(nu->tty->dev->parent->of_node,
137 pr_info("No platform data / DT -> fallback to module params\n");
138 config.hci_muxed = hci_muxed;
139 config.reset_n_io = reset_n_io;
140 config.flow_control = flow_control;
141 config.break_control = break_control;
145 priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_UART, nu, &uart_ops,
146 nu->tty->dev, pdata);
148 return PTR_ERR(priv);
150 priv->support_fw_dnld = true;
153 nu->ndev = priv->ndev;
156 if (priv->config.break_control && nu->tty->ops->break_ctl)
157 nu->tty->ops->break_ctl(nu->tty, -1);
162 static void nfcmrvl_nci_uart_close(struct nci_uart *nu)
164 nfcmrvl_nci_unregister_dev((struct nfcmrvl_private *)nu->drv_data);
167 static int nfcmrvl_nci_uart_recv(struct nci_uart *nu, struct sk_buff *skb)
169 return nfcmrvl_nci_recv_frame((struct nfcmrvl_private *)nu->drv_data,
173 static void nfcmrvl_nci_uart_tx_start(struct nci_uart *nu)
175 struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
177 /* Remove BREAK to wake up the NFCC */
178 if (priv->config.break_control && nu->tty->ops->break_ctl) {
179 nu->tty->ops->break_ctl(nu->tty, 0);
180 usleep_range(3000, 5000);
184 static void nfcmrvl_nci_uart_tx_done(struct nci_uart *nu)
186 struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
189 ** To ensure that if the NFCC goes in DEEP SLEEP sate we can wake him
190 ** up. we set BREAK. Once we will be ready to send again we will remove
193 if (priv->config.break_control && nu->tty->ops->break_ctl)
194 nu->tty->ops->break_ctl(nu->tty, -1);
197 static struct nci_uart nfcmrvl_nci_uart = {
198 .owner = THIS_MODULE,
199 .name = "nfcmrvl_uart",
200 .driver = NCI_UART_DRIVER_MARVELL,
202 .open = nfcmrvl_nci_uart_open,
203 .close = nfcmrvl_nci_uart_close,
204 .recv = nfcmrvl_nci_uart_recv,
205 .tx_start = nfcmrvl_nci_uart_tx_start,
206 .tx_done = nfcmrvl_nci_uart_tx_done,
214 static int nfcmrvl_uart_init_module(void)
216 return nci_uart_register(&nfcmrvl_nci_uart);
219 static void nfcmrvl_uart_exit_module(void)
221 nci_uart_unregister(&nfcmrvl_nci_uart);
224 module_init(nfcmrvl_uart_init_module);
225 module_exit(nfcmrvl_uart_exit_module);
227 MODULE_AUTHOR("Marvell International Ltd.");
228 MODULE_DESCRIPTION("Marvell NFC-over-UART");
229 MODULE_LICENSE("GPL v2");
231 module_param(flow_control, uint, 0);
232 MODULE_PARM_DESC(flow_control, "Tell if UART needs flow control at init.");
234 module_param(break_control, uint, 0);
235 MODULE_PARM_DESC(break_control, "Tell if UART driver must drive break signal.");
237 module_param(hci_muxed, uint, 0);
238 MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one.");
240 module_param(reset_n_io, uint, 0);
241 MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");