2 * NCI based driver for Samsung S3FWRN5 NFC chip
4 * Copyright (C) 2015 Samsung Electrnoics
5 * Robert Baldyga <r.baldyga@samsung.com>
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 or later, as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <linux/module.h>
21 #include <net/nfc/nci_core.h>
27 #define S3FWRN5_NFC_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
28 NFC_PROTO_MIFARE_MASK | \
29 NFC_PROTO_FELICA_MASK | \
30 NFC_PROTO_ISO14443_MASK | \
31 NFC_PROTO_ISO14443_B_MASK | \
32 NFC_PROTO_ISO15693_MASK)
34 static int s3fwrn5_firmware_update(struct s3fwrn5_info *info)
39 s3fwrn5_fw_init(&info->fw_info, "/*(DEBLOBBED)*/");
43 s3fwrn5_set_wake(info, false);
44 s3fwrn5_set_mode(info, S3FWRN5_MODE_FW);
46 ret = s3fwrn5_fw_setup(&info->fw_info);
50 need_update = s3fwrn5_fw_check_version(&info->fw_info,
51 info->ndev->manufact_specific_info);
55 dev_info(&info->ndev->nfc_dev->dev, "Detected new firmware version\n");
57 ret = s3fwrn5_fw_download(&info->fw_info);
61 /* Update RF configuration */
63 s3fwrn5_set_mode(info, S3FWRN5_MODE_NCI);
65 s3fwrn5_set_wake(info, true);
66 ret = s3fwrn5_nci_rf_configure(info, "/*(DEBLOBBED)*/");
67 s3fwrn5_set_wake(info, false);
70 s3fwrn5_set_mode(info, S3FWRN5_MODE_COLD);
71 s3fwrn5_fw_cleanup(&info->fw_info);
75 static int s3fwrn5_nci_open(struct nci_dev *ndev)
77 struct s3fwrn5_info *info = nci_get_drvdata(ndev);
79 if (s3fwrn5_get_mode(info) != S3FWRN5_MODE_COLD)
82 s3fwrn5_set_mode(info, S3FWRN5_MODE_NCI);
83 s3fwrn5_set_wake(info, true);
88 static int s3fwrn5_nci_close(struct nci_dev *ndev)
90 struct s3fwrn5_info *info = nci_get_drvdata(ndev);
92 s3fwrn5_set_wake(info, false);
93 s3fwrn5_set_mode(info, S3FWRN5_MODE_COLD);
98 static int s3fwrn5_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
100 struct s3fwrn5_info *info = nci_get_drvdata(ndev);
103 mutex_lock(&info->mutex);
105 if (s3fwrn5_get_mode(info) != S3FWRN5_MODE_NCI) {
106 mutex_unlock(&info->mutex);
110 ret = s3fwrn5_write(info, skb);
113 mutex_unlock(&info->mutex);
118 mutex_unlock(&info->mutex);
122 static int s3fwrn5_nci_post_setup(struct nci_dev *ndev)
124 struct s3fwrn5_info *info = nci_get_drvdata(ndev);
127 ret = s3fwrn5_firmware_update(info);
133 s3fwrn5_set_mode(info, S3FWRN5_MODE_NCI);
134 s3fwrn5_set_wake(info, true);
136 ret = nci_core_reset(info->ndev);
140 ret = nci_core_init(info->ndev);
146 static struct nci_ops s3fwrn5_nci_ops = {
147 .open = s3fwrn5_nci_open,
148 .close = s3fwrn5_nci_close,
149 .send = s3fwrn5_nci_send,
150 .post_setup = s3fwrn5_nci_post_setup,
153 int s3fwrn5_probe(struct nci_dev **ndev, void *phy_id, struct device *pdev,
154 const struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload)
156 struct s3fwrn5_info *info;
159 info = devm_kzalloc(pdev, sizeof(*info), GFP_KERNEL);
163 info->phy_id = phy_id;
165 info->phy_ops = phy_ops;
166 info->max_payload = max_payload;
167 mutex_init(&info->mutex);
169 s3fwrn5_set_mode(info, S3FWRN5_MODE_COLD);
171 s3fwrn5_nci_get_prop_ops(&s3fwrn5_nci_ops.prop_ops,
172 &s3fwrn5_nci_ops.n_prop_ops);
174 info->ndev = nci_allocate_device(&s3fwrn5_nci_ops,
175 S3FWRN5_NFC_PROTOCOLS, 0, 0);
179 nci_set_parent_dev(info->ndev, pdev);
180 nci_set_drvdata(info->ndev, info);
182 ret = nci_register_device(info->ndev);
184 nci_free_device(info->ndev);
188 info->fw_info.ndev = info->ndev;
194 EXPORT_SYMBOL(s3fwrn5_probe);
196 void s3fwrn5_remove(struct nci_dev *ndev)
198 struct s3fwrn5_info *info = nci_get_drvdata(ndev);
200 s3fwrn5_set_mode(info, S3FWRN5_MODE_COLD);
202 nci_unregister_device(ndev);
203 nci_free_device(ndev);
205 EXPORT_SYMBOL(s3fwrn5_remove);
207 int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
208 enum s3fwrn5_mode mode)
211 case S3FWRN5_MODE_NCI:
212 return nci_recv_frame(ndev, skb);
213 case S3FWRN5_MODE_FW:
214 return s3fwrn5_fw_recv_frame(ndev, skb);
220 EXPORT_SYMBOL(s3fwrn5_recv_frame);
222 MODULE_LICENSE("GPL");
223 MODULE_DESCRIPTION("Samsung S3FWRN5 NFC driver");
224 MODULE_AUTHOR("Robert Baldyga <r.baldyga@samsung.com>");