#include <linux/delay.h>
#include <linux/init.h>
#include <linux/slab.h>
+#include <linux/mutex.h>
+
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/control.h>
},
},
{
- /* FIXME: double rates */
+ /* double rates */
{
- /* 3&4 front, 7&8 rear, 6&9 center/lfe */
+ /* 3&4 front, 7&8 front (t+1) */
AC97_PCM_FRONT_DAC_RATE, /* slot 3 */
AC97_PCM_FRONT_DAC_RATE, /* slot 4 */
0xff, /* slot 5 */
- AC97_PCM_LFE_DAC_RATE, /* slot 6 */
- AC97_PCM_SURR_DAC_RATE, /* slot 7 */
- AC97_PCM_SURR_DAC_RATE, /* slot 8 */
- AC97_PCM_LFE_DAC_RATE, /* slot 9 */
+ 0xff, /* slot 6 */
+ AC97_PCM_FRONT_DAC_RATE, /* slot 7 */
+ AC97_PCM_FRONT_DAC_RATE, /* slot 8 */
+ 0xff, /* slot 9 */
0xff, /* slot 10 */
0xff, /* slot 11 */
},
{
- /* 7&8 front, 6&9 rear, 10&11 center/lfe */
+ /* not specified in the specification */
0xff, /* slot 3 */
0xff, /* slot 4 */
0xff, /* slot 5 */
- AC97_PCM_SURR_DAC_RATE, /* slot 6 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 7 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 8 */
- AC97_PCM_SURR_DAC_RATE, /* slot 9 */
- AC97_PCM_LFE_DAC_RATE, /* slot 10 */
- AC97_PCM_LFE_DAC_RATE, /* slot 11 */
+ 0xff, /* slot 6 */
+ 0xff, /* slot 7 */
+ 0xff, /* slot 8 */
+ 0xff, /* slot 9 */
+ 0xff, /* slot 10 */
+ 0xff, /* slot 11 */
},
{
- /* 6&9 front, 10&11 rear, 3&4 center/lfe */
- AC97_PCM_LFE_DAC_RATE, /* slot 3 */
- AC97_PCM_LFE_DAC_RATE, /* slot 4 */
+ 0xff, /* slot 3 */
+ 0xff, /* slot 4 */
0xff, /* slot 5 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 6 */
+ 0xff, /* slot 6 */
0xff, /* slot 7 */
0xff, /* slot 8 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 9 */
- AC97_PCM_SURR_DAC_RATE, /* slot 10 */
- AC97_PCM_SURR_DAC_RATE, /* slot 11 */
+ 0xff, /* slot 9 */
+ 0xff, /* slot 10 */
+ 0xff, /* slot 11 */
},
{
- /* 10&11 front, 3&4 rear, 7&8 center/lfe */
- AC97_PCM_SURR_DAC_RATE, /* slot 3 */
- AC97_PCM_SURR_DAC_RATE, /* slot 4 */
+ 0xff, /* slot 3 */
+ 0xff, /* slot 4 */
0xff, /* slot 5 */
0xff, /* slot 6 */
- AC97_PCM_LFE_DAC_RATE, /* slot 7 */
- AC97_PCM_LFE_DAC_RATE, /* slot 8 */
+ 0xff, /* slot 7 */
+ 0xff, /* slot 8 */
0xff, /* slot 9 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 10 */
- AC97_PCM_FRONT_DAC_RATE, /* slot 11 */
+ 0xff, /* slot 10 */
+ 0xff, /* slot 11 */
}
}};
return rate_cregs[slot - 3];
}
-static int set_spdif_rate(ac97_t *ac97, unsigned short rate)
+static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate)
{
unsigned short old, bits, reg, mask;
unsigned int sbits;
if (! (ac97->ext_id & AC97_EI_SPDIF))
return -ENODEV;
+ /* TODO: double rate support */
if (ac97->flags & AC97_CS_SPDIF) {
switch (rate) {
case 48000: bits = 0; break;
mask = AC97_SC_SPSR_MASK;
}
- spin_lock(&ac97->reg_lock);
+ mutex_lock(&ac97->reg_mutex);
old = snd_ac97_read(ac97, reg) & mask;
- spin_unlock(&ac97->reg_lock);
if (old != bits) {
- snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
- snd_ac97_update_bits(ac97, reg, mask, bits);
+ snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
+ snd_ac97_update_bits_nolock(ac97, reg, mask, bits);
/* update the internal spdif bits */
- spin_lock(&ac97->reg_lock);
sbits = ac97->spdif_status;
if (sbits & IEC958_AES0_PROFESSIONAL) {
sbits &= ~IEC958_AES0_PRO_FS;
}
}
ac97->spdif_status = sbits;
- spin_unlock(&ac97->reg_lock);
}
- snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
+ snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
+ mutex_unlock(&ac97->reg_mutex);
return 0;
}
*
* Returns zero if successful, or a negative error code on failure.
*/
-int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned short rate)
+int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate)
{
+ int dbl;
unsigned int tmp;
+ dbl = rate > 48000;
+ if (dbl) {
+ if (!(ac97->flags & AC97_DOUBLE_RATE))
+ return -EINVAL;
+ if (reg != AC97_PCM_FRONT_DAC_RATE)
+ return -EINVAL;
+ }
+
+ snd_ac97_update_power(ac97, reg, 1);
switch (reg) {
case AC97_PCM_MIC_ADC_RATE:
if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRM) == 0) /* MIC VRA */
case AC97_PCM_FRONT_DAC_RATE:
case AC97_PCM_LR_ADC_RATE:
if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRA) == 0) /* VRA */
- if (rate != 48000)
+ if (rate != 48000 && rate != 96000)
return -EINVAL;
break;
case AC97_PCM_SURR_DAC_RATE:
default:
return -EINVAL;
}
- tmp = ((unsigned int)rate * ac97->bus->clock) / 48000;
+ if (dbl)
+ rate /= 2;
+ tmp = (rate * ac97->bus->clock) / 48000;
if (tmp > 65535)
return -EINVAL;
+ if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
+ snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
+ AC97_EA_DRA, dbl ? AC97_EA_DRA : 0);
snd_ac97_update(ac97, reg, tmp & 0xffff);
snd_ac97_read(ac97, reg);
+ if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) {
+ /* Intel controllers require double rate data to be put in
+ * slots 7+8
+ */
+ snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE,
+ AC97_GP_DRSS_MASK,
+ dbl ? AC97_GP_DRSS_78 : 0);
+ snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
+ }
return 0;
}
-static unsigned short get_pslots(ac97_t *ac97, unsigned char *rate_table, unsigned short *spdif_slots)
+EXPORT_SYMBOL(snd_ac97_set_rate);
+
+static unsigned short get_pslots(struct snd_ac97 *ac97, unsigned char *rate_table, unsigned short *spdif_slots)
{
if (!ac97_is_audio(ac97))
return 0;
if (ac97_is_rev22(ac97)) {
/* Note: it's simply emulation of AMAP behaviour */
u16 es;
- es = ac97->regs[AC97_EXTENDED_STATUS] &= ~AC97_EI_DACS_SLOT_MASK;
+ es = ac97->regs[AC97_EXTENDED_ID] &= ~AC97_EI_DACS_SLOT_MASK;
switch (ac97->addr) {
case 1:
case 2: es |= (1<<AC97_EI_DACS_SLOT_SHIFT); break;
case 3: es |= (2<<AC97_EI_DACS_SLOT_SHIFT); break;
}
- snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, es);
+ snd_ac97_write_cache(ac97, AC97_EXTENDED_ID, es);
}
switch (ac97->addr) {
case 0:
}
}
-static unsigned short get_cslots(ac97_t *ac97)
+static unsigned short get_cslots(struct snd_ac97 *ac97)
{
unsigned short slots;
}
rates &= pcm->r[dbl].codec[cidx]->rates[idx];
}
+ if (!dbl)
+ rates &= ~(SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 |
+ SNDRV_PCM_RATE_96000);
return rates;
}
* some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
* are reduced and might be zero.
*/
-int snd_ac97_pcm_assign(ac97_bus_t *bus,
+int snd_ac97_pcm_assign(struct snd_ac97_bus *bus,
unsigned short pcms_count,
const struct ac97_pcm *pcms)
{
unsigned short tmp, slots;
unsigned short spdif_slots[4];
unsigned int rates;
- ac97_t *codec;
+ struct snd_ac97 *codec;
rpcms = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL);
if (rpcms == NULL)
}
}
}
- /* FIXME: add double rate allocation */
/* first step - exclusive devices */
for (i = 0; i < pcms_count; i++) {
pcm = &pcms[i];
rpcm->r[0].slots |= tmp;
rpcm->rates &= rates;
}
+ /* for double rate, we check the first codec only */
+ if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+ bus->codec[0] && (bus->codec[0]->flags & AC97_DOUBLE_RATE) &&
+ rate_table[pcm->stream][0] == 0) {
+ tmp = (1<<AC97_SLOT_PCM_LEFT) | (1<<AC97_SLOT_PCM_RIGHT) |
+ (1<<AC97_SLOT_PCM_LEFT_0) | (1<<AC97_SLOT_PCM_RIGHT_0);
+ if ((tmp & pcm->r[1].slots) == tmp) {
+ rpcm->r[1].slots = tmp;
+ rpcm->r[1].rslots[0] = tmp;
+ rpcm->r[1].rate_table[0] = 0;
+ rpcm->r[1].codec[0] = bus->codec[0];
+ if (pcm->exclusive)
+ avail_slots[pcm->stream][0] &= ~tmp;
+ if (bus->no_vra)
+ rates = SNDRV_PCM_RATE_96000;
+ else
+ rates = get_rates(rpcm, 0, tmp, 1);
+ rpcm->rates |= rates;
+ }
+ }
if (rpcm->rates == ~0)
rpcm->rates = 0; /* not used */
}
return 0;
}
+EXPORT_SYMBOL(snd_ac97_pcm_assign);
+
/**
* snd_ac97_pcm_open - opens the given AC97 pcm
* @pcm: the ac97 pcm instance
int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
enum ac97_pcm_cfg cfg, unsigned short slots)
{
- ac97_bus_t *bus;
- int i, cidx, r = 0, ok_flag;
- unsigned int reg_ok = 0;
+ struct snd_ac97_bus *bus;
+ int i, cidx, r, ok_flag;
+ unsigned int reg_ok[4] = {0,0,0,0};
unsigned char reg;
int err = 0;
- if (rate > 48000) /* FIXME: add support for double rate */
- return -EINVAL;
+ r = rate > 48000;
bus = pcm->bus;
if (cfg == AC97_PCM_CFG_SPDIF) {
int err;
goto error;
}
}
+ pcm->cur_dbl = r;
spin_unlock_irq(&pcm->bus->bus_lock);
for (i = 3; i < 12; i++) {
if (!(slots & (1 << i)))
snd_printk(KERN_ERR "invalid AC97 slot %i?\n", i);
continue;
}
- if (reg_ok & (1 << (reg - AC97_PCM_FRONT_DAC_RATE)))
+ if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE)))
continue;
//printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate);
err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate);
if (err < 0)
snd_printk(KERN_ERR "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx, reg, rate, err);
else
- reg_ok |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE));
+ reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE));
}
}
}
return err;
}
+EXPORT_SYMBOL(snd_ac97_pcm_open);
+
/**
* snd_ac97_pcm_close - closes the given AC97 pcm
* @pcm: the ac97 pcm instance
*/
int snd_ac97_pcm_close(struct ac97_pcm *pcm)
{
- ac97_bus_t *bus;
+ struct snd_ac97_bus *bus;
unsigned short slots = pcm->aslots;
int i, cidx;
+#ifdef CONFIG_SND_AC97_POWER_SAVE
+ int r = pcm->cur_dbl;
+ for (i = 3; i < 12; i++) {
+ if (!(slots & (1 << i)))
+ continue;
+ for (cidx = 0; cidx < 4; cidx++) {
+ if (pcm->r[r].rslots[cidx] & (1 << i)) {
+ int reg = get_slot_reg(pcm, cidx, i, r);
+ snd_ac97_update_power(pcm->r[r].codec[cidx],
+ reg, 0);
+ }
+ }
+ }
+#endif
+
bus = pcm->bus;
spin_lock_irq(&pcm->bus->bus_lock);
for (i = 3; i < 12; i++) {
bus->used_slots[pcm->stream][cidx] &= ~(1 << i);
}
pcm->aslots = 0;
+ pcm->cur_dbl = 0;
spin_unlock_irq(&pcm->bus->bus_lock);
return 0;
}
+
+EXPORT_SYMBOL(snd_ac97_pcm_close);
+
+static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params *params,
+ struct snd_pcm_hw_rule *rule)
+{
+ struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+ if (channels->min > 2) {
+ static const struct snd_interval single_rates = {
+ .min = 1,
+ .max = 48000,
+ };
+ struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+ return snd_interval_refine(rate, &single_rates);
+ }
+ return 0;
+}
+
+static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params *params,
+ struct snd_pcm_hw_rule *rule)
+{
+ struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+ if (rate->min > 48000) {
+ static const struct snd_interval double_rate_channels = {
+ .min = 2,
+ .max = 2,
+ };
+ struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+ return snd_interval_refine(channels, &double_rate_channels);
+ }
+ return 0;
+}
+
+/**
+ * snd_ac97_pcm_double_rate_rules - set double rate constraints
+ * @runtime: the runtime of the ac97 front playback pcm
+ *
+ * Installs the hardware constraint rules to prevent using double rates and
+ * more than two channels at the same time.
+ */
+int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime)
+{
+ int err;
+
+ err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ double_rate_hw_constraint_rate, NULL,
+ SNDRV_PCM_HW_PARAM_CHANNELS, -1);
+ if (err < 0)
+ return err;
+ err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
+ double_rate_hw_constraint_channels, NULL,
+ SNDRV_PCM_HW_PARAM_RATE, -1);
+ return err;
+}
+
+EXPORT_SYMBOL(snd_ac97_pcm_double_rate_rules);