blob: 798521b036926024f23d1c57162628f452e574f9
1 | /* |
2 | * Copyright (c) 2014 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This source code is subject to the terms and conditions defined in the |
5 | * file 'LICENSE' which is part of this source code package. |
6 | * |
7 | * Description: |
8 | */ |
9 | |
10 | |
11 | #define LOG_TAG "AmAvutls" |
12 | |
13 | #include <stdlib.h> |
14 | #include <fcntl.h> |
15 | #include <errno.h> |
16 | #include <strings.h> |
17 | #include <cutils/log.h> |
18 | #include <sys/ioctl.h> |
19 | |
20 | #include <Amsysfsutils.h> |
21 | #include "include/amaudioutils.h" |
22 | |
23 | typedef enum { |
24 | AUDIO_DSP_FREQ_NONE = 0, |
25 | AUDIO_DSP_FREQ_NORMAL, |
26 | AUDIO_DSP_FREQ_HIGH, |
27 | AUDIO_DSP_FREQ_MAX |
28 | } audiodsp_freqlevel_t; |
29 | |
30 | #define AUDIODSP_CODEC_MIPS_IN "/sys/class/audiodsp/codec_mips" |
31 | #define AUDIODSP_CODEC_MIPS_OUT "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" |
32 | #define AUDIODSP_CLK81_FRQ_LEVEL "/sys/class/aml_clk81/clk81_freq_level" |
33 | |
34 | #ifndef LOGD |
35 | #define LOGV ALOGV |
36 | #define LOGD ALOGD |
37 | #define LOGI ALOGI |
38 | #define LOGW ALOGW |
39 | #define LOGE ALOGE |
40 | #endif |
41 | |
42 | #define LOG_FUNCTION_NAME LOGI("%s-%d\n",__FUNCTION__,__LINE__); |
43 | ///#define LOG_FUNCTION_NAME |
44 | |
45 | static int set_audiodsp_frelevel(int m1_flag, int coeff) |
46 | { |
47 | int val; |
48 | if (m1_flag) { |
49 | val = amsysfs_get_sysfs_int16(AUDIODSP_CODEC_MIPS_IN); |
50 | if (val > 0 && coeff > 0) { |
51 | val = coeff * val; |
52 | amsysfs_set_sysfs_int(AUDIODSP_CODEC_MIPS_OUT, val); |
53 | LOGI("m1:set_cpu_freq_scaling_based_auido %d\n", val); |
54 | } else { |
55 | LOGI("m1:set_cpu_freq_scaling_based_auido failed\n"); |
56 | return -1; |
57 | } |
58 | } else { |
59 | amsysfs_set_sysfs_int(AUDIODSP_CLK81_FRQ_LEVEL, coeff); |
60 | } |
61 | return 0; |
62 | } |
63 | |
64 | int amaudio_utils_set_dsp_freqlevel(audiodsp_freqlevel_t level, int val) |
65 | { |
66 | int m1_cpu_flag = 0; |
67 | |
68 | LOG_FUNCTION_NAME |
69 | |
70 | switch (level) { |
71 | case AUDIO_DSP_FREQ_NONE: |
72 | break; |
73 | |
74 | case AUDIO_DSP_FREQ_NORMAL: |
75 | if (open(AUDIODSP_CODEC_MIPS_IN, O_RDWR) >= 0) { |
76 | m1_cpu_flag = 1; |
77 | } |
78 | set_audiodsp_frelevel(m1_cpu_flag, val); |
79 | break; |
80 | |
81 | case AUDIO_DSP_FREQ_HIGH: |
82 | case AUDIO_DSP_FREQ_MAX: |
83 | break; |
84 | |
85 | default: |
86 | LOGI("level not in range! level=%d\n", level); |
87 | } |
88 | |
89 | return 0; |
90 | |
91 | } |
92 |