From patchwork Fri Sep 13 22:03:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11145367 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54D891395 for ; Fri, 13 Sep 2019 22:03:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C292206A5 for ; Fri, 13 Sep 2019 22:03:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P4dhKWyP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389689AbfIMWDW (ORCPT ); Fri, 13 Sep 2019 18:03:22 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39219 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389617AbfIMWDW (ORCPT ); Fri, 13 Sep 2019 18:03:22 -0400 Received: by mail-pf1-f196.google.com with SMTP id i1so10073678pfa.6 for ; Fri, 13 Sep 2019 15:03:21 -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:mime-version :content-transfer-encoding; bh=25qzplbXApZnP+DKOlWLX+iTXkqbrEK2FpGiW9vlz0c=; b=P4dhKWyP4Ub/MZ6AMjDsPu+4zpjqVjT5+JSJvszkLnyJkhnTrKAvWBbD6wZ8exTXmo B+5l22PlldcHjMBnQWB/mDb/xj+p+hpHx91A9h0RsvI9KUVmPgzWrlQEDFnTFWWv3xzb RQyZVEjJNoL+QwHQ8/dWtl55tNjy7n4XIuRAc= 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:mime-version :content-transfer-encoding; bh=25qzplbXApZnP+DKOlWLX+iTXkqbrEK2FpGiW9vlz0c=; b=RvJ7aG1vMQHM+lcchjUW5/CMyOFqKrZ8V3vxLvFlxm2dH5xKPV/tUNqjerPYbGqjpw bTHlWbP50Eo83RkIrre8/Sh7a9AzZNtNW+t3ln0em1K3AAkeq1UI2Y1zxhfpkbCUrvt6 gZbIjtMhRSDC/I/DKvl3FDxIiBdb8CROZ8kzsorWioKl5dYubjWIsXoaCitDLqEuJTiz 67lSV+I4stF6YFv2GY9QT5ZK/auUD/GcHM6L9o7Iej7zXbquz+wQy26nAFRzeu11qNxC aBxaq1xsLVjnBZ+1SNyEMLvVxuUWTG94hyZpvCN67J6wEtUtZFaxE8WSVgZpYTYoPSOQ 5vSg== X-Gm-Message-State: APjAAAUVyBOgjqQkJc1K9p9/0KXh+Cvgu3UwvaklquiK2OzpbLbish+2 IE/pJXMkVRPVez3cVMlS36L73g== X-Google-Smtp-Source: APXvYqyYA+41djJA2irqj5wpO7M+ULzOQnTc8ElqcWKy1Ruq7000CypPFM4TDB2HUSKSTm1A9MSd3Q== X-Received: by 2002:a62:780c:: with SMTP id t12mr57332149pfc.211.1568412201427; Fri, 13 Sep 2019 15:03:21 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id o19sm2524486pjr.23.2019.09.13.15.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2019 15:03:20 -0700 (PDT) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires Cc: Nicolas Boichat , Benson Leung , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] HID: google: whiskers: more robust tablet mode detection Date: Fri, 13 Sep 2019 15:03:15 -0700 Message-Id: <20190913220317.58289-1-dtor@chromium.org> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The USB interface may get detected before the platform/EC one, so let's note the state of the base (if we receive event) and use it to correctly initialize the tablet mode switch state. Also let's start the HID interface immediately when probing, this will ensure that we correctly process "base folded" events that may be sent as we initialize the base. Note that this requires us to add a release() function where we stop and close the hardware and switch the LED registration away from devm interface as we need to make sure that we destroy the LED instance before we stop the hardware. Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-hammer.c | 71 ++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 84f8c127ebdc..4f64f93ddfcb 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -35,6 +35,7 @@ struct cbas_ec { struct device *dev; /* The platform device (EC) */ struct input_dev *input; bool base_present; + bool base_folded; struct notifier_block notifier; }; @@ -208,7 +209,14 @@ static int __cbas_ec_probe(struct platform_device *pdev) return error; } - input_report_switch(input, SW_TABLET_MODE, !cbas_ec.base_present); + if (!cbas_ec.base_present) + cbas_ec.base_folded = false; + + dev_dbg(&pdev->dev, "%s: base: %d, folded: %d\n", __func__, + cbas_ec.base_present, cbas_ec.base_folded); + + input_report_switch(input, SW_TABLET_MODE, + !cbas_ec.base_present || cbas_ec.base_folded); cbas_ec_set_input(input); @@ -322,10 +330,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, static int hammer_register_leds(struct hid_device *hdev) { struct hammer_kbd_leds *kbd_backlight; + int error; - kbd_backlight = devm_kzalloc(&hdev->dev, - sizeof(*kbd_backlight), - GFP_KERNEL); + kbd_backlight = kzalloc(sizeof(*kbd_backlight), GFP_KERNEL); if (!kbd_backlight) return -ENOMEM; @@ -339,7 +346,26 @@ static int hammer_register_leds(struct hid_device *hdev) /* Set backlight to 0% initially. */ hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0); - return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev); + error = led_classdev_register(&hdev->dev, &kbd_backlight->cdev); + if (error) + goto err_free_mem; + + hid_set_drvdata(hdev, kbd_backlight); + return 0; + +err_free_mem: + kfree(kbd_backlight); + return error; +} + +static void hammer_unregister_leds(struct hid_device *hdev) +{ + struct hammer_kbd_leds *kbd_backlight = hid_get_drvdata(hdev); + + if (kbd_backlight) { + led_classdev_unregister(&kbd_backlight->cdev); + kfree(kbd_backlight); + } } #define HID_UP_GOOGLEVENDOR 0xffd10000 @@ -376,8 +402,9 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field, usage->hid == WHISKERS_KBD_FOLDED) { spin_lock_irqsave(&cbas_ec_lock, flags); + cbas_ec.base_folded = value; hid_dbg(hid, "%s: base: %d, folded: %d\n", __func__, - cbas_ec.base_present, value); + cbas_ec.base_present, cbas_ec.base_folded); /* * We should not get event if base is detached, but in case @@ -436,6 +463,14 @@ static int hammer_probe(struct hid_device *hdev, { int error; + error = hid_parse(hdev); + if (error) + return error; + + error = hid_hw_start(hdev, HID_CONNECT_DEFAULT); + if (error) + return error; + /* * We always want to poll for, and handle tablet mode events from * Whiskers, even when nobody has opened the input device. This also @@ -443,16 +478,12 @@ static int hammer_probe(struct hid_device *hdev, * the device. */ if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - hammer_is_keyboard_interface(hdev)) + hammer_is_keyboard_interface(hdev)) { hdev->quirks |= HID_QUIRK_ALWAYS_POLL; - - error = hid_parse(hdev); - if (error) - return error; - - error = hid_hw_start(hdev, HID_CONNECT_DEFAULT); - if (error) - return error; + error = hid_hw_open(hdev); + if (error) + return error; + } if (hammer_has_backlight_control(hdev)) { error = hammer_register_leds(hdev); @@ -465,6 +496,15 @@ static int hammer_probe(struct hid_device *hdev, return 0; } +static void hammer_remove(struct hid_device *hdev) +{ + if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && + hammer_is_keyboard_interface(hdev)) + hid_hw_close(hdev); + + hammer_unregister_leds(hdev); + hid_hw_stop(hdev); +} static const struct hid_device_id hammer_devices[] = { { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, @@ -483,6 +523,7 @@ static struct hid_driver hammer_driver = { .name = "hammer", .id_table = hammer_devices, .probe = hammer_probe, + .remove = hammer_remove, .input_mapping = hammer_input_mapping, .event = hammer_event, }; From patchwork Fri Sep 13 22:03:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11145371 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DDE5912 for ; Fri, 13 Sep 2019 22:03:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34A09206A5 for ; Fri, 13 Sep 2019 22:03:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZKFaxzvW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403794AbfIMWDX (ORCPT ); Fri, 13 Sep 2019 18:03:23 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37025 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389815AbfIMWDX (ORCPT ); Fri, 13 Sep 2019 18:03:23 -0400 Received: by mail-pf1-f196.google.com with SMTP id y5so16165267pfo.4 for ; Fri, 13 Sep 2019 15:03:22 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=5OuUUYePxpHluCqMl7cvfllWii8PgjzTxgE9+4rxXRM=; b=ZKFaxzvWbhRmu4uN/9qxncrxzMsoDyXA3zns7wrGS75pXmzy0AKIHEhTb5ikpfucyR c3XuA4tHbMivSmlOavtBIf/v8rQxgAgkdlQXPCd4heteRYJHEATd/4UlHvGJTngZjT87 mZw6Po9kl50Ad/koB+J1mrjckoQCmoJ/0yadY= 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=5OuUUYePxpHluCqMl7cvfllWii8PgjzTxgE9+4rxXRM=; b=mNPiZfOIl4n1baiyrwcc3u0uX8aIsPdoYloCvGihZTys2xEzr5syIMSD8EaoPsItN0 3xH3sGCkNPUqadqmqqM5xnuWByUkVg3rba1M0RJVP4o2V8lsuktHzf7UcPFeLn2seBvT GxybyDKv+tk/AXuCCJUD8O+WNK5ZWpbdcUW/kqBwGqgrxmTtvDc3zBUUr4c5lEh1VGNp rVORCVekMmHrQTGFht+eN6kbQfMFUVOp+4DuG69nGtsfa2mYrNbNRAznnBdI7dyodFsn 7A7LCzmhzZZ659AiuYDoS2B0TDeT8wOJu5YZWcuCol1ElHNLbz1Aqgu2QpU8a9N1Vjha Vhmg== X-Gm-Message-State: APjAAAVECN38P7OjowMttQZres8a9xdpR55M/PicHx/P1PBDE9GaRdYu sXknXJMi1q+d+4aY9F4bnhw6IA== X-Google-Smtp-Source: APXvYqzKmKHK77rdEuBzDi0l1gLCv207/3lzWYVAdIll1ShglSz2Vkv1JOJ6nXMEhcOaN+r8ppGAtw== X-Received: by 2002:a63:29c7:: with SMTP id p190mr9445210pgp.124.1568412202462; Fri, 13 Sep 2019 15:03:22 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id o19sm2524486pjr.23.2019.09.13.15.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2019 15:03:21 -0700 (PDT) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires Cc: Nicolas Boichat , Benson Leung , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] HID: google: whiskers: signal tablet mode switch on disconnect Date: Fri, 13 Sep 2019 15:03:16 -0700 Message-Id: <20190913220317.58289-2-dtor@chromium.org> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190913220317.58289-1-dtor@chromium.org> References: <20190913220317.58289-1-dtor@chromium.org> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Currently, the tablet mode switch that takes two signals as its input: base attached switch from the EC and some GMR signal from whiskers when it's folded over. This tablet mode switch is then sent to Chrome, which changes the UI. However, there are some units which have a lot of leakage on the ADC pins that the EC uses to determine whether or not a base is attached. This can result in the base being physically detached, but the EC thinking that it's still attached. The user would then be stuck in laptop mode and wouldn't be able to rotate their display. To work around this let's send "tablet mode" signal when we remove HID interface, which normally happens when we physically disconnect whiskers. Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-hammer.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 4f64f93ddfcb..3dc6116c8f76 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -498,11 +498,33 @@ static int hammer_probe(struct hid_device *hdev, static void hammer_remove(struct hid_device *hdev) { + unsigned long flags; + if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - hammer_is_keyboard_interface(hdev)) + hammer_is_keyboard_interface(hdev)) { hid_hw_close(hdev); + /* + * If we are disconnecting then most likely Whiskers is + * being removed. Even if it is not removed, without proper + * keyboard we should not stay in clamshell mode. + * + * The reason for doing it here and not waiting for signal + * from EC, is that on some devices there are high leakage + * on Whiskers pins and we do not detect disconnect reliably, + * resulting in devices being stuck in clamshell mode. + */ + spin_lock_irqsave(&cbas_ec_lock, flags); + if (cbas_ec.input && cbas_ec.base_present) { + input_report_switch(cbas_ec.input, SW_TABLET_MODE, 1); + input_sync(cbas_ec.input); + } + cbas_ec.base_present = false; + spin_unlock_irqrestore(&cbas_ec_lock, flags); + } + hammer_unregister_leds(hdev); + hid_hw_stop(hdev); } From patchwork Fri Sep 13 22:03:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 11145369 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 590D31395 for ; Fri, 13 Sep 2019 22:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39211206A5 for ; Fri, 13 Sep 2019 22:03:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="a16SB8y7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403962AbfIMWD2 (ORCPT ); Fri, 13 Sep 2019 18:03:28 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34674 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390504AbfIMWDY (ORCPT ); Fri, 13 Sep 2019 18:03:24 -0400 Received: by mail-pg1-f194.google.com with SMTP id n9so15972019pgc.1 for ; Fri, 13 Sep 2019 15:03:24 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=peRAbMQ2xKT0fFJ89FYNdeBR3nBllTZJZRN8uGrtZQY=; b=a16SB8y7DtHAZOq5Hes9SBNTETQkEg+2M16auoZs6P5Nx+GDEkq6hcyakn5++4DdcB xuotJ1/LBSLQ6/x9i8PSx9EORvkMkkcAslecx1PEO2e932P8IGbrvFqJcEOscwYd0Qjl JGGr1z03FZH0C+mmPO4aH9P6LGbCOROUFsGTs= 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=peRAbMQ2xKT0fFJ89FYNdeBR3nBllTZJZRN8uGrtZQY=; b=r74sN/6m3hI+kSUz/c+Dcmu5Rv39lGiaoVC6OLTptEd+ZJzmNvIfomOl5N+g6PsH/d efi/K8CXb96C5+zWN3sczkNz61RHz0vyZNv1RF9pfa3uha26nnGqBX4oOLBFf9sP2+pp krtXTqgKoBCTnjV2WqHcAYkJR+PmvubRyWrL9VRmBaWXy11S486SThkgQNFKBhNg0vBR 2CF1rp5g+O0j0VX9Omd2iqW47GSeV2UFqtc0Ok9pjs1qea2hYwgizvBNa3qmBop4D0df jhheXSSX2/JVNw8DJZWtkdbP5nyJyxS11JMt448reep9FiH3T8KM9BwacKRuy9JYvhmY CFMw== X-Gm-Message-State: APjAAAVzVwLvJDre2tblmJw8Org8dzlDMHyJQoz1qSGgCKkOdFpG+76v q5bujRQsvUsMH5ZFEUUB+k/6Uw== X-Google-Smtp-Source: APXvYqyKIbWs4Y3boyjYAXcLk2CgyMhKDAHsPob+taOZvGOpsX89CxIujHHpsDtA4DxKLQQ7FYVN9Q== X-Received: by 2002:a63:c149:: with SMTP id p9mr11350330pgi.50.1568412203692; Fri, 13 Sep 2019 15:03:23 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id o19sm2524486pjr.23.2019.09.13.15.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2019 15:03:22 -0700 (PDT) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires Cc: Nicolas Boichat , Benson Leung , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] HID: google: whiskers: signal tablet mode on connect Date: Fri, 13 Sep 2019 15:03:17 -0700 Message-Id: <20190913220317.58289-3-dtor@chromium.org> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190913220317.58289-1-dtor@chromium.org> References: <20190913220317.58289-1-dtor@chromium.org> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org When we receive "keyboard position" event from Whiskers we can conclude that the base is attached, even if we did not get EC event for that. We may miss EC event because there are some units which have a lot of leakage on the ADC pins that the EC uses to determine whether or not a base is attached. Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-hammer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 3dc6116c8f76..31e4a39946f5 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -402,16 +402,16 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field, usage->hid == WHISKERS_KBD_FOLDED) { spin_lock_irqsave(&cbas_ec_lock, flags); + /* + * If we are getting events from Whiskers that means that it + * is attached to the lid. + */ + cbas_ec.base_present = true; cbas_ec.base_folded = value; hid_dbg(hid, "%s: base: %d, folded: %d\n", __func__, cbas_ec.base_present, cbas_ec.base_folded); - /* - * We should not get event if base is detached, but in case - * we happen to service HID and EC notifications out of order - * let's still check the "base present" flag. - */ - if (cbas_ec.input && cbas_ec.base_present) { + if (cbas_ec.input) { input_report_switch(cbas_ec.input, SW_TABLET_MODE, value); input_sync(cbas_ec.input);