ac97_patch.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Universal interface for Audio Codec '97
  4. *
  5. * For more details look to AC '97 component specification revision 2.2
  6. * by Intel Corporation (http://developer.intel.com) and to datasheets
  7. * for specific codecs.
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #include "ac97_local.h"
  26. #include "ac97_patch.h"
  27. /*
  28. * Chip specific initialization
  29. */
  30. static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
  31. {
  32. int idx, err;
  33. for (idx = 0; idx < count; idx++)
  34. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
  35. return err;
  36. return 0;
  37. }
  38. /* replace with a new TLV */
  39. static void reset_tlv(struct snd_ac97 *ac97, const char *name,
  40. const unsigned int *tlv)
  41. {
  42. struct snd_ctl_elem_id sid;
  43. struct snd_kcontrol *kctl;
  44. memset(&sid, 0, sizeof(sid));
  45. strcpy(sid.name, name);
  46. sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  47. kctl = snd_ctl_find_id(ac97->bus->card, &sid);
  48. if (kctl && kctl->tlv.p)
  49. kctl->tlv.p = tlv;
  50. }
  51. /* set to the page, update bits and restore the page */
  52. static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
  53. {
  54. unsigned short page_save;
  55. int ret;
  56. mutex_lock(&ac97->page_mutex);
  57. page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
  58. snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
  59. ret = snd_ac97_update_bits(ac97, reg, mask, value);
  60. snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
  61. mutex_unlock(&ac97->page_mutex); /* unlock paging */
  62. return ret;
  63. }
  64. /*
  65. * shared line-in/mic controls
  66. */
  67. static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
  68. const char **texts, unsigned int nums)
  69. {
  70. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  71. uinfo->count = 1;
  72. uinfo->value.enumerated.items = nums;
  73. if (uinfo->value.enumerated.item > nums - 1)
  74. uinfo->value.enumerated.item = nums - 1;
  75. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  76. return 0;
  77. }
  78. static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  79. {
  80. static const char *texts[] = { "Shared", "Independent" };
  81. return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
  82. }
  83. static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  84. {
  85. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  86. ucontrol->value.enumerated.item[0] = ac97->indep_surround;
  87. return 0;
  88. }
  89. static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  90. {
  91. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  92. unsigned char indep = !!ucontrol->value.enumerated.item[0];
  93. if (indep != ac97->indep_surround) {
  94. ac97->indep_surround = indep;
  95. if (ac97->build_ops->update_jacks)
  96. ac97->build_ops->update_jacks(ac97);
  97. return 1;
  98. }
  99. return 0;
  100. }
  101. static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  102. {
  103. static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" };
  104. return ac97_enum_text_info(kcontrol, uinfo, texts,
  105. kcontrol->private_value);
  106. }
  107. static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  108. {
  109. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  110. ucontrol->value.enumerated.item[0] = ac97->channel_mode;
  111. return 0;
  112. }
  113. static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  114. {
  115. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  116. unsigned char mode = ucontrol->value.enumerated.item[0];
  117. if (mode >= kcontrol->private_value)
  118. return -EINVAL;
  119. if (mode != ac97->channel_mode) {
  120. ac97->channel_mode = mode;
  121. if (ac97->build_ops->update_jacks)
  122. ac97->build_ops->update_jacks(ac97);
  123. return 1;
  124. }
  125. return 0;
  126. }
  127. #define AC97_SURROUND_JACK_MODE_CTL \
  128. { \
  129. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  130. .name = "Surround Jack Mode", \
  131. .info = ac97_surround_jack_mode_info, \
  132. .get = ac97_surround_jack_mode_get, \
  133. .put = ac97_surround_jack_mode_put, \
  134. }
  135. /* 6ch */
  136. #define AC97_CHANNEL_MODE_CTL \
  137. { \
  138. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  139. .name = "Channel Mode", \
  140. .info = ac97_channel_mode_info, \
  141. .get = ac97_channel_mode_get, \
  142. .put = ac97_channel_mode_put, \
  143. .private_value = 3, \
  144. }
  145. /* 4ch */
  146. #define AC97_CHANNEL_MODE_4CH_CTL \
  147. { \
  148. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  149. .name = "Channel Mode", \
  150. .info = ac97_channel_mode_info, \
  151. .get = ac97_channel_mode_get, \
  152. .put = ac97_channel_mode_put, \
  153. .private_value = 2, \
  154. }
  155. /* 8ch */
  156. #define AC97_CHANNEL_MODE_8CH_CTL \
  157. { \
  158. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  159. .name = "Channel Mode", \
  160. .info = ac97_channel_mode_info, \
  161. .get = ac97_channel_mode_get, \
  162. .put = ac97_channel_mode_put, \
  163. .private_value = 4, \
  164. }
  165. static inline int is_surround_on(struct snd_ac97 *ac97)
  166. {
  167. return ac97->channel_mode >= 1;
  168. }
  169. static inline int is_clfe_on(struct snd_ac97 *ac97)
  170. {
  171. return ac97->channel_mode >= 2;
  172. }
  173. /* system has shared jacks with surround out enabled */
  174. static inline int is_shared_surrout(struct snd_ac97 *ac97)
  175. {
  176. return !ac97->indep_surround && is_surround_on(ac97);
  177. }
  178. /* system has shared jacks with center/lfe out enabled */
  179. static inline int is_shared_clfeout(struct snd_ac97 *ac97)
  180. {
  181. return !ac97->indep_surround && is_clfe_on(ac97);
  182. }
  183. /* system has shared jacks with line in enabled */
  184. static inline int is_shared_linein(struct snd_ac97 *ac97)
  185. {
  186. return !ac97->indep_surround && !is_surround_on(ac97);
  187. }
  188. /* system has shared jacks with mic in enabled */
  189. static inline int is_shared_micin(struct snd_ac97 *ac97)
  190. {
  191. return !ac97->indep_surround && !is_clfe_on(ac97);
  192. }
  193. static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
  194. {
  195. return is_surround_on(ac97);
  196. }
  197. /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
  198. /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
  199. /* It is possible to indicate to the Yamaha YMF7x3 the type of
  200. speakers being used. */
  201. static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
  202. struct snd_ctl_elem_info *uinfo)
  203. {
  204. static char *texts[3] = {
  205. "Standard", "Small", "Smaller"
  206. };
  207. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  208. uinfo->count = 1;
  209. uinfo->value.enumerated.items = 3;
  210. if (uinfo->value.enumerated.item > 2)
  211. uinfo->value.enumerated.item = 2;
  212. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  213. return 0;
  214. }
  215. static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
  216. struct snd_ctl_elem_value *ucontrol)
  217. {
  218. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  219. unsigned short val;
  220. val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
  221. val = (val >> 10) & 3;
  222. if (val > 0) /* 0 = invalid */
  223. val--;
  224. ucontrol->value.enumerated.item[0] = val;
  225. return 0;
  226. }
  227. static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
  228. struct snd_ctl_elem_value *ucontrol)
  229. {
  230. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  231. unsigned short val;
  232. if (ucontrol->value.enumerated.item[0] > 2)
  233. return -EINVAL;
  234. val = (ucontrol->value.enumerated.item[0] + 1) << 10;
  235. return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
  236. }
  237. static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
  238. {
  239. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  240. .name = "3D Control - Speaker",
  241. .info = snd_ac97_ymf7x3_info_speaker,
  242. .get = snd_ac97_ymf7x3_get_speaker,
  243. .put = snd_ac97_ymf7x3_put_speaker,
  244. };
  245. /* It is possible to indicate to the Yamaha YMF7x3 the source to
  246. direct to the S/PDIF output. */
  247. static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
  248. struct snd_ctl_elem_info *uinfo)
  249. {
  250. static char *texts[2] = { "AC-Link", "A/D Converter" };
  251. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  252. uinfo->count = 1;
  253. uinfo->value.enumerated.items = 2;
  254. if (uinfo->value.enumerated.item > 1)
  255. uinfo->value.enumerated.item = 1;
  256. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  257. return 0;
  258. }
  259. static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
  260. struct snd_ctl_elem_value *ucontrol)
  261. {
  262. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  263. unsigned short val;
  264. val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
  265. ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
  266. return 0;
  267. }
  268. static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
  269. struct snd_ctl_elem_value *ucontrol)
  270. {
  271. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  272. unsigned short val;
  273. if (ucontrol->value.enumerated.item[0] > 1)
  274. return -EINVAL;
  275. val = ucontrol->value.enumerated.item[0] << 1;
  276. return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
  277. }
  278. static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
  279. {
  280. struct snd_kcontrol *kctl;
  281. int err;
  282. kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
  283. err = snd_ctl_add(ac97->bus->card, kctl);
  284. if (err < 0)
  285. return err;
  286. strcpy(kctl->id.name, "3D Control - Wide");
  287. kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
  288. snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
  289. err = snd_ctl_add(ac97->bus->card,
  290. snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
  291. ac97));
  292. if (err < 0)
  293. return err;
  294. snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
  295. return 0;
  296. }
  297. static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
  298. {
  299. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
  300. AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
  301. {
  302. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  303. .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
  304. .info = snd_ac97_ymf7x3_spdif_source_info,
  305. .get = snd_ac97_ymf7x3_spdif_source_get,
  306. .put = snd_ac97_ymf7x3_spdif_source_put,
  307. },
  308. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
  309. AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
  310. };
  311. static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
  312. {
  313. int err;
  314. err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
  315. if (err < 0)
  316. return err;
  317. err = patch_build_controls(ac97,
  318. snd_ac97_yamaha_ymf743_controls_spdif, 3);
  319. if (err < 0)
  320. return err;
  321. /* set default PCM S/PDIF params */
  322. /* PCM audio,no copyright,no preemphasis,PCM coder,original */
  323. snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
  324. return 0;
  325. }
  326. static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
  327. .build_spdif = patch_yamaha_ymf743_build_spdif,
  328. .build_3d = patch_yamaha_ymf7x3_3d,
  329. };
  330. static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
  331. {
  332. ac97->build_ops = &patch_yamaha_ymf743_ops;
  333. ac97->caps |= AC97_BC_BASS_TREBLE;
  334. ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
  335. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
  336. ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
  337. return 0;
  338. }
  339. /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
  340. The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
  341. By default, no output pin is selected, and the S/PDIF signal is not output.
  342. There is also a bit to mute S/PDIF output in a vendor-specific register. */
  343. static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  344. {
  345. static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
  346. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  347. uinfo->count = 1;
  348. uinfo->value.enumerated.items = 3;
  349. if (uinfo->value.enumerated.item > 2)
  350. uinfo->value.enumerated.item = 2;
  351. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  352. return 0;
  353. }
  354. static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  355. {
  356. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  357. unsigned short val;
  358. val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
  359. ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
  360. return 0;
  361. }
  362. static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  363. {
  364. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  365. unsigned short val;
  366. if (ucontrol->value.enumerated.item[0] > 2)
  367. return -EINVAL;
  368. val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
  369. (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
  370. return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
  371. /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
  372. snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
  373. }
  374. static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
  375. {
  376. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  377. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  378. .info = snd_ac97_ymf7x3_spdif_source_info,
  379. .get = snd_ac97_ymf7x3_spdif_source_get,
  380. .put = snd_ac97_ymf7x3_spdif_source_put,
  381. },
  382. {
  383. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  384. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
  385. .info = snd_ac97_ymf753_spdif_output_pin_info,
  386. .get = snd_ac97_ymf753_spdif_output_pin_get,
  387. .put = snd_ac97_ymf753_spdif_output_pin_put,
  388. },
  389. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
  390. AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
  391. };
  392. static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
  393. {
  394. int err;
  395. if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
  396. return err;
  397. return 0;
  398. }
  399. static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
  400. .build_3d = patch_yamaha_ymf7x3_3d,
  401. .build_post_spdif = patch_yamaha_ymf753_post_spdif
  402. };
  403. static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
  404. {
  405. /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
  406. This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
  407. The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
  408. The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
  409. By default, no output pin is selected, and the S/PDIF signal is not output.
  410. There is also a bit to mute S/PDIF output in a vendor-specific register.
  411. */
  412. ac97->build_ops = &patch_yamaha_ymf753_ops;
  413. ac97->caps |= AC97_BC_BASS_TREBLE;
  414. ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
  415. return 0;
  416. }
  417. /*
  418. * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
  419. * removed broken wolfson00 patch.
  420. * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
  421. */
  422. static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
  423. AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
  424. AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
  425. };
  426. static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
  427. {
  428. /* This is known to work for the ViewSonic ViewPad 1000
  429. * Randolph Bentson <bentson@holmsjoen.com>
  430. * WM9703/9707/9708/9717
  431. */
  432. int err, i;
  433. for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
  434. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
  435. return err;
  436. }
  437. snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
  438. return 0;
  439. }
  440. static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
  441. .build_specific = patch_wolfson_wm9703_specific,
  442. };
  443. static int patch_wolfson03(struct snd_ac97 * ac97)
  444. {
  445. ac97->build_ops = &patch_wolfson_wm9703_ops;
  446. return 0;
  447. }
  448. static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
  449. AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
  450. AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
  451. AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
  452. AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
  453. AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
  454. AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
  455. };
  456. static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
  457. {
  458. int err, i;
  459. for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
  460. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
  461. return err;
  462. }
  463. /* patch for DVD noise */
  464. snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
  465. return 0;
  466. }
  467. static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
  468. .build_specific = patch_wolfson_wm9704_specific,
  469. };
  470. static int patch_wolfson04(struct snd_ac97 * ac97)
  471. {
  472. /* WM9704M/9704Q */
  473. ac97->build_ops = &patch_wolfson_wm9704_ops;
  474. return 0;
  475. }
  476. static int patch_wolfson05(struct snd_ac97 * ac97)
  477. {
  478. /* WM9705, WM9710 */
  479. ac97->build_ops = &patch_wolfson_wm9703_ops;
  480. #ifdef CONFIG_TOUCHSCREEN_WM9705
  481. /* WM9705 touchscreen uses AUX and VIDEO for touch */
  482. ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
  483. #endif
  484. return 0;
  485. }
  486. static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
  487. static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
  488. static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
  489. static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
  490. static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
  491. static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
  492. static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
  493. static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
  494. static const char* wm9711_rec_sel[] =
  495. {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
  496. static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
  497. static const struct ac97_enum wm9711_enum[] = {
  498. AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
  499. AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
  500. AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
  501. AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
  502. AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
  503. AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
  504. AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
  505. AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
  506. AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
  507. AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
  508. };
  509. static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
  510. AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
  511. AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
  512. AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
  513. AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
  514. AC97_ENUM("ALC Function", wm9711_enum[0]),
  515. AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
  516. AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
  517. AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
  518. AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
  519. AC97_ENUM("ALC NG Type", wm9711_enum[9]),
  520. AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
  521. AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
  522. AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
  523. AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
  524. AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
  525. AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
  526. AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
  527. AC97_ENUM("Out3 Mux", wm9711_enum[2]),
  528. AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
  529. AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
  530. AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
  531. AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
  532. AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
  533. AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
  534. AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
  535. AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
  536. AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
  537. AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
  538. AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
  539. AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
  540. AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
  541. AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
  542. AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
  543. AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
  544. AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
  545. AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
  546. AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
  547. AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
  548. AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
  549. AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
  550. AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
  551. AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
  552. AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
  553. AC97_ENUM("Capture Select", wm9711_enum[8]),
  554. AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
  555. AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
  556. AC97_ENUM("Bass Control", wm9711_enum[5]),
  557. AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
  558. AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
  559. AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
  560. AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
  561. AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
  562. AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
  563. AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
  564. AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
  565. AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
  566. AC97_ENUM("Mic Select Source", wm9711_enum[7]),
  567. AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
  568. AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
  569. AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
  570. AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
  571. AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
  572. AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
  573. AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
  574. };
  575. static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
  576. {
  577. int err, i;
  578. for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
  579. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
  580. return err;
  581. }
  582. snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
  583. snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
  584. snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
  585. snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
  586. snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
  587. snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
  588. return 0;
  589. }
  590. static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
  591. .build_specific = patch_wolfson_wm9711_specific,
  592. };
  593. static int patch_wolfson11(struct snd_ac97 * ac97)
  594. {
  595. /* WM9711, WM9712 */
  596. ac97->build_ops = &patch_wolfson_wm9711_ops;
  597. ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
  598. AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
  599. return 0;
  600. }
  601. static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
  602. static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
  603. static const char* wm9713_rec_src[] =
  604. {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
  605. "Mono Mix", "Zh"};
  606. static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
  607. static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
  608. static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
  609. static const char* wm9713_spk_pga[] =
  610. {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
  611. static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
  612. static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
  613. static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
  614. static const char* wm9713_dac_inv[] =
  615. {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
  616. "Headphone Mix Mono", "NC", "Vmid"};
  617. static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
  618. static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
  619. static const struct ac97_enum wm9713_enum[] = {
  620. AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
  621. AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
  622. AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
  623. AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
  624. AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
  625. AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
  626. AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
  627. AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
  628. AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
  629. AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
  630. AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
  631. AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
  632. AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
  633. AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
  634. };
  635. static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
  636. AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
  637. AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
  638. AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
  639. AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
  640. AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
  641. AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
  642. AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
  643. AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
  644. AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
  645. AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
  646. AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
  647. AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
  648. AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
  649. AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
  650. AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
  651. AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
  652. AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
  653. AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
  654. AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
  655. AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
  656. AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
  657. AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
  658. AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
  659. AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
  660. AC97_ENUM("Capture Select", wm9713_enum[3]),
  661. AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
  662. AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
  663. AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
  664. AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
  665. AC97_ENUM("ALC Function", wm9713_enum[5]),
  666. AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
  667. AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
  668. AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
  669. AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
  670. AC97_ENUM("ALC NG Type", wm9713_enum[13]),
  671. AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
  672. AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
  673. AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
  674. AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
  675. AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
  676. AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
  677. AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
  678. AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
  679. AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
  680. AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
  681. AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
  682. AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
  683. AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
  684. AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
  685. AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
  686. AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
  687. AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
  688. AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
  689. AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
  690. AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
  691. AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
  692. AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
  693. AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
  694. AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
  695. AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
  696. AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
  697. AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
  698. AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
  699. AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
  700. AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
  701. AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
  702. AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
  703. AC97_ENUM("Master Input Mux", wm9713_enum[7]),
  704. AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
  705. AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
  706. AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
  707. AC97_ENUM("Bass Control", wm9713_enum[12]),
  708. AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
  709. AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
  710. AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
  711. AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
  712. AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
  713. };
  714. static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
  715. AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
  716. AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
  717. AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
  718. AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
  719. };
  720. static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
  721. {
  722. int err, i;
  723. for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
  724. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
  725. return err;
  726. }
  727. return 0;
  728. }
  729. static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
  730. {
  731. int err, i;
  732. for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
  733. if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
  734. return err;
  735. }
  736. snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
  737. snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
  738. snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
  739. snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
  740. snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
  741. snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
  742. snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
  743. return 0;
  744. }
  745. #ifdef CONFIG_PM
  746. static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
  747. {
  748. snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
  749. snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
  750. }
  751. static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
  752. {
  753. snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
  754. snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
  755. snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
  756. }
  757. #endif
  758. static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
  759. .build_specific = patch_wolfson_wm9713_specific,
  760. .build_3d = patch_wolfson_wm9713_3d,
  761. #ifdef CONFIG_PM
  762. .suspend = patch_wolfson_wm9713_suspend,
  763. .resume = patch_wolfson_wm9713_resume
  764. #endif
  765. };
  766. static int patch_wolfson13(struct snd_ac97 * ac97)
  767. {
  768. /* WM9713, WM9714 */
  769. ac97->build_ops = &patch_wolfson_wm9713_ops;
  770. ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
  771. AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
  772. AC97_HAS_NO_STD_PCM;
  773. ac97->scaps &= ~AC97_SCAP_MODEM;
  774. snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
  775. snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
  776. snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
  777. return 0;
  778. }
  779. /*
  780. * Tritech codec
  781. */
  782. static int patch_tritech_tr28028(struct snd_ac97 * ac97)
  783. {
  784. snd_ac97_write_cache(ac97, 0x26, 0x0300);
  785. snd_ac97_write_cache(ac97, 0x26, 0x0000);
  786. snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
  787. snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
  788. return 0;
  789. }
  790. /*
  791. * Sigmatel STAC97xx codecs
  792. */
  793. static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
  794. {
  795. struct snd_kcontrol *kctl;
  796. int err;
  797. if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
  798. return err;
  799. strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
  800. kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
  801. snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
  802. return 0;
  803. }
  804. static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
  805. {
  806. struct snd_kcontrol *kctl;
  807. int err;
  808. if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
  809. return err;
  810. strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
  811. kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
  812. if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
  813. return err;
  814. strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
  815. kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
  816. snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
  817. return 0;
  818. }
  819. static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
  820. AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
  821. AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
  822. /* "Sigmatel " removed due to excessive name length: */
  823. static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
  824. AC97_SINGLE("Surround Phase Inversion Playback Switch",
  825. AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
  826. static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
  827. AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
  828. AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
  829. };
  830. static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
  831. {
  832. int err;
  833. snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
  834. if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
  835. if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
  836. return err;
  837. if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
  838. if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
  839. return err;
  840. if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
  841. if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
  842. return err;
  843. if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
  844. if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
  845. return err;
  846. return 0;
  847. }
  848. static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
  849. .build_3d = patch_sigmatel_stac9700_3d,
  850. .build_specific = patch_sigmatel_stac97xx_specific
  851. };
  852. static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
  853. {
  854. ac97->build_ops = &patch_sigmatel_stac9700_ops;
  855. return 0;
  856. }
  857. static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  858. {
  859. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  860. int err;
  861. mutex_lock(&ac97->page_mutex);
  862. snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
  863. err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
  864. (ucontrol->value.integer.value[0] & 1) << 4);
  865. snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
  866. mutex_unlock(&ac97->page_mutex);
  867. return err;
  868. }
  869. static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
  870. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  871. .name = "Sigmatel Output Bias Switch",
  872. .info = snd_ac97_info_volsw,
  873. .get = snd_ac97_get_volsw,
  874. .put = snd_ac97_stac9708_put_bias,
  875. .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
  876. };
  877. static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
  878. {
  879. int err;
  880. /* the register bit is writable, but the function is not implemented: */
  881. snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
  882. snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
  883. if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
  884. return err;
  885. return patch_sigmatel_stac97xx_specific(ac97);
  886. }
  887. static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
  888. .build_3d = patch_sigmatel_stac9708_3d,
  889. .build_specific = patch_sigmatel_stac9708_specific
  890. };
  891. static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
  892. {
  893. unsigned int codec72, codec6c;
  894. ac97->build_ops = &patch_sigmatel_stac9708_ops;
  895. ac97->caps |= 0x10; /* HP (sigmatel surround) support */
  896. codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
  897. codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
  898. if ((codec72==0) && (codec6c==0)) {
  899. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
  900. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
  901. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
  902. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
  903. } else if ((codec72==0x8000) && (codec6c==0)) {
  904. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
  905. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
  906. snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
  907. } else if ((codec72==0x8000) && (codec6c==0x0080)) {
  908. /* nothing */
  909. }
  910. snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
  911. return 0;
  912. }
  913. static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
  914. {
  915. ac97->build_ops = &patch_sigmatel_stac9700_ops;
  916. if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
  917. // patch for SigmaTel
  918. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
  919. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
  920. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
  921. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
  922. }
  923. snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
  924. return 0;
  925. }
  926. static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
  927. {
  928. // patch for SigmaTel
  929. ac97->build_ops = &patch_sigmatel_stac9700_ops;
  930. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
  931. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
  932. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
  933. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
  934. snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
  935. return 0;
  936. }
  937. static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
  938. {
  939. // patch for SigmaTel
  940. ac97->build_ops = &patch_sigmatel_stac9700_ops;
  941. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
  942. snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
  943. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
  944. snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
  945. snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
  946. return 0;
  947. }
  948. static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  949. {
  950. static char *texts[5] = { "Input/Disabled", "Front Output",
  951. "Rear Output", "Center/LFE Output", "Mixer Output" };
  952. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  953. uinfo->count = 1;
  954. uinfo->value.enumerated.items = 5;
  955. if (uinfo->value.enumerated.item > 4)
  956. uinfo->value.enumerated.item = 4;
  957. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  958. return 0;
  959. }
  960. static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  961. {
  962. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  963. int shift = kcontrol->private_value;
  964. unsigned short val;
  965. val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
  966. if (!(val & 4))
  967. ucontrol->value.enumerated.item[0] = 0;
  968. else
  969. ucontrol->value.enumerated.item[0] = 1 + (val & 3);
  970. return 0;
  971. }
  972. static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  973. {
  974. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  975. int shift = kcontrol->private_value;
  976. unsigned short val;
  977. if (ucontrol->value.enumerated.item[0] > 4)
  978. return -EINVAL;
  979. if (ucontrol->value.enumerated.item[0] == 0)
  980. val = 0;
  981. else
  982. val = 4 | (ucontrol->value.enumerated.item[0] - 1);
  983. return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
  984. 7 << shift, val << shift, 0);
  985. }
  986. static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  987. {
  988. static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
  989. "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
  990. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  991. uinfo->count = 1;
  992. uinfo->value.enumerated.items = 7;
  993. if (uinfo->value.enumerated.item > 6)
  994. uinfo->value.enumerated.item = 6;
  995. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  996. return 0;
  997. }
  998. static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  999. {
  1000. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1001. int shift = kcontrol->private_value;
  1002. unsigned short val;
  1003. val = ac97->regs[AC97_SIGMATEL_INSEL];
  1004. ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
  1005. return 0;
  1006. }
  1007. static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1008. {
  1009. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1010. int shift = kcontrol->private_value;
  1011. return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
  1012. ucontrol->value.enumerated.item[0] << shift, 0);
  1013. }
  1014. static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1015. {
  1016. static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
  1017. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1018. uinfo->count = 1;
  1019. uinfo->value.enumerated.items = 3;
  1020. if (uinfo->value.enumerated.item > 2)
  1021. uinfo->value.enumerated.item = 2;
  1022. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1023. return 0;
  1024. }
  1025. static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1026. {
  1027. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1028. ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
  1029. return 0;
  1030. }
  1031. static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1032. {
  1033. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1034. return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
  1035. ucontrol->value.enumerated.item[0], 0);
  1036. }
  1037. #define STAC9758_OUTPUT_JACK(xname, shift) \
  1038. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1039. .info = snd_ac97_stac9758_output_jack_info, \
  1040. .get = snd_ac97_stac9758_output_jack_get, \
  1041. .put = snd_ac97_stac9758_output_jack_put, \
  1042. .private_value = shift }
  1043. #define STAC9758_INPUT_JACK(xname, shift) \
  1044. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1045. .info = snd_ac97_stac9758_input_jack_info, \
  1046. .get = snd_ac97_stac9758_input_jack_get, \
  1047. .put = snd_ac97_stac9758_input_jack_put, \
  1048. .private_value = shift }
  1049. static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
  1050. STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
  1051. STAC9758_OUTPUT_JACK("LineIn Jack", 4),
  1052. STAC9758_OUTPUT_JACK("Front Jack", 7),
  1053. STAC9758_OUTPUT_JACK("Rear Jack", 10),
  1054. STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
  1055. STAC9758_INPUT_JACK("Mic Input Source", 0),
  1056. STAC9758_INPUT_JACK("Line Input Source", 8),
  1057. {
  1058. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1059. .name = "Headphone Amp",
  1060. .info = snd_ac97_stac9758_phonesel_info,
  1061. .get = snd_ac97_stac9758_phonesel_get,
  1062. .put = snd_ac97_stac9758_phonesel_put
  1063. },
  1064. AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
  1065. AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
  1066. };
  1067. static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
  1068. {
  1069. int err;
  1070. err = patch_sigmatel_stac97xx_specific(ac97);
  1071. if (err < 0)
  1072. return err;
  1073. err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
  1074. ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
  1075. if (err < 0)
  1076. return err;
  1077. /* DAC-A direct */
  1078. snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
  1079. /* DAC-A to Mix = PCM */
  1080. /* DAC-B direct = Surround */
  1081. /* DAC-B to Mix */
  1082. snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
  1083. /* DAC-C direct = Center/LFE */
  1084. return 0;
  1085. }
  1086. static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
  1087. .build_3d = patch_sigmatel_stac9700_3d,
  1088. .build_specific = patch_sigmatel_stac9758_specific
  1089. };
  1090. static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
  1091. {
  1092. static unsigned short regs[4] = {
  1093. AC97_SIGMATEL_OUTSEL,
  1094. AC97_SIGMATEL_IOMISC,
  1095. AC97_SIGMATEL_INSEL,
  1096. AC97_SIGMATEL_VARIOUS
  1097. };
  1098. static unsigned short def_regs[4] = {
  1099. /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
  1100. /* IOMISC */ 0x2001,
  1101. /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
  1102. /* VARIOUS */ 0x0040
  1103. };
  1104. static unsigned short m675_regs[4] = {
  1105. /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
  1106. /* IOMISC */ 0x2102, /* HP amp on */
  1107. /* INSEL */ 0x0203, /* LI:LI, MI:FR */
  1108. /* VARIOUS */ 0x0041 /* stereo mic */
  1109. };
  1110. unsigned short *pregs = def_regs;
  1111. int i;
  1112. /* Gateway M675 notebook */
  1113. if (ac97->pci &&
  1114. ac97->subsystem_vendor == 0x107b &&
  1115. ac97->subsystem_device == 0x0601)
  1116. pregs = m675_regs;
  1117. // patch for SigmaTel
  1118. ac97->build_ops = &patch_sigmatel_stac9758_ops;
  1119. /* FIXME: assume only page 0 for writing cache */
  1120. snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
  1121. for (i = 0; i < 4; i++)
  1122. snd_ac97_write_cache(ac97, regs[i], pregs[i]);
  1123. ac97->flags |= AC97_STEREO_MUTES;
  1124. return 0;
  1125. }
  1126. /*
  1127. * Cirrus Logic CS42xx codecs
  1128. */
  1129. static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
  1130. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
  1131. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
  1132. };
  1133. static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
  1134. {
  1135. int err;
  1136. /* con mask, pro mask, default */
  1137. if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
  1138. return err;
  1139. /* switch, spsa */
  1140. if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
  1141. return err;
  1142. switch (ac97->id & AC97_ID_CS_MASK) {
  1143. case AC97_ID_CS4205:
  1144. if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
  1145. return err;
  1146. break;
  1147. }
  1148. /* set default PCM S/PDIF params */
  1149. /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
  1150. snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
  1151. return 0;
  1152. }
  1153. static struct snd_ac97_build_ops patch_cirrus_ops = {
  1154. .build_spdif = patch_cirrus_build_spdif
  1155. };
  1156. static int patch_cirrus_spdif(struct snd_ac97 * ac97)
  1157. {
  1158. /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
  1159. WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
  1160. - sp/dif EA ID is not set, but sp/dif is always present.
  1161. - enable/disable is spdif register bit 15.
  1162. - sp/dif control register is 0x68. differs from AC97:
  1163. - valid is bit 14 (vs 15)
  1164. - no DRS
  1165. - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
  1166. - sp/dif ssource select is in 0x5e bits 0,1.
  1167. */
  1168. ac97->build_ops = &patch_cirrus_ops;
  1169. ac97->flags |= AC97_CS_SPDIF;
  1170. ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
  1171. ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
  1172. snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
  1173. return 0;
  1174. }
  1175. static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
  1176. {
  1177. /* force the detection of PC Beep */
  1178. ac97->flags |= AC97_HAS_PC_BEEP;
  1179. return patch_cirrus_spdif(ac97);
  1180. }
  1181. /*
  1182. * Conexant codecs
  1183. */
  1184. static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
  1185. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
  1186. };
  1187. static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
  1188. {
  1189. int err;
  1190. /* con mask, pro mask, default */
  1191. if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
  1192. return err;
  1193. /* switch */
  1194. if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
  1195. return err;
  1196. /* set default PCM S/PDIF params */
  1197. /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
  1198. snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
  1199. snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
  1200. return 0;
  1201. }
  1202. static struct snd_ac97_build_ops patch_conexant_ops = {
  1203. .build_spdif = patch_conexant_build_spdif
  1204. };
  1205. static int patch_conexant(struct snd_ac97 * ac97)
  1206. {
  1207. ac97->build_ops = &patch_conexant_ops;
  1208. ac97->flags |= AC97_CX_SPDIF;
  1209. ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
  1210. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
  1211. return 0;
  1212. }
  1213. static int patch_cx20551(struct snd_ac97 *ac97)
  1214. {
  1215. snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
  1216. return 0;
  1217. }
  1218. /*
  1219. * Analog Device AD18xx, AD19xx codecs
  1220. */
  1221. #ifdef CONFIG_PM
  1222. static void ad18xx_resume(struct snd_ac97 *ac97)
  1223. {
  1224. static unsigned short setup_regs[] = {
  1225. AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
  1226. };
  1227. int i, codec;
  1228. for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
  1229. unsigned short reg = setup_regs[i];
  1230. if (test_bit(reg, ac97->reg_accessed)) {
  1231. snd_ac97_write(ac97, reg, ac97->regs[reg]);
  1232. snd_ac97_read(ac97, reg);
  1233. }
  1234. }
  1235. if (! (ac97->flags & AC97_AD_MULTI))
  1236. /* normal restore */
  1237. snd_ac97_restore_status(ac97);
  1238. else {
  1239. /* restore the AD18xx codec configurations */
  1240. for (codec = 0; codec < 3; codec++) {
  1241. if (! ac97->spec.ad18xx.id[codec])
  1242. continue;
  1243. /* select single codec */
  1244. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
  1245. ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
  1246. ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
  1247. }
  1248. /* select all codecs */
  1249. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
  1250. /* restore status */
  1251. for (i = 2; i < 0x7c ; i += 2) {
  1252. if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
  1253. continue;
  1254. if (test_bit(i, ac97->reg_accessed)) {
  1255. /* handle multi codecs for AD18xx */
  1256. if (i == AC97_PCM) {
  1257. for (codec = 0; codec < 3; codec++) {
  1258. if (! ac97->spec.ad18xx.id[codec])
  1259. continue;
  1260. /* select single codec */
  1261. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
  1262. ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
  1263. /* update PCM bits */
  1264. ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
  1265. }
  1266. /* select all codecs */
  1267. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
  1268. continue;
  1269. } else if (i == AC97_AD_TEST ||
  1270. i == AC97_AD_CODEC_CFG ||
  1271. i == AC97_AD_SERIAL_CFG)
  1272. continue; /* ignore */
  1273. }
  1274. snd_ac97_write(ac97, i, ac97->regs[i]);
  1275. snd_ac97_read(ac97, i);
  1276. }
  1277. }
  1278. snd_ac97_restore_iec958(ac97);
  1279. }
  1280. static void ad1888_resume(struct snd_ac97 *ac97)
  1281. {
  1282. ad18xx_resume(ac97);
  1283. snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
  1284. }
  1285. #endif
  1286. static const struct snd_ac97_res_table ad1819_restbl[] = {
  1287. { AC97_PHONE, 0x9f1f },
  1288. { AC97_MIC, 0x9f1f },
  1289. { AC97_LINE, 0x9f1f },
  1290. { AC97_CD, 0x9f1f },
  1291. { AC97_VIDEO, 0x9f1f },
  1292. { AC97_AUX, 0x9f1f },
  1293. { AC97_PCM, 0x9f1f },
  1294. { } /* terminator */
  1295. };
  1296. static int patch_ad1819(struct snd_ac97 * ac97)
  1297. {
  1298. unsigned short scfg;
  1299. // patch for Analog Devices
  1300. scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
  1301. snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
  1302. ac97->res_table = ad1819_restbl;
  1303. return 0;
  1304. }
  1305. static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
  1306. {
  1307. unsigned short val;
  1308. // test for unchained codec
  1309. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
  1310. snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
  1311. val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
  1312. if ((val & 0xff40) != 0x5340)
  1313. return 0;
  1314. ac97->spec.ad18xx.unchained[idx] = mask;
  1315. ac97->spec.ad18xx.id[idx] = val;
  1316. ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
  1317. return mask;
  1318. }
  1319. static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
  1320. {
  1321. static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
  1322. unsigned short val;
  1323. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
  1324. snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
  1325. val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
  1326. if ((val & 0xff40) != 0x5340)
  1327. return 0;
  1328. if (codec_bits)
  1329. snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
  1330. ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
  1331. ac97->spec.ad18xx.id[idx] = val;
  1332. ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
  1333. return 1;
  1334. }
  1335. static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
  1336. {
  1337. // already detected?
  1338. if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
  1339. cidx1 = -1;
  1340. if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
  1341. cidx2 = -1;
  1342. if (cidx1 < 0 && cidx2 < 0)
  1343. return;
  1344. // test for chained codecs
  1345. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
  1346. ac97->spec.ad18xx.unchained[unchained_idx]);
  1347. snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
  1348. ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
  1349. if (cidx1 >= 0) {
  1350. if (cidx2 < 0)
  1351. patch_ad1881_chained1(ac97, cidx1, 0);
  1352. else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
  1353. patch_ad1881_chained1(ac97, cidx2, 0);
  1354. else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
  1355. patch_ad1881_chained1(ac97, cidx1, 0);
  1356. } else if (cidx2 >= 0) {
  1357. patch_ad1881_chained1(ac97, cidx2, 0);
  1358. }
  1359. }
  1360. static struct snd_ac97_build_ops patch_ad1881_build_ops = {
  1361. #ifdef CONFIG_PM
  1362. .resume = ad18xx_resume
  1363. #endif
  1364. };
  1365. static int patch_ad1881(struct snd_ac97 * ac97)
  1366. {
  1367. static const char cfg_idxs[3][2] = {
  1368. {2, 1},
  1369. {0, 2},
  1370. {0, 1}
  1371. };
  1372. // patch for Analog Devices
  1373. unsigned short codecs[3];
  1374. unsigned short val;
  1375. int idx, num;
  1376. val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
  1377. snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
  1378. codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
  1379. codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
  1380. codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
  1381. if (! (codecs[0] || codecs[1] || codecs[2]))
  1382. goto __end;
  1383. for (idx = 0; idx < 3; idx++)
  1384. if (ac97->spec.ad18xx.unchained[idx])
  1385. patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
  1386. if (ac97->spec.ad18xx.id[1]) {
  1387. ac97->flags |= AC97_AD_MULTI;
  1388. ac97->scaps |= AC97_SCAP_SURROUND_DAC;
  1389. }
  1390. if (ac97->spec.ad18xx.id[2]) {
  1391. ac97->flags |= AC97_AD_MULTI;
  1392. ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
  1393. }
  1394. __end:
  1395. /* select all codecs */
  1396. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
  1397. /* check if only one codec is present */
  1398. for (idx = num = 0; idx < 3; idx++)
  1399. if (ac97->spec.ad18xx.id[idx])
  1400. num++;
  1401. if (num == 1) {
  1402. /* ok, deselect all ID bits */
  1403. snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
  1404. ac97->spec.ad18xx.codec_cfg[0] =
  1405. ac97->spec.ad18xx.codec_cfg[1] =
  1406. ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
  1407. }
  1408. /* required for AD1886/AD1885 combination */
  1409. ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
  1410. if (ac97->spec.ad18xx.id[0]) {
  1411. ac97->id &= 0xffff0000;
  1412. ac97->id |= ac97->spec.ad18xx.id[0];
  1413. }
  1414. ac97->build_ops = &patch_ad1881_build_ops;
  1415. return 0;
  1416. }
  1417. static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
  1418. AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
  1419. /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
  1420. AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
  1421. AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
  1422. AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
  1423. AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
  1424. };
  1425. static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
  1426. static int patch_ad1885_specific(struct snd_ac97 * ac97)
  1427. {
  1428. int err;
  1429. if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
  1430. return err;
  1431. reset_tlv(ac97, "Headphone Playback Volume",
  1432. db_scale_6bit_6db_max);
  1433. return 0;
  1434. }
  1435. static struct snd_ac97_build_ops patch_ad1885_build_ops = {
  1436. .build_specific = &patch_ad1885_specific,
  1437. #ifdef CONFIG_PM
  1438. .resume = ad18xx_resume
  1439. #endif
  1440. };
  1441. static int patch_ad1885(struct snd_ac97 * ac97)
  1442. {
  1443. patch_ad1881(ac97);
  1444. /* This is required to deal with the Intel D815EEAL2 */
  1445. /* i.e. Line out is actually headphone out from codec */
  1446. /* set default */
  1447. snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
  1448. ac97->build_ops = &patch_ad1885_build_ops;
  1449. return 0;
  1450. }
  1451. static int patch_ad1886_specific(struct snd_ac97 * ac97)
  1452. {
  1453. reset_tlv(ac97, "Headphone Playback Volume",
  1454. db_scale_6bit_6db_max);
  1455. return 0;
  1456. }
  1457. static struct snd_ac97_build_ops patch_ad1886_build_ops = {
  1458. .build_specific = &patch_ad1886_specific,
  1459. #ifdef CONFIG_PM
  1460. .resume = ad18xx_resume
  1461. #endif
  1462. };
  1463. static int patch_ad1886(struct snd_ac97 * ac97)
  1464. {
  1465. patch_ad1881(ac97);
  1466. /* Presario700 workaround */
  1467. /* for Jack Sense/SPDIF Register misetting causing */
  1468. snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
  1469. ac97->build_ops = &patch_ad1886_build_ops;
  1470. return 0;
  1471. }
  1472. /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
  1473. #define AC97_AD198X_MBC 0x0003 /* mic boost */
  1474. #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
  1475. #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
  1476. #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
  1477. #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
  1478. #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
  1479. #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
  1480. #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
  1481. #define AC97_AD198X_VREF_SHIFT 2
  1482. #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
  1483. #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
  1484. #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
  1485. #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
  1486. #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
  1487. /* 0 = 6-to-4, 1 = 6-to-2 downmix */
  1488. #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
  1489. #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
  1490. #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
  1491. #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
  1492. #define AC97_AD198X_MSPLT 0x2000 /* mute split */
  1493. #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
  1494. #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
  1495. /* MISC 1 bits (AD1986 register 0x76) */
  1496. #define AC97_AD1986_MBC 0x0003 /* mic boost */
  1497. #define AC97_AD1986_MBC_20 0x0000 /* +20dB */
  1498. #define AC97_AD1986_MBC_10 0x0001 /* +10dB */
  1499. #define AC97_AD1986_MBC_30 0x0002 /* +30dB */
  1500. #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
  1501. #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
  1502. #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
  1503. #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
  1504. #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
  1505. #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
  1506. #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
  1507. #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
  1508. #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
  1509. #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
  1510. #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
  1511. /* 0 = 6-to-4, 1 = 6-to-2 downmix */
  1512. #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
  1513. #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
  1514. #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
  1515. #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
  1516. #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
  1517. #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
  1518. /* MISC 2 bits (AD1986 register 0x70) */
  1519. #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
  1520. #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
  1521. #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
  1522. #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
  1523. #define AC97_AD1986_CVREF_MASK \
  1524. (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
  1525. #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
  1526. #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
  1527. #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
  1528. #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
  1529. #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
  1530. #define AC97_AD1986_MVREF_MASK \
  1531. (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
  1532. /* MISC 3 bits (AD1986 register 0x7a) */
  1533. #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
  1534. #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
  1535. #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
  1536. #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
  1537. #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
  1538. #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
  1539. #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
  1540. #define AC97_AD1986_LVREF_MASK \
  1541. (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
  1542. #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
  1543. #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
  1544. #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
  1545. /* input select Surround DACs */
  1546. #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
  1547. /* select C/LFE DACs */
  1548. #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
  1549. /* Serial Config bits (AD1986 register 0x74) (incomplete) */
  1550. #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
  1551. #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
  1552. #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
  1553. #define AC97_AD1986_OMS_MASK \
  1554. (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
  1555. #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
  1556. #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
  1557. #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
  1558. #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
  1559. /* are MIC sources */
  1560. #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
  1561. /* are MIC sources */
  1562. #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
  1563. /* are MIC sources */
  1564. #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
  1565. /* are MIC sources */
  1566. static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1567. {
  1568. static char *texts[2] = { "AC-Link", "A/D Converter" };
  1569. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1570. uinfo->count = 1;
  1571. uinfo->value.enumerated.items = 2;
  1572. if (uinfo->value.enumerated.item > 1)
  1573. uinfo->value.enumerated.item = 1;
  1574. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1575. return 0;
  1576. }
  1577. static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1578. {
  1579. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1580. unsigned short val;
  1581. val = ac97->regs[AC97_AD_SERIAL_CFG];
  1582. ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
  1583. return 0;
  1584. }
  1585. static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1586. {
  1587. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1588. unsigned short val;
  1589. if (ucontrol->value.enumerated.item[0] > 1)
  1590. return -EINVAL;
  1591. val = ucontrol->value.enumerated.item[0] << 2;
  1592. return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
  1593. }
  1594. static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
  1595. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1596. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1597. .info = snd_ac97_ad198x_spdif_source_info,
  1598. .get = snd_ac97_ad198x_spdif_source_get,
  1599. .put = snd_ac97_ad198x_spdif_source_put,
  1600. };
  1601. static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
  1602. {
  1603. return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
  1604. }
  1605. static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
  1606. AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
  1607. AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
  1608. };
  1609. /* black list to avoid HP/Line jack-sense controls
  1610. * (SS vendor << 16 | device)
  1611. */
  1612. static unsigned int ad1981_jacks_blacklist[] = {
  1613. 0x10140523, /* Thinkpad R40 */
  1614. 0x10140534, /* Thinkpad X31 */
  1615. 0x10140537, /* Thinkpad T41p */
  1616. 0x1014053e, /* Thinkpad R40e */
  1617. 0x10140554, /* Thinkpad T42p/R50p */
  1618. 0x10140567, /* Thinkpad T43p 2668-G7U */
  1619. 0x10140581, /* Thinkpad X41-2527 */
  1620. 0x10280160, /* Dell Dimension 2400 */
  1621. 0x104380b0, /* Asus A7V8X-MX */
  1622. 0x11790241, /* Toshiba Satellite A-15 S127 */
  1623. 0x144dc01a, /* Samsung NP-X20C004/SEG */
  1624. 0 /* end */
  1625. };
  1626. static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
  1627. {
  1628. u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
  1629. for (; *list; list++)
  1630. if (*list == subid)
  1631. return 1;
  1632. return 0;
  1633. }
  1634. static int patch_ad1981a_specific(struct snd_ac97 * ac97)
  1635. {
  1636. if (check_list(ac97, ad1981_jacks_blacklist))
  1637. return 0;
  1638. return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
  1639. ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
  1640. }
  1641. static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
  1642. .build_post_spdif = patch_ad198x_post_spdif,
  1643. .build_specific = patch_ad1981a_specific,
  1644. #ifdef CONFIG_PM
  1645. .resume = ad18xx_resume
  1646. #endif
  1647. };
  1648. /* white list to enable HP jack-sense bits
  1649. * (SS vendor << 16 | device)
  1650. */
  1651. static unsigned int ad1981_jacks_whitelist[] = {
  1652. 0x0e11005a, /* HP nc4000/4010 */
  1653. 0x103c0890, /* HP nc6000 */
  1654. 0x103c0938, /* HP nc4220 */
  1655. 0x103c099c, /* HP nx6110 */
  1656. 0x103c0944, /* HP nc6220 */
  1657. 0x103c0934, /* HP nc8220 */
  1658. 0x103c006d, /* HP nx9105 */
  1659. 0x17340088, /* FSC Scenic-W */
  1660. 0 /* end */
  1661. };
  1662. static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
  1663. {
  1664. if (check_list(ac97, ad1981_jacks_whitelist))
  1665. /* enable headphone jack sense */
  1666. snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
  1667. }
  1668. static int patch_ad1981a(struct snd_ac97 *ac97)
  1669. {
  1670. patch_ad1881(ac97);
  1671. ac97->build_ops = &patch_ad1981a_build_ops;
  1672. snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
  1673. ac97->flags |= AC97_STEREO_MUTES;
  1674. check_ad1981_hp_jack_sense(ac97);
  1675. return 0;
  1676. }
  1677. static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
  1678. AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
  1679. static int patch_ad1981b_specific(struct snd_ac97 *ac97)
  1680. {
  1681. int err;
  1682. if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
  1683. return err;
  1684. if (check_list(ac97, ad1981_jacks_blacklist))
  1685. return 0;
  1686. return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
  1687. ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
  1688. }
  1689. static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
  1690. .build_post_spdif = patch_ad198x_post_spdif,
  1691. .build_specific = patch_ad1981b_specific,
  1692. #ifdef CONFIG_PM
  1693. .resume = ad18xx_resume
  1694. #endif
  1695. };
  1696. static int patch_ad1981b(struct snd_ac97 *ac97)
  1697. {
  1698. patch_ad1881(ac97);
  1699. ac97->build_ops = &patch_ad1981b_build_ops;
  1700. snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
  1701. ac97->flags |= AC97_STEREO_MUTES;
  1702. check_ad1981_hp_jack_sense(ac97);
  1703. return 0;
  1704. }
  1705. #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
  1706. static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1707. {
  1708. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1709. unsigned short val;
  1710. val = ac97->regs[AC97_AD_MISC];
  1711. ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
  1712. if (ac97->spec.ad18xx.lo_as_master)
  1713. ucontrol->value.integer.value[0] =
  1714. !ucontrol->value.integer.value[0];
  1715. return 0;
  1716. }
  1717. static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1718. {
  1719. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1720. unsigned short val;
  1721. val = !ucontrol->value.integer.value[0];
  1722. if (ac97->spec.ad18xx.lo_as_master)
  1723. val = !val;
  1724. val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
  1725. return snd_ac97_update_bits(ac97, AC97_AD_MISC,
  1726. AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
  1727. }
  1728. static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1729. {
  1730. static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
  1731. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1732. uinfo->count = 1;
  1733. uinfo->value.enumerated.items = 3;
  1734. if (uinfo->value.enumerated.item > 2)
  1735. uinfo->value.enumerated.item = 2;
  1736. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1737. return 0;
  1738. }
  1739. static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1740. {
  1741. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1742. unsigned short val;
  1743. val = ac97->regs[AC97_AD_MISC];
  1744. if (!(val & AC97_AD198X_DMIX1))
  1745. ucontrol->value.enumerated.item[0] = 0;
  1746. else
  1747. ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
  1748. return 0;
  1749. }
  1750. static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1751. {
  1752. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1753. unsigned short val;
  1754. if (ucontrol->value.enumerated.item[0] > 2)
  1755. return -EINVAL;
  1756. if (ucontrol->value.enumerated.item[0] == 0)
  1757. val = 0;
  1758. else
  1759. val = AC97_AD198X_DMIX1 |
  1760. ((ucontrol->value.enumerated.item[0] - 1) << 8);
  1761. return snd_ac97_update_bits(ac97, AC97_AD_MISC,
  1762. AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
  1763. }
  1764. static void ad1888_update_jacks(struct snd_ac97 *ac97)
  1765. {
  1766. unsigned short val = 0;
  1767. /* clear LODIS if shared jack is to be used for Surround out */
  1768. if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
  1769. val |= (1 << 12);
  1770. /* clear CLDIS if shared jack is to be used for C/LFE out */
  1771. if (is_shared_micin(ac97))
  1772. val |= (1 << 11);
  1773. /* shared Line-In */
  1774. snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
  1775. }
  1776. static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
  1777. {
  1778. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1779. .name = "Exchange Front/Surround",
  1780. .info = snd_ac97_ad1888_lohpsel_info,
  1781. .get = snd_ac97_ad1888_lohpsel_get,
  1782. .put = snd_ac97_ad1888_lohpsel_put
  1783. },
  1784. AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
  1785. AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
  1786. AC97_AD_HPFD_SHIFT, 1, 1),
  1787. AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
  1788. {
  1789. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1790. .name = "Downmix",
  1791. .info = snd_ac97_ad1888_downmix_info,
  1792. .get = snd_ac97_ad1888_downmix_get,
  1793. .put = snd_ac97_ad1888_downmix_put
  1794. },
  1795. AC97_SURROUND_JACK_MODE_CTL,
  1796. AC97_CHANNEL_MODE_CTL,
  1797. AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
  1798. AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
  1799. };
  1800. static int patch_ad1888_specific(struct snd_ac97 *ac97)
  1801. {
  1802. if (!ac97->spec.ad18xx.lo_as_master) {
  1803. /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
  1804. snd_ac97_rename_vol_ctl(ac97, "Master Playback",
  1805. "Master Surround Playback");
  1806. snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
  1807. "Master Playback");
  1808. }
  1809. return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
  1810. }
  1811. static struct snd_ac97_build_ops patch_ad1888_build_ops = {
  1812. .build_post_spdif = patch_ad198x_post_spdif,
  1813. .build_specific = patch_ad1888_specific,
  1814. #ifdef CONFIG_PM
  1815. .resume = ad1888_resume,
  1816. #endif
  1817. .update_jacks = ad1888_update_jacks,
  1818. };
  1819. static int patch_ad1888(struct snd_ac97 * ac97)
  1820. {
  1821. unsigned short misc;
  1822. patch_ad1881(ac97);
  1823. ac97->build_ops = &patch_ad1888_build_ops;
  1824. /*
  1825. * LO can be used as a real line-out on some devices,
  1826. * and we need to revert the front/surround mixer switches
  1827. */
  1828. if (ac97->subsystem_vendor == 0x1043 &&
  1829. ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
  1830. ac97->spec.ad18xx.lo_as_master = 1;
  1831. misc = snd_ac97_read(ac97, AC97_AD_MISC);
  1832. /* AD-compatible mode */
  1833. /* Stereo mutes enabled */
  1834. misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
  1835. if (!ac97->spec.ad18xx.lo_as_master)
  1836. /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
  1837. /* it seems that most vendors connect line-out connector to
  1838. * headphone out of AC'97
  1839. */
  1840. misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
  1841. snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
  1842. ac97->flags |= AC97_STEREO_MUTES;
  1843. return 0;
  1844. }
  1845. static int patch_ad1980_specific(struct snd_ac97 *ac97)
  1846. {
  1847. int err;
  1848. if ((err = patch_ad1888_specific(ac97)) < 0)
  1849. return err;
  1850. return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
  1851. }
  1852. static struct snd_ac97_build_ops patch_ad1980_build_ops = {
  1853. .build_post_spdif = patch_ad198x_post_spdif,
  1854. .build_specific = patch_ad1980_specific,
  1855. #ifdef CONFIG_PM
  1856. .resume = ad18xx_resume,
  1857. #endif
  1858. .update_jacks = ad1888_update_jacks,
  1859. };
  1860. static int patch_ad1980(struct snd_ac97 * ac97)
  1861. {
  1862. patch_ad1888(ac97);
  1863. ac97->build_ops = &patch_ad1980_build_ops;
  1864. return 0;
  1865. }
  1866. static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
  1867. struct snd_ctl_elem_info *uinfo)
  1868. {
  1869. static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
  1870. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1871. uinfo->count = 1;
  1872. uinfo->value.enumerated.items = 4;
  1873. if (uinfo->value.enumerated.item > 3)
  1874. uinfo->value.enumerated.item = 3;
  1875. strcpy(uinfo->value.enumerated.name,
  1876. texts[uinfo->value.enumerated.item]);
  1877. return 0;
  1878. }
  1879. static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
  1880. struct snd_ctl_elem_value *ucontrol)
  1881. {
  1882. static const int reg2ctrl[4] = {2, 0, 1, 3};
  1883. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1884. unsigned short val;
  1885. val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
  1886. >> AC97_AD198X_VREF_SHIFT;
  1887. ucontrol->value.enumerated.item[0] = reg2ctrl[val];
  1888. return 0;
  1889. }
  1890. static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
  1891. struct snd_ctl_elem_value *ucontrol)
  1892. {
  1893. static const int ctrl2reg[4] = {1, 2, 0, 3};
  1894. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1895. unsigned short val;
  1896. if (ucontrol->value.enumerated.item[0] > 3)
  1897. return -EINVAL;
  1898. val = ctrl2reg[ucontrol->value.enumerated.item[0]]
  1899. << AC97_AD198X_VREF_SHIFT;
  1900. return snd_ac97_update_bits(ac97, AC97_AD_MISC,
  1901. AC97_AD198X_VREF_MASK, val);
  1902. }
  1903. static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
  1904. AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
  1905. {
  1906. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1907. .name = "Exchange Front/Surround",
  1908. .info = snd_ac97_ad1888_lohpsel_info,
  1909. .get = snd_ac97_ad1888_lohpsel_get,
  1910. .put = snd_ac97_ad1888_lohpsel_put
  1911. },
  1912. AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
  1913. AC97_SINGLE("Spread Front to Surround and Center/LFE",
  1914. AC97_AD_MISC, 7, 1, 0),
  1915. {
  1916. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1917. .name = "Downmix",
  1918. .info = snd_ac97_ad1888_downmix_info,
  1919. .get = snd_ac97_ad1888_downmix_get,
  1920. .put = snd_ac97_ad1888_downmix_put
  1921. },
  1922. {
  1923. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1924. .name = "V_REFOUT",
  1925. .info = snd_ac97_ad1985_vrefout_info,
  1926. .get = snd_ac97_ad1985_vrefout_get,
  1927. .put = snd_ac97_ad1985_vrefout_put
  1928. },
  1929. AC97_SURROUND_JACK_MODE_CTL,
  1930. AC97_CHANNEL_MODE_CTL,
  1931. AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
  1932. AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
  1933. };
  1934. static void ad1985_update_jacks(struct snd_ac97 *ac97)
  1935. {
  1936. ad1888_update_jacks(ac97);
  1937. /* clear OMS if shared jack is to be used for C/LFE out */
  1938. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
  1939. is_shared_micin(ac97) ? 1 << 9 : 0);
  1940. }
  1941. static int patch_ad1985_specific(struct snd_ac97 *ac97)
  1942. {
  1943. int err;
  1944. /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
  1945. snd_ac97_rename_vol_ctl(ac97, "Master Playback",
  1946. "Master Surround Playback");
  1947. snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
  1948. if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
  1949. return err;
  1950. return patch_build_controls(ac97, snd_ac97_ad1985_controls,
  1951. ARRAY_SIZE(snd_ac97_ad1985_controls));
  1952. }
  1953. static struct snd_ac97_build_ops patch_ad1985_build_ops = {
  1954. .build_post_spdif = patch_ad198x_post_spdif,
  1955. .build_specific = patch_ad1985_specific,
  1956. #ifdef CONFIG_PM
  1957. .resume = ad18xx_resume,
  1958. #endif
  1959. .update_jacks = ad1985_update_jacks,
  1960. };
  1961. static int patch_ad1985(struct snd_ac97 * ac97)
  1962. {
  1963. unsigned short misc;
  1964. patch_ad1881(ac97);
  1965. ac97->build_ops = &patch_ad1985_build_ops;
  1966. misc = snd_ac97_read(ac97, AC97_AD_MISC);
  1967. /* switch front/surround line-out/hp-out */
  1968. /* AD-compatible mode */
  1969. /* Stereo mutes enabled */
  1970. snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
  1971. AC97_AD198X_LOSEL |
  1972. AC97_AD198X_HPSEL |
  1973. AC97_AD198X_MSPLT |
  1974. AC97_AD198X_AC97NC);
  1975. ac97->flags |= AC97_STEREO_MUTES;
  1976. /* update current jack configuration */
  1977. ad1985_update_jacks(ac97);
  1978. /* on AD1985 rev. 3, AC'97 revision bits are zero */
  1979. ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
  1980. return 0;
  1981. }
  1982. #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
  1983. static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
  1984. struct snd_ctl_elem_value *ucontrol)
  1985. {
  1986. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1987. unsigned short val;
  1988. val = ac97->regs[AC97_AD_MISC3];
  1989. ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
  1990. return 0;
  1991. }
  1992. static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
  1993. struct snd_ctl_elem_value *ucontrol)
  1994. {
  1995. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  1996. int ret0;
  1997. int ret1;
  1998. int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
  1999. ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
  2000. ucontrol->value.integer.value[0] != 0
  2001. ? AC97_AD1986_LOSEL : 0);
  2002. if (ret0 < 0)
  2003. return ret0;
  2004. /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
  2005. ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
  2006. (ucontrol->value.integer.value[0] != 0
  2007. || sprd)
  2008. ? AC97_AD1986_SOSEL : 0);
  2009. if (ret1 < 0)
  2010. return ret1;
  2011. return (ret0 > 0 || ret1 > 0) ? 1 : 0;
  2012. }
  2013. static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
  2014. struct snd_ctl_elem_value *ucontrol)
  2015. {
  2016. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2017. unsigned short val;
  2018. val = ac97->regs[AC97_AD_MISC];
  2019. ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
  2020. return 0;
  2021. }
  2022. static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
  2023. struct snd_ctl_elem_value *ucontrol)
  2024. {
  2025. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2026. int ret0;
  2027. int ret1;
  2028. int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
  2029. ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
  2030. ucontrol->value.integer.value[0] != 0
  2031. ? AC97_AD1986_SPRD : 0);
  2032. if (ret0 < 0)
  2033. return ret0;
  2034. /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
  2035. ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
  2036. (ucontrol->value.integer.value[0] != 0
  2037. || sprd)
  2038. ? AC97_AD1986_SOSEL : 0);
  2039. if (ret1 < 0)
  2040. return ret1;
  2041. return (ret0 > 0 || ret1 > 0) ? 1 : 0;
  2042. }
  2043. static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
  2044. struct snd_ctl_elem_value *ucontrol)
  2045. {
  2046. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2047. ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
  2048. return 0;
  2049. }
  2050. static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
  2051. struct snd_ctl_elem_value *ucontrol)
  2052. {
  2053. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2054. unsigned char swap = ucontrol->value.integer.value[0] != 0;
  2055. if (swap != ac97->spec.ad18xx.swap_mic_linein) {
  2056. ac97->spec.ad18xx.swap_mic_linein = swap;
  2057. if (ac97->build_ops->update_jacks)
  2058. ac97->build_ops->update_jacks(ac97);
  2059. return 1;
  2060. }
  2061. return 0;
  2062. }
  2063. static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
  2064. struct snd_ctl_elem_value *ucontrol)
  2065. {
  2066. /* Use MIC_1/2 V_REFOUT as the "get" value */
  2067. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2068. unsigned short val;
  2069. unsigned short reg = ac97->regs[AC97_AD_MISC2];
  2070. if ((reg & AC97_AD1986_MVREF0) != 0)
  2071. val = 2;
  2072. else if ((reg & AC97_AD1986_MVREF1) != 0)
  2073. val = 3;
  2074. else if ((reg & AC97_AD1986_MVREF2) != 0)
  2075. val = 1;
  2076. else
  2077. val = 0;
  2078. ucontrol->value.enumerated.item[0] = val;
  2079. return 0;
  2080. }
  2081. static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
  2082. struct snd_ctl_elem_value *ucontrol)
  2083. {
  2084. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2085. unsigned short cval;
  2086. unsigned short lval;
  2087. unsigned short mval;
  2088. int cret;
  2089. int lret;
  2090. int mret;
  2091. switch (ucontrol->value.enumerated.item[0])
  2092. {
  2093. case 0: /* High-Z */
  2094. cval = 0;
  2095. lval = 0;
  2096. mval = 0;
  2097. break;
  2098. case 1: /* 3.7 V */
  2099. cval = AC97_AD1986_CVREF2;
  2100. lval = AC97_AD1986_LVREF2;
  2101. mval = AC97_AD1986_MVREF2;
  2102. break;
  2103. case 2: /* 2.25 V */
  2104. cval = AC97_AD1986_CVREF0;
  2105. lval = AC97_AD1986_LVREF0;
  2106. mval = AC97_AD1986_MVREF0;
  2107. break;
  2108. case 3: /* 0 V */
  2109. cval = AC97_AD1986_CVREF1;
  2110. lval = AC97_AD1986_LVREF1;
  2111. mval = AC97_AD1986_MVREF1;
  2112. break;
  2113. default:
  2114. return -EINVAL;
  2115. }
  2116. cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
  2117. AC97_AD1986_CVREF_MASK, cval);
  2118. if (cret < 0)
  2119. return cret;
  2120. lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
  2121. AC97_AD1986_LVREF_MASK, lval);
  2122. if (lret < 0)
  2123. return lret;
  2124. mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
  2125. AC97_AD1986_MVREF_MASK, mval);
  2126. if (mret < 0)
  2127. return mret;
  2128. return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
  2129. }
  2130. static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
  2131. AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
  2132. {
  2133. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2134. .name = "Exchange Front/Surround",
  2135. .info = snd_ac97_ad1986_bool_info,
  2136. .get = snd_ac97_ad1986_lososel_get,
  2137. .put = snd_ac97_ad1986_lososel_put
  2138. },
  2139. {
  2140. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2141. .name = "Exchange Mic/Line In",
  2142. .info = snd_ac97_ad1986_bool_info,
  2143. .get = snd_ac97_ad1986_miclisel_get,
  2144. .put = snd_ac97_ad1986_miclisel_put
  2145. },
  2146. {
  2147. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2148. .name = "Spread Front to Surround and Center/LFE",
  2149. .info = snd_ac97_ad1986_bool_info,
  2150. .get = snd_ac97_ad1986_spread_get,
  2151. .put = snd_ac97_ad1986_spread_put
  2152. },
  2153. {
  2154. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2155. .name = "Downmix",
  2156. .info = snd_ac97_ad1888_downmix_info,
  2157. .get = snd_ac97_ad1888_downmix_get,
  2158. .put = snd_ac97_ad1888_downmix_put
  2159. },
  2160. {
  2161. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2162. .name = "V_REFOUT",
  2163. .info = snd_ac97_ad1985_vrefout_info,
  2164. .get = snd_ac97_ad1986_vrefout_get,
  2165. .put = snd_ac97_ad1986_vrefout_put
  2166. },
  2167. AC97_SURROUND_JACK_MODE_CTL,
  2168. AC97_CHANNEL_MODE_CTL,
  2169. AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
  2170. AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
  2171. };
  2172. static void ad1986_update_jacks(struct snd_ac97 *ac97)
  2173. {
  2174. unsigned short misc_val = 0;
  2175. unsigned short ser_val;
  2176. /* disable SURROUND and CENTER/LFE if not surround mode */
  2177. if (!is_surround_on(ac97))
  2178. misc_val |= AC97_AD1986_SODIS;
  2179. if (!is_clfe_on(ac97))
  2180. misc_val |= AC97_AD1986_CLDIS;
  2181. /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
  2182. if (is_shared_linein(ac97))
  2183. misc_val |= AC97_AD1986_LISEL_SURR;
  2184. else if (ac97->spec.ad18xx.swap_mic_linein != 0)
  2185. misc_val |= AC97_AD1986_LISEL_MIC;
  2186. snd_ac97_update_bits(ac97, AC97_AD_MISC,
  2187. AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
  2188. AC97_AD1986_LISEL_MASK,
  2189. misc_val);
  2190. /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
  2191. if (is_shared_micin(ac97))
  2192. ser_val = AC97_AD1986_OMS_C;
  2193. else if (ac97->spec.ad18xx.swap_mic_linein != 0)
  2194. ser_val = AC97_AD1986_OMS_L;
  2195. else
  2196. ser_val = AC97_AD1986_OMS_M;
  2197. snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
  2198. AC97_AD1986_OMS_MASK,
  2199. ser_val);
  2200. }
  2201. static int patch_ad1986_specific(struct snd_ac97 *ac97)
  2202. {
  2203. int err;
  2204. if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
  2205. return err;
  2206. return patch_build_controls(ac97, snd_ac97_ad1986_controls,
  2207. ARRAY_SIZE(snd_ac97_ad1985_controls));
  2208. }
  2209. static struct snd_ac97_build_ops patch_ad1986_build_ops = {
  2210. .build_post_spdif = patch_ad198x_post_spdif,
  2211. .build_specific = patch_ad1986_specific,
  2212. #ifdef CONFIG_PM
  2213. .resume = ad18xx_resume,
  2214. #endif
  2215. .update_jacks = ad1986_update_jacks,
  2216. };
  2217. static int patch_ad1986(struct snd_ac97 * ac97)
  2218. {
  2219. patch_ad1881(ac97);
  2220. ac97->build_ops = &patch_ad1986_build_ops;
  2221. ac97->flags |= AC97_STEREO_MUTES;
  2222. /* update current jack configuration */
  2223. ad1986_update_jacks(ac97);
  2224. return 0;
  2225. }
  2226. /*
  2227. * realtek ALC203: use mono-out for pin 37
  2228. */
  2229. static int patch_alc203(struct snd_ac97 *ac97)
  2230. {
  2231. snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
  2232. return 0;
  2233. }
  2234. /*
  2235. * realtek ALC65x/850 codecs
  2236. */
  2237. static void alc650_update_jacks(struct snd_ac97 *ac97)
  2238. {
  2239. int shared;
  2240. /* shared Line-In / Surround Out */
  2241. shared = is_shared_surrout(ac97);
  2242. snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
  2243. shared ? (1 << 9) : 0);
  2244. /* update shared Mic In / Center/LFE Out */
  2245. shared = is_shared_clfeout(ac97);
  2246. /* disable/enable vref */
  2247. snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
  2248. shared ? (1 << 12) : 0);
  2249. /* turn on/off center-on-mic */
  2250. snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
  2251. shared ? (1 << 10) : 0);
  2252. /* GPIO0 high for mic */
  2253. snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
  2254. shared ? 0 : 0x100);
  2255. }
  2256. static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
  2257. AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
  2258. AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
  2259. AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
  2260. AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
  2261. /* 4: Analog Input To Surround */
  2262. /* 5: Analog Input To Center/LFE */
  2263. /* 6: Independent Master Volume Right */
  2264. /* 7: Independent Master Volume Left */
  2265. /* 8: reserved */
  2266. /* 9: Line-In/Surround share */
  2267. /* 10: Mic/CLFE share */
  2268. /* 11-13: in IEC958 controls */
  2269. AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
  2270. #if 0 /* always set in patch_alc650 */
  2271. AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
  2272. AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
  2273. AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
  2274. AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
  2275. AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
  2276. AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
  2277. #endif
  2278. AC97_SURROUND_JACK_MODE_CTL,
  2279. AC97_CHANNEL_MODE_CTL,
  2280. };
  2281. static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
  2282. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
  2283. AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
  2284. /* disable this controls since it doesn't work as expected */
  2285. /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
  2286. };
  2287. static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
  2288. static int patch_alc650_specific(struct snd_ac97 * ac97)
  2289. {
  2290. int err;
  2291. if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
  2292. return err;
  2293. if (ac97->ext_id & AC97_EI_SPDIF) {
  2294. if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
  2295. return err;
  2296. }
  2297. if (ac97->id != AC97_ID_ALC650F)
  2298. reset_tlv(ac97, "Master Playback Volume",
  2299. db_scale_5bit_3db_max);
  2300. return 0;
  2301. }
  2302. static struct snd_ac97_build_ops patch_alc650_ops = {
  2303. .build_specific = patch_alc650_specific,
  2304. .update_jacks = alc650_update_jacks
  2305. };
  2306. static int patch_alc650(struct snd_ac97 * ac97)
  2307. {
  2308. unsigned short val;
  2309. ac97->build_ops = &patch_alc650_ops;
  2310. /* determine the revision */
  2311. val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
  2312. if (val < 3)
  2313. ac97->id = 0x414c4720; /* Old version */
  2314. else if (val < 0x10)
  2315. ac97->id = 0x414c4721; /* D version */
  2316. else if (val < 0x20)
  2317. ac97->id = 0x414c4722; /* E version */
  2318. else if (val < 0x30)
  2319. ac97->id = 0x414c4723; /* F version */
  2320. /* revision E or F */
  2321. /* FIXME: what about revision D ? */
  2322. ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
  2323. ac97->id == 0x414c4723);
  2324. /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
  2325. snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
  2326. snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
  2327. /* Enable SPDIF-IN only on Rev.E and above */
  2328. val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
  2329. /* SPDIF IN with pin 47 */
  2330. if (ac97->spec.dev_flags &&
  2331. /* ASUS A6KM requires EAPD */
  2332. ! (ac97->subsystem_vendor == 0x1043 &&
  2333. ac97->subsystem_device == 0x1103))
  2334. val |= 0x03; /* enable */
  2335. else
  2336. val &= ~0x03; /* disable */
  2337. snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
  2338. /* set default: slot 3,4,7,8,6,9
  2339. spdif-in monitor off, analog-spdif off, spdif-in off
  2340. center on mic off, surround on line-in off
  2341. downmix off, duplicate front off
  2342. */
  2343. snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
  2344. /* set GPIO0 for mic bias */
  2345. /* GPIO0 pin output, no interrupt, high */
  2346. snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
  2347. snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
  2348. snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
  2349. (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
  2350. /* full DAC volume */
  2351. snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
  2352. snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
  2353. return 0;
  2354. }
  2355. static void alc655_update_jacks(struct snd_ac97 *ac97)
  2356. {
  2357. int shared;
  2358. /* shared Line-In / Surround Out */
  2359. shared = is_shared_surrout(ac97);
  2360. ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
  2361. shared ? (1 << 9) : 0, 0);
  2362. /* update shared Mic In / Center/LFE Out */
  2363. shared = is_shared_clfeout(ac97);
  2364. /* misc control; vrefout disable */
  2365. snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
  2366. shared ? (1 << 12) : 0);
  2367. ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
  2368. shared ? (1 << 10) : 0, 0);
  2369. }
  2370. static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
  2371. AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
  2372. AC97_SURROUND_JACK_MODE_CTL,
  2373. AC97_CHANNEL_MODE_CTL,
  2374. };
  2375. static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2376. {
  2377. static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
  2378. static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
  2379. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2380. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2381. uinfo->count = 1;
  2382. uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
  2383. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  2384. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  2385. strcpy(uinfo->value.enumerated.name,
  2386. ac97->spec.dev_flags ?
  2387. texts_658[uinfo->value.enumerated.item] :
  2388. texts_655[uinfo->value.enumerated.item]);
  2389. return 0;
  2390. }
  2391. static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2392. {
  2393. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2394. unsigned short val;
  2395. val = ac97->regs[AC97_ALC650_MULTICH];
  2396. val = (val >> 12) & 3;
  2397. if (ac97->spec.dev_flags && val == 3)
  2398. val = 0;
  2399. ucontrol->value.enumerated.item[0] = val;
  2400. return 0;
  2401. }
  2402. static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2403. {
  2404. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2405. return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
  2406. (unsigned short)ucontrol->value.enumerated.item[0] << 12,
  2407. 0);
  2408. }
  2409. static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
  2410. AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
  2411. /* disable this controls since it doesn't work as expected */
  2412. /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
  2413. {
  2414. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2415. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  2416. .info = alc655_iec958_route_info,
  2417. .get = alc655_iec958_route_get,
  2418. .put = alc655_iec958_route_put,
  2419. },
  2420. };
  2421. static int patch_alc655_specific(struct snd_ac97 * ac97)
  2422. {
  2423. int err;
  2424. if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
  2425. return err;
  2426. if (ac97->ext_id & AC97_EI_SPDIF) {
  2427. if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
  2428. return err;
  2429. }
  2430. return 0;
  2431. }
  2432. static struct snd_ac97_build_ops patch_alc655_ops = {
  2433. .build_specific = patch_alc655_specific,
  2434. .update_jacks = alc655_update_jacks
  2435. };
  2436. static int patch_alc655(struct snd_ac97 * ac97)
  2437. {
  2438. unsigned int val;
  2439. if (ac97->id == AC97_ID_ALC658) {
  2440. ac97->spec.dev_flags = 1; /* ALC658 */
  2441. if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
  2442. ac97->id = AC97_ID_ALC658D;
  2443. ac97->spec.dev_flags = 2;
  2444. }
  2445. }
  2446. ac97->build_ops = &patch_alc655_ops;
  2447. /* assume only page 0 for writing cache */
  2448. snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
  2449. /* adjust default values */
  2450. val = snd_ac97_read(ac97, 0x7a); /* misc control */
  2451. if (ac97->spec.dev_flags) /* ALC658 */
  2452. val &= ~(1 << 1); /* Pin 47 is spdif input pin */
  2453. else { /* ALC655 */
  2454. if (ac97->subsystem_vendor == 0x1462 &&
  2455. (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
  2456. ac97->subsystem_device == 0x0161 || /* LG K1 Express */
  2457. ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
  2458. ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
  2459. ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
  2460. val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
  2461. else
  2462. val |= (1 << 1); /* Pin 47 is spdif input pin */
  2463. /* this seems missing on some hardwares */
  2464. ac97->ext_id |= AC97_EI_SPDIF;
  2465. }
  2466. val &= ~(1 << 12); /* vref enable */
  2467. snd_ac97_write_cache(ac97, 0x7a, val);
  2468. /* set default: spdif-in enabled,
  2469. spdif-in monitor off, spdif-in PCM off
  2470. center on mic off, surround on line-in off
  2471. duplicate front off
  2472. */
  2473. snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
  2474. /* full DAC volume */
  2475. snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
  2476. snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
  2477. /* update undocumented bit... */
  2478. if (ac97->id == AC97_ID_ALC658D)
  2479. snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
  2480. return 0;
  2481. }
  2482. #define AC97_ALC850_JACK_SELECT 0x76
  2483. #define AC97_ALC850_MISC1 0x7a
  2484. #define AC97_ALC850_MULTICH 0x6a
  2485. static void alc850_update_jacks(struct snd_ac97 *ac97)
  2486. {
  2487. int shared;
  2488. int aux_is_back_surround;
  2489. /* shared Line-In / Surround Out */
  2490. shared = is_shared_surrout(ac97);
  2491. /* SURR 1kOhm (bit4), Amp (bit5) */
  2492. snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
  2493. shared ? (1<<5) : (1<<4));
  2494. /* LINE-IN = 0, SURROUND = 2 */
  2495. snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
  2496. shared ? (2<<12) : (0<<12));
  2497. /* update shared Mic In / Center/LFE Out */
  2498. shared = is_shared_clfeout(ac97);
  2499. /* Vref disable (bit12), 1kOhm (bit13) */
  2500. snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
  2501. shared ? (1<<12) : (1<<13));
  2502. /* MIC-IN = 1, CENTER-LFE = 5 */
  2503. snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
  2504. shared ? (5<<4) : (1<<4));
  2505. aux_is_back_surround = alc850_is_aux_back_surround(ac97);
  2506. /* Aux is Back Surround */
  2507. snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
  2508. aux_is_back_surround ? (1<<10) : (0<<10));
  2509. }
  2510. static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
  2511. AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
  2512. AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
  2513. AC97_SURROUND_JACK_MODE_CTL,
  2514. AC97_CHANNEL_MODE_8CH_CTL,
  2515. };
  2516. static int patch_alc850_specific(struct snd_ac97 *ac97)
  2517. {
  2518. int err;
  2519. if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
  2520. return err;
  2521. if (ac97->ext_id & AC97_EI_SPDIF) {
  2522. if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
  2523. return err;
  2524. }
  2525. return 0;
  2526. }
  2527. static struct snd_ac97_build_ops patch_alc850_ops = {
  2528. .build_specific = patch_alc850_specific,
  2529. .update_jacks = alc850_update_jacks
  2530. };
  2531. static int patch_alc850(struct snd_ac97 *ac97)
  2532. {
  2533. ac97->build_ops = &patch_alc850_ops;
  2534. ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
  2535. ac97->flags |= AC97_HAS_8CH;
  2536. /* assume only page 0 for writing cache */
  2537. snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
  2538. /* adjust default values */
  2539. /* set default: spdif-in enabled,
  2540. spdif-in monitor off, spdif-in PCM off
  2541. center on mic off, surround on line-in off
  2542. duplicate front off
  2543. NB default bit 10=0 = Aux is Capture, not Back Surround
  2544. */
  2545. snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
  2546. /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
  2547. * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
  2548. */
  2549. snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
  2550. (1<<7)|(0<<12)|(1<<13)|(0<<14));
  2551. /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
  2552. * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
  2553. */
  2554. snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
  2555. (1<<11)|(0<<12)|(1<<15));
  2556. /* full DAC volume */
  2557. snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
  2558. snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
  2559. return 0;
  2560. }
  2561. /*
  2562. * C-Media CM97xx codecs
  2563. */
  2564. static void cm9738_update_jacks(struct snd_ac97 *ac97)
  2565. {
  2566. /* shared Line-In / Surround Out */
  2567. snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
  2568. is_shared_surrout(ac97) ? (1 << 10) : 0);
  2569. }
  2570. static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
  2571. AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
  2572. AC97_SURROUND_JACK_MODE_CTL,
  2573. AC97_CHANNEL_MODE_4CH_CTL,
  2574. };
  2575. static int patch_cm9738_specific(struct snd_ac97 * ac97)
  2576. {
  2577. return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
  2578. }
  2579. static struct snd_ac97_build_ops patch_cm9738_ops = {
  2580. .build_specific = patch_cm9738_specific,
  2581. .update_jacks = cm9738_update_jacks
  2582. };
  2583. static int patch_cm9738(struct snd_ac97 * ac97)
  2584. {
  2585. ac97->build_ops = &patch_cm9738_ops;
  2586. /* FIXME: can anyone confirm below? */
  2587. /* CM9738 has no PCM volume although the register reacts */
  2588. ac97->flags |= AC97_HAS_NO_PCM_VOL;
  2589. snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
  2590. return 0;
  2591. }
  2592. static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2593. {
  2594. static char *texts[] = { "Analog", "Digital" };
  2595. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2596. uinfo->count = 1;
  2597. uinfo->value.enumerated.items = 2;
  2598. if (uinfo->value.enumerated.item > 1)
  2599. uinfo->value.enumerated.item = 1;
  2600. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2601. return 0;
  2602. }
  2603. static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2604. {
  2605. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2606. unsigned short val;
  2607. val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
  2608. ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
  2609. return 0;
  2610. }
  2611. static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2612. {
  2613. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2614. return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
  2615. 0x01 << 1,
  2616. (ucontrol->value.enumerated.item[0] & 0x01) << 1);
  2617. }
  2618. static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
  2619. /* BIT 0: SPDI_EN - always true */
  2620. { /* BIT 1: SPDIFS */
  2621. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2622. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  2623. .info = snd_ac97_cmedia_spdif_playback_source_info,
  2624. .get = snd_ac97_cmedia_spdif_playback_source_get,
  2625. .put = snd_ac97_cmedia_spdif_playback_source_put,
  2626. },
  2627. /* BIT 2: IG_SPIV */
  2628. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
  2629. /* BIT 3: SPI2F */
  2630. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
  2631. /* BIT 4: SPI2SDI */
  2632. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
  2633. /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
  2634. };
  2635. static void cm9739_update_jacks(struct snd_ac97 *ac97)
  2636. {
  2637. /* shared Line-In / Surround Out */
  2638. snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
  2639. is_shared_surrout(ac97) ? (1 << 10) : 0);
  2640. /* shared Mic In / Center/LFE Out **/
  2641. snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
  2642. is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
  2643. }
  2644. static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
  2645. AC97_SURROUND_JACK_MODE_CTL,
  2646. AC97_CHANNEL_MODE_CTL,
  2647. };
  2648. static int patch_cm9739_specific(struct snd_ac97 * ac97)
  2649. {
  2650. return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
  2651. }
  2652. static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
  2653. {
  2654. return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
  2655. }
  2656. static struct snd_ac97_build_ops patch_cm9739_ops = {
  2657. .build_specific = patch_cm9739_specific,
  2658. .build_post_spdif = patch_cm9739_post_spdif,
  2659. .update_jacks = cm9739_update_jacks
  2660. };
  2661. static int patch_cm9739(struct snd_ac97 * ac97)
  2662. {
  2663. unsigned short val;
  2664. ac97->build_ops = &patch_cm9739_ops;
  2665. /* CM9739/A has no Master and PCM volume although the register reacts */
  2666. ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
  2667. snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
  2668. snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
  2669. /* check spdif */
  2670. val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
  2671. if (val & AC97_EA_SPCV) {
  2672. /* enable spdif in */
  2673. snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
  2674. snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
  2675. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
  2676. } else {
  2677. ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
  2678. ac97->rates[AC97_RATES_SPDIF] = 0;
  2679. }
  2680. /* set-up multi channel */
  2681. /* bit 14: 0 = SPDIF, 1 = EAPD */
  2682. /* bit 13: enable internal vref output for mic */
  2683. /* bit 12: disable center/lfe (swithable) */
  2684. /* bit 10: disable surround/line (switchable) */
  2685. /* bit 9: mix 2 surround off */
  2686. /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
  2687. /* bit 3: undocumented; surround? */
  2688. /* bit 0: dB */
  2689. val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
  2690. val |= (1 << 3);
  2691. val |= (1 << 13);
  2692. if (! (ac97->ext_id & AC97_EI_SPDIF))
  2693. val |= (1 << 14);
  2694. snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
  2695. /* FIXME: set up GPIO */
  2696. snd_ac97_write_cache(ac97, 0x70, 0x0100);
  2697. snd_ac97_write_cache(ac97, 0x72, 0x0020);
  2698. /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
  2699. if (ac97->pci &&
  2700. ac97->subsystem_vendor == 0x1043 &&
  2701. ac97->subsystem_device == 0x1843) {
  2702. snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
  2703. snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
  2704. snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
  2705. snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
  2706. }
  2707. return 0;
  2708. }
  2709. #define AC97_CM9761_MULTI_CHAN 0x64
  2710. #define AC97_CM9761_FUNC 0x66
  2711. #define AC97_CM9761_SPDIF_CTRL 0x6c
  2712. static void cm9761_update_jacks(struct snd_ac97 *ac97)
  2713. {
  2714. /* FIXME: check the bits for each model
  2715. * model 83 is confirmed to work
  2716. */
  2717. static unsigned short surr_on[3][2] = {
  2718. { 0x0008, 0x0000 }, /* 9761-78 & 82 */
  2719. { 0x0000, 0x0008 }, /* 9761-82 rev.B */
  2720. { 0x0000, 0x0008 }, /* 9761-83 */
  2721. };
  2722. static unsigned short clfe_on[3][2] = {
  2723. { 0x0000, 0x1000 }, /* 9761-78 & 82 */
  2724. { 0x1000, 0x0000 }, /* 9761-82 rev.B */
  2725. { 0x0000, 0x1000 }, /* 9761-83 */
  2726. };
  2727. static unsigned short surr_shared[3][2] = {
  2728. { 0x0000, 0x0400 }, /* 9761-78 & 82 */
  2729. { 0x0000, 0x0400 }, /* 9761-82 rev.B */
  2730. { 0x0000, 0x0400 }, /* 9761-83 */
  2731. };
  2732. static unsigned short clfe_shared[3][2] = {
  2733. { 0x2000, 0x0880 }, /* 9761-78 & 82 */
  2734. { 0x0000, 0x2880 }, /* 9761-82 rev.B */
  2735. { 0x2000, 0x0800 }, /* 9761-83 */
  2736. };
  2737. unsigned short val = 0;
  2738. val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
  2739. val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
  2740. val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
  2741. val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
  2742. snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
  2743. }
  2744. static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
  2745. AC97_SURROUND_JACK_MODE_CTL,
  2746. AC97_CHANNEL_MODE_CTL,
  2747. };
  2748. static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  2749. {
  2750. static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
  2751. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2752. uinfo->count = 1;
  2753. uinfo->value.enumerated.items = 3;
  2754. if (uinfo->value.enumerated.item > 2)
  2755. uinfo->value.enumerated.item = 2;
  2756. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2757. return 0;
  2758. }
  2759. static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2760. {
  2761. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2762. if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
  2763. ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
  2764. else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
  2765. ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
  2766. else
  2767. ucontrol->value.enumerated.item[0] = 0; /* AC-link */
  2768. return 0;
  2769. }
  2770. static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2771. {
  2772. struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
  2773. if (ucontrol->value.enumerated.item[0] == 2)
  2774. return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
  2775. snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
  2776. return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
  2777. ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
  2778. }
  2779. static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
  2780. static const struct ac97_enum cm9761_dac_clock_enum =
  2781. AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
  2782. static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
  2783. { /* BIT 1: SPDIFS */
  2784. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2785. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  2786. .info = cm9761_spdif_out_source_info,
  2787. .get = cm9761_spdif_out_source_get,
  2788. .put = cm9761_spdif_out_source_put,
  2789. },
  2790. /* BIT 2: IG_SPIV */
  2791. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
  2792. /* BIT 3: SPI2F */
  2793. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
  2794. /* BIT 4: SPI2SDI */
  2795. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
  2796. /* BIT 9-10: DAC_CTL */
  2797. AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
  2798. };
  2799. static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
  2800. {
  2801. return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
  2802. }
  2803. static int patch_cm9761_specific(struct snd_ac97 * ac97)
  2804. {
  2805. return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
  2806. }
  2807. static struct snd_ac97_build_ops patch_cm9761_ops = {
  2808. .build_specific = patch_cm9761_specific,
  2809. .build_post_spdif = patch_cm9761_post_spdif,
  2810. .update_jacks = cm9761_update_jacks
  2811. };
  2812. static int patch_cm9761(struct snd_ac97 *ac97)
  2813. {
  2814. unsigned short val;
  2815. /* CM9761 has no PCM volume although the register reacts */
  2816. /* Master volume seems to have _some_ influence on the analog
  2817. * input sounds
  2818. */
  2819. ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
  2820. snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
  2821. snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
  2822. ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
  2823. if (ac97->id == AC97_ID_CM9761_82) {
  2824. unsigned short tmp;
  2825. /* check page 1, reg 0x60 */
  2826. val = snd_ac97_read(ac97, AC97_INT_PAGING);
  2827. snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
  2828. tmp = snd_ac97_read(ac97, 0x60);
  2829. ac97->spec.dev_flags = tmp & 1; /* revision B? */
  2830. snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
  2831. } else if (ac97->id == AC97_ID_CM9761_83)
  2832. ac97->spec.dev_flags = 2;
  2833. ac97->build_ops = &patch_cm9761_ops;
  2834. /* enable spdif */
  2835. /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
  2836. ac97->ext_id |= AC97_EI_SPDIF;
  2837. /* to be sure: we overwrite the ext status bits */
  2838. snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
  2839. /* Don't set 0x0200 here. This results in the silent analog output */
  2840. snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
  2841. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
  2842. /* set-up multi channel */
  2843. /* bit 15: pc master beep off
  2844. * bit 14: pin47 = EAPD/SPDIF
  2845. * bit 13: vref ctl [= cm9739]
  2846. * bit 12: CLFE control (reverted on rev B)
  2847. * bit 11: Mic/center share (reverted on rev B)
  2848. * bit 10: suddound/line share
  2849. * bit 9: Analog-in mix -> surround
  2850. * bit 8: Analog-in mix -> CLFE
  2851. * bit 7: Mic/LFE share (mic/center/lfe)
  2852. * bit 5: vref select (9761A)
  2853. * bit 4: front control
  2854. * bit 3: surround control (revereted with rev B)
  2855. * bit 2: front mic
  2856. * bit 1: stereo mic
  2857. * bit 0: mic boost level (0=20dB, 1=30dB)
  2858. */
  2859. #if 0
  2860. if (ac97->spec.dev_flags)
  2861. val = 0x0214;
  2862. else
  2863. val = 0x321c;
  2864. #endif
  2865. val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
  2866. val |= (1 << 4); /* front on */
  2867. snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
  2868. /* FIXME: set up GPIO */
  2869. snd_ac97_write_cache(ac97, 0x70, 0x0100);
  2870. snd_ac97_write_cache(ac97, 0x72, 0x0020);
  2871. return 0;
  2872. }
  2873. #define AC97_CM9780_SIDE 0x60
  2874. #define AC97_CM9780_JACK 0x62
  2875. #define AC97_CM9780_MIXER 0x64
  2876. #define AC97_CM9780_MULTI_CHAN 0x66
  2877. #define AC97_CM9780_SPDIF 0x6c
  2878. static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
  2879. static const struct ac97_enum cm9780_ch_select_enum =
  2880. AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
  2881. static const struct snd_kcontrol_new cm9780_controls[] = {
  2882. AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
  2883. AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
  2884. AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
  2885. };
  2886. static int patch_cm9780_specific(struct snd_ac97 *ac97)
  2887. {
  2888. return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
  2889. }
  2890. static struct snd_ac97_build_ops patch_cm9780_ops = {
  2891. .build_specific = patch_cm9780_specific,
  2892. .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
  2893. };
  2894. static int patch_cm9780(struct snd_ac97 *ac97)
  2895. {
  2896. unsigned short val;
  2897. ac97->build_ops = &patch_cm9780_ops;
  2898. /* enable spdif */
  2899. if (ac97->ext_id & AC97_EI_SPDIF) {
  2900. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
  2901. val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
  2902. val |= 0x1; /* SPDI_EN */
  2903. snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
  2904. }
  2905. return 0;
  2906. }
  2907. /*
  2908. * VIA VT1616 codec
  2909. */
  2910. static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
  2911. AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
  2912. AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
  2913. AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
  2914. AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
  2915. };
  2916. static const char *slave_vols_vt1616[] = {
  2917. "Front Playback Volume",
  2918. "Surround Playback Volume",
  2919. "Center Playback Volume",
  2920. "LFE Playback Volume",
  2921. NULL
  2922. };
  2923. static const char *slave_sws_vt1616[] = {
  2924. "Front Playback Switch",
  2925. "Surround Playback Switch",
  2926. "Center Playback Switch",
  2927. "LFE Playback Switch",
  2928. NULL
  2929. };
  2930. /* find a mixer control element with the given name */
  2931. static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
  2932. const char *name)
  2933. {
  2934. struct snd_ctl_elem_id id;
  2935. memset(&id, 0, sizeof(id));
  2936. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  2937. strcpy(id.name, name);
  2938. return snd_ctl_find_id(ac97->bus->card, &id);
  2939. }
  2940. /* create a virtual master control and add slaves */
  2941. static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
  2942. const unsigned int *tlv, const char **slaves)
  2943. {
  2944. struct snd_kcontrol *kctl;
  2945. const char **s;
  2946. int err;
  2947. kctl = snd_ctl_make_virtual_master(name, tlv);
  2948. if (!kctl)
  2949. return -ENOMEM;
  2950. err = snd_ctl_add(ac97->bus->card, kctl);
  2951. if (err < 0)
  2952. return err;
  2953. for (s = slaves; *s; s++) {
  2954. struct snd_kcontrol *sctl;
  2955. sctl = snd_ac97_find_mixer_ctl(ac97, *s);
  2956. if (!sctl) {
  2957. snd_printdd("Cannot find slave %s, skipped\n", *s);
  2958. continue;
  2959. }
  2960. err = snd_ctl_add_slave(kctl, sctl);
  2961. if (err < 0)
  2962. return err;
  2963. }
  2964. return 0;
  2965. }
  2966. static int patch_vt1616_specific(struct snd_ac97 * ac97)
  2967. {
  2968. struct snd_kcontrol *kctl;
  2969. int err;
  2970. if (snd_ac97_try_bit(ac97, 0x5a, 9))
  2971. if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
  2972. return err;
  2973. if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
  2974. return err;
  2975. /* There is already a misnamed master switch. Rename it. */
  2976. kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
  2977. if (!kctl)
  2978. return -EINVAL;
  2979. snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
  2980. err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
  2981. kctl->tlv.p, slave_vols_vt1616);
  2982. if (err < 0)
  2983. return err;
  2984. err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
  2985. NULL, slave_sws_vt1616);
  2986. if (err < 0)
  2987. return err;
  2988. return 0;
  2989. }
  2990. static struct snd_ac97_build_ops patch_vt1616_ops = {
  2991. .build_specific = patch_vt1616_specific
  2992. };
  2993. static int patch_vt1616(struct snd_ac97 * ac97)
  2994. {
  2995. ac97->build_ops = &patch_vt1616_ops;
  2996. return 0;
  2997. }
  2998. /*
  2999. * VT1617A codec
  3000. */
  3001. /*
  3002. * unfortunately, the vt1617a stashes the twiddlers required for
  3003. * noodling the i/o jacks on 2 different regs. that means that we can't
  3004. * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
  3005. * are own funcs.
  3006. *
  3007. * NB: this is absolutely and utterly different from the vt1618. dunno
  3008. * about the 1616.
  3009. */
  3010. /* copied from ac97_surround_jack_mode_info() */
  3011. static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
  3012. struct snd_ctl_elem_info *uinfo)
  3013. {
  3014. /* ordering in this list reflects vt1617a docs for Reg 20 and
  3015. * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
  3016. * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
  3017. * counter-intuitive */
  3018. static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3",
  3019. "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
  3020. "LineIn Mic2", "LineIn Mic2 Mic1",
  3021. "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
  3022. return ac97_enum_text_info(kcontrol, uinfo, texts, 8);
  3023. }
  3024. static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
  3025. struct snd_ctl_elem_value *ucontrol)
  3026. {
  3027. ushort usSM51, usMS;
  3028. struct snd_ac97 *pac97;
  3029. pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
  3030. /* grab our desired bits, then mash them together in a manner
  3031. * consistent with Table 6 on page 17 in the 1617a docs */
  3032. usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
  3033. usMS = snd_ac97_read(pac97, 0x20) >> 8;
  3034. ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
  3035. return 0;
  3036. }
  3037. static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
  3038. struct snd_ctl_elem_value *ucontrol)
  3039. {
  3040. ushort usSM51, usMS, usReg;
  3041. struct snd_ac97 *pac97;
  3042. pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
  3043. usSM51 = ucontrol->value.enumerated.item[0] >> 1;
  3044. usMS = ucontrol->value.enumerated.item[0] & 1;
  3045. /* push our values into the register - consider that things will be left
  3046. * in a funky state if the write fails */
  3047. usReg = snd_ac97_read(pac97, 0x7a);
  3048. snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
  3049. usReg = snd_ac97_read(pac97, 0x20);
  3050. snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
  3051. return 0;
  3052. }
  3053. static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
  3054. AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
  3055. /*
  3056. * These are used to enable/disable surround sound on motherboards
  3057. * that have 3 bidirectional analog jacks
  3058. */
  3059. {
  3060. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3061. .name = "Smart 5.1 Select",
  3062. .info = snd_ac97_vt1617a_smart51_info,
  3063. .get = snd_ac97_vt1617a_smart51_get,
  3064. .put = snd_ac97_vt1617a_smart51_put,
  3065. },
  3066. };
  3067. static int patch_vt1617a(struct snd_ac97 * ac97)
  3068. {
  3069. int err = 0;
  3070. int val;
  3071. /* we choose to not fail out at this point, but we tell the
  3072. caller when we return */
  3073. err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
  3074. ARRAY_SIZE(snd_ac97_controls_vt1617a));
  3075. /* bring analog power consumption to normal by turning off the
  3076. * headphone amplifier, like WinXP driver for EPIA SP
  3077. */
  3078. /* We need to check the bit before writing it.
  3079. * On some (many?) hardwares, setting bit actually clears it!
  3080. */
  3081. val = snd_ac97_read(ac97, 0x5c);
  3082. if (!(val & 0x20))
  3083. snd_ac97_write_cache(ac97, 0x5c, 0x20);
  3084. ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
  3085. ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
  3086. ac97->build_ops = &patch_vt1616_ops;
  3087. return err;
  3088. }
  3089. /* VIA VT1618 8 CHANNEL AC97 CODEC
  3090. *
  3091. * VIA implements 'Smart 5.1' completely differently on the 1618 than
  3092. * it does on the 1617a. awesome! They seem to have sourced this
  3093. * particular revision of the technology from somebody else, it's
  3094. * called Universal Audio Jack and it shows up on some other folk's chips
  3095. * as well.
  3096. *
  3097. * ordering in this list reflects vt1618 docs for Reg 60h and
  3098. * the block diagram, DACs are as follows:
  3099. *
  3100. * OUT_O -> Front,
  3101. * OUT_1 -> Surround,
  3102. * OUT_2 -> C/LFE
  3103. *
  3104. * Unlike the 1617a, each OUT has a consistent set of mappings
  3105. * for all bitpatterns other than 00:
  3106. *
  3107. * 01 Unmixed Output
  3108. * 10 Line In
  3109. * 11 Mic In
  3110. *
  3111. * Special Case of 00:
  3112. *
  3113. * OUT_0 Mixed Output
  3114. * OUT_1 Reserved
  3115. * OUT_2 Reserved
  3116. *
  3117. * I have no idea what the hell Reserved does, but on an MSI
  3118. * CN700T, i have to set it to get 5.1 output - YMMV, bad
  3119. * shit may happen.
  3120. *
  3121. * If other chips use Universal Audio Jack, then this code might be applicable
  3122. * to them.
  3123. */
  3124. struct vt1618_uaj_item {
  3125. unsigned short mask;
  3126. unsigned short shift;
  3127. const char *items[4];
  3128. };
  3129. /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
  3130. static struct vt1618_uaj_item vt1618_uaj[3] = {
  3131. {
  3132. /* speaker jack */
  3133. .mask = 0x03,
  3134. .shift = 0,
  3135. .items = {
  3136. "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
  3137. }
  3138. },
  3139. {
  3140. /* line jack */
  3141. .mask = 0x0c,
  3142. .shift = 2,
  3143. .items = {
  3144. "Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
  3145. }
  3146. },
  3147. {
  3148. /* mic jack */
  3149. .mask = 0x30,
  3150. .shift = 4,
  3151. .items = {
  3152. "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
  3153. },
  3154. },
  3155. };
  3156. static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
  3157. struct snd_ctl_elem_info *uinfo)
  3158. {
  3159. return ac97_enum_text_info(kcontrol, uinfo,
  3160. vt1618_uaj[kcontrol->private_value].items,
  3161. 4);
  3162. }
  3163. /* All of the vt1618 Universal Audio Jack twiddlers are on
  3164. * Vendor Defined Register 0x60, page 0. The bits, and thus
  3165. * the mask, are the only thing that changes
  3166. */
  3167. static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
  3168. struct snd_ctl_elem_value *ucontrol)
  3169. {
  3170. unsigned short datpag, uaj;
  3171. struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
  3172. mutex_lock(&pac97->page_mutex);
  3173. datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
  3174. snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
  3175. uaj = snd_ac97_read(pac97, 0x60) &
  3176. vt1618_uaj[kcontrol->private_value].mask;
  3177. snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
  3178. mutex_unlock(&pac97->page_mutex);
  3179. ucontrol->value.enumerated.item[0] = uaj >>
  3180. vt1618_uaj[kcontrol->private_value].shift;
  3181. return 0;
  3182. }
  3183. static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
  3184. struct snd_ctl_elem_value *ucontrol)
  3185. {
  3186. return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
  3187. vt1618_uaj[kcontrol->private_value].mask,
  3188. ucontrol->value.enumerated.item[0]<<
  3189. vt1618_uaj[kcontrol->private_value].shift,
  3190. 0);
  3191. }
  3192. /* config aux in jack - not found on 3 jack motherboards or soundcards */
  3193. static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
  3194. struct snd_ctl_elem_info *uinfo)
  3195. {
  3196. static const char *txt_aux[] = {"Aux In", "Back Surr Out"};
  3197. return ac97_enum_text_info(kcontrol, uinfo, txt_aux, 2);
  3198. }
  3199. static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
  3200. struct snd_ctl_elem_value *ucontrol)
  3201. {
  3202. ucontrol->value.enumerated.item[0] =
  3203. (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
  3204. return 0;
  3205. }
  3206. static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
  3207. struct snd_ctl_elem_value *ucontrol)
  3208. {
  3209. /* toggle surround rear dac power */
  3210. snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
  3211. ucontrol->value.enumerated.item[0] << 3);
  3212. /* toggle aux in surround rear out jack */
  3213. return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
  3214. ucontrol->value.enumerated.item[0] << 3);
  3215. }
  3216. static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
  3217. AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0),
  3218. AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0),
  3219. AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1),
  3220. AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1),
  3221. AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1),
  3222. AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1),
  3223. {
  3224. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3225. .name = "Speaker Jack Mode",
  3226. .info = snd_ac97_vt1618_UAJ_info,
  3227. .get = snd_ac97_vt1618_UAJ_get,
  3228. .put = snd_ac97_vt1618_UAJ_put,
  3229. .private_value = 0
  3230. },
  3231. {
  3232. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3233. .name = "Line Jack Mode",
  3234. .info = snd_ac97_vt1618_UAJ_info,
  3235. .get = snd_ac97_vt1618_UAJ_get,
  3236. .put = snd_ac97_vt1618_UAJ_put,
  3237. .private_value = 1
  3238. },
  3239. {
  3240. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3241. .name = "Mic Jack Mode",
  3242. .info = snd_ac97_vt1618_UAJ_info,
  3243. .get = snd_ac97_vt1618_UAJ_get,
  3244. .put = snd_ac97_vt1618_UAJ_put,
  3245. .private_value = 2
  3246. },
  3247. {
  3248. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3249. .name = "Aux Jack Mode",
  3250. .info = snd_ac97_vt1618_aux_info,
  3251. .get = snd_ac97_vt1618_aux_get,
  3252. .put = snd_ac97_vt1618_aux_put,
  3253. }
  3254. };
  3255. static int patch_vt1618(struct snd_ac97 *ac97)
  3256. {
  3257. return patch_build_controls(ac97, snd_ac97_controls_vt1618,
  3258. ARRAY_SIZE(snd_ac97_controls_vt1618));
  3259. }
  3260. /*
  3261. */
  3262. static void it2646_update_jacks(struct snd_ac97 *ac97)
  3263. {
  3264. /* shared Line-In / Surround Out */
  3265. snd_ac97_update_bits(ac97, 0x76, 1 << 9,
  3266. is_shared_surrout(ac97) ? (1<<9) : 0);
  3267. /* shared Mic / Center/LFE Out */
  3268. snd_ac97_update_bits(ac97, 0x76, 1 << 10,
  3269. is_shared_clfeout(ac97) ? (1<<10) : 0);
  3270. }
  3271. static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
  3272. AC97_SURROUND_JACK_MODE_CTL,
  3273. AC97_CHANNEL_MODE_CTL,
  3274. };
  3275. static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
  3276. AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
  3277. AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
  3278. AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
  3279. };
  3280. static int patch_it2646_specific(struct snd_ac97 * ac97)
  3281. {
  3282. int err;
  3283. if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
  3284. return err;
  3285. if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
  3286. return err;
  3287. return 0;
  3288. }
  3289. static struct snd_ac97_build_ops patch_it2646_ops = {
  3290. .build_specific = patch_it2646_specific,
  3291. .update_jacks = it2646_update_jacks
  3292. };
  3293. static int patch_it2646(struct snd_ac97 * ac97)
  3294. {
  3295. ac97->build_ops = &patch_it2646_ops;
  3296. /* full DAC volume */
  3297. snd_ac97_write_cache(ac97, 0x5E, 0x0808);
  3298. snd_ac97_write_cache(ac97, 0x7A, 0x0808);
  3299. return 0;
  3300. }
  3301. /*
  3302. * Si3036 codec
  3303. */
  3304. #define AC97_SI3036_CHIP_ID 0x5a
  3305. #define AC97_SI3036_LINE_CFG 0x5c
  3306. static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
  3307. AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
  3308. };
  3309. static int patch_si3036_specific(struct snd_ac97 * ac97)
  3310. {
  3311. int idx, err;
  3312. for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
  3313. if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
  3314. return err;
  3315. return 0;
  3316. }
  3317. static struct snd_ac97_build_ops patch_si3036_ops = {
  3318. .build_specific = patch_si3036_specific,
  3319. };
  3320. static int mpatch_si3036(struct snd_ac97 * ac97)
  3321. {
  3322. ac97->build_ops = &patch_si3036_ops;
  3323. snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
  3324. snd_ac97_write_cache(ac97, 0x68, 0);
  3325. return 0;
  3326. }
  3327. /*
  3328. * LM 4550 Codec
  3329. *
  3330. * We use a static resolution table since LM4550 codec cannot be
  3331. * properly autoprobed to determine the resolution via
  3332. * check_volume_resolution().
  3333. */
  3334. static struct snd_ac97_res_table lm4550_restbl[] = {
  3335. { AC97_MASTER, 0x1f1f },
  3336. { AC97_HEADPHONE, 0x1f1f },
  3337. { AC97_MASTER_MONO, 0x001f },
  3338. { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
  3339. { AC97_PHONE, 0x001f },
  3340. { AC97_MIC, 0x001f },
  3341. { AC97_LINE, 0x1f1f },
  3342. { AC97_CD, 0x1f1f },
  3343. { AC97_VIDEO, 0x1f1f },
  3344. { AC97_AUX, 0x1f1f },
  3345. { AC97_PCM, 0x1f1f },
  3346. { AC97_REC_GAIN, 0x0f0f },
  3347. { } /* terminator */
  3348. };
  3349. static int patch_lm4550(struct snd_ac97 *ac97)
  3350. {
  3351. ac97->res_table = lm4550_restbl;
  3352. return 0;
  3353. }
  3354. /*
  3355. * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
  3356. */
  3357. static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
  3358. /* enable/disable headphone driver which allows direct connection to
  3359. stereo headphone without the use of external DC blocking
  3360. capacitors */
  3361. AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
  3362. /* Filter used to compensate the DC offset is added in the ADC to remove idle
  3363. tones from the audio band. */
  3364. AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
  3365. /* Control smart-low-power mode feature. Allows automatic power down
  3366. of unused blocks in the ADC analog front end and the PLL. */
  3367. AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
  3368. };
  3369. static int patch_ucb1400_specific(struct snd_ac97 * ac97)
  3370. {
  3371. int idx, err;
  3372. for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
  3373. if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
  3374. return err;
  3375. return 0;
  3376. }
  3377. static struct snd_ac97_build_ops patch_ucb1400_ops = {
  3378. .build_specific = patch_ucb1400_specific,
  3379. };
  3380. static int patch_ucb1400(struct snd_ac97 * ac97)
  3381. {
  3382. ac97->build_ops = &patch_ucb1400_ops;
  3383. /* enable headphone driver and smart low power mode by default */
  3384. snd_ac97_write_cache(ac97, 0x6a, 0x0050);
  3385. snd_ac97_write_cache(ac97, 0x6c, 0x0030);
  3386. return 0;
  3387. }