1/* $OpenBSD: pckbcvar.h,v 1.17 2023/07/25 10:00:44 miod Exp $ */
2/* $NetBSD: pckbcvar.h,v 1.4 2000/06/09 04:58:35 soda Exp $ */
3
4/*
5 * Copyright (c) 1998
6 *	Matthias Drochner.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#ifndef _DEV_IC_PCKBCVAR_H_
31#define _DEV_IC_PCKBCVAR_H_
32
33#include <sys/timeout.h>
34
35#define PCKBCCF_SLOT            0
36#define PCKBCCF_SLOT_DEFAULT    -1
37
38typedef void *pckbc_tag_t;
39typedef int pckbc_slot_t;
40#define	PCKBC_KBD_SLOT	0
41#define	PCKBC_AUX_SLOT	1
42#define	PCKBC_NSLOTS	2
43
44/*
45 * external representation (pckbc_tag_t),
46 * needed early for console operation
47 */
48struct pckbc_internal {
49	bus_space_tag_t t_iot;
50	bus_space_handle_t t_ioh_d, t_ioh_c; /* data port, cmd port */
51	bus_addr_t t_addr;
52	u_char t_cmdbyte; /* shadow */
53
54	int t_flags;
55	/* need auxwrite command to find aux */
56#define	PCKBC_NEED_AUXWRITE	0x0001
57	/* can't translate to XT scancodes, stuck to set #2 */
58#define	PCKBC_FIXED_SET2	0x0002
59	/* can't translate to XT scancodes, stuck to set #3 */
60#define	PCKBC_FIXED_SET3	0x0004
61#define	PCKBC_CANT_TRANSLATE	(PCKBC_FIXED_SET2 | PCKBC_FIXED_SET3)
62	int t_haveaux;	/* controller has an aux port */
63
64	struct pckbc_slotdata *t_slotdata[PCKBC_NSLOTS];
65
66	struct pckbc_softc *t_sc; /* back pointer */
67
68	struct timeout t_cleanup;
69	struct timeout t_poll;
70};
71
72typedef void (*pckbc_inputfcn)(void *, int);
73
74/*
75 * State per device.
76 */
77struct pckbc_softc {
78	struct device sc_dv;
79	struct pckbc_internal *id;
80
81	pckbc_inputfcn inputhandler[PCKBC_NSLOTS];
82	void *inputarg[PCKBC_NSLOTS];
83	char *subname[PCKBC_NSLOTS];
84};
85
86struct pckbc_attach_args {
87	pckbc_tag_t pa_tag;
88	pckbc_slot_t pa_slot;
89};
90
91extern const char *pckbc_slot_names[];
92extern struct pckbc_internal pckbc_consdata;
93extern int pckbc_console_attached;
94
95void pckbc_set_inputhandler(pckbc_tag_t, pckbc_slot_t,
96				 pckbc_inputfcn, void *, char *);
97
98void pckbc_flush(pckbc_tag_t, pckbc_slot_t);
99int pckbc_poll_cmd(pckbc_tag_t, pckbc_slot_t, u_char *, int,
100			int, u_char *, int);
101int pckbc_enqueue_cmd(pckbc_tag_t, pckbc_slot_t, u_char *, int,
102			   int, int, u_char *);
103int pckbc_send_cmd(bus_space_tag_t, bus_space_handle_t, u_char);
104int pckbc_poll_data(pckbc_tag_t, pckbc_slot_t);
105int pckbc_poll_data1(bus_space_tag_t, bus_space_handle_t,
106			  bus_space_handle_t, pckbc_slot_t, int);
107void pckbc_set_poll(pckbc_tag_t, pckbc_slot_t, int);
108int pckbc_xt_translation(pckbc_tag_t, int *);
109void pckbc_slot_enable(pckbc_tag_t, pckbc_slot_t, int);
110
111void pckbc_attach(struct pckbc_softc *, int);
112int pckbc_cnattach(bus_space_tag_t, bus_addr_t, bus_size_t, int);
113int pckbc_is_console(bus_space_tag_t, bus_addr_t);
114void pckbc_reset(struct pckbc_softc *);
115void pckbc_stop(struct pckbc_softc *);
116int pckbcintr(void *);
117
118void pckbc_release_console(void);
119
120/*
121 * Device configuration flags (cf_flags).
122 */
123
124#define	PCKBCF_FORCE_KEYBOARD_PRESENT	0x0001
125
126#endif /* _DEV_IC_PCKBCVAR_H_ */
127