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

Commit 9e938360 authored by Laxminath Kasam's avatar Laxminath Kasam Committed by Venkata Narendra Kumar Gutta
Browse files

hal: audio: change wsa detection to sysfs thermal

For WSA detection, use sysfs thermal entry instead
of debugfs. Since debugfs will not be available
in production builds, change detection logic
for WSA presence to use sysfs thermal entries.

Change-Id: I79069d6286fd63b688211826740b89d0a6f8afa7
parent ece0b9ec
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -470,6 +470,7 @@ typedef enum {

int b64decode(char *inp, int ilen, uint8_t* outp);
int b64encode(uint8_t *inp, int ilen, char* outp);
int read_line_from_file(const char *path, char *buf, size_t count);

#ifndef KPI_OPTIMIZE_ENABLED
#define audio_extn_perf_lock_init() (0)
+27 −23
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@
#define SPKR_PROCESSING_IN_PROGRESS 1
#define SPKR_PROCESSING_IN_IDLE 0

#ifdef PLATFORM_MSM8916
#define ACDB_DEVICE_SPKR_PROT_WSA_ANALOG 136
#define ACDB_DEVICE_VI_FEEDBACK_WSA_ANALOG 137
#endif

#define MAX_PATH             (256)
#define THERMAL_SYSFS "/sys/class/thermal"
#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
@@ -151,27 +156,6 @@ static struct pcm_config pcm_config_skr_prot = {
static struct speaker_prot_session handle;
static int vi_feed_no_channels;

int read_line_from_file(const char *path, char *buf, size_t count)
{
    char * fgets_ret;
    FILE * fd;
    int rv;

    fd = fopen(path, "r");
    if (fd == NULL)
        return -1;

    fgets_ret = fgets(buf, (int)count, fd);
    if (NULL != fgets_ret) {
        rv = (int)strlen(buf);
    } else {
        rv = ferror(fd);
    }
    fclose(fd);

   return rv;
}

/*===========================================================================
FUNCTION get_tzn

@@ -950,12 +934,20 @@ void audio_extn_spkr_prot_init(void *adev)
    handle.spkr_prot_t0 = -1;

    if (is_wsa_present()) {
#ifdef PLATFORM_MSM8916
        if (platform_get_wsa_mode(adev) == 1) {
            ALOGD("%s: WSA analog mode", __func__);
            platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED, 136);
            platform_set_snd_device_acdb_id(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, 137);
            platform_set_snd_device_backend(SND_DEVICE_OUT_VOICE_SPEAKER_WSA,
                                            "speaker-protected");
            platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED,
                                            ACDB_DEVICE_SPKR_PROT_WSA_ANALOG);
            platform_set_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED,
                                            ACDB_DEVICE_SPKR_PROT_WSA_ANALOG);
            platform_set_snd_device_acdb_id(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK,
                                            ACDB_DEVICE_VI_FEEDBACK_WSA_ANALOG);
            pcm_config_skr_prot.channels = 2;
        }
#endif
        pthread_cond_init(&handle.spkr_calib_cancel, NULL);
        pthread_cond_init(&handle.spkr_calibcancel_ack, NULL);
        pthread_mutex_init(&handle.mutex_spkr_prot, NULL);
@@ -1030,9 +1022,15 @@ int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device)

    switch(snd_device) {
    case SND_DEVICE_OUT_SPEAKER:
#ifdef PLATFORM_MSM8916
    case SND_DEVICE_OUT_SPEAKER_WSA:
#endif
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
        break;
    case SND_DEVICE_OUT_VOICE_SPEAKER:
#ifdef PLATFORM_MSM8916
    case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
#endif
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
        break;
    default:
@@ -1049,8 +1047,14 @@ int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device)

    switch(snd_device) {
    case SND_DEVICE_OUT_SPEAKER:
#ifdef PLATFORM_MSM8916
    case SND_DEVICE_OUT_SPEAKER_WSA:
#endif
        return SND_DEVICE_OUT_SPEAKER_PROTECTED;
    case SND_DEVICE_OUT_VOICE_SPEAKER:
#ifdef PLATFORM_MSM8916
    case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
#endif
        return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
    default:
        return snd_device;
+21 −0
Original line number Diff line number Diff line
@@ -605,6 +605,27 @@ exit_send_app_type_cfg:
    return rc;
}

int read_line_from_file(const char *path, char *buf, size_t count)
{
    char * fgets_ret;
    FILE * fd;
    int rv;

    fd = fopen(path, "r");
    if (fd == NULL)
        return -1;

    fgets_ret = fgets(buf, (int)count, fd);
    if (NULL != fgets_ret) {
        rv = (int)strlen(buf);
    } else {
        rv = ferror(fd);
    }
    fclose(fd);

   return rv;
}

void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
                                             struct audio_usecase *usecase)
{
+57 −18
Original line number Diff line number Diff line
@@ -1293,6 +1293,61 @@ int platform_acdb_init(void *platform)
    return result;
}

#define MAX_PATH             (256)
#define THERMAL_SYSFS "/sys/class/thermal"
#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"

bool is_wsa_found(void)
{
    DIR *tdir = NULL;
    struct dirent *tdirent = NULL;
    int tzn = 0;
    char name[MAX_PATH] = {0};
    char cwd[MAX_PATH] = {0};
    char file[10] = "wsa";
    bool found = false;

    if (!getcwd(cwd, sizeof(cwd)))
        return false;

    chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
                             otherwise */
    tdir = opendir(THERMAL_SYSFS);
    if (!tdir) {
        ALOGE("Unable to open %s\n", THERMAL_SYSFS);
        return false;
    }

    while ((tdirent = readdir(tdir))) {
        char buf[50];
        struct dirent *tzdirent;
        DIR *tzdir = NULL;

        tzdir = opendir(tdirent->d_name);
        if (!tzdir)
            continue;
        while ((tzdirent = readdir(tzdir))) {
            if (strcmp(tzdirent->d_name, "type"))
                continue;
            snprintf(name, MAX_PATH, TZ_TYPE, tzn);
            ALOGD("Opening %s\n", name);
            read_line_from_file(name, buf, sizeof(buf));
            if (strstr(buf, file)) {
                found = true;
                break;
            }
            tzn++;
        }
        closedir(tzdir);
        if (found == true)
            break;
    }
    closedir(tdir);
    chdir(cwd); /* Restore current working dir */
    return found;
}

void *platform_init(struct audio_device *adev)
{
    char platform[PROPERTY_VALUE_MAX];
@@ -1484,24 +1539,8 @@ void *platform_init(struct audio_device *adev)
    }
    audio_extn_pm_vote();

    // Check if WSA speaker is supported in codec
    char CodecPeek[1024] = "/sys/kernel/debug/asoc/";
    DIR *dir;
    struct dirent *dirent;
    char file_name[10] = "wsa";
    strlcat(CodecPeek, snd_card_name, sizeof(CodecPeek));

    dir = opendir(CodecPeek);
    if (dir != NULL) {
        while (NULL != (dirent = readdir(dir))) {
            if (strstr (dirent->d_name,file_name))
            {
    if (is_wsa_found())
        my_data->is_wsa_speaker = true;
                break;
            }
        }
        closedir(dir);
    }

    /* Configure active back end for HPX*/
    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);