drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / nfc / fdp / fdp.c
blob7c1eaea3b68546dccbee989786a8f563932485e0
1 /* -------------------------------------------------------------------------
2 * Copyright (C) 2014-2016, Intel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * -------------------------------------------------------------------------
16 #include <linux/module.h>
17 #include <linux/nfc.h>
18 #include <linux/i2c.h>
19 #include <linux/delay.h>
20 #include <linux/firmware.h>
21 #include <net/nfc/nci_core.h>
23 #include "fdp.h"
25 #define FDP_OTP_PATCH_NAME "otp.bin"
26 #define FDP_RAM_PATCH_NAME "ram.bin"
27 #define FDP_FW_HEADER_SIZE 576
28 #define FDP_FW_UPDATE_SLEEP 1000
30 #define NCI_GET_VERSION_TIMEOUT 8000
31 #define NCI_PATCH_REQUEST_TIMEOUT 8000
32 #define FDP_PATCH_CONN_DEST 0xC2
33 #define FDP_PATCH_CONN_PARAM_TYPE 0xA0
35 #define NCI_PATCH_TYPE_RAM 0x00
36 #define NCI_PATCH_TYPE_OTP 0x01
37 #define NCI_PATCH_TYPE_EOT 0xFF
39 #define NCI_PARAM_ID_FW_RAM_VERSION 0xA0
40 #define NCI_PARAM_ID_FW_OTP_VERSION 0xA1
41 #define NCI_PARAM_ID_OTP_LIMITED_VERSION 0xC5
42 #define NCI_PARAM_ID_KEY_INDEX_ID 0xC6
44 #define NCI_GID_PROP 0x0F
45 #define NCI_OP_PROP_PATCH_OID 0x08
46 #define NCI_OP_PROP_SET_PDATA_OID 0x23
48 struct fdp_nci_info {
49 struct nfc_phy_ops *phy_ops;
50 struct fdp_i2c_phy *phy;
51 struct nci_dev *ndev;
53 const struct firmware *otp_patch;
54 const struct firmware *ram_patch;
55 u32 otp_patch_version;
56 u32 ram_patch_version;
58 u32 otp_version;
59 u32 ram_version;
60 u32 limited_otp_version;
61 u8 key_index;
63 u8 *fw_vsc_cfg;
64 u8 clock_type;
65 u32 clock_freq;
67 atomic_t data_pkt_counter;
68 void (*data_pkt_counter_cb)(struct nci_dev *ndev);
69 u8 setup_patch_sent;
70 u8 setup_patch_ntf;
71 u8 setup_patch_status;
72 u8 setup_reset_ntf;
73 wait_queue_head_t setup_wq;
76 static u8 nci_core_get_config_otp_ram_version[5] = {
77 0x04,
78 NCI_PARAM_ID_FW_RAM_VERSION,
79 NCI_PARAM_ID_FW_OTP_VERSION,
80 NCI_PARAM_ID_OTP_LIMITED_VERSION,
81 NCI_PARAM_ID_KEY_INDEX_ID
84 struct nci_core_get_config_rsp {
85 u8 status;
86 u8 count;
87 u8 data[0];
90 static int fdp_nci_create_conn(struct nci_dev *ndev)
92 struct fdp_nci_info *info = nci_get_drvdata(ndev);
93 struct core_conn_create_dest_spec_params param;
94 int r;
96 /* proprietary destination specific paramerer without value */
97 param.type = FDP_PATCH_CONN_PARAM_TYPE;
98 param.length = 0x00;
100 r = nci_core_conn_create(info->ndev, FDP_PATCH_CONN_DEST, 1,
101 sizeof(param), &param);
102 if (r)
103 return r;
105 return nci_get_conn_info_by_dest_type_params(ndev,
106 FDP_PATCH_CONN_DEST, NULL);
109 static inline int fdp_nci_get_versions(struct nci_dev *ndev)
111 return nci_core_cmd(ndev, NCI_OP_CORE_GET_CONFIG_CMD,
112 sizeof(nci_core_get_config_otp_ram_version),
113 (__u8 *) &nci_core_get_config_otp_ram_version);
116 static inline int fdp_nci_patch_cmd(struct nci_dev *ndev, u8 type)
118 return nci_prop_cmd(ndev, NCI_OP_PROP_PATCH_OID, sizeof(type), &type);
121 static inline int fdp_nci_set_production_data(struct nci_dev *ndev, u8 len,
122 char *data)
124 return nci_prop_cmd(ndev, NCI_OP_PROP_SET_PDATA_OID, len, data);
127 static int fdp_nci_set_clock(struct nci_dev *ndev, u8 clock_type,
128 u32 clock_freq)
130 u32 fc = 13560;
131 u32 nd, num, delta;
132 char data[9];
134 nd = (24 * fc) / clock_freq;
135 delta = 24 * fc - nd * clock_freq;
136 num = (32768 * delta) / clock_freq;
138 data[0] = 0x00;
139 data[1] = 0x00;
140 data[2] = 0x00;
142 data[3] = 0x10;
143 data[4] = 0x04;
144 data[5] = num & 0xFF;
145 data[6] = (num >> 8) & 0xff;
146 data[7] = nd;
147 data[8] = clock_type;
149 return fdp_nci_set_production_data(ndev, 9, data);
152 static void fdp_nci_send_patch_cb(struct nci_dev *ndev)
154 struct fdp_nci_info *info = nci_get_drvdata(ndev);
156 info->setup_patch_sent = 1;
157 wake_up(&info->setup_wq);
161 * Register a packet sent counter and a callback
163 * We have no other way of knowing when all firmware packets were sent out
164 * on the i2c bus. We need to know that in order to close the connection and
165 * send the patch end message.
167 static void fdp_nci_set_data_pkt_counter(struct nci_dev *ndev,
168 void (*cb)(struct nci_dev *ndev), int count)
170 struct fdp_nci_info *info = nci_get_drvdata(ndev);
171 struct device *dev = &info->phy->i2c_dev->dev;
173 dev_dbg(dev, "NCI data pkt counter %d\n", count);
174 atomic_set(&info->data_pkt_counter, count);
175 info->data_pkt_counter_cb = cb;
179 * The device is expecting a stream of packets. All packets need to
180 * have the PBF flag set to 0x0 (last packet) even if the firmware
181 * file is segmented and there are multiple packets. If we give the
182 * whole firmware to nci_send_data it will segment it and it will set
183 * the PBF flag to 0x01 so we need to do the segmentation here.
185 * The firmware will be analyzed and applied when we send NCI_OP_PROP_PATCH_CMD
186 * command with NCI_PATCH_TYPE_EOT parameter. The device will send a
187 * NFCC_PATCH_NTF packaet and a NCI_OP_CORE_RESET_NTF packet.
189 static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type)
191 struct fdp_nci_info *info = nci_get_drvdata(ndev);
192 const struct firmware *fw;
193 struct sk_buff *skb;
194 unsigned long len;
195 u8 max_size, payload_size;
196 int rc = 0;
198 if ((type == NCI_PATCH_TYPE_OTP && !info->otp_patch) ||
199 (type == NCI_PATCH_TYPE_RAM && !info->ram_patch))
200 return -EINVAL;
202 if (type == NCI_PATCH_TYPE_OTP)
203 fw = info->otp_patch;
204 else
205 fw = info->ram_patch;
207 max_size = nci_conn_max_data_pkt_payload_size(ndev, conn_id);
208 if (max_size <= 0)
209 return -EINVAL;
211 len = fw->size;
213 fdp_nci_set_data_pkt_counter(ndev, fdp_nci_send_patch_cb,
214 DIV_ROUND_UP(fw->size, max_size));
216 while (len) {
218 payload_size = min_t(unsigned long, (unsigned long) max_size,
219 len);
221 skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + payload_size),
222 GFP_KERNEL);
223 if (!skb) {
224 fdp_nci_set_data_pkt_counter(ndev, NULL, 0);
225 return -ENOMEM;
229 skb_reserve(skb, NCI_CTRL_HDR_SIZE);
231 memcpy(skb_put(skb, payload_size), fw->data + (fw->size - len),
232 payload_size);
234 rc = nci_send_data(ndev, conn_id, skb);
236 if (rc) {
237 fdp_nci_set_data_pkt_counter(ndev, NULL, 0);
238 return rc;
241 len -= payload_size;
244 return rc;
247 static int fdp_nci_open(struct nci_dev *ndev)
249 int r;
250 struct fdp_nci_info *info = nci_get_drvdata(ndev);
251 struct device *dev = &info->phy->i2c_dev->dev;
253 dev_dbg(dev, "%s\n", __func__);
255 r = info->phy_ops->enable(info->phy);
257 return r;
260 static int fdp_nci_close(struct nci_dev *ndev)
262 struct fdp_nci_info *info = nci_get_drvdata(ndev);
263 struct device *dev = &info->phy->i2c_dev->dev;
265 dev_dbg(dev, "%s\n", __func__);
266 return 0;
269 static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
271 struct fdp_nci_info *info = nci_get_drvdata(ndev);
272 struct device *dev = &info->phy->i2c_dev->dev;
274 dev_dbg(dev, "%s\n", __func__);
276 if (atomic_dec_and_test(&info->data_pkt_counter))
277 info->data_pkt_counter_cb(ndev);
279 return info->phy_ops->write(info->phy, skb);
282 int fdp_nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
284 struct fdp_nci_info *info = nci_get_drvdata(ndev);
285 struct device *dev = &info->phy->i2c_dev->dev;
287 dev_dbg(dev, "%s\n", __func__);
288 return nci_recv_frame(ndev, skb);
290 EXPORT_SYMBOL(fdp_nci_recv_frame);
292 static int fdp_nci_request_firmware(struct nci_dev *ndev)
294 struct fdp_nci_info *info = nci_get_drvdata(ndev);
295 struct device *dev = &info->phy->i2c_dev->dev;
296 u8 *data;
297 int r;
299 r = request_firmware(&info->ram_patch, FDP_RAM_PATCH_NAME, dev);
300 if (r < 0) {
301 nfc_err(dev, "RAM patch request error\n");
302 goto error;
305 data = (u8 *) info->ram_patch->data;
306 info->ram_patch_version =
307 data[FDP_FW_HEADER_SIZE] |
308 (data[FDP_FW_HEADER_SIZE + 1] << 8) |
309 (data[FDP_FW_HEADER_SIZE + 2] << 16) |
310 (data[FDP_FW_HEADER_SIZE + 3] << 24);
312 dev_dbg(dev, "RAM patch version: %d, size: %d\n",
313 info->ram_patch_version, (int) info->ram_patch->size);
316 r = request_firmware(&info->otp_patch, FDP_OTP_PATCH_NAME, dev);
317 if (r < 0) {
318 nfc_err(dev, "OTP patch request error\n");
319 goto out;
322 data = (u8 *) info->otp_patch->data;
323 info->otp_patch_version =
324 data[FDP_FW_HEADER_SIZE] |
325 (data[FDP_FW_HEADER_SIZE + 1] << 8) |
326 (data[FDP_FW_HEADER_SIZE+2] << 16) |
327 (data[FDP_FW_HEADER_SIZE+3] << 24);
329 dev_dbg(dev, "OTP patch version: %d, size: %d\n",
330 info->otp_patch_version, (int) info->otp_patch->size);
331 out:
332 return 0;
333 error:
334 return r;
337 static void fdp_nci_release_firmware(struct nci_dev *ndev)
339 struct fdp_nci_info *info = nci_get_drvdata(ndev);
341 if (info->otp_patch) {
342 release_firmware(info->otp_patch);
343 info->otp_patch = NULL;
346 if (info->ram_patch) {
347 release_firmware(info->ram_patch);
348 info->ram_patch = NULL;
352 static int fdp_nci_patch_otp(struct nci_dev *ndev)
354 struct fdp_nci_info *info = nci_get_drvdata(ndev);
355 struct device *dev = &info->phy->i2c_dev->dev;
356 int conn_id;
357 int r = 0;
359 if (info->otp_version >= info->otp_patch_version)
360 goto out;
362 info->setup_patch_sent = 0;
363 info->setup_reset_ntf = 0;
364 info->setup_patch_ntf = 0;
366 /* Patch init request */
367 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_OTP);
368 if (r)
369 goto out;
371 /* Patch data connection creation */
372 conn_id = fdp_nci_create_conn(ndev);
373 if (conn_id < 0) {
374 r = conn_id;
375 goto out;
378 /* Send the patch over the data connection */
379 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_OTP);
380 if (r)
381 goto out;
383 /* Wait for all the packets to be send over i2c */
384 wait_event_interruptible(info->setup_wq,
385 info->setup_patch_sent == 1);
387 /* make sure that the NFCC processed the last data packet */
388 msleep(FDP_FW_UPDATE_SLEEP);
390 /* Close the data connection */
391 r = nci_core_conn_close(info->ndev, conn_id);
392 if (r)
393 goto out;
395 /* Patch finish message */
396 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) {
397 nfc_err(dev, "OTP patch error 0x%x\n", r);
398 r = -EINVAL;
399 goto out;
402 /* If the patch notification didn't arrive yet, wait for it */
403 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
405 /* Check if the patching was successful */
406 r = info->setup_patch_status;
407 if (r) {
408 nfc_err(dev, "OTP patch error 0x%x\n", r);
409 r = -EINVAL;
410 goto out;
414 * We need to wait for the reset notification before we
415 * can continue
417 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
419 out:
420 return r;
423 static int fdp_nci_patch_ram(struct nci_dev *ndev)
425 struct fdp_nci_info *info = nci_get_drvdata(ndev);
426 struct device *dev = &info->phy->i2c_dev->dev;
427 int conn_id;
428 int r = 0;
430 if (info->ram_version >= info->ram_patch_version)
431 goto out;
433 info->setup_patch_sent = 0;
434 info->setup_reset_ntf = 0;
435 info->setup_patch_ntf = 0;
437 /* Patch init request */
438 r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_RAM);
439 if (r)
440 goto out;
442 /* Patch data connection creation */
443 conn_id = fdp_nci_create_conn(ndev);
444 if (conn_id < 0) {
445 r = conn_id;
446 goto out;
449 /* Send the patch over the data connection */
450 r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_RAM);
451 if (r)
452 goto out;
454 /* Wait for all the packets to be send over i2c */
455 wait_event_interruptible(info->setup_wq,
456 info->setup_patch_sent == 1);
458 /* make sure that the NFCC processed the last data packet */
459 msleep(FDP_FW_UPDATE_SLEEP);
461 /* Close the data connection */
462 r = nci_core_conn_close(info->ndev, conn_id);
463 if (r)
464 goto out;
466 /* Patch finish message */
467 if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) {
468 nfc_err(dev, "RAM patch error 0x%x\n", r);
469 r = -EINVAL;
470 goto out;
473 /* If the patch notification didn't arrive yet, wait for it */
474 wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
476 /* Check if the patching was successful */
477 r = info->setup_patch_status;
478 if (r) {
479 nfc_err(dev, "RAM patch error 0x%x\n", r);
480 r = -EINVAL;
481 goto out;
485 * We need to wait for the reset notification before we
486 * can continue
488 wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
490 out:
491 return r;
494 static int fdp_nci_setup(struct nci_dev *ndev)
496 /* Format: total length followed by an NCI packet */
497 struct fdp_nci_info *info = nci_get_drvdata(ndev);
498 struct device *dev = &info->phy->i2c_dev->dev;
499 int r;
500 u8 patched = 0;
502 dev_dbg(dev, "%s\n", __func__);
504 r = nci_core_init(ndev);
505 if (r)
506 goto error;
508 /* Get RAM and OTP version */
509 r = fdp_nci_get_versions(ndev);
510 if (r)
511 goto error;
513 /* Load firmware from disk */
514 r = fdp_nci_request_firmware(ndev);
515 if (r)
516 goto error;
518 /* Update OTP */
519 if (info->otp_version < info->otp_patch_version) {
520 r = fdp_nci_patch_otp(ndev);
521 if (r)
522 goto error;
523 patched = 1;
526 /* Update RAM */
527 if (info->ram_version < info->ram_patch_version) {
528 r = fdp_nci_patch_ram(ndev);
529 if (r)
530 goto error;
531 patched = 1;
534 /* Release the firmware buffers */
535 fdp_nci_release_firmware(ndev);
537 /* If a patch was applied the new version is checked */
538 if (patched) {
539 r = nci_core_init(ndev);
540 if (r)
541 goto error;
543 r = fdp_nci_get_versions(ndev);
544 if (r)
545 goto error;
547 if (info->otp_version != info->otp_patch_version ||
548 info->ram_version != info->ram_patch_version) {
549 nfc_err(dev, "Firmware update failed");
550 r = -EINVAL;
551 goto error;
556 * We initialized the devices but the NFC subsystem expects
557 * it to not be initialized.
559 return nci_core_reset(ndev);
561 error:
562 fdp_nci_release_firmware(ndev);
563 nfc_err(dev, "Setup error %d\n", r);
564 return r;
567 static int fdp_nci_post_setup(struct nci_dev *ndev)
569 struct fdp_nci_info *info = nci_get_drvdata(ndev);
570 struct device *dev = &info->phy->i2c_dev->dev;
571 int r;
573 /* Check if the device has VSC */
574 if (info->fw_vsc_cfg && info->fw_vsc_cfg[0]) {
576 /* Set the vendor specific configuration */
577 r = fdp_nci_set_production_data(ndev, info->fw_vsc_cfg[3],
578 &info->fw_vsc_cfg[4]);
579 if (r) {
580 nfc_err(dev, "Vendor specific config set error %d\n",
582 return r;
586 /* Set clock type and frequency */
587 r = fdp_nci_set_clock(ndev, info->clock_type, info->clock_freq);
588 if (r) {
589 nfc_err(dev, "Clock set error %d\n", r);
590 return r;
594 * In order to apply the VSC FDP needs a reset
596 r = nci_core_reset(ndev);
597 if (r)
598 return r;
601 * The nci core was initialized when post setup was called
602 * so we leave it like that
604 return nci_core_init(ndev);
607 static int fdp_nci_core_reset_ntf_packet(struct nci_dev *ndev,
608 struct sk_buff *skb)
610 struct fdp_nci_info *info = nci_get_drvdata(ndev);
611 struct device *dev = &info->phy->i2c_dev->dev;
613 dev_dbg(dev, "%s\n", __func__);
614 info->setup_reset_ntf = 1;
615 wake_up(&info->setup_wq);
617 return 0;
620 static int fdp_nci_prop_patch_ntf_packet(struct nci_dev *ndev,
621 struct sk_buff *skb)
623 struct fdp_nci_info *info = nci_get_drvdata(ndev);
624 struct device *dev = &info->phy->i2c_dev->dev;
626 dev_dbg(dev, "%s\n", __func__);
627 info->setup_patch_ntf = 1;
628 info->setup_patch_status = skb->data[0];
629 wake_up(&info->setup_wq);
631 return 0;
634 static int fdp_nci_prop_patch_rsp_packet(struct nci_dev *ndev,
635 struct sk_buff *skb)
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];
641 dev_dbg(dev, "%s: status 0x%x\n", __func__, status);
642 nci_req_complete(ndev, status);
644 return 0;
647 static int fdp_nci_prop_set_production_data_rsp_packet(struct nci_dev *ndev,
648 struct sk_buff *skb)
650 struct fdp_nci_info *info = nci_get_drvdata(ndev);
651 struct device *dev = &info->phy->i2c_dev->dev;
652 u8 status = skb->data[0];
654 dev_dbg(dev, "%s: status 0x%x\n", __func__, status);
655 nci_req_complete(ndev, status);
657 return 0;
660 static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev,
661 struct sk_buff *skb)
663 struct fdp_nci_info *info = nci_get_drvdata(ndev);
664 struct device *dev = &info->phy->i2c_dev->dev;
665 struct nci_core_get_config_rsp *rsp = (void *) skb->data;
666 u8 i, *p;
668 if (rsp->status == NCI_STATUS_OK) {
670 p = rsp->data;
671 for (i = 0; i < 4; i++) {
673 switch (*p++) {
674 case NCI_PARAM_ID_FW_RAM_VERSION:
675 p++;
676 info->ram_version = le32_to_cpup((__le32 *) p);
677 p += 4;
678 break;
679 case NCI_PARAM_ID_FW_OTP_VERSION:
680 p++;
681 info->otp_version = le32_to_cpup((__le32 *) p);
682 p += 4;
683 break;
684 case NCI_PARAM_ID_OTP_LIMITED_VERSION:
685 p++;
686 info->otp_version = le32_to_cpup((__le32 *) p);
687 p += 4;
688 break;
689 case NCI_PARAM_ID_KEY_INDEX_ID:
690 p++;
691 info->key_index = *p++;
696 dev_dbg(dev, "OTP version %d\n", info->otp_version);
697 dev_dbg(dev, "RAM version %d\n", info->ram_version);
698 dev_dbg(dev, "key index %d\n", info->key_index);
699 dev_dbg(dev, "%s: status 0x%x\n", __func__, rsp->status);
701 nci_req_complete(ndev, rsp->status);
703 return 0;
706 static struct nci_driver_ops fdp_core_ops[] = {
708 .opcode = NCI_OP_CORE_GET_CONFIG_RSP,
709 .rsp = fdp_nci_core_get_config_rsp_packet,
712 .opcode = NCI_OP_CORE_RESET_NTF,
713 .ntf = fdp_nci_core_reset_ntf_packet,
717 static struct nci_driver_ops fdp_prop_ops[] = {
719 .opcode = nci_opcode_pack(NCI_GID_PROP, NCI_OP_PROP_PATCH_OID),
720 .rsp = fdp_nci_prop_patch_rsp_packet,
721 .ntf = fdp_nci_prop_patch_ntf_packet,
724 .opcode = nci_opcode_pack(NCI_GID_PROP,
725 NCI_OP_PROP_SET_PDATA_OID),
726 .rsp = fdp_nci_prop_set_production_data_rsp_packet,
730 struct nci_ops nci_ops = {
731 .open = fdp_nci_open,
732 .close = fdp_nci_close,
733 .send = fdp_nci_send,
734 .setup = fdp_nci_setup,
735 .post_setup = fdp_nci_post_setup,
736 .prop_ops = fdp_prop_ops,
737 .n_prop_ops = ARRAY_SIZE(fdp_prop_ops),
738 .core_ops = fdp_core_ops,
739 .n_core_ops = ARRAY_SIZE(fdp_core_ops),
742 int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops,
743 struct nci_dev **ndevp, int tx_headroom,
744 int tx_tailroom, u8 clock_type, u32 clock_freq,
745 u8 *fw_vsc_cfg)
747 struct device *dev = &phy->i2c_dev->dev;
748 struct fdp_nci_info *info;
749 struct nci_dev *ndev;
750 u32 protocols;
751 int r;
753 info = kzalloc(sizeof(struct fdp_nci_info), GFP_KERNEL);
754 if (!info) {
755 r = -ENOMEM;
756 goto err_info_alloc;
759 info->phy = phy;
760 info->phy_ops = phy_ops;
761 info->clock_type = clock_type;
762 info->clock_freq = clock_freq;
763 info->fw_vsc_cfg = fw_vsc_cfg;
765 init_waitqueue_head(&info->setup_wq);
767 protocols = NFC_PROTO_JEWEL_MASK |
768 NFC_PROTO_MIFARE_MASK |
769 NFC_PROTO_FELICA_MASK |
770 NFC_PROTO_ISO14443_MASK |
771 NFC_PROTO_ISO14443_B_MASK |
772 NFC_PROTO_NFC_DEP_MASK |
773 NFC_PROTO_ISO15693_MASK;
775 ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom,
776 tx_tailroom);
777 if (!ndev) {
778 nfc_err(dev, "Cannot allocate nfc ndev\n");
779 r = -ENOMEM;
780 goto err_alloc_ndev;
783 r = nci_register_device(ndev);
784 if (r)
785 goto err_regdev;
787 *ndevp = ndev;
788 info->ndev = ndev;
790 nci_set_drvdata(ndev, info);
792 return 0;
794 err_regdev:
795 nci_free_device(ndev);
796 err_alloc_ndev:
797 kfree(info);
798 err_info_alloc:
799 return r;
801 EXPORT_SYMBOL(fdp_nci_probe);
803 void fdp_nci_remove(struct nci_dev *ndev)
805 struct fdp_nci_info *info = nci_get_drvdata(ndev);
806 struct device *dev = &info->phy->i2c_dev->dev;
808 dev_dbg(dev, "%s\n", __func__);
810 nci_unregister_device(ndev);
811 nci_free_device(ndev);
812 kfree(info);
814 EXPORT_SYMBOL(fdp_nci_remove);
816 MODULE_LICENSE("GPL");
817 MODULE_DESCRIPTION("NFC NCI driver for Intel Fields Peak NFC controller");
818 MODULE_AUTHOR("Robert Dolca <robert.dolca@intel.com>");