X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fac97%2Fac97_pcm.c;h=3758d07182f8013f2707971894ffe7a963c5ddf7;hb=refs%2Fheads%2Fvserver;hp=f87194ddcf344fe8116dc1864473cf50ece80814;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c index f87194ddc..3758d0718 100644 --- a/sound/pci/ac97/ac97_pcm.c +++ b/sound/pci/ac97/ac97_pcm.c @@ -27,6 +27,8 @@ #include #include #include +#include + #include #include #include @@ -36,8 +38,6 @@ #include "ac97_id.h" #include "ac97_local.h" -#define chip_t ac97_t - /* * PCM support */ @@ -95,54 +95,52 @@ static unsigned char rate_reg_tables[2][4][9] = { }, }, { - /* 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 */ } }}; @@ -174,7 +172,7 @@ static unsigned char get_slot_reg(struct ac97_pcm *pcm, unsigned short cidx, 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; @@ -182,6 +180,7 @@ static int set_spdif_rate(ac97_t *ac97, unsigned short rate) 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; @@ -209,14 +208,12 @@ static int set_spdif_rate(ac97_t *ac97, unsigned short rate) mask = AC97_SC_SPSR_MASK; } - spin_lock(&ac97->reg_lock); - old = ac97->regs[reg] & mask; - spin_unlock(&ac97->reg_lock); + mutex_lock(&ac97->reg_mutex); + old = snd_ac97_read(ac97, reg) & mask; 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; @@ -234,9 +231,9 @@ static int set_spdif_rate(ac97_t *ac97, unsigned short rate) } } 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; } @@ -259,10 +256,20 @@ static int set_spdif_rate(ac97_t *ac97, unsigned short rate) * * 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 */ @@ -272,7 +279,7 @@ int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned short rate) 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: @@ -289,15 +296,31 @@ int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned short 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; @@ -306,13 +329,13 @@ static unsigned short get_pslots(ac97_t *ac97, unsigned char *rate_table, unsign 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<addr) { case 0: @@ -372,7 +395,7 @@ static unsigned short get_pslots(ac97_t *ac97, unsigned char *rate_table, unsign } } -static unsigned short get_cslots(ac97_t *ac97) +static unsigned short get_cslots(struct snd_ac97 *ac97) { unsigned short slots; @@ -403,6 +426,9 @@ static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned } 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; } @@ -416,7 +442,7 @@ static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned * 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) { @@ -428,9 +454,9 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, unsigned short tmp, slots; unsigned short spdif_slots[4]; unsigned int rates; - ac97_t *codec; + struct snd_ac97 *codec; - rpcms = snd_kcalloc(sizeof(struct ac97_pcm) * pcms_count, GFP_KERNEL); + rpcms = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL); if (rpcms == NULL) return -ENOMEM; memset(avail_slots, 0, sizeof(avail_slots)); @@ -449,7 +475,6 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, } } } - /* FIXME: add double rate allocation */ /* first step - exclusive devices */ for (i = 0; i < pcms_count; i++) { pcm = &pcms[i]; @@ -489,7 +514,10 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, rpcm->r[0].rslots[j] = tmp; rpcm->r[0].codec[j] = bus->codec[j]; rpcm->r[0].rate_table[j] = rate_table[pcm->stream][j]; - rates = get_rates(rpcm, j, tmp, 0); + if (bus->no_vra) + rates = SNDRV_PCM_RATE_48000; + else + rates = get_rates(rpcm, j, tmp, 0); if (pcm->exclusive) avail_slots[pcm->stream][j] &= ~tmp; } @@ -497,6 +525,26 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, 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<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 */ } @@ -505,6 +553,8 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, return 0; } +EXPORT_SYMBOL(snd_ac97_pcm_assign); + /** * snd_ac97_pcm_open - opens the given AC97 pcm * @pcm: the ac97 pcm instance @@ -517,14 +567,13 @@ int snd_ac97_pcm_assign(ac97_bus_t *bus, 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; @@ -558,6 +607,7 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, goto error; } } + pcm->cur_dbl = r; spin_unlock_irq(&pcm->bus->bus_lock); for (i = 3; i < 12; i++) { if (!(slots & (1 << i))) @@ -569,14 +619,14 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, 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)); } } } @@ -589,6 +639,8 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, return err; } +EXPORT_SYMBOL(snd_ac97_pcm_open); + /** * snd_ac97_pcm_close - closes the given AC97 pcm * @pcm: the ac97 pcm instance @@ -597,10 +649,25 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, */ 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++) { @@ -610,6 +677,63 @@ int snd_ac97_pcm_close(struct ac97_pcm *pcm) 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);