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
43 #define FULL_VERSION_LEN 11
45 /* Proprietary commands */
46 #define PN544_WRITE 0x3f
48 /* Proprietary gates, events, commands and registers */
50 /* NFC_HCI_RF_READER_A_GATE additional registers and commands */
51 #define PN544_RF_READER_A_AUTO_ACTIVATION 0x10
52 #define PN544_RF_READER_A_CMD_CONTINUE_ACTIVATION 0x12
53 #define PN544_MIFARE_CMD 0x21
55 /* Commands that apply to all RF readers */
56 #define PN544_RF_READER_CMD_PRESENCE_CHECK 0x30
57 #define PN544_RF_READER_CMD_ACTIVATE_NEXT 0x32
59 /* NFC_HCI_ID_MGMT_GATE additional registers */
60 #define PN544_ID_MGMT_FULL_VERSION_SW 0x10
62 #define PN544_RF_READER_ISO15693_GATE 0x12
64 #define PN544_RF_READER_F_GATE 0x14
65 #define PN544_FELICA_ID 0x04
66 #define PN544_FELICA_RAW 0x20
68 #define PN544_RF_READER_JEWEL_GATE 0x15
69 #define PN544_JEWEL_RAW_CMD 0x23
71 #define PN544_RF_READER_NFCIP1_INITIATOR_GATE 0x30
72 #define PN544_RF_READER_NFCIP1_TARGET_GATE 0x31
74 #define PN544_SYS_MGMT_GATE 0x90
75 #define PN544_SYS_MGMT_INFO_NOTIFICATION 0x02
77 #define PN544_POLLING_LOOP_MGMT_GATE 0x94
78 #define PN544_DEP_MODE 0x01
79 #define PN544_DEP_ATR_REQ 0x02
80 #define PN544_DEP_ATR_RES 0x03
81 #define PN544_DEP_MERGE 0x0D
82 #define PN544_PL_RDPHASES 0x06
83 #define PN544_PL_EMULATION 0x07
84 #define PN544_PL_NFCT_DEACTIVATED 0x09
86 #define PN544_SWP_MGMT_GATE 0xA0
88 #define PN544_NFC_WI_MGMT_GATE 0xA1
90 #define PN544_HCI_EVT_SND_DATA 0x01
91 #define PN544_HCI_EVT_ACTIVATED 0x02
92 #define PN544_HCI_EVT_DEACTIVATED 0x03
93 #define PN544_HCI_EVT_RCV_DATA 0x04
94 #define PN544_HCI_EVT_CONTINUE_MI 0x05
96 #define PN544_HCI_CMD_ATTREQUEST 0x12
97 #define PN544_HCI_CMD_CONTINUE_ACTIVATION 0x13
99 static struct nfc_hci_gate pn544_gates
[] = {
100 {NFC_HCI_ADMIN_GATE
, NFC_HCI_INVALID_PIPE
},
101 {NFC_HCI_LOOPBACK_GATE
, NFC_HCI_INVALID_PIPE
},
102 {NFC_HCI_ID_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
103 {NFC_HCI_LINK_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
104 {NFC_HCI_RF_READER_B_GATE
, NFC_HCI_INVALID_PIPE
},
105 {NFC_HCI_RF_READER_A_GATE
, NFC_HCI_INVALID_PIPE
},
106 {PN544_SYS_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
107 {PN544_SWP_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
108 {PN544_POLLING_LOOP_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
109 {PN544_NFC_WI_MGMT_GATE
, NFC_HCI_INVALID_PIPE
},
110 {PN544_RF_READER_F_GATE
, NFC_HCI_INVALID_PIPE
},
111 {PN544_RF_READER_JEWEL_GATE
, NFC_HCI_INVALID_PIPE
},
112 {PN544_RF_READER_ISO15693_GATE
, NFC_HCI_INVALID_PIPE
},
113 {PN544_RF_READER_NFCIP1_INITIATOR_GATE
, NFC_HCI_INVALID_PIPE
},
114 {PN544_RF_READER_NFCIP1_TARGET_GATE
, NFC_HCI_INVALID_PIPE
}
117 /* Largest headroom needed for outgoing custom commands */
118 #define PN544_CMDS_HEADROOM 2
120 struct pn544_hci_info
{
121 struct nfc_phy_ops
*phy_ops
;
124 struct nfc_hci_dev
*hdev
;
126 enum pn544_state state
;
128 struct mutex info_lock
;
131 data_exchange_cb_t async_cb
;
132 void *async_cb_context
;
135 static int pn544_hci_open(struct nfc_hci_dev
*hdev
)
137 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
140 mutex_lock(&info
->info_lock
);
142 if (info
->state
!= PN544_ST_COLD
) {
147 r
= info
->phy_ops
->enable(info
->phy_id
);
150 info
->state
= PN544_ST_READY
;
153 mutex_unlock(&info
->info_lock
);
157 static void pn544_hci_close(struct nfc_hci_dev
*hdev
)
159 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
161 mutex_lock(&info
->info_lock
);
163 if (info
->state
== PN544_ST_COLD
)
166 info
->phy_ops
->disable(info
->phy_id
);
168 info
->state
= PN544_ST_COLD
;
171 mutex_unlock(&info
->info_lock
);
174 static int pn544_hci_ready(struct nfc_hci_dev
*hdev
)
177 static struct hw_config
{
181 {{0x9f, 0x9a}, 0x00},
183 {{0x98, 0x10}, 0xbc},
185 {{0x9e, 0x71}, 0x00},
187 {{0x98, 0x09}, 0x00},
189 {{0x9e, 0xb4}, 0x00},
191 {{0x9e, 0xd9}, 0xff},
192 {{0x9e, 0xda}, 0xff},
193 {{0x9e, 0xdb}, 0x23},
194 {{0x9e, 0xdc}, 0x21},
195 {{0x9e, 0xdd}, 0x22},
196 {{0x9e, 0xde}, 0x24},
198 {{0x9c, 0x01}, 0x08},
200 {{0x9e, 0xaa}, 0x01},
202 {{0x9b, 0xd1}, 0x0d},
203 {{0x9b, 0xd2}, 0x24},
204 {{0x9b, 0xd3}, 0x0a},
205 {{0x9b, 0xd4}, 0x22},
206 {{0x9b, 0xd5}, 0x08},
207 {{0x9b, 0xd6}, 0x1e},
208 {{0x9b, 0xdd}, 0x1c},
210 {{0x9b, 0x84}, 0x13},
211 {{0x99, 0x81}, 0x7f},
212 {{0x99, 0x31}, 0x70},
214 {{0x98, 0x00}, 0x3f},
216 {{0x9f, 0x09}, 0x00},
218 {{0x9f, 0x0a}, 0x05},
220 {{0x9e, 0xd1}, 0xa1},
221 {{0x99, 0x23}, 0x00},
223 {{0x9e, 0x74}, 0x80},
225 {{0x9f, 0x28}, 0x10},
227 {{0x9f, 0x35}, 0x14},
229 {{0x9f, 0x36}, 0x60},
231 {{0x9c, 0x31}, 0x00},
233 {{0x9c, 0x32}, 0xc8},
235 {{0x9c, 0x19}, 0x40},
237 {{0x9c, 0x1a}, 0x40},
239 {{0x9c, 0x0c}, 0x00},
241 {{0x9c, 0x0d}, 0x00},
243 {{0x9c, 0x12}, 0x00},
245 {{0x9c, 0x13}, 0x00},
247 {{0x98, 0xa2}, 0x0e},
249 {{0x98, 0x93}, 0x40},
251 {{0x98, 0x7d}, 0x02},
252 {{0x98, 0x7e}, 0x00},
253 {{0x9f, 0xc8}, 0x01},
255 struct hw_config
*p
= hw_config
;
256 int count
= ARRAY_SIZE(hw_config
);
257 struct sk_buff
*res_skb
;
263 param
[1] = p
->adr
[0];
264 param
[2] = p
->adr
[1];
267 r
= nfc_hci_send_cmd(hdev
, PN544_SYS_MGMT_GATE
, PN544_WRITE
,
272 if (res_skb
->len
!= 1) {
277 if (res_skb
->data
[0] != p
->value
) {
287 param
[0] = NFC_HCI_UICC_HOST_ID
;
288 r
= nfc_hci_set_param(hdev
, NFC_HCI_ADMIN_GATE
,
289 NFC_HCI_ADMIN_WHITELIST
, param
, 1);
294 r
= nfc_hci_set_param(hdev
, PN544_SYS_MGMT_GATE
,
295 PN544_SYS_MGMT_INFO_NOTIFICATION
, param
, 1);
300 r
= nfc_hci_set_param(hdev
, NFC_HCI_RF_READER_A_GATE
,
301 PN544_RF_READER_A_AUTO_ACTIVATION
, param
, 1);
305 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
306 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
311 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
312 PN544_PL_NFCT_DEACTIVATED
, param
, 1);
317 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
318 PN544_PL_RDPHASES
, param
, 1);
322 r
= nfc_hci_get_param(hdev
, NFC_HCI_ID_MGMT_GATE
,
323 PN544_ID_MGMT_FULL_VERSION_SW
, &skb
);
327 if (skb
->len
!= FULL_VERSION_LEN
) {
332 print_hex_dump(KERN_DEBUG
, "FULL VERSION SOFTWARE INFO: ",
333 DUMP_PREFIX_NONE
, 16, 1,
334 skb
->data
, FULL_VERSION_LEN
, false);
341 static int pn544_hci_xmit(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
343 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
345 return info
->phy_ops
->write(info
->phy_id
, skb
);
348 static int pn544_hci_start_poll(struct nfc_hci_dev
*hdev
,
349 u32 im_protocols
, u32 tm_protocols
)
355 u8 i_mode
= 0x3f; /* Enable all supported modes */
357 u8 t_merge
= 0x01; /* Enable merge by default */
359 pr_info(DRIVER_DESC
": %s protocols 0x%x 0x%x\n",
360 __func__
, im_protocols
, tm_protocols
);
362 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
363 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
369 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
370 PN544_PL_EMULATION
, duration
, 2);
375 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
376 PN544_PL_NFCT_DEACTIVATED
, &activated
, 1);
380 if (im_protocols
& (NFC_PROTO_ISO14443_MASK
| NFC_PROTO_MIFARE_MASK
|
381 NFC_PROTO_JEWEL_MASK
))
382 phases
|= 1; /* Type A */
383 if (im_protocols
& NFC_PROTO_FELICA_MASK
) {
384 phases
|= (1 << 2); /* Type F 212 */
385 phases
|= (1 << 3); /* Type F 424 */
388 phases
|= (1 << 5); /* NFC active */
390 r
= nfc_hci_set_param(hdev
, PN544_POLLING_LOOP_MGMT_GATE
,
391 PN544_PL_RDPHASES
, &phases
, 1);
395 if ((im_protocols
| tm_protocols
) & NFC_PROTO_NFC_DEP_MASK
) {
396 hdev
->gb
= nfc_get_local_general_bytes(hdev
->ndev
,
398 pr_debug("generate local bytes %p", hdev
->gb
);
399 if (hdev
->gb
== NULL
|| hdev
->gb_len
== 0) {
400 im_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
401 tm_protocols
&= ~NFC_PROTO_NFC_DEP_MASK
;
405 if (im_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
406 r
= nfc_hci_send_event(hdev
,
407 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
408 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
412 r
= nfc_hci_set_param(hdev
,
413 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
414 PN544_DEP_MODE
, &i_mode
, 1);
418 r
= nfc_hci_set_param(hdev
,
419 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
420 PN544_DEP_ATR_REQ
, hdev
->gb
, hdev
->gb_len
);
424 r
= nfc_hci_send_event(hdev
,
425 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
426 NFC_HCI_EVT_READER_REQUESTED
, NULL
, 0);
428 nfc_hci_send_event(hdev
,
429 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
430 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
433 if (tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
434 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
435 PN544_DEP_MODE
, &t_mode
, 1);
439 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
440 PN544_DEP_ATR_RES
, hdev
->gb
, hdev
->gb_len
);
444 r
= nfc_hci_set_param(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
445 PN544_DEP_MERGE
, &t_merge
, 1);
450 r
= nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
451 NFC_HCI_EVT_READER_REQUESTED
, NULL
, 0);
453 nfc_hci_send_event(hdev
, NFC_HCI_RF_READER_A_GATE
,
454 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
459 static int pn544_hci_dep_link_up(struct nfc_hci_dev
*hdev
,
460 struct nfc_target
*target
, u8 comm_mode
,
461 u8
*gb
, size_t gb_len
)
463 struct sk_buff
*rgb_skb
= NULL
;
466 r
= nfc_hci_get_param(hdev
, target
->hci_reader_gate
,
467 PN544_DEP_ATR_RES
, &rgb_skb
);
471 if (rgb_skb
->len
== 0 || rgb_skb
->len
> NFC_GB_MAXSIZE
) {
475 print_hex_dump(KERN_DEBUG
, "remote gb: ", DUMP_PREFIX_OFFSET
,
476 16, 1, rgb_skb
->data
, rgb_skb
->len
, true);
478 r
= nfc_set_remote_general_bytes(hdev
->ndev
, rgb_skb
->data
,
482 r
= nfc_dep_link_is_up(hdev
->ndev
, target
->idx
, comm_mode
,
489 static int pn544_hci_dep_link_down(struct nfc_hci_dev
*hdev
)
492 return nfc_hci_send_event(hdev
, PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
493 NFC_HCI_EVT_END_OPERATION
, NULL
, 0);
496 static int pn544_hci_target_from_gate(struct nfc_hci_dev
*hdev
, u8 gate
,
497 struct nfc_target
*target
)
500 case PN544_RF_READER_F_GATE
:
501 target
->supported_protocols
= NFC_PROTO_FELICA_MASK
;
503 case PN544_RF_READER_JEWEL_GATE
:
504 target
->supported_protocols
= NFC_PROTO_JEWEL_MASK
;
505 target
->sens_res
= 0x0c00;
507 case PN544_RF_READER_NFCIP1_INITIATOR_GATE
:
508 target
->supported_protocols
= NFC_PROTO_NFC_DEP_MASK
;
517 static int pn544_hci_complete_target_discovered(struct nfc_hci_dev
*hdev
,
519 struct nfc_target
*target
)
521 struct sk_buff
*uid_skb
;
524 if (gate
== PN544_RF_READER_NFCIP1_INITIATOR_GATE
)
527 if (target
->supported_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
528 r
= nfc_hci_send_cmd(hdev
,
529 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
530 PN544_HCI_CMD_CONTINUE_ACTIVATION
, NULL
, 0, NULL
);
534 target
->hci_reader_gate
= PN544_RF_READER_NFCIP1_INITIATOR_GATE
;
535 } else if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
536 if (target
->nfcid1_len
!= 4 && target
->nfcid1_len
!= 7 &&
537 target
->nfcid1_len
!= 10)
540 r
= nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
541 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
542 target
->nfcid1
, target
->nfcid1_len
, NULL
);
543 } else if (target
->supported_protocols
& NFC_PROTO_FELICA_MASK
) {
544 r
= nfc_hci_get_param(hdev
, PN544_RF_READER_F_GATE
,
545 PN544_FELICA_ID
, &uid_skb
);
549 if (uid_skb
->len
!= 8) {
554 r
= nfc_hci_send_cmd(hdev
, PN544_RF_READER_F_GATE
,
555 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
556 uid_skb
->data
, uid_skb
->len
, NULL
);
559 r
= nfc_hci_send_cmd(hdev
,
560 PN544_RF_READER_NFCIP1_INITIATOR_GATE
,
561 PN544_HCI_CMD_CONTINUE_ACTIVATION
,
566 target
->hci_reader_gate
= PN544_RF_READER_NFCIP1_INITIATOR_GATE
;
567 target
->supported_protocols
= NFC_PROTO_NFC_DEP_MASK
;
568 } else if (target
->supported_protocols
& NFC_PROTO_ISO14443_MASK
) {
570 * TODO: maybe other ISO 14443 require some kind of continue
571 * activation, but for now we've seen only this one below.
573 if (target
->sens_res
== 0x4403) /* Type 4 Mifare DESFire */
574 r
= nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
575 PN544_RF_READER_A_CMD_CONTINUE_ACTIVATION
,
582 #define PN544_CB_TYPE_READER_F 1
584 static void pn544_hci_data_exchange_cb(void *context
, struct sk_buff
*skb
,
587 struct pn544_hci_info
*info
= context
;
589 switch (info
->async_cb_type
) {
590 case PN544_CB_TYPE_READER_F
:
593 info
->async_cb(info
->async_cb_context
, skb
, err
);
602 #define MIFARE_CMD_AUTH_KEY_A 0x60
603 #define MIFARE_CMD_AUTH_KEY_B 0x61
604 #define MIFARE_CMD_HEADER 2
605 #define MIFARE_UID_LEN 4
606 #define MIFARE_KEY_LEN 6
607 #define MIFARE_CMD_LEN 12
610 * <= 0: driver handled the data exchange
611 * 1: driver doesn't especially handle, please do standard processing
613 static int pn544_hci_im_transceive(struct nfc_hci_dev
*hdev
,
614 struct nfc_target
*target
,
615 struct sk_buff
*skb
, data_exchange_cb_t cb
,
618 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
620 pr_info(DRIVER_DESC
": %s for gate=%d\n", __func__
,
621 target
->hci_reader_gate
);
623 switch (target
->hci_reader_gate
) {
624 case NFC_HCI_RF_READER_A_GATE
:
625 if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
627 * It seems that pn544 is inverting key and UID for
628 * MIFARE authentication commands.
630 if (skb
->len
== MIFARE_CMD_LEN
&&
631 (skb
->data
[0] == MIFARE_CMD_AUTH_KEY_A
||
632 skb
->data
[0] == MIFARE_CMD_AUTH_KEY_B
)) {
633 u8 uid
[MIFARE_UID_LEN
];
634 u8
*data
= skb
->data
+ MIFARE_CMD_HEADER
;
636 memcpy(uid
, data
+ MIFARE_KEY_LEN
,
638 memmove(data
+ MIFARE_UID_LEN
, data
,
640 memcpy(data
, uid
, MIFARE_UID_LEN
);
643 return nfc_hci_send_cmd_async(hdev
,
644 target
->hci_reader_gate
,
650 case PN544_RF_READER_F_GATE
:
651 *skb_push(skb
, 1) = 0;
652 *skb_push(skb
, 1) = 0;
654 info
->async_cb_type
= PN544_CB_TYPE_READER_F
;
656 info
->async_cb_context
= cb_context
;
658 return nfc_hci_send_cmd_async(hdev
, target
->hci_reader_gate
,
659 PN544_FELICA_RAW
, skb
->data
,
661 pn544_hci_data_exchange_cb
, info
);
662 case PN544_RF_READER_JEWEL_GATE
:
663 return nfc_hci_send_cmd_async(hdev
, target
->hci_reader_gate
,
664 PN544_JEWEL_RAW_CMD
, skb
->data
,
665 skb
->len
, cb
, cb_context
);
666 case PN544_RF_READER_NFCIP1_INITIATOR_GATE
:
667 *skb_push(skb
, 1) = 0;
669 return nfc_hci_send_event(hdev
, target
->hci_reader_gate
,
670 PN544_HCI_EVT_SND_DATA
, skb
->data
,
677 static int pn544_hci_tm_send(struct nfc_hci_dev
*hdev
, struct sk_buff
*skb
)
681 /* Set default false for multiple information chaining */
682 *skb_push(skb
, 1) = 0;
684 r
= nfc_hci_send_event(hdev
, PN544_RF_READER_NFCIP1_TARGET_GATE
,
685 PN544_HCI_EVT_SND_DATA
, skb
->data
, skb
->len
);
692 static int pn544_hci_check_presence(struct nfc_hci_dev
*hdev
,
693 struct nfc_target
*target
)
695 pr_debug("supported protocol %d", target
->supported_protocols
);
696 if (target
->supported_protocols
& (NFC_PROTO_ISO14443_MASK
|
697 NFC_PROTO_ISO14443_B_MASK
)) {
698 return nfc_hci_send_cmd(hdev
, target
->hci_reader_gate
,
699 PN544_RF_READER_CMD_PRESENCE_CHECK
,
701 } else if (target
->supported_protocols
& NFC_PROTO_MIFARE_MASK
) {
702 if (target
->nfcid1_len
!= 4 && target
->nfcid1_len
!= 7 &&
703 target
->nfcid1_len
!= 10)
706 return nfc_hci_send_cmd(hdev
, NFC_HCI_RF_READER_A_GATE
,
707 PN544_RF_READER_CMD_ACTIVATE_NEXT
,
708 target
->nfcid1
, target
->nfcid1_len
, NULL
);
709 } else if (target
->supported_protocols
& NFC_PROTO_JEWEL_MASK
) {
710 return nfc_hci_send_cmd(hdev
, target
->hci_reader_gate
,
711 PN544_JEWEL_RAW_CMD
, NULL
, 0, NULL
);
712 } else if (target
->supported_protocols
& NFC_PROTO_FELICA_MASK
) {
713 return nfc_hci_send_cmd(hdev
, PN544_RF_READER_F_GATE
,
714 PN544_FELICA_RAW
, NULL
, 0, NULL
);
715 } else if (target
->supported_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
716 return nfc_hci_send_cmd(hdev
, target
->hci_reader_gate
,
717 PN544_HCI_CMD_ATTREQUEST
,
726 * <= 0: driver handled the event, skb consumed
727 * 1: driver does not handle the event, please do standard processing
729 static int pn544_hci_event_received(struct nfc_hci_dev
*hdev
, u8 gate
, u8 event
,
732 struct sk_buff
*rgb_skb
= NULL
;
735 pr_debug("hci event %d", event
);
737 case PN544_HCI_EVT_ACTIVATED
:
738 if (gate
== PN544_RF_READER_NFCIP1_INITIATOR_GATE
) {
739 r
= nfc_hci_target_discovered(hdev
, gate
);
740 } else if (gate
== PN544_RF_READER_NFCIP1_TARGET_GATE
) {
741 r
= nfc_hci_get_param(hdev
, gate
, PN544_DEP_ATR_REQ
,
746 r
= nfc_tm_activated(hdev
->ndev
, NFC_PROTO_NFC_DEP_MASK
,
747 NFC_COMM_PASSIVE
, rgb_skb
->data
,
755 case PN544_HCI_EVT_DEACTIVATED
:
756 r
= nfc_hci_send_event(hdev
, gate
, NFC_HCI_EVT_END_OPERATION
,
759 case PN544_HCI_EVT_RCV_DATA
:
765 if (skb
->data
[0] != 0) {
766 pr_debug("data0 %d", skb
->data
[0]);
772 return nfc_tm_data_received(hdev
->ndev
, skb
);
783 static struct nfc_hci_ops pn544_hci_ops
= {
784 .open
= pn544_hci_open
,
785 .close
= pn544_hci_close
,
786 .hci_ready
= pn544_hci_ready
,
787 .xmit
= pn544_hci_xmit
,
788 .start_poll
= pn544_hci_start_poll
,
789 .dep_link_up
= pn544_hci_dep_link_up
,
790 .dep_link_down
= pn544_hci_dep_link_down
,
791 .target_from_gate
= pn544_hci_target_from_gate
,
792 .complete_target_discovered
= pn544_hci_complete_target_discovered
,
793 .im_transceive
= pn544_hci_im_transceive
,
794 .tm_send
= pn544_hci_tm_send
,
795 .check_presence
= pn544_hci_check_presence
,
796 .event_received
= pn544_hci_event_received
,
799 int pn544_hci_probe(void *phy_id
, struct nfc_phy_ops
*phy_ops
, char *llc_name
,
800 int phy_headroom
, int phy_tailroom
, int phy_payload
,
801 struct nfc_hci_dev
**hdev
)
803 struct pn544_hci_info
*info
;
805 struct nfc_hci_init_data init_data
;
808 info
= kzalloc(sizeof(struct pn544_hci_info
), GFP_KERNEL
);
810 pr_err("Cannot allocate memory for pn544_hci_info.\n");
815 info
->phy_ops
= phy_ops
;
816 info
->phy_id
= phy_id
;
817 info
->state
= PN544_ST_COLD
;
818 mutex_init(&info
->info_lock
);
820 init_data
.gate_count
= ARRAY_SIZE(pn544_gates
);
822 memcpy(init_data
.gates
, pn544_gates
, sizeof(pn544_gates
));
825 * TODO: Session id must include the driver name + some bus addr
826 * persistent info to discriminate 2 identical chips
828 strcpy(init_data
.session_id
, "ID544HCI");
830 protocols
= NFC_PROTO_JEWEL_MASK
|
831 NFC_PROTO_MIFARE_MASK
|
832 NFC_PROTO_FELICA_MASK
|
833 NFC_PROTO_ISO14443_MASK
|
834 NFC_PROTO_ISO14443_B_MASK
|
835 NFC_PROTO_NFC_DEP_MASK
;
837 se
= NFC_SE_UICC
| NFC_SE_EMBEDDED
;
839 info
->hdev
= nfc_hci_allocate_device(&pn544_hci_ops
, &init_data
, 0,
840 protocols
, se
, llc_name
,
841 phy_headroom
+ PN544_CMDS_HEADROOM
,
842 phy_tailroom
, phy_payload
);
844 pr_err("Cannot allocate nfc hdev.\n");
849 nfc_hci_set_clientdata(info
->hdev
, info
);
851 r
= nfc_hci_register_device(info
->hdev
);
860 nfc_hci_free_device(info
->hdev
);
868 EXPORT_SYMBOL(pn544_hci_probe
);
870 void pn544_hci_remove(struct nfc_hci_dev
*hdev
)
872 struct pn544_hci_info
*info
= nfc_hci_get_clientdata(hdev
);
874 nfc_hci_unregister_device(hdev
);
875 nfc_hci_free_device(hdev
);
878 EXPORT_SYMBOL(pn544_hci_remove
);
880 MODULE_LICENSE("GPL");
881 MODULE_DESCRIPTION(DRIVER_DESC
);