From patchwork Wed Sep 27 03:03:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei-Ning Huang X-Patchwork-Id: 9972991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4072960365 for ; Wed, 27 Sep 2017 03:03:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2786E28A06 for ; Wed, 27 Sep 2017 03:03:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B2C028A1F; Wed, 27 Sep 2017 03:03:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A7728A06 for ; Wed, 27 Sep 2017 03:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936592AbdI0DD1 (ORCPT ); Tue, 26 Sep 2017 23:03:27 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:52516 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936342AbdI0DD0 (ORCPT ); Tue, 26 Sep 2017 23:03:26 -0400 Received: by mail-pg0-f45.google.com with SMTP id i195so6996570pgd.9 for ; Tue, 26 Sep 2017 20:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=BSN8xzL2Pz90wemGgsnrta4rxoNxf/jtwvg2TqerYyQ=; b=D+4IOoVUmpZoWuIPK0ufxwPhE0XVi5pPCFTg3W8p2czZsL90X1WxKTf3odDxasthxa p5srpULwGkslGHqFDcj6OhpvoTvbv6ZfHMqp6gW5b/PPCaGrxABWw6AuiHqTYu9gsidd R9Balb4HXXXMsrUmDe3d3U+5NGWCZSdQFW3KQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BSN8xzL2Pz90wemGgsnrta4rxoNxf/jtwvg2TqerYyQ=; b=LyNqjJONM+2olpjlde5EGMzEE1h6GkVjtbz+msrnDSQc6Zpr3OYTB9glRnm5DyKbtx wsKFTpqf94vfnXFcQK26oQDAKjuNuI2sIhCsYADPwfQCYof2mkCUx/fKj9GhQ//BffVo /gPTOYHo5Dl3FZOR0FMDtzMhnHxA6GLoCSviDFklItt2WbXlWnDW4urZh4Kl76L5OaE3 T9cNEc6NTLx0gJln3plAeBPuzbx08TH1Q07ZxuxzqRvfe6uU8pdWrpoMTD/jx8ruVyDU BDuh3C+BT52IOjPCuir8gLt0HdaGwamHANgBsTLO8LgxOlHlNO7jl/yafRxr/pkBh5DN tReA== X-Gm-Message-State: AHPjjUiQMszOU218MPDoNUz1+gAkZsMZi+t9BnJ1iuLgkM6IuxNBH/e7 1K+9fA9DgEeA5kMLfsSeL1xJzA== X-Google-Smtp-Source: AOwi7QC65JOXaODdTxSLZX4oi8kvkfEzrJnjLxBVs77eh/JazRUQDa9zuwN/DqAPfKeqRePq/LYqvQ== X-Received: by 10.98.79.156 with SMTP id f28mr12774472pfj.232.1506481405667; Tue, 26 Sep 2017 20:03:25 -0700 (PDT) Received: from wnhuang0.tpe.corp.google.com ([2401:fa00:1:b:58f1:5e65:f85f:de7b]) by smtp.gmail.com with ESMTPSA id j83sm17537559pfe.133.2017.09.26.20.03.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Sep 2017 20:03:24 -0700 (PDT) From: Wei-Ning Huang X-Google-Original-From: Wei-Ning Huang To: LKML , Linux Input Cc: Dmitry Torokhov , Jiri Kosina , Wei-Ning Huang Subject: [PATCH] HID: hid-multitouch: support fine-grain orientation reporting Date: Wed, 27 Sep 2017 11:03:12 +0800 Message-Id: <20170927030312.5573-1-wnhuang@google.com> X-Mailer: git-send-email 2.12.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current hid-multitouch driver only allow the report of two orientations, vertical and horizontal. We use the Azimuth orientation usage 0x5b under the Digitizer usage page to report orientation directly from the hid device. A new quirk MT_QUIRK_REPORT_ORIENTATION is added so user can enable this only if their device supports it. Signed-off-by: Wei-Ning Huang Reviewed-by: Dmitry Torokhov --- drivers/hid/hid-multitouch.c | 38 ++++++++++++++++++++++++++++++++++++-- include/linux/hid.h | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 440b999304a5..4663bf4b2892 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -84,11 +84,12 @@ MODULE_LICENSE("GPL"); #define MT_IO_FLAGS_PENDING_SLOTS 2 struct mt_slot { - __s32 x, y, cx, cy, p, w, h; + __s32 x, y, cx, cy, p, w, h, a; __s32 contactid; /* the device ContactID assigned to this slot */ bool touch_state; /* is the touch valid? */ bool inrange_state; /* is the finger in proximity of the sensor? */ bool confidence_state; /* is the touch made by a finger? */ + bool has_azimuth; /* the contact reports azimuth */ }; struct mt_class { @@ -591,6 +592,23 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, td->cc_index = field->index; td->cc_value_index = usage->usage_index; return 1; + case HID_DG_AZIMUTH: + hid_map_usage(hi, usage, bit, max, + EV_ABS, ABS_MT_ORIENTATION); + /* + * Azimuth has the range of [0, MAX) representing a full + * revolution. Set ABS_MT_ORIENTATION to a quarter of + * MAX according the definition of ABS_MT_ORIENTATION + */ + input_set_abs_params(hi->input, ABS_MT_ORIENTATION, + 0, field->logical_maximum / 4, + cls->sn_move ? + field->logical_maximum / cls->sn_move : 0, 0); + input_abs_set_res(hi->input, ABS_MT_ORIENTATION, + hidinput_calc_abs_res(field, + ABS_MT_ORIENTATION)); + mt_store_field(usage, td, hi); + return 1; case HID_DG_CONTACTMAX: /* we don't set td->last_slot_field as contactcount and * contact max are global to the report */ @@ -683,6 +701,10 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) int wide = (s->w > s->h); int major = max(s->w, s->h); int minor = min(s->w, s->h); + int orientation = wide; + + if (s->has_azimuth) + orientation = s->a; /* * divided by two to match visual scale of touch @@ -699,7 +721,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); input_event(input, EV_ABS, ABS_MT_DISTANCE, !s->touch_state); - input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); + input_event(input, EV_ABS, ABS_MT_ORIENTATION, + orientation); input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); @@ -789,6 +812,17 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, break; case HID_DG_CONTACTCOUNT: break; + case HID_DG_AZIMUTH: + /* + * Azimuth is counter-clockwise and ranges from [0, MAX) + * (a full revolution). Convert it to clockwise ranging + * [-MAX/2, MAX/2]. + */ + if (value > field->logical_maximum / 2) + value -= field->logical_maximum; + td->curdata.a = -value; + td->curdata.has_azimuth = true; + break; case HID_DG_TOUCH: /* do nothing */ break; diff --git a/include/linux/hid.h b/include/linux/hid.h index ab05a86269dc..d81b9b6fd83a 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -281,6 +281,7 @@ struct hid_item { #define HID_DG_DEVICECONFIG 0x000d000e #define HID_DG_DEVICESETTINGS 0x000d0023 +#define HID_DG_AZIMUTH 0x000d003f #define HID_DG_CONFIDENCE 0x000d0047 #define HID_DG_WIDTH 0x000d0048 #define HID_DG_HEIGHT 0x000d0049