PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/sound/pci/hda/patch_sigmatel.c

https://code.google.com/
C | 6318 lines | 5058 code | 749 blank | 511 comment | 689 complexity | 1dc7dc31c7f3ca7483ebe3402c279632 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/pci.h>
  30. #include <linux/dmi.h>
  31. #include <sound/core.h>
  32. #include <sound/asoundef.h>
  33. #include <sound/jack.h>
  34. #include "hda_codec.h"
  35. #include "hda_local.h"
  36. #include "hda_beep.h"
  37. enum {
  38. STAC_VREF_EVENT = 1,
  39. STAC_INSERT_EVENT,
  40. STAC_PWR_EVENT,
  41. STAC_HP_EVENT,
  42. STAC_LO_EVENT,
  43. STAC_MIC_EVENT,
  44. };
  45. enum {
  46. STAC_AUTO,
  47. STAC_REF,
  48. STAC_9200_OQO,
  49. STAC_9200_DELL_D21,
  50. STAC_9200_DELL_D22,
  51. STAC_9200_DELL_D23,
  52. STAC_9200_DELL_M21,
  53. STAC_9200_DELL_M22,
  54. STAC_9200_DELL_M23,
  55. STAC_9200_DELL_M24,
  56. STAC_9200_DELL_M25,
  57. STAC_9200_DELL_M26,
  58. STAC_9200_DELL_M27,
  59. STAC_9200_M4,
  60. STAC_9200_M4_2,
  61. STAC_9200_PANASONIC,
  62. STAC_9200_MODELS
  63. };
  64. enum {
  65. STAC_9205_AUTO,
  66. STAC_9205_REF,
  67. STAC_9205_DELL_M42,
  68. STAC_9205_DELL_M43,
  69. STAC_9205_DELL_M44,
  70. STAC_9205_EAPD,
  71. STAC_9205_MODELS
  72. };
  73. enum {
  74. STAC_92HD73XX_AUTO,
  75. STAC_92HD73XX_NO_JD, /* no jack-detection */
  76. STAC_92HD73XX_REF,
  77. STAC_92HD73XX_INTEL,
  78. STAC_DELL_M6_AMIC,
  79. STAC_DELL_M6_DMIC,
  80. STAC_DELL_M6_BOTH,
  81. STAC_DELL_EQ,
  82. STAC_ALIENWARE_M17X,
  83. STAC_92HD73XX_MODELS
  84. };
  85. enum {
  86. STAC_92HD83XXX_AUTO,
  87. STAC_92HD83XXX_REF,
  88. STAC_92HD83XXX_PWR_REF,
  89. STAC_DELL_S14,
  90. STAC_92HD83XXX_HP,
  91. STAC_92HD83XXX_MODELS
  92. };
  93. enum {
  94. STAC_92HD71BXX_AUTO,
  95. STAC_92HD71BXX_REF,
  96. STAC_DELL_M4_1,
  97. STAC_DELL_M4_2,
  98. STAC_DELL_M4_3,
  99. STAC_HP_M4,
  100. STAC_HP_DV4,
  101. STAC_HP_DV5,
  102. STAC_HP_HDX,
  103. STAC_HP_DV4_1222NR,
  104. STAC_92HD71BXX_MODELS
  105. };
  106. enum {
  107. STAC_925x_AUTO,
  108. STAC_925x_REF,
  109. STAC_M1,
  110. STAC_M1_2,
  111. STAC_M2,
  112. STAC_M2_2,
  113. STAC_M3,
  114. STAC_M5,
  115. STAC_M6,
  116. STAC_925x_MODELS
  117. };
  118. enum {
  119. STAC_922X_AUTO,
  120. STAC_D945_REF,
  121. STAC_D945GTP3,
  122. STAC_D945GTP5,
  123. STAC_INTEL_MAC_V1,
  124. STAC_INTEL_MAC_V2,
  125. STAC_INTEL_MAC_V3,
  126. STAC_INTEL_MAC_V4,
  127. STAC_INTEL_MAC_V5,
  128. STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
  129. * is given, one of the above models will be
  130. * chosen according to the subsystem id. */
  131. /* for backward compatibility */
  132. STAC_MACMINI,
  133. STAC_MACBOOK,
  134. STAC_MACBOOK_PRO_V1,
  135. STAC_MACBOOK_PRO_V2,
  136. STAC_IMAC_INTEL,
  137. STAC_IMAC_INTEL_20,
  138. STAC_ECS_202,
  139. STAC_922X_DELL_D81,
  140. STAC_922X_DELL_D82,
  141. STAC_922X_DELL_M81,
  142. STAC_922X_DELL_M82,
  143. STAC_922X_MODELS
  144. };
  145. enum {
  146. STAC_927X_AUTO,
  147. STAC_D965_REF_NO_JD, /* no jack-detection */
  148. STAC_D965_REF,
  149. STAC_D965_3ST,
  150. STAC_D965_5ST,
  151. STAC_D965_5ST_NO_FP,
  152. STAC_DELL_3ST,
  153. STAC_DELL_BIOS,
  154. STAC_927X_VOLKNOB,
  155. STAC_927X_MODELS
  156. };
  157. enum {
  158. STAC_9872_AUTO,
  159. STAC_9872_VAIO,
  160. STAC_9872_MODELS
  161. };
  162. struct sigmatel_event {
  163. hda_nid_t nid;
  164. unsigned char type;
  165. unsigned char tag;
  166. int data;
  167. };
  168. struct sigmatel_jack {
  169. hda_nid_t nid;
  170. int type;
  171. struct snd_jack *jack;
  172. };
  173. struct sigmatel_mic_route {
  174. hda_nid_t pin;
  175. signed char mux_idx;
  176. signed char dmux_idx;
  177. };
  178. struct sigmatel_spec {
  179. struct snd_kcontrol_new *mixers[4];
  180. unsigned int num_mixers;
  181. int board_config;
  182. unsigned int eapd_switch: 1;
  183. unsigned int surr_switch: 1;
  184. unsigned int alt_switch: 1;
  185. unsigned int hp_detect: 1;
  186. unsigned int spdif_mute: 1;
  187. unsigned int check_volume_offset:1;
  188. unsigned int auto_mic:1;
  189. unsigned int linear_tone_beep:1;
  190. /* gpio lines */
  191. unsigned int eapd_mask;
  192. unsigned int gpio_mask;
  193. unsigned int gpio_dir;
  194. unsigned int gpio_data;
  195. unsigned int gpio_mute;
  196. unsigned int gpio_led;
  197. unsigned int gpio_led_polarity;
  198. /* stream */
  199. unsigned int stream_delay;
  200. /* analog loopback */
  201. struct snd_kcontrol_new *aloopback_ctl;
  202. unsigned char aloopback_mask;
  203. unsigned char aloopback_shift;
  204. /* power management */
  205. unsigned int num_pwrs;
  206. unsigned int *pwr_mapping;
  207. hda_nid_t *pwr_nids;
  208. hda_nid_t *dac_list;
  209. /* jack detection */
  210. struct snd_array jacks;
  211. /* events */
  212. struct snd_array events;
  213. /* playback */
  214. struct hda_input_mux *mono_mux;
  215. unsigned int cur_mmux;
  216. struct hda_multi_out multiout;
  217. hda_nid_t dac_nids[5];
  218. hda_nid_t hp_dacs[5];
  219. hda_nid_t speaker_dacs[5];
  220. int volume_offset;
  221. /* capture */
  222. hda_nid_t *adc_nids;
  223. unsigned int num_adcs;
  224. hda_nid_t *mux_nids;
  225. unsigned int num_muxes;
  226. hda_nid_t *dmic_nids;
  227. unsigned int num_dmics;
  228. hda_nid_t *dmux_nids;
  229. unsigned int num_dmuxes;
  230. hda_nid_t *smux_nids;
  231. unsigned int num_smuxes;
  232. unsigned int num_analog_muxes;
  233. unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
  234. unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
  235. unsigned int num_caps; /* number of capture volume/switch elements */
  236. struct sigmatel_mic_route ext_mic;
  237. struct sigmatel_mic_route int_mic;
  238. const char **spdif_labels;
  239. hda_nid_t dig_in_nid;
  240. hda_nid_t mono_nid;
  241. hda_nid_t anabeep_nid;
  242. hda_nid_t digbeep_nid;
  243. /* pin widgets */
  244. hda_nid_t *pin_nids;
  245. unsigned int num_pins;
  246. /* codec specific stuff */
  247. struct hda_verb *init;
  248. struct snd_kcontrol_new *mixer;
  249. /* capture source */
  250. struct hda_input_mux *dinput_mux;
  251. unsigned int cur_dmux[2];
  252. struct hda_input_mux *input_mux;
  253. unsigned int cur_mux[3];
  254. struct hda_input_mux *sinput_mux;
  255. unsigned int cur_smux[2];
  256. unsigned int cur_amux;
  257. hda_nid_t *amp_nids;
  258. unsigned int powerdown_adcs;
  259. /* i/o switches */
  260. unsigned int io_switch[2];
  261. unsigned int clfe_swap;
  262. hda_nid_t line_switch; /* shared line-in for input and output */
  263. hda_nid_t mic_switch; /* shared mic-in for input and output */
  264. hda_nid_t hp_switch; /* NID of HP as line-out */
  265. unsigned int aloopback;
  266. struct hda_pcm pcm_rec[2]; /* PCM information */
  267. /* dynamic controls and input_mux */
  268. struct auto_pin_cfg autocfg;
  269. struct snd_array kctls;
  270. struct hda_input_mux private_dimux;
  271. struct hda_input_mux private_imux;
  272. struct hda_input_mux private_smux;
  273. struct hda_input_mux private_mono_mux;
  274. };
  275. static hda_nid_t stac9200_adc_nids[1] = {
  276. 0x03,
  277. };
  278. static hda_nid_t stac9200_mux_nids[1] = {
  279. 0x0c,
  280. };
  281. static hda_nid_t stac9200_dac_nids[1] = {
  282. 0x02,
  283. };
  284. static hda_nid_t stac92hd73xx_pwr_nids[8] = {
  285. 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
  286. 0x0f, 0x10, 0x11
  287. };
  288. static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
  289. 0x26, 0,
  290. };
  291. static hda_nid_t stac92hd73xx_adc_nids[2] = {
  292. 0x1a, 0x1b
  293. };
  294. #define STAC92HD73XX_NUM_DMICS 2
  295. static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
  296. 0x13, 0x14, 0
  297. };
  298. #define STAC92HD73_DAC_COUNT 5
  299. static hda_nid_t stac92hd73xx_mux_nids[2] = {
  300. 0x20, 0x21,
  301. };
  302. static hda_nid_t stac92hd73xx_dmux_nids[2] = {
  303. 0x20, 0x21,
  304. };
  305. static hda_nid_t stac92hd73xx_smux_nids[2] = {
  306. 0x22, 0x23,
  307. };
  308. #define STAC92HD73XX_NUM_CAPS 2
  309. static unsigned long stac92hd73xx_capvols[] = {
  310. HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
  311. HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  312. };
  313. #define stac92hd73xx_capsws stac92hd73xx_capvols
  314. #define STAC92HD83_DAC_COUNT 3
  315. static hda_nid_t stac92hd83xxx_mux_nids[2] = {
  316. 0x17, 0x18,
  317. };
  318. static hda_nid_t stac92hd83xxx_adc_nids[2] = {
  319. 0x15, 0x16,
  320. };
  321. static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
  322. 0xa, 0xb, 0xd, 0xe,
  323. };
  324. static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
  325. 0x1e, 0,
  326. };
  327. static unsigned int stac92hd83xxx_pwr_mapping[4] = {
  328. 0x03, 0x0c, 0x20, 0x40,
  329. };
  330. #define STAC92HD83XXX_NUM_CAPS 2
  331. static unsigned long stac92hd83xxx_capvols[] = {
  332. HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
  333. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
  334. };
  335. #define stac92hd83xxx_capsws stac92hd83xxx_capvols
  336. static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
  337. 0x0a, 0x0d, 0x0f
  338. };
  339. static hda_nid_t stac92hd71bxx_adc_nids[2] = {
  340. 0x12, 0x13,
  341. };
  342. static hda_nid_t stac92hd71bxx_mux_nids[2] = {
  343. 0x1a, 0x1b
  344. };
  345. static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
  346. 0x1c, 0x1d,
  347. };
  348. static hda_nid_t stac92hd71bxx_smux_nids[2] = {
  349. 0x24, 0x25,
  350. };
  351. #define STAC92HD71BXX_NUM_DMICS 2
  352. static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
  353. 0x18, 0x19, 0
  354. };
  355. static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
  356. 0x22, 0
  357. };
  358. #define STAC92HD71BXX_NUM_CAPS 2
  359. static unsigned long stac92hd71bxx_capvols[] = {
  360. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
  361. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  362. };
  363. #define stac92hd71bxx_capsws stac92hd71bxx_capvols
  364. static hda_nid_t stac925x_adc_nids[1] = {
  365. 0x03,
  366. };
  367. static hda_nid_t stac925x_mux_nids[1] = {
  368. 0x0f,
  369. };
  370. static hda_nid_t stac925x_dac_nids[1] = {
  371. 0x02,
  372. };
  373. #define STAC925X_NUM_DMICS 1
  374. static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
  375. 0x15, 0
  376. };
  377. static hda_nid_t stac925x_dmux_nids[1] = {
  378. 0x14,
  379. };
  380. static unsigned long stac925x_capvols[] = {
  381. HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
  382. };
  383. static unsigned long stac925x_capsws[] = {
  384. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
  385. };
  386. static hda_nid_t stac922x_adc_nids[2] = {
  387. 0x06, 0x07,
  388. };
  389. static hda_nid_t stac922x_mux_nids[2] = {
  390. 0x12, 0x13,
  391. };
  392. #define STAC922X_NUM_CAPS 2
  393. static unsigned long stac922x_capvols[] = {
  394. HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
  395. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
  396. };
  397. #define stac922x_capsws stac922x_capvols
  398. static hda_nid_t stac927x_slave_dig_outs[2] = {
  399. 0x1f, 0,
  400. };
  401. static hda_nid_t stac927x_adc_nids[3] = {
  402. 0x07, 0x08, 0x09
  403. };
  404. static hda_nid_t stac927x_mux_nids[3] = {
  405. 0x15, 0x16, 0x17
  406. };
  407. static hda_nid_t stac927x_smux_nids[1] = {
  408. 0x21,
  409. };
  410. static hda_nid_t stac927x_dac_nids[6] = {
  411. 0x02, 0x03, 0x04, 0x05, 0x06, 0
  412. };
  413. static hda_nid_t stac927x_dmux_nids[1] = {
  414. 0x1b,
  415. };
  416. #define STAC927X_NUM_DMICS 2
  417. static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
  418. 0x13, 0x14, 0
  419. };
  420. #define STAC927X_NUM_CAPS 3
  421. static unsigned long stac927x_capvols[] = {
  422. HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
  423. HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
  424. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
  425. };
  426. static unsigned long stac927x_capsws[] = {
  427. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  428. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
  429. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  430. };
  431. static const char *stac927x_spdif_labels[5] = {
  432. "Digital Playback", "ADAT", "Analog Mux 1",
  433. "Analog Mux 2", "Analog Mux 3"
  434. };
  435. static hda_nid_t stac9205_adc_nids[2] = {
  436. 0x12, 0x13
  437. };
  438. static hda_nid_t stac9205_mux_nids[2] = {
  439. 0x19, 0x1a
  440. };
  441. static hda_nid_t stac9205_dmux_nids[1] = {
  442. 0x1d,
  443. };
  444. static hda_nid_t stac9205_smux_nids[1] = {
  445. 0x21,
  446. };
  447. #define STAC9205_NUM_DMICS 2
  448. static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
  449. 0x17, 0x18, 0
  450. };
  451. #define STAC9205_NUM_CAPS 2
  452. static unsigned long stac9205_capvols[] = {
  453. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
  454. HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
  455. };
  456. static unsigned long stac9205_capsws[] = {
  457. HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
  458. HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
  459. };
  460. static hda_nid_t stac9200_pin_nids[8] = {
  461. 0x08, 0x09, 0x0d, 0x0e,
  462. 0x0f, 0x10, 0x11, 0x12,
  463. };
  464. static hda_nid_t stac925x_pin_nids[8] = {
  465. 0x07, 0x08, 0x0a, 0x0b,
  466. 0x0c, 0x0d, 0x10, 0x11,
  467. };
  468. static hda_nid_t stac922x_pin_nids[10] = {
  469. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  470. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  471. };
  472. static hda_nid_t stac92hd73xx_pin_nids[13] = {
  473. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  474. 0x0f, 0x10, 0x11, 0x12, 0x13,
  475. 0x14, 0x22, 0x23
  476. };
  477. static hda_nid_t stac92hd83xxx_pin_nids[10] = {
  478. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  479. 0x0f, 0x10, 0x11, 0x1f, 0x20,
  480. };
  481. static hda_nid_t stac92hd88xxx_pin_nids[10] = {
  482. 0x0a, 0x0b, 0x0c, 0x0d,
  483. 0x0f, 0x11, 0x1f, 0x20,
  484. };
  485. #define STAC92HD71BXX_NUM_PINS 13
  486. static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
  487. 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
  488. 0x00, 0x14, 0x18, 0x19, 0x1e,
  489. 0x1f, 0x20, 0x27
  490. };
  491. static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
  492. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  493. 0x0f, 0x14, 0x18, 0x19, 0x1e,
  494. 0x1f, 0x20, 0x27
  495. };
  496. static hda_nid_t stac927x_pin_nids[14] = {
  497. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  498. 0x0f, 0x10, 0x11, 0x12, 0x13,
  499. 0x14, 0x21, 0x22, 0x23,
  500. };
  501. static hda_nid_t stac9205_pin_nids[12] = {
  502. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  503. 0x0f, 0x14, 0x16, 0x17, 0x18,
  504. 0x21, 0x22,
  505. };
  506. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_info *uinfo)
  508. {
  509. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  510. struct sigmatel_spec *spec = codec->spec;
  511. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  512. }
  513. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  514. struct snd_ctl_elem_value *ucontrol)
  515. {
  516. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  517. struct sigmatel_spec *spec = codec->spec;
  518. unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  519. ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
  520. return 0;
  521. }
  522. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  523. struct snd_ctl_elem_value *ucontrol)
  524. {
  525. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  526. struct sigmatel_spec *spec = codec->spec;
  527. unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  528. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  529. spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
  530. }
  531. static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
  532. struct snd_ctl_elem_info *uinfo)
  533. {
  534. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  535. struct sigmatel_spec *spec = codec->spec;
  536. return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
  537. }
  538. static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
  539. struct snd_ctl_elem_value *ucontrol)
  540. {
  541. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  542. struct sigmatel_spec *spec = codec->spec;
  543. unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  544. ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
  545. return 0;
  546. }
  547. static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
  548. struct snd_ctl_elem_value *ucontrol)
  549. {
  550. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  551. struct sigmatel_spec *spec = codec->spec;
  552. struct hda_input_mux *smux = &spec->private_smux;
  553. unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  554. int err, val;
  555. hda_nid_t nid;
  556. err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
  557. spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
  558. if (err < 0)
  559. return err;
  560. if (spec->spdif_mute) {
  561. if (smux_idx == 0)
  562. nid = spec->multiout.dig_out_nid;
  563. else
  564. nid = codec->slave_dig_outs[smux_idx - 1];
  565. if (spec->cur_smux[smux_idx] == smux->num_items - 1)
  566. val = HDA_AMP_MUTE;
  567. else
  568. val = 0;
  569. /* un/mute SPDIF out */
  570. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  571. HDA_AMP_MUTE, val);
  572. }
  573. return 0;
  574. }
  575. static unsigned int stac92xx_vref_set(struct hda_codec *codec,
  576. hda_nid_t nid, unsigned int new_vref)
  577. {
  578. int error;
  579. unsigned int pincfg;
  580. pincfg = snd_hda_codec_read(codec, nid, 0,
  581. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  582. pincfg &= 0xff;
  583. pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  584. pincfg |= new_vref;
  585. if (new_vref == AC_PINCTL_VREF_HIZ)
  586. pincfg |= AC_PINCTL_OUT_EN;
  587. else
  588. pincfg |= AC_PINCTL_IN_EN;
  589. error = snd_hda_codec_write_cache(codec, nid, 0,
  590. AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
  591. if (error < 0)
  592. return error;
  593. else
  594. return 1;
  595. }
  596. static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
  597. {
  598. unsigned int vref;
  599. vref = snd_hda_codec_read(codec, nid, 0,
  600. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  601. vref &= AC_PINCTL_VREFEN;
  602. return vref;
  603. }
  604. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  605. {
  606. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  607. struct sigmatel_spec *spec = codec->spec;
  608. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  609. }
  610. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  611. {
  612. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  613. struct sigmatel_spec *spec = codec->spec;
  614. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  615. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  616. return 0;
  617. }
  618. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  619. {
  620. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  621. struct sigmatel_spec *spec = codec->spec;
  622. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  623. const struct hda_input_mux *imux = spec->input_mux;
  624. unsigned int idx, prev_idx;
  625. idx = ucontrol->value.enumerated.item[0];
  626. if (idx >= imux->num_items)
  627. idx = imux->num_items - 1;
  628. prev_idx = spec->cur_mux[adc_idx];
  629. if (prev_idx == idx)
  630. return 0;
  631. if (idx < spec->num_analog_muxes) {
  632. snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
  633. AC_VERB_SET_CONNECT_SEL,
  634. imux->items[idx].index);
  635. if (prev_idx >= spec->num_analog_muxes) {
  636. imux = spec->dinput_mux;
  637. /* 0 = analog */
  638. snd_hda_codec_write_cache(codec,
  639. spec->dmux_nids[adc_idx], 0,
  640. AC_VERB_SET_CONNECT_SEL,
  641. imux->items[0].index);
  642. }
  643. } else {
  644. imux = spec->dinput_mux;
  645. snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
  646. AC_VERB_SET_CONNECT_SEL,
  647. imux->items[idx - 1].index);
  648. }
  649. spec->cur_mux[adc_idx] = idx;
  650. return 1;
  651. }
  652. static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
  653. struct snd_ctl_elem_info *uinfo)
  654. {
  655. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  656. struct sigmatel_spec *spec = codec->spec;
  657. return snd_hda_input_mux_info(spec->mono_mux, uinfo);
  658. }
  659. static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
  660. struct snd_ctl_elem_value *ucontrol)
  661. {
  662. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  663. struct sigmatel_spec *spec = codec->spec;
  664. ucontrol->value.enumerated.item[0] = spec->cur_mmux;
  665. return 0;
  666. }
  667. static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
  668. struct snd_ctl_elem_value *ucontrol)
  669. {
  670. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  671. struct sigmatel_spec *spec = codec->spec;
  672. return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
  673. spec->mono_nid, &spec->cur_mmux);
  674. }
  675. #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
  676. static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
  677. struct snd_ctl_elem_value *ucontrol)
  678. {
  679. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  680. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  681. struct sigmatel_spec *spec = codec->spec;
  682. ucontrol->value.integer.value[0] = !!(spec->aloopback &
  683. (spec->aloopback_mask << idx));
  684. return 0;
  685. }
  686. static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
  687. struct snd_ctl_elem_value *ucontrol)
  688. {
  689. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  690. struct sigmatel_spec *spec = codec->spec;
  691. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  692. unsigned int dac_mode;
  693. unsigned int val, idx_val;
  694. idx_val = spec->aloopback_mask << idx;
  695. if (ucontrol->value.integer.value[0])
  696. val = spec->aloopback | idx_val;
  697. else
  698. val = spec->aloopback & ~idx_val;
  699. if (spec->aloopback == val)
  700. return 0;
  701. spec->aloopback = val;
  702. /* Only return the bits defined by the shift value of the
  703. * first two bytes of the mask
  704. */
  705. dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
  706. kcontrol->private_value & 0xFFFF, 0x0);
  707. dac_mode >>= spec->aloopback_shift;
  708. if (spec->aloopback & idx_val) {
  709. snd_hda_power_up(codec);
  710. dac_mode |= idx_val;
  711. } else {
  712. snd_hda_power_down(codec);
  713. dac_mode &= ~idx_val;
  714. }
  715. snd_hda_codec_write_cache(codec, codec->afg, 0,
  716. kcontrol->private_value >> 16, dac_mode);
  717. return 1;
  718. }
  719. static struct hda_verb stac9200_core_init[] = {
  720. /* set dac0mux for dac converter */
  721. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  722. {}
  723. };
  724. static struct hda_verb stac9200_eapd_init[] = {
  725. /* set dac0mux for dac converter */
  726. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  727. {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  728. {}
  729. };
  730. static struct hda_verb dell_eq_core_init[] = {
  731. /* set master volume to max value without distortion
  732. * and direct control */
  733. { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
  734. {}
  735. };
  736. static struct hda_verb stac92hd73xx_core_init[] = {
  737. /* set master volume and direct control */
  738. { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  739. {}
  740. };
  741. static struct hda_verb stac92hd83xxx_core_init[] = {
  742. /* power state controls amps */
  743. { 0x01, AC_VERB_SET_EAPD, 1 << 2},
  744. {}
  745. };
  746. static struct hda_verb stac92hd71bxx_core_init[] = {
  747. /* set master volume and direct control */
  748. { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  749. {}
  750. };
  751. static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
  752. /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
  753. { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  754. { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  755. { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  756. {}
  757. };
  758. static struct hda_verb stac925x_core_init[] = {
  759. /* set dac0mux for dac converter */
  760. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  761. /* mute the master volume */
  762. { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  763. {}
  764. };
  765. static struct hda_verb stac922x_core_init[] = {
  766. /* set master volume and direct control */
  767. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  768. {}
  769. };
  770. static struct hda_verb d965_core_init[] = {
  771. /* set master volume and direct control */
  772. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  773. /* unmute node 0x1b */
  774. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  775. /* select node 0x03 as DAC */
  776. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  777. {}
  778. };
  779. static struct hda_verb dell_3st_core_init[] = {
  780. /* don't set delta bit */
  781. {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
  782. /* unmute node 0x1b */
  783. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  784. /* select node 0x03 as DAC */
  785. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  786. {}
  787. };
  788. static struct hda_verb stac927x_core_init[] = {
  789. /* set master volume and direct control */
  790. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  791. /* enable analog pc beep path */
  792. { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  793. {}
  794. };
  795. static struct hda_verb stac927x_volknob_core_init[] = {
  796. /* don't set delta bit */
  797. {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
  798. /* enable analog pc beep path */
  799. {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  800. {}
  801. };
  802. static struct hda_verb stac9205_core_init[] = {
  803. /* set master volume and direct control */
  804. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  805. /* enable analog pc beep path */
  806. { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
  807. {}
  808. };
  809. #define STAC_MONO_MUX \
  810. { \
  811. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  812. .name = "Mono Mux", \
  813. .count = 1, \
  814. .info = stac92xx_mono_mux_enum_info, \
  815. .get = stac92xx_mono_mux_enum_get, \
  816. .put = stac92xx_mono_mux_enum_put, \
  817. }
  818. #define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
  819. { \
  820. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  821. .name = "Analog Loopback", \
  822. .count = cnt, \
  823. .info = stac92xx_aloopback_info, \
  824. .get = stac92xx_aloopback_get, \
  825. .put = stac92xx_aloopback_put, \
  826. .private_value = verb_read | (verb_write << 16), \
  827. }
  828. #define DC_BIAS(xname, idx, nid) \
  829. { \
  830. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  831. .name = xname, \
  832. .index = idx, \
  833. .info = stac92xx_dc_bias_info, \
  834. .get = stac92xx_dc_bias_get, \
  835. .put = stac92xx_dc_bias_put, \
  836. .private_value = nid, \
  837. }
  838. static struct snd_kcontrol_new stac9200_mixer[] = {
  839. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  840. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  841. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  842. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  843. { } /* end */
  844. };
  845. static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
  846. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
  847. {}
  848. };
  849. static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
  850. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
  851. {}
  852. };
  853. static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
  854. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
  855. {}
  856. };
  857. static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
  858. STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
  859. };
  860. static struct snd_kcontrol_new stac925x_mixer[] = {
  861. HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
  862. HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
  863. { } /* end */
  864. };
  865. static struct snd_kcontrol_new stac9205_loopback[] = {
  866. STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
  867. {}
  868. };
  869. static struct snd_kcontrol_new stac927x_loopback[] = {
  870. STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
  871. {}
  872. };
  873. static struct snd_kcontrol_new stac_dmux_mixer = {
  874. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  875. .name = "Digital Input Source",
  876. /* count set later */
  877. .info = stac92xx_dmux_enum_info,
  878. .get = stac92xx_dmux_enum_get,
  879. .put = stac92xx_dmux_enum_put,
  880. };
  881. static struct snd_kcontrol_new stac_smux_mixer = {
  882. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  883. .name = "IEC958 Playback Source",
  884. /* count set later */
  885. .info = stac92xx_smux_enum_info,
  886. .get = stac92xx_smux_enum_get,
  887. .put = stac92xx_smux_enum_put,
  888. };
  889. static const char *slave_vols[] = {
  890. "Front Playback Volume",
  891. "Surround Playback Volume",
  892. "Center Playback Volume",
  893. "LFE Playback Volume",
  894. "Side Playback Volume",
  895. "Headphone Playback Volume",
  896. "Speaker Playback Volume",
  897. NULL
  898. };
  899. static const char *slave_sws[] = {
  900. "Front Playback Switch",
  901. "Surround Playback Switch",
  902. "Center Playback Switch",
  903. "LFE Playback Switch",
  904. "Side Playback Switch",
  905. "Headphone Playback Switch",
  906. "Speaker Playback Switch",
  907. "IEC958 Playback Switch",
  908. NULL
  909. };
  910. static void stac92xx_free_kctls(struct hda_codec *codec);
  911. static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
  912. static int stac92xx_build_controls(struct hda_codec *codec)
  913. {
  914. struct sigmatel_spec *spec = codec->spec;
  915. struct auto_pin_cfg *cfg = &spec->autocfg;
  916. hda_nid_t nid;
  917. int err;
  918. int i;
  919. if (spec->mixer) {
  920. err = snd_hda_add_new_ctls(codec, spec->mixer);
  921. if (err < 0)
  922. return err;
  923. }
  924. for (i = 0; i < spec->num_mixers; i++) {
  925. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  926. if (err < 0)
  927. return err;
  928. }
  929. if (!spec->auto_mic && spec->num_dmuxes > 0 &&
  930. snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
  931. stac_dmux_mixer.count = spec->num_dmuxes;
  932. err = snd_hda_ctl_add(codec, 0,
  933. snd_ctl_new1(&stac_dmux_mixer, codec));
  934. if (err < 0)
  935. return err;
  936. }
  937. if (spec->num_smuxes > 0) {
  938. int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
  939. struct hda_input_mux *smux = &spec->private_smux;
  940. /* check for mute support on SPDIF out */
  941. if (wcaps & AC_WCAP_OUT_AMP) {
  942. smux->items[smux->num_items].label = "Off";
  943. smux->items[smux->num_items].index = 0;
  944. smux->num_items++;
  945. spec->spdif_mute = 1;
  946. }
  947. stac_smux_mixer.count = spec->num_smuxes;
  948. err = snd_hda_ctl_add(codec, 0,
  949. snd_ctl_new1(&stac_smux_mixer, codec));
  950. if (err < 0)
  951. return err;
  952. }
  953. if (spec->multiout.dig_out_nid) {
  954. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  955. if (err < 0)
  956. return err;
  957. err = snd_hda_create_spdif_share_sw(codec,
  958. &spec->multiout);
  959. if (err < 0)
  960. return err;
  961. spec->multiout.share_spdif = 1;
  962. }
  963. if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
  964. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  965. if (err < 0)
  966. return err;
  967. }
  968. /* if we have no master control, let's create it */
  969. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  970. unsigned int vmaster_tlv[4];
  971. snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
  972. HDA_OUTPUT, vmaster_tlv);
  973. /* correct volume offset */
  974. vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
  975. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  976. vmaster_tlv, slave_vols);
  977. if (err < 0)
  978. return err;
  979. }
  980. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  981. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  982. NULL, slave_sws);
  983. if (err < 0)
  984. return err;
  985. }
  986. if (spec->aloopback_ctl &&
  987. snd_hda_get_bool_hint(codec, "loopback") == 1) {
  988. err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
  989. if (err < 0)
  990. return err;
  991. }
  992. stac92xx_free_kctls(codec); /* no longer needed */
  993. /* create jack input elements */
  994. if (spec->hp_detect) {
  995. for (i = 0; i < cfg->hp_outs; i++) {
  996. int type = SND_JACK_HEADPHONE;
  997. nid = cfg->hp_pins[i];
  998. /* jack detection */
  999. if (cfg->hp_outs == i)
  1000. type |= SND_JACK_LINEOUT;
  1001. err = stac92xx_add_jack(codec, nid, type);
  1002. if (err < 0)
  1003. return err;
  1004. }
  1005. }
  1006. for (i = 0; i < cfg->line_outs; i++) {
  1007. err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
  1008. SND_JACK_LINEOUT);
  1009. if (err < 0)
  1010. return err;
  1011. }
  1012. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1013. nid = cfg->input_pins[i];
  1014. if (nid) {
  1015. err = stac92xx_add_jack(codec, nid,
  1016. SND_JACK_MICROPHONE);
  1017. if (err < 0)
  1018. return err;
  1019. }
  1020. }
  1021. return 0;
  1022. }
  1023. static unsigned int ref9200_pin_configs[8] = {
  1024. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  1025. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  1026. };
  1027. static unsigned int gateway9200_m4_pin_configs[8] = {
  1028. 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
  1029. 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
  1030. };
  1031. static unsigned int gateway9200_m4_2_pin_configs[8] = {
  1032. 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
  1033. 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
  1034. };
  1035. /*
  1036. STAC 9200 pin configs for
  1037. 102801A8
  1038. 102801DE
  1039. 102801E8
  1040. */
  1041. static unsigned int dell9200_d21_pin_configs[8] = {
  1042. 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
  1043. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  1044. };
  1045. /*
  1046. STAC 9200 pin configs for
  1047. 102801C0
  1048. 102801C1
  1049. */
  1050. static unsigned int dell9200_d22_pin_configs[8] = {
  1051. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  1052. 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
  1053. };
  1054. /*
  1055. STAC 9200 pin configs for
  1056. 102801C4 (Dell Dimension E310)
  1057. 102801C5
  1058. 102801C7
  1059. 102801D9
  1060. 102801DA
  1061. 102801E3
  1062. */
  1063. static unsigned int dell9200_d23_pin_configs[8] = {
  1064. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  1065. 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
  1066. };
  1067. /*
  1068. STAC 9200-32 pin configs for
  1069. 102801B5 (Dell Inspiron 630m)
  1070. 102801D8 (Dell Inspiron 640m)
  1071. */
  1072. static unsigned int dell9200_m21_pin_configs[8] = {
  1073. 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
  1074. 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
  1075. };
  1076. /*
  1077. STAC 9200-32 pin configs for
  1078. 102801C2 (Dell Latitude D620)
  1079. 102801C8
  1080. 102801CC (Dell Latitude D820)
  1081. 102801D4
  1082. 102801D6
  1083. */
  1084. static unsigned int dell9200_m22_pin_configs[8] = {
  1085. 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
  1086. 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
  1087. };
  1088. /*
  1089. STAC 9200-32 pin configs for
  1090. 102801CE (Dell XPS M1710)
  1091. 102801CF (Dell Precision M90)
  1092. */
  1093. static unsigned int dell9200_m23_pin_configs[8] = {
  1094. 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
  1095. 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
  1096. };
  1097. /*
  1098. STAC 9200-32 pin configs for
  1099. 102801C9
  1100. 102801CA
  1101. 102801CB (Dell Latitude 120L)
  1102. 102801D3
  1103. */
  1104. static unsigned int dell9200_m24_pin_configs[8] = {
  1105. 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
  1106. 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
  1107. };
  1108. /*
  1109. STAC 9200-32 pin configs for
  1110. 102801BD (Dell Inspiron E1505n)
  1111. 102801EE
  1112. 102801EF
  1113. */
  1114. static unsigned int dell9200_m25_pin_configs[8] = {
  1115. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  1116. 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
  1117. };
  1118. /*
  1119. STAC 9200-32 pin configs for
  1120. 102801F5 (Dell Inspiron 1501)
  1121. 102801F6
  1122. */
  1123. static unsigned int dell9200_m26_pin_configs[8] = {
  1124. 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
  1125. 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
  1126. };
  1127. /*
  1128. STAC 9200-32
  1129. 102801CD (Dell Inspiron E1705/9400)
  1130. */
  1131. static unsigned int dell9200_m27_pin_configs[8] = {
  1132. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  1133. 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
  1134. };
  1135. static unsigned int oqo9200_pin_configs[8] = {
  1136. 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
  1137. 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
  1138. };
  1139. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  1140. [STAC_REF] = ref9200_pin_configs,
  1141. [STAC_9200_OQO] = oqo9200_pin_configs,
  1142. [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
  1143. [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
  1144. [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
  1145. [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
  1146. [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
  1147. [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
  1148. [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
  1149. [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
  1150. [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
  1151. [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
  1152. [STAC_9200_M4] = gateway9200_m4_pin_configs,
  1153. [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
  1154. [STAC_9200_PANASONIC] = ref9200_pin_configs,
  1155. };
  1156. static const char *stac9200_models[STAC_9200_MODELS] = {
  1157. [STAC_AUTO] = "auto",
  1158. [STAC_REF] = "ref",
  1159. [STAC_9200_OQO] = "oqo",
  1160. [STAC_9200_DELL_D21] = "dell-d21",
  1161. [STAC_9200_DELL_D22] = "dell-d22",
  1162. [STAC_9200_DELL_D23] = "dell-d23",
  1163. [STAC_9200_DELL_M21] = "dell-m21",
  1164. [STAC_9200_DELL_M22] = "dell-m22",
  1165. [STAC_9200_DELL_M23] = "dell-m23",
  1166. [STAC_9200_DELL_M24] = "dell-m24",
  1167. [STAC_9200_DELL_M25] = "dell-m25",
  1168. [STAC_9200_DELL_M26] = "dell-m26",
  1169. [STAC_9200_DELL_M27] = "dell-m27",
  1170. [STAC_9200_M4] = "gateway-m4",
  1171. [STAC_9200_M4_2] = "gateway-m4-2",
  1172. [STAC_9200_PANASONIC] = "panasonic",
  1173. };
  1174. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  1175. /* SigmaTel reference board */
  1176. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1177. "DFI LanParty", STAC_REF),
  1178. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1179. "DFI LanParty", STAC_REF),
  1180. /* Dell laptops have BIOS problem */
  1181. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
  1182. "unknown Dell", STAC_9200_DELL_D21),
  1183. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  1184. "Dell Inspiron 630m", STAC_9200_DELL_M21),
  1185. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
  1186. "Dell Inspiron E1505n", STAC_9200_DELL_M25),
  1187. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
  1188. "unknown Dell", STAC_9200_DELL_D22),
  1189. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
  1190. "unknown Dell", STAC_9200_DELL_D22),
  1191. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  1192. "Dell Latitude D620", STAC_9200_DELL_M22),
  1193. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
  1194. "unknown Dell", STAC_9200_DELL_D23),
  1195. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
  1196. "unknown Dell", STAC_9200_DELL_D23),
  1197. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
  1198. "unknown Dell", STAC_9200_DELL_M22),
  1199. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
  1200. "unknown Dell", STAC_9200_DELL_M24),
  1201. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
  1202. "unknown Dell", STAC_9200_DELL_M24),
  1203. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  1204. "Dell Latitude 120L", STAC_9200_DELL_M24),
  1205. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  1206. "Dell Latitude D820", STAC_9200_DELL_M22),
  1207. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  1208. "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
  1209. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  1210. "Dell XPS M1710", STAC_9200_DELL_M23),
  1211. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  1212. "Dell Precision M90", STAC_9200_DELL_M23),
  1213. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
  1214. "unknown Dell", STAC_9200_DELL_M22),
  1215. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
  1216. "unknown Dell", STAC_9200_DELL_M22),
  1217. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  1218. "unknown Dell", STAC_9200_DELL_M22),
  1219. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  1220. "Dell Inspiron 640m", STAC_9200_DELL_M21),
  1221. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
  1222. "unknown Dell", STAC_9200_DELL_D23),
  1223. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
  1224. "unknown Dell", STAC_9200_DELL_D23),
  1225. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
  1226. "unknown Dell", STAC_9200_DELL_D21),
  1227. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
  1228. "unknown Dell", STAC_9200_DELL_D23),
  1229. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
  1230. "unknown Dell", STAC_9200_DELL_D21),
  1231. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
  1232. "unknown Dell", STAC_9200_DELL_M25),
  1233. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
  1234. "unknown Dell", STAC_9200_DELL_M25),
  1235. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  1236. "Dell Inspiron 1501", STAC_9200_DELL_M26),
  1237. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
  1238. "unknown Dell", STAC_9200_DELL_M26),
  1239. /* Panasonic */
  1240. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
  1241. /* Gateway machines needs EAPD to be set on resume */
  1242. SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
  1243. SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
  1244. SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
  1245. /* OQO Mobile */
  1246. SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
  1247. {} /* terminator */
  1248. };
  1249. static unsigned int ref925x_pin_configs[8] = {
  1250. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  1251. 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
  1252. };
  1253. static unsigned int stac925xM1_pin_configs[8] = {
  1254. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1255. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1256. };
  1257. static unsigned int stac925xM1_2_pin_configs[8] = {
  1258. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1259. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1260. };
  1261. static unsigned int stac925xM2_pin_configs[8] = {
  1262. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1263. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1264. };
  1265. static unsigned int stac925xM2_2_pin_configs[8] = {
  1266. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1267. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1268. };
  1269. static unsigned int stac925xM3_pin_configs[8] = {
  1270. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1271. 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
  1272. };
  1273. static unsigned int stac925xM5_pin_configs[8] = {
  1274. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1275. 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
  1276. };
  1277. static unsigned int stac925xM6_pin_configs[8] = {
  1278. 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
  1279. 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
  1280. };
  1281. static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  1282. [STAC_REF] = ref925x_pin_configs,
  1283. [STAC_M1] = stac925xM1_pin_configs,
  1284. [STAC_M1_2] = stac925xM1_2_pin_configs,
  1285. [STAC_M2] = stac925xM2_pin_configs,
  1286. [STAC_M2_2] = stac925xM2_2_pin_configs,
  1287. [STAC_M3] = stac925xM3_pin_configs,
  1288. [STAC_M5] = stac925xM5_pin_configs,
  1289. [STAC_M6] = stac925xM6_pin_configs,
  1290. };
  1291. static const char *stac925x_models[STAC_925x_MODELS] = {
  1292. [STAC_925x_AUTO] = "auto",
  1293. [STAC_REF] = "ref",
  1294. [STAC_M1] = "m1",
  1295. [STAC_M1_2] = "m1-2",
  1296. [STAC_M2] = "m2",
  1297. [STAC_M2_2] = "m2-2",
  1298. [STAC_M3] = "m3",
  1299. [STAC_M5] = "m5",
  1300. [STAC_M6] = "m6",
  1301. };
  1302. static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
  1303. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
  1304. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
  1305. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
  1306. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
  1307. SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
  1308. /* Not sure about the brand name for those */
  1309. SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
  1310. SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
  1311. SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
  1312. SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
  1313. {} /* terminator */
  1314. };
  1315. static struct snd_pci_quirk stac925x_cfg_tbl[] = {
  1316. /* SigmaTel reference board */
  1317. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  1318. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
  1319. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  1320. /* Default table for unknown ID */
  1321. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
  1322. {} /* terminator */
  1323. };
  1324. static unsigned int ref92hd73xx_pin_configs[13] = {
  1325. 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
  1326. 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
  1327. 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
  1328. 0x01452050,
  1329. };
  1330. static unsigned int dell_m6_pin_configs[13] = {
  1331. 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
  1332. 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
  1333. 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
  1334. 0x4f0000f0,
  1335. };
  1336. static unsigned int alienware_m17x_pin_configs[13] = {
  1337. 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
  1338. 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
  1339. 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
  1340. 0x904601b0,
  1341. };
  1342. static unsigned int intel_dg45id_pin_configs[13] = {
  1343. 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
  1344. 0x01A19250, 0x01011212, 0x01016211
  1345. };
  1346. static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
  1347. [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
  1348. [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
  1349. [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
  1350. [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
  1351. [STAC_DELL_EQ] = dell_m6_pin_configs,
  1352. [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
  1353. [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
  1354. };
  1355. static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
  1356. [STAC_92HD73XX_AUTO] = "auto",
  1357. [STAC_92HD73XX_NO_JD] = "no-jd",
  1358. [STAC_92HD73XX_REF] = "ref",
  1359. [STAC_92HD73XX_INTEL] = "intel",
  1360. [STAC_DELL_M6_AMIC] = "dell-m6-amic",
  1361. [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
  1362. [STAC_DELL_M6_BOTH] = "dell-m6",
  1363. [STAC_DELL_EQ] = "dell-eq",
  1364. [STAC_ALIENWARE_M17X] = "alienware",
  1365. };
  1366. static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
  1367. /* SigmaTel reference board */
  1368. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1369. "DFI LanParty", STAC_92HD73XX_REF),
  1370. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1371. "DFI LanParty", STAC_92HD73XX_REF),
  1372. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
  1373. "Intel DG45ID", STAC_92HD73XX_INTEL),
  1374. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
  1375. "Intel DG45FC", STAC_92HD73XX_INTEL),
  1376. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
  1377. "Dell Studio 1535", STAC_DELL_M6_DMIC),
  1378. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
  1379. "unknown Dell", STAC_DELL_M6_DMIC),
  1380. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
  1381. "unknown Dell", STAC_DELL_M6_BOTH),
  1382. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
  1383. "unknown Dell", STAC_DELL_M6_BOTH),
  1384. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
  1385. "unknown Dell", STAC_DELL_M6_AMIC),
  1386. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
  1387. "unknown Dell", STAC_DELL_M6_AMIC),
  1388. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
  1389. "unknown Dell", STAC_DELL_M6_DMIC),
  1390. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
  1391. "unknown Dell", STAC_DELL_M6_DMIC),
  1392. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
  1393. "Dell Studio 1537", STAC_DELL_M6_DMIC),
  1394. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
  1395. "Dell Studio 17", STAC_DELL_M6_DMIC),
  1396. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
  1397. "Dell Studio 1555", STAC_DELL_M6_DMIC),
  1398. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
  1399. "Dell Studio 1557", STAC_DELL_M6_DMIC),
  1400. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
  1401. "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
  1402. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
  1403. "Dell Studio 1558", STAC_DELL_M6_DMIC),
  1404. {} /* terminator */
  1405. };
  1406. static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
  1407. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
  1408. "Alienware M17x", STAC_ALIENWARE_M17X),
  1409. {} /* terminator */
  1410. };
  1411. static unsigned int ref92hd83xxx_pin_configs[10] = {
  1412. 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
  1413. 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
  1414. 0x01451160, 0x98560170,
  1415. };
  1416. static unsigned int dell_s14_pin_configs[10] = {
  1417. 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
  1418. 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
  1419. 0x40f000f0, 0x40f000f0,
  1420. };
  1421. static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
  1422. [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
  1423. [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
  1424. [STAC_DELL_S14] = dell_s14_pin_configs,
  1425. };
  1426. static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
  1427. [STAC_92HD83XXX_AUTO] = "auto",
  1428. [STAC_92HD83XXX_REF] = "ref",
  1429. [STAC_92HD83XXX_PWR_REF] = "mic-ref",
  1430. [STAC_DELL_S14] = "dell-s14",
  1431. [STAC_92HD83XXX_HP] = "hp",
  1432. };
  1433. static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
  1434. /* SigmaTel reference board */
  1435. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1436. "DFI LanParty", STAC_92HD83XXX_REF),
  1437. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1438. "DFI LanParty", STAC_92HD83XXX_REF),
  1439. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
  1440. "unknown Dell", STAC_DELL_S14),
  1441. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
  1442. "HP", STAC_92HD83XXX_HP),
  1443. {} /* terminator */
  1444. };
  1445. static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1446. 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
  1447. 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
  1448. 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
  1449. 0x00000000
  1450. };
  1451. static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1452. 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
  1453. 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
  1454. 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
  1455. 0x00000000
  1456. };
  1457. static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1458. 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
  1459. 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
  1460. 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
  1461. 0x00000000
  1462. };
  1463. static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
  1464. 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
  1465. 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
  1466. 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
  1467. 0x00000000
  1468. };
  1469. static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
  1470. [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
  1471. [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
  1472. [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
  1473. [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
  1474. [STAC_HP_M4] = NULL,
  1475. [STAC_HP_DV4] = NULL,
  1476. [STAC_HP_DV5] = NULL,
  1477. [STAC_HP_HDX] = NULL,
  1478. [STAC_HP_DV4_1222NR] = NULL,
  1479. };
  1480. static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
  1481. [STAC_92HD71BXX_AUTO] = "auto",
  1482. [STAC_92HD71BXX_REF] = "ref",
  1483. [STAC_DELL_M4_1] = "dell-m4-1",
  1484. [STAC_DELL_M4_2] = "dell-m4-2",
  1485. [STAC_DELL_M4_3] = "dell-m4-3",
  1486. [STAC_HP_M4] = "hp-m4",
  1487. [STAC_HP_DV4] = "hp-dv4",
  1488. [STAC_HP_DV5] = "hp-dv5",
  1489. [STAC_HP_HDX] = "hp-hdx",
  1490. [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
  1491. };
  1492. static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
  1493. /* SigmaTel reference board */
  1494. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1495. "DFI LanParty", STAC_92HD71BXX_REF),
  1496. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1497. "DFI LanParty", STAC_92HD71BXX_REF),
  1498. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
  1499. "HP dv4-1222nr", STAC_HP_DV4_1222NR),
  1500. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
  1501. "HP", STAC_HP_DV5),
  1502. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
  1503. "HP", STAC_HP_DV5),
  1504. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
  1505. "HP dv4-7", STAC_HP_DV4),
  1506. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
  1507. "HP dv4-7", STAC_HP_DV5),
  1508. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
  1509. "HP HDX", STAC_HP_HDX), /* HDX18 */
  1510. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
  1511. "HP mini 1000", STAC_HP_M4),
  1512. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
  1513. "HP HDX", STAC_HP_HDX), /* HDX16 */
  1514. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
  1515. "HP dv6", STAC_HP_DV5),
  1516. SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
  1517. "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
  1518. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
  1519. "HP", STAC_HP_DV5),
  1520. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
  1521. "unknown Dell", STAC_DELL_M4_1),
  1522. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
  1523. "unknown Dell", STAC_DELL_M4_1),
  1524. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
  1525. "unknown Dell", STAC_DELL_M4_1),
  1526. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
  1527. "unknown Dell", STAC_DELL_M4_1),
  1528. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
  1529. "unknown Dell", STAC_DELL_M4_1),
  1530. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
  1531. "unknown Dell", STAC_DELL_M4_1),
  1532. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
  1533. "unknown Dell", STAC_DELL_M4_1),
  1534. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
  1535. "unknown Dell", STAC_DELL_M4_2),
  1536. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
  1537. "unknown Dell", STAC_DELL_M4_2),
  1538. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
  1539. "unknown Dell", STAC_DELL_M4_2),
  1540. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
  1541. "unknown Dell", STAC_DELL_M4_2),
  1542. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
  1543. "unknown Dell", STAC_DELL_M4_3),
  1544. {} /* terminator */
  1545. };
  1546. static unsigned int ref922x_pin_configs[10] = {
  1547. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  1548. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  1549. 0x40000100, 0x40000100,
  1550. };
  1551. /*
  1552. STAC 922X pin configs for
  1553. 102801A7
  1554. 102801AB
  1555. 102801A9
  1556. 102801D1
  1557. 102801D2
  1558. */
  1559. static unsigned int dell_922x_d81_pin_configs[10] = {
  1560. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  1561. 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
  1562. 0x01813122, 0x400001f2,
  1563. };
  1564. /*
  1565. STAC 922X pin configs for
  1566. 102801AC
  1567. 102801D0
  1568. */
  1569. static unsigned int dell_922x_d82_pin_configs[10] = {
  1570. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  1571. 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
  1572. 0x01813122, 0x400001f1,
  1573. };
  1574. /*
  1575. STAC 922X pin configs for
  1576. 102801BF
  1577. */
  1578. static unsigned int dell_922x_m81_pin_configs[10] = {
  1579. 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
  1580. 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
  1581. 0x40C003f1, 0x405003f0,
  1582. };
  1583. /*
  1584. STAC 9221 A1 pin configs for
  1585. 102801D7 (Dell XPS M1210)
  1586. */
  1587. static unsigned int dell_922x_m82_pin_configs[10] = {
  1588. 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
  1589. 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
  1590. 0x508003f3, 0x405003f4,
  1591. };
  1592. static unsigned int d945gtp3_pin_configs[10] = {
  1593. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  1594. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  1595. 0x02a19120, 0x40000100,
  1596. };
  1597. static unsigned int d945gtp5_pin_configs[10] = {
  1598. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  1599. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  1600. 0x02a19320, 0x40000100,
  1601. };
  1602. static unsigned int intel_mac_v1_pin_configs[10] = {
  1603. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  1604. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  1605. 0x400000fc, 0x400000fb,
  1606. };
  1607. static unsigned int intel_mac_v2_pin_configs[10] = {
  1608. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  1609. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  1610. 0x400000fc, 0x400000fb,
  1611. };
  1612. static unsigned int intel_mac_v3_pin_configs[10] = {
  1613. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  1614. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  1615. 0x400000fc, 0x400000fb,
  1616. };
  1617. static unsigned int intel_mac_v4_pin_configs[10] = {
  1618. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  1619. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  1620. 0x400000fc, 0x400000fb,
  1621. };
  1622. static unsigned int intel_mac_v5_pin_configs[10] = {
  1623. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  1624. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  1625. 0x400000fc, 0x400000fb,
  1626. };
  1627. static unsigned int ecs202_pin_configs[10] = {
  1628. 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
  1629. 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
  1630. 0x9037012e, 0x40e000f2,
  1631. };
  1632. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  1633. [STAC_D945_REF] = ref922x_pin_configs,
  1634. [STAC_D945GTP3] = d945gtp3_pin_configs,
  1635. [STAC_D945GTP5] = d945gtp5_pin_configs,
  1636. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  1637. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  1638. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  1639. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  1640. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  1641. [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
  1642. /* for backward compatibility */
  1643. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  1644. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  1645. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  1646. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  1647. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  1648. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  1649. [STAC_ECS_202] = ecs202_pin_configs,
  1650. [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
  1651. [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
  1652. [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
  1653. [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
  1654. };
  1655. static const char *stac922x_models[STAC_922X_MODELS] = {
  1656. [STAC_922X_AUTO] = "auto",
  1657. [STAC_D945_REF] = "ref",
  1658. [STAC_D945GTP5] = "5stack",
  1659. [STAC_D945GTP3] = "3stack",
  1660. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  1661. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  1662. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  1663. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  1664. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  1665. [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
  1666. /* for backward compatibility */
  1667. [STAC_MACMINI] = "macmini",
  1668. [STAC_MACBOOK] = "macbook",
  1669. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  1670. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  1671. [STAC_IMAC_INTEL] = "imac-intel",
  1672. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  1673. [STAC_ECS_202] = "ecs202",
  1674. [STAC_922X_DELL_D81] = "dell-d81",
  1675. [STAC_922X_DELL_D82] = "dell-d82",
  1676. [STAC_922X_DELL_M81] = "dell-m81",
  1677. [STAC_922X_DELL_M82] = "dell-m82",
  1678. };
  1679. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  1680. /* SigmaTel reference board */
  1681. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1682. "DFI LanParty", STAC_D945_REF),
  1683. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1684. "DFI LanParty", STAC_D945_REF),
  1685. /* Intel 945G based systems */
  1686. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  1687. "Intel D945G", STAC_D945GTP3),
  1688. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  1689. "Intel D945G", STAC_D945GTP3),
  1690. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  1691. "Intel D945G", STAC_D945GTP3),
  1692. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  1693. "Intel D945G", STAC_D945GTP3),
  1694. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  1695. "Intel D945G", STAC_D945GTP3),
  1696. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  1697. "Intel D945G", STAC_D945GTP3),
  1698. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  1699. "Intel D945G", STAC_D945GTP3),
  1700. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  1701. "Intel D945G", STAC_D945GTP3),
  1702. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  1703. "Intel D945G", STAC_D945GTP3),
  1704. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  1705. "Intel D945G", STAC_D945GTP3),
  1706. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  1707. "Intel D945G", STAC_D945GTP3),
  1708. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  1709. "Intel D945G", STAC_D945GTP3),
  1710. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  1711. "Intel D945G", STAC_D945GTP3),
  1712. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  1713. "Intel D945G", STAC_D945GTP3),
  1714. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  1715. "Intel D945G", STAC_D945GTP3),
  1716. /* Intel D945G 5-stack systems */
  1717. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  1718. "Intel D945G", STAC_D945GTP5),
  1719. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  1720. "Intel D945G", STAC_D945GTP5),
  1721. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  1722. "Intel D945G", STAC_D945GTP5),
  1723. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  1724. "Intel D945G", STAC_D945GTP5),
  1725. /* Intel 945P based systems */
  1726. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  1727. "Intel D945P", STAC_D945GTP3),
  1728. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  1729. "Intel D945P", STAC_D945GTP3),
  1730. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  1731. "Intel D945P", STAC_D945GTP3),
  1732. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  1733. "Intel D945P", STAC_D945GTP3),
  1734. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  1735. "Intel D945P", STAC_D945GTP3),
  1736. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  1737. "Intel D945P", STAC_D945GTP5),
  1738. /* other intel */
  1739. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
  1740. "Intel D945", STAC_D945_REF),
  1741. /* other systems */
  1742. /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
  1743. SND_PCI_QUIRK(0x8384, 0x7680,
  1744. "Mac", STAC_INTEL_MAC_AUTO),
  1745. /* Dell systems */
  1746. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
  1747. "unknown Dell", STAC_922X_DELL_D81),
  1748. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
  1749. "unknown Dell", STAC_922X_DELL_D81),
  1750. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
  1751. "unknown Dell", STAC_922X_DELL_D81),
  1752. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
  1753. "unknown Dell", STAC_922X_DELL_D82),
  1754. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
  1755. "unknown Dell", STAC_922X_DELL_M81),
  1756. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
  1757. "unknown Dell", STAC_922X_DELL_D82),
  1758. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
  1759. "unknown Dell", STAC_922X_DELL_D81),
  1760. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
  1761. "unknown Dell", STAC_922X_DELL_D81),
  1762. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
  1763. "Dell XPS M1210", STAC_922X_DELL_M82),
  1764. /* ECS/PC Chips boards */
  1765. SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
  1766. "ECS/PC chips", STAC_ECS_202),
  1767. {} /* terminator */
  1768. };
  1769. static unsigned int ref927x_pin_configs[14] = {
  1770. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  1771. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  1772. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  1773. 0x01c42190, 0x40000100,
  1774. };
  1775. static unsigned int d965_3st_pin_configs[14] = {
  1776. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  1777. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  1778. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  1779. 0x40000100, 0x40000100
  1780. };
  1781. static unsigned int d965_5st_pin_configs[14] = {
  1782. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  1783. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  1784. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  1785. 0x40000100, 0x40000100
  1786. };
  1787. static unsigned int d965_5st_no_fp_pin_configs[14] = {
  1788. 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
  1789. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  1790. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  1791. 0x40000100, 0x40000100
  1792. };
  1793. static unsigned int dell_3st_pin_configs[14] = {
  1794. 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
  1795. 0x01111212, 0x01116211, 0x01813050, 0x01112214,
  1796. 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
  1797. 0x40c003fc, 0x40000100
  1798. };
  1799. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  1800. [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
  1801. [STAC_D965_REF] = ref927x_pin_configs,
  1802. [STAC_D965_3ST] = d965_3st_pin_configs,
  1803. [STAC_D965_5ST] = d965_5st_pin_configs,
  1804. [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
  1805. [STAC_DELL_3ST] = dell_3st_pin_configs,
  1806. [STAC_DELL_BIOS] = NULL,
  1807. [STAC_927X_VOLKNOB] = NULL,
  1808. };
  1809. static const char *stac927x_models[STAC_927X_MODELS] = {
  1810. [STAC_927X_AUTO] = "auto",
  1811. [STAC_D965_REF_NO_JD] = "ref-no-jd",
  1812. [STAC_D965_REF] = "ref",
  1813. [STAC_D965_3ST] = "3stack",
  1814. [STAC_D965_5ST] = "5stack",
  1815. [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
  1816. [STAC_DELL_3ST] = "dell-3stack",
  1817. [STAC_DELL_BIOS] = "dell-bios",
  1818. [STAC_927X_VOLKNOB] = "volknob",
  1819. };
  1820. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  1821. /* SigmaTel reference board */
  1822. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1823. "DFI LanParty", STAC_D965_REF),
  1824. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1825. "DFI LanParty", STAC_D965_REF),
  1826. /* Intel 946 based systems */
  1827. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  1828. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  1829. /* 965 based 3 stack systems */
  1830. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
  1831. "Intel D965", STAC_D965_3ST),
  1832. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
  1833. "Intel D965", STAC_D965_3ST),
  1834. /* Dell 3 stack systems */
  1835. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
  1836. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
  1837. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
  1838. /* Dell 3 stack systems with verb table in BIOS */
  1839. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
  1840. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
  1841. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
  1842. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
  1843. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
  1844. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
  1845. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
  1846. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
  1847. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
  1848. /* 965 based 5 stack systems */
  1849. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
  1850. "Intel D965", STAC_D965_5ST),
  1851. SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
  1852. "Intel D965", STAC_D965_5ST),
  1853. /* volume-knob fixes */
  1854. SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
  1855. {} /* terminator */
  1856. };
  1857. static unsigned int ref9205_pin_configs[12] = {
  1858. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  1859. 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
  1860. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  1861. };
  1862. /*
  1863. STAC 9205 pin configs for
  1864. 102801F1
  1865. 102801F2
  1866. 102801FC
  1867. 102801FD
  1868. 10280204
  1869. 1028021F
  1870. 10280228 (Dell Vostro 1500)
  1871. 10280229 (Dell Vostro 1700)
  1872. */
  1873. static unsigned int dell_9205_m42_pin_configs[12] = {
  1874. 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
  1875. 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
  1876. 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
  1877. };
  1878. /*
  1879. STAC 9205 pin configs for
  1880. 102801F9
  1881. 102801FA
  1882. 102801FE
  1883. 102801FF (Dell Precision M4300)
  1884. 10280206
  1885. 10280200
  1886. 10280201
  1887. */
  1888. static unsigned int dell_9205_m43_pin_configs[12] = {
  1889. 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
  1890. 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
  1891. 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
  1892. };
  1893. static unsigned int dell_9205_m44_pin_configs[12] = {
  1894. 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
  1895. 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
  1896. 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
  1897. };
  1898. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  1899. [STAC_9205_REF] = ref9205_pin_configs,
  1900. [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
  1901. [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
  1902. [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
  1903. [STAC_9205_EAPD] = NULL,
  1904. };
  1905. static const char *stac9205_models[STAC_9205_MODELS] = {
  1906. [STAC_9205_AUTO] = "auto",
  1907. [STAC_9205_REF] = "ref",
  1908. [STAC_9205_DELL_M42] = "dell-m42",
  1909. [STAC_9205_DELL_M43] = "dell-m43",
  1910. [STAC_9205_DELL_M44] = "dell-m44",
  1911. [STAC_9205_EAPD] = "eapd",
  1912. };
  1913. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  1914. /* SigmaTel reference board */
  1915. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1916. "DFI LanParty", STAC_9205_REF),
  1917. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
  1918. "SigmaTel", STAC_9205_REF),
  1919. SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
  1920. "DFI LanParty", STAC_9205_REF),
  1921. /* Dell */
  1922. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1923. "unknown Dell", STAC_9205_DELL_M42),
  1924. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1925. "unknown Dell", STAC_9205_DELL_M42),
  1926. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
  1927. "Dell Precision", STAC_9205_DELL_M43),
  1928. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
  1929. "Dell Precision", STAC_9205_DELL_M43),
  1930. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
  1931. "Dell Precision", STAC_9205_DELL_M43),
  1932. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1933. "unknown Dell", STAC_9205_DELL_M42),
  1934. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1935. "unknown Dell", STAC_9205_DELL_M42),
  1936. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
  1937. "Dell Precision", STAC_9205_DELL_M43),
  1938. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
  1939. "Dell Precision M4300", STAC_9205_DELL_M43),
  1940. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
  1941. "unknown Dell", STAC_9205_DELL_M42),
  1942. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
  1943. "Dell Precision", STAC_9205_DELL_M43),
  1944. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
  1945. "Dell Precision", STAC_9205_DELL_M43),
  1946. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
  1947. "Dell Precision", STAC_9205_DELL_M43),
  1948. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
  1949. "Dell Inspiron", STAC_9205_DELL_M44),
  1950. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
  1951. "Dell Vostro 1500", STAC_9205_DELL_M42),
  1952. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
  1953. "Dell Vostro 1700", STAC_9205_DELL_M42),
  1954. /* Gateway */
  1955. SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
  1956. SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
  1957. {} /* terminator */
  1958. };
  1959. static void stac92xx_set_config_regs(struct hda_codec *codec,
  1960. unsigned int *pincfgs)
  1961. {
  1962. int i;
  1963. struct sigmatel_spec *spec = codec->spec;
  1964. if (!pincfgs)
  1965. return;
  1966. for (i = 0; i < spec->num_pins; i++)
  1967. if (spec->pin_nids[i] && pincfgs[i])
  1968. snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
  1969. pincfgs[i]);
  1970. }
  1971. /*
  1972. * Analog playback callbacks
  1973. */
  1974. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1975. struct hda_codec *codec,
  1976. struct snd_pcm_substream *substream)
  1977. {
  1978. struct sigmatel_spec *spec = codec->spec;
  1979. if (spec->stream_delay)
  1980. msleep(spec->stream_delay);
  1981. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1982. hinfo);
  1983. }
  1984. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1985. struct hda_codec *codec,
  1986. unsigned int stream_tag,
  1987. unsigned int format,
  1988. struct snd_pcm_substream *substream)
  1989. {
  1990. struct sigmatel_spec *spec = codec->spec;
  1991. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  1992. }
  1993. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1994. struct hda_codec *codec,
  1995. struct snd_pcm_substream *substream)
  1996. {
  1997. struct sigmatel_spec *spec = codec->spec;
  1998. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1999. }
  2000. /*
  2001. * Digital playback callbacks
  2002. */
  2003. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  2004. struct hda_codec *codec,
  2005. struct snd_pcm_substream *substream)
  2006. {
  2007. struct sigmatel_spec *spec = codec->spec;
  2008. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  2009. }
  2010. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  2011. struct hda_codec *codec,
  2012. struct snd_pcm_substream *substream)
  2013. {
  2014. struct sigmatel_spec *spec = codec->spec;
  2015. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  2016. }
  2017. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  2018. struct hda_codec *codec,
  2019. unsigned int stream_tag,
  2020. unsigned int format,
  2021. struct snd_pcm_substream *substream)
  2022. {
  2023. struct sigmatel_spec *spec = codec->spec;
  2024. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  2025. stream_tag, format, substream);
  2026. }
  2027. static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2028. struct hda_codec *codec,
  2029. struct snd_pcm_substream *substream)
  2030. {
  2031. struct sigmatel_spec *spec = codec->spec;
  2032. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  2033. }
  2034. /*
  2035. * Analog capture callbacks
  2036. */
  2037. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2038. struct hda_codec *codec,
  2039. unsigned int stream_tag,
  2040. unsigned int format,
  2041. struct snd_pcm_substream *substream)
  2042. {
  2043. struct sigmatel_spec *spec = codec->spec;
  2044. hda_nid_t nid = spec->adc_nids[substream->number];
  2045. if (spec->powerdown_adcs) {
  2046. msleep(40);
  2047. snd_hda_codec_write(codec, nid, 0,
  2048. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  2049. }
  2050. snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
  2051. return 0;
  2052. }
  2053. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2054. struct hda_codec *codec,
  2055. struct snd_pcm_substream *substream)
  2056. {
  2057. struct sigmatel_spec *spec = codec->spec;
  2058. hda_nid_t nid = spec->adc_nids[substream->number];
  2059. snd_hda_codec_cleanup_stream(codec, nid);
  2060. if (spec->powerdown_adcs)
  2061. snd_hda_codec_write(codec, nid, 0,
  2062. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  2063. return 0;
  2064. }
  2065. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  2066. .substreams = 1,
  2067. .channels_min = 2,
  2068. .channels_max = 2,
  2069. /* NID is set in stac92xx_build_pcms */
  2070. .ops = {
  2071. .open = stac92xx_dig_playback_pcm_open,
  2072. .close = stac92xx_dig_playback_pcm_close,
  2073. .prepare = stac92xx_dig_playback_pcm_prepare,
  2074. .cleanup = stac92xx_dig_playback_pcm_cleanup
  2075. },
  2076. };
  2077. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  2078. .substreams = 1,
  2079. .channels_min = 2,
  2080. .channels_max = 2,
  2081. /* NID is set in stac92xx_build_pcms */
  2082. };
  2083. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  2084. .substreams = 1,
  2085. .channels_min = 2,
  2086. .channels_max = 8,
  2087. .nid = 0x02, /* NID to query formats and rates */
  2088. .ops = {
  2089. .open = stac92xx_playback_pcm_open,
  2090. .prepare = stac92xx_playback_pcm_prepare,
  2091. .cleanup = stac92xx_playback_pcm_cleanup
  2092. },
  2093. };
  2094. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  2095. .substreams = 1,
  2096. .channels_min = 2,
  2097. .channels_max = 2,
  2098. .nid = 0x06, /* NID to query formats and rates */
  2099. .ops = {
  2100. .open = stac92xx_playback_pcm_open,
  2101. .prepare = stac92xx_playback_pcm_prepare,
  2102. .cleanup = stac92xx_playback_pcm_cleanup
  2103. },
  2104. };
  2105. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  2106. .channels_min = 2,
  2107. .channels_max = 2,
  2108. /* NID + .substreams is set in stac92xx_build_pcms */
  2109. .ops = {
  2110. .prepare = stac92xx_capture_pcm_prepare,
  2111. .cleanup = stac92xx_capture_pcm_cleanup
  2112. },
  2113. };
  2114. static int stac92xx_build_pcms(struct hda_codec *codec)
  2115. {
  2116. struct sigmatel_spec *spec = codec->spec;
  2117. struct hda_pcm *info = spec->pcm_rec;
  2118. codec->num_pcms = 1;
  2119. codec->pcm_info = info;
  2120. info->name = "STAC92xx Analog";
  2121. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  2122. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  2123. spec->multiout.dac_nids[0];
  2124. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  2125. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  2126. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
  2127. if (spec->alt_switch) {
  2128. codec->num_pcms++;
  2129. info++;
  2130. info->name = "STAC92xx Analog Alt";
  2131. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  2132. }
  2133. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  2134. codec->num_pcms++;
  2135. info++;
  2136. info->name = "STAC92xx Digital";
  2137. info->pcm_type = spec->autocfg.dig_out_type[0];
  2138. if (spec->multiout.dig_out_nid) {
  2139. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  2140. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  2141. }
  2142. if (spec->dig_in_nid) {
  2143. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  2144. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  2145. }
  2146. }
  2147. return 0;
  2148. }
  2149. static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
  2150. hda_nid_t nid)
  2151. {
  2152. unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
  2153. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  2154. if (pincap & AC_PINCAP_VREF_100)
  2155. return AC_PINCTL_VREF_100;
  2156. if (pincap & AC_PINCAP_VREF_80)
  2157. return AC_PINCTL_VREF_80;
  2158. if (pincap & AC_PINCAP_VREF_50)
  2159. return AC_PINCTL_VREF_50;
  2160. if (pincap & AC_PINCAP_VREF_GRD)
  2161. return AC_PINCTL_VREF_GRD;
  2162. return 0;
  2163. }
  2164. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  2165. {
  2166. snd_hda_codec_write_cache(codec, nid, 0,
  2167. AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2168. }
  2169. #define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
  2170. static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
  2171. struct snd_ctl_elem_value *ucontrol)
  2172. {
  2173. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2174. struct sigmatel_spec *spec = codec->spec;
  2175. ucontrol->value.integer.value[0] = !!spec->hp_switch;
  2176. return 0;
  2177. }
  2178. static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
  2179. static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
  2180. struct snd_ctl_elem_value *ucontrol)
  2181. {
  2182. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2183. struct sigmatel_spec *spec = codec->spec;
  2184. int nid = kcontrol->private_value;
  2185. spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
  2186. /* check to be sure that the ports are upto date with
  2187. * switch changes
  2188. */
  2189. stac_issue_unsol_event(codec, nid);
  2190. return 1;
  2191. }
  2192. static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
  2193. struct snd_ctl_elem_info *uinfo)
  2194. {
  2195. int i;
  2196. static char *texts[] = {
  2197. "Mic In", "Line In", "Line Out"
  2198. };
  2199. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2200. struct sigmatel_spec *spec = codec->spec;
  2201. hda_nid_t nid = kcontrol->private_value;
  2202. if (nid == spec->mic_switch || nid == spec->line_switch)
  2203. i = 3;
  2204. else
  2205. i = 2;
  2206. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2207. uinfo->value.enumerated.items = i;
  2208. uinfo->count = 1;
  2209. if (uinfo->value.enumerated.item >= i)
  2210. uinfo->value.enumerated.item = i-1;
  2211. strcpy(uinfo->value.enumerated.name,
  2212. texts[uinfo->value.enumerated.item]);
  2213. return 0;
  2214. }
  2215. static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
  2216. struct snd_ctl_elem_value *ucontrol)
  2217. {
  2218. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2219. hda_nid_t nid = kcontrol->private_value;
  2220. unsigned int vref = stac92xx_vref_get(codec, nid);
  2221. if (vref == stac92xx_get_default_vref(codec, nid))
  2222. ucontrol->value.enumerated.item[0] = 0;
  2223. else if (vref == AC_PINCTL_VREF_GRD)
  2224. ucontrol->value.enumerated.item[0] = 1;
  2225. else if (vref == AC_PINCTL_VREF_HIZ)
  2226. ucontrol->value.enumerated.item[0] = 2;
  2227. return 0;
  2228. }
  2229. static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
  2230. struct snd_ctl_elem_value *ucontrol)
  2231. {
  2232. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2233. unsigned int new_vref = 0;
  2234. int error;
  2235. hda_nid_t nid = kcontrol->private_value;
  2236. if (ucontrol->value.enumerated.item[0] == 0)
  2237. new_vref = stac92xx_get_default_vref(codec, nid);
  2238. else if (ucontrol->value.enumerated.item[0] == 1)
  2239. new_vref = AC_PINCTL_VREF_GRD;
  2240. else if (ucontrol->value.enumerated.item[0] == 2)
  2241. new_vref = AC_PINCTL_VREF_HIZ;
  2242. else
  2243. return 0;
  2244. if (new_vref != stac92xx_vref_get(codec, nid)) {
  2245. error = stac92xx_vref_set(codec, nid, new_vref);
  2246. return error;
  2247. }
  2248. return 0;
  2249. }
  2250. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
  2251. struct snd_ctl_elem_info *uinfo)
  2252. {
  2253. static char *texts[2];
  2254. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2255. struct sigmatel_spec *spec = codec->spec;
  2256. if (kcontrol->private_value == spec->line_switch)
  2257. texts[0] = "Line In";
  2258. else
  2259. texts[0] = "Mic In";
  2260. texts[1] = "Line Out";
  2261. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2262. uinfo->value.enumerated.items = 2;
  2263. uinfo->count = 1;
  2264. if (uinfo->value.enumerated.item >= 2)
  2265. uinfo->value.enumerated.item = 1;
  2266. strcpy(uinfo->value.enumerated.name,
  2267. texts[uinfo->value.enumerated.item]);
  2268. return 0;
  2269. }
  2270. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2271. {
  2272. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2273. struct sigmatel_spec *spec = codec->spec;
  2274. hda_nid_t nid = kcontrol->private_value;
  2275. int io_idx = (nid == spec->mic_switch) ? 1 : 0;
  2276. ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
  2277. return 0;
  2278. }
  2279. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2280. {
  2281. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2282. struct sigmatel_spec *spec = codec->spec;
  2283. hda_nid_t nid = kcontrol->private_value;
  2284. int io_idx = (nid == spec->mic_switch) ? 1 : 0;
  2285. unsigned short val = !!ucontrol->value.enumerated.item[0];
  2286. spec->io_switch[io_idx] = val;
  2287. if (val)
  2288. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  2289. else {
  2290. unsigned int pinctl = AC_PINCTL_IN_EN;
  2291. if (io_idx) /* set VREF for mic */
  2292. pinctl |= stac92xx_get_default_vref(codec, nid);
  2293. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  2294. }
  2295. /* check the auto-mute again: we need to mute/unmute the speaker
  2296. * appropriately according to the pin direction
  2297. */
  2298. if (spec->hp_detect)
  2299. stac_issue_unsol_event(codec, nid);
  2300. return 1;
  2301. }
  2302. #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
  2303. static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
  2304. struct snd_ctl_elem_value *ucontrol)
  2305. {
  2306. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2307. struct sigmatel_spec *spec = codec->spec;
  2308. ucontrol->value.integer.value[0] = spec->clfe_swap;
  2309. return 0;
  2310. }
  2311. static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
  2312. struct snd_ctl_elem_value *ucontrol)
  2313. {
  2314. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2315. struct sigmatel_spec *spec = codec->spec;
  2316. hda_nid_t nid = kcontrol->private_value & 0xff;
  2317. unsigned int val = !!ucontrol->value.integer.value[0];
  2318. if (spec->clfe_swap == val)
  2319. return 0;
  2320. spec->clfe_swap = val;
  2321. snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  2322. spec->clfe_swap ? 0x4 : 0x0);
  2323. return 1;
  2324. }
  2325. #define STAC_CODEC_HP_SWITCH(xname) \
  2326. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2327. .name = xname, \
  2328. .index = 0, \
  2329. .info = stac92xx_hp_switch_info, \
  2330. .get = stac92xx_hp_switch_get, \
  2331. .put = stac92xx_hp_switch_put, \
  2332. }
  2333. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  2334. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2335. .name = xname, \
  2336. .index = 0, \
  2337. .info = stac92xx_io_switch_info, \
  2338. .get = stac92xx_io_switch_get, \
  2339. .put = stac92xx_io_switch_put, \
  2340. .private_value = xpval, \
  2341. }
  2342. #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
  2343. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2344. .name = xname, \
  2345. .index = 0, \
  2346. .info = stac92xx_clfe_switch_info, \
  2347. .get = stac92xx_clfe_switch_get, \
  2348. .put = stac92xx_clfe_switch_put, \
  2349. .private_value = xpval, \
  2350. }
  2351. enum {
  2352. STAC_CTL_WIDGET_VOL,
  2353. STAC_CTL_WIDGET_MUTE,
  2354. STAC_CTL_WIDGET_MUTE_BEEP,
  2355. STAC_CTL_WIDGET_MONO_MUX,
  2356. STAC_CTL_WIDGET_HP_SWITCH,
  2357. STAC_CTL_WIDGET_IO_SWITCH,
  2358. STAC_CTL_WIDGET_CLFE_SWITCH,
  2359. STAC_CTL_WIDGET_DC_BIAS
  2360. };
  2361. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  2362. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2363. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2364. HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
  2365. STAC_MONO_MUX,
  2366. STAC_CODEC_HP_SWITCH(NULL),
  2367. STAC_CODEC_IO_SWITCH(NULL, 0),
  2368. STAC_CODEC_CLFE_SWITCH(NULL, 0),
  2369. DC_BIAS(NULL, 0, 0),
  2370. };
  2371. /* add dynamic controls */
  2372. static struct snd_kcontrol_new *
  2373. stac_control_new(struct sigmatel_spec *spec,
  2374. struct snd_kcontrol_new *ktemp,
  2375. const char *name,
  2376. unsigned int subdev)
  2377. {
  2378. struct snd_kcontrol_new *knew;
  2379. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  2380. knew = snd_array_new(&spec->kctls);
  2381. if (!knew)
  2382. return NULL;
  2383. *knew = *ktemp;
  2384. knew->name = kstrdup(name, GFP_KERNEL);
  2385. if (!knew->name) {
  2386. /* roolback */
  2387. memset(knew, 0, sizeof(*knew));
  2388. spec->kctls.alloced--;
  2389. return NULL;
  2390. }
  2391. knew->subdevice = subdev;
  2392. return knew;
  2393. }
  2394. static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
  2395. struct snd_kcontrol_new *ktemp,
  2396. int idx, const char *name,
  2397. unsigned long val)
  2398. {
  2399. struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
  2400. HDA_SUBDEV_AMP_FLAG);
  2401. if (!knew)
  2402. return -ENOMEM;
  2403. knew->index = idx;
  2404. knew->private_value = val;
  2405. return 0;
  2406. }
  2407. static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
  2408. int type, int idx, const char *name,
  2409. unsigned long val)
  2410. {
  2411. return stac92xx_add_control_temp(spec,
  2412. &stac92xx_control_templates[type],
  2413. idx, name, val);
  2414. }
  2415. /* add dynamic controls */
  2416. static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
  2417. const char *name, unsigned long val)
  2418. {
  2419. return stac92xx_add_control_idx(spec, type, 0, name, val);
  2420. }
  2421. static struct snd_kcontrol_new stac_input_src_temp = {
  2422. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2423. .name = "Input Source",
  2424. .info = stac92xx_mux_enum_info,
  2425. .get = stac92xx_mux_enum_get,
  2426. .put = stac92xx_mux_enum_put,
  2427. };
  2428. static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
  2429. hda_nid_t nid, int idx)
  2430. {
  2431. int def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2432. int control = 0;
  2433. struct sigmatel_spec *spec = codec->spec;
  2434. char name[22];
  2435. if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
  2436. if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
  2437. && nid == spec->line_switch)
  2438. control = STAC_CTL_WIDGET_IO_SWITCH;
  2439. else if (snd_hda_query_pin_caps(codec, nid)
  2440. & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
  2441. control = STAC_CTL_WIDGET_DC_BIAS;
  2442. else if (nid == spec->mic_switch)
  2443. control = STAC_CTL_WIDGET_IO_SWITCH;
  2444. }
  2445. if (control) {
  2446. strcpy(name, auto_pin_cfg_labels[idx]);
  2447. return stac92xx_add_control(codec->spec, control,
  2448. strcat(name, " Jack Mode"), nid);
  2449. }
  2450. return 0;
  2451. }
  2452. static int stac92xx_add_input_source(struct sigmatel_spec *spec)
  2453. {
  2454. struct snd_kcontrol_new *knew;
  2455. struct hda_input_mux *imux = &spec->private_imux;
  2456. if (spec->auto_mic)
  2457. return 0; /* no need for input source */
  2458. if (!spec->num_adcs || imux->num_items <= 1)
  2459. return 0; /* no need for input source control */
  2460. knew = stac_control_new(spec, &stac_input_src_temp,
  2461. stac_input_src_temp.name, 0);
  2462. if (!knew)
  2463. return -ENOMEM;
  2464. knew->count = spec->num_adcs;
  2465. return 0;
  2466. }
  2467. /* check whether the line-input can be used as line-out */
  2468. static hda_nid_t check_line_out_switch(struct hda_codec *codec)
  2469. {
  2470. struct sigmatel_spec *spec = codec->spec;
  2471. struct auto_pin_cfg *cfg = &spec->autocfg;
  2472. hda_nid_t nid;
  2473. unsigned int pincap;
  2474. if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
  2475. return 0;
  2476. nid = cfg->input_pins[AUTO_PIN_LINE];
  2477. pincap = snd_hda_query_pin_caps(codec, nid);
  2478. if (pincap & AC_PINCAP_OUT)
  2479. return nid;
  2480. return 0;
  2481. }
  2482. /* check whether the mic-input can be used as line-out */
  2483. static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
  2484. {
  2485. struct sigmatel_spec *spec = codec->spec;
  2486. struct auto_pin_cfg *cfg = &spec->autocfg;
  2487. unsigned int def_conf, pincap;
  2488. unsigned int mic_pin;
  2489. if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
  2490. return 0;
  2491. mic_pin = AUTO_PIN_MIC;
  2492. for (;;) {
  2493. hda_nid_t nid = cfg->input_pins[mic_pin];
  2494. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2495. /* some laptops have an internal analog microphone
  2496. * which can't be used as a output */
  2497. if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
  2498. pincap = snd_hda_query_pin_caps(codec, nid);
  2499. if (pincap & AC_PINCAP_OUT)
  2500. return nid;
  2501. }
  2502. if (mic_pin == AUTO_PIN_MIC)
  2503. mic_pin = AUTO_PIN_FRONT_MIC;
  2504. else
  2505. break;
  2506. }
  2507. return 0;
  2508. }
  2509. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  2510. {
  2511. int i;
  2512. for (i = 0; i < spec->multiout.num_dacs; i++) {
  2513. if (spec->multiout.dac_nids[i] == nid)
  2514. return 1;
  2515. }
  2516. return 0;
  2517. }
  2518. static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  2519. {
  2520. int i;
  2521. if (is_in_dac_nids(spec, nid))
  2522. return 1;
  2523. for (i = 0; i < spec->autocfg.hp_outs; i++)
  2524. if (spec->hp_dacs[i] == nid)
  2525. return 1;
  2526. for (i = 0; i < spec->autocfg.speaker_outs; i++)
  2527. if (spec->speaker_dacs[i] == nid)
  2528. return 1;
  2529. return 0;
  2530. }
  2531. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
  2532. {
  2533. struct sigmatel_spec *spec = codec->spec;
  2534. int j, conn_len;
  2535. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  2536. unsigned int wcaps, wtype;
  2537. conn_len = snd_hda_get_connections(codec, nid, conn,
  2538. HDA_MAX_CONNECTIONS);
  2539. /* 92HD88: trace back up the link of nids to find the DAC */
  2540. while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
  2541. != AC_WID_AUD_OUT)) {
  2542. nid = conn[0];
  2543. conn_len = snd_hda_get_connections(codec, nid, conn,
  2544. HDA_MAX_CONNECTIONS);
  2545. }
  2546. for (j = 0; j < conn_len; j++) {
  2547. wcaps = get_wcaps(codec, conn[j]);
  2548. wtype = get_wcaps_type(wcaps);
  2549. /* we check only analog outputs */
  2550. if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
  2551. continue;
  2552. /* if this route has a free DAC, assign it */
  2553. if (!check_all_dac_nids(spec, conn[j])) {
  2554. if (conn_len > 1) {
  2555. /* select this DAC in the pin's input mux */
  2556. snd_hda_codec_write_cache(codec, nid, 0,
  2557. AC_VERB_SET_CONNECT_SEL, j);
  2558. }
  2559. return conn[j];
  2560. }
  2561. }
  2562. /* if all DACs are already assigned, connect to the primary DAC */
  2563. if (conn_len > 1) {
  2564. for (j = 0; j < conn_len; j++) {
  2565. if (conn[j] == spec->multiout.dac_nids[0]) {
  2566. snd_hda_codec_write_cache(codec, nid, 0,
  2567. AC_VERB_SET_CONNECT_SEL, j);
  2568. break;
  2569. }
  2570. }
  2571. }
  2572. return 0;
  2573. }
  2574. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
  2575. static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
  2576. /*
  2577. * Fill in the dac_nids table from the parsed pin configuration
  2578. * This function only works when every pin in line_out_pins[]
  2579. * contains atleast one DAC in its connection list. Some 92xx
  2580. * codecs are not connected directly to a DAC, such as the 9200
  2581. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  2582. */
  2583. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
  2584. {
  2585. struct sigmatel_spec *spec = codec->spec;
  2586. struct auto_pin_cfg *cfg = &spec->autocfg;
  2587. int i;
  2588. hda_nid_t nid, dac;
  2589. for (i = 0; i < cfg->line_outs; i++) {
  2590. nid = cfg->line_out_pins[i];
  2591. dac = get_unassigned_dac(codec, nid);
  2592. if (!dac) {
  2593. if (spec->multiout.num_dacs > 0) {
  2594. /* we have already working output pins,
  2595. * so let's drop the broken ones again
  2596. */
  2597. cfg->line_outs = spec->multiout.num_dacs;
  2598. break;
  2599. }
  2600. /* error out, no available DAC found */
  2601. snd_printk(KERN_ERR
  2602. "%s: No available DAC for pin 0x%x\n",
  2603. __func__, nid);
  2604. return -ENODEV;
  2605. }
  2606. add_spec_dacs(spec, dac);
  2607. }
  2608. for (i = 0; i < cfg->hp_outs; i++) {
  2609. nid = cfg->hp_pins[i];
  2610. dac = get_unassigned_dac(codec, nid);
  2611. if (dac) {
  2612. if (!spec->multiout.hp_nid)
  2613. spec->multiout.hp_nid = dac;
  2614. else
  2615. add_spec_extra_dacs(spec, dac);
  2616. }
  2617. spec->hp_dacs[i] = dac;
  2618. }
  2619. for (i = 0; i < cfg->speaker_outs; i++) {
  2620. nid = cfg->speaker_pins[i];
  2621. dac = get_unassigned_dac(codec, nid);
  2622. if (dac)
  2623. add_spec_extra_dacs(spec, dac);
  2624. spec->speaker_dacs[i] = dac;
  2625. }
  2626. /* add line-in as output */
  2627. nid = check_line_out_switch(codec);
  2628. if (nid) {
  2629. dac = get_unassigned_dac(codec, nid);
  2630. if (dac) {
  2631. snd_printdd("STAC: Add line-in 0x%x as output %d\n",
  2632. nid, cfg->line_outs);
  2633. cfg->line_out_pins[cfg->line_outs] = nid;
  2634. cfg->line_outs++;
  2635. spec->line_switch = nid;
  2636. add_spec_dacs(spec, dac);
  2637. }
  2638. }
  2639. /* add mic as output */
  2640. nid = check_mic_out_switch(codec);
  2641. if (nid) {
  2642. dac = get_unassigned_dac(codec, nid);
  2643. if (dac) {
  2644. snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
  2645. nid, cfg->line_outs);
  2646. cfg->line_out_pins[cfg->line_outs] = nid;
  2647. cfg->line_outs++;
  2648. spec->mic_switch = nid;
  2649. add_spec_dacs(spec, dac);
  2650. }
  2651. }
  2652. snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  2653. spec->multiout.num_dacs,
  2654. spec->multiout.dac_nids[0],
  2655. spec->multiout.dac_nids[1],
  2656. spec->multiout.dac_nids[2],
  2657. spec->multiout.dac_nids[3],
  2658. spec->multiout.dac_nids[4]);
  2659. return 0;
  2660. }
  2661. /* create volume control/switch for the given prefx type */
  2662. static int create_controls_idx(struct hda_codec *codec, const char *pfx,
  2663. int idx, hda_nid_t nid, int chs)
  2664. {
  2665. struct sigmatel_spec *spec = codec->spec;
  2666. char name[32];
  2667. int err;
  2668. if (!spec->check_volume_offset) {
  2669. unsigned int caps, step, nums, db_scale;
  2670. caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  2671. step = (caps & AC_AMPCAP_STEP_SIZE) >>
  2672. AC_AMPCAP_STEP_SIZE_SHIFT;
  2673. step = (step + 1) * 25; /* in .01dB unit */
  2674. nums = (caps & AC_AMPCAP_NUM_STEPS) >>
  2675. AC_AMPCAP_NUM_STEPS_SHIFT;
  2676. db_scale = nums * step;
  2677. /* if dB scale is over -64dB, and finer enough,
  2678. * let's reduce it to half
  2679. */
  2680. if (db_scale > 6400 && nums >= 0x1f)
  2681. spec->volume_offset = nums / 2;
  2682. spec->check_volume_offset = 1;
  2683. }
  2684. sprintf(name, "%s Playback Volume", pfx);
  2685. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
  2686. HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
  2687. spec->volume_offset));
  2688. if (err < 0)
  2689. return err;
  2690. sprintf(name, "%s Playback Switch", pfx);
  2691. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
  2692. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  2693. if (err < 0)
  2694. return err;
  2695. return 0;
  2696. }
  2697. #define create_controls(codec, pfx, nid, chs) \
  2698. create_controls_idx(codec, pfx, 0, nid, chs)
  2699. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  2700. {
  2701. if (spec->multiout.num_dacs > 4) {
  2702. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  2703. return 1;
  2704. } else {
  2705. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  2706. spec->multiout.num_dacs++;
  2707. }
  2708. return 0;
  2709. }
  2710. static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  2711. {
  2712. int i;
  2713. for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
  2714. if (!spec->multiout.extra_out_nid[i]) {
  2715. spec->multiout.extra_out_nid[i] = nid;
  2716. return 0;
  2717. }
  2718. }
  2719. printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
  2720. return 1;
  2721. }
  2722. /* Create output controls
  2723. * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
  2724. */
  2725. static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
  2726. const hda_nid_t *pins,
  2727. const hda_nid_t *dac_nids,
  2728. int type)
  2729. {
  2730. struct sigmatel_spec *spec = codec->spec;
  2731. static const char *chname[4] = {
  2732. "Front", "Surround", NULL /*CLFE*/, "Side"
  2733. };
  2734. hda_nid_t nid;
  2735. int i, err;
  2736. unsigned int wid_caps;
  2737. for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
  2738. if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
  2739. wid_caps = get_wcaps(codec, pins[i]);
  2740. if (wid_caps & AC_WCAP_UNSOL_CAP)
  2741. spec->hp_detect = 1;
  2742. }
  2743. nid = dac_nids[i];
  2744. if (!nid)
  2745. continue;
  2746. if (type != AUTO_PIN_HP_OUT && i == 2) {
  2747. /* Center/LFE */
  2748. err = create_controls(codec, "Center", nid, 1);
  2749. if (err < 0)
  2750. return err;
  2751. err = create_controls(codec, "LFE", nid, 2);
  2752. if (err < 0)
  2753. return err;
  2754. wid_caps = get_wcaps(codec, nid);
  2755. if (wid_caps & AC_WCAP_LR_SWAP) {
  2756. err = stac92xx_add_control(spec,
  2757. STAC_CTL_WIDGET_CLFE_SWITCH,
  2758. "Swap Center/LFE Playback Switch", nid);
  2759. if (err < 0)
  2760. return err;
  2761. }
  2762. } else {
  2763. const char *name;
  2764. int idx;
  2765. switch (type) {
  2766. case AUTO_PIN_HP_OUT:
  2767. name = "Headphone";
  2768. idx = i;
  2769. break;
  2770. case AUTO_PIN_SPEAKER_OUT:
  2771. name = "Speaker";
  2772. idx = i;
  2773. break;
  2774. default:
  2775. name = chname[i];
  2776. idx = 0;
  2777. break;
  2778. }
  2779. err = create_controls_idx(codec, name, idx, nid, 3);
  2780. if (err < 0)
  2781. return err;
  2782. }
  2783. }
  2784. return 0;
  2785. }
  2786. static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
  2787. unsigned long sw, int idx)
  2788. {
  2789. int err;
  2790. err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
  2791. "Capture Volume", vol);
  2792. if (err < 0)
  2793. return err;
  2794. err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
  2795. "Capture Switch", sw);
  2796. if (err < 0)
  2797. return err;
  2798. return 0;
  2799. }
  2800. /* add playback controls from the parsed DAC table */
  2801. static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
  2802. const struct auto_pin_cfg *cfg)
  2803. {
  2804. struct sigmatel_spec *spec = codec->spec;
  2805. hda_nid_t nid;
  2806. int err;
  2807. int idx;
  2808. err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
  2809. spec->multiout.dac_nids,
  2810. cfg->line_out_type);
  2811. if (err < 0)
  2812. return err;
  2813. if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
  2814. err = stac92xx_add_control(spec,
  2815. STAC_CTL_WIDGET_HP_SWITCH,
  2816. "Headphone as Line Out Switch",
  2817. cfg->hp_pins[cfg->hp_outs - 1]);
  2818. if (err < 0)
  2819. return err;
  2820. }
  2821. for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
  2822. nid = cfg->input_pins[idx];
  2823. if (nid) {
  2824. err = stac92xx_add_jack_mode_control(codec, nid, idx);
  2825. if (err < 0)
  2826. return err;
  2827. }
  2828. }
  2829. return 0;
  2830. }
  2831. /* add playback controls for Speaker and HP outputs */
  2832. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  2833. struct auto_pin_cfg *cfg)
  2834. {
  2835. struct sigmatel_spec *spec = codec->spec;
  2836. int err;
  2837. err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
  2838. spec->hp_dacs, AUTO_PIN_HP_OUT);
  2839. if (err < 0)
  2840. return err;
  2841. err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
  2842. spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
  2843. if (err < 0)
  2844. return err;
  2845. return 0;
  2846. }
  2847. /* labels for mono mux outputs */
  2848. static const char *stac92xx_mono_labels[4] = {
  2849. "DAC0", "DAC1", "Mixer", "DAC2"
  2850. };
  2851. /* create mono mux for mono out on capable codecs */
  2852. static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
  2853. {
  2854. struct sigmatel_spec *spec = codec->spec;
  2855. struct hda_input_mux *mono_mux = &spec->private_mono_mux;
  2856. int i, num_cons;
  2857. hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
  2858. num_cons = snd_hda_get_connections(codec,
  2859. spec->mono_nid,
  2860. con_lst,
  2861. HDA_MAX_NUM_INPUTS);
  2862. if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
  2863. return -EINVAL;
  2864. for (i = 0; i < num_cons; i++) {
  2865. mono_mux->items[mono_mux->num_items].label =
  2866. stac92xx_mono_labels[i];
  2867. mono_mux->items[mono_mux->num_items].index = i;
  2868. mono_mux->num_items++;
  2869. }
  2870. return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
  2871. "Mono Mux", spec->mono_nid);
  2872. }
  2873. /* create PC beep volume controls */
  2874. static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
  2875. hda_nid_t nid)
  2876. {
  2877. struct sigmatel_spec *spec = codec->spec;
  2878. u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  2879. int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
  2880. if (spec->anabeep_nid == nid)
  2881. type = STAC_CTL_WIDGET_MUTE;
  2882. /* check for mute support for the the amp */
  2883. if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
  2884. err = stac92xx_add_control(spec, type,
  2885. "Beep Playback Switch",
  2886. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
  2887. if (err < 0)
  2888. return err;
  2889. }
  2890. /* check to see if there is volume support for the amp */
  2891. if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
  2892. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
  2893. "Beep Playback Volume",
  2894. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
  2895. if (err < 0)
  2896. return err;
  2897. }
  2898. return 0;
  2899. }
  2900. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2901. #define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
  2902. static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
  2903. struct snd_ctl_elem_value *ucontrol)
  2904. {
  2905. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2906. ucontrol->value.integer.value[0] = codec->beep->enabled;
  2907. return 0;
  2908. }
  2909. static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
  2910. struct snd_ctl_elem_value *ucontrol)
  2911. {
  2912. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2913. return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
  2914. }
  2915. static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
  2916. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2917. .info = stac92xx_dig_beep_switch_info,
  2918. .get = stac92xx_dig_beep_switch_get,
  2919. .put = stac92xx_dig_beep_switch_put,
  2920. };
  2921. static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
  2922. {
  2923. return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
  2924. 0, "Beep Playback Switch", 0);
  2925. }
  2926. #endif
  2927. static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
  2928. {
  2929. struct sigmatel_spec *spec = codec->spec;
  2930. int i, j, err = 0;
  2931. for (i = 0; i < spec->num_muxes; i++) {
  2932. hda_nid_t nid;
  2933. unsigned int wcaps;
  2934. unsigned long val;
  2935. nid = spec->mux_nids[i];
  2936. wcaps = get_wcaps(codec, nid);
  2937. if (!(wcaps & AC_WCAP_OUT_AMP))
  2938. continue;
  2939. /* check whether already the same control was created as
  2940. * normal Capture Volume.
  2941. */
  2942. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2943. for (j = 0; j < spec->num_caps; j++) {
  2944. if (spec->capvols[j] == val)
  2945. break;
  2946. }
  2947. if (j < spec->num_caps)
  2948. continue;
  2949. err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
  2950. "Mux Capture Volume", val);
  2951. if (err < 0)
  2952. return err;
  2953. }
  2954. return 0;
  2955. };
  2956. static const char *stac92xx_spdif_labels[3] = {
  2957. "Digital Playback", "Analog Mux 1", "Analog Mux 2",
  2958. };
  2959. static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
  2960. {
  2961. struct sigmatel_spec *spec = codec->spec;
  2962. struct hda_input_mux *spdif_mux = &spec->private_smux;
  2963. const char **labels = spec->spdif_labels;
  2964. int i, num_cons;
  2965. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  2966. num_cons = snd_hda_get_connections(codec,
  2967. spec->smux_nids[0],
  2968. con_lst,
  2969. HDA_MAX_NUM_INPUTS);
  2970. if (num_cons <= 0)
  2971. return -EINVAL;
  2972. if (!labels)
  2973. labels = stac92xx_spdif_labels;
  2974. for (i = 0; i < num_cons; i++) {
  2975. spdif_mux->items[spdif_mux->num_items].label = labels[i];
  2976. spdif_mux->items[spdif_mux->num_items].index = i;
  2977. spdif_mux->num_items++;
  2978. }
  2979. return 0;
  2980. }
  2981. /* labels for dmic mux inputs */
  2982. static const char *stac92xx_dmic_labels[5] = {
  2983. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  2984. "Digital Mic 3", "Digital Mic 4"
  2985. };
  2986. static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
  2987. hda_nid_t nid)
  2988. {
  2989. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  2990. int i, nums;
  2991. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  2992. for (i = 0; i < nums; i++)
  2993. if (conn[i] == nid)
  2994. return i;
  2995. return -1;
  2996. }
  2997. /* create a volume assigned to the given pin (only if supported) */
  2998. /* return 1 if the volume control is created */
  2999. static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
  3000. const char *label, int direction)
  3001. {
  3002. unsigned int caps, nums;
  3003. char name[32];
  3004. int err;
  3005. if (direction == HDA_OUTPUT)
  3006. caps = AC_WCAP_OUT_AMP;
  3007. else
  3008. caps = AC_WCAP_IN_AMP;
  3009. if (!(get_wcaps(codec, nid) & caps))
  3010. return 0;
  3011. caps = query_amp_caps(codec, nid, direction);
  3012. nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
  3013. if (!nums)
  3014. return 0;
  3015. snprintf(name, sizeof(name), "%s Capture Volume", label);
  3016. err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
  3017. HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
  3018. if (err < 0)
  3019. return err;
  3020. return 1;
  3021. }
  3022. /* create playback/capture controls for input pins on dmic capable codecs */
  3023. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  3024. const struct auto_pin_cfg *cfg)
  3025. {
  3026. struct sigmatel_spec *spec = codec->spec;
  3027. struct hda_input_mux *imux = &spec->private_imux;
  3028. struct hda_input_mux *dimux = &spec->private_dimux;
  3029. int err, i, active_mics;
  3030. unsigned int def_conf;
  3031. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  3032. dimux->items[dimux->num_items].index = 0;
  3033. dimux->num_items++;
  3034. active_mics = 0;
  3035. for (i = 0; i < spec->num_dmics; i++) {
  3036. /* check the validity: sometimes it's a dead vendor-spec node */
  3037. if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
  3038. != AC_WID_PIN)
  3039. continue;
  3040. def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
  3041. if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
  3042. active_mics++;
  3043. }
  3044. for (i = 0; i < spec->num_dmics; i++) {
  3045. hda_nid_t nid;
  3046. int index;
  3047. const char *label;
  3048. nid = spec->dmic_nids[i];
  3049. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  3050. continue;
  3051. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3052. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  3053. continue;
  3054. index = get_connection_index(codec, spec->dmux_nids[0], nid);
  3055. if (index < 0)
  3056. continue;
  3057. if (active_mics == 1)
  3058. label = "Digital Mic";
  3059. else
  3060. label = stac92xx_dmic_labels[dimux->num_items];
  3061. err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
  3062. if (err < 0)
  3063. return err;
  3064. if (!err) {
  3065. err = create_elem_capture_vol(codec, nid, label,
  3066. HDA_OUTPUT);
  3067. if (err < 0)
  3068. return err;
  3069. }
  3070. dimux->items[dimux->num_items].label = label;
  3071. dimux->items[dimux->num_items].index = index;
  3072. dimux->num_items++;
  3073. if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
  3074. imux->items[imux->num_items].label = label;
  3075. imux->items[imux->num_items].index = index;
  3076. imux->num_items++;
  3077. }
  3078. }
  3079. return 0;
  3080. }
  3081. static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
  3082. hda_nid_t *fixed, hda_nid_t *ext)
  3083. {
  3084. unsigned int cfg;
  3085. if (!nid)
  3086. return 0;
  3087. cfg = snd_hda_codec_get_pincfg(codec, nid);
  3088. switch (get_defcfg_connect(cfg)) {
  3089. case AC_JACK_PORT_FIXED:
  3090. if (*fixed)
  3091. return 1; /* already occupied */
  3092. *fixed = nid;
  3093. break;
  3094. case AC_JACK_PORT_COMPLEX:
  3095. if (*ext)
  3096. return 1; /* already occupied */
  3097. *ext = nid;
  3098. break;
  3099. }
  3100. return 0;
  3101. }
  3102. static int set_mic_route(struct hda_codec *codec,
  3103. struct sigmatel_mic_route *mic,
  3104. hda_nid_t pin)
  3105. {
  3106. struct sigmatel_spec *spec = codec->spec;
  3107. struct auto_pin_cfg *cfg = &spec->autocfg;
  3108. int i;
  3109. mic->pin = pin;
  3110. for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
  3111. if (pin == cfg->input_pins[i])
  3112. break;
  3113. if (i <= AUTO_PIN_FRONT_MIC) {
  3114. /* analog pin */
  3115. i = get_connection_index(codec, spec->mux_nids[0], pin);
  3116. if (i < 0)
  3117. return -1;
  3118. mic->mux_idx = i;
  3119. mic->dmux_idx = -1;
  3120. if (spec->dmux_nids)
  3121. mic->dmux_idx = get_connection_index(codec,
  3122. spec->dmux_nids[0],
  3123. spec->mux_nids[0]);
  3124. } else if (spec->dmux_nids) {
  3125. /* digital pin */
  3126. i = get_connection_index(codec, spec->dmux_nids[0], pin);
  3127. if (i < 0)
  3128. return -1;
  3129. mic->dmux_idx = i;
  3130. mic->mux_idx = -1;
  3131. if (spec->mux_nids)
  3132. mic->mux_idx = get_connection_index(codec,
  3133. spec->mux_nids[0],
  3134. spec->dmux_nids[0]);
  3135. }
  3136. return 0;
  3137. }
  3138. /* return non-zero if the device is for automatic mic switch */
  3139. static int stac_check_auto_mic(struct hda_codec *codec)
  3140. {
  3141. struct sigmatel_spec *spec = codec->spec;
  3142. struct auto_pin_cfg *cfg = &spec->autocfg;
  3143. hda_nid_t fixed, ext;
  3144. int i;
  3145. for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
  3146. if (cfg->input_pins[i])
  3147. return 0; /* must be exclusively mics */
  3148. }
  3149. fixed = ext = 0;
  3150. for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
  3151. if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
  3152. return 0;
  3153. for (i = 0; i < spec->num_dmics; i++)
  3154. if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
  3155. return 0;
  3156. if (!fixed || !ext)
  3157. return 0;
  3158. if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
  3159. return 0; /* no unsol support */
  3160. if (set_mic_route(codec, &spec->ext_mic, ext) ||
  3161. set_mic_route(codec, &spec->int_mic, fixed))
  3162. return 0; /* something is wrong */
  3163. return 1;
  3164. }
  3165. /* create playback/capture controls for input pins */
  3166. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  3167. {
  3168. struct sigmatel_spec *spec = codec->spec;
  3169. struct hda_input_mux *imux = &spec->private_imux;
  3170. int i, j;
  3171. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3172. hda_nid_t nid = cfg->input_pins[i];
  3173. int index, err;
  3174. if (!nid)
  3175. continue;
  3176. index = -1;
  3177. for (j = 0; j < spec->num_muxes; j++) {
  3178. index = get_connection_index(codec, spec->mux_nids[j],
  3179. nid);
  3180. if (index >= 0)
  3181. break;
  3182. }
  3183. if (index < 0)
  3184. continue;
  3185. err = create_elem_capture_vol(codec, nid,
  3186. auto_pin_cfg_labels[i],
  3187. HDA_INPUT);
  3188. if (err < 0)
  3189. return err;
  3190. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  3191. imux->items[imux->num_items].index = index;
  3192. imux->num_items++;
  3193. }
  3194. spec->num_analog_muxes = imux->num_items;
  3195. if (imux->num_items) {
  3196. /*
  3197. * Set the current input for the muxes.
  3198. * The STAC9221 has two input muxes with identical source
  3199. * NID lists. Hopefully this won't get confused.
  3200. */
  3201. for (i = 0; i < spec->num_muxes; i++) {
  3202. snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
  3203. AC_VERB_SET_CONNECT_SEL,
  3204. imux->items[0].index);
  3205. }
  3206. }
  3207. return 0;
  3208. }
  3209. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  3210. {
  3211. struct sigmatel_spec *spec = codec->spec;
  3212. int i;
  3213. for (i = 0; i < spec->autocfg.line_outs; i++) {
  3214. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3215. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  3216. }
  3217. }
  3218. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  3219. {
  3220. struct sigmatel_spec *spec = codec->spec;
  3221. int i;
  3222. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3223. hda_nid_t pin;
  3224. pin = spec->autocfg.hp_pins[i];
  3225. if (pin) /* connect to front */
  3226. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  3227. }
  3228. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  3229. hda_nid_t pin;
  3230. pin = spec->autocfg.speaker_pins[i];
  3231. if (pin) /* connect to front */
  3232. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  3233. }
  3234. }
  3235. static int is_dual_headphones(struct hda_codec *codec)
  3236. {
  3237. struct sigmatel_spec *spec = codec->spec;
  3238. int i, valid_hps;
  3239. if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
  3240. spec->autocfg.hp_outs <= 1)
  3241. return 0;
  3242. valid_hps = 0;
  3243. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3244. hda_nid_t nid = spec->autocfg.hp_pins[i];
  3245. unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
  3246. if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
  3247. continue;
  3248. valid_hps++;
  3249. }
  3250. return (valid_hps > 1);
  3251. }
  3252. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  3253. {
  3254. struct sigmatel_spec *spec = codec->spec;
  3255. int hp_swap = 0;
  3256. int i, err;
  3257. if ((err = snd_hda_parse_pin_def_config(codec,
  3258. &spec->autocfg,
  3259. spec->dmic_nids)) < 0)
  3260. return err;
  3261. if (! spec->autocfg.line_outs)
  3262. return 0; /* can't find valid pin config */
  3263. /* If we have no real line-out pin and multiple hp-outs, HPs should
  3264. * be set up as multi-channel outputs.
  3265. */
  3266. if (is_dual_headphones(codec)) {
  3267. /* Copy hp_outs to line_outs, backup line_outs in
  3268. * speaker_outs so that the following routines can handle
  3269. * HP pins as primary outputs.
  3270. */
  3271. snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
  3272. memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
  3273. sizeof(spec->autocfg.line_out_pins));
  3274. spec->autocfg.speaker_outs = spec->autocfg.line_outs;
  3275. memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
  3276. sizeof(spec->autocfg.hp_pins));
  3277. spec->autocfg.line_outs = spec->autocfg.hp_outs;
  3278. spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
  3279. spec->autocfg.hp_outs = 0;
  3280. hp_swap = 1;
  3281. }
  3282. if (spec->autocfg.mono_out_pin) {
  3283. int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
  3284. (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
  3285. u32 caps = query_amp_caps(codec,
  3286. spec->autocfg.mono_out_pin, dir);
  3287. hda_nid_t conn_list[1];
  3288. /* get the mixer node and then the mono mux if it exists */
  3289. if (snd_hda_get_connections(codec,
  3290. spec->autocfg.mono_out_pin, conn_list, 1) &&
  3291. snd_hda_get_connections(codec, conn_list[0],
  3292. conn_list, 1) > 0) {
  3293. int wcaps = get_wcaps(codec, conn_list[0]);
  3294. int wid_type = get_wcaps_type(wcaps);
  3295. /* LR swap check, some stac925x have a mux that
  3296. * changes the DACs output path instead of the
  3297. * mono-mux path.
  3298. */
  3299. if (wid_type == AC_WID_AUD_SEL &&
  3300. !(wcaps & AC_WCAP_LR_SWAP))
  3301. spec->mono_nid = conn_list[0];
  3302. }
  3303. if (dir) {
  3304. hda_nid_t nid = spec->autocfg.mono_out_pin;
  3305. /* most mono outs have a least a mute/unmute switch */
  3306. dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
  3307. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
  3308. "Mono Playback Switch",
  3309. HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
  3310. if (err < 0)
  3311. return err;
  3312. /* check for volume support for the amp */
  3313. if ((caps & AC_AMPCAP_NUM_STEPS)
  3314. >> AC_AMPCAP_NUM_STEPS_SHIFT) {
  3315. err = stac92xx_add_control(spec,
  3316. STAC_CTL_WIDGET_VOL,
  3317. "Mono Playback Volume",
  3318. HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
  3319. if (err < 0)
  3320. return err;
  3321. }
  3322. }
  3323. stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
  3324. AC_PINCTL_OUT_EN);
  3325. }
  3326. if (!spec->multiout.num_dacs) {
  3327. err = stac92xx_auto_fill_dac_nids(codec);
  3328. if (err < 0)
  3329. return err;
  3330. err = stac92xx_auto_create_multi_out_ctls(codec,
  3331. &spec->autocfg);
  3332. if (err < 0)
  3333. return err;
  3334. }
  3335. /* setup analog beep controls */
  3336. if (spec->anabeep_nid > 0) {
  3337. err = stac92xx_auto_create_beep_ctls(codec,
  3338. spec->anabeep_nid);
  3339. if (err < 0)
  3340. return err;
  3341. }
  3342. /* setup digital beep controls and input device */
  3343. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3344. if (spec->digbeep_nid > 0) {
  3345. hda_nid_t nid = spec->digbeep_nid;
  3346. unsigned int caps;
  3347. err = stac92xx_auto_create_beep_ctls(codec, nid);
  3348. if (err < 0)
  3349. return err;
  3350. err = snd_hda_attach_beep_device(codec, nid);
  3351. if (err < 0)
  3352. return err;
  3353. if (codec->beep) {
  3354. /* IDT/STAC codecs have linear beep tone parameter */
  3355. codec->beep->linear_tone = spec->linear_tone_beep;
  3356. /* if no beep switch is available, make its own one */
  3357. caps = query_amp_caps(codec, nid, HDA_OUTPUT);
  3358. if (!(caps & AC_AMPCAP_MUTE)) {
  3359. err = stac92xx_beep_switch_ctl(codec);
  3360. if (err < 0)
  3361. return err;
  3362. }
  3363. }
  3364. }
  3365. #endif
  3366. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  3367. if (err < 0)
  3368. return err;
  3369. /* All output parsing done, now restore the swapped hp pins */
  3370. if (hp_swap) {
  3371. memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
  3372. sizeof(spec->autocfg.hp_pins));
  3373. spec->autocfg.hp_outs = spec->autocfg.line_outs;
  3374. spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
  3375. spec->autocfg.line_outs = 0;
  3376. }
  3377. if (stac_check_auto_mic(codec)) {
  3378. spec->auto_mic = 1;
  3379. /* only one capture for auto-mic */
  3380. spec->num_adcs = 1;
  3381. spec->num_caps = 1;
  3382. spec->num_muxes = 1;
  3383. }
  3384. for (i = 0; i < spec->num_caps; i++) {
  3385. err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
  3386. spec->capsws[i], i);
  3387. if (err < 0)
  3388. return err;
  3389. }
  3390. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  3391. if (err < 0)
  3392. return err;
  3393. if (spec->mono_nid > 0) {
  3394. err = stac92xx_auto_create_mono_output_ctls(codec);
  3395. if (err < 0)
  3396. return err;
  3397. }
  3398. if (spec->num_dmics > 0 && !spec->dinput_mux)
  3399. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  3400. &spec->autocfg)) < 0)
  3401. return err;
  3402. if (spec->num_muxes > 0) {
  3403. err = stac92xx_auto_create_mux_input_ctls(codec);
  3404. if (err < 0)
  3405. return err;
  3406. }
  3407. if (spec->num_smuxes > 0) {
  3408. err = stac92xx_auto_create_spdif_mux_ctls(codec);
  3409. if (err < 0)
  3410. return err;
  3411. }
  3412. err = stac92xx_add_input_source(spec);
  3413. if (err < 0)
  3414. return err;
  3415. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3416. if (spec->multiout.max_channels > 2)
  3417. spec->surr_switch = 1;
  3418. if (spec->autocfg.dig_outs)
  3419. spec->multiout.dig_out_nid = dig_out;
  3420. if (dig_in && spec->autocfg.dig_in_pin)
  3421. spec->dig_in_nid = dig_in;
  3422. if (spec->kctls.list)
  3423. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3424. spec->input_mux = &spec->private_imux;
  3425. if (!spec->dinput_mux)
  3426. spec->dinput_mux = &spec->private_dimux;
  3427. spec->sinput_mux = &spec->private_smux;
  3428. spec->mono_mux = &spec->private_mono_mux;
  3429. return 1;
  3430. }
  3431. /* add playback controls for HP output */
  3432. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  3433. struct auto_pin_cfg *cfg)
  3434. {
  3435. struct sigmatel_spec *spec = codec->spec;
  3436. hda_nid_t pin = cfg->hp_pins[0];
  3437. unsigned int wid_caps;
  3438. if (! pin)
  3439. return 0;
  3440. wid_caps = get_wcaps(codec, pin);
  3441. if (wid_caps & AC_WCAP_UNSOL_CAP)
  3442. spec->hp_detect = 1;
  3443. return 0;
  3444. }
  3445. /* add playback controls for LFE output */
  3446. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  3447. struct auto_pin_cfg *cfg)
  3448. {
  3449. struct sigmatel_spec *spec = codec->spec;
  3450. int err;
  3451. hda_nid_t lfe_pin = 0x0;
  3452. int i;
  3453. /*
  3454. * search speaker outs and line outs for a mono speaker pin
  3455. * with an amp. If one is found, add LFE controls
  3456. * for it.
  3457. */
  3458. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  3459. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  3460. unsigned int wcaps = get_wcaps(codec, pin);
  3461. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  3462. if (wcaps == AC_WCAP_OUT_AMP)
  3463. /* found a mono speaker with an amp, must be lfe */
  3464. lfe_pin = pin;
  3465. }
  3466. /* if speaker_outs is 0, then speakers may be in line_outs */
  3467. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  3468. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  3469. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  3470. unsigned int defcfg;
  3471. defcfg = snd_hda_codec_get_pincfg(codec, pin);
  3472. if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
  3473. unsigned int wcaps = get_wcaps(codec, pin);
  3474. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  3475. if (wcaps == AC_WCAP_OUT_AMP)
  3476. /* found a mono speaker with an amp,
  3477. must be lfe */
  3478. lfe_pin = pin;
  3479. }
  3480. }
  3481. }
  3482. if (lfe_pin) {
  3483. err = create_controls(codec, "LFE", lfe_pin, 1);
  3484. if (err < 0)
  3485. return err;
  3486. }
  3487. return 0;
  3488. }
  3489. static int stac9200_parse_auto_config(struct hda_codec *codec)
  3490. {
  3491. struct sigmatel_spec *spec = codec->spec;
  3492. int err;
  3493. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  3494. return err;
  3495. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  3496. return err;
  3497. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  3498. return err;
  3499. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  3500. return err;
  3501. if (spec->num_muxes > 0) {
  3502. err = stac92xx_auto_create_mux_input_ctls(codec);
  3503. if (err < 0)
  3504. return err;
  3505. }
  3506. err = stac92xx_add_input_source(spec);
  3507. if (err < 0)
  3508. return err;
  3509. if (spec->autocfg.dig_outs)
  3510. spec->multiout.dig_out_nid = 0x05;
  3511. if (spec->autocfg.dig_in_pin)
  3512. spec->dig_in_nid = 0x04;
  3513. if (spec->kctls.list)
  3514. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  3515. spec->input_mux = &spec->private_imux;
  3516. spec->dinput_mux = &spec->private_dimux;
  3517. return 1;
  3518. }
  3519. /*
  3520. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  3521. * funky external mute control using GPIO pins.
  3522. */
  3523. static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
  3524. unsigned int dir_mask, unsigned int data)
  3525. {
  3526. unsigned int gpiostate, gpiomask, gpiodir;
  3527. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  3528. AC_VERB_GET_GPIO_DATA, 0);
  3529. gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
  3530. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  3531. AC_VERB_GET_GPIO_MASK, 0);
  3532. gpiomask |= mask;
  3533. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  3534. AC_VERB_GET_GPIO_DIRECTION, 0);
  3535. gpiodir |= dir_mask;
  3536. /* Configure GPIOx as CMOS */
  3537. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  3538. snd_hda_codec_write(codec, codec->afg, 0,
  3539. AC_VERB_SET_GPIO_MASK, gpiomask);
  3540. snd_hda_codec_read(codec, codec->afg, 0,
  3541. AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
  3542. msleep(1);
  3543. snd_hda_codec_read(codec, codec->afg, 0,
  3544. AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
  3545. }
  3546. #ifdef CONFIG_SND_HDA_INPUT_JACK
  3547. static void stac92xx_free_jack_priv(struct snd_jack *jack)
  3548. {
  3549. struct sigmatel_jack *jacks = jack->private_data;
  3550. jacks->nid = 0;
  3551. jacks->jack = NULL;
  3552. }
  3553. #endif
  3554. static int stac92xx_add_jack(struct hda_codec *codec,
  3555. hda_nid_t nid, int type)
  3556. {
  3557. #ifdef CONFIG_SND_HDA_INPUT_JACK
  3558. struct sigmatel_spec *spec = codec->spec;
  3559. struct sigmatel_jack *jack;
  3560. int def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3561. int connectivity = get_defcfg_connect(def_conf);
  3562. char name[32];
  3563. int err;
  3564. if (connectivity && connectivity != AC_JACK_PORT_FIXED)
  3565. return 0;
  3566. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  3567. jack = snd_array_new(&spec->jacks);
  3568. if (!jack)
  3569. return -ENOMEM;
  3570. jack->nid = nid;
  3571. jack->type = type;
  3572. snprintf(name, sizeof(name), "%s at %s %s Jack",
  3573. snd_hda_get_jack_type(def_conf),
  3574. snd_hda_get_jack_connectivity(def_conf),
  3575. snd_hda_get_jack_location(def_conf));
  3576. err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
  3577. if (err < 0) {
  3578. jack->nid = 0;
  3579. return err;
  3580. }
  3581. jack->jack->private_data = jack;
  3582. jack->jack->private_free = stac92xx_free_jack_priv;
  3583. #endif
  3584. return 0;
  3585. }
  3586. static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
  3587. unsigned char type, int data)
  3588. {
  3589. struct sigmatel_event *event;
  3590. snd_array_init(&spec->events, sizeof(*event), 32);
  3591. event = snd_array_new(&spec->events);
  3592. if (!event)
  3593. return -ENOMEM;
  3594. event->nid = nid;
  3595. event->type = type;
  3596. event->tag = spec->events.used;
  3597. event->data = data;
  3598. return event->tag;
  3599. }
  3600. static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
  3601. hda_nid_t nid)
  3602. {
  3603. struct sigmatel_spec *spec = codec->spec;
  3604. struct sigmatel_event *event = spec->events.list;
  3605. int i;
  3606. for (i = 0; i < spec->events.used; i++, event++) {
  3607. if (event->nid == nid)
  3608. return event;
  3609. }
  3610. return NULL;
  3611. }
  3612. static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
  3613. unsigned char tag)
  3614. {
  3615. struct sigmatel_spec *spec = codec->spec;
  3616. struct sigmatel_event *event = spec->events.list;
  3617. int i;
  3618. for (i = 0; i < spec->events.used; i++, event++) {
  3619. if (event->tag == tag)
  3620. return event;
  3621. }
  3622. return NULL;
  3623. }
  3624. /* check if given nid is a valid pin and no other events are assigned
  3625. * to it. If OK, assign the event, set the unsol flag, and returns 1.
  3626. * Otherwise, returns zero.
  3627. */
  3628. static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  3629. unsigned int type)
  3630. {
  3631. struct sigmatel_event *event;
  3632. int tag;
  3633. if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
  3634. return 0;
  3635. event = stac_get_event(codec, nid);
  3636. if (event) {
  3637. if (event->type != type)
  3638. return 0;
  3639. tag = event->tag;
  3640. } else {
  3641. tag = stac_add_event(codec->spec, nid, type, 0);
  3642. if (tag < 0)
  3643. return 0;
  3644. }
  3645. snd_hda_codec_write_cache(codec, nid, 0,
  3646. AC_VERB_SET_UNSOLICITED_ENABLE,
  3647. AC_USRSP_EN | tag);
  3648. return 1;
  3649. }
  3650. static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
  3651. {
  3652. int i;
  3653. for (i = 0; i < cfg->hp_outs; i++)
  3654. if (cfg->hp_pins[i] == nid)
  3655. return 1; /* nid is a HP-Out */
  3656. return 0; /* nid is not a HP-Out */
  3657. };
  3658. static void stac92xx_power_down(struct hda_codec *codec)
  3659. {
  3660. struct sigmatel_spec *spec = codec->spec;
  3661. /* power down inactive DACs */
  3662. hda_nid_t *dac;
  3663. for (dac = spec->dac_list; *dac; dac++)
  3664. if (!check_all_dac_nids(spec, *dac))
  3665. snd_hda_codec_write(codec, *dac, 0,
  3666. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3667. }
  3668. static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
  3669. int enable);
  3670. static inline int get_int_hint(struct hda_codec *codec, const char *key,
  3671. int *valp)
  3672. {
  3673. const char *p;
  3674. p = snd_hda_get_hint(codec, key);
  3675. if (p) {
  3676. unsigned long val;
  3677. if (!strict_strtoul(p, 0, &val)) {
  3678. *valp = val;
  3679. return 1;
  3680. }
  3681. }
  3682. return 0;
  3683. }
  3684. /* override some hints from the hwdep entry */
  3685. static void stac_store_hints(struct hda_codec *codec)
  3686. {
  3687. struct sigmatel_spec *spec = codec->spec;
  3688. int val;
  3689. val = snd_hda_get_bool_hint(codec, "hp_detect");
  3690. if (val >= 0)
  3691. spec->hp_detect = val;
  3692. if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
  3693. spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
  3694. spec->gpio_mask;
  3695. }
  3696. if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
  3697. spec->gpio_mask &= spec->gpio_mask;
  3698. if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
  3699. spec->gpio_dir &= spec->gpio_mask;
  3700. if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
  3701. spec->eapd_mask &= spec->gpio_mask;
  3702. if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
  3703. spec->gpio_mute &= spec->gpio_mask;
  3704. val = snd_hda_get_bool_hint(codec, "eapd_switch");
  3705. if (val >= 0)
  3706. spec->eapd_switch = val;
  3707. get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
  3708. if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
  3709. spec->gpio_mask |= spec->gpio_led;
  3710. spec->gpio_dir |= spec->gpio_led;
  3711. if (spec->gpio_led_polarity)
  3712. spec->gpio_data |= spec->gpio_led;
  3713. }
  3714. }
  3715. static int stac92xx_init(struct hda_codec *codec)
  3716. {
  3717. struct sigmatel_spec *spec = codec->spec;
  3718. struct auto_pin_cfg *cfg = &spec->autocfg;
  3719. unsigned int gpio;
  3720. int i;
  3721. snd_hda_sequence_write(codec, spec->init);
  3722. /* power down adcs initially */
  3723. if (spec->powerdown_adcs)
  3724. for (i = 0; i < spec->num_adcs; i++)
  3725. snd_hda_codec_write(codec,
  3726. spec->adc_nids[i], 0,
  3727. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3728. /* override some hints */
  3729. stac_store_hints(codec);
  3730. /* set up GPIO */
  3731. gpio = spec->gpio_data;
  3732. /* turn on EAPD statically when spec->eapd_switch isn't set.
  3733. * otherwise, unsol event will turn it on/off dynamically
  3734. */
  3735. if (!spec->eapd_switch)
  3736. gpio |= spec->eapd_mask;
  3737. stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
  3738. /* set up pins */
  3739. if (spec->hp_detect) {
  3740. /* Enable unsolicited responses on the HP widget */
  3741. for (i = 0; i < cfg->hp_outs; i++) {
  3742. hda_nid_t nid = cfg->hp_pins[i];
  3743. enable_pin_detect(codec, nid, STAC_HP_EVENT);
  3744. }
  3745. if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
  3746. cfg->speaker_outs > 0) {
  3747. /* enable pin-detect for line-outs as well */
  3748. for (i = 0; i < cfg->line_outs; i++) {
  3749. hda_nid_t nid = cfg->line_out_pins[i];
  3750. enable_pin_detect(codec, nid, STAC_LO_EVENT);
  3751. }
  3752. }
  3753. /* force to enable the first line-out; the others are set up
  3754. * in unsol_event
  3755. */
  3756. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  3757. AC_PINCTL_OUT_EN);
  3758. /* fake event to set up pins */
  3759. if (cfg->hp_pins[0])
  3760. stac_issue_unsol_event(codec, cfg->hp_pins[0]);
  3761. else if (cfg->line_out_pins[0])
  3762. stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
  3763. } else {
  3764. stac92xx_auto_init_multi_out(codec);
  3765. stac92xx_auto_init_hp_out(codec);
  3766. for (i = 0; i < cfg->hp_outs; i++)
  3767. stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
  3768. }
  3769. if (spec->auto_mic) {
  3770. /* initialize connection to analog input */
  3771. if (spec->dmux_nids)
  3772. snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
  3773. AC_VERB_SET_CONNECT_SEL, 0);
  3774. if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
  3775. stac_issue_unsol_event(codec, spec->ext_mic.pin);
  3776. }
  3777. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3778. hda_nid_t nid = cfg->input_pins[i];
  3779. if (nid) {
  3780. unsigned int pinctl, conf;
  3781. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
  3782. /* for mic pins, force to initialize */
  3783. pinctl = stac92xx_get_default_vref(codec, nid);
  3784. pinctl |= AC_PINCTL_IN_EN;
  3785. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  3786. } else {
  3787. pinctl = snd_hda_codec_read(codec, nid, 0,
  3788. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3789. /* if PINCTL already set then skip */
  3790. /* Also, if both INPUT and OUTPUT are set,
  3791. * it must be a BIOS bug; need to override, too
  3792. */
  3793. if (!(pinctl & AC_PINCTL_IN_EN) ||
  3794. (pinctl & AC_PINCTL_OUT_EN)) {
  3795. pinctl &= ~AC_PINCTL_OUT_EN;
  3796. pinctl |= AC_PINCTL_IN_EN;
  3797. stac92xx_auto_set_pinctl(codec, nid,
  3798. pinctl);
  3799. }
  3800. }
  3801. conf = snd_hda_codec_get_pincfg(codec, nid);
  3802. if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
  3803. if (enable_pin_detect(codec, nid,
  3804. STAC_INSERT_EVENT))
  3805. stac_issue_unsol_event(codec, nid);
  3806. }
  3807. }
  3808. }
  3809. for (i = 0; i < spec->num_dmics; i++)
  3810. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  3811. AC_PINCTL_IN_EN);
  3812. if (cfg->dig_out_pins[0])
  3813. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
  3814. AC_PINCTL_OUT_EN);
  3815. if (cfg->dig_in_pin)
  3816. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  3817. AC_PINCTL_IN_EN);
  3818. for (i = 0; i < spec->num_pwrs; i++) {
  3819. hda_nid_t nid = spec->pwr_nids[i];
  3820. int pinctl, def_conf;
  3821. /* power on when no jack detection is available */
  3822. if (!spec->hp_detect) {
  3823. stac_toggle_power_map(codec, nid, 1);
  3824. continue;
  3825. }
  3826. if (is_nid_hp_pin(cfg, nid))
  3827. continue; /* already has an unsol event */
  3828. pinctl = snd_hda_codec_read(codec, nid, 0,
  3829. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3830. /* outputs are only ports capable of power management
  3831. * any attempts on powering down a input port cause the
  3832. * referenced VREF to act quirky.
  3833. */
  3834. if (pinctl & AC_PINCTL_IN_EN) {
  3835. stac_toggle_power_map(codec, nid, 1);
  3836. continue;
  3837. }
  3838. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  3839. def_conf = get_defcfg_connect(def_conf);
  3840. /* skip any ports that don't have jacks since presence
  3841. * detection is useless */
  3842. if (def_conf != AC_JACK_PORT_COMPLEX) {
  3843. if (def_conf != AC_JACK_PORT_NONE)
  3844. stac_toggle_power_map(codec, nid, 1);
  3845. continue;
  3846. }
  3847. if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
  3848. stac_issue_unsol_event(codec, nid);
  3849. }
  3850. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3851. /* sync mute LED */
  3852. if (spec->gpio_led && codec->patch_ops.check_power_status)
  3853. codec->patch_ops.check_power_status(codec, 0x01);
  3854. #endif
  3855. if (spec->dac_list)
  3856. stac92xx_power_down(codec);
  3857. return 0;
  3858. }
  3859. static void stac92xx_free_jacks(struct hda_codec *codec)
  3860. {
  3861. #ifdef CONFIG_SND_HDA_INPUT_JACK
  3862. /* free jack instances manually when clearing/reconfiguring */
  3863. struct sigmatel_spec *spec = codec->spec;
  3864. if (!codec->bus->shutdown && spec->jacks.list) {
  3865. struct sigmatel_jack *jacks = spec->jacks.list;
  3866. int i;
  3867. for (i = 0; i < spec->jacks.used; i++, jacks++) {
  3868. if (jacks->jack)
  3869. snd_device_free(codec->bus->card, jacks->jack);
  3870. }
  3871. }
  3872. snd_array_free(&spec->jacks);
  3873. #endif
  3874. }
  3875. static void stac92xx_free_kctls(struct hda_codec *codec)
  3876. {
  3877. struct sigmatel_spec *spec = codec->spec;
  3878. if (spec->kctls.list) {
  3879. struct snd_kcontrol_new *kctl = spec->kctls.list;
  3880. int i;
  3881. for (i = 0; i < spec->kctls.used; i++)
  3882. kfree(kctl[i].name);
  3883. }
  3884. snd_array_free(&spec->kctls);
  3885. }
  3886. static void stac92xx_shutup(struct hda_codec *codec)
  3887. {
  3888. struct sigmatel_spec *spec = codec->spec;
  3889. snd_hda_shutup_pins(codec);
  3890. if (spec->eapd_mask)
  3891. stac_gpio_set(codec, spec->gpio_mask,
  3892. spec->gpio_dir, spec->gpio_data &
  3893. ~spec->eapd_mask);
  3894. }
  3895. static void stac92xx_free(struct hda_codec *codec)
  3896. {
  3897. struct sigmatel_spec *spec = codec->spec;
  3898. if (! spec)
  3899. return;
  3900. stac92xx_shutup(codec);
  3901. stac92xx_free_jacks(codec);
  3902. snd_array_free(&spec->events);
  3903. kfree(spec);
  3904. snd_hda_detach_beep_device(codec);
  3905. }
  3906. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  3907. unsigned int flag)
  3908. {
  3909. unsigned int old_ctl, pin_ctl;
  3910. pin_ctl = snd_hda_codec_read(codec, nid,
  3911. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  3912. if (pin_ctl & AC_PINCTL_IN_EN) {
  3913. /*
  3914. * we need to check the current set-up direction of
  3915. * shared input pins since they can be switched via
  3916. * "xxx as Output" mixer switch
  3917. */
  3918. struct sigmatel_spec *spec = codec->spec;
  3919. if (nid == spec->line_switch || nid == spec->mic_switch)
  3920. return;
  3921. }
  3922. old_ctl = pin_ctl;
  3923. /* if setting pin direction bits, clear the current
  3924. direction bits first */
  3925. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  3926. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  3927. pin_ctl |= flag;
  3928. if (old_ctl != pin_ctl)
  3929. snd_hda_codec_write_cache(codec, nid, 0,
  3930. AC_VERB_SET_PIN_WIDGET_CONTROL,
  3931. pin_ctl);
  3932. }
  3933. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  3934. unsigned int flag)
  3935. {
  3936. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  3937. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  3938. if (pin_ctl & flag)
  3939. snd_hda_codec_write_cache(codec, nid, 0,
  3940. AC_VERB_SET_PIN_WIDGET_CONTROL,
  3941. pin_ctl & ~flag);
  3942. }
  3943. static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  3944. {
  3945. if (!nid)
  3946. return 0;
  3947. return snd_hda_jack_detect(codec, nid);
  3948. }
  3949. static void stac92xx_line_out_detect(struct hda_codec *codec,
  3950. int presence)
  3951. {
  3952. struct sigmatel_spec *spec = codec->spec;
  3953. struct auto_pin_cfg *cfg = &spec->autocfg;
  3954. int i;
  3955. for (i = 0; i < cfg->line_outs; i++) {
  3956. if (presence)
  3957. break;
  3958. presence = get_pin_presence(codec, cfg->line_out_pins[i]);
  3959. if (presence) {
  3960. unsigned int pinctl;
  3961. pinctl = snd_hda_codec_read(codec,
  3962. cfg->line_out_pins[i], 0,
  3963. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3964. if (pinctl & AC_PINCTL_IN_EN)
  3965. presence = 0; /* mic- or line-input */
  3966. }
  3967. }
  3968. if (presence) {
  3969. /* disable speakers */
  3970. for (i = 0; i < cfg->speaker_outs; i++)
  3971. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  3972. AC_PINCTL_OUT_EN);
  3973. if (spec->eapd_mask && spec->eapd_switch)
  3974. stac_gpio_set(codec, spec->gpio_mask,
  3975. spec->gpio_dir, spec->gpio_data &
  3976. ~spec->eapd_mask);
  3977. } else {
  3978. /* enable speakers */
  3979. for (i = 0; i < cfg->speaker_outs; i++)
  3980. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  3981. AC_PINCTL_OUT_EN);
  3982. if (spec->eapd_mask && spec->eapd_switch)
  3983. stac_gpio_set(codec, spec->gpio_mask,
  3984. spec->gpio_dir, spec->gpio_data |
  3985. spec->eapd_mask);
  3986. }
  3987. }
  3988. /* return non-zero if the hp-pin of the given array index isn't
  3989. * a jack-detection target
  3990. */
  3991. static int no_hp_sensing(struct sigmatel_spec *spec, int i)
  3992. {
  3993. struct auto_pin_cfg *cfg = &spec->autocfg;
  3994. /* ignore sensing of shared line and mic jacks */
  3995. if (cfg->hp_pins[i] == spec->line_switch)
  3996. return 1;
  3997. if (cfg->hp_pins[i] == spec->mic_switch)
  3998. return 1;
  3999. /* ignore if the pin is set as line-out */
  4000. if (cfg->hp_pins[i] == spec->hp_switch)
  4001. return 1;
  4002. return 0;
  4003. }
  4004. static void stac92xx_hp_detect(struct hda_codec *codec)
  4005. {
  4006. struct sigmatel_spec *spec = codec->spec;
  4007. struct auto_pin_cfg *cfg = &spec->autocfg;
  4008. int i, presence;
  4009. presence = 0;
  4010. if (spec->gpio_mute)
  4011. presence = !(snd_hda_codec_read(codec, codec->afg, 0,
  4012. AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
  4013. for (i = 0; i < cfg->hp_outs; i++) {
  4014. if (presence)
  4015. break;
  4016. if (no_hp_sensing(spec, i))
  4017. continue;
  4018. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  4019. if (presence) {
  4020. unsigned int pinctl;
  4021. pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  4022. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4023. if (pinctl & AC_PINCTL_IN_EN)
  4024. presence = 0; /* mic- or line-input */
  4025. }
  4026. }
  4027. if (presence) {
  4028. /* disable lineouts */
  4029. if (spec->hp_switch)
  4030. stac92xx_reset_pinctl(codec, spec->hp_switch,
  4031. AC_PINCTL_OUT_EN);
  4032. for (i = 0; i < cfg->line_outs; i++)
  4033. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  4034. AC_PINCTL_OUT_EN);
  4035. } else {
  4036. /* enable lineouts */
  4037. if (spec->hp_switch)
  4038. stac92xx_set_pinctl(codec, spec->hp_switch,
  4039. AC_PINCTL_OUT_EN);
  4040. for (i = 0; i < cfg->line_outs; i++)
  4041. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  4042. AC_PINCTL_OUT_EN);
  4043. }
  4044. stac92xx_line_out_detect(codec, presence);
  4045. /* toggle hp outs */
  4046. for (i = 0; i < cfg->hp_outs; i++) {
  4047. unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
  4048. if (no_hp_sensing(spec, i))
  4049. continue;
  4050. if (presence)
  4051. stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
  4052. #if 0 /* FIXME */
  4053. /* Resetting the pinctl like below may lead to (a sort of) regressions
  4054. * on some devices since they use the HP pin actually for line/speaker
  4055. * outs although the default pin config shows a different pin (that is
  4056. * wrong and useless).
  4057. *
  4058. * So, it's basically a problem of default pin configs, likely a BIOS issue.
  4059. * But, disabling the code below just works around it, and I'm too tired of
  4060. * bug reports with such devices...
  4061. */
  4062. else
  4063. stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
  4064. #endif /* FIXME */
  4065. }
  4066. }
  4067. static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
  4068. int enable)
  4069. {
  4070. struct sigmatel_spec *spec = codec->spec;
  4071. unsigned int idx, val;
  4072. for (idx = 0; idx < spec->num_pwrs; idx++) {
  4073. if (spec->pwr_nids[idx] == nid)
  4074. break;
  4075. }
  4076. if (idx >= spec->num_pwrs)
  4077. return;
  4078. /* several codecs have two power down bits */
  4079. if (spec->pwr_mapping)
  4080. idx = spec->pwr_mapping[idx];
  4081. else
  4082. idx = 1 << idx;
  4083. val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
  4084. if (enable)
  4085. val &= ~idx;
  4086. else
  4087. val |= idx;
  4088. /* power down unused output ports */
  4089. snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
  4090. }
  4091. static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
  4092. {
  4093. stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
  4094. }
  4095. static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
  4096. {
  4097. struct sigmatel_spec *spec = codec->spec;
  4098. struct sigmatel_jack *jacks = spec->jacks.list;
  4099. if (jacks) {
  4100. int i;
  4101. for (i = 0; i < spec->jacks.used; i++) {
  4102. if (jacks->nid == nid) {
  4103. unsigned int pin_ctl =
  4104. snd_hda_codec_read(codec, nid,
  4105. 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
  4106. 0x00);
  4107. int type = jacks->type;
  4108. if (type == (SND_JACK_LINEOUT
  4109. | SND_JACK_HEADPHONE))
  4110. type = (pin_ctl & AC_PINCTL_HP_EN)
  4111. ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
  4112. snd_jack_report(jacks->jack,
  4113. get_pin_presence(codec, nid)
  4114. ? type : 0);
  4115. }
  4116. jacks++;
  4117. }
  4118. }
  4119. }
  4120. static void stac92xx_mic_detect(struct hda_codec *codec)
  4121. {
  4122. struct sigmatel_spec *spec = codec->spec;
  4123. struct sigmatel_mic_route *mic;
  4124. if (get_pin_presence(codec, spec->ext_mic.pin))
  4125. mic = &spec->ext_mic;
  4126. else
  4127. mic = &spec->int_mic;
  4128. if (mic->dmux_idx >= 0)
  4129. snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
  4130. AC_VERB_SET_CONNECT_SEL,
  4131. mic->dmux_idx);
  4132. if (mic->mux_idx >= 0)
  4133. snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
  4134. AC_VERB_SET_CONNECT_SEL,
  4135. mic->mux_idx);
  4136. }
  4137. static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
  4138. {
  4139. struct sigmatel_event *event = stac_get_event(codec, nid);
  4140. if (!event)
  4141. return;
  4142. codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
  4143. }
  4144. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  4145. {
  4146. struct sigmatel_spec *spec = codec->spec;
  4147. struct sigmatel_event *event;
  4148. int tag, data;
  4149. tag = (res >> 26) & 0x7f;
  4150. event = stac_get_event_from_tag(codec, tag);
  4151. if (!event)
  4152. return;
  4153. switch (event->type) {
  4154. case STAC_HP_EVENT:
  4155. case STAC_LO_EVENT:
  4156. stac92xx_hp_detect(codec);
  4157. break;
  4158. case STAC_MIC_EVENT:
  4159. stac92xx_mic_detect(codec);
  4160. break;
  4161. }
  4162. switch (event->type) {
  4163. case STAC_HP_EVENT:
  4164. case STAC_LO_EVENT:
  4165. case STAC_MIC_EVENT:
  4166. case STAC_INSERT_EVENT:
  4167. case STAC_PWR_EVENT:
  4168. if (spec->num_pwrs > 0)
  4169. stac92xx_pin_sense(codec, event->nid);
  4170. stac92xx_report_jack(codec, event->nid);
  4171. switch (codec->subsystem_id) {
  4172. case 0x103c308f:
  4173. if (event->nid == 0xb) {
  4174. int pin = AC_PINCTL_IN_EN;
  4175. if (get_pin_presence(codec, 0xa)
  4176. && get_pin_presence(codec, 0xb))
  4177. pin |= AC_PINCTL_VREF_80;
  4178. if (!get_pin_presence(codec, 0xb))
  4179. pin |= AC_PINCTL_VREF_80;
  4180. /* toggle VREF state based on mic + hp pin
  4181. * status
  4182. */
  4183. stac92xx_auto_set_pinctl(codec, 0x0a, pin);
  4184. }
  4185. }
  4186. break;
  4187. case STAC_VREF_EVENT:
  4188. data = snd_hda_codec_read(codec, codec->afg, 0,
  4189. AC_VERB_GET_GPIO_DATA, 0);
  4190. /* toggle VREF state based on GPIOx status */
  4191. snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
  4192. !!(data & (1 << event->data)));
  4193. break;
  4194. }
  4195. }
  4196. static int hp_blike_system(u32 subsystem_id);
  4197. static void set_hp_led_gpio(struct hda_codec *codec)
  4198. {
  4199. struct sigmatel_spec *spec = codec->spec;
  4200. unsigned int gpio;
  4201. if (spec->gpio_led)
  4202. return;
  4203. gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
  4204. gpio &= AC_GPIO_IO_COUNT;
  4205. if (gpio > 3)
  4206. spec->gpio_led = 0x08; /* GPIO 3 */
  4207. else
  4208. spec->gpio_led = 0x01; /* GPIO 0 */
  4209. }
  4210. /*
  4211. * This method searches for the mute LED GPIO configuration
  4212. * provided as OEM string in SMBIOS. The format of that string
  4213. * is HP_Mute_LED_P_G or HP_Mute_LED_P
  4214. * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
  4215. * that corresponds to the NOT muted state of the master volume
  4216. * and G is the index of the GPIO to use as the mute LED control (0..9)
  4217. * If _G portion is missing it is assigned based on the codec ID
  4218. *
  4219. * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
  4220. * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
  4221. *
  4222. *
  4223. * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
  4224. * SMBIOS - at least the ones I have seen do not have them - which include
  4225. * my own system (HP Pavilion dv6-1110ax) and my cousin's
  4226. * HP Pavilion dv9500t CTO.
  4227. * Need more information on whether it is true across the entire series.
  4228. * -- kunal
  4229. */
  4230. static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
  4231. {
  4232. struct sigmatel_spec *spec = codec->spec;
  4233. const struct dmi_device *dev = NULL;
  4234. if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
  4235. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
  4236. NULL, dev))) {
  4237. if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
  4238. &spec->gpio_led_polarity,
  4239. &spec->gpio_led) == 2) {
  4240. spec->gpio_led = 1 << spec->gpio_led;
  4241. return 1;
  4242. }
  4243. if (sscanf(dev->name, "HP_Mute_LED_%d",
  4244. &spec->gpio_led_polarity) == 1) {
  4245. set_hp_led_gpio(codec);
  4246. return 1;
  4247. }
  4248. }
  4249. /*
  4250. * Fallback case - if we don't find the DMI strings,
  4251. * we statically set the GPIO - if not a B-series system.
  4252. */
  4253. if (!hp_blike_system(codec->subsystem_id)) {
  4254. set_hp_led_gpio(codec);
  4255. spec->gpio_led_polarity = default_polarity;
  4256. return 1;
  4257. }
  4258. }
  4259. return 0;
  4260. }
  4261. static int hp_blike_system(u32 subsystem_id)
  4262. {
  4263. switch (subsystem_id) {
  4264. case 0x103c1520:
  4265. case 0x103c1521:
  4266. case 0x103c1523:
  4267. case 0x103c1524:
  4268. case 0x103c1525:
  4269. case 0x103c1722:
  4270. case 0x103c1723:
  4271. case 0x103c1724:
  4272. case 0x103c1725:
  4273. case 0x103c1726:
  4274. case 0x103c1727:
  4275. case 0x103c1728:
  4276. case 0x103c1729:
  4277. case 0x103c172a:
  4278. case 0x103c172b:
  4279. case 0x103c307e:
  4280. case 0x103c307f:
  4281. case 0x103c3080:
  4282. case 0x103c3081:
  4283. case 0x103c7007:
  4284. case 0x103c7008:
  4285. return 1;
  4286. }
  4287. return 0;
  4288. }
  4289. #ifdef CONFIG_PROC_FS
  4290. static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
  4291. struct hda_codec *codec, hda_nid_t nid)
  4292. {
  4293. if (nid == codec->afg)
  4294. snd_iprintf(buffer, "Power-Map: 0x%02x\n",
  4295. snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
  4296. }
  4297. static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
  4298. struct hda_codec *codec,
  4299. unsigned int verb)
  4300. {
  4301. snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
  4302. snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
  4303. }
  4304. /* stac92hd71bxx, stac92hd73xx */
  4305. static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
  4306. struct hda_codec *codec, hda_nid_t nid)
  4307. {
  4308. stac92hd_proc_hook(buffer, codec, nid);
  4309. if (nid == codec->afg)
  4310. analog_loop_proc_hook(buffer, codec, 0xfa0);
  4311. }
  4312. static void stac9205_proc_hook(struct snd_info_buffer *buffer,
  4313. struct hda_codec *codec, hda_nid_t nid)
  4314. {
  4315. if (nid == codec->afg)
  4316. analog_loop_proc_hook(buffer, codec, 0xfe0);
  4317. }
  4318. static void stac927x_proc_hook(struct snd_info_buffer *buffer,
  4319. struct hda_codec *codec, hda_nid_t nid)
  4320. {
  4321. if (nid == codec->afg)
  4322. analog_loop_proc_hook(buffer, codec, 0xfeb);
  4323. }
  4324. #else
  4325. #define stac92hd_proc_hook NULL
  4326. #define stac92hd7x_proc_hook NULL
  4327. #define stac9205_proc_hook NULL
  4328. #define stac927x_proc_hook NULL
  4329. #endif
  4330. #ifdef SND_HDA_NEEDS_RESUME
  4331. static int stac92xx_resume(struct hda_codec *codec)
  4332. {
  4333. struct sigmatel_spec *spec = codec->spec;
  4334. stac92xx_init(codec);
  4335. snd_hda_codec_resume_amp(codec);
  4336. snd_hda_codec_resume_cache(codec);
  4337. /* fake event to set up pins again to override cached values */
  4338. if (spec->hp_detect) {
  4339. if (spec->autocfg.hp_pins[0])
  4340. stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
  4341. else if (spec->autocfg.line_out_pins[0])
  4342. stac_issue_unsol_event(codec,
  4343. spec->autocfg.line_out_pins[0]);
  4344. }
  4345. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4346. /* sync mute LED */
  4347. if (spec->gpio_led && codec->patch_ops.check_power_status)
  4348. codec->patch_ops.check_power_status(codec, 0x01);
  4349. #endif
  4350. return 0;
  4351. }
  4352. /*
  4353. * using power check for controlling mute led of HP notebooks
  4354. * check for mute state only on Speakers (nid = 0x10)
  4355. *
  4356. * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
  4357. * the LED is NOT working properly !
  4358. *
  4359. * Changed name to reflect that it now works for any designated
  4360. * model, not just HP HDX.
  4361. */
  4362. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4363. static int stac92xx_hp_check_power_status(struct hda_codec *codec,
  4364. hda_nid_t nid)
  4365. {
  4366. struct sigmatel_spec *spec = codec->spec;
  4367. int i, muted = 1;
  4368. for (i = 0; i < spec->multiout.num_dacs; i++) {
  4369. nid = spec->multiout.dac_nids[i];
  4370. if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
  4371. HDA_AMP_MUTE)) {
  4372. muted = 0; /* something heard */
  4373. break;
  4374. }
  4375. }
  4376. if (muted)
  4377. spec->gpio_data &= ~spec->gpio_led; /* orange */
  4378. else
  4379. spec->gpio_data |= spec->gpio_led; /* white */
  4380. if (!spec->gpio_led_polarity) {
  4381. /* LED state is inverted on these systems */
  4382. spec->gpio_data ^= spec->gpio_led;
  4383. }
  4384. stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
  4385. return 0;
  4386. }
  4387. #endif
  4388. static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
  4389. {
  4390. stac92xx_shutup(codec);
  4391. return 0;
  4392. }
  4393. #endif
  4394. static struct hda_codec_ops stac92xx_patch_ops = {
  4395. .build_controls = stac92xx_build_controls,
  4396. .build_pcms = stac92xx_build_pcms,
  4397. .init = stac92xx_init,
  4398. .free = stac92xx_free,
  4399. .unsol_event = stac92xx_unsol_event,
  4400. #ifdef SND_HDA_NEEDS_RESUME
  4401. .suspend = stac92xx_suspend,
  4402. .resume = stac92xx_resume,
  4403. #endif
  4404. .reboot_notify = stac92xx_shutup,
  4405. };
  4406. static int patch_stac9200(struct hda_codec *codec)
  4407. {
  4408. struct sigmatel_spec *spec;
  4409. int err;
  4410. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4411. if (spec == NULL)
  4412. return -ENOMEM;
  4413. codec->no_trigger_sense = 1;
  4414. codec->spec = spec;
  4415. spec->linear_tone_beep = 1;
  4416. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  4417. spec->pin_nids = stac9200_pin_nids;
  4418. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  4419. stac9200_models,
  4420. stac9200_cfg_tbl);
  4421. if (spec->board_config < 0)
  4422. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4423. codec->chip_name);
  4424. else
  4425. stac92xx_set_config_regs(codec,
  4426. stac9200_brd_tbl[spec->board_config]);
  4427. spec->multiout.max_channels = 2;
  4428. spec->multiout.num_dacs = 1;
  4429. spec->multiout.dac_nids = stac9200_dac_nids;
  4430. spec->adc_nids = stac9200_adc_nids;
  4431. spec->mux_nids = stac9200_mux_nids;
  4432. spec->num_muxes = 1;
  4433. spec->num_dmics = 0;
  4434. spec->num_adcs = 1;
  4435. spec->num_pwrs = 0;
  4436. if (spec->board_config == STAC_9200_M4 ||
  4437. spec->board_config == STAC_9200_M4_2 ||
  4438. spec->board_config == STAC_9200_OQO)
  4439. spec->init = stac9200_eapd_init;
  4440. else
  4441. spec->init = stac9200_core_init;
  4442. spec->mixer = stac9200_mixer;
  4443. if (spec->board_config == STAC_9200_PANASONIC) {
  4444. spec->gpio_mask = spec->gpio_dir = 0x09;
  4445. spec->gpio_data = 0x00;
  4446. }
  4447. err = stac9200_parse_auto_config(codec);
  4448. if (err < 0) {
  4449. stac92xx_free(codec);
  4450. return err;
  4451. }
  4452. /* CF-74 has no headphone detection, and the driver should *NOT*
  4453. * do detection and HP/speaker toggle because the hardware does it.
  4454. */
  4455. if (spec->board_config == STAC_9200_PANASONIC)
  4456. spec->hp_detect = 0;
  4457. codec->patch_ops = stac92xx_patch_ops;
  4458. return 0;
  4459. }
  4460. static int patch_stac925x(struct hda_codec *codec)
  4461. {
  4462. struct sigmatel_spec *spec;
  4463. int err;
  4464. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4465. if (spec == NULL)
  4466. return -ENOMEM;
  4467. codec->no_trigger_sense = 1;
  4468. codec->spec = spec;
  4469. spec->linear_tone_beep = 1;
  4470. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  4471. spec->pin_nids = stac925x_pin_nids;
  4472. /* Check first for codec ID */
  4473. spec->board_config = snd_hda_check_board_codec_sid_config(codec,
  4474. STAC_925x_MODELS,
  4475. stac925x_models,
  4476. stac925x_codec_id_cfg_tbl);
  4477. /* Now checks for PCI ID, if codec ID is not found */
  4478. if (spec->board_config < 0)
  4479. spec->board_config = snd_hda_check_board_config(codec,
  4480. STAC_925x_MODELS,
  4481. stac925x_models,
  4482. stac925x_cfg_tbl);
  4483. again:
  4484. if (spec->board_config < 0)
  4485. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4486. codec->chip_name);
  4487. else
  4488. stac92xx_set_config_regs(codec,
  4489. stac925x_brd_tbl[spec->board_config]);
  4490. spec->multiout.max_channels = 2;
  4491. spec->multiout.num_dacs = 1;
  4492. spec->multiout.dac_nids = stac925x_dac_nids;
  4493. spec->adc_nids = stac925x_adc_nids;
  4494. spec->mux_nids = stac925x_mux_nids;
  4495. spec->num_muxes = 1;
  4496. spec->num_adcs = 1;
  4497. spec->num_pwrs = 0;
  4498. switch (codec->vendor_id) {
  4499. case 0x83847632: /* STAC9202 */
  4500. case 0x83847633: /* STAC9202D */
  4501. case 0x83847636: /* STAC9251 */
  4502. case 0x83847637: /* STAC9251D */
  4503. spec->num_dmics = STAC925X_NUM_DMICS;
  4504. spec->dmic_nids = stac925x_dmic_nids;
  4505. spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
  4506. spec->dmux_nids = stac925x_dmux_nids;
  4507. break;
  4508. default:
  4509. spec->num_dmics = 0;
  4510. break;
  4511. }
  4512. spec->init = stac925x_core_init;
  4513. spec->mixer = stac925x_mixer;
  4514. spec->num_caps = 1;
  4515. spec->capvols = stac925x_capvols;
  4516. spec->capsws = stac925x_capsws;
  4517. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  4518. if (!err) {
  4519. if (spec->board_config < 0) {
  4520. printk(KERN_WARNING "hda_codec: No auto-config is "
  4521. "available, default to model=ref\n");
  4522. spec->board_config = STAC_925x_REF;
  4523. goto again;
  4524. }
  4525. err = -EINVAL;
  4526. }
  4527. if (err < 0) {
  4528. stac92xx_free(codec);
  4529. return err;
  4530. }
  4531. codec->patch_ops = stac92xx_patch_ops;
  4532. return 0;
  4533. }
  4534. static int patch_stac92hd73xx(struct hda_codec *codec)
  4535. {
  4536. struct sigmatel_spec *spec;
  4537. hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
  4538. int err = 0;
  4539. int num_dacs;
  4540. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4541. if (spec == NULL)
  4542. return -ENOMEM;
  4543. codec->no_trigger_sense = 1;
  4544. codec->spec = spec;
  4545. spec->linear_tone_beep = 0;
  4546. codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
  4547. spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
  4548. spec->pin_nids = stac92hd73xx_pin_nids;
  4549. spec->board_config = snd_hda_check_board_config(codec,
  4550. STAC_92HD73XX_MODELS,
  4551. stac92hd73xx_models,
  4552. stac92hd73xx_cfg_tbl);
  4553. /* check codec subsystem id if not found */
  4554. if (spec->board_config < 0)
  4555. spec->board_config =
  4556. snd_hda_check_board_codec_sid_config(codec,
  4557. STAC_92HD73XX_MODELS, stac92hd73xx_models,
  4558. stac92hd73xx_codec_id_cfg_tbl);
  4559. again:
  4560. if (spec->board_config < 0)
  4561. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4562. codec->chip_name);
  4563. else
  4564. stac92xx_set_config_regs(codec,
  4565. stac92hd73xx_brd_tbl[spec->board_config]);
  4566. num_dacs = snd_hda_get_connections(codec, 0x0a,
  4567. conn, STAC92HD73_DAC_COUNT + 2) - 1;
  4568. if (num_dacs < 3 || num_dacs > 5) {
  4569. printk(KERN_WARNING "hda_codec: Could not determine "
  4570. "number of channels defaulting to DAC count\n");
  4571. num_dacs = STAC92HD73_DAC_COUNT;
  4572. }
  4573. spec->init = stac92hd73xx_core_init;
  4574. switch (num_dacs) {
  4575. case 0x3: /* 6 Channel */
  4576. spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
  4577. break;
  4578. case 0x4: /* 8 Channel */
  4579. spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
  4580. break;
  4581. case 0x5: /* 10 Channel */
  4582. spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
  4583. break;
  4584. }
  4585. spec->multiout.dac_nids = spec->dac_nids;
  4586. spec->aloopback_mask = 0x01;
  4587. spec->aloopback_shift = 8;
  4588. spec->digbeep_nid = 0x1c;
  4589. spec->mux_nids = stac92hd73xx_mux_nids;
  4590. spec->adc_nids = stac92hd73xx_adc_nids;
  4591. spec->dmic_nids = stac92hd73xx_dmic_nids;
  4592. spec->dmux_nids = stac92hd73xx_dmux_nids;
  4593. spec->smux_nids = stac92hd73xx_smux_nids;
  4594. spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
  4595. spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
  4596. spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
  4597. spec->num_caps = STAC92HD73XX_NUM_CAPS;
  4598. spec->capvols = stac92hd73xx_capvols;
  4599. spec->capsws = stac92hd73xx_capsws;
  4600. switch (spec->board_config) {
  4601. case STAC_DELL_EQ:
  4602. spec->init = dell_eq_core_init;
  4603. /* fallthru */
  4604. case STAC_DELL_M6_AMIC:
  4605. case STAC_DELL_M6_DMIC:
  4606. case STAC_DELL_M6_BOTH:
  4607. spec->num_smuxes = 0;
  4608. spec->eapd_switch = 0;
  4609. switch (spec->board_config) {
  4610. case STAC_DELL_M6_AMIC: /* Analog Mics */
  4611. snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
  4612. spec->num_dmics = 0;
  4613. break;
  4614. case STAC_DELL_M6_DMIC: /* Digital Mics */
  4615. snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
  4616. spec->num_dmics = 1;
  4617. break;
  4618. case STAC_DELL_M6_BOTH: /* Both */
  4619. snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
  4620. snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
  4621. spec->num_dmics = 1;
  4622. break;
  4623. }
  4624. break;
  4625. case STAC_ALIENWARE_M17X:
  4626. spec->num_dmics = STAC92HD73XX_NUM_DMICS;
  4627. spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
  4628. spec->eapd_switch = 0;
  4629. break;
  4630. default:
  4631. spec->num_dmics = STAC92HD73XX_NUM_DMICS;
  4632. spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
  4633. spec->eapd_switch = 1;
  4634. break;
  4635. }
  4636. if (spec->board_config != STAC_92HD73XX_REF) {
  4637. /* GPIO0 High = Enable EAPD */
  4638. spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
  4639. spec->gpio_data = 0x01;
  4640. }
  4641. spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
  4642. spec->pwr_nids = stac92hd73xx_pwr_nids;
  4643. err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
  4644. if (!err) {
  4645. if (spec->board_config < 0) {
  4646. printk(KERN_WARNING "hda_codec: No auto-config is "
  4647. "available, default to model=ref\n");
  4648. spec->board_config = STAC_92HD73XX_REF;
  4649. goto again;
  4650. }
  4651. err = -EINVAL;
  4652. }
  4653. if (err < 0) {
  4654. stac92xx_free(codec);
  4655. return err;
  4656. }
  4657. if (spec->board_config == STAC_92HD73XX_NO_JD)
  4658. spec->hp_detect = 0;
  4659. codec->patch_ops = stac92xx_patch_ops;
  4660. codec->proc_widget_hook = stac92hd7x_proc_hook;
  4661. return 0;
  4662. }
  4663. static int patch_stac92hd83xxx(struct hda_codec *codec)
  4664. {
  4665. struct sigmatel_spec *spec;
  4666. hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
  4667. int err;
  4668. int num_dacs;
  4669. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4670. if (spec == NULL)
  4671. return -ENOMEM;
  4672. codec->no_trigger_sense = 1;
  4673. codec->spec = spec;
  4674. spec->linear_tone_beep = 1;
  4675. codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
  4676. spec->digbeep_nid = 0x21;
  4677. spec->mux_nids = stac92hd83xxx_mux_nids;
  4678. spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
  4679. spec->adc_nids = stac92hd83xxx_adc_nids;
  4680. spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
  4681. spec->pwr_nids = stac92hd83xxx_pwr_nids;
  4682. spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
  4683. spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
  4684. spec->multiout.dac_nids = spec->dac_nids;
  4685. spec->init = stac92hd83xxx_core_init;
  4686. spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
  4687. spec->pin_nids = stac92hd83xxx_pin_nids;
  4688. spec->num_caps = STAC92HD83XXX_NUM_CAPS;
  4689. spec->capvols = stac92hd83xxx_capvols;
  4690. spec->capsws = stac92hd83xxx_capsws;
  4691. spec->board_config = snd_hda_check_board_config(codec,
  4692. STAC_92HD83XXX_MODELS,
  4693. stac92hd83xxx_models,
  4694. stac92hd83xxx_cfg_tbl);
  4695. again:
  4696. if (spec->board_config < 0)
  4697. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4698. codec->chip_name);
  4699. else
  4700. stac92xx_set_config_regs(codec,
  4701. stac92hd83xxx_brd_tbl[spec->board_config]);
  4702. switch (codec->vendor_id) {
  4703. case 0x111d7666:
  4704. case 0x111d7667:
  4705. case 0x111d7668:
  4706. case 0x111d7669:
  4707. spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
  4708. spec->pin_nids = stac92hd88xxx_pin_nids;
  4709. spec->mono_nid = 0;
  4710. spec->digbeep_nid = 0;
  4711. spec->num_pwrs = 0;
  4712. break;
  4713. case 0x111d7604:
  4714. case 0x111d76d4:
  4715. case 0x111d7605:
  4716. case 0x111d76d5:
  4717. if (spec->board_config == STAC_92HD83XXX_PWR_REF)
  4718. break;
  4719. spec->num_pwrs = 0;
  4720. break;
  4721. }
  4722. codec->patch_ops = stac92xx_patch_ops;
  4723. if (find_mute_led_gpio(codec, 0))
  4724. snd_printd("mute LED gpio %d polarity %d\n",
  4725. spec->gpio_led,
  4726. spec->gpio_led_polarity);
  4727. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4728. if (spec->gpio_led) {
  4729. spec->gpio_mask |= spec->gpio_led;
  4730. spec->gpio_dir |= spec->gpio_led;
  4731. spec->gpio_data |= spec->gpio_led;
  4732. /* register check_power_status callback. */
  4733. codec->patch_ops.check_power_status =
  4734. stac92xx_hp_check_power_status;
  4735. }
  4736. #endif
  4737. err = stac92xx_parse_auto_config(codec, 0x1d, 0);
  4738. if (!err) {
  4739. if (spec->board_config < 0) {
  4740. printk(KERN_WARNING "hda_codec: No auto-config is "
  4741. "available, default to model=ref\n");
  4742. spec->board_config = STAC_92HD83XXX_REF;
  4743. goto again;
  4744. }
  4745. err = -EINVAL;
  4746. }
  4747. if (err < 0) {
  4748. stac92xx_free(codec);
  4749. return err;
  4750. }
  4751. /* docking output support */
  4752. num_dacs = snd_hda_get_connections(codec, 0xF,
  4753. conn, STAC92HD83_DAC_COUNT + 1) - 1;
  4754. /* skip non-DAC connections */
  4755. while (num_dacs >= 0 &&
  4756. (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
  4757. != AC_WID_AUD_OUT))
  4758. num_dacs--;
  4759. /* set port E and F to select the last DAC */
  4760. if (num_dacs >= 0) {
  4761. snd_hda_codec_write_cache(codec, 0xE, 0,
  4762. AC_VERB_SET_CONNECT_SEL, num_dacs);
  4763. snd_hda_codec_write_cache(codec, 0xF, 0,
  4764. AC_VERB_SET_CONNECT_SEL, num_dacs);
  4765. }
  4766. codec->proc_widget_hook = stac92hd_proc_hook;
  4767. return 0;
  4768. }
  4769. /* get the pin connection (fixed, none, etc) */
  4770. static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
  4771. {
  4772. struct sigmatel_spec *spec = codec->spec;
  4773. unsigned int cfg;
  4774. cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
  4775. return get_defcfg_connect(cfg);
  4776. }
  4777. static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
  4778. hda_nid_t *nids, int num_nids)
  4779. {
  4780. struct sigmatel_spec *spec = codec->spec;
  4781. int idx, num;
  4782. unsigned int def_conf;
  4783. for (num = 0; num < num_nids; num++) {
  4784. for (idx = 0; idx < spec->num_pins; idx++)
  4785. if (spec->pin_nids[idx] == nids[num])
  4786. break;
  4787. if (idx >= spec->num_pins)
  4788. break;
  4789. def_conf = stac_get_defcfg_connect(codec, idx);
  4790. if (def_conf == AC_JACK_PORT_NONE)
  4791. break;
  4792. }
  4793. return num;
  4794. }
  4795. static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
  4796. hda_nid_t dig0pin)
  4797. {
  4798. struct sigmatel_spec *spec = codec->spec;
  4799. int idx;
  4800. for (idx = 0; idx < spec->num_pins; idx++)
  4801. if (spec->pin_nids[idx] == dig0pin)
  4802. break;
  4803. if ((idx + 2) >= spec->num_pins)
  4804. return 0;
  4805. /* dig1pin case */
  4806. if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
  4807. return 2;
  4808. /* dig0pin + dig2pin case */
  4809. if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
  4810. return 2;
  4811. if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
  4812. return 1;
  4813. else
  4814. return 0;
  4815. }
  4816. /* HP dv7 bass switch - GPIO5 */
  4817. #define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
  4818. static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
  4819. struct snd_ctl_elem_value *ucontrol)
  4820. {
  4821. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4822. struct sigmatel_spec *spec = codec->spec;
  4823. ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
  4824. return 0;
  4825. }
  4826. static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
  4827. struct snd_ctl_elem_value *ucontrol)
  4828. {
  4829. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  4830. struct sigmatel_spec *spec = codec->spec;
  4831. unsigned int gpio_data;
  4832. gpio_data = (spec->gpio_data & ~0x20) |
  4833. (ucontrol->value.integer.value[0] ? 0x20 : 0);
  4834. if (gpio_data == spec->gpio_data)
  4835. return 0;
  4836. spec->gpio_data = gpio_data;
  4837. stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
  4838. return 1;
  4839. }
  4840. static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
  4841. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4842. .info = stac_hp_bass_gpio_info,
  4843. .get = stac_hp_bass_gpio_get,
  4844. .put = stac_hp_bass_gpio_put,
  4845. };
  4846. static int stac_add_hp_bass_switch(struct hda_codec *codec)
  4847. {
  4848. struct sigmatel_spec *spec = codec->spec;
  4849. if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
  4850. "Bass Speaker Playback Switch", 0))
  4851. return -ENOMEM;
  4852. spec->gpio_mask |= 0x20;
  4853. spec->gpio_dir |= 0x20;
  4854. spec->gpio_data |= 0x20;
  4855. return 0;
  4856. }
  4857. static int patch_stac92hd71bxx(struct hda_codec *codec)
  4858. {
  4859. struct sigmatel_spec *spec;
  4860. struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
  4861. unsigned int pin_cfg;
  4862. int err = 0;
  4863. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4864. if (spec == NULL)
  4865. return -ENOMEM;
  4866. codec->no_trigger_sense = 1;
  4867. codec->spec = spec;
  4868. spec->linear_tone_beep = 0;
  4869. codec->patch_ops = stac92xx_patch_ops;
  4870. spec->num_pins = STAC92HD71BXX_NUM_PINS;
  4871. switch (codec->vendor_id) {
  4872. case 0x111d76b6:
  4873. case 0x111d76b7:
  4874. spec->pin_nids = stac92hd71bxx_pin_nids_4port;
  4875. break;
  4876. case 0x111d7603:
  4877. case 0x111d7608:
  4878. /* On 92HD75Bx 0x27 isn't a pin nid */
  4879. spec->num_pins--;
  4880. /* fallthrough */
  4881. default:
  4882. spec->pin_nids = stac92hd71bxx_pin_nids_6port;
  4883. }
  4884. spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
  4885. spec->board_config = snd_hda_check_board_config(codec,
  4886. STAC_92HD71BXX_MODELS,
  4887. stac92hd71bxx_models,
  4888. stac92hd71bxx_cfg_tbl);
  4889. again:
  4890. if (spec->board_config < 0)
  4891. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4892. codec->chip_name);
  4893. else
  4894. stac92xx_set_config_regs(codec,
  4895. stac92hd71bxx_brd_tbl[spec->board_config]);
  4896. if (spec->board_config != STAC_92HD71BXX_REF) {
  4897. /* GPIO0 = EAPD */
  4898. spec->gpio_mask = 0x01;
  4899. spec->gpio_dir = 0x01;
  4900. spec->gpio_data = 0x01;
  4901. }
  4902. spec->dmic_nids = stac92hd71bxx_dmic_nids;
  4903. spec->dmux_nids = stac92hd71bxx_dmux_nids;
  4904. spec->num_caps = STAC92HD71BXX_NUM_CAPS;
  4905. spec->capvols = stac92hd71bxx_capvols;
  4906. spec->capsws = stac92hd71bxx_capsws;
  4907. switch (codec->vendor_id) {
  4908. case 0x111d76b6: /* 4 Port without Analog Mixer */
  4909. case 0x111d76b7:
  4910. unmute_init++;
  4911. /* fallthru */
  4912. case 0x111d76b4: /* 6 Port without Analog Mixer */
  4913. case 0x111d76b5:
  4914. spec->init = stac92hd71bxx_core_init;
  4915. codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
  4916. spec->num_dmics = stac92hd71bxx_connected_ports(codec,
  4917. stac92hd71bxx_dmic_nids,
  4918. STAC92HD71BXX_NUM_DMICS);
  4919. break;
  4920. case 0x111d7608: /* 5 Port with Analog Mixer */
  4921. switch (spec->board_config) {
  4922. case STAC_HP_M4:
  4923. /* Enable VREF power saving on GPIO1 detect */
  4924. err = stac_add_event(spec, codec->afg,
  4925. STAC_VREF_EVENT, 0x02);
  4926. if (err < 0)
  4927. return err;
  4928. snd_hda_codec_write_cache(codec, codec->afg, 0,
  4929. AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
  4930. snd_hda_codec_write_cache(codec, codec->afg, 0,
  4931. AC_VERB_SET_UNSOLICITED_ENABLE,
  4932. AC_USRSP_EN | err);
  4933. spec->gpio_mask |= 0x02;
  4934. break;
  4935. }
  4936. if ((codec->revision_id & 0xf) == 0 ||
  4937. (codec->revision_id & 0xf) == 1)
  4938. spec->stream_delay = 40; /* 40 milliseconds */
  4939. /* no output amps */
  4940. spec->num_pwrs = 0;
  4941. /* disable VSW */
  4942. spec->init = stac92hd71bxx_core_init;
  4943. unmute_init++;
  4944. snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
  4945. snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
  4946. stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
  4947. spec->num_dmics = stac92hd71bxx_connected_ports(codec,
  4948. stac92hd71bxx_dmic_nids,
  4949. STAC92HD71BXX_NUM_DMICS - 1);
  4950. break;
  4951. case 0x111d7603: /* 6 Port with Analog Mixer */
  4952. if ((codec->revision_id & 0xf) == 1)
  4953. spec->stream_delay = 40; /* 40 milliseconds */
  4954. /* no output amps */
  4955. spec->num_pwrs = 0;
  4956. /* fallthru */
  4957. default:
  4958. spec->init = stac92hd71bxx_core_init;
  4959. codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
  4960. spec->num_dmics = stac92hd71bxx_connected_ports(codec,
  4961. stac92hd71bxx_dmic_nids,
  4962. STAC92HD71BXX_NUM_DMICS);
  4963. break;
  4964. }
  4965. if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
  4966. snd_hda_sequence_write_cache(codec, unmute_init);
  4967. /* Some HP machines seem to have unstable codec communications
  4968. * especially with ATI fglrx driver. For recovering from the
  4969. * CORB/RIRB stall, allow the BUS reset and keep always sync
  4970. */
  4971. if (spec->board_config == STAC_HP_DV5) {
  4972. codec->bus->sync_write = 1;
  4973. codec->bus->allow_bus_reset = 1;
  4974. }
  4975. spec->aloopback_ctl = stac92hd71bxx_loopback;
  4976. spec->aloopback_mask = 0x50;
  4977. spec->aloopback_shift = 0;
  4978. spec->powerdown_adcs = 1;
  4979. spec->digbeep_nid = 0x26;
  4980. spec->mux_nids = stac92hd71bxx_mux_nids;
  4981. spec->adc_nids = stac92hd71bxx_adc_nids;
  4982. spec->smux_nids = stac92hd71bxx_smux_nids;
  4983. spec->pwr_nids = stac92hd71bxx_pwr_nids;
  4984. spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
  4985. spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
  4986. spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
  4987. spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
  4988. snd_printdd("Found board config: %d\n", spec->board_config);
  4989. switch (spec->board_config) {
  4990. case STAC_HP_M4:
  4991. /* enable internal microphone */
  4992. snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
  4993. stac92xx_auto_set_pinctl(codec, 0x0e,
  4994. AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
  4995. /* fallthru */
  4996. case STAC_DELL_M4_2:
  4997. spec->num_dmics = 0;
  4998. spec->num_smuxes = 0;
  4999. spec->num_dmuxes = 0;
  5000. break;
  5001. case STAC_DELL_M4_1:
  5002. case STAC_DELL_M4_3:
  5003. spec->num_dmics = 1;
  5004. spec->num_smuxes = 0;
  5005. spec->num_dmuxes = 1;
  5006. break;
  5007. case STAC_HP_DV4_1222NR:
  5008. spec->num_dmics = 1;
  5009. /* I don't know if it needs 1 or 2 smuxes - will wait for
  5010. * bug reports to fix if needed
  5011. */
  5012. spec->num_smuxes = 1;
  5013. spec->num_dmuxes = 1;
  5014. /* fallthrough */
  5015. case STAC_HP_DV4:
  5016. spec->gpio_led = 0x01;
  5017. /* fallthrough */
  5018. case STAC_HP_DV5:
  5019. snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
  5020. stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
  5021. /* HP dv6 gives the headphone pin as a line-out. Thus we
  5022. * need to set hp_detect flag here to force to enable HP
  5023. * detection.
  5024. */
  5025. spec->hp_detect = 1;
  5026. break;
  5027. case STAC_HP_HDX:
  5028. spec->num_dmics = 1;
  5029. spec->num_dmuxes = 1;
  5030. spec->num_smuxes = 1;
  5031. spec->gpio_led = 0x08;
  5032. break;
  5033. }
  5034. if (hp_blike_system(codec->subsystem_id)) {
  5035. pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
  5036. if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
  5037. get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
  5038. get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
  5039. /* It was changed in the BIOS to just satisfy MS DTM.
  5040. * Lets turn it back into slaved HP
  5041. */
  5042. pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
  5043. | (AC_JACK_HP_OUT <<
  5044. AC_DEFCFG_DEVICE_SHIFT);
  5045. pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
  5046. | AC_DEFCFG_SEQUENCE)))
  5047. | 0x1f;
  5048. snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
  5049. }
  5050. }
  5051. if (find_mute_led_gpio(codec, 1))
  5052. snd_printd("mute LED gpio %d polarity %d\n",
  5053. spec->gpio_led,
  5054. spec->gpio_led_polarity);
  5055. #ifdef CONFIG_SND_HDA_POWER_SAVE
  5056. if (spec->gpio_led) {
  5057. spec->gpio_mask |= spec->gpio_led;
  5058. spec->gpio_dir |= spec->gpio_led;
  5059. spec->gpio_data |= spec->gpio_led;
  5060. /* register check_power_status callback. */
  5061. codec->patch_ops.check_power_status =
  5062. stac92xx_hp_check_power_status;
  5063. }
  5064. #endif
  5065. spec->multiout.dac_nids = spec->dac_nids;
  5066. err = stac92xx_parse_auto_config(codec, 0x21, 0);
  5067. if (!err) {
  5068. if (spec->board_config < 0) {
  5069. printk(KERN_WARNING "hda_codec: No auto-config is "
  5070. "available, default to model=ref\n");
  5071. spec->board_config = STAC_92HD71BXX_REF;
  5072. goto again;
  5073. }
  5074. err = -EINVAL;
  5075. }
  5076. if (err < 0) {
  5077. stac92xx_free(codec);
  5078. return err;
  5079. }
  5080. /* enable bass on HP dv7 */
  5081. if (spec->board_config == STAC_HP_DV4 ||
  5082. spec->board_config == STAC_HP_DV5) {
  5083. unsigned int cap;
  5084. cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
  5085. cap &= AC_GPIO_IO_COUNT;
  5086. if (cap >= 6)
  5087. stac_add_hp_bass_switch(codec);
  5088. }
  5089. codec->proc_widget_hook = stac92hd7x_proc_hook;
  5090. return 0;
  5091. }
  5092. static int patch_stac922x(struct hda_codec *codec)
  5093. {
  5094. struct sigmatel_spec *spec;
  5095. int err;
  5096. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5097. if (spec == NULL)
  5098. return -ENOMEM;
  5099. codec->no_trigger_sense = 1;
  5100. codec->spec = spec;
  5101. spec->linear_tone_beep = 1;
  5102. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  5103. spec->pin_nids = stac922x_pin_nids;
  5104. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  5105. stac922x_models,
  5106. stac922x_cfg_tbl);
  5107. if (spec->board_config == STAC_INTEL_MAC_AUTO) {
  5108. spec->gpio_mask = spec->gpio_dir = 0x03;
  5109. spec->gpio_data = 0x03;
  5110. /* Intel Macs have all same PCI SSID, so we need to check
  5111. * codec SSID to distinguish the exact models
  5112. */
  5113. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  5114. switch (codec->subsystem_id) {
  5115. case 0x106b0800:
  5116. spec->board_config = STAC_INTEL_MAC_V1;
  5117. break;
  5118. case 0x106b0600:
  5119. case 0x106b0700:
  5120. spec->board_config = STAC_INTEL_MAC_V2;
  5121. break;
  5122. case 0x106b0e00:
  5123. case 0x106b0f00:
  5124. case 0x106b1600:
  5125. case 0x106b1700:
  5126. case 0x106b0200:
  5127. case 0x106b1e00:
  5128. spec->board_config = STAC_INTEL_MAC_V3;
  5129. break;
  5130. case 0x106b1a00:
  5131. case 0x00000100:
  5132. spec->board_config = STAC_INTEL_MAC_V4;
  5133. break;
  5134. case 0x106b0a00:
  5135. case 0x106b2200:
  5136. spec->board_config = STAC_INTEL_MAC_V5;
  5137. break;
  5138. default:
  5139. spec->board_config = STAC_INTEL_MAC_V3;
  5140. break;
  5141. }
  5142. }
  5143. again:
  5144. if (spec->board_config < 0)
  5145. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5146. codec->chip_name);
  5147. else
  5148. stac92xx_set_config_regs(codec,
  5149. stac922x_brd_tbl[spec->board_config]);
  5150. spec->adc_nids = stac922x_adc_nids;
  5151. spec->mux_nids = stac922x_mux_nids;
  5152. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  5153. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  5154. spec->num_dmics = 0;
  5155. spec->num_pwrs = 0;
  5156. spec->init = stac922x_core_init;
  5157. spec->num_caps = STAC922X_NUM_CAPS;
  5158. spec->capvols = stac922x_capvols;
  5159. spec->capsws = stac922x_capsws;
  5160. spec->multiout.dac_nids = spec->dac_nids;
  5161. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  5162. if (!err) {
  5163. if (spec->board_config < 0) {
  5164. printk(KERN_WARNING "hda_codec: No auto-config is "
  5165. "available, default to model=ref\n");
  5166. spec->board_config = STAC_D945_REF;
  5167. goto again;
  5168. }
  5169. err = -EINVAL;
  5170. }
  5171. if (err < 0) {
  5172. stac92xx_free(codec);
  5173. return err;
  5174. }
  5175. codec->patch_ops = stac92xx_patch_ops;
  5176. /* Fix Mux capture level; max to 2 */
  5177. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  5178. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  5179. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5180. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5181. (0 << AC_AMPCAP_MUTE_SHIFT));
  5182. return 0;
  5183. }
  5184. static int patch_stac927x(struct hda_codec *codec)
  5185. {
  5186. struct sigmatel_spec *spec;
  5187. int err;
  5188. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5189. if (spec == NULL)
  5190. return -ENOMEM;
  5191. codec->no_trigger_sense = 1;
  5192. codec->spec = spec;
  5193. spec->linear_tone_beep = 1;
  5194. codec->slave_dig_outs = stac927x_slave_dig_outs;
  5195. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  5196. spec->pin_nids = stac927x_pin_nids;
  5197. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  5198. stac927x_models,
  5199. stac927x_cfg_tbl);
  5200. again:
  5201. if (spec->board_config < 0)
  5202. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5203. codec->chip_name);
  5204. else
  5205. stac92xx_set_config_regs(codec,
  5206. stac927x_brd_tbl[spec->board_config]);
  5207. spec->digbeep_nid = 0x23;
  5208. spec->adc_nids = stac927x_adc_nids;
  5209. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  5210. spec->mux_nids = stac927x_mux_nids;
  5211. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  5212. spec->smux_nids = stac927x_smux_nids;
  5213. spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
  5214. spec->spdif_labels = stac927x_spdif_labels;
  5215. spec->dac_list = stac927x_dac_nids;
  5216. spec->multiout.dac_nids = spec->dac_nids;
  5217. if (spec->board_config != STAC_D965_REF) {
  5218. /* GPIO0 High = Enable EAPD */
  5219. spec->eapd_mask = spec->gpio_mask = 0x01;
  5220. spec->gpio_dir = spec->gpio_data = 0x01;
  5221. }
  5222. switch (spec->board_config) {
  5223. case STAC_D965_3ST:
  5224. case STAC_D965_5ST:
  5225. /* GPIO0 High = Enable EAPD */
  5226. spec->num_dmics = 0;
  5227. spec->init = d965_core_init;
  5228. break;
  5229. case STAC_DELL_BIOS:
  5230. switch (codec->subsystem_id) {
  5231. case 0x10280209:
  5232. case 0x1028022e:
  5233. /* correct the device field to SPDIF out */
  5234. snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
  5235. break;
  5236. }
  5237. /* configure the analog microphone on some laptops */
  5238. snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
  5239. /* correct the front output jack as a hp out */
  5240. snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
  5241. /* correct the front input jack as a mic */
  5242. snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
  5243. /* fallthru */
  5244. case STAC_DELL_3ST:
  5245. if (codec->subsystem_id != 0x1028022f) {
  5246. /* GPIO2 High = Enable EAPD */
  5247. spec->eapd_mask = spec->gpio_mask = 0x04;
  5248. spec->gpio_dir = spec->gpio_data = 0x04;
  5249. }
  5250. spec->dmic_nids = stac927x_dmic_nids;
  5251. spec->num_dmics = STAC927X_NUM_DMICS;
  5252. spec->init = dell_3st_core_init;
  5253. spec->dmux_nids = stac927x_dmux_nids;
  5254. spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
  5255. break;
  5256. case STAC_927X_VOLKNOB:
  5257. spec->num_dmics = 0;
  5258. spec->init = stac927x_volknob_core_init;
  5259. break;
  5260. default:
  5261. spec->num_dmics = 0;
  5262. spec->init = stac927x_core_init;
  5263. break;
  5264. }
  5265. spec->num_caps = STAC927X_NUM_CAPS;
  5266. spec->capvols = stac927x_capvols;
  5267. spec->capsws = stac927x_capsws;
  5268. spec->num_pwrs = 0;
  5269. spec->aloopback_ctl = stac927x_loopback;
  5270. spec->aloopback_mask = 0x40;
  5271. spec->aloopback_shift = 0;
  5272. spec->eapd_switch = 1;
  5273. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  5274. if (!err) {
  5275. if (spec->board_config < 0) {
  5276. printk(KERN_WARNING "hda_codec: No auto-config is "
  5277. "available, default to model=ref\n");
  5278. spec->board_config = STAC_D965_REF;
  5279. goto again;
  5280. }
  5281. err = -EINVAL;
  5282. }
  5283. if (err < 0) {
  5284. stac92xx_free(codec);
  5285. return err;
  5286. }
  5287. codec->patch_ops = stac92xx_patch_ops;
  5288. codec->proc_widget_hook = stac927x_proc_hook;
  5289. /*
  5290. * !!FIXME!!
  5291. * The STAC927x seem to require fairly long delays for certain
  5292. * command sequences. With too short delays (even if the answer
  5293. * is set to RIRB properly), it results in the silence output
  5294. * on some hardwares like Dell.
  5295. *
  5296. * The below flag enables the longer delay (see get_response
  5297. * in hda_intel.c).
  5298. */
  5299. codec->bus->needs_damn_long_delay = 1;
  5300. /* no jack detecion for ref-no-jd model */
  5301. if (spec->board_config == STAC_D965_REF_NO_JD)
  5302. spec->hp_detect = 0;
  5303. return 0;
  5304. }
  5305. static int patch_stac9205(struct hda_codec *codec)
  5306. {
  5307. struct sigmatel_spec *spec;
  5308. int err;
  5309. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5310. if (spec == NULL)
  5311. return -ENOMEM;
  5312. codec->no_trigger_sense = 1;
  5313. codec->spec = spec;
  5314. spec->linear_tone_beep = 1;
  5315. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  5316. spec->pin_nids = stac9205_pin_nids;
  5317. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  5318. stac9205_models,
  5319. stac9205_cfg_tbl);
  5320. again:
  5321. if (spec->board_config < 0)
  5322. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5323. codec->chip_name);
  5324. else
  5325. stac92xx_set_config_regs(codec,
  5326. stac9205_brd_tbl[spec->board_config]);
  5327. spec->digbeep_nid = 0x23;
  5328. spec->adc_nids = stac9205_adc_nids;
  5329. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  5330. spec->mux_nids = stac9205_mux_nids;
  5331. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  5332. spec->smux_nids = stac9205_smux_nids;
  5333. spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
  5334. spec->dmic_nids = stac9205_dmic_nids;
  5335. spec->num_dmics = STAC9205_NUM_DMICS;
  5336. spec->dmux_nids = stac9205_dmux_nids;
  5337. spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
  5338. spec->num_pwrs = 0;
  5339. spec->init = stac9205_core_init;
  5340. spec->aloopback_ctl = stac9205_loopback;
  5341. spec->num_caps = STAC9205_NUM_CAPS;
  5342. spec->capvols = stac9205_capvols;
  5343. spec->capsws = stac9205_capsws;
  5344. spec->aloopback_mask = 0x40;
  5345. spec->aloopback_shift = 0;
  5346. /* Turn on/off EAPD per HP plugging */
  5347. if (spec->board_config != STAC_9205_EAPD)
  5348. spec->eapd_switch = 1;
  5349. spec->multiout.dac_nids = spec->dac_nids;
  5350. switch (spec->board_config){
  5351. case STAC_9205_DELL_M43:
  5352. /* Enable SPDIF in/out */
  5353. snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
  5354. snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
  5355. /* Enable unsol response for GPIO4/Dock HP connection */
  5356. err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
  5357. if (err < 0)
  5358. return err;
  5359. snd_hda_codec_write_cache(codec, codec->afg, 0,
  5360. AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
  5361. snd_hda_codec_write_cache(codec, codec->afg, 0,
  5362. AC_VERB_SET_UNSOLICITED_ENABLE,
  5363. AC_USRSP_EN | err);
  5364. spec->gpio_dir = 0x0b;
  5365. spec->eapd_mask = 0x01;
  5366. spec->gpio_mask = 0x1b;
  5367. spec->gpio_mute = 0x10;
  5368. /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
  5369. * GPIO3 Low = DRM
  5370. */
  5371. spec->gpio_data = 0x01;
  5372. break;
  5373. case STAC_9205_REF:
  5374. /* SPDIF-In enabled */
  5375. break;
  5376. default:
  5377. /* GPIO0 High = EAPD */
  5378. spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
  5379. spec->gpio_data = 0x01;
  5380. break;
  5381. }
  5382. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  5383. if (!err) {
  5384. if (spec->board_config < 0) {
  5385. printk(KERN_WARNING "hda_codec: No auto-config is "
  5386. "available, default to model=ref\n");
  5387. spec->board_config = STAC_9205_REF;
  5388. goto again;
  5389. }
  5390. err = -EINVAL;
  5391. }
  5392. if (err < 0) {
  5393. stac92xx_free(codec);
  5394. return err;
  5395. }
  5396. codec->patch_ops = stac92xx_patch_ops;
  5397. codec->proc_widget_hook = stac9205_proc_hook;
  5398. return 0;
  5399. }
  5400. /*
  5401. * STAC9872 hack
  5402. */
  5403. static struct hda_verb stac9872_core_init[] = {
  5404. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  5405. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  5406. {}
  5407. };
  5408. static hda_nid_t stac9872_pin_nids[] = {
  5409. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  5410. 0x11, 0x13, 0x14,
  5411. };
  5412. static hda_nid_t stac9872_adc_nids[] = {
  5413. 0x8 /*,0x6*/
  5414. };
  5415. static hda_nid_t stac9872_mux_nids[] = {
  5416. 0x15
  5417. };
  5418. static unsigned long stac9872_capvols[] = {
  5419. HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
  5420. };
  5421. #define stac9872_capsws stac9872_capvols
  5422. static unsigned int stac9872_vaio_pin_configs[9] = {
  5423. 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
  5424. 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
  5425. 0x90a7013e
  5426. };
  5427. static const char *stac9872_models[STAC_9872_MODELS] = {
  5428. [STAC_9872_AUTO] = "auto",
  5429. [STAC_9872_VAIO] = "vaio",
  5430. };
  5431. static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
  5432. [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
  5433. };
  5434. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  5435. SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
  5436. "Sony VAIO F/S", STAC_9872_VAIO),
  5437. {} /* terminator */
  5438. };
  5439. static int patch_stac9872(struct hda_codec *codec)
  5440. {
  5441. struct sigmatel_spec *spec;
  5442. int err;
  5443. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  5444. if (spec == NULL)
  5445. return -ENOMEM;
  5446. codec->no_trigger_sense = 1;
  5447. codec->spec = spec;
  5448. spec->linear_tone_beep = 1;
  5449. spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
  5450. spec->pin_nids = stac9872_pin_nids;
  5451. spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  5452. stac9872_models,
  5453. stac9872_cfg_tbl);
  5454. if (spec->board_config < 0)
  5455. snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  5456. codec->chip_name);
  5457. else
  5458. stac92xx_set_config_regs(codec,
  5459. stac9872_brd_tbl[spec->board_config]);
  5460. spec->multiout.dac_nids = spec->dac_nids;
  5461. spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
  5462. spec->adc_nids = stac9872_adc_nids;
  5463. spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
  5464. spec->mux_nids = stac9872_mux_nids;
  5465. spec->init = stac9872_core_init;
  5466. spec->num_caps = 1;
  5467. spec->capvols = stac9872_capvols;
  5468. spec->capsws = stac9872_capsws;
  5469. err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
  5470. if (err < 0) {
  5471. stac92xx_free(codec);
  5472. return -EINVAL;
  5473. }
  5474. spec->input_mux = &spec->private_imux;
  5475. codec->patch_ops = stac92xx_patch_ops;
  5476. return 0;
  5477. }
  5478. /*
  5479. * patch entries
  5480. */
  5481. static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  5482. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  5483. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  5484. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  5485. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  5486. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  5487. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  5488. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  5489. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  5490. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  5491. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  5492. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  5493. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  5494. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  5495. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  5496. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  5497. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  5498. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  5499. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  5500. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  5501. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  5502. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  5503. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  5504. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  5505. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  5506. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  5507. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  5508. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  5509. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  5510. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  5511. { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
  5512. { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
  5513. /* The following does not take into account .id=0x83847661 when subsys =
  5514. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  5515. * currently not fully supported.
  5516. */
  5517. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  5518. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  5519. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  5520. { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
  5521. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  5522. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  5523. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  5524. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  5525. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  5526. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  5527. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  5528. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  5529. { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
  5530. { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
  5531. { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
  5532. { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
  5533. { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
  5534. { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
  5535. { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
  5536. { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
  5537. { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
  5538. { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
  5539. { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
  5540. { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
  5541. { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
  5542. { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
  5543. { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
  5544. { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
  5545. { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
  5546. { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
  5547. { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
  5548. { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
  5549. { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
  5550. {} /* terminator */
  5551. };
  5552. MODULE_ALIAS("snd-hda-codec-id:8384*");
  5553. MODULE_ALIAS("snd-hda-codec-id:111d*");
  5554. MODULE_LICENSE("GPL");
  5555. MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
  5556. static struct hda_codec_preset_list sigmatel_list = {
  5557. .preset = snd_hda_preset_sigmatel,
  5558. .owner = THIS_MODULE,
  5559. };
  5560. static int __init patch_sigmatel_init(void)
  5561. {
  5562. return snd_hda_add_codec_preset(&sigmatel_list);
  5563. }
  5564. static void __exit patch_sigmatel_exit(void)
  5565. {
  5566. snd_hda_delete_codec_preset(&sigmatel_list);
  5567. }
  5568. module_init(patch_sigmatel_init)
  5569. module_exit(patch_sigmatel_exit)