Home | History | Annotate | Line # | Download | only in adb
      1 /*	$NetBSD: adbvar.h,v 1.6 2025/06/16 08:00:50 macallan Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2006 Michael Lorenz
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: adbvar.h,v 1.6 2025/06/16 08:00:50 macallan Exp $");
     31 
     32 #ifndef ADBVAR_H
     33 #define ADBVAR_H
     34 
     35 #define ADB_CMDADDR(cmd)	((u_int8_t)((cmd) & 0xf0) >> 4)
     36 #define ADBFLUSH(dev)		((((u_int8_t)(dev) & 0x0f) << 4) | 0x01)
     37 #define ADBLISTEN(dev, reg)	((((u_int8_t)(dev) & 0x0f) << 4) | 0x08 | (reg))
     38 #define ADBTALK(dev, reg)	((((u_int8_t)(dev) & 0x0f) << 4) | 0x0c | (reg))
     39 
     40 	/* Interesting default addresses */
     41 #define	ADBADDR_SECURE	1		/* Security dongles */
     42 #define ADBADDR_MAP	2		/* Mapped devices (keyboards/pads) */
     43 #define ADBADDR_REL	3		/* Relative positioning devices
     44 					   (mice, trackballs/pads) */
     45 #define ADBADDR_ABS	4		/* Absolute positioning devices
     46 					   (graphics tablets) */
     47 #define ADBADDR_DATATX	5
     48 #define ADBADDR_RSRVD	6		/* Reserved by Apple */
     49 #define ADBADDR_MISC	7		/* Miscellaneous appliances */
     50 #define ADBADDR_DONGLE	ADBADDR_SECURE
     51 #define ADBADDR_KBD	ADBADDR_MAP
     52 #define ADBADDR_MS	ADBADDR_REL
     53 #define ADBADDR_TABLET	ADBADDR_ABS
     54 #define ADBADDR_MODEM	ADBADDR_DATATX
     55 
     56 #define ADBADDR_APM	0xac0ff		/* A faux-addr for the APM driver to
     57 					   latch onto */
     58 
     59 	/* Interesting keyboard handler IDs */
     60 #define ADB_STDKBD	1
     61 #define ADB_EXTKBD	2
     62 #define ADB_ISOKBD	4
     63 #define ADB_EXTISOKBD	5
     64 #define ADB_KBDII	8
     65 #define ADB_ISOKBDII	9
     66 #define ADB_PBKBD	12
     67 #define ADB_PBISOKBD	13
     68 #define ADB_ADJKPD	14
     69 #define ADB_ADJKBD	16
     70 #define ADB_ADJISOKBD	17
     71 #define ADB_ADJJAPKBD	18
     72 #define ADB_PBEXTISOKBD	20
     73 #define ADB_PBEXTJAPKBD	21
     74 #define ADB_JPKBDII	22
     75 #define ADB_PBEXTKBD	24
     76 #define ADB_DESIGNKBD	27	/* XXX Needs to be verified XXX */
     77 #define ADB_PBJPKBD	30
     78 #define ADB_PBG3KBD	195
     79 #define ADB_IBOOKKBD	196	/* iBook, probably others? */
     80 #define ADB_PBG3JPKBD	201
     81 
     82 	/* Interesting mouse handler IDs */
     83 #define ADBMS_100DPI	1
     84 #define ADBMS_200DPI	2
     85 #define ADBMS_MSA3	3	/* Mouse Systems A3 Mouse */
     86 #define ADBMS_EXTENDED	4	/* Extended mouse protocol */
     87 #define ADBMS_USPEED	0x2f	/* MicroSpeed mouse */
     88 #define ADBMS_UCONTOUR	0x66	/* Contour mouse */
     89 #define ADBMS_TURBO	50	/* Kensington Turbo Mouse */
     90 
     91 	/* Interesting tablet handler ID */
     92 #define ADB_ARTPAD	58	/* WACOM ArtPad II tablet */
     93 
     94 	/* Interesting miscellaneous handler ID */
     95 #define ADB_POWERKEY	34	/* Sophisticated Circuits PowerKey */
     96 				/* (intelligent power tap) */
     97 
     98 #define ADBK_KEYVAL(key)	((key) & 0x7f)
     99 #define ADBK_PRESS(key)		(((key) & 0x80) == 0)
    100 #define ADBK_KEYDOWN(key)	(key)
    101 #define ADBK_KEYUP(key)		((key) | 0x80)
    102 
    103 /* EMP device classes */
    104 #define MSCLASS_TABLET		0
    105 #define MSCLASS_MOUSE		1
    106 #define MSCLASS_TRACKBALL	2
    107 #define MSCLASS_TRACKPAD	3
    108 
    109 struct adb_bus_accessops {
    110 	void *cookie;
    111 	/* cookie, poll, address/command, length, data */
    112 	int (*send)(void *, int, int, int, uint8_t *);
    113 	void (*poll)(void *);
    114 	void (*autopoll)(void *, int);	/* bitmask of ADB addresses to poll */
    115 	int (*set_handler)(void *, void (*)(void *, int, uint8_t *), void *);
    116 };
    117 
    118 struct adb_device {
    119 	void *cookie;
    120 	void (*handler)(void *, int, uint8_t *);
    121 	int current_addr;
    122 	int original_addr;
    123 	int handler_id;
    124 };
    125 
    126 struct adb_attach_args {
    127 	struct adb_bus_accessops *ops;
    128 	struct adb_device *dev;
    129 };
    130 
    131 int nadb_print(void *, const char *);
    132 
    133 
    134 #endif /* ADBVAR_H */
    135