summaryrefslogtreecommitdiffstats
path: root/sound/pci/fm801.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/fm801.c')
-rw-r--r--sound/pci/fm801.c478
1 files changed, 277 insertions, 201 deletions
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 4e1d343..6ab4aef 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -103,7 +103,11 @@ MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
#define FM801_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
#define FM801_POWERDOWN 0x70 /* Blocks Power Down Control */
-#define FM801_AC97_ADDR_SHIFT 10
+/* codec access */
+#define FM801_AC97_READ (1<<7) /* read=1, write=0 */
+#define FM801_AC97_VALID (1<<8) /* port valid=1 */
+#define FM801_AC97_BUSY (1<<9) /* busy=1 */
+#define FM801_AC97_ADDR_SHIFT 10 /* codec id (2bit) */
/* playback and record control register bits */
#define FM801_BUF1_LAST (1<<1)
@@ -147,9 +151,7 @@ MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
*/
-typedef struct _snd_fm801 fm801_t;
-
-struct _snd_fm801 {
+struct fm801 {
int irq;
unsigned long port; /* I/O port number */
@@ -172,24 +174,28 @@ struct _snd_fm801 {
unsigned int cap_size;
unsigned int cap_pos;
- ac97_bus_t *ac97_bus;
- ac97_t *ac97;
- ac97_t *ac97_sec;
+ struct snd_ac97_bus *ac97_bus;
+ struct snd_ac97 *ac97;
+ struct snd_ac97 *ac97_sec;
struct pci_dev *pci;
- snd_card_t *card;
- snd_pcm_t *pcm;
- snd_rawmidi_t *rmidi;
- snd_pcm_substream_t *playback_substream;
- snd_pcm_substream_t *capture_substream;
+ struct snd_card *card;
+ struct snd_pcm *pcm;
+ struct snd_rawmidi *rmidi;
+ struct snd_pcm_substream *playback_substream;
+ struct snd_pcm_substream *capture_substream;
unsigned int p_dma_size;
unsigned int c_dma_size;
spinlock_t reg_lock;
- snd_info_entry_t *proc_entry;
+ struct snd_info_entry *proc_entry;
#ifdef TEA575X_RADIO
- tea575x_t tea;
+ struct snd_tea575x tea;
+#endif
+
+#ifdef CONFIG_PM
+ u16 saved_regs[0x20];
#endif
};
@@ -205,7 +211,7 @@ MODULE_DEVICE_TABLE(pci, snd_fm801_ids);
* common I/O routines
*/
-static int snd_fm801_update_bits(fm801_t *chip, unsigned short reg,
+static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
unsigned short mask, unsigned short value)
{
int change;
@@ -222,18 +228,18 @@ static int snd_fm801_update_bits(fm801_t *chip, unsigned short reg,
return change;
}
-static void snd_fm801_codec_write(ac97_t *ac97,
+static void snd_fm801_codec_write(struct snd_ac97 *ac97,
unsigned short reg,
unsigned short val)
{
- fm801_t *chip = ac97->private_data;
+ struct fm801 *chip = ac97->private_data;
int idx;
/*
* Wait until the codec interface is not ready..
*/
for (idx = 0; idx < 100; idx++) {
- if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+ if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
goto ok1;
udelay(10);
}
@@ -248,23 +254,23 @@ static void snd_fm801_codec_write(ac97_t *ac97,
* Wait until the write command is not completed..
*/
for (idx = 0; idx < 1000; idx++) {
- if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+ if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
return;
udelay(10);
}
snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
}
-static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
+static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
{
- fm801_t *chip = ac97->private_data;
+ struct fm801 *chip = ac97->private_data;
int idx;
/*
* Wait until the codec interface is not ready..
*/
for (idx = 0; idx < 100; idx++) {
- if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+ if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
goto ok1;
udelay(10);
}
@@ -273,9 +279,10 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
ok1:
/* read command */
- outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | (1<<7), FM801_REG(chip, AC97_CMD));
+ outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ,
+ FM801_REG(chip, AC97_CMD));
for (idx = 0; idx < 100; idx++) {
- if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+ if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
goto ok2;
udelay(10);
}
@@ -284,7 +291,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
ok2:
for (idx = 0; idx < 1000; idx++) {
- if (inw(FM801_REG(chip, AC97_CMD)) & (1<<8))
+ if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID)
goto ok3;
udelay(10);
}
@@ -301,7 +308,7 @@ static unsigned int rates[] = {
38400, 44100, 48000
};
-static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
.count = ARRAY_SIZE(rates),
.list = rates,
.mask = 0,
@@ -313,7 +320,7 @@ static unsigned int channels[] = {
#define CHANNELS sizeof(channels) / sizeof(channels[0])
-static snd_pcm_hw_constraint_list_t hw_constraints_channels = {
+static struct snd_pcm_hw_constraint_list hw_constraints_channels = {
.count = CHANNELS,
.list = channels,
.mask = 0,
@@ -338,10 +345,10 @@ static unsigned short snd_fm801_rate_bits(unsigned int rate)
* PCM part
*/
-static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
+static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
int cmd)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
spin_lock(&chip->reg_lock);
switch (cmd) {
@@ -356,9 +363,11 @@ static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE);
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
chip->ply_ctrl |= FM801_PAUSE;
break;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ case SNDRV_PCM_TRIGGER_RESUME:
chip->ply_ctrl &= ~FM801_PAUSE;
break;
default:
@@ -371,10 +380,10 @@ static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
return 0;
}
-static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
+static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
int cmd)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
spin_lock(&chip->reg_lock);
switch (cmd) {
@@ -389,9 +398,11 @@ static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
chip->cap_ctrl &= ~(FM801_START | FM801_PAUSE);
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
chip->cap_ctrl |= FM801_PAUSE;
break;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ case SNDRV_PCM_TRIGGER_RESUME:
chip->cap_ctrl &= ~FM801_PAUSE;
break;
default:
@@ -404,21 +415,21 @@ static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
return 0;
}
-static int snd_fm801_hw_params(snd_pcm_substream_t * substream,
- snd_pcm_hw_params_t * hw_params)
+static int snd_fm801_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *hw_params)
{
return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
}
-static int snd_fm801_hw_free(snd_pcm_substream_t * substream)
+static int snd_fm801_hw_free(struct snd_pcm_substream *substream)
{
return snd_pcm_lib_free_pages(substream);
}
-static int snd_fm801_playback_prepare(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
- snd_pcm_runtime_t *runtime = substream->runtime;
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
chip->ply_count = snd_pcm_lib_period_bytes(substream);
@@ -447,10 +458,10 @@ static int snd_fm801_playback_prepare(snd_pcm_substream_t * substream)
return 0;
}
-static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
- snd_pcm_runtime_t *runtime = substream->runtime;
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
chip->cap_count = snd_pcm_lib_period_bytes(substream);
@@ -473,9 +484,9 @@ static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream)
return 0;
}
-static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
size_t ptr;
if (!(chip->ply_ctrl & FM801_START))
@@ -490,9 +501,9 @@ static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substr
return bytes_to_frames(substream->runtime, ptr);
}
-static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
size_t ptr;
if (!(chip->cap_ctrl & FM801_START))
@@ -509,7 +520,7 @@ static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substre
static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
- fm801_t *chip = dev_id;
+ struct fm801 *chip = dev_id;
unsigned short status;
unsigned int tmp;
@@ -555,11 +566,11 @@ static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *re
return IRQ_HANDLED;
}
-static snd_pcm_hardware_t snd_fm801_playback =
+static struct snd_pcm_hardware snd_fm801_playback =
{
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_PAUSE |
+ SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
@@ -575,11 +586,11 @@ static snd_pcm_hardware_t snd_fm801_playback =
.fifo_size = 0,
};
-static snd_pcm_hardware_t snd_fm801_capture =
+static struct snd_pcm_hardware snd_fm801_capture =
{
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
- SNDRV_PCM_INFO_PAUSE |
+ SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
@@ -595,55 +606,59 @@ static snd_pcm_hardware_t snd_fm801_capture =
.fifo_size = 0,
};
-static int snd_fm801_playback_open(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_open(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
- snd_pcm_runtime_t *runtime = substream->runtime;
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
int err;
chip->playback_substream = substream;
runtime->hw = snd_fm801_playback;
- snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_rates);
if (chip->multichannel) {
runtime->hw.channels_max = 6;
- snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels);
+ snd_pcm_hw_constraint_list(runtime, 0,
+ SNDRV_PCM_HW_PARAM_CHANNELS,
+ &hw_constraints_channels);
}
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;
return 0;
}
-static int snd_fm801_capture_open(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_open(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
- snd_pcm_runtime_t *runtime = substream->runtime;
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
int err;
chip->capture_substream = substream;
runtime->hw = snd_fm801_capture;
- snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_rates);
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
return err;
return 0;
}
-static int snd_fm801_playback_close(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_close(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
chip->playback_substream = NULL;
return 0;
}
-static int snd_fm801_capture_close(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_close(struct snd_pcm_substream *substream)
{
- fm801_t *chip = snd_pcm_substream_chip(substream);
+ struct fm801 *chip = snd_pcm_substream_chip(substream);
chip->capture_substream = NULL;
return 0;
}
-static snd_pcm_ops_t snd_fm801_playback_ops = {
+static struct snd_pcm_ops snd_fm801_playback_ops = {
.open = snd_fm801_playback_open,
.close = snd_fm801_playback_close,
.ioctl = snd_pcm_lib_ioctl,
@@ -654,7 +669,7 @@ static snd_pcm_ops_t snd_fm801_playback_ops = {
.pointer = snd_fm801_playback_pointer,
};
-static snd_pcm_ops_t snd_fm801_capture_ops = {
+static struct snd_pcm_ops snd_fm801_capture_ops = {
.open = snd_fm801_capture_open,
.close = snd_fm801_capture_close,
.ioctl = snd_pcm_lib_ioctl,
@@ -665,16 +680,9 @@ static snd_pcm_ops_t snd_fm801_capture_ops = {
.pointer = snd_fm801_capture_pointer,
};
-static void snd_fm801_pcm_free(snd_pcm_t *pcm)
+static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm)
{
- fm801_t *chip = pcm->private_data;
- chip->pcm = NULL;
- snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
-{
- snd_pcm_t *pcm;
+ struct snd_pcm *pcm;
int err;
if (rpcm)
@@ -686,7 +694,6 @@ static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_fm801_capture_ops);
pcm->private_data = chip;
- pcm->private_free = snd_fm801_pcm_free;
pcm->info_flags = 0;
strcpy(pcm->name, "FM801");
chip->pcm = pcm;
@@ -711,9 +718,9 @@ static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
#define TEA_256PCS_WRITE_ENABLE 2 /* inverted */
#define TEA_256PCS_BUS_CLOCK 3
-static void snd_fm801_tea575x_256pcs_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
int i = 25;
@@ -755,9 +762,9 @@ static void snd_fm801_tea575x_256pcs_write(tea575x_t *tea, unsigned int val)
spin_unlock_irq(&chip->reg_lock);
}
-static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
unsigned int val = 0;
int i;
@@ -799,9 +806,9 @@ static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t *tea)
#define TEA_256PCPR_DATA 1
#define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */
-static void snd_fm801_tea575x_256pcpr_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
int i = 25;
@@ -843,9 +850,9 @@ static void snd_fm801_tea575x_256pcpr_write(tea575x_t *tea, unsigned int val)
spin_unlock_irq(&chip->reg_lock);
}
-static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
unsigned int val = 0;
int i;
@@ -887,9 +894,9 @@ static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t *tea)
#define TEA_64PCR_WRITE_ENABLE 1 /* inverted */
#define TEA_64PCR_DATA 2
-static void snd_fm801_tea575x_64pcr_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
int i = 25;
@@ -931,9 +938,9 @@ static void snd_fm801_tea575x_64pcr_write(tea575x_t *tea, unsigned int val)
spin_unlock_irq(&chip->reg_lock);
}
-static unsigned int snd_fm801_tea575x_64pcr_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
{
- fm801_t *chip = tea->private_data;
+ struct fm801 *chip = tea->private_data;
unsigned short reg;
unsigned int val = 0;
int i;
@@ -998,7 +1005,8 @@ static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
.get = snd_fm801_get_single, .put = snd_fm801_put_single, \
.private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
-static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_single(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
{
int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -1009,9 +1017,10 @@ static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
return 0;
}
-static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_single(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift = (kcontrol->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -1023,9 +1032,10 @@ static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
return 0;
}
-static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_single(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift = (kcontrol->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -1043,7 +1053,8 @@ static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
.get = snd_fm801_get_double, .put = snd_fm801_put_double, \
.private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
-static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_double(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
{
int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -1054,9 +1065,10 @@ static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
return 0;
}
-static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift_left = (kcontrol->private_value >> 8) & 0x0f;
int shift_right = (kcontrol->private_value >> 12) & 0x0f;
@@ -1074,9 +1086,10 @@ static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
return 0;
}
-static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift_left = (kcontrol->private_value >> 8) & 0x0f;
int shift_right = (kcontrol->private_value >> 12) & 0x0f;
@@ -1095,7 +1108,8 @@ static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
(val1 << shift_left ) | (val2 << shift_right));
}
-static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
{
static char *texts[5] = {
"AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
@@ -1110,9 +1124,10 @@ static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * ui
return 0;
}
-static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
unsigned short val;
val = inw(FM801_REG(chip, REC_SRC)) & 7;
@@ -1122,9 +1137,10 @@ static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * u
return 0;
}
-static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
{
- fm801_t *chip = snd_kcontrol_chip(kcontrol);
+ struct fm801 *chip = snd_kcontrol_chip(kcontrol);
unsigned short val;
if ((val = ucontrol->value.enumerated.item[0]) > 4)
@@ -1132,9 +1148,9 @@ static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * u
return snd_fm801_update_bits(chip, FM801_REC_SRC, 7, val);
}
-#define FM801_CONTROLS (sizeof(snd_fm801_controls)/sizeof(snd_kcontrol_new_t))
+#define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
-static snd_kcontrol_new_t snd_fm801_controls[] __devinitdata = {
+static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = {
FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1),
FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1),
FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1),
@@ -1150,9 +1166,9 @@ FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
}
};
-#define FM801_CONTROLS_MULTI (sizeof(snd_fm801_controls_multi)/sizeof(snd_kcontrol_new_t))
+#define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
-static snd_kcontrol_new_t snd_fm801_controls_multi[] __devinitdata = {
+static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0),
@@ -1161,15 +1177,15 @@ FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE,
FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0),
};
-static void snd_fm801_mixer_free_ac97_bus(ac97_bus_t *bus)
+static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
{
- fm801_t *chip = bus->private_data;
+ struct fm801 *chip = bus->private_data;
chip->ac97_bus = NULL;
}
-static void snd_fm801_mixer_free_ac97(ac97_t *ac97)
+static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97)
{
- fm801_t *chip = ac97->private_data;
+ struct fm801 *chip = ac97->private_data;
if (ac97->num == 0) {
chip->ac97 = NULL;
} else {
@@ -1177,12 +1193,12 @@ static void snd_fm801_mixer_free_ac97(ac97_t *ac97)
}
}
-static int __devinit snd_fm801_mixer(fm801_t *chip)
+static int __devinit snd_fm801_mixer(struct fm801 *chip)
{
- ac97_template_t ac97;
+ struct snd_ac97_template ac97;
unsigned int i;
int err;
- static ac97_bus_ops_t ops = {
+ static struct snd_ac97_bus_ops ops = {
.write = snd_fm801_codec_write,
.read = snd_fm801_codec_read,
};
@@ -1215,7 +1231,86 @@ static int __devinit snd_fm801_mixer(fm801_t *chip)
* initialization routines
*/
-static int snd_fm801_free(fm801_t *chip)
+static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
+ unsigned short reg, unsigned long waits)
+{
+ unsigned long timeout = jiffies + waits;
+
+ outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,
+ FM801_REG(chip, AC97_CMD));
+ udelay(5);
+ do {
+ if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))
+ == FM801_AC97_VALID)
+ return 0;
+ schedule_timeout_uninterruptible(1);
+ } while (time_after(timeout, jiffies));
+ return -EIO;
+}
+
+static int snd_fm801_chip_init(struct fm801 *chip, int resume)
+{
+ int id;
+ unsigned short cmdw;
+
+ /* codec cold reset + AC'97 warm reset */
+ outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));
+ inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
+ udelay(100);
+ outw(0, FM801_REG(chip, CODEC_CTRL));
+
+ if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) {
+ snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
+ if (! resume)
+ return -EIO;
+ }
+
+ if (chip->multichannel) {
+ if (chip->secondary_addr) {
+ wait_for_codec(chip, chip->secondary_addr,
+ AC97_VENDOR_ID1, msecs_to_jiffies(50));
+ } else {
+ /* my card has the secondary codec */
+ /* at address #3, so the loop is inverted */
+ for (id = 3; id > 0; id--) {
+ if (! wait_for_codec(chip, id, AC97_VENDOR_ID1,
+ msecs_to_jiffies(50))) {
+ cmdw = inw(FM801_REG(chip, AC97_DATA));
+ if (cmdw != 0xffff && cmdw != 0) {
+ chip->secondary = 1;
+ chip->secondary_addr = id;
+ break;
+ }
+ }
+ }
+ }
+
+ /* the recovery phase, it seems that probing for non-existing codec might */
+ /* cause timeout problems */
+ wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
+ }
+
+ /* init volume */
+ outw(0x0808, FM801_REG(chip, PCM_VOL));
+ outw(0x9f1f, FM801_REG(chip, FM_VOL));
+ outw(0x8808, FM801_REG(chip, I2S_VOL));
+
+ /* I2S control - I2S mode */
+ outw(0x0003, FM801_REG(chip, I2S_MODE));
+
+ /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */
+ cmdw = inw(FM801_REG(chip, IRQ_MASK));
+ cmdw &= ~0x0083;
+ outw(cmdw, FM801_REG(chip, IRQ_MASK));
+
+ /* interrupt clear */
+ outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
+
+ return 0;
+}
+
+
+static int snd_fm801_free(struct fm801 *chip)
{
unsigned short cmdw;
@@ -1232,7 +1327,7 @@ static int snd_fm801_free(fm801_t *chip)
snd_tea575x_exit(&chip->tea);
#endif
if (chip->irq >= 0)
- free_irq(chip->irq, (void *)chip);
+ free_irq(chip->irq, chip);
pci_release_regions(chip->pci);
pci_disable_device(chip->pci);
@@ -1240,23 +1335,21 @@ static int snd_fm801_free(fm801_t *chip)
return 0;
}
-static int snd_fm801_dev_free(snd_device_t *device)
+static int snd_fm801_dev_free(struct snd_device *device)
{
- fm801_t *chip = device->device_data;
+ struct fm801 *chip = device->device_data;
return snd_fm801_free(chip);
}
-static int __devinit snd_fm801_create(snd_card_t * card,
+static int __devinit snd_fm801_create(struct snd_card *card,
struct pci_dev * pci,
int tea575x_tuner,
- fm801_t ** rchip)
+ struct fm801 ** rchip)
{
- fm801_t *chip;
- unsigned char rev, id;
- unsigned short cmdw;
- unsigned long timeout;
+ struct fm801 *chip;
+ unsigned char rev;
int err;
- static snd_device_ops_t ops = {
+ static struct snd_device_ops ops = {
.dev_free = snd_fm801_dev_free,
};
@@ -1278,7 +1371,8 @@ static int __devinit snd_fm801_create(snd_card_t * card,
return err;
}
chip->port = pci_resource_start(pci, 0);
- if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
+ if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ,
+ "FM801", chip)) {
snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
snd_fm801_free(chip);
return -EBUSY;
@@ -1290,80 +1384,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
if (rev >= 0xb1) /* FM801-AU */
chip->multichannel = 1;
- /* codec cold reset + AC'97 warm reset */
- outw((1<<5)|(1<<6), FM801_REG(chip, CODEC_CTRL));
- inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
- udelay(100);
- outw(0, FM801_REG(chip, CODEC_CTRL));
-
- timeout = (jiffies + (3 * HZ) / 4) + 1; /* min 750ms */
-
- outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
- udelay(5);
- do {
- if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
- goto __ac97_secondary;
- schedule_timeout_uninterruptible(1);
- } while (time_after(timeout, jiffies));
- snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
- snd_fm801_free(chip);
- return -EIO;
-
- __ac97_secondary:
- if (!chip->multichannel) /* lookup is not required */
- goto __ac97_ok;
- for (id = 3; id > 0; id--) { /* my card has the secondary codec */
- /* at address #3, so the loop is inverted */
-
- timeout = jiffies + HZ / 20;
-
- outw((1<<7) | (id << FM801_AC97_ADDR_SHIFT) | AC97_VENDOR_ID1, FM801_REG(chip, AC97_CMD));
- udelay(5);
- do {
- if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) {
- cmdw = inw(FM801_REG(chip, AC97_DATA));
- if (cmdw != 0xffff && cmdw != 0) {
- chip->secondary = 1;
- chip->secondary_addr = id;
- goto __ac97_ok;
- }
- }
- schedule_timeout_uninterruptible(1);
- } while (time_after(timeout, jiffies));
- }
-
- /* the recovery phase, it seems that probing for non-existing codec might */
- /* cause timeout problems */
- timeout = (jiffies + (3 * HZ) / 4) + 1; /* min 750ms */
-
- outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
- udelay(5);
- do {
- if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
- goto __ac97_ok;
- schedule_timeout_uninterruptible(1);
- } while (time_after(timeout, jiffies));
- snd_printk(KERN_ERR "Primary AC'97 codec not responding\n");
- snd_fm801_free(chip);
- return -EIO;
-
- __ac97_ok:
-
- /* init volume */
- outw(0x0808, FM801_REG(chip, PCM_VOL));
- outw(0x9f1f, FM801_REG(chip, FM_VOL));
- outw(0x8808, FM801_REG(chip, I2S_VOL));
-
- /* I2S control - I2S mode */
- outw(0x0003, FM801_REG(chip, I2S_MODE));
-
- /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */
- cmdw = inw(FM801_REG(chip, IRQ_MASK));
- cmdw &= ~0x0083;
- outw(cmdw, FM801_REG(chip, IRQ_MASK));
-
- /* interrupt clear */
- outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
+ snd_fm801_chip_init(chip, 0);
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
snd_fm801_free(chip);
@@ -1391,9 +1412,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
static int dev;
- snd_card_t *card;
- fm801_t *chip;
- opl3_t *opl3;
+ struct snd_card *card;
+ struct fm801 *chip;
+ struct snd_opl3 *opl3;
int err;
if (dev >= SNDRV_CARDS)
@@ -1410,6 +1431,7 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
snd_card_free(card);
return err;
}
+ card->private_data = chip;
strcpy(card->driver, "FM801");
strcpy(card->shortname, "ForteMedia FM801-");
@@ -1457,11 +1479,65 @@ static void __devexit snd_card_fm801_remove(struct pci_dev *pci)
pci_set_drvdata(pci, NULL);
}
+#ifdef CONFIG_PM
+static unsigned char saved_regs[] = {
+ FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
+ FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
+ FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2,
+ FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL,
+};
+
+static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)
+{
+ struct snd_card *card = pci_get_drvdata(pci);
+ struct fm801 *chip = card->private_data;
+ int i;
+
+ snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+ snd_pcm_suspend_all(chip->pcm);
+ snd_ac97_suspend(chip->ac97);
+ snd_ac97_suspend(chip->ac97_sec);
+ for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+ chip->saved_regs[i] = inw(chip->port + saved_regs[i]);
+ /* FIXME: tea575x suspend */
+
+ pci_set_power_state(pci, PCI_D3hot);
+ pci_disable_device(pci);
+ pci_save_state(pci);
+ return 0;
+}
+
+static int snd_fm801_resume(struct pci_dev *pci)
+{
+ struct snd_card *card = pci_get_drvdata(pci);
+ struct fm801 *chip = card->private_data;
+ int i;
+
+ pci_restore_state(pci);
+ pci_enable_device(pci);
+ pci_set_power_state(pci, PCI_D0);
+ pci_set_master(pci);
+
+ snd_fm801_chip_init(chip, 1);
+ snd_ac97_resume(chip->ac97);
+ snd_ac97_resume(chip->ac97_sec);
+ for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+ outw(chip->saved_regs[i], chip->port + saved_regs[i]);
+
+ snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+ return 0;
+}
+#endif
+
static struct pci_driver driver = {
.name = "FM801",
.id_table = snd_fm801_ids,
.probe = snd_card_fm801_probe,
.remove = __devexit_p(snd_card_fm801_remove),
+#ifdef CONFIG_PM
+ .suspend = snd_fm801_suspend,
+ .resume = snd_fm801_resume,
+#endif
};
static int __init alsa_card_fm801_init(void)
OpenPOWER on IntegriCloud