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