drivers/nfc/s3fwrn5/i2c.c
Source file repositories/reference/linux-study-clean/drivers/nfc/s3fwrn5/i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nfc/s3fwrn5/i2c.c- Extension
.c- Size
- 5281 bytes
- Lines
- 234
- 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/clk.hlinux/i2c.hlinux/gpio/consumer.hlinux/delay.hlinux/module.hnet/nfc/nfc.hphy_common.h
Detected Declarations
struct s3fwrn5_i2c_phyfunction s3fwrn5_i2c_set_modefunction s3fwrn5_i2c_writefunction s3fwrn5_i2c_readfunction s3fwrn5_i2c_irq_thread_fnfunction s3fwrn5_i2c_probefunction s3fwrn5_i2c_remove
Annotated Snippet
struct s3fwrn5_i2c_phy {
struct phy_common common;
struct i2c_client *i2c_dev;
struct clk *clk;
unsigned int irq_skip:1;
};
static void s3fwrn5_i2c_set_mode(void *phy_id, enum s3fwrn5_mode mode)
{
struct s3fwrn5_i2c_phy *phy = phy_id;
mutex_lock(&phy->common.mutex);
if (s3fwrn5_phy_power_ctrl(&phy->common, mode) == false)
goto out;
phy->irq_skip = true;
out:
mutex_unlock(&phy->common.mutex);
}
static int s3fwrn5_i2c_write(void *phy_id, struct sk_buff *skb)
{
struct s3fwrn5_i2c_phy *phy = phy_id;
int ret;
mutex_lock(&phy->common.mutex);
phy->irq_skip = false;
ret = i2c_master_send(phy->i2c_dev, skb->data, skb->len);
if (ret == -EREMOTEIO) {
/* Retry, chip was in standby */
usleep_range(110000, 120000);
ret = i2c_master_send(phy->i2c_dev, skb->data, skb->len);
}
mutex_unlock(&phy->common.mutex);
if (ret < 0)
return ret;
if (ret != skb->len)
return -EREMOTEIO;
return 0;
}
static const struct s3fwrn5_phy_ops i2c_phy_ops = {
.set_wake = s3fwrn5_phy_set_wake,
.set_mode = s3fwrn5_i2c_set_mode,
.get_mode = s3fwrn5_phy_get_mode,
.write = s3fwrn5_i2c_write,
};
static int s3fwrn5_i2c_read(struct s3fwrn5_i2c_phy *phy)
{
struct sk_buff *skb;
size_t hdr_size;
size_t data_len;
char hdr[4];
int ret;
hdr_size = (phy->common.mode == S3FWRN5_MODE_NCI) ?
NCI_CTRL_HDR_SIZE : S3FWRN5_FW_HDR_SIZE;
ret = i2c_master_recv(phy->i2c_dev, hdr, hdr_size);
if (ret < 0)
return ret;
if (ret < hdr_size)
return -EBADMSG;
data_len = (phy->common.mode == S3FWRN5_MODE_NCI) ?
((struct nci_ctrl_hdr *)hdr)->plen :
((struct s3fwrn5_fw_header *)hdr)->len;
skb = alloc_skb(hdr_size + data_len, GFP_KERNEL);
if (!skb)
return -ENOMEM;
skb_put_data(skb, hdr, hdr_size);
if (data_len == 0)
goto out;
ret = i2c_master_recv(phy->i2c_dev, skb_put(skb, data_len), data_len);
if (ret != data_len) {
kfree_skb(skb);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/i2c.h`, `linux/gpio/consumer.h`, `linux/delay.h`, `linux/module.h`, `net/nfc/nfc.h`, `phy_common.h`.
- Detected declarations: `struct s3fwrn5_i2c_phy`, `function s3fwrn5_i2c_set_mode`, `function s3fwrn5_i2c_write`, `function s3fwrn5_i2c_read`, `function s3fwrn5_i2c_irq_thread_fn`, `function s3fwrn5_i2c_probe`, `function s3fwrn5_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.