patch_sigmatel.c 89 KB

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