From patchwork Sun Feb 10 10:14:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolai Kondrashov X-Patchwork-Id: 10804699 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81E321515 for ; Sun, 10 Feb 2019 10:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 739BB29F45 for ; Sun, 10 Feb 2019 10:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67FFB29F4A; Sun, 10 Feb 2019 10:15:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 0248429F45 for ; Sun, 10 Feb 2019 10:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726127AbfBJKPI (ORCPT ); Sun, 10 Feb 2019 05:15:08 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33423 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbfBJKPI (ORCPT ); Sun, 10 Feb 2019 05:15:08 -0500 Received: by mail-lj1-f194.google.com with SMTP id f24-v6so6475283ljk.0 for ; Sun, 10 Feb 2019 02:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iYX7oziVmMWRZL/NrahYZjN+ATBishUKc/WP2vJni74=; b=V9H/v1SwlGfBzeoc7j5ie+4diRzywWUeyY4BPJKef4WEvQqDpCQbCKv1gp/BKbaJ0S spPePpQm8eaKB3EftJQz04aE2edcqH+1vPI5D2RBviuvR/h4QPRx0GxfT8vlKQtcRJUb JwpWiny3uKmd5b/ZPZ+YWv+S8rEKCJGcuY5fiavQVS/OAknAZyYbErinsRD9hRdUy0D0 h8wThamsnC7cZ3uSEQtmbLyG4fzJ+4/sD+9zAp6KUlFbZ2SxtpKkNm0VROL3fp1ASQTO xxD0278O6F/yXDoFPxwV0QOJLaoWpD2/sIR9xflr+/MR3++1/4yl68A0LTqtgQGx78gE +FhQ== 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=iYX7oziVmMWRZL/NrahYZjN+ATBishUKc/WP2vJni74=; b=DGuDhDFndbwy2qEKGHMH9V7jrhYndrKDIN/gAJ2pZDAsS4rjA4ZXNcVYDVS6Wk+sRD odMNKxjKqq2WTTVH106czIb6uMFfNeQrV5FQBt0al7Im6eRd62QD7WeL8ZvZBFtmgYeg +fuf2KAMfguDqjjvx5E48ZfgEHiC4iQcpBGdVloD9OU7j6XFSITmZRLLBvOPORo1NE+k mxU1mt06Fbr3ptMcwMItjy47gs6IrkzvdfZB/Rqq3s1C92rlR/p0tzTiw8DQG8GmMB7J nJUjiZiUp4DRLYmGNpE2ZHPgGO7UhR52MFFOvMtErIcibjh1v4XB+bIZjAygFcb3vJ8V ybzw== X-Gm-Message-State: AHQUAuY9q7GFiamOkBBWDxbDcv39mYpG4emyXjJIYxQWO5rocAHbMzWY CWVfeuDYPgysPsIRcU5BHoA= X-Google-Smtp-Source: AHgI3IZ/RPHKRdxXyeW3hZcrYnIrxYmL68CCdG6zaFuCS7MDWbDLAnyduUADh6aErttEfUyp1rRa/Q== X-Received: by 2002:a2e:2416:: with SMTP id k22-v6mr5219572ljk.80.1549793706301; Sun, 10 Feb 2019 02:15:06 -0800 (PST) Received: from bard.ponomarevs.fi (88-112-122-53.elisa-laajakaista.fi. [88.112.122.53]) by smtp.gmail.com with ESMTPSA id l21-v6sm1472010ljj.48.2019.02.10.02.15.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 02:15:05 -0800 (PST) From: Nikolai Kondrashov To: Benjamin Tissoires Cc: Jiri Kosina , linux-input@vger.kernel.org, Nikolai Kondrashov Subject: [PATCH v2 18/23] HID: uclogic: Support Gray-coded rotary encoders Date: Sun, 10 Feb 2019 12:14:04 +0200 Message-Id: <20190210101409.3511-19-spbnick@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210101409.3511-1-spbnick@gmail.com> References: <20181227171625.11164-1-spbnick@gmail.com> <20190210101409.3511-1-spbnick@gmail.com> 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 Add support for converting Gray-coded rotary encoder input into dial input compatible with HID standard. Needed for Ugee G5 support. Signed-off-by: Nikolai Kondrashov --- drivers/hid/hid-uclogic-core.c | 29 +++++++++++++++++++++++++++++ drivers/hid/hid-uclogic-params.h | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index f5fb612daa1e..dfacb04308b1 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -37,6 +37,8 @@ struct uclogic_drvdata { struct input_dev *pen_input; /* In-range timer */ struct timer_list inrange_timer; + /* Last rotary encoder state, or U8_MAX for none */ + u8 re_state; }; /** @@ -175,6 +177,7 @@ static int uclogic_probe(struct hid_device *hdev, goto failure; } timer_setup(&drvdata->inrange_timer, uclogic_inrange_timeout, 0); + drvdata->re_state = U8_MAX; hid_set_drvdata(hdev, drvdata); /* Initialize the device and retrieve interface parameters */ @@ -308,6 +311,32 @@ static int uclogic_raw_event(struct hid_device *hdev, params->frame.dev_id_byte < size) { data[params->frame.dev_id_byte] = 0xf; } + /* If need to, and can, read rotary encoder state change */ + if (params->frame.re_lsb > 0 && + params->frame.re_lsb / 8 < size) { + unsigned int byte = params->frame.re_lsb / 8; + unsigned int bit = params->frame.re_lsb % 8; + + u8 change; + u8 prev_state = drvdata->re_state; + /* Read Gray-coded state */ + u8 state = (data[byte] >> bit) & 0x3; + /* Encode state change into 2-bit signed integer */ + if ((prev_state == 1 && state == 0) || + (prev_state == 2 && state == 3)) { + change = 1; + } else if ((prev_state == 2 && state == 0) || + (prev_state == 1 && state == 3)) { + change = 3; + } else { + change = 0; + } + /* Write change */ + data[byte] = (data[byte] & ~((u8)3 << bit)) | + (change << bit); + /* Remember state */ + drvdata->re_state = state; + } } return 0; diff --git a/drivers/hid/hid-uclogic-params.h b/drivers/hid/hid-uclogic-params.h index 4ba6ecc2b8b8..ba48b1c7a0e5 100644 --- a/drivers/hid/hid-uclogic-params.h +++ b/drivers/hid/hid-uclogic-params.h @@ -87,6 +87,12 @@ struct uclogic_params_frame { * Report ID, if reports should be tweaked, zero if not. */ unsigned int id; + /* + * Number of the least-significant bit of the 2-bit state of a rotary + * encoder, in the report. Cannot point to a 2-bit field crossing a + * byte boundary. Zero if not present. Only valid if "id" is not zero. + */ + unsigned int re_lsb; /* * Offset of the Wacom-style device ID byte in the report, to be set * to pad device ID (0xf), for compatibility with Wacom drivers. Zero @@ -168,6 +174,7 @@ extern int uclogic_params_init(struct uclogic_params *params, ".frame.desc_ptr = %p\n" \ ".frame.desc_size = %u\n" \ ".frame.id = %u\n" \ + ".frame.re_lsb = %u\n" \ ".frame.dev_id_byte = %u\n" \ ".pen_frame_flag = 0x%02x\n" @@ -185,6 +192,7 @@ extern int uclogic_params_init(struct uclogic_params *params, (_params)->frame.desc_ptr, \ (_params)->frame.desc_size, \ (_params)->frame.id, \ + (_params)->frame.re_lsb, \ (_params)->frame.dev_id_byte, \ (_params)->pen_frame_flag