Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d93feb4 authored by nadlabak's avatar nadlabak Committed by Arne Coucheron
Browse files

hal: Port the dock support to non-legacy 8960 hal

- allows to define and use 'dock' and 'speaker-and-dock' mixer paths
- can be enabled by the same board flags used in legacy hal:
  BOARD_USES_MOTOROLA_EMU_AUDIO or BOARD_HAVE_SAMSUNG_AUDIO

Change-Id: I04732856ee2b87295aced3e01995720009900974
parent c4b7b464
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -140,6 +140,14 @@ ifeq ($(strip $(BOARD_HAVE_SAMSUNG_CSDCLIENT)),true)
    LOCAL_CFLAGS += -DSAMSUNG_CSDCLIENT
endif

ifeq ($(strip $(BOARD_USES_MOTOROLA_EMU_AUDIO)),true)
    LOCAL_CFLAGS += -DDOCK_SUPPORT -DMOTOROLA_EMU_AUDIO
endif

ifeq ($(strip $(BOARD_HAVE_SAMSUNG_AUDIO)),true)
    LOCAL_CFLAGS += -DDOCK_SUPPORT
endif

LOCAL_SHARED_LIBRARIES := \
	liblog \
	libcutils \
+92 −0
Original line number Diff line number Diff line
@@ -219,6 +219,10 @@ static char * device_table[SND_DEVICE_MAX] = {
    [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset-comm",
    [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker-comm",
    [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headset-comm",
#ifdef DOCK_SUPPORT
    [SND_DEVICE_OUT_DOCK] = "dock",
    [SND_DEVICE_OUT_SPEAKER_AND_DOCK] = "speaker-and-dock",
#endif

    /* Capture sound devices */
    [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
@@ -382,6 +386,10 @@ static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
    {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
#ifdef DOCK_SUPPORT
    {TO_NAME_INDEX(SND_DEVICE_OUT_DOCK)},
    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_DOCK)},
#endif
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
@@ -1347,12 +1355,58 @@ int platform_set_device_mute(void *platform, bool state, char *dir)
    return ret;
}

#ifdef DOCK_SUPPORT
bool is_dock_connected()
{
    FILE *dock_node = NULL;
    char buf[32];
    bool connected = false;

    dock_node = fopen(DOCK_SWITCH, "r");
    if (dock_node) {
        fread(buf, sizeof(char), 32, dock_node);
        connected = atoi(buf) > 0;
        fclose(dock_node);
    }
    return connected;
}
#endif

#ifdef MOTOROLA_EMU_AUDIO
int emu_antipop_state = 0;

int set_emu_antipop(struct audio_device *adev, int emu_antipop)
{
    struct mixer_ctl *ctl;
    const char *mixer_ctl_name = "EMU Antipop";

    if (emu_antipop == emu_antipop_state) return 0;

    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
    if (!ctl) {
        ALOGE("%s: Could not get ctl for mixer cmd - %s",
              __func__, mixer_ctl_name);
        return -EINVAL;
    }
    ALOGV("Setting EMU Antipop to %d", emu_antipop);
    mixer_ctl_set_value(ctl, 0, emu_antipop);
    emu_antipop_state = emu_antipop;
    return 0;
}
#endif

snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
{
    struct platform_data *my_data = (struct platform_data *)platform;
    struct audio_device *adev = my_data->adev;
    audio_mode_t mode = adev->mode;
    snd_device_t snd_device = SND_DEVICE_NONE;
#ifdef DOCK_SUPPORT
    bool dock_connected = is_dock_connected();
#ifdef MOTOROLA_EMU_AUDIO
    if (!dock_connected) set_emu_antipop(adev, 0);
#endif
#endif

    audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
                                AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
@@ -1382,6 +1436,14 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
                               AUDIO_DEVICE_OUT_SPEAKER)) ||
                    devices == (AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
                               AUDIO_DEVICE_OUT_SPEAKER)) {
#ifdef DOCK_SUPPORT
            if (dock_connected) {
                snd_device = SND_DEVICE_OUT_SPEAKER_AND_DOCK;
#ifdef MOTOROLA_EMU_AUDIO
                set_emu_antipop(adev, 1);
#endif
            } else
#endif
            snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
        } else {
            ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
@@ -1444,6 +1506,14 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
            }
        } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
                   devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
#ifdef DOCK_SUPPORT
            if (dock_connected) {
                snd_device = SND_DEVICE_OUT_DOCK;
#ifdef MOTOROLA_EMU_AUDIO
                set_emu_antipop(adev, 1);
#endif
            } else
#endif
            snd_device = SND_DEVICE_OUT_USB_HEADSET;
        } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
            snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
@@ -1487,9 +1557,20 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
        snd_device = SND_DEVICE_OUT_HDMI ;
    } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
               devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
#ifdef DOCK_SUPPORT
        if (dock_connected) {
            snd_device = SND_DEVICE_OUT_DOCK;
#ifdef MOTOROLA_EMU_AUDIO
            set_emu_antipop(adev, 1);
#endif
        } else {
#endif
        ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
        audio_extn_set_afe_proxy_channel_mixer(adev, 2);
        snd_device = SND_DEVICE_OUT_USB_HEADSET;
#ifdef DOCK_SUPPORT
        }
#endif
    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
@@ -1524,6 +1605,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
                                AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
    snd_device_t snd_device = SND_DEVICE_NONE;
    int channel_count = popcount(channel_mask);
#ifdef DOCK_SUPPORT
    bool dock_connected = is_dock_connected();
#endif

    ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
          __func__, out_device, in_device);
@@ -1709,6 +1793,10 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            snd_device = SND_DEVICE_IN_HDMI_MIC;
        } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
                   in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
#ifdef DOCK_SUPPORT
            if (dock_connected) snd_device = SND_DEVICE_IN_HANDSET_MIC;
            else
#endif
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
            snd_device = SND_DEVICE_IN_CAPTURE_FM;
@@ -1738,6 +1826,10 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            snd_device = SND_DEVICE_IN_HDMI_MIC;
        } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
                   out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
#ifdef DOCK_SUPPORT
            if (dock_connected) snd_device = SND_DEVICE_IN_HANDSET_MIC;
            else
#endif
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else {
            ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
+17 −0
Original line number Diff line number Diff line
@@ -31,9 +31,16 @@ enum {
 * All these devices are handled by the internal HW codec. We can
 * enable any one of these devices at any time
 */
#ifdef DOCK_SUPPORT
#define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \
    (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \
     AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE | \
     AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)
#else
#define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \
    (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \
     AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
#endif

/* Sound devices specific to the platform
 * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound
@@ -75,6 +82,10 @@ enum {
    SND_DEVICE_OUT_VOIP_HANDSET,
    SND_DEVICE_OUT_VOIP_SPEAKER,
    SND_DEVICE_OUT_VOIP_HEADPHONES,
#ifdef DOCK_SUPPORT
    SND_DEVICE_OUT_DOCK,
    SND_DEVICE_OUT_SPEAKER_AND_DOCK,
#endif
    SND_DEVICE_OUT_END,

    /*
@@ -292,4 +303,10 @@ struct csd_data {
    stop_record_t stop_record;
};

#ifdef MOTOROLA_EMU_AUDIO
#define DOCK_SWITCH "/sys/devices/virtual/switch/semu_audio/state"
#elif DOCK_SUPPORT
#define DOCK_SWITCH "/sys/devices/virtual/switch/dock/state"
#endif

#endif // QCOM_AUDIO_PLATFORM_H