drivers/clk/clk-fractional-divider_test.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-fractional-divider_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-fractional-divider_test.c- Extension
.c- Size
- 4335 bytes
- Lines
- 149
- 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.
- 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/clk-provider.hkunit/test.hclk-fractional-divider.h
Detected Declarations
function clk_fd_test_approximation_max_denominatorfunction clk_fd_test_approximation_max_numeratorfunction clk_fd_test_approximation_max_denominator_zero_basedfunction clk_fd_test_approximation_max_numerator_zero_based
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Kunit tests for clk fractional divider
*/
#include <linux/clk-provider.h>
#include <kunit/test.h>
#include "clk-fractional-divider.h"
/*
* Test the maximum denominator case for fd clock without flags.
*
* Expect the highest possible denominator to be used in order to get as close as possible to the
* requested rate.
*/
static void clk_fd_test_approximation_max_denominator(struct kunit *test)
{
struct clk_fractional_divider *fd;
unsigned long rate, parent_rate, parent_rate_before, m, n, max_n;
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, fd);
fd->mwidth = 3;
fd->nwidth = 3;
max_n = 7;
rate = 240000000;
parent_rate = (max_n + 1) * rate; /* so that it exceeds the maximum divisor */
parent_rate_before = parent_rate;
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
KUNIT_EXPECT_EQ(test, m, 1);
KUNIT_EXPECT_EQ(test, n, max_n);
}
/*
* Test the maximum numerator case for fd clock without flags.
*
* Expect the highest possible numerator to be used in order to get as close as possible to the
* requested rate.
*/
static void clk_fd_test_approximation_max_numerator(struct kunit *test)
{
struct clk_fractional_divider *fd;
unsigned long rate, parent_rate, parent_rate_before, m, n, max_m;
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, fd);
fd->mwidth = 3;
max_m = 7;
fd->nwidth = 3;
rate = 240000000;
parent_rate = rate / (max_m + 1); /* so that it exceeds the maximum numerator */
parent_rate_before = parent_rate;
clk_fractional_divider_general_approximation(&fd->hw, rate, &parent_rate, &m, &n);
KUNIT_ASSERT_EQ(test, parent_rate, parent_rate_before);
KUNIT_EXPECT_EQ(test, m, max_m);
KUNIT_EXPECT_EQ(test, n, 1);
}
/*
* Test the maximum denominator case for zero based fd clock.
*
* Expect the highest possible denominator to be used in order to get as close as possible to the
* requested rate.
*/
static void clk_fd_test_approximation_max_denominator_zero_based(struct kunit *test)
{
struct clk_fractional_divider *fd;
unsigned long rate, parent_rate, parent_rate_before, m, n, max_n;
fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, fd);
fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
fd->mwidth = 3;
fd->nwidth = 3;
max_n = 8;
rate = 240000000;
parent_rate = (max_n + 1) * rate; /* so that it exceeds the maximum divisor */
parent_rate_before = parent_rate;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `kunit/test.h`, `clk-fractional-divider.h`.
- Detected declarations: `function clk_fd_test_approximation_max_denominator`, `function clk_fd_test_approximation_max_numerator`, `function clk_fd_test_approximation_max_denominator_zero_based`, `function clk_fd_test_approximation_max_numerator_zero_based`.
- Atlas domain: Driver Families / drivers/clk.
- 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.