1
/* Copyright 2014-2016 IBM Corp.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
* See the License for the specific language governing permissions and
14
* imitations under the License.
26
static void print_usage(int code)
28
printf("usage: putscom [-c|--chip chip-id] addr value\n");
29
printf(" putscom -v|--version\n");
33
extern const char version[];
35
int main(int argc, char *argv[])
37
uint64_t val = -1ull, addr = -1ull;
38
uint32_t def_chip, chip_id = 0xffffffff;
39
bool got_addr = false, got_val = false;
43
static struct option long_opts[] = {
44
{"chip", required_argument, NULL, 'c'},
45
{"help", no_argument, NULL, 'h'},
46
{"version", no_argument, NULL, 'v'},
50
c = getopt_long(argc, argv, "-c:hv", long_opts, &oidx);
56
addr = strtoull(optarg, NULL, 16);
60
val = strtoull(optarg, NULL, 16);
64
chip_id = strtoul(optarg, NULL, 0);
67
printf("xscom utils version %s\n", version);
77
if (!got_addr || !got_val) {
78
fprintf(stderr, "Invalid or missing address/value\n");
82
def_chip = xscom_init();
83
if (def_chip == 0xffffffff) {
84
fprintf(stderr, "No valid XSCOM chip found\n");
87
if (chip_id == 0xffffffff)
90
rc = xscom_write(chip_id, addr, val);
92
fprintf(stderr,"Error %d writing XSCOM\n", rc);
95
rc = xscom_read(chip_id, addr, &val);
97
fprintf(stderr,"Error %d reading XSCOM\n", rc);
100
printf("%016" PRIx64 "\n", val);