sound/soc/intel/avs/boards/rt5640.c

Source file repositories/reference/linux-study-clean/sound/soc/intel/avs/boards/rt5640.c

File Facts

System
Linux kernel
Corpus path
sound/soc/intel/avs/boards/rt5640.c
Extension
.c
Size
7710 bytes
Lines
272
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2022-2025 Intel Corporation
//
// Authors: Cezary Rojewski <cezary.rojewski@intel.com>
//          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
//

#include <linux/module.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include "../../../codecs/rt5640.h"
#include "../utils.h"

#define AVS_RT5640_MCLK_HZ		19200000
#define RT5640_CODEC_DAI		"rt5640-aif1"

static const struct snd_soc_dapm_widget card_widgets[] = {
	SND_SOC_DAPM_HP("Headphone Jack", NULL),
	SND_SOC_DAPM_MIC("Mic Jack", NULL),
	SND_SOC_DAPM_SPK("Speaker", NULL),
};

static const struct snd_soc_dapm_route card_routes[] = {
	{ "Headphone Jack", NULL, "HPOR" },
	{ "Headphone Jack", NULL, "HPOL" },
	{ "IN2P", NULL, "Mic Jack" },
	{ "IN2P", NULL, "MICBIAS1" },
	{ "Speaker", NULL, "SPOLP" },
	{ "Speaker", NULL, "SPOLN" },
	{ "Speaker", NULL, "SPORP" },
	{ "Speaker", NULL, "SPORN" },
};

static const struct snd_soc_jack_pin card_headset_pins[] = {
	{
		.pin = "Headphone Jack",
		.mask = SND_JACK_HEADPHONE,
	},
	{
		.pin = "Mic Jack",
		.mask = SND_JACK_MICROPHONE,
	},
};

static int avs_rt5640_codec_init(struct snd_soc_pcm_runtime *runtime)
{
	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(runtime, 0);
	struct snd_soc_card *card = runtime->card;
	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
	struct snd_soc_jack_pin *pins;
	struct snd_soc_jack *jack;
	int num_pins, ret;

	jack = snd_soc_card_get_drvdata(card);
	num_pins = ARRAY_SIZE(card_headset_pins);

	pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
	if (!pins)
		return -ENOMEM;

	ret = snd_soc_card_jack_new_pins(card, "Headset Jack", SND_JACK_HEADSET, jack, pins,
					 num_pins);
	if (ret)
		return ret;

	snd_soc_component_set_jack(codec_dai->component, jack, NULL);
	snd_soc_dapm_set_idle_bias(dapm, false);

	return 0;
}

static void avs_rt5640_codec_exit(struct snd_soc_pcm_runtime *runtime)
{
	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(runtime, 0);

	snd_soc_component_set_jack(codec_dai->component, NULL, NULL);
}

static int avs_rt5640_be_fixup(struct snd_soc_pcm_runtime *runtime,
			       struct snd_pcm_hw_params *params)
{
	struct snd_mask *fmask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);

	/* Format 24/32 is MSB-aligned for HDAudio and LSB-aligned for I2S. */
	if (params_format(params) == SNDRV_PCM_FORMAT_S32_LE)
		snd_mask_set_format(fmask, SNDRV_PCM_FORMAT_S24_LE);

Annotation

Implementation Notes