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.

Dependency Surface

Detected Declarations

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

Implementation Notes