1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* ------------------------------------------------------------------------- 3 * Copyright (C) 2014-2016, Intel Corporation 4 * 5 * ------------------------------------------------------------------------- 6 */ 7 8 #include <linux/module.h> 9 #include <linux/nfc.h> 10 #include <linux/i2c.h> 11 #include <linux/delay.h> 12 #include <linux/firmware.h> 13 #include <net/nfc/nci_core.h> 14 15 #include "fdp.h" 16 17 #define FDP_OTP_PATCH_NAME "otp.bin" 18 #define FDP_RAM_PATCH_NAME "ram.bin" 19 #define FDP_FW_HEADER_SIZE 576 20 #define FDP_FW_UPDATE_SLEEP 1000 21 22 #define NCI_GET_VERSION_TIMEOUT 8000 23 #define NCI_PATCH_REQUEST_TIMEOUT 8000 24 #define FDP_PATCH_CONN_DEST 0xC2 25 #define FDP_PATCH_CONN_PARAM_TYPE 0xA0 26 27 #define NCI_PATCH_TYPE_RAM 0x00 28 #define NCI_PATCH_TYPE_OTP 0x01 29 #define NCI_PATCH_TYPE_EOT 0xFF 30 31 #define NCI_PARAM_ID_FW_RAM_VERSION 0xA0 32 #define NCI_PARAM_ID_FW_OTP_VERSION 0xA1 33 #define NCI_PARAM_ID_OTP_LIMITED_VERSION 0xC5 34 #define NCI_PARAM_ID_KEY_INDEX_ID 0xC6 35 36 #define NCI_GID_PROP 0x0F 37 #define NCI_OP_PROP_PATCH_OID 0x08 38 #define NCI_OP_PROP_SET_PDATA_OID 0x23 39 40 struct fdp_nci_info { 41 struct nfc_phy_ops *phy_ops; 42 struct fdp_i2c_phy *phy; 43 struct nci_dev *ndev; 44 45 const struct firmware *otp_patch; 46 const struct firmware *ram_patch; 47 u32 otp_patch_version; 48 u32 ram_patch_version; 49 50 u32 otp_version; 51 u32 ram_version; 52 u32 limited_otp_version; 53 u8 key_index; 54 55 u8 *fw_vsc_cfg; 56 u8 clock_type; 57 u32 clock_freq; 58 59 atomic_t data_pkt_counter; 60 void (*data_pkt_counter_cb)(struct nci_dev *ndev); 61 u8 setup_patch_sent; 62 u8 setup_patch_ntf; 63 u8 setup_patch_status; 64 u8 setup_reset_ntf; 65 wait_queue_head_t setup_wq; 66 }; 67 68 static u8 nci_core_get_config_otp_ram_version[5] = { 69 0x04, 70 NCI_PARAM_ID_FW_RAM_VERSION, 71 NCI_PARAM_ID_FW_OTP_VERSION, 72 NCI_PARAM_ID_OTP_LIMITED_VERSION, 73 NCI_PARAM_ID_KEY_INDEX_ID 74 }; 75 76 struct nci_core_get_config_rsp { 77 u8 status; 78 u8 count; 79 u8 data[]; 80 }; 81 82 static int fdp_nci_create_conn(struct nci_dev *ndev) 83 { 84 struct fdp_nci_info *info = nci_get_drvdata(ndev); 85 struct core_conn_create_dest_spec_params param; 86 int r; 87 88 /* proprietary destination specific paramerer without value */ 89 param.type = FDP_PATCH_CONN_PARAM_TYPE; 90 param.length = 0x00; 91 92 r = nci_core_conn_create(info->ndev, FDP_PATCH_CONN_DEST, 1, 93 sizeof(param), ¶m); 94 if (r) 95 return r; 96 97 return nci_get_conn_info_by_dest_type_params(ndev, 98 FDP_PATCH_CONN_DEST, NULL); 99 } 100 101 static inline int fdp_nci_get_versions(struct nci_dev *ndev) 102 { 103 return nci_core_cmd(ndev, NCI_OP_CORE_GET_CONFIG_CMD, 104 sizeof(nci_core_get_config_otp_ram_version), 105 (__u8 *) &nci_core_get_config_otp_ram_version); 106 } 107 108 static inline int fdp_nci_patch_cmd(struct nci_dev *ndev, u8 type) 109 { 110 return nci_prop_cmd(ndev, NCI_OP_PROP_PATCH_OID, sizeof(type), &type); 111 } 112 113 static inline int fdp_nci_set_production_data(struct nci_dev *ndev, u8 len, 114 char *data) 115 { 116 return nci_prop_cmd(ndev, NCI_OP_PROP_SET_PDATA_OID, len, data); 117 } 118 119 static int fdp_nci_set_clock(struct nci_dev *ndev, u8 clock_type, 120 u32 clock_freq) 121 { 122 u32 fc = 13560; 123 u32 nd, num, delta; 124 char data[9]; 125 126 nd = (24 * fc) / clock_freq; 127 delta = 24 * fc - nd * clock_freq; 128 num = (32768 * delta) / clock_freq; 129 130 data[0] = 0x00; 131 data[1] = 0x00; 132 data[2] = 0x00; 133 134 data[3] = 0x10; 135 data[4] = 0x04; 136 data[5] = num & 0xFF; 137 data[6] = (num >> 8) & 0xff; 138 data[7] = nd; 139 data[8] = clock_type; 140 141 return fdp_nci_set_production_data(ndev, 9, data); 142 } 143 144 static void fdp_nci_send_patch_cb(struct nci_dev *ndev) 145 { 146 struct fdp_nci_info *info = nci_get_drvdata(ndev); 147 148 info->setup_patch_sent = 1; 149 wake_up(&info->setup_wq); 150 } 151 152 /* 153 * Register a packet sent counter and a callback 154 * 155 * We have no other way of knowing when all firmware packets were sent out 156 * on the i2c bus. We need to know that in order to close the connection and 157 * send the patch end message. 158 */ 159 static void fdp_nci_set_data_pkt_counter(struct nci_dev *ndev, 160 void (*cb)(struct nci_dev *ndev), int count) 161 { 162 struct fdp_nci_info *info = nci_get_drvdata(ndev); 163 struct device *dev = &info->phy->i2c_dev->dev; 164 165 dev_dbg(dev, "NCI data pkt counter %d\n", count); 166 atomic_set(&info->data_pkt_counter, count); 167 info->data_pkt_counter_cb = cb; 168 } 169 170 /* 171 * The device is expecting a stream of packets. All packets need to 172 * have the PBF flag set to 0x0 (last packet) even if the firmware 173 * file is segmented and there are multiple packets. If we give the 174 * whole firmware to nci_send_data it will segment it and it will set 175 * the PBF flag to 0x01 so we need to do the segmentation here. 176 * 177 * The firmware will be analyzed and applied when we send NCI_OP_PROP_PATCH_CMD 178 * command with NCI_PATCH_TYPE_EOT parameter. The device will send a 179 * NFCC_PATCH_NTF packet and a NCI_OP_CORE_RESET_NTF packet. 180 */ 181 static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type) 182 { 183 struct fdp_nci_info *info = nci_get_drvdata(ndev); 184 const struct firmware *fw; 185 struct sk_buff *skb; 186 unsigned long len; 187 int max_size, payload_size; 188 int rc = 0; 189 190 if ((type == NCI_PATCH_TYPE_OTP && !info->otp_patch) || 191 (type == NCI_PATCH_TYPE_RAM && !info->ram_patch)) 192 return -EINVAL; 193 194 if (type == NCI_PATCH_TYPE_OTP) 195 fw = info->otp_patch; 196 else 197 fw = info->ram_patch; 198 199 max_size = nci_conn_max_data_pkt_payload_size(ndev, conn_id); 200 if (max_size <= 0) 201 return -EINVAL; 202 203 len = fw->size; 204 205 fdp_nci_set_data_pkt_counter(ndev, fdp_nci_send_patch_cb, 206 DIV_ROUND_UP(fw->size, max_size)); 207 208 while (len) { 209 210 payload_size = min_t(unsigned long, max_size, len); 211 212 skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + payload_size), 213 GFP_KERNEL); 214 if (!skb) { 215 fdp_nci_set_data_pkt_counter(ndev, NULL, 0); 216 return -ENOMEM; 217 } 218 219 220 skb_reserve(skb, NCI_CTRL_HDR_SIZE); 221 222 skb_put_data(skb, fw->data + (fw->size - len), payload_size); 223 224 rc = nci_send_data(ndev, conn_id, skb); 225 226 if (rc) { 227 fdp_nci_set_data_pkt_counter(ndev, NULL, 0); 228 return rc; 229 } 230 231 len -= payload_size; 232 } 233 234 return rc; 235 } 236 237 static int fdp_nci_open(struct nci_dev *ndev) 238 { 239 struct fdp_nci_info *info = nci_get_drvdata(ndev); 240 241 return info->phy_ops->enable(info->phy); 242 } 243 244 static int fdp_nci_close(struct nci_dev *ndev) 245 { 246 return 0; 247 } 248 249 static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb) 250 { 251 struct fdp_nci_info *info = nci_get_drvdata(ndev); 252 253 if (atomic_dec_and_test(&info->data_pkt_counter)) 254 info->data_pkt_counter_cb(ndev); 255 256 return info->phy_ops->write(info->phy, skb); 257 } 258 259 static int fdp_nci_request_firmware(struct nci_dev *ndev) 260 { 261 struct fdp_nci_info *info = nci_get_drvdata(ndev); 262 struct device *dev = &info->phy->i2c_dev->dev; 263 u8 *data; 264 int r; 265 266 r = request_firmware(&info->ram_patch, FDP_RAM_PATCH_NAME, dev); 267 if (r < 0) { 268 nfc_err(dev, "RAM patch request error\n"); 269 goto error; 270 } 271 272 data = (u8 *) info->ram_patch->data; 273 info->ram_patch_version = 274 data[FDP_FW_HEADER_SIZE] | 275 (data[FDP_FW_HEADER_SIZE + 1] << 8) | 276 (data[FDP_FW_HEADER_SIZE + 2] << 16) | 277 (data[FDP_FW_HEADER_SIZE + 3] << 24); 278 279 dev_dbg(dev, "RAM patch version: %d, size: %d\n", 280 info->ram_patch_version, (int) info->ram_patch->size); 281 282 283 r = request_firmware(&info->otp_patch, FDP_OTP_PATCH_NAME, dev); 284 if (r < 0) { 285 nfc_err(dev, "OTP patch request error\n"); 286 goto out; 287 } 288 289 data = (u8 *) info->otp_patch->data; 290 info->otp_patch_version = 291 data[FDP_FW_HEADER_SIZE] | 292 (data[FDP_FW_HEADER_SIZE + 1] << 8) | 293 (data[FDP_FW_HEADER_SIZE+2] << 16) | 294 (data[FDP_FW_HEADER_SIZE+3] << 24); 295 296 dev_dbg(dev, "OTP patch version: %d, size: %d\n", 297 info->otp_patch_version, (int) info->otp_patch->size); 298 out: 299 return 0; 300 error: 301 return r; 302 } 303 304 static void fdp_nci_release_firmware(struct nci_dev *ndev) 305 { 306 struct fdp_nci_info *info = nci_get_drvdata(ndev); 307 308 if (info->otp_patch) { 309 release_firmware(info->otp_patch); 310 info->otp_patch = NULL; 311 } 312 313 if (info->ram_patch) { 314 release_firmware(info->ram_patch); 315 info->ram_patch = NULL; 316 } 317 } 318 319 static int fdp_nci_patch_otp(struct nci_dev *ndev) 320 { 321 struct fdp_nci_info *info = nci_get_drvdata(ndev); 322 struct device *dev = &info->phy->i2c_dev->dev; 323 int conn_id; 324 int r = 0; 325 326 if (info->otp_version >= info->otp_patch_version) 327 return r; 328 329 info->setup_patch_sent = 0; 330 info->setup_reset_ntf = 0; 331 info->setup_patch_ntf = 0; 332 333 /* Patch init request */ 334 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_OTP); 335 if (r) 336 return r; 337 338 /* Patch data connection creation */ 339 conn_id = fdp_nci_create_conn(ndev); 340 if (conn_id < 0) 341 return conn_id; 342 343 /* Send the patch over the data connection */ 344 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_OTP); 345 if (r) 346 return r; 347 348 /* Wait for all the packets to be send over i2c */ 349 wait_event_interruptible(info->setup_wq, 350 info->setup_patch_sent == 1); 351 352 /* make sure that the NFCC processed the last data packet */ 353 msleep(FDP_FW_UPDATE_SLEEP); 354 355 /* Close the data connection */ 356 r = nci_core_conn_close(info->ndev, conn_id); 357 if (r) 358 return r; 359 360 /* Patch finish message */ 361 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { 362 nfc_err(dev, "OTP patch error 0x%x\n", r); 363 return -EINVAL; 364 } 365 366 /* If the patch notification didn't arrive yet, wait for it */ 367 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf); 368 369 /* Check if the patching was successful */ 370 r = info->setup_patch_status; 371 if (r) { 372 nfc_err(dev, "OTP patch error 0x%x\n", r); 373 return -EINVAL; 374 } 375 376 /* 377 * We need to wait for the reset notification before we 378 * can continue 379 */ 380 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); 381 382 return r; 383 } 384 385 static int fdp_nci_patch_ram(struct nci_dev *ndev) 386 { 387 struct fdp_nci_info *info = nci_get_drvdata(ndev); 388 struct device *dev = &info->phy->i2c_dev->dev; 389 int conn_id; 390 int r = 0; 391 392 if (info->ram_version >= info->ram_patch_version) 393 return r; 394 395 info->setup_patch_sent = 0; 396 info->setup_reset_ntf = 0; 397 info->setup_patch_ntf = 0; 398 399 /* Patch init request */ 400 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_RAM); 401 if (r) 402 return r; 403 404 /* Patch data connection creation */ 405 conn_id = fdp_nci_create_conn(ndev); 406 if (conn_id < 0) 407 return conn_id; 408 409 /* Send the patch over the data connection */ 410 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_RAM); 411 if (r) 412 return r; 413 414 /* Wait for all the packets to be send over i2c */ 415 wait_event_interruptible(info->setup_wq, 416 info->setup_patch_sent == 1); 417 418 /* make sure that the NFCC processed the last data packet */ 419 msleep(FDP_FW_UPDATE_SLEEP); 420 421 /* Close the data connection */ 422 r = nci_core_conn_close(info->ndev, conn_id); 423 if (r) 424 return r; 425 426 /* Patch finish message */ 427 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { 428 nfc_err(dev, "RAM patch error 0x%x\n", r); 429 return -EINVAL; 430 } 431 432 /* If the patch notification didn't arrive yet, wait for it */ 433 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf); 434 435 /* Check if the patching was successful */ 436 r = info->setup_patch_status; 437 if (r) { 438 nfc_err(dev, "RAM patch error 0x%x\n", r); 439 return -EINVAL; 440 } 441 442 /* 443 * We need to wait for the reset notification before we 444 * can continue 445 */ 446 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); 447 448 return r; 449 } 450 451 static int fdp_nci_setup(struct nci_dev *ndev) 452 { 453 /* Format: total length followed by an NCI packet */ 454 struct fdp_nci_info *info = nci_get_drvdata(ndev); 455 struct device *dev = &info->phy->i2c_dev->dev; 456 int r; 457 u8 patched = 0; 458 459 r = nci_core_init(ndev); 460 if (r) 461 goto error; 462 463 /* Get RAM and OTP version */ 464 r = fdp_nci_get_versions(ndev); 465 if (r) 466 goto error; 467 468 /* Load firmware from disk */ 469 r = fdp_nci_request_firmware(ndev); 470 if (r) 471 goto error; 472 473 /* Update OTP */ 474 if (info->otp_version < info->otp_patch_version) { 475 r = fdp_nci_patch_otp(ndev); 476 if (r) 477 goto error; 478 patched = 1; 479 } 480 481 /* Update RAM */ 482 if (info->ram_version < info->ram_patch_version) { 483 r = fdp_nci_patch_ram(ndev); 484 if (r) 485 goto error; 486 patched = 1; 487 } 488 489 /* Release the firmware buffers */ 490 fdp_nci_release_firmware(ndev); 491 492 /* If a patch was applied the new version is checked */ 493 if (patched) { 494 r = nci_core_init(ndev); 495 if (r) 496 goto error; 497 498 r = fdp_nci_get_versions(ndev); 499 if (r) 500 goto error; 501 502 if (info->otp_version != info->otp_patch_version || 503 info->ram_version != info->ram_patch_version) { 504 nfc_err(dev, "Firmware update failed"); 505 r = -EINVAL; 506 goto error; 507 } 508 } 509 510 /* 511 * We initialized the devices but the NFC subsystem expects 512 * it to not be initialized. 513 */ 514 return nci_core_reset(ndev); 515 516 error: 517 fdp_nci_release_firmware(ndev); 518 nfc_err(dev, "Setup error %d\n", r); 519 return r; 520 } 521 522 static int fdp_nci_post_setup(struct nci_dev *ndev) 523 { 524 struct fdp_nci_info *info = nci_get_drvdata(ndev); 525 struct device *dev = &info->phy->i2c_dev->dev; 526 int r; 527 528 /* Check if the device has VSC */ 529 if (info->fw_vsc_cfg && info->fw_vsc_cfg[0]) { 530 531 /* Set the vendor specific configuration */ 532 r = fdp_nci_set_production_data(ndev, info->fw_vsc_cfg[3], 533 &info->fw_vsc_cfg[4]); 534 if (r) { 535 nfc_err(dev, "Vendor specific config set error %d\n", 536 r); 537 return r; 538 } 539 } 540 541 /* Set clock type and frequency */ 542 r = fdp_nci_set_clock(ndev, info->clock_type, info->clock_freq); 543 if (r) { 544 nfc_err(dev, "Clock set error %d\n", r); 545 return r; 546 } 547 548 /* 549 * In order to apply the VSC FDP needs a reset 550 */ 551 r = nci_core_reset(ndev); 552 if (r) 553 return r; 554 555 /** 556 * The nci core was initialized when post setup was called 557 * so we leave it like that 558 */ 559 return nci_core_init(ndev); 560 } 561 562 static int fdp_nci_core_reset_ntf_packet(struct nci_dev *ndev, 563 struct sk_buff *skb) 564 { 565 struct fdp_nci_info *info = nci_get_drvdata(ndev); 566 567 info->setup_reset_ntf = 1; 568 wake_up(&info->setup_wq); 569 570 return 0; 571 } 572 573 static int fdp_nci_prop_patch_ntf_packet(struct nci_dev *ndev, 574 struct sk_buff *skb) 575 { 576 struct fdp_nci_info *info = nci_get_drvdata(ndev); 577 578 info->setup_patch_ntf = 1; 579 info->setup_patch_status = skb->data[0]; 580 wake_up(&info->setup_wq); 581 582 return 0; 583 } 584 585 static int fdp_nci_prop_patch_rsp_packet(struct nci_dev *ndev, 586 struct sk_buff *skb) 587 { 588 struct fdp_nci_info *info = nci_get_drvdata(ndev); 589 struct device *dev = &info->phy->i2c_dev->dev; 590 u8 status = skb->data[0]; 591 592 dev_dbg(dev, "%s: status 0x%x\n", __func__, status); 593 nci_req_complete(ndev, status); 594 595 return 0; 596 } 597 598 static int fdp_nci_prop_set_production_data_rsp_packet(struct nci_dev *ndev, 599 struct sk_buff *skb) 600 { 601 struct fdp_nci_info *info = nci_get_drvdata(ndev); 602 struct device *dev = &info->phy->i2c_dev->dev; 603 u8 status = skb->data[0]; 604 605 dev_dbg(dev, "%s: status 0x%x\n", __func__, status); 606 nci_req_complete(ndev, status); 607 608 return 0; 609 } 610 611 static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev, 612 struct sk_buff *skb) 613 { 614 struct fdp_nci_info *info = nci_get_drvdata(ndev); 615 struct device *dev = &info->phy->i2c_dev->dev; 616 struct nci_core_get_config_rsp *rsp = (void *) skb->data; 617 u8 i, *p; 618 619 if (rsp->status == NCI_STATUS_OK) { 620 621 p = rsp->data; 622 for (i = 0; i < 4; i++) { 623 624 switch (*p++) { 625 case NCI_PARAM_ID_FW_RAM_VERSION: 626 p++; 627 info->ram_version = le32_to_cpup((__le32 *) p); 628 p += 4; 629 break; 630 case NCI_PARAM_ID_FW_OTP_VERSION: 631 p++; 632 info->otp_version = le32_to_cpup((__le32 *) p); 633 p += 4; 634 break; 635 case NCI_PARAM_ID_OTP_LIMITED_VERSION: 636 p++; 637 info->otp_version = le32_to_cpup((__le32 *) p); 638 p += 4; 639 break; 640 case NCI_PARAM_ID_KEY_INDEX_ID: 641 p++; 642 info->key_index = *p++; 643 } 644 } 645 } 646 647 dev_dbg(dev, "OTP version %d\n", info->otp_version); 648 dev_dbg(dev, "RAM version %d\n", info->ram_version); 649 dev_dbg(dev, "key index %d\n", info->key_index); 650 dev_dbg(dev, "%s: status 0x%x\n", __func__, rsp->status); 651 652 nci_req_complete(ndev, rsp->status); 653 654 return 0; 655 } 656 657 static struct nci_driver_ops fdp_core_ops[] = { 658 { 659 .opcode = NCI_OP_CORE_GET_CONFIG_RSP, 660 .rsp = fdp_nci_core_get_config_rsp_packet, 661 }, 662 { 663 .opcode = NCI_OP_CORE_RESET_NTF, 664 .ntf = fdp_nci_core_reset_ntf_packet, 665 }, 666 }; 667 668 static struct nci_driver_ops fdp_prop_ops[] = { 669 { 670 .opcode = nci_opcode_pack(NCI_GID_PROP, NCI_OP_PROP_PATCH_OID), 671 .rsp = fdp_nci_prop_patch_rsp_packet, 672 .ntf = fdp_nci_prop_patch_ntf_packet, 673 }, 674 { 675 .opcode = nci_opcode_pack(NCI_GID_PROP, 676 NCI_OP_PROP_SET_PDATA_OID), 677 .rsp = fdp_nci_prop_set_production_data_rsp_packet, 678 }, 679 }; 680 681 static struct nci_ops nci_ops = { 682 .open = fdp_nci_open, 683 .close = fdp_nci_close, 684 .send = fdp_nci_send, 685 .setup = fdp_nci_setup, 686 .post_setup = fdp_nci_post_setup, 687 .prop_ops = fdp_prop_ops, 688 .n_prop_ops = ARRAY_SIZE(fdp_prop_ops), 689 .core_ops = fdp_core_ops, 690 .n_core_ops = ARRAY_SIZE(fdp_core_ops), 691 }; 692 693 int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, 694 struct nci_dev **ndevp, int tx_headroom, 695 int tx_tailroom, u8 clock_type, u32 clock_freq, 696 u8 *fw_vsc_cfg) 697 { 698 struct device *dev = &phy->i2c_dev->dev; 699 struct fdp_nci_info *info; 700 struct nci_dev *ndev; 701 u32 protocols; 702 int r; 703 704 info = devm_kzalloc(dev, sizeof(struct fdp_nci_info), GFP_KERNEL); 705 if (!info) 706 return -ENOMEM; 707 708 info->phy = phy; 709 info->phy_ops = phy_ops; 710 info->clock_type = clock_type; 711 info->clock_freq = clock_freq; 712 info->fw_vsc_cfg = fw_vsc_cfg; 713 714 init_waitqueue_head(&info->setup_wq); 715 716 protocols = NFC_PROTO_JEWEL_MASK | 717 NFC_PROTO_MIFARE_MASK | 718 NFC_PROTO_FELICA_MASK | 719 NFC_PROTO_ISO14443_MASK | 720 NFC_PROTO_ISO14443_B_MASK | 721 NFC_PROTO_NFC_DEP_MASK | 722 NFC_PROTO_ISO15693_MASK; 723 724 ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom, 725 tx_tailroom); 726 if (!ndev) { 727 nfc_err(dev, "Cannot allocate nfc ndev\n"); 728 return -ENOMEM; 729 } 730 731 r = nci_register_device(ndev); 732 if (r) 733 goto err_regdev; 734 735 *ndevp = ndev; 736 info->ndev = ndev; 737 738 nci_set_drvdata(ndev, info); 739 740 return 0; 741 742 err_regdev: 743 nci_free_device(ndev); 744 return r; 745 } 746 EXPORT_SYMBOL(fdp_nci_probe); 747 748 void fdp_nci_remove(struct nci_dev *ndev) 749 { 750 nci_unregister_device(ndev); 751 nci_free_device(ndev); 752 } 753 EXPORT_SYMBOL(fdp_nci_remove); 754 755 MODULE_LICENSE("GPL"); 756 MODULE_DESCRIPTION("NFC NCI driver for Intel Fields Peak NFC controller"); 757 MODULE_AUTHOR("Robert Dolca <robert.dolca@intel.com>"); 758