ice1724.c 72 KB

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