24 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
38 #define NFC_CHECK_PRES_FREQ_MS 2000
56 device_lock(&dev->
dev);
58 if (!device_is_registered(&dev->
dev)) {
69 rc = dev->
ops->dev_up(dev);
75 device_unlock(&dev->
dev);
90 device_lock(&dev->
dev);
92 if (!device_is_registered(&dev->
dev)) {
107 if (dev->
ops->dev_down)
108 dev->
ops->dev_down(dev);
113 device_unlock(&dev->
dev);
130 pr_debug(
"dev_name %s initiator protocols 0x%x target protocols 0x%x\n",
131 dev_name(&dev->
dev), im_protocols, tm_protocols);
133 if (!im_protocols && !tm_protocols)
136 device_lock(&dev->
dev);
138 if (!device_is_registered(&dev->
dev)) {
148 rc = dev->
ops->start_poll(dev, im_protocols, tm_protocols);
155 device_unlock(&dev->
dev);
170 device_lock(&dev->
dev);
172 if (!device_is_registered(&dev->
dev)) {
182 dev->
ops->stop_poll(dev);
186 device_unlock(&dev->
dev);
198 if (dev->
targets[i].idx == target_idx)
212 pr_debug(
"dev_name=%s comm %d\n", dev_name(&dev->
dev), comm_mode);
214 if (!dev->
ops->dep_link_up)
217 device_lock(&dev->
dev);
219 if (!device_is_registered(&dev->
dev)) {
235 target = nfc_find_target(dev, target_index);
236 if (target ==
NULL) {
241 rc = dev->
ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
248 device_unlock(&dev->
dev);
258 if (!dev->
ops->dep_link_down)
261 device_lock(&dev->
dev);
263 if (!device_is_registered(&dev->
dev)) {
273 rc = dev->
ops->dep_link_down(dev);
282 device_unlock(&dev->
dev);
287 u8 comm_mode,
u8 rf_mode)
309 pr_debug(
"dev_name=%s target_idx=%u protocol=%u\n",
310 dev_name(&dev->
dev), target_idx, protocol);
312 device_lock(&dev->
dev);
314 if (!device_is_registered(&dev->
dev)) {
324 target = nfc_find_target(dev, target_idx);
325 if (target ==
NULL) {
330 rc = dev->
ops->activate_target(dev, target, protocol);
335 if (dev->
ops->check_presence)
341 device_unlock(&dev->
dev);
355 pr_debug(
"dev_name=%s target_idx=%u\n",
356 dev_name(&dev->
dev), target_idx);
358 device_lock(&dev->
dev);
360 if (!device_is_registered(&dev->
dev)) {
375 if (dev->
ops->check_presence)
382 device_unlock(&dev->
dev);
402 pr_debug(
"dev_name=%s target_idx=%u skb->len=%u\n",
403 dev_name(&dev->
dev), target_idx, skb->
len);
405 device_lock(&dev->
dev);
407 if (!device_is_registered(&dev->
dev)) {
420 if (dev->
ops->check_presence)
426 if (!rc && dev->
ops->check_presence)
430 rc = dev->
ops->tm_send(dev, skb);
439 device_unlock(&dev->
dev);
445 pr_debug(
"dev_name=%s gb_len=%d\n", dev_name(&dev->
dev), gb_len);
475 u8 *gb,
size_t gb_len)
479 device_lock(&dev->
dev);
497 device_unlock(&dev->
dev);
545 total_size = size + 1;
546 skb = alloc_skb(total_size, gfp);
576 pr_debug(
"dev_name=%s n_targets=%d\n", dev_name(&dev->
dev), n_targets);
578 for (i = 0; i < n_targets; i++)
581 device_lock(&dev->
dev);
584 device_unlock(&dev->
dev);
602 device_unlock(&dev->
dev);
608 device_unlock(&dev->
dev);
633 pr_debug(
"dev_name %s n_target %d\n", dev_name(&dev->
dev), target_idx);
635 device_lock(&dev->
dev);
639 if (tg->
idx == target_idx)
644 device_unlock(&dev->
dev);
660 device_unlock(&dev->
dev);
674 static void nfc_release(
struct device *
d)
680 if (dev->
ops->check_presence) {
696 device_lock(&dev->
dev);
705 device_unlock(&dev->
dev);
711 device_unlock(&dev->
dev);
714 static void nfc_check_pres_timeout(
unsigned long data)
723 .dev_release = nfc_release,
727 static int match_idx(
struct device *d,
void *
data)
763 if (!supported_protocols)
819 pr_err(
"Could not register llcp device\n");
823 pr_debug(
"The userspace won't be notified that the device %s was added\n",
824 dev_name(&dev->
dev));
846 device_lock(&dev->
dev);
848 device_unlock(&dev->
dev);
856 pr_debug(
"The userspace won't be notified that the device %s was removed\n",
857 dev_name(&dev->
dev));
862 static int __init nfc_init(
void)
904 static void __exit nfc_exit(
void)