18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Focaltech TouchPad PS/2 mouse driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2014 Red Hat Inc. 68c2ecf20Sopenharmony_ci * Copyright (c) 2014 Mathias Gottschlag <mgottschlag@gmail.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Red Hat authors: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Hans de Goede <hdegoede@redhat.com> 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/device.h> 158c2ecf20Sopenharmony_ci#include <linux/libps2.h> 168c2ecf20Sopenharmony_ci#include <linux/input/mt.h> 178c2ecf20Sopenharmony_ci#include <linux/serio.h> 188c2ecf20Sopenharmony_ci#include <linux/slab.h> 198c2ecf20Sopenharmony_ci#include "psmouse.h" 208c2ecf20Sopenharmony_ci#include "focaltech.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic const char * const focaltech_pnp_ids[] = { 238c2ecf20Sopenharmony_ci "FLT0101", 248c2ecf20Sopenharmony_ci "FLT0102", 258c2ecf20Sopenharmony_ci "FLT0103", 268c2ecf20Sopenharmony_ci NULL 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * Even if the kernel is built without support for Focaltech PS/2 touchpads (or 318c2ecf20Sopenharmony_ci * when the real driver fails to recognize the device), we still have to detect 328c2ecf20Sopenharmony_ci * them in order to avoid further detection attempts confusing the touchpad. 338c2ecf20Sopenharmony_ci * This way it at least works in PS/2 mouse compatibility mode. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ciint focaltech_detect(struct psmouse *psmouse, bool set_properties) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci if (!psmouse_matches_pnp_id(psmouse, focaltech_pnp_ids)) 388c2ecf20Sopenharmony_ci return -ENODEV; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci if (set_properties) { 418c2ecf20Sopenharmony_ci psmouse->vendor = "FocalTech"; 428c2ecf20Sopenharmony_ci psmouse->name = "Touchpad"; 438c2ecf20Sopenharmony_ci } 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci return 0; 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#ifdef CONFIG_MOUSE_PS2_FOCALTECH 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * Packet types - the numbers are not consecutive, so we might be missing 528c2ecf20Sopenharmony_ci * something here. 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_ci#define FOC_TOUCH 0x3 /* bitmap of active fingers */ 558c2ecf20Sopenharmony_ci#define FOC_ABS 0x6 /* absolute position of one finger */ 568c2ecf20Sopenharmony_ci#define FOC_REL 0x9 /* relative position of 1-2 fingers */ 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define FOC_MAX_FINGERS 5 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * Current state of a single finger on the touchpad. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_cistruct focaltech_finger_state { 648c2ecf20Sopenharmony_ci /* The touchpad has generated a touch event for the finger */ 658c2ecf20Sopenharmony_ci bool active; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci /* 688c2ecf20Sopenharmony_ci * The touchpad has sent position data for the finger. The 698c2ecf20Sopenharmony_ci * flag is 0 when the finger is not active, and there is a 708c2ecf20Sopenharmony_ci * time between the first touch event for the finger and the 718c2ecf20Sopenharmony_ci * following absolute position packet for the finger where the 728c2ecf20Sopenharmony_ci * touchpad has declared the finger to be valid, but we do not 738c2ecf20Sopenharmony_ci * have any valid position yet. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_ci bool valid; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* 788c2ecf20Sopenharmony_ci * Absolute position (from the bottom left corner) of the 798c2ecf20Sopenharmony_ci * finger. 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_ci unsigned int x; 828c2ecf20Sopenharmony_ci unsigned int y; 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* 868c2ecf20Sopenharmony_ci * Description of the current state of the touchpad hardware. 878c2ecf20Sopenharmony_ci */ 888c2ecf20Sopenharmony_cistruct focaltech_hw_state { 898c2ecf20Sopenharmony_ci /* 908c2ecf20Sopenharmony_ci * The touchpad tracks the positions of the fingers for us, 918c2ecf20Sopenharmony_ci * the array indices correspond to the finger indices returned 928c2ecf20Sopenharmony_ci * in the report packages. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ci struct focaltech_finger_state fingers[FOC_MAX_FINGERS]; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci /* 978c2ecf20Sopenharmony_ci * Finger width 0-7 and 15 for a very big contact area. 988c2ecf20Sopenharmony_ci * 15 value stays until the finger is released. 998c2ecf20Sopenharmony_ci * Width is reported only in absolute packets. 1008c2ecf20Sopenharmony_ci * Since hardware reports width only for last touching finger, 1018c2ecf20Sopenharmony_ci * there is no need to store width for every specific finger, 1028c2ecf20Sopenharmony_ci * so we keep only last value reported. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci unsigned int width; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci /* True if the clickpad has been pressed. */ 1078c2ecf20Sopenharmony_ci bool pressed; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct focaltech_data { 1118c2ecf20Sopenharmony_ci unsigned int x_max, y_max; 1128c2ecf20Sopenharmony_ci struct focaltech_hw_state state; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic void focaltech_report_state(struct psmouse *psmouse) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 1188c2ecf20Sopenharmony_ci struct focaltech_hw_state *state = &priv->state; 1198c2ecf20Sopenharmony_ci struct input_dev *dev = psmouse->dev; 1208c2ecf20Sopenharmony_ci int i; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci for (i = 0; i < FOC_MAX_FINGERS; i++) { 1238c2ecf20Sopenharmony_ci struct focaltech_finger_state *finger = &state->fingers[i]; 1248c2ecf20Sopenharmony_ci bool active = finger->active && finger->valid; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci input_mt_slot(dev, i); 1278c2ecf20Sopenharmony_ci input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); 1288c2ecf20Sopenharmony_ci if (active) { 1298c2ecf20Sopenharmony_ci unsigned int clamped_x, clamped_y; 1308c2ecf20Sopenharmony_ci /* 1318c2ecf20Sopenharmony_ci * The touchpad might report invalid data, so we clamp 1328c2ecf20Sopenharmony_ci * the resulting values so that we do not confuse 1338c2ecf20Sopenharmony_ci * userspace. 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci clamped_x = clamp(finger->x, 0U, priv->x_max); 1368c2ecf20Sopenharmony_ci clamped_y = clamp(finger->y, 0U, priv->y_max); 1378c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_MT_POSITION_X, clamped_x); 1388c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_MT_POSITION_Y, 1398c2ecf20Sopenharmony_ci priv->y_max - clamped_y); 1408c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_TOOL_WIDTH, state->width); 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci input_mt_report_pointer_emulation(dev, true); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci input_report_key(dev, BTN_LEFT, state->pressed); 1468c2ecf20Sopenharmony_ci input_sync(dev); 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic void focaltech_process_touch_packet(struct psmouse *psmouse, 1508c2ecf20Sopenharmony_ci unsigned char *packet) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 1538c2ecf20Sopenharmony_ci struct focaltech_hw_state *state = &priv->state; 1548c2ecf20Sopenharmony_ci unsigned char fingers = packet[1]; 1558c2ecf20Sopenharmony_ci int i; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci state->pressed = (packet[0] >> 4) & 1; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* the second byte contains a bitmap of all fingers touching the pad */ 1608c2ecf20Sopenharmony_ci for (i = 0; i < FOC_MAX_FINGERS; i++) { 1618c2ecf20Sopenharmony_ci state->fingers[i].active = fingers & 0x1; 1628c2ecf20Sopenharmony_ci if (!state->fingers[i].active) { 1638c2ecf20Sopenharmony_ci /* 1648c2ecf20Sopenharmony_ci * Even when the finger becomes active again, we still 1658c2ecf20Sopenharmony_ci * will have to wait for the first valid position. 1668c2ecf20Sopenharmony_ci */ 1678c2ecf20Sopenharmony_ci state->fingers[i].valid = false; 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci fingers >>= 1; 1708c2ecf20Sopenharmony_ci } 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistatic void focaltech_process_abs_packet(struct psmouse *psmouse, 1748c2ecf20Sopenharmony_ci unsigned char *packet) 1758c2ecf20Sopenharmony_ci{ 1768c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 1778c2ecf20Sopenharmony_ci struct focaltech_hw_state *state = &priv->state; 1788c2ecf20Sopenharmony_ci unsigned int finger; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci finger = (packet[1] >> 4) - 1; 1818c2ecf20Sopenharmony_ci if (finger >= FOC_MAX_FINGERS) { 1828c2ecf20Sopenharmony_ci psmouse_err(psmouse, "Invalid finger in abs packet: %d\n", 1838c2ecf20Sopenharmony_ci finger); 1848c2ecf20Sopenharmony_ci return; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci state->pressed = (packet[0] >> 4) & 1; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci state->fingers[finger].x = ((packet[1] & 0xf) << 8) | packet[2]; 1908c2ecf20Sopenharmony_ci state->fingers[finger].y = (packet[3] << 8) | packet[4]; 1918c2ecf20Sopenharmony_ci state->width = packet[5] >> 4; 1928c2ecf20Sopenharmony_ci state->fingers[finger].valid = true; 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic void focaltech_process_rel_packet(struct psmouse *psmouse, 1968c2ecf20Sopenharmony_ci unsigned char *packet) 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 1998c2ecf20Sopenharmony_ci struct focaltech_hw_state *state = &priv->state; 2008c2ecf20Sopenharmony_ci int finger1, finger2; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci state->pressed = packet[0] >> 7; 2038c2ecf20Sopenharmony_ci finger1 = ((packet[0] >> 4) & 0x7) - 1; 2048c2ecf20Sopenharmony_ci if (finger1 < FOC_MAX_FINGERS) { 2058c2ecf20Sopenharmony_ci state->fingers[finger1].x += (s8)packet[1]; 2068c2ecf20Sopenharmony_ci state->fingers[finger1].y += (s8)packet[2]; 2078c2ecf20Sopenharmony_ci } else { 2088c2ecf20Sopenharmony_ci psmouse_err(psmouse, "First finger in rel packet invalid: %d\n", 2098c2ecf20Sopenharmony_ci finger1); 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* 2138c2ecf20Sopenharmony_ci * If there is an odd number of fingers, the last relative 2148c2ecf20Sopenharmony_ci * packet only contains one finger. In this case, the second 2158c2ecf20Sopenharmony_ci * finger index in the packet is 0 (we subtract 1 in the lines 2168c2ecf20Sopenharmony_ci * above to create array indices, so the finger will overflow 2178c2ecf20Sopenharmony_ci * and be above FOC_MAX_FINGERS). 2188c2ecf20Sopenharmony_ci */ 2198c2ecf20Sopenharmony_ci finger2 = ((packet[3] >> 4) & 0x7) - 1; 2208c2ecf20Sopenharmony_ci if (finger2 < FOC_MAX_FINGERS) { 2218c2ecf20Sopenharmony_ci state->fingers[finger2].x += (s8)packet[4]; 2228c2ecf20Sopenharmony_ci state->fingers[finger2].y += (s8)packet[5]; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci} 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistatic void focaltech_process_packet(struct psmouse *psmouse) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci unsigned char *packet = psmouse->packet; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci switch (packet[0] & 0xf) { 2318c2ecf20Sopenharmony_ci case FOC_TOUCH: 2328c2ecf20Sopenharmony_ci focaltech_process_touch_packet(psmouse, packet); 2338c2ecf20Sopenharmony_ci break; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci case FOC_ABS: 2368c2ecf20Sopenharmony_ci focaltech_process_abs_packet(psmouse, packet); 2378c2ecf20Sopenharmony_ci break; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci case FOC_REL: 2408c2ecf20Sopenharmony_ci focaltech_process_rel_packet(psmouse, packet); 2418c2ecf20Sopenharmony_ci break; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci default: 2448c2ecf20Sopenharmony_ci psmouse_err(psmouse, "Unknown packet type: %02x\n", packet[0]); 2458c2ecf20Sopenharmony_ci break; 2468c2ecf20Sopenharmony_ci } 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci focaltech_report_state(psmouse); 2498c2ecf20Sopenharmony_ci} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic psmouse_ret_t focaltech_process_byte(struct psmouse *psmouse) 2528c2ecf20Sopenharmony_ci{ 2538c2ecf20Sopenharmony_ci if (psmouse->pktcnt >= 6) { /* Full packet received */ 2548c2ecf20Sopenharmony_ci focaltech_process_packet(psmouse); 2558c2ecf20Sopenharmony_ci return PSMOUSE_FULL_PACKET; 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* 2598c2ecf20Sopenharmony_ci * We might want to do some validation of the data here, but 2608c2ecf20Sopenharmony_ci * we do not know the protocol well enough 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ci return PSMOUSE_GOOD_DATA; 2638c2ecf20Sopenharmony_ci} 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistatic int focaltech_switch_protocol(struct psmouse *psmouse) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct ps2dev *ps2dev = &psmouse->ps2dev; 2688c2ecf20Sopenharmony_ci unsigned char param[3]; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci param[0] = 0; 2718c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, 0x10f8)) 2728c2ecf20Sopenharmony_ci return -EIO; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, 0x10f8)) 2758c2ecf20Sopenharmony_ci return -EIO; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, 0x10f8)) 2788c2ecf20Sopenharmony_ci return -EIO; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci param[0] = 1; 2818c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, 0x10f8)) 2828c2ecf20Sopenharmony_ci return -EIO; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETSCALE11)) 2858c2ecf20Sopenharmony_ci return -EIO; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_ENABLE)) 2888c2ecf20Sopenharmony_ci return -EIO; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci return 0; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic void focaltech_reset(struct psmouse *psmouse) 2948c2ecf20Sopenharmony_ci{ 2958c2ecf20Sopenharmony_ci ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 2968c2ecf20Sopenharmony_ci psmouse_reset(psmouse); 2978c2ecf20Sopenharmony_ci} 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistatic void focaltech_disconnect(struct psmouse *psmouse) 3008c2ecf20Sopenharmony_ci{ 3018c2ecf20Sopenharmony_ci focaltech_reset(psmouse); 3028c2ecf20Sopenharmony_ci kfree(psmouse->private); 3038c2ecf20Sopenharmony_ci psmouse->private = NULL; 3048c2ecf20Sopenharmony_ci} 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cistatic int focaltech_reconnect(struct psmouse *psmouse) 3078c2ecf20Sopenharmony_ci{ 3088c2ecf20Sopenharmony_ci int error; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci focaltech_reset(psmouse); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci error = focaltech_switch_protocol(psmouse); 3138c2ecf20Sopenharmony_ci if (error) { 3148c2ecf20Sopenharmony_ci psmouse_err(psmouse, "Unable to initialize the device\n"); 3158c2ecf20Sopenharmony_ci return error; 3168c2ecf20Sopenharmony_ci } 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci return 0; 3198c2ecf20Sopenharmony_ci} 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cistatic void focaltech_set_input_params(struct psmouse *psmouse) 3228c2ecf20Sopenharmony_ci{ 3238c2ecf20Sopenharmony_ci struct input_dev *dev = psmouse->dev; 3248c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* 3278c2ecf20Sopenharmony_ci * Undo part of setup done for us by psmouse core since touchpad 3288c2ecf20Sopenharmony_ci * is not a relative device. 3298c2ecf20Sopenharmony_ci */ 3308c2ecf20Sopenharmony_ci __clear_bit(EV_REL, dev->evbit); 3318c2ecf20Sopenharmony_ci __clear_bit(REL_X, dev->relbit); 3328c2ecf20Sopenharmony_ci __clear_bit(REL_Y, dev->relbit); 3338c2ecf20Sopenharmony_ci __clear_bit(BTN_RIGHT, dev->keybit); 3348c2ecf20Sopenharmony_ci __clear_bit(BTN_MIDDLE, dev->keybit); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* 3378c2ecf20Sopenharmony_ci * Now set up our capabilities. 3388c2ecf20Sopenharmony_ci */ 3398c2ecf20Sopenharmony_ci __set_bit(EV_ABS, dev->evbit); 3408c2ecf20Sopenharmony_ci input_set_abs_params(dev, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0); 3418c2ecf20Sopenharmony_ci input_set_abs_params(dev, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0); 3428c2ecf20Sopenharmony_ci input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); 3438c2ecf20Sopenharmony_ci input_mt_init_slots(dev, 5, INPUT_MT_POINTER); 3448c2ecf20Sopenharmony_ci __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); 3458c2ecf20Sopenharmony_ci} 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic int focaltech_read_register(struct ps2dev *ps2dev, int reg, 3488c2ecf20Sopenharmony_ci unsigned char *param) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETSCALE11)) 3518c2ecf20Sopenharmony_ci return -EIO; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci param[0] = 0; 3548c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES)) 3558c2ecf20Sopenharmony_ci return -EIO; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES)) 3588c2ecf20Sopenharmony_ci return -EIO; 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES)) 3618c2ecf20Sopenharmony_ci return -EIO; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci param[0] = reg; 3648c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES)) 3658c2ecf20Sopenharmony_ci return -EIO; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) 3688c2ecf20Sopenharmony_ci return -EIO; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci return 0; 3718c2ecf20Sopenharmony_ci} 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_cistatic int focaltech_read_size(struct psmouse *psmouse) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci struct ps2dev *ps2dev = &psmouse->ps2dev; 3768c2ecf20Sopenharmony_ci struct focaltech_data *priv = psmouse->private; 3778c2ecf20Sopenharmony_ci char param[3]; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci if (focaltech_read_register(ps2dev, 2, param)) 3808c2ecf20Sopenharmony_ci return -EIO; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci /* not sure whether this is 100% correct */ 3838c2ecf20Sopenharmony_ci priv->x_max = (unsigned char)param[1] * 128; 3848c2ecf20Sopenharmony_ci priv->y_max = (unsigned char)param[2] * 128; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci return 0; 3878c2ecf20Sopenharmony_ci} 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_cistatic void focaltech_set_resolution(struct psmouse *psmouse, 3908c2ecf20Sopenharmony_ci unsigned int resolution) 3918c2ecf20Sopenharmony_ci{ 3928c2ecf20Sopenharmony_ci /* not supported yet */ 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic void focaltech_set_rate(struct psmouse *psmouse, unsigned int rate) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci /* not supported yet */ 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic void focaltech_set_scale(struct psmouse *psmouse, 4018c2ecf20Sopenharmony_ci enum psmouse_scale scale) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci /* not supported yet */ 4048c2ecf20Sopenharmony_ci} 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ciint focaltech_init(struct psmouse *psmouse) 4078c2ecf20Sopenharmony_ci{ 4088c2ecf20Sopenharmony_ci struct focaltech_data *priv; 4098c2ecf20Sopenharmony_ci int error; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci psmouse->private = priv = kzalloc(sizeof(struct focaltech_data), 4128c2ecf20Sopenharmony_ci GFP_KERNEL); 4138c2ecf20Sopenharmony_ci if (!priv) 4148c2ecf20Sopenharmony_ci return -ENOMEM; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci focaltech_reset(psmouse); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci error = focaltech_read_size(psmouse); 4198c2ecf20Sopenharmony_ci if (error) { 4208c2ecf20Sopenharmony_ci psmouse_err(psmouse, 4218c2ecf20Sopenharmony_ci "Unable to read the size of the touchpad\n"); 4228c2ecf20Sopenharmony_ci goto fail; 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci error = focaltech_switch_protocol(psmouse); 4268c2ecf20Sopenharmony_ci if (error) { 4278c2ecf20Sopenharmony_ci psmouse_err(psmouse, "Unable to initialize the device\n"); 4288c2ecf20Sopenharmony_ci goto fail; 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci focaltech_set_input_params(psmouse); 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci psmouse->protocol_handler = focaltech_process_byte; 4348c2ecf20Sopenharmony_ci psmouse->pktsize = 6; 4358c2ecf20Sopenharmony_ci psmouse->disconnect = focaltech_disconnect; 4368c2ecf20Sopenharmony_ci psmouse->reconnect = focaltech_reconnect; 4378c2ecf20Sopenharmony_ci psmouse->cleanup = focaltech_reset; 4388c2ecf20Sopenharmony_ci /* resync is not supported yet */ 4398c2ecf20Sopenharmony_ci psmouse->resync_time = 0; 4408c2ecf20Sopenharmony_ci /* 4418c2ecf20Sopenharmony_ci * rate/resolution/scale changes are not supported yet, and 4428c2ecf20Sopenharmony_ci * the generic implementations of these functions seem to 4438c2ecf20Sopenharmony_ci * confuse some touchpads 4448c2ecf20Sopenharmony_ci */ 4458c2ecf20Sopenharmony_ci psmouse->set_resolution = focaltech_set_resolution; 4468c2ecf20Sopenharmony_ci psmouse->set_rate = focaltech_set_rate; 4478c2ecf20Sopenharmony_ci psmouse->set_scale = focaltech_set_scale; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci return 0; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_cifail: 4528c2ecf20Sopenharmony_ci focaltech_reset(psmouse); 4538c2ecf20Sopenharmony_ci kfree(priv); 4548c2ecf20Sopenharmony_ci return error; 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci#endif /* CONFIG_MOUSE_PS2_FOCALTECH */ 457