forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/nfc/pn533/usb.c
....@@ -1,21 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for NXP PN533 NFC Chip - USB transport layer
34 *
45 * Copyright (C) 2011 Instituto Nokia de Tecnologia
56 * 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/>.
197 */
208
219 #include <linux/device.h>
....@@ -165,10 +153,17 @@
165153 return usb_submit_urb(phy->ack_urb, flags);
166154 }
167155
156
+struct pn533_out_arg {
157
+ struct pn533_usb_phy *phy;
158
+ struct completion done;
159
+};
160
+
168161 static int pn533_usb_send_frame(struct pn533 *dev,
169162 struct sk_buff *out)
170163 {
171164 struct pn533_usb_phy *phy = dev->phy;
165
+ struct pn533_out_arg arg;
166
+ void *cntx;
172167 int rc;
173168
174169 if (phy->priv == NULL)
....@@ -180,9 +175,17 @@
180175 print_hex_dump_debug("PN533 TX: ", DUMP_PREFIX_NONE, 16, 1,
181176 out->data, out->len, false);
182177
178
+ arg.phy = phy;
179
+ init_completion(&arg.done);
180
+ cntx = phy->out_urb->context;
181
+ phy->out_urb->context = &arg;
182
+
183183 rc = usb_submit_urb(phy->out_urb, GFP_KERNEL);
184184 if (rc)
185185 return rc;
186
+
187
+ wait_for_completion(&arg.done);
188
+ phy->out_urb->context = cntx;
186189
187190 if (dev->protocol_type == PN533_PROTO_REQ_RESP) {
188191 /* request for response for sent packet directly */
....@@ -222,7 +225,7 @@
222225 usb_kill_urb(phy->in_urb);
223226 }
224227
225
-/* ACR122 specific structs and fucntions */
228
+/* ACR122 specific structs and functions */
226229
227230 /* ACS ACR122 pn533 frame definitions */
228231 #define PN533_ACR122_TX_FRAME_HEADER_LEN (sizeof(struct pn533_acr122_tx_frame) \
....@@ -424,7 +427,31 @@
424427 return arg.rc;
425428 }
426429
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)
428455 {
429456 struct pn533_usb_phy *phy = urb->context;
430457
....@@ -512,10 +539,10 @@
512539
513540 usb_fill_bulk_urb(phy->out_urb, phy->udev,
514541 usb_sndbulkpipe(phy->udev, out_endpoint),
515
- NULL, 0, pn533_send_complete, phy);
542
+ NULL, 0, pn533_out_complete, phy);
516543 usb_fill_bulk_urb(phy->ack_urb, phy->udev,
517544 usb_sndbulkpipe(phy->udev, out_endpoint),
518
- NULL, 0, pn533_send_complete, phy);
545
+ NULL, 0, pn533_ack_complete, phy);
519546
520547 switch (id->driver_info) {
521548 case PN533_DEVICE_STD:
....@@ -546,9 +573,9 @@
546573 goto error;
547574 }
548575
549
- priv = pn533_register_device(id->driver_info, protocols, protocol_type,
576
+ priv = pn53x_common_init(id->driver_info, protocol_type,
550577 phy, &usb_phy_ops, fops,
551
- &phy->udev->dev, &interface->dev);
578
+ &phy->udev->dev);
552579
553580 if (IS_ERR(priv)) {
554581 rc = PTR_ERR(priv);
....@@ -559,14 +586,17 @@
559586
560587 rc = pn533_finalize_setup(priv);
561588 if (rc)
562
- goto err_deregister;
589
+ goto err_clean;
563590
564591 usb_set_intfdata(interface, phy);
592
+ rc = pn53x_register_nfc(priv, protocols, &interface->dev);
593
+ if (rc)
594
+ goto err_clean;
565595
566596 return 0;
567597
568
-err_deregister:
569
- pn533_unregister_device(phy->priv);
598
+err_clean:
599
+ pn53x_common_clean(priv);
570600 error:
571601 usb_kill_urb(phy->in_urb);
572602 usb_kill_urb(phy->out_urb);
....@@ -589,7 +619,8 @@
589619 if (!phy)
590620 return;
591621
592
- pn533_unregister_device(phy->priv);
622
+ pn53x_unregister_nfc(phy->priv);
623
+ pn53x_common_clean(phy->priv);
593624
594625 usb_set_intfdata(interface, NULL);
595626