Changeset 604 for GPL/trunk/alsa-kernel
- Timestamp:
- Jan 8, 2018, 2:07:36 AM (8 years ago)
- Location:
- GPL/trunk/alsa-kernel
- Files:
-
- 2 edited
-
core/pcm_lib.c (modified) (1 diff)
-
pci/hda/hda_intel.c (modified) (56 diffs)
Legend:
- Unmodified
- Added
- Removed
-
GPL/trunk/alsa-kernel/core/pcm_lib.c
r598 r604 433 433 434 434 /* Do jiffies check only in xrun_debug mode */ 435 #ifdef CONFIG_SND_PCM_XRUN_DEBUG435 //#ifdef CONFIG_SND_PCM_XRUN_DEBUG 436 436 if (!xrun_debug(substream, XRUN_DEBUG_JIFFIESCHECK)) 437 437 goto no_jiffies_check; 438 #endif438 //#endif 439 439 /* Skip the jiffies check for hardwares with BATCH flag. 440 440 * Such hardware usually just increases the position at each IRQ, -
GPL/trunk/alsa-kernel/pci/hda/hda_intel.c
r598 r604 25 25 * CONTACTS: 26 26 * 27 * Matt Jared matt.jared@intel.com28 * Andy Kopp andy.kopp@intel.com29 * Dan Kogan dan.d.kogan@intel.com27 * Matt Jared matt.jared@intel.com 28 * Andy Kopp andy.kopp@intel.com 29 * Dan Kogan dan.d.kogan@intel.com 30 30 * 31 31 * CHANGES: 32 32 * 33 * 2004.12.01 Major rewrite by tiwai, merged the work of pshou33 * 2004.12.01 Major rewrite by tiwai, merged the work of pshou 34 34 * 35 35 */ … … 72 72 #ifdef CONFIG_SND_HDA_INPUT_BEEP 73 73 static int beep_mode[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 74 CONFIG_SND_HDA_INPUT_BEEP_MODE};74 CONFIG_SND_HDA_INPUT_BEEP_MODE}; 75 75 #endif 76 76 … … 85 85 module_param_array(position_fix, int, NULL, 0444); 86 86 MODULE_PARM_DESC(position_fix, "DMA pointer read method." 87 "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO).");87 "(0 = auto, 1 = LPIB, 2 = POSBUF, 3 = VIACOMBO)."); 88 88 module_param_array(bdl_pos_adj, int, NULL, 0644); 89 89 MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset."); … … 94 94 module_param(single_cmd, bool, 0444); 95 95 MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs " 96 "(for debugging only).");96 "(for debugging only)."); 97 97 module_param(enable_msi, int, 0444); 98 98 MODULE_PARM_DESC(enable_msi, "Enable Message Signaled Interrupt (MSI)"); … … 104 104 module_param_array(beep_mode, int, NULL, 0444); 105 105 MODULE_PARM_DESC(beep_mode, "Select HDA Beep registration mode " 106 "(0=off, 1=on, 2=mute switch on/off) (default=1).");106 "(0=off, 1=on, 2=mute switch on/off) (default=1)."); 107 107 #endif 108 108 … … 111 111 module_param(power_save, int, 0644); 112 112 MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " 113 "(in second, 0 = disable).");113 "(in second, 0 = disable)."); 114 114 115 115 /* reset the HD-audio controller in power save mode. … … 124 124 MODULE_LICENSE("GPL"); 125 125 MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," 126 "{Intel, ICH6M},"127 "{Intel, ICH7},"128 "{Intel, ESB2},"129 "{Intel, ICH8},"130 "{Intel, ICH9},"131 "{Intel, ICH10},"132 "{Intel, PCH},"133 "{Intel, CPT},"134 "{Intel, PBG},"135 "{Intel, SCH},"136 "{ATI, SB450},"137 "{ATI, SB600},"138 "{ATI, RS600},"139 "{ATI, RS690},"140 "{ATI, RS780},"141 "{ATI, R600},"142 "{ATI, RV630},"143 "{ATI, RV610},"144 "{ATI, RV670},"145 "{ATI, RV635},"146 "{ATI, RV620},"147 "{ATI, RV770},"148 "{VIA, VT8251},"149 "{VIA, VT8237A},"150 "{SiS, SIS966},"151 "{ULI, M5461}}");126 "{Intel, ICH6M}," 127 "{Intel, ICH7}," 128 "{Intel, ESB2}," 129 "{Intel, ICH8}," 130 "{Intel, ICH9}," 131 "{Intel, ICH10}," 132 "{Intel, PCH}," 133 "{Intel, CPT}," 134 "{Intel, PBG}," 135 "{Intel, SCH}," 136 "{ATI, SB450}," 137 "{ATI, SB600}," 138 "{ATI, RS600}," 139 "{ATI, RS690}," 140 "{ATI, RS780}," 141 "{ATI, R600}," 142 "{ATI, RV630}," 143 "{ATI, RV610}," 144 "{ATI, RV670}," 145 "{ATI, RV635}," 146 "{ATI, RV620}," 147 "{ATI, RV770}," 148 "{VIA, VT8251}," 149 "{VIA, VT8237A}," 150 "{SiS, SIS966}," 151 "{ULI, M5461}}"); 152 152 MODULE_DESCRIPTION("Intel HDA driver"); 153 153 154 154 #ifdef CONFIG_SND_VERBOSE_PRINTK 155 #define SFX /* nop */155 #define SFX /* nop */ 156 156 #else 157 #define SFX "hda-intel: "157 #define SFX "hda-intel: " 158 158 #endif 159 159 … … 161 161 * registers 162 162 */ 163 #define ICH6_REG_GCAP 0x00164 #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */165 #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */166 #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */167 #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */168 #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */169 #define ICH6_REG_VMIN 0x02170 #define ICH6_REG_VMAJ 0x03171 #define ICH6_REG_OUTPAY 0x04172 #define ICH6_REG_INPAY 0x06173 #define ICH6_REG_GCTL 0x08174 #define ICH6_GCTL_RESET (1 << 0) /* controller reset */175 #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */176 #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */177 #define ICH6_REG_WAKEEN 0x0c178 #define ICH6_REG_STATESTS 0x0e179 #define ICH6_REG_GSTS 0x10180 #define ICH6_GSTS_FSTS (1 << 1) /* flush status */181 #define ICH6_REG_INTCTL 0x20182 #define ICH6_REG_INTSTS 0x24183 #define ICH6_REG_WALLCLK 0x30/* 24Mhz source */184 #define ICH6_REG_SYNC 0x34185 #define ICH6_REG_CORBLBASE 0x40186 #define ICH6_REG_CORBUBASE 0x44187 #define ICH6_REG_CORBWP 0x48188 #define ICH6_REG_CORBRP 0x4a189 #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */190 #define ICH6_REG_CORBCTL 0x4c191 #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */192 #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */193 #define ICH6_REG_CORBSTS 0x4d194 #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */195 #define ICH6_REG_CORBSIZE 0x4e196 197 #define ICH6_REG_RIRBLBASE 0x50198 #define ICH6_REG_RIRBUBASE 0x54199 #define ICH6_REG_RIRBWP 0x58200 #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */201 #define ICH6_REG_RINTCNT 0x5a202 #define ICH6_REG_RIRBCTL 0x5c203 #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */204 #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */205 #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */206 #define ICH6_REG_RIRBSTS 0x5d207 #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */208 #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */209 #define ICH6_REG_RIRBSIZE 0x5e210 211 #define ICH6_REG_IC 0x60212 #define ICH6_REG_IR 0x64213 #define ICH6_REG_IRS 0x68214 #define ICH6_IRS_VALID (1<<1)215 #define ICH6_IRS_BUSY (1<<0)216 217 #define ICH6_REG_DPLBASE 0x70218 #define ICH6_REG_DPUBASE 0x74219 #define ICH6_DPLBASE_ENABLE 0x1/* Enable position buffer */163 #define ICH6_REG_GCAP 0x00 164 #define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */ 165 #define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */ 166 #define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */ 167 #define ICH6_GCAP_ISS (15 << 8) /* # of input streams */ 168 #define ICH6_GCAP_OSS (15 << 12) /* # of output streams */ 169 #define ICH6_REG_VMIN 0x02 170 #define ICH6_REG_VMAJ 0x03 171 #define ICH6_REG_OUTPAY 0x04 172 #define ICH6_REG_INPAY 0x06 173 #define ICH6_REG_GCTL 0x08 174 #define ICH6_GCTL_RESET (1 << 0) /* controller reset */ 175 #define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */ 176 #define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */ 177 #define ICH6_REG_WAKEEN 0x0c 178 #define ICH6_REG_STATESTS 0x0e 179 #define ICH6_REG_GSTS 0x10 180 #define ICH6_GSTS_FSTS (1 << 1) /* flush status */ 181 #define ICH6_REG_INTCTL 0x20 182 #define ICH6_REG_INTSTS 0x24 183 #define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */ 184 #define ICH6_REG_SYNC 0x34 185 #define ICH6_REG_CORBLBASE 0x40 186 #define ICH6_REG_CORBUBASE 0x44 187 #define ICH6_REG_CORBWP 0x48 188 #define ICH6_REG_CORBRP 0x4a 189 #define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */ 190 #define ICH6_REG_CORBCTL 0x4c 191 #define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */ 192 #define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */ 193 #define ICH6_REG_CORBSTS 0x4d 194 #define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */ 195 #define ICH6_REG_CORBSIZE 0x4e 196 197 #define ICH6_REG_RIRBLBASE 0x50 198 #define ICH6_REG_RIRBUBASE 0x54 199 #define ICH6_REG_RIRBWP 0x58 200 #define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */ 201 #define ICH6_REG_RINTCNT 0x5a 202 #define ICH6_REG_RIRBCTL 0x5c 203 #define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */ 204 #define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */ 205 #define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */ 206 #define ICH6_REG_RIRBSTS 0x5d 207 #define ICH6_RBSTS_IRQ (1 << 0) /* response irq */ 208 #define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */ 209 #define ICH6_REG_RIRBSIZE 0x5e 210 211 #define ICH6_REG_IC 0x60 212 #define ICH6_REG_IR 0x64 213 #define ICH6_REG_IRS 0x68 214 #define ICH6_IRS_VALID (1<<1) 215 #define ICH6_IRS_BUSY (1<<0) 216 217 #define ICH6_REG_DPLBASE 0x70 218 #define ICH6_REG_DPUBASE 0x74 219 #define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */ 220 220 221 221 /* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ … … 223 223 224 224 /* stream register offsets from stream base */ 225 #define ICH6_REG_SD_CTL 0x00226 #define ICH6_REG_SD_STS 0x03227 #define ICH6_REG_SD_LPIB 0x04228 #define ICH6_REG_SD_CBL 0x08229 #define ICH6_REG_SD_LVI 0x0c230 #define ICH6_REG_SD_FIFOW 0x0e231 #define ICH6_REG_SD_FIFOSIZE 0x10232 #define ICH6_REG_SD_FORMAT 0x12233 #define ICH6_REG_SD_BDLPL 0x18234 #define ICH6_REG_SD_BDLPU 0x1c225 #define ICH6_REG_SD_CTL 0x00 226 #define ICH6_REG_SD_STS 0x03 227 #define ICH6_REG_SD_LPIB 0x04 228 #define ICH6_REG_SD_CBL 0x08 229 #define ICH6_REG_SD_LVI 0x0c 230 #define ICH6_REG_SD_FIFOW 0x0e 231 #define ICH6_REG_SD_FIFOSIZE 0x10 232 #define ICH6_REG_SD_FORMAT 0x12 233 #define ICH6_REG_SD_BDLPL 0x18 234 #define ICH6_REG_SD_BDLPU 0x1c 235 235 236 236 /* PCI space */ 237 #define ICH6_PCIREG_TCSEL 0x44237 #define ICH6_PCIREG_TCSEL 0x44 238 238 239 239 /* … … 243 243 /* max number of SDs */ 244 244 /* ICH, ATI and VIA have 4 playback and 4 capture */ 245 #define ICH6_NUM_CAPTURE 4246 #define ICH6_NUM_PLAYBACK 4245 #define ICH6_NUM_CAPTURE 4 246 #define ICH6_NUM_PLAYBACK 4 247 247 248 248 /* ULI has 6 playback and 5 capture */ 249 #define ULI_NUM_CAPTURE 5250 #define ULI_NUM_PLAYBACK 6249 #define ULI_NUM_CAPTURE 5 250 #define ULI_NUM_PLAYBACK 6 251 251 252 252 /* ATI HDMI has 1 playback and 0 capture */ 253 #define ATIHDMI_NUM_CAPTURE 0254 #define ATIHDMI_NUM_PLAYBACK 1253 #define ATIHDMI_NUM_CAPTURE 0 254 #define ATIHDMI_NUM_PLAYBACK 1 255 255 256 256 /* TERA has 4 playback and 3 capture */ 257 #define TERA_NUM_CAPTURE 3258 #define TERA_NUM_PLAYBACK 4257 #define TERA_NUM_CAPTURE 3 258 #define TERA_NUM_PLAYBACK 4 259 259 260 260 /* this number is statically defined for simplicity */ 261 #define MAX_AZX_DEV 16261 #define MAX_AZX_DEV 16 262 262 263 263 /* max number of fragments - we may use more if allocating more pages for BDL */ 264 #define BDL_SIZE 4096265 #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)266 #define AZX_MAX_FRAG 32264 #define BDL_SIZE 4096 265 #define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16) 266 #define AZX_MAX_FRAG 32 267 267 /* max buffer size - no h/w limit, you can increase as you like */ 268 #define AZX_MAX_BUF_SIZE (1024*1024*1024)268 #define AZX_MAX_BUF_SIZE (1024*1024*1024) 269 269 270 270 /* RIRB int mask: overrun[2], response[0] */ 271 #define RIRB_INT_RESPONSE 0x01272 #define RIRB_INT_OVERRUN 0x04273 #define RIRB_INT_MASK 0x05271 #define RIRB_INT_RESPONSE 0x01 272 #define RIRB_INT_OVERRUN 0x04 273 #define RIRB_INT_MASK 0x05 274 274 275 275 /* STATESTS int mask: S3,SD2,SD1,SD0 */ 276 #define AZX_MAX_CODECS 8277 #define AZX_DEFAULT_CODECS 4278 #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)276 #define AZX_MAX_CODECS 8 277 #define AZX_DEFAULT_CODECS 4 278 #define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1) 279 279 280 280 /* SD_CTL bits */ 281 #define SD_CTL_STREAM_RESET 0x01/* stream reset bit */282 #define SD_CTL_DMA_START 0x02/* stream DMA start bit */283 #define SD_CTL_STRIPE (3 << 16)/* stripe control */284 #define SD_CTL_TRAFFIC_PRIO (1 << 18)/* traffic priority */285 #define SD_CTL_DIR (1 << 19)/* bi-directional stream */286 #define SD_CTL_STREAM_TAG_MASK (0xf << 20)287 #define SD_CTL_STREAM_TAG_SHIFT 20281 #define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 282 #define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ 283 #define SD_CTL_STRIPE (3 << 16) /* stripe control */ 284 #define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */ 285 #define SD_CTL_DIR (1 << 19) /* bi-directional stream */ 286 #define SD_CTL_STREAM_TAG_MASK (0xf << 20) 287 #define SD_CTL_STREAM_TAG_SHIFT 20 288 288 289 289 /* SD_CTL and SD_STS */ 290 #define SD_INT_DESC_ERR 0x10/* descriptor error interrupt */291 #define SD_INT_FIFO_ERR 0x08/* FIFO error interrupt */292 #define SD_INT_COMPLETE 0x04/* completion interrupt */293 #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\294 SD_INT_COMPLETE)290 #define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */ 291 #define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */ 292 #define SD_INT_COMPLETE 0x04 /* completion interrupt */ 293 #define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\ 294 SD_INT_COMPLETE) 295 295 296 296 /* SD_STS */ 297 #define SD_STS_FIFO_READY 0x20/* FIFO ready */297 #define SD_STS_FIFO_READY 0x20 /* FIFO ready */ 298 298 299 299 /* INTCTL and INTSTS */ 300 #define ICH6_INT_ALL_STREAM 0xff/* all stream interrupts */301 #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */302 #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */300 #define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */ 301 #define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */ 302 #define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */ 303 303 304 304 /* below are so far hardcoded - should read registers in future */ 305 #define ICH6_MAX_CORB_ENTRIES 256306 #define ICH6_MAX_RIRB_ENTRIES 256305 #define ICH6_MAX_CORB_ENTRIES 256 306 #define ICH6_MAX_RIRB_ENTRIES 256 307 307 308 308 /* position fix mode */ 309 309 enum { 310 POS_FIX_AUTO,311 POS_FIX_LPIB,312 POS_FIX_POSBUF,313 POS_FIX_VIACOMBO,310 POS_FIX_AUTO, 311 POS_FIX_LPIB, 312 POS_FIX_POSBUF, 313 POS_FIX_VIACOMBO, 314 314 }; 315 315 … … 330 330 331 331 /* Define IN stream 0 FIFO size offset in VIA controller */ 332 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90332 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90 333 333 /* Define VIA HD Audio Device ID*/ 334 #define VIA_HDAC_DEVICE_ID 0x3288334 #define VIA_HDAC_DEVICE_ID 0x3288 335 335 336 336 /* HD Audio class code */ 337 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403337 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 338 338 339 339 /* … … 341 341 342 342 struct azx_dev { 343 struct snd_dma_buffer bdl; /* BDL buffer */343 struct snd_dma_buffer bdl; /* BDL buffer */ 344 344 #ifdef TARGET_OS2 345 volatile u32 *posbuf;/* position buffer pointer */345 volatile u32 *posbuf; /* position buffer pointer */ 346 346 #else 347 u32 *posbuf;/* position buffer pointer */347 u32 *posbuf; /* position buffer pointer */ 348 348 #endif 349 349 350 unsigned int bufsize;/* size of the play buffer in bytes */351 unsigned int period_bytes; /* size of the period in bytes */352 unsigned int frags;/* number for period in the play buffer */353 unsigned int fifo_size;/* FIFO size */354 unsigned long start_wallclk;/* start + minimum wallclk */355 unsigned long period_wallclk;/* wallclk for period */350 unsigned int bufsize; /* size of the play buffer in bytes */ 351 unsigned int period_bytes; /* size of the period in bytes */ 352 unsigned int frags; /* number for period in the play buffer */ 353 unsigned int fifo_size; /* FIFO size */ 354 unsigned long start_wallclk; /* start + minimum wallclk */ 355 unsigned long period_wallclk; /* wallclk for period */ 356 356 357 357 #ifdef TARGET_OS2 358 volatile void __iomem *sd_addr;/* stream descriptor pointer */358 volatile void __iomem *sd_addr; /* stream descriptor pointer */ 359 359 #else 360 void __iomem *sd_addr;/* stream descriptor pointer */360 void __iomem *sd_addr; /* stream descriptor pointer */ 361 361 #endif 362 362 363 u32 sd_int_sta_mask;/* stream int status mask */364 365 /* pcm support */366 struct snd_pcm_substream *substream;/* assigned substream,367 * set in PCM open368 */369 unsigned int format_val;/* format value to be set in the370 * controller and the codec371 */372 unsigned char stream_tag;/* assigned stream */373 unsigned char index;/* stream index */374 int device;/* last device number assigned to */375 376 unsigned int opened :1;377 unsigned int running :1;378 unsigned int irq_pending :1;379 /*380 * For VIA:381 * A flag to ensure DMA position is 0382 * when link position is not greater than FIFO size383 */384 unsigned int insufficient :1;363 u32 sd_int_sta_mask; /* stream int status mask */ 364 365 /* pcm support */ 366 struct snd_pcm_substream *substream; /* assigned substream, 367 * set in PCM open 368 */ 369 unsigned int format_val; /* format value to be set in the 370 * controller and the codec 371 */ 372 unsigned char stream_tag; /* assigned stream */ 373 unsigned char index; /* stream index */ 374 int device; /* last device number assigned to */ 375 376 unsigned int opened :1; 377 unsigned int running :1; 378 unsigned int irq_pending :1; 379 /* 380 * For VIA: 381 * A flag to ensure DMA position is 0 382 * when link position is not greater than FIFO size 383 */ 384 unsigned int insufficient :1; 385 385 }; 386 386 … … 388 388 struct azx_rb { 389 389 #ifdef TARGET_OS2 390 volatile u32 *buf;/* CORB/RIRB buffer */390 volatile u32 *buf; /* CORB/RIRB buffer */ 391 391 #else 392 u32 *buf;/* CORB/RIRB buffer */392 u32 *buf; /* CORB/RIRB buffer */ 393 393 #endif 394 /* Each CORB entry is 4byte, RIRB is 8byte395 */396 dma_addr_t addr;/* physical address of CORB/RIRB buffer */397 /* for RIRB */398 unsigned short rp, wp;/* read/write pointers */399 int cmds[AZX_MAX_CODECS];/* number of pending requests */400 u32 res[AZX_MAX_CODECS];/* last read value */394 /* Each CORB entry is 4byte, RIRB is 8byte 395 */ 396 dma_addr_t addr; /* physical address of CORB/RIRB buffer */ 397 /* for RIRB */ 398 unsigned short rp, wp; /* read/write pointers */ 399 int cmds[AZX_MAX_CODECS]; /* number of pending requests */ 400 u32 res[AZX_MAX_CODECS]; /* last read value */ 401 401 }; 402 402 403 403 struct azx { 404 struct snd_card *card;405 struct pci_dev *pci;406 int dev_index;407 408 /* chip type specific */409 int driver_type;410 int playback_streams;411 int playback_index_offset;412 int capture_streams;413 int capture_index_offset;414 int num_streams;415 416 /* pci resources */417 unsigned long addr;404 struct snd_card *card; 405 struct pci_dev *pci; 406 int dev_index; 407 408 /* chip type specific */ 409 int driver_type; 410 int playback_streams; 411 int playback_index_offset; 412 int capture_streams; 413 int capture_index_offset; 414 int num_streams; 415 416 /* pci resources */ 417 unsigned long addr; 418 418 #ifdef TARGET_OS2 419 volatile void __iomem *remap_addr;419 volatile void __iomem *remap_addr; 420 420 #else /* !TARGET_OS2 */ 421 void __iomem *remap_addr;421 void __iomem *remap_addr; 422 422 #endif /* !TARGET_OS2 */ 423 int irq;424 425 /* locks */426 spinlock_t reg_lock;427 struct mutex open_mutex;428 429 /* streams (x num_streams) */430 struct azx_dev *azx_dev;431 432 /* PCM */433 struct snd_pcm *pcm[HDA_MAX_PCMS];434 435 /* HD codec */436 unsigned short codec_mask;437 int codec_probe_mask; /* copied from probe_mask option */438 struct hda_bus *bus;439 unsigned int beep_mode;440 441 /* CORB/RIRB */442 struct azx_rb corb;443 struct azx_rb rirb;444 445 /* CORB/RIRB and position buffers */446 struct snd_dma_buffer rb;447 struct snd_dma_buffer posbuf;448 449 /* flags */450 int position_fix[2]; /* for both playback/capture streams */451 int poll_count;452 unsigned int running :1;453 unsigned int initialized :1;454 unsigned int single_cmd :1;455 unsigned int polling_mode :1;456 unsigned int msi :1;457 unsigned int irq_pending_warned :1;458 unsigned int probing :1; /* codec probing phase */459 460 /* for debugging */461 unsigned int last_cmd[AZX_MAX_CODECS];462 463 /* for pending irqs */464 struct work_struct irq_pending_work;465 466 /* reboot notifier (for mysterious hangup problem at power-down) */467 struct notifier_block reboot_notifier;423 int irq; 424 425 /* locks */ 426 spinlock_t reg_lock; 427 struct mutex open_mutex; 428 429 /* streams (x num_streams) */ 430 struct azx_dev *azx_dev; 431 432 /* PCM */ 433 struct snd_pcm *pcm[HDA_MAX_PCMS]; 434 435 /* HD codec */ 436 unsigned short codec_mask; 437 int codec_probe_mask; /* copied from probe_mask option */ 438 struct hda_bus *bus; 439 unsigned int beep_mode; 440 441 /* CORB/RIRB */ 442 struct azx_rb corb; 443 struct azx_rb rirb; 444 445 /* CORB/RIRB and position buffers */ 446 struct snd_dma_buffer rb; 447 struct snd_dma_buffer posbuf; 448 449 /* flags */ 450 int position_fix[2]; /* for both playback/capture streams */ 451 int poll_count; 452 unsigned int running :1; 453 unsigned int initialized :1; 454 unsigned int single_cmd :1; 455 unsigned int polling_mode :1; 456 unsigned int msi :1; 457 unsigned int irq_pending_warned :1; 458 unsigned int probing :1; /* codec probing phase */ 459 460 /* for debugging */ 461 unsigned int last_cmd[AZX_MAX_CODECS]; 462 463 /* for pending irqs */ 464 struct work_struct irq_pending_work; 465 466 /* reboot notifier (for mysterious hangup problem at power-down) */ 467 struct notifier_block reboot_notifier; 468 468 }; 469 469 470 470 /* driver types */ 471 471 enum { 472 AZX_DRIVER_ICH, 473 AZX_DRIVER_PCH, 474 AZX_DRIVER_SCH, 475 AZX_DRIVER_ATI, 476 AZX_DRIVER_ATIHDMI, 477 AZX_DRIVER_VIA, 478 AZX_DRIVER_SIS, 479 AZX_DRIVER_ULI, 480 AZX_DRIVER_NVIDIA, 481 AZX_DRIVER_TERA, 482 AZX_DRIVER_CTX, 483 AZX_DRIVER_GENERIC, 484 AZX_NUM_DRIVERS, /* keep this as last entry */ 472 AZX_DRIVER_ICH, 473 AZX_DRIVER_PCH, 474 AZX_DRIVER_SCH, 475 AZX_DRIVER_HDMI, 476 AZX_DRIVER_ATI, 477 AZX_DRIVER_ATIHDMI, 478 AZX_DRIVER_VIA, 479 AZX_DRIVER_SIS, 480 AZX_DRIVER_ULI, 481 AZX_DRIVER_NVIDIA, 482 AZX_DRIVER_TERA, 483 AZX_DRIVER_CTX, 484 AZX_DRIVER_GENERIC, 485 AZX_NUM_DRIVERS, /* keep this as last entry */ 485 486 }; 486 487 487 488 static char *driver_short_names[] __devinitdata = { 488 [AZX_DRIVER_ICH] = "HDA Intel", 489 [AZX_DRIVER_PCH] = "HDA Intel PCH", 490 [AZX_DRIVER_SCH] = "HDA Intel MID", 491 [AZX_DRIVER_ATI] = "HDA ATI SB", 492 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", 493 [AZX_DRIVER_VIA] = "HDA VIA VT82xx", 494 [AZX_DRIVER_SIS] = "HDA SIS966", 495 [AZX_DRIVER_ULI] = "HDA ULI M5461", 496 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 497 [AZX_DRIVER_TERA] = "HDA Teradici", 498 [AZX_DRIVER_CTX] = "HDA Creative", 499 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 489 [AZX_DRIVER_ICH] = "HDA Intel", 490 [AZX_DRIVER_PCH] = "HDA Intel PCH", 491 [AZX_DRIVER_SCH] = "HDA Intel MID", 492 [AZX_DRIVER_HDMI] = "HDA Intel HDMI", 493 [AZX_DRIVER_ATI] = "HDA ATI SB", 494 [AZX_DRIVER_ATIHDMI] = "HDA ATI HDMI", 495 [AZX_DRIVER_VIA] = "HDA VIA VT82xx", 496 [AZX_DRIVER_SIS] = "HDA SIS966", 497 [AZX_DRIVER_ULI] = "HDA ULI M5461", 498 [AZX_DRIVER_NVIDIA] = "HDA NVidia", 499 [AZX_DRIVER_TERA] = "HDA Teradici", 500 [AZX_DRIVER_CTX] = "HDA Creative", 501 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 500 502 }; 501 503 … … 504 506 */ 505 507 #define azx_writel(chip,reg,value) \ 506 writel(value, (chip)->remap_addr + ICH6_REG_##reg)508 writel(value, (chip)->remap_addr + ICH6_REG_##reg) 507 509 #define azx_readl(chip,reg) \ 508 readl((chip)->remap_addr + ICH6_REG_##reg)510 readl((chip)->remap_addr + ICH6_REG_##reg) 509 511 #define azx_writew(chip,reg,value) \ 510 writew(value, (chip)->remap_addr + ICH6_REG_##reg)512 writew(value, (chip)->remap_addr + ICH6_REG_##reg) 511 513 #define azx_readw(chip,reg) \ 512 readw((chip)->remap_addr + ICH6_REG_##reg)514 readw((chip)->remap_addr + ICH6_REG_##reg) 513 515 #define azx_writeb(chip,reg,value) \ 514 writeb(value, (chip)->remap_addr + ICH6_REG_##reg)516 writeb(value, (chip)->remap_addr + ICH6_REG_##reg) 515 517 #define azx_readb(chip,reg) \ 516 readb((chip)->remap_addr + ICH6_REG_##reg)518 readb((chip)->remap_addr + ICH6_REG_##reg) 517 519 518 520 #define azx_sd_writel(dev,reg,value) \ 519 writel(value, (dev)->sd_addr + ICH6_REG_##reg)521 writel(value, (dev)->sd_addr + ICH6_REG_##reg) 520 522 #define azx_sd_readl(dev,reg) \ 521 readl((dev)->sd_addr + ICH6_REG_##reg)523 readl((dev)->sd_addr + ICH6_REG_##reg) 522 524 #define azx_sd_writew(dev,reg,value) \ 523 writew(value, (dev)->sd_addr + ICH6_REG_##reg)525 writew(value, (dev)->sd_addr + ICH6_REG_##reg) 524 526 #define azx_sd_readw(dev,reg) \ 525 readw((dev)->sd_addr + ICH6_REG_##reg)527 readw((dev)->sd_addr + ICH6_REG_##reg) 526 528 #define azx_sd_writeb(dev,reg,value) \ 527 writeb(value, (dev)->sd_addr + ICH6_REG_##reg)529 writeb(value, (dev)->sd_addr + ICH6_REG_##reg) 528 530 #define azx_sd_readb(dev,reg) \ 529 readb((dev)->sd_addr + ICH6_REG_##reg)531 readb((dev)->sd_addr + ICH6_REG_##reg) 530 532 531 533 /* for pcm support */ … … 543 545 static int azx_alloc_cmd_io(struct azx *chip) 544 546 { 545 int err;546 547 /* single page (at least 4096 bytes) must suffice for both ringbuffes */548 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,549 snd_dma_pci_data(chip->pci),550 PAGE_SIZE, &chip->rb);551 if (err < 0) {552 snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");553 return err;554 }555 return 0;547 int err; 548 549 /* single page (at least 4096 bytes) must suffice for both ringbuffes */ 550 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 551 snd_dma_pci_data(chip->pci), 552 PAGE_SIZE, &chip->rb); 553 if (err < 0) { 554 snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n"); 555 return err; 556 } 557 return 0; 556 558 } 557 559 558 560 static void azx_init_cmd_io(struct azx *chip) 559 561 { 560 spin_lock_irq(&chip->reg_lock);561 /* CORB set up */562 chip->corb.addr = chip->rb.addr;563 chip->corb.buf = (u32 *)chip->rb.area;564 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);565 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));566 567 /* set the corb size to 256 entries (ULI requires explicitly) */568 azx_writeb(chip, CORBSIZE, 0x02);569 /* set the corb write pointer to 0 */570 azx_writew(chip, CORBWP, 0);571 /* reset the corb hw read pointer */572 azx_writew(chip, CORBRP, ICH6_CORBRP_RST);573 /* enable corb dma */574 azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);575 576 /* RIRB set up */577 chip->rirb.addr = chip->rb.addr + 2048;578 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);579 chip->rirb.wp = chip->rirb.rp = 0;580 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));581 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);582 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));583 584 /* set the rirb size to 256 entries (ULI requires explicitly) */585 azx_writeb(chip, RIRBSIZE, 0x02);586 /* reset the rirb hw write pointer */587 azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);588 /* set N=1, get RIRB response interrupt for new entry */589 if (chip->driver_type == AZX_DRIVER_CTX)590 azx_writew(chip, RINTCNT, 0xc0);591 else592 azx_writew(chip, RINTCNT, 1);593 /* enable rirb dma and response irq */594 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);595 spin_unlock_irq(&chip->reg_lock);562 spin_lock_irq(&chip->reg_lock); 563 /* CORB set up */ 564 chip->corb.addr = chip->rb.addr; 565 chip->corb.buf = (u32 *)chip->rb.area; 566 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr); 567 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr)); 568 569 /* set the corb size to 256 entries (ULI requires explicitly) */ 570 azx_writeb(chip, CORBSIZE, 0x02); 571 /* set the corb write pointer to 0 */ 572 azx_writew(chip, CORBWP, 0); 573 /* reset the corb hw read pointer */ 574 azx_writew(chip, CORBRP, ICH6_CORBRP_RST); 575 /* enable corb dma */ 576 azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN); 577 578 /* RIRB set up */ 579 chip->rirb.addr = chip->rb.addr + 2048; 580 chip->rirb.buf = (u32 *)(chip->rb.area + 2048); 581 chip->rirb.wp = chip->rirb.rp = 0; 582 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds)); 583 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr); 584 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr)); 585 586 /* set the rirb size to 256 entries (ULI requires explicitly) */ 587 azx_writeb(chip, RIRBSIZE, 0x02); 588 /* reset the rirb hw write pointer */ 589 azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST); 590 /* set N=1, get RIRB response interrupt for new entry */ 591 if (chip->driver_type == AZX_DRIVER_CTX) 592 azx_writew(chip, RINTCNT, 0xc0); 593 else 594 azx_writew(chip, RINTCNT, 1); 595 /* enable rirb dma and response irq */ 596 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN); 597 spin_unlock_irq(&chip->reg_lock); 596 598 } 597 599 598 600 static void azx_free_cmd_io(struct azx *chip) 599 601 { 600 spin_lock_irq(&chip->reg_lock);601 /* disable ringbuffer DMAs */602 azx_writeb(chip, RIRBCTL, 0);603 azx_writeb(chip, CORBCTL, 0);604 spin_unlock_irq(&chip->reg_lock);602 spin_lock_irq(&chip->reg_lock); 603 /* disable ringbuffer DMAs */ 604 azx_writeb(chip, RIRBCTL, 0); 605 azx_writeb(chip, CORBCTL, 0); 606 spin_unlock_irq(&chip->reg_lock); 605 607 } 606 608 607 609 static unsigned int azx_command_addr(u32 cmd) 608 610 { 609 unsigned int addr = cmd >> 28;610 611 if (addr >= AZX_MAX_CODECS) {612 snd_BUG();613 addr = 0;614 }615 616 return addr;611 unsigned int addr = cmd >> 28; 612 613 if (addr >= AZX_MAX_CODECS) { 614 snd_BUG(); 615 addr = 0; 616 } 617 618 return addr; 617 619 } 618 620 619 621 static unsigned int azx_response_addr(u32 res) 620 622 { 621 unsigned int addr = res & 0xf;622 623 if (addr >= AZX_MAX_CODECS) {624 snd_BUG();625 addr = 0;626 }627 628 return addr;623 unsigned int addr = res & 0xf; 624 625 if (addr >= AZX_MAX_CODECS) { 626 snd_BUG(); 627 addr = 0; 628 } 629 630 return addr; 629 631 } 630 632 … … 632 634 static int azx_corb_send_cmd(struct hda_bus *bus, u32 val) 633 635 { 634 struct azx *chip = bus->private_data;635 unsigned int addr = azx_command_addr(val);636 unsigned int wp;637 638 spin_lock_irq(&chip->reg_lock);639 640 /* add command to corb */641 wp = azx_readb(chip, CORBWP);642 wp++;643 wp %= ICH6_MAX_CORB_ENTRIES;644 645 chip->rirb.cmds[addr]++;646 chip->corb.buf[wp] = cpu_to_le32(val);647 azx_writel(chip, CORBWP, wp);648 649 spin_unlock_irq(&chip->reg_lock);650 651 return 0;652 } 653 654 #define ICH6_RIRB_EX_UNSOL_EV (1<<4)636 struct azx *chip = bus->private_data; 637 unsigned int addr = azx_command_addr(val); 638 unsigned int wp; 639 640 spin_lock_irq(&chip->reg_lock); 641 642 /* add command to corb */ 643 wp = azx_readb(chip, CORBWP); 644 wp++; 645 wp %= ICH6_MAX_CORB_ENTRIES; 646 647 chip->rirb.cmds[addr]++; 648 chip->corb.buf[wp] = cpu_to_le32(val); 649 azx_writel(chip, CORBWP, wp); 650 651 spin_unlock_irq(&chip->reg_lock); 652 653 return 0; 654 } 655 656 #define ICH6_RIRB_EX_UNSOL_EV (1<<4) 655 657 656 658 /* retrieve RIRB entry - called from interrupt handler */ 657 659 static void azx_update_rirb(struct azx *chip) 658 660 { 659 unsigned int rp, wp;660 unsigned int addr;661 u32 res, res_ex;662 663 wp = azx_readb(chip, RIRBWP);664 if (wp == chip->rirb.wp)665 return;666 chip->rirb.wp = wp;667 668 while (chip->rirb.rp != wp) {669 chip->rirb.rp++;670 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;671 672 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */673 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);674 res = le32_to_cpu(chip->rirb.buf[rp]);675 addr = azx_response_addr(res_ex);676 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)677 snd_hda_queue_unsol_event(chip->bus, res, res_ex);678 else if (chip->rirb.cmds[addr]) {679 chip->rirb.res[addr] = res;680 smp_wmb();681 chip->rirb.cmds[addr]--;682 } else683 snd_printk(KERN_ERR SFX "spurious response %#x:%#x, "684 "last cmd=%#08x\n",685 res, res_ex,686 chip->last_cmd[addr]);687 }661 unsigned int rp, wp; 662 unsigned int addr; 663 u32 res, res_ex; 664 665 wp = azx_readb(chip, RIRBWP); 666 if (wp == chip->rirb.wp) 667 return; 668 chip->rirb.wp = wp; 669 670 while (chip->rirb.rp != wp) { 671 chip->rirb.rp++; 672 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES; 673 674 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ 675 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); 676 res = le32_to_cpu(chip->rirb.buf[rp]); 677 addr = azx_response_addr(res_ex); 678 if (res_ex & ICH6_RIRB_EX_UNSOL_EV) 679 snd_hda_queue_unsol_event(chip->bus, res, res_ex); 680 else if (chip->rirb.cmds[addr]) { 681 chip->rirb.res[addr] = res; 682 smp_wmb(); 683 chip->rirb.cmds[addr]--; 684 } else 685 snd_printk(KERN_ERR SFX "spurious response %#x:%#x, " 686 "last cmd=%#08x\n", 687 res, res_ex, 688 chip->last_cmd[addr]); 689 } 688 690 } 689 691 690 692 /* receive a response */ 691 693 static unsigned int azx_rirb_get_response(struct hda_bus *bus, 692 unsigned int addr)693 { 694 struct azx *chip = bus->private_data;695 unsigned long timeout;694 unsigned int addr) 695 { 696 struct azx *chip = bus->private_data; 697 unsigned long timeout; 696 698 #ifdef TARGET_OS2 697 int count = 0;699 int count = 0; 698 700 #endif 699 int do_poll = 0;701 int do_poll = 0; 700 702 701 703 again: 702 timeout = jiffies + msecs_to_jiffies(1000);703 for ( ; ; ) {704 if (chip->polling_mode || do_poll) {705 spin_lock_irq(&chip->reg_lock);706 azx_update_rirb(chip);707 spin_unlock_irq(&chip->reg_lock);708 }709 if (!chip->rirb.cmds[addr]) {710 smp_rmb();711 bus->rirb_error = 0;712 713 if (!do_poll)714 chip->poll_count = 0;715 return chip->rirb.res[addr]; /* the last value */716 }717 if (time_after(jiffies, timeout))718 break;704 timeout = jiffies + msecs_to_jiffies(1000); 705 for ( ; ; ) { 706 if (chip->polling_mode || do_poll) { 707 spin_lock_irq(&chip->reg_lock); 708 azx_update_rirb(chip); 709 spin_unlock_irq(&chip->reg_lock); 710 } 711 if (!chip->rirb.cmds[addr]) { 712 smp_rmb(); 713 bus->rirb_error = 0; 714 715 if (!do_poll) 716 chip->poll_count = 0; 717 return chip->rirb.res[addr]; /* the last value */ 718 } 719 if (time_after(jiffies, timeout)) 720 break; 719 721 #ifdef TARGET_OS2 720 if (count >= 5000) /* Hack on OS/2 to stop infinite loop as jiffies sometimes don't increment */721 break;722 if (count >= 5000) /* Hack on OS/2 to stop infinite loop as jiffies sometimes don't increment */ 723 break; 722 724 #endif 723 if (bus->needs_damn_long_delay)724 msleep(2); /* temporary workaround */725 else {726 udelay(10);727 cond_resched();728 }725 if (bus->needs_damn_long_delay) 726 msleep(2); /* temporary workaround */ 727 else { 728 udelay(10); 729 cond_resched(); 730 } 729 731 #ifdef TARGET_OS2 730 count++;732 count++; 731 733 #endif 732 }733 734 if (!chip->polling_mode && chip->poll_count < 2) {735 snd_printdd(SFX "azx_get_response timeout, "736 "polling the codec once: last cmd=0x%08x\n",737 chip->last_cmd[addr]);738 do_poll = 1;739 chip->poll_count++;740 goto again;741 }742 743 744 if (!chip->polling_mode) {745 snd_printk(KERN_WARNING SFX "azx_get_response timeout, "746 "switching to polling mode: last cmd=0x%08x\n",747 chip->last_cmd[addr]);748 chip->polling_mode = 1;749 goto again;750 }734 } 735 736 if (!chip->polling_mode && chip->poll_count < 2) { 737 snd_printdd(SFX "azx_get_response timeout, " 738 "polling the codec once: last cmd=0x%08x\n", 739 chip->last_cmd[addr]); 740 do_poll = 1; 741 chip->poll_count++; 742 goto again; 743 } 744 745 746 if (!chip->polling_mode) { 747 snd_printk(KERN_WARNING SFX "azx_get_response timeout, " 748 "switching to polling mode: last cmd=0x%08x\n", 749 chip->last_cmd[addr]); 750 chip->polling_mode = 1; 751 goto again; 752 } 751 753 #ifdef TARGET_OS2 752 if (count >= 5000) {753 snd_printk(KERN_WARNING "hda_intel: count >= 5000, aborting loop in azx_rirb_get_response\n");754 }754 if (count >= 5000) { 755 snd_printk(KERN_WARNING "hda_intel: count >= 5000, aborting loop in azx_rirb_get_response\n"); 756 } 755 757 #endif 756 if (chip->msi) {757 snd_printk(KERN_WARNING SFX "No response from codec, "758 "disabling MSI: last cmd=0x%08x\n",759 chip->last_cmd[addr]);760 free_irq(chip->irq, chip);761 chip->irq = -1;762 pci_disable_msi(chip->pci);763 chip->msi = 0;764 if (azx_acquire_irq(chip, 1) < 0) {765 bus->rirb_error = 1;766 return -1;767 }768 goto again;769 }770 771 if (chip->probing) {772 /* If this critical timeout happens during the codec probing773 * phase, this is likely an access to a non-existing codec774 * slot. Better to return an error and reset the system.775 */776 return -1;777 }778 779 /* a fatal communication error; need either to reset or to fallback780 * to the single_cmd mode781 */782 bus->rirb_error = 1;783 if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {784 bus->response_reset = 1;785 return -1; /* give a chance to retry */786 }787 788 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "789 "switching to single_cmd mode: last cmd=0x%08x\n",790 chip->last_cmd[addr]);791 chip->single_cmd = 1;792 bus->response_reset = 0;793 /* release CORB/RIRB */794 azx_free_cmd_io(chip);795 /* disable unsolicited responses */796 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);797 return -1;758 if (chip->msi) { 759 snd_printk(KERN_WARNING SFX "No response from codec, " 760 "disabling MSI: last cmd=0x%08x\n", 761 chip->last_cmd[addr]); 762 free_irq(chip->irq, chip); 763 chip->irq = -1; 764 pci_disable_msi(chip->pci); 765 chip->msi = 0; 766 if (azx_acquire_irq(chip, 1) < 0) { 767 bus->rirb_error = 1; 768 return -1; 769 } 770 goto again; 771 } 772 773 if (chip->probing) { 774 /* If this critical timeout happens during the codec probing 775 * phase, this is likely an access to a non-existing codec 776 * slot. Better to return an error and reset the system. 777 */ 778 return -1; 779 } 780 781 /* a fatal communication error; need either to reset or to fallback 782 * to the single_cmd mode 783 */ 784 bus->rirb_error = 1; 785 if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) { 786 bus->response_reset = 1; 787 return -1; /* give a chance to retry */ 788 } 789 790 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, " 791 "switching to single_cmd mode: last cmd=0x%08x\n", 792 chip->last_cmd[addr]); 793 chip->single_cmd = 1; 794 bus->response_reset = 0; 795 /* release CORB/RIRB */ 796 azx_free_cmd_io(chip); 797 /* disable unsolicited responses */ 798 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL); 799 return -1; 798 800 } 799 801 … … 811 813 static int azx_single_wait_for_response(struct azx *chip, unsigned int addr) 812 814 { 813 int timeout = 50;814 815 while (timeout--) {816 /* check IRV busy bit */817 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {818 /* reuse rirb.res as the response return value */819 chip->rirb.res[addr] = azx_readl(chip, IR);820 return 0;821 }822 udelay(1);823 }824 if (printk_ratelimit())825 snd_printd(SFX "get_response timeout: IRS=0x%x\n",826 azx_readw(chip, IRS));827 chip->rirb.res[addr] = -1;828 return -EIO;815 int timeout = 50; 816 817 while (timeout--) { 818 /* check IRV busy bit */ 819 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) { 820 /* reuse rirb.res as the response return value */ 821 chip->rirb.res[addr] = azx_readl(chip, IR); 822 return 0; 823 } 824 udelay(1); 825 } 826 if (printk_ratelimit()) 827 snd_printd(SFX "get_response timeout: IRS=0x%x\n", 828 azx_readw(chip, IRS)); 829 chip->rirb.res[addr] = -1; 830 return -EIO; 829 831 } 830 832 … … 832 834 static int azx_single_send_cmd(struct hda_bus *bus, u32 val) 833 835 { 834 struct azx *chip = bus->private_data;835 unsigned int addr = azx_command_addr(val);836 int timeout = 50;837 838 bus->rirb_error = 0;839 while (timeout--) {840 /* check ICB busy bit */841 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {842 /* Clear IRV valid bit */843 azx_writew(chip, IRS, azx_readw(chip, IRS) |844 ICH6_IRS_VALID);845 azx_writel(chip, IC, val);846 azx_writew(chip, IRS, azx_readw(chip, IRS) |847 ICH6_IRS_BUSY);848 return azx_single_wait_for_response(chip, addr);849 }850 udelay(1);851 }852 if (printk_ratelimit())853 snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n",854 azx_readw(chip, IRS), val);855 return -EIO;836 struct azx *chip = bus->private_data; 837 unsigned int addr = azx_command_addr(val); 838 int timeout = 50; 839 840 bus->rirb_error = 0; 841 while (timeout--) { 842 /* check ICB busy bit */ 843 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) { 844 /* Clear IRV valid bit */ 845 azx_writew(chip, IRS, azx_readw(chip, IRS) | 846 ICH6_IRS_VALID); 847 azx_writel(chip, IC, val); 848 azx_writew(chip, IRS, azx_readw(chip, IRS) | 849 ICH6_IRS_BUSY); 850 return azx_single_wait_for_response(chip, addr); 851 } 852 udelay(1); 853 } 854 if (printk_ratelimit()) 855 snd_printd(SFX "send_cmd timeout: IRS=0x%x, val=0x%x\n", 856 azx_readw(chip, IRS), val); 857 return -EIO; 856 858 } 857 859 858 860 /* receive a response */ 859 861 static unsigned int azx_single_get_response(struct hda_bus *bus, 860 unsigned int addr)861 { 862 struct azx *chip = bus->private_data;863 return chip->rirb.res[addr];862 unsigned int addr) 863 { 864 struct azx *chip = bus->private_data; 865 return chip->rirb.res[addr]; 864 866 } 865 867 … … 874 876 static int azx_send_cmd(struct hda_bus *bus, unsigned int val) 875 877 { 876 struct azx *chip = bus->private_data;877 878 chip->last_cmd[azx_command_addr(val)] = val;879 if (chip->single_cmd)880 return azx_single_send_cmd(bus, val);881 else882 return azx_corb_send_cmd(bus, val);878 struct azx *chip = bus->private_data; 879 880 chip->last_cmd[azx_command_addr(val)] = val; 881 if (chip->single_cmd) 882 return azx_single_send_cmd(bus, val); 883 else 884 return azx_corb_send_cmd(bus, val); 883 885 } 884 886 885 887 /* get a response */ 886 888 static unsigned int azx_get_response(struct hda_bus *bus, 887 unsigned int addr)888 { 889 struct azx *chip = bus->private_data;890 if (chip->single_cmd)891 return azx_single_get_response(bus, addr);892 else893 return azx_rirb_get_response(bus, addr);889 unsigned int addr) 890 { 891 struct azx *chip = bus->private_data; 892 if (chip->single_cmd) 893 return azx_single_get_response(bus, addr); 894 else 895 return azx_rirb_get_response(bus, addr); 894 896 } 895 897 … … 901 903 static int azx_reset(struct azx *chip, int full_reset) 902 904 { 903 int count;904 905 if (!full_reset)906 goto __skip;907 908 /* clear STATESTS */909 azx_writeb(chip, STATESTS, STATESTS_INT_MASK);910 911 /* reset controller */912 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);913 914 count = 50;915 while (azx_readb(chip, GCTL) && --count)916 msleep(1);917 918 /* delay for >= 100us for codec PLL to settle per spec919 * Rev 0.9 section 5.5.1920 */921 msleep(1);922 923 /* Bring controller out of reset */924 azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);925 926 count = 50;927 while (!azx_readb(chip, GCTL) && --count)928 msleep(1);929 930 /* Brent Chartrand said to wait >= 540us for codecs to initialize */931 msleep(1);905 int count; 906 907 if (!full_reset) 908 goto __skip; 909 910 /* clear STATESTS */ 911 azx_writeb(chip, STATESTS, STATESTS_INT_MASK); 912 913 /* reset controller */ 914 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET); 915 916 count = 50; 917 while (azx_readb(chip, GCTL) && --count) 918 msleep(1); 919 920 /* delay for >= 100us for codec PLL to settle per spec 921 * Rev 0.9 section 5.5.1 922 */ 923 msleep(1); 924 925 /* Bring controller out of reset */ 926 azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET); 927 928 count = 50; 929 while (!azx_readb(chip, GCTL) && --count) 930 msleep(1); 931 932 /* Brent Chartrand said to wait >= 540us for codecs to initialize */ 933 msleep(1); 932 934 933 935 __skip: 934 /* check to see if controller is ready */935 if (!azx_readb(chip, GCTL)) {936 snd_printd(SFX "azx_reset: controller not ready!\n");937 return -EBUSY;938 }939 940 /* Accept unsolicited responses */941 if (!chip->single_cmd)942 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |943 ICH6_GCTL_UNSOL);944 945 /* detect codecs */946 if (!chip->codec_mask) {947 chip->codec_mask = azx_readw(chip, STATESTS);948 snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask);949 }950 951 return 0;936 /* check to see if controller is ready */ 937 if (!azx_readb(chip, GCTL)) { 938 snd_printd(SFX "azx_reset: controller not ready!\n"); 939 return -EBUSY; 940 } 941 942 /* Accept unsolicited responses */ 943 if (!chip->single_cmd) 944 azx_writel(chip, GCTL, azx_readl(chip, GCTL) | 945 ICH6_GCTL_UNSOL); 946 947 /* detect codecs */ 948 if (!chip->codec_mask) { 949 chip->codec_mask = azx_readw(chip, STATESTS); 950 snd_printdd(SFX "codec_mask = 0x%x\n", chip->codec_mask); 951 } 952 953 return 0; 952 954 } 953 955 … … 960 962 static void azx_int_enable(struct azx *chip) 961 963 { 962 /* enable controller CIE and GIE */963 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |964 ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);964 /* enable controller CIE and GIE */ 965 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) | 966 ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN); 965 967 } 966 968 … … 968 970 static void azx_int_disable(struct azx *chip) 969 971 { 970 int i;971 972 /* disable interrupts in stream descriptor */973 for (i = 0; i < chip->num_streams; i++) {974 struct azx_dev *azx_dev = &chip->azx_dev[i];975 azx_sd_writeb(azx_dev, SD_CTL,976 azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);977 }978 979 /* disable SIE for all streams */980 azx_writeb(chip, INTCTL, 0);981 982 /* disable controller CIE and GIE */983 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &984 ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));972 int i; 973 974 /* disable interrupts in stream descriptor */ 975 for (i = 0; i < chip->num_streams; i++) { 976 struct azx_dev *azx_dev = &chip->azx_dev[i]; 977 azx_sd_writeb(azx_dev, SD_CTL, 978 azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK); 979 } 980 981 /* disable SIE for all streams */ 982 azx_writeb(chip, INTCTL, 0); 983 984 /* disable controller CIE and GIE */ 985 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) & 986 ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN)); 985 987 } 986 988 … … 988 990 static void azx_int_clear(struct azx *chip) 989 991 { 990 int i;991 992 /* clear stream status */993 for (i = 0; i < chip->num_streams; i++) {994 struct azx_dev *azx_dev = &chip->azx_dev[i];995 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);996 }997 998 /* clear STATESTS */999 azx_writeb(chip, STATESTS, STATESTS_INT_MASK);1000 1001 /* clear rirb status */1002 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);1003 1004 /* clear int status */1005 azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);992 int i; 993 994 /* clear stream status */ 995 for (i = 0; i < chip->num_streams; i++) { 996 struct azx_dev *azx_dev = &chip->azx_dev[i]; 997 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); 998 } 999 1000 /* clear STATESTS */ 1001 azx_writeb(chip, STATESTS, STATESTS_INT_MASK); 1002 1003 /* clear rirb status */ 1004 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); 1005 1006 /* clear int status */ 1007 azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM); 1006 1008 } 1007 1009 … … 1009 1011 static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev) 1010 1012 { 1011 /*1012 * Before stream start, initialize parameter1013 */1014 azx_dev->insufficient = 1;1015 1016 /* enable SIE */1017 azx_writel(chip, INTCTL,1018 azx_readl(chip, INTCTL) | (1 << azx_dev->index));1019 /* set DMA start and interrupt mask */1020 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |1021 SD_CTL_DMA_START | SD_INT_MASK);1013 /* 1014 * Before stream start, initialize parameter 1015 */ 1016 azx_dev->insufficient = 1; 1017 1018 /* enable SIE */ 1019 azx_writel(chip, INTCTL, 1020 azx_readl(chip, INTCTL) | (1 << azx_dev->index)); 1021 /* set DMA start and interrupt mask */ 1022 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) | 1023 SD_CTL_DMA_START | SD_INT_MASK); 1022 1024 } 1023 1025 … … 1025 1027 static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev) 1026 1028 { 1027 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &1028 ~(SD_CTL_DMA_START | SD_INT_MASK));1029 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */1029 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) & 1030 ~(SD_CTL_DMA_START | SD_INT_MASK)); 1031 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */ 1030 1032 } 1031 1033 … … 1033 1035 static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev) 1034 1036 { 1035 azx_stream_clear(chip, azx_dev);1036 /* disable SIE */1037 azx_writel(chip, INTCTL,1038 azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));1037 azx_stream_clear(chip, azx_dev); 1038 /* disable SIE */ 1039 azx_writel(chip, INTCTL, 1040 azx_readl(chip, INTCTL) & ~(1 << azx_dev->index)); 1039 1041 } 1040 1042 … … 1045 1047 static void azx_init_chip(struct azx *chip, int full_reset) 1046 1048 { 1047 if (chip->initialized)1048 return;1049 1050 /* reset controller */1051 azx_reset(chip, full_reset);1052 1053 /* initialize interrupts */1054 azx_int_clear(chip);1055 azx_int_enable(chip);1056 1057 /* initialize the codec command I/O */1058 if (!chip->single_cmd)1059 azx_init_cmd_io(chip);1060 1061 /* program the position buffer */1062 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);1063 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));1064 1065 chip->initialized = 1;1049 if (chip->initialized) 1050 return; 1051 1052 /* reset controller */ 1053 azx_reset(chip, full_reset); 1054 1055 /* initialize interrupts */ 1056 azx_int_clear(chip); 1057 azx_int_enable(chip); 1058 1059 /* initialize the codec command I/O */ 1060 if (!chip->single_cmd) 1061 azx_init_cmd_io(chip); 1062 1063 /* program the position buffer */ 1064 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); 1065 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr)); 1066 1067 chip->initialized = 1; 1066 1068 } 1067 1069 … … 1071 1073 /* update bits in a PCI register byte */ 1072 1074 static void update_pci_byte(struct pci_dev *pci, unsigned int reg, 1073 unsigned char mask, unsigned char val)1074 { 1075 unsigned char data;1076 1077 pci_read_config_byte(pci, reg, &data);1078 data &= ~mask;1079 data |= (val & mask);1080 pci_write_config_byte(pci, reg, data);1075 unsigned char mask, unsigned char val) 1076 { 1077 unsigned char data; 1078 1079 pci_read_config_byte(pci, reg, &data); 1080 data &= ~mask; 1081 data |= (val & mask); 1082 pci_write_config_byte(pci, reg, data); 1081 1083 } 1082 1084 1083 1085 static void azx_init_pci(struct azx *chip) 1084 1086 { 1085 unsigned short snoop;1086 1087 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)1088 * TCSEL == Traffic Class Select Register, which sets PCI express QOS1089 * Ensuring these bits are 0 clears playback static on some HD Audio1090 * codecs1091 */1092 update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);1093 1094 switch (chip->driver_type) {1095 case AZX_DRIVER_ATI:1096 /* For ATI SB450 azalia HD audio, we need to enable snoop */1097 update_pci_byte(chip->pci,1098 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,1099 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP);1100 break;1101 case AZX_DRIVER_NVIDIA:1102 /* For NVIDIA HDA, enable snoop */1103 update_pci_byte(chip->pci,1104 NVIDIA_HDA_TRANSREG_ADDR,1105 0x0f, NVIDIA_HDA_ENABLE_COHBITS);1106 update_pci_byte(chip->pci,1107 NVIDIA_HDA_ISTRM_COH,1108 0x01, NVIDIA_HDA_ENABLE_COHBIT);1109 update_pci_byte(chip->pci,1110 NVIDIA_HDA_OSTRM_COH,1111 0x01, NVIDIA_HDA_ENABLE_COHBIT);1112 break;1113 case AZX_DRIVER_SCH:1114 case AZX_DRIVER_PCH:1115 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);1116 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) {1117 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC,1118 snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP));1119 pci_read_config_word(chip->pci,1120 INTEL_SCH_HDA_DEVC, &snoop);1121 snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",1122 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)1123 ? "Failed" : "OK");1124 }1125 break;1087 unsigned short snoop; 1088 1089 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) 1090 * TCSEL == Traffic Class Select Register, which sets PCI express QOS 1091 * Ensuring these bits are 0 clears playback static on some HD Audio 1092 * codecs 1093 */ 1094 update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0); 1095 1096 switch (chip->driver_type) { 1097 case AZX_DRIVER_ATI: 1098 /* For ATI SB450 azalia HD audio, we need to enable snoop */ 1099 update_pci_byte(chip->pci, 1100 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 1101 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP); 1102 break; 1103 case AZX_DRIVER_NVIDIA: 1104 /* For NVIDIA HDA, enable snoop */ 1105 update_pci_byte(chip->pci, 1106 NVIDIA_HDA_TRANSREG_ADDR, 1107 0x0f, NVIDIA_HDA_ENABLE_COHBITS); 1108 update_pci_byte(chip->pci, 1109 NVIDIA_HDA_ISTRM_COH, 1110 0x01, NVIDIA_HDA_ENABLE_COHBIT); 1111 update_pci_byte(chip->pci, 1112 NVIDIA_HDA_OSTRM_COH, 1113 0x01, NVIDIA_HDA_ENABLE_COHBIT); 1114 break; 1115 case AZX_DRIVER_SCH: 1116 case AZX_DRIVER_PCH: 1117 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); 1118 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) { 1119 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, 1120 snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP)); 1121 pci_read_config_word(chip->pci, 1122 INTEL_SCH_HDA_DEVC, &snoop); 1123 snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n", 1124 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) 1125 ? "Failed" : "OK"); 1126 } 1127 break; 1126 1128 1127 1129 } … … 1136 1138 static irqreturn_t azx_interrupt(int irq, void *dev_id) 1137 1139 { 1138 struct azx *chip = dev_id;1139 struct azx_dev *azx_dev;1140 u32 status;1141 u8 sd_status;1142 int i, ok;1143 1144 spin_lock(&chip->reg_lock);1145 1146 status = azx_readl(chip, INTSTS);1147 if (status == 0) {1148 spin_unlock(&chip->reg_lock);1149 return IRQ_NONE;1150 }1151 1152 for (i = 0; i < chip->num_streams; i++) {1153 azx_dev = &chip->azx_dev[i];1154 if (status & azx_dev->sd_int_sta_mask) {1155 sd_status = azx_sd_readb(azx_dev, SD_STS);1156 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);1157 if (!azx_dev->substream || !azx_dev->running ||1158 !(sd_status & SD_INT_COMPLETE))1159 continue;1160 /* check whether this IRQ is really acceptable */1161 ok = azx_position_ok(chip, azx_dev);1162 if (ok == 1) {1163 azx_dev->irq_pending = 0;1164 spin_unlock(&chip->reg_lock);1165 snd_pcm_period_elapsed(azx_dev->substream);1166 spin_lock(&chip->reg_lock);1167 } else if (ok == 0 && chip->bus && chip->bus->workq) {1168 /* bogus IRQ, process it later */1169 azx_dev->irq_pending = 1;1170 queue_work(chip->bus->workq,1171 &chip->irq_pending_work);1172 }1173 }1174 }1175 1176 /* clear rirb int */1177 status = azx_readb(chip, RIRBSTS);1178 if (status & RIRB_INT_MASK) {1179 if (status & RIRB_INT_RESPONSE) {1180 if (chip->driver_type == AZX_DRIVER_CTX)1181 udelay(80);1182 azx_update_rirb(chip);1183 }1184 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);1185 }1140 struct azx *chip = dev_id; 1141 struct azx_dev *azx_dev; 1142 u32 status; 1143 u8 sd_status; 1144 int i, ok; 1145 1146 spin_lock(&chip->reg_lock); 1147 1148 status = azx_readl(chip, INTSTS); 1149 if (status == 0) { 1150 spin_unlock(&chip->reg_lock); 1151 return IRQ_NONE; 1152 } 1153 1154 for (i = 0; i < chip->num_streams; i++) { 1155 azx_dev = &chip->azx_dev[i]; 1156 if (status & azx_dev->sd_int_sta_mask) { 1157 sd_status = azx_sd_readb(azx_dev, SD_STS); 1158 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); 1159 if (!azx_dev->substream || !azx_dev->running || 1160 !(sd_status & SD_INT_COMPLETE)) 1161 continue; 1162 /* check whether this IRQ is really acceptable */ 1163 ok = azx_position_ok(chip, azx_dev); 1164 if (ok == 1) { 1165 azx_dev->irq_pending = 0; 1166 spin_unlock(&chip->reg_lock); 1167 snd_pcm_period_elapsed(azx_dev->substream); 1168 spin_lock(&chip->reg_lock); 1169 } else if (ok == 0 && chip->bus && chip->bus->workq) { 1170 /* bogus IRQ, process it later */ 1171 azx_dev->irq_pending = 1; 1172 queue_work(chip->bus->workq, 1173 &chip->irq_pending_work); 1174 } 1175 } 1176 } 1177 1178 /* clear rirb int */ 1179 status = azx_readb(chip, RIRBSTS); 1180 if (status & RIRB_INT_MASK) { 1181 if (status & RIRB_INT_RESPONSE) { 1182 if (chip->driver_type == AZX_DRIVER_CTX) 1183 udelay(80); 1184 azx_update_rirb(chip); 1185 } 1186 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK); 1187 } 1186 1188 1187 1189 #if 0 1188 /* clear state status int */1189 if (azx_readb(chip, STATESTS) & 0x04)1190 azx_writeb(chip, STATESTS, 0x04);1190 /* clear state status int */ 1191 if (azx_readb(chip, STATESTS) & 0x04) 1192 azx_writeb(chip, STATESTS, 0x04); 1191 1193 #endif 1192 spin_unlock(&chip->reg_lock);1194 spin_unlock(&chip->reg_lock); 1193 1195 1194 1196 #ifdef TARGET_OS2 … … 1198 1200 #endif 1199 1201 1200 return IRQ_HANDLED;1202 return IRQ_HANDLED; 1201 1203 } 1202 1204 … … 1206 1208 */ 1207 1209 static int setup_bdle(struct snd_pcm_substream *substream, 1208 struct azx_dev *azx_dev, u32 **bdlp,1209 int ofs, int size, int with_ioc)1210 { 1211 u32 *bdl = *bdlp;1212 1213 while (size > 0) {1214 dma_addr_t addr;1215 int chunk;1216 1217 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)1218 return -EINVAL;1219 1220 addr = snd_pcm_sgbuf_get_addr(substream, ofs);1221 /* program the address field of the BDL entry */1222 bdl[0] = cpu_to_le32((u32)addr);1223 bdl[1] = cpu_to_le32(upper_32_bits(addr));1224 /* program the size field of the BDL entry */1225 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);1226 bdl[2] = cpu_to_le32(chunk);1227 /* program the IOC to enable interrupt1228 * only when the whole fragment is processed1229 */1230 size -= chunk;1231 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);1232 bdl += 4;1233 azx_dev->frags++;1234 ofs += chunk;1235 }1236 *bdlp = bdl;1237 return ofs;1210 struct azx_dev *azx_dev, u32 **bdlp, 1211 int ofs, int size, int with_ioc) 1212 { 1213 u32 *bdl = *bdlp; 1214 1215 while (size > 0) { 1216 dma_addr_t addr; 1217 int chunk; 1218 1219 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES) 1220 return -EINVAL; 1221 1222 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 1223 /* program the address field of the BDL entry */ 1224 bdl[0] = cpu_to_le32((u32)addr); 1225 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 1226 /* program the size field of the BDL entry */ 1227 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); 1228 bdl[2] = cpu_to_le32(chunk); 1229 /* program the IOC to enable interrupt 1230 * only when the whole fragment is processed 1231 */ 1232 size -= chunk; 1233 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01); 1234 bdl += 4; 1235 azx_dev->frags++; 1236 ofs += chunk; 1237 } 1238 *bdlp = bdl; 1239 return ofs; 1238 1240 } 1239 1241 … … 1242 1244 */ 1243 1245 static int azx_setup_periods(struct azx *chip, 1244 struct snd_pcm_substream *substream,1245 struct azx_dev *azx_dev)1246 { 1247 u32 *bdl;1248 int i, ofs, periods, period_bytes;1249 int pos_adj;1250 1251 /* reset BDL address */1252 azx_sd_writel(azx_dev, SD_BDLPL, 0);1253 azx_sd_writel(azx_dev, SD_BDLPU, 0);1254 1255 period_bytes = azx_dev->period_bytes;1256 periods = azx_dev->bufsize / period_bytes;1257 1258 /* program the initial BDL entries */1259 bdl = (u32 *)azx_dev->bdl.area;1260 ofs = 0;1261 azx_dev->frags = 0;1262 pos_adj = bdl_pos_adj[chip->dev_index];1263 if (pos_adj > 0) {1264 struct snd_pcm_runtime *runtime = substream->runtime;1265 int pos_align = pos_adj;1266 pos_adj = (pos_adj * runtime->rate + 47999) / 48000;1267 if (!pos_adj)1268 pos_adj = pos_align;1269 else1270 pos_adj = ((pos_adj + pos_align - 1) / pos_align) *1271 pos_align;1272 pos_adj = frames_to_bytes(runtime, pos_adj);1273 if (pos_adj >= period_bytes) {1274 snd_printk(KERN_WARNING SFX "Too big adjustment %d\n",1275 bdl_pos_adj[chip->dev_index]);1276 pos_adj = 0;1277 } else {1278 ofs = setup_bdle(substream, azx_dev,1279 &bdl, ofs, pos_adj,1280 !substream->runtime->no_period_wakeup);1281 if (ofs < 0)1282 goto error;1283 }1284 } else1285 pos_adj = 0;1286 for (i = 0; i < periods; i++) {1287 if (i == periods - 1 && pos_adj)1288 ofs = setup_bdle(substream, azx_dev, &bdl, ofs,1289 period_bytes - pos_adj, 0);1290 else1291 ofs = setup_bdle(substream, azx_dev, &bdl, ofs,1292 period_bytes,1293 !substream->runtime->no_period_wakeup);1294 if (ofs < 0)1295 goto error;1296 }1297 return 0;1246 struct snd_pcm_substream *substream, 1247 struct azx_dev *azx_dev) 1248 { 1249 u32 *bdl; 1250 int i, ofs, periods, period_bytes; 1251 int pos_adj; 1252 1253 /* reset BDL address */ 1254 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1255 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1256 1257 period_bytes = azx_dev->period_bytes; 1258 periods = azx_dev->bufsize / period_bytes; 1259 1260 /* program the initial BDL entries */ 1261 bdl = (u32 *)azx_dev->bdl.area; 1262 ofs = 0; 1263 azx_dev->frags = 0; 1264 pos_adj = bdl_pos_adj[chip->dev_index]; 1265 if (pos_adj > 0) { 1266 struct snd_pcm_runtime *runtime = substream->runtime; 1267 int pos_align = pos_adj; 1268 pos_adj = (pos_adj * runtime->rate + 47999) / 48000; 1269 if (!pos_adj) 1270 pos_adj = pos_align; 1271 else 1272 pos_adj = ((pos_adj + pos_align - 1) / pos_align) * 1273 pos_align; 1274 pos_adj = frames_to_bytes(runtime, pos_adj); 1275 if (pos_adj >= period_bytes) { 1276 snd_printk(KERN_WARNING SFX "Too big adjustment %d\n", 1277 bdl_pos_adj[chip->dev_index]); 1278 pos_adj = 0; 1279 } else { 1280 ofs = setup_bdle(substream, azx_dev, 1281 &bdl, ofs, pos_adj, 1282 !substream->runtime->no_period_wakeup); 1283 if (ofs < 0) 1284 goto error; 1285 } 1286 } else 1287 pos_adj = 0; 1288 for (i = 0; i < periods; i++) { 1289 if (i == periods - 1 && pos_adj) 1290 ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1291 period_bytes - pos_adj, 0); 1292 else 1293 ofs = setup_bdle(substream, azx_dev, &bdl, ofs, 1294 period_bytes, 1295 !substream->runtime->no_period_wakeup); 1296 if (ofs < 0) 1297 goto error; 1298 } 1299 return 0; 1298 1300 1299 1301 error: 1300 snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",1301 azx_dev->bufsize, period_bytes);1302 return -EINVAL;1302 snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n", 1303 azx_dev->bufsize, period_bytes); 1304 return -EINVAL; 1303 1305 } 1304 1306 … … 1306 1308 static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev) 1307 1309 { 1308 unsigned char val;1309 int timeout;1310 1311 azx_stream_clear(chip, azx_dev);1312 1313 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |1314 SD_CTL_STREAM_RESET);1315 udelay(3);1316 timeout = 300;1317 while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&1318 --timeout)1319 ;1320 val &= ~SD_CTL_STREAM_RESET;1321 azx_sd_writeb(azx_dev, SD_CTL, val);1322 udelay(3);1323 1324 timeout = 300;1325 /* waiting for hardware to report that the stream is out of reset */1326 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&1327 --timeout)1328 ;1329 1330 /* reset first position - may not be synced with hw at this time */1331 *azx_dev->posbuf = 0;1310 unsigned char val; 1311 int timeout; 1312 1313 azx_stream_clear(chip, azx_dev); 1314 1315 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) | 1316 SD_CTL_STREAM_RESET); 1317 udelay(3); 1318 timeout = 300; 1319 while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) && 1320 --timeout) 1321 ; 1322 val &= ~SD_CTL_STREAM_RESET; 1323 azx_sd_writeb(azx_dev, SD_CTL, val); 1324 udelay(3); 1325 1326 timeout = 300; 1327 /* waiting for hardware to report that the stream is out of reset */ 1328 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) && 1329 --timeout) 1330 ; 1331 1332 /* reset first position - may not be synced with hw at this time */ 1333 *azx_dev->posbuf = 0; 1332 1334 } 1333 1335 … … 1337 1339 static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) 1338 1340 { 1339 /* make sure the run bit is zero for SD */1340 azx_stream_clear(chip, azx_dev);1341 /* program the stream_tag */1342 azx_sd_writel(azx_dev, SD_CTL,1343 (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|1344 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT));1345 1346 /* program the length of samples in cyclic buffer */1347 azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);1348 1349 /* program the stream format */1350 /* this value needs to be the same as the one programmed */1351 azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);1352 1353 /* program the stream LVI (last valid index) of the BDL */1354 azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);1355 1356 /* program the BDL address */1357 /* lower BDL address */1358 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);1359 /* upper BDL address */1360 azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));1361 1362 /* enable the position buffer */1363 if (chip->position_fix[0] != POS_FIX_LPIB ||1364 chip->position_fix[1] != POS_FIX_LPIB) {1365 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))1366 azx_writel(chip, DPLBASE,1367 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);1368 }1369 1370 /* set the interrupt enable bits in the descriptor control register */1371 azx_sd_writel(azx_dev, SD_CTL,1372 azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);1373 1374 return 0;1341 /* make sure the run bit is zero for SD */ 1342 azx_stream_clear(chip, azx_dev); 1343 /* program the stream_tag */ 1344 azx_sd_writel(azx_dev, SD_CTL, 1345 (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)| 1346 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT)); 1347 1348 /* program the length of samples in cyclic buffer */ 1349 azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize); 1350 1351 /* program the stream format */ 1352 /* this value needs to be the same as the one programmed */ 1353 azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val); 1354 1355 /* program the stream LVI (last valid index) of the BDL */ 1356 azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1); 1357 1358 /* program the BDL address */ 1359 /* lower BDL address */ 1360 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr); 1361 /* upper BDL address */ 1362 azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr)); 1363 1364 /* enable the position buffer */ 1365 if (chip->position_fix[0] != POS_FIX_LPIB || 1366 chip->position_fix[1] != POS_FIX_LPIB) { 1367 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) 1368 azx_writel(chip, DPLBASE, 1369 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE); 1370 } 1371 1372 /* set the interrupt enable bits in the descriptor control register */ 1373 azx_sd_writel(azx_dev, SD_CTL, 1374 azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK); 1375 1376 return 0; 1375 1377 } 1376 1378 … … 1380 1382 static int probe_codec(struct azx *chip, int addr) 1381 1383 { 1382 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |1383 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;1384 unsigned int res;1385 1386 mutex_lock(&chip->bus->cmd_mutex);1387 chip->probing = 1;1388 azx_send_cmd(chip->bus, cmd);1389 res = azx_get_response(chip->bus, addr);1390 chip->probing = 0;1391 mutex_unlock(&chip->bus->cmd_mutex);1392 if (res == -1)1393 return -EIO;1394 snd_printdd(SFX "codec #%d probed OK\n", addr);1395 return 0;1384 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | 1385 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; 1386 unsigned int res; 1387 1388 mutex_lock(&chip->bus->cmd_mutex); 1389 chip->probing = 1; 1390 azx_send_cmd(chip->bus, cmd); 1391 res = azx_get_response(chip->bus, addr); 1392 chip->probing = 0; 1393 mutex_unlock(&chip->bus->cmd_mutex); 1394 if (res == -1) 1395 return -EIO; 1396 snd_printdd(SFX "codec #%d probed OK\n", addr); 1397 return 0; 1396 1398 } 1397 1399 1398 1400 static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, 1399 struct hda_pcm *cpcm);1401 struct hda_pcm *cpcm); 1400 1402 static void azx_stop_chip(struct azx *chip); 1401 1403 1402 1404 static void azx_bus_reset(struct hda_bus *bus) 1403 1405 { 1404 struct azx *chip = bus->private_data;1405 1406 bus->in_reset = 1;1407 azx_stop_chip(chip);1408 azx_init_chip(chip, 1);1406 struct azx *chip = bus->private_data; 1407 1408 bus->in_reset = 1; 1409 azx_stop_chip(chip); 1410 azx_init_chip(chip, 1); 1409 1411 #ifdef CONFIG_PM 1410 if (chip->initialized) {1411 int i;1412 1413 for (i = 0; i < HDA_MAX_PCMS; i++)1414 snd_pcm_suspend_all(chip->pcm[i]);1415 snd_hda_suspend(chip->bus);1416 snd_hda_resume(chip->bus);1417 }1412 if (chip->initialized) { 1413 int i; 1414 1415 for (i = 0; i < HDA_MAX_PCMS; i++) 1416 snd_pcm_suspend_all(chip->pcm[i]); 1417 snd_hda_suspend(chip->bus); 1418 snd_hda_resume(chip->bus); 1419 } 1418 1420 #endif 1419 bus->in_reset = 0;1421 bus->in_reset = 0; 1420 1422 } 1421 1423 … … 1426 1428 /* number of codec slots for each chipset: 0 = default slots (i.e. 4) */ 1427 1429 static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = { 1428 [AZX_DRIVER_NVIDIA] = 8,1429 [AZX_DRIVER_TERA] = 1,1430 [AZX_DRIVER_NVIDIA] = 8, 1431 [AZX_DRIVER_TERA] = 1, 1430 1432 }; 1431 1433 1432 1434 static int __devinit azx_codec_create(struct azx *chip, const char *model) 1433 1435 { 1434 struct hda_bus_template bus_temp;1435 int c, codecs, err;1436 int max_slots;1437 1438 memset(&bus_temp, 0, sizeof(bus_temp));1439 bus_temp.private_data = chip;1440 bus_temp.modelname = model;1441 bus_temp.pci = chip->pci;1442 bus_temp.ops.command = azx_send_cmd;1443 bus_temp.ops.get_response = azx_get_response;1444 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;1445 bus_temp.ops.bus_reset = azx_bus_reset;1436 struct hda_bus_template bus_temp; 1437 int c, codecs, err; 1438 int max_slots; 1439 1440 memset(&bus_temp, 0, sizeof(bus_temp)); 1441 bus_temp.private_data = chip; 1442 bus_temp.modelname = model; 1443 bus_temp.pci = chip->pci; 1444 bus_temp.ops.command = azx_send_cmd; 1445 bus_temp.ops.get_response = azx_get_response; 1446 bus_temp.ops.attach_pcm = azx_attach_pcm_stream; 1447 bus_temp.ops.bus_reset = azx_bus_reset; 1446 1448 #ifdef CONFIG_SND_HDA_POWER_SAVE 1447 bus_temp.power_save = &power_save;1448 bus_temp.ops.pm_notify = azx_power_notify;1449 bus_temp.power_save = &power_save; 1450 bus_temp.ops.pm_notify = azx_power_notify; 1449 1451 #endif 1450 1452 1451 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);1452 if (err < 0)1453 return err;1454 1455 if (chip->driver_type == AZX_DRIVER_NVIDIA)1456 chip->bus->needs_damn_long_delay = 1;1457 1458 codecs = 0;1459 max_slots = azx_max_codecs[chip->driver_type];1460 if (!max_slots)1461 max_slots = AZX_DEFAULT_CODECS;1462 1463 /* First try to probe all given codec slots */1464 for (c = 0; c < max_slots; c++) {1465 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {1466 if (probe_codec(chip, c) < 0) {1467 /* Some BIOSen give you wrong codec addresses1468 * that don't exist1469 */1470 snd_printk(KERN_WARNING SFX1471 "Codec #%d probe error; "1472 "disabling it...\n", c);1473 chip->codec_mask &= ~(1 << c);1474 /* More badly, accessing to a non-existing1475 * codec often screws up the controller chip,1476 * and disturbs the further communications.1477 * Thus if an error occurs during probing,1478 * better to reset the controller chip to1479 * get back to the sanity state.1480 */1481 azx_stop_chip(chip);1482 azx_init_chip(chip, 1);1483 }1484 }1485 }1486 1487 /* Then create codec instances */1488 for (c = 0; c < max_slots; c++) {1489 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {1490 struct hda_codec *codec;1491 err = snd_hda_codec_new(chip->bus, c, &codec);1492 if (err < 0)1493 continue;1494 codec->beep_mode = chip->beep_mode;1495 codecs++;1496 }1497 }1498 if (!codecs) {1499 snd_printk(KERN_ERR SFX "no codecs initialized\n");1500 return -ENXIO;1501 }1502 return 0;1453 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus); 1454 if (err < 0) 1455 return err; 1456 1457 if (chip->driver_type == AZX_DRIVER_NVIDIA) 1458 chip->bus->needs_damn_long_delay = 1; 1459 1460 codecs = 0; 1461 max_slots = azx_max_codecs[chip->driver_type]; 1462 if (!max_slots) 1463 max_slots = AZX_DEFAULT_CODECS; 1464 1465 /* First try to probe all given codec slots */ 1466 for (c = 0; c < max_slots; c++) { 1467 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { 1468 if (probe_codec(chip, c) < 0) { 1469 /* Some BIOSen give you wrong codec addresses 1470 * that don't exist 1471 */ 1472 snd_printk(KERN_WARNING SFX 1473 "Codec #%d probe error; " 1474 "disabling it...\n", c); 1475 chip->codec_mask &= ~(1 << c); 1476 /* More badly, accessing to a non-existing 1477 * codec often screws up the controller chip, 1478 * and disturbs the further communications. 1479 * Thus if an error occurs during probing, 1480 * better to reset the controller chip to 1481 * get back to the sanity state. 1482 */ 1483 azx_stop_chip(chip); 1484 azx_init_chip(chip, 1); 1485 } 1486 } 1487 } 1488 1489 /* Then create codec instances */ 1490 for (c = 0; c < max_slots; c++) { 1491 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) { 1492 struct hda_codec *codec; 1493 err = snd_hda_codec_new(chip->bus, c, &codec); 1494 if (err < 0) 1495 continue; 1496 codec->beep_mode = chip->beep_mode; 1497 codecs++; 1498 } 1499 } 1500 if (!codecs) { 1501 snd_printk(KERN_ERR SFX "no codecs initialized\n"); 1502 return -ENXIO; 1503 } 1504 return 0; 1503 1505 } 1504 1506 … … 1506 1508 static int __devinit azx_codec_configure(struct azx *chip) 1507 1509 { 1508 struct hda_codec *codec;1509 list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {1510 snd_hda_codec_configure(codec);1511 }1512 return 0;1510 struct hda_codec *codec; 1511 list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) { 1512 snd_hda_codec_configure(codec); 1513 } 1514 return 0; 1513 1515 } 1514 1516 … … 1522 1524 azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream) 1523 1525 { 1524 int dev, i, nums;1525 struct azx_dev *res = NULL;1526 1527 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {1528 dev = chip->playback_index_offset;1529 nums = chip->playback_streams;1530 } else {1531 dev = chip->capture_index_offset;1532 nums = chip->capture_streams;1533 }1534 for (i = 0; i < nums; i++, dev++)1535 if (!chip->azx_dev[dev].opened) {1536 res = &chip->azx_dev[dev];1537 if (res->device == substream->pcm->device)1538 break;1539 }1540 if (res) {1541 res->opened = 1;1542 res->device = substream->pcm->device;1543 }1544 return res;1526 int dev, i, nums; 1527 struct azx_dev *res = NULL; 1528 1529 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1530 dev = chip->playback_index_offset; 1531 nums = chip->playback_streams; 1532 } else { 1533 dev = chip->capture_index_offset; 1534 nums = chip->capture_streams; 1535 } 1536 for (i = 0; i < nums; i++, dev++) 1537 if (!chip->azx_dev[dev].opened) { 1538 res = &chip->azx_dev[dev]; 1539 if (res->device == substream->pcm->device) 1540 break; 1541 } 1542 if (res) { 1543 res->opened = 1; 1544 res->device = substream->pcm->device; 1545 } 1546 return res; 1545 1547 } 1546 1548 … … 1548 1550 static inline void azx_release_device(struct azx_dev *azx_dev) 1549 1551 { 1550 azx_dev->opened = 0;1552 azx_dev->opened = 0; 1551 1553 } 1552 1554 1553 1555 static struct snd_pcm_hardware azx_pcm_hw = { 1554 .info =(SNDRV_PCM_INFO_MMAP |1555 SNDRV_PCM_INFO_INTERLEAVED |1556 SNDRV_PCM_INFO_BLOCK_TRANSFER |1557 SNDRV_PCM_INFO_MMAP_VALID |1558 /* No full-resume yet implemented */1559 /* SNDRV_PCM_INFO_RESUME |*/1560 SNDRV_PCM_INFO_PAUSE |1561 SNDRV_PCM_INFO_SYNC_START |1562 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),1563 .formats =SNDRV_PCM_FMTBIT_S16_LE,1564 .rates =SNDRV_PCM_RATE_48000,1565 .rate_min =48000,1566 .rate_max =48000,1567 .channels_min =2,1568 .channels_max =2,1569 .buffer_bytes_max =AZX_MAX_BUF_SIZE,1570 .period_bytes_min =128,1571 .period_bytes_max =AZX_MAX_BUF_SIZE / 2,1572 .periods_min =2,1573 .periods_max =AZX_MAX_FRAG,1574 .fifo_size =0,1556 .info = (SNDRV_PCM_INFO_MMAP | 1557 SNDRV_PCM_INFO_INTERLEAVED | 1558 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1559 SNDRV_PCM_INFO_MMAP_VALID | 1560 /* No full-resume yet implemented */ 1561 /* SNDRV_PCM_INFO_RESUME |*/ 1562 SNDRV_PCM_INFO_PAUSE | 1563 SNDRV_PCM_INFO_SYNC_START | 1564 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP), 1565 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1566 .rates = SNDRV_PCM_RATE_48000, 1567 .rate_min = 48000, 1568 .rate_max = 48000, 1569 .channels_min = 2, 1570 .channels_max = 2, 1571 .buffer_bytes_max = AZX_MAX_BUF_SIZE, 1572 .period_bytes_min = 128, 1573 .period_bytes_max = AZX_MAX_BUF_SIZE / 2, 1574 .periods_min = 2, 1575 .periods_max = AZX_MAX_FRAG, 1576 .fifo_size = 0, 1575 1577 }; 1576 1578 1577 1579 struct azx_pcm { 1578 struct azx *chip;1579 struct hda_codec *codec;1580 struct hda_pcm_stream *hinfo[2];1580 struct azx *chip; 1581 struct hda_codec *codec; 1582 struct hda_pcm_stream *hinfo[2]; 1581 1583 }; 1582 1584 1583 1585 static int azx_pcm_open(struct snd_pcm_substream *substream) 1584 1586 { 1585 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1586 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];1587 struct azx *chip = apcm->chip;1588 struct azx_dev *azx_dev;1589 struct snd_pcm_runtime *runtime = substream->runtime;1590 unsigned long flags;1591 int err;1592 1593 mutex_lock(&chip->open_mutex);1594 azx_dev = azx_assign_device(chip, substream);1595 if (azx_dev == NULL) {1596 mutex_unlock(&chip->open_mutex);1597 return -EBUSY;1598 }1599 runtime->hw = azx_pcm_hw;1600 runtime->hw.channels_min = hinfo->channels_min;1601 runtime->hw.channels_max = hinfo->channels_max;1602 runtime->hw.formats = hinfo->formats;1603 runtime->hw.rates = hinfo->rates;1604 snd_pcm_limit_hw_rates(runtime);1605 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);1606 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,1607 128);1608 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,1609 128);1610 snd_hda_power_up(apcm->codec);1611 err = hinfo->ops.open(hinfo, apcm->codec, substream);1612 if (err < 0) {1613 azx_release_device(azx_dev);1614 snd_hda_power_down(apcm->codec);1615 mutex_unlock(&chip->open_mutex);1616 return err;1617 }1618 snd_pcm_limit_hw_rates(runtime);1619 /* sanity check */1620 if (snd_BUG_ON(!runtime->hw.channels_min) ||1621 snd_BUG_ON(!runtime->hw.channels_max) ||1622 snd_BUG_ON(!runtime->hw.formats) ||1623 snd_BUG_ON(!runtime->hw.rates)) {1624 azx_release_device(azx_dev);1625 hinfo->ops.close(hinfo, apcm->codec, substream);1626 snd_hda_power_down(apcm->codec);1627 mutex_unlock(&chip->open_mutex);1628 return -EINVAL;1629 }1630 spin_lock_irqsave(&chip->reg_lock, flags);1631 azx_dev->substream = substream;1632 azx_dev->running = 0;1633 spin_unlock_irqrestore(&chip->reg_lock, flags);1634 1635 runtime->private_data = azx_dev;1636 snd_pcm_set_sync(substream);1637 mutex_unlock(&chip->open_mutex);1638 return 0;1587 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1588 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1589 struct azx *chip = apcm->chip; 1590 struct azx_dev *azx_dev; 1591 struct snd_pcm_runtime *runtime = substream->runtime; 1592 unsigned long flags; 1593 int err; 1594 1595 mutex_lock(&chip->open_mutex); 1596 azx_dev = azx_assign_device(chip, substream); 1597 if (azx_dev == NULL) { 1598 mutex_unlock(&chip->open_mutex); 1599 return -EBUSY; 1600 } 1601 runtime->hw = azx_pcm_hw; 1602 runtime->hw.channels_min = hinfo->channels_min; 1603 runtime->hw.channels_max = hinfo->channels_max; 1604 runtime->hw.formats = hinfo->formats; 1605 runtime->hw.rates = hinfo->rates; 1606 snd_pcm_limit_hw_rates(runtime); 1607 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 1608 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1609 128); 1610 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 1611 128); 1612 snd_hda_power_up(apcm->codec); 1613 err = hinfo->ops.open(hinfo, apcm->codec, substream); 1614 if (err < 0) { 1615 azx_release_device(azx_dev); 1616 snd_hda_power_down(apcm->codec); 1617 mutex_unlock(&chip->open_mutex); 1618 return err; 1619 } 1620 snd_pcm_limit_hw_rates(runtime); 1621 /* sanity check */ 1622 if (snd_BUG_ON(!runtime->hw.channels_min) || 1623 snd_BUG_ON(!runtime->hw.channels_max) || 1624 snd_BUG_ON(!runtime->hw.formats) || 1625 snd_BUG_ON(!runtime->hw.rates)) { 1626 azx_release_device(azx_dev); 1627 hinfo->ops.close(hinfo, apcm->codec, substream); 1628 snd_hda_power_down(apcm->codec); 1629 mutex_unlock(&chip->open_mutex); 1630 return -EINVAL; 1631 } 1632 spin_lock_irqsave(&chip->reg_lock, flags); 1633 azx_dev->substream = substream; 1634 azx_dev->running = 0; 1635 spin_unlock_irqrestore(&chip->reg_lock, flags); 1636 1637 runtime->private_data = azx_dev; 1638 snd_pcm_set_sync(substream); 1639 mutex_unlock(&chip->open_mutex); 1640 return 0; 1639 1641 } 1640 1642 1641 1643 static int azx_pcm_close(struct snd_pcm_substream *substream) 1642 1644 { 1643 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1644 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];1645 struct azx *chip = apcm->chip;1646 struct azx_dev *azx_dev = get_azx_dev(substream);1647 unsigned long flags;1648 1649 mutex_lock(&chip->open_mutex);1650 spin_lock_irqsave(&chip->reg_lock, flags);1651 azx_dev->substream = NULL;1652 azx_dev->running = 0;1653 spin_unlock_irqrestore(&chip->reg_lock, flags);1654 azx_release_device(azx_dev);1655 hinfo->ops.close(hinfo, apcm->codec, substream);1656 snd_hda_power_down(apcm->codec);1657 mutex_unlock(&chip->open_mutex);1658 return 0;1645 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1646 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1647 struct azx *chip = apcm->chip; 1648 struct azx_dev *azx_dev = get_azx_dev(substream); 1649 unsigned long flags; 1650 1651 mutex_lock(&chip->open_mutex); 1652 spin_lock_irqsave(&chip->reg_lock, flags); 1653 azx_dev->substream = NULL; 1654 azx_dev->running = 0; 1655 spin_unlock_irqrestore(&chip->reg_lock, flags); 1656 azx_release_device(azx_dev); 1657 hinfo->ops.close(hinfo, apcm->codec, substream); 1658 snd_hda_power_down(apcm->codec); 1659 mutex_unlock(&chip->open_mutex); 1660 return 0; 1659 1661 } 1660 1662 1661 1663 static int azx_pcm_hw_params(struct snd_pcm_substream *substream, 1662 struct snd_pcm_hw_params *hw_params)1663 { 1664 struct azx_dev *azx_dev = get_azx_dev(substream);1665 1666 azx_dev->bufsize = 0;1667 azx_dev->period_bytes = 0;1668 azx_dev->format_val = 0;1669 return snd_pcm_lib_malloc_pages(substream,1670 params_buffer_bytes(hw_params));1664 struct snd_pcm_hw_params *hw_params) 1665 { 1666 struct azx_dev *azx_dev = get_azx_dev(substream); 1667 1668 azx_dev->bufsize = 0; 1669 azx_dev->period_bytes = 0; 1670 azx_dev->format_val = 0; 1671 return snd_pcm_lib_malloc_pages(substream, 1672 params_buffer_bytes(hw_params)); 1671 1673 } 1672 1674 1673 1675 static int azx_pcm_hw_free(struct snd_pcm_substream *substream) 1674 1676 { 1675 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1676 struct azx_dev *azx_dev = get_azx_dev(substream);1677 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];1678 1679 /* reset BDL address */1680 azx_sd_writel(azx_dev, SD_BDLPL, 0);1681 azx_sd_writel(azx_dev, SD_BDLPU, 0);1682 azx_sd_writel(azx_dev, SD_CTL, 0);1683 azx_dev->bufsize = 0;1684 azx_dev->period_bytes = 0;1685 azx_dev->format_val = 0;1686 1687 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);1688 1689 return snd_pcm_lib_free_pages(substream);1677 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1678 struct azx_dev *azx_dev = get_azx_dev(substream); 1679 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1680 1681 /* reset BDL address */ 1682 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1683 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1684 azx_sd_writel(azx_dev, SD_CTL, 0); 1685 azx_dev->bufsize = 0; 1686 azx_dev->period_bytes = 0; 1687 azx_dev->format_val = 0; 1688 1689 snd_hda_codec_cleanup(apcm->codec, hinfo, substream); 1690 1691 return snd_pcm_lib_free_pages(substream); 1690 1692 } 1691 1693 1692 1694 static int azx_pcm_prepare(struct snd_pcm_substream *substream) 1693 1695 { 1694 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1695 struct azx *chip = apcm->chip;1696 struct azx_dev *azx_dev = get_azx_dev(substream);1697 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];1698 struct snd_pcm_runtime *runtime = substream->runtime;1699 unsigned int bufsize, period_bytes, format_val, stream_tag;1700 int err;1701 1702 azx_stream_reset(chip, azx_dev);1703 format_val = snd_hda_calc_stream_format(runtime->rate,1704 runtime->channels,1705 runtime->format,1706 hinfo->maxbps,1707 apcm->codec->spdif_ctls);1708 if (!format_val) {1709 snd_printk(KERN_ERR SFX1710 "invalid format_val, rate=%d, ch=%d, format=%d\n",1711 runtime->rate, runtime->channels, runtime->format);1712 return -EINVAL;1713 }1714 1715 bufsize = snd_pcm_lib_buffer_bytes(substream);1716 period_bytes = snd_pcm_lib_period_bytes(substream);1717 1718 snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",1719 bufsize, format_val);1720 1721 if (bufsize != azx_dev->bufsize ||1722 period_bytes != azx_dev->period_bytes ||1723 format_val != azx_dev->format_val) {1724 azx_dev->bufsize = bufsize;1725 azx_dev->period_bytes = period_bytes;1726 azx_dev->format_val = format_val;1727 err = azx_setup_periods(chip, substream, azx_dev);1728 if (err < 0)1729 return err;1730 }1731 1732 /* wallclk has 24Mhz clock source */1733 azx_dev->period_wallclk = (((runtime->period_size * 24000) /1734 runtime->rate) * 1000);1735 azx_setup_controller(chip, azx_dev);1736 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)1737 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;1738 else1739 azx_dev->fifo_size = 0;1740 1741 stream_tag = azx_dev->stream_tag;1742 /* CA-IBG chips need the playback stream starting from 1 */1743 if (chip->driver_type == AZX_DRIVER_CTX &&1744 stream_tag > chip->capture_streams)1745 stream_tag -= chip->capture_streams;1746 return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,1747 azx_dev->format_val, substream);1696 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1697 struct azx *chip = apcm->chip; 1698 struct azx_dev *azx_dev = get_azx_dev(substream); 1699 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1700 struct snd_pcm_runtime *runtime = substream->runtime; 1701 unsigned int bufsize, period_bytes, format_val, stream_tag; 1702 int err; 1703 1704 azx_stream_reset(chip, azx_dev); 1705 format_val = snd_hda_calc_stream_format(runtime->rate, 1706 runtime->channels, 1707 runtime->format, 1708 hinfo->maxbps, 1709 apcm->codec->spdif_ctls); 1710 if (!format_val) { 1711 snd_printk(KERN_ERR SFX 1712 "invalid format_val, rate=%d, ch=%d, format=%d\n", 1713 runtime->rate, runtime->channels, runtime->format); 1714 return -EINVAL; 1715 } 1716 1717 bufsize = snd_pcm_lib_buffer_bytes(substream); 1718 period_bytes = snd_pcm_lib_period_bytes(substream); 1719 1720 snd_printdd(SFX "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n", 1721 bufsize, format_val); 1722 1723 if (bufsize != azx_dev->bufsize || 1724 period_bytes != azx_dev->period_bytes || 1725 format_val != azx_dev->format_val) { 1726 azx_dev->bufsize = bufsize; 1727 azx_dev->period_bytes = period_bytes; 1728 azx_dev->format_val = format_val; 1729 err = azx_setup_periods(chip, substream, azx_dev); 1730 if (err < 0) 1731 return err; 1732 } 1733 1734 /* wallclk has 24Mhz clock source */ 1735 azx_dev->period_wallclk = (((runtime->period_size * 24000) / 1736 runtime->rate) * 1000); 1737 azx_setup_controller(chip, azx_dev); 1738 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1739 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1740 else 1741 azx_dev->fifo_size = 0; 1742 1743 stream_tag = azx_dev->stream_tag; 1744 /* CA-IBG chips need the playback stream starting from 1 */ 1745 if (chip->driver_type == AZX_DRIVER_CTX && 1746 stream_tag > chip->capture_streams) 1747 stream_tag -= chip->capture_streams; 1748 return snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag, 1749 azx_dev->format_val, substream); 1748 1750 } 1749 1751 1750 1752 static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1751 1753 { 1752 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1753 struct azx *chip = apcm->chip;1754 struct azx_dev *azx_dev;1755 struct snd_pcm_substream *s;1756 int rstart = 0, start, nsync = 0, sbits = 0;1757 int nwait, timeout;1758 1759 switch (cmd) {1760 case SNDRV_PCM_TRIGGER_START:1761 rstart = 1;1762 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:1763 case SNDRV_PCM_TRIGGER_RESUME:1764 start = 1;1765 break;1766 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:1767 case SNDRV_PCM_TRIGGER_SUSPEND:1768 case SNDRV_PCM_TRIGGER_STOP:1769 start = 0;1770 break;1771 default:1772 return -EINVAL;1773 }1774 1775 snd_pcm_group_for_each_entry(s, substream) {1776 if (s->pcm->card != substream->pcm->card)1777 continue;1778 azx_dev = get_azx_dev(s);1779 sbits |= 1 << azx_dev->index;1780 nsync++;1781 snd_pcm_trigger_done(s, substream);1782 }1783 1784 spin_lock(&chip->reg_lock);1785 if (nsync > 1) {1786 /* first, set SYNC bits of corresponding streams */1787 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);1788 }1789 snd_pcm_group_for_each_entry(s, substream) {1790 if (s->pcm->card != substream->pcm->card)1791 continue;1792 azx_dev = get_azx_dev(s);1793 if (start) {1794 azx_dev->start_wallclk = azx_readl(chip, WALLCLK);1795 if (!rstart)1796 azx_dev->start_wallclk -=1797 azx_dev->period_wallclk;1798 azx_stream_start(chip, azx_dev);1799 } else {1800 azx_stream_stop(chip, azx_dev);1801 }1802 azx_dev->running = start;1803 }1804 spin_unlock(&chip->reg_lock);1805 if (start) {1806 if (nsync == 1)1807 return 0;1808 /* wait until all FIFOs get ready */1809 for (timeout = 5000; timeout; timeout--) {1810 nwait = 0;1811 snd_pcm_group_for_each_entry(s, substream) {1812 if (s->pcm->card != substream->pcm->card)1813 continue;1814 azx_dev = get_azx_dev(s);1815 if (!(azx_sd_readb(azx_dev, SD_STS) &1816 SD_STS_FIFO_READY))1817 nwait++;1818 }1819 if (!nwait)1820 break;1821 cpu_relax();1822 }1823 } else {1824 /* wait until all RUN bits are cleared */1825 for (timeout = 5000; timeout; timeout--) {1826 nwait = 0;1827 snd_pcm_group_for_each_entry(s, substream) {1828 if (s->pcm->card != substream->pcm->card)1829 continue;1830 azx_dev = get_azx_dev(s);1831 if (azx_sd_readb(azx_dev, SD_CTL) &1832 SD_CTL_DMA_START)1833 nwait++;1834 }1835 if (!nwait)1836 break;1837 cpu_relax();1838 }1839 }1840 if (nsync > 1) {1841 spin_lock(&chip->reg_lock);1842 /* reset SYNC bits */1843 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);1844 spin_unlock(&chip->reg_lock);1845 }1846 return 0;1754 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1755 struct azx *chip = apcm->chip; 1756 struct azx_dev *azx_dev; 1757 struct snd_pcm_substream *s; 1758 int rstart = 0, start, nsync = 0, sbits = 0; 1759 int nwait, timeout; 1760 1761 switch (cmd) { 1762 case SNDRV_PCM_TRIGGER_START: 1763 rstart = 1; 1764 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1765 case SNDRV_PCM_TRIGGER_RESUME: 1766 start = 1; 1767 break; 1768 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1769 case SNDRV_PCM_TRIGGER_SUSPEND: 1770 case SNDRV_PCM_TRIGGER_STOP: 1771 start = 0; 1772 break; 1773 default: 1774 return -EINVAL; 1775 } 1776 1777 snd_pcm_group_for_each_entry(s, substream) { 1778 if (s->pcm->card != substream->pcm->card) 1779 continue; 1780 azx_dev = get_azx_dev(s); 1781 sbits |= 1 << azx_dev->index; 1782 nsync++; 1783 snd_pcm_trigger_done(s, substream); 1784 } 1785 1786 spin_lock(&chip->reg_lock); 1787 if (nsync > 1) { 1788 /* first, set SYNC bits of corresponding streams */ 1789 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits); 1790 } 1791 snd_pcm_group_for_each_entry(s, substream) { 1792 if (s->pcm->card != substream->pcm->card) 1793 continue; 1794 azx_dev = get_azx_dev(s); 1795 if (start) { 1796 azx_dev->start_wallclk = azx_readl(chip, WALLCLK); 1797 if (!rstart) 1798 azx_dev->start_wallclk -= 1799 azx_dev->period_wallclk; 1800 azx_stream_start(chip, azx_dev); 1801 } else { 1802 azx_stream_stop(chip, azx_dev); 1803 } 1804 azx_dev->running = start; 1805 } 1806 spin_unlock(&chip->reg_lock); 1807 if (start) { 1808 if (nsync == 1) 1809 return 0; 1810 /* wait until all FIFOs get ready */ 1811 for (timeout = 5000; timeout; timeout--) { 1812 nwait = 0; 1813 snd_pcm_group_for_each_entry(s, substream) { 1814 if (s->pcm->card != substream->pcm->card) 1815 continue; 1816 azx_dev = get_azx_dev(s); 1817 if (!(azx_sd_readb(azx_dev, SD_STS) & 1818 SD_STS_FIFO_READY)) 1819 nwait++; 1820 } 1821 if (!nwait) 1822 break; 1823 cpu_relax(); 1824 } 1825 } else { 1826 /* wait until all RUN bits are cleared */ 1827 for (timeout = 5000; timeout; timeout--) { 1828 nwait = 0; 1829 snd_pcm_group_for_each_entry(s, substream) { 1830 if (s->pcm->card != substream->pcm->card) 1831 continue; 1832 azx_dev = get_azx_dev(s); 1833 if (azx_sd_readb(azx_dev, SD_CTL) & 1834 SD_CTL_DMA_START) 1835 nwait++; 1836 } 1837 if (!nwait) 1838 break; 1839 cpu_relax(); 1840 } 1841 } 1842 if (nsync > 1) { 1843 spin_lock(&chip->reg_lock); 1844 /* reset SYNC bits */ 1845 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits); 1846 spin_unlock(&chip->reg_lock); 1847 } 1848 return 0; 1847 1849 } 1848 1850 1849 1851 /* get the current DMA position with correction on VIA chips */ 1850 1852 static unsigned int azx_via_get_position(struct azx *chip, 1851 struct azx_dev *azx_dev)1852 { 1853 unsigned int link_pos, mini_pos, bound_pos;1854 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;1855 unsigned int fifo_size;1856 1857 link_pos = azx_sd_readl(azx_dev, SD_LPIB);1858 if (azx_dev->index >= 4) {1859 /* Playback, no problem using link position */1860 return link_pos;1861 }1862 1863 /* Capture */1864 /* For new chipset,1865 * use mod to get the DMA position just like old chipset1866 */1867 mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);1868 mod_dma_pos %= azx_dev->period_bytes;1869 1870 /* azx_dev->fifo_size can't get FIFO size of in stream.1871 * Get from base address + offset.1872 */1873 fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);1874 1875 if (azx_dev->insufficient) {1876 /* Link position never gather than FIFO size */1877 if (link_pos <= fifo_size)1878 return 0;1879 1880 azx_dev->insufficient = 0;1881 }1882 1883 if (link_pos <= fifo_size)1884 mini_pos = azx_dev->bufsize + link_pos - fifo_size;1885 else1886 mini_pos = link_pos - fifo_size;1887 1888 /* Find nearest previous boudary */1889 mod_mini_pos = mini_pos % azx_dev->period_bytes;1890 mod_link_pos = link_pos % azx_dev->period_bytes;1891 if (mod_link_pos >= fifo_size)1892 bound_pos = link_pos - mod_link_pos;1893 else if (mod_dma_pos >= mod_mini_pos)1894 bound_pos = mini_pos - mod_mini_pos;1895 else {1896 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;1897 if (bound_pos >= azx_dev->bufsize)1898 bound_pos = 0;1899 }1900 1901 /* Calculate real DMA position we want */1902 return bound_pos + mod_dma_pos;1853 struct azx_dev *azx_dev) 1854 { 1855 unsigned int link_pos, mini_pos, bound_pos; 1856 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos; 1857 unsigned int fifo_size; 1858 1859 link_pos = azx_sd_readl(azx_dev, SD_LPIB); 1860 if (azx_dev->index >= 4) { 1861 /* Playback, no problem using link position */ 1862 return link_pos; 1863 } 1864 1865 /* Capture */ 1866 /* For new chipset, 1867 * use mod to get the DMA position just like old chipset 1868 */ 1869 mod_dma_pos = le32_to_cpu(*azx_dev->posbuf); 1870 mod_dma_pos %= azx_dev->period_bytes; 1871 1872 /* azx_dev->fifo_size can't get FIFO size of in stream. 1873 * Get from base address + offset. 1874 */ 1875 fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET); 1876 1877 if (azx_dev->insufficient) { 1878 /* Link position never gather than FIFO size */ 1879 if (link_pos <= fifo_size) 1880 return 0; 1881 1882 azx_dev->insufficient = 0; 1883 } 1884 1885 if (link_pos <= fifo_size) 1886 mini_pos = azx_dev->bufsize + link_pos - fifo_size; 1887 else 1888 mini_pos = link_pos - fifo_size; 1889 1890 /* Find nearest previous boudary */ 1891 mod_mini_pos = mini_pos % azx_dev->period_bytes; 1892 mod_link_pos = link_pos % azx_dev->period_bytes; 1893 if (mod_link_pos >= fifo_size) 1894 bound_pos = link_pos - mod_link_pos; 1895 else if (mod_dma_pos >= mod_mini_pos) 1896 bound_pos = mini_pos - mod_mini_pos; 1897 else { 1898 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes; 1899 if (bound_pos >= azx_dev->bufsize) 1900 bound_pos = 0; 1901 } 1902 1903 /* Calculate real DMA position we want */ 1904 return bound_pos + mod_dma_pos; 1903 1905 } 1904 1906 1905 1907 static unsigned int azx_get_position(struct azx *chip, 1906 struct azx_dev *azx_dev)1907 { 1908 unsigned int pos;1909 int stream = azx_dev->substream->stream;1910 1911 switch (chip->position_fix[stream]) {1912 case POS_FIX_LPIB:1913 /* read LPIB */1914 pos = azx_sd_readl(azx_dev, SD_LPIB);1915 break;1916 case POS_FIX_VIACOMBO:1917 pos = azx_via_get_position(chip, azx_dev);1918 break;1919 default:1920 /* use the position buffer */1921 pos = le32_to_cpu(*azx_dev->posbuf);1922 }1923 1924 if (pos >= azx_dev->bufsize)1925 pos = 0;1926 return pos;1908 struct azx_dev *azx_dev) 1909 { 1910 unsigned int pos; 1911 int stream = azx_dev->substream->stream; 1912 1913 switch (chip->position_fix[stream]) { 1914 case POS_FIX_LPIB: 1915 /* read LPIB */ 1916 pos = azx_sd_readl(azx_dev, SD_LPIB); 1917 break; 1918 case POS_FIX_VIACOMBO: 1919 pos = azx_via_get_position(chip, azx_dev); 1920 break; 1921 default: 1922 /* use the position buffer */ 1923 pos = le32_to_cpu(*azx_dev->posbuf); 1924 } 1925 1926 if (pos >= azx_dev->bufsize) 1927 pos = 0; 1928 return pos; 1927 1929 } 1928 1930 1929 1931 static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) 1930 1932 { 1931 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);1932 struct azx *chip = apcm->chip;1933 struct azx_dev *azx_dev = get_azx_dev(substream);1934 return bytes_to_frames(substream->runtime,1935 azx_get_position(chip, azx_dev));1933 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1934 struct azx *chip = apcm->chip; 1935 struct azx_dev *azx_dev = get_azx_dev(substream); 1936 return bytes_to_frames(substream->runtime, 1937 azx_get_position(chip, azx_dev)); 1936 1938 } 1937 1939 … … 1947 1949 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev) 1948 1950 { 1949 u32 wallclk;1950 unsigned int pos;1951 int stream;1952 1953 wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;1954 if (wallclk < (azx_dev->period_wallclk * 2) / 3)1955 return -1;/* bogus (too early) interrupt */1956 1957 stream = azx_dev->substream->stream;1958 pos = azx_get_position(chip, azx_dev);1959 if (chip->position_fix[stream] == POS_FIX_AUTO) {1960 if (!pos) {1961 printk(KERN_WARNING1962 "hda-intel: Invalid position buffer, "1963 "using LPIB read method instead.\n");1964 chip->position_fix[stream] = POS_FIX_LPIB;1965 pos = azx_get_position(chip, azx_dev);1966 } else1967 chip->position_fix[stream] = POS_FIX_POSBUF;1968 }1951 u32 wallclk; 1952 unsigned int pos; 1953 int stream; 1954 1955 wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk; 1956 if (wallclk < (azx_dev->period_wallclk * 2) / 3) 1957 return -1; /* bogus (too early) interrupt */ 1958 1959 stream = azx_dev->substream->stream; 1960 pos = azx_get_position(chip, azx_dev); 1961 if (chip->position_fix[stream] == POS_FIX_AUTO) { 1962 if (!pos) { 1963 printk(KERN_WARNING 1964 "hda-intel: Invalid position buffer, " 1965 "using LPIB read method instead.\n"); 1966 chip->position_fix[stream] = POS_FIX_LPIB; 1967 pos = azx_get_position(chip, azx_dev); 1968 } else 1969 chip->position_fix[stream] = POS_FIX_POSBUF; 1970 } 1969 1971 1970 1972 #ifndef TARGET_OS2 1971 if (WARN_ONCE(!azx_dev->period_bytes,1972 "hda-intel: zero azx_dev->period_bytes"))1973 return -1; /* this shouldn't happen! */1973 if (WARN_ONCE(!azx_dev->period_bytes, 1974 "hda-intel: zero azx_dev->period_bytes")) 1975 return -1; /* this shouldn't happen! */ 1974 1976 #endif 1975 if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&1976 pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)1977 /* NG - it's below the first next period boundary */1978 return bdl_pos_adj[chip->dev_index] ? 0 : -1;1979 azx_dev->start_wallclk += wallclk;1980 return 1; /* OK, it's fine */1977 if (wallclk < (azx_dev->period_wallclk * 5) / 4 && 1978 pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) 1979 /* NG - it's below the first next period boundary */ 1980 return bdl_pos_adj[chip->dev_index] ? 0 : -1; 1981 azx_dev->start_wallclk += wallclk; 1982 return 1; /* OK, it's fine */ 1981 1983 } 1982 1984 … … 1986 1988 static void azx_irq_pending_work(struct work_struct *work) 1987 1989 { 1988 struct azx *chip = container_of(work, struct azx, irq_pending_work);1989 int i, pending, ok;1990 1991 if (!chip->irq_pending_warned) {1992 printk(KERN_WARNING1993 "hda-intel: IRQ timing workaround is activated "1994 "for card #%d. Suggest a bigger bdl_pos_adj.\n",1995 chip->card->number);1996 chip->irq_pending_warned = 1;1997 }1998 1999 for (;;) {2000 pending = 0;2001 spin_lock_irq(&chip->reg_lock);2002 for (i = 0; i < chip->num_streams; i++) {2003 struct azx_dev *azx_dev = &chip->azx_dev[i];2004 if (!azx_dev->irq_pending ||2005 !azx_dev->substream ||2006 !azx_dev->running)2007 continue;2008 ok = azx_position_ok(chip, azx_dev);2009 if (ok > 0) {2010 azx_dev->irq_pending = 0;2011 spin_unlock(&chip->reg_lock);2012 snd_pcm_period_elapsed(azx_dev->substream);2013 spin_lock(&chip->reg_lock);2014 } else if (ok < 0) {2015 pending = 0;/* too early */2016 } else2017 pending++;2018 }2019 spin_unlock_irq(&chip->reg_lock);2020 if (!pending)2021 return;2022 msleep(1);2023 }1990 struct azx *chip = container_of(work, struct azx, irq_pending_work); 1991 int i, pending, ok; 1992 1993 if (!chip->irq_pending_warned) { 1994 printk(KERN_WARNING 1995 "hda-intel: IRQ timing workaround is activated " 1996 "for card #%d. Suggest a bigger bdl_pos_adj.\n", 1997 chip->card->number); 1998 chip->irq_pending_warned = 1; 1999 } 2000 2001 for (;;) { 2002 pending = 0; 2003 spin_lock_irq(&chip->reg_lock); 2004 for (i = 0; i < chip->num_streams; i++) { 2005 struct azx_dev *azx_dev = &chip->azx_dev[i]; 2006 if (!azx_dev->irq_pending || 2007 !azx_dev->substream || 2008 !azx_dev->running) 2009 continue; 2010 ok = azx_position_ok(chip, azx_dev); 2011 if (ok > 0) { 2012 azx_dev->irq_pending = 0; 2013 spin_unlock(&chip->reg_lock); 2014 snd_pcm_period_elapsed(azx_dev->substream); 2015 spin_lock(&chip->reg_lock); 2016 } else if (ok < 0) { 2017 pending = 0; /* too early */ 2018 } else 2019 pending++; 2020 } 2021 spin_unlock_irq(&chip->reg_lock); 2022 if (!pending) 2023 return; 2024 msleep(1); 2025 } 2024 2026 } 2025 2027 … … 2027 2029 static void azx_clear_irq_pending(struct azx *chip) 2028 2030 { 2029 int i;2030 2031 spin_lock_irq(&chip->reg_lock);2032 for (i = 0; i < chip->num_streams; i++)2033 chip->azx_dev[i].irq_pending = 0;2034 spin_unlock_irq(&chip->reg_lock);2031 int i; 2032 2033 spin_lock_irq(&chip->reg_lock); 2034 for (i = 0; i < chip->num_streams; i++) 2035 chip->azx_dev[i].irq_pending = 0; 2036 spin_unlock_irq(&chip->reg_lock); 2035 2037 } 2036 2038 2037 2039 static struct snd_pcm_ops azx_pcm_ops = { 2038 .open = azx_pcm_open,2039 .close = azx_pcm_close,2040 .ioctl = snd_pcm_lib_ioctl,2041 .hw_params = azx_pcm_hw_params,2042 .hw_free = azx_pcm_hw_free,2043 .prepare = azx_pcm_prepare,2044 .trigger = azx_pcm_trigger,2045 .pointer = azx_pcm_pointer,2046 .page = snd_pcm_sgbuf_ops_page,2040 .open = azx_pcm_open, 2041 .close = azx_pcm_close, 2042 .ioctl = snd_pcm_lib_ioctl, 2043 .hw_params = azx_pcm_hw_params, 2044 .hw_free = azx_pcm_hw_free, 2045 .prepare = azx_pcm_prepare, 2046 .trigger = azx_pcm_trigger, 2047 .pointer = azx_pcm_pointer, 2048 .page = snd_pcm_sgbuf_ops_page, 2047 2049 }; 2048 2050 2049 2051 static void azx_pcm_free(struct snd_pcm *pcm) 2050 2052 { 2051 struct azx_pcm *apcm = pcm->private_data;2052 if (apcm) {2053 apcm->chip->pcm[pcm->device] = NULL;2054 kfree(apcm);2055 }2053 struct azx_pcm *apcm = pcm->private_data; 2054 if (apcm) { 2055 apcm->chip->pcm[pcm->device] = NULL; 2056 kfree(apcm); 2057 } 2056 2058 } 2057 2059 2058 2060 static int 2059 2061 azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, 2060 struct hda_pcm *cpcm)2061 { 2062 struct azx *chip = bus->private_data;2063 struct snd_pcm *pcm;2064 struct azx_pcm *apcm;2065 int pcm_dev = cpcm->device;2066 int s, err;2067 2068 if (pcm_dev >= HDA_MAX_PCMS) {2069 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n",2070 pcm_dev);2071 return -EINVAL;2072 }2073 if (chip->pcm[pcm_dev]) {2074 snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev);2075 return -EBUSY;2076 }2077 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,2078 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,2079 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,2080 &pcm);2081 if (err < 0)2082 return err;2083 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));2084 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);2085 if (apcm == NULL)2086 return -ENOMEM;2087 apcm->chip = chip;2088 apcm->codec = codec;2089 pcm->private_data = apcm;2090 pcm->private_free = azx_pcm_free;2091 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)2092 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;2093 chip->pcm[pcm_dev] = pcm;2094 cpcm->pcm = pcm;2095 for (s = 0; s < 2; s++) {2096 apcm->hinfo[s] = &cpcm->stream[s];2097 if (cpcm->stream[s].substreams)2098 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);2099 }2100 /* buffer pre-allocation */2101 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,2102 snd_dma_pci_data(chip->pci),2103 1024 * 64, 32 * 1024 * 1024);2104 return 0;2062 struct hda_pcm *cpcm) 2063 { 2064 struct azx *chip = bus->private_data; 2065 struct snd_pcm *pcm; 2066 struct azx_pcm *apcm; 2067 int pcm_dev = cpcm->device; 2068 int s, err; 2069 2070 if (pcm_dev >= HDA_MAX_PCMS) { 2071 snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n", 2072 pcm_dev); 2073 return -EINVAL; 2074 } 2075 if (chip->pcm[pcm_dev]) { 2076 snd_printk(KERN_ERR SFX "PCM %d already exists\n", pcm_dev); 2077 return -EBUSY; 2078 } 2079 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, 2080 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams, 2081 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams, 2082 &pcm); 2083 if (err < 0) 2084 return err; 2085 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name)); 2086 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); 2087 if (apcm == NULL) 2088 return -ENOMEM; 2089 apcm->chip = chip; 2090 apcm->codec = codec; 2091 pcm->private_data = apcm; 2092 pcm->private_free = azx_pcm_free; 2093 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM) 2094 pcm->dev_class = SNDRV_PCM_CLASS_MODEM; 2095 chip->pcm[pcm_dev] = pcm; 2096 cpcm->pcm = pcm; 2097 for (s = 0; s < 2; s++) { 2098 apcm->hinfo[s] = &cpcm->stream[s]; 2099 if (cpcm->stream[s].substreams) 2100 snd_pcm_set_ops(pcm, s, &azx_pcm_ops); 2101 } 2102 /* buffer pre-allocation */ 2103 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 2104 snd_dma_pci_data(chip->pci), 2105 1024 * 64, 32 * 1024 * 1024); 2106 return 0; 2105 2107 } 2106 2108 … … 2110 2112 static int __devinit azx_mixer_create(struct azx *chip) 2111 2113 { 2112 return snd_hda_build_controls(chip->bus);2114 return snd_hda_build_controls(chip->bus); 2113 2115 } 2114 2116 … … 2119 2121 static int __devinit azx_init_stream(struct azx *chip) 2120 2122 { 2121 int i;2122 2123 /* initialize each stream (aka device)2124 * assign the starting bdl address to each stream (device)2125 * and initialize2126 */2127 for (i = 0; i < chip->num_streams; i++) {2128 struct azx_dev *azx_dev = &chip->azx_dev[i];2129 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);2130 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */2131 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);2132 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */2133 azx_dev->sd_int_sta_mask = 1 << i;2134 /* stream tag: must be non-zero and unique */2135 azx_dev->index = i;2136 azx_dev->stream_tag = i + 1;2137 }2138 2139 return 0;2123 int i; 2124 2125 /* initialize each stream (aka device) 2126 * assign the starting bdl address to each stream (device) 2127 * and initialize 2128 */ 2129 for (i = 0; i < chip->num_streams; i++) { 2130 struct azx_dev *azx_dev = &chip->azx_dev[i]; 2131 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); 2132 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ 2133 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); 2134 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */ 2135 azx_dev->sd_int_sta_mask = 1 << i; 2136 /* stream tag: must be non-zero and unique */ 2137 azx_dev->index = i; 2138 azx_dev->stream_tag = i + 1; 2139 } 2140 2141 return 0; 2140 2142 } 2141 2143 2142 2144 static int azx_acquire_irq(struct azx *chip, int do_disconnect) 2143 2145 { 2144 if (request_irq(chip->pci->irq, azx_interrupt,2145 chip->msi ? 0 : IRQF_SHARED,2146 "hda_intel", chip)) {2147 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, "2148 "disabling device\n", chip->pci->irq);2146 if (request_irq(chip->pci->irq, azx_interrupt, 2147 chip->msi ? 0 : IRQF_SHARED, 2148 "hda_intel", chip)) { 2149 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, " 2150 "disabling device\n", chip->pci->irq); 2149 2151 #ifndef TARGET_OS2 2150 if (do_disconnect)2151 snd_card_disconnect(chip->card);2152 if (do_disconnect) 2153 snd_card_disconnect(chip->card); 2152 2154 #endif 2153 return -1;2154 }2155 chip->irq = chip->pci->irq;2156 pci_intx(chip->pci, !chip->msi);2157 return 0;2155 return -1; 2156 } 2157 chip->irq = chip->pci->irq; 2158 pci_intx(chip->pci, !chip->msi); 2159 return 0; 2158 2160 } 2159 2161 … … 2161 2163 static void azx_stop_chip(struct azx *chip) 2162 2164 { 2163 if (!chip->initialized)2164 return;2165 2166 /* disable interrupts */2167 azx_int_disable(chip);2168 azx_int_clear(chip);2169 2170 /* disable CORB/RIRB */2171 azx_free_cmd_io(chip);2172 2173 /* disable position buffer */2174 azx_writel(chip, DPLBASE, 0);2175 azx_writel(chip, DPUBASE, 0);2176 2177 chip->initialized = 0;2165 if (!chip->initialized) 2166 return; 2167 2168 /* disable interrupts */ 2169 azx_int_disable(chip); 2170 azx_int_clear(chip); 2171 2172 /* disable CORB/RIRB */ 2173 azx_free_cmd_io(chip); 2174 2175 /* disable position buffer */ 2176 azx_writel(chip, DPLBASE, 0); 2177 azx_writel(chip, DPUBASE, 0); 2178 2179 chip->initialized = 0; 2178 2180 } 2179 2181 … … 2182 2184 static void azx_power_notify(struct hda_bus *bus) 2183 2185 { 2184 struct azx *chip = bus->private_data;2185 struct hda_codec *c;2186 int power_on = 0;2187 2188 list_for_each_entry(c, &bus->codec_list, list, struct hda_codec) {2189 if (c->power_on) {2190 power_on = 1;2191 break;2192 }2193 }2194 if (power_on)2195 azx_init_chip(chip, 1);2196 else if (chip->running && power_save_controller &&2197 !bus->power_keep_link_on)2198 azx_stop_chip(chip);2186 struct azx *chip = bus->private_data; 2187 struct hda_codec *c; 2188 int power_on = 0; 2189 2190 list_for_each_entry(c, &bus->codec_list, list, struct hda_codec) { 2191 if (c->power_on) { 2192 power_on = 1; 2193 break; 2194 } 2195 } 2196 if (power_on) 2197 azx_init_chip(chip, 1); 2198 else if (chip->running && power_save_controller && 2199 !bus->power_keep_link_on) 2200 azx_stop_chip(chip); 2199 2201 } 2200 2202 #endif /* CONFIG_SND_HDA_POWER_SAVE */ … … 2207 2209 static int snd_hda_codecs_inuse(struct hda_bus *bus) 2208 2210 { 2209 struct hda_codec *codec;2210 2211 list_for_each_entry(codec, &bus->codec_list, list, struct hda_codec) {2212 if (snd_hda_codec_needs_resume(codec))2213 return 1;2214 }2215 return 0;2211 struct hda_codec *codec; 2212 2213 list_for_each_entry(codec, &bus->codec_list, list, struct hda_codec) { 2214 if (snd_hda_codec_needs_resume(codec)) 2215 return 1; 2216 } 2217 return 0; 2216 2218 } 2217 2219 2218 2220 static int azx_suspend(struct pci_dev *pci, pm_message_t state) 2219 2221 { 2220 struct snd_card *card = pci_get_drvdata(pci);2221 struct azx *chip = card->private_data;2222 int i;2223 2224 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);2225 azx_clear_irq_pending(chip);2226 for (i = 0; i < HDA_MAX_PCMS; i++)2227 snd_pcm_suspend_all(chip->pcm[i]);2228 if (chip->initialized)2229 snd_hda_suspend(chip->bus);2230 azx_stop_chip(chip);2231 if (chip->irq >= 0) {2232 free_irq(chip->irq, chip);2233 chip->irq = -1;2234 }2235 if (chip->msi)2236 pci_disable_msi(chip->pci);2237 pci_disable_device(pci);2238 pci_save_state(pci);2239 pci_set_power_state(pci, pci_choose_state(pci, state));2240 return 0;2222 struct snd_card *card = pci_get_drvdata(pci); 2223 struct azx *chip = card->private_data; 2224 int i; 2225 2226 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2227 azx_clear_irq_pending(chip); 2228 for (i = 0; i < HDA_MAX_PCMS; i++) 2229 snd_pcm_suspend_all(chip->pcm[i]); 2230 if (chip->initialized) 2231 snd_hda_suspend(chip->bus); 2232 azx_stop_chip(chip); 2233 if (chip->irq >= 0) { 2234 free_irq(chip->irq, chip); 2235 chip->irq = -1; 2236 } 2237 if (chip->msi) 2238 pci_disable_msi(chip->pci); 2239 pci_disable_device(pci); 2240 pci_save_state(pci); 2241 pci_set_power_state(pci, pci_choose_state(pci, state)); 2242 return 0; 2241 2243 } 2242 2244 2243 2245 static int azx_resume(struct pci_dev *pci) 2244 2246 { 2245 struct snd_card *card = pci_get_drvdata(pci);2246 struct azx *chip = card->private_data;2247 2248 pci_set_power_state(pci, PCI_D0);2249 pci_restore_state(pci);2250 if (pci_enable_device(pci) < 0) {2251 printk(KERN_ERR "hda-intel: pci_enable_device failed, "2252 "disabling device\n");2253 snd_card_disconnect(card);2254 return -EIO;2255 }2256 pci_set_master(pci);2257 if (chip->msi)2258 if (pci_enable_msi(pci) < 0)2259 chip->msi = 0;2260 if (azx_acquire_irq(chip, 1) < 0)2261 return -EIO;2262 azx_init_pci(chip);2263 2264 if (snd_hda_codecs_inuse(chip->bus))2265 azx_init_chip(chip, 1);2266 2267 snd_hda_resume(chip->bus);2268 snd_power_change_state(card, SNDRV_CTL_POWER_D0);2269 return 0;2247 struct snd_card *card = pci_get_drvdata(pci); 2248 struct azx *chip = card->private_data; 2249 2250 pci_set_power_state(pci, PCI_D0); 2251 pci_restore_state(pci); 2252 if (pci_enable_device(pci) < 0) { 2253 printk(KERN_ERR "hda-intel: pci_enable_device failed, " 2254 "disabling device\n"); 2255 snd_card_disconnect(card); 2256 return -EIO; 2257 } 2258 pci_set_master(pci); 2259 if (chip->msi) 2260 if (pci_enable_msi(pci) < 0) 2261 chip->msi = 0; 2262 if (azx_acquire_irq(chip, 1) < 0) 2263 return -EIO; 2264 azx_init_pci(chip); 2265 2266 if (snd_hda_codecs_inuse(chip->bus)) 2267 azx_init_chip(chip, 1); 2268 2269 snd_hda_resume(chip->bus); 2270 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2271 return 0; 2270 2272 } 2271 2273 #endif /* CONFIG_PM */ … … 2277 2279 static int azx_halt(struct notifier_block *nb, unsigned long event, void *buf) 2278 2280 { 2279 struct azx *chip = container_of(nb, struct azx, reboot_notifier);2280 snd_hda_bus_reboot_notify(chip->bus);2281 azx_stop_chip(chip);2282 return NOTIFY_OK;2281 struct azx *chip = container_of(nb, struct azx, reboot_notifier); 2282 snd_hda_bus_reboot_notify(chip->bus); 2283 azx_stop_chip(chip); 2284 return NOTIFY_OK; 2283 2285 } 2284 2286 2285 2287 static void azx_notifier_register(struct azx *chip) 2286 2288 { 2287 chip->reboot_notifier.notifier_call = azx_halt;2288 register_reboot_notifier(&chip->reboot_notifier);2289 chip->reboot_notifier.notifier_call = azx_halt; 2290 register_reboot_notifier(&chip->reboot_notifier); 2289 2291 } 2290 2292 2291 2293 static void azx_notifier_unregister(struct azx *chip) 2292 2294 { 2293 if (chip->reboot_notifier.notifier_call)2294 unregister_reboot_notifier(&chip->reboot_notifier);2295 if (chip->reboot_notifier.notifier_call) 2296 unregister_reboot_notifier(&chip->reboot_notifier); 2295 2297 } 2296 2298 … … 2300 2302 static int azx_free(struct azx *chip) 2301 2303 { 2302 int i;2303 2304 azx_notifier_unregister(chip);2305 2306 if (chip->initialized) {2307 azx_clear_irq_pending(chip);2308 for (i = 0; i < chip->num_streams; i++)2309 azx_stream_stop(chip, &chip->azx_dev[i]);2310 azx_stop_chip(chip);2311 }2312 2313 if (chip->irq >= 0)2314 free_irq(chip->irq, (void*)chip);2315 if (chip->msi)2316 pci_disable_msi(chip->pci);2317 if (chip->remap_addr)2304 int i; 2305 2306 azx_notifier_unregister(chip); 2307 2308 if (chip->initialized) { 2309 azx_clear_irq_pending(chip); 2310 for (i = 0; i < chip->num_streams; i++) 2311 azx_stream_stop(chip, &chip->azx_dev[i]); 2312 azx_stop_chip(chip); 2313 } 2314 2315 if (chip->irq >= 0) 2316 free_irq(chip->irq, (void*)chip); 2317 if (chip->msi) 2318 pci_disable_msi(chip->pci); 2319 if (chip->remap_addr) 2318 2320 #ifdef TARGET_OS2 2319 iounmap((void *)chip->remap_addr);2321 iounmap((void *)chip->remap_addr); 2320 2322 #else 2321 iounmap(chip->remap_addr);2323 iounmap(chip->remap_addr); 2322 2324 #endif 2323 if (chip->azx_dev) {2324 for (i = 0; i < chip->num_streams; i++)2325 if (chip->azx_dev[i].bdl.area)2326 snd_dma_free_pages(&chip->azx_dev[i].bdl);2327 }2328 if (chip->rb.area)2329 snd_dma_free_pages(&chip->rb);2330 if (chip->posbuf.area)2331 snd_dma_free_pages(&chip->posbuf);2332 pci_release_regions(chip->pci);2333 pci_disable_device(chip->pci);2334 kfree(chip->azx_dev);2335 kfree(chip);2336 2337 return 0;2325 if (chip->azx_dev) { 2326 for (i = 0; i < chip->num_streams; i++) 2327 if (chip->azx_dev[i].bdl.area) 2328 snd_dma_free_pages(&chip->azx_dev[i].bdl); 2329 } 2330 if (chip->rb.area) 2331 snd_dma_free_pages(&chip->rb); 2332 if (chip->posbuf.area) 2333 snd_dma_free_pages(&chip->posbuf); 2334 pci_release_regions(chip->pci); 2335 pci_disable_device(chip->pci); 2336 kfree(chip->azx_dev); 2337 kfree(chip); 2338 2339 return 0; 2338 2340 } 2339 2341 2340 2342 static int azx_dev_free(struct snd_device *device) 2341 2343 { 2342 return azx_free(device->device_data);2344 return azx_free(device->device_data); 2343 2345 } 2344 2346 … … 2347 2349 */ 2348 2350 static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2349 SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB),2350 SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB),2351 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),2352 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),2353 SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB),2354 SND_PCI_QUIRK(0x1028, 0x0470, "Dell Inspiron 1120", POS_FIX_LPIB),2355 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),2356 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),2357 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),2358 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB),2359 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB),2360 SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB),2361 SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB),2362 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB),2363 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB),2364 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB),2365 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB),2366 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB),2367 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB),2368 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB),2369 SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB),2370 {0}2351 SND_PCI_QUIRK(0x1025, 0x009f, "Acer Aspire 5110", POS_FIX_LPIB), 2352 SND_PCI_QUIRK(0x1025, 0x026f, "Acer Aspire 5538", POS_FIX_LPIB), 2353 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2354 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2355 SND_PCI_QUIRK(0x1028, 0x01f6, "Dell Latitude 131L", POS_FIX_LPIB), 2356 SND_PCI_QUIRK(0x1028, 0x0470, "Dell Inspiron 1120", POS_FIX_LPIB), 2357 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB), 2358 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2359 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB), 2360 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS M2V", POS_FIX_LPIB), 2361 SND_PCI_QUIRK(0x104d, 0x9069, "Sony VPCS11V9E", POS_FIX_LPIB), 2362 SND_PCI_QUIRK(0x1106, 0x3288, "ASUS M2V-MX SE", POS_FIX_LPIB), 2363 SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba A100-259", POS_FIX_LPIB), 2364 SND_PCI_QUIRK(0x1297, 0x3166, "Shuttle", POS_FIX_LPIB), 2365 SND_PCI_QUIRK(0x1458, 0xa022, "ga-ma770-ud3", POS_FIX_LPIB), 2366 SND_PCI_QUIRK(0x1462, 0x1002, "MSI Wind U115", POS_FIX_LPIB), 2367 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar Microtech", POS_FIX_LPIB), 2368 SND_PCI_QUIRK(0x1565, 0x8218, "Biostar Microtech", POS_FIX_LPIB), 2369 SND_PCI_QUIRK(0x1849, 0x0888, "775Dual-VSTA", POS_FIX_LPIB), 2370 SND_PCI_QUIRK(0x8086, 0x2503, "DG965OT AAD63733-203", POS_FIX_LPIB), 2371 SND_PCI_QUIRK(0x8086, 0xd601, "eMachines T5212", POS_FIX_LPIB), 2372 {0} 2371 2373 }; 2372 2374 2373 2375 static int __devinit check_position_fix(struct azx *chip, int fix) 2374 2376 { 2375 const struct snd_pci_quirk *q;2376 2377 switch (fix) {2378 case POS_FIX_LPIB:2379 case POS_FIX_POSBUF:2380 case POS_FIX_VIACOMBO:2381 return fix;2382 }2383 2384 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);2385 if (q) {2386 printk(KERN_INFO2387 "hda_intel: position_fix set to %d "2388 "for device %04x:%04x\n",2389 q->value, q->subvendor, q->subdevice);2390 return q->value;2391 }2392 2393 /* Check VIA/ATI HD Audio Controller exist */2394 switch (chip->driver_type) {2395 case AZX_DRIVER_VIA:2396 case AZX_DRIVER_ATI:2397 /* Use link position directly, avoid any transfer problem. */2398 return POS_FIX_VIACOMBO;2399 }2400 2401 return POS_FIX_AUTO;2377 const struct snd_pci_quirk *q; 2378 2379 switch (fix) { 2380 case POS_FIX_LPIB: 2381 case POS_FIX_POSBUF: 2382 case POS_FIX_VIACOMBO: 2383 return fix; 2384 } 2385 2386 q = snd_pci_quirk_lookup(chip->pci, position_fix_list); 2387 if (q) { 2388 printk(KERN_INFO 2389 "hda_intel: position_fix set to %d " 2390 "for device %04x:%04x\n", 2391 q->value, q->subvendor, q->subdevice); 2392 return q->value; 2393 } 2394 2395 /* Check VIA/ATI HD Audio Controller exist */ 2396 switch (chip->driver_type) { 2397 case AZX_DRIVER_VIA: 2398 case AZX_DRIVER_ATI: 2399 /* Use link position directly, avoid any transfer problem. */ 2400 return POS_FIX_VIACOMBO; 2401 } 2402 2403 return POS_FIX_AUTO; 2402 2404 } 2403 2405 … … 2406 2408 */ 2407 2409 static struct snd_pci_quirk probe_mask_list[] __devinitdata = { 2408 /* Thinkpad often breaks the controller communication when accessing2409 * to the non-working (or non-existing) modem codec slot.2410 */2411 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01),2412 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01),2413 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01),2414 /* broken BIOS */2415 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),2416 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */2417 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),2418 /* forced codec slots */2419 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103),2420 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),2421 {0}2410 /* Thinkpad often breaks the controller communication when accessing 2411 * to the non-working (or non-existing) modem codec slot. 2412 */ 2413 SND_PCI_QUIRK(0x1014, 0x05b7, "Thinkpad Z60", 0x01), 2414 SND_PCI_QUIRK(0x17aa, 0x2010, "Thinkpad X/T/R60", 0x01), 2415 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X/T/R61", 0x01), 2416 /* broken BIOS */ 2417 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01), 2418 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */ 2419 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01), 2420 /* forced codec slots */ 2421 SND_PCI_QUIRK(0x1043, 0x1262, "ASUS W5Fm", 0x103), 2422 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103), 2423 {0} 2422 2424 }; 2423 2425 2424 #define AZX_FORCE_CODEC_MASK 0x1002426 #define AZX_FORCE_CODEC_MASK 0x100 2425 2427 2426 2428 static void __devinit check_probe_mask(struct azx *chip, int dev) 2427 2429 { 2428 const struct snd_pci_quirk *q;2429 2430 chip->codec_probe_mask = probe_mask[dev];2431 if (chip->codec_probe_mask == -1) {2432 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);2433 if (q) {2434 printk(KERN_INFO2435 "hda_intel: probe_mask set to 0x%x "2436 "for device %04x:%04x\n",2437 q->value, q->subvendor, q->subdevice);2438 chip->codec_probe_mask = q->value;2439 }2440 }2441 2442 /* check forced option */2443 if (chip->codec_probe_mask != -1 &&2444 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {2445 chip->codec_mask = chip->codec_probe_mask & 0xff;2446 printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",2447 chip->codec_mask);2448 }2430 const struct snd_pci_quirk *q; 2431 2432 chip->codec_probe_mask = probe_mask[dev]; 2433 if (chip->codec_probe_mask == -1) { 2434 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); 2435 if (q) { 2436 printk(KERN_INFO 2437 "hda_intel: probe_mask set to 0x%x " 2438 "for device %04x:%04x\n", 2439 q->value, q->subvendor, q->subdevice); 2440 chip->codec_probe_mask = q->value; 2441 } 2442 } 2443 2444 /* check forced option */ 2445 if (chip->codec_probe_mask != -1 && 2446 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { 2447 chip->codec_mask = chip->codec_probe_mask & 0xff; 2448 printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n", 2449 chip->codec_mask); 2450 } 2449 2451 } 2450 2452 … … 2453 2455 */ 2454 2456 static struct snd_pci_quirk msi_black_list[] __devinitdata = { 2455 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */2456 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */2457 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */2458 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */2459 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */2460 {0}2457 SND_PCI_QUIRK(0x1043, 0x81f2, "ASUS", 0), /* Athlon64 X2 + nvidia */ 2458 SND_PCI_QUIRK(0x1043, 0x81f6, "ASUS", 0), /* nvidia */ 2459 SND_PCI_QUIRK(0x1043, 0x822d, "ASUS", 0), /* Athlon64 X2 + nvidia MCP55 */ 2460 SND_PCI_QUIRK(0x1849, 0x0888, "ASRock", 0), /* Athlon64 X2 + nvidia */ 2461 SND_PCI_QUIRK(0xa0a0, 0x0575, "Aopen MZ915-M", 0), /* ICH6 */ 2462 {0} 2461 2463 }; 2462 2464 2463 2465 static void __devinit check_msi(struct azx *chip) 2464 2466 { 2465 const struct snd_pci_quirk *q;2466 2467 if (enable_msi >= 0) {2468 chip->msi = !!enable_msi;2469 return;2470 }2471 chip->msi = 1;/* enable MSI as default */2472 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);2473 if (q) {2474 printk(KERN_INFO2475 "hda_intel: msi for device %04x:%04x set to %d\n",2476 q->subvendor, q->subdevice, q->value);2477 chip->msi = q->value;2478 return;2479 }2480 2481 /* NVidia chipsets seem to cause troubles with MSI */2482 if (chip->driver_type == AZX_DRIVER_NVIDIA) {2483 printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n");2484 chip->msi = 0;2485 }2467 const struct snd_pci_quirk *q; 2468 2469 if (enable_msi >= 0) { 2470 chip->msi = !!enable_msi; 2471 return; 2472 } 2473 chip->msi = 1; /* enable MSI as default */ 2474 q = snd_pci_quirk_lookup(chip->pci, msi_black_list); 2475 if (q) { 2476 printk(KERN_INFO 2477 "hda_intel: msi for device %04x:%04x set to %d\n", 2478 q->subvendor, q->subdevice, q->value); 2479 chip->msi = q->value; 2480 return; 2481 } 2482 2483 /* NVidia chipsets seem to cause troubles with MSI */ 2484 if (chip->driver_type == AZX_DRIVER_NVIDIA) { 2485 printk(KERN_INFO "hda_intel: Disable MSI for Nvidia chipset\n"); 2486 chip->msi = 0; 2487 } 2486 2488 } 2487 2489 … … 2491 2493 */ 2492 2494 static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci, 2493 int dev, int driver_type,2494 struct azx **rchip)2495 { 2496 struct azx *chip;2497 int i, err;2498 unsigned short gcap;2499 static struct snd_device_ops ops = {2500 .dev_free = azx_dev_free,2501 };2502 2503 *rchip = NULL;2504 2505 err = pci_enable_device(pci);2506 if (err < 0)2507 return err;2508 2509 chip = kzalloc(sizeof(*chip), GFP_KERNEL);2510 if (!chip) {2511 snd_printk(KERN_ERR SFX "cannot allocate chip\n");2512 pci_disable_device(pci);2513 return -ENOMEM;2514 }2515 2516 spin_lock_init(&chip->reg_lock);2517 mutex_init(&chip->open_mutex);2518 chip->card = card;2519 chip->pci = pci;2520 chip->irq = -1;2521 chip->driver_type = driver_type;2522 check_msi(chip);2523 chip->dev_index = dev;2524 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);2525 2526 chip->position_fix[0] = chip->position_fix[1] =2527 check_position_fix(chip, position_fix[dev]);2528 check_probe_mask(chip, dev);2529 2530 chip->single_cmd = single_cmd;2531 2532 if (bdl_pos_adj[dev] < 0) {2533 switch (chip->driver_type) {2534 case AZX_DRIVER_ICH:2535 case AZX_DRIVER_PCH:2536 bdl_pos_adj[dev] = 1;2537 break;2538 default:2539 bdl_pos_adj[dev] = 32;2540 break;2541 }2542 }2495 int dev, int driver_type, 2496 struct azx **rchip) 2497 { 2498 struct azx *chip; 2499 int i, err; 2500 unsigned short gcap; 2501 static struct snd_device_ops ops = { 2502 .dev_free = azx_dev_free, 2503 }; 2504 2505 *rchip = NULL; 2506 2507 err = pci_enable_device(pci); 2508 if (err < 0) 2509 return err; 2510 2511 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 2512 if (!chip) { 2513 snd_printk(KERN_ERR SFX "cannot allocate chip\n"); 2514 pci_disable_device(pci); 2515 return -ENOMEM; 2516 } 2517 2518 spin_lock_init(&chip->reg_lock); 2519 mutex_init(&chip->open_mutex); 2520 chip->card = card; 2521 chip->pci = pci; 2522 chip->irq = -1; 2523 chip->driver_type = driver_type; 2524 check_msi(chip); 2525 chip->dev_index = dev; 2526 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); 2527 2528 chip->position_fix[0] = chip->position_fix[1] = 2529 check_position_fix(chip, position_fix[dev]); 2530 check_probe_mask(chip, dev); 2531 2532 chip->single_cmd = single_cmd; 2533 2534 if (bdl_pos_adj[dev] < 0) { 2535 switch (chip->driver_type) { 2536 case AZX_DRIVER_ICH: 2537 case AZX_DRIVER_PCH: 2538 bdl_pos_adj[dev] = 1; 2539 break; 2540 default: 2541 bdl_pos_adj[dev] = 32; 2542 break; 2543 } 2544 } 2543 2545 2544 2546 #if BITS_PER_LONG != 64 2545 /* Fix up base address on ULI M5461 */2546 if (chip->driver_type == AZX_DRIVER_ULI) {2547 u16 tmp3;2548 pci_read_config_word(pci, 0x40, &tmp3);2549 pci_write_config_word(pci, 0x40, tmp3 | 0x10);2550 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0);2551 }2547 /* Fix up base address on ULI M5461 */ 2548 if (chip->driver_type == AZX_DRIVER_ULI) { 2549 u16 tmp3; 2550 pci_read_config_word(pci, 0x40, &tmp3); 2551 pci_write_config_word(pci, 0x40, tmp3 | 0x10); 2552 pci_write_config_dword(pci, PCI_BASE_ADDRESS_1, 0); 2553 } 2552 2554 #endif 2553 2555 2554 err = pci_request_regions(pci, "ICH HD audio");2555 if (err < 0) {2556 kfree(chip);2557 pci_disable_device(pci);2558 return err;2559 }2560 2561 chip->addr = pci_resource_start(pci, 0);2562 chip->remap_addr = pci_ioremap_bar(pci, 0);2563 if (chip->remap_addr == NULL) {2564 snd_printk(KERN_ERR SFX "ioremap error\n");2565 err = -ENXIO;2566 goto errout;2567 }2568 2569 if (chip->msi)2570 if (pci_enable_msi(pci) < 0)2571 chip->msi = 0;2572 2573 if (azx_acquire_irq(chip, 0) < 0) {2574 err = -EBUSY;2575 goto errout;2576 }2577 2578 pci_set_master(pci);2579 synchronize_irq(chip->irq);2580 2581 gcap = azx_readw(chip, GCAP);2582 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap);2583 2584 /* disable SB600 64bit support for safety */2585 if ((chip->driver_type == AZX_DRIVER_ATI) ||2586 (chip->driver_type == AZX_DRIVER_ATIHDMI)) {2587 struct pci_dev *p_smbus;2588 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,2589 PCI_DEVICE_ID_ATI_SBX00_SMBUS,2590 NULL);2591 if (p_smbus) {2592 if (snd_pci_revision(p_smbus) < 0x30)2593 gcap &= ~ICH6_GCAP_64OK;2594 pci_dev_put(p_smbus);2595 }2596 }2597 2598 /* disable 64bit DMA address for Teradici */2599 /* it does not work with device 6549:1200 subsys e4a2:040b */2600 if (chip->driver_type == AZX_DRIVER_TERA)2601 gcap &= ~ICH6_GCAP_64OK;2556 err = pci_request_regions(pci, "ICH HD audio"); 2557 if (err < 0) { 2558 kfree(chip); 2559 pci_disable_device(pci); 2560 return err; 2561 } 2562 2563 chip->addr = pci_resource_start(pci, 0); 2564 chip->remap_addr = pci_ioremap_bar(pci, 0); 2565 if (chip->remap_addr == NULL) { 2566 snd_printk(KERN_ERR SFX "ioremap error\n"); 2567 err = -ENXIO; 2568 goto errout; 2569 } 2570 2571 if (chip->msi) 2572 if (pci_enable_msi(pci) < 0) 2573 chip->msi = 0; 2574 2575 if (azx_acquire_irq(chip, 0) < 0) { 2576 err = -EBUSY; 2577 goto errout; 2578 } 2579 2580 pci_set_master(pci); 2581 synchronize_irq(chip->irq); 2582 2583 gcap = azx_readw(chip, GCAP); 2584 snd_printdd(SFX "chipset global capabilities = 0x%x\n", gcap); 2585 2586 /* disable SB600 64bit support for safety */ 2587 if ((chip->driver_type == AZX_DRIVER_ATI) || 2588 (chip->driver_type == AZX_DRIVER_ATIHDMI)) { 2589 struct pci_dev *p_smbus; 2590 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, 2591 PCI_DEVICE_ID_ATI_SBX00_SMBUS, 2592 NULL); 2593 if (p_smbus) { 2594 if (snd_pci_revision(p_smbus) < 0x30) 2595 gcap &= ~ICH6_GCAP_64OK; 2596 pci_dev_put(p_smbus); 2597 } 2598 } 2599 2600 /* disable 64bit DMA address for Teradici */ 2601 /* it does not work with device 6549:1200 subsys e4a2:040b */ 2602 if (chip->driver_type == AZX_DRIVER_TERA) 2603 gcap &= ~ICH6_GCAP_64OK; 2602 2604 2603 2605 #pragma disable_message (135,302) 2604 /* allow 64bit DMA address if supported by H/W */2605 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))2606 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));2607 else {2608 pci_set_dma_mask(pci, DMA_BIT_MASK(32));2609 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));2610 }2606 /* allow 64bit DMA address if supported by H/W */ 2607 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2608 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); 2609 else { 2610 pci_set_dma_mask(pci, DMA_BIT_MASK(32)); 2611 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); 2612 } 2611 2613 #pragma enable_message (135,302) 2612 2614 2613 /* read number of streams from GCAP register instead of using2614 * hardcoded value2615 */2616 chip->capture_streams = (gcap >> 8) & 0x0f;2617 chip->playback_streams = (gcap >> 12) & 0x0f;2618 if (!chip->playback_streams && !chip->capture_streams) {2619 /* gcap didn't give any info, switching to old method */2620 2621 switch (chip->driver_type) {2622 case AZX_DRIVER_ULI:2623 chip->playback_streams = ULI_NUM_PLAYBACK;2624 chip->capture_streams = ULI_NUM_CAPTURE;2625 break;2626 case AZX_DRIVER_ATIHDMI:2627 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;2628 chip->capture_streams = ATIHDMI_NUM_CAPTURE;2629 break;2630 case AZX_DRIVER_GENERIC:2631 default:2632 chip->playback_streams = ICH6_NUM_PLAYBACK;2633 chip->capture_streams = ICH6_NUM_CAPTURE;2634 break;2635 }2636 }2637 chip->capture_index_offset = 0;2638 chip->playback_index_offset = chip->capture_streams;2639 chip->num_streams = chip->playback_streams + chip->capture_streams;2640 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),2641 GFP_KERNEL);2642 if (!chip->azx_dev) {2643 snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n");2644 goto errout;2645 }2646 2647 for (i = 0; i < chip->num_streams; i++) {2648 /* allocate memory for the BDL for each stream */2649 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,2650 snd_dma_pci_data(chip->pci),2651 BDL_SIZE, &chip->azx_dev[i].bdl);2652 if (err < 0) {2653 snd_printk(KERN_ERR SFX "cannot allocate BDL\n");2654 goto errout;2655 }2656 }2657 /* allocate memory for the position buffer */2658 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,2659 snd_dma_pci_data(chip->pci),2660 chip->num_streams * 8, &chip->posbuf);2661 if (err < 0) {2662 snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");2663 goto errout;2664 }2665 /* allocate CORB/RIRB */2666 err = azx_alloc_cmd_io(chip);2667 if (err < 0)2668 goto errout;2669 2670 /* initialize streams */2671 azx_init_stream(chip);2672 2673 /* initialize chip */2674 azx_init_pci(chip);2675 azx_init_chip(chip, (probe_only[dev] & 2) == 0);2676 2677 /* codec detection */2678 if (!chip->codec_mask) {2679 snd_printk(KERN_ERR SFX "no codecs found!\n");2680 err = -ENODEV;2681 goto errout;2682 }2683 2684 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);2685 if (err <0) {2686 snd_printk(KERN_ERR SFX "Error creating device [card]!\n");2687 goto errout;2688 }2689 2690 strcpy(card->driver, "HDA-Intel");2691 strlcpy(card->shortname, driver_short_names[chip->driver_type],2692 sizeof(card->shortname));2693 snprintf(card->longname, sizeof(card->longname),2694 "%s at 0x%lx irq %i",2695 card->shortname, chip->addr, chip->irq);2696 2697 *rchip = chip;2698 return 0;2615 /* read number of streams from GCAP register instead of using 2616 * hardcoded value 2617 */ 2618 chip->capture_streams = (gcap >> 8) & 0x0f; 2619 chip->playback_streams = (gcap >> 12) & 0x0f; 2620 if (!chip->playback_streams && !chip->capture_streams) { 2621 /* gcap didn't give any info, switching to old method */ 2622 2623 switch (chip->driver_type) { 2624 case AZX_DRIVER_ULI: 2625 chip->playback_streams = ULI_NUM_PLAYBACK; 2626 chip->capture_streams = ULI_NUM_CAPTURE; 2627 break; 2628 case AZX_DRIVER_ATIHDMI: 2629 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; 2630 chip->capture_streams = ATIHDMI_NUM_CAPTURE; 2631 break; 2632 case AZX_DRIVER_GENERIC: 2633 default: 2634 chip->playback_streams = ICH6_NUM_PLAYBACK; 2635 chip->capture_streams = ICH6_NUM_CAPTURE; 2636 break; 2637 } 2638 } 2639 chip->capture_index_offset = 0; 2640 chip->playback_index_offset = chip->capture_streams; 2641 chip->num_streams = chip->playback_streams + chip->capture_streams; 2642 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 2643 GFP_KERNEL); 2644 if (!chip->azx_dev) { 2645 snd_printk(KERN_ERR SFX "cannot malloc azx_dev\n"); 2646 goto errout; 2647 } 2648 2649 for (i = 0; i < chip->num_streams; i++) { 2650 /* allocate memory for the BDL for each stream */ 2651 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 2652 snd_dma_pci_data(chip->pci), 2653 BDL_SIZE, &chip->azx_dev[i].bdl); 2654 if (err < 0) { 2655 snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); 2656 goto errout; 2657 } 2658 } 2659 /* allocate memory for the position buffer */ 2660 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 2661 snd_dma_pci_data(chip->pci), 2662 chip->num_streams * 8, &chip->posbuf); 2663 if (err < 0) { 2664 snd_printk(KERN_ERR SFX "cannot allocate posbuf\n"); 2665 goto errout; 2666 } 2667 /* allocate CORB/RIRB */ 2668 err = azx_alloc_cmd_io(chip); 2669 if (err < 0) 2670 goto errout; 2671 2672 /* initialize streams */ 2673 azx_init_stream(chip); 2674 2675 /* initialize chip */ 2676 azx_init_pci(chip); 2677 azx_init_chip(chip, (probe_only[dev] & 2) == 0); 2678 2679 /* codec detection */ 2680 if (!chip->codec_mask) { 2681 snd_printk(KERN_ERR SFX "no codecs found!\n"); 2682 err = -ENODEV; 2683 goto errout; 2684 } 2685 2686 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 2687 if (err <0) { 2688 snd_printk(KERN_ERR SFX "Error creating device [card]!\n"); 2689 goto errout; 2690 } 2691 2692 strcpy(card->driver, "HDA-Intel"); 2693 strlcpy(card->shortname, driver_short_names[chip->driver_type], 2694 sizeof(card->shortname)); 2695 snprintf(card->longname, sizeof(card->longname), 2696 "%s at 0x%lx irq %i", 2697 card->shortname, chip->addr, chip->irq); 2698 2699 *rchip = chip; 2700 return 0; 2699 2701 2700 2702 errout: 2701 azx_free(chip);2702 return err;2703 azx_free(chip); 2704 return err; 2703 2705 } 2704 2706 … … 2706 2708 { 2707 2709 #ifdef CONFIG_SND_HDA_POWER_SAVE 2708 /* The codecs were powered up in snd_hda_codec_new().2709 * Now all initialization done, so turn them down if possible2710 */2711 struct hda_codec *codec;2712 list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) {2713 snd_hda_power_down(codec);2714 }2710 /* The codecs were powered up in snd_hda_codec_new(). 2711 * Now all initialization done, so turn them down if possible 2712 */ 2713 struct hda_codec *codec; 2714 list_for_each_entry(codec, &chip->bus->codec_list, list, struct hda_codec) { 2715 snd_hda_power_down(codec); 2716 } 2715 2717 #endif 2716 2718 } 2717 2719 2718 2720 static int __devinit azx_probe(struct pci_dev *pci, 2719 const struct pci_device_id *pci_id)2720 { 2721 static int dev;2722 struct snd_card *card;2723 struct azx *chip;2724 int err;2725 2726 if (dev >= SNDRV_CARDS)2727 return -ENODEV;2728 if (!enable[dev]) {2729 dev++;2730 return -ENOENT;2731 }2732 2733 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);2734 if (err < 0) {2735 snd_printk(KERN_ERR SFX "Error creating card!\n");2736 return err;2737 }2738 2739 /* set this here since it's referred in snd_hda_load_patch() */2740 snd_card_set_dev(card, &pci->dev);2741 2742 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);2743 if (err < 0)2744 goto out_free;2745 card->private_data = chip;2721 const struct pci_device_id *pci_id) 2722 { 2723 static int dev; 2724 struct snd_card *card; 2725 struct azx *chip; 2726 int err; 2727 2728 if (dev >= SNDRV_CARDS) 2729 return -ENODEV; 2730 if (!enable[dev]) { 2731 dev++; 2732 return -ENOENT; 2733 } 2734 2735 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2736 if (err < 0) { 2737 snd_printk(KERN_ERR SFX "Error creating card!\n"); 2738 return err; 2739 } 2740 2741 /* set this here since it's referred in snd_hda_load_patch() */ 2742 snd_card_set_dev(card, &pci->dev); 2743 2744 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); 2745 if (err < 0) 2746 goto out_free; 2747 card->private_data = chip; 2746 2748 2747 2749 #ifdef CONFIG_SND_HDA_INPUT_BEEP 2748 chip->beep_mode = beep_mode[dev];2750 chip->beep_mode = beep_mode[dev]; 2749 2751 #endif 2750 2752 2751 /* create codec instances */2752 err = azx_codec_create(chip, model[dev]);2753 if (err < 0)2754 goto out_free;2753 /* create codec instances */ 2754 err = azx_codec_create(chip, model[dev]); 2755 if (err < 0) 2756 goto out_free; 2755 2757 #ifdef CONFIG_SND_HDA_PATCH_LOADER 2756 if (patch[dev]) {2757 snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n",2758 patch[dev]);2759 err = snd_hda_load_patch(chip->bus, patch[dev]);2760 if (err < 0)2761 goto out_free;2762 }2758 if (patch[dev]) { 2759 snd_printk(KERN_ERR SFX "Applying patch firmware '%s'\n", 2760 patch[dev]); 2761 err = snd_hda_load_patch(chip->bus, patch[dev]); 2762 if (err < 0) 2763 goto out_free; 2764 } 2763 2765 #endif 2764 if ((probe_only[dev] & 1) == 0) {2765 err = azx_codec_configure(chip);2766 if (err < 0)2767 goto out_free;2768 }2769 2770 /* create PCM streams */2771 err = snd_hda_build_pcms(chip->bus);2772 if (err < 0)2773 goto out_free;2774 2775 /* create mixer controls */2776 err = azx_mixer_create(chip);2777 if (err < 0)2778 goto out_free;2779 2780 err = snd_card_register(card);2781 if (err < 0)2782 goto out_free;2783 2784 pci_set_drvdata(pci, card);2785 chip->running = 1;2786 power_down_all_codecs(chip);2787 azx_notifier_register(chip);2788 2789 dev++;2790 return err;2766 if ((probe_only[dev] & 1) == 0) { 2767 err = azx_codec_configure(chip); 2768 if (err < 0) 2769 goto out_free; 2770 } 2771 2772 /* create PCM streams */ 2773 err = snd_hda_build_pcms(chip->bus); 2774 if (err < 0) 2775 goto out_free; 2776 2777 /* create mixer controls */ 2778 err = azx_mixer_create(chip); 2779 if (err < 0) 2780 goto out_free; 2781 2782 err = snd_card_register(card); 2783 if (err < 0) 2784 goto out_free; 2785 2786 pci_set_drvdata(pci, card); 2787 chip->running = 1; 2788 power_down_all_codecs(chip); 2789 azx_notifier_register(chip); 2790 2791 dev++; 2792 return err; 2791 2793 out_free: 2792 snd_card_free(card);2793 return err;2794 snd_card_free(card); 2795 return err; 2794 2796 } 2795 2797 2796 2798 static void __devexit azx_remove(struct pci_dev *pci) 2797 2799 { 2798 snd_card_free(pci_get_drvdata(pci));2799 pci_set_drvdata(pci, NULL);2800 snd_card_free(pci_get_drvdata(pci)); 2801 pci_set_drvdata(pci, NULL); 2800 2802 } 2801 2803 2802 2804 /* PCI IDs */ 2803 2805 static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { 2804 /* CPT */ 2805 { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH }, 2806 /* PBG */ 2807 { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH }, 2808 /* SCH */ 2809 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH }, 2810 /* Generic Intel */ 2811 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), 2812 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2813 .class_mask = 0xffffff, 2814 .driver_data = AZX_DRIVER_ICH }, 2815 /* ATI SB 450/600 */ 2816 { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI }, 2817 { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI }, 2818 /* ATI HDMI */ 2819 { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI }, 2820 { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI }, 2821 { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI }, 2822 { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI }, 2823 { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI }, 2824 { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI }, 2825 { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI }, 2826 { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI }, 2827 { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI }, 2828 { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI }, 2829 { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI }, 2830 { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI }, 2831 { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI }, 2832 { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI }, 2833 /* VIA VT8251/VT8237A */ 2834 { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA }, 2835 /* SIS966 */ 2836 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS }, 2837 /* ULI M5461 */ 2838 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI }, 2839 /* NVIDIA MCP */ 2840 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), 2841 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2842 .class_mask = 0xffffff, 2843 .driver_data = AZX_DRIVER_NVIDIA }, 2844 /* Teradici */ 2845 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, 2846 /* Creative X-Fi (CA0110-IBG) */ 2806 /* CPT */ 2807 { PCI_DEVICE(0x8086, 0x1c20), .driver_data = AZX_DRIVER_PCH }, 2808 /* PBG */ 2809 { PCI_DEVICE(0x8086, 0x1d20), .driver_data = AZX_DRIVER_PCH }, 2810 { PCI_DEVICE(0x8086, 0x1e20), .driver_data = AZX_DRIVER_PCH }, 2811 { PCI_DEVICE(0x8086, 0x8c20), .driver_data = AZX_DRIVER_PCH }, 2812 { PCI_DEVICE(0x8086, 0x8d20), .driver_data = AZX_DRIVER_PCH }, 2813 { PCI_DEVICE(0x8086, 0x8d21), .driver_data = AZX_DRIVER_PCH }, 2814 { PCI_DEVICE(0x8086, 0x9c20), .driver_data = AZX_DRIVER_PCH }, 2815 { PCI_DEVICE(0x8086, 0x9c21), .driver_data = AZX_DRIVER_PCH }, 2816 { PCI_DEVICE(0x8086, 0x9ca0), .driver_data = AZX_DRIVER_PCH }, 2817 /* SCH */ 2818 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH }, 2819 /* Generic Intel */ 2820 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), 2821 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2822 .class_mask = 0xffffff, 2823 .driver_data = AZX_DRIVER_ICH }, 2824 /* ATI SB 450/600 */ 2825 { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI }, 2826 { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI }, 2827 /* ATI HDMI */ 2828 { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI }, 2829 { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI }, 2830 { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI }, 2831 { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI }, 2832 { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI }, 2833 { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI }, 2834 { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI }, 2835 { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI }, 2836 { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI }, 2837 { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI }, 2838 { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI }, 2839 { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI }, 2840 { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI }, 2841 { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI }, 2842 /* VIA VT8251/VT8237A */ 2843 { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA }, 2844 /* SIS966 */ 2845 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS }, 2846 /* ULI M5461 */ 2847 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI }, 2848 /* NVIDIA MCP */ 2849 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), 2850 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2851 .class_mask = 0xffffff, 2852 .driver_data = AZX_DRIVER_NVIDIA }, 2853 /* Teradici */ 2854 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, 2855 /* Creative X-Fi (CA0110-IBG) */ 2847 2856 #if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE) 2848 /* the following entry conflicts with snd-ctxfi driver,2849 * as ctxfi driver mutates from HD-audio to native mode with2850 * a special command sequence.2851 */2852 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID),2853 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,2854 .class_mask = 0xffffff,2855 .driver_data = AZX_DRIVER_CTX },2857 /* the following entry conflicts with snd-ctxfi driver, 2858 * as ctxfi driver mutates from HD-audio to native mode with 2859 * a special command sequence. 2860 */ 2861 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_ANY_ID), 2862 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2863 .class_mask = 0xffffff, 2864 .driver_data = AZX_DRIVER_CTX }, 2856 2865 #else 2857 /* this entry seems still valid -- i.e. without emu20kx chip */2858 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX },2866 /* this entry seems still valid -- i.e. without emu20kx chip */ 2867 { PCI_DEVICE(0x1102, 0x0009), .driver_data = AZX_DRIVER_CTX }, 2859 2868 #endif 2860 /* Vortex86MX */2861 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC },2862 /* VMware HDAudio */2863 { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC },2864 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */2865 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID),2866 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,2867 .class_mask = 0xffffff,2868 .driver_data = AZX_DRIVER_GENERIC },2869 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID),2870 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,2871 .class_mask = 0xffffff,2872 .driver_data = AZX_DRIVER_GENERIC },2873 { 0, }2869 /* Vortex86MX */ 2870 { PCI_DEVICE(0x17f3, 0x3010), .driver_data = AZX_DRIVER_GENERIC }, 2871 /* VMware HDAudio */ 2872 { PCI_DEVICE(0x15ad, 0x1977), .driver_data = AZX_DRIVER_GENERIC }, 2873 /* AMD/ATI Generic, PCI class code and Vendor ID for HD Audio */ 2874 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_ANY_ID), 2875 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2876 .class_mask = 0xffffff, 2877 .driver_data = AZX_DRIVER_GENERIC }, 2878 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_ANY_ID), 2879 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 2880 .class_mask = 0xffffff, 2881 .driver_data = AZX_DRIVER_GENERIC }, 2882 { 0, } 2874 2883 }; 2875 2884 MODULE_DEVICE_TABLE(pci, azx_ids); … … 2877 2886 /* pci_driver definition */ 2878 2887 static struct pci_driver driver = { 2879 .name = "HDA Intel",2880 .id_table = azx_ids,2881 .probe = azx_probe,2882 .remove = __devexit_p(azx_remove),2888 .name = "HDA Intel", 2889 .id_table = azx_ids, 2890 .probe = azx_probe, 2891 .remove = __devexit_p(azx_remove), 2883 2892 #ifdef CONFIG_PM 2884 .suspend = azx_suspend,2885 .resume = azx_resume,2893 .suspend = azx_suspend, 2894 .resume = azx_resume, 2886 2895 #endif 2887 2896 }; … … 2889 2898 static int __init alsa_card_azx_init(void) 2890 2899 { 2891 return pci_register_driver(&driver);2900 return pci_register_driver(&driver); 2892 2901 } 2893 2902 2894 2903 static void __exit alsa_card_azx_exit(void) 2895 2904 { 2896 pci_unregister_driver(&driver);2905 pci_unregister_driver(&driver); 2897 2906 } 2898 2907
Note:
See TracChangeset
for help on using the changeset viewer.
