12470Scsgr/*
22470Scsgr * Copyright (c) 1994 Geoffrey M. Rehmet
32470Scsgr * All rights reserved.
42470Scsgr *
52470Scsgr * Redistribution and use in source and binary forms, with or without
62470Scsgr * modification, are permitted provided that the following conditions
72470Scsgr * are met:
82470Scsgr * 1. Redistributions of source code must retain the above copyright
92470Scsgr *    notice, this list of conditions and the following disclaimer.
102470Scsgr * 2. Redistributions in binary form must reproduce the above copyright
112470Scsgr *    notice, this list of conditions and the following disclaimer in the
122470Scsgr *    documentation and/or other materials provided with the distribution.
132470Scsgr * 3. All advertising materials mentioning features or use of this software
142470Scsgr *    must display the following acknowledgement:
152470Scsgr *      This product includes software developed by Geoffrey M. Rehmet
162470Scsgr * 4. The name of the author may not be used to endorse or promote products
1797748Sschweikh *    derived from this software without specific prior written permission
182470Scsgr *
192470Scsgr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
202470Scsgr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
212470Scsgr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
222470Scsgr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
232470Scsgr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
242470Scsgr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
252470Scsgr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
262470Scsgr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
272470Scsgr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
282470Scsgr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292470Scsgr */
302470Scsgr
31114601Sobrien#include <sys/cdefs.h>
32114601Sobrien__FBSDID("$FreeBSD$");
3329846Scharnier
34136037Sschweikh#include <dev/ppbus/lptio.h>
35136037Sschweikh
3629846Scharnier#include <err.h>
37136037Sschweikh#include <fcntl.h>
38136037Sschweikh#include <unistd.h>
39136037Sschweikh
402484Scsgr#include <stdio.h>
412470Scsgr#include <stdlib.h>
422484Scsgr
43136037Sschweikh#define DEFAULT_DEVICE	"/dev/lpt0.ctl"
44136037Sschweikh#define IRQ_UNSPECIFIED	-1
452470Scsgr#define DO_POLL		0
462470Scsgr#define USE_IRQ		1
4742475Snsouch#define USE_EXT_MODE	2
4842475Snsouch#define USE_STD_MODE	3
492470Scsgr
5078714Sddstatic void usage(void)
512470Scsgr{
52136037Sschweikh	fprintf(stderr,
53136037Sschweikh		"usage: lptcontrol -e | -i | -p | -s [[-d] controldevice]\n");
542470Scsgr	exit(1);
552470Scsgr}
562470Scsgr
57136037Sschweikhint main (int argc, char **argv)
582470Scsgr{
59136037Sschweikh	const char *device;
60136037Sschweikh	int fd;
61136037Sschweikh	int irq_status;
62136037Sschweikh	int opt;
632470Scsgr
64136037Sschweikh	device = DEFAULT_DEVICE;
65136037Sschweikh	irq_status = IRQ_UNSPECIFIED;
66136037Sschweikh	while ((opt = getopt(argc, argv, "d:eips")) != -1)
67136037Sschweikh		switch (opt) {
68136037Sschweikh		case 'd':
69136037Sschweikh			device = optarg;
70136037Sschweikh			break;
71136037Sschweikh		case 'e':
72136037Sschweikh			irq_status = USE_EXT_MODE;
73136037Sschweikh			break;
74136037Sschweikh		case 'i':
75136037Sschweikh			irq_status = USE_IRQ;
76136037Sschweikh			break;
77136037Sschweikh		case 'p':
78136037Sschweikh			irq_status = DO_POLL;
79136037Sschweikh			break;
80136037Sschweikh		case 's':
81136037Sschweikh			irq_status = USE_STD_MODE;
82136037Sschweikh			break;
83136037Sschweikh		case '?':
84136037Sschweikh		default:
85136037Sschweikh			usage();
86136037Sschweikh			/* NOTREACHED */
87136037Sschweikh		}
88136037Sschweikh	argc -= optind;
89136037Sschweikh	argv += optind;
90136037Sschweikh	/* POLA: DTRT if -d was forgotten, but device name was specified. */
91136037Sschweikh	if (argc == 1) {
92136037Sschweikh		device = argv[0];
93136037Sschweikh		--argc;
94136037Sschweikh	}
95136037Sschweikh
96136037Sschweikh	if (irq_status == IRQ_UNSPECIFIED || argc != 0)
97136037Sschweikh		usage();
98136037Sschweikh
99140814Sssouhlal	if ((fd = open(device, O_WRONLY)) < 0)
10029846Scharnier		err(1, "open");
101136037Sschweikh	if (ioctl(fd, LPT_IRQ, &irq_status) < 0)
10229846Scharnier		err(1, "ioctl");
1032470Scsgr	close(fd);
1042470Scsgr
105136037Sschweikh	return(0);
1062470Scsgr}
107