patch_cirrus.c 30 KB

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