xref: /freebsd/sys/dev/cyapa/cyapa.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
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 
36 #ifndef _SYS_DEV_SMBUS_CYAPA_CYAPA_H_
37 #define _SYS_DEV_SMBUS_CYAPA_CYAPA_H_
38 
39 #define CYAPA_MAX_MT    5
40 
41 /*
42  * Boot-time registers.  This is the device map
43  * if (stat & CYAPA_STAT_RUNNING) is 0.
44  */
45 struct cyapa_boot_regs {
46 	uint8_t stat;			/* CYAPA_STAT_xxx */
47 	uint8_t boot;			/* CYAPA_BOOT_xxx */
48 	uint8_t error;
49 } __packed;
50 
51 #define CYAPA_BOOT_BUSY		0x80
52 #define CYAPA_BOOT_RUNNING	0x10
53 #define CYAPA_BOOT_DATA_VALID	0x08
54 #define CYAPA_BOOT_CSUM_VALID	0x01
55 
56 #define CYAPA_ERROR_INVALID     0x80
57 #define CYAPA_ERROR_INVALID_KEY 0x40
58 #define CYAPA_ERROR_BOOTLOADER	0x20
59 #define CYAPA_ERROR_CMD_CSUM    0x10
60 #define CYAPA_ERROR_FLASH_PROT  0x08
61 #define CYAPA_ERROR_FLASH_CSUM  0x04
62 
63 struct cyapa_regs {
64 	uint8_t stat;
65 	uint8_t fngr;
66 
67 	struct {
68 		uint8_t xy_high;        /* 7:4 high 4 bits of x */
69 		uint8_t x_low;          /* 3:0 high 4 bits of y */
70 		uint8_t y_low;
71 		uint8_t pressure;
72 		uint8_t id;             /* 1-15 incremented each touch */
73 	} touch[CYAPA_MAX_MT];
74 } __packed;
75 
76 struct cyapa_cap {
77 	uint8_t prod_ida[5];    /* 0x00 - 0x04 */
78 	uint8_t prod_idb[6];    /* 0x05 - 0x0A */
79 	uint8_t prod_idc[2];    /* 0x0B - 0x0C */
80 	uint8_t reserved[6];    /* 0x0D - 0x12 */
81 	uint8_t buttons;        /* 0x13 */
82 	uint8_t gen;            /* 0x14, low 4 bits */
83 	uint8_t max_abs_xy_high;/* 0x15 7:4 high x bits, 3:0 high y bits */
84 	uint8_t max_abs_x_low;  /* 0x16 */
85 	uint8_t max_abs_y_low;  /* 0x17 */
86 	uint8_t phy_siz_xy_high;/* 0x18 7:4 high x bits, 3:0 high y bits */
87 	uint8_t phy_siz_x_low;  /* 0x19 */
88 	uint8_t phy_siz_y_low;  /* 0x1A */
89 } __packed;
90 
91 #define CYAPA_STAT_RUNNING      0x80
92 #define CYAPA_STAT_PWR_MASK     0x0C
93 #define  CYAPA_PWR_OFF          0x00
94 #define  CYAPA_PWR_IDLE         0x08
95 #define  CYAPA_PWR_ACTIVE       0x0C
96 
97 #define CYAPA_STAT_DEV_MASK     0x03
98 #define  CYAPA_DEV_NORMAL       0x03
99 #define  CYAPA_DEV_BUSY         0x01
100 
101 #define CYAPA_FNGR_DATA_VALID   0x08
102 #define CYAPA_FNGR_MIDDLE       0x04
103 #define CYAPA_FNGR_RIGHT        0x02
104 #define CYAPA_FNGR_LEFT         0x01
105 #define CYAPA_FNGR_NUMFINGERS(c) (((c) >> 4) & 0x0F)
106 
107 #define CYAPA_TOUCH_X(regs, i)  ((((regs)->touch[i].xy_high << 4) & 0x0F00) | \
108 				  (regs)->touch[i].x_low)
109 #define CYAPA_TOUCH_Y(regs, i)  ((((regs)->touch[i].xy_high << 8) & 0x0F00) | \
110 				  (regs)->touch[i].y_low)
111 #define CYAPA_TOUCH_P(regs, i)  ((regs)->touch[i].pressure)
112 
113 #define CMD_BOOT_STATUS		0x00	/* only if in boot state */
114 #define CMD_DEV_STATUS          0x00	/* only if in operational state */
115 #define CMD_SOFT_RESET          0x28
116 #define CMD_POWER_MODE          0x29
117 #define  CMD_POWER_MODE_OFF	0x00
118 #define  CMD_POWER_MODE_IDLE	0x14
119 #define  CMD_POWER_MODE_FULL	0xFC
120 #define CMD_QUERY_CAPABILITIES  0x2A
121 
122 #endif
123