xref: /freebsd/sys/dev/cyapa/cyapa.h (revision d8a0fe102c0cfdfcd5b818f850eff09d8536c9bc)
1 /*
2  * Copyright (c) 2014 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com> and was subsequently ported
6  * to FreeBSD by Michael Gmelin <freebsd@grem.de>
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  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  * 3. Neither the name of The DragonFly Project nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific, prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
26  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * $FreeBSD$
36  */
37 
38 #ifndef _SYS_DEV_SMBUS_CYAPA_CYAPA_H_
39 #define _SYS_DEV_SMBUS_CYAPA_CYAPA_H_
40 
41 #define CYAPA_MAX_MT    5
42 
43 /*
44  * Boot-time registers.  This is the device map
45  * if (stat & CYAPA_STAT_RUNNING) is 0.
46  */
47 struct cyapa_boot_regs {
48 	uint8_t stat;			/* CYAPA_STAT_xxx */
49 	uint8_t boot;			/* CYAPA_BOOT_xxx */
50 	uint8_t error;
51 } __packed;
52 
53 #define CYAPA_BOOT_BUSY		0x80
54 #define CYAPA_BOOT_RUNNING	0x10
55 #define CYAPA_BOOT_DATA_VALID	0x08
56 #define CYAPA_BOOT_CSUM_VALID	0x01
57 
58 #define CYAPA_ERROR_INVALID     0x80
59 #define CYAPA_ERROR_INVALID_KEY 0x40
60 #define CYAPA_ERROR_BOOTLOADER	0x20
61 #define CYAPA_ERROR_CMD_CSUM    0x10
62 #define CYAPA_ERROR_FLASH_PROT  0x08
63 #define CYAPA_ERROR_FLASH_CSUM  0x04
64 
65 struct cyapa_regs {
66 	uint8_t stat;
67 	uint8_t fngr;
68 
69 	struct {
70 		uint8_t xy_high;        /* 7:4 high 4 bits of x */
71 		uint8_t x_low;          /* 3:0 high 4 bits of y */
72 		uint8_t y_low;
73 		uint8_t pressure;
74 		uint8_t id;             /* 1-15 incremented each touch */
75 	} touch[CYAPA_MAX_MT];
76 } __packed;
77 
78 struct cyapa_cap {
79 	uint8_t prod_ida[5];    /* 0x00 - 0x04 */
80 	uint8_t prod_idb[6];    /* 0x05 - 0x0A */
81 	uint8_t prod_idc[2];    /* 0x0B - 0x0C */
82 	uint8_t reserved[6];    /* 0x0D - 0x12 */
83 	uint8_t buttons;        /* 0x13 */
84 	uint8_t gen;            /* 0x14, low 4 bits */
85 	uint8_t max_abs_xy_high;/* 0x15 7:4 high x bits, 3:0 high y bits */
86 	uint8_t max_abs_x_low;  /* 0x16 */
87 	uint8_t max_abs_y_low;  /* 0x17 */
88 	uint8_t phy_siz_xy_high;/* 0x18 7:4 high x bits, 3:0 high y bits */
89 	uint8_t phy_siz_x_low;  /* 0x19 */
90 	uint8_t phy_siz_y_low;  /* 0x1A */
91 } __packed;
92 
93 #define CYAPA_STAT_RUNNING      0x80
94 #define CYAPA_STAT_PWR_MASK     0x0C
95 #define  CYAPA_PWR_OFF          0x00
96 #define  CYAPA_PWR_IDLE         0x08
97 #define  CYAPA_PWR_ACTIVE       0x0C
98 
99 #define CYAPA_STAT_DEV_MASK     0x03
100 #define  CYAPA_DEV_NORMAL       0x03
101 #define  CYAPA_DEV_BUSY         0x01
102 
103 #define CYAPA_FNGR_DATA_VALID   0x08
104 #define CYAPA_FNGR_MIDDLE       0x04
105 #define CYAPA_FNGR_RIGHT        0x02
106 #define CYAPA_FNGR_LEFT         0x01
107 #define CYAPA_FNGR_NUMFINGERS(c) (((c) >> 4) & 0x0F)
108 
109 #define CYAPA_TOUCH_X(regs, i)  ((((regs)->touch[i].xy_high << 4) & 0x0F00) | \
110 				  (regs)->touch[i].x_low)
111 #define CYAPA_TOUCH_Y(regs, i)  ((((regs)->touch[i].xy_high << 8) & 0x0F00) | \
112 				  (regs)->touch[i].y_low)
113 #define CYAPA_TOUCH_P(regs, i)  ((regs)->touch[i].pressure)
114 
115 #define CMD_BOOT_STATUS		0x00	/* only if in boot state */
116 #define CMD_DEV_STATUS          0x00	/* only if in operational state */
117 #define CMD_SOFT_RESET          0x28
118 #define CMD_POWER_MODE          0x29
119 #define  CMD_POWER_MODE_OFF	0x00
120 #define  CMD_POWER_MODE_IDLE	0x14
121 #define  CMD_POWER_MODE_FULL	0xFC
122 #define CMD_QUERY_CAPABILITIES  0x2A
123 
124 #endif
125