From patchwork Mon Jul 5 22:08:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Poole X-Patchwork-Id: 110288 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o65M8eSn031670 for ; Mon, 5 Jul 2010 22:08:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752897Ab0GEWIk (ORCPT ); Mon, 5 Jul 2010 18:08:40 -0400 Received: from na3sys009aog108.obsmtp.com ([74.125.149.199]:40949 "HELO na3sys009aog108.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752043Ab0GEWIj (ORCPT ); Mon, 5 Jul 2010 18:08:39 -0400 Received: from source ([209.85.212.43]) by na3sys009aob108.postini.com ([74.125.148.12]) with SMTP ID DSNKTDJX4nXAV2pTHRglmFgpNFf16kcc4kUR@postini.com; Mon, 05 Jul 2010 15:08:39 PDT Received: by vws4 with SMTP id 4so5754789vws.16 for ; Mon, 05 Jul 2010 15:08:34 -0700 (PDT) Received: by 10.229.219.212 with SMTP id hv20mr2010400qcb.35.1278367714434; Mon, 05 Jul 2010 15:08:34 -0700 (PDT) Received: from graviton.troilus.org (pool-72-83-66-147.washdc.east.verizon.net [72.83.66.147]) by mx.google.com with ESMTPS id fb41sm20038282qcb.15.2010.07.05.15.08.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 05 Jul 2010 15:08:33 -0700 (PDT) From: Michael Poole To: Chase Douglas Cc: Ping Cheng , Jiri Kosina , linux-input@vger.kernel.org Subject: Re: [PATCH] hid-magicmouse: Correct parsing of large X and Y motions. References: <878w5qaspq.fsf@troilus.org> <1278360120.2425.97.camel@cndougla> <87wrt9acu5.fsf@troilus.org> <1278363118.10426.15.camel@cndougla> Date: Mon, 05 Jul 2010 18:08:32 -0400 In-Reply-To: <1278363118.10426.15.camel@cndougla> (Chase Douglas's message of "Mon, 05 Jul 2010 16:51:58 -0400") Message-ID: <87sk3xa8f3.fsf@troilus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 05 Jul 2010 22:08:41 +0000 (UTC) --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -163,14 +163,26 @@ static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state) msc->scroll_accel = SCROLL_ACCEL_DEFAULT; } +/* Function shamelessly borrowed from hid-core.c. */ + +static s32 snto32(__u32 value, unsigned n) +{ + switch (n) { + case 8: return ((__s8)value); + case 16: return ((__s16)value); + case 32: return ((__s32)value); + } + return value & (1 << (n - 1)) ? value | (-1 << n) : value; +} + static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata) { struct input_dev *input = msc->input; __s32 x_y = tdata[0] << 8 | tdata[1] << 16 | tdata[2] << 24; int misc = tdata[5] | tdata[6] << 8; int id = (misc >> 6) & 15; - int x = x_y << 12 >> 20; - int y = -(x_y >> 20); + int x = snto32((x_y >> 8) & 4095, 12); + int y = snto32(x_y >> 20, 12); int down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE; /* Store tracking ID and other fields. */ @@ -285,8 +297,8 @@ static int magicmouse_raw_event(struct hid_device *hdev, * to have the current touch information before * generating a click event. */ - x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22; - y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22; + x = snto32(((data[3] & 0x0c) << 6) | data[1], 10); + y = snto32(((data[3] & 0x30) << 4) | data[2], 10); clicks = data[3]; break; case 0x20: /* Theoretically battery status (0-100), but I have