2 * HCI based Driver for NXP PN544 NFC Chip
4 * Copyright (C) 2012 Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
25 #include <linux/nfc.h>
26 #include <net/nfc/hci.h>
27 #include <net/nfc/llc.h>
31 /* Timing restrictions (ms) */
32 #define PN544_HCI_RESETVEN_TIME 30
40 #define FULL_VERSION_LEN 11
42 /* Proprietary commands */
43 #define PN544_WRITE 0x3f
45 /* Proprietary gates, events, commands and registers */
47 /* NFC_HCI_RF_READER_A_GATE additional registers and commands */
48 #define PN544_RF_READER_A_AUTO_ACTIVATION 0x10
49 #define PN544_RF_READER_A_CMD_CONTINUE_ACTIVATION 0x12
50 #define PN544_MIFARE_CMD 0x21
52 /* Commands that apply to all RF readers */
53 #define PN544_RF_READER_CMD_PRESENCE_CHECK 0x30
54 #define PN544_RF_READER_CMD_ACTIVATE_NEXT 0x32
56 /* NFC_HCI_ID_MGMT_GATE additional registers */
57 #define PN544_ID_MGMT_FULL_VERSION_SW 0x10
59 #define PN544_RF_READER_ISO15693_GATE 0x12
61 #define PN544_RF_READER_F_GATE 0x14
62 #define PN544_FELICA_ID 0x04
63 #define PN544_FELICA_RAW 0x20
65 #define PN544_RF_READER_JEWEL_GATE 0x15
66 #define PN544_JEWEL_RAW_CMD 0x23
68 #define PN544_RF_READER_NFCIP1_INITIATOR_GATE 0x30
69 #define PN544_RF_READER_NFCIP1_TARGET_GATE 0x31
71 #define PN544_SYS_MGMT_GATE 0x90
72 #define PN544_SYS_MGMT_INFO_NOTIFICATION 0x02
74 #define PN544_POLLING_LOOP_MGMT_GATE 0x94
75 #define PN544_DEP_MODE 0x01
76 #define PN544_DEP_ATR_REQ 0x02
77 #define PN544_DEP_ATR_RES 0x03
78 #define PN544_DEP_MERGE 0x0D
79 #define PN544_PL_RDPHASES 0x06
80 #define PN544_PL_EMULATION 0x07
81 #define PN544_PL_NFCT_DEACTIVATED 0x09
83 #define PN544_SWP_MGMT_GATE 0xA0
85 #define PN544_NFC_WI_MGMT_GATE 0xA1
87 #define PN544_HCI_EVT_SND_DATA 0x01
88 #define PN544_HCI_EVT_ACTIVATED 0x02
89 #define PN544_HCI_EVT_DEACTIVATED 0x03
90 #define PN544_HCI_EVT_RCV_DATA 0x04
91 #define PN544_HCI_EVT_CONTINUE_MI 0x05
93 #define PN544_HCI_CMD_ATTREQUEST 0x12
94 #define PN544_HCI_CMD_CONTINUE_ACTIVATION 0x13
96 static struct nfc_hci_gate pn544_gates
[] = {
97 {NFC_HCI_ADMIN_GATE
, NFC_HCI_INVALID_PIPE
},
98 {NFC_HCI_LOOPBACK_GATE
, NFC_HCI_INVALID_PIPE
},
99 {NFC_HCI_ID_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
100 {NFC_HCI_LINK_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
101 {NFC_HCI_RF_READER_B_GATE
, NFC_HCI_INVALID_PIPE
},
102 {NFC_HCI_RF_READER_A_GATE
, NFC_HCI_INVALID_PIPE
},
103 {PN544_SYS_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
104 {PN544_SWP_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
105 {PN544_POLLING_LOOP_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
106 {PN544_NFC_WI_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
107 {PN544_RF_READER_F_GATE
, NFC_HCI_INVALID_PIPE
},
108 {PN544_RF_READER_JEWEL_GATE
, NFC_HCI_INVALID_PIPE
},
109 {PN544_RF_READER_ISO15693_GATE
, NFC_HCI_INVALID_PIPE
},
110 {PN544_RF_READER_NFCIP1_INITIATOR_GATE
, NFC_HCI_INVALID_PIPE
},
111 {PN544_RF_READER_NFCIP1_TARGET_GATE
, NFC_HCI_INVALID_PIPE
}
114 /* Largest headroom needed for outgoing custom commands */
115 #define PN544_CMDS_HEADROOM 2
117 struct pn544_hci_info
{
118 struct nfc_phy_ops
*phy_ops
;
121 struct nfc_hci_dev
*hdev
;
123 enum pn544_state state
;
125 struct mutex info_lock
;
128 data_exchange_cb_t async_cb
;
129 void *async_cb_context
;
131 fw_download_t fw_download
;
134 static int pn544_hci_open(struct nfc_hci_dev
*hdev
)
136 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
139 mutex_lock(&info
->info_lock
);
141 if (info
->state
!= PN544_ST_COLD
) {
146 r
= info
->phy_ops
->enable(info
->phy_id
);
149 info
->state
= PN544_ST_READY
;
152 mutex_unlock(&info
->info_lock
);
156 static void pn544_hci_close(struct nfc_hci_dev
*hdev
)
158 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
160 mutex_lock(&info
->info_lock
);
162 if (info
->state
== PN544_ST_COLD
)
165 info
->phy_ops
->disable(info
->phy_id
);
167 info
->state
= PN544_ST_COLD
;
170 mutex_unlock(&info
->info_lock
);
173 static int pn544_hci_ready(struct nfc_hci_dev
*hdev
)
176 static struct hw_config
{
180 {{0x9f, 0x9a}, 0x00},
182 {{0x98, 0x10}, 0xbc},
184 {{0x9e, 0x71}, 0x00},
186 {{0x98, 0x09}, 0x00},
188 {{0x9e, 0xb4}, 0x00},
190 {{0x9e, 0xd9}, 0xff},
191 {{0x9e, 0xda}, 0xff},
192 {{0x9e, 0xdb}, 0x23},
193 {{0x9e, 0xdc}, 0x21},
194 {{0x9e, 0xdd}, 0x22},
195 {{0x9e, 0xde}, 0x24},
197 {{0x9c, 0x01}, 0x08},
199 {{0x9e, 0xaa}, 0x01},
201 {{0x9b, 0xd1}, 0x0d},
202 {{0x9b, 0xd2}, 0x24},
203 {{0x9b, 0xd3}, 0x0a},
204 {{0x9b, 0xd4}, 0x22},
205 {{0x9b, 0xd5}, 0x08},
206 {{0x9b, 0xd6}, 0x1e},
207 {{0x9b, 0xdd}, 0x1c},
209 {{0x9b, 0x84}, 0x13},
210 {{0x99, 0x81}, 0x7f},
211 {{0x99, 0x31}, 0x70},
213 {{0x98, 0x00}, 0x3f},
215 {{0x9f, 0x09}, 0x00},
217 {{0x9f, 0x0a}, 0x05},
219 {{0x9e, 0xd1}, 0xa1},
220 {{0x99, 0x23}, 0x00},
222 {{0x9e, 0x74}, 0x80},
224 {{0x9f, 0x28}, 0x10},
226 {{0x9f, 0x35}, 0x14},
228 {{0x9f, 0x36}, 0x60},
230 {{0x9c, 0x31}, 0x00},
232 {{0x9c, 0x32}, 0xc8},
234 {{0x9c, 0x19}, 0x40},
236 {{0x9c, 0x1a}, 0x40},
238 {{0x9c, 0x0c}, 0x00},
240 {{0x9c, 0x0d}, 0x00},
242 {{0x9c, 0x12}, 0x00},
244 {{0x9c, 0x13}, 0x00},
246 {{0x98, 0xa2}, 0x0e},
248 {{0x98, 0x93}, 0x40},
250 {{0x98, 0x7d}, 0x02},
251 {{0x98, 0x7e}, 0x00},
252 {{0x9f, 0xc8}, 0x01},
254 struct hw_config
*p
= hw_config
;
255 int count
= ARRAY_SIZE(hw_config
);
256 struct sk_buff
*res_skb
;
262 param
[1] = p
->adr
[0];
263 param
[2] = p
->adr
[1];
266 r
= nfc_hci_send_cmd(hdev
, PN544_SYS_MGMT_GATE
, PN544_WRITE
,
271 if (res_skb
->len
!= 1) {
276 if (res_skb
->data
[0] != p
->value
) {
286 param
[0] = NFC_HCI_UICC_HOST_ID
;
287 r
= nfc_hci_set_param(hdev
, NFC_HCI_ADMIN_GATE
,
288 NFC_HCI_ADMIN_WHITELIST
, param
, 1);
293 r
= nfc_hci_set_param(hdev
, PN544_SYS_MGMT_GATE
,
294 PN544_SYS_MGMT_INFO_NOTIFICATION
, param
, 1);
299 r
= nfc_hci_set_param(hdev
, NFC_HCI_RF_READER_A_GATE
,
300 PN544_RF_READER_A_AUTO_ACTIVATION
, param
, 1);
304 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
305 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
310 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
311 PN544_PL_NFCT_DEACTIVATED
, param
, 1);
316 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
317 PN544_PL_RDPHASES
, param
, 1);
321 r
= nfc_hci_get_param(hdev
, NFC_HCI_ID_MGMT_GATE
,
322 PN544_ID_MGMT_FULL_VERSION_SW
, &skb
);
326 if (skb
->len
!= FULL_VERSION_LEN
) {
331 print_hex_dump(KERN_DEBUG
, "FULL VERSION SOFTWARE INFO: ",
332 DUMP_PREFIX_NONE
, 16, 1,
333 skb
->data
, FULL_VERSION_LEN
, false);
340 static int pn544_hci_xmit(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
342 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
344 return info
->phy_ops
->write(info
->phy_id
, skb
);
347 static int pn544_hci_start_poll(struct nfc_hci_dev
*hdev
,
348 u32 im_protocols
, u32 tm_protocols
)
354 u8 i_mode
= 0x3f; /* Enable all supported modes */
356 u8 t_merge
= 0x01; /* Enable merge by default */
358 pr_info(DRIVER_DESC
": %s protocols 0x%x 0x%x\n",
359 __func__
, im_protocols
, tm_protocols
);
361 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
362 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
368 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
369 PN544_PL_EMULATION
, duration
, 2);
374 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
375 PN544_PL_NFCT_DEACTIVATED
, &activated
, 1);
379 if (im_protocols
& (NFC_PROTO_ISO14443_MASK
| NFC_PROTO_MIFARE_MASK
|
380 NFC_PROTO_JEWEL_MASK
))
381 phases
|= 1; /* Type A */
382 if (im_protocols
& NFC_PROTO_FELICA_MASK
) {
383 phases
|= (1 << 2); /* Type F 212 */
384 phases
|= (1 << 3); /* Type F 424 */
387 phases
|= (1 << 5); /* NFC active */
389 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
390 PN544_PL_RDPHASES
, &phases
, 1);
394 if ((im_protocols
| tm_protocols
) & NFC_PROTO_NFC_DEP_MASK
) {
395 hdev
->gb
= nfc_get_local_general_bytes(hdev
->ndev
,
397 pr_debug("generate local bytes %p", hdev
->gb
);
398 if (hdev
->gb
== NULL
|| hdev
->gb_len
== 0) {
399 im_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
400 tm_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
404 if (im_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
405 r
= nfc_hci_send_event(hdev
,
406 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
407 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
411 r
= nfc_hci_set_param(hdev
,
412 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
413 PN544_DEP_MODE
, &i_mode
, 1);
417 r
= nfc_hci_set_param(hdev
,
418 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
419 PN544_DEP_ATR_REQ
, hdev
->gb
, hdev
->gb_len
);
423 r
= nfc_hci_send_event(hdev
,
424 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
425 NFC_HCI_EVT_READER_REQUESTED
, NULL
, 0);
427 nfc_hci_send_event(hdev
,
428 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
429 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
432 if (tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
433 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
434 PN544_DEP_MODE
, &t_mode
, 1);
438 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
439 PN544_DEP_ATR_RES
, hdev
->gb
, hdev
->gb_len
);
443 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
444 PN544_DEP_MERGE
, &t_merge
, 1);
449 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
450 NFC_HCI_EVT_READER_REQUESTED
, NULL
, 0);
452 nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
453 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
458 static int pn544_hci_dep_link_up(struct nfc_hci_dev
*hdev
,
459 struct nfc_target
*target
, u8 comm_mode
,
460 u8
*gb
, size_t gb_len
)
462 struct sk_buff
*rgb_skb
= NULL
;
465 r
= nfc_hci_get_param(hdev
, target
->hci_reader_gate
,
466 PN544_DEP_ATR_RES
, &rgb_skb
);
470 if (rgb_skb
->len
== 0 || rgb_skb
->len
> NFC_GB_MAXSIZE
) {
474 print_hex_dump(KERN_DEBUG
, "remote gb: ", DUMP_PREFIX_OFFSET
,
475 16, 1, rgb_skb
->data
, rgb_skb
->len
, true);
477 r
= nfc_set_remote_general_bytes(hdev
->ndev
, rgb_skb
->data
,
481 r
= nfc_dep_link_is_up(hdev
->ndev
, target
->idx
, comm_mode
,
488 static int pn544_hci_dep_link_down(struct nfc_hci_dev
*hdev
)
491 return nfc_hci_send_event(hdev
, PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
492 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
495 static int pn544_hci_target_from_gate(struct nfc_hci_dev
*hdev
, u8 gate
,
496 struct nfc_target
*target
)
499 case PN544_RF_READER_F_GATE
:
500 target
->supported_protocols
= NFC_PROTO_FELICA_MASK
;
502 case PN544_RF_READER_JEWEL_GATE
:
503 target
->supported_protocols
= NFC_PROTO_JEWEL_MASK
;
504 target
->sens_res
= 0x0c00;
506 case PN544_RF_READER_NFCIP1_INITIATOR_GATE
:
507 target
->supported_protocols
= NFC_PROTO_NFC_DEP_MASK
;
516 static int pn544_hci_complete_target_discovered(struct nfc_hci_dev
*hdev
,
518 struct nfc_target
*target
)
520 struct sk_buff
*uid_skb
;
523 if (gate
== PN544_RF_READER_NFCIP1_INITIATOR_GATE
)
526 if (target
->supported_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
527 r
= nfc_hci_send_cmd(hdev
,
528 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
529 PN544_HCI_CMD_CONTINUE_ACTIVATION
, NULL
, 0, NULL
);
533 target
->hci_reader_gate
= PN544_RF_READER_NFCIP1_INITIATOR_GATE
;
534 } else if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
535 if (target
->nfcid1_len
!= 4 && target
->nfcid1_len
!= 7 &&
536 target
->nfcid1_len
!= 10)
539 r
= nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
540 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
541 target
->nfcid1
, target
->nfcid1_len
, NULL
);
542 } else if (target
->supported_protocols
& NFC_PROTO_FELICA_MASK
) {
543 r
= nfc_hci_get_param(hdev
, PN544_RF_READER_F_GATE
,
544 PN544_FELICA_ID
, &uid_skb
);
548 if (uid_skb
->len
!= 8) {
553 /* Type F NFC-DEP IDm has prefix 0x01FE */
554 if ((uid_skb
->data
[0] == 0x01) && (uid_skb
->data
[1] == 0xfe)) {
556 r
= nfc_hci_send_cmd(hdev
,
557 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
558 PN544_HCI_CMD_CONTINUE_ACTIVATION
,
563 target
->supported_protocols
= NFC_PROTO_NFC_DEP_MASK
;
564 target
->hci_reader_gate
=
565 PN544_RF_READER_NFCIP1_INITIATOR_GATE
;
567 r
= nfc_hci_send_cmd(hdev
, PN544_RF_READER_F_GATE
,
568 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
569 uid_skb
->data
, uid_skb
->len
, NULL
);
572 } else if (target
->supported_protocols
& NFC_PROTO_ISO14443_MASK
) {
574 * TODO: maybe other ISO 14443 require some kind of continue
575 * activation, but for now we've seen only this one below.
577 if (target
->sens_res
== 0x4403) /* Type 4 Mifare DESFire */
578 r
= nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
579 PN544_RF_READER_A_CMD_CONTINUE_ACTIVATION
,
586 #define PN544_CB_TYPE_READER_F 1
588 static void pn544_hci_data_exchange_cb(void *context
, struct sk_buff
*skb
,
591 struct pn544_hci_info
*info
= context
;
593 switch (info
->async_cb_type
) {
594 case PN544_CB_TYPE_READER_F
:
597 info
->async_cb(info
->async_cb_context
, skb
, err
);
606 #define MIFARE_CMD_AUTH_KEY_A 0x60
607 #define MIFARE_CMD_AUTH_KEY_B 0x61
608 #define MIFARE_CMD_HEADER 2
609 #define MIFARE_UID_LEN 4
610 #define MIFARE_KEY_LEN 6
611 #define MIFARE_CMD_LEN 12
614 * <= 0: driver handled the data exchange
615 * 1: driver doesn't especially handle, please do standard processing
617 static int pn544_hci_im_transceive(struct nfc_hci_dev
*hdev
,
618 struct nfc_target
*target
,
619 struct sk_buff
*skb
, data_exchange_cb_t cb
,
622 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
624 pr_info(DRIVER_DESC
": %s for gate=%d\n", __func__
,
625 target
->hci_reader_gate
);
627 switch (target
->hci_reader_gate
) {
628 case NFC_HCI_RF_READER_A_GATE
:
629 if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
631 * It seems that pn544 is inverting key and UID for
632 * MIFARE authentication commands.
634 if (skb
->len
== MIFARE_CMD_LEN
&&
635 (skb
->data
[0] == MIFARE_CMD_AUTH_KEY_A
||
636 skb
->data
[0] == MIFARE_CMD_AUTH_KEY_B
)) {
637 u8 uid
[MIFARE_UID_LEN
];
638 u8
*data
= skb
->data
+ MIFARE_CMD_HEADER
;
640 memcpy(uid
, data
+ MIFARE_KEY_LEN
,
642 memmove(data
+ MIFARE_UID_LEN
, data
,
644 memcpy(data
, uid
, MIFARE_UID_LEN
);
647 return nfc_hci_send_cmd_async(hdev
,
648 target
->hci_reader_gate
,
654 case PN544_RF_READER_F_GATE
:
655 *skb_push(skb
, 1) = 0;
656 *skb_push(skb
, 1) = 0;
658 info
->async_cb_type
= PN544_CB_TYPE_READER_F
;
660 info
->async_cb_context
= cb_context
;
662 return nfc_hci_send_cmd_async(hdev
, target
->hci_reader_gate
,
663 PN544_FELICA_RAW
, skb
->data
,
665 pn544_hci_data_exchange_cb
, info
);
666 case PN544_RF_READER_JEWEL_GATE
:
667 return nfc_hci_send_cmd_async(hdev
, target
->hci_reader_gate
,
668 PN544_JEWEL_RAW_CMD
, skb
->data
,
669 skb
->len
, cb
, cb_context
);
670 case PN544_RF_READER_NFCIP1_INITIATOR_GATE
:
671 *skb_push(skb
, 1) = 0;
673 return nfc_hci_send_event(hdev
, target
->hci_reader_gate
,
674 PN544_HCI_EVT_SND_DATA
, skb
->data
,
681 static int pn544_hci_tm_send(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
685 /* Set default false for multiple information chaining */
686 *skb_push(skb
, 1) = 0;
688 r
= nfc_hci_send_event(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
689 PN544_HCI_EVT_SND_DATA
, skb
->data
, skb
->len
);
696 static int pn544_hci_check_presence(struct nfc_hci_dev
*hdev
,
697 struct nfc_target
*target
)
699 pr_debug("supported protocol %d", target
->supported_protocols
);
700 if (target
->supported_protocols
& (NFC_PROTO_ISO14443_MASK
|
701 NFC_PROTO_ISO14443_B_MASK
)) {
702 return nfc_hci_send_cmd(hdev
, target
->hci_reader_gate
,
703 PN544_RF_READER_CMD_PRESENCE_CHECK
,
705 } else if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
706 if (target
->nfcid1_len
!= 4 && target
->nfcid1_len
!= 7 &&
707 target
->nfcid1_len
!= 10)
710 return nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
711 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
712 target
->nfcid1
, target
->nfcid1_len
, NULL
);
713 } else if (target
->supported_protocols
& (NFC_PROTO_JEWEL_MASK
|
714 NFC_PROTO_FELICA_MASK
)) {
716 } else if (target
->supported_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
717 return nfc_hci_send_cmd(hdev
, target
->hci_reader_gate
,
718 PN544_HCI_CMD_ATTREQUEST
,
727 * <= 0: driver handled the event, skb consumed
728 * 1: driver does not handle the event, please do standard processing
730 static int pn544_hci_event_received(struct nfc_hci_dev
*hdev
, u8 gate
, u8 event
,
733 struct sk_buff
*rgb_skb
= NULL
;
736 pr_debug("hci event %d", event
);
738 case PN544_HCI_EVT_ACTIVATED
:
739 if (gate
== PN544_RF_READER_NFCIP1_INITIATOR_GATE
) {
740 r
= nfc_hci_target_discovered(hdev
, gate
);
741 } else if (gate
== PN544_RF_READER_NFCIP1_TARGET_GATE
) {
742 r
= nfc_hci_get_param(hdev
, gate
, PN544_DEP_ATR_REQ
,
747 r
= nfc_tm_activated(hdev
->ndev
, NFC_PROTO_NFC_DEP_MASK
,
748 NFC_COMM_PASSIVE
, rgb_skb
->data
,
756 case PN544_HCI_EVT_DEACTIVATED
:
757 r
= nfc_hci_send_event(hdev
, gate
, NFC_HCI_EVT_END_OPERATION
,
760 case PN544_HCI_EVT_RCV_DATA
:
766 if (skb
->data
[0] != 0) {
767 pr_debug("data0 %d", skb
->data
[0]);
773 return nfc_tm_data_received(hdev
->ndev
, skb
);
784 static int pn544_hci_fw_download(struct nfc_hci_dev
*hdev
,
785 const char *firmware_name
)
787 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
789 if (info
->fw_download
== NULL
)
792 return info
->fw_download(info
->phy_id
, firmware_name
);
795 static struct nfc_hci_ops pn544_hci_ops
= {
796 .open
= pn544_hci_open
,
797 .close
= pn544_hci_close
,
798 .hci_ready
= pn544_hci_ready
,
799 .xmit
= pn544_hci_xmit
,
800 .start_poll
= pn544_hci_start_poll
,
801 .dep_link_up
= pn544_hci_dep_link_up
,
802 .dep_link_down
= pn544_hci_dep_link_down
,
803 .target_from_gate
= pn544_hci_target_from_gate
,
804 .complete_target_discovered
= pn544_hci_complete_target_discovered
,
805 .im_transceive
= pn544_hci_im_transceive
,
806 .tm_send
= pn544_hci_tm_send
,
807 .check_presence
= pn544_hci_check_presence
,
808 .event_received
= pn544_hci_event_received
,
809 .fw_download
= pn544_hci_fw_download
,
812 int pn544_hci_probe(void *phy_id
, struct nfc_phy_ops
*phy_ops
, char *llc_name
,
813 int phy_headroom
, int phy_tailroom
, int phy_payload
,
814 fw_download_t fw_download
, struct nfc_hci_dev
**hdev
)
816 struct pn544_hci_info
*info
;
818 struct nfc_hci_init_data init_data
;
821 info
= kzalloc(sizeof(struct pn544_hci_info
), GFP_KERNEL
);
823 pr_err("Cannot allocate memory for pn544_hci_info.\n");
828 info
->phy_ops
= phy_ops
;
829 info
->phy_id
= phy_id
;
830 info
->fw_download
= fw_download
;
831 info
->state
= PN544_ST_COLD
;
832 mutex_init(&info
->info_lock
);
834 init_data
.gate_count
= ARRAY_SIZE(pn544_gates
);
836 memcpy(init_data
.gates
, pn544_gates
, sizeof(pn544_gates
));
839 * TODO: Session id must include the driver name + some bus addr
840 * persistent info to discriminate 2 identical chips
842 strcpy(init_data
.session_id
, "ID544HCI");
844 protocols
= NFC_PROTO_JEWEL_MASK
|
845 NFC_PROTO_MIFARE_MASK
|
846 NFC_PROTO_FELICA_MASK
|
847 NFC_PROTO_ISO14443_MASK
|
848 NFC_PROTO_ISO14443_B_MASK
|
849 NFC_PROTO_NFC_DEP_MASK
;
851 info
->hdev
= nfc_hci_allocate_device(&pn544_hci_ops
, &init_data
, 0,
853 phy_headroom
+ PN544_CMDS_HEADROOM
,
854 phy_tailroom
, phy_payload
);
856 pr_err("Cannot allocate nfc hdev.\n");
861 nfc_hci_set_clientdata(info
->hdev
, info
);
863 r
= nfc_hci_register_device(info
->hdev
);
872 nfc_hci_free_device(info
->hdev
);
880 EXPORT_SYMBOL(pn544_hci_probe
);
882 void pn544_hci_remove(struct nfc_hci_dev
*hdev
)
884 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
886 nfc_hci_unregister_device(hdev
);
887 nfc_hci_free_device(hdev
);
890 EXPORT_SYMBOL(pn544_hci_remove
);
892 MODULE_LICENSE("GPL");
893 MODULE_DESCRIPTION(DRIVER_DESC
);