ice1712.c 79 KB

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