123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- #include <linux/io.h>
- #include <linux/init.h>
- #include <linux/pci.h>
- #include <linux/gameport.h>
- #include <linux/module.h>
- #include <linux/dma-mapping.h>
- #include <sound/core.h>
- #include <sound/pcm.h>
- #include <sound/rawmidi.h>
- #include <sound/mpu401.h>
- #include <sound/opl3.h>
- #include <sound/sb.h>
- #include <sound/initval.h>
- MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>, Andreas Mohr");
- MODULE_DESCRIPTION("Avance Logic ALS4000");
- MODULE_LICENSE("GPL");
- MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}");
- #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
- #define SUPPORT_JOYSTICK 1
- #endif
- static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
- static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
- static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
- #ifdef SUPPORT_JOYSTICK
- static int joystick_port[SNDRV_CARDS];
- #endif
- module_param_array(index, int, NULL, 0444);
- MODULE_PARM_DESC(index, "Index value for ALS4000 soundcard.");
- module_param_array(id, charp, NULL, 0444);
- MODULE_PARM_DESC(id, "ID string for ALS4000 soundcard.");
- module_param_array(enable, bool, NULL, 0444);
- MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard.");
- #ifdef SUPPORT_JOYSTICK
- module_param_array(joystick_port, int, NULL, 0444);
- MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)");
- #endif
- struct snd_card_als4000 {
-
- unsigned long iobase;
- struct pci_dev *pci;
- struct snd_sb *chip;
- #ifdef SUPPORT_JOYSTICK
- struct gameport *gameport;
- #endif
- };
- static const struct pci_device_id snd_als4000_ids[] = {
- { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
- { 0, }
- };
- MODULE_DEVICE_TABLE(pci, snd_als4000_ids);
- enum als4k_iobase_t {
-
- ALS4K_IOD_00_AC97_ACCESS = 0x00,
- ALS4K_IOW_04_AC97_READ = 0x04,
- ALS4K_IOB_06_AC97_STATUS = 0x06,
- ALS4K_IOB_07_IRQSTATUS = 0x07,
- ALS4K_IOD_08_GCR_DATA = 0x08,
- ALS4K_IOB_0C_GCR_INDEX = 0x0c,
- ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU = 0x0e,
- ALS4K_IOB_10_ADLIB_ADDR0 = 0x10,
- ALS4K_IOB_11_ADLIB_ADDR1 = 0x11,
- ALS4K_IOB_12_ADLIB_ADDR2 = 0x12,
- ALS4K_IOB_13_ADLIB_ADDR3 = 0x13,
- ALS4K_IOB_14_MIXER_INDEX = 0x14,
- ALS4K_IOB_15_MIXER_DATA = 0x15,
- ALS4K_IOB_16_ESP_RESET = 0x16,
- ALS4K_IOB_16_ACK_FOR_CR1E = 0x16,
- ALS4K_IOB_18_OPL_ADDR0 = 0x18,
- ALS4K_IOB_19_OPL_ADDR1 = 0x19,
- ALS4K_IOB_1A_ESP_RD_DATA = 0x1a,
- ALS4K_IOB_1C_ESP_CMD_DATA = 0x1c,
- ALS4K_IOB_1C_ESP_WR_STATUS = 0x1c,
- ALS4K_IOB_1E_ESP_RD_STATUS8 = 0x1e,
- ALS4K_IOB_1F_ESP_RD_STATUS16 = 0x1f,
- ALS4K_IOB_20_ESP_GAMEPORT_200 = 0x20,
- ALS4K_IOB_21_ESP_GAMEPORT_201 = 0x21,
- ALS4K_IOB_30_MIDI_DATA = 0x30,
- ALS4K_IOB_31_MIDI_STATUS = 0x31,
- ALS4K_IOB_31_MIDI_COMMAND = 0x31,
- };
- enum als4k_iobase_0e_t {
- ALS4K_IOB_0E_MPU_IRQ = 0x10,
- ALS4K_IOB_0E_CR1E_IRQ = 0x40,
- ALS4K_IOB_0E_SB_DMA_IRQ = 0x80,
- };
- enum als4k_gcr_t {
- ALS4K_GCR8C_MISC_CTRL = 0x8c,
- ALS4K_GCR90_TEST_MODE_REG = 0x90,
- ALS4K_GCR91_DMA0_ADDR = 0x91,
- ALS4K_GCR92_DMA0_MODE_COUNT = 0x92,
- ALS4K_GCR93_DMA1_ADDR = 0x93,
- ALS4K_GCR94_DMA1_MODE_COUNT = 0x94,
- ALS4K_GCR95_DMA3_ADDR = 0x95,
- ALS4K_GCR96_DMA3_MODE_COUNT = 0x96,
- ALS4K_GCR99_DMA_EMULATION_CTRL = 0x99,
- ALS4K_GCRA0_FIFO1_CURRENT_ADDR = 0xa0,
- ALS4K_GCRA1_FIFO1_STATUS_BYTECOUNT = 0xa1,
- ALS4K_GCRA2_FIFO2_PCIADDR = 0xa2,
- ALS4K_GCRA3_FIFO2_COUNT = 0xa3,
- ALS4K_GCRA4_FIFO2_CURRENT_ADDR = 0xa4,
- ALS4K_GCRA5_FIFO1_STATUS_BYTECOUNT = 0xa5,
- ALS4K_GCRA6_PM_CTRL = 0xa6,
- ALS4K_GCRA7_PCI_ACCESS_STORAGE = 0xa7,
- ALS4K_GCRA8_LEGACY_CFG1 = 0xa8,
- ALS4K_GCRA9_LEGACY_CFG2 = 0xa9,
- ALS4K_GCRFF_DUMMY_SCRATCH = 0xff,
- };
- enum als4k_gcr8c_t {
- ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE = 0x8000,
- ALS4K_GCR8C_CHIP_REV_MASK = 0xf0000
- };
- static inline void snd_als4k_iobase_writeb(unsigned long iobase,
- enum als4k_iobase_t reg,
- u8 val)
- {
- outb(val, iobase + reg);
- }
- static inline void snd_als4k_iobase_writel(unsigned long iobase,
- enum als4k_iobase_t reg,
- u32 val)
- {
- outl(val, iobase + reg);
- }
- static inline u8 snd_als4k_iobase_readb(unsigned long iobase,
- enum als4k_iobase_t reg)
- {
- return inb(iobase + reg);
- }
- static inline u32 snd_als4k_iobase_readl(unsigned long iobase,
- enum als4k_iobase_t reg)
- {
- return inl(iobase + reg);
- }
- static inline void snd_als4k_gcr_write_addr(unsigned long iobase,
- enum als4k_gcr_t reg,
- u32 val)
- {
- snd_als4k_iobase_writeb(iobase, ALS4K_IOB_0C_GCR_INDEX, reg);
- snd_als4k_iobase_writel(iobase, ALS4K_IOD_08_GCR_DATA, val);
- }
- static inline void snd_als4k_gcr_write(struct snd_sb *sb,
- enum als4k_gcr_t reg,
- u32 val)
- {
- snd_als4k_gcr_write_addr(sb->alt_port, reg, val);
- }
- static inline u32 snd_als4k_gcr_read_addr(unsigned long iobase,
- enum als4k_gcr_t reg)
- {
-
- snd_als4k_iobase_writeb(iobase, ALS4K_IOB_0C_GCR_INDEX, reg);
- return snd_als4k_iobase_readl(iobase, ALS4K_IOD_08_GCR_DATA);
- }
- static inline u32 snd_als4k_gcr_read(struct snd_sb *sb, enum als4k_gcr_t reg)
- {
- return snd_als4k_gcr_read_addr(sb->alt_port, reg);
- }
- enum als4k_cr_t {
- ALS4K_CR0_SB_CONFIG = 0x00,
- ALS4K_CR2_MISC_CONTROL = 0x02,
- ALS4K_CR3_CONFIGURATION = 0x03,
- ALS4K_CR17_FIFO_STATUS = 0x17,
- ALS4K_CR18_ESP_MAJOR_VERSION = 0x18,
- ALS4K_CR19_ESP_MINOR_VERSION = 0x19,
- ALS4K_CR1A_MPU401_UART_MODE_CONTROL = 0x1a,
- ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO = 0x1c,
- ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI = 0x1d,
- ALS4K_CR1E_FIFO2_CONTROL = 0x1e,
- ALS4K_CR3A_MISC_CONTROL = 0x3a,
- ALS4K_CR3B_CRC32_BYTE0 = 0x3b,
- ALS4K_CR3C_CRC32_BYTE1 = 0x3c,
- ALS4K_CR3D_CRC32_BYTE2 = 0x3d,
- ALS4K_CR3E_CRC32_BYTE3 = 0x3e,
- };
- enum als4k_cr0_t {
- ALS4K_CR0_DMA_CONTIN_MODE_CTRL = 0x02,
- ALS4K_CR0_DMA_90H_MODE_CTRL = 0x04,
- ALS4K_CR0_MX80_81_REG_WRITE_ENABLE = 0x80,
- };
- static inline void snd_als4_cr_write(struct snd_sb *chip,
- enum als4k_cr_t reg,
- u8 data)
- {
-
- snd_sbmixer_write(chip, reg | 0xc0, data);
- }
- static inline u8 snd_als4_cr_read(struct snd_sb *chip,
- enum als4k_cr_t reg)
- {
-
- return snd_sbmixer_read(chip, reg | 0xc0);
- }
- 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);
- snd_sbdsp_command(chip, rate>>8);
- snd_sbdsp_command(chip, rate);
- }
- }
- static inline void snd_als4000_set_capture_dma(struct snd_sb *chip,
- dma_addr_t addr, unsigned size)
- {
-
- snd_als4k_gcr_write(chip, ALS4K_GCRA2_FIFO2_PCIADDR, addr);
- snd_als4k_gcr_write(chip, ALS4K_GCRA3_FIFO2_COUNT, (size-1));
- }
- static inline void snd_als4000_set_playback_dma(struct snd_sb *chip,
- dma_addr_t addr,
- unsigned size)
- {
-
- snd_als4k_gcr_write(chip, ALS4K_GCR91_DMA0_ADDR, addr);
- snd_als4k_gcr_write(chip, ALS4K_GCR92_DMA0_MODE_COUNT,
- (size-1)|0x180000);
- }
- #define ALS4000_FORMAT_SIGNED (1<<0)
- #define ALS4000_FORMAT_16BIT (1<<1)
- #define ALS4000_FORMAT_STEREO (1<<2)
- static int snd_als4000_get_format(struct snd_pcm_runtime *runtime)
- {
- int result;
- result = 0;
- if (snd_pcm_format_signed(runtime->format))
- result |= ALS4000_FORMAT_SIGNED;
- if (snd_pcm_format_physical_width(runtime->format) == 16)
- result |= ALS4000_FORMAT_16BIT;
- if (runtime->channels > 1)
- result |= ALS4000_FORMAT_STEREO;
- return result;
- }
- static const struct {
- unsigned char dsp_cmd, dma_on, dma_off, format;
- } playback_cmd_vals[]={
- { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_MONO },
-
- { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_MONO },
- { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_MONO },
- { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_MONO },
- { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_STEREO },
-
- { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_STEREO },
- { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_STEREO },
- { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_STEREO },
- };
- #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format])
- enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 };
- static const unsigned char capture_cmd_vals[]=
- {
- CMD_WIDTH8|CMD_MONO,
- CMD_WIDTH8|CMD_SIGNED|CMD_MONO,
- CMD_MONO,
- CMD_SIGNED|CMD_MONO,
- CMD_WIDTH8|CMD_STEREO,
- CMD_WIDTH8|CMD_SIGNED|CMD_STEREO,
- CMD_STEREO,
- CMD_SIGNED|CMD_STEREO,
- };
- #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
- 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(struct snd_pcm_substream *substream)
- {
- snd_pcm_lib_free_pages(substream);
- return 0;
- }
- static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- unsigned long size;
- unsigned count;
- chip->capture_format = snd_als4000_get_format(runtime);
-
- size = snd_pcm_lib_buffer_bytes(substream);
- count = snd_pcm_lib_period_bytes(substream);
-
- if (chip->capture_format & ALS4000_FORMAT_16BIT)
- count >>= 1;
- count--;
- 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_irq(&chip->reg_lock);
- spin_lock_irq(&chip->mixer_lock);
- snd_als4_cr_write(chip, ALS4K_CR1C_FIFO2_BLOCK_LENGTH_LO, count & 0xff);
- snd_als4_cr_write(chip, ALS4K_CR1D_FIFO2_BLOCK_LENGTH_HI, count >> 8);
- spin_unlock_irq(&chip->mixer_lock);
- return 0;
- }
- static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- struct snd_pcm_runtime *runtime = substream->runtime;
- unsigned long size;
- unsigned count;
- chip->playback_format = snd_als4000_get_format(runtime);
-
- size = snd_pcm_lib_buffer_bytes(substream);
- count = snd_pcm_lib_period_bytes(substream);
-
- if (chip->playback_format & ALS4000_FORMAT_16BIT)
- count >>= 1;
- count--;
-
-
- spin_lock_irq(&chip->reg_lock);
- snd_als4000_set_rate(chip, runtime->rate);
- snd_als4000_set_playback_dma(chip, runtime->dma_addr, size);
-
-
-
- snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
- snd_sbdsp_command(chip, playback_cmd(chip).format);
- snd_sbdsp_command(chip, count & 0xff);
- snd_sbdsp_command(chip, count >> 8);
- snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
- spin_unlock_irq(&chip->reg_lock);
-
- return 0;
- }
- static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int cmd)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- int result = 0;
-
-
- spin_lock(&chip->mixer_lock);
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_RESUME:
- chip->mode |= SB_RATE_LOCK_CAPTURE;
- snd_als4_cr_write(chip, ALS4K_CR1E_FIFO2_CONTROL,
- capture_cmd(chip));
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- case SNDRV_PCM_TRIGGER_SUSPEND:
- chip->mode &= ~SB_RATE_LOCK_CAPTURE;
- snd_als4_cr_write(chip, ALS4K_CR1E_FIFO2_CONTROL,
- capture_cmd(chip));
- break;
- default:
- result = -EINVAL;
- break;
- }
- spin_unlock(&chip->mixer_lock);
- return result;
- }
- static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int cmd)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- int result = 0;
- spin_lock(&chip->reg_lock);
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_RESUME:
- chip->mode |= SB_RATE_LOCK_PLAYBACK;
- snd_sbdsp_command(chip, playback_cmd(chip).dma_on);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- case SNDRV_PCM_TRIGGER_SUSPEND:
- snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
- chip->mode &= ~SB_RATE_LOCK_PLAYBACK;
- break;
- default:
- result = -EINVAL;
- break;
- }
- spin_unlock(&chip->reg_lock);
- return result;
- }
- static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *substream)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- unsigned int result;
- spin_lock(&chip->reg_lock);
- result = snd_als4k_gcr_read(chip, ALS4K_GCRA4_FIFO2_CURRENT_ADDR);
- spin_unlock(&chip->reg_lock);
- result &= 0xffff;
- return bytes_to_frames( substream->runtime, result );
- }
- static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *substream)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- unsigned result;
- spin_lock(&chip->reg_lock);
- result = snd_als4k_gcr_read(chip, ALS4K_GCRA0_FIFO1_CURRENT_ADDR);
- spin_unlock(&chip->reg_lock);
- result &= 0xffff;
- return bytes_to_frames( substream->runtime, result );
- }
- static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id)
- {
- struct snd_sb *chip = dev_id;
- unsigned pci_irqstatus;
- unsigned sb_irqstatus;
-
- pci_irqstatus = snd_als4k_iobase_readb(chip->alt_port,
- ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU);
- if ((pci_irqstatus & ALS4K_IOB_0E_SB_DMA_IRQ)
- && (chip->playback_substream))
- snd_pcm_period_elapsed(chip->playback_substream);
- if ((pci_irqstatus & ALS4K_IOB_0E_CR1E_IRQ)
- && (chip->capture_substream))
- snd_pcm_period_elapsed(chip->capture_substream);
- if ((pci_irqstatus & ALS4K_IOB_0E_MPU_IRQ)
- && (chip->rmidi))
- snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
-
- snd_als4k_iobase_writeb(chip->alt_port,
- ALS4K_IOB_0E_IRQTYPE_SB_CR1E_MPU, pci_irqstatus);
-
- spin_lock(&chip->mixer_lock);
-
- sb_irqstatus = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
- spin_unlock(&chip->mixer_lock);
-
- if (sb_irqstatus & SB_IRQTYPE_8BIT)
- snd_sb_ack_8bit(chip);
- if (sb_irqstatus & SB_IRQTYPE_16BIT)
- snd_sb_ack_16bit(chip);
- if (sb_irqstatus & SB_IRQTYPE_MPUIN)
- inb(chip->mpu_port);
- if (sb_irqstatus & ALS4K_IRQTYPE_CR1E_DMA)
- snd_als4k_iobase_readb(chip->alt_port,
- ALS4K_IOB_16_ACK_FOR_CR1E);
-
-
- return IRQ_RETVAL(
- (pci_irqstatus & (ALS4K_IOB_0E_SB_DMA_IRQ|ALS4K_IOB_0E_CR1E_IRQ|
- ALS4K_IOB_0E_MPU_IRQ))
- || (sb_irqstatus & (SB_IRQTYPE_8BIT|SB_IRQTYPE_16BIT|
- SB_IRQTYPE_MPUIN|ALS4K_IRQTYPE_CR1E_DMA))
- );
- }
- static struct snd_pcm_hardware snd_als4000_playback =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_MMAP_VALID),
- .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
- SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE,
- .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
- .rate_min = 4000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = 65536,
- .period_bytes_min = 64,
- .period_bytes_max = 65536,
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0
- };
- static struct snd_pcm_hardware snd_als4000_capture =
- {
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_MMAP_VALID),
- .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
- SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE,
- .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
- .rate_min = 4000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = 65536,
- .period_bytes_min = 64,
- .period_bytes_max = 65536,
- .periods_min = 1,
- .periods_max = 1024,
- .fifo_size = 0
- };
- static int snd_als4000_playback_open(struct snd_pcm_substream *substream)
- {
- 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(struct snd_pcm_substream *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(struct snd_pcm_substream *substream)
- {
- 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(struct snd_pcm_substream *substream)
- {
- struct snd_sb *chip = snd_pcm_substream_chip(substream);
- chip->capture_substream = NULL;
- snd_pcm_lib_free_pages(substream);
- return 0;
- }
- static struct snd_pcm_ops snd_als4000_playback_ops = {
- .open = snd_als4000_playback_open,
- .close = snd_als4000_playback_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_als4000_hw_params,
- .hw_free = snd_als4000_hw_free,
- .prepare = snd_als4000_playback_prepare,
- .trigger = snd_als4000_playback_trigger,
- .pointer = snd_als4000_playback_pointer
- };
- static struct snd_pcm_ops snd_als4000_capture_ops = {
- .open = snd_als4000_capture_open,
- .close = snd_als4000_capture_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_als4000_hw_params,
- .hw_free = snd_als4000_hw_free,
- .prepare = snd_als4000_capture_prepare,
- .trigger = snd_als4000_capture_trigger,
- .pointer = snd_als4000_capture_pointer
- };
- static int snd_als4000_pcm(struct snd_sb *chip, int device)
- {
- struct snd_pcm *pcm;
- int err;
- err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm);
- if (err < 0)
- return err;
- 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);
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops);
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
- 64*1024, 64*1024);
- chip->pcm = pcm;
- return 0;
- }
- static void snd_als4000_set_addr(unsigned long iobase,
- unsigned int sb_io,
- unsigned int mpu_io,
- unsigned int opl_io,
- unsigned int game_io)
- {
- u32 cfg1 = 0;
- u32 cfg2 = 0;
- if (mpu_io > 0)
- cfg2 |= (mpu_io | 1) << 16;
- if (sb_io > 0)
- cfg2 |= (sb_io | 1);
- if (game_io > 0)
- cfg1 |= (game_io | 1) << 16;
- if (opl_io > 0)
- cfg1 |= (opl_io | 1);
- snd_als4k_gcr_write_addr(iobase, ALS4K_GCRA8_LEGACY_CFG1, cfg1);
- snd_als4k_gcr_write_addr(iobase, ALS4K_GCRA9_LEGACY_CFG2, cfg2);
- }
- static void snd_als4000_configure(struct snd_sb *chip)
- {
- u8 tmp;
- int i;
-
- spin_lock_irq(&chip->mixer_lock);
- tmp = snd_als4_cr_read(chip, ALS4K_CR0_SB_CONFIG);
- snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG,
- tmp|ALS4K_CR0_MX80_81_REG_WRITE_ENABLE);
-
- snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0);
- snd_als4_cr_write(chip, ALS4K_CR0_SB_CONFIG,
- tmp & ~ALS4K_CR0_MX80_81_REG_WRITE_ENABLE);
- spin_unlock_irq(&chip->mixer_lock);
-
- spin_lock_irq(&chip->reg_lock);
-
- snd_als4k_gcr_write(chip, ALS4K_GCR8C_MISC_CTRL,
- ALS4K_GCR8C_IRQ_MASK_CTRL_ENABLE);
-
- for (i = ALS4K_GCR91_DMA0_ADDR; i <= ALS4K_GCR96_DMA3_MODE_COUNT; ++i)
- snd_als4k_gcr_write(chip, i, 0);
-
- snd_als4k_gcr_write(chip, ALS4K_GCR99_DMA_EMULATION_CTRL,
- (snd_als4k_gcr_read(chip, ALS4K_GCR99_DMA_EMULATION_CTRL) & ~0x07) | 0x04);
- spin_unlock_irq(&chip->reg_lock);
- }
- #ifdef SUPPORT_JOYSTICK
- static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
- {
- struct gameport *gp;
- struct resource *r;
- int io_port;
- if (joystick_port[dev] == 0)
- return -ENODEV;
- if (joystick_port[dev] == 1) {
- for (io_port = 0x200; io_port <= 0x218; io_port += 8) {
- r = request_region(io_port, 8, "ALS4000 gameport");
- if (r)
- break;
- }
- } else {
- io_port = joystick_port[dev];
- r = request_region(io_port, 8, "ALS4000 gameport");
- }
- if (!r) {
- dev_warn(&acard->pci->dev, "cannot reserve joystick ports\n");
- return -EBUSY;
- }
- acard->gameport = gp = gameport_allocate_port();
- if (!gp) {
- dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n");
- release_and_free_resource(r);
- return -ENOMEM;
- }
- gameport_set_name(gp, "ALS4000 Gameport");
- gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci));
- gameport_set_dev_parent(gp, &acard->pci->dev);
- gp->io = io_port;
- gameport_set_port_data(gp, r);
-
- snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1);
- gameport_register_port(acard->gameport);
- return 0;
- }
- static void snd_als4000_free_gameport(struct snd_card_als4000 *acard)
- {
- if (acard->gameport) {
- struct resource *r = gameport_get_port_data(acard->gameport);
- gameport_unregister_port(acard->gameport);
- acard->gameport = NULL;
-
- snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0);
- release_and_free_resource(r);
- }
- }
- #else
- 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( struct snd_card *card )
- {
- struct snd_card_als4000 *acard = card->private_data;
-
- snd_als4k_gcr_write_addr(acard->iobase, ALS4K_GCR8C_MISC_CTRL, 0);
-
- snd_als4000_free_gameport(acard);
- pci_release_regions(acard->pci);
- pci_disable_device(acard->pci);
- }
- static int snd_card_als4000_probe(struct pci_dev *pci,
- const struct pci_device_id *pci_id)
- {
- static int dev;
- struct snd_card *card;
- struct snd_card_als4000 *acard;
- unsigned long iobase;
- struct snd_sb *chip;
- struct snd_opl3 *opl3;
- unsigned short word;
- int err;
- if (dev >= SNDRV_CARDS)
- return -ENODEV;
- if (!enable[dev]) {
- dev++;
- return -ENOENT;
- }
-
- if ((err = pci_enable_device(pci)) < 0) {
- return err;
- }
-
- if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
- dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) {
- dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n");
- pci_disable_device(pci);
- return -ENXIO;
- }
- if ((err = pci_request_regions(pci, "ALS4000")) < 0) {
- pci_disable_device(pci);
- return err;
- }
- iobase = pci_resource_start(pci, 0);
- pci_read_config_word(pci, PCI_COMMAND, &word);
- pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
- pci_set_master(pci);
-
- err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
- sizeof(*acard) ,
- &card);
- if (err < 0) {
- pci_release_regions(pci);
- pci_disable_device(pci);
- return err;
- }
- acard = card->private_data;
- acard->pci = pci;
- acard->iobase = iobase;
- card->private_free = snd_card_als4000_free;
-
- snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0);
- if ((err = snd_sbdsp_create(card,
- iobase + ALS4K_IOB_10_ADLIB_ADDR0,
- pci->irq,
-
- snd_als4000_interrupt,
- -1,
- -1,
- SB_HW_ALS4000,
- &chip)) < 0) {
- goto out_err;
- }
- acard->chip = chip;
- chip->pci = pci;
- chip->alt_port = iobase;
- snd_als4000_configure(chip);
- strcpy(card->driver, "ALS4000");
- strcpy(card->shortname, "Avance Logic ALS4000");
- sprintf(card->longname, "%s at 0x%lx, irq %i",
- card->shortname, chip->alt_port, chip->irq);
- if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
- iobase + ALS4K_IOB_30_MIDI_DATA,
- MPU401_INFO_INTEGRATED |
- MPU401_INFO_IRQ_HOOK,
- -1, &chip->rmidi)) < 0) {
- dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n",
- iobase + ALS4K_IOB_30_MIDI_DATA);
- goto out_err;
- }
-
- if ((err = snd_als4000_pcm(chip, 0)) < 0) {
- goto out_err;
- }
- if ((err = snd_sbmixer_new(chip)) < 0) {
- goto out_err;
- }
- if (snd_opl3_create(card,
- iobase + ALS4K_IOB_10_ADLIB_ADDR0,
- iobase + ALS4K_IOB_12_ADLIB_ADDR2,
- OPL3_HW_AUTO, 1, &opl3) < 0) {
- dev_err(&pci->dev, "no OPL device at 0x%lx-0x%lx?\n",
- iobase + ALS4K_IOB_10_ADLIB_ADDR0,
- iobase + ALS4K_IOB_12_ADLIB_ADDR2);
- } else {
- if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
- goto out_err;
- }
- }
- snd_als4000_create_gameport(acard, dev);
- if ((err = snd_card_register(card)) < 0) {
- goto out_err;
- }
- pci_set_drvdata(pci, card);
- dev++;
- err = 0;
- goto out;
- out_err:
- snd_card_free(card);
-
- out:
- return err;
- }
- static void snd_card_als4000_remove(struct pci_dev *pci)
- {
- snd_card_free(pci_get_drvdata(pci));
- }
- #ifdef CONFIG_PM_SLEEP
- static int snd_als4000_suspend(struct device *dev)
- {
- struct snd_card *card = dev_get_drvdata(dev);
- struct snd_card_als4000 *acard = card->private_data;
- struct snd_sb *chip = acard->chip;
- snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-
- snd_pcm_suspend_all(chip->pcm);
- snd_sbmixer_suspend(chip);
- return 0;
- }
- static int snd_als4000_resume(struct device *dev)
- {
- struct snd_card *card = dev_get_drvdata(dev);
- struct snd_card_als4000 *acard = card->private_data;
- struct snd_sb *chip = acard->chip;
- snd_als4000_configure(chip);
- snd_sbdsp_reset(chip);
- snd_sbmixer_resume(chip);
- #ifdef SUPPORT_JOYSTICK
- if (acard->gameport)
- snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1);
- #endif
- snd_power_change_state(card, SNDRV_CTL_POWER_D0);
- return 0;
- }
- static SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume);
- #define SND_ALS4000_PM_OPS &snd_als4000_pm
- #else
- #define SND_ALS4000_PM_OPS NULL
- #endif
- static struct pci_driver als4000_driver = {
- .name = KBUILD_MODNAME,
- .id_table = snd_als4000_ids,
- .probe = snd_card_als4000_probe,
- .remove = snd_card_als4000_remove,
- .driver = {
- .pm = SND_ALS4000_PM_OPS,
- },
- };
- module_pci_driver(als4000_driver);
|