From patchwork Fri Dec 1 17:13:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ryan Hendrickson X-Patchwork-Id: 10087531 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 728E260327 for ; Fri, 1 Dec 2017 17:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 588E72A2F9 for ; Fri, 1 Dec 2017 17:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C1822A2FB; Fri, 1 Dec 2017 17:20:01 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI 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 DD00228845 for ; Fri, 1 Dec 2017 17:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751405AbdLART7 (ORCPT ); Fri, 1 Dec 2017 12:19:59 -0500 Received: from vicky.finemachine.org ([45.79.146.116]:59686 "EHLO vicky.finemachine.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750988AbdLART6 (ORCPT ); Fri, 1 Dec 2017 12:19:58 -0500 X-Greylist: delayed 384 seconds by postgrey-1.27 at vger.kernel.org; Fri, 01 Dec 2017 12:19:58 EST Received: from adam.lan (ool-18bcc478.dyn.optonline.net [24.188.196.120]) (Authenticated sender: ryan) by vicky.finemachine.org (Postfix) with ESMTPSA id E7CAD15101; Fri, 1 Dec 2017 12:13:33 -0500 (EST) Date: Fri, 1 Dec 2017 12:13:22 -0500 (EST) From: Ryan Hendrickson To: linux-input@vger.kernel.org cc: Henrik Rydberg Subject: [PATCH] bcm5974: report ABS_MT_PRESSURE Message-ID: User-Agent: Alpine 2.21 (LNX 202 2017-01-01) MIME-Version: 1.0 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 Report ABS_MT_PRESSURE in the bcm5974 driver with the same data used for ABS_PRESSURE. Some touchpad improvements in recent versions of libinput, such as pressure-based palm detection, will only work if ABS_MT_PRESSURE is reported. Signed-off-by: Ryan Hendrickson --- Please treat all of this with an extra grain of salt; this is my first real foray into both evdev/libinput internals and kernel development. That said, I have been running this patch on my daily-use MacBookPro5,1 for several months, so I have reason to believe it's stable. It might not be the ‘right’ way to do this though; I mostly just copied the corresponding code for ABS_PRESSURE, which from this[1] blog post I've inferred should have the same values and range. [1]: http://who-t.blogspot.com/2016/09/understanding-evdev.html Patch was originally submitted as bug 197909[2], which can be closed if this is accepted. [2]: https://bugzilla.kernel.org/show_bug.cgi?id=197909 --- linux-4.13/drivers/input/mouse/bcm5974.c.orig 2017-12-01 11:36:35.258890243 -0500 +++ linux-4.13/drivers/input/mouse/bcm5974.c 2017-12-01 11:48:55.187342210 -0500 @@ -548,6 +548,8 @@ static void setup_events_to_report(struc set_abs(input_dev, ABS_MT_POSITION_X, &cfg->x); set_abs(input_dev, ABS_MT_POSITION_Y, &cfg->y); + set_abs(input_dev, ABS_MT_PRESSURE, &cfg->p); + __set_bit(EV_KEY, input_dev->evbit); __set_bit(BTN_LEFT, input_dev->keybit); @@ -575,10 +577,14 @@ static int report_bt_state(struct bcm597 return 0; } -static void report_finger_data(struct input_dev *input, int slot, +static void report_finger_data(struct input_dev *input, + const struct bcm5974_config *cfg, + int slot, const struct input_mt_pos *pos, const struct tp_finger *f) { + int abs_p; + input_mt_slot(input, slot); input_mt_report_slot_state(input, MT_TOOL_FINGER, true); @@ -594,6 +600,9 @@ static void report_finger_data(struct in MAX_FINGER_ORIENTATION - raw2int(f->orientation)); input_report_abs(input, ABS_MT_POSITION_X, pos->x); input_report_abs(input, ABS_MT_POSITION_Y, pos->y); + + abs_p = clamp_val(256 * raw2int(f->touch_major) / cfg->p.max, 0, 255); + input_report_abs(input, ABS_MT_PRESSURE, abs_p); } static void report_synaptics_data(struct input_dev *input, @@ -640,7 +649,7 @@ static int report_tp_state(struct bcm597 input_mt_assign_slots(input, dev->slots, dev->pos, n, 0); for (i = 0; i < n; i++) - report_finger_data(input, dev->slots[i], + report_finger_data(input, c, dev->slots[i], &dev->pos[i], dev->index[i]); input_mt_sync_frame(input);