util/pmh7tool: Add option to read specific bit
Change-Id: I045383eedbcf438270e9c64329a8d910bb941ab8 Signed-off-by: Evgeny Zinoviev <me@ch1p.com> Reviewed-on: https://review.coreboot.org/28388 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
This commit is contained in:
parent
ce7bc17149
commit
672f56166d
|
@ -53,16 +53,25 @@ void pmh7_register_clear_bit(uint16_t reg, uint8_t bit)
|
||||||
pmh7_register_write(reg, val & ~(1 << bit));
|
pmh7_register_write(reg, val & ~(1 << bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t pmh7_register_read_bit(int16_t reg, uint8_t bit)
|
||||||
|
{
|
||||||
|
uint8_t val;
|
||||||
|
|
||||||
|
val = pmh7_register_read(reg);
|
||||||
|
return (val >> bit) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
void print_usage(const char *name)
|
void print_usage(const char *name)
|
||||||
{
|
{
|
||||||
printf("usage: %s\n", name);
|
printf("usage: %s\n", name);
|
||||||
printf("\n"
|
printf("\n"
|
||||||
" -h, --help: print this help\n"
|
" -h, --help: print this help\n"
|
||||||
" -d, --dump: print registers\n"
|
" -d, --dump: print registers\n"
|
||||||
" -w, --write <addr> <data>: write to register\n"
|
" -w, --write <addr> <data>: write to register\n"
|
||||||
" -r, --read <addr>: read from register\n"
|
" -r, --read <addr>: read from register\n"
|
||||||
" -c, --clear-bit <addr> <bit>\n"
|
" -b, --read-bit <addr> <bit> read bit\n"
|
||||||
" -s, --set-bit <addr> <bit>\n"
|
" -c, --clear-bit <addr> <bit> clear bit\n"
|
||||||
|
" -s, --set-bit <addr> <bit> set bit\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Attention! Writing to PMH7 registers is very dangerous, as you\n"
|
"Attention! Writing to PMH7 registers is very dangerous, as you\n"
|
||||||
" directly manipulate the power rails, enable lines,\n"
|
" directly manipulate the power rails, enable lines,\n"
|
||||||
|
@ -71,7 +80,7 @@ void print_usage(const char *name)
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum action {HELP, DUMP, WRITE, READ, CLEAR, SET};
|
enum action {HELP, DUMP, WRITE, READ, READBIT, CLEAR, SET};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -84,6 +93,7 @@ int main(int argc, char *argv[])
|
||||||
{"dump", 0, 0, 'd'},
|
{"dump", 0, 0, 'd'},
|
||||||
{"write", 1, 0, 'w'},
|
{"write", 1, 0, 'w'},
|
||||||
{"read", 1, 0, 'r'},
|
{"read", 1, 0, 'r'},
|
||||||
|
{"read-bit", 1, 0, 'b'},
|
||||||
{"clear-bit", 1, 0, 'c'},
|
{"clear-bit", 1, 0, 'c'},
|
||||||
{"set-bit", 1, 0, 's'},
|
{"set-bit", 1, 0, 's'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
|
@ -94,7 +104,7 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "hdw:r:c:s:",
|
while ((opt = getopt_long(argc, argv, "hdw:r:c:s:b:",
|
||||||
long_options, &option_index)) != EOF) {
|
long_options, &option_index)) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
|
@ -107,6 +117,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
|
case 'b':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 's':
|
case 's':
|
||||||
input_addr = strtoul(optarg, NULL, 16);
|
input_addr = strtoul(optarg, NULL, 16);
|
||||||
|
@ -125,6 +136,9 @@ int main(int argc, char *argv[])
|
||||||
case 'w':
|
case 'w':
|
||||||
act = WRITE;
|
act = WRITE;
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
act = READBIT;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
act = CLEAR;
|
act = CLEAR;
|
||||||
break;
|
break;
|
||||||
|
@ -153,7 +167,7 @@ int main(int argc, char *argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (act == SET || act == CLEAR) {
|
if (act == SET || act == CLEAR || act == READBIT) {
|
||||||
if (input_data > 7) {
|
if (input_data > 7) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: <bit> cannot be greater than 7.\n");
|
"Error: <bit> cannot be greater than 7.\n");
|
||||||
|
@ -198,6 +212,10 @@ int main(int argc, char *argv[])
|
||||||
pmh7_register_write(input_addr, input_data);
|
pmh7_register_write(input_addr, input_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case READBIT:
|
||||||
|
printf("%d\n", pmh7_register_read_bit(input_addr, input_data));
|
||||||
|
break;
|
||||||
|
|
||||||
case CLEAR:
|
case CLEAR:
|
||||||
pmh7_register_clear_bit(input_addr, input_data);
|
pmh7_register_clear_bit(input_addr, input_data);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue