Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6267888pxu; Wed, 23 Dec 2020 19:47:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwS1MydowMBt+oktt9DQNa2GYK/kA5KePhk8qd8mf8B6rrYu5lARv/Nr0JWJGhQzZIodqJJ X-Received: by 2002:a17:906:3d4a:: with SMTP id q10mr1060470ejf.85.1608781673086; Wed, 23 Dec 2020 19:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608781673; cv=none; d=google.com; s=arc-20160816; b=J+uvpw/mYzp+h3haKRchh5GOLXXR1R5nVIjW6TDMvn6cE6OXoXVoTFi0YihTYtVj7l ZvtyvZghhgf9ZG+SZiEid/xxKV7UmbR0Xl2NSTQhdKgayp0hzxzWOeg9OfUFAQAd6dDU EF61IpVDPyM29XvKixmhaQD7Y00//6NWZBsyqWbUPYLx/Vur/Gr1idlx8ao7hXhgW+Da vhA86ZIO1FE1xOjlsu0ePX2yk1IIs0QeFALrdBCxViuB8Xow7ex2pzgL+66H/W/ic/2G eSDOwKHvuN7Iqv7IZIVsDnbWn7MEzI2sDqG2OH6jA31qZTJlbmi5up9opiubFS+y+C5n 62Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZcSp+cRdP2bcqWVQZJCDIiTdhj/sfG8FWouaFgmCU4k=; b=hSHY88orCIMvVx8GJHAa55ZfsIiWNVmeUu1Aa2Va3pmtLPVioySd4m2+IgRhttNxN4 ItoDZfQM1QDVQChPlplba33gzMMceEbBNe9K9pScCgXZfmjCsxTKUaK/OSY/E1+BIdLg C34R7k1rT7ToCGPZpCXl54Sxu3mGziol31YTQzJxgi6nysaoghnXf31G67PXJyTDyEKZ lWjyBGCYs1T/weOdPRR5JfBXSH+W9fSdKJr6VPAGi1Nsj6ySex5PmNz50ngYnoIvNd78 reJ4k11NAaL6INM7b6JMr9cDJ2LRkQQbKnu7KYPMx0RFlBfDgjeLhzSXTdw+fFf9wYsc ibJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oF8LweNT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w1si1612282ejn.628.2020.12.23.19.47.19; Wed, 23 Dec 2020 19:47:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oF8LweNT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728724AbgLXDpy (ORCPT + 99 others); Wed, 23 Dec 2020 22:45:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728334AbgLXDpx (ORCPT ); Wed, 23 Dec 2020 22:45:53 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99217C061794 for ; Wed, 23 Dec 2020 19:45:13 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id f14so458279pju.4 for ; Wed, 23 Dec 2020 19:45:13 -0800 (PST) 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=ZcSp+cRdP2bcqWVQZJCDIiTdhj/sfG8FWouaFgmCU4k=; b=oF8LweNTM0O1s0jpipHfe0Skl2HB5E2BuMofWlS8SNgvnYFeOQqCMoabngGlgi9vP0 QIXvD9HulcL+AG9TpZTBjrDDGf0Bxw9ZbwxgpK7IaTrWBmEMazXhnFkhwbpIG7hEYMPX 42AXp7O7KfFL4ea41pn6PXA1ilhSzOP0IHJ0M= 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=ZcSp+cRdP2bcqWVQZJCDIiTdhj/sfG8FWouaFgmCU4k=; b=HK2UPyrNRpVqm7sDsjTjdg8XBi8eH7WoWPG8VPOFe6yrdIU0N9w87wcnGRh5ky09M6 82uLSZCE3MnehptxgdZyNYZz9QLVEp9mJwnVhmkR7kwkdAHyBKCq7iO6wo6cnj/aHX1y YqlEDhJPn8FaCElXu2GPslGE9IqW2hn9gfThj/PcbHXIy1ALTxELV+NVQKtjoBKOIUWV xIE9vUCliLKevSAtAlEhdqdCCGIIkG3/YHfcFOzumGIVONDD5fW5J68g8vR9bu3tS7l3 AGP6h2J1VW9jqBjZb6HxjtGQM94+E/dEpemArYLBlFRUgLfsagCbJHxvBLsKicuwPcz0 dDrg== X-Gm-Message-State: AOAM532OZhDn8qInJ3wk65SznXXEIEC3OjRD3q9oqhv9c3qyLrqGDoww OROmwS9wIPZscEoU/Y4PfPFdaQ== X-Received: by 2002:a17:90b:4acc:: with SMTP id mh12mr2606669pjb.54.1608781512942; Wed, 23 Dec 2020 19:45:12 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:7220:84ff:fe09:41dc]) by smtp.gmail.com with ESMTPSA id f24sm942332pjj.5.2020.12.23.19.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 19:45:12 -0800 (PST) From: Nicolas Boichat To: Benjamin Tissoires Cc: Dmitry Torokhov , Nicolas Boichat , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: google: Get HID report on probe to confirm tablet switch state Date: Thu, 24 Dec 2020 11:45:07 +0800 Message-Id: <20201224114502.1.I41b9795e4b5bda7209eb9099aebdc6a29677391e@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This forces reading the base folded status anytime the device is probed. Signed-off-by: Nicolas Boichat --- Instead of all this manual parsing, it'd be easier to just call: hid_hw_request(hdev, report, HID_REQ_GET_REPORT); However, that fails silently as hdev->driver_input_lock is held during probe (or even some callbacks like input_configured. drivers/hid/hid-google-hammer.c | 85 +++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 85a054f1ce38..d9319622da44 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -392,30 +392,34 @@ static int hammer_input_mapping(struct hid_device *hdev, struct hid_input *hi, return 0; } -static int hammer_event(struct hid_device *hid, struct hid_field *field, - struct hid_usage *usage, __s32 value) +static void hammer_folded_event(struct hid_device *hdev, bool folded) { unsigned long flags; - if (usage->hid == HID_USAGE_KBD_FOLDED) { - spin_lock_irqsave(&cbas_ec_lock, flags); + 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); - - if (cbas_ec.input) { - input_report_switch(cbas_ec.input, - SW_TABLET_MODE, value); - input_sync(cbas_ec.input); - } + /* + * 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 = folded; + hid_dbg(hdev, "%s: base: %d, folded: %d\n", __func__, + cbas_ec.base_present, cbas_ec.base_folded); - spin_unlock_irqrestore(&cbas_ec_lock, flags); + if (cbas_ec.input) { + input_report_switch(cbas_ec.input, SW_TABLET_MODE, folded); + input_sync(cbas_ec.input); + } + + spin_unlock_irqrestore(&cbas_ec_lock, flags); +} + +static int hammer_event(struct hid_device *hid, struct hid_field *field, + struct hid_usage *usage, __s32 value) +{ + if (usage->hid == HID_USAGE_KBD_FOLDED) { + hammer_folded_event(hid, value); return 1; /* We handled this event */ } @@ -457,6 +461,47 @@ static bool hammer_has_backlight_control(struct hid_device *hdev) HID_GD_KEYBOARD, HID_AD_BRIGHTNESS); } +static void hammer_get_folded_state(struct hid_device *hdev) +{ + struct hid_report *report; + char *buf; + int len, rlen; + int a; + + report = hdev->report_enum[HID_INPUT_REPORT].report_id_hash[0x0]; + + if (!report || report->maxfield < 1) + return; + + len = hid_report_len(report) + 1; + + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return; + + rlen = hid_hw_raw_request(hdev, report->id, buf, len, report->type, HID_REQ_GET_REPORT); + + if (rlen != len) { + hid_warn(hdev, "Unable to read base folded state: %d (expected %d)\n", rlen, len); + goto out; + } + + for (a = 0; a < report->maxfield; a++) { + struct hid_field *field = report->field[a]; + + if (field->usage->hid == HID_USAGE_KBD_FOLDED) { + u32 value = hid_field_extract(hdev, buf+1, + field->report_offset, field->report_size); + + hammer_folded_event(hdev, value); + break; + } + } + +out: + kfree(buf); +} + static int hammer_probe(struct hid_device *hdev, const struct hid_device_id *id) { @@ -481,6 +526,8 @@ static int hammer_probe(struct hid_device *hdev, error = hid_hw_open(hdev); if (error) return error; + + hammer_get_folded_state(hdev); } if (hammer_has_backlight_control(hdev)) { -- 2.29.2.729.g45daf8777d-goog