xref: /haiku/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h (revision 3856867b031bf88fa8f4895d78aa8ea6c57c81c9)
1d61a52a7SMarcus Overhagen /*
2*3856867bSAxel Dörfler  * Copyright 2005-2010 Haiku, Inc.
3d61a52a7SMarcus Overhagen  * Distributed under the terms of the MIT License.
4d61a52a7SMarcus Overhagen  *
5ce8185b3SMarcus Overhagen  * PS/2 bus manager
6d61a52a7SMarcus Overhagen  *
7d61a52a7SMarcus Overhagen  * Authors (in chronological order):
8d61a52a7SMarcus Overhagen  *		Marcus Overhagen (marcus@overhagen.de)
9d61a52a7SMarcus Overhagen  */
10d61a52a7SMarcus Overhagen #ifndef __PS2_DEV_H
11d61a52a7SMarcus Overhagen #define __PS2_DEV_H
12d61a52a7SMarcus Overhagen 
13*3856867bSAxel Dörfler 
14dfd5628dSMarcus Overhagen struct ps2_dev;
15dfd5628dSMarcus Overhagen typedef struct ps2_dev ps2_dev;
16dfd5628dSMarcus Overhagen 
17487f6591SMarcus Overhagen #include "ps2_common.h"
18d61a52a7SMarcus Overhagen 
196849a228SStephan Aßmus 
20802b6330SStephan Aßmus typedef struct {
21f9ff1193SMarcus Overhagen 	bigtime_t		time;
22f9ff1193SMarcus Overhagen 	uint8			data;
2345d3c4ecSMarcus Overhagen 	bool			error;
24f9ff1193SMarcus Overhagen } data_history;
25dfd5628dSMarcus Overhagen 
26802b6330SStephan Aßmus struct ps2_dev {
27d61a52a7SMarcus Overhagen 	const char *	name;
28d61a52a7SMarcus Overhagen 	bool			active;
2903d0d41aSMarcus Overhagen 	uint8           idx;
30d61a52a7SMarcus Overhagen 	sem_id			result_sem;
316849a228SStephan Aßmus 	vint32			flags;
32d61a52a7SMarcus Overhagen 	uint8 *			result_buf;
33d61a52a7SMarcus Overhagen 	int				result_buf_idx;
34d61a52a7SMarcus Overhagen 	int				result_buf_cnt;
35dfd5628dSMarcus Overhagen 	void *			cookie;
3645d3c4ecSMarcus Overhagen 	data_history	history[2];
376849a228SStephan Aßmus 	ps2_dev *		parent_dev;
386849a228SStephan Aßmus 	size_t			packet_size;
39130a1761SMarcus Overhagen 
40130a1761SMarcus Overhagen // functions
41130a1761SMarcus Overhagen 	void          (*disconnect)(ps2_dev *);
42f9ff1193SMarcus Overhagen 	int32		  (*handle_int)(ps2_dev *);
435bb8f085SStephan Aßmus 	status_t	  (*command)(ps2_dev *dev, uint8 cmd, const uint8 *out,
445bb8f085SStephan Aßmus 					int out_count, uint8 *in, int in_count, bigtime_t timeout);
45dfd5628dSMarcus Overhagen };
46d61a52a7SMarcus Overhagen 
476849a228SStephan Aßmus #define PS2_DEVICE_COUNT 6
48395817e3SMarcus Overhagen 
49395817e3SMarcus Overhagen extern ps2_dev ps2_device[PS2_DEVICE_COUNT];
50d61a52a7SMarcus Overhagen 
51d61a52a7SMarcus Overhagen #define PS2_DEVICE_MOUSE 0
526849a228SStephan Aßmus #define PS2_DEVICE_SYN_PASSTHROUGH 4
536849a228SStephan Aßmus #define PS2_DEVICE_KEYB  5
54d61a52a7SMarcus Overhagen 
55dfd5628dSMarcus Overhagen #define PS2_FLAG_KEYB		(1 << 0)
56dfd5628dSMarcus Overhagen #define PS2_FLAG_OPEN		(1 << 1)
57dfd5628dSMarcus Overhagen #define PS2_FLAG_ENABLED	(1 << 2)
58dfd5628dSMarcus Overhagen #define PS2_FLAG_CMD		(1 << 3)
59dfd5628dSMarcus Overhagen #define PS2_FLAG_ACK		(1 << 4)
60dfd5628dSMarcus Overhagen #define PS2_FLAG_NACK		(1 << 5)
61a9e8a72aSMarcus Overhagen #define PS2_FLAG_GETID		(1 << 6)
62d61a52a7SMarcus Overhagen 
63*3856867bSAxel Dörfler 
64*3856867bSAxel Dörfler #ifdef __cplusplus
65*3856867bSAxel Dörfler extern "C" {
66*3856867bSAxel Dörfler #endif
67*3856867bSAxel Dörfler 
686849a228SStephan Aßmus void 		ps2_dev_send(ps2_dev *dev, uint8 data);
696849a228SStephan Aßmus 
706849a228SStephan Aßmus status_t	ps2_dev_detect_pointing(ps2_dev *dev, device_hooks **hooks);
716849a228SStephan Aßmus 
72d61a52a7SMarcus Overhagen status_t	ps2_dev_init(void);
73d61a52a7SMarcus Overhagen void		ps2_dev_exit(void);
74d61a52a7SMarcus Overhagen 
755bb8f085SStephan Aßmus status_t	standard_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
765bb8f085SStephan Aßmus 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
776849a228SStephan Aßmus 
785bb8f085SStephan Aßmus status_t	ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out,
795bb8f085SStephan Aßmus 				int out_count, uint8 *in, int in_count);
805bb8f085SStephan Aßmus status_t	ps2_dev_command_timeout(ps2_dev *dev, uint8 cmd, const uint8 *out,
815bb8f085SStephan Aßmus 				int out_count, uint8 *in, int in_count, bigtime_t timeout);
8203d0d41aSMarcus Overhagen 
83ab89b2f0SStephan Aßmus status_t	ps2_reset_mouse(ps2_dev *dev);
84ab89b2f0SStephan Aßmus 
85d61a52a7SMarcus Overhagen void		ps2_dev_publish(ps2_dev *dev);
86d61a52a7SMarcus Overhagen void		ps2_dev_unpublish(ps2_dev *dev);
87d61a52a7SMarcus Overhagen 
8845d3c4ecSMarcus Overhagen int32		ps2_dev_handle_int(ps2_dev *dev);
89d61a52a7SMarcus Overhagen 
90*3856867bSAxel Dörfler #ifdef __cplusplus
91*3856867bSAxel Dörfler }
92d61a52a7SMarcus Overhagen #endif
93*3856867bSAxel Dörfler 
94*3856867bSAxel Dörfler 
95*3856867bSAxel Dörfler #endif	/* __PS2_DEV_H */
96