sound/soc/codecs/nau8325.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/nau8325.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/nau8325.c- Extension
.c- Size
- 26377 bytes
- Lines
- 907
- Domain
- Driver Families
- Bucket
- sound/soc
- 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.hlinux/delay.hlinux/init.hlinux/i2c.hlinux/module.hlinux/regmap.hlinux/slab.hsound/core.hsound/initval.hsound/pcm.hsound/pcm_params.hsound/soc.hsound/tlv.hnau8325.h
Detected Declarations
function nau8325_readable_regfunction nau8325_writeable_regfunction nau8325_volatile_regfunction nau8325_dac_eventfunction nau8325_powerup_eventfunction nau8325_srate_clk_applyfunction nau8325_clksrc_n2function nau8325_clksrc_choosefunction nau8325_clock_configfunction nau8325_dai_startupfunction nau8325_hw_paramsfunction nau8325_set_fmtfunction nau8325_set_sysclkfunction nau8325_reset_chipfunction nau8325_software_resetfunction nau8325_init_regsfunction nau8325_print_device_propertiesfunction nau8325_read_device_propertiesfunction nau8325_i2c_probe
Annotated Snippet
if (srate_table->mclk_src[NAU8325_MCLK_FS_RATIO_256] == mclk_src) {
ratio = NAU8325_MCLK_FS_RATIO_256;
break;
} else if (srate_table->mclk_src[NAU8325_MCLK_FS_RATIO_400] == mclk_src) {
ratio = NAU8325_MCLK_FS_RATIO_400;
break;
} else if (srate_table->mclk_src[NAU8325_MCLK_FS_RATIO_500] == mclk_src) {
ratio = NAU8325_MCLK_FS_RATIO_500;
break;
}
}
if (ratio != NAU8325_MCLK_FS_RATIO_NUM)
*n2_sel = i;
return ratio;
}
static const struct nau8325_srate_attr *target_srate_attribute(int srate)
{
int i;
for (i = 0; i < ARRAY_SIZE(target_srate_table); i++)
if (target_srate_table[i].fs == srate)
break;
if (i == ARRAY_SIZE(target_srate_table))
goto proc_err;
return &target_srate_table[i];
proc_err:
return NULL;
}
static int nau8325_clksrc_choose(struct nau8325 *nau8325,
const struct nau8325_srate_attr **srate_table,
int *n1_sel, int *mult_sel, int *n2_sel)
{
int i, j, mclk, ratio;
int mclk_max = 0, ratio_sel = 0, n2_max = 0;
if (!nau8325->mclk || !nau8325->fs)
goto proc_err;
/* select sampling rate and MCLK_SRC */
*srate_table = target_srate_attribute(nau8325->fs);
if (!*srate_table)
goto proc_err;
/* First check clock from MCLK directly, decide N2 for MCLK_SRC.
* If not good, consider 1/N1 and Multiplier.
*/
ratio = nau8325_clksrc_n2(nau8325, *srate_table, nau8325->mclk, n2_sel);
if (ratio != NAU8325_MCLK_FS_RATIO_NUM) {
*n1_sel = 0;
*mult_sel = CLK_PROC_BYPASS;
*n2_sel = MCLK_SRC;
goto proc_done;
}
/* Get MCLK_SRC through 1/N, Multiplier, and then 1/N2. */
for (i = 0; i < ARRAY_SIZE(mclk_n1_div); i++) {
for (j = 0; j < ARRAY_SIZE(mclk_n3_mult); j++) {
mclk = nau8325->mclk << mclk_n3_mult[j].param;
mclk = mclk / mclk_n1_div[i].param;
ratio = nau8325_clksrc_n2(nau8325,
*srate_table, mclk, n2_sel);
if (ratio != NAU8325_MCLK_FS_RATIO_NUM &&
(mclk_max < mclk || i > *n1_sel)) {
mclk_max = mclk;
n2_max = *n2_sel;
*n1_sel = i;
*mult_sel = j;
ratio_sel = ratio;
goto proc_done;
}
}
}
if (mclk_max) {
*n2_sel = n2_max;
ratio = ratio_sel;
goto proc_done;
}
proc_err:
dev_dbg(nau8325->dev, "The MCLK %d is invalid. It can't get MCLK_SRC of 256/400/500 FS (%d)",
nau8325->mclk, nau8325->fs);
return -EINVAL;
proc_done:
dev_dbg(nau8325->dev, "nau8325->fs=%d,range=0x%x, %s, (n1,mu,n2,dmu):(%d,%d,%d), MCLK_SRC=%uHz (%d)",
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/init.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`, `sound/core.h`.
- Detected declarations: `function nau8325_readable_reg`, `function nau8325_writeable_reg`, `function nau8325_volatile_reg`, `function nau8325_dac_event`, `function nau8325_powerup_event`, `function nau8325_srate_clk_apply`, `function nau8325_clksrc_n2`, `function nau8325_clksrc_choose`, `function nau8325_clock_config`, `function nau8325_dai_startup`.
- Atlas domain: Driver Families / sound/soc.
- 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.