ice1724.c 73 KB

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