drivers/nfc/st-nci/spi.c
Source file repositories/reference/linux-study-clean/drivers/nfc/st-nci/spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nfc/st-nci/spi.c- Extension
.c- Size
- 7058 bytes
- Lines
- 306
- Domain
- Driver Families
- Bucket
- drivers/nfc
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/spi/spi.hlinux/gpio/consumer.hlinux/acpi.hlinux/interrupt.hlinux/delay.hlinux/nfc.hlinux/of.hnet/nfc/nci.hst-nci.h
Detected Declarations
struct st_nci_spi_phyfunction st_nci_spi_enablefunction st_nci_spi_disablefunction st_nci_spi_writefunction st_nci_spi_readfunction st_nci_irq_thread_fnfunction st_nci_spi_probefunction st_nci_spi_remove
Annotated Snippet
struct st_nci_spi_phy {
struct spi_device *spi_dev;
struct llt_ndlc *ndlc;
bool irq_active;
struct gpio_desc *gpiod_reset;
struct st_nci_se_status se_status;
};
static int st_nci_spi_enable(void *phy_id)
{
struct st_nci_spi_phy *phy = phy_id;
gpiod_set_value(phy->gpiod_reset, 0);
usleep_range(10000, 15000);
gpiod_set_value(phy->gpiod_reset, 1);
usleep_range(80000, 85000);
if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->spi_dev->irq);
phy->irq_active = true;
}
return 0;
}
static void st_nci_spi_disable(void *phy_id)
{
struct st_nci_spi_phy *phy = phy_id;
disable_irq_nosync(phy->spi_dev->irq);
phy->irq_active = false;
}
/*
* Writing a frame must not return the number of written bytes.
* It must return either zero for success, or <0 for error.
* In addition, it must not alter the skb
*/
static int st_nci_spi_write(void *phy_id, struct sk_buff *skb)
{
int r;
struct st_nci_spi_phy *phy = phy_id;
struct spi_device *dev = phy->spi_dev;
struct sk_buff *skb_rx;
u8 buf[ST_NCI_SPI_MAX_SIZE + NCI_DATA_HDR_SIZE +
ST_NCI_FRAME_HEADROOM + ST_NCI_FRAME_TAILROOM];
struct spi_transfer spi_xfer = {
.tx_buf = skb->data,
.rx_buf = buf,
.len = skb->len,
};
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
r = spi_sync_transfer(dev, &spi_xfer, 1);
/*
* We may have received some valuable data on miso line.
* Send them back in the ndlc state machine.
*/
if (!r) {
skb_rx = alloc_skb(skb->len, GFP_KERNEL);
if (!skb_rx)
return -ENOMEM;
skb_put(skb_rx, skb->len);
memcpy(skb_rx->data, buf, skb->len);
ndlc_recv(phy->ndlc, skb_rx);
}
return r;
}
/*
* Reads an ndlc frame and returns it in a newly allocated sk_buff.
* returns:
* 0 : if received frame is complete
* -EREMOTEIO : i2c read error (fatal)
* -EBADMSG : frame was incorrect and discarded
* -ENOMEM : cannot allocate skb, frame dropped
*/
static int st_nci_spi_read(struct st_nci_spi_phy *phy,
struct sk_buff **skb)
{
int r;
u8 len;
u8 buf[ST_NCI_SPI_MAX_SIZE];
Annotation
- Immediate include surface: `linux/module.h`, `linux/spi/spi.h`, `linux/gpio/consumer.h`, `linux/acpi.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/nfc.h`, `linux/of.h`.
- Detected declarations: `struct st_nci_spi_phy`, `function st_nci_spi_enable`, `function st_nci_spi_disable`, `function st_nci_spi_write`, `function st_nci_spi_read`, `function st_nci_irq_thread_fn`, `function st_nci_spi_probe`, `function st_nci_spi_remove`.
- Atlas domain: Driver Families / drivers/nfc.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.