ac97_patch.c 127 KB

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