Lines Matching refs:cs35l41
101 static void cs35l41_add_controls(struct cs35l41_hda *cs35l41) in cs35l41_add_controls() argument
105 info.device_name = cs35l41->amp_name; in cs35l41_add_controls()
106 info.fw_type = cs35l41->firmware_type; in cs35l41_add_controls()
107 info.card = cs35l41->codec->card; in cs35l41_add_controls()
109 hda_cs_dsp_add_controls(&cs35l41->cs_dsp, &info); in cs35l41_add_controls()
116 static int cs35l41_request_firmware_file(struct cs35l41_hda *cs35l41, in cs35l41_request_firmware_file() argument
121 const char * const dsp_name = cs35l41->cs_dsp.name; in cs35l41_request_firmware_file()
127 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
131 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
135 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
139 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
143 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
163 ret = firmware_request_nowarn(firmware, *filename, cs35l41->dev); in cs35l41_request_firmware_file()
165 dev_dbg(cs35l41->dev, "Failed to request '%s'\n", *filename); in cs35l41_request_firmware_file()
173 static int cs35l41_request_firmware_files_spkid(struct cs35l41_hda *cs35l41, in cs35l41_request_firmware_files_spkid() argument
182 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files_spkid()
184 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files_spkid()
185 cs35l41->speaker_id, "wmfw"); in cs35l41_request_firmware_files_spkid()
188 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files_spkid()
190 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files_spkid()
191 cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
199 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files_spkid()
200 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files_spkid()
201 cs35l41->amp_name, -1, "wmfw"); in cs35l41_request_firmware_files_spkid()
204 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files_spkid()
206 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files_spkid()
207 cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
215 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files_spkid()
216 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files_spkid()
217 NULL, cs35l41->speaker_id, "wmfw"); in cs35l41_request_firmware_files_spkid()
220 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files_spkid()
222 cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files_spkid()
223 cs35l41->amp_name, cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
226 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, in cs35l41_request_firmware_files_spkid()
228 cs35l41->acpi_subsystem_id, NULL, in cs35l41_request_firmware_files_spkid()
229 cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
237 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files_spkid()
238 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files_spkid()
242 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files_spkid()
244 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files_spkid()
245 cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
248 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, in cs35l41_request_firmware_files_spkid()
250 cs35l41->acpi_subsystem_id, NULL, in cs35l41_request_firmware_files_spkid()
251 cs35l41->speaker_id, "bin"); in cs35l41_request_firmware_files_spkid()
263 static int cs35l41_fallback_firmware_file(struct cs35l41_hda *cs35l41, in cs35l41_fallback_firmware_file() argument
272 dev_warn(cs35l41->dev, "Falling back to default firmware.\n"); in cs35l41_fallback_firmware_file()
275 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_fallback_firmware_file()
281 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_fallback_firmware_file()
291 dev_warn(cs35l41->dev, "Unable to find firmware and tuning\n"); in cs35l41_fallback_firmware_file()
295 static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41, in cs35l41_request_firmware_files() argument
303 if (cs35l41->speaker_id > -1) { in cs35l41_request_firmware_files()
304 ret = cs35l41_request_firmware_files_spkid(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files()
310 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files()
311 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files()
312 cs35l41->amp_name, -1, "wmfw"); in cs35l41_request_firmware_files()
315 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files()
317 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files()
326 ret = cs35l41_request_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files()
327 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files()
331 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files()
333 cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files()
334 cs35l41->amp_name, -1, "bin"); in cs35l41_request_firmware_files()
337 ret = cs35l41_request_firmware_file(cs35l41, coeff_firmware, coeff_filename, in cs35l41_request_firmware_files()
339 cs35l41->acpi_subsystem_id, NULL, -1, in cs35l41_request_firmware_files()
356 return cs35l41_fallback_firmware_file(cs35l41, wmfw_firmware, wmfw_filename, in cs35l41_request_firmware_files()
361 static int cs35l41_apply_calibration(struct cs35l41_hda *cs35l41, __be32 ambient, __be32 r0, in cs35l41_apply_calibration() argument
366 ret = hda_cs_dsp_write_ctl(&cs35l41->cs_dsp, CAL_AMBIENT_DSP_CTL_NAME, CAL_DSP_CTL_TYPE, in cs35l41_apply_calibration()
369 dev_err(cs35l41->dev, "Cannot Write Control: %s - %d\n", CAL_AMBIENT_DSP_CTL_NAME, in cs35l41_apply_calibration()
373 ret = hda_cs_dsp_write_ctl(&cs35l41->cs_dsp, CAL_R_DSP_CTL_NAME, CAL_DSP_CTL_TYPE, in cs35l41_apply_calibration()
376 dev_err(cs35l41->dev, "Cannot Write Control: %s - %d\n", CAL_R_DSP_CTL_NAME, ret); in cs35l41_apply_calibration()
379 ret = hda_cs_dsp_write_ctl(&cs35l41->cs_dsp, CAL_STATUS_DSP_CTL_NAME, CAL_DSP_CTL_TYPE, in cs35l41_apply_calibration()
382 dev_err(cs35l41->dev, "Cannot Write Control: %s - %d\n", CAL_STATUS_DSP_CTL_NAME, in cs35l41_apply_calibration()
386 ret = hda_cs_dsp_write_ctl(&cs35l41->cs_dsp, CAL_CHECKSUM_DSP_CTL_NAME, CAL_DSP_CTL_TYPE, in cs35l41_apply_calibration()
389 dev_err(cs35l41->dev, "Cannot Write Control: %s - %d\n", CAL_CHECKSUM_DSP_CTL_NAME, in cs35l41_apply_calibration()
397 static int cs35l41_save_calibration(struct cs35l41_hda *cs35l41) in cs35l41_save_calibration() argument
422 dev_dbg(cs35l41->dev, "Calibration: Size=%d, Amp Count=%d\n", in cs35l41_save_calibration()
424 if (efi_data->count > cs35l41->index) { in cs35l41_save_calibration()
425 cl = &efi_data->data[cs35l41->index]; in cs35l41_save_calibration()
426 dev_dbg(cs35l41->dev, in cs35l41_save_calibration()
431 ret = cs35l41_apply_calibration(cs35l41, in cs35l41_save_calibration()
443 static int cs35l41_save_calibration(struct cs35l41_hda *cs35l41) in cs35l41_save_calibration() argument
445 dev_warn(cs35l41->dev, "Calibration not supported without EFI support.\n"); in cs35l41_save_calibration()
450 static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41) in cs35l41_init_dsp() argument
454 struct cs_dsp *dsp = &cs35l41->cs_dsp; in cs35l41_init_dsp()
459 if (!cs35l41->halo_initialized) { in cs35l41_init_dsp()
460 cs35l41_configure_cs_dsp(cs35l41->dev, cs35l41->regmap, dsp); in cs35l41_init_dsp()
463 ret = cs_dsp_halo_init(&cs35l41->cs_dsp); in cs35l41_init_dsp()
466 cs35l41->halo_initialized = true; in cs35l41_init_dsp()
469 ret = cs35l41_request_firmware_files(cs35l41, &wmfw_firmware, &wmfw_filename, in cs35l41_init_dsp()
474 dev_dbg(cs35l41->dev, "Loading WMFW Firmware: %s\n", wmfw_filename); in cs35l41_init_dsp()
476 dev_dbg(cs35l41->dev, "Loading Coefficient File: %s\n", coeff_filename); in cs35l41_init_dsp()
478 dev_warn(cs35l41->dev, "No Coefficient File available.\n"); in cs35l41_init_dsp()
481 hda_cs_dsp_fw_ids[cs35l41->firmware_type]); in cs35l41_init_dsp()
485 cs35l41_add_controls(cs35l41); in cs35l41_init_dsp()
487 ret = cs35l41_save_calibration(cs35l41); in cs35l41_init_dsp()
498 static void cs35l41_shutdown_dsp(struct cs35l41_hda *cs35l41) in cs35l41_shutdown_dsp() argument
500 struct cs_dsp *dsp = &cs35l41->cs_dsp; in cs35l41_shutdown_dsp()
504 cs35l41->firmware_running = false; in cs35l41_shutdown_dsp()
505 dev_dbg(cs35l41->dev, "Unloaded Firmware\n"); in cs35l41_shutdown_dsp()
508 static void cs35l41_remove_dsp(struct cs35l41_hda *cs35l41) in cs35l41_remove_dsp() argument
510 struct cs_dsp *dsp = &cs35l41->cs_dsp; in cs35l41_remove_dsp()
512 cancel_work_sync(&cs35l41->fw_load_work); in cs35l41_remove_dsp()
514 mutex_lock(&cs35l41->fw_mutex); in cs35l41_remove_dsp()
515 cs35l41_shutdown_dsp(cs35l41); in cs35l41_remove_dsp()
517 cs35l41->halo_initialized = false; in cs35l41_remove_dsp()
518 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_remove_dsp()
530 static void cs35l41_irq_release(struct cs35l41_hda *cs35l41) in cs35l41_irq_release() argument
532 cs35l41_error_release(cs35l41->dev, cs35l41->regmap, cs35l41->irq_errors); in cs35l41_irq_release()
533 cs35l41->irq_errors = 0; in cs35l41_irq_release()
538 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_play_start() local
539 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_play_start()
543 if (cs35l41->playback_started) { in cs35l41_hda_play_start()
548 cs35l41->playback_started = true; in cs35l41_hda_play_start()
550 if (cs35l41->firmware_running) { in cs35l41_hda_play_start()
556 cs35l41_set_cspl_mbox_cmd(cs35l41->dev, reg, CSPL_MBOX_CMD_RESUME); in cs35l41_hda_play_start()
561 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST) in cs35l41_hda_play_start()
568 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_play_done() local
569 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_play_done()
573 cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 1, NULL, in cs35l41_hda_play_done()
574 cs35l41->firmware_running); in cs35l41_hda_play_done()
575 if (cs35l41->firmware_running) { in cs35l41_hda_play_done()
586 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_pause_start() local
587 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_pause_start()
592 cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 0, NULL, in cs35l41_hda_pause_start()
593 cs35l41->firmware_running); in cs35l41_hda_pause_start()
598 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_pause_done() local
599 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_pause_done()
604 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST) in cs35l41_hda_pause_done()
606 if (cs35l41->firmware_running) { in cs35l41_hda_pause_done()
612 cs35l41_irq_release(cs35l41); in cs35l41_hda_pause_done()
613 cs35l41->playback_started = false; in cs35l41_hda_pause_done()
618 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_pre_playback_hook() local
622 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_pre_playback_hook()
624 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_pre_playback_hook()
632 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_playback_hook() local
645 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
647 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
650 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
652 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
655 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
656 if (!cs35l41->firmware_running && cs35l41->request_fw_load && in cs35l41_hda_playback_hook()
657 !cs35l41->fw_request_ongoing) { in cs35l41_hda_playback_hook()
659 cs35l41->fw_request_ongoing = true; in cs35l41_hda_playback_hook()
660 schedule_work(&cs35l41->fw_load_work); in cs35l41_hda_playback_hook()
662 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_playback_hook()
678 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_post_playback_hook() local
682 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_post_playback_hook()
684 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_post_playback_hook()
694 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_channel_map() local
697 if (!cs35l41->amp_name) { in cs35l41_hda_channel_map()
701 cs35l41->amp_name = devm_kasprintf(cs35l41->dev, GFP_KERNEL, "%s%d", in cs35l41_hda_channel_map()
702 channel_name[*rx_slot], cs35l41->channel_index); in cs35l41_hda_channel_map()
703 if (!cs35l41->amp_name) in cs35l41_hda_channel_map()
707 return cs35l41_set_channels(cs35l41->dev, cs35l41->regmap, tx_num, tx_slot, rx_num, in cs35l41_hda_channel_map()
711 static int cs35l41_ready_for_reset(struct cs35l41_hda *cs35l41) in cs35l41_ready_for_reset() argument
715 mutex_lock(&cs35l41->fw_mutex); in cs35l41_ready_for_reset()
716 if (cs35l41->firmware_running) { in cs35l41_ready_for_reset()
718 regcache_cache_only(cs35l41->regmap, false); in cs35l41_ready_for_reset()
720 ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap); in cs35l41_ready_for_reset()
722 dev_warn(cs35l41->dev, "Unable to exit Hibernate."); in cs35l41_ready_for_reset()
727 cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap); in cs35l41_ready_for_reset()
728 ret = regcache_sync(cs35l41->regmap); in cs35l41_ready_for_reset()
729 cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap); in cs35l41_ready_for_reset()
731 dev_err(cs35l41->dev, "Failed to restore register cache: %d\n", ret); in cs35l41_ready_for_reset()
735 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST) in cs35l41_ready_for_reset()
736 cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, &cs35l41->hw_cfg); in cs35l41_ready_for_reset()
738 cs35l41_shutdown_dsp(cs35l41); in cs35l41_ready_for_reset()
739 cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type); in cs35l41_ready_for_reset()
742 regcache_cache_only(cs35l41->regmap, true); in cs35l41_ready_for_reset()
743 regcache_mark_dirty(cs35l41->regmap); in cs35l41_ready_for_reset()
745 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_ready_for_reset()
752 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_system_suspend_prep() local
754 dev_dbg(cs35l41->dev, "System Suspend Prepare\n"); in cs35l41_system_suspend_prep()
756 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) { in cs35l41_system_suspend_prep()
757 dev_err_once(cs35l41->dev, "System Suspend not supported\n"); in cs35l41_system_suspend_prep()
761 mutex_lock(&cs35l41->fw_mutex); in cs35l41_system_suspend_prep()
762 if (cs35l41->playback_started) in cs35l41_system_suspend_prep()
764 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_system_suspend_prep()
771 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_system_suspend() local
774 dev_dbg(cs35l41->dev, "System Suspend\n"); in cs35l41_system_suspend()
776 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) { in cs35l41_system_suspend()
777 dev_err_once(cs35l41->dev, "System Suspend not supported\n"); in cs35l41_system_suspend()
781 mutex_lock(&cs35l41->fw_mutex); in cs35l41_system_suspend()
782 if (cs35l41->playback_started) in cs35l41_system_suspend()
784 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_system_suspend()
793 ret = cs35l41_ready_for_reset(cs35l41); in cs35l41_system_suspend()
807 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_system_resume() local
810 dev_dbg(cs35l41->dev, "System Resume\n"); in cs35l41_system_resume()
812 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) { in cs35l41_system_resume()
813 dev_err_once(cs35l41->dev, "System Resume not supported\n"); in cs35l41_system_resume()
817 if (cs35l41->reset_gpio) { in cs35l41_system_resume()
819 gpiod_set_value_cansleep(cs35l41->reset_gpio, 1); in cs35l41_system_resume()
830 mutex_lock(&cs35l41->fw_mutex); in cs35l41_system_resume()
832 if (cs35l41->request_fw_load && !cs35l41->fw_request_ongoing) { in cs35l41_system_resume()
833 cs35l41->fw_request_ongoing = true; in cs35l41_system_resume()
834 schedule_work(&cs35l41->fw_load_work); in cs35l41_system_resume()
836 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_system_resume()
843 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_runtime_idle() local
845 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) in cs35l41_runtime_idle()
852 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_runtime_suspend() local
855 dev_dbg(cs35l41->dev, "Runtime Suspend\n"); in cs35l41_runtime_suspend()
857 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) { in cs35l41_runtime_suspend()
858 dev_dbg(cs35l41->dev, "Runtime Suspend not supported\n"); in cs35l41_runtime_suspend()
862 mutex_lock(&cs35l41->fw_mutex); in cs35l41_runtime_suspend()
864 if (cs35l41->firmware_running) { in cs35l41_runtime_suspend()
865 ret = cs35l41_enter_hibernate(cs35l41->dev, cs35l41->regmap, in cs35l41_runtime_suspend()
866 cs35l41->hw_cfg.bst_type); in cs35l41_runtime_suspend()
870 cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type); in cs35l41_runtime_suspend()
873 regcache_cache_only(cs35l41->regmap, true); in cs35l41_runtime_suspend()
874 regcache_mark_dirty(cs35l41->regmap); in cs35l41_runtime_suspend()
877 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_runtime_suspend()
884 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_runtime_resume() local
887 dev_dbg(cs35l41->dev, "Runtime Resume\n"); in cs35l41_runtime_resume()
889 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) { in cs35l41_runtime_resume()
890 dev_dbg(cs35l41->dev, "Runtime Resume not supported\n"); in cs35l41_runtime_resume()
894 mutex_lock(&cs35l41->fw_mutex); in cs35l41_runtime_resume()
896 regcache_cache_only(cs35l41->regmap, false); in cs35l41_runtime_resume()
898 if (cs35l41->firmware_running) { in cs35l41_runtime_resume()
899 ret = cs35l41_exit_hibernate(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
901 dev_warn(cs35l41->dev, "Unable to exit Hibernate."); in cs35l41_runtime_resume()
907 cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
908 ret = regcache_sync(cs35l41->regmap); in cs35l41_runtime_resume()
909 cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap); in cs35l41_runtime_resume()
911 dev_err(cs35l41->dev, "Failed to restore register cache: %d\n", ret); in cs35l41_runtime_resume()
915 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST) in cs35l41_runtime_resume()
916 cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, &cs35l41->hw_cfg); in cs35l41_runtime_resume()
919 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_runtime_resume()
924 static int cs35l41_smart_amp(struct cs35l41_hda *cs35l41) in cs35l41_smart_amp() argument
929 ret = cs35l41_init_dsp(cs35l41); in cs35l41_smart_amp()
931 dev_warn(cs35l41->dev, "Cannot Initialize Firmware. Error: %d\n", ret); in cs35l41_smart_amp()
935 ret = cs35l41_write_fs_errata(cs35l41->dev, cs35l41->regmap); in cs35l41_smart_amp()
937 dev_err(cs35l41->dev, "Cannot Write FS Errata: %d\n", ret); in cs35l41_smart_amp()
941 ret = cs_dsp_run(&cs35l41->cs_dsp); in cs35l41_smart_amp()
943 dev_err(cs35l41->dev, "Fail to start dsp: %d\n", ret); in cs35l41_smart_amp()
949 1000, 15000, false, &cs35l41->cs_dsp, HALO_STATE_DSP_CTL_NAME, in cs35l41_smart_amp()
954 dev_err(cs35l41->dev, "Timeout waiting for HALO Core to start. State: %u\n", in cs35l41_smart_amp()
959 ret = cs35l41_set_cspl_mbox_cmd(cs35l41->dev, cs35l41->regmap, CSPL_MBOX_CMD_PAUSE); in cs35l41_smart_amp()
961 dev_err(cs35l41->dev, "Error waiting for DSP to pause: %u\n", ret); in cs35l41_smart_amp()
965 cs35l41->firmware_running = true; in cs35l41_smart_amp()
970 cs35l41_shutdown_dsp(cs35l41); in cs35l41_smart_amp()
974 static void cs35l41_load_firmware(struct cs35l41_hda *cs35l41, bool load) in cs35l41_load_firmware() argument
976 if (cs35l41->firmware_running && !load) { in cs35l41_load_firmware()
977 dev_dbg(cs35l41->dev, "Unloading Firmware\n"); in cs35l41_load_firmware()
978 cs35l41_shutdown_dsp(cs35l41); in cs35l41_load_firmware()
979 } else if (!cs35l41->firmware_running && load) { in cs35l41_load_firmware()
980 dev_dbg(cs35l41->dev, "Loading Firmware\n"); in cs35l41_load_firmware()
981 cs35l41_smart_amp(cs35l41); in cs35l41_load_firmware()
983 dev_dbg(cs35l41->dev, "Unable to Load firmware.\n"); in cs35l41_load_firmware()
990 struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol); in cs35l41_fw_load_ctl_get() local
992 ucontrol->value.integer.value[0] = cs35l41->request_fw_load; in cs35l41_fw_load_ctl_get()
998 struct cs35l41_hda *cs35l41 = container_of(work, struct cs35l41_hda, fw_load_work); in cs35l41_fw_load_work() local
1000 pm_runtime_get_sync(cs35l41->dev); in cs35l41_fw_load_work()
1002 mutex_lock(&cs35l41->fw_mutex); in cs35l41_fw_load_work()
1005 if (cs35l41->playback_started) in cs35l41_fw_load_work()
1006 dev_err(cs35l41->dev, "Cannot Load/Unload firmware during Playback. Retrying...\n"); in cs35l41_fw_load_work()
1008 cs35l41_load_firmware(cs35l41, cs35l41->request_fw_load); in cs35l41_fw_load_work()
1010 cs35l41->fw_request_ongoing = false; in cs35l41_fw_load_work()
1011 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_fw_load_work()
1013 pm_runtime_mark_last_busy(cs35l41->dev); in cs35l41_fw_load_work()
1014 pm_runtime_put_autosuspend(cs35l41->dev); in cs35l41_fw_load_work()
1020 struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol); in cs35l41_fw_load_ctl_put() local
1022 if (cs35l41->request_fw_load == ucontrol->value.integer.value[0]) in cs35l41_fw_load_ctl_put()
1025 if (cs35l41->fw_request_ongoing) { in cs35l41_fw_load_ctl_put()
1026 dev_dbg(cs35l41->dev, "Existing request not complete\n"); in cs35l41_fw_load_ctl_put()
1031 if (cs35l41->playback_started) { in cs35l41_fw_load_ctl_put()
1032 dev_err(cs35l41->dev, "Cannot Load/Unload firmware during Playback\n"); in cs35l41_fw_load_ctl_put()
1036 cs35l41->fw_request_ongoing = true; in cs35l41_fw_load_ctl_put()
1037 cs35l41->request_fw_load = ucontrol->value.integer.value[0]; in cs35l41_fw_load_ctl_put()
1038 schedule_work(&cs35l41->fw_load_work); in cs35l41_fw_load_ctl_put()
1046 struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol); in cs35l41_fw_type_ctl_get() local
1048 ucontrol->value.enumerated.item[0] = cs35l41->firmware_type; in cs35l41_fw_type_ctl_get()
1056 struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol); in cs35l41_fw_type_ctl_put() local
1059 if (cs35l41->firmware_type != ucontrol->value.enumerated.item[0]) { in cs35l41_fw_type_ctl_put()
1060 cs35l41->firmware_type = ucontrol->value.enumerated.item[0]; in cs35l41_fw_type_ctl_put()
1075 static int cs35l41_create_controls(struct cs35l41_hda *cs35l41) in cs35l41_create_controls() argument
1096 cs35l41->amp_name); in cs35l41_create_controls()
1098 cs35l41->amp_name); in cs35l41_create_controls()
1100 ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&fw_type_ctl, cs35l41)); in cs35l41_create_controls()
1102 dev_err(cs35l41->dev, "Failed to add KControl %s = %d\n", fw_type_ctl.name, ret); in cs35l41_create_controls()
1106 dev_dbg(cs35l41->dev, "Added Control %s\n", fw_type_ctl.name); in cs35l41_create_controls()
1108 ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&fw_load_ctl, cs35l41)); in cs35l41_create_controls()
1110 dev_err(cs35l41->dev, "Failed to add KControl %s = %d\n", fw_load_ctl.name, ret); in cs35l41_create_controls()
1114 dev_dbg(cs35l41->dev, "Added Control %s\n", fw_load_ctl.name); in cs35l41_create_controls()
1121 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_bind() local
1126 if (!comps || cs35l41->index < 0 || cs35l41->index >= HDA_MAX_COMPONENTS) in cs35l41_hda_bind()
1129 comps = &comps[cs35l41->index]; in cs35l41_hda_bind()
1135 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_bind()
1138 if (!cs35l41->acpi_subsystem_id) in cs35l41_hda_bind()
1139 cs35l41->acpi_subsystem_id = kasprintf(GFP_KERNEL, "%.8x", in cs35l41_hda_bind()
1141 cs35l41->codec = comps->codec; in cs35l41_hda_bind()
1144 cs35l41->firmware_type = HDA_CS_DSP_FW_SPK_PROT; in cs35l41_hda_bind()
1147 dev_dbg(cs35l41->dev, "Firmware Autostart.\n"); in cs35l41_hda_bind()
1148 cs35l41->request_fw_load = true; in cs35l41_hda_bind()
1149 if (cs35l41_smart_amp(cs35l41) < 0) in cs35l41_hda_bind()
1150 dev_warn(cs35l41->dev, "Cannot Run Firmware, reverting to dsp bypass...\n"); in cs35l41_hda_bind()
1152 dev_dbg(cs35l41->dev, "Firmware Autostart is disabled.\n"); in cs35l41_hda_bind()
1155 ret = cs35l41_create_controls(cs35l41); in cs35l41_hda_bind()
1161 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_bind()
1164 if (!device_link_add(&comps->codec->core.dev, cs35l41->dev, DL_FLAG_STATELESS)) in cs35l41_hda_bind()
1171 dev_info(cs35l41->dev, in cs35l41_hda_bind()
1173 cs35l41->acpi_subsystem_id, cs35l41->hw_cfg.bst_type, in cs35l41_hda_bind()
1174 cs35l41->hw_cfg.gpio1.func == CS35l41_VSPK_SWITCH, in cs35l41_hda_bind()
1175 cs35l41->hw_cfg.spk_pos ? 'R' : 'L', in cs35l41_hda_bind()
1176 cs35l41->firmware_running, cs35l41->speaker_id); in cs35l41_hda_bind()
1183 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_unbind() local
1187 if (comps[cs35l41->index].dev == dev) { in cs35l41_hda_unbind()
1188 memset(&comps[cs35l41->index], 0, sizeof(*comps)); in cs35l41_hda_unbind()
1190 device_link_remove(&comps->codec->core.dev, cs35l41->dev); in cs35l41_hda_unbind()
1202 struct cs35l41_hda *cs35l41 = data; in cs35l41_bst_short_err() local
1204 dev_crit_ratelimited(cs35l41->dev, "LBST Error\n"); in cs35l41_bst_short_err()
1205 set_bit(CS35L41_BST_SHORT_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_bst_short_err()
1212 struct cs35l41_hda *cs35l41 = data; in cs35l41_bst_dcm_uvp_err() local
1214 dev_crit_ratelimited(cs35l41->dev, "DCM VBST Under Voltage Error\n"); in cs35l41_bst_dcm_uvp_err()
1215 set_bit(CS35L41_BST_UVP_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_bst_dcm_uvp_err()
1222 struct cs35l41_hda *cs35l41 = data; in cs35l41_bst_ovp_err() local
1224 dev_crit_ratelimited(cs35l41->dev, "VBST Over Voltage error\n"); in cs35l41_bst_ovp_err()
1225 set_bit(CS35L41_BST_OVP_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_bst_ovp_err()
1232 struct cs35l41_hda *cs35l41 = data; in cs35l41_temp_err() local
1234 dev_crit_ratelimited(cs35l41->dev, "Over temperature error\n"); in cs35l41_temp_err()
1235 set_bit(CS35L41_TEMP_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_temp_err()
1242 struct cs35l41_hda *cs35l41 = data; in cs35l41_temp_warn() local
1244 dev_crit_ratelimited(cs35l41->dev, "Over temperature warning\n"); in cs35l41_temp_warn()
1245 set_bit(CS35L41_TEMP_WARN_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_temp_warn()
1252 struct cs35l41_hda *cs35l41 = data; in cs35l41_amp_short() local
1254 dev_crit_ratelimited(cs35l41->dev, "Amp short error\n"); in cs35l41_amp_short()
1255 set_bit(CS35L41_AMP_SHORT_ERR_RLS_SHIFT, &cs35l41->irq_errors); in cs35l41_amp_short()
1289 static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41) in cs35l41_hda_apply_properties() argument
1291 struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; in cs35l41_hda_apply_properties()
1297 if (!cs35l41->hw_cfg.valid) in cs35l41_hda_apply_properties()
1300 ret = cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, hw_cfg); in cs35l41_hda_apply_properties()
1316 dev_err(cs35l41->dev, "Invalid function %d for GPIO1\n", in cs35l41_hda_apply_properties()
1331 dev_err(cs35l41->dev, "Invalid GPIO2 function %d\n", hw_cfg->gpio2.func); in cs35l41_hda_apply_properties()
1336 irq_pol = cs35l41_gpio_config(cs35l41->regmap, hw_cfg); in cs35l41_hda_apply_properties()
1338 if (cs35l41->irq && using_irq) { in cs35l41_hda_apply_properties()
1339 ret = devm_regmap_add_irq_chip(cs35l41->dev, cs35l41->regmap, cs35l41->irq, in cs35l41_hda_apply_properties()
1341 0, &cs35l41_regmap_irq_chip, &cs35l41->irq_data); in cs35l41_hda_apply_properties()
1346 irq = regmap_irq_get_virq(cs35l41->irq_data, cs35l41_irqs[i].irq); in cs35l41_hda_apply_properties()
1350 ret = devm_request_threaded_irq(cs35l41->dev, irq, NULL, in cs35l41_hda_apply_properties()
1353 cs35l41_irqs[i].name, cs35l41); in cs35l41_hda_apply_properties()
1359 return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos); in cs35l41_hda_apply_properties()
1416 static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id) in cs35l41_hda_read_acpi() argument
1418 struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; in cs35l41_hda_read_acpi()
1429 dev_err(cs35l41->dev, "Failed to find an ACPI device for %s\n", hid); in cs35l41_hda_read_acpi()
1439 cs35l41->acpi_subsystem_id = sub; in cs35l41_hda_read_acpi()
1441 ret = cs35l41_add_dsd_properties(cs35l41, physdev, id, hid); in cs35l41_hda_read_acpi()
1443 dev_info(cs35l41->dev, "Using extra _DSD properties, bypassing _DSD in ACPI\n"); in cs35l41_hda_read_acpi()
1462 cs35l41->index = -1; in cs35l41_hda_read_acpi()
1465 cs35l41->index = i; in cs35l41_hda_read_acpi()
1469 if (cs35l41->index == -1) { in cs35l41_hda_read_acpi()
1470 dev_err(cs35l41->dev, "No index found in %s\n", property); in cs35l41_hda_read_acpi()
1478 cs35l41->reset_gpio = fwnode_gpiod_get_index(acpi_fwnode_handle(adev), "reset", cs35l41->index, in cs35l41_hda_read_acpi()
1485 hw_cfg->spk_pos = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1487 cs35l41->channel_index = 0; in cs35l41_hda_read_acpi()
1488 for (i = 0; i < cs35l41->index; i++) in cs35l41_hda_read_acpi()
1490 cs35l41->channel_index++; in cs35l41_hda_read_acpi()
1496 hw_cfg->gpio1.func = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1503 hw_cfg->gpio2.func = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1509 hw_cfg->bst_ipk = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1516 hw_cfg->bst_ind = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1523 hw_cfg->bst_cap = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1527 cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, nval, -1); in cs35l41_hda_read_acpi()
1540 dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret); in cs35l41_hda_read_acpi()
1554 struct cs35l41_hda *cs35l41; in cs35l41_hda_probe() local
1563 cs35l41 = devm_kzalloc(dev, sizeof(*cs35l41), GFP_KERNEL); in cs35l41_hda_probe()
1564 if (!cs35l41) in cs35l41_hda_probe()
1567 cs35l41->dev = dev; in cs35l41_hda_probe()
1568 cs35l41->irq = irq; in cs35l41_hda_probe()
1569 cs35l41->regmap = regmap; in cs35l41_hda_probe()
1570 dev_set_drvdata(dev, cs35l41); in cs35l41_hda_probe()
1572 ret = cs35l41_hda_read_acpi(cs35l41, device_name, id); in cs35l41_hda_probe()
1574 return dev_err_probe(cs35l41->dev, ret, "Platform not supported\n"); in cs35l41_hda_probe()
1576 if (IS_ERR(cs35l41->reset_gpio)) { in cs35l41_hda_probe()
1577 ret = PTR_ERR(cs35l41->reset_gpio); in cs35l41_hda_probe()
1578 cs35l41->reset_gpio = NULL; in cs35l41_hda_probe()
1580 dev_info(cs35l41->dev, "Reset line busy, assuming shared reset\n"); in cs35l41_hda_probe()
1582 dev_err_probe(cs35l41->dev, ret, "Failed to get reset GPIO\n"); in cs35l41_hda_probe()
1586 if (cs35l41->reset_gpio) { in cs35l41_hda_probe()
1588 gpiod_set_value_cansleep(cs35l41->reset_gpio, 1); in cs35l41_hda_probe()
1593 ret = regmap_read_poll_timeout(cs35l41->regmap, CS35L41_IRQ1_STATUS4, int_status, in cs35l41_hda_probe()
1596 dev_err(cs35l41->dev, "Failed waiting for OTP_BOOT_DONE: %d\n", ret); in cs35l41_hda_probe()
1600 ret = regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS3, &int_sts); in cs35l41_hda_probe()
1602 dev_err(cs35l41->dev, "OTP Boot status %x error: %d\n", in cs35l41_hda_probe()
1608 ret = regmap_read(cs35l41->regmap, CS35L41_DEVID, ®id); in cs35l41_hda_probe()
1610 dev_err(cs35l41->dev, "Get Device ID failed: %d\n", ret); in cs35l41_hda_probe()
1614 ret = regmap_read(cs35l41->regmap, CS35L41_REVID, ®_revid); in cs35l41_hda_probe()
1616 dev_err(cs35l41->dev, "Get Revision ID failed: %d\n", ret); in cs35l41_hda_probe()
1624 dev_err(cs35l41->dev, "CS35L41 Device ID (%X). Expected ID %X\n", regid, chipid); in cs35l41_hda_probe()
1629 ret = cs35l41_test_key_unlock(cs35l41->dev, cs35l41->regmap); in cs35l41_hda_probe()
1633 ret = cs35l41_register_errata_patch(cs35l41->dev, cs35l41->regmap, reg_revid); in cs35l41_hda_probe()
1637 ret = cs35l41_otp_unpack(cs35l41->dev, cs35l41->regmap); in cs35l41_hda_probe()
1639 dev_err(cs35l41->dev, "OTP Unpack failed: %d\n", ret); in cs35l41_hda_probe()
1643 ret = cs35l41_test_key_lock(cs35l41->dev, cs35l41->regmap); in cs35l41_hda_probe()
1647 ret = regmap_multi_reg_write(cs35l41->regmap, cs35l41_hda_mute, in cs35l41_hda_probe()
1652 INIT_WORK(&cs35l41->fw_load_work, cs35l41_fw_load_work); in cs35l41_hda_probe()
1653 mutex_init(&cs35l41->fw_mutex); in cs35l41_hda_probe()
1655 pm_runtime_set_autosuspend_delay(cs35l41->dev, 3000); in cs35l41_hda_probe()
1656 pm_runtime_use_autosuspend(cs35l41->dev); in cs35l41_hda_probe()
1657 pm_runtime_mark_last_busy(cs35l41->dev); in cs35l41_hda_probe()
1658 pm_runtime_set_active(cs35l41->dev); in cs35l41_hda_probe()
1659 pm_runtime_get_noresume(cs35l41->dev); in cs35l41_hda_probe()
1660 pm_runtime_enable(cs35l41->dev); in cs35l41_hda_probe()
1662 ret = cs35l41_hda_apply_properties(cs35l41); in cs35l41_hda_probe()
1666 pm_runtime_put_autosuspend(cs35l41->dev); in cs35l41_hda_probe()
1668 ret = component_add(cs35l41->dev, &cs35l41_hda_comp_ops); in cs35l41_hda_probe()
1670 dev_err(cs35l41->dev, "Register component failed: %d\n", ret); in cs35l41_hda_probe()
1671 pm_runtime_disable(cs35l41->dev); in cs35l41_hda_probe()
1675 dev_info(cs35l41->dev, "Cirrus Logic CS35L41 (%x), Revision: %02X\n", regid, reg_revid); in cs35l41_hda_probe()
1680 pm_runtime_disable(cs35l41->dev); in cs35l41_hda_probe()
1681 pm_runtime_put_noidle(cs35l41->dev); in cs35l41_hda_probe()
1684 if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type)) in cs35l41_hda_probe()
1685 gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); in cs35l41_hda_probe()
1686 gpiod_put(cs35l41->reset_gpio); in cs35l41_hda_probe()
1687 kfree(cs35l41->acpi_subsystem_id); in cs35l41_hda_probe()
1695 struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); in cs35l41_hda_remove() local
1697 pm_runtime_get_sync(cs35l41->dev); in cs35l41_hda_remove()
1698 pm_runtime_disable(cs35l41->dev); in cs35l41_hda_remove()
1700 if (cs35l41->halo_initialized) in cs35l41_hda_remove()
1701 cs35l41_remove_dsp(cs35l41); in cs35l41_hda_remove()
1703 component_del(cs35l41->dev, &cs35l41_hda_comp_ops); in cs35l41_hda_remove()
1705 pm_runtime_put_noidle(cs35l41->dev); in cs35l41_hda_remove()
1707 if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type)) in cs35l41_hda_remove()
1708 gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); in cs35l41_hda_remove()
1709 gpiod_put(cs35l41->reset_gpio); in cs35l41_hda_remove()
1710 kfree(cs35l41->acpi_subsystem_id); in cs35l41_hda_remove()