patch_sigmatel.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for SigmaTel STAC92xx
  5. *
  6. * Copyright (c) 2005 Embedded Alley Solutions, Inc.
  7. * Matt Porter <mporter@embeddedalley.com>
  8. *
  9. * Based on patch_cmedia.c and patch_realtek.c
  10. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  11. *
  12. * This driver is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This driver is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <sound/driver.h>
  27. #include <linux/init.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <sound/core.h>
  32. #include <sound/asoundef.h>
  33. #include "hda_codec.h"
  34. #include "hda_local.h"
  35. #define NUM_CONTROL_ALLOC 32
  36. #define STAC_HP_EVENT 0x37
  37. enum {
  38. STAC_REF,
  39. STAC_9200_DELL_D21,
  40. STAC_9200_DELL_D22,
  41. STAC_9200_DELL_D23,
  42. STAC_9200_DELL_M21,
  43. STAC_9200_DELL_M22,
  44. STAC_9200_DELL_M23,
  45. STAC_9200_DELL_M24,
  46. STAC_9200_DELL_M25,
  47. STAC_9200_DELL_M26,
  48. STAC_9200_DELL_M27,
  49. STAC_9200_GATEWAY,
  50. STAC_9200_MODELS
  51. };
  52. enum {
  53. STAC_9205_REF,
  54. STAC_9205_DELL_M42,
  55. STAC_9205_DELL_M43,
  56. STAC_9205_DELL_M44,
  57. STAC_9205_MODELS
  58. };
  59. enum {
  60. STAC_925x_REF,
  61. STAC_M2_2,
  62. STAC_MA6,
  63. STAC_PA6,
  64. STAC_925x_MODELS
  65. };
  66. enum {
  67. STAC_D945_REF,
  68. STAC_D945GTP3,
  69. STAC_D945GTP5,
  70. STAC_INTEL_MAC_V1,
  71. STAC_INTEL_MAC_V2,
  72. STAC_INTEL_MAC_V3,
  73. STAC_INTEL_MAC_V4,
  74. STAC_INTEL_MAC_V5,
  75. /* for backward compatibility */
  76. STAC_MACMINI,
  77. STAC_MACBOOK,
  78. STAC_MACBOOK_PRO_V1,
  79. STAC_MACBOOK_PRO_V2,
  80. STAC_IMAC_INTEL,
  81. STAC_IMAC_INTEL_20,
  82. STAC_922X_DELL_D81,
  83. STAC_922X_DELL_D82,
  84. STAC_922X_DELL_M81,
  85. STAC_922X_DELL_M82,
  86. STAC_922X_MODELS
  87. };
  88. enum {
  89. STAC_D965_REF,
  90. STAC_D965_3ST,
  91. STAC_D965_5ST,
  92. STAC_DELL_3ST,
  93. STAC_927X_MODELS
  94. };
  95. struct sigmatel_spec {
  96. struct snd_kcontrol_new *mixers[4];
  97. unsigned int num_mixers;
  98. int board_config;
  99. unsigned int surr_switch: 1;
  100. unsigned int line_switch: 1;
  101. unsigned int mic_switch: 1;
  102. unsigned int alt_switch: 1;
  103. unsigned int hp_detect: 1;
  104. unsigned int gpio_mute: 1;
  105. unsigned int gpio_mask, gpio_data;
  106. /* playback */
  107. struct hda_multi_out multiout;
  108. hda_nid_t dac_nids[5];
  109. /* capture */
  110. hda_nid_t *adc_nids;
  111. unsigned int num_adcs;
  112. hda_nid_t *mux_nids;
  113. unsigned int num_muxes;
  114. hda_nid_t *dmic_nids;
  115. unsigned int num_dmics;
  116. hda_nid_t dmux_nid;
  117. hda_nid_t dig_in_nid;
  118. /* pin widgets */
  119. hda_nid_t *pin_nids;
  120. unsigned int num_pins;
  121. unsigned int *pin_configs;
  122. unsigned int *bios_pin_configs;
  123. /* codec specific stuff */
  124. struct hda_verb *init;
  125. struct snd_kcontrol_new *mixer;
  126. /* capture source */
  127. struct hda_input_mux *dinput_mux;
  128. unsigned int cur_dmux;
  129. struct hda_input_mux *input_mux;
  130. unsigned int cur_mux[3];
  131. /* i/o switches */
  132. unsigned int io_switch[2];
  133. unsigned int clfe_swap;
  134. unsigned int aloopback;
  135. struct hda_pcm pcm_rec[2]; /* PCM information */
  136. /* dynamic controls and input_mux */
  137. struct auto_pin_cfg autocfg;
  138. unsigned int num_kctl_alloc, num_kctl_used;
  139. struct snd_kcontrol_new *kctl_alloc;
  140. struct hda_input_mux private_dimux;
  141. struct hda_input_mux private_imux;
  142. };
  143. static hda_nid_t stac9200_adc_nids[1] = {
  144. 0x03,
  145. };
  146. static hda_nid_t stac9200_mux_nids[1] = {
  147. 0x0c,
  148. };
  149. static hda_nid_t stac9200_dac_nids[1] = {
  150. 0x02,
  151. };
  152. static hda_nid_t stac925x_adc_nids[1] = {
  153. 0x03,
  154. };
  155. static hda_nid_t stac925x_mux_nids[1] = {
  156. 0x0f,
  157. };
  158. static hda_nid_t stac925x_dac_nids[1] = {
  159. 0x02,
  160. };
  161. #define STAC925X_NUM_DMICS 1
  162. static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
  163. 0x15, 0
  164. };
  165. static hda_nid_t stac922x_adc_nids[2] = {
  166. 0x06, 0x07,
  167. };
  168. static hda_nid_t stac922x_mux_nids[2] = {
  169. 0x12, 0x13,
  170. };
  171. static hda_nid_t stac927x_adc_nids[3] = {
  172. 0x07, 0x08, 0x09
  173. };
  174. static hda_nid_t stac927x_mux_nids[3] = {
  175. 0x15, 0x16, 0x17
  176. };
  177. #define STAC927X_NUM_DMICS 2
  178. static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
  179. 0x13, 0x14, 0
  180. };
  181. static hda_nid_t stac9205_adc_nids[2] = {
  182. 0x12, 0x13
  183. };
  184. static hda_nid_t stac9205_mux_nids[2] = {
  185. 0x19, 0x1a
  186. };
  187. #define STAC9205_NUM_DMICS 2
  188. static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
  189. 0x17, 0x18, 0
  190. };
  191. static hda_nid_t stac9200_pin_nids[8] = {
  192. 0x08, 0x09, 0x0d, 0x0e,
  193. 0x0f, 0x10, 0x11, 0x12,
  194. };
  195. static hda_nid_t stac925x_pin_nids[8] = {
  196. 0x07, 0x08, 0x0a, 0x0b,
  197. 0x0c, 0x0d, 0x10, 0x11,
  198. };
  199. static hda_nid_t stac922x_pin_nids[10] = {
  200. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  201. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  202. };
  203. static hda_nid_t stac927x_pin_nids[14] = {
  204. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  205. 0x0f, 0x10, 0x11, 0x12, 0x13,
  206. 0x14, 0x21, 0x22, 0x23,
  207. };
  208. static hda_nid_t stac9205_pin_nids[12] = {
  209. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  210. 0x0f, 0x14, 0x16, 0x17, 0x18,
  211. 0x21, 0x22,
  212. };
  213. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  214. struct snd_ctl_elem_info *uinfo)
  215. {
  216. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  217. struct sigmatel_spec *spec = codec->spec;
  218. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  219. }
  220. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  221. struct snd_ctl_elem_value *ucontrol)
  222. {
  223. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  224. struct sigmatel_spec *spec = codec->spec;
  225. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  226. return 0;
  227. }
  228. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  229. struct snd_ctl_elem_value *ucontrol)
  230. {
  231. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  232. struct sigmatel_spec *spec = codec->spec;
  233. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  234. spec->dmux_nid, &spec->cur_dmux);
  235. }
  236. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  237. {
  238. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  239. struct sigmatel_spec *spec = codec->spec;
  240. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  241. }
  242. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  243. {
  244. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  245. struct sigmatel_spec *spec = codec->spec;
  246. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  247. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  248. return 0;
  249. }
  250. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  251. {
  252. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  253. struct sigmatel_spec *spec = codec->spec;
  254. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  255. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  256. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  257. }
  258. #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
  259. static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
  260. struct snd_ctl_elem_value *ucontrol)
  261. {
  262. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  263. struct sigmatel_spec *spec = codec->spec;
  264. ucontrol->value.integer.value[0] = spec->aloopback;
  265. return 0;
  266. }
  267. static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
  268. struct snd_ctl_elem_value *ucontrol)
  269. {
  270. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  271. struct sigmatel_spec *spec = codec->spec;
  272. unsigned int dac_mode;
  273. if (spec->aloopback == ucontrol->value.integer.value[0])
  274. return 0;
  275. spec->aloopback = ucontrol->value.integer.value[0];
  276. dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
  277. kcontrol->private_value & 0xFFFF, 0x0);
  278. if (spec->aloopback) {
  279. snd_hda_power_up(codec);
  280. dac_mode |= 0x40;
  281. } else {
  282. snd_hda_power_down(codec);
  283. dac_mode &= ~0x40;
  284. }
  285. snd_hda_codec_write_cache(codec, codec->afg, 0,
  286. kcontrol->private_value >> 16, dac_mode);
  287. return 1;
  288. }
  289. static struct hda_verb stac9200_core_init[] = {
  290. /* set dac0mux for dac converter */
  291. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  292. {}
  293. };
  294. static struct hda_verb stac9200_eapd_init[] = {
  295. /* set dac0mux for dac converter */
  296. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  297. {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  298. {}
  299. };
  300. static struct hda_verb stac925x_core_init[] = {
  301. /* set dac0mux for dac converter */
  302. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  303. {}
  304. };
  305. static struct hda_verb stac922x_core_init[] = {
  306. /* set master volume and direct control */
  307. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  308. {}
  309. };
  310. static struct hda_verb d965_core_init[] = {
  311. /* set master volume and direct control */
  312. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  313. /* unmute node 0x1b */
  314. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  315. /* select node 0x03 as DAC */
  316. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  317. {}
  318. };
  319. static struct hda_verb stac927x_core_init[] = {
  320. /* set master volume and direct control */
  321. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  322. {}
  323. };
  324. static struct hda_verb stac9205_core_init[] = {
  325. /* set master volume and direct control */
  326. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  327. {}
  328. };
  329. #define STAC_DIGITAL_INPUT_SOURCE(cnt) \
  330. { \
  331. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  332. .name = "Digital Input Source", \
  333. .count = cnt, \
  334. .info = stac92xx_dmux_enum_info, \
  335. .get = stac92xx_dmux_enum_get, \
  336. .put = stac92xx_dmux_enum_put,\
  337. }
  338. #define STAC_INPUT_SOURCE(cnt) \
  339. { \
  340. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  341. .name = "Input Source", \
  342. .count = cnt, \
  343. .info = stac92xx_mux_enum_info, \
  344. .get = stac92xx_mux_enum_get, \
  345. .put = stac92xx_mux_enum_put, \
  346. }
  347. #define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
  348. { \
  349. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  350. .name = "Analog Loopback", \
  351. .count = 1, \
  352. .info = stac92xx_aloopback_info, \
  353. .get = stac92xx_aloopback_get, \
  354. .put = stac92xx_aloopback_put, \
  355. .private_value = verb_read | (verb_write << 16), \
  356. }
  357. static struct snd_kcontrol_new stac9200_mixer[] = {
  358. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  359. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  360. STAC_INPUT_SOURCE(1),
  361. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  362. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  363. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  364. { } /* end */
  365. };
  366. static struct snd_kcontrol_new stac925x_mixer[] = {
  367. STAC_INPUT_SOURCE(1),
  368. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
  369. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
  370. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
  371. { } /* end */
  372. };
  373. static struct snd_kcontrol_new stac9205_mixer[] = {
  374. STAC_DIGITAL_INPUT_SOURCE(1),
  375. STAC_INPUT_SOURCE(2),
  376. STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
  377. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
  378. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
  379. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
  380. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
  381. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
  382. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
  383. { } /* end */
  384. };
  385. /* This needs to be generated dynamically based on sequence */
  386. static struct snd_kcontrol_new stac922x_mixer[] = {
  387. STAC_INPUT_SOURCE(2),
  388. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
  389. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
  390. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
  391. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
  392. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
  393. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
  394. { } /* end */
  395. };
  396. static struct snd_kcontrol_new stac927x_mixer[] = {
  397. STAC_DIGITAL_INPUT_SOURCE(1),
  398. STAC_INPUT_SOURCE(3),
  399. STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
  400. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
  401. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
  402. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
  403. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
  404. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
  405. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
  406. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
  407. HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
  408. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
  409. { } /* end */
  410. };
  411. static int stac92xx_build_controls(struct hda_codec *codec)
  412. {
  413. struct sigmatel_spec *spec = codec->spec;
  414. int err;
  415. int i;
  416. err = snd_hda_add_new_ctls(codec, spec->mixer);
  417. if (err < 0)
  418. return err;
  419. for (i = 0; i < spec->num_mixers; i++) {
  420. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  421. if (err < 0)
  422. return err;
  423. }
  424. if (spec->multiout.dig_out_nid) {
  425. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  426. if (err < 0)
  427. return err;
  428. }
  429. if (spec->dig_in_nid) {
  430. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  431. if (err < 0)
  432. return err;
  433. }
  434. return 0;
  435. }
  436. static unsigned int ref9200_pin_configs[8] = {
  437. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  438. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  439. };
  440. /*
  441. STAC 9200 pin configs for
  442. 102801A8
  443. 102801DE
  444. 102801E8
  445. */
  446. static unsigned int dell9200_d21_pin_configs[8] = {
  447. 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
  448. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  449. };
  450. /*
  451. STAC 9200 pin configs for
  452. 102801C0
  453. 102801C1
  454. */
  455. static unsigned int dell9200_d22_pin_configs[8] = {
  456. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  457. 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
  458. };
  459. /*
  460. STAC 9200 pin configs for
  461. 102801C4 (Dell Dimension E310)
  462. 102801C5
  463. 102801C7
  464. 102801D9
  465. 102801DA
  466. 102801E3
  467. */
  468. static unsigned int dell9200_d23_pin_configs[8] = {
  469. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  470. 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
  471. };
  472. /*
  473. STAC 9200-32 pin configs for
  474. 102801B5 (Dell Inspiron 630m)
  475. 102801D8 (Dell Inspiron 640m)
  476. */
  477. static unsigned int dell9200_m21_pin_configs[8] = {
  478. 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
  479. 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
  480. };
  481. /*
  482. STAC 9200-32 pin configs for
  483. 102801C2 (Dell Latitude D620)
  484. 102801C8
  485. 102801CC (Dell Latitude D820)
  486. 102801D4
  487. 102801D6
  488. */
  489. static unsigned int dell9200_m22_pin_configs[8] = {
  490. 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
  491. 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
  492. };
  493. /*
  494. STAC 9200-32 pin configs for
  495. 102801CE (Dell XPS M1710)
  496. 102801CF (Dell Precision M90)
  497. */
  498. static unsigned int dell9200_m23_pin_configs[8] = {
  499. 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
  500. 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
  501. };
  502. /*
  503. STAC 9200-32 pin configs for
  504. 102801C9
  505. 102801CA
  506. 102801CB (Dell Latitude 120L)
  507. 102801D3
  508. */
  509. static unsigned int dell9200_m24_pin_configs[8] = {
  510. 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
  511. 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
  512. };
  513. /*
  514. STAC 9200-32 pin configs for
  515. 102801BD (Dell Inspiron E1505n)
  516. 102801EE
  517. 102801EF
  518. */
  519. static unsigned int dell9200_m25_pin_configs[8] = {
  520. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  521. 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
  522. };
  523. /*
  524. STAC 9200-32 pin configs for
  525. 102801F5 (Dell Inspiron 1501)
  526. 102801F6
  527. */
  528. static unsigned int dell9200_m26_pin_configs[8] = {
  529. 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
  530. 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
  531. };
  532. /*
  533. STAC 9200-32
  534. 102801CD (Dell Inspiron E1705/9400)
  535. */
  536. static unsigned int dell9200_m27_pin_configs[8] = {
  537. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  538. 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
  539. };
  540. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  541. [STAC_REF] = ref9200_pin_configs,
  542. [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
  543. [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
  544. [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
  545. [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
  546. [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
  547. [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
  548. [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
  549. [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
  550. [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
  551. [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
  552. };
  553. static const char *stac9200_models[STAC_9200_MODELS] = {
  554. [STAC_REF] = "ref",
  555. [STAC_9200_DELL_D21] = "dell-d21",
  556. [STAC_9200_DELL_D22] = "dell-d22",
  557. [STAC_9200_DELL_D23] = "dell-d23",
  558. [STAC_9200_DELL_M21] = "dell-m21",
  559. [STAC_9200_DELL_M22] = "dell-m22",
  560. [STAC_9200_DELL_M23] = "dell-m23",
  561. [STAC_9200_DELL_M24] = "dell-m24",
  562. [STAC_9200_DELL_M25] = "dell-m25",
  563. [STAC_9200_DELL_M26] = "dell-m26",
  564. [STAC_9200_DELL_M27] = "dell-m27",
  565. [STAC_9200_GATEWAY] = "gateway",
  566. };
  567. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  568. /* SigmaTel reference board */
  569. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  570. "DFI LanParty", STAC_REF),
  571. /* Dell laptops have BIOS problem */
  572. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
  573. "unknown Dell", STAC_9200_DELL_D21),
  574. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  575. "Dell Inspiron 630m", STAC_9200_DELL_M21),
  576. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
  577. "Dell Inspiron E1505n", STAC_9200_DELL_M25),
  578. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
  579. "unknown Dell", STAC_9200_DELL_D22),
  580. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
  581. "unknown Dell", STAC_9200_DELL_D22),
  582. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  583. "Dell Latitude D620", STAC_9200_DELL_M22),
  584. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
  585. "unknown Dell", STAC_9200_DELL_D23),
  586. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
  587. "unknown Dell", STAC_9200_DELL_D23),
  588. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
  589. "unknown Dell", STAC_9200_DELL_M22),
  590. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
  591. "unknown Dell", STAC_9200_DELL_M24),
  592. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
  593. "unknown Dell", STAC_9200_DELL_M24),
  594. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  595. "Dell Latitude 120L", STAC_9200_DELL_M24),
  596. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  597. "Dell Latitude D820", STAC_9200_DELL_M22),
  598. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  599. "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
  600. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  601. "Dell XPS M1710", STAC_9200_DELL_M23),
  602. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  603. "Dell Precision M90", STAC_9200_DELL_M23),
  604. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
  605. "unknown Dell", STAC_9200_DELL_M22),
  606. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
  607. "unknown Dell", STAC_9200_DELL_M22),
  608. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  609. "unknown Dell", STAC_9200_DELL_M22),
  610. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  611. "Dell Inspiron 640m", STAC_9200_DELL_M21),
  612. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
  613. "unknown Dell", STAC_9200_DELL_D23),
  614. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
  615. "unknown Dell", STAC_9200_DELL_D23),
  616. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
  617. "unknown Dell", STAC_9200_DELL_D21),
  618. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
  619. "unknown Dell", STAC_9200_DELL_D23),
  620. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
  621. "unknown Dell", STAC_9200_DELL_D21),
  622. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
  623. "unknown Dell", STAC_9200_DELL_M25),
  624. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
  625. "unknown Dell", STAC_9200_DELL_M25),
  626. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  627. "Dell Inspiron 1501", STAC_9200_DELL_M26),
  628. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
  629. "unknown Dell", STAC_9200_DELL_M26),
  630. /* Panasonic */
  631. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
  632. /* Gateway machines needs EAPD to be set on resume */
  633. SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
  634. SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
  635. STAC_9200_GATEWAY),
  636. SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
  637. STAC_9200_GATEWAY),
  638. {} /* terminator */
  639. };
  640. static unsigned int ref925x_pin_configs[8] = {
  641. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  642. 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
  643. };
  644. static unsigned int stac925x_MA6_pin_configs[8] = {
  645. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  646. 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
  647. };
  648. static unsigned int stac925x_PA6_pin_configs[8] = {
  649. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  650. 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
  651. };
  652. static unsigned int stac925xM2_2_pin_configs[8] = {
  653. 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
  654. 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
  655. };
  656. static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  657. [STAC_REF] = ref925x_pin_configs,
  658. [STAC_M2_2] = stac925xM2_2_pin_configs,
  659. [STAC_MA6] = stac925x_MA6_pin_configs,
  660. [STAC_PA6] = stac925x_PA6_pin_configs,
  661. };
  662. static const char *stac925x_models[STAC_925x_MODELS] = {
  663. [STAC_REF] = "ref",
  664. [STAC_M2_2] = "m2-2",
  665. [STAC_MA6] = "m6",
  666. [STAC_PA6] = "pa6",
  667. };
  668. static struct snd_pci_quirk stac925x_cfg_tbl[] = {
  669. /* SigmaTel reference board */
  670. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  671. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  672. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
  673. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
  674. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
  675. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
  676. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
  677. {} /* terminator */
  678. };
  679. static unsigned int ref922x_pin_configs[10] = {
  680. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  681. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  682. 0x40000100, 0x40000100,
  683. };
  684. /*
  685. STAC 922X pin configs for
  686. 102801A7
  687. 102801AB
  688. 102801A9
  689. 102801D1
  690. 102801D2
  691. */
  692. static unsigned int dell_922x_d81_pin_configs[10] = {
  693. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  694. 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
  695. 0x01813122, 0x400001f2,
  696. };
  697. /*
  698. STAC 922X pin configs for
  699. 102801AC
  700. 102801D0
  701. */
  702. static unsigned int dell_922x_d82_pin_configs[10] = {
  703. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  704. 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
  705. 0x01813122, 0x400001f1,
  706. };
  707. /*
  708. STAC 922X pin configs for
  709. 102801BF
  710. */
  711. static unsigned int dell_922x_m81_pin_configs[10] = {
  712. 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
  713. 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
  714. 0x40C003f1, 0x405003f0,
  715. };
  716. /*
  717. STAC 9221 A1 pin configs for
  718. 102801D7 (Dell XPS M1210)
  719. */
  720. static unsigned int dell_922x_m82_pin_configs[10] = {
  721. 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
  722. 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
  723. 0x508003f3, 0x405003f4,
  724. };
  725. static unsigned int d945gtp3_pin_configs[10] = {
  726. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  727. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  728. 0x02a19120, 0x40000100,
  729. };
  730. static unsigned int d945gtp5_pin_configs[10] = {
  731. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  732. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  733. 0x02a19320, 0x40000100,
  734. };
  735. static unsigned int intel_mac_v1_pin_configs[10] = {
  736. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  737. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  738. 0x400000fc, 0x400000fb,
  739. };
  740. static unsigned int intel_mac_v2_pin_configs[10] = {
  741. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  742. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  743. 0x400000fc, 0x400000fb,
  744. };
  745. static unsigned int intel_mac_v3_pin_configs[10] = {
  746. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  747. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  748. 0x400000fc, 0x400000fb,
  749. };
  750. static unsigned int intel_mac_v4_pin_configs[10] = {
  751. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  752. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  753. 0x400000fc, 0x400000fb,
  754. };
  755. static unsigned int intel_mac_v5_pin_configs[10] = {
  756. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  757. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  758. 0x400000fc, 0x400000fb,
  759. };
  760. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  761. [STAC_D945_REF] = ref922x_pin_configs,
  762. [STAC_D945GTP3] = d945gtp3_pin_configs,
  763. [STAC_D945GTP5] = d945gtp5_pin_configs,
  764. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  765. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  766. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  767. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  768. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  769. /* for backward compatibility */
  770. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  771. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  772. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  773. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  774. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  775. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  776. [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
  777. [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
  778. [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
  779. [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
  780. };
  781. static const char *stac922x_models[STAC_922X_MODELS] = {
  782. [STAC_D945_REF] = "ref",
  783. [STAC_D945GTP5] = "5stack",
  784. [STAC_D945GTP3] = "3stack",
  785. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  786. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  787. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  788. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  789. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  790. /* for backward compatibility */
  791. [STAC_MACMINI] = "macmini",
  792. [STAC_MACBOOK] = "macbook",
  793. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  794. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  795. [STAC_IMAC_INTEL] = "imac-intel",
  796. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  797. [STAC_922X_DELL_D81] = "dell-d81",
  798. [STAC_922X_DELL_D82] = "dell-d82",
  799. [STAC_922X_DELL_M81] = "dell-m81",
  800. [STAC_922X_DELL_M82] = "dell-m82",
  801. };
  802. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  803. /* SigmaTel reference board */
  804. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  805. "DFI LanParty", STAC_D945_REF),
  806. /* Intel 945G based systems */
  807. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  808. "Intel D945G", STAC_D945GTP3),
  809. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  810. "Intel D945G", STAC_D945GTP3),
  811. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  812. "Intel D945G", STAC_D945GTP3),
  813. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  814. "Intel D945G", STAC_D945GTP3),
  815. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  816. "Intel D945G", STAC_D945GTP3),
  817. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  818. "Intel D945G", STAC_D945GTP3),
  819. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  820. "Intel D945G", STAC_D945GTP3),
  821. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  822. "Intel D945G", STAC_D945GTP3),
  823. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  824. "Intel D945G", STAC_D945GTP3),
  825. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  826. "Intel D945G", STAC_D945GTP3),
  827. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  828. "Intel D945G", STAC_D945GTP3),
  829. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  830. "Intel D945G", STAC_D945GTP3),
  831. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  832. "Intel D945G", STAC_D945GTP3),
  833. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  834. "Intel D945G", STAC_D945GTP3),
  835. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  836. "Intel D945G", STAC_D945GTP3),
  837. /* Intel D945G 5-stack systems */
  838. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  839. "Intel D945G", STAC_D945GTP5),
  840. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  841. "Intel D945G", STAC_D945GTP5),
  842. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  843. "Intel D945G", STAC_D945GTP5),
  844. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  845. "Intel D945G", STAC_D945GTP5),
  846. /* Intel 945P based systems */
  847. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  848. "Intel D945P", STAC_D945GTP3),
  849. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  850. "Intel D945P", STAC_D945GTP3),
  851. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  852. "Intel D945P", STAC_D945GTP3),
  853. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  854. "Intel D945P", STAC_D945GTP3),
  855. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  856. "Intel D945P", STAC_D945GTP3),
  857. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  858. "Intel D945P", STAC_D945GTP5),
  859. /* other systems */
  860. /* Apple Mac Mini (early 2006) */
  861. SND_PCI_QUIRK(0x8384, 0x7680,
  862. "Mac Mini", STAC_INTEL_MAC_V3),
  863. /* Dell systems */
  864. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
  865. "unknown Dell", STAC_922X_DELL_D81),
  866. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
  867. "unknown Dell", STAC_922X_DELL_D81),
  868. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
  869. "unknown Dell", STAC_922X_DELL_D81),
  870. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
  871. "unknown Dell", STAC_922X_DELL_D82),
  872. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
  873. "unknown Dell", STAC_922X_DELL_M81),
  874. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
  875. "unknown Dell", STAC_922X_DELL_D82),
  876. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
  877. "unknown Dell", STAC_922X_DELL_D81),
  878. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
  879. "unknown Dell", STAC_922X_DELL_D81),
  880. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
  881. "Dell XPS M1210", STAC_922X_DELL_M82),
  882. {} /* terminator */
  883. };
  884. static unsigned int ref927x_pin_configs[14] = {
  885. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  886. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  887. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  888. 0x01c42190, 0x40000100,
  889. };
  890. static unsigned int d965_3st_pin_configs[14] = {
  891. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  892. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  893. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  894. 0x40000100, 0x40000100
  895. };
  896. static unsigned int d965_5st_pin_configs[14] = {
  897. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  898. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  899. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  900. 0x40000100, 0x40000100
  901. };
  902. static unsigned int dell_3st_pin_configs[14] = {
  903. 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
  904. 0x01111212, 0x01116211, 0x01813050, 0x01112214,
  905. 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
  906. 0x40c003fc, 0x40000100
  907. };
  908. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  909. [STAC_D965_REF] = ref927x_pin_configs,
  910. [STAC_D965_3ST] = d965_3st_pin_configs,
  911. [STAC_D965_5ST] = d965_5st_pin_configs,
  912. [STAC_DELL_3ST] = dell_3st_pin_configs,
  913. };
  914. static const char *stac927x_models[STAC_927X_MODELS] = {
  915. [STAC_D965_REF] = "ref",
  916. [STAC_D965_3ST] = "3stack",
  917. [STAC_D965_5ST] = "5stack",
  918. [STAC_DELL_3ST] = "dell-3stack",
  919. };
  920. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  921. /* SigmaTel reference board */
  922. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  923. "DFI LanParty", STAC_D965_REF),
  924. /* Intel 946 based systems */
  925. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  926. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  927. /* 965 based 3 stack systems */
  928. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
  929. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
  930. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
  931. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
  932. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
  933. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
  934. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
  935. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
  936. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
  937. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
  938. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
  939. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
  940. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
  941. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
  942. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
  943. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
  944. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
  945. /* Dell 3 stack systems */
  946. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
  947. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
  948. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
  949. /* 965 based 5 stack systems */
  950. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
  951. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
  952. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
  953. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
  954. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
  955. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
  956. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
  957. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
  958. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
  959. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
  960. {} /* terminator */
  961. };
  962. static unsigned int ref9205_pin_configs[12] = {
  963. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  964. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  965. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  966. };
  967. /*
  968. STAC 9205 pin configs for
  969. 102801F1
  970. 102801F2
  971. 102801FC
  972. 102801FD
  973. 10280204
  974. 1028021F
  975. */
  976. static unsigned int dell_9205_m42_pin_configs[12] = {
  977. 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
  978. 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
  979. 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
  980. };
  981. /*
  982. STAC 9205 pin configs for
  983. 102801F9
  984. 102801FA
  985. 102801FE
  986. 102801FF (Dell Precision M4300)
  987. 10280206
  988. 10280200
  989. 10280201
  990. */
  991. static unsigned int dell_9205_m43_pin_configs[12] = {
  992. 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
  993. 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
  994. 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
  995. };
  996. static unsigned int dell_9205_m44_pin_configs[12] = {
  997. 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
  998. 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
  999. 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
  1000. };
  1001. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  1002. [STAC_9205_REF] = ref9205_pin_configs,
  1003. [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
  1004. [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
  1005. [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
  1006. };
  1007. static const char *stac9205_models[STAC_9205_MODELS] = {
  1008. [STAC_9205_REF] = "ref",
  1009. [STAC_9205_DELL_M42] = "dell-m42",
  1010. [STAC_9205_DELL_M43] = "dell-m43",
  1011. [STAC_9205_DELL_M44] = "dell-m44",
  1012. };
  1013. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  1014. /* SigmaTel reference board */
  1015. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1016. "DFI LanParty", STAC_9205_REF),
  1017. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1018. "unknown Dell", STAC_9205_DELL_M42),
  1019. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1020. "unknown Dell", STAC_9205_DELL_M42),
  1021. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
  1022. "Dell Precision", STAC_9205_DELL_M43),
  1023. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
  1024. "Dell Precision", STAC_9205_DELL_M43),
  1025. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
  1026. "Dell Precision", STAC_9205_DELL_M43),
  1027. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
  1028. "Dell Precision", STAC_9205_DELL_M43),
  1029. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
  1030. "Dell Precision", STAC_9205_DELL_M43),
  1031. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1032. "unknown Dell", STAC_9205_DELL_M42),
  1033. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1034. "unknown Dell", STAC_9205_DELL_M42),
  1035. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
  1036. "Dell Precision", STAC_9205_DELL_M43),
  1037. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
  1038. "Dell Precision M4300", STAC_9205_DELL_M43),
  1039. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
  1040. "Dell Precision", STAC_9205_DELL_M43),
  1041. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1042. "Dell Inspiron", STAC_9205_DELL_M44),
  1043. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1044. "Dell Inspiron", STAC_9205_DELL_M44),
  1045. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1046. "Dell Inspiron", STAC_9205_DELL_M44),
  1047. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1048. "Dell Inspiron", STAC_9205_DELL_M44),
  1049. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
  1050. "unknown Dell", STAC_9205_DELL_M42),
  1051. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
  1052. "Dell Inspiron", STAC_9205_DELL_M44),
  1053. {} /* terminator */
  1054. };
  1055. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  1056. {
  1057. int i;
  1058. struct sigmatel_spec *spec = codec->spec;
  1059. if (! spec->bios_pin_configs) {
  1060. spec->bios_pin_configs = kcalloc(spec->num_pins,
  1061. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  1062. if (! spec->bios_pin_configs)
  1063. return -ENOMEM;
  1064. }
  1065. for (i = 0; i < spec->num_pins; i++) {
  1066. hda_nid_t nid = spec->pin_nids[i];
  1067. unsigned int pin_cfg;
  1068. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  1069. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  1070. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  1071. nid, pin_cfg);
  1072. spec->bios_pin_configs[i] = pin_cfg;
  1073. }
  1074. return 0;
  1075. }
  1076. static void stac92xx_set_config_reg(struct hda_codec *codec,
  1077. hda_nid_t pin_nid, unsigned int pin_config)
  1078. {
  1079. int i;
  1080. snd_hda_codec_write(codec, pin_nid, 0,
  1081. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  1082. pin_config & 0x000000ff);
  1083. snd_hda_codec_write(codec, pin_nid, 0,
  1084. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  1085. (pin_config & 0x0000ff00) >> 8);
  1086. snd_hda_codec_write(codec, pin_nid, 0,
  1087. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  1088. (pin_config & 0x00ff0000) >> 16);
  1089. snd_hda_codec_write(codec, pin_nid, 0,
  1090. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  1091. pin_config >> 24);
  1092. i = snd_hda_codec_read(codec, pin_nid, 0,
  1093. AC_VERB_GET_CONFIG_DEFAULT,
  1094. 0x00);
  1095. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
  1096. pin_nid, i);
  1097. }
  1098. static void stac92xx_set_config_regs(struct hda_codec *codec)
  1099. {
  1100. int i;
  1101. struct sigmatel_spec *spec = codec->spec;
  1102. if (!spec->pin_configs)
  1103. return;
  1104. for (i = 0; i < spec->num_pins; i++)
  1105. stac92xx_set_config_reg(codec, spec->pin_nids[i],
  1106. spec->pin_configs[i]);
  1107. }
  1108. static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
  1109. {
  1110. struct sigmatel_spec *spec = codec->spec;
  1111. /* Configure GPIOx as output */
  1112. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1113. AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
  1114. /* Configure GPIOx as CMOS */
  1115. snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
  1116. /* Assert GPIOx */
  1117. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1118. AC_VERB_SET_GPIO_DATA, spec->gpio_data);
  1119. /* Enable GPIOx */
  1120. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1121. AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
  1122. }
  1123. /*
  1124. * Analog playback callbacks
  1125. */
  1126. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1127. struct hda_codec *codec,
  1128. struct snd_pcm_substream *substream)
  1129. {
  1130. struct sigmatel_spec *spec = codec->spec;
  1131. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  1132. }
  1133. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1134. struct hda_codec *codec,
  1135. unsigned int stream_tag,
  1136. unsigned int format,
  1137. struct snd_pcm_substream *substream)
  1138. {
  1139. struct sigmatel_spec *spec = codec->spec;
  1140. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  1141. }
  1142. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1143. struct hda_codec *codec,
  1144. struct snd_pcm_substream *substream)
  1145. {
  1146. struct sigmatel_spec *spec = codec->spec;
  1147. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1148. }
  1149. /*
  1150. * Digital playback callbacks
  1151. */
  1152. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1153. struct hda_codec *codec,
  1154. struct snd_pcm_substream *substream)
  1155. {
  1156. struct sigmatel_spec *spec = codec->spec;
  1157. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1158. }
  1159. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1160. struct hda_codec *codec,
  1161. struct snd_pcm_substream *substream)
  1162. {
  1163. struct sigmatel_spec *spec = codec->spec;
  1164. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1165. }
  1166. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1167. struct hda_codec *codec,
  1168. unsigned int stream_tag,
  1169. unsigned int format,
  1170. struct snd_pcm_substream *substream)
  1171. {
  1172. struct sigmatel_spec *spec = codec->spec;
  1173. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1174. stream_tag, format, substream);
  1175. }
  1176. /*
  1177. * Analog capture callbacks
  1178. */
  1179. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1180. struct hda_codec *codec,
  1181. unsigned int stream_tag,
  1182. unsigned int format,
  1183. struct snd_pcm_substream *substream)
  1184. {
  1185. struct sigmatel_spec *spec = codec->spec;
  1186. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1187. stream_tag, 0, format);
  1188. return 0;
  1189. }
  1190. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1191. struct hda_codec *codec,
  1192. struct snd_pcm_substream *substream)
  1193. {
  1194. struct sigmatel_spec *spec = codec->spec;
  1195. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  1196. return 0;
  1197. }
  1198. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  1199. .substreams = 1,
  1200. .channels_min = 2,
  1201. .channels_max = 2,
  1202. /* NID is set in stac92xx_build_pcms */
  1203. .ops = {
  1204. .open = stac92xx_dig_playback_pcm_open,
  1205. .close = stac92xx_dig_playback_pcm_close,
  1206. .prepare = stac92xx_dig_playback_pcm_prepare
  1207. },
  1208. };
  1209. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  1210. .substreams = 1,
  1211. .channels_min = 2,
  1212. .channels_max = 2,
  1213. /* NID is set in stac92xx_build_pcms */
  1214. };
  1215. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  1216. .substreams = 1,
  1217. .channels_min = 2,
  1218. .channels_max = 8,
  1219. .nid = 0x02, /* NID to query formats and rates */
  1220. .ops = {
  1221. .open = stac92xx_playback_pcm_open,
  1222. .prepare = stac92xx_playback_pcm_prepare,
  1223. .cleanup = stac92xx_playback_pcm_cleanup
  1224. },
  1225. };
  1226. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  1227. .substreams = 1,
  1228. .channels_min = 2,
  1229. .channels_max = 2,
  1230. .nid = 0x06, /* NID to query formats and rates */
  1231. .ops = {
  1232. .open = stac92xx_playback_pcm_open,
  1233. .prepare = stac92xx_playback_pcm_prepare,
  1234. .cleanup = stac92xx_playback_pcm_cleanup
  1235. },
  1236. };
  1237. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  1238. .channels_min = 2,
  1239. .channels_max = 2,
  1240. /* NID + .substreams is set in stac92xx_build_pcms */
  1241. .ops = {
  1242. .prepare = stac92xx_capture_pcm_prepare,
  1243. .cleanup = stac92xx_capture_pcm_cleanup
  1244. },
  1245. };
  1246. static int stac92xx_build_pcms(struct hda_codec *codec)
  1247. {
  1248. struct sigmatel_spec *spec = codec->spec;
  1249. struct hda_pcm *info = spec->pcm_rec;
  1250. codec->num_pcms = 1;
  1251. codec->pcm_info = info;
  1252. info->name = "STAC92xx Analog";
  1253. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  1254. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  1255. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1256. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
  1257. if (spec->alt_switch) {
  1258. codec->num_pcms++;
  1259. info++;
  1260. info->name = "STAC92xx Analog Alt";
  1261. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  1262. }
  1263. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1264. codec->num_pcms++;
  1265. info++;
  1266. info->name = "STAC92xx Digital";
  1267. if (spec->multiout.dig_out_nid) {
  1268. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  1269. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  1270. }
  1271. if (spec->dig_in_nid) {
  1272. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  1273. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  1274. }
  1275. }
  1276. return 0;
  1277. }
  1278. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  1279. {
  1280. unsigned int pincap = snd_hda_param_read(codec, nid,
  1281. AC_PAR_PIN_CAP);
  1282. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  1283. if (pincap & AC_PINCAP_VREF_100)
  1284. return AC_PINCTL_VREF_100;
  1285. if (pincap & AC_PINCAP_VREF_80)
  1286. return AC_PINCTL_VREF_80;
  1287. if (pincap & AC_PINCAP_VREF_50)
  1288. return AC_PINCTL_VREF_50;
  1289. if (pincap & AC_PINCAP_VREF_GRD)
  1290. return AC_PINCTL_VREF_GRD;
  1291. return 0;
  1292. }
  1293. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  1294. {
  1295. snd_hda_codec_write_cache(codec, nid, 0,
  1296. AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  1297. }
  1298. #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
  1299. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1300. {
  1301. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1302. struct sigmatel_spec *spec = codec->spec;
  1303. int io_idx = kcontrol-> private_value & 0xff;
  1304. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  1305. return 0;
  1306. }
  1307. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1308. {
  1309. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1310. struct sigmatel_spec *spec = codec->spec;
  1311. hda_nid_t nid = kcontrol->private_value >> 8;
  1312. int io_idx = kcontrol-> private_value & 0xff;
  1313. unsigned short val = ucontrol->value.integer.value[0];
  1314. spec->io_switch[io_idx] = val;
  1315. if (val)
  1316. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1317. else {
  1318. unsigned int pinctl = AC_PINCTL_IN_EN;
  1319. if (io_idx) /* set VREF for mic */
  1320. pinctl |= stac92xx_get_vref(codec, nid);
  1321. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1322. }
  1323. return 1;
  1324. }
  1325. #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
  1326. static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
  1327. struct snd_ctl_elem_value *ucontrol)
  1328. {
  1329. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1330. struct sigmatel_spec *spec = codec->spec;
  1331. ucontrol->value.integer.value[0] = spec->clfe_swap;
  1332. return 0;
  1333. }
  1334. static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
  1335. struct snd_ctl_elem_value *ucontrol)
  1336. {
  1337. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1338. struct sigmatel_spec *spec = codec->spec;
  1339. hda_nid_t nid = kcontrol->private_value & 0xff;
  1340. if (spec->clfe_swap == ucontrol->value.integer.value[0])
  1341. return 0;
  1342. spec->clfe_swap = ucontrol->value.integer.value[0];
  1343. snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  1344. spec->clfe_swap ? 0x4 : 0x0);
  1345. return 1;
  1346. }
  1347. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  1348. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1349. .name = xname, \
  1350. .index = 0, \
  1351. .info = stac92xx_io_switch_info, \
  1352. .get = stac92xx_io_switch_get, \
  1353. .put = stac92xx_io_switch_put, \
  1354. .private_value = xpval, \
  1355. }
  1356. #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
  1357. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1358. .name = xname, \
  1359. .index = 0, \
  1360. .info = stac92xx_clfe_switch_info, \
  1361. .get = stac92xx_clfe_switch_get, \
  1362. .put = stac92xx_clfe_switch_put, \
  1363. .private_value = xpval, \
  1364. }
  1365. enum {
  1366. STAC_CTL_WIDGET_VOL,
  1367. STAC_CTL_WIDGET_MUTE,
  1368. STAC_CTL_WIDGET_IO_SWITCH,
  1369. STAC_CTL_WIDGET_CLFE_SWITCH
  1370. };
  1371. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  1372. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1373. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1374. STAC_CODEC_IO_SWITCH(NULL, 0),
  1375. STAC_CODEC_CLFE_SWITCH(NULL, 0),
  1376. };
  1377. /* add dynamic controls */
  1378. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  1379. {
  1380. struct snd_kcontrol_new *knew;
  1381. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1382. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1383. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1384. if (! knew)
  1385. return -ENOMEM;
  1386. if (spec->kctl_alloc) {
  1387. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1388. kfree(spec->kctl_alloc);
  1389. }
  1390. spec->kctl_alloc = knew;
  1391. spec->num_kctl_alloc = num;
  1392. }
  1393. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1394. *knew = stac92xx_control_templates[type];
  1395. knew->name = kstrdup(name, GFP_KERNEL);
  1396. if (! knew->name)
  1397. return -ENOMEM;
  1398. knew->private_value = val;
  1399. spec->num_kctl_used++;
  1400. return 0;
  1401. }
  1402. /* flag inputs as additional dynamic lineouts */
  1403. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  1404. {
  1405. struct sigmatel_spec *spec = codec->spec;
  1406. unsigned int wcaps, wtype;
  1407. int i, num_dacs = 0;
  1408. /* use the wcaps cache to count all DACs available for line-outs */
  1409. for (i = 0; i < codec->num_nodes; i++) {
  1410. wcaps = codec->wcaps[i];
  1411. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1412. if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
  1413. num_dacs++;
  1414. }
  1415. snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
  1416. switch (cfg->line_outs) {
  1417. case 3:
  1418. /* add line-in as side */
  1419. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
  1420. cfg->line_out_pins[cfg->line_outs] =
  1421. cfg->input_pins[AUTO_PIN_LINE];
  1422. spec->line_switch = 1;
  1423. cfg->line_outs++;
  1424. }
  1425. break;
  1426. case 2:
  1427. /* add line-in as clfe and mic as side */
  1428. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
  1429. cfg->line_out_pins[cfg->line_outs] =
  1430. cfg->input_pins[AUTO_PIN_LINE];
  1431. spec->line_switch = 1;
  1432. cfg->line_outs++;
  1433. }
  1434. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
  1435. cfg->line_out_pins[cfg->line_outs] =
  1436. cfg->input_pins[AUTO_PIN_MIC];
  1437. spec->mic_switch = 1;
  1438. cfg->line_outs++;
  1439. }
  1440. break;
  1441. case 1:
  1442. /* add line-in as surr and mic as clfe */
  1443. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
  1444. cfg->line_out_pins[cfg->line_outs] =
  1445. cfg->input_pins[AUTO_PIN_LINE];
  1446. spec->line_switch = 1;
  1447. cfg->line_outs++;
  1448. }
  1449. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
  1450. cfg->line_out_pins[cfg->line_outs] =
  1451. cfg->input_pins[AUTO_PIN_MIC];
  1452. spec->mic_switch = 1;
  1453. cfg->line_outs++;
  1454. }
  1455. break;
  1456. }
  1457. return 0;
  1458. }
  1459. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1460. {
  1461. int i;
  1462. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1463. if (spec->multiout.dac_nids[i] == nid)
  1464. return 1;
  1465. }
  1466. return 0;
  1467. }
  1468. /*
  1469. * Fill in the dac_nids table from the parsed pin configuration
  1470. * This function only works when every pin in line_out_pins[]
  1471. * contains atleast one DAC in its connection list. Some 92xx
  1472. * codecs are not connected directly to a DAC, such as the 9200
  1473. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  1474. */
  1475. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  1476. struct auto_pin_cfg *cfg)
  1477. {
  1478. struct sigmatel_spec *spec = codec->spec;
  1479. int i, j, conn_len = 0;
  1480. hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
  1481. unsigned int wcaps, wtype;
  1482. for (i = 0; i < cfg->line_outs; i++) {
  1483. nid = cfg->line_out_pins[i];
  1484. conn_len = snd_hda_get_connections(codec, nid, conn,
  1485. HDA_MAX_CONNECTIONS);
  1486. for (j = 0; j < conn_len; j++) {
  1487. wcaps = snd_hda_param_read(codec, conn[j],
  1488. AC_PAR_AUDIO_WIDGET_CAP);
  1489. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1490. if (wtype != AC_WID_AUD_OUT ||
  1491. (wcaps & AC_WCAP_DIGITAL))
  1492. continue;
  1493. /* conn[j] is a DAC routed to this line-out */
  1494. if (!is_in_dac_nids(spec, conn[j]))
  1495. break;
  1496. }
  1497. if (j == conn_len) {
  1498. if (spec->multiout.num_dacs > 0) {
  1499. /* we have already working output pins,
  1500. * so let's drop the broken ones again
  1501. */
  1502. cfg->line_outs = spec->multiout.num_dacs;
  1503. break;
  1504. }
  1505. /* error out, no available DAC found */
  1506. snd_printk(KERN_ERR
  1507. "%s: No available DAC for pin 0x%x\n",
  1508. __func__, nid);
  1509. return -ENODEV;
  1510. }
  1511. spec->multiout.dac_nids[i] = conn[j];
  1512. spec->multiout.num_dacs++;
  1513. if (conn_len > 1) {
  1514. /* select this DAC in the pin's input mux */
  1515. snd_hda_codec_write_cache(codec, nid, 0,
  1516. AC_VERB_SET_CONNECT_SEL, j);
  1517. }
  1518. }
  1519. snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1520. spec->multiout.num_dacs,
  1521. spec->multiout.dac_nids[0],
  1522. spec->multiout.dac_nids[1],
  1523. spec->multiout.dac_nids[2],
  1524. spec->multiout.dac_nids[3],
  1525. spec->multiout.dac_nids[4]);
  1526. return 0;
  1527. }
  1528. /* create volume control/switch for the given prefx type */
  1529. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  1530. {
  1531. char name[32];
  1532. int err;
  1533. sprintf(name, "%s Playback Volume", pfx);
  1534. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  1535. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1536. if (err < 0)
  1537. return err;
  1538. sprintf(name, "%s Playback Switch", pfx);
  1539. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  1540. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1541. if (err < 0)
  1542. return err;
  1543. return 0;
  1544. }
  1545. /* add playback controls from the parsed DAC table */
  1546. static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
  1547. const struct auto_pin_cfg *cfg)
  1548. {
  1549. static const char *chname[4] = {
  1550. "Front", "Surround", NULL /*CLFE*/, "Side"
  1551. };
  1552. hda_nid_t nid;
  1553. int i, err;
  1554. struct sigmatel_spec *spec = codec->spec;
  1555. unsigned int wid_caps;
  1556. for (i = 0; i < cfg->line_outs; i++) {
  1557. if (!spec->multiout.dac_nids[i])
  1558. continue;
  1559. nid = spec->multiout.dac_nids[i];
  1560. if (i == 2) {
  1561. /* Center/LFE */
  1562. err = create_controls(spec, "Center", nid, 1);
  1563. if (err < 0)
  1564. return err;
  1565. err = create_controls(spec, "LFE", nid, 2);
  1566. if (err < 0)
  1567. return err;
  1568. wid_caps = get_wcaps(codec, nid);
  1569. if (wid_caps & AC_WCAP_LR_SWAP) {
  1570. err = stac92xx_add_control(spec,
  1571. STAC_CTL_WIDGET_CLFE_SWITCH,
  1572. "Swap Center/LFE Playback Switch", nid);
  1573. if (err < 0)
  1574. return err;
  1575. }
  1576. } else {
  1577. err = create_controls(spec, chname[i], nid, 3);
  1578. if (err < 0)
  1579. return err;
  1580. }
  1581. }
  1582. if (spec->line_switch)
  1583. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  1584. return err;
  1585. if (spec->mic_switch)
  1586. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  1587. return err;
  1588. return 0;
  1589. }
  1590. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1591. {
  1592. if (is_in_dac_nids(spec, nid))
  1593. return 1;
  1594. if (spec->multiout.hp_nid == nid)
  1595. return 1;
  1596. return 0;
  1597. }
  1598. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  1599. {
  1600. if (!spec->multiout.hp_nid)
  1601. spec->multiout.hp_nid = nid;
  1602. else if (spec->multiout.num_dacs > 4) {
  1603. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  1604. return 1;
  1605. } else {
  1606. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  1607. spec->multiout.num_dacs++;
  1608. }
  1609. return 0;
  1610. }
  1611. /* add playback controls for Speaker and HP outputs */
  1612. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  1613. struct auto_pin_cfg *cfg)
  1614. {
  1615. struct sigmatel_spec *spec = codec->spec;
  1616. hda_nid_t nid;
  1617. int i, old_num_dacs, err;
  1618. old_num_dacs = spec->multiout.num_dacs;
  1619. for (i = 0; i < cfg->hp_outs; i++) {
  1620. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  1621. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1622. spec->hp_detect = 1;
  1623. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  1624. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1625. if (check_in_dac_nids(spec, nid))
  1626. nid = 0;
  1627. if (! nid)
  1628. continue;
  1629. add_spec_dacs(spec, nid);
  1630. }
  1631. for (i = 0; i < cfg->speaker_outs; i++) {
  1632. nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
  1633. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1634. if (check_in_dac_nids(spec, nid))
  1635. nid = 0;
  1636. if (! nid)
  1637. continue;
  1638. add_spec_dacs(spec, nid);
  1639. }
  1640. for (i = 0; i < cfg->line_outs; i++) {
  1641. nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
  1642. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1643. if (check_in_dac_nids(spec, nid))
  1644. nid = 0;
  1645. if (! nid)
  1646. continue;
  1647. add_spec_dacs(spec, nid);
  1648. }
  1649. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  1650. static const char *pfxs[] = {
  1651. "Speaker", "External Speaker", "Speaker2",
  1652. };
  1653. err = create_controls(spec, pfxs[i - old_num_dacs],
  1654. spec->multiout.dac_nids[i], 3);
  1655. if (err < 0)
  1656. return err;
  1657. }
  1658. if (spec->multiout.hp_nid) {
  1659. const char *pfx;
  1660. if (old_num_dacs == spec->multiout.num_dacs)
  1661. pfx = "Master";
  1662. else
  1663. pfx = "Headphone";
  1664. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1665. if (err < 0)
  1666. return err;
  1667. }
  1668. return 0;
  1669. }
  1670. /* labels for dmic mux inputs */
  1671. static const char *stac92xx_dmic_labels[5] = {
  1672. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1673. "Digital Mic 3", "Digital Mic 4"
  1674. };
  1675. /* create playback/capture controls for input pins on dmic capable codecs */
  1676. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1677. const struct auto_pin_cfg *cfg)
  1678. {
  1679. struct sigmatel_spec *spec = codec->spec;
  1680. struct hda_input_mux *dimux = &spec->private_dimux;
  1681. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1682. int i, j;
  1683. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1684. dimux->items[dimux->num_items].index = 0;
  1685. dimux->num_items++;
  1686. for (i = 0; i < spec->num_dmics; i++) {
  1687. int index;
  1688. int num_cons;
  1689. unsigned int def_conf;
  1690. def_conf = snd_hda_codec_read(codec,
  1691. spec->dmic_nids[i],
  1692. 0,
  1693. AC_VERB_GET_CONFIG_DEFAULT,
  1694. 0);
  1695. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1696. continue;
  1697. num_cons = snd_hda_get_connections(codec,
  1698. spec->dmux_nid,
  1699. con_lst,
  1700. HDA_MAX_NUM_INPUTS);
  1701. for (j = 0; j < num_cons; j++)
  1702. if (con_lst[j] == spec->dmic_nids[i]) {
  1703. index = j;
  1704. goto found;
  1705. }
  1706. continue;
  1707. found:
  1708. dimux->items[dimux->num_items].label =
  1709. stac92xx_dmic_labels[dimux->num_items];
  1710. dimux->items[dimux->num_items].index = index;
  1711. dimux->num_items++;
  1712. }
  1713. return 0;
  1714. }
  1715. /* create playback/capture controls for input pins */
  1716. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1717. {
  1718. struct sigmatel_spec *spec = codec->spec;
  1719. struct hda_input_mux *imux = &spec->private_imux;
  1720. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1721. int i, j, k;
  1722. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1723. int index;
  1724. if (!cfg->input_pins[i])
  1725. continue;
  1726. index = -1;
  1727. for (j = 0; j < spec->num_muxes; j++) {
  1728. int num_cons;
  1729. num_cons = snd_hda_get_connections(codec,
  1730. spec->mux_nids[j],
  1731. con_lst,
  1732. HDA_MAX_NUM_INPUTS);
  1733. for (k = 0; k < num_cons; k++)
  1734. if (con_lst[k] == cfg->input_pins[i]) {
  1735. index = k;
  1736. goto found;
  1737. }
  1738. }
  1739. continue;
  1740. found:
  1741. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1742. imux->items[imux->num_items].index = index;
  1743. imux->num_items++;
  1744. }
  1745. if (imux->num_items) {
  1746. /*
  1747. * Set the current input for the muxes.
  1748. * The STAC9221 has two input muxes with identical source
  1749. * NID lists. Hopefully this won't get confused.
  1750. */
  1751. for (i = 0; i < spec->num_muxes; i++) {
  1752. snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
  1753. AC_VERB_SET_CONNECT_SEL,
  1754. imux->items[0].index);
  1755. }
  1756. }
  1757. return 0;
  1758. }
  1759. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1760. {
  1761. struct sigmatel_spec *spec = codec->spec;
  1762. int i;
  1763. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1764. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1765. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1766. }
  1767. }
  1768. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1769. {
  1770. struct sigmatel_spec *spec = codec->spec;
  1771. int i;
  1772. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1773. hda_nid_t pin;
  1774. pin = spec->autocfg.hp_pins[i];
  1775. if (pin) /* connect to front */
  1776. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1777. }
  1778. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1779. hda_nid_t pin;
  1780. pin = spec->autocfg.speaker_pins[i];
  1781. if (pin) /* connect to front */
  1782. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1783. }
  1784. }
  1785. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1786. {
  1787. struct sigmatel_spec *spec = codec->spec;
  1788. int err;
  1789. if ((err = snd_hda_parse_pin_def_config(codec,
  1790. &spec->autocfg,
  1791. spec->dmic_nids)) < 0)
  1792. return err;
  1793. if (! spec->autocfg.line_outs)
  1794. return 0; /* can't find valid pin config */
  1795. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1796. return err;
  1797. if (spec->multiout.num_dacs == 0)
  1798. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1799. return err;
  1800. err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
  1801. if (err < 0)
  1802. return err;
  1803. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  1804. if (err < 0)
  1805. return err;
  1806. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  1807. if (err < 0)
  1808. return err;
  1809. if (spec->num_dmics > 0)
  1810. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1811. &spec->autocfg)) < 0)
  1812. return err;
  1813. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1814. if (spec->multiout.max_channels > 2)
  1815. spec->surr_switch = 1;
  1816. if (spec->autocfg.dig_out_pin)
  1817. spec->multiout.dig_out_nid = dig_out;
  1818. if (spec->autocfg.dig_in_pin)
  1819. spec->dig_in_nid = dig_in;
  1820. if (spec->kctl_alloc)
  1821. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1822. spec->input_mux = &spec->private_imux;
  1823. spec->dinput_mux = &spec->private_dimux;
  1824. return 1;
  1825. }
  1826. /* add playback controls for HP output */
  1827. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1828. struct auto_pin_cfg *cfg)
  1829. {
  1830. struct sigmatel_spec *spec = codec->spec;
  1831. hda_nid_t pin = cfg->hp_pins[0];
  1832. unsigned int wid_caps;
  1833. if (! pin)
  1834. return 0;
  1835. wid_caps = get_wcaps(codec, pin);
  1836. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1837. spec->hp_detect = 1;
  1838. return 0;
  1839. }
  1840. /* add playback controls for LFE output */
  1841. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1842. struct auto_pin_cfg *cfg)
  1843. {
  1844. struct sigmatel_spec *spec = codec->spec;
  1845. int err;
  1846. hda_nid_t lfe_pin = 0x0;
  1847. int i;
  1848. /*
  1849. * search speaker outs and line outs for a mono speaker pin
  1850. * with an amp. If one is found, add LFE controls
  1851. * for it.
  1852. */
  1853. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1854. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1855. unsigned long wcaps = get_wcaps(codec, pin);
  1856. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1857. if (wcaps == AC_WCAP_OUT_AMP)
  1858. /* found a mono speaker with an amp, must be lfe */
  1859. lfe_pin = pin;
  1860. }
  1861. /* if speaker_outs is 0, then speakers may be in line_outs */
  1862. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1863. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1864. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1865. unsigned long cfg;
  1866. cfg = snd_hda_codec_read(codec, pin, 0,
  1867. AC_VERB_GET_CONFIG_DEFAULT,
  1868. 0x00);
  1869. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1870. unsigned long wcaps = get_wcaps(codec, pin);
  1871. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1872. if (wcaps == AC_WCAP_OUT_AMP)
  1873. /* found a mono speaker with an amp,
  1874. must be lfe */
  1875. lfe_pin = pin;
  1876. }
  1877. }
  1878. }
  1879. if (lfe_pin) {
  1880. err = create_controls(spec, "LFE", lfe_pin, 1);
  1881. if (err < 0)
  1882. return err;
  1883. }
  1884. return 0;
  1885. }
  1886. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1887. {
  1888. struct sigmatel_spec *spec = codec->spec;
  1889. int err;
  1890. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1891. return err;
  1892. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1893. return err;
  1894. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1895. return err;
  1896. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1897. return err;
  1898. if (spec->autocfg.dig_out_pin)
  1899. spec->multiout.dig_out_nid = 0x05;
  1900. if (spec->autocfg.dig_in_pin)
  1901. spec->dig_in_nid = 0x04;
  1902. if (spec->kctl_alloc)
  1903. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1904. spec->input_mux = &spec->private_imux;
  1905. spec->dinput_mux = &spec->private_dimux;
  1906. return 1;
  1907. }
  1908. /*
  1909. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1910. * funky external mute control using GPIO pins.
  1911. */
  1912. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1913. {
  1914. unsigned int gpiostate, gpiomask, gpiodir;
  1915. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1916. AC_VERB_GET_GPIO_DATA, 0);
  1917. if (!muted)
  1918. gpiostate |= (1 << pin);
  1919. else
  1920. gpiostate &= ~(1 << pin);
  1921. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  1922. AC_VERB_GET_GPIO_MASK, 0);
  1923. gpiomask |= (1 << pin);
  1924. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  1925. AC_VERB_GET_GPIO_DIRECTION, 0);
  1926. gpiodir |= (1 << pin);
  1927. /* AppleHDA seems to do this -- WTF is this verb?? */
  1928. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  1929. snd_hda_codec_write(codec, codec->afg, 0,
  1930. AC_VERB_SET_GPIO_MASK, gpiomask);
  1931. snd_hda_codec_write(codec, codec->afg, 0,
  1932. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  1933. msleep(1);
  1934. snd_hda_codec_write(codec, codec->afg, 0,
  1935. AC_VERB_SET_GPIO_DATA, gpiostate);
  1936. }
  1937. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  1938. unsigned int event)
  1939. {
  1940. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  1941. snd_hda_codec_write_cache(codec, nid, 0,
  1942. AC_VERB_SET_UNSOLICITED_ENABLE,
  1943. (AC_USRSP_EN | event));
  1944. }
  1945. static int stac92xx_init(struct hda_codec *codec)
  1946. {
  1947. struct sigmatel_spec *spec = codec->spec;
  1948. struct auto_pin_cfg *cfg = &spec->autocfg;
  1949. int i;
  1950. snd_hda_sequence_write(codec, spec->init);
  1951. /* set up pins */
  1952. if (spec->hp_detect) {
  1953. /* Enable unsolicited responses on the HP widget */
  1954. for (i = 0; i < cfg->hp_outs; i++)
  1955. enable_pin_detect(codec, cfg->hp_pins[i],
  1956. STAC_HP_EVENT);
  1957. /* force to enable the first line-out; the others are set up
  1958. * in unsol_event
  1959. */
  1960. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  1961. AC_PINCTL_OUT_EN);
  1962. stac92xx_auto_init_hp_out(codec);
  1963. /* fake event to set up pins */
  1964. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  1965. } else {
  1966. stac92xx_auto_init_multi_out(codec);
  1967. stac92xx_auto_init_hp_out(codec);
  1968. }
  1969. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1970. hda_nid_t nid = cfg->input_pins[i];
  1971. if (nid) {
  1972. unsigned int pinctl = AC_PINCTL_IN_EN;
  1973. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  1974. pinctl |= stac92xx_get_vref(codec, nid);
  1975. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1976. }
  1977. }
  1978. if (spec->num_dmics > 0)
  1979. for (i = 0; i < spec->num_dmics; i++)
  1980. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  1981. AC_PINCTL_IN_EN);
  1982. if (cfg->dig_out_pin)
  1983. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  1984. AC_PINCTL_OUT_EN);
  1985. if (cfg->dig_in_pin)
  1986. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  1987. AC_PINCTL_IN_EN);
  1988. if (spec->gpio_mute) {
  1989. stac922x_gpio_mute(codec, 0, 0);
  1990. stac922x_gpio_mute(codec, 1, 0);
  1991. }
  1992. return 0;
  1993. }
  1994. static void stac92xx_free(struct hda_codec *codec)
  1995. {
  1996. struct sigmatel_spec *spec = codec->spec;
  1997. int i;
  1998. if (! spec)
  1999. return;
  2000. if (spec->kctl_alloc) {
  2001. for (i = 0; i < spec->num_kctl_used; i++)
  2002. kfree(spec->kctl_alloc[i].name);
  2003. kfree(spec->kctl_alloc);
  2004. }
  2005. if (spec->bios_pin_configs)
  2006. kfree(spec->bios_pin_configs);
  2007. kfree(spec);
  2008. }
  2009. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2010. unsigned int flag)
  2011. {
  2012. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2013. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2014. if (pin_ctl & AC_PINCTL_IN_EN) {
  2015. /*
  2016. * we need to check the current set-up direction of
  2017. * shared input pins since they can be switched via
  2018. * "xxx as Output" mixer switch
  2019. */
  2020. struct sigmatel_spec *spec = codec->spec;
  2021. struct auto_pin_cfg *cfg = &spec->autocfg;
  2022. if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
  2023. spec->line_switch) ||
  2024. (nid == cfg->input_pins[AUTO_PIN_MIC] &&
  2025. spec->mic_switch))
  2026. return;
  2027. }
  2028. /* if setting pin direction bits, clear the current
  2029. direction bits first */
  2030. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  2031. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  2032. snd_hda_codec_write_cache(codec, nid, 0,
  2033. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2034. pin_ctl | flag);
  2035. }
  2036. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2037. unsigned int flag)
  2038. {
  2039. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2040. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2041. snd_hda_codec_write_cache(codec, nid, 0,
  2042. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2043. pin_ctl & ~flag);
  2044. }
  2045. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  2046. {
  2047. if (!nid)
  2048. return 0;
  2049. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  2050. & (1 << 31))
  2051. return 1;
  2052. return 0;
  2053. }
  2054. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  2055. {
  2056. struct sigmatel_spec *spec = codec->spec;
  2057. struct auto_pin_cfg *cfg = &spec->autocfg;
  2058. int i, presence;
  2059. presence = 0;
  2060. for (i = 0; i < cfg->hp_outs; i++) {
  2061. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  2062. if (presence)
  2063. break;
  2064. }
  2065. if (presence) {
  2066. /* disable lineouts, enable hp */
  2067. for (i = 0; i < cfg->line_outs; i++)
  2068. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  2069. AC_PINCTL_OUT_EN);
  2070. for (i = 0; i < cfg->speaker_outs; i++)
  2071. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  2072. AC_PINCTL_OUT_EN);
  2073. } else {
  2074. /* enable lineouts, disable hp */
  2075. for (i = 0; i < cfg->line_outs; i++)
  2076. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  2077. AC_PINCTL_OUT_EN);
  2078. for (i = 0; i < cfg->speaker_outs; i++)
  2079. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  2080. AC_PINCTL_OUT_EN);
  2081. }
  2082. }
  2083. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  2084. {
  2085. switch (res >> 26) {
  2086. case STAC_HP_EVENT:
  2087. stac92xx_hp_detect(codec, res);
  2088. break;
  2089. }
  2090. }
  2091. #ifdef SND_HDA_NEEDS_RESUME
  2092. static int stac92xx_resume(struct hda_codec *codec)
  2093. {
  2094. struct sigmatel_spec *spec = codec->spec;
  2095. stac92xx_set_config_regs(codec);
  2096. snd_hda_sequence_write(codec, spec->init);
  2097. if (spec->gpio_mute) {
  2098. stac922x_gpio_mute(codec, 0, 0);
  2099. stac922x_gpio_mute(codec, 1, 0);
  2100. }
  2101. snd_hda_codec_resume_amp(codec);
  2102. snd_hda_codec_resume_cache(codec);
  2103. /* invoke unsolicited event to reset the HP state */
  2104. if (spec->hp_detect)
  2105. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2106. return 0;
  2107. }
  2108. #endif
  2109. static struct hda_codec_ops stac92xx_patch_ops = {
  2110. .build_controls = stac92xx_build_controls,
  2111. .build_pcms = stac92xx_build_pcms,
  2112. .init = stac92xx_init,
  2113. .free = stac92xx_free,
  2114. .unsol_event = stac92xx_unsol_event,
  2115. #ifdef SND_HDA_NEEDS_RESUME
  2116. .resume = stac92xx_resume,
  2117. #endif
  2118. };
  2119. static int patch_stac9200(struct hda_codec *codec)
  2120. {
  2121. struct sigmatel_spec *spec;
  2122. int err;
  2123. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2124. if (spec == NULL)
  2125. return -ENOMEM;
  2126. codec->spec = spec;
  2127. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  2128. spec->pin_nids = stac9200_pin_nids;
  2129. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  2130. stac9200_models,
  2131. stac9200_cfg_tbl);
  2132. if (spec->board_config < 0) {
  2133. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  2134. err = stac92xx_save_bios_config_regs(codec);
  2135. if (err < 0) {
  2136. stac92xx_free(codec);
  2137. return err;
  2138. }
  2139. spec->pin_configs = spec->bios_pin_configs;
  2140. } else {
  2141. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  2142. stac92xx_set_config_regs(codec);
  2143. }
  2144. spec->multiout.max_channels = 2;
  2145. spec->multiout.num_dacs = 1;
  2146. spec->multiout.dac_nids = stac9200_dac_nids;
  2147. spec->adc_nids = stac9200_adc_nids;
  2148. spec->mux_nids = stac9200_mux_nids;
  2149. spec->num_muxes = 1;
  2150. spec->num_dmics = 0;
  2151. spec->num_adcs = 1;
  2152. if (spec->board_config == STAC_9200_GATEWAY)
  2153. spec->init = stac9200_eapd_init;
  2154. else
  2155. spec->init = stac9200_core_init;
  2156. spec->mixer = stac9200_mixer;
  2157. err = stac9200_parse_auto_config(codec);
  2158. if (err < 0) {
  2159. stac92xx_free(codec);
  2160. return err;
  2161. }
  2162. codec->patch_ops = stac92xx_patch_ops;
  2163. return 0;
  2164. }
  2165. static int patch_stac925x(struct hda_codec *codec)
  2166. {
  2167. struct sigmatel_spec *spec;
  2168. int err;
  2169. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2170. if (spec == NULL)
  2171. return -ENOMEM;
  2172. codec->spec = spec;
  2173. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  2174. spec->pin_nids = stac925x_pin_nids;
  2175. spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
  2176. stac925x_models,
  2177. stac925x_cfg_tbl);
  2178. again:
  2179. if (spec->board_config < 0) {
  2180. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
  2181. "using BIOS defaults\n");
  2182. err = stac92xx_save_bios_config_regs(codec);
  2183. if (err < 0) {
  2184. stac92xx_free(codec);
  2185. return err;
  2186. }
  2187. spec->pin_configs = spec->bios_pin_configs;
  2188. } else if (stac925x_brd_tbl[spec->board_config] != NULL){
  2189. spec->pin_configs = stac925x_brd_tbl[spec->board_config];
  2190. stac92xx_set_config_regs(codec);
  2191. }
  2192. spec->multiout.max_channels = 2;
  2193. spec->multiout.num_dacs = 1;
  2194. spec->multiout.dac_nids = stac925x_dac_nids;
  2195. spec->adc_nids = stac925x_adc_nids;
  2196. spec->mux_nids = stac925x_mux_nids;
  2197. spec->num_muxes = 1;
  2198. spec->num_adcs = 1;
  2199. switch (codec->vendor_id) {
  2200. case 0x83847632: /* STAC9202 */
  2201. case 0x83847633: /* STAC9202D */
  2202. case 0x83847636: /* STAC9251 */
  2203. case 0x83847637: /* STAC9251D */
  2204. spec->num_dmics = STAC925X_NUM_DMICS;
  2205. spec->dmic_nids = stac925x_dmic_nids;
  2206. break;
  2207. default:
  2208. spec->num_dmics = 0;
  2209. break;
  2210. }
  2211. spec->init = stac925x_core_init;
  2212. spec->mixer = stac925x_mixer;
  2213. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  2214. if (!err) {
  2215. if (spec->board_config < 0) {
  2216. printk(KERN_WARNING "hda_codec: No auto-config is "
  2217. "available, default to model=ref\n");
  2218. spec->board_config = STAC_925x_REF;
  2219. goto again;
  2220. }
  2221. err = -EINVAL;
  2222. }
  2223. if (err < 0) {
  2224. stac92xx_free(codec);
  2225. return err;
  2226. }
  2227. codec->patch_ops = stac92xx_patch_ops;
  2228. return 0;
  2229. }
  2230. static int patch_stac922x(struct hda_codec *codec)
  2231. {
  2232. struct sigmatel_spec *spec;
  2233. int err;
  2234. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2235. if (spec == NULL)
  2236. return -ENOMEM;
  2237. codec->spec = spec;
  2238. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  2239. spec->pin_nids = stac922x_pin_nids;
  2240. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  2241. stac922x_models,
  2242. stac922x_cfg_tbl);
  2243. if (spec->board_config == STAC_INTEL_MAC_V3) {
  2244. spec->gpio_mute = 1;
  2245. /* Intel Macs have all same PCI SSID, so we need to check
  2246. * codec SSID to distinguish the exact models
  2247. */
  2248. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  2249. switch (codec->subsystem_id) {
  2250. case 0x106b0800:
  2251. spec->board_config = STAC_INTEL_MAC_V1;
  2252. break;
  2253. case 0x106b0600:
  2254. case 0x106b0700:
  2255. spec->board_config = STAC_INTEL_MAC_V2;
  2256. break;
  2257. case 0x106b0e00:
  2258. case 0x106b0f00:
  2259. case 0x106b1600:
  2260. case 0x106b1700:
  2261. case 0x106b0200:
  2262. case 0x106b1e00:
  2263. spec->board_config = STAC_INTEL_MAC_V3;
  2264. break;
  2265. case 0x106b1a00:
  2266. case 0x00000100:
  2267. spec->board_config = STAC_INTEL_MAC_V4;
  2268. break;
  2269. case 0x106b0a00:
  2270. case 0x106b2200:
  2271. spec->board_config = STAC_INTEL_MAC_V5;
  2272. break;
  2273. }
  2274. }
  2275. again:
  2276. if (spec->board_config < 0) {
  2277. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  2278. "using BIOS defaults\n");
  2279. err = stac92xx_save_bios_config_regs(codec);
  2280. if (err < 0) {
  2281. stac92xx_free(codec);
  2282. return err;
  2283. }
  2284. spec->pin_configs = spec->bios_pin_configs;
  2285. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  2286. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  2287. stac92xx_set_config_regs(codec);
  2288. }
  2289. spec->adc_nids = stac922x_adc_nids;
  2290. spec->mux_nids = stac922x_mux_nids;
  2291. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  2292. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  2293. spec->num_dmics = 0;
  2294. spec->init = stac922x_core_init;
  2295. spec->mixer = stac922x_mixer;
  2296. spec->multiout.dac_nids = spec->dac_nids;
  2297. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  2298. if (!err) {
  2299. if (spec->board_config < 0) {
  2300. printk(KERN_WARNING "hda_codec: No auto-config is "
  2301. "available, default to model=ref\n");
  2302. spec->board_config = STAC_D945_REF;
  2303. goto again;
  2304. }
  2305. err = -EINVAL;
  2306. }
  2307. if (err < 0) {
  2308. stac92xx_free(codec);
  2309. return err;
  2310. }
  2311. codec->patch_ops = stac92xx_patch_ops;
  2312. /* Fix Mux capture level; max to 2 */
  2313. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  2314. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  2315. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2316. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2317. (0 << AC_AMPCAP_MUTE_SHIFT));
  2318. return 0;
  2319. }
  2320. static int patch_stac927x(struct hda_codec *codec)
  2321. {
  2322. struct sigmatel_spec *spec;
  2323. int err;
  2324. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2325. if (spec == NULL)
  2326. return -ENOMEM;
  2327. codec->spec = spec;
  2328. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  2329. spec->pin_nids = stac927x_pin_nids;
  2330. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  2331. stac927x_models,
  2332. stac927x_cfg_tbl);
  2333. again:
  2334. if (spec->board_config < 0) {
  2335. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  2336. err = stac92xx_save_bios_config_regs(codec);
  2337. if (err < 0) {
  2338. stac92xx_free(codec);
  2339. return err;
  2340. }
  2341. spec->pin_configs = spec->bios_pin_configs;
  2342. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  2343. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  2344. stac92xx_set_config_regs(codec);
  2345. }
  2346. switch (spec->board_config) {
  2347. case STAC_D965_3ST:
  2348. spec->adc_nids = stac927x_adc_nids;
  2349. spec->mux_nids = stac927x_mux_nids;
  2350. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2351. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2352. spec->init = d965_core_init;
  2353. spec->mixer = stac927x_mixer;
  2354. break;
  2355. case STAC_D965_5ST:
  2356. spec->adc_nids = stac927x_adc_nids;
  2357. spec->mux_nids = stac927x_mux_nids;
  2358. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2359. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2360. spec->init = d965_core_init;
  2361. spec->mixer = stac927x_mixer;
  2362. break;
  2363. default:
  2364. spec->adc_nids = stac927x_adc_nids;
  2365. spec->mux_nids = stac927x_mux_nids;
  2366. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2367. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2368. spec->init = stac927x_core_init;
  2369. spec->mixer = stac927x_mixer;
  2370. }
  2371. switch (codec->subsystem_id) {
  2372. case 0x1028020A: /* STAC 9228 */
  2373. case 0x10280209: /* STAC 9228 */
  2374. spec->dmic_nids = stac927x_dmic_nids;
  2375. spec->num_dmics = STAC927X_NUM_DMICS;
  2376. spec->dmux_nid = 0x1c;
  2377. break;
  2378. default:
  2379. spec->num_dmics = 0;
  2380. }
  2381. spec->multiout.dac_nids = spec->dac_nids;
  2382. /* GPIO0 High = Enable EAPD */
  2383. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2384. stac92xx_enable_gpio_mask(codec);
  2385. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  2386. if (!err) {
  2387. if (spec->board_config < 0) {
  2388. printk(KERN_WARNING "hda_codec: No auto-config is "
  2389. "available, default to model=ref\n");
  2390. spec->board_config = STAC_D965_REF;
  2391. goto again;
  2392. }
  2393. err = -EINVAL;
  2394. }
  2395. if (err < 0) {
  2396. stac92xx_free(codec);
  2397. return err;
  2398. }
  2399. codec->patch_ops = stac92xx_patch_ops;
  2400. return 0;
  2401. }
  2402. static int patch_stac9205(struct hda_codec *codec)
  2403. {
  2404. struct sigmatel_spec *spec;
  2405. int err;
  2406. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2407. if (spec == NULL)
  2408. return -ENOMEM;
  2409. codec->spec = spec;
  2410. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  2411. spec->pin_nids = stac9205_pin_nids;
  2412. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  2413. stac9205_models,
  2414. stac9205_cfg_tbl);
  2415. again:
  2416. if (spec->board_config < 0) {
  2417. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  2418. err = stac92xx_save_bios_config_regs(codec);
  2419. if (err < 0) {
  2420. stac92xx_free(codec);
  2421. return err;
  2422. }
  2423. spec->pin_configs = spec->bios_pin_configs;
  2424. } else {
  2425. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  2426. stac92xx_set_config_regs(codec);
  2427. }
  2428. spec->adc_nids = stac9205_adc_nids;
  2429. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  2430. spec->mux_nids = stac9205_mux_nids;
  2431. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  2432. spec->dmic_nids = stac9205_dmic_nids;
  2433. spec->num_dmics = STAC9205_NUM_DMICS;
  2434. spec->dmux_nid = 0x1d;
  2435. spec->init = stac9205_core_init;
  2436. spec->mixer = stac9205_mixer;
  2437. spec->multiout.dac_nids = spec->dac_nids;
  2438. switch (spec->board_config){
  2439. case STAC_9205_DELL_M43:
  2440. /* Enable SPDIF in/out */
  2441. stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
  2442. stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
  2443. spec->gpio_mask = 0x00000007; /* GPIO0-2 */
  2444. /* GPIO0 High = EAPD, GPIO1 Low = DRM,
  2445. * GPIO2 High = Headphone Mute
  2446. */
  2447. spec->gpio_data = 0x00000005;
  2448. break;
  2449. default:
  2450. /* GPIO0 High = EAPD */
  2451. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2452. break;
  2453. }
  2454. stac92xx_enable_gpio_mask(codec);
  2455. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  2456. if (!err) {
  2457. if (spec->board_config < 0) {
  2458. printk(KERN_WARNING "hda_codec: No auto-config is "
  2459. "available, default to model=ref\n");
  2460. spec->board_config = STAC_9205_REF;
  2461. goto again;
  2462. }
  2463. err = -EINVAL;
  2464. }
  2465. if (err < 0) {
  2466. stac92xx_free(codec);
  2467. return err;
  2468. }
  2469. codec->patch_ops = stac92xx_patch_ops;
  2470. return 0;
  2471. }
  2472. /*
  2473. * STAC9872 hack
  2474. */
  2475. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  2476. static hda_nid_t vaio_dacs[] = { 0x2 };
  2477. #define VAIO_HP_DAC 0x5
  2478. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  2479. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  2480. static struct hda_input_mux vaio_mux = {
  2481. .num_items = 3,
  2482. .items = {
  2483. /* { "HP", 0x0 }, */
  2484. { "Mic Jack", 0x1 },
  2485. { "Internal Mic", 0x2 },
  2486. { "PCM", 0x3 },
  2487. }
  2488. };
  2489. static struct hda_verb vaio_init[] = {
  2490. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2491. {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
  2492. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2493. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2494. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2495. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2496. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2497. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2498. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2499. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2500. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2501. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2502. {}
  2503. };
  2504. static struct hda_verb vaio_ar_init[] = {
  2505. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2506. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2507. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2508. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2509. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  2510. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2511. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2512. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2513. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2514. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  2515. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2516. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2517. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2518. {}
  2519. };
  2520. /* bind volumes of both NID 0x02 and 0x05 */
  2521. static struct hda_bind_ctls vaio_bind_master_vol = {
  2522. .ops = &snd_hda_bind_vol,
  2523. .values = {
  2524. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2525. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2526. 0
  2527. },
  2528. };
  2529. /* bind volumes of both NID 0x02 and 0x05 */
  2530. static struct hda_bind_ctls vaio_bind_master_sw = {
  2531. .ops = &snd_hda_bind_sw,
  2532. .values = {
  2533. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2534. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2535. 0,
  2536. },
  2537. };
  2538. static struct snd_kcontrol_new vaio_mixer[] = {
  2539. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2540. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2541. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2542. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2543. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2544. {
  2545. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2546. .name = "Capture Source",
  2547. .count = 1,
  2548. .info = stac92xx_mux_enum_info,
  2549. .get = stac92xx_mux_enum_get,
  2550. .put = stac92xx_mux_enum_put,
  2551. },
  2552. {}
  2553. };
  2554. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  2555. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2556. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2557. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2558. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2559. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2560. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  2561. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  2562. {
  2563. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2564. .name = "Capture Source",
  2565. .count = 1,
  2566. .info = stac92xx_mux_enum_info,
  2567. .get = stac92xx_mux_enum_get,
  2568. .put = stac92xx_mux_enum_put,
  2569. },
  2570. {}
  2571. };
  2572. static struct hda_codec_ops stac9872_patch_ops = {
  2573. .build_controls = stac92xx_build_controls,
  2574. .build_pcms = stac92xx_build_pcms,
  2575. .init = stac92xx_init,
  2576. .free = stac92xx_free,
  2577. #ifdef SND_HDA_NEEDS_RESUME
  2578. .resume = stac92xx_resume,
  2579. #endif
  2580. };
  2581. static int stac9872_vaio_init(struct hda_codec *codec)
  2582. {
  2583. int err;
  2584. err = stac92xx_init(codec);
  2585. if (err < 0)
  2586. return err;
  2587. if (codec->patch_ops.unsol_event)
  2588. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2589. return 0;
  2590. }
  2591. static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
  2592. {
  2593. if (get_pin_presence(codec, 0x0a)) {
  2594. stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2595. stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2596. } else {
  2597. stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2598. stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2599. }
  2600. }
  2601. static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
  2602. {
  2603. switch (res >> 26) {
  2604. case STAC_HP_EVENT:
  2605. stac9872_vaio_hp_detect(codec, res);
  2606. break;
  2607. }
  2608. }
  2609. static struct hda_codec_ops stac9872_vaio_patch_ops = {
  2610. .build_controls = stac92xx_build_controls,
  2611. .build_pcms = stac92xx_build_pcms,
  2612. .init = stac9872_vaio_init,
  2613. .free = stac92xx_free,
  2614. .unsol_event = stac9872_vaio_unsol_event,
  2615. #ifdef CONFIG_PM
  2616. .resume = stac92xx_resume,
  2617. #endif
  2618. };
  2619. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  2620. CXD9872RD_VAIO,
  2621. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  2622. STAC9872AK_VAIO,
  2623. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  2624. STAC9872K_VAIO,
  2625. /* AR Series. id=0x83847664 and subsys=104D1300 */
  2626. CXD9872AKD_VAIO,
  2627. STAC_9872_MODELS,
  2628. };
  2629. static const char *stac9872_models[STAC_9872_MODELS] = {
  2630. [CXD9872RD_VAIO] = "vaio",
  2631. [CXD9872AKD_VAIO] = "vaio-ar",
  2632. };
  2633. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  2634. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  2635. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  2636. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  2637. SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
  2638. {}
  2639. };
  2640. static int patch_stac9872(struct hda_codec *codec)
  2641. {
  2642. struct sigmatel_spec *spec;
  2643. int board_config;
  2644. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  2645. stac9872_models,
  2646. stac9872_cfg_tbl);
  2647. if (board_config < 0)
  2648. /* unknown config, let generic-parser do its job... */
  2649. return snd_hda_parse_generic_codec(codec);
  2650. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2651. if (spec == NULL)
  2652. return -ENOMEM;
  2653. codec->spec = spec;
  2654. switch (board_config) {
  2655. case CXD9872RD_VAIO:
  2656. case STAC9872AK_VAIO:
  2657. case STAC9872K_VAIO:
  2658. spec->mixer = vaio_mixer;
  2659. spec->init = vaio_init;
  2660. spec->multiout.max_channels = 2;
  2661. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2662. spec->multiout.dac_nids = vaio_dacs;
  2663. spec->multiout.hp_nid = VAIO_HP_DAC;
  2664. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2665. spec->adc_nids = vaio_adcs;
  2666. spec->input_mux = &vaio_mux;
  2667. spec->mux_nids = vaio_mux_nids;
  2668. codec->patch_ops = stac9872_vaio_patch_ops;
  2669. break;
  2670. case CXD9872AKD_VAIO:
  2671. spec->mixer = vaio_ar_mixer;
  2672. spec->init = vaio_ar_init;
  2673. spec->multiout.max_channels = 2;
  2674. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2675. spec->multiout.dac_nids = vaio_dacs;
  2676. spec->multiout.hp_nid = VAIO_HP_DAC;
  2677. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2678. spec->adc_nids = vaio_adcs;
  2679. spec->input_mux = &vaio_mux;
  2680. spec->mux_nids = vaio_mux_nids;
  2681. codec->patch_ops = stac9872_patch_ops;
  2682. break;
  2683. }
  2684. return 0;
  2685. }
  2686. /*
  2687. * patch entries
  2688. */
  2689. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  2690. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  2691. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  2692. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  2693. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  2694. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  2695. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  2696. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  2697. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  2698. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  2699. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  2700. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  2701. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  2702. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  2703. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  2704. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  2705. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  2706. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  2707. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  2708. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  2709. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  2710. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  2711. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  2712. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  2713. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  2714. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  2715. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  2716. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  2717. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  2718. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  2719. /* The following does not take into account .id=0x83847661 when subsys =
  2720. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  2721. * currently not fully supported.
  2722. */
  2723. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  2724. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  2725. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  2726. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  2727. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  2728. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  2729. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  2730. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  2731. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  2732. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  2733. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  2734. {} /* terminator */
  2735. };