1*1de7b4b8SPedro F. Giffuni /*-
2*1de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
3*1de7b4b8SPedro F. Giffuni *
46dc3c6f7SGeoff Rehmet * Copyright (c) 1994 Geoffrey M. Rehmet
56dc3c6f7SGeoff Rehmet * All rights reserved.
66dc3c6f7SGeoff Rehmet *
76dc3c6f7SGeoff Rehmet * Redistribution and use in source and binary forms, with or without
86dc3c6f7SGeoff Rehmet * modification, are permitted provided that the following conditions
96dc3c6f7SGeoff Rehmet * are met:
106dc3c6f7SGeoff Rehmet * 1. Redistributions of source code must retain the above copyright
116dc3c6f7SGeoff Rehmet * notice, this list of conditions and the following disclaimer.
126dc3c6f7SGeoff Rehmet * 2. Redistributions in binary form must reproduce the above copyright
136dc3c6f7SGeoff Rehmet * notice, this list of conditions and the following disclaimer in the
146dc3c6f7SGeoff Rehmet * documentation and/or other materials provided with the distribution.
156dc3c6f7SGeoff Rehmet * 3. All advertising materials mentioning features or use of this software
166dc3c6f7SGeoff Rehmet * must display the following acknowledgement:
176dc3c6f7SGeoff Rehmet * This product includes software developed by Geoffrey M. Rehmet
186dc3c6f7SGeoff Rehmet * 4. The name of the author may not be used to endorse or promote products
1921dc7d4fSJens Schweikhardt * derived from this software without specific prior written permission
206dc3c6f7SGeoff Rehmet *
216dc3c6f7SGeoff Rehmet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
226dc3c6f7SGeoff Rehmet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
236dc3c6f7SGeoff Rehmet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
246dc3c6f7SGeoff Rehmet * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
256dc3c6f7SGeoff Rehmet * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
266dc3c6f7SGeoff Rehmet * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
276dc3c6f7SGeoff Rehmet * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
286dc3c6f7SGeoff Rehmet * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
296dc3c6f7SGeoff Rehmet * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
306dc3c6f7SGeoff Rehmet * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
316dc3c6f7SGeoff Rehmet */
326dc3c6f7SGeoff Rehmet
33b728350eSDavid E. O'Brien #include <sys/cdefs.h>
344ae6befaSJens Schweikhardt #include <dev/ppbus/lptio.h>
354ae6befaSJens Schweikhardt
36fe577fe9SPhilippe Charnier #include <err.h>
374ae6befaSJens Schweikhardt #include <fcntl.h>
3812365022SGeoff Rehmet #include <unistd.h>
3912365022SGeoff Rehmet
404ae6befaSJens Schweikhardt #include <stdio.h>
414ae6befaSJens Schweikhardt #include <stdlib.h>
426dc3c6f7SGeoff Rehmet
434ae6befaSJens Schweikhardt #define DEFAULT_DEVICE "/dev/lpt0.ctl"
444ae6befaSJens Schweikhardt #define IRQ_UNSPECIFIED -1
456dc3c6f7SGeoff Rehmet #define DO_POLL 0
466dc3c6f7SGeoff Rehmet #define USE_IRQ 1
47bc35c174SNicolas Souchu #define USE_EXT_MODE 2
48bc35c174SNicolas Souchu #define USE_STD_MODE 3
496dc3c6f7SGeoff Rehmet
usage(void)50167ce4fbSDima Dorfman static void usage(void)
516dc3c6f7SGeoff Rehmet {
524ae6befaSJens Schweikhardt fprintf(stderr,
534ae6befaSJens Schweikhardt "usage: lptcontrol -e | -i | -p | -s [[-d] controldevice]\n");
546dc3c6f7SGeoff Rehmet exit(1);
556dc3c6f7SGeoff Rehmet }
566dc3c6f7SGeoff Rehmet
main(int argc,char ** argv)574ae6befaSJens Schweikhardt int main (int argc, char **argv)
586dc3c6f7SGeoff Rehmet {
594ae6befaSJens Schweikhardt const char *device;
606dc3c6f7SGeoff Rehmet int fd;
614ae6befaSJens Schweikhardt int irq_status;
624ae6befaSJens Schweikhardt int opt;
636dc3c6f7SGeoff Rehmet
644ae6befaSJens Schweikhardt device = DEFAULT_DEVICE;
654ae6befaSJens Schweikhardt irq_status = IRQ_UNSPECIFIED;
664ae6befaSJens Schweikhardt while ((opt = getopt(argc, argv, "d:eips")) != -1)
674ae6befaSJens Schweikhardt switch (opt) {
684ae6befaSJens Schweikhardt case 'd':
694ae6befaSJens Schweikhardt device = optarg;
704ae6befaSJens Schweikhardt break;
714ae6befaSJens Schweikhardt case 'e':
724ae6befaSJens Schweikhardt irq_status = USE_EXT_MODE;
734ae6befaSJens Schweikhardt break;
744ae6befaSJens Schweikhardt case 'i':
754ae6befaSJens Schweikhardt irq_status = USE_IRQ;
764ae6befaSJens Schweikhardt break;
774ae6befaSJens Schweikhardt case 'p':
784ae6befaSJens Schweikhardt irq_status = DO_POLL;
794ae6befaSJens Schweikhardt break;
804ae6befaSJens Schweikhardt case 's':
814ae6befaSJens Schweikhardt irq_status = USE_STD_MODE;
824ae6befaSJens Schweikhardt break;
834ae6befaSJens Schweikhardt case '?':
844ae6befaSJens Schweikhardt default:
854ae6befaSJens Schweikhardt usage();
864ae6befaSJens Schweikhardt /* NOTREACHED */
874ae6befaSJens Schweikhardt }
884ae6befaSJens Schweikhardt argc -= optind;
894ae6befaSJens Schweikhardt argv += optind;
904ae6befaSJens Schweikhardt /* POLA: DTRT if -d was forgotten, but device name was specified. */
914ae6befaSJens Schweikhardt if (argc == 1) {
924ae6befaSJens Schweikhardt device = argv[0];
934ae6befaSJens Schweikhardt --argc;
944ae6befaSJens Schweikhardt }
954ae6befaSJens Schweikhardt
964ae6befaSJens Schweikhardt if (irq_status == IRQ_UNSPECIFIED || argc != 0)
974ae6befaSJens Schweikhardt usage();
984ae6befaSJens Schweikhardt
99e65b4394SSuleiman Souhlal if ((fd = open(device, O_WRONLY)) < 0)
100fe577fe9SPhilippe Charnier err(1, "open");
101fe577fe9SPhilippe Charnier if (ioctl(fd, LPT_IRQ, &irq_status) < 0)
102fe577fe9SPhilippe Charnier err(1, "ioctl");
1036dc3c6f7SGeoff Rehmet close(fd);
1046dc3c6f7SGeoff Rehmet
1054ae6befaSJens Schweikhardt return(0);
1066dc3c6f7SGeoff Rehmet }
107