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
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 28 * Andy Kopp 29 * Dan Kogan 27 * 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 33 * 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 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 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 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 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 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 155 #define SFX /* nop */ 156 156 #else 157 #define SFX 157 #define SFX "hda-intel: " 158 158 #endif 159 159 … … 161 161 * registers 162 162 */ 163 #define ICH6_REG_GCAP 164 #define ICH6_GCAP_64OK 165 #define ICH6_GCAP_NSDO 166 #define ICH6_GCAP_BSS 167 #define ICH6_GCAP_ISS 168 #define ICH6_GCAP_OSS 169 #define ICH6_REG_VMIN 170 #define ICH6_REG_VMAJ 171 #define ICH6_REG_OUTPAY 172 #define ICH6_REG_INPAY 173 #define ICH6_REG_GCTL 174 #define ICH6_GCTL_RESET 175 #define ICH6_GCTL_FCNTRL 176 #define ICH6_GCTL_UNSOL 177 #define ICH6_REG_WAKEEN 178 #define ICH6_REG_STATESTS 179 #define ICH6_REG_GSTS 180 #define ICH6_GSTS_FSTS 181 #define ICH6_REG_INTCTL 182 #define ICH6_REG_INTSTS 183 #define ICH6_REG_WALLCLK 0x30/* 24Mhz source */184 #define ICH6_REG_SYNC 0x34185 #define ICH6_REG_CORBLBASE 186 #define ICH6_REG_CORBUBASE 187 #define ICH6_REG_CORBWP 188 #define ICH6_REG_CORBRP 189 #define ICH6_CORBRP_RST 190 #define ICH6_REG_CORBCTL 191 #define ICH6_CORBCTL_RUN 192 #define ICH6_CORBCTL_CMEIE 193 #define ICH6_REG_CORBSTS 194 #define ICH6_CORBSTS_CMEI 195 #define ICH6_REG_CORBSIZE 196 197 #define ICH6_REG_RIRBLBASE 198 #define ICH6_REG_RIRBUBASE 199 #define ICH6_REG_RIRBWP 200 #define ICH6_RIRBWP_RST 201 #define ICH6_REG_RINTCNT 202 #define ICH6_REG_RIRBCTL 203 #define ICH6_RBCTL_IRQ_EN 204 #define ICH6_RBCTL_DMA_EN 205 #define ICH6_RBCTL_OVERRUN_EN 206 #define ICH6_REG_RIRBSTS 207 #define ICH6_RBSTS_IRQ 208 #define ICH6_RBSTS_OVERRUN 209 #define ICH6_REG_RIRBSIZE 210 211 #define ICH6_REG_IC 212 #define ICH6_REG_IR 213 #define ICH6_REG_IRS 214 #define ICH6_IRS_VALID 215 #define ICH6_IRS_BUSY 216 217 #define ICH6_REG_DPLBASE 218 #define ICH6_REG_DPUBASE 219 #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 226 #define ICH6_REG_SD_STS 227 #define ICH6_REG_SD_LPIB 228 #define ICH6_REG_SD_CBL 229 #define ICH6_REG_SD_LVI 230 #define ICH6_REG_SD_FIFOW 231 #define ICH6_REG_SD_FIFOSIZE 232 #define ICH6_REG_SD_FORMAT 233 #define ICH6_REG_SD_BDLPL 234 #define ICH6_REG_SD_BDLPU 225 #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 237 #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 246 #define ICH6_NUM_PLAYBACK 245 #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 250 #define ULI_NUM_PLAYBACK 249 #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 254 #define ATIHDMI_NUM_PLAYBACK 253 #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 258 #define TERA_NUM_PLAYBACK 257 #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 261 #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 265 #define AZX_MAX_BDL_ENTRIES 266 #define AZX_MAX_FRAG 264 #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 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 272 #define RIRB_INT_OVERRUN 273 #define RIRB_INT_MASK 271 #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 277 #define AZX_DEFAULT_CODECS 278 #define STATESTS_INT_MASK 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 287 #define SD_CTL_STREAM_TAG_SHIFT 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 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 294 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 302 #define ICH6_INT_GLOBAL_EN 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 306 #define ICH6_MAX_RIRB_ENTRIES 305 #define ICH6_MAX_CORB_ENTRIES 256 306 #define ICH6_MAX_RIRB_ENTRIES 256 307 307 308 308 /* position fix mode */ 309 309 enum { 310 311 312 313 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 332 #define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90 333 333 /* Define VIA HD Audio Device ID*/ 334 #define VIA_HDAC_DEVICE_ID 334 #define VIA_HDAC_DEVICE_ID 0x3288 335 335 336 336 /* HD Audio class code */ 337 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 337 #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 338 338 339 339 /* … … 341 341 342 342 struct azx_dev { 343 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 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 366 struct snd_pcm_substream *substream;/* assigned substream,367 368 369 unsigned int format_val;/* format value to be set in the370 371 372 unsigned char stream_tag;/* assigned stream */373 unsigned char index;/* stream index */374 int device;/* last device number assigned to */375 376 377 378 379 380 381 382 383 384 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 395 396 dma_addr_t addr;/* physical address of CORB/RIRB buffer */397 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 405 406 407 408 409 410 411 412 413 414 415 416 417 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 419 volatile void __iomem *remap_addr; 420 420 #else /* !TARGET_OS2 */ 421 421 void __iomem *remap_addr; 422 422 #endif /* !TARGET_OS2 */ 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 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 508 writel(value, (chip)->remap_addr + ICH6_REG_##reg) 507 509 #define azx_readl(chip,reg) \ 508 510 readl((chip)->remap_addr + ICH6_REG_##reg) 509 511 #define azx_writew(chip,reg,value) \ 510 512 writew(value, (chip)->remap_addr + ICH6_REG_##reg) 511 513 #define azx_readw(chip,reg) \ 512 514 readw((chip)->remap_addr + ICH6_REG_##reg) 513 515 #define azx_writeb(chip,reg,value) \ 514 516 writeb(value, (chip)->remap_addr + ICH6_REG_##reg) 515 517 #define azx_readb(chip,reg) \ 516 518 readb((chip)->remap_addr + ICH6_REG_##reg) 517 519 518 520 #define azx_sd_writel(dev,reg,value) \ 519 521 writel(value, (dev)->sd_addr + ICH6_REG_##reg) 520 522 #define azx_sd_readl(dev,reg) \ 521 523 readl((dev)->sd_addr + ICH6_REG_##reg) 522 524 #define azx_sd_writew(dev,reg,value) \ 523 525 writew(value, (dev)->sd_addr + ICH6_REG_##reg) 524 526 #define azx_sd_readw(dev,reg) \ 525 527 readw((dev)->sd_addr + ICH6_REG_##reg) 526 528 #define azx_sd_writeb(dev,reg,value) \ 527 529 writeb(value, (dev)->sd_addr + ICH6_REG_##reg) 528 530 #define azx_sd_readb(dev,reg) \ 529 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 546 547 548 549 550 551 552 553 554 555 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 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 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 601 602 603 604 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 610 611 612 613 614 615 616 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 622 623 624 625 626 627 628 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 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 } 653 654 #define ICH6_RIRB_EX_UNSOL_EV 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 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 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 693 { 694 695 694 unsigned int addr) 695 { 696 struct azx *chip = bus->private_data; 697 unsigned long timeout; 696 698 #ifdef TARGET_OS2 697 699 int count = 0; 698 700 #endif 699 701 int do_poll = 0; 700 702 701 703 again: 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 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 721 722 if (count >= 5000) /* Hack on OS/2 to stop infinite loop as jiffies sometimes don't increment */ 723 break; 722 724 #endif 723 724 725 726 727 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 732 count++; 731 733 #endif 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 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 753 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 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 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 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 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 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 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 861 { 862 863 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 877 878 879 880 881 882 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 888 { 889 890 891 892 893 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 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 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 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 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 963 964 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 971 972 973 974 975 976 977 978 979 980 981 982 983 984 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 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 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 1013 1014 1015 1016 1017 1018 1019 1020 1021 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 1028 1029 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 1036 1037 1038 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 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 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 1074 { 1075 1076 1077 1078 1079 1080 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 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 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 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 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 1189 1190 1190 /* clear state status int */ 1191 if (azx_readb(chip, STATESTS) & 0x04) 1192 azx_writeb(chip, STATESTS, 0x04); 1191 1193 #endif 1192 1194 spin_unlock(&chip->reg_lock); 1193 1195 1194 1196 #ifdef TARGET_OS2 … … 1198 1200 #endif 1199 1201 1200 1202 return IRQ_HANDLED; 1201 1203 } 1202 1204 … … 1206 1208 */ 1207 1209 static int setup_bdle(struct snd_pcm_substream *substream, 1208 1209 1210 { 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 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 1245 1246 { 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 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 1301 1302 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 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 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 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 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 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 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 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 1405 1406 1407 1408 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 1411 1412 1413 1414 1415 1416 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 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 1429 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 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 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 1448 1449 bus_temp.power_save = &power_save; 1450 bus_temp.ops.pm_notify = azx_power_notify; 1449 1451 #endif 1450 1452 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 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 1509 1510 1511 1512 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 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 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 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 1556 1557 1558 1559 1560 1561 1562 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 1579 1580 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 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 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 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 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 1663 { 1664 1665 1666 1667 1668 1669 1670 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 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 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 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 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 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 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 1852 { 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 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 1907 { 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 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 1932 1933 1934 1935 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 1950 1951 1952 1953 1954 1955 return -1;/* bogus (too early) interrupt */1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 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 1972 1973 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 1976 1977 1978 1979 1980 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 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 pending = 0;/* too early */2016 2017 2018 2019 2020 2021 2022 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 2030 2031 2032 2033 2034 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 2039 2040 2041 2042 2043 2044 2045 2046 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 2052 2053 2054 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 2061 { 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 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 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 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 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 2145 2146 2147 2148 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 2151 2152 if (do_disconnect) 2153 snd_card_disconnect(chip->card); 2152 2154 #endif 2153 2154 2155 2156 2157 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 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 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 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 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 2210 2211 2212 2213 2214 2215 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 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 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 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 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 2280 2281 2282 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 2288 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 2294 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 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 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 2321 iounmap((void *)chip->remap_addr); 2320 2322 #else 2321 2323 iounmap(chip->remap_addr); 2322 2324 #endif 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 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 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 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 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 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 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 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 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 2426 #define AZX_FORCE_CODEC_MASK 0x100 2425 2427 2426 2428 static void __devinit check_probe_mask(struct azx *chip, int dev) 2427 2429 { 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 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 2456 2457 2458 2459 2460 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 2466 2467 2468 2469 2470 2471 chip->msi = 1;/* enable MSI as default */2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 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 2494 2495 { 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 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 2546 2547 2548 2549 2550 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 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 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 2605 2606 2607 2608 2609 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 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 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 2702 2703 azx_free(chip); 2704 return err; 2703 2705 } 2704 2706 … … 2706 2708 { 2707 2709 #ifdef CONFIG_SND_HDA_POWER_SAVE 2708 2709 2710 2711 2712 2713 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 2720 { 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 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 2750 chip->beep_mode = beep_mode[dev]; 2749 2751 #endif 2750 2752 2751 2752 2753 2754 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 2757 2758 2759 2760 2761 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 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 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 2793 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 2799 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 2849 2850 2851 2852 2853 2854 2855 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 2858 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 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 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 2880 2881 2882 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 2885 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 2900 return pci_register_driver(&driver); 2892 2901 } 2893 2902 2894 2903 static void __exit alsa_card_azx_exit(void) 2895 2904 { 2896 2905 pci_unregister_driver(&driver); 2897 2906 } 2898 2907
Note:
See TracChangeset
for help on using the changeset viewer.