drivers/i2c/i2c-smbus.c
Source file repositories/reference/linux-study-clean/drivers/i2c/i2c-smbus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/i2c-smbus.c- Extension
.c- Size
- 12808 bytes
- Lines
- 494
- Domain
- Driver Families
- Bucket
- drivers/i2c
- 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.
- 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/device.hlinux/dmi.hlinux/gpio/consumer.hlinux/i2c.hlinux/i2c-smbus.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/property.hlinux/slab.hlinux/workqueue.h
Detected Declarations
struct i2c_smbus_alertstruct alert_datastruct i2c_slave_host_notify_statusfunction smbus_do_alertfunction smbus_do_alert_forcefunction smbus_alertfunction smbalert_workfunction smbalert_probefunction smbalert_removefunction i2c_new_smbus_alert_devicefunction i2c_slave_host_notify_cbfunction i2c_free_slave_host_notify_devicefunction i2c_register_spdfunction i2c_register_spd_write_disablefunction i2c_register_spd_write_enableexport i2c_handle_smbus_alertexport i2c_new_slave_host_notify_deviceexport i2c_free_slave_host_notify_deviceexport i2c_register_spd_write_disableexport i2c_register_spd_write_enable
Annotated Snippet
struct i2c_smbus_alert {
struct work_struct alert;
struct i2c_client *ara; /* Alert response address */
};
struct alert_data {
unsigned short addr;
enum i2c_alert_protocol type;
unsigned int data;
};
/* If this is the alerting device, notify its driver */
static int smbus_do_alert(struct device *dev, void *addrp)
{
struct i2c_client *client = i2c_verify_client(dev);
struct alert_data *data = addrp;
struct i2c_driver *driver;
int ret;
if (!client || client->addr != data->addr)
return 0;
if (client->flags & I2C_CLIENT_TEN)
return 0;
/*
* Drivers should either disable alerts, or provide at least
* a minimal handler. Lock so the driver won't change.
*/
device_lock(dev);
if (client->dev.driver) {
driver = to_i2c_driver(client->dev.driver);
if (driver->alert) {
/* Stop iterating after we find the device */
driver->alert(client, data->type, data->data);
ret = -EBUSY;
} else {
dev_warn(&client->dev, "no driver alert()!\n");
ret = -EOPNOTSUPP;
}
} else {
dev_dbg(&client->dev, "alert with no driver\n");
ret = -ENODEV;
}
device_unlock(dev);
return ret;
}
/* Same as above, but call back all drivers with alert handler */
static int smbus_do_alert_force(struct device *dev, void *addrp)
{
struct i2c_client *client = i2c_verify_client(dev);
struct alert_data *data = addrp;
struct i2c_driver *driver;
if (!client || (client->flags & I2C_CLIENT_TEN))
return 0;
/*
* Drivers should either disable alerts, or provide at least
* a minimal handler. Lock so the driver won't change.
*/
device_lock(dev);
if (client->dev.driver) {
driver = to_i2c_driver(client->dev.driver);
if (driver->alert)
driver->alert(client, data->type, data->data);
}
device_unlock(dev);
return 0;
}
/*
* The alert IRQ handler needs to hand work off to a task which can issue
* SMBus calls, because those sleeping calls can't be made in IRQ context.
*/
static irqreturn_t smbus_alert(int irq, void *d)
{
struct i2c_smbus_alert *alert = d;
struct i2c_client *ara;
unsigned short prev_addr = I2C_CLIENT_END; /* Not a valid address */
ara = alert->ara;
for (;;) {
s32 status;
struct alert_data data;
Annotation
- Immediate include surface: `linux/device.h`, `linux/dmi.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/i2c-smbus.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct i2c_smbus_alert`, `struct alert_data`, `struct i2c_slave_host_notify_status`, `function smbus_do_alert`, `function smbus_do_alert_force`, `function smbus_alert`, `function smbalert_work`, `function smbalert_probe`, `function smbalert_remove`, `function i2c_new_smbus_alert_device`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: integration implementation candidate.
- 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.