From patchwork Sun Feb 7 21:48:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roderick Colenbrander X-Patchwork-Id: 12073401 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87073C43381 for ; Sun, 7 Feb 2021 21:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A3B964E35 for ; Sun, 7 Feb 2021 21:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbhBGVt7 (ORCPT ); Sun, 7 Feb 2021 16:49:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbhBGVt6 (ORCPT ); Sun, 7 Feb 2021 16:49:58 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8032EC06178A for ; Sun, 7 Feb 2021 13:49:18 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id t25so8995289pga.2 for ; Sun, 07 Feb 2021 13:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaikai-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kn3Xm39IUpFr6Y3GNzdLj+spjqDqR6bA47h6Zrszf/s=; b=Mun6vuuRHSbNxa7dgHU4DVbvXTkqwXKymogSHkrcEG94idSkr/HzkntopesMRDcruN 31cI/ECEG/s87jkeE+Jl+O5/WCpuMP6UP0dOAcyZj1H7SiZJdgj7RSJ/A+BBlnRWMKPd NdnXJhdZgkLeh9kyX02rA+iQm3Ka+1Vo07kauT4G/lN/fL2e/t9MozgSw9Orhpgekpo/ diN3+NeDzm48eMFjgEuie9/m173buRN5T3ySoq1bI5RY88wlyCGFtVDUx13/2tzOwdaq 77Q/5kwWtRQj0vzi16hHD31w4mjSn7RFISGGvz7JCfU6VI5LLhp3v7a4sOz2ZVXBXXN7 k7kg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kn3Xm39IUpFr6Y3GNzdLj+spjqDqR6bA47h6Zrszf/s=; b=XT6Zt1RQbVqAdh8np64odQDpONkM9UT/765JIEYryPuiLE5NgKIFFCOUzSy/ZJGF9D wzLaovm9n+K34pyzRevxxzcex0c+lRblNy545GzdMmZMRmShlO01G4xH5L4552uOARjk DfhzCX4CMAVpo/mI9O7JQgGvrAnsbi8y48G8yh8u+AAu4CwwOgcU/RomikF9bhIEikwB MSqhVTKtIW3FAKNRcN4OUKwww2NhhFUzxn4ZvOMz2AEDzdggf/7t7lfFOcyJOeTsGaKK rvbSwWbn1TtYZJLJsPQmYfhpvE9foBfglSSzMU1lEf3JlL/5VNXcjeZ/UoKRbekV1fR3 rY9Q== X-Gm-Message-State: AOAM5314EmeLHgRf6TFsfhMi+D5uHe7/86Mz2w+oyM9Iq7su7IiAUgA5 VFuJ2Z+mvP4ykkcouSuL83O8Kw== X-Google-Smtp-Source: ABdhPJwL5sKC8jNE1sbkKv5un21hm3zjmfL2PHNOZmU+trdTW5TRh45SCEJ+Cyej2ertoLYV602hOg== X-Received: by 2002:a65:6152:: with SMTP id o18mr14591920pgv.392.1612734557876; Sun, 07 Feb 2021 13:49:17 -0800 (PST) Received: from us8c16456344dc.lan (cpe-76-87-77-78.socal.res.rr.com. [76.87.77.78]) by smtp.gmail.com with ESMTPSA id a141sm16578991pfa.189.2021.02.07.13.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 13:49:17 -0800 (PST) From: Roderick Colenbrander To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, Chris Ye , =?utf-8?q?Barna?= =?utf-8?q?b=C3=A1s_P=C5=91cze?= , =?utf-8?q?Samuel_?= =?utf-8?q?=C4=8Cavoj?= , =?utf-8?q?Florian_M=C3=A4rk?= =?utf-8?q?l?= , Roderick Colenbrander Subject: [PATCH v6 04/13] HID: playstation: add DualSense touchpad support. Date: Sun, 7 Feb 2021 13:48:59 -0800 Message-Id: <20210207214908.79573-5-roderick@gaikai.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210207214908.79573-1-roderick@gaikai.com> References: <20210207214908.79573-1-roderick@gaikai.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Roderick Colenbrander Implement support for DualSense touchpad as a separate input device. Signed-off-by: Roderick Colenbrander --- drivers/hid/hid-playstation.c | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 3bb5091be308..30ae9434240c 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -60,9 +60,21 @@ struct ps_device { #define DS_STATUS_CHARGING GENMASK(7, 4) #define DS_STATUS_CHARGING_SHIFT 4 +/* + * Status of a DualSense touch point contact. + * Contact IDs, with highest bit set are 'inactive' + * and any associated data is then invalid. + */ +#define DS_TOUCH_POINT_INACTIVE BIT(7) + +/* DualSense hardware limits */ +#define DS_TOUCHPAD_WIDTH 1920 +#define DS_TOUCHPAD_HEIGHT 1080 + struct dualsense { struct ps_device base; struct input_dev *gamepad; + struct input_dev *touchpad; }; struct dualsense_touch_point { @@ -281,6 +293,34 @@ static int ps_get_report(struct hid_device *hdev, uint8_t report_id, uint8_t *bu return 0; } +static struct input_dev *ps_touchpad_create(struct hid_device *hdev, int width, int height, + unsigned int num_contacts) +{ + struct input_dev *touchpad; + int ret; + + touchpad = ps_allocate_input_dev(hdev, "Touchpad"); + if (IS_ERR(touchpad)) + return ERR_CAST(touchpad); + + /* Map button underneath touchpad to BTN_LEFT. */ + input_set_capability(touchpad, EV_KEY, BTN_LEFT); + __set_bit(INPUT_PROP_BUTTONPAD, touchpad->propbit); + + input_set_abs_params(touchpad, ABS_MT_POSITION_X, 0, width - 1, 0, 0); + input_set_abs_params(touchpad, ABS_MT_POSITION_Y, 0, height - 1, 0, 0); + + ret = input_mt_init_slots(touchpad, num_contacts, INPUT_MT_POINTER); + if (ret) + return ERR_PTR(ret); + + ret = input_register_device(touchpad); + if (ret) + return ERR_PTR(ret); + + return touchpad; +} + static int dualsense_get_mac_address(struct dualsense *ds) { uint8_t *buf; @@ -313,6 +353,7 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r uint8_t battery_data, battery_capacity, charging_status, value; int battery_status; unsigned long flags; + int i; /* * DualSense in USB uses the full HID report for reportID 1, but @@ -355,6 +396,25 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME); input_sync(ds->gamepad); + for (i = 0; i < ARRAY_SIZE(ds_report->points); i++) { + struct dualsense_touch_point *point = &ds_report->points[i]; + bool active = (point->contact & DS_TOUCH_POINT_INACTIVE) ? false : true; + + input_mt_slot(ds->touchpad, i); + input_mt_report_slot_state(ds->touchpad, MT_TOOL_FINGER, active); + + if (active) { + int x = (point->x_hi << 8) | point->x_lo; + int y = (point->y_hi << 4) | point->y_lo; + + input_report_abs(ds->touchpad, ABS_MT_POSITION_X, x); + input_report_abs(ds->touchpad, ABS_MT_POSITION_Y, y); + } + } + input_mt_sync_frame(ds->touchpad); + input_report_key(ds->touchpad, BTN_LEFT, ds_report->buttons[2] & DS_BUTTONS2_TOUCHPAD); + input_sync(ds->touchpad); + battery_data = ds_report->status & DS_STATUS_BATTERY_CAPACITY; charging_status = (ds_report->status & DS_STATUS_CHARGING) >> DS_STATUS_CHARGING_SHIFT; @@ -431,6 +491,12 @@ static struct ps_device *dualsense_create(struct hid_device *hdev) goto err; } + ds->touchpad = ps_touchpad_create(hdev, DS_TOUCHPAD_WIDTH, DS_TOUCHPAD_HEIGHT, 2); + if (IS_ERR(ds->touchpad)) { + ret = PTR_ERR(ds->touchpad); + goto err; + } + ret = ps_device_register_battery(ps_dev); if (ret) goto err;