sound/soc/codecs/rt5640.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/rt5640.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/rt5640.c- Extension
.c- Size
- 96222 bytes
- Lines
- 3075
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/moduleparam.hlinux/init.hlinux/delay.hlinux/pm.hlinux/gpio/consumer.hlinux/i2c.hlinux/regmap.hlinux/of.hlinux/platform_device.hlinux/spi/spi.hlinux/acpi.hsound/core.hsound/jack.hsound/pcm.hsound/pcm_params.hsound/soc.hsound/soc-dapm.hsound/initval.hsound/tlv.hrl6231.hrt5640.h
Detected Declarations
function rt5640_resetfunction rt5640_volatile_registerfunction rt5640_readable_registerfunction set_dmic_clkfunction is_using_asrcfunction hp_amp_power_onfunction rt5640_pmu_depopfunction rt5640_hp_eventfunction rt5640_lout_eventfunction rt5640_hp_power_eventfunction rt5640_hp_post_eventfunction get_sdp_infofunction rt5640_hw_paramsfunction rt5640_set_dai_fmtfunction rt5640_set_dai_sysclkfunction rt5640_set_dai_pllfunction rt5640_set_bias_levelfunction rt5640_dmic_enablefunction rt5640_sel_asrc_clk_srcfunction rt5640_enable_micbias1_for_ovcdfunction rt5640_disable_micbias1_for_ovcdfunction rt5640_enable_micbias1_ovcd_irqfunction rt5640_disable_micbias1_ovcd_irqfunction rt5640_clear_micbias1_ovcdfunction rt5640_micbias1_ovcdfunction rt5640_jack_insertedfunction rt5640_start_button_press_workfunction rt5640_button_press_workfunction rt5640_detect_headsetfunction rt5640_jack_workfunction rt5640_irqfunction rt5640_jd_gpio_irqfunction rt5640_disable_irq_and_cancel_workfunction rt5640_set_ovcd_paramsfunction rt5640_disable_jack_detectfunction rt5640_enable_jack_detectfunction rt5640_enable_hda_jack_detectfunction rt5640_set_jackfunction rt5640_probefunction rt5640_removefunction rt5640_suspendfunction rt5640_resumefunction rt5640_i2c_probeexport rt5640_dmic_enableexport rt5640_sel_asrc_clk_srcexport rt5640_enable_micbias1_for_ovcdexport rt5640_disable_micbias1_for_ovcdexport rt5640_detect_headset
Annotated Snippet
switch (val) {
case RT5640_IF_123:
case RT5640_IF_132:
ret |= RT5640_U_IF1;
break;
case RT5640_IF_113:
ret |= RT5640_U_IF1;
fallthrough;
case RT5640_IF_312:
case RT5640_IF_213:
ret |= RT5640_U_IF2;
break;
}
break;
case RT5640_AIF2:
switch (val) {
case RT5640_IF_231:
case RT5640_IF_213:
ret |= RT5640_U_IF1;
break;
case RT5640_IF_223:
ret |= RT5640_U_IF1;
fallthrough;
case RT5640_IF_123:
case RT5640_IF_321:
ret |= RT5640_U_IF2;
break;
}
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int rt5640_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
struct snd_soc_component *component = dai->component;
struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
unsigned int val_len = 0, val_clk, mask_clk;
int dai_sel, pre_div, bclk_ms, frame_size;
rt5640->lrck[dai->id] = params_rate(params);
pre_div = rl6231_get_clk_info(rt5640->sysclk, rt5640->lrck[dai->id]);
if (pre_div < 0) {
dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n",
rt5640->lrck[dai->id], dai->id);
return -EINVAL;
}
frame_size = snd_soc_params_to_frame_size(params);
if (frame_size < 0) {
dev_err(component->dev, "Unsupported frame size: %d\n", frame_size);
return frame_size;
}
if (frame_size > 32)
bclk_ms = 1;
else
bclk_ms = 0;
rt5640->bclk[dai->id] = rt5640->lrck[dai->id] * (32 << bclk_ms);
dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n",
rt5640->bclk[dai->id], rt5640->lrck[dai->id]);
dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
bclk_ms, pre_div, dai->id);
switch (params_width(params)) {
case 16:
break;
case 20:
val_len |= RT5640_I2S_DL_20;
break;
case 24:
val_len |= RT5640_I2S_DL_24;
break;
case 8:
val_len |= RT5640_I2S_DL_8;
break;
default:
return -EINVAL;
}
dai_sel = get_sdp_info(component, dai->id);
if (dai_sel < 0) {
dev_err(component->dev, "Failed to get sdp info: %d\n", dai_sel);
return -EINVAL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/init.h`, `linux/delay.h`, `linux/pm.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/regmap.h`.
- Detected declarations: `function rt5640_reset`, `function rt5640_volatile_register`, `function rt5640_readable_register`, `function set_dmic_clk`, `function is_using_asrc`, `function hp_amp_power_on`, `function rt5640_pmu_depop`, `function rt5640_hp_event`, `function rt5640_lout_event`, `function rt5640_hp_power_event`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.