patch_cirrus.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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/delay.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <sound/core.h>
  25. #include "hda_codec.h"
  26. #include "hda_local.h"
  27. /*
  28. */
  29. struct cs_spec {
  30. int board_config;
  31. struct auto_pin_cfg autocfg;
  32. struct hda_multi_out multiout;
  33. struct snd_kcontrol *vmaster_sw;
  34. struct snd_kcontrol *vmaster_vol;
  35. hda_nid_t dac_nid[AUTO_CFG_MAX_OUTS];
  36. hda_nid_t slave_dig_outs[2];
  37. unsigned int input_idx[AUTO_PIN_LAST];
  38. unsigned int capsrc_idx[AUTO_PIN_LAST];
  39. hda_nid_t adc_nid[AUTO_PIN_LAST];
  40. unsigned int adc_idx[AUTO_PIN_LAST];
  41. unsigned int num_inputs;
  42. unsigned int cur_input;
  43. unsigned int automic_idx;
  44. hda_nid_t cur_adc;
  45. unsigned int cur_adc_stream_tag;
  46. unsigned int cur_adc_format;
  47. hda_nid_t dig_in;
  48. struct hda_bind_ctls *capture_bind[2];
  49. unsigned int gpio_mask;
  50. unsigned int gpio_dir;
  51. unsigned int gpio_data;
  52. struct hda_pcm pcm_rec[2]; /* PCM information */
  53. unsigned int hp_detect:1;
  54. unsigned int mic_detect:1;
  55. };
  56. /* available models */
  57. enum {
  58. CS420X_MBP55,
  59. CS420X_IMAC27,
  60. CS420X_AUTO,
  61. CS420X_MODELS
  62. };
  63. /* Vendor-specific processing widget */
  64. #define CS420X_VENDOR_NID 0x11
  65. #define CS_DIG_OUT1_PIN_NID 0x10
  66. #define CS_DIG_OUT2_PIN_NID 0x15
  67. #define CS_DMIC1_PIN_NID 0x12
  68. #define CS_DMIC2_PIN_NID 0x0e
  69. /* coef indices */
  70. #define IDX_SPDIF_STAT 0x0000
  71. #define IDX_SPDIF_CTL 0x0001
  72. #define IDX_ADC_CFG 0x0002
  73. /* SZC bitmask, 4 modes below:
  74. * 0 = immediate,
  75. * 1 = digital immediate, analog zero-cross
  76. * 2 = digtail & analog soft-ramp
  77. * 3 = digital soft-ramp, analog zero-cross
  78. */
  79. #define CS_COEF_ADC_SZC_MASK (3 << 0)
  80. #define CS_COEF_ADC_MIC_SZC_MODE (3 << 0) /* SZC setup for mic */
  81. #define CS_COEF_ADC_LI_SZC_MODE (3 << 0) /* SZC setup for line-in */
  82. /* PGA mode: 0 = differential, 1 = signle-ended */
  83. #define CS_COEF_ADC_MIC_PGA_MODE (1 << 5) /* PGA setup for mic */
  84. #define CS_COEF_ADC_LI_PGA_MODE (1 << 6) /* PGA setup for line-in */
  85. #define IDX_DAC_CFG 0x0003
  86. /* SZC bitmask, 4 modes below:
  87. * 0 = Immediate
  88. * 1 = zero-cross
  89. * 2 = soft-ramp
  90. * 3 = soft-ramp on zero-cross
  91. */
  92. #define CS_COEF_DAC_HP_SZC_MODE (3 << 0) /* nid 0x02 */
  93. #define CS_COEF_DAC_LO_SZC_MODE (3 << 2) /* nid 0x03 */
  94. #define CS_COEF_DAC_SPK_SZC_MODE (3 << 4) /* nid 0x04 */
  95. #define IDX_BEEP_CFG 0x0004
  96. /* 0x0008 - test reg key */
  97. /* 0x0009 - 0x0014 -> 12 test regs */
  98. /* 0x0015 - visibility reg */
  99. static inline int cs_vendor_coef_get(struct hda_codec *codec, unsigned int idx)
  100. {
  101. snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
  102. AC_VERB_SET_COEF_INDEX, idx);
  103. return snd_hda_codec_read(codec, CS420X_VENDOR_NID, 0,
  104. AC_VERB_GET_PROC_COEF, 0);
  105. }
  106. static inline void cs_vendor_coef_set(struct hda_codec *codec, unsigned int idx,
  107. unsigned int coef)
  108. {
  109. snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
  110. AC_VERB_SET_COEF_INDEX, idx);
  111. snd_hda_codec_write(codec, CS420X_VENDOR_NID, 0,
  112. AC_VERB_SET_PROC_COEF, coef);
  113. }
  114. #define HP_EVENT 1
  115. #define MIC_EVENT 2
  116. /*
  117. * PCM callbacks
  118. */
  119. static int cs_playback_pcm_open(struct hda_pcm_stream *hinfo,
  120. struct hda_codec *codec,
  121. struct snd_pcm_substream *substream)
  122. {
  123. struct cs_spec *spec = codec->spec;
  124. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  125. hinfo);
  126. }
  127. static int cs_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  128. struct hda_codec *codec,
  129. unsigned int stream_tag,
  130. unsigned int format,
  131. struct snd_pcm_substream *substream)
  132. {
  133. struct cs_spec *spec = codec->spec;
  134. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  135. stream_tag, format, substream);
  136. }
  137. static int cs_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  138. struct hda_codec *codec,
  139. struct snd_pcm_substream *substream)
  140. {
  141. struct cs_spec *spec = codec->spec;
  142. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  143. }
  144. /*
  145. * Digital out
  146. */
  147. static int cs_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  148. struct hda_codec *codec,
  149. struct snd_pcm_substream *substream)
  150. {
  151. struct cs_spec *spec = codec->spec;
  152. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  153. }
  154. static int cs_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  155. struct hda_codec *codec,
  156. struct snd_pcm_substream *substream)
  157. {
  158. struct cs_spec *spec = codec->spec;
  159. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  160. }
  161. static int cs_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  162. struct hda_codec *codec,
  163. unsigned int stream_tag,
  164. unsigned int format,
  165. struct snd_pcm_substream *substream)
  166. {
  167. struct cs_spec *spec = codec->spec;
  168. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  169. format, substream);
  170. }
  171. static int cs_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  172. struct hda_codec *codec,
  173. struct snd_pcm_substream *substream)
  174. {
  175. struct cs_spec *spec = codec->spec;
  176. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  177. }
  178. /*
  179. * Analog capture
  180. */
  181. static int cs_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  182. struct hda_codec *codec,
  183. unsigned int stream_tag,
  184. unsigned int format,
  185. struct snd_pcm_substream *substream)
  186. {
  187. struct cs_spec *spec = codec->spec;
  188. spec->cur_adc = spec->adc_nid[spec->cur_input];
  189. spec->cur_adc_stream_tag = stream_tag;
  190. spec->cur_adc_format = format;
  191. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  192. return 0;
  193. }
  194. static int cs_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  195. struct hda_codec *codec,
  196. struct snd_pcm_substream *substream)
  197. {
  198. struct cs_spec *spec = codec->spec;
  199. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  200. spec->cur_adc = 0;
  201. return 0;
  202. }
  203. /*
  204. */
  205. static struct hda_pcm_stream cs_pcm_analog_playback = {
  206. .substreams = 1,
  207. .channels_min = 2,
  208. .channels_max = 2,
  209. .ops = {
  210. .open = cs_playback_pcm_open,
  211. .prepare = cs_playback_pcm_prepare,
  212. .cleanup = cs_playback_pcm_cleanup
  213. },
  214. };
  215. static struct hda_pcm_stream cs_pcm_analog_capture = {
  216. .substreams = 1,
  217. .channels_min = 2,
  218. .channels_max = 2,
  219. .ops = {
  220. .prepare = cs_capture_pcm_prepare,
  221. .cleanup = cs_capture_pcm_cleanup
  222. },
  223. };
  224. static struct hda_pcm_stream cs_pcm_digital_playback = {
  225. .substreams = 1,
  226. .channels_min = 2,
  227. .channels_max = 2,
  228. .ops = {
  229. .open = cs_dig_playback_pcm_open,
  230. .close = cs_dig_playback_pcm_close,
  231. .prepare = cs_dig_playback_pcm_prepare,
  232. .cleanup = cs_dig_playback_pcm_cleanup
  233. },
  234. };
  235. static struct hda_pcm_stream cs_pcm_digital_capture = {
  236. .substreams = 1,
  237. .channels_min = 2,
  238. .channels_max = 2,
  239. };
  240. static int cs_build_pcms(struct hda_codec *codec)
  241. {
  242. struct cs_spec *spec = codec->spec;
  243. struct hda_pcm *info = spec->pcm_rec;
  244. codec->pcm_info = info;
  245. codec->num_pcms = 0;
  246. info->name = "Cirrus Analog";
  247. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cs_pcm_analog_playback;
  248. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
  249. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  250. spec->multiout.max_channels;
  251. info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
  252. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  253. spec->adc_nid[spec->cur_input];
  254. codec->num_pcms++;
  255. if (!spec->multiout.dig_out_nid && !spec->dig_in)
  256. return 0;
  257. info++;
  258. info->name = "Cirrus Digital";
  259. info->pcm_type = spec->autocfg.dig_out_type[0];
  260. if (!info->pcm_type)
  261. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  262. if (spec->multiout.dig_out_nid) {
  263. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  264. cs_pcm_digital_playback;
  265. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  266. spec->multiout.dig_out_nid;
  267. }
  268. if (spec->dig_in) {
  269. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  270. cs_pcm_digital_capture;
  271. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in;
  272. }
  273. codec->num_pcms++;
  274. return 0;
  275. }
  276. /*
  277. * parse codec topology
  278. */
  279. static hda_nid_t get_dac(struct hda_codec *codec, hda_nid_t pin)
  280. {
  281. hda_nid_t dac;
  282. if (!pin)
  283. return 0;
  284. if (snd_hda_get_connections(codec, pin, &dac, 1) != 1)
  285. return 0;
  286. return dac;
  287. }
  288. static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
  289. {
  290. struct cs_spec *spec = codec->spec;
  291. struct auto_pin_cfg *cfg = &spec->autocfg;
  292. hda_nid_t pin = cfg->input_pins[idx];
  293. unsigned int val = snd_hda_query_pin_caps(codec, pin);
  294. if (!(val & AC_PINCAP_PRES_DETECT))
  295. return 0;
  296. val = snd_hda_codec_get_pincfg(codec, pin);
  297. return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX);
  298. }
  299. static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
  300. unsigned int *idxp)
  301. {
  302. int i;
  303. hda_nid_t nid;
  304. nid = codec->start_nid;
  305. for (i = 0; i < codec->num_nodes; i++, nid++) {
  306. hda_nid_t pins[2];
  307. unsigned int type;
  308. int j, nums;
  309. type = (get_wcaps(codec, nid) & AC_WCAP_TYPE)
  310. >> AC_WCAP_TYPE_SHIFT;
  311. if (type != AC_WID_AUD_IN)
  312. continue;
  313. nums = snd_hda_get_connections(codec, nid, pins,
  314. ARRAY_SIZE(pins));
  315. if (nums <= 0)
  316. continue;
  317. for (j = 0; j < nums; j++) {
  318. if (pins[j] == pin) {
  319. *idxp = j;
  320. return nid;
  321. }
  322. }
  323. }
  324. return 0;
  325. }
  326. static int is_active_pin(struct hda_codec *codec, hda_nid_t nid)
  327. {
  328. unsigned int val;
  329. val = snd_hda_codec_get_pincfg(codec, nid);
  330. return (get_defcfg_connect(val) != AC_JACK_PORT_NONE);
  331. }
  332. static int parse_output(struct hda_codec *codec)
  333. {
  334. struct cs_spec *spec = codec->spec;
  335. struct auto_pin_cfg *cfg = &spec->autocfg;
  336. int i, extra_nids;
  337. hda_nid_t dac;
  338. for (i = 0; i < cfg->line_outs; i++) {
  339. dac = get_dac(codec, cfg->line_out_pins[i]);
  340. if (!dac)
  341. break;
  342. spec->dac_nid[i] = dac;
  343. }
  344. spec->multiout.num_dacs = i;
  345. spec->multiout.dac_nids = spec->dac_nid;
  346. spec->multiout.max_channels = i * 2;
  347. /* add HP and speakers */
  348. extra_nids = 0;
  349. for (i = 0; i < cfg->hp_outs; i++) {
  350. dac = get_dac(codec, cfg->hp_pins[i]);
  351. if (!dac)
  352. break;
  353. if (!i)
  354. spec->multiout.hp_nid = dac;
  355. else
  356. spec->multiout.extra_out_nid[extra_nids++] = dac;
  357. }
  358. for (i = 0; i < cfg->speaker_outs; i++) {
  359. dac = get_dac(codec, cfg->speaker_pins[i]);
  360. if (!dac)
  361. break;
  362. spec->multiout.extra_out_nid[extra_nids++] = dac;
  363. }
  364. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  365. cfg->speaker_outs = cfg->line_outs;
  366. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  367. sizeof(cfg->speaker_pins));
  368. cfg->line_outs = 0;
  369. }
  370. return 0;
  371. }
  372. static int parse_input(struct hda_codec *codec)
  373. {
  374. struct cs_spec *spec = codec->spec;
  375. struct auto_pin_cfg *cfg = &spec->autocfg;
  376. int i;
  377. for (i = 0; i < AUTO_PIN_LAST; i++) {
  378. hda_nid_t pin = cfg->input_pins[i];
  379. if (!pin)
  380. continue;
  381. spec->input_idx[spec->num_inputs] = i;
  382. spec->capsrc_idx[i] = spec->num_inputs++;
  383. spec->cur_input = i;
  384. spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]);
  385. }
  386. if (!spec->num_inputs)
  387. return 0;
  388. /* check whether the automatic mic switch is available */
  389. if (spec->num_inputs == 2 &&
  390. spec->adc_nid[AUTO_PIN_MIC] && spec->adc_nid[AUTO_PIN_FRONT_MIC]) {
  391. if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_FRONT_MIC])) {
  392. if (!is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
  393. spec->mic_detect = 1;
  394. spec->automic_idx = AUTO_PIN_FRONT_MIC;
  395. }
  396. } else {
  397. if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) {
  398. spec->mic_detect = 1;
  399. spec->automic_idx = AUTO_PIN_MIC;
  400. }
  401. }
  402. }
  403. return 0;
  404. }
  405. static int parse_digital_output(struct hda_codec *codec)
  406. {
  407. struct cs_spec *spec = codec->spec;
  408. struct auto_pin_cfg *cfg = &spec->autocfg;
  409. hda_nid_t nid;
  410. if (!cfg->dig_outs)
  411. return 0;
  412. if (snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) < 1)
  413. return 0;
  414. spec->multiout.dig_out_nid = nid;
  415. spec->multiout.share_spdif = 1;
  416. if (cfg->dig_outs > 1 &&
  417. snd_hda_get_connections(codec, cfg->dig_out_pins[1], &nid, 1) > 0) {
  418. spec->slave_dig_outs[0] = nid;
  419. codec->slave_dig_outs = spec->slave_dig_outs;
  420. }
  421. return 0;
  422. }
  423. static int parse_digital_input(struct hda_codec *codec)
  424. {
  425. struct cs_spec *spec = codec->spec;
  426. struct auto_pin_cfg *cfg = &spec->autocfg;
  427. int idx;
  428. if (cfg->dig_in_pin)
  429. spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx);
  430. return 0;
  431. }
  432. /*
  433. * create mixer controls
  434. */
  435. static const char *dir_sfx[2] = { "Playback", "Capture" };
  436. static int add_mute(struct hda_codec *codec, const char *name, int index,
  437. unsigned int pval, int dir, struct snd_kcontrol **kctlp)
  438. {
  439. char tmp[44];
  440. struct snd_kcontrol_new knew =
  441. HDA_CODEC_MUTE_IDX(tmp, index, 0, 0, HDA_OUTPUT);
  442. knew.private_value = pval;
  443. snprintf(tmp, sizeof(tmp), "%s %s Switch", name, dir_sfx[dir]);
  444. *kctlp = snd_ctl_new1(&knew, codec);
  445. (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
  446. return snd_hda_ctl_add(codec, 0, *kctlp);
  447. }
  448. static int add_volume(struct hda_codec *codec, const char *name,
  449. int index, unsigned int pval, int dir,
  450. struct snd_kcontrol **kctlp)
  451. {
  452. char tmp[32];
  453. struct snd_kcontrol_new knew =
  454. HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
  455. knew.private_value = pval;
  456. snprintf(tmp, sizeof(tmp), "%s %s Volume", name, dir_sfx[dir]);
  457. *kctlp = snd_ctl_new1(&knew, codec);
  458. (*kctlp)->id.subdevice = HDA_SUBDEV_AMP_FLAG;
  459. return snd_hda_ctl_add(codec, 0, *kctlp);
  460. }
  461. static void fix_volume_caps(struct hda_codec *codec, hda_nid_t dac)
  462. {
  463. unsigned int caps;
  464. /* set the upper-limit for mixer amp to 0dB */
  465. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  466. caps &= ~(0x7f << AC_AMPCAP_NUM_STEPS_SHIFT);
  467. caps |= ((caps >> AC_AMPCAP_OFFSET_SHIFT) & 0x7f)
  468. << AC_AMPCAP_NUM_STEPS_SHIFT;
  469. snd_hda_override_amp_caps(codec, dac, HDA_OUTPUT, caps);
  470. }
  471. static int add_vmaster(struct hda_codec *codec, hda_nid_t dac)
  472. {
  473. struct cs_spec *spec = codec->spec;
  474. unsigned int tlv[4];
  475. int err;
  476. spec->vmaster_sw =
  477. snd_ctl_make_virtual_master("Master Playback Switch", NULL);
  478. err = snd_hda_ctl_add(codec, dac, spec->vmaster_sw);
  479. if (err < 0)
  480. return err;
  481. snd_hda_set_vmaster_tlv(codec, dac, HDA_OUTPUT, tlv);
  482. spec->vmaster_vol =
  483. snd_ctl_make_virtual_master("Master Playback Volume", tlv);
  484. err = snd_hda_ctl_add(codec, dac, spec->vmaster_vol);
  485. if (err < 0)
  486. return err;
  487. return 0;
  488. }
  489. static int add_output(struct hda_codec *codec, hda_nid_t dac, int idx,
  490. int num_ctls, int type)
  491. {
  492. struct cs_spec *spec = codec->spec;
  493. const char *name;
  494. int err, index;
  495. struct snd_kcontrol *kctl;
  496. static char *speakers[] = {
  497. "Front Speaker", "Surround Speaker", "Bass Speaker"
  498. };
  499. static char *line_outs[] = {
  500. "Front Line-Out", "Surround Line-Out", "Bass Line-Out"
  501. };
  502. fix_volume_caps(codec, dac);
  503. if (!spec->vmaster_sw) {
  504. err = add_vmaster(codec, dac);
  505. if (err < 0)
  506. return err;
  507. }
  508. index = 0;
  509. switch (type) {
  510. case AUTO_PIN_HP_OUT:
  511. name = "Headphone";
  512. index = idx;
  513. break;
  514. case AUTO_PIN_SPEAKER_OUT:
  515. if (num_ctls > 1)
  516. name = speakers[idx];
  517. else
  518. name = "Speaker";
  519. break;
  520. default:
  521. if (num_ctls > 1)
  522. name = line_outs[idx];
  523. else
  524. name = "Line-Out";
  525. break;
  526. }
  527. err = add_mute(codec, name, index,
  528. HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
  529. if (err < 0)
  530. return err;
  531. err = snd_ctl_add_slave(spec->vmaster_sw, kctl);
  532. if (err < 0)
  533. return err;
  534. err = add_volume(codec, name, index,
  535. HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT), 0, &kctl);
  536. if (err < 0)
  537. return err;
  538. err = snd_ctl_add_slave(spec->vmaster_vol, kctl);
  539. if (err < 0)
  540. return err;
  541. return 0;
  542. }
  543. static int build_output(struct hda_codec *codec)
  544. {
  545. struct cs_spec *spec = codec->spec;
  546. struct auto_pin_cfg *cfg = &spec->autocfg;
  547. int i, err;
  548. for (i = 0; i < cfg->line_outs; i++) {
  549. err = add_output(codec, get_dac(codec, cfg->line_out_pins[i]),
  550. i, cfg->line_outs, cfg->line_out_type);
  551. if (err < 0)
  552. return err;
  553. }
  554. for (i = 0; i < cfg->hp_outs; i++) {
  555. err = add_output(codec, get_dac(codec, cfg->hp_pins[i]),
  556. i, cfg->hp_outs, AUTO_PIN_HP_OUT);
  557. if (err < 0)
  558. return err;
  559. }
  560. for (i = 0; i < cfg->speaker_outs; i++) {
  561. err = add_output(codec, get_dac(codec, cfg->speaker_pins[i]),
  562. i, cfg->speaker_outs, AUTO_PIN_SPEAKER_OUT);
  563. if (err < 0)
  564. return err;
  565. }
  566. return 0;
  567. }
  568. /*
  569. */
  570. static struct snd_kcontrol_new cs_capture_ctls[] = {
  571. HDA_BIND_SW("Capture Switch", 0),
  572. HDA_BIND_VOL("Capture Volume", 0),
  573. };
  574. static int change_cur_input(struct hda_codec *codec, unsigned int idx,
  575. int force)
  576. {
  577. struct cs_spec *spec = codec->spec;
  578. if (spec->cur_input == idx && !force)
  579. return 0;
  580. if (spec->cur_adc && spec->cur_adc != spec->adc_nid[idx]) {
  581. /* stream is running, let's swap the current ADC */
  582. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  583. spec->cur_adc = spec->adc_nid[idx];
  584. snd_hda_codec_setup_stream(codec, spec->cur_adc,
  585. spec->cur_adc_stream_tag, 0,
  586. spec->cur_adc_format);
  587. }
  588. snd_hda_codec_write(codec, spec->cur_adc, 0,
  589. AC_VERB_SET_CONNECT_SEL,
  590. spec->adc_idx[idx]);
  591. spec->cur_input = idx;
  592. return 1;
  593. }
  594. static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
  595. struct snd_ctl_elem_info *uinfo)
  596. {
  597. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  598. struct cs_spec *spec = codec->spec;
  599. unsigned int idx;
  600. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  601. uinfo->count = 1;
  602. uinfo->value.enumerated.items = spec->num_inputs;
  603. if (uinfo->value.enumerated.item >= spec->num_inputs)
  604. uinfo->value.enumerated.item = spec->num_inputs - 1;
  605. idx = spec->input_idx[uinfo->value.enumerated.item];
  606. strcpy(uinfo->value.enumerated.name, auto_pin_cfg_labels[idx]);
  607. return 0;
  608. }
  609. static int cs_capture_source_get(struct snd_kcontrol *kcontrol,
  610. struct snd_ctl_elem_value *ucontrol)
  611. {
  612. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  613. struct cs_spec *spec = codec->spec;
  614. ucontrol->value.enumerated.item[0] = spec->capsrc_idx[spec->cur_input];
  615. return 0;
  616. }
  617. static int cs_capture_source_put(struct snd_kcontrol *kcontrol,
  618. struct snd_ctl_elem_value *ucontrol)
  619. {
  620. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  621. struct cs_spec *spec = codec->spec;
  622. unsigned int idx = ucontrol->value.enumerated.item[0];
  623. if (idx >= spec->num_inputs)
  624. return -EINVAL;
  625. idx = spec->input_idx[idx];
  626. return change_cur_input(codec, idx, 0);
  627. }
  628. static struct snd_kcontrol_new cs_capture_source = {
  629. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  630. .name = "Capture Source",
  631. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  632. .info = cs_capture_source_info,
  633. .get = cs_capture_source_get,
  634. .put = cs_capture_source_put,
  635. };
  636. static struct hda_bind_ctls *make_bind_capture(struct hda_codec *codec,
  637. struct hda_ctl_ops *ops)
  638. {
  639. struct cs_spec *spec = codec->spec;
  640. struct hda_bind_ctls *bind;
  641. int i, n;
  642. bind = kzalloc(sizeof(*bind) + sizeof(long) * (spec->num_inputs + 1),
  643. GFP_KERNEL);
  644. if (!bind)
  645. return NULL;
  646. bind->ops = ops;
  647. n = 0;
  648. for (i = 0; i < AUTO_PIN_LAST; i++) {
  649. if (!spec->adc_nid[i])
  650. continue;
  651. bind->values[n++] =
  652. HDA_COMPOSE_AMP_VAL(spec->adc_nid[i], 3,
  653. spec->adc_idx[i], HDA_INPUT);
  654. }
  655. return bind;
  656. }
  657. static int build_input(struct hda_codec *codec)
  658. {
  659. struct cs_spec *spec = codec->spec;
  660. int i, err;
  661. if (!spec->num_inputs)
  662. return 0;
  663. /* make bind-capture */
  664. spec->capture_bind[0] = make_bind_capture(codec, &snd_hda_bind_sw);
  665. spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
  666. for (i = 0; i < 2; i++) {
  667. struct snd_kcontrol *kctl;
  668. int n;
  669. if (!spec->capture_bind[i])
  670. return -ENOMEM;
  671. kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
  672. if (!kctl)
  673. return -ENOMEM;
  674. kctl->private_value = (long)spec->capture_bind[i];
  675. err = snd_hda_ctl_add(codec, 0, kctl);
  676. if (err < 0)
  677. return err;
  678. for (n = 0; n < AUTO_PIN_LAST; n++) {
  679. if (!spec->adc_nid[n])
  680. continue;
  681. err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[n]);
  682. if (err < 0)
  683. return err;
  684. }
  685. }
  686. if (spec->num_inputs > 1 && !spec->mic_detect) {
  687. err = snd_hda_ctl_add(codec, 0,
  688. snd_ctl_new1(&cs_capture_source, codec));
  689. if (err < 0)
  690. return err;
  691. }
  692. return 0;
  693. }
  694. /*
  695. */
  696. static int build_digital_output(struct hda_codec *codec)
  697. {
  698. struct cs_spec *spec = codec->spec;
  699. int err;
  700. if (!spec->multiout.dig_out_nid)
  701. return 0;
  702. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  703. if (err < 0)
  704. return err;
  705. err = snd_hda_create_spdif_share_sw(codec, &spec->multiout);
  706. if (err < 0)
  707. return err;
  708. return 0;
  709. }
  710. static int build_digital_input(struct hda_codec *codec)
  711. {
  712. struct cs_spec *spec = codec->spec;
  713. if (spec->dig_in)
  714. return snd_hda_create_spdif_in_ctls(codec, spec->dig_in);
  715. return 0;
  716. }
  717. /*
  718. * auto-mute and auto-mic switching
  719. */
  720. static void cs_automute(struct hda_codec *codec)
  721. {
  722. struct cs_spec *spec = codec->spec;
  723. struct auto_pin_cfg *cfg = &spec->autocfg;
  724. unsigned int caps, hp_present;
  725. hda_nid_t nid;
  726. int i;
  727. hp_present = 0;
  728. for (i = 0; i < cfg->hp_outs; i++) {
  729. nid = cfg->hp_pins[i];
  730. caps = snd_hda_query_pin_caps(codec, nid);
  731. if (!(caps & AC_PINCAP_PRES_DETECT))
  732. continue;
  733. hp_present = snd_hda_jack_detect(codec, nid);
  734. if (hp_present)
  735. break;
  736. }
  737. for (i = 0; i < cfg->speaker_outs; i++) {
  738. nid = cfg->speaker_pins[i];
  739. snd_hda_codec_write(codec, nid, 0,
  740. AC_VERB_SET_PIN_WIDGET_CONTROL,
  741. hp_present ? 0 : PIN_OUT);
  742. }
  743. if (spec->board_config == CS420X_MBP55 ||
  744. spec->board_config == CS420X_IMAC27) {
  745. unsigned int gpio = hp_present ? 0x02 : 0x08;
  746. snd_hda_codec_write(codec, 0x01, 0,
  747. AC_VERB_SET_GPIO_DATA, gpio);
  748. }
  749. }
  750. static void cs_automic(struct hda_codec *codec)
  751. {
  752. struct cs_spec *spec = codec->spec;
  753. struct auto_pin_cfg *cfg = &spec->autocfg;
  754. hda_nid_t nid;
  755. unsigned int present;
  756. nid = cfg->input_pins[spec->automic_idx];
  757. present = snd_hda_jack_detect(codec, nid);
  758. if (present)
  759. change_cur_input(codec, spec->automic_idx, 0);
  760. else {
  761. unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
  762. AUTO_PIN_FRONT_MIC : AUTO_PIN_MIC;
  763. change_cur_input(codec, imic, 0);
  764. }
  765. }
  766. /*
  767. */
  768. static void init_output(struct hda_codec *codec)
  769. {
  770. struct cs_spec *spec = codec->spec;
  771. struct auto_pin_cfg *cfg = &spec->autocfg;
  772. int i;
  773. /* mute first */
  774. for (i = 0; i < spec->multiout.num_dacs; i++)
  775. snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
  776. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
  777. if (spec->multiout.hp_nid)
  778. snd_hda_codec_write(codec, spec->multiout.hp_nid, 0,
  779. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
  780. for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
  781. if (!spec->multiout.extra_out_nid[i])
  782. break;
  783. snd_hda_codec_write(codec, spec->multiout.extra_out_nid[i], 0,
  784. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
  785. }
  786. /* set appropriate pin controls */
  787. for (i = 0; i < cfg->line_outs; i++)
  788. snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
  789. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  790. for (i = 0; i < cfg->hp_outs; i++) {
  791. hda_nid_t nid = cfg->hp_pins[i];
  792. snd_hda_codec_write(codec, nid, 0,
  793. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
  794. if (!cfg->speaker_outs)
  795. continue;
  796. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
  797. snd_hda_codec_write(codec, nid, 0,
  798. AC_VERB_SET_UNSOLICITED_ENABLE,
  799. AC_USRSP_EN | HP_EVENT);
  800. spec->hp_detect = 1;
  801. }
  802. }
  803. for (i = 0; i < cfg->speaker_outs; i++)
  804. snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
  805. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  806. if (spec->hp_detect)
  807. cs_automute(codec);
  808. }
  809. static void init_input(struct hda_codec *codec)
  810. {
  811. struct cs_spec *spec = codec->spec;
  812. struct auto_pin_cfg *cfg = &spec->autocfg;
  813. unsigned int coef;
  814. int i;
  815. for (i = 0; i < AUTO_PIN_LAST; i++) {
  816. unsigned int ctl;
  817. hda_nid_t pin = cfg->input_pins[i];
  818. if (!pin || !spec->adc_nid[i])
  819. continue;
  820. /* set appropriate pin control and mute first */
  821. ctl = PIN_IN;
  822. if (i <= AUTO_PIN_FRONT_MIC) {
  823. unsigned int caps = snd_hda_query_pin_caps(codec, pin);
  824. caps >>= AC_PINCAP_VREF_SHIFT;
  825. if (caps & AC_PINCAP_VREF_80)
  826. ctl = PIN_VREF80;
  827. }
  828. snd_hda_codec_write(codec, pin, 0,
  829. AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
  830. snd_hda_codec_write(codec, spec->adc_nid[i], 0,
  831. AC_VERB_SET_AMP_GAIN_MUTE,
  832. AMP_IN_MUTE(spec->adc_idx[i]));
  833. if (spec->mic_detect && spec->automic_idx == i)
  834. snd_hda_codec_write(codec, pin, 0,
  835. AC_VERB_SET_UNSOLICITED_ENABLE,
  836. AC_USRSP_EN | MIC_EVENT);
  837. }
  838. change_cur_input(codec, spec->cur_input, 1);
  839. if (spec->mic_detect)
  840. cs_automic(codec);
  841. coef = 0x000a; /* ADC1/2 - Digital and Analog Soft Ramp */
  842. if (is_active_pin(codec, CS_DMIC2_PIN_NID))
  843. coef |= 0x0500; /* DMIC2 enable 2 channels, disable GPIO1 */
  844. if (is_active_pin(codec, CS_DMIC1_PIN_NID))
  845. coef |= 0x1800; /* DMIC1 enable 2 channels, disable GPIO0
  846. * No effect if SPDIF_OUT2 is selected in
  847. * IDX_SPDIF_CTL.
  848. */
  849. cs_vendor_coef_set(codec, IDX_ADC_CFG, coef);
  850. }
  851. static struct hda_verb cs_coef_init_verbs[] = {
  852. {0x11, AC_VERB_SET_PROC_STATE, 1},
  853. {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
  854. {0x11, AC_VERB_SET_PROC_COEF,
  855. (0x002a /* DAC1/2/3 SZCMode Soft Ramp */
  856. | 0x0040 /* Mute DACs on FIFO error */
  857. | 0x1000 /* Enable DACs High Pass Filter */
  858. | 0x0400 /* Disable Coefficient Auto increment */
  859. )},
  860. /* Beep */
  861. {0x11, AC_VERB_SET_COEF_INDEX, IDX_DAC_CFG},
  862. {0x11, AC_VERB_SET_PROC_COEF, 0x0007}, /* Enable Beep thru DAC1/2/3 */
  863. {} /* terminator */
  864. };
  865. /* SPDIF setup */
  866. static void init_digital(struct hda_codec *codec)
  867. {
  868. unsigned int coef;
  869. coef = 0x0002; /* SRC_MUTE soft-mute on SPDIF (if no lock) */
  870. coef |= 0x0008; /* Replace with mute on error */
  871. if (is_active_pin(codec, CS_DIG_OUT2_PIN_NID))
  872. coef |= 0x4000; /* RX to TX1 or TX2 Loopthru / SPDIF2
  873. * SPDIF_OUT2 is shared with GPIO1 and
  874. * DMIC_SDA2.
  875. */
  876. cs_vendor_coef_set(codec, IDX_SPDIF_CTL, coef);
  877. }
  878. static int cs_init(struct hda_codec *codec)
  879. {
  880. struct cs_spec *spec = codec->spec;
  881. snd_hda_sequence_write(codec, cs_coef_init_verbs);
  882. if (spec->gpio_mask) {
  883. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
  884. spec->gpio_mask);
  885. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
  886. spec->gpio_dir);
  887. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  888. spec->gpio_data);
  889. }
  890. init_output(codec);
  891. init_input(codec);
  892. init_digital(codec);
  893. return 0;
  894. }
  895. static int cs_build_controls(struct hda_codec *codec)
  896. {
  897. int err;
  898. err = build_output(codec);
  899. if (err < 0)
  900. return err;
  901. err = build_input(codec);
  902. if (err < 0)
  903. return err;
  904. err = build_digital_output(codec);
  905. if (err < 0)
  906. return err;
  907. err = build_digital_input(codec);
  908. if (err < 0)
  909. return err;
  910. return cs_init(codec);
  911. }
  912. static void cs_free(struct hda_codec *codec)
  913. {
  914. struct cs_spec *spec = codec->spec;
  915. kfree(spec->capture_bind[0]);
  916. kfree(spec->capture_bind[1]);
  917. kfree(codec->spec);
  918. }
  919. static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
  920. {
  921. switch ((res >> 26) & 0x7f) {
  922. case HP_EVENT:
  923. cs_automute(codec);
  924. break;
  925. case MIC_EVENT:
  926. cs_automic(codec);
  927. break;
  928. }
  929. }
  930. static struct hda_codec_ops cs_patch_ops = {
  931. .build_controls = cs_build_controls,
  932. .build_pcms = cs_build_pcms,
  933. .init = cs_init,
  934. .free = cs_free,
  935. .unsol_event = cs_unsol_event,
  936. };
  937. static int cs_parse_auto_config(struct hda_codec *codec)
  938. {
  939. struct cs_spec *spec = codec->spec;
  940. int err;
  941. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  942. if (err < 0)
  943. return err;
  944. err = parse_output(codec);
  945. if (err < 0)
  946. return err;
  947. err = parse_input(codec);
  948. if (err < 0)
  949. return err;
  950. err = parse_digital_output(codec);
  951. if (err < 0)
  952. return err;
  953. err = parse_digital_input(codec);
  954. if (err < 0)
  955. return err;
  956. return 0;
  957. }
  958. static const char *cs420x_models[CS420X_MODELS] = {
  959. [CS420X_MBP55] = "mbp55",
  960. [CS420X_IMAC27] = "imac27",
  961. [CS420X_AUTO] = "auto",
  962. };
  963. static struct snd_pci_quirk cs420x_cfg_tbl[] = {
  964. SND_PCI_QUIRK(0x10de, 0xcb79, "MacBookPro 5,5", CS420X_MBP55),
  965. SND_PCI_QUIRK(0x8086, 0x7270, "IMac 27 Inch", CS420X_IMAC27),
  966. {} /* terminator */
  967. };
  968. struct cs_pincfg {
  969. hda_nid_t nid;
  970. u32 val;
  971. };
  972. static struct cs_pincfg mbp55_pincfgs[] = {
  973. { 0x09, 0x012b4030 },
  974. { 0x0a, 0x90100121 },
  975. { 0x0b, 0x90100120 },
  976. { 0x0c, 0x400000f0 },
  977. { 0x0d, 0x90a00110 },
  978. { 0x0e, 0x400000f0 },
  979. { 0x0f, 0x400000f0 },
  980. { 0x10, 0x014be040 },
  981. { 0x12, 0x400000f0 },
  982. { 0x15, 0x400000f0 },
  983. {} /* terminator */
  984. };
  985. static struct cs_pincfg imac27_pincfgs[] = {
  986. { 0x09, 0x012b4050 },
  987. { 0x0a, 0x90100140 },
  988. { 0x0b, 0x90100142 },
  989. { 0x0c, 0x018b3020 },
  990. { 0x0d, 0x90a00110 },
  991. { 0x0e, 0x400000f0 },
  992. { 0x0f, 0x01cbe030 },
  993. { 0x10, 0x014be060 },
  994. { 0x12, 0x01ab9070 },
  995. { 0x15, 0x400000f0 },
  996. {} /* terminator */
  997. };
  998. static struct cs_pincfg *cs_pincfgs[CS420X_MODELS] = {
  999. [CS420X_MBP55] = mbp55_pincfgs,
  1000. [CS420X_IMAC27] = imac27_pincfgs,
  1001. };
  1002. static void fix_pincfg(struct hda_codec *codec, int model)
  1003. {
  1004. const struct cs_pincfg *cfg = cs_pincfgs[model];
  1005. if (!cfg)
  1006. return;
  1007. for (; cfg->nid; cfg++)
  1008. snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
  1009. }
  1010. static int patch_cs420x(struct hda_codec *codec)
  1011. {
  1012. struct cs_spec *spec;
  1013. int err;
  1014. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1015. if (!spec)
  1016. return -ENOMEM;
  1017. codec->spec = spec;
  1018. spec->board_config =
  1019. snd_hda_check_board_config(codec, CS420X_MODELS,
  1020. cs420x_models, cs420x_cfg_tbl);
  1021. if (spec->board_config >= 0)
  1022. fix_pincfg(codec, spec->board_config);
  1023. switch (spec->board_config) {
  1024. case CS420X_IMAC27:
  1025. case CS420X_MBP55:
  1026. /* GPIO1 = headphones */
  1027. /* GPIO3 = speakers */
  1028. spec->gpio_mask = 0x0a;
  1029. spec->gpio_dir = 0x0a;
  1030. break;
  1031. }
  1032. err = cs_parse_auto_config(codec);
  1033. if (err < 0)
  1034. goto error;
  1035. codec->patch_ops = cs_patch_ops;
  1036. return 0;
  1037. error:
  1038. kfree(codec->spec);
  1039. codec->spec = NULL;
  1040. return err;
  1041. }
  1042. /*
  1043. * patch entries
  1044. */
  1045. static struct hda_codec_preset snd_hda_preset_cirrus[] = {
  1046. { .id = 0x10134206, .name = "CS4206", .patch = patch_cs420x },
  1047. { .id = 0x10134207, .name = "CS4207", .patch = patch_cs420x },
  1048. {} /* terminator */
  1049. };
  1050. MODULE_ALIAS("snd-hda-codec-id:10134206");
  1051. MODULE_ALIAS("snd-hda-codec-id:10134207");
  1052. MODULE_LICENSE("GPL");
  1053. MODULE_DESCRIPTION("Cirrus Logic HD-audio codec");
  1054. static struct hda_codec_preset_list cirrus_list = {
  1055. .preset = snd_hda_preset_cirrus,
  1056. .owner = THIS_MODULE,
  1057. };
  1058. static int __init patch_cirrus_init(void)
  1059. {
  1060. return snd_hda_add_codec_preset(&cirrus_list);
  1061. }
  1062. static void __exit patch_cirrus_exit(void)
  1063. {
  1064. snd_hda_delete_codec_preset(&cirrus_list);
  1065. }
  1066. module_init(patch_cirrus_init)
  1067. module_exit(patch_cirrus_exit)