drivers/gpio/gpiolib-kunit.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib-kunit.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpiolib-kunit.c- Extension
.c- Size
- 9357 bytes
- Lines
- 359
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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/fwnode.hlinux/gpio/consumer.hlinux/gpio/driver.hlinux/gpio/machine.hlinux/gpio/property.hlinux/notifier.hlinux/platform_device.hlinux/property.hkunit/platform_device.hkunit/test.h
Detected Declarations
struct gpio_swnode_consumer_pdatastruct gpio_unbind_consumer_drvdatafunction Copyrightfunction gpio_test_provider_setfunction gpio_test_provider_probefunction gpio_swnode_consumer_probefunction gpio_swnode_lookup_by_primaryfunction gpio_swnode_lookup_by_secondaryfunction gpio_unbind_notifyfunction gpio_unbind_unregister_notifierfunction gpio_unbind_consumer_probefunction gpio_unbind_with_consumersfunction scoped_guard
Annotated Snippet
struct gpio_swnode_consumer_pdata {
bool gpio_ok;
};
static const struct gpio_swnode_consumer_pdata gpio_swnode_pdata_template = {
.gpio_ok = false,
};
static int gpio_swnode_consumer_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct gpio_swnode_consumer_pdata *pdata = dev_get_platdata(dev);
struct gpio_desc *desc;
desc = devm_gpiod_get(dev, "foo", GPIOD_OUT_HIGH);
if (IS_ERR(desc))
return PTR_ERR(desc);
pdata->gpio_ok = true;
return 0;
}
static struct platform_driver gpio_swnode_consumer_driver = {
.probe = gpio_swnode_consumer_probe,
.driver = {
.name = GPIO_SWNODE_TEST_CONSUMER,
},
};
static void gpio_swnode_lookup_by_primary(struct kunit *test)
{
struct gpio_swnode_consumer_pdata *pdata;
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct platform_device *pdev;
bool bound = false;
int ret;
ret = kunit_platform_driver_register(test, &gpio_test_provider_driver);
KUNIT_ASSERT_EQ(test, ret, 0);
ret = kunit_platform_driver_register(test, &gpio_swnode_consumer_driver);
KUNIT_ASSERT_EQ(test, ret, 0);
pdevinfo = (struct platform_device_info){
.name = GPIO_TEST_PROVIDER,
.id = PLATFORM_DEVID_NONE,
.swnode = &gpio_test_provider_swnode,
};
pdev = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
properties[0] = PROPERTY_ENTRY_GPIO("foo-gpios",
&gpio_test_provider_swnode,
0, GPIO_ACTIVE_HIGH);
properties[1] = (struct property_entry){ };
pdevinfo = (struct platform_device_info){
.name = GPIO_SWNODE_TEST_CONSUMER,
.id = PLATFORM_DEVID_NONE,
.data = &gpio_swnode_pdata_template,
.size_data = sizeof(gpio_swnode_pdata_template),
.properties = properties,
};
pdev = kunit_platform_device_register_full(test, &pdevinfo);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
wait_for_device_probe();
scoped_guard(device, &pdev->dev)
bound = device_is_bound(&pdev->dev);
KUNIT_ASSERT_TRUE(test, bound);
pdata = dev_get_platdata(&pdev->dev);
KUNIT_ASSERT_TRUE(test, pdata->gpio_ok);
}
static void gpio_swnode_lookup_by_secondary(struct kunit *test)
{
struct gpio_swnode_consumer_pdata *pdata;
struct platform_device_info pdevinfo;
struct property_entry properties[2];
struct fwnode_handle *primary;
struct platform_device *pdev;
bool bound = false;
int ret;
Annotation
- Immediate include surface: `linux/fwnode.h`, `linux/gpio/consumer.h`, `linux/gpio/driver.h`, `linux/gpio/machine.h`, `linux/gpio/property.h`, `linux/notifier.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct gpio_swnode_consumer_pdata`, `struct gpio_unbind_consumer_drvdata`, `function Copyright`, `function gpio_test_provider_set`, `function gpio_test_provider_probe`, `function gpio_swnode_consumer_probe`, `function gpio_swnode_lookup_by_primary`, `function gpio_swnode_lookup_by_secondary`, `function gpio_unbind_notify`, `function gpio_unbind_unregister_notifier`.
- Atlas domain: Driver Families / drivers/gpio.
- 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.