// SPDX-License-Identifier: GPL-2.0-or-later
/*
* ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
* AD and DA converters
*
* Copyright (c) 2000-2004 Jaroslav Kysela <perex@perex.cz>,
* Takashi Iwai <tiwai@suse.de>
*/
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/module.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/ak4xxx-adda.h>
#include <sound/info.h>
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>" );
MODULE_DESCRIPTION("Routines for control of AK452x / AK43xx AD/DA converters" );
MODULE_LICENSE("GPL" );
/* write the given register and save the data to the cache */
void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg,
unsigned char val)
{
ak->ops.lock(ak, chip);
ak->ops.write(ak, chip, reg, val);
/* save the data */
snd_akm4xxx_set(ak, chip, reg, val);
ak->ops.unlock(ak, chip);
}
EXPORT_SYMBOL(snd_akm4xxx_write);
/* reset procedure for AK4524 and AK4528 */
static void ak4524_reset(struct snd_akm4xxx *ak, int state)
{
unsigned int chip;
unsigned char reg;
for (chip = 0 ; chip < ak->num_dacs/2 ; chip++) {
snd_akm4xxx_write(ak, chip, 0 x01, state ? 0 x00 : 0 x03);
if (state)
continue ;
/* DAC volumes */
for (reg = 0 x04; reg < ak->total_regs; reg++)
snd_akm4xxx_write(ak, chip, reg,
snd_akm4xxx_get(ak, chip, reg));
}
}
/* reset procedure for AK4355 and AK4358 */
static void ak435X_reset(struct snd_akm4xxx *ak, int state)
{
unsigned char reg;
if (state) {
snd_akm4xxx_write(ak, 0 , 0 x01, 0 x02); /* reset and soft-mute */
return ;
}
for (reg = 0 x00; reg < ak->total_regs; reg++)
if (reg != 0 x01)
snd_akm4xxx_write(ak, 0 , reg,
snd_akm4xxx_get(ak, 0 , reg));
snd_akm4xxx_write(ak, 0 , 0 x01, 0 x01); /* un-reset, unmute */
}
/* reset procedure for AK4381 */
static void ak4381_reset(struct snd_akm4xxx *ak, int state)
{
unsigned int chip;
unsigned char reg;
for (chip = 0 ; chip < ak->num_dacs/2 ; chip++) {
snd_akm4xxx_write(ak, chip, 0 x00, state ? 0 x0c : 0 x0f);
if (state)
continue ;
for (reg = 0 x01; reg < ak->total_regs; reg++)
snd_akm4xxx_write(ak, chip, reg,
snd_akm4xxx_get(ak, chip, reg));
}
}
/*
* reset the AKM codecs
* @state: 1 = reset codec, 0 = restore the registers
*
* assert the reset operation and restores the register values to the chips.
*/
void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
{
switch (ak->type) {
case SND_AK4524:
case SND_AK4528:
case SND_AK4620:
ak4524_reset(ak, state);
break ;
case SND_AK4529:
/* FIXME: needed for ak4529? */
break ;
case SND_AK4355:
ak435X_reset(ak, state);
break ;
case SND_AK4358:
ak435X_reset(ak, state);
break ;
case SND_AK4381:
ak4381_reset(ak, state);
break ;
default :
break ;
}
}
EXPORT_SYMBOL(snd_akm4xxx_reset);
/*
* Volume conversion table for non-linear volumes
* from -63.5dB (mute) to 0dB step 0.5dB
*
* Used for AK4524/AK4620 input/ouput attenuation, AK4528, and
* AK5365 input attenuation
*/
static const unsigned char vol_cvt_datt[128 ] = {
0 x00, 0 x01, 0 x01, 0 x02, 0 x02, 0 x03, 0 x03, 0 x04,
0 x04, 0 x04, 0 x04, 0 x05, 0 x05, 0 x05, 0 x06, 0 x06,
0 x06, 0 x07, 0 x07, 0 x08, 0 x08, 0 x08, 0 x09, 0 x0a,
0 x0a, 0 x0b, 0 x0b, 0 x0c, 0 x0d, 0 x0e, 0 x0f, 0 x0f,
0 x10, 0 x10, 0 x11, 0 x12, 0 x12, 0 x13, 0 x13, 0 x14,
0 x15, 0 x16, 0 x17, 0 x17, 0 x18, 0 x19, 0 x1a, 0 x1c,
0 x1d, 0 x1e, 0 x1f, 0 x20, 0 x21, 0 x22, 0 x23, 0 x23,
0 x24, 0 x25, 0 x26, 0 x28, 0 x29, 0 x2a, 0 x2b, 0 x2d,
0 x2e, 0 x30, 0 x30, 0 x31, 0 x32, 0 x33, 0 x34, 0 x35,
0 x37, 0 x38, 0 x39, 0 x3b, 0 x3c, 0 x3e, 0 x3f, 0 x40,
0 x41, 0 x42, 0 x43, 0 x44, 0 x46, 0 x47, 0 x48, 0 x4a,
0 x4b, 0 x4d, 0 x4e, 0 x50, 0 x51, 0 x52, 0 x53, 0 x54,
0 x55, 0 x56, 0 x58, 0 x59, 0 x5b, 0 x5c, 0 x5e, 0 x5f,
0 x60, 0 x61, 0 x62, 0 x64, 0 x65, 0 x66, 0 x67, 0 x69,
0 x6a, 0 x6c, 0 x6d, 0 x6f, 0 x70, 0 x71, 0 x72, 0 x73,
0 x75, 0 x76, 0 x77, 0 x79, 0 x7a, 0 x7c, 0 x7d, 0 x7f,
};
/*
* dB tables
*/
static const DECLARE_TLV_DB_SCALE(db_scale_vol_datt, -6350 , 50 , 1 );
static const DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750 , 50 , 1 );
static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350 , 50 , 1 );
static const DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0 );
/*
* initialize all the ak4xxx chips
*/
void snd_akm4xxx_init(struct snd_akm4xxx *ak)
{
static const unsigned char inits_ak4524[] = {
0 x00, 0 x07, /* 0: all power up */
0 x01, 0 x00, /* 1: ADC/DAC reset */
0 x02, 0 x60, /* 2: 24bit I2S */
0 x03, 0 x19, /* 3: deemphasis off */
0 x01, 0 x03, /* 1: ADC/DAC enable */
0 x04, 0 x00, /* 4: ADC left muted */
0 x05, 0 x00, /* 5: ADC right muted */
0 x06, 0 x00, /* 6: DAC left muted */
0 x07, 0 x00, /* 7: DAC right muted */
0 xff, 0 xff
};
static const unsigned char inits_ak4528[] = {
0 x00, 0 x07, /* 0: all power up */
0 x01, 0 x00, /* 1: ADC/DAC reset */
0 x02, 0 x60, /* 2: 24bit I2S */
0 x03, 0 x0d, /* 3: deemphasis off, turn LR highpass filters on */
0 x01, 0 x03, /* 1: ADC/DAC enable */
0 x04, 0 x00, /* 4: ADC left muted */
0 x05, 0 x00, /* 5: ADC right muted */
0 xff, 0 xff
};
static const unsigned char inits_ak4529[] = {
0 x09, 0 x01, /* 9: ATS=0, RSTN=1 */
0 x0a, 0 x3f, /* A: all power up, no zero/overflow detection */
0 x00, 0 x0c, /* 0: TDM=0, 24bit I2S, SMUTE=0 */
0 x01, 0 x00, /* 1: ACKS=0, ADC, loop off */
0 x02, 0 xff, /* 2: LOUT1 muted */
0 x03, 0 xff, /* 3: ROUT1 muted */
0 x04, 0 xff, /* 4: LOUT2 muted */
0 x05, 0 xff, /* 5: ROUT2 muted */
0 x06, 0 xff, /* 6: LOUT3 muted */
0 x07, 0 xff, /* 7: ROUT3 muted */
0 x0b, 0 xff, /* B: LOUT4 muted */
0 x0c, 0 xff, /* C: ROUT4 muted */
0 x08, 0 x55, /* 8: deemphasis all off */
0 xff, 0 xff
};
static const unsigned char inits_ak4355[] = {
0 x01, 0 x02, /* 1: reset and soft-mute */
0 x00, 0 x06, /* 0: mode3(i2s), disable auto-clock detect,
* disable DZF, sharp roll-off, RSTN#=0 */
0 x02, 0 x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
// 0x02, 0x2e, /* quad speed */
0 x03, 0 x01, /* 3: de-emphasis off */
0 x04, 0 x00, /* 4: LOUT1 volume muted */
0 x05, 0 x00, /* 5: ROUT1 volume muted */
0 x06, 0 x00, /* 6: LOUT2 volume muted */
0 x07, 0 x00, /* 7: ROUT2 volume muted */
0 x08, 0 x00, /* 8: LOUT3 volume muted */
0 x09, 0 x00, /* 9: ROUT3 volume muted */
0 x0a, 0 x00, /* a: DATT speed=0, ignore DZF */
0 x01, 0 x01, /* 1: un-reset, unmute */
0 xff, 0 xff
};
static const unsigned char inits_ak4358[] = {
0 x01, 0 x02, /* 1: reset and soft-mute */
0 x00, 0 x06, /* 0: mode3(i2s), disable auto-clock detect,
* disable DZF, sharp roll-off, RSTN#=0 */
0 x02, 0 x4e, /* 2: DA's power up, normal speed, RSTN#=0 */
/* 0x02, 0x6e,*/ /* quad speed */
0 x03, 0 x01, /* 3: de-emphasis off */
0 x04, 0 x00, /* 4: LOUT1 volume muted */
0 x05, 0 x00, /* 5: ROUT1 volume muted */
0 x06, 0 x00, /* 6: LOUT2 volume muted */
0 x07, 0 x00, /* 7: ROUT2 volume muted */
0 x08, 0 x00, /* 8: LOUT3 volume muted */
0 x09, 0 x00, /* 9: ROUT3 volume muted */
0 x0b, 0 x00, /* b: LOUT4 volume muted */
0 x0c, 0 x00, /* c: ROUT4 volume muted */
0 x0a, 0 x00, /* a: DATT speed=0, ignore DZF */
0 x01, 0 x01, /* 1: un-reset, unmute */
0 xff, 0 xff
};
static const unsigned char inits_ak4381[] = {
0 x00, 0 x0c, /* 0: mode3(i2s), disable auto-clock detect */
0 x01, 0 x02, /* 1: de-emphasis off, normal speed,
* sharp roll-off, DZF off */
// 0x01, 0x12, /* quad speed */
0 x02, 0 x00, /* 2: DZF disabled */
0 x03, 0 x00, /* 3: LATT 0 */
0 x04, 0 x00, /* 4: RATT 0 */
0 x00, 0 x0f, /* 0: power-up, un-reset */
0 xff, 0 xff
};
static const unsigned char inits_ak4620[] = {
0 x00, 0 x07, /* 0: normal */
0 x01, 0 x00, /* 0: reset */
0 x01, 0 x02, /* 1: RSTAD */
0 x01, 0 x03, /* 1: RSTDA */
0 x01, 0 x0f, /* 1: normal */
0 x02, 0 x60, /* 2: 24bit I2S */
0 x03, 0 x01, /* 3: deemphasis off */
0 x04, 0 x00, /* 4: LIN muted */
0 x05, 0 x00, /* 5: RIN muted */
0 x06, 0 x00, /* 6: LOUT muted */
0 x07, 0 x00, /* 7: ROUT muted */
0 xff, 0 xff
};
int chip;
const unsigned char *ptr, *inits;
unsigned char reg, data;
memset(ak->images, 0 , sizeof (ak->images));
memset(ak->volumes, 0 , sizeof (ak->volumes));
switch (ak->type) {
case SND_AK4524:
inits = inits_ak4524;
ak->num_chips = ak->num_dacs / 2 ;
ak->name = "ak4524" ;
ak->total_regs = 0 x08;
break ;
case SND_AK4528:
inits = inits_ak4528;
ak->num_chips = ak->num_dacs / 2 ;
ak->name = "ak4528" ;
ak->total_regs = 0 x06;
break ;
case SND_AK4529:
inits = inits_ak4529;
ak->num_chips = 1 ;
ak->name = "ak4529" ;
ak->total_regs = 0 x0d;
break ;
case SND_AK4355:
inits = inits_ak4355;
ak->num_chips = 1 ;
ak->name = "ak4355" ;
ak->total_regs = 0 x0b;
break ;
case SND_AK4358:
inits = inits_ak4358;
ak->num_chips = 1 ;
ak->name = "ak4358" ;
ak->total_regs = 0 x10;
break ;
case SND_AK4381:
inits = inits_ak4381;
ak->num_chips = ak->num_dacs / 2 ;
ak->name = "ak4381" ;
ak->total_regs = 0 x05;
break ;
case SND_AK5365:
/* FIXME: any init sequence? */
ak->num_chips = 1 ;
ak->name = "ak5365" ;
ak->total_regs = 0 x08;
return ;
case SND_AK4620:
inits = inits_ak4620;
ak->num_chips = ak->num_dacs / 2 ;
ak->name = "ak4620" ;
ak->total_regs = 0 x08;
break ;
default :
snd_BUG();
return ;
}
for (chip = 0 ; chip < ak->num_chips; chip++) {
ptr = inits;
while (*ptr != 0 xff) {
reg = *ptr++;
data = *ptr++;
snd_akm4xxx_write(ak, chip, reg, data);
udelay(10 );
}
}
}
EXPORT_SYMBOL(snd_akm4xxx_init);
/*
* Mixer callbacks
*/
#define AK_IPGA (1 <<20 ) /* including IPGA */
#define AK_VOL_CVT (1 <<21 ) /* need dB conversion */
#define AK_NEEDSMSB (1 <<22 ) /* need MSB update bit */
#define AK_INVERT (1 <<23 ) /* data is inverted */
#define AK_GET_CHIP(val) (((val) >> 8 ) & 0 xff)
#define AK_GET_ADDR(val) ((val) & 0 xff)
#define AK_GET_SHIFT(val) (((val) >> 16 ) & 0 x0f)
#define AK_GET_VOL_CVT(val) (((val) >> 21 ) & 1 )
#define AK_GET_IPGA(val) (((val) >> 20 ) & 1 )
#define AK_GET_NEEDSMSB(val) (((val) >> 22 ) & 1 )
#define AK_GET_INVERT(val) (((val) >> 23 ) & 1 )
#define AK_GET_MASK(val) (((val) >> 24 ) & 0 xff)
#define AK_COMPOSE(chip,addr,shift,mask) \
(((chip) << 8 ) | (addr) | ((shift) << 16 ) | ((mask) << 24 ))
static int snd_akm4xxx_volume_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
unsigned int mask = AK_GET_MASK(kcontrol->private_value);
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1 ;
uinfo->value.integer.min = 0 ;
uinfo->value.integer.max = mask;
return 0 ;
}
static int snd_akm4xxx_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
ucontrol->value.integer.value[0 ] = snd_akm4xxx_get_vol(ak, chip, addr);
return 0 ;
}
static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
unsigned char nval)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
unsigned int mask = AK_GET_MASK(kcontrol->private_value);
int chip = AK_GET_CHIP(kcontrol->private_value);
if (snd_akm4xxx_get_vol(ak, chip, addr) == nval)
return 0 ;
snd_akm4xxx_set_vol(ak, chip, addr, nval);
if (AK_GET_VOL_CVT(kcontrol->private_value) && nval < 128 )
nval = vol_cvt_datt[nval];
if (AK_GET_IPGA(kcontrol->private_value) && nval >= 128 )
nval++; /* need to correct + 1 since both 127 and 128 are 0dB */
if (AK_GET_INVERT(kcontrol->private_value))
nval = mask - nval;
if (AK_GET_NEEDSMSB(kcontrol->private_value))
nval |= 0 x80;
snd_akm4xxx_write(ak, chip, addr, nval);
return 1 ;
}
static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
unsigned int mask = AK_GET_MASK(kcontrol->private_value);
unsigned int val = ucontrol->value.integer.value[0 ];
if (val > mask)
return -EINVAL;
return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value), val);
}
static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
unsigned int mask = AK_GET_MASK(kcontrol->private_value);
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 2 ;
uinfo->value.integer.min = 0 ;
uinfo->value.integer.max = mask;
return 0 ;
}
static int snd_akm4xxx_stereo_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
ucontrol->value.integer.value[0 ] = snd_akm4xxx_get_vol(ak, chip, addr);
ucontrol->value.integer.value[1 ] = snd_akm4xxx_get_vol(ak, chip, addr+1 );
return 0 ;
}
static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
int addr = AK_GET_ADDR(kcontrol->private_value);
unsigned int mask = AK_GET_MASK(kcontrol->private_value);
unsigned int val[2 ];
int change;
val[0 ] = ucontrol->value.integer.value[0 ];
val[1 ] = ucontrol->value.integer.value[1 ];
if (val[0 ] > mask || val[1 ] > mask)
return -EINVAL;
change = put_ak_reg(kcontrol, addr, val[0 ]);
change |= put_ak_reg(kcontrol, addr + 1 , val[1 ]);
return change;
}
static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
static const char * const texts[4 ] = {
"44.1kHz" , "Off" , "48kHz" , "32kHz" ,
};
return snd_ctl_enum_info(uinfo, 1 , 4 , texts);
}
static int snd_akm4xxx_deemphasis_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int shift = AK_GET_SHIFT(kcontrol->private_value);
ucontrol->value.enumerated.item[0 ] =
(snd_akm4xxx_get(ak, chip, addr) >> shift) & 3 ;
return 0 ;
}
static int snd_akm4xxx_deemphasis_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int shift = AK_GET_SHIFT(kcontrol->private_value);
unsigned char nval = ucontrol->value.enumerated.item[0 ] & 3 ;
int change;
nval = (nval << shift) |
(snd_akm4xxx_get(ak, chip, addr) & ~(3 << shift));
change = snd_akm4xxx_get(ak, chip, addr) != nval;
if (change)
snd_akm4xxx_write(ak, chip, addr, nval);
return change;
}
#define ak4xxx_switch_info snd_ctl_boolean_mono_info
static int ak4xxx_switch_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int shift = AK_GET_SHIFT(kcontrol->private_value);
int invert = AK_GET_INVERT(kcontrol->private_value);
/* we observe the (1<<shift) bit only */
unsigned char val = snd_akm4xxx_get(ak, chip, addr) & (1 <<shift);
if (invert)
val = ! val;
ucontrol->value.integer.value[0 ] = (val & (1 <<shift)) != 0 ;
return 0 ;
}
static int ak4xxx_switch_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int shift = AK_GET_SHIFT(kcontrol->private_value);
int invert = AK_GET_INVERT(kcontrol->private_value);
long flag = ucontrol->value.integer.value[0 ];
unsigned char val, oval;
int change;
if (invert)
flag = ! flag;
oval = snd_akm4xxx_get(ak, chip, addr);
if (flag)
val = oval | (1 <<shift);
else
val = oval & ~(1 <<shift);
change = (oval != val);
if (change)
snd_akm4xxx_write(ak, chip, addr, val);
return change;
}
#define AK5365_NUM_INPUTS 5
static int ak4xxx_capture_num_inputs(struct snd_akm4xxx *ak, int mixer_ch)
{
int num_names;
const char **input_names;
input_names = ak->adc_info[mixer_ch].input_names;
num_names = 0 ;
while (num_names < AK5365_NUM_INPUTS && input_names[num_names])
++num_names;
return num_names;
}
static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int mixer_ch = AK_GET_SHIFT(kcontrol->private_value);
unsigned int num_names;
num_names = ak4xxx_capture_num_inputs(ak, mixer_ch);
if (!num_names)
return -EINVAL;
return snd_ctl_enum_info(uinfo, 1 , num_names,
ak->adc_info[mixer_ch].input_names);
}
static int ak4xxx_capture_source_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int mask = AK_GET_MASK(kcontrol->private_value);
unsigned char val;
val = snd_akm4xxx_get(ak, chip, addr) & mask;
ucontrol->value.enumerated.item[0 ] = val;
return 0 ;
}
static int ak4xxx_capture_source_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
int mixer_ch = AK_GET_SHIFT(kcontrol->private_value);
int chip = AK_GET_CHIP(kcontrol->private_value);
int addr = AK_GET_ADDR(kcontrol->private_value);
int mask = AK_GET_MASK(kcontrol->private_value);
unsigned char oval, val;
int num_names = ak4xxx_capture_num_inputs(ak, mixer_ch);
if (ucontrol->value.enumerated.item[0 ] >= num_names)
return -EINVAL;
oval = snd_akm4xxx_get(ak, chip, addr);
val = oval & ~mask;
val |= ucontrol->value.enumerated.item[0 ] & mask;
if (val != oval) {
snd_akm4xxx_write(ak, chip, addr, val);
return 1 ;
}
return 0 ;
}
/*
* build AK4xxx controls
*/
static int build_dac_controls(struct snd_akm4xxx *ak)
{
int idx, err, mixer_ch, num_stereo;
struct snd_kcontrol_new knew;
mixer_ch = 0 ;
for (idx = 0 ; idx < ak->num_dacs; ) {
/* mute control for Revolution 7.1 - AK4381 */
if (ak->type == SND_AK4381
&& ak->dac_info[mixer_ch].switch_name) {
memset(&knew, 0 , sizeof (knew));
knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
knew.count = 1 ;
knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
knew.name = ak->dac_info[mixer_ch].switch_name;
knew.info = ak4xxx_switch_info;
knew.get = ak4xxx_switch_get;
knew.put = ak4xxx_switch_put;
knew.access = 0 ;
/* register 1, bit 0 (SMUTE): 0 = normal operation,
1 = mute */
knew.private_value =
AK_COMPOSE(idx/2 , 1 , 0 , 0 ) | AK_INVERT;
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
}
memset(&knew, 0 , sizeof (knew));
if (! ak->dac_info || ! ak->dac_info[mixer_ch].name) {
knew.name = "DAC Volume" ;
knew.index = mixer_ch + ak->idx_offset * 2 ;
num_stereo = 1 ;
} else {
knew.name = ak->dac_info[mixer_ch].name;
num_stereo = ak->dac_info[mixer_ch].num_channels;
}
knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
knew.count = 1 ;
knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ;
if (num_stereo == 2 ) {
knew.info = snd_akm4xxx_stereo_volume_info;
knew.get = snd_akm4xxx_stereo_volume_get;
knew.put = snd_akm4xxx_stereo_volume_put;
} else {
knew.info = snd_akm4xxx_volume_info;
knew.get = snd_akm4xxx_volume_get;
knew.put = snd_akm4xxx_volume_put;
}
switch (ak->type) {
case SND_AK4524:
/* register 6 & 7 */
knew.private_value =
AK_COMPOSE(idx/2 , (idx%2 ) + 6 , 0 , 127 ) |
AK_VOL_CVT;
knew.tlv.p = db_scale_vol_datt;
break ;
case SND_AK4528:
/* register 4 & 5 */
knew.private_value =
AK_COMPOSE(idx/2 , (idx%2 ) + 4 , 0 , 127 ) |
AK_VOL_CVT;
knew.tlv.p = db_scale_vol_datt;
break ;
case SND_AK4529: {
/* registers 2-7 and b,c */
int val = idx < 6 ? idx + 2 : (idx - 6 ) + 0 xb;
knew.private_value =
AK_COMPOSE(0 , val, 0 , 255 ) | AK_INVERT;
knew.tlv.p = db_scale_8bit;
break ;
}
case SND_AK4355:
/* register 4-9, chip #0 only */
knew.private_value = AK_COMPOSE(0 , idx + 4 , 0 , 255 );
knew.tlv.p = db_scale_8bit;
break ;
case SND_AK4358: {
/* register 4-9 and 11-12, chip #0 only */
int addr = idx < 6 ? idx + 4 : idx + 5 ;
knew.private_value =
AK_COMPOSE(0 , addr, 0 , 127 ) | AK_NEEDSMSB;
knew.tlv.p = db_scale_7bit;
break ;
}
case SND_AK4381:
/* register 3 & 4 */
knew.private_value =
AK_COMPOSE(idx/2 , (idx%2 ) + 3 , 0 , 255 );
knew.tlv.p = db_scale_linear;
break ;
case SND_AK4620:
/* register 6 & 7 */
knew.private_value =
AK_COMPOSE(idx/2 , (idx%2 ) + 6 , 0 , 255 );
knew.tlv.p = db_scale_linear;
break ;
default :
return -EINVAL;
}
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
idx += num_stereo;
mixer_ch++;
}
return 0 ;
}
static int build_adc_controls(struct snd_akm4xxx *ak)
{
int idx, err, mixer_ch, num_stereo, max_steps;
struct snd_kcontrol_new knew;
mixer_ch = 0 ;
if (ak->type == SND_AK4528)
return 0 ; /* no controls */
for (idx = 0 ; idx < ak->num_adcs;) {
memset(&knew, 0 , sizeof (knew));
if (! ak->adc_info || ! ak->adc_info[mixer_ch].name) {
knew.name = "ADC Volume" ;
knew.index = mixer_ch + ak->idx_offset * 2 ;
num_stereo = 1 ;
} else {
knew.name = ak->adc_info[mixer_ch].name;
num_stereo = ak->adc_info[mixer_ch].num_channels;
}
knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
knew.count = 1 ;
knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ;
if (num_stereo == 2 ) {
knew.info = snd_akm4xxx_stereo_volume_info;
knew.get = snd_akm4xxx_stereo_volume_get;
knew.put = snd_akm4xxx_stereo_volume_put;
} else {
knew.info = snd_akm4xxx_volume_info;
knew.get = snd_akm4xxx_volume_get;
knew.put = snd_akm4xxx_volume_put;
}
/* register 4 & 5 */
if (ak->type == SND_AK5365)
max_steps = 152 ;
else
max_steps = 164 ;
knew.private_value =
AK_COMPOSE(idx/2 , (idx%2 ) + 4 , 0 , max_steps) |
AK_VOL_CVT | AK_IPGA;
knew.tlv.p = db_scale_vol_datt;
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
if (ak->type == SND_AK5365 && (idx % 2 ) == 0 ) {
if (! ak->adc_info ||
! ak->adc_info[mixer_ch].switch_name) {
knew.name = "Capture Switch" ;
knew.index = mixer_ch + ak->idx_offset * 2 ;
} else
knew.name = ak->adc_info[mixer_ch].switch_name;
knew.info = ak4xxx_switch_info;
knew.get = ak4xxx_switch_get;
knew.put = ak4xxx_switch_put;
knew.access = 0 ;
/* register 2, bit 0 (SMUTE): 0 = normal operation,
1 = mute */
knew.private_value =
AK_COMPOSE(idx/2 , 2 , 0 , 0 ) | AK_INVERT;
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
memset(&knew, 0 , sizeof (knew));
if (!ak->adc_info ||
!ak->adc_info[mixer_ch].selector_name) {
knew.name = "Capture Channel" ;
knew.index = mixer_ch + ak->idx_offset * 2 ;
} else
knew.name = ak->adc_info[mixer_ch].selector_name;
knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
knew.info = ak4xxx_capture_source_info;
knew.get = ak4xxx_capture_source_get;
knew.put = ak4xxx_capture_source_put;
knew.access = 0 ;
/* input selector control: reg. 1, bits 0-2.
* mis-use 'shift' to pass mixer_ch */
knew.private_value
= AK_COMPOSE(idx/2 , 1 , mixer_ch, 0 x07);
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
}
idx += num_stereo;
mixer_ch++;
}
return 0 ;
}
static int build_deemphasis(struct snd_akm4xxx *ak, int num_emphs)
{
int idx, err;
struct snd_kcontrol_new knew;
for (idx = 0 ; idx < num_emphs; idx++) {
memset(&knew, 0 , sizeof (knew));
knew.name = "Deemphasis" ;
knew.index = idx + ak->idx_offset;
knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
knew.count = 1 ;
knew.info = snd_akm4xxx_deemphasis_info;
knew.get = snd_akm4xxx_deemphasis_get;
knew.put = snd_akm4xxx_deemphasis_put;
switch (ak->type) {
case SND_AK4524:
case SND_AK4528:
case SND_AK4620:
/* register 3 */
knew.private_value = AK_COMPOSE(idx, 3 , 0 , 0 );
break ;
case SND_AK4529: {
int shift = idx == 3 ? 6 : (2 - idx) * 2 ;
/* register 8 with shift */
knew.private_value = AK_COMPOSE(0 , 8 , shift, 0 );
break ;
}
case SND_AK4355:
case SND_AK4358:
knew.private_value = AK_COMPOSE(idx, 3 , 0 , 0 );
break ;
case SND_AK4381:
knew.private_value = AK_COMPOSE(idx, 1 , 1 , 0 );
break ;
default :
return -EINVAL;
}
err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
if (err < 0 )
return err;
}
return 0 ;
}
static void proc_regs_read(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct snd_akm4xxx *ak = entry->private_data;
int reg, val, chip;
for (chip = 0 ; chip < ak->num_chips; chip++) {
for (reg = 0 ; reg < ak->total_regs; reg++) {
val = snd_akm4xxx_get(ak, chip, reg);
snd_iprintf(buffer, "chip %d: 0x%02x = 0x%02x\n" , chip,
reg, val);
}
}
}
static int proc_init(struct snd_akm4xxx *ak)
{
return snd_card_ro_proc_new(ak->card, ak->name, ak, proc_regs_read);
}
int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
{
int err, num_emphs;
err = build_dac_controls(ak);
if (err < 0 )
return err;
err = build_adc_controls(ak);
if (err < 0 )
return err;
if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
num_emphs = 1 ;
else if (ak->type == SND_AK4620)
num_emphs = 0 ;
else
num_emphs = ak->num_dacs / 2 ;
err = build_deemphasis(ak, num_emphs);
if (err < 0 )
return err;
err = proc_init(ak);
if (err < 0 )
return err;
return 0 ;
}
EXPORT_SYMBOL(snd_akm4xxx_build_controls);
Messung V0.5 in Prozent C=96 H=90 G=93
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-08)
¤
*© Formatika GbR, Deutschland