drivers/media/pci/ivtv/ivtv-i2c.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/ivtv/ivtv-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/ivtv/ivtv-i2c.c- Extension
.c- Size
- 20470 bytes
- Lines
- 740
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
ivtv-driver.hivtv-cards.hivtv-gpio.hivtv-i2c.hmedia/drv-intf/cx25840.h
Detected Declarations
function get_key_adaptecfunction ivtv_i2c_new_irfunction ivtv_i2c_new_ir_legacyfunction ivtv_i2c_registerfunction ivtv_setsclfunction ivtv_setsdafunction ivtv_getsclfunction ivtv_getsdafunction ivtv_scldelayfunction ivtv_waitsclfunction ivtv_waitsdafunction ivtv_ackfunction ivtv_sendbytefunction ivtv_readbytefunction ivtv_startfunction ivtv_stopfunction conditionfunction ivtv_readfunction ivtv_xferfunction ivtv_functionalityfunction ivtv_setscl_oldfunction ivtv_setsda_oldfunction ivtv_getscl_oldfunction ivtv_getsda_oldfunction init_ivtv_i2cfunction exit_ivtv_i2c
Annotated Snippet
if (sd->grp_id == hw) {
result = sd;
break;
}
}
spin_unlock(&itv->v4l2_dev.lock);
return result;
}
/* Set the serial clock line to the desired state */
static void ivtv_setscl(struct ivtv *itv, int state)
{
/* write them out */
/* write bits are inverted */
write_reg(~state, IVTV_REG_I2C_SETSCL_OFFSET);
}
/* Set the serial data line to the desired state */
static void ivtv_setsda(struct ivtv *itv, int state)
{
/* write them out */
/* write bits are inverted */
write_reg(~state & 1, IVTV_REG_I2C_SETSDA_OFFSET);
}
/* Read the serial clock line */
static int ivtv_getscl(struct ivtv *itv)
{
return read_reg(IVTV_REG_I2C_GETSCL_OFFSET) & 1;
}
/* Read the serial data line */
static int ivtv_getsda(struct ivtv *itv)
{
return read_reg(IVTV_REG_I2C_GETSDA_OFFSET) & 1;
}
/* Implement a short delay by polling the serial clock line */
static void ivtv_scldelay(struct ivtv *itv)
{
int i;
for (i = 0; i < 5; ++i)
ivtv_getscl(itv);
}
/* Wait for the serial clock line to become set to a specific value */
static int ivtv_waitscl(struct ivtv *itv, int val)
{
int i;
ivtv_scldelay(itv);
for (i = 0; i < 1000; ++i) {
if (ivtv_getscl(itv) == val)
return 1;
}
return 0;
}
/* Wait for the serial data line to become set to a specific value */
static int ivtv_waitsda(struct ivtv *itv, int val)
{
int i;
ivtv_scldelay(itv);
for (i = 0; i < 1000; ++i) {
if (ivtv_getsda(itv) == val)
return 1;
}
return 0;
}
/* Wait for the slave to issue an ACK */
static int ivtv_ack(struct ivtv *itv)
{
int ret = 0;
if (ivtv_getscl(itv) == 1) {
IVTV_DEBUG_HI_I2C("SCL was high starting an ack\n");
ivtv_setscl(itv, 0);
if (!ivtv_waitscl(itv, 0)) {
IVTV_DEBUG_I2C("Could not set SCL low starting an ack\n");
return -EREMOTEIO;
}
}
ivtv_setsda(itv, 1);
ivtv_scldelay(itv);
ivtv_setscl(itv, 1);
if (!ivtv_waitsda(itv, 0)) {
IVTV_DEBUG_I2C("Slave did not ack\n");
Annotation
- Immediate include surface: `ivtv-driver.h`, `ivtv-cards.h`, `ivtv-gpio.h`, `ivtv-i2c.h`, `media/drv-intf/cx25840.h`.
- Detected declarations: `function get_key_adaptec`, `function ivtv_i2c_new_ir`, `function ivtv_i2c_new_ir_legacy`, `function ivtv_i2c_register`, `function ivtv_setscl`, `function ivtv_setsda`, `function ivtv_getscl`, `function ivtv_getsda`, `function ivtv_scldelay`, `function ivtv_waitscl`.
- Atlas domain: Driver Families / drivers/media.
- 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.