xref: /openbsd/sys/arch/armv7/exynos/crosecvar.h (revision d504b169)
1 /* $OpenBSD: crosecvar.h,v 1.2 2015/07/19 01:13:27 bmercer Exp $ */
2 /*
3  * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef CROSECVAR_H
19 #define CROSECVAR_H
20 
21 #include <sys/timeout.h>
22 #include <sys/task.h>
23 #include <dev/i2c/i2cvar.h>
24 #include <armv7/exynos/ec_commands.h>
25 
26 /* message sizes */
27 #define MSG_HEADER		0xec
28 #define MSG_HEADER_BYTES	3
29 #define MSG_TRAILER_BYTES	2
30 #define MSG_PROTO_BYTES		(MSG_HEADER_BYTES + MSG_TRAILER_BYTES)
31 #define MSG_BYTES		(EC_HOST_PARAM_SIZE + MSG_PROTO_BYTES)
32 #define MSG_BYTES_ALIGNED	((MSG_BYTES+8) & ~8)
33 
34 #define min(a,b)	(((a)<(b))?(a):(b))
35 
36 struct cros_ec_softc {
37 	struct device sc_dev;
38 	i2c_tag_t sc_tag;
39 	i2c_addr_t sc_addr;
40 
41 	int cmd_version_is_supported;
42 	struct {
43 		int rows;
44 		int cols;
45 		int switches;
46 		uint8_t *state;
47 
48 		/* wskbd bits */
49 		struct device *wskbddev;
50 		int rawkbd;
51 		int polling;
52 
53 		/* polling */
54 		struct timeout timeout;
55 		struct taskq *taskq;
56 		struct task task;
57 	} keyboard;
58 	uint8_t in[MSG_BYTES_ALIGNED];
59 	uint8_t out[MSG_BYTES_ALIGNED];
60 };
61 
62 int	cros_ec_check_version(struct cros_ec_softc *);
63 int	cros_ec_scan_keyboard(struct cros_ec_softc *, uint8_t *, int);
64 int	cros_ec_info(struct cros_ec_softc *, struct ec_response_cros_ec_info *);
65 
66 int	cros_ec_init_keyboard(struct cros_ec_softc *);
67 
68 #endif /* !CROSECVAR_H */
69