-
Notifications
You must be signed in to change notification settings - Fork 2
/
hda-decode-verb.c
126 lines (111 loc) · 2.93 KB
/
hda-decode-verb.c
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
116
117
118
119
120
121
122
123
124
125
126
/*
* hda-emu - simple HD-audio codec emulator for debugging snd-hda-intel driver
*
* Decode HD-audio verb/parameter values
*
* Copyright (c) Takashi Iwai <[email protected]>
*
* This driver 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 2 of the License, or
* (at your option) any later version.
*
* This driver 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include "hda-types.h"
#include "hda-log.h"
enum { DECODE, ENCODE };
static void usage(int mode)
{
if (mode == DECODE) {
fprintf(stderr,
"usage: \n"
" hda-decode-verb VALUE\n"
" Decode the encoded command value\n"
" hda-decode-verb VERB PARAMETER\n"
" Decode the verb and parameter values\n"
);
} else {
fprintf(stderr,
"usage: \n"
" hda-encode-verb VERB PARAMETER\n"
" Encode the verb and parameter values\n"
);
}
exit(1);
}
unsigned int hda_decode_verb(struct xhda_codec *codec, unsigned int val)
{
unsigned int cid, /*dir,*/ nid, verb, parm;
hda_log(HDA_LOG_INFO, "raw value = 0x%08x\n", val);
cid = (val >> 28) & 0xf;
/* dir = (val >> 27) & 1; */
nid = (val >> 20) & 0x7f;
verb = (val >> 8) & 0xfff;
parm = val & 0xff;
hda_log(HDA_LOG_INFO,
"cid = %d, nid = 0x%02x, verb = 0x%x, parm = 0x%02x\n",
cid, nid, verb, parm);
return hda_decode_verb_parm(codec, verb, parm);
}
static void encode(const char *vstr, const char *pstr)
{
unsigned int verb, parm;
if (hda_encode_verb_parm(vstr, pstr, &verb, &parm) < 0) {
hda_log(HDA_LOG_ERR, "Invalid parameters\n");
exit(1);
}
hda_log(HDA_LOG_INFO, "verb = 0x%x, parm = 0x%x\n", verb, parm);
}
int main(int argc, char **argv)
{
int mode = DECODE;
int c;
hda_log_init(NULL, 0);
hda_log_level_set(HDA_LOG_INFO);
if (strstr(argv[0], "hda-encode-verb"))
mode = ENCODE;
while ((c = getopt(argc, argv, "de")) != -1) {
switch (c) {
case 'd':
mode = DECODE;
break;
case 'e':
mode = ENCODE;
break;
default:
usage(mode);
}
}
switch (mode) {
case DECODE:
if (optind >= argc)
usage(mode);
if (optind + 1 == argc) {
hda_decode_verb(NULL, strtoul(argv[optind], NULL, 0));
} else {
hda_decode_verb_parm(NULL,
strtoul(argv[optind], NULL, 0),
strtoul(argv[optind + 1], NULL, 0));
}
break;
case ENCODE:
if (optind + 2 > argc)
usage(mode);
encode(argv[optind], argv[optind + 1]);
break;
}
return 0;
}