p16v.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
  3. * Driver p16v chips
  4. * Version: 0.22
  5. *
  6. * FEATURES currently supported:
  7. * Output fixed at S32_LE, 2 channel to hw:0,0
  8. * Rates: 44.1, 48, 96, 192.
  9. *
  10. * Changelog:
  11. * 0.8
  12. * Use separate card based buffer for periods table.
  13. * 0.9
  14. * Use 2 channel output streams instead of 8 channel.
  15. * (8 channel output streams might be good for ASIO type output)
  16. * Corrected speaker output, so Front -> Front etc.
  17. * 0.10
  18. * Fixed missed interrupts.
  19. * 0.11
  20. * Add Sound card model number and names.
  21. * Add Analog volume controls.
  22. * 0.12
  23. * Corrected playback interrupts. Now interrupt per period, instead of half period.
  24. * 0.13
  25. * Use single trigger for multichannel.
  26. * 0.14
  27. * Mic capture now works at fixed: S32_LE, 96000Hz, Stereo.
  28. * 0.15
  29. * Force buffer_size / period_size == INTEGER.
  30. * 0.16
  31. * Update p16v.c to work with changed alsa api.
  32. * 0.17
  33. * Update p16v.c to work with changed alsa api. Removed boot_devs.
  34. * 0.18
  35. * Merging with snd-emu10k1 driver.
  36. * 0.19
  37. * One stereo channel at 24bit now works.
  38. * 0.20
  39. * Added better register defines.
  40. * 0.21
  41. * Integrated with snd-emu10k1 driver.
  42. * 0.22
  43. * Removed #if 0 ... #endif
  44. *
  45. *
  46. * BUGS:
  47. * Some stability problems when unloading the snd-p16v kernel module.
  48. * --
  49. *
  50. * TODO:
  51. * SPDIF out.
  52. * Find out how to change capture sample rates. E.g. To record SPDIF at 48000Hz.
  53. * Currently capture fixed at 48000Hz.
  54. *
  55. * --
  56. * GENERAL INFO:
  57. * Model: SB0240
  58. * P16V Chip: CA0151-DBS
  59. * Audigy 2 Chip: CA0102-IAT
  60. * AC97 Codec: STAC 9721
  61. * ADC: Philips 1361T (Stereo 24bit)
  62. * DAC: CS4382-K (8-channel, 24bit, 192Khz)
  63. *
  64. * This code was initally based on code from ALSA's emu10k1x.c which is:
  65. * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
  66. *
  67. * This program is free software; you can redistribute it and/or modify
  68. * it under the terms of the GNU General Public License as published by
  69. * the Free Software Foundation; either version 2 of the License, or
  70. * (at your option) any later version.
  71. *
  72. * This program is distributed in the hope that it will be useful,
  73. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  74. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  75. * GNU General Public License for more details.
  76. *
  77. * You should have received a copy of the GNU General Public License
  78. * along with this program; if not, write to the Free Software
  79. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  80. *
  81. */
  82. #include <sound/driver.h>
  83. #include <linux/delay.h>
  84. #include <linux/init.h>
  85. #include <linux/interrupt.h>
  86. #include <linux/pci.h>
  87. #include <linux/slab.h>
  88. #include <linux/moduleparam.h>
  89. #include <sound/core.h>
  90. #include <sound/initval.h>
  91. #include <sound/pcm.h>
  92. #include <sound/ac97_codec.h>
  93. #include <sound/info.h>
  94. #include <sound/emu10k1.h>
  95. #include "p16v.h"
  96. #define SET_CHANNEL 0 /* Testing channel outputs 0=Front, 1=Center/LFE, 2=Unknown, 3=Rear */
  97. #define PCM_FRONT_CHANNEL 0
  98. #define PCM_REAR_CHANNEL 1
  99. #define PCM_CENTER_LFE_CHANNEL 2
  100. #define PCM_UNKNOWN_CHANNEL 3
  101. #define CONTROL_FRONT_CHANNEL 0
  102. #define CONTROL_REAR_CHANNEL 3
  103. #define CONTROL_CENTER_LFE_CHANNEL 1
  104. #define CONTROL_UNKNOWN_CHANNEL 2
  105. /* Card IDs:
  106. * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:2002 -> Audigy2 ZS 7.1 Model:SB0350
  107. * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:1007 -> Audigy2 6.1 Model:SB0240
  108. * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:1002 -> Audigy2 Platinum Model:SB msb0240230009266
  109. * Class 0401: 1102:0004 (rev 04) Subsystem: 1102:2007 -> Audigy4 Pro Model:SB0380 M1SB0380472001901E
  110. *
  111. */
  112. /* hardware definition */
  113. static snd_pcm_hardware_t snd_p16v_playback_hw = {
  114. .info = (SNDRV_PCM_INFO_MMAP |
  115. SNDRV_PCM_INFO_INTERLEAVED |
  116. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  117. SNDRV_PCM_INFO_MMAP_VALID),
  118. .formats = SNDRV_PCM_FMTBIT_S32_LE, /* Only supports 24-bit samples padded to 32 bits. */
  119. .rates = SNDRV_PCM_RATE_192000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_48000 ,
  120. .rate_min = 48000,
  121. .rate_max = 192000,
  122. .channels_min = 8,
  123. .channels_max = 8,
  124. .buffer_bytes_max = (32*1024),
  125. .period_bytes_min = 64,
  126. .period_bytes_max = (16*1024),
  127. .periods_min = 2,
  128. .periods_max = 8,
  129. .fifo_size = 0,
  130. };
  131. static void snd_p16v_pcm_free_substream(snd_pcm_runtime_t *runtime)
  132. {
  133. snd_pcm_t *epcm = runtime->private_data;
  134. if (epcm) {
  135. //snd_printk("epcm free: %p\n", epcm);
  136. kfree(epcm);
  137. }
  138. }
  139. /* open_playback callback */
  140. static int snd_p16v_pcm_open_playback_channel(snd_pcm_substream_t *substream, int channel_id)
  141. {
  142. emu10k1_t *emu = snd_pcm_substream_chip(substream);
  143. emu10k1_voice_t *channel = &(emu->p16v_voices[channel_id]);
  144. emu10k1_pcm_t *epcm;
  145. snd_pcm_runtime_t *runtime = substream->runtime;
  146. int err;
  147. epcm = kcalloc(1, sizeof(*epcm), GFP_KERNEL);
  148. //snd_printk("epcm kcalloc: %p\n", epcm);
  149. if (epcm == NULL)
  150. return -ENOMEM;
  151. epcm->emu = emu;
  152. epcm->substream = substream;
  153. //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id);
  154. runtime->private_data = epcm;
  155. runtime->private_free = snd_p16v_pcm_free_substream;
  156. runtime->hw = snd_p16v_playback_hw;
  157. channel->emu = emu;
  158. channel->number = channel_id;
  159. channel->use=1;
  160. //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use);
  161. //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
  162. //channel->interrupt = snd_p16v_pcm_channel_interrupt;
  163. channel->epcm=epcm;
  164. if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  165. return err;
  166. return 0;
  167. }
  168. /* close callback */
  169. static int snd_p16v_pcm_close_playback(snd_pcm_substream_t *substream)
  170. {
  171. emu10k1_t *emu = snd_pcm_substream_chip(substream);
  172. //snd_pcm_runtime_t *runtime = substream->runtime;
  173. //emu10k1_pcm_t *epcm = runtime->private_data;
  174. emu->p16v_voices[substream->pcm->device - emu->p16v_device_offset].use=0;
  175. /* FIXME: maybe zero others */
  176. return 0;
  177. }
  178. static int snd_p16v_pcm_open_playback_front(snd_pcm_substream_t *substream)
  179. {
  180. return snd_p16v_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
  181. }
  182. /* hw_params callback */
  183. static int snd_p16v_pcm_hw_params_playback(snd_pcm_substream_t *substream,
  184. snd_pcm_hw_params_t * hw_params)
  185. {
  186. int result;
  187. //snd_printk("hw_params alloc: substream=%p\n", substream);
  188. result = snd_pcm_lib_malloc_pages(substream,
  189. params_buffer_bytes(hw_params));
  190. //snd_printk("hw_params alloc: result=%d\n", result);
  191. //dump_stack();
  192. return result;
  193. }
  194. /* hw_free callback */
  195. static int snd_p16v_pcm_hw_free_playback(snd_pcm_substream_t *substream)
  196. {
  197. int result;
  198. //snd_printk("hw_params free: substream=%p\n", substream);
  199. result = snd_pcm_lib_free_pages(substream);
  200. //snd_printk("hw_params free: result=%d\n", result);
  201. //dump_stack();
  202. return result;
  203. }
  204. /* prepare playback callback */
  205. static int snd_p16v_pcm_prepare_playback(snd_pcm_substream_t *substream)
  206. {
  207. emu10k1_t *emu = snd_pcm_substream_chip(substream);
  208. snd_pcm_runtime_t *runtime = substream->runtime;
  209. //emu10k1_pcm_t *epcm = runtime->private_data;
  210. int channel = substream->pcm->device - emu->p16v_device_offset;
  211. u32 *table_base = (u32 *)(emu->p16v_buffer.area+(8*16*channel));
  212. u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
  213. int i;
  214. u32 tmp;
  215. //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));
  216. //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
  217. //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->p16v_buffer.addr, emu->p16v_buffer.area, emu->p16v_buffer.bytes);
  218. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
  219. switch (runtime->rate) {
  220. case 44100:
  221. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x8000); /* FIXME: This will change the capture rate as well! */
  222. break;
  223. case 48000:
  224. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x0000); /* FIXME: This will change the capture rate as well! */
  225. break;
  226. case 96000:
  227. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x4000); /* FIXME: This will change the capture rate as well! */
  228. break;
  229. case 192000:
  230. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, (tmp & ~0xe000) | 0x2000); /* FIXME: This will change the capture rate as well! */
  231. break;
  232. default:
  233. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, channel, 0x0000); /* FIXME: This will change the capture rate as well! */
  234. break;
  235. }
  236. /* FIXME: Check emu->buffer.size before actually writing to it. */
  237. for(i=0; i < runtime->periods; i++) {
  238. table_base[i*2]=runtime->dma_addr+(i*period_size_bytes);
  239. table_base[(i*2)+1]=period_size_bytes<<16;
  240. }
  241. snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_ADDR, channel, emu->p16v_buffer.addr+(8*16*channel));
  242. snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
  243. snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_PTR, channel, 0);
  244. snd_emu10k1_ptr20_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
  245. snd_emu10k1_ptr20_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
  246. snd_emu10k1_ptr20_write(emu, PLAYBACK_POINTER, channel, 0);
  247. snd_emu10k1_ptr20_write(emu, 0x07, channel, 0x0);
  248. snd_emu10k1_ptr20_write(emu, 0x08, channel, 0);
  249. return 0;
  250. }
  251. static void snd_p16v_intr_enable(emu10k1_t *emu, unsigned int intrenb)
  252. {
  253. unsigned long flags;
  254. unsigned int enable;
  255. spin_lock_irqsave(&emu->emu_lock, flags);
  256. enable = inl(emu->port + INTE2) | intrenb;
  257. outl(enable, emu->port + INTE2);
  258. spin_unlock_irqrestore(&emu->emu_lock, flags);
  259. }
  260. static void snd_p16v_intr_disable(emu10k1_t *emu, unsigned int intrenb)
  261. {
  262. unsigned long flags;
  263. unsigned int disable;
  264. spin_lock_irqsave(&emu->emu_lock, flags);
  265. disable = inl(emu->port + INTE2) & (~intrenb);
  266. outl(disable, emu->port + INTE2);
  267. spin_unlock_irqrestore(&emu->emu_lock, flags);
  268. }
  269. /* trigger_playback callback */
  270. static int snd_p16v_pcm_trigger_playback(snd_pcm_substream_t *substream,
  271. int cmd)
  272. {
  273. emu10k1_t *emu = snd_pcm_substream_chip(substream);
  274. snd_pcm_runtime_t *runtime;
  275. emu10k1_pcm_t *epcm;
  276. int channel;
  277. int result = 0;
  278. struct list_head *pos;
  279. snd_pcm_substream_t *s;
  280. u32 basic = 0;
  281. u32 inte = 0;
  282. int running=0;
  283. switch (cmd) {
  284. case SNDRV_PCM_TRIGGER_START:
  285. running=1;
  286. break;
  287. case SNDRV_PCM_TRIGGER_STOP:
  288. default:
  289. running=0;
  290. break;
  291. }
  292. snd_pcm_group_for_each(pos, substream) {
  293. s = snd_pcm_group_substream_entry(pos);
  294. runtime = s->runtime;
  295. epcm = runtime->private_data;
  296. channel = substream->pcm->device-emu->p16v_device_offset;
  297. //snd_printk("p16v channel=%d\n",channel);
  298. epcm->running = running;
  299. basic |= (0x1<<channel);
  300. inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel);
  301. snd_pcm_trigger_done(s, substream);
  302. }
  303. //snd_printk("basic=0x%x, inte=0x%x\n",basic, inte);
  304. switch (cmd) {
  305. case SNDRV_PCM_TRIGGER_START:
  306. snd_p16v_intr_enable(emu, inte);
  307. snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0)| (basic));
  308. break;
  309. case SNDRV_PCM_TRIGGER_STOP:
  310. snd_emu10k1_ptr20_write(emu, BASIC_INTERRUPT, 0, snd_emu10k1_ptr20_read(emu, BASIC_INTERRUPT, 0) & ~(basic));
  311. snd_p16v_intr_disable(emu, inte);
  312. break;
  313. default:
  314. result = -EINVAL;
  315. break;
  316. }
  317. return result;
  318. }
  319. /* pointer_playback callback */
  320. static snd_pcm_uframes_t
  321. snd_p16v_pcm_pointer_playback(snd_pcm_substream_t *substream)
  322. {
  323. emu10k1_t *emu = snd_pcm_substream_chip(substream);
  324. snd_pcm_runtime_t *runtime = substream->runtime;
  325. emu10k1_pcm_t *epcm = runtime->private_data;
  326. snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
  327. int channel = substream->pcm->device - emu->p16v_device_offset;
  328. if (!epcm->running)
  329. return 0;
  330. ptr3 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
  331. ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
  332. ptr4 = snd_emu10k1_ptr20_read(emu, PLAYBACK_LIST_PTR, channel);
  333. if (ptr3 != ptr4) ptr1 = snd_emu10k1_ptr20_read(emu, PLAYBACK_POINTER, channel);
  334. ptr2 = bytes_to_frames(runtime, ptr1);
  335. ptr2+= (ptr4 >> 3) * runtime->period_size;
  336. ptr=ptr2;
  337. if (ptr >= runtime->buffer_size)
  338. ptr -= runtime->buffer_size;
  339. return ptr;
  340. }
  341. /* operators */
  342. static snd_pcm_ops_t snd_p16v_playback_front_ops = {
  343. .open = snd_p16v_pcm_open_playback_front,
  344. .close = snd_p16v_pcm_close_playback,
  345. .ioctl = snd_pcm_lib_ioctl,
  346. .hw_params = snd_p16v_pcm_hw_params_playback,
  347. .hw_free = snd_p16v_pcm_hw_free_playback,
  348. .prepare = snd_p16v_pcm_prepare_playback,
  349. .trigger = snd_p16v_pcm_trigger_playback,
  350. .pointer = snd_p16v_pcm_pointer_playback,
  351. };
  352. int snd_p16v_free(emu10k1_t *chip)
  353. {
  354. // release the data
  355. if (chip->p16v_buffer.area) {
  356. snd_dma_free_pages(&chip->p16v_buffer);
  357. //snd_printk("period lables free: %p\n", &chip->p16v_buffer);
  358. }
  359. return 0;
  360. }
  361. static void snd_p16v_pcm_free(snd_pcm_t *pcm)
  362. {
  363. emu10k1_t *emu = pcm->private_data;
  364. //snd_printk("snd_p16v_pcm_free pcm: called\n");
  365. snd_pcm_lib_preallocate_free_for_all(pcm);
  366. emu->pcm = NULL;
  367. }
  368. int snd_p16v_pcm(emu10k1_t *emu, int device, snd_pcm_t **rpcm)
  369. {
  370. snd_pcm_t *pcm;
  371. snd_pcm_substream_t *substream;
  372. int err;
  373. int capture=0;
  374. //snd_printk("snd_p16v_pcm called. device=%d\n", device);
  375. emu->p16v_device_offset = device;
  376. if (rpcm)
  377. *rpcm = NULL;
  378. //if (device == 0) capture=1;
  379. if ((err = snd_pcm_new(emu->card, "p16v", device, 1, capture, &pcm)) < 0)
  380. return err;
  381. pcm->private_data = emu;
  382. pcm->private_free = snd_p16v_pcm_free;
  383. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_p16v_playback_front_ops);
  384. pcm->info_flags = 0;
  385. pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
  386. strcpy(pcm->name, "p16v");
  387. emu->pcm = pcm;
  388. for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  389. substream;
  390. substream = substream->next) {
  391. if ((err = snd_pcm_lib_preallocate_pages(substream,
  392. SNDRV_DMA_TYPE_DEV,
  393. snd_dma_pci_data(emu->pci),
  394. 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
  395. return err;
  396. //snd_printk("preallocate playback substream: err=%d\n", err);
  397. }
  398. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  399. substream;
  400. substream = substream->next) {
  401. if ((err = snd_pcm_lib_preallocate_pages(substream,
  402. SNDRV_DMA_TYPE_DEV,
  403. snd_dma_pci_data(emu->pci),
  404. 64*1024, 64*1024)) < 0)
  405. return err;
  406. //snd_printk("preallocate capture substream: err=%d\n", err);
  407. }
  408. if (rpcm)
  409. *rpcm = pcm;
  410. return 0;
  411. }
  412. static int snd_p16v_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
  413. {
  414. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  415. uinfo->count = 2;
  416. uinfo->value.integer.min = 0;
  417. uinfo->value.integer.max = 255;
  418. return 0;
  419. }
  420. static int snd_p16v_volume_get(snd_kcontrol_t * kcontrol,
  421. snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
  422. {
  423. emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
  424. u32 value;
  425. value = snd_emu10k1_ptr20_read(emu, reg, high_low);
  426. if (high_low == 1) {
  427. ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */
  428. ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */
  429. } else {
  430. ucontrol->value.integer.value[0] = 0xff - ((value >> 8) & 0xff); /* Left */
  431. ucontrol->value.integer.value[1] = 0xff - ((value >> 0) & 0xff); /* Right */
  432. }
  433. return 0;
  434. }
  435. static int snd_p16v_volume_get_spdif_front(snd_kcontrol_t * kcontrol,
  436. snd_ctl_elem_value_t * ucontrol)
  437. {
  438. int high_low = 0;
  439. int reg = PLAYBACK_VOLUME_MIXER7;
  440. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  441. }
  442. static int snd_p16v_volume_get_spdif_center_lfe(snd_kcontrol_t * kcontrol,
  443. snd_ctl_elem_value_t * ucontrol)
  444. {
  445. int high_low = 1;
  446. int reg = PLAYBACK_VOLUME_MIXER7;
  447. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  448. }
  449. static int snd_p16v_volume_get_spdif_unknown(snd_kcontrol_t * kcontrol,
  450. snd_ctl_elem_value_t * ucontrol)
  451. {
  452. int high_low = 0;
  453. int reg = PLAYBACK_VOLUME_MIXER8;
  454. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  455. }
  456. static int snd_p16v_volume_get_spdif_rear(snd_kcontrol_t * kcontrol,
  457. snd_ctl_elem_value_t * ucontrol)
  458. {
  459. int high_low = 1;
  460. int reg = PLAYBACK_VOLUME_MIXER8;
  461. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  462. }
  463. static int snd_p16v_volume_get_analog_front(snd_kcontrol_t * kcontrol,
  464. snd_ctl_elem_value_t * ucontrol)
  465. {
  466. int high_low = 0;
  467. int reg = PLAYBACK_VOLUME_MIXER9;
  468. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  469. }
  470. static int snd_p16v_volume_get_analog_center_lfe(snd_kcontrol_t * kcontrol,
  471. snd_ctl_elem_value_t * ucontrol)
  472. {
  473. int high_low = 1;
  474. int reg = PLAYBACK_VOLUME_MIXER9;
  475. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  476. }
  477. static int snd_p16v_volume_get_analog_rear(snd_kcontrol_t * kcontrol,
  478. snd_ctl_elem_value_t * ucontrol)
  479. {
  480. int high_low = 1;
  481. int reg = PLAYBACK_VOLUME_MIXER10;
  482. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  483. }
  484. static int snd_p16v_volume_get_analog_unknown(snd_kcontrol_t * kcontrol,
  485. snd_ctl_elem_value_t * ucontrol)
  486. {
  487. int high_low = 0;
  488. int reg = PLAYBACK_VOLUME_MIXER10;
  489. return snd_p16v_volume_get(kcontrol, ucontrol, reg, high_low);
  490. }
  491. static int snd_p16v_volume_put(snd_kcontrol_t * kcontrol,
  492. snd_ctl_elem_value_t * ucontrol, int reg, int high_low)
  493. {
  494. emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
  495. u32 value;
  496. value = snd_emu10k1_ptr20_read(emu, reg, 0);
  497. //value = value & 0xffff;
  498. if (high_low == 1) {
  499. value &= 0xffff;
  500. value = value | ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16);
  501. } else {
  502. value &= 0xffff0000;
  503. value = value | ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) );
  504. }
  505. snd_emu10k1_ptr20_write(emu, reg, 0, value);
  506. return 1;
  507. }
  508. static int snd_p16v_volume_put_spdif_front(snd_kcontrol_t * kcontrol,
  509. snd_ctl_elem_value_t * ucontrol)
  510. {
  511. int high_low = 0;
  512. int reg = PLAYBACK_VOLUME_MIXER7;
  513. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  514. }
  515. static int snd_p16v_volume_put_spdif_center_lfe(snd_kcontrol_t * kcontrol,
  516. snd_ctl_elem_value_t * ucontrol)
  517. {
  518. int high_low = 1;
  519. int reg = PLAYBACK_VOLUME_MIXER7;
  520. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  521. }
  522. static int snd_p16v_volume_put_spdif_unknown(snd_kcontrol_t * kcontrol,
  523. snd_ctl_elem_value_t * ucontrol)
  524. {
  525. int high_low = 0;
  526. int reg = PLAYBACK_VOLUME_MIXER8;
  527. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  528. }
  529. static int snd_p16v_volume_put_spdif_rear(snd_kcontrol_t * kcontrol,
  530. snd_ctl_elem_value_t * ucontrol)
  531. {
  532. int high_low = 1;
  533. int reg = PLAYBACK_VOLUME_MIXER8;
  534. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  535. }
  536. static int snd_p16v_volume_put_analog_front(snd_kcontrol_t * kcontrol,
  537. snd_ctl_elem_value_t * ucontrol)
  538. {
  539. int high_low = 0;
  540. int reg = PLAYBACK_VOLUME_MIXER9;
  541. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  542. }
  543. static int snd_p16v_volume_put_analog_center_lfe(snd_kcontrol_t * kcontrol,
  544. snd_ctl_elem_value_t * ucontrol)
  545. {
  546. int high_low = 1;
  547. int reg = PLAYBACK_VOLUME_MIXER9;
  548. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  549. }
  550. static int snd_p16v_volume_put_analog_rear(snd_kcontrol_t * kcontrol,
  551. snd_ctl_elem_value_t * ucontrol)
  552. {
  553. int high_low = 1;
  554. int reg = PLAYBACK_VOLUME_MIXER10;
  555. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  556. }
  557. static int snd_p16v_volume_put_analog_unknown(snd_kcontrol_t * kcontrol,
  558. snd_ctl_elem_value_t * ucontrol)
  559. {
  560. int high_low = 0;
  561. int reg = PLAYBACK_VOLUME_MIXER10;
  562. return snd_p16v_volume_put(kcontrol, ucontrol, reg, high_low);
  563. }
  564. static snd_kcontrol_new_t snd_p16v_volume_control_analog_front =
  565. {
  566. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  567. .name = "HD Analog Front Volume",
  568. .info = snd_p16v_volume_info,
  569. .get = snd_p16v_volume_get_analog_front,
  570. .put = snd_p16v_volume_put_analog_front
  571. };
  572. static snd_kcontrol_new_t snd_p16v_volume_control_analog_center_lfe =
  573. {
  574. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  575. .name = "HD Analog Center/LFE Volume",
  576. .info = snd_p16v_volume_info,
  577. .get = snd_p16v_volume_get_analog_center_lfe,
  578. .put = snd_p16v_volume_put_analog_center_lfe
  579. };
  580. static snd_kcontrol_new_t snd_p16v_volume_control_analog_unknown =
  581. {
  582. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  583. .name = "HD Analog Unknown Volume",
  584. .info = snd_p16v_volume_info,
  585. .get = snd_p16v_volume_get_analog_unknown,
  586. .put = snd_p16v_volume_put_analog_unknown
  587. };
  588. static snd_kcontrol_new_t snd_p16v_volume_control_analog_rear =
  589. {
  590. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  591. .name = "HD Analog Rear Volume",
  592. .info = snd_p16v_volume_info,
  593. .get = snd_p16v_volume_get_analog_rear,
  594. .put = snd_p16v_volume_put_analog_rear
  595. };
  596. static snd_kcontrol_new_t snd_p16v_volume_control_spdif_front =
  597. {
  598. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  599. .name = "HD SPDIF Front Volume",
  600. .info = snd_p16v_volume_info,
  601. .get = snd_p16v_volume_get_spdif_front,
  602. .put = snd_p16v_volume_put_spdif_front
  603. };
  604. static snd_kcontrol_new_t snd_p16v_volume_control_spdif_center_lfe =
  605. {
  606. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  607. .name = "HD SPDIF Center/LFE Volume",
  608. .info = snd_p16v_volume_info,
  609. .get = snd_p16v_volume_get_spdif_center_lfe,
  610. .put = snd_p16v_volume_put_spdif_center_lfe
  611. };
  612. static snd_kcontrol_new_t snd_p16v_volume_control_spdif_unknown =
  613. {
  614. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  615. .name = "HD SPDIF Unknown Volume",
  616. .info = snd_p16v_volume_info,
  617. .get = snd_p16v_volume_get_spdif_unknown,
  618. .put = snd_p16v_volume_put_spdif_unknown
  619. };
  620. static snd_kcontrol_new_t snd_p16v_volume_control_spdif_rear =
  621. {
  622. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  623. .name = "HD SPDIF Rear Volume",
  624. .info = snd_p16v_volume_info,
  625. .get = snd_p16v_volume_get_spdif_rear,
  626. .put = snd_p16v_volume_put_spdif_rear
  627. };
  628. int snd_p16v_mixer(emu10k1_t *emu)
  629. {
  630. int err;
  631. snd_kcontrol_t *kctl;
  632. snd_card_t *card = emu->card;
  633. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_front, emu)) == NULL)
  634. return -ENOMEM;
  635. if ((err = snd_ctl_add(card, kctl)))
  636. return err;
  637. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_rear, emu)) == NULL)
  638. return -ENOMEM;
  639. if ((err = snd_ctl_add(card, kctl)))
  640. return err;
  641. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_center_lfe, emu)) == NULL)
  642. return -ENOMEM;
  643. if ((err = snd_ctl_add(card, kctl)))
  644. return err;
  645. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_analog_unknown, emu)) == NULL)
  646. return -ENOMEM;
  647. if ((err = snd_ctl_add(card, kctl)))
  648. return err;
  649. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_front, emu)) == NULL)
  650. return -ENOMEM;
  651. if ((err = snd_ctl_add(card, kctl)))
  652. return err;
  653. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_rear, emu)) == NULL)
  654. return -ENOMEM;
  655. if ((err = snd_ctl_add(card, kctl)))
  656. return err;
  657. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_center_lfe, emu)) == NULL)
  658. return -ENOMEM;
  659. if ((err = snd_ctl_add(card, kctl)))
  660. return err;
  661. if ((kctl = snd_ctl_new1(&snd_p16v_volume_control_spdif_unknown, emu)) == NULL)
  662. return -ENOMEM;
  663. if ((err = snd_ctl_add(card, kctl)))
  664. return err;
  665. return 0;
  666. }