Skip to content

Commit bf30a67

Browse files
mgreerazSamuel Ortiz
authored andcommitted
NFC: digital: Add 'tg_listen_md' and 'tg_get_rf_tech' driver hooks
The digital layer of the NFC subsystem currently supports a 'tg_listen_mdaa' driver hook that supports devices that can do mode detection and automatic anticollision. However, there are some devices that can do mode detection but not automatic anitcollision so add the 'tg_listen_md' hook to support those devices. In order for the digital layer to get the RF technology detected by the device from the driver, add the 'tg_get_rf_tech' hook. It is only valid to call this hook immediately after a successful call to 'tg_listen_md'. CC: Thierry Escande <thierry.escande@linux.intel.com> Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent f63bac9 commit bf30a67

4 files changed

Lines changed: 93 additions & 9 deletions

File tree

‎include/net/nfc/digital.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ typedef void (*nfc_digital_cmd_complete_t)(struct nfc_digital_dev *ddev,
127127
* the NFC-DEP ATR_REQ command through cb. The digital stack deducts the RF
128128
* tech by analyzing the SoD of the frame containing the ATR_REQ command.
129129
* This is an asynchronous function.
130+
* @tg_listen_md: If supported, put the device in automatic listen mode with
131+
* mode detection but without automatic anti-collision. In this mode, the
132+
* device automatically detects the RF technology. What the actual
133+
* RF technology is can be retrieved by calling @tg_get_rf_tech.
134+
* The digital stack will then perform the appropriate anti-collision
135+
* sequence. This is an asynchronous function.
136+
* @tg_get_rf_tech: Required when @tg_listen_md is supported, unused otherwise.
137+
* Return the RF Technology that was detected by the @tg_listen_md call.
138+
* This is a synchronous function.
130139
*
131140
* @switch_rf: Turns device radio on or off. The stack does not call explicitly
132141
* switch_rf to turn the radio on. A call to in|tg_configure_hw must turn
@@ -161,6 +170,9 @@ struct nfc_digital_ops {
161170
struct digital_tg_mdaa_params *mdaa_params,
162171
u16 timeout, nfc_digital_cmd_complete_t cb,
163172
void *arg);
173+
int (*tg_listen_md)(struct nfc_digital_dev *ddev, u16 timeout,
174+
nfc_digital_cmd_complete_t cb, void *arg);
175+
int (*tg_get_rf_tech)(struct nfc_digital_dev *ddev, u8 *rf_tech);
164176

165177
int (*switch_rf)(struct nfc_digital_dev *ddev, bool on);
166178
void (*abort_cmd)(struct nfc_digital_dev *ddev);

‎net/nfc/digital.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define DIGITAL_CMD_TG_SEND 1
3030
#define DIGITAL_CMD_TG_LISTEN 2
3131
#define DIGITAL_CMD_TG_LISTEN_MDAA 3
32+
#define DIGITAL_CMD_TG_LISTEN_MD 4
3233

3334
#define DIGITAL_MAX_HEADER_LEN 7
3435
#define DIGITAL_CRC_LEN 2
@@ -121,6 +122,8 @@ int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb);
121122

122123
int digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech);
123124
int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech);
125+
void digital_tg_recv_md_req(struct nfc_digital_dev *ddev, void *arg,
126+
struct sk_buff *resp);
124127

125128
typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
126129

‎net/nfc/digital_core.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ static void digital_wq_cmd(struct work_struct *work)
201201
digital_send_cmd_complete, cmd);
202202
break;
203203

204+
case DIGITAL_CMD_TG_LISTEN_MD:
205+
rc = ddev->ops->tg_listen_md(ddev, cmd->timeout,
206+
digital_send_cmd_complete, cmd);
207+
break;
208+
204209
default:
205210
pr_err("Unknown cmd type %d\n", cmd->type);
206211
return;
@@ -293,6 +298,12 @@ static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
293298
500, digital_tg_recv_atr_req, NULL);
294299
}
295300

