drivers/i2c/i2c-core-of-prober.c
Source file repositories/reference/linux-study-clean/drivers/i2c/i2c-core-of-prober.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/i2c/i2c-core-of-prober.c- Extension
.c- Size
- 12737 bytes
- Lines
- 416
- 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.
- 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/cleanup.hlinux/delay.hlinux/device.hlinux/dev_printk.hlinux/err.hlinux/gpio/consumer.hlinux/i2c.hlinux/i2c-of-prober.hlinux/module.hlinux/of.hlinux/regulator/consumer.hlinux/slab.hlinux/stddef.h
Detected Declarations
function Copyrightfunction i2c_of_probe_enable_nodefunction i2c_of_probe_componentfunction for_each_child_of_node_with_prefixfunction i2c_of_probe_simple_get_supplyfunction i2c_of_probe_simple_put_supplyfunction i2c_of_probe_simple_enable_regulatorfunction i2c_of_probe_simple_disable_regulatorfunction i2c_of_probe_simple_get_gpiodfunction i2c_of_probe_simple_put_gpiodfunction i2c_of_probe_simple_set_gpiofunction i2c_of_probe_simple_disable_gpiofunction i2c_of_probe_simple_enablefunction i2c_of_probe_simple_cleanup_earlyfunction i2c_of_probe_simple_enable
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Linux I2C core OF component prober code
*
* Copyright (C) 2024 Google LLC
*/
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/i2c-of-prober.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/stddef.h>
/*
* Some devices, such as Google Hana Chromebooks, are produced by multiple
* vendors each using their preferred components. Such components are all
* in the device tree. Instead of having all of them enabled and having each
* driver separately try and probe its device while fighting over shared
* resources, they can be marked as "fail-needs-probe" and have a prober
* figure out which one is actually used beforehand.
*
* This prober assumes such drop-in parts are on the same I2C bus, have
* non-conflicting addresses, and can be directly probed by seeing which
* address responds.
*
* TODO:
* - Support I2C muxes
*/
static struct device_node *i2c_of_probe_get_i2c_node(struct device *dev, const char *type)
{
struct device_node *node __free(device_node) = of_find_node_by_name(NULL, type);
if (!node) {
dev_err(dev, "Could not find %s device node\n", type);
return NULL;
}
struct device_node *i2c_node __free(device_node) = of_get_parent(node);
if (!of_node_name_eq(i2c_node, "i2c")) {
dev_err(dev, "%s device isn't on I2C bus\n", type);
return NULL;
}
if (!of_device_is_available(i2c_node)) {
dev_err(dev, "I2C controller not available\n");
return NULL;
}
return no_free_ptr(i2c_node);
}
static int i2c_of_probe_enable_node(struct device *dev, struct device_node *node)
{
int ret;
dev_dbg(dev, "Enabling %pOF\n", node);
struct of_changeset *ocs __free(kfree) = kzalloc_obj(*ocs);
if (!ocs)
return -ENOMEM;
of_changeset_init(ocs);
ret = of_changeset_update_prop_string(ocs, node, "status", "okay");
if (ret)
return ret;
ret = of_changeset_apply(ocs);
if (ret) {
/* ocs needs to be explicitly cleaned up before being freed. */
of_changeset_destroy(ocs);
} else {
/*
* ocs is intentionally kept around as it needs to
* exist as long as the change is applied.
*/
void *ptr __always_unused = no_free_ptr(ocs);
}
return ret;
}
static const struct i2c_of_probe_ops i2c_of_probe_dummy_ops;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/delay.h`, `linux/device.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/i2c-of-prober.h`.
- Detected declarations: `function Copyright`, `function i2c_of_probe_enable_node`, `function i2c_of_probe_component`, `function for_each_child_of_node_with_prefix`, `function i2c_of_probe_simple_get_supply`, `function i2c_of_probe_simple_put_supply`, `function i2c_of_probe_simple_enable_regulator`, `function i2c_of_probe_simple_disable_regulator`, `function i2c_of_probe_simple_get_gpiod`, `function i2c_of_probe_simple_put_gpiod`.
- 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.