patch_sigmatel.c 68 KB

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