drivers/i2c/busses/i2c-cbus-gpio.c
Source file repositories/reference/linux-study-clean/drivers/i2c/busses/i2c-cbus-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/busses/i2c-cbus-gpio.c- Extension
.c- Size
- 7017 bytes
- Lines
- 283
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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.
- 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/io.hlinux/i2c.hlinux/slab.hlinux/delay.hlinux/errno.hlinux/kernel.hlinux/module.hlinux/gpio/consumer.hlinux/interrupt.hlinux/platform_device.h
Detected Declarations
struct cbus_hostfunction cbus_send_bitfunction cbus_send_datafunction cbus_receive_bitfunction cbus_receive_wordfunction cbus_transferfunction cbus_i2c_smbus_xferfunction cbus_i2c_funcfunction cbus_i2c_removefunction cbus_i2c_probe
Annotated Snippet
struct cbus_host {
spinlock_t lock; /* host lock */
struct device *dev;
struct gpio_desc *clk;
struct gpio_desc *dat;
struct gpio_desc *sel;
};
/**
* cbus_send_bit - sends one bit over the bus
* @host: the host we're using
* @bit: one bit of information to send
*/
static void cbus_send_bit(struct cbus_host *host, unsigned bit)
{
gpiod_set_value(host->dat, bit ? 1 : 0);
gpiod_set_value(host->clk, 1);
gpiod_set_value(host->clk, 0);
}
/**
* cbus_send_data - sends @len amount of data over the bus
* @host: the host we're using
* @data: the data to send
* @len: size of the transfer
*/
static void cbus_send_data(struct cbus_host *host, unsigned data, unsigned len)
{
int i;
for (i = len; i > 0; i--)
cbus_send_bit(host, data & (1 << (i - 1)));
}
/**
* cbus_receive_bit - receives one bit from the bus
* @host: the host we're using
*/
static int cbus_receive_bit(struct cbus_host *host)
{
int ret;
gpiod_set_value(host->clk, 1);
ret = gpiod_get_value(host->dat);
gpiod_set_value(host->clk, 0);
return ret;
}
/**
* cbus_receive_word - receives 16-bit word from the bus
* @host: the host we're using
*/
static int cbus_receive_word(struct cbus_host *host)
{
int ret = 0;
int i;
for (i = 16; i > 0; i--) {
int bit = cbus_receive_bit(host);
if (bit < 0)
return bit;
if (bit)
ret |= 1 << (i - 1);
}
return ret;
}
/**
* cbus_transfer - transfers data over the bus
* @host: the host we're using
* @rw: read/write flag
* @dev: device address
* @reg: register address
* @data: if @rw == I2C_SBUS_WRITE data to send otherwise 0
*/
static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev,
unsigned reg, unsigned data)
{
unsigned long flags;
int ret;
/* We don't want interrupts disturbing our transfer */
spin_lock_irqsave(&host->lock, flags);
/* Reset state and start of transfer, SEL stays down during transfer */
gpiod_set_value(host->sel, 0);
/* Set the DAT pin to output */
Annotation
- Immediate include surface: `linux/io.h`, `linux/i2c.h`, `linux/slab.h`, `linux/delay.h`, `linux/errno.h`, `linux/kernel.h`, `linux/module.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct cbus_host`, `function cbus_send_bit`, `function cbus_send_data`, `function cbus_receive_bit`, `function cbus_receive_word`, `function cbus_transfer`, `function cbus_i2c_smbus_xfer`, `function cbus_i2c_func`, `function cbus_i2c_remove`, `function cbus_i2c_probe`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.