summaryrefslogtreecommitdiff
path: root/mt8173-pcm.c
blob: fef7ea1ad2051a1006b52bb52f9326309149fb18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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;
}