ice1712.c 82 KB

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