drivers/clk/clk-fixed-rate_test.c

Source file repositories/reference/linux-study-clean/drivers/clk/clk-fixed-rate_test.c

File Facts

System
Linux kernel
Corpus path
drivers/clk/clk-fixed-rate_test.c
Extension
.c
Size
11072 bytes
Lines
381
Domain
Driver Families
Bucket
drivers/clk
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 clk_hw_fixed_rate_kunit_params {
	struct device *dev;
	struct device_node *np;
	const char *name;
	const char *parent_name;
	const struct clk_hw *parent_hw;
	const struct clk_parent_data *parent_data;
	unsigned long flags;
	unsigned long fixed_rate;
	unsigned long fixed_accuracy;
	unsigned long clk_fixed_flags;
};

static int
clk_hw_register_fixed_rate_kunit_init(struct kunit_resource *res, void *context)
{
	struct clk_hw_fixed_rate_kunit_params *params = context;
	struct clk_hw *hw;

	hw = __clk_hw_register_fixed_rate(params->dev, params->np,
					  params->name,
					  params->parent_name,
					  params->parent_hw,
					  params->parent_data,
					  params->flags,
					  params->fixed_rate,
					  params->fixed_accuracy,
					  params->clk_fixed_flags,
					  false);
	if (IS_ERR(hw))
		return PTR_ERR(hw);

	res->data = hw;

	return 0;
}

static void clk_hw_register_fixed_rate_kunit_exit(struct kunit_resource *res)
{
	struct clk_hw *hw = res->data;

	clk_hw_unregister_fixed_rate(hw);
}

/**
 * clk_hw_register_fixed_rate_kunit() - Test managed __clk_hw_register_fixed_rate()
 * @test: The test context
 * @params: Arguments to __clk_hw_register_fixed_rate()
 *
 * Return: Registered fixed rate clk_hw or ERR_PTR on failure
 */
static struct clk_hw *
clk_hw_register_fixed_rate_kunit(struct kunit *test,
				 struct clk_hw_fixed_rate_kunit_params *params)
{
	struct clk_hw *hw;

	hw = kunit_alloc_resource(test,
				  clk_hw_register_fixed_rate_kunit_init,
				  clk_hw_register_fixed_rate_kunit_exit,
				  GFP_KERNEL, params);
	if (!hw)
		return ERR_PTR(-EINVAL);

	return hw;
}

/**
 * clk_hw_unregister_fixed_rate_kunit() - Test managed clk_hw_unregister_fixed_rate()
 * @test: The test context
 * @hw: fixed rate clk to unregister upon test completion
 *
 * Automatically unregister @hw when @test is complete via
 * clk_hw_unregister_fixed_rate().
 *
 * Return: 0 on success or negative errno on failure
 */
static int clk_hw_unregister_fixed_rate_kunit(struct kunit *test, struct clk_hw *hw)
{
	if (!kunit_alloc_resource(test, NULL,
				  clk_hw_register_fixed_rate_kunit_exit,
				  GFP_KERNEL, hw))
		return -ENOMEM;

	return 0;
}

/*
 * Test that clk_get_rate() on a fixed rate clk registered with
 * clk_hw_register_fixed_rate() gets the proper frequency.

Annotation

Implementation Notes