drivers/nfc/st-nci/i2c.c
Source file repositories/reference/linux-study-clean/drivers/nfc/st-nci/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nfc/st-nci/i2c.c- Extension
.c- Size
- 6840 bytes
- Lines
- 294
- 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/i2c.hlinux/gpio/consumer.hlinux/acpi.hlinux/interrupt.hlinux/delay.hlinux/nfc.hlinux/of.hst-nci.h
Detected Declarations
struct st_nci_i2c_phyfunction st_nci_i2c_enablefunction st_nci_i2c_disablefunction st_nci_i2c_writefunction st_nci_i2c_readfunction st_nci_irq_thread_fnfunction st_nci_i2c_probefunction st_nci_i2c_remove
Annotated Snippet
struct st_nci_i2c_phy {
struct i2c_client *i2c_dev;
struct llt_ndlc *ndlc;
bool irq_active;
struct gpio_desc *gpiod_reset;
struct st_nci_se_status se_status;
};
static int st_nci_i2c_enable(void *phy_id)
{
struct st_nci_i2c_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->i2c_dev->irq);
phy->irq_active = true;
}
return 0;
}
static void st_nci_i2c_disable(void *phy_id)
{
struct st_nci_i2c_phy *phy = phy_id;
disable_irq_nosync(phy->i2c_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_i2c_write(void *phy_id, struct sk_buff *skb)
{
int r;
struct st_nci_i2c_phy *phy = phy_id;
struct i2c_client *client = phy->i2c_dev;
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
r = i2c_master_send(client, skb->data, skb->len);
if (r < 0) { /* Retry, chip was in standby */
usleep_range(1000, 4000);
r = i2c_master_send(client, skb->data, skb->len);
}
if (r >= 0) {
if (r != skb->len)
r = -EREMOTEIO;
else
r = 0;
}
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_i2c_read(struct st_nci_i2c_phy *phy,
struct sk_buff **skb)
{
int r;
u8 len;
u8 buf[ST_NCI_I2C_MAX_SIZE];
struct i2c_client *client = phy->i2c_dev;
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE);
if (r < 0) { /* Retry, chip was in standby */
usleep_range(1000, 4000);
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE);
}
if (r != ST_NCI_I2C_MIN_SIZE)
return -EREMOTEIO;
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.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_i2c_phy`, `function st_nci_i2c_enable`, `function st_nci_i2c_disable`, `function st_nci_i2c_write`, `function st_nci_i2c_read`, `function st_nci_irq_thread_fn`, `function st_nci_i2c_probe`, `function st_nci_i2c_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.