ad1843.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * AD1843 low level driver
  3. *
  4. * Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
  5. * Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  6. *
  7. * inspired from vwsnd.c (SGI VW audio driver)
  8. * Copyright 1999 Silicon Graphics, Inc. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include <linux/init.h>
  26. #include <linux/sched.h>
  27. #include <linux/errno.h>
  28. #include <sound/core.h>
  29. #include <sound/pcm.h>
  30. #include <sound/ad1843.h>
  31. /*
  32. * AD1843 bitfield definitions. All are named as in the AD1843 data
  33. * sheet, with ad1843_ prepended and individual bit numbers removed.
  34. *
  35. * E.g., bits LSS0 through LSS2 become ad1843_LSS.
  36. *
  37. * Only the bitfields we need are defined.
  38. */
  39. struct ad1843_bitfield {
  40. char reg;
  41. char lo_bit;
  42. char nbits;
  43. };
  44. static const struct ad1843_bitfield
  45. ad1843_PDNO = { 0, 14, 1 }, /* Converter Power-Down Flag */
  46. ad1843_INIT = { 0, 15, 1 }, /* Clock Initialization Flag */
  47. ad1843_RIG = { 2, 0, 4 }, /* Right ADC Input Gain */
  48. ad1843_RMGE = { 2, 4, 1 }, /* Right ADC Mic Gain Enable */
  49. ad1843_RSS = { 2, 5, 3 }, /* Right ADC Source Select */
  50. ad1843_LIG = { 2, 8, 4 }, /* Left ADC Input Gain */
  51. ad1843_LMGE = { 2, 12, 1 }, /* Left ADC Mic Gain Enable */
  52. ad1843_LSS = { 2, 13, 3 }, /* Left ADC Source Select */
  53. ad1843_RD2M = { 3, 0, 5 }, /* Right DAC 2 Mix Gain/Atten */
  54. ad1843_RD2MM = { 3, 7, 1 }, /* Right DAC 2 Mix Mute */
  55. ad1843_LD2M = { 3, 8, 5 }, /* Left DAC 2 Mix Gain/Atten */
  56. ad1843_LD2MM = { 3, 15, 1 }, /* Left DAC 2 Mix Mute */
  57. ad1843_RX1M = { 4, 0, 5 }, /* Right Aux 1 Mix Gain/Atten */
  58. ad1843_RX1MM = { 4, 7, 1 }, /* Right Aux 1 Mix Mute */
  59. ad1843_LX1M = { 4, 8, 5 }, /* Left Aux 1 Mix Gain/Atten */
  60. ad1843_LX1MM = { 4, 15, 1 }, /* Left Aux 1 Mix Mute */
  61. ad1843_RX2M = { 5, 0, 5 }, /* Right Aux 2 Mix Gain/Atten */
  62. ad1843_RX2MM = { 5, 7, 1 }, /* Right Aux 2 Mix Mute */
  63. ad1843_LX2M = { 5, 8, 5 }, /* Left Aux 2 Mix Gain/Atten */
  64. ad1843_LX2MM = { 5, 15, 1 }, /* Left Aux 2 Mix Mute */
  65. ad1843_RMCM = { 7, 0, 5 }, /* Right Mic Mix Gain/Atten */
  66. ad1843_RMCMM = { 7, 7, 1 }, /* Right Mic Mix Mute */
  67. ad1843_LMCM = { 7, 8, 5 }, /* Left Mic Mix Gain/Atten */
  68. ad1843_LMCMM = { 7, 15, 1 }, /* Left Mic Mix Mute */
  69. ad1843_HPOS = { 8, 4, 1 }, /* Headphone Output Voltage Swing */
  70. ad1843_HPOM = { 8, 5, 1 }, /* Headphone Output Mute */
  71. ad1843_MPOM = { 8, 6, 1 }, /* Mono Output Mute */
  72. ad1843_RDA1G = { 9, 0, 6 }, /* Right DAC1 Analog/Digital Gain */
  73. ad1843_RDA1GM = { 9, 7, 1 }, /* Right DAC1 Analog Mute */
  74. ad1843_LDA1G = { 9, 8, 6 }, /* Left DAC1 Analog/Digital Gain */
  75. ad1843_LDA1GM = { 9, 15, 1 }, /* Left DAC1 Analog Mute */
  76. ad1843_RDA2G = { 10, 0, 6 }, /* Right DAC2 Analog/Digital Gain */
  77. ad1843_RDA2GM = { 10, 7, 1 }, /* Right DAC2 Analog Mute */
  78. ad1843_LDA2G = { 10, 8, 6 }, /* Left DAC2 Analog/Digital Gain */
  79. ad1843_LDA2GM = { 10, 15, 1 }, /* Left DAC2 Analog Mute */
  80. ad1843_RDA1AM = { 11, 7, 1 }, /* Right DAC1 Digital Mute */
  81. ad1843_LDA1AM = { 11, 15, 1 }, /* Left DAC1 Digital Mute */
  82. ad1843_RDA2AM = { 12, 7, 1 }, /* Right DAC2 Digital Mute */
  83. ad1843_LDA2AM = { 12, 15, 1 }, /* Left DAC2 Digital Mute */
  84. ad1843_ADLC = { 15, 0, 2 }, /* ADC Left Sample Rate Source */
  85. ad1843_ADRC = { 15, 2, 2 }, /* ADC Right Sample Rate Source */
  86. ad1843_DA1C = { 15, 8, 2 }, /* DAC1 Sample Rate Source */
  87. ad1843_DA2C = { 15, 10, 2 }, /* DAC2 Sample Rate Source */
  88. ad1843_C1C = { 17, 0, 16 }, /* Clock 1 Sample Rate Select */
  89. ad1843_C2C = { 20, 0, 16 }, /* Clock 2 Sample Rate Select */
  90. ad1843_C3C = { 23, 0, 16 }, /* Clock 3 Sample Rate Select */
  91. ad1843_DAADL = { 25, 4, 2 }, /* Digital ADC Left Source Select */
  92. ad1843_DAADR = { 25, 6, 2 }, /* Digital ADC Right Source Select */
  93. ad1843_DAMIX = { 25, 14, 1 }, /* DAC Digital Mix Enable */
  94. ad1843_DRSFLT = { 25, 15, 1 }, /* Digital Reampler Filter Mode */
  95. ad1843_ADLF = { 26, 0, 2 }, /* ADC Left Channel Data Format */
  96. ad1843_ADRF = { 26, 2, 2 }, /* ADC Right Channel Data Format */
  97. ad1843_ADTLK = { 26, 4, 1 }, /* ADC Transmit Lock Mode Select */
  98. ad1843_SCF = { 26, 7, 1 }, /* SCLK Frequency Select */
  99. ad1843_DA1F = { 26, 8, 2 }, /* DAC1 Data Format Select */
  100. ad1843_DA2F = { 26, 10, 2 }, /* DAC2 Data Format Select */
  101. ad1843_DA1SM = { 26, 14, 1 }, /* DAC1 Stereo/Mono Mode Select */
  102. ad1843_DA2SM = { 26, 15, 1 }, /* DAC2 Stereo/Mono Mode Select */
  103. ad1843_ADLEN = { 27, 0, 1 }, /* ADC Left Channel Enable */
  104. ad1843_ADREN = { 27, 1, 1 }, /* ADC Right Channel Enable */
  105. ad1843_AAMEN = { 27, 4, 1 }, /* Analog to Analog Mix Enable */
  106. ad1843_ANAEN = { 27, 7, 1 }, /* Analog Channel Enable */
  107. ad1843_DA1EN = { 27, 8, 1 }, /* DAC1 Enable */
  108. ad1843_DA2EN = { 27, 9, 1 }, /* DAC2 Enable */
  109. ad1843_DDMEN = { 27, 12, 1 }, /* DAC2 to DAC1 Mix Enable */
  110. ad1843_C1EN = { 28, 11, 1 }, /* Clock Generator 1 Enable */
  111. ad1843_C2EN = { 28, 12, 1 }, /* Clock Generator 2 Enable */
  112. ad1843_C3EN = { 28, 13, 1 }, /* Clock Generator 3 Enable */
  113. ad1843_PDNI = { 28, 15, 1 }; /* Converter Power Down */
  114. /*
  115. * The various registers of the AD1843 use three different formats for
  116. * specifying gain. The ad1843_gain structure parameterizes the
  117. * formats.
  118. */
  119. struct ad1843_gain {
  120. int negative; /* nonzero if gain is negative. */
  121. const struct ad1843_bitfield *lfield;
  122. const struct ad1843_bitfield *rfield;
  123. const struct ad1843_bitfield *lmute;
  124. const struct ad1843_bitfield *rmute;
  125. };
  126. static const struct ad1843_gain ad1843_gain_RECLEV = {
  127. .negative = 0,
  128. .lfield = &ad1843_LIG,
  129. .rfield = &ad1843_RIG
  130. };
  131. static const struct ad1843_gain ad1843_gain_LINE = {
  132. .negative = 1,
  133. .lfield = &ad1843_LX1M,
  134. .rfield = &ad1843_RX1M,
  135. .lmute = &ad1843_LX1MM,
  136. .rmute = &ad1843_RX1MM
  137. };
  138. static const struct ad1843_gain ad1843_gain_LINE_2 = {
  139. .negative = 1,
  140. .lfield = &ad1843_LDA2G,
  141. .rfield = &ad1843_RDA2G,
  142. .lmute = &ad1843_LDA2GM,
  143. .rmute = &ad1843_RDA2GM
  144. };
  145. static const struct ad1843_gain ad1843_gain_MIC = {
  146. .negative = 1,
  147. .lfield = &ad1843_LMCM,
  148. .rfield = &ad1843_RMCM,
  149. .lmute = &ad1843_LMCMM,
  150. .rmute = &ad1843_RMCMM
  151. };
  152. static const struct ad1843_gain ad1843_gain_PCM_0 = {
  153. .negative = 1,
  154. .lfield = &ad1843_LDA1G,
  155. .rfield = &ad1843_RDA1G,
  156. .lmute = &ad1843_LDA1GM,
  157. .rmute = &ad1843_RDA1GM
  158. };
  159. static const struct ad1843_gain ad1843_gain_PCM_1 = {
  160. .negative = 1,
  161. .lfield = &ad1843_LD2M,
  162. .rfield = &ad1843_RD2M,
  163. .lmute = &ad1843_LD2MM,
  164. .rmute = &ad1843_RD2MM
  165. };
  166. static const struct ad1843_gain *ad1843_gain[AD1843_GAIN_SIZE] =
  167. {
  168. &ad1843_gain_RECLEV,
  169. &ad1843_gain_LINE,
  170. &ad1843_gain_LINE_2,
  171. &ad1843_gain_MIC,
  172. &ad1843_gain_PCM_0,
  173. &ad1843_gain_PCM_1,
  174. };
  175. /* read the current value of an AD1843 bitfield. */
  176. static int ad1843_read_bits(struct snd_ad1843 *ad1843,
  177. const struct ad1843_bitfield *field)
  178. {
  179. int w;
  180. w = ad1843->read(ad1843->chip, field->reg);
  181. return w >> field->lo_bit & ((1 << field->nbits) - 1);
  182. }
  183. /*
  184. * write a new value to an AD1843 bitfield and return the old value.
  185. */
  186. static int ad1843_write_bits(struct snd_ad1843 *ad1843,
  187. const struct ad1843_bitfield *field,
  188. int newval)
  189. {
  190. int w, mask, oldval, newbits;
  191. w = ad1843->read(ad1843->chip, field->reg);
  192. mask = ((1 << field->nbits) - 1) << field->lo_bit;
  193. oldval = (w & mask) >> field->lo_bit;
  194. newbits = (newval << field->lo_bit) & mask;
  195. w = (w & ~mask) | newbits;
  196. ad1843->write(ad1843->chip, field->reg, w);
  197. return oldval;
  198. }
  199. /*
  200. * ad1843_read_multi reads multiple bitfields from the same AD1843
  201. * register. It uses a single read cycle to do it. (Reading the
  202. * ad1843 requires 256 bit times at 12.288 MHz, or nearly 20
  203. * microseconds.)
  204. *
  205. * Called like this.
  206. *
  207. * ad1843_read_multi(ad1843, nfields,
  208. * &ad1843_FIELD1, &val1,
  209. * &ad1843_FIELD2, &val2, ...);
  210. */
  211. static void ad1843_read_multi(struct snd_ad1843 *ad1843, int argcount, ...)
  212. {
  213. va_list ap;
  214. const struct ad1843_bitfield *fp;
  215. int w = 0, mask, *value, reg = -1;
  216. va_start(ap, argcount);
  217. while (--argcount >= 0) {
  218. fp = va_arg(ap, const struct ad1843_bitfield *);
  219. value = va_arg(ap, int *);
  220. if (reg == -1) {
  221. reg = fp->reg;
  222. w = ad1843->read(ad1843->chip, reg);
  223. }
  224. mask = (1 << fp->nbits) - 1;
  225. *value = w >> fp->lo_bit & mask;
  226. }
  227. va_end(ap);
  228. }
  229. /*
  230. * ad1843_write_multi stores multiple bitfields into the same AD1843
  231. * register. It uses one read and one write cycle to do it.
  232. *
  233. * Called like this.
  234. *
  235. * ad1843_write_multi(ad1843, nfields,
  236. * &ad1843_FIELD1, val1,
  237. * &ad1843_FIELF2, val2, ...);
  238. */
  239. static void ad1843_write_multi(struct snd_ad1843 *ad1843, int argcount, ...)
  240. {
  241. va_list ap;
  242. int reg;
  243. const struct ad1843_bitfield *fp;
  244. int value;
  245. int w, m, mask, bits;
  246. mask = 0;
  247. bits = 0;
  248. reg = -1;
  249. va_start(ap, argcount);
  250. while (--argcount >= 0) {
  251. fp = va_arg(ap, const struct ad1843_bitfield *);
  252. value = va_arg(ap, int);
  253. if (reg == -1)
  254. reg = fp->reg;
  255. else
  256. WARN_ON(reg != fp->reg);
  257. m = ((1 << fp->nbits) - 1) << fp->lo_bit;
  258. mask |= m;
  259. bits |= (value << fp->lo_bit) & m;
  260. }
  261. va_end(ap);
  262. if (~mask & 0xFFFF)
  263. w = ad1843->read(ad1843->chip, reg);
  264. else
  265. w = 0;
  266. w = (w & ~mask) | bits;
  267. ad1843->write(ad1843->chip, reg, w);
  268. }
  269. int ad1843_get_gain_max(struct snd_ad1843 *ad1843, int id)
  270. {
  271. const struct ad1843_gain *gp = ad1843_gain[id];
  272. int ret;
  273. ret = (1 << gp->lfield->nbits);
  274. if (!gp->lmute)
  275. ret -= 1;
  276. return ret;
  277. }
  278. /*
  279. * ad1843_get_gain reads the specified register and extracts the gain value
  280. * using the supplied gain type.
  281. */
  282. int ad1843_get_gain(struct snd_ad1843 *ad1843, int id)
  283. {
  284. int lg, rg, lm, rm;
  285. const struct ad1843_gain *gp = ad1843_gain[id];
  286. unsigned short mask = (1 << gp->lfield->nbits) - 1;
  287. ad1843_read_multi(ad1843, 2, gp->lfield, &lg, gp->rfield, &rg);
  288. if (gp->negative) {
  289. lg = mask - lg;
  290. rg = mask - rg;
  291. }
  292. if (gp->lmute) {
  293. ad1843_read_multi(ad1843, 2, gp->lmute, &lm, gp->rmute, &rm);
  294. if (lm)
  295. lg = 0;
  296. if (rm)
  297. rg = 0;
  298. }
  299. return lg << 0 | rg << 8;
  300. }
  301. /*
  302. * Set an audio channel's gain.
  303. *
  304. * Returns the new gain, which may be lower than the old gain.
  305. */
  306. int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval)
  307. {
  308. const struct ad1843_gain *gp = ad1843_gain[id];
  309. unsigned short mask = (1 << gp->lfield->nbits) - 1;
  310. int lg = (newval >> 0) & mask;
  311. int rg = (newval >> 8) & mask;
  312. int lm = (lg == 0) ? 1 : 0;
  313. int rm = (rg == 0) ? 1 : 0;
  314. if (gp->negative) {
  315. lg = mask - lg;
  316. rg = mask - rg;
  317. }
  318. if (gp->lmute)
  319. ad1843_write_multi(ad1843, 2, gp->lmute, lm, gp->rmute, rm);
  320. ad1843_write_multi(ad1843, 2, gp->lfield, lg, gp->rfield, rg);
  321. return ad1843_get_gain(ad1843, id);
  322. }
  323. /* Returns the current recording source */
  324. int ad1843_get_recsrc(struct snd_ad1843 *ad1843)
  325. {
  326. int val = ad1843_read_bits(ad1843, &ad1843_LSS);
  327. if (val < 0 || val > 2) {
  328. val = 2;
  329. ad1843_write_multi(ad1843, 2,
  330. &ad1843_LSS, val, &ad1843_RSS, val);
  331. }
  332. return val;
  333. }
  334. /*
  335. * Set recording source.
  336. *
  337. * Returns newsrc on success, -errno on failure.
  338. */
  339. int ad1843_set_recsrc(struct snd_ad1843 *ad1843, int newsrc)
  340. {
  341. if (newsrc < 0 || newsrc > 2)
  342. return -EINVAL;
  343. ad1843_write_multi(ad1843, 2, &ad1843_LSS, newsrc, &ad1843_RSS, newsrc);
  344. return newsrc;
  345. }
  346. /* Setup ad1843 for D/A conversion. */
  347. void ad1843_setup_dac(struct snd_ad1843 *ad1843,
  348. unsigned int id,
  349. unsigned int framerate,
  350. snd_pcm_format_t fmt,
  351. unsigned int channels)
  352. {
  353. int ad_fmt = 0, ad_mode = 0;
  354. switch (fmt) {
  355. case SNDRV_PCM_FORMAT_S8:
  356. ad_fmt = 0;
  357. break;
  358. case SNDRV_PCM_FORMAT_U8:
  359. ad_fmt = 0;
  360. break;
  361. case SNDRV_PCM_FORMAT_S16_LE:
  362. ad_fmt = 1;
  363. break;
  364. case SNDRV_PCM_FORMAT_MU_LAW:
  365. ad_fmt = 2;
  366. break;
  367. case SNDRV_PCM_FORMAT_A_LAW:
  368. ad_fmt = 3;
  369. break;
  370. default:
  371. break;
  372. }
  373. switch (channels) {
  374. case 2:
  375. ad_mode = 0;
  376. break;
  377. case 1:
  378. ad_mode = 1;
  379. break;
  380. default:
  381. break;
  382. }
  383. if (id) {
  384. ad1843_write_bits(ad1843, &ad1843_C2C, framerate);
  385. ad1843_write_multi(ad1843, 2,
  386. &ad1843_DA2SM, ad_mode,
  387. &ad1843_DA2F, ad_fmt);
  388. } else {
  389. ad1843_write_bits(ad1843, &ad1843_C1C, framerate);
  390. ad1843_write_multi(ad1843, 2,
  391. &ad1843_DA1SM, ad_mode,
  392. &ad1843_DA1F, ad_fmt);
  393. }
  394. }
  395. void ad1843_shutdown_dac(struct snd_ad1843 *ad1843, unsigned int id)
  396. {
  397. if (id)
  398. ad1843_write_bits(ad1843, &ad1843_DA2F, 1);
  399. else
  400. ad1843_write_bits(ad1843, &ad1843_DA1F, 1);
  401. }
  402. void ad1843_setup_adc(struct snd_ad1843 *ad1843,
  403. unsigned int framerate,
  404. snd_pcm_format_t fmt,
  405. unsigned int channels)
  406. {
  407. int da_fmt = 0;
  408. switch (fmt) {
  409. case SNDRV_PCM_FORMAT_S8: da_fmt = 0; break;
  410. case SNDRV_PCM_FORMAT_U8: da_fmt = 0; break;
  411. case SNDRV_PCM_FORMAT_S16_LE: da_fmt = 1; break;
  412. case SNDRV_PCM_FORMAT_MU_LAW: da_fmt = 2; break;
  413. case SNDRV_PCM_FORMAT_A_LAW: da_fmt = 3; break;
  414. default: break;
  415. }
  416. ad1843_write_bits(ad1843, &ad1843_C3C, framerate);
  417. ad1843_write_multi(ad1843, 2,
  418. &ad1843_ADLF, da_fmt, &ad1843_ADRF, da_fmt);
  419. }
  420. void ad1843_shutdown_adc(struct snd_ad1843 *ad1843)
  421. {
  422. /* nothing to do */
  423. }
  424. /*
  425. * Fully initialize the ad1843. As described in the AD1843 data
  426. * sheet, section "START-UP SEQUENCE". The numbered comments are
  427. * subsection headings from the data sheet. See the data sheet, pages
  428. * 52-54, for more info.
  429. *
  430. * return 0 on success, -errno on failure. */
  431. int ad1843_init(struct snd_ad1843 *ad1843)
  432. {
  433. unsigned long later;
  434. if (ad1843_read_bits(ad1843, &ad1843_INIT) != 0) {
  435. printk(KERN_ERR "ad1843: AD1843 won't initialize\n");
  436. return -EIO;
  437. }
  438. ad1843_write_bits(ad1843, &ad1843_SCF, 1);
  439. /* 4. Put the conversion resources into standby. */
  440. ad1843_write_bits(ad1843, &ad1843_PDNI, 0);
  441. later = jiffies + msecs_to_jiffies(500);
  442. while (ad1843_read_bits(ad1843, &ad1843_PDNO)) {
  443. if (time_after(jiffies, later)) {
  444. printk(KERN_ERR
  445. "ad1843: AD1843 won't power up\n");
  446. return -EIO;
  447. }
  448. schedule_timeout_interruptible(5);
  449. }
  450. /* 5. Power up the clock generators and enable clock output pins. */
  451. ad1843_write_multi(ad1843, 3,
  452. &ad1843_C1EN, 1,
  453. &ad1843_C2EN, 1,
  454. &ad1843_C3EN, 1);
  455. /* 6. Configure conversion resources while they are in standby. */
  456. /* DAC1/2 use clock 1/2 as source, ADC uses clock 3. Always. */
  457. ad1843_write_multi(ad1843, 4,
  458. &ad1843_DA1C, 1,
  459. &ad1843_DA2C, 2,
  460. &ad1843_ADLC, 3,
  461. &ad1843_ADRC, 3);
  462. /* 7. Enable conversion resources. */
  463. ad1843_write_bits(ad1843, &ad1843_ADTLK, 1);
  464. ad1843_write_multi(ad1843, 7,
  465. &ad1843_ANAEN, 1,
  466. &ad1843_AAMEN, 1,
  467. &ad1843_DA1EN, 1,
  468. &ad1843_DA2EN, 1,
  469. &ad1843_DDMEN, 1,
  470. &ad1843_ADLEN, 1,
  471. &ad1843_ADREN, 1);
  472. /* 8. Configure conversion resources while they are enabled. */
  473. /* set gain to 0 for all channels */
  474. ad1843_set_gain(ad1843, AD1843_GAIN_RECLEV, 0);
  475. ad1843_set_gain(ad1843, AD1843_GAIN_LINE, 0);
  476. ad1843_set_gain(ad1843, AD1843_GAIN_LINE_2, 0);
  477. ad1843_set_gain(ad1843, AD1843_GAIN_MIC, 0);
  478. ad1843_set_gain(ad1843, AD1843_GAIN_PCM_0, 0);
  479. ad1843_set_gain(ad1843, AD1843_GAIN_PCM_1, 0);
  480. /* Unmute all channels. */
  481. /* DAC1 */
  482. ad1843_write_multi(ad1843, 2, &ad1843_LDA1GM, 0, &ad1843_RDA1GM, 0);
  483. /* DAC2 */
  484. ad1843_write_multi(ad1843, 2, &ad1843_LDA2GM, 0, &ad1843_RDA2GM, 0);
  485. /* Set default recording source to Line In and set
  486. * mic gain to +20 dB.
  487. */
  488. ad1843_set_recsrc(ad1843, 2);
  489. ad1843_write_multi(ad1843, 2, &ad1843_LMGE, 1, &ad1843_RMGE, 1);
  490. /* Set Speaker Out level to +/- 4V and unmute it. */
  491. ad1843_write_multi(ad1843, 3,
  492. &ad1843_HPOS, 1,
  493. &ad1843_HPOM, 0,
  494. &ad1843_MPOM, 0);
  495. return 0;
  496. }