Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * card-als4000.c - driver for Avance Logic ALS4000 based soundcards. |
| 3 | * Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>, |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com> |
| 6 | * |
| 7 | * Framework borrowed from Massimo Piccioni's card-als100.c. |
| 8 | * |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * NOTES |
| 25 | * |
| 26 | * Since Avance does not provide any meaningful documentation, and I |
| 27 | * bought an ALS4000 based soundcard, I was forced to base this driver |
| 28 | * on reverse engineering. |
| 29 | * |
| 30 | * Note: this is no longer true. Pretty verbose chip docu (ALS4000a.PDF) |
| 31 | * can be found on the ALSA web site. |
| 32 | * |
| 33 | * The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an |
| 34 | * ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport |
| 35 | * interface. These subsystems can be mapped into ISA io-port space, |
| 36 | * using the PCI-interface. In addition, the PCI-bit provides DMA and IRQ |
| 37 | * services to the subsystems. |
| 38 | * |
| 39 | * While ALS4000 is very similar to a SoundBlaster, the differences in |
| 40 | * DMA and capturing require more changes to the SoundBlaster than |
| 41 | * desirable, so I made this separate driver. |
| 42 | * |
| 43 | * The ALS4000 can do real full duplex playback/capture. |
| 44 | * |
| 45 | * FMDAC: |
| 46 | * - 0x4f -> port 0x14 |
| 47 | * - port 0x15 |= 1 |
| 48 | * |
| 49 | * Enable/disable 3D sound: |
| 50 | * - 0x50 -> port 0x14 |
| 51 | * - change bit 6 (0x40) of port 0x15 |
| 52 | * |
| 53 | * Set QSound: |
| 54 | * - 0xdb -> port 0x14 |
| 55 | * - set port 0x15: |
| 56 | * 0x3e (mode 3), 0x3c (mode 2), 0x3a (mode 1), 0x38 (mode 0) |
| 57 | * |
| 58 | * Set KSound: |
| 59 | * - value -> some port 0x0c0d |
| 60 | * |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 61 | * ToDo: |
| 62 | * - Proper shared IRQ handling? |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 63 | * - by default, don't enable legacy game and use PCI game I/O |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 64 | * - power management? (card can do voice wakeup according to datasheet!!) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <asm/io.h> |
| 68 | #include <linux/init.h> |
| 69 | #include <linux/pci.h> |
| 70 | #include <linux/slab.h> |
| 71 | #include <linux/gameport.h> |
| 72 | #include <linux/moduleparam.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 73 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #include <sound/core.h> |
| 75 | #include <sound/pcm.h> |
| 76 | #include <sound/rawmidi.h> |
| 77 | #include <sound/mpu401.h> |
| 78 | #include <sound/opl3.h> |
| 79 | #include <sound/sb.h> |
| 80 | #include <sound/initval.h> |
| 81 | |
| 82 | MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>"); |
| 83 | MODULE_DESCRIPTION("Avance Logic ALS4000"); |
| 84 | MODULE_LICENSE("GPL"); |
| 85 | MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}"); |
| 86 | |
| 87 | #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) |
| 88 | #define SUPPORT_JOYSTICK 1 |
| 89 | #endif |
| 90 | |
| 91 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 92 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 93 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 94 | #ifdef SUPPORT_JOYSTICK |
| 95 | static int joystick_port[SNDRV_CARDS]; |
| 96 | #endif |
| 97 | |
| 98 | module_param_array(index, int, NULL, 0444); |
| 99 | MODULE_PARM_DESC(index, "Index value for ALS4000 soundcard."); |
| 100 | module_param_array(id, charp, NULL, 0444); |
| 101 | MODULE_PARM_DESC(id, "ID string for ALS4000 soundcard."); |
| 102 | module_param_array(enable, bool, NULL, 0444); |
| 103 | MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard."); |
| 104 | #ifdef SUPPORT_JOYSTICK |
| 105 | module_param_array(joystick_port, int, NULL, 0444); |
| 106 | MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)"); |
| 107 | #endif |
| 108 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 109 | struct snd_card_als4000 { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 110 | /* most frequent access first */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 111 | unsigned long iobase; |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 112 | struct pci_dev *pci; |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 113 | struct snd_sb *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #ifdef SUPPORT_JOYSTICK |
| 115 | struct gameport *gameport; |
| 116 | #endif |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 117 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Takashi Iwai | f40b689 | 2006-07-05 16:51:05 +0200 | [diff] [blame] | 119 | static struct pci_device_id snd_als4000_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ALS4000 */ |
| 121 | { 0, } |
| 122 | }; |
| 123 | |
| 124 | MODULE_DEVICE_TABLE(pci, snd_als4000_ids); |
| 125 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 126 | enum als4k_iobase_t { |
| 127 | /* IOx: B == Byte, W = Word, D = DWord */ |
| 128 | ALS4K_IOD_00_AC97_ACCESS = 0x00, |
| 129 | ALS4K_IOW_04_AC97_READ = 0x04, |
| 130 | ALS4K_IOB_06_AC97_STATUS = 0x06, |
| 131 | ALS4K_IOB_07_IRQSTATUS = 0x07, |
| 132 | ALS4K_IOD_08_GCR_DATA = 0x08, |
| 133 | ALS4K_IOB_0C_GCR_INDEX = 0x0c, |
| 134 | ALS4K_IOB_0E_SB_MPU_IRQ = 0x0e, |
| 135 | ALS4K_IOB_10_ADLIB_ADDR0 = 0x10, |
| 136 | ALS4K_IOB_11_ADLIB_ADDR1 = 0x11, |
| 137 | ALS4K_IOB_12_ADLIB_ADDR2 = 0x12, |
| 138 | ALS4K_IOB_13_ADLIB_ADDR3 = 0x13, |
| 139 | ALS4K_IOB_14_MIXER_INDEX = 0x14, |
| 140 | ALS4K_IOB_15_MIXER_DATA = 0x15, |
| 141 | ALS4K_IOB_16_ESP_RST_PORT = 0x16, |
| 142 | ALS4K_IOB_16_CR1E_ACK_PORT = 0x16, /* 2nd function */ |
| 143 | ALS4K_IOB_18_OPL_ADDR0 = 0x18, |
| 144 | ALS4K_IOB_19_OPL_ADDR1 = 0x19, |
| 145 | ALS4K_IOB_1A_ESP_RD_DATA = 0x1a, |
| 146 | ALS4K_IOB_1C_ESP_CMD_DATA = 0x1c, |
| 147 | ALS4K_IOB_1C_ESP_WR_STATUS = 0x1c, /* 2nd function */ |
| 148 | ALS4K_IOB_1E_ESP_RD_STATUS8 = 0x1e, |
| 149 | ALS4K_IOB_1F_ESP_RD_STATUS16 = 0x1f, |
| 150 | ALS4K_IOB_20_ESP_GAMEPORT_200 = 0x20, |
| 151 | ALS4K_IOB_21_ESP_GAMEPORT_201 = 0x21, |
| 152 | ALS4K_IOB_30_MIDI_DATA = 0x30, |
| 153 | ALS4K_IOB_31_MIDI_STATUS = 0x31, |
| 154 | ALS4K_IOB_31_MIDI_COMMAND = 0x31, /* 2nd function */ |
| 155 | }; |
| 156 | |
| 157 | enum als4k_gcr_t { |
| 158 | /* all registers 32bit wide */ |
| 159 | ALS4K_GCR_8C_MISC_CTRL = 0x8c, |
| 160 | ALS4K_GCR_90_TEST_MODE_REG = 0x90, |
| 161 | ALS4K_GCR_91_DMA0_ADDR = 0x91, |
| 162 | ALS4K_GCR_92_DMA0_MODE_COUNT = 0x92, |
| 163 | ALS4K_GCR_93_DMA1_ADDR = 0x93, |
| 164 | ALS4K_GCR_94_DMA1_MODE_COUNT = 0x94, |
| 165 | ALS4K_GCR_95_DMA3_ADDR = 0x95, |
| 166 | ALS4K_GCR_96_DMA3_MODE_COUNT = 0x96, |
| 167 | ALS4K_GCR_99_DMA_EMULATION_CTRL = 0x99, |
| 168 | ALS4K_GCR_A0_FIFO1_CURRENT_ADDR = 0xa0, |
| 169 | ALS4K_GCR_A1_FIFO1_STATUS_BYTECOUNT = 0xa1, |
| 170 | ALS4K_GCR_A2_FIFO2_PCIADDR = 0xa2, |
| 171 | ALS4K_GCR_A3_FIFO2_COUNT = 0xa3, |
| 172 | ALS4K_GCR_A4_FIFO2_CURRENT_ADDR = 0xa4, |
| 173 | ALS4K_GCR_A5_FIFO1_STATUS_BYTECOUNT = 0xa5, |
| 174 | ALS4K_GCR_A6_PM_CTRL = 0xa6, |
| 175 | ALS4K_GCR_A7_PCI_ACCESS_STORAGE = 0xa7, |
| 176 | ALS4K_GCR_A8_LEGACY_CFG1 = 0xa8, |
| 177 | ALS4K_GCR_A9_LEGACY_CFG2 = 0xa9, |
| 178 | ALS4K_GCR_FF_DUMMY_SCRATCH = 0xff, |
| 179 | }; |
| 180 | |
| 181 | enum als4k_gcr_8c_t { |
| 182 | ALS4K_GCR_8C_IRQ_MASK_CTRL_ENABLE = 0x8000, |
| 183 | ALS4K_GCR_8C_CHIP_REV_MASK = 0xf0000 |
| 184 | }; |
| 185 | |
| 186 | static inline void snd_als4000_gcr_write_addr(unsigned long iobase, |
| 187 | enum als4k_gcr_t reg, |
| 188 | u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 190 | outb(reg, iobase + ALS4K_IOB_0C_GCR_INDEX); |
| 191 | outl(val, iobase + ALS4K_IOD_08_GCR_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 194 | static inline void snd_als4000_gcr_write(struct snd_sb *sb, |
| 195 | enum als4k_gcr_t reg, |
| 196 | u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | snd_als4000_gcr_write_addr(sb->alt_port, reg, val); |
| 199 | } |
| 200 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 201 | static inline u32 snd_als4000_gcr_read_addr(unsigned long iobase, |
| 202 | enum als4k_gcr_t reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 204 | outb(reg, iobase + ALS4K_IOB_0C_GCR_INDEX); |
| 205 | return inl(iobase + ALS4K_IOD_08_GCR_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 208 | static inline u32 snd_als4000_gcr_read(struct snd_sb *sb, enum als4k_gcr_t reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | return snd_als4000_gcr_read_addr(sb->alt_port, reg); |
| 211 | } |
| 212 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 213 | static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | if (!(chip->mode & SB_RATE_LOCK)) { |
| 216 | snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT); |
| 217 | snd_sbdsp_command(chip, rate>>8); |
| 218 | snd_sbdsp_command(chip, rate); |
| 219 | } |
| 220 | } |
| 221 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 222 | static inline void snd_als4000_set_capture_dma(struct snd_sb *chip, |
| 223 | dma_addr_t addr, unsigned size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 225 | snd_als4000_gcr_write(chip, ALS4K_GCR_A2_FIFO2_PCIADDR, addr); |
| 226 | snd_als4000_gcr_write(chip, ALS4K_GCR_A3_FIFO2_COUNT, (size-1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 229 | static inline void snd_als4000_set_playback_dma(struct snd_sb *chip, |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 230 | dma_addr_t addr, |
| 231 | unsigned size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 233 | snd_als4000_gcr_write(chip, ALS4K_GCR_91_DMA0_ADDR, addr); |
| 234 | snd_als4000_gcr_write(chip, ALS4K_GCR_92_DMA0_MODE_COUNT, |
| 235 | (size-1)|0x180000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | #define ALS4000_FORMAT_SIGNED (1<<0) |
| 239 | #define ALS4000_FORMAT_16BIT (1<<1) |
| 240 | #define ALS4000_FORMAT_STEREO (1<<2) |
| 241 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 242 | static int snd_als4000_get_format(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | int result; |
| 245 | |
| 246 | result = 0; |
| 247 | if (snd_pcm_format_signed(runtime->format)) |
| 248 | result |= ALS4000_FORMAT_SIGNED; |
| 249 | if (snd_pcm_format_physical_width(runtime->format) == 16) |
| 250 | result |= ALS4000_FORMAT_16BIT; |
| 251 | if (runtime->channels > 1) |
| 252 | result |= ALS4000_FORMAT_STEREO; |
| 253 | return result; |
| 254 | } |
| 255 | |
| 256 | /* structure for setting up playback */ |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 257 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | unsigned char dsp_cmd, dma_on, dma_off, format; |
| 259 | } playback_cmd_vals[]={ |
| 260 | /* ALS4000_FORMAT_U8_MONO */ |
| 261 | { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_MONO }, |
| 262 | /* ALS4000_FORMAT_S8_MONO */ |
| 263 | { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_MONO }, |
| 264 | /* ALS4000_FORMAT_U16L_MONO */ |
| 265 | { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_MONO }, |
| 266 | /* ALS4000_FORMAT_S16L_MONO */ |
| 267 | { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_MONO }, |
| 268 | /* ALS4000_FORMAT_U8_STEREO */ |
| 269 | { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_STEREO }, |
| 270 | /* ALS4000_FORMAT_S8_STEREO */ |
| 271 | { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_STEREO }, |
| 272 | /* ALS4000_FORMAT_U16L_STEREO */ |
| 273 | { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_STEREO }, |
| 274 | /* ALS4000_FORMAT_S16L_STEREO */ |
| 275 | { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_STEREO }, |
| 276 | }; |
| 277 | #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format]) |
| 278 | |
| 279 | /* structure for setting up capture */ |
| 280 | enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 }; |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 281 | static const unsigned char capture_cmd_vals[]= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
| 283 | CMD_WIDTH8|CMD_MONO, /* ALS4000_FORMAT_U8_MONO */ |
| 284 | CMD_WIDTH8|CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S8_MONO */ |
| 285 | CMD_MONO, /* ALS4000_FORMAT_U16L_MONO */ |
| 286 | CMD_SIGNED|CMD_MONO, /* ALS4000_FORMAT_S16L_MONO */ |
| 287 | CMD_WIDTH8|CMD_STEREO, /* ALS4000_FORMAT_U8_STEREO */ |
| 288 | CMD_WIDTH8|CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S8_STEREO */ |
| 289 | CMD_STEREO, /* ALS4000_FORMAT_U16L_STEREO */ |
| 290 | CMD_SIGNED|CMD_STEREO, /* ALS4000_FORMAT_S16L_STEREO */ |
| 291 | }; |
| 292 | #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format]) |
| 293 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 294 | static int snd_als4000_hw_params(struct snd_pcm_substream *substream, |
| 295 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 298 | } |
| 299 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 300 | static int snd_als4000_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
| 302 | snd_pcm_lib_free_pages(substream); |
| 303 | return 0; |
| 304 | } |
| 305 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 306 | static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 308 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
| 309 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | unsigned long size; |
| 311 | unsigned count; |
| 312 | |
| 313 | chip->capture_format = snd_als4000_get_format(runtime); |
| 314 | |
| 315 | size = snd_pcm_lib_buffer_bytes(substream); |
| 316 | count = snd_pcm_lib_period_bytes(substream); |
| 317 | |
| 318 | if (chip->capture_format & ALS4000_FORMAT_16BIT) |
| 319 | count >>=1; |
| 320 | count--; |
| 321 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 322 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | snd_als4000_set_rate(chip, runtime->rate); |
| 324 | snd_als4000_set_capture_dma(chip, runtime->dma_addr, size); |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 325 | spin_unlock_irq(&chip->reg_lock); |
| 326 | spin_lock_irq(&chip->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | snd_sbmixer_write(chip, 0xdc, count); |
| 328 | snd_sbmixer_write(chip, 0xdd, count>>8); |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 329 | spin_unlock_irq(&chip->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 333 | static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 335 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
| 336 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | unsigned long size; |
| 338 | unsigned count; |
| 339 | |
| 340 | chip->playback_format = snd_als4000_get_format(runtime); |
| 341 | |
| 342 | size = snd_pcm_lib_buffer_bytes(substream); |
| 343 | count = snd_pcm_lib_period_bytes(substream); |
| 344 | |
| 345 | if (chip->playback_format & ALS4000_FORMAT_16BIT) |
| 346 | count >>=1; |
| 347 | count--; |
| 348 | |
| 349 | /* FIXME: from second playback on, there's a lot more clicks and pops |
| 350 | * involved here than on first playback. Fiddling with |
| 351 | * tons of different settings didn't help (DMA, speaker on/off, |
| 352 | * reordering, ...). Something seems to get enabled on playback |
| 353 | * that I haven't found out how to disable again, which then causes |
| 354 | * the switching pops to reach the speakers the next time here. */ |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 355 | spin_lock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | snd_als4000_set_rate(chip, runtime->rate); |
| 357 | snd_als4000_set_playback_dma(chip, runtime->dma_addr, size); |
| 358 | |
| 359 | /* SPEAKER_ON not needed, since dma_on seems to also enable speaker */ |
| 360 | /* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */ |
| 361 | snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd); |
| 362 | snd_sbdsp_command(chip, playback_cmd(chip).format); |
| 363 | snd_sbdsp_command(chip, count); |
| 364 | snd_sbdsp_command(chip, count>>8); |
| 365 | snd_sbdsp_command(chip, playback_cmd(chip).dma_off); |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 366 | spin_unlock_irq(&chip->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 371 | static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 373 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | int result = 0; |
| 375 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 376 | /* FIXME race condition in here!!! |
| 377 | chip->mode non-atomic update gets consistently protected |
| 378 | by reg_lock always, _except_ for this place!! |
| 379 | Probably need to take reg_lock as outer (or inner??) lock, too. |
| 380 | (or serialize both lock operations? probably not, though... - racy?) |
| 381 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spin_lock(&chip->mixer_lock); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 383 | switch (cmd) { |
| 384 | case SNDRV_PCM_TRIGGER_START: |
| 385 | case SNDRV_PCM_TRIGGER_RESUME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | chip->mode |= SB_RATE_LOCK_CAPTURE; |
| 387 | snd_sbmixer_write(chip, 0xde, capture_cmd(chip)); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 388 | break; |
| 389 | case SNDRV_PCM_TRIGGER_STOP: |
| 390 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | chip->mode &= ~SB_RATE_LOCK_CAPTURE; |
| 392 | snd_sbmixer_write(chip, 0xde, 0); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 393 | break; |
| 394 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | result = -EINVAL; |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 396 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | spin_unlock(&chip->mixer_lock); |
| 399 | return result; |
| 400 | } |
| 401 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 402 | static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 404 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | int result = 0; |
| 406 | |
| 407 | spin_lock(&chip->reg_lock); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 408 | switch (cmd) { |
| 409 | case SNDRV_PCM_TRIGGER_START: |
| 410 | case SNDRV_PCM_TRIGGER_RESUME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | chip->mode |= SB_RATE_LOCK_PLAYBACK; |
| 412 | snd_sbdsp_command(chip, playback_cmd(chip).dma_on); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 413 | break; |
| 414 | case SNDRV_PCM_TRIGGER_STOP: |
| 415 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | snd_sbdsp_command(chip, playback_cmd(chip).dma_off); |
| 417 | chip->mode &= ~SB_RATE_LOCK_PLAYBACK; |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 418 | break; |
| 419 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | result = -EINVAL; |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 421 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | spin_unlock(&chip->reg_lock); |
| 424 | return result; |
| 425 | } |
| 426 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 427 | static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 429 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | unsigned int result; |
| 431 | |
| 432 | spin_lock(&chip->reg_lock); |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 433 | result = snd_als4000_gcr_read(chip, ALS4K_GCR_A4_FIFO2_CURRENT_ADDR); |
| 434 | result &= 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | spin_unlock(&chip->reg_lock); |
| 436 | return bytes_to_frames( substream->runtime, result ); |
| 437 | } |
| 438 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 439 | static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 441 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | unsigned result; |
| 443 | |
| 444 | spin_lock(&chip->reg_lock); |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 445 | result = snd_als4000_gcr_read(chip, ALS4K_GCR_A0_FIFO1_CURRENT_ADDR); |
| 446 | result &= 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | spin_unlock(&chip->reg_lock); |
| 448 | return bytes_to_frames( substream->runtime, result ); |
| 449 | } |
| 450 | |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 451 | /* FIXME: this IRQ routine doesn't really support IRQ sharing (we always |
| 452 | * return IRQ_HANDLED no matter whether we actually had an IRQ flag or not). |
| 453 | * ALS4000a.PDF writes that while ACKing IRQ in PCI block will *not* ACK |
| 454 | * the IRQ in the SB core, ACKing IRQ in SB block *will* ACK the PCI IRQ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 455 | * register (alt_port + ALS4K_IOB_0E_SB_MPU_IRQ). Probably something |
| 456 | * could be optimized here to query/write one register only... |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 457 | * And even if both registers need to be queried, then there's still the |
| 458 | * question of whether it's actually correct to ACK PCI IRQ before reading |
| 459 | * SB IRQ like we do now, since ALS4000a.PDF mentions that PCI IRQ will *clear* |
| 460 | * SB IRQ status. |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 461 | * (hmm, page 38 mentions it the other way around!) |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 462 | * And do we *really* need the lock here for *reading* SB_DSP4_IRQSTATUS?? |
| 463 | * */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 464 | static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 466 | struct snd_sb *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | unsigned gcr_status; |
| 468 | unsigned sb_status; |
| 469 | |
| 470 | /* find out which bit of the ALS4000 produced the interrupt */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 471 | gcr_status = inb(chip->alt_port + ALS4K_IOB_0E_SB_MPU_IRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | if ((gcr_status & 0x80) && (chip->playback_substream)) /* playback */ |
| 474 | snd_pcm_period_elapsed(chip->playback_substream); |
| 475 | if ((gcr_status & 0x40) && (chip->capture_substream)) /* capturing */ |
| 476 | snd_pcm_period_elapsed(chip->capture_substream); |
| 477 | if ((gcr_status & 0x10) && (chip->rmidi)) /* MPU401 interrupt */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 478 | snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* release the gcr */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 480 | outb(gcr_status, chip->alt_port + ALS4K_IOB_0E_SB_MPU_IRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | spin_lock(&chip->mixer_lock); |
| 483 | sb_status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS); |
| 484 | spin_unlock(&chip->mixer_lock); |
| 485 | |
| 486 | if (sb_status & SB_IRQTYPE_8BIT) |
| 487 | snd_sb_ack_8bit(chip); |
| 488 | if (sb_status & SB_IRQTYPE_16BIT) |
| 489 | snd_sb_ack_16bit(chip); |
| 490 | if (sb_status & SB_IRQTYPE_MPUIN) |
| 491 | inb(chip->mpu_port); |
| 492 | if (sb_status & 0x20) |
| 493 | inb(SBP(chip, RESET)); |
| 494 | return IRQ_HANDLED; |
| 495 | } |
| 496 | |
| 497 | /*****************************************************************/ |
| 498 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 499 | static struct snd_pcm_hardware snd_als4000_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 502 | SNDRV_PCM_INFO_MMAP_VALID), |
| 503 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | |
| 504 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */ |
| 505 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 506 | .rate_min = 4000, |
| 507 | .rate_max = 48000, |
| 508 | .channels_min = 1, |
| 509 | .channels_max = 2, |
| 510 | .buffer_bytes_max = 65536, |
| 511 | .period_bytes_min = 64, |
| 512 | .period_bytes_max = 65536, |
| 513 | .periods_min = 1, |
| 514 | .periods_max = 1024, |
| 515 | .fifo_size = 0 |
| 516 | }; |
| 517 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 518 | static struct snd_pcm_hardware snd_als4000_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 521 | SNDRV_PCM_INFO_MMAP_VALID), |
| 522 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | |
| 523 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, /* formats */ |
| 524 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 525 | .rate_min = 4000, |
| 526 | .rate_max = 48000, |
| 527 | .channels_min = 1, |
| 528 | .channels_max = 2, |
| 529 | .buffer_bytes_max = 65536, |
| 530 | .period_bytes_min = 64, |
| 531 | .period_bytes_max = 65536, |
| 532 | .periods_min = 1, |
| 533 | .periods_max = 1024, |
| 534 | .fifo_size = 0 |
| 535 | }; |
| 536 | |
| 537 | /*****************************************************************/ |
| 538 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 539 | static int snd_als4000_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 541 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
| 542 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | chip->playback_substream = substream; |
| 545 | runtime->hw = snd_als4000_playback; |
| 546 | return 0; |
| 547 | } |
| 548 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 549 | static int snd_als4000_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 551 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| 553 | chip->playback_substream = NULL; |
| 554 | snd_pcm_lib_free_pages(substream); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 558 | static int snd_als4000_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 560 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
| 561 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | chip->capture_substream = substream; |
| 564 | runtime->hw = snd_als4000_capture; |
| 565 | return 0; |
| 566 | } |
| 567 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 568 | static int snd_als4000_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 570 | struct snd_sb *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | chip->capture_substream = NULL; |
| 573 | snd_pcm_lib_free_pages(substream); |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /******************************************************************/ |
| 578 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 579 | static struct snd_pcm_ops snd_als4000_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | .open = snd_als4000_playback_open, |
| 581 | .close = snd_als4000_playback_close, |
| 582 | .ioctl = snd_pcm_lib_ioctl, |
| 583 | .hw_params = snd_als4000_hw_params, |
| 584 | .hw_free = snd_als4000_hw_free, |
| 585 | .prepare = snd_als4000_playback_prepare, |
| 586 | .trigger = snd_als4000_playback_trigger, |
| 587 | .pointer = snd_als4000_playback_pointer |
| 588 | }; |
| 589 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 590 | static struct snd_pcm_ops snd_als4000_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | .open = snd_als4000_capture_open, |
| 592 | .close = snd_als4000_capture_close, |
| 593 | .ioctl = snd_pcm_lib_ioctl, |
| 594 | .hw_params = snd_als4000_hw_params, |
| 595 | .hw_free = snd_als4000_hw_free, |
| 596 | .prepare = snd_als4000_capture_prepare, |
| 597 | .trigger = snd_als4000_capture_trigger, |
| 598 | .pointer = snd_als4000_capture_pointer |
| 599 | }; |
| 600 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 601 | static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 603 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | int err; |
| 605 | |
| 606 | if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0) |
| 607 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | pcm->private_data = chip; |
| 609 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 610 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops); |
| 611 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops); |
| 612 | |
| 613 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), |
| 614 | 64*1024, 64*1024); |
| 615 | |
| 616 | chip->pcm = pcm; |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /******************************************************************/ |
| 622 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 623 | static void snd_als4000_set_addr(unsigned long iobase, |
| 624 | unsigned int sb_io, |
| 625 | unsigned int mpu_io, |
| 626 | unsigned int opl_io, |
| 627 | unsigned int game_io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 629 | u32 cfg1 = 0; |
| 630 | u32 cfg2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 632 | if (mpu_io > 0) |
| 633 | cfg2 |= (mpu_io | 1) << 16; |
| 634 | if (sb_io > 0) |
| 635 | cfg2 |= (sb_io | 1); |
| 636 | if (game_io > 0) |
| 637 | cfg1 |= (game_io | 1) << 16; |
| 638 | if (opl_io > 0) |
| 639 | cfg1 |= (opl_io | 1); |
| 640 | snd_als4000_gcr_write_addr(iobase, ALS4K_GCR_A8_LEGACY_CFG1, cfg1); |
| 641 | snd_als4000_gcr_write_addr(iobase, ALS4K_GCR_A9_LEGACY_CFG2, cfg2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 644 | static void snd_als4000_configure(struct snd_sb *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
| 646 | unsigned tmp; |
| 647 | int i; |
| 648 | |
| 649 | /* do some more configuration */ |
| 650 | spin_lock_irq(&chip->mixer_lock); |
| 651 | tmp = snd_sbmixer_read(chip, 0xc0); |
| 652 | snd_sbmixer_write(chip, 0xc0, tmp|0x80); |
| 653 | /* always select DMA channel 0, since we do not actually use DMA */ |
| 654 | snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0); |
| 655 | snd_sbmixer_write(chip, 0xc0, tmp&0x7f); |
| 656 | spin_unlock_irq(&chip->mixer_lock); |
| 657 | |
| 658 | spin_lock_irq(&chip->reg_lock); |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 659 | /* enable interrupts */ |
| 660 | snd_als4000_gcr_write(chip, ALS4K_GCR_8C_MISC_CTRL, |
| 661 | ALS4K_GCR_8C_IRQ_MASK_CTRL_ENABLE); |
| 662 | |
| 663 | for (i = ALS4K_GCR_91_DMA0_ADDR; i <= ALS4K_GCR_96_DMA3_MODE_COUNT; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | snd_als4000_gcr_write(chip, i, 0); |
| 665 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 666 | snd_als4000_gcr_write(chip, ALS4K_GCR_99_DMA_EMULATION_CTRL, |
| 667 | snd_als4000_gcr_read(chip, ALS4K_GCR_99_DMA_EMULATION_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | spin_unlock_irq(&chip->reg_lock); |
| 669 | } |
| 670 | |
| 671 | #ifdef SUPPORT_JOYSTICK |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 672 | static int __devinit snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | struct gameport *gp; |
| 675 | struct resource *r; |
| 676 | int io_port; |
| 677 | |
| 678 | if (joystick_port[dev] == 0) |
| 679 | return -ENODEV; |
| 680 | |
| 681 | if (joystick_port[dev] == 1) { /* auto-detect */ |
| 682 | for (io_port = 0x200; io_port <= 0x218; io_port += 8) { |
| 683 | r = request_region(io_port, 8, "ALS4000 gameport"); |
| 684 | if (r) |
| 685 | break; |
| 686 | } |
| 687 | } else { |
| 688 | io_port = joystick_port[dev]; |
| 689 | r = request_region(io_port, 8, "ALS4000 gameport"); |
| 690 | } |
| 691 | |
| 692 | if (!r) { |
| 693 | printk(KERN_WARNING "als4000: cannot reserve joystick ports\n"); |
| 694 | return -EBUSY; |
| 695 | } |
| 696 | |
| 697 | acard->gameport = gp = gameport_allocate_port(); |
| 698 | if (!gp) { |
| 699 | printk(KERN_ERR "als4000: cannot allocate memory for gameport\n"); |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 700 | release_and_free_resource(r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | return -ENOMEM; |
| 702 | } |
| 703 | |
| 704 | gameport_set_name(gp, "ALS4000 Gameport"); |
| 705 | gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci)); |
| 706 | gameport_set_dev_parent(gp, &acard->pci->dev); |
| 707 | gp->io = io_port; |
| 708 | gameport_set_port_data(gp, r); |
| 709 | |
| 710 | /* Enable legacy joystick port */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 711 | snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | gameport_register_port(acard->gameport); |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 718 | static void snd_als4000_free_gameport(struct snd_card_als4000 *acard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
| 720 | if (acard->gameport) { |
| 721 | struct resource *r = gameport_get_port_data(acard->gameport); |
| 722 | |
| 723 | gameport_unregister_port(acard->gameport); |
| 724 | acard->gameport = NULL; |
| 725 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 726 | /* disable joystick */ |
| 727 | snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0); |
| 728 | |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 729 | release_and_free_resource(r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | #else |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 733 | static inline int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) { return -ENOSYS; } |
| 734 | static inline void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | #endif |
| 736 | |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 737 | static void snd_card_als4000_free( struct snd_card *card ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 739 | struct snd_card_als4000 *acard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | /* make sure that interrupts are disabled */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 742 | snd_als4000_gcr_write_addr(acard->iobase, ALS4K_GCR_8C_MISC_CTRL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /* free resources */ |
| 744 | snd_als4000_free_gameport(acard); |
| 745 | pci_release_regions(acard->pci); |
| 746 | pci_disable_device(acard->pci); |
| 747 | } |
| 748 | |
| 749 | static int __devinit snd_card_als4000_probe(struct pci_dev *pci, |
| 750 | const struct pci_device_id *pci_id) |
| 751 | { |
| 752 | static int dev; |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 753 | struct snd_card *card; |
| 754 | struct snd_card_als4000 *acard; |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 755 | unsigned long iobase; |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 756 | struct snd_sb *chip; |
| 757 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | unsigned short word; |
| 759 | int err; |
| 760 | |
| 761 | if (dev >= SNDRV_CARDS) |
| 762 | return -ENODEV; |
| 763 | if (!enable[dev]) { |
| 764 | dev++; |
| 765 | return -ENOENT; |
| 766 | } |
| 767 | |
| 768 | /* enable PCI device */ |
| 769 | if ((err = pci_enable_device(pci)) < 0) { |
| 770 | return err; |
| 771 | } |
| 772 | /* check, if we can restrict PCI DMA transfers to 24 bits */ |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 773 | if (pci_set_dma_mask(pci, DMA_24BIT_MASK) < 0 || |
| 774 | pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 775 | snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | pci_disable_device(pci); |
| 777 | return -ENXIO; |
| 778 | } |
| 779 | |
| 780 | if ((err = pci_request_regions(pci, "ALS4000")) < 0) { |
| 781 | pci_disable_device(pci); |
| 782 | return err; |
| 783 | } |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 784 | iobase = pci_resource_start(pci, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | pci_read_config_word(pci, PCI_COMMAND, &word); |
| 787 | pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); |
| 788 | pci_set_master(pci); |
| 789 | |
| 790 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
Takashi Iwai | 17c39d9 | 2005-11-17 15:02:01 +0100 | [diff] [blame] | 791 | sizeof( struct snd_card_als4000 ) ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | if (card == NULL) { |
| 793 | pci_release_regions(pci); |
| 794 | pci_disable_device(pci); |
| 795 | return -ENOMEM; |
| 796 | } |
| 797 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 798 | acard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | acard->pci = pci; |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 800 | acard->iobase = iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | card->private_free = snd_card_als4000_free; |
| 802 | |
| 803 | /* disable all legacy ISA stuff */ |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 804 | snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
| 806 | if ((err = snd_sbdsp_create(card, |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 807 | iobase + ALS4K_IOB_10_ADLIB_ADDR0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | pci->irq, |
| 809 | snd_als4000_interrupt, |
| 810 | -1, |
| 811 | -1, |
| 812 | SB_HW_ALS4000, |
| 813 | &chip)) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 814 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 816 | acard->chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | chip->pci = pci; |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 819 | chip->alt_port = iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | snd_card_set_dev(card, &pci->dev); |
| 821 | |
| 822 | snd_als4000_configure(chip); |
| 823 | |
| 824 | strcpy(card->driver, "ALS4000"); |
| 825 | strcpy(card->shortname, "Avance Logic ALS4000"); |
| 826 | sprintf(card->longname, "%s at 0x%lx, irq %i", |
| 827 | card->shortname, chip->alt_port, chip->irq); |
| 828 | |
| 829 | if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 830 | iobase + ALS4K_IOB_30_MIDI_DATA, |
| 831 | MPU401_INFO_INTEGRATED, |
Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 832 | pci->irq, 0, &chip->rmidi)) < 0) { |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 833 | printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", |
| 834 | iobase + ALS4K_IOB_30_MIDI_DATA); |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 835 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 837 | /* FIXME: ALS4000 has interesting MPU401 configuration features |
| 838 | * at CR 0x1A (pass-thru / UART switching, fast MIDI clock, etc.), |
| 839 | * however there doesn't seem to be an ALSA API for this... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | if ((err = snd_als4000_pcm(chip, 0)) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 842 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | if ((err = snd_sbmixer_new(chip)) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 845 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 848 | if (snd_opl3_create(card, |
| 849 | iobase + ALS4K_IOB_10_ADLIB_ADDR0, |
| 850 | iobase + ALS4K_IOB_12_ADLIB_ADDR2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | OPL3_HW_AUTO, 1, &opl3) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 852 | printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n", |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 853 | iobase + ALS4K_IOB_10_ADLIB_ADDR0, |
| 854 | iobase + ALS4K_IOB_12_ADLIB_ADDR2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } else { |
| 856 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 857 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | |
| 861 | snd_als4000_create_gameport(acard, dev); |
| 862 | |
| 863 | if ((err = snd_card_register(card)) < 0) { |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 864 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
| 866 | pci_set_drvdata(pci, card); |
| 867 | dev++; |
Andreas Mohr | ba7301c | 2005-11-17 11:03:31 +0100 | [diff] [blame] | 868 | err = 0; |
| 869 | goto out; |
| 870 | |
| 871 | out_err: |
| 872 | snd_card_free(card); |
| 873 | |
| 874 | out: |
| 875 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static void __devexit snd_card_als4000_remove(struct pci_dev *pci) |
| 879 | { |
| 880 | snd_card_free(pci_get_drvdata(pci)); |
| 881 | pci_set_drvdata(pci, NULL); |
| 882 | } |
| 883 | |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 884 | #ifdef CONFIG_PM |
| 885 | static int snd_als4000_suspend(struct pci_dev *pci, pm_message_t state) |
| 886 | { |
| 887 | struct snd_card *card = pci_get_drvdata(pci); |
| 888 | struct snd_card_als4000 *acard = card->private_data; |
| 889 | struct snd_sb *chip = acard->chip; |
| 890 | |
| 891 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 892 | |
| 893 | snd_pcm_suspend_all(chip->pcm); |
| 894 | snd_sbmixer_suspend(chip); |
| 895 | |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 896 | pci_disable_device(pci); |
| 897 | pci_save_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 898 | pci_set_power_state(pci, pci_choose_state(pci, state)); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static int snd_als4000_resume(struct pci_dev *pci) |
| 903 | { |
| 904 | struct snd_card *card = pci_get_drvdata(pci); |
| 905 | struct snd_card_als4000 *acard = card->private_data; |
| 906 | struct snd_sb *chip = acard->chip; |
| 907 | |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 908 | pci_set_power_state(pci, PCI_D0); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 909 | pci_restore_state(pci); |
| 910 | if (pci_enable_device(pci) < 0) { |
| 911 | printk(KERN_ERR "als4000: pci_enable_device failed, " |
| 912 | "disabling device\n"); |
| 913 | snd_card_disconnect(card); |
| 914 | return -EIO; |
| 915 | } |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 916 | pci_set_master(pci); |
| 917 | |
| 918 | snd_als4000_configure(chip); |
| 919 | snd_sbdsp_reset(chip); |
| 920 | snd_sbmixer_resume(chip); |
| 921 | |
| 922 | #ifdef SUPPORT_JOYSTICK |
| 923 | if (acard->gameport) |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 924 | snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1); |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 925 | #endif |
| 926 | |
| 927 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 928 | return 0; |
| 929 | } |
Andreas Mohr | c087444 | 2008-08-20 10:04:56 +0200 | [diff] [blame^] | 930 | #endif /* CONFIG_PM */ |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 931 | |
| 932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | static struct pci_driver driver = { |
| 934 | .name = "ALS4000", |
| 935 | .id_table = snd_als4000_ids, |
| 936 | .probe = snd_card_als4000_probe, |
| 937 | .remove = __devexit_p(snd_card_als4000_remove), |
Takashi Iwai | 7035291 | 2005-11-17 16:16:36 +0100 | [diff] [blame] | 938 | #ifdef CONFIG_PM |
| 939 | .suspend = snd_als4000_suspend, |
| 940 | .resume = snd_als4000_resume, |
| 941 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | }; |
| 943 | |
| 944 | static int __init alsa_card_als4000_init(void) |
| 945 | { |
Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 946 | return pci_register_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | static void __exit alsa_card_als4000_exit(void) |
| 950 | { |
| 951 | pci_unregister_driver(&driver); |
| 952 | } |
| 953 | |
| 954 | module_init(alsa_card_als4000_init) |
| 955 | module_exit(alsa_card_als4000_exit) |