drivers/clk/ti/mux.c
Source file repositories/reference/linux-study-clean/drivers/clk/ti/mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/ti/mux.c- Extension
.c- Size
- 6441 bytes
- Lines
- 286
- 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.hlinux/slab.hlinux/err.hlinux/of.hlinux/of_address.hlinux/clk/ti.hclock.h
Detected Declarations
function Copyrightfunction ti_clk_mux_set_parentfunction clk_mux_save_contextfunction clk_mux_restore_contextfunction of_mux_clk_setupfunction of_ti_composite_mux_clk_setup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* TI Multiplexer Clock
*
* Copyright (C) 2013 Texas Instruments, Inc.
*
* Tero Kristo <t-kristo@ti.com>
*/
#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/clk/ti.h>
#include "clock.h"
#undef pr_fmt
#define pr_fmt(fmt) "%s: " fmt, __func__
static u8 ti_clk_mux_get_parent(struct clk_hw *hw)
{
struct clk_omap_mux *mux = to_clk_omap_mux(hw);
int num_parents = clk_hw_get_num_parents(hw);
u32 val;
/*
* FIXME need a mux-specific flag to determine if val is bitwise or
* numeric. e.g. sys_clkin_ck's clksel field is 3 bits wide, but ranges
* from 0x1 to 0x7 (index starts at one)
* OTOH, pmd_trace_clk_mux_ck uses a separate bit for each clock, so
* val = 0x4 really means "bit 2, index starts at bit 0"
*/
val = ti_clk_ll_ops->clk_readl(&mux->reg) >> mux->shift;
val &= mux->mask;
if (mux->table) {
int i;
for (i = 0; i < num_parents; i++)
if (mux->table[i] == val)
return i;
return -EINVAL;
}
if (val && (mux->flags & CLK_MUX_INDEX_BIT))
val = ffs(val) - 1;
if (val && (mux->flags & CLK_MUX_INDEX_ONE))
val--;
if (val >= num_parents)
return -EINVAL;
return val;
}
static int ti_clk_mux_set_parent(struct clk_hw *hw, u8 index)
{
struct clk_omap_mux *mux = to_clk_omap_mux(hw);
u32 val;
if (mux->table) {
index = mux->table[index];
} else {
if (mux->flags & CLK_MUX_INDEX_BIT)
index = (1 << ffs(index));
if (mux->flags & CLK_MUX_INDEX_ONE)
index++;
}
if (mux->flags & CLK_MUX_HIWORD_MASK) {
val = mux->mask << (mux->shift + 16);
} else {
val = ti_clk_ll_ops->clk_readl(&mux->reg);
val &= ~(mux->mask << mux->shift);
}
val |= index << mux->shift;
ti_clk_ll_ops->clk_writel(val, &mux->reg);
ti_clk_latch(&mux->reg, mux->latch);
return 0;
}
/**
* clk_mux_save_context - Save the parent selected in the mux
* @hw: pointer struct clk_hw
*
* Save the parent mux value.
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/slab.h`, `linux/err.h`, `linux/of.h`, `linux/of_address.h`, `linux/clk/ti.h`, `clock.h`.
- Detected declarations: `function Copyright`, `function ti_clk_mux_set_parent`, `function clk_mux_save_context`, `function clk_mux_restore_context`, `function of_mux_clk_setup`, `function of_ti_composite_mux_clk_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.