cs4231_lib.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * Routines for control of CS4231(A)/CS4232/InterWave & compatible chips
  4. *
  5. * Bugs:
  6. * - sometimes record brokes playback with WSS portion of
  7. * Yamaha OPL3-SA3 chip
  8. * - CS4231 (GUS MAX) - still trouble with occasional noises
  9. * - broken initialization?
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. #include <sound/driver.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm.h>
  29. #include <linux/init.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/slab.h>
  32. #include <linux/ioport.h>
  33. #include <sound/core.h>
  34. #include <sound/cs4231.h>
  35. #include <sound/pcm_params.h>
  36. #include <asm/io.h>
  37. #include <asm/dma.h>
  38. #include <asm/irq.h>
  39. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  40. MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
  41. MODULE_LICENSE("GPL");
  42. #if 0
  43. #define SNDRV_DEBUG_MCE
  44. #endif
  45. /*
  46. * Some variables
  47. */
  48. static unsigned char freq_bits[14] = {
  49. /* 5510 */ 0x00 | CS4231_XTAL2,
  50. /* 6620 */ 0x0E | CS4231_XTAL2,
  51. /* 8000 */ 0x00 | CS4231_XTAL1,
  52. /* 9600 */ 0x0E | CS4231_XTAL1,
  53. /* 11025 */ 0x02 | CS4231_XTAL2,
  54. /* 16000 */ 0x02 | CS4231_XTAL1,
  55. /* 18900 */ 0x04 | CS4231_XTAL2,
  56. /* 22050 */ 0x06 | CS4231_XTAL2,
  57. /* 27042 */ 0x04 | CS4231_XTAL1,
  58. /* 32000 */ 0x06 | CS4231_XTAL1,
  59. /* 33075 */ 0x0C | CS4231_XTAL2,
  60. /* 37800 */ 0x08 | CS4231_XTAL2,
  61. /* 44100 */ 0x0A | CS4231_XTAL2,
  62. /* 48000 */ 0x0C | CS4231_XTAL1
  63. };
  64. static unsigned int rates[14] = {
  65. 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
  66. 27042, 32000, 33075, 37800, 44100, 48000
  67. };
  68. static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
  69. .count = 14,
  70. .list = rates,
  71. .mask = 0,
  72. };
  73. static int snd_cs4231_xrate(snd_pcm_runtime_t *runtime)
  74. {
  75. return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
  76. }
  77. static unsigned char snd_cs4231_original_image[32] =
  78. {
  79. 0x00, /* 00/00 - lic */
  80. 0x00, /* 01/01 - ric */
  81. 0x9f, /* 02/02 - la1ic */
  82. 0x9f, /* 03/03 - ra1ic */
  83. 0x9f, /* 04/04 - la2ic */
  84. 0x9f, /* 05/05 - ra2ic */
  85. 0xbf, /* 06/06 - loc */
  86. 0xbf, /* 07/07 - roc */
  87. 0x20, /* 08/08 - pdfr */
  88. CS4231_AUTOCALIB, /* 09/09 - ic */
  89. 0x00, /* 0a/10 - pc */
  90. 0x00, /* 0b/11 - ti */
  91. CS4231_MODE2, /* 0c/12 - mi */
  92. 0xfc, /* 0d/13 - lbc */
  93. 0x00, /* 0e/14 - pbru */
  94. 0x00, /* 0f/15 - pbrl */
  95. 0x80, /* 10/16 - afei */
  96. 0x01, /* 11/17 - afeii */
  97. 0x9f, /* 12/18 - llic */
  98. 0x9f, /* 13/19 - rlic */
  99. 0x00, /* 14/20 - tlb */
  100. 0x00, /* 15/21 - thb */
  101. 0x00, /* 16/22 - la3mic/reserved */
  102. 0x00, /* 17/23 - ra3mic/reserved */
  103. 0x00, /* 18/24 - afs */
  104. 0x00, /* 19/25 - lamoc/version */
  105. 0xcf, /* 1a/26 - mioc */
  106. 0x00, /* 1b/27 - ramoc/reserved */
  107. 0x20, /* 1c/28 - cdfr */
  108. 0x00, /* 1d/29 - res4 */
  109. 0x00, /* 1e/30 - cbru */
  110. 0x00, /* 1f/31 - cbrl */
  111. };
  112. /*
  113. * Basic I/O functions
  114. */
  115. #if !defined(EBUS_SUPPORT) && !defined(SBUS_SUPPORT)
  116. #define __CS4231_INLINE__ inline
  117. #else
  118. #define __CS4231_INLINE__ /* nothing */
  119. #endif
  120. static __CS4231_INLINE__ void cs4231_outb(cs4231_t *chip, u8 offset, u8 val)
  121. {
  122. #ifdef EBUS_SUPPORT
  123. if (chip->ebus->flag) {
  124. writeb(val, chip->port + (offset << 2));
  125. } else {
  126. #endif
  127. #ifdef SBUS_SUPPORT
  128. sbus_writeb(val, chip->port + (offset << 2));
  129. #endif
  130. #ifdef EBUS_SUPPORT
  131. }
  132. #endif
  133. #ifdef LEGACY_SUPPORT
  134. outb(val, chip->port + offset);
  135. #endif
  136. }
  137. static __CS4231_INLINE__ u8 cs4231_inb(cs4231_t *chip, u8 offset)
  138. {
  139. #ifdef EBUS_SUPPORT
  140. if (chip->ebus_flag) {
  141. return readb(chip->port + (offset << 2));
  142. } else {
  143. #endif
  144. #ifdef SBUS_SUPPORT
  145. return sbus_readb(chip->port + (offset << 2));
  146. #endif
  147. #ifdef EBUS_SUPPORT
  148. }
  149. #endif
  150. #ifdef LEGACY_SUPPORT
  151. return inb(chip->port + offset);
  152. #endif
  153. }
  154. static void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
  155. unsigned char mask, unsigned char value)
  156. {
  157. int timeout;
  158. unsigned char tmp;
  159. for (timeout = 250;
  160. timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
  161. timeout--)
  162. udelay(100);
  163. #ifdef CONFIG_SND_DEBUG
  164. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  165. snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
  166. #endif
  167. if (chip->calibrate_mute) {
  168. chip->image[reg] &= mask;
  169. chip->image[reg] |= value;
  170. } else {
  171. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
  172. mb();
  173. tmp = (chip->image[reg] & mask) | value;
  174. cs4231_outb(chip, CS4231P(REG), tmp);
  175. chip->image[reg] = tmp;
  176. mb();
  177. }
  178. }
  179. static void snd_cs4231_dout(cs4231_t *chip, unsigned char reg, unsigned char value)
  180. {
  181. int timeout;
  182. for (timeout = 250;
  183. timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
  184. timeout--)
  185. udelay(10);
  186. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
  187. cs4231_outb(chip, CS4231P(REG), value);
  188. mb();
  189. }
  190. void snd_cs4231_out(cs4231_t *chip, unsigned char reg, unsigned char value)
  191. {
  192. int timeout;
  193. for (timeout = 250;
  194. timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
  195. timeout--)
  196. udelay(100);
  197. #ifdef CONFIG_SND_DEBUG
  198. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  199. snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
  200. #endif
  201. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
  202. cs4231_outb(chip, CS4231P(REG), value);
  203. chip->image[reg] = value;
  204. mb();
  205. #if 0
  206. printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
  207. #endif
  208. }
  209. unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
  210. {
  211. int timeout;
  212. for (timeout = 250;
  213. timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
  214. timeout--)
  215. udelay(100);
  216. #ifdef CONFIG_SND_DEBUG
  217. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  218. snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
  219. #endif
  220. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
  221. mb();
  222. return cs4231_inb(chip, CS4231P(REG));
  223. }
  224. void snd_cs4236_ext_out(cs4231_t *chip, unsigned char reg, unsigned char val)
  225. {
  226. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
  227. cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
  228. cs4231_outb(chip, CS4231P(REG), val);
  229. chip->eimage[CS4236_REG(reg)] = val;
  230. #if 0
  231. printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val);
  232. #endif
  233. }
  234. unsigned char snd_cs4236_ext_in(cs4231_t *chip, unsigned char reg)
  235. {
  236. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
  237. cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
  238. #if 1
  239. return cs4231_inb(chip, CS4231P(REG));
  240. #else
  241. {
  242. unsigned char res;
  243. res = cs4231_inb(chip, CS4231P(REG));
  244. printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res);
  245. return res;
  246. }
  247. #endif
  248. }
  249. #if 0
  250. static void snd_cs4231_debug(cs4231_t *chip)
  251. {
  252. printk("CS4231 REGS: INDEX = 0x%02x ", cs4231_inb(chip, CS4231P(REGSEL)));
  253. printk(" STATUS = 0x%02x\n", cs4231_inb(chip, CS4231P(STATUS)));
  254. printk(" 0x00: left input = 0x%02x ", snd_cs4231_in(chip, 0x00));
  255. printk(" 0x10: alt 1 (CFIG 2) = 0x%02x\n", snd_cs4231_in(chip, 0x10));
  256. printk(" 0x01: right input = 0x%02x ", snd_cs4231_in(chip, 0x01));
  257. printk(" 0x11: alt 2 (CFIG 3) = 0x%02x\n", snd_cs4231_in(chip, 0x11));
  258. printk(" 0x02: GF1 left input = 0x%02x ", snd_cs4231_in(chip, 0x02));
  259. printk(" 0x12: left line in = 0x%02x\n", snd_cs4231_in(chip, 0x12));
  260. printk(" 0x03: GF1 right input = 0x%02x ", snd_cs4231_in(chip, 0x03));
  261. printk(" 0x13: right line in = 0x%02x\n", snd_cs4231_in(chip, 0x13));
  262. printk(" 0x04: CD left input = 0x%02x ", snd_cs4231_in(chip, 0x04));
  263. printk(" 0x14: timer low = 0x%02x\n", snd_cs4231_in(chip, 0x14));
  264. printk(" 0x05: CD right input = 0x%02x ", snd_cs4231_in(chip, 0x05));
  265. printk(" 0x15: timer high = 0x%02x\n", snd_cs4231_in(chip, 0x15));
  266. printk(" 0x06: left output = 0x%02x ", snd_cs4231_in(chip, 0x06));
  267. printk(" 0x16: left MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x16));
  268. printk(" 0x07: right output = 0x%02x ", snd_cs4231_in(chip, 0x07));
  269. printk(" 0x17: right MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x17));
  270. printk(" 0x08: playback format = 0x%02x ", snd_cs4231_in(chip, 0x08));
  271. printk(" 0x18: IRQ status = 0x%02x\n", snd_cs4231_in(chip, 0x18));
  272. printk(" 0x09: iface (CFIG 1) = 0x%02x ", snd_cs4231_in(chip, 0x09));
  273. printk(" 0x19: left line out = 0x%02x\n", snd_cs4231_in(chip, 0x19));
  274. printk(" 0x0a: pin control = 0x%02x ", snd_cs4231_in(chip, 0x0a));
  275. printk(" 0x1a: mono control = 0x%02x\n", snd_cs4231_in(chip, 0x1a));
  276. printk(" 0x0b: init & status = 0x%02x ", snd_cs4231_in(chip, 0x0b));
  277. printk(" 0x1b: right line out = 0x%02x\n", snd_cs4231_in(chip, 0x1b));
  278. printk(" 0x0c: revision & mode = 0x%02x ", snd_cs4231_in(chip, 0x0c));
  279. printk(" 0x1c: record format = 0x%02x\n", snd_cs4231_in(chip, 0x1c));
  280. printk(" 0x0d: loopback = 0x%02x ", snd_cs4231_in(chip, 0x0d));
  281. printk(" 0x1d: var freq (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x1d));
  282. printk(" 0x0e: ply upr count = 0x%02x ", snd_cs4231_in(chip, 0x0e));
  283. printk(" 0x1e: ply lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1e));
  284. printk(" 0x0f: rec upr count = 0x%02x ", snd_cs4231_in(chip, 0x0f));
  285. printk(" 0x1f: rec lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1f));
  286. }
  287. #endif
  288. /*
  289. * CS4231 detection / MCE routines
  290. */
  291. static void snd_cs4231_busy_wait(cs4231_t *chip)
  292. {
  293. int timeout;
  294. /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
  295. for (timeout = 5; timeout > 0; timeout--)
  296. cs4231_inb(chip, CS4231P(REGSEL));
  297. /* end of cleanup sequence */
  298. for (timeout = 250;
  299. timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
  300. timeout--)
  301. udelay(10);
  302. }
  303. void snd_cs4231_mce_up(cs4231_t *chip)
  304. {
  305. unsigned long flags;
  306. int timeout;
  307. for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--)
  308. udelay(100);
  309. #ifdef CONFIG_SND_DEBUG
  310. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  311. snd_printk("mce_up - auto calibration time out (0)\n");
  312. #endif
  313. spin_lock_irqsave(&chip->reg_lock, flags);
  314. chip->mce_bit |= CS4231_MCE;
  315. timeout = cs4231_inb(chip, CS4231P(REGSEL));
  316. if (timeout == 0x80)
  317. snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
  318. if (!(timeout & CS4231_MCE))
  319. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
  320. spin_unlock_irqrestore(&chip->reg_lock, flags);
  321. }
  322. void snd_cs4231_mce_down(cs4231_t *chip)
  323. {
  324. unsigned long flags;
  325. int timeout;
  326. snd_cs4231_busy_wait(chip);
  327. #if 0
  328. printk("(1) timeout = %i\n", timeout);
  329. #endif
  330. #ifdef CONFIG_SND_DEBUG
  331. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  332. snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
  333. #endif
  334. spin_lock_irqsave(&chip->reg_lock, flags);
  335. chip->mce_bit &= ~CS4231_MCE;
  336. timeout = cs4231_inb(chip, CS4231P(REGSEL));
  337. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
  338. spin_unlock_irqrestore(&chip->reg_lock, flags);
  339. if (timeout == 0x80)
  340. snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
  341. if ((timeout & CS4231_MCE) == 0 ||
  342. !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
  343. return;
  344. }
  345. snd_cs4231_busy_wait(chip);
  346. /* calibration process */
  347. for (timeout = 500; timeout > 0 && (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0; timeout--)
  348. udelay(10);
  349. if ((snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0) {
  350. snd_printd("cs4231_mce_down - auto calibration time out (1)\n");
  351. return;
  352. }
  353. #if 0
  354. printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
  355. #endif
  356. /* in 10 ms increments, check condition, up to 250 ms */
  357. timeout = 25;
  358. while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) {
  359. if (--timeout < 0) {
  360. snd_printk("mce_down - auto calibration time out (2)\n");
  361. return;
  362. }
  363. msleep(10);
  364. }
  365. #if 0
  366. printk("(3) jiffies = %li\n", jiffies);
  367. #endif
  368. /* in 10 ms increments, check condition, up to 100 ms */
  369. timeout = 10;
  370. while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
  371. if (--timeout < 0) {
  372. snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
  373. return;
  374. }
  375. msleep(10);
  376. }
  377. #if 0
  378. printk("(4) jiffies = %li\n", jiffies);
  379. snd_printk("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
  380. #endif
  381. }
  382. static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size)
  383. {
  384. switch (format & 0xe0) {
  385. case CS4231_LINEAR_16:
  386. case CS4231_LINEAR_16_BIG:
  387. size >>= 1;
  388. break;
  389. case CS4231_ADPCM_16:
  390. return size >> 2;
  391. }
  392. if (format & CS4231_STEREO)
  393. size >>= 1;
  394. return size;
  395. }
  396. static int snd_cs4231_trigger(snd_pcm_substream_t *substream,
  397. int cmd)
  398. {
  399. cs4231_t *chip = snd_pcm_substream_chip(substream);
  400. int result = 0;
  401. unsigned int what;
  402. struct list_head *pos;
  403. snd_pcm_substream_t *s;
  404. int do_start;
  405. #if 0
  406. printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, cs4231_inb(chip, CS4231P(STATUS)));
  407. #endif
  408. switch (cmd) {
  409. case SNDRV_PCM_TRIGGER_START:
  410. case SNDRV_PCM_TRIGGER_RESUME:
  411. do_start = 1; break;
  412. case SNDRV_PCM_TRIGGER_STOP:
  413. case SNDRV_PCM_TRIGGER_SUSPEND:
  414. do_start = 0; break;
  415. default:
  416. return -EINVAL;
  417. }
  418. what = 0;
  419. snd_pcm_group_for_each(pos, substream) {
  420. s = snd_pcm_group_substream_entry(pos);
  421. if (s == chip->playback_substream) {
  422. what |= CS4231_PLAYBACK_ENABLE;
  423. snd_pcm_trigger_done(s, substream);
  424. } else if (s == chip->capture_substream) {
  425. what |= CS4231_RECORD_ENABLE;
  426. snd_pcm_trigger_done(s, substream);
  427. }
  428. }
  429. spin_lock(&chip->reg_lock);
  430. if (do_start) {
  431. chip->image[CS4231_IFACE_CTRL] |= what;
  432. if (chip->trigger)
  433. chip->trigger(chip, what, 1);
  434. } else {
  435. chip->image[CS4231_IFACE_CTRL] &= ~what;
  436. if (chip->trigger)
  437. chip->trigger(chip, what, 0);
  438. }
  439. snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
  440. spin_unlock(&chip->reg_lock);
  441. #if 0
  442. snd_cs4231_debug(chip);
  443. #endif
  444. return result;
  445. }
  446. /*
  447. * CODEC I/O
  448. */
  449. static unsigned char snd_cs4231_get_rate(unsigned int rate)
  450. {
  451. int i;
  452. for (i = 0; i < 14; i++)
  453. if (rate == rates[i])
  454. return freq_bits[i];
  455. // snd_BUG();
  456. return freq_bits[13];
  457. }
  458. static unsigned char snd_cs4231_get_format(cs4231_t *chip,
  459. int format,
  460. int channels)
  461. {
  462. unsigned char rformat;
  463. rformat = CS4231_LINEAR_8;
  464. switch (format) {
  465. case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break;
  466. case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break;
  467. case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break;
  468. case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break;
  469. case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break;
  470. }
  471. if (channels > 1)
  472. rformat |= CS4231_STEREO;
  473. #if 0
  474. snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
  475. #endif
  476. return rformat;
  477. }
  478. static void snd_cs4231_calibrate_mute(cs4231_t *chip, int mute)
  479. {
  480. unsigned long flags;
  481. mute = mute ? 1 : 0;
  482. spin_lock_irqsave(&chip->reg_lock, flags);
  483. if (chip->calibrate_mute == mute) {
  484. spin_unlock_irqrestore(&chip->reg_lock, flags);
  485. return;
  486. }
  487. if (!mute) {
  488. snd_cs4231_dout(chip, CS4231_LEFT_INPUT, chip->image[CS4231_LEFT_INPUT]);
  489. snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, chip->image[CS4231_RIGHT_INPUT]);
  490. snd_cs4231_dout(chip, CS4231_LOOPBACK, chip->image[CS4231_LOOPBACK]);
  491. }
  492. snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]);
  493. snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]);
  494. snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]);
  495. snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]);
  496. snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]);
  497. snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]);
  498. snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]);
  499. snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]);
  500. snd_cs4231_dout(chip, CS4231_MONO_CTRL, mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]);
  501. if (chip->hardware == CS4231_HW_INTERWAVE) {
  502. snd_cs4231_dout(chip, CS4231_LEFT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_LEFT_MIC_INPUT]);
  503. snd_cs4231_dout(chip, CS4231_RIGHT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_MIC_INPUT]);
  504. snd_cs4231_dout(chip, CS4231_LINE_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_LEFT_OUTPUT]);
  505. snd_cs4231_dout(chip, CS4231_LINE_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_RIGHT_OUTPUT]);
  506. }
  507. chip->calibrate_mute = mute;
  508. spin_unlock_irqrestore(&chip->reg_lock, flags);
  509. }
  510. static void snd_cs4231_playback_format(cs4231_t *chip,
  511. snd_pcm_hw_params_t *params,
  512. unsigned char pdfr)
  513. {
  514. unsigned long flags;
  515. int full_calib = 1;
  516. down(&chip->mce_mutex);
  517. snd_cs4231_calibrate_mute(chip, 1);
  518. if (chip->hardware == CS4231_HW_CS4231A ||
  519. (chip->hardware & CS4231_HW_CS4232_MASK)) {
  520. spin_lock_irqsave(&chip->reg_lock, flags);
  521. if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */
  522. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
  523. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
  524. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x10);
  525. udelay(100); /* Fixes audible clicks at least on GUS MAX */
  526. full_calib = 0;
  527. }
  528. spin_unlock_irqrestore(&chip->reg_lock, flags);
  529. }
  530. if (full_calib) {
  531. snd_cs4231_mce_up(chip);
  532. spin_lock_irqsave(&chip->reg_lock, flags);
  533. if (chip->hardware != CS4231_HW_INTERWAVE && !chip->single_dma) {
  534. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
  535. (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ?
  536. (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) :
  537. pdfr);
  538. } else {
  539. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
  540. }
  541. spin_unlock_irqrestore(&chip->reg_lock, flags);
  542. snd_cs4231_mce_down(chip);
  543. }
  544. snd_cs4231_calibrate_mute(chip, 0);
  545. up(&chip->mce_mutex);
  546. }
  547. static void snd_cs4231_capture_format(cs4231_t *chip,
  548. snd_pcm_hw_params_t *params,
  549. unsigned char cdfr)
  550. {
  551. unsigned long flags;
  552. int full_calib = 1;
  553. down(&chip->mce_mutex);
  554. snd_cs4231_calibrate_mute(chip, 1);
  555. if (chip->hardware == CS4231_HW_CS4231A ||
  556. (chip->hardware & CS4231_HW_CS4232_MASK)) {
  557. spin_lock_irqsave(&chip->reg_lock, flags);
  558. if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */
  559. (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
  560. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
  561. snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT] = cdfr);
  562. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x20);
  563. full_calib = 0;
  564. }
  565. spin_unlock_irqrestore(&chip->reg_lock, flags);
  566. }
  567. if (full_calib) {
  568. snd_cs4231_mce_up(chip);
  569. spin_lock_irqsave(&chip->reg_lock, flags);
  570. if (chip->hardware != CS4231_HW_INTERWAVE) {
  571. if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
  572. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
  573. ((chip->single_dma ? cdfr : chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) |
  574. (cdfr & 0x0f));
  575. spin_unlock_irqrestore(&chip->reg_lock, flags);
  576. snd_cs4231_mce_down(chip);
  577. snd_cs4231_mce_up(chip);
  578. spin_lock_irqsave(&chip->reg_lock, flags);
  579. }
  580. }
  581. snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr);
  582. spin_unlock_irqrestore(&chip->reg_lock, flags);
  583. snd_cs4231_mce_down(chip);
  584. }
  585. snd_cs4231_calibrate_mute(chip, 0);
  586. up(&chip->mce_mutex);
  587. }
  588. /*
  589. * Timer interface
  590. */
  591. static unsigned long snd_cs4231_timer_resolution(snd_timer_t * timer)
  592. {
  593. cs4231_t *chip = snd_timer_chip(timer);
  594. if (chip->hardware & CS4231_HW_CS4236B_MASK)
  595. return 14467;
  596. else
  597. return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
  598. }
  599. static int snd_cs4231_timer_start(snd_timer_t * timer)
  600. {
  601. unsigned long flags;
  602. unsigned int ticks;
  603. cs4231_t *chip = snd_timer_chip(timer);
  604. spin_lock_irqsave(&chip->reg_lock, flags);
  605. ticks = timer->sticks;
  606. if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
  607. (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] ||
  608. (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) {
  609. snd_cs4231_out(chip, CS4231_TIMER_HIGH, chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8));
  610. snd_cs4231_out(chip, CS4231_TIMER_LOW, chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks);
  611. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | CS4231_TIMER_ENABLE);
  612. }
  613. spin_unlock_irqrestore(&chip->reg_lock, flags);
  614. return 0;
  615. }
  616. static int snd_cs4231_timer_stop(snd_timer_t * timer)
  617. {
  618. unsigned long flags;
  619. cs4231_t *chip = snd_timer_chip(timer);
  620. spin_lock_irqsave(&chip->reg_lock, flags);
  621. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE);
  622. spin_unlock_irqrestore(&chip->reg_lock, flags);
  623. return 0;
  624. }
  625. static void snd_cs4231_init(cs4231_t *chip)
  626. {
  627. unsigned long flags;
  628. snd_cs4231_mce_down(chip);
  629. #ifdef SNDRV_DEBUG_MCE
  630. snd_printk("init: (1)\n");
  631. #endif
  632. snd_cs4231_mce_up(chip);
  633. spin_lock_irqsave(&chip->reg_lock, flags);
  634. chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
  635. CS4231_RECORD_ENABLE | CS4231_RECORD_PIO |
  636. CS4231_CALIB_MODE);
  637. chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB;
  638. snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
  639. spin_unlock_irqrestore(&chip->reg_lock, flags);
  640. snd_cs4231_mce_down(chip);
  641. #ifdef SNDRV_DEBUG_MCE
  642. snd_printk("init: (2)\n");
  643. #endif
  644. snd_cs4231_mce_up(chip);
  645. spin_lock_irqsave(&chip->reg_lock, flags);
  646. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
  647. spin_unlock_irqrestore(&chip->reg_lock, flags);
  648. snd_cs4231_mce_down(chip);
  649. #ifdef SNDRV_DEBUG_MCE
  650. snd_printk("init: (3) - afei = 0x%x\n", chip->image[CS4231_ALT_FEATURE_1]);
  651. #endif
  652. spin_lock_irqsave(&chip->reg_lock, flags);
  653. snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, chip->image[CS4231_ALT_FEATURE_2]);
  654. spin_unlock_irqrestore(&chip->reg_lock, flags);
  655. snd_cs4231_mce_up(chip);
  656. spin_lock_irqsave(&chip->reg_lock, flags);
  657. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT]);
  658. spin_unlock_irqrestore(&chip->reg_lock, flags);
  659. snd_cs4231_mce_down(chip);
  660. #ifdef SNDRV_DEBUG_MCE
  661. snd_printk("init: (4)\n");
  662. #endif
  663. snd_cs4231_mce_up(chip);
  664. spin_lock_irqsave(&chip->reg_lock, flags);
  665. snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]);
  666. spin_unlock_irqrestore(&chip->reg_lock, flags);
  667. snd_cs4231_mce_down(chip);
  668. #ifdef SNDRV_DEBUG_MCE
  669. snd_printk("init: (5)\n");
  670. #endif
  671. }
  672. static int snd_cs4231_open(cs4231_t *chip, unsigned int mode)
  673. {
  674. unsigned long flags;
  675. down(&chip->open_mutex);
  676. if ((chip->mode & mode) ||
  677. ((chip->mode & CS4231_MODE_OPEN) && chip->single_dma)) {
  678. up(&chip->open_mutex);
  679. return -EAGAIN;
  680. }
  681. if (chip->mode & CS4231_MODE_OPEN) {
  682. chip->mode |= mode;
  683. up(&chip->open_mutex);
  684. return 0;
  685. }
  686. /* ok. now enable and ack CODEC IRQ */
  687. spin_lock_irqsave(&chip->reg_lock, flags);
  688. snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
  689. CS4231_RECORD_IRQ |
  690. CS4231_TIMER_IRQ);
  691. snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
  692. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  693. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  694. chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE;
  695. snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
  696. snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
  697. CS4231_RECORD_IRQ |
  698. CS4231_TIMER_IRQ);
  699. snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
  700. spin_unlock_irqrestore(&chip->reg_lock, flags);
  701. chip->mode = mode;
  702. up(&chip->open_mutex);
  703. return 0;
  704. }
  705. static void snd_cs4231_close(cs4231_t *chip, unsigned int mode)
  706. {
  707. unsigned long flags;
  708. down(&chip->open_mutex);
  709. chip->mode &= ~mode;
  710. if (chip->mode & CS4231_MODE_OPEN) {
  711. up(&chip->open_mutex);
  712. return;
  713. }
  714. snd_cs4231_calibrate_mute(chip, 1);
  715. /* disable IRQ */
  716. spin_lock_irqsave(&chip->reg_lock, flags);
  717. snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
  718. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  719. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  720. chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE;
  721. snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
  722. /* now disable record & playback */
  723. if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
  724. CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) {
  725. spin_unlock_irqrestore(&chip->reg_lock, flags);
  726. snd_cs4231_mce_up(chip);
  727. spin_lock_irqsave(&chip->reg_lock, flags);
  728. chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
  729. CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
  730. snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
  731. spin_unlock_irqrestore(&chip->reg_lock, flags);
  732. snd_cs4231_mce_down(chip);
  733. spin_lock_irqsave(&chip->reg_lock, flags);
  734. }
  735. /* clear IRQ again */
  736. snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
  737. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  738. cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
  739. spin_unlock_irqrestore(&chip->reg_lock, flags);
  740. snd_cs4231_calibrate_mute(chip, 0);
  741. chip->mode = 0;
  742. up(&chip->open_mutex);
  743. }
  744. /*
  745. * timer open/close
  746. */
  747. static int snd_cs4231_timer_open(snd_timer_t * timer)
  748. {
  749. cs4231_t *chip = snd_timer_chip(timer);
  750. snd_cs4231_open(chip, CS4231_MODE_TIMER);
  751. return 0;
  752. }
  753. static int snd_cs4231_timer_close(snd_timer_t * timer)
  754. {
  755. cs4231_t *chip = snd_timer_chip(timer);
  756. snd_cs4231_close(chip, CS4231_MODE_TIMER);
  757. return 0;
  758. }
  759. static struct _snd_timer_hardware snd_cs4231_timer_table =
  760. {
  761. .flags = SNDRV_TIMER_HW_AUTO,
  762. .resolution = 9945,
  763. .ticks = 65535,
  764. .open = snd_cs4231_timer_open,
  765. .close = snd_cs4231_timer_close,
  766. .c_resolution = snd_cs4231_timer_resolution,
  767. .start = snd_cs4231_timer_start,
  768. .stop = snd_cs4231_timer_stop,
  769. };
  770. /*
  771. * ok.. exported functions..
  772. */
  773. static int snd_cs4231_playback_hw_params(snd_pcm_substream_t * substream,
  774. snd_pcm_hw_params_t * hw_params)
  775. {
  776. cs4231_t *chip = snd_pcm_substream_chip(substream);
  777. unsigned char new_pdfr;
  778. int err;
  779. if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
  780. return err;
  781. new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
  782. snd_cs4231_get_rate(params_rate(hw_params));
  783. chip->set_playback_format(chip, hw_params, new_pdfr);
  784. return 0;
  785. }
  786. static int snd_cs4231_playback_hw_free(snd_pcm_substream_t * substream)
  787. {
  788. return snd_pcm_lib_free_pages(substream);
  789. }
  790. #ifdef LEGACY_SUPPORT
  791. static int snd_cs4231_playback_prepare(snd_pcm_substream_t * substream)
  792. {
  793. cs4231_t *chip = snd_pcm_substream_chip(substream);
  794. snd_pcm_runtime_t *runtime = substream->runtime;
  795. unsigned long flags;
  796. unsigned int size = snd_pcm_lib_buffer_bytes(substream);
  797. unsigned int count = snd_pcm_lib_period_bytes(substream);
  798. spin_lock_irqsave(&chip->reg_lock, flags);
  799. chip->p_dma_size = size;
  800. chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO);
  801. snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
  802. count = snd_cs4231_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1;
  803. snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
  804. snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
  805. spin_unlock_irqrestore(&chip->reg_lock, flags);
  806. #if 0
  807. snd_cs4231_debug(chip);
  808. #endif
  809. return 0;
  810. }
  811. #endif /* LEGACY_SUPPORT */
  812. static int snd_cs4231_capture_hw_params(snd_pcm_substream_t * substream,
  813. snd_pcm_hw_params_t * hw_params)
  814. {
  815. cs4231_t *chip = snd_pcm_substream_chip(substream);
  816. unsigned char new_cdfr;
  817. int err;
  818. if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
  819. return err;
  820. new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
  821. snd_cs4231_get_rate(params_rate(hw_params));
  822. chip->set_capture_format(chip, hw_params, new_cdfr);
  823. return 0;
  824. }
  825. static int snd_cs4231_capture_hw_free(snd_pcm_substream_t * substream)
  826. {
  827. return snd_pcm_lib_free_pages(substream);
  828. }
  829. #ifdef LEGACY_SUPPORT
  830. static int snd_cs4231_capture_prepare(snd_pcm_substream_t * substream)
  831. {
  832. cs4231_t *chip = snd_pcm_substream_chip(substream);
  833. snd_pcm_runtime_t *runtime = substream->runtime;
  834. unsigned long flags;
  835. unsigned int size = snd_pcm_lib_buffer_bytes(substream);
  836. unsigned int count = snd_pcm_lib_period_bytes(substream);
  837. spin_lock_irqsave(&chip->reg_lock, flags);
  838. chip->c_dma_size = size;
  839. chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
  840. snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
  841. count = snd_cs4231_get_count(chip->image[CS4231_REC_FORMAT], count) - 1;
  842. if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
  843. snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
  844. snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
  845. } else {
  846. snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count);
  847. snd_cs4231_out(chip, CS4231_REC_UPR_CNT, (unsigned char) (count >> 8));
  848. }
  849. spin_unlock_irqrestore(&chip->reg_lock, flags);
  850. return 0;
  851. }
  852. #endif
  853. static void snd_cs4231_overrange(cs4231_t *chip)
  854. {
  855. unsigned long flags;
  856. unsigned char res;
  857. spin_lock_irqsave(&chip->reg_lock, flags);
  858. res = snd_cs4231_in(chip, CS4231_TEST_INIT);
  859. spin_unlock_irqrestore(&chip->reg_lock, flags);
  860. if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
  861. chip->capture_substream->runtime->overrange++;
  862. }
  863. irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  864. {
  865. cs4231_t *chip = dev_id;
  866. unsigned char status;
  867. status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
  868. if (status & CS4231_TIMER_IRQ) {
  869. if (chip->timer)
  870. snd_timer_interrupt(chip->timer, chip->timer->sticks);
  871. }
  872. if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
  873. if (status & CS4231_PLAYBACK_IRQ) {
  874. if (chip->mode & CS4231_MODE_PLAY) {
  875. if (chip->playback_substream)
  876. snd_pcm_period_elapsed(chip->playback_substream);
  877. }
  878. if (chip->mode & CS4231_MODE_RECORD) {
  879. if (chip->capture_substream) {
  880. snd_cs4231_overrange(chip);
  881. snd_pcm_period_elapsed(chip->capture_substream);
  882. }
  883. }
  884. }
  885. } else {
  886. if (status & CS4231_PLAYBACK_IRQ) {
  887. if (chip->playback_substream)
  888. snd_pcm_period_elapsed(chip->playback_substream);
  889. }
  890. if (status & CS4231_RECORD_IRQ) {
  891. if (chip->capture_substream) {
  892. snd_cs4231_overrange(chip);
  893. snd_pcm_period_elapsed(chip->capture_substream);
  894. }
  895. }
  896. }
  897. spin_lock(&chip->reg_lock);
  898. snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
  899. spin_unlock(&chip->reg_lock);
  900. return IRQ_HANDLED;
  901. }
  902. #ifdef LEGACY_SUPPORT
  903. static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t * substream)
  904. {
  905. cs4231_t *chip = snd_pcm_substream_chip(substream);
  906. size_t ptr;
  907. if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
  908. return 0;
  909. ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
  910. return bytes_to_frames(substream->runtime, ptr);
  911. }
  912. static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream)
  913. {
  914. cs4231_t *chip = snd_pcm_substream_chip(substream);
  915. size_t ptr;
  916. if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
  917. return 0;
  918. ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
  919. return bytes_to_frames(substream->runtime, ptr);
  920. }
  921. #endif /* LEGACY_SUPPORT */
  922. /*
  923. */
  924. static int snd_cs4231_probe(cs4231_t *chip)
  925. {
  926. unsigned long flags;
  927. int i, id, rev;
  928. unsigned char *ptr;
  929. unsigned int hw;
  930. #if 0
  931. snd_cs4231_debug(chip);
  932. #endif
  933. id = 0;
  934. for (i = 0; i < 50; i++) {
  935. mb();
  936. if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
  937. udelay(2000);
  938. else {
  939. spin_lock_irqsave(&chip->reg_lock, flags);
  940. snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
  941. id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f;
  942. spin_unlock_irqrestore(&chip->reg_lock, flags);
  943. if (id == 0x0a)
  944. break; /* this is valid value */
  945. }
  946. }
  947. snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip->port, id);
  948. if (id != 0x0a)
  949. return -ENODEV; /* no valid device found */
  950. if (((hw = chip->hardware) & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
  951. rev = snd_cs4231_in(chip, CS4231_VERSION) & 0xe7;
  952. snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev);
  953. if (rev == 0x80) {
  954. unsigned char tmp = snd_cs4231_in(chip, 23);
  955. snd_cs4231_out(chip, 23, ~tmp);
  956. if (snd_cs4231_in(chip, 23) != tmp)
  957. chip->hardware = CS4231_HW_AD1845;
  958. else
  959. chip->hardware = CS4231_HW_CS4231;
  960. } else if (rev == 0xa0) {
  961. chip->hardware = CS4231_HW_CS4231A;
  962. } else if (rev == 0xa2) {
  963. chip->hardware = CS4231_HW_CS4232;
  964. } else if (rev == 0xb2) {
  965. chip->hardware = CS4231_HW_CS4232A;
  966. } else if (rev == 0x83) {
  967. chip->hardware = CS4231_HW_CS4236;
  968. } else if (rev == 0x03) {
  969. chip->hardware = CS4231_HW_CS4236B;
  970. } else {
  971. snd_printk("unknown CS chip with version 0x%x\n", rev);
  972. return -ENODEV; /* unknown CS4231 chip? */
  973. }
  974. }
  975. spin_lock_irqsave(&chip->reg_lock, flags);
  976. cs4231_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */
  977. cs4231_outb(chip, CS4231P(STATUS), 0);
  978. mb();
  979. spin_unlock_irqrestore(&chip->reg_lock, flags);
  980. chip->image[CS4231_MISC_INFO] = CS4231_MODE2;
  981. switch (chip->hardware) {
  982. case CS4231_HW_INTERWAVE:
  983. chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3;
  984. break;
  985. case CS4231_HW_CS4235:
  986. case CS4231_HW_CS4236B:
  987. case CS4231_HW_CS4237B:
  988. case CS4231_HW_CS4238B:
  989. case CS4231_HW_CS4239:
  990. if (hw == CS4231_HW_DETECT3)
  991. chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3;
  992. else
  993. chip->hardware = CS4231_HW_CS4236;
  994. break;
  995. }
  996. chip->image[CS4231_IFACE_CTRL] =
  997. (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
  998. (chip->single_dma ? CS4231_SINGLE_DMA : 0);
  999. chip->image[CS4231_ALT_FEATURE_1] = 0x80;
  1000. chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
  1001. ptr = (unsigned char *) &chip->image;
  1002. snd_cs4231_mce_down(chip);
  1003. spin_lock_irqsave(&chip->reg_lock, flags);
  1004. for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */
  1005. snd_cs4231_out(chip, i, *ptr++);
  1006. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1007. snd_cs4231_mce_up(chip);
  1008. snd_cs4231_mce_down(chip);
  1009. mdelay(2);
  1010. /* ok.. try check hardware version for CS4236+ chips */
  1011. if ((hw & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
  1012. if (chip->hardware == CS4231_HW_CS4236B) {
  1013. rev = snd_cs4236_ext_in(chip, CS4236_VERSION);
  1014. snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff);
  1015. id = snd_cs4236_ext_in(chip, CS4236_VERSION);
  1016. snd_cs4236_ext_out(chip, CS4236_VERSION, rev);
  1017. snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id);
  1018. if ((id & 0x1f) == 0x1d) { /* CS4235 */
  1019. chip->hardware = CS4231_HW_CS4235;
  1020. switch (id >> 5) {
  1021. case 4:
  1022. case 5:
  1023. case 6:
  1024. break;
  1025. default:
  1026. snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id);
  1027. }
  1028. } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
  1029. switch (id >> 5) {
  1030. case 4:
  1031. case 5:
  1032. case 6:
  1033. case 7:
  1034. chip->hardware = CS4231_HW_CS4236B;
  1035. break;
  1036. default:
  1037. snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id);
  1038. }
  1039. } else if ((id & 0x1f) == 0x08) { /* CS4237B */
  1040. chip->hardware = CS4231_HW_CS4237B;
  1041. switch (id >> 5) {
  1042. case 4:
  1043. case 5:
  1044. case 6:
  1045. case 7:
  1046. break;
  1047. default:
  1048. snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id);
  1049. }
  1050. } else if ((id & 0x1f) == 0x09) { /* CS4238B */
  1051. chip->hardware = CS4231_HW_CS4238B;
  1052. switch (id >> 5) {
  1053. case 5:
  1054. case 6:
  1055. case 7:
  1056. break;
  1057. default:
  1058. snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id);
  1059. }
  1060. } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
  1061. chip->hardware = CS4231_HW_CS4239;
  1062. switch (id >> 5) {
  1063. case 4:
  1064. case 5:
  1065. case 6:
  1066. break;
  1067. default:
  1068. snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id);
  1069. }
  1070. } else {
  1071. snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id);
  1072. }
  1073. }
  1074. }
  1075. return 0; /* all things are ok.. */
  1076. }
  1077. /*
  1078. */
  1079. static snd_pcm_hardware_t snd_cs4231_playback =
  1080. {
  1081. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1082. SNDRV_PCM_INFO_MMAP_VALID |
  1083. SNDRV_PCM_INFO_RESUME |
  1084. SNDRV_PCM_INFO_SYNC_START),
  1085. .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
  1086. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
  1087. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  1088. .rate_min = 5510,
  1089. .rate_max = 48000,
  1090. .channels_min = 1,
  1091. .channels_max = 2,
  1092. .buffer_bytes_max = (128*1024),
  1093. .period_bytes_min = 64,
  1094. .period_bytes_max = (128*1024),
  1095. .periods_min = 1,
  1096. .periods_max = 1024,
  1097. .fifo_size = 0,
  1098. };
  1099. static snd_pcm_hardware_t snd_cs4231_capture =
  1100. {
  1101. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1102. SNDRV_PCM_INFO_MMAP_VALID |
  1103. SNDRV_PCM_INFO_RESUME |
  1104. SNDRV_PCM_INFO_SYNC_START),
  1105. .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
  1106. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
  1107. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  1108. .rate_min = 5510,
  1109. .rate_max = 48000,
  1110. .channels_min = 1,
  1111. .channels_max = 2,
  1112. .buffer_bytes_max = (128*1024),
  1113. .period_bytes_min = 64,
  1114. .period_bytes_max = (128*1024),
  1115. .periods_min = 1,
  1116. .periods_max = 1024,
  1117. .fifo_size = 0,
  1118. };
  1119. /*
  1120. */
  1121. static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
  1122. {
  1123. cs4231_t *chip = snd_pcm_substream_chip(substream);
  1124. snd_pcm_runtime_t *runtime = substream->runtime;
  1125. int err;
  1126. runtime->hw = snd_cs4231_playback;
  1127. /* hardware bug in InterWave chipset */
  1128. if (chip->hardware == CS4231_HW_INTERWAVE && chip->dma1 > 3)
  1129. runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW;
  1130. /* hardware limitation of cheap chips */
  1131. if (chip->hardware == CS4231_HW_CS4235 ||
  1132. chip->hardware == CS4231_HW_CS4239)
  1133. runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
  1134. #ifdef LEGACY_SUPPORT
  1135. snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
  1136. snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
  1137. if (chip->claim_dma) {
  1138. if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
  1139. return err;
  1140. }
  1141. #endif
  1142. if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) {
  1143. #ifdef LEGACY_SUPPORT
  1144. if (chip->release_dma)
  1145. chip->release_dma(chip, chip->dma_private_data, chip->dma1);
  1146. #endif
  1147. snd_free_pages(runtime->dma_area, runtime->dma_bytes);
  1148. return err;
  1149. }
  1150. chip->playback_substream = substream;
  1151. #if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
  1152. chip->p_periods_sent = 0;
  1153. #endif
  1154. snd_pcm_set_sync(substream);
  1155. chip->rate_constraint(runtime);
  1156. return 0;
  1157. }
  1158. static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
  1159. {
  1160. cs4231_t *chip = snd_pcm_substream_chip(substream);
  1161. snd_pcm_runtime_t *runtime = substream->runtime;
  1162. int err;
  1163. runtime->hw = snd_cs4231_capture;
  1164. /* hardware limitation of cheap chips */
  1165. if (chip->hardware == CS4231_HW_CS4235 ||
  1166. chip->hardware == CS4231_HW_CS4239)
  1167. runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
  1168. #ifdef LEGACY_SUPPORT
  1169. snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
  1170. snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
  1171. if (chip->claim_dma) {
  1172. if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
  1173. return err;
  1174. }
  1175. #endif
  1176. if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) {
  1177. #ifdef LEGACY_SUPPORT
  1178. if (chip->release_dma)
  1179. chip->release_dma(chip, chip->dma_private_data, chip->dma2);
  1180. #endif
  1181. snd_free_pages(runtime->dma_area, runtime->dma_bytes);
  1182. return err;
  1183. }
  1184. chip->capture_substream = substream;
  1185. #if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
  1186. chip->c_periods_sent = 0;
  1187. #endif
  1188. snd_pcm_set_sync(substream);
  1189. chip->rate_constraint(runtime);
  1190. return 0;
  1191. }
  1192. static int snd_cs4231_playback_close(snd_pcm_substream_t * substream)
  1193. {
  1194. cs4231_t *chip = snd_pcm_substream_chip(substream);
  1195. chip->playback_substream = NULL;
  1196. snd_cs4231_close(chip, CS4231_MODE_PLAY);
  1197. return 0;
  1198. }
  1199. static int snd_cs4231_capture_close(snd_pcm_substream_t * substream)
  1200. {
  1201. cs4231_t *chip = snd_pcm_substream_chip(substream);
  1202. chip->capture_substream = NULL;
  1203. snd_cs4231_close(chip, CS4231_MODE_RECORD);
  1204. return 0;
  1205. }
  1206. #ifdef CONFIG_PM
  1207. /* lowlevel suspend callback for CS4231 */
  1208. static void snd_cs4231_suspend(cs4231_t *chip)
  1209. {
  1210. int reg;
  1211. unsigned long flags;
  1212. if (chip->pcm)
  1213. snd_pcm_suspend_all(chip->pcm);
  1214. spin_lock_irqsave(&chip->reg_lock, flags);
  1215. for (reg = 0; reg < 32; reg++)
  1216. chip->image[reg] = snd_cs4231_in(chip, reg);
  1217. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1218. }
  1219. /* lowlevel resume callback for CS4231 */
  1220. static void snd_cs4231_resume(cs4231_t *chip)
  1221. {
  1222. int reg;
  1223. unsigned long flags;
  1224. int timeout;
  1225. snd_cs4231_mce_up(chip);
  1226. spin_lock_irqsave(&chip->reg_lock, flags);
  1227. for (reg = 0; reg < 32; reg++) {
  1228. switch (reg) {
  1229. case CS4231_VERSION:
  1230. break;
  1231. default:
  1232. snd_cs4231_out(chip, reg, chip->image[reg]);
  1233. break;
  1234. }
  1235. }
  1236. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1237. #if 0
  1238. snd_cs4231_mce_down(chip);
  1239. #else
  1240. /* The following is a workaround to avoid freeze after resume on TP600E.
  1241. This is the first half of copy of snd_cs4231_mce_down(), but doesn't
  1242. include rescheduling. -- iwai
  1243. */
  1244. snd_cs4231_busy_wait(chip);
  1245. spin_lock_irqsave(&chip->reg_lock, flags);
  1246. chip->mce_bit &= ~CS4231_MCE;
  1247. timeout = cs4231_inb(chip, CS4231P(REGSEL));
  1248. cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
  1249. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1250. if (timeout == 0x80)
  1251. snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port);
  1252. if ((timeout & CS4231_MCE) == 0 ||
  1253. !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
  1254. return;
  1255. }
  1256. snd_cs4231_busy_wait(chip);
  1257. #endif
  1258. }
  1259. static int snd_cs4231_pm_suspend(snd_card_t *card, pm_message_t state)
  1260. {
  1261. cs4231_t *chip = card->pm_private_data;
  1262. if (chip->suspend)
  1263. chip->suspend(chip);
  1264. return 0;
  1265. }
  1266. static int snd_cs4231_pm_resume(snd_card_t *card)
  1267. {
  1268. cs4231_t *chip = card->pm_private_data;
  1269. if (chip->resume)
  1270. chip->resume(chip);
  1271. return 0;
  1272. }
  1273. #endif /* CONFIG_PM */
  1274. #ifdef LEGACY_SUPPORT
  1275. static int snd_cs4231_free(cs4231_t *chip)
  1276. {
  1277. if (chip->res_port) {
  1278. release_resource(chip->res_port);
  1279. kfree_nocheck(chip->res_port);
  1280. }
  1281. if (chip->res_cport) {
  1282. release_resource(chip->res_cport);
  1283. kfree_nocheck(chip->res_cport);
  1284. }
  1285. if (chip->irq >= 0) {
  1286. disable_irq(chip->irq);
  1287. if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
  1288. free_irq(chip->irq, (void *) chip);
  1289. }
  1290. if (!(chip->hwshare & CS4231_HWSHARE_DMA1) && chip->dma1 >= 0) {
  1291. snd_dma_disable(chip->dma1);
  1292. free_dma(chip->dma1);
  1293. }
  1294. if (!(chip->hwshare & CS4231_HWSHARE_DMA2) && chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
  1295. snd_dma_disable(chip->dma2);
  1296. free_dma(chip->dma2);
  1297. }
  1298. if (chip->timer)
  1299. snd_device_free(chip->card, chip->timer);
  1300. kfree(chip);
  1301. return 0;
  1302. }
  1303. static int snd_cs4231_dev_free(snd_device_t *device)
  1304. {
  1305. cs4231_t *chip = device->device_data;
  1306. return snd_cs4231_free(chip);
  1307. }
  1308. #endif /* LEGACY_SUPPORT */
  1309. const char *snd_cs4231_chip_id(cs4231_t *chip)
  1310. {
  1311. switch (chip->hardware) {
  1312. case CS4231_HW_CS4231: return "CS4231";
  1313. case CS4231_HW_CS4231A: return "CS4231A";
  1314. case CS4231_HW_CS4232: return "CS4232";
  1315. case CS4231_HW_CS4232A: return "CS4232A";
  1316. case CS4231_HW_CS4235: return "CS4235";
  1317. case CS4231_HW_CS4236: return "CS4236";
  1318. case CS4231_HW_CS4236B: return "CS4236B";
  1319. case CS4231_HW_CS4237B: return "CS4237B";
  1320. case CS4231_HW_CS4238B: return "CS4238B";
  1321. case CS4231_HW_CS4239: return "CS4239";
  1322. case CS4231_HW_INTERWAVE: return "AMD InterWave";
  1323. case CS4231_HW_OPL3SA2: return chip->card->shortname;
  1324. case CS4231_HW_AD1845: return "AD1845";
  1325. default: return "???";
  1326. }
  1327. }
  1328. static int snd_cs4231_new(snd_card_t * card,
  1329. unsigned short hardware,
  1330. unsigned short hwshare,
  1331. cs4231_t ** rchip)
  1332. {
  1333. cs4231_t *chip;
  1334. *rchip = NULL;
  1335. chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
  1336. if (chip == NULL)
  1337. return -ENOMEM;
  1338. chip->hardware = hardware;
  1339. chip->hwshare = hwshare;
  1340. spin_lock_init(&chip->reg_lock);
  1341. init_MUTEX(&chip->mce_mutex);
  1342. init_MUTEX(&chip->open_mutex);
  1343. chip->card = card;
  1344. chip->rate_constraint = snd_cs4231_xrate;
  1345. chip->set_playback_format = snd_cs4231_playback_format;
  1346. chip->set_capture_format = snd_cs4231_capture_format;
  1347. memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
  1348. *rchip = chip;
  1349. return 0;
  1350. }
  1351. #ifdef LEGACY_SUPPORT
  1352. int snd_cs4231_create(snd_card_t * card,
  1353. unsigned long port,
  1354. unsigned long cport,
  1355. int irq, int dma1, int dma2,
  1356. unsigned short hardware,
  1357. unsigned short hwshare,
  1358. cs4231_t ** rchip)
  1359. {
  1360. static snd_device_ops_t ops = {
  1361. .dev_free = snd_cs4231_dev_free,
  1362. };
  1363. cs4231_t *chip;
  1364. int err;
  1365. err = snd_cs4231_new(card, hardware, hwshare, &chip);
  1366. if (err < 0)
  1367. return err;
  1368. chip->irq = -1;
  1369. chip->dma1 = -1;
  1370. chip->dma2 = -1;
  1371. if ((chip->res_port = request_region(port, 4, "CS4231")) == NULL) {
  1372. snd_printk(KERN_ERR "cs4231: can't grab port 0x%lx\n", port);
  1373. snd_cs4231_free(chip);
  1374. return -EBUSY;
  1375. }
  1376. chip->port = port;
  1377. if ((long)cport >= 0 && (chip->res_cport = request_region(cport, 8, "CS4232 Control")) == NULL) {
  1378. snd_printk(KERN_ERR "cs4231: can't grab control port 0x%lx\n", cport);
  1379. snd_cs4231_free(chip);
  1380. return -ENODEV;
  1381. }
  1382. chip->cport = cport;
  1383. if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, SA_INTERRUPT, "CS4231", (void *) chip)) {
  1384. snd_printk(KERN_ERR "cs4231: can't grab IRQ %d\n", irq);
  1385. snd_cs4231_free(chip);
  1386. return -EBUSY;
  1387. }
  1388. chip->irq = irq;
  1389. if (!(hwshare & CS4231_HWSHARE_DMA1) && request_dma(dma1, "CS4231 - 1")) {
  1390. snd_printk(KERN_ERR "cs4231: can't grab DMA1 %d\n", dma1);
  1391. snd_cs4231_free(chip);
  1392. return -EBUSY;
  1393. }
  1394. chip->dma1 = dma1;
  1395. if (!(hwshare & CS4231_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 && request_dma(dma2, "CS4231 - 2")) {
  1396. snd_printk(KERN_ERR "cs4231: can't grab DMA2 %d\n", dma2);
  1397. snd_cs4231_free(chip);
  1398. return -EBUSY;
  1399. }
  1400. if (dma1 == dma2 || dma2 < 0) {
  1401. chip->single_dma = 1;
  1402. chip->dma2 = chip->dma1;
  1403. } else
  1404. chip->dma2 = dma2;
  1405. /* global setup */
  1406. if (snd_cs4231_probe(chip) < 0) {
  1407. snd_cs4231_free(chip);
  1408. return -ENODEV;
  1409. }
  1410. snd_cs4231_init(chip);
  1411. if (chip->hardware & CS4231_HW_CS4232_MASK) {
  1412. if (chip->res_cport == NULL)
  1413. snd_printk("CS4232 control port features are not accessible\n");
  1414. }
  1415. /* Register device */
  1416. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  1417. snd_cs4231_free(chip);
  1418. return err;
  1419. }
  1420. #ifdef CONFIG_PM
  1421. /* Power Management */
  1422. chip->suspend = snd_cs4231_suspend;
  1423. chip->resume = snd_cs4231_resume;
  1424. snd_card_set_isa_pm_callback(card, snd_cs4231_pm_suspend, snd_cs4231_pm_resume, chip);
  1425. #endif
  1426. *rchip = chip;
  1427. return 0;
  1428. }
  1429. #endif /* LEGACY_SUPPORT */
  1430. static snd_pcm_ops_t snd_cs4231_playback_ops = {
  1431. .open = snd_cs4231_playback_open,
  1432. .close = snd_cs4231_playback_close,
  1433. .ioctl = snd_pcm_lib_ioctl,
  1434. .hw_params = snd_cs4231_playback_hw_params,
  1435. .hw_free = snd_cs4231_playback_hw_free,
  1436. .prepare = snd_cs4231_playback_prepare,
  1437. .trigger = snd_cs4231_trigger,
  1438. .pointer = snd_cs4231_playback_pointer,
  1439. };
  1440. static snd_pcm_ops_t snd_cs4231_capture_ops = {
  1441. .open = snd_cs4231_capture_open,
  1442. .close = snd_cs4231_capture_close,
  1443. .ioctl = snd_pcm_lib_ioctl,
  1444. .hw_params = snd_cs4231_capture_hw_params,
  1445. .hw_free = snd_cs4231_capture_hw_free,
  1446. .prepare = snd_cs4231_capture_prepare,
  1447. .trigger = snd_cs4231_trigger,
  1448. .pointer = snd_cs4231_capture_pointer,
  1449. };
  1450. static void snd_cs4231_pcm_free(snd_pcm_t *pcm)
  1451. {
  1452. cs4231_t *chip = pcm->private_data;
  1453. chip->pcm = NULL;
  1454. snd_pcm_lib_preallocate_free_for_all(pcm);
  1455. }
  1456. int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
  1457. {
  1458. snd_pcm_t *pcm;
  1459. int err;
  1460. if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
  1461. return err;
  1462. spin_lock_init(&chip->reg_lock);
  1463. init_MUTEX(&chip->mce_mutex);
  1464. init_MUTEX(&chip->open_mutex);
  1465. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops);
  1466. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops);
  1467. /* global setup */
  1468. pcm->private_data = chip;
  1469. pcm->private_free = snd_cs4231_pcm_free;
  1470. pcm->info_flags = 0;
  1471. if (chip->single_dma)
  1472. pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
  1473. if (chip->hardware != CS4231_HW_INTERWAVE)
  1474. pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
  1475. strcpy(pcm->name, snd_cs4231_chip_id(chip));
  1476. #ifdef LEGACY_SUPPORT
  1477. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1478. snd_dma_isa_data(),
  1479. 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
  1480. #else
  1481. # ifdef EBUS_SUPPORT
  1482. if (chip->ebus_flag) {
  1483. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1484. chip->dev_u.pdev,
  1485. 64*1024, 128*1024);
  1486. } else {
  1487. # endif
  1488. # ifdef SBUS_SUPPORT
  1489. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
  1490. chip->dev_u.sdev,
  1491. 64*1024, 128*1024);
  1492. # endif
  1493. # ifdef EBUS_SUPPORT
  1494. }
  1495. # endif
  1496. #endif
  1497. chip->pcm = pcm;
  1498. if (rpcm)
  1499. *rpcm = pcm;
  1500. return 0;
  1501. }
  1502. static void snd_cs4231_timer_free(snd_timer_t *timer)
  1503. {
  1504. cs4231_t *chip = timer->private_data;
  1505. chip->timer = NULL;
  1506. }
  1507. int snd_cs4231_timer(cs4231_t *chip, int device, snd_timer_t **rtimer)
  1508. {
  1509. snd_timer_t *timer;
  1510. snd_timer_id_t tid;
  1511. int err;
  1512. /* Timer initialization */
  1513. tid.dev_class = SNDRV_TIMER_CLASS_CARD;
  1514. tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
  1515. tid.card = chip->card->number;
  1516. tid.device = device;
  1517. tid.subdevice = 0;
  1518. if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0)
  1519. return err;
  1520. strcpy(timer->name, snd_cs4231_chip_id(chip));
  1521. timer->private_data = chip;
  1522. timer->private_free = snd_cs4231_timer_free;
  1523. timer->hw = snd_cs4231_timer_table;
  1524. chip->timer = timer;
  1525. if (rtimer)
  1526. *rtimer = timer;
  1527. return 0;
  1528. }
  1529. /*
  1530. * MIXER part
  1531. */
  1532. static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1533. {
  1534. static char *texts[4] = {
  1535. "Line", "Aux", "Mic", "Mix"
  1536. };
  1537. static char *opl3sa_texts[4] = {
  1538. "Line", "CD", "Mic", "Mix"
  1539. };
  1540. static char *gusmax_texts[4] = {
  1541. "Line", "Synth", "Mic", "Mix"
  1542. };
  1543. char **ptexts = texts;
  1544. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1545. snd_assert(chip->card != NULL, return -EINVAL);
  1546. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1547. uinfo->count = 2;
  1548. uinfo->value.enumerated.items = 4;
  1549. if (uinfo->value.enumerated.item > 3)
  1550. uinfo->value.enumerated.item = 3;
  1551. if (!strcmp(chip->card->driver, "GUS MAX"))
  1552. ptexts = gusmax_texts;
  1553. switch (chip->hardware) {
  1554. case CS4231_HW_INTERWAVE: ptexts = gusmax_texts; break;
  1555. case CS4231_HW_OPL3SA2: ptexts = opl3sa_texts; break;
  1556. }
  1557. strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]);
  1558. return 0;
  1559. }
  1560. static int snd_cs4231_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1561. {
  1562. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1563. unsigned long flags;
  1564. spin_lock_irqsave(&chip->reg_lock, flags);
  1565. ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6;
  1566. ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6;
  1567. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1568. return 0;
  1569. }
  1570. static int snd_cs4231_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1571. {
  1572. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1573. unsigned long flags;
  1574. unsigned short left, right;
  1575. int change;
  1576. if (ucontrol->value.enumerated.item[0] > 3 ||
  1577. ucontrol->value.enumerated.item[1] > 3)
  1578. return -EINVAL;
  1579. left = ucontrol->value.enumerated.item[0] << 6;
  1580. right = ucontrol->value.enumerated.item[1] << 6;
  1581. spin_lock_irqsave(&chip->reg_lock, flags);
  1582. left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left;
  1583. right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right;
  1584. change = left != chip->image[CS4231_LEFT_INPUT] ||
  1585. right != chip->image[CS4231_RIGHT_INPUT];
  1586. snd_cs4231_out(chip, CS4231_LEFT_INPUT, left);
  1587. snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right);
  1588. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1589. return change;
  1590. }
  1591. int snd_cs4231_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1592. {
  1593. int mask = (kcontrol->private_value >> 16) & 0xff;
  1594. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  1595. uinfo->count = 1;
  1596. uinfo->value.integer.min = 0;
  1597. uinfo->value.integer.max = mask;
  1598. return 0;
  1599. }
  1600. int snd_cs4231_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1601. {
  1602. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1603. unsigned long flags;
  1604. int reg = kcontrol->private_value & 0xff;
  1605. int shift = (kcontrol->private_value >> 8) & 0xff;
  1606. int mask = (kcontrol->private_value >> 16) & 0xff;
  1607. int invert = (kcontrol->private_value >> 24) & 0xff;
  1608. spin_lock_irqsave(&chip->reg_lock, flags);
  1609. ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
  1610. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1611. if (invert)
  1612. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  1613. return 0;
  1614. }
  1615. int snd_cs4231_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1616. {
  1617. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1618. unsigned long flags;
  1619. int reg = kcontrol->private_value & 0xff;
  1620. int shift = (kcontrol->private_value >> 8) & 0xff;
  1621. int mask = (kcontrol->private_value >> 16) & 0xff;
  1622. int invert = (kcontrol->private_value >> 24) & 0xff;
  1623. int change;
  1624. unsigned short val;
  1625. val = (ucontrol->value.integer.value[0] & mask);
  1626. if (invert)
  1627. val = mask - val;
  1628. val <<= shift;
  1629. spin_lock_irqsave(&chip->reg_lock, flags);
  1630. val = (chip->image[reg] & ~(mask << shift)) | val;
  1631. change = val != chip->image[reg];
  1632. snd_cs4231_out(chip, reg, val);
  1633. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1634. return change;
  1635. }
  1636. int snd_cs4231_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  1637. {
  1638. int mask = (kcontrol->private_value >> 24) & 0xff;
  1639. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  1640. uinfo->count = 2;
  1641. uinfo->value.integer.min = 0;
  1642. uinfo->value.integer.max = mask;
  1643. return 0;
  1644. }
  1645. int snd_cs4231_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1646. {
  1647. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1648. unsigned long flags;
  1649. int left_reg = kcontrol->private_value & 0xff;
  1650. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  1651. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  1652. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  1653. int mask = (kcontrol->private_value >> 24) & 0xff;
  1654. int invert = (kcontrol->private_value >> 22) & 1;
  1655. spin_lock_irqsave(&chip->reg_lock, flags);
  1656. ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
  1657. ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
  1658. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1659. if (invert) {
  1660. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  1661. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  1662. }
  1663. return 0;
  1664. }
  1665. int snd_cs4231_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
  1666. {
  1667. cs4231_t *chip = snd_kcontrol_chip(kcontrol);
  1668. unsigned long flags;
  1669. int left_reg = kcontrol->private_value & 0xff;
  1670. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  1671. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  1672. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  1673. int mask = (kcontrol->private_value >> 24) & 0xff;
  1674. int invert = (kcontrol->private_value >> 22) & 1;
  1675. int change;
  1676. unsigned short val1, val2;
  1677. val1 = ucontrol->value.integer.value[0] & mask;
  1678. val2 = ucontrol->value.integer.value[1] & mask;
  1679. if (invert) {
  1680. val1 = mask - val1;
  1681. val2 = mask - val2;
  1682. }
  1683. val1 <<= shift_left;
  1684. val2 <<= shift_right;
  1685. spin_lock_irqsave(&chip->reg_lock, flags);
  1686. val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
  1687. val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
  1688. change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
  1689. snd_cs4231_out(chip, left_reg, val1);
  1690. snd_cs4231_out(chip, right_reg, val2);
  1691. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1692. return change;
  1693. }
  1694. static snd_kcontrol_new_t snd_cs4231_controls[] = {
  1695. CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
  1696. CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
  1697. CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  1698. CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
  1699. CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
  1700. CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
  1701. CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
  1702. CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
  1703. CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1),
  1704. CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
  1705. CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1),
  1706. CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
  1707. CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
  1708. {
  1709. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1710. .name = "Capture Source",
  1711. .info = snd_cs4231_info_mux,
  1712. .get = snd_cs4231_get_mux,
  1713. .put = snd_cs4231_put_mux,
  1714. },
  1715. CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
  1716. CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
  1717. CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
  1718. };
  1719. int snd_cs4231_mixer(cs4231_t *chip)
  1720. {
  1721. snd_card_t *card;
  1722. unsigned int idx;
  1723. int err;
  1724. snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
  1725. card = chip->card;
  1726. strcpy(card->mixername, chip->pcm->name);
  1727. for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
  1728. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
  1729. return err;
  1730. }
  1731. return 0;
  1732. }
  1733. EXPORT_SYMBOL(snd_cs4231_out);
  1734. EXPORT_SYMBOL(snd_cs4231_in);
  1735. EXPORT_SYMBOL(snd_cs4236_ext_out);
  1736. EXPORT_SYMBOL(snd_cs4236_ext_in);
  1737. EXPORT_SYMBOL(snd_cs4231_mce_up);
  1738. EXPORT_SYMBOL(snd_cs4231_mce_down);
  1739. EXPORT_SYMBOL(snd_cs4231_interrupt);
  1740. EXPORT_SYMBOL(snd_cs4231_chip_id);
  1741. EXPORT_SYMBOL(snd_cs4231_create);
  1742. EXPORT_SYMBOL(snd_cs4231_pcm);
  1743. EXPORT_SYMBOL(snd_cs4231_mixer);
  1744. EXPORT_SYMBOL(snd_cs4231_timer);
  1745. EXPORT_SYMBOL(snd_cs4231_info_single);
  1746. EXPORT_SYMBOL(snd_cs4231_get_single);
  1747. EXPORT_SYMBOL(snd_cs4231_put_single);
  1748. EXPORT_SYMBOL(snd_cs4231_info_double);
  1749. EXPORT_SYMBOL(snd_cs4231_get_double);
  1750. EXPORT_SYMBOL(snd_cs4231_put_double);
  1751. /*
  1752. * INIT part
  1753. */
  1754. static int __init alsa_cs4231_init(void)
  1755. {
  1756. return 0;
  1757. }
  1758. static void __exit alsa_cs4231_exit(void)
  1759. {
  1760. }
  1761. module_init(alsa_cs4231_init)
  1762. module_exit(alsa_cs4231_exit)