ice1712.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778
  1. /*
  2. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  3. *
  4. * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. /*
  22. NOTES:
  23. - spdif nonaudio consumer mode does not work (at least with my
  24. Sony STR-DB830)
  25. */
  26. /*
  27. * Changes:
  28. *
  29. * 2002.09.09 Takashi Iwai <tiwai@suse.de>
  30. * split the code to several files. each low-level routine
  31. * is stored in the local file and called from registration
  32. * function from card_info struct.
  33. *
  34. * 2002.11.26 James Stafford <jstafford@ampltd.com>
  35. * Added support for VT1724 (Envy24HT)
  36. * I have left out support for 176.4 and 192 KHz for the moment.
  37. * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401
  38. *
  39. * 2003.02.20 Taksahi Iwai <tiwai@suse.de>
  40. * Split vt1724 part to an independent driver.
  41. * The GPIO is accessed through the callback functions now.
  42. *
  43. * 2004.03.31 Doug McLain <nostar@comcast.net>
  44. * Added support for Event Electronics EZ8 card to hoontech.c.
  45. */
  46. #include <asm/io.h>
  47. #include <linux/delay.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/init.h>
  50. #include <linux/pci.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/slab.h>
  53. #include <linux/moduleparam.h>
  54. #include <linux/mutex.h>
  55. #include <sound/core.h>
  56. #include <sound/cs8427.h>
  57. #include <sound/info.h>
  58. #include <sound/initval.h>
  59. #include <sound/tlv.h>
  60. #include <sound/asoundef.h>
  61. #include "ice1712.h"
  62. /* lowlevel routines */
  63. #include "delta.h"
  64. #include "ews.h"
  65. #include "hoontech.h"
  66. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  67. MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)");
  68. MODULE_LICENSE("GPL");
  69. MODULE_SUPPORTED_DEVICE("{"
  70. HOONTECH_DEVICE_DESC
  71. DELTA_DEVICE_DESC
  72. EWS_DEVICE_DESC
  73. "{ICEnsemble,Generic ICE1712},"
  74. "{ICEnsemble,Generic Envy24}}");
  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. static int omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */
  80. static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transciever reset timeout value in msec */
  81. static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */
  82. module_param_array(index, int, NULL, 0444);
  83. MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard.");
  84. module_param_array(id, charp, NULL, 0444);
  85. MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard.");
  86. module_param_array(enable, bool, NULL, 0444);
  87. MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard.");
  88. module_param_array(omni, bool, NULL, 0444);
  89. MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support.");
  90. module_param_array(cs8427_timeout, int, NULL, 0444);
  91. MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution.");
  92. module_param_array(model, charp, NULL, 0444);
  93. MODULE_PARM_DESC(model, "Use the given board model.");
  94. module_param_array(dxr_enable, int, NULL, 0444);
  95. MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE.");
  96. static const struct pci_device_id snd_ice1712_ids[] = {
  97. { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_ICE_1712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* ICE1712 */
  98. { 0, }
  99. };
  100. MODULE_DEVICE_TABLE(pci, snd_ice1712_ids);
  101. static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice);
  102. static int snd_ice1712_build_controls(struct snd_ice1712 *ice);
  103. static int PRO_RATE_LOCKED;
  104. static int PRO_RATE_RESET = 1;
  105. static unsigned int PRO_RATE_DEFAULT = 44100;
  106. /*
  107. * Basic I/O
  108. */
  109. /* check whether the clock mode is spdif-in */
  110. static inline int is_spdif_master(struct snd_ice1712 *ice)
  111. {
  112. return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0;
  113. }
  114. static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
  115. {
  116. return is_spdif_master(ice) || PRO_RATE_LOCKED;
  117. }
  118. static inline void snd_ice1712_ds_write(struct snd_ice1712 * ice, u8 channel, u8 addr, u32 data)
  119. {
  120. outb((channel << 4) | addr, ICEDS(ice, INDEX));
  121. outl(data, ICEDS(ice, DATA));
  122. }
  123. static inline u32 snd_ice1712_ds_read(struct snd_ice1712 * ice, u8 channel, u8 addr)
  124. {
  125. outb((channel << 4) | addr, ICEDS(ice, INDEX));
  126. return inl(ICEDS(ice, DATA));
  127. }
  128. static void snd_ice1712_ac97_write(struct snd_ac97 *ac97,
  129. unsigned short reg,
  130. unsigned short val)
  131. {
  132. struct snd_ice1712 *ice = ac97->private_data;
  133. int tm;
  134. unsigned char old_cmd = 0;
  135. for (tm = 0; tm < 0x10000; tm++) {
  136. old_cmd = inb(ICEREG(ice, AC97_CMD));
  137. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  138. continue;
  139. if (!(old_cmd & ICE1712_AC97_READY))
  140. continue;
  141. break;
  142. }
  143. outb(reg, ICEREG(ice, AC97_INDEX));
  144. outw(val, ICEREG(ice, AC97_DATA));
  145. old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
  146. outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD));
  147. for (tm = 0; tm < 0x10000; tm++)
  148. if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
  149. break;
  150. }
  151. static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97,
  152. unsigned short reg)
  153. {
  154. struct snd_ice1712 *ice = ac97->private_data;
  155. int tm;
  156. unsigned char old_cmd = 0;
  157. for (tm = 0; tm < 0x10000; tm++) {
  158. old_cmd = inb(ICEREG(ice, AC97_CMD));
  159. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  160. continue;
  161. if (!(old_cmd & ICE1712_AC97_READY))
  162. continue;
  163. break;
  164. }
  165. outb(reg, ICEREG(ice, AC97_INDEX));
  166. outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD));
  167. for (tm = 0; tm < 0x10000; tm++)
  168. if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
  169. break;
  170. if (tm >= 0x10000) /* timeout */
  171. return ~0;
  172. return inw(ICEREG(ice, AC97_DATA));
  173. }
  174. /*
  175. * pro ac97 section
  176. */
  177. static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97,
  178. unsigned short reg,
  179. unsigned short val)
  180. {
  181. struct snd_ice1712 *ice = ac97->private_data;
  182. int tm;
  183. unsigned char old_cmd = 0;
  184. for (tm = 0; tm < 0x10000; tm++) {
  185. old_cmd = inb(ICEMT(ice, AC97_CMD));
  186. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  187. continue;
  188. if (!(old_cmd & ICE1712_AC97_READY))
  189. continue;
  190. break;
  191. }
  192. outb(reg, ICEMT(ice, AC97_INDEX));
  193. outw(val, ICEMT(ice, AC97_DATA));
  194. old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR);
  195. outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD));
  196. for (tm = 0; tm < 0x10000; tm++)
  197. if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0)
  198. break;
  199. }
  200. static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97,
  201. unsigned short reg)
  202. {
  203. struct snd_ice1712 *ice = ac97->private_data;
  204. int tm;
  205. unsigned char old_cmd = 0;
  206. for (tm = 0; tm < 0x10000; tm++) {
  207. old_cmd = inb(ICEMT(ice, AC97_CMD));
  208. if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ))
  209. continue;
  210. if (!(old_cmd & ICE1712_AC97_READY))
  211. continue;
  212. break;
  213. }
  214. outb(reg, ICEMT(ice, AC97_INDEX));
  215. outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD));
  216. for (tm = 0; tm < 0x10000; tm++)
  217. if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0)
  218. break;
  219. if (tm >= 0x10000) /* timeout */
  220. return ~0;
  221. return inw(ICEMT(ice, AC97_DATA));
  222. }
  223. /*
  224. * consumer ac97 digital mix
  225. */
  226. #define snd_ice1712_digmix_route_ac97_info snd_ctl_boolean_mono_info
  227. static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  228. {
  229. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  230. ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0;
  231. return 0;
  232. }
  233. static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  234. {
  235. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  236. unsigned char val, nval;
  237. spin_lock_irq(&ice->reg_lock);
  238. val = inb(ICEMT(ice, MONITOR_ROUTECTRL));
  239. nval = val & ~ICE1712_ROUTE_AC97;
  240. if (ucontrol->value.integer.value[0]) nval |= ICE1712_ROUTE_AC97;
  241. outb(nval, ICEMT(ice, MONITOR_ROUTECTRL));
  242. spin_unlock_irq(&ice->reg_lock);
  243. return val != nval;
  244. }
  245. static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = {
  246. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  247. .name = "Digital Mixer To AC97",
  248. .info = snd_ice1712_digmix_route_ac97_info,
  249. .get = snd_ice1712_digmix_route_ac97_get,
  250. .put = snd_ice1712_digmix_route_ac97_put,
  251. };
  252. /*
  253. * gpio operations
  254. */
  255. static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data)
  256. {
  257. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data);
  258. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  259. }
  260. static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data)
  261. {
  262. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data);
  263. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  264. }
  265. static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice)
  266. {
  267. return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
  268. }
  269. static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val)
  270. {
  271. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val);
  272. inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */
  273. }
  274. /*
  275. *
  276. * CS8427 interface
  277. *
  278. */
  279. /*
  280. * change the input clock selection
  281. * spdif_clock = 1 - IEC958 input, 0 - Envy24
  282. */
  283. static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock)
  284. {
  285. unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */
  286. unsigned char val, nval;
  287. int res = 0;
  288. snd_i2c_lock(ice->i2c);
  289. if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) {
  290. snd_i2c_unlock(ice->i2c);
  291. return -EIO;
  292. }
  293. if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) {
  294. snd_i2c_unlock(ice->i2c);
  295. return -EIO;
  296. }
  297. nval = val & 0xf0;
  298. if (spdif_clock)
  299. nval |= 0x01;
  300. else
  301. nval |= 0x04;
  302. if (val != nval) {
  303. reg[1] = nval;
  304. if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) {
  305. res = -EIO;
  306. } else {
  307. res++;
  308. }
  309. }
  310. snd_i2c_unlock(ice->i2c);
  311. return res;
  312. }
  313. /*
  314. * spdif callbacks
  315. */
  316. static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
  317. {
  318. snd_cs8427_iec958_active(ice->cs8427, 1);
  319. }
  320. static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
  321. {
  322. snd_cs8427_iec958_active(ice->cs8427, 0);
  323. }
  324. static void setup_cs8427(struct snd_ice1712 *ice, int rate)
  325. {
  326. snd_cs8427_iec958_pcm(ice->cs8427, rate);
  327. }
  328. /*
  329. * create and initialize callbacks for cs8427 interface
  330. */
  331. int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
  332. {
  333. int err;
  334. if ((err = snd_cs8427_create(ice->i2c, addr,
  335. (ice->cs8427_timeout * HZ) / 1000,
  336. &ice->cs8427)) < 0) {
  337. snd_printk(KERN_ERR "CS8427 initialization failed\n");
  338. return err;
  339. }
  340. ice->spdif.ops.open = open_cs8427;
  341. ice->spdif.ops.close = close_cs8427;
  342. ice->spdif.ops.setup_rate = setup_cs8427;
  343. return 0;
  344. }
  345. static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master)
  346. {
  347. /* change CS8427 clock source too */
  348. if (ice->cs8427)
  349. snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master);
  350. /* notify ak4524 chip as well */
  351. if (spdif_is_master) {
  352. unsigned int i;
  353. for (i = 0; i < ice->akm_codecs; i++) {
  354. if (ice->akm[i].ops.set_rate_val)
  355. ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
  356. }
  357. }
  358. }
  359. /*
  360. * Interrupt handler
  361. */
  362. static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
  363. {
  364. struct snd_ice1712 *ice = dev_id;
  365. unsigned char status;
  366. int handled = 0;
  367. while (1) {
  368. status = inb(ICEREG(ice, IRQSTAT));
  369. if (status == 0)
  370. break;
  371. handled = 1;
  372. if (status & ICE1712_IRQ_MPU1) {
  373. if (ice->rmidi[0])
  374. snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data);
  375. outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT));
  376. status &= ~ICE1712_IRQ_MPU1;
  377. }
  378. if (status & ICE1712_IRQ_TIMER)
  379. outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT));
  380. if (status & ICE1712_IRQ_MPU2) {
  381. if (ice->rmidi[1])
  382. snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data);
  383. outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT));
  384. status &= ~ICE1712_IRQ_MPU2;
  385. }
  386. if (status & ICE1712_IRQ_PROPCM) {
  387. unsigned char mtstat = inb(ICEMT(ice, IRQ));
  388. if (mtstat & ICE1712_MULTI_PBKSTATUS) {
  389. if (ice->playback_pro_substream)
  390. snd_pcm_period_elapsed(ice->playback_pro_substream);
  391. outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ));
  392. }
  393. if (mtstat & ICE1712_MULTI_CAPSTATUS) {
  394. if (ice->capture_pro_substream)
  395. snd_pcm_period_elapsed(ice->capture_pro_substream);
  396. outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ));
  397. }
  398. }
  399. if (status & ICE1712_IRQ_FM)
  400. outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT));
  401. if (status & ICE1712_IRQ_PBKDS) {
  402. u32 idx;
  403. u16 pbkstatus;
  404. struct snd_pcm_substream *substream;
  405. pbkstatus = inw(ICEDS(ice, INTSTAT));
  406. //printk("pbkstatus = 0x%x\n", pbkstatus);
  407. for (idx = 0; idx < 6; idx++) {
  408. if ((pbkstatus & (3 << (idx * 2))) == 0)
  409. continue;
  410. if ((substream = ice->playback_con_substream_ds[idx]) != NULL)
  411. snd_pcm_period_elapsed(substream);
  412. outw(3 << (idx * 2), ICEDS(ice, INTSTAT));
  413. }
  414. outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT));
  415. }
  416. if (status & ICE1712_IRQ_CONCAP) {
  417. if (ice->capture_con_substream)
  418. snd_pcm_period_elapsed(ice->capture_con_substream);
  419. outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT));
  420. }
  421. if (status & ICE1712_IRQ_CONPBK) {
  422. if (ice->playback_con_substream)
  423. snd_pcm_period_elapsed(ice->playback_con_substream);
  424. outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT));
  425. }
  426. }
  427. return IRQ_RETVAL(handled);
  428. }
  429. /*
  430. * PCM part - misc
  431. */
  432. static int snd_ice1712_hw_params(struct snd_pcm_substream *substream,
  433. struct snd_pcm_hw_params *hw_params)
  434. {
  435. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  436. }
  437. static int snd_ice1712_hw_free(struct snd_pcm_substream *substream)
  438. {
  439. return snd_pcm_lib_free_pages(substream);
  440. }
  441. /*
  442. * PCM part - consumer I/O
  443. */
  444. static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream,
  445. int cmd)
  446. {
  447. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  448. int result = 0;
  449. u32 tmp;
  450. spin_lock(&ice->reg_lock);
  451. tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL);
  452. if (cmd == SNDRV_PCM_TRIGGER_START) {
  453. tmp |= 1;
  454. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  455. tmp &= ~1;
  456. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
  457. tmp |= 2;
  458. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
  459. tmp &= ~2;
  460. } else {
  461. result = -EINVAL;
  462. }
  463. snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
  464. spin_unlock(&ice->reg_lock);
  465. return result;
  466. }
  467. static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream,
  468. int cmd)
  469. {
  470. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  471. int result = 0;
  472. u32 tmp;
  473. spin_lock(&ice->reg_lock);
  474. tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL);
  475. if (cmd == SNDRV_PCM_TRIGGER_START) {
  476. tmp |= 1;
  477. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  478. tmp &= ~1;
  479. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) {
  480. tmp |= 2;
  481. } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) {
  482. tmp &= ~2;
  483. } else {
  484. result = -EINVAL;
  485. }
  486. snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp);
  487. spin_unlock(&ice->reg_lock);
  488. return result;
  489. }
  490. static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream,
  491. int cmd)
  492. {
  493. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  494. int result = 0;
  495. u8 tmp;
  496. spin_lock(&ice->reg_lock);
  497. tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL);
  498. if (cmd == SNDRV_PCM_TRIGGER_START) {
  499. tmp |= 1;
  500. } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
  501. tmp &= ~1;
  502. } else {
  503. result = -EINVAL;
  504. }
  505. snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
  506. spin_unlock(&ice->reg_lock);
  507. return result;
  508. }
  509. static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream)
  510. {
  511. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  512. struct snd_pcm_runtime *runtime = substream->runtime;
  513. u32 period_size, buf_size, rate, tmp;
  514. period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  515. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  516. tmp = 0x0000;
  517. if (snd_pcm_format_width(runtime->format) == 16)
  518. tmp |= 0x10;
  519. if (runtime->channels == 2)
  520. tmp |= 0x08;
  521. rate = (runtime->rate * 8192) / 375;
  522. if (rate > 0x000fffff)
  523. rate = 0x000fffff;
  524. spin_lock_irq(&ice->reg_lock);
  525. outb(0, ice->ddma_port + 15);
  526. outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b);
  527. outl(runtime->dma_addr, ice->ddma_port + 0);
  528. outw(buf_size, ice->ddma_port + 4);
  529. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff);
  530. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff);
  531. snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff);
  532. snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp);
  533. snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff);
  534. snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8);
  535. snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0);
  536. snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0);
  537. spin_unlock_irq(&ice->reg_lock);
  538. return 0;
  539. }
  540. static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream)
  541. {
  542. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  543. struct snd_pcm_runtime *runtime = substream->runtime;
  544. u32 period_size, buf_size, rate, tmp, chn;
  545. period_size = snd_pcm_lib_period_bytes(substream) - 1;
  546. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  547. tmp = 0x0064;
  548. if (snd_pcm_format_width(runtime->format) == 16)
  549. tmp &= ~0x04;
  550. if (runtime->channels == 2)
  551. tmp |= 0x08;
  552. rate = (runtime->rate * 8192) / 375;
  553. if (rate > 0x000fffff)
  554. rate = 0x000fffff;
  555. ice->playback_con_active_buf[substream->number] = 0;
  556. ice->playback_con_virt_addr[substream->number] = runtime->dma_addr;
  557. chn = substream->number * 2;
  558. spin_lock_irq(&ice->reg_lock);
  559. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr);
  560. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size);
  561. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0));
  562. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size);
  563. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate);
  564. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0);
  565. snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp);
  566. if (runtime->channels == 2) {
  567. snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate);
  568. snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0);
  569. }
  570. spin_unlock_irq(&ice->reg_lock);
  571. return 0;
  572. }
  573. static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream)
  574. {
  575. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  576. struct snd_pcm_runtime *runtime = substream->runtime;
  577. u32 period_size, buf_size;
  578. u8 tmp;
  579. period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1;
  580. buf_size = snd_pcm_lib_buffer_bytes(substream) - 1;
  581. tmp = 0x06;
  582. if (snd_pcm_format_width(runtime->format) == 16)
  583. tmp &= ~0x04;
  584. if (runtime->channels == 2)
  585. tmp &= ~0x02;
  586. spin_lock_irq(&ice->reg_lock);
  587. outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR));
  588. outw(buf_size, ICEREG(ice, CONCAP_COUNT));
  589. snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8);
  590. snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff);
  591. snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp);
  592. spin_unlock_irq(&ice->reg_lock);
  593. snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
  594. return 0;
  595. }
  596. static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream)
  597. {
  598. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  599. struct snd_pcm_runtime *runtime = substream->runtime;
  600. size_t ptr;
  601. if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1))
  602. return 0;
  603. ptr = runtime->buffer_size - inw(ice->ddma_port + 4);
  604. if (ptr == runtime->buffer_size)
  605. ptr = 0;
  606. return bytes_to_frames(substream->runtime, ptr);
  607. }
  608. static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream)
  609. {
  610. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  611. u8 addr;
  612. size_t ptr;
  613. if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1))
  614. return 0;
  615. if (ice->playback_con_active_buf[substream->number])
  616. addr = ICE1712_DSC_ADDR1;
  617. else
  618. addr = ICE1712_DSC_ADDR0;
  619. ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) -
  620. ice->playback_con_virt_addr[substream->number];
  621. if (ptr == substream->runtime->buffer_size)
  622. ptr = 0;
  623. return bytes_to_frames(substream->runtime, ptr);
  624. }
  625. static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream)
  626. {
  627. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  628. size_t ptr;
  629. if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1))
  630. return 0;
  631. ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr;
  632. if (ptr == substream->runtime->buffer_size)
  633. ptr = 0;
  634. return bytes_to_frames(substream->runtime, ptr);
  635. }
  636. static const struct snd_pcm_hardware snd_ice1712_playback =
  637. {
  638. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  639. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  640. SNDRV_PCM_INFO_MMAP_VALID |
  641. SNDRV_PCM_INFO_PAUSE),
  642. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  643. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  644. .rate_min = 4000,
  645. .rate_max = 48000,
  646. .channels_min = 1,
  647. .channels_max = 2,
  648. .buffer_bytes_max = (64*1024),
  649. .period_bytes_min = 64,
  650. .period_bytes_max = (64*1024),
  651. .periods_min = 1,
  652. .periods_max = 1024,
  653. .fifo_size = 0,
  654. };
  655. static const struct snd_pcm_hardware snd_ice1712_playback_ds =
  656. {
  657. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  658. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  659. SNDRV_PCM_INFO_MMAP_VALID |
  660. SNDRV_PCM_INFO_PAUSE),
  661. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  662. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  663. .rate_min = 4000,
  664. .rate_max = 48000,
  665. .channels_min = 1,
  666. .channels_max = 2,
  667. .buffer_bytes_max = (128*1024),
  668. .period_bytes_min = 64,
  669. .period_bytes_max = (128*1024),
  670. .periods_min = 2,
  671. .periods_max = 2,
  672. .fifo_size = 0,
  673. };
  674. static const struct snd_pcm_hardware snd_ice1712_capture =
  675. {
  676. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  677. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  678. SNDRV_PCM_INFO_MMAP_VALID),
  679. .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  680. .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  681. .rate_min = 4000,
  682. .rate_max = 48000,
  683. .channels_min = 1,
  684. .channels_max = 2,
  685. .buffer_bytes_max = (64*1024),
  686. .period_bytes_min = 64,
  687. .period_bytes_max = (64*1024),
  688. .periods_min = 1,
  689. .periods_max = 1024,
  690. .fifo_size = 0,
  691. };
  692. static int snd_ice1712_playback_open(struct snd_pcm_substream *substream)
  693. {
  694. struct snd_pcm_runtime *runtime = substream->runtime;
  695. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  696. ice->playback_con_substream = substream;
  697. runtime->hw = snd_ice1712_playback;
  698. return 0;
  699. }
  700. static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream)
  701. {
  702. struct snd_pcm_runtime *runtime = substream->runtime;
  703. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  704. u32 tmp;
  705. ice->playback_con_substream_ds[substream->number] = substream;
  706. runtime->hw = snd_ice1712_playback_ds;
  707. spin_lock_irq(&ice->reg_lock);
  708. tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2));
  709. outw(tmp, ICEDS(ice, INTMASK));
  710. spin_unlock_irq(&ice->reg_lock);
  711. return 0;
  712. }
  713. static int snd_ice1712_capture_open(struct snd_pcm_substream *substream)
  714. {
  715. struct snd_pcm_runtime *runtime = substream->runtime;
  716. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  717. ice->capture_con_substream = substream;
  718. runtime->hw = snd_ice1712_capture;
  719. runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC];
  720. if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000))
  721. runtime->hw.rate_min = 48000;
  722. return 0;
  723. }
  724. static int snd_ice1712_playback_close(struct snd_pcm_substream *substream)
  725. {
  726. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  727. ice->playback_con_substream = NULL;
  728. return 0;
  729. }
  730. static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream)
  731. {
  732. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  733. u32 tmp;
  734. spin_lock_irq(&ice->reg_lock);
  735. tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2));
  736. outw(tmp, ICEDS(ice, INTMASK));
  737. spin_unlock_irq(&ice->reg_lock);
  738. ice->playback_con_substream_ds[substream->number] = NULL;
  739. return 0;
  740. }
  741. static int snd_ice1712_capture_close(struct snd_pcm_substream *substream)
  742. {
  743. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  744. ice->capture_con_substream = NULL;
  745. return 0;
  746. }
  747. static struct snd_pcm_ops snd_ice1712_playback_ops = {
  748. .open = snd_ice1712_playback_open,
  749. .close = snd_ice1712_playback_close,
  750. .ioctl = snd_pcm_lib_ioctl,
  751. .hw_params = snd_ice1712_hw_params,
  752. .hw_free = snd_ice1712_hw_free,
  753. .prepare = snd_ice1712_playback_prepare,
  754. .trigger = snd_ice1712_playback_trigger,
  755. .pointer = snd_ice1712_playback_pointer,
  756. };
  757. static struct snd_pcm_ops snd_ice1712_playback_ds_ops = {
  758. .open = snd_ice1712_playback_ds_open,
  759. .close = snd_ice1712_playback_ds_close,
  760. .ioctl = snd_pcm_lib_ioctl,
  761. .hw_params = snd_ice1712_hw_params,
  762. .hw_free = snd_ice1712_hw_free,
  763. .prepare = snd_ice1712_playback_ds_prepare,
  764. .trigger = snd_ice1712_playback_ds_trigger,
  765. .pointer = snd_ice1712_playback_ds_pointer,
  766. };
  767. static struct snd_pcm_ops snd_ice1712_capture_ops = {
  768. .open = snd_ice1712_capture_open,
  769. .close = snd_ice1712_capture_close,
  770. .ioctl = snd_pcm_lib_ioctl,
  771. .hw_params = snd_ice1712_hw_params,
  772. .hw_free = snd_ice1712_hw_free,
  773. .prepare = snd_ice1712_capture_prepare,
  774. .trigger = snd_ice1712_capture_trigger,
  775. .pointer = snd_ice1712_capture_pointer,
  776. };
  777. static int __devinit snd_ice1712_pcm(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
  778. {
  779. struct snd_pcm *pcm;
  780. int err;
  781. if (rpcm)
  782. *rpcm = NULL;
  783. err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm);
  784. if (err < 0)
  785. return err;
  786. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops);
  787. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops);
  788. pcm->private_data = ice;
  789. pcm->info_flags = 0;
  790. strcpy(pcm->name, "ICE1712 consumer");
  791. ice->pcm = pcm;
  792. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  793. snd_dma_pci_data(ice->pci), 64*1024, 64*1024);
  794. if (rpcm)
  795. *rpcm = pcm;
  796. printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n");
  797. return 0;
  798. }
  799. static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
  800. {
  801. struct snd_pcm *pcm;
  802. int err;
  803. if (rpcm)
  804. *rpcm = NULL;
  805. err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm);
  806. if (err < 0)
  807. return err;
  808. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops);
  809. pcm->private_data = ice;
  810. pcm->info_flags = 0;
  811. strcpy(pcm->name, "ICE1712 consumer (DS)");
  812. ice->pcm_ds = pcm;
  813. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  814. snd_dma_pci_data(ice->pci), 64*1024, 128*1024);
  815. if (rpcm)
  816. *rpcm = pcm;
  817. return 0;
  818. }
  819. /*
  820. * PCM code - professional part (multitrack)
  821. */
  822. static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  823. 32000, 44100, 48000, 64000, 88200, 96000 };
  824. static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
  825. .count = ARRAY_SIZE(rates),
  826. .list = rates,
  827. .mask = 0,
  828. };
  829. static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream,
  830. int cmd)
  831. {
  832. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  833. switch (cmd) {
  834. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  835. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  836. {
  837. unsigned int what;
  838. unsigned int old;
  839. if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
  840. return -EINVAL;
  841. what = ICE1712_PLAYBACK_PAUSE;
  842. snd_pcm_trigger_done(substream, substream);
  843. spin_lock(&ice->reg_lock);
  844. old = inl(ICEMT(ice, PLAYBACK_CONTROL));
  845. if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
  846. old |= what;
  847. else
  848. old &= ~what;
  849. outl(old, ICEMT(ice, PLAYBACK_CONTROL));
  850. spin_unlock(&ice->reg_lock);
  851. break;
  852. }
  853. case SNDRV_PCM_TRIGGER_START:
  854. case SNDRV_PCM_TRIGGER_STOP:
  855. {
  856. unsigned int what = 0;
  857. unsigned int old;
  858. struct snd_pcm_substream *s;
  859. snd_pcm_group_for_each_entry(s, substream) {
  860. if (s == ice->playback_pro_substream) {
  861. what |= ICE1712_PLAYBACK_START;
  862. snd_pcm_trigger_done(s, substream);
  863. } else if (s == ice->capture_pro_substream) {
  864. what |= ICE1712_CAPTURE_START_SHADOW;
  865. snd_pcm_trigger_done(s, substream);
  866. }
  867. }
  868. spin_lock(&ice->reg_lock);
  869. old = inl(ICEMT(ice, PLAYBACK_CONTROL));
  870. if (cmd == SNDRV_PCM_TRIGGER_START)
  871. old |= what;
  872. else
  873. old &= ~what;
  874. outl(old, ICEMT(ice, PLAYBACK_CONTROL));
  875. spin_unlock(&ice->reg_lock);
  876. break;
  877. }
  878. default:
  879. return -EINVAL;
  880. }
  881. return 0;
  882. }
  883. /*
  884. */
  885. static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force)
  886. {
  887. unsigned long flags;
  888. unsigned char val, old;
  889. unsigned int i;
  890. switch (rate) {
  891. case 8000: val = 6; break;
  892. case 9600: val = 3; break;
  893. case 11025: val = 10; break;
  894. case 12000: val = 2; break;
  895. case 16000: val = 5; break;
  896. case 22050: val = 9; break;
  897. case 24000: val = 1; break;
  898. case 32000: val = 4; break;
  899. case 44100: val = 8; break;
  900. case 48000: val = 0; break;
  901. case 64000: val = 15; break;
  902. case 88200: val = 11; break;
  903. case 96000: val = 7; break;
  904. default:
  905. snd_BUG();
  906. val = 0;
  907. rate = 48000;
  908. break;
  909. }
  910. spin_lock_irqsave(&ice->reg_lock, flags);
  911. if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
  912. ICE1712_PLAYBACK_PAUSE|
  913. ICE1712_PLAYBACK_START)) {
  914. __out:
  915. spin_unlock_irqrestore(&ice->reg_lock, flags);
  916. return;
  917. }
  918. if (!force && is_pro_rate_locked(ice))
  919. goto __out;
  920. old = inb(ICEMT(ice, RATE));
  921. if (!force && old == val)
  922. goto __out;
  923. outb(val, ICEMT(ice, RATE));
  924. spin_unlock_irqrestore(&ice->reg_lock, flags);
  925. if (ice->gpio.set_pro_rate)
  926. ice->gpio.set_pro_rate(ice, rate);
  927. for (i = 0; i < ice->akm_codecs; i++) {
  928. if (ice->akm[i].ops.set_rate_val)
  929. ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
  930. }
  931. if (ice->spdif.ops.setup_rate)
  932. ice->spdif.ops.setup_rate(ice, rate);
  933. }
  934. static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream)
  935. {
  936. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  937. ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream);
  938. spin_lock_irq(&ice->reg_lock);
  939. outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR));
  940. outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE));
  941. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT));
  942. spin_unlock_irq(&ice->reg_lock);
  943. return 0;
  944. }
  945. static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream,
  946. struct snd_pcm_hw_params *hw_params)
  947. {
  948. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  949. snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
  950. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  951. }
  952. static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream)
  953. {
  954. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  955. ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream);
  956. spin_lock_irq(&ice->reg_lock);
  957. outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR));
  958. outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE));
  959. outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT));
  960. spin_unlock_irq(&ice->reg_lock);
  961. return 0;
  962. }
  963. static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream,
  964. struct snd_pcm_hw_params *hw_params)
  965. {
  966. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  967. snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0);
  968. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  969. }
  970. static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream)
  971. {
  972. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  973. size_t ptr;
  974. if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START))
  975. return 0;
  976. ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2);
  977. if (ptr == substream->runtime->buffer_size)
  978. ptr = 0;
  979. return bytes_to_frames(substream->runtime, ptr);
  980. }
  981. static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream)
  982. {
  983. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  984. size_t ptr;
  985. if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW))
  986. return 0;
  987. ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2);
  988. if (ptr == substream->runtime->buffer_size)
  989. ptr = 0;
  990. return bytes_to_frames(substream->runtime, ptr);
  991. }
  992. static const struct snd_pcm_hardware snd_ice1712_playback_pro =
  993. {
  994. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  995. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  996. SNDRV_PCM_INFO_MMAP_VALID |
  997. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  998. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  999. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
  1000. .rate_min = 4000,
  1001. .rate_max = 96000,
  1002. .channels_min = 10,
  1003. .channels_max = 10,
  1004. .buffer_bytes_max = (256*1024),
  1005. .period_bytes_min = 10 * 4 * 2,
  1006. .period_bytes_max = 131040,
  1007. .periods_min = 1,
  1008. .periods_max = 1024,
  1009. .fifo_size = 0,
  1010. };
  1011. static const struct snd_pcm_hardware snd_ice1712_capture_pro =
  1012. {
  1013. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  1014. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  1015. SNDRV_PCM_INFO_MMAP_VALID |
  1016. SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
  1017. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  1018. .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000,
  1019. .rate_min = 4000,
  1020. .rate_max = 96000,
  1021. .channels_min = 12,
  1022. .channels_max = 12,
  1023. .buffer_bytes_max = (256*1024),
  1024. .period_bytes_min = 12 * 4 * 2,
  1025. .period_bytes_max = 131040,
  1026. .periods_min = 1,
  1027. .periods_max = 1024,
  1028. .fifo_size = 0,
  1029. };
  1030. static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream)
  1031. {
  1032. struct snd_pcm_runtime *runtime = substream->runtime;
  1033. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1034. ice->playback_pro_substream = substream;
  1035. runtime->hw = snd_ice1712_playback_pro;
  1036. snd_pcm_set_sync(substream);
  1037. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1038. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
  1039. if (ice->spdif.ops.open)
  1040. ice->spdif.ops.open(ice, substream);
  1041. return 0;
  1042. }
  1043. static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream)
  1044. {
  1045. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1046. struct snd_pcm_runtime *runtime = substream->runtime;
  1047. ice->capture_pro_substream = substream;
  1048. runtime->hw = snd_ice1712_capture_pro;
  1049. snd_pcm_set_sync(substream);
  1050. snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
  1051. snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
  1052. return 0;
  1053. }
  1054. static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream)
  1055. {
  1056. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1057. if (PRO_RATE_RESET)
  1058. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1059. ice->playback_pro_substream = NULL;
  1060. if (ice->spdif.ops.close)
  1061. ice->spdif.ops.close(ice, substream);
  1062. return 0;
  1063. }
  1064. static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream)
  1065. {
  1066. struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
  1067. if (PRO_RATE_RESET)
  1068. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0);
  1069. ice->capture_pro_substream = NULL;
  1070. return 0;
  1071. }
  1072. static struct snd_pcm_ops snd_ice1712_playback_pro_ops = {
  1073. .open = snd_ice1712_playback_pro_open,
  1074. .close = snd_ice1712_playback_pro_close,
  1075. .ioctl = snd_pcm_lib_ioctl,
  1076. .hw_params = snd_ice1712_playback_pro_hw_params,
  1077. .hw_free = snd_ice1712_hw_free,
  1078. .prepare = snd_ice1712_playback_pro_prepare,
  1079. .trigger = snd_ice1712_pro_trigger,
  1080. .pointer = snd_ice1712_playback_pro_pointer,
  1081. };
  1082. static struct snd_pcm_ops snd_ice1712_capture_pro_ops = {
  1083. .open = snd_ice1712_capture_pro_open,
  1084. .close = snd_ice1712_capture_pro_close,
  1085. .ioctl = snd_pcm_lib_ioctl,
  1086. .hw_params = snd_ice1712_capture_pro_hw_params,
  1087. .hw_free = snd_ice1712_hw_free,
  1088. .prepare = snd_ice1712_capture_pro_prepare,
  1089. .trigger = snd_ice1712_pro_trigger,
  1090. .pointer = snd_ice1712_capture_pro_pointer,
  1091. };
  1092. static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 * ice, int device, struct snd_pcm ** rpcm)
  1093. {
  1094. struct snd_pcm *pcm;
  1095. int err;
  1096. if (rpcm)
  1097. *rpcm = NULL;
  1098. err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm);
  1099. if (err < 0)
  1100. return err;
  1101. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops);
  1102. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops);
  1103. pcm->private_data = ice;
  1104. pcm->info_flags = 0;
  1105. strcpy(pcm->name, "ICE1712 multi");
  1106. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  1107. snd_dma_pci_data(ice->pci), 256*1024, 256*1024);
  1108. ice->pcm_pro = pcm;
  1109. if (rpcm)
  1110. *rpcm = pcm;
  1111. if (ice->cs8427) {
  1112. /* assign channels to iec958 */
  1113. err = snd_cs8427_iec958_build(ice->cs8427,
  1114. pcm->streams[0].substream,
  1115. pcm->streams[1].substream);
  1116. if (err < 0)
  1117. return err;
  1118. }
  1119. if ((err = snd_ice1712_build_pro_mixer(ice)) < 0)
  1120. return err;
  1121. return 0;
  1122. }
  1123. /*
  1124. * Mixer section
  1125. */
  1126. static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
  1127. {
  1128. unsigned int vol = ice->pro_volumes[index];
  1129. unsigned short val = 0;
  1130. val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f;
  1131. val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8;
  1132. outb(index, ICEMT(ice, MONITOR_INDEX));
  1133. outw(val, ICEMT(ice, MONITOR_VOLUME));
  1134. }
  1135. #define snd_ice1712_pro_mixer_switch_info snd_ctl_boolean_stereo_info
  1136. static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1137. {
  1138. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1139. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1140. spin_lock_irq(&ice->reg_lock);
  1141. ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1);
  1142. ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1);
  1143. spin_unlock_irq(&ice->reg_lock);
  1144. return 0;
  1145. }
  1146. static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1147. {
  1148. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1149. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1150. unsigned int nval, change;
  1151. nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
  1152. (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
  1153. spin_lock_irq(&ice->reg_lock);
  1154. nval |= ice->pro_volumes[index] & ~0x80008000;
  1155. change = nval != ice->pro_volumes[index];
  1156. ice->pro_volumes[index] = nval;
  1157. snd_ice1712_update_volume(ice, index);
  1158. spin_unlock_irq(&ice->reg_lock);
  1159. return change;
  1160. }
  1161. static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1162. {
  1163. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1164. uinfo->count = 2;
  1165. uinfo->value.integer.min = 0;
  1166. uinfo->value.integer.max = 96;
  1167. return 0;
  1168. }
  1169. static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1170. {
  1171. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1172. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1173. spin_lock_irq(&ice->reg_lock);
  1174. ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127;
  1175. ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127;
  1176. spin_unlock_irq(&ice->reg_lock);
  1177. return 0;
  1178. }
  1179. static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1180. {
  1181. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1182. int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value;
  1183. unsigned int nval, change;
  1184. nval = (ucontrol->value.integer.value[0] & 127) |
  1185. ((ucontrol->value.integer.value[1] & 127) << 16);
  1186. spin_lock_irq(&ice->reg_lock);
  1187. nval |= ice->pro_volumes[index] & ~0x007f007f;
  1188. change = nval != ice->pro_volumes[index];
  1189. ice->pro_volumes[index] = nval;
  1190. snd_ice1712_update_volume(ice, index);
  1191. spin_unlock_irq(&ice->reg_lock);
  1192. return change;
  1193. }
  1194. static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0);
  1195. static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = {
  1196. {
  1197. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1198. .name = "Multi Playback Switch",
  1199. .info = snd_ice1712_pro_mixer_switch_info,
  1200. .get = snd_ice1712_pro_mixer_switch_get,
  1201. .put = snd_ice1712_pro_mixer_switch_put,
  1202. .private_value = 0,
  1203. .count = 10,
  1204. },
  1205. {
  1206. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1207. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  1208. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  1209. .name = "Multi Playback Volume",
  1210. .info = snd_ice1712_pro_mixer_volume_info,
  1211. .get = snd_ice1712_pro_mixer_volume_get,
  1212. .put = snd_ice1712_pro_mixer_volume_put,
  1213. .private_value = 0,
  1214. .count = 10,
  1215. .tlv = { .p = db_scale_playback }
  1216. },
  1217. };
  1218. static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = {
  1219. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1220. .name = "H/W Multi Capture Switch",
  1221. .info = snd_ice1712_pro_mixer_switch_info,
  1222. .get = snd_ice1712_pro_mixer_switch_get,
  1223. .put = snd_ice1712_pro_mixer_switch_put,
  1224. .private_value = 10,
  1225. };
  1226. static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = {
  1227. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1228. .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,SWITCH),
  1229. .info = snd_ice1712_pro_mixer_switch_info,
  1230. .get = snd_ice1712_pro_mixer_switch_get,
  1231. .put = snd_ice1712_pro_mixer_switch_put,
  1232. .private_value = 18,
  1233. .count = 2,
  1234. };
  1235. static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = {
  1236. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1237. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  1238. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  1239. .name = "H/W Multi Capture Volume",
  1240. .info = snd_ice1712_pro_mixer_volume_info,
  1241. .get = snd_ice1712_pro_mixer_volume_get,
  1242. .put = snd_ice1712_pro_mixer_volume_put,
  1243. .private_value = 10,
  1244. .tlv = { .p = db_scale_playback }
  1245. };
  1246. static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = {
  1247. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1248. .name = SNDRV_CTL_NAME_IEC958("Multi ",CAPTURE,VOLUME),
  1249. .info = snd_ice1712_pro_mixer_volume_info,
  1250. .get = snd_ice1712_pro_mixer_volume_get,
  1251. .put = snd_ice1712_pro_mixer_volume_put,
  1252. .private_value = 18,
  1253. .count = 2,
  1254. };
  1255. static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice)
  1256. {
  1257. struct snd_card *card = ice->card;
  1258. unsigned int idx;
  1259. int err;
  1260. /* multi-channel mixer */
  1261. for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) {
  1262. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice));
  1263. if (err < 0)
  1264. return err;
  1265. }
  1266. if (ice->num_total_adcs > 0) {
  1267. struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch;
  1268. tmp.count = ice->num_total_adcs;
  1269. err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
  1270. if (err < 0)
  1271. return err;
  1272. }
  1273. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice));
  1274. if (err < 0)
  1275. return err;
  1276. if (ice->num_total_adcs > 0) {
  1277. struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume;
  1278. tmp.count = ice->num_total_adcs;
  1279. err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice));
  1280. if (err < 0)
  1281. return err;
  1282. }
  1283. err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice));
  1284. if (err < 0)
  1285. return err;
  1286. /* initialize volumes */
  1287. for (idx = 0; idx < 10; idx++) {
  1288. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1289. snd_ice1712_update_volume(ice, idx);
  1290. }
  1291. for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) {
  1292. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1293. snd_ice1712_update_volume(ice, idx);
  1294. }
  1295. for (idx = 18; idx < 20; idx++) {
  1296. ice->pro_volumes[idx] = 0x80008000; /* mute */
  1297. snd_ice1712_update_volume(ice, idx);
  1298. }
  1299. return 0;
  1300. }
  1301. static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97)
  1302. {
  1303. struct snd_ice1712 *ice = ac97->private_data;
  1304. ice->ac97 = NULL;
  1305. }
  1306. static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 * ice)
  1307. {
  1308. int err, bus_num = 0;
  1309. struct snd_ac97_template ac97;
  1310. struct snd_ac97_bus *pbus;
  1311. static struct snd_ac97_bus_ops con_ops = {
  1312. .write = snd_ice1712_ac97_write,
  1313. .read = snd_ice1712_ac97_read,
  1314. };
  1315. static struct snd_ac97_bus_ops pro_ops = {
  1316. .write = snd_ice1712_pro_ac97_write,
  1317. .read = snd_ice1712_pro_ac97_read,
  1318. };
  1319. if (ice_has_con_ac97(ice)) {
  1320. if ((err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus)) < 0)
  1321. return err;
  1322. memset(&ac97, 0, sizeof(ac97));
  1323. ac97.private_data = ice;
  1324. ac97.private_free = snd_ice1712_mixer_free_ac97;
  1325. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1326. printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n");
  1327. else {
  1328. if ((err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice))) < 0)
  1329. return err;
  1330. return 0;
  1331. }
  1332. }
  1333. if (! (ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) {
  1334. if ((err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus)) < 0)
  1335. return err;
  1336. memset(&ac97, 0, sizeof(ac97));
  1337. ac97.private_data = ice;
  1338. ac97.private_free = snd_ice1712_mixer_free_ac97;
  1339. if ((err = snd_ac97_mixer(pbus, &ac97, &ice->ac97)) < 0)
  1340. printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n");
  1341. else
  1342. return 0;
  1343. }
  1344. /* I2S mixer only */
  1345. strcat(ice->card->mixername, "ICE1712 - multitrack");
  1346. return 0;
  1347. }
  1348. /*
  1349. *
  1350. */
  1351. static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx)
  1352. {
  1353. return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8);
  1354. }
  1355. static void snd_ice1712_proc_read(struct snd_info_entry *entry,
  1356. struct snd_info_buffer *buffer)
  1357. {
  1358. struct snd_ice1712 *ice = entry->private_data;
  1359. unsigned int idx;
  1360. snd_iprintf(buffer, "%s\n\n", ice->card->longname);
  1361. snd_iprintf(buffer, "EEPROM:\n");
  1362. snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor);
  1363. snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size);
  1364. snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version);
  1365. snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]);
  1366. snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]);
  1367. snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]);
  1368. snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]);
  1369. snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask);
  1370. snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate);
  1371. snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir);
  1372. snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO));
  1373. snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO));
  1374. snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO));
  1375. snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]);
  1376. for (idx = 0; idx < 4; idx++)
  1377. snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]);
  1378. for (idx = 0; idx < 4; idx++)
  1379. snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]);
  1380. for (idx = 0x1c; idx < ice->eeprom.size; idx++)
  1381. snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]);
  1382. snd_iprintf(buffer, "\nRegisters:\n");
  1383. snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03)));
  1384. snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE)));
  1385. snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT)));
  1386. snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE)));
  1387. snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice));
  1388. snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK));
  1389. snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION));
  1390. }
  1391. static void __devinit snd_ice1712_proc_init(struct snd_ice1712 * ice)
  1392. {
  1393. struct snd_info_entry *entry;
  1394. if (! snd_card_proc_new(ice->card, "ice1712", &entry))
  1395. snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read);
  1396. }
  1397. /*
  1398. *
  1399. */
  1400. static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol,
  1401. struct snd_ctl_elem_info *uinfo)
  1402. {
  1403. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  1404. uinfo->count = sizeof(struct snd_ice1712_eeprom);
  1405. return 0;
  1406. }
  1407. static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol,
  1408. struct snd_ctl_elem_value *ucontrol)
  1409. {
  1410. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1411. memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom));
  1412. return 0;
  1413. }
  1414. static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = {
  1415. .iface = SNDRV_CTL_ELEM_IFACE_CARD,
  1416. .name = "ICE1712 EEPROM",
  1417. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1418. .info = snd_ice1712_eeprom_info,
  1419. .get = snd_ice1712_eeprom_get
  1420. };
  1421. /*
  1422. */
  1423. static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol,
  1424. struct snd_ctl_elem_info *uinfo)
  1425. {
  1426. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  1427. uinfo->count = 1;
  1428. return 0;
  1429. }
  1430. static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol,
  1431. struct snd_ctl_elem_value *ucontrol)
  1432. {
  1433. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1434. if (ice->spdif.ops.default_get)
  1435. ice->spdif.ops.default_get(ice, ucontrol);
  1436. return 0;
  1437. }
  1438. static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol,
  1439. struct snd_ctl_elem_value *ucontrol)
  1440. {
  1441. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1442. if (ice->spdif.ops.default_put)
  1443. return ice->spdif.ops.default_put(ice, ucontrol);
  1444. return 0;
  1445. }
  1446. static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata =
  1447. {
  1448. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1449. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  1450. .info = snd_ice1712_spdif_info,
  1451. .get = snd_ice1712_spdif_default_get,
  1452. .put = snd_ice1712_spdif_default_put
  1453. };
  1454. static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol,
  1455. struct snd_ctl_elem_value *ucontrol)
  1456. {
  1457. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1458. if (ice->spdif.ops.default_get) {
  1459. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1460. IEC958_AES0_PROFESSIONAL |
  1461. IEC958_AES0_CON_NOT_COPYRIGHT |
  1462. IEC958_AES0_CON_EMPHASIS;
  1463. ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL |
  1464. IEC958_AES1_CON_CATEGORY;
  1465. ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS;
  1466. } else {
  1467. ucontrol->value.iec958.status[0] = 0xff;
  1468. ucontrol->value.iec958.status[1] = 0xff;
  1469. ucontrol->value.iec958.status[2] = 0xff;
  1470. ucontrol->value.iec958.status[3] = 0xff;
  1471. ucontrol->value.iec958.status[4] = 0xff;
  1472. }
  1473. return 0;
  1474. }
  1475. static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol,
  1476. struct snd_ctl_elem_value *ucontrol)
  1477. {
  1478. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1479. if (ice->spdif.ops.default_get) {
  1480. ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO |
  1481. IEC958_AES0_PROFESSIONAL |
  1482. IEC958_AES0_PRO_FS |
  1483. IEC958_AES0_PRO_EMPHASIS;
  1484. ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE;
  1485. } else {
  1486. ucontrol->value.iec958.status[0] = 0xff;
  1487. ucontrol->value.iec958.status[1] = 0xff;
  1488. ucontrol->value.iec958.status[2] = 0xff;
  1489. ucontrol->value.iec958.status[3] = 0xff;
  1490. ucontrol->value.iec958.status[4] = 0xff;
  1491. }
  1492. return 0;
  1493. }
  1494. static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata =
  1495. {
  1496. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1497. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1498. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  1499. .info = snd_ice1712_spdif_info,
  1500. .get = snd_ice1712_spdif_maskc_get,
  1501. };
  1502. static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata =
  1503. {
  1504. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  1505. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1506. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  1507. .info = snd_ice1712_spdif_info,
  1508. .get = snd_ice1712_spdif_maskp_get,
  1509. };
  1510. static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol,
  1511. struct snd_ctl_elem_value *ucontrol)
  1512. {
  1513. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1514. if (ice->spdif.ops.stream_get)
  1515. ice->spdif.ops.stream_get(ice, ucontrol);
  1516. return 0;
  1517. }
  1518. static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol,
  1519. struct snd_ctl_elem_value *ucontrol)
  1520. {
  1521. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1522. if (ice->spdif.ops.stream_put)
  1523. return ice->spdif.ops.stream_put(ice, ucontrol);
  1524. return 0;
  1525. }
  1526. static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata =
  1527. {
  1528. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  1529. SNDRV_CTL_ELEM_ACCESS_INACTIVE),
  1530. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  1531. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
  1532. .info = snd_ice1712_spdif_info,
  1533. .get = snd_ice1712_spdif_stream_get,
  1534. .put = snd_ice1712_spdif_stream_put
  1535. };
  1536. int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol,
  1537. struct snd_ctl_elem_value *ucontrol)
  1538. {
  1539. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1540. unsigned char mask = kcontrol->private_value & 0xff;
  1541. int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0;
  1542. snd_ice1712_save_gpio_status(ice);
  1543. ucontrol->value.integer.value[0] =
  1544. (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert;
  1545. snd_ice1712_restore_gpio_status(ice);
  1546. return 0;
  1547. }
  1548. int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
  1549. struct snd_ctl_elem_value *ucontrol)
  1550. {
  1551. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1552. unsigned char mask = kcontrol->private_value & 0xff;
  1553. int invert = (kcontrol->private_value & (1<<24)) ? mask : 0;
  1554. unsigned int val, nval;
  1555. if (kcontrol->private_value & (1 << 31))
  1556. return -EPERM;
  1557. nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert;
  1558. snd_ice1712_save_gpio_status(ice);
  1559. val = snd_ice1712_gpio_read(ice);
  1560. nval |= val & ~mask;
  1561. if (val != nval)
  1562. snd_ice1712_gpio_write(ice, nval);
  1563. snd_ice1712_restore_gpio_status(ice);
  1564. return val != nval;
  1565. }
  1566. /*
  1567. * rate
  1568. */
  1569. static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
  1570. struct snd_ctl_elem_info *uinfo)
  1571. {
  1572. static const char * const texts[] = {
  1573. "8000", /* 0: 6 */
  1574. "9600", /* 1: 3 */
  1575. "11025", /* 2: 10 */
  1576. "12000", /* 3: 2 */
  1577. "16000", /* 4: 5 */
  1578. "22050", /* 5: 9 */
  1579. "24000", /* 6: 1 */
  1580. "32000", /* 7: 4 */
  1581. "44100", /* 8: 8 */
  1582. "48000", /* 9: 0 */
  1583. "64000", /* 10: 15 */
  1584. "88200", /* 11: 11 */
  1585. "96000", /* 12: 7 */
  1586. "IEC958 Input", /* 13: -- */
  1587. };
  1588. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1589. uinfo->count = 1;
  1590. uinfo->value.enumerated.items = 14;
  1591. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1592. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1593. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1594. return 0;
  1595. }
  1596. static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
  1597. struct snd_ctl_elem_value *ucontrol)
  1598. {
  1599. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1600. static const unsigned char xlate[16] = {
  1601. 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10
  1602. };
  1603. unsigned char val;
  1604. spin_lock_irq(&ice->reg_lock);
  1605. if (is_spdif_master(ice)) {
  1606. ucontrol->value.enumerated.item[0] = 13;
  1607. } else {
  1608. val = xlate[inb(ICEMT(ice, RATE)) & 15];
  1609. if (val == 255) {
  1610. snd_BUG();
  1611. val = 0;
  1612. }
  1613. ucontrol->value.enumerated.item[0] = val;
  1614. }
  1615. spin_unlock_irq(&ice->reg_lock);
  1616. return 0;
  1617. }
  1618. static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
  1619. struct snd_ctl_elem_value *ucontrol)
  1620. {
  1621. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1622. static const unsigned int xrate[13] = {
  1623. 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  1624. 32000, 44100, 48000, 64000, 88200, 96000
  1625. };
  1626. unsigned char oval;
  1627. int change = 0;
  1628. spin_lock_irq(&ice->reg_lock);
  1629. oval = inb(ICEMT(ice, RATE));
  1630. if (ucontrol->value.enumerated.item[0] == 13) {
  1631. outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE));
  1632. } else {
  1633. PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
  1634. spin_unlock_irq(&ice->reg_lock);
  1635. snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1);
  1636. spin_lock_irq(&ice->reg_lock);
  1637. }
  1638. change = inb(ICEMT(ice, RATE)) != oval;
  1639. spin_unlock_irq(&ice->reg_lock);
  1640. if ((oval & ICE1712_SPDIF_MASTER) !=
  1641. (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER))
  1642. snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice));
  1643. return change;
  1644. }
  1645. static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = {
  1646. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1647. .name = "Multi Track Internal Clock",
  1648. .info = snd_ice1712_pro_internal_clock_info,
  1649. .get = snd_ice1712_pro_internal_clock_get,
  1650. .put = snd_ice1712_pro_internal_clock_put
  1651. };
  1652. static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol,
  1653. struct snd_ctl_elem_info *uinfo)
  1654. {
  1655. static const char * const texts[] = {
  1656. "8000", /* 0: 6 */
  1657. "9600", /* 1: 3 */
  1658. "11025", /* 2: 10 */
  1659. "12000", /* 3: 2 */
  1660. "16000", /* 4: 5 */
  1661. "22050", /* 5: 9 */
  1662. "24000", /* 6: 1 */
  1663. "32000", /* 7: 4 */
  1664. "44100", /* 8: 8 */
  1665. "48000", /* 9: 0 */
  1666. "64000", /* 10: 15 */
  1667. "88200", /* 11: 11 */
  1668. "96000", /* 12: 7 */
  1669. // "IEC958 Input", /* 13: -- */
  1670. };
  1671. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1672. uinfo->count = 1;
  1673. uinfo->value.enumerated.items = 13;
  1674. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1675. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1676. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1677. return 0;
  1678. }
  1679. static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol,
  1680. struct snd_ctl_elem_value *ucontrol)
  1681. {
  1682. int val;
  1683. static const unsigned int xrate[13] = {
  1684. 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  1685. 32000, 44100, 48000, 64000, 88200, 96000
  1686. };
  1687. for (val = 0; val < 13; val++) {
  1688. if (xrate[val] == PRO_RATE_DEFAULT)
  1689. break;
  1690. }
  1691. ucontrol->value.enumerated.item[0] = val;
  1692. return 0;
  1693. }
  1694. static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol,
  1695. struct snd_ctl_elem_value *ucontrol)
  1696. {
  1697. static const unsigned int xrate[13] = {
  1698. 8000, 9600, 11025, 12000, 16000, 22050, 24000,
  1699. 32000, 44100, 48000, 64000, 88200, 96000
  1700. };
  1701. unsigned char oval;
  1702. int change = 0;
  1703. oval = PRO_RATE_DEFAULT;
  1704. PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13];
  1705. change = PRO_RATE_DEFAULT != oval;
  1706. return change;
  1707. }
  1708. static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = {
  1709. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1710. .name = "Multi Track Internal Clock Default",
  1711. .info = snd_ice1712_pro_internal_clock_default_info,
  1712. .get = snd_ice1712_pro_internal_clock_default_get,
  1713. .put = snd_ice1712_pro_internal_clock_default_put
  1714. };
  1715. #define snd_ice1712_pro_rate_locking_info snd_ctl_boolean_mono_info
  1716. static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol,
  1717. struct snd_ctl_elem_value *ucontrol)
  1718. {
  1719. ucontrol->value.integer.value[0] = PRO_RATE_LOCKED;
  1720. return 0;
  1721. }
  1722. static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol,
  1723. struct snd_ctl_elem_value *ucontrol)
  1724. {
  1725. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1726. int change = 0, nval;
  1727. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1728. spin_lock_irq(&ice->reg_lock);
  1729. change = PRO_RATE_LOCKED != nval;
  1730. PRO_RATE_LOCKED = nval;
  1731. spin_unlock_irq(&ice->reg_lock);
  1732. return change;
  1733. }
  1734. static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = {
  1735. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1736. .name = "Multi Track Rate Locking",
  1737. .info = snd_ice1712_pro_rate_locking_info,
  1738. .get = snd_ice1712_pro_rate_locking_get,
  1739. .put = snd_ice1712_pro_rate_locking_put
  1740. };
  1741. #define snd_ice1712_pro_rate_reset_info snd_ctl_boolean_mono_info
  1742. static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol,
  1743. struct snd_ctl_elem_value *ucontrol)
  1744. {
  1745. ucontrol->value.integer.value[0] = PRO_RATE_RESET;
  1746. return 0;
  1747. }
  1748. static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol,
  1749. struct snd_ctl_elem_value *ucontrol)
  1750. {
  1751. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1752. int change = 0, nval;
  1753. nval = ucontrol->value.integer.value[0] ? 1 : 0;
  1754. spin_lock_irq(&ice->reg_lock);
  1755. change = PRO_RATE_RESET != nval;
  1756. PRO_RATE_RESET = nval;
  1757. spin_unlock_irq(&ice->reg_lock);
  1758. return change;
  1759. }
  1760. static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = {
  1761. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1762. .name = "Multi Track Rate Reset",
  1763. .info = snd_ice1712_pro_rate_reset_info,
  1764. .get = snd_ice1712_pro_rate_reset_get,
  1765. .put = snd_ice1712_pro_rate_reset_put
  1766. };
  1767. /*
  1768. * routing
  1769. */
  1770. static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol,
  1771. struct snd_ctl_elem_info *uinfo)
  1772. {
  1773. static const char * const texts[] = {
  1774. "PCM Out", /* 0 */
  1775. "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */
  1776. "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */
  1777. "IEC958 In L", "IEC958 In R", /* 9-10 */
  1778. "Digital Mixer", /* 11 - optional */
  1779. };
  1780. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1781. uinfo->count = 1;
  1782. uinfo->value.enumerated.items =
  1783. snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11;
  1784. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  1785. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  1786. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1787. return 0;
  1788. }
  1789. static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol,
  1790. struct snd_ctl_elem_value *ucontrol)
  1791. {
  1792. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1793. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1794. unsigned int val, cval;
  1795. spin_lock_irq(&ice->reg_lock);
  1796. val = inw(ICEMT(ice, ROUTE_PSDOUT03));
  1797. cval = inl(ICEMT(ice, ROUTE_CAPTURE));
  1798. spin_unlock_irq(&ice->reg_lock);
  1799. val >>= ((idx % 2) * 8) + ((idx / 2) * 2);
  1800. val &= 3;
  1801. cval >>= ((idx / 2) * 8) + ((idx % 2) * 4);
  1802. if (val == 1 && idx < 2)
  1803. ucontrol->value.enumerated.item[0] = 11;
  1804. else if (val == 2)
  1805. ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
  1806. else if (val == 3)
  1807. ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
  1808. else
  1809. ucontrol->value.enumerated.item[0] = 0;
  1810. return 0;
  1811. }
  1812. static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol,
  1813. struct snd_ctl_elem_value *ucontrol)
  1814. {
  1815. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1816. int change, shift;
  1817. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1818. unsigned int val, old_val, nval;
  1819. /* update PSDOUT */
  1820. if (ucontrol->value.enumerated.item[0] >= 11)
  1821. nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */
  1822. else if (ucontrol->value.enumerated.item[0] >= 9)
  1823. nval = 3; /* spdif in */
  1824. else if (ucontrol->value.enumerated.item[0] >= 1)
  1825. nval = 2; /* analog in */
  1826. else
  1827. nval = 0; /* pcm */
  1828. shift = ((idx % 2) * 8) + ((idx / 2) * 2);
  1829. spin_lock_irq(&ice->reg_lock);
  1830. val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03));
  1831. val &= ~(0x03 << shift);
  1832. val |= nval << shift;
  1833. change = val != old_val;
  1834. if (change)
  1835. outw(val, ICEMT(ice, ROUTE_PSDOUT03));
  1836. spin_unlock_irq(&ice->reg_lock);
  1837. if (nval < 2) /* dig mixer of pcm */
  1838. return change;
  1839. /* update CAPTURE */
  1840. spin_lock_irq(&ice->reg_lock);
  1841. val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE));
  1842. shift = ((idx / 2) * 8) + ((idx % 2) * 4);
  1843. if (nval == 2) { /* analog in */
  1844. nval = ucontrol->value.enumerated.item[0] - 1;
  1845. val &= ~(0x07 << shift);
  1846. val |= nval << shift;
  1847. } else { /* spdif in */
  1848. nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
  1849. val &= ~(0x08 << shift);
  1850. val |= nval << shift;
  1851. }
  1852. if (val != old_val) {
  1853. change = 1;
  1854. outl(val, ICEMT(ice, ROUTE_CAPTURE));
  1855. }
  1856. spin_unlock_irq(&ice->reg_lock);
  1857. return change;
  1858. }
  1859. static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol,
  1860. struct snd_ctl_elem_value *ucontrol)
  1861. {
  1862. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1863. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1864. unsigned int val, cval;
  1865. val = inw(ICEMT(ice, ROUTE_SPDOUT));
  1866. cval = (val >> (idx * 4 + 8)) & 0x0f;
  1867. val = (val >> (idx * 2)) & 0x03;
  1868. if (val == 1)
  1869. ucontrol->value.enumerated.item[0] = 11;
  1870. else if (val == 2)
  1871. ucontrol->value.enumerated.item[0] = (cval & 7) + 1;
  1872. else if (val == 3)
  1873. ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9;
  1874. else
  1875. ucontrol->value.enumerated.item[0] = 0;
  1876. return 0;
  1877. }
  1878. static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol,
  1879. struct snd_ctl_elem_value *ucontrol)
  1880. {
  1881. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1882. int change, shift;
  1883. int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1884. unsigned int val, old_val, nval;
  1885. /* update SPDOUT */
  1886. spin_lock_irq(&ice->reg_lock);
  1887. val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT));
  1888. if (ucontrol->value.enumerated.item[0] >= 11)
  1889. nval = 1;
  1890. else if (ucontrol->value.enumerated.item[0] >= 9)
  1891. nval = 3;
  1892. else if (ucontrol->value.enumerated.item[0] >= 1)
  1893. nval = 2;
  1894. else
  1895. nval = 0;
  1896. shift = idx * 2;
  1897. val &= ~(0x03 << shift);
  1898. val |= nval << shift;
  1899. shift = idx * 4 + 8;
  1900. if (nval == 2) {
  1901. nval = ucontrol->value.enumerated.item[0] - 1;
  1902. val &= ~(0x07 << shift);
  1903. val |= nval << shift;
  1904. } else if (nval == 3) {
  1905. nval = (ucontrol->value.enumerated.item[0] - 9) << 3;
  1906. val &= ~(0x08 << shift);
  1907. val |= nval << shift;
  1908. }
  1909. change = val != old_val;
  1910. if (change)
  1911. outw(val, ICEMT(ice, ROUTE_SPDOUT));
  1912. spin_unlock_irq(&ice->reg_lock);
  1913. return change;
  1914. }
  1915. static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = {
  1916. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1917. .name = "H/W Playback Route",
  1918. .info = snd_ice1712_pro_route_info,
  1919. .get = snd_ice1712_pro_route_analog_get,
  1920. .put = snd_ice1712_pro_route_analog_put,
  1921. };
  1922. static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = {
  1923. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1924. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
  1925. .info = snd_ice1712_pro_route_info,
  1926. .get = snd_ice1712_pro_route_spdif_get,
  1927. .put = snd_ice1712_pro_route_spdif_put,
  1928. .count = 2,
  1929. };
  1930. static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol,
  1931. struct snd_ctl_elem_info *uinfo)
  1932. {
  1933. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1934. uinfo->count = 1;
  1935. uinfo->value.integer.min = 0;
  1936. uinfo->value.integer.max = 255;
  1937. return 0;
  1938. }
  1939. static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol,
  1940. struct snd_ctl_elem_value *ucontrol)
  1941. {
  1942. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1943. ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE));
  1944. return 0;
  1945. }
  1946. static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol,
  1947. struct snd_ctl_elem_value *ucontrol)
  1948. {
  1949. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1950. int change;
  1951. spin_lock_irq(&ice->reg_lock);
  1952. change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0];
  1953. outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE));
  1954. spin_unlock_irq(&ice->reg_lock);
  1955. return change;
  1956. }
  1957. static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = {
  1958. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1959. .name = "Multi Track Volume Rate",
  1960. .info = snd_ice1712_pro_volume_rate_info,
  1961. .get = snd_ice1712_pro_volume_rate_get,
  1962. .put = snd_ice1712_pro_volume_rate_put
  1963. };
  1964. static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol,
  1965. struct snd_ctl_elem_info *uinfo)
  1966. {
  1967. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1968. uinfo->count = 22;
  1969. uinfo->value.integer.min = 0;
  1970. uinfo->value.integer.max = 255;
  1971. return 0;
  1972. }
  1973. static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
  1974. struct snd_ctl_elem_value *ucontrol)
  1975. {
  1976. struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
  1977. int idx;
  1978. spin_lock_irq(&ice->reg_lock);
  1979. for (idx = 0; idx < 22; idx++) {
  1980. outb(idx, ICEMT(ice, MONITOR_PEAKINDEX));
  1981. ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA));
  1982. }
  1983. spin_unlock_irq(&ice->reg_lock);
  1984. return 0;
  1985. }
  1986. static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
  1987. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1988. .name = "Multi Track Peak",
  1989. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  1990. .info = snd_ice1712_pro_peak_info,
  1991. .get = snd_ice1712_pro_peak_get
  1992. };
  1993. /*
  1994. *
  1995. */
  1996. /*
  1997. * list of available boards
  1998. */
  1999. static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
  2000. snd_ice1712_hoontech_cards,
  2001. snd_ice1712_delta_cards,
  2002. snd_ice1712_ews_cards,
  2003. NULL,
  2004. };
  2005. static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice,
  2006. unsigned char dev,
  2007. unsigned char addr)
  2008. {
  2009. long t = 0x10000;
  2010. outb(addr, ICEREG(ice, I2C_BYTE_ADDR));
  2011. outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR));
  2012. while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ;
  2013. return inb(ICEREG(ice, I2C_DATA));
  2014. }
  2015. static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
  2016. const char *modelname)
  2017. {
  2018. int dev = 0xa0; /* EEPROM device address */
  2019. unsigned int i, size;
  2020. struct snd_ice1712_card_info * const *tbl, *c;
  2021. if (! modelname || ! *modelname) {
  2022. ice->eeprom.subvendor = 0;
  2023. if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0)
  2024. ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) |
  2025. (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) |
  2026. (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) |
  2027. (snd_ice1712_read_i2c(ice, dev, 0x03) << 24);
  2028. if (ice->eeprom.subvendor == 0 ||
  2029. ice->eeprom.subvendor == (unsigned int)-1) {
  2030. /* invalid subvendor from EEPROM, try the PCI subststem ID instead */
  2031. u16 vendor, device;
  2032. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor);
  2033. pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
  2034. ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
  2035. if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
  2036. printk(KERN_ERR "ice1712: No valid ID is found\n");
  2037. return -ENXIO;
  2038. }
  2039. }
  2040. }
  2041. for (tbl = card_tables; *tbl; tbl++) {
  2042. for (c = *tbl; c->subvendor; c++) {
  2043. if (modelname && c->model && ! strcmp(modelname, c->model)) {
  2044. printk(KERN_INFO "ice1712: Using board model %s\n", c->name);
  2045. ice->eeprom.subvendor = c->subvendor;
  2046. } else if (c->subvendor != ice->eeprom.subvendor)
  2047. continue;
  2048. if (! c->eeprom_size || ! c->eeprom_data)
  2049. goto found;
  2050. /* if the EEPROM is given by the driver, use it */
  2051. snd_printdd("using the defined eeprom..\n");
  2052. ice->eeprom.version = 1;
  2053. ice->eeprom.size = c->eeprom_size + 6;
  2054. memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
  2055. goto read_skipped;
  2056. }
  2057. }
  2058. printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n",
  2059. ice->eeprom.subvendor);
  2060. found:
  2061. ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04);
  2062. if (ice->eeprom.size < 6)
  2063. ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
  2064. else if (ice->eeprom.size > 32) {
  2065. snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
  2066. return -EIO;
  2067. }
  2068. ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
  2069. if (ice->eeprom.version != 1) {
  2070. snd_printk(KERN_ERR "invalid EEPROM version %i\n",
  2071. ice->eeprom.version);
  2072. /* return -EIO; */
  2073. }
  2074. size = ice->eeprom.size - 6;
  2075. for (i = 0; i < size; i++)
  2076. ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6);
  2077. read_skipped:
  2078. ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK];
  2079. ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE];
  2080. ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR];
  2081. return 0;
  2082. }
  2083. static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice)
  2084. {
  2085. outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL));
  2086. udelay(200);
  2087. outb(ICE1712_NATIVE, ICEREG(ice, CONTROL));
  2088. udelay(200);
  2089. if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE &&
  2090. !ice->dxr_enable)
  2091. /* Set eeprom value to limit active ADCs and DACs to 6;
  2092. * Also disable AC97 as no hardware in standard 6fire card/box
  2093. * Note: DXR extensions are not currently supported
  2094. */
  2095. ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a;
  2096. pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]);
  2097. pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]);
  2098. pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]);
  2099. pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]);
  2100. if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) {
  2101. ice->gpio.write_mask = ice->eeprom.gpiomask;
  2102. ice->gpio.direction = ice->eeprom.gpiodir;
  2103. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK,
  2104. ice->eeprom.gpiomask);
  2105. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
  2106. ice->eeprom.gpiodir);
  2107. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
  2108. ice->eeprom.gpiostate);
  2109. } else {
  2110. ice->gpio.write_mask = 0xc0;
  2111. ice->gpio.direction = 0xff;
  2112. snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0);
  2113. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff);
  2114. snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA,
  2115. ICE1712_STDSP24_CLOCK_BIT);
  2116. }
  2117. snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0);
  2118. if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) {
  2119. outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD));
  2120. udelay(100);
  2121. outb(0, ICEREG(ice, AC97_CMD));
  2122. udelay(200);
  2123. snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
  2124. }
  2125. snd_ice1712_set_pro_rate(ice, 48000, 1);
  2126. return 0;
  2127. }
  2128. int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice)
  2129. {
  2130. int err;
  2131. struct snd_kcontrol *kctl;
  2132. snd_assert(ice->pcm_pro != NULL, return -EIO);
  2133. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice));
  2134. if (err < 0)
  2135. return err;
  2136. kctl->id.device = ice->pcm_pro->device;
  2137. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice));
  2138. if (err < 0)
  2139. return err;
  2140. kctl->id.device = ice->pcm_pro->device;
  2141. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice));
  2142. if (err < 0)
  2143. return err;
  2144. kctl->id.device = ice->pcm_pro->device;
  2145. err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice));
  2146. if (err < 0)
  2147. return err;
  2148. kctl->id.device = ice->pcm_pro->device;
  2149. ice->spdif.stream_ctl = kctl;
  2150. return 0;
  2151. }
  2152. static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice)
  2153. {
  2154. int err;
  2155. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice));
  2156. if (err < 0)
  2157. return err;
  2158. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice));
  2159. if (err < 0)
  2160. return err;
  2161. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice));
  2162. if (err < 0)
  2163. return err;
  2164. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice));
  2165. if (err < 0)
  2166. return err;
  2167. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice));
  2168. if (err < 0)
  2169. return err;
  2170. if (ice->num_total_dacs > 0) {
  2171. struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route;
  2172. tmp.count = ice->num_total_dacs;
  2173. err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice));
  2174. if (err < 0)
  2175. return err;
  2176. }
  2177. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice));
  2178. if (err < 0)
  2179. return err;
  2180. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice));
  2181. if (err < 0)
  2182. return err;
  2183. err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice));
  2184. if (err < 0)
  2185. return err;
  2186. return 0;
  2187. }
  2188. static int snd_ice1712_free(struct snd_ice1712 *ice)
  2189. {
  2190. if (! ice->port)
  2191. goto __hw_end;
  2192. /* mask all interrupts */
  2193. outb(0xc0, ICEMT(ice, IRQ));
  2194. outb(0xff, ICEREG(ice, IRQMASK));
  2195. /* --- */
  2196. __hw_end:
  2197. if (ice->irq >= 0) {
  2198. synchronize_irq(ice->irq);
  2199. free_irq(ice->irq, ice);
  2200. }
  2201. if (ice->port)
  2202. pci_release_regions(ice->pci);
  2203. snd_ice1712_akm4xxx_free(ice);
  2204. pci_disable_device(ice->pci);
  2205. kfree(ice->spec);
  2206. kfree(ice);
  2207. return 0;
  2208. }
  2209. static int snd_ice1712_dev_free(struct snd_device *device)
  2210. {
  2211. struct snd_ice1712 *ice = device->device_data;
  2212. return snd_ice1712_free(ice);
  2213. }
  2214. static int __devinit snd_ice1712_create(struct snd_card *card,
  2215. struct pci_dev *pci,
  2216. const char *modelname,
  2217. int omni,
  2218. int cs8427_timeout,
  2219. int dxr_enable,
  2220. struct snd_ice1712 ** r_ice1712)
  2221. {
  2222. struct snd_ice1712 *ice;
  2223. int err;
  2224. static struct snd_device_ops ops = {
  2225. .dev_free = snd_ice1712_dev_free,
  2226. };
  2227. *r_ice1712 = NULL;
  2228. /* enable PCI device */
  2229. if ((err = pci_enable_device(pci)) < 0)
  2230. return err;
  2231. /* check, if we can restrict PCI DMA transfers to 28 bits */
  2232. if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
  2233. pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
  2234. snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
  2235. pci_disable_device(pci);
  2236. return -ENXIO;
  2237. }
  2238. ice = kzalloc(sizeof(*ice), GFP_KERNEL);
  2239. if (ice == NULL) {
  2240. pci_disable_device(pci);
  2241. return -ENOMEM;
  2242. }
  2243. ice->omni = omni ? 1 : 0;
  2244. if (cs8427_timeout < 1)
  2245. cs8427_timeout = 1;
  2246. else if (cs8427_timeout > 1000)
  2247. cs8427_timeout = 1000;
  2248. ice->cs8427_timeout = cs8427_timeout;
  2249. ice->dxr_enable = dxr_enable;
  2250. spin_lock_init(&ice->reg_lock);
  2251. mutex_init(&ice->gpio_mutex);
  2252. mutex_init(&ice->i2c_mutex);
  2253. mutex_init(&ice->open_mutex);
  2254. ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
  2255. ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
  2256. ice->gpio.set_data = snd_ice1712_set_gpio_data;
  2257. ice->gpio.get_data = snd_ice1712_get_gpio_data;
  2258. ice->spdif.cs8403_bits =
  2259. ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */
  2260. 0x10 | /* no emphasis */
  2261. 0x20); /* PCM encoder/decoder */
  2262. ice->card = card;
  2263. ice->pci = pci;
  2264. ice->irq = -1;
  2265. pci_set_master(pci);
  2266. pci_write_config_word(ice->pci, 0x40, 0x807f);
  2267. pci_write_config_word(ice->pci, 0x42, 0x0006);
  2268. snd_ice1712_proc_init(ice);
  2269. synchronize_irq(pci->irq);
  2270. if ((err = pci_request_regions(pci, "ICE1712")) < 0) {
  2271. kfree(ice);
  2272. pci_disable_device(pci);
  2273. return err;
  2274. }
  2275. ice->port = pci_resource_start(pci, 0);
  2276. ice->ddma_port = pci_resource_start(pci, 1);
  2277. ice->dmapath_port = pci_resource_start(pci, 2);
  2278. ice->profi_port = pci_resource_start(pci, 3);
  2279. if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED,
  2280. "ICE1712", ice)) {
  2281. snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
  2282. snd_ice1712_free(ice);
  2283. return -EIO;
  2284. }
  2285. ice->irq = pci->irq;
  2286. if (snd_ice1712_read_eeprom(ice, modelname) < 0) {
  2287. snd_ice1712_free(ice);
  2288. return -EIO;
  2289. }
  2290. if (snd_ice1712_chip_init(ice) < 0) {
  2291. snd_ice1712_free(ice);
  2292. return -EIO;
  2293. }
  2294. /* unmask used interrupts */
  2295. outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ?
  2296. ICE1712_IRQ_MPU2 : 0) |
  2297. ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ?
  2298. ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0),
  2299. ICEREG(ice, IRQMASK));
  2300. outb(0x00, ICEMT(ice, IRQ));
  2301. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops)) < 0) {
  2302. snd_ice1712_free(ice);
  2303. return err;
  2304. }
  2305. snd_card_set_dev(card, &pci->dev);
  2306. *r_ice1712 = ice;
  2307. return 0;
  2308. }
  2309. /*
  2310. *
  2311. * Registration
  2312. *
  2313. */
  2314. static struct snd_ice1712_card_info no_matched __devinitdata;
  2315. static int __devinit snd_ice1712_probe(struct pci_dev *pci,
  2316. const struct pci_device_id *pci_id)
  2317. {
  2318. static int dev;
  2319. struct snd_card *card;
  2320. struct snd_ice1712 *ice;
  2321. int pcm_dev = 0, err;
  2322. struct snd_ice1712_card_info * const *tbl, *c;
  2323. if (dev >= SNDRV_CARDS)
  2324. return -ENODEV;
  2325. if (!enable[dev]) {
  2326. dev++;
  2327. return -ENOENT;
  2328. }
  2329. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  2330. if (card == NULL)
  2331. return -ENOMEM;
  2332. strcpy(card->driver, "ICE1712");
  2333. strcpy(card->shortname, "ICEnsemble ICE1712");
  2334. if ((err = snd_ice1712_create(card, pci, model[dev], omni[dev],
  2335. cs8427_timeout[dev], dxr_enable[dev],
  2336. &ice)) < 0) {
  2337. snd_card_free(card);
  2338. return err;
  2339. }
  2340. for (tbl = card_tables; *tbl; tbl++) {
  2341. for (c = *tbl; c->subvendor; c++) {
  2342. if (c->subvendor == ice->eeprom.subvendor) {
  2343. strcpy(card->shortname, c->name);
  2344. if (c->driver) /* specific driver? */
  2345. strcpy(card->driver, c->driver);
  2346. if (c->chip_init) {
  2347. if ((err = c->chip_init(ice)) < 0) {
  2348. snd_card_free(card);
  2349. return err;
  2350. }
  2351. }
  2352. goto __found;
  2353. }
  2354. }
  2355. }
  2356. c = &no_matched;
  2357. __found:
  2358. if ((err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL)) < 0) {
  2359. snd_card_free(card);
  2360. return err;
  2361. }
  2362. if (ice_has_con_ac97(ice))
  2363. if ((err = snd_ice1712_pcm(ice, pcm_dev++, NULL)) < 0) {
  2364. snd_card_free(card);
  2365. return err;
  2366. }
  2367. if ((err = snd_ice1712_ac97_mixer(ice)) < 0) {
  2368. snd_card_free(card);
  2369. return err;
  2370. }
  2371. if ((err = snd_ice1712_build_controls(ice)) < 0) {
  2372. snd_card_free(card);
  2373. return err;
  2374. }
  2375. if (c->build_controls) {
  2376. if ((err = c->build_controls(ice)) < 0) {
  2377. snd_card_free(card);
  2378. return err;
  2379. }
  2380. }
  2381. if (ice_has_con_ac97(ice))
  2382. if ((err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL)) < 0) {
  2383. snd_card_free(card);
  2384. return err;
  2385. }
  2386. if (! c->no_mpu401) {
  2387. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
  2388. ICEREG(ice, MPU1_CTRL),
  2389. (c->mpu401_1_info_flags |
  2390. MPU401_INFO_INTEGRATED),
  2391. ice->irq, 0,
  2392. &ice->rmidi[0])) < 0) {
  2393. snd_card_free(card);
  2394. return err;
  2395. }
  2396. if (c->mpu401_1_name)
  2397. /* Prefered name available in card_info */
  2398. snprintf(ice->rmidi[0]->name,
  2399. sizeof(ice->rmidi[0]->name),
  2400. "%s %d", c->mpu401_1_name, card->number);
  2401. if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) {
  2402. /* 2nd port used */
  2403. if ((err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
  2404. ICEREG(ice, MPU2_CTRL),
  2405. (c->mpu401_2_info_flags |
  2406. MPU401_INFO_INTEGRATED),
  2407. ice->irq, 0,
  2408. &ice->rmidi[1])) < 0) {
  2409. snd_card_free(card);
  2410. return err;
  2411. }
  2412. if (c->mpu401_2_name)
  2413. /* Prefered name available in card_info */
  2414. snprintf(ice->rmidi[1]->name,
  2415. sizeof(ice->rmidi[1]->name),
  2416. "%s %d", c->mpu401_2_name,
  2417. card->number);
  2418. }
  2419. }
  2420. snd_ice1712_set_input_clock_source(ice, 0);
  2421. sprintf(card->longname, "%s at 0x%lx, irq %i",
  2422. card->shortname, ice->port, ice->irq);
  2423. if ((err = snd_card_register(card)) < 0) {
  2424. snd_card_free(card);
  2425. return err;
  2426. }
  2427. pci_set_drvdata(pci, card);
  2428. dev++;
  2429. return 0;
  2430. }
  2431. static void __devexit snd_ice1712_remove(struct pci_dev *pci)
  2432. {
  2433. snd_card_free(pci_get_drvdata(pci));
  2434. pci_set_drvdata(pci, NULL);
  2435. }
  2436. static struct pci_driver driver = {
  2437. .name = "ICE1712",
  2438. .id_table = snd_ice1712_ids,
  2439. .probe = snd_ice1712_probe,
  2440. .remove = __devexit_p(snd_ice1712_remove),
  2441. };
  2442. static int __init alsa_card_ice1712_init(void)
  2443. {
  2444. return pci_register_driver(&driver);
  2445. }
  2446. static void __exit alsa_card_ice1712_exit(void)
  2447. {
  2448. pci_unregister_driver(&driver);
  2449. }
  2450. module_init(alsa_card_ice1712_init)
  2451. module_exit(alsa_card_ice1712_exit)