From 432f38af1f8e09b40fb17db3b9b30cd1916e19ad Mon Sep 17 00:00:00 2001 From: hmz007 Date: Sat, 1 Nov 2025 12:45:58 +0800 Subject: [PATCH] rockchip: tinyalsa_hal: add support for es8389 codec Signed-off-by: hmz007 --- .../rockchip/audio/tinyalsa_hal/audio_hw.c | 15 +- .../tinyalsa_hal/codec_config/config_list.h | 5 + .../tinyalsa_hal/codec_config/es8389_config.h | 361 ++++++++++++++++++ 3 files changed, 378 insertions(+), 3 deletions(-) create mode 100644 hardware/rockchip/audio/tinyalsa_hal/codec_config/es8389_config.h diff --git a/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c b/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c index 7f83792bfbd..9f59b68ea93 100644 --- a/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c +++ b/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c @@ -520,6 +520,7 @@ struct dev_proc_info SPEAKER_OUT_NAME[] = /* add codes& dai name here*/ {"rockchipes8323c", NULL,}, {"rockchipes8388c", NULL,}, {"rockchipes8388", NULL,}, + {"rockchipes8389", NULL,}, {"rockchipes8396c", NULL,}, {"rockchiprk", NULL, }, {"rockchiprk809co", NULL,}, @@ -589,6 +590,7 @@ struct dev_proc_info MIC_IN_NAME[] = {"rockchipes8323c", NULL,}, {"rockchipes8388c", NULL,}, {"rockchipes8388", NULL,}, + {"rockchipes8389", NULL,}, {"rockchipes8396c", NULL,}, {"rockchipes7210", NULL,}, {"rockchipes7243", NULL,}, @@ -625,14 +627,22 @@ struct dev_proc_info BT_IN_NAME[] = static int name_match(const char* dst, const char* src) { int score = 0; + char value[PROPERTY_VALUE_MAX] = ""; + // total equal if (!strcmp(dst, src)) { score = 100; - } else if (strstr(dst, src)) { + } else if (strstr(dst, src)) { // part equal score = 50; } + if (score > 0 && property_get("persist.vendor.audio.card", value, NULL) > 0) { + if (!strcmp(dst, value)) { + score = 110; + } + } + return score; } @@ -885,7 +895,6 @@ static void dumpdev_info(const char *tag, struct dev_info *devinfo, int count) */ static void read_out_sound_card(struct stream_out *out) { - struct audio_device *device = NULL; int card = 0; char str[32]; @@ -916,7 +925,7 @@ static void read_out_sound_card(struct stream_out *out) len--; id[len] = '\0'; } - ALOGD("card%d id:%s", card, id); + ALOGD("card%d id: %s", card, id); get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_SPEAKER], card, id, SPEAKER_OUT_NAME); get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_HDMI], card, id, HDMI_OUT_NAME); get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_HDMI_1], card, id, HDMI_1_OUT_NAME); diff --git a/hardware/rockchip/audio/tinyalsa_hal/codec_config/config_list.h b/hardware/rockchip/audio/tinyalsa_hal/codec_config/config_list.h index 4f7bc006839..b4aa28d6aa2 100644 --- a/hardware/rockchip/audio/tinyalsa_hal/codec_config/config_list.h +++ b/hardware/rockchip/audio/tinyalsa_hal/codec_config/config_list.h @@ -26,6 +26,7 @@ #include "es8396_config.h" #include "rt5651_config.h" #include "es8316_config.h" +#include "es8389_config.h" #include "cx2072_config.h" #include "hdmi_analog_config.h" @@ -69,6 +70,10 @@ struct alsa_sound_card_config sound_card_config_list[] = { .sound_card_name = "rockchipes8388c", .route_table = &es8388_config_table, }, + { + .sound_card_name = "rockchipes8389", + .route_table = &es8389_config_table, + }, { .sound_card_name = "rockchipes8396c", .route_table = &es8396_config_table, diff --git a/hardware/rockchip/audio/tinyalsa_hal/codec_config/es8389_config.h b/hardware/rockchip/audio/tinyalsa_hal/codec_config/es8389_config.h new file mode 100644 index 00000000000..454a2a2e968 --- /dev/null +++ b/hardware/rockchip/audio/tinyalsa_hal/codec_config/es8389_config.h @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2025 FriendlyElec Computer Tech. Co., Ltd. + * (http://www.friendlyelec.com) + * + * Copyright (C) 2015 Rockchip Electronics Co., Ltd. + */ + +#ifndef _ES8389_CONFIG_H_ +#define _ES8389_CONFIG_H_ + +#include "config.h" + +const struct config_control es8389_speaker_normal_controls[] = { +}; + +const struct config_control es8389_speaker_incall_controls[] = { + +}; + +const struct config_control es8389_speaker_ringtone_controls[] = { + +}; + +const struct config_control es8389_speaker_voip_controls[] = { + +}; + +const struct config_control es8389_earpiece_normal_controls[] = { + +}; + +const struct config_control es8389_earpiece_incall_controls[] = { + +}; + +const struct config_control es8389_earpiece_ringtone_controls[] = { + +}; + +const struct config_control es8389_earpiece_voip_controls[] = { + +}; + +const struct config_control es8389_headphone_normal_controls[] = { +#if 0 + { + .ctl_name = "DACL Playback Volume", + .int_val = {191}, + }, + { + .ctl_name = "DACR Playback Volume", + .int_val = {191}, + }, +#endif +}; + +const struct config_control es8389_headphone_incall_controls[] = { + +}; + +const struct config_control es8389_headphone_ringtone_controls[] = { + +}; + +const struct config_control es8389_speaker_headphone_normal_controls[] = { + +}; + +const struct config_control es8389_speaker_headphone_ringtone_controls[] = { + +}; + +const struct config_control es8389_headphone_voip_controls[] = { + +}; + +const struct config_control es8389_headset_normal_controls[] = { +}; + +const struct config_control es8389_headset_incall_controls[] = { + +}; + +const struct config_control es8389_headset_ringtone_controls[] = { + +}; + +const struct config_control es8389_headset_voip_controls[] = { + +}; + +const struct config_control es8389_bluetooth_normal_controls[] = { + +}; + +const struct config_control es8389_bluetooth_incall_controls[] = { + +}; + +const struct config_control es8389_bluetooth_voip_controls[] = { + +}; + +const struct config_control es8389_hands_free_mic_capture_controls[] = { + { + .ctl_name = "ADCL PGA Volume", + .int_val = {12}, + }, + { + .ctl_name = "ADCR PGA Volume", + .int_val = {12}, + }, + + { + .ctl_name = "ADCL Capture Volume", + .int_val = {235}, + }, + { + .ctl_name = "ADCR Capture Volume", + .int_val = {235}, + }, +}; + +const struct config_control es8389_main_mic_capture_controls[] = { + { + .ctl_name = "ADCL PGA Volume", + .int_val = {12}, + // ==> 30.5 dB + }, + { + .ctl_name = "ADCR PGA Volume", + .int_val = {12}, + }, + + { + .ctl_name = "ADCL Capture Volume", + .int_val = {231}, + // ==> 231 * 0.5 - 95.5 = 20 dB + }, + { + .ctl_name = "ADCR Capture Volume", + .int_val = {231}, + }, +}; + +const struct config_control es8389_bluetooth_sco_mic_capture_controls[] = { + +}; + +const struct config_control es8389_playback_off_controls[] = { + +}; + +const struct config_control es8389_capture_off_controls[] = { + +}; + +const struct config_control es8389_incall_off_controls[] = { + +}; + +const struct config_control es8389_voip_off_controls[] = { + +}; + +const struct config_route_table es8389_config_table = { + //speaker + .speaker_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_normal_controls, + .controls_count = sizeof(es8389_speaker_normal_controls) / sizeof(struct config_control), + }, + .speaker_incall = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_incall_controls, + .controls_count = sizeof(es8389_speaker_incall_controls) / sizeof(struct config_control), + }, + .speaker_ringtone = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_ringtone_controls, + .controls_count = sizeof(es8389_speaker_ringtone_controls) / sizeof(struct config_control), + }, + .speaker_voip = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_voip_controls, + .controls_count = sizeof(es8389_speaker_voip_controls) / sizeof(struct config_control), + }, + + //earpiece + .earpiece_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_earpiece_normal_controls, + .controls_count = sizeof(es8389_earpiece_normal_controls) / sizeof(struct config_control), + }, + .earpiece_incall = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_earpiece_incall_controls, + .controls_count = sizeof(es8389_earpiece_incall_controls) / sizeof(struct config_control), + }, + .earpiece_ringtone = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_earpiece_ringtone_controls, + .controls_count = sizeof(es8389_earpiece_ringtone_controls) / sizeof(struct config_control), + }, + .earpiece_voip = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_earpiece_voip_controls, + .controls_count = sizeof(es8389_earpiece_voip_controls) / sizeof(struct config_control), + }, + + //headphone + .headphone_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headphone_normal_controls, + .controls_count = sizeof(es8389_headphone_normal_controls) / sizeof(struct config_control), + }, + .headphone_incall = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headphone_incall_controls, + .controls_count = sizeof(es8389_headphone_incall_controls) / sizeof(struct config_control), + }, + .headphone_ringtone = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headphone_ringtone_controls, + .controls_count = sizeof(es8389_headphone_ringtone_controls) / sizeof(struct config_control), + }, + .speaker_headphone_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_headphone_normal_controls, + .controls_count = sizeof(es8389_speaker_headphone_normal_controls) / sizeof(struct config_control), + }, + .speaker_headphone_ringtone = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_speaker_headphone_ringtone_controls, + .controls_count = sizeof(es8389_speaker_headphone_ringtone_controls) / sizeof(struct config_control), + }, + .headphone_voip = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headphone_voip_controls, + .controls_count = sizeof(es8389_headphone_voip_controls) / sizeof(struct config_control), + }, + + //headset + .headset_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headset_normal_controls, + .controls_count = sizeof(es8389_headset_normal_controls) / sizeof(struct config_control), + }, + .headset_incall = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headset_incall_controls, + .controls_count = sizeof(es8389_headset_incall_controls) / sizeof(struct config_control), + }, + .headset_ringtone = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headset_ringtone_controls, + .controls_count = sizeof(es8389_headset_ringtone_controls) / sizeof(struct config_control), + }, + .headset_voip = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_headset_voip_controls, + .controls_count = sizeof(es8389_headset_voip_controls) / sizeof(struct config_control), + }, + + //bluetooth + .bluetooth_normal = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_bluetooth_normal_controls, + .controls_count = sizeof(es8389_bluetooth_normal_controls) / sizeof(struct config_control), + }, + .bluetooth_incall = { + .sound_card = 0, + .devices = DEVICES_0_1, + .controls = es8389_bluetooth_incall_controls, + .controls_count = sizeof(es8389_bluetooth_incall_controls) / sizeof(struct config_control), + }, + .bluetooth_voip = { + .sound_card = 0, + .devices = DEVICES_0_1, + .controls = es8389_bluetooth_voip_controls, + .controls_count = sizeof(es8389_bluetooth_voip_controls) / sizeof(struct config_control), + }, + + //capture + .main_mic_capture = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_main_mic_capture_controls, + .controls_count = sizeof(es8389_main_mic_capture_controls) / sizeof(struct config_control), + }, + .hands_free_mic_capture = { + .sound_card = 0, + .devices = DEVICES_0, + .controls = es8389_hands_free_mic_capture_controls, + .controls_count = sizeof(es8389_hands_free_mic_capture_controls) / sizeof(struct config_control), + }, + .bluetooth_sco_mic_capture = { + .sound_card = 0, + .devices = DEVICES_0_1, + .controls = es8389_bluetooth_sco_mic_capture_controls, + .controls_count = sizeof(es8389_bluetooth_sco_mic_capture_controls) / sizeof(struct config_control), + }, + + //off + .playback_off = { + .controls = es8389_playback_off_controls, + .controls_count = sizeof(es8389_playback_off_controls) / sizeof(struct config_control), + }, + .capture_off = { + .controls = es8389_capture_off_controls, + .controls_count = sizeof(es8389_capture_off_controls) / sizeof(struct config_control), + }, + .incall_off = { + .controls = es8389_incall_off_controls, + .controls_count = sizeof(es8389_incall_off_controls) / sizeof(struct config_control), + }, + .voip_off = { + .controls = es8389_voip_off_controls, + .controls_count = sizeof(es8389_voip_off_controls) / sizeof(struct config_control), + }, + + //hdmi + .hdmi_normal = { + .sound_card = 1, + .devices = DEVICES_0, + .controls_count = 0, + }, + + //usb audio + .usb_normal = { + .sound_card = 2, + .devices = DEVICES_0, + .controls_count = 0, + }, + .usb_capture = { + .sound_card = 2, + .devices = DEVICES_0, + .controls_count = 0, + }, +}; + +#endif //_ES8389_CONFIG_H_