// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for Digigram AlpX PCI-e boards * * Copyright (c) 2024 Digigram Digital (info@digigram.com) */ #ifndef _ALPX_CONTROLS_H #define _ALPX_CONTROLS_H #include "alpx.h" #include "alpx_axcmem.h" enum alpx_control_type { ALPX_CONTROL_TYPE_AMPLIFIER = 0, /* Amplification stage*/ ALPX_CONTROL_TYPE_ANALOG_EQ, /* Analog CODEC stage*/ ALPX_CONTROL_TYPE_ROUTER, /* Router stage*/ ALPX_CONTROL_TYPE_MIXER, /* Mixer stage*/ ALPX_CONTROL_TYPE_CHOICE, /* misc controls */ ALPX_CONTROL_TYPE_FLAG, /* boolean controls */ ALPX_CONTROL_TYPE_FLAGS_EMBEDDED, /* Boolean controls embedded with others in the same register*/ ALPX_CONTROL_TYPE_GAINS_EMBEDDED, /* Amplifier controls embedded with others in the same register*/ ALPX_CONTROL_RESERVED, /* RESERVED Control, used to keep NumId if some controls are removed */ ALPX_CONTROL_TYPE_CONSTANT, /* CONSTANT Control, used for a mere constant value */ ALPX_CONTROL_TYPE_AXCMEM_REL_CHOICE, /*AXCM Relativ position Control*/ ALPX_CONTROL_TYPE_AXCMEM_REL_VALUE, /*AXCM Relativ position Control*/ ALPX_CONTROL_TYPE_TRANSLATED_CHOICE, /* Enumerated controls with translation tables for compatibility issue between Apps and FW */ }; struct alpx_control_descriptor_amplifier { const unsigned int* gains_scale; /* Amplifier gains scale for application id cdB (snd_kcontrol_tlv_rw_t*) */ unsigned int reg_gain_min; /* min value for the register value*/ unsigned int reg_gain_max; /* max value for the register value*/ unsigned int lines_count; /* lines of this amplifier */ }; struct alpx_control_descriptor_codec { u32 offset; /* Offset of the associated register */ const unsigned int* gains_scale; /* Amplifier gains scale for application id cdB (snd_kcontrol_tlv_rw_t*) */ unsigned int reg_gain_min; /* min value for the register value*/ unsigned int reg_gain_max; /* max value for the register value*/ unsigned int lines_count; }; struct alpx_control_descriptor_router { unsigned int lines_count; const char **entries; unsigned int entries_count; }; struct alpx_control_descriptor_mixer { const unsigned int* gains_scale; /* Amplifier gains scale for application id cdB (snd_kcontrol_tlv_rw_t*) */ unsigned int reg_gain_min; /* min value for the register value*/ unsigned int reg_gain_max; /* max value for the register value*/ unsigned int lines_count; }; struct alpx_control_descriptor_choice { u32 offset; u32 mask; u32 pos; /* start bit position in the register */ const char **entries; u32 *entries_values; unsigned int entries_count; }; struct alpx_control_descriptor_translated_choice { u32 offset; u32 mask; u32 pos; /* start bit position in the register */ const char **entries; u32 *entries_values; /*Entries in card's context */ unsigned int entries_count; u32* card_entries_values; /*Entries in register's context */ unsigned int card_entries_count; }; struct alpx_control_descriptor_flag { u32 offset; u32 mask; u32 pos; }; struct alpx_control_descriptor_flags_embedded { u32 offset; u32 mask; u32 pos; unsigned int lines_count; }; /* To be used when the amplifier controls are mixed with others in the same register*/ struct alpx_control_descriptor_gains_embedded { const unsigned int* gains_scale; /* Amplifier gains scale for application id cdB (snd_kcontrol_tlv_rw_t*)*/ unsigned int min ; unsigned int max; unsigned int lines_count ; unsigned int offset; unsigned int mask; unsigned int pos; unsigned int width; }; struct alpx_control_descriptor_constant { u32 value; }; struct alpx_control_descriptor_axcmem_rel_choice { struct alpx_axcmem_loc base_loc; struct alpx_axcmem_loc reg_loc; u32 mask; u32 pos; uint32_t (*getter) (void* addr); void (*setter) (void* addr, uint32_t value); const char** entries; u32* entries_values; unsigned int entries_count; }; struct alpx_control_descriptor_axcmem_rel_value { struct alpx_axcmem_loc base_loc; struct alpx_axcmem_loc reg_loc; u32 mask; u32 pos; u32 min; u32 max; uint32_t (*getter) (void* addr); void (*setter) (void* addr, uint32_t value); }; /*****************************************************/ struct alpx_control_descriptor { enum alpx_control_type type; u32 base; const char *prefix; unsigned int access; /*Control access in ALSA way (se https://www.kernel.org/doc/html/v4.17/sound/kernel-api/writing-an-alsa-driver.html?highlight=sndrv_ctl_elem_access_readwrite#access-flags)*/ union { struct alpx_control_descriptor_amplifier ampli; struct alpx_control_descriptor_codec codec; struct alpx_control_descriptor_router router; struct alpx_control_descriptor_mixer mixer; struct alpx_control_descriptor_choice choice; struct alpx_control_descriptor_flag flag; struct alpx_control_descriptor_flags_embedded mic_flags; struct alpx_control_descriptor_gains_embedded mic_gains; struct alpx_control_descriptor_constant constant; struct alpx_control_descriptor_axcmem_rel_choice axcmem_rel_choice; struct alpx_control_descriptor_axcmem_rel_value axcmem_rel_value; struct alpx_control_descriptor_translated_choice translated_choice; } data; }; struct alpx_control_amplifier { unsigned int gain; unsigned int idx; }; struct alpx_control_router { unsigned int index; }; struct alpx_control_mixer { unsigned int mixer_in; unsigned int mixer_out; }; struct alpx_control_codec{ unsigned int idx; }; struct alpx_control_mic { unsigned int stored_gain_in_reg; }; struct alpx_control { struct alpx_control_descriptor *descriptor; union { struct alpx_control_amplifier ampli; struct alpx_control_router router; struct alpx_control_mixer mixer; struct alpx_control_codec codec; struct alpx_control_mic mic; } data; }; int alpx_controls_register(struct snd_card *card); int alp222_mic_controls_default_config(struct alpx_device * alpx_dev); #endif