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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
crypto/sha2.hlinux/acpi.hlinux/delay.hlinux/device.hlinux/io.hlinux/jiffies.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_address.hlinux/of_reserved_mem.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/string_choices.hsound/pcm.hsound/pcm_params.hsound/soc.hsound/tlv.h
Detected Declarations
struct cros_ec_codec_privfunction ec_codec_capablefunction send_ec_host_commandfunction dmic_get_gainfunction dmic_put_gainfunction dmic_probefunction i2s_rx_hw_paramsfunction i2s_rx_set_bclk_ratiofunction i2s_rx_set_fmtfunction i2s_rx_eventfunction i2s_rx_probefunction wov_queue_fullfunction wov_queue_sizefunction wov_queue_dequeuefunction wov_queue_try_dequeuefunction wov_queue_enqueuefunction wov_read_audio_shmfunction wov_read_audiofunction wov_copy_workfunction wov_enable_getfunction wov_enable_putfunction wov_set_lang_shmfunction wov_set_langfunction wov_hotword_model_putfunction wov_host_eventfunction wov_probefunction wov_removefunction wov_pcm_openfunction wov_pcm_hw_paramsfunction wov_pcm_hw_freefunction wov_pcm_pointerfunction wov_pcm_newfunction cros_ec_codec_platform_probe
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
- Immediate include surface: `crypto/sha2.h`, `linux/acpi.h`, `linux/delay.h`, `linux/device.h`, `linux/io.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct cros_ec_codec_priv`, `function ec_codec_capable`, `function send_ec_host_command`, `function dmic_get_gain`, `function dmic_put_gain`, `function dmic_probe`, `function i2s_rx_hw_params`, `function i2s_rx_set_bclk_ratio`, `function i2s_rx_set_fmt`, `function i2s_rx_event`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.