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 struct device *dev = &info->phy->i2c_dev->dev; 241 242 dev_dbg(dev, "%s\n", __func__); 243 244 return info->phy_ops->enable(info->phy); 245 } 246 247 static int fdp_nci_close(struct nci_dev *ndev) 248 { 249 struct fdp_nci_info *info = nci_get_drvdata(ndev); 250 struct device *dev = &info->phy->i2c_dev->dev; 251 252 dev_dbg(dev, "%s\n", __func__); 253 return 0; 254 } 255 256 static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb) 257 { 258 struct fdp_nci_info *info = nci_get_drvdata(ndev); 259 struct device *dev = &info->phy->i2c_dev->dev; 260 261 dev_dbg(dev, "%s\n", __func__); 262 263 if (atomic_dec_and_test(&info->data_pkt_counter)) 264 info->data_pkt_counter_cb(ndev); 265 266 return info->phy_ops->write(info->phy, skb); 267 } 268 269 int fdp_nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb) 270 { 271 struct fdp_nci_info *info = nci_get_drvdata(ndev); 272 struct device *dev = &info->phy->i2c_dev->dev; 273 274 dev_dbg(dev, "%s\n", __func__); 275 return nci_recv_frame(ndev, skb); 276 } 277 EXPORT_SYMBOL(fdp_nci_recv_frame); 278 279 static int fdp_nci_request_firmware(struct nci_dev *ndev) 280 { 281 struct fdp_nci_info *info = nci_get_drvdata(ndev); 282 struct device *dev = &info->phy->i2c_dev->dev; 283 u8 *data; 284 int r; 285 286 r = request_firmware(&info->ram_patch, FDP_RAM_PATCH_NAME, dev); 287 if (r < 0) { 288 nfc_err(dev, "RAM patch request error\n"); 289 goto error; 290 } 291 292 data = (u8 *) info->ram_patch->data; 293 info->ram_patch_version = 294 data[FDP_FW_HEADER_SIZE] | 295 (data[FDP_FW_HEADER_SIZE + 1] << 8) | 296 (data[FDP_FW_HEADER_SIZE + 2] << 16) | 297 (data[FDP_FW_HEADER_SIZE + 3] << 24); 298 299 dev_dbg(dev, "RAM patch version: %d, size: %d\n", 300 info->ram_patch_version, (int) info->ram_patch->size); 301 302 303 r = request_firmware(&info->otp_patch, FDP_OTP_PATCH_NAME, dev); 304 if (r < 0) { 305 nfc_err(dev, "OTP patch request error\n"); 306 goto out; 307 } 308 309 data = (u8 *) info->otp_patch->data; 310 info->otp_patch_version = 311 data[FDP_FW_HEADER_SIZE] | 312 (data[FDP_FW_HEADER_SIZE + 1] << 8) | 313 (data[FDP_FW_HEADER_SIZE+2] << 16) | 314 (data[FDP_FW_HEADER_SIZE+3] << 24); 315 316 dev_dbg(dev, "OTP patch version: %d, size: %d\n", 317 info->otp_patch_version, (int) info->otp_patch->size); 318 out: 319 return 0; 320 error: 321 return r; 322 } 323 324 static void fdp_nci_release_firmware(struct nci_dev *ndev) 325 { 326 struct fdp_nci_info *info = nci_get_drvdata(ndev); 327 328 if (info->otp_patch) { 329 release_firmware(info->otp_patch); 330 info->otp_patch = NULL; 331 } 332 333 if (info->ram_patch) { 334 release_firmware(info->ram_patch); 335 info->ram_patch = NULL; 336 } 337 } 338 339 static int fdp_nci_patch_otp(struct nci_dev *ndev) 340 { 341 struct fdp_nci_info *info = nci_get_drvdata(ndev); 342 struct device *dev = &info->phy->i2c_dev->dev; 343 int conn_id; 344 int r = 0; 345 346 if (info->otp_version >= info->otp_patch_version) 347 goto out; 348 349 info->setup_patch_sent = 0; 350 info->setup_reset_ntf = 0; 351 info->setup_patch_ntf = 0; 352 353 /* Patch init request */ 354 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_OTP); 355 if (r) 356 goto out; 357 358 /* Patch data connection creation */ 359 conn_id = fdp_nci_create_conn(ndev); 360 if (conn_id < 0) { 361 r = conn_id; 362 goto out; 363 } 364 365 /* Send the patch over the data connection */ 366 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_OTP); 367 if (r) 368 goto out; 369 370 /* Wait for all the packets to be send over i2c */ 371 wait_event_interruptible(info->setup_wq, 372 info->setup_patch_sent == 1); 373 374 /* make sure that the NFCC processed the last data packet */ 375 msleep(FDP_FW_UPDATE_SLEEP); 376 377 /* Close the data connection */ 378 r = nci_core_conn_close(info->ndev, conn_id); 379 if (r) 380 goto out; 381 382 /* Patch finish message */ 383 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { 384 nfc_err(dev, "OTP patch error 0x%x\n", r); 385 r = -EINVAL; 386 goto out; 387 } 388 389 /* If the patch notification didn't arrive yet, wait for it */ 390 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf); 391 392 /* Check if the patching was successful */ 393 r = info->setup_patch_status; 394 if (r) { 395 nfc_err(dev, "OTP patch error 0x%x\n", r); 396 r = -EINVAL; 397 goto out; 398 } 399 400 /* 401 * We need to wait for the reset notification before we 402 * can continue 403 */ 404 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); 405 406 out: 407 return r; 408 } 409 410 static int fdp_nci_patch_ram(struct nci_dev *ndev) 411 { 412 struct fdp_nci_info *info = nci_get_drvdata(ndev); 413 struct device *dev = &info->phy->i2c_dev->dev; 414 int conn_id; 415 int r = 0; 416 417 if (info->ram_version >= info->ram_patch_version) 418 goto out; 419 420 info->setup_patch_sent = 0; 421 info->setup_reset_ntf = 0; 422 info->setup_patch_ntf = 0; 423 424 /* Patch init request */ 425 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_RAM); 426 if (r) 427 goto out; 428 429 /* Patch data connection creation */ 430 conn_id = fdp_nci_create_conn(ndev); 431 if (conn_id < 0) { 432 r = conn_id; 433 goto out; 434 } 435 436 /* Send the patch over the data connection */ 437 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_RAM); 438 if (r) 439 goto out; 440 441 /* Wait for all the packets to be send over i2c */ 442 wait_event_interruptible(info->setup_wq, 443 info->setup_patch_sent == 1); 444 445 /* make sure that the NFCC processed the last data packet */ 446 msleep(FDP_FW_UPDATE_SLEEP); 447 448 /* Close the data connection */ 449 r = nci_core_conn_close(info->ndev, conn_id); 450 if (r) 451 goto out; 452 453 /* Patch finish message */ 454 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { 455 nfc_err(dev, "RAM patch error 0x%x\n", r); 456 r = -EINVAL; 457 goto out; 458 } 459 460 /* If the patch notification didn't arrive yet, wait for it */ 461 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf); 462 463 /* Check if the patching was successful */ 464 r = info->setup_patch_status; 465 if (r) { 466 nfc_err(dev, "RAM patch error 0x%x\n", r); 467 r = -EINVAL; 468 goto out; 469 } 470 471 /* 472 * We need to wait for the reset notification before we 473 * can continue 474 */ 475 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); 476 477 out: 478 return r; 479 } 480 481 static int fdp_nci_setup(struct nci_dev *ndev) 482 { 483 /* Format: total length followed by an NCI packet */ 484 struct fdp_nci_info *info = nci_get_drvdata(ndev); 485 struct device *dev = &info->phy->i2c_dev->dev; 486 int r; 487 u8 patched = 0; 488 489 dev_dbg(dev, "%s\n", __func__); 490 491 r = nci_core_init(ndev); 492 if (r) 493 goto error; 494 495 /* Get RAM and OTP version */ 496 r = fdp_nci_get_versions(ndev); 497 if (r) 498 goto error; 499 500 /* Load firmware from disk */ 501 r = fdp_nci_request_firmware(ndev); 502 if (r) 503 goto error; 504 505 /* Update OTP */ 506 if (info->otp_version < info->otp_patch_version) { 507 r = fdp_nci_patch_otp(ndev); 508 if (r) 509 goto error; 510 patched = 1; 511 } 512 513 /* Update RAM */ 514 if (info->ram_version < info->ram_patch_version) { 515 r = fdp_nci_patch_ram(ndev); 516 if (r) 517 goto error; 518 patched = 1; 519 } 520 521 /* Release the firmware buffers */ 522 fdp_nci_release_firmware(ndev); 523 524 /* If a patch was applied the new version is checked */ 525 if (patched) { 526 r = nci_core_init(ndev); 527 if (r) 528 goto error; 529 530 r = fdp_nci_get_versions(ndev); 531 if (r) 532 goto error; 533 534 if (info->otp_version != info->otp_patch_version || 535 info->ram_version != info->ram_patch_version) { 536 nfc_err(dev, "Firmware update failed"); 537 r = -EINVAL; 538 goto error; 539 } 540 } 541 542 /* 543 * We initialized the devices but the NFC subsystem expects 544 * it to not be initialized. 545 */ 546 return nci_core_reset(ndev); 547 548 error: 549 fdp_nci_release_firmware(ndev); 550 nfc_err(dev, "Setup error %d\n", r); 551 return r; 552 } 553 554 static int fdp_nci_post_setup(struct nci_dev *ndev) 555 { 556 struct fdp_nci_info *info = nci_get_drvdata(ndev); 557 struct device *dev = &info->phy->i2c_dev->dev; 558 int r; 559 560 /* Check if the device has VSC */ 561 if (info->fw_vsc_cfg && info->fw_vsc_cfg[0]) { 562 563 /* Set the vendor specific configuration */ 564 r = fdp_nci_set_production_data(ndev, info->fw_vsc_cfg[3], 565 &info->fw_vsc_cfg[4]); 566 if (r) { 567 nfc_err(dev, "Vendor specific config set error %d\n", 568 r); 569 return r; 570 } 571 } 572 573 /* Set clock type and frequency */ 574 r = fdp_nci_set_clock(ndev, info->clock_type, info->clock_freq); 575 if (r) { 576 nfc_err(dev, "Clock set error %d\n", r); 577 return r; 578 } 579 580 /* 581 * In order to apply the VSC FDP needs a reset 582 */ 583 r = nci_core_reset(ndev); 584 if (r) 585 return r; 586 587 /** 588 * The nci core was initialized when post setup was called 589 * so we leave it like that 590 */ 591 return nci_core_init(ndev); 592 } 593 594 static int fdp_nci_core_reset_ntf_packet(struct nci_dev *ndev, 595 struct sk_buff *skb) 596 { 597 struct fdp_nci_info *info = nci_get_drvdata(ndev); 598 struct device *dev = &info->phy->i2c_dev->dev; 599 600 dev_dbg(dev, "%s\n", __func__); 601 info->setup_reset_ntf = 1; 602 wake_up(&info->setup_wq); 603 604 return 0; 605 } 606 607 static int fdp_nci_prop_patch_ntf_packet(struct nci_dev *ndev, 608 struct sk_buff *skb) 609 { 610 struct fdp_nci_info *info = nci_get_drvdata(ndev); 611 struct device *dev = &info->phy->i2c_dev->dev; 612 613 dev_dbg(dev, "%s\n", __func__); 614 info->setup_patch_ntf = 1; 615 info->setup_patch_status = skb->data[0]; 616 wake_up(&info->setup_wq); 617 618 return 0; 619 } 620 621 static int fdp_nci_prop_patch_rsp_packet(struct nci_dev *ndev, 622 struct sk_buff *skb) 623 { 624 struct fdp_nci_info *info = nci_get_drvdata(ndev); 625 struct device *dev = &info->phy->i2c_dev->dev; 626 u8 status = skb->data[0]; 627 628 dev_dbg(dev, "%s: status 0x%x\n", __func__, status); 629 nci_req_complete(ndev, status); 630 631 return 0; 632 } 633 634 static int fdp_nci_prop_set_production_data_rsp_packet(struct nci_dev *ndev, 635 struct sk_buff *skb) 636 { 637 struct fdp_nci_info *info = nci_get_drvdata(ndev); 638 struct device *dev = &info->phy->i2c_dev->dev; 639 u8 status = skb->data[0]; 640 641 dev_dbg(dev, "%s: status 0x%x\n", __func__, status); 642 nci_req_complete(ndev, status); 643 644 return 0; 645 } 646 647 static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev, 648 struct sk_buff *skb) 649 { 650 struct fdp_nci_info *info = nci_get_drvdata(ndev); 651 struct device *dev = &info->phy->i2c_dev->dev; 652 struct nci_core_get_config_rsp *rsp = (void *) skb->data; 653 u8 i, *p; 654 655 if (rsp->status == NCI_STATUS_OK) { 656 657 p = rsp->data; 658 for (i = 0; i < 4; i++) { 659 660 switch (*p++) { 661 case NCI_PARAM_ID_FW_RAM_VERSION: 662 p++; 663 info->ram_version = le32_to_cpup((__le32 *) p); 664 p += 4; 665 break; 666 case NCI_PARAM_ID_FW_OTP_VERSION: 667 p++; 668 info->otp_version = le32_to_cpup((__le32 *) p); 669 p += 4; 670 break; 671 case NCI_PARAM_ID_OTP_LIMITED_VERSION: 672 p++; 673 info->otp_version = le32_to_cpup((__le32 *) p); 674 p += 4; 675 break; 676 case NCI_PARAM_ID_KEY_INDEX_ID: 677 p++; 678 info->key_index = *p++; 679 } 680 } 681 } 682 683 dev_dbg(dev, "OTP version %d\n", info->otp_version); 684 dev_dbg(dev, "RAM version %d\n", info->ram_version); 685 dev_dbg(dev, "key index %d\n", info->key_index); 686 dev_dbg(dev, "%s: status 0x%x\n", __func__, rsp->status); 687 688 nci_req_complete(ndev, rsp->status); 689 690 return 0; 691 } 692 693 static struct nci_driver_ops fdp_core_ops[] = { 694 { 695 .opcode = NCI_OP_CORE_GET_CONFIG_RSP, 696 .rsp = fdp_nci_core_get_config_rsp_packet, 697 }, 698 { 699 .opcode = NCI_OP_CORE_RESET_NTF, 700 .ntf = fdp_nci_core_reset_ntf_packet, 701 }, 702 }; 703 704 static struct nci_driver_ops fdp_prop_ops[] = { 705 { 706 .opcode = nci_opcode_pack(NCI_GID_PROP, NCI_OP_PROP_PATCH_OID), 707 .rsp = fdp_nci_prop_patch_rsp_packet, 708 .ntf = fdp_nci_prop_patch_ntf_packet, 709 }, 710 { 711 .opcode = nci_opcode_pack(NCI_GID_PROP, 712 NCI_OP_PROP_SET_PDATA_OID), 713 .rsp = fdp_nci_prop_set_production_data_rsp_packet, 714 }, 715 }; 716 717 static struct nci_ops nci_ops = { 718 .open = fdp_nci_open, 719 .close = fdp_nci_close, 720 .send = fdp_nci_send, 721 .setup = fdp_nci_setup, 722 .post_setup = fdp_nci_post_setup, 723 .prop_ops = fdp_prop_ops, 724 .n_prop_ops = ARRAY_SIZE(fdp_prop_ops), 725 .core_ops = fdp_core_ops, 726 .n_core_ops = ARRAY_SIZE(fdp_core_ops), 727 }; 728 729 int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, 730 struct nci_dev **ndevp, int tx_headroom, 731 int tx_tailroom, u8 clock_type, u32 clock_freq, 732 u8 *fw_vsc_cfg) 733 { 734 struct device *dev = &phy->i2c_dev->dev; 735 struct fdp_nci_info *info; 736 struct nci_dev *ndev; 737 u32 protocols; 738 int r; 739 740 info = devm_kzalloc(dev, sizeof(struct fdp_nci_info), GFP_KERNEL); 741 if (!info) 742 return -ENOMEM; 743 744 info->phy = phy; 745 info->phy_ops = phy_ops; 746 info->clock_type = clock_type; 747 info->clock_freq = clock_freq; 748 info->fw_vsc_cfg = fw_vsc_cfg; 749 750 init_waitqueue_head(&info->setup_wq); 751 752 protocols = NFC_PROTO_JEWEL_MASK | 753 NFC_PROTO_MIFARE_MASK | 754 NFC_PROTO_FELICA_MASK | 755 NFC_PROTO_ISO14443_MASK | 756 NFC_PROTO_ISO14443_B_MASK | 757 NFC_PROTO_NFC_DEP_MASK | 758 NFC_PROTO_ISO15693_MASK; 759 760 ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom, 761 tx_tailroom); 762 if (!ndev) { 763 nfc_err(dev, "Cannot allocate nfc ndev\n"); 764 return -ENOMEM; 765 } 766 767 r = nci_register_device(ndev); 768 if (r) 769 goto err_regdev; 770 771 *ndevp = ndev; 772 info->ndev = ndev; 773 774 nci_set_drvdata(ndev, info); 775 776 return 0; 777 778 err_regdev: 779 nci_free_device(ndev); 780 return r; 781 } 782 EXPORT_SYMBOL(fdp_nci_probe); 783 784 void fdp_nci_remove(struct nci_dev *ndev) 785 { 786 struct fdp_nci_info *info = nci_get_drvdata(ndev); 787 struct device *dev = &info->phy->i2c_dev->dev; 788 789 dev_dbg(dev, "%s\n", __func__); 790 791 nci_unregister_device(ndev); 792 nci_free_device(ndev); 793 } 794 EXPORT_SYMBOL(fdp_nci_remove); 795 796 MODULE_LICENSE("GPL"); 797 MODULE_DESCRIPTION("NFC NCI driver for Intel Fields Peak NFC controller"); 798 MODULE_AUTHOR("Robert Dolca <robert.dolca@intel.com>"); 799