blob: 838ec17073fd191ac6a6211288e80d0e40b7d3e6 [file] [log] [blame]
Thierry Escande562d4d52013-10-04 12:12:00 +02001/*
2 * Sony NFC Port-100 Series driver
3 * Copyright (c) 2013, Intel Corporation.
4 *
5 * Partly based/Inspired by Stephen Tiedemann's nfcpy
6 *
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.
10 *
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
14 * more details.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/usb.h>
20#include <net/nfc/digital.h>
21
22#define VERSION "0.1"
23
24#define SONY_VENDOR_ID 0x054c
25#define RCS380_PRODUCT_ID 0x06c1
26
27#define PORT100_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
28 NFC_PROTO_MIFARE_MASK | \
29 NFC_PROTO_FELICA_MASK | \
Thierry Escande2a26f9a2014-01-27 00:31:33 +010030 NFC_PROTO_NFC_DEP_MASK | \
Thierry Escande09592cc2014-04-12 00:03:17 +020031 NFC_PROTO_ISO14443_MASK | \
32 NFC_PROTO_ISO14443_B_MASK)
Thierry Escande562d4d52013-10-04 12:12:00 +020033
34#define PORT100_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC | \
35 NFC_DIGITAL_DRV_CAPS_TG_CRC)
36
Thierry Escande0347a6a2013-10-04 12:12:01 +020037/* 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*/
41
42#define PORT100_COMM_RF_HEAD_MAX_LEN (sizeof(struct port100_tg_comm_rf_cmd))
43
44/*
45 * Max extended frame payload len, excluding CC and SCC
46 * which are already in PORT100_FRAME_HEADER_LEN.
47 */
48#define PORT100_FRAME_MAX_PAYLOAD_LEN 1001
49
50#define PORT100_FRAME_ACK_SIZE 6 /* Preamble (1), SoPC (2), ACK Code (2),
51 Postamble (1) */
52static u8 ack_frame[PORT100_FRAME_ACK_SIZE] = {
53 0x00, 0x00, 0xff, 0x00, 0xff, 0x00
54};
55
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])
58
59/* start of frame */
60#define PORT100_FRAME_SOF 0x00FF
61#define PORT100_FRAME_EXT 0xFFFF
62#define PORT100_FRAME_ACK 0x00FF
63
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
68
69/* Port-100 sub-command */
70#define PORT100_FRAME_CMD(f) (f->data[1]) /* SCC */
71
72#define PORT100_CMD_GET_FIRMWARE_VERSION 0x20
73#define PORT100_CMD_GET_COMMAND_TYPE 0x28
74#define PORT100_CMD_SET_COMMAND_TYPE 0x2A
75
Thierry Escande9f7b57f2013-10-04 12:12:02 +020076#define PORT100_CMD_IN_SET_RF 0x00
77#define PORT100_CMD_IN_SET_PROTOCOL 0x02
78#define PORT100_CMD_IN_COMM_RF 0x04
79
Thierry Escande7227c022013-10-04 12:12:03 +020080#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
84
Thierry Escande9f7b57f2013-10-04 12:12:02 +020085#define PORT100_CMD_SWITCH_RF 0x06
86
Thierry Escande0347a6a2013-10-04 12:12:01 +020087#define PORT100_CMD_RESPONSE(cmd) (cmd + 1)
88
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
93
Thierry Escande9f7b57f2013-10-04 12:12:02 +020094#define PORT100_CMD_STATUS_OK 0x00
95#define PORT100_CMD_STATUS_TIMEOUT 0x80
96
Thierry Escande7227c022013-10-04 12:12:03 +020097#define PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK 0x01
98#define PORT100_MDAA_TGT_WAS_ACTIVATED_MASK 0x02
99
Thierry Escande0347a6a2013-10-04 12:12:01 +0200100struct port100;
101
102typedef void (*port100_send_async_complete_t)(struct port100 *dev, void *arg,
103 struct sk_buff *resp);
104
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200105/**
106 * Setting sets structure for in_set_rf command
107 *
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
110 * communication.
111 *
112 * @in_*_comm_type: Theses fields set the communication type to be used.
113 */
114struct 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;
119} __packed;
120
121#define PORT100_COMM_TYPE_IN_212F 0x01
122#define PORT100_COMM_TYPE_IN_424F 0x02
123#define PORT100_COMM_TYPE_IN_106A 0x03
Thierry Escande09592cc2014-04-12 00:03:17 +0200124#define PORT100_COMM_TYPE_IN_106B 0x07
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200125
126static 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,
132 },
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,
138 },
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,
144 },
Thierry Escande09592cc2014-04-12 00:03:17 +0200145 [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,
150 },
Thierry Escanded3815ea2014-01-27 00:31:14 +0100151 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */
152 [NFC_DIGITAL_RF_TECH_LAST] = { 0 },
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200153};
154
Thierry Escande7227c022013-10-04 12:12:03 +0200155/**
156 * Setting sets structure for tg_set_rf command
157 *
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
161 * settings.
162 *
163 * @tg_comm_type: Sets the communication type to be used to send and receive
164 * data.
165 */
166struct port100_tg_rf_setting {
167 u8 tg_set_number;
168 u8 tg_comm_type;
169} __packed;
170
171#define PORT100_COMM_TYPE_TG_106A 0x0B
172#define PORT100_COMM_TYPE_TG_212F 0x0C
173#define PORT100_COMM_TYPE_TG_424F 0x0D
174
175static const struct port100_tg_rf_setting tg_rf_settings[] = {
176 [NFC_DIGITAL_RF_TECH_106A] = {
177 .tg_set_number = 8,
178 .tg_comm_type = PORT100_COMM_TYPE_TG_106A,
179 },
180 [NFC_DIGITAL_RF_TECH_212F] = {
181 .tg_set_number = 8,
182 .tg_comm_type = PORT100_COMM_TYPE_TG_212F,
183 },
184 [NFC_DIGITAL_RF_TECH_424F] = {
185 .tg_set_number = 8,
186 .tg_comm_type = PORT100_COMM_TYPE_TG_424F,
187 },
Thierry Escanded3815ea2014-01-27 00:31:14 +0100188 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */
189 [NFC_DIGITAL_RF_TECH_LAST] = { 0 },
190
Thierry Escande7227c022013-10-04 12:12:03 +0200191};
192
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200193#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
213
214#define PORT100_IN_MAX_NUM_PROTOCOLS 19
215
Thierry Escande7227c022013-10-04 12:12:03 +0200216#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
220
221#define PORT100_TG_MAX_NUM_PROTOCOLS 3
222
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200223struct port100_protocol {
224 u8 number;
225 u8 value;
226} __packed;
227
228static struct port100_protocol
229in_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 },
251 },
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 },
273 },
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 },
295 },
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 },
303 },
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 },
309 },
Thierry Escande2a26f9a2014-01-27 00:31:33 +0100310 [NFC_DIGITAL_FRAMING_NFCA_T4T] = {
311 /* nfc_digital_framing_nfca_standard_with_crc_a */
312 { PORT100_IN_PROT_END, 0 },
313 },
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200314 [NFC_DIGITAL_FRAMING_NFCA_NFC_DEP] = {
315 /* nfc_digital_framing_nfca_standard */
316 { PORT100_IN_PROT_END, 0 },
317 },
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 },
339 },
340 [NFC_DIGITAL_FRAMING_NFCF_T3T] = {
341 /* nfc_digital_framing_nfcf */
342 { PORT100_IN_PROT_END, 0 },
343 },
344 [NFC_DIGITAL_FRAMING_NFCF_NFC_DEP] = {
345 /* nfc_digital_framing_nfcf */
Thierry Escandea81ba502016-06-07 16:21:51 +0200346 { PORT100_IN_PROT_INITIAL_GUARD_TIME, 18 },
347 { PORT100_IN_PROT_ADD_CRC, 1 },
348 { PORT100_IN_PROT_CHECK_CRC, 1 },
349 { PORT100_IN_PROT_MULTI_CARD, 0 },
350 { PORT100_IN_PROT_ADD_PARITY, 0 },
351 { PORT100_IN_PROT_CHECK_PARITY, 0 },
352 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE, 0 },
353 { PORT100_IN_PROT_VALID_BIT_NUMBER, 8 },
354 { PORT100_IN_PROT_CRYPTO1, 0 },
355 { PORT100_IN_PROT_ADD_SOF, 0 },
356 { PORT100_IN_PROT_CHECK_SOF, 0 },
357 { PORT100_IN_PROT_ADD_EOF, 0 },
358 { PORT100_IN_PROT_CHECK_EOF, 0 },
359 { PORT100_IN_PROT_DEAF_TIME, 4 },
360 { PORT100_IN_PROT_CRM, 0 },
361 { PORT100_IN_PROT_CRM_MIN_LEN, 0 },
362 { PORT100_IN_PROT_T1_TAG_FRAME, 0 },
363 { PORT100_IN_PROT_RFCA, 0 },
364 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR, 6 },
365 { PORT100_IN_PROT_END, 0 },
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200366 },
367 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED] = {
368 { PORT100_IN_PROT_END, 0 },
369 },
Thierry Escande09592cc2014-04-12 00:03:17 +0200370 [NFC_DIGITAL_FRAMING_NFCB] = {
371 { PORT100_IN_PROT_INITIAL_GUARD_TIME, 20 },
372 { PORT100_IN_PROT_ADD_CRC, 1 },
373 { PORT100_IN_PROT_CHECK_CRC, 1 },
374 { PORT100_IN_PROT_MULTI_CARD, 0 },
375 { PORT100_IN_PROT_ADD_PARITY, 0 },
376 { PORT100_IN_PROT_CHECK_PARITY, 0 },
377 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE, 0 },
378 { PORT100_IN_PROT_VALID_BIT_NUMBER, 8 },
379 { PORT100_IN_PROT_CRYPTO1, 0 },
380 { PORT100_IN_PROT_ADD_SOF, 1 },
381 { PORT100_IN_PROT_CHECK_SOF, 1 },
382 { PORT100_IN_PROT_ADD_EOF, 1 },
383 { PORT100_IN_PROT_CHECK_EOF, 1 },
384 { PORT100_IN_PROT_DEAF_TIME, 4 },
385 { PORT100_IN_PROT_CRM, 0 },
386 { PORT100_IN_PROT_CRM_MIN_LEN, 0 },
387 { PORT100_IN_PROT_T1_TAG_FRAME, 0 },
388 { PORT100_IN_PROT_RFCA, 0 },
389 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR, 6 },
390 { PORT100_IN_PROT_END, 0 },
391 },
392 [NFC_DIGITAL_FRAMING_NFCB_T4T] = {
393 /* nfc_digital_framing_nfcb */
394 { PORT100_IN_PROT_END, 0 },
395 },
Thierry Escanded3815ea2014-01-27 00:31:14 +0100396 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */
397 [NFC_DIGITAL_FRAMING_LAST] = {
398 { PORT100_IN_PROT_END, 0 },
399 },
Thierry Escande9f7b57f2013-10-04 12:12:02 +0200400};
401
Thierry Escande7227c022013-10-04 12:12:03 +0200402static struct port100_protocol
403tg_protocols[][PORT100_TG_MAX_NUM_PROTOCOLS + 1] = {
404 [NFC_DIGITAL_FRAMING_NFCA_SHORT] = {
405 { PORT100_TG_PROT_END, 0 },
406 },
407 [NFC_DIGITAL_FRAMING_NFCA_STANDARD] = {
408 { PORT100_TG_PROT_END, 0 },
409 },
410 [NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A] = {
411 { PORT100_TG_PROT_END, 0 },
412 },
413 [NFC_DIGITAL_FRAMING_NFCA_T1T] = {
414 { PORT100_TG_PROT_END, 0 },
415 },
416 [NFC_DIGITAL_FRAMING_NFCA_T2T] = {
417 { PORT100_TG_PROT_END, 0 },
418 },
419 [NFC_DIGITAL_FRAMING_NFCA_NFC_DEP] = {
420 { PORT100_TG_PROT_TU, 1 },
421 { PORT100_TG_PROT_RF_OFF, 0 },
422 { PORT100_TG_PROT_CRM, 7 },
423 { PORT100_TG_PROT_END, 0 },
424 },
425 [NFC_DIGITAL_FRAMING_NFCF] = {
426 { PORT100_TG_PROT_END, 0 },
427 },
428 [NFC_DIGITAL_FRAMING_NFCF_T3T] = {
429 { PORT100_TG_PROT_END, 0 },
430 },
431 [NFC_DIGITAL_FRAMING_NFCF_NFC_DEP] = {
432 { PORT100_TG_PROT_TU, 1 },
433 { PORT100_TG_PROT_RF_OFF, 0 },
434 { PORT100_TG_PROT_CRM, 7 },
435 { PORT100_TG_PROT_END, 0 },
436 },
437 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED] = {
438 { PORT100_TG_PROT_RF_OFF, 1 },
439 { PORT100_TG_PROT_END, 0 },
440 },
Thierry Escanded3815ea2014-01-27 00:31:14 +0100441 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */
442 [NFC_DIGITAL_FRAMING_LAST] = {
443 { PORT100_TG_PROT_END, 0 },
444 },
Thierry Escande7227c022013-10-04 12:12:03 +0200445};
446
Thierry Escande562d4d52013-10-04 12:12:00 +0200447struct port100 {
448 struct nfc_digital_dev *nfc_digital_dev;
449
450 int skb_headroom;
451 int skb_tailroom;
452
453 struct usb_device *udev;
454 struct usb_interface *interface;
Thierry Escande0347a6a2013-10-04 12:12:01 +0200455
456 struct urb *out_urb;
457 struct urb *in_urb;
458
Thierry Escandeb74584c2016-06-16 20:25:21 +0200459 /* This mutex protects the out_urb and avoids to submit a new command
460 * through port100_send_frame_async() while the previous one is being
461 * canceled through port100_abort_cmd().
462 */
463 struct mutex out_urb_lock;
464
Thierry Escande0347a6a2013-10-04 12:12:01 +0200465 struct work_struct cmd_complete_work;
466
467 u8 cmd_type;
468
469 /* The digital stack serializes commands to be sent. There is no need
470 * for any queuing/locking mechanism at driver level.
471 */
472 struct port100_cmd *cmd;
Thierry Escandeb74584c2016-06-16 20:25:21 +0200473
474 bool cmd_cancel;
Thierry Escandea52bd7d2016-06-16 20:25:22 +0200475 struct completion cmd_cancel_done;
Thierry Escande562d4d52013-10-04 12:12:00 +0200476};
477
Thierry Escande0347a6a2013-10-04 12:12:01 +0200478struct port100_cmd {
479 u8 code;
480 int status;
481 struct sk_buff *req;
482 struct sk_buff *resp;
483 int resp_len;
484 port100_send_async_complete_t complete_cb;
485 void *complete_cb_context;
486};
487
488struct port100_frame {
489 u8 preamble;
490 __be16 start_frame;
491 __be16 extended_frame;
492 __le16 datalen;
493 u8 datalen_checksum;
494 u8 data[];
495} __packed;
496
497struct port100_ack_frame {
498 u8 preamble;
499 __be16 start_frame;
500 __be16 ack_frame;
501 u8 postambule;
502} __packed;
503
504struct port100_cb_arg {
505 nfc_digital_cmd_complete_t complete_cb;
506 void *complete_arg;
507 u8 mdaa;
508};
509
510struct port100_tg_comm_rf_cmd {
511 __le16 guard_time;
512 __le16 send_timeout;
513 u8 mdaa;
514 u8 nfca_param[6];
515 u8 nfcf_param[18];
516 u8 mf_halted;
517 u8 arae_flag;
518 __le16 recv_timeout;
519 u8 data[];
520} __packed;
521
Thierry Escande7227c022013-10-04 12:12:03 +0200522struct port100_tg_comm_rf_res {
523 u8 comm_type;
524 u8 ar_status;
525 u8 target_activated;
526 __le32 status;
527 u8 data[];
528} __packed;
529
Thierry Escande0347a6a2013-10-04 12:12:01 +0200530/* The rule: value + checksum = 0 */
531static inline u8 port100_checksum(u16 value)
532{
533 return ~(((u8 *)&value)[0] + ((u8 *)&value)[1]) + 1;
534}
535
536/* The rule: sum(data elements) + checksum = 0 */
537static u8 port100_data_checksum(u8 *data, int datalen)
538{
539 u8 sum = 0;
540 int i;
541
542 for (i = 0; i < datalen; i++)
543 sum += data[i];
544
545 return port100_checksum(sum);
546}
547
548static void port100_tx_frame_init(void *_frame, u8 cmd_code)
549{
550 struct port100_frame *frame = _frame;
551
552 frame->preamble = 0;
553 frame->start_frame = cpu_to_be16(PORT100_FRAME_SOF);
554 frame->extended_frame = cpu_to_be16(PORT100_FRAME_EXT);
555 PORT100_FRAME_DIRECTION(frame) = PORT100_FRAME_DIR_OUT;
556 PORT100_FRAME_CMD(frame) = cmd_code;
557 frame->datalen = cpu_to_le16(2);
558}
559
560static void port100_tx_frame_finish(void *_frame)
561{
562 struct port100_frame *frame = _frame;
563
564 frame->datalen_checksum = port100_checksum(le16_to_cpu(frame->datalen));
565
566 PORT100_FRAME_CHECKSUM(frame) =
567 port100_data_checksum(frame->data, le16_to_cpu(frame->datalen));
568
569 PORT100_FRAME_POSTAMBLE(frame) = 0;
570}
571
572static void port100_tx_update_payload_len(void *_frame, int len)
573{
574 struct port100_frame *frame = _frame;
575
Mao Wenan9fe83ea2019-12-09 21:08:45 +0800576 le16_add_cpu(&frame->datalen, len);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200577}
578
579static bool port100_rx_frame_is_valid(void *_frame)
580{
581 u8 checksum;
582 struct port100_frame *frame = _frame;
583
584 if (frame->start_frame != cpu_to_be16(PORT100_FRAME_SOF) ||
585 frame->extended_frame != cpu_to_be16(PORT100_FRAME_EXT))
586 return false;
587
588 checksum = port100_checksum(le16_to_cpu(frame->datalen));
589 if (checksum != frame->datalen_checksum)
590 return false;
591
592 checksum = port100_data_checksum(frame->data,
593 le16_to_cpu(frame->datalen));
594 if (checksum != PORT100_FRAME_CHECKSUM(frame))
595 return false;
596
597 return true;
598}
599
600static bool port100_rx_frame_is_ack(struct port100_ack_frame *frame)
601{
602 return (frame->start_frame == cpu_to_be16(PORT100_FRAME_SOF) &&
603 frame->ack_frame == cpu_to_be16(PORT100_FRAME_ACK));
604}
605
606static inline int port100_rx_frame_size(void *frame)
607{
608 struct port100_frame *f = frame;
609
610 return sizeof(struct port100_frame) + le16_to_cpu(f->datalen) +
611 PORT100_FRAME_TAIL_LEN;
612}
613
614static bool port100_rx_frame_is_cmd_response(struct port100 *dev, void *frame)
615{
616 struct port100_frame *f = frame;
617
618 return (PORT100_FRAME_CMD(f) == PORT100_CMD_RESPONSE(dev->cmd->code));
619}
620
621static void port100_recv_response(struct urb *urb)
622{
623 struct port100 *dev = urb->context;
624 struct port100_cmd *cmd = dev->cmd;
625 u8 *in_frame;
626
627 cmd->status = urb->status;
628
629 switch (urb->status) {
630 case 0:
631 break; /* success */
632 case -ECONNRESET:
633 case -ENOENT:
634 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -0700635 "The urb has been canceled (status %d)\n", urb->status);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200636 goto sched_wq;
637 case -ESHUTDOWN:
638 default:
Joe Perches3590ebc2015-04-07 00:17:00 -0700639 nfc_err(&dev->interface->dev, "Urb failure (status %d)\n",
Thierry Escande0347a6a2013-10-04 12:12:01 +0200640 urb->status);
641 goto sched_wq;
642 }
643
644 in_frame = dev->in_urb->transfer_buffer;
645
646 if (!port100_rx_frame_is_valid(in_frame)) {
Joe Perches3590ebc2015-04-07 00:17:00 -0700647 nfc_err(&dev->interface->dev, "Received an invalid frame\n");
Thierry Escande0347a6a2013-10-04 12:12:01 +0200648 cmd->status = -EIO;
649 goto sched_wq;
650 }
651
652 print_hex_dump_debug("PORT100 RX: ", DUMP_PREFIX_NONE, 16, 1, in_frame,
653 port100_rx_frame_size(in_frame), false);
654
655 if (!port100_rx_frame_is_cmd_response(dev, in_frame)) {
656 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -0700657 "It's not the response to the last command\n");
Thierry Escande0347a6a2013-10-04 12:12:01 +0200658 cmd->status = -EIO;
659 goto sched_wq;
660 }
661
662sched_wq:
663 schedule_work(&dev->cmd_complete_work);
664}
665
666static int port100_submit_urb_for_response(struct port100 *dev, gfp_t flags)
667{
668 dev->in_urb->complete = port100_recv_response;
669
670 return usb_submit_urb(dev->in_urb, flags);
671}
672
673static void port100_recv_ack(struct urb *urb)
674{
675 struct port100 *dev = urb->context;
676 struct port100_cmd *cmd = dev->cmd;
677 struct port100_ack_frame *in_frame;
678 int rc;
679
680 cmd->status = urb->status;
681
682 switch (urb->status) {
683 case 0:
684 break; /* success */
685 case -ECONNRESET:
686 case -ENOENT:
687 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -0700688 "The urb has been stopped (status %d)\n", urb->status);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200689 goto sched_wq;
690 case -ESHUTDOWN:
691 default:
Joe Perches3590ebc2015-04-07 00:17:00 -0700692 nfc_err(&dev->interface->dev, "Urb failure (status %d)\n",
Thierry Escande0347a6a2013-10-04 12:12:01 +0200693 urb->status);
694 goto sched_wq;
695 }
696
697 in_frame = dev->in_urb->transfer_buffer;
698
699 if (!port100_rx_frame_is_ack(in_frame)) {
Joe Perches3590ebc2015-04-07 00:17:00 -0700700 nfc_err(&dev->interface->dev, "Received an invalid ack\n");
Thierry Escande0347a6a2013-10-04 12:12:01 +0200701 cmd->status = -EIO;
702 goto sched_wq;
703 }
704
705 rc = port100_submit_urb_for_response(dev, GFP_ATOMIC);
706 if (rc) {
707 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -0700708 "usb_submit_urb failed with result %d\n", rc);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200709 cmd->status = rc;
710 goto sched_wq;
711 }
712
713 return;
714
715sched_wq:
716 schedule_work(&dev->cmd_complete_work);
717}
718
719static int port100_submit_urb_for_ack(struct port100 *dev, gfp_t flags)
720{
721 dev->in_urb->complete = port100_recv_ack;
722
723 return usb_submit_urb(dev->in_urb, flags);
724}
725
726static int port100_send_ack(struct port100 *dev)
727{
OGAWA Hirofumi35bdf9a2017-02-04 10:16:56 +0900728 int rc = 0;
Thierry Escande0347a6a2013-10-04 12:12:01 +0200729
Thierry Escandeb74584c2016-06-16 20:25:21 +0200730 mutex_lock(&dev->out_urb_lock);
731
OGAWA Hirofumi35bdf9a2017-02-04 10:16:56 +0900732 /*
733 * If prior cancel is in-flight (dev->cmd_cancel == true), we
734 * can skip to send cancel. Then this will wait the prior
735 * cancel, or merged into the next cancel rarely if next
736 * cancel was started before waiting done. In any case, this
737 * will be waked up soon or later.
Thierry Escandeb74584c2016-06-16 20:25:21 +0200738 */
OGAWA Hirofumi35bdf9a2017-02-04 10:16:56 +0900739 if (!dev->cmd_cancel) {
740 reinit_completion(&dev->cmd_cancel_done);
741
742 usb_kill_urb(dev->out_urb);
743
744 dev->out_urb->transfer_buffer = ack_frame;
745 dev->out_urb->transfer_buffer_length = sizeof(ack_frame);
746 rc = usb_submit_urb(dev->out_urb, GFP_KERNEL);
747
748 /*
749 * Set the cmd_cancel flag only if the URB has been
750 * successfully submitted. It will be reset by the out
751 * URB completion callback port100_send_complete().
752 */
753 dev->cmd_cancel = !rc;
754 }
Thierry Escandeb74584c2016-06-16 20:25:21 +0200755
756 mutex_unlock(&dev->out_urb_lock);
757
Thierry Escandea52bd7d2016-06-16 20:25:22 +0200758 if (!rc)
759 wait_for_completion(&dev->cmd_cancel_done);
760
Thierry Escande0347a6a2013-10-04 12:12:01 +0200761 return rc;
762}
763
764static int port100_send_frame_async(struct port100 *dev, struct sk_buff *out,
765 struct sk_buff *in, int in_len)
766{
767 int rc;
768
Thierry Escandeb74584c2016-06-16 20:25:21 +0200769 mutex_lock(&dev->out_urb_lock);
770
771 /* A command cancel frame as been sent through dev->out_urb. Don't try
772 * to submit a new one.
773 */
774 if (dev->cmd_cancel) {
775 rc = -EAGAIN;
776 goto exit;
777 }
778
Thierry Escande0347a6a2013-10-04 12:12:01 +0200779 dev->out_urb->transfer_buffer = out->data;
780 dev->out_urb->transfer_buffer_length = out->len;
781
782 dev->in_urb->transfer_buffer = in->data;
783 dev->in_urb->transfer_buffer_length = in_len;
784
785 print_hex_dump_debug("PORT100 TX: ", DUMP_PREFIX_NONE, 16, 1,
786 out->data, out->len, false);
787
788 rc = usb_submit_urb(dev->out_urb, GFP_KERNEL);
789 if (rc)
Thierry Escandeb74584c2016-06-16 20:25:21 +0200790 goto exit;
Thierry Escande0347a6a2013-10-04 12:12:01 +0200791
792 rc = port100_submit_urb_for_ack(dev, GFP_KERNEL);
793 if (rc)
Oliver Neukum81f48ce2019-11-21 11:37:10 +0100794 usb_kill_urb(dev->out_urb);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200795
Thierry Escandeb74584c2016-06-16 20:25:21 +0200796exit:
797 mutex_unlock(&dev->out_urb_lock);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200798
Thierry Escande0347a6a2013-10-04 12:12:01 +0200799 return rc;
800}
801
802static void port100_build_cmd_frame(struct port100 *dev, u8 cmd_code,
803 struct sk_buff *skb)
804{
805 /* payload is already there, just update datalen */
806 int payload_len = skb->len;
807
808 skb_push(skb, PORT100_FRAME_HEADER_LEN);
809 skb_put(skb, PORT100_FRAME_TAIL_LEN);
810
811 port100_tx_frame_init(skb->data, cmd_code);
812 port100_tx_update_payload_len(skb->data, payload_len);
813 port100_tx_frame_finish(skb->data);
814}
815
816static void port100_send_async_complete(struct port100 *dev)
817{
818 struct port100_cmd *cmd = dev->cmd;
819 int status = cmd->status;
820
821 struct sk_buff *req = cmd->req;
822 struct sk_buff *resp = cmd->resp;
823
824 dev_kfree_skb(req);
825
826 dev->cmd = NULL;
827
828 if (status < 0) {
829 cmd->complete_cb(dev, cmd->complete_cb_context,
830 ERR_PTR(status));
831 dev_kfree_skb(resp);
832 goto done;
833 }
834
835 skb_put(resp, port100_rx_frame_size(resp->data));
836 skb_pull(resp, PORT100_FRAME_HEADER_LEN);
837 skb_trim(resp, resp->len - PORT100_FRAME_TAIL_LEN);
838
839 cmd->complete_cb(dev, cmd->complete_cb_context, resp);
840
841done:
842 kfree(cmd);
843}
844
845static int port100_send_cmd_async(struct port100 *dev, u8 cmd_code,
846 struct sk_buff *req,
847 port100_send_async_complete_t complete_cb,
848 void *complete_cb_context)
849{
850 struct port100_cmd *cmd;
851 struct sk_buff *resp;
852 int rc;
853 int resp_len = PORT100_FRAME_HEADER_LEN +
854 PORT100_FRAME_MAX_PAYLOAD_LEN +
855 PORT100_FRAME_TAIL_LEN;
856
Thierry Escandee3e02582016-06-16 20:25:20 +0200857 if (dev->cmd) {
858 nfc_err(&dev->interface->dev,
859 "A command is still in process\n");
860 return -EBUSY;
861 }
862
Thierry Escande0347a6a2013-10-04 12:12:01 +0200863 resp = alloc_skb(resp_len, GFP_KERNEL);
864 if (!resp)
865 return -ENOMEM;
866
867 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
868 if (!cmd) {
869 dev_kfree_skb(resp);
870 return -ENOMEM;
871 }
872
873 cmd->code = cmd_code;
874 cmd->req = req;
875 cmd->resp = resp;
876 cmd->resp_len = resp_len;
877 cmd->complete_cb = complete_cb;
878 cmd->complete_cb_context = complete_cb_context;
879
880 port100_build_cmd_frame(dev, cmd_code, req);
881
882 dev->cmd = cmd;
883
884 rc = port100_send_frame_async(dev, req, resp, resp_len);
885 if (rc) {
886 kfree(cmd);
887 dev_kfree_skb(resp);
888 dev->cmd = NULL;
889 }
890
891 return rc;
892}
893
894struct port100_sync_cmd_response {
895 struct sk_buff *resp;
896 struct completion done;
897};
898
899static void port100_wq_cmd_complete(struct work_struct *work)
900{
901 struct port100 *dev = container_of(work, struct port100,
902 cmd_complete_work);
903
904 port100_send_async_complete(dev);
905}
906
907static void port100_send_sync_complete(struct port100 *dev, void *_arg,
908 struct sk_buff *resp)
909{
910 struct port100_sync_cmd_response *arg = _arg;
911
912 arg->resp = resp;
913 complete(&arg->done);
914}
915
916static struct sk_buff *port100_send_cmd_sync(struct port100 *dev, u8 cmd_code,
917 struct sk_buff *req)
918{
919 int rc;
920 struct port100_sync_cmd_response arg;
921
922 init_completion(&arg.done);
923
924 rc = port100_send_cmd_async(dev, cmd_code, req,
925 port100_send_sync_complete, &arg);
926 if (rc) {
927 dev_kfree_skb(req);
928 return ERR_PTR(rc);
929 }
930
931 wait_for_completion(&arg.done);
932
933 return arg.resp;
934}
935
936static void port100_send_complete(struct urb *urb)
937{
938 struct port100 *dev = urb->context;
939
Thierry Escandea52bd7d2016-06-16 20:25:22 +0200940 if (dev->cmd_cancel) {
OGAWA Hirofumi35bdf9a2017-02-04 10:16:56 +0900941 complete_all(&dev->cmd_cancel_done);
Thierry Escandea52bd7d2016-06-16 20:25:22 +0200942 dev->cmd_cancel = false;
Thierry Escandea52bd7d2016-06-16 20:25:22 +0200943 }
Thierry Escandeb74584c2016-06-16 20:25:21 +0200944
Thierry Escande0347a6a2013-10-04 12:12:01 +0200945 switch (urb->status) {
946 case 0:
947 break; /* success */
948 case -ECONNRESET:
949 case -ENOENT:
950 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -0700951 "The urb has been stopped (status %d)\n", urb->status);
Thierry Escande0347a6a2013-10-04 12:12:01 +0200952 break;
953 case -ESHUTDOWN:
954 default:
Joe Perches3590ebc2015-04-07 00:17:00 -0700955 nfc_err(&dev->interface->dev, "Urb failure (status %d)\n",
Thierry Escande0347a6a2013-10-04 12:12:01 +0200956 urb->status);
957 }
958}
959
Thierry Escande562d4d52013-10-04 12:12:00 +0200960static void port100_abort_cmd(struct nfc_digital_dev *ddev)
961{
Thierry Escande0347a6a2013-10-04 12:12:01 +0200962 struct port100 *dev = nfc_digital_get_drvdata(ddev);
963
964 /* An ack will cancel the last issued command */
965 port100_send_ack(dev);
966
967 /* cancel the urb request */
968 usb_kill_urb(dev->in_urb);
969}
970
971static struct sk_buff *port100_alloc_skb(struct port100 *dev, unsigned int size)
972{
973 struct sk_buff *skb;
974
975 skb = alloc_skb(dev->skb_headroom + dev->skb_tailroom + size,
976 GFP_KERNEL);
977 if (skb)
978 skb_reserve(skb, dev->skb_headroom);
979
980 return skb;
981}
982
983static int port100_set_command_type(struct port100 *dev, u8 command_type)
984{
985 struct sk_buff *skb;
986 struct sk_buff *resp;
987 int rc;
988
989 skb = port100_alloc_skb(dev, 1);
990 if (!skb)
991 return -ENOMEM;
992
993 *skb_put(skb, sizeof(u8)) = command_type;
994
995 resp = port100_send_cmd_sync(dev, PORT100_CMD_SET_COMMAND_TYPE, skb);
996 if (IS_ERR(resp))
997 return PTR_ERR(resp);
998
999 rc = resp->data[0];
1000
1001 dev_kfree_skb(resp);
1002
1003 return rc;
1004}
1005
1006static u64 port100_get_command_type_mask(struct port100 *dev)
1007{
1008 struct sk_buff *skb;
1009 struct sk_buff *resp;
1010 u64 mask;
1011
1012 skb = port100_alloc_skb(dev, 0);
1013 if (!skb)
Krzysztof Kozlowskie316ae42021-10-25 16:49:36 +02001014 return 0;
Thierry Escande0347a6a2013-10-04 12:12:01 +02001015
1016 resp = port100_send_cmd_sync(dev, PORT100_CMD_GET_COMMAND_TYPE, skb);
1017 if (IS_ERR(resp))
Krzysztof Kozlowskie316ae42021-10-25 16:49:36 +02001018 return 0;
Thierry Escande0347a6a2013-10-04 12:12:01 +02001019
1020 if (resp->len < 8)
1021 mask = 0;
1022 else
1023 mask = be64_to_cpu(*(__be64 *)resp->data);
1024
1025 dev_kfree_skb(resp);
1026
1027 return mask;
1028}
1029
1030static u16 port100_get_firmware_version(struct port100 *dev)
1031{
1032 struct sk_buff *skb;
1033 struct sk_buff *resp;
1034 u16 fw_ver;
1035
1036 skb = port100_alloc_skb(dev, 0);
1037 if (!skb)
1038 return 0;
1039
1040 resp = port100_send_cmd_sync(dev, PORT100_CMD_GET_FIRMWARE_VERSION,
1041 skb);
1042 if (IS_ERR(resp))
1043 return 0;
1044
1045 fw_ver = le16_to_cpu(*(__le16 *)resp->data);
1046
1047 dev_kfree_skb(resp);
1048
1049 return fw_ver;
Thierry Escande562d4d52013-10-04 12:12:00 +02001050}
1051
1052static int port100_switch_rf(struct nfc_digital_dev *ddev, bool on)
1053{
Thierry Escande9f7b57f2013-10-04 12:12:02 +02001054 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1055 struct sk_buff *skb, *resp;
1056
1057 skb = port100_alloc_skb(dev, 1);
1058 if (!skb)
1059 return -ENOMEM;
1060
1061 *skb_put(skb, 1) = on ? 1 : 0;
1062
Thierry Escande9f0c4542016-06-16 20:25:23 +02001063 /* Cancel the last command if the device is being switched off */
1064 if (!on)
1065 port100_abort_cmd(ddev);
1066
Thierry Escande9f7b57f2013-10-04 12:12:02 +02001067 resp = port100_send_cmd_sync(dev, PORT100_CMD_SWITCH_RF, skb);
1068
1069 if (IS_ERR(resp))
1070 return PTR_ERR(resp);
1071
1072 dev_kfree_skb(resp);
1073
1074 return 0;
1075}
1076
1077static int port100_in_set_rf(struct nfc_digital_dev *ddev, u8 rf)
1078{
1079 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1080 struct sk_buff *skb;
1081 struct sk_buff *resp;
1082 int rc;
1083
1084 if (rf >= NFC_DIGITAL_RF_TECH_LAST)
1085 return -EINVAL;
1086
1087 skb = port100_alloc_skb(dev, sizeof(struct port100_in_rf_setting));
1088 if (!skb)
1089 return -ENOMEM;
1090
1091 memcpy(skb_put(skb, sizeof(struct port100_in_rf_setting)),
1092 &in_rf_settings[rf],
1093 sizeof(struct port100_in_rf_setting));
1094
1095 resp = port100_send_cmd_sync(dev, PORT100_CMD_IN_SET_RF, skb);
1096
1097 if (IS_ERR(resp))
1098 return PTR_ERR(resp);
1099
1100 rc = resp->data[0];
1101
1102 dev_kfree_skb(resp);
1103
1104 return rc;
1105}
1106
1107static int port100_in_set_framing(struct nfc_digital_dev *ddev, int param)
1108{
1109 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1110 struct port100_protocol *protocols;
1111 struct sk_buff *skb;
1112 struct sk_buff *resp;
1113 int num_protocols;
1114 size_t size;
1115 int rc;
1116
1117 if (param >= NFC_DIGITAL_FRAMING_LAST)
1118 return -EINVAL;
1119
1120 protocols = in_protocols[param];
1121
1122 num_protocols = 0;
1123 while (protocols[num_protocols].number != PORT100_IN_PROT_END)
1124 num_protocols++;
1125
1126 if (!num_protocols)
1127 return 0;
1128
1129 size = sizeof(struct port100_protocol) * num_protocols;
1130
1131 skb = port100_alloc_skb(dev, size);
1132 if (!skb)
1133 return -ENOMEM;
1134
1135 memcpy(skb_put(skb, size), protocols, size);
1136
1137 resp = port100_send_cmd_sync(dev, PORT100_CMD_IN_SET_PROTOCOL, skb);
1138
1139 if (IS_ERR(resp))
1140 return PTR_ERR(resp);
1141
1142 rc = resp->data[0];
1143
1144 dev_kfree_skb(resp);
1145
1146 return rc;
Thierry Escande562d4d52013-10-04 12:12:00 +02001147}
1148
1149static int port100_in_configure_hw(struct nfc_digital_dev *ddev, int type,
1150 int param)
1151{
Thierry Escande9f7b57f2013-10-04 12:12:02 +02001152 if (type == NFC_DIGITAL_CONFIG_RF_TECH)
1153 return port100_in_set_rf(ddev, param);
1154
1155 if (type == NFC_DIGITAL_CONFIG_FRAMING)
1156 return port100_in_set_framing(ddev, param);
1157
1158 return -EINVAL;
1159}
1160
1161static void port100_in_comm_rf_complete(struct port100 *dev, void *arg,
1162 struct sk_buff *resp)
1163{
1164 struct port100_cb_arg *cb_arg = arg;
1165 nfc_digital_cmd_complete_t cb = cb_arg->complete_cb;
1166 u32 status;
1167 int rc;
1168
1169 if (IS_ERR(resp)) {
1170 rc = PTR_ERR(resp);
1171 goto exit;
1172 }
1173
1174 if (resp->len < 4) {
1175 nfc_err(&dev->interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001176 "Invalid packet length received\n");
Thierry Escande9f7b57f2013-10-04 12:12:02 +02001177 rc = -EIO;
1178 goto error;
1179 }
1180
1181 status = le32_to_cpu(*(__le32 *)resp->data);
1182
1183 skb_pull(resp, sizeof(u32));
1184
1185 if (status == PORT100_CMD_STATUS_TIMEOUT) {
1186 rc = -ETIMEDOUT;
1187 goto error;
1188 }
1189
1190 if (status != PORT100_CMD_STATUS_OK) {
1191 nfc_err(&dev->interface->dev,
1192 "in_comm_rf failed with status 0x%08x\n", status);
1193 rc = -EIO;
1194 goto error;
1195 }
1196
1197 /* Remove collision bits byte */
1198 skb_pull(resp, 1);
1199
1200 goto exit;
1201
1202error:
1203 kfree_skb(resp);
1204 resp = ERR_PTR(rc);
1205
1206exit:
1207 cb(dev->nfc_digital_dev, cb_arg->complete_arg, resp);
1208
1209 kfree(cb_arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001210}
1211
1212static int port100_in_send_cmd(struct nfc_digital_dev *ddev,
1213 struct sk_buff *skb, u16 _timeout,
1214 nfc_digital_cmd_complete_t cb, void *arg)
1215{
Thierry Escande9f7b57f2013-10-04 12:12:02 +02001216 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1217 struct port100_cb_arg *cb_arg;
1218 __le16 timeout;
1219
1220 cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL);
1221 if (!cb_arg)
1222 return -ENOMEM;
1223
1224 cb_arg->complete_cb = cb;
1225 cb_arg->complete_arg = arg;
1226
1227 timeout = cpu_to_le16(_timeout * 10);
1228
1229 memcpy(skb_push(skb, sizeof(__le16)), &timeout, sizeof(__le16));
1230
1231 return port100_send_cmd_async(dev, PORT100_CMD_IN_COMM_RF, skb,
1232 port100_in_comm_rf_complete, cb_arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001233}
1234
Thierry Escande7227c022013-10-04 12:12:03 +02001235static int port100_tg_set_rf(struct nfc_digital_dev *ddev, u8 rf)
1236{
1237 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1238 struct sk_buff *skb;
1239 struct sk_buff *resp;
1240 int rc;
1241
1242 if (rf >= NFC_DIGITAL_RF_TECH_LAST)
1243 return -EINVAL;
1244
1245 skb = port100_alloc_skb(dev, sizeof(struct port100_tg_rf_setting));
1246 if (!skb)
1247 return -ENOMEM;
1248
1249 memcpy(skb_put(skb, sizeof(struct port100_tg_rf_setting)),
1250 &tg_rf_settings[rf],
1251 sizeof(struct port100_tg_rf_setting));
1252
1253 resp = port100_send_cmd_sync(dev, PORT100_CMD_TG_SET_RF, skb);
1254
1255 if (IS_ERR(resp))
1256 return PTR_ERR(resp);
1257
1258 rc = resp->data[0];
1259
1260 dev_kfree_skb(resp);
1261
1262 return rc;
1263}
1264
1265static int port100_tg_set_framing(struct nfc_digital_dev *ddev, int param)
1266{
1267 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1268 struct port100_protocol *protocols;
1269 struct sk_buff *skb;
1270 struct sk_buff *resp;
1271 int rc;
1272 int num_protocols;
1273 size_t size;
1274
1275 if (param >= NFC_DIGITAL_FRAMING_LAST)
1276 return -EINVAL;
1277
1278 protocols = tg_protocols[param];
1279
1280 num_protocols = 0;
1281 while (protocols[num_protocols].number != PORT100_TG_PROT_END)
1282 num_protocols++;
1283
1284 if (!num_protocols)
1285 return 0;
1286
1287 size = sizeof(struct port100_protocol) * num_protocols;
1288
1289 skb = port100_alloc_skb(dev, size);
1290 if (!skb)
1291 return -ENOMEM;
1292
1293 memcpy(skb_put(skb, size), protocols, size);
1294
1295 resp = port100_send_cmd_sync(dev, PORT100_CMD_TG_SET_PROTOCOL, skb);
1296
1297 if (IS_ERR(resp))
1298 return PTR_ERR(resp);
1299
1300 rc = resp->data[0];
1301
1302 dev_kfree_skb(resp);
1303
1304 return rc;
1305}
1306
Thierry Escande562d4d52013-10-04 12:12:00 +02001307static int port100_tg_configure_hw(struct nfc_digital_dev *ddev, int type,
1308 int param)
1309{
Thierry Escande7227c022013-10-04 12:12:03 +02001310 if (type == NFC_DIGITAL_CONFIG_RF_TECH)
1311 return port100_tg_set_rf(ddev, param);
1312
1313 if (type == NFC_DIGITAL_CONFIG_FRAMING)
1314 return port100_tg_set_framing(ddev, param);
1315
1316 return -EINVAL;
1317}
1318
1319static bool port100_tg_target_activated(struct port100 *dev, u8 tgt_activated)
1320{
1321 u8 mask;
1322
1323 switch (dev->cmd_type) {
1324 case PORT100_CMD_TYPE_0:
1325 mask = PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK;
1326 break;
1327 case PORT100_CMD_TYPE_1:
1328 mask = PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK |
1329 PORT100_MDAA_TGT_WAS_ACTIVATED_MASK;
1330 break;
1331 default:
Joe Perches3590ebc2015-04-07 00:17:00 -07001332 nfc_err(&dev->interface->dev, "Unknown command type\n");
Thierry Escande7227c022013-10-04 12:12:03 +02001333 return false;
1334 }
1335
1336 return ((tgt_activated & mask) == mask);
1337}
1338
1339static void port100_tg_comm_rf_complete(struct port100 *dev, void *arg,
1340 struct sk_buff *resp)
1341{
1342 u32 status;
1343 struct port100_cb_arg *cb_arg = arg;
1344 nfc_digital_cmd_complete_t cb = cb_arg->complete_cb;
1345 struct port100_tg_comm_rf_res *hdr;
1346
1347 if (IS_ERR(resp))
1348 goto exit;
1349
1350 hdr = (struct port100_tg_comm_rf_res *)resp->data;
1351
1352 status = le32_to_cpu(hdr->status);
1353
1354 if (cb_arg->mdaa &&
1355 !port100_tg_target_activated(dev, hdr->target_activated)) {
1356 kfree_skb(resp);
1357 resp = ERR_PTR(-ETIMEDOUT);
1358
1359 goto exit;
1360 }
1361
1362 skb_pull(resp, sizeof(struct port100_tg_comm_rf_res));
1363
1364 if (status != PORT100_CMD_STATUS_OK) {
1365 kfree_skb(resp);
1366
1367 if (status == PORT100_CMD_STATUS_TIMEOUT)
1368 resp = ERR_PTR(-ETIMEDOUT);
1369 else
1370 resp = ERR_PTR(-EIO);
1371 }
1372
1373exit:
1374 cb(dev->nfc_digital_dev, cb_arg->complete_arg, resp);
1375
1376 kfree(cb_arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001377}
1378
1379static int port100_tg_send_cmd(struct nfc_digital_dev *ddev,
1380 struct sk_buff *skb, u16 timeout,
1381 nfc_digital_cmd_complete_t cb, void *arg)
1382{
Thierry Escande7227c022013-10-04 12:12:03 +02001383 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1384 struct port100_tg_comm_rf_cmd *hdr;
1385 struct port100_cb_arg *cb_arg;
1386
1387 cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL);
1388 if (!cb_arg)
1389 return -ENOMEM;
1390
1391 cb_arg->complete_cb = cb;
1392 cb_arg->complete_arg = arg;
1393
1394 skb_push(skb, sizeof(struct port100_tg_comm_rf_cmd));
1395
1396 hdr = (struct port100_tg_comm_rf_cmd *)skb->data;
1397
1398 memset(hdr, 0, sizeof(struct port100_tg_comm_rf_cmd));
1399 hdr->guard_time = cpu_to_le16(500);
1400 hdr->send_timeout = cpu_to_le16(0xFFFF);
1401 hdr->recv_timeout = cpu_to_le16(timeout);
1402
1403 return port100_send_cmd_async(dev, PORT100_CMD_TG_COMM_RF, skb,
1404 port100_tg_comm_rf_complete, cb_arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001405}
1406
1407static int port100_listen_mdaa(struct nfc_digital_dev *ddev,
1408 struct digital_tg_mdaa_params *params,
1409 u16 timeout,
1410 nfc_digital_cmd_complete_t cb, void *arg)
1411{
Thierry Escande7227c022013-10-04 12:12:03 +02001412 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1413 struct port100_tg_comm_rf_cmd *hdr;
1414 struct port100_cb_arg *cb_arg;
1415 struct sk_buff *skb;
1416 int rc;
1417
1418 rc = port100_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH,
1419 NFC_DIGITAL_RF_TECH_106A);
1420 if (rc)
1421 return rc;
1422
1423 rc = port100_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING,
1424 NFC_DIGITAL_FRAMING_NFCA_NFC_DEP);
1425 if (rc)
1426 return rc;
1427
1428 cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL);
1429 if (!cb_arg)
1430 return -ENOMEM;
1431
1432 cb_arg->complete_cb = cb;
1433 cb_arg->complete_arg = arg;
1434 cb_arg->mdaa = 1;
1435
1436 skb = port100_alloc_skb(dev, 0);
1437 if (!skb) {
1438 kfree(cb_arg);
1439 return -ENOMEM;
1440 }
1441
1442 skb_push(skb, sizeof(struct port100_tg_comm_rf_cmd));
1443 hdr = (struct port100_tg_comm_rf_cmd *)skb->data;
1444
1445 memset(hdr, 0, sizeof(struct port100_tg_comm_rf_cmd));
1446
1447 hdr->guard_time = 0;
1448 hdr->send_timeout = cpu_to_le16(0xFFFF);
1449 hdr->mdaa = 1;
1450 hdr->nfca_param[0] = (params->sens_res >> 8) & 0xFF;
1451 hdr->nfca_param[1] = params->sens_res & 0xFF;
1452 memcpy(hdr->nfca_param + 2, params->nfcid1, 3);
1453 hdr->nfca_param[5] = params->sel_res;
1454 memcpy(hdr->nfcf_param, params->nfcid2, 8);
1455 hdr->nfcf_param[16] = (params->sc >> 8) & 0xFF;
1456 hdr->nfcf_param[17] = params->sc & 0xFF;
1457 hdr->recv_timeout = cpu_to_le16(timeout);
1458
1459 return port100_send_cmd_async(dev, PORT100_CMD_TG_COMM_RF, skb,
1460 port100_tg_comm_rf_complete, cb_arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001461}
1462
1463static int port100_listen(struct nfc_digital_dev *ddev, u16 timeout,
1464 nfc_digital_cmd_complete_t cb, void *arg)
1465{
Thierry Escande7227c022013-10-04 12:12:03 +02001466 struct port100 *dev = nfc_digital_get_drvdata(ddev);
1467 struct sk_buff *skb;
1468
1469 skb = port100_alloc_skb(dev, 0);
1470 if (!skb)
1471 return -ENOMEM;
1472
1473 return port100_tg_send_cmd(ddev, skb, timeout, cb, arg);
Thierry Escande562d4d52013-10-04 12:12:00 +02001474}
1475
1476static struct nfc_digital_ops port100_digital_ops = {
1477 .in_configure_hw = port100_in_configure_hw,
1478 .in_send_cmd = port100_in_send_cmd,
1479
1480 .tg_listen_mdaa = port100_listen_mdaa,
1481 .tg_listen = port100_listen,
1482 .tg_configure_hw = port100_tg_configure_hw,
1483 .tg_send_cmd = port100_tg_send_cmd,
1484
1485 .switch_rf = port100_switch_rf,
1486 .abort_cmd = port100_abort_cmd,
1487};
1488
1489static const struct usb_device_id port100_table[] = {
Axel Lin4aa7ed02014-02-14 17:00:12 +08001490 { USB_DEVICE(SONY_VENDOR_ID, RCS380_PRODUCT_ID), },
Thierry Escande562d4d52013-10-04 12:12:00 +02001491 { }
1492};
1493MODULE_DEVICE_TABLE(usb, port100_table);
1494
1495static int port100_probe(struct usb_interface *interface,
1496 const struct usb_device_id *id)
1497{
1498 struct port100 *dev;
1499 int rc;
Thierry Escande0347a6a2013-10-04 12:12:01 +02001500 struct usb_host_interface *iface_desc;
1501 struct usb_endpoint_descriptor *endpoint;
1502 int in_endpoint;
1503 int out_endpoint;
1504 u16 fw_version;
1505 u64 cmd_type_mask;
1506 int i;
Thierry Escande562d4d52013-10-04 12:12:00 +02001507
1508 dev = devm_kzalloc(&interface->dev, sizeof(struct port100), GFP_KERNEL);
1509 if (!dev)
1510 return -ENOMEM;
1511
Thierry Escandeb74584c2016-06-16 20:25:21 +02001512 mutex_init(&dev->out_urb_lock);
Thierry Escande562d4d52013-10-04 12:12:00 +02001513 dev->udev = usb_get_dev(interface_to_usbdev(interface));
1514 dev->interface = interface;
1515 usb_set_intfdata(interface, dev);
1516
Thierry Escande0347a6a2013-10-04 12:12:01 +02001517 in_endpoint = out_endpoint = 0;
1518 iface_desc = interface->cur_altsetting;
1519 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1520 endpoint = &iface_desc->endpoint[i].desc;
1521
1522 if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint))
1523 in_endpoint = endpoint->bEndpointAddress;
1524
1525 if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint))
1526 out_endpoint = endpoint->bEndpointAddress;
1527 }
1528
1529 if (!in_endpoint || !out_endpoint) {
1530 nfc_err(&interface->dev,
1531 "Could not find bulk-in or bulk-out endpoint\n");
1532 rc = -ENODEV;
1533 goto error;
1534 }
1535
1536 dev->in_urb = usb_alloc_urb(0, GFP_KERNEL);
1537 dev->out_urb = usb_alloc_urb(0, GFP_KERNEL);
1538
1539 if (!dev->in_urb || !dev->out_urb) {
1540 nfc_err(&interface->dev, "Could not allocate USB URBs\n");
1541 rc = -ENOMEM;
1542 goto error;
1543 }
1544
1545 usb_fill_bulk_urb(dev->in_urb, dev->udev,
1546 usb_rcvbulkpipe(dev->udev, in_endpoint),
1547 NULL, 0, NULL, dev);
1548 usb_fill_bulk_urb(dev->out_urb, dev->udev,
1549 usb_sndbulkpipe(dev->udev, out_endpoint),
1550 NULL, 0, port100_send_complete, dev);
1551
1552 dev->skb_headroom = PORT100_FRAME_HEADER_LEN +
1553 PORT100_COMM_RF_HEAD_MAX_LEN;
1554 dev->skb_tailroom = PORT100_FRAME_TAIL_LEN;
1555
OGAWA Hirofumi35bdf9a2017-02-04 10:16:56 +09001556 init_completion(&dev->cmd_cancel_done);
Thierry Escande0347a6a2013-10-04 12:12:01 +02001557 INIT_WORK(&dev->cmd_complete_work, port100_wq_cmd_complete);
1558
1559 /* The first thing to do with the Port-100 is to set the command type
1560 * to be used. If supported we use command type 1. 0 otherwise.
1561 */
1562 cmd_type_mask = port100_get_command_type_mask(dev);
1563 if (!cmd_type_mask) {
1564 nfc_err(&interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001565 "Could not get supported command types\n");
Thierry Escande0347a6a2013-10-04 12:12:01 +02001566 rc = -ENODEV;
1567 goto error;
1568 }
1569
1570 if (PORT100_CMD_TYPE_IS_SUPPORTED(cmd_type_mask, PORT100_CMD_TYPE_1))
1571 dev->cmd_type = PORT100_CMD_TYPE_1;
1572 else
1573 dev->cmd_type = PORT100_CMD_TYPE_0;
1574
1575 rc = port100_set_command_type(dev, dev->cmd_type);
1576 if (rc) {
1577 nfc_err(&interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001578 "The device does not support command type %u\n",
Thierry Escande0347a6a2013-10-04 12:12:01 +02001579 dev->cmd_type);
1580 goto error;
1581 }
1582
1583 fw_version = port100_get_firmware_version(dev);
1584 if (!fw_version)
1585 nfc_err(&interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001586 "Could not get device firmware version\n");
Thierry Escande0347a6a2013-10-04 12:12:01 +02001587
1588 nfc_info(&interface->dev,
1589 "Sony NFC Port-100 Series attached (firmware v%x.%02x)\n",
1590 (fw_version & 0xFF00) >> 8, fw_version & 0xFF);
Thierry Escande562d4d52013-10-04 12:12:00 +02001591
1592 dev->nfc_digital_dev = nfc_digital_allocate_device(&port100_digital_ops,
1593 PORT100_PROTOCOLS,
1594 PORT100_CAPABILITIES,
1595 dev->skb_headroom,
1596 dev->skb_tailroom);
1597 if (!dev->nfc_digital_dev) {
1598 nfc_err(&interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001599 "Could not allocate nfc_digital_dev\n");
Thierry Escande562d4d52013-10-04 12:12:00 +02001600 rc = -ENOMEM;
1601 goto error;
1602 }
1603
1604 nfc_digital_set_parent_dev(dev->nfc_digital_dev, &interface->dev);
1605 nfc_digital_set_drvdata(dev->nfc_digital_dev, dev);
1606
1607 rc = nfc_digital_register_device(dev->nfc_digital_dev);
1608 if (rc) {
1609 nfc_err(&interface->dev,
Joe Perches3590ebc2015-04-07 00:17:00 -07001610 "Could not register digital device\n");
Thierry Escande562d4d52013-10-04 12:12:00 +02001611 goto free_nfc_dev;
1612 }
1613
1614 return 0;
1615
1616free_nfc_dev:
1617 nfc_digital_free_device(dev->nfc_digital_dev);
1618
1619error:
Pavel Skripkin205c4ec2022-03-08 21:50:07 +03001620 usb_kill_urb(dev->in_urb);
Thierry Escande0347a6a2013-10-04 12:12:01 +02001621 usb_free_urb(dev->in_urb);
Pavel Skripkin205c4ec2022-03-08 21:50:07 +03001622 usb_kill_urb(dev->out_urb);
Thierry Escande0347a6a2013-10-04 12:12:01 +02001623 usb_free_urb(dev->out_urb);
1624 usb_put_dev(dev->udev);
1625
Thierry Escande562d4d52013-10-04 12:12:00 +02001626 return rc;
1627}
1628
1629static void port100_disconnect(struct usb_interface *interface)
1630{
1631 struct port100 *dev;
1632
1633 dev = usb_get_intfdata(interface);
1634 usb_set_intfdata(interface, NULL);
1635
1636 nfc_digital_unregister_device(dev->nfc_digital_dev);
1637 nfc_digital_free_device(dev->nfc_digital_dev);
1638
Thierry Escande0347a6a2013-10-04 12:12:01 +02001639 usb_kill_urb(dev->in_urb);
1640 usb_kill_urb(dev->out_urb);
1641
1642 usb_free_urb(dev->in_urb);
1643 usb_free_urb(dev->out_urb);
Alexey Khoroshilovc36aeba2014-01-05 00:08:05 +04001644 usb_put_dev(dev->udev);
Thierry Escande0347a6a2013-10-04 12:12:01 +02001645
1646 kfree(dev->cmd);
1647
Joe Perches3590ebc2015-04-07 00:17:00 -07001648 nfc_info(&interface->dev, "Sony Port-100 NFC device disconnected\n");
Thierry Escande562d4d52013-10-04 12:12:00 +02001649}
1650
1651static struct usb_driver port100_driver = {
1652 .name = "port100",
1653 .probe = port100_probe,
1654 .disconnect = port100_disconnect,
1655 .id_table = port100_table,
1656};
1657
1658module_usb_driver(port100_driver);
1659
1660MODULE_DESCRIPTION("NFC Port-100 series usb driver ver " VERSION);
1661MODULE_VERSION(VERSION);
1662MODULE_LICENSE("GPL");