cx88-alsa.c 20 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. dprintk(1, "Starting audio DMA for %i bytes/line and %i (%i) lines at address %08x\n",buf->bpl, chip->num_periods, audio_ch->fifo_size / buf->bpl, audio_ch->fifo_start);
  107. /* setup fifo + format - out channel */
  108. cx88_sram_channel_setup(chip->core, &cx88_sram_channels[SRAM_CH25],
  109. 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, "Enabling IRQ, setting mask from 0x%x to 0x%x\n",
  115. chip->core->pci_irqmask,
  116. chip->core->pci_irqmask | PCI_INT_AUDINT);
  117. /* enable irqs */
  118. cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT);
  119. /* Enables corresponding bits at AUD_INT_STAT */
  120. cx_write(MO_AUD_INTMSK,
  121. (1<<16)|
  122. (1<<12)|
  123. (1<<4)|
  124. (1<<0)
  125. );
  126. /* start dma */
  127. cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */
  128. cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */
  129. if (debug)
  130. cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]);
  131. return 0;
  132. }
  133. /*
  134. * BOARD Specific: Resets audio DMA
  135. */
  136. static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
  137. {
  138. struct cx88_core *core=chip->core;
  139. dprintk(1, "Stopping audio DMA\n");
  140. /* stop dma */
  141. cx_clear(MO_AUD_DMACNTRL, 0x11);
  142. /* disable irqs */
  143. cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
  144. cx_clear(MO_AUD_INTMSK,
  145. (1<<16)|
  146. (1<<12)|
  147. (1<<4)|
  148. (1<<0)
  149. );
  150. if (debug)
  151. cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]);
  152. return 0;
  153. }
  154. #define MAX_IRQ_LOOP 10
  155. /*
  156. * BOARD Specific: IRQ dma bits
  157. */
  158. static char *cx88_aud_irqs[32] = {
  159. "dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
  160. NULL, /* reserved */
  161. "dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
  162. NULL, /* reserved */
  163. "dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
  164. NULL, /* reserved */
  165. "dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
  166. NULL, /* reserved */
  167. "opc_err", "par_err", "rip_err", /* 16-18 */
  168. "pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
  169. };
  170. /*
  171. * BOARD Specific: Threats IRQ audio specific calls
  172. */
  173. static void cx8801_aud_irq(snd_cx88_card_t *chip)
  174. {
  175. struct cx88_core *core = chip->core;
  176. u32 status, mask;
  177. u32 count;
  178. status = cx_read(MO_AUD_INTSTAT);
  179. mask = cx_read(MO_AUD_INTMSK);
  180. if (0 == (status & mask)) {
  181. spin_unlock(&chip->reg_lock);
  182. return;
  183. }
  184. cx_write(MO_AUD_INTSTAT, status);
  185. if (debug > 1 || (status & mask & ~0xff))
  186. cx88_print_irqbits(core->name, "irq aud",
  187. cx88_aud_irqs, ARRAY_SIZE(cx88_aud_irqs),
  188. status, mask);
  189. /* risc op code error */
  190. if (status & (1 << 16)) {
  191. printk(KERN_WARNING "%s/0: audio risc op code error\n",core->name);
  192. cx_clear(MO_AUD_DMACNTRL, 0x11);
  193. cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH25]);
  194. }
  195. /* risc1 downstream */
  196. if (status & 0x01) {
  197. spin_lock(&chip->reg_lock);
  198. count = cx_read(MO_AUDD_GPCNT);
  199. spin_unlock(&chip->reg_lock);
  200. if (chip->read_count == 0)
  201. chip->read_count += chip->dma_size;
  202. }
  203. if (chip->read_count >= chip->period_size) {
  204. dprintk(2, "Elapsing period\n");
  205. snd_pcm_period_elapsed(chip->substream);
  206. }
  207. dprintk(3,"Leaving audio IRQ handler...\n");
  208. /* FIXME: Any other status should deserve a special handling? */
  209. }
  210. /*
  211. * BOARD Specific: Handles IRQ calls
  212. */
  213. static irqreturn_t cx8801_irq(int irq, void *dev_id)
  214. {
  215. snd_cx88_card_t *chip = dev_id;
  216. struct cx88_core *core = chip->core;
  217. u32 status;
  218. int loop, handled = 0;
  219. for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
  220. status = cx_read(MO_PCI_INTSTAT) &
  221. (core->pci_irqmask | PCI_INT_AUDINT);
  222. if (0 == status)
  223. goto out;
  224. dprintk( 3, "cx8801_irq\n" );
  225. dprintk( 3, " loop: %d/%d\n", loop, MAX_IRQ_LOOP );
  226. dprintk( 3, " status: %d\n", status );
  227. handled = 1;
  228. cx_write(MO_PCI_INTSTAT, status);
  229. if (status & PCI_INT_AUDINT) {
  230. dprintk( 2, " ALSA IRQ handling\n" );
  231. cx8801_aud_irq(chip);
  232. }
  233. };
  234. if (MAX_IRQ_LOOP == loop) {
  235. dprintk( 0, "clearing mask\n" );
  236. dprintk(1,"%s/0: irq loop -- clearing mask\n",
  237. core->name);
  238. cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
  239. }
  240. out:
  241. return IRQ_RETVAL(handled);
  242. }
  243. static int dsp_buffer_free(snd_cx88_card_t *chip)
  244. {
  245. BUG_ON(!chip->dma_size);
  246. dprintk(2,"Freeing buffer\n");
  247. videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc);
  248. videobuf_dma_free(&chip->dma_risc);
  249. btcx_riscmem_free(chip->pci,&chip->buf->risc);
  250. kfree(chip->buf);
  251. chip->dma_size = 0;
  252. return 0;
  253. }
  254. /****************************************************************************
  255. ALSA PCM Interface
  256. ****************************************************************************/
  257. /*
  258. * Digital hardware definition
  259. */
  260. static struct snd_pcm_hardware snd_cx88_digital_hw = {
  261. .info = SNDRV_PCM_INFO_MMAP |
  262. SNDRV_PCM_INFO_INTERLEAVED |
  263. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  264. SNDRV_PCM_INFO_MMAP_VALID,
  265. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  266. .rates = SNDRV_PCM_RATE_48000,
  267. .rate_min = 48000,
  268. .rate_max = 48000,
  269. .channels_min = 1,
  270. .channels_max = 2,
  271. .buffer_bytes_max = (2*2048),
  272. .period_bytes_min = 2048,
  273. .period_bytes_max = 2048,
  274. .periods_min = 2,
  275. .periods_max = 2,
  276. };
  277. /*
  278. * audio pcm capture runtime free
  279. */
  280. static void snd_card_cx88_runtime_free(struct snd_pcm_runtime *runtime)
  281. {
  282. }
  283. /*
  284. * audio pcm capture open callback
  285. */
  286. static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
  287. {
  288. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  289. struct snd_pcm_runtime *runtime = substream->runtime;
  290. int err;
  291. if (test_and_set_bit(0, &chip->opened))
  292. return -EBUSY;
  293. err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  294. if (err < 0)
  295. goto _error;
  296. chip->substream = substream;
  297. chip->read_count = 0;
  298. chip->read_offset = 0;
  299. runtime->private_free = snd_card_cx88_runtime_free;
  300. runtime->hw = snd_cx88_digital_hw;
  301. return 0;
  302. _error:
  303. dprintk(1,"Error opening PCM!\n");
  304. clear_bit(0, &chip->opened);
  305. smp_mb__after_clear_bit();
  306. return err;
  307. }
  308. /*
  309. * audio close callback
  310. */
  311. static int snd_cx88_close(struct snd_pcm_substream *substream)
  312. {
  313. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  314. clear_bit(0, &chip->opened);
  315. smp_mb__after_clear_bit();
  316. return 0;
  317. }
  318. /*
  319. * hw_params callback
  320. */
  321. static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
  322. struct snd_pcm_hw_params * hw_params)
  323. {
  324. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  325. struct cx88_buffer *buf;
  326. if (substream->runtime->dma_area) {
  327. dsp_buffer_free(chip);
  328. substream->runtime->dma_area = NULL;
  329. }
  330. chip->period_size = params_period_bytes(hw_params);
  331. chip->num_periods = params_periods(hw_params);
  332. chip->dma_size = chip->period_size * params_periods(hw_params);
  333. BUG_ON(!chip->dma_size);
  334. dprintk(1,"Setting buffer\n");
  335. buf = kzalloc(sizeof(*buf),GFP_KERNEL);
  336. if (NULL == buf)
  337. return -ENOMEM;
  338. buf->vb.memory = V4L2_MEMORY_MMAP;
  339. buf->vb.width = chip->period_size;
  340. buf->vb.height = chip->num_periods;
  341. buf->vb.size = chip->dma_size;
  342. buf->vb.field = V4L2_FIELD_NONE;
  343. videobuf_dma_init(&buf->vb.dma);
  344. videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE,
  345. (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
  346. videobuf_pci_dma_map(chip->pci,&buf->vb.dma);
  347. cx88_risc_databuffer(chip->pci, &buf->risc,
  348. buf->vb.dma.sglist,
  349. buf->vb.width, buf->vb.height);
  350. buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
  351. buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
  352. buf->vb.state = STATE_PREPARED;
  353. buf->bpl = chip->period_size;
  354. chip->buf = buf;
  355. chip->dma_risc = buf->vb.dma;
  356. dprintk(1,"Buffer ready at %u\n",chip->dma_risc.nr_pages);
  357. substream->runtime->dma_area = chip->dma_risc.vmalloc;
  358. return 0;
  359. }
  360. /*
  361. * hw free callback
  362. */
  363. static int snd_cx88_hw_free(struct snd_pcm_substream * substream)
  364. {
  365. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  366. if (substream->runtime->dma_area) {
  367. dsp_buffer_free(chip);
  368. substream->runtime->dma_area = NULL;
  369. }
  370. return 0;
  371. }
  372. /*
  373. * prepare callback
  374. */
  375. static int snd_cx88_prepare(struct snd_pcm_substream *substream)
  376. {
  377. return 0;
  378. }
  379. /*
  380. * trigger callback
  381. */
  382. static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
  383. {
  384. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  385. int err;
  386. spin_lock(&chip->reg_lock);
  387. switch (cmd) {
  388. case SNDRV_PCM_TRIGGER_START:
  389. err=_cx88_start_audio_dma(chip);
  390. break;
  391. case SNDRV_PCM_TRIGGER_STOP:
  392. err=_cx88_stop_audio_dma(chip);
  393. break;
  394. default:
  395. err=-EINVAL;
  396. break;
  397. }
  398. spin_unlock(&chip->reg_lock);
  399. return err;
  400. }
  401. /*
  402. * pointer callback
  403. */
  404. static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
  405. {
  406. snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
  407. struct snd_pcm_runtime *runtime = substream->runtime;
  408. if (chip->read_count) {
  409. chip->read_count -= snd_pcm_lib_period_bytes(substream);
  410. chip->read_offset += snd_pcm_lib_period_bytes(substream);
  411. if (chip->read_offset == chip->dma_size)
  412. chip->read_offset = 0;
  413. }
  414. dprintk(2, "Pointer time, will return %li, read %li\n",chip->read_offset,chip->read_count);
  415. return bytes_to_frames(runtime, chip->read_offset);
  416. }
  417. /*
  418. * operators
  419. */
  420. static struct snd_pcm_ops snd_cx88_pcm_ops = {
  421. .open = snd_cx88_pcm_open,
  422. .close = snd_cx88_close,
  423. .ioctl = snd_pcm_lib_ioctl,
  424. .hw_params = snd_cx88_hw_params,
  425. .hw_free = snd_cx88_hw_free,
  426. .prepare = snd_cx88_prepare,
  427. .trigger = snd_cx88_card_trigger,
  428. .pointer = snd_cx88_pointer,
  429. };
  430. /*
  431. * create a PCM device
  432. */
  433. static int __devinit snd_cx88_pcm(snd_cx88_card_t *chip, int device, char *name)
  434. {
  435. int err;
  436. struct snd_pcm *pcm;
  437. err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
  438. if (err < 0)
  439. return err;
  440. pcm->private_data = chip;
  441. strcpy(pcm->name, name);
  442. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx88_pcm_ops);
  443. return 0;
  444. }
  445. /****************************************************************************
  446. CONTROL INTERFACE
  447. ****************************************************************************/
  448. static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
  449. struct snd_ctl_elem_info *info)
  450. {
  451. info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  452. info->count = 1;
  453. info->value.integer.min = 0;
  454. info->value.integer.max = 0x3f;
  455. return 0;
  456. }
  457. /* OK - TODO: test it */
  458. static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
  459. struct snd_ctl_elem_value *value)
  460. {
  461. snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
  462. struct cx88_core *core=chip->core;
  463. value->value.integer.value[0] = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
  464. return 0;
  465. }
  466. /* OK - TODO: test it */
  467. static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
  468. struct snd_ctl_elem_value *value)
  469. {
  470. snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
  471. struct cx88_core *core=chip->core;
  472. int v;
  473. u32 old_control;
  474. spin_lock_irq(&chip->reg_lock);
  475. old_control = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f);
  476. v = 0x3f - (value->value.integer.value[0] & 0x3f);
  477. cx_andor(AUD_VOL_CTL, 0x3f, v);
  478. spin_unlock_irq(&chip->reg_lock);
  479. return v != old_control;
  480. }
  481. static struct snd_kcontrol_new snd_cx88_capture_volume = {
  482. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  483. .name = "Capture Volume",
  484. .info = snd_cx88_capture_volume_info,
  485. .get = snd_cx88_capture_volume_get,
  486. .put = snd_cx88_capture_volume_put,
  487. };
  488. /****************************************************************************
  489. Basic Flow for Sound Devices
  490. ****************************************************************************/
  491. /*
  492. * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
  493. * Only boards with eeprom and byte 1 at eeprom=1 have it
  494. */
  495. static struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
  496. {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
  497. {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
  498. {0, }
  499. };
  500. MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
  501. /*
  502. * Chip-specific destructor
  503. */
  504. static int snd_cx88_free(snd_cx88_card_t *chip)
  505. {
  506. if (chip->irq >= 0){
  507. synchronize_irq(chip->irq);
  508. free_irq(chip->irq, chip);
  509. }
  510. cx88_core_put(chip->core,chip->pci);
  511. pci_disable_device(chip->pci);
  512. return 0;
  513. }
  514. /*
  515. * Component Destructor
  516. */
  517. static void snd_cx88_dev_free(struct snd_card * card)
  518. {
  519. snd_cx88_card_t *chip = card->private_data;
  520. snd_cx88_free(chip);
  521. }
  522. /*
  523. * Alsa Constructor - Component probe
  524. */
  525. static int devno;
  526. static int __devinit snd_cx88_create(struct snd_card *card,
  527. struct pci_dev *pci,
  528. snd_cx88_card_t **rchip)
  529. {
  530. snd_cx88_card_t *chip;
  531. struct cx88_core *core;
  532. int err;
  533. *rchip = NULL;
  534. err = pci_enable_device(pci);
  535. if (err < 0)
  536. return err;
  537. pci_set_master(pci);
  538. chip = (snd_cx88_card_t *) card->private_data;
  539. core = cx88_core_get(pci);
  540. if (NULL == core) {
  541. err = -EINVAL;
  542. kfree (chip);
  543. return err;
  544. }
  545. if (!pci_dma_supported(pci,DMA_32BIT_MASK)) {
  546. dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n",core->name);
  547. err = -EIO;
  548. cx88_core_put(core,pci);
  549. return err;
  550. }
  551. /* pci init */
  552. chip->card = card;
  553. chip->pci = pci;
  554. chip->irq = -1;
  555. spin_lock_init(&chip->reg_lock);
  556. chip->core = core;
  557. /* get irq */
  558. err = request_irq(chip->pci->irq, cx8801_irq,
  559. IRQF_SHARED | IRQF_DISABLED, chip->core->name, chip);
  560. if (err < 0) {
  561. dprintk(0, "%s: can't get IRQ %d\n",
  562. chip->core->name, chip->pci->irq);
  563. return err;
  564. }
  565. /* print pci info */
  566. pci_read_config_byte(pci, PCI_CLASS_REVISION, &chip->pci_rev);
  567. pci_read_config_byte(pci, PCI_LATENCY_TIMER, &chip->pci_lat);
  568. dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, "
  569. "latency: %d, mmio: 0x%llx\n", core->name, devno,
  570. pci_name(pci), chip->pci_rev, pci->irq,
  571. chip->pci_lat,(unsigned long long)pci_resource_start(pci,0));
  572. chip->irq = pci->irq;
  573. synchronize_irq(chip->irq);
  574. snd_card_set_dev(card, &pci->dev);
  575. *rchip = chip;
  576. return 0;
  577. }
  578. static int __devinit cx88_audio_initdev(struct pci_dev *pci,
  579. const struct pci_device_id *pci_id)
  580. {
  581. struct snd_card *card;
  582. snd_cx88_card_t *chip;
  583. int err;
  584. if (devno >= SNDRV_CARDS)
  585. return (-ENODEV);
  586. if (!enable[devno]) {
  587. ++devno;
  588. return (-ENOENT);
  589. }
  590. card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx88_card_t));
  591. if (!card)
  592. return (-ENOMEM);
  593. card->private_free = snd_cx88_dev_free;
  594. err = snd_cx88_create(card, pci, &chip);
  595. if (err < 0)
  596. return (err);
  597. err = snd_cx88_pcm(chip, 0, "CX88 Digital");
  598. if (err < 0) {
  599. snd_card_free(card);
  600. return (err);
  601. }
  602. err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip));
  603. if (err < 0) {
  604. snd_card_free(card);
  605. return (err);
  606. }
  607. strcpy (card->driver, "CX88x");
  608. sprintf(card->shortname, "Conexant CX%x", pci->device);
  609. sprintf(card->longname, "%s at %#llx",
  610. card->shortname,(unsigned long long)pci_resource_start(pci, 0));
  611. strcpy (card->mixername, "CX88");
  612. dprintk (0, "%s/%i: ALSA support for cx2388x boards\n",
  613. card->driver,devno);
  614. err = snd_card_register(card);
  615. if (err < 0) {
  616. snd_card_free(card);
  617. return (err);
  618. }
  619. snd_cx88_cards[devno] = card;
  620. pci_set_drvdata(pci,card);
  621. devno++;
  622. return 0;
  623. }
  624. /*
  625. * ALSA destructor
  626. */
  627. static void __devexit cx88_audio_finidev(struct pci_dev *pci)
  628. {
  629. struct cx88_audio_dev *card = pci_get_drvdata(pci);
  630. snd_card_free((void *)card);
  631. pci_set_drvdata(pci, NULL);
  632. devno--;
  633. }
  634. /*
  635. * PCI driver definition
  636. */
  637. static struct pci_driver cx88_audio_pci_driver = {
  638. .name = "cx88_audio",
  639. .id_table = cx88_audio_pci_tbl,
  640. .probe = cx88_audio_initdev,
  641. .remove = cx88_audio_finidev,
  642. };
  643. /****************************************************************************
  644. LINUX MODULE INIT
  645. ****************************************************************************/
  646. /*
  647. * module init
  648. */
  649. static int cx88_audio_init(void)
  650. {
  651. printk(KERN_INFO "cx2388x alsa driver version %d.%d.%d loaded\n",
  652. (CX88_VERSION_CODE >> 16) & 0xff,
  653. (CX88_VERSION_CODE >> 8) & 0xff,
  654. CX88_VERSION_CODE & 0xff);
  655. #ifdef SNAPSHOT
  656. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  657. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  658. #endif
  659. return pci_register_driver(&cx88_audio_pci_driver);
  660. }
  661. /*
  662. * module remove
  663. */
  664. static void cx88_audio_fini(void)
  665. {
  666. pci_unregister_driver(&cx88_audio_pci_driver);
  667. }
  668. module_init(cx88_audio_init);
  669. module_exit(cx88_audio_fini);
  670. /* ----------------------------------------------------------- */
  671. /*
  672. * Local variables:
  673. * c-basic-offset: 8
  674. * End:
  675. */