drivers/sbus/char/bbc_i2c.c
Source file repositories/reference/linux-study-clean/drivers/sbus/char/bbc_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/sbus/char/bbc_i2c.c- Extension
.c- Size
- 9705 bytes
- Lines
- 423
- Domain
- Driver Families
- Bucket
- drivers/sbus
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/kernel.hlinux/types.hlinux/slab.hlinux/sched.hlinux/wait.hlinux/delay.hlinux/interrupt.hlinux/of.hlinux/of_platform.hlinux/platform_device.hasm/bbc.hasm/io.hbbc_i2c.h
Detected Declarations
function Copyrightfunction bbc_i2c_detachfunction wait_for_pinfunction bbc_i2c_writebfunction bbc_i2c_readbfunction bbc_i2c_write_buffunction bbc_i2c_read_buffunction bbc_i2c_interruptfunction reset_one_i2cfunction attach_one_i2cfunction bbc_i2c_probefunction bbc_i2c_removeexport bbc_i2c_getdevexport bbc_i2c_attachexport bbc_i2c_detachexport bbc_i2c_writebexport bbc_i2c_readbexport bbc_i2c_write_bufexport bbc_i2c_read_buf
Annotated Snippet
if (bp->devs[i].device == op) {
bp->devs[i].client_claimed = val;
return;
}
}
}
#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1)
#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0)
struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index)
{
struct platform_device *op = NULL;
int curidx = 0, i;
for (i = 0; i < NUM_CHILDREN; i++) {
if (!(op = bp->devs[i].device))
break;
if (curidx == index)
goto out;
op = NULL;
curidx++;
}
out:
if (curidx == index)
return op;
return NULL;
}
struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *op)
{
struct bbc_i2c_client *client;
const u32 *reg;
client = kzalloc_obj(*client);
if (!client)
return NULL;
client->bp = bp;
client->op = op;
reg = of_get_property(op->dev.of_node, "reg", NULL);
if (!reg) {
kfree(client);
return NULL;
}
client->bus = reg[0];
client->address = reg[1];
claim_device(bp, op);
return client;
}
void bbc_i2c_detach(struct bbc_i2c_client *client)
{
struct bbc_i2c_bus *bp = client->bp;
struct platform_device *op = client->op;
release_device(bp, op);
kfree(client);
}
static int wait_for_pin(struct bbc_i2c_bus *bp, u8 *status)
{
DECLARE_WAITQUEUE(wait, current);
int limit = 32;
int ret = 1;
bp->waiting = 1;
add_wait_queue(&bp->wq, &wait);
while (limit-- > 0) {
long val;
val = wait_event_interruptible_timeout(
bp->wq,
(((*status = readb(bp->i2c_control_regs + 0))
& I2C_PCF_PIN) == 0),
msecs_to_jiffies(250));
if (val > 0) {
ret = 0;
break;
}
}
remove_wait_queue(&bp->wq, &wait);
bp->waiting = 0;
return ret;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/types.h`, `linux/slab.h`, `linux/sched.h`, `linux/wait.h`, `linux/delay.h`, `linux/interrupt.h`.
- Detected declarations: `function Copyright`, `function bbc_i2c_detach`, `function wait_for_pin`, `function bbc_i2c_writeb`, `function bbc_i2c_readb`, `function bbc_i2c_write_buf`, `function bbc_i2c_read_buf`, `function bbc_i2c_interrupt`, `function reset_one_i2c`, `function attach_one_i2c`.
- Atlas domain: Driver Families / drivers/sbus.
- Implementation status: integration 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.