ARM: pmu: add support for interrupt-affinity property
[linux/fpc-iii.git] / drivers / nfc / st21nfcb / st21nfcb.c
blobca9871ab3fb3c7040188d6ee8c6404bb26d876e5
1 /*
2 * NCI based Driver for STMicroelectronics NFC Chip
4 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include <linux/module.h>
20 #include <linux/nfc.h>
21 #include <net/nfc/nci.h>
22 #include <net/nfc/nci_core.h>
24 #include "st21nfcb.h"
25 #include "st21nfcb_se.h"
27 #define DRIVER_DESC "NCI NFC driver for ST21NFCB"
29 #define ST21NFCB_NCI1_X_PROPRIETARY_ISO15693 0x83
31 static int st21nfcb_nci_open(struct nci_dev *ndev)
33 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
34 int r;
36 if (test_and_set_bit(ST21NFCB_NCI_RUNNING, &info->flags))
37 return 0;
39 r = ndlc_open(info->ndlc);
40 if (r)
41 clear_bit(ST21NFCB_NCI_RUNNING, &info->flags);
43 return r;
46 static int st21nfcb_nci_close(struct nci_dev *ndev)
48 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
50 if (!test_and_clear_bit(ST21NFCB_NCI_RUNNING, &info->flags))
51 return 0;
53 ndlc_close(info->ndlc);
55 return 0;
58 static int st21nfcb_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
60 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
62 skb->dev = (void *)ndev;
64 if (!test_bit(ST21NFCB_NCI_RUNNING, &info->flags))
65 return -EBUSY;
67 return ndlc_send(info->ndlc, skb);
70 static __u32 st21nfcb_nci_get_rfprotocol(struct nci_dev *ndev,
71 __u8 rf_protocol)
73 return rf_protocol == ST21NFCB_NCI1_X_PROPRIETARY_ISO15693 ?
74 NFC_PROTO_ISO15693_MASK : 0;
77 static struct nci_ops st21nfcb_nci_ops = {
78 .open = st21nfcb_nci_open,
79 .close = st21nfcb_nci_close,
80 .send = st21nfcb_nci_send,
81 .get_rfprotocol = st21nfcb_nci_get_rfprotocol,
82 .discover_se = st21nfcb_nci_discover_se,
83 .enable_se = st21nfcb_nci_enable_se,
84 .disable_se = st21nfcb_nci_disable_se,
85 .se_io = st21nfcb_nci_se_io,
86 .hci_load_session = st21nfcb_hci_load_session,
87 .hci_event_received = st21nfcb_hci_event_received,
88 .hci_cmd_received = st21nfcb_hci_cmd_received,
91 int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
92 int phy_tailroom)
94 struct st21nfcb_nci_info *info;
95 int r;
96 u32 protocols;
98 info = devm_kzalloc(ndlc->dev,
99 sizeof(struct st21nfcb_nci_info), GFP_KERNEL);
100 if (!info)
101 return -ENOMEM;
103 protocols = NFC_PROTO_JEWEL_MASK
104 | NFC_PROTO_MIFARE_MASK
105 | NFC_PROTO_FELICA_MASK
106 | NFC_PROTO_ISO14443_MASK
107 | NFC_PROTO_ISO14443_B_MASK
108 | NFC_PROTO_ISO15693_MASK
109 | NFC_PROTO_NFC_DEP_MASK;
111 ndlc->ndev = nci_allocate_device(&st21nfcb_nci_ops, protocols,
112 phy_headroom, phy_tailroom);
113 if (!ndlc->ndev) {
114 pr_err("Cannot allocate nfc ndev\n");
115 return -ENOMEM;
117 info->ndlc = ndlc;
119 nci_set_drvdata(ndlc->ndev, info);
121 r = nci_register_device(ndlc->ndev);
122 if (r) {
123 pr_err("Cannot register nfc device to nci core\n");
124 nci_free_device(ndlc->ndev);
125 return r;
128 return st21nfcb_se_init(ndlc->ndev);
130 EXPORT_SYMBOL_GPL(st21nfcb_nci_probe);
132 void st21nfcb_nci_remove(struct nci_dev *ndev)
134 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
136 nci_unregister_device(ndev);
137 nci_free_device(ndev);
138 kfree(info);
140 EXPORT_SYMBOL_GPL(st21nfcb_nci_remove);
142 MODULE_LICENSE("GPL");
143 MODULE_DESCRIPTION(DRIVER_DESC);