atiixp.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ALSA driver for ATI IXP 150/200/250/300 AC97 controllers
  4. *
  5. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  6. */
  7. #include <linux/io.h>
  8. #include <linux/delay.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/init.h>
  11. #include <linux/pci.h>
  12. #include <linux/slab.h>
  13. #include <linux/module.h>
  14. #include <linux/mutex.h>
  15. #include <sound/core.h>
  16. #include <sound/pcm.h>
  17. #include <sound/pcm_params.h>
  18. #include <sound/info.h>
  19. #include <sound/ac97_codec.h>
  20. #include <sound/initval.h>
  21. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  22. MODULE_DESCRIPTION("ATI IXP AC97 controller");
  23. MODULE_LICENSE("GPL");
  24. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  25. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  26. static int ac97_clock = 48000;
  27. static char *ac97_quirk;
  28. static bool spdif_aclink = 1;
  29. static int ac97_codec = -1;
  30. module_param(index, int, 0444);
  31. MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
  32. module_param(id, charp, 0444);
  33. MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
  34. module_param(ac97_clock, int, 0444);
  35. MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
  36. module_param(ac97_quirk, charp, 0444);
  37. MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
  38. module_param(ac97_codec, int, 0444);
  39. MODULE_PARM_DESC(ac97_codec, "Specify codec instead of probing.");
  40. module_param(spdif_aclink, bool, 0444);
  41. MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
  42. /* just for backward compatibility */
  43. static bool enable;
  44. module_param(enable, bool, 0444);
  45. /*
  46. */
  47. #define ATI_REG_ISR 0x00 /* interrupt source */
  48. #define ATI_REG_ISR_IN_XRUN (1U<<0)
  49. #define ATI_REG_ISR_IN_STATUS (1U<<1)
  50. #define ATI_REG_ISR_OUT_XRUN (1U<<2)
  51. #define ATI_REG_ISR_OUT_STATUS (1U<<3)
  52. #define ATI_REG_ISR_SPDF_XRUN (1U<<4)
  53. #define ATI_REG_ISR_SPDF_STATUS (1U<<5)
  54. #define ATI_REG_ISR_PHYS_INTR (1U<<8)
  55. #define ATI_REG_ISR_PHYS_MISMATCH (1U<<9)
  56. #define ATI_REG_ISR_CODEC0_NOT_READY (1U<<10)
  57. #define ATI_REG_ISR_CODEC1_NOT_READY (1U<<11)
  58. #define ATI_REG_ISR_CODEC2_NOT_READY (1U<<12)
  59. #define ATI_REG_ISR_NEW_FRAME (1U<<13)
  60. #define ATI_REG_IER 0x04 /* interrupt enable */
  61. #define ATI_REG_IER_IN_XRUN_EN (1U<<0)
  62. #define ATI_REG_IER_IO_STATUS_EN (1U<<1)
  63. #define ATI_REG_IER_OUT_XRUN_EN (1U<<2)
  64. #define ATI_REG_IER_OUT_XRUN_COND (1U<<3)
  65. #define ATI_REG_IER_SPDF_XRUN_EN (1U<<4)
  66. #define ATI_REG_IER_SPDF_STATUS_EN (1U<<5)
  67. #define ATI_REG_IER_PHYS_INTR_EN (1U<<8)
  68. #define ATI_REG_IER_PHYS_MISMATCH_EN (1U<<9)
  69. #define ATI_REG_IER_CODEC0_INTR_EN (1U<<10)
  70. #define ATI_REG_IER_CODEC1_INTR_EN (1U<<11)
  71. #define ATI_REG_IER_CODEC2_INTR_EN (1U<<12)
  72. #define ATI_REG_IER_NEW_FRAME_EN (1U<<13) /* (RO */
  73. #define ATI_REG_IER_SET_BUS_BUSY (1U<<14) /* (WO) audio is running */
  74. #define ATI_REG_CMD 0x08 /* command */
  75. #define ATI_REG_CMD_POWERDOWN (1U<<0)
  76. #define ATI_REG_CMD_RECEIVE_EN (1U<<1)
  77. #define ATI_REG_CMD_SEND_EN (1U<<2)
  78. #define ATI_REG_CMD_STATUS_MEM (1U<<3)
  79. #define ATI_REG_CMD_SPDF_OUT_EN (1U<<4)
  80. #define ATI_REG_CMD_SPDF_STATUS_MEM (1U<<5)
  81. #define ATI_REG_CMD_SPDF_THRESHOLD (3U<<6)
  82. #define ATI_REG_CMD_SPDF_THRESHOLD_SHIFT 6
  83. #define ATI_REG_CMD_IN_DMA_EN (1U<<8)
  84. #define ATI_REG_CMD_OUT_DMA_EN (1U<<9)
  85. #define ATI_REG_CMD_SPDF_DMA_EN (1U<<10)
  86. #define ATI_REG_CMD_SPDF_OUT_STOPPED (1U<<11)
  87. #define ATI_REG_CMD_SPDF_CONFIG_MASK (7U<<12)
  88. #define ATI_REG_CMD_SPDF_CONFIG_34 (1U<<12)
  89. #define ATI_REG_CMD_SPDF_CONFIG_78 (2U<<12)
  90. #define ATI_REG_CMD_SPDF_CONFIG_69 (3U<<12)
  91. #define ATI_REG_CMD_SPDF_CONFIG_01 (4U<<12)
  92. #define ATI_REG_CMD_INTERLEAVE_SPDF (1U<<16)
  93. #define ATI_REG_CMD_AUDIO_PRESENT (1U<<20)
  94. #define ATI_REG_CMD_INTERLEAVE_IN (1U<<21)
  95. #define ATI_REG_CMD_INTERLEAVE_OUT (1U<<22)
  96. #define ATI_REG_CMD_LOOPBACK_EN (1U<<23)
  97. #define ATI_REG_CMD_PACKED_DIS (1U<<24)
  98. #define ATI_REG_CMD_BURST_EN (1U<<25)
  99. #define ATI_REG_CMD_PANIC_EN (1U<<26)
  100. #define ATI_REG_CMD_MODEM_PRESENT (1U<<27)
  101. #define ATI_REG_CMD_ACLINK_ACTIVE (1U<<28)
  102. #define ATI_REG_CMD_AC_SOFT_RESET (1U<<29)
  103. #define ATI_REG_CMD_AC_SYNC (1U<<30)
  104. #define ATI_REG_CMD_AC_RESET (1U<<31)
  105. #define ATI_REG_PHYS_OUT_ADDR 0x0c
  106. #define ATI_REG_PHYS_OUT_CODEC_MASK (3U<<0)
  107. #define ATI_REG_PHYS_OUT_RW (1U<<2)
  108. #define ATI_REG_PHYS_OUT_ADDR_EN (1U<<8)
  109. #define ATI_REG_PHYS_OUT_ADDR_SHIFT 9
  110. #define ATI_REG_PHYS_OUT_DATA_SHIFT 16
  111. #define ATI_REG_PHYS_IN_ADDR 0x10
  112. #define ATI_REG_PHYS_IN_READ_FLAG (1U<<8)
  113. #define ATI_REG_PHYS_IN_ADDR_SHIFT 9
  114. #define ATI_REG_PHYS_IN_DATA_SHIFT 16
  115. #define ATI_REG_SLOTREQ 0x14
  116. #define ATI_REG_COUNTER 0x18
  117. #define ATI_REG_COUNTER_SLOT (3U<<0) /* slot # */
  118. #define ATI_REG_COUNTER_BITCLOCK (31U<<8)
  119. #define ATI_REG_IN_FIFO_THRESHOLD 0x1c
  120. #define ATI_REG_IN_DMA_LINKPTR 0x20
  121. #define ATI_REG_IN_DMA_DT_START 0x24 /* RO */
  122. #define ATI_REG_IN_DMA_DT_NEXT 0x28 /* RO */
  123. #define ATI_REG_IN_DMA_DT_CUR 0x2c /* RO */
  124. #define ATI_REG_IN_DMA_DT_SIZE 0x30
  125. #define ATI_REG_OUT_DMA_SLOT 0x34
  126. #define ATI_REG_OUT_DMA_SLOT_BIT(x) (1U << ((x) - 3))
  127. #define ATI_REG_OUT_DMA_SLOT_MASK 0x1ff
  128. #define ATI_REG_OUT_DMA_THRESHOLD_MASK 0xf800
  129. #define ATI_REG_OUT_DMA_THRESHOLD_SHIFT 11
  130. #define ATI_REG_OUT_DMA_LINKPTR 0x38
  131. #define ATI_REG_OUT_DMA_DT_START 0x3c /* RO */
  132. #define ATI_REG_OUT_DMA_DT_NEXT 0x40 /* RO */
  133. #define ATI_REG_OUT_DMA_DT_CUR 0x44 /* RO */
  134. #define ATI_REG_OUT_DMA_DT_SIZE 0x48
  135. #define ATI_REG_SPDF_CMD 0x4c
  136. #define ATI_REG_SPDF_CMD_LFSR (1U<<4)
  137. #define ATI_REG_SPDF_CMD_SINGLE_CH (1U<<5)
  138. #define ATI_REG_SPDF_CMD_LFSR_ACC (0xff<<8) /* RO */
  139. #define ATI_REG_SPDF_DMA_LINKPTR 0x50
  140. #define ATI_REG_SPDF_DMA_DT_START 0x54 /* RO */
  141. #define ATI_REG_SPDF_DMA_DT_NEXT 0x58 /* RO */
  142. #define ATI_REG_SPDF_DMA_DT_CUR 0x5c /* RO */
  143. #define ATI_REG_SPDF_DMA_DT_SIZE 0x60
  144. #define ATI_REG_MODEM_MIRROR 0x7c
  145. #define ATI_REG_AUDIO_MIRROR 0x80
  146. #define ATI_REG_6CH_REORDER 0x84 /* reorder slots for 6ch */
  147. #define ATI_REG_6CH_REORDER_EN (1U<<0) /* 3,4,7,8,6,9 -> 3,4,6,9,7,8 */
  148. #define ATI_REG_FIFO_FLUSH 0x88
  149. #define ATI_REG_FIFO_OUT_FLUSH (1U<<0)
  150. #define ATI_REG_FIFO_IN_FLUSH (1U<<1)
  151. /* LINKPTR */
  152. #define ATI_REG_LINKPTR_EN (1U<<0)
  153. /* [INT|OUT|SPDIF]_DMA_DT_SIZE */
  154. #define ATI_REG_DMA_DT_SIZE (0xffffU<<0)
  155. #define ATI_REG_DMA_FIFO_USED (0x1fU<<16)
  156. #define ATI_REG_DMA_FIFO_FREE (0x1fU<<21)
  157. #define ATI_REG_DMA_STATE (7U<<26)
  158. #define ATI_MAX_DESCRIPTORS 256 /* max number of descriptor packets */
  159. struct atiixp;
  160. /*
  161. * DMA packate descriptor
  162. */
  163. struct atiixp_dma_desc {
  164. __le32 addr; /* DMA buffer address */
  165. u16 status; /* status bits */
  166. u16 size; /* size of the packet in dwords */
  167. __le32 next; /* address of the next packet descriptor */
  168. };
  169. /*
  170. * stream enum
  171. */
  172. enum { ATI_DMA_PLAYBACK, ATI_DMA_CAPTURE, ATI_DMA_SPDIF, NUM_ATI_DMAS }; /* DMAs */
  173. enum { ATI_PCM_OUT, ATI_PCM_IN, ATI_PCM_SPDIF, NUM_ATI_PCMS }; /* AC97 pcm slots */
  174. enum { ATI_PCMDEV_ANALOG, ATI_PCMDEV_DIGITAL, NUM_ATI_PCMDEVS }; /* pcm devices */
  175. #define NUM_ATI_CODECS 3
  176. /*
  177. * constants and callbacks for each DMA type
  178. */
  179. struct atiixp_dma_ops {
  180. int type; /* ATI_DMA_XXX */
  181. unsigned int llp_offset; /* LINKPTR offset */
  182. unsigned int dt_cur; /* DT_CUR offset */
  183. /* called from open callback */
  184. void (*enable_dma)(struct atiixp *chip, int on);
  185. /* called from trigger (START/STOP) */
  186. void (*enable_transfer)(struct atiixp *chip, int on);
  187. /* called from trigger (STOP only) */
  188. void (*flush_dma)(struct atiixp *chip);
  189. };
  190. /*
  191. * DMA stream
  192. */
  193. struct atiixp_dma {
  194. const struct atiixp_dma_ops *ops;
  195. struct snd_dma_buffer desc_buf;
  196. struct snd_pcm_substream *substream; /* assigned PCM substream */
  197. unsigned int buf_addr, buf_bytes; /* DMA buffer address, bytes */
  198. unsigned int period_bytes, periods;
  199. int opened;
  200. int running;
  201. int suspended;
  202. int pcm_open_flag;
  203. int ac97_pcm_type; /* index # of ac97_pcm to access, -1 = not used */
  204. unsigned int saved_curptr;
  205. };
  206. /*
  207. * ATI IXP chip
  208. */
  209. struct atiixp {
  210. struct snd_card *card;
  211. struct pci_dev *pci;
  212. unsigned long addr;
  213. void __iomem *remap_addr;
  214. int irq;
  215. struct snd_ac97_bus *ac97_bus;
  216. struct snd_ac97 *ac97[NUM_ATI_CODECS];
  217. spinlock_t reg_lock;
  218. struct atiixp_dma dmas[NUM_ATI_DMAS];
  219. struct ac97_pcm *pcms[NUM_ATI_PCMS];
  220. struct snd_pcm *pcmdevs[NUM_ATI_PCMDEVS];
  221. int max_channels; /* max. channels for PCM out */
  222. unsigned int codec_not_ready_bits; /* for codec detection */
  223. int spdif_over_aclink; /* passed from the module option */
  224. struct mutex open_mutex; /* playback open mutex */
  225. };
  226. /*
  227. */
  228. static const struct pci_device_id snd_atiixp_ids[] = {
  229. { PCI_VDEVICE(ATI, 0x4341), 0 }, /* SB200 */
  230. { PCI_VDEVICE(ATI, 0x4361), 0 }, /* SB300 */
  231. { PCI_VDEVICE(ATI, 0x4370), 0 }, /* SB400 */
  232. { PCI_VDEVICE(ATI, 0x4382), 0 }, /* SB600 */
  233. { 0, }
  234. };
  235. MODULE_DEVICE_TABLE(pci, snd_atiixp_ids);
  236. static const struct snd_pci_quirk atiixp_quirks[] = {
  237. SND_PCI_QUIRK(0x105b, 0x0c81, "Foxconn RC4107MA-RS2", 0),
  238. SND_PCI_QUIRK(0x15bd, 0x3100, "DFI RS482", 0),
  239. { } /* terminator */
  240. };
  241. /*
  242. * lowlevel functions
  243. */
  244. /*
  245. * update the bits of the given register.
  246. * return 1 if the bits changed.
  247. */
  248. static int snd_atiixp_update_bits(struct atiixp *chip, unsigned int reg,
  249. unsigned int mask, unsigned int value)
  250. {
  251. void __iomem *addr = chip->remap_addr + reg;
  252. unsigned int data, old_data;
  253. old_data = data = readl(addr);
  254. data &= ~mask;
  255. data |= value;
  256. if (old_data == data)
  257. return 0;
  258. writel(data, addr);
  259. return 1;
  260. }
  261. /*
  262. * macros for easy use
  263. */
  264. #define atiixp_write(chip,reg,value) \
  265. writel(value, chip->remap_addr + ATI_REG_##reg)
  266. #define atiixp_read(chip,reg) \
  267. readl(chip->remap_addr + ATI_REG_##reg)
  268. #define atiixp_update(chip,reg,mask,val) \
  269. snd_atiixp_update_bits(chip, ATI_REG_##reg, mask, val)
  270. /*
  271. * handling DMA packets
  272. *
  273. * we allocate a linear buffer for the DMA, and split it to each packet.
  274. * in a future version, a scatter-gather buffer should be implemented.
  275. */
  276. #define ATI_DESC_LIST_SIZE \
  277. PAGE_ALIGN(ATI_MAX_DESCRIPTORS * sizeof(struct atiixp_dma_desc))
  278. /*
  279. * build packets ring for the given buffer size.
  280. *
  281. * IXP handles the buffer descriptors, which are connected as a linked
  282. * list. although we can change the list dynamically, in this version,
  283. * a static RING of buffer descriptors is used.
  284. *
  285. * the ring is built in this function, and is set up to the hardware.
  286. */
  287. static int atiixp_build_dma_packets(struct atiixp *chip, struct atiixp_dma *dma,
  288. struct snd_pcm_substream *substream,
  289. unsigned int periods,
  290. unsigned int period_bytes)
  291. {
  292. unsigned int i;
  293. u32 addr, desc_addr;
  294. unsigned long flags;
  295. if (periods > ATI_MAX_DESCRIPTORS)
  296. return -ENOMEM;
  297. if (dma->desc_buf.area == NULL) {
  298. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  299. &chip->pci->dev,
  300. ATI_DESC_LIST_SIZE,
  301. &dma->desc_buf) < 0)
  302. return -ENOMEM;
  303. dma->period_bytes = dma->periods = 0; /* clear */
  304. }
  305. if (dma->periods == periods && dma->period_bytes == period_bytes)
  306. return 0;
  307. /* reset DMA before changing the descriptor table */
  308. spin_lock_irqsave(&chip->reg_lock, flags);
  309. writel(0, chip->remap_addr + dma->ops->llp_offset);
  310. dma->ops->enable_dma(chip, 0);
  311. dma->ops->enable_dma(chip, 1);
  312. spin_unlock_irqrestore(&chip->reg_lock, flags);
  313. /* fill the entries */
  314. addr = (u32)substream->runtime->dma_addr;
  315. desc_addr = (u32)dma->desc_buf.addr;
  316. for (i = 0; i < periods; i++) {
  317. struct atiixp_dma_desc *desc;
  318. desc = &((struct atiixp_dma_desc *)dma->desc_buf.area)[i];
  319. desc->addr = cpu_to_le32(addr);
  320. desc->status = 0;
  321. desc->size = period_bytes >> 2; /* in dwords */
  322. desc_addr += sizeof(struct atiixp_dma_desc);
  323. if (i == periods - 1)
  324. desc->next = cpu_to_le32((u32)dma->desc_buf.addr);
  325. else
  326. desc->next = cpu_to_le32(desc_addr);
  327. addr += period_bytes;
  328. }
  329. writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN,
  330. chip->remap_addr + dma->ops->llp_offset);
  331. dma->period_bytes = period_bytes;
  332. dma->periods = periods;
  333. return 0;
  334. }
  335. /*
  336. * remove the ring buffer and release it if assigned
  337. */
  338. static void atiixp_clear_dma_packets(struct atiixp *chip, struct atiixp_dma *dma,
  339. struct snd_pcm_substream *substream)
  340. {
  341. if (dma->desc_buf.area) {
  342. writel(0, chip->remap_addr + dma->ops->llp_offset);
  343. snd_dma_free_pages(&dma->desc_buf);
  344. dma->desc_buf.area = NULL;
  345. }
  346. }
  347. /*
  348. * AC97 interface
  349. */
  350. static int snd_atiixp_acquire_codec(struct atiixp *chip)
  351. {
  352. int timeout = 1000;
  353. while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) {
  354. if (! timeout--) {
  355. dev_warn(chip->card->dev, "codec acquire timeout\n");
  356. return -EBUSY;
  357. }
  358. udelay(1);
  359. }
  360. return 0;
  361. }
  362. static unsigned short snd_atiixp_codec_read(struct atiixp *chip, unsigned short codec, unsigned short reg)
  363. {
  364. unsigned int data;
  365. int timeout;
  366. if (snd_atiixp_acquire_codec(chip) < 0)
  367. return 0xffff;
  368. data = (reg << ATI_REG_PHYS_OUT_ADDR_SHIFT) |
  369. ATI_REG_PHYS_OUT_ADDR_EN |
  370. ATI_REG_PHYS_OUT_RW |
  371. codec;
  372. atiixp_write(chip, PHYS_OUT_ADDR, data);
  373. if (snd_atiixp_acquire_codec(chip) < 0)
  374. return 0xffff;
  375. timeout = 1000;
  376. do {
  377. data = atiixp_read(chip, PHYS_IN_ADDR);
  378. if (data & ATI_REG_PHYS_IN_READ_FLAG)
  379. return data >> ATI_REG_PHYS_IN_DATA_SHIFT;
  380. udelay(1);
  381. } while (--timeout);
  382. /* time out may happen during reset */
  383. if (reg < 0x7c)
  384. dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg);
  385. return 0xffff;
  386. }
  387. static void snd_atiixp_codec_write(struct atiixp *chip, unsigned short codec,
  388. unsigned short reg, unsigned short val)
  389. {
  390. unsigned int data;
  391. if (snd_atiixp_acquire_codec(chip) < 0)
  392. return;
  393. data = ((unsigned int)val << ATI_REG_PHYS_OUT_DATA_SHIFT) |
  394. ((unsigned int)reg << ATI_REG_PHYS_OUT_ADDR_SHIFT) |
  395. ATI_REG_PHYS_OUT_ADDR_EN | codec;
  396. atiixp_write(chip, PHYS_OUT_ADDR, data);
  397. }
  398. static unsigned short snd_atiixp_ac97_read(struct snd_ac97 *ac97,
  399. unsigned short reg)
  400. {
  401. struct atiixp *chip = ac97->private_data;
  402. return snd_atiixp_codec_read(chip, ac97->num, reg);
  403. }
  404. static void snd_atiixp_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
  405. unsigned short val)
  406. {
  407. struct atiixp *chip = ac97->private_data;
  408. snd_atiixp_codec_write(chip, ac97->num, reg, val);
  409. }
  410. /*
  411. * reset AC link
  412. */
  413. static int snd_atiixp_aclink_reset(struct atiixp *chip)
  414. {
  415. int timeout;
  416. /* reset powerdoewn */
  417. if (atiixp_update(chip, CMD, ATI_REG_CMD_POWERDOWN, 0))
  418. udelay(10);
  419. /* perform a software reset */
  420. atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, ATI_REG_CMD_AC_SOFT_RESET);
  421. atiixp_read(chip, CMD);
  422. udelay(10);
  423. atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, 0);
  424. timeout = 10;
  425. while (! (atiixp_read(chip, CMD) & ATI_REG_CMD_ACLINK_ACTIVE)) {
  426. /* do a hard reset */
  427. atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
  428. ATI_REG_CMD_AC_SYNC);
  429. atiixp_read(chip, CMD);
  430. mdelay(1);
  431. atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
  432. if (!--timeout) {
  433. dev_err(chip->card->dev, "codec reset timeout\n");
  434. break;
  435. }
  436. }
  437. /* deassert RESET and assert SYNC to make sure */
  438. atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
  439. ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET);
  440. return 0;
  441. }
  442. static int snd_atiixp_aclink_down(struct atiixp *chip)
  443. {
  444. // if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */
  445. // return -EBUSY;
  446. atiixp_update(chip, CMD,
  447. ATI_REG_CMD_POWERDOWN | ATI_REG_CMD_AC_RESET,
  448. ATI_REG_CMD_POWERDOWN);
  449. return 0;
  450. }
  451. /*
  452. * auto-detection of codecs
  453. *
  454. * the IXP chip can generate interrupts for the non-existing codecs.
  455. * NEW_FRAME interrupt is used to make sure that the interrupt is generated
  456. * even if all three codecs are connected.
  457. */
  458. #define ALL_CODEC_NOT_READY \
  459. (ATI_REG_ISR_CODEC0_NOT_READY |\
  460. ATI_REG_ISR_CODEC1_NOT_READY |\
  461. ATI_REG_ISR_CODEC2_NOT_READY)
  462. #define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME)
  463. static int ac97_probing_bugs(struct pci_dev *pci)
  464. {
  465. const struct snd_pci_quirk *q;
  466. q = snd_pci_quirk_lookup(pci, atiixp_quirks);
  467. if (q) {
  468. dev_dbg(&pci->dev, "atiixp quirk for %s. Forcing codec %d\n",
  469. snd_pci_quirk_name(q), q->value);
  470. return q->value;
  471. }
  472. /* this hardware doesn't need workarounds. Probe for codec */
  473. return -1;
  474. }
  475. static int snd_atiixp_codec_detect(struct atiixp *chip)
  476. {
  477. int timeout;
  478. chip->codec_not_ready_bits = 0;
  479. if (ac97_codec == -1)
  480. ac97_codec = ac97_probing_bugs(chip->pci);
  481. if (ac97_codec >= 0) {
  482. chip->codec_not_ready_bits |=
  483. CODEC_CHECK_BITS ^ (1 << (ac97_codec + 10));
  484. return 0;
  485. }
  486. atiixp_write(chip, IER, CODEC_CHECK_BITS);
  487. /* wait for the interrupts */
  488. timeout = 50;
  489. while (timeout-- > 0) {
  490. mdelay(1);
  491. if (chip->codec_not_ready_bits)
  492. break;
  493. }
  494. atiixp_write(chip, IER, 0); /* disable irqs */
  495. if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
  496. dev_err(chip->card->dev, "no codec detected!\n");
  497. return -ENXIO;
  498. }
  499. return 0;
  500. }
  501. /*
  502. * enable DMA and irqs
  503. */
  504. static int snd_atiixp_chip_start(struct atiixp *chip)
  505. {
  506. unsigned int reg;
  507. /* set up spdif, enable burst mode */
  508. reg = atiixp_read(chip, CMD);
  509. reg |= 0x02 << ATI_REG_CMD_SPDF_THRESHOLD_SHIFT;
  510. reg |= ATI_REG_CMD_BURST_EN;
  511. atiixp_write(chip, CMD, reg);
  512. reg = atiixp_read(chip, SPDF_CMD);
  513. reg &= ~(ATI_REG_SPDF_CMD_LFSR|ATI_REG_SPDF_CMD_SINGLE_CH);
  514. atiixp_write(chip, SPDF_CMD, reg);
  515. /* clear all interrupt source */
  516. atiixp_write(chip, ISR, 0xffffffff);
  517. /* enable irqs */
  518. atiixp_write(chip, IER,
  519. ATI_REG_IER_IO_STATUS_EN |
  520. ATI_REG_IER_IN_XRUN_EN |
  521. ATI_REG_IER_OUT_XRUN_EN |
  522. ATI_REG_IER_SPDF_XRUN_EN |
  523. ATI_REG_IER_SPDF_STATUS_EN);
  524. return 0;
  525. }
  526. /*
  527. * disable DMA and IRQs
  528. */
  529. static int snd_atiixp_chip_stop(struct atiixp *chip)
  530. {
  531. /* clear interrupt source */
  532. atiixp_write(chip, ISR, atiixp_read(chip, ISR));
  533. /* disable irqs */
  534. atiixp_write(chip, IER, 0);
  535. return 0;
  536. }
  537. /*
  538. * PCM section
  539. */
  540. /*
  541. * pointer callback simplly reads XXX_DMA_DT_CUR register as the current
  542. * position. when SG-buffer is implemented, the offset must be calculated
  543. * correctly...
  544. */
  545. static snd_pcm_uframes_t snd_atiixp_pcm_pointer(struct snd_pcm_substream *substream)
  546. {
  547. struct atiixp *chip = snd_pcm_substream_chip(substream);
  548. struct snd_pcm_runtime *runtime = substream->runtime;
  549. struct atiixp_dma *dma = runtime->private_data;
  550. unsigned int curptr;
  551. int timeout = 1000;
  552. while (timeout--) {
  553. curptr = readl(chip->remap_addr + dma->ops->dt_cur);
  554. if (curptr < dma->buf_addr)
  555. continue;
  556. curptr -= dma->buf_addr;
  557. if (curptr >= dma->buf_bytes)
  558. continue;
  559. return bytes_to_frames(runtime, curptr);
  560. }
  561. dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n",
  562. readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);
  563. return 0;
  564. }
  565. /*
  566. * XRUN detected, and stop the PCM substream
  567. */
  568. static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma)
  569. {
  570. if (! dma->substream || ! dma->running)
  571. return;
  572. dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
  573. snd_pcm_stop_xrun(dma->substream);
  574. }
  575. /*
  576. * the period ack. update the substream.
  577. */
  578. static void snd_atiixp_update_dma(struct atiixp *chip, struct atiixp_dma *dma)
  579. {
  580. if (! dma->substream || ! dma->running)
  581. return;
  582. snd_pcm_period_elapsed(dma->substream);
  583. }
  584. /* set BUS_BUSY interrupt bit if any DMA is running */
  585. /* call with spinlock held */
  586. static void snd_atiixp_check_bus_busy(struct atiixp *chip)
  587. {
  588. unsigned int bus_busy;
  589. if (atiixp_read(chip, CMD) & (ATI_REG_CMD_SEND_EN |
  590. ATI_REG_CMD_RECEIVE_EN |
  591. ATI_REG_CMD_SPDF_OUT_EN))
  592. bus_busy = ATI_REG_IER_SET_BUS_BUSY;
  593. else
  594. bus_busy = 0;
  595. atiixp_update(chip, IER, ATI_REG_IER_SET_BUS_BUSY, bus_busy);
  596. }
  597. /* common trigger callback
  598. * calling the lowlevel callbacks in it
  599. */
  600. static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  601. {
  602. struct atiixp *chip = snd_pcm_substream_chip(substream);
  603. struct atiixp_dma *dma = substream->runtime->private_data;
  604. int err = 0;
  605. if (snd_BUG_ON(!dma->ops->enable_transfer ||
  606. !dma->ops->flush_dma))
  607. return -EINVAL;
  608. spin_lock(&chip->reg_lock);
  609. switch (cmd) {
  610. case SNDRV_PCM_TRIGGER_START:
  611. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  612. case SNDRV_PCM_TRIGGER_RESUME:
  613. if (dma->running && dma->suspended &&
  614. cmd == SNDRV_PCM_TRIGGER_RESUME)
  615. writel(dma->saved_curptr, chip->remap_addr +
  616. dma->ops->dt_cur);
  617. dma->ops->enable_transfer(chip, 1);
  618. dma->running = 1;
  619. dma->suspended = 0;
  620. break;
  621. case SNDRV_PCM_TRIGGER_STOP:
  622. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  623. case SNDRV_PCM_TRIGGER_SUSPEND:
  624. dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND;
  625. if (dma->running && dma->suspended)
  626. dma->saved_curptr = readl(chip->remap_addr +
  627. dma->ops->dt_cur);
  628. dma->ops->enable_transfer(chip, 0);
  629. dma->running = 0;
  630. break;
  631. default:
  632. err = -EINVAL;
  633. break;
  634. }
  635. if (! err) {
  636. snd_atiixp_check_bus_busy(chip);
  637. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  638. dma->ops->flush_dma(chip);
  639. snd_atiixp_check_bus_busy(chip);
  640. }
  641. }
  642. spin_unlock(&chip->reg_lock);
  643. return err;
  644. }
  645. /*
  646. * lowlevel callbacks for each DMA type
  647. *
  648. * every callback is supposed to be called in chip->reg_lock spinlock
  649. */
  650. /* flush FIFO of analog OUT DMA */
  651. static void atiixp_out_flush_dma(struct atiixp *chip)
  652. {
  653. atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_OUT_FLUSH);
  654. }
  655. /* enable/disable analog OUT DMA */
  656. static void atiixp_out_enable_dma(struct atiixp *chip, int on)
  657. {
  658. unsigned int data;
  659. data = atiixp_read(chip, CMD);
  660. if (on) {
  661. if (data & ATI_REG_CMD_OUT_DMA_EN)
  662. return;
  663. atiixp_out_flush_dma(chip);
  664. data |= ATI_REG_CMD_OUT_DMA_EN;
  665. } else
  666. data &= ~ATI_REG_CMD_OUT_DMA_EN;
  667. atiixp_write(chip, CMD, data);
  668. }
  669. /* start/stop transfer over OUT DMA */
  670. static void atiixp_out_enable_transfer(struct atiixp *chip, int on)
  671. {
  672. atiixp_update(chip, CMD, ATI_REG_CMD_SEND_EN,
  673. on ? ATI_REG_CMD_SEND_EN : 0);
  674. }
  675. /* enable/disable analog IN DMA */
  676. static void atiixp_in_enable_dma(struct atiixp *chip, int on)
  677. {
  678. atiixp_update(chip, CMD, ATI_REG_CMD_IN_DMA_EN,
  679. on ? ATI_REG_CMD_IN_DMA_EN : 0);
  680. }
  681. /* start/stop analog IN DMA */
  682. static void atiixp_in_enable_transfer(struct atiixp *chip, int on)
  683. {
  684. if (on) {
  685. unsigned int data = atiixp_read(chip, CMD);
  686. if (! (data & ATI_REG_CMD_RECEIVE_EN)) {
  687. data |= ATI_REG_CMD_RECEIVE_EN;
  688. #if 0 /* FIXME: this causes the endless loop */
  689. /* wait until slot 3/4 are finished */
  690. while ((atiixp_read(chip, COUNTER) &
  691. ATI_REG_COUNTER_SLOT) != 5)
  692. ;
  693. #endif
  694. atiixp_write(chip, CMD, data);
  695. }
  696. } else
  697. atiixp_update(chip, CMD, ATI_REG_CMD_RECEIVE_EN, 0);
  698. }
  699. /* flush FIFO of analog IN DMA */
  700. static void atiixp_in_flush_dma(struct atiixp *chip)
  701. {
  702. atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_IN_FLUSH);
  703. }
  704. /* enable/disable SPDIF OUT DMA */
  705. static void atiixp_spdif_enable_dma(struct atiixp *chip, int on)
  706. {
  707. atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_DMA_EN,
  708. on ? ATI_REG_CMD_SPDF_DMA_EN : 0);
  709. }
  710. /* start/stop SPDIF OUT DMA */
  711. static void atiixp_spdif_enable_transfer(struct atiixp *chip, int on)
  712. {
  713. unsigned int data;
  714. data = atiixp_read(chip, CMD);
  715. if (on)
  716. data |= ATI_REG_CMD_SPDF_OUT_EN;
  717. else
  718. data &= ~ATI_REG_CMD_SPDF_OUT_EN;
  719. atiixp_write(chip, CMD, data);
  720. }
  721. /* flush FIFO of SPDIF OUT DMA */
  722. static void atiixp_spdif_flush_dma(struct atiixp *chip)
  723. {
  724. int timeout;
  725. /* DMA off, transfer on */
  726. atiixp_spdif_enable_dma(chip, 0);
  727. atiixp_spdif_enable_transfer(chip, 1);
  728. timeout = 100;
  729. do {
  730. if (! (atiixp_read(chip, SPDF_DMA_DT_SIZE) & ATI_REG_DMA_FIFO_USED))
  731. break;
  732. udelay(1);
  733. } while (timeout-- > 0);
  734. atiixp_spdif_enable_transfer(chip, 0);
  735. }
  736. /* set up slots and formats for SPDIF OUT */
  737. static int snd_atiixp_spdif_prepare(struct snd_pcm_substream *substream)
  738. {
  739. struct atiixp *chip = snd_pcm_substream_chip(substream);
  740. spin_lock_irq(&chip->reg_lock);
  741. if (chip->spdif_over_aclink) {
  742. unsigned int data;
  743. /* enable slots 10/11 */
  744. atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_CONFIG_MASK,
  745. ATI_REG_CMD_SPDF_CONFIG_01);
  746. data = atiixp_read(chip, OUT_DMA_SLOT) & ~ATI_REG_OUT_DMA_SLOT_MASK;
  747. data |= ATI_REG_OUT_DMA_SLOT_BIT(10) |
  748. ATI_REG_OUT_DMA_SLOT_BIT(11);
  749. data |= 0x04 << ATI_REG_OUT_DMA_THRESHOLD_SHIFT;
  750. atiixp_write(chip, OUT_DMA_SLOT, data);
  751. atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_OUT,
  752. substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE ?
  753. ATI_REG_CMD_INTERLEAVE_OUT : 0);
  754. } else {
  755. atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_CONFIG_MASK, 0);
  756. atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_SPDF, 0);
  757. }
  758. spin_unlock_irq(&chip->reg_lock);
  759. return 0;
  760. }
  761. /* set up slots and formats for analog OUT */
  762. static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream)
  763. {
  764. struct atiixp *chip = snd_pcm_substream_chip(substream);
  765. unsigned int data;
  766. spin_lock_irq(&chip->reg_lock);
  767. data = atiixp_read(chip, OUT_DMA_SLOT) & ~ATI_REG_OUT_DMA_SLOT_MASK;
  768. switch (substream->runtime->channels) {
  769. case 8:
  770. data |= ATI_REG_OUT_DMA_SLOT_BIT(10) |
  771. ATI_REG_OUT_DMA_SLOT_BIT(11);
  772. fallthrough;
  773. case 6:
  774. data |= ATI_REG_OUT_DMA_SLOT_BIT(7) |
  775. ATI_REG_OUT_DMA_SLOT_BIT(8);
  776. fallthrough;
  777. case 4:
  778. data |= ATI_REG_OUT_DMA_SLOT_BIT(6) |
  779. ATI_REG_OUT_DMA_SLOT_BIT(9);
  780. fallthrough;
  781. default:
  782. data |= ATI_REG_OUT_DMA_SLOT_BIT(3) |
  783. ATI_REG_OUT_DMA_SLOT_BIT(4);
  784. break;
  785. }
  786. /* set output threshold */
  787. data |= 0x04 << ATI_REG_OUT_DMA_THRESHOLD_SHIFT;
  788. atiixp_write(chip, OUT_DMA_SLOT, data);
  789. atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_OUT,
  790. substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE ?
  791. ATI_REG_CMD_INTERLEAVE_OUT : 0);
  792. /*
  793. * enable 6 channel re-ordering bit if needed
  794. */
  795. atiixp_update(chip, 6CH_REORDER, ATI_REG_6CH_REORDER_EN,
  796. substream->runtime->channels >= 6 ? ATI_REG_6CH_REORDER_EN: 0);
  797. spin_unlock_irq(&chip->reg_lock);
  798. return 0;
  799. }
  800. /* set up slots and formats for analog IN */
  801. static int snd_atiixp_capture_prepare(struct snd_pcm_substream *substream)
  802. {
  803. struct atiixp *chip = snd_pcm_substream_chip(substream);
  804. spin_lock_irq(&chip->reg_lock);
  805. atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_IN,
  806. substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE ?
  807. ATI_REG_CMD_INTERLEAVE_IN : 0);
  808. spin_unlock_irq(&chip->reg_lock);
  809. return 0;
  810. }
  811. /*
  812. * hw_params - allocate the buffer and set up buffer descriptors
  813. */
  814. static int snd_atiixp_pcm_hw_params(struct snd_pcm_substream *substream,
  815. struct snd_pcm_hw_params *hw_params)
  816. {
  817. struct atiixp *chip = snd_pcm_substream_chip(substream);
  818. struct atiixp_dma *dma = substream->runtime->private_data;
  819. int err;
  820. dma->buf_addr = substream->runtime->dma_addr;
  821. dma->buf_bytes = params_buffer_bytes(hw_params);
  822. err = atiixp_build_dma_packets(chip, dma, substream,
  823. params_periods(hw_params),
  824. params_period_bytes(hw_params));
  825. if (err < 0)
  826. return err;
  827. if (dma->ac97_pcm_type >= 0) {
  828. struct ac97_pcm *pcm = chip->pcms[dma->ac97_pcm_type];
  829. /* PCM is bound to AC97 codec(s)
  830. * set up the AC97 codecs
  831. */
  832. if (dma->pcm_open_flag) {
  833. snd_ac97_pcm_close(pcm);
  834. dma->pcm_open_flag = 0;
  835. }
  836. err = snd_ac97_pcm_open(pcm, params_rate(hw_params),
  837. params_channels(hw_params),
  838. pcm->r[0].slots);
  839. if (err >= 0)
  840. dma->pcm_open_flag = 1;
  841. }
  842. return err;
  843. }
  844. static int snd_atiixp_pcm_hw_free(struct snd_pcm_substream *substream)
  845. {
  846. struct atiixp *chip = snd_pcm_substream_chip(substream);
  847. struct atiixp_dma *dma = substream->runtime->private_data;
  848. if (dma->pcm_open_flag) {
  849. struct ac97_pcm *pcm = chip->pcms[dma->ac97_pcm_type];
  850. snd_ac97_pcm_close(pcm);
  851. dma->pcm_open_flag = 0;
  852. }
  853. atiixp_clear_dma_packets(chip, dma, substream);
  854. return 0;
  855. }
  856. /*
  857. * pcm hardware definition, identical for all DMA types
  858. */
  859. static const struct snd_pcm_hardware snd_atiixp_pcm_hw =
  860. {
  861. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  862. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  863. SNDRV_PCM_INFO_PAUSE |
  864. SNDRV_PCM_INFO_RESUME |
  865. SNDRV_PCM_INFO_MMAP_VALID),
  866. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
  867. .rates = SNDRV_PCM_RATE_48000,
  868. .rate_min = 48000,
  869. .rate_max = 48000,
  870. .channels_min = 2,
  871. .channels_max = 2,
  872. .buffer_bytes_max = 256 * 1024,
  873. .period_bytes_min = 32,
  874. .period_bytes_max = 128 * 1024,
  875. .periods_min = 2,
  876. .periods_max = ATI_MAX_DESCRIPTORS,
  877. };
  878. static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream,
  879. struct atiixp_dma *dma, int pcm_type)
  880. {
  881. struct atiixp *chip = snd_pcm_substream_chip(substream);
  882. struct snd_pcm_runtime *runtime = substream->runtime;
  883. int err;
  884. if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
  885. return -EINVAL;
  886. if (dma->opened)
  887. return -EBUSY;
  888. dma->substream = substream;
  889. runtime->hw = snd_atiixp_pcm_hw;
  890. dma->ac97_pcm_type = pcm_type;
  891. if (pcm_type >= 0) {
  892. runtime->hw.rates = chip->pcms[pcm_type]->rates;
  893. snd_pcm_limit_hw_rates(runtime);
  894. } else {
  895. /* direct SPDIF */
  896. runtime->hw.formats = SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
  897. }
  898. err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  899. if (err < 0)
  900. return err;
  901. runtime->private_data = dma;
  902. /* enable DMA bits */
  903. spin_lock_irq(&chip->reg_lock);
  904. dma->ops->enable_dma(chip, 1);
  905. spin_unlock_irq(&chip->reg_lock);
  906. dma->opened = 1;
  907. return 0;
  908. }
  909. static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,
  910. struct atiixp_dma *dma)
  911. {
  912. struct atiixp *chip = snd_pcm_substream_chip(substream);
  913. /* disable DMA bits */
  914. if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma))
  915. return -EINVAL;
  916. spin_lock_irq(&chip->reg_lock);
  917. dma->ops->enable_dma(chip, 0);
  918. spin_unlock_irq(&chip->reg_lock);
  919. dma->substream = NULL;
  920. dma->opened = 0;
  921. return 0;
  922. }
  923. /*
  924. */
  925. static int snd_atiixp_playback_open(struct snd_pcm_substream *substream)
  926. {
  927. struct atiixp *chip = snd_pcm_substream_chip(substream);
  928. int err;
  929. mutex_lock(&chip->open_mutex);
  930. err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 0);
  931. mutex_unlock(&chip->open_mutex);
  932. if (err < 0)
  933. return err;
  934. substream->runtime->hw.channels_max = chip->max_channels;
  935. if (chip->max_channels > 2)
  936. /* channels must be even */
  937. snd_pcm_hw_constraint_step(substream->runtime, 0,
  938. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  939. return 0;
  940. }
  941. static int snd_atiixp_playback_close(struct snd_pcm_substream *substream)
  942. {
  943. struct atiixp *chip = snd_pcm_substream_chip(substream);
  944. int err;
  945. mutex_lock(&chip->open_mutex);
  946. err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
  947. mutex_unlock(&chip->open_mutex);
  948. return err;
  949. }
  950. static int snd_atiixp_capture_open(struct snd_pcm_substream *substream)
  951. {
  952. struct atiixp *chip = snd_pcm_substream_chip(substream);
  953. return snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_CAPTURE], 1);
  954. }
  955. static int snd_atiixp_capture_close(struct snd_pcm_substream *substream)
  956. {
  957. struct atiixp *chip = snd_pcm_substream_chip(substream);
  958. return snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_CAPTURE]);
  959. }
  960. static int snd_atiixp_spdif_open(struct snd_pcm_substream *substream)
  961. {
  962. struct atiixp *chip = snd_pcm_substream_chip(substream);
  963. int err;
  964. mutex_lock(&chip->open_mutex);
  965. if (chip->spdif_over_aclink) /* share DMA_PLAYBACK */
  966. err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 2);
  967. else
  968. err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_SPDIF], -1);
  969. mutex_unlock(&chip->open_mutex);
  970. return err;
  971. }
  972. static int snd_atiixp_spdif_close(struct snd_pcm_substream *substream)
  973. {
  974. struct atiixp *chip = snd_pcm_substream_chip(substream);
  975. int err;
  976. mutex_lock(&chip->open_mutex);
  977. if (chip->spdif_over_aclink)
  978. err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
  979. else
  980. err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_SPDIF]);
  981. mutex_unlock(&chip->open_mutex);
  982. return err;
  983. }
  984. /* AC97 playback */
  985. static const struct snd_pcm_ops snd_atiixp_playback_ops = {
  986. .open = snd_atiixp_playback_open,
  987. .close = snd_atiixp_playback_close,
  988. .hw_params = snd_atiixp_pcm_hw_params,
  989. .hw_free = snd_atiixp_pcm_hw_free,
  990. .prepare = snd_atiixp_playback_prepare,
  991. .trigger = snd_atiixp_pcm_trigger,
  992. .pointer = snd_atiixp_pcm_pointer,
  993. };
  994. /* AC97 capture */
  995. static const struct snd_pcm_ops snd_atiixp_capture_ops = {
  996. .open = snd_atiixp_capture_open,
  997. .close = snd_atiixp_capture_close,
  998. .hw_params = snd_atiixp_pcm_hw_params,
  999. .hw_free = snd_atiixp_pcm_hw_free,
  1000. .prepare = snd_atiixp_capture_prepare,
  1001. .trigger = snd_atiixp_pcm_trigger,
  1002. .pointer = snd_atiixp_pcm_pointer,
  1003. };
  1004. /* SPDIF playback */
  1005. static const struct snd_pcm_ops snd_atiixp_spdif_ops = {
  1006. .open = snd_atiixp_spdif_open,
  1007. .close = snd_atiixp_spdif_close,
  1008. .hw_params = snd_atiixp_pcm_hw_params,
  1009. .hw_free = snd_atiixp_pcm_hw_free,
  1010. .prepare = snd_atiixp_spdif_prepare,
  1011. .trigger = snd_atiixp_pcm_trigger,
  1012. .pointer = snd_atiixp_pcm_pointer,
  1013. };
  1014. static const struct ac97_pcm atiixp_pcm_defs[] = {
  1015. /* front PCM */
  1016. {
  1017. .exclusive = 1,
  1018. .r = { {
  1019. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1020. (1 << AC97_SLOT_PCM_RIGHT) |
  1021. (1 << AC97_SLOT_PCM_CENTER) |
  1022. (1 << AC97_SLOT_PCM_SLEFT) |
  1023. (1 << AC97_SLOT_PCM_SRIGHT) |
  1024. (1 << AC97_SLOT_LFE)
  1025. }
  1026. }
  1027. },
  1028. /* PCM IN #1 */
  1029. {
  1030. .stream = 1,
  1031. .exclusive = 1,
  1032. .r = { {
  1033. .slots = (1 << AC97_SLOT_PCM_LEFT) |
  1034. (1 << AC97_SLOT_PCM_RIGHT)
  1035. }
  1036. }
  1037. },
  1038. /* S/PDIF OUT (optional) */
  1039. {
  1040. .exclusive = 1,
  1041. .spdif = 1,
  1042. .r = { {
  1043. .slots = (1 << AC97_SLOT_SPDIF_LEFT2) |
  1044. (1 << AC97_SLOT_SPDIF_RIGHT2)
  1045. }
  1046. }
  1047. },
  1048. };
  1049. static const struct atiixp_dma_ops snd_atiixp_playback_dma_ops = {
  1050. .type = ATI_DMA_PLAYBACK,
  1051. .llp_offset = ATI_REG_OUT_DMA_LINKPTR,
  1052. .dt_cur = ATI_REG_OUT_DMA_DT_CUR,
  1053. .enable_dma = atiixp_out_enable_dma,
  1054. .enable_transfer = atiixp_out_enable_transfer,
  1055. .flush_dma = atiixp_out_flush_dma,
  1056. };
  1057. static const struct atiixp_dma_ops snd_atiixp_capture_dma_ops = {
  1058. .type = ATI_DMA_CAPTURE,
  1059. .llp_offset = ATI_REG_IN_DMA_LINKPTR,
  1060. .dt_cur = ATI_REG_IN_DMA_DT_CUR,
  1061. .enable_dma = atiixp_in_enable_dma,
  1062. .enable_transfer = atiixp_in_enable_transfer,
  1063. .flush_dma = atiixp_in_flush_dma,
  1064. };
  1065. static const struct atiixp_dma_ops snd_atiixp_spdif_dma_ops = {
  1066. .type = ATI_DMA_SPDIF,
  1067. .llp_offset = ATI_REG_SPDF_DMA_LINKPTR,
  1068. .dt_cur = ATI_REG_SPDF_DMA_DT_CUR,
  1069. .enable_dma = atiixp_spdif_enable_dma,
  1070. .enable_transfer = atiixp_spdif_enable_transfer,
  1071. .flush_dma = atiixp_spdif_flush_dma,
  1072. };
  1073. static int snd_atiixp_pcm_new(struct atiixp *chip)
  1074. {
  1075. struct snd_pcm *pcm;
  1076. struct snd_pcm_chmap *chmap;
  1077. struct snd_ac97_bus *pbus = chip->ac97_bus;
  1078. int err, i, num_pcms;
  1079. /* initialize constants */
  1080. chip->dmas[ATI_DMA_PLAYBACK].ops = &snd_atiixp_playback_dma_ops;
  1081. chip->dmas[ATI_DMA_CAPTURE].ops = &snd_atiixp_capture_dma_ops;
  1082. if (! chip->spdif_over_aclink)
  1083. chip->dmas[ATI_DMA_SPDIF].ops = &snd_atiixp_spdif_dma_ops;
  1084. /* assign AC97 pcm */
  1085. if (chip->spdif_over_aclink)
  1086. num_pcms = 3;
  1087. else
  1088. num_pcms = 2;
  1089. err = snd_ac97_pcm_assign(pbus, num_pcms, atiixp_pcm_defs);
  1090. if (err < 0)
  1091. return err;
  1092. for (i = 0; i < num_pcms; i++)
  1093. chip->pcms[i] = &pbus->pcms[i];
  1094. chip->max_channels = 2;
  1095. if (pbus->pcms[ATI_PCM_OUT].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
  1096. if (pbus->pcms[ATI_PCM_OUT].r[0].slots & (1 << AC97_SLOT_LFE))
  1097. chip->max_channels = 6;
  1098. else
  1099. chip->max_channels = 4;
  1100. }
  1101. /* PCM #0: analog I/O */
  1102. err = snd_pcm_new(chip->card, "ATI IXP AC97",
  1103. ATI_PCMDEV_ANALOG, 1, 1, &pcm);
  1104. if (err < 0)
  1105. return err;
  1106. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops);
  1107. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_atiixp_capture_ops);
  1108. pcm->private_data = chip;
  1109. strcpy(pcm->name, "ATI IXP AC97");
  1110. chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm;
  1111. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
  1112. &chip->pci->dev, 64*1024, 128*1024);
  1113. err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1114. snd_pcm_alt_chmaps, chip->max_channels, 0,
  1115. &chmap);
  1116. if (err < 0)
  1117. return err;
  1118. chmap->channel_mask = SND_PCM_CHMAP_MASK_2468;
  1119. chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
  1120. /* no SPDIF support on codec? */
  1121. if (chip->pcms[ATI_PCM_SPDIF] && ! chip->pcms[ATI_PCM_SPDIF]->rates)
  1122. return 0;
  1123. /* FIXME: non-48k sample rate doesn't work on my test machine with AD1888 */
  1124. if (chip->pcms[ATI_PCM_SPDIF])
  1125. chip->pcms[ATI_PCM_SPDIF]->rates = SNDRV_PCM_RATE_48000;
  1126. /* PCM #1: spdif playback */
  1127. err = snd_pcm_new(chip->card, "ATI IXP IEC958",
  1128. ATI_PCMDEV_DIGITAL, 1, 0, &pcm);
  1129. if (err < 0)
  1130. return err;
  1131. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_spdif_ops);
  1132. pcm->private_data = chip;
  1133. if (chip->spdif_over_aclink)
  1134. strcpy(pcm->name, "ATI IXP IEC958 (AC97)");
  1135. else
  1136. strcpy(pcm->name, "ATI IXP IEC958 (Direct)");
  1137. chip->pcmdevs[ATI_PCMDEV_DIGITAL] = pcm;
  1138. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
  1139. &chip->pci->dev, 64*1024, 128*1024);
  1140. /* pre-select AC97 SPDIF slots 10/11 */
  1141. for (i = 0; i < NUM_ATI_CODECS; i++) {
  1142. if (chip->ac97[i])
  1143. snd_ac97_update_bits(chip->ac97[i],
  1144. AC97_EXTENDED_STATUS,
  1145. 0x03 << 4, 0x03 << 4);
  1146. }
  1147. return 0;
  1148. }
  1149. /*
  1150. * interrupt handler
  1151. */
  1152. static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id)
  1153. {
  1154. struct atiixp *chip = dev_id;
  1155. unsigned int status;
  1156. status = atiixp_read(chip, ISR);
  1157. if (! status)
  1158. return IRQ_NONE;
  1159. /* process audio DMA */
  1160. if (status & ATI_REG_ISR_OUT_XRUN)
  1161. snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]);
  1162. else if (status & ATI_REG_ISR_OUT_STATUS)
  1163. snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]);
  1164. if (status & ATI_REG_ISR_IN_XRUN)
  1165. snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]);
  1166. else if (status & ATI_REG_ISR_IN_STATUS)
  1167. snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]);
  1168. if (! chip->spdif_over_aclink) {
  1169. if (status & ATI_REG_ISR_SPDF_XRUN)
  1170. snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_SPDIF]);
  1171. else if (status & ATI_REG_ISR_SPDF_STATUS)
  1172. snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_SPDIF]);
  1173. }
  1174. /* for codec detection */
  1175. if (status & CODEC_CHECK_BITS) {
  1176. unsigned int detected;
  1177. detected = status & CODEC_CHECK_BITS;
  1178. spin_lock(&chip->reg_lock);
  1179. chip->codec_not_ready_bits |= detected;
  1180. atiixp_update(chip, IER, detected, 0); /* disable the detected irqs */
  1181. spin_unlock(&chip->reg_lock);
  1182. }
  1183. /* ack */
  1184. atiixp_write(chip, ISR, status);
  1185. return IRQ_HANDLED;
  1186. }
  1187. /*
  1188. * ac97 mixer section
  1189. */
  1190. static const struct ac97_quirk ac97_quirks[] = {
  1191. {
  1192. .subvendor = 0x103c,
  1193. .subdevice = 0x006b,
  1194. .name = "HP Pavilion ZV5030US",
  1195. .type = AC97_TUNE_MUTE_LED
  1196. },
  1197. {
  1198. .subvendor = 0x103c,
  1199. .subdevice = 0x308b,
  1200. .name = "HP nx6125",
  1201. .type = AC97_TUNE_MUTE_LED
  1202. },
  1203. {
  1204. .subvendor = 0x103c,
  1205. .subdevice = 0x3091,
  1206. .name = "unknown HP",
  1207. .type = AC97_TUNE_MUTE_LED
  1208. },
  1209. { } /* terminator */
  1210. };
  1211. static int snd_atiixp_mixer_new(struct atiixp *chip, int clock,
  1212. const char *quirk_override)
  1213. {
  1214. struct snd_ac97_bus *pbus;
  1215. struct snd_ac97_template ac97;
  1216. int i, err;
  1217. int codec_count;
  1218. static const struct snd_ac97_bus_ops ops = {
  1219. .write = snd_atiixp_ac97_write,
  1220. .read = snd_atiixp_ac97_read,
  1221. };
  1222. static const unsigned int codec_skip[NUM_ATI_CODECS] = {
  1223. ATI_REG_ISR_CODEC0_NOT_READY,
  1224. ATI_REG_ISR_CODEC1_NOT_READY,
  1225. ATI_REG_ISR_CODEC2_NOT_READY,
  1226. };
  1227. if (snd_atiixp_codec_detect(chip) < 0)
  1228. return -ENXIO;
  1229. err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus);
  1230. if (err < 0)
  1231. return err;
  1232. pbus->clock = clock;
  1233. chip->ac97_bus = pbus;
  1234. codec_count = 0;
  1235. for (i = 0; i < NUM_ATI_CODECS; i++) {
  1236. if (chip->codec_not_ready_bits & codec_skip[i])
  1237. continue;
  1238. memset(&ac97, 0, sizeof(ac97));
  1239. ac97.private_data = chip;
  1240. ac97.pci = chip->pci;
  1241. ac97.num = i;
  1242. ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
  1243. if (! chip->spdif_over_aclink)
  1244. ac97.scaps |= AC97_SCAP_NO_SPDIF;
  1245. err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i]);
  1246. if (err < 0) {
  1247. chip->ac97[i] = NULL; /* to be sure */
  1248. dev_dbg(chip->card->dev,
  1249. "codec %d not available for audio\n", i);
  1250. continue;
  1251. }
  1252. codec_count++;
  1253. }
  1254. if (! codec_count) {
  1255. dev_err(chip->card->dev, "no codec available\n");
  1256. return -ENODEV;
  1257. }
  1258. snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
  1259. return 0;
  1260. }
  1261. /*
  1262. * power management
  1263. */
  1264. static int snd_atiixp_suspend(struct device *dev)
  1265. {
  1266. struct snd_card *card = dev_get_drvdata(dev);
  1267. struct atiixp *chip = card->private_data;
  1268. int i;
  1269. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  1270. for (i = 0; i < NUM_ATI_CODECS; i++)
  1271. snd_ac97_suspend(chip->ac97[i]);
  1272. snd_atiixp_aclink_down(chip);
  1273. snd_atiixp_chip_stop(chip);
  1274. return 0;
  1275. }
  1276. static int snd_atiixp_resume(struct device *dev)
  1277. {
  1278. struct snd_card *card = dev_get_drvdata(dev);
  1279. struct atiixp *chip = card->private_data;
  1280. int i;
  1281. snd_atiixp_aclink_reset(chip);
  1282. snd_atiixp_chip_start(chip);
  1283. for (i = 0; i < NUM_ATI_CODECS; i++)
  1284. snd_ac97_resume(chip->ac97[i]);
  1285. for (i = 0; i < NUM_ATI_PCMDEVS; i++)
  1286. if (chip->pcmdevs[i]) {
  1287. struct atiixp_dma *dma = &chip->dmas[i];
  1288. if (dma->substream && dma->suspended) {
  1289. dma->ops->enable_dma(chip, 1);
  1290. dma->substream->ops->prepare(dma->substream);
  1291. writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN,
  1292. chip->remap_addr + dma->ops->llp_offset);
  1293. }
  1294. }
  1295. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  1296. return 0;
  1297. }
  1298. static DEFINE_SIMPLE_DEV_PM_OPS(snd_atiixp_pm, snd_atiixp_suspend, snd_atiixp_resume);
  1299. /*
  1300. * proc interface for register dump
  1301. */
  1302. static void snd_atiixp_proc_read(struct snd_info_entry *entry,
  1303. struct snd_info_buffer *buffer)
  1304. {
  1305. struct atiixp *chip = entry->private_data;
  1306. int i;
  1307. for (i = 0; i < 256; i += 4)
  1308. snd_iprintf(buffer, "%02x: %08x\n", i, readl(chip->remap_addr + i));
  1309. }
  1310. static void snd_atiixp_proc_init(struct atiixp *chip)
  1311. {
  1312. snd_card_ro_proc_new(chip->card, "atiixp", chip, snd_atiixp_proc_read);
  1313. }
  1314. /*
  1315. * destructor
  1316. */
  1317. static void snd_atiixp_free(struct snd_card *card)
  1318. {
  1319. snd_atiixp_chip_stop(card->private_data);
  1320. }
  1321. /*
  1322. * constructor for chip instance
  1323. */
  1324. static int snd_atiixp_init(struct snd_card *card, struct pci_dev *pci)
  1325. {
  1326. struct atiixp *chip = card->private_data;
  1327. int err;
  1328. err = pcim_enable_device(pci);
  1329. if (err < 0)
  1330. return err;
  1331. spin_lock_init(&chip->reg_lock);
  1332. mutex_init(&chip->open_mutex);
  1333. chip->card = card;
  1334. chip->pci = pci;
  1335. chip->irq = -1;
  1336. err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP AC97");
  1337. if (err < 0)
  1338. return err;
  1339. chip->addr = pci_resource_start(pci, 0);
  1340. chip->remap_addr = pcim_iomap_table(pci)[0];
  1341. if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt,
  1342. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  1343. dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
  1344. return -EBUSY;
  1345. }
  1346. chip->irq = pci->irq;
  1347. card->sync_irq = chip->irq;
  1348. card->private_free = snd_atiixp_free;
  1349. pci_set_master(pci);
  1350. return 0;
  1351. }
  1352. static int __snd_atiixp_probe(struct pci_dev *pci,
  1353. const struct pci_device_id *pci_id)
  1354. {
  1355. struct snd_card *card;
  1356. struct atiixp *chip;
  1357. int err;
  1358. err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
  1359. sizeof(*chip), &card);
  1360. if (err < 0)
  1361. return err;
  1362. chip = card->private_data;
  1363. strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA");
  1364. strcpy(card->shortname, "ATI IXP");
  1365. err = snd_atiixp_init(card, pci);
  1366. if (err < 0)
  1367. return err;
  1368. err = snd_atiixp_aclink_reset(chip);
  1369. if (err < 0)
  1370. return err;
  1371. chip->spdif_over_aclink = spdif_aclink;
  1372. err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk);
  1373. if (err < 0)
  1374. return err;
  1375. err = snd_atiixp_pcm_new(chip);
  1376. if (err < 0)
  1377. return err;
  1378. snd_atiixp_proc_init(chip);
  1379. snd_atiixp_chip_start(chip);
  1380. snprintf(card->longname, sizeof(card->longname),
  1381. "%s rev %x with %s at %#lx, irq %i", card->shortname,
  1382. pci->revision,
  1383. chip->ac97[0] ? snd_ac97_get_short_name(chip->ac97[0]) : "?",
  1384. chip->addr, chip->irq);
  1385. err = snd_card_register(card);
  1386. if (err < 0)
  1387. return err;
  1388. pci_set_drvdata(pci, card);
  1389. return 0;
  1390. }
  1391. static int snd_atiixp_probe(struct pci_dev *pci,
  1392. const struct pci_device_id *pci_id)
  1393. {
  1394. return snd_card_free_on_error(&pci->dev, __snd_atiixp_probe(pci, pci_id));
  1395. }
  1396. static struct pci_driver atiixp_driver = {
  1397. .name = KBUILD_MODNAME,
  1398. .id_table = snd_atiixp_ids,
  1399. .probe = snd_atiixp_probe,
  1400. .driver = {
  1401. .pm = &snd_atiixp_pm,
  1402. },
  1403. };
  1404. module_pci_driver(atiixp_driver);