xref: /netbsd-src/sys/dev/hpc/hpctpanel.c (revision 53524e44efd7c7176da8dc8190a698b2fe184db1)
1*53524e44Schristos /*	$NetBSD: hpctpanel.c,v 1.5 2007/03/04 06:01:47 christos Exp $	*/
2f53a32e6Stsarna 
3f53a32e6Stsarna /*
4f53a32e6Stsarna  * Copyright (c) 1999-2003 TAKEMURA Shin All rights reserved.
5f53a32e6Stsarna  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
6f53a32e6Stsarna  *
7f53a32e6Stsarna  * Redistribution and use in source and binary forms, with or without
8f53a32e6Stsarna  * modification, are permitted provided that the following conditions
9f53a32e6Stsarna  * are met:
10f53a32e6Stsarna  * 1. Redistributions of source code must retain the above copyright
11f53a32e6Stsarna  *    notice, this list of conditions and the following disclaimer.
12f53a32e6Stsarna  * 2. Redistributions in binary form must reproduce the above copyright
13f53a32e6Stsarna  *    notice, this list of conditions and the following disclaimer in the
14f53a32e6Stsarna  *    documentation and/or other materials provided with the distribution.
15f53a32e6Stsarna  *
16f53a32e6Stsarna  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17f53a32e6Stsarna  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f53a32e6Stsarna  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f53a32e6Stsarna  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20f53a32e6Stsarna  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f53a32e6Stsarna  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f53a32e6Stsarna  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f53a32e6Stsarna  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f53a32e6Stsarna  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f53a32e6Stsarna  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f53a32e6Stsarna  * SUCH DAMAGE.
27f53a32e6Stsarna  *
28f53a32e6Stsarna  */
29f53a32e6Stsarna 
30f53a32e6Stsarna #include <sys/cdefs.h>
31*53524e44Schristos __KERNEL_RCSID(0, "$NetBSD: hpctpanel.c,v 1.5 2007/03/04 06:01:47 christos Exp $");
32f53a32e6Stsarna 
33f53a32e6Stsarna #include <sys/param.h>
34f53a32e6Stsarna #include <sys/systm.h>
35f53a32e6Stsarna #include <sys/device.h>
36f53a32e6Stsarna #include <sys/kernel.h>
37f53a32e6Stsarna #include <dev/wscons/wsconsio.h>
38f53a32e6Stsarna #include <dev/hpc/hpctpanelvar.h>
39f53a32e6Stsarna 
40f53a32e6Stsarna #include <machine/platid.h>
41f53a32e6Stsarna #include <machine/platid_mask.h>
42f53a32e6Stsarna 
43f53a32e6Stsarna int
hpc_tpanel_ioctl(struct tpcalib_softc * sc,u_long cmd,void * data,int flag,struct lwp * l)44*53524e44Schristos hpc_tpanel_ioctl(struct tpcalib_softc *sc, u_long cmd, void *data, int flag,
4595e1ffb1Schristos     struct lwp *l)
46f53a32e6Stsarna {
47f53a32e6Stsarna 	struct wsmouse_id *id;
481f2b389bSuwe 	const char *idstr;
49f53a32e6Stsarna 	int s;
50f53a32e6Stsarna 
51f53a32e6Stsarna 	switch (cmd) {
52f53a32e6Stsarna         case WSMOUSEIO_GTYPE:
53f53a32e6Stsarna 		*(u_int *)data = WSMOUSE_TYPE_TPANEL;
54f53a32e6Stsarna 		return (0);
55f53a32e6Stsarna 
56f53a32e6Stsarna 	case WSMOUSEIO_GETID:
57f53a32e6Stsarna 		/*
58f53a32e6Stsarna 		 * return unique ID string,
59f53a32e6Stsarna 		 * "<vendor> <model> <serial number>"
60f53a32e6Stsarna 		 */
61f53a32e6Stsarna 		id = (struct wsmouse_id *)data;
62f53a32e6Stsarna 		if (id->type != WSMOUSE_ID_TYPE_UIDSTR)
63f53a32e6Stsarna 			return (EINVAL);
64f53a32e6Stsarna 		idstr = platid_name(&platid);
65f53a32e6Stsarna 		s = strlen(idstr);
66f53a32e6Stsarna 		if (WSMOUSE_ID_MAXLEN - 10 < s)
67f53a32e6Stsarna 			s = WSMOUSE_ID_MAXLEN - 10;
68f53a32e6Stsarna 		memcpy(id->data, idstr, s);
69f53a32e6Stsarna 		strcpy(&id->data[s], " SN000000");
70f53a32e6Stsarna 		id->length = s + 9;
71f53a32e6Stsarna 		break;
72f53a32e6Stsarna 
73f53a32e6Stsarna         case WSMOUSEIO_SCALIBCOORDS:
74f53a32e6Stsarna         case WSMOUSEIO_GCALIBCOORDS:
7595e1ffb1Schristos                 return tpcalib_ioctl(sc, cmd, data, flag, l);
76f53a32e6Stsarna 
77f53a32e6Stsarna 	default:
78f53a32e6Stsarna 		return EPASSTHROUGH;
79f53a32e6Stsarna 	}
80f53a32e6Stsarna 
81f53a32e6Stsarna 	return 0;
82f53a32e6Stsarna }
83