diff options
author | Paul Kocialkowski | 2017-02-16 15:53:29 +0100 |
---|---|---|
committer | Paul Kocialkowski | 2017-02-22 19:10:44 +0100 |
commit | c677de25a612e7ef24cbbb9f82e2542944632d71 (patch) | |
tree | 4bc1193c9b5f9a4bb51e7b2bb41f738cf7256a33 /mt8173-pcm.c |
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'mt8173-pcm.c')
-rw-r--r-- | mt8173-pcm.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/mt8173-pcm.c b/mt8173-pcm.c new file mode 100644 index 0000000..fef7ea1 --- /dev/null +++ b/mt8173-pcm.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2016-2017 Paul Kocialkowski <contact@paulk.fr> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include "spm.h" + +#include "pcm_mcdi_mt8173_20160401_v1.h" +#include "pcm_power_down_mt8173_V37.h" +#include "pcm_suspend_20150805_V1.h" +#include "pcm_suspend_20150917_V4.h" + +static const struct pcm_desc *pcm_descs[] = { + &pcm_mcdi_mt8173_20160401_v1, + &pcm_power_down_mt8173_V37, + &pcm_suspend_20150805_V1, + &pcm_suspend_20150917_V4, + NULL +}; + +static const struct pcm_desc *pcm_desc_find(const char *version) +{ + int i; + + for (i = 0; pcm_descs[i] != NULL; i++) { + if (strcmp(pcm_descs[i]->version, version) == 0) + return pcm_descs[i]; + } + + return NULL; +} + +static void pcm_desc_list(void) +{ + int i; + + printf("Available PCM descriptions:\n"); + + for (i = 0; pcm_descs[i] != NULL; i++) + printf("%s\n", pcm_descs[i]->version); +} + +int main(int argc, char *argv[]) +{ + const struct pcm_desc *desc; + char *version = NULL; + char *name; + int fd; + int i; + + if (argc > 1 && argv[1] != NULL) + version = argv[1]; + + if (version == NULL) { + pcm_desc_list(); + return 1; + } + + desc = pcm_desc_find(version); + if (desc == NULL) { + printf("Couldn't find PCM description with version %s\n", version); + return 1; + } + + asprintf(&name, "%s.bin", desc->version); + + fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0644); + if (fd < 0) + return 1; + + free(name); + + write(fd, desc->base, desc->size * sizeof(unsigned int)); + + close(fd); + + asprintf(&name, "%s.txt", desc->version); + + fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0644); + if (fd < 0) + return 1; + + free(name); + + for (i = 0 ; i < desc->size ; i++) + dprintf(fd, "[0x%04x] 0x%08x\n", i, desc->base[i]); + + close(fd); + + printf("Produced %s\n", desc->version); + + return 0; +} |