ice1712.c 83 KB

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