upgrade to fedora-2.6.12-1.1398.FC4 + vserver 2.0.rc7
[linux-2.6.git] / sound / pci / bt87x.c
index 83b7546..89a7ffe 100644 (file)
@@ -41,10 +41,11 @@ MODULE_LICENSE("GPL");
 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 load_all;   /* allow to load the non-whitelisted cards */
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for Bt87x soundcard");
@@ -54,6 +55,8 @@ module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable Bt87x soundcard");
 module_param_array(digital_rate, int, NULL, 0444);
 MODULE_PARM_DESC(digital_rate, "Digital input rate for Bt87x soundcard");
+module_param(load_all, bool, 0444);
+MODULE_PARM_DESC(load_all, "Allow to load the non-whitelisted cards");
 
 
 #ifndef PCI_VENDOR_ID_BROOKTREE
@@ -159,7 +162,7 @@ struct snd_bt87x {
        snd_card_t *card;
        struct pci_dev *pci;
 
-       void *mmio;
+       void __iomem *mmio;
        int irq;
 
        int dig_rate;
@@ -173,7 +176,11 @@ struct snd_bt87x {
        unsigned int lines;
 
        u32 reg_control;
+       u32 interrupt_mask;
+
        int current_line;
+
+       int pci_parity_errors;
 };
 
 enum { DEVICE_DIGITAL, DEVICE_ANALOG };
@@ -246,33 +253,53 @@ static void snd_bt87x_free_risc(bt87x_t *chip)
        }
 }
 
+static void snd_bt87x_pci_error(bt87x_t *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 = dev_id;
-       unsigned int status;
+       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) && (chip->reg_control & CTL_ACAP_EN)) {
+       if ((irq_status & INT_RISCI) && (chip->reg_control & CTL_ACAP_EN)) {
                int current_block, irq_block;
 
                /* assume that exactly one line has been recorded */
@@ -458,7 +485,7 @@ static int snd_bt87x_start(bt87x_t *chip)
        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(&chip->reg_lock);
        return 0;
@@ -717,6 +744,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);
@@ -741,13 +769,73 @@ 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 = 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, 0x13eb, 32000), /* Hauppauge WinTV series */
+       BT_DEVICE(879, 0x0070, 0x13eb, 32000), /* Hauppauge WinTV series */
+       BT_DEVICE(878, 0x0070, 0xff01, 44100), /* Viewcast Osprey 200 */
+       { }
+};
+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 */
+};
+
+/* 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(snd_bt87x_ids, pci);
+       if (supported)
+               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 "
+                  "<alsa-devel@lists.sf.net>\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;
+       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;
@@ -767,7 +855,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)
@@ -811,22 +899,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(878, PCI_ANY_ID, PCI_ANY_ID, 0),
+       BT_DEVICE(879, PCI_ANY_ID, PCI_ANY_ID, 0),
        { }
 };
-MODULE_DEVICE_TABLE(pci, snd_bt87x_ids);
 
 static struct pci_driver driver = {
        .name = "Bt87x",
@@ -837,6 +916,8 @@ static struct pci_driver driver = {
 
 static int __init alsa_card_bt87x_init(void)
 {
+       if (load_all)
+               driver.id_table = snd_bt87x_default_ids;
        return pci_module_init(&driver);
 }