2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/digiio.h>
38 #include <sys/ioctl.h>
41 enum aflag { NO_AFLAG, ALTPIN_DISABLE, ALTPIN_ENABLE, ALTPIN_QUERY };
44 usage(const char *prog)
46 fprintf(stderr, "usage: %s -a disable|enable|query device\n", prog);
47 fprintf(stderr, " %s [-d debug] [-ir] ctrl-device...\n", prog);
52 main(int argc, char **argv)
54 char namedata[256], *name = namedata;
56 enum digi_model model;
57 int altpin, ch, debug, fd, i, res;
58 int dflag, iflag, rflag;
61 if ((prog = strrchr(argv[0], '/')) == NULL)
67 dflag = iflag = rflag = 0;
68 while ((ch = getopt(argc, argv, "a:d:ir")) != -1)
71 if (strcasecmp(optarg, "disable") == 0)
72 aflag = ALTPIN_DISABLE;
73 else if (strcasecmp(optarg, "enable") == 0)
74 aflag = ALTPIN_ENABLE;
75 else if (strcasecmp(optarg, "query") == 0)
98 if ((dflag || iflag || rflag) && aflag != NO_AFLAG)
102 return (usage(prog));
104 altpin = (aflag == ALTPIN_ENABLE);
107 for (i = optind; i < argc; i++) {
108 if ((fd = open(argv[i], O_RDONLY)) == -1) {
109 fprintf(stderr, "%s: %s: open: %s\n", prog, argv[i],
121 if (ioctl(fd, DIGIIO_SETALTPIN, &altpin) != 0) {
122 fprintf(stderr, "%s: %s: set altpin: %s\n",
123 prog, argv[i], strerror(errno));
129 if (ioctl(fd, DIGIIO_GETALTPIN, &altpin) != 0) {
130 fprintf(stderr, "%s: %s: get altpin: %s\n",
131 prog, argv[i], strerror(errno));
134 if (argc > optind + 1)
135 printf("%s: ", argv[i]);
136 puts(altpin ? "enabled" : "disabled");
141 if (dflag && ioctl(fd, DIGIIO_DEBUG, &debug) != 0) {
142 fprintf(stderr, "%s: %s: debug: %s\n",
143 prog, argv[i], strerror(errno));
148 if (ioctl(fd, DIGIIO_MODEL, &model) != 0) {
149 fprintf(stderr, "%s: %s: model: %s\n",
150 prog, argv[i], strerror(errno));
152 } else if (ioctl(fd, DIGIIO_IDENT, &name) != 0) {
153 fprintf(stderr, "%s: %s: ident: %s\n",
154 prog, argv[i], strerror(errno));
157 if (argc > optind + 1)
158 printf("%s: ", argv[i]);
159 printf("%s (type %d)\n", name, (int)model);
163 if (rflag && ioctl(fd, DIGIIO_REINIT) != 0) {
164 fprintf(stderr, "%s: %s: reinit: %s\n",
165 prog, argv[i], strerror(errno));