ice1724.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  1. /*
  2. * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT)
  3. * VIA VT1720 (Envy24PT)
  4. *
  5. * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
  6. * 2002 James Stafford <jstafford@ampltd.com>
  7. * 2003 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/driver.h>
  25. #include <asm/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/slab.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/mutex.h>
  33. #include <sound/core.h>
  34. #include <sound/info.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/initval.h>
  37. #include <sound/asoundef.h>
  38. #include "ice1712.h"
  39. #include "envy24ht.h"
  40. /* lowlevel routines */
  41. #include "amp.h"
  42. #include "revo.h"
  43. #include "aureon.h"
  44. #include "vt1720_mobo.h"
  45. #include "pontis.h"
  46. #include "prodigy192.h"
  47. #include "juli.h"
  48. #include "phase.h"
  49. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  50. MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)");
  51. MODULE_LICENSE("GPL");
  52. MODULE_SUPPORTED_DEVICE("{"
  53. REVO_DEVICE_DESC
  54. AMP_AUDIO2000_DEVICE_DESC
  55. AUREON_DEVICE_DESC
  56. VT1720_MOBO_DEVICE_DESC
  57. PONTIS_DEVICE_DESC
  58. PRODIGY192_DEVICE_DESC
  59. JULI_DEVICE_DESC
  60. PHASE_DEVICE_DESC
  61. "{VIA,VT1720},"
  62. "{VIA,VT1724},"
  63. "{ICEnsemble,Generic ICE1724},"
  64. "{ICEnsemble,Generic Envy24HT}"
  65. "{ICEnsemble,Generic Envy24PT}}");
  66. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  67. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  68. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  69. static char *model[SNDRV_CARDS];
  70. module_param_array(index, int, NULL, 0444);
  71. MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard.");
  72. module_param_array(id, charp, NULL, 0444);
  73. MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard.");
  74. module_param_array(enable, bool, NULL, 0444);
  75. MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard.");
  76. module_param_array(model, charp, NULL, 0444);
  77. MODULE_PARM_DESC(model, "Use the given board model.");
  78. /* Both VT1720 and VT1724 have the same PCI IDs */
  79. static struct pci_device_id snd_vt1724_ids[] = {
  80. { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  81. { 0, }
  82. };
  83. MODULE_DEVICE_TABLE(pci, snd_vt1724_ids);
  84. static int PRO_RATE_LOCKED;
  85. static int PRO_RATE_RESET = 1;
  86. static unsigned int PRO_RATE_DEFAULT = 44100;
  87. /*
  88. * Basic I/O
  89. */
  90. /* check whether the clock mode is spdif-in */
  91. static inline int is_spdif_master(struct snd_ice1712 *ice)
  92. {
  93. return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
  94. }
  95. static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
  96. {
  97. return is_spdif_master(ice) || PRO_RATE_LOCKED;
  98. }
  99. /*
  100. * ac97 section
  101. */
  102. static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
  103. {
  104. unsigned char old_cmd;
  105. int tm;
  106. for (tm = 0; tm < 0x10000; tm++) {
  107. old_cmd = inb(ICEMT1724(ice, AC97_CMD));
  108. if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ))
  109. continue;
  110. if (!(old_cmd & VT1724_AC97_READY))
  111. continue;
  112. return old_cmd;
  113. }
  114. snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n");
  115. return old_cmd;
  116. }
  117. static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
  118. {
  119. int tm;
  120. for (tm = 0; tm < 0x10000; tm++)
  121. if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
  122. return 0;
  123. snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n");
  124. return -EIO;
  125. }
  126. static void snd_vt1724_ac97_write(struct snd_ac97 *ac97,
  127. unsigned short reg,
  128. unsigned short val)
  129. {
  130. struct snd_ice1712 *ice = ac97->private_data;
  131. unsigned char old_cmd;
  132. old_cmd = snd_vt1724_ac97_ready(ice);
  133. old_cmd &= ~VT1724_AC97_ID_MASK;
  134. old_cmd |= ac97->num;
  135. outb(reg, ICEMT1724(ice, AC97_INDEX));
  136. outw(val, ICEMT1724(ice, AC97_DATA));
  137. outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD));
  138. snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE);
  139. }
  140. static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
  141. {
  142. struct snd_ice1712 *ice = ac97->private_data;
  143. unsigned char old_cmd;
  144. old_cmd = snd_vt1724_ac97_ready(ice);
  145. old_cmd &= ~VT1724_AC97_ID_MASK;
  146. old_cmd |= ac97->num;
  147. outb(reg, ICEMT1724(ice, AC97_INDEX));
  148. outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD));
  149. if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0)
  150. return ~0;
  151. return inw(ICEMT1724(ice, AC97_DATA));
  152. }
  153. /*
  154. * GPIO operations
  155. */
  156. /* set gpio direction 0 = read, 1 = write */
  157. static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
  158. {
  159. outl(data, ICEREG1724(ice, GPIO_DIRECTION));
  160. inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */
  161. }
  162. /* set the gpio mask (0 = writable) */
  163. static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
  164. {
  165. outw(data, ICEREG1724(ice, GPIO_WRITE_MASK));
  166. if (! ice->vt1720) /* VT1720 supports only 16 GPIO bits */
  167. outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22));
  168. inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */
  169. }
  170. static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data)
  171. {
  172. outw(data, ICEREG1724(ice, GPIO_DATA));
  173. if (! ice->vt1720)
  174. outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22));
  175. inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */
  176. }
  177. static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
  178. {
  179. unsigned int data;
  180. if (! ice->vt1720)
  181. data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22));
  182. else
  183. data = 0;
  184. data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA));
  185. return data;
  186. }
  187. /*
  188. * Interrupt handler
  189. */
  190. static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
  191. {
  192. struct snd_ice1712 *ice = dev_id;
  193. unsigned char status;
  194. int handled = 0;
  195. while (1) {
  196. status = inb(ICEREG1724(ice, IRQSTAT));
  197. if (status == 0)
  198. break;
  199. handled = 1;
  200. /* these should probably be separated at some point,
  201. * but as we don't currently have MPU support on the board
  202. * I will leave it
  203. */
  204. if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) {
  205. if (ice->rmidi[0])
  206. snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
  207. outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT));
  208. status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX);
  209. }
  210. if (status & VT1724_IRQ_MTPCM) {
  211. /*
  212. * Multi-track PCM
  213. * PCM assignment are:
  214. * Playback DMA0 (M/C) = playback_pro_substream
  215. * Playback DMA1 = playback_con_substream_ds[0]
  216. * Playback DMA2 = playback_con_substream_ds[1]
  217. * Playback DMA3 = playback_con_substream_ds[2]
  218. * Playback DMA4 (SPDIF) = playback_con_substream
  219. * Record DMA0 = capture_pro_substream
  220. * Record DMA1 = capture_con_substream
  221. */
  222. unsigned char mtstat = inb(ICEMT1724(ice, IRQ));
  223. if (mtstat & VT1724_MULTI_PDMA0) {
  224. if (ice->playback_pro_substream)
  225. snd_pcm_period_elapsed(ice->playback_pro_substream);
  226. }
  227. if (mtstat & VT1724_MULTI_RDMA0) {
  228. if (ice->capture_pro_substream)
  229. snd_pcm_period_elapsed(ice->capture_pro_substream);
  230. }
  231. if (mtstat & VT1724_MULTI_PDMA1) {
  232. if (ice->playback_con_substream_ds[0])
  233. snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]);
  234. }
  235. if (mtstat & VT1724_MULTI_PDMA2) {
  236. if (ice->playback_con_substream_ds[1])
  237. snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]);
  238. }
  239. if (mtstat & VT1724_MULTI_PDMA3) {
  240. if (ice->playback_con_substream_ds[2])
  241. snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]);
  242. }
  243. if (mtstat & VT1724_MULTI_PDMA4) {
  244. if (ice->playback_con_substream)
  245. snd_pcm_period_elapsed(ice->playback_con_substream);
  246. }
  247. if (mtstat & VT1724_MULTI_RDMA1) {
  248. if (ice->capture_con_substream)
  249. snd_pcm_period_elapsed(ice->capture_con_substream);
  250. }
  251. /* ack anyway to avoid freeze */
  252. outb(mtstat, ICEMT1724(ice, IRQ));
  253. /* ought to really handle this properly */
  254. if (mtstat & VT1724_MULTI_FIFO_ERR) {
  255. unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR));
  256. outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR));
  257. outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK));
  258. /* If I don't do this, I get machine lockup due to continual interrupts */
  259. }
  260. }
  261. }
  262. return IRQ_RETVAL(handled);
  263. }
  264. /*
  265. * PCM code - professional part (multitrack)
  266. */
  267. static unsigned int rates[] = {
  268. 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  269. 32000, 44100, 48000, 64000, 88200, 96000,
  270. 176400, 192000,
  271. };
  272. static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = {
  273. .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */
  274. .list = rates,
  275. .mask = 0,
  276. };
  277. static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = {
  278. .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */
  279. .list = rates,
  280. .mask = 0,
  281. };
  282. static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = {
  283. .count = ARRAY_SIZE(rates),
  284. .list = rates,
  285. .mask = 0,
  286. };
  287. struct vt1724_pcm_reg {
  288. unsigned int addr; /* ADDR register offset */
  289. unsigned int size; /* SIZE register offset */
  290. unsigned int count; /* COUNT register offset */
  291. unsigned int start; /* start & pause bit */
  292. };
  293. static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  294. {
  295. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  296. unsigned char what;
  297. unsigned char old;
  298. struct list_head *pos;
  299. struct snd_pcm_substream *s;
  300. what = 0;
  301. snd_pcm_group_for_each(pos, substream) {
  302. struct vt1724_pcm_reg *reg;
  303. s = snd_pcm_group_substream_entry(pos);
  304. reg = s->runtime->private_data;
  305. what |= reg->start;
  306. snd_pcm_trigger_done(s, substream);
  307. }
  308. switch (cmd) {
  309. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  310. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  311. spin_lock(&ice->reg_lock);
  312. old = inb(ICEMT1724(ice, DMA_PAUSE));
  313. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  314. old |= what;
  315. else
  316. old &= ~what;
  317. outb(old, ICEMT1724(ice, DMA_PAUSE));
  318. spin_unlock(&ice->reg_lock);
  319. break;
  320. case SNDRV_PCM_TRIGGER_START:
  321. case SNDRV_PCM_TRIGGER_STOP:
  322. spin_lock(&ice->reg_lock);
  323. old = inb(ICEMT1724(ice, DMA_CONTROL));
  324. if (cmd == SNDRV_PCM_TRIGGER_START)
  325. old |= what;
  326. else
  327. old &= ~what;
  328. outb(old, ICEMT1724(ice, DMA_CONTROL));
  329. spin_unlock(&ice->reg_lock);
  330. break;
  331. default:
  332. return -EINVAL;
  333. }
  334. return 0;
  335. }
  336. /*
  337. */
  338. #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\
  339. VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START)
  340. #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
  341. VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
  342. static int get_max_rate(struct snd_ice1712 *ice)
  343. {
  344. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  345. if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
  346. return 192000;
  347. else
  348. return 96000;
  349. } else
  350. return 48000;
  351. }
  352. static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
  353. int force)
  354. {
  355. unsigned long flags;
  356. unsigned char val, old;
  357. unsigned int i, mclk_change;
  358. if (rate > get_max_rate(ice))
  359. return;
  360. switch (rate) {
  361. case 8000: val = 6; break;
  362. case 9600: val = 3; break;
  363. case 11025: val = 10; break;
  364. case 12000: val = 2; break;
  365. case 16000: val = 5; break;
  366. case 22050: val = 9; break;
  367. case 24000: val = 1; break;
  368. case 32000: val = 4; break;
  369. case 44100: val = 8; break;
  370. case 48000: val = 0; break;
  371. case 64000: val = 15; break;
  372. case 88200: val = 11; break;
  373. case 96000: val = 7; break;
  374. case 176400: val = 12; break;
  375. case 192000: val = 14; break;
  376. default:
  377. snd_BUG();
  378. val = 0;
  379. break;
  380. }
  381. spin_lock_irqsave(&ice->reg_lock, flags);
  382. if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
  383. (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
  384. /* running? we cannot change the rate now... */
  385. spin_unlock_irqrestore(&ice->reg_lock, flags);
  386. return;
  387. }
  388. if (!force && is_pro_rate_locked(ice)) {
  389. spin_unlock_irqrestore(&ice->reg_lock, flags);
  390. return;
  391. }
  392. old = inb(ICEMT1724(ice, RATE));
  393. if (force || old != val)
  394. outb(val, ICEMT1724(ice, RATE));
  395. else if (rate == ice->cur_rate) {
  396. spin_unlock_irqrestore(&ice->reg_lock, flags);
  397. return;
  398. }
  399. ice->cur_rate = rate;
  400. /* check MT02 */
  401. mclk_change = 0;
  402. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  403. val = old = inb(ICEMT1724(ice, I2S_FORMAT));
  404. if (rate > 96000)
  405. val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
  406. else
  407. val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
  408. if (val != old) {
  409. outb(val, ICEMT1724(ice, I2S_FORMAT));
  410. mclk_change = 1;
  411. }
  412. }
  413. spin_unlock_irqrestore(&ice->reg_lock, flags);
  414. if (mclk_change && ice->gpio.i2s_mclk_changed)
  415. ice->gpio.i2s_mclk_changed(ice);
  416. if (ice->gpio.set_pro_rate)
  417. ice->gpio.set_pro_rate(ice, rate);
  418. /* set up codecs */
  419. for (i = 0; i < ice->akm_codecs; i++) {
  420. if (ice->akm[i].ops.set_rate_val)
  421. ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
  422. }
  423. if (ice->spdif.ops.setup_rate)
  424. ice->spdif.ops.setup_rate(ice, rate);
  425. }
  426. static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream,
  427. struct snd_pcm_hw_params *hw_params)
  428. {
  429. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  430. int i, chs;
  431. chs = params_channels(hw_params);
  432. mutex_lock(&ice->open_mutex);
  433. /* mark surround channels */
  434. if (substream == ice->playback_pro_substream) {
  435. /* PDMA0 can be multi-channel up to 8 */
  436. chs = chs / 2 - 1;
  437. for (i = 0; i < chs; i++) {
  438. if (ice->pcm_reserved[i] &&
  439. ice->pcm_reserved[i] != substream) {
  440. mutex_unlock(&ice->open_mutex);
  441. return -EBUSY;
  442. }
  443. ice->pcm_reserved[i] = substream;
  444. }
  445. for (; i < 3; i++) {
  446. if (ice->pcm_reserved[i] == substream)
  447. ice->pcm_reserved[i] = NULL;
  448. }
  449. } else {
  450. for (i = 0; i < 3; i++) {
  451. /* check individual playback stream */
  452. if (ice->playback_con_substream_ds[i] == substream) {
  453. if (ice->pcm_reserved[i] &&
  454. ice->pcm_reserved[i] != substream) {
  455. mutex_unlock(&ice->open_mutex);
  456. return -EBUSY;
  457. }
  458. ice->pcm_reserved[i] = substream;
  459. break;
  460. }
  461. }
  462. }
  463. mutex_unlock(&ice->open_mutex);
  464. snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0);
  465. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  466. }
  467. static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream)
  468. {
  469. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  470. int i;
  471. mutex_lock(&ice->open_mutex);
  472. /* unmark surround channels */
  473. for (i = 0; i < 3; i++)
  474. if (ice->pcm_reserved[i] == substream)
  475. ice->pcm_reserved[i] = NULL;
  476. mutex_unlock(&ice->open_mutex);
  477. return snd_pcm_lib_free_pages(substream);
  478. }
  479. static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
  480. {
  481. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  482. unsigned char val;
  483. unsigned int size;
  484. spin_lock_irq(&ice->reg_lock);
  485. val = (8 - substream->runtime->channels) >> 1;
  486. outb(val, ICEMT1724(ice, BURST));
  487. outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR));
  488. size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1;
  489. // outl(size, ICEMT1724(ice, PLAYBACK_SIZE));
  490. outw(size, ICEMT1724(ice, PLAYBACK_SIZE));
  491. outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2);
  492. size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  493. // outl(size, ICEMT1724(ice, PLAYBACK_COUNT));
  494. outw(size, ICEMT1724(ice, PLAYBACK_COUNT));
  495. outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2);
  496. spin_unlock_irq(&ice->reg_lock);
  497. // printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream));
  498. return 0;
  499. }
  500. static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream)
  501. {
  502. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  503. size_t ptr;
  504. if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START))
  505. return 0;
  506. #if 0 /* read PLAYBACK_ADDR */
  507. ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
  508. if (ptr < substream->runtime->dma_addr) {
  509. snd_printd("ice1724: invalid negative ptr\n");
  510. return 0;
  511. }
  512. ptr -= substream->runtime->dma_addr;
  513. ptr = bytes_to_frames(substream->runtime, ptr);
  514. if (ptr >= substream->runtime->buffer_size) {
  515. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  516. (int)ptr, (int)substream->runtime->period_size);
  517. return 0;
  518. }
  519. #else /* read PLAYBACK_SIZE */
  520. ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff;
  521. ptr = (ptr + 1) << 2;
  522. ptr = bytes_to_frames(substream->runtime, ptr);
  523. if (! ptr)
  524. ;
  525. else if (ptr <= substream->runtime->buffer_size)
  526. ptr = substream->runtime->buffer_size - ptr;
  527. else {
  528. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  529. (int)ptr, (int)substream->runtime->buffer_size);
  530. ptr = 0;
  531. }
  532. #endif
  533. return ptr;
  534. }
  535. static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream)
  536. {
  537. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  538. struct vt1724_pcm_reg *reg = substream->runtime->private_data;
  539. spin_lock_irq(&ice->reg_lock);
  540. outl(substream->runtime->dma_addr, ice->profi_port + reg->addr);
  541. outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1,
  542. ice->profi_port + reg->size);
  543. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1,
  544. ice->profi_port + reg->count);
  545. spin_unlock_irq(&ice->reg_lock);
  546. return 0;
  547. }
  548. static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream)
  549. {
  550. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  551. struct vt1724_pcm_reg *reg = substream->runtime->private_data;
  552. size_t ptr;
  553. if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start))
  554. return 0;
  555. #if 0 /* use ADDR register */
  556. ptr = inl(ice->profi_port + reg->addr);
  557. ptr -= substream->runtime->dma_addr;
  558. return bytes_to_frames(substream->runtime, ptr);
  559. #else /* use SIZE register */
  560. ptr = inw(ice->profi_port + reg->size);
  561. ptr = (ptr + 1) << 2;
  562. ptr = bytes_to_frames(substream->runtime, ptr);
  563. if (! ptr)
  564. ;
  565. else if (ptr <= substream->runtime->buffer_size)
  566. ptr = substream->runtime->buffer_size - ptr;
  567. else {
  568. snd_printd("ice1724: invalid ptr %d (size=%d)\n",
  569. (int)ptr, (int)substream->runtime->buffer_size);
  570. ptr = 0;
  571. }
  572. return ptr;
  573. #endif
  574. }
  575. static struct vt1724_pcm_reg vt1724_playback_pro_reg = {
  576. .addr = VT1724_MT_PLAYBACK_ADDR,
  577. .size = VT1724_MT_PLAYBACK_SIZE,
  578. .count = VT1724_MT_PLAYBACK_COUNT,
  579. .start = VT1724_PDMA0_START,
  580. };
  581. static struct vt1724_pcm_reg vt1724_capture_pro_reg = {
  582. .addr = VT1724_MT_CAPTURE_ADDR,
  583. .size = VT1724_MT_CAPTURE_SIZE,
  584. .count = VT1724_MT_CAPTURE_COUNT,
  585. .start = VT1724_RDMA0_START,
  586. };
  587. static struct snd_pcm_hardware snd_vt1724_playback_pro =
  588. {
  589. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  590. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  591. SNDRV_PCM_INFO_MMAP_VALID |
  592. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  593. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  594. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
  595. .rate_min = 8000,
  596. .rate_max = 192000,
  597. .channels_min = 2,
  598. .channels_max = 8,
  599. .buffer_bytes_max = (1UL << 21), /* 19bits dword */
  600. .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */
  601. .period_bytes_max = (1UL << 21),
  602. .periods_min = 2,
  603. .periods_max = 1024,
  604. };
  605. static struct snd_pcm_hardware snd_vt1724_spdif =
  606. {
  607. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  608. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  609. SNDRV_PCM_INFO_MMAP_VALID |
  610. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  611. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  612. .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
  613. SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
  614. SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
  615. SNDRV_PCM_RATE_192000),
  616. .rate_min = 32000,
  617. .rate_max = 192000,
  618. .channels_min = 2,
  619. .channels_max = 2,
  620. .buffer_bytes_max = (1UL << 18), /* 16bits dword */
  621. .period_bytes_min = 2 * 4 * 2,
  622. .period_bytes_max = (1UL << 18),
  623. .periods_min = 2,
  624. .periods_max = 1024,
  625. };
  626. static struct snd_pcm_hardware snd_vt1724_2ch_stereo =
  627. {
  628. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  629. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  630. SNDRV_PCM_INFO_MMAP_VALID |
  631. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  632. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  633. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000,
  634. .rate_min = 8000,
  635. .rate_max = 192000,
  636. .channels_min = 2,
  637. .channels_max = 2,
  638. .buffer_bytes_max = (1UL << 18), /* 16bits dword */
  639. .period_bytes_min = 2 * 4 * 2,
  640. .period_bytes_max = (1UL << 18),
  641. .periods_min = 2,
  642. .periods_max = 1024,
  643. };
  644. /*
  645. * set rate constraints
  646. */
  647. static int set_rate_constraints(struct snd_ice1712 *ice,
  648. struct snd_pcm_substream *substream)
  649. {
  650. struct snd_pcm_runtime *runtime = substream->runtime;
  651. if (ice->hw_rates) {
  652. /* hardware specific */
  653. runtime->hw.rate_min = ice->hw_rates->list[0];
  654. runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
  655. runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
  656. return snd_pcm_hw_constraint_list(runtime, 0,
  657. SNDRV_PCM_HW_PARAM_RATE,
  658. ice->hw_rates);
  659. }
  660. if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
  661. /* I2S */
  662. /* VT1720 doesn't support more than 96kHz */
  663. if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
  664. return snd_pcm_hw_constraint_list(runtime, 0,
  665. SNDRV_PCM_HW_PARAM_RATE,
  666. &hw_constraints_rates_192);
  667. else {
  668. runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
  669. SNDRV_PCM_RATE_8000_96000;
  670. runtime->hw.rate_max = 96000;
  671. return snd_pcm_hw_constraint_list(runtime, 0,
  672. SNDRV_PCM_HW_PARAM_RATE,
  673. &hw_constraints_rates_96);
  674. }
  675. } else if (ice->ac97) {
  676. /* ACLINK */
  677. runtime->hw.rate_max = 48000;
  678. runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
  679. return snd_pcm_hw_constraint_list(runtime, 0,
  680. SNDRV_PCM_HW_PARAM_RATE,
  681. &hw_constraints_rates_48);
  682. }
  683. return 0;
  684. }
  685. /* multi-channel playback needs alignment 8x32bit regardless of the channels
  686. * actually used
  687. */
  688. #define VT1724_BUFFER_ALIGN 0x20
  689. static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream)
  690. {
  691. struct snd_pcm_runtime *runtime = substream->runtime;
  692. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  693. int chs;
  694. runtime->private_data = &vt1724_playback_pro_reg;
  695. ice->playback_pro_substream = substream;
  696. runtime->hw = snd_vt1724_playback_pro;
  697. snd_pcm_set_sync(substream);
  698. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  699. set_rate_constraints(ice, substream);
  700. mutex_lock(&ice->open_mutex);
  701. /* calculate the currently available channels */
  702. for (chs = 0; chs < 3; chs++) {
  703. if (ice->pcm_reserved[chs])
  704. break;
  705. }
  706. chs = (chs + 1) * 2;
  707. runtime->hw.channels_max = chs;
  708. if (chs > 2) /* channels must be even */
  709. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  710. mutex_unlock(&ice->open_mutex);
  711. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  712. VT1724_BUFFER_ALIGN);
  713. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  714. VT1724_BUFFER_ALIGN);
  715. return 0;
  716. }
  717. static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream)
  718. {
  719. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  720. struct snd_pcm_runtime *runtime = substream->runtime;
  721. runtime->private_data = &vt1724_capture_pro_reg;
  722. ice->capture_pro_substream = substream;
  723. runtime->hw = snd_vt1724_2ch_stereo;
  724. snd_pcm_set_sync(substream);
  725. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  726. set_rate_constraints(ice, substream);
  727. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  728. VT1724_BUFFER_ALIGN);
  729. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  730. VT1724_BUFFER_ALIGN);
  731. return 0;
  732. }
  733. static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
  734. {
  735. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  736. if (PRO_RATE_RESET)
  737. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  738. ice->playback_pro_substream = NULL;
  739. return 0;
  740. }
  741. static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
  742. {
  743. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  744. if (PRO_RATE_RESET)
  745. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  746. ice->capture_pro_substream = NULL;
  747. return 0;
  748. }
  749. static struct snd_pcm_ops snd_vt1724_playback_pro_ops = {
  750. .open = snd_vt1724_playback_pro_open,
  751. .close = snd_vt1724_playback_pro_close,
  752. .ioctl = snd_pcm_lib_ioctl,
  753. .hw_params = snd_vt1724_pcm_hw_params,
  754. .hw_free = snd_vt1724_pcm_hw_free,
  755. .prepare = snd_vt1724_playback_pro_prepare,
  756. .trigger = snd_vt1724_pcm_trigger,
  757. .pointer = snd_vt1724_playback_pro_pointer,
  758. };
  759. static struct snd_pcm_ops snd_vt1724_capture_pro_ops = {
  760. .open = snd_vt1724_capture_pro_open,
  761. .close = snd_vt1724_capture_pro_close,
  762. .ioctl = snd_pcm_lib_ioctl,
  763. .hw_params = snd_vt1724_pcm_hw_params,
  764. .hw_free = snd_vt1724_pcm_hw_free,
  765. .prepare = snd_vt1724_pcm_prepare,
  766. .trigger = snd_vt1724_pcm_trigger,
  767. .pointer = snd_vt1724_pcm_pointer,
  768. };
  769. static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 * ice, int device)
  770. {
  771. struct snd_pcm *pcm;
  772. int err;
  773. err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm);
  774. if (err < 0)
  775. return err;
  776. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops);
  777. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops);
  778. pcm->private_data = ice;
  779. pcm->info_flags = 0;
  780. strcpy(pcm->name, "ICE1724");
  781. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  782. snd_dma_pci_data(ice->pci),
  783. 256*1024, 256*1024);
  784. ice->pcm_pro = pcm;
  785. return 0;
  786. }
  787. /*
  788. * SPDIF PCM
  789. */
  790. static struct vt1724_pcm_reg vt1724_playback_spdif_reg = {
  791. .addr = VT1724_MT_PDMA4_ADDR,
  792. .size = VT1724_MT_PDMA4_SIZE,
  793. .count = VT1724_MT_PDMA4_COUNT,
  794. .start = VT1724_PDMA4_START,
  795. };
  796. static struct vt1724_pcm_reg vt1724_capture_spdif_reg = {
  797. .addr = VT1724_MT_RDMA1_ADDR,
  798. .size = VT1724_MT_RDMA1_SIZE,
  799. .count = VT1724_MT_RDMA1_COUNT,
  800. .start = VT1724_RDMA1_START,
  801. };
  802. /* update spdif control bits; call with reg_lock */
  803. static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val)
  804. {
  805. unsigned char cbit, disabled;
  806. cbit = inb(ICEREG1724(ice, SPDIF_CFG));
  807. disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN;
  808. if (cbit != disabled)
  809. outb(disabled, ICEREG1724(ice, SPDIF_CFG));
  810. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  811. if (cbit != disabled)
  812. outb(cbit, ICEREG1724(ice, SPDIF_CFG));
  813. outw(val, ICEMT1724(ice, SPDIF_CTRL));
  814. }
  815. /* update SPDIF control bits according to the given rate */
  816. static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate)
  817. {
  818. unsigned int val, nval;
  819. unsigned long flags;
  820. spin_lock_irqsave(&ice->reg_lock, flags);
  821. nval = val = inw(ICEMT1724(ice, SPDIF_CTRL));
  822. nval &= ~(7 << 12);
  823. switch (rate) {
  824. case 44100: break;
  825. case 48000: nval |= 2 << 12; break;
  826. case 32000: nval |= 3 << 12; break;
  827. case 88200: nval |= 4 << 12; break;
  828. case 96000: nval |= 5 << 12; break;
  829. case 192000: nval |= 6 << 12; break;
  830. case 176400: nval |= 7 << 12; break;
  831. }
  832. if (val != nval)
  833. update_spdif_bits(ice, nval);
  834. spin_unlock_irqrestore(&ice->reg_lock, flags);
  835. }
  836. static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream)
  837. {
  838. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  839. if (! ice->force_pdma4)
  840. update_spdif_rate(ice, substream->runtime->rate);
  841. return snd_vt1724_pcm_prepare(substream);
  842. }
  843. static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
  844. {
  845. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  846. struct snd_pcm_runtime *runtime = substream->runtime;
  847. runtime->private_data = &vt1724_playback_spdif_reg;
  848. ice->playback_con_substream = substream;
  849. if (ice->force_pdma4) {
  850. runtime->hw = snd_vt1724_2ch_stereo;
  851. set_rate_constraints(ice, substream);
  852. } else
  853. runtime->hw = snd_vt1724_spdif;
  854. snd_pcm_set_sync(substream);
  855. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  856. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  857. VT1724_BUFFER_ALIGN);
  858. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  859. VT1724_BUFFER_ALIGN);
  860. return 0;
  861. }
  862. static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
  863. {
  864. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  865. if (PRO_RATE_RESET)
  866. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  867. ice->playback_con_substream = NULL;
  868. return 0;
  869. }
  870. static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
  871. {
  872. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  873. struct snd_pcm_runtime *runtime = substream->runtime;
  874. runtime->private_data = &vt1724_capture_spdif_reg;
  875. ice->capture_con_substream = substream;
  876. if (ice->force_rdma1) {
  877. runtime->hw = snd_vt1724_2ch_stereo;
  878. set_rate_constraints(ice, substream);
  879. } else
  880. runtime->hw = snd_vt1724_spdif;
  881. snd_pcm_set_sync(substream);
  882. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  883. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  884. VT1724_BUFFER_ALIGN);
  885. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  886. VT1724_BUFFER_ALIGN);
  887. return 0;
  888. }
  889. static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
  890. {
  891. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  892. if (PRO_RATE_RESET)
  893. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  894. ice->capture_con_substream = NULL;
  895. return 0;
  896. }
  897. static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = {
  898. .open = snd_vt1724_playback_spdif_open,
  899. .close = snd_vt1724_playback_spdif_close,
  900. .ioctl = snd_pcm_lib_ioctl,
  901. .hw_params = snd_vt1724_pcm_hw_params,
  902. .hw_free = snd_vt1724_pcm_hw_free,
  903. .prepare = snd_vt1724_playback_spdif_prepare,
  904. .trigger = snd_vt1724_pcm_trigger,
  905. .pointer = snd_vt1724_pcm_pointer,
  906. };
  907. static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = {
  908. .open = snd_vt1724_capture_spdif_open,
  909. .close = snd_vt1724_capture_spdif_close,
  910. .ioctl = snd_pcm_lib_ioctl,
  911. .hw_params = snd_vt1724_pcm_hw_params,
  912. .hw_free = snd_vt1724_pcm_hw_free,
  913. .prepare = snd_vt1724_pcm_prepare,
  914. .trigger = snd_vt1724_pcm_trigger,
  915. .pointer = snd_vt1724_pcm_pointer,
  916. };
  917. static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 * ice, int device)
  918. {
  919. char *name;
  920. struct snd_pcm *pcm;
  921. int play, capt;
  922. int err;
  923. if (ice->force_pdma4 ||
  924. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) {
  925. play = 1;
  926. ice->has_spdif = 1;
  927. } else
  928. play = 0;
  929. if (ice->force_rdma1 ||
  930. (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) {
  931. capt = 1;
  932. ice->has_spdif = 1;
  933. } else
  934. capt = 0;
  935. if (! play && ! capt)
  936. return 0; /* no spdif device */
  937. if (ice->force_pdma4 || ice->force_rdma1)
  938. name = "ICE1724 Secondary";
  939. else
  940. name = "IEC1724 IEC958";
  941. err = snd_pcm_new(ice->card, name, device, play, capt, &pcm);
  942. if (err < 0)
  943. return err;
  944. if (play)
  945. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  946. &snd_vt1724_playback_spdif_ops);
  947. if (capt)
  948. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
  949. &snd_vt1724_capture_spdif_ops);
  950. pcm->private_data = ice;
  951. pcm->info_flags = 0;
  952. strcpy(pcm->name, name);
  953. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  954. snd_dma_pci_data(ice->pci),
  955. 64*1024, 64*1024);
  956. ice->pcm = pcm;
  957. return 0;
  958. }
  959. /*
  960. * independent surround PCMs
  961. */
  962. static struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = {
  963. {
  964. .addr = VT1724_MT_PDMA1_ADDR,
  965. .size = VT1724_MT_PDMA1_SIZE,
  966. .count = VT1724_MT_PDMA1_COUNT,
  967. .start = VT1724_PDMA1_START,
  968. },
  969. {
  970. .addr = VT1724_MT_PDMA2_ADDR,
  971. .size = VT1724_MT_PDMA2_SIZE,
  972. .count = VT1724_MT_PDMA2_COUNT,
  973. .start = VT1724_PDMA2_START,
  974. },
  975. {
  976. .addr = VT1724_MT_PDMA3_ADDR,
  977. .size = VT1724_MT_PDMA3_SIZE,
  978. .count = VT1724_MT_PDMA3_COUNT,
  979. .start = VT1724_PDMA3_START,
  980. },
  981. };
  982. static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream)
  983. {
  984. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  985. unsigned char val;
  986. spin_lock_irq(&ice->reg_lock);
  987. val = 3 - substream->number;
  988. if (inb(ICEMT1724(ice, BURST)) < val)
  989. outb(val, ICEMT1724(ice, BURST));
  990. spin_unlock_irq(&ice->reg_lock);
  991. return snd_vt1724_pcm_prepare(substream);
  992. }
  993. static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream)
  994. {
  995. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  996. struct snd_pcm_runtime *runtime = substream->runtime;
  997. mutex_lock(&ice->open_mutex);
  998. /* already used by PDMA0? */
  999. if (ice->pcm_reserved[substream->number]) {
  1000. mutex_unlock(&ice->open_mutex);
  1001. return -EBUSY; /* FIXME: should handle blocking mode properly */
  1002. }
  1003. mutex_unlock(&ice->open_mutex);
  1004. runtime->private_data = &vt1724_playback_dma_regs[substream->number];
  1005. ice->playback_con_substream_ds[substream->number] = substream;
  1006. runtime->hw = snd_vt1724_2ch_stereo;
  1007. snd_pcm_set_sync(substream);
  1008. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1009. set_rate_constraints(ice, substream);
  1010. return 0;
  1011. }
  1012. static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
  1013. {
  1014. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1015. if (PRO_RATE_RESET)
  1016. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1017. ice->playback_con_substream_ds[substream->number] = NULL;
  1018. ice->pcm_reserved[substream->number] = NULL;
  1019. return 0;
  1020. }
  1021. static struct snd_pcm_ops snd_vt1724_playback_indep_ops = {
  1022. .open = snd_vt1724_playback_indep_open,
  1023. .close = snd_vt1724_playback_indep_close,
  1024. .ioctl = snd_pcm_lib_ioctl,
  1025. .hw_params = snd_vt1724_pcm_hw_params,
  1026. .hw_free = snd_vt1724_pcm_hw_free,
  1027. .prepare = snd_vt1724_playback_indep_prepare,
  1028. .trigger = snd_vt1724_pcm_trigger,
  1029. .pointer = snd_vt1724_pcm_pointer,
  1030. };
  1031. static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 * ice, int device)
  1032. {
  1033. struct snd_pcm *pcm;
  1034. int play;
  1035. int err;
  1036. play = ice->num_total_dacs / 2 - 1;
  1037. if (play <= 0)
  1038. return 0;
  1039. err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm);
  1040. if (err < 0)
  1041. return err;
  1042. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  1043. &snd_vt1724_playback_indep_ops);
  1044. pcm->private_data = ice;
  1045. pcm->info_flags = 0;
  1046. strcpy(pcm->name, "ICE1724 Surround PCM");
  1047. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1048. snd_dma_pci_data(ice->pci),
  1049. 64*1024, 64*1024);
  1050. ice->pcm_ds = pcm;
  1051. return 0;
  1052. }
  1053. /*
  1054. * Mixer section
  1055. */
  1056. static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 * ice)
  1057. {
  1058. int err;
  1059. if (! (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) {
  1060. struct snd_ac97_bus *pbus;
  1061. struct snd_ac97_template ac97;
  1062. static struct snd_ac97_bus_ops ops = {
  1063. .write = snd_vt1724_ac97_write,
  1064. .read = snd_vt1724_ac97_read,
  1065. };
  1066. /* cold reset */
  1067. outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
  1068. mdelay(5); /* FIXME */
  1069. outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
  1070. if ((err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus)) < 0)
  1071. return err;
  1072. memset(&ac97, 0, sizeof(ac97));
  1073. ac97.private_data = ice;
  1074. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1075. printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
  1076. else
  1077. return 0;
  1078. }
  1079. /* I2S mixer only */
  1080. strcat(ice->card->mixername, "ICE1724 - multitrack");
  1081. return 0;
  1082. }
  1083. /*
  1084. *
  1085. */
  1086. static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx)
  1087. {
  1088. return (unsigned int)ice->eeprom.data[idx] | \
  1089. ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \
  1090. ((unsigned int)ice->eeprom.data[idx + 2] << 16);
  1091. }
  1092. static void snd_vt1724_proc_read(struct snd_info_entry *entry,
  1093. struct snd_info_buffer *buffer)
  1094. {
  1095. struct snd_ice1712 *ice = entry->private_data;
  1096. unsigned int idx;
  1097. snd_iprintf(buffer, "%s\n\n", ice->card->longname);
  1098. snd_iprintf(buffer, "EEPROM:\n");
  1099. snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
  1100. snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
  1101. snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
  1102. snd_iprintf(buffer, " System Config : 0x%x\n",
  1103. ice->eeprom.data[ICE_EEP2_SYSCONF]);
  1104. snd_iprintf(buffer, " ACLink : 0x%x\n",
  1105. ice->eeprom.data[ICE_EEP2_ACLINK]);
  1106. snd_iprintf(buffer, " I2S : 0x%x\n",
  1107. ice->eeprom.data[ICE_EEP2_I2S]);
  1108. snd_iprintf(buffer, " S/PDIF : 0x%x\n",
  1109. ice->eeprom.data[ICE_EEP2_SPDIF]);
  1110. snd_iprintf(buffer, " GPIO direction : 0x%x\n",
  1111. ice->eeprom.gpiodir);
  1112. snd_iprintf(buffer, " GPIO mask : 0x%x\n",
  1113. ice->eeprom.gpiomask);
  1114. snd_iprintf(buffer, " GPIO state : 0x%x\n",
  1115. ice->eeprom.gpiostate);
  1116. for (idx = 0x12; idx < ice->eeprom.size; idx++)
  1117. snd_iprintf(buffer, " Extra #%02i : 0x%x\n",
  1118. idx, ice->eeprom.data[idx]);
  1119. snd_iprintf(buffer, "\nRegisters:\n");
  1120. snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n",
  1121. (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK)));
  1122. for (idx = 0x0; idx < 0x20 ; idx++)
  1123. snd_iprintf(buffer, " CCS%02x : 0x%02x\n",
  1124. idx, inb(ice->port+idx));
  1125. for (idx = 0x0; idx < 0x30 ; idx++)
  1126. snd_iprintf(buffer, " MT%02x : 0x%02x\n",
  1127. idx, inb(ice->profi_port+idx));
  1128. }
  1129. static void __devinit snd_vt1724_proc_init(struct snd_ice1712 * ice)
  1130. {
  1131. struct snd_info_entry *entry;
  1132. if (! snd_card_proc_new(ice->card, "ice1724", &entry))
  1133. snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read);
  1134. }
  1135. /*
  1136. *
  1137. */
  1138. static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol,
  1139. struct snd_ctl_elem_info *uinfo)
  1140. {
  1141. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1142. uinfo->count = sizeof(struct snd_ice1712_eeprom);
  1143. return 0;
  1144. }
  1145. static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol,
  1146. struct snd_ctl_elem_value *ucontrol)
  1147. {
  1148. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1149. memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
  1150. return 0;
  1151. }
  1152. static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = {
  1153. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1154. .name = "ICE1724 EEPROM",
  1155. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1156. .info = snd_vt1724_eeprom_info,
  1157. .get = snd_vt1724_eeprom_get
  1158. };
  1159. /*
  1160. */
  1161. static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol,
  1162. struct snd_ctl_elem_info *uinfo)
  1163. {
  1164. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1165. uinfo->count = 1;
  1166. return 0;
  1167. }
  1168. static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga)
  1169. {
  1170. unsigned int val, rbits;
  1171. val = diga->status[0] & 0x03; /* professional, non-audio */
  1172. if (val & 0x01) {
  1173. /* professional */
  1174. if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) ==
  1175. IEC958_AES0_PRO_EMPHASIS_5015)
  1176. val |= 1U << 3;
  1177. rbits = (diga->status[4] >> 3) & 0x0f;
  1178. if (rbits) {
  1179. switch (rbits) {
  1180. case 2: val |= 5 << 12; break; /* 96k */
  1181. case 3: val |= 6 << 12; break; /* 192k */
  1182. case 10: val |= 4 << 12; break; /* 88.2k */
  1183. case 11: val |= 7 << 12; break; /* 176.4k */
  1184. }
  1185. } else {
  1186. switch (diga->status[0] & IEC958_AES0_PRO_FS) {
  1187. case IEC958_AES0_PRO_FS_44100:
  1188. break;
  1189. case IEC958_AES0_PRO_FS_32000:
  1190. val |= 3U << 12;
  1191. break;
  1192. default:
  1193. val |= 2U << 12;
  1194. break;
  1195. }
  1196. }
  1197. } else {
  1198. /* consumer */
  1199. val |= diga->status[1] & 0x04; /* copyright */
  1200. if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) ==
  1201. IEC958_AES0_CON_EMPHASIS_5015)
  1202. val |= 1U << 3;
  1203. val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */
  1204. val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */
  1205. }
  1206. return val;
  1207. }
  1208. static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val)
  1209. {
  1210. memset(diga->status, 0, sizeof(diga->status));
  1211. diga->status[0] = val & 0x03; /* professional, non-audio */
  1212. if (val & 0x01) {
  1213. /* professional */
  1214. if (val & (1U << 3))
  1215. diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015;
  1216. switch ((val >> 12) & 0x7) {
  1217. case 0:
  1218. break;
  1219. case 2:
  1220. diga->status[0] |= IEC958_AES0_PRO_FS_32000;
  1221. break;
  1222. default:
  1223. diga->status[0] |= IEC958_AES0_PRO_FS_48000;
  1224. break;
  1225. }
  1226. } else {
  1227. /* consumer */
  1228. diga->status[0] |= val & (1U << 2); /* copyright */
  1229. if (val & (1U << 3))
  1230. diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015;
  1231. diga->status[1] |= (val >> 4) & 0x3f; /* category */
  1232. diga->status[3] |= (val >> 12) & 0x07; /* fs */
  1233. }
  1234. }
  1235. static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol,
  1236. struct snd_ctl_elem_value *ucontrol)
  1237. {
  1238. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1239. unsigned int val;
  1240. val = inw(ICEMT1724(ice, SPDIF_CTRL));
  1241. decode_spdif_bits(&ucontrol->value.iec958, val);
  1242. return 0;
  1243. }
  1244. static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol,
  1245. struct snd_ctl_elem_value *ucontrol)
  1246. {
  1247. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1248. unsigned int val, old;
  1249. val = encode_spdif_bits(&ucontrol->value.iec958);
  1250. spin_lock_irq(&ice->reg_lock);
  1251. old = inw(ICEMT1724(ice, SPDIF_CTRL));
  1252. if (val != old)
  1253. update_spdif_bits(ice, val);
  1254. spin_unlock_irq(&ice->reg_lock);
  1255. return (val != old);
  1256. }
  1257. static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata =
  1258. {
  1259. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1260. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  1261. .info = snd_vt1724_spdif_info,
  1262. .get = snd_vt1724_spdif_default_get,
  1263. .put = snd_vt1724_spdif_default_put
  1264. };
  1265. static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol,
  1266. struct snd_ctl_elem_value *ucontrol)
  1267. {
  1268. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1269. IEC958_AES0_PROFESSIONAL |
  1270. IEC958_AES0_CON_NOT_COPYRIGHT |
  1271. IEC958_AES0_CON_EMPHASIS;
  1272. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
  1273. IEC958_AES1_CON_CATEGORY;
  1274. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  1275. return 0;
  1276. }
  1277. static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol,
  1278. struct snd_ctl_elem_value *ucontrol)
  1279. {
  1280. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1281. IEC958_AES0_PROFESSIONAL |
  1282. IEC958_AES0_PRO_FS |
  1283. IEC958_AES0_PRO_EMPHASIS;
  1284. return 0;
  1285. }
  1286. static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata =
  1287. {
  1288. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1289. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1290. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  1291. .info = snd_vt1724_spdif_info,
  1292. .get = snd_vt1724_spdif_maskc_get,
  1293. };
  1294. static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata =
  1295. {
  1296. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1297. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1298. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  1299. .info = snd_vt1724_spdif_info,
  1300. .get = snd_vt1724_spdif_maskp_get,
  1301. };
  1302. static int snd_vt1724_spdif_sw_info(struct snd_kcontrol *kcontrol,
  1303. struct snd_ctl_elem_info *uinfo)
  1304. {
  1305. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1306. uinfo->count = 1;
  1307. uinfo->value.integer.min = 0;
  1308. uinfo->value.integer.max = 1;
  1309. return 0;
  1310. }
  1311. static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol,
  1312. struct snd_ctl_elem_value *ucontrol)
  1313. {
  1314. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1315. ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) &
  1316. VT1724_CFG_SPDIF_OUT_EN ? 1 : 0;
  1317. return 0;
  1318. }
  1319. static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol,
  1320. struct snd_ctl_elem_value *ucontrol)
  1321. {
  1322. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1323. unsigned char old, val;
  1324. spin_lock_irq(&ice->reg_lock);
  1325. old = val = inb(ICEREG1724(ice, SPDIF_CFG));
  1326. val &= ~VT1724_CFG_SPDIF_OUT_EN;
  1327. if (ucontrol->value.integer.value[0])
  1328. val |= VT1724_CFG_SPDIF_OUT_EN;
  1329. if (old != val)
  1330. outb(val, ICEREG1724(ice, SPDIF_CFG));
  1331. spin_unlock_irq(&ice->reg_lock);
  1332. return old != val;
  1333. }
  1334. static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata =
  1335. {
  1336. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1337. /* FIXME: the following conflict with IEC958 Playback Route */
  1338. // .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH),
  1339. .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
  1340. .info = snd_vt1724_spdif_sw_info,
  1341. .get = snd_vt1724_spdif_sw_get,
  1342. .put = snd_vt1724_spdif_sw_put
  1343. };
  1344. #if 0 /* NOT USED YET */
  1345. /*
  1346. * GPIO access from extern
  1347. */
  1348. int snd_vt1724_gpio_info(struct snd_kcontrol *kcontrol,
  1349. struct snd_ctl_elem_info *uinfo)
  1350. {
  1351. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1352. uinfo->count = 1;
  1353. uinfo->value.integer.min = 0;
  1354. uinfo->value.integer.max = 1;
  1355. return 0;
  1356. }
  1357. int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol,
  1358. struct snd_ctl_elem_value *ucontrol)
  1359. {
  1360. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1361. int shift = kcontrol->private_value & 0xff;
  1362. int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
  1363. snd_ice1712_save_gpio_status(ice);
  1364. ucontrol->value.integer.value[0] =
  1365. (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert;
  1366. snd_ice1712_restore_gpio_status(ice);
  1367. return 0;
  1368. }
  1369. int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
  1370. struct snd_ctl_elem_value *ucontrol)
  1371. {
  1372. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1373. int shift = kcontrol->private_value & 0xff;
  1374. int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
  1375. unsigned int val, nval;
  1376. if (kcontrol->private_value & (1 << 31))
  1377. return -EPERM;
  1378. nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert;
  1379. snd_ice1712_save_gpio_status(ice);
  1380. val = snd_ice1712_gpio_read(ice);
  1381. nval |= val & ~(1 << shift);
  1382. if (val != nval)
  1383. snd_ice1712_gpio_write(ice, nval);
  1384. snd_ice1712_restore_gpio_status(ice);
  1385. return val != nval;
  1386. }
  1387. #endif /* NOT USED YET */
  1388. /*
  1389. * rate
  1390. */
  1391. static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
  1392. struct snd_ctl_elem_info *uinfo)
  1393. {
  1394. static char *texts_1724[] = {
  1395. "8000", /* 0: 6 */
  1396. "9600", /* 1: 3 */
  1397. "11025", /* 2: 10 */
  1398. "12000", /* 3: 2 */
  1399. "16000", /* 4: 5 */
  1400. "22050", /* 5: 9 */
  1401. "24000", /* 6: 1 */
  1402. "32000", /* 7: 4 */
  1403. "44100", /* 8: 8 */
  1404. "48000", /* 9: 0 */
  1405. "64000", /* 10: 15 */
  1406. "88200", /* 11: 11 */
  1407. "96000", /* 12: 7 */
  1408. "176400", /* 13: 12 */
  1409. "192000", /* 14: 14 */
  1410. "IEC958 Input", /* 15: -- */
  1411. };
  1412. static char *texts_1720[] = {
  1413. "8000", /* 0: 6 */
  1414. "9600", /* 1: 3 */
  1415. "11025", /* 2: 10 */
  1416. "12000", /* 3: 2 */
  1417. "16000", /* 4: 5 */
  1418. "22050", /* 5: 9 */
  1419. "24000", /* 6: 1 */
  1420. "32000", /* 7: 4 */
  1421. "44100", /* 8: 8 */
  1422. "48000", /* 9: 0 */
  1423. "64000", /* 10: 15 */
  1424. "88200", /* 11: 11 */
  1425. "96000", /* 12: 7 */
  1426. "IEC958 Input", /* 13: -- */
  1427. };
  1428. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1429. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1430. uinfo->count = 1;
  1431. uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16;
  1432. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1433. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1434. strcpy(uinfo->value.enumerated.name,
  1435. ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] :
  1436. texts_1724[uinfo->value.enumerated.item]);
  1437. return 0;
  1438. }
  1439. static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
  1440. struct snd_ctl_elem_value *ucontrol)
  1441. {
  1442. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1443. static unsigned char xlate[16] = {
  1444. 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
  1445. };
  1446. unsigned char val;
  1447. spin_lock_irq(&ice->reg_lock);
  1448. if (is_spdif_master(ice)) {
  1449. ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15;
  1450. } else {
  1451. val = xlate[inb(ICEMT1724(ice, RATE)) & 15];
  1452. if (val == 255) {
  1453. snd_BUG();
  1454. val = 0;
  1455. }
  1456. ucontrol->value.enumerated.item[0] = val;
  1457. }
  1458. spin_unlock_irq(&ice->reg_lock);
  1459. return 0;
  1460. }
  1461. static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
  1462. struct snd_ctl_elem_value *ucontrol)
  1463. {
  1464. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1465. unsigned char oval;
  1466. int rate;
  1467. int change = 0;
  1468. int spdif = ice->vt1720 ? 13 : 15;
  1469. spin_lock_irq(&ice->reg_lock);
  1470. oval = inb(ICEMT1724(ice, RATE));
  1471. if (ucontrol->value.enumerated.item[0] == spdif) {
  1472. outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
  1473. } else {
  1474. rate = rates[ucontrol->value.integer.value[0] % 15];
  1475. if (rate <= get_max_rate(ice)) {
  1476. PRO_RATE_DEFAULT = rate;
  1477. spin_unlock_irq(&ice->reg_lock);
  1478. snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
  1479. spin_lock_irq(&ice->reg_lock);
  1480. }
  1481. }
  1482. change = inb(ICEMT1724(ice, RATE)) != oval;
  1483. spin_unlock_irq(&ice->reg_lock);
  1484. if ((oval & VT1724_SPDIF_MASTER) !=
  1485. (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) {
  1486. /* notify akm chips as well */
  1487. if (is_spdif_master(ice)) {
  1488. unsigned int i;
  1489. for (i = 0; i < ice->akm_codecs; i++) {
  1490. if (ice->akm[i].ops.set_rate_val)
  1491. ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
  1492. }
  1493. }
  1494. }
  1495. return change;
  1496. }
  1497. static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
  1498. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1499. .name = "Multi Track Internal Clock",
  1500. .info = snd_vt1724_pro_internal_clock_info,
  1501. .get = snd_vt1724_pro_internal_clock_get,
  1502. .put = snd_vt1724_pro_internal_clock_put
  1503. };
  1504. static int snd_vt1724_pro_rate_locking_info(struct snd_kcontrol *kcontrol,
  1505. struct snd_ctl_elem_info *uinfo)
  1506. {
  1507. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1508. uinfo->count = 1;
  1509. uinfo->value.integer.min = 0;
  1510. uinfo->value.integer.max = 1;
  1511. return 0;
  1512. }
  1513. static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
  1514. struct snd_ctl_elem_value *ucontrol)
  1515. {
  1516. ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
  1517. return 0;
  1518. }
  1519. static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
  1520. struct snd_ctl_elem_value *ucontrol)
  1521. {
  1522. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1523. int change = 0, nval;
  1524. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1525. spin_lock_irq(&ice->reg_lock);
  1526. change = PRO_RATE_LOCKED != nval;
  1527. PRO_RATE_LOCKED = nval;
  1528. spin_unlock_irq(&ice->reg_lock);
  1529. return change;
  1530. }
  1531. static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = {
  1532. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1533. .name = "Multi Track Rate Locking",
  1534. .info = snd_vt1724_pro_rate_locking_info,
  1535. .get = snd_vt1724_pro_rate_locking_get,
  1536. .put = snd_vt1724_pro_rate_locking_put
  1537. };
  1538. static int snd_vt1724_pro_rate_reset_info(struct snd_kcontrol *kcontrol,
  1539. struct snd_ctl_elem_info *uinfo)
  1540. {
  1541. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1542. uinfo->count = 1;
  1543. uinfo->value.integer.min = 0;
  1544. uinfo->value.integer.max = 1;
  1545. return 0;
  1546. }
  1547. static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
  1548. struct snd_ctl_elem_value *ucontrol)
  1549. {
  1550. ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0;
  1551. return 0;
  1552. }
  1553. static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
  1554. struct snd_ctl_elem_value *ucontrol)
  1555. {
  1556. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1557. int change = 0, nval;
  1558. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1559. spin_lock_irq(&ice->reg_lock);
  1560. change = PRO_RATE_RESET != nval;
  1561. PRO_RATE_RESET = nval;
  1562. spin_unlock_irq(&ice->reg_lock);
  1563. return change;
  1564. }
  1565. static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = {
  1566. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1567. .name = "Multi Track Rate Reset",
  1568. .info = snd_vt1724_pro_rate_reset_info,
  1569. .get = snd_vt1724_pro_rate_reset_get,
  1570. .put = snd_vt1724_pro_rate_reset_put
  1571. };
  1572. /*
  1573. * routing
  1574. */
  1575. static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
  1576. struct snd_ctl_elem_info *uinfo)
  1577. {
  1578. static char *texts[] = {
  1579. "PCM Out", /* 0 */
  1580. "H/W In 0", "H/W In 1", /* 1-2 */
  1581. "IEC958 In L", "IEC958 In R", /* 3-4 */
  1582. };
  1583. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1584. uinfo->count = 1;
  1585. uinfo->value.enumerated.items = 5;
  1586. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1587. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1588. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1589. return 0;
  1590. }
  1591. static inline int analog_route_shift(int idx)
  1592. {
  1593. return (idx % 2) * 12 + ((idx / 2) * 3) + 8;
  1594. }
  1595. static inline int digital_route_shift(int idx)
  1596. {
  1597. return idx * 3;
  1598. }
  1599. static int get_route_val(struct snd_ice1712 *ice, int shift)
  1600. {
  1601. unsigned long val;
  1602. unsigned char eitem;
  1603. static unsigned char xlate[8] = {
  1604. 0, 255, 1, 2, 255, 255, 3, 4,
  1605. };
  1606. val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1607. val >>= shift;
  1608. val &= 7; //we now have 3 bits per output
  1609. eitem = xlate[val];
  1610. if (eitem == 255) {
  1611. snd_BUG();
  1612. return 0;
  1613. }
  1614. return eitem;
  1615. }
  1616. static int put_route_val(struct snd_ice1712 *ice, unsigned int val, int shift)
  1617. {
  1618. unsigned int old_val, nval;
  1619. int change;
  1620. static unsigned char xroute[8] = {
  1621. 0, /* PCM */
  1622. 2, /* PSDIN0 Left */
  1623. 3, /* PSDIN0 Right */
  1624. 6, /* SPDIN Left */
  1625. 7, /* SPDIN Right */
  1626. };
  1627. nval = xroute[val % 5];
  1628. val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK));
  1629. val &= ~(0x07 << shift);
  1630. val |= nval << shift;
  1631. change = val != old_val;
  1632. if (change)
  1633. outl(val, ICEMT1724(ice, ROUTE_PLAYBACK));
  1634. return change;
  1635. }
  1636. static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol,
  1637. struct snd_ctl_elem_value *ucontrol)
  1638. {
  1639. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1640. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1641. ucontrol->value.enumerated.item[0] =
  1642. get_route_val(ice, analog_route_shift(idx));
  1643. return 0;
  1644. }
  1645. static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol,
  1646. struct snd_ctl_elem_value *ucontrol)
  1647. {
  1648. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1649. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1650. return put_route_val(ice, ucontrol->value.enumerated.item[0],
  1651. analog_route_shift(idx));
  1652. }
  1653. static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
  1654. struct snd_ctl_elem_value *ucontrol)
  1655. {
  1656. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1657. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1658. ucontrol->value.enumerated.item[0] =
  1659. get_route_val(ice, digital_route_shift(idx));
  1660. return 0;
  1661. }
  1662. static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
  1663. struct snd_ctl_elem_value *ucontrol)
  1664. {
  1665. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1666. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1667. return put_route_val(ice, ucontrol->value.enumerated.item[0],
  1668. digital_route_shift(idx));
  1669. }
  1670. static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = {
  1671. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1672. .name = "H/W Playback Route",
  1673. .info = snd_vt1724_pro_route_info,
  1674. .get = snd_vt1724_pro_route_analog_get,
  1675. .put = snd_vt1724_pro_route_analog_put,
  1676. };
  1677. static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = {
  1678. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1679. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  1680. .info = snd_vt1724_pro_route_info,
  1681. .get = snd_vt1724_pro_route_spdif_get,
  1682. .put = snd_vt1724_pro_route_spdif_put,
  1683. .count = 2,
  1684. };
  1685. static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol,
  1686. struct snd_ctl_elem_info *uinfo)
  1687. {
  1688. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1689. uinfo->count = 22; /* FIXME: for compatibility with ice1712... */
  1690. uinfo->value.integer.min = 0;
  1691. uinfo->value.integer.max = 255;
  1692. return 0;
  1693. }
  1694. static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
  1695. struct snd_ctl_elem_value *ucontrol)
  1696. {
  1697. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1698. int idx;
  1699. spin_lock_irq(&ice->reg_lock);
  1700. for (idx = 0; idx < 22; idx++) {
  1701. outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX));
  1702. ucontrol->value.integer.value[idx] =
  1703. inb(ICEMT1724(ice, MONITOR_PEAKDATA));
  1704. }
  1705. spin_unlock_irq(&ice->reg_lock);
  1706. return 0;
  1707. }
  1708. static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
  1709. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1710. .name = "Multi Track Peak",
  1711. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1712. .info = snd_vt1724_pro_peak_info,
  1713. .get = snd_vt1724_pro_peak_get
  1714. };
  1715. /*
  1716. *
  1717. */
  1718. static struct snd_ice1712_card_info no_matched __devinitdata;
  1719. static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
  1720. snd_vt1724_revo_cards,
  1721. snd_vt1724_amp_cards,
  1722. snd_vt1724_aureon_cards,
  1723. snd_vt1720_mobo_cards,
  1724. snd_vt1720_pontis_cards,
  1725. snd_vt1724_prodigy192_cards,
  1726. snd_vt1724_juli_cards,
  1727. snd_vt1724_phase_cards,
  1728. NULL,
  1729. };
  1730. /*
  1731. */
  1732. static void wait_i2c_busy(struct snd_ice1712 *ice)
  1733. {
  1734. int t = 0x10000;
  1735. while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
  1736. ;
  1737. if (t == -1)
  1738. printk(KERN_ERR "ice1724: i2c busy timeout\n");
  1739. }
  1740. unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
  1741. unsigned char dev, unsigned char addr)
  1742. {
  1743. unsigned char val;
  1744. mutex_lock(&ice->i2c_mutex);
  1745. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  1746. outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  1747. wait_i2c_busy(ice);
  1748. val = inb(ICEREG1724(ice, I2C_DATA));
  1749. mutex_unlock(&ice->i2c_mutex);
  1750. //printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
  1751. return val;
  1752. }
  1753. void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
  1754. unsigned char dev, unsigned char addr, unsigned char data)
  1755. {
  1756. mutex_lock(&ice->i2c_mutex);
  1757. wait_i2c_busy(ice);
  1758. //printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
  1759. outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
  1760. outb(data, ICEREG1724(ice, I2C_DATA));
  1761. outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
  1762. wait_i2c_busy(ice);
  1763. mutex_unlock(&ice->i2c_mutex);
  1764. }
  1765. static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
  1766. const char *modelname)
  1767. {
  1768. const int dev = 0xa0; /* EEPROM device address */
  1769. unsigned int i, size;
  1770. struct snd_ice1712_card_info **tbl, *c;
  1771. if (! modelname || ! *modelname) {
  1772. ice->eeprom.subvendor = 0;
  1773. if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
  1774. ice->eeprom.subvendor =
  1775. (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
  1776. (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
  1777. (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
  1778. (snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
  1779. if (ice->eeprom.subvendor == 0 ||
  1780. ice->eeprom.subvendor == (unsigned int)-1) {
  1781. /* invalid subvendor from EEPROM, try the PCI
  1782. * subststem ID instead
  1783. */
  1784. u16 vendor, device;
  1785. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID,
  1786. &vendor);
  1787. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
  1788. ice->eeprom.subvendor =
  1789. ((unsigned int)swab16(vendor) << 16) | swab16(device);
  1790. if (ice->eeprom.subvendor == 0 ||
  1791. ice->eeprom.subvendor == (unsigned int)-1) {
  1792. printk(KERN_ERR "ice1724: No valid ID is found\n");
  1793. return -ENXIO;
  1794. }
  1795. }
  1796. }
  1797. for (tbl = card_tables; *tbl; tbl++) {
  1798. for (c = *tbl; c->subvendor; c++) {
  1799. if (modelname && c->model &&
  1800. ! strcmp(modelname, c->model)) {
  1801. printk(KERN_INFO "ice1724: Using board model %s\n",
  1802. c->name);
  1803. ice->eeprom.subvendor = c->subvendor;
  1804. } else if (c->subvendor != ice->eeprom.subvendor)
  1805. continue;
  1806. if (! c->eeprom_size || ! c->eeprom_data)
  1807. goto found;
  1808. /* if the EEPROM is given by the driver, use it */
  1809. snd_printdd("using the defined eeprom..\n");
  1810. ice->eeprom.version = 2;
  1811. ice->eeprom.size = c->eeprom_size + 6;
  1812. memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
  1813. goto read_skipped;
  1814. }
  1815. }
  1816. printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n",
  1817. ice->eeprom.subvendor);
  1818. found:
  1819. ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04);
  1820. if (ice->eeprom.size < 6)
  1821. ice->eeprom.size = 32;
  1822. else if (ice->eeprom.size > 32) {
  1823. printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n",
  1824. ice->eeprom.size);
  1825. return -EIO;
  1826. }
  1827. ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
  1828. if (ice->eeprom.version != 2)
  1829. printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n",
  1830. ice->eeprom.version);
  1831. size = ice->eeprom.size - 6;
  1832. for (i = 0; i < size; i++)
  1833. ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6);
  1834. read_skipped:
  1835. ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK);
  1836. ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE);
  1837. ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR);
  1838. return 0;
  1839. }
  1840. static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
  1841. {
  1842. outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
  1843. udelay(200);
  1844. outb(0, ICEREG1724(ice, CONTROL));
  1845. udelay(200);
  1846. outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
  1847. outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
  1848. outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
  1849. outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG));
  1850. ice->gpio.write_mask = ice->eeprom.gpiomask;
  1851. ice->gpio.direction = ice->eeprom.gpiodir;
  1852. snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask);
  1853. snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir);
  1854. snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate);
  1855. outb(0, ICEREG1724(ice, POWERDOWN));
  1856. return 0;
  1857. }
  1858. static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
  1859. {
  1860. int err;
  1861. struct snd_kcontrol *kctl;
  1862. snd_assert(ice->pcm != NULL, return -EIO);
  1863. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice));
  1864. if (err < 0)
  1865. return err;
  1866. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice));
  1867. if (err < 0)
  1868. return err;
  1869. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice));
  1870. if (err < 0)
  1871. return err;
  1872. kctl->id.device = ice->pcm->device;
  1873. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice));
  1874. if (err < 0)
  1875. return err;
  1876. kctl->id.device = ice->pcm->device;
  1877. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice));
  1878. if (err < 0)
  1879. return err;
  1880. kctl->id.device = ice->pcm->device;
  1881. #if 0 /* use default only */
  1882. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice));
  1883. if (err < 0)
  1884. return err;
  1885. kctl->id.device = ice->pcm->device;
  1886. ice->spdif.stream_ctl = kctl;
  1887. #endif
  1888. return 0;
  1889. }
  1890. static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice)
  1891. {
  1892. int err;
  1893. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice));
  1894. if (err < 0)
  1895. return err;
  1896. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice));
  1897. if (err < 0)
  1898. return err;
  1899. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice));
  1900. if (err < 0)
  1901. return err;
  1902. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice));
  1903. if (err < 0)
  1904. return err;
  1905. if (ice->num_total_dacs > 0) {
  1906. struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route;
  1907. tmp.count = ice->num_total_dacs;
  1908. if (ice->vt1720 && tmp.count > 2)
  1909. tmp.count = 2;
  1910. err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
  1911. if (err < 0)
  1912. return err;
  1913. }
  1914. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice));
  1915. if (err < 0)
  1916. return err;
  1917. return 0;
  1918. }
  1919. static int snd_vt1724_free(struct snd_ice1712 *ice)
  1920. {
  1921. if (! ice->port)
  1922. goto __hw_end;
  1923. /* mask all interrupts */
  1924. outb(0xff, ICEMT1724(ice, DMA_INT_MASK));
  1925. outb(0xff, ICEREG1724(ice, IRQMASK));
  1926. /* --- */
  1927. __hw_end:
  1928. if (ice->irq >= 0) {
  1929. synchronize_irq(ice->irq);
  1930. free_irq(ice->irq, ice);
  1931. }
  1932. pci_release_regions(ice->pci);
  1933. snd_ice1712_akm4xxx_free(ice);
  1934. pci_disable_device(ice->pci);
  1935. kfree(ice);
  1936. return 0;
  1937. }
  1938. static int snd_vt1724_dev_free(struct snd_device *device)
  1939. {
  1940. struct snd_ice1712 *ice = device->device_data;
  1941. return snd_vt1724_free(ice);
  1942. }
  1943. static int __devinit snd_vt1724_create(struct snd_card *card,
  1944. struct pci_dev *pci,
  1945. const char *modelname,
  1946. struct snd_ice1712 ** r_ice1712)
  1947. {
  1948. struct snd_ice1712 *ice;
  1949. int err;
  1950. unsigned char mask;
  1951. static struct snd_device_ops ops = {
  1952. .dev_free = snd_vt1724_dev_free,
  1953. };
  1954. *r_ice1712 = NULL;
  1955. /* enable PCI device */
  1956. if ((err = pci_enable_device(pci)) < 0)
  1957. return err;
  1958. ice = kzalloc(sizeof(*ice), GFP_KERNEL);
  1959. if (ice == NULL) {
  1960. pci_disable_device(pci);
  1961. return -ENOMEM;
  1962. }
  1963. ice->vt1724 = 1;
  1964. spin_lock_init(&ice->reg_lock);
  1965. mutex_init(&ice->gpio_mutex);
  1966. mutex_init(&ice->open_mutex);
  1967. mutex_init(&ice->i2c_mutex);
  1968. ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
  1969. ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
  1970. ice->gpio.set_data = snd_vt1724_set_gpio_data;
  1971. ice->gpio.get_data = snd_vt1724_get_gpio_data;
  1972. ice->card = card;
  1973. ice->pci = pci;
  1974. ice->irq = -1;
  1975. pci_set_master(pci);
  1976. snd_vt1724_proc_init(ice);
  1977. synchronize_irq(pci->irq);
  1978. if ((err = pci_request_regions(pci, "ICE1724")) < 0) {
  1979. kfree(ice);
  1980. pci_disable_device(pci);
  1981. return err;
  1982. }
  1983. ice->port = pci_resource_start(pci, 0);
  1984. ice->profi_port = pci_resource_start(pci, 1);
  1985. if (request_irq(pci->irq, snd_vt1724_interrupt,
  1986. IRQF_DISABLED|IRQF_SHARED, "ICE1724", ice)) {
  1987. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  1988. snd_vt1724_free(ice);
  1989. return -EIO;
  1990. }
  1991. ice->irq = pci->irq;
  1992. if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
  1993. snd_vt1724_free(ice);
  1994. return -EIO;
  1995. }
  1996. if (snd_vt1724_chip_init(ice) < 0) {
  1997. snd_vt1724_free(ice);
  1998. return -EIO;
  1999. }
  2000. /* unmask used interrupts */
  2001. if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401))
  2002. mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
  2003. else
  2004. mask = 0;
  2005. outb(mask, ICEREG1724(ice, IRQMASK));
  2006. /* don't handle FIFO overrun/underruns (just yet),
  2007. * since they cause machine lockups
  2008. */
  2009. outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK));
  2010. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
  2011. snd_vt1724_free(ice);
  2012. return err;
  2013. }
  2014. snd_card_set_dev(card, &pci->dev);
  2015. *r_ice1712 = ice;
  2016. return 0;
  2017. }
  2018. /*
  2019. *
  2020. * Registration
  2021. *
  2022. */
  2023. static int __devinit snd_vt1724_probe(struct pci_dev *pci,
  2024. const struct pci_device_id *pci_id)
  2025. {
  2026. static int dev;
  2027. struct snd_card *card;
  2028. struct snd_ice1712 *ice;
  2029. int pcm_dev = 0, err;
  2030. struct snd_ice1712_card_info **tbl, *c;
  2031. if (dev >= SNDRV_CARDS)
  2032. return -ENODEV;
  2033. if (!enable[dev]) {
  2034. dev++;
  2035. return -ENOENT;
  2036. }
  2037. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  2038. if (card == NULL)
  2039. return -ENOMEM;
  2040. strcpy(card->driver, "ICE1724");
  2041. strcpy(card->shortname, "ICEnsemble ICE1724");
  2042. if ((err = snd_vt1724_create(card, pci, model[dev], &ice)) < 0) {
  2043. snd_card_free(card);
  2044. return err;
  2045. }
  2046. for (tbl = card_tables; *tbl; tbl++) {
  2047. for (c = *tbl; c->subvendor; c++) {
  2048. if (c->subvendor == ice->eeprom.subvendor) {
  2049. strcpy(card->shortname, c->name);
  2050. if (c->driver) /* specific driver? */
  2051. strcpy(card->driver, c->driver);
  2052. if (c->chip_init) {
  2053. if ((err = c->chip_init(ice)) < 0) {
  2054. snd_card_free(card);
  2055. return err;
  2056. }
  2057. }
  2058. goto __found;
  2059. }
  2060. }
  2061. }
  2062. c = &no_matched;
  2063. __found:
  2064. if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
  2065. snd_card_free(card);
  2066. return err;
  2067. }
  2068. if ((err = snd_vt1724_pcm_spdif(ice, pcm_dev++)) < 0) {
  2069. snd_card_free(card);
  2070. return err;
  2071. }
  2072. if ((err = snd_vt1724_pcm_indep(ice, pcm_dev++)) < 0) {
  2073. snd_card_free(card);
  2074. return err;
  2075. }
  2076. if ((err = snd_vt1724_ac97_mixer(ice)) < 0) {
  2077. snd_card_free(card);
  2078. return err;
  2079. }
  2080. if ((err = snd_vt1724_build_controls(ice)) < 0) {
  2081. snd_card_free(card);
  2082. return err;
  2083. }
  2084. if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */
  2085. if ((err = snd_vt1724_spdif_build_controls(ice)) < 0) {
  2086. snd_card_free(card);
  2087. return err;
  2088. }
  2089. }
  2090. if (c->build_controls) {
  2091. if ((err = c->build_controls(ice)) < 0) {
  2092. snd_card_free(card);
  2093. return err;
  2094. }
  2095. }
  2096. if (! c->no_mpu401) {
  2097. if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
  2098. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
  2099. ICEREG1724(ice, MPU_CTRL),
  2100. MPU401_INFO_INTEGRATED,
  2101. ice->irq, 0,
  2102. &ice->rmidi[0])) < 0) {
  2103. snd_card_free(card);
  2104. return err;
  2105. }
  2106. }
  2107. }
  2108. sprintf(card->longname, "%s at 0x%lx, irq %i",
  2109. card->shortname, ice->port, ice->irq);
  2110. if ((err = snd_card_register(card)) < 0) {
  2111. snd_card_free(card);
  2112. return err;
  2113. }
  2114. pci_set_drvdata(pci, card);
  2115. dev++;
  2116. return 0;
  2117. }
  2118. static void __devexit snd_vt1724_remove(struct pci_dev *pci)
  2119. {
  2120. snd_card_free(pci_get_drvdata(pci));
  2121. pci_set_drvdata(pci, NULL);
  2122. }
  2123. static struct pci_driver driver = {
  2124. .name = "ICE1724",
  2125. .id_table = snd_vt1724_ids,
  2126. .probe = snd_vt1724_probe,
  2127. .remove = __devexit_p(snd_vt1724_remove),
  2128. };
  2129. static int __init alsa_card_ice1724_init(void)
  2130. {
  2131. return pci_register_driver(&driver);
  2132. }
  2133. static void __exit alsa_card_ice1724_exit(void)
  2134. {
  2135. pci_unregister_driver(&driver);
  2136. }
  2137. module_init(alsa_card_ice1724_init)
  2138. module_exit(alsa_card_ice1724_exit)