ac97_patch.c 115 KB

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