cx88-alsa.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. *
  3. * Support for audio capture
  4. * PCI function #1 of the cx2388x.
  5. *
  6. * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org>
  7. * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
  8. * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org>
  9. * Based on dummy.c by Jaroslav Kysela <perex@suse.cz>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/device.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/dma-mapping.h>
  30. #include <asm/delay.h>
  31. #include <sound/driver.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 "cx88.h"
  38. #include "cx88-reg.h"
  39. #define dprintk(level,fmt, arg...) if (debug >= level) \
  40. printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg)
  41. #define dprintk_core(level,fmt, arg...) if (debug >= level) \
  42. printk(KERN_DEBUG "%s/1: " fmt, chip->core->name , ## arg)
  43. /****************************************************************************
  44. Data type declarations - Can be moded to a header file later
  45. ****************************************************************************/
  46. /* These can be replaced after done */
  47. #define MIXER_ADDR_LAST MAX_CX88_INPUT
  48. struct cx88_audio_dev {
  49. struct cx88_core *core;
  50. struct cx88_dmaqueue q;
  51. /* pci i/o */
  52. struct pci_dev *pci;
  53. unsigned char pci_rev,pci_lat;
  54. /* audio controls */
  55. int irq;
  56. struct snd_card *card;
  57. spinlock_t reg_lock;
  58. unsigned int dma_size;
  59. unsigned int period_size;
  60. unsigned int num_periods;
  61. struct videobuf_dmabuf dma_risc;
  62. int mixer_volume[MIXER_ADDR_LAST+1][2];
  63. int capture_source[MIXER_ADDR_LAST+1][2];
  64. long int read_count;
  65. long int read_offset;
  66. struct cx88_buffer *buf;
  67. long opened;
  68. struct snd_pcm_substream *substream;
  69. };
  70. typedef struct cx88_audio_dev snd_cx88_card_t;
  71. /****************************************************************************
  72. Module global static vars
  73. ****************************************************************************/
  74. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  75. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  76. static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
  77. static struct snd_card *snd_cx88_cards[SNDRV_CARDS];
  78. module_param_array(enable, bool, NULL, 0444);
  79. MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled.");
  80. module_param_array(index, int, NULL, 0444);
  81. MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s).");
  82. /****************************************************************************
  83. Module macros
  84. ****************************************************************************/
  85. MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards");
  86. MODULE_AUTHOR("Ricardo Cerqueira");
  87. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  88. MODULE_LICENSE("GPL");
  89. MODULE_SUPPORTED_DEVICE("{{Conexant,23881},"
  90. "{{Conexant,23882},"
  91. "{{Conexant,23883}");
  92. static unsigned int debug;
  93. module_param(debug,int,0644);
  94. MODULE_PARM_DESC(debug,"enable debug messages");
  95. /****************************************************************************
  96. Module specific funtions
  97. ****************************************************************************/
  98. /*
  99. * BOARD Specific: Sets audio DMA
  100. */
  101. static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
  102. {
  103. struct cx88_buffer *buf = chip->buf;
  104. struct cx88_core *core=chip->core;
  105. struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25];
  106. /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
  107. cx_clear(MO_AUD_DMACNTRL, 0x11);
  108. /* setup fifo + format - out channel */
  109. cx88_sram_channel_setup(chip->core, audio_ch, buf->bpl, buf->risc.dma);
  110. /* sets bpl size */
  111. cx_write(MO_AUDD_LNGTH, buf->bpl);
  112. /* reset counter */
  113. cx_write(MO_AUDD_GPCNTRL,GP_COUNT_CONTROL_RESET);
  114. dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d lines/irq, "
  115. "%d B/irq\n", buf->bpl, cx_read(audio_ch->cmds_start + 8)>>1,
  116. chip->num_periods, buf->bpl * chip->num_periods);
  117. dprintk(1, "Enabling IRQ, setting mask from 0x%x to 0x%x\n",
  118. chip->core->pci_irqmask,
  119. chip->core->pci_irqmask | PCI_INT_AUDINT);
  120. /* Enables corresponding bits at AUD_INT_STAT */
  121. cx_write(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
  122. AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
  123. /* Clean any pending interrupt bits already set */
  124. cx_write(MO_AUD_INTSTAT, ~0);
  125. /* enable audio irqs */
  126. cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT);
  127. /* start dma */
  128. cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */
  129. cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */
  130. if (debug)
  131. cx88_sram_channel_dump(chip->core, audio_ch);
  132. return 0;
  133. }
  134. /*
  135. * BOARD Specific: Resets audio DMA
  136. */
  137. static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
  138. {
  139. struct cx88_core *core=chip->core;
  140. dprintk(1, "Stopping audio DMA\n");
  141. /* stop dma */
  142. cx_clear(MO_AUD_DMACNTRL, 0x11);
  143. /* disable irqs */
  144. cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
  145. cx_clear(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
  146. AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
  147. if (debug)
  148. cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]);
  149. return 0;
  150. }
  151. #define MAX_IRQ_LOOP 10
  152. /*
  153. * BOARD Specific: IRQ dma bits
  154. */
  155. static char *cx88_aud_irqs[32] = {
  156. "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
  157. NULL, /* reserved */
  158. "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
  159. NULL, /* reserved */
  160. "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
  161. NULL, /* reserved */
  162. "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
  163. NULL, /* reserved */
  164. "opc_err", "par_err", "rip_err", /* 16-18 */
  165. "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
  166. };
  167. /*
  168. * BOARD Specific: Threats IRQ audio specific calls
  169. */
  170. static void cx8801_aud_irq(snd_cx88_card_t *chip)
  171. {
  172. struct cx88_core *core = chip->core;
  173. u32 status, mask;
  174. u32 count;
  175. status = cx_read(MO_AUD_INTSTAT);
  176. mask = cx_read(MO_AUD_INTMSK);
  177. if (0 == (status & mask)) {
  178. spin_unlock(&chip->reg_lock);
  179. return;
  180. }
  181. cx_write(MO_AUD_INTSTAT, status);
  182. if (debug > 1 || (status & mask & ~0xff))
  183. cx88_print_irqbits(core->name, "irq aud",
  184. cx88_aud_irqs, ARRAY_SIZE(cx88_aud_irqs),
  185. status, mask);
  186. /* risc op code error */
  187. if (status & AUD_INT_OPC_ERR) {
  188. printk(KERN_WARNING "%s/0: audio risc op code error\n",core->name);
  189. cx_clear(MO_AUD_DMACNTRL, 0x11);
  190. cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH25]);
  191. }
  192. /* risc1 downstream */
  193. if (status & AUD_INT_DN_RISCI1) {
  194. spin_lock(&chip->reg_lock);
  195. count = cx_read(MO_AUDD_GPCNT);
  196. spin_unlock(&chip->reg_lock);
  197. if (chip->read_count == 0)
  198. chip->read_count += chip->dma_size;
  199. }
  200. if (chip->read_count >= chip->period_size) {
  201. dprintk(2, "Elapsing period\n");
  202. snd_pcm_period_elapsed(chip->substream);
  203. }
  204. dprintk(3,"Leaving audio IRQ handler...\n");
  205. /* FIXME: Any other status should deserve a special handling? */
  206. }
  207. /*
  208. * BOARD Specific: Handles IRQ calls
  209. */
  210. static irqreturn_t cx8801_irq(int irq, void *dev_id)
  211. {
  212. snd_cx88_card_t *chip = dev_id;
  213. struct cx88_core *core = chip->core;
  214. u32 status;
  215. int loop, handled = 0;
  216. for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
  217. status = cx_read(MO_PCI_INTSTAT) &
  218. (core->pci_irqmask | PCI_INT_AUDINT);
  219. if (0 == status)
  220. goto out;
  221. dprintk( 3, "cx8801_irq\n" );
  222. dprintk( 3, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
  223. dprintk( 3, " status: %d\n", status );
  224. handled = 1;
  225. cx_write(MO_PCI_INTSTAT, status);
  226. if (status & core->pci_irqmask)
  227. cx88_core_irq(core, status);
  228. if (status & PCI_INT_AUDINT) {
  229. dprintk( 2, " ALSA IRQ handling\n" );
  230. cx8801_aud_irq(chip);
  231. }
  232. };
  233. if (MAX_IRQ_LOOP == loop) {
  234. dprintk( 0, "clearing mask\n" );
  235. dprintk(1,"%s/0: irq loop -- clearing mask\n",
  236. core->name);
  237. cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
  238. }
  239. out:
  240. return IRQ_RETVAL(handled);
  241. }
  242. static int dsp_buffer_free(snd_cx88_card_t *chip)
  243. {
  244. BUG_ON(!chip->dma_size);
  245. dprintk(2,"Freeing buffer\n");
  246. videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc);
  247. videobuf_dma_free(&chip->dma_risc);
  248. btcx_riscmem_free(chip->pci,&chip->buf->risc);
  249. kfree(chip->buf);
  250. chip->dma_size = 0;
  251. return 0;
  252. }
  253. /****************************************************************************
  254. ALSA PCM Interface
  255. ****************************************************************************/
  256. /*
  257. * Digital hardware definition
  258. */
  259. static struct snd_pcm_hardware snd_cx88_digital_hw = {
  260. .info = SNDRV_PCM_INFO_MMAP |
  261. SNDRV_PCM_INFO_INTERLEAVED |
  262. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  263. SNDRV_PCM_INFO_MMAP_VALID,
  264. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  265. .rates = SNDRV_PCM_RATE_48000,
  266. .rate_min = 48000,
  267. .rate_max = 48000,
  268. .channels_min = 2,
  269. .channels_max = 2,
  270. .buffer_bytes_max = (2*2048),
  271. .period_bytes_min = 2048,
  272. .period_bytes_max = 2048,
  273. .periods_min = 2,
  274. .periods_max = 2,
  275. };
  276. /*
  277. * audio pcm capture runtime free
  278. */
  279. static void snd_card_cx88_runtime_free(struct snd_pcm_runtime *runtime)
  280. {
  281. }
  282. /*
  283. * audio pcm capture open callback
  284. */
  285. static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
  286. {
  287. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  288. struct snd_pcm_runtime *runtime = substream->runtime;
  289. int err;
  290. if (test_and_set_bit(0, &chip->opened))
  291. return -EBUSY;
  292. err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  293. if (err < 0)
  294. goto _error;
  295. chip->substream = substream;
  296. chip->read_count = 0;
  297. chip->read_offset = 0;
  298. runtime->private_free = snd_card_cx88_runtime_free;
  299. runtime->hw = snd_cx88_digital_hw;
  300. return 0;
  301. _error:
  302. dprintk(1,"Error opening PCM!\n");
  303. clear_bit(0, &chip->opened);
  304. smp_mb__after_clear_bit();
  305. return err;
  306. }
  307. /*
  308. * audio close callback
  309. */
  310. static int snd_cx88_close(struct snd_pcm_substream *substream)
  311. {
  312. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  313. clear_bit(0, &chip->opened);
  314. smp_mb__after_clear_bit();
  315. return 0;
  316. }
  317. /*
  318. * hw_params callback
  319. */
  320. static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
  321. struct snd_pcm_hw_params * hw_params)
  322. {
  323. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  324. struct cx88_buffer *buf;
  325. if (substream->runtime->dma_area) {
  326. dsp_buffer_free(chip);
  327. substream->runtime->dma_area = NULL;
  328. }
  329. chip->period_size = params_period_bytes(hw_params);
  330. chip->num_periods = params_periods(hw_params);
  331. chip->dma_size = chip->period_size * params_periods(hw_params);
  332. BUG_ON(!chip->dma_size);
  333. dprintk(1,"Setting buffer\n");
  334. buf = kzalloc(sizeof(*buf),GFP_KERNEL);
  335. if (NULL == buf)
  336. return -ENOMEM;
  337. buf->vb.memory = V4L2_MEMORY_MMAP;
  338. buf->vb.width = chip->period_size;
  339. buf->vb.height = chip->num_periods;
  340. buf->vb.size = chip->dma_size;
  341. buf->vb.field = V4L2_FIELD_NONE;
  342. videobuf_dma_init(&buf->vb.dma);
  343. videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE,
  344. (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
  345. videobuf_pci_dma_map(chip->pci,&buf->vb.dma);
  346. cx88_risc_databuffer(chip->pci, &buf->risc,
  347. buf->vb.dma.sglist,
  348. buf->vb.width, buf->vb.height);
  349. buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
  350. buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  351. buf->vb.state = STATE_PREPARED;
  352. buf->bpl = chip->period_size;
  353. chip->buf = buf;
  354. chip->dma_risc = buf->vb.dma;
  355. dprintk(1,"Buffer ready at %u\n",chip->dma_risc.nr_pages);
  356. substream->runtime->dma_area = chip->dma_risc.vmalloc;
  357. return 0;
  358. }
  359. /*
  360. * hw free callback
  361. */
  362. static int snd_cx88_hw_free(struct snd_pcm_substream * substream)
  363. {
  364. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  365. if (substream->runtime->dma_area) {
  366. dsp_buffer_free(chip);
  367. substream->runtime->dma_area = NULL;
  368. }
  369. return 0;
  370. }
  371. /*
  372. * prepare callback
  373. */
  374. static int snd_cx88_prepare(struct snd_pcm_substream *substream)
  375. {
  376. return 0;
  377. }
  378. /*
  379. * trigger callback
  380. */
  381. static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
  382. {
  383. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  384. int err;
  385. spin_lock(&chip->reg_lock);
  386. switch (cmd) {
  387. case SNDRV_PCM_TRIGGER_START:
  388. err=_cx88_start_audio_dma(chip);
  389. break;
  390. case SNDRV_PCM_TRIGGER_STOP:
  391. err=_cx88_stop_audio_dma(chip);
  392. break;
  393. default:
  394. err=-EINVAL;
  395. break;
  396. }
  397. spin_unlock(&chip->reg_lock);
  398. return err;
  399. }
  400. /*
  401. * pointer callback
  402. */
  403. static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
  404. {
  405. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  406. struct snd_pcm_runtime *runtime = substream->runtime;
  407. if (chip->read_count) {
  408. chip->read_count -= snd_pcm_lib_period_bytes(substream);
  409. chip->read_offset += snd_pcm_lib_period_bytes(substream);
  410. if (chip->read_offset == chip->dma_size)
  411. chip->read_offset = 0;
  412. }
  413. dprintk(2, "Pointer time, will return %li, read %li\n",chip->read_offset,chip->read_count);
  414. return bytes_to_frames(runtime, chip->read_offset);
  415. }
  416. /*
  417. * operators
  418. */
  419. static struct snd_pcm_ops snd_cx88_pcm_ops = {
  420. .open = snd_cx88_pcm_open,
  421. .close = snd_cx88_close,
  422. .ioctl = snd_pcm_lib_ioctl,
  423. .hw_params = snd_cx88_hw_params,
  424. .hw_free = snd_cx88_hw_free,
  425. .prepare = snd_cx88_prepare,
  426. .trigger = snd_cx88_card_trigger,
  427. .pointer = snd_cx88_pointer,
  428. };
  429. /*
  430. * create a PCM device
  431. */
  432. static int __devinit snd_cx88_pcm(snd_cx88_card_t *chip, int device, char *name)
  433. {
  434. int err;
  435. struct snd_pcm *pcm;
  436. err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
  437. if (err < 0)
  438. return err;
  439. pcm->private_data = chip;
  440. strcpy(pcm->name, name);
  441. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx88_pcm_ops);
  442. return 0;
  443. }
  444. /****************************************************************************
  445. CONTROL INTERFACE
  446. ****************************************************************************/
  447. static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
  448. struct snd_ctl_elem_info *info)
  449. {
  450. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  451. info->count = 1;
  452. info->value.integer.min = 0;
  453. info->value.integer.max = 0x3f;
  454. return 0;
  455. }
  456. /* OK - TODO: test it */
  457. static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
  458. struct snd_ctl_elem_value *value)
  459. {
  460. snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
  461. struct cx88_core *core=chip->core;
  462. value->value.integer.value[0] = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
  463. return 0;
  464. }
  465. /* OK - TODO: test it */
  466. static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
  467. struct snd_ctl_elem_value *value)
  468. {
  469. snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
  470. struct cx88_core *core=chip->core;
  471. int v;
  472. u32 old_control;
  473. spin_lock_irq(&chip->reg_lock);
  474. old_control = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
  475. v = 0x3f - (value->value.integer.value[0] & 0x3f);
  476. cx_andor(AUD_VOL_CTL, 0x3f, v);
  477. spin_unlock_irq(&chip->reg_lock);
  478. return v != old_control;
  479. }
  480. static struct snd_kcontrol_new snd_cx88_capture_volume = {
  481. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  482. .name = "Capture Volume",
  483. .info = snd_cx88_capture_volume_info,
  484. .get = snd_cx88_capture_volume_get,
  485. .put = snd_cx88_capture_volume_put,
  486. };
  487. /****************************************************************************
  488. Basic Flow for Sound Devices
  489. ****************************************************************************/
  490. /*
  491. * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
  492. * Only boards with eeprom and byte 1 at eeprom=1 have it
  493. */
  494. static struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
  495. {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
  496. {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
  497. {0, }
  498. };
  499. MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
  500. /*
  501. * Chip-specific destructor
  502. */
  503. static int snd_cx88_free(snd_cx88_card_t *chip)
  504. {
  505. if (chip->irq >= 0){
  506. synchronize_irq(chip->irq);
  507. free_irq(chip->irq, chip);
  508. }
  509. cx88_core_put(chip->core,chip->pci);
  510. pci_disable_device(chip->pci);
  511. return 0;
  512. }
  513. /*
  514. * Component Destructor
  515. */
  516. static void snd_cx88_dev_free(struct snd_card * card)
  517. {
  518. snd_cx88_card_t *chip = card->private_data;
  519. snd_cx88_free(chip);
  520. }
  521. /*
  522. * Alsa Constructor - Component probe
  523. */
  524. static int devno;
  525. static int __devinit snd_cx88_create(struct snd_card *card,
  526. struct pci_dev *pci,
  527. snd_cx88_card_t **rchip)
  528. {
  529. snd_cx88_card_t *chip;
  530. struct cx88_core *core;
  531. int err;
  532. *rchip = NULL;
  533. err = pci_enable_device(pci);
  534. if (err < 0)
  535. return err;
  536. pci_set_master(pci);
  537. chip = (snd_cx88_card_t *) card->private_data;
  538. core = cx88_core_get(pci);
  539. if (NULL == core) {
  540. err = -EINVAL;
  541. kfree (chip);
  542. return err;
  543. }
  544. if (!pci_dma_supported(pci,DMA_32BIT_MASK)) {
  545. dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name);
  546. err = -EIO;
  547. cx88_core_put(core,pci);
  548. return err;
  549. }
  550. /* pci init */
  551. chip->card = card;
  552. chip->pci = pci;
  553. chip->irq = -1;
  554. spin_lock_init(&chip->reg_lock);
  555. chip->core = core;
  556. /* get irq */
  557. err = request_irq(chip->pci->irq, cx8801_irq,
  558. IRQF_SHARED | IRQF_DISABLED, chip->core->name, chip);
  559. if (err < 0) {
  560. dprintk(0, "%s: can't get IRQ %d\n",
  561. chip->core->name, chip->pci->irq);
  562. return err;
  563. }
  564. /* print pci info */
  565. pci_read_config_byte(pci, PCI_CLASS_REVISION, &chip->pci_rev);
  566. pci_read_config_byte(pci, PCI_LATENCY_TIMER, &chip->pci_lat);
  567. dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, "
  568. "latency: %d, mmio: 0x%llx\n", core->name, devno,
  569. pci_name(pci), chip->pci_rev, pci->irq,
  570. chip->pci_lat,(unsigned long long)pci_resource_start(pci,0));
  571. chip->irq = pci->irq;
  572. synchronize_irq(chip->irq);
  573. snd_card_set_dev(card, &pci->dev);
  574. *rchip = chip;
  575. return 0;
  576. }
  577. static int __devinit cx88_audio_initdev(struct pci_dev *pci,
  578. const struct pci_device_id *pci_id)
  579. {
  580. struct snd_card *card;
  581. snd_cx88_card_t *chip;
  582. int err;
  583. if (devno >= SNDRV_CARDS)
  584. return (-ENODEV);
  585. if (!enable[devno]) {
  586. ++devno;
  587. return (-ENOENT);
  588. }
  589. card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx88_card_t));
  590. if (!card)
  591. return (-ENOMEM);
  592. card->private_free = snd_cx88_dev_free;
  593. err = snd_cx88_create(card, pci, &chip);
  594. if (err < 0)
  595. return (err);
  596. err = snd_cx88_pcm(chip, 0, "CX88 Digital");
  597. if (err < 0) {
  598. snd_card_free(card);
  599. return (err);
  600. }
  601. err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip));
  602. if (err < 0) {
  603. snd_card_free(card);
  604. return (err);
  605. }
  606. strcpy (card->driver, "CX88x");
  607. sprintf(card->shortname, "Conexant CX%x", pci->device);
  608. sprintf(card->longname, "%s at %#llx",
  609. card->shortname,(unsigned long long)pci_resource_start(pci, 0));
  610. strcpy (card->mixername, "CX88");
  611. dprintk (0, "%s/%i: ALSA support for cx2388x boards\n",
  612. card->driver,devno);
  613. err = snd_card_register(card);
  614. if (err < 0) {
  615. snd_card_free(card);
  616. return (err);
  617. }
  618. snd_cx88_cards[devno] = card;
  619. pci_set_drvdata(pci,card);
  620. devno++;
  621. return 0;
  622. }
  623. /*
  624. * ALSA destructor
  625. */
  626. static void __devexit cx88_audio_finidev(struct pci_dev *pci)
  627. {
  628. struct cx88_audio_dev *card = pci_get_drvdata(pci);
  629. snd_card_free((void *)card);
  630. pci_set_drvdata(pci, NULL);
  631. devno--;
  632. }
  633. /*
  634. * PCI driver definition
  635. */
  636. static struct pci_driver cx88_audio_pci_driver = {
  637. .name = "cx88_audio",
  638. .id_table = cx88_audio_pci_tbl,
  639. .probe = cx88_audio_initdev,
  640. .remove = cx88_audio_finidev,
  641. };
  642. /****************************************************************************
  643. LINUX MODULE INIT
  644. ****************************************************************************/
  645. /*
  646. * module init
  647. */
  648. static int cx88_audio_init(void)
  649. {
  650. printk(KERN_INFO "cx2388x alsa driver version %d.%d.%d loaded\n",
  651. (CX88_VERSION_CODE >> 16) & 0xff,
  652. (CX88_VERSION_CODE >> 8) & 0xff,
  653. CX88_VERSION_CODE & 0xff);
  654. #ifdef SNAPSHOT
  655. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  656. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  657. #endif
  658. return pci_register_driver(&cx88_audio_pci_driver);
  659. }
  660. /*
  661. * module remove
  662. */
  663. static void cx88_audio_fini(void)
  664. {
  665. pci_unregister_driver(&cx88_audio_pci_driver);
  666. }
  667. module_init(cx88_audio_init);
  668. module_exit(cx88_audio_fini);
  669. /* ----------------------------------------------------------- */
  670. /*
  671. * Local variables:
  672. * c-basic-offset: 8
  673. * End:
  674. */