lola.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * Support for Digigram Lola PCI-e boards
  3. *
  4. * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/delay.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/slab.h>
  27. #include <linux/pci.h>
  28. #include <sound/core.h>
  29. #include <sound/control.h>
  30. #include <sound/pcm.h>
  31. #include <sound/initval.h>
  32. #include "lola.h"
  33. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  34. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  35. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  36. module_param_array(index, int, NULL, 0444);
  37. MODULE_PARM_DESC(index, "Index value for Digigram Lola driver.");
  38. module_param_array(id, charp, NULL, 0444);
  39. MODULE_PARM_DESC(id, "ID string for Digigram Lola driver.");
  40. module_param_array(enable, bool, NULL, 0444);
  41. MODULE_PARM_DESC(enable, "Enable Digigram Lola driver.");
  42. MODULE_LICENSE("GPL");
  43. MODULE_SUPPORTED_DEVICE("{{Digigram, Lola}}");
  44. MODULE_DESCRIPTION("Digigram Lola driver");
  45. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  46. #ifdef CONFIG_SND_DEBUG_VERBOSE
  47. static int debug;
  48. module_param(debug, int, 0644);
  49. #define verbose_debug(fmt, args...) \
  50. do { if (debug > 1) printk(KERN_DEBUG SFX fmt, ##args); } while (0)
  51. #else
  52. #define verbose_debug(fmt, args...)
  53. #endif
  54. /*
  55. * pseudo-codec read/write via CORB/RIRB
  56. */
  57. static int corb_send_verb(struct lola *chip, unsigned int nid,
  58. unsigned int verb, unsigned int data,
  59. unsigned int extdata)
  60. {
  61. unsigned long flags;
  62. int ret = -EIO;
  63. chip->last_cmd_nid = nid;
  64. chip->last_verb = verb;
  65. chip->last_data = data;
  66. chip->last_extdata = extdata;
  67. data |= (nid << 20) | (verb << 8);
  68. spin_lock_irqsave(&chip->reg_lock, flags);
  69. if (chip->rirb.cmds < LOLA_CORB_ENTRIES - 1) {
  70. unsigned int wp = chip->corb.wp + 1;
  71. wp %= LOLA_CORB_ENTRIES;
  72. chip->corb.wp = wp;
  73. chip->corb.buf[wp * 2] = cpu_to_le32(data);
  74. chip->corb.buf[wp * 2 + 1] = cpu_to_le32(extdata);
  75. lola_writew(chip, BAR0, CORBWP, wp);
  76. chip->rirb.cmds++;
  77. smp_wmb();
  78. ret = 0;
  79. }
  80. spin_unlock_irqrestore(&chip->reg_lock, flags);
  81. return ret;
  82. }
  83. static void lola_queue_unsol_event(struct lola *chip, unsigned int res,
  84. unsigned int res_ex)
  85. {
  86. lola_update_ext_clock_freq(chip, res);
  87. }
  88. /* retrieve RIRB entry - called from interrupt handler */
  89. static void lola_update_rirb(struct lola *chip)
  90. {
  91. unsigned int rp, wp;
  92. u32 res, res_ex;
  93. wp = lola_readw(chip, BAR0, RIRBWP);
  94. if (wp == chip->rirb.wp)
  95. return;
  96. chip->rirb.wp = wp;
  97. while (chip->rirb.rp != wp) {
  98. chip->rirb.rp++;
  99. chip->rirb.rp %= LOLA_CORB_ENTRIES;
  100. rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
  101. res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
  102. res = le32_to_cpu(chip->rirb.buf[rp]);
  103. if (res_ex & LOLA_RIRB_EX_UNSOL_EV)
  104. lola_queue_unsol_event(chip, res, res_ex);
  105. else if (chip->rirb.cmds) {
  106. chip->res = res;
  107. chip->res_ex = res_ex;
  108. smp_wmb();
  109. chip->rirb.cmds--;
  110. }
  111. }
  112. }
  113. static int rirb_get_response(struct lola *chip, unsigned int *val,
  114. unsigned int *extval)
  115. {
  116. unsigned long timeout;
  117. timeout = jiffies + msecs_to_jiffies(1000);
  118. for (;;) {
  119. if (!chip->rirb.cmds) {
  120. *val = chip->res;
  121. if (extval)
  122. *extval = chip->res_ex;
  123. verbose_debug("get_response: %x, %x\n",
  124. chip->res, chip->res_ex);
  125. if (chip->res_ex & LOLA_RIRB_EX_ERROR) {
  126. printk(KERN_WARNING SFX "RIRB ERROR: "
  127. "NID=%x, verb=%x, data=%x, ext=%x\n",
  128. chip->last_cmd_nid,
  129. chip->last_verb, chip->last_data,
  130. chip->last_extdata);
  131. return -EIO;
  132. }
  133. return 0;
  134. }
  135. if (time_after(jiffies, timeout))
  136. break;
  137. udelay(20);
  138. cond_resched();
  139. lola_update_rirb(chip);
  140. }
  141. printk(KERN_WARNING SFX "RIRB response error\n");
  142. return -EIO;
  143. }
  144. /* aynchronous write of a codec verb with data */
  145. int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
  146. unsigned int data, unsigned int extdata)
  147. {
  148. verbose_debug("codec_write NID=%x, verb=%x, data=%x, ext=%x\n",
  149. nid, verb, data, extdata);
  150. return corb_send_verb(chip, nid, verb, data, extdata);
  151. }
  152. /* write a codec verb with data and read the returned status */
  153. int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
  154. unsigned int data, unsigned int extdata,
  155. unsigned int *val, unsigned int *extval)
  156. {
  157. int err;
  158. verbose_debug("codec_read NID=%x, verb=%x, data=%x, ext=%x\n",
  159. nid, verb, data, extdata);
  160. err = corb_send_verb(chip, nid, verb, data, extdata);
  161. if (err < 0)
  162. return err;
  163. err = rirb_get_response(chip, val, extval);
  164. return err;
  165. }
  166. /* flush all pending codec writes */
  167. int lola_codec_flush(struct lola *chip)
  168. {
  169. unsigned int tmp;
  170. return rirb_get_response(chip, &tmp, NULL);
  171. }
  172. /*
  173. * interrupt handler
  174. */
  175. static irqreturn_t lola_interrupt(int irq, void *dev_id)
  176. {
  177. struct lola *chip = dev_id;
  178. unsigned int notify_ins, notify_outs, error_ins, error_outs;
  179. int handled = 0;
  180. int i;
  181. notify_ins = notify_outs = error_ins = error_outs = 0;
  182. spin_lock(&chip->reg_lock);
  183. for (;;) {
  184. unsigned int status, in_sts, out_sts;
  185. unsigned int reg;
  186. status = lola_readl(chip, BAR1, DINTSTS);
  187. if (!status || status == -1)
  188. break;
  189. in_sts = lola_readl(chip, BAR1, DIINTSTS);
  190. out_sts = lola_readl(chip, BAR1, DOINTSTS);
  191. /* clear Input Interrupts */
  192. for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) {
  193. if (!(in_sts & (1 << i)))
  194. continue;
  195. in_sts &= ~(1 << i);
  196. reg = lola_dsd_read(chip, i, STS);
  197. if (reg & LOLA_DSD_STS_DESE) /* error */
  198. error_ins |= (1 << i);
  199. if (reg & LOLA_DSD_STS_BCIS) /* notify */
  200. notify_ins |= (1 << i);
  201. /* clear */
  202. lola_dsd_write(chip, i, STS, reg);
  203. }
  204. /* clear Output Interrupts */
  205. for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) {
  206. if (!(out_sts & (1 << i)))
  207. continue;
  208. out_sts &= ~(1 << i);
  209. reg = lola_dsd_read(chip, i + MAX_STREAM_IN_COUNT, STS);
  210. if (reg & LOLA_DSD_STS_DESE) /* error */
  211. error_outs |= (1 << i);
  212. if (reg & LOLA_DSD_STS_BCIS) /* notify */
  213. notify_outs |= (1 << i);
  214. lola_dsd_write(chip, i + MAX_STREAM_IN_COUNT, STS, reg);
  215. }
  216. if (status & LOLA_DINT_CTRL) {
  217. unsigned char rbsts; /* ring status is byte access */
  218. rbsts = lola_readb(chip, BAR0, RIRBSTS);
  219. rbsts &= LOLA_RIRB_INT_MASK;
  220. if (rbsts)
  221. lola_writeb(chip, BAR0, RIRBSTS, rbsts);
  222. rbsts = lola_readb(chip, BAR0, CORBSTS);
  223. rbsts &= LOLA_CORB_INT_MASK;
  224. if (rbsts)
  225. lola_writeb(chip, BAR0, CORBSTS, rbsts);
  226. lola_update_rirb(chip);
  227. }
  228. if (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)) {
  229. /* clear global fifo error interrupt */
  230. lola_writel(chip, BAR1, DINTSTS,
  231. (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)));
  232. }
  233. handled = 1;
  234. }
  235. spin_unlock(&chip->reg_lock);
  236. lola_pcm_update(chip, &chip->pcm[CAPT], notify_ins);
  237. lola_pcm_update(chip, &chip->pcm[PLAY], notify_outs);
  238. return IRQ_RETVAL(handled);
  239. }
  240. /*
  241. * controller
  242. */
  243. static int reset_controller(struct lola *chip)
  244. {
  245. unsigned int gctl = lola_readl(chip, BAR0, GCTL);
  246. unsigned long end_time;
  247. if (gctl) {
  248. /* to be sure */
  249. lola_writel(chip, BAR1, BOARD_MODE, 0);
  250. return 0;
  251. }
  252. chip->cold_reset = 1;
  253. lola_writel(chip, BAR0, GCTL, LOLA_GCTL_RESET);
  254. end_time = jiffies + msecs_to_jiffies(200);
  255. do {
  256. msleep(1);
  257. gctl = lola_readl(chip, BAR0, GCTL);
  258. if (gctl)
  259. break;
  260. } while (time_before(jiffies, end_time));
  261. if (!gctl) {
  262. printk(KERN_ERR SFX "cannot reset controller\n");
  263. return -EIO;
  264. }
  265. return 0;
  266. }
  267. static void lola_irq_enable(struct lola *chip)
  268. {
  269. unsigned int val;
  270. /* enalbe all I/O streams */
  271. val = (1 << chip->pcm[PLAY].num_streams) - 1;
  272. lola_writel(chip, BAR1, DOINTCTL, val);
  273. val = (1 << chip->pcm[CAPT].num_streams) - 1;
  274. lola_writel(chip, BAR1, DIINTCTL, val);
  275. /* enable global irqs */
  276. val = LOLA_DINT_GLOBAL | LOLA_DINT_CTRL | LOLA_DINT_FIFOERR |
  277. LOLA_DINT_MUERR;
  278. lola_writel(chip, BAR1, DINTCTL, val);
  279. }
  280. static void lola_irq_disable(struct lola *chip)
  281. {
  282. lola_writel(chip, BAR1, DINTCTL, 0);
  283. lola_writel(chip, BAR1, DIINTCTL, 0);
  284. lola_writel(chip, BAR1, DOINTCTL, 0);
  285. }
  286. static int setup_corb_rirb(struct lola *chip)
  287. {
  288. int err;
  289. unsigned char tmp;
  290. unsigned long end_time;
  291. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  292. snd_dma_pci_data(chip->pci),
  293. PAGE_SIZE, &chip->rb);
  294. if (err < 0)
  295. return err;
  296. chip->corb.addr = chip->rb.addr;
  297. chip->corb.buf = (u32 *)chip->rb.area;
  298. chip->rirb.addr = chip->rb.addr + 2048;
  299. chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
  300. /* disable ringbuffer DMAs */
  301. lola_writeb(chip, BAR0, RIRBCTL, 0);
  302. lola_writeb(chip, BAR0, CORBCTL, 0);
  303. end_time = jiffies + msecs_to_jiffies(200);
  304. do {
  305. if (!lola_readb(chip, BAR0, RIRBCTL) &&
  306. !lola_readb(chip, BAR0, CORBCTL))
  307. break;
  308. msleep(1);
  309. } while (time_before(jiffies, end_time));
  310. /* CORB set up */
  311. lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr);
  312. lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr));
  313. /* set the corb size to 256 entries */
  314. lola_writeb(chip, BAR0, CORBSIZE, 0x02);
  315. /* set the corb write pointer to 0 */
  316. lola_writew(chip, BAR0, CORBWP, 0);
  317. /* reset the corb hw read pointer */
  318. lola_writew(chip, BAR0, CORBRP, LOLA_RBRWP_CLR);
  319. /* enable corb dma */
  320. lola_writeb(chip, BAR0, CORBCTL, LOLA_RBCTL_DMA_EN);
  321. /* clear flags if set */
  322. tmp = lola_readb(chip, BAR0, CORBSTS) & LOLA_CORB_INT_MASK;
  323. if (tmp)
  324. lola_writeb(chip, BAR0, CORBSTS, tmp);
  325. chip->corb.wp = 0;
  326. /* RIRB set up */
  327. lola_writel(chip, BAR0, RIRBLBASE, (u32)chip->rirb.addr);
  328. lola_writel(chip, BAR0, RIRBUBASE, upper_32_bits(chip->rirb.addr));
  329. /* set the rirb size to 256 entries */
  330. lola_writeb(chip, BAR0, RIRBSIZE, 0x02);
  331. /* reset the rirb hw write pointer */
  332. lola_writew(chip, BAR0, RIRBWP, LOLA_RBRWP_CLR);
  333. /* set N=1, get RIRB response interrupt for new entry */
  334. lola_writew(chip, BAR0, RINTCNT, 1);
  335. /* enable rirb dma and response irq */
  336. lola_writeb(chip, BAR0, RIRBCTL, LOLA_RBCTL_DMA_EN | LOLA_RBCTL_IRQ_EN);
  337. /* clear flags if set */
  338. tmp = lola_readb(chip, BAR0, RIRBSTS) & LOLA_RIRB_INT_MASK;
  339. if (tmp)
  340. lola_writeb(chip, BAR0, RIRBSTS, tmp);
  341. chip->rirb.rp = chip->rirb.cmds = 0;
  342. return 0;
  343. }
  344. static void stop_corb_rirb(struct lola *chip)
  345. {
  346. /* disable ringbuffer DMAs */
  347. lola_writeb(chip, BAR0, RIRBCTL, 0);
  348. lola_writeb(chip, BAR0, CORBCTL, 0);
  349. }
  350. static void lola_reset_setups(struct lola *chip)
  351. {
  352. /* update the granularity */
  353. lola_set_granularity(chip, chip->granularity, true);
  354. /* update the sample clock */
  355. lola_set_clock_index(chip, chip->clock.cur_index);
  356. /* enable unsolicited events of the clock widget */
  357. lola_enable_clock_events(chip);
  358. /* update the analog gains */
  359. lola_setup_all_analog_gains(chip, CAPT, false); /* input, update */
  360. /* update SRC configuration if applicable */
  361. lola_set_src_config(chip, chip->input_src_mask, false);
  362. /* update the analog outputs */
  363. lola_setup_all_analog_gains(chip, PLAY, false); /* output, update */
  364. }
  365. static int lola_parse_tree(struct lola *chip)
  366. {
  367. unsigned int val;
  368. int nid, err;
  369. err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
  370. if (err < 0) {
  371. printk(KERN_ERR SFX "Can't read VENDOR_ID\n");
  372. return err;
  373. }
  374. val >>= 16;
  375. if (val != 0x1369) {
  376. printk(KERN_ERR SFX "Unknown codec vendor 0x%x\n", val);
  377. return -EINVAL;
  378. }
  379. err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
  380. if (err < 0) {
  381. printk(KERN_ERR SFX "Can't read FUNCTION_TYPE for 0x%x\n", nid);
  382. return err;
  383. }
  384. if (val != 1) {
  385. printk(KERN_ERR SFX "Unknown function type %d\n", val);
  386. return -EINVAL;
  387. }
  388. err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
  389. if (err < 0) {
  390. printk(KERN_ERR SFX "Can't read SPECCAPS\n");
  391. return err;
  392. }
  393. chip->lola_caps = val;
  394. chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps);
  395. chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps);
  396. snd_printdd(SFX "speccaps=0x%x, pins in=%d, out=%d\n",
  397. chip->lola_caps,
  398. chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
  399. if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT ||
  400. chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) {
  401. printk(KERN_ERR SFX "Invalid Lola-spec caps 0x%x\n", val);
  402. return -EINVAL;
  403. }
  404. nid = 0x02;
  405. err = lola_init_pcm(chip, CAPT, &nid);
  406. if (err < 0)
  407. return err;
  408. err = lola_init_pcm(chip, PLAY, &nid);
  409. if (err < 0)
  410. return err;
  411. err = lola_init_pins(chip, CAPT, &nid);
  412. if (err < 0)
  413. return err;
  414. err = lola_init_pins(chip, PLAY, &nid);
  415. if (err < 0)
  416. return err;
  417. if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
  418. err = lola_init_clock_widget(chip, nid);
  419. if (err < 0)
  420. return err;
  421. nid++;
  422. }
  423. if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
  424. err = lola_init_mixer_widget(chip, nid);
  425. if (err < 0)
  426. return err;
  427. nid++;
  428. }
  429. /* enable unsolicited events of the clock widget */
  430. err = lola_enable_clock_events(chip);
  431. if (err < 0)
  432. return err;
  433. /* if last ResetController was not a ColdReset, we don't know
  434. * the state of the card; initialize here again
  435. */
  436. if (!chip->cold_reset) {
  437. lola_reset_setups(chip);
  438. chip->cold_reset = 1;
  439. } else {
  440. /* set the granularity if it is not the default */
  441. if (chip->granularity != LOLA_GRANULARITY_MIN)
  442. lola_set_granularity(chip, chip->granularity, true);
  443. }
  444. return 0;
  445. }
  446. static void lola_stop_hw(struct lola *chip)
  447. {
  448. stop_corb_rirb(chip);
  449. lola_irq_disable(chip);
  450. }
  451. static void lola_free(struct lola *chip)
  452. {
  453. if (chip->initialized)
  454. lola_stop_hw(chip);
  455. lola_free_pcm(chip);
  456. lola_free_mixer(chip);
  457. if (chip->irq >= 0)
  458. free_irq(chip->irq, (void *)chip);
  459. if (chip->bar[0].remap_addr)
  460. iounmap(chip->bar[0].remap_addr);
  461. if (chip->bar[1].remap_addr)
  462. iounmap(chip->bar[1].remap_addr);
  463. if (chip->rb.area)
  464. snd_dma_free_pages(&chip->rb);
  465. pci_release_regions(chip->pci);
  466. pci_disable_device(chip->pci);
  467. kfree(chip);
  468. }
  469. static int lola_dev_free(struct snd_device *device)
  470. {
  471. lola_free(device->device_data);
  472. return 0;
  473. }
  474. static int __devinit lola_create(struct snd_card *card, struct pci_dev *pci,
  475. struct lola **rchip)
  476. {
  477. struct lola *chip;
  478. int err;
  479. unsigned int dever;
  480. static struct snd_device_ops ops = {
  481. .dev_free = lola_dev_free,
  482. };
  483. *rchip = NULL;
  484. err = pci_enable_device(pci);
  485. if (err < 0)
  486. return err;
  487. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  488. if (!chip) {
  489. snd_printk(KERN_ERR SFX "cannot allocate chip\n");
  490. pci_disable_device(pci);
  491. return -ENOMEM;
  492. }
  493. spin_lock_init(&chip->reg_lock);
  494. mutex_init(&chip->open_mutex);
  495. chip->card = card;
  496. chip->pci = pci;
  497. chip->irq = -1;
  498. /* below a sample_rate of 16kHz the analogue audio quality
  499. * is NOT excellent
  500. */
  501. chip->sample_rate_min = 16000;
  502. /* for instance use always max granularity which is compatible
  503. * with all sample rates
  504. */
  505. chip->granularity = LOLA_GRANULARITY_MAX;
  506. err = pci_request_regions(pci, DRVNAME);
  507. if (err < 0) {
  508. kfree(chip);
  509. pci_disable_device(pci);
  510. return err;
  511. }
  512. chip->bar[0].addr = pci_resource_start(pci, 0);
  513. chip->bar[0].remap_addr = pci_ioremap_bar(pci, 0);
  514. chip->bar[1].addr = pci_resource_start(pci, 2);
  515. chip->bar[1].remap_addr = pci_ioremap_bar(pci, 2);
  516. if (!chip->bar[0].remap_addr || !chip->bar[1].remap_addr) {
  517. snd_printk(KERN_ERR SFX "ioremap error\n");
  518. err = -ENXIO;
  519. goto errout;
  520. }
  521. pci_set_master(pci);
  522. err = reset_controller(chip);
  523. if (err < 0)
  524. goto errout;
  525. if (request_irq(pci->irq, lola_interrupt, IRQF_SHARED,
  526. DRVNAME, chip)) {
  527. printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq);
  528. err = -EBUSY;
  529. goto errout;
  530. }
  531. chip->irq = pci->irq;
  532. synchronize_irq(chip->irq);
  533. dever = lola_readl(chip, BAR1, DEVER);
  534. chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff;
  535. chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff;
  536. chip->version = (dever >> 24) & 0xff;
  537. snd_printdd(SFX "streams in=%d, out=%d, version=0x%x\n",
  538. chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams,
  539. chip->version);
  540. /* Test LOLA_BAR1_DEVER */
  541. if (chip->pcm[CAPT].num_streams > MAX_STREAM_IN_COUNT ||
  542. chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT ||
  543. (!chip->pcm[CAPT].num_streams &&
  544. !chip->pcm[PLAY].num_streams)) {
  545. printk(KERN_ERR SFX "invalid DEVER = %x\n", dever);
  546. err = -EINVAL;
  547. goto errout;
  548. }
  549. err = setup_corb_rirb(chip);
  550. if (err < 0)
  551. goto errout;
  552. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  553. if (err < 0) {
  554. snd_printk(KERN_ERR SFX "Error creating device [card]!\n");
  555. goto errout;
  556. }
  557. strcpy(card->driver, "Lola");
  558. strlcpy(card->shortname, "Digigram Lola", sizeof(card->shortname));
  559. snprintf(card->longname, sizeof(card->longname),
  560. "%s at 0x%lx irq %i",
  561. card->shortname, chip->bar[0].addr, chip->irq);
  562. strcpy(card->mixername, card->shortname);
  563. lola_irq_enable(chip);
  564. chip->initialized = 1;
  565. *rchip = chip;
  566. return 0;
  567. errout:
  568. lola_free(chip);
  569. return err;
  570. }
  571. static int __devinit lola_probe(struct pci_dev *pci,
  572. const struct pci_device_id *pci_id)
  573. {
  574. static int dev;
  575. struct snd_card *card;
  576. struct lola *chip;
  577. int err;
  578. if (dev >= SNDRV_CARDS)
  579. return -ENODEV;
  580. if (!enable[dev]) {
  581. dev++;
  582. return -ENOENT;
  583. }
  584. err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  585. if (err < 0) {
  586. snd_printk(KERN_ERR SFX "Error creating card!\n");
  587. return err;
  588. }
  589. snd_card_set_dev(card, &pci->dev);
  590. err = lola_create(card, pci, &chip);
  591. if (err < 0)
  592. goto out_free;
  593. card->private_data = chip;
  594. err = lola_parse_tree(chip);
  595. if (err < 0)
  596. goto out_free;
  597. err = lola_create_pcm(chip);
  598. if (err < 0)
  599. goto out_free;
  600. err = lola_create_mixer(chip);
  601. if (err < 0)
  602. goto out_free;
  603. lola_proc_debug_new(chip);
  604. err = snd_card_register(card);
  605. if (err < 0)
  606. goto out_free;
  607. pci_set_drvdata(pci, card);
  608. dev++;
  609. return err;
  610. out_free:
  611. snd_card_free(card);
  612. return err;
  613. }
  614. static void __devexit lola_remove(struct pci_dev *pci)
  615. {
  616. snd_card_free(pci_get_drvdata(pci));
  617. pci_set_drvdata(pci, NULL);
  618. }
  619. /* PCI IDs */
  620. static DEFINE_PCI_DEVICE_TABLE(lola_ids) = {
  621. { PCI_VDEVICE(DIGIGRAM, 0x0001) },
  622. { 0, }
  623. };
  624. MODULE_DEVICE_TABLE(pci, lola_ids);
  625. /* pci_driver definition */
  626. static struct pci_driver driver = {
  627. .name = DRVNAME,
  628. .id_table = lola_ids,
  629. .probe = lola_probe,
  630. .remove = __devexit_p(lola_remove),
  631. };
  632. static int __init alsa_card_lola_init(void)
  633. {
  634. return pci_register_driver(&driver);
  635. }
  636. static void __exit alsa_card_lola_exit(void)
  637. {
  638. pci_unregister_driver(&driver);
  639. }
  640. module_init(alsa_card_lola_init)
  641. module_exit(alsa_card_lola_exit)