drivers/clk/sunxi/clk-sun9i-core.c
Source file repositories/reference/linux-study-clean/drivers/clk/sunxi/clk-sun9i-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sunxi/clk-sun9i-core.c- Extension
.c- Size
- 6408 bytes
- Lines
- 283
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/clk-provider.hlinux/of.hlinux/of_address.hlinux/log2.hclk-factors.h
Detected Declarations
function sun9i_a80_get_pll4_factorsfunction sun9i_a80_pll4_setupfunction sun9i_a80_get_gt_factorsfunction sun9i_a80_gt_setupfunction sun9i_a80_get_ahb_factorsfunction sun9i_a80_ahb_setupfunction sun9i_a80_apb0_setupfunction sun9i_a80_get_apb1_factorsfunction sun9i_a80_apb1_setup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2014 Chen-Yu Tsai
*
* Chen-Yu Tsai <wens@csie.org>
*/
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/log2.h>
#include "clk-factors.h"
/*
* sun9i_a80_get_pll4_factors() - calculates n, p, m factors for PLL4
* PLL4 rate is calculated as follows
* rate = (parent_rate * n >> p) / (m + 1);
* parent_rate is always 24MHz
*
* p and m are named div1 and div2 in Allwinner's SDK
*/
static void sun9i_a80_get_pll4_factors(struct factors_request *req)
{
int n;
int m = 1;
int p = 1;
/* Normalize value to a 6 MHz multiple (24 MHz / 4) */
n = DIV_ROUND_UP(req->rate, 6000000);
/* If n is too large switch to steps of 12 MHz */
if (n > 255) {
m = 0;
n = (n + 1) / 2;
}
/* If n is still too large switch to steps of 24 MHz */
if (n > 255) {
p = 0;
n = (n + 1) / 2;
}
/* n must be between 12 and 255 */
if (n > 255)
n = 255;
else if (n < 12)
n = 12;
req->rate = ((24000000 * n) >> p) / (m + 1);
req->n = n;
req->m = m;
req->p = p;
}
static const struct clk_factors_config sun9i_a80_pll4_config = {
.mshift = 18,
.mwidth = 1,
.nshift = 8,
.nwidth = 8,
.pshift = 16,
.pwidth = 1,
};
static const struct factors_data sun9i_a80_pll4_data __initconst = {
.enable = 31,
.table = &sun9i_a80_pll4_config,
.getter = sun9i_a80_get_pll4_factors,
};
static DEFINE_SPINLOCK(sun9i_a80_pll4_lock);
static void __init sun9i_a80_pll4_setup(struct device_node *node)
{
void __iomem *reg;
reg = of_io_request_and_map(node, 0, of_node_full_name(node));
if (IS_ERR(reg)) {
pr_err("Could not get registers for a80-pll4-clk: %pOFn\n",
node);
return;
}
sunxi_factors_register(node, &sun9i_a80_pll4_data,
&sun9i_a80_pll4_lock, reg);
}
CLK_OF_DECLARE(sun9i_a80_pll4, "allwinner,sun9i-a80-pll4-clk", sun9i_a80_pll4_setup);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/of.h`, `linux/of_address.h`, `linux/log2.h`, `clk-factors.h`.
- Detected declarations: `function sun9i_a80_get_pll4_factors`, `function sun9i_a80_pll4_setup`, `function sun9i_a80_get_gt_factors`, `function sun9i_a80_gt_setup`, `function sun9i_a80_get_ahb_factors`, `function sun9i_a80_ahb_setup`, `function sun9i_a80_apb0_setup`, `function sun9i_a80_get_apb1_factors`, `function sun9i_a80_apb1_setup`.
- 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.