0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/delay.h>
0010 #include <linux/of_gpio.h>
0011 #include <net/nfc/nci.h>
0012 #include <net/nfc/nci_core.h>
0013 #include "nfcmrvl.h"
0014
0015 static unsigned int hci_muxed;
0016 static unsigned int flow_control;
0017 static unsigned int break_control;
0018 static int reset_n_io = -EINVAL;
0019
0020
0021
0022
0023
0024 static int nfcmrvl_uart_nci_open(struct nfcmrvl_private *priv)
0025 {
0026 return 0;
0027 }
0028
0029 static int nfcmrvl_uart_nci_close(struct nfcmrvl_private *priv)
0030 {
0031 return 0;
0032 }
0033
0034 static int nfcmrvl_uart_nci_send(struct nfcmrvl_private *priv,
0035 struct sk_buff *skb)
0036 {
0037 struct nci_uart *nu = priv->drv_data;
0038
0039 return nu->ops.send(nu, skb);
0040 }
0041
0042 static void nfcmrvl_uart_nci_update_config(struct nfcmrvl_private *priv,
0043 const void *param)
0044 {
0045 struct nci_uart *nu = priv->drv_data;
0046 const struct nfcmrvl_fw_uart_config *config = param;
0047
0048 nci_uart_set_config(nu, le32_to_cpu(config->baudrate),
0049 config->flow_control);
0050 }
0051
0052 static const struct nfcmrvl_if_ops uart_ops = {
0053 .nci_open = nfcmrvl_uart_nci_open,
0054 .nci_close = nfcmrvl_uart_nci_close,
0055 .nci_send = nfcmrvl_uart_nci_send,
0056 .nci_update_config = nfcmrvl_uart_nci_update_config
0057 };
0058
0059 static int nfcmrvl_uart_parse_dt(struct device_node *node,
0060 struct nfcmrvl_platform_data *pdata)
0061 {
0062 struct device_node *matched_node;
0063 int ret;
0064
0065 matched_node = of_get_compatible_child(node, "marvell,nfc-uart");
0066 if (!matched_node) {
0067 matched_node = of_get_compatible_child(node, "mrvl,nfc-uart");
0068 if (!matched_node)
0069 return -ENODEV;
0070 }
0071
0072 ret = nfcmrvl_parse_dt(matched_node, pdata);
0073 if (ret < 0) {
0074 pr_err("Failed to get generic entries\n");
0075 of_node_put(matched_node);
0076 return ret;
0077 }
0078
0079 if (of_find_property(matched_node, "flow-control", NULL))
0080 pdata->flow_control = 1;
0081 else
0082 pdata->flow_control = 0;
0083
0084 if (of_find_property(matched_node, "break-control", NULL))
0085 pdata->break_control = 1;
0086 else
0087 pdata->break_control = 0;
0088
0089 of_node_put(matched_node);
0090
0091 return 0;
0092 }
0093
0094
0095
0096
0097
0098 static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
0099 {
0100 struct nfcmrvl_private *priv;
0101 struct nfcmrvl_platform_data config;
0102 const struct nfcmrvl_platform_data *pdata = NULL;
0103 struct device *dev = nu->tty->dev;
0104
0105
0106
0107
0108
0109
0110
0111 if (dev && dev->parent && dev->parent->of_node)
0112 if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0)
0113 pdata = &config;
0114
0115 if (!pdata) {
0116 pr_info("No platform data / DT -> fallback to module params\n");
0117 config.hci_muxed = hci_muxed;
0118 config.reset_n_io = reset_n_io;
0119 config.flow_control = flow_control;
0120 config.break_control = break_control;
0121 pdata = &config;
0122 }
0123
0124 priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_UART, nu, &uart_ops,
0125 dev, pdata);
0126 if (IS_ERR(priv))
0127 return PTR_ERR(priv);
0128
0129 priv->support_fw_dnld = true;
0130
0131 nu->drv_data = priv;
0132 nu->ndev = priv->ndev;
0133
0134 return 0;
0135 }
0136
0137 static void nfcmrvl_nci_uart_close(struct nci_uart *nu)
0138 {
0139 nfcmrvl_nci_unregister_dev((struct nfcmrvl_private *)nu->drv_data);
0140 }
0141
0142 static int nfcmrvl_nci_uart_recv(struct nci_uart *nu, struct sk_buff *skb)
0143 {
0144 return nfcmrvl_nci_recv_frame((struct nfcmrvl_private *)nu->drv_data,
0145 skb);
0146 }
0147
0148 static void nfcmrvl_nci_uart_tx_start(struct nci_uart *nu)
0149 {
0150 struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
0151
0152 if (priv->ndev->nfc_dev->fw_download_in_progress)
0153 return;
0154
0155
0156 if (priv->config.break_control && nu->tty->ops->break_ctl) {
0157 nu->tty->ops->break_ctl(nu->tty, 0);
0158 usleep_range(3000, 5000);
0159 }
0160 }
0161
0162 static void nfcmrvl_nci_uart_tx_done(struct nci_uart *nu)
0163 {
0164 struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
0165
0166 if (priv->ndev->nfc_dev->fw_download_in_progress)
0167 return;
0168
0169
0170
0171
0172
0173
0174 if (priv->config.break_control && nu->tty->ops->break_ctl) {
0175 nu->tty->ops->break_ctl(nu->tty, -1);
0176 usleep_range(1000, 3000);
0177 }
0178 }
0179
0180 static struct nci_uart nfcmrvl_nci_uart = {
0181 .owner = THIS_MODULE,
0182 .name = "nfcmrvl_uart",
0183 .driver = NCI_UART_DRIVER_MARVELL,
0184 .ops = {
0185 .open = nfcmrvl_nci_uart_open,
0186 .close = nfcmrvl_nci_uart_close,
0187 .recv = nfcmrvl_nci_uart_recv,
0188 .tx_start = nfcmrvl_nci_uart_tx_start,
0189 .tx_done = nfcmrvl_nci_uart_tx_done,
0190 }
0191 };
0192 module_driver(nfcmrvl_nci_uart, nci_uart_register, nci_uart_unregister);
0193
0194 MODULE_AUTHOR("Marvell International Ltd.");
0195 MODULE_DESCRIPTION("Marvell NFC-over-UART");
0196 MODULE_LICENSE("GPL v2");
0197
0198 module_param(flow_control, uint, 0);
0199 MODULE_PARM_DESC(flow_control, "Tell if UART needs flow control at init.");
0200
0201 module_param(break_control, uint, 0);
0202 MODULE_PARM_DESC(break_control, "Tell if UART driver must drive break signal.");
0203
0204 module_param(hci_muxed, uint, 0);
0205 MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one.");
0206
0207 module_param(reset_n_io, int, 0);
0208 MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");