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