Lines Matching +full:st21nfcb +full:- +full:spi

1 // SPDX-License-Identifier: GPL-2.0-only
3 * SPI Link Layer for ST NCI based Driver
4 * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
10 #include <linux/spi/spi.h>
19 #include "st-nci.h"
48 gpiod_set_value(phy->gpiod_reset, 0); in st_nci_spi_enable()
50 gpiod_set_value(phy->gpiod_reset, 1); in st_nci_spi_enable()
53 if (phy->ndlc->powered == 0 && phy->irq_active == 0) { in st_nci_spi_enable()
54 enable_irq(phy->spi_dev->irq); in st_nci_spi_enable()
55 phy->irq_active = true; in st_nci_spi_enable()
65 disable_irq_nosync(phy->spi_dev->irq); in st_nci_spi_disable()
66 phy->irq_active = false; in st_nci_spi_disable()
78 struct spi_device *dev = phy->spi_dev; in st_nci_spi_write()
83 .tx_buf = skb->data, in st_nci_spi_write()
85 .len = skb->len, in st_nci_spi_write()
88 if (phy->ndlc->hard_fault != 0) in st_nci_spi_write()
89 return phy->ndlc->hard_fault; in st_nci_spi_write()
97 skb_rx = alloc_skb(skb->len, GFP_KERNEL); in st_nci_spi_write()
99 return -ENOMEM; in st_nci_spi_write()
101 skb_put(skb_rx, skb->len); in st_nci_spi_write()
102 memcpy(skb_rx->data, buf, skb->len); in st_nci_spi_write()
103 ndlc_recv(phy->ndlc, skb_rx); in st_nci_spi_write()
113 * -EREMOTEIO : i2c read error (fatal)
114 * -EBADMSG : frame was incorrect and discarded
115 * -ENOMEM : cannot allocate skb, frame dropped
123 struct spi_device *dev = phy->spi_dev; in st_nci_spi_read()
131 return -EREMOTEIO; in st_nci_spi_read()
135 nfc_err(&dev->dev, "invalid frame len\n"); in st_nci_spi_read()
136 phy->ndlc->hard_fault = 1; in st_nci_spi_read()
137 return -EBADMSG; in st_nci_spi_read()
142 return -ENOMEM; in st_nci_spi_read()
146 memcpy((*skb)->data, buf, ST_NCI_SPI_MIN_SIZE); in st_nci_spi_read()
155 return -EREMOTEIO; in st_nci_spi_read()
159 memcpy((*skb)->data + ST_NCI_SPI_MIN_SIZE, buf, len); in st_nci_spi_read()
167 * On ST21NFCB, IRQ goes in idle state when read starts.
175 if (!phy || !phy->ndlc || irq != phy->spi_dev->irq) { in st_nci_irq_thread_fn()
180 if (phy->ndlc->hard_fault) in st_nci_irq_thread_fn()
183 if (!phy->ndlc->powered) { in st_nci_irq_thread_fn()
189 if (r == -EREMOTEIO || r == -ENOMEM || r == -EBADMSG) in st_nci_irq_thread_fn()
192 ndlc_recv(phy->ndlc, skb); in st_nci_irq_thread_fn()
206 { "reset-gpios", &reset_gpios, 1 },
215 /* Check SPI platform functionnalities */ in st_nci_spi_probe()
219 return -ENODEV; in st_nci_spi_probe()
222 phy = devm_kzalloc(&dev->dev, sizeof(struct st_nci_spi_phy), in st_nci_spi_probe()
225 return -ENOMEM; in st_nci_spi_probe()
227 phy->spi_dev = dev; in st_nci_spi_probe()
231 r = devm_acpi_dev_add_driver_gpios(&dev->dev, acpi_st_nci_gpios); in st_nci_spi_probe()
233 dev_dbg(&dev->dev, "Unable to add GPIO mapping table\n"); in st_nci_spi_probe()
236 phy->gpiod_reset = devm_gpiod_get(&dev->dev, "reset", GPIOD_OUT_HIGH); in st_nci_spi_probe()
237 if (IS_ERR(phy->gpiod_reset)) { in st_nci_spi_probe()
238 nfc_err(&dev->dev, "Unable to get RESET GPIO\n"); in st_nci_spi_probe()
239 return PTR_ERR(phy->gpiod_reset); in st_nci_spi_probe()
242 phy->se_status.is_ese_present = in st_nci_spi_probe()
243 device_property_read_bool(&dev->dev, "ese-present"); in st_nci_spi_probe()
244 phy->se_status.is_uicc_present = in st_nci_spi_probe()
245 device_property_read_bool(&dev->dev, "uicc-present"); in st_nci_spi_probe()
247 r = ndlc_probe(phy, &spi_phy_ops, &dev->dev, in st_nci_spi_probe()
249 &phy->ndlc, &phy->se_status); in st_nci_spi_probe()
251 nfc_err(&dev->dev, "Unable to register ndlc layer\n"); in st_nci_spi_probe()
255 phy->irq_active = true; in st_nci_spi_probe()
256 r = devm_request_threaded_irq(&dev->dev, dev->irq, NULL, in st_nci_spi_probe()
261 nfc_err(&dev->dev, "Unable to register IRQ handler\n"); in st_nci_spi_probe()
270 ndlc_remove(phy->ndlc); in st_nci_spi_remove()
275 {"st21nfcb-spi", 0},
278 MODULE_DEVICE_TABLE(spi, st_nci_spi_id_table);
287 { .compatible = "st,st21nfcb-spi", },