ca0106_main.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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 ca0106_details_t 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 snd_pcm_hardware_t 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 | SNDRV_PCM_RATE_192000,
  205. .rate_min = 48000,
  206. .rate_max = 192000,
  207. .channels_min = 2, //1,
  208. .channels_max = 2, //6,
  209. .buffer_bytes_max = ((65536 - 64) * 8),
  210. .period_bytes_min = 64,
  211. .period_bytes_max = (65536 - 64),
  212. .periods_min = 2,
  213. .periods_max = 8,
  214. .fifo_size = 0,
  215. };
  216. static snd_pcm_hardware_t snd_ca0106_capture_hw = {
  217. .info = (SNDRV_PCM_INFO_MMAP |
  218. SNDRV_PCM_INFO_INTERLEAVED |
  219. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  220. SNDRV_PCM_INFO_MMAP_VALID),
  221. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
  222. .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
  223. .rate_min = 44100,
  224. .rate_max = 192000,
  225. .channels_min = 2,
  226. .channels_max = 2,
  227. .buffer_bytes_max = ((65536 - 64) * 8),
  228. .period_bytes_min = 64,
  229. .period_bytes_max = (65536 - 64),
  230. .periods_min = 2,
  231. .periods_max = 2,
  232. .fifo_size = 0,
  233. };
  234. unsigned int snd_ca0106_ptr_read(ca0106_t * emu,
  235. unsigned int reg,
  236. unsigned int chn)
  237. {
  238. unsigned long flags;
  239. unsigned int regptr, val;
  240. regptr = (reg << 16) | chn;
  241. spin_lock_irqsave(&emu->emu_lock, flags);
  242. outl(regptr, emu->port + PTR);
  243. val = inl(emu->port + DATA);
  244. spin_unlock_irqrestore(&emu->emu_lock, flags);
  245. return val;
  246. }
  247. void snd_ca0106_ptr_write(ca0106_t *emu,
  248. unsigned int reg,
  249. unsigned int chn,
  250. unsigned int data)
  251. {
  252. unsigned int regptr;
  253. unsigned long flags;
  254. regptr = (reg << 16) | chn;
  255. spin_lock_irqsave(&emu->emu_lock, flags);
  256. outl(regptr, emu->port + PTR);
  257. outl(data, emu->port + DATA);
  258. spin_unlock_irqrestore(&emu->emu_lock, flags);
  259. }
  260. int snd_ca0106_i2c_write(ca0106_t *emu,
  261. u32 reg,
  262. u32 value)
  263. {
  264. u32 tmp;
  265. int timeout=0;
  266. int status;
  267. int retry;
  268. if ((reg > 0x7f) || (value > 0x1ff))
  269. {
  270. snd_printk(KERN_ERR "i2c_write: invalid values.\n");
  271. return -EINVAL;
  272. }
  273. tmp = reg << 25 | value << 16;
  274. /* Not sure what this I2C channel controls. */
  275. /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
  276. /* This controls the I2C connected to the WM8775 ADC Codec */
  277. snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
  278. for(retry=0;retry<10;retry++)
  279. {
  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. {
  288. status = snd_ca0106_ptr_read(emu, I2C_A, 0);
  289. //snd_printk("I2C:status=0x%x\n", status);
  290. timeout++;
  291. if((status & I2C_A_ADC_START)==0)
  292. break;
  293. if(timeout>1000)
  294. break;
  295. }
  296. //Read back and see if the transaction is successful
  297. if((status & I2C_A_ADC_ABORT)==0)
  298. break;
  299. }
  300. if(retry==10)
  301. {
  302. snd_printk(KERN_ERR "Writing to ADC failed!\n");
  303. return -EINVAL;
  304. }
  305. return 0;
  306. }
  307. static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb)
  308. {
  309. unsigned long flags;
  310. unsigned int enable;
  311. spin_lock_irqsave(&emu->emu_lock, flags);
  312. enable = inl(emu->port + INTE) | intrenb;
  313. outl(enable, emu->port + INTE);
  314. spin_unlock_irqrestore(&emu->emu_lock, flags);
  315. }
  316. static void snd_ca0106_intr_disable(ca0106_t *emu, unsigned int intrenb)
  317. {
  318. unsigned long flags;
  319. unsigned int enable;
  320. spin_lock_irqsave(&emu->emu_lock, flags);
  321. enable = inl(emu->port + INTE) & ~intrenb;
  322. outl(enable, emu->port + INTE);
  323. spin_unlock_irqrestore(&emu->emu_lock, flags);
  324. }
  325. static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime)
  326. {
  327. kfree(runtime->private_data);
  328. }
  329. /* open_playback callback */
  330. static int snd_ca0106_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
  331. {
  332. ca0106_t *chip = snd_pcm_substream_chip(substream);
  333. ca0106_channel_t *channel = &(chip->playback_channels[channel_id]);
  334. ca0106_pcm_t *epcm;
  335. snd_pcm_runtime_t *runtime = substream->runtime;
  336. int err;
  337. epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
  338. if (epcm == NULL)
  339. return -ENOMEM;
  340. epcm->emu = chip;
  341. epcm->substream = substream;
  342. epcm->channel_id=channel_id;
  343. runtime->private_data = epcm;
  344. runtime->private_free = snd_ca0106_pcm_free_substream;
  345. runtime->hw = snd_ca0106_playback_hw;
  346. channel->emu = chip;
  347. channel->number = channel_id;
  348. channel->use=1;
  349. //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
  350. //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
  351. channel->epcm=epcm;
  352. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  353. return err;
  354. if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
  355. return err;
  356. return 0;
  357. }
  358. /* close callback */
  359. static int snd_ca0106_pcm_close_playback(snd_pcm_substream_t *substream)
  360. {
  361. ca0106_t *chip = snd_pcm_substream_chip(substream);
  362. snd_pcm_runtime_t *runtime = substream->runtime;
  363. ca0106_pcm_t *epcm = runtime->private_data;
  364. chip->playback_channels[epcm->channel_id].use=0;
  365. /* FIXME: maybe zero others */
  366. return 0;
  367. }
  368. static int snd_ca0106_pcm_open_playback_front(snd_pcm_substream_t *substream)
  369. {
  370. return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
  371. }
  372. static int snd_ca0106_pcm_open_playback_center_lfe(snd_pcm_substream_t *substream)
  373. {
  374. return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL);
  375. }
  376. static int snd_ca0106_pcm_open_playback_unknown(snd_pcm_substream_t *substream)
  377. {
  378. return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL);
  379. }
  380. static int snd_ca0106_pcm_open_playback_rear(snd_pcm_substream_t *substream)
  381. {
  382. return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL);
  383. }
  384. /* open_capture callback */
  385. static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, int channel_id)
  386. {
  387. ca0106_t *chip = snd_pcm_substream_chip(substream);
  388. ca0106_channel_t *channel = &(chip->capture_channels[channel_id]);
  389. ca0106_pcm_t *epcm;
  390. snd_pcm_runtime_t *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(snd_pcm_substream_t *substream)
  418. {
  419. ca0106_t *chip = snd_pcm_substream_chip(substream);
  420. snd_pcm_runtime_t *runtime = substream->runtime;
  421. ca0106_pcm_t *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(snd_pcm_substream_t *substream)
  427. {
  428. return snd_ca0106_pcm_open_capture_channel(substream, 0);
  429. }
  430. static int snd_ca0106_pcm_open_1_capture(snd_pcm_substream_t *substream)
  431. {
  432. return snd_ca0106_pcm_open_capture_channel(substream, 1);
  433. }
  434. static int snd_ca0106_pcm_open_2_capture(snd_pcm_substream_t *substream)
  435. {
  436. return snd_ca0106_pcm_open_capture_channel(substream, 2);
  437. }
  438. static int snd_ca0106_pcm_open_3_capture(snd_pcm_substream_t *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(snd_pcm_substream_t *substream,
  444. snd_pcm_hw_params_t * 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(snd_pcm_substream_t *substream)
  451. {
  452. return snd_pcm_lib_free_pages(substream);
  453. }
  454. /* hw_params callback */
  455. static int snd_ca0106_pcm_hw_params_capture(snd_pcm_substream_t *substream,
  456. snd_pcm_hw_params_t * 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(snd_pcm_substream_t *substream)
  463. {
  464. return snd_pcm_lib_free_pages(substream);
  465. }
  466. /* prepare playback callback */
  467. static int snd_ca0106_pcm_prepare_playback(snd_pcm_substream_t *substream)
  468. {
  469. ca0106_t *emu = snd_pcm_substream_chip(substream);
  470. snd_pcm_runtime_t *runtime = substream->runtime;
  471. ca0106_pcm_t *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(snd_pcm_substream_t *substream)
  564. {
  565. ca0106_t *emu = snd_pcm_substream_chip(substream);
  566. snd_pcm_runtime_t *runtime = substream->runtime;
  567. ca0106_pcm_t *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(snd_pcm_substream_t *substream,
  630. int cmd)
  631. {
  632. ca0106_t *emu = snd_pcm_substream_chip(substream);
  633. snd_pcm_runtime_t *runtime;
  634. ca0106_pcm_t *epcm;
  635. int channel;
  636. int result = 0;
  637. struct list_head *pos;
  638. snd_pcm_substream_t *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(snd_pcm_substream_t *substream,
  680. int cmd)
  681. {
  682. ca0106_t *emu = snd_pcm_substream_chip(substream);
  683. snd_pcm_runtime_t *runtime = substream->runtime;
  684. ca0106_pcm_t *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(snd_pcm_substream_t *substream)
  707. {
  708. ca0106_t *emu = snd_pcm_substream_chip(substream);
  709. snd_pcm_runtime_t *runtime = substream->runtime;
  710. ca0106_pcm_t *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(snd_pcm_substream_t *substream)
  730. {
  731. ca0106_t *emu = snd_pcm_substream_chip(substream);
  732. snd_pcm_runtime_t *runtime = substream->runtime;
  733. ca0106_pcm_t *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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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 snd_pcm_ops_t 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(ac97_t *ac97,
  828. unsigned short reg)
  829. {
  830. ca0106_t *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(ac97_t *ac97,
  840. unsigned short reg, unsigned short val)
  841. {
  842. ca0106_t *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(ca0106_t *chip)
  850. {
  851. ac97_bus_t *pbus;
  852. ac97_template_t ac97;
  853. int err;
  854. static ac97_bus_ops_t 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(ca0106_t *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(snd_device_t *device)
  897. {
  898. ca0106_t *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. ca0106_t *chip = dev_id;
  906. int i;
  907. int mask;
  908. unsigned int stat76;
  909. ca0106_channel_t *pchannel;
  910. spin_lock(&chip->emu_lock);
  911. status = inl(chip->port + IPR);
  912. // call updater, unlock before it
  913. spin_unlock(&chip->emu_lock);
  914. if (! status)
  915. return IRQ_NONE;
  916. stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0);
  917. //snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76);
  918. //snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
  919. mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
  920. for(i = 0; i < 4; i++) {
  921. pchannel = &(chip->playback_channels[i]);
  922. if(stat76 & mask) {
  923. /* FIXME: Select the correct substream for period elapsed */
  924. if(pchannel->use) {
  925. snd_pcm_period_elapsed(pchannel->epcm->substream);
  926. //printk(KERN_INFO "interrupt [%d] used\n", i);
  927. }
  928. }
  929. //printk(KERN_INFO "channel=%p\n",pchannel);
  930. //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
  931. mask <<= 1;
  932. }
  933. mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
  934. for(i = 0; i < 4; i++) {
  935. pchannel = &(chip->capture_channels[i]);
  936. if(stat76 & mask) {
  937. /* FIXME: Select the correct substream for period elapsed */
  938. if(pchannel->use) {
  939. snd_pcm_period_elapsed(pchannel->epcm->substream);
  940. //printk(KERN_INFO "interrupt [%d] used\n", i);
  941. }
  942. }
  943. //printk(KERN_INFO "channel=%p\n",pchannel);
  944. //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
  945. mask <<= 1;
  946. }
  947. snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
  948. spin_lock(&chip->emu_lock);
  949. if (chip->midi.dev_id &&
  950. (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
  951. if (chip->midi.interrupt)
  952. chip->midi.interrupt(&chip->midi, status);
  953. else
  954. chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
  955. }
  956. // acknowledge the interrupt if necessary
  957. outl(status, chip->port+IPR);
  958. spin_unlock(&chip->emu_lock);
  959. return IRQ_HANDLED;
  960. }
  961. static int __devinit snd_ca0106_pcm(ca0106_t *emu, int device, snd_pcm_t **rpcm)
  962. {
  963. snd_pcm_t *pcm;
  964. snd_pcm_substream_t *substream;
  965. int err;
  966. if (rpcm)
  967. *rpcm = NULL;
  968. if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
  969. return err;
  970. pcm->private_data = emu;
  971. switch (device) {
  972. case 0:
  973. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_front_ops);
  974. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_0_ops);
  975. break;
  976. case 1:
  977. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_rear_ops);
  978. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_1_ops);
  979. break;
  980. case 2:
  981. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_center_lfe_ops);
  982. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_2_ops);
  983. break;
  984. case 3:
  985. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_unknown_ops);
  986. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_3_ops);
  987. break;
  988. }
  989. pcm->info_flags = 0;
  990. pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
  991. strcpy(pcm->name, "CA0106");
  992. emu->pcm = pcm;
  993. for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  994. substream;
  995. substream = substream->next) {
  996. if ((err = snd_pcm_lib_preallocate_pages(substream,
  997. SNDRV_DMA_TYPE_DEV,
  998. snd_dma_pci_data(emu->pci),
  999. 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
  1000. return err;
  1001. }
  1002. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  1003. substream;
  1004. substream = substream->next) {
  1005. if ((err = snd_pcm_lib_preallocate_pages(substream,
  1006. SNDRV_DMA_TYPE_DEV,
  1007. snd_dma_pci_data(emu->pci),
  1008. 64*1024, 64*1024)) < 0)
  1009. return err;
  1010. }
  1011. if (rpcm)
  1012. *rpcm = pcm;
  1013. return 0;
  1014. }
  1015. static int __devinit snd_ca0106_create(snd_card_t *card,
  1016. struct pci_dev *pci,
  1017. ca0106_t **rchip)
  1018. {
  1019. ca0106_t *chip;
  1020. ca0106_details_t *c;
  1021. int err;
  1022. int ch;
  1023. static snd_device_ops_t ops = {
  1024. .dev_free = snd_ca0106_dev_free,
  1025. };
  1026. *rchip = NULL;
  1027. if ((err = pci_enable_device(pci)) < 0)
  1028. return err;
  1029. if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
  1030. pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
  1031. printk(KERN_ERR "error to set 32bit mask DMA\n");
  1032. pci_disable_device(pci);
  1033. return -ENXIO;
  1034. }
  1035. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  1036. if (chip == NULL) {
  1037. pci_disable_device(pci);
  1038. return -ENOMEM;
  1039. }
  1040. chip->card = card;
  1041. chip->pci = pci;
  1042. chip->irq = -1;
  1043. spin_lock_init(&chip->emu_lock);
  1044. chip->port = pci_resource_start(pci, 0);
  1045. if ((chip->res_port = request_region(chip->port, 0x20,
  1046. "snd_ca0106")) == NULL) {
  1047. snd_ca0106_free(chip);
  1048. printk(KERN_ERR "cannot allocate the port\n");
  1049. return -EBUSY;
  1050. }
  1051. if (request_irq(pci->irq, snd_ca0106_interrupt,
  1052. SA_INTERRUPT|SA_SHIRQ, "snd_ca0106",
  1053. (void *)chip)) {
  1054. snd_ca0106_free(chip);
  1055. printk(KERN_ERR "cannot grab irq\n");
  1056. return -EBUSY;
  1057. }
  1058. chip->irq = pci->irq;
  1059. /* This stores the periods table. */
  1060. if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
  1061. snd_ca0106_free(chip);
  1062. return -ENOMEM;
  1063. }
  1064. pci_set_master(pci);
  1065. /* read revision & serial */
  1066. pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision);
  1067. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
  1068. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
  1069. #if 1
  1070. printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
  1071. chip->revision, chip->serial);
  1072. #endif
  1073. strcpy(card->driver, "CA0106");
  1074. strcpy(card->shortname, "CA0106");
  1075. for (c=ca0106_chip_details; c->serial; c++) {
  1076. if (c->serial == chip->serial) break;
  1077. }
  1078. chip->details = c;
  1079. sprintf(card->longname, "%s at 0x%lx irq %i",
  1080. c->name, chip->port, chip->irq);
  1081. outl(0, chip->port + INTE);
  1082. /*
  1083. * Init to 0x02109204 :
  1084. * Clock accuracy = 0 (1000ppm)
  1085. * Sample Rate = 2 (48kHz)
  1086. * Audio Channel = 1 (Left of 2)
  1087. * Source Number = 0 (Unspecified)
  1088. * Generation Status = 1 (Original for Cat Code 12)
  1089. * Cat Code = 12 (Digital Signal Mixer)
  1090. * Mode = 0 (Mode 0)
  1091. * Emphasis = 0 (None)
  1092. * CP = 1 (Copyright unasserted)
  1093. * AN = 0 (Audio data)
  1094. * P = 0 (Consumer)
  1095. */
  1096. snd_ca0106_ptr_write(chip, SPCS0, 0,
  1097. chip->spdif_bits[0] =
  1098. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1099. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1100. SPCS_GENERATIONSTATUS | 0x00001200 |
  1101. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1102. /* Only SPCS1 has been tested */
  1103. snd_ca0106_ptr_write(chip, SPCS1, 0,
  1104. chip->spdif_bits[1] =
  1105. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1106. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1107. SPCS_GENERATIONSTATUS | 0x00001200 |
  1108. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1109. snd_ca0106_ptr_write(chip, SPCS2, 0,
  1110. chip->spdif_bits[2] =
  1111. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1112. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1113. SPCS_GENERATIONSTATUS | 0x00001200 |
  1114. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1115. snd_ca0106_ptr_write(chip, SPCS3, 0,
  1116. chip->spdif_bits[3] =
  1117. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1118. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1119. SPCS_GENERATIONSTATUS | 0x00001200 |
  1120. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  1121. snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000);
  1122. snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000);
  1123. /* Write 0x8000 to AC97_REC_GAIN to mute it. */
  1124. outb(AC97_REC_GAIN, chip->port + AC97ADDRESS);
  1125. outw(0x8000, chip->port + AC97DATA);
  1126. #if 0
  1127. snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006);
  1128. snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006);
  1129. snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006);
  1130. snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006);
  1131. #endif
  1132. //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */
  1133. /* Analog or Digital output */
  1134. snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
  1135. snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
  1136. chip->spdif_enable = 0; /* Set digital SPDIF output off */
  1137. chip->capture_source = 3; /* Set CAPTURE_SOURCE */
  1138. //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */
  1139. //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */
  1140. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
  1141. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
  1142. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */
  1143. snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
  1144. snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410);
  1145. snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676);
  1146. snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410);
  1147. snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676);
  1148. for(ch = 0; ch < 4; ch++) {
  1149. snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */
  1150. snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030);
  1151. //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */
  1152. //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */
  1153. snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */
  1154. snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */
  1155. }
  1156. snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Select MIC, Line in, TAD in, AUX in */
  1157. chip->capture_source = 3; /* Set CAPTURE_SOURCE */
  1158. if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */
  1159. /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
  1160. outl(0x0, chip->port+GPIO);
  1161. //outl(0x00f0e000, chip->port+GPIO); /* Analog */
  1162. outl(0x005f5301, chip->port+GPIO); /* Analog */
  1163. } else {
  1164. outl(0x0, chip->port+GPIO);
  1165. outl(0x005f03a3, chip->port+GPIO); /* Analog */
  1166. //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */
  1167. }
  1168. snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */
  1169. //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
  1170. //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
  1171. //outl(0x00000009, chip->port+HCFG);
  1172. outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */
  1173. if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
  1174. snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */
  1175. }
  1176. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
  1177. chip, &ops)) < 0) {
  1178. snd_ca0106_free(chip);
  1179. return err;
  1180. }
  1181. *rchip = chip;
  1182. return 0;
  1183. }
  1184. static void ca0106_midi_interrupt_enable(ca_midi_t *midi, int intr)
  1185. {
  1186. snd_ca0106_intr_enable((ca0106_t *)(midi->dev_id), intr);
  1187. }
  1188. static void ca0106_midi_interrupt_disable(ca_midi_t *midi, int intr)
  1189. {
  1190. snd_ca0106_intr_disable((ca0106_t *)(midi->dev_id), intr);
  1191. }
  1192. static unsigned char ca0106_midi_read(ca_midi_t *midi, int idx)
  1193. {
  1194. return (unsigned char)snd_ca0106_ptr_read((ca0106_t *)(midi->dev_id), midi->port + idx, 0);
  1195. }
  1196. static void ca0106_midi_write(ca_midi_t *midi, int data, int idx)
  1197. {
  1198. snd_ca0106_ptr_write((ca0106_t *)(midi->dev_id), midi->port + idx, 0, data);
  1199. }
  1200. static snd_card_t *ca0106_dev_id_card(void *dev_id)
  1201. {
  1202. return ((ca0106_t *)dev_id)->card;
  1203. }
  1204. static int ca0106_dev_id_port(void *dev_id)
  1205. {
  1206. return ((ca0106_t *)dev_id)->port;
  1207. }
  1208. static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel)
  1209. {
  1210. ca_midi_t *midi;
  1211. char *name;
  1212. int err;
  1213. if(channel==CA0106_MIDI_CHAN_B) {
  1214. name = "CA0106 MPU-401 (UART) B";
  1215. midi = &chip->midi2;
  1216. midi->tx_enable = INTE_MIDI_TX_B;
  1217. midi->rx_enable = INTE_MIDI_RX_B;
  1218. midi->ipr_tx = IPR_MIDI_TX_B;
  1219. midi->ipr_rx = IPR_MIDI_RX_B;
  1220. midi->port = MIDI_UART_B_DATA;
  1221. } else {
  1222. name = "CA0106 MPU-401 (UART)";
  1223. midi = &chip->midi;
  1224. midi->tx_enable = INTE_MIDI_TX_A;
  1225. midi->rx_enable = INTE_MIDI_TX_B;
  1226. midi->ipr_tx = IPR_MIDI_TX_A;
  1227. midi->ipr_rx = IPR_MIDI_RX_A;
  1228. midi->port = MIDI_UART_A_DATA;
  1229. }
  1230. midi->reset = CA0106_MPU401_RESET;
  1231. midi->enter_uart = CA0106_MPU401_ENTER_UART;
  1232. midi->ack = CA0106_MPU401_ACK;
  1233. midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
  1234. midi->output_ready = CA0106_MIDI_OUTPUT_READY;
  1235. midi->channel = channel;
  1236. midi->interrupt_enable = ca0106_midi_interrupt_enable;
  1237. midi->interrupt_disable = ca0106_midi_interrupt_disable;
  1238. midi->read = ca0106_midi_read;
  1239. midi->write = ca0106_midi_write;
  1240. midi->get_dev_id_card = ca0106_dev_id_card;
  1241. midi->get_dev_id_port = ca0106_dev_id_port;
  1242. midi->dev_id = chip;
  1243. if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
  1244. return err;
  1245. return 0;
  1246. }
  1247. static int __devinit snd_ca0106_probe(struct pci_dev *pci,
  1248. const struct pci_device_id *pci_id)
  1249. {
  1250. static int dev;
  1251. snd_card_t *card;
  1252. ca0106_t *chip;
  1253. int err;
  1254. if (dev >= SNDRV_CARDS)
  1255. return -ENODEV;
  1256. if (!enable[dev]) {
  1257. dev++;
  1258. return -ENOENT;
  1259. }
  1260. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1261. if (card == NULL)
  1262. return -ENOMEM;
  1263. if ((err = snd_ca0106_create(card, pci, &chip)) < 0) {
  1264. snd_card_free(card);
  1265. return err;
  1266. }
  1267. if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) {
  1268. snd_card_free(card);
  1269. return err;
  1270. }
  1271. if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) {
  1272. snd_card_free(card);
  1273. return err;
  1274. }
  1275. if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) {
  1276. snd_card_free(card);
  1277. return err;
  1278. }
  1279. if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) {
  1280. snd_card_free(card);
  1281. return err;
  1282. }
  1283. if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
  1284. if ((err = snd_ca0106_ac97(chip)) < 0) {
  1285. snd_card_free(card);
  1286. return err;
  1287. }
  1288. }
  1289. if ((err = snd_ca0106_mixer(chip)) < 0) {
  1290. snd_card_free(card);
  1291. return err;
  1292. }
  1293. snd_printdd("ca0106: probe for MIDI channel A ...");
  1294. if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
  1295. snd_card_free(card);
  1296. snd_printdd(" failed, err=0x%x\n",err);
  1297. return err;
  1298. }
  1299. snd_printdd(" done.\n");
  1300. snd_ca0106_proc_init(chip);
  1301. if ((err = snd_card_register(card)) < 0) {
  1302. snd_card_free(card);
  1303. return err;
  1304. }
  1305. pci_set_drvdata(pci, card);
  1306. dev++;
  1307. return 0;
  1308. }
  1309. static void __devexit snd_ca0106_remove(struct pci_dev *pci)
  1310. {
  1311. snd_card_free(pci_get_drvdata(pci));
  1312. pci_set_drvdata(pci, NULL);
  1313. }
  1314. // PCI IDs
  1315. static struct pci_device_id snd_ca0106_ids[] = {
  1316. { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */
  1317. { 0, }
  1318. };
  1319. MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
  1320. // pci_driver definition
  1321. static struct pci_driver driver = {
  1322. .name = "CA0106",
  1323. .id_table = snd_ca0106_ids,
  1324. .probe = snd_ca0106_probe,
  1325. .remove = __devexit_p(snd_ca0106_remove),
  1326. };
  1327. // initialization of the module
  1328. static int __init alsa_card_ca0106_init(void)
  1329. {
  1330. int err;
  1331. if ((err = pci_register_driver(&driver)) > 0)
  1332. return err;
  1333. return 0;
  1334. }
  1335. // clean up the module
  1336. static void __exit alsa_card_ca0106_exit(void)
  1337. {
  1338. pci_unregister_driver(&driver);
  1339. }
  1340. module_init(alsa_card_ca0106_init)
  1341. module_exit(alsa_card_ca0106_exit)