X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=sound%2Fpci%2Fals4000.c;h=8d0d9c0222c1eae015527a76416f7fe201c2d7db;hb=95de77660bb54e603d32f2ce342ae16e6de1b2d4;hp=ca28b229c704051154ef1a05aae2a485f7234e64;hpb=d6ac1a7910d22626bc77e73db091e00b810715f4;p=linux-2.6-omap-h63xx.git diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index ca28b229c70..8d0d9c0222c 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c @@ -6,6 +6,21 @@ * * Framework borrowed from Massimo Piccioni's card-als100.c. * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * * NOTES * * Since Avance does not provide any meaningful documentation, and I @@ -43,19 +58,9 @@ * Set KSound: * - value -> some port 0x0c0d * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * ToDo: + * - Proper shared IRQ handling? + * - power management? (card can do voice wakeup according to datasheet!!) */ #include @@ -100,13 +105,14 @@ module_param_array(joystick_port, int, NULL, 0444); MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)"); #endif -typedef struct { - struct pci_dev *pci; +struct snd_card_als4000 { + /* most frequent access first */ unsigned long gcr; + struct pci_dev *pci; #ifdef SUPPORT_JOYSTICK struct gameport *gameport; #endif -} snd_card_als4000_t; +}; static struct pci_device_id snd_als4000_ids[] = { { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */ @@ -121,7 +127,7 @@ static inline void snd_als4000_gcr_write_addr(unsigned long port, u32 reg, u32 v outl(val, port+0x08); } -static inline void snd_als4000_gcr_write(sb_t *sb, u32 reg, u32 val) +static inline void snd_als4000_gcr_write(struct snd_sb *sb, u32 reg, u32 val) { snd_als4000_gcr_write_addr(sb->alt_port, reg, val); } @@ -132,12 +138,12 @@ static inline u32 snd_als4000_gcr_read_addr(unsigned long port, u32 reg) return inl(port+0x08); } -static inline u32 snd_als4000_gcr_read(sb_t *sb, u32 reg) +static inline u32 snd_als4000_gcr_read(struct snd_sb *sb, u32 reg) { return snd_als4000_gcr_read_addr(sb->alt_port, reg); } -static void snd_als4000_set_rate(sb_t *chip, unsigned int rate) +static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate) { if (!(chip->mode & SB_RATE_LOCK)) { snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT); @@ -146,13 +152,15 @@ static void snd_als4000_set_rate(sb_t *chip, unsigned int rate) } } -static void snd_als4000_set_capture_dma(sb_t *chip, dma_addr_t addr, unsigned size) +static inline void snd_als4000_set_capture_dma(struct snd_sb *chip, + dma_addr_t addr, unsigned size) { snd_als4000_gcr_write(chip, 0xa2, addr); snd_als4000_gcr_write(chip, 0xa3, (size-1)); } -static void snd_als4000_set_playback_dma(sb_t *chip, dma_addr_t addr, unsigned size) +static inline void snd_als4000_set_playback_dma(struct snd_sb *chip, + dma_addr_t addr, unsigned size) { snd_als4000_gcr_write(chip, 0x91, addr); snd_als4000_gcr_write(chip, 0x92, (size-1)|0x180000); @@ -162,7 +170,7 @@ static void snd_als4000_set_playback_dma(sb_t *chip, dma_addr_t addr, unsigned s #define ALS4000_FORMAT_16BIT (1<<1) #define ALS4000_FORMAT_STEREO (1<<2) -static int snd_als4000_get_format(snd_pcm_runtime_t *runtime) +static int snd_als4000_get_format(struct snd_pcm_runtime *runtime) { int result; @@ -177,7 +185,7 @@ static int snd_als4000_get_format(snd_pcm_runtime_t *runtime) } /* structure for setting up playback */ -static struct { +static const struct { unsigned char dsp_cmd, dma_on, dma_off, format; } playback_cmd_vals[]={ /* ALS4000_FORMAT_U8_MONO */ @@ -201,7 +209,7 @@ static struct { /* structure for setting up capture */ enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 }; -static unsigned char capture_cmd_vals[]= +static const unsigned char capture_cmd_vals[]= { CMD_WIDTH8|CMD_MONO, /* ALS4000_FORMAT_U8_MONO */ CMD_WIDTH8|CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S8_MONO */ @@ -214,23 +222,22 @@ CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S16L_STEREO */ }; #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format]) -static int snd_als4000_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_als4000_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_als4000_hw_free(snd_pcm_substream_t * substream) +static int snd_als4000_hw_free(struct snd_pcm_substream *substream) { snd_pcm_lib_free_pages(substream); return 0; } -static int snd_als4000_capture_prepare(snd_pcm_substream_t * substream) +static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream) { - unsigned long flags; - sb_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_sb *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; unsigned long size; unsigned count; @@ -243,22 +250,21 @@ static int snd_als4000_capture_prepare(snd_pcm_substream_t * substream) count >>=1; count--; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); snd_als4000_set_rate(chip, runtime->rate); snd_als4000_set_capture_dma(chip, runtime->dma_addr, size); - spin_unlock_irqrestore(&chip->reg_lock, flags); - spin_lock_irqsave(&chip->mixer_lock, flags ); + spin_unlock_irq(&chip->reg_lock); + spin_lock_irq(&chip->mixer_lock); snd_sbmixer_write(chip, 0xdc, count); snd_sbmixer_write(chip, 0xdd, count>>8); - spin_unlock_irqrestore(&chip->mixer_lock, flags ); + spin_unlock_irq(&chip->mixer_lock); return 0; } -static int snd_als4000_playback_prepare(snd_pcm_substream_t *substream) +static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream) { - unsigned long flags; - sb_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_sb *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; unsigned long size; unsigned count; @@ -277,7 +283,7 @@ static int snd_als4000_playback_prepare(snd_pcm_substream_t *substream) * reordering, ...). Something seems to get enabled on playback * that I haven't found out how to disable again, which then causes * the switching pops to reach the speakers the next time here. */ - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); snd_als4000_set_rate(chip, runtime->rate); snd_als4000_set_playback_dma(chip, runtime->dma_addr, size); @@ -288,14 +294,14 @@ static int snd_als4000_playback_prepare(snd_pcm_substream_t *substream) snd_sbdsp_command(chip, count); snd_sbdsp_command(chip, count>>8); snd_sbdsp_command(chip, playback_cmd(chip).dma_off); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return 0; } -static int snd_als4000_capture_trigger(snd_pcm_substream_t * substream, int cmd) +static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int cmd) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); int result = 0; spin_lock(&chip->mixer_lock); @@ -312,9 +318,9 @@ static int snd_als4000_capture_trigger(snd_pcm_substream_t * substream, int cmd) return result; } -static int snd_als4000_playback_trigger(snd_pcm_substream_t * substream, int cmd) +static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int cmd) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); int result = 0; spin_lock(&chip->reg_lock); @@ -331,9 +337,9 @@ static int snd_als4000_playback_trigger(snd_pcm_substream_t * substream, int cmd return result; } -static snd_pcm_uframes_t snd_als4000_capture_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); unsigned int result; spin_lock(&chip->reg_lock); @@ -342,9 +348,9 @@ static snd_pcm_uframes_t snd_als4000_capture_pointer(snd_pcm_substream_t * subst return bytes_to_frames( substream->runtime, result ); } -static snd_pcm_uframes_t snd_als4000_playback_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); unsigned result; spin_lock(&chip->reg_lock); @@ -353,9 +359,21 @@ static snd_pcm_uframes_t snd_als4000_playback_pointer(snd_pcm_substream_t * subs return bytes_to_frames( substream->runtime, result ); } +/* FIXME: this IRQ routine doesn't really support IRQ sharing (we always + * return IRQ_HANDLED no matter whether we actually had an IRQ flag or not). + * ALS4000a.PDF writes that while ACKing IRQ in PCI block will *not* ACK + * the IRQ in the SB core, ACKing IRQ in SB block *will* ACK the PCI IRQ + * register (alt_port + 0x0e). Probably something could be optimized here to + * query/write one register only... + * And even if both registers need to be queried, then there's still the + * question of whether it's actually correct to ACK PCI IRQ before reading + * SB IRQ like we do now, since ALS4000a.PDF mentions that PCI IRQ will *clear* + * SB IRQ status. + * And do we *really* need the lock here for *reading* SB_DSP4_IRQSTATUS?? + * */ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - sb_t *chip = dev_id; + struct snd_sb *chip = dev_id; unsigned gcr_status; unsigned sb_status; @@ -388,7 +406,7 @@ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id, struct pt_regs * /*****************************************************************/ -static snd_pcm_hardware_t snd_als4000_playback = +static struct snd_pcm_hardware snd_als4000_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID), @@ -407,7 +425,7 @@ static snd_pcm_hardware_t snd_als4000_playback = .fifo_size = 0 }; -static snd_pcm_hardware_t snd_als4000_capture = +static struct snd_pcm_hardware snd_als4000_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID), @@ -428,38 +446,38 @@ static snd_pcm_hardware_t snd_als4000_capture = /*****************************************************************/ -static int snd_als4000_playback_open(snd_pcm_substream_t * substream) +static int snd_als4000_playback_open(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_sb *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; chip->playback_substream = substream; runtime->hw = snd_als4000_playback; return 0; } -static int snd_als4000_playback_close(snd_pcm_substream_t * substream) +static int snd_als4000_playback_close(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); chip->playback_substream = NULL; snd_pcm_lib_free_pages(substream); return 0; } -static int snd_als4000_capture_open(snd_pcm_substream_t * substream) +static int snd_als4000_capture_open(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_sb *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; chip->capture_substream = substream; runtime->hw = snd_als4000_capture; return 0; } -static int snd_als4000_capture_close(snd_pcm_substream_t * substream) +static int snd_als4000_capture_close(struct snd_pcm_substream *substream) { - sb_t *chip = snd_pcm_substream_chip(substream); + struct snd_sb *chip = snd_pcm_substream_chip(substream); chip->capture_substream = NULL; snd_pcm_lib_free_pages(substream); @@ -468,7 +486,7 @@ static int snd_als4000_capture_close(snd_pcm_substream_t * substream) /******************************************************************/ -static snd_pcm_ops_t snd_als4000_playback_ops = { +static struct snd_pcm_ops snd_als4000_playback_ops = { .open = snd_als4000_playback_open, .close = snd_als4000_playback_close, .ioctl = snd_pcm_lib_ioctl, @@ -479,7 +497,7 @@ static snd_pcm_ops_t snd_als4000_playback_ops = { .pointer = snd_als4000_playback_pointer }; -static snd_pcm_ops_t snd_als4000_capture_ops = { +static struct snd_pcm_ops snd_als4000_capture_ops = { .open = snd_als4000_capture_open, .close = snd_als4000_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -490,21 +508,13 @@ static snd_pcm_ops_t snd_als4000_capture_ops = { .pointer = snd_als4000_capture_pointer }; -static void snd_als4000_pcm_free(snd_pcm_t *pcm) -{ - sb_t *chip = pcm->private_data; - chip->pcm = NULL; - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -static int __devinit snd_als4000_pcm(sb_t *chip, int device) +static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0) return err; - pcm->private_free = snd_als4000_pcm_free; pcm->private_data = chip; pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops); @@ -541,7 +551,7 @@ static void snd_als4000_set_addr(unsigned long gcr, snd_als4000_gcr_write_addr(gcr, 0xa9, confB); } -static void __devinit snd_als4000_configure(sb_t *chip) +static void __devinit snd_als4000_configure(struct snd_sb *chip) { unsigned tmp; int i; @@ -566,7 +576,7 @@ static void __devinit snd_als4000_configure(sb_t *chip) } #ifdef SUPPORT_JOYSTICK -static int __devinit snd_als4000_create_gameport(snd_card_als4000_t *acard, int dev) +static int __devinit snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) { struct gameport *gp; struct resource *r; @@ -594,8 +604,7 @@ static int __devinit snd_als4000_create_gameport(snd_card_als4000_t *acard, int acard->gameport = gp = gameport_allocate_port(); if (!gp) { printk(KERN_ERR "als4000: cannot allocate memory for gameport\n"); - release_resource(r); - kfree_nocheck(r); + release_and_free_resource(r); return -ENOMEM; } @@ -613,7 +622,7 @@ static int __devinit snd_als4000_create_gameport(snd_card_als4000_t *acard, int return 0; } -static void snd_als4000_free_gameport(snd_card_als4000_t *acard) +static void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { if (acard->gameport) { struct resource *r = gameport_get_port_data(acard->gameport); @@ -622,18 +631,17 @@ static void snd_als4000_free_gameport(snd_card_als4000_t *acard) acard->gameport = NULL; snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */ - release_resource(r); - kfree_nocheck(r); + release_and_free_resource(r); } } #else -static inline int snd_als4000_create_gameport(snd_card_als4000_t *acard, int dev) { return -ENOSYS; } -static inline void snd_als4000_free_gameport(snd_card_als4000_t *acard) { } +static inline int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) { return -ENOSYS; } +static inline void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { } #endif -static void snd_card_als4000_free( snd_card_t *card ) +static void snd_card_als4000_free( struct snd_card *card ) { - snd_card_als4000_t * acard = (snd_card_als4000_t *)card->private_data; + struct snd_card_als4000 * acard = (struct snd_card_als4000 *)card->private_data; /* make sure that interrupts are disabled */ snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0); @@ -647,11 +655,11 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; - snd_card_t *card; - snd_card_als4000_t *acard; + struct snd_card *card; + struct snd_card_als4000 *acard; unsigned long gcr; - sb_t *chip; - opl3_t *opl3; + struct snd_sb *chip; + struct snd_opl3 *opl3; unsigned short word; int err; @@ -669,7 +677,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, /* check, if we can restrict PCI DMA transfers to 24 bits */ if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { - snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); + snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); pci_disable_device(pci); return -ENXIO; } @@ -685,14 +693,14 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, pci_set_master(pci); card = snd_card_new(index[dev], id[dev], THIS_MODULE, - sizeof( snd_card_als4000_t ) ); + sizeof( struct snd_card_als4000 ) ); if (card == NULL) { pci_release_regions(pci); pci_disable_device(pci); return -ENOMEM; } - acard = (snd_card_als4000_t *)card->private_data; + acard = (struct snd_card_als4000 *)card->private_data; acard->pci = pci; acard->gcr = gcr; card->private_free = snd_card_als4000_free; @@ -708,8 +716,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, -1, SB_HW_ALS4000, &chip)) < 0) { - snd_card_free(card); - return err; + goto out_err; } chip->pci = pci; @@ -726,40 +733,42 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci, if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, gcr+0x30, 1, pci->irq, 0, &chip->rmidi)) < 0) { - snd_card_free(card); - printk(KERN_ERR "als4000: no MPU-401device at 0x%lx ?\n", gcr+0x30); - return err; + printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", gcr+0x30); + goto out_err; } if ((err = snd_als4000_pcm(chip, 0)) < 0) { - snd_card_free(card); - return err; + goto out_err; } if ((err = snd_sbmixer_new(chip)) < 0) { - snd_card_free(card); - return err; + goto out_err; } if (snd_opl3_create(card, gcr+0x10, gcr+0x12, OPL3_HW_AUTO, 1, &opl3) < 0) { - printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx ?\n", + printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n", gcr+0x10, gcr+0x12 ); } else { if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { - snd_card_free(card); - return err; + goto out_err; } } snd_als4000_create_gameport(acard, dev); if ((err = snd_card_register(card)) < 0) { - snd_card_free(card); - return err; + goto out_err; } pci_set_drvdata(pci, card); dev++; - return 0; + err = 0; + goto out; + +out_err: + snd_card_free(card); + +out: + return err; } static void __devexit snd_card_als4000_remove(struct pci_dev *pci)