ice1724.c 77 KB

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