drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c- Extension
.c- Size
- 9872 bytes
- Lines
- 384
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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/pci.hdrm/drm_edid.hdrm/amdgpu_drm.hamdgpu.hamdgpu_i2c.hamdgpu_atombios.hatom.hatombios_dp.hatombios_i2c.h
Detected Declarations
function filesfunction amdgpu_i2c_post_xferfunction amdgpu_i2c_get_clockfunction amdgpu_i2c_get_datafunction amdgpu_i2c_set_clockfunction amdgpu_i2c_set_datafunction amdgpu_i2c_initfunction amdgpu_i2c_finifunction amdgpu_i2c_lookupfunction amdgpu_i2c_get_bytefunction amdgpu_i2c_put_bytefunction amdgpu_i2c_router_select_ddc_portfunction amdgpu_i2c_router_select_cd_port
Annotated Snippet
if (ret) {
DRM_ERROR("Failed to register bit i2c %s\n", name);
goto out_free;
}
}
return i2c;
out_free:
kfree(i2c);
return NULL;
}
void amdgpu_i2c_init(struct amdgpu_device *adev)
{
if (!adev->is_atom_fw) {
if (!amdgpu_device_has_dc_support(adev)) {
amdgpu_atombios_i2c_init(adev);
} else {
switch (adev->asic_type) {
case CHIP_POLARIS10:
case CHIP_POLARIS11:
case CHIP_POLARIS12:
amdgpu_atombios_oem_i2c_init(adev, 0x97);
break;
default:
break;
}
}
}
}
/* remove all the buses */
void amdgpu_i2c_fini(struct amdgpu_device *adev)
{
int i;
for (i = 0; i < AMDGPU_MAX_I2C_BUS; i++)
if (adev->i2c_bus[i])
adev->i2c_bus[i] = NULL;
}
/* looks up bus based on id */
struct amdgpu_i2c_chan *
amdgpu_i2c_lookup(struct amdgpu_device *adev,
const struct amdgpu_i2c_bus_rec *i2c_bus)
{
int i;
for (i = 0; i < AMDGPU_MAX_I2C_BUS; i++) {
if (adev->i2c_bus[i] &&
(adev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
return adev->i2c_bus[i];
}
}
return NULL;
}
static int amdgpu_i2c_get_byte(struct amdgpu_i2c_chan *i2c_bus,
u8 slave_addr,
u8 addr,
u8 *val)
{
u8 out_buf[2];
u8 in_buf[2];
struct i2c_msg msgs[] = {
{
.addr = slave_addr,
.flags = 0,
.len = 1,
.buf = out_buf,
},
{
.addr = slave_addr,
.flags = I2C_M_RD,
.len = 1,
.buf = in_buf,
}
};
out_buf[0] = addr;
out_buf[1] = 0;
if (i2c_transfer(&i2c_bus->adapter, msgs, 2) != 2) {
DRM_DEBUG("i2c 0x%02x read failed\n", addr);
return -EIO;
}
*val = in_buf[0];
DRM_DEBUG("val = 0x%02x\n", *val);
Annotation
- Immediate include surface: `linux/pci.h`, `drm/drm_edid.h`, `drm/amdgpu_drm.h`, `amdgpu.h`, `amdgpu_i2c.h`, `amdgpu_atombios.h`, `atom.h`, `atombios_dp.h`.
- Detected declarations: `function files`, `function amdgpu_i2c_post_xfer`, `function amdgpu_i2c_get_clock`, `function amdgpu_i2c_get_data`, `function amdgpu_i2c_set_clock`, `function amdgpu_i2c_set_data`, `function amdgpu_i2c_init`, `function amdgpu_i2c_fini`, `function amdgpu_i2c_lookup`, `function amdgpu_i2c_get_byte`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.