X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fac97%2Fac97_pcm.c;h=512a3583b0ce91f4b8cc280086431d266932f3f2;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=04f3b60969c48e63b3e028d12aea7f1914834df8;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c index 04f3b6096..512a3583b 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 @@ -93,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 */ } }}; @@ -172,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; @@ -180,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; @@ -207,14 +208,12 @@ static int set_spdif_rate(ac97_t *ac97, unsigned short rate) 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; @@ -232,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; } @@ -257,10 +256,19 @@ 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; + } + switch (reg) { case AC97_PCM_MIC_ADC_RATE: if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRM) == 0) /* MIC VRA */ @@ -270,7 +278,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: @@ -287,15 +295,29 @@ 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) +static unsigned short get_pslots(struct snd_ac97 *ac97, unsigned char *rate_table, unsigned short *spdif_slots) { if (!ac97_is_audio(ac97)) return 0; @@ -304,13 +326,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: @@ -370,7 +392,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; @@ -401,6 +423,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; } @@ -414,7 +439,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) { @@ -426,7 +451,7 @@ 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 = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL); if (rpcms == NULL) @@ -447,7 +472,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]; @@ -498,6 +522,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 */ } @@ -518,14 +562,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; @@ -570,14 +613,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)); } } } @@ -598,7 +641,7 @@ 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; @@ -614,3 +657,55 @@ int snd_ac97_pcm_close(struct ac97_pcm *pcm) spin_unlock_irq(&pcm->bus->bus_lock); return 0; } + +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; +}