X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fbt87x.c;h=c840a4c08e9814c197d30b631b782c420e26869a;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=3c232660fd406faac8e6f4622de62200d7bcb071;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c index 3c232660f..c840a4c08 100644 --- a/sound/pci/bt87x.c +++ b/sound/pci/bt87x.c @@ -27,8 +27,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -38,40 +38,27 @@ MODULE_AUTHOR("Clemens Ladisch "); MODULE_DESCRIPTION("Brooktree Bt87x audio driver"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{Brooktree,Bt878}," +MODULE_SUPPORTED_DEVICE("{{Brooktree,Bt878}," "{Brooktree,Bt879}}"); -static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ +static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ static int digital_rate[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* digital input rate */ -static int boot_devs; +static int load_all; /* allow to load the non-whitelisted cards */ -module_param_array(index, int, boot_devs, 0444); +module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Bt87x soundcard"); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -module_param_array(id, charp, boot_devs, 0444); +module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Bt87x soundcard"); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -module_param_array(enable, bool, boot_devs, 0444); +module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Bt87x soundcard"); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); -module_param_array(digital_rate, int, boot_devs, 0444); +module_param_array(digital_rate, int, NULL, 0444); MODULE_PARM_DESC(digital_rate, "Digital input rate for Bt87x soundcard"); -MODULE_PARM_SYNTAX(digital_rate, SNDRV_ENABLED); +module_param(load_all, bool, 0444); +MODULE_PARM_DESC(load_all, "Allow to load the non-whitelisted cards"); -#ifndef PCI_VENDOR_ID_BROOKTREE -#define PCI_VENDOR_ID_BROOKTREE 0x109e -#endif -#ifndef PCI_DEVICE_ID_BROOKTREE_878 -#define PCI_DEVICE_ID_BROOKTREE_878 0x0878 -#endif -#ifndef PCI_DEVICE_ID_BROOKTREE_879 -#define PCI_DEVICE_ID_BROOKTREE_879 0x0879 -#endif - /* register offsets */ #define REG_INT_STAT 0x100 /* interrupt status */ #define REG_INT_MASK 0x104 /* interrupt mask */ @@ -145,6 +132,14 @@ MODULE_PARM_SYNTAX(digital_rate, SNDRV_ENABLED); #define RISC_SYNC_FM1 0x6 #define RISC_SYNC_VRO 0xc +#define ANALOG_CLOCK 1792000 +#ifdef CONFIG_SND_BT87X_OVERCLOCK +#define CLOCK_DIV_MIN 1 +#else +#define CLOCK_DIV_MIN 4 +#endif +#define CLOCK_DIV_MAX 15 + #define ERROR_INTERRUPTS (INT_FBUS | INT_FTRGT | INT_PPERR | \ INT_RIPERR | INT_PABORT | INT_OCERR) #define MY_INTERRUPTS (INT_RISCI | ERROR_INTERRUPTS) @@ -152,44 +147,44 @@ MODULE_PARM_SYNTAX(digital_rate, SNDRV_ENABLED); /* SYNC, one WRITE per line, one extra WRITE per page boundary, SYNC, JUMP */ #define MAX_RISC_SIZE ((1 + 255 + (PAGE_ALIGN(255 * 4092) / PAGE_SIZE - 1) + 1 + 1) * 8) -#define chip_t bt87x_t -typedef struct snd_bt87x bt87x_t; struct snd_bt87x { - snd_card_t *card; + struct snd_card *card; struct pci_dev *pci; - void *mmio; - struct resource *res_mmio; + void __iomem *mmio; int irq; int dig_rate; spinlock_t reg_lock; long opened; - snd_pcm_substream_t *substream; + struct snd_pcm_substream *substream; - struct snd_dma_device dma_dev; struct snd_dma_buffer dma_risc; unsigned int line_bytes; unsigned int lines; u32 reg_control; + u32 interrupt_mask; + int current_line; + + int pci_parity_errors; }; enum { DEVICE_DIGITAL, DEVICE_ANALOG }; -static inline u32 snd_bt87x_readl(bt87x_t *chip, u32 reg) +static inline u32 snd_bt87x_readl(struct snd_bt87x *chip, u32 reg) { return readl(chip->mmio + reg); } -static inline void snd_bt87x_writel(bt87x_t *chip, u32 reg, u32 value) +static inline void snd_bt87x_writel(struct snd_bt87x *chip, u32 reg, u32 value) { writel(value, chip->mmio + reg); } -static int snd_bt87x_create_risc(bt87x_t *chip, snd_pcm_substream_t *substream, +static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream, unsigned int periods, unsigned int period_bytes) { struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); @@ -197,10 +192,8 @@ static int snd_bt87x_create_risc(bt87x_t *chip, snd_pcm_substream_t *substream, u32 *risc; if (chip->dma_risc.area == NULL) { - memset(&chip->dma_dev, 0, sizeof(chip->dma_dev)); - chip->dma_dev.type = SNDRV_DMA_TYPE_DEV; - chip->dma_dev.dev = snd_dma_pci_data(chip->pci); - if (snd_dma_alloc_pages(&chip->dma_dev, PAGE_ALIGN(MAX_RISC_SIZE), &chip->dma_risc) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + PAGE_ALIGN(MAX_RISC_SIZE), &chip->dma_risc) < 0) return -ENOMEM; } risc = (u32 *)chip->dma_risc.area; @@ -241,41 +234,61 @@ static int snd_bt87x_create_risc(bt87x_t *chip, snd_pcm_substream_t *substream, return 0; } -static void snd_bt87x_free_risc(bt87x_t *chip) +static void snd_bt87x_free_risc(struct snd_bt87x *chip) { if (chip->dma_risc.area) { - snd_dma_free_pages(&chip->dma_dev, &chip->dma_risc); + snd_dma_free_pages(&chip->dma_risc); chip->dma_risc.area = NULL; } } +static void snd_bt87x_pci_error(struct snd_bt87x *chip, unsigned int status) +{ + u16 pci_status; + + pci_read_config_word(chip->pci, PCI_STATUS, &pci_status); + pci_status &= PCI_STATUS_PARITY | PCI_STATUS_SIG_TARGET_ABORT | + PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT | + PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY; + pci_write_config_word(chip->pci, PCI_STATUS, pci_status); + if (pci_status != PCI_STATUS_DETECTED_PARITY) + snd_printk(KERN_ERR "Aieee - PCI error! status %#08x, PCI status %#04x\n", + status & ERROR_INTERRUPTS, pci_status); + else { + snd_printk(KERN_ERR "Aieee - PCI parity error detected!\n"); + /* error 'handling' similar to aic7xxx_pci.c: */ + chip->pci_parity_errors++; + if (chip->pci_parity_errors > 20) { + snd_printk(KERN_ERR "Too many PCI parity errors observed.\n"); + snd_printk(KERN_ERR "Some device on this bus is generating bad parity.\n"); + snd_printk(KERN_ERR "This is an error *observed by*, not *generated by*, this card.\n"); + snd_printk(KERN_ERR "PCI parity error checking has been disabled.\n"); + chip->interrupt_mask &= ~(INT_PPERR | INT_RIPERR); + snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask); + } + } +} + static irqreturn_t snd_bt87x_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - bt87x_t *chip = snd_magic_cast(bt87x_t, dev_id, return IRQ_NONE); - unsigned int status; + struct snd_bt87x *chip = dev_id; + unsigned int status, irq_status; status = snd_bt87x_readl(chip, REG_INT_STAT); - if (!(status & MY_INTERRUPTS)) + irq_status = status & chip->interrupt_mask; + if (!irq_status) return IRQ_NONE; - snd_bt87x_writel(chip, REG_INT_STAT, status & MY_INTERRUPTS); + snd_bt87x_writel(chip, REG_INT_STAT, irq_status); - if (status & ERROR_INTERRUPTS) { - if (status & (INT_FBUS | INT_FTRGT)) + if (irq_status & ERROR_INTERRUPTS) { + if (irq_status & (INT_FBUS | INT_FTRGT)) snd_printk(KERN_WARNING "FIFO overrun, status %#08x\n", status); - if (status & INT_OCERR) + if (irq_status & INT_OCERR) snd_printk(KERN_ERR "internal RISC error, status %#08x\n", status); - if (status & (INT_PPERR | INT_RIPERR | INT_PABORT)) { - u16 pci_status; - pci_read_config_word(chip->pci, PCI_STATUS, &pci_status); - pci_write_config_word(chip->pci, PCI_STATUS, pci_status & - (PCI_STATUS_PARITY | PCI_STATUS_SIG_TARGET_ABORT | - PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT | - PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY)); - snd_printk(KERN_ERR "Aieee - PCI error! status %#08x, PCI status %#04x\n", - status, pci_status); - } + if (irq_status & (INT_PPERR | INT_RIPERR | INT_PABORT)) + snd_bt87x_pci_error(chip, irq_status); } - if (status & INT_RISCI) { + if ((irq_status & INT_RISCI) && (chip->reg_control & CTL_ACAP_EN)) { int current_block, irq_block; /* assume that exactly one line has been recorded */ @@ -291,7 +304,7 @@ static irqreturn_t snd_bt87x_interrupt(int irq, void *dev_id, struct pt_regs *re return IRQ_HANDLED; } -static snd_pcm_hardware_t snd_bt87x_digital_hw = { +static struct snd_pcm_hardware snd_bt87x_digital_hw = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | @@ -307,15 +320,15 @@ static snd_pcm_hardware_t snd_bt87x_digital_hw = { .periods_max = 255, }; -static snd_pcm_hardware_t snd_bt87x_analog_hw = { +static struct snd_pcm_hardware snd_bt87x_analog_hw = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8, .rates = SNDRV_PCM_RATE_KNOT, - .rate_min = 119467, - .rate_max = 448000, + .rate_min = ANALOG_CLOCK / CLOCK_DIV_MAX, + .rate_max = ANALOG_CLOCK / CLOCK_DIV_MIN, .channels_min = 1, .channels_max = 1, .buffer_bytes_max = 255 * 4092, @@ -325,7 +338,7 @@ static snd_pcm_hardware_t snd_bt87x_analog_hw = { .periods_max = 255, }; -static int snd_bt87x_set_digital_hw(bt87x_t *chip, snd_pcm_runtime_t *runtime) +static int snd_bt87x_set_digital_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime) { static struct { int rate; @@ -354,28 +367,29 @@ static int snd_bt87x_set_digital_hw(bt87x_t *chip, snd_pcm_runtime_t *runtime) return 0; } -static int snd_bt87x_set_analog_hw(bt87x_t *chip, snd_pcm_runtime_t *runtime) +static int snd_bt87x_set_analog_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime) { - static unsigned int rates[] = { - 119467, 128000, 137846, 149333, 162909, 179200, - 199111, 224000, 256000, 298667, 358400, 448000 + static struct snd_ratnum analog_clock = { + .num = ANALOG_CLOCK, + .den_min = CLOCK_DIV_MIN, + .den_max = CLOCK_DIV_MAX, + .den_step = 1 }; - static snd_pcm_hw_constraint_list_t constraint_rates = { - .count = ARRAY_SIZE(rates), - .list = rates, - .mask = 0, + static struct snd_pcm_hw_constraint_ratnums constraint_rates = { + .nrats = 1, + .rats = &analog_clock }; chip->reg_control &= ~CTL_DA_IOM_DA; runtime->hw = snd_bt87x_analog_hw; - return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, - &constraint_rates); + return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, + &constraint_rates); } -static int snd_bt87x_pcm_open(snd_pcm_substream_t *substream) +static int snd_bt87x_pcm_open(struct snd_pcm_substream *substream) { - bt87x_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int err; if (test_and_set_bit(0, &chip->opened)) @@ -401,9 +415,9 @@ _error: return err; } -static int snd_bt87x_close(snd_pcm_substream_t *substream) +static int snd_bt87x_close(struct snd_pcm_substream *substream) { - bt87x_t *chip = snd_pcm_substream_chip(substream); + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); chip->substream = NULL; clear_bit(0, &chip->opened); @@ -411,10 +425,10 @@ static int snd_bt87x_close(snd_pcm_substream_t *substream) return 0; } -static int snd_bt87x_hw_params(snd_pcm_substream_t *substream, - snd_pcm_hw_params_t *hw_params) +static int snd_bt87x_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { - bt87x_t *chip = snd_pcm_substream_chip(substream); + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); int err; err = snd_pcm_lib_malloc_pages(substream, @@ -426,65 +440,60 @@ static int snd_bt87x_hw_params(snd_pcm_substream_t *substream, params_period_bytes(hw_params)); } -static int snd_bt87x_hw_free(snd_pcm_substream_t *substream) +static int snd_bt87x_hw_free(struct snd_pcm_substream *substream) { - bt87x_t *chip = snd_pcm_substream_chip(substream); + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); snd_bt87x_free_risc(chip); snd_pcm_lib_free_pages(substream); return 0; } -static int snd_bt87x_prepare(snd_pcm_substream_t *substream) +static int snd_bt87x_prepare(struct snd_pcm_substream *substream) { - bt87x_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - unsigned long flags; + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int decimation; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); chip->reg_control &= ~(CTL_DA_SDR_MASK | CTL_DA_SBR); - decimation = (1792000 + 5) / runtime->rate; + decimation = (ANALOG_CLOCK + runtime->rate / 4) / runtime->rate; chip->reg_control |= decimation << CTL_DA_SDR_SHIFT; if (runtime->format == SNDRV_PCM_FORMAT_S8) chip->reg_control |= CTL_DA_SBR; snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return 0; } -static int snd_bt87x_start(bt87x_t *chip) +static int snd_bt87x_start(struct snd_bt87x *chip) { - unsigned long flags; - - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock(&chip->reg_lock); chip->current_line = 0; chip->reg_control |= CTL_FIFO_ENABLE | CTL_RISC_ENABLE | CTL_ACAP_EN; snd_bt87x_writel(chip, REG_RISC_STRT_ADD, chip->dma_risc.addr); snd_bt87x_writel(chip, REG_PACKET_LEN, chip->line_bytes | (chip->lines << 16)); - snd_bt87x_writel(chip, REG_INT_MASK, MY_INTERRUPTS); + snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask); snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock(&chip->reg_lock); return 0; } -static int snd_bt87x_stop(bt87x_t *chip) +static int snd_bt87x_stop(struct snd_bt87x *chip) { - unsigned long flags; - - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock(&chip->reg_lock); chip->reg_control &= ~(CTL_FIFO_ENABLE | CTL_RISC_ENABLE | CTL_ACAP_EN); snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); snd_bt87x_writel(chip, REG_INT_MASK, 0); snd_bt87x_writel(chip, REG_INT_STAT, MY_INTERRUPTS); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock(&chip->reg_lock); return 0; } -static int snd_bt87x_trigger(snd_pcm_substream_t *substream, int cmd) +static int snd_bt87x_trigger(struct snd_pcm_substream *substream, int cmd) { - bt87x_t *chip = snd_pcm_substream_chip(substream); + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -496,15 +505,15 @@ static int snd_bt87x_trigger(snd_pcm_substream_t *substream, int cmd) } } -static snd_pcm_uframes_t snd_bt87x_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_bt87x_pointer(struct snd_pcm_substream *substream) { - bt87x_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_bt87x *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_line * chip->line_bytes); } -static snd_pcm_ops_t snd_bt87x_pcm_ops = { +static struct snd_pcm_ops snd_bt87x_pcm_ops = { .open = snd_bt87x_pcm_open, .close = snd_bt87x_close, .ioctl = snd_pcm_lib_ioctl, @@ -516,7 +525,8 @@ static snd_pcm_ops_t snd_bt87x_pcm_ops = { .page = snd_pcm_sgbuf_ops_page, }; -static int snd_bt87x_capture_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *info) +static int snd_bt87x_capture_volume_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *info) { info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; info->count = 1; @@ -525,32 +535,33 @@ static int snd_bt87x_capture_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_ return 0; } -static int snd_bt87x_capture_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_volume_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); value->value.integer.value[0] = (chip->reg_control & CTL_A_GAIN_MASK) >> CTL_A_GAIN_SHIFT; return 0; } -static int snd_bt87x_capture_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_volume_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); u32 old_control; int changed; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_GAIN_MASK) | (value->value.integer.value[0] << CTL_A_GAIN_SHIFT); snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); changed = old_control != chip->reg_control; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return changed; } -static snd_kcontrol_new_t snd_bt87x_capture_volume = { +static struct snd_kcontrol_new snd_bt87x_capture_volume = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Volume", .info = snd_bt87x_capture_volume_info, @@ -558,7 +569,8 @@ static snd_kcontrol_new_t snd_bt87x_capture_volume = { .put = snd_bt87x_capture_volume_put, }; -static int snd_bt87x_capture_boost_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *info) +static int snd_bt87x_capture_boost_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *info) { info->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; info->count = 1; @@ -567,32 +579,33 @@ static int snd_bt87x_capture_boost_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_i return 0; } -static int snd_bt87x_capture_boost_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_boost_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); value->value.integer.value[0] = !! (chip->reg_control & CTL_A_G2X); return 0; } -static int snd_bt87x_capture_boost_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_boost_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); u32 old_control; int changed; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_G2X) | (value->value.integer.value[0] ? CTL_A_G2X : 0); snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); changed = chip->reg_control != old_control; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return changed; } -static snd_kcontrol_new_t snd_bt87x_capture_boost = { +static struct snd_kcontrol_new snd_bt87x_capture_boost = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Boost", .info = snd_bt87x_capture_boost_info, @@ -600,7 +613,8 @@ static snd_kcontrol_new_t snd_bt87x_capture_boost = { .put = snd_bt87x_capture_boost_put, }; -static int snd_bt87x_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *info) +static int snd_bt87x_capture_source_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *info) { static char *texts[3] = {"TV Tuner", "FM", "Mic/Line"}; @@ -613,32 +627,33 @@ static int snd_bt87x_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_ return 0; } -static int snd_bt87x_capture_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_source_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); value->value.enumerated.item[0] = (chip->reg_control & CTL_A_SEL_MASK) >> CTL_A_SEL_SHIFT; return 0; } -static int snd_bt87x_capture_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_bt87x_capture_source_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) { - bt87x_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol); u32 old_control; int changed; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); old_control = chip->reg_control; chip->reg_control = (chip->reg_control & ~CTL_A_SEL_MASK) | (value->value.enumerated.item[0] << CTL_A_SEL_SHIFT); snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); changed = chip->reg_control != old_control; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return changed; } -static snd_kcontrol_new_t snd_bt87x_capture_source = { +static struct snd_kcontrol_new snd_bt87x_capture_source = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Source", .info = snd_bt87x_capture_source_info, @@ -646,7 +661,7 @@ static snd_kcontrol_new_t snd_bt87x_capture_source = { .put = snd_bt87x_capture_source_put, }; -static int snd_bt87x_free(bt87x_t *chip) +static int snd_bt87x_free(struct snd_bt87x *chip) { if (chip->mmio) { snd_bt87x_stop(chip); @@ -655,26 +670,24 @@ static int snd_bt87x_free(bt87x_t *chip) iounmap(chip->mmio); } - if (chip->res_mmio) { - release_resource(chip->res_mmio); - kfree_nocheck(chip->res_mmio); - } if (chip->irq >= 0) free_irq(chip->irq, chip); - snd_magic_kfree(chip); + pci_release_regions(chip->pci); + pci_disable_device(chip->pci); + kfree(chip); return 0; } -static int snd_bt87x_dev_free(snd_device_t *device) +static int snd_bt87x_dev_free(struct snd_device *device) { - bt87x_t *chip = snd_magic_cast(bt87x_t, device->device_data, return -ENXIO); + struct snd_bt87x *chip = device->device_data; return snd_bt87x_free(chip); } -static int __devinit snd_bt87x_pcm(bt87x_t *chip, int device, char *name) +static int __devinit snd_bt87x_pcm(struct snd_bt87x *chip, int device, char *name) { int err; - snd_pcm_t *pcm; + struct snd_pcm *pcm; err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm); if (err < 0) @@ -689,13 +702,13 @@ static int __devinit snd_bt87x_pcm(bt87x_t *chip, int device, char *name) (255 * 4092 + 1023) & ~1023); } -static int __devinit snd_bt87x_create(snd_card_t *card, +static int __devinit snd_bt87x_create(struct snd_card *card, struct pci_dev *pci, - bt87x_t **rchip) + struct snd_bt87x **rchip) { - bt87x_t *chip; + struct snd_bt87x *chip; int err; - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_bt87x_dev_free }; @@ -705,21 +718,20 @@ static int __devinit snd_bt87x_create(snd_card_t *card, if (err < 0) return err; - chip = snd_magic_kcalloc(bt87x_t, 0, GFP_KERNEL); - if (!chip) + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (!chip) { + pci_disable_device(pci); return -ENOMEM; + } chip->card = card; chip->pci = pci; chip->irq = -1; spin_lock_init(&chip->reg_lock); - chip->res_mmio = request_mem_region(pci_resource_start(pci, 0), - pci_resource_len(pci, 0), - "Bt87x audio"); - if (!chip->res_mmio) { - snd_bt87x_free(chip); - snd_printk(KERN_ERR "cannot allocate io memory\n"); - return -EBUSY; + if ((err = pci_request_regions(pci, "Bt87x audio")) < 0) { + kfree(chip); + pci_disable_device(pci); + return err; } chip->mmio = ioremap_nocache(pci_resource_start(pci, 0), pci_resource_len(pci, 0)); @@ -730,6 +742,7 @@ static int __devinit snd_bt87x_create(snd_card_t *card, } chip->reg_control = CTL_DA_ES2 | CTL_PKTP_16 | (15 << CTL_DA_SDR_SHIFT); + chip->interrupt_mask = MY_INTERRUPTS; snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control); snd_bt87x_writel(chip, REG_INT_MASK, 0); snd_bt87x_writel(chip, REG_INT_STAT, MY_INTERRUPTS); @@ -754,13 +767,80 @@ static int __devinit snd_bt87x_create(snd_card_t *card, return 0; } +#define BT_DEVICE(chip, subvend, subdev, rate) \ + { .vendor = PCI_VENDOR_ID_BROOKTREE, \ + .device = chip, \ + .subvendor = subvend, .subdevice = subdev, \ + .driver_data = rate } + +/* driver_data is the default digital_rate value for that device */ +static struct pci_device_id snd_bt87x_ids[] = { + /* Hauppauge WinTV series */ + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0x13eb, 32000), + /* Hauppauge WinTV series */ + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, 0x0070, 0x13eb, 32000), + /* Viewcast Osprey 200 */ + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0xff01, 44100), + /* AVerMedia Studio No. 103, 203, ...? */ + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1461, 0x0003, 48000), + { } +}; +MODULE_DEVICE_TABLE(pci, snd_bt87x_ids); + +/* cards known not to have audio + * (DVB cards use the audio function to transfer MPEG data) */ +static struct { + unsigned short subvendor, subdevice; +} blacklist[] __devinitdata = { + {0x0071, 0x0101}, /* Nebula Electronics DigiTV */ + {0x11bd, 0x0026}, /* Pinnacle PCTV SAT CI */ + {0x1461, 0x0761}, /* AVermedia AverTV DVB-T */ + {0x1461, 0x0771}, /* AVermedia DVB-T 771 */ + {0x1822, 0x0001}, /* Twinhan VisionPlus DVB-T */ + {0x18ac, 0xdb10}, /* DVICO FusionHDTV DVB-T Lite */ + {0x270f, 0xfc00}, /* Chaintech Digitop DST-1000 DVB-S */ +}; + +static struct pci_driver driver; + +/* return the rate of the card, or a negative value if it's blacklisted */ +static int __devinit snd_bt87x_detect_card(struct pci_dev *pci) +{ + int i; + const struct pci_device_id *supported; + + supported = pci_match_device(&driver, pci); + if (supported && supported->driver_data > 0) + return supported->driver_data; + + for (i = 0; i < ARRAY_SIZE(blacklist); ++i) + if (blacklist[i].subvendor == pci->subsystem_vendor && + blacklist[i].subdevice == pci->subsystem_device) { + snd_printdd(KERN_INFO "card %#04x:%#04x has no audio\n", + pci->subsystem_vendor, pci->subsystem_device); + return -EBUSY; + } + + snd_printk(KERN_INFO "unknown card %#04x:%#04x, using default rate 32000\n", + pci->subsystem_vendor, pci->subsystem_device); + snd_printk(KERN_DEBUG "please mail id, board name, and, " + "if it works, the correct digital_rate option to " + "\n"); + return 32000; /* default rate */ +} + static int __devinit snd_bt87x_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; - snd_card_t *card; - bt87x_t *chip; - int err; + struct snd_card *card; + struct snd_bt87x *chip; + int err, rate; + + rate = pci_id->driver_data; + if (! rate) + if ((rate = snd_bt87x_detect_card(pci)) <= 0) + return -ENODEV; if (dev >= SNDRV_CARDS) return -ENODEV; @@ -780,7 +860,7 @@ static int __devinit snd_bt87x_probe(struct pci_dev *pci, if (digital_rate[dev] > 0) chip->dig_rate = digital_rate[dev]; else - chip->dig_rate = (int)pci_id->driver_data; + chip->dig_rate = rate; err = snd_bt87x_pcm(chip, DEVICE_DIGITAL, "Bt87x Digital"); if (err < 0) @@ -824,22 +904,13 @@ static void __devexit snd_bt87x_remove(struct pci_dev *pci) pci_set_drvdata(pci, NULL); } -#define BT_DEVICE(chip, subvend, subdev, rate) \ - { .vendor = PCI_VENDOR_ID_BROOKTREE, \ - .device = PCI_DEVICE_ID_BROOKTREE_##chip, \ - .subvendor = subvend, .subdevice = subdev, \ - .driver_data = rate } - -/* driver_data is the default digital_rate value for that device */ -static struct pci_device_id snd_bt87x_ids[] = { - BT_DEVICE(878, 0x0070, 0xff01, 44100), /* Osprey 200 */ - - /* default entries for 32kHz and generic Bt87x cards */ - BT_DEVICE(878, PCI_ANY_ID, PCI_ANY_ID, 32000), - BT_DEVICE(879, PCI_ANY_ID, PCI_ANY_ID, 32000), +/* default entries for all Bt87x cards - it's not exported */ +/* driver_data is set to 0 to call detection */ +static struct pci_device_id snd_bt87x_default_ids[] = { + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, PCI_ANY_ID, PCI_ANY_ID, 0), + BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, PCI_ANY_ID, PCI_ANY_ID, 0), { } }; -MODULE_DEVICE_TABLE(pci, snd_bt87x_ids); static struct pci_driver driver = { .name = "Bt87x", @@ -850,7 +921,9 @@ static struct pci_driver driver = { static int __init alsa_card_bt87x_init(void) { - return pci_module_init(&driver); + if (load_all) + driver.id_table = snd_bt87x_default_ids; + return pci_register_driver(&driver); } static void __exit alsa_card_bt87x_exit(void)