ad1816a_lib.c 30 KB

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