Lines Matching +full:jack +full:- +full:det +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0-or-later
24 struct cs8409_spec *spec = codec->spec;
28 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
32 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
37 if (spec->gen.dyn_adc_switch) {
40 for (i = 0; i < spec->gen.input_mux.num_items; i++) {
41 int idx = spec->gen.dyn_adc_idx[i];
45 snd_hda_gen_fix_pin_power(codec, spec->gen.adc_nids[idx]);
62 codec->spec = spec;
63 spec->codec = codec;
64 codec->power_save_node = 1;
65 mutex_init(&spec->i2c_mux);
66 INIT_DELAYED_WORK(&spec->i2c_clk_work, cs8409_disable_i2c_clock_worker);
67 snd_hda_gen_spec_init(&spec->gen);
86 * cs8409_enable_i2c_clock - Disable I2C clocks
93 struct cs8409_spec *spec = codec->spec;
95 guard(mutex)(&spec->i2c_mux);
96 if (spec->i2c_clck_enabled) {
97 cs8409_vendor_coef_set(spec->codec, 0x0,
98 cs8409_vendor_coef_get(spec->codec, 0x0) & 0xfffffff7);
99 spec->i2c_clck_enabled = 0;
104 * cs8409_disable_i2c_clock_worker - Worker that disable the I2C Clock after 25ms without use
110 cs8409_disable_i2c_clock(spec->codec);
114 * cs8409_enable_i2c_clock - Enable I2C clocks
121 struct cs8409_spec *spec = codec->spec;
127 * afterwards in the scenario. The next enable call will re-enable the clock, regardless.
129 cancel_delayed_work(&spec->i2c_clk_work);
131 if (!spec->i2c_clck_enabled) {
133 spec->i2c_clck_enabled = 1;
135 queue_delayed_work(system_power_efficient_wq, &spec->i2c_clk_work, msecs_to_jiffies(25));
139 * cs8409_i2c_wait_complete - Wait for I2C transaction
143 * Return -ETIMEDOUT if transaction wait times out.
154 * cs8409_set_i2c_dev_addr - Set i2c address for transaction
160 struct cs8409_spec *spec = codec->spec;
162 if (spec->dev_addr != addr) {
164 spec->dev_addr = addr;
169 * cs8409_i2c_set_page - CS8409 I2C set page register.
177 struct hda_codec *codec = scodec->codec;
179 if (scodec->paged && (scodec->last_page != (i2c_reg >> 8))) {
182 return -EIO;
183 scodec->last_page = i2c_reg >> 8;
190 * cs8409_i2c_read - CS8409 I2C Read.
194 * Returns negative on error, otherwise returns read value in bits 0-7.
198 struct hda_codec *codec = scodec->codec;
199 struct cs8409_spec *spec = codec->spec;
203 if (scodec->suspended)
204 return -EPERM;
206 guard(mutex)(&spec->i2c_mux);
208 cs8409_set_i2c_dev_addr(codec, scodec->addr);
218 /* Register in bits 15-8 and the data in 7-0 */
224 codec_err(codec, "%s() Failed 0x%02x : 0x%04x\n", __func__, scodec->addr, addr);
225 return -EIO;
229 * cs8409_i2c_bulk_read - CS8409 I2C Read Sequence.
238 struct hda_codec *codec = scodec->codec;
239 struct cs8409_spec *spec = codec->spec;
243 if (scodec->suspended)
244 return -EPERM;
246 guard(mutex)(&spec->i2c_mux);
247 cs8409_set_i2c_dev_addr(codec, scodec->addr);
266 codec_err(codec, "I2C Bulk Write Failed 0x%02x\n", scodec->addr);
267 return -EIO;
271 * cs8409_i2c_write - CS8409 I2C Write.
280 struct hda_codec *codec = scodec->codec;
281 struct cs8409_spec *spec = codec->spec;
284 if (scodec->suspended)
285 return -EPERM;
287 guard(mutex)(&spec->i2c_mux);
290 cs8409_set_i2c_dev_addr(codec, scodec->addr);
304 codec_err(codec, "%s() Failed 0x%02x : 0x%04x\n", __func__, scodec->addr, addr);
305 return -EIO;
309 * cs8409_i2c_bulk_write - CS8409 I2C Write Sequence.
319 struct hda_codec *codec = scodec->codec;
320 struct cs8409_spec *spec = codec->spec;
324 if (scodec->suspended)
325 return -EPERM;
327 guard(mutex)(&spec->i2c_mux);
328 cs8409_set_i2c_dev_addr(codec, scodec->addr);
350 codec_err(codec, "I2C Bulk Write Failed 0x%02x\n", scodec->addr);
351 return -EIO;
379 struct cs8409_spec *spec = codec->spec;
383 for (i = 0; i < spec->num_scodecs; i++)
384 ur_gpios |= spec->scodecs[i]->irq_mask;
403 * connected to these pins which supports jack detect
407 caps = snd_hdac_read_parm(&codec->core, nid, AC_PAR_PIN_CAP);
409 snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP,
419 struct cs8409_spec *spec = codec->spec;
421 ucontrol->value.integer.value[0] = !!(spec->gpio_data & spec->speaker_pdn_gpio);
429 struct cs8409_spec *spec = codec->spec;
432 gpio_data = (spec->gpio_data & ~spec->speaker_pdn_gpio) |
433 (ucontrol->value.integer.value[0] ? spec->speaker_pdn_gpio : 0);
434 if (gpio_data == spec->gpio_data)
436 spec->gpio_data = gpio_data;
437 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data);
457 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
458 uinfo->value.integer.step = 1;
459 uinfo->count = chs == 3 ? 2 : 1;
463 uinfo->value.integer.min = CS42L42_HP_VOL_REAL_MIN;
464 uinfo->value.integer.max = CS42L42_HP_VOL_REAL_MAX;
467 uinfo->value.integer.min = CS42L42_AMIC_VOL_REAL_MIN;
468 uinfo->value.integer.max = CS42L42_AMIC_VOL_REAL_MAX;
480 struct cs8409_spec *spec = codec->spec;
481 struct sub_codec *cs42l42 = spec->scodecs[get_amp_index(kctrl)];
484 long *valp = uctrl->value.integer.value;
489 *valp++ = cs42l42->vol[ofs];
491 *valp = cs42l42->vol[ofs+1];
495 *valp = cs42l42->vol[ofs];
521 -(cs42l42->vol[CS42L42_DAC_CH0_VOL_OFFSET])
525 -(cs42l42->vol[CS42L42_DAC_CH1_VOL_OFFSET])
530 cs42l42->vol[CS42L42_ADC_VOL_OFFSET]
539 struct cs8409_spec *spec = codec->spec;
540 struct sub_codec *cs42l42 = spec->scodecs[get_amp_index(kctrl)];
543 long *valp = uctrl->value.integer.value;
548 cs42l42->vol[ofs] = *valp;
551 cs42l42->vol[ofs + 1] = *valp;
553 if (spec->playback_started)
558 cs42l42->vol[ofs] = *valp;
559 if (spec->capture_started)
574 struct cs8409_spec *spec = codec->spec;
582 spec->playback_started = 1;
586 spec->playback_started = 0;
592 for (i = 0; i < spec->num_scodecs; i++) {
593 cs42l42 = spec->scodecs[i];
603 struct cs8409_spec *spec = codec->spec;
611 spec->capture_started = 1;
615 spec->capture_started = 0;
621 for (i = 0; i < spec->num_scodecs; i++) {
622 cs42l42 = spec->scodecs[i];
627 /* Configure CS42L42 slave codec for jack autodetect */
630 cs8409_i2c_write(cs42l42, CS42L42_HSBIAS_SC_AUTOCTL, cs42l42->hsbias_hiz);
643 /* Enable and run CS42L42 slave codec jack auto detect */
678 /* Configure HS DET comparator reference levels. */
749 /* Configure HS DET comparator reference levels. */
764 if (cs42l42->no_type_dect) {
766 cs42l42->hp_jack_in = 1;
767 cs42l42->mic_jack_in = 0;
775 cs42l42->hp_jack_in = 0;
776 cs42l42->mic_jack_in = 0;
779 /* jack in transition */
783 codec_dbg(cs42l42->codec, "Tip Sense Detection: (%d)\n", reg_ts_status);
797 /* Read jack detect status registers */
804 return -EIO;
820 if (cs42l42->no_type_dect) {
824 codec_dbg(cs42l42->codec,
825 "Auto detect value not valid (%d), running manual det\n",
834 cs42l42->hp_jack_in = 1;
835 cs42l42->mic_jack_in = 1;
839 cs42l42->hp_jack_in = 1;
840 cs42l42->mic_jack_in = 0;
844 cs42l42->hp_jack_in = 0;
845 cs42l42->mic_jack_in = 0;
848 codec_dbg(cs42l42->codec, "Detection done (%d)\n", type);
851 /* Enable the HPOUT ground clamp and configure the HP pull-down */
853 /* Re-Enable Tip Sense Interrupt */
864 struct hda_codec *codec = cs42l42->codec;
865 struct cs8409_spec *spec = codec->spec;
875 spec->gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0);
876 spec->gpio_data |= cs42l42->reset_gpio;
877 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data);
880 cs42l42->suspended = 0;
883 cs8409_i2c_bulk_write(cs42l42, cs42l42->init_seq, cs42l42->init_seq_num);
889 if (cs42l42->full_scale_vol) {
899 * resume phase so that the jack event is processed properly
901 snd_hda_codec_allow_unsol_events(cs42l42->codec);
908 struct hda_codec *codec = cs42l42->codec;
909 struct cs8409_spec *spec = codec->spec;
934 cs42l42->suspended = 1;
935 cs42l42->last_page = 0;
936 cs42l42->hp_jack_in = 0;
937 cs42l42->mic_jack_in = 0;
940 spec->gpio_data = snd_hda_codec_read(codec, CS8409_PIN_AFG, 0, AC_VERB_GET_GPIO_DATA, 0);
941 spec->gpio_data &= ~cs42l42->reset_gpio;
942 snd_hda_codec_write(codec, CS8409_PIN_AFG, 0, AC_VERB_SET_GPIO_DATA, spec->gpio_data);
947 struct cs8409_spec *spec = codec->spec;
950 cancel_delayed_work_sync(&spec->i2c_clk_work);
964 * generate interrupt via gpio 4 to notify jack events. We have to overwrite
965 * generic snd_hda_jack_unsol_event(), read CS42L42 jack detect status registers
970 struct cs8409_spec *spec = codec->spec;
971 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0];
974 /* jack_unsol_event() will be called every time gpio line changing state.
979 if (res & cs42l42->irq_mask)
984 cs42l42->hp_jack_in ? 0 : PIN_OUT);
985 /* Report jack*/
988 snd_hda_jack_unsol_event(codec, (jk->tag << AC_UNSOL_RES_TAG_SHIFT) &
990 /* Report jack*/
993 snd_hda_jack_unsol_event(codec, (jk->tag << AC_UNSOL_RES_TAG_SHIFT) &
1000 struct cs8409_spec *spec = codec->spec;
1002 if (spec->unsol_event)
1003 spec->unsol_event(codec, res);
1011 struct cs8409_spec *spec = codec->spec;
1014 spec->init_done = 0;
1018 for (i = 0; i < spec->num_scodecs; i++)
1019 cs42l42_suspend(spec->scodecs[i]);
1022 cancel_delayed_work_sync(&spec->i2c_clk_work);
1037 struct cs8409_spec *spec = codec->spec;
1038 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0];
1040 if (spec->gpio_mask) {
1042 spec->gpio_mask);
1044 spec->gpio_dir);
1046 spec->gpio_data);
1049 for (; seq->nid; seq++)
1050 cs8409_vendor_coef_set(codec, seq->cir, seq->coeff);
1052 if (codec->fixup_id == CS8409_BULLSEYE) {
1053 for (; seq_bullseye->nid; seq_bullseye++)
1054 cs8409_vendor_coef_set(codec, seq_bullseye->cir, seq_bullseye->coeff);
1057 switch (codec->fixup_id) {
1081 struct cs8409_spec *spec = codec->spec;
1082 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0];
1090 * hda_jack based on CS42L42 jack detect status.
1095 *res = (cs42l42->hp_jack_in) ? AC_PINSENSE_PRESENCE : 0;
1101 *res = (cs42l42->mic_jack_in) ? AC_PINSENSE_PRESENCE : 0;
1109 return spec->exec_verb(dev, cmd, flags, res);
1114 struct cs8409_spec *spec = codec->spec;
1120 spec->exec_verb = codec->core.exec_verb;
1121 codec->core.exec_verb = cs8409_cs42l42_exec_verb;
1123 spec->scodecs[CS8409_CODEC0] = &cs8409_cs42l42_codec;
1124 spec->num_scodecs = 1;
1125 spec->scodecs[CS8409_CODEC0]->codec = codec;
1127 spec->gen.suppress_auto_mute = 1;
1128 spec->gen.no_primary_hp = 1;
1129 spec->gen.suppress_vmaster = 1;
1131 spec->speaker_pdn_gpio = 0;
1133 /* GPIO 5 out, 3,4 in */
1134 spec->gpio_dir = spec->scodecs[CS8409_CODEC0]->reset_gpio;
1135 spec->gpio_data = 0;
1136 spec->gpio_mask = 0x03f;
1144 spec->scodecs[CS8409_CODEC0]->hsbias_hiz = 0x0020;
1146 switch (codec->fixup_id) {
1148 spec->scodecs[CS8409_CODEC0]->full_scale_vol =
1150 spec->speaker_pdn_gpio = CS8409_CYBORG_SPEAKER_PDN;
1153 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_0DB;
1154 spec->speaker_pdn_gpio = CS8409_CYBORG_SPEAKER_PDN;
1158 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_0DB;
1159 spec->speaker_pdn_gpio = CS8409_WARLOCK_SPEAKER_PDN;
1162 spec->scodecs[CS8409_CODEC0]->full_scale_vol =
1164 spec->speaker_pdn_gpio = CS8409_WARLOCK_SPEAKER_PDN;
1168 if (spec->speaker_pdn_gpio > 0) {
1169 spec->gpio_dir |= spec->speaker_pdn_gpio;
1170 spec->gpio_data |= spec->speaker_pdn_gpio;
1176 spec->gen.stream_analog_playback = &cs42l42_48k_pcm_analog_playback;
1177 spec->gen.stream_analog_capture = &cs42l42_48k_pcm_analog_capture;
1179 spec->gen.pcm_playback_hook = cs42l42_playback_pcm_hook;
1180 spec->gen.pcm_capture_hook = cs42l42_capture_pcm_hook;
1181 if (codec->fixup_id != CS8409_ODIN)
1182 /* Set initial DMIC volume to -26 dB */
1185 snd_hda_gen_add_kctl(&spec->gen, "Headphone Playback Volume",
1187 snd_hda_gen_add_kctl(&spec->gen, "Mic Capture Volume",
1189 if (spec->speaker_pdn_gpio > 0)
1190 snd_hda_gen_add_kctl(&spec->gen, "Speaker Playback Switch",
1198 spec->init_done = 1;
1199 if (spec->init_done && spec->build_ctrl_done
1200 && !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
1201 cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
1204 spec->build_ctrl_done = 1;
1205 /* Run jack auto detect first time on boot
1206 * after controls have been added, to check if jack has
1210 if (spec->init_done && spec->build_ctrl_done
1211 && !spec->scodecs[CS8409_CODEC0]->hp_jack_in)
1212 cs42l42_run_jack_detect(spec->scodecs[CS8409_CODEC0]);
1227 * generate interrupt via irq_mask to notify jack events. We have to overwrite
1228 * generic snd_hda_jack_unsol_event(), read CS42L42 jack detect status registers
1233 struct cs8409_spec *spec = codec->spec;
1237 cs42l42 = spec->scodecs[CS8409_CODEC0];
1238 if (!cs42l42->suspended && (~res & cs42l42->irq_mask) &&
1243 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) &
1249 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) &
1253 cs42l42 = spec->scodecs[CS8409_CODEC1];
1254 if (!cs42l42->suspended && (~res & cs42l42->irq_mask) &&
1259 (jk->tag << AC_UNSOL_RES_TAG_SHIFT) &
1270 struct cs8409_spec *spec = codec->spec;
1274 if (spec->gpio_mask) {
1276 spec->gpio_mask);
1278 spec->gpio_dir);
1280 spec->gpio_data);
1283 for (; seq->nid; seq++)
1284 cs8409_vendor_coef_set(codec, seq->cir, seq->coeff);
1286 for (i = 0; i < spec->num_scodecs; i++) {
1287 cs42l42 = spec->scodecs[i];
1299 struct cs8409_spec *spec = codec->spec;
1300 struct sub_codec *cs42l42 = spec->scodecs[CS8409_CODEC0];
1308 * hda_jack based on CS42L42 jack detect status.
1314 cs42l42 = spec->scodecs[CS8409_CODEC1];
1316 *res = (cs42l42->hp_jack_in) ? AC_PINSENSE_PRESENCE : 0;
1322 *res = (cs42l42->mic_jack_in) ? AC_PINSENSE_PRESENCE : 0;
1330 return spec->exec_verb(dev, cmd, flags, res);
1335 struct cs8409_spec *spec = codec->spec;
1343 spec->exec_verb = codec->core.exec_verb;
1344 codec->core.exec_verb = dolphin_exec_verb;
1346 spec->scodecs[CS8409_CODEC0] = &dolphin_cs42l42_0;
1347 spec->scodecs[CS8409_CODEC0]->codec = codec;
1348 spec->scodecs[CS8409_CODEC1] = &dolphin_cs42l42_1;
1349 spec->scodecs[CS8409_CODEC1]->codec = codec;
1350 spec->num_scodecs = 2;
1351 spec->gen.suppress_vmaster = 1;
1353 spec->unsol_event = dolphin_jack_unsol_event;
1355 /* GPIO 1,5 out, 0,4 in */
1356 spec->gpio_dir = spec->scodecs[CS8409_CODEC0]->reset_gpio |
1357 spec->scodecs[CS8409_CODEC1]->reset_gpio;
1358 spec->gpio_data = 0;
1359 spec->gpio_mask = 0x03f;
1374 spec->scodecs[CS8409_CODEC0]->full_scale_vol = CS42L42_FULL_SCALE_VOL_MINUS6DB;
1375 spec->scodecs[CS8409_CODEC1]->full_scale_vol = CS42L42_FULL_SCALE_VOL_MINUS6DB;
1380 spec->gen.stream_analog_playback = &cs42l42_48k_pcm_analog_playback;
1381 spec->gen.stream_analog_capture = &cs42l42_48k_pcm_analog_capture;
1383 spec->gen.pcm_playback_hook = cs42l42_playback_pcm_hook;
1384 spec->gen.pcm_capture_hook = cs42l42_capture_pcm_hook;
1385 snd_hda_gen_add_kctl(&spec->gen, "Headphone Playback Volume",
1387 snd_hda_gen_add_kctl(&spec->gen, "Mic Capture Volume", &cs42l42_adc_volume_mixer);
1388 kctrl = snd_hda_gen_add_kctl(&spec->gen, "Line Out Playback Volume",
1392 kctrl->private_value = HDA_COMPOSE_AMP_VAL_OFS(DOLPHIN_HP_PIN_NID, 3, CS8409_CODEC1,
1399 spec->init_done = 1;
1400 if (spec->init_done && spec->build_ctrl_done) {
1401 for (i = 0; i < spec->num_scodecs; i++) {
1402 if (!spec->scodecs[i]->hp_jack_in)
1403 cs42l42_run_jack_detect(spec->scodecs[i]);
1408 spec->build_ctrl_done = 1;
1409 /* Run jack auto detect first time on boot
1410 * after controls have been added, to check if jack has
1414 if (spec->init_done && spec->build_ctrl_done) {
1415 for (i = 0; i < spec->num_scodecs; i++) {
1416 if (!spec->scodecs[i]->hp_jack_in)
1417 cs42l42_run_jack_detect(spec->scodecs[i]);
1431 return -ENOMEM;
1435 codec_dbg(codec, "Picked ID=%d, VID=%08x, DEV=%08x\n", codec->fixup_id,
1436 codec->bus->pci->subsystem_vendor,
1437 codec->bus->pci->subsystem_device);