patch_sigmatel.c 90 KB

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