ac97_patch.c 115 KB

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