sound/soc/amd/acp-es8336.c

Source file repositories/reference/linux-study-clean/sound/soc/amd/acp-es8336.c

File Facts

System
Linux kernel
Corpus path
sound/soc/amd/acp-es8336.c
Extension
.c
Size
8174 bytes
Lines
320
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+
/*
 * Machine driver for AMD Stoney platform using ES8336 Codec
 *
 * Copyright 2022 Advanced Micro Devices, Inc.
 */

#include <sound/core.h>
#include <sound/soc.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc-dapm.h>
#include <sound/jack.h>
#include <linux/device.h>
#include <linux/dmi.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/machine.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/acpi.h>

#include "acp.h"

#define DUAL_CHANNEL	2
#define DRV_NAME "acp2x_mach"
#define ST_JADEITE	1
#define ES8336_PLL_FREQ (48000 * 256)

static unsigned long acp2x_machine_id;
static struct snd_soc_jack st_jack;
static struct device *codec_dev;
static struct gpio_desc *gpio_pa;

static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
					  struct snd_kcontrol *kcontrol, int event)
{
	if (SND_SOC_DAPM_EVENT_ON(event))
		gpiod_set_value_cansleep(gpio_pa, true);
	else
		gpiod_set_value_cansleep(gpio_pa, false);

	return 0;
}

static struct snd_soc_jack_pin st_es8316_jack_pins[] = {
	{
		.pin	= "Headphone",
		.mask	= SND_JACK_HEADPHONE,
	},
	{
		.pin	= "Headset Mic",
		.mask	= SND_JACK_MICROPHONE,
	},
};

static int st_es8336_init(struct snd_soc_pcm_runtime *rtd)
{
	int ret;
	struct snd_soc_card *card;
	struct snd_soc_component *codec;

	codec = snd_soc_rtd_to_codec(rtd, 0)->component;
	card = rtd->card;

	ret = snd_soc_card_jack_new_pins(card, "Headset", SND_JACK_HEADSET | SND_JACK_BTN_0,
					 &st_jack, st_es8316_jack_pins,
					 ARRAY_SIZE(st_es8316_jack_pins));
	if (ret) {
		dev_err(card->dev, "HP jack creation failed %d\n", ret);
		return ret;
	}
	snd_jack_set_key(st_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
	ret = snd_soc_component_set_jack(codec, &st_jack, NULL);
	if (ret) {
		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
		return ret;
	}
	return 0;
}

static const unsigned int st_channels[] = {
	DUAL_CHANNEL,
};

static const unsigned int st_rates[] = {
	48000,
};

Annotation

Implementation Notes