drivers/nfc/nfcmrvl/i2c.c
Source file repositories/reference/linux-study-clean/drivers/nfc/nfcmrvl/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nfc/nfcmrvl/i2c.c- Extension
.c- Size
- 6248 bytes
- Lines
- 275
- 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/interrupt.hlinux/i2c.hlinux/nfc.hlinux/delay.hlinux/of_irq.hnet/nfc/nci.hnet/nfc/nci_core.hnfcmrvl.h
Detected Declarations
struct nfcmrvl_i2c_drv_datafunction nfcmrvl_i2c_readfunction nfcmrvl_i2c_int_irq_thread_fnfunction nfcmrvl_i2c_nci_openfunction nfcmrvl_i2c_nci_closefunction nfcmrvl_i2c_nci_sendfunction nfcmrvl_i2c_nci_update_configfunction nfcmrvl_i2c_parse_dtfunction nfcmrvl_i2c_probefunction nfcmrvl_i2c_remove
Annotated Snippet
struct nfcmrvl_i2c_drv_data {
unsigned long flags;
struct device *dev;
struct i2c_client *i2c;
struct nfcmrvl_private *priv;
};
static int nfcmrvl_i2c_read(struct nfcmrvl_i2c_drv_data *drv_data,
struct sk_buff **skb)
{
int ret;
struct nci_ctrl_hdr nci_hdr;
/* Read NCI header to know the payload size */
ret = i2c_master_recv(drv_data->i2c, (u8 *)&nci_hdr, NCI_CTRL_HDR_SIZE);
if (ret != NCI_CTRL_HDR_SIZE) {
nfc_err(&drv_data->i2c->dev, "cannot read NCI header\n");
return -EBADMSG;
}
*skb = nci_skb_alloc(drv_data->priv->ndev,
nci_hdr.plen + NCI_CTRL_HDR_SIZE, GFP_KERNEL);
if (!*skb)
return -ENOMEM;
/* Copy NCI header into the SKB */
skb_put_data(*skb, &nci_hdr, NCI_CTRL_HDR_SIZE);
if (nci_hdr.plen) {
/* Read the NCI payload */
ret = i2c_master_recv(drv_data->i2c,
skb_put(*skb, nci_hdr.plen),
nci_hdr.plen);
if (ret != nci_hdr.plen) {
nfc_err(&drv_data->i2c->dev,
"Invalid frame payload length: %u (expected %u)\n",
ret, nci_hdr.plen);
kfree_skb(*skb);
return -EBADMSG;
}
}
return 0;
}
static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr)
{
struct nfcmrvl_i2c_drv_data *drv_data = drv_data_ptr;
struct sk_buff *skb = NULL;
int ret;
if (!drv_data->priv)
return IRQ_HANDLED;
if (test_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags))
return IRQ_HANDLED;
ret = nfcmrvl_i2c_read(drv_data, &skb);
switch (ret) {
case -EREMOTEIO:
set_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags);
break;
case -ENOMEM:
case -EBADMSG:
nfc_err(&drv_data->i2c->dev, "read failed %d\n", ret);
break;
default:
if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n");
break;
}
return IRQ_HANDLED;
}
static int nfcmrvl_i2c_nci_open(struct nfcmrvl_private *priv)
{
struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data;
if (!drv_data)
return -ENODEV;
return 0;
}
static int nfcmrvl_i2c_nci_close(struct nfcmrvl_private *priv)
{
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/interrupt.h`, `linux/i2c.h`, `linux/nfc.h`, `linux/delay.h`, `linux/of_irq.h`, `net/nfc/nci.h`, `net/nfc/nci_core.h`.
- Detected declarations: `struct nfcmrvl_i2c_drv_data`, `function nfcmrvl_i2c_read`, `function nfcmrvl_i2c_int_irq_thread_fn`, `function nfcmrvl_i2c_nci_open`, `function nfcmrvl_i2c_nci_close`, `function nfcmrvl_i2c_nci_send`, `function nfcmrvl_i2c_nci_update_config`, `function nfcmrvl_i2c_parse_dt`, `function nfcmrvl_i2c_probe`, `function nfcmrvl_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.