From patchwork Tue Aug 31 18:41:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chase Douglas X-Patchwork-Id: 145521 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o7VIgkHR023140 for ; Tue, 31 Aug 2010 18:42:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755231Ab0HaSl6 (ORCPT ); Tue, 31 Aug 2010 14:41:58 -0400 Received: from adelie.canonical.com ([91.189.90.139]:51897 "EHLO adelie.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754974Ab0HaSlW (ORCPT ); Tue, 31 Aug 2010 14:41:22 -0400 Received: from hutte.canonical.com ([91.189.90.181]) by adelie.canonical.com with esmtp (Exim 4.69 #1 (Debian)) id 1OqVlm-0003zx-0O; Tue, 31 Aug 2010 19:41:18 +0100 Received: from cpe-75-180-27-10.columbus.res.rr.com ([75.180.27.10] helo=canonical.com) by hutte.canonical.com with esmtpsa (TLS-1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1OqVll-0005ZY-F7; Tue, 31 Aug 2010 19:41:17 +0100 From: Chase Douglas To: Jiri Kosina Cc: Michael Poole , Henrik Rydberg , Tejun Heo , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6 v2] HID: magicmouse: simplify touch data bit manipulation Date: Tue, 31 Aug 2010 14:41:05 -0400 Message-Id: <1283280068-12285-3-git-send-email-chase.douglas@canonical.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1283280068-12285-1-git-send-email-chase.douglas@canonical.com> References: <1283280068-12285-1-git-send-email-chase.douglas@canonical.com> 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 (demeter1.kernel.org [140.211.167.41]); Tue, 31 Aug 2010 18:42:57 +0000 (UTC) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 3a2147d..98bbc53 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -166,18 +166,21 @@ static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state) 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 down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE; + int id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf; + int x = (tdata[1] << 28 | tdata[0] << 20) >> 20; + int y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); + int size = tdata[5] & 0x3f; + int orientation = (tdata[6] >> 2) - 32; + int touch_major = tdata[3]; + int touch_minor = tdata[4]; + int state = tdata[7] & TOUCH_STATE_MASK; + int down = state != TOUCH_STATE_NONE; /* Store tracking ID and other fields. */ msc->tracking_ids[raw_id] = id; msc->touches[id].x = x; msc->touches[id].y = y; - msc->touches[id].size = misc & 63; + msc->touches[id].size = size; /* If requested, emulate a scroll wheel by detecting small * vertical touch motions. @@ -188,7 +191,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda int step_y = msc->touches[id].scroll_y - y; /* Calculate and apply the scroll motion. */ - switch (tdata[7] & TOUCH_STATE_MASK) { + switch (state) { case TOUCH_STATE_START: msc->touches[id].scroll_x = x; msc->touches[id].scroll_y = y; @@ -224,13 +227,11 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda /* Generate the input events for this touch. */ if (report_touches && down) { - int orientation = (misc >> 10) - 32; - msc->touches[id].down = 1; input_report_abs(input, ABS_MT_TRACKING_ID, id); - input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]); - input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]); + input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major); + input_report_abs(input, ABS_MT_TOUCH_MINOR, touch_minor); input_report_abs(input, ABS_MT_ORIENTATION, orientation); input_report_abs(input, ABS_MT_POSITION_X, x); input_report_abs(input, ABS_MT_POSITION_Y, y);