drivers/nfc/nxp-nci/i2c.c
Source file repositories/reference/linux-study-clean/drivers/nfc/nxp-nci/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nfc/nxp-nci/i2c.c- Extension
.c- Size
- 9156 bytes
- Lines
- 390
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/acpi.hlinux/delay.hlinux/i2c.hlinux/interrupt.hlinux/irq.hlinux/module.hlinux/nfc.hlinux/gpio/consumer.hlinux/unaligned.hnet/nfc/nfc.hnxp-nci.h
Detected Declarations
struct nxp_nci_i2c_phyfunction nxp_nci_i2c_set_modefunction nxp_nci_i2c_writefunction nxp_nci_i2c_fw_readfunction nxp_nci_i2c_nci_readfunction nxp_nci_i2c_irq_thread_fnfunction nxp_nci_i2c_probefunction nxp_nci_i2c_remove
Annotated Snippet
struct nxp_nci_i2c_phy {
struct i2c_client *i2c_dev;
struct nci_dev *ndev;
struct gpio_desc *gpiod_en;
struct gpio_desc *gpiod_fw;
int hard_fault; /*
* < 0 if hardware error occurred (e.g. i2c err)
* and prevents normal operation.
*/
};
static int nxp_nci_i2c_set_mode(void *phy_id,
enum nxp_nci_mode mode)
{
struct nxp_nci_i2c_phy *phy = (struct nxp_nci_i2c_phy *) phy_id;
gpiod_set_value_cansleep(phy->gpiod_fw, (mode == NXP_NCI_MODE_FW) ? 1 : 0);
gpiod_set_value_cansleep(phy->gpiod_en, (mode != NXP_NCI_MODE_COLD) ? 1 : 0);
usleep_range(10000, 15000);
if (mode == NXP_NCI_MODE_COLD)
phy->hard_fault = 0;
return 0;
}
static int nxp_nci_i2c_write(void *phy_id, struct sk_buff *skb)
{
int r;
struct nxp_nci_i2c_phy *phy = phy_id;
struct i2c_client *client = phy->i2c_dev;
if (phy->hard_fault != 0)
return phy->hard_fault;
r = i2c_master_send(client, skb->data, skb->len);
if (r < 0) {
/* Retry, chip was in standby */
msleep(110);
r = i2c_master_send(client, skb->data, skb->len);
}
if (r < 0) {
nfc_err(&client->dev, "Error %d on I2C send\n", r);
} else if (r != skb->len) {
nfc_err(&client->dev,
"Invalid length sent: %u (expected %u)\n",
r, skb->len);
r = -EREMOTEIO;
} else {
/* Success but return 0 and not number of bytes */
r = 0;
}
return r;
}
static const struct nxp_nci_phy_ops i2c_phy_ops = {
.set_mode = nxp_nci_i2c_set_mode,
.write = nxp_nci_i2c_write,
};
static int nxp_nci_i2c_fw_read(struct nxp_nci_i2c_phy *phy,
struct sk_buff **skb)
{
struct i2c_client *client = phy->i2c_dev;
size_t frame_len;
__be16 header;
int r;
r = i2c_master_recv(client, (u8 *) &header, NXP_NCI_FW_HDR_LEN);
if (r < 0) {
goto fw_read_exit;
} else if (r != NXP_NCI_FW_HDR_LEN) {
nfc_err(&client->dev, "Incorrect header length: %u\n", r);
r = -EBADMSG;
goto fw_read_exit;
}
frame_len = (be16_to_cpu(header) & NXP_NCI_FW_FRAME_LEN_MASK) +
NXP_NCI_FW_CRC_LEN;
*skb = alloc_skb(NXP_NCI_FW_HDR_LEN + frame_len, GFP_KERNEL);
if (*skb == NULL) {
r = -ENOMEM;
goto fw_read_exit;
}
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/delay.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/module.h`, `linux/nfc.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct nxp_nci_i2c_phy`, `function nxp_nci_i2c_set_mode`, `function nxp_nci_i2c_write`, `function nxp_nci_i2c_fw_read`, `function nxp_nci_i2c_nci_read`, `function nxp_nci_i2c_irq_thread_fn`, `function nxp_nci_i2c_probe`, `function nxp_nci_i2c_remove`.
- Atlas domain: Driver Families / drivers/nfc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.