intel8x0m.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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 <[email protected]>
  6. *
  7. * This is modified (by Sasha Khapyorsky <[email protected]>) 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 <[email protected]>");
  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. // snd_printd("civ same %d\n", civ);
  366. step = 1;
  367. ichdev->civ++;
  368. ichdev->civ &= ICH_REG_LVI_MASK;
  369. } else {
  370. step = civ - ichdev->civ;
  371. if (step < 0)
  372. step += ICH_REG_LVI_MASK + 1;
  373. // if (step != 1)
  374. // snd_printd("step = %d, %d -> %d\n", step, ichdev->civ, civ);
  375. ichdev->civ = civ;
  376. }
  377. ichdev->position += step * ichdev->fragsize1;
  378. ichdev->position %= ichdev->size;
  379. ichdev->lvi += step;
  380. ichdev->lvi &= ICH_REG_LVI_MASK;
  381. iputbyte(chip, port + ICH_REG_OFF_LVI, ichdev->lvi);
  382. for (i = 0; i < step; i++) {
  383. ichdev->lvi_frag++;
  384. ichdev->lvi_frag %= ichdev->frags;
  385. ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf +
  386. ichdev->lvi_frag *
  387. ichdev->fragsize1);
  388. #if 0
  389. dev_dbg(chip->card->dev,
  390. "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
  391. ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
  392. ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
  393. inl(port + 4), inb(port + ICH_REG_OFF_CR));
  394. #endif
  395. if (--ichdev->ack == 0) {
  396. ichdev->ack = ichdev->ack_reload;
  397. ack = 1;
  398. }
  399. }
  400. if (ack && ichdev->substream) {
  401. spin_unlock(&chip->reg_lock);
  402. snd_pcm_period_elapsed(ichdev->substream);
  403. spin_lock(&chip->reg_lock);
  404. }
  405. iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
  406. }
  407. static irqreturn_t snd_intel8x0m_interrupt(int irq, void *dev_id)
  408. {
  409. struct intel8x0m *chip = dev_id;
  410. struct ichdev *ichdev;
  411. unsigned int status;
  412. unsigned int i;
  413. spin_lock(&chip->reg_lock);
  414. status = igetdword(chip, chip->int_sta_reg);
  415. if (status == 0xffffffff) { /* we are not yet resumed */
  416. spin_unlock(&chip->reg_lock);
  417. return IRQ_NONE;
  418. }
  419. if ((status & chip->int_sta_mask) == 0) {
  420. if (status)
  421. iputdword(chip, chip->int_sta_reg, status);
  422. spin_unlock(&chip->reg_lock);
  423. return IRQ_NONE;
  424. }
  425. for (i = 0; i < chip->bdbars_count; i++) {
  426. ichdev = &chip->ichd[i];
  427. if (status & ichdev->int_sta_mask)
  428. snd_intel8x0m_update(chip, ichdev);
  429. }
  430. /* ack them */
  431. iputdword(chip, chip->int_sta_reg, status & chip->int_sta_mask);
  432. spin_unlock(&chip->reg_lock);
  433. return IRQ_HANDLED;
  434. }
  435. /*
  436. * PCM part
  437. */
  438. static int snd_intel8x0m_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  439. {
  440. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  441. struct ichdev *ichdev = get_ichdev(substream);
  442. unsigned char val = 0;
  443. unsigned long port = ichdev->reg_offset;
  444. switch (cmd) {
  445. case SNDRV_PCM_TRIGGER_START:
  446. case SNDRV_PCM_TRIGGER_RESUME:
  447. val = ICH_IOCE | ICH_STARTBM;
  448. break;
  449. case SNDRV_PCM_TRIGGER_STOP:
  450. case SNDRV_PCM_TRIGGER_SUSPEND:
  451. val = 0;
  452. break;
  453. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  454. val = ICH_IOCE;
  455. break;
  456. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  457. val = ICH_IOCE | ICH_STARTBM;
  458. break;
  459. default:
  460. return -EINVAL;
  461. }
  462. iputbyte(chip, port + ICH_REG_OFF_CR, val);
  463. if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  464. /* wait until DMA stopped */
  465. while (!(igetbyte(chip, port + ichdev->roff_sr) & ICH_DCH)) ;
  466. /* reset whole DMA things */
  467. iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
  468. }
  469. return 0;
  470. }
  471. static snd_pcm_uframes_t snd_intel8x0m_pcm_pointer(struct snd_pcm_substream *substream)
  472. {
  473. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  474. struct ichdev *ichdev = get_ichdev(substream);
  475. size_t ptr1, ptr;
  476. ptr1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << chip->pcm_pos_shift;
  477. if (ptr1 != 0)
  478. ptr = ichdev->fragsize1 - ptr1;
  479. else
  480. ptr = 0;
  481. ptr += ichdev->position;
  482. if (ptr >= ichdev->size)
  483. return 0;
  484. return bytes_to_frames(substream->runtime, ptr);
  485. }
  486. static int snd_intel8x0m_pcm_prepare(struct snd_pcm_substream *substream)
  487. {
  488. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  489. struct snd_pcm_runtime *runtime = substream->runtime;
  490. struct ichdev *ichdev = get_ichdev(substream);
  491. ichdev->physbuf = runtime->dma_addr;
  492. ichdev->size = snd_pcm_lib_buffer_bytes(substream);
  493. ichdev->fragsize = snd_pcm_lib_period_bytes(substream);
  494. snd_ac97_write(ichdev->ac97, AC97_LINE1_RATE, runtime->rate);
  495. snd_ac97_write(ichdev->ac97, AC97_LINE1_LEVEL, 0);
  496. snd_intel8x0m_setup_periods(chip, ichdev);
  497. return 0;
  498. }
  499. static const struct snd_pcm_hardware snd_intel8x0m_stream =
  500. {
  501. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  502. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  503. SNDRV_PCM_INFO_MMAP_VALID |
  504. SNDRV_PCM_INFO_PAUSE |
  505. SNDRV_PCM_INFO_RESUME),
  506. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  507. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_KNOT,
  508. .rate_min = 8000,
  509. .rate_max = 16000,
  510. .channels_min = 1,
  511. .channels_max = 1,
  512. .buffer_bytes_max = 64 * 1024,
  513. .period_bytes_min = 32,
  514. .period_bytes_max = 64 * 1024,
  515. .periods_min = 1,
  516. .periods_max = 1024,
  517. .fifo_size = 0,
  518. };
  519. static int snd_intel8x0m_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
  520. {
  521. static const unsigned int rates[] = { 8000, 9600, 12000, 16000 };
  522. static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
  523. .count = ARRAY_SIZE(rates),
  524. .list = rates,
  525. .mask = 0,
  526. };
  527. struct snd_pcm_runtime *runtime = substream->runtime;
  528. int err;
  529. ichdev->substream = substream;
  530. runtime->hw = snd_intel8x0m_stream;
  531. err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  532. &hw_constraints_rates);
  533. if ( err < 0 )
  534. return err;
  535. runtime->private_data = ichdev;
  536. return 0;
  537. }
  538. static int snd_intel8x0m_playback_open(struct snd_pcm_substream *substream)
  539. {
  540. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  541. return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMOUT]);
  542. }
  543. static int snd_intel8x0m_playback_close(struct snd_pcm_substream *substream)
  544. {
  545. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  546. chip->ichd[ICHD_MDMOUT].substream = NULL;
  547. return 0;
  548. }
  549. static int snd_intel8x0m_capture_open(struct snd_pcm_substream *substream)
  550. {
  551. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  552. return snd_intel8x0m_pcm_open(substream, &chip->ichd[ICHD_MDMIN]);
  553. }
  554. static int snd_intel8x0m_capture_close(struct snd_pcm_substream *substream)
  555. {
  556. struct intel8x0m *chip = snd_pcm_substream_chip(substream);
  557. chip->ichd[ICHD_MDMIN].substream = NULL;
  558. return 0;
  559. }
  560. static const struct snd_pcm_ops snd_intel8x0m_playback_ops = {
  561. .open = snd_intel8x0m_playback_open,
  562. .close = snd_intel8x0m_playback_close,
  563. .prepare = snd_intel8x0m_pcm_prepare,
  564. .trigger = snd_intel8x0m_pcm_trigger,
  565. .pointer = snd_intel8x0m_pcm_pointer,
  566. };
  567. static const struct snd_pcm_ops snd_intel8x0m_capture_ops = {
  568. .open = snd_intel8x0m_capture_open,
  569. .close = snd_intel8x0m_capture_close,
  570. .prepare = snd_intel8x0m_pcm_prepare,
  571. .trigger = snd_intel8x0m_pcm_trigger,
  572. .pointer = snd_intel8x0m_pcm_pointer,
  573. };
  574. struct ich_pcm_table {
  575. char *suffix;
  576. const struct snd_pcm_ops *playback_ops;
  577. const struct snd_pcm_ops *capture_ops;
  578. size_t prealloc_size;
  579. size_t prealloc_max_size;
  580. int ac97_idx;
  581. };
  582. static int snd_intel8x0m_pcm1(struct intel8x0m *chip, int device,
  583. const struct ich_pcm_table *rec)
  584. {
  585. struct snd_pcm *pcm;
  586. int err;
  587. char name[32];
  588. if (rec->suffix)
  589. sprintf(name, "Intel ICH - %s", rec->suffix);
  590. else
  591. strcpy(name, "Intel ICH");
  592. err = snd_pcm_new(chip->card, name, device,
  593. rec->playback_ops ? 1 : 0,
  594. rec->capture_ops ? 1 : 0, &pcm);
  595. if (err < 0)
  596. return err;
  597. if (rec->playback_ops)
  598. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, rec->playback_ops);
  599. if (rec->capture_ops)
  600. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, rec->capture_ops);
  601. pcm->private_data = chip;
  602. pcm->info_flags = 0;
  603. pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
  604. if (rec->suffix)
  605. sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
  606. else
  607. strcpy(pcm->name, chip->card->shortname);
  608. chip->pcm[device] = pcm;
  609. snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
  610. &chip->pci->dev,
  611. rec->prealloc_size,
  612. rec->prealloc_max_size);
  613. return 0;
  614. }
  615. static const struct ich_pcm_table intel_pcms[] = {
  616. {
  617. .suffix = "Modem",
  618. .playback_ops = &snd_intel8x0m_playback_ops,
  619. .capture_ops = &snd_intel8x0m_capture_ops,
  620. .prealloc_size = 32 * 1024,
  621. .prealloc_max_size = 64 * 1024,
  622. },
  623. };
  624. static int snd_intel8x0m_pcm(struct intel8x0m *chip)
  625. {
  626. int i, tblsize, device, err;
  627. const struct ich_pcm_table *tbl, *rec;
  628. #if 1
  629. tbl = intel_pcms;
  630. tblsize = 1;
  631. #else
  632. switch (chip->device_type) {
  633. case DEVICE_NFORCE:
  634. tbl = nforce_pcms;
  635. tblsize = ARRAY_SIZE(nforce_pcms);
  636. break;
  637. case DEVICE_ALI:
  638. tbl = ali_pcms;
  639. tblsize = ARRAY_SIZE(ali_pcms);
  640. break;
  641. default:
  642. tbl = intel_pcms;
  643. tblsize = 2;
  644. break;
  645. }
  646. #endif
  647. device = 0;
  648. for (i = 0; i < tblsize; i++) {
  649. rec = tbl + i;
  650. if (i > 0 && rec->ac97_idx) {
  651. /* activate PCM only when associated AC'97 codec */
  652. if (! chip->ichd[rec->ac97_idx].ac97)
  653. continue;
  654. }
  655. err = snd_intel8x0m_pcm1(chip, device, rec);
  656. if (err < 0)
  657. return err;
  658. device++;
  659. }
  660. chip->pcm_devs = device;
  661. return 0;
  662. }
  663. /*
  664. * Mixer part
  665. */
  666. static void snd_intel8x0m_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
  667. {
  668. struct intel8x0m *chip = bus->private_data;
  669. chip->ac97_bus = NULL;
  670. }
  671. static void snd_intel8x0m_mixer_free_ac97(struct snd_ac97 *ac97)
  672. {
  673. struct intel8x0m *chip = ac97->private_data;
  674. chip->ac97 = NULL;
  675. }
  676. static int snd_intel8x0m_mixer(struct intel8x0m *chip, int ac97_clock)
  677. {
  678. struct snd_ac97_bus *pbus;
  679. struct snd_ac97_template ac97;
  680. struct snd_ac97 *x97;
  681. int err;
  682. unsigned int glob_sta = 0;
  683. static const struct snd_ac97_bus_ops ops = {
  684. .write = snd_intel8x0m_codec_write,
  685. .read = snd_intel8x0m_codec_read,
  686. };
  687. chip->in_ac97_init = 1;
  688. memset(&ac97, 0, sizeof(ac97));
  689. ac97.private_data = chip;
  690. ac97.private_free = snd_intel8x0m_mixer_free_ac97;
  691. ac97.scaps = AC97_SCAP_SKIP_AUDIO | AC97_SCAP_POWER_SAVE;
  692. glob_sta = igetdword(chip, ICHREG(GLOB_STA));
  693. err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus);
  694. if (err < 0)
  695. goto __err;
  696. pbus->private_free = snd_intel8x0m_mixer_free_ac97_bus;
  697. if (ac97_clock >= 8000 && ac97_clock <= 48000)
  698. pbus->clock = ac97_clock;
  699. chip->ac97_bus = pbus;
  700. ac97.pci = chip->pci;
  701. ac97.num = glob_sta & ICH_SCR ? 1 : 0;
  702. err = snd_ac97_mixer(pbus, &ac97, &x97);
  703. if (err < 0) {
  704. dev_err(chip->card->dev,
  705. "Unable to initialize codec #%d\n", ac97.num);
  706. if (ac97.num == 0)
  707. goto __err;
  708. return err;
  709. }
  710. chip->ac97 = x97;
  711. if(ac97_is_modem(x97) && !chip->ichd[ICHD_MDMIN].ac97) {
  712. chip->ichd[ICHD_MDMIN].ac97 = x97;
  713. chip->ichd[ICHD_MDMOUT].ac97 = x97;
  714. }
  715. chip->in_ac97_init = 0;
  716. return 0;
  717. __err:
  718. /* clear the cold-reset bit for the next chance */
  719. if (chip->device_type != DEVICE_ALI)
  720. iputdword(chip, ICHREG(GLOB_CNT),
  721. igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_AC97COLD);
  722. return err;
  723. }
  724. /*
  725. *
  726. */
  727. static int snd_intel8x0m_ich_chip_init(struct intel8x0m *chip, int probing)
  728. {
  729. unsigned long end_time;
  730. unsigned int cnt, status, nstatus;
  731. /* put logic to right state */
  732. /* first clear status bits */
  733. status = ICH_RCS | ICH_MIINT | ICH_MOINT;
  734. cnt = igetdword(chip, ICHREG(GLOB_STA));
  735. iputdword(chip, ICHREG(GLOB_STA), cnt & status);
  736. /* ACLink on, 2 channels */
  737. cnt = igetdword(chip, ICHREG(GLOB_CNT));
  738. cnt &= ~(ICH_ACLINK);
  739. /* finish cold or do warm reset */
  740. cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
  741. iputdword(chip, ICHREG(GLOB_CNT), cnt);
  742. usleep_range(500, 1000); /* give warm reset some time */
  743. end_time = jiffies + HZ / 4;
  744. do {
  745. if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
  746. goto __ok;
  747. schedule_timeout_uninterruptible(1);
  748. } while (time_after_eq(end_time, jiffies));
  749. dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
  750. igetdword(chip, ICHREG(GLOB_CNT)));
  751. return -EIO;
  752. __ok:
  753. if (probing) {
  754. /* wait for any codec ready status.
  755. * Once it becomes ready it should remain ready
  756. * as long as we do not disable the ac97 link.
  757. */
  758. end_time = jiffies + HZ;
  759. do {
  760. status = igetdword(chip, ICHREG(GLOB_STA)) &
  761. (ICH_PCR | ICH_SCR | ICH_TCR);
  762. if (status)
  763. break;
  764. schedule_timeout_uninterruptible(1);
  765. } while (time_after_eq(end_time, jiffies));
  766. if (! status) {
  767. /* no codec is found */
  768. dev_err(chip->card->dev,
  769. "codec_ready: codec is not ready [0x%x]\n",
  770. igetdword(chip, ICHREG(GLOB_STA)));
  771. return -EIO;
  772. }
  773. /* up to two codecs (modem cannot be tertiary with ICH4) */
  774. nstatus = ICH_PCR | ICH_SCR;
  775. /* wait for other codecs ready status. */
  776. end_time = jiffies + HZ / 4;
  777. while (status != nstatus && time_after_eq(end_time, jiffies)) {
  778. schedule_timeout_uninterruptible(1);
  779. status |= igetdword(chip, ICHREG(GLOB_STA)) & nstatus;
  780. }
  781. } else {
  782. /* resume phase */
  783. status = 0;
  784. if (chip->ac97)
  785. status |= get_ich_codec_bit(chip, chip->ac97->num);
  786. /* wait until all the probed codecs are ready */
  787. end_time = jiffies + HZ;
  788. do {
  789. nstatus = igetdword(chip, ICHREG(GLOB_STA)) &
  790. (ICH_PCR | ICH_SCR | ICH_TCR);
  791. if (status == nstatus)
  792. break;
  793. schedule_timeout_uninterruptible(1);
  794. } while (time_after_eq(end_time, jiffies));
  795. }
  796. if (chip->device_type == DEVICE_SIS) {
  797. /* unmute the output on SIS7012 */
  798. iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
  799. }
  800. return 0;
  801. }
  802. static int snd_intel8x0m_chip_init(struct intel8x0m *chip, int probing)
  803. {
  804. unsigned int i;
  805. int err;
  806. err = snd_intel8x0m_ich_chip_init(chip, probing);
  807. if (err < 0)
  808. return err;
  809. iagetword(chip, 0); /* clear semaphore flag */
  810. /* disable interrupts */
  811. for (i = 0; i < chip->bdbars_count; i++)
  812. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  813. /* reset channels */
  814. for (i = 0; i < chip->bdbars_count; i++)
  815. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  816. /* initialize Buffer Descriptor Lists */
  817. for (i = 0; i < chip->bdbars_count; i++)
  818. iputdword(chip, ICH_REG_OFF_BDBAR + chip->ichd[i].reg_offset, chip->ichd[i].bdbar_addr);
  819. return 0;
  820. }
  821. static void snd_intel8x0m_free(struct snd_card *card)
  822. {
  823. struct intel8x0m *chip = card->private_data;
  824. unsigned int i;
  825. if (chip->irq < 0)
  826. goto __hw_end;
  827. /* disable interrupts */
  828. for (i = 0; i < chip->bdbars_count; i++)
  829. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, 0x00);
  830. /* reset channels */
  831. for (i = 0; i < chip->bdbars_count; i++)
  832. iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
  833. __hw_end:
  834. if (chip->irq >= 0)
  835. free_irq(chip->irq, chip);
  836. }
  837. #ifdef CONFIG_PM_SLEEP
  838. /*
  839. * power management
  840. */
  841. static int intel8x0m_suspend(struct device *dev)
  842. {
  843. struct snd_card *card = dev_get_drvdata(dev);
  844. struct intel8x0m *chip = card->private_data;
  845. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  846. snd_ac97_suspend(chip->ac97);
  847. if (chip->irq >= 0) {
  848. free_irq(chip->irq, chip);
  849. chip->irq = -1;
  850. card->sync_irq = -1;
  851. }
  852. return 0;
  853. }
  854. static int intel8x0m_resume(struct device *dev)
  855. {
  856. struct pci_dev *pci = to_pci_dev(dev);
  857. struct snd_card *card = dev_get_drvdata(dev);
  858. struct intel8x0m *chip = card->private_data;
  859. if (request_irq(pci->irq, snd_intel8x0m_interrupt,
  860. IRQF_SHARED, KBUILD_MODNAME, chip)) {
  861. dev_err(dev, "unable to grab IRQ %d, disabling device\n",
  862. pci->irq);
  863. snd_card_disconnect(card);
  864. return -EIO;
  865. }
  866. chip->irq = pci->irq;
  867. card->sync_irq = chip->irq;
  868. snd_intel8x0m_chip_init(chip, 0);
  869. snd_ac97_resume(chip->ac97);
  870. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  871. return 0;
  872. }
  873. static SIMPLE_DEV_PM_OPS(intel8x0m_pm, intel8x0m_suspend, intel8x0m_resume);
  874. #define INTEL8X0M_PM_OPS &intel8x0m_pm
  875. #else
  876. #define INTEL8X0M_PM_OPS NULL
  877. #endif /* CONFIG_PM_SLEEP */
  878. static void snd_intel8x0m_proc_read(struct snd_info_entry * entry,
  879. struct snd_info_buffer *buffer)
  880. {
  881. struct intel8x0m *chip = entry->private_data;
  882. unsigned int tmp;
  883. snd_iprintf(buffer, "Intel8x0m\n\n");
  884. if (chip->device_type == DEVICE_ALI)
  885. return;
  886. tmp = igetdword(chip, ICHREG(GLOB_STA));
  887. snd_iprintf(buffer, "Global control : 0x%08x\n",
  888. igetdword(chip, ICHREG(GLOB_CNT)));
  889. snd_iprintf(buffer, "Global status : 0x%08x\n", tmp);
  890. snd_iprintf(buffer, "AC'97 codecs ready :%s%s%s%s\n",
  891. tmp & ICH_PCR ? " primary" : "",
  892. tmp & ICH_SCR ? " secondary" : "",
  893. tmp & ICH_TCR ? " tertiary" : "",
  894. (tmp & (ICH_PCR | ICH_SCR | ICH_TCR)) == 0 ? " none" : "");
  895. }
  896. static void snd_intel8x0m_proc_init(struct intel8x0m *chip)
  897. {
  898. snd_card_ro_proc_new(chip->card, "intel8x0m", chip,
  899. snd_intel8x0m_proc_read);
  900. }
  901. struct ich_reg_info {
  902. unsigned int int_sta_mask;
  903. unsigned int offset;
  904. };
  905. static int snd_intel8x0m_init(struct snd_card *card,
  906. struct pci_dev *pci,
  907. unsigned long device_type)
  908. {
  909. struct intel8x0m *chip = card->private_data;
  910. int err;
  911. unsigned int i;
  912. unsigned int int_sta_masks;
  913. struct ichdev *ichdev;
  914. static const struct ich_reg_info intel_regs[2] = {
  915. { ICH_MIINT, 0 },
  916. { ICH_MOINT, 0x10 },
  917. };
  918. const struct ich_reg_info *tbl;
  919. err = pcim_enable_device(pci);
  920. if (err < 0)
  921. return err;
  922. spin_lock_init(&chip->reg_lock);
  923. chip->device_type = device_type;
  924. chip->card = card;
  925. chip->pci = pci;
  926. chip->irq = -1;
  927. err = pci_request_regions(pci, card->shortname);
  928. if (err < 0)
  929. return err;
  930. if (device_type == DEVICE_ALI) {
  931. /* ALI5455 has no ac97 region */
  932. chip->bmaddr = pcim_iomap(pci, 0, 0);
  933. } else {
  934. if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
  935. chip->addr = pcim_iomap(pci, 2, 0);
  936. else
  937. chip->addr = pcim_iomap(pci, 0, 0);
  938. if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
  939. chip->bmaddr = pcim_iomap(pci, 3, 0);
  940. else
  941. chip->bmaddr = pcim_iomap(pci, 1, 0);
  942. }
  943. /* initialize offsets */
  944. chip->bdbars_count = 2;
  945. tbl = intel_regs;
  946. for (i = 0; i < chip->bdbars_count; i++) {
  947. ichdev = &chip->ichd[i];
  948. ichdev->ichd = i;
  949. ichdev->reg_offset = tbl[i].offset;
  950. ichdev->int_sta_mask = tbl[i].int_sta_mask;
  951. if (device_type == DEVICE_SIS) {
  952. /* SiS 7013 swaps the registers */
  953. ichdev->roff_sr = ICH_REG_OFF_PICB;
  954. ichdev->roff_picb = ICH_REG_OFF_SR;
  955. } else {
  956. ichdev->roff_sr = ICH_REG_OFF_SR;
  957. ichdev->roff_picb = ICH_REG_OFF_PICB;
  958. }
  959. if (device_type == DEVICE_ALI)
  960. ichdev->ali_slot = (ichdev->reg_offset - 0x40) / 0x10;
  961. }
  962. /* SIS7013 handles the pcm data in bytes, others are in words */
  963. chip->pcm_pos_shift = (device_type == DEVICE_SIS) ? 0 : 1;
  964. /* allocate buffer descriptor lists */
  965. /* the start of each lists must be aligned to 8 bytes */
  966. chip->bdbars = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV,
  967. chip->bdbars_count * sizeof(u32) *
  968. ICH_MAX_FRAGS * 2);
  969. if (!chip->bdbars)
  970. return -ENOMEM;
  971. /* tables must be aligned to 8 bytes here, but the kernel pages
  972. are much bigger, so we don't care (on i386) */
  973. int_sta_masks = 0;
  974. for (i = 0; i < chip->bdbars_count; i++) {
  975. ichdev = &chip->ichd[i];
  976. ichdev->bdbar = ((__le32 *)chip->bdbars->area) + (i * ICH_MAX_FRAGS * 2);
  977. ichdev->bdbar_addr = chip->bdbars->addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
  978. int_sta_masks |= ichdev->int_sta_mask;
  979. }
  980. chip->int_sta_reg = ICH_REG_GLOB_STA;
  981. chip->int_sta_mask = int_sta_masks;
  982. pci_set_master(pci);
  983. err = snd_intel8x0m_chip_init(chip, 1);
  984. if (err < 0)
  985. return err;
  986. /* NOTE: we don't use devm version here since it's released /
  987. * re-acquired in PM callbacks.
  988. * It's released explicitly in snd_intel8x0m_free(), too.
  989. */
  990. if (request_irq(pci->irq, snd_intel8x0m_interrupt, IRQF_SHARED,
  991. KBUILD_MODNAME, chip)) {
  992. dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
  993. return -EBUSY;
  994. }
  995. chip->irq = pci->irq;
  996. card->sync_irq = chip->irq;
  997. card->private_free = snd_intel8x0m_free;
  998. return 0;
  999. }
  1000. static struct shortname_table {
  1001. unsigned int id;
  1002. const char *s;
  1003. } shortnames[] = {
  1004. { PCI_DEVICE_ID_INTEL_82801AA_6, "Intel 82801AA-ICH" },
  1005. { PCI_DEVICE_ID_INTEL_82801AB_6, "Intel 82901AB-ICH0" },
  1006. { PCI_DEVICE_ID_INTEL_82801BA_6, "Intel 82801BA-ICH2" },
  1007. { PCI_DEVICE_ID_INTEL_440MX_6, "Intel 440MX" },
  1008. { PCI_DEVICE_ID_INTEL_82801CA_6, "Intel 82801CA-ICH3" },
  1009. { PCI_DEVICE_ID_INTEL_82801DB_6, "Intel 82801DB-ICH4" },
  1010. { PCI_DEVICE_ID_INTEL_82801EB_6, "Intel ICH5" },
  1011. { PCI_DEVICE_ID_INTEL_ICH6_17, "Intel ICH6" },
  1012. { PCI_DEVICE_ID_INTEL_ICH7_19, "Intel ICH7" },
  1013. { 0x7446, "AMD AMD768" },
  1014. { PCI_DEVICE_ID_SI_7013, "SiS SI7013" },
  1015. { PCI_DEVICE_ID_NVIDIA_MCP1_MODEM, "NVidia nForce" },
  1016. { PCI_DEVICE_ID_NVIDIA_MCP2_MODEM, "NVidia nForce2" },
  1017. { PCI_DEVICE_ID_NVIDIA_MCP2S_MODEM, "NVidia nForce2s" },
  1018. { PCI_DEVICE_ID_NVIDIA_MCP3_MODEM, "NVidia nForce3" },
  1019. { 0x746e, "AMD AMD8111" },
  1020. #if 0
  1021. { 0x5455, "ALi M5455" },
  1022. #endif
  1023. { 0 },
  1024. };
  1025. static int __snd_intel8x0m_probe(struct pci_dev *pci,
  1026. const struct pci_device_id *pci_id)
  1027. {
  1028. struct snd_card *card;
  1029. struct intel8x0m *chip;
  1030. int err;
  1031. struct shortname_table *name;
  1032. err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
  1033. sizeof(*chip), &card);
  1034. if (err < 0)
  1035. return err;
  1036. chip = card->private_data;
  1037. strcpy(card->driver, "ICH-MODEM");
  1038. strcpy(card->shortname, "Intel ICH");
  1039. for (name = shortnames; name->id; name++) {
  1040. if (pci->device == name->id) {
  1041. strcpy(card->shortname, name->s);
  1042. break;
  1043. }
  1044. }
  1045. strcat(card->shortname," Modem");
  1046. err = snd_intel8x0m_init(card, pci, pci_id->driver_data);
  1047. if (err < 0)
  1048. return err;
  1049. err = snd_intel8x0m_mixer(chip, ac97_clock);
  1050. if (err < 0)
  1051. return err;
  1052. err = snd_intel8x0m_pcm(chip);
  1053. if (err < 0)
  1054. return err;
  1055. snd_intel8x0m_proc_init(chip);
  1056. sprintf(card->longname, "%s at irq %i",
  1057. card->shortname, chip->irq);
  1058. err = snd_card_register(card);
  1059. if (err < 0)
  1060. return err;
  1061. pci_set_drvdata(pci, card);
  1062. return 0;
  1063. }
  1064. static int snd_intel8x0m_probe(struct pci_dev *pci,
  1065. const struct pci_device_id *pci_id)
  1066. {
  1067. return snd_card_free_on_error(&pci->dev, __snd_intel8x0m_probe(pci, pci_id));
  1068. }
  1069. static struct pci_driver intel8x0m_driver = {
  1070. .name = KBUILD_MODNAME,
  1071. .id_table = snd_intel8x0m_ids,
  1072. .probe = snd_intel8x0m_probe,
  1073. .driver = {
  1074. .pm = INTEL8X0M_PM_OPS,
  1075. },
  1076. };
  1077. module_pci_driver(intel8x0m_driver);