X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Ffm801.c;h=9a0e1580b58ed9b8e2922f6ac461dc5ba974c75f;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=f21a17dda09408678d11822f1f6f8620e386c640;hpb=a2c21200f1c81b08cb55e417b68150bba439b646;p=linux-2.6.git diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index f21a17dda..9a0e1580b 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -40,13 +40,10 @@ #define TEA575X_RADIO 1 #endif -#define chip_t fm801_t - MODULE_AUTHOR("Jaroslav Kysela "); MODULE_DESCRIPTION("ForteMedia FM801"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{ForteMedia,FM801}," +MODULE_SUPPORTED_DEVICE("{{ForteMedia,FM801}," "{Genius,SoundMaker Live 5.1}}"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ @@ -64,16 +61,12 @@ static int boot_devs; module_param_array(index, int, boot_devs, 0444); MODULE_PARM_DESC(index, "Index value for the FM801 soundcard."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); module_param_array(id, charp, boot_devs, 0444); MODULE_PARM_DESC(id, "ID string for the FM801 soundcard."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); module_param_array(enable, bool, boot_devs, 0444); MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); module_param_array(tea575x_tuner, bool, boot_devs, 0444); MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner."); -MODULE_PARM_SYNTAX(tea575x_tuner, SNDRV_ENABLE_DESC); /* * Direct registers @@ -161,7 +154,6 @@ struct _snd_fm801 { int irq; unsigned long port; /* I/O port number */ - struct resource *res_port; unsigned int multichannel: 1, /* multichannel support */ secondary: 1; /* secondary codec */ unsigned char secondary_addr; /* address of the secondary codec */ @@ -233,7 +225,7 @@ static void snd_fm801_codec_write(ac97_t *ac97, unsigned short reg, unsigned short val) { - fm801_t *chip = snd_magic_cast(fm801_t, ac97->private_data, return); + fm801_t *chip = ac97->private_data; int idx; /* @@ -264,7 +256,7 @@ static void snd_fm801_codec_write(ac97_t *ac97, static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg) { - fm801_t *chip = snd_magic_cast(fm801_t, ac97->private_data, return -ENXIO); + fm801_t *chip = ac97->private_data; int idx; /* @@ -308,10 +300,8 @@ static unsigned int rates[] = { 38400, 44100, 48000 }; -#define RATES sizeof(rates) / sizeof(rates[0]) - static snd_pcm_hw_constraint_list_t hw_constraints_rates = { - .count = RATES, + .count = ARRAY_SIZE(rates), .list = rates, .mask = 0, }; @@ -336,11 +326,11 @@ static unsigned short snd_fm801_rate_bits(unsigned int rate) { unsigned int idx; - for (idx = 0; idx < 11; idx++) + for (idx = 0; idx < ARRAY_SIZE(rates); idx++) if (rates[idx] == rate) return idx; snd_BUG(); - return RATES - 1; + return ARRAY_SIZE(rates) - 1; } /* @@ -487,42 +477,40 @@ static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream) static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substream) { fm801_t *chip = snd_pcm_substream_chip(substream); - unsigned long flags; size_t ptr; if (!(chip->ply_ctrl & FM801_START)) return 0; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock(&chip->reg_lock); ptr = chip->ply_pos + (chip->ply_count - 1) - inw(FM801_REG(chip, PLY_COUNT)); if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_PLAYBACK) { ptr += chip->ply_count; ptr %= chip->ply_size; } - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock(&chip->reg_lock); return bytes_to_frames(substream->runtime, ptr); } static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substream) { fm801_t *chip = snd_pcm_substream_chip(substream); - unsigned long flags; size_t ptr; if (!(chip->cap_ctrl & FM801_START)) return 0; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock(&chip->reg_lock); ptr = chip->cap_pos + (chip->cap_count - 1) - inw(FM801_REG(chip, CAP_COUNT)); if (inw(FM801_REG(chip, IRQ_STATUS)) & FM801_IRQ_CAPTURE) { ptr += chip->cap_count; ptr %= chip->cap_size; } - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock(&chip->reg_lock); return bytes_to_frames(substream->runtime, ptr); } static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - fm801_t *chip = snd_magic_cast(fm801_t, dev_id, return IRQ_NONE); + fm801_t *chip = dev_id; unsigned short status; unsigned int tmp; @@ -680,7 +668,7 @@ static snd_pcm_ops_t snd_fm801_capture_ops = { static void snd_fm801_pcm_free(snd_pcm_t *pcm) { - fm801_t *chip = snd_magic_cast(fm801_t, pcm->private_data, return); + fm801_t *chip = pcm->private_data; chip->pcm = NULL; snd_pcm_lib_preallocate_free_for_all(pcm); } @@ -1076,10 +1064,10 @@ static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t int mask = (kcontrol->private_value >> 16) & 0xff; int invert = (kcontrol->private_value >> 24) & 0xff; - spin_lock(&chip->reg_lock); + spin_lock_irq(&chip->reg_lock); ucontrol->value.integer.value[0] = (inw(chip->port + reg) >> shift_left) & mask; ucontrol->value.integer.value[1] = (inw(chip->port + reg) >> shift_right) & mask; - spin_unlock(&chip->reg_lock); + spin_unlock_irq(&chip->reg_lock); if (invert) { ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; @@ -1176,13 +1164,13 @@ FM801_SINGLE("IEC958 Playback Switch", FM801_GEN_CTRL, 2, 1, 0), static void snd_fm801_mixer_free_ac97_bus(ac97_bus_t *bus) { - fm801_t *chip = snd_magic_cast(fm801_t, bus->private_data, return); + fm801_t *chip = bus->private_data; chip->ac97_bus = NULL; } static void snd_fm801_mixer_free_ac97(ac97_t *ac97) { - fm801_t *chip = snd_magic_cast(fm801_t, ac97->private_data, return); + fm801_t *chip = ac97->private_data; if (ac97->num == 0) { chip->ac97 = NULL; } else { @@ -1192,18 +1180,17 @@ static void snd_fm801_mixer_free_ac97(ac97_t *ac97) static int __devinit snd_fm801_mixer(fm801_t *chip) { - ac97_bus_t bus; - ac97_t ac97; + ac97_template_t ac97; unsigned int i; int err; + static ac97_bus_ops_t ops = { + .write = snd_fm801_codec_write, + .read = snd_fm801_codec_read, + }; - memset(&bus, 0, sizeof(bus)); - bus.write = snd_fm801_codec_write; - bus.read = snd_fm801_codec_read; - bus.private_data = chip; - bus.private_free = snd_fm801_mixer_free_ac97_bus; - if ((err = snd_ac97_bus(chip->card, &bus, &chip->ac97_bus)) < 0) + if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) return err; + chip->ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; @@ -1245,20 +1232,17 @@ static int snd_fm801_free(fm801_t *chip) #ifdef TEA575X_RADIO snd_tea575x_exit(&chip->tea); #endif - if (chip->res_port) { - release_resource(chip->res_port); - kfree_nocheck(chip->res_port); - } if (chip->irq >= 0) free_irq(chip->irq, (void *)chip); + pci_release_regions(chip->pci); - snd_magic_kfree(chip); + kfree(chip); return 0; } static int snd_fm801_dev_free(snd_device_t *device) { - fm801_t *chip = snd_magic_cast(fm801_t, device->device_data, return -ENXIO); + fm801_t *chip = device->device_data; return snd_fm801_free(chip); } @@ -1279,19 +1263,18 @@ static int __devinit snd_fm801_create(snd_card_t * card, *rchip = NULL; if ((err = pci_enable_device(pci)) < 0) return err; - chip = snd_magic_kcalloc(fm801_t, 0, GFP_KERNEL); + chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); if (chip == NULL) return -ENOMEM; spin_lock_init(&chip->reg_lock); chip->card = card; chip->pci = pci; chip->irq = -1; - chip->port = pci_resource_start(pci, 0); - if ((chip->res_port = request_region(chip->port, 0x80, "FM801")) == NULL) { - snd_printk("unable to grab region 0x%lx-0x%lx\n", chip->port, chip->port + 0x80 - 1); - snd_fm801_free(chip); - return -EBUSY; + if ((err = pci_request_regions(pci, "FM801")) < 0) { + kfree(chip); + return err; } + chip->port = pci_resource_start(pci, 0); if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) { snd_printk("unable to grab IRQ %d\n", chip->irq); snd_fm801_free(chip);