Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Fujitsu B-series Lifebook PS/2 TouchScreen driver |
| 3 | * |
| 4 | * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> |
| 5 | * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de> |
| 6 | * |
| 7 | * TouchScreen detection, absolute mode setting and packet layout is taken from |
| 8 | * Harald Hoyer's description of the device. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/input.h> |
| 16 | #include <linux/serio.h> |
| 17 | #include <linux/libps2.h> |
| 18 | #include <linux/dmi.h> |
| 19 | |
| 20 | #include "psmouse.h" |
| 21 | #include "lifebook.h" |
| 22 | |
Dmitry Torokhov | e7afcd1 | 2007-04-12 01:36:25 -0400 | [diff] [blame] | 23 | static const char *desired_serio_phys; |
| 24 | |
| 25 | static int lifebook_set_serio_phys(struct dmi_system_id *d) |
| 26 | { |
| 27 | desired_serio_phys = d->driver_data; |
| 28 | return 0; |
| 29 | } |
| 30 | |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 31 | static unsigned char lifebook_use_6byte_proto; |
| 32 | |
| 33 | static int lifebook_set_6byte_proto(struct dmi_system_id *d) |
| 34 | { |
| 35 | lifebook_use_6byte_proto = 1; |
| 36 | return 0; |
| 37 | } |
| 38 | |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 39 | static struct dmi_system_id lifebook_dmi_table[] = { |
Andrew Morton | b1b2965 | 2006-11-02 23:27:44 -0500 | [diff] [blame] | 40 | { |
| 41 | .ident = "FLORA-ie 55mi", |
| 42 | .matches = { |
| 43 | DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"), |
| 44 | }, |
| 45 | }, |
| 46 | { |
| 47 | .ident = "LifeBook B", |
| 48 | .matches = { |
| 49 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"), |
| 50 | }, |
| 51 | }, |
| 52 | { |
| 53 | .ident = "Lifebook B", |
| 54 | .matches = { |
| 55 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"), |
| 56 | }, |
| 57 | }, |
| 58 | { |
| 59 | .ident = "Lifebook B213x/B2150", |
| 60 | .matches = { |
| 61 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"), |
| 62 | }, |
| 63 | }, |
| 64 | { |
| 65 | .ident = "Zephyr", |
| 66 | .matches = { |
| 67 | DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"), |
| 68 | }, |
| 69 | }, |
| 70 | { |
| 71 | .ident = "CF-18", |
| 72 | .matches = { |
| 73 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"), |
| 74 | }, |
Dmitry Torokhov | e7afcd1 | 2007-04-12 01:36:25 -0400 | [diff] [blame] | 75 | .callback = lifebook_set_serio_phys, |
| 76 | .driver_data = "isa0060/serio3", |
Andrew Morton | b1b2965 | 2006-11-02 23:27:44 -0500 | [diff] [blame] | 77 | }, |
| 78 | { |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 79 | .ident = "Panasonic CF-28", |
| 80 | .matches = { |
| 81 | DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"), |
| 82 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"), |
| 83 | }, |
| 84 | .callback = lifebook_set_6byte_proto, |
| 85 | }, |
| 86 | { |
Andrew Morton | b1b2965 | 2006-11-02 23:27:44 -0500 | [diff] [blame] | 87 | .ident = "Lifebook B142", |
| 88 | .matches = { |
| 89 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"), |
| 90 | }, |
| 91 | }, |
| 92 | { } |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 95 | static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse) |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 96 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 97 | struct input_dev *dev = psmouse->dev; |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 98 | unsigned char *packet = psmouse->packet; |
| 99 | int relative_packet = packet[0] & 0x08; |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 100 | |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 101 | if (relative_packet || !lifebook_use_6byte_proto) { |
| 102 | if (psmouse->pktcnt != 3) |
| 103 | return PSMOUSE_GOOD_DATA; |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 104 | } else { |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 105 | switch (psmouse->pktcnt) { |
| 106 | case 1: |
| 107 | return (packet[0] & 0xf8) == 0x00 ? |
| 108 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 109 | case 2: |
| 110 | return PSMOUSE_GOOD_DATA; |
| 111 | case 3: |
| 112 | return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ? |
| 113 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 114 | case 4: |
| 115 | return (packet[3] & 0xf8) == 0xc0 ? |
| 116 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 117 | case 5: |
| 118 | return (packet[4] & 0xc0) == (packet[2] & 0xc0) ? |
| 119 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; |
| 120 | case 6: |
| 121 | if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0)) |
| 122 | return PSMOUSE_BAD_DATA; |
| 123 | if ((packet[5] & 0xc0) != (packet[1] & 0xc0)) |
| 124 | return PSMOUSE_BAD_DATA; |
| 125 | break; /* report data */ |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if (relative_packet) { |
Dmitry Torokhov | 14e9414 | 2005-05-29 02:30:28 -0500 | [diff] [blame] | 130 | input_report_rel(dev, REL_X, |
| 131 | ((packet[0] & 0x10) ? packet[1] - 256 : packet[1])); |
| 132 | input_report_rel(dev, REL_Y, |
| 133 | -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2])); |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 134 | } else if (lifebook_use_6byte_proto) { |
| 135 | input_report_abs(dev, ABS_X, |
| 136 | ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f)); |
| 137 | input_report_abs(dev, ABS_Y, |
| 138 | 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f))); |
| 139 | } else { |
| 140 | input_report_abs(dev, ABS_X, |
| 141 | (packet[1] | ((packet[0] & 0x30) << 4))); |
| 142 | input_report_abs(dev, ABS_Y, |
| 143 | 1024 - (packet[2] | ((packet[0] & 0xC0) << 2))); |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | input_report_key(dev, BTN_LEFT, packet[0] & 0x01); |
| 147 | input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); |
| 148 | input_report_key(dev, BTN_TOUCH, packet[0] & 0x04); |
| 149 | |
| 150 | input_sync(dev); |
| 151 | |
| 152 | return PSMOUSE_FULL_PACKET; |
| 153 | } |
| 154 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 155 | static int lifebook_absolute_mode(struct psmouse *psmouse) |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 156 | { |
| 157 | struct ps2dev *ps2dev = &psmouse->ps2dev; |
| 158 | unsigned char param; |
| 159 | |
Dmitry Torokhov | 14e9414 | 2005-05-29 02:30:28 -0500 | [diff] [blame] | 160 | if (psmouse_reset(psmouse)) |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 161 | return -1; |
| 162 | |
Dmitry Torokhov | 14e9414 | 2005-05-29 02:30:28 -0500 | [diff] [blame] | 163 | /* |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 164 | Enable absolute output -- ps2_command fails always but if |
| 165 | you leave this call out the touchsreen will never send |
| 166 | absolute coordinates |
Dmitry Torokhov | 14e9414 | 2005-05-29 02:30:28 -0500 | [diff] [blame] | 167 | */ |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 168 | param = lifebook_use_6byte_proto ? 0x08 : 0x07; |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 169 | ps2_command(ps2dev, ¶m, PSMOUSE_CMD_SETRES); |
| 170 | |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Dmitry Torokhov | a913829 | 2005-05-29 02:30:37 -0500 | [diff] [blame] | 174 | static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution) |
| 175 | { |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 176 | static const unsigned char params[] = { 0, 1, 2, 2, 3 }; |
| 177 | unsigned char p; |
Dmitry Torokhov | a913829 | 2005-05-29 02:30:37 -0500 | [diff] [blame] | 178 | |
| 179 | if (resolution == 0 || resolution > 400) |
| 180 | resolution = 400; |
| 181 | |
Helge Deller | e38de67 | 2006-09-10 21:54:39 -0400 | [diff] [blame] | 182 | p = params[resolution / 100]; |
| 183 | ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES); |
| 184 | psmouse->resolution = 50 << p; |
Dmitry Torokhov | a913829 | 2005-05-29 02:30:37 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 187 | static void lifebook_disconnect(struct psmouse *psmouse) |
| 188 | { |
| 189 | psmouse_reset(psmouse); |
| 190 | } |
| 191 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 192 | int lifebook_detect(struct psmouse *psmouse, int set_properties) |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 193 | { |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 194 | if (!dmi_check_system(lifebook_dmi_table)) |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 195 | return -1; |
| 196 | |
Dmitry Torokhov | e7afcd1 | 2007-04-12 01:36:25 -0400 | [diff] [blame] | 197 | if (desired_serio_phys && |
| 198 | strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys)) |
| 199 | return -1; |
| 200 | |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 201 | if (set_properties) { |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 202 | psmouse->vendor = "Fujitsu"; |
| 203 | psmouse->name = "Lifebook TouchScreen"; |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 206 | return 0; |
Kenan Esau | 02d7f58 | 2005-05-29 02:30:22 -0500 | [diff] [blame] | 207 | } |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 208 | |
| 209 | int lifebook_init(struct psmouse *psmouse) |
| 210 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 211 | struct input_dev *input_dev = psmouse->dev; |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 212 | int max_coord = lifebook_use_6byte_proto ? 1024 : 4096; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 213 | |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 214 | if (lifebook_absolute_mode(psmouse)) |
| 215 | return -1; |
| 216 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 217 | input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL); |
| 218 | input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); |
| 219 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); |
| 220 | input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 221 | input_set_abs_params(input_dev, ABS_X, 0, max_coord, 0, 0); |
| 222 | input_set_abs_params(input_dev, ABS_Y, 0, max_coord, 0, 0); |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 223 | |
| 224 | psmouse->protocol_handler = lifebook_process_byte; |
Dmitry Torokhov | a913829 | 2005-05-29 02:30:37 -0500 | [diff] [blame] | 225 | psmouse->set_resolution = lifebook_set_resolution; |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 226 | psmouse->disconnect = lifebook_disconnect; |
| 227 | psmouse->reconnect = lifebook_absolute_mode; |
Dmitry Torokhov | 1b11879 | 2007-04-12 01:36:34 -0400 | [diff] [blame^] | 228 | |
| 229 | /* |
| 230 | * Use packet size = 3 even when using 6-byte protocol because |
| 231 | * that's what POLL will return on Lifebooks (according to spec). |
| 232 | */ |
Dmitry Torokhov | a15d60f | 2005-05-29 02:30:32 -0500 | [diff] [blame] | 233 | psmouse->pktsize = 3; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |