ad1816a_lib.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /*
  2. ad1816a.c - lowlevel code for Analog Devices AD1816A chip.
  3. Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/slab.h>
  20. #include <linux/ioport.h>
  21. #include <sound/core.h>
  22. #include <sound/tlv.h>
  23. #include <sound/ad1816a.h>
  24. #include <asm/io.h>
  25. #include <asm/dma.h>
  26. static inline int snd_ad1816a_busy_wait(struct snd_ad1816a *chip)
  27. {
  28. int timeout;
  29. for (timeout = 1000; timeout-- > 0; udelay(10))
  30. if (inb(AD1816A_REG(AD1816A_CHIP_STATUS)) & AD1816A_READY)
  31. return 0;
  32. snd_printk(KERN_WARNING "chip busy.\n");
  33. return -EBUSY;
  34. }
  35. static inline unsigned char snd_ad1816a_in(struct snd_ad1816a *chip, unsigned char reg)
  36. {
  37. snd_ad1816a_busy_wait(chip);
  38. return inb(AD1816A_REG(reg));
  39. }
  40. static inline void snd_ad1816a_out(struct snd_ad1816a *chip, unsigned char reg,
  41. unsigned char value)
  42. {
  43. snd_ad1816a_busy_wait(chip);
  44. outb(value, AD1816A_REG(reg));
  45. }
  46. static inline void snd_ad1816a_out_mask(struct snd_ad1816a *chip, unsigned char reg,
  47. unsigned char mask, unsigned char value)
  48. {
  49. snd_ad1816a_out(chip, reg,
  50. (value & mask) | (snd_ad1816a_in(chip, reg) & ~mask));
  51. }
  52. static unsigned short snd_ad1816a_read(struct snd_ad1816a *chip, unsigned char reg)
  53. {
  54. snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
  55. return snd_ad1816a_in(chip, AD1816A_INDIR_DATA_LOW) |
  56. (snd_ad1816a_in(chip, AD1816A_INDIR_DATA_HIGH) << 8);
  57. }
  58. static void snd_ad1816a_write(struct snd_ad1816a *chip, unsigned char reg,
  59. unsigned short value)
  60. {
  61. snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
  62. snd_ad1816a_out(chip, AD1816A_INDIR_DATA_LOW, value & 0xff);
  63. snd_ad1816a_out(chip, AD1816A_INDIR_DATA_HIGH, (value >> 8) & 0xff);
  64. }
  65. static void snd_ad1816a_write_mask(struct snd_ad1816a *chip, unsigned char reg,
  66. unsigned short mask, unsigned short value)
  67. {
  68. snd_ad1816a_write(chip, reg,
  69. (value & mask) | (snd_ad1816a_read(chip, reg) & ~mask));
  70. }
  71. static unsigned char snd_ad1816a_get_format(struct snd_ad1816a *chip,
  72. unsigned int format, int channels)
  73. {
  74. unsigned char retval = AD1816A_FMT_LINEAR_8;
  75. switch (format) {
  76. case SNDRV_PCM_FORMAT_MU_LAW:
  77. retval = AD1816A_FMT_ULAW_8;
  78. break;
  79. case SNDRV_PCM_FORMAT_A_LAW:
  80. retval = AD1816A_FMT_ALAW_8;
  81. break;
  82. case SNDRV_PCM_FORMAT_S16_LE:
  83. retval = AD1816A_FMT_LINEAR_16_LIT;
  84. break;
  85. case SNDRV_PCM_FORMAT_S16_BE:
  86. retval = AD1816A_FMT_LINEAR_16_BIG;
  87. }
  88. return (channels > 1) ? (retval | AD1816A_FMT_STEREO) : retval;
  89. }
  90. static int snd_ad1816a_open(struct snd_ad1816a *chip, unsigned int mode)
  91. {
  92. unsigned long flags;
  93. spin_lock_irqsave(&chip->lock, flags);
  94. if (chip->mode & mode) {
  95. spin_unlock_irqrestore(&chip->lock, flags);
  96. return -EAGAIN;
  97. }
  98. switch ((mode &= AD1816A_MODE_OPEN)) {
  99. case AD1816A_MODE_PLAYBACK:
  100. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  101. AD1816A_PLAYBACK_IRQ_PENDING, 0x00);
  102. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  103. AD1816A_PLAYBACK_IRQ_ENABLE, 0xffff);
  104. break;
  105. case AD1816A_MODE_CAPTURE:
  106. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  107. AD1816A_CAPTURE_IRQ_PENDING, 0x00);
  108. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  109. AD1816A_CAPTURE_IRQ_ENABLE, 0xffff);
  110. break;
  111. case AD1816A_MODE_TIMER:
  112. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  113. AD1816A_TIMER_IRQ_PENDING, 0x00);
  114. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  115. AD1816A_TIMER_IRQ_ENABLE, 0xffff);
  116. }
  117. chip->mode |= mode;
  118. spin_unlock_irqrestore(&chip->lock, flags);
  119. return 0;
  120. }
  121. static void snd_ad1816a_close(struct snd_ad1816a *chip, unsigned int mode)
  122. {
  123. unsigned long flags;
  124. spin_lock_irqsave(&chip->lock, flags);
  125. switch ((mode &= AD1816A_MODE_OPEN)) {
  126. case AD1816A_MODE_PLAYBACK:
  127. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  128. AD1816A_PLAYBACK_IRQ_PENDING, 0x00);
  129. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  130. AD1816A_PLAYBACK_IRQ_ENABLE, 0x0000);
  131. break;
  132. case AD1816A_MODE_CAPTURE:
  133. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  134. AD1816A_CAPTURE_IRQ_PENDING, 0x00);
  135. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  136. AD1816A_CAPTURE_IRQ_ENABLE, 0x0000);
  137. break;
  138. case AD1816A_MODE_TIMER:
  139. snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
  140. AD1816A_TIMER_IRQ_PENDING, 0x00);
  141. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  142. AD1816A_TIMER_IRQ_ENABLE, 0x0000);
  143. }
  144. if (!((chip->mode &= ~mode) & AD1816A_MODE_OPEN))
  145. chip->mode = 0;
  146. spin_unlock_irqrestore(&chip->lock, flags);
  147. }
  148. static int snd_ad1816a_trigger(struct snd_ad1816a *chip, unsigned char what,
  149. int channel, int cmd, int iscapture)
  150. {
  151. int error = 0;
  152. switch (cmd) {
  153. case SNDRV_PCM_TRIGGER_START:
  154. case SNDRV_PCM_TRIGGER_STOP:
  155. spin_lock(&chip->lock);
  156. cmd = (cmd == SNDRV_PCM_TRIGGER_START) ? 0xff: 0x00;
  157. /* if (what & AD1816A_PLAYBACK_ENABLE) */
  158. /* That is not valid, because playback and capture enable
  159. * are the same bit pattern, just to different addresses
  160. */
  161. if (! iscapture)
  162. snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
  163. AD1816A_PLAYBACK_ENABLE, cmd);
  164. else
  165. snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
  166. AD1816A_CAPTURE_ENABLE, cmd);
  167. spin_unlock(&chip->lock);
  168. break;
  169. default:
  170. snd_printk(KERN_WARNING "invalid trigger mode 0x%x.\n", what);
  171. error = -EINVAL;
  172. }
  173. return error;
  174. }
  175. static int snd_ad1816a_playback_trigger(struct snd_pcm_substream *substream, int cmd)
  176. {
  177. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  178. return snd_ad1816a_trigger(chip, AD1816A_PLAYBACK_ENABLE,
  179. SNDRV_PCM_STREAM_PLAYBACK, cmd, 0);
  180. }
  181. static int snd_ad1816a_capture_trigger(struct snd_pcm_substream *substream, int cmd)
  182. {
  183. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  184. return snd_ad1816a_trigger(chip, AD1816A_CAPTURE_ENABLE,
  185. SNDRV_PCM_STREAM_CAPTURE, cmd, 1);
  186. }
  187. static int snd_ad1816a_hw_params(struct snd_pcm_substream *substream,
  188. struct snd_pcm_hw_params *hw_params)
  189. {
  190. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  191. }
  192. static int snd_ad1816a_hw_free(struct snd_pcm_substream *substream)
  193. {
  194. return snd_pcm_lib_free_pages(substream);
  195. }
  196. static int snd_ad1816a_playback_prepare(struct snd_pcm_substream *substream)
  197. {
  198. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  199. unsigned long flags;
  200. struct snd_pcm_runtime *runtime = substream->runtime;
  201. unsigned int size, rate;
  202. spin_lock_irqsave(&chip->lock, flags);
  203. chip->p_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
  204. snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
  205. AD1816A_PLAYBACK_ENABLE | AD1816A_PLAYBACK_PIO, 0x00);
  206. snd_dma_program(chip->dma1, runtime->dma_addr, size,
  207. DMA_MODE_WRITE | DMA_AUTOINIT);
  208. rate = runtime->rate;
  209. if (chip->clock_freq)
  210. rate = (rate * 33000) / chip->clock_freq;
  211. snd_ad1816a_write(chip, AD1816A_PLAYBACK_SAMPLE_RATE, rate);
  212. snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
  213. AD1816A_FMT_ALL | AD1816A_FMT_STEREO,
  214. snd_ad1816a_get_format(chip, runtime->format,
  215. runtime->channels));
  216. snd_ad1816a_write(chip, AD1816A_PLAYBACK_BASE_COUNT,
  217. snd_pcm_lib_period_bytes(substream) / 4 - 1);
  218. spin_unlock_irqrestore(&chip->lock, flags);
  219. return 0;
  220. }
  221. static int snd_ad1816a_capture_prepare(struct snd_pcm_substream *substream)
  222. {
  223. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  224. unsigned long flags;
  225. struct snd_pcm_runtime *runtime = substream->runtime;
  226. unsigned int size, rate;
  227. spin_lock_irqsave(&chip->lock, flags);
  228. chip->c_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
  229. snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
  230. AD1816A_CAPTURE_ENABLE | AD1816A_CAPTURE_PIO, 0x00);
  231. snd_dma_program(chip->dma2, runtime->dma_addr, size,
  232. DMA_MODE_READ | DMA_AUTOINIT);
  233. rate = runtime->rate;
  234. if (chip->clock_freq)
  235. rate = (rate * 33000) / chip->clock_freq;
  236. snd_ad1816a_write(chip, AD1816A_CAPTURE_SAMPLE_RATE, rate);
  237. snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
  238. AD1816A_FMT_ALL | AD1816A_FMT_STEREO,
  239. snd_ad1816a_get_format(chip, runtime->format,
  240. runtime->channels));
  241. snd_ad1816a_write(chip, AD1816A_CAPTURE_BASE_COUNT,
  242. snd_pcm_lib_period_bytes(substream) / 4 - 1);
  243. spin_unlock_irqrestore(&chip->lock, flags);
  244. return 0;
  245. }
  246. static snd_pcm_uframes_t snd_ad1816a_playback_pointer(struct snd_pcm_substream *substream)
  247. {
  248. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  249. size_t ptr;
  250. if (!(chip->mode & AD1816A_MODE_PLAYBACK))
  251. return 0;
  252. ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
  253. return bytes_to_frames(substream->runtime, ptr);
  254. }
  255. static snd_pcm_uframes_t snd_ad1816a_capture_pointer(struct snd_pcm_substream *substream)
  256. {
  257. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  258. size_t ptr;
  259. if (!(chip->mode & AD1816A_MODE_CAPTURE))
  260. return 0;
  261. ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
  262. return bytes_to_frames(substream->runtime, ptr);
  263. }
  264. static irqreturn_t snd_ad1816a_interrupt(int irq, void *dev_id)
  265. {
  266. struct snd_ad1816a *chip = dev_id;
  267. unsigned char status;
  268. spin_lock(&chip->lock);
  269. status = snd_ad1816a_in(chip, AD1816A_INTERRUPT_STATUS);
  270. spin_unlock(&chip->lock);
  271. if ((status & AD1816A_PLAYBACK_IRQ_PENDING) && chip->playback_substream)
  272. snd_pcm_period_elapsed(chip->playback_substream);
  273. if ((status & AD1816A_CAPTURE_IRQ_PENDING) && chip->capture_substream)
  274. snd_pcm_period_elapsed(chip->capture_substream);
  275. if ((status & AD1816A_TIMER_IRQ_PENDING) && chip->timer)
  276. snd_timer_interrupt(chip->timer, chip->timer->sticks);
  277. spin_lock(&chip->lock);
  278. snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
  279. spin_unlock(&chip->lock);
  280. return IRQ_HANDLED;
  281. }
  282. static struct snd_pcm_hardware snd_ad1816a_playback = {
  283. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  284. SNDRV_PCM_INFO_MMAP_VALID),
  285. .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
  286. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
  287. SNDRV_PCM_FMTBIT_S16_BE),
  288. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  289. .rate_min = 4000,
  290. .rate_max = 55200,
  291. .channels_min = 1,
  292. .channels_max = 2,
  293. .buffer_bytes_max = (128*1024),
  294. .period_bytes_min = 64,
  295. .period_bytes_max = (128*1024),
  296. .periods_min = 1,
  297. .periods_max = 1024,
  298. .fifo_size = 0,
  299. };
  300. static struct snd_pcm_hardware snd_ad1816a_capture = {
  301. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  302. SNDRV_PCM_INFO_MMAP_VALID),
  303. .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
  304. SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
  305. SNDRV_PCM_FMTBIT_S16_BE),
  306. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  307. .rate_min = 4000,
  308. .rate_max = 55200,
  309. .channels_min = 1,
  310. .channels_max = 2,
  311. .buffer_bytes_max = (128*1024),
  312. .period_bytes_min = 64,
  313. .period_bytes_max = (128*1024),
  314. .periods_min = 1,
  315. .periods_max = 1024,
  316. .fifo_size = 0,
  317. };
  318. static int snd_ad1816a_timer_close(struct snd_timer *timer)
  319. {
  320. struct snd_ad1816a *chip = snd_timer_chip(timer);
  321. snd_ad1816a_close(chip, AD1816A_MODE_TIMER);
  322. return 0;
  323. }
  324. static int snd_ad1816a_timer_open(struct snd_timer *timer)
  325. {
  326. struct snd_ad1816a *chip = snd_timer_chip(timer);
  327. snd_ad1816a_open(chip, AD1816A_MODE_TIMER);
  328. return 0;
  329. }
  330. static unsigned long snd_ad1816a_timer_resolution(struct snd_timer *timer)
  331. {
  332. if (snd_BUG_ON(!timer))
  333. return 0;
  334. return 10000;
  335. }
  336. static int snd_ad1816a_timer_start(struct snd_timer *timer)
  337. {
  338. unsigned short bits;
  339. unsigned long flags;
  340. struct snd_ad1816a *chip = snd_timer_chip(timer);
  341. spin_lock_irqsave(&chip->lock, flags);
  342. bits = snd_ad1816a_read(chip, AD1816A_INTERRUPT_ENABLE);
  343. if (!(bits & AD1816A_TIMER_ENABLE)) {
  344. snd_ad1816a_write(chip, AD1816A_TIMER_BASE_COUNT,
  345. timer->sticks & 0xffff);
  346. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  347. AD1816A_TIMER_ENABLE, 0xffff);
  348. }
  349. spin_unlock_irqrestore(&chip->lock, flags);
  350. return 0;
  351. }
  352. static int snd_ad1816a_timer_stop(struct snd_timer *timer)
  353. {
  354. unsigned long flags;
  355. struct snd_ad1816a *chip = snd_timer_chip(timer);
  356. spin_lock_irqsave(&chip->lock, flags);
  357. snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
  358. AD1816A_TIMER_ENABLE, 0x0000);
  359. spin_unlock_irqrestore(&chip->lock, flags);
  360. return 0;
  361. }
  362. static struct snd_timer_hardware snd_ad1816a_timer_table = {
  363. .flags = SNDRV_TIMER_HW_AUTO,
  364. .resolution = 10000,
  365. .ticks = 65535,
  366. .open = snd_ad1816a_timer_open,
  367. .close = snd_ad1816a_timer_close,
  368. .c_resolution = snd_ad1816a_timer_resolution,
  369. .start = snd_ad1816a_timer_start,
  370. .stop = snd_ad1816a_timer_stop,
  371. };
  372. static int snd_ad1816a_playback_open(struct snd_pcm_substream *substream)
  373. {
  374. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  375. struct snd_pcm_runtime *runtime = substream->runtime;
  376. int error;
  377. if ((error = snd_ad1816a_open(chip, AD1816A_MODE_PLAYBACK)) < 0)
  378. return error;
  379. runtime->hw = snd_ad1816a_playback;
  380. snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
  381. snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
  382. chip->playback_substream = substream;
  383. return 0;
  384. }
  385. static int snd_ad1816a_capture_open(struct snd_pcm_substream *substream)
  386. {
  387. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  388. struct snd_pcm_runtime *runtime = substream->runtime;
  389. int error;
  390. if ((error = snd_ad1816a_open(chip, AD1816A_MODE_CAPTURE)) < 0)
  391. return error;
  392. runtime->hw = snd_ad1816a_capture;
  393. snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
  394. snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
  395. chip->capture_substream = substream;
  396. return 0;
  397. }
  398. static int snd_ad1816a_playback_close(struct snd_pcm_substream *substream)
  399. {
  400. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  401. chip->playback_substream = NULL;
  402. snd_ad1816a_close(chip, AD1816A_MODE_PLAYBACK);
  403. return 0;
  404. }
  405. static int snd_ad1816a_capture_close(struct snd_pcm_substream *substream)
  406. {
  407. struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
  408. chip->capture_substream = NULL;
  409. snd_ad1816a_close(chip, AD1816A_MODE_CAPTURE);
  410. return 0;
  411. }
  412. static void __devinit snd_ad1816a_init(struct snd_ad1816a *chip)
  413. {
  414. unsigned long flags;
  415. spin_lock_irqsave(&chip->lock, flags);
  416. snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
  417. snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
  418. AD1816A_PLAYBACK_ENABLE | AD1816A_PLAYBACK_PIO, 0x00);
  419. snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
  420. AD1816A_CAPTURE_ENABLE | AD1816A_CAPTURE_PIO, 0x00);
  421. snd_ad1816a_write(chip, AD1816A_INTERRUPT_ENABLE, 0x0000);
  422. snd_ad1816a_write_mask(chip, AD1816A_CHIP_CONFIG,
  423. AD1816A_CAPTURE_NOT_EQUAL | AD1816A_WSS_ENABLE, 0xffff);
  424. snd_ad1816a_write(chip, AD1816A_DSP_CONFIG, 0x0000);
  425. snd_ad1816a_write(chip, AD1816A_POWERDOWN_CTRL, 0x0000);
  426. spin_unlock_irqrestore(&chip->lock, flags);
  427. }
  428. static int __devinit snd_ad1816a_probe(struct snd_ad1816a *chip)
  429. {
  430. unsigned long flags;
  431. spin_lock_irqsave(&chip->lock, flags);
  432. switch (chip->version = snd_ad1816a_read(chip, AD1816A_VERSION_ID)) {
  433. case 0:
  434. chip->hardware = AD1816A_HW_AD1815;
  435. break;
  436. case 1:
  437. chip->hardware = AD1816A_HW_AD18MAX10;
  438. break;
  439. case 3:
  440. chip->hardware = AD1816A_HW_AD1816A;
  441. break;
  442. default:
  443. chip->hardware = AD1816A_HW_AUTO;
  444. }
  445. spin_unlock_irqrestore(&chip->lock, flags);
  446. return 0;
  447. }
  448. static int snd_ad1816a_free(struct snd_ad1816a *chip)
  449. {
  450. release_and_free_resource(chip->res_port);
  451. if (chip->irq >= 0)
  452. free_irq(chip->irq, (void *) chip);
  453. if (chip->dma1 >= 0) {
  454. snd_dma_disable(chip->dma1);
  455. free_dma(chip->dma1);
  456. }
  457. if (chip->dma2 >= 0) {
  458. snd_dma_disable(chip->dma2);
  459. free_dma(chip->dma2);
  460. }
  461. kfree(chip);
  462. return 0;
  463. }
  464. static int snd_ad1816a_dev_free(struct snd_device *device)
  465. {
  466. struct snd_ad1816a *chip = device->device_data;
  467. return snd_ad1816a_free(chip);
  468. }
  469. static const char __devinit *snd_ad1816a_chip_id(struct snd_ad1816a *chip)
  470. {
  471. switch (chip->hardware) {
  472. case AD1816A_HW_AD1816A: return "AD1816A";
  473. case AD1816A_HW_AD1815: return "AD1815";
  474. case AD1816A_HW_AD18MAX10: return "AD18max10";
  475. default:
  476. snd_printk(KERN_WARNING "Unknown chip version %d:%d.\n",
  477. chip->version, chip->hardware);
  478. return "AD1816A - unknown";
  479. }
  480. }
  481. int __devinit snd_ad1816a_create(struct snd_card *card,
  482. unsigned long port, int irq, int dma1, int dma2,
  483. struct snd_ad1816a **rchip)
  484. {
  485. static struct snd_device_ops ops = {
  486. .dev_free = snd_ad1816a_dev_free,
  487. };
  488. int error;
  489. struct snd_ad1816a *chip;
  490. *rchip = NULL;
  491. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  492. if (chip == NULL)
  493. return -ENOMEM;
  494. chip->irq = -1;
  495. chip->dma1 = -1;
  496. chip->dma2 = -1;
  497. if ((chip->res_port = request_region(port, 16, "AD1816A")) == NULL) {
  498. snd_printk(KERN_ERR "ad1816a: can't grab port 0x%lx\n", port);
  499. snd_ad1816a_free(chip);
  500. return -EBUSY;
  501. }
  502. if (request_irq(irq, snd_ad1816a_interrupt, 0, "AD1816A", (void *) chip)) {
  503. snd_printk(KERN_ERR "ad1816a: can't grab IRQ %d\n", irq);
  504. snd_ad1816a_free(chip);
  505. return -EBUSY;
  506. }
  507. chip->irq = irq;
  508. if (request_dma(dma1, "AD1816A - 1")) {
  509. snd_printk(KERN_ERR "ad1816a: can't grab DMA1 %d\n", dma1);
  510. snd_ad1816a_free(chip);
  511. return -EBUSY;
  512. }
  513. chip->dma1 = dma1;
  514. if (request_dma(dma2, "AD1816A - 2")) {
  515. snd_printk(KERN_ERR "ad1816a: can't grab DMA2 %d\n", dma2);
  516. snd_ad1816a_free(chip);
  517. return -EBUSY;
  518. }
  519. chip->dma2 = dma2;
  520. chip->card = card;
  521. chip->port = port;
  522. spin_lock_init(&chip->lock);
  523. if ((error = snd_ad1816a_probe(chip))) {
  524. snd_ad1816a_free(chip);
  525. return error;
  526. }
  527. snd_ad1816a_init(chip);
  528. /* Register device */
  529. if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  530. snd_ad1816a_free(chip);
  531. return error;
  532. }
  533. *rchip = chip;
  534. return 0;
  535. }
  536. static struct snd_pcm_ops snd_ad1816a_playback_ops = {
  537. .open = snd_ad1816a_playback_open,
  538. .close = snd_ad1816a_playback_close,
  539. .ioctl = snd_pcm_lib_ioctl,
  540. .hw_params = snd_ad1816a_hw_params,
  541. .hw_free = snd_ad1816a_hw_free,
  542. .prepare = snd_ad1816a_playback_prepare,
  543. .trigger = snd_ad1816a_playback_trigger,
  544. .pointer = snd_ad1816a_playback_pointer,
  545. };
  546. static struct snd_pcm_ops snd_ad1816a_capture_ops = {
  547. .open = snd_ad1816a_capture_open,
  548. .close = snd_ad1816a_capture_close,
  549. .ioctl = snd_pcm_lib_ioctl,
  550. .hw_params = snd_ad1816a_hw_params,
  551. .hw_free = snd_ad1816a_hw_free,
  552. .prepare = snd_ad1816a_capture_prepare,
  553. .trigger = snd_ad1816a_capture_trigger,
  554. .pointer = snd_ad1816a_capture_pointer,
  555. };
  556. int __devinit snd_ad1816a_pcm(struct snd_ad1816a *chip, int device, struct snd_pcm **rpcm)
  557. {
  558. int error;
  559. struct snd_pcm *pcm;
  560. if ((error = snd_pcm_new(chip->card, "AD1816A", device, 1, 1, &pcm)))
  561. return error;
  562. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1816a_playback_ops);
  563. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1816a_capture_ops);
  564. pcm->private_data = chip;
  565. pcm->info_flags = (chip->dma1 == chip->dma2 ) ? SNDRV_PCM_INFO_JOINT_DUPLEX : 0;
  566. strcpy(pcm->name, snd_ad1816a_chip_id(chip));
  567. snd_ad1816a_init(chip);
  568. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  569. snd_dma_isa_data(),
  570. 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
  571. chip->pcm = pcm;
  572. if (rpcm)
  573. *rpcm = pcm;
  574. return 0;
  575. }
  576. int __devinit snd_ad1816a_timer(struct snd_ad1816a *chip, int device, struct snd_timer **rtimer)
  577. {
  578. struct snd_timer *timer;
  579. struct snd_timer_id tid;
  580. int error;
  581. tid.dev_class = SNDRV_TIMER_CLASS_CARD;
  582. tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
  583. tid.card = chip->card->number;
  584. tid.device = device;
  585. tid.subdevice = 0;
  586. if ((error = snd_timer_new(chip->card, "AD1816A", &tid, &timer)) < 0)
  587. return error;
  588. strcpy(timer->name, snd_ad1816a_chip_id(chip));
  589. timer->private_data = chip;
  590. chip->timer = timer;
  591. timer->hw = snd_ad1816a_timer_table;
  592. if (rtimer)
  593. *rtimer = timer;
  594. return 0;
  595. }
  596. /*
  597. *
  598. */
  599. static int snd_ad1816a_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  600. {
  601. static char *texts[8] = {
  602. "Line", "Mix", "CD", "Synth", "Video",
  603. "Mic", "Phone",
  604. };
  605. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  606. uinfo->count = 2;
  607. uinfo->value.enumerated.items = 7;
  608. if (uinfo->value.enumerated.item > 6)
  609. uinfo->value.enumerated.item = 6;
  610. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  611. return 0;
  612. }
  613. static int snd_ad1816a_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  614. {
  615. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  616. unsigned long flags;
  617. unsigned short val;
  618. spin_lock_irqsave(&chip->lock, flags);
  619. val = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL);
  620. spin_unlock_irqrestore(&chip->lock, flags);
  621. ucontrol->value.enumerated.item[0] = (val >> 12) & 7;
  622. ucontrol->value.enumerated.item[1] = (val >> 4) & 7;
  623. return 0;
  624. }
  625. static int snd_ad1816a_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  626. {
  627. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  628. unsigned long flags;
  629. unsigned short val;
  630. int change;
  631. if (ucontrol->value.enumerated.item[0] > 6 ||
  632. ucontrol->value.enumerated.item[1] > 6)
  633. return -EINVAL;
  634. val = (ucontrol->value.enumerated.item[0] << 12) |
  635. (ucontrol->value.enumerated.item[1] << 4);
  636. spin_lock_irqsave(&chip->lock, flags);
  637. change = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL) != val;
  638. snd_ad1816a_write(chip, AD1816A_ADC_SOURCE_SEL, val);
  639. spin_unlock_irqrestore(&chip->lock, flags);
  640. return change;
  641. }
  642. #define AD1816A_SINGLE_TLV(xname, reg, shift, mask, invert, xtlv) \
  643. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  644. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  645. .name = xname, .info = snd_ad1816a_info_single, \
  646. .get = snd_ad1816a_get_single, .put = snd_ad1816a_put_single, \
  647. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
  648. .tlv = { .p = (xtlv) } }
  649. #define AD1816A_SINGLE(xname, reg, shift, mask, invert) \
  650. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_single, \
  651. .get = snd_ad1816a_get_single, .put = snd_ad1816a_put_single, \
  652. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  653. static int snd_ad1816a_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  654. {
  655. int mask = (kcontrol->private_value >> 16) & 0xff;
  656. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  657. uinfo->count = 1;
  658. uinfo->value.integer.min = 0;
  659. uinfo->value.integer.max = mask;
  660. return 0;
  661. }
  662. static int snd_ad1816a_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  663. {
  664. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  665. unsigned long flags;
  666. int reg = kcontrol->private_value & 0xff;
  667. int shift = (kcontrol->private_value >> 8) & 0xff;
  668. int mask = (kcontrol->private_value >> 16) & 0xff;
  669. int invert = (kcontrol->private_value >> 24) & 0xff;
  670. spin_lock_irqsave(&chip->lock, flags);
  671. ucontrol->value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask;
  672. spin_unlock_irqrestore(&chip->lock, flags);
  673. if (invert)
  674. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  675. return 0;
  676. }
  677. static int snd_ad1816a_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  678. {
  679. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  680. unsigned long flags;
  681. int reg = kcontrol->private_value & 0xff;
  682. int shift = (kcontrol->private_value >> 8) & 0xff;
  683. int mask = (kcontrol->private_value >> 16) & 0xff;
  684. int invert = (kcontrol->private_value >> 24) & 0xff;
  685. int change;
  686. unsigned short old_val, val;
  687. val = (ucontrol->value.integer.value[0] & mask);
  688. if (invert)
  689. val = mask - val;
  690. val <<= shift;
  691. spin_lock_irqsave(&chip->lock, flags);
  692. old_val = snd_ad1816a_read(chip, reg);
  693. val = (old_val & ~(mask << shift)) | val;
  694. change = val != old_val;
  695. snd_ad1816a_write(chip, reg, val);
  696. spin_unlock_irqrestore(&chip->lock, flags);
  697. return change;
  698. }
  699. #define AD1816A_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
  700. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  701. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  702. .name = xname, .info = snd_ad1816a_info_double, \
  703. .get = snd_ad1816a_get_double, .put = snd_ad1816a_put_double, \
  704. .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
  705. .tlv = { .p = (xtlv) } }
  706. #define AD1816A_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
  707. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_double, \
  708. .get = snd_ad1816a_get_double, .put = snd_ad1816a_put_double, \
  709. .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
  710. static int snd_ad1816a_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  711. {
  712. int mask = (kcontrol->private_value >> 16) & 0xff;
  713. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  714. uinfo->count = 2;
  715. uinfo->value.integer.min = 0;
  716. uinfo->value.integer.max = mask;
  717. return 0;
  718. }
  719. static int snd_ad1816a_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  720. {
  721. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  722. unsigned long flags;
  723. int reg = kcontrol->private_value & 0xff;
  724. int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  725. int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  726. int mask = (kcontrol->private_value >> 16) & 0xff;
  727. int invert = (kcontrol->private_value >> 24) & 0xff;
  728. unsigned short val;
  729. spin_lock_irqsave(&chip->lock, flags);
  730. val = snd_ad1816a_read(chip, reg);
  731. ucontrol->value.integer.value[0] = (val >> shift_left) & mask;
  732. ucontrol->value.integer.value[1] = (val >> shift_right) & mask;
  733. spin_unlock_irqrestore(&chip->lock, flags);
  734. if (invert) {
  735. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  736. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  737. }
  738. return 0;
  739. }
  740. static int snd_ad1816a_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  741. {
  742. struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
  743. unsigned long flags;
  744. int reg = kcontrol->private_value & 0xff;
  745. int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  746. int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  747. int mask = (kcontrol->private_value >> 16) & 0xff;
  748. int invert = (kcontrol->private_value >> 24) & 0xff;
  749. int change;
  750. unsigned short old_val, val1, val2;
  751. val1 = ucontrol->value.integer.value[0] & mask;
  752. val2 = ucontrol->value.integer.value[1] & mask;
  753. if (invert) {
  754. val1 = mask - val1;
  755. val2 = mask - val2;
  756. }
  757. val1 <<= shift_left;
  758. val2 <<= shift_right;
  759. spin_lock_irqsave(&chip->lock, flags);
  760. old_val = snd_ad1816a_read(chip, reg);
  761. val1 = (old_val & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
  762. change = val1 != old_val;
  763. snd_ad1816a_write(chip, reg, val1);
  764. spin_unlock_irqrestore(&chip->lock, flags);
  765. return change;
  766. }
  767. static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
  768. static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
  769. static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
  770. static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
  771. static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
  772. static struct snd_kcontrol_new snd_ad1816a_controls[] __devinitdata = {
  773. AD1816A_DOUBLE("Master Playback Switch", AD1816A_MASTER_ATT, 15, 7, 1, 1),
  774. AD1816A_DOUBLE_TLV("Master Playback Volume", AD1816A_MASTER_ATT, 8, 0, 31, 1,
  775. db_scale_5bit),
  776. AD1816A_DOUBLE("PCM Playback Switch", AD1816A_VOICE_ATT, 15, 7, 1, 1),
  777. AD1816A_DOUBLE_TLV("PCM Playback Volume", AD1816A_VOICE_ATT, 8, 0, 63, 1,
  778. db_scale_6bit),
  779. AD1816A_DOUBLE("Line Playback Switch", AD1816A_LINE_GAIN_ATT, 15, 7, 1, 1),
  780. AD1816A_DOUBLE_TLV("Line Playback Volume", AD1816A_LINE_GAIN_ATT, 8, 0, 31, 1,
  781. db_scale_5bit_12db_max),
  782. AD1816A_DOUBLE("CD Playback Switch", AD1816A_CD_GAIN_ATT, 15, 7, 1, 1),
  783. AD1816A_DOUBLE_TLV("CD Playback Volume", AD1816A_CD_GAIN_ATT, 8, 0, 31, 1,
  784. db_scale_5bit_12db_max),
  785. AD1816A_DOUBLE("Synth Playback Switch", AD1816A_SYNTH_GAIN_ATT, 15, 7, 1, 1),
  786. AD1816A_DOUBLE_TLV("Synth Playback Volume", AD1816A_SYNTH_GAIN_ATT, 8, 0, 31, 1,
  787. db_scale_5bit_12db_max),
  788. AD1816A_DOUBLE("FM Playback Switch", AD1816A_FM_ATT, 15, 7, 1, 1),
  789. AD1816A_DOUBLE_TLV("FM Playback Volume", AD1816A_FM_ATT, 8, 0, 63, 1,
  790. db_scale_6bit),
  791. AD1816A_SINGLE("Mic Playback Switch", AD1816A_MIC_GAIN_ATT, 15, 1, 1),
  792. AD1816A_SINGLE_TLV("Mic Playback Volume", AD1816A_MIC_GAIN_ATT, 8, 31, 1,
  793. db_scale_5bit_12db_max),
  794. AD1816A_SINGLE("Mic Boost", AD1816A_MIC_GAIN_ATT, 14, 1, 0),
  795. AD1816A_DOUBLE("Video Playback Switch", AD1816A_VID_GAIN_ATT, 15, 7, 1, 1),
  796. AD1816A_DOUBLE_TLV("Video Playback Volume", AD1816A_VID_GAIN_ATT, 8, 0, 31, 1,
  797. db_scale_5bit_12db_max),
  798. AD1816A_SINGLE("Phone Capture Switch", AD1816A_PHONE_IN_GAIN_ATT, 15, 1, 1),
  799. AD1816A_SINGLE_TLV("Phone Capture Volume", AD1816A_PHONE_IN_GAIN_ATT, 0, 15, 1,
  800. db_scale_4bit),
  801. AD1816A_SINGLE("Phone Playback Switch", AD1816A_PHONE_OUT_ATT, 7, 1, 1),
  802. AD1816A_SINGLE_TLV("Phone Playback Volume", AD1816A_PHONE_OUT_ATT, 0, 31, 1,
  803. db_scale_5bit),
  804. {
  805. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  806. .name = "Capture Source",
  807. .info = snd_ad1816a_info_mux,
  808. .get = snd_ad1816a_get_mux,
  809. .put = snd_ad1816a_put_mux,
  810. },
  811. AD1816A_DOUBLE("Capture Switch", AD1816A_ADC_PGA, 15, 7, 1, 1),
  812. AD1816A_DOUBLE_TLV("Capture Volume", AD1816A_ADC_PGA, 8, 0, 15, 0,
  813. db_scale_rec_gain),
  814. AD1816A_SINGLE("3D Control - Switch", AD1816A_3D_PHAT_CTRL, 15, 1, 1),
  815. AD1816A_SINGLE("3D Control - Level", AD1816A_3D_PHAT_CTRL, 0, 15, 0),
  816. };
  817. int __devinit snd_ad1816a_mixer(struct snd_ad1816a *chip)
  818. {
  819. struct snd_card *card;
  820. unsigned int idx;
  821. int err;
  822. if (snd_BUG_ON(!chip || !chip->card))
  823. return -EINVAL;
  824. card = chip->card;
  825. strcpy(card->mixername, snd_ad1816a_chip_id(chip));
  826. for (idx = 0; idx < ARRAY_SIZE(snd_ad1816a_controls); idx++) {
  827. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ad1816a_controls[idx], chip))) < 0)
  828. return err;
  829. }
  830. return 0;
  831. }