drivers/clk/mmp/clk-frac.c
Source file repositories/reference/linux-study-clean/drivers/clk/mmp/clk-frac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/mmp/clk-frac.c- Extension
.c- Size
- 4960 bytes
- Lines
- 207
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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.hlinux/slab.hlinux/io.hlinux/err.hclk.h
Detected Declarations
function Copyrightfunction clk_factor_recalc_ratefunction clk_factor_set_ratefunction clk_factor_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* mmp factor clock operation source file
*
* Copyright (C) 2012 Marvell
* Chao Xie <xiechao.mail@gmail.com>
*/
#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/err.h>
#include "clk.h"
/*
* It is M/N clock
*
* Fout from synthesizer can be given from two equations:
* numerator/denominator = Fin / (Fout * factor)
*/
#define to_clk_factor(hw) container_of(hw, struct mmp_clk_factor, hw)
static int clk_factor_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct mmp_clk_factor *factor = to_clk_factor(hw);
u64 rate = 0, prev_rate;
struct u32_fract *d;
int i;
for (i = 0; i < factor->ftbl_cnt; i++) {
d = &factor->ftbl[i];
prev_rate = rate;
rate = (u64)(req->best_parent_rate) * d->denominator;
do_div(rate, d->numerator * factor->masks->factor);
if (rate > req->rate)
break;
}
if ((i == 0) || (i == factor->ftbl_cnt))
req->rate = rate;
else if ((req->rate - prev_rate) > (rate - req->rate))
req->rate = rate;
else
req->rate = prev_rate;
return 0;
}
static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct mmp_clk_factor *factor = to_clk_factor(hw);
struct mmp_clk_factor_masks *masks = factor->masks;
struct u32_fract d;
unsigned int val;
u64 rate;
val = readl_relaxed(factor->base);
/* calculate numerator */
d.numerator = (val >> masks->num_shift) & masks->num_mask;
/* calculate denominator */
d.denominator = (val >> masks->den_shift) & masks->den_mask;
if (!d.denominator)
return 0;
rate = (u64)parent_rate * d.denominator;
do_div(rate, d.numerator * factor->masks->factor);
return rate;
}
/* Configures new clock rate*/
static int clk_factor_set_rate(struct clk_hw *hw, unsigned long drate,
unsigned long prate)
{
struct mmp_clk_factor *factor = to_clk_factor(hw);
struct mmp_clk_factor_masks *masks = factor->masks;
int i;
unsigned long val;
unsigned long flags = 0;
struct u32_fract *d;
u64 rate = 0;
for (i = 0; i < factor->ftbl_cnt; i++) {
d = &factor->ftbl[i];
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/slab.h`, `linux/io.h`, `linux/err.h`, `clk.h`.
- Detected declarations: `function Copyright`, `function clk_factor_recalc_rate`, `function clk_factor_set_rate`, `function clk_factor_init`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.