Received: by 10.223.176.46 with SMTP id f43csp250163wra; Thu, 18 Jan 2018 16:51:08 -0800 (PST) X-Google-Smtp-Source: ACJfBotfATe8NyVpe8dQq/T+dSLWsgUU2czKnYbp/9XkHIs3+NrL9IzUByu9vD8aM6gipxZVv61Q X-Received: by 10.98.210.5 with SMTP id c5mr37306164pfg.238.1516323068144; Thu, 18 Jan 2018 16:51:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516323068; cv=none; d=google.com; s=arc-20160816; b=g5ZrphSPiA4ULAfj9b8P3rGG4yIwi0ZIJxlELSGWAb6Yv6ZfPAxWZtC1hhae1m5kZy 8aTvWEqwnCmRaKEAgCwiPGogriv7+Jigb3wQG6N1CY00b5b3VXqAHmgjuI8Cs+tteOTH ZMYElIL1knetQ8kTQvJqGEg/OZ/bizUTJ2VUhcbx5VdGzsbTzGMdu/eGSVfoxMd4A7zf TWPK5DcvcNO+Gk4wjgPewmyu4ik0/IpsYnMEpKrPA0zKNgZdTQJbeyAQIvZO+212dIKQ exa+9cVHNWbBLOZfjRUaSkoII/5BL1N/+dWaazgK3jhYjwRpJ+k1VR1SWV6so16mOYps 9SQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=bgmq/sRiSTX4Dzt3xaNTeggWMj29BSA+Ec5sMq6OwO0=; b=SmX6QBU8OiC4IHnquiYauyl5ntPmoaL5HUrys6FnXdE+ynQlmV0RkUPppe7WXNczZQ aJEfT+M2isSQoEpATDQwQxaqZVOHScsge6KCQRFeiNmez6sdyqXPQfGXzB04QlE//fua w4QWyZoNZsVWJf1tkn+JLkX/tmlUH6UoIUpegpgD0IdFJc+DjuzSCViE9CaOlBe7ocQT 1Iw0VcsLAMZFj+diOm0clyCmI66D2n/P1SHAEYFvOLuYUTvgVkehzSKrfkbe7xdzOjIt q8FEV/qEQbPkkOQ6xztNpvanR87cMsNLXFSkmCio8+gaAGGaakZsoIukysBuO2xMT3ua 3EkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aG4xu9Qw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n28si8011936pfg.103.2018.01.18.16.50.54; Thu, 18 Jan 2018 16:51:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aG4xu9Qw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755363AbeASAuX (ORCPT + 99 others); Thu, 18 Jan 2018 19:50:23 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:47047 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754976AbeASAuC (ORCPT ); Thu, 18 Jan 2018 19:50:02 -0500 Received: by mail-pf0-f195.google.com with SMTP id y5so62791pff.13; Thu, 18 Jan 2018 16:50:02 -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; bh=bgmq/sRiSTX4Dzt3xaNTeggWMj29BSA+Ec5sMq6OwO0=; b=aG4xu9QwacqbuUZtqZXConDwj4ZKRrC4fTipVx9NE00eTJ/mAEEsojL+OHkTq41iwp Yup6kkLwReV00tyPlPVGwNUD4Vl1W+vhZyX1fz/9wocIX4BNaIym22NDEpiyM1SE40t2 1984aUIC1HkpndDj/svKqde1bTxIJJdehNQ4AlGEL/+mj7hl7Dq5Bh00lzRWE42nOx99 mq5Ikr7us8M6V0CBzfg6mrnte9zG5n10bD5v8XAUujgz1UEJKjQetK1GSEvug/+fUUDP +WpI8MZRMhm7B11FCGsFe6WFyTbrKzHTbm+ru8feLDWUjxFT3a1f6Qxa7gfCdrur6knd /7YQ== 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; bh=bgmq/sRiSTX4Dzt3xaNTeggWMj29BSA+Ec5sMq6OwO0=; b=YjL27IV8AM7m2+zwPKIRSaS22Ufx0yRxmlUX9L3/9bufM7J6wvJIyXJT8HqY6gob0O rUYUx3X5hMOZG26A8pAFdJxTPorBJD/Sp9r9jsyEi9eIIzVMcDK/2XdCuJS0RA7u18Sa iEE85NH4uHPuAuaZsoSgVGPQGduF5xYHvPPubGzpdy54N9RWmWMjZJMDnv+sM8P4jVBM 7xkqqgkwdeBeuYBSvROGNLeYSyfY4FQo1p8GPntZOwqB1/LzGzNf9ITABtvZ6zHAzELH wr2uf7aXJfEEWeYfTfKin5fvemHFznU18u14OtvfwiFCY1S/qp0bFKucSUOT6TURp6Az kjCQ== X-Gm-Message-State: AKwxytecw3Kn/YmK6X07BXeIa1u299cVkmJAxQ3GoQMzWmcaqLG8Ylp9 8i+rx/+beDSmIZg8vcH5yCE= X-Received: by 2002:a17:902:d807:: with SMTP id a7-v6mr678468plz.334.1516323001393; Thu, 18 Jan 2018 16:50:01 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id t80sm12540937pgb.88.2018.01.18.16.49.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 16:49:59 -0800 (PST) From: Dmitry Torokhov To: Benjamin Tissoires , Lyude Paul , Damjan Georgievski Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Duggan , stable@vger.kernel.org Subject: [PATCH 2/3] Input: synaptics_rmi4 - unmask F03 interrupts when port is opened Date: Thu, 18 Jan 2018 16:49:54 -0800 Message-Id: <20180119004955.247190-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180119004955.247190-1-dmitry.torokhov@gmail.com> References: <20180119004955.247190-1-dmitry.torokhov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we register the pass-through serio port when we probe the F03 RMI function, and then, in sensor configure phase, we unmask interrupts. Unfortunately this is too late, as other drivers are free probe devices attached to the serio port as soon as it is probed. Because interrupts are masked, the IO times out, which may result in not being able to detect trackpoints on the pass-through port. To fix the issue we implement open() and close() methods for the pass-through serio port and unmask interrupts from there. We also move creation of the pass-through port form probe to configure stage, as RMI driver does not enable transport interrupt until all functions are probed (we should change this, but this is a separate topic). We also try to clear the pending data before unmasking interrupts, because some devices like to spam the system with multiple 0xaa 0x00 announcements, which may interfere with us trying to query ID of the device. Fixes: c5e8848fc98e ("Input: synaptics-rmi4 - add support for F03") Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f03.c | 64 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/drivers/input/rmi4/rmi_f03.c b/drivers/input/rmi4/rmi_f03.c index ad71a5e768dc4..7ccbb370a9a81 100644 --- a/drivers/input/rmi4/rmi_f03.c +++ b/drivers/input/rmi4/rmi_f03.c @@ -32,6 +32,7 @@ struct f03_data { struct rmi_function *fn; struct serio *serio; + bool serio_registered; unsigned int overwrite_buttons; @@ -138,6 +139,37 @@ static int rmi_f03_initialize(struct f03_data *f03) return 0; } +static int rmi_f03_pt_open(struct serio *serio) +{ + struct f03_data *f03 = serio->port_data; + struct rmi_function *fn = f03->fn; + const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE; + const u16 data_addr = fn->fd.data_base_addr + RMI_F03_OB_OFFSET; + u8 obs[RMI_F03_QUEUE_LENGTH * RMI_F03_OB_SIZE]; + int error; + + /* + * Consume any pending data. Some devices like to spam with + * 0xaa 0x00 announcements which may confuse us as we try to + * probe the device. + */ + error = rmi_read_block(fn->rmi_dev, data_addr, &obs, ob_len); + if (!error) + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "%s: Consumed %*ph (%d) from PS2 guest\n", + __func__, ob_len, obs, ob_len); + + return fn->rmi_dev->driver->set_irq_bits(fn->rmi_dev, fn->irq_mask); +} + +static void rmi_f03_pt_close(struct serio *serio) +{ + struct f03_data *f03 = serio->port_data; + struct rmi_function *fn = f03->fn; + + fn->rmi_dev->driver->clear_irq_bits(fn->rmi_dev, fn->irq_mask); +} + static int rmi_f03_register_pt(struct f03_data *f03) { struct serio *serio; @@ -148,6 +180,8 @@ static int rmi_f03_register_pt(struct f03_data *f03) serio->id.type = SERIO_PS_PSTHRU; serio->write = rmi_f03_pt_write; + serio->open = rmi_f03_pt_open; + serio->close = rmi_f03_pt_close; serio->port_data = f03; strlcpy(serio->name, "Synaptics RMI4 PS/2 pass-through", @@ -184,17 +218,27 @@ static int rmi_f03_probe(struct rmi_function *fn) f03->device_count); dev_set_drvdata(dev, f03); - - error = rmi_f03_register_pt(f03); - if (error) - return error; - return 0; } static int rmi_f03_config(struct rmi_function *fn) { - fn->rmi_dev->driver->set_irq_bits(fn->rmi_dev, fn->irq_mask); + struct f03_data *f03 = dev_get_drvdata(&fn->dev); + int error; + + if (!f03->serio_registered) { + error = rmi_f03_register_pt(f03); + if (error) + return error; + + f03->serio_registered = true; + } else { + /* + * We must be re-configuring the sensor, just enable + * interrupts for this function. + */ + fn->rmi_dev->driver->set_irq_bits(fn->rmi_dev, fn->irq_mask); + } return 0; } @@ -204,7 +248,7 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits) struct rmi_device *rmi_dev = fn->rmi_dev; struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); struct f03_data *f03 = dev_get_drvdata(&fn->dev); - u16 data_addr = fn->fd.data_base_addr; + const u16 data_addr = fn->fd.data_base_addr + RMI_F03_OB_OFFSET; const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE; u8 obs[RMI_F03_QUEUE_LENGTH * RMI_F03_OB_SIZE]; u8 ob_status; @@ -226,8 +270,7 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits) drvdata->attn_data.size -= ob_len; } else { /* Grab all of the data registers, and check them for data */ - error = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET, - &obs, ob_len); + error = rmi_read_block(fn->rmi_dev, data_addr, &obs, ob_len); if (error) { dev_err(&fn->dev, "%s: Failed to read F03 output buffers: %d\n", @@ -266,7 +309,8 @@ static void rmi_f03_remove(struct rmi_function *fn) { struct f03_data *f03 = dev_get_drvdata(&fn->dev); - serio_unregister_port(f03->serio); + if (f03->serio_registered) + serio_unregister_port(f03->serio); } struct rmi_function_handler rmi_f03_handler = { -- 2.16.0.rc1.238.g530d649a79-goog