patch_sigmatel.c 70 KB

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