301+
static int digital_tg_listen_md(struct nfc_digital_dev *ddev, u8 rf_tech)
302+
{
303+
return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MD, NULL, NULL, 500,
304+
digital_tg_recv_md_req, NULL);
305+
}
306+
296307
int digital_target_found(struct nfc_digital_dev *ddev,
297308
struct nfc_target *target, u8 protocol)
298309
{
@@ -510,6 +521,9 @@ static int digital_start_poll(struct nfc_dev *nfc_dev, __u32 im_protocols,
510521
if (ddev->ops->tg_listen_mdaa) {
511522
digital_add_poll_tech(ddev, 0,
512523
digital_tg_listen_mdaa);
524+
} else if (ddev->ops->tg_listen_md) {
525+
digital_add_poll_tech(ddev, 0,
526+
digital_tg_listen_md);
513527
} else {
514528
digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A,
515529
digital_tg_listen_nfca);
@@ -737,7 +751,7 @@ struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
737751

738752
if (!ops->in_configure_hw || !ops->in_send_cmd || !ops->tg_listen ||
739753
!ops->tg_configure_hw || !ops->tg_send_cmd || !ops->abort_cmd ||
740-
!ops->switch_rf)
754+
!ops->switch_rf || (ops->tg_listen_md && !ops->tg_get_rf_tech))
741755
return NULL;
742756

743757
ddev = kzalloc(sizeof(struct nfc_digital_dev), GFP_KERNEL);

‎net/nfc/digital_technology.c‎

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,33 +1218,48 @@ void digital_tg_recv_sensf_req(struct nfc_digital_dev *ddev, void *arg,
12181218
dev_kfree_skb(resp);
12191219
}
12201220

1221-
int digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech)
1221+
static int digital_tg_config_nfca(struct nfc_digital_dev *ddev)
12221222
{
12231223
int rc;
12241224

1225-
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, rf_tech);
1225+
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH,
1226+
NFC_DIGITAL_RF_TECH_106A);
12261227
if (rc)
12271228
return rc;
12281229

1229-
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING,
1230-
NFC_DIGITAL_FRAMING_NFCA_NFC_DEP);
1230+
return digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING,
1231+
NFC_DIGITAL_FRAMING_NFCA_NFC_DEP);
1232+
}
1233+
1234+
int digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech)
1235+
{
1236+
int rc;
1237+
1238+
rc = digital_tg_config_nfca(ddev);
12311239
if (rc)
12321240
return rc;
12331241

12341242
return digital_tg_listen(ddev, 300, digital_tg_recv_sens_req, NULL);
12351243
}
12361244

1237-
int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech)
1245+
static int digital_tg_config_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech)
12381246
{
12391247
int rc;
1240-
u8 *nfcid2;
12411248

12421249
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, rf_tech);
12431250
if (rc)
12441251
return rc;
12451252

1246-
rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING,
1247-
NFC_DIGITAL_FRAMING_NFCF_NFC_DEP);
1253+
return digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING,
1254+
NFC_DIGITAL_FRAMING_NFCF_NFC_DEP);
1255+
}
1256+
1257+
int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech)
1258+
{
1259+
int rc;
1260+
u8 *nfcid2;
1261+
1262+
rc = digital_tg_config_nfcf(ddev, rf_tech);
12481263
if (rc)
12491264
return rc;
12501265

@@ -1258,3 +1273,43 @@ int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech)
12581273

12591274
return digital_tg_listen(ddev, 300, digital_tg_recv_sensf_req, nfcid2);
12601275
}
1276+
1277+
void digital_tg_recv_md_req(struct nfc_digital_dev *ddev, void *arg,
1278+
struct sk_buff *resp)
1279+
{
1280+
u8 rf_tech;
1281+
int rc;
1282+
1283+
if (IS_ERR(resp)) {
1284+
resp = NULL;
1285+
goto exit_free_skb;
1286+
}
1287+
1288+
rc = ddev->ops->tg_get_rf_tech(ddev, &rf_tech);
1289+
if (rc)
1290+
goto exit_free_skb;
1291+
1292+
switch (rf_tech) {
1293+
case NFC_DIGITAL_RF_TECH_106A:
1294+
rc = digital_tg_config_nfca(ddev);
1295+
if (rc)
1296+
goto exit_free_skb;
1297+
digital_tg_recv_sens_req(ddev, arg, resp);
1298+
break;
1299+
case NFC_DIGITAL_RF_TECH_212F:
1300+
case NFC_DIGITAL_RF_TECH_424F:
1301+
rc = digital_tg_config_nfcf(ddev, rf_tech);
1302+
if (rc)
1303+
goto exit_free_skb;
1304+
digital_tg_recv_sensf_req(ddev, arg, resp);
1305+
break;
1306+
default:
1307+
goto exit_free_skb;
1308+
}
1309+
1310+
return;
1311+
1312+
exit_free_skb:
1313+
digital_poll_next_tech(ddev);
1314+
dev_kfree_skb(resp);
1315+
}

0 commit comments

Comments
 (0)