cx25821-alsa.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Driver for the Conexant CX25821 PCIe bridge
  3. *
  4. * Copyright (C) 2009 Conexant Systems Inc.
  5. * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
  6. * Based on SAA713x ALSA driver and CX88 driver
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, version 2
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/pci.h>
  30. #include <linux/slab.h>
  31. #include <linux/delay.h>
  32. #include <sound/core.h>
  33. #include <sound/pcm.h>
  34. #include <sound/pcm_params.h>
  35. #include <sound/control.h>
  36. #include <sound/initval.h>
  37. #include <sound/tlv.h>
  38. #include "cx25821.h"
  39. #include "cx25821-reg.h"
  40. #define AUDIO_SRAM_CHANNEL SRAM_CH08
  41. #define dprintk(level, fmt, arg...) \
  42. do { \
  43. if (debug >= level) \
  44. pr_info("%s/1: " fmt, chip->dev->name, ##arg); \
  45. } while (0)
  46. #define dprintk_core(level, fmt, arg...) \
  47. do { \
  48. if (debug >= level) \
  49. printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name, ##arg); \
  50. } while (0)
  51. /****************************************************************************
  52. Data type declarations - Can be moded to a header file later
  53. ****************************************************************************/
  54. static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
  55. static int devno;
  56. struct cx25821_audio_buffer {
  57. unsigned int bpl;
  58. struct btcx_riscmem risc;
  59. struct videobuf_dmabuf dma;
  60. };
  61. struct cx25821_audio_dev {
  62. struct cx25821_dev *dev;
  63. struct cx25821_dmaqueue q;
  64. /* pci i/o */
  65. struct pci_dev *pci;
  66. /* audio controls */
  67. int irq;
  68. struct snd_card *card;
  69. unsigned long iobase;
  70. spinlock_t reg_lock;
  71. atomic_t count;
  72. unsigned int dma_size;
  73. unsigned int period_size;
  74. unsigned int num_periods;
  75. struct videobuf_dmabuf *dma_risc;
  76. struct cx25821_audio_buffer *buf;
  77. struct snd_pcm_substream *substream;
  78. };
  79. /****************************************************************************
  80. Module global static vars
  81. ****************************************************************************/
  82. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  83. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  84. static bool enable[SNDRV_CARDS] = { 1, [1 ... (SNDRV_CARDS - 1)] = 1 };
  85. module_param_array(enable, bool, NULL, 0444);
  86. MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
  87. module_param_array(index, int, NULL, 0444);
  88. MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
  89. /****************************************************************************
  90. Module macros
  91. ****************************************************************************/
  92. MODULE_DESCRIPTION("ALSA driver module for cx25821 based capture cards");
  93. MODULE_AUTHOR("Hiep Huynh");
  94. MODULE_LICENSE("GPL");
  95. MODULE_SUPPORTED_DEVICE("{{Conexant,25821}"); /* "{{Conexant,23881}," */
  96. static unsigned int debug;
  97. module_param(debug, int, 0644);
  98. MODULE_PARM_DESC(debug, "enable debug messages");
  99. /****************************************************************************
  100. Module specific funtions
  101. ****************************************************************************/
  102. /* Constants taken from cx88-reg.h */
  103. #define AUD_INT_DN_RISCI1 (1 << 0)
  104. #define AUD_INT_UP_RISCI1 (1 << 1)
  105. #define AUD_INT_RDS_DN_RISCI1 (1 << 2)
  106. #define AUD_INT_DN_RISCI2 (1 << 4) /* yes, 3 is skipped */
  107. #define AUD_INT_UP_RISCI2 (1 << 5)
  108. #define AUD_INT_RDS_DN_RISCI2 (1 << 6)
  109. #define AUD_INT_DN_SYNC (1 << 12)
  110. #define AUD_INT_UP_SYNC (1 << 13)
  111. #define AUD_INT_RDS_DN_SYNC (1 << 14)
  112. #define AUD_INT_OPC_ERR (1 << 16)
  113. #define AUD_INT_BER_IRQ (1 << 20)
  114. #define AUD_INT_MCHG_IRQ (1 << 21)
  115. #define GP_COUNT_CONTROL_RESET 0x3
  116. #define PCI_MSK_AUD_EXT (1 << 4)
  117. #define PCI_MSK_AUD_INT (1 << 3)
  118. /*
  119. * BOARD Specific: Sets audio DMA
  120. */
  121. static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
  122. {
  123. struct cx25821_audio_buffer *buf = chip->buf;
  124. struct cx25821_dev *dev = chip->dev;
  125. struct sram_channel *audio_ch =
  126. &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
  127. u32 tmp = 0;
  128. /* enable output on the GPIO 0 for the MCLK ADC (Audio) */
  129. cx25821_set_gpiopin_direction(chip->dev, 0, 0);
  130. /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
  131. cx_clear(AUD_INT_DMA_CTL,
  132. FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
  133. /* setup fifo + format - out channel */
  134. cx25821_sram_channel_setup_audio(chip->dev, audio_ch, buf->bpl,
  135. buf->risc.dma);
  136. /* sets bpl size */
  137. cx_write(AUD_A_LNGTH, buf->bpl);
  138. /* reset counter */
  139. /* GP_COUNT_CONTROL_RESET = 0x3 */
  140. cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
  141. atomic_set(&chip->count, 0);
  142. /* Set the input mode to 16-bit */
  143. tmp = cx_read(AUD_A_CFG);
  144. cx_write(AUD_A_CFG, tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE |
  145. FLD_AUD_CLK_ENABLE);
  146. /*
  147. pr_info("DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d byte buffer\n",
  148. buf->bpl, audio_ch->cmds_start,
  149. cx_read(audio_ch->cmds_start + 12)>>1,
  150. chip->num_periods, buf->bpl * chip->num_periods);
  151. */
  152. /* Enables corresponding bits at AUD_INT_STAT */
  153. cx_write(AUD_A_INT_MSK, FLD_AUD_DST_RISCI1 | FLD_AUD_DST_OF |
  154. FLD_AUD_DST_SYNC | FLD_AUD_DST_OPC_ERR);
  155. /* Clean any pending interrupt bits already set */
  156. cx_write(AUD_A_INT_STAT, ~0);
  157. /* enable audio irqs */
  158. cx_set(PCI_INT_MSK, chip->dev->pci_irqmask | PCI_MSK_AUD_INT);
  159. /* Turn on audio downstream fifo and risc enable 0x101 */
  160. tmp = cx_read(AUD_INT_DMA_CTL);
  161. cx_set(AUD_INT_DMA_CTL, tmp |
  162. (FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN));
  163. mdelay(100);
  164. return 0;
  165. }
  166. /*
  167. * BOARD Specific: Resets audio DMA
  168. */
  169. static int _cx25821_stop_audio_dma(struct cx25821_audio_dev *chip)
  170. {
  171. struct cx25821_dev *dev = chip->dev;
  172. /* stop dma */
  173. cx_clear(AUD_INT_DMA_CTL,
  174. FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
  175. /* disable irqs */
  176. cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT);
  177. cx_clear(AUD_A_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
  178. AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
  179. return 0;
  180. }
  181. #define MAX_IRQ_LOOP 50
  182. /*
  183. * BOARD Specific: IRQ dma bits
  184. */
  185. static char *cx25821_aud_irqs[32] = {
  186. "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
  187. NULL, /* reserved */
  188. "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
  189. NULL, /* reserved */
  190. "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
  191. NULL, /* reserved */
  192. "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
  193. NULL, /* reserved */
  194. "opc_err", "par_err", "rip_err", /* 16-18 */
  195. "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
  196. };
  197. /*
  198. * BOARD Specific: Threats IRQ audio specific calls
  199. */
  200. static void cx25821_aud_irq(struct cx25821_audio_dev *chip, u32 status,
  201. u32 mask)
  202. {
  203. struct cx25821_dev *dev = chip->dev;
  204. if (0 == (status & mask))
  205. return;
  206. cx_write(AUD_A_INT_STAT, status);
  207. if (debug > 1 || (status & mask & ~0xff))
  208. cx25821_print_irqbits(dev->name, "irq aud", cx25821_aud_irqs,
  209. ARRAY_SIZE(cx25821_aud_irqs), status, mask);
  210. /* risc op code error */
  211. if (status & AUD_INT_OPC_ERR) {
  212. pr_warn("WARNING %s/1: Audio risc op code error\n", dev->name);
  213. cx_clear(AUD_INT_DMA_CTL,
  214. FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
  215. cx25821_sram_channel_dump_audio(dev,
  216. &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]);
  217. }
  218. if (status & AUD_INT_DN_SYNC) {
  219. pr_warn("WARNING %s: Downstream sync error!\n", dev->name);
  220. cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
  221. return;
  222. }
  223. /* risc1 downstream */
  224. if (status & AUD_INT_DN_RISCI1) {
  225. atomic_set(&chip->count, cx_read(AUD_A_GPCNT));
  226. snd_pcm_period_elapsed(chip->substream);
  227. }
  228. }
  229. /*
  230. * BOARD Specific: Handles IRQ calls
  231. */
  232. static irqreturn_t cx25821_irq(int irq, void *dev_id)
  233. {
  234. struct cx25821_audio_dev *chip = dev_id;
  235. struct cx25821_dev *dev = chip->dev;
  236. u32 status, pci_status;
  237. u32 audint_status, audint_mask;
  238. int loop, handled = 0;
  239. audint_status = cx_read(AUD_A_INT_STAT);
  240. audint_mask = cx_read(AUD_A_INT_MSK);
  241. status = cx_read(PCI_INT_STAT);
  242. for (loop = 0; loop < 1; loop++) {
  243. status = cx_read(PCI_INT_STAT);
  244. if (0 == status) {
  245. status = cx_read(PCI_INT_STAT);
  246. audint_status = cx_read(AUD_A_INT_STAT);
  247. audint_mask = cx_read(AUD_A_INT_MSK);
  248. if (status) {
  249. handled = 1;
  250. cx_write(PCI_INT_STAT, status);
  251. cx25821_aud_irq(chip, audint_status,
  252. audint_mask);
  253. break;
  254. } else {
  255. goto out;
  256. }
  257. }
  258. handled = 1;
  259. cx_write(PCI_INT_STAT, status);
  260. cx25821_aud_irq(chip, audint_status, audint_mask);
  261. }
  262. pci_status = cx_read(PCI_INT_STAT);
  263. if (handled)
  264. cx_write(PCI_INT_STAT, pci_status);
  265. out:
  266. return IRQ_RETVAL(handled);
  267. }
  268. static int dsp_buffer_free(struct cx25821_audio_dev *chip)
  269. {
  270. BUG_ON(!chip->dma_size);
  271. dprintk(2, "Freeing buffer\n");
  272. videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc);
  273. videobuf_dma_free(chip->dma_risc);
  274. btcx_riscmem_free(chip->pci, &chip->buf->risc);
  275. kfree(chip->buf);
  276. chip->dma_risc = NULL;
  277. chip->dma_size = 0;
  278. return 0;
  279. }
  280. /****************************************************************************
  281. ALSA PCM Interface
  282. ****************************************************************************/
  283. /*
  284. * Digital hardware definition
  285. */
  286. #define DEFAULT_FIFO_SIZE 384
  287. static struct snd_pcm_hardware snd_cx25821_digital_hw = {
  288. .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  289. SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID,
  290. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  291. .rates = SNDRV_PCM_RATE_48000,
  292. .rate_min = 48000,
  293. .rate_max = 48000,
  294. .channels_min = 2,
  295. .channels_max = 2,
  296. /* Analog audio output will be full of clicks and pops if there
  297. are not exactly four lines in the SRAM FIFO buffer. */
  298. .period_bytes_min = DEFAULT_FIFO_SIZE / 3,
  299. .period_bytes_max = DEFAULT_FIFO_SIZE / 3,
  300. .periods_min = 1,
  301. .periods_max = AUDIO_LINE_SIZE,
  302. /* 128 * 128 = 16384 = 1024 * 16 */
  303. .buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE),
  304. };
  305. /*
  306. * audio pcm capture open callback
  307. */
  308. static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
  309. {
  310. struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
  311. struct snd_pcm_runtime *runtime = substream->runtime;
  312. int err;
  313. unsigned int bpl = 0;
  314. if (!chip) {
  315. pr_err("DEBUG: cx25821 can't find device struct. Can't proceed with open\n");
  316. return -ENODEV;
  317. }
  318. err = snd_pcm_hw_constraint_pow2(runtime, 0,
  319. SNDRV_PCM_HW_PARAM_PERIODS);
  320. if (err < 0)
  321. goto _error;
  322. chip->substream = substream;
  323. runtime->hw = snd_cx25821_digital_hw;
  324. if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size !=
  325. DEFAULT_FIFO_SIZE) {
  326. /* since there are 3 audio Clusters */
  327. bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3;
  328. bpl &= ~7; /* must be multiple of 8 */
  329. if (bpl > AUDIO_LINE_SIZE)
  330. bpl = AUDIO_LINE_SIZE;
  331. runtime->hw.period_bytes_min = bpl;
  332. runtime->hw.period_bytes_max = bpl;
  333. }
  334. return 0;
  335. _error:
  336. dprintk(1, "Error opening PCM!\n");
  337. return err;
  338. }
  339. /*
  340. * audio close callback
  341. */
  342. static int snd_cx25821_close(struct snd_pcm_substream *substream)
  343. {
  344. return 0;
  345. }
  346. /*
  347. * hw_params callback
  348. */
  349. static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
  350. struct snd_pcm_hw_params *hw_params)
  351. {
  352. struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
  353. struct videobuf_dmabuf *dma;
  354. struct cx25821_audio_buffer *buf;
  355. int ret;
  356. if (substream->runtime->dma_area) {
  357. dsp_buffer_free(chip);
  358. substream->runtime->dma_area = NULL;
  359. }
  360. chip->period_size = params_period_bytes(hw_params);
  361. chip->num_periods = params_periods(hw_params);
  362. chip->dma_size = chip->period_size * params_periods(hw_params);
  363. BUG_ON(!chip->dma_size);
  364. BUG_ON(chip->num_periods & (chip->num_periods - 1));
  365. buf = kzalloc(sizeof(*buf), GFP_KERNEL);
  366. if (NULL == buf)
  367. return -ENOMEM;
  368. if (chip->period_size > AUDIO_LINE_SIZE)
  369. chip->period_size = AUDIO_LINE_SIZE;
  370. buf->bpl = chip->period_size;
  371. dma = &buf->dma;
  372. videobuf_dma_init(dma);
  373. ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
  374. (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
  375. if (ret < 0)
  376. goto error;
  377. ret = videobuf_dma_map(&chip->pci->dev, dma);
  378. if (ret < 0)
  379. goto error;
  380. ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist,
  381. chip->period_size, chip->num_periods, 1);
  382. if (ret < 0) {
  383. pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
  384. goto error;
  385. }
  386. /* Loop back to start of program */
  387. buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
  388. buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  389. buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
  390. chip->buf = buf;
  391. chip->dma_risc = dma;
  392. substream->runtime->dma_area = chip->dma_risc->vaddr;
  393. substream->runtime->dma_bytes = chip->dma_size;
  394. substream->runtime->dma_addr = 0;
  395. return 0;
  396. error:
  397. kfree(buf);
  398. return ret;
  399. }
  400. /*
  401. * hw free callback
  402. */
  403. static int snd_cx25821_hw_free(struct snd_pcm_substream *substream)
  404. {
  405. struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
  406. if (substream->runtime->dma_area) {
  407. dsp_buffer_free(chip);
  408. substream->runtime->dma_area = NULL;
  409. }
  410. return 0;
  411. }
  412. /*
  413. * prepare callback
  414. */
  415. static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
  416. {
  417. return 0;
  418. }
  419. /*
  420. * trigger callback
  421. */
  422. static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream,
  423. int cmd)
  424. {
  425. struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
  426. int err = 0;
  427. /* Local interrupts are already disabled by ALSA */
  428. spin_lock(&chip->reg_lock);
  429. switch (cmd) {
  430. case SNDRV_PCM_TRIGGER_START:
  431. err = _cx25821_start_audio_dma(chip);
  432. break;
  433. case SNDRV_PCM_TRIGGER_STOP:
  434. err = _cx25821_stop_audio_dma(chip);
  435. break;
  436. default:
  437. err = -EINVAL;
  438. break;
  439. }
  440. spin_unlock(&chip->reg_lock);
  441. return err;
  442. }
  443. /*
  444. * pointer callback
  445. */
  446. static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream
  447. *substream)
  448. {
  449. struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
  450. struct snd_pcm_runtime *runtime = substream->runtime;
  451. u16 count;
  452. count = atomic_read(&chip->count);
  453. return runtime->period_size * (count & (runtime->periods - 1));
  454. }
  455. /*
  456. * page callback (needed for mmap)
  457. */
  458. static struct page *snd_cx25821_page(struct snd_pcm_substream *substream,
  459. unsigned long offset)
  460. {
  461. void *pageptr = substream->runtime->dma_area + offset;
  462. return vmalloc_to_page(pageptr);
  463. }
  464. /*
  465. * operators
  466. */
  467. static struct snd_pcm_ops snd_cx25821_pcm_ops = {
  468. .open = snd_cx25821_pcm_open,
  469. .close = snd_cx25821_close,
  470. .ioctl = snd_pcm_lib_ioctl,
  471. .hw_params = snd_cx25821_hw_params,
  472. .hw_free = snd_cx25821_hw_free,
  473. .prepare = snd_cx25821_prepare,
  474. .trigger = snd_cx25821_card_trigger,
  475. .pointer = snd_cx25821_pointer,
  476. .page = snd_cx25821_page,
  477. };
  478. /*
  479. * ALSA create a PCM device: Called when initializing the board.
  480. * Sets up the name and hooks up the callbacks
  481. */
  482. static int snd_cx25821_pcm(struct cx25821_audio_dev *chip, int device,
  483. char *name)
  484. {
  485. struct snd_pcm *pcm;
  486. int err;
  487. err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
  488. if (err < 0) {
  489. pr_info("ERROR: FAILED snd_pcm_new() in %s\n", __func__);
  490. return err;
  491. }
  492. pcm->private_data = chip;
  493. pcm->info_flags = 0;
  494. strcpy(pcm->name, name);
  495. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx25821_pcm_ops);
  496. return 0;
  497. }
  498. /****************************************************************************
  499. Basic Flow for Sound Devices
  500. ****************************************************************************/
  501. /*
  502. * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
  503. * Only boards with eeprom and byte 1 at eeprom=1 have it
  504. */
  505. static DEFINE_PCI_DEVICE_TABLE(cx25821_audio_pci_tbl) = {
  506. {0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  507. {0,}
  508. };
  509. MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
  510. /*
  511. * Not used in the function snd_cx25821_dev_free so removing
  512. * from the file.
  513. */
  514. /*
  515. static int snd_cx25821_free(struct cx25821_audio_dev *chip)
  516. {
  517. if (chip->irq >= 0)
  518. free_irq(chip->irq, chip);
  519. cx25821_dev_unregister(chip->dev);
  520. pci_disable_device(chip->pci);
  521. return 0;
  522. }
  523. */
  524. /*
  525. * Component Destructor
  526. */
  527. static void snd_cx25821_dev_free(struct snd_card *card)
  528. {
  529. struct cx25821_audio_dev *chip = card->private_data;
  530. /* snd_cx25821_free(chip); */
  531. snd_card_free(chip->card);
  532. }
  533. /*
  534. * Alsa Constructor - Component probe
  535. */
  536. static int cx25821_audio_initdev(struct cx25821_dev *dev)
  537. {
  538. struct snd_card *card;
  539. struct cx25821_audio_dev *chip;
  540. int err;
  541. if (devno >= SNDRV_CARDS) {
  542. pr_info("DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__);
  543. return -ENODEV;
  544. }
  545. if (!enable[devno]) {
  546. ++devno;
  547. pr_info("DEBUG ERROR: !enable[devno] %s\n", __func__);
  548. return -ENOENT;
  549. }
  550. err = snd_card_create(index[devno], id[devno], THIS_MODULE,
  551. sizeof(struct cx25821_audio_dev), &card);
  552. if (err < 0) {
  553. pr_info("DEBUG ERROR: cannot create snd_card_new in %s\n",
  554. __func__);
  555. return err;
  556. }
  557. strcpy(card->driver, "cx25821");
  558. /* Card "creation" */
  559. card->private_free = snd_cx25821_dev_free;
  560. chip = card->private_data;
  561. spin_lock_init(&chip->reg_lock);
  562. chip->dev = dev;
  563. chip->card = card;
  564. chip->pci = dev->pci;
  565. chip->iobase = pci_resource_start(dev->pci, 0);
  566. chip->irq = dev->pci->irq;
  567. err = request_irq(dev->pci->irq, cx25821_irq,
  568. IRQF_SHARED, chip->dev->name, chip);
  569. if (err < 0) {
  570. pr_err("ERROR %s: can't get IRQ %d for ALSA\n", chip->dev->name,
  571. dev->pci->irq);
  572. goto error;
  573. }
  574. err = snd_cx25821_pcm(chip, 0, "cx25821 Digital");
  575. if (err < 0) {
  576. pr_info("DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
  577. __func__);
  578. goto error;
  579. }
  580. snd_card_set_dev(card, &chip->pci->dev);
  581. strcpy(card->shortname, "cx25821");
  582. sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name,
  583. chip->iobase, chip->irq);
  584. strcpy(card->mixername, "CX25821");
  585. pr_info("%s/%i: ALSA support for cx25821 boards\n", card->driver,
  586. devno);
  587. err = snd_card_register(card);
  588. if (err < 0) {
  589. pr_info("DEBUG ERROR: cannot register sound card %s\n",
  590. __func__);
  591. goto error;
  592. }
  593. snd_cx25821_cards[devno] = card;
  594. devno++;
  595. return 0;
  596. error:
  597. snd_card_free(card);
  598. return err;
  599. }
  600. /****************************************************************************
  601. LINUX MODULE INIT
  602. ****************************************************************************/
  603. static void cx25821_audio_fini(void)
  604. {
  605. snd_card_free(snd_cx25821_cards[0]);
  606. }
  607. /*
  608. * Module initializer
  609. *
  610. * Loops through present saa7134 cards, and assigns an ALSA device
  611. * to each one
  612. *
  613. */
  614. static int cx25821_alsa_init(void)
  615. {
  616. struct cx25821_dev *dev = NULL;
  617. struct list_head *list;
  618. mutex_lock(&cx25821_devlist_mutex);
  619. list_for_each(list, &cx25821_devlist) {
  620. dev = list_entry(list, struct cx25821_dev, devlist);
  621. cx25821_audio_initdev(dev);
  622. }
  623. mutex_unlock(&cx25821_devlist_mutex);
  624. if (dev == NULL)
  625. pr_info("ERROR ALSA: no cx25821 cards found\n");
  626. return 0;
  627. }
  628. late_initcall(cx25821_alsa_init);
  629. module_exit(cx25821_audio_fini);
  630. /* ----------------------------------------------------------- */
  631. /*
  632. * Local variables:
  633. * c-basic-offset: 8
  634. * End:
  635. */