ice1712.c 79 KB

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