intel8x0m.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ALSA modem driver for Intel ICH (i8x0) chipsets
  4. *
  5. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  6. *
  7. * This is modified (by Sasha Khapyorsky <sashak@alsa-project.org>) version
  8. * of ALSA ICH sound driver intel8x0.c .
  9. */
  10. #include <linux/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <linux/slab.h>
  16. #include <linux/module.h>
  17. #include <sound/core.h>
  18. #include <sound/pcm.h>
  19. #include <sound/ac97_codec.h>
  20. #include <sound/info.h>
  21. #include <sound/initval.h>
  22. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  23. MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; "
  24. "SiS 7013; NVidia MCP/2/2S/3 modems");
  25. MODULE_LICENSE("GPL");
  26. static int index = -2; /* Exclude the first card */
  27. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  28. static int ac97_clock;
  29. module_param(index, int, 0444);
  30. MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard.");
  31. module_param(id, charp, 0444);
  32. MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard.");
  33. module_param(ac97_clock, int, 0444);
  34. MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
  35. /* just for backward compatibility */
  36. static bool enable;
  37. module_param(enable, bool, 0444);
  38. /*
  39. * Direct registers
  40. */
  41. enum { DEVICE_INTEL, DEVICE_SIS, DEVICE_ALI, DEVICE_NFORCE };
  42. #define ICHREG(x) ICH_REG_##x
  43. #define DEFINE_REGSET(name,base) \
  44. enum { \
  45. ICH_REG_##name##_BDBAR = base + 0x0, /* dword - buffer descriptor list base address */ \
  46. ICH_REG_##name##_CIV = base + 0x04, /* byte - current index value */ \
  47. ICH_REG_##name##_LVI = base + 0x05, /* byte - last valid index */ \
  48. ICH_REG_##name##_SR = base + 0x06, /* byte - status register */ \
  49. ICH_REG_##name##_PICB = base + 0x08, /* word - position in current buffer */ \
  50. ICH_REG_##name##_PIV = base + 0x0a, /* byte - prefetched index value */ \
  51. ICH_REG_##name##_CR = base + 0x0b, /* byte - control register */ \
  52. }
  53. /* busmaster blocks */
  54. DEFINE_REGSET(OFF, 0); /* offset */
  55. /* values for each busmaster block */
  56. /* LVI */
  57. #define ICH_REG_LVI_MASK 0x1f
  58. /* SR */
  59. #define ICH_FIFOE 0x10 /* FIFO error */
  60. #define ICH_BCIS 0x08 /* buffer completion interrupt status */
  61. #define ICH_LVBCI 0x04 /* last valid buffer completion interrupt */
  62. #define ICH_CELV 0x02 /* current equals last valid */
  63. #define ICH_DCH 0x01 /* DMA controller halted */
  64. /* PIV */
  65. #define ICH_REG_PIV_MASK 0x1f /* mask */
  66. /* CR */
  67. #define ICH_IOCE 0x10 /* interrupt on completion enable */
  68. #define ICH_FEIE 0x08 /* fifo error interrupt enable */
  69. #define ICH_LVBIE 0x04 /* last valid buffer interrupt enable */
  70. #define ICH_RESETREGS 0x02 /* reset busmaster registers */
  71. #define ICH_STARTBM 0x01 /* start busmaster operation */
  72. /* global block */
  73. #define ICH_REG_GLOB_CNT 0x3c /* dword - global control */
  74. #define ICH_TRIE 0x00000040 /* tertiary resume interrupt enable */
  75. #define ICH_SRIE 0x00000020 /* secondary resume interrupt enable */
  76. #define ICH_PRIE 0x00000010 /* primary resume interrupt enable */
  77. #define ICH_ACLINK 0x00000008 /* AClink shut off */
  78. #define ICH_AC97WARM 0x00000004 /* AC'97 warm reset */
  79. #define ICH_AC97COLD 0x00000002 /* AC'97 cold reset */
  80. #define ICH_GIE 0x00000001 /* GPI interrupt enable */
  81. #define ICH_REG_GLOB_STA 0x40 /* dword - global status */
  82. #define ICH_TRI 0x20000000 /* ICH4: tertiary (AC_SDIN2) resume interrupt */
  83. #define ICH_TCR 0x10000000 /* ICH4: tertiary (AC_SDIN2) codec ready */
  84. #define ICH_BCS 0x08000000 /* ICH4: bit clock stopped */
  85. #define ICH_SPINT 0x04000000 /* ICH4: S/PDIF interrupt */
  86. #define ICH_P2INT 0x02000000 /* ICH4: PCM2-In interrupt */
  87. #define ICH_M2INT 0x01000000 /* ICH4: Mic2-In interrupt */
  88. #define ICH_SAMPLE_CAP 0x00c00000 /* ICH4: sample capability bits (RO) */
  89. #define ICH_MULTICHAN_CAP 0x00300000 /* ICH4: multi-channel capability bits (RO) */
  90. #define ICH_MD3 0x00020000 /* modem power down semaphore */
  91. #define ICH_AD3 0x00010000 /* audio power down semaphore */
  92. #define ICH_RCS 0x00008000 /* read completion status */
  93. #define ICH_BIT3 0x00004000 /* bit 3 slot 12 */
  94. #define ICH_BIT2 0x00002000 /* bit 2 slot 12 */
  95. #define ICH_BIT1 0x00001000 /* bit 1 slot 12 */
  96. #define ICH_SRI 0x00000800 /* secondary (AC_SDIN1) resume interrupt */
  97. #define ICH_PRI 0x00000400 /* primary (AC_SDIN0) resume interrupt */
  98. #define ICH_SCR 0x00000200 /* secondary (AC_SDIN1) codec ready */
  99. #define ICH_PCR 0x00000100 /* primary (AC_SDIN0) codec ready */
  100. #define ICH_MCINT 0x00000080 /* MIC capture interrupt */
  101. #define ICH_POINT 0x00000040 /* playback interrupt */
  102. #define ICH_PIINT 0x00000020 /* capture interrupt */
  103. #define ICH_NVSPINT 0x00000010 /* nforce spdif interrupt */
  104. #define ICH_MOINT 0x00000004 /* modem playback interrupt */
  105. #define ICH_MIINT 0x00000002 /* modem capture interrupt */
  106. #define ICH_GSCI 0x00000001 /* GPI status change interrupt */
  107. #define ICH_REG_ACC_SEMA 0x44 /* byte - codec write semaphore */
  108. #define ICH_CAS 0x01 /* codec access semaphore */
  109. #define ICH_MAX_FRAGS 32 /* max hw frags */
  110. /*
  111. *
  112. */
  113. enum { ICHD_MDMIN, ICHD_MDMOUT, ICHD_MDMLAST = ICHD_MDMOUT };
  114. enum { ALID_MDMIN, ALID_MDMOUT, ALID_MDMLAST = ALID_MDMOUT };
  115. #define get_ichdev(substream) (substream->runtime->private_data)
  116. struct ichdev {
  117. unsigned int ichd; /* ich device number */
  118. unsigned long reg_offset; /* offset to bmaddr */
  119. __le32 *bdbar; /* CPU address (32bit) */
  120. unsigned int bdbar_addr; /* PCI bus address (32bit) */
  121. struct snd_pcm_substream *substream;
  122. unsigned int physbuf; /* physical address (32bit) */
  123. unsigned int size;
  124. unsigned int fragsize;
  125. unsigned int fragsize1;
  126. unsigned int position;
  127. int frags;
  128. int lvi;
  129. int lvi_frag;
  130. int civ;
  131. int ack;
  132. int ack_reload;
  133. unsigned int ack_bit;
  134. unsigned int roff_sr;
  135. unsigned int roff_picb;
  136. unsigned int int_sta_mask; /* interrupt status mask */
  137. unsigned int ali_slot; /* ALI DMA slot */
  138. struct snd_ac97 *ac97;
  139. };
  140. struct intel8x0m {
  141. unsigned int device_type;
  142. int irq;
  143. void __iomem *addr;
  144. void __iomem *bmaddr;
  145. struct pci_dev *pci;
  146. struct snd_card *card;
  147. int pcm_devs;
  148. struct snd_pcm *pcm[2];
  149. struct ichdev ichd[2];
  150. unsigned int in_ac97_init: 1;
  151. struct snd_ac97_bus *ac97_bus;
  152. struct snd_ac97 *ac97;
  153. spinlock_t reg_lock;
  154. struct snd_dma_buffer *bdbars;
  155. u32 bdbars_count;
  156. u32 int_sta_reg; /* interrupt status register */
  157. u32 int_sta_mask; /* interrupt status mask */
  158. unsigned int pcm_pos_shift;
  159. };
  160. static const struct pci_device_id snd_intel8x0m_ids[] = {
  161. { PCI_VDEVICE(INTEL, 0x2416), DEVICE_INTEL }, /* 82801AA */
  162. { PCI_VDEVICE(INTEL, 0x2426), DEVICE_INTEL }, /* 82901AB */
  163. { PCI_VDEVICE(INTEL, 0x2446), DEVICE_INTEL }, /* 82801BA */
  164. { PCI_VDEVICE(INTEL, 0x2486), DEVICE_INTEL }, /* ICH3 */
  165. { PCI_VDEVICE(INTEL, 0x24c6), DEVICE_INTEL }, /* ICH4 */
  166. { PCI_VDEVICE(INTEL, 0x24d6), DEVICE_INTEL }, /* ICH5 */
  167. { PCI_VDEVICE(INTEL, 0x266d), DEVICE_INTEL }, /* ICH6 */
  168. { PCI_VDEVICE(INTEL, 0x27dd), DEVICE_INTEL }, /* ICH7 */
  169. { PCI_VDEVICE(INTEL, 0x7196), DEVICE_INTEL }, /* 440MX */
  170. { PCI_VDEVICE(AMD, 0x7446), DEVICE_INTEL }, /* AMD768 */
  171. { PCI_VDEVICE(SI, 0x7013), DEVICE_SIS }, /* SI7013 */
  172. { PCI_VDEVICE(NVIDIA, 0x01c1), DEVICE_NFORCE }, /* NFORCE */
  173. { PCI_VDEVICE(NVIDIA, 0x0069), DEVICE_NFORCE }, /* NFORCE2 */
  174. { PCI_VDEVICE(NVIDIA, 0x0089), DEVICE_NFORCE }, /* NFORCE2s */
  175. { PCI_VDEVICE(NVIDIA, 0x00d9), DEVICE_NFORCE }, /* NFORCE3 */
  176. { PCI_VDEVICE(AMD, 0x746e), DEVICE_INTEL }, /* AMD8111 */
  177. #if 0
  178. { PCI_VDEVICE(AL, 0x5455), DEVICE_ALI }, /* Ali5455 */
  179. #endif
  180. { 0, }
  181. };
  182. MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
  183. /*
  184. * Lowlevel I/O - busmaster
  185. */
  186. static inline u8 igetbyte(struct intel8x0m *chip, u32 offset)
  187. {
  188. return ioread8(chip->bmaddr + offset);
  189. }
  190. static inline u16 igetword(struct intel8x0m *chip, u32 offset)
  191. {
  192. return ioread16(chip->bmaddr + offset);
  193. }
  194. static inline u32 igetdword(struct intel8x0m *chip, u32 offset)
  195. {
  196. return ioread32(chip->bmaddr + offset);
  197. }
  198. static inline void iputbyte(struct intel8x0m *chip, u32 offset, u8 val)
  199. {
  200. iowrite8(val, chip->bmaddr + offset);
  201. }
  202. static inline void iputword(struct intel8x0m *chip, u32 offset, u16 val)
  203. {
  204. iowrite16(val, chip->bmaddr + offset);
  205. }
  206. static inline void iputdword(struct intel8x0m *chip, u32 offset, u32 val)
  207. {
  208. iowrite32(val, chip->bmaddr + offset);
  209. }
  210. /*
  211. * Lowlevel I/O - AC'97 registers
  212. */
  213. static inline u16 iagetword(struct intel8x0m *chip, u32 offset)
  214. {
  215. return ioread16(chip->addr + offset);
  216. }
  217. static inline void iaputword(struct intel8x0m *chip, u32 offset, u16 val)
  218. {
  219. iowrite16(val, chip->addr + offset);
  220. }
  221. /*
  222. * Basic I/O
  223. */
  224. /*
  225. * access to AC97 codec via normal i/o (for ICH and SIS7013)
  226. */
  227. /* return the GLOB_STA bit for the corresponding codec */
  228. static unsigned int get_ich_codec_bit(struct intel8x0m *chip, unsigned int codec)
  229. {
  230. static const unsigned int codec_bit[3] = {
  231. ICH_PCR, ICH_SCR, ICH_TCR
  232. };
  233. if (snd_BUG_ON(codec >= 3))
  234. return ICH_PCR;
  235. return codec_bit[codec];
  236. }
  237. static int snd_intel8x0m_codec_semaphore(struct intel8x0m *chip, unsigned int codec)
  238. {
  239. int time;
  240. if (codec > 1)
  241. return -EIO;
  242. codec = get_ich_codec_bit(chip, codec);
  243. /* codec ready ? */
  244. if ((igetdword(chip, ICHREG(GLOB_STA)) & codec) == 0)
  245. return -EIO;
  246. /* Anyone holding a semaphore for 1 msec should be shot... */
  247. time = 100;
  248. do {
  249. if (!(igetbyte(chip, ICHREG(ACC_SEMA)) & ICH_CAS))
  250. return 0;
  251. udelay(10);
  252. } while (time--);
  253. /* access to some forbidden (non existent) ac97 registers will not
  254. * reset the semaphore. So even if you don't get the semaphore, still
  255. * continue the access. We don't need the semaphore anyway. */
  256. dev_err(chip->card->dev,
  257. "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
  258. igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
  259. iagetword(chip, 0); /* clear semaphore flag */
  260. /* I don't care about the semaphore */
  261. return -EBUSY;
  262. }
  263. static void snd_intel8x0m_codec_write(struct snd_ac97 *ac97,
  264. unsigned short reg,
  265. unsigned short val)
  266. {
  267. struct intel8x0m *chip = ac97->private_data;
  268. if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
  269. if (! chip->in_ac97_init)
  270. dev_err(chip->card->dev,
  271. "codec_write %d: semaphore is not ready for register 0x%x\n",
  272. ac97->num, reg);
  273. }
  274. iaputword(chip, reg + ac97->num * 0x80, val);
  275. }
  276. static unsigned short snd_intel8x0m_codec_read(struct snd_ac97 *ac97,
  277. unsigned short reg)
  278. {
  279. struct intel8x0m *chip = ac97->private_data;
  280. unsigned short res;
  281. unsigned int tmp;
  282. if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
  283. if (! chip->in_ac97_init)
  284. dev_err(chip->card->dev,
  285. "codec_read %d: semaphore is not ready for register 0x%x\n",
  286. ac97->num, reg);
  287. res = 0xffff;
  288. } else {
  289. res = iagetword(chip, reg + ac97->num * 0x80);
  290. tmp = igetdword(chip, ICHREG(GLOB_STA));
  291. if (tmp & ICH_RCS) {
  292. /* reset RCS and preserve other R/WC bits */
  293. iputdword(chip, ICHREG(GLOB_STA),
  294. tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
  295. if (! chip->in_ac97_init)
  296. dev_err(chip->card->dev,
  297. "codec_read %d: read timeout for register 0x%x\n",
  298. ac97->num, reg);
  299. res = 0xffff;
  300. }
  301. }
  302. if (reg == AC97_GPIO_STATUS)
  303. iagetword(chip, 0); /* clear semaphore */
  304. return res;
  305. }
  306. /*
  307. * DMA I/O
  308. */
  309. static void snd_intel8x0m_setup_periods(struct intel8x0m *chip, struct ichdev *ichdev)
  310. {
  311. int idx;
  312. __le32 *bdbar = ichdev->bdbar;
  313. unsigned long port = ichdev->reg_offset;
  314. iputdword(chip, port + ICH_REG_OFF_BDBAR, ichdev->bdbar_addr);
  315. if (ichdev->size == ichdev->fragsize) {
  316. ichdev->ack_reload = ichdev->ack = 2;
  317. ichdev->fragsize1 = ichdev->fragsize >> 1;
  318. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 4) {
  319. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf);
  320. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  321. ichdev->fragsize1 >> chip->pcm_pos_shift);
  322. bdbar[idx + 2] = cpu_to_le32(ichdev->physbuf + (ichdev->size >> 1));
  323. bdbar[idx + 3] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  324. ichdev->fragsize1 >> chip->pcm_pos_shift);
  325. }
  326. ichdev->frags = 2;
  327. } else {
  328. ichdev->ack_reload = ichdev->ack = 1;
  329. ichdev->fragsize1 = ichdev->fragsize;
  330. for (idx = 0; idx < (ICH_REG_LVI_MASK + 1) * 2; idx += 2) {
  331. bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
  332. bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
  333. ichdev->fragsize >> chip->pcm_pos_shift);
  334. /*
  335. dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
  336. idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
  337. */
  338. }
  339. ichdev->frags = ichdev->size / ichdev->fragsize;
  340. }
  341. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi = ICH_REG_LVI_MASK);
  342. ichdev->civ = 0;
  343. iputbyte(chip, port + ICH_REG_OFF_CIV, 0);
  344. ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
  345. ichdev->position = 0;
  346. #if 0
  347. dev_dbg(chip->card->dev,
  348. "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
  349. ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
  350. ichdev->fragsize1);
  351. #endif
  352. /* clear interrupts */
  353. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  354. }
  355. /*
  356. * Interrupt handler
  357. */
  358. static inline void snd_intel8x0m_update(struct intel8x0m *chip, struct ichdev *ichdev)
  359. {
  360. unsigned long port = ichdev->reg_offset;
  361. int civ, i, step;
  362. int ack = 0;
  363. civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
  364. if (civ == ichdev->civ) {
  365. step = 1;
  366. ichdev->civ++;
  367. ichdev->civ &= ICH_REG_LVI_MASK;
  368. } else {
  369. step = civ - ichdev->civ;
  370. if (step < 0)
  371. step += ICH_REG_LVI_MASK + 1;
  372. ichdev->civ = civ;
  373. }
  374. ichdev->position += step * ichdev->fragsize1;
  375. ichdev->position %= ichdev->size;
  376. ichdev->lvi += step;
  377. ichdev->lvi &= ICH_REG_LVI_MASK;
  378. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  379. for (i = 0; i < step; i++) {
  380. ichdev->lvi_frag++;
  381. ichdev->lvi_frag %= ichdev->frags;
  382. ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf +
  383. ichdev->lvi_frag *
  384. ichdev->fragsize1);
  385. #if 0
  386. dev_dbg(chip->card->dev,
  387. "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
  388. ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
  389. ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
  390. inl(port + 4), inb(port + ICH_REG_OFF_CR));
  391. #endif
  392. if (--ichdev->ack == 0) {
  393. ichdev->ack = ichdev->ack_reload;
  394. ack = 1;
  395. }
  396. }
  397. if (ack && ichdev->substream) {
  398. spin_unlock(&chip->reg_lock);
  399. snd_pcm_period_elapsed(ichdev->substream);
  400. spin_lock(&chip->reg_lock);
  401. }
  402. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  403. }
  404. static irqreturn_t snd_intel8x0m_interrupt(int irq, void *dev_id)
  405. {
  406. struct intel8x0m *chip = dev_id;
  407. struct ichdev *ichdev;
  408. unsigned int status;
  409. unsigned int i;
  410. spin_lock(&chip->reg_lock);
  411. status = igetdword(chip, chip->int_sta_reg);
  412. if (status == 0xffffffff) { /* we are not yet resumed */
  413. spin_unlock(&chip->reg_lock);
  414. return IRQ_NONE;
  415. }
  416. if ((status & chip->int_sta_mask) == 0) {
  417. if (status)
  418. iputdword(chip, chip->int_sta_reg, status);
  419. spin_unlock(&chip->reg_lock);
  420. return IRQ_NONE;
  421. }
  422. for (i = 0; i < chip->bdbars_count; i++) {
  423. ichdev = &chip->ichd[i];
  424. if (status & ichdev->int_sta_mask)
  425. snd_intel8x0m_update(chip, ichdev);
  426. }
  427. /* ack them */
  428. iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  429. spin_unlock(&chip->reg_lock);
  430. return IRQ_HANDLED;
  431. }
  432. /*
  433. * PCM part
  434. */
  435. static int snd_intel8x0m_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  436. {
  437. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  438. struct ichdev *ichdev = get_ichdev(substream);
  439. unsigned char val = 0;
  440. unsigned long port = ichdev->reg_offset;
  441. switch (cmd) {
  442. case SNDRV_PCM_TRIGGER_START:
  443. case SNDRV_PCM_TRIGGER_RESUME:
  444. val = ICH_IOCE | ICH_STARTBM;
  445. break;
  446. case SNDRV_PCM_TRIGGER_STOP:
  447. case SNDRV_PCM_TRIGGER_SUSPEND:
  448. val = 0;
  449. break;
  450. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  451. val = ICH_IOCE;
  452. break;
  453. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  454. val = ICH_IOCE | ICH_STARTBM;
  455. break;
  456. default:
  457. return -EINVAL;
  458. }
  459. iputbyte(chip, port + ICH_REG_OFF_CR, val);
  460. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  461. /* wait until DMA stopped */
  462. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  463. /* reset whole DMA things */
  464. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  465. }
  466. return 0;
  467. }
  468. static snd_pcm_uframes_t snd_intel8x0m_pcm_pointer(struct snd_pcm_substream *substream)
  469. {
  470. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  471. struct ichdev *ichdev = get_ichdev(substream);
  472. size_t ptr1, ptr;
  473. ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << chip->pcm_pos_shift;
  474. if (ptr1 != 0)
  475. ptr = ichdev->fragsize1 - ptr1;
  476. else
  477. ptr = 0;
  478. ptr += ichdev->position;
  479. if (ptr >= ichdev->size)
  480. return 0;
  481. return bytes_to_frames(substream->runtime, ptr);
  482. }
  483. static int snd_intel8x0m_pcm_prepare(struct snd_pcm_substream *substream)
  484. {
  485. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  486. struct snd_pcm_runtime *runtime = substream->runtime;
  487. struct ichdev *ichdev = get_ichdev(substream);
  488. ichdev->physbuf = runtime->dma_addr;
  489. ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  490. ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
  491. snd_ac97_write(ichdev->ac97, AC97_LINE1_RATE, runtime->rate);
  492. snd_ac97_write(ichdev->ac97, AC97_LINE1_LEVEL, 0);
  493. snd_intel8x0m_setup_periods(chip, ichdev);
  494. return 0;
  495. }
  496. static const struct snd_pcm_hardware snd_intel8x0m_stream =
  497. {
  498. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  499. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  500. SNDRV_PCM_INFO_MMAP_VALID |
  501. SNDRV_PCM_INFO_PAUSE |
  502. SNDRV_PCM_INFO_RESUME),
  503. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  504. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_KNOT,
  505. .rate_min = 8000,
  506. .rate_max = 16000,
  507. .channels_min = 1,
  508. .channels_max = 1,
  509. .buffer_bytes_max = 64 * 1024,
  510. .period_bytes_min = 32,
  511. .period_bytes_max = 64 * 1024,
  512. .periods_min = 1,
  513. .periods_max = 1024,
  514. .fifo_size = 0,
  515. };
  516. static int snd_intel8x0m_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
  517. {
  518. static const unsigned int rates[] = { 8000, 9600, 12000, 16000 };
  519. static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
  520. .count = ARRAY_SIZE(rates),
  521. .list = rates,
  522. .mask = 0,
  523. };
  524. struct snd_pcm_runtime *runtime = substream->runtime;
  525. int err;
  526. ichdev->substream = substream;
  527. runtime->hw = snd_intel8x0m_stream;
  528. err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  529. &hw_constraints_rates);
  530. if ( err < 0 )
  531. return err;
  532. runtime->private_data = ichdev;
  533. return 0;
  534. }
  535. static int snd_intel8x0m_playback_open(struct snd_pcm_substream *substream)
  536. {
  537. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  538. return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMOUT]);
  539. }
  540. static int snd_intel8x0m_playback_close(struct snd_pcm_substream *substream)
  541. {
  542. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  543. chip->ichd[ICHD_MDMOUT].substream = NULL;
  544. return 0;
  545. }
  546. static int snd_intel8x0m_capture_open(struct snd_pcm_substream *substream)
  547. {
  548. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  549. return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMIN]);
  550. }
  551. static int snd_intel8x0m_capture_close(struct snd_pcm_substream *substream)
  552. {
  553. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  554. chip->ichd[ICHD_MDMIN].substream = NULL;
  555. return 0;
  556. }
  557. static const struct snd_pcm_ops snd_intel8x0m_playback_ops = {
  558. .open = snd_intel8x0m_playback_open,
  559. .close = snd_intel8x0m_playback_close,
  560. .prepare = snd_intel8x0m_pcm_prepare,
  561. .trigger = snd_intel8x0m_pcm_trigger,
  562. .pointer = snd_intel8x0m_pcm_pointer,
  563. };
  564. static const struct snd_pcm_ops snd_intel8x0m_capture_ops = {
  565. .open = snd_intel8x0m_capture_open,
  566. .close = snd_intel8x0m_capture_close,
  567. .prepare = snd_intel8x0m_pcm_prepare,
  568. .trigger = snd_intel8x0m_pcm_trigger,
  569. .pointer = snd_intel8x0m_pcm_pointer,
  570. };
  571. struct ich_pcm_table {
  572. char *suffix;
  573. const struct snd_pcm_ops *playback_ops;
  574. const struct snd_pcm_ops *capture_ops;
  575. size_t prealloc_size;
  576. size_t prealloc_max_size;
  577. int ac97_idx;
  578. };
  579. static int snd_intel8x0m_pcm1(struct intel8x0m *chip, int device,
  580. const struct ich_pcm_table *rec)
  581. {
  582. struct snd_pcm *pcm;
  583. int err;
  584. char name[32];
  585. if (rec->suffix)
  586. sprintf(name, "Intel ICH - %s", rec->suffix);
  587. else
  588. strcpy(name, "Intel ICH");
  589. err = snd_pcm_new(chip->card, name, device,
  590. rec->playback_ops ? 1 : 0,
  591. rec->capture_ops ? 1 : 0, &pcm);
  592. if (err < 0)
  593. return err;
  594. if (rec->playback_ops)
  595. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
  596. if (rec->capture_ops)
  597. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
  598. pcm->private_data = chip;
  599. pcm->info_flags = 0;
  600. pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
  601. if (rec->suffix)
  602. sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
  603. else
  604. strcpy(pcm->name, chip->card->shortname);
  605. chip->pcm[device] = pcm;
  606. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
  607. &chip->pci->dev,
  608. rec->prealloc_size,
  609. rec->prealloc_max_size);
  610. return 0;
  611. }
  612. static const struct ich_pcm_table intel_pcms[] = {
  613. {
  614. .suffix = "Modem",
  615. .playback_ops = &snd_intel8x0m_playback_ops,
  616. .capture_ops = &snd_intel8x0m_capture_ops,
  617. .prealloc_size = 32 * 1024,
  618. .prealloc_max_size = 64 * 1024,
  619. },
  620. };
  621. static int snd_intel8x0m_pcm(struct intel8x0m *chip)
  622. {
  623. int i, tblsize, device, err;
  624. const struct ich_pcm_table *tbl, *rec;
  625. #if 1
  626. tbl = intel_pcms;
  627. tblsize = 1;
  628. #else
  629. switch (chip->device_type) {
  630. case DEVICE_NFORCE:
  631. tbl = nforce_pcms;
  632. tblsize = ARRAY_SIZE(nforce_pcms);
  633. break;
  634. case DEVICE_ALI:
  635. tbl = ali_pcms;
  636. tblsize = ARRAY_SIZE(ali_pcms);
  637. break;
  638. default:
  639. tbl = intel_pcms;
  640. tblsize = 2;
  641. break;
  642. }
  643. #endif
  644. device = 0;
  645. for (i = 0; i < tblsize; i++) {
  646. rec = tbl + i;
  647. if (i > 0 && rec->ac97_idx) {
  648. /* activate PCM only when associated AC'97 codec */
  649. if (! chip->ichd[rec->ac97_idx].ac97)
  650. continue;
  651. }
  652. err = snd_intel8x0m_pcm1(chip, device, rec);
  653. if (err < 0)
  654. return err;
  655. device++;
  656. }
  657. chip->pcm_devs = device;
  658. return 0;
  659. }
  660. /*
  661. * Mixer part
  662. */
  663. static void snd_intel8x0m_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  664. {
  665. struct intel8x0m *chip = bus->private_data;
  666. chip->ac97_bus = NULL;
  667. }
  668. static void snd_intel8x0m_mixer_free_ac97(struct snd_ac97 *ac97)
  669. {
  670. struct intel8x0m *chip = ac97->private_data;
  671. chip->ac97 = NULL;
  672. }
  673. static int snd_intel8x0m_mixer(struct intel8x0m *chip, int ac97_clock)
  674. {
  675. struct snd_ac97_bus *pbus;
  676. struct snd_ac97_template ac97;
  677. struct snd_ac97 *x97;
  678. int err;
  679. unsigned int glob_sta = 0;
  680. static const struct snd_ac97_bus_ops ops = {
  681. .write = snd_intel8x0m_codec_write,
  682. .read = snd_intel8x0m_codec_read,
  683. };
  684. chip->in_ac97_init = 1;
  685. memset(&ac97, 0, sizeof(ac97));
  686. ac97.private_data = chip;
  687. ac97.private_free = snd_intel8x0m_mixer_free_ac97;
  688. ac97.scaps = AC97_SCAP_SKIP_AUDIO | AC97_SCAP_POWER_SAVE;
  689. glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  690. err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus);
  691. if (err < 0)
  692. goto __err;
  693. pbus->private_free = snd_intel8x0m_mixer_free_ac97_bus;
  694. if (ac97_clock >= 8000 && ac97_clock <= 48000)
  695. pbus->clock = ac97_clock;
  696. chip->ac97_bus = pbus;
  697. ac97.pci = chip->pci;
  698. ac97.num = glob_sta & ICH_SCR ? 1 : 0;
  699. err = snd_ac97_mixer(pbus, &ac97, &x97);
  700. if (err < 0) {
  701. dev_err(chip->card->dev,
  702. "Unable to initialize codec #%d\n", ac97.num);
  703. if (ac97.num == 0)
  704. goto __err;
  705. return err;
  706. }
  707. chip->ac97 = x97;
  708. if(ac97_is_modem(x97) && !chip->ichd[ICHD_MDMIN].ac97) {
  709. chip->ichd[ICHD_MDMIN].ac97 = x97;
  710. chip->ichd[ICHD_MDMOUT].ac97 = x97;
  711. }
  712. chip->in_ac97_init = 0;
  713. return 0;
  714. __err:
  715. /* clear the cold-reset bit for the next chance */
  716. if (chip->device_type != DEVICE_ALI)
  717. iputdword(chip, ICHREG(GLOB_CNT),
  718. igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
  719. return err;
  720. }
  721. /*
  722. *
  723. */
  724. static int snd_intel8x0m_ich_chip_init(struct intel8x0m *chip, int probing)
  725. {
  726. unsigned long end_time;
  727. unsigned int cnt, status, nstatus;
  728. /* put logic to right state */
  729. /* first clear status bits */
  730. status = ICH_RCS | ICH_MIINT | ICH_MOINT;
  731. cnt = igetdword(chip, ICHREG(GLOB_STA));
  732. iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  733. /* ACLink on, 2 channels */
  734. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  735. cnt &= ~(ICH_ACLINK);
  736. /* finish cold or do warm reset */
  737. cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  738. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  739. usleep_range(500, 1000); /* give warm reset some time */
  740. end_time = jiffies + HZ / 4;
  741. do {
  742. if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
  743. goto __ok;
  744. schedule_timeout_uninterruptible(1);
  745. } while (time_after_eq(end_time, jiffies));
  746. dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
  747. igetdword(chip, ICHREG(GLOB_CNT)));
  748. return -EIO;
  749. __ok:
  750. if (probing) {
  751. /* wait for any codec ready status.
  752. * Once it becomes ready it should remain ready
  753. * as long as we do not disable the ac97 link.
  754. */
  755. end_time = jiffies + HZ;
  756. do {
  757. status = igetdword(chip, ICHREG(GLOB_STA)) &
  758. (ICH_PCR | ICH_SCR | ICH_TCR);
  759. if (status)
  760. break;
  761. schedule_timeout_uninterruptible(1);
  762. } while (time_after_eq(end_time, jiffies));
  763. if (! status) {
  764. /* no codec is found */
  765. dev_err(chip->card->dev,
  766. "codec_ready: codec is not ready [0x%x]\n",
  767. igetdword(chip, ICHREG(GLOB_STA)));
  768. return -EIO;
  769. }
  770. /* up to two codecs (modem cannot be tertiary with ICH4) */
  771. nstatus = ICH_PCR | ICH_SCR;
  772. /* wait for other codecs ready status. */
  773. end_time = jiffies + HZ / 4;
  774. while (status != nstatus && time_after_eq(end_time, jiffies)) {
  775. schedule_timeout_uninterruptible(1);
  776. status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
  777. }
  778. } else {
  779. /* resume phase */
  780. status = 0;
  781. if (chip->ac97)
  782. status |= get_ich_codec_bit(chip, chip->ac97->num);
  783. /* wait until all the probed codecs are ready */
  784. end_time = jiffies + HZ;
  785. do {
  786. nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
  787. (ICH_PCR | ICH_SCR | ICH_TCR);
  788. if (status == nstatus)
  789. break;
  790. schedule_timeout_uninterruptible(1);
  791. } while (time_after_eq(end_time, jiffies));
  792. }
  793. if (chip->device_type == DEVICE_SIS) {
  794. /* unmute the output on SIS7013 */
  795. iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  796. }
  797. return 0;
  798. }
  799. static int snd_intel8x0m_chip_init(struct intel8x0m *chip, int probing)
  800. {
  801. unsigned int i;
  802. int err;
  803. err = snd_intel8x0m_ich_chip_init(chip, probing);
  804. if (err < 0)
  805. return err;
  806. iagetword(chip, 0); /* clear semaphore flag */
  807. /* disable interrupts */
  808. for (i = 0; i < chip->bdbars_count; i++)
  809. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  810. /* reset channels */
  811. for (i = 0; i < chip->bdbars_count; i++)
  812. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  813. /* initialize Buffer Descriptor Lists */
  814. for (i = 0; i < chip->bdbars_count; i++)
  815. iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
  816. return 0;
  817. }
  818. static void snd_intel8x0m_free(struct snd_card *card)
  819. {
  820. struct intel8x0m *chip = card->private_data;
  821. unsigned int i;
  822. if (chip->irq < 0)
  823. goto __hw_end;
  824. /* disable interrupts */
  825. for (i = 0; i < chip->bdbars_count; i++)
  826. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  827. /* reset channels */
  828. for (i = 0; i < chip->bdbars_count; i++)
  829. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  830. __hw_end:
  831. if (chip->irq >= 0)
  832. free_irq(chip->irq, chip);
  833. }
  834. /*
  835. * power management
  836. */
  837. static int intel8x0m_suspend(struct device *dev)
  838. {
  839. struct snd_card *card = dev_get_drvdata(dev);
  840. struct intel8x0m *chip = card->private_data;
  841. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  842. snd_ac97_suspend(chip->ac97);
  843. if (chip->irq >= 0) {
  844. free_irq(chip->irq, chip);
  845. chip->irq = -1;
  846. card->sync_irq = -1;
  847. }
  848. return 0;
  849. }
  850. static int intel8x0m_resume(struct device *dev)
  851. {
  852. struct pci_dev *pci = to_pci_dev(dev);
  853. struct snd_card *card = dev_get_drvdata(dev);
  854. struct intel8x0m *chip = card->private_data;
  855. if (request_irq(pci->irq, snd_intel8x0m_interrupt,
  856. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  857. dev_err(dev, "unable to grab IRQ %d, disabling device\n",
  858. pci->irq);
  859. snd_card_disconnect(card);
  860. return -EIO;
  861. }
  862. chip->irq = pci->irq;
  863. card->sync_irq = chip->irq;
  864. snd_intel8x0m_chip_init(chip, 0);
  865. snd_ac97_resume(chip->ac97);
  866. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  867. return 0;
  868. }
  869. static DEFINE_SIMPLE_DEV_PM_OPS(intel8x0m_pm, intel8x0m_suspend, intel8x0m_resume);
  870. static void snd_intel8x0m_proc_read(struct snd_info_entry * entry,
  871. struct snd_info_buffer *buffer)
  872. {
  873. struct intel8x0m *chip = entry->private_data;
  874. unsigned int tmp;
  875. snd_iprintf(buffer, "Intel8x0m\n\n");
  876. if (chip->device_type == DEVICE_ALI)
  877. return;
  878. tmp = igetdword(chip, ICHREG(GLOB_STA));
  879. snd_iprintf(buffer, "Global control : 0x%08x\n",
  880. igetdword(chip, ICHREG(GLOB_CNT)));
  881. snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
  882. snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
  883. tmp & ICH_PCR ? " primary" : "",
  884. tmp & ICH_SCR ? " secondary" : "",
  885. tmp & ICH_TCR ? " tertiary" : "",
  886. (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
  887. }
  888. static void snd_intel8x0m_proc_init(struct intel8x0m *chip)
  889. {
  890. snd_card_ro_proc_new(chip->card, "intel8x0m", chip,
  891. snd_intel8x0m_proc_read);
  892. }
  893. struct ich_reg_info {
  894. unsigned int int_sta_mask;
  895. unsigned int offset;
  896. };
  897. static int snd_intel8x0m_init(struct snd_card *card,
  898. struct pci_dev *pci,
  899. unsigned long device_type)
  900. {
  901. struct intel8x0m *chip = card->private_data;
  902. int err;
  903. unsigned int i;
  904. unsigned int int_sta_masks;
  905. struct ichdev *ichdev;
  906. static const struct ich_reg_info intel_regs[2] = {
  907. { ICH_MIINT, 0 },
  908. { ICH_MOINT, 0x10 },
  909. };
  910. const struct ich_reg_info *tbl;
  911. err = pcim_enable_device(pci);
  912. if (err < 0)
  913. return err;
  914. spin_lock_init(&chip->reg_lock);
  915. chip->device_type = device_type;
  916. chip->card = card;
  917. chip->pci = pci;
  918. chip->irq = -1;
  919. err = pci_request_regions(pci, card->shortname);
  920. if (err < 0)
  921. return err;
  922. if (device_type == DEVICE_ALI) {
  923. /* ALI5455 has no ac97 region */
  924. chip->bmaddr = pcim_iomap(pci, 0, 0);
  925. } else {
  926. if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
  927. chip->addr = pcim_iomap(pci, 2, 0);
  928. else
  929. chip->addr = pcim_iomap(pci, 0, 0);
  930. if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
  931. chip->bmaddr = pcim_iomap(pci, 3, 0);
  932. else
  933. chip->bmaddr = pcim_iomap(pci, 1, 0);
  934. }
  935. /* initialize offsets */
  936. chip->bdbars_count = 2;
  937. tbl = intel_regs;
  938. for (i = 0; i < chip->bdbars_count; i++) {
  939. ichdev = &chip->ichd[i];
  940. ichdev->ichd = i;
  941. ichdev->reg_offset = tbl[i].offset;
  942. ichdev->int_sta_mask = tbl[i].int_sta_mask;
  943. if (device_type == DEVICE_SIS) {
  944. /* SiS 7013 swaps the registers */
  945. ichdev->roff_sr = ICH_REG_OFF_PICB;
  946. ichdev->roff_picb = ICH_REG_OFF_SR;
  947. } else {
  948. ichdev->roff_sr = ICH_REG_OFF_SR;
  949. ichdev->roff_picb = ICH_REG_OFF_PICB;
  950. }
  951. if (device_type == DEVICE_ALI)
  952. ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  953. }
  954. /* SIS7013 handles the pcm data in bytes, others are in words */
  955. chip->pcm_pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  956. /* allocate buffer descriptor lists */
  957. /* the start of each lists must be aligned to 8 bytes */
  958. chip->bdbars = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV,
  959. chip->bdbars_count * sizeof(u32) *
  960. ICH_MAX_FRAGS * 2);
  961. if (!chip->bdbars)
  962. return -ENOMEM;
  963. /* tables must be aligned to 8 bytes here, but the kernel pages
  964. are much bigger, so we don't care (on i386) */
  965. int_sta_masks = 0;
  966. for (i = 0; i < chip->bdbars_count; i++) {
  967. ichdev = &chip->ichd[i];
  968. ichdev->bdbar = ((__le32 *)chip->bdbars->area) + (i * ICH_MAX_FRAGS * 2);
  969. ichdev->bdbar_addr = chip->bdbars->addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
  970. int_sta_masks |= ichdev->int_sta_mask;
  971. }
  972. chip->int_sta_reg = ICH_REG_GLOB_STA;
  973. chip->int_sta_mask = int_sta_masks;
  974. pci_set_master(pci);
  975. err = snd_intel8x0m_chip_init(chip, 1);
  976. if (err < 0)
  977. return err;
  978. /* NOTE: we don't use devm version here since it's released /
  979. * re-acquired in PM callbacks.
  980. * It's released explicitly in snd_intel8x0m_free(), too.
  981. */
  982. if (request_irq(pci->irq, snd_intel8x0m_interrupt, IRQF_SHARED,
  983. KBUILD_MODNAME, chip)) {
  984. dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
  985. return -EBUSY;
  986. }
  987. chip->irq = pci->irq;
  988. card->sync_irq = chip->irq;
  989. card->private_free = snd_intel8x0m_free;
  990. return 0;
  991. }
  992. static struct shortname_table {
  993. unsigned int id;
  994. const char *s;
  995. } shortnames[] = {
  996. { PCI_DEVICE_ID_INTEL_82801AA_6, "Intel 82801AA-ICH" },
  997. { PCI_DEVICE_ID_INTEL_82801AB_6, "Intel 82901AB-ICH0" },
  998. { PCI_DEVICE_ID_INTEL_82801BA_6, "Intel 82801BA-ICH2" },
  999. { PCI_DEVICE_ID_INTEL_440MX_6, "Intel 440MX" },
  1000. { PCI_DEVICE_ID_INTEL_82801CA_6, "Intel 82801CA-ICH3" },
  1001. { PCI_DEVICE_ID_INTEL_82801DB_6, "Intel 82801DB-ICH4" },
  1002. { PCI_DEVICE_ID_INTEL_82801EB_6, "Intel ICH5" },
  1003. { PCI_DEVICE_ID_INTEL_ICH6_17, "Intel ICH6" },
  1004. { PCI_DEVICE_ID_INTEL_ICH7_19, "Intel ICH7" },
  1005. { 0x7446, "AMD AMD768" },
  1006. { PCI_DEVICE_ID_SI_7013, "SiS SI7013" },
  1007. { PCI_DEVICE_ID_NVIDIA_MCP1_MODEM, "NVidia nForce" },
  1008. { PCI_DEVICE_ID_NVIDIA_MCP2_MODEM, "NVidia nForce2" },
  1009. { PCI_DEVICE_ID_NVIDIA_MCP2S_MODEM, "NVidia nForce2s" },
  1010. { PCI_DEVICE_ID_NVIDIA_MCP3_MODEM, "NVidia nForce3" },
  1011. { 0x746e, "AMD AMD8111" },
  1012. #if 0
  1013. { 0x5455, "ALi M5455" },
  1014. #endif
  1015. { 0 },
  1016. };
  1017. static int __snd_intel8x0m_probe(struct pci_dev *pci,
  1018. const struct pci_device_id *pci_id)
  1019. {
  1020. struct snd_card *card;
  1021. struct intel8x0m *chip;
  1022. int err;
  1023. struct shortname_table *name;
  1024. err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
  1025. sizeof(*chip), &card);
  1026. if (err < 0)
  1027. return err;
  1028. chip = card->private_data;
  1029. strcpy(card->driver, "ICH-MODEM");
  1030. strcpy(card->shortname, "Intel ICH");
  1031. for (name = shortnames; name->id; name++) {
  1032. if (pci->device == name->id) {
  1033. strcpy(card->shortname, name->s);
  1034. break;
  1035. }
  1036. }
  1037. strcat(card->shortname," Modem");
  1038. err = snd_intel8x0m_init(card, pci, pci_id->driver_data);
  1039. if (err < 0)
  1040. return err;
  1041. err = snd_intel8x0m_mixer(chip, ac97_clock);
  1042. if (err < 0)
  1043. return err;
  1044. err = snd_intel8x0m_pcm(chip);
  1045. if (err < 0)
  1046. return err;
  1047. snd_intel8x0m_proc_init(chip);
  1048. sprintf(card->longname, "%s at irq %i",
  1049. card->shortname, chip->irq);
  1050. err = snd_card_register(card);
  1051. if (err < 0)
  1052. return err;
  1053. pci_set_drvdata(pci, card);
  1054. return 0;
  1055. }
  1056. static int snd_intel8x0m_probe(struct pci_dev *pci,
  1057. const struct pci_device_id *pci_id)
  1058. {
  1059. return snd_card_free_on_error(&pci->dev, __snd_intel8x0m_probe(pci, pci_id));
  1060. }
  1061. static struct pci_driver intel8x0m_driver = {
  1062. .name = KBUILD_MODNAME,
  1063. .id_table = snd_intel8x0m_ids,
  1064. .probe = snd_intel8x0m_probe,
  1065. .driver = {
  1066. .pm = &intel8x0m_pm,
  1067. },
  1068. };
  1069. module_pci_driver(intel8x0m_driver);