patch_sigmatel.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637
  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_MODELS
  40. };
  41. enum {
  42. STAC_9205_REF,
  43. STAC_M43xx,
  44. STAC_9205_MODELS
  45. };
  46. enum {
  47. STAC_925x_REF,
  48. STAC_M2_2,
  49. STAC_MA6,
  50. STAC_PA6,
  51. STAC_925x_MODELS
  52. };
  53. enum {
  54. STAC_D945_REF,
  55. STAC_D945GTP3,
  56. STAC_D945GTP5,
  57. STAC_922X_DELL,
  58. STAC_INTEL_MAC_V1,
  59. STAC_INTEL_MAC_V2,
  60. STAC_INTEL_MAC_V3,
  61. STAC_INTEL_MAC_V4,
  62. STAC_INTEL_MAC_V5,
  63. /* for backward compitability */
  64. STAC_MACMINI,
  65. STAC_MACBOOK,
  66. STAC_MACBOOK_PRO_V1,
  67. STAC_MACBOOK_PRO_V2,
  68. STAC_IMAC_INTEL,
  69. STAC_IMAC_INTEL_20,
  70. STAC_922X_MODELS
  71. };
  72. enum {
  73. STAC_D965_REF,
  74. STAC_D965_3ST,
  75. STAC_D965_5ST,
  76. STAC_927X_MODELS
  77. };
  78. struct sigmatel_spec {
  79. struct snd_kcontrol_new *mixers[4];
  80. unsigned int num_mixers;
  81. int board_config;
  82. unsigned int surr_switch: 1;
  83. unsigned int line_switch: 1;
  84. unsigned int mic_switch: 1;
  85. unsigned int alt_switch: 1;
  86. unsigned int hp_detect: 1;
  87. unsigned int gpio_mute: 1;
  88. /* playback */
  89. struct hda_multi_out multiout;
  90. hda_nid_t dac_nids[5];
  91. /* capture */
  92. hda_nid_t *adc_nids;
  93. unsigned int num_adcs;
  94. hda_nid_t *mux_nids;
  95. unsigned int num_muxes;
  96. hda_nid_t *dmic_nids;
  97. unsigned int num_dmics;
  98. hda_nid_t dmux_nid;
  99. hda_nid_t dig_in_nid;
  100. /* pin widgets */
  101. hda_nid_t *pin_nids;
  102. unsigned int num_pins;
  103. unsigned int *pin_configs;
  104. unsigned int *bios_pin_configs;
  105. /* codec specific stuff */
  106. struct hda_verb *init;
  107. struct snd_kcontrol_new *mixer;
  108. /* capture source */
  109. struct hda_input_mux *dinput_mux;
  110. unsigned int cur_dmux;
  111. struct hda_input_mux *input_mux;
  112. unsigned int cur_mux[3];
  113. /* i/o switches */
  114. unsigned int io_switch[2];
  115. struct hda_pcm pcm_rec[2]; /* PCM information */
  116. /* dynamic controls and input_mux */
  117. struct auto_pin_cfg autocfg;
  118. unsigned int num_kctl_alloc, num_kctl_used;
  119. struct snd_kcontrol_new *kctl_alloc;
  120. struct hda_input_mux private_dimux;
  121. struct hda_input_mux private_imux;
  122. };
  123. static hda_nid_t stac9200_adc_nids[1] = {
  124. 0x03,
  125. };
  126. static hda_nid_t stac9200_mux_nids[1] = {
  127. 0x0c,
  128. };
  129. static hda_nid_t stac9200_dac_nids[1] = {
  130. 0x02,
  131. };
  132. static hda_nid_t stac925x_adc_nids[1] = {
  133. 0x03,
  134. };
  135. static hda_nid_t stac925x_mux_nids[1] = {
  136. 0x0f,
  137. };
  138. static hda_nid_t stac925x_dac_nids[1] = {
  139. 0x02,
  140. };
  141. static hda_nid_t stac925x_dmic_nids[1] = {
  142. 0x15,
  143. };
  144. static hda_nid_t stac922x_adc_nids[2] = {
  145. 0x06, 0x07,
  146. };
  147. static hda_nid_t stac922x_mux_nids[2] = {
  148. 0x12, 0x13,
  149. };
  150. static hda_nid_t stac927x_adc_nids[3] = {
  151. 0x07, 0x08, 0x09
  152. };
  153. static hda_nid_t stac927x_mux_nids[3] = {
  154. 0x15, 0x16, 0x17
  155. };
  156. static hda_nid_t stac9205_adc_nids[2] = {
  157. 0x12, 0x13
  158. };
  159. static hda_nid_t stac9205_mux_nids[2] = {
  160. 0x19, 0x1a
  161. };
  162. static hda_nid_t stac9205_dmic_nids[2] = {
  163. 0x17, 0x18,
  164. };
  165. static hda_nid_t stac9200_pin_nids[8] = {
  166. 0x08, 0x09, 0x0d, 0x0e,
  167. 0x0f, 0x10, 0x11, 0x12,
  168. };
  169. static hda_nid_t stac925x_pin_nids[8] = {
  170. 0x07, 0x08, 0x0a, 0x0b,
  171. 0x0c, 0x0d, 0x10, 0x11,
  172. };
  173. static hda_nid_t stac922x_pin_nids[10] = {
  174. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  175. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  176. };
  177. static hda_nid_t stac927x_pin_nids[14] = {
  178. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  179. 0x0f, 0x10, 0x11, 0x12, 0x13,
  180. 0x14, 0x21, 0x22, 0x23,
  181. };
  182. static hda_nid_t stac9205_pin_nids[12] = {
  183. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  184. 0x0f, 0x14, 0x16, 0x17, 0x18,
  185. 0x21, 0x22,
  186. };
  187. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  188. struct snd_ctl_elem_info *uinfo)
  189. {
  190. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  191. struct sigmatel_spec *spec = codec->spec;
  192. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  193. }
  194. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  195. struct snd_ctl_elem_value *ucontrol)
  196. {
  197. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  198. struct sigmatel_spec *spec = codec->spec;
  199. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  200. return 0;
  201. }
  202. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  203. struct snd_ctl_elem_value *ucontrol)
  204. {
  205. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  206. struct sigmatel_spec *spec = codec->spec;
  207. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  208. spec->dmux_nid, &spec->cur_dmux);
  209. }
  210. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  211. {
  212. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  213. struct sigmatel_spec *spec = codec->spec;
  214. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  215. }
  216. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  217. {
  218. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  219. struct sigmatel_spec *spec = codec->spec;
  220. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  221. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  222. return 0;
  223. }
  224. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  225. {
  226. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  227. struct sigmatel_spec *spec = codec->spec;
  228. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  229. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  230. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  231. }
  232. static struct hda_verb stac9200_core_init[] = {
  233. /* set dac0mux for dac converter */
  234. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  235. {}
  236. };
  237. static struct hda_verb stac925x_core_init[] = {
  238. /* set dac0mux for dac converter */
  239. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  240. {}
  241. };
  242. static struct hda_verb stac922x_core_init[] = {
  243. /* set master volume and direct control */
  244. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  245. {}
  246. };
  247. static struct hda_verb d965_core_init[] = {
  248. /* set master volume and direct control */
  249. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  250. /* unmute node 0x1b */
  251. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  252. /* select node 0x03 as DAC */
  253. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  254. {}
  255. };
  256. static struct hda_verb stac927x_core_init[] = {
  257. /* set master volume and direct control */
  258. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  259. {}
  260. };
  261. static struct hda_verb stac9205_core_init[] = {
  262. /* set master volume and direct control */
  263. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  264. {}
  265. };
  266. static struct snd_kcontrol_new stac9200_mixer[] = {
  267. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  268. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  269. {
  270. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  271. .name = "Input Source",
  272. .count = 1,
  273. .info = stac92xx_mux_enum_info,
  274. .get = stac92xx_mux_enum_get,
  275. .put = stac92xx_mux_enum_put,
  276. },
  277. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  278. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  279. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  280. { } /* end */
  281. };
  282. static struct snd_kcontrol_new stac925x_mixer[] = {
  283. {
  284. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  285. .name = "Input Source",
  286. .count = 1,
  287. .info = stac92xx_mux_enum_info,
  288. .get = stac92xx_mux_enum_get,
  289. .put = stac92xx_mux_enum_put,
  290. },
  291. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
  292. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
  293. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
  294. { } /* end */
  295. };
  296. /* This needs to be generated dynamically based on sequence */
  297. static struct snd_kcontrol_new stac922x_mixer[] = {
  298. {
  299. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  300. .name = "Input Source",
  301. .count = 1,
  302. .info = stac92xx_mux_enum_info,
  303. .get = stac92xx_mux_enum_get,
  304. .put = stac92xx_mux_enum_put,
  305. },
  306. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
  307. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
  308. HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  309. { } /* end */
  310. };
  311. /* This needs to be generated dynamically based on sequence */
  312. static struct snd_kcontrol_new stac9227_mixer[] = {
  313. {
  314. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  315. .name = "Input Source",
  316. .count = 1,
  317. .info = stac92xx_mux_enum_info,
  318. .get = stac92xx_mux_enum_get,
  319. .put = stac92xx_mux_enum_put,
  320. },
  321. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  322. HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  323. { } /* end */
  324. };
  325. static struct snd_kcontrol_new stac927x_mixer[] = {
  326. {
  327. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  328. .name = "Input Source",
  329. .count = 1,
  330. .info = stac92xx_mux_enum_info,
  331. .get = stac92xx_mux_enum_get,
  332. .put = stac92xx_mux_enum_put,
  333. },
  334. HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  335. HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
  336. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  337. { } /* end */
  338. };
  339. static struct snd_kcontrol_new stac9205_mixer[] = {
  340. {
  341. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  342. .name = "Digital Input Source",
  343. .count = 1,
  344. .info = stac92xx_dmux_enum_info,
  345. .get = stac92xx_dmux_enum_get,
  346. .put = stac92xx_dmux_enum_put,
  347. },
  348. {
  349. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  350. .name = "Input Source",
  351. .count = 1,
  352. .info = stac92xx_mux_enum_info,
  353. .get = stac92xx_mux_enum_get,
  354. .put = stac92xx_mux_enum_put,
  355. },
  356. HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
  357. HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
  358. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
  359. { } /* end */
  360. };
  361. static int stac92xx_build_controls(struct hda_codec *codec)
  362. {
  363. struct sigmatel_spec *spec = codec->spec;
  364. int err;
  365. int i;
  366. err = snd_hda_add_new_ctls(codec, spec->mixer);
  367. if (err < 0)
  368. return err;
  369. for (i = 0; i < spec->num_mixers; i++) {
  370. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  371. if (err < 0)
  372. return err;
  373. }
  374. if (spec->multiout.dig_out_nid) {
  375. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  376. if (err < 0)
  377. return err;
  378. }
  379. if (spec->dig_in_nid) {
  380. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  381. if (err < 0)
  382. return err;
  383. }
  384. return 0;
  385. }
  386. static unsigned int ref9200_pin_configs[8] = {
  387. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  388. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  389. };
  390. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  391. [STAC_REF] = ref9200_pin_configs,
  392. };
  393. static const char *stac9200_models[STAC_9200_MODELS] = {
  394. [STAC_REF] = "ref",
  395. };
  396. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  397. /* SigmaTel reference board */
  398. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  399. "DFI LanParty", STAC_REF),
  400. /* Dell laptops have BIOS problem */
  401. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  402. "Dell Inspiron 630m", STAC_REF),
  403. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  404. "Dell Latitude D620", STAC_REF),
  405. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  406. "Dell Latitude 120L", STAC_REF),
  407. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  408. "Dell Latitude D820", STAC_REF),
  409. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  410. "Dell Inspiron E1705/9400", STAC_REF),
  411. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  412. "Dell XPS M1710", STAC_REF),
  413. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  414. "Dell Precision M90", STAC_REF),
  415. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  416. "unknown Dell", STAC_REF),
  417. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  418. "Dell Inspiron 640m", STAC_REF),
  419. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  420. "Dell Inspiron 1501", STAC_REF),
  421. /* Panasonic */
  422. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
  423. {} /* terminator */
  424. };
  425. static unsigned int ref925x_pin_configs[8] = {
  426. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  427. 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
  428. };
  429. static unsigned int stac925x_MA6_pin_configs[8] = {
  430. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  431. 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
  432. };
  433. static unsigned int stac925x_PA6_pin_configs[8] = {
  434. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  435. 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
  436. };
  437. static unsigned int stac925xM2_2_pin_configs[8] = {
  438. 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
  439. 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
  440. };
  441. static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  442. [STAC_REF] = ref925x_pin_configs,
  443. [STAC_M2_2] = stac925xM2_2_pin_configs,
  444. [STAC_MA6] = stac925x_MA6_pin_configs,
  445. [STAC_PA6] = stac925x_PA6_pin_configs,
  446. };
  447. static const char *stac925x_models[STAC_925x_MODELS] = {
  448. [STAC_REF] = "ref",
  449. [STAC_M2_2] = "m2-2",
  450. [STAC_MA6] = "m6",
  451. [STAC_PA6] = "pa6",
  452. };
  453. static struct snd_pci_quirk stac925x_cfg_tbl[] = {
  454. /* SigmaTel reference board */
  455. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  456. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  457. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
  458. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
  459. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
  460. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
  461. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
  462. {} /* terminator */
  463. };
  464. static unsigned int ref922x_pin_configs[10] = {
  465. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  466. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  467. 0x40000100, 0x40000100,
  468. };
  469. static unsigned int d945gtp3_pin_configs[10] = {
  470. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  471. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  472. 0x02a19120, 0x40000100,
  473. };
  474. static unsigned int d945gtp5_pin_configs[10] = {
  475. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  476. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  477. 0x02a19320, 0x40000100,
  478. };
  479. static unsigned int intel_mac_v1_pin_configs[10] = {
  480. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  481. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  482. 0x400000fc, 0x400000fb,
  483. };
  484. static unsigned int intel_mac_v2_pin_configs[10] = {
  485. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  486. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  487. 0x400000fc, 0x400000fb,
  488. };
  489. static unsigned int intel_mac_v3_pin_configs[10] = {
  490. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  491. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  492. 0x400000fc, 0x400000fb,
  493. };
  494. static unsigned int intel_mac_v4_pin_configs[10] = {
  495. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  496. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  497. 0x400000fc, 0x400000fb,
  498. };
  499. static unsigned int intel_mac_v5_pin_configs[10] = {
  500. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  501. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  502. 0x400000fc, 0x400000fb,
  503. };
  504. static unsigned int stac922x_dell_pin_configs[10] = {
  505. 0x0221121e, 0x408103ff, 0x02a1123e, 0x90100310,
  506. 0x408003f1, 0x0221122f, 0x03451340, 0x40c003f2,
  507. 0x50a003f3, 0x405003f4
  508. };
  509. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  510. [STAC_D945_REF] = ref922x_pin_configs,
  511. [STAC_D945GTP3] = d945gtp3_pin_configs,
  512. [STAC_D945GTP5] = d945gtp5_pin_configs,
  513. [STAC_922X_DELL] = stac922x_dell_pin_configs,
  514. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  515. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  516. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  517. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  518. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  519. /* for backward compitability */
  520. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  521. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  522. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  523. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  524. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  525. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  526. };
  527. static const char *stac922x_models[STAC_922X_MODELS] = {
  528. [STAC_D945_REF] = "ref",
  529. [STAC_D945GTP5] = "5stack",
  530. [STAC_D945GTP3] = "3stack",
  531. [STAC_922X_DELL] = "dell",
  532. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  533. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  534. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  535. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  536. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  537. /* for backward compitability */
  538. [STAC_MACMINI] = "macmini",
  539. [STAC_MACBOOK] = "macbook",
  540. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  541. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  542. [STAC_IMAC_INTEL] = "imac-intel",
  543. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  544. };
  545. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  546. /* SigmaTel reference board */
  547. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  548. "DFI LanParty", STAC_D945_REF),
  549. /* Intel 945G based systems */
  550. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  551. "Intel D945G", STAC_D945GTP3),
  552. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  553. "Intel D945G", STAC_D945GTP3),
  554. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  555. "Intel D945G", STAC_D945GTP3),
  556. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  557. "Intel D945G", STAC_D945GTP3),
  558. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  559. "Intel D945G", STAC_D945GTP3),
  560. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  561. "Intel D945G", STAC_D945GTP3),
  562. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  563. "Intel D945G", STAC_D945GTP3),
  564. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  565. "Intel D945G", STAC_D945GTP3),
  566. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  567. "Intel D945G", STAC_D945GTP3),
  568. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  569. "Intel D945G", STAC_D945GTP3),
  570. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  571. "Intel D945G", STAC_D945GTP3),
  572. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  573. "Intel D945G", STAC_D945GTP3),
  574. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  575. "Intel D945G", STAC_D945GTP3),
  576. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  577. "Intel D945G", STAC_D945GTP3),
  578. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  579. "Intel D945G", STAC_D945GTP3),
  580. /* Intel D945G 5-stack systems */
  581. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  582. "Intel D945G", STAC_D945GTP5),
  583. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  584. "Intel D945G", STAC_D945GTP5),
  585. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  586. "Intel D945G", STAC_D945GTP5),
  587. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  588. "Intel D945G", STAC_D945GTP5),
  589. /* Intel 945P based systems */
  590. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  591. "Intel D945P", STAC_D945GTP3),
  592. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  593. "Intel D945P", STAC_D945GTP3),
  594. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  595. "Intel D945P", STAC_D945GTP3),
  596. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  597. "Intel D945P", STAC_D945GTP3),
  598. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  599. "Intel D945P", STAC_D945GTP3),
  600. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  601. "Intel D945P", STAC_D945GTP5),
  602. /* other systems */
  603. /* Apple Mac Mini (early 2006) */
  604. SND_PCI_QUIRK(0x8384, 0x7680,
  605. "Mac Mini", STAC_INTEL_MAC_V3),
  606. /* Dell */
  607. SND_PCI_QUIRK(0x1028, 0x01d7, "Dell XPS M1210", STAC_922X_DELL),
  608. {} /* terminator */
  609. };
  610. static unsigned int ref927x_pin_configs[14] = {
  611. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  612. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  613. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  614. 0x01c42190, 0x40000100,
  615. };
  616. static unsigned int d965_3st_pin_configs[14] = {
  617. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  618. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  619. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  620. 0x40000100, 0x40000100
  621. };
  622. static unsigned int d965_5st_pin_configs[14] = {
  623. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  624. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  625. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  626. 0x40000100, 0x40000100
  627. };
  628. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  629. [STAC_D965_REF] = ref927x_pin_configs,
  630. [STAC_D965_3ST] = d965_3st_pin_configs,
  631. [STAC_D965_5ST] = d965_5st_pin_configs,
  632. };
  633. static const char *stac927x_models[STAC_927X_MODELS] = {
  634. [STAC_D965_REF] = "ref",
  635. [STAC_D965_3ST] = "3stack",
  636. [STAC_D965_5ST] = "5stack",
  637. };
  638. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  639. /* SigmaTel reference board */
  640. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  641. "DFI LanParty", STAC_D965_REF),
  642. /* Intel 946 based systems */
  643. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  644. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  645. /* 965 based 3 stack systems */
  646. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
  647. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
  648. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
  649. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
  650. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
  651. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
  652. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
  653. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
  654. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
  655. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
  656. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
  657. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
  658. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
  659. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
  660. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
  661. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
  662. /* 965 based 5 stack systems */
  663. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
  664. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
  665. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
  666. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
  667. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
  668. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
  669. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
  670. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
  671. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
  672. {} /* terminator */
  673. };
  674. static unsigned int ref9205_pin_configs[12] = {
  675. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  676. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  677. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  678. };
  679. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  680. [STAC_REF] = ref9205_pin_configs,
  681. [STAC_M43xx] = NULL,
  682. };
  683. static const char *stac9205_models[STAC_9205_MODELS] = {
  684. [STAC_9205_REF] = "ref",
  685. };
  686. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  687. /* SigmaTel reference board */
  688. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  689. "DFI LanParty", STAC_9205_REF),
  690. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01f8,
  691. "Dell Precision", STAC_M43xx),
  692. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x01ff,
  693. "Dell Precision", STAC_M43xx),
  694. {} /* terminator */
  695. };
  696. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  697. {
  698. int i;
  699. struct sigmatel_spec *spec = codec->spec;
  700. if (! spec->bios_pin_configs) {
  701. spec->bios_pin_configs = kcalloc(spec->num_pins,
  702. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  703. if (! spec->bios_pin_configs)
  704. return -ENOMEM;
  705. }
  706. for (i = 0; i < spec->num_pins; i++) {
  707. hda_nid_t nid = spec->pin_nids[i];
  708. unsigned int pin_cfg;
  709. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  710. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  711. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  712. nid, pin_cfg);
  713. spec->bios_pin_configs[i] = pin_cfg;
  714. }
  715. return 0;
  716. }
  717. static void stac92xx_set_config_reg(struct hda_codec *codec,
  718. hda_nid_t pin_nid, unsigned int pin_config)
  719. {
  720. int i;
  721. snd_hda_codec_write(codec, pin_nid, 0,
  722. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  723. pin_config & 0x000000ff);
  724. snd_hda_codec_write(codec, pin_nid, 0,
  725. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  726. (pin_config & 0x0000ff00) >> 8);
  727. snd_hda_codec_write(codec, pin_nid, 0,
  728. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  729. (pin_config & 0x00ff0000) >> 16);
  730. snd_hda_codec_write(codec, pin_nid, 0,
  731. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  732. pin_config >> 24);
  733. i = snd_hda_codec_read(codec, pin_nid, 0,
  734. AC_VERB_GET_CONFIG_DEFAULT,
  735. 0x00);
  736. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
  737. pin_nid, i);
  738. }
  739. static void stac92xx_set_config_regs(struct hda_codec *codec)
  740. {
  741. int i;
  742. struct sigmatel_spec *spec = codec->spec;
  743. if (!spec->pin_configs)
  744. return;
  745. for (i = 0; i < spec->num_pins; i++)
  746. stac92xx_set_config_reg(codec, spec->pin_nids[i],
  747. spec->pin_configs[i]);
  748. }
  749. static void stac92xx_enable_gpio_mask(struct hda_codec *codec,
  750. int gpio_mask, int gpio_data)
  751. {
  752. /* Configure GPIOx as output */
  753. snd_hda_codec_write(codec, codec->afg, 0,
  754. AC_VERB_SET_GPIO_DIRECTION, gpio_mask);
  755. /* Configure GPIOx as CMOS */
  756. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
  757. /* Assert GPIOx */
  758. snd_hda_codec_write(codec, codec->afg, 0,
  759. AC_VERB_SET_GPIO_DATA, gpio_data);
  760. /* Enable GPIOx */
  761. snd_hda_codec_write(codec, codec->afg, 0,
  762. AC_VERB_SET_GPIO_MASK, gpio_mask);
  763. }
  764. /*
  765. * Analog playback callbacks
  766. */
  767. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  768. struct hda_codec *codec,
  769. struct snd_pcm_substream *substream)
  770. {
  771. struct sigmatel_spec *spec = codec->spec;
  772. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  773. }
  774. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  775. struct hda_codec *codec,
  776. unsigned int stream_tag,
  777. unsigned int format,
  778. struct snd_pcm_substream *substream)
  779. {
  780. struct sigmatel_spec *spec = codec->spec;
  781. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  782. }
  783. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  784. struct hda_codec *codec,
  785. struct snd_pcm_substream *substream)
  786. {
  787. struct sigmatel_spec *spec = codec->spec;
  788. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  789. }
  790. /*
  791. * Digital playback callbacks
  792. */
  793. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  794. struct hda_codec *codec,
  795. struct snd_pcm_substream *substream)
  796. {
  797. struct sigmatel_spec *spec = codec->spec;
  798. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  799. }
  800. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  801. struct hda_codec *codec,
  802. struct snd_pcm_substream *substream)
  803. {
  804. struct sigmatel_spec *spec = codec->spec;
  805. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  806. }
  807. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  808. struct hda_codec *codec,
  809. unsigned int stream_tag,
  810. unsigned int format,
  811. struct snd_pcm_substream *substream)
  812. {
  813. struct sigmatel_spec *spec = codec->spec;
  814. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  815. stream_tag, format, substream);
  816. }
  817. /*
  818. * Analog capture callbacks
  819. */
  820. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  821. struct hda_codec *codec,
  822. unsigned int stream_tag,
  823. unsigned int format,
  824. struct snd_pcm_substream *substream)
  825. {
  826. struct sigmatel_spec *spec = codec->spec;
  827. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  828. stream_tag, 0, format);
  829. return 0;
  830. }
  831. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  832. struct hda_codec *codec,
  833. struct snd_pcm_substream *substream)
  834. {
  835. struct sigmatel_spec *spec = codec->spec;
  836. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  837. return 0;
  838. }
  839. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  840. .substreams = 1,
  841. .channels_min = 2,
  842. .channels_max = 2,
  843. /* NID is set in stac92xx_build_pcms */
  844. .ops = {
  845. .open = stac92xx_dig_playback_pcm_open,
  846. .close = stac92xx_dig_playback_pcm_close,
  847. .prepare = stac92xx_dig_playback_pcm_prepare
  848. },
  849. };
  850. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  851. .substreams = 1,
  852. .channels_min = 2,
  853. .channels_max = 2,
  854. /* NID is set in stac92xx_build_pcms */
  855. };
  856. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  857. .substreams = 1,
  858. .channels_min = 2,
  859. .channels_max = 8,
  860. .nid = 0x02, /* NID to query formats and rates */
  861. .ops = {
  862. .open = stac92xx_playback_pcm_open,
  863. .prepare = stac92xx_playback_pcm_prepare,
  864. .cleanup = stac92xx_playback_pcm_cleanup
  865. },
  866. };
  867. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  868. .substreams = 1,
  869. .channels_min = 2,
  870. .channels_max = 2,
  871. .nid = 0x06, /* NID to query formats and rates */
  872. .ops = {
  873. .open = stac92xx_playback_pcm_open,
  874. .prepare = stac92xx_playback_pcm_prepare,
  875. .cleanup = stac92xx_playback_pcm_cleanup
  876. },
  877. };
  878. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  879. .substreams = 2,
  880. .channels_min = 2,
  881. .channels_max = 2,
  882. /* NID is set in stac92xx_build_pcms */
  883. .ops = {
  884. .prepare = stac92xx_capture_pcm_prepare,
  885. .cleanup = stac92xx_capture_pcm_cleanup
  886. },
  887. };
  888. static int stac92xx_build_pcms(struct hda_codec *codec)
  889. {
  890. struct sigmatel_spec *spec = codec->spec;
  891. struct hda_pcm *info = spec->pcm_rec;
  892. codec->num_pcms = 1;
  893. codec->pcm_info = info;
  894. info->name = "STAC92xx Analog";
  895. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  896. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  897. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  898. if (spec->alt_switch) {
  899. codec->num_pcms++;
  900. info++;
  901. info->name = "STAC92xx Analog Alt";
  902. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  903. }
  904. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  905. codec->num_pcms++;
  906. info++;
  907. info->name = "STAC92xx Digital";
  908. if (spec->multiout.dig_out_nid) {
  909. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  910. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  911. }
  912. if (spec->dig_in_nid) {
  913. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  914. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  915. }
  916. }
  917. return 0;
  918. }
  919. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  920. {
  921. unsigned int pincap = snd_hda_param_read(codec, nid,
  922. AC_PAR_PIN_CAP);
  923. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  924. if (pincap & AC_PINCAP_VREF_100)
  925. return AC_PINCTL_VREF_100;
  926. if (pincap & AC_PINCAP_VREF_80)
  927. return AC_PINCTL_VREF_80;
  928. if (pincap & AC_PINCAP_VREF_50)
  929. return AC_PINCTL_VREF_50;
  930. if (pincap & AC_PINCAP_VREF_GRD)
  931. return AC_PINCTL_VREF_GRD;
  932. return 0;
  933. }
  934. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  935. {
  936. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  937. }
  938. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  939. {
  940. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  941. uinfo->count = 1;
  942. uinfo->value.integer.min = 0;
  943. uinfo->value.integer.max = 1;
  944. return 0;
  945. }
  946. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  947. {
  948. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  949. struct sigmatel_spec *spec = codec->spec;
  950. int io_idx = kcontrol-> private_value & 0xff;
  951. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  952. return 0;
  953. }
  954. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  955. {
  956. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  957. struct sigmatel_spec *spec = codec->spec;
  958. hda_nid_t nid = kcontrol->private_value >> 8;
  959. int io_idx = kcontrol-> private_value & 0xff;
  960. unsigned short val = ucontrol->value.integer.value[0];
  961. spec->io_switch[io_idx] = val;
  962. if (val)
  963. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  964. else {
  965. unsigned int pinctl = AC_PINCTL_IN_EN;
  966. if (io_idx) /* set VREF for mic */
  967. pinctl |= stac92xx_get_vref(codec, nid);
  968. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  969. }
  970. return 1;
  971. }
  972. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  973. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  974. .name = xname, \
  975. .index = 0, \
  976. .info = stac92xx_io_switch_info, \
  977. .get = stac92xx_io_switch_get, \
  978. .put = stac92xx_io_switch_put, \
  979. .private_value = xpval, \
  980. }
  981. enum {
  982. STAC_CTL_WIDGET_VOL,
  983. STAC_CTL_WIDGET_MUTE,
  984. STAC_CTL_WIDGET_IO_SWITCH,
  985. };
  986. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  987. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  988. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  989. STAC_CODEC_IO_SWITCH(NULL, 0),
  990. };
  991. /* add dynamic controls */
  992. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  993. {
  994. struct snd_kcontrol_new *knew;
  995. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  996. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  997. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  998. if (! knew)
  999. return -ENOMEM;
  1000. if (spec->kctl_alloc) {
  1001. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1002. kfree(spec->kctl_alloc);
  1003. }
  1004. spec->kctl_alloc = knew;
  1005. spec->num_kctl_alloc = num;
  1006. }
  1007. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1008. *knew = stac92xx_control_templates[type];
  1009. knew->name = kstrdup(name, GFP_KERNEL);
  1010. if (! knew->name)
  1011. return -ENOMEM;
  1012. knew->private_value = val;
  1013. spec->num_kctl_used++;
  1014. return 0;
  1015. }
  1016. /* flag inputs as additional dynamic lineouts */
  1017. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  1018. {
  1019. struct sigmatel_spec *spec = codec->spec;
  1020. unsigned int wcaps, wtype;
  1021. int i, num_dacs = 0;
  1022. /* use the wcaps cache to count all DACs available for line-outs */
  1023. for (i = 0; i < codec->num_nodes; i++) {
  1024. wcaps = codec->wcaps[i];
  1025. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1026. if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
  1027. num_dacs++;
  1028. }
  1029. snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
  1030. switch (cfg->line_outs) {
  1031. case 3:
  1032. /* add line-in as side */
  1033. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
  1034. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
  1035. spec->line_switch = 1;
  1036. cfg->line_outs++;
  1037. }
  1038. break;
  1039. case 2:
  1040. /* add line-in as clfe and mic as side */
  1041. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
  1042. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
  1043. spec->line_switch = 1;
  1044. cfg->line_outs++;
  1045. }
  1046. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
  1047. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
  1048. spec->mic_switch = 1;
  1049. cfg->line_outs++;
  1050. }
  1051. break;
  1052. case 1:
  1053. /* add line-in as surr and mic as clfe */
  1054. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
  1055. cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
  1056. spec->line_switch = 1;
  1057. cfg->line_outs++;
  1058. }
  1059. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
  1060. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
  1061. spec->mic_switch = 1;
  1062. cfg->line_outs++;
  1063. }
  1064. break;
  1065. }
  1066. return 0;
  1067. }
  1068. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1069. {
  1070. int i;
  1071. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1072. if (spec->multiout.dac_nids[i] == nid)
  1073. return 1;
  1074. }
  1075. return 0;
  1076. }
  1077. /*
  1078. * Fill in the dac_nids table from the parsed pin configuration
  1079. * This function only works when every pin in line_out_pins[]
  1080. * contains atleast one DAC in its connection list. Some 92xx
  1081. * codecs are not connected directly to a DAC, such as the 9200
  1082. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  1083. */
  1084. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  1085. struct auto_pin_cfg *cfg)
  1086. {
  1087. struct sigmatel_spec *spec = codec->spec;
  1088. int i, j, conn_len = 0;
  1089. hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
  1090. unsigned int wcaps, wtype;
  1091. for (i = 0; i < cfg->line_outs; i++) {
  1092. nid = cfg->line_out_pins[i];
  1093. conn_len = snd_hda_get_connections(codec, nid, conn,
  1094. HDA_MAX_CONNECTIONS);
  1095. for (j = 0; j < conn_len; j++) {
  1096. wcaps = snd_hda_param_read(codec, conn[j],
  1097. AC_PAR_AUDIO_WIDGET_CAP);
  1098. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1099. if (wtype != AC_WID_AUD_OUT ||
  1100. (wcaps & AC_WCAP_DIGITAL))
  1101. continue;
  1102. /* conn[j] is a DAC routed to this line-out */
  1103. if (!is_in_dac_nids(spec, conn[j]))
  1104. break;
  1105. }
  1106. if (j == conn_len) {
  1107. if (spec->multiout.num_dacs > 0) {
  1108. /* we have already working output pins,
  1109. * so let's drop the broken ones again
  1110. */
  1111. cfg->line_outs = spec->multiout.num_dacs;
  1112. break;
  1113. }
  1114. /* error out, no available DAC found */
  1115. snd_printk(KERN_ERR
  1116. "%s: No available DAC for pin 0x%x\n",
  1117. __func__, nid);
  1118. return -ENODEV;
  1119. }
  1120. spec->multiout.dac_nids[i] = conn[j];
  1121. spec->multiout.num_dacs++;
  1122. if (conn_len > 1) {
  1123. /* select this DAC in the pin's input mux */
  1124. snd_hda_codec_write(codec, nid, 0,
  1125. AC_VERB_SET_CONNECT_SEL, j);
  1126. }
  1127. }
  1128. snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1129. spec->multiout.num_dacs,
  1130. spec->multiout.dac_nids[0],
  1131. spec->multiout.dac_nids[1],
  1132. spec->multiout.dac_nids[2],
  1133. spec->multiout.dac_nids[3],
  1134. spec->multiout.dac_nids[4]);
  1135. return 0;
  1136. }
  1137. /* create volume control/switch for the given prefx type */
  1138. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  1139. {
  1140. char name[32];
  1141. int err;
  1142. sprintf(name, "%s Playback Volume", pfx);
  1143. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  1144. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1145. if (err < 0)
  1146. return err;
  1147. sprintf(name, "%s Playback Switch", pfx);
  1148. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  1149. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1150. if (err < 0)
  1151. return err;
  1152. return 0;
  1153. }
  1154. /* add playback controls from the parsed DAC table */
  1155. static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
  1156. const struct auto_pin_cfg *cfg)
  1157. {
  1158. static const char *chname[4] = {
  1159. "Front", "Surround", NULL /*CLFE*/, "Side"
  1160. };
  1161. hda_nid_t nid;
  1162. int i, err;
  1163. for (i = 0; i < cfg->line_outs; i++) {
  1164. if (!spec->multiout.dac_nids[i])
  1165. continue;
  1166. nid = spec->multiout.dac_nids[i];
  1167. if (i == 2) {
  1168. /* Center/LFE */
  1169. err = create_controls(spec, "Center", nid, 1);
  1170. if (err < 0)
  1171. return err;
  1172. err = create_controls(spec, "LFE", nid, 2);
  1173. if (err < 0)
  1174. return err;
  1175. } else {
  1176. err = create_controls(spec, chname[i], nid, 3);
  1177. if (err < 0)
  1178. return err;
  1179. }
  1180. }
  1181. if (spec->line_switch)
  1182. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  1183. return err;
  1184. if (spec->mic_switch)
  1185. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  1186. return err;
  1187. return 0;
  1188. }
  1189. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1190. {
  1191. if (is_in_dac_nids(spec, nid))
  1192. return 1;
  1193. if (spec->multiout.hp_nid == nid)
  1194. return 1;
  1195. return 0;
  1196. }
  1197. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  1198. {
  1199. if (!spec->multiout.hp_nid)
  1200. spec->multiout.hp_nid = nid;
  1201. else if (spec->multiout.num_dacs > 4) {
  1202. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  1203. return 1;
  1204. } else {
  1205. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  1206. spec->multiout.num_dacs++;
  1207. }
  1208. return 0;
  1209. }
  1210. /* add playback controls for Speaker and HP outputs */
  1211. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  1212. struct auto_pin_cfg *cfg)
  1213. {
  1214. struct sigmatel_spec *spec = codec->spec;
  1215. hda_nid_t nid;
  1216. int i, old_num_dacs, err;
  1217. old_num_dacs = spec->multiout.num_dacs;
  1218. for (i = 0; i < cfg->hp_outs; i++) {
  1219. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  1220. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1221. spec->hp_detect = 1;
  1222. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  1223. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1224. if (check_in_dac_nids(spec, nid))
  1225. nid = 0;
  1226. if (! nid)
  1227. continue;
  1228. add_spec_dacs(spec, nid);
  1229. }
  1230. for (i = 0; i < cfg->speaker_outs; i++) {
  1231. nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
  1232. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1233. if (check_in_dac_nids(spec, nid))
  1234. nid = 0;
  1235. if (! nid)
  1236. continue;
  1237. add_spec_dacs(spec, nid);
  1238. }
  1239. for (i = 0; i < cfg->line_outs; i++) {
  1240. nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
  1241. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1242. if (check_in_dac_nids(spec, nid))
  1243. nid = 0;
  1244. if (! nid)
  1245. continue;
  1246. add_spec_dacs(spec, nid);
  1247. }
  1248. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  1249. static const char *pfxs[] = {
  1250. "Speaker", "External Speaker", "Speaker2",
  1251. };
  1252. err = create_controls(spec, pfxs[i - old_num_dacs],
  1253. spec->multiout.dac_nids[i], 3);
  1254. if (err < 0)
  1255. return err;
  1256. }
  1257. if (spec->multiout.hp_nid) {
  1258. const char *pfx;
  1259. if (old_num_dacs == spec->multiout.num_dacs)
  1260. pfx = "Master";
  1261. else
  1262. pfx = "Headphone";
  1263. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1264. if (err < 0)
  1265. return err;
  1266. }
  1267. return 0;
  1268. }
  1269. /* labels for dmic mux inputs */
  1270. static const char *stac92xx_dmic_labels[5] = {
  1271. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1272. "Digital Mic 3", "Digital Mic 4"
  1273. };
  1274. /* create playback/capture controls for input pins on dmic capable codecs */
  1275. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1276. const struct auto_pin_cfg *cfg)
  1277. {
  1278. struct sigmatel_spec *spec = codec->spec;
  1279. struct hda_input_mux *dimux = &spec->private_dimux;
  1280. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1281. int i, j;
  1282. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1283. dimux->items[dimux->num_items].index = 0;
  1284. dimux->num_items++;
  1285. for (i = 0; i < spec->num_dmics; i++) {
  1286. int index;
  1287. int num_cons;
  1288. unsigned int def_conf;
  1289. def_conf = snd_hda_codec_read(codec,
  1290. spec->dmic_nids[i],
  1291. 0,
  1292. AC_VERB_GET_CONFIG_DEFAULT,
  1293. 0);
  1294. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1295. continue;
  1296. num_cons = snd_hda_get_connections(codec,
  1297. spec->dmux_nid,
  1298. con_lst,
  1299. HDA_MAX_NUM_INPUTS);
  1300. for (j = 0; j < num_cons; j++)
  1301. if (con_lst[j] == spec->dmic_nids[i]) {
  1302. index = j;
  1303. goto found;
  1304. }
  1305. continue;
  1306. found:
  1307. dimux->items[dimux->num_items].label =
  1308. stac92xx_dmic_labels[dimux->num_items];
  1309. dimux->items[dimux->num_items].index = index;
  1310. dimux->num_items++;
  1311. }
  1312. return 0;
  1313. }
  1314. /* create playback/capture controls for input pins */
  1315. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1316. {
  1317. struct sigmatel_spec *spec = codec->spec;
  1318. struct hda_input_mux *imux = &spec->private_imux;
  1319. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1320. int i, j, k;
  1321. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1322. int index;
  1323. if (!cfg->input_pins[i])
  1324. continue;
  1325. index = -1;
  1326. for (j = 0; j < spec->num_muxes; j++) {
  1327. int num_cons;
  1328. num_cons = snd_hda_get_connections(codec,
  1329. spec->mux_nids[j],
  1330. con_lst,
  1331. HDA_MAX_NUM_INPUTS);
  1332. for (k = 0; k < num_cons; k++)
  1333. if (con_lst[k] == cfg->input_pins[i]) {
  1334. index = k;
  1335. goto found;
  1336. }
  1337. }
  1338. continue;
  1339. found:
  1340. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1341. imux->items[imux->num_items].index = index;
  1342. imux->num_items++;
  1343. }
  1344. if (imux->num_items) {
  1345. /*
  1346. * Set the current input for the muxes.
  1347. * The STAC9221 has two input muxes with identical source
  1348. * NID lists. Hopefully this won't get confused.
  1349. */
  1350. for (i = 0; i < spec->num_muxes; i++) {
  1351. snd_hda_codec_write(codec, spec->mux_nids[i], 0,
  1352. AC_VERB_SET_CONNECT_SEL,
  1353. imux->items[0].index);
  1354. }
  1355. }
  1356. return 0;
  1357. }
  1358. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1359. {
  1360. struct sigmatel_spec *spec = codec->spec;
  1361. int i;
  1362. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1363. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1364. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1365. }
  1366. }
  1367. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1368. {
  1369. struct sigmatel_spec *spec = codec->spec;
  1370. int i;
  1371. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1372. hda_nid_t pin;
  1373. pin = spec->autocfg.hp_pins[i];
  1374. if (pin) /* connect to front */
  1375. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1376. }
  1377. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1378. hda_nid_t pin;
  1379. pin = spec->autocfg.speaker_pins[i];
  1380. if (pin) /* connect to front */
  1381. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1382. }
  1383. }
  1384. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1385. {
  1386. struct sigmatel_spec *spec = codec->spec;
  1387. int err;
  1388. if ((err = snd_hda_parse_pin_def_config(codec,
  1389. &spec->autocfg,
  1390. spec->dmic_nids)) < 0)
  1391. return err;
  1392. if (! spec->autocfg.line_outs)
  1393. return 0; /* can't find valid pin config */
  1394. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1395. return err;
  1396. if (spec->multiout.num_dacs == 0)
  1397. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1398. return err;
  1399. if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  1400. (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
  1401. (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1402. return err;
  1403. if (spec->num_dmics > 0)
  1404. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1405. &spec->autocfg)) < 0)
  1406. return err;
  1407. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1408. if (spec->multiout.max_channels > 2)
  1409. spec->surr_switch = 1;
  1410. if (spec->autocfg.dig_out_pin)
  1411. spec->multiout.dig_out_nid = dig_out;
  1412. if (spec->autocfg.dig_in_pin)
  1413. spec->dig_in_nid = dig_in;
  1414. if (spec->kctl_alloc)
  1415. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1416. spec->input_mux = &spec->private_imux;
  1417. spec->dinput_mux = &spec->private_dimux;
  1418. return 1;
  1419. }
  1420. /* add playback controls for HP output */
  1421. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1422. struct auto_pin_cfg *cfg)
  1423. {
  1424. struct sigmatel_spec *spec = codec->spec;
  1425. hda_nid_t pin = cfg->hp_pins[0];
  1426. unsigned int wid_caps;
  1427. if (! pin)
  1428. return 0;
  1429. wid_caps = get_wcaps(codec, pin);
  1430. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1431. spec->hp_detect = 1;
  1432. return 0;
  1433. }
  1434. /* add playback controls for LFE output */
  1435. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1436. struct auto_pin_cfg *cfg)
  1437. {
  1438. struct sigmatel_spec *spec = codec->spec;
  1439. int err;
  1440. hda_nid_t lfe_pin = 0x0;
  1441. int i;
  1442. /*
  1443. * search speaker outs and line outs for a mono speaker pin
  1444. * with an amp. If one is found, add LFE controls
  1445. * for it.
  1446. */
  1447. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1448. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1449. unsigned long wcaps = get_wcaps(codec, pin);
  1450. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1451. if (wcaps == AC_WCAP_OUT_AMP)
  1452. /* found a mono speaker with an amp, must be lfe */
  1453. lfe_pin = pin;
  1454. }
  1455. /* if speaker_outs is 0, then speakers may be in line_outs */
  1456. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1457. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1458. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1459. unsigned long cfg;
  1460. cfg = snd_hda_codec_read(codec, pin, 0,
  1461. AC_VERB_GET_CONFIG_DEFAULT,
  1462. 0x00);
  1463. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1464. unsigned long wcaps = get_wcaps(codec, pin);
  1465. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1466. if (wcaps == AC_WCAP_OUT_AMP)
  1467. /* found a mono speaker with an amp,
  1468. must be lfe */
  1469. lfe_pin = pin;
  1470. }
  1471. }
  1472. }
  1473. if (lfe_pin) {
  1474. err = create_controls(spec, "LFE", lfe_pin, 1);
  1475. if (err < 0)
  1476. return err;
  1477. }
  1478. return 0;
  1479. }
  1480. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1481. {
  1482. struct sigmatel_spec *spec = codec->spec;
  1483. int err;
  1484. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1485. return err;
  1486. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1487. return err;
  1488. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1489. return err;
  1490. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1491. return err;
  1492. if (spec->autocfg.dig_out_pin)
  1493. spec->multiout.dig_out_nid = 0x05;
  1494. if (spec->autocfg.dig_in_pin)
  1495. spec->dig_in_nid = 0x04;
  1496. if (spec->kctl_alloc)
  1497. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1498. spec->input_mux = &spec->private_imux;
  1499. spec->dinput_mux = &spec->private_dimux;
  1500. return 1;
  1501. }
  1502. /*
  1503. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1504. * funky external mute control using GPIO pins.
  1505. */
  1506. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1507. {
  1508. unsigned int gpiostate, gpiomask, gpiodir;
  1509. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1510. AC_VERB_GET_GPIO_DATA, 0);
  1511. if (!muted)
  1512. gpiostate |= (1 << pin);
  1513. else
  1514. gpiostate &= ~(1 << pin);
  1515. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  1516. AC_VERB_GET_GPIO_MASK, 0);
  1517. gpiomask |= (1 << pin);
  1518. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  1519. AC_VERB_GET_GPIO_DIRECTION, 0);
  1520. gpiodir |= (1 << pin);
  1521. /* AppleHDA seems to do this -- WTF is this verb?? */
  1522. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  1523. snd_hda_codec_write(codec, codec->afg, 0,
  1524. AC_VERB_SET_GPIO_MASK, gpiomask);
  1525. snd_hda_codec_write(codec, codec->afg, 0,
  1526. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  1527. msleep(1);
  1528. snd_hda_codec_write(codec, codec->afg, 0,
  1529. AC_VERB_SET_GPIO_DATA, gpiostate);
  1530. }
  1531. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  1532. unsigned int event)
  1533. {
  1534. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  1535. snd_hda_codec_write(codec, nid, 0,
  1536. AC_VERB_SET_UNSOLICITED_ENABLE,
  1537. (AC_USRSP_EN | event));
  1538. }
  1539. static int stac92xx_init(struct hda_codec *codec)
  1540. {
  1541. struct sigmatel_spec *spec = codec->spec;
  1542. struct auto_pin_cfg *cfg = &spec->autocfg;
  1543. int i;
  1544. snd_hda_sequence_write(codec, spec->init);
  1545. /* set up pins */
  1546. if (spec->hp_detect) {
  1547. /* Enable unsolicited responses on the HP widget */
  1548. for (i = 0; i < cfg->hp_outs; i++)
  1549. enable_pin_detect(codec, cfg->hp_pins[i],
  1550. STAC_HP_EVENT);
  1551. /* force to enable the first line-out; the others are set up
  1552. * in unsol_event
  1553. */
  1554. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  1555. AC_PINCTL_OUT_EN);
  1556. stac92xx_auto_init_hp_out(codec);
  1557. /* fake event to set up pins */
  1558. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  1559. } else {
  1560. stac92xx_auto_init_multi_out(codec);
  1561. stac92xx_auto_init_hp_out(codec);
  1562. }
  1563. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1564. hda_nid_t nid = cfg->input_pins[i];
  1565. if (nid) {
  1566. unsigned int pinctl = AC_PINCTL_IN_EN;
  1567. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  1568. pinctl |= stac92xx_get_vref(codec, nid);
  1569. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1570. }
  1571. }
  1572. if (spec->num_dmics > 0)
  1573. for (i = 0; i < spec->num_dmics; i++)
  1574. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  1575. AC_PINCTL_IN_EN);
  1576. if (cfg->dig_out_pin)
  1577. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  1578. AC_PINCTL_OUT_EN);
  1579. if (cfg->dig_in_pin)
  1580. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  1581. AC_PINCTL_IN_EN);
  1582. if (spec->gpio_mute) {
  1583. stac922x_gpio_mute(codec, 0, 0);
  1584. stac922x_gpio_mute(codec, 1, 0);
  1585. }
  1586. return 0;
  1587. }
  1588. static void stac92xx_free(struct hda_codec *codec)
  1589. {
  1590. struct sigmatel_spec *spec = codec->spec;
  1591. int i;
  1592. if (! spec)
  1593. return;
  1594. if (spec->kctl_alloc) {
  1595. for (i = 0; i < spec->num_kctl_used; i++)
  1596. kfree(spec->kctl_alloc[i].name);
  1597. kfree(spec->kctl_alloc);
  1598. }
  1599. if (spec->bios_pin_configs)
  1600. kfree(spec->bios_pin_configs);
  1601. kfree(spec);
  1602. }
  1603. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1604. unsigned int flag)
  1605. {
  1606. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1607. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1608. if (pin_ctl & AC_PINCTL_IN_EN) {
  1609. /*
  1610. * we need to check the current set-up direction of
  1611. * shared input pins since they can be switched via
  1612. * "xxx as Output" mixer switch
  1613. */
  1614. struct sigmatel_spec *spec = codec->spec;
  1615. struct auto_pin_cfg *cfg = &spec->autocfg;
  1616. if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
  1617. spec->line_switch) ||
  1618. (nid == cfg->input_pins[AUTO_PIN_MIC] &&
  1619. spec->mic_switch))
  1620. return;
  1621. }
  1622. /* if setting pin direction bits, clear the current
  1623. direction bits first */
  1624. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  1625. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  1626. snd_hda_codec_write(codec, nid, 0,
  1627. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1628. pin_ctl | flag);
  1629. }
  1630. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1631. unsigned int flag)
  1632. {
  1633. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1634. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1635. snd_hda_codec_write(codec, nid, 0,
  1636. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1637. pin_ctl & ~flag);
  1638. }
  1639. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  1640. {
  1641. if (!nid)
  1642. return 0;
  1643. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  1644. & (1 << 31))
  1645. return 1;
  1646. return 0;
  1647. }
  1648. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  1649. {
  1650. struct sigmatel_spec *spec = codec->spec;
  1651. struct auto_pin_cfg *cfg = &spec->autocfg;
  1652. int i, presence;
  1653. presence = 0;
  1654. for (i = 0; i < cfg->hp_outs; i++) {
  1655. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  1656. if (presence)
  1657. break;
  1658. }
  1659. if (presence) {
  1660. /* disable lineouts, enable hp */
  1661. for (i = 0; i < cfg->line_outs; i++)
  1662. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  1663. AC_PINCTL_OUT_EN);
  1664. for (i = 0; i < cfg->speaker_outs; i++)
  1665. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  1666. AC_PINCTL_OUT_EN);
  1667. } else {
  1668. /* enable lineouts, disable hp */
  1669. for (i = 0; i < cfg->line_outs; i++)
  1670. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  1671. AC_PINCTL_OUT_EN);
  1672. for (i = 0; i < cfg->speaker_outs; i++)
  1673. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  1674. AC_PINCTL_OUT_EN);
  1675. }
  1676. }
  1677. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  1678. {
  1679. switch (res >> 26) {
  1680. case STAC_HP_EVENT:
  1681. stac92xx_hp_detect(codec, res);
  1682. break;
  1683. }
  1684. }
  1685. #ifdef CONFIG_PM
  1686. static int stac92xx_resume(struct hda_codec *codec)
  1687. {
  1688. struct sigmatel_spec *spec = codec->spec;
  1689. int i;
  1690. stac92xx_init(codec);
  1691. stac92xx_set_config_regs(codec);
  1692. snd_hda_resume_ctls(codec, spec->mixer);
  1693. for (i = 0; i < spec->num_mixers; i++)
  1694. snd_hda_resume_ctls(codec, spec->mixers[i]);
  1695. if (spec->multiout.dig_out_nid)
  1696. snd_hda_resume_spdif_out(codec);
  1697. if (spec->dig_in_nid)
  1698. snd_hda_resume_spdif_in(codec);
  1699. return 0;
  1700. }
  1701. #endif
  1702. static struct hda_codec_ops stac92xx_patch_ops = {
  1703. .build_controls = stac92xx_build_controls,
  1704. .build_pcms = stac92xx_build_pcms,
  1705. .init = stac92xx_init,
  1706. .free = stac92xx_free,
  1707. .unsol_event = stac92xx_unsol_event,
  1708. #ifdef CONFIG_PM
  1709. .resume = stac92xx_resume,
  1710. #endif
  1711. };
  1712. static int patch_stac9200(struct hda_codec *codec)
  1713. {
  1714. struct sigmatel_spec *spec;
  1715. int err;
  1716. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1717. if (spec == NULL)
  1718. return -ENOMEM;
  1719. codec->spec = spec;
  1720. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  1721. spec->pin_nids = stac9200_pin_nids;
  1722. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  1723. stac9200_models,
  1724. stac9200_cfg_tbl);
  1725. if (spec->board_config < 0) {
  1726. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  1727. err = stac92xx_save_bios_config_regs(codec);
  1728. if (err < 0) {
  1729. stac92xx_free(codec);
  1730. return err;
  1731. }
  1732. spec->pin_configs = spec->bios_pin_configs;
  1733. } else {
  1734. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  1735. stac92xx_set_config_regs(codec);
  1736. }
  1737. spec->multiout.max_channels = 2;
  1738. spec->multiout.num_dacs = 1;
  1739. spec->multiout.dac_nids = stac9200_dac_nids;
  1740. spec->adc_nids = stac9200_adc_nids;
  1741. spec->mux_nids = stac9200_mux_nids;
  1742. spec->num_muxes = 1;
  1743. spec->num_dmics = 0;
  1744. spec->init = stac9200_core_init;
  1745. spec->mixer = stac9200_mixer;
  1746. err = stac9200_parse_auto_config(codec);
  1747. if (err < 0) {
  1748. stac92xx_free(codec);
  1749. return err;
  1750. }
  1751. codec->patch_ops = stac92xx_patch_ops;
  1752. return 0;
  1753. }
  1754. static int patch_stac925x(struct hda_codec *codec)
  1755. {
  1756. struct sigmatel_spec *spec;
  1757. int err;
  1758. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1759. if (spec == NULL)
  1760. return -ENOMEM;
  1761. codec->spec = spec;
  1762. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  1763. spec->pin_nids = stac925x_pin_nids;
  1764. spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
  1765. stac925x_models,
  1766. stac925x_cfg_tbl);
  1767. again:
  1768. if (spec->board_config < 0) {
  1769. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
  1770. "using BIOS defaults\n");
  1771. err = stac92xx_save_bios_config_regs(codec);
  1772. if (err < 0) {
  1773. stac92xx_free(codec);
  1774. return err;
  1775. }
  1776. spec->pin_configs = spec->bios_pin_configs;
  1777. } else if (stac925x_brd_tbl[spec->board_config] != NULL){
  1778. spec->pin_configs = stac925x_brd_tbl[spec->board_config];
  1779. stac92xx_set_config_regs(codec);
  1780. }
  1781. spec->multiout.max_channels = 2;
  1782. spec->multiout.num_dacs = 1;
  1783. spec->multiout.dac_nids = stac925x_dac_nids;
  1784. spec->adc_nids = stac925x_adc_nids;
  1785. spec->mux_nids = stac925x_mux_nids;
  1786. spec->num_muxes = 1;
  1787. switch (codec->vendor_id) {
  1788. case 0x83847632: /* STAC9202 */
  1789. case 0x83847633: /* STAC9202D */
  1790. case 0x83847636: /* STAC9251 */
  1791. case 0x83847637: /* STAC9251D */
  1792. spec->num_dmics = 1;
  1793. spec->dmic_nids = stac925x_dmic_nids;
  1794. break;
  1795. default:
  1796. spec->num_dmics = 0;
  1797. break;
  1798. }
  1799. spec->init = stac925x_core_init;
  1800. spec->mixer = stac925x_mixer;
  1801. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  1802. if (!err) {
  1803. if (spec->board_config < 0) {
  1804. printk(KERN_WARNING "hda_codec: No auto-config is "
  1805. "available, default to model=ref\n");
  1806. spec->board_config = STAC_925x_REF;
  1807. goto again;
  1808. }
  1809. err = -EINVAL;
  1810. }
  1811. if (err < 0) {
  1812. stac92xx_free(codec);
  1813. return err;
  1814. }
  1815. codec->patch_ops = stac92xx_patch_ops;
  1816. return 0;
  1817. }
  1818. static int patch_stac922x(struct hda_codec *codec)
  1819. {
  1820. struct sigmatel_spec *spec;
  1821. int err;
  1822. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1823. if (spec == NULL)
  1824. return -ENOMEM;
  1825. codec->spec = spec;
  1826. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  1827. spec->pin_nids = stac922x_pin_nids;
  1828. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  1829. stac922x_models,
  1830. stac922x_cfg_tbl);
  1831. if (spec->board_config == STAC_INTEL_MAC_V3) {
  1832. spec->gpio_mute = 1;
  1833. /* Intel Macs have all same PCI SSID, so we need to check
  1834. * codec SSID to distinguish the exact models
  1835. */
  1836. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  1837. switch (codec->subsystem_id) {
  1838. case 0x106b0800:
  1839. spec->board_config = STAC_INTEL_MAC_V1;
  1840. break;
  1841. case 0x106b0600:
  1842. case 0x106b0700:
  1843. spec->board_config = STAC_INTEL_MAC_V2;
  1844. break;
  1845. case 0x106b0e00:
  1846. case 0x106b0f00:
  1847. case 0x106b1600:
  1848. case 0x106b1700:
  1849. case 0x106b0200:
  1850. case 0x106b1e00:
  1851. spec->board_config = STAC_INTEL_MAC_V3;
  1852. break;
  1853. case 0x106b1a00:
  1854. case 0x00000100:
  1855. spec->board_config = STAC_INTEL_MAC_V4;
  1856. break;
  1857. case 0x106b0a00:
  1858. case 0x106b2200:
  1859. spec->board_config = STAC_INTEL_MAC_V5;
  1860. break;
  1861. }
  1862. }
  1863. again:
  1864. if (spec->board_config < 0) {
  1865. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  1866. "using BIOS defaults\n");
  1867. err = stac92xx_save_bios_config_regs(codec);
  1868. if (err < 0) {
  1869. stac92xx_free(codec);
  1870. return err;
  1871. }
  1872. spec->pin_configs = spec->bios_pin_configs;
  1873. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  1874. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  1875. stac92xx_set_config_regs(codec);
  1876. }
  1877. spec->adc_nids = stac922x_adc_nids;
  1878. spec->mux_nids = stac922x_mux_nids;
  1879. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  1880. spec->num_dmics = 0;
  1881. spec->init = stac922x_core_init;
  1882. spec->mixer = stac922x_mixer;
  1883. spec->multiout.dac_nids = spec->dac_nids;
  1884. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  1885. if (!err) {
  1886. if (spec->board_config < 0) {
  1887. printk(KERN_WARNING "hda_codec: No auto-config is "
  1888. "available, default to model=ref\n");
  1889. spec->board_config = STAC_D945_REF;
  1890. goto again;
  1891. }
  1892. err = -EINVAL;
  1893. }
  1894. if (err < 0) {
  1895. stac92xx_free(codec);
  1896. return err;
  1897. }
  1898. codec->patch_ops = stac92xx_patch_ops;
  1899. /* Fix Mux capture level; max to 2 */
  1900. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  1901. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  1902. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1903. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1904. (0 << AC_AMPCAP_MUTE_SHIFT));
  1905. return 0;
  1906. }
  1907. static int patch_stac927x(struct hda_codec *codec)
  1908. {
  1909. struct sigmatel_spec *spec;
  1910. int err;
  1911. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1912. if (spec == NULL)
  1913. return -ENOMEM;
  1914. codec->spec = spec;
  1915. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  1916. spec->pin_nids = stac927x_pin_nids;
  1917. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  1918. stac927x_models,
  1919. stac927x_cfg_tbl);
  1920. again:
  1921. if (spec->board_config < 0) {
  1922. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  1923. err = stac92xx_save_bios_config_regs(codec);
  1924. if (err < 0) {
  1925. stac92xx_free(codec);
  1926. return err;
  1927. }
  1928. spec->pin_configs = spec->bios_pin_configs;
  1929. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  1930. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  1931. stac92xx_set_config_regs(codec);
  1932. }
  1933. switch (spec->board_config) {
  1934. case STAC_D965_3ST:
  1935. spec->adc_nids = stac927x_adc_nids;
  1936. spec->mux_nids = stac927x_mux_nids;
  1937. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  1938. spec->num_dmics = 0;
  1939. spec->init = d965_core_init;
  1940. spec->mixer = stac9227_mixer;
  1941. break;
  1942. case STAC_D965_5ST:
  1943. spec->adc_nids = stac927x_adc_nids;
  1944. spec->mux_nids = stac927x_mux_nids;
  1945. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  1946. spec->num_dmics = 0;
  1947. spec->init = d965_core_init;
  1948. spec->mixer = stac9227_mixer;
  1949. break;
  1950. default:
  1951. spec->adc_nids = stac927x_adc_nids;
  1952. spec->mux_nids = stac927x_mux_nids;
  1953. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  1954. spec->num_dmics = 0;
  1955. spec->init = stac927x_core_init;
  1956. spec->mixer = stac927x_mixer;
  1957. }
  1958. spec->multiout.dac_nids = spec->dac_nids;
  1959. /* GPIO0 High = Enable EAPD */
  1960. stac92xx_enable_gpio_mask(codec, 0x00000001, 0x00000001);
  1961. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  1962. if (!err) {
  1963. if (spec->board_config < 0) {
  1964. printk(KERN_WARNING "hda_codec: No auto-config is "
  1965. "available, default to model=ref\n");
  1966. spec->board_config = STAC_D965_REF;
  1967. goto again;
  1968. }
  1969. err = -EINVAL;
  1970. }
  1971. if (err < 0) {
  1972. stac92xx_free(codec);
  1973. return err;
  1974. }
  1975. codec->patch_ops = stac92xx_patch_ops;
  1976. return 0;
  1977. }
  1978. static int patch_stac9205(struct hda_codec *codec)
  1979. {
  1980. struct sigmatel_spec *spec;
  1981. int err, gpio_mask, gpio_data;
  1982. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1983. if (spec == NULL)
  1984. return -ENOMEM;
  1985. codec->spec = spec;
  1986. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  1987. spec->pin_nids = stac9205_pin_nids;
  1988. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  1989. stac9205_models,
  1990. stac9205_cfg_tbl);
  1991. again:
  1992. if (spec->board_config < 0) {
  1993. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  1994. err = stac92xx_save_bios_config_regs(codec);
  1995. if (err < 0) {
  1996. stac92xx_free(codec);
  1997. return err;
  1998. }
  1999. spec->pin_configs = spec->bios_pin_configs;
  2000. } else {
  2001. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  2002. stac92xx_set_config_regs(codec);
  2003. }
  2004. spec->adc_nids = stac9205_adc_nids;
  2005. spec->mux_nids = stac9205_mux_nids;
  2006. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  2007. spec->dmic_nids = stac9205_dmic_nids;
  2008. spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
  2009. spec->dmux_nid = 0x1d;
  2010. spec->init = stac9205_core_init;
  2011. spec->mixer = stac9205_mixer;
  2012. spec->multiout.dac_nids = spec->dac_nids;
  2013. if (spec->board_config == STAC_M43xx) {
  2014. /* Enable SPDIF in/out */
  2015. stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
  2016. stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
  2017. gpio_mask = 0x00000007; /* GPIO0-2 */
  2018. /* GPIO0 High = EAPD, GPIO1 Low = DRM,
  2019. * GPIO2 High = Headphone Mute
  2020. */
  2021. gpio_data = 0x00000005;
  2022. } else
  2023. gpio_mask = gpio_data = 0x00000001; /* GPIO0 High = EAPD */
  2024. stac92xx_enable_gpio_mask(codec, gpio_mask, gpio_data);
  2025. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  2026. if (!err) {
  2027. if (spec->board_config < 0) {
  2028. printk(KERN_WARNING "hda_codec: No auto-config is "
  2029. "available, default to model=ref\n");
  2030. spec->board_config = STAC_9205_REF;
  2031. goto again;
  2032. }
  2033. err = -EINVAL;
  2034. }
  2035. if (err < 0) {
  2036. stac92xx_free(codec);
  2037. return err;
  2038. }
  2039. codec->patch_ops = stac92xx_patch_ops;
  2040. return 0;
  2041. }
  2042. /*
  2043. * STAC9872 hack
  2044. */
  2045. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  2046. static hda_nid_t vaio_dacs[] = { 0x2 };
  2047. #define VAIO_HP_DAC 0x5
  2048. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  2049. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  2050. static struct hda_input_mux vaio_mux = {
  2051. .num_items = 2,
  2052. .items = {
  2053. /* { "HP", 0x0 }, */
  2054. { "Mic Jack", 0x1 },
  2055. { "Internal Mic", 0x2 },
  2056. { "PCM", 0x3 },
  2057. }
  2058. };
  2059. static struct hda_verb vaio_init[] = {
  2060. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2061. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2062. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2063. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2064. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2065. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2066. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2067. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2068. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2069. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2070. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2071. {}
  2072. };
  2073. static struct hda_verb vaio_ar_init[] = {
  2074. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2075. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2076. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2077. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2078. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  2079. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2080. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2081. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2082. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2083. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  2084. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2085. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2086. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2087. {}
  2088. };
  2089. /* bind volumes of both NID 0x02 and 0x05 */
  2090. static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
  2091. struct snd_ctl_elem_value *ucontrol)
  2092. {
  2093. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2094. long *valp = ucontrol->value.integer.value;
  2095. int change;
  2096. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  2097. 0x7f, valp[0] & 0x7f);
  2098. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  2099. 0x7f, valp[1] & 0x7f);
  2100. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  2101. 0x7f, valp[0] & 0x7f);
  2102. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  2103. 0x7f, valp[1] & 0x7f);
  2104. return change;
  2105. }
  2106. /* bind volumes of both NID 0x02 and 0x05 */
  2107. static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
  2108. struct snd_ctl_elem_value *ucontrol)
  2109. {
  2110. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2111. long *valp = ucontrol->value.integer.value;
  2112. int change;
  2113. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  2114. 0x80, (valp[0] ? 0 : 0x80));
  2115. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  2116. 0x80, (valp[1] ? 0 : 0x80));
  2117. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  2118. 0x80, (valp[0] ? 0 : 0x80));
  2119. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  2120. 0x80, (valp[1] ? 0 : 0x80));
  2121. return change;
  2122. }
  2123. static struct snd_kcontrol_new vaio_mixer[] = {
  2124. {
  2125. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2126. .name = "Master Playback Volume",
  2127. .info = snd_hda_mixer_amp_volume_info,
  2128. .get = snd_hda_mixer_amp_volume_get,
  2129. .put = vaio_master_vol_put,
  2130. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2131. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2132. },
  2133. {
  2134. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2135. .name = "Master Playback Switch",
  2136. .info = snd_hda_mixer_amp_switch_info,
  2137. .get = snd_hda_mixer_amp_switch_get,
  2138. .put = vaio_master_sw_put,
  2139. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2140. },
  2141. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2142. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2143. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2144. {
  2145. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2146. .name = "Capture Source",
  2147. .count = 1,
  2148. .info = stac92xx_mux_enum_info,
  2149. .get = stac92xx_mux_enum_get,
  2150. .put = stac92xx_mux_enum_put,
  2151. },
  2152. {}
  2153. };
  2154. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  2155. {
  2156. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2157. .name = "Master Playback Volume",
  2158. .info = snd_hda_mixer_amp_volume_info,
  2159. .get = snd_hda_mixer_amp_volume_get,
  2160. .put = vaio_master_vol_put,
  2161. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2162. },
  2163. {
  2164. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2165. .name = "Master Playback Switch",
  2166. .info = snd_hda_mixer_amp_switch_info,
  2167. .get = snd_hda_mixer_amp_switch_get,
  2168. .put = vaio_master_sw_put,
  2169. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2170. },
  2171. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2172. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2173. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2174. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  2175. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  2176. {
  2177. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2178. .name = "Capture Source",
  2179. .count = 1,
  2180. .info = stac92xx_mux_enum_info,
  2181. .get = stac92xx_mux_enum_get,
  2182. .put = stac92xx_mux_enum_put,
  2183. },
  2184. {}
  2185. };
  2186. static struct hda_codec_ops stac9872_patch_ops = {
  2187. .build_controls = stac92xx_build_controls,
  2188. .build_pcms = stac92xx_build_pcms,
  2189. .init = stac92xx_init,
  2190. .free = stac92xx_free,
  2191. #ifdef CONFIG_PM
  2192. .resume = stac92xx_resume,
  2193. #endif
  2194. };
  2195. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  2196. CXD9872RD_VAIO,
  2197. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  2198. STAC9872AK_VAIO,
  2199. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  2200. STAC9872K_VAIO,
  2201. /* AR Series. id=0x83847664 and subsys=104D1300 */
  2202. CXD9872AKD_VAIO,
  2203. STAC_9872_MODELS,
  2204. };
  2205. static const char *stac9872_models[STAC_9872_MODELS] = {
  2206. [CXD9872RD_VAIO] = "vaio",
  2207. [CXD9872AKD_VAIO] = "vaio-ar",
  2208. };
  2209. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  2210. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  2211. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  2212. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  2213. SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
  2214. {}
  2215. };
  2216. static int patch_stac9872(struct hda_codec *codec)
  2217. {
  2218. struct sigmatel_spec *spec;
  2219. int board_config;
  2220. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  2221. stac9872_models,
  2222. stac9872_cfg_tbl);
  2223. if (board_config < 0)
  2224. /* unknown config, let generic-parser do its job... */
  2225. return snd_hda_parse_generic_codec(codec);
  2226. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2227. if (spec == NULL)
  2228. return -ENOMEM;
  2229. codec->spec = spec;
  2230. switch (board_config) {
  2231. case CXD9872RD_VAIO:
  2232. case STAC9872AK_VAIO:
  2233. case STAC9872K_VAIO:
  2234. spec->mixer = vaio_mixer;
  2235. spec->init = vaio_init;
  2236. spec->multiout.max_channels = 2;
  2237. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2238. spec->multiout.dac_nids = vaio_dacs;
  2239. spec->multiout.hp_nid = VAIO_HP_DAC;
  2240. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2241. spec->adc_nids = vaio_adcs;
  2242. spec->input_mux = &vaio_mux;
  2243. spec->mux_nids = vaio_mux_nids;
  2244. break;
  2245. case CXD9872AKD_VAIO:
  2246. spec->mixer = vaio_ar_mixer;
  2247. spec->init = vaio_ar_init;
  2248. spec->multiout.max_channels = 2;
  2249. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2250. spec->multiout.dac_nids = vaio_dacs;
  2251. spec->multiout.hp_nid = VAIO_HP_DAC;
  2252. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2253. spec->adc_nids = vaio_adcs;
  2254. spec->input_mux = &vaio_mux;
  2255. spec->mux_nids = vaio_mux_nids;
  2256. break;
  2257. }
  2258. codec->patch_ops = stac9872_patch_ops;
  2259. return 0;
  2260. }
  2261. /*
  2262. * patch entries
  2263. */
  2264. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  2265. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  2266. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  2267. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  2268. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  2269. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  2270. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  2271. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  2272. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  2273. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  2274. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  2275. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  2276. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  2277. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  2278. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  2279. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  2280. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  2281. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  2282. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  2283. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  2284. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  2285. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  2286. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  2287. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  2288. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  2289. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  2290. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  2291. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  2292. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  2293. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  2294. /* The following does not take into account .id=0x83847661 when subsys =
  2295. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  2296. * currently not fully supported.
  2297. */
  2298. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  2299. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  2300. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  2301. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  2302. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  2303. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  2304. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  2305. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  2306. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  2307. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  2308. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  2309. {} /* terminator */
  2310. };