drivers/i2c/muxes/i2c-mux-gpio.c
Source file repositories/reference/linux-study-clean/drivers/i2c/muxes/i2c-mux-gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/muxes/i2c-mux-gpio.c- Extension
.c- Size
- 6102 bytes
- Lines
- 263
- 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.
- 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/bits.hlinux/delay.hlinux/gpio/consumer.hlinux/gpio/driver.hlinux/i2c.hlinux/i2c-mux.hlinux/module.hlinux/overflow.hlinux/platform_data/i2c-mux-gpio.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct gpiomuxfunction i2c_mux_gpio_setfunction i2c_mux_gpio_selectfunction i2c_mux_gpio_deselectfunction i2c_mux_gpio_probe_fwfunction device_for_each_child_nodefunction i2c_mux_gpio_probefunction i2c_mux_gpio_remove
Annotated Snippet
struct gpiomux {
struct i2c_mux_gpio_platform_data data;
int ngpios;
struct gpio_desc **gpios;
};
static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned int val)
{
DECLARE_BITMAP(values, BITS_PER_TYPE(val));
values[0] = val;
gpiod_set_array_value_cansleep(mux->ngpios, mux->gpios, NULL, values);
}
static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan)
{
struct gpiomux *mux = i2c_mux_priv(muxc);
i2c_mux_gpio_set(mux, chan);
if (mux->data.settle_time)
fsleep(mux->data.settle_time);
return 0;
}
static int i2c_mux_gpio_deselect(struct i2c_mux_core *muxc, u32 chan)
{
struct gpiomux *mux = i2c_mux_priv(muxc);
i2c_mux_gpio_set(mux, mux->data.idle);
return 0;
}
static int i2c_mux_gpio_probe_fw(struct gpiomux *mux,
struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct fwnode_handle *fwnode = dev_fwnode(dev);
struct device_node *np = dev->of_node;
struct device_node *adapter_np;
struct i2c_adapter *adapter = NULL;
struct fwnode_handle *child;
unsigned int *values;
int rc, i = 0;
if (is_of_node(fwnode)) {
if (!np)
return -ENODEV;
adapter_np = of_parse_phandle(np, "i2c-parent", 0);
if (!adapter_np) {
dev_err(&pdev->dev, "Cannot parse i2c-parent\n");
return -ENODEV;
}
adapter = of_find_i2c_adapter_by_node(adapter_np);
of_node_put(adapter_np);
} else if (is_acpi_node(fwnode)) {
/*
* In ACPI land the mux should be a direct child of the i2c
* bus it muxes.
*/
acpi_handle dev_handle = ACPI_HANDLE(dev->parent);
adapter = i2c_acpi_find_adapter_by_handle(dev_handle);
}
if (!adapter)
return -EPROBE_DEFER;
mux->data.parent = i2c_adapter_id(adapter);
put_device(&adapter->dev);
mux->data.n_values = device_get_child_node_count(dev);
values = devm_kcalloc(dev,
mux->data.n_values, sizeof(*mux->data.values),
GFP_KERNEL);
if (!values) {
dev_err(dev, "Cannot allocate values array");
return -ENOMEM;
}
device_for_each_child_node(dev, child) {
if (is_of_node(child)) {
fwnode_property_read_u32(child, "reg", values + i);
} else if (is_acpi_node(child)) {
rc = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), values + i);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/gpio/driver.h`, `linux/i2c.h`, `linux/i2c-mux.h`, `linux/module.h`, `linux/overflow.h`.
- Detected declarations: `struct gpiomux`, `function i2c_mux_gpio_set`, `function i2c_mux_gpio_select`, `function i2c_mux_gpio_deselect`, `function i2c_mux_gpio_probe_fw`, `function device_for_each_child_node`, `function i2c_mux_gpio_probe`, `function i2c_mux_gpio_remove`.
- Atlas domain: Driver Families / drivers/i2c.
- Implementation status: source 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.