/* Returns the new gain, which may be lower than the old gain.  */
int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval)
/* Returns the new gain, which may be lower than the old gain.  */
int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval)
{
	const struct ad1843_gain *gp = ad1843_gain[id];
	unsigned short mask = (1 << gp->lfield->nbits) - 1;
	int lg = (newval >> 0) & mask;
	int rg = (newval >> 8) & mask;
	int lm = (lg == 0) ? 1 : 0;
	int rm = (rg == 0) ? 1 : 0;
	if (gp->negative) {
		lg = mask - lg;
		rg = mask - rg;
	}
	if (gp->lmute)
		ad1843_write_multi(ad1843, 2, gp->lmute, lm, gp->rmute, rm);
	ad1843_write_multi(ad1843, 2, gp->lfield, lg, gp->rfield, rg);
	return ad1843_get_gain(ad1843, id);
}