2 * Copyright (C) 2011 Instituto Nokia de Tecnologia
5 * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
6 * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/rfkill.h>
29 #include <linux/nfc.h>
31 #include <net/genetlink.h>
37 #define NFC_CHECK_PRES_FREQ_MS 2000
39 int nfc_devlist_generation;
40 DEFINE_MUTEX(nfc_devlist_mutex);
42 /* NFC device ID bitmap */
43 static DEFINE_IDA(nfc_index_ida);
45 int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
49 pr_debug("%s do firmware %s\n", dev_name(&dev->dev), firmware_name);
51 device_lock(&dev->dev);
53 if (!device_is_registered(&dev->dev)) {
63 if (!dev->ops->fw_download) {
68 dev->fw_download_in_progress = true;
69 rc = dev->ops->fw_download(dev, firmware_name);
71 dev->fw_download_in_progress = false;
74 device_unlock(&dev->dev);
79 * nfc_fw_download_done - inform that a firmware download was completed
81 * @dev: The nfc device to which firmware was downloaded
82 * @firmware_name: The firmware filename
83 * @result: The positive value of a standard errno value
85 int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
88 dev->fw_download_in_progress = false;
90 return nfc_genl_fw_download_done(dev, firmware_name, result);
92 EXPORT_SYMBOL(nfc_fw_download_done);
95 * nfc_dev_up - turn on the NFC device
97 * @dev: The nfc device to be turned on
99 * The device remains up until the nfc_dev_down function is called.
101 int nfc_dev_up(struct nfc_dev *dev)
105 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
107 device_lock(&dev->dev);
109 if (dev->rfkill && rfkill_blocked(dev->rfkill)) {
114 if (!device_is_registered(&dev->dev)) {
119 if (dev->fw_download_in_progress) {
129 if (dev->ops->dev_up)
130 rc = dev->ops->dev_up(dev);
135 /* We have to enable the device before discovering SEs */
136 if (dev->ops->discover_se) {
137 rc = dev->ops->discover_se(dev);
139 pr_warn("SE discovery failed\n");
143 device_unlock(&dev->dev);
148 * nfc_dev_down - turn off the NFC device
150 * @dev: The nfc device to be turned off
152 int nfc_dev_down(struct nfc_dev *dev)
156 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
158 device_lock(&dev->dev);
160 if (!device_is_registered(&dev->dev)) {
170 if (dev->polling || dev->active_target) {
175 if (dev->ops->dev_down)
176 dev->ops->dev_down(dev);
181 device_unlock(&dev->dev);
185 static int nfc_rfkill_set_block(void *data, bool blocked)
187 struct nfc_dev *dev = data;
189 pr_debug("%s blocked %d", dev_name(&dev->dev), blocked);
199 static const struct rfkill_ops nfc_rfkill_ops = {
200 .set_block = nfc_rfkill_set_block,
204 * nfc_start_poll - start polling for nfc targets
206 * @dev: The nfc device that must start polling
207 * @protocols: bitset of nfc protocols that must be used for polling
209 * The device remains polling for targets until a target is found or
210 * the nfc_stop_poll function is called.
212 int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
216 pr_debug("dev_name %s initiator protocols 0x%x target protocols 0x%x\n",
217 dev_name(&dev->dev), im_protocols, tm_protocols);
219 if (!im_protocols && !tm_protocols)
222 device_lock(&dev->dev);
224 if (!device_is_registered(&dev->dev)) {
239 rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
242 dev->rf_mode = NFC_RF_NONE;
246 device_unlock(&dev->dev);
251 * nfc_stop_poll - stop polling for nfc targets
253 * @dev: The nfc device that must stop polling
255 int nfc_stop_poll(struct nfc_dev *dev)
259 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
261 device_lock(&dev->dev);
263 if (!device_is_registered(&dev->dev)) {
273 dev->ops->stop_poll(dev);
274 dev->polling = false;
275 dev->rf_mode = NFC_RF_NONE;
278 device_unlock(&dev->dev);
282 static struct nfc_target *nfc_find_target(struct nfc_dev *dev, u32 target_idx)
286 if (dev->n_targets == 0)
289 for (i = 0; i < dev->n_targets; i++) {
290 if (dev->targets[i].idx == target_idx)
291 return &dev->targets[i];
297 int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
302 struct nfc_target *target;
304 pr_debug("dev_name=%s comm %d\n", dev_name(&dev->dev), comm_mode);
306 if (!dev->ops->dep_link_up)
309 device_lock(&dev->dev);
311 if (!device_is_registered(&dev->dev)) {
316 if (dev->dep_link_up == true) {
321 gb = nfc_llcp_general_bytes(dev, &gb_len);
322 if (gb_len > NFC_MAX_GT_LEN) {
327 target = nfc_find_target(dev, target_index);
328 if (target == NULL) {
333 rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
335 dev->active_target = target;
336 dev->rf_mode = NFC_RF_INITIATOR;
340 device_unlock(&dev->dev);
344 int nfc_dep_link_down(struct nfc_dev *dev)
348 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
350 if (!dev->ops->dep_link_down)
353 device_lock(&dev->dev);
355 if (!device_is_registered(&dev->dev)) {
360 if (dev->dep_link_up == false) {
365 rc = dev->ops->dep_link_down(dev);
367 dev->dep_link_up = false;
368 dev->active_target = NULL;
369 dev->rf_mode = NFC_RF_NONE;
370 nfc_llcp_mac_is_down(dev);
371 nfc_genl_dep_link_down_event(dev);
375 device_unlock(&dev->dev);
380 int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
381 u8 comm_mode, u8 rf_mode)
383 dev->dep_link_up = true;
385 if (!dev->active_target && rf_mode == NFC_RF_INITIATOR) {
386 struct nfc_target *target;
388 target = nfc_find_target(dev, target_idx);
392 dev->active_target = target;
395 dev->polling = false;
396 dev->rf_mode = rf_mode;
398 nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
400 return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode);
402 EXPORT_SYMBOL(nfc_dep_link_is_up);
405 * nfc_activate_target - prepare the target for data exchange
407 * @dev: The nfc device that found the target
408 * @target_idx: index of the target that must be activated
409 * @protocol: nfc protocol that will be used for data exchange
411 int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
414 struct nfc_target *target;
416 pr_debug("dev_name=%s target_idx=%u protocol=%u\n",
417 dev_name(&dev->dev), target_idx, protocol);
419 device_lock(&dev->dev);
421 if (!device_is_registered(&dev->dev)) {
426 if (dev->active_target) {
431 target = nfc_find_target(dev, target_idx);
432 if (target == NULL) {
437 rc = dev->ops->activate_target(dev, target, protocol);
439 dev->active_target = target;
440 dev->rf_mode = NFC_RF_INITIATOR;
442 if (dev->ops->check_presence && !dev->shutting_down)
443 mod_timer(&dev->check_pres_timer, jiffies +
444 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
448 device_unlock(&dev->dev);
453 * nfc_deactivate_target - deactivate a nfc target
455 * @dev: The nfc device that found the target
456 * @target_idx: index of the target that must be deactivated
458 int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
462 pr_debug("dev_name=%s target_idx=%u\n",
463 dev_name(&dev->dev), target_idx);
465 device_lock(&dev->dev);
467 if (!device_is_registered(&dev->dev)) {
472 if (dev->active_target == NULL) {
477 if (dev->active_target->idx != target_idx) {
482 if (dev->ops->check_presence)
483 del_timer_sync(&dev->check_pres_timer);
485 dev->ops->deactivate_target(dev, dev->active_target);
486 dev->active_target = NULL;
489 device_unlock(&dev->dev);
494 * nfc_data_exchange - transceive data
496 * @dev: The nfc device that found the target
497 * @target_idx: index of the target
498 * @skb: data to be sent
499 * @cb: callback called when the response is received
500 * @cb_context: parameter for the callback function
502 * The user must wait for the callback before calling this function again.
504 int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
505 data_exchange_cb_t cb, void *cb_context)
509 pr_debug("dev_name=%s target_idx=%u skb->len=%u\n",
510 dev_name(&dev->dev), target_idx, skb->len);
512 device_lock(&dev->dev);
514 if (!device_is_registered(&dev->dev)) {
520 if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) {
521 if (dev->active_target->idx != target_idx) {
527 if (dev->ops->check_presence)
528 del_timer_sync(&dev->check_pres_timer);
530 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb,
533 if (!rc && dev->ops->check_presence && !dev->shutting_down)
534 mod_timer(&dev->check_pres_timer, jiffies +
535 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
536 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) {
537 rc = dev->ops->tm_send(dev, skb);
546 device_unlock(&dev->dev);
550 struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx)
552 struct nfc_se *se, *n;
554 list_for_each_entry_safe(se, n, &dev->secure_elements, list)
555 if (se->idx == se_idx)
560 EXPORT_SYMBOL(nfc_find_se);
562 int nfc_enable_se(struct nfc_dev *dev, u32 se_idx)
568 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
570 device_lock(&dev->dev);
572 if (!device_is_registered(&dev->dev)) {
587 if (!dev->ops->enable_se || !dev->ops->disable_se) {
592 se = nfc_find_se(dev, se_idx);
598 if (se->state == NFC_SE_ENABLED) {
603 rc = dev->ops->enable_se(dev, se_idx);
605 se->state = NFC_SE_ENABLED;
608 device_unlock(&dev->dev);
612 int nfc_disable_se(struct nfc_dev *dev, u32 se_idx)
618 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
620 device_lock(&dev->dev);
622 if (!device_is_registered(&dev->dev)) {
632 if (!dev->ops->enable_se || !dev->ops->disable_se) {
637 se = nfc_find_se(dev, se_idx);
643 if (se->state == NFC_SE_DISABLED) {
648 rc = dev->ops->disable_se(dev, se_idx);
650 se->state = NFC_SE_DISABLED;
653 device_unlock(&dev->dev);
657 int nfc_set_remote_general_bytes(struct nfc_dev *dev, u8 *gb, u8 gb_len)
659 pr_debug("dev_name=%s gb_len=%d\n", dev_name(&dev->dev), gb_len);
661 if (gb_len > NFC_MAX_GT_LEN)
664 return nfc_llcp_set_remote_gb(dev, gb, gb_len);
666 EXPORT_SYMBOL(nfc_set_remote_general_bytes);
668 u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len)
670 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
672 return nfc_llcp_general_bytes(dev, gb_len);
674 EXPORT_SYMBOL(nfc_get_local_general_bytes);
676 int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb)
678 /* Only LLCP target mode for now */
679 if (dev->dep_link_up == false) {
684 return nfc_llcp_data_received(dev, skb);
686 EXPORT_SYMBOL(nfc_tm_data_received);
688 int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
689 u8 *gb, size_t gb_len)
693 device_lock(&dev->dev);
695 dev->polling = false;
698 rc = nfc_set_remote_general_bytes(dev, gb, gb_len);
703 dev->rf_mode = NFC_RF_TARGET;
705 if (protocol == NFC_PROTO_NFC_DEP_MASK)
706 nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);
708 rc = nfc_genl_tm_activated(dev, protocol);
711 device_unlock(&dev->dev);
715 EXPORT_SYMBOL(nfc_tm_activated);
717 int nfc_tm_deactivated(struct nfc_dev *dev)
719 dev->dep_link_up = false;
720 dev->rf_mode = NFC_RF_NONE;
722 return nfc_genl_tm_deactivated(dev);
724 EXPORT_SYMBOL(nfc_tm_deactivated);
727 * nfc_alloc_send_skb - allocate a skb for data exchange responses
729 * @size: size to allocate
732 struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
733 unsigned int flags, unsigned int size,
737 unsigned int total_size;
740 dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
742 skb = sock_alloc_send_skb(sk, total_size, flags & MSG_DONTWAIT, err);
744 skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
750 * nfc_alloc_recv_skb - allocate a skb for data exchange responses
752 * @size: size to allocate
755 struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp)
758 unsigned int total_size;
760 total_size = size + 1;
761 skb = alloc_skb(total_size, gfp);
768 EXPORT_SYMBOL(nfc_alloc_recv_skb);
771 * nfc_targets_found - inform that targets were found
773 * @dev: The nfc device that found the targets
774 * @targets: array of nfc targets found
775 * @ntargets: targets array size
777 * The device driver must call this function when one or many nfc targets
778 * are found. After calling this function, the device driver must stop
779 * polling for targets.
780 * NOTE: This function can be called with targets=NULL and n_targets=0 to
781 * notify a driver error, meaning that the polling operation cannot complete.
782 * IMPORTANT: this function must not be called from an atomic context.
783 * In addition, it must also not be called from a context that would prevent
784 * the NFC Core to call other nfc ops entry point concurrently.
786 int nfc_targets_found(struct nfc_dev *dev,
787 struct nfc_target *targets, int n_targets)
791 pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
793 for (i = 0; i < n_targets; i++)
794 targets[i].idx = dev->target_next_idx++;
796 device_lock(&dev->dev);
798 if (dev->polling == false) {
799 device_unlock(&dev->dev);
803 dev->polling = false;
805 dev->targets_generation++;
811 dev->targets = kmemdup(targets,
812 n_targets * sizeof(struct nfc_target),
817 device_unlock(&dev->dev);
822 dev->n_targets = n_targets;
823 device_unlock(&dev->dev);
825 nfc_genl_targets_found(dev);
829 EXPORT_SYMBOL(nfc_targets_found);
832 * nfc_target_lost - inform that an activated target went out of field
834 * @dev: The nfc device that had the activated target in field
835 * @target_idx: the nfc index of the target
837 * The device driver must call this function when the activated target
838 * goes out of the field.
839 * IMPORTANT: this function must not be called from an atomic context.
840 * In addition, it must also not be called from a context that would prevent
841 * the NFC Core to call other nfc ops entry point concurrently.
843 int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
845 struct nfc_target *tg;
848 pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
850 device_lock(&dev->dev);
852 for (i = 0; i < dev->n_targets; i++) {
853 tg = &dev->targets[i];
854 if (tg->idx == target_idx)
858 if (i == dev->n_targets) {
859 device_unlock(&dev->dev);
863 dev->targets_generation++;
865 dev->active_target = NULL;
867 if (dev->n_targets) {
868 memcpy(&dev->targets[i], &dev->targets[i + 1],
869 (dev->n_targets - i) * sizeof(struct nfc_target));
875 device_unlock(&dev->dev);
877 nfc_genl_target_lost(dev, target_idx);
881 EXPORT_SYMBOL(nfc_target_lost);
883 inline void nfc_driver_failure(struct nfc_dev *dev, int err)
885 nfc_targets_found(dev, NULL, 0);
887 EXPORT_SYMBOL(nfc_driver_failure);
889 int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type)
894 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
896 se = nfc_find_se(dev, se_idx);
900 se = kzalloc(sizeof(struct nfc_se), GFP_KERNEL);
906 se->state = NFC_SE_DISABLED;
907 INIT_LIST_HEAD(&se->list);
909 list_add(&se->list, &dev->secure_elements);
911 rc = nfc_genl_se_added(dev, se_idx, type);
921 EXPORT_SYMBOL(nfc_add_se);
923 int nfc_remove_se(struct nfc_dev *dev, u32 se_idx)
925 struct nfc_se *se, *n;
928 pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
930 list_for_each_entry_safe(se, n, &dev->secure_elements, list)
931 if (se->idx == se_idx) {
932 rc = nfc_genl_se_removed(dev, se_idx);
944 EXPORT_SYMBOL(nfc_remove_se);
946 static void nfc_release(struct device *d)
948 struct nfc_dev *dev = to_nfc_dev(d);
949 struct nfc_se *se, *n;
951 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
953 nfc_genl_data_exit(&dev->genl_data);
956 list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
957 nfc_genl_se_removed(dev, se->idx);
965 static void nfc_check_pres_work(struct work_struct *work)
967 struct nfc_dev *dev = container_of(work, struct nfc_dev,
971 device_lock(&dev->dev);
973 if (dev->active_target && timer_pending(&dev->check_pres_timer) == 0) {
974 rc = dev->ops->check_presence(dev, dev->active_target);
975 if (rc == -EOPNOTSUPP)
978 u32 active_target_idx = dev->active_target->idx;
979 device_unlock(&dev->dev);
980 nfc_target_lost(dev, active_target_idx);
984 if (!dev->shutting_down)
985 mod_timer(&dev->check_pres_timer, jiffies +
986 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
990 device_unlock(&dev->dev);
993 static void nfc_check_pres_timeout(unsigned long data)
995 struct nfc_dev *dev = (struct nfc_dev *)data;
997 schedule_work(&dev->check_pres_work);
1000 struct class nfc_class = {
1002 .dev_release = nfc_release,
1004 EXPORT_SYMBOL(nfc_class);
1006 static int match_idx(struct device *d, const void *data)
1008 struct nfc_dev *dev = to_nfc_dev(d);
1009 const unsigned int *idx = data;
1011 return dev->idx == *idx;
1014 struct nfc_dev *nfc_get_device(unsigned int idx)
1018 d = class_find_device(&nfc_class, NULL, &idx, match_idx);
1022 return to_nfc_dev(d);
1026 * nfc_allocate_device - allocate a new nfc device
1028 * @ops: device operations
1029 * @supported_protocols: NFC protocols supported by the device
1031 struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
1032 u32 supported_protocols,
1033 int tx_headroom, int tx_tailroom)
1035 struct nfc_dev *dev;
1037 if (!ops->start_poll || !ops->stop_poll || !ops->activate_target ||
1038 !ops->deactivate_target || !ops->im_transceive)
1041 if (!supported_protocols)
1044 dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
1049 dev->supported_protocols = supported_protocols;
1050 dev->tx_headroom = tx_headroom;
1051 dev->tx_tailroom = tx_tailroom;
1052 INIT_LIST_HEAD(&dev->secure_elements);
1054 nfc_genl_data_init(&dev->genl_data);
1056 dev->rf_mode = NFC_RF_NONE;
1058 /* first generation must not be 0 */
1059 dev->targets_generation = 1;
1061 if (ops->check_presence) {
1062 init_timer(&dev->check_pres_timer);
1063 dev->check_pres_timer.data = (unsigned long)dev;
1064 dev->check_pres_timer.function = nfc_check_pres_timeout;
1066 INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
1071 EXPORT_SYMBOL(nfc_allocate_device);
1074 * nfc_register_device - register a nfc device in the nfc subsystem
1076 * @dev: The nfc device to register
1078 int nfc_register_device(struct nfc_dev *dev)
1082 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
1084 dev->idx = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL);
1088 dev->dev.class = &nfc_class;
1089 dev_set_name(&dev->dev, "nfc%d", dev->idx);
1090 device_initialize(&dev->dev);
1092 mutex_lock(&nfc_devlist_mutex);
1093 nfc_devlist_generation++;
1094 rc = device_add(&dev->dev);
1095 mutex_unlock(&nfc_devlist_mutex);
1100 rc = nfc_llcp_register_device(dev);
1102 pr_err("Could not register llcp device\n");
1104 rc = nfc_genl_device_added(dev);
1106 pr_debug("The userspace won't be notified that the device %s was added\n",
1107 dev_name(&dev->dev));
1109 dev->rfkill = rfkill_alloc(dev_name(&dev->dev), &dev->dev,
1110 RFKILL_TYPE_NFC, &nfc_rfkill_ops, dev);
1112 if (rfkill_register(dev->rfkill) < 0) {
1113 rfkill_destroy(dev->rfkill);
1120 EXPORT_SYMBOL(nfc_register_device);
1123 * nfc_unregister_device - unregister a nfc device in the nfc subsystem
1125 * @dev: The nfc device to unregister
1127 void nfc_unregister_device(struct nfc_dev *dev)
1131 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
1136 rfkill_unregister(dev->rfkill);
1137 rfkill_destroy(dev->rfkill);
1140 if (dev->ops->check_presence) {
1141 device_lock(&dev->dev);
1142 dev->shutting_down = true;
1143 device_unlock(&dev->dev);
1144 del_timer_sync(&dev->check_pres_timer);
1145 cancel_work_sync(&dev->check_pres_work);
1148 rc = nfc_genl_device_removed(dev);
1150 pr_debug("The userspace won't be notified that the device %s "
1151 "was removed\n", dev_name(&dev->dev));
1153 nfc_llcp_unregister_device(dev);
1155 mutex_lock(&nfc_devlist_mutex);
1156 nfc_devlist_generation++;
1157 device_del(&dev->dev);
1158 mutex_unlock(&nfc_devlist_mutex);
1160 ida_simple_remove(&nfc_index_ida, id);
1162 EXPORT_SYMBOL(nfc_unregister_device);
1164 static int __init nfc_init(void)
1168 pr_info("NFC Core ver %s\n", VERSION);
1170 rc = class_register(&nfc_class);
1174 rc = nfc_genl_init();
1178 /* the first generation must not be 0 */
1179 nfc_devlist_generation = 1;
1181 rc = rawsock_init();
1185 rc = nfc_llcp_init();
1202 class_unregister(&nfc_class);
1206 static void __exit nfc_exit(void)
1212 class_unregister(&nfc_class);
1215 subsys_initcall(nfc_init);
1216 module_exit(nfc_exit);
1218 MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>");
1219 MODULE_DESCRIPTION("NFC Core ver " VERSION);
1220 MODULE_VERSION(VERSION);
1221 MODULE_LICENSE("GPL");
1222 MODULE_ALIAS_NETPROTO(PF_NFC);
1223 MODULE_ALIAS_GENL_FAMILY(NFC_GENL_NAME);