Пример #1
0
static int snd_akm4xxx_stereo_volume_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 invert = AK_GET_INVERT(kcontrol->private_value);
	unsigned int mask = AK_GET_MASK(kcontrol->private_value);
	unsigned char nval = ucontrol->value.integer.value[0] % (mask+1);
	int change0, change1;

	if (invert)
		nval = mask - nval;
	change0 = snd_akm4xxx_get(ak, chip, addr) != nval;
	if (change0)
		snd_akm4xxx_write(ak, chip, addr, nval);

	nval = ucontrol->value.integer.value[1] % (mask+1);
	if (invert)
		nval = mask - nval;
	change1 = snd_akm4xxx_get(ak, chip, addr+1) != nval;
	if (change1)
		snd_akm4xxx_write(ak, chip, addr+1, nval);


	return change0 || change1;
}
Пример #2
0
/*
 * change the rate of AK4524 on VX442
 */
static void vx442_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
{
	unsigned char val;

	val = (rate > 48000) ? 0x65 : 0x60;
	if (snd_akm4xxx_get(ak, 0, 0x02) != val ||
	    snd_akm4xxx_get(ak, 1, 0x02) != val) {
		snd_akm4xxx_reset(ak, 1);
		snd_akm4xxx_write(ak, 0, 0x02, val);
		snd_akm4xxx_write(ak, 1, 0x02, val);
		snd_akm4xxx_reset(ak, 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;
}
Пример #4
0
/* reset procedure for AK4524 and AK4528 */
static void ak4524_reset(struct snd_akm4xxx *ak, int state)
{
	unsigned int chip;
	unsigned char reg, maxreg;

	if (ak->type == SND_AK4528)
		maxreg = 0x06;
	else
		maxreg = 0x08;
	for (chip = 0; chip < ak->num_dacs/2; chip++) {
		snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
		if (state)
			continue;
		/* DAC volumes */
		for (reg = 0x04; reg < maxreg; reg++)
			snd_akm4xxx_write(ak, chip, reg,
					  snd_akm4xxx_get(ak, chip, reg));
		if (ak->type == SND_AK4528)
			continue;
		/* IPGA */
		for (reg = 0x04; reg < 0x06; reg++)
			snd_akm4xxx_write(ak, chip, reg,
					  snd_akm4xxx_get_ipga(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)
{
	unsigned int chip;
	unsigned char reg;
	
	switch (ak->type) {
	case SND_AK4524:
	case SND_AK4528:
		for (chip = 0; chip < ak->num_dacs/2; chip++) {
			snd_akm4xxx_write(ak, chip, 0x01, state ? 0x00 : 0x03);
			if (state)
				continue;
			/* DAC volumes */
			for (reg = 0x04; reg < (ak->type == SND_AK4528 ? 0x06 : 0x08); reg++)
				snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
			if (ak->type == SND_AK4528)
				continue;
			/* IPGA */
			for (reg = 0x04; reg < 0x06; reg++)
				snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get_ipga(ak, chip, reg));
		}
		break;
	case SND_AK4529:
		/* FIXME: needed for ak4529? */
		break;
	case SND_AK4355:
	case SND_AK4358:
		if (state) {
			snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
			return;
		}
		for (reg = 0x00; reg < 0x0b; reg++)
			if (reg != 0x01)
				snd_akm4xxx_write(ak, 0, reg, snd_akm4xxx_get(ak, 0, reg));
		snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
		break;
	case SND_AK4381:
		for (chip = 0; chip < ak->num_dacs/2; chip++) {
			snd_akm4xxx_write(ak, chip, 0x00, state ? 0x0c : 0x0f);
			if (state)
				continue;
			for (reg = 0x01; reg < 0x05; reg++)
				snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg));
		}
		break;
	}
}
Пример #6
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);
	int invert = AK_GET_INVERT(kcontrol->private_value);
	unsigned int mask = AK_GET_MASK(kcontrol->private_value);
	unsigned char val = snd_akm4xxx_get(ak, chip, addr);
	
	ucontrol->value.integer.value[0] = invert ? mask - val : val;

	val = snd_akm4xxx_get(ak, chip, addr+1);
	ucontrol->value.integer.value[1] = invert ? mask - val : val;

	return 0;
}
Пример #7
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);
		}
	}
}
Пример #8
0
/* 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, 0x00, state ? 0x0c : 0x0f);
		if (state)
			continue;
		for (reg = 0x01; reg < ak->total_regs; reg++)
			snd_akm4xxx_write(ak, chip, reg,
					  snd_akm4xxx_get(ak, chip, reg));
	}
}
Пример #9
0
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;
}
Пример #10
0
/* 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, 0x01, 0x02); /* reset and soft-mute */
		return;
	}
	for (reg = 0x00; reg < ak->total_regs; reg++)
		if (reg != 0x01)
			snd_akm4xxx_write(ak, 0, reg,
					  snd_akm4xxx_get(ak, 0, reg));
	snd_akm4xxx_write(ak, 0, 0x01, 0x01); /* un-reset, unmute */
}
Пример #11
0
/* 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, 0x01, state ? 0x00 : 0x03);
		if (state)
			continue;
		/* DAC volumes */
		for (reg = 0x04; reg < ak->total_regs; reg++)
			snd_akm4xxx_write(ak, chip, reg,
					  snd_akm4xxx_get(ak, chip, reg));
	}
}
Пример #12
0
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;
}
Пример #13
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;
}
Пример #14
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;
}
Пример #15
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 |= 0x80;
#ifdef CONFIG_DEBUG_PRINTK
	/* printk(KERN_DEBUG "DEBUG - AK writing reg: chip %x addr %x,
	   nval %x\n", chip, addr, nval); */
#else
	/* ;
#endif
	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 char *texts[4] = {
		"44.1kHz", "Off", "48kHz", "32kHz",
	};
	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 4;
	if (uinfo->value.enumerated.item >= 4)
		uinfo->value.enumerated.item = 3;
	strcpy(uinfo->value.enumerated.name,
	       texts[uinfo->value.enumerated.item]);
	return 0;
}

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;
}