drivers/i2c/i2c-core-slave.c
Source file repositories/reference/linux-study-clean/drivers/i2c/i2c-core-slave.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/i2c-core-slave.c- Extension
.c- Size
- 3271 bytes
- Lines
- 128
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dt-bindings/i2c/i2c.hlinux/acpi.hlinux/device.hlinux/err.hlinux/i2c.hlinux/of.hlinux/property.hi2c-core.htrace/events/i2c_slave.h
Detected Declarations
function Copyrightfunction i2c_slave_unregisterfunction i2c_slave_eventfunction i2c_detect_slave_modefunction fwnode_for_each_child_node_scopedexport i2c_slave_registerexport i2c_slave_unregisterexport i2c_slave_eventexport i2c_detect_slave_mode
Annotated Snippet
if (ret) {
dev_err(&client->dev, "%s: invalid address\n", __func__);
return ret;
}
}
if (!client->adapter->algo->reg_slave) {
dev_err(&client->dev, "%s: not supported by adapter\n", __func__);
return -EOPNOTSUPP;
}
client->slave_cb = slave_cb;
i2c_lock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
ret = client->adapter->algo->reg_slave(client);
i2c_unlock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
if (ret) {
client->slave_cb = NULL;
dev_err(&client->dev, "%s: adapter returned error %d\n", __func__, ret);
}
return ret;
}
EXPORT_SYMBOL_GPL(i2c_slave_register);
int i2c_slave_unregister(struct i2c_client *client)
{
int ret;
if (IS_ERR_OR_NULL(client))
return -EINVAL;
if (!client->adapter->algo->unreg_slave) {
dev_err(&client->dev, "%s: not supported by adapter\n", __func__);
return -EOPNOTSUPP;
}
i2c_lock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
ret = client->adapter->algo->unreg_slave(client);
i2c_unlock_bus(client->adapter, I2C_LOCK_ROOT_ADAPTER);
if (ret == 0)
client->slave_cb = NULL;
else
dev_err(&client->dev, "%s: adapter returned error %d\n", __func__, ret);
return ret;
}
EXPORT_SYMBOL_GPL(i2c_slave_unregister);
int i2c_slave_event(struct i2c_client *client,
enum i2c_slave_event event, u8 *val)
{
int ret = client->slave_cb(client, event, val);
if (trace_i2c_slave_enabled())
trace_call__i2c_slave(client, event, val, ret);
return ret;
}
EXPORT_SYMBOL_GPL(i2c_slave_event);
/**
* i2c_detect_slave_mode - detect operation mode
* @dev: The device owning the bus
*
* This checks the device nodes for an I2C slave by checking the address
* used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
* flag this means the device is configured to act as a I2C slave and it will
* be listening at that address.
*
* Returns true if an I2C own slave address is detected, otherwise returns
* false.
*/
bool i2c_detect_slave_mode(struct device *dev)
{
struct fwnode_handle *fwnode = dev_fwnode(dev);
if (is_of_node(fwnode)) {
u32 reg;
fwnode_for_each_child_node_scoped(fwnode, child) {
fwnode_property_read_u32(child, "reg", ®);
if (reg & I2C_OWN_SLAVE_ADDRESS)
return true;
}
} else if (is_acpi_device_node(fwnode)) {
dev_dbg(dev, "ACPI slave is not supported yet\n");
}
Annotation
- Immediate include surface: `dt-bindings/i2c/i2c.h`, `linux/acpi.h`, `linux/device.h`, `linux/err.h`, `linux/i2c.h`, `linux/of.h`, `linux/property.h`, `i2c-core.h`.
- Detected declarations: `function Copyright`, `function i2c_slave_unregister`, `function i2c_slave_event`, `function i2c_detect_slave_mode`, `function fwnode_for_each_child_node_scoped`, `export i2c_slave_register`, `export i2c_slave_unregister`, `export i2c_slave_event`, `export i2c_detect_slave_mode`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: integration implementation candidate.
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.