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