2 * Copyright (C) 2013 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 #define pr_fmt(fmt) "nci_spi: %s: " fmt, __func__
21 #include <linux/export.h>
22 #include <linux/spi/spi.h>
23 #include <linux/nfc.h>
24 #include <net/nfc/nci_core.h>
26 #define NCI_SPI_HDR_LEN 4
27 #define NCI_SPI_CRC_LEN 2
29 static int nci_spi_open(struct nci_dev *nci_dev)
31 struct nci_spi_dev *ndev = nci_get_drvdata(nci_dev);
33 return ndev->ops->open(ndev);
36 static int nci_spi_close(struct nci_dev *nci_dev)
38 struct nci_spi_dev *ndev = nci_get_drvdata(nci_dev);
40 return ndev->ops->close(ndev);
43 static int nci_spi_send(struct nci_dev *nci_dev, struct sk_buff *skb)
48 static struct nci_ops nci_spi_ops = {
50 .close = nci_spi_close,
54 /* ---- Interface to NCI SPI drivers ---- */
57 * nci_spi_allocate_device - allocate a new nci spi device
60 * @ops: device operations
61 * @supported_protocols: NFC protocols supported by the device
62 * @supported_se: NFC Secure Elements supported by the device
63 * @acknowledge_mode: Acknowledge mode used by the device
64 * @delay: delay between transactions in us
66 struct nci_spi_dev *nci_spi_allocate_device(struct spi_device *spi,
67 struct nci_spi_ops *ops,
68 u32 supported_protocols,
73 struct nci_spi_dev *ndev;
76 if (!ops->open || !ops->close || !ops->assert_int || !ops->deassert_int)
79 if (!supported_protocols)
82 ndev = devm_kzalloc(&spi->dev, sizeof(struct nci_dev), GFP_KERNEL);
87 ndev->acknowledge_mode = acknowledge_mode;
88 ndev->xfer_udelay = delay;
90 if (acknowledge_mode == NCI_SPI_CRC_ENABLED)
91 tailroom += NCI_SPI_CRC_LEN;
93 ndev->nci_dev = nci_allocate_device(&nci_spi_ops, supported_protocols,
94 supported_se, NCI_SPI_HDR_LEN,
99 nci_set_drvdata(ndev->nci_dev, ndev);
103 EXPORT_SYMBOL_GPL(nci_spi_allocate_device);
106 * nci_spi_free_device - deallocate nci spi device
108 * @ndev: The nci spi device to deallocate
110 void nci_spi_free_device(struct nci_spi_dev *ndev)
112 nci_free_device(ndev->nci_dev);
114 EXPORT_SYMBOL_GPL(nci_spi_free_device);
117 * nci_spi_register_device - register a nci spi device in the nfc subsystem
119 * @pdev: The nci spi device to register
121 int nci_spi_register_device(struct nci_spi_dev *ndev)
123 return nci_register_device(ndev->nci_dev);
125 EXPORT_SYMBOL_GPL(nci_spi_register_device);
128 * nci_spi_unregister_device - unregister a nci spi device in the nfc subsystem
130 * @dev: The nci spi device to unregister
132 void nci_spi_unregister_device(struct nci_spi_dev *ndev)
134 nci_unregister_device(ndev->nci_dev);
136 EXPORT_SYMBOL_GPL(nci_spi_unregister_device);