ac97_patch.c 125 KB

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