1 | /*
|
---|
2 | * bt87x.c - Brooktree Bt878/Bt879 driver for ALSA
|
---|
3 | *
|
---|
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
|
---|
5 | *
|
---|
6 | * based on btaudio.c by Gerd Knorr <kraxel@bytesex.org>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This driver is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This driver is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include <linux/init.h>
|
---|
25 | #include <linux/interrupt.h>
|
---|
26 | #include <linux/pci.h>
|
---|
27 | #include <linux/slab.h>
|
---|
28 | #include <linux/moduleparam.h>
|
---|
29 | #include <linux/bitops.h>
|
---|
30 | #include <asm/io.h>
|
---|
31 | #include <sound/core.h>
|
---|
32 | #include <sound/pcm.h>
|
---|
33 | #include <sound/pcm_params.h>
|
---|
34 | #include <sound/control.h>
|
---|
35 | #include <sound/initval.h>
|
---|
36 |
|
---|
37 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
|
---|
38 | MODULE_DESCRIPTION("Brooktree Bt87x audio driver");
|
---|
39 | MODULE_LICENSE("GPL");
|
---|
40 | MODULE_SUPPORTED_DEVICE("{{Brooktree,Bt878},"
|
---|
41 | "{Brooktree,Bt879}}");
|
---|
42 |
|
---|
43 | #ifndef TARGET_OS2
|
---|
44 | static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */
|
---|
45 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
46 | #else
|
---|
47 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
48 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
49 | #endif
|
---|
50 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
|
---|
51 | static int digital_rate[SNDRV_CARDS]; /* digital input rate */
|
---|
52 | static int load_all; /* allow to load the non-whitelisted cards */
|
---|
53 |
|
---|
54 | module_param_array(index, int, NULL, 0444);
|
---|
55 | MODULE_PARM_DESC(index, "Index value for Bt87x soundcard");
|
---|
56 | module_param_array(id, charp, NULL, 0444);
|
---|
57 | MODULE_PARM_DESC(id, "ID string for Bt87x soundcard");
|
---|
58 | module_param_array(enable, bool, NULL, 0444);
|
---|
59 | MODULE_PARM_DESC(enable, "Enable Bt87x soundcard");
|
---|
60 | module_param_array(digital_rate, int, NULL, 0444);
|
---|
61 | MODULE_PARM_DESC(digital_rate, "Digital input rate for Bt87x soundcard");
|
---|
62 | module_param(load_all, bool, 0444);
|
---|
63 | MODULE_PARM_DESC(load_all, "Allow to load the non-whitelisted cards");
|
---|
64 |
|
---|
65 |
|
---|
66 | /* register offsets */
|
---|
67 | #define REG_INT_STAT 0x100 /* interrupt status */
|
---|
68 | #define REG_INT_MASK 0x104 /* interrupt mask */
|
---|
69 | #define REG_GPIO_DMA_CTL 0x10c /* audio control */
|
---|
70 | #define REG_PACKET_LEN 0x110 /* audio packet lengths */
|
---|
71 | #define REG_RISC_STRT_ADD 0x114 /* RISC program start address */
|
---|
72 | #define REG_RISC_COUNT 0x120 /* RISC program counter */
|
---|
73 |
|
---|
74 | /* interrupt bits */
|
---|
75 | #define INT_OFLOW (1 << 3) /* audio A/D overflow */
|
---|
76 | #define INT_RISCI (1 << 11) /* RISC instruction IRQ bit set */
|
---|
77 | #define INT_FBUS (1 << 12) /* FIFO overrun due to bus access latency */
|
---|
78 | #define INT_FTRGT (1 << 13) /* FIFO overrun due to target latency */
|
---|
79 | #define INT_FDSR (1 << 14) /* FIFO data stream resynchronization */
|
---|
80 | #define INT_PPERR (1 << 15) /* PCI parity error */
|
---|
81 | #define INT_RIPERR (1 << 16) /* RISC instruction parity error */
|
---|
82 | #define INT_PABORT (1 << 17) /* PCI master or target abort */
|
---|
83 | #define INT_OCERR (1 << 18) /* invalid opcode */
|
---|
84 | #define INT_SCERR (1 << 19) /* sync counter overflow */
|
---|
85 | #define INT_RISC_EN (1 << 27) /* DMA controller running */
|
---|
86 | #define INT_RISCS_SHIFT 28 /* RISC status bits */
|
---|
87 |
|
---|
88 | /* audio control bits */
|
---|
89 | #define CTL_FIFO_ENABLE (1 << 0) /* enable audio data FIFO */
|
---|
90 | #define CTL_RISC_ENABLE (1 << 1) /* enable audio DMA controller */
|
---|
91 | #define CTL_PKTP_4 (0 << 2) /* packet mode FIFO trigger point - 4 DWORDs */
|
---|
92 | #define CTL_PKTP_8 (1 << 2) /* 8 DWORDs */
|
---|
93 | #define CTL_PKTP_16 (2 << 2) /* 16 DWORDs */
|
---|
94 | #define CTL_ACAP_EN (1 << 4) /* enable audio capture */
|
---|
95 | #define CTL_DA_APP (1 << 5) /* GPIO input */
|
---|
96 | #define CTL_DA_IOM_AFE (0 << 6) /* audio A/D input */
|
---|
97 | #define CTL_DA_IOM_DA (1 << 6) /* digital audio input */
|
---|
98 | #define CTL_DA_SDR_SHIFT 8 /* DDF first stage decimation rate */
|
---|
99 | #define CTL_DA_SDR_MASK (0xf<< 8)
|
---|
100 | #define CTL_DA_LMT (1 << 12) /* limit audio data values */
|
---|
101 | #define CTL_DA_ES2 (1 << 13) /* enable DDF stage 2 */
|
---|
102 | #define CTL_DA_SBR (1 << 14) /* samples rounded to 8 bits */
|
---|
103 | #define CTL_DA_DPM (1 << 15) /* data packet mode */
|
---|
104 | #define CTL_DA_LRD_SHIFT 16 /* ALRCK delay */
|
---|
105 | #define CTL_DA_MLB (1 << 21) /* MSB/LSB format */
|
---|
106 | #define CTL_DA_LRI (1 << 22) /* left/right indication */
|
---|
107 | #define CTL_DA_SCE (1 << 23) /* sample clock edge */
|
---|
108 | #define CTL_A_SEL_STV (0 << 24) /* TV tuner audio input */
|
---|
109 | #define CTL_A_SEL_SFM (1 << 24) /* FM audio input */
|
---|
110 | #define CTL_A_SEL_SML (2 << 24) /* mic/line audio input */
|
---|
111 | #define CTL_A_SEL_SMXC (3 << 24) /* MUX bypass */
|
---|
112 | #define CTL_A_SEL_SHIFT 24
|
---|
113 | #define CTL_A_SEL_MASK (3 << 24)
|
---|
114 | #define CTL_A_PWRDN (1 << 26) /* analog audio power-down */
|
---|
115 | #define CTL_A_G2X (1 << 27) /* audio gain boost */
|
---|
116 | #define CTL_A_GAIN_SHIFT 28 /* audio input gain */
|
---|
117 | #define CTL_A_GAIN_MASK (0xf<<28)
|
---|
118 |
|
---|
119 | /* RISC instruction opcodes */
|
---|
120 | #define RISC_WRITE (0x1 << 28) /* write FIFO data to memory at address */
|
---|
121 | #define RISC_WRITEC (0x5 << 28) /* write FIFO data to memory at current address */
|
---|
122 | #define RISC_SKIP (0x2 << 28) /* skip FIFO data */
|
---|
123 | #define RISC_JUMP (0x7 << 28) /* jump to address */
|
---|
124 | #define RISC_SYNC (0x8 << 28) /* synchronize with FIFO */
|
---|
125 |
|
---|
126 | /* RISC instruction bits */
|
---|
127 | #define RISC_BYTES_ENABLE (0xf << 12) /* byte enable bits */
|
---|
128 | #define RISC_RESYNC ( 1 << 15) /* disable FDSR errors */
|
---|
129 | #define RISC_SET_STATUS_SHIFT 16 /* set status bits */
|
---|
130 | #define RISC_RESET_STATUS_SHIFT 20 /* clear status bits */
|
---|
131 | #define RISC_IRQ ( 1 << 24) /* interrupt */
|
---|
132 | #define RISC_EOL ( 1 << 26) /* end of line */
|
---|
133 | #define RISC_SOL ( 1 << 27) /* start of line */
|
---|
134 |
|
---|
135 | /* SYNC status bits values */
|
---|
136 | #define RISC_SYNC_FM1 0x6
|
---|
137 | #define RISC_SYNC_VRO 0xc
|
---|
138 |
|
---|
139 | #define ANALOG_CLOCK 1792000
|
---|
140 | #ifdef CONFIG_SND_BT87X_OVERCLOCK
|
---|
141 | #define CLOCK_DIV_MIN 1
|
---|
142 | #else
|
---|
143 | #define CLOCK_DIV_MIN 4
|
---|
144 | #endif
|
---|
145 | #define CLOCK_DIV_MAX 15
|
---|
146 |
|
---|
147 | #define ERROR_INTERRUPTS (INT_FBUS | INT_FTRGT | INT_PPERR | \
|
---|
148 | INT_RIPERR | INT_PABORT | INT_OCERR)
|
---|
149 | #define MY_INTERRUPTS (INT_RISCI | ERROR_INTERRUPTS)
|
---|
150 |
|
---|
151 | /* SYNC, one WRITE per line, one extra WRITE per page boundary, SYNC, JUMP */
|
---|
152 | #define MAX_RISC_SIZE ((1 + 255 + (PAGE_ALIGN(255 * 4092) / PAGE_SIZE - 1) + 1 + 1) * 8)
|
---|
153 |
|
---|
154 | /* Cards with configuration information */
|
---|
155 | enum snd_bt87x_boardid {
|
---|
156 | SND_BT87X_BOARD_UNKNOWN,
|
---|
157 | SND_BT87X_BOARD_GENERIC, /* both an & dig interfaces, 32kHz */
|
---|
158 | SND_BT87X_BOARD_ANALOG, /* board with no external A/D */
|
---|
159 | SND_BT87X_BOARD_OSPREY2x0,
|
---|
160 | SND_BT87X_BOARD_OSPREY440,
|
---|
161 | SND_BT87X_BOARD_AVPHONE98,
|
---|
162 | };
|
---|
163 |
|
---|
164 | /* Card configuration */
|
---|
165 | struct snd_bt87x_board {
|
---|
166 | int dig_rate; /* Digital input sampling rate */
|
---|
167 | u32 digital_fmt; /* Register settings for digital input */
|
---|
168 | unsigned no_analog:1; /* No analog input */
|
---|
169 | unsigned no_digital:1; /* No digital input */
|
---|
170 | };
|
---|
171 |
|
---|
172 | static __devinitdata struct snd_bt87x_board snd_bt87x_boards[] = {
|
---|
173 | [SND_BT87X_BOARD_UNKNOWN] = {
|
---|
174 | .dig_rate = 32000, /* just a guess */
|
---|
175 | },
|
---|
176 | [SND_BT87X_BOARD_GENERIC] = {
|
---|
177 | .dig_rate = 32000,
|
---|
178 | },
|
---|
179 | [SND_BT87X_BOARD_ANALOG] = {
|
---|
180 | .no_digital = 1,
|
---|
181 | },
|
---|
182 | [SND_BT87X_BOARD_OSPREY2x0] = {
|
---|
183 | .dig_rate = 44100,
|
---|
184 | .digital_fmt = CTL_DA_LRI | (1 << CTL_DA_LRD_SHIFT),
|
---|
185 | },
|
---|
186 | [SND_BT87X_BOARD_OSPREY440] = {
|
---|
187 | .dig_rate = 32000,
|
---|
188 | .digital_fmt = CTL_DA_LRI | (1 << CTL_DA_LRD_SHIFT),
|
---|
189 | .no_analog = 1,
|
---|
190 | },
|
---|
191 | [SND_BT87X_BOARD_AVPHONE98] = {
|
---|
192 | .dig_rate = 48000,
|
---|
193 | },
|
---|
194 | };
|
---|
195 |
|
---|
196 | struct snd_bt87x {
|
---|
197 | struct snd_card *card;
|
---|
198 | struct pci_dev *pci;
|
---|
199 | struct snd_bt87x_board board;
|
---|
200 |
|
---|
201 | void __iomem *mmio;
|
---|
202 | int irq;
|
---|
203 |
|
---|
204 | spinlock_t reg_lock;
|
---|
205 | unsigned long opened;
|
---|
206 | struct snd_pcm_substream *substream;
|
---|
207 |
|
---|
208 | struct snd_dma_buffer dma_risc;
|
---|
209 | unsigned int line_bytes;
|
---|
210 | unsigned int lines;
|
---|
211 |
|
---|
212 | u32 reg_control;
|
---|
213 | u32 interrupt_mask;
|
---|
214 |
|
---|
215 | int current_line;
|
---|
216 |
|
---|
217 | int pci_parity_errors;
|
---|
218 | };
|
---|
219 |
|
---|
220 | enum { DEVICE_DIGITAL, DEVICE_ANALOG };
|
---|
221 |
|
---|
222 | static inline u32 snd_bt87x_readl(struct snd_bt87x *chip, u32 reg)
|
---|
223 | {
|
---|
224 | return readl(chip->mmio + reg);
|
---|
225 | }
|
---|
226 |
|
---|
227 | static inline void snd_bt87x_writel(struct snd_bt87x *chip, u32 reg, u32 value)
|
---|
228 | {
|
---|
229 | writel(value, chip->mmio + reg);
|
---|
230 | }
|
---|
231 |
|
---|
232 | static int snd_bt87x_create_risc(struct snd_bt87x *chip, struct snd_pcm_substream *substream,
|
---|
233 | unsigned int periods, unsigned int period_bytes)
|
---|
234 | {
|
---|
235 | unsigned int i, offset;
|
---|
236 | u32 *risc;
|
---|
237 |
|
---|
238 | if (chip->dma_risc.area == NULL) {
|
---|
239 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
|
---|
240 | PAGE_ALIGN(MAX_RISC_SIZE), &chip->dma_risc) < 0)
|
---|
241 | return -ENOMEM;
|
---|
242 | }
|
---|
243 | risc = (u32 *)chip->dma_risc.area;
|
---|
244 | offset = 0;
|
---|
245 | *risc++ = cpu_to_le32(RISC_SYNC | RISC_SYNC_FM1);
|
---|
246 | *risc++ = cpu_to_le32(0);
|
---|
247 | for (i = 0; i < periods; ++i) {
|
---|
248 | u32 rest;
|
---|
249 |
|
---|
250 | rest = period_bytes;
|
---|
251 | do {
|
---|
252 | u32 cmd, len;
|
---|
253 | unsigned int addr;
|
---|
254 |
|
---|
255 | len = PAGE_SIZE - (offset % PAGE_SIZE);
|
---|
256 | if (len > rest)
|
---|
257 | len = rest;
|
---|
258 | cmd = RISC_WRITE | len;
|
---|
259 | if (rest == period_bytes) {
|
---|
260 | u32 block = i * 16 / periods;
|
---|
261 | cmd |= RISC_SOL;
|
---|
262 | cmd |= block << RISC_SET_STATUS_SHIFT;
|
---|
263 | cmd |= (~block & 0xf) << RISC_RESET_STATUS_SHIFT;
|
---|
264 | }
|
---|
265 | if (len == rest)
|
---|
266 | cmd |= RISC_EOL | RISC_IRQ;
|
---|
267 | *risc++ = cpu_to_le32(cmd);
|
---|
268 | addr = snd_pcm_sgbuf_get_addr(substream, offset);
|
---|
269 | *risc++ = cpu_to_le32(addr);
|
---|
270 | offset += len;
|
---|
271 | rest -= len;
|
---|
272 | } while (rest > 0);
|
---|
273 | }
|
---|
274 | *risc++ = cpu_to_le32(RISC_SYNC | RISC_SYNC_VRO);
|
---|
275 | *risc++ = cpu_to_le32(0);
|
---|
276 | *risc++ = cpu_to_le32(RISC_JUMP);
|
---|
277 | *risc++ = cpu_to_le32(chip->dma_risc.addr);
|
---|
278 | chip->line_bytes = period_bytes;
|
---|
279 | chip->lines = periods;
|
---|
280 | return 0;
|
---|
281 | }
|
---|
282 |
|
---|
283 | static void snd_bt87x_free_risc(struct snd_bt87x *chip)
|
---|
284 | {
|
---|
285 | if (chip->dma_risc.area) {
|
---|
286 | snd_dma_free_pages(&chip->dma_risc);
|
---|
287 | chip->dma_risc.area = NULL;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | static void snd_bt87x_pci_error(struct snd_bt87x *chip, unsigned int status)
|
---|
292 | {
|
---|
293 | u16 pci_status;
|
---|
294 |
|
---|
295 | pci_read_config_word(chip->pci, PCI_STATUS, &pci_status);
|
---|
296 | pci_status &= PCI_STATUS_PARITY | PCI_STATUS_SIG_TARGET_ABORT |
|
---|
297 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT |
|
---|
298 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY;
|
---|
299 | pci_write_config_word(chip->pci, PCI_STATUS, pci_status);
|
---|
300 | if (pci_status != PCI_STATUS_DETECTED_PARITY)
|
---|
301 | snd_printk(KERN_ERR "Aieee - PCI error! status %#08x, PCI status %#04x\n",
|
---|
302 | status & ERROR_INTERRUPTS, pci_status);
|
---|
303 | else {
|
---|
304 | snd_printk(KERN_ERR "Aieee - PCI parity error detected!\n");
|
---|
305 | /* error 'handling' similar to aic7xxx_pci.c: */
|
---|
306 | chip->pci_parity_errors++;
|
---|
307 | if (chip->pci_parity_errors > 20) {
|
---|
308 | snd_printk(KERN_ERR "Too many PCI parity errors observed.\n");
|
---|
309 | snd_printk(KERN_ERR "Some device on this bus is generating bad parity.\n");
|
---|
310 | snd_printk(KERN_ERR "This is an error *observed by*, not *generated by*, this card.\n");
|
---|
311 | snd_printk(KERN_ERR "PCI parity error checking has been disabled.\n");
|
---|
312 | chip->interrupt_mask &= ~(INT_PPERR | INT_RIPERR);
|
---|
313 | snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask);
|
---|
314 | }
|
---|
315 | }
|
---|
316 | }
|
---|
317 |
|
---|
318 | static irqreturn_t snd_bt87x_interrupt(int irq, void *dev_id)
|
---|
319 | {
|
---|
320 | struct snd_bt87x *chip = dev_id;
|
---|
321 | unsigned int status, irq_status;
|
---|
322 |
|
---|
323 | status = snd_bt87x_readl(chip, REG_INT_STAT);
|
---|
324 | irq_status = status & chip->interrupt_mask;
|
---|
325 | if (!irq_status)
|
---|
326 | return IRQ_NONE;
|
---|
327 | snd_bt87x_writel(chip, REG_INT_STAT, irq_status);
|
---|
328 |
|
---|
329 | if (irq_status & ERROR_INTERRUPTS) {
|
---|
330 | if (irq_status & (INT_FBUS | INT_FTRGT))
|
---|
331 | snd_printk(KERN_WARNING "FIFO overrun, status %#08x\n", status);
|
---|
332 | if (irq_status & INT_OCERR)
|
---|
333 | snd_printk(KERN_ERR "internal RISC error, status %#08x\n", status);
|
---|
334 | if (irq_status & (INT_PPERR | INT_RIPERR | INT_PABORT))
|
---|
335 | snd_bt87x_pci_error(chip, irq_status);
|
---|
336 | }
|
---|
337 | if ((irq_status & INT_RISCI) && (chip->reg_control & CTL_ACAP_EN)) {
|
---|
338 | int current_block, irq_block;
|
---|
339 |
|
---|
340 | /* assume that exactly one line has been recorded */
|
---|
341 | chip->current_line = (chip->current_line + 1) % chip->lines;
|
---|
342 | /* but check if some interrupts have been skipped */
|
---|
343 | current_block = chip->current_line * 16 / chip->lines;
|
---|
344 | irq_block = status >> INT_RISCS_SHIFT;
|
---|
345 | if (current_block != irq_block)
|
---|
346 | chip->current_line = (irq_block * chip->lines + 15) / 16;
|
---|
347 |
|
---|
348 | snd_pcm_period_elapsed(chip->substream);
|
---|
349 | }
|
---|
350 | return IRQ_HANDLED;
|
---|
351 | }
|
---|
352 |
|
---|
353 | static struct snd_pcm_hardware snd_bt87x_digital_hw = {
|
---|
354 | .info = SNDRV_PCM_INFO_MMAP |
|
---|
355 | SNDRV_PCM_INFO_INTERLEAVED |
|
---|
356 | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
---|
357 | SNDRV_PCM_INFO_MMAP_VALID |
|
---|
358 | SNDRV_PCM_INFO_BATCH,
|
---|
359 | .formats = SNDRV_PCM_FMTBIT_S16_LE,
|
---|
360 | .rates = 0, /* set at runtime */
|
---|
361 | .channels_min = 2,
|
---|
362 | .channels_max = 2,
|
---|
363 | .buffer_bytes_max = 255 * 4092,
|
---|
364 | .period_bytes_min = 32,
|
---|
365 | .period_bytes_max = 4092,
|
---|
366 | .periods_min = 2,
|
---|
367 | .periods_max = 255,
|
---|
368 | };
|
---|
369 |
|
---|
370 | static struct snd_pcm_hardware snd_bt87x_analog_hw = {
|
---|
371 | .info = SNDRV_PCM_INFO_MMAP |
|
---|
372 | SNDRV_PCM_INFO_INTERLEAVED |
|
---|
373 | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
---|
374 | SNDRV_PCM_INFO_MMAP_VALID |
|
---|
375 | SNDRV_PCM_INFO_BATCH,
|
---|
376 | .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
|
---|
377 | .rates = SNDRV_PCM_RATE_KNOT,
|
---|
378 | .rate_min = ANALOG_CLOCK / CLOCK_DIV_MAX,
|
---|
379 | .rate_max = ANALOG_CLOCK / CLOCK_DIV_MIN,
|
---|
380 | .channels_min = 1,
|
---|
381 | .channels_max = 1,
|
---|
382 | .buffer_bytes_max = 255 * 4092,
|
---|
383 | .period_bytes_min = 32,
|
---|
384 | .period_bytes_max = 4092,
|
---|
385 | .periods_min = 2,
|
---|
386 | .periods_max = 255,
|
---|
387 | };
|
---|
388 |
|
---|
389 | static int snd_bt87x_set_digital_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime)
|
---|
390 | {
|
---|
391 | chip->reg_control |= CTL_DA_IOM_DA | CTL_A_PWRDN;
|
---|
392 | runtime->hw = snd_bt87x_digital_hw;
|
---|
393 | runtime->hw.rates = snd_pcm_rate_to_rate_bit(chip->board.dig_rate);
|
---|
394 | runtime->hw.rate_min = chip->board.dig_rate;
|
---|
395 | runtime->hw.rate_max = chip->board.dig_rate;
|
---|
396 | return 0;
|
---|
397 | }
|
---|
398 |
|
---|
399 | static int snd_bt87x_set_analog_hw(struct snd_bt87x *chip, struct snd_pcm_runtime *runtime)
|
---|
400 | {
|
---|
401 | static struct snd_ratnum analog_clock = {
|
---|
402 | .num = ANALOG_CLOCK,
|
---|
403 | .den_min = CLOCK_DIV_MIN,
|
---|
404 | .den_max = CLOCK_DIV_MAX,
|
---|
405 | .den_step = 1
|
---|
406 | };
|
---|
407 | static struct snd_pcm_hw_constraint_ratnums constraint_rates = {
|
---|
408 | .nrats = 1,
|
---|
409 | .rats = &analog_clock
|
---|
410 | };
|
---|
411 |
|
---|
412 | chip->reg_control &= ~(CTL_DA_IOM_DA | CTL_A_PWRDN);
|
---|
413 | runtime->hw = snd_bt87x_analog_hw;
|
---|
414 | return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
---|
415 | &constraint_rates);
|
---|
416 | }
|
---|
417 |
|
---|
418 | static int snd_bt87x_pcm_open(struct snd_pcm_substream *substream)
|
---|
419 | {
|
---|
420 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
421 | struct snd_pcm_runtime *runtime = substream->runtime;
|
---|
422 | int err;
|
---|
423 |
|
---|
424 | if (test_and_set_bit(0, &chip->opened))
|
---|
425 | return -EBUSY;
|
---|
426 |
|
---|
427 | if (substream->pcm->device == DEVICE_DIGITAL)
|
---|
428 | err = snd_bt87x_set_digital_hw(chip, runtime);
|
---|
429 | else
|
---|
430 | err = snd_bt87x_set_analog_hw(chip, runtime);
|
---|
431 | if (err < 0)
|
---|
432 | goto _error;
|
---|
433 |
|
---|
434 | err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
|
---|
435 | if (err < 0)
|
---|
436 | goto _error;
|
---|
437 |
|
---|
438 | chip->substream = substream;
|
---|
439 | return 0;
|
---|
440 |
|
---|
441 | _error:
|
---|
442 | clear_bit(0, &chip->opened);
|
---|
443 | smp_mb__after_clear_bit();
|
---|
444 | return err;
|
---|
445 | }
|
---|
446 |
|
---|
447 | static int snd_bt87x_close(struct snd_pcm_substream *substream)
|
---|
448 | {
|
---|
449 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
450 |
|
---|
451 | spin_lock_irq(&chip->reg_lock);
|
---|
452 | chip->reg_control |= CTL_A_PWRDN;
|
---|
453 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
454 | spin_unlock_irq(&chip->reg_lock);
|
---|
455 |
|
---|
456 | chip->substream = NULL;
|
---|
457 | clear_bit(0, &chip->opened);
|
---|
458 | smp_mb__after_clear_bit();
|
---|
459 | return 0;
|
---|
460 | }
|
---|
461 |
|
---|
462 | static int snd_bt87x_hw_params(struct snd_pcm_substream *substream,
|
---|
463 | struct snd_pcm_hw_params *hw_params)
|
---|
464 | {
|
---|
465 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
466 | int err;
|
---|
467 |
|
---|
468 | err = snd_pcm_lib_malloc_pages(substream,
|
---|
469 | params_buffer_bytes(hw_params));
|
---|
470 | if (err < 0)
|
---|
471 | return err;
|
---|
472 | return snd_bt87x_create_risc(chip, substream,
|
---|
473 | params_periods(hw_params),
|
---|
474 | params_period_bytes(hw_params));
|
---|
475 | }
|
---|
476 |
|
---|
477 | static int snd_bt87x_hw_free(struct snd_pcm_substream *substream)
|
---|
478 | {
|
---|
479 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
480 |
|
---|
481 | snd_bt87x_free_risc(chip);
|
---|
482 | snd_pcm_lib_free_pages(substream);
|
---|
483 | return 0;
|
---|
484 | }
|
---|
485 |
|
---|
486 | static int snd_bt87x_prepare(struct snd_pcm_substream *substream)
|
---|
487 | {
|
---|
488 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
489 | struct snd_pcm_runtime *runtime = substream->runtime;
|
---|
490 | int decimation;
|
---|
491 |
|
---|
492 | spin_lock_irq(&chip->reg_lock);
|
---|
493 | chip->reg_control &= ~(CTL_DA_SDR_MASK | CTL_DA_SBR);
|
---|
494 | decimation = (ANALOG_CLOCK + runtime->rate / 4) / runtime->rate;
|
---|
495 | chip->reg_control |= decimation << CTL_DA_SDR_SHIFT;
|
---|
496 | if (runtime->format == SNDRV_PCM_FORMAT_S8)
|
---|
497 | chip->reg_control |= CTL_DA_SBR;
|
---|
498 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
499 | spin_unlock_irq(&chip->reg_lock);
|
---|
500 | return 0;
|
---|
501 | }
|
---|
502 |
|
---|
503 | static int snd_bt87x_start(struct snd_bt87x *chip)
|
---|
504 | {
|
---|
505 | spin_lock(&chip->reg_lock);
|
---|
506 | chip->current_line = 0;
|
---|
507 | chip->reg_control |= CTL_FIFO_ENABLE | CTL_RISC_ENABLE | CTL_ACAP_EN;
|
---|
508 | snd_bt87x_writel(chip, REG_RISC_STRT_ADD, chip->dma_risc.addr);
|
---|
509 | snd_bt87x_writel(chip, REG_PACKET_LEN,
|
---|
510 | chip->line_bytes | (chip->lines << 16));
|
---|
511 | snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask);
|
---|
512 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
513 | spin_unlock(&chip->reg_lock);
|
---|
514 | return 0;
|
---|
515 | }
|
---|
516 |
|
---|
517 | static int snd_bt87x_stop(struct snd_bt87x *chip)
|
---|
518 | {
|
---|
519 | spin_lock(&chip->reg_lock);
|
---|
520 | chip->reg_control &= ~(CTL_FIFO_ENABLE | CTL_RISC_ENABLE | CTL_ACAP_EN);
|
---|
521 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
522 | snd_bt87x_writel(chip, REG_INT_MASK, 0);
|
---|
523 | snd_bt87x_writel(chip, REG_INT_STAT, MY_INTERRUPTS);
|
---|
524 | spin_unlock(&chip->reg_lock);
|
---|
525 | return 0;
|
---|
526 | }
|
---|
527 |
|
---|
528 | static int snd_bt87x_trigger(struct snd_pcm_substream *substream, int cmd)
|
---|
529 | {
|
---|
530 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
531 |
|
---|
532 | switch (cmd) {
|
---|
533 | case SNDRV_PCM_TRIGGER_START:
|
---|
534 | return snd_bt87x_start(chip);
|
---|
535 | case SNDRV_PCM_TRIGGER_STOP:
|
---|
536 | return snd_bt87x_stop(chip);
|
---|
537 | default:
|
---|
538 | return -EINVAL;
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 | static snd_pcm_uframes_t snd_bt87x_pointer(struct snd_pcm_substream *substream)
|
---|
543 | {
|
---|
544 | struct snd_bt87x *chip = snd_pcm_substream_chip(substream);
|
---|
545 | struct snd_pcm_runtime *runtime = substream->runtime;
|
---|
546 |
|
---|
547 | return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_line * chip->line_bytes);
|
---|
548 | }
|
---|
549 |
|
---|
550 | static struct snd_pcm_ops snd_bt87x_pcm_ops = {
|
---|
551 | .open = snd_bt87x_pcm_open,
|
---|
552 | .close = snd_bt87x_close,
|
---|
553 | .ioctl = snd_pcm_lib_ioctl,
|
---|
554 | .hw_params = snd_bt87x_hw_params,
|
---|
555 | .hw_free = snd_bt87x_hw_free,
|
---|
556 | .prepare = snd_bt87x_prepare,
|
---|
557 | .trigger = snd_bt87x_trigger,
|
---|
558 | .pointer = snd_bt87x_pointer,
|
---|
559 | .page = snd_pcm_sgbuf_ops_page,
|
---|
560 | };
|
---|
561 |
|
---|
562 | static int snd_bt87x_capture_volume_info(struct snd_kcontrol *kcontrol,
|
---|
563 | struct snd_ctl_elem_info *info)
|
---|
564 | {
|
---|
565 | info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
---|
566 | info->count = 1;
|
---|
567 | info->value.integer.min = 0;
|
---|
568 | info->value.integer.max = 15;
|
---|
569 | return 0;
|
---|
570 | }
|
---|
571 |
|
---|
572 | static int snd_bt87x_capture_volume_get(struct snd_kcontrol *kcontrol,
|
---|
573 | struct snd_ctl_elem_value *value)
|
---|
574 | {
|
---|
575 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
576 |
|
---|
577 | value->value.integer.value[0] = (chip->reg_control & CTL_A_GAIN_MASK) >> CTL_A_GAIN_SHIFT;
|
---|
578 | return 0;
|
---|
579 | }
|
---|
580 |
|
---|
581 | static int snd_bt87x_capture_volume_put(struct snd_kcontrol *kcontrol,
|
---|
582 | struct snd_ctl_elem_value *value)
|
---|
583 | {
|
---|
584 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
585 | u32 old_control;
|
---|
586 | int changed;
|
---|
587 |
|
---|
588 | spin_lock_irq(&chip->reg_lock);
|
---|
589 | old_control = chip->reg_control;
|
---|
590 | chip->reg_control = (chip->reg_control & ~CTL_A_GAIN_MASK)
|
---|
591 | | (value->value.integer.value[0] << CTL_A_GAIN_SHIFT);
|
---|
592 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
593 | changed = old_control != chip->reg_control;
|
---|
594 | spin_unlock_irq(&chip->reg_lock);
|
---|
595 | return changed;
|
---|
596 | }
|
---|
597 |
|
---|
598 | static struct snd_kcontrol_new snd_bt87x_capture_volume = {
|
---|
599 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
600 | .name = "Capture Volume",
|
---|
601 | .info = snd_bt87x_capture_volume_info,
|
---|
602 | .get = snd_bt87x_capture_volume_get,
|
---|
603 | .put = snd_bt87x_capture_volume_put,
|
---|
604 | };
|
---|
605 |
|
---|
606 | #define snd_bt87x_capture_boost_info snd_ctl_boolean_mono_info
|
---|
607 |
|
---|
608 | static int snd_bt87x_capture_boost_get(struct snd_kcontrol *kcontrol,
|
---|
609 | struct snd_ctl_elem_value *value)
|
---|
610 | {
|
---|
611 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
612 |
|
---|
613 | value->value.integer.value[0] = !! (chip->reg_control & CTL_A_G2X);
|
---|
614 | return 0;
|
---|
615 | }
|
---|
616 |
|
---|
617 | static int snd_bt87x_capture_boost_put(struct snd_kcontrol *kcontrol,
|
---|
618 | struct snd_ctl_elem_value *value)
|
---|
619 | {
|
---|
620 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
621 | u32 old_control;
|
---|
622 | int changed;
|
---|
623 |
|
---|
624 | spin_lock_irq(&chip->reg_lock);
|
---|
625 | old_control = chip->reg_control;
|
---|
626 | chip->reg_control = (chip->reg_control & ~CTL_A_G2X)
|
---|
627 | | (value->value.integer.value[0] ? CTL_A_G2X : 0);
|
---|
628 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
629 | changed = chip->reg_control != old_control;
|
---|
630 | spin_unlock_irq(&chip->reg_lock);
|
---|
631 | return changed;
|
---|
632 | }
|
---|
633 |
|
---|
634 | static struct snd_kcontrol_new snd_bt87x_capture_boost = {
|
---|
635 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
636 | .name = "Capture Boost",
|
---|
637 | .info = snd_bt87x_capture_boost_info,
|
---|
638 | .get = snd_bt87x_capture_boost_get,
|
---|
639 | .put = snd_bt87x_capture_boost_put,
|
---|
640 | };
|
---|
641 |
|
---|
642 | static int snd_bt87x_capture_source_info(struct snd_kcontrol *kcontrol,
|
---|
643 | struct snd_ctl_elem_info *info)
|
---|
644 | {
|
---|
645 | static const char *const texts[3] = {"TV Tuner", "FM", "Mic/Line"};
|
---|
646 |
|
---|
647 | return snd_ctl_enum_info(info, 1, 3, texts);
|
---|
648 | }
|
---|
649 |
|
---|
650 | static int snd_bt87x_capture_source_get(struct snd_kcontrol *kcontrol,
|
---|
651 | struct snd_ctl_elem_value *value)
|
---|
652 | {
|
---|
653 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
654 |
|
---|
655 | value->value.enumerated.item[0] = (chip->reg_control & CTL_A_SEL_MASK) >> CTL_A_SEL_SHIFT;
|
---|
656 | return 0;
|
---|
657 | }
|
---|
658 |
|
---|
659 | static int snd_bt87x_capture_source_put(struct snd_kcontrol *kcontrol,
|
---|
660 | struct snd_ctl_elem_value *value)
|
---|
661 | {
|
---|
662 | struct snd_bt87x *chip = snd_kcontrol_chip(kcontrol);
|
---|
663 | u32 old_control;
|
---|
664 | int changed;
|
---|
665 |
|
---|
666 | spin_lock_irq(&chip->reg_lock);
|
---|
667 | old_control = chip->reg_control;
|
---|
668 | chip->reg_control = (chip->reg_control & ~CTL_A_SEL_MASK)
|
---|
669 | | (value->value.enumerated.item[0] << CTL_A_SEL_SHIFT);
|
---|
670 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
671 | changed = chip->reg_control != old_control;
|
---|
672 | spin_unlock_irq(&chip->reg_lock);
|
---|
673 | return changed;
|
---|
674 | }
|
---|
675 |
|
---|
676 | static struct snd_kcontrol_new snd_bt87x_capture_source = {
|
---|
677 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
---|
678 | .name = "Capture Source",
|
---|
679 | .info = snd_bt87x_capture_source_info,
|
---|
680 | .get = snd_bt87x_capture_source_get,
|
---|
681 | .put = snd_bt87x_capture_source_put,
|
---|
682 | };
|
---|
683 |
|
---|
684 | static int snd_bt87x_free(struct snd_bt87x *chip)
|
---|
685 | {
|
---|
686 | if (chip->mmio)
|
---|
687 | snd_bt87x_stop(chip);
|
---|
688 | if (chip->irq >= 0)
|
---|
689 | free_irq(chip->irq, chip);
|
---|
690 | if (chip->mmio)
|
---|
691 | iounmap(chip->mmio);
|
---|
692 | pci_release_regions(chip->pci);
|
---|
693 | pci_disable_device(chip->pci);
|
---|
694 | kfree(chip);
|
---|
695 | return 0;
|
---|
696 | }
|
---|
697 |
|
---|
698 | static int snd_bt87x_dev_free(struct snd_device *device)
|
---|
699 | {
|
---|
700 | struct snd_bt87x *chip = device->device_data;
|
---|
701 | return snd_bt87x_free(chip);
|
---|
702 | }
|
---|
703 |
|
---|
704 | static int __devinit snd_bt87x_pcm(struct snd_bt87x *chip, int device, char *name)
|
---|
705 | {
|
---|
706 | int err;
|
---|
707 | struct snd_pcm *pcm;
|
---|
708 |
|
---|
709 | err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
|
---|
710 | if (err < 0)
|
---|
711 | return err;
|
---|
712 | pcm->private_data = chip;
|
---|
713 | strcpy(pcm->name, name);
|
---|
714 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_bt87x_pcm_ops);
|
---|
715 | return snd_pcm_lib_preallocate_pages_for_all(pcm,
|
---|
716 | SNDRV_DMA_TYPE_DEV_SG,
|
---|
717 | snd_dma_pci_data(chip->pci),
|
---|
718 | 128 * 1024,
|
---|
719 | ALIGN(255 * 4092, 1024));
|
---|
720 | }
|
---|
721 |
|
---|
722 | static int __devinit snd_bt87x_create(struct snd_card *card,
|
---|
723 | struct pci_dev *pci,
|
---|
724 | struct snd_bt87x **rchip)
|
---|
725 | {
|
---|
726 | struct snd_bt87x *chip;
|
---|
727 | int err;
|
---|
728 | static struct snd_device_ops ops = {
|
---|
729 | .dev_free = snd_bt87x_dev_free
|
---|
730 | };
|
---|
731 |
|
---|
732 | *rchip = NULL;
|
---|
733 |
|
---|
734 | err = pci_enable_device(pci);
|
---|
735 | if (err < 0)
|
---|
736 | return err;
|
---|
737 |
|
---|
738 | chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
---|
739 | if (!chip) {
|
---|
740 | pci_disable_device(pci);
|
---|
741 | return -ENOMEM;
|
---|
742 | }
|
---|
743 | chip->card = card;
|
---|
744 | chip->pci = pci;
|
---|
745 | chip->irq = -1;
|
---|
746 | spin_lock_init(&chip->reg_lock);
|
---|
747 |
|
---|
748 | if ((err = pci_request_regions(pci, "Bt87x audio")) < 0) {
|
---|
749 | kfree(chip);
|
---|
750 | pci_disable_device(pci);
|
---|
751 | return err;
|
---|
752 | }
|
---|
753 | chip->mmio = pci_ioremap_bar(pci, 0);
|
---|
754 | if (!chip->mmio) {
|
---|
755 | snd_printk(KERN_ERR "cannot remap io memory\n");
|
---|
756 | err = -ENOMEM;
|
---|
757 | goto fail;
|
---|
758 | }
|
---|
759 |
|
---|
760 | chip->reg_control = CTL_A_PWRDN | CTL_DA_ES2 |
|
---|
761 | CTL_PKTP_16 | (15 << CTL_DA_SDR_SHIFT);
|
---|
762 | chip->interrupt_mask = MY_INTERRUPTS;
|
---|
763 | snd_bt87x_writel(chip, REG_GPIO_DMA_CTL, chip->reg_control);
|
---|
764 | snd_bt87x_writel(chip, REG_INT_MASK, 0);
|
---|
765 | snd_bt87x_writel(chip, REG_INT_STAT, MY_INTERRUPTS);
|
---|
766 |
|
---|
767 | err = request_irq(pci->irq, snd_bt87x_interrupt, IRQF_SHARED,
|
---|
768 | "Bt87x audio", chip);
|
---|
769 | if (err < 0) {
|
---|
770 | snd_printk(KERN_ERR "cannot grab irq %d\n", pci->irq);
|
---|
771 | goto fail;
|
---|
772 | }
|
---|
773 | chip->irq = pci->irq;
|
---|
774 | pci_set_master(pci);
|
---|
775 | synchronize_irq(chip->irq);
|
---|
776 |
|
---|
777 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
---|
778 | if (err < 0)
|
---|
779 | goto fail;
|
---|
780 |
|
---|
781 | snd_card_set_dev(card, &pci->dev);
|
---|
782 | *rchip = chip;
|
---|
783 | return 0;
|
---|
784 |
|
---|
785 | fail:
|
---|
786 | snd_bt87x_free(chip);
|
---|
787 | return err;
|
---|
788 | }
|
---|
789 |
|
---|
790 | #define BT_DEVICE(chip, subvend, subdev, id) \
|
---|
791 | { .vendor = PCI_VENDOR_ID_BROOKTREE, \
|
---|
792 | .device = chip, \
|
---|
793 | .subvendor = subvend, .subdevice = subdev, \
|
---|
794 | .driver_data = SND_BT87X_BOARD_ ## id }
|
---|
795 | /* driver_data is the card id for that device */
|
---|
796 |
|
---|
797 | static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_ids) = {
|
---|
798 | /* Hauppauge WinTV series */
|
---|
799 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0x13eb, GENERIC),
|
---|
800 | /* Hauppauge WinTV series */
|
---|
801 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, 0x0070, 0x13eb, GENERIC),
|
---|
802 | /* Viewcast Osprey 200 */
|
---|
803 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0xff01, OSPREY2x0),
|
---|
804 | /* Viewcast Osprey 440 (rate is configurable via gpio) */
|
---|
805 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x0070, 0xff07, OSPREY440),
|
---|
806 | /* ATI TV-Wonder */
|
---|
807 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1002, 0x0001, GENERIC),
|
---|
808 | /* Leadtek Winfast tv 2000xp delux */
|
---|
809 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x107d, 0x6606, GENERIC),
|
---|
810 | /* Pinnacle PCTV */
|
---|
811 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x11bd, 0x0012, GENERIC),
|
---|
812 | /* Voodoo TV 200 */
|
---|
813 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x121a, 0x3000, GENERIC),
|
---|
814 | /* Askey Computer Corp. MagicTView'99 */
|
---|
815 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x144f, 0x3000, GENERIC),
|
---|
816 | /* AVerMedia Studio No. 103, 203, ...? */
|
---|
817 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1461, 0x0003, AVPHONE98),
|
---|
818 | /* Prolink PixelView PV-M4900 */
|
---|
819 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1554, 0x4011, GENERIC),
|
---|
820 | /* Pinnacle Studio PCTV rave */
|
---|
821 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0xbd11, 0x1200, GENERIC),
|
---|
822 | {0}
|
---|
823 | };
|
---|
824 | MODULE_DEVICE_TABLE(pci, snd_bt87x_ids);
|
---|
825 |
|
---|
826 | /* cards known not to have audio
|
---|
827 | * (DVB cards use the audio function to transfer MPEG data) */
|
---|
828 | static struct {
|
---|
829 | unsigned short subvendor, subdevice;
|
---|
830 | } blacklist[] __devinitdata = {
|
---|
831 | {0x0071, 0x0101}, /* Nebula Electronics DigiTV */
|
---|
832 | {0x11bd, 0x001c}, /* Pinnacle PCTV Sat */
|
---|
833 | {0x11bd, 0x0026}, /* Pinnacle PCTV SAT CI */
|
---|
834 | {0x1461, 0x0761}, /* AVermedia AverTV DVB-T */
|
---|
835 | {0x1461, 0x0771}, /* AVermedia DVB-T 771 */
|
---|
836 | {0x1822, 0x0001}, /* Twinhan VisionPlus DVB-T */
|
---|
837 | {0x18ac, 0xd500}, /* DVICO FusionHDTV 5 Lite */
|
---|
838 | {0x18ac, 0xdb10}, /* DVICO FusionHDTV DVB-T Lite */
|
---|
839 | {0x18ac, 0xdb11}, /* Ultraview DVB-T Lite */
|
---|
840 | {0x270f, 0xfc00}, /* Chaintech Digitop DST-1000 DVB-S */
|
---|
841 | {0x7063, 0x2000}, /* pcHDTV HD-2000 TV */
|
---|
842 | };
|
---|
843 |
|
---|
844 | static struct pci_driver driver;
|
---|
845 |
|
---|
846 | /* return the id of the card, or a negative value if it's blacklisted */
|
---|
847 | static int __devinit snd_bt87x_detect_card(struct pci_dev *pci)
|
---|
848 | {
|
---|
849 | int i;
|
---|
850 | const struct pci_device_id *supported;
|
---|
851 | #ifdef TARGET_OS2
|
---|
852 | u16 subsystem_vendor, subsystem_device;
|
---|
853 | #endif
|
---|
854 |
|
---|
855 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
|
---|
856 | supported = pci_match_id(snd_bt87x_ids, pci);
|
---|
857 | #else
|
---|
858 | supported = pci_match_device(snd_bt87x_ids, pci);
|
---|
859 | #endif
|
---|
860 | if (supported && supported->driver_data > 0)
|
---|
861 | return supported->driver_data;
|
---|
862 |
|
---|
863 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 0)
|
---|
864 | subsystem_vendor = pci->subsystem_vendor;
|
---|
865 | subsystem_device = pci->subsystem_device;
|
---|
866 | #else
|
---|
867 | pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
|
---|
868 | pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
|
---|
869 | #endif
|
---|
870 | for (i = 0; i < ARRAY_SIZE(blacklist); ++i)
|
---|
871 | #ifndef TARGET_OS2
|
---|
872 | if (blacklist[i].subvendor == pci->subsystem_vendor &&
|
---|
873 | blacklist[i].subdevice == pci->subsystem_device) {
|
---|
874 | #else
|
---|
875 | if (blacklist[i].subvendor == subsystem_vendor &&
|
---|
876 | blacklist[i].subdevice == subsystem_device) {
|
---|
877 | #endif
|
---|
878 | snd_printdd(KERN_INFO "card %#04x-%#04x:%#04x has no audio\n",
|
---|
879 | #ifndef TARGET_OS2
|
---|
880 | pci->device, pci->subsystem_vendor, pci->subsystem_device);
|
---|
881 | #else
|
---|
882 | pci->device, subsystem_vendor, subsystem_device);
|
---|
883 | #endif
|
---|
884 | return -EBUSY;
|
---|
885 | }
|
---|
886 |
|
---|
887 | snd_printk(KERN_INFO "unknown card %#04x-%#04x:%#04x\n",
|
---|
888 | #ifndef TARGET_OS2
|
---|
889 | pci->device, pci->subsystem_vendor, pci->subsystem_device);
|
---|
890 | #else
|
---|
891 | pci->device, subsystem_vendor, subsystem_device);
|
---|
892 | #endif
|
---|
893 | snd_printk(KERN_DEBUG "please mail id, board name, and, "
|
---|
894 | "if it works, the correct digital_rate option to "
|
---|
895 | "<alsa-devel@alsa-project.org>\n");
|
---|
896 | return SND_BT87X_BOARD_UNKNOWN;
|
---|
897 | }
|
---|
898 |
|
---|
899 | static int __devinit snd_bt87x_probe(struct pci_dev *pci,
|
---|
900 | const struct pci_device_id *pci_id)
|
---|
901 | {
|
---|
902 | static int dev;
|
---|
903 | struct snd_card *card;
|
---|
904 | struct snd_bt87x *chip;
|
---|
905 | int err;
|
---|
906 | enum snd_bt87x_boardid boardid;
|
---|
907 |
|
---|
908 | if (!pci_id->driver_data) {
|
---|
909 | err = snd_bt87x_detect_card(pci);
|
---|
910 | if (err < 0)
|
---|
911 | return -ENODEV;
|
---|
912 | boardid = err;
|
---|
913 | } else
|
---|
914 | boardid = pci_id->driver_data;
|
---|
915 |
|
---|
916 | if (dev >= SNDRV_CARDS)
|
---|
917 | return -ENODEV;
|
---|
918 | if (!enable[dev]) {
|
---|
919 | ++dev;
|
---|
920 | return -ENOENT;
|
---|
921 | }
|
---|
922 |
|
---|
923 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
|
---|
924 | if (err < 0)
|
---|
925 | return err;
|
---|
926 |
|
---|
927 | err = snd_bt87x_create(card, pci, &chip);
|
---|
928 | if (err < 0)
|
---|
929 | goto _error;
|
---|
930 |
|
---|
931 | memcpy(&chip->board, &snd_bt87x_boards[boardid], sizeof(chip->board));
|
---|
932 |
|
---|
933 | if (!chip->board.no_digital) {
|
---|
934 | if (digital_rate[dev] > 0)
|
---|
935 | chip->board.dig_rate = digital_rate[dev];
|
---|
936 |
|
---|
937 | chip->reg_control |= chip->board.digital_fmt;
|
---|
938 |
|
---|
939 | err = snd_bt87x_pcm(chip, DEVICE_DIGITAL, "Bt87x Digital");
|
---|
940 | if (err < 0)
|
---|
941 | goto _error;
|
---|
942 | }
|
---|
943 | if (!chip->board.no_analog) {
|
---|
944 | err = snd_bt87x_pcm(chip, DEVICE_ANALOG, "Bt87x Analog");
|
---|
945 | if (err < 0)
|
---|
946 | goto _error;
|
---|
947 | err = snd_ctl_add(card, snd_ctl_new1(
|
---|
948 | &snd_bt87x_capture_volume, chip));
|
---|
949 | if (err < 0)
|
---|
950 | goto _error;
|
---|
951 | err = snd_ctl_add(card, snd_ctl_new1(
|
---|
952 | &snd_bt87x_capture_boost, chip));
|
---|
953 | if (err < 0)
|
---|
954 | goto _error;
|
---|
955 | err = snd_ctl_add(card, snd_ctl_new1(
|
---|
956 | &snd_bt87x_capture_source, chip));
|
---|
957 | if (err < 0)
|
---|
958 | goto _error;
|
---|
959 | }
|
---|
960 | snd_printk(KERN_INFO "bt87x%d: Using board %d, %sanalog, %sdigital "
|
---|
961 | "(rate %d Hz)\n", dev, boardid,
|
---|
962 | chip->board.no_analog ? "no " : "",
|
---|
963 | chip->board.no_digital ? "no " : "", chip->board.dig_rate);
|
---|
964 |
|
---|
965 | strcpy(card->driver, "Bt87x");
|
---|
966 | sprintf(card->shortname, "Brooktree Bt%x", pci->device);
|
---|
967 | sprintf(card->longname, "%s at %#llx, irq %i",
|
---|
968 | card->shortname, (unsigned long long)pci_resource_start(pci, 0),
|
---|
969 | chip->irq);
|
---|
970 | strcpy(card->mixername, "Bt87x");
|
---|
971 |
|
---|
972 | err = snd_card_register(card);
|
---|
973 | if (err < 0)
|
---|
974 | goto _error;
|
---|
975 |
|
---|
976 | pci_set_drvdata(pci, card);
|
---|
977 | ++dev;
|
---|
978 | return 0;
|
---|
979 |
|
---|
980 | _error:
|
---|
981 | snd_card_free(card);
|
---|
982 | return err;
|
---|
983 | }
|
---|
984 |
|
---|
985 | static void __devexit snd_bt87x_remove(struct pci_dev *pci)
|
---|
986 | {
|
---|
987 | snd_card_free(pci_get_drvdata(pci));
|
---|
988 | pci_set_drvdata(pci, NULL);
|
---|
989 | }
|
---|
990 |
|
---|
991 | /* default entries for all Bt87x cards - it's not exported */
|
---|
992 | /* driver_data is set to 0 to call detection */
|
---|
993 | static DEFINE_PCI_DEVICE_TABLE(snd_bt87x_default_ids) = {
|
---|
994 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
|
---|
995 | BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_879, PCI_ANY_ID, PCI_ANY_ID, UNKNOWN),
|
---|
996 | {0}
|
---|
997 | };
|
---|
998 |
|
---|
999 | static struct pci_driver driver = {
|
---|
1000 | .name = "Bt87x",
|
---|
1001 | .id_table = snd_bt87x_ids,
|
---|
1002 | .probe = snd_bt87x_probe,
|
---|
1003 | .remove = __devexit_p(snd_bt87x_remove),
|
---|
1004 | };
|
---|
1005 |
|
---|
1006 | static int __init alsa_card_bt87x_init(void)
|
---|
1007 | {
|
---|
1008 | if (load_all)
|
---|
1009 | driver.id_table = snd_bt87x_default_ids;
|
---|
1010 | return pci_register_driver(&driver);
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | static void __exit alsa_card_bt87x_exit(void)
|
---|
1014 | {
|
---|
1015 | pci_unregister_driver(&driver);
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | module_init(alsa_card_bt87x_init)
|
---|
1019 | module_exit(alsa_card_bt87x_exit)
|
---|