2 * Sony NFC Port-100 Series driver
3 * Copyright (c) 2013, Intel Corporation.
5 * Partly based/Inspired by Stephen Tiedemann's nfcpy
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 #include <linux/module.h>
19 #include <linux/usb.h>
20 #include <net/nfc/digital.h>
24 #define SONY_VENDOR_ID 0x054c
25 #define RCS380_PRODUCT_ID 0x06c1
27 #define PORT100_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
28 NFC_PROTO_MIFARE_MASK | \
29 NFC_PROTO_FELICA_MASK | \
30 NFC_PROTO_NFC_DEP_MASK | \
31 NFC_PROTO_ISO14443_MASK | \
32 NFC_PROTO_ISO14443_B_MASK)
34 #define PORT100_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC | \
35 NFC_DIGITAL_DRV_CAPS_TG_CRC)
37 /* Standard port100 frame definitions */
38 #define PORT100_FRAME_HEADER_LEN (sizeof(struct port100_frame) \
39 + 2) /* data[0] CC, data[1] SCC */
40 #define PORT100_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/
42 #define PORT100_COMM_RF_HEAD_MAX_LEN (sizeof(struct port100_tg_comm_rf_cmd))
45 * Max extended frame payload len, excluding CC and SCC
46 * which are already in PORT100_FRAME_HEADER_LEN.
48 #define PORT100_FRAME_MAX_PAYLOAD_LEN 1001
50 #define PORT100_FRAME_ACK_SIZE 6 /* Preamble (1), SoPC (2), ACK Code (2),
52 static u8 ack_frame
[PORT100_FRAME_ACK_SIZE
] = {
53 0x00, 0x00, 0xff, 0x00, 0xff, 0x00
56 #define PORT100_FRAME_CHECKSUM(f) (f->data[le16_to_cpu(f->datalen)])
57 #define PORT100_FRAME_POSTAMBLE(f) (f->data[le16_to_cpu(f->datalen) + 1])
60 #define PORT100_FRAME_SOF 0x00FF
61 #define PORT100_FRAME_EXT 0xFFFF
62 #define PORT100_FRAME_ACK 0x00FF
64 /* Port-100 command: in or out */
65 #define PORT100_FRAME_DIRECTION(f) (f->data[0]) /* CC */
66 #define PORT100_FRAME_DIR_OUT 0xD6
67 #define PORT100_FRAME_DIR_IN 0xD7
69 /* Port-100 sub-command */
70 #define PORT100_FRAME_CMD(f) (f->data[1]) /* SCC */
72 #define PORT100_CMD_GET_FIRMWARE_VERSION 0x20
73 #define PORT100_CMD_GET_COMMAND_TYPE 0x28
74 #define PORT100_CMD_SET_COMMAND_TYPE 0x2A
76 #define PORT100_CMD_IN_SET_RF 0x00
77 #define PORT100_CMD_IN_SET_PROTOCOL 0x02
78 #define PORT100_CMD_IN_COMM_RF 0x04
80 #define PORT100_CMD_TG_SET_RF 0x40
81 #define PORT100_CMD_TG_SET_PROTOCOL 0x42
82 #define PORT100_CMD_TG_SET_RF_OFF 0x46
83 #define PORT100_CMD_TG_COMM_RF 0x48
85 #define PORT100_CMD_SWITCH_RF 0x06
87 #define PORT100_CMD_RESPONSE(cmd) (cmd + 1)
89 #define PORT100_CMD_TYPE_IS_SUPPORTED(mask, cmd_type) \
90 ((mask) & (0x01 << (cmd_type)))
91 #define PORT100_CMD_TYPE_0 0
92 #define PORT100_CMD_TYPE_1 1
94 #define PORT100_CMD_STATUS_OK 0x00
95 #define PORT100_CMD_STATUS_TIMEOUT 0x80
97 #define PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK 0x01
98 #define PORT100_MDAA_TGT_WAS_ACTIVATED_MASK 0x02
102 typedef void (*port100_send_async_complete_t
)(struct port100
*dev
, void *arg
,
103 struct sk_buff
*resp
);
106 * Setting sets structure for in_set_rf command
108 * @in_*_set_number: Represent the entry indexes in the port-100 RF Base Table.
109 * This table contains multiple RF setting sets required for RF
112 * @in_*_comm_type: Theses fields set the communication type to be used.
114 struct port100_in_rf_setting
{
115 u8 in_send_set_number
;
116 u8 in_send_comm_type
;
117 u8 in_recv_set_number
;
118 u8 in_recv_comm_type
;
121 #define PORT100_COMM_TYPE_IN_212F 0x01
122 #define PORT100_COMM_TYPE_IN_424F 0x02
123 #define PORT100_COMM_TYPE_IN_106A 0x03
124 #define PORT100_COMM_TYPE_IN_106B 0x07
126 static const struct port100_in_rf_setting in_rf_settings
[] = {
127 [NFC_DIGITAL_RF_TECH_212F
] = {
128 .in_send_set_number
= 1,
129 .in_send_comm_type
= PORT100_COMM_TYPE_IN_212F
,
130 .in_recv_set_number
= 15,
131 .in_recv_comm_type
= PORT100_COMM_TYPE_IN_212F
,
133 [NFC_DIGITAL_RF_TECH_424F
] = {
134 .in_send_set_number
= 1,
135 .in_send_comm_type
= PORT100_COMM_TYPE_IN_424F
,
136 .in_recv_set_number
= 15,
137 .in_recv_comm_type
= PORT100_COMM_TYPE_IN_424F
,
139 [NFC_DIGITAL_RF_TECH_106A
] = {
140 .in_send_set_number
= 2,
141 .in_send_comm_type
= PORT100_COMM_TYPE_IN_106A
,
142 .in_recv_set_number
= 15,
143 .in_recv_comm_type
= PORT100_COMM_TYPE_IN_106A
,
145 [NFC_DIGITAL_RF_TECH_106B
] = {
146 .in_send_set_number
= 3,
147 .in_send_comm_type
= PORT100_COMM_TYPE_IN_106B
,
148 .in_recv_set_number
= 15,
149 .in_recv_comm_type
= PORT100_COMM_TYPE_IN_106B
,
151 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */
152 [NFC_DIGITAL_RF_TECH_LAST
] = { 0 },
156 * Setting sets structure for tg_set_rf command
158 * @tg_set_number: Represents the entry index in the port-100 RF Base Table.
159 * This table contains multiple RF setting sets required for RF
160 * communication. this field is used for both send and receive
163 * @tg_comm_type: Sets the communication type to be used to send and receive
166 struct port100_tg_rf_setting
{
171 #define PORT100_COMM_TYPE_TG_106A 0x0B
172 #define PORT100_COMM_TYPE_TG_212F 0x0C
173 #define PORT100_COMM_TYPE_TG_424F 0x0D
175 static const struct port100_tg_rf_setting tg_rf_settings
[] = {
176 [NFC_DIGITAL_RF_TECH_106A
] = {
178 .tg_comm_type
= PORT100_COMM_TYPE_TG_106A
,
180 [NFC_DIGITAL_RF_TECH_212F
] = {
182 .tg_comm_type
= PORT100_COMM_TYPE_TG_212F
,
184 [NFC_DIGITAL_RF_TECH_424F
] = {
186 .tg_comm_type
= PORT100_COMM_TYPE_TG_424F
,
188 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */
189 [NFC_DIGITAL_RF_TECH_LAST
] = { 0 },
193 #define PORT100_IN_PROT_INITIAL_GUARD_TIME 0x00
194 #define PORT100_IN_PROT_ADD_CRC 0x01
195 #define PORT100_IN_PROT_CHECK_CRC 0x02
196 #define PORT100_IN_PROT_MULTI_CARD 0x03
197 #define PORT100_IN_PROT_ADD_PARITY 0x04
198 #define PORT100_IN_PROT_CHECK_PARITY 0x05
199 #define PORT100_IN_PROT_BITWISE_AC_RECV_MODE 0x06
200 #define PORT100_IN_PROT_VALID_BIT_NUMBER 0x07
201 #define PORT100_IN_PROT_CRYPTO1 0x08
202 #define PORT100_IN_PROT_ADD_SOF 0x09
203 #define PORT100_IN_PROT_CHECK_SOF 0x0A
204 #define PORT100_IN_PROT_ADD_EOF 0x0B
205 #define PORT100_IN_PROT_CHECK_EOF 0x0C
206 #define PORT100_IN_PROT_DEAF_TIME 0x0E
207 #define PORT100_IN_PROT_CRM 0x0F
208 #define PORT100_IN_PROT_CRM_MIN_LEN 0x10
209 #define PORT100_IN_PROT_T1_TAG_FRAME 0x11
210 #define PORT100_IN_PROT_RFCA 0x12
211 #define PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR 0x13
212 #define PORT100_IN_PROT_END 0x14
214 #define PORT100_IN_MAX_NUM_PROTOCOLS 19
216 #define PORT100_TG_PROT_TU 0x00
217 #define PORT100_TG_PROT_RF_OFF 0x01
218 #define PORT100_TG_PROT_CRM 0x02
219 #define PORT100_TG_PROT_END 0x03
221 #define PORT100_TG_MAX_NUM_PROTOCOLS 3
223 struct port100_protocol
{
228 static struct port100_protocol
229 in_protocols
[][PORT100_IN_MAX_NUM_PROTOCOLS
+ 1] = {
230 [NFC_DIGITAL_FRAMING_NFCA_SHORT
] = {
231 { PORT100_IN_PROT_INITIAL_GUARD_TIME
, 6 },
232 { PORT100_IN_PROT_ADD_CRC
, 0 },
233 { PORT100_IN_PROT_CHECK_CRC
, 0 },
234 { PORT100_IN_PROT_MULTI_CARD
, 0 },
235 { PORT100_IN_PROT_ADD_PARITY
, 0 },
236 { PORT100_IN_PROT_CHECK_PARITY
, 1 },
237 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE
, 0 },
238 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 7 },
239 { PORT100_IN_PROT_CRYPTO1
, 0 },
240 { PORT100_IN_PROT_ADD_SOF
, 0 },
241 { PORT100_IN_PROT_CHECK_SOF
, 0 },
242 { PORT100_IN_PROT_ADD_EOF
, 0 },
243 { PORT100_IN_PROT_CHECK_EOF
, 0 },
244 { PORT100_IN_PROT_DEAF_TIME
, 4 },
245 { PORT100_IN_PROT_CRM
, 0 },
246 { PORT100_IN_PROT_CRM_MIN_LEN
, 0 },
247 { PORT100_IN_PROT_T1_TAG_FRAME
, 0 },
248 { PORT100_IN_PROT_RFCA
, 0 },
249 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR
, 6 },
250 { PORT100_IN_PROT_END
, 0 },
252 [NFC_DIGITAL_FRAMING_NFCA_STANDARD
] = {
253 { PORT100_IN_PROT_INITIAL_GUARD_TIME
, 6 },
254 { PORT100_IN_PROT_ADD_CRC
, 0 },
255 { PORT100_IN_PROT_CHECK_CRC
, 0 },
256 { PORT100_IN_PROT_MULTI_CARD
, 0 },
257 { PORT100_IN_PROT_ADD_PARITY
, 1 },
258 { PORT100_IN_PROT_CHECK_PARITY
, 1 },
259 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE
, 0 },
260 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 8 },
261 { PORT100_IN_PROT_CRYPTO1
, 0 },
262 { PORT100_IN_PROT_ADD_SOF
, 0 },
263 { PORT100_IN_PROT_CHECK_SOF
, 0 },
264 { PORT100_IN_PROT_ADD_EOF
, 0 },
265 { PORT100_IN_PROT_CHECK_EOF
, 0 },
266 { PORT100_IN_PROT_DEAF_TIME
, 4 },
267 { PORT100_IN_PROT_CRM
, 0 },
268 { PORT100_IN_PROT_CRM_MIN_LEN
, 0 },
269 { PORT100_IN_PROT_T1_TAG_FRAME
, 0 },
270 { PORT100_IN_PROT_RFCA
, 0 },
271 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR
, 6 },
272 { PORT100_IN_PROT_END
, 0 },
274 [NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A
] = {
275 { PORT100_IN_PROT_INITIAL_GUARD_TIME
, 6 },
276 { PORT100_IN_PROT_ADD_CRC
, 1 },
277 { PORT100_IN_PROT_CHECK_CRC
, 1 },
278 { PORT100_IN_PROT_MULTI_CARD
, 0 },
279 { PORT100_IN_PROT_ADD_PARITY
, 1 },
280 { PORT100_IN_PROT_CHECK_PARITY
, 1 },
281 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE
, 0 },
282 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 8 },
283 { PORT100_IN_PROT_CRYPTO1
, 0 },
284 { PORT100_IN_PROT_ADD_SOF
, 0 },
285 { PORT100_IN_PROT_CHECK_SOF
, 0 },
286 { PORT100_IN_PROT_ADD_EOF
, 0 },
287 { PORT100_IN_PROT_CHECK_EOF
, 0 },
288 { PORT100_IN_PROT_DEAF_TIME
, 4 },
289 { PORT100_IN_PROT_CRM
, 0 },
290 { PORT100_IN_PROT_CRM_MIN_LEN
, 0 },
291 { PORT100_IN_PROT_T1_TAG_FRAME
, 0 },
292 { PORT100_IN_PROT_RFCA
, 0 },
293 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR
, 6 },
294 { PORT100_IN_PROT_END
, 0 },
296 [NFC_DIGITAL_FRAMING_NFCA_T1T
] = {
297 /* nfc_digital_framing_nfca_short */
298 { PORT100_IN_PROT_ADD_CRC
, 2 },
299 { PORT100_IN_PROT_CHECK_CRC
, 2 },
300 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 8 },
301 { PORT100_IN_PROT_T1_TAG_FRAME
, 2 },
302 { PORT100_IN_PROT_END
, 0 },
304 [NFC_DIGITAL_FRAMING_NFCA_T2T
] = {
305 /* nfc_digital_framing_nfca_standard */
306 { PORT100_IN_PROT_ADD_CRC
, 1 },
307 { PORT100_IN_PROT_CHECK_CRC
, 0 },
308 { PORT100_IN_PROT_END
, 0 },
310 [NFC_DIGITAL_FRAMING_NFCA_T4T
] = {
311 /* nfc_digital_framing_nfca_standard_with_crc_a */
312 { PORT100_IN_PROT_END
, 0 },
314 [NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
] = {
315 /* nfc_digital_framing_nfca_standard */
316 { PORT100_IN_PROT_END
, 0 },
318 [NFC_DIGITAL_FRAMING_NFCF
] = {
319 { PORT100_IN_PROT_INITIAL_GUARD_TIME
, 18 },
320 { PORT100_IN_PROT_ADD_CRC
, 1 },
321 { PORT100_IN_PROT_CHECK_CRC
, 1 },
322 { PORT100_IN_PROT_MULTI_CARD
, 0 },
323 { PORT100_IN_PROT_ADD_PARITY
, 0 },
324 { PORT100_IN_PROT_CHECK_PARITY
, 0 },
325 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE
, 0 },
326 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 8 },
327 { PORT100_IN_PROT_CRYPTO1
, 0 },
328 { PORT100_IN_PROT_ADD_SOF
, 0 },
329 { PORT100_IN_PROT_CHECK_SOF
, 0 },
330 { PORT100_IN_PROT_ADD_EOF
, 0 },
331 { PORT100_IN_PROT_CHECK_EOF
, 0 },
332 { PORT100_IN_PROT_DEAF_TIME
, 4 },
333 { PORT100_IN_PROT_CRM
, 0 },
334 { PORT100_IN_PROT_CRM_MIN_LEN
, 0 },
335 { PORT100_IN_PROT_T1_TAG_FRAME
, 0 },
336 { PORT100_IN_PROT_RFCA
, 0 },
337 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR
, 6 },
338 { PORT100_IN_PROT_END
, 0 },
340 [NFC_DIGITAL_FRAMING_NFCF_T3T
] = {
341 /* nfc_digital_framing_nfcf */
342 { PORT100_IN_PROT_END
, 0 },
344 [NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
] = {
345 /* nfc_digital_framing_nfcf */
346 { PORT100_IN_PROT_END
, 0 },
348 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED
] = {
349 { PORT100_IN_PROT_END
, 0 },
351 [NFC_DIGITAL_FRAMING_NFCB
] = {
352 { PORT100_IN_PROT_INITIAL_GUARD_TIME
, 20 },
353 { PORT100_IN_PROT_ADD_CRC
, 1 },
354 { PORT100_IN_PROT_CHECK_CRC
, 1 },
355 { PORT100_IN_PROT_MULTI_CARD
, 0 },
356 { PORT100_IN_PROT_ADD_PARITY
, 0 },
357 { PORT100_IN_PROT_CHECK_PARITY
, 0 },
358 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE
, 0 },
359 { PORT100_IN_PROT_VALID_BIT_NUMBER
, 8 },
360 { PORT100_IN_PROT_CRYPTO1
, 0 },
361 { PORT100_IN_PROT_ADD_SOF
, 1 },
362 { PORT100_IN_PROT_CHECK_SOF
, 1 },
363 { PORT100_IN_PROT_ADD_EOF
, 1 },
364 { PORT100_IN_PROT_CHECK_EOF
, 1 },
365 { PORT100_IN_PROT_DEAF_TIME
, 4 },
366 { PORT100_IN_PROT_CRM
, 0 },
367 { PORT100_IN_PROT_CRM_MIN_LEN
, 0 },
368 { PORT100_IN_PROT_T1_TAG_FRAME
, 0 },
369 { PORT100_IN_PROT_RFCA
, 0 },
370 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR
, 6 },
371 { PORT100_IN_PROT_END
, 0 },
373 [NFC_DIGITAL_FRAMING_NFCB_T4T
] = {
374 /* nfc_digital_framing_nfcb */
375 { PORT100_IN_PROT_END
, 0 },
377 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */
378 [NFC_DIGITAL_FRAMING_LAST
] = {
379 { PORT100_IN_PROT_END
, 0 },
383 static struct port100_protocol
384 tg_protocols
[][PORT100_TG_MAX_NUM_PROTOCOLS
+ 1] = {
385 [NFC_DIGITAL_FRAMING_NFCA_SHORT
] = {
386 { PORT100_TG_PROT_END
, 0 },
388 [NFC_DIGITAL_FRAMING_NFCA_STANDARD
] = {
389 { PORT100_TG_PROT_END
, 0 },
391 [NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A
] = {
392 { PORT100_TG_PROT_END
, 0 },
394 [NFC_DIGITAL_FRAMING_NFCA_T1T
] = {
395 { PORT100_TG_PROT_END
, 0 },
397 [NFC_DIGITAL_FRAMING_NFCA_T2T
] = {
398 { PORT100_TG_PROT_END
, 0 },
400 [NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
] = {
401 { PORT100_TG_PROT_TU
, 1 },
402 { PORT100_TG_PROT_RF_OFF
, 0 },
403 { PORT100_TG_PROT_CRM
, 7 },
404 { PORT100_TG_PROT_END
, 0 },
406 [NFC_DIGITAL_FRAMING_NFCF
] = {
407 { PORT100_TG_PROT_END
, 0 },
409 [NFC_DIGITAL_FRAMING_NFCF_T3T
] = {
410 { PORT100_TG_PROT_END
, 0 },
412 [NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
] = {
413 { PORT100_TG_PROT_TU
, 1 },
414 { PORT100_TG_PROT_RF_OFF
, 0 },
415 { PORT100_TG_PROT_CRM
, 7 },
416 { PORT100_TG_PROT_END
, 0 },
418 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED
] = {
419 { PORT100_TG_PROT_RF_OFF
, 1 },
420 { PORT100_TG_PROT_END
, 0 },
422 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */
423 [NFC_DIGITAL_FRAMING_LAST
] = {
424 { PORT100_TG_PROT_END
, 0 },
429 struct nfc_digital_dev
*nfc_digital_dev
;
434 struct usb_device
*udev
;
435 struct usb_interface
*interface
;
440 struct work_struct cmd_complete_work
;
444 /* The digital stack serializes commands to be sent. There is no need
445 * for any queuing/locking mechanism at driver level.
447 struct port100_cmd
*cmd
;
454 struct sk_buff
*resp
;
456 port100_send_async_complete_t complete_cb
;
457 void *complete_cb_context
;
460 struct port100_frame
{
463 __be16 extended_frame
;
469 struct port100_ack_frame
{
476 struct port100_cb_arg
{
477 nfc_digital_cmd_complete_t complete_cb
;
482 struct port100_tg_comm_rf_cmd
{
494 struct port100_tg_comm_rf_res
{
502 /* The rule: value + checksum = 0 */
503 static inline u8
port100_checksum(u16 value
)
505 return ~(((u8
*)&value
)[0] + ((u8
*)&value
)[1]) + 1;
508 /* The rule: sum(data elements) + checksum = 0 */
509 static u8
port100_data_checksum(u8
*data
, int datalen
)
514 for (i
= 0; i
< datalen
; i
++)
517 return port100_checksum(sum
);
520 static void port100_tx_frame_init(void *_frame
, u8 cmd_code
)
522 struct port100_frame
*frame
= _frame
;
525 frame
->start_frame
= cpu_to_be16(PORT100_FRAME_SOF
);
526 frame
->extended_frame
= cpu_to_be16(PORT100_FRAME_EXT
);
527 PORT100_FRAME_DIRECTION(frame
) = PORT100_FRAME_DIR_OUT
;
528 PORT100_FRAME_CMD(frame
) = cmd_code
;
529 frame
->datalen
= cpu_to_le16(2);
532 static void port100_tx_frame_finish(void *_frame
)
534 struct port100_frame
*frame
= _frame
;
536 frame
->datalen_checksum
= port100_checksum(le16_to_cpu(frame
->datalen
));
538 PORT100_FRAME_CHECKSUM(frame
) =
539 port100_data_checksum(frame
->data
, le16_to_cpu(frame
->datalen
));
541 PORT100_FRAME_POSTAMBLE(frame
) = 0;
544 static void port100_tx_update_payload_len(void *_frame
, int len
)
546 struct port100_frame
*frame
= _frame
;
548 frame
->datalen
= cpu_to_le16(le16_to_cpu(frame
->datalen
) + len
);
551 static bool port100_rx_frame_is_valid(void *_frame
)
554 struct port100_frame
*frame
= _frame
;
556 if (frame
->start_frame
!= cpu_to_be16(PORT100_FRAME_SOF
) ||
557 frame
->extended_frame
!= cpu_to_be16(PORT100_FRAME_EXT
))
560 checksum
= port100_checksum(le16_to_cpu(frame
->datalen
));
561 if (checksum
!= frame
->datalen_checksum
)
564 checksum
= port100_data_checksum(frame
->data
,
565 le16_to_cpu(frame
->datalen
));
566 if (checksum
!= PORT100_FRAME_CHECKSUM(frame
))
572 static bool port100_rx_frame_is_ack(struct port100_ack_frame
*frame
)
574 return (frame
->start_frame
== cpu_to_be16(PORT100_FRAME_SOF
) &&
575 frame
->ack_frame
== cpu_to_be16(PORT100_FRAME_ACK
));
578 static inline int port100_rx_frame_size(void *frame
)
580 struct port100_frame
*f
= frame
;
582 return sizeof(struct port100_frame
) + le16_to_cpu(f
->datalen
) +
583 PORT100_FRAME_TAIL_LEN
;
586 static bool port100_rx_frame_is_cmd_response(struct port100
*dev
, void *frame
)
588 struct port100_frame
*f
= frame
;
590 return (PORT100_FRAME_CMD(f
) == PORT100_CMD_RESPONSE(dev
->cmd
->code
));
593 static void port100_recv_response(struct urb
*urb
)
595 struct port100
*dev
= urb
->context
;
596 struct port100_cmd
*cmd
= dev
->cmd
;
599 cmd
->status
= urb
->status
;
601 switch (urb
->status
) {
606 nfc_err(&dev
->interface
->dev
,
607 "The urb has been canceled (status %d)", urb
->status
);
611 nfc_err(&dev
->interface
->dev
, "Urb failure (status %d)",
616 in_frame
= dev
->in_urb
->transfer_buffer
;
618 if (!port100_rx_frame_is_valid(in_frame
)) {
619 nfc_err(&dev
->interface
->dev
, "Received an invalid frame");
624 print_hex_dump_debug("PORT100 RX: ", DUMP_PREFIX_NONE
, 16, 1, in_frame
,
625 port100_rx_frame_size(in_frame
), false);
627 if (!port100_rx_frame_is_cmd_response(dev
, in_frame
)) {
628 nfc_err(&dev
->interface
->dev
,
629 "It's not the response to the last command");
635 schedule_work(&dev
->cmd_complete_work
);
638 static int port100_submit_urb_for_response(struct port100
*dev
, gfp_t flags
)
640 dev
->in_urb
->complete
= port100_recv_response
;
642 return usb_submit_urb(dev
->in_urb
, flags
);
645 static void port100_recv_ack(struct urb
*urb
)
647 struct port100
*dev
= urb
->context
;
648 struct port100_cmd
*cmd
= dev
->cmd
;
649 struct port100_ack_frame
*in_frame
;
652 cmd
->status
= urb
->status
;
654 switch (urb
->status
) {
659 nfc_err(&dev
->interface
->dev
,
660 "The urb has been stopped (status %d)", urb
->status
);
664 nfc_err(&dev
->interface
->dev
, "Urb failure (status %d)",
669 in_frame
= dev
->in_urb
->transfer_buffer
;
671 if (!port100_rx_frame_is_ack(in_frame
)) {
672 nfc_err(&dev
->interface
->dev
, "Received an invalid ack");
677 rc
= port100_submit_urb_for_response(dev
, GFP_ATOMIC
);
679 nfc_err(&dev
->interface
->dev
,
680 "usb_submit_urb failed with result %d", rc
);
688 schedule_work(&dev
->cmd_complete_work
);
691 static int port100_submit_urb_for_ack(struct port100
*dev
, gfp_t flags
)
693 dev
->in_urb
->complete
= port100_recv_ack
;
695 return usb_submit_urb(dev
->in_urb
, flags
);
698 static int port100_send_ack(struct port100
*dev
)
702 dev
->out_urb
->transfer_buffer
= ack_frame
;
703 dev
->out_urb
->transfer_buffer_length
= sizeof(ack_frame
);
704 rc
= usb_submit_urb(dev
->out_urb
, GFP_KERNEL
);
709 static int port100_send_frame_async(struct port100
*dev
, struct sk_buff
*out
,
710 struct sk_buff
*in
, int in_len
)
714 dev
->out_urb
->transfer_buffer
= out
->data
;
715 dev
->out_urb
->transfer_buffer_length
= out
->len
;
717 dev
->in_urb
->transfer_buffer
= in
->data
;
718 dev
->in_urb
->transfer_buffer_length
= in_len
;
720 print_hex_dump_debug("PORT100 TX: ", DUMP_PREFIX_NONE
, 16, 1,
721 out
->data
, out
->len
, false);
723 rc
= usb_submit_urb(dev
->out_urb
, GFP_KERNEL
);
727 rc
= port100_submit_urb_for_ack(dev
, GFP_KERNEL
);
734 usb_unlink_urb(dev
->out_urb
);
738 static void port100_build_cmd_frame(struct port100
*dev
, u8 cmd_code
,
741 /* payload is already there, just update datalen */
742 int payload_len
= skb
->len
;
744 skb_push(skb
, PORT100_FRAME_HEADER_LEN
);
745 skb_put(skb
, PORT100_FRAME_TAIL_LEN
);
747 port100_tx_frame_init(skb
->data
, cmd_code
);
748 port100_tx_update_payload_len(skb
->data
, payload_len
);
749 port100_tx_frame_finish(skb
->data
);
752 static void port100_send_async_complete(struct port100
*dev
)
754 struct port100_cmd
*cmd
= dev
->cmd
;
755 int status
= cmd
->status
;
757 struct sk_buff
*req
= cmd
->req
;
758 struct sk_buff
*resp
= cmd
->resp
;
765 cmd
->complete_cb(dev
, cmd
->complete_cb_context
,
771 skb_put(resp
, port100_rx_frame_size(resp
->data
));
772 skb_pull(resp
, PORT100_FRAME_HEADER_LEN
);
773 skb_trim(resp
, resp
->len
- PORT100_FRAME_TAIL_LEN
);
775 cmd
->complete_cb(dev
, cmd
->complete_cb_context
, resp
);
781 static int port100_send_cmd_async(struct port100
*dev
, u8 cmd_code
,
783 port100_send_async_complete_t complete_cb
,
784 void *complete_cb_context
)
786 struct port100_cmd
*cmd
;
787 struct sk_buff
*resp
;
789 int resp_len
= PORT100_FRAME_HEADER_LEN
+
790 PORT100_FRAME_MAX_PAYLOAD_LEN
+
791 PORT100_FRAME_TAIL_LEN
;
793 resp
= alloc_skb(resp_len
, GFP_KERNEL
);
797 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
803 cmd
->code
= cmd_code
;
806 cmd
->resp_len
= resp_len
;
807 cmd
->complete_cb
= complete_cb
;
808 cmd
->complete_cb_context
= complete_cb_context
;
810 port100_build_cmd_frame(dev
, cmd_code
, req
);
814 rc
= port100_send_frame_async(dev
, req
, resp
, resp_len
);
824 struct port100_sync_cmd_response
{
825 struct sk_buff
*resp
;
826 struct completion done
;
829 static void port100_wq_cmd_complete(struct work_struct
*work
)
831 struct port100
*dev
= container_of(work
, struct port100
,
834 port100_send_async_complete(dev
);
837 static void port100_send_sync_complete(struct port100
*dev
, void *_arg
,
838 struct sk_buff
*resp
)
840 struct port100_sync_cmd_response
*arg
= _arg
;
843 complete(&arg
->done
);
846 static struct sk_buff
*port100_send_cmd_sync(struct port100
*dev
, u8 cmd_code
,
850 struct port100_sync_cmd_response arg
;
852 init_completion(&arg
.done
);
854 rc
= port100_send_cmd_async(dev
, cmd_code
, req
,
855 port100_send_sync_complete
, &arg
);
861 wait_for_completion(&arg
.done
);
866 static void port100_send_complete(struct urb
*urb
)
868 struct port100
*dev
= urb
->context
;
870 switch (urb
->status
) {
875 nfc_err(&dev
->interface
->dev
,
876 "The urb has been stopped (status %d)", urb
->status
);
880 nfc_err(&dev
->interface
->dev
, "Urb failure (status %d)",
885 static void port100_abort_cmd(struct nfc_digital_dev
*ddev
)
887 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
889 /* An ack will cancel the last issued command */
890 port100_send_ack(dev
);
892 /* cancel the urb request */
893 usb_kill_urb(dev
->in_urb
);
896 static struct sk_buff
*port100_alloc_skb(struct port100
*dev
, unsigned int size
)
900 skb
= alloc_skb(dev
->skb_headroom
+ dev
->skb_tailroom
+ size
,
903 skb_reserve(skb
, dev
->skb_headroom
);
908 static int port100_set_command_type(struct port100
*dev
, u8 command_type
)
911 struct sk_buff
*resp
;
914 skb
= port100_alloc_skb(dev
, 1);
918 *skb_put(skb
, sizeof(u8
)) = command_type
;
920 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_SET_COMMAND_TYPE
, skb
);
922 return PTR_ERR(resp
);
931 static u64
port100_get_command_type_mask(struct port100
*dev
)
934 struct sk_buff
*resp
;
937 skb
= port100_alloc_skb(dev
, 0);
941 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_GET_COMMAND_TYPE
, skb
);
943 return PTR_ERR(resp
);
948 mask
= be64_to_cpu(*(__be64
*)resp
->data
);
955 static u16
port100_get_firmware_version(struct port100
*dev
)
958 struct sk_buff
*resp
;
961 skb
= port100_alloc_skb(dev
, 0);
965 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_GET_FIRMWARE_VERSION
,
970 fw_ver
= le16_to_cpu(*(__le16
*)resp
->data
);
977 static int port100_switch_rf(struct nfc_digital_dev
*ddev
, bool on
)
979 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
980 struct sk_buff
*skb
, *resp
;
982 skb
= port100_alloc_skb(dev
, 1);
986 *skb_put(skb
, 1) = on
? 1 : 0;
988 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_SWITCH_RF
, skb
);
991 return PTR_ERR(resp
);
998 static int port100_in_set_rf(struct nfc_digital_dev
*ddev
, u8 rf
)
1000 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1001 struct sk_buff
*skb
;
1002 struct sk_buff
*resp
;
1005 if (rf
>= NFC_DIGITAL_RF_TECH_LAST
)
1008 skb
= port100_alloc_skb(dev
, sizeof(struct port100_in_rf_setting
));
1012 memcpy(skb_put(skb
, sizeof(struct port100_in_rf_setting
)),
1013 &in_rf_settings
[rf
],
1014 sizeof(struct port100_in_rf_setting
));
1016 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_IN_SET_RF
, skb
);
1019 return PTR_ERR(resp
);
1023 dev_kfree_skb(resp
);
1028 static int port100_in_set_framing(struct nfc_digital_dev
*ddev
, int param
)
1030 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1031 struct port100_protocol
*protocols
;
1032 struct sk_buff
*skb
;
1033 struct sk_buff
*resp
;
1038 if (param
>= NFC_DIGITAL_FRAMING_LAST
)
1041 protocols
= in_protocols
[param
];
1044 while (protocols
[num_protocols
].number
!= PORT100_IN_PROT_END
)
1050 size
= sizeof(struct port100_protocol
) * num_protocols
;
1052 skb
= port100_alloc_skb(dev
, size
);
1056 memcpy(skb_put(skb
, size
), protocols
, size
);
1058 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_IN_SET_PROTOCOL
, skb
);
1061 return PTR_ERR(resp
);
1065 dev_kfree_skb(resp
);
1070 static int port100_in_configure_hw(struct nfc_digital_dev
*ddev
, int type
,
1073 if (type
== NFC_DIGITAL_CONFIG_RF_TECH
)
1074 return port100_in_set_rf(ddev
, param
);
1076 if (type
== NFC_DIGITAL_CONFIG_FRAMING
)
1077 return port100_in_set_framing(ddev
, param
);
1082 static void port100_in_comm_rf_complete(struct port100
*dev
, void *arg
,
1083 struct sk_buff
*resp
)
1085 struct port100_cb_arg
*cb_arg
= arg
;
1086 nfc_digital_cmd_complete_t cb
= cb_arg
->complete_cb
;
1095 if (resp
->len
< 4) {
1096 nfc_err(&dev
->interface
->dev
,
1097 "Invalid packet length received.\n");
1102 status
= le32_to_cpu(*(__le32
*)resp
->data
);
1104 skb_pull(resp
, sizeof(u32
));
1106 if (status
== PORT100_CMD_STATUS_TIMEOUT
) {
1111 if (status
!= PORT100_CMD_STATUS_OK
) {
1112 nfc_err(&dev
->interface
->dev
,
1113 "in_comm_rf failed with status 0x%08x\n", status
);
1118 /* Remove collision bits byte */
1128 cb(dev
->nfc_digital_dev
, cb_arg
->complete_arg
, resp
);
1133 static int port100_in_send_cmd(struct nfc_digital_dev
*ddev
,
1134 struct sk_buff
*skb
, u16 _timeout
,
1135 nfc_digital_cmd_complete_t cb
, void *arg
)
1137 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1138 struct port100_cb_arg
*cb_arg
;
1141 cb_arg
= kzalloc(sizeof(struct port100_cb_arg
), GFP_KERNEL
);
1145 cb_arg
->complete_cb
= cb
;
1146 cb_arg
->complete_arg
= arg
;
1148 timeout
= cpu_to_le16(_timeout
* 10);
1150 memcpy(skb_push(skb
, sizeof(__le16
)), &timeout
, sizeof(__le16
));
1152 return port100_send_cmd_async(dev
, PORT100_CMD_IN_COMM_RF
, skb
,
1153 port100_in_comm_rf_complete
, cb_arg
);
1156 static int port100_tg_set_rf(struct nfc_digital_dev
*ddev
, u8 rf
)
1158 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1159 struct sk_buff
*skb
;
1160 struct sk_buff
*resp
;
1163 if (rf
>= NFC_DIGITAL_RF_TECH_LAST
)
1166 skb
= port100_alloc_skb(dev
, sizeof(struct port100_tg_rf_setting
));
1170 memcpy(skb_put(skb
, sizeof(struct port100_tg_rf_setting
)),
1171 &tg_rf_settings
[rf
],
1172 sizeof(struct port100_tg_rf_setting
));
1174 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_TG_SET_RF
, skb
);
1177 return PTR_ERR(resp
);
1181 dev_kfree_skb(resp
);
1186 static int port100_tg_set_framing(struct nfc_digital_dev
*ddev
, int param
)
1188 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1189 struct port100_protocol
*protocols
;
1190 struct sk_buff
*skb
;
1191 struct sk_buff
*resp
;
1196 if (param
>= NFC_DIGITAL_FRAMING_LAST
)
1199 protocols
= tg_protocols
[param
];
1202 while (protocols
[num_protocols
].number
!= PORT100_TG_PROT_END
)
1208 size
= sizeof(struct port100_protocol
) * num_protocols
;
1210 skb
= port100_alloc_skb(dev
, size
);
1214 memcpy(skb_put(skb
, size
), protocols
, size
);
1216 resp
= port100_send_cmd_sync(dev
, PORT100_CMD_TG_SET_PROTOCOL
, skb
);
1219 return PTR_ERR(resp
);
1223 dev_kfree_skb(resp
);
1228 static int port100_tg_configure_hw(struct nfc_digital_dev
*ddev
, int type
,
1231 if (type
== NFC_DIGITAL_CONFIG_RF_TECH
)
1232 return port100_tg_set_rf(ddev
, param
);
1234 if (type
== NFC_DIGITAL_CONFIG_FRAMING
)
1235 return port100_tg_set_framing(ddev
, param
);
1240 static bool port100_tg_target_activated(struct port100
*dev
, u8 tgt_activated
)
1244 switch (dev
->cmd_type
) {
1245 case PORT100_CMD_TYPE_0
:
1246 mask
= PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK
;
1248 case PORT100_CMD_TYPE_1
:
1249 mask
= PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK
|
1250 PORT100_MDAA_TGT_WAS_ACTIVATED_MASK
;
1253 nfc_err(&dev
->interface
->dev
, "Unknonwn command type.\n");
1257 return ((tgt_activated
& mask
) == mask
);
1260 static void port100_tg_comm_rf_complete(struct port100
*dev
, void *arg
,
1261 struct sk_buff
*resp
)
1264 struct port100_cb_arg
*cb_arg
= arg
;
1265 nfc_digital_cmd_complete_t cb
= cb_arg
->complete_cb
;
1266 struct port100_tg_comm_rf_res
*hdr
;
1271 hdr
= (struct port100_tg_comm_rf_res
*)resp
->data
;
1273 status
= le32_to_cpu(hdr
->status
);
1276 !port100_tg_target_activated(dev
, hdr
->target_activated
)) {
1278 resp
= ERR_PTR(-ETIMEDOUT
);
1283 skb_pull(resp
, sizeof(struct port100_tg_comm_rf_res
));
1285 if (status
!= PORT100_CMD_STATUS_OK
) {
1288 if (status
== PORT100_CMD_STATUS_TIMEOUT
)
1289 resp
= ERR_PTR(-ETIMEDOUT
);
1291 resp
= ERR_PTR(-EIO
);
1295 cb(dev
->nfc_digital_dev
, cb_arg
->complete_arg
, resp
);
1300 static int port100_tg_send_cmd(struct nfc_digital_dev
*ddev
,
1301 struct sk_buff
*skb
, u16 timeout
,
1302 nfc_digital_cmd_complete_t cb
, void *arg
)
1304 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1305 struct port100_tg_comm_rf_cmd
*hdr
;
1306 struct port100_cb_arg
*cb_arg
;
1308 cb_arg
= kzalloc(sizeof(struct port100_cb_arg
), GFP_KERNEL
);
1312 cb_arg
->complete_cb
= cb
;
1313 cb_arg
->complete_arg
= arg
;
1315 skb_push(skb
, sizeof(struct port100_tg_comm_rf_cmd
));
1317 hdr
= (struct port100_tg_comm_rf_cmd
*)skb
->data
;
1319 memset(hdr
, 0, sizeof(struct port100_tg_comm_rf_cmd
));
1320 hdr
->guard_time
= cpu_to_le16(500);
1321 hdr
->send_timeout
= cpu_to_le16(0xFFFF);
1322 hdr
->recv_timeout
= cpu_to_le16(timeout
);
1324 return port100_send_cmd_async(dev
, PORT100_CMD_TG_COMM_RF
, skb
,
1325 port100_tg_comm_rf_complete
, cb_arg
);
1328 static int port100_listen_mdaa(struct nfc_digital_dev
*ddev
,
1329 struct digital_tg_mdaa_params
*params
,
1331 nfc_digital_cmd_complete_t cb
, void *arg
)
1333 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1334 struct port100_tg_comm_rf_cmd
*hdr
;
1335 struct port100_cb_arg
*cb_arg
;
1336 struct sk_buff
*skb
;
1339 rc
= port100_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
1340 NFC_DIGITAL_RF_TECH_106A
);
1344 rc
= port100_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1345 NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
);
1349 cb_arg
= kzalloc(sizeof(struct port100_cb_arg
), GFP_KERNEL
);
1353 cb_arg
->complete_cb
= cb
;
1354 cb_arg
->complete_arg
= arg
;
1357 skb
= port100_alloc_skb(dev
, 0);
1363 skb_push(skb
, sizeof(struct port100_tg_comm_rf_cmd
));
1364 hdr
= (struct port100_tg_comm_rf_cmd
*)skb
->data
;
1366 memset(hdr
, 0, sizeof(struct port100_tg_comm_rf_cmd
));
1368 hdr
->guard_time
= 0;
1369 hdr
->send_timeout
= cpu_to_le16(0xFFFF);
1371 hdr
->nfca_param
[0] = (params
->sens_res
>> 8) & 0xFF;
1372 hdr
->nfca_param
[1] = params
->sens_res
& 0xFF;
1373 memcpy(hdr
->nfca_param
+ 2, params
->nfcid1
, 3);
1374 hdr
->nfca_param
[5] = params
->sel_res
;
1375 memcpy(hdr
->nfcf_param
, params
->nfcid2
, 8);
1376 hdr
->nfcf_param
[16] = (params
->sc
>> 8) & 0xFF;
1377 hdr
->nfcf_param
[17] = params
->sc
& 0xFF;
1378 hdr
->recv_timeout
= cpu_to_le16(timeout
);
1380 return port100_send_cmd_async(dev
, PORT100_CMD_TG_COMM_RF
, skb
,
1381 port100_tg_comm_rf_complete
, cb_arg
);
1384 static int port100_listen(struct nfc_digital_dev
*ddev
, u16 timeout
,
1385 nfc_digital_cmd_complete_t cb
, void *arg
)
1387 struct port100
*dev
= nfc_digital_get_drvdata(ddev
);
1388 struct sk_buff
*skb
;
1390 skb
= port100_alloc_skb(dev
, 0);
1394 return port100_tg_send_cmd(ddev
, skb
, timeout
, cb
, arg
);
1397 static struct nfc_digital_ops port100_digital_ops
= {
1398 .in_configure_hw
= port100_in_configure_hw
,
1399 .in_send_cmd
= port100_in_send_cmd
,
1401 .tg_listen_mdaa
= port100_listen_mdaa
,
1402 .tg_listen
= port100_listen
,
1403 .tg_configure_hw
= port100_tg_configure_hw
,
1404 .tg_send_cmd
= port100_tg_send_cmd
,
1406 .switch_rf
= port100_switch_rf
,
1407 .abort_cmd
= port100_abort_cmd
,
1410 static const struct usb_device_id port100_table
[] = {
1411 { USB_DEVICE(SONY_VENDOR_ID
, RCS380_PRODUCT_ID
), },
1414 MODULE_DEVICE_TABLE(usb
, port100_table
);
1416 static int port100_probe(struct usb_interface
*interface
,
1417 const struct usb_device_id
*id
)
1419 struct port100
*dev
;
1421 struct usb_host_interface
*iface_desc
;
1422 struct usb_endpoint_descriptor
*endpoint
;
1429 dev
= devm_kzalloc(&interface
->dev
, sizeof(struct port100
), GFP_KERNEL
);
1433 dev
->udev
= usb_get_dev(interface_to_usbdev(interface
));
1434 dev
->interface
= interface
;
1435 usb_set_intfdata(interface
, dev
);
1437 in_endpoint
= out_endpoint
= 0;
1438 iface_desc
= interface
->cur_altsetting
;
1439 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
1440 endpoint
= &iface_desc
->endpoint
[i
].desc
;
1442 if (!in_endpoint
&& usb_endpoint_is_bulk_in(endpoint
))
1443 in_endpoint
= endpoint
->bEndpointAddress
;
1445 if (!out_endpoint
&& usb_endpoint_is_bulk_out(endpoint
))
1446 out_endpoint
= endpoint
->bEndpointAddress
;
1449 if (!in_endpoint
|| !out_endpoint
) {
1450 nfc_err(&interface
->dev
,
1451 "Could not find bulk-in or bulk-out endpoint\n");
1456 dev
->in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1457 dev
->out_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1459 if (!dev
->in_urb
|| !dev
->out_urb
) {
1460 nfc_err(&interface
->dev
, "Could not allocate USB URBs\n");
1465 usb_fill_bulk_urb(dev
->in_urb
, dev
->udev
,
1466 usb_rcvbulkpipe(dev
->udev
, in_endpoint
),
1467 NULL
, 0, NULL
, dev
);
1468 usb_fill_bulk_urb(dev
->out_urb
, dev
->udev
,
1469 usb_sndbulkpipe(dev
->udev
, out_endpoint
),
1470 NULL
, 0, port100_send_complete
, dev
);
1472 dev
->skb_headroom
= PORT100_FRAME_HEADER_LEN
+
1473 PORT100_COMM_RF_HEAD_MAX_LEN
;
1474 dev
->skb_tailroom
= PORT100_FRAME_TAIL_LEN
;
1476 INIT_WORK(&dev
->cmd_complete_work
, port100_wq_cmd_complete
);
1478 /* The first thing to do with the Port-100 is to set the command type
1479 * to be used. If supported we use command type 1. 0 otherwise.
1481 cmd_type_mask
= port100_get_command_type_mask(dev
);
1482 if (!cmd_type_mask
) {
1483 nfc_err(&interface
->dev
,
1484 "Could not get supported command types.\n");
1489 if (PORT100_CMD_TYPE_IS_SUPPORTED(cmd_type_mask
, PORT100_CMD_TYPE_1
))
1490 dev
->cmd_type
= PORT100_CMD_TYPE_1
;
1492 dev
->cmd_type
= PORT100_CMD_TYPE_0
;
1494 rc
= port100_set_command_type(dev
, dev
->cmd_type
);
1496 nfc_err(&interface
->dev
,
1497 "The device does not support command type %u.\n",
1502 fw_version
= port100_get_firmware_version(dev
);
1504 nfc_err(&interface
->dev
,
1505 "Could not get device firmware version.\n");
1507 nfc_info(&interface
->dev
,
1508 "Sony NFC Port-100 Series attached (firmware v%x.%02x)\n",
1509 (fw_version
& 0xFF00) >> 8, fw_version
& 0xFF);
1511 dev
->nfc_digital_dev
= nfc_digital_allocate_device(&port100_digital_ops
,
1513 PORT100_CAPABILITIES
,
1516 if (!dev
->nfc_digital_dev
) {
1517 nfc_err(&interface
->dev
,
1518 "Could not allocate nfc_digital_dev.\n");
1523 nfc_digital_set_parent_dev(dev
->nfc_digital_dev
, &interface
->dev
);
1524 nfc_digital_set_drvdata(dev
->nfc_digital_dev
, dev
);
1526 rc
= nfc_digital_register_device(dev
->nfc_digital_dev
);
1528 nfc_err(&interface
->dev
,
1529 "Could not register digital device.\n");
1536 nfc_digital_free_device(dev
->nfc_digital_dev
);
1539 usb_free_urb(dev
->in_urb
);
1540 usb_free_urb(dev
->out_urb
);
1541 usb_put_dev(dev
->udev
);
1546 static void port100_disconnect(struct usb_interface
*interface
)
1548 struct port100
*dev
;
1550 dev
= usb_get_intfdata(interface
);
1551 usb_set_intfdata(interface
, NULL
);
1553 nfc_digital_unregister_device(dev
->nfc_digital_dev
);
1554 nfc_digital_free_device(dev
->nfc_digital_dev
);
1556 usb_kill_urb(dev
->in_urb
);
1557 usb_kill_urb(dev
->out_urb
);
1559 usb_free_urb(dev
->in_urb
);
1560 usb_free_urb(dev
->out_urb
);
1561 usb_put_dev(dev
->udev
);
1565 nfc_info(&interface
->dev
, "Sony Port-100 NFC device disconnected");
1568 static struct usb_driver port100_driver
= {
1570 .probe
= port100_probe
,
1571 .disconnect
= port100_disconnect
,
1572 .id_table
= port100_table
,
1575 module_usb_driver(port100_driver
);
1577 MODULE_DESCRIPTION("NFC Port-100 series usb driver ver " VERSION
);
1578 MODULE_VERSION(VERSION
);
1579 MODULE_LICENSE("GPL");