xref: /haiku/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2005-2010 Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * PS/2 bus manager
6  *
7  * Authors (in chronological order):
8  *		Marcus Overhagen (marcus@overhagen.de)
9  */
10 #ifndef __PS2_DEV_H
11 #define __PS2_DEV_H
12 
13 
14 struct ps2_dev;
15 typedef struct ps2_dev ps2_dev;
16 
17 #include "ps2_common.h"
18 
19 
20 typedef struct {
21 	bigtime_t		time;
22 	uint8			data;
23 	bool			error;
24 } data_history;
25 
26 struct ps2_dev {
27 	const char *	name;
28 	bool			active;
29 	uint8           idx;
30 	sem_id			result_sem;
31 	vint32			flags;
32 	uint8 *			result_buf;
33 	int				result_buf_idx;
34 	int				result_buf_cnt;
35 	void *			cookie;
36 	data_history	history[2];
37 	ps2_dev *		parent_dev;
38 	size_t			packet_size;
39 
40 // functions
41 	void          (*disconnect)(ps2_dev *);
42 	int32		  (*handle_int)(ps2_dev *);
43 	status_t	  (*command)(ps2_dev *dev, uint8 cmd, const uint8 *out,
44 					int out_count, uint8 *in, int in_count, bigtime_t timeout);
45 };
46 
47 #define PS2_DEVICE_COUNT 6
48 
49 extern ps2_dev ps2_device[PS2_DEVICE_COUNT];
50 
51 #define PS2_DEVICE_MOUSE 0
52 #define PS2_DEVICE_SYN_PASSTHROUGH 4
53 #define PS2_DEVICE_KEYB  5
54 
55 #define PS2_FLAG_KEYB		(1 << 0)
56 #define PS2_FLAG_OPEN		(1 << 1)
57 #define PS2_FLAG_ENABLED	(1 << 2)
58 #define PS2_FLAG_CMD		(1 << 3)
59 #define PS2_FLAG_ACK		(1 << 4)
60 #define PS2_FLAG_NACK		(1 << 5)
61 #define PS2_FLAG_GETID		(1 << 6)
62 #define PS2_FLAG_RESEND		(1 << 7)
63 
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 void 		ps2_dev_send(ps2_dev *dev, uint8 data);
70 
71 status_t	ps2_dev_detect_pointing(ps2_dev *dev, device_hooks **hooks);
72 
73 status_t	ps2_dev_init(void);
74 void		ps2_dev_exit(void);
75 
76 status_t	standard_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
77 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
78 
79 status_t	ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out,
80 				int out_count, uint8 *in, int in_count);
81 status_t	ps2_dev_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
82 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
83 
84 status_t	ps2_reset_mouse(ps2_dev *dev);
85 
86 void		ps2_dev_publish(ps2_dev *dev);
87 void		ps2_dev_unpublish(ps2_dev *dev);
88 
89 int32		ps2_dev_handle_int(ps2_dev *dev);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 
96 #endif	/* __PS2_DEV_H */
97