patch_cirrus.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /*
  2. * HD audio interface patch for Cirrus Logic CS420x chip
  3. *
  4. * Copyright (c) 2009 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This driver is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This driver is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/slab.h>
  22. #include <linux/pci.h>
  23. #include <linux/module.h>
  24. #include <sound/core.h>
  25. #include <sound/tlv.h>
  26. #include "hda_codec.h"
  27. #include "hda_local.h"
  28. #include "hda_auto_parser.h"
  29. #include "hda_jack.h"
  30. #include "hda_generic.h"
  31. /*
  32. */
  33. struct cs_spec {
  34. struct hda_gen_spec gen;
  35. unsigned int gpio_mask;
  36. unsigned int gpio_dir;
  37. unsigned int gpio_data;
  38. unsigned int gpio_eapd_hp; /* EAPD GPIO bit for headphones */
  39. unsigned int gpio_eapd_speaker; /* EAPD GPIO bit for speakers */
  40. /* CS421x */
  41. unsigned int spdif_detect:1;
  42. unsigned int spdif_present:1;
  43. unsigned int sense_b:1;
  44. hda_nid_t vendor_nid;
  45. /* for MBP SPDIF control */
  46. int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
  47. struct snd_ctl_elem_value *ucontrol);
  48. };
  49. /* available models with CS420x */
  50. enum {
  51. CS420X_MBP53,
  52. CS420X_MBP55,
  53. CS420X_IMAC27,
  54. CS420X_GPIO_13,
  55. CS420X_GPIO_23,
  56. CS420X_MBP101,
  57. CS420X_MBP81,
  58. CS420X_MBA42,
  59. CS420X_AUTO,
  60. /* aliases */
  61. CS420X_IMAC27_122 = CS420X_GPIO_23,
  62. CS420X_APPLE = CS420X_GPIO_13,
  63. };
  64. /* CS421x boards */
  65. enum {
  66. CS421X_CDB4210,
  67. CS421X_SENSE_B,
  68. CS421X_STUMPY,
  69. };
  70. /* Vendor-specific processing widget */
  71. #define CS420X_VENDOR_NID 0x11
  72. #define CS_DIG_OUT1_PIN_NID 0x10
  73. #define CS_DIG_OUT2_PIN_NID 0x15
  74. #define CS_DMIC1_PIN_NID 0x0e
  75. #define CS_DMIC2_PIN_NID 0x12
  76. /* coef indices */
  77. #define IDX_SPDIF_STAT 0x0000
  78. #define IDX_SPDIF_CTL 0x0001
  79. #define IDX_ADC_CFG 0x0002
  80. /* SZC bitmask, 4 modes below:
  81. * 0 = immediate,
  82. * 1 = digital immediate, analog zero-cross
  83. * 2 = digtail & analog soft-ramp
  84. * 3 = digital soft-ramp, analog zero-cross
  85. */
  86. #define CS_COEF_ADC_SZC_MASK (3 << 0)
  87. #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
  88. #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
  89. /* PGA mode: 0 = differential, 1 = signle-ended */
  90. #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
  91. #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
  92. #define IDX_DAC_CFG 0x0003
  93. /* SZC bitmask, 4 modes below:
  94. * 0 = Immediate
  95. * 1 = zero-cross
  96. * 2 = soft-ramp
  97. * 3 = soft-ramp on zero-cross
  98. */
  99. #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
  100. #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
  101. #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
  102. #define IDX_BEEP_CFG 0x0004
  103. /* 0x0008 - test reg key */
  104. /* 0x0009 - 0x0014 -> 12 test regs */
  105. /* 0x0015 - visibility reg */
  106. /* Cirrus Logic CS4208 */
  107. #define CS4208_VENDOR_NID 0x24
  108. /*
  109. * Cirrus Logic CS4210
  110. *
  111. * 1 DAC => HP(sense) / Speakers,
  112. * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
  113. * 1 SPDIF OUT => SPDIF Trasmitter(sense)
  114. */
  115. #define CS4210_DAC_NID 0x02
  116. #define CS4210_ADC_NID 0x03
  117. #define CS4210_VENDOR_NID 0x0B
  118. #define CS421X_DMIC_PIN_NID 0x09 /* Port E */
  119. #define CS421X_SPDIF_PIN_NID 0x0A /* Port H */
  120. #define CS421X_IDX_DEV_CFG 0x01
  121. #define CS421X_IDX_ADC_CFG 0x02
  122. #define CS421X_IDX_DAC_CFG 0x03
  123. #define CS421X_IDX_SPK_CTL 0x04
  124. #define SPDIF_EVENT 0x04
  125. /* Cirrus Logic CS4213 is like CS4210 but does not have SPDIF input/output */
  126. #define CS4213_VENDOR_NID 0x09
  127. static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
  128. {
  129. struct cs_spec *spec = codec->spec;
  130. snd_hda_codec_write(codec, spec->vendor_nid, 0,
  131. AC_VERB_SET_COEF_INDEX, idx);
  132. return snd_hda_codec_read(codec, spec->vendor_nid, 0,
  133. AC_VERB_GET_PROC_COEF, 0);
  134. }
  135. static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
  136. unsigned int coef)
  137. {
  138. struct cs_spec *spec = codec->spec;
  139. snd_hda_codec_write(codec, spec->vendor_nid, 0,
  140. AC_VERB_SET_COEF_INDEX, idx);
  141. snd_hda_codec_write(codec, spec->vendor_nid, 0,
  142. AC_VERB_SET_PROC_COEF, coef);
  143. }
  144. /*
  145. * auto-mute and auto-mic switching
  146. * CS421x auto-output redirecting
  147. * HP/SPK/SPDIF
  148. */
  149. static void cs_automute(struct hda_codec *codec)
  150. {
  151. struct cs_spec *spec = codec->spec;
  152. /* mute HPs if spdif jack (SENSE_B) is present */
  153. spec->gen.master_mute = !!(spec->spdif_present && spec->sense_b);
  154. snd_hda_gen_update_outputs(codec);
  155. if (spec->gpio_eapd_hp || spec->gpio_eapd_speaker) {
  156. spec->gpio_data = spec->gen.hp_jack_present ?
  157. spec->gpio_eapd_hp : spec->gpio_eapd_speaker;
  158. snd_hda_codec_write(codec, 0x01, 0,
  159. AC_VERB_SET_GPIO_DATA, spec->gpio_data);
  160. }
  161. }
  162. static bool is_active_pin(struct hda_codec *codec, hda_nid_t nid)
  163. {
  164. unsigned int val;
  165. val = snd_hda_codec_get_pincfg(codec, nid);
  166. return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
  167. }
  168. static void init_input_coef(struct hda_codec *codec)
  169. {
  170. struct cs_spec *spec = codec->spec;
  171. unsigned int coef;
  172. /* CS420x has multiple ADC, CS421x has single ADC */
  173. if (spec->vendor_nid == CS420X_VENDOR_NID) {
  174. coef = cs_vendor_coef_get(codec, IDX_BEEP_CFG);
  175. if (is_active_pin(codec, CS_DMIC2_PIN_NID))
  176. coef |= 1 << 4; /* DMIC2 2 chan on, GPIO1 off */
  177. if (is_active_pin(codec, CS_DMIC1_PIN_NID))
  178. coef |= 1 << 3; /* DMIC1 2 chan on, GPIO0 off
  179. * No effect if SPDIF_OUT2 is
  180. * selected in IDX_SPDIF_CTL.
  181. */
  182. cs_vendor_coef_set(codec, IDX_BEEP_CFG, coef);
  183. }
  184. }
  185. static const struct hda_verb cs_coef_init_verbs[] = {
  186. {0x11, AC_VERB_SET_PROC_STATE, 1},
  187. {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
  188. {0x11, AC_VERB_SET_PROC_COEF,
  189. (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
  190. | 0x0040 /* Mute DACs on FIFO error */
  191. | 0x1000 /* Enable DACs High Pass Filter */
  192. | 0x0400 /* Disable Coefficient Auto increment */
  193. )},
  194. /* ADC1/2 - Digital and Analog Soft Ramp */
  195. {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
  196. {0x11, AC_VERB_SET_PROC_COEF, 0x000a},
  197. /* Beep */
  198. {0x11, AC_VERB_SET_COEF_INDEX, IDX_BEEP_CFG},
  199. {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
  200. {} /* terminator */
  201. };
  202. static const struct hda_verb cs4208_coef_init_verbs[] = {
  203. {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
  204. {0x24, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
  205. {0x24, AC_VERB_SET_COEF_INDEX, 0x0033},
  206. {0x24, AC_VERB_SET_PROC_COEF, 0x0001}, /* A1 ICS */
  207. {0x24, AC_VERB_SET_COEF_INDEX, 0x0034},
  208. {0x24, AC_VERB_SET_PROC_COEF, 0x1C01}, /* A1 Enable, A Thresh = 300mV */
  209. {} /* terminator */
  210. };
  211. /* Errata: CS4207 rev C0/C1/C2 Silicon
  212. *
  213. * http://www.cirrus.com/en/pubs/errata/ER880C3.pdf
  214. *
  215. * 6. At high temperature (TA > +85°C), the digital supply current (IVD)
  216. * may be excessive (up to an additional 200 μA), which is most easily
  217. * observed while the part is being held in reset (RESET# active low).
  218. *
  219. * Root Cause: At initial powerup of the device, the logic that drives
  220. * the clock and write enable to the S/PDIF SRC RAMs is not properly
  221. * initialized.
  222. * Certain random patterns will cause a steady leakage current in those
  223. * RAM cells. The issue will resolve once the SRCs are used (turned on).
  224. *
  225. * Workaround: The following verb sequence briefly turns on the S/PDIF SRC
  226. * blocks, which will alleviate the issue.
  227. */
  228. static const struct hda_verb cs_errata_init_verbs[] = {
  229. {0x01, AC_VERB_SET_POWER_STATE, 0x00}, /* AFG: D0 */
  230. {0x11, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
  231. {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
  232. {0x11, AC_VERB_SET_PROC_COEF, 0x9999},
  233. {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
  234. {0x11, AC_VERB_SET_PROC_COEF, 0xa412},
  235. {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
  236. {0x11, AC_VERB_SET_PROC_COEF, 0x0009},
  237. {0x07, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Rx: D0 */
  238. {0x08, AC_VERB_SET_POWER_STATE, 0x00}, /* S/PDIF Tx: D0 */
  239. {0x11, AC_VERB_SET_COEF_INDEX, 0x0017},
  240. {0x11, AC_VERB_SET_PROC_COEF, 0x2412},
  241. {0x11, AC_VERB_SET_COEF_INDEX, 0x0008},
  242. {0x11, AC_VERB_SET_PROC_COEF, 0x0000},
  243. {0x11, AC_VERB_SET_COEF_INDEX, 0x0001},
  244. {0x11, AC_VERB_SET_PROC_COEF, 0x0008},
  245. {0x11, AC_VERB_SET_PROC_STATE, 0x00},
  246. #if 0 /* Don't to set to D3 as we are in power-up sequence */
  247. {0x07, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Rx: D3 */
  248. {0x08, AC_VERB_SET_POWER_STATE, 0x03}, /* S/PDIF Tx: D3 */
  249. /*{0x01, AC_VERB_SET_POWER_STATE, 0x03},*/ /* AFG: D3 This is already handled */
  250. #endif
  251. {} /* terminator */
  252. };
  253. /* SPDIF setup */
  254. static void init_digital_coef(struct hda_codec *codec)
  255. {
  256. unsigned int coef;
  257. coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
  258. coef |= 0x0008; /* Replace with mute on error */
  259. if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
  260. coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
  261. * SPDIF_OUT2 is shared with GPIO1 and
  262. * DMIC_SDA2.
  263. */
  264. cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
  265. }
  266. static int cs_init(struct hda_codec *codec)
  267. {
  268. struct cs_spec *spec = codec->spec;
  269. if (spec->vendor_nid == CS420X_VENDOR_NID) {
  270. /* init_verb sequence for C0/C1/C2 errata*/
  271. snd_hda_sequence_write(codec, cs_errata_init_verbs);
  272. snd_hda_sequence_write(codec, cs_coef_init_verbs);
  273. } else if (spec->vendor_nid == CS4208_VENDOR_NID) {
  274. snd_hda_sequence_write(codec, cs4208_coef_init_verbs);
  275. }
  276. snd_hda_gen_init(codec);
  277. if (spec->gpio_mask) {
  278. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
  279. spec->gpio_mask);
  280. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
  281. spec->gpio_dir);
  282. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  283. spec->gpio_data);
  284. }
  285. if (spec->vendor_nid == CS420X_VENDOR_NID) {
  286. init_input_coef(codec);
  287. init_digital_coef(codec);
  288. }
  289. return 0;
  290. }
  291. static int cs_build_controls(struct hda_codec *codec)
  292. {
  293. int err;
  294. err = snd_hda_gen_build_controls(codec);
  295. if (err < 0)
  296. return err;
  297. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
  298. return 0;
  299. }
  300. #define cs_free snd_hda_gen_free
  301. static const struct hda_codec_ops cs_patch_ops = {
  302. .build_controls = cs_build_controls,
  303. .build_pcms = snd_hda_gen_build_pcms,
  304. .init = cs_init,
  305. .free = cs_free,
  306. .unsol_event = snd_hda_jack_unsol_event,
  307. };
  308. static int cs_parse_auto_config(struct hda_codec *codec)
  309. {
  310. struct cs_spec *spec = codec->spec;
  311. int err;
  312. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
  313. if (err < 0)
  314. return err;
  315. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  316. if (err < 0)
  317. return err;
  318. return 0;
  319. }
  320. static const struct hda_model_fixup cs420x_models[] = {
  321. { .id = CS420X_MBP53, .name = "mbp53" },
  322. { .id = CS420X_MBP55, .name = "mbp55" },
  323. { .id = CS420X_IMAC27, .name = "imac27" },
  324. { .id = CS420X_IMAC27_122, .name = "imac27_122" },
  325. { .id = CS420X_APPLE, .name = "apple" },
  326. { .id = CS420X_MBP101, .name = "mbp101" },
  327. { .id = CS420X_MBP81, .name = "mbp81" },
  328. { .id = CS420X_MBA42, .name = "mba42" },
  329. {}
  330. };
  331. static const struct snd_pci_quirk cs420x_fixup_tbl[] = {
  332. SND_PCI_QUIRK(0x10de, 0x0ac0, "MacBookPro 5,3", CS420X_MBP53),
  333. SND_PCI_QUIRK(0x10de, 0x0d94, "MacBookAir 3,1(2)", CS420X_MBP55),
  334. SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
  335. SND_PCI_QUIRK(0x10de, 0xcb89, "MacBookPro 7,1", CS420X_MBP55),
  336. /* this conflicts with too many other models */
  337. /*SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),*/
  338. /* codec SSID */
  339. SND_PCI_QUIRK(0x106b, 0x1c00, "MacBookPro 8,1", CS420X_MBP81),
  340. SND_PCI_QUIRK(0x106b, 0x2000, "iMac 12,2", CS420X_IMAC27_122),
  341. SND_PCI_QUIRK(0x106b, 0x2800, "MacBookPro 10,1", CS420X_MBP101),
  342. SND_PCI_QUIRK(0x106b, 0x5b00, "MacBookAir 4,2", CS420X_MBA42),
  343. SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS420X_APPLE),
  344. {} /* terminator */
  345. };
  346. static const struct hda_pintbl mbp53_pincfgs[] = {
  347. { 0x09, 0x012b4050 },
  348. { 0x0a, 0x90100141 },
  349. { 0x0b, 0x90100140 },
  350. { 0x0c, 0x018b3020 },
  351. { 0x0d, 0x90a00110 },
  352. { 0x0e, 0x400000f0 },
  353. { 0x0f, 0x01cbe030 },
  354. { 0x10, 0x014be060 },
  355. { 0x12, 0x400000f0 },
  356. { 0x15, 0x400000f0 },
  357. {} /* terminator */
  358. };
  359. static const struct hda_pintbl mbp55_pincfgs[] = {
  360. { 0x09, 0x012b4030 },
  361. { 0x0a, 0x90100121 },
  362. { 0x0b, 0x90100120 },
  363. { 0x0c, 0x400000f0 },
  364. { 0x0d, 0x90a00110 },
  365. { 0x0e, 0x400000f0 },
  366. { 0x0f, 0x400000f0 },
  367. { 0x10, 0x014be040 },
  368. { 0x12, 0x400000f0 },
  369. { 0x15, 0x400000f0 },
  370. {} /* terminator */
  371. };
  372. static const struct hda_pintbl imac27_pincfgs[] = {
  373. { 0x09, 0x012b4050 },
  374. { 0x0a, 0x90100140 },
  375. { 0x0b, 0x90100142 },
  376. { 0x0c, 0x018b3020 },
  377. { 0x0d, 0x90a00110 },
  378. { 0x0e, 0x400000f0 },
  379. { 0x0f, 0x01cbe030 },
  380. { 0x10, 0x014be060 },
  381. { 0x12, 0x01ab9070 },
  382. { 0x15, 0x400000f0 },
  383. {} /* terminator */
  384. };
  385. static const struct hda_pintbl mbp101_pincfgs[] = {
  386. { 0x0d, 0x40ab90f0 },
  387. { 0x0e, 0x90a600f0 },
  388. { 0x12, 0x50a600f0 },
  389. {} /* terminator */
  390. };
  391. static const struct hda_pintbl mba42_pincfgs[] = {
  392. { 0x09, 0x012b4030 }, /* HP */
  393. { 0x0a, 0x400000f0 },
  394. { 0x0b, 0x90100120 }, /* speaker */
  395. { 0x0c, 0x400000f0 },
  396. { 0x0d, 0x90a00110 }, /* mic */
  397. { 0x0e, 0x400000f0 },
  398. { 0x0f, 0x400000f0 },
  399. { 0x10, 0x400000f0 },
  400. { 0x12, 0x400000f0 },
  401. { 0x15, 0x400000f0 },
  402. {} /* terminator */
  403. };
  404. static const struct hda_pintbl mba6_pincfgs[] = {
  405. { 0x10, 0x032120f0 }, /* HP */
  406. { 0x11, 0x500000f0 },
  407. { 0x12, 0x90100010 }, /* Speaker */
  408. { 0x13, 0x500000f0 },
  409. { 0x14, 0x500000f0 },
  410. { 0x15, 0x770000f0 },
  411. { 0x16, 0x770000f0 },
  412. { 0x17, 0x430000f0 },
  413. { 0x18, 0x43ab9030 }, /* Mic */
  414. { 0x19, 0x770000f0 },
  415. { 0x1a, 0x770000f0 },
  416. { 0x1b, 0x770000f0 },
  417. { 0x1c, 0x90a00090 },
  418. { 0x1d, 0x500000f0 },
  419. { 0x1e, 0x500000f0 },
  420. { 0x1f, 0x500000f0 },
  421. { 0x20, 0x500000f0 },
  422. { 0x21, 0x430000f0 },
  423. { 0x22, 0x430000f0 },
  424. {} /* terminator */
  425. };
  426. static void cs420x_fixup_gpio_13(struct hda_codec *codec,
  427. const struct hda_fixup *fix, int action)
  428. {
  429. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  430. struct cs_spec *spec = codec->spec;
  431. spec->gpio_eapd_hp = 2; /* GPIO1 = headphones */
  432. spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
  433. spec->gpio_mask = spec->gpio_dir =
  434. spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
  435. }
  436. }
  437. static void cs420x_fixup_gpio_23(struct hda_codec *codec,
  438. const struct hda_fixup *fix, int action)
  439. {
  440. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  441. struct cs_spec *spec = codec->spec;
  442. spec->gpio_eapd_hp = 4; /* GPIO2 = headphones */
  443. spec->gpio_eapd_speaker = 8; /* GPIO3 = speakers */
  444. spec->gpio_mask = spec->gpio_dir =
  445. spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
  446. }
  447. }
  448. static const struct hda_fixup cs420x_fixups[] = {
  449. [CS420X_MBP53] = {
  450. .type = HDA_FIXUP_PINS,
  451. .v.pins = mbp53_pincfgs,
  452. .chained = true,
  453. .chain_id = CS420X_APPLE,
  454. },
  455. [CS420X_MBP55] = {
  456. .type = HDA_FIXUP_PINS,
  457. .v.pins = mbp55_pincfgs,
  458. .chained = true,
  459. .chain_id = CS420X_GPIO_13,
  460. },
  461. [CS420X_IMAC27] = {
  462. .type = HDA_FIXUP_PINS,
  463. .v.pins = imac27_pincfgs,
  464. .chained = true,
  465. .chain_id = CS420X_GPIO_13,
  466. },
  467. [CS420X_GPIO_13] = {
  468. .type = HDA_FIXUP_FUNC,
  469. .v.func = cs420x_fixup_gpio_13,
  470. },
  471. [CS420X_GPIO_23] = {
  472. .type = HDA_FIXUP_FUNC,
  473. .v.func = cs420x_fixup_gpio_23,
  474. },
  475. [CS420X_MBP101] = {
  476. .type = HDA_FIXUP_PINS,
  477. .v.pins = mbp101_pincfgs,
  478. .chained = true,
  479. .chain_id = CS420X_GPIO_13,
  480. },
  481. [CS420X_MBP81] = {
  482. .type = HDA_FIXUP_VERBS,
  483. .v.verbs = (const struct hda_verb[]) {
  484. /* internal mic ADC2: right only, single ended */
  485. {0x11, AC_VERB_SET_COEF_INDEX, IDX_ADC_CFG},
  486. {0x11, AC_VERB_SET_PROC_COEF, 0x102a},
  487. {}
  488. },
  489. .chained = true,
  490. .chain_id = CS420X_GPIO_13,
  491. },
  492. [CS420X_MBA42] = {
  493. .type = HDA_FIXUP_PINS,
  494. .v.pins = mba42_pincfgs,
  495. .chained = true,
  496. .chain_id = CS420X_GPIO_13,
  497. },
  498. };
  499. static struct cs_spec *cs_alloc_spec(struct hda_codec *codec, int vendor_nid)
  500. {
  501. struct cs_spec *spec;
  502. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  503. if (!spec)
  504. return NULL;
  505. codec->spec = spec;
  506. spec->vendor_nid = vendor_nid;
  507. snd_hda_gen_spec_init(&spec->gen);
  508. return spec;
  509. }
  510. static int patch_cs420x(struct hda_codec *codec)
  511. {
  512. struct cs_spec *spec;
  513. int err;
  514. spec = cs_alloc_spec(codec, CS420X_VENDOR_NID);
  515. if (!spec)
  516. return -ENOMEM;
  517. spec->gen.automute_hook = cs_automute;
  518. snd_hda_pick_fixup(codec, cs420x_models, cs420x_fixup_tbl,
  519. cs420x_fixups);
  520. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  521. err = cs_parse_auto_config(codec);
  522. if (err < 0)
  523. goto error;
  524. codec->patch_ops = cs_patch_ops;
  525. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  526. return 0;
  527. error:
  528. cs_free(codec);
  529. return err;
  530. }
  531. /*
  532. * CS4208 support:
  533. * Its layout is no longer compatible with CS4206/CS4207
  534. */
  535. enum {
  536. CS4208_MAC_AUTO,
  537. CS4208_MBA6,
  538. CS4208_MBP11,
  539. CS4208_GPIO0,
  540. };
  541. static const struct hda_model_fixup cs4208_models[] = {
  542. { .id = CS4208_GPIO0, .name = "gpio0" },
  543. { .id = CS4208_MBA6, .name = "mba6" },
  544. { .id = CS4208_MBP11, .name = "mbp11" },
  545. {}
  546. };
  547. static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
  548. SND_PCI_QUIRK_VENDOR(0x106b, "Apple", CS4208_MAC_AUTO),
  549. {} /* terminator */
  550. };
  551. /* codec SSID matching */
  552. static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
  553. SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
  554. SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
  555. SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
  556. {} /* terminator */
  557. };
  558. static void cs4208_fixup_gpio0(struct hda_codec *codec,
  559. const struct hda_fixup *fix, int action)
  560. {
  561. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  562. struct cs_spec *spec = codec->spec;
  563. spec->gpio_eapd_hp = 0;
  564. spec->gpio_eapd_speaker = 1;
  565. spec->gpio_mask = spec->gpio_dir =
  566. spec->gpio_eapd_hp | spec->gpio_eapd_speaker;
  567. }
  568. }
  569. static const struct hda_fixup cs4208_fixups[];
  570. /* remap the fixup from codec SSID and apply it */
  571. static void cs4208_fixup_mac(struct hda_codec *codec,
  572. const struct hda_fixup *fix, int action)
  573. {
  574. if (action != HDA_FIXUP_ACT_PRE_PROBE)
  575. return;
  576. snd_hda_pick_fixup(codec, NULL, cs4208_mac_fixup_tbl, cs4208_fixups);
  577. if (codec->fixup_id < 0 || codec->fixup_id == CS4208_MAC_AUTO)
  578. codec->fixup_id = CS4208_GPIO0; /* default fixup */
  579. snd_hda_apply_fixup(codec, action);
  580. }
  581. static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
  582. struct snd_ctl_elem_value *ucontrol)
  583. {
  584. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  585. struct cs_spec *spec = codec->spec;
  586. hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
  587. int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
  588. snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
  589. return spec->spdif_sw_put(kcontrol, ucontrol);
  590. }
  591. /* hook the SPDIF switch */
  592. static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
  593. const struct hda_fixup *fix, int action)
  594. {
  595. if (action == HDA_FIXUP_ACT_BUILD) {
  596. struct cs_spec *spec = codec->spec;
  597. struct snd_kcontrol *kctl;
  598. if (!spec->gen.autocfg.dig_out_pins[0])
  599. return;
  600. kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
  601. if (!kctl)
  602. return;
  603. spec->spdif_sw_put = kctl->put;
  604. kctl->put = cs4208_spdif_sw_put;
  605. }
  606. }
  607. static const struct hda_fixup cs4208_fixups[] = {
  608. [CS4208_MBA6] = {
  609. .type = HDA_FIXUP_PINS,
  610. .v.pins = mba6_pincfgs,
  611. .chained = true,
  612. .chain_id = CS4208_GPIO0,
  613. },
  614. [CS4208_MBP11] = {
  615. .type = HDA_FIXUP_FUNC,
  616. .v.func = cs4208_fixup_spdif_switch,
  617. .chained = true,
  618. .chain_id = CS4208_GPIO0,
  619. },
  620. [CS4208_GPIO0] = {
  621. .type = HDA_FIXUP_FUNC,
  622. .v.func = cs4208_fixup_gpio0,
  623. },
  624. [CS4208_MAC_AUTO] = {
  625. .type = HDA_FIXUP_FUNC,
  626. .v.func = cs4208_fixup_mac,
  627. },
  628. };
  629. /* correct the 0dB offset of input pins */
  630. static void cs4208_fix_amp_caps(struct hda_codec *codec, hda_nid_t adc)
  631. {
  632. unsigned int caps;
  633. caps = query_amp_caps(codec, adc, HDA_INPUT);
  634. caps &= ~(AC_AMPCAP_OFFSET);
  635. caps |= 0x02;
  636. snd_hda_override_amp_caps(codec, adc, HDA_INPUT, caps);
  637. }
  638. static int patch_cs4208(struct hda_codec *codec)
  639. {
  640. struct cs_spec *spec;
  641. int err;
  642. spec = cs_alloc_spec(codec, CS4208_VENDOR_NID);
  643. if (!spec)
  644. return -ENOMEM;
  645. spec->gen.automute_hook = cs_automute;
  646. /* exclude NID 0x10 (HP) from output volumes due to different steps */
  647. spec->gen.out_vol_mask = 1ULL << 0x10;
  648. snd_hda_pick_fixup(codec, cs4208_models, cs4208_fixup_tbl,
  649. cs4208_fixups);
  650. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  651. snd_hda_override_wcaps(codec, 0x18,
  652. get_wcaps(codec, 0x18) | AC_WCAP_STEREO);
  653. cs4208_fix_amp_caps(codec, 0x18);
  654. cs4208_fix_amp_caps(codec, 0x1b);
  655. cs4208_fix_amp_caps(codec, 0x1c);
  656. err = cs_parse_auto_config(codec);
  657. if (err < 0)
  658. goto error;
  659. codec->patch_ops = cs_patch_ops;
  660. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  661. return 0;
  662. error:
  663. cs_free(codec);
  664. return err;
  665. }
  666. /*
  667. * Cirrus Logic CS4210
  668. *
  669. * 1 DAC => HP(sense) / Speakers,
  670. * 1 ADC <= LineIn(sense) / MicIn / DMicIn,
  671. * 1 SPDIF OUT => SPDIF Trasmitter(sense)
  672. */
  673. /* CS4210 board names */
  674. static const struct hda_model_fixup cs421x_models[] = {
  675. { .id = CS421X_CDB4210, .name = "cdb4210" },
  676. { .id = CS421X_STUMPY, .name = "stumpy" },
  677. {}
  678. };
  679. static const struct snd_pci_quirk cs421x_fixup_tbl[] = {
  680. /* Test Intel board + CDB2410 */
  681. SND_PCI_QUIRK(0x8086, 0x5001, "DP45SG/CDB4210", CS421X_CDB4210),
  682. {} /* terminator */
  683. };
  684. /* CS4210 board pinconfigs */
  685. /* Default CS4210 (CDB4210)*/
  686. static const struct hda_pintbl cdb4210_pincfgs[] = {
  687. { 0x05, 0x0321401f },
  688. { 0x06, 0x90170010 },
  689. { 0x07, 0x03813031 },
  690. { 0x08, 0xb7a70037 },
  691. { 0x09, 0xb7a6003e },
  692. { 0x0a, 0x034510f0 },
  693. {} /* terminator */
  694. };
  695. /* Stumpy ChromeBox */
  696. static const struct hda_pintbl stumpy_pincfgs[] = {
  697. { 0x05, 0x022120f0 },
  698. { 0x06, 0x901700f0 },
  699. { 0x07, 0x02a120f0 },
  700. { 0x08, 0x77a70037 },
  701. { 0x09, 0x77a6003e },
  702. { 0x0a, 0x434510f0 },
  703. {} /* terminator */
  704. };
  705. /* Setup GPIO/SENSE for each board (if used) */
  706. static void cs421x_fixup_sense_b(struct hda_codec *codec,
  707. const struct hda_fixup *fix, int action)
  708. {
  709. struct cs_spec *spec = codec->spec;
  710. if (action == HDA_FIXUP_ACT_PRE_PROBE)
  711. spec->sense_b = 1;
  712. }
  713. static const struct hda_fixup cs421x_fixups[] = {
  714. [CS421X_CDB4210] = {
  715. .type = HDA_FIXUP_PINS,
  716. .v.pins = cdb4210_pincfgs,
  717. .chained = true,
  718. .chain_id = CS421X_SENSE_B,
  719. },
  720. [CS421X_SENSE_B] = {
  721. .type = HDA_FIXUP_FUNC,
  722. .v.func = cs421x_fixup_sense_b,
  723. },
  724. [CS421X_STUMPY] = {
  725. .type = HDA_FIXUP_PINS,
  726. .v.pins = stumpy_pincfgs,
  727. },
  728. };
  729. static const struct hda_verb cs421x_coef_init_verbs[] = {
  730. {0x0B, AC_VERB_SET_PROC_STATE, 1},
  731. {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DEV_CFG},
  732. /*
  733. Disable Coefficient Index Auto-Increment(DAI)=1,
  734. PDREF=0
  735. */
  736. {0x0B, AC_VERB_SET_PROC_COEF, 0x0001 },
  737. {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_ADC_CFG},
  738. /* ADC SZCMode = Digital Soft Ramp */
  739. {0x0B, AC_VERB_SET_PROC_COEF, 0x0002 },
  740. {0x0B, AC_VERB_SET_COEF_INDEX, CS421X_IDX_DAC_CFG},
  741. {0x0B, AC_VERB_SET_PROC_COEF,
  742. (0x0002 /* DAC SZCMode = Digital Soft Ramp */
  743. | 0x0004 /* Mute DAC on FIFO error */
  744. | 0x0008 /* Enable DAC High Pass Filter */
  745. )},
  746. {} /* terminator */
  747. };
  748. /* Errata: CS4210 rev A1 Silicon
  749. *
  750. * http://www.cirrus.com/en/pubs/errata/
  751. *
  752. * Description:
  753. * 1. Performance degredation is present in the ADC.
  754. * 2. Speaker output is not completely muted upon HP detect.
  755. * 3. Noise is present when clipping occurs on the amplified
  756. * speaker outputs.
  757. *
  758. * Workaround:
  759. * The following verb sequence written to the registers during
  760. * initialization will correct the issues listed above.
  761. */
  762. static const struct hda_verb cs421x_coef_init_verbs_A1_silicon_fixes[] = {
  763. {0x0B, AC_VERB_SET_PROC_STATE, 0x01}, /* VPW: processing on */
  764. {0x0B, AC_VERB_SET_COEF_INDEX, 0x0006},
  765. {0x0B, AC_VERB_SET_PROC_COEF, 0x9999}, /* Test mode: on */
  766. {0x0B, AC_VERB_SET_COEF_INDEX, 0x000A},
  767. {0x0B, AC_VERB_SET_PROC_COEF, 0x14CB}, /* Chop double */
  768. {0x0B, AC_VERB_SET_COEF_INDEX, 0x0011},
  769. {0x0B, AC_VERB_SET_PROC_COEF, 0xA2D0}, /* Increase ADC current */
  770. {0x0B, AC_VERB_SET_COEF_INDEX, 0x001A},
  771. {0x0B, AC_VERB_SET_PROC_COEF, 0x02A9}, /* Mute speaker */
  772. {0x0B, AC_VERB_SET_COEF_INDEX, 0x001B},
  773. {0x0B, AC_VERB_SET_PROC_COEF, 0X1006}, /* Remove noise */
  774. {} /* terminator */
  775. };
  776. /* Speaker Amp Gain is controlled by the vendor widget's coef 4 */
  777. static const DECLARE_TLV_DB_SCALE(cs421x_speaker_boost_db_scale, 900, 300, 0);
  778. static int cs421x_boost_vol_info(struct snd_kcontrol *kcontrol,
  779. struct snd_ctl_elem_info *uinfo)
  780. {
  781. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  782. uinfo->count = 1;
  783. uinfo->value.integer.min = 0;
  784. uinfo->value.integer.max = 3;
  785. return 0;
  786. }
  787. static int cs421x_boost_vol_get(struct snd_kcontrol *kcontrol,
  788. struct snd_ctl_elem_value *ucontrol)
  789. {
  790. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  791. ucontrol->value.integer.value[0] =
  792. cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL) & 0x0003;
  793. return 0;
  794. }
  795. static int cs421x_boost_vol_put(struct snd_kcontrol *kcontrol,
  796. struct snd_ctl_elem_value *ucontrol)
  797. {
  798. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  799. unsigned int vol = ucontrol->value.integer.value[0];
  800. unsigned int coef =
  801. cs_vendor_coef_get(codec, CS421X_IDX_SPK_CTL);
  802. unsigned int original_coef = coef;
  803. coef &= ~0x0003;
  804. coef |= (vol & 0x0003);
  805. if (original_coef == coef)
  806. return 0;
  807. else {
  808. cs_vendor_coef_set(codec, CS421X_IDX_SPK_CTL, coef);
  809. return 1;
  810. }
  811. }
  812. static const struct snd_kcontrol_new cs421x_speaker_boost_ctl = {
  813. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  814. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  815. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  816. .name = "Speaker Boost Playback Volume",
  817. .info = cs421x_boost_vol_info,
  818. .get = cs421x_boost_vol_get,
  819. .put = cs421x_boost_vol_put,
  820. .tlv = { .p = cs421x_speaker_boost_db_scale },
  821. };
  822. static void cs4210_pinmux_init(struct hda_codec *codec)
  823. {
  824. struct cs_spec *spec = codec->spec;
  825. unsigned int def_conf, coef;
  826. /* GPIO, DMIC_SCL, DMIC_SDA and SENSE_B are multiplexed */
  827. coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
  828. if (spec->gpio_mask)
  829. coef |= 0x0008; /* B1,B2 are GPIOs */
  830. else
  831. coef &= ~0x0008;
  832. if (spec->sense_b)
  833. coef |= 0x0010; /* B2 is SENSE_B, not inverted */
  834. else
  835. coef &= ~0x0010;
  836. cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
  837. if ((spec->gpio_mask || spec->sense_b) &&
  838. is_active_pin(codec, CS421X_DMIC_PIN_NID)) {
  839. /*
  840. GPIO or SENSE_B forced - disconnect the DMIC pin.
  841. */
  842. def_conf = snd_hda_codec_get_pincfg(codec, CS421X_DMIC_PIN_NID);
  843. def_conf &= ~AC_DEFCFG_PORT_CONN;
  844. def_conf |= (AC_JACK_PORT_NONE << AC_DEFCFG_PORT_CONN_SHIFT);
  845. snd_hda_codec_set_pincfg(codec, CS421X_DMIC_PIN_NID, def_conf);
  846. }
  847. }
  848. static void cs4210_spdif_automute(struct hda_codec *codec,
  849. struct hda_jack_tbl *tbl)
  850. {
  851. struct cs_spec *spec = codec->spec;
  852. bool spdif_present = false;
  853. hda_nid_t spdif_pin = spec->gen.autocfg.dig_out_pins[0];
  854. /* detect on spdif is specific to CS4210 */
  855. if (!spec->spdif_detect ||
  856. spec->vendor_nid != CS4210_VENDOR_NID)
  857. return;
  858. spdif_present = snd_hda_jack_detect(codec, spdif_pin);
  859. if (spdif_present == spec->spdif_present)
  860. return;
  861. spec->spdif_present = spdif_present;
  862. /* SPDIF TX on/off */
  863. if (spdif_present)
  864. snd_hda_set_pin_ctl(codec, spdif_pin,
  865. spdif_present ? PIN_OUT : 0);
  866. cs_automute(codec);
  867. }
  868. static void parse_cs421x_digital(struct hda_codec *codec)
  869. {
  870. struct cs_spec *spec = codec->spec;
  871. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  872. int i;
  873. for (i = 0; i < cfg->dig_outs; i++) {
  874. hda_nid_t nid = cfg->dig_out_pins[i];
  875. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
  876. spec->spdif_detect = 1;
  877. snd_hda_jack_detect_enable_callback(codec, nid,
  878. SPDIF_EVENT,
  879. cs4210_spdif_automute);
  880. }
  881. }
  882. }
  883. static int cs421x_init(struct hda_codec *codec)
  884. {
  885. struct cs_spec *spec = codec->spec;
  886. if (spec->vendor_nid == CS4210_VENDOR_NID) {
  887. snd_hda_sequence_write(codec, cs421x_coef_init_verbs);
  888. snd_hda_sequence_write(codec, cs421x_coef_init_verbs_A1_silicon_fixes);
  889. cs4210_pinmux_init(codec);
  890. }
  891. snd_hda_gen_init(codec);
  892. if (spec->gpio_mask) {
  893. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
  894. spec->gpio_mask);
  895. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
  896. spec->gpio_dir);
  897. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  898. spec->gpio_data);
  899. }
  900. init_input_coef(codec);
  901. cs4210_spdif_automute(codec, NULL);
  902. return 0;
  903. }
  904. static int cs421x_build_controls(struct hda_codec *codec)
  905. {
  906. struct cs_spec *spec = codec->spec;
  907. int err;
  908. err = snd_hda_gen_build_controls(codec);
  909. if (err < 0)
  910. return err;
  911. if (spec->gen.autocfg.speaker_outs &&
  912. spec->vendor_nid == CS4210_VENDOR_NID) {
  913. err = snd_hda_ctl_add(codec, 0,
  914. snd_ctl_new1(&cs421x_speaker_boost_ctl, codec));
  915. if (err < 0)
  916. return err;
  917. }
  918. return 0;
  919. }
  920. static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
  921. {
  922. unsigned int caps;
  923. /* set the upper-limit for mixer amp to 0dB */
  924. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  925. caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
  926. caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
  927. << AC_AMPCAP_NUM_STEPS_SHIFT;
  928. snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
  929. }
  930. static int cs421x_parse_auto_config(struct hda_codec *codec)
  931. {
  932. struct cs_spec *spec = codec->spec;
  933. hda_nid_t dac = CS4210_DAC_NID;
  934. int err;
  935. fix_volume_caps(codec, dac);
  936. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
  937. if (err < 0)
  938. return err;
  939. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  940. if (err < 0)
  941. return err;
  942. parse_cs421x_digital(codec);
  943. return 0;
  944. }
  945. #ifdef CONFIG_PM
  946. /*
  947. Manage PDREF, when transitioning to D3hot
  948. (DAC,ADC) -> D3, PDREF=1, AFG->D3
  949. */
  950. static int cs421x_suspend(struct hda_codec *codec)
  951. {
  952. struct cs_spec *spec = codec->spec;
  953. unsigned int coef;
  954. snd_hda_shutup_pins(codec);
  955. snd_hda_codec_write(codec, CS4210_DAC_NID, 0,
  956. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  957. snd_hda_codec_write(codec, CS4210_ADC_NID, 0,
  958. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  959. if (spec->vendor_nid == CS4210_VENDOR_NID) {
  960. coef = cs_vendor_coef_get(codec, CS421X_IDX_DEV_CFG);
  961. coef |= 0x0004; /* PDREF */
  962. cs_vendor_coef_set(codec, CS421X_IDX_DEV_CFG, coef);
  963. }
  964. return 0;
  965. }
  966. #endif
  967. static const struct hda_codec_ops cs421x_patch_ops = {
  968. .build_controls = cs421x_build_controls,
  969. .build_pcms = snd_hda_gen_build_pcms,
  970. .init = cs421x_init,
  971. .free = cs_free,
  972. .unsol_event = snd_hda_jack_unsol_event,
  973. #ifdef CONFIG_PM
  974. .suspend = cs421x_suspend,
  975. #endif
  976. };
  977. static int patch_cs4210(struct hda_codec *codec)
  978. {
  979. struct cs_spec *spec;
  980. int err;
  981. spec = cs_alloc_spec(codec, CS4210_VENDOR_NID);
  982. if (!spec)
  983. return -ENOMEM;
  984. spec->gen.automute_hook = cs_automute;
  985. snd_hda_pick_fixup(codec, cs421x_models, cs421x_fixup_tbl,
  986. cs421x_fixups);
  987. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  988. /*
  989. Update the GPIO/DMIC/SENSE_B pinmux before the configuration
  990. is auto-parsed. If GPIO or SENSE_B is forced, DMIC input
  991. is disabled.
  992. */
  993. cs4210_pinmux_init(codec);
  994. err = cs421x_parse_auto_config(codec);
  995. if (err < 0)
  996. goto error;
  997. codec->patch_ops = cs421x_patch_ops;
  998. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  999. return 0;
  1000. error:
  1001. cs_free(codec);
  1002. return err;
  1003. }
  1004. static int patch_cs4213(struct hda_codec *codec)
  1005. {
  1006. struct cs_spec *spec;
  1007. int err;
  1008. spec = cs_alloc_spec(codec, CS4213_VENDOR_NID);
  1009. if (!spec)
  1010. return -ENOMEM;
  1011. err = cs421x_parse_auto_config(codec);
  1012. if (err < 0)
  1013. goto error;
  1014. codec->patch_ops = cs421x_patch_ops;
  1015. return 0;
  1016. error:
  1017. cs_free(codec);
  1018. return err;
  1019. }
  1020. /*
  1021. * patch entries
  1022. */
  1023. static const struct hda_codec_preset snd_hda_preset_cirrus[] = {
  1024. { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
  1025. { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
  1026. { .id = 0x10134208, .name = "CS4208", .patch = patch_cs4208 },
  1027. { .id = 0x10134210, .name = "CS4210", .patch = patch_cs4210 },
  1028. { .id = 0x10134213, .name = "CS4213", .patch = patch_cs4213 },
  1029. {} /* terminator */
  1030. };
  1031. MODULE_ALIAS("snd-hda-codec-id:10134206");
  1032. MODULE_ALIAS("snd-hda-codec-id:10134207");
  1033. MODULE_ALIAS("snd-hda-codec-id:10134208");
  1034. MODULE_ALIAS("snd-hda-codec-id:10134210");
  1035. MODULE_ALIAS("snd-hda-codec-id:10134213");
  1036. MODULE_LICENSE("GPL");
  1037. MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
  1038. static struct hda_codec_preset_list cirrus_list = {
  1039. .preset = snd_hda_preset_cirrus,
  1040. .owner = THIS_MODULE,
  1041. };
  1042. static int __init patch_cirrus_init(void)
  1043. {
  1044. return snd_hda_add_codec_preset(&cirrus_list);
  1045. }
  1046. static void __exit patch_cirrus_exit(void)
  1047. {
  1048. snd_hda_delete_codec_preset(&cirrus_list);
  1049. }
  1050. module_init(patch_cirrus_init)
  1051. module_exit(patch_cirrus_exit)