sound/soc/codecs/cros_ec_codec.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/cros_ec_codec.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/cros_ec_codec.c
Extension
.c
Size
27880 bytes
Lines
1065
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

struct cros_ec_codec_priv {
	struct device *dev;
	struct cros_ec_device *ec_device;

	/* common */
	uint32_t ec_capabilities;

	uint64_t ec_shm_addr;
	uint32_t ec_shm_len;

	uint64_t ap_shm_phys_addr;
	uint32_t ap_shm_len;
	uint64_t ap_shm_addr;
	uint64_t ap_shm_last_alloc;

	/* DMIC */
	atomic_t dmic_probed;

	/* I2S_RX */
	uint32_t i2s_rx_bclk_ratio;

	/* WoV */
	bool wov_enabled;
	uint8_t *wov_audio_shm_p;
	uint32_t wov_audio_shm_len;
	uint8_t wov_audio_shm_type;
	uint8_t *wov_lang_shm_p;
	uint32_t wov_lang_shm_len;
	uint8_t wov_lang_shm_type;

	struct mutex wov_dma_lock;
	uint8_t wov_buf[64000];
	uint32_t wov_rp, wov_wp;
	size_t wov_dma_offset;
	bool wov_burst_read;
	struct snd_pcm_substream *wov_substream;
	struct delayed_work wov_copy_work;
	struct notifier_block wov_notifier;
};

static int ec_codec_capable(struct cros_ec_codec_priv *priv, uint8_t cap)
{
	return priv->ec_capabilities & BIT(cap);
}

static int send_ec_host_command(struct cros_ec_device *ec_dev, uint32_t cmd,
				uint8_t *out, size_t outsize,
				uint8_t *in, size_t insize)
{
	int ret;
	struct cros_ec_command *msg;

	msg = kmalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	msg->version = 0;
	msg->command = cmd;
	msg->outsize = outsize;
	msg->insize = insize;

	if (outsize)
		memcpy(msg->data, out, outsize);

	ret = cros_ec_cmd_xfer_status(ec_dev, msg);
	if (ret < 0)
		goto error;

	if (in && insize)
		memcpy(in, msg->data, insize);

	ret = 0;
error:
	kfree(msg);
	return ret;
}

static int dmic_get_gain(struct snd_kcontrol *kcontrol,
			 struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
	struct cros_ec_codec_priv *priv =
		snd_soc_component_get_drvdata(component);
	struct ec_param_ec_codec_dmic p;
	struct ec_response_ec_codec_dmic_get_gain_idx r;
	int ret;

	p.cmd = EC_CODEC_DMIC_GET_GAIN_IDX;
	p.get_gain_idx_param.channel = EC_CODEC_DMIC_CHANNEL_0;
	ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_DMIC,

Annotation

Implementation Notes