--- pckbd.c Tue May 18 10:45:09 2004 +++ pckbd.c.new Tue May 18 11:35:46 2004 @@ -91,6 +91,7 @@ #define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */ #define AUX_SET_RES 0xE8 /* Set resolution */ #define AUX_GET_SCALE 0xE9 /* Get scaling factor */ +/* according to Synaptic docs this $E9 is really 3-byte status */ #define AUX_SET_STREAM 0xEA /* Set stream mode */ #define AUX_POLL 0xEB /* Poll */ #define AUX_RESET_WRAP 0xEC /* Reset wrap mode */ @@ -115,6 +116,11 @@ int rptr, wptr, count; } KBDQueue; +typedef struct { + int absolute; + int high; +} TouchPad; + typedef struct KBDState { KBDQueue queues[2]; uint8_t write_cmd; /* if non zero, write data to port 60 is expected */ @@ -135,6 +141,7 @@ int mouse_dy; int mouse_dz; uint8_t mouse_buttons; + TouchPad touchpad; } KBDState; KBDState kbd_state; @@ -394,6 +401,51 @@ dx1 = s->mouse_dx; dy1 = s->mouse_dy; dz1 = s->mouse_dz; + if (s->touchpad.absolute) + { + int dz2, dleftnright, dg, df; + if (dx1 > 6143) + dx1 = 6143; + else if (dx1 < 0) + dx1 = 0; + if (dy1 > 6143) + dy1 = 6143; + else if (dy1 < 0) + dy1 = 0; + dz2 = 80; /* normal finger pressure */ + dg = 0; /* guesture not supported */ + df = 0; /* finger not supported */ + dleftnright = (s->mouse_buttons & 0x07); + /* + X: 13 bits --return absolute x ord + Y: 13 bits --return absolute y ord + Z: 8 bits --return constant 80 since we don't know how hard the user + is pressing on the mouse button ;) 80 is the default for pen + pressure, as touchpads cant sense what pressure a pen makes. + W: 4 bits --return 0, we don't support finger width (should we?) + left: 1 bit --is left button pressed + right: 1 bit --is right button pressed + guesture: 1 bit --we dont support, return 0 + finger: 1 bit --ditto + total: 42 bits in 6 bytes + note that Synaptics drivers ignore the finger and guesture bits and + consider them redundant + */ + /* + note: the packet setup is different when Wmode = 1, but + this doesn't apply since we don't support Wmode capability + format of packet is as follows: + */ + // 1 0 finger reserved 0 gesture right left + kbd_queue(s, (0x80 | (df ? 0x20 : 0) | (dg ? 0x04 : 0) | dleftnright), 1); + kbd_queue(s, ((dy1 & 0xF) * 256) + (dx1 & 0xF), 1); + kbd_queue(s, 80, 1); //byte 3 + // 1 1 y-12 x-12 0 gesture right left + kbd_queue(s, (0xC0 | ((dy1 & 1000) ? 0x20 : 0) | ((dx1 & 1000) ? 0x10 : 0) | (dg ? 0x04 : 0) | dleftnright), 1); + kbd_queue(s, dx1 & 0xFF, 1); + kbd_queue(s, dy1 & 0xFF, 1); + return; + } /* XXX: increase range to 8 bits ? */ if (dx1 > 127) dx1 = 127; @@ -465,6 +517,9 @@ static void kbd_write_mouse(KBDState *s, int val) { +/* variables needed to store synaptics command info */ +static int rr = 0, ss = 0, tt = 0, uu = 0, res_count = 0, last_com = 0; +int spare; #ifdef DEBUG_MOUSE printf("kbd: write mouse 0x%02x\n", val); #endif @@ -483,6 +538,7 @@ return; } } + last_com = val; switch(val) { case AUX_SET_SCALE11: s->mouse_status &= ~MOUSE_STATUS_SCALE21; @@ -514,10 +570,126 @@ kbd_queue(s, AUX_ACK, 1); break; case AUX_GET_SCALE: - kbd_queue(s, AUX_ACK, 1); - kbd_queue(s, s->mouse_status, 1); - kbd_queue(s, s->mouse_resolution, 1); - kbd_queue(s, s->mouse_sample_rate, 1); + if (res_count == 4) + { + /* time for the special stuff */ + kbd_queue(s, AUX_ACK, 1); + /* below is how we get the real synaptic command */ + val = (rr*64) + (ss*16) + (tt*4) + uu; + switch(val) + { + /* id touchpad */ + case 0x00: + /* info Minor */ + kbd_queue(s, 0x00, 1); + /* special verification byte */ + kbd_queue(s, 0x47, 1); + /* info Major * 0x10 + Info ModelCode*/ + kbd_queue(s, 4 * 0x10 + 0, 1); + break; + /* read touchpad modes */ + case 0x01: + /* special verification byte */ + kbd_queue(s, 0x3B, 1); + /* mode */ + /* + bit 7 - absolute or relative position + bit 6 - 0 for 40 packets/sec, 1 for 80 pack/sec + bit 3 - 1 for sleep mode, 0 for normal + bit 2 - 1 to detect tap/drag, 0 to disable + bit 1 - packet size, only valid for serial protocol + bit 0 - 0 for normal packets, 1 for enhanced packets + (absolute mode packets which have finger width) + */ + if (s->touchpad.absolute && s->touchpad.high) + { + spare = 0xC0; + } + else if (s->touchpad.absolute) + { + spare = 0x80; + } + else if (s->touchpad.high) + { + spare = 0x40; + } + else + { + spare = 0x00; + } + kbd_queue(s, spare, 1); + /* special verification byte */ + kbd_queue(s, 0x47, 1); + break; + /* read touchpad capabilites */ + case 0x02: + /* extended capability first 8 bits */ + kbd_queue(s, 0x00, 1); + /* special verification byte */ + kbd_queue(s, 0x47, 1); + /* extended capability last 8 bits */ + kbd_queue(s, 0x00, 1); + /* basicly, we don't have any capabilites ;0 */ + break; + /* read model id */ + case 0x03: + /* + bit 23 = 0 (1 for upsidedownpad) + bit 22 = 0 (1 for 90 degree rotated pad) + bits 21-16 = 1 (standard model) + bits 15-9 = ??? (reserved for synaptics use) + bit 7 = 1 + bit 6 = 0 (1 for sensing pens) + bit 5 = 1 + bits 3-0 = 1 (rectangular geometery) + */ + kbd_queue(s, 0xFC, 1); + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0xF5, 1); //F7 for sensing pens + break; + /* read serial number prefix */ + case 0x06: + /* strange how they have this query even though + no touchpad actually has serial numbers */ + /* return serial prefix of 0 if we dont have one */ + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + break; + /* read serial number suffix */ + case 0x07: + /* undefined if we dont have a valid serial prefix */ + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + break; + /* read resolutions */ + case 0x08: + /* going to go with infoSensor = 1 (Standard model) here */ + /* absolute X in abolute units per mm */ + kbd_queue(s, 85, 1); + /* undefined but first bit 7 will be set to 1... + hell I'm going to set them all to 1 */ + kbd_queue(s, 0xFF, 1); + /* absolute Y in abolute units per mm */ + kbd_queue(s, 94, 1); + break; + default: + /* invalid commands return undefined data */ + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + kbd_queue(s, 0x00, 1); + break; + } + } + else + { + /* not a special command, just do the regular stuff */ + kbd_queue(s, AUX_ACK, 1); + kbd_queue(s, s->mouse_status, 1); + kbd_queue(s, s->mouse_resolution, 1); + kbd_queue(s, s->mouse_sample_rate, 1); + } break; case AUX_POLL: kbd_queue(s, AUX_ACK, 1); @@ -535,12 +707,14 @@ s->mouse_sample_rate = 100; s->mouse_resolution = 2; s->mouse_status = 0; + s->touchpad.absolute = 0; kbd_queue(s, AUX_ACK, 1); break; case AUX_RESET: s->mouse_sample_rate = 100; s->mouse_resolution = 2; s->mouse_status = 0; + s->touchpad.absolute = 0; kbd_queue(s, AUX_ACK, 1); kbd_queue(s, 0xaa, 1); kbd_queue(s, s->mouse_type, 1); @@ -550,6 +724,13 @@ } break; case AUX_SET_SAMPLE: + if (res_count == 4 && val == 0x14) + { + /* time for the special stuff */ + /* below is how we get the real synaptic command */ + val = (rr*64) + (ss*16) + (tt*4) + uu; + /* TODO: set the mode byte */ + } else s->mouse_sample_rate = val; #if 0 /* detect IMPS/2 or IMEX */ @@ -583,6 +764,34 @@ s->mouse_write_cmd = -1; break; case AUX_SET_RES: + if (last_com != AUX_SET_RES) + { + /* if its not 4 in a row, its not a command */ + /* FIXME: if we are set 8 of these in a row, or 12, or 16, + or etc ... or 4^n commands, then the nth'd mode byte sent might + still work. not sure if this is how things are suppose to be + or not. */ + res_count = 0; + } + res_count++; + if (res_count > 4) res_count = 4; + switch(res_count) + /* we need to save the val in the right spots to get the + real command later */ + { + case 1: + break; + rr = val; + case 2: + ss = val; + break; + case 3: + tt = val; + break; + case 4: + uu = val; + break; + } s->mouse_resolution = val; kbd_queue(s, AUX_ACK, 1); s->mouse_write_cmd = -1;