emu10k1x.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. /*
  2. * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
  3. * Driver EMU10K1X chips
  4. *
  5. * Parts of this code were adapted from audigyls.c driver which is
  6. * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
  7. *
  8. * BUGS:
  9. * --
  10. *
  11. * TODO:
  12. *
  13. * Chips (SB0200 model):
  14. * - EMU10K1X-DBQ
  15. * - STAC 9708T
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. */
  32. #include <sound/driver.h>
  33. #include <linux/init.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/pci.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/slab.h>
  38. #include <linux/moduleparam.h>
  39. #include <sound/core.h>
  40. #include <sound/initval.h>
  41. #include <sound/pcm.h>
  42. #include <sound/ac97_codec.h>
  43. #include <sound/info.h>
  44. #include <sound/rawmidi.h>
  45. MODULE_AUTHOR("Francisco Moraes <fmoraes@nc.rr.com>");
  46. MODULE_DESCRIPTION("EMU10K1X");
  47. MODULE_LICENSE("GPL");
  48. MODULE_SUPPORTED_DEVICE("{{Dell Creative Labs,SB Live!}");
  49. // module parameters (see "Module Parameters")
  50. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  51. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  52. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  53. module_param_array(index, int, NULL, 0444);
  54. MODULE_PARM_DESC(index, "Index value for the EMU10K1X soundcard.");
  55. module_param_array(id, charp, NULL, 0444);
  56. MODULE_PARM_DESC(id, "ID string for the EMU10K1X soundcard.");
  57. module_param_array(enable, bool, NULL, 0444);
  58. MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
  59. // some definitions were borrowed from emu10k1 driver as they seem to be the same
  60. /************************************************************************************************/
  61. /* PCI function 0 registers, address = <val> + PCIBASE0 */
  62. /************************************************************************************************/
  63. #define PTR 0x00 /* Indexed register set pointer register */
  64. /* NOTE: The CHANNELNUM and ADDRESS words can */
  65. /* be modified independently of each other. */
  66. #define DATA 0x04 /* Indexed register set data register */
  67. #define IPR 0x08 /* Global interrupt pending register */
  68. /* Clear pending interrupts by writing a 1 to */
  69. /* the relevant bits and zero to the other bits */
  70. #define IPR_MIDITRANSBUFEMPTY 0x00000001 /* MIDI UART transmit buffer empty */
  71. #define IPR_MIDIRECVBUFEMPTY 0x00000002 /* MIDI UART receive buffer empty */
  72. #define IPR_CH_0_LOOP 0x00000800 /* Channel 0 loop */
  73. #define IPR_CH_0_HALF_LOOP 0x00000100 /* Channel 0 half loop */
  74. #define IPR_CAP_0_LOOP 0x00080000 /* Channel capture loop */
  75. #define IPR_CAP_0_HALF_LOOP 0x00010000 /* Channel capture half loop */
  76. #define INTE 0x0c /* Interrupt enable register */
  77. #define INTE_MIDITXENABLE 0x00000001 /* Enable MIDI transmit-buffer-empty interrupts */
  78. #define INTE_MIDIRXENABLE 0x00000002 /* Enable MIDI receive-buffer-empty interrupts */
  79. #define INTE_CH_0_LOOP 0x00000800 /* Channel 0 loop */
  80. #define INTE_CH_0_HALF_LOOP 0x00000100 /* Channel 0 half loop */
  81. #define INTE_CAP_0_LOOP 0x00080000 /* Channel capture loop */
  82. #define INTE_CAP_0_HALF_LOOP 0x00010000 /* Channel capture half loop */
  83. #define HCFG 0x14 /* Hardware config register */
  84. #define HCFG_LOCKSOUNDCACHE 0x00000008 /* 1 = Cancel bustmaster accesses to soundcache */
  85. /* NOTE: This should generally never be used. */
  86. #define HCFG_AUDIOENABLE 0x00000001 /* 0 = CODECs transmit zero-valued samples */
  87. /* Should be set to 1 when the EMU10K1 is */
  88. /* completely initialized. */
  89. #define GPIO 0x18 /* Defaults: 00001080-Analog, 00001000-SPDIF. */
  90. #define AC97DATA 0x1c /* AC97 register set data register (16 bit) */
  91. #define AC97ADDRESS 0x1e /* AC97 register set address register (8 bit) */
  92. /********************************************************************************************************/
  93. /* Emu10k1x pointer-offset register set, accessed through the PTR and DATA registers */
  94. /********************************************************************************************************/
  95. #define PLAYBACK_LIST_ADDR 0x00 /* Base DMA address of a list of pointers to each period/size */
  96. /* One list entry: 4 bytes for DMA address,
  97. * 4 bytes for period_size << 16.
  98. * One list entry is 8 bytes long.
  99. * One list entry for each period in the buffer.
  100. */
  101. #define PLAYBACK_LIST_SIZE 0x01 /* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000 */
  102. #define PLAYBACK_LIST_PTR 0x02 /* Pointer to the current period being played */
  103. #define PLAYBACK_DMA_ADDR 0x04 /* Playback DMA addresss */
  104. #define PLAYBACK_PERIOD_SIZE 0x05 /* Playback period size */
  105. #define PLAYBACK_POINTER 0x06 /* Playback period pointer. Sample currently in DAC */
  106. #define PLAYBACK_UNKNOWN1 0x07
  107. #define PLAYBACK_UNKNOWN2 0x08
  108. /* Only one capture channel supported */
  109. #define CAPTURE_DMA_ADDR 0x10 /* Capture DMA address */
  110. #define CAPTURE_BUFFER_SIZE 0x11 /* Capture buffer size */
  111. #define CAPTURE_POINTER 0x12 /* Capture buffer pointer. Sample currently in ADC */
  112. #define CAPTURE_UNKNOWN 0x13
  113. /* From 0x20 - 0x3f, last samples played on each channel */
  114. #define TRIGGER_CHANNEL 0x40 /* Trigger channel playback */
  115. #define TRIGGER_CHANNEL_0 0x00000001 /* Trigger channel 0 */
  116. #define TRIGGER_CHANNEL_1 0x00000002 /* Trigger channel 1 */
  117. #define TRIGGER_CHANNEL_2 0x00000004 /* Trigger channel 2 */
  118. #define TRIGGER_CAPTURE 0x00000100 /* Trigger capture channel */
  119. #define ROUTING 0x41 /* Setup sound routing ? */
  120. #define ROUTING_FRONT_LEFT 0x00000001
  121. #define ROUTING_FRONT_RIGHT 0x00000002
  122. #define ROUTING_REAR_LEFT 0x00000004
  123. #define ROUTING_REAR_RIGHT 0x00000008
  124. #define ROUTING_CENTER_LFE 0x00010000
  125. #define SPCS0 0x42 /* SPDIF output Channel Status 0 register */
  126. #define SPCS1 0x43 /* SPDIF output Channel Status 1 register */
  127. #define SPCS2 0x44 /* SPDIF output Channel Status 2 register */
  128. #define SPCS_CLKACCYMASK 0x30000000 /* Clock accuracy */
  129. #define SPCS_CLKACCY_1000PPM 0x00000000 /* 1000 parts per million */
  130. #define SPCS_CLKACCY_50PPM 0x10000000 /* 50 parts per million */
  131. #define SPCS_CLKACCY_VARIABLE 0x20000000 /* Variable accuracy */
  132. #define SPCS_SAMPLERATEMASK 0x0f000000 /* Sample rate */
  133. #define SPCS_SAMPLERATE_44 0x00000000 /* 44.1kHz sample rate */
  134. #define SPCS_SAMPLERATE_48 0x02000000 /* 48kHz sample rate */
  135. #define SPCS_SAMPLERATE_32 0x03000000 /* 32kHz sample rate */
  136. #define SPCS_CHANNELNUMMASK 0x00f00000 /* Channel number */
  137. #define SPCS_CHANNELNUM_UNSPEC 0x00000000 /* Unspecified channel number */
  138. #define SPCS_CHANNELNUM_LEFT 0x00100000 /* Left channel */
  139. #define SPCS_CHANNELNUM_RIGHT 0x00200000 /* Right channel */
  140. #define SPCS_SOURCENUMMASK 0x000f0000 /* Source number */
  141. #define SPCS_SOURCENUM_UNSPEC 0x00000000 /* Unspecified source number */
  142. #define SPCS_GENERATIONSTATUS 0x00008000 /* Originality flag (see IEC-958 spec) */
  143. #define SPCS_CATEGORYCODEMASK 0x00007f00 /* Category code (see IEC-958 spec) */
  144. #define SPCS_MODEMASK 0x000000c0 /* Mode (see IEC-958 spec) */
  145. #define SPCS_EMPHASISMASK 0x00000038 /* Emphasis */
  146. #define SPCS_EMPHASIS_NONE 0x00000000 /* No emphasis */
  147. #define SPCS_EMPHASIS_50_15 0x00000008 /* 50/15 usec 2 channel */
  148. #define SPCS_COPYRIGHT 0x00000004 /* Copyright asserted flag -- do not modify */
  149. #define SPCS_NOTAUDIODATA 0x00000002 /* 0 = Digital audio, 1 = not audio */
  150. #define SPCS_PROFESSIONAL 0x00000001 /* 0 = Consumer (IEC-958), 1 = pro (AES3-1992) */
  151. #define SPDIF_SELECT 0x45 /* Enables SPDIF or Analogue outputs 0-Analogue, 0x700-SPDIF */
  152. /* This is the MPU port on the card */
  153. #define MUDATA 0x47
  154. #define MUCMD 0x48
  155. #define MUSTAT MUCMD
  156. /* From 0x50 - 0x5f, last samples captured */
  157. /**
  158. * The hardware has 3 channels for playback and 1 for capture.
  159. * - channel 0 is the front channel
  160. * - channel 1 is the rear channel
  161. * - channel 2 is the center/lfe chanel
  162. * Volume is controlled by the AC97 for the front and rear channels by
  163. * the PCM Playback Volume, Sigmatel Surround Playback Volume and
  164. * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
  165. * the front/rear channel mixing in the REAR OUT jack. When using the
  166. * 4-Speaker Stereo, both front and rear channels will be mixed in the
  167. * REAR OUT.
  168. * The center/lfe channel has no volume control and cannot be muted during
  169. * playback.
  170. */
  171. struct emu10k1x_voice {
  172. struct emu10k1x *emu;
  173. int number;
  174. int use;
  175. struct emu10k1x_pcm *epcm;
  176. };
  177. struct emu10k1x_pcm {
  178. struct emu10k1x *emu;
  179. struct snd_pcm_substream *substream;
  180. struct emu10k1x_voice *voice;
  181. unsigned short running;
  182. };
  183. struct emu10k1x_midi {
  184. struct emu10k1x *emu;
  185. struct snd_rawmidi *rmidi;
  186. struct snd_rawmidi_substream *substream_input;
  187. struct snd_rawmidi_substream *substream_output;
  188. unsigned int midi_mode;
  189. spinlock_t input_lock;
  190. spinlock_t output_lock;
  191. spinlock_t open_lock;
  192. int tx_enable, rx_enable;
  193. int port;
  194. int ipr_tx, ipr_rx;
  195. void (*interrupt)(struct emu10k1x *emu, unsigned int status);
  196. };
  197. // definition of the chip-specific record
  198. struct emu10k1x {
  199. struct snd_card *card;
  200. struct pci_dev *pci;
  201. unsigned long port;
  202. struct resource *res_port;
  203. int irq;
  204. unsigned char revision; /* chip revision */
  205. unsigned int serial; /* serial number */
  206. unsigned short model; /* subsystem id */
  207. spinlock_t emu_lock;
  208. spinlock_t voice_lock;
  209. struct snd_ac97 *ac97;
  210. struct snd_pcm *pcm;
  211. struct emu10k1x_voice voices[3];
  212. struct emu10k1x_voice capture_voice;
  213. u32 spdif_bits[3]; // SPDIF out setup
  214. struct snd_dma_buffer dma_buffer;
  215. struct emu10k1x_midi midi;
  216. };
  217. /* hardware definition */
  218. static struct snd_pcm_hardware snd_emu10k1x_playback_hw = {
  219. .info = (SNDRV_PCM_INFO_MMAP |
  220. SNDRV_PCM_INFO_INTERLEAVED |
  221. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  222. SNDRV_PCM_INFO_MMAP_VALID),
  223. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  224. .rates = SNDRV_PCM_RATE_48000,
  225. .rate_min = 48000,
  226. .rate_max = 48000,
  227. .channels_min = 2,
  228. .channels_max = 2,
  229. .buffer_bytes_max = (32*1024),
  230. .period_bytes_min = 64,
  231. .period_bytes_max = (16*1024),
  232. .periods_min = 2,
  233. .periods_max = 8,
  234. .fifo_size = 0,
  235. };
  236. static struct snd_pcm_hardware snd_emu10k1x_capture_hw = {
  237. .info = (SNDRV_PCM_INFO_MMAP |
  238. SNDRV_PCM_INFO_INTERLEAVED |
  239. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  240. SNDRV_PCM_INFO_MMAP_VALID),
  241. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  242. .rates = SNDRV_PCM_RATE_48000,
  243. .rate_min = 48000,
  244. .rate_max = 48000,
  245. .channels_min = 2,
  246. .channels_max = 2,
  247. .buffer_bytes_max = (32*1024),
  248. .period_bytes_min = 64,
  249. .period_bytes_max = (16*1024),
  250. .periods_min = 2,
  251. .periods_max = 2,
  252. .fifo_size = 0,
  253. };
  254. static unsigned int snd_emu10k1x_ptr_read(struct emu10k1x * emu,
  255. unsigned int reg,
  256. unsigned int chn)
  257. {
  258. unsigned long flags;
  259. unsigned int regptr, val;
  260. regptr = (reg << 16) | chn;
  261. spin_lock_irqsave(&emu->emu_lock, flags);
  262. outl(regptr, emu->port + PTR);
  263. val = inl(emu->port + DATA);
  264. spin_unlock_irqrestore(&emu->emu_lock, flags);
  265. return val;
  266. }
  267. static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
  268. unsigned int reg,
  269. unsigned int chn,
  270. unsigned int data)
  271. {
  272. unsigned int regptr;
  273. unsigned long flags;
  274. regptr = (reg << 16) | chn;
  275. spin_lock_irqsave(&emu->emu_lock, flags);
  276. outl(regptr, emu->port + PTR);
  277. outl(data, emu->port + DATA);
  278. spin_unlock_irqrestore(&emu->emu_lock, flags);
  279. }
  280. static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
  281. {
  282. unsigned long flags;
  283. unsigned int enable;
  284. spin_lock_irqsave(&emu->emu_lock, flags);
  285. enable = inl(emu->port + INTE) | intrenb;
  286. outl(enable, emu->port + INTE);
  287. spin_unlock_irqrestore(&emu->emu_lock, flags);
  288. }
  289. static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
  290. {
  291. unsigned long flags;
  292. unsigned int enable;
  293. spin_lock_irqsave(&emu->emu_lock, flags);
  294. enable = inl(emu->port + INTE) & ~intrenb;
  295. outl(enable, emu->port + INTE);
  296. spin_unlock_irqrestore(&emu->emu_lock, flags);
  297. }
  298. static void snd_emu10k1x_gpio_write(struct emu10k1x *emu, unsigned int value)
  299. {
  300. unsigned long flags;
  301. spin_lock_irqsave(&emu->emu_lock, flags);
  302. outl(value, emu->port + GPIO);
  303. spin_unlock_irqrestore(&emu->emu_lock, flags);
  304. }
  305. static void snd_emu10k1x_pcm_free_substream(struct snd_pcm_runtime *runtime)
  306. {
  307. kfree(runtime->private_data);
  308. }
  309. static void snd_emu10k1x_pcm_interrupt(struct emu10k1x *emu, struct emu10k1x_voice *voice)
  310. {
  311. struct emu10k1x_pcm *epcm;
  312. if ((epcm = voice->epcm) == NULL)
  313. return;
  314. if (epcm->substream == NULL)
  315. return;
  316. #if 0
  317. snd_printk(KERN_INFO "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
  318. epcm->substream->ops->pointer(epcm->substream),
  319. snd_pcm_lib_period_bytes(epcm->substream),
  320. snd_pcm_lib_buffer_bytes(epcm->substream));
  321. #endif
  322. snd_pcm_period_elapsed(epcm->substream);
  323. }
  324. /* open callback */
  325. static int snd_emu10k1x_playback_open(struct snd_pcm_substream *substream)
  326. {
  327. struct emu10k1x *chip = snd_pcm_substream_chip(substream);
  328. struct emu10k1x_pcm *epcm;
  329. struct snd_pcm_runtime *runtime = substream->runtime;
  330. int err;
  331. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
  332. return err;
  333. }
  334. if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
  335. return err;
  336. epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
  337. if (epcm == NULL)
  338. return -ENOMEM;
  339. epcm->emu = chip;
  340. epcm->substream = substream;
  341. runtime->private_data = epcm;
  342. runtime->private_free = snd_emu10k1x_pcm_free_substream;
  343. runtime->hw = snd_emu10k1x_playback_hw;
  344. return 0;
  345. }
  346. /* close callback */
  347. static int snd_emu10k1x_playback_close(struct snd_pcm_substream *substream)
  348. {
  349. return 0;
  350. }
  351. /* hw_params callback */
  352. static int snd_emu10k1x_pcm_hw_params(struct snd_pcm_substream *substream,
  353. struct snd_pcm_hw_params *hw_params)
  354. {
  355. struct snd_pcm_runtime *runtime = substream->runtime;
  356. struct emu10k1x_pcm *epcm = runtime->private_data;
  357. if (! epcm->voice) {
  358. epcm->voice = &epcm->emu->voices[substream->pcm->device];
  359. epcm->voice->use = 1;
  360. epcm->voice->epcm = epcm;
  361. }
  362. return snd_pcm_lib_malloc_pages(substream,
  363. params_buffer_bytes(hw_params));
  364. }
  365. /* hw_free callback */
  366. static int snd_emu10k1x_pcm_hw_free(struct snd_pcm_substream *substream)
  367. {
  368. struct snd_pcm_runtime *runtime = substream->runtime;
  369. struct emu10k1x_pcm *epcm;
  370. if (runtime->private_data == NULL)
  371. return 0;
  372. epcm = runtime->private_data;
  373. if (epcm->voice) {
  374. epcm->voice->use = 0;
  375. epcm->voice->epcm = NULL;
  376. epcm->voice = NULL;
  377. }
  378. return snd_pcm_lib_free_pages(substream);
  379. }
  380. /* prepare callback */
  381. static int snd_emu10k1x_pcm_prepare(struct snd_pcm_substream *substream)
  382. {
  383. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  384. struct snd_pcm_runtime *runtime = substream->runtime;
  385. struct emu10k1x_pcm *epcm = runtime->private_data;
  386. int voice = epcm->voice->number;
  387. u32 *table_base = (u32 *)(emu->dma_buffer.area+1024*voice);
  388. u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
  389. int i;
  390. for(i = 0; i < runtime->periods; i++) {
  391. *table_base++=runtime->dma_addr+(i*period_size_bytes);
  392. *table_base++=period_size_bytes<<16;
  393. }
  394. snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_ADDR, voice, emu->dma_buffer.addr+1024*voice);
  395. snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_SIZE, voice, (runtime->periods - 1) << 19);
  396. snd_emu10k1x_ptr_write(emu, PLAYBACK_LIST_PTR, voice, 0);
  397. snd_emu10k1x_ptr_write(emu, PLAYBACK_POINTER, voice, 0);
  398. snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN1, voice, 0);
  399. snd_emu10k1x_ptr_write(emu, PLAYBACK_UNKNOWN2, voice, 0);
  400. snd_emu10k1x_ptr_write(emu, PLAYBACK_DMA_ADDR, voice, runtime->dma_addr);
  401. snd_emu10k1x_ptr_write(emu, PLAYBACK_PERIOD_SIZE, voice, frames_to_bytes(runtime, runtime->period_size)<<16);
  402. return 0;
  403. }
  404. /* trigger callback */
  405. static int snd_emu10k1x_pcm_trigger(struct snd_pcm_substream *substream,
  406. int cmd)
  407. {
  408. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  409. struct snd_pcm_runtime *runtime = substream->runtime;
  410. struct emu10k1x_pcm *epcm = runtime->private_data;
  411. int channel = epcm->voice->number;
  412. int result = 0;
  413. // snd_printk(KERN_INFO "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream));
  414. switch (cmd) {
  415. case SNDRV_PCM_TRIGGER_START:
  416. if(runtime->periods == 2)
  417. snd_emu10k1x_intr_enable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
  418. else
  419. snd_emu10k1x_intr_enable(emu, INTE_CH_0_LOOP << channel);
  420. epcm->running = 1;
  421. snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|(TRIGGER_CHANNEL_0<<channel));
  422. break;
  423. case SNDRV_PCM_TRIGGER_STOP:
  424. epcm->running = 0;
  425. snd_emu10k1x_intr_disable(emu, (INTE_CH_0_LOOP | INTE_CH_0_HALF_LOOP) << channel);
  426. snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CHANNEL_0<<channel));
  427. break;
  428. default:
  429. result = -EINVAL;
  430. break;
  431. }
  432. return result;
  433. }
  434. /* pointer callback */
  435. static snd_pcm_uframes_t
  436. snd_emu10k1x_pcm_pointer(struct snd_pcm_substream *substream)
  437. {
  438. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  439. struct snd_pcm_runtime *runtime = substream->runtime;
  440. struct emu10k1x_pcm *epcm = runtime->private_data;
  441. int channel = epcm->voice->number;
  442. snd_pcm_uframes_t ptr = 0, ptr1 = 0, ptr2= 0,ptr3 = 0,ptr4 = 0;
  443. if (!epcm->running)
  444. return 0;
  445. ptr3 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
  446. ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
  447. ptr4 = snd_emu10k1x_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
  448. if(ptr4 == 0 && ptr1 == frames_to_bytes(runtime, runtime->buffer_size))
  449. return 0;
  450. if (ptr3 != ptr4)
  451. ptr1 = snd_emu10k1x_ptr_read(emu, PLAYBACK_POINTER, channel);
  452. ptr2 = bytes_to_frames(runtime, ptr1);
  453. ptr2 += (ptr4 >> 3) * runtime->period_size;
  454. ptr = ptr2;
  455. if (ptr >= runtime->buffer_size)
  456. ptr -= runtime->buffer_size;
  457. return ptr;
  458. }
  459. /* operators */
  460. static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
  461. .open = snd_emu10k1x_playback_open,
  462. .close = snd_emu10k1x_playback_close,
  463. .ioctl = snd_pcm_lib_ioctl,
  464. .hw_params = snd_emu10k1x_pcm_hw_params,
  465. .hw_free = snd_emu10k1x_pcm_hw_free,
  466. .prepare = snd_emu10k1x_pcm_prepare,
  467. .trigger = snd_emu10k1x_pcm_trigger,
  468. .pointer = snd_emu10k1x_pcm_pointer,
  469. };
  470. /* open_capture callback */
  471. static int snd_emu10k1x_pcm_open_capture(struct snd_pcm_substream *substream)
  472. {
  473. struct emu10k1x *chip = snd_pcm_substream_chip(substream);
  474. struct emu10k1x_pcm *epcm;
  475. struct snd_pcm_runtime *runtime = substream->runtime;
  476. int err;
  477. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  478. return err;
  479. if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
  480. return err;
  481. epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
  482. if (epcm == NULL)
  483. return -ENOMEM;
  484. epcm->emu = chip;
  485. epcm->substream = substream;
  486. runtime->private_data = epcm;
  487. runtime->private_free = snd_emu10k1x_pcm_free_substream;
  488. runtime->hw = snd_emu10k1x_capture_hw;
  489. return 0;
  490. }
  491. /* close callback */
  492. static int snd_emu10k1x_pcm_close_capture(struct snd_pcm_substream *substream)
  493. {
  494. return 0;
  495. }
  496. /* hw_params callback */
  497. static int snd_emu10k1x_pcm_hw_params_capture(struct snd_pcm_substream *substream,
  498. struct snd_pcm_hw_params *hw_params)
  499. {
  500. struct snd_pcm_runtime *runtime = substream->runtime;
  501. struct emu10k1x_pcm *epcm = runtime->private_data;
  502. if (! epcm->voice) {
  503. if (epcm->emu->capture_voice.use)
  504. return -EBUSY;
  505. epcm->voice = &epcm->emu->capture_voice;
  506. epcm->voice->epcm = epcm;
  507. epcm->voice->use = 1;
  508. }
  509. return snd_pcm_lib_malloc_pages(substream,
  510. params_buffer_bytes(hw_params));
  511. }
  512. /* hw_free callback */
  513. static int snd_emu10k1x_pcm_hw_free_capture(struct snd_pcm_substream *substream)
  514. {
  515. struct snd_pcm_runtime *runtime = substream->runtime;
  516. struct emu10k1x_pcm *epcm;
  517. if (runtime->private_data == NULL)
  518. return 0;
  519. epcm = runtime->private_data;
  520. if (epcm->voice) {
  521. epcm->voice->use = 0;
  522. epcm->voice->epcm = NULL;
  523. epcm->voice = NULL;
  524. }
  525. return snd_pcm_lib_free_pages(substream);
  526. }
  527. /* prepare capture callback */
  528. static int snd_emu10k1x_pcm_prepare_capture(struct snd_pcm_substream *substream)
  529. {
  530. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  531. struct snd_pcm_runtime *runtime = substream->runtime;
  532. snd_emu10k1x_ptr_write(emu, CAPTURE_DMA_ADDR, 0, runtime->dma_addr);
  533. snd_emu10k1x_ptr_write(emu, CAPTURE_BUFFER_SIZE, 0, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
  534. snd_emu10k1x_ptr_write(emu, CAPTURE_POINTER, 0, 0);
  535. snd_emu10k1x_ptr_write(emu, CAPTURE_UNKNOWN, 0, 0);
  536. return 0;
  537. }
  538. /* trigger_capture callback */
  539. static int snd_emu10k1x_pcm_trigger_capture(struct snd_pcm_substream *substream,
  540. int cmd)
  541. {
  542. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  543. struct snd_pcm_runtime *runtime = substream->runtime;
  544. struct emu10k1x_pcm *epcm = runtime->private_data;
  545. int result = 0;
  546. switch (cmd) {
  547. case SNDRV_PCM_TRIGGER_START:
  548. snd_emu10k1x_intr_enable(emu, INTE_CAP_0_LOOP |
  549. INTE_CAP_0_HALF_LOOP);
  550. snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0)|TRIGGER_CAPTURE);
  551. epcm->running = 1;
  552. break;
  553. case SNDRV_PCM_TRIGGER_STOP:
  554. epcm->running = 0;
  555. snd_emu10k1x_intr_disable(emu, INTE_CAP_0_LOOP |
  556. INTE_CAP_0_HALF_LOOP);
  557. snd_emu10k1x_ptr_write(emu, TRIGGER_CHANNEL, 0, snd_emu10k1x_ptr_read(emu, TRIGGER_CHANNEL, 0) & ~(TRIGGER_CAPTURE));
  558. break;
  559. default:
  560. result = -EINVAL;
  561. break;
  562. }
  563. return result;
  564. }
  565. /* pointer_capture callback */
  566. static snd_pcm_uframes_t
  567. snd_emu10k1x_pcm_pointer_capture(struct snd_pcm_substream *substream)
  568. {
  569. struct emu10k1x *emu = snd_pcm_substream_chip(substream);
  570. struct snd_pcm_runtime *runtime = substream->runtime;
  571. struct emu10k1x_pcm *epcm = runtime->private_data;
  572. snd_pcm_uframes_t ptr;
  573. if (!epcm->running)
  574. return 0;
  575. ptr = bytes_to_frames(runtime, snd_emu10k1x_ptr_read(emu, CAPTURE_POINTER, 0));
  576. if (ptr >= runtime->buffer_size)
  577. ptr -= runtime->buffer_size;
  578. return ptr;
  579. }
  580. static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
  581. .open = snd_emu10k1x_pcm_open_capture,
  582. .close = snd_emu10k1x_pcm_close_capture,
  583. .ioctl = snd_pcm_lib_ioctl,
  584. .hw_params = snd_emu10k1x_pcm_hw_params_capture,
  585. .hw_free = snd_emu10k1x_pcm_hw_free_capture,
  586. .prepare = snd_emu10k1x_pcm_prepare_capture,
  587. .trigger = snd_emu10k1x_pcm_trigger_capture,
  588. .pointer = snd_emu10k1x_pcm_pointer_capture,
  589. };
  590. static unsigned short snd_emu10k1x_ac97_read(struct snd_ac97 *ac97,
  591. unsigned short reg)
  592. {
  593. struct emu10k1x *emu = ac97->private_data;
  594. unsigned long flags;
  595. unsigned short val;
  596. spin_lock_irqsave(&emu->emu_lock, flags);
  597. outb(reg, emu->port + AC97ADDRESS);
  598. val = inw(emu->port + AC97DATA);
  599. spin_unlock_irqrestore(&emu->emu_lock, flags);
  600. return val;
  601. }
  602. static void snd_emu10k1x_ac97_write(struct snd_ac97 *ac97,
  603. unsigned short reg, unsigned short val)
  604. {
  605. struct emu10k1x *emu = ac97->private_data;
  606. unsigned long flags;
  607. spin_lock_irqsave(&emu->emu_lock, flags);
  608. outb(reg, emu->port + AC97ADDRESS);
  609. outw(val, emu->port + AC97DATA);
  610. spin_unlock_irqrestore(&emu->emu_lock, flags);
  611. }
  612. static int snd_emu10k1x_ac97(struct emu10k1x *chip)
  613. {
  614. struct snd_ac97_bus *pbus;
  615. struct snd_ac97_template ac97;
  616. int err;
  617. static struct snd_ac97_bus_ops ops = {
  618. .write = snd_emu10k1x_ac97_write,
  619. .read = snd_emu10k1x_ac97_read,
  620. };
  621. if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
  622. return err;
  623. pbus->no_vra = 1; /* we don't need VRA */
  624. memset(&ac97, 0, sizeof(ac97));
  625. ac97.private_data = chip;
  626. ac97.scaps = AC97_SCAP_NO_SPDIF;
  627. return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
  628. }
  629. static int snd_emu10k1x_free(struct emu10k1x *chip)
  630. {
  631. snd_emu10k1x_ptr_write(chip, TRIGGER_CHANNEL, 0, 0);
  632. // disable interrupts
  633. outl(0, chip->port + INTE);
  634. // disable audio
  635. outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
  636. // release the i/o port
  637. release_and_free_resource(chip->res_port);
  638. // release the irq
  639. if (chip->irq >= 0)
  640. free_irq(chip->irq, chip);
  641. // release the DMA
  642. if (chip->dma_buffer.area) {
  643. snd_dma_free_pages(&chip->dma_buffer);
  644. }
  645. pci_disable_device(chip->pci);
  646. // release the data
  647. kfree(chip);
  648. return 0;
  649. }
  650. static int snd_emu10k1x_dev_free(struct snd_device *device)
  651. {
  652. struct emu10k1x *chip = device->device_data;
  653. return snd_emu10k1x_free(chip);
  654. }
  655. static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
  656. {
  657. unsigned int status;
  658. struct emu10k1x *chip = dev_id;
  659. struct emu10k1x_voice *pvoice = chip->voices;
  660. int i;
  661. int mask;
  662. status = inl(chip->port + IPR);
  663. if (! status)
  664. return IRQ_NONE;
  665. // capture interrupt
  666. if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
  667. struct emu10k1x_voice *pvoice = &chip->capture_voice;
  668. if (pvoice->use)
  669. snd_emu10k1x_pcm_interrupt(chip, pvoice);
  670. else
  671. snd_emu10k1x_intr_disable(chip,
  672. INTE_CAP_0_LOOP |
  673. INTE_CAP_0_HALF_LOOP);
  674. }
  675. mask = IPR_CH_0_LOOP|IPR_CH_0_HALF_LOOP;
  676. for (i = 0; i < 3; i++) {
  677. if (status & mask) {
  678. if (pvoice->use)
  679. snd_emu10k1x_pcm_interrupt(chip, pvoice);
  680. else
  681. snd_emu10k1x_intr_disable(chip, mask);
  682. }
  683. pvoice++;
  684. mask <<= 1;
  685. }
  686. if (status & (IPR_MIDITRANSBUFEMPTY|IPR_MIDIRECVBUFEMPTY)) {
  687. if (chip->midi.interrupt)
  688. chip->midi.interrupt(chip, status);
  689. else
  690. snd_emu10k1x_intr_disable(chip, INTE_MIDITXENABLE|INTE_MIDIRXENABLE);
  691. }
  692. // acknowledge the interrupt if necessary
  693. outl(status, chip->port + IPR);
  694. // snd_printk(KERN_INFO "interrupt %08x\n", status);
  695. return IRQ_HANDLED;
  696. }
  697. static int __devinit snd_emu10k1x_pcm(struct emu10k1x *emu, int device, struct snd_pcm **rpcm)
  698. {
  699. struct snd_pcm *pcm;
  700. int err;
  701. int capture = 0;
  702. if (rpcm)
  703. *rpcm = NULL;
  704. if (device == 0)
  705. capture = 1;
  706. if ((err = snd_pcm_new(emu->card, "emu10k1x", device, 1, capture, &pcm)) < 0)
  707. return err;
  708. pcm->private_data = emu;
  709. switch(device) {
  710. case 0:
  711. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
  712. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1x_capture_ops);
  713. break;
  714. case 1:
  715. case 2:
  716. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1x_playback_ops);
  717. break;
  718. }
  719. pcm->info_flags = 0;
  720. pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
  721. switch(device) {
  722. case 0:
  723. strcpy(pcm->name, "EMU10K1X Front");
  724. break;
  725. case 1:
  726. strcpy(pcm->name, "EMU10K1X Rear");
  727. break;
  728. case 2:
  729. strcpy(pcm->name, "EMU10K1X Center/LFE");
  730. break;
  731. }
  732. emu->pcm = pcm;
  733. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  734. snd_dma_pci_data(emu->pci),
  735. 32*1024, 32*1024);
  736. if (rpcm)
  737. *rpcm = pcm;
  738. return 0;
  739. }
  740. static int __devinit snd_emu10k1x_create(struct snd_card *card,
  741. struct pci_dev *pci,
  742. struct emu10k1x **rchip)
  743. {
  744. struct emu10k1x *chip;
  745. int err;
  746. int ch;
  747. static struct snd_device_ops ops = {
  748. .dev_free = snd_emu10k1x_dev_free,
  749. };
  750. *rchip = NULL;
  751. if ((err = pci_enable_device(pci)) < 0)
  752. return err;
  753. if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
  754. pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
  755. snd_printk(KERN_ERR "error to set 28bit mask DMA\n");
  756. pci_disable_device(pci);
  757. return -ENXIO;
  758. }
  759. chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  760. if (chip == NULL) {
  761. pci_disable_device(pci);
  762. return -ENOMEM;
  763. }
  764. chip->card = card;
  765. chip->pci = pci;
  766. chip->irq = -1;
  767. spin_lock_init(&chip->emu_lock);
  768. spin_lock_init(&chip->voice_lock);
  769. chip->port = pci_resource_start(pci, 0);
  770. if ((chip->res_port = request_region(chip->port, 8,
  771. "EMU10K1X")) == NULL) {
  772. snd_printk(KERN_ERR "emu10k1x: cannot allocate the port 0x%lx\n", chip->port);
  773. snd_emu10k1x_free(chip);
  774. return -EBUSY;
  775. }
  776. if (request_irq(pci->irq, snd_emu10k1x_interrupt,
  777. IRQF_SHARED, "EMU10K1X", chip)) {
  778. snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq);
  779. snd_emu10k1x_free(chip);
  780. return -EBUSY;
  781. }
  782. chip->irq = pci->irq;
  783. if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  784. 4 * 1024, &chip->dma_buffer) < 0) {
  785. snd_emu10k1x_free(chip);
  786. return -ENOMEM;
  787. }
  788. pci_set_master(pci);
  789. /* read revision & serial */
  790. chip->revision = pci->revision;
  791. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
  792. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
  793. snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
  794. chip->revision, chip->serial);
  795. outl(0, chip->port + INTE);
  796. for(ch = 0; ch < 3; ch++) {
  797. chip->voices[ch].emu = chip;
  798. chip->voices[ch].number = ch;
  799. }
  800. /*
  801. * Init to 0x02109204 :
  802. * Clock accuracy = 0 (1000ppm)
  803. * Sample Rate = 2 (48kHz)
  804. * Audio Channel = 1 (Left of 2)
  805. * Source Number = 0 (Unspecified)
  806. * Generation Status = 1 (Original for Cat Code 12)
  807. * Cat Code = 12 (Digital Signal Mixer)
  808. * Mode = 0 (Mode 0)
  809. * Emphasis = 0 (None)
  810. * CP = 1 (Copyright unasserted)
  811. * AN = 0 (Audio data)
  812. * P = 0 (Consumer)
  813. */
  814. snd_emu10k1x_ptr_write(chip, SPCS0, 0,
  815. chip->spdif_bits[0] =
  816. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  817. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  818. SPCS_GENERATIONSTATUS | 0x00001200 |
  819. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  820. snd_emu10k1x_ptr_write(chip, SPCS1, 0,
  821. chip->spdif_bits[1] =
  822. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  823. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  824. SPCS_GENERATIONSTATUS | 0x00001200 |
  825. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  826. snd_emu10k1x_ptr_write(chip, SPCS2, 0,
  827. chip->spdif_bits[2] =
  828. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  829. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  830. SPCS_GENERATIONSTATUS | 0x00001200 |
  831. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  832. snd_emu10k1x_ptr_write(chip, SPDIF_SELECT, 0, 0x700); // disable SPDIF
  833. snd_emu10k1x_ptr_write(chip, ROUTING, 0, 0x1003F); // routing
  834. snd_emu10k1x_gpio_write(chip, 0x1080); // analog mode
  835. outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
  836. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
  837. chip, &ops)) < 0) {
  838. snd_emu10k1x_free(chip);
  839. return err;
  840. }
  841. *rchip = chip;
  842. return 0;
  843. }
  844. static void snd_emu10k1x_proc_reg_read(struct snd_info_entry *entry,
  845. struct snd_info_buffer *buffer)
  846. {
  847. struct emu10k1x *emu = entry->private_data;
  848. unsigned long value,value1,value2;
  849. unsigned long flags;
  850. int i;
  851. snd_iprintf(buffer, "Registers:\n\n");
  852. for(i = 0; i < 0x20; i+=4) {
  853. spin_lock_irqsave(&emu->emu_lock, flags);
  854. value = inl(emu->port + i);
  855. spin_unlock_irqrestore(&emu->emu_lock, flags);
  856. snd_iprintf(buffer, "Register %02X: %08lX\n", i, value);
  857. }
  858. snd_iprintf(buffer, "\nRegisters\n\n");
  859. for(i = 0; i <= 0x48; i++) {
  860. value = snd_emu10k1x_ptr_read(emu, i, 0);
  861. if(i < 0x10 || (i >= 0x20 && i < 0x40)) {
  862. value1 = snd_emu10k1x_ptr_read(emu, i, 1);
  863. value2 = snd_emu10k1x_ptr_read(emu, i, 2);
  864. snd_iprintf(buffer, "%02X: %08lX %08lX %08lX\n", i, value, value1, value2);
  865. } else {
  866. snd_iprintf(buffer, "%02X: %08lX\n", i, value);
  867. }
  868. }
  869. }
  870. static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
  871. struct snd_info_buffer *buffer)
  872. {
  873. struct emu10k1x *emu = entry->private_data;
  874. char line[64];
  875. unsigned int reg, channel_id , val;
  876. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  877. if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
  878. continue;
  879. if ((reg < 0x49) && (reg >= 0) && (val <= 0xffffffff)
  880. && (channel_id >= 0) && (channel_id <= 2) )
  881. snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
  882. }
  883. }
  884. static int __devinit snd_emu10k1x_proc_init(struct emu10k1x * emu)
  885. {
  886. struct snd_info_entry *entry;
  887. if(! snd_card_proc_new(emu->card, "emu10k1x_regs", &entry)) {
  888. snd_info_set_text_ops(entry, emu, snd_emu10k1x_proc_reg_read);
  889. entry->c.text.write = snd_emu10k1x_proc_reg_write;
  890. entry->mode |= S_IWUSR;
  891. entry->private_data = emu;
  892. }
  893. return 0;
  894. }
  895. #define snd_emu10k1x_shared_spdif_info snd_ctl_boolean_mono_info
  896. static int snd_emu10k1x_shared_spdif_get(struct snd_kcontrol *kcontrol,
  897. struct snd_ctl_elem_value *ucontrol)
  898. {
  899. struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
  900. ucontrol->value.integer.value[0] = (snd_emu10k1x_ptr_read(emu, SPDIF_SELECT, 0) == 0x700) ? 0 : 1;
  901. return 0;
  902. }
  903. static int snd_emu10k1x_shared_spdif_put(struct snd_kcontrol *kcontrol,
  904. struct snd_ctl_elem_value *ucontrol)
  905. {
  906. struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
  907. unsigned int val;
  908. int change = 0;
  909. val = ucontrol->value.integer.value[0] ;
  910. if (val) {
  911. // enable spdif output
  912. snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x000);
  913. snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x700);
  914. snd_emu10k1x_gpio_write(emu, 0x1000);
  915. } else {
  916. // disable spdif output
  917. snd_emu10k1x_ptr_write(emu, SPDIF_SELECT, 0, 0x700);
  918. snd_emu10k1x_ptr_write(emu, ROUTING, 0, 0x1003F);
  919. snd_emu10k1x_gpio_write(emu, 0x1080);
  920. }
  921. return change;
  922. }
  923. static struct snd_kcontrol_new snd_emu10k1x_shared_spdif __devinitdata =
  924. {
  925. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  926. .name = "Analog/Digital Output Jack",
  927. .info = snd_emu10k1x_shared_spdif_info,
  928. .get = snd_emu10k1x_shared_spdif_get,
  929. .put = snd_emu10k1x_shared_spdif_put
  930. };
  931. static int snd_emu10k1x_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  932. {
  933. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  934. uinfo->count = 1;
  935. return 0;
  936. }
  937. static int snd_emu10k1x_spdif_get(struct snd_kcontrol *kcontrol,
  938. struct snd_ctl_elem_value *ucontrol)
  939. {
  940. struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
  941. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  942. ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
  943. ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
  944. ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
  945. ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
  946. return 0;
  947. }
  948. static int snd_emu10k1x_spdif_get_mask(struct snd_kcontrol *kcontrol,
  949. struct snd_ctl_elem_value *ucontrol)
  950. {
  951. ucontrol->value.iec958.status[0] = 0xff;
  952. ucontrol->value.iec958.status[1] = 0xff;
  953. ucontrol->value.iec958.status[2] = 0xff;
  954. ucontrol->value.iec958.status[3] = 0xff;
  955. return 0;
  956. }
  957. static int snd_emu10k1x_spdif_put(struct snd_kcontrol *kcontrol,
  958. struct snd_ctl_elem_value *ucontrol)
  959. {
  960. struct emu10k1x *emu = snd_kcontrol_chip(kcontrol);
  961. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  962. int change;
  963. unsigned int val;
  964. val = (ucontrol->value.iec958.status[0] << 0) |
  965. (ucontrol->value.iec958.status[1] << 8) |
  966. (ucontrol->value.iec958.status[2] << 16) |
  967. (ucontrol->value.iec958.status[3] << 24);
  968. change = val != emu->spdif_bits[idx];
  969. if (change) {
  970. snd_emu10k1x_ptr_write(emu, SPCS0 + idx, 0, val);
  971. emu->spdif_bits[idx] = val;
  972. }
  973. return change;
  974. }
  975. static struct snd_kcontrol_new snd_emu10k1x_spdif_mask_control =
  976. {
  977. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  978. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  979. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
  980. .count = 3,
  981. .info = snd_emu10k1x_spdif_info,
  982. .get = snd_emu10k1x_spdif_get_mask
  983. };
  984. static struct snd_kcontrol_new snd_emu10k1x_spdif_control =
  985. {
  986. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  987. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  988. .count = 3,
  989. .info = snd_emu10k1x_spdif_info,
  990. .get = snd_emu10k1x_spdif_get,
  991. .put = snd_emu10k1x_spdif_put
  992. };
  993. static int __devinit snd_emu10k1x_mixer(struct emu10k1x *emu)
  994. {
  995. int err;
  996. struct snd_kcontrol *kctl;
  997. struct snd_card *card = emu->card;
  998. if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_mask_control, emu)) == NULL)
  999. return -ENOMEM;
  1000. if ((err = snd_ctl_add(card, kctl)))
  1001. return err;
  1002. if ((kctl = snd_ctl_new1(&snd_emu10k1x_shared_spdif, emu)) == NULL)
  1003. return -ENOMEM;
  1004. if ((err = snd_ctl_add(card, kctl)))
  1005. return err;
  1006. if ((kctl = snd_ctl_new1(&snd_emu10k1x_spdif_control, emu)) == NULL)
  1007. return -ENOMEM;
  1008. if ((err = snd_ctl_add(card, kctl)))
  1009. return err;
  1010. return 0;
  1011. }
  1012. #define EMU10K1X_MIDI_MODE_INPUT (1<<0)
  1013. #define EMU10K1X_MIDI_MODE_OUTPUT (1<<1)
  1014. static inline unsigned char mpu401_read(struct emu10k1x *emu, struct emu10k1x_midi *mpu, int idx)
  1015. {
  1016. return (unsigned char)snd_emu10k1x_ptr_read(emu, mpu->port + idx, 0);
  1017. }
  1018. static inline void mpu401_write(struct emu10k1x *emu, struct emu10k1x_midi *mpu, int data, int idx)
  1019. {
  1020. snd_emu10k1x_ptr_write(emu, mpu->port + idx, 0, data);
  1021. }
  1022. #define mpu401_write_data(emu, mpu, data) mpu401_write(emu, mpu, data, 0)
  1023. #define mpu401_write_cmd(emu, mpu, data) mpu401_write(emu, mpu, data, 1)
  1024. #define mpu401_read_data(emu, mpu) mpu401_read(emu, mpu, 0)
  1025. #define mpu401_read_stat(emu, mpu) mpu401_read(emu, mpu, 1)
  1026. #define mpu401_input_avail(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x80))
  1027. #define mpu401_output_ready(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x40))
  1028. #define MPU401_RESET 0xff
  1029. #define MPU401_ENTER_UART 0x3f
  1030. #define MPU401_ACK 0xfe
  1031. static void mpu401_clear_rx(struct emu10k1x *emu, struct emu10k1x_midi *mpu)
  1032. {
  1033. int timeout = 100000;
  1034. for (; timeout > 0 && mpu401_input_avail(emu, mpu); timeout--)
  1035. mpu401_read_data(emu, mpu);
  1036. #ifdef CONFIG_SND_DEBUG
  1037. if (timeout <= 0)
  1038. snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu));
  1039. #endif
  1040. }
  1041. /*
  1042. */
  1043. static void do_emu10k1x_midi_interrupt(struct emu10k1x *emu,
  1044. struct emu10k1x_midi *midi, unsigned int status)
  1045. {
  1046. unsigned char byte;
  1047. if (midi->rmidi == NULL) {
  1048. snd_emu10k1x_intr_disable(emu, midi->tx_enable | midi->rx_enable);
  1049. return;
  1050. }
  1051. spin_lock(&midi->input_lock);
  1052. if ((status & midi->ipr_rx) && mpu401_input_avail(emu, midi)) {
  1053. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
  1054. mpu401_clear_rx(emu, midi);
  1055. } else {
  1056. byte = mpu401_read_data(emu, midi);
  1057. if (midi->substream_input)
  1058. snd_rawmidi_receive(midi->substream_input, &byte, 1);
  1059. }
  1060. }
  1061. spin_unlock(&midi->input_lock);
  1062. spin_lock(&midi->output_lock);
  1063. if ((status & midi->ipr_tx) && mpu401_output_ready(emu, midi)) {
  1064. if (midi->substream_output &&
  1065. snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
  1066. mpu401_write_data(emu, midi, byte);
  1067. } else {
  1068. snd_emu10k1x_intr_disable(emu, midi->tx_enable);
  1069. }
  1070. }
  1071. spin_unlock(&midi->output_lock);
  1072. }
  1073. static void snd_emu10k1x_midi_interrupt(struct emu10k1x *emu, unsigned int status)
  1074. {
  1075. do_emu10k1x_midi_interrupt(emu, &emu->midi, status);
  1076. }
  1077. static int snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
  1078. struct emu10k1x_midi *midi, unsigned char cmd, int ack)
  1079. {
  1080. unsigned long flags;
  1081. int timeout, ok;
  1082. spin_lock_irqsave(&midi->input_lock, flags);
  1083. mpu401_write_data(emu, midi, 0x00);
  1084. /* mpu401_clear_rx(emu, midi); */
  1085. mpu401_write_cmd(emu, midi, cmd);
  1086. if (ack) {
  1087. ok = 0;
  1088. timeout = 10000;
  1089. while (!ok && timeout-- > 0) {
  1090. if (mpu401_input_avail(emu, midi)) {
  1091. if (mpu401_read_data(emu, midi) == MPU401_ACK)
  1092. ok = 1;
  1093. }
  1094. }
  1095. if (!ok && mpu401_read_data(emu, midi) == MPU401_ACK)
  1096. ok = 1;
  1097. } else {
  1098. ok = 1;
  1099. }
  1100. spin_unlock_irqrestore(&midi->input_lock, flags);
  1101. if (!ok) {
  1102. snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
  1103. cmd, emu->port,
  1104. mpu401_read_stat(emu, midi),
  1105. mpu401_read_data(emu, midi));
  1106. return 1;
  1107. }
  1108. return 0;
  1109. }
  1110. static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream)
  1111. {
  1112. struct emu10k1x *emu;
  1113. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1114. unsigned long flags;
  1115. emu = midi->emu;
  1116. snd_assert(emu, return -ENXIO);
  1117. spin_lock_irqsave(&midi->open_lock, flags);
  1118. midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT;
  1119. midi->substream_input = substream;
  1120. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
  1121. spin_unlock_irqrestore(&midi->open_lock, flags);
  1122. if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
  1123. goto error_out;
  1124. if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
  1125. goto error_out;
  1126. } else {
  1127. spin_unlock_irqrestore(&midi->open_lock, flags);
  1128. }
  1129. return 0;
  1130. error_out:
  1131. return -EIO;
  1132. }
  1133. static int snd_emu10k1x_midi_output_open(struct snd_rawmidi_substream *substream)
  1134. {
  1135. struct emu10k1x *emu;
  1136. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1137. unsigned long flags;
  1138. emu = midi->emu;
  1139. snd_assert(emu, return -ENXIO);
  1140. spin_lock_irqsave(&midi->open_lock, flags);
  1141. midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT;
  1142. midi->substream_output = substream;
  1143. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
  1144. spin_unlock_irqrestore(&midi->open_lock, flags);
  1145. if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
  1146. goto error_out;
  1147. if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
  1148. goto error_out;
  1149. } else {
  1150. spin_unlock_irqrestore(&midi->open_lock, flags);
  1151. }
  1152. return 0;
  1153. error_out:
  1154. return -EIO;
  1155. }
  1156. static int snd_emu10k1x_midi_input_close(struct snd_rawmidi_substream *substream)
  1157. {
  1158. struct emu10k1x *emu;
  1159. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1160. unsigned long flags;
  1161. int err = 0;
  1162. emu = midi->emu;
  1163. snd_assert(emu, return -ENXIO);
  1164. spin_lock_irqsave(&midi->open_lock, flags);
  1165. snd_emu10k1x_intr_disable(emu, midi->rx_enable);
  1166. midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT;
  1167. midi->substream_input = NULL;
  1168. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
  1169. spin_unlock_irqrestore(&midi->open_lock, flags);
  1170. err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
  1171. } else {
  1172. spin_unlock_irqrestore(&midi->open_lock, flags);
  1173. }
  1174. return err;
  1175. }
  1176. static int snd_emu10k1x_midi_output_close(struct snd_rawmidi_substream *substream)
  1177. {
  1178. struct emu10k1x *emu;
  1179. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1180. unsigned long flags;
  1181. int err = 0;
  1182. emu = midi->emu;
  1183. snd_assert(emu, return -ENXIO);
  1184. spin_lock_irqsave(&midi->open_lock, flags);
  1185. snd_emu10k1x_intr_disable(emu, midi->tx_enable);
  1186. midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT;
  1187. midi->substream_output = NULL;
  1188. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
  1189. spin_unlock_irqrestore(&midi->open_lock, flags);
  1190. err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
  1191. } else {
  1192. spin_unlock_irqrestore(&midi->open_lock, flags);
  1193. }
  1194. return err;
  1195. }
  1196. static void snd_emu10k1x_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  1197. {
  1198. struct emu10k1x *emu;
  1199. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1200. emu = midi->emu;
  1201. snd_assert(emu, return);
  1202. if (up)
  1203. snd_emu10k1x_intr_enable(emu, midi->rx_enable);
  1204. else
  1205. snd_emu10k1x_intr_disable(emu, midi->rx_enable);
  1206. }
  1207. static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
  1208. {
  1209. struct emu10k1x *emu;
  1210. struct emu10k1x_midi *midi = substream->rmidi->private_data;
  1211. unsigned long flags;
  1212. emu = midi->emu;
  1213. snd_assert(emu, return);
  1214. if (up) {
  1215. int max = 4;
  1216. unsigned char byte;
  1217. /* try to send some amount of bytes here before interrupts */
  1218. spin_lock_irqsave(&midi->output_lock, flags);
  1219. while (max > 0) {
  1220. if (mpu401_output_ready(emu, midi)) {
  1221. if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT) ||
  1222. snd_rawmidi_transmit(substream, &byte, 1) != 1) {
  1223. /* no more data */
  1224. spin_unlock_irqrestore(&midi->output_lock, flags);
  1225. return;
  1226. }
  1227. mpu401_write_data(emu, midi, byte);
  1228. max--;
  1229. } else {
  1230. break;
  1231. }
  1232. }
  1233. spin_unlock_irqrestore(&midi->output_lock, flags);
  1234. snd_emu10k1x_intr_enable(emu, midi->tx_enable);
  1235. } else {
  1236. snd_emu10k1x_intr_disable(emu, midi->tx_enable);
  1237. }
  1238. }
  1239. /*
  1240. */
  1241. static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
  1242. {
  1243. .open = snd_emu10k1x_midi_output_open,
  1244. .close = snd_emu10k1x_midi_output_close,
  1245. .trigger = snd_emu10k1x_midi_output_trigger,
  1246. };
  1247. static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
  1248. {
  1249. .open = snd_emu10k1x_midi_input_open,
  1250. .close = snd_emu10k1x_midi_input_close,
  1251. .trigger = snd_emu10k1x_midi_input_trigger,
  1252. };
  1253. static void snd_emu10k1x_midi_free(struct snd_rawmidi *rmidi)
  1254. {
  1255. struct emu10k1x_midi *midi = rmidi->private_data;
  1256. midi->interrupt = NULL;
  1257. midi->rmidi = NULL;
  1258. }
  1259. static int __devinit emu10k1x_midi_init(struct emu10k1x *emu,
  1260. struct emu10k1x_midi *midi, int device, char *name)
  1261. {
  1262. struct snd_rawmidi *rmidi;
  1263. int err;
  1264. if ((err = snd_rawmidi_new(emu->card, name, device, 1, 1, &rmidi)) < 0)
  1265. return err;
  1266. midi->emu = emu;
  1267. spin_lock_init(&midi->open_lock);
  1268. spin_lock_init(&midi->input_lock);
  1269. spin_lock_init(&midi->output_lock);
  1270. strcpy(rmidi->name, name);
  1271. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_emu10k1x_midi_output);
  1272. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_emu10k1x_midi_input);
  1273. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
  1274. SNDRV_RAWMIDI_INFO_INPUT |
  1275. SNDRV_RAWMIDI_INFO_DUPLEX;
  1276. rmidi->private_data = midi;
  1277. rmidi->private_free = snd_emu10k1x_midi_free;
  1278. midi->rmidi = rmidi;
  1279. return 0;
  1280. }
  1281. static int __devinit snd_emu10k1x_midi(struct emu10k1x *emu)
  1282. {
  1283. struct emu10k1x_midi *midi = &emu->midi;
  1284. int err;
  1285. if ((err = emu10k1x_midi_init(emu, midi, 0, "EMU10K1X MPU-401 (UART)")) < 0)
  1286. return err;
  1287. midi->tx_enable = INTE_MIDITXENABLE;
  1288. midi->rx_enable = INTE_MIDIRXENABLE;
  1289. midi->port = MUDATA;
  1290. midi->ipr_tx = IPR_MIDITRANSBUFEMPTY;
  1291. midi->ipr_rx = IPR_MIDIRECVBUFEMPTY;
  1292. midi->interrupt = snd_emu10k1x_midi_interrupt;
  1293. return 0;
  1294. }
  1295. static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
  1296. const struct pci_device_id *pci_id)
  1297. {
  1298. static int dev;
  1299. struct snd_card *card;
  1300. struct emu10k1x *chip;
  1301. int err;
  1302. if (dev >= SNDRV_CARDS)
  1303. return -ENODEV;
  1304. if (!enable[dev]) {
  1305. dev++;
  1306. return -ENOENT;
  1307. }
  1308. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  1309. if (card == NULL)
  1310. return -ENOMEM;
  1311. if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
  1312. snd_card_free(card);
  1313. return err;
  1314. }
  1315. if ((err = snd_emu10k1x_pcm(chip, 0, NULL)) < 0) {
  1316. snd_card_free(card);
  1317. return err;
  1318. }
  1319. if ((err = snd_emu10k1x_pcm(chip, 1, NULL)) < 0) {
  1320. snd_card_free(card);
  1321. return err;
  1322. }
  1323. if ((err = snd_emu10k1x_pcm(chip, 2, NULL)) < 0) {
  1324. snd_card_free(card);
  1325. return err;
  1326. }
  1327. if ((err = snd_emu10k1x_ac97(chip)) < 0) {
  1328. snd_card_free(card);
  1329. return err;
  1330. }
  1331. if ((err = snd_emu10k1x_mixer(chip)) < 0) {
  1332. snd_card_free(card);
  1333. return err;
  1334. }
  1335. if ((err = snd_emu10k1x_midi(chip)) < 0) {
  1336. snd_card_free(card);
  1337. return err;
  1338. }
  1339. snd_emu10k1x_proc_init(chip);
  1340. strcpy(card->driver, "EMU10K1X");
  1341. strcpy(card->shortname, "Dell Sound Blaster Live!");
  1342. sprintf(card->longname, "%s at 0x%lx irq %i",
  1343. card->shortname, chip->port, chip->irq);
  1344. if ((err = snd_card_register(card)) < 0) {
  1345. snd_card_free(card);
  1346. return err;
  1347. }
  1348. pci_set_drvdata(pci, card);
  1349. dev++;
  1350. return 0;
  1351. }
  1352. static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
  1353. {
  1354. snd_card_free(pci_get_drvdata(pci));
  1355. pci_set_drvdata(pci, NULL);
  1356. }
  1357. // PCI IDs
  1358. static struct pci_device_id snd_emu10k1x_ids[] = {
  1359. { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Dell OEM version (EMU10K1) */
  1360. { 0, }
  1361. };
  1362. MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
  1363. // pci_driver definition
  1364. static struct pci_driver driver = {
  1365. .name = "EMU10K1X",
  1366. .id_table = snd_emu10k1x_ids,
  1367. .probe = snd_emu10k1x_probe,
  1368. .remove = __devexit_p(snd_emu10k1x_remove),
  1369. };
  1370. // initialization of the module
  1371. static int __init alsa_card_emu10k1x_init(void)
  1372. {
  1373. return pci_register_driver(&driver);
  1374. }
  1375. // clean up the module
  1376. static void __exit alsa_card_emu10k1x_exit(void)
  1377. {
  1378. pci_unregister_driver(&driver);
  1379. }
  1380. module_init(alsa_card_emu10k1x_init)
  1381. module_exit(alsa_card_emu10k1x_exit)