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