From patchwork Tue Jan 29 04:23:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NOGUCHI Hiroshi X-Patchwork-Id: 10785371 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 61CF2139A for ; Tue, 29 Jan 2019 04:24:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45CFB2ABC7 for ; Tue, 29 Jan 2019 04:24:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C212AC00; Tue, 29 Jan 2019 04:24:56 +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 1A8462ABC7 for ; Tue, 29 Jan 2019 04:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfA2EYy (ORCPT ); Mon, 28 Jan 2019 23:24:54 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35302 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbfA2EYy (ORCPT ); Mon, 28 Jan 2019 23:24:54 -0500 Received: by mail-pf1-f194.google.com with SMTP id z9so9070057pfi.2 for ; Mon, 28 Jan 2019 20:24:53 -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:mime-version :content-transfer-encoding; bh=ORFLQywu5qdfKsoBgiSFegnZKNHLiiri0ZqZHGy5cXk=; b=N21o6jsrWNWz0eorZUCfTsk7E2arHl3uaxZlQZNb9Hrix4drVNhdQJFd3hTnCmMkMA 9I2LHCey8mm4XSla5KpulLl1+A96DrqYhb0qwZ0sRtLXi4cPsANU3nQAHl4NZltGOXSi gLab6W7DxiJGBuX/HV6UDz5VFVs94YAa1v8CDFxC9yaavhovFOwEUUhSqTdX2IwtgSxj +prNN1CNqTfw33BntsuVBu8CiF2xiUJNCM/klLNIHqakNuL2oO9PByO/TYfaUVL3HHua OnAzpXJcZ4r4zvY18r+newh83EhlKFXI4h4WB/+VTf0VDPom0Om9A0p5h/BMSVQN4jMc fFbg== 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=ORFLQywu5qdfKsoBgiSFegnZKNHLiiri0ZqZHGy5cXk=; b=qcaE8gM7bLnoNvQDdBXX9DDUMEutL8IhKfML7jRzM4aC1tKuW7YBbhTL21TaGQoXZq pYgq1mK0XzslpakVGYCMTF8eoAdOryW7YdOqFb0DhazcWqGoiQRizR1rwQy/N7RZsl+i 0mmBrCmYOhWyk5K5dlZVm1AAtbHoD1weDPQRUr1Bv3jFycjTYIbODYxcsSIJZByv4b7t xwCupC2Yv2QvMfNNcLLPt78OJEi6tERDiqVmK88I+J3d1Axj6vBMWdNGyJrQo5rswz6p P9TFMpsFBVkSGohUu4Grw0YMjBnI4qltX+eAtaqyUiRAz7cQhhyK5fbbgQNlnLambptk zxbw== X-Gm-Message-State: AJcUukdyACH5Uyh3BGrrCmUcQMBZtYFCAZsbbNmaabYnMVAbEzSYU8sD cZPJoaUwybMYg6xrAQnIcknZVRlF X-Google-Smtp-Source: ALg8bN4BCpDiMdOczPQDka0hfHgnWwz/r8+pttCRyhxV5C81tRRK8pUYr/MQ4Oc2Iuu7aZJn92x12A== X-Received: by 2002:a62:b80a:: with SMTP id p10mr24480082pfe.32.1548735892943; Mon, 28 Jan 2019 20:24:52 -0800 (PST) Received: from localhost.localdomain (32.236.69.115.shared.user.transix.jp. [115.69.236.32]) by smtp.gmail.com with ESMTPSA id r130sm52192650pfr.48.2019.01.28.20.24.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 20:24:52 -0800 (PST) From: NOGUCHI Hiroshi To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, NOGUCHI Hiroshi Subject: [PATCH 1/3] HID: hid-asus Transbook T90CHI support Date: Tue, 29 Jan 2019 13:23:20 +0900 Message-Id: <20190129042322.13168-1-drvlabo@gmail.com> X-Mailer: git-send-email 2.20.1 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 Transbook T90CHI support into hid-asus. T90CHI returns same BT vendor/product values as T100CHI, so identifies T90CHI by name. Signed-off-by: NOGUCHI Hiroshi --- drivers/hid/hid-asus.c | 54 +++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 951bb17ae8b2..c7b4638cdeb1 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -71,6 +71,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define QUIRK_T100CHI BIT(7) #define QUIRK_G752_KEYBOARD BIT(8) #define QUIRK_T101HA_DOCK BIT(9) +#define QUIRK_T90CHI BIT(10) #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \ @@ -500,7 +501,7 @@ static int asus_input_mapping(struct hid_device *hdev, * This avoids a bunch of non-functional hid_input devices getting * created because of the T100CHI using HID_QUIRK_MULTI_INPUT. */ - if (drvdata->quirks & QUIRK_T100CHI) { + if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { if (field->application == (HID_UP_GENDESK | 0x0080) || usage->hid == (HID_UP_GENDEVCTRLS | 0x0024) || usage->hid == (HID_UP_GENDEVCTRLS | 0x0025) || @@ -660,6 +661,11 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) drvdata->quirks = id->driver_data; + if (strstr(hdev->name, "T90CHI")) { + drvdata->quirks &= ~QUIRK_T100CHI; + drvdata->quirks |= QUIRK_T90CHI; + } + if (drvdata->quirks & QUIRK_IS_MULTITOUCH) drvdata->tp = &asus_i2c_tp; @@ -769,28 +775,44 @@ static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, hid_info(hdev, "Fixing up Asus T100 keyb report descriptor\n"); rdesc[74] &= ~HID_MAIN_ITEM_CONSTANT; } - /* For the T100CHI keyboard dock */ - if (drvdata->quirks & QUIRK_T100CHI && - *rsize == 403 && rdesc[388] == 0x09 && rdesc[389] == 0x76) { + /* For the T100CHI/T90CHI keyboard dock */ + if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { + int rsize_orig; + int offs; + + if (drvdata->quirks & QUIRK_T100CHI) { + rsize_orig = 403; + offs = 388; + } else { + rsize_orig = 306; + offs = 291; + } + /* * Change Usage (76h) to Usage Minimum (00h), Usage Maximum * (FFh) and clear the flags in the Input() byte. * Note the descriptor has a bogus 0 byte at the end so we * only need 1 extra byte. */ - *rsize = 404; - rdesc = kmemdup(rdesc, *rsize, GFP_KERNEL); - if (!rdesc) - return NULL; - - hid_info(hdev, "Fixing up T100CHI keyb report descriptor\n"); - memmove(rdesc + 392, rdesc + 390, 12); - rdesc[388] = 0x19; - rdesc[389] = 0x00; - rdesc[390] = 0x29; - rdesc[391] = 0xff; - rdesc[402] = 0x00; + if (*rsize == rsize_orig && + rdesc[offs] == 0x09 && rdesc[offs + 1] == 0x76) { + *rsize = rsize_orig + 1; + rdesc = kmemdup(rdesc, *rsize, GFP_KERNEL); + if (!rdesc) + return NULL; + + hid_info(hdev, "Fixing up %s keyb report descriptor\n", + drvdata->quirks & QUIRK_T100CHI ? + "T100CHI" : "T90CHI"); + memmove(rdesc + offs + 4, rdesc + offs + 2, 12); + rdesc[offs] = 0x19; + rdesc[offs + 1] = 0x00; + rdesc[offs + 2] = 0x29; + rdesc[offs + 3] = 0xff; + rdesc[offs + 14] = 0x00; + } } + if (drvdata->quirks & QUIRK_G752_KEYBOARD && *rsize == 75 && rdesc[61] == 0x15 && rdesc[62] == 0x00) { /* report is missing usage mninum and maximum */ From patchwork Tue Jan 29 04:31:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NOGUCHI Hiroshi X-Patchwork-Id: 10785377 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 70AFF139A for ; Tue, 29 Jan 2019 04:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A3552B1DA for ; Tue, 29 Jan 2019 04:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E0712B1F7; Tue, 29 Jan 2019 04:31:25 +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 00A3C2B1F2 for ; Tue, 29 Jan 2019 04:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726832AbfA2EbY (ORCPT ); Mon, 28 Jan 2019 23:31:24 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38802 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726762AbfA2EbY (ORCPT ); Mon, 28 Jan 2019 23:31:24 -0500 Received: by mail-pg1-f195.google.com with SMTP id g189so8212218pgc.5 for ; Mon, 28 Jan 2019 20:31:23 -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:mime-version :content-transfer-encoding; bh=PSoOr3/jG0D09LXeiPwFFEtUwpX55tobq7JreO4yabc=; b=aacDtsVpM3kckt3fHdArexRPKjFlInPjOcIu8/5+srbhY8KOrWja5t6+wIXmLyH+hI KvGIjzVadQEY4xdf94lMGOQ0NAICtvP6UtVWnOo+WrCzni0m3eCdaFcnWvgVyorehhqq 0kYVzIUov8g4ZwAP3EOa174rhdyVEsRRmKVNQtYlOJ9uaB6GYaQnMBcFjTex11ydk8wM O7s1wcDNa6AgvZ9KXd991wdu787Zs4EJSpQv6MtSJnwuPj4sL82jlzQeEW9yEKr3WErU qI+h5s5qHngmMTTgNjS8lz6z7VH0W8s8BAcY4qABC2GDpp5Ou//3fV/3a/uKNhToZkBb g7Gw== 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=PSoOr3/jG0D09LXeiPwFFEtUwpX55tobq7JreO4yabc=; b=MmDG2QJIxBsof/SMXY0Ccca56wh/ppXYcR2MhbwBtqdhpYLoJQFRbWNmXXZbuDl8BX RSzCARA1HIoGTF0zaVokxKR6scxhw0lfvD6VCbqpl0t9AiZVscHxXMkiMaCHZnBTJ5RO Rs1wE2Bpamq9ksIGXIxle4fPgLJTj/HAD4XvaoulKtB5/nvL96oa6iUEsGlhc9vE70kg B2HopFEf9dupsE3XHgZ9snYdgGGbxVEYiiTDxbWnviK0//wCUBCdCQsOAC3JShEs/Otd oq4iv3aZWZ3I467xX9/rfaMG8aW+6gmEsL3YrTsdnTvYtMwOzWOhPZVJaZ0wgjuHy/Cg Yw4A== X-Gm-Message-State: AJcUukd1znI1zCNJH6zAovVUGYLy3m3+jSVoO1T4Ncz3zLsiiWrH5DKO tKH5QRRjvM60E6qi7hBjwan4/VIg X-Google-Smtp-Source: ALg8bN4CItQCXLVjUNUVr+i28VOT01CNhtfFNCJ0MBtwWsyvte86h6HdI2QB/hSukg5arYNQ45PckQ== X-Received: by 2002:aa7:810c:: with SMTP id b12mr24429211pfi.44.1548736283533; Mon, 28 Jan 2019 20:31:23 -0800 (PST) Received: from localhost.localdomain ([2409:251:20c0:100:fe80:8e59:9ae1:e028]) by smtp.gmail.com with ESMTPSA id y6sm40041937pfl.187.2019.01.28.20.31.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 20:31:23 -0800 (PST) From: NOGUCHI Hiroshi To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, NOGUCHI Hiroshi Subject: [PATCH 2/3] ASUS T100CHI keyboard dock battery quirks Date: Tue, 29 Jan 2019 13:31:05 +0900 Message-Id: <20190129043105.13251-1-drvlabo@gmail.com> X-Mailer: git-send-email 2.20.1 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 ASUS Transbook T100CHI/T90CHI keyboard dock into battery quirk list, in order to add specific implementation in hid-asus. Signed-off-by: NOGUCHI Hiroshi --- drivers/hid/hid-input.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 59a5608b8dc0..b10b1922c5bd 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -328,6 +328,9 @@ static const struct hid_device_id hid_battery_quirks[] = { { HID_USB_DEVICE(USB_VENDOR_ID_SYMBOL, USB_DEVICE_ID_SYMBOL_SCANNER_3), HID_BATTERY_QUIRK_IGNORE }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK, + USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD), + HID_BATTERY_QUIRK_IGNORE }, {} }; From patchwork Tue Jan 29 04:31:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NOGUCHI Hiroshi X-Patchwork-Id: 10785385 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 7EDB8139A for ; Tue, 29 Jan 2019 04:31:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E0F92B090 for ; Tue, 29 Jan 2019 04:31:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 629702B23E; Tue, 29 Jan 2019 04:31:51 +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 9CDF92B23A for ; Tue, 29 Jan 2019 04:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbfA2Ebs (ORCPT ); Mon, 28 Jan 2019 23:31:48 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42429 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727511AbfA2Ebr (ORCPT ); Mon, 28 Jan 2019 23:31:47 -0500 Received: by mail-pg1-f195.google.com with SMTP id d72so8203779pga.9 for ; Mon, 28 Jan 2019 20:31:46 -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:mime-version :content-transfer-encoding; bh=mAU5RVkp9aB5ydBjmBJbtt/IKhmLGDuzAoJFZuVzpaM=; b=MJM4g7WPmNtgukOmcFGAcxBaMATnpoYSd9QbenJptyWjK7cFxm0FXvfwfiNBrSgV/m TqJ14syUby3PCfGcJwZf7IETJfbzi6h3PvU3ohL81f78bN56oOqfifPpdZnFlWIeer3V 8Wl0QkcS9TlNe1+kN2qK43A0xAqgyWegEv55qkr7bqxY+frnQPVrnMy+NZCIWBujni5k +5+a7poqIAU8DxmLunfxDnXJu5cTABCNTILz+NNB1GC+4so3VTMxCdJVOSb0ONgSmZHq K4z0hLTcKgljMLWYnQIzPkdhdGIyYv1eOZWuxMJBUxLJy2XC5cZ4peMf7ahDZiWaDE+J V6Ng== 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=mAU5RVkp9aB5ydBjmBJbtt/IKhmLGDuzAoJFZuVzpaM=; b=STMVNNfC5p/3YUVKZ1VwmdXKCsP7CA1vLrCo+koAhLJJAjqiGQooW3rDtHFr9RNtwW IT4hGEh29MuOiGdnwwFKbzu4nm13yPV+ya7K34qg6BIKsB4Pc7NgAcz4cRrULUTOB/fh b/Ne20AEvKQEjcww5/peZOMKytCVRLwQ8qKMTjEPLgwGYdyS1hlwoxY8WkTMolK4N9qH Ab/YJwmC/zL2bhmCYOaND4zXDZSIIHZiBcwZ7N2hhAxM2SdjNi78PyR1UyffoP86cO6M u2MfaSTtVr2tjXlsV4074rHNJS9jKMz1DiJTPqkE2VzJifkJnYwwgcIny5+2GXeCuWY4 IkTw== X-Gm-Message-State: AJcUukfCWVk0bueRLuAXMyo6i3pO8n7Bci1GpG1AINy42EQSbPpiDDDO gL+kB0T21g2JxR+/8MWANwDNq6A2 X-Google-Smtp-Source: ALg8bN5DwINF0R8sTBmFWLt8HZ3thuMCEh+BEtwjY36HNA4dUEEjrxiLmLmWlg7iWlg1cg3m/1Jauw== X-Received: by 2002:a62:1212:: with SMTP id a18mr25375964pfj.217.1548736306293; Mon, 28 Jan 2019 20:31:46 -0800 (PST) Received: from localhost.localdomain ([2409:251:20c0:100:fe80:8e59:9ae1:e028]) by smtp.gmail.com with ESMTPSA id x127sm54900165pfd.156.2019.01.28.20.31.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 20:31:45 -0800 (PST) From: NOGUCHI Hiroshi To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, NOGUCHI Hiroshi Subject: [PATCH 3/3] HID: hid-asus BT keyboard dock battery monitoring support Date: Tue, 29 Jan 2019 13:31:29 +0900 Message-Id: <20190129043129.13297-1-drvlabo@gmail.com> X-Mailer: git-send-email 2.20.1 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 battery monitoring support for Transbook T100CHI/T90CHI's Bluetooth keyboard dock. They report rest battery level and charging status. Signed-off-by: NOGUCHI Hiroshi --- drivers/hid/hid-asus.c | 193 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index c7b4638cdeb1..336aeaed1159 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -32,6 +32,7 @@ #include #include #include /* For to_usb_interface for T100 touchpad intf check */ +#include #include "hid-ids.h" @@ -61,6 +62,13 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define CONTACT_TOUCH_MAJOR_MASK 0x07 #define CONTACT_PRESSURE_MASK 0x7f +#define BATTERY_REPORT_ID (0x03) +#define BATTERY_REPORT_SIZE (1 + 8) +#define BATTERY_LEVEL_MAX ((u8)255) +#define BATTERY_STAT_DISCONNECT (0) +#define BATTERY_STAT_CHARGING (1) +#define BATTERY_STAT_FULL (2) + #define QUIRK_FIX_NOTEBOOK_REPORT BIT(0) #define QUIRK_NO_INIT_REPORTS BIT(1) #define QUIRK_SKIP_INPUT_MAPPING BIT(2) @@ -101,12 +109,21 @@ struct asus_touchpad_info { struct asus_drvdata { unsigned long quirks; + struct hid_device *hdev; struct input_dev *input; struct asus_kbd_leds *kbd_backlight; const struct asus_touchpad_info *tp; bool enable_backlight; + struct power_supply *battery; + struct power_supply_desc battery_desc; + int battery_capacity; + int battery_stat; + bool battery_in_query; + unsigned long battery_next_query; }; +static int asus_report_battery(struct asus_drvdata *, u8 *, int); + static const struct asus_touchpad_info asus_i2c_tp = { .max_x = 2794, .max_y = 1758, @@ -260,6 +277,9 @@ static int asus_raw_event(struct hid_device *hdev, { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); + if (drvdata->battery && data[0] == BATTERY_REPORT_ID) + return asus_report_battery(drvdata, data, size); + if (drvdata->tp && data[0] == INPUT_REPORT_ID) return asus_report_input(drvdata, data, size); @@ -429,6 +449,164 @@ static int asus_kbd_register_leds(struct hid_device *hdev) return ret; } +/* + * [0] REPORT_ID (same value defined in report descriptor) + * [1] rest battery level. range [0..255] + * [2]..[7] Bluetooth hardware address (MAC address) + * [8] charging status + * = 0 : AC offline / discharging + * = 1 : AC online / charging + * = 2 : AC online / fully charged + */ +static int asus_parse_battery(struct asus_drvdata *drvdata, u8 *data, int size) +{ + u8 sts; + u8 lvl; + int val; + + lvl = data[1]; + sts = data[8]; + + drvdata->battery_capacity = ((int)lvl * 100) / (int)BATTERY_LEVEL_MAX; + + switch (sts) { + case BATTERY_STAT_CHARGING: + val = POWER_SUPPLY_STATUS_CHARGING; + break; + case BATTERY_STAT_FULL: + val = POWER_SUPPLY_STATUS_FULL; + break; + case BATTERY_STAT_DISCONNECT: + default: + val = POWER_SUPPLY_STATUS_DISCHARGING; + break; + } + drvdata->battery_stat = val; + + return 0; +} + +static int asus_report_battery(struct asus_drvdata *drvdata, u8 *data, int size) +{ + /* notify only the autonomous event by device */ + if ((drvdata->battery_in_query == false) && + (size == BATTERY_REPORT_SIZE)) + power_supply_changed(drvdata->battery); + + return 0; +} + +static int asus_battery_query(struct asus_drvdata *drvdata) +{ + u8 *buf; + int ret = 0; + + buf = kmalloc(BATTERY_REPORT_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + drvdata->battery_in_query = true; + ret = hid_hw_raw_request(drvdata->hdev, BATTERY_REPORT_ID, + buf, BATTERY_REPORT_SIZE, + HID_INPUT_REPORT, HID_REQ_GET_REPORT); + drvdata->battery_in_query = false; + if (ret == BATTERY_REPORT_SIZE) + ret = asus_parse_battery(drvdata, buf, BATTERY_REPORT_SIZE); + else + ret = -ENODATA; + + kfree(buf); + + return ret; +} + +static enum power_supply_property asus_battery_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_SCOPE, + POWER_SUPPLY_PROP_MODEL_NAME, +}; + +#define QUERY_MIN_INTERVAL (60 * HZ) /* 60[sec] */ + +static int asus_battery_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct asus_drvdata *drvdata = power_supply_get_drvdata(psy); + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + case POWER_SUPPLY_PROP_CAPACITY: + if (time_before(drvdata->battery_next_query, jiffies)) { + drvdata->battery_next_query = + jiffies + QUERY_MIN_INTERVAL; + ret = asus_battery_query(drvdata); + if (ret) + return ret; + } + if (psp == POWER_SUPPLY_PROP_STATUS) + val->intval = drvdata->battery_stat; + else + val->intval = drvdata->battery_capacity; + break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = 1; + break; + case POWER_SUPPLY_PROP_SCOPE: + val->intval = POWER_SUPPLY_SCOPE_DEVICE; + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = drvdata->hdev->name; + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static int asus_battery_probe(struct hid_device *hdev) +{ + struct asus_drvdata *drvdata = hid_get_drvdata(hdev); + struct power_supply_config pscfg = { .drv_data = drvdata }; + int ret = 0; + + drvdata->battery_capacity = 0; + drvdata->battery_stat = POWER_SUPPLY_STATUS_UNKNOWN; + drvdata->battery_in_query = false; + + drvdata->battery_desc.properties = asus_battery_props; + drvdata->battery_desc.num_properties = ARRAY_SIZE(asus_battery_props); + drvdata->battery_desc.get_property = asus_battery_get_property; + drvdata->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; + drvdata->battery_desc.use_for_apm = 0; + drvdata->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, + "asus-keyboard-%s-battery", + strlen(hdev->uniq) ? + hdev->uniq : dev_name(&hdev->dev)); + if (!drvdata->battery_desc.name) + return -ENOMEM; + + drvdata->battery_next_query = jiffies; + + drvdata->battery = devm_power_supply_register(&hdev->dev, + &(drvdata->battery_desc), &pscfg); + if (IS_ERR(drvdata->battery)) { + ret = PTR_ERR(drvdata->battery); + drvdata->battery = NULL; + hid_err(hdev, "Unable to register battery device\n"); + return ret; + } + + power_supply_powers(drvdata->battery, &hdev->dev); + + return ret; +} + static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) { struct input_dev *input = hi->input; @@ -661,6 +839,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) drvdata->quirks = id->driver_data; + /* + * T90CHI's keyboard dock returns same ID values as T100CHI's dock. + * Thus, identify T90CHI dock with product name string. + */ if (strstr(hdev->name, "T90CHI")) { drvdata->quirks &= ~QUIRK_T100CHI; drvdata->quirks |= QUIRK_T90CHI; @@ -700,6 +882,17 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) if (drvdata->quirks & QUIRK_NO_INIT_REPORTS) hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; + drvdata->hdev = hdev; + + if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) { + ret = asus_battery_probe(hdev); + if (ret) { + hid_err(hdev, + "Asus hid battery_probe failed: %d\n", ret); + return ret; + } + } + ret = hid_parse(hdev); if (ret) { hid_err(hdev, "Asus hid parse failed: %d\n", ret);