Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp834115pxu; Mon, 23 Nov 2020 05:28:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyg9Jm41jw4Ce1BHQEPzEjmDoO5+PAZwhGdLTEHGAu1hEW0IhzM+v6CjgfKVvJrkcv9cnT X-Received: by 2002:a17:906:6546:: with SMTP id u6mr42855829ejn.36.1606138124111; Mon, 23 Nov 2020 05:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606138124; cv=none; d=google.com; s=arc-20160816; b=xHD1fJxRYGDvo3F//ybAz4KyZ6HiCH78Pe/jbt/ckAED6SgWtWCS/CBwA5hBqy3Sfi Kk8Wuu0XXbz7xNgduvXbk1ts1TvWe9B7ZIdh1KPYwaTXrwIzqZY2UqZ8ahEd7g7EDAG5 Sgqc3CrIk2N2qcUue1iVh4R0JJNYqnBUKApsCUQ4iIpyprmkvbceoCTzqqKWFxHCE2YK 4FxmUFSnkJ1U6Yl6ofJ6wao+0VCh5uAJM2QKr8W410oQVZ0Jr26fOYKIF5F8wqUgVOQG qQk1Xj7EElxfpJ0PuIoP11dMARgKh3hV3m+JNux2xpAlsVOX8f6F7TaOkOTNm2GaOevL 4Q6g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gL4fF8LSu6jQTg7YLHjc7YWz0fxzlFA8qM9RC+2q8Bw=; b=QBa0tABKdW88qOm8J+bEhEdYWp0A0Ds/SMRtwb4P++WIMkxN8cZtoeiZKPk+Bk4vNw mE6VSZGrUzZgAcKMP8rpAm4rGw6C5V3RcsjAgxDS6H4qZXycNoNPIR2JYSXQ8lc+FwrQ ZBmYtFPj7O1D+TaFojI9MJrxby77i6BoIktxQ6/br1yTwjSK5CXFLh5w1s7n07/H7pc7 cX9TE5OVHMcMApZBibocnsRtGFUvbLMW5N8vqq6rlzFMV+1Nxw7HB4rRgKgfRPd9yZpW 4cxTBlS+2eqKnGKvckjn8nvLnyWmHspLojN5xYk5hcUrlcYp8DKUNvBkbSwWPskXrGiY OUPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o6p8Bk4f; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx24si6462737edb.419.2020.11.23.05.28.21; Mon, 23 Nov 2020 05:28:44 -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=@linuxfoundation.org header.s=korg header.b=o6p8Bk4f; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731175AbgKWMdO (ORCPT + 99 others); Mon, 23 Nov 2020 07:33:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:44124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731138AbgKWMcw (ORCPT ); Mon, 23 Nov 2020 07:32:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 325B920728; Mon, 23 Nov 2020 12:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134771; bh=SNmOTrYumDbeoO8R2LSsVtkf19qUhscjepDZKMpxfhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o6p8Bk4faummQCI5zcsdt4a6QRxXgKBvv2g4xKUNNjkWqE6qqse8t9XjdKaFjYnsB DOUxpgv1QK+8Hn22XwVC9ttlwQO5EZXmydOpXbqdvpEJb5uSKBIrkSAdfPdSLVsvYp oRXEU1B43oRj8s7bKFhcGIMI5RqU814cvfEygRP0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Stable@vger.kernel.org, Jonathan Cameron , russianneuromancer Subject: [PATCH 4.19 77/91] iio: accel: kxcjk1013: Add support for KIOX010A ACPI DSM for setting tablet-mode Date: Mon, 23 Nov 2020 13:22:37 +0100 Message-Id: <20201123121813.070000500@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121809.285416732@linuxfoundation.org> References: <20201123121809.285416732@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede commit e5b1032a656e9aa4c7a4df77cb9156a2a651a5f9 upstream. Some 360 degree hinges (yoga) style 2-in-1 devices use 2 KXCJ91008-s to allow the OS to determine the angle between the display and the base of the device, so that the OS can determine if the 2-in-1 is in laptop or in tablet-mode. On Windows both accelerometers are read by a special HingeAngleService process; and this process calls a DSM (Device Specific Method) on the ACPI KIOX010A device node for the sensor in the display, to let the embedded-controller (EC) know about the mode so that it can disable the kbd and touchpad to avoid spurious input while folded into tablet-mode. This notifying of the EC is problematic because sometimes the EC comes up thinking that device is in tablet-mode and the kbd and touchpad do not work. This happens for example on Irbis NB111 devices after a suspend / resume cycle (after a complete battery drain / hard reset without having booted Windows at least once). Other 2-in-1s which are likely affected too are e.g. the Teclast F5 and F6 series. The kxcjk-1013 driver may seem like a strange place to deal with this, but since it is *the* driver for the ACPI KIOX010A device, it is also the driver which has access to the ACPI handle needed by the DSM. Add support for calling the DSM and on probe unconditionally tell the EC that the device is laptop mode, fixing the kbd and touchpad sometimes not working. Fixes: 7f6232e69539 ("iio: accel: kxcjk1013: Add KIOX010A ACPI Hardware-ID") Reported-and-tested-by: russianneuromancer Signed-off-by: Hans de Goede Cc: Link: https://lore.kernel.org/r/20201110133835.129080-3-hdegoede@redhat.com Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/accel/kxcjk-1013.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -137,6 +137,7 @@ enum kx_chipset { enum kx_acpi_type { ACPI_GENERIC, ACPI_SMO8500, + ACPI_KIOX010A, }; struct kxcjk1013_data { @@ -282,6 +283,32 @@ static const struct { {19163, 1, 0}, {38326, 0, 1} }; +#ifdef CONFIG_ACPI +enum kiox010a_fn_index { + KIOX010A_SET_LAPTOP_MODE = 1, + KIOX010A_SET_TABLET_MODE = 2, +}; + +static int kiox010a_dsm(struct device *dev, int fn_index) +{ + acpi_handle handle = ACPI_HANDLE(dev); + guid_t kiox010a_dsm_guid; + union acpi_object *obj; + + if (!handle) + return -ENODEV; + + guid_parse("1f339696-d475-4e26-8cad-2e9f8e6d7a91", &kiox010a_dsm_guid); + + obj = acpi_evaluate_dsm(handle, &kiox010a_dsm_guid, 1, fn_index, NULL); + if (!obj) + return -EIO; + + ACPI_FREE(obj); + return 0; +} +#endif + static int kxcjk1013_set_mode(struct kxcjk1013_data *data, enum kxcjk1013_mode mode) { @@ -359,6 +386,13 @@ static int kxcjk1013_chip_init(struct kx { int ret; +#ifdef CONFIG_ACPI + if (data->acpi_type == ACPI_KIOX010A) { + /* Make sure the kbd and touchpad on 2-in-1s using 2 KXCJ91008-s work */ + kiox010a_dsm(&data->client->dev, KIOX010A_SET_LAPTOP_MODE); + } +#endif + ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_WHO_AM_I); if (ret < 0) { dev_err(&data->client->dev, "Error reading who_am_i\n"); @@ -1256,6 +1290,8 @@ static const char *kxcjk1013_match_acpi_ if (strcmp(id->id, "SMO8500") == 0) *acpi_type = ACPI_SMO8500; + else if (strcmp(id->id, "KIOX010A") == 0) + *acpi_type = ACPI_KIOX010A; *chipset = (enum kx_chipset)id->driver_data;