sound/aoa/codecs/onyx.c
Source file repositories/reference/linux-study-clean/sound/aoa/codecs/onyx.c
File Facts
- System
- Linux kernel
- Corpus path
sound/aoa/codecs/onyx.c- Extension
.c- Size
- 27596 bytes
- Lines
- 1049
- Domain
- Driver Families
- Bucket
- sound/aoa
- 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/delay.hlinux/module.hlinux/of.hlinux/slab.hsound/asoundef.honyx.h../aoa.h../soundbus/soundbus.h
Detected Declarations
struct onyxfunction onyx_read_registerfunction onyx_write_registerfunction onyx_dev_registerfunction onyx_snd_vol_infofunction onyx_snd_vol_getfunction onyx_snd_vol_putfunction onyx_snd_inputgain_infofunction onyx_snd_inputgain_getfunction onyx_snd_inputgain_putfunction onyx_snd_capture_source_infofunction onyx_snd_capture_source_getfunction onyx_set_capture_sourcefunction onyx_snd_capture_source_putfunction onyx_snd_mute_getfunction onyx_snd_mute_putfunction onyx_snd_single_bit_getfunction onyx_snd_single_bit_putfunction onyx_spdif_infofunction onyx_spdif_mask_getfunction onyx_spdif_getfunction onyx_spdif_putfunction onyx_set_spdif_pcm_ratefunction onyx_register_initfunction onyx_usablefunction onyx_preparefunction onyx_openfunction onyx_closefunction onyx_switch_clockfunction onyx_suspendfunction onyx_resumefunction onyx_init_codecfunction onyx_exit_codecfunction onyx_i2c_probefunction onyx_i2c_remove
Annotated Snippet
struct onyx {
/* cache registers 65 to 80, they are write-only! */
u8 cache[16];
struct i2c_client *i2c;
struct aoa_codec codec;
u32 initialised:1,
spdif_locked:1,
analog_locked:1,
original_mute:2;
int open_count;
struct codec_info *codec_info;
/* mutex serializes concurrent access to the device
* and this structure.
*/
struct mutex mutex;
};
#define codec_to_onyx(c) container_of(c, struct onyx, codec)
/* both return 0 if all ok, else on error */
static int onyx_read_register(struct onyx *onyx, u8 reg, u8 *value)
{
s32 v;
if (reg != ONYX_REG_CONTROL) {
*value = onyx->cache[reg-FIRSTREGISTER];
return 0;
}
v = i2c_smbus_read_byte_data(onyx->i2c, reg);
if (v < 0) {
*value = 0;
return -1;
}
*value = (u8)v;
onyx->cache[ONYX_REG_CONTROL-FIRSTREGISTER] = *value;
return 0;
}
static int onyx_write_register(struct onyx *onyx, u8 reg, u8 value)
{
int result;
result = i2c_smbus_write_byte_data(onyx->i2c, reg, value);
if (!result)
onyx->cache[reg-FIRSTREGISTER] = value;
return result;
}
/* alsa stuff */
static int onyx_dev_register(struct snd_device *dev)
{
return 0;
}
static const struct snd_device_ops ops = {
.dev_register = onyx_dev_register,
};
/* this is necessary because most alsa mixer programs
* can't properly handle the negative range */
#define VOLUME_RANGE_SHIFT 128
static int onyx_snd_vol_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 2;
uinfo->value.integer.min = -128 + VOLUME_RANGE_SHIFT;
uinfo->value.integer.max = -1 + VOLUME_RANGE_SHIFT;
return 0;
}
static int onyx_snd_vol_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct onyx *onyx = snd_kcontrol_chip(kcontrol);
s8 l, r;
guard(mutex)(&onyx->mutex);
onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l);
onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r);
ucontrol->value.integer.value[0] = l + VOLUME_RANGE_SHIFT;
ucontrol->value.integer.value[1] = r + VOLUME_RANGE_SHIFT;
return 0;
}
static int onyx_snd_vol_put(struct snd_kcontrol *kcontrol,
Annotation
- Immediate include surface: `linux/delay.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`, `sound/asoundef.h`, `onyx.h`, `../aoa.h`, `../soundbus/soundbus.h`.
- Detected declarations: `struct onyx`, `function onyx_read_register`, `function onyx_write_register`, `function onyx_dev_register`, `function onyx_snd_vol_info`, `function onyx_snd_vol_get`, `function onyx_snd_vol_put`, `function onyx_snd_inputgain_info`, `function onyx_snd_inputgain_get`, `function onyx_snd_inputgain_put`.
- Atlas domain: Driver Families / sound/aoa.
- 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.