/* P29: The recommended use of programming the external codec through slot 1 and slot 2 data is to use the channels during setup routines and the slot register at any other time. The data written into slot 1, slot 2 and slot 12 registers is transmitted only when their corresponding SI1TxEn, SI2TxEn and SI12TxEn bits are set in the AACI_MAINCR register.  */
static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
/* P29: The recommended use of programming the external codec through slot 1 and slot 2 data is to use the channels during setup routines and the slot register at any other time. The data written into slot 1, slot 2 and slot 12 registers is transmitted only when their corresponding SI1TxEn, SI2TxEn and SI12TxEn bits are set in the AACI_MAINCR register.  */
static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
{
	struct aaci *aaci = ac97->private_data;
	u32 v;
	int timeout = 5000;
	if (ac97->num >= 4)
		return;
	mutex_lock(&aaci->ac97_sem);
	aaci_ac97_select_codec(aaci, ac97);
	writel(val << 4, aaci->base + AACI_SL2TX);
	writel(reg << 12, aaci->base + AACI_SL1TX);
	do {
		v = readl(aaci->base + AACI_SLFR);
	} while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout);
	if (!timeout)
		dev_err(&aaci->dev->dev,
			"timeout waiting for write to complete\n");
	mutex_unlock(&aaci->ac97_sem);
}