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