.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for NXP PN533 NFC Chip - USB transport layer |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2011 Instituto Nokia de Tecnologia |
---|
5 | 6 | * Copyright (C) 2012-2013 Tieto Poland |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - * (at your option) any later version. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
---|
19 | 7 | */ |
---|
20 | 8 | |
---|
21 | 9 | #include <linux/device.h> |
---|
.. | .. |
---|
165 | 153 | return usb_submit_urb(phy->ack_urb, flags); |
---|
166 | 154 | } |
---|
167 | 155 | |
---|
| 156 | +struct pn533_out_arg { |
---|
| 157 | + struct pn533_usb_phy *phy; |
---|
| 158 | + struct completion done; |
---|
| 159 | +}; |
---|
| 160 | + |
---|
168 | 161 | static int pn533_usb_send_frame(struct pn533 *dev, |
---|
169 | 162 | struct sk_buff *out) |
---|
170 | 163 | { |
---|
171 | 164 | struct pn533_usb_phy *phy = dev->phy; |
---|
| 165 | + struct pn533_out_arg arg; |
---|
| 166 | + void *cntx; |
---|
172 | 167 | int rc; |
---|
173 | 168 | |
---|
174 | 169 | if (phy->priv == NULL) |
---|
.. | .. |
---|
180 | 175 | print_hex_dump_debug("PN533 TX: ", DUMP_PREFIX_NONE, 16, 1, |
---|
181 | 176 | out->data, out->len, false); |
---|
182 | 177 | |
---|
| 178 | + arg.phy = phy; |
---|
| 179 | + init_completion(&arg.done); |
---|
| 180 | + cntx = phy->out_urb->context; |
---|
| 181 | + phy->out_urb->context = &arg; |
---|
| 182 | + |
---|
183 | 183 | rc = usb_submit_urb(phy->out_urb, GFP_KERNEL); |
---|
184 | 184 | if (rc) |
---|
185 | 185 | return rc; |
---|
| 186 | + |
---|
| 187 | + wait_for_completion(&arg.done); |
---|
| 188 | + phy->out_urb->context = cntx; |
---|
186 | 189 | |
---|
187 | 190 | if (dev->protocol_type == PN533_PROTO_REQ_RESP) { |
---|
188 | 191 | /* request for response for sent packet directly */ |
---|
.. | .. |
---|
222 | 225 | usb_kill_urb(phy->in_urb); |
---|
223 | 226 | } |
---|
224 | 227 | |
---|
225 | | -/* ACR122 specific structs and fucntions */ |
---|
| 228 | +/* ACR122 specific structs and functions */ |
---|
226 | 229 | |
---|
227 | 230 | /* ACS ACR122 pn533 frame definitions */ |
---|
228 | 231 | #define PN533_ACR122_TX_FRAME_HEADER_LEN (sizeof(struct pn533_acr122_tx_frame) \ |
---|
.. | .. |
---|
424 | 427 | return arg.rc; |
---|
425 | 428 | } |
---|
426 | 429 | |
---|
427 | | -static void pn533_send_complete(struct urb *urb) |
---|
| 430 | +static void pn533_out_complete(struct urb *urb) |
---|
| 431 | +{ |
---|
| 432 | + struct pn533_out_arg *arg = urb->context; |
---|
| 433 | + struct pn533_usb_phy *phy = arg->phy; |
---|
| 434 | + |
---|
| 435 | + switch (urb->status) { |
---|
| 436 | + case 0: |
---|
| 437 | + break; /* success */ |
---|
| 438 | + case -ECONNRESET: |
---|
| 439 | + case -ENOENT: |
---|
| 440 | + dev_dbg(&phy->udev->dev, |
---|
| 441 | + "The urb has been stopped (status %d)\n", |
---|
| 442 | + urb->status); |
---|
| 443 | + break; |
---|
| 444 | + case -ESHUTDOWN: |
---|
| 445 | + default: |
---|
| 446 | + nfc_err(&phy->udev->dev, |
---|
| 447 | + "Urb failure (status %d)\n", |
---|
| 448 | + urb->status); |
---|
| 449 | + } |
---|
| 450 | + |
---|
| 451 | + complete(&arg->done); |
---|
| 452 | +} |
---|
| 453 | + |
---|
| 454 | +static void pn533_ack_complete(struct urb *urb) |
---|
428 | 455 | { |
---|
429 | 456 | struct pn533_usb_phy *phy = urb->context; |
---|
430 | 457 | |
---|
.. | .. |
---|
512 | 539 | |
---|
513 | 540 | usb_fill_bulk_urb(phy->out_urb, phy->udev, |
---|
514 | 541 | usb_sndbulkpipe(phy->udev, out_endpoint), |
---|
515 | | - NULL, 0, pn533_send_complete, phy); |
---|
| 542 | + NULL, 0, pn533_out_complete, phy); |
---|
516 | 543 | usb_fill_bulk_urb(phy->ack_urb, phy->udev, |
---|
517 | 544 | usb_sndbulkpipe(phy->udev, out_endpoint), |
---|
518 | | - NULL, 0, pn533_send_complete, phy); |
---|
| 545 | + NULL, 0, pn533_ack_complete, phy); |
---|
519 | 546 | |
---|
520 | 547 | switch (id->driver_info) { |
---|
521 | 548 | case PN533_DEVICE_STD: |
---|
.. | .. |
---|
546 | 573 | goto error; |
---|
547 | 574 | } |
---|
548 | 575 | |
---|
549 | | - priv = pn533_register_device(id->driver_info, protocols, protocol_type, |
---|
| 576 | + priv = pn53x_common_init(id->driver_info, protocol_type, |
---|
550 | 577 | phy, &usb_phy_ops, fops, |
---|
551 | | - &phy->udev->dev, &interface->dev); |
---|
| 578 | + &phy->udev->dev); |
---|
552 | 579 | |
---|
553 | 580 | if (IS_ERR(priv)) { |
---|
554 | 581 | rc = PTR_ERR(priv); |
---|
.. | .. |
---|
559 | 586 | |
---|
560 | 587 | rc = pn533_finalize_setup(priv); |
---|
561 | 588 | if (rc) |
---|
562 | | - goto err_deregister; |
---|
| 589 | + goto err_clean; |
---|
563 | 590 | |
---|
564 | 591 | usb_set_intfdata(interface, phy); |
---|
| 592 | + rc = pn53x_register_nfc(priv, protocols, &interface->dev); |
---|
| 593 | + if (rc) |
---|
| 594 | + goto err_clean; |
---|
565 | 595 | |
---|
566 | 596 | return 0; |
---|
567 | 597 | |
---|
568 | | -err_deregister: |
---|
569 | | - pn533_unregister_device(phy->priv); |
---|
| 598 | +err_clean: |
---|
| 599 | + pn53x_common_clean(priv); |
---|
570 | 600 | error: |
---|
571 | 601 | usb_kill_urb(phy->in_urb); |
---|
572 | 602 | usb_kill_urb(phy->out_urb); |
---|
.. | .. |
---|
589 | 619 | if (!phy) |
---|
590 | 620 | return; |
---|
591 | 621 | |
---|
592 | | - pn533_unregister_device(phy->priv); |
---|
| 622 | + pn53x_unregister_nfc(phy->priv); |
---|
| 623 | + pn53x_common_clean(phy->priv); |
---|
593 | 624 | |
---|
594 | 625 | usb_set_intfdata(interface, NULL); |
---|
595 | 626 | |
---|