ca0106_main.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*
  2. * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
  3. * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
  4. * Version: 0.0.23
  5. *
  6. * FEATURES currently supported:
  7. * Front, Rear and Center/LFE.
  8. * Surround40 and Surround51.
  9. * Capture from MIC an LINE IN input.
  10. * SPDIF digital playback of PCM stereo and AC3/DTS works.
  11. * (One can use a standard mono mini-jack to one RCA plugs cable.
  12. * or one can use a standard stereo mini-jack to two RCA plugs cable.
  13. * Plug one of the RCA plugs into the Coax input of the external decoder/receiver.)
  14. * ( In theory one could output 3 different AC3 streams at once, to 3 different SPDIF outputs. )
  15. * Notes on how to capture sound:
  16. * The AC97 is used in the PLAYBACK direction.
  17. * The output from the AC97 chip, instead of reaching the speakers, is fed into the Philips 1361T ADC.
  18. * So, to record from the MIC, set the MIC Playback volume to max,
  19. * unmute the MIC and turn up the MASTER Playback volume.
  20. * So, to prevent feedback when capturing, minimise the "Capture feedback into Playback" volume.
  21. *
  22. * The only playback controls that currently do anything are: -
  23. * Analog Front
  24. * Analog Rear
  25. * Analog Center/LFE
  26. * SPDIF Front
  27. * SPDIF Rear
  28. * SPDIF Center/LFE
  29. *
  30. * For capture from Mic in or Line in.
  31. * Digital/Analog ( switch must be in Analog mode for CAPTURE. )
  32. *
  33. * CAPTURE feedback into PLAYBACK
  34. *
  35. * Changelog:
  36. * Support interrupts per period.
  37. * Removed noise from Center/LFE channel when in Analog mode.
  38. * Rename and remove mixer controls.
  39. * 0.0.6
  40. * Use separate card based DMA buffer for periods table list.
  41. * 0.0.7
  42. * Change remove and rename ctrls into lists.
  43. * 0.0.8
  44. * Try to fix capture sources.
  45. * 0.0.9
  46. * Fix AC3 output.
  47. * Enable S32_LE format support.
  48. * 0.0.10
  49. * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
  50. * 0.0.11
  51. * Add Model name recognition.
  52. * 0.0.12
  53. * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
  54. * Remove redundent "voice" handling.
  55. * 0.0.13
  56. * Single trigger call for multi channels.
  57. * 0.0.14
  58. * Set limits based on what the sound card hardware can do.
  59. * playback periods_min=2, periods_max=8
  60. * capture hw constraints require period_size = n * 64 bytes.
  61. * playback hw constraints require period_size = n * 64 bytes.
  62. * 0.0.15
  63. * Minor updates.
  64. * 0.0.16
  65. * Implement 192000 sample rate.
  66. * 0.0.17
  67. * Add support for SB0410 and SB0413.
  68. * 0.0.18
  69. * Modified Copyright message.
  70. * 0.0.19
  71. * Finally fix support for SB Live 24 bit. SB0410 and SB0413.
  72. * The output codec needs resetting, otherwise all output is muted.
  73. * 0.0.20
  74. * Merge "pci_disable_device(pci);" fixes.
  75. * 0.0.21
  76. * Add 4 capture channels. (SPDIF only comes in on channel 0. )
  77. * Add SPDIF capture using optional digital I/O module for SB Live 24bit. (Analog capture does not yet work.)
  78. * 0.0.22
  79. * Add support for MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97. From kiksen, bug #901
  80. * 0.0.23
  81. * Implement support for Line-in capture on SB Live 24bit.
  82. *
  83. * BUGS:
  84. * Some stability problems when unloading the snd-ca0106 kernel module.
  85. * --
  86. *
  87. * TODO:
  88. * 4 Capture channels, only one implemented so far.
  89. * Other capture rates apart from 48khz not implemented.
  90. * MIDI
  91. * --
  92. * GENERAL INFO:
  93. * Model: SB0310
  94. * P17 Chip: CA0106-DAT
  95. * AC97 Codec: STAC 9721
  96. * ADC: Philips 1361T (Stereo 24bit)
  97. * DAC: WM8746EDS (6-channel, 24bit, 192Khz)
  98. *
  99. * GENERAL INFO:
  100. * Model: SB0410
  101. * P17 Chip: CA0106-DAT
  102. * AC97 Codec: None
  103. * ADC: WM8775EDS (4 Channel)
  104. * DAC: CS4382 (114 dB, 24-Bit, 192 kHz, 8-Channel D/A Converter with DSD Support)
  105. * SPDIF Out control switches between Mic in and SPDIF out.
  106. * No sound out or mic input working yet.
  107. *
  108. * GENERAL INFO:
  109. * Model: SB0413
  110. * P17 Chip: CA0106-DAT
  111. * AC97 Codec: None.
  112. * ADC: Unknown
  113. * DAC: Unknown
  114. * Trying to handle it like the SB0410.
  115. *
  116. * This code was initally based on code from ALSA's emu10k1x.c which is:
  117. * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
  118. *
  119. * This program is free software; you can redistribute it and/or modify
  120. * it under the terms of the GNU General Public License as published by
  121. * the Free Software Foundation; either version 2 of the License, or
  122. * (at your option) any later version.
  123. *
  124. * This program is distributed in the hope that it will be useful,
  125. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  126. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  127. * GNU General Public License for more details.
  128. *
  129. * You should have received a copy of the GNU General Public License
  130. * along with this program; if not, write to the Free Software
  131. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  132. *
  133. */
  134. #include <sound/driver.h>
  135. #include <linux/delay.h>
  136. #include <linux/init.h>
  137. #include <linux/interrupt.h>
  138. #include <linux/pci.h>
  139. #include <linux/slab.h>
  140. #include <linux/moduleparam.h>
  141. #include <linux/dma-mapping.h>
  142. #include <sound/core.h>
  143. #include <sound/initval.h>
  144. #include <sound/pcm.h>
  145. #include <sound/ac97_codec.h>
  146. #include <sound/info.h>
  147. MODULE_AUTHOR("James Courtier-Dutton <James@superbug.demon.co.uk>");
  148. MODULE_DESCRIPTION("CA0106");
  149. MODULE_LICENSE("GPL");
  150. MODULE_SUPPORTED_DEVICE("{{Creative,SB CA0106 chip}}");
  151. // module parameters (see "Module Parameters")
  152. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  153. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  154. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  155. module_param_array(index, int, NULL, 0444);
  156. MODULE_PARM_DESC(index, "Index value for the CA0106 soundcard.");
  157. module_param_array(id, charp, NULL, 0444);
  158. MODULE_PARM_DESC(id, "ID string for the CA0106 soundcard.");
  159. module_param_array(enable, bool, NULL, 0444);
  160. MODULE_PARM_DESC(enable, "Enable the CA0106 soundcard.");
  161. #include "ca0106.h"
  162. static struct snd_ca0106_details ca0106_chip_details[] = {
  163. /* AudigyLS[SB0310] */
  164. { .serial = 0x10021102,
  165. .name = "AudigyLS [SB0310]",
  166. .ac97 = 1 } ,
  167. /* Unknown AudigyLS that also says SB0310 on it */
  168. { .serial = 0x10051102,
  169. .name = "AudigyLS [SB0310b]",
  170. .ac97 = 1 } ,
  171. /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
  172. { .serial = 0x10061102,
  173. .name = "Live! 7.1 24bit [SB0410]",
  174. .gpio_type = 1,
  175. .i2c_adc = 1 } ,
  176. /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */
  177. { .serial = 0x10071102,
  178. .name = "Live! 7.1 24bit [SB0413]",
  179. .gpio_type = 1,
  180. .i2c_adc = 1 } ,
  181. /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */
  182. { .serial = 0x10091462,
  183. .name = "MSI K8N Diamond MB [SB0438]",
  184. .gpio_type = 1,
  185. .i2c_adc = 1 } ,
  186. /* Shuttle XPC SD31P which has an onboard Creative Labs Sound Blaster Live! 24-bit EAX
  187. * high-definition 7.1 audio processor".
  188. * Added using info from andrewvegan in alsa bug #1298
  189. */
  190. { .serial = 0x30381297,
  191. .name = "Shuttle XPC SD31P [SD31P]",
  192. .gpio_type = 1,
  193. .i2c_adc = 1 } ,
  194. { .serial = 0,
  195. .name = "AudigyLS [Unknown]" }
  196. };
  197. /* hardware definition */
  198. static struct snd_pcm_hardware snd_ca0106_playback_hw = {
  199. .info = (SNDRV_PCM_INFO_MMAP |
  200. SNDRV_PCM_INFO_INTERLEAVED |
  201. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  202. SNDRV_PCM_INFO_MMAP_VALID),
  203. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
  204. .rates = (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
  205. SNDRV_PCM_RATE_192000),
  206. .rate_min = 48000,
  207. .rate_max = 192000,
  208. .channels_min = 2, //1,
  209. .channels_max = 2, //6,
  210. .buffer_bytes_max = ((65536 - 64) * 8),
  211. .period_bytes_min = 64,
  212. .period_bytes_max = (65536 - 64),
  213. .periods_min = 2,
  214. .periods_max = 8,
  215. .fifo_size = 0,
  216. };
  217. static struct snd_pcm_hardware snd_ca0106_capture_hw = {
  218. .info = (SNDRV_PCM_INFO_MMAP |
  219. SNDRV_PCM_INFO_INTERLEAVED |
  220. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  221. SNDRV_PCM_INFO_MMAP_VALID),
  222. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
  223. .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
  224. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
  225. .rate_min = 44100,
  226. .rate_max = 192000,
  227. .channels_min = 2,
  228. .channels_max = 2,
  229. .buffer_bytes_max = ((65536 - 64) * 8),
  230. .period_bytes_min = 64,
  231. .period_bytes_max = (65536 - 64),
  232. .periods_min = 2,
  233. .periods_max = 2,
  234. .fifo_size = 0,
  235. };
  236. unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
  237. unsigned int reg,
  238. unsigned int chn)
  239. {
  240. unsigned long flags;
  241. unsigned int regptr, val;
  242. regptr = (reg << 16) | chn;
  243. spin_lock_irqsave(&emu->emu_lock, flags);
  244. outl(regptr, emu->port + PTR);
  245. val = inl(emu->port + DATA);
  246. spin_unlock_irqrestore(&emu->emu_lock, flags);
  247. return val;
  248. }
  249. void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
  250. unsigned int reg,
  251. unsigned int chn,
  252. unsigned int data)
  253. {
  254. unsigned int regptr;
  255. unsigned long flags;
  256. regptr = (reg << 16) | chn;
  257. spin_lock_irqsave(&emu->emu_lock, flags);
  258. outl(regptr, emu->port + PTR);
  259. outl(data, emu->port + DATA);
  260. spin_unlock_irqrestore(&emu->emu_lock, flags);
  261. }
  262. int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
  263. u32 reg,
  264. u32 value)
  265. {
  266. u32 tmp;
  267. int timeout = 0;
  268. int status;
  269. int retry;
  270. if ((reg > 0x7f) || (value > 0x1ff)) {
  271. snd_printk(KERN_ERR "i2c_write: invalid values.\n");
  272. return -EINVAL;
  273. }
  274. tmp = reg << 25 | value << 16;
  275. /* Not sure what this I2C channel controls. */
  276. /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
  277. /* This controls the I2C connected to the WM8775 ADC Codec */
  278. snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
  279. for (retry = 0; retry < 10; retry++) {
  280. /* Send the data to i2c */
  281. tmp = snd_ca0106_ptr_read(emu, I2C_A, 0);
  282. tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK);
  283. tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD);
  284. snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
  285. /* Wait till the transaction ends */
  286. while (1) {
  287. status = snd_ca0106_ptr_read(emu, I2C_A, 0);
  288. //snd_printk("I2C:status=0x%x\n", status);
  289. timeout++;
  290. if ((status & I2C_A_ADC_START) == 0)
  291. break;
  292. if (timeout > 1000)
  293. break;
  294. }
  295. //Read back and see if the transaction is successful
  296. if ((status & I2C_A_ADC_ABORT) == 0)
  297. break;
  298. }
  299. if (retry == 10) {
  300. snd_printk(KERN_ERR "Writing to ADC failed!\n");
  301. return -EINVAL;
  302. }
  303. return 0;
  304. }
  305. static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
  306. {
  307. unsigned long flags;
  308. unsigned int enable;
  309. spin_lock_irqsave(&emu->emu_lock, flags);
  310. enable = inl(emu->port + INTE) | intrenb;
  311. outl(enable, emu->port + INTE);
  312. spin_unlock_irqrestore(&emu->emu_lock, flags);
  313. }
  314. static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
  315. {
  316. unsigned long flags;
  317. unsigned int enable;
  318. spin_lock_irqsave(&emu->emu_lock, flags);
  319. enable = inl(emu->port + INTE) & ~intrenb;
  320. outl(enable, emu->port + INTE);
  321. spin_unlock_irqrestore(&emu->emu_lock, flags);
  322. }
  323. static void snd_ca0106_pcm_free_substream(struct snd_pcm_runtime *runtime)
  324. {
  325. kfree(runtime->private_data);
  326. }
  327. /* open_playback callback */
  328. static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream,
  329. int channel_id)
  330. {
  331. struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
  332. struct snd_ca0106_channel *channel = &(chip->playback_channels[channel_id]);
  333. struct snd_ca0106_pcm *epcm;
  334. struct snd_pcm_runtime *runtime = substream->runtime;
  335. int err;
  336. epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
  337. if (epcm == NULL)
  338. return -ENOMEM;
  339. epcm->emu = chip;
  340. epcm->substream = substream;
  341. epcm->channel_id=channel_id;
  342. runtime->private_data = epcm;
  343. runtime->private_free = snd_ca0106_pcm_free_substream;
  344. runtime->hw = snd_ca0106_playback_hw;
  345. channel->emu = chip;
  346. channel->number = channel_id;
  347. channel->use = 1;
  348. //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
  349. //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
  350. channel->epcm = epcm;
  351. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  352. return err;
  353. if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
  354. return err;
  355. return 0;
  356. }
  357. /* close callback */
  358. static int snd_ca0106_pcm_close_playback(struct snd_pcm_substream *substream)
  359. {
  360. struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
  361. struct snd_pcm_runtime *runtime = substream->runtime;
  362. struct snd_ca0106_pcm *epcm = runtime->private_data;
  363. chip->playback_channels[epcm->channel_id].use = 0;
  364. /* FIXME: maybe zero others */
  365. return 0;
  366. }
  367. static int snd_ca0106_pcm_open_playback_front(struct snd_pcm_substream *substream)
  368. {
  369. return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
  370. }
  371. static int snd_ca0106_pcm_open_playback_center_lfe(struct snd_pcm_substream *substream)
  372. {
  373. return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL);
  374. }
  375. static int snd_ca0106_pcm_open_playback_unknown(struct snd_pcm_substream *substream)
  376. {
  377. return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL);
  378. }
  379. static int snd_ca0106_pcm_open_playback_rear(struct snd_pcm_substream *substream)
  380. {
  381. return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL);
  382. }
  383. /* open_capture callback */
  384. static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substream,
  385. int channel_id)
  386. {
  387. struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
  388. struct snd_ca0106_channel *channel = &(chip->capture_channels[channel_id]);
  389. struct snd_ca0106_pcm *epcm;
  390. struct snd_pcm_runtime *runtime = substream->runtime;
  391. int err;
  392. epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
  393. if (epcm == NULL) {
  394. snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n");
  395. return -ENOMEM;
  396. }
  397. epcm->emu = chip;
  398. epcm->substream = substream;
  399. epcm->channel_id=channel_id;
  400. runtime->private_data = epcm;
  401. runtime->private_free = snd_ca0106_pcm_free_substream;
  402. runtime->hw = snd_ca0106_capture_hw;
  403. channel->emu = chip;
  404. channel->number = channel_id;
  405. channel->use = 1;
  406. //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
  407. //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
  408. channel->epcm = epcm;
  409. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  410. return err;
  411. //snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes);
  412. if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
  413. return err;
  414. return 0;
  415. }
  416. /* close callback */
  417. static int snd_ca0106_pcm_close_capture(struct snd_pcm_substream *substream)
  418. {
  419. struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
  420. struct snd_pcm_runtime *runtime = substream->runtime;
  421. struct snd_ca0106_pcm *epcm = runtime->private_data;
  422. chip->capture_channels[epcm->channel_id].use = 0;
  423. /* FIXME: maybe zero others */
  424. return 0;
  425. }
  426. static int snd_ca0106_pcm_open_0_capture(struct snd_pcm_substream *substream)
  427. {
  428. return snd_ca0106_pcm_open_capture_channel(substream, 0);
  429. }
  430. static int snd_ca0106_pcm_open_1_capture(struct snd_pcm_substream *substream)
  431. {
  432. return snd_ca0106_pcm_open_capture_channel(substream, 1);
  433. }
  434. static int snd_ca0106_pcm_open_2_capture(struct snd_pcm_substream *substream)
  435. {
  436. return snd_ca0106_pcm_open_capture_channel(substream, 2);
  437. }
  438. static int snd_ca0106_pcm_open_3_capture(struct snd_pcm_substream *substream)
  439. {
  440. return snd_ca0106_pcm_open_capture_channel(substream, 3);
  441. }
  442. /* hw_params callback */
  443. static int snd_ca0106_pcm_hw_params_playback(struct snd_pcm_substream *substream,
  444. struct snd_pcm_hw_params *hw_params)
  445. {
  446. return snd_pcm_lib_malloc_pages(substream,
  447. params_buffer_bytes(hw_params));
  448. }
  449. /* hw_free callback */
  450. static int snd_ca0106_pcm_hw_free_playback(struct snd_pcm_substream *substream)
  451. {
  452. return snd_pcm_lib_free_pages(substream);
  453. }
  454. /* hw_params callback */
  455. static int snd_ca0106_pcm_hw_params_capture(struct snd_pcm_substream *substream,
  456. struct snd_pcm_hw_params *hw_params)
  457. {
  458. return snd_pcm_lib_malloc_pages(substream,
  459. params_buffer_bytes(hw_params));
  460. }
  461. /* hw_free callback */
  462. static int snd_ca0106_pcm_hw_free_capture(struct snd_pcm_substream *substream)
  463. {
  464. return snd_pcm_lib_free_pages(substream);
  465. }
  466. /* prepare playback callback */
  467. static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
  468. {
  469. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  470. struct snd_pcm_runtime *runtime = substream->runtime;
  471. struct snd_ca0106_pcm *epcm = runtime->private_data;
  472. int channel = epcm->channel_id;
  473. u32 *table_base = (u32 *)(emu->buffer.area+(8*16*channel));
  474. u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
  475. u32 hcfg_mask = HCFG_PLAYBACK_S32_LE;
  476. u32 hcfg_set = 0x00000000;
  477. u32 hcfg;
  478. u32 reg40_mask = 0x30000 << (channel<<1);
  479. u32 reg40_set = 0;
  480. u32 reg40;
  481. /* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */
  482. u32 reg71_mask = 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */
  483. u32 reg71_set = 0;
  484. u32 reg71;
  485. int i;
  486. //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
  487. //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
  488. //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
  489. /* Rate can be set per channel. */
  490. /* reg40 control host to fifo */
  491. /* reg71 controls DAC rate. */
  492. switch (runtime->rate) {
  493. case 44100:
  494. reg40_set = 0x10000 << (channel<<1);
  495. reg71_set = 0x01010000;
  496. break;
  497. case 48000:
  498. reg40_set = 0;
  499. reg71_set = 0;
  500. break;
  501. case 96000:
  502. reg40_set = 0x20000 << (channel<<1);
  503. reg71_set = 0x02020000;
  504. break;
  505. case 192000:
  506. reg40_set = 0x30000 << (channel<<1);
  507. reg71_set = 0x03030000;
  508. break;
  509. default:
  510. reg40_set = 0;
  511. reg71_set = 0;
  512. break;
  513. }
  514. /* Format is a global setting */
  515. /* FIXME: Only let the first channel accessed set this. */
  516. switch (runtime->format) {
  517. case SNDRV_PCM_FORMAT_S16_LE:
  518. hcfg_set = 0;
  519. break;
  520. case SNDRV_PCM_FORMAT_S32_LE:
  521. hcfg_set = HCFG_PLAYBACK_S32_LE;
  522. break;
  523. default:
  524. hcfg_set = 0;
  525. break;
  526. }
  527. hcfg = inl(emu->port + HCFG) ;
  528. hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
  529. outl(hcfg, emu->port + HCFG);
  530. reg40 = snd_ca0106_ptr_read(emu, 0x40, 0);
  531. reg40 = (reg40 & ~reg40_mask) | reg40_set;
  532. snd_ca0106_ptr_write(emu, 0x40, 0, reg40);
  533. reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
  534. reg71 = (reg71 & ~reg71_mask) | reg71_set;
  535. snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
  536. /* FIXME: Check emu->buffer.size before actually writing to it. */
  537. for(i=0; i < runtime->periods; i++) {
  538. table_base[i*2] = runtime->dma_addr + (i * period_size_bytes);
  539. table_base[i*2+1] = period_size_bytes << 16;
  540. }
  541. snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel));
  542. snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
  543. snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0);
  544. snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
  545. snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
  546. /* FIXME test what 0 bytes does. */
  547. snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes
  548. snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0);
  549. snd_ca0106_ptr_write(emu, 0x07, channel, 0x0);
  550. snd_ca0106_ptr_write(emu, 0x08, channel, 0);
  551. snd_ca0106_ptr_write(emu, PLAYBACK_MUTE, 0x0, 0x0); /* Unmute output */
  552. #if 0
  553. snd_ca0106_ptr_write(emu, SPCS0, 0,
  554. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  555. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  556. SPCS_GENERATIONSTATUS | 0x00001200 |
  557. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT );
  558. }
  559. #endif
  560. return 0;
  561. }
  562. /* prepare capture callback */
  563. static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
  564. {
  565. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  566. struct snd_pcm_runtime *runtime = substream->runtime;
  567. struct snd_ca0106_pcm *epcm = runtime->private_data;
  568. int channel = epcm->channel_id;
  569. u32 hcfg_mask = HCFG_CAPTURE_S32_LE;
  570. u32 hcfg_set = 0x00000000;
  571. u32 hcfg;
  572. u32 over_sampling=0x2;
  573. u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */
  574. u32 reg71_set = 0;
  575. u32 reg71;
  576. //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
  577. //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
  578. //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
  579. /* reg71 controls ADC rate. */
  580. switch (runtime->rate) {
  581. case 44100:
  582. reg71_set = 0x00004000;
  583. break;
  584. case 48000:
  585. reg71_set = 0;
  586. break;
  587. case 96000:
  588. reg71_set = 0x00008000;
  589. over_sampling=0xa;
  590. break;
  591. case 192000:
  592. reg71_set = 0x0000c000;
  593. over_sampling=0xa;
  594. break;
  595. default:
  596. reg71_set = 0;
  597. break;
  598. }
  599. /* Format is a global setting */
  600. /* FIXME: Only let the first channel accessed set this. */
  601. switch (runtime->format) {
  602. case SNDRV_PCM_FORMAT_S16_LE:
  603. hcfg_set = 0;
  604. break;
  605. case SNDRV_PCM_FORMAT_S32_LE:
  606. hcfg_set = HCFG_CAPTURE_S32_LE;
  607. break;
  608. default:
  609. hcfg_set = 0;
  610. break;
  611. }
  612. hcfg = inl(emu->port + HCFG) ;
  613. hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
  614. outl(hcfg, emu->port + HCFG);
  615. reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
  616. reg71 = (reg71 & ~reg71_mask) | reg71_set;
  617. snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
  618. if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
  619. snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */
  620. }
  621. //printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1));
  622. snd_ca0106_ptr_write(emu, 0x13, channel, 0);
  623. snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr);
  624. snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
  625. snd_ca0106_ptr_write(emu, CAPTURE_POINTER, channel, 0);
  626. return 0;
  627. }
  628. /* trigger_playback callback */
  629. static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
  630. int cmd)
  631. {
  632. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  633. struct snd_pcm_runtime *runtime;
  634. struct snd_ca0106_pcm *epcm;
  635. int channel;
  636. int result = 0;
  637. struct list_head *pos;
  638. struct snd_pcm_substream *s;
  639. u32 basic = 0;
  640. u32 extended = 0;
  641. int running=0;
  642. switch (cmd) {
  643. case SNDRV_PCM_TRIGGER_START:
  644. running=1;
  645. break;
  646. case SNDRV_PCM_TRIGGER_STOP:
  647. default:
  648. running=0;
  649. break;
  650. }
  651. snd_pcm_group_for_each(pos, substream) {
  652. s = snd_pcm_group_substream_entry(pos);
  653. runtime = s->runtime;
  654. epcm = runtime->private_data;
  655. channel = epcm->channel_id;
  656. //snd_printk("channel=%d\n",channel);
  657. epcm->running = running;
  658. basic |= (0x1<<channel);
  659. extended |= (0x10<<channel);
  660. snd_pcm_trigger_done(s, substream);
  661. }
  662. //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended);
  663. switch (cmd) {
  664. case SNDRV_PCM_TRIGGER_START:
  665. snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended));
  666. snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic));
  667. break;
  668. case SNDRV_PCM_TRIGGER_STOP:
  669. snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic));
  670. snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended));
  671. break;
  672. default:
  673. result = -EINVAL;
  674. break;
  675. }
  676. return result;
  677. }
  678. /* trigger_capture callback */
  679. static int snd_ca0106_pcm_trigger_capture(struct snd_pcm_substream *substream,
  680. int cmd)
  681. {
  682. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  683. struct snd_pcm_runtime *runtime = substream->runtime;
  684. struct snd_ca0106_pcm *epcm = runtime->private_data;
  685. int channel = epcm->channel_id;
  686. int result = 0;
  687. switch (cmd) {
  688. case SNDRV_PCM_TRIGGER_START:
  689. snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel));
  690. snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel));
  691. epcm->running = 1;
  692. break;
  693. case SNDRV_PCM_TRIGGER_STOP:
  694. snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel));
  695. snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel));
  696. epcm->running = 0;
  697. break;
  698. default:
  699. result = -EINVAL;
  700. break;
  701. }
  702. return result;
  703. }
  704. /* pointer_playback callback */
  705. static snd_pcm_uframes_t
  706. snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
  707. {
  708. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  709. struct snd_pcm_runtime *runtime = substream->runtime;
  710. struct snd_ca0106_pcm *epcm = runtime->private_data;
  711. snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
  712. int channel = epcm->channel_id;
  713. if (!epcm->running)
  714. return 0;
  715. ptr3 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
  716. ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel);
  717. ptr4 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
  718. if (ptr3 != ptr4) ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel);
  719. ptr2 = bytes_to_frames(runtime, ptr1);
  720. ptr2+= (ptr4 >> 3) * runtime->period_size;
  721. ptr=ptr2;
  722. if (ptr >= runtime->buffer_size)
  723. ptr -= runtime->buffer_size;
  724. //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
  725. return ptr;
  726. }
  727. /* pointer_capture callback */
  728. static snd_pcm_uframes_t
  729. snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
  730. {
  731. struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
  732. struct snd_pcm_runtime *runtime = substream->runtime;
  733. struct snd_ca0106_pcm *epcm = runtime->private_data;
  734. snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
  735. int channel = channel=epcm->channel_id;
  736. if (!epcm->running)
  737. return 0;
  738. ptr1 = snd_ca0106_ptr_read(emu, CAPTURE_POINTER, channel);
  739. ptr2 = bytes_to_frames(runtime, ptr1);
  740. ptr=ptr2;
  741. if (ptr >= runtime->buffer_size)
  742. ptr -= runtime->buffer_size;
  743. //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
  744. return ptr;
  745. }
  746. /* operators */
  747. static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
  748. .open = snd_ca0106_pcm_open_playback_front,
  749. .close = snd_ca0106_pcm_close_playback,
  750. .ioctl = snd_pcm_lib_ioctl,
  751. .hw_params = snd_ca0106_pcm_hw_params_playback,
  752. .hw_free = snd_ca0106_pcm_hw_free_playback,
  753. .prepare = snd_ca0106_pcm_prepare_playback,
  754. .trigger = snd_ca0106_pcm_trigger_playback,
  755. .pointer = snd_ca0106_pcm_pointer_playback,
  756. };
  757. static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
  758. .open = snd_ca0106_pcm_open_0_capture,
  759. .close = snd_ca0106_pcm_close_capture,
  760. .ioctl = snd_pcm_lib_ioctl,
  761. .hw_params = snd_ca0106_pcm_hw_params_capture,
  762. .hw_free = snd_ca0106_pcm_hw_free_capture,
  763. .prepare = snd_ca0106_pcm_prepare_capture,
  764. .trigger = snd_ca0106_pcm_trigger_capture,
  765. .pointer = snd_ca0106_pcm_pointer_capture,
  766. };
  767. static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
  768. .open = snd_ca0106_pcm_open_1_capture,
  769. .close = snd_ca0106_pcm_close_capture,
  770. .ioctl = snd_pcm_lib_ioctl,
  771. .hw_params = snd_ca0106_pcm_hw_params_capture,
  772. .hw_free = snd_ca0106_pcm_hw_free_capture,
  773. .prepare = snd_ca0106_pcm_prepare_capture,
  774. .trigger = snd_ca0106_pcm_trigger_capture,
  775. .pointer = snd_ca0106_pcm_pointer_capture,
  776. };
  777. static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
  778. .open = snd_ca0106_pcm_open_2_capture,
  779. .close = snd_ca0106_pcm_close_capture,
  780. .ioctl = snd_pcm_lib_ioctl,
  781. .hw_params = snd_ca0106_pcm_hw_params_capture,
  782. .hw_free = snd_ca0106_pcm_hw_free_capture,
  783. .prepare = snd_ca0106_pcm_prepare_capture,
  784. .trigger = snd_ca0106_pcm_trigger_capture,
  785. .pointer = snd_ca0106_pcm_pointer_capture,
  786. };
  787. static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
  788. .open = snd_ca0106_pcm_open_3_capture,
  789. .close = snd_ca0106_pcm_close_capture,
  790. .ioctl = snd_pcm_lib_ioctl,
  791. .hw_params = snd_ca0106_pcm_hw_params_capture,
  792. .hw_free = snd_ca0106_pcm_hw_free_capture,
  793. .prepare = snd_ca0106_pcm_prepare_capture,
  794. .trigger = snd_ca0106_pcm_trigger_capture,
  795. .pointer = snd_ca0106_pcm_pointer_capture,
  796. };
  797. static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
  798. .open = snd_ca0106_pcm_open_playback_center_lfe,
  799. .close = snd_ca0106_pcm_close_playback,
  800. .ioctl = snd_pcm_lib_ioctl,
  801. .hw_params = snd_ca0106_pcm_hw_params_playback,
  802. .hw_free = snd_ca0106_pcm_hw_free_playback,
  803. .prepare = snd_ca0106_pcm_prepare_playback,
  804. .trigger = snd_ca0106_pcm_trigger_playback,
  805. .pointer = snd_ca0106_pcm_pointer_playback,
  806. };
  807. static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
  808. .open = snd_ca0106_pcm_open_playback_unknown,
  809. .close = snd_ca0106_pcm_close_playback,
  810. .ioctl = snd_pcm_lib_ioctl,
  811. .hw_params = snd_ca0106_pcm_hw_params_playback,
  812. .hw_free = snd_ca0106_pcm_hw_free_playback,
  813. .prepare = snd_ca0106_pcm_prepare_playback,
  814. .trigger = snd_ca0106_pcm_trigger_playback,
  815. .pointer = snd_ca0106_pcm_pointer_playback,
  816. };
  817. static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
  818. .open = snd_ca0106_pcm_open_playback_rear,
  819. .close = snd_ca0106_pcm_close_playback,
  820. .ioctl = snd_pcm_lib_ioctl,
  821. .hw_params = snd_ca0106_pcm_hw_params_playback,
  822. .hw_free = snd_ca0106_pcm_hw_free_playback,
  823. .prepare = snd_ca0106_pcm_prepare_playback,
  824. .trigger = snd_ca0106_pcm_trigger_playback,
  825. .pointer = snd_ca0106_pcm_pointer_playback,
  826. };
  827. static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97,
  828. unsigned short reg)
  829. {
  830. struct snd_ca0106 *emu = ac97->private_data;
  831. unsigned long flags;
  832. unsigned short val;
  833. spin_lock_irqsave(&emu->emu_lock, flags);
  834. outb(reg, emu->port + AC97ADDRESS);
  835. val = inw(emu->port + AC97DATA);
  836. spin_unlock_irqrestore(&emu->emu_lock, flags);
  837. return val;
  838. }
  839. static void snd_ca0106_ac97_write(struct snd_ac97 *ac97,
  840. unsigned short reg, unsigned short val)
  841. {
  842. struct snd_ca0106 *emu = ac97->private_data;
  843. unsigned long flags;
  844. spin_lock_irqsave(&emu->emu_lock, flags);
  845. outb(reg, emu->port + AC97ADDRESS);
  846. outw(val, emu->port + AC97DATA);
  847. spin_unlock_irqrestore(&emu->emu_lock, flags);
  848. }
  849. static int snd_ca0106_ac97(struct snd_ca0106 *chip)
  850. {
  851. struct snd_ac97_bus *pbus;
  852. struct snd_ac97_template ac97;
  853. int err;
  854. static struct snd_ac97_bus_ops ops = {
  855. .write = snd_ca0106_ac97_write,
  856. .read = snd_ca0106_ac97_read,
  857. };
  858. if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
  859. return err;
  860. pbus->no_vra = 1; /* we don't need VRA */
  861. memset(&ac97, 0, sizeof(ac97));
  862. ac97.private_data = chip;
  863. ac97.scaps = AC97_SCAP_NO_SPDIF;
  864. return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
  865. }
  866. static int snd_ca0106_free(struct snd_ca0106 *chip)
  867. {
  868. if (chip->res_port != NULL) { /* avoid access to already used hardware */
  869. // disable interrupts
  870. snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0);
  871. outl(0, chip->port + INTE);
  872. snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
  873. udelay(1000);
  874. // disable audio
  875. //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
  876. outl(0, chip->port + HCFG);
  877. /* FIXME: We need to stop and DMA transfers here.
  878. * But as I am not sure how yet, we cannot from the dma pages.
  879. * So we can fix: snd-malloc: Memory leak? pages not freed = 8
  880. */
  881. }
  882. // release the data
  883. #if 1
  884. if (chip->buffer.area)
  885. snd_dma_free_pages(&chip->buffer);
  886. #endif
  887. // release the i/o port
  888. release_and_free_resource(chip->res_port);
  889. // release the irq
  890. if (chip->irq >= 0)
  891. free_irq(chip->irq, (void *)chip);
  892. pci_disable_device(chip->pci);
  893. kfree(chip);
  894. return 0;
  895. }
  896. static int snd_ca0106_dev_free(struct snd_device *device)
  897. {
  898. struct snd_ca0106 *chip = device->device_data;
  899. return snd_ca0106_free(chip);
  900. }
  901. static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
  902. struct pt_regs *regs)
  903. {
  904. unsigned int status;
  905. struct snd_ca0106 *chip = dev_id;
  906. int i;
  907. int mask;
  908. unsigned int stat76;
  909. struct snd_ca0106_channel *pchannel;
  910. status = inl(chip->port + IPR);
  911. if (! status)
  912. return IRQ_NONE;
  913. stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0);
  914. //snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76);
  915. //snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
  916. mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
  917. for(i = 0; i < 4; i++) {
  918. pchannel = &(chip->playback_channels[i]);
  919. if (stat76 & mask) {
  920. /* FIXME: Select the correct substream for period elapsed */
  921. if(pchannel->use) {
  922. snd_pcm_period_elapsed(pchannel->epcm->substream);
  923. //printk(KERN_INFO "interrupt [%d] used\n", i);
  924. }
  925. }
  926. //printk(KERN_INFO "channel=%p\n",pchannel);
  927. //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
  928. mask <<= 1;
  929. }
  930. mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
  931. for(i = 0; i < 4; i++) {
  932. pchannel = &(chip->capture_channels[i]);
  933. if (stat76 & mask) {
  934. /* FIXME: Select the correct substream for period elapsed */
  935. if(pchannel->use) {
  936. snd_pcm_period_elapsed(pchannel->epcm->substream);
  937. //printk(KERN_INFO "interrupt [%d] used\n", i);
  938. }
  939. }
  940. //printk(KERN_INFO "channel=%p\n",pchannel);
  941. //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
  942. mask <<= 1;
  943. }
  944. snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
  945. if (chip->midi.dev_id &&
  946. (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
  947. if (chip->midi.interrupt)
  948. chip->midi.interrupt(&chip->midi, status);
  949. else
  950. chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
  951. }
  952. // acknowledge the interrupt if necessary
  953. outl(status, chip->port+IPR);
  954. return IRQ_HANDLED;
  955. }
  956. static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm)
  957. {
  958. struct snd_pcm *pcm;
  959. struct snd_pcm_substream *substream;
  960. int err;
  961. if (rpcm)
  962. *rpcm = NULL;
  963. if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
  964. return err;
  965. pcm->private_data = emu;
  966. switch (device) {
  967. case 0:
  968. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_front_ops);
  969. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_0_ops);
  970. break;
  971. case 1:
  972. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_rear_ops);
  973. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_1_ops);
  974. break;
  975. case 2:
  976. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_center_lfe_ops);
  977. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_2_ops);
  978. break;
  979. case 3:
  980. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_unknown_ops);
  981. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_3_ops);
  982. break;
  983. }
  984. pcm->info_flags = 0;
  985. pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
  986. strcpy(pcm->name, "CA0106");
  987. emu->pcm = pcm;
  988. for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  989. substream;
  990. substream = substream->next) {
  991. if ((err = snd_pcm_lib_preallocate_pages(substream,
  992. SNDRV_DMA_TYPE_DEV,
  993. snd_dma_pci_data(emu->pci),
  994. 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
  995. return err;
  996. }
  997. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  998. substream;
  999. substream = substream->next) {
  1000. if ((err = snd_pcm_lib_preallocate_pages(substream,
  1001. SNDRV_DMA_TYPE_DEV,
  1002. snd_dma_pci_data(emu->pci),
  1003. 64*1024, 64*1024)) < 0)
  1004. return err;
  1005. }
  1006. if (rpcm)
  1007. *rpcm = pcm;
  1008. return 0;
  1009. }
  1010. static int __devinit snd_ca0106_create(struct snd_card *card,
  1011. struct pci_dev *pci,
  1012. struct snd_ca0106 **rchip)
  1013. {
  1014. struct snd_ca0106 *chip;
  1015. struct snd_ca0106_details *c;
  1016. int err;
  1017. int ch;
  1018. static struct snd_device_ops ops = {
  1019. .dev_free = snd_ca0106_dev_free,
  1020. };
  1021. *rchip = NULL;
  1022. if ((err = pci_enable_device(pci)) < 0)
  1023. return err;
  1024. if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
  1025. pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
  1026. printk(KERN_ERR "error to set 32bit mask DMA\n");
  1027. pci_disable_device(pci);
  1028. return -ENXIO;
  1029. }
  1030. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1031. if (chip == NULL) {
  1032. pci_disable_device(pci);
  1033. return -ENOMEM;
  1034. }
  1035. chip->card = card;
  1036. chip->pci = pci;
  1037. chip->irq = -1;
  1038. spin_lock_init(&chip->emu_lock);
  1039. chip->port = pci_resource_start(pci, 0);
  1040. if ((chip->res_port = request_region(chip->port, 0x20,
  1041. "snd_ca0106")) == NULL) {
  1042. snd_ca0106_free(chip);
  1043. printk(KERN_ERR "cannot allocate the port\n");
  1044. return -EBUSY;
  1045. }
  1046. if (request_irq(pci->irq, snd_ca0106_interrupt,
  1047. SA_INTERRUPT|SA_SHIRQ, "snd_ca0106",
  1048. (void *)chip)) {
  1049. snd_ca0106_free(chip);
  1050. printk(KERN_ERR "cannot grab irq\n");
  1051. return -EBUSY;
  1052. }
  1053. chip->irq = pci->irq;
  1054. /* This stores the periods table. */
  1055. if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
  1056. snd_ca0106_free(chip);
  1057. return -ENOMEM;
  1058. }
  1059. pci_set_master(pci);
  1060. /* read revision & serial */
  1061. pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision);
  1062. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
  1063. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
  1064. #if 1
  1065. printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
  1066. chip->revision, chip->serial);
  1067. #endif
  1068. strcpy(card->driver, "CA0106");
  1069. strcpy(card->shortname, "CA0106");
  1070. for (c = ca0106_chip_details; c->serial; c++) {
  1071. if (c->serial == chip->serial)
  1072. break;
  1073. }
  1074. chip->details = c;
  1075. sprintf(card->longname, "%s at 0x%lx irq %i",
  1076. c->name, chip->port, chip->irq);
  1077. outl(0, chip->port + INTE);
  1078. /*
  1079. * Init to 0x02109204 :
  1080. * Clock accuracy = 0 (1000ppm)
  1081. * Sample Rate = 2 (48kHz)
  1082. * Audio Channel = 1 (Left of 2)
  1083. * Source Number = 0 (Unspecified)
  1084. * Generation Status = 1 (Original for Cat Code 12)
  1085. * Cat Code = 12 (Digital Signal Mixer)
  1086. * Mode = 0 (Mode 0)
  1087. * Emphasis = 0 (None)
  1088. * CP = 1 (Copyright unasserted)
  1089. * AN = 0 (Audio data)
  1090. * P = 0 (Consumer)
  1091. */
  1092. snd_ca0106_ptr_write(chip, SPCS0, 0,
  1093. chip->spdif_bits[0] =
  1094. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1095. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1096. SPCS_GENERATIONSTATUS | 0x00001200 |
  1097. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1098. /* Only SPCS1 has been tested */
  1099. snd_ca0106_ptr_write(chip, SPCS1, 0,
  1100. chip->spdif_bits[1] =
  1101. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1102. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1103. SPCS_GENERATIONSTATUS | 0x00001200 |
  1104. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1105. snd_ca0106_ptr_write(chip, SPCS2, 0,
  1106. chip->spdif_bits[2] =
  1107. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1108. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1109. SPCS_GENERATIONSTATUS | 0x00001200 |
  1110. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1111. snd_ca0106_ptr_write(chip, SPCS3, 0,
  1112. chip->spdif_bits[3] =
  1113. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1114. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1115. SPCS_GENERATIONSTATUS | 0x00001200 |
  1116. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1117. snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000);
  1118. snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000);
  1119. /* Write 0x8000 to AC97_REC_GAIN to mute it. */
  1120. outb(AC97_REC_GAIN, chip->port + AC97ADDRESS);
  1121. outw(0x8000, chip->port + AC97DATA);
  1122. #if 0
  1123. snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006);
  1124. snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006);
  1125. snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006);
  1126. snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006);
  1127. #endif
  1128. //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */
  1129. /* Analog or Digital output */
  1130. snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
  1131. snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
  1132. chip->spdif_enable = 0; /* Set digital SPDIF output off */
  1133. chip->capture_source = 3; /* Set CAPTURE_SOURCE */
  1134. //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */
  1135. //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */
  1136. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
  1137. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
  1138. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */
  1139. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
  1140. snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410);
  1141. snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676);
  1142. snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410);
  1143. snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676);
  1144. for(ch = 0; ch < 4; ch++) {
  1145. snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */
  1146. snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030);
  1147. //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */
  1148. //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */
  1149. snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */
  1150. snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */
  1151. }
  1152. snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Select MIC, Line in, TAD in, AUX in */
  1153. chip->capture_source = 3; /* Set CAPTURE_SOURCE */
  1154. if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */
  1155. /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
  1156. outl(0x0, chip->port+GPIO);
  1157. //outl(0x00f0e000, chip->port+GPIO); /* Analog */
  1158. outl(0x005f5301, chip->port+GPIO); /* Analog */
  1159. } else {
  1160. outl(0x0, chip->port+GPIO);
  1161. outl(0x005f03a3, chip->port+GPIO); /* Analog */
  1162. //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */
  1163. }
  1164. snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */
  1165. //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
  1166. //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
  1167. //outl(0x00000009, chip->port+HCFG);
  1168. outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */
  1169. if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
  1170. snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */
  1171. }
  1172. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
  1173. chip, &ops)) < 0) {
  1174. snd_ca0106_free(chip);
  1175. return err;
  1176. }
  1177. *rchip = chip;
  1178. return 0;
  1179. }
  1180. static void ca0106_midi_interrupt_enable(struct snd_ca_midi *midi, int intr)
  1181. {
  1182. snd_ca0106_intr_enable((struct snd_ca0106 *)(midi->dev_id), intr);
  1183. }
  1184. static void ca0106_midi_interrupt_disable(struct snd_ca_midi *midi, int intr)
  1185. {
  1186. snd_ca0106_intr_disable((struct snd_ca0106 *)(midi->dev_id), intr);
  1187. }
  1188. static unsigned char ca0106_midi_read(struct snd_ca_midi *midi, int idx)
  1189. {
  1190. return (unsigned char)snd_ca0106_ptr_read((struct snd_ca0106 *)(midi->dev_id),
  1191. midi->port + idx, 0);
  1192. }
  1193. static void ca0106_midi_write(struct snd_ca_midi *midi, int data, int idx)
  1194. {
  1195. snd_ca0106_ptr_write((struct snd_ca0106 *)(midi->dev_id), midi->port + idx, 0, data);
  1196. }
  1197. static struct snd_card *ca0106_dev_id_card(void *dev_id)
  1198. {
  1199. return ((struct snd_ca0106 *)dev_id)->card;
  1200. }
  1201. static int ca0106_dev_id_port(void *dev_id)
  1202. {
  1203. return ((struct snd_ca0106 *)dev_id)->port;
  1204. }
  1205. static int __devinit snd_ca0106_midi(struct snd_ca0106 *chip, unsigned int channel)
  1206. {
  1207. struct snd_ca_midi *midi;
  1208. char *name;
  1209. int err;
  1210. if (channel == CA0106_MIDI_CHAN_B) {
  1211. name = "CA0106 MPU-401 (UART) B";
  1212. midi = &chip->midi2;
  1213. midi->tx_enable = INTE_MIDI_TX_B;
  1214. midi->rx_enable = INTE_MIDI_RX_B;
  1215. midi->ipr_tx = IPR_MIDI_TX_B;
  1216. midi->ipr_rx = IPR_MIDI_RX_B;
  1217. midi->port = MIDI_UART_B_DATA;
  1218. } else {
  1219. name = "CA0106 MPU-401 (UART)";
  1220. midi = &chip->midi;
  1221. midi->tx_enable = INTE_MIDI_TX_A;
  1222. midi->rx_enable = INTE_MIDI_TX_B;
  1223. midi->ipr_tx = IPR_MIDI_TX_A;
  1224. midi->ipr_rx = IPR_MIDI_RX_A;
  1225. midi->port = MIDI_UART_A_DATA;
  1226. }
  1227. midi->reset = CA0106_MPU401_RESET;
  1228. midi->enter_uart = CA0106_MPU401_ENTER_UART;
  1229. midi->ack = CA0106_MPU401_ACK;
  1230. midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
  1231. midi->output_ready = CA0106_MIDI_OUTPUT_READY;
  1232. midi->channel = channel;
  1233. midi->interrupt_enable = ca0106_midi_interrupt_enable;
  1234. midi->interrupt_disable = ca0106_midi_interrupt_disable;
  1235. midi->read = ca0106_midi_read;
  1236. midi->write = ca0106_midi_write;
  1237. midi->get_dev_id_card = ca0106_dev_id_card;
  1238. midi->get_dev_id_port = ca0106_dev_id_port;
  1239. midi->dev_id = chip;
  1240. if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
  1241. return err;
  1242. return 0;
  1243. }
  1244. static int __devinit snd_ca0106_probe(struct pci_dev *pci,
  1245. const struct pci_device_id *pci_id)
  1246. {
  1247. static int dev;
  1248. struct snd_card *card;
  1249. struct snd_ca0106 *chip;
  1250. int err;
  1251. if (dev >= SNDRV_CARDS)
  1252. return -ENODEV;
  1253. if (!enable[dev]) {
  1254. dev++;
  1255. return -ENOENT;
  1256. }
  1257. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1258. if (card == NULL)
  1259. return -ENOMEM;
  1260. if ((err = snd_ca0106_create(card, pci, &chip)) < 0) {
  1261. snd_card_free(card);
  1262. return err;
  1263. }
  1264. if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) {
  1265. snd_card_free(card);
  1266. return err;
  1267. }
  1268. if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) {
  1269. snd_card_free(card);
  1270. return err;
  1271. }
  1272. if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) {
  1273. snd_card_free(card);
  1274. return err;
  1275. }
  1276. if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) {
  1277. snd_card_free(card);
  1278. return err;
  1279. }
  1280. if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
  1281. if ((err = snd_ca0106_ac97(chip)) < 0) {
  1282. snd_card_free(card);
  1283. return err;
  1284. }
  1285. }
  1286. if ((err = snd_ca0106_mixer(chip)) < 0) {
  1287. snd_card_free(card);
  1288. return err;
  1289. }
  1290. snd_printdd("ca0106: probe for MIDI channel A ...");
  1291. if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
  1292. snd_card_free(card);
  1293. snd_printdd(" failed, err=0x%x\n",err);
  1294. return err;
  1295. }
  1296. snd_printdd(" done.\n");
  1297. snd_ca0106_proc_init(chip);
  1298. if ((err = snd_card_register(card)) < 0) {
  1299. snd_card_free(card);
  1300. return err;
  1301. }
  1302. pci_set_drvdata(pci, card);
  1303. dev++;
  1304. return 0;
  1305. }
  1306. static void __devexit snd_ca0106_remove(struct pci_dev *pci)
  1307. {
  1308. snd_card_free(pci_get_drvdata(pci));
  1309. pci_set_drvdata(pci, NULL);
  1310. }
  1311. // PCI IDs
  1312. static struct pci_device_id snd_ca0106_ids[] = {
  1313. { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */
  1314. { 0, }
  1315. };
  1316. MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
  1317. // pci_driver definition
  1318. static struct pci_driver driver = {
  1319. .name = "CA0106",
  1320. .id_table = snd_ca0106_ids,
  1321. .probe = snd_ca0106_probe,
  1322. .remove = __devexit_p(snd_ca0106_remove),
  1323. };
  1324. // initialization of the module
  1325. static int __init alsa_card_ca0106_init(void)
  1326. {
  1327. return pci_register_driver(&driver);
  1328. }
  1329. // clean up the module
  1330. static void __exit alsa_card_ca0106_exit(void)
  1331. {
  1332. pci_unregister_driver(&driver);
  1333. }
  1334. module_init(alsa_card_ca0106_init)
  1335. module_exit(alsa_card_ca0106_exit)