Lines Matching +full:codec +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0-or-later
22 static int cs8409_parse_auto_config(struct hda_codec *codec) in cs8409_parse_auto_config() argument
24 struct cs8409_spec *spec = codec->spec; in cs8409_parse_auto_config()
28 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); in cs8409_parse_auto_config()
32 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); in cs8409_parse_auto_config()
37 if (spec->gen.dyn_adc_switch) { in cs8409_parse_auto_config()
40 for (i = 0; i < spec->gen.input_mux.num_items; i++) { in cs8409_parse_auto_config()
41 int idx = spec->gen.dyn_adc_idx[i]; in cs8409_parse_auto_config()
43 if (done & (1 << idx)) in cs8409_parse_auto_config()
45 snd_hda_gen_fix_pin_power(codec, spec->gen.adc_nids[idx]); in cs8409_parse_auto_config()
46 done |= 1 << idx; in cs8409_parse_auto_config()
55 static struct cs8409_spec *cs8409_alloc_spec(struct hda_codec *codec) in cs8409_alloc_spec() argument
62 codec->spec = spec; in cs8409_alloc_spec()
63 spec->codec = codec; in cs8409_alloc_spec()
64 codec->power_save_node = 1; in cs8409_alloc_spec()
65 mutex_init(&spec->i2c_mux); in cs8409_alloc_spec()
66 INIT_DELAYED_WORK(&spec->i2c_clk_work, cs8409_disable_i2c_clock_worker); in cs8409_alloc_spec()
67 snd_hda_gen_spec_init(&spec->gen); in cs8409_alloc_spec()
72 static inline int cs8409_vendor_coef_get(struct hda_codec *codec, unsigned int idx) in cs8409_vendor_coef_get() argument
74 snd_hda_codec_write(codec, CS8409_PIN_VENDOR_WIDGET, 0, AC_VERB_SET_COEF_INDEX, idx); in cs8409_vendor_coef_get()
75 return snd_hda_codec_read(codec, CS8409_PIN_VENDOR_WIDGET, 0, AC_VERB_GET_PROC_COEF, 0); in cs8409_vendor_coef_get()
78 static inline void cs8409_vendor_coef_set(struct hda_codec *codec, unsigned int idx, in cs8409_vendor_coef_set() argument
81 snd_hda_codec_write(codec, CS8409_PIN_VENDOR_WIDGET, 0, AC_VERB_SET_COEF_INDEX, idx); in cs8409_vendor_coef_set()
82 snd_hda_codec_write(codec, CS8409_PIN_VENDOR_WIDGET, 0, AC_VERB_SET_PROC_COEF, coef); in cs8409_vendor_coef_set()
86 * cs8409_enable_i2c_clock - Disable I2C clocks
87 * @codec: the codec instance
91 static void cs8409_disable_i2c_clock(struct hda_codec *codec) in cs8409_disable_i2c_clock() argument
93 struct cs8409_spec *spec = codec->spec; in cs8409_disable_i2c_clock()
95 mutex_lock(&spec->i2c_mux); in cs8409_disable_i2c_clock()
96 if (spec->i2c_clck_enabled) { in cs8409_disable_i2c_clock()
97 cs8409_vendor_coef_set(spec->codec, 0x0, in cs8409_disable_i2c_clock()
98 cs8409_vendor_coef_get(spec->codec, 0x0) & 0xfffffff7); in cs8409_disable_i2c_clock()
99 spec->i2c_clck_enabled = 0; in cs8409_disable_i2c_clock()
101 mutex_unlock(&spec->i2c_mux); in cs8409_disable_i2c_clock()
105 * cs8409_disable_i2c_clock_worker - Worker that disable the I2C Clock after 25ms without use
111 cs8409_disable_i2c_clock(spec->codec); in cs8409_disable_i2c_clock_worker()
115 * cs8409_enable_i2c_clock - Enable I2C clocks
116 * @codec: the codec instance
120 static void cs8409_enable_i2c_clock(struct hda_codec *codec) in cs8409_enable_i2c_clock() argument
122 struct cs8409_spec *spec = codec->spec; in cs8409_enable_i2c_clock()
128 * afterwards in the scenario. The next enable call will re-enable the clock, regardless. in cs8409_enable_i2c_clock()
130 cancel_delayed_work(&spec->i2c_clk_work); in cs8409_enable_i2c_clock()
132 if (!spec->i2c_clck_enabled) { in cs8409_enable_i2c_clock()
133 cs8409_vendor_coef_set(codec, 0x0, cs8409_vendor_coef_get(codec, 0x0) | 0x8); in cs8409_enable_i2c_clock()
134 spec->i2c_clck_enabled = 1; in cs8409_enable_i2c_clock()
136 queue_delayed_work(system_power_efficient_wq, &spec->i2c_clk_work, msecs_to_jiffies(25)); in cs8409_enable_i2c_clock()
140 * cs8409_i2c_wait_complete - Wait for I2C transaction
141 * @codec: the codec instance
144 * Return -ETIMEDOUT if transaction wait times out.
146 static int cs8409_i2c_wait_complete(struct hda_codec *codec) in cs8409_i2c_wait_complete() argument
151 CS42L42_I2C_SLEEP_US, CS42L42_I2C_TIMEOUT_US, false, codec, CS8409_I2C_STS); in cs8409_i2c_wait_complete()
155 * cs8409_set_i2c_dev_addr - Set i2c address for transaction
156 * @codec: the codec instance
159 static void cs8409_set_i2c_dev_addr(struct hda_codec *codec, unsigned int addr) in cs8409_set_i2c_dev_addr() argument
161 struct cs8409_spec *spec = codec->spec; in cs8409_set_i2c_dev_addr()
163 if (spec->dev_addr != addr) { in cs8409_set_i2c_dev_addr()
164 cs8409_vendor_coef_set(codec, CS8409_I2C_ADDR, addr); in cs8409_set_i2c_dev_addr()
165 spec->dev_addr = addr; in cs8409_set_i2c_dev_addr()
170 * cs8409_i2c_set_page - CS8409 I2C set page register.
171 * @scodec: the codec instance
178 struct hda_codec *codec = scodec->codec; in cs8409_i2c_set_page() local
180 if (scodec->paged && (scodec->last_page != (i2c_reg >> 8))) { in cs8409_i2c_set_page()
181 cs8409_vendor_coef_set(codec, CS8409_I2C_QWRITE, i2c_reg >> 8); in cs8409_i2c_set_page()
182 if (cs8409_i2c_wait_complete(codec) < 0) in cs8409_i2c_set_page()
183 return -EIO; in cs8409_i2c_set_page()
184 scodec->last_page = i2c_reg >> 8; in cs8409_i2c_set_page()
191 * cs8409_i2c_read - CS8409 I2C Read.
192 * @scodec: the codec instance
195 * Returns negative on error, otherwise returns read value in bits 0-7.
199 struct hda_codec *codec = scodec->codec; in cs8409_i2c_read() local
200 struct cs8409_spec *spec = codec->spec; in cs8409_i2c_read()
204 if (scodec->suspended) in cs8409_i2c_read()
205 return -EPERM; in cs8409_i2c_read()
207 mutex_lock(&spec->i2c_mux); in cs8409_i2c_read()
208 cs8409_enable_i2c_clock(codec); in cs8409_i2c_read()
209 cs8409_set_i2c_dev_addr(codec, scodec->addr); in cs8409_i2c_read()
215 cs8409_vendor_coef_set(codec, CS8409_I2C_QREAD, i2c_reg_data); in cs8409_i2c_read()
216 if (cs8409_i2c_wait_complete(codec) < 0) in cs8409_i2c_read()
219 /* Register in bits 15-8 and the data in 7-0 */ in cs8409_i2c_read()
220 read_data = cs8409_vendor_coef_get(codec, CS8409_I2C_QREAD); in cs8409_i2c_read()
222 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_read()
227 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_read()
228 codec_err(codec, "%s() Failed 0x%02x : 0x%04x\n", __func__, scodec->addr, addr); in cs8409_i2c_read()
229 return -EIO; in cs8409_i2c_read()
233 * cs8409_i2c_bulk_read - CS8409 I2C Read Sequence.
234 * @scodec: the codec instance
242 struct hda_codec *codec = scodec->codec; in cs8409_i2c_bulk_read() local
243 struct cs8409_spec *spec = codec->spec; in cs8409_i2c_bulk_read()
247 if (scodec->suspended) in cs8409_i2c_bulk_read()
248 return -EPERM; in cs8409_i2c_bulk_read()
250 mutex_lock(&spec->i2c_mux); in cs8409_i2c_bulk_read()
251 cs8409_set_i2c_dev_addr(codec, scodec->addr); in cs8409_i2c_bulk_read()
254 cs8409_enable_i2c_clock(codec); in cs8409_i2c_bulk_read()
259 cs8409_vendor_coef_set(codec, CS8409_I2C_QREAD, i2c_reg_data); in cs8409_i2c_bulk_read()
261 if (cs8409_i2c_wait_complete(codec) < 0) in cs8409_i2c_bulk_read()
264 seq[i].value = cs8409_vendor_coef_get(codec, CS8409_I2C_QREAD) & 0xff; in cs8409_i2c_bulk_read()
267 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_bulk_read()
272 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_bulk_read()
273 codec_err(codec, "I2C Bulk Write Failed 0x%02x\n", scodec->addr); in cs8409_i2c_bulk_read()
274 return -EIO; in cs8409_i2c_bulk_read()
278 * cs8409_i2c_write - CS8409 I2C Write.
279 * @scodec: the codec instance
287 struct hda_codec *codec = scodec->codec; in cs8409_i2c_write() local
288 struct cs8409_spec *spec = codec->spec; in cs8409_i2c_write()
291 if (scodec->suspended) in cs8409_i2c_write()
292 return -EPERM; in cs8409_i2c_write()
294 mutex_lock(&spec->i2c_mux); in cs8409_i2c_write()
296 cs8409_enable_i2c_clock(codec); in cs8409_i2c_write()
297 cs8409_set_i2c_dev_addr(codec, scodec->addr); in cs8409_i2c_write()
303 cs8409_vendor_coef_set(codec, CS8409_I2C_QWRITE, i2c_reg_data); in cs8409_i2c_write()
305 if (cs8409_i2c_wait_complete(codec) < 0) in cs8409_i2c_write()
308 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_write()
312 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_write()
313 codec_err(codec, "%s() Failed 0x%02x : 0x%04x\n", __func__, scodec->addr, addr); in cs8409_i2c_write()
314 return -EIO; in cs8409_i2c_write()
318 * cs8409_i2c_bulk_write - CS8409 I2C Write Sequence.
319 * @scodec: the codec instance
328 struct hda_codec *codec = scodec->codec; in cs8409_i2c_bulk_write() local
329 struct cs8409_spec *spec = codec->spec; in cs8409_i2c_bulk_write()
333 if (scodec->suspended) in cs8409_i2c_bulk_write()
334 return -EPERM; in cs8409_i2c_bulk_write()
336 mutex_lock(&spec->i2c_mux); in cs8409_i2c_bulk_write()
337 cs8409_set_i2c_dev_addr(codec, scodec->addr); in cs8409_i2c_bulk_write()
340 cs8409_enable_i2c_clock(codec); in cs8409_i2c_bulk_write()
345 cs8409_vendor_coef_set(codec, CS8409_I2C_QWRITE, i2c_reg_data); in cs8409_i2c_bulk_write()
347 if (cs8409_i2c_wait_complete(codec) < 0) in cs8409_i2c_bulk_write()
351 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_bulk_write()
356 mutex_unlock(&spec->i2c_mux); in cs8409_i2c_bulk_write()
357 codec_err(codec, "I2C Bulk Write Failed 0x%02x\n", scodec->addr); in cs8409_i2c_bulk_write()
358 return -EIO; in cs8409_i2c_bulk_write()
361 static int cs8409_init(struct hda_codec *codec) in cs8409_init() argument
363 int ret = snd_hda_gen_init(codec); in cs8409_init()
366 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT); in cs8409_init()
371 static int cs8409_build_controls(struct hda_codec *codec) in cs8409_build_controls() argument
375 err = snd_hda_gen_build_controls(codec); in cs8409_build_controls()
378 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD); in cs8409_build_controls()
384 static void cs8409_enable_ur(struct hda_codec *codec, int flag) in cs8409_enable_ur() argument
386 struct cs8409_spec *spec = codec->spec; in cs8409_enable_ur()
390 for (i = 0; i < spec->num_scodecs; i++) in cs8409_enable_ur()
391 ur_gpios |= spec->scodecs[i]->irq_mask; in cs8409_enable_ur()
393 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, in cs8409_enable_ur()
396 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_UNSOLICITED_ENABLE, in cs8409_enable_ur()
400 static void cs8409_fix_caps(struct hda_codec *codec, unsigned int nid) in cs8409_fix_caps() argument
405 * companion codec. Most of input/output PIN(s) have only basic in cs8409_fix_caps()
409 * phantom jacks. However, a companion codec may be in cs8409_fix_caps()
414 caps = snd_hdac_read_parm(&codec->core, nid, AC_PAR_PIN_CAP); in cs8409_fix_caps()
416 snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, in cs8409_fix_caps()
419 snd_hda_override_wcaps(codec, nid, (get_wcaps(codec, nid) | AC_WCAP_UNSOL_CAP)); in cs8409_fix_caps()
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in cs8409_spk_sw_gpio_get() local
426 struct cs8409_spec *spec = codec->spec; in cs8409_spk_sw_gpio_get()
428 ucontrol->value.integer.value[0] = !!(spec->gpio_data & spec->speaker_pdn_gpio); in cs8409_spk_sw_gpio_get()
435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); in cs8409_spk_sw_gpio_put() local
436 struct cs8409_spec *spec = codec->spec; in cs8409_spk_sw_gpio_put()
439 gpio_data = (spec->gpio_data & ~spec->speaker_pdn_gpio) | in cs8409_spk_sw_gpio_put()
440 (ucontrol->value.integer.value[0] ? spec->speaker_pdn_gpio : 0); in cs8409_spk_sw_gpio_put()
441 if (gpio_data == spec->gpio_data) in cs8409_spk_sw_gpio_put()
443 spec->gpio_data = gpio_data; in cs8409_spk_sw_gpio_put()
444 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data); in cs8409_spk_sw_gpio_put()
445 return 1; in cs8409_spk_sw_gpio_put()
464 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in cs42l42_volume_info()
465 uinfo->value.integer.step = 1; in cs42l42_volume_info()
466 uinfo->count = chs == 3 ? 2 : 1; in cs42l42_volume_info()
470 uinfo->value.integer.min = CS42L42_HP_VOL_REAL_MIN; in cs42l42_volume_info()
471 uinfo->value.integer.max = CS42L42_HP_VOL_REAL_MAX; in cs42l42_volume_info()
474 uinfo->value.integer.min = CS42L42_AMIC_VOL_REAL_MIN; in cs42l42_volume_info()
475 uinfo->value.integer.max = CS42L42_AMIC_VOL_REAL_MAX; in cs42l42_volume_info()
486 struct hda_codec *codec = snd_kcontrol_chip(kctrl); in cs42l42_volume_get() local
487 struct cs8409_spec *spec = codec->spec; in cs42l42_volume_get()
488 struct sub_codec *cs42l42 = spec->scodecs[get_amp_index(kctrl)]; in cs42l42_volume_get()
491 long *valp = uctrl->value.integer.value; in cs42l42_volume_get()
496 *valp++ = cs42l42->vol[ofs]; in cs42l42_volume_get()
497 if (chs & BIT(1)) in cs42l42_volume_get()
498 *valp = cs42l42->vol[ofs+1]; in cs42l42_volume_get()
502 *valp = cs42l42->vol[ofs]; in cs42l42_volume_get()
518 if (chs & BIT(1)) in cs42l42_mute()
528 -(cs42l42->vol[CS42L42_DAC_CH0_VOL_OFFSET]) in cs42l42_mute()
530 if (chs & BIT(1)) in cs42l42_mute()
532 -(cs42l42->vol[CS42L42_DAC_CH1_VOL_OFFSET]) in cs42l42_mute()
537 cs42l42->vol[CS42L42_ADC_VOL_OFFSET] in cs42l42_mute()
545 struct hda_codec *codec = snd_kcontrol_chip(kctrl); in cs42l42_volume_put() local
546 struct cs8409_spec *spec = codec->spec; in cs42l42_volume_put()
547 struct sub_codec *cs42l42 = spec->scodecs[get_amp_index(kctrl)]; in cs42l42_volume_put()
550 long *valp = uctrl->value.integer.value; in cs42l42_volume_put()
555 cs42l42->vol[ofs] = *valp; in cs42l42_volume_put()
556 if (chs & BIT(1)) { in cs42l42_volume_put()
558 cs42l42->vol[ofs + 1] = *valp; in cs42l42_volume_put()
560 if (spec->playback_started) in cs42l42_volume_put()
565 cs42l42->vol[ofs] = *valp; in cs42l42_volume_put()
566 if (spec->capture_started) in cs42l42_volume_put()
577 struct hda_codec *codec, in cs42l42_playback_pcm_hook() argument
581 struct cs8409_spec *spec = codec->spec; in cs42l42_playback_pcm_hook()
589 spec->playback_started = 1; in cs42l42_playback_pcm_hook()
593 spec->playback_started = 0; in cs42l42_playback_pcm_hook()
599 for (i = 0; i < spec->num_scodecs; i++) { in cs42l42_playback_pcm_hook()
600 cs42l42 = spec->scodecs[i]; in cs42l42_playback_pcm_hook()
606 struct hda_codec *codec, in cs42l42_capture_pcm_hook() argument
610 struct cs8409_spec *spec = codec->spec; in cs42l42_capture_pcm_hook()
618 spec->capture_started = 1; in cs42l42_capture_pcm_hook()
622 spec->capture_started = 0; in cs42l42_capture_pcm_hook()
628 for (i = 0; i < spec->num_scodecs; i++) { in cs42l42_capture_pcm_hook()
629 cs42l42 = spec->scodecs[i]; in cs42l42_capture_pcm_hook()
634 /* Configure CS42L42 slave codec for jack autodetect */
637 cs8409_i2c_write(cs42l42, CS42L42_HSBIAS_SC_AUTOCTL, cs42l42->hsbias_hiz); in cs42l42_enable_jack_detect()
650 /* Enable and run CS42L42 slave codec jack auto detect */
680 (1 << CS42L42_HSDET_CTRL_SHIFT) | in cs42l42_manual_hs_det()
690 /* Open the SW_HSB_HS3 switch and close SW_HSB_HS4 for a Type 1 headset. */ in cs42l42_manual_hs_det()
710 CS42L42_HSDET_COMP1_OUT_SHIFT) << 1; in cs42l42_manual_hs_det()
712 CS42L42_HSDET_COMP2_OUT_SHIFT) << 1; in cs42l42_manual_hs_det()
714 /* Use Comparator 1 with 1.25V Threshold. */ in cs42l42_manual_hs_det()
771 if (cs42l42->no_type_dect) { in cs42l42_handle_tip_sense()
772 status_changed = 1; in cs42l42_handle_tip_sense()
773 cs42l42->hp_jack_in = 1; in cs42l42_handle_tip_sense()
774 cs42l42->mic_jack_in = 0; in cs42l42_handle_tip_sense()
781 status_changed = 1; in cs42l42_handle_tip_sense()
782 cs42l42->hp_jack_in = 0; in cs42l42_handle_tip_sense()
783 cs42l42->mic_jack_in = 0; in cs42l42_handle_tip_sense()
790 codec_dbg(cs42l42->codec, "Tip Sense Detection: (%d)\n", reg_ts_status); in cs42l42_handle_tip_sense()
811 return -EIO; in cs42l42_jack_unsol_event()
827 if (cs42l42->no_type_dect) { in cs42l42_jack_unsol_event()
831 codec_dbg(cs42l42->codec, in cs42l42_jack_unsol_event()
840 status_changed = 1; in cs42l42_jack_unsol_event()
841 cs42l42->hp_jack_in = 1; in cs42l42_jack_unsol_event()
842 cs42l42->mic_jack_in = 1; in cs42l42_jack_unsol_event()
845 status_changed = 1; in cs42l42_jack_unsol_event()
846 cs42l42->hp_jack_in = 1; in cs42l42_jack_unsol_event()
847 cs42l42->mic_jack_in = 0; in cs42l42_jack_unsol_event()
850 status_changed = 1; in cs42l42_jack_unsol_event()
851 cs42l42->hp_jack_in = 0; in cs42l42_jack_unsol_event()
852 cs42l42->mic_jack_in = 0; in cs42l42_jack_unsol_event()
855 codec_dbg(cs42l42->codec, "Detection done (%d)\n", type); in cs42l42_jack_unsol_event()
858 /* Enable the HPOUT ground clamp and configure the HP pull-down */ in cs42l42_jack_unsol_event()
860 /* Re-Enable Tip Sense Interrupt */ in cs42l42_jack_unsol_event()
871 struct hda_codec *codec = cs42l42->codec; in cs42l42_resume() local
872 struct cs8409_spec *spec = codec->spec; in cs42l42_resume()
882 spec->gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0); in cs42l42_resume()
883 spec->gpio_data |= cs42l42->reset_gpio; in cs42l42_resume()
884 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data); in cs42l42_resume()
887 cs42l42->suspended = 0; in cs42l42_resume()
889 /* Initialize CS42L42 companion codec */ in cs42l42_resume()
890 cs8409_i2c_bulk_write(cs42l42, cs42l42->init_seq, cs42l42->init_seq_num); in cs42l42_resume()
897 if (cs42l42->full_scale_vol == CS42L42_FULL_SCALE_VOL_0DB) in cs42l42_resume()
907 snd_hda_codec_allow_unsol_events(cs42l42->codec); in cs42l42_resume()
914 struct hda_codec *codec = cs42l42->codec; in cs42l42_suspend() local
915 struct cs8409_spec *spec = codec->spec; in cs42l42_suspend()
936 codec_warn(codec, "Timeout waiting for PDN_DONE for CS42L42\n"); in cs42l42_suspend()
940 cs42l42->suspended = 1; in cs42l42_suspend()
941 cs42l42->last_page = 0; in cs42l42_suspend()
942 cs42l42->hp_jack_in = 0; in cs42l42_suspend()
943 cs42l42->mic_jack_in = 0; in cs42l42_suspend()
946 spec->gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0); in cs42l42_suspend()
947 spec->gpio_data &= ~cs42l42->reset_gpio; in cs42l42_suspend()
948 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data); in cs42l42_suspend()
951 static void cs8409_free(struct hda_codec *codec) in cs8409_free() argument
953 struct cs8409_spec *spec = codec->spec; in cs8409_free()
956 cancel_delayed_work_sync(&spec->i2c_clk_work); in cs8409_free()
957 cs8409_disable_i2c_clock(codec); in cs8409_free()
959 snd_hda_gen_free(codec); in cs8409_free()
969 * and 0x34 where hs mic and hp are connected. Companion codec CS42L42 will
974 static void cs8409_cs42l42_jack_unsol_event(struct hda_codec *codec, unsigned int res) in cs8409_cs42l42_jack_unsol_event() argument
976 struct cs8409_spec *spec = codec->spec; in cs8409_cs42l42_jack_unsol_event()
977 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0]; in cs8409_cs42l42_jack_unsol_event()
985 if (res & cs42l42->irq_mask) in cs8409_cs42l42_jack_unsol_event()
989 snd_hda_set_pin_ctl(codec, CS8409_CS42L42_SPK_PIN_NID, in cs8409_cs42l42_jack_unsol_event()
990 cs42l42->hp_jack_in ? 0 : PIN_OUT); in cs8409_cs42l42_jack_unsol_event()
992 jk = snd_hda_jack_tbl_get_mst(codec, CS8409_CS42L42_HP_PIN_NID, 0); in cs8409_cs42l42_jack_unsol_event()
994 snd_hda_jack_unsol_event(codec, (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & in cs8409_cs42l42_jack_unsol_event()
997 jk = snd_hda_jack_tbl_get_mst(codec, CS8409_CS42L42_AMIC_PIN_NID, 0); in cs8409_cs42l42_jack_unsol_event()
999 snd_hda_jack_unsol_event(codec, (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & in cs8409_cs42l42_jack_unsol_event()
1005 static int cs8409_cs42l42_suspend(struct hda_codec *codec) in cs8409_cs42l42_suspend() argument
1007 struct cs8409_spec *spec = codec->spec; in cs8409_cs42l42_suspend()
1010 spec->init_done = 0; in cs8409_cs42l42_suspend()
1012 cs8409_enable_ur(codec, 0); in cs8409_cs42l42_suspend()
1014 for (i = 0; i < spec->num_scodecs; i++) in cs8409_cs42l42_suspend()
1015 cs42l42_suspend(spec->scodecs[i]); in cs8409_cs42l42_suspend()
1018 cancel_delayed_work_sync(&spec->i2c_clk_work); in cs8409_cs42l42_suspend()
1019 cs8409_disable_i2c_clock(codec); in cs8409_cs42l42_suspend()
1021 snd_hda_shutup_pins(codec); in cs8409_cs42l42_suspend()
1029 static void cs8409_cs42l42_hw_init(struct hda_codec *codec) in cs8409_cs42l42_hw_init() argument
1033 struct cs8409_spec *spec = codec->spec; in cs8409_cs42l42_hw_init()
1034 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0]; in cs8409_cs42l42_hw_init()
1036 if (spec->gpio_mask) { in cs8409_cs42l42_hw_init()
1037 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_MASK, in cs8409_cs42l42_hw_init()
1038 spec->gpio_mask); in cs8409_cs42l42_hw_init()
1039 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DIRECTION, in cs8409_cs42l42_hw_init()
1040 spec->gpio_dir); in cs8409_cs42l42_hw_init()
1041 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, in cs8409_cs42l42_hw_init()
1042 spec->gpio_data); in cs8409_cs42l42_hw_init()
1045 for (; seq->nid; seq++) in cs8409_cs42l42_hw_init()
1046 cs8409_vendor_coef_set(codec, seq->cir, seq->coeff); in cs8409_cs42l42_hw_init()
1048 if (codec->fixup_id == CS8409_BULLSEYE) { in cs8409_cs42l42_hw_init()
1049 for (; seq_bullseye->nid; seq_bullseye++) in cs8409_cs42l42_hw_init()
1050 cs8409_vendor_coef_set(codec, seq_bullseye->cir, seq_bullseye->coeff); in cs8409_cs42l42_hw_init()
1053 switch (codec->fixup_id) { in cs8409_cs42l42_hw_init()
1056 /* DMIC1_MO=00b, DMIC1/2_SR=1 */ in cs8409_cs42l42_hw_init()
1057 cs8409_vendor_coef_set(codec, CS8409_DMIC_CFG, 0x0003); in cs8409_cs42l42_hw_init()
1060 /* ASP1/2_xxx_EN=1, ASP1/2_MCLK_EN=0, DMIC1_SCL_EN=0 */ in cs8409_cs42l42_hw_init()
1061 cs8409_vendor_coef_set(codec, CS8409_PAD_CFG_SLW_RATE_CTRL, 0xfc00); in cs8409_cs42l42_hw_init()
1070 cs8409_enable_ur(codec, 1); in cs8409_cs42l42_hw_init()
1085 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in cs8409_cs42l42_exec_verb() local
1086 struct cs8409_spec *spec = codec->spec; in cs8409_cs42l42_exec_verb()
1087 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0]; in cs8409_cs42l42_exec_verb()
1100 *res = (cs42l42->hp_jack_in) ? AC_PINSENSE_PRESENCE : 0; in cs8409_cs42l42_exec_verb()
1106 *res = (cs42l42->mic_jack_in) ? AC_PINSENSE_PRESENCE : 0; in cs8409_cs42l42_exec_verb()
1114 return spec->exec_verb(dev, cmd, flags, res); in cs8409_cs42l42_exec_verb()
1117 void cs8409_cs42l42_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int action) in cs8409_cs42l42_fixups() argument
1119 struct cs8409_spec *spec = codec->spec; in cs8409_cs42l42_fixups()
1123 snd_hda_add_verbs(codec, cs8409_cs42l42_init_verbs); in cs8409_cs42l42_fixups()
1125 spec->exec_verb = codec->core.exec_verb; in cs8409_cs42l42_fixups()
1126 codec->core.exec_verb = cs8409_cs42l42_exec_verb; in cs8409_cs42l42_fixups()
1128 spec->scodecs[CS8409_CODEC0] = &cs8409_cs42l42_codec; in cs8409_cs42l42_fixups()
1129 spec->num_scodecs = 1; in cs8409_cs42l42_fixups()
1130 spec->scodecs[CS8409_CODEC0]->codec = codec; in cs8409_cs42l42_fixups()
1131 codec->patch_ops = cs8409_cs42l42_patch_ops; in cs8409_cs42l42_fixups()
1133 spec->gen.suppress_auto_mute = 1; in cs8409_cs42l42_fixups()
1134 spec->gen.no_primary_hp = 1; in cs8409_cs42l42_fixups()
1135 spec->gen.suppress_vmaster = 1; in cs8409_cs42l42_fixups()
1137 spec->speaker_pdn_gpio = 0; in cs8409_cs42l42_fixups()
1140 spec->gpio_dir = spec->scodecs[CS8409_CODEC0]->reset_gpio; in cs8409_cs42l42_fixups()
1141 spec->gpio_data = 0; in cs8409_cs42l42_fixups()
1142 spec->gpio_mask = 0x03f; in cs8409_cs42l42_fixups()
1145 snd_hda_sequence_write(codec, cs8409_cs42l42_init_verbs); in cs8409_cs42l42_fixups()
1147 cs8409_fix_caps(codec, CS8409_CS42L42_HP_PIN_NID); in cs8409_cs42l42_fixups()
1148 cs8409_fix_caps(codec, CS8409_CS42L42_AMIC_PIN_NID); in cs8409_cs42l42_fixups()
1150 spec->scodecs[CS8409_CODEC0]->hsbias_hiz = 0x0020; in cs8409_cs42l42_fixups()
1152 switch (codec->fixup_id) { in cs8409_cs42l42_fixups()
1154 spec->scodecs[CS8409_CODEC0]->full_scale_vol = in cs8409_cs42l42_fixups()
1156 spec->speaker_pdn_gpio = CS8409_CYBORG_SPEAKER_PDN; in cs8409_cs42l42_fixups()
1159 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_0DB; in cs8409_cs42l42_fixups()
1160 spec->speaker_pdn_gpio = CS8409_CYBORG_SPEAKER_PDN; in cs8409_cs42l42_fixups()
1164 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_0DB; in cs8409_cs42l42_fixups()
1165 spec->speaker_pdn_gpio = CS8409_WARLOCK_SPEAKER_PDN; in cs8409_cs42l42_fixups()
1168 spec->scodecs[CS8409_CODEC0]->full_scale_vol = in cs8409_cs42l42_fixups()
1170 spec->speaker_pdn_gpio = CS8409_WARLOCK_SPEAKER_PDN; in cs8409_cs42l42_fixups()
1174 if (spec->speaker_pdn_gpio > 0) { in cs8409_cs42l42_fixups()
1175 spec->gpio_dir |= spec->speaker_pdn_gpio; in cs8409_cs42l42_fixups()
1176 spec->gpio_data |= spec->speaker_pdn_gpio; in cs8409_cs42l42_fixups()
1182 spec->gen.stream_analog_playback = &cs42l42_48k_pcm_analog_playback; in cs8409_cs42l42_fixups()
1183 spec->gen.stream_analog_capture = &cs42l42_48k_pcm_analog_capture; in cs8409_cs42l42_fixups()
1185 spec->gen.pcm_playback_hook = cs42l42_playback_pcm_hook; in cs8409_cs42l42_fixups()
1186 spec->gen.pcm_capture_hook = cs42l42_capture_pcm_hook; in cs8409_cs42l42_fixups()
1187 if (codec->fixup_id != CS8409_ODIN) in cs8409_cs42l42_fixups()
1188 /* Set initial DMIC volume to -26 dB */ in cs8409_cs42l42_fixups()
1189 snd_hda_codec_amp_init_stereo(codec, CS8409_CS42L42_DMIC_ADC_PIN_NID, in cs8409_cs42l42_fixups()
1191 snd_hda_gen_add_kctl(&spec->gen, "Headphone Playback Volume", in cs8409_cs42l42_fixups()
1193 snd_hda_gen_add_kctl(&spec->gen, "Mic Capture Volume", in cs8409_cs42l42_fixups()
1195 if (spec->speaker_pdn_gpio > 0) in cs8409_cs42l42_fixups()
1196 snd_hda_gen_add_kctl(&spec->gen, "Speaker Playback Switch", in cs8409_cs42l42_fixups()
1199 cs8409_enable_ur(codec, 0); in cs8409_cs42l42_fixups()
1200 snd_hda_codec_set_name(codec, "CS8409/CS42L42"); in cs8409_cs42l42_fixups()
1203 cs8409_cs42l42_hw_init(codec); in cs8409_cs42l42_fixups()
1204 spec->init_done = 1; in cs8409_cs42l42_fixups()
1205 if (spec->init_done && spec->build_ctrl_done in cs8409_cs42l42_fixups()
1206 && !spec->scodecs[CS8409_CODEC0]->hp_jack_in) in cs8409_cs42l42_fixups()
1207 cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]); in cs8409_cs42l42_fixups()
1210 spec->build_ctrl_done = 1; in cs8409_cs42l42_fixups()
1216 if (spec->init_done && spec->build_ctrl_done in cs8409_cs42l42_fixups()
1217 && !spec->scodecs[CS8409_CODEC0]->hp_jack_in) in cs8409_cs42l42_fixups()
1218 cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]); in cs8409_cs42l42_fixups()
1232 * hs mic and hp are connected. Companion codec CS42L42 will
1237 static void dolphin_jack_unsol_event(struct hda_codec *codec, unsigned int res) in dolphin_jack_unsol_event() argument
1239 struct cs8409_spec *spec = codec->spec; in dolphin_jack_unsol_event()
1243 cs42l42 = spec->scodecs[CS8409_CODEC0]; in dolphin_jack_unsol_event()
1244 if (!cs42l42->suspended && (~res & cs42l42->irq_mask) && in dolphin_jack_unsol_event()
1246 jk = snd_hda_jack_tbl_get_mst(codec, DOLPHIN_HP_PIN_NID, 0); in dolphin_jack_unsol_event()
1248 snd_hda_jack_unsol_event(codec, in dolphin_jack_unsol_event()
1249 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & in dolphin_jack_unsol_event()
1252 jk = snd_hda_jack_tbl_get_mst(codec, DOLPHIN_AMIC_PIN_NID, 0); in dolphin_jack_unsol_event()
1254 snd_hda_jack_unsol_event(codec, in dolphin_jack_unsol_event()
1255 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & in dolphin_jack_unsol_event()
1259 cs42l42 = spec->scodecs[CS8409_CODEC1]; in dolphin_jack_unsol_event()
1260 if (!cs42l42->suspended && (~res & cs42l42->irq_mask) && in dolphin_jack_unsol_event()
1262 jk = snd_hda_jack_tbl_get_mst(codec, DOLPHIN_LO_PIN_NID, 0); in dolphin_jack_unsol_event()
1264 snd_hda_jack_unsol_event(codec, in dolphin_jack_unsol_event()
1265 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) & in dolphin_jack_unsol_event()
1273 static void dolphin_hw_init(struct hda_codec *codec) in dolphin_hw_init() argument
1276 struct cs8409_spec *spec = codec->spec; in dolphin_hw_init()
1280 if (spec->gpio_mask) { in dolphin_hw_init()
1281 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_MASK, in dolphin_hw_init()
1282 spec->gpio_mask); in dolphin_hw_init()
1283 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DIRECTION, in dolphin_hw_init()
1284 spec->gpio_dir); in dolphin_hw_init()
1285 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, in dolphin_hw_init()
1286 spec->gpio_data); in dolphin_hw_init()
1289 for (; seq->nid; seq++) in dolphin_hw_init()
1290 cs8409_vendor_coef_set(codec, seq->cir, seq->coeff); in dolphin_hw_init()
1292 for (i = 0; i < spec->num_scodecs; i++) { in dolphin_hw_init()
1293 cs42l42 = spec->scodecs[i]; in dolphin_hw_init()
1298 cs8409_enable_ur(codec, 1); in dolphin_hw_init()
1313 struct hda_codec *codec = container_of(dev, struct hda_codec, core); in dolphin_exec_verb() local
1314 struct cs8409_spec *spec = codec->spec; in dolphin_exec_verb()
1315 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0]; in dolphin_exec_verb()
1329 cs42l42 = spec->scodecs[CS8409_CODEC1]; in dolphin_exec_verb()
1331 *res = (cs42l42->hp_jack_in) ? AC_PINSENSE_PRESENCE : 0; in dolphin_exec_verb()
1337 *res = (cs42l42->mic_jack_in) ? AC_PINSENSE_PRESENCE : 0; in dolphin_exec_verb()
1345 return spec->exec_verb(dev, cmd, flags, res); in dolphin_exec_verb()
1348 void dolphin_fixups(struct hda_codec *codec, const struct hda_fixup *fix, int action) in dolphin_fixups() argument
1350 struct cs8409_spec *spec = codec->spec; in dolphin_fixups()
1356 snd_hda_add_verbs(codec, dolphin_init_verbs); in dolphin_fixups()
1358 spec->exec_verb = codec->core.exec_verb; in dolphin_fixups()
1359 codec->core.exec_verb = dolphin_exec_verb; in dolphin_fixups()
1361 spec->scodecs[CS8409_CODEC0] = &dolphin_cs42l42_0; in dolphin_fixups()
1362 spec->scodecs[CS8409_CODEC0]->codec = codec; in dolphin_fixups()
1363 spec->scodecs[CS8409_CODEC1] = &dolphin_cs42l42_1; in dolphin_fixups()
1364 spec->scodecs[CS8409_CODEC1]->codec = codec; in dolphin_fixups()
1365 spec->num_scodecs = 2; in dolphin_fixups()
1366 spec->gen.suppress_vmaster = 1; in dolphin_fixups()
1368 codec->patch_ops = cs8409_dolphin_patch_ops; in dolphin_fixups()
1370 /* GPIO 1,5 out, 0,4 in */ in dolphin_fixups()
1371 spec->gpio_dir = spec->scodecs[CS8409_CODEC0]->reset_gpio | in dolphin_fixups()
1372 spec->scodecs[CS8409_CODEC1]->reset_gpio; in dolphin_fixups()
1373 spec->gpio_data = 0; in dolphin_fixups()
1374 spec->gpio_mask = 0x03f; in dolphin_fixups()
1377 snd_hda_sequence_write(codec, dolphin_init_verbs); in dolphin_fixups()
1379 snd_hda_jack_add_kctl(codec, DOLPHIN_LO_PIN_NID, "Line Out", true, in dolphin_fixups()
1382 snd_hda_jack_add_kctl(codec, DOLPHIN_AMIC_PIN_NID, "Microphone", true, in dolphin_fixups()
1385 cs8409_fix_caps(codec, DOLPHIN_HP_PIN_NID); in dolphin_fixups()
1386 cs8409_fix_caps(codec, DOLPHIN_LO_PIN_NID); in dolphin_fixups()
1387 cs8409_fix_caps(codec, DOLPHIN_AMIC_PIN_NID); in dolphin_fixups()
1389 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_MINUS6DB; in dolphin_fixups()
1390 spec->scodecs[CS8409_CODEC1]->full_scale_vol = CS42L42_FULL_SCALE_VOL_MINUS6DB; in dolphin_fixups()
1395 spec->gen.stream_analog_playback = &cs42l42_48k_pcm_analog_playback; in dolphin_fixups()
1396 spec->gen.stream_analog_capture = &cs42l42_48k_pcm_analog_capture; in dolphin_fixups()
1398 spec->gen.pcm_playback_hook = cs42l42_playback_pcm_hook; in dolphin_fixups()
1399 spec->gen.pcm_capture_hook = cs42l42_capture_pcm_hook; in dolphin_fixups()
1400 snd_hda_gen_add_kctl(&spec->gen, "Headphone Playback Volume", in dolphin_fixups()
1402 snd_hda_gen_add_kctl(&spec->gen, "Mic Capture Volume", &cs42l42_adc_volume_mixer); in dolphin_fixups()
1403 kctrl = snd_hda_gen_add_kctl(&spec->gen, "Line Out Playback Volume", in dolphin_fixups()
1407 kctrl->private_value = HDA_COMPOSE_AMP_VAL_OFS(DOLPHIN_HP_PIN_NID, 3, CS8409_CODEC1, in dolphin_fixups()
1409 cs8409_enable_ur(codec, 0); in dolphin_fixups()
1410 snd_hda_codec_set_name(codec, "CS8409/CS42L42"); in dolphin_fixups()
1413 dolphin_hw_init(codec); in dolphin_fixups()
1414 spec->init_done = 1; in dolphin_fixups()
1415 if (spec->init_done && spec->build_ctrl_done) { in dolphin_fixups()
1416 for (i = 0; i < spec->num_scodecs; i++) { in dolphin_fixups()
1417 if (!spec->scodecs[i]->hp_jack_in) in dolphin_fixups()
1418 cs42l42_run_jack_detect(spec->scodecs[i]); in dolphin_fixups()
1423 spec->build_ctrl_done = 1; in dolphin_fixups()
1429 if (spec->init_done && spec->build_ctrl_done) { in dolphin_fixups()
1430 for (i = 0; i < spec->num_scodecs; i++) { in dolphin_fixups()
1431 if (!spec->scodecs[i]->hp_jack_in) in dolphin_fixups()
1432 cs42l42_run_jack_detect(spec->scodecs[i]); in dolphin_fixups()
1441 static int patch_cs8409(struct hda_codec *codec) in patch_cs8409() argument
1445 if (!cs8409_alloc_spec(codec)) in patch_cs8409()
1446 return -ENOMEM; in patch_cs8409()
1448 snd_hda_pick_fixup(codec, cs8409_models, cs8409_fixup_tbl, cs8409_fixups); in patch_cs8409()
1450 codec_dbg(codec, "Picked ID=%d, VID=%08x, DEV=%08x\n", codec->fixup_id, in patch_cs8409()
1451 codec->bus->pci->subsystem_vendor, in patch_cs8409()
1452 codec->bus->pci->subsystem_device); in patch_cs8409()
1454 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); in patch_cs8409()
1456 err = cs8409_parse_auto_config(codec); in patch_cs8409()
1458 cs8409_free(codec); in patch_cs8409()
1462 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); in patch_cs8409()