1 .\" $NetBSD: pckbport.9,v 1.4 2004/08/07 10:03:29 wiz Exp $
3 .\" Copyright (c) 2004 Ben Harris
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\" derived from this software without specific prior written permission.
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.
34 .Nm pckbport_attach_slot ,
35 .Nm pckbport_cnattach ,
37 .Nm pckbport_set_inputhandler ,
39 .Nm pckbport_poll_cmd ,
40 .Nm pckbport_enqueue_cmd ,
41 .Nm pckbport_poll_data ,
42 .Nm pckbport_set_poll ,
43 .Nm pckbport_xt_translation ,
44 .Nm pckbport_slot_enable
45 .Nd PC keyboard port interface
47 .In dev/pckbport/pckbportvar.h
49 .Fn pckbport_attach "void *" "struct pckbport_accessops const *"
51 .Fn pckbport_attach_slot "struct device *" pckbport_tag_t pckbport_slot_t
53 .Fn pckbport_cnattach "void *" "struct pckbport_accessops const *" \
56 .Fn pckbportintr pckbport_tag_t pckbport_slot_t int
58 .Fn pckbport_set_inputhandler pckbport_tag_t pckbport_slot_t \
59 pckbport_inputfcn "void *" "char *"
61 .Fn pckbport_flush pckbport_tag_t pckbport_slot_t
63 .Fn pckbport_poll_cmd pckbport_tag_t pckbport_slot_t "u_char *" int int \
66 .Fn pckbport_enqueue_cmd pckbport_tag_t pckbport_slot_t "u_char *" int int \
69 .Fn pckbport_poll_data pckbport_tag_t pckbport_slot_t
71 .Fn pckbport_set_poll pckbport_tag_t pckbport_slot_t int
73 .Fn pckbport_xt_translation pckbport_tag_t pckbport_slot_t int
75 .Fn pckbport_slot_enable pckbport_tag_t pckbport_slot_t int
77 The machine-independent
79 subsystem provides an interface layer corresponding to the serial
80 keyboard and mouse interface used on the
82 and many other machines.
83 It interfaces a controller driver such as
85 to device drivers such as
90 A single controller can have up to two ports (known as
92 and these are identified by values of type
98 should be used for keyboard and mouse ports respectively.
99 Each controller is identified by an opaque value of type
101 .Ss Controller interface
102 A PC keyboard controller registers itself by calling
103 .Fn pckbport_attach cookie ops ,
107 .Fa struct pckbport_accessops
108 containing pointers to functions for driving the controller, which will
111 as their first argument.
115 assigned to the controller.
116 The controller is then expected to call
117 .Fn pckbport_attach_slot
118 for each slot with which it is equipped, passing the
119 .Fa "struct device *"
120 corresponding to the controller.
121 This function returns a pointer to the child device attached to the slot,
124 if no such device was attached.
127 .Fa "struct pckbport_accessops"
128 each take as their first two arguments the
132 and the slot in question.
135 .It Fa int Fn (*t_xt_translation) "void *cookie" "pckbport_slot_t slot" \
139 is non-zero, enable, otherwise disable, AT-to-XT keycode translation
140 on the slot specified.
141 Returns 1 on success, 0 on failure (or if the controller does not support such
143 .It Fa int Fn (*t_send_devcmd) "void *cookie" "pckbport_slot_t slot" \
147 to the device without waiting for completion.
148 Returns 1 on success, 0 on failure.
149 .It Fa int Fn (*t_poll_data1) "void *cookie" "pckbport_slot_t slot"
150 Wait for and return one byte of data from the device, without using interrupts.
151 This function will only be called after
153 has been used to put the slot in polling mode.
154 If no data are forthcoming from the device after about 100ms, return \-1.
155 .It Fa void Fn (*t_slot_enable) "void *cookie" "pckbport_slot_t slot" "int on"
158 is non-zero, enable, otherwise disable, the slot.
159 If a slot is disabled, it can be powered down, and is not expected to
160 generate any interrupts.
161 When first attached, ports should be disabled.
162 .It Fa void Fn (*t_intr_establish) "void *cookie" "pckbport_slot_t slot"
163 Set up an interrupt handler for the slot.
164 Called when a device gets attached to it.
165 .It Fa void Fn (*t_set_poll) "void *cookie" "pckbport_slot_t slot" "int on"
168 is non-zero, enable, otherwise disable, polling mode on the slot.
169 In polling mode, data received from the device are provided to
173 whether or not interrupts are enabled.
175 data from the device are expected to cause interrupts.
176 The controller interrupt handler should call
177 .Fn pckbportintr tag slot byte
180 received from the device.
181 When first attached, a port should be in non-polling mode.
184 Devices that attach to
186 controllers do so using the normal
193 functions get passed a
194 .Fa "struct pckbport_attach_args"
195 which contains the controller and slot number where the device was found.
196 Device drivers can use the following functions to communicate with the
202 arguments to specify the slot to be acted on.
204 .It Fn pckbport_set_inputhandler tag slot fn arg name
207 to be called with argument
209 whenever an unsolicited byte is received from the slot.
210 The function will be called at
212 .It Fn pckbport_flush tag slot
213 Ensure that there is no pending input from the slot.
214 .It Fn pckbport_poll_cmd tag slot cmd len responselen respbuf slow
215 Issue a complete device command,
218 bytes long, expecting a response
220 bytes long, which will be placed in
224 is true, the command is expected to take over a second to execute.
225 .Fn pckbport_poll_cmd
226 handles getting an acknowledgement from the device and retrying the command
228 Returns 0 on success, and an error value on failure.
229 This function should only be called during autoconfiguration or when the
230 slot has been placed into polling mode by
231 .Fn pckbport_set_poll .
232 .It Fn pckbport_enqueue_cmd tag slot cmd len responselen sync respbuf
233 Issue a complete device command,
236 bytes long, expecting a response
238 bytes long, which will be places in
243 .Fn pckbport_enqueue_cmd
244 waits for the command to complete before returning, otherwise it returns
246 It is not safe to set
248 when calling from an interrupt context.
251 layer handles getting an acknowledgement from the device and retrying
252 the command if necessary.
253 Returns 0 on success, and an error value on failure.
254 .It Fn pckbport_poll_data tag slot
255 Low-level command to poll for a single byte of data from the device, but
256 ignoring bytes that are part of the response to a command issued through
257 .Fn pckbport_enqueue_command .
258 .It Fn pckbport_set_poll tag slot on
261 is true, enable polling on the slot, otherwise disable it.
263 .Fn pckbport_poll_cmd
264 can be used to issue commands and
265 .Fn pckbport_poll_data
266 to read unsolicited data, without enabling interrupts.
267 In non-polling mode, commands should be issued using
268 .Fn pckbport_enqueue_cmd ,
269 unsolicited data are handled by the input function, and disabling interrupts
273 .It Fn pckbport_xt_translation tag slot on
275 .Fn (*t_xt_translation)
277 .It Fn pckbport_slot enable tag slot on
282 .Ss Console interface
283 On systems that can attach consoles through
285 the controller's console attachment function (called very early in
286 autoconfiguration) calls
287 .Fn pckbport_cnattach cookie ops slot .
288 The first two arguments are the same as for
289 .Fn pckbport_attach ,
290 while the third indicates which slot the console keyboard is attached to.
291 .Fn pckbport_cnattach
294 if it is available, or
295 .Fn pckbport_machdep_cnattach .
296 The latter allows machine-dependent keyboard drivers to attach themselves,
297 but it is only called if a device with the
298 .Ql pckbport_machdep_cnattach
299 attribute is configured into the system.
300 .Fn pckbport_cnattach
301 returns 0 on success and an error value on failure.
302 .Fn pckbport_machdep_cnattach
303 is expected to do the same.
311 device drivers are in
312 .Pa sys/dev/pckbport .
330 without any sensible way of using a different controller.