2 * The driver for the ForteMedia FM801 based soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/delay.h>
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 <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/ac97_codec.h>
32 #include <sound/mpu401.h>
33 #include <sound/opl3.h>
34 #include <sound/initval.h>
38 #if (defined(CONFIG_SND_FM801_TEA575X) || defined(CONFIG_SND_FM801_TEA575X_MODULE)) && (defined(CONFIG_VIDEO_DEV) || defined(CONFIG_VIDEO_DEV_MODULE))
39 #include <sound/tea575x-tuner.h>
40 #define TEA575X_RADIO 1
43 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
44 MODULE_DESCRIPTION("ForteMedia FM801");
45 MODULE_LICENSE("GPL");
46 MODULE_SUPPORTED_DEVICE("{{ForteMedia,FM801},"
47 "{Genius,SoundMaker Live 5.1}}");
49 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
50 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
51 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable this card */
53 * Enable TEA575x tuner
54 * 1 = MediaForte 256-PCS
55 * 2 = MediaForte 256-PCPR
56 * 3 = MediaForte 64-PCR
57 * High 16-bits are video (radio) device number + 1
59 static int tea575x_tuner
[SNDRV_CARDS
] = { [0 ... (SNDRV_CARDS
-1)] = 0 };
61 module_param_array(index
, int, NULL
, 0444);
62 MODULE_PARM_DESC(index
, "Index value for the FM801 soundcard.");
63 module_param_array(id
, charp
, NULL
, 0444);
64 MODULE_PARM_DESC(id
, "ID string for the FM801 soundcard.");
65 module_param_array(enable
, bool, NULL
, 0444);
66 MODULE_PARM_DESC(enable
, "Enable FM801 soundcard.");
67 module_param_array(tea575x_tuner
, int, NULL
, 0444);
68 MODULE_PARM_DESC(tea575x_tuner
, "Enable TEA575x tuner.");
74 #define FM801_REG(chip, reg) (chip->port + FM801_##reg)
76 #define FM801_PCM_VOL 0x00 /* PCM Output Volume */
77 #define FM801_FM_VOL 0x02 /* FM Output Volume */
78 #define FM801_I2S_VOL 0x04 /* I2S Volume */
79 #define FM801_REC_SRC 0x06 /* Record Source */
80 #define FM801_PLY_CTRL 0x08 /* Playback Control */
81 #define FM801_PLY_COUNT 0x0a /* Playback Count */
82 #define FM801_PLY_BUF1 0x0c /* Playback Bufer I */
83 #define FM801_PLY_BUF2 0x10 /* Playback Buffer II */
84 #define FM801_CAP_CTRL 0x14 /* Capture Control */
85 #define FM801_CAP_COUNT 0x16 /* Capture Count */
86 #define FM801_CAP_BUF1 0x18 /* Capture Buffer I */
87 #define FM801_CAP_BUF2 0x1c /* Capture Buffer II */
88 #define FM801_CODEC_CTRL 0x22 /* Codec Control */
89 #define FM801_I2S_MODE 0x24 /* I2S Mode Control */
90 #define FM801_VOLUME 0x26 /* Volume Up/Down/Mute Status */
91 #define FM801_I2C_CTRL 0x29 /* I2C Control */
92 #define FM801_AC97_CMD 0x2a /* AC'97 Command */
93 #define FM801_AC97_DATA 0x2c /* AC'97 Data */
94 #define FM801_MPU401_DATA 0x30 /* MPU401 Data */
95 #define FM801_MPU401_CMD 0x31 /* MPU401 Command */
96 #define FM801_GPIO_CTRL 0x52 /* General Purpose I/O Control */
97 #define FM801_GEN_CTRL 0x54 /* General Control */
98 #define FM801_IRQ_MASK 0x56 /* Interrupt Mask */
99 #define FM801_IRQ_STATUS 0x5a /* Interrupt Status */
100 #define FM801_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */
101 #define FM801_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */
102 #define FM801_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */
103 #define FM801_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
104 #define FM801_POWERDOWN 0x70 /* Blocks Power Down Control */
106 #define FM801_AC97_ADDR_SHIFT 10
108 /* playback and record control register bits */
109 #define FM801_BUF1_LAST (1<<1)
110 #define FM801_BUF2_LAST (1<<2)
111 #define FM801_START (1<<5)
112 #define FM801_PAUSE (1<<6)
113 #define FM801_IMMED_STOP (1<<7)
114 #define FM801_RATE_SHIFT 8
115 #define FM801_RATE_MASK (15 << FM801_RATE_SHIFT)
116 #define FM801_CHANNELS_4 (1<<12) /* playback only */
117 #define FM801_CHANNELS_6 (2<<12) /* playback only */
118 #define FM801_CHANNELS_6MS (3<<12) /* playback only */
119 #define FM801_CHANNELS_MASK (3<<12)
120 #define FM801_16BIT (1<<14)
121 #define FM801_STEREO (1<<15)
123 /* IRQ status bits */
124 #define FM801_IRQ_PLAYBACK (1<<8)
125 #define FM801_IRQ_CAPTURE (1<<9)
126 #define FM801_IRQ_VOLUME (1<<14)
127 #define FM801_IRQ_MPU (1<<15)
129 /* GPIO control register */
130 #define FM801_GPIO_GP0 (1<<0) /* read/write */
131 #define FM801_GPIO_GP1 (1<<1)
132 #define FM801_GPIO_GP2 (1<<2)
133 #define FM801_GPIO_GP3 (1<<3)
134 #define FM801_GPIO_GP(x) (1<<(0+(x)))
135 #define FM801_GPIO_GD0 (1<<8) /* directions: 1 = input, 0 = output*/
136 #define FM801_GPIO_GD1 (1<<9)
137 #define FM801_GPIO_GD2 (1<<10)
138 #define FM801_GPIO_GD3 (1<<11)
139 #define FM801_GPIO_GD(x) (1<<(8+(x)))
140 #define FM801_GPIO_GS0 (1<<12) /* function select: */
141 #define FM801_GPIO_GS1 (1<<13) /* 1 = GPIO */
142 #define FM801_GPIO_GS2 (1<<14) /* 0 = other (S/PDIF, VOL) */
143 #define FM801_GPIO_GS3 (1<<15)
144 #define FM801_GPIO_GS(x) (1<<(12+(x)))
150 typedef struct _snd_fm801 fm801_t
;
155 unsigned long port
; /* I/O port number */
156 unsigned int multichannel
: 1, /* multichannel support */
157 secondary
: 1; /* secondary codec */
158 unsigned char secondary_addr
; /* address of the secondary codec */
160 unsigned short ply_ctrl
; /* playback control */
161 unsigned short cap_ctrl
; /* capture control */
163 unsigned long ply_buffer
;
164 unsigned int ply_buf
;
165 unsigned int ply_count
;
166 unsigned int ply_size
;
167 unsigned int ply_pos
;
169 unsigned long cap_buffer
;
170 unsigned int cap_buf
;
171 unsigned int cap_count
;
172 unsigned int cap_size
;
173 unsigned int cap_pos
;
175 ac97_bus_t
*ac97_bus
;
182 snd_rawmidi_t
*rmidi
;
183 snd_pcm_substream_t
*playback_substream
;
184 snd_pcm_substream_t
*capture_substream
;
185 unsigned int p_dma_size
;
186 unsigned int c_dma_size
;
189 snd_info_entry_t
*proc_entry
;
196 static struct pci_device_id snd_fm801_ids
[] = {
197 { 0x1319, 0x0801, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_MULTIMEDIA_AUDIO
<< 8, 0xffff00, 0, }, /* FM801 */
201 MODULE_DEVICE_TABLE(pci
, snd_fm801_ids
);
204 * common I/O routines
207 static int snd_fm801_update_bits(fm801_t
*chip
, unsigned short reg
,
208 unsigned short mask
, unsigned short value
)
212 unsigned short old
, new;
214 spin_lock_irqsave(&chip
->reg_lock
, flags
);
215 old
= inw(chip
->port
+ reg
);
216 new = (old
& ~mask
) | value
;
219 outw(new, chip
->port
+ reg
);
220 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
224 static void snd_fm801_codec_write(ac97_t
*ac97
,
228 fm801_t
*chip
= ac97
->private_data
;
232 * Wait until the codec interface is not ready..
234 for (idx
= 0; idx
< 100; idx
++) {
235 if (!(inw(FM801_REG(chip
, AC97_CMD
)) & (1<<9)))
239 snd_printk("AC'97 interface is busy (1)\n");
243 /* write data and address */
244 outw(val
, FM801_REG(chip
, AC97_DATA
));
245 outw(reg
| (ac97
->addr
<< FM801_AC97_ADDR_SHIFT
), FM801_REG(chip
, AC97_CMD
));
247 * Wait until the write command is not completed..
249 for (idx
= 0; idx
< 1000; idx
++) {
250 if (!(inw(FM801_REG(chip
, AC97_CMD
)) & (1<<9)))
254 snd_printk("AC'97 interface #%d is busy (2)\n", ac97
->num
);
257 static unsigned short snd_fm801_codec_read(ac97_t
*ac97
, unsigned short reg
)
259 fm801_t
*chip
= ac97
->private_data
;
263 * Wait until the codec interface is not ready..
265 for (idx
= 0; idx
< 100; idx
++) {
266 if (!(inw(FM801_REG(chip
, AC97_CMD
)) & (1<<9)))
270 snd_printk("AC'97 interface is busy (1)\n");
275 outw(reg
| (ac97
->addr
<< FM801_AC97_ADDR_SHIFT
) | (1<<7), FM801_REG(chip
, AC97_CMD
));
276 for (idx
= 0; idx
< 100; idx
++) {
277 if (!(inw(FM801_REG(chip
, AC97_CMD
)) & (1<<9)))
281 snd_printk("AC'97 interface #%d is busy (2)\n", ac97
->num
);
285 for (idx
= 0; idx
< 1000; idx
++) {
286 if (inw(FM801_REG(chip
, AC97_CMD
)) & (1<<8))
290 snd_printk("AC'97 interface #%d is not valid (2)\n", ac97
->num
);
294 return inw(FM801_REG(chip
, AC97_DATA
));
297 static unsigned int rates
[] = {
298 5500, 8000, 9600, 11025,
299 16000, 19200, 22050, 32000,
303 static snd_pcm_hw_constraint_list_t hw_constraints_rates
= {
304 .count
= ARRAY_SIZE(rates
),
309 static unsigned int channels
[] = {
313 #define CHANNELS sizeof(channels) / sizeof(channels[0])
315 static snd_pcm_hw_constraint_list_t hw_constraints_channels
= {
322 * Sample rate routines
325 static unsigned short snd_fm801_rate_bits(unsigned int rate
)
329 for (idx
= 0; idx
< ARRAY_SIZE(rates
); idx
++)
330 if (rates
[idx
] == rate
)
333 return ARRAY_SIZE(rates
) - 1;
340 static int snd_fm801_playback_trigger(snd_pcm_substream_t
* substream
,
343 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
345 spin_lock(&chip
->reg_lock
);
347 case SNDRV_PCM_TRIGGER_START
:
348 chip
->ply_ctrl
&= ~(FM801_BUF1_LAST
|
351 chip
->ply_ctrl
|= FM801_START
|
354 case SNDRV_PCM_TRIGGER_STOP
:
355 chip
->ply_ctrl
&= ~(FM801_START
| FM801_PAUSE
);
357 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
358 chip
->ply_ctrl
|= FM801_PAUSE
;
360 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
361 chip
->ply_ctrl
&= ~FM801_PAUSE
;
364 spin_unlock(&chip
->reg_lock
);
368 outw(chip
->ply_ctrl
, FM801_REG(chip
, PLY_CTRL
));
369 spin_unlock(&chip
->reg_lock
);
373 static int snd_fm801_capture_trigger(snd_pcm_substream_t
* substream
,
376 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
378 spin_lock(&chip
->reg_lock
);
380 case SNDRV_PCM_TRIGGER_START
:
381 chip
->cap_ctrl
&= ~(FM801_BUF1_LAST
|
384 chip
->cap_ctrl
|= FM801_START
|
387 case SNDRV_PCM_TRIGGER_STOP
:
388 chip
->cap_ctrl
&= ~(FM801_START
| FM801_PAUSE
);
390 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
391 chip
->cap_ctrl
|= FM801_PAUSE
;
393 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
394 chip
->cap_ctrl
&= ~FM801_PAUSE
;
397 spin_unlock(&chip
->reg_lock
);
401 outw(chip
->cap_ctrl
, FM801_REG(chip
, CAP_CTRL
));
402 spin_unlock(&chip
->reg_lock
);
406 static int snd_fm801_hw_params(snd_pcm_substream_t
* substream
,
407 snd_pcm_hw_params_t
* hw_params
)
409 return snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(hw_params
));
412 static int snd_fm801_hw_free(snd_pcm_substream_t
* substream
)
414 return snd_pcm_lib_free_pages(substream
);
417 static int snd_fm801_playback_prepare(snd_pcm_substream_t
* substream
)
419 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
420 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
422 chip
->ply_size
= snd_pcm_lib_buffer_bytes(substream
);
423 chip
->ply_count
= snd_pcm_lib_period_bytes(substream
);
424 spin_lock_irq(&chip
->reg_lock
);
425 chip
->ply_ctrl
&= ~(FM801_START
| FM801_16BIT
|
426 FM801_STEREO
| FM801_RATE_MASK
|
427 FM801_CHANNELS_MASK
);
428 if (snd_pcm_format_width(runtime
->format
) == 16)
429 chip
->ply_ctrl
|= FM801_16BIT
;
430 if (runtime
->channels
> 1) {
431 chip
->ply_ctrl
|= FM801_STEREO
;
432 if (runtime
->channels
== 4)
433 chip
->ply_ctrl
|= FM801_CHANNELS_4
;
434 else if (runtime
->channels
== 6)
435 chip
->ply_ctrl
|= FM801_CHANNELS_6
;
437 chip
->ply_ctrl
|= snd_fm801_rate_bits(runtime
->rate
) << FM801_RATE_SHIFT
;
439 outw(chip
->ply_ctrl
, FM801_REG(chip
, PLY_CTRL
));
440 outw(chip
->ply_count
- 1, FM801_REG(chip
, PLY_COUNT
));
441 chip
->ply_buffer
= runtime
->dma_addr
;
443 outl(chip
->ply_buffer
, FM801_REG(chip
, PLY_BUF1
));
444 outl(chip
->ply_buffer
+ (chip
->ply_count
% chip
->ply_size
), FM801_REG(chip
, PLY_BUF2
));
445 spin_unlock_irq(&chip
->reg_lock
);
449 static int snd_fm801_capture_prepare(snd_pcm_substream_t
* substream
)
451 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
452 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
454 chip
->cap_size
= snd_pcm_lib_buffer_bytes(substream
);
455 chip
->cap_count
= snd_pcm_lib_period_bytes(substream
);
456 spin_lock_irq(&chip
->reg_lock
);
457 chip
->cap_ctrl
&= ~(FM801_START
| FM801_16BIT
|
458 FM801_STEREO
| FM801_RATE_MASK
);
459 if (snd_pcm_format_width(runtime
->format
) == 16)
460 chip
->cap_ctrl
|= FM801_16BIT
;
461 if (runtime
->channels
> 1)
462 chip
->cap_ctrl
|= FM801_STEREO
;
463 chip
->cap_ctrl
|= snd_fm801_rate_bits(runtime
->rate
) << FM801_RATE_SHIFT
;
465 outw(chip
->cap_ctrl
, FM801_REG(chip
, CAP_CTRL
));
466 outw(chip
->cap_count
- 1, FM801_REG(chip
, CAP_COUNT
));
467 chip
->cap_buffer
= runtime
->dma_addr
;
469 outl(chip
->cap_buffer
, FM801_REG(chip
, CAP_BUF1
));
470 outl(chip
->cap_buffer
+ (chip
->cap_count
% chip
->cap_size
), FM801_REG(chip
, CAP_BUF2
));
471 spin_unlock_irq(&chip
->reg_lock
);
475 static snd_pcm_uframes_t
snd_fm801_playback_pointer(snd_pcm_substream_t
* substream
)
477 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
480 if (!(chip
->ply_ctrl
& FM801_START
))
482 spin_lock(&chip
->reg_lock
);
483 ptr
= chip
->ply_pos
+ (chip
->ply_count
- 1) - inw(FM801_REG(chip
, PLY_COUNT
));
484 if (inw(FM801_REG(chip
, IRQ_STATUS
)) & FM801_IRQ_PLAYBACK
) {
485 ptr
+= chip
->ply_count
;
486 ptr
%= chip
->ply_size
;
488 spin_unlock(&chip
->reg_lock
);
489 return bytes_to_frames(substream
->runtime
, ptr
);
492 static snd_pcm_uframes_t
snd_fm801_capture_pointer(snd_pcm_substream_t
* substream
)
494 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
497 if (!(chip
->cap_ctrl
& FM801_START
))
499 spin_lock(&chip
->reg_lock
);
500 ptr
= chip
->cap_pos
+ (chip
->cap_count
- 1) - inw(FM801_REG(chip
, CAP_COUNT
));
501 if (inw(FM801_REG(chip
, IRQ_STATUS
)) & FM801_IRQ_CAPTURE
) {
502 ptr
+= chip
->cap_count
;
503 ptr
%= chip
->cap_size
;
505 spin_unlock(&chip
->reg_lock
);
506 return bytes_to_frames(substream
->runtime
, ptr
);
509 static irqreturn_t
snd_fm801_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
511 fm801_t
*chip
= dev_id
;
512 unsigned short status
;
515 status
= inw(FM801_REG(chip
, IRQ_STATUS
));
516 status
&= FM801_IRQ_PLAYBACK
|FM801_IRQ_CAPTURE
|FM801_IRQ_MPU
|FM801_IRQ_VOLUME
;
520 outw(status
, FM801_REG(chip
, IRQ_STATUS
));
521 if (chip
->pcm
&& (status
& FM801_IRQ_PLAYBACK
) && chip
->playback_substream
) {
522 spin_lock(&chip
->reg_lock
);
524 chip
->ply_pos
+= chip
->ply_count
;
525 chip
->ply_pos
%= chip
->ply_size
;
526 tmp
= chip
->ply_pos
+ chip
->ply_count
;
527 tmp
%= chip
->ply_size
;
528 outl(chip
->ply_buffer
+ tmp
,
529 (chip
->ply_buf
& 1) ?
530 FM801_REG(chip
, PLY_BUF1
) :
531 FM801_REG(chip
, PLY_BUF2
));
532 spin_unlock(&chip
->reg_lock
);
533 snd_pcm_period_elapsed(chip
->playback_substream
);
535 if (chip
->pcm
&& (status
& FM801_IRQ_CAPTURE
) && chip
->capture_substream
) {
536 spin_lock(&chip
->reg_lock
);
538 chip
->cap_pos
+= chip
->cap_count
;
539 chip
->cap_pos
%= chip
->cap_size
;
540 tmp
= chip
->cap_pos
+ chip
->cap_count
;
541 tmp
%= chip
->cap_size
;
542 outl(chip
->cap_buffer
+ tmp
,
543 (chip
->cap_buf
& 1) ?
544 FM801_REG(chip
, CAP_BUF1
) :
545 FM801_REG(chip
, CAP_BUF2
));
546 spin_unlock(&chip
->reg_lock
);
547 snd_pcm_period_elapsed(chip
->capture_substream
);
549 if (chip
->rmidi
&& (status
& FM801_IRQ_MPU
))
550 snd_mpu401_uart_interrupt(irq
, chip
->rmidi
->private_data
, regs
);
551 if (status
& FM801_IRQ_VOLUME
)
557 static snd_pcm_hardware_t snd_fm801_playback
=
559 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
560 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
561 SNDRV_PCM_INFO_PAUSE
|
562 SNDRV_PCM_INFO_MMAP_VALID
),
563 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
564 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
569 .buffer_bytes_max
= (128*1024),
570 .period_bytes_min
= 64,
571 .period_bytes_max
= (128*1024),
577 static snd_pcm_hardware_t snd_fm801_capture
=
579 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
580 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
581 SNDRV_PCM_INFO_PAUSE
|
582 SNDRV_PCM_INFO_MMAP_VALID
),
583 .formats
= SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
,
584 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
589 .buffer_bytes_max
= (128*1024),
590 .period_bytes_min
= 64,
591 .period_bytes_max
= (128*1024),
597 static int snd_fm801_playback_open(snd_pcm_substream_t
* substream
)
599 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
600 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
603 chip
->playback_substream
= substream
;
604 runtime
->hw
= snd_fm801_playback
;
605 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates
);
606 if (chip
->multichannel
) {
607 runtime
->hw
.channels_max
= 6;
608 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
, &hw_constraints_channels
);
610 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
615 static int snd_fm801_capture_open(snd_pcm_substream_t
* substream
)
617 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
618 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
621 chip
->capture_substream
= substream
;
622 runtime
->hw
= snd_fm801_capture
;
623 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hw_constraints_rates
);
624 if ((err
= snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
)) < 0)
629 static int snd_fm801_playback_close(snd_pcm_substream_t
* substream
)
631 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
633 chip
->playback_substream
= NULL
;
637 static int snd_fm801_capture_close(snd_pcm_substream_t
* substream
)
639 fm801_t
*chip
= snd_pcm_substream_chip(substream
);
641 chip
->capture_substream
= NULL
;
645 static snd_pcm_ops_t snd_fm801_playback_ops
= {
646 .open
= snd_fm801_playback_open
,
647 .close
= snd_fm801_playback_close
,
648 .ioctl
= snd_pcm_lib_ioctl
,
649 .hw_params
= snd_fm801_hw_params
,
650 .hw_free
= snd_fm801_hw_free
,
651 .prepare
= snd_fm801_playback_prepare
,
652 .trigger
= snd_fm801_playback_trigger
,
653 .pointer
= snd_fm801_playback_pointer
,
656 static snd_pcm_ops_t snd_fm801_capture_ops
= {
657 .open
= snd_fm801_capture_open
,
658 .close
= snd_fm801_capture_close
,
659 .ioctl
= snd_pcm_lib_ioctl
,
660 .hw_params
= snd_fm801_hw_params
,
661 .hw_free
= snd_fm801_hw_free
,
662 .prepare
= snd_fm801_capture_prepare
,
663 .trigger
= snd_fm801_capture_trigger
,
664 .pointer
= snd_fm801_capture_pointer
,
667 static void snd_fm801_pcm_free(snd_pcm_t
*pcm
)
669 fm801_t
*chip
= pcm
->private_data
;
671 snd_pcm_lib_preallocate_free_for_all(pcm
);
674 static int __devinit
snd_fm801_pcm(fm801_t
*chip
, int device
, snd_pcm_t
** rpcm
)
681 if ((err
= snd_pcm_new(chip
->card
, "FM801", device
, 1, 1, &pcm
)) < 0)
684 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_fm801_playback_ops
);
685 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_fm801_capture_ops
);
687 pcm
->private_data
= chip
;
688 pcm
->private_free
= snd_fm801_pcm_free
;
690 strcpy(pcm
->name
, "FM801");
693 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
694 snd_dma_pci_data(chip
->pci
),
695 chip
->multichannel
? 128*1024 : 64*1024, 128*1024);
708 /* 256PCS GPIO numbers */
709 #define TEA_256PCS_DATA 1
710 #define TEA_256PCS_WRITE_ENABLE 2 /* inverted */
711 #define TEA_256PCS_BUS_CLOCK 3
713 static void snd_fm801_tea575x_256pcs_write(tea575x_t
*tea
, unsigned int val
)
715 fm801_t
*chip
= tea
->private_data
;
719 spin_lock_irq(&chip
->reg_lock
);
720 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
721 /* use GPIO lines and set write enable bit */
722 reg
|= FM801_GPIO_GS(TEA_256PCS_DATA
) |
723 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE
) |
724 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK
);
725 /* all of lines are in the write direction */
726 /* clear data and clock lines */
727 reg
&= ~(FM801_GPIO_GD(TEA_256PCS_DATA
) |
728 FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE
) |
729 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK
) |
730 FM801_GPIO_GP(TEA_256PCS_DATA
) |
731 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
) |
732 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE
));
733 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
738 reg
|= FM801_GPIO_GP(TEA_256PCS_DATA
);
740 reg
&= ~FM801_GPIO_GP(TEA_256PCS_DATA
);
741 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
743 reg
|= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
);
744 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
745 reg
&= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
);
746 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
750 /* and reset the write enable bit */
751 reg
|= FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE
) |
752 FM801_GPIO_GP(TEA_256PCS_DATA
);
753 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
754 spin_unlock_irq(&chip
->reg_lock
);
757 static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t
*tea
)
759 fm801_t
*chip
= tea
->private_data
;
761 unsigned int val
= 0;
764 spin_lock_irq(&chip
->reg_lock
);
765 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
766 /* use GPIO lines, set data direction to input */
767 reg
|= FM801_GPIO_GS(TEA_256PCS_DATA
) |
768 FM801_GPIO_GS(TEA_256PCS_WRITE_ENABLE
) |
769 FM801_GPIO_GS(TEA_256PCS_BUS_CLOCK
) |
770 FM801_GPIO_GD(TEA_256PCS_DATA
) |
771 FM801_GPIO_GP(TEA_256PCS_DATA
) |
772 FM801_GPIO_GP(TEA_256PCS_WRITE_ENABLE
);
773 /* all of lines are in the write direction, except data */
774 /* clear data, write enable and clock lines */
775 reg
&= ~(FM801_GPIO_GD(TEA_256PCS_WRITE_ENABLE
) |
776 FM801_GPIO_GD(TEA_256PCS_BUS_CLOCK
) |
777 FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
));
779 for (i
= 0; i
< 24; i
++) {
780 reg
&= ~FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
);
781 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
783 reg
|= FM801_GPIO_GP(TEA_256PCS_BUS_CLOCK
);
784 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
787 if (inw(FM801_REG(chip
, GPIO_CTRL
)) & FM801_GPIO_GP(TEA_256PCS_DATA
))
791 spin_unlock_irq(&chip
->reg_lock
);
796 /* 256PCPR GPIO numbers */
797 #define TEA_256PCPR_BUS_CLOCK 0
798 #define TEA_256PCPR_DATA 1
799 #define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */
801 static void snd_fm801_tea575x_256pcpr_write(tea575x_t
*tea
, unsigned int val
)
803 fm801_t
*chip
= tea
->private_data
;
807 spin_lock_irq(&chip
->reg_lock
);
808 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
809 /* use GPIO lines and set write enable bit */
810 reg
|= FM801_GPIO_GS(TEA_256PCPR_DATA
) |
811 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE
) |
812 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK
);
813 /* all of lines are in the write direction */
814 /* clear data and clock lines */
815 reg
&= ~(FM801_GPIO_GD(TEA_256PCPR_DATA
) |
816 FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE
) |
817 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK
) |
818 FM801_GPIO_GP(TEA_256PCPR_DATA
) |
819 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
) |
820 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE
));
821 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
826 reg
|= FM801_GPIO_GP(TEA_256PCPR_DATA
);
828 reg
&= ~FM801_GPIO_GP(TEA_256PCPR_DATA
);
829 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
831 reg
|= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
);
832 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
833 reg
&= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
);
834 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
838 /* and reset the write enable bit */
839 reg
|= FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE
) |
840 FM801_GPIO_GP(TEA_256PCPR_DATA
);
841 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
842 spin_unlock_irq(&chip
->reg_lock
);
845 static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t
*tea
)
847 fm801_t
*chip
= tea
->private_data
;
849 unsigned int val
= 0;
852 spin_lock_irq(&chip
->reg_lock
);
853 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
854 /* use GPIO lines, set data direction to input */
855 reg
|= FM801_GPIO_GS(TEA_256PCPR_DATA
) |
856 FM801_GPIO_GS(TEA_256PCPR_WRITE_ENABLE
) |
857 FM801_GPIO_GS(TEA_256PCPR_BUS_CLOCK
) |
858 FM801_GPIO_GD(TEA_256PCPR_DATA
) |
859 FM801_GPIO_GP(TEA_256PCPR_DATA
) |
860 FM801_GPIO_GP(TEA_256PCPR_WRITE_ENABLE
);
861 /* all of lines are in the write direction, except data */
862 /* clear data, write enable and clock lines */
863 reg
&= ~(FM801_GPIO_GD(TEA_256PCPR_WRITE_ENABLE
) |
864 FM801_GPIO_GD(TEA_256PCPR_BUS_CLOCK
) |
865 FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
));
867 for (i
= 0; i
< 24; i
++) {
868 reg
&= ~FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
);
869 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
871 reg
|= FM801_GPIO_GP(TEA_256PCPR_BUS_CLOCK
);
872 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
875 if (inw(FM801_REG(chip
, GPIO_CTRL
)) & FM801_GPIO_GP(TEA_256PCPR_DATA
))
879 spin_unlock_irq(&chip
->reg_lock
);
884 /* 64PCR GPIO numbers */
885 #define TEA_64PCR_BUS_CLOCK 0
886 #define TEA_64PCR_WRITE_ENABLE 1 /* inverted */
887 #define TEA_64PCR_DATA 2
889 static void snd_fm801_tea575x_64pcr_write(tea575x_t
*tea
, unsigned int val
)
891 fm801_t
*chip
= tea
->private_data
;
895 spin_lock_irq(&chip
->reg_lock
);
896 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
897 /* use GPIO lines and set write enable bit */
898 reg
|= FM801_GPIO_GS(TEA_64PCR_DATA
) |
899 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE
) |
900 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK
);
901 /* all of lines are in the write direction */
902 /* clear data and clock lines */
903 reg
&= ~(FM801_GPIO_GD(TEA_64PCR_DATA
) |
904 FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE
) |
905 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK
) |
906 FM801_GPIO_GP(TEA_64PCR_DATA
) |
907 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
) |
908 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE
));
909 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
914 reg
|= FM801_GPIO_GP(TEA_64PCR_DATA
);
916 reg
&= ~FM801_GPIO_GP(TEA_64PCR_DATA
);
917 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
919 reg
|= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
);
920 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
921 reg
&= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
);
922 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
926 /* and reset the write enable bit */
927 reg
|= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE
) |
928 FM801_GPIO_GP(TEA_64PCR_DATA
);
929 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
930 spin_unlock_irq(&chip
->reg_lock
);
933 static unsigned int snd_fm801_tea575x_64pcr_read(tea575x_t
*tea
)
935 fm801_t
*chip
= tea
->private_data
;
937 unsigned int val
= 0;
940 spin_lock_irq(&chip
->reg_lock
);
941 reg
= inw(FM801_REG(chip
, GPIO_CTRL
));
942 /* use GPIO lines, set data direction to input */
943 reg
|= FM801_GPIO_GS(TEA_64PCR_DATA
) |
944 FM801_GPIO_GS(TEA_64PCR_WRITE_ENABLE
) |
945 FM801_GPIO_GS(TEA_64PCR_BUS_CLOCK
) |
946 FM801_GPIO_GD(TEA_64PCR_DATA
) |
947 FM801_GPIO_GP(TEA_64PCR_DATA
) |
948 FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE
);
949 /* all of lines are in the write direction, except data */
950 /* clear data, write enable and clock lines */
951 reg
&= ~(FM801_GPIO_GD(TEA_64PCR_WRITE_ENABLE
) |
952 FM801_GPIO_GD(TEA_64PCR_BUS_CLOCK
) |
953 FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
));
955 for (i
= 0; i
< 24; i
++) {
956 reg
&= ~FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
);
957 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
959 reg
|= FM801_GPIO_GP(TEA_64PCR_BUS_CLOCK
);
960 outw(reg
, FM801_REG(chip
, GPIO_CTRL
));
963 if (inw(FM801_REG(chip
, GPIO_CTRL
)) & FM801_GPIO_GP(TEA_64PCR_DATA
))
967 spin_unlock_irq(&chip
->reg_lock
);
972 static struct snd_tea575x_ops snd_fm801_tea_ops
[3] = {
974 /* 1 = MediaForte 256-PCS */
975 .write
= snd_fm801_tea575x_256pcs_write
,
976 .read
= snd_fm801_tea575x_256pcs_read
,
979 /* 2 = MediaForte 256-PCPR */
980 .write
= snd_fm801_tea575x_256pcpr_write
,
981 .read
= snd_fm801_tea575x_256pcpr_read
,
984 /* 3 = MediaForte 64-PCR */
985 .write
= snd_fm801_tea575x_64pcr_write
,
986 .read
= snd_fm801_tea575x_64pcr_read
,
995 #define FM801_SINGLE(xname, reg, shift, mask, invert) \
996 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \
997 .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
998 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
1000 static int snd_fm801_info_single(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1002 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1004 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1006 uinfo
->value
.integer
.min
= 0;
1007 uinfo
->value
.integer
.max
= mask
;
1011 static int snd_fm801_get_single(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1013 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1014 int reg
= kcontrol
->private_value
& 0xff;
1015 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1016 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1017 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1019 ucontrol
->value
.integer
.value
[0] = (inw(chip
->port
+ reg
) >> shift
) & mask
;
1021 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1025 static int snd_fm801_put_single(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1027 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1028 int reg
= kcontrol
->private_value
& 0xff;
1029 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1030 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1031 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1034 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1037 return snd_fm801_update_bits(chip
, reg
, mask
<< shift
, val
<< shift
);
1040 #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
1041 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
1042 .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
1043 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
1045 static int snd_fm801_info_double(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1047 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1049 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1051 uinfo
->value
.integer
.min
= 0;
1052 uinfo
->value
.integer
.max
= mask
;
1056 static int snd_fm801_get_double(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1058 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1059 int reg
= kcontrol
->private_value
& 0xff;
1060 int shift_left
= (kcontrol
->private_value
>> 8) & 0x0f;
1061 int shift_right
= (kcontrol
->private_value
>> 12) & 0x0f;
1062 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1063 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1065 spin_lock_irq(&chip
->reg_lock
);
1066 ucontrol
->value
.integer
.value
[0] = (inw(chip
->port
+ reg
) >> shift_left
) & mask
;
1067 ucontrol
->value
.integer
.value
[1] = (inw(chip
->port
+ reg
) >> shift_right
) & mask
;
1068 spin_unlock_irq(&chip
->reg_lock
);
1070 ucontrol
->value
.integer
.value
[0] = mask
- ucontrol
->value
.integer
.value
[0];
1071 ucontrol
->value
.integer
.value
[1] = mask
- ucontrol
->value
.integer
.value
[1];
1076 static int snd_fm801_put_double(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1078 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1079 int reg
= kcontrol
->private_value
& 0xff;
1080 int shift_left
= (kcontrol
->private_value
>> 8) & 0x0f;
1081 int shift_right
= (kcontrol
->private_value
>> 12) & 0x0f;
1082 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1083 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1084 unsigned short val1
, val2
;
1086 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1087 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1092 return snd_fm801_update_bits(chip
, reg
,
1093 (mask
<< shift_left
) | (mask
<< shift_right
),
1094 (val1
<< shift_left
) | (val2
<< shift_right
));
1097 static int snd_fm801_info_mux(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1099 static char *texts
[5] = {
1100 "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
1103 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1105 uinfo
->value
.enumerated
.items
= 5;
1106 if (uinfo
->value
.enumerated
.item
> 4)
1107 uinfo
->value
.enumerated
.item
= 4;
1108 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1112 static int snd_fm801_get_mux(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1114 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1117 val
= inw(FM801_REG(chip
, REC_SRC
)) & 7;
1120 ucontrol
->value
.enumerated
.item
[0] = val
;
1124 static int snd_fm801_put_mux(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1126 fm801_t
*chip
= snd_kcontrol_chip(kcontrol
);
1129 if ((val
= ucontrol
->value
.enumerated
.item
[0]) > 4)
1131 return snd_fm801_update_bits(chip
, FM801_REC_SRC
, 7, val
);
1134 #define FM801_CONTROLS (sizeof(snd_fm801_controls)/sizeof(snd_kcontrol_new_t))
1136 static snd_kcontrol_new_t snd_fm801_controls
[] __devinitdata
= {
1137 FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL
, 0, 8, 31, 1),
1138 FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL
, 15, 1, 1),
1139 FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL
, 0, 8, 31, 1),
1140 FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL
, 15, 1, 1),
1141 FM801_DOUBLE("FM Playback Volume", FM801_FM_VOL
, 0, 8, 31, 1),
1142 FM801_SINGLE("FM Playback Switch", FM801_FM_VOL
, 15, 1, 1),
1144 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1145 .name
= "Digital Capture Source",
1146 .info
= snd_fm801_info_mux
,
1147 .get
= snd_fm801_get_mux
,
1148 .put
= snd_fm801_put_mux
,
1152 #define FM801_CONTROLS_MULTI (sizeof(snd_fm801_controls_multi)/sizeof(snd_kcontrol_new_t))
1154 static snd_kcontrol_new_t snd_fm801_controls_multi
[] __devinitdata
= {
1155 FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL
, 7, 1, 0),
1156 FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL
, 10, 1, 0),
1157 FM801_SINGLE("IEC958 Capture Switch", FM801_I2S_MODE
, 8, 1, 0),
1158 FM801_SINGLE("IEC958 Raw Data Playback Switch", FM801_I2S_MODE
, 9, 1, 0),
1159 FM801_SINGLE("IEC958 Raw Data Capture Switch", FM801_I2S_MODE
, 10, 1, 0),
1160 FM801_SINGLE("IEC958 Playback Switch", FM801_GEN_CTRL
, 2, 1, 0),
1163 static void snd_fm801_mixer_free_ac97_bus(ac97_bus_t
*bus
)
1165 fm801_t
*chip
= bus
->private_data
;
1166 chip
->ac97_bus
= NULL
;
1169 static void snd_fm801_mixer_free_ac97(ac97_t
*ac97
)
1171 fm801_t
*chip
= ac97
->private_data
;
1172 if (ac97
->num
== 0) {
1175 chip
->ac97_sec
= NULL
;
1179 static int __devinit
snd_fm801_mixer(fm801_t
*chip
)
1181 ac97_template_t ac97
;
1184 static ac97_bus_ops_t ops
= {
1185 .write
= snd_fm801_codec_write
,
1186 .read
= snd_fm801_codec_read
,
1189 if ((err
= snd_ac97_bus(chip
->card
, 0, &ops
, chip
, &chip
->ac97_bus
)) < 0)
1191 chip
->ac97_bus
->private_free
= snd_fm801_mixer_free_ac97_bus
;
1193 memset(&ac97
, 0, sizeof(ac97
));
1194 ac97
.private_data
= chip
;
1195 ac97
.private_free
= snd_fm801_mixer_free_ac97
;
1196 if ((err
= snd_ac97_mixer(chip
->ac97_bus
, &ac97
, &chip
->ac97
)) < 0)
1198 if (chip
->secondary
) {
1200 ac97
.addr
= chip
->secondary_addr
;
1201 if ((err
= snd_ac97_mixer(chip
->ac97_bus
, &ac97
, &chip
->ac97_sec
)) < 0)
1204 for (i
= 0; i
< FM801_CONTROLS
; i
++)
1205 snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_fm801_controls
[i
], chip
));
1206 if (chip
->multichannel
) {
1207 for (i
= 0; i
< FM801_CONTROLS_MULTI
; i
++)
1208 snd_ctl_add(chip
->card
, snd_ctl_new1(&snd_fm801_controls_multi
[i
], chip
));
1214 * initialization routines
1217 static int snd_fm801_free(fm801_t
*chip
)
1219 unsigned short cmdw
;
1224 /* interrupt setup - mask everything */
1225 cmdw
= inw(FM801_REG(chip
, IRQ_MASK
));
1227 outw(cmdw
, FM801_REG(chip
, IRQ_MASK
));
1230 #ifdef TEA575X_RADIO
1231 snd_tea575x_exit(&chip
->tea
);
1234 free_irq(chip
->irq
, (void *)chip
);
1235 pci_release_regions(chip
->pci
);
1236 pci_disable_device(chip
->pci
);
1242 static int snd_fm801_dev_free(snd_device_t
*device
)
1244 fm801_t
*chip
= device
->device_data
;
1245 return snd_fm801_free(chip
);
1248 static int __devinit
snd_fm801_create(snd_card_t
* card
,
1249 struct pci_dev
* pci
,
1254 unsigned char rev
, id
;
1255 unsigned short cmdw
;
1256 unsigned long timeout
;
1258 static snd_device_ops_t ops
= {
1259 .dev_free
= snd_fm801_dev_free
,
1263 if ((err
= pci_enable_device(pci
)) < 0)
1265 chip
= kcalloc(1, sizeof(*chip
), GFP_KERNEL
);
1267 pci_disable_device(pci
);
1270 spin_lock_init(&chip
->reg_lock
);
1274 if ((err
= pci_request_regions(pci
, "FM801")) < 0) {
1276 pci_disable_device(pci
);
1279 chip
->port
= pci_resource_start(pci
, 0);
1280 if (request_irq(pci
->irq
, snd_fm801_interrupt
, SA_INTERRUPT
|SA_SHIRQ
, "FM801", (void *)chip
)) {
1281 snd_printk("unable to grab IRQ %d\n", chip
->irq
);
1282 snd_fm801_free(chip
);
1285 chip
->irq
= pci
->irq
;
1286 pci_set_master(pci
);
1288 pci_read_config_byte(pci
, PCI_REVISION_ID
, &rev
);
1289 if (rev
>= 0xb1) /* FM801-AU */
1290 chip
->multichannel
= 1;
1292 /* codec cold reset + AC'97 warm reset */
1293 outw((1<<5)|(1<<6), FM801_REG(chip
, CODEC_CTRL
));
1294 inw(FM801_REG(chip
, CODEC_CTRL
)); /* flush posting data */
1296 outw(0, FM801_REG(chip
, CODEC_CTRL
));
1298 timeout
= (jiffies
+ (3 * HZ
) / 4) + 1; /* min 750ms */
1300 outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT
), FM801_REG(chip
, AC97_CMD
));
1303 if ((inw(FM801_REG(chip
, AC97_CMD
)) & (3<<8)) == (1<<8))
1304 goto __ac97_secondary
;
1305 set_current_state(TASK_UNINTERRUPTIBLE
);
1306 schedule_timeout(1);
1307 } while (time_after(timeout
, jiffies
));
1308 snd_printk("Primary AC'97 codec not found\n");
1309 snd_fm801_free(chip
);
1313 if (!chip
->multichannel
) /* lookup is not required */
1315 for (id
= 3; id
> 0; id
--) { /* my card has the secondary codec */
1316 /* at address #3, so the loop is inverted */
1318 timeout
= jiffies
+ HZ
/ 20;
1320 outw((1<<7) | (id
<< FM801_AC97_ADDR_SHIFT
) | AC97_VENDOR_ID1
, FM801_REG(chip
, AC97_CMD
));
1323 if ((inw(FM801_REG(chip
, AC97_CMD
)) & (3<<8)) == (1<<8)) {
1324 cmdw
= inw(FM801_REG(chip
, AC97_DATA
));
1325 if (cmdw
!= 0xffff && cmdw
!= 0) {
1326 chip
->secondary
= 1;
1327 chip
->secondary_addr
= id
;
1331 set_current_state(TASK_UNINTERRUPTIBLE
);
1332 schedule_timeout(1);
1333 } while (time_after(timeout
, jiffies
));
1336 /* the recovery phase, it seems that probing for non-existing codec might */
1337 /* cause timeout problems */
1338 timeout
= (jiffies
+ (3 * HZ
) / 4) + 1; /* min 750ms */
1340 outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT
), FM801_REG(chip
, AC97_CMD
));
1343 if ((inw(FM801_REG(chip
, AC97_CMD
)) & (3<<8)) == (1<<8))
1345 set_current_state(TASK_UNINTERRUPTIBLE
);
1346 schedule_timeout(1);
1347 } while (time_after(timeout
, jiffies
));
1348 snd_printk("Primary AC'97 codec not responding\n");
1349 snd_fm801_free(chip
);
1355 outw(0x0808, FM801_REG(chip
, PCM_VOL
));
1356 outw(0x9f1f, FM801_REG(chip
, FM_VOL
));
1357 outw(0x8808, FM801_REG(chip
, I2S_VOL
));
1359 /* I2S control - I2S mode */
1360 outw(0x0003, FM801_REG(chip
, I2S_MODE
));
1362 /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */
1363 cmdw
= inw(FM801_REG(chip
, IRQ_MASK
));
1365 outw(cmdw
, FM801_REG(chip
, IRQ_MASK
));
1367 /* interrupt clear */
1368 outw(FM801_IRQ_PLAYBACK
|FM801_IRQ_CAPTURE
|FM801_IRQ_MPU
, FM801_REG(chip
, IRQ_STATUS
));
1370 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1371 snd_fm801_free(chip
);
1375 snd_card_set_dev(card
, &pci
->dev
);
1377 #ifdef TEA575X_RADIO
1378 if (tea575x_tuner
> 0 && (tea575x_tuner
& 0xffff) < 4) {
1379 chip
->tea
.dev_nr
= tea575x_tuner
>> 16;
1380 chip
->tea
.card
= card
;
1381 chip
->tea
.freq_fixup
= 10700;
1382 chip
->tea
.private_data
= chip
;
1383 chip
->tea
.ops
= &snd_fm801_tea_ops
[(tea575x_tuner
& 0xffff) - 1];
1384 snd_tea575x_init(&chip
->tea
);
1392 static int __devinit
snd_card_fm801_probe(struct pci_dev
*pci
,
1393 const struct pci_device_id
*pci_id
)
1401 if (dev
>= SNDRV_CARDS
)
1408 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
1411 if ((err
= snd_fm801_create(card
, pci
, tea575x_tuner
[dev
], &chip
)) < 0) {
1412 snd_card_free(card
);
1416 strcpy(card
->driver
, "FM801");
1417 strcpy(card
->shortname
, "ForteMedia FM801-");
1418 strcat(card
->shortname
, chip
->multichannel
? "AU" : "AS");
1419 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
1420 card
->shortname
, chip
->port
, chip
->irq
);
1422 if ((err
= snd_fm801_pcm(chip
, 0, NULL
)) < 0) {
1423 snd_card_free(card
);
1426 if ((err
= snd_fm801_mixer(chip
)) < 0) {
1427 snd_card_free(card
);
1430 if ((err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_FM801
,
1431 FM801_REG(chip
, MPU401_DATA
), 1,
1432 chip
->irq
, 0, &chip
->rmidi
)) < 0) {
1433 snd_card_free(card
);
1436 if ((err
= snd_opl3_create(card
, FM801_REG(chip
, OPL3_BANK0
),
1437 FM801_REG(chip
, OPL3_BANK1
),
1438 OPL3_HW_OPL3_FM801
, 1, &opl3
)) < 0) {
1439 snd_card_free(card
);
1442 if ((err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0) {
1443 snd_card_free(card
);
1447 if ((err
= snd_card_register(card
)) < 0) {
1448 snd_card_free(card
);
1451 pci_set_drvdata(pci
, card
);
1456 static void __devexit
snd_card_fm801_remove(struct pci_dev
*pci
)
1458 snd_card_free(pci_get_drvdata(pci
));
1459 pci_set_drvdata(pci
, NULL
);
1462 static struct pci_driver driver
= {
1464 .id_table
= snd_fm801_ids
,
1465 .probe
= snd_card_fm801_probe
,
1466 .remove
= __devexit_p(snd_card_fm801_remove
),
1469 static int __init
alsa_card_fm801_init(void)
1471 return pci_module_init(&driver
);
1474 static void __exit
alsa_card_fm801_exit(void)
1476 pci_unregister_driver(&driver
);
1479 module_init(alsa_card_fm801_init
)
1480 module_exit(alsa_card_fm801_exit
)