2 * Copyright (C) 2011-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
28 #include "utils/log.h"
29 #include "utils/StringUtils.h"
31 int aml_set_sysfs_str(const char *path, const char *val)
33 int fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
36 write(fd, val, strlen(val));
43 int aml_get_sysfs_str(const char *path, char *valstr, const int size)
45 int fd = open(path, O_RDONLY);
48 read(fd, valstr, size - 1);
49 valstr[strlen(valstr)] = '\0';
54 sprintf(valstr, "%s", "fail");
58 int aml_set_sysfs_int(const char *path, const int val)
60 int fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
64 sprintf(bcmd, "%d", val);
65 write(fd, bcmd, strlen(bcmd));
72 int aml_get_sysfs_int(const char *path)
75 int fd = open(path, O_RDONLY);
79 read(fd, bcmd, sizeof(bcmd));
80 val = strtol(bcmd, NULL, 16);
88 static int has_aml = -1;
91 int rtn = aml_get_sysfs_int("/sys/class/audiodsp/digital_raw");
97 CLog::Log(LOGNOTICE, "aml_present, rtn(%d)", rtn);
102 int aml_get_cputype()
104 static int aml_cputype = -1;
105 if (aml_cputype == -1)
110 FILE *cpuinfo_fd = fopen("/proc/cpuinfo", "r");
114 while (fgets(buffer, sizeof(buffer), cpuinfo_fd))
116 std::string stdbuffer(buffer);
117 if (stdbuffer.find("MESON-M3") != std::string::npos)
122 else if (stdbuffer.find("MESON3") != std::string::npos)
127 else if (stdbuffer.find("Meson6") != std::string::npos)
140 void aml_cpufreq_limit(bool limit)
142 int cpufreq = 300000;
146 aml_set_sysfs_int("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", cpufreq);
149 void aml_set_audio_passthrough(bool passthrough)
153 int raw = aml_get_cputype() < 3 ? 1:2;
154 aml_set_sysfs_int("/sys/class/audiodsp/digital_raw", passthrough ? raw:0);
158 void aml_probe_hdmi_audio()
160 std::vector<CStdString> audio_formats;
161 // Audio {format, channel, freq, cce}
169 int fd = open("/sys/class/amhdmitx/amhdmitx0/edid", O_RDONLY);
172 char valstr[1024] = {0};
174 read(fd, valstr, sizeof(valstr) - 1);
175 valstr[strlen(valstr)] = '\0';
178 std::vector<CStdString> probe_str;
179 StringUtils::SplitString(valstr, "\n", probe_str);
181 for (size_t i = 0; i < probe_str.size(); i++)
183 if (probe_str[i].find("Audio") == std::string::npos)
185 for (size_t j = i+1; j < probe_str.size(); j++)
187 if (probe_str[i].find("{1,") != std::string::npos)
188 printf(" PCM found {1,\n");
189 else if (probe_str[i].find("{2,") != std::string::npos)
190 printf(" AC3 found {2,\n");
191 else if (probe_str[i].find("{3,") != std::string::npos)
192 printf(" MPEG1 found {3,\n");
193 else if (probe_str[i].find("{4,") != std::string::npos)
194 printf(" MP3 found {4,\n");
195 else if (probe_str[i].find("{5,") != std::string::npos)
196 printf(" MPEG2 found {5,\n");
197 else if (probe_str[i].find("{6,") != std::string::npos)
198 printf(" AAC found {6,\n");
199 else if (probe_str[i].find("{7,") != std::string::npos)
200 printf(" DTS found {7,\n");
201 else if (probe_str[i].find("{8,") != std::string::npos)
202 printf(" ATRAC found {8,\n");
203 else if (probe_str[i].find("{9,") != std::string::npos)
204 printf(" One_Bit_Audio found {9,\n");
205 else if (probe_str[i].find("{10,") != std::string::npos)
206 printf(" Dolby found {10,\n");
207 else if (probe_str[i].find("{11,") != std::string::npos)
208 printf(" DTS_HD found {11,\n");
209 else if (probe_str[i].find("{12,") != std::string::npos)
210 printf(" MAT found {12,\n");
211 else if (probe_str[i].find("{13,") != std::string::npos)
212 printf(" ATRAC found {13,\n");
213 else if (probe_str[i].find("{14,") != std::string::npos)
214 printf(" WMA found {14,\n");