Lines Matching +full:dcm +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
49 { CS35L41_SP_HIZ_CTRL, 0x00000002 }, // Hi-Z unused
71 { CS35L41_SP_HIZ_CTRL, 0x00000003 }, // Hi-Z unused/disabled
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()
121 const char * const dsp_name = cs35l41->cs_dsp.name; in cs35l41_request_firmware_file()
125 if (spkid > -1 && ssid && amp_name) in cs35l41_request_firmware_file()
126 *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-spkid%d-%s.%s", dir, CS35L41_PART, in cs35l41_request_firmware_file()
127 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
129 else if (spkid > -1 && ssid) in cs35l41_request_firmware_file()
130 *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-spkid%d.%s", dir, CS35L41_PART, in cs35l41_request_firmware_file()
131 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
134 *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, CS35L41_PART, in cs35l41_request_firmware_file()
135 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
138 *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, CS35L41_PART, in cs35l41_request_firmware_file()
139 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
142 *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, CS35L41_PART, in cs35l41_request_firmware_file()
143 dsp_name, hda_cs_dsp_fw_ids[cs35l41->firmware_type], in cs35l41_request_firmware_file()
147 return -ENOMEM; in cs35l41_request_firmware_file()
150 * Make sure that filename is lower-case and any non alpha-numeric in cs35l41_request_firmware_file()
159 *s = '-'; 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()
181 /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.wmfw */ 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()
187 /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */ 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()
198 /* try cirrus/part-dspN-fwtype-sub<-ampname>.wmfw */ 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()
203 /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */ 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()
214 /* try cirrus/part-dspN-fwtype-sub<-spkidN>.wmfw */ 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()
219 /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */ 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()
225 /* try cirrus/part-dspN-fwtype-sub<-spkidN>.bin */ 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()
236 /* try cirrus/part-dspN-fwtype-sub.wmfw */ in cs35l41_request_firmware_files_spkid()
238 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files_spkid()
239 NULL, -1, "wmfw"); in cs35l41_request_firmware_files_spkid()
241 /* try cirrus/part-dspN-fwtype-sub<-spkidN><-ampname>.bin */ 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()
247 /* try cirrus/part-dspN-fwtype-sub<-spkidN>.bin */ 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()
272 dev_warn(cs35l41->dev, "Falling back to default firmware.\n"); in cs35l41_fallback_firmware_file()
274 /* fallback try cirrus/part-dspN-fwtype.wmfw */ in cs35l41_fallback_firmware_file()
276 CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "wmfw"); in cs35l41_fallback_firmware_file()
280 /* fallback try cirrus/part-dspN-fwtype.bin */ in cs35l41_fallback_firmware_file()
282 CS35L41_FIRMWARE_ROOT, NULL, NULL, -1, "bin"); in cs35l41_fallback_firmware_file()
291 dev_warn(cs35l41->dev, "Unable to find firmware and tuning\n"); in cs35l41_fallback_firmware_file()
303 if (cs35l41->speaker_id > -1) { in cs35l41_request_firmware_files()
309 /* try cirrus/part-dspN-fwtype-sub<-ampname>.wmfw */ 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()
314 /* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */ in cs35l41_request_firmware_files()
317 cs35l41->acpi_subsystem_id, cs35l41->amp_name, in cs35l41_request_firmware_files()
318 -1, "bin"); in cs35l41_request_firmware_files()
325 /* try cirrus/part-dspN-fwtype-sub.wmfw */ in cs35l41_request_firmware_files()
327 CS35L41_FIRMWARE_ROOT, cs35l41->acpi_subsystem_id, in cs35l41_request_firmware_files()
328 NULL, -1, "wmfw"); in cs35l41_request_firmware_files()
330 /* try cirrus/part-dspN-fwtype-sub<-ampname>.bin */ 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()
336 /* try cirrus/part-dspN-fwtype-sub.bin */ in cs35l41_request_firmware_files()
339 cs35l41->acpi_subsystem_id, NULL, -1, in cs35l41_request_firmware_files()
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()
413 ret = -ENODEV; in cs35l41_save_calibration()
417 return -ENOMEM; in cs35l41_save_calibration()
422 dev_dbg(cs35l41->dev, "Calibration: Size=%d, Amp Count=%d\n", in cs35l41_save_calibration()
423 efi_data->size, efi_data->count); 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()
428 cl->calAmbient, cl->calStatus, cl->calR); in cs35l41_save_calibration()
432 cpu_to_be32(cl->calAmbient), in cs35l41_save_calibration()
433 cpu_to_be32(cl->calR), in cs35l41_save_calibration()
434 cpu_to_be32(cl->calStatus), in cs35l41_save_calibration()
435 cpu_to_be32(cl->calR + 1)); in cs35l41_save_calibration()
445 dev_warn(cs35l41->dev, "Calibration not supported without EFI support.\n"); in cs35l41_save_calibration()
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()
461 dsp->client_ops = &client_ops; 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()
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()
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()
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()
517 cs35l41->halo_initialized = false; in cs35l41_remove_dsp()
518 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_remove_dsp()
521 /* Protection release cycle to get the speaker out of Safe-Mode */
532 cs35l41_error_release(cs35l41->dev, cs35l41->regmap, cs35l41->irq_errors); in cs35l41_irq_release()
533 cs35l41->irq_errors = 0; in cs35l41_irq_release()
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()
569 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_play_done()
573 cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 1, in cs35l41_hda_play_done()
574 cs35l41->firmware_running); in cs35l41_hda_play_done()
575 if (cs35l41->firmware_running) { in cs35l41_hda_play_done()
587 struct regmap *reg = cs35l41->regmap; in cs35l41_hda_pause_start()
592 cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 0, in cs35l41_hda_pause_start()
593 cs35l41->firmware_running); in cs35l41_hda_pause_start()
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()
613 cs35l41->playback_started = false; in cs35l41_hda_pause_done()
622 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_pre_playback_hook()
624 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_pre_playback_hook()
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()
682 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_post_playback_hook()
684 mutex_unlock(&cs35l41->fw_mutex); in cs35l41_hda_post_playback_hook()
697 if (!cs35l41->amp_name) { in cs35l41_hda_channel_map()
699 return -EINVAL; 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()
704 return -ENOMEM; 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()
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()
726 /* Test key needs to be unlocked to allow the OTP settings to re-apply */ 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()
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()
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()
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()
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()
845 if (cs35l41->hw_cfg.bst_type == CS35L41_EXT_BOOST_NO_VSPK_SWITCH) in cs35l41_runtime_idle()
846 return -EBUSY; /* suspend not supported yet on this model */ in cs35l41_runtime_idle()
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()
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()
906 /* Test key needs to be unlocked to allow the OTP settings to re-apply */ 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()
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()
976 if (cs35l41->firmware_running && !load) { in cs35l41_load_firmware()
977 dev_dbg(cs35l41->dev, "Unloading Firmware\n"); 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()
983 dev_dbg(cs35l41->dev, "Unable to Load firmware.\n"); in cs35l41_load_firmware()
992 ucontrol->value.integer.value[0] = cs35l41->request_fw_load; in cs35l41_fw_load_ctl_get()
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()
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()
1027 return -EBUSY; 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()
1033 return -EBUSY; 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()
1048 ucontrol->value.enumerated.item[0] = cs35l41->firmware_type; in cs35l41_fw_type_ctl_get()
1058 if (ucontrol->value.enumerated.item[0] < HDA_CS_DSP_NUM_FW) { in cs35l41_fw_type_ctl_put()
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()
1067 return -EINVAL; in cs35l41_fw_type_ctl_put()
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()
1126 if (!comps || cs35l41->index < 0 || cs35l41->index >= HDA_MAX_COMPONENTS) in cs35l41_hda_bind()
1127 return -EINVAL; in cs35l41_hda_bind()
1129 comps = &comps[cs35l41->index]; in cs35l41_hda_bind()
1130 if (comps->dev) in cs35l41_hda_bind()
1131 return -EBUSY; in cs35l41_hda_bind()
1135 mutex_lock(&cs35l41->fw_mutex); in cs35l41_hda_bind()
1137 comps->dev = dev; 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()
1140 comps->codec->core.subsystem_id); in cs35l41_hda_bind()
1141 cs35l41->codec = comps->codec; in cs35l41_hda_bind()
1142 strscpy(comps->name, dev_name(dev), sizeof(comps->name)); 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()
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()
1157 comps->playback_hook = cs35l41_hda_playback_hook; in cs35l41_hda_bind()
1158 comps->pre_playback_hook = cs35l41_hda_pre_playback_hook; in cs35l41_hda_bind()
1159 comps->post_playback_hook = cs35l41_hda_post_playback_hook; 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()
1172 "CS35L41 Bound - SSID: %s, BST: %d, VSPK: %d, CH: %c, FW EN: %d, SPKID: %d\n", 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()
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(&cs35l41->codec->core.dev, cs35l41->dev); in cs35l41_hda_unbind()
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()
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()
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()
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()
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()
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()
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()
1298 return -EINVAL; in cs35l41_hda_apply_properties()
1300 ret = cs35l41_init_boost(cs35l41->dev, cs35l41->regmap, hw_cfg); in cs35l41_hda_apply_properties()
1304 if (hw_cfg->gpio1.valid) { in cs35l41_hda_apply_properties()
1305 switch (hw_cfg->gpio1.func) { in cs35l41_hda_apply_properties()
1309 hw_cfg->gpio1.func = CS35L41_GPIO1_GPIO; in cs35l41_hda_apply_properties()
1310 hw_cfg->gpio1.out_en = true; in cs35l41_hda_apply_properties()
1313 hw_cfg->gpio1.func = CS35L41_GPIO1_MDSYNC; in cs35l41_hda_apply_properties()
1316 dev_err(cs35l41->dev, "Invalid function %d for GPIO1\n", in cs35l41_hda_apply_properties()
1317 hw_cfg->gpio1.func); in cs35l41_hda_apply_properties()
1318 return -EINVAL; in cs35l41_hda_apply_properties()
1322 if (hw_cfg->gpio2.valid) { in cs35l41_hda_apply_properties()
1323 switch (hw_cfg->gpio2.func) { in cs35l41_hda_apply_properties()
1328 hw_cfg->gpio2.func = CS35L41_GPIO2_INT_OPEN_DRAIN; in cs35l41_hda_apply_properties()
1331 dev_err(cs35l41->dev, "Invalid GPIO2 function %d\n", hw_cfg->gpio2.func); in cs35l41_hda_apply_properties()
1332 return -EINVAL; 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()
1359 return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos); in cs35l41_hda_apply_properties()
1365 int speaker_id = -ENODEV; in cs35l41_get_speaker_id()
1384 count = gpiod_count(dev, "spk-id"); in cs35l41_get_speaker_id()
1391 return -EINVAL; in cs35l41_get_speaker_id()
1393 dev_dbg(dev, "Found %d Speaker ID GPIOs per Amp\n", gpios_per_amp); in cs35l41_get_speaker_id()
1396 speaker_id_desc = gpiod_get_index(dev, "spk-id", i + base_index, in cs35l41_get_speaker_id()
1418 struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; in cs35l41_hda_read_acpi()
1427 adev = acpi_dev_get_first_match_dev(hid, NULL, -1); 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()
1430 return -ENODEV; in cs35l41_hda_read_acpi()
1439 cs35l41->acpi_subsystem_id = sub; in cs35l41_hda_read_acpi()
1443 dev_info(cs35l41->dev, "Using extra _DSD properties, bypassing _DSD in ACPI\n"); in cs35l41_hda_read_acpi()
1447 property = "cirrus,dev-index"; in cs35l41_hda_read_acpi()
1453 ret = -EINVAL; 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()
1471 ret = -ENODEV; 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()
1479 GPIOD_OUT_LOW, "cs35l41-reset"); in cs35l41_hda_read_acpi()
1481 property = "cirrus,speaker-position"; 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()
1489 if (values[i] == hw_cfg->spk_pos) in cs35l41_hda_read_acpi()
1490 cs35l41->channel_index++; in cs35l41_hda_read_acpi()
1492 property = "cirrus,gpio1-func"; in cs35l41_hda_read_acpi()
1496 hw_cfg->gpio1.func = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1497 hw_cfg->gpio1.valid = true; in cs35l41_hda_read_acpi()
1499 property = "cirrus,gpio2-func"; in cs35l41_hda_read_acpi()
1503 hw_cfg->gpio2.func = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1504 hw_cfg->gpio2.valid = true; in cs35l41_hda_read_acpi()
1506 property = "cirrus,boost-peak-milliamp"; in cs35l41_hda_read_acpi()
1509 hw_cfg->bst_ipk = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1511 hw_cfg->bst_ipk = -1; in cs35l41_hda_read_acpi()
1513 property = "cirrus,boost-ind-nanohenry"; in cs35l41_hda_read_acpi()
1516 hw_cfg->bst_ind = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1518 hw_cfg->bst_ind = -1; in cs35l41_hda_read_acpi()
1520 property = "cirrus,boost-cap-microfarad"; in cs35l41_hda_read_acpi()
1523 hw_cfg->bst_cap = values[cs35l41->index]; in cs35l41_hda_read_acpi()
1525 hw_cfg->bst_cap = -1; in cs35l41_hda_read_acpi()
1527 cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, cs35l41->index, nval, -1); in cs35l41_hda_read_acpi()
1529 if (hw_cfg->bst_ind > 0 || hw_cfg->bst_cap > 0 || hw_cfg->bst_ipk > 0) in cs35l41_hda_read_acpi()
1530 hw_cfg->bst_type = CS35L41_INT_BOOST; in cs35l41_hda_read_acpi()
1532 hw_cfg->bst_type = CS35L41_EXT_BOOST; in cs35l41_hda_read_acpi()
1534 hw_cfg->valid = true; in cs35l41_hda_read_acpi()
1540 dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret); in cs35l41_hda_read_acpi()
1541 hw_cfg->valid = false; in cs35l41_hda_read_acpi()
1542 hw_cfg->gpio1.valid = false; in cs35l41_hda_read_acpi()
1543 hw_cfg->gpio2.valid = false; in cs35l41_hda_read_acpi()
1565 return -ENOMEM; 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()
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()
1579 if (ret == -EBUSY) { 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()
1604 ret = -EIO; 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()
1625 ret = -ENODEV; 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()
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()
1674 dev_info(cs35l41->dev, "Cirrus Logic CS35L41 (%x), Revision: %02X\n", regid, reg_revid); in cs35l41_hda_probe()
1679 pm_runtime_dont_use_autosuspend(cs35l41->dev); 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()
1697 pm_runtime_get_sync(cs35l41->dev); in cs35l41_hda_remove()
1698 pm_runtime_dont_use_autosuspend(cs35l41->dev); in cs35l41_hda_remove()
1699 pm_runtime_disable(cs35l41->dev); in cs35l41_hda_remove()
1701 if (cs35l41->halo_initialized) in cs35l41_hda_remove()
1704 component_del(cs35l41->dev, &cs35l41_hda_comp_ops); in cs35l41_hda_remove()
1706 pm_runtime_put_noidle(cs35l41->dev); in cs35l41_hda_remove()
1708 if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type)) in cs35l41_hda_remove()
1709 gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); in cs35l41_hda_remove()
1710 gpiod_put(cs35l41->reset_gpio); in cs35l41_hda_remove()
1711 kfree(cs35l41->acpi_subsystem_id); in cs35l41_hda_remove()