sound/soc/codecs/audio-iio-aux.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/audio-iio-aux.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/audio-iio-aux.c- Extension
.c- Size
- 8726 bytes
- Lines
- 315
- 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.
- 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/cleanup.hlinux/iio/consumer.hlinux/minmax.hlinux/mod_devicetable.hlinux/platform_device.hlinux/slab.hlinux/string_helpers.hsound/soc.hsound/tlv.h
Detected Declarations
struct audio_iio_aux_chanstruct audio_iio_auxfunction audio_iio_aux_info_volswfunction audio_iio_aux_get_volswfunction audio_iio_aux_put_volswfunction audio_iio_aux_add_controlsfunction audio_iio_aux_add_dapmsfunction audio_iio_aux_component_probefunction audio_iio_aux_probe
Annotated Snippet
struct audio_iio_aux_chan {
struct iio_channel *iio_chan;
const char *name;
int max;
int min;
bool is_invert_range;
};
struct audio_iio_aux {
struct device *dev;
unsigned int num_chans;
struct audio_iio_aux_chan chans[] __counted_by(num_chans);
};
static int audio_iio_aux_info_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = chan->max - chan->min;
uinfo->type = (uinfo->value.integer.max == 1) ?
SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
return 0;
}
static int audio_iio_aux_get_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value;
int max = chan->max;
int min = chan->min;
bool invert_range = chan->is_invert_range;
int ret;
int val;
ret = iio_read_channel_raw(chan->iio_chan, &val);
if (ret < 0)
return ret;
ucontrol->value.integer.value[0] = val - min;
if (invert_range)
ucontrol->value.integer.value[0] = max - ucontrol->value.integer.value[0];
return 0;
}
static int audio_iio_aux_put_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct audio_iio_aux_chan *chan = (struct audio_iio_aux_chan *)kcontrol->private_value;
int max = chan->max;
int min = chan->min;
bool invert_range = chan->is_invert_range;
int val;
int ret;
int tmp;
val = ucontrol->value.integer.value[0];
if (val < 0)
return -EINVAL;
if (val > max - min)
return -EINVAL;
val = val + min;
if (invert_range)
val = max - val;
ret = iio_read_channel_raw(chan->iio_chan, &tmp);
if (ret < 0)
return ret;
if (tmp == val)
return 0;
ret = iio_write_channel_raw(chan->iio_chan, val);
if (ret)
return ret;
return 1; /* The value changed */
}
static int audio_iio_aux_add_controls(struct snd_soc_component *component,
struct audio_iio_aux_chan *chan)
{
struct snd_kcontrol_new control = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = chan->name,
.info = audio_iio_aux_info_volsw,
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/iio/consumer.h`, `linux/minmax.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/string_helpers.h`, `sound/soc.h`.
- Detected declarations: `struct audio_iio_aux_chan`, `struct audio_iio_aux`, `function audio_iio_aux_info_volsw`, `function audio_iio_aux_get_volsw`, `function audio_iio_aux_put_volsw`, `function audio_iio_aux_add_controls`, `function audio_iio_aux_add_dapms`, `function audio_iio_aux_component_probe`, `function audio_iio_aux_probe`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source implementation candidate.
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.