~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/external/xscom-utils/putscom.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2014-2016 IBM Corp.
 
2
 *
 
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
 
6
 *
 
7
 *      http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
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
 
12
 * implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * imitations under the License.
 
15
 */
 
16
 
 
17
#include <stdio.h>
 
18
#include <stdlib.h>
 
19
#include <getopt.h>
 
20
#include <stdint.h>
 
21
#include <stdbool.h>
 
22
#include <inttypes.h>
 
23
 
 
24
#include "xscom.h"
 
25
 
 
26
static void print_usage(int code)
 
27
{
 
28
        printf("usage: putscom [-c|--chip chip-id] addr value\n");
 
29
        printf("       putscom -v|--version\n");
 
30
        exit(code);
 
31
}
 
32
 
 
33
extern const char version[];
 
34
 
 
35
int main(int argc, char *argv[])
 
36
{
 
37
        uint64_t val = -1ull, addr = -1ull;
 
38
        uint32_t def_chip, chip_id = 0xffffffff;
 
39
        bool got_addr = false, got_val = false;
 
40
        int rc;
 
41
 
 
42
        while(1) {
 
43
                static struct option long_opts[] = {
 
44
                        {"chip",        required_argument,      NULL,   'c'},
 
45
                        {"help",        no_argument,            NULL,   'h'},
 
46
                        {"version",     no_argument,            NULL,   'v'},
 
47
                };
 
48
                int c, oidx = 0;
 
49
 
 
50
                c = getopt_long(argc, argv, "-c:hv", long_opts, &oidx);
 
51
                if (c == EOF)
 
52
                        break;
 
53
                switch(c) {
 
54
                case 1:
 
55
                        if (!got_addr) {
 
56
                                addr = strtoull(optarg, NULL, 16);
 
57
                                got_addr = true;
 
58
                                break;
 
59
                        }
 
60
                        val = strtoull(optarg, NULL, 16);
 
61
                        got_val = true;
 
62
                        break;
 
63
                case 'c':
 
64
                        chip_id = strtoul(optarg, NULL, 0);
 
65
                        break;
 
66
                case 'v':
 
67
                        printf("xscom utils version %s\n", version);
 
68
                        exit(0);
 
69
                case 'h':
 
70
                        print_usage(0);
 
71
                        break;
 
72
                default:
 
73
                        exit(1);
 
74
                }
 
75
        }
 
76
        
 
77
        if (!got_addr || !got_val) {
 
78
                fprintf(stderr, "Invalid or missing address/value\n");
 
79
                print_usage(1);
 
80
        }
 
81
 
 
82
        def_chip = xscom_init();
 
83
        if (def_chip == 0xffffffff) {
 
84
                fprintf(stderr, "No valid XSCOM chip found\n");
 
85
                exit(1);
 
86
        }
 
87
        if (chip_id == 0xffffffff)
 
88
                chip_id = def_chip;
 
89
 
 
90
        rc = xscom_write(chip_id, addr, val);
 
91
        if (rc) {
 
92
                fprintf(stderr,"Error %d writing XSCOM\n", rc);
 
93
                exit(1);
 
94
        }
 
95
        rc = xscom_read(chip_id, addr, &val);
 
96
        if (rc) {
 
97
                fprintf(stderr,"Error %d reading XSCOM\n", rc);
 
98
                exit(1);
 
99
        }
 
100
        printf("%016" PRIx64 "\n", val);
 
101
        return 0;
 
102
}
 
103