vserver 1.9.5.x5
[linux-2.6.git] / sound / pci / bt87x.c
index 2e0ba15..3b7a31f 100644 (file)
@@ -27,8 +27,8 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/moduleparam.h>
+#include <linux/bitops.h>
 #include <asm/io.h>
-#include <asm/bitops.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -45,16 +45,18 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;  /* Index 0-MAX */
 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_param_array(id, charp, boot_devs, 0444);
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for Bt87x soundcard");
-module_param_array(enable, bool, boot_devs, 0444);
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable Bt87x soundcard");
-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_param(load_all, bool, 0444);
+MODULE_PARM_DESC(load_all, "Allow to load the non-whitelisted cards");
 
 
 #ifndef PCI_VENDOR_ID_BROOKTREE
@@ -140,6 +142,14 @@ MODULE_PARM_DESC(digital_rate, "Digital input rate for Bt87x soundcard");
 #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,7 +162,7 @@ struct snd_bt87x {
        snd_card_t *card;
        struct pci_dev *pci;
 
-       void *mmio;
+       void __iomem *mmio;
        int irq;
 
        int dig_rate;
@@ -166,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 };
@@ -239,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) {
+       if ((irq_status & INT_RISCI) && (chip->reg_control & CTL_ACAP_EN)) {
                int current_block, irq_block;
 
                /* assume that exactly one line has been recorded */
@@ -304,8 +338,8 @@ static snd_pcm_hardware_t snd_bt87x_analog_hw = {
                SNDRV_PCM_INFO_MMAP_VALID,
        .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
        .rates = SNDRV_PCM_RATE_KNOT,
-       .rate_min = 119466,
-       .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,
@@ -347,9 +381,9 @@ static int snd_bt87x_set_digital_hw(bt87x_t *chip, snd_pcm_runtime_t *runtime)
 static int snd_bt87x_set_analog_hw(bt87x_t *chip, snd_pcm_runtime_t *runtime)
 {
        static ratnum_t analog_clock = {
-               .num = 1792000,
-               .den_min = 4,
-               .den_max = 15,
+               .num = ANALOG_CLOCK,
+               .den_min = CLOCK_DIV_MIN,
+               .den_max = CLOCK_DIV_MAX,
                .den_step = 1
        };
        static snd_pcm_hw_constraint_ratnums_t constraint_rates = {
@@ -434,7 +468,7 @@ static int snd_bt87x_prepare(snd_pcm_substream_t *substream)
 
        spin_lock_irq(&chip->reg_lock);
        chip->reg_control &= ~(CTL_DA_SDR_MASK | CTL_DA_SBR);
-       decimation = (1792000 + runtime->rate / 4) / 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;
@@ -451,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;
@@ -641,6 +675,7 @@ static int snd_bt87x_free(bt87x_t *chip)
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
        pci_release_regions(chip->pci);
+       pci_disable_device(chip->pci);
        kfree(chip);
        return 0;
 }
@@ -686,8 +721,10 @@ static int __devinit snd_bt87x_create(snd_card_t *card,
                return err;
 
        chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
-       if (!chip)
+       if (!chip) {
+               pci_disable_device(pci);
                return -ENOMEM;
+       }
        chip->card = card;
        chip->pci = pci;
        chip->irq = -1;
@@ -695,6 +732,7 @@ static int __devinit snd_bt87x_create(snd_card_t *card,
 
        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),
@@ -706,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);
@@ -730,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;
@@ -756,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)
@@ -800,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",
@@ -826,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);
 }