psmcomm.c revision 28515619
1/* 2 * Copyright � 1997 C. Scott Ananian 3 * Copyright � 1998-2000 Bruce Kalk 4 * Copyright � 2001 Stefan Gmeiner 5 * Copyright � 2002 Linuxcare Inc. David Kennedy 6 * Copyright � 2003 Fred Hucht 7 * Copyright � 2004 Arne Schwabe 8 * 9 * Permission to use, copy, modify, distribute, and sell this software 10 * and its documentation for any purpose is hereby granted without 11 * fee, provided that the above copyright notice appear in all copies 12 * and that both that copyright notice and this permission notice 13 * appear in supporting documentation, and that the name of Red Hat 14 * not be used in advertising or publicity pertaining to distribution 15 * of the software without specific, written prior permission. Red 16 * Hat makes no representations about the suitability of this software 17 * for any purpose. It is provided "as is" without express or implied 18 * warranty. 19 * 20 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 21 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 22 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 23 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 24 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 25 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 26 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 27 * 28 * Authors: 29 * Stefan Gmeiner (riddlebox@freesurf.ch) 30 * C. Scott Ananian (cananian@alumni.priceton.edu) 31 * Bruce Kalk (kall@compass.com) 32 * Linuxcare Inc. David Kennedy (dkennedy@linuxcare.com) 33 * Fred Hucht (fred@thp.Uni-Duisburg.de) 34 * Arne Schwabe <schwabe@uni-paderborn.de> 35 */ 36 37#ifdef HAVE_CONFIG_H 38#include "config.h" 39#endif 40 41#include <xorg-server.h> 42#include <unistd.h> 43#include <sys/ioctl.h> 44#include <sys/mouse.h> 45#include <errno.h> 46#include <string.h> 47#include "synproto.h" 48#include "synapticsstr.h" 49#include "ps2comm.h" /* ps2_print_ident() */ 50#include <xf86.h> 51 52#define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) 53 54/* 55 * Identify Touchpad 56 * See also the SYN_ID_* macros 57 */ 58static Bool 59psm_synaptics_identify(int fd, synapticshw_t * ident) 60{ 61 int ret; 62 63 SYSCALL(ret = ioctl(fd, MOUSE_SYN_GETHWINFO, ident)); 64 if (ret == 0) 65 return TRUE; 66 else 67 return FALSE; 68} 69 70/* This define is used in a ioctl but not in mouse.h :/ */ 71#define PSM_LEVEL_NATIVE 2 72 73static Bool 74PSMQueryIsSynaptics(InputInfoPtr pInfo) 75{ 76 int ret; 77 int level = PSM_LEVEL_NATIVE; 78 mousehw_t mhw; 79 80 /* Put the device in native protocol mode to be sure 81 * Otherwise HWINFO will not return the right id 82 * And we will need native mode anyway ... 83 */ 84 SYSCALL(ret = ioctl(pInfo->fd, MOUSE_SETLEVEL, &level)); 85 if (ret != 0) { 86 xf86IDrvMsg(pInfo, X_ERROR, "%s Can't set native mode\n", pInfo->name); 87 return FALSE; 88 } 89 SYSCALL(ret = ioctl(pInfo->fd, MOUSE_GETHWINFO, &mhw)); 90 if (ret != 0) { 91 xf86IDrvMsg(pInfo, X_ERROR, "%s Can't get hardware info\n", 92 pInfo->name); 93 return FALSE; 94 } 95 96 if (mhw.model == MOUSE_MODEL_SYNAPTICS) { 97 return TRUE; 98 } 99 else { 100 xf86IDrvMsg(pInfo, X_ERROR, 101 "%s Found no Synaptics, found Mouse model %d instead\n", 102 pInfo->name, mhw.model); 103 return FALSE; 104 } 105} 106 107static void 108convert_hw_info(const synapticshw_t * psm_ident, 109 struct PS2SynapticsHwInfo *synhw) 110{ 111 memset(synhw, 0, sizeof(*synhw)); 112 synhw->model_id = ((psm_ident->infoRot180 << 23) | 113 (psm_ident->infoPortrait << 22) | 114 (psm_ident->infoSensor << 16) | 115 (psm_ident->infoHardware << 9) | 116 (psm_ident->infoNewAbs << 7) | 117 (psm_ident->capPen << 6) | 118 (psm_ident->infoSimplC << 5) | 119 (psm_ident->infoGeometry)); 120 synhw->capabilities = ((psm_ident->capExtended << 23) | 121 (psm_ident->capPassthrough << 7) | 122 (psm_ident->capSleep << 4) | 123 (psm_ident->capFourButtons << 3) | 124 (psm_ident->capMultiFinger << 1) | 125 (psm_ident->capPalmDetect)); 126 synhw->ext_cap = 0; 127 synhw->identity = ((psm_ident->infoMajor) | 128 (0x47 << 8) | (psm_ident->infoMinor << 16)); 129} 130 131static Bool 132PSMQueryHardware(InputInfoPtr pInfo) 133{ 134 synapticshw_t psm_ident; 135 struct PS2SynapticsHwInfo *synhw; 136 SynapticsPrivate *priv; 137 138 priv = (SynapticsPrivate *) pInfo->private; 139 140 if (!priv->proto_data) 141 priv->proto_data = calloc(1, sizeof(struct PS2SynapticsHwInfo)); 142 synhw = (struct PS2SynapticsHwInfo *) priv->proto_data; 143 144 /* is the synaptics touchpad active? */ 145 if (!PSMQueryIsSynaptics(pInfo)) 146 return FALSE; 147 148 xf86IDrvMsg(pInfo, X_PROBED, "synaptics touchpad found\n"); 149 150 if (!psm_synaptics_identify(pInfo->fd, &psm_ident)) 151 return FALSE; 152 153 convert_hw_info(&psm_ident, synhw); 154 155 ps2_print_ident(pInfo, synhw); 156 157 return TRUE; 158} 159 160static Bool 161PSMReadHwState(InputInfoPtr pInfo, 162 struct CommData *comm, struct SynapticsHwState *hwRet) 163{ 164 return PS2ReadHwStateProto(pInfo, &psm_proto_operations, comm, hwRet); 165} 166 167struct SynapticsProtocolOperations psm_proto_operations = { 168 NULL, 169 NULL, 170 PSMQueryHardware, 171 PSMReadHwState, 172 NULL, 173 NULL 174}; 175