From patchwork Sun Apr 30 16:57:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49891C77B60 for ; Sun, 30 Apr 2023 16:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjD3Q7D (ORCPT ); Sun, 30 Apr 2023 12:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjD3Q7C (ORCPT ); Sun, 30 Apr 2023 12:59:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE8E213F for ; Sun, 30 Apr 2023 09:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mCBm5jOnhjJEt6pe1UKwQEu4teSD01GVaLjt+SyOQmE=; b=UP8hM8gLqMlFXbS7HmVi3itRF//p9zwYtu1OD/m2vF2gvKQ4QMqiOo/If6dRpKAWyNQq/o W7/TdL60PpeXkiGHw3eq5Bfi48DliyJRK0ccAOlDdC8WkgN+OT2nft3X+q57MPP6GPe90o oaVls78hivTHq31hFi7GoCqMCJY+O4c= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-lf4Ik5L4OJSoaWzigonaxA-1; Sun, 30 Apr 2023 12:58:19 -0400 X-MC-Unique: lf4Ik5L4OJSoaWzigonaxA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 769212A59553; Sun, 30 Apr 2023 16:58:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A1832166B26; Sun, 30 Apr 2023 16:58:17 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 01/19] pwm: Export pwm_add_table() / pwm_remove_table() Date: Sun, 30 Apr 2023 18:57:49 +0200 Message-Id: <20230430165807.472798-2-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Lenovo Yoga Book 1 (yb1-x90f/l) models have a backlit keyboard where the brightness is directly controlled by one of the Intel Cherry Trail SoCs PWM controllers. To control the backlight the drivers/platform/lenovo-yogabook.c needs to add a pwm_lookup table entry so that it can call pwm_get() to get a reference to the PWM controller. The lenovo-yogabook driver can be build as a module, export pwm_add_table() and pwm_remove_table() so that the lenovo-yogabook driver can use them when build as a module. Signed-off-by: Hans de Goede --- drivers/pwm/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 474725714a05..c66daac6154f 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -881,6 +881,7 @@ void pwm_add_table(struct pwm_lookup *table, size_t num) mutex_unlock(&pwm_lookup_lock); } +EXPORT_SYMBOL_GPL(pwm_add_table); /** * pwm_remove_table() - unregister PWM device consumers @@ -898,6 +899,7 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num) mutex_unlock(&pwm_lookup_lock); } +EXPORT_SYMBOL_GPL(pwm_remove_table); /** * pwm_get() - look up and request a PWM device From patchwork Sun Apr 30 16:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57A24C7EE23 for ; Sun, 30 Apr 2023 17:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjD3RAh (ORCPT ); Sun, 30 Apr 2023 13:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjD3RAg (ORCPT ); Sun, 30 Apr 2023 13:00:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE6B3595 for ; Sun, 30 Apr 2023 09:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hPUodKH8f+H/JW+lPIMV3CIdr4U3egsnh7kn3ioo34Q=; b=KAr6x/R4aBU5xgXyoGi08lN1WT38CbCajAyoOziebHqkgTyu57NLgKpiQBuA9YuhxkM29L bUnvcZEcAWa9r5jXpQ8z0jGC1uimrEyMGkdQIaKzBqodFAA/CdMaVZYqHx+ZlDzaNmGz0V ZdiPvzbw8E4iyoRn5Mq3ftBQokc/9+k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-Aniwy0goP_Or2D1SQIUjVw-1; Sun, 30 Apr 2023 12:58:20 -0400 X-MC-Unique: Aniwy0goP_Or2D1SQIUjVw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C575B185A79C; Sun, 30 Apr 2023 16:58:19 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id AADB72166B26; Sun, 30 Apr 2023 16:58:18 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 02/19] platform/x86: lenovo-yogabook: Fix work race on remove() Date: Sun, 30 Apr 2023 18:57:50 +0200 Message-Id: <20230430165807.472798-3-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org When yogabook_wmi_remove() runs yogabook_wmi_work might still be running and using the devices which yogabook_wmi_remove() puts. To avoid this move to explicitly cancelling the work rather then using devm_work_autocancel(). This requires also making the yogabook_backside_hall_irq handler non devm managed, so that it cannot re-queue the work while yogabook_wmi_remove() runs. Fixes: c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book") Signed-off-by: Hans de Goede --- Changes in v2: - Drop no longer used include --- drivers/platform/x86/lenovo-yogabook-wmi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 5f4bd1eec38a..3a6de4ab74a4 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -2,7 +2,6 @@ /* WMI driver for Lenovo Yoga Book YB1-X90* / -X91* tablets */ #include -#include #include #include #include @@ -248,10 +247,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) data->brightness = YB_KBD_BL_DEFAULT; set_bit(YB_KBD_IS_ON, &data->flags); set_bit(YB_DIGITIZER_IS_ON, &data->flags); - - r = devm_work_autocancel(&wdev->dev, &data->work, yogabook_wmi_work); - if (r) - return r; + INIT_WORK(&data->work, yogabook_wmi_work); data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1); if (!data->kbd_adev) { @@ -299,10 +295,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) } data->backside_hall_irq = r; - r = devm_request_irq(&wdev->dev, data->backside_hall_irq, - yogabook_backside_hall_irq, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, - "backside_hall_sw", data); + r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + "backside_hall_sw", data); if (r) { dev_err_probe(&wdev->dev, r, "Requesting backside_hall_sw IRQ\n"); goto error_put_devs; @@ -318,11 +313,14 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) r = devm_led_classdev_register(&wdev->dev, &data->kbd_bl_led); if (r < 0) { dev_err_probe(&wdev->dev, r, "Registering backlight LED device\n"); - goto error_put_devs; + goto error_free_irq; } return 0; +error_free_irq: + free_irq(data->backside_hall_irq, data); + cancel_work_sync(&data->work); error_put_devs: put_device(data->dig_dev); put_device(data->kbd_dev); @@ -335,6 +333,8 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) { struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); + free_irq(data->backside_hall_irq, data); + cancel_work_sync(&data->work); put_device(data->dig_dev); put_device(data->kbd_dev); acpi_dev_put(data->dig_adev); From patchwork Sun Apr 30 16:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6449C7EE23 for ; Sun, 30 Apr 2023 16:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbjD3Q7t (ORCPT ); Sun, 30 Apr 2023 12:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbjD3Q7r (ORCPT ); Sun, 30 Apr 2023 12:59:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5A1926A5 for ; Sun, 30 Apr 2023 09:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j47T03mSJNmFM0nSRpUoxlZmIGdmkMYlP32wgG6jzVI=; b=KC2zh62JmZL2KMTZLRsZCXgLCOKIYxgMXhWCz1Gqga0E37LbveVne5dsVSXog3hILWsnm5 gLkjjAWM9YUJDfJZJVRgD4Hsi5W0egFBhljehFl7OijYxEUSp71ycus6WsNSrywQBh1TgM +87KEYn9XXbBmjl+Lm1NsEBxStRAIbM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-DwUclbVgMseewkJ5Meof-g-1; Sun, 30 Apr 2023 12:58:21 -0400 X-MC-Unique: DwUclbVgMseewkJ5Meof-g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1CD4F8828C0; Sun, 30 Apr 2023 16:58:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03C222166B26; Sun, 30 Apr 2023 16:58:19 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 03/19] platform/x86: lenovo-yogabook: Reprobe devices on remove() Date: Sun, 30 Apr 2023 18:57:51 +0200 Message-Id: <20230430165807.472798-4-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Ensure that both the keyboard touchscreen and the digitizer have their driver bound after remove(). Without this modprobing lenovo-yogabook-wmi after a rmmod fails because lenovo-yogabook-wmi defers probing until both devices have their driver bound. Fixes: c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book") Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 3a6de4ab74a4..5948ffa74acd 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -332,9 +332,20 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) static void yogabook_wmi_remove(struct wmi_device *wdev) { struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); + int r = 0; free_irq(data->backside_hall_irq, data); cancel_work_sync(&data->work); + + if (!test_bit(YB_KBD_IS_ON, &data->flags)) + r |= device_reprobe(data->kbd_dev); + + if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags)) + r |= device_reprobe(data->dig_dev); + + if (r) + dev_warn(&wdev->dev, "Reprobe of devices failed\n"); + put_device(data->dig_dev); put_device(data->kbd_dev); acpi_dev_put(data->dig_adev); From patchwork Sun Apr 30 16:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78D33C7EE26 for ; Sun, 30 Apr 2023 16:59:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbjD3Q7v (ORCPT ); Sun, 30 Apr 2023 12:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjD3Q7u (ORCPT ); Sun, 30 Apr 2023 12:59:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 361D92706 for ; Sun, 30 Apr 2023 09:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1auKSye34shTdwIrsT6sISE6jxpc0xAhF7vTm5kv+RI=; b=bTB4P2xJUXYiq5cRA0184SwqWYO2UKWfUFR0h30HsQZhwl6KZ1TXwHVEkY6NfirTp3wNRv SdSFyHmkTOhnuSDk3URubCSpcgFXbLracZvYdQ0lcpAmHa7GZOzXdEoG844H8+r103Pr+U vUS+GCE5AmZmPwvYOfGmEjixgYp8ar0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-JeYXrbPnPv2qjUJOc7IH6w-1; Sun, 30 Apr 2023 12:58:22 -0400 X-MC-Unique: JeYXrbPnPv2qjUJOc7IH6w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A2678828C2; Sun, 30 Apr 2023 16:58:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FDFB2166B26; Sun, 30 Apr 2023 16:58:21 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 04/19] platform/x86: lenovo-yogabook: Set default keyboard backligh brightness on probe() Date: Sun, 30 Apr 2023 18:57:52 +0200 Message-Id: <20230430165807.472798-5-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Set default keyboard backlight brightness on probe(), this fixes the backlight being off after a rmmod + modprobe. Fixes: c0549b72d99d ("platform/x86: lenovo-yogabook-wmi: Add driver for Lenovo Yoga Book") Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 5948ffa74acd..d57fcc838851 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -295,6 +295,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) } data->backside_hall_irq = r; + /* Set default brightness before enabling the IRQ */ + yogabook_wmi_set_kbd_backlight(data->wdev, YB_KBD_BL_DEFAULT); + r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "backside_hall_sw", data); From patchwork Sun Apr 30 16:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF1D0C77B60 for ; Sun, 30 Apr 2023 16:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbjD3Q75 (ORCPT ); Sun, 30 Apr 2023 12:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbjD3Q74 (ORCPT ); Sun, 30 Apr 2023 12:59:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A3012D52 for ; Sun, 30 Apr 2023 09:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i59r/bRojMCKxgdqJr0IbUbUR2qp+P1v88uAOLYH+p8=; b=GMVJl7YhdvfpO6fDRoJalaTPNsc6+q/rbmxmrNWBSQNd9zCJb/8hFt6b8eNqnGfOMyQj4R rJ+i3Q0RWz8AByZPq/UlZDD23eY29USb81L+sILosALI8vztznzBQ9QleRI7QS6hpWD9/6 8erOsNovxlQhHOGTFlfH3Uqe0yOlsu4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-GhKghBGyN5SKbHv2iiHRrA-1; Sun, 30 Apr 2023 12:58:24 -0400 X-MC-Unique: GhKghBGyN5SKbHv2iiHRrA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5D4685A588; Sun, 30 Apr 2023 16:58:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C9E22166B26; Sun, 30 Apr 2023 16:58:22 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 05/19] platform/x86: lenovo-yogabook: Simplify gpio lookup table cleanup Date: Sun, 30 Apr 2023 18:57:53 +0200 Message-Id: <20230430165807.472798-6-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org After the devm_gpiod_get("backside_hall_sw") call the gpio lookup table is no longer necessary. Remove it directly after this call instead using a devm reset-action for this. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index d57fcc838851..0b49c7a54bfc 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -227,11 +227,6 @@ static struct gpiod_lookup_table yogabook_wmi_gpios = { }, }; -static void yogabook_wmi_rm_gpio_lookup(void *unused) -{ - gpiod_remove_lookup_table(&yogabook_wmi_gpios); -} - static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) { struct yogabook_wmi *data; @@ -275,13 +270,9 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) } gpiod_add_lookup_table(&yogabook_wmi_gpios); + data->backside_hall_gpio = devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN); + gpiod_remove_lookup_table(&yogabook_wmi_gpios); - r = devm_add_action_or_reset(&wdev->dev, yogabook_wmi_rm_gpio_lookup, NULL); - if (r) - goto error_put_devs; - - data->backside_hall_gpio = - devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN); if (IS_ERR(data->backside_hall_gpio)) { r = PTR_ERR(data->backside_hall_gpio); dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw GPIO\n"); From patchwork Sun Apr 30 16:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1334C77B73 for ; Sun, 30 Apr 2023 16:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbjD3Q7u (ORCPT ); Sun, 30 Apr 2023 12:59:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjD3Q7s (ORCPT ); Sun, 30 Apr 2023 12:59:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE5D2709 for ; Sun, 30 Apr 2023 09:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QncfvbxoisQ0r9XQST3rgFnhIErMKLMQEVSKDtcu3zw=; b=b6s4d+bdoEwuoZ8s47h4Qx0az+fE7tz4dzg2+IHWXwNph9Fn1h7iHTl0Tx7B6sHkkg47Xb dQXH1Xc36n3aA9zy3XLfwKIU6DzHOafNlnYJIRefQtBkLqzqLOn+7vkRN+/Ry0F5V0ZEgq vX8+mkv/Pnc3EgWmIVU2B7HcWTyCy40= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-gVDiX9D5MCeTAFmR5RrjDQ-1; Sun, 30 Apr 2023 12:58:25 -0400 X-MC-Unique: gVDiX9D5MCeTAFmR5RrjDQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 100021C06EC1; Sun, 30 Apr 2023 16:58:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA5FE2166B26; Sun, 30 Apr 2023 16:58:23 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 06/19] platform/x86: lenovo-yogabook: Switch to DEFINE_SIMPLE_DEV_PM_OPS() Date: Sun, 30 Apr 2023 18:57:54 +0200 Message-Id: <20230430165807.472798-7-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Switch to DEFINE_SIMPLE_DEV_PM_OPS() so that the __maybe_unused can be dropped from the suspend/resume callbacks. While at it also drop the _wmi_ part from the callback names in preparation for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 0b49c7a54bfc..2a46e19893e8 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -346,7 +346,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) acpi_dev_put(data->kbd_adev); } -static int __maybe_unused yogabook_wmi_suspend(struct device *dev) +static int yogabook_suspend(struct device *dev) { struct wmi_device *wdev = container_of(dev, struct wmi_device, dev); struct yogabook_wmi *data = dev_get_drvdata(dev); @@ -362,7 +362,7 @@ static int __maybe_unused yogabook_wmi_suspend(struct device *dev) return 0; } -static int __maybe_unused yogabook_wmi_resume(struct device *dev) +static int yogabook_resume(struct device *dev) { struct wmi_device *wdev = container_of(dev, struct wmi_device, dev); struct yogabook_wmi *data = dev_get_drvdata(dev); @@ -391,13 +391,12 @@ static const struct wmi_device_id yogabook_wmi_id_table[] = { { } /* Terminating entry */ }; -static SIMPLE_DEV_PM_OPS(yogabook_wmi_pm_ops, - yogabook_wmi_suspend, yogabook_wmi_resume); +static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume); static struct wmi_driver yogabook_wmi_driver = { .driver = { .name = "yogabook-wmi", - .pm = &yogabook_wmi_pm_ops, + .pm = pm_sleep_ptr(&yogabook_pm_ops), }, .no_notify_data = true, .id_table = yogabook_wmi_id_table, From patchwork Sun Apr 30 16:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32A07C7EE23 for ; Sun, 30 Apr 2023 16:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbjD3Q75 (ORCPT ); Sun, 30 Apr 2023 12:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjD3Q74 (ORCPT ); Sun, 30 Apr 2023 12:59:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A35E2D54 for ; Sun, 30 Apr 2023 09:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y2Uo1i+eLG74vBzADXNF7vLaMYH1S8dd92pyB0j92Ng=; b=b3eeowF0xEOpyUeYsIoSc5ks08DmtPTdrizspVQFH47D9+Lz+P81CjCuluSOTa/lJVlq2B XxTWz9+mzvnQHzkgtpja0x33kJ06MfsnCG6JO7dmLspt7i2yU3DOBtZgP4dEmKHgH4sNLo 9QVCgMTEdp2yDy6kLaUHwtcendt1WE0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-73-0kXCQxbuMoy8ShikvdHU_w-1; Sun, 30 Apr 2023 12:58:26 -0400 X-MC-Unique: 0kXCQxbuMoy8ShikvdHU_w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C9722A59553; Sun, 30 Apr 2023 16:58:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42C7C2166B26; Sun, 30 Apr 2023 16:58:25 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 07/19] platform/x86: lenovo-yogabook: Store dev instead of wdev in drvdata struct Date: Sun, 30 Apr 2023 18:57:55 +0200 Message-Id: <20230430165807.472798-8-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Store a "struct device *dev" instead of a "struct wmi_device *wdev;" in the "struct yogabook_wmi" driver-data. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 2a46e19893e8..1bbdc48aef5b 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -29,7 +29,7 @@ enum { }; struct yogabook_wmi { - struct wmi_device *wdev; + struct device *dev; struct acpi_device *kbd_adev; struct acpi_device *dig_adev; struct device *kbd_dev; @@ -42,14 +42,14 @@ struct yogabook_wmi { uint8_t brightness; }; -static int yogabook_wmi_do_action(struct wmi_device *wdev, int action) +static int yogabook_wmi_do_action(struct yogabook_wmi *data, int action) { struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer input; acpi_status status; u32 dummy_arg = 0; - dev_dbg(&wdev->dev, "Do action: %d\n", action); + dev_dbg(data->dev, "Do action: %d\n", action); input.pointer = &dummy_arg; input.length = sizeof(dummy_arg); @@ -57,7 +57,7 @@ static int yogabook_wmi_do_action(struct wmi_device *wdev, int action) status = wmi_evaluate_method(YB_MBTN_METHOD_GUID, 0, action, &input, &output); if (ACPI_FAILURE(status)) { - dev_err(&wdev->dev, "Calling WMI method failure: 0x%x\n", + dev_err(data->dev, "Calling WMI method failure: 0x%x\n", status); return status; } @@ -71,21 +71,20 @@ static int yogabook_wmi_do_action(struct wmi_device *wdev, int action) * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI * device (Goodix touchpad acts as virtual sensor keyboard). */ -static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev, +static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, uint8_t level) { - struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_object_list input; union acpi_object param; acpi_status status; if (data->kbd_adev->power.state != ACPI_STATE_D0) { - dev_warn(&wdev->dev, "keyboard touchscreen not in D0, cannot set brightness\n"); + dev_warn(data->dev, "keyboard touchscreen not in D0, cannot set brightness\n"); return -ENXIO; } - dev_dbg(&wdev->dev, "Set KBLC level to %u\n", level); + dev_dbg(data->dev, "Set KBLC level to %u\n", level); input.count = 1; input.pointer = ¶m; @@ -96,7 +95,7 @@ static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev, status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC", &input, &output); if (ACPI_FAILURE(status)) { - dev_err(&wdev->dev, "Failed to call KBLC method: 0x%x\n", status); + dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status); return status; } @@ -107,7 +106,6 @@ static int yogabook_wmi_set_kbd_backlight(struct wmi_device *wdev, static void yogabook_wmi_work(struct work_struct *work) { struct yogabook_wmi *data = container_of(work, struct yogabook_wmi, work); - struct device *dev = &data->wdev->dev; bool kbd_on, digitizer_on; int r; @@ -130,13 +128,13 @@ static void yogabook_wmi_work(struct work_struct *work) * Must be done before releasing the keyboard touchscreen driver, * so that the keyboard touchscreen dev is still in D0. */ - yogabook_wmi_set_kbd_backlight(data->wdev, 0); + yogabook_wmi_set_kbd_backlight(data, 0); device_release_driver(data->kbd_dev); clear_bit(YB_KBD_IS_ON, &data->flags); } if (!digitizer_on && test_bit(YB_DIGITIZER_IS_ON, &data->flags)) { - yogabook_wmi_do_action(data->wdev, YB_PAD_DISABLE); + yogabook_wmi_do_action(data, YB_PAD_DISABLE); device_release_driver(data->dig_dev); clear_bit(YB_DIGITIZER_IS_ON, &data->flags); } @@ -144,18 +142,18 @@ static void yogabook_wmi_work(struct work_struct *work) if (kbd_on && !test_bit(YB_KBD_IS_ON, &data->flags)) { r = device_reprobe(data->kbd_dev); if (r) - dev_warn(dev, "Reprobe of keyboard touchscreen failed: %d\n", r); + dev_warn(data->dev, "Reprobe of keyboard touchscreen failed: %d\n", r); - yogabook_wmi_set_kbd_backlight(data->wdev, data->brightness); + yogabook_wmi_set_kbd_backlight(data, data->brightness); set_bit(YB_KBD_IS_ON, &data->flags); } if (digitizer_on && !test_bit(YB_DIGITIZER_IS_ON, &data->flags)) { r = device_reprobe(data->dig_dev); if (r) - dev_warn(dev, "Reprobe of digitizer failed: %d\n", r); + dev_warn(data->dev, "Reprobe of digitizer failed: %d\n", r); - yogabook_wmi_do_action(data->wdev, YB_PAD_ENABLE); + yogabook_wmi_do_action(data, YB_PAD_ENABLE); set_bit(YB_DIGITIZER_IS_ON, &data->flags); } } @@ -206,7 +204,6 @@ static int kbd_brightness_set(struct led_classdev *cdev, { struct yogabook_wmi *data = container_of(cdev, struct yogabook_wmi, kbd_bl_led); - struct wmi_device *wdev = data->wdev; if ((value < 0) || (value > 255)) return -EINVAL; @@ -216,7 +213,7 @@ static int kbd_brightness_set(struct led_classdev *cdev, if (data->kbd_adev->power.state != ACPI_STATE_D0) return 0; - return yogabook_wmi_set_kbd_backlight(wdev, data->brightness); + return yogabook_wmi_set_kbd_backlight(data, data->brightness); } static struct gpiod_lookup_table yogabook_wmi_gpios = { @@ -238,7 +235,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) dev_set_drvdata(&wdev->dev, data); - data->wdev = wdev; + data->dev = &wdev->dev; data->brightness = YB_KBD_BL_DEFAULT; set_bit(YB_KBD_IS_ON, &data->flags); set_bit(YB_DIGITIZER_IS_ON, &data->flags); @@ -287,7 +284,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) data->backside_hall_irq = r; /* Set default brightness before enabling the IRQ */ - yogabook_wmi_set_kbd_backlight(data->wdev, YB_KBD_BL_DEFAULT); + yogabook_wmi_set_kbd_backlight(data, YB_KBD_BL_DEFAULT); r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, @@ -338,7 +335,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) r |= device_reprobe(data->dig_dev); if (r) - dev_warn(&wdev->dev, "Reprobe of devices failed\n"); + dev_warn(data->dev, "Reprobe of devices failed\n"); put_device(data->dig_dev); put_device(data->kbd_dev); @@ -348,7 +345,6 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) static int yogabook_suspend(struct device *dev) { - struct wmi_device *wdev = container_of(dev, struct wmi_device, dev); struct yogabook_wmi *data = dev_get_drvdata(dev); set_bit(YB_SUSPENDED, &data->flags); @@ -357,24 +353,23 @@ static int yogabook_suspend(struct device *dev) /* Turn off the pen button at sleep */ if (test_bit(YB_DIGITIZER_IS_ON, &data->flags)) - yogabook_wmi_do_action(wdev, YB_PAD_DISABLE); + yogabook_wmi_do_action(data, YB_PAD_DISABLE); return 0; } static int yogabook_resume(struct device *dev) { - struct wmi_device *wdev = container_of(dev, struct wmi_device, dev); struct yogabook_wmi *data = dev_get_drvdata(dev); if (test_bit(YB_KBD_IS_ON, &data->flags)) { /* Ensure keyboard touchpad is on before we call KBLC() */ acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); - yogabook_wmi_set_kbd_backlight(wdev, data->brightness); + yogabook_wmi_set_kbd_backlight(data, data->brightness); } if (test_bit(YB_DIGITIZER_IS_ON, &data->flags)) - yogabook_wmi_do_action(wdev, YB_PAD_ENABLE); + yogabook_wmi_do_action(data, YB_PAD_ENABLE); clear_bit(YB_SUSPENDED, &data->flags); From patchwork Sun Apr 30 16:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8333CC7EE21 for ; Sun, 30 Apr 2023 16:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231132AbjD3Q74 (ORCPT ); Sun, 30 Apr 2023 12:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbjD3Q74 (ORCPT ); Sun, 30 Apr 2023 12:59:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D1F2D73 for ; Sun, 30 Apr 2023 09:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fc0o4FmfepKkzUDJlnn+iIoOvetPn6yXTjCkGtCtkSw=; b=U2TR6VK6RZaZTIoFt9w5AI4f297FTykrNA+1nkaL0W/Od0ko4+UQj7O+hbuLf7LBP26nMP L4nUJ7279Ynw9jU6FN821jJF4sLV0khXJUO3qUof4s4X2wUQEcSBJMmRwIrfVGpqsUcIG/ /n38KLYDyQHoGEhvTef5/fb4LjX9BW4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-JRhLCf32NKqz_sDd3ckFkQ-1; Sun, 30 Apr 2023 12:58:28 -0400 X-MC-Unique: JRhLCf32NKqz_sDd3ckFkQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B0A8C8828C1; Sun, 30 Apr 2023 16:58:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94EA02166B26; Sun, 30 Apr 2023 16:58:26 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 08/19] platform/x86: lenovo-yogabook: Add dev local variable to probe() Date: Sun, 30 Apr 2023 18:57:56 +0200 Message-Id: <20230430165807.472798-9-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Add a "struct device *dev" local variable to probe(). This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. While at it also move the dev_set_drvdata() call to the end of probe(). Signed-off-by: Hans de Goede --- Changes in v2: - Move the dev_set_drvdata() call to the end of probe() --- drivers/platform/x86/lenovo-yogabook-wmi.c | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 1bbdc48aef5b..4f2624eba210 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -226,16 +226,15 @@ static struct gpiod_lookup_table yogabook_wmi_gpios = { static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) { + struct device *dev = &wdev->dev; struct yogabook_wmi *data; int r; - data = devm_kzalloc(&wdev->dev, sizeof(struct yogabook_wmi), GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct yogabook_wmi), GFP_KERNEL); if (data == NULL) return -ENOMEM; - dev_set_drvdata(&wdev->dev, data); - - data->dev = &wdev->dev; + data->dev = dev; data->brightness = YB_KBD_BL_DEFAULT; set_bit(YB_KBD_IS_ON, &data->flags); set_bit(YB_DIGITIZER_IS_ON, &data->flags); @@ -243,13 +242,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1); if (!data->kbd_adev) { - dev_err(&wdev->dev, "Cannot find the touchpad device in ACPI tables\n"); + dev_err(dev, "Cannot find the touchpad device in ACPI tables\n"); return -ENODEV; } data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1); if (!data->dig_adev) { - dev_err(&wdev->dev, "Cannot find the digitizer device in ACPI tables\n"); + dev_err(dev, "Cannot find the digitizer device in ACPI tables\n"); r = -ENODEV; goto error_put_devs; } @@ -267,18 +266,18 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) } gpiod_add_lookup_table(&yogabook_wmi_gpios); - data->backside_hall_gpio = devm_gpiod_get(&wdev->dev, "backside_hall_sw", GPIOD_IN); + data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN); gpiod_remove_lookup_table(&yogabook_wmi_gpios); if (IS_ERR(data->backside_hall_gpio)) { r = PTR_ERR(data->backside_hall_gpio); - dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw GPIO\n"); + dev_err_probe(dev, r, "Getting backside_hall_sw GPIO\n"); goto error_put_devs; } r = gpiod_to_irq(data->backside_hall_gpio); if (r < 0) { - dev_err_probe(&wdev->dev, r, "Getting backside_hall_sw IRQ\n"); + dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n"); goto error_put_devs; } data->backside_hall_irq = r; @@ -290,7 +289,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "backside_hall_sw", data); if (r) { - dev_err_probe(&wdev->dev, r, "Requesting backside_hall_sw IRQ\n"); + dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n"); goto error_put_devs; } @@ -301,12 +300,13 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) data->kbd_bl_led.brightness_get = kbd_brightness_get; data->kbd_bl_led.max_brightness = 255; - r = devm_led_classdev_register(&wdev->dev, &data->kbd_bl_led); + r = devm_led_classdev_register(dev, &data->kbd_bl_led); if (r < 0) { - dev_err_probe(&wdev->dev, r, "Registering backlight LED device\n"); + dev_err_probe(dev, r, "Registering backlight LED device\n"); goto error_free_irq; } + dev_set_drvdata(dev, data); return 0; error_free_irq: From patchwork Sun Apr 30 16:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 015F9C7EE29 for ; Sun, 30 Apr 2023 17:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231246AbjD3RAi (ORCPT ); Sun, 30 Apr 2023 13:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231126AbjD3RAg (ORCPT ); Sun, 30 Apr 2023 13:00:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1127730D8 for ; Sun, 30 Apr 2023 09:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7ZA6DXgyTXvwIadThlqTV1A5YcEulIvzodUVYHO63jc=; b=TsvJTfTiNTacjiqM8CuhtYCm/ZwQfHfFEH1qVG0mZi2NxD41kAZbvqSH8BI82+7yZ1FH4x CkiX6WgWUkX1QGx/dqrtFwm0qdJ3EvAG9PLiInosYK64W1mS9powUxctW6CL5mfJ57+7TS GP62nHtih54NV9nvRt3TuxrqvGQwZG4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-c9vZKObjPoahPew8O9R_Zw-1; Sun, 30 Apr 2023 12:58:29 -0400 X-MC-Unique: c9vZKObjPoahPew8O9R_Zw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B223811E7B; Sun, 30 Apr 2023 16:58:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id E35202166B26; Sun, 30 Apr 2023 16:58:27 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 09/19] platform/x86: lenovo-yogabook: Use PMIC LED driver for pen icon LED control Date: Sun, 30 Apr 2023 18:57:57 +0200 Message-Id: <20230430165807.472798-10-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use the (new) PMIC LED driver for pen icon LED control instead of using custom WMI calls for this. This will also work on the Android version of the Lenovo Yoga Book 1, where there is no WMI interface for this. The dev_id of the lookup is set using dev_name() so that it will also work for both the Windows YB1 WMI-device as well as the Android YB1 platform-device. While at it also move the gpio_lookup to using dev_name() for the dev_id. Note this also removes the need to turn of the LED during suspend since the PMIC LED driver now already does that. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 63 ++++++++-------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 4f2624eba210..68057150f465 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -11,11 +11,6 @@ #include #define YB_MBTN_EVENT_GUID "243FEC1D-1963-41C1-8100-06A9D82A94B4" -#define YB_MBTN_METHOD_GUID "742B0CA1-0B20-404B-9CAA-AEFCABF30CE0" - -#define YB_PAD_ENABLE 1 -#define YB_PAD_DISABLE 2 -#define YB_LIGHTUP_BTN 3 #define YB_KBD_BL_DEFAULT 128 @@ -34,6 +29,7 @@ struct yogabook_wmi { struct acpi_device *dig_adev; struct device *kbd_dev; struct device *dig_dev; + struct led_classdev *pen_led; struct gpio_desc *backside_hall_gpio; int backside_hall_irq; struct work_struct work; @@ -42,31 +38,6 @@ struct yogabook_wmi { uint8_t brightness; }; -static int yogabook_wmi_do_action(struct yogabook_wmi *data, int action) -{ - struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_buffer input; - acpi_status status; - u32 dummy_arg = 0; - - dev_dbg(data->dev, "Do action: %d\n", action); - - input.pointer = &dummy_arg; - input.length = sizeof(dummy_arg); - - status = wmi_evaluate_method(YB_MBTN_METHOD_GUID, 0, action, &input, - &output); - if (ACPI_FAILURE(status)) { - dev_err(data->dev, "Calling WMI method failure: 0x%x\n", - status); - return status; - } - - kfree(output.pointer); - - return 0; -} - /* * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI * device (Goodix touchpad acts as virtual sensor keyboard). @@ -134,7 +105,7 @@ static void yogabook_wmi_work(struct work_struct *work) } if (!digitizer_on && test_bit(YB_DIGITIZER_IS_ON, &data->flags)) { - yogabook_wmi_do_action(data, YB_PAD_DISABLE); + led_set_brightness(data->pen_led, LED_OFF); device_release_driver(data->dig_dev); clear_bit(YB_DIGITIZER_IS_ON, &data->flags); } @@ -153,7 +124,7 @@ static void yogabook_wmi_work(struct work_struct *work) if (r) dev_warn(data->dev, "Reprobe of digitizer failed: %d\n", r); - yogabook_wmi_do_action(data, YB_PAD_ENABLE); + led_set_brightness(data->pen_led, LED_FULL); set_bit(YB_DIGITIZER_IS_ON, &data->flags); } } @@ -217,13 +188,17 @@ static int kbd_brightness_set(struct led_classdev *cdev, } static struct gpiod_lookup_table yogabook_wmi_gpios = { - .dev_id = "243FEC1D-1963-41C1-8100-06A9D82A94B4", - .table = { + .table = { GPIO_LOOKUP("INT33FF:02", 18, "backside_hall_sw", GPIO_ACTIVE_LOW), {} }, }; +static struct led_lookup_data yogabook_pen_led = { + .provider = "platform::indicator", + .con_id = "pen-icon-led", +}; + static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) { struct device *dev = &wdev->dev; @@ -265,6 +240,18 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) goto error_put_devs; } + yogabook_pen_led.dev_id = dev_name(dev); + led_add_lookup(&yogabook_pen_led); + data->pen_led = devm_led_get(dev, "pen-icon-led"); + led_remove_lookup(&yogabook_pen_led); + + if (IS_ERR(data->pen_led)) { + r = PTR_ERR(data->pen_led); + dev_err_probe(dev, r, "Getting pen icon LED\n"); + goto error_put_devs; + } + + yogabook_wmi_gpios.dev_id = dev_name(dev); gpiod_add_lookup_table(&yogabook_wmi_gpios); data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN); gpiod_remove_lookup_table(&yogabook_wmi_gpios); @@ -350,11 +337,6 @@ static int yogabook_suspend(struct device *dev) set_bit(YB_SUSPENDED, &data->flags); flush_work(&data->work); - - /* Turn off the pen button at sleep */ - if (test_bit(YB_DIGITIZER_IS_ON, &data->flags)) - yogabook_wmi_do_action(data, YB_PAD_DISABLE); - return 0; } @@ -368,9 +350,6 @@ static int yogabook_resume(struct device *dev) yogabook_wmi_set_kbd_backlight(data, data->brightness); } - if (test_bit(YB_DIGITIZER_IS_ON, &data->flags)) - yogabook_wmi_do_action(data, YB_PAD_ENABLE); - clear_bit(YB_SUSPENDED, &data->flags); /* Check for YB_TABLET_MODE changes made during suspend */ From patchwork Sun Apr 30 16:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48B6AC77B73 for ; Sun, 30 Apr 2023 17:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231150AbjD3RAg (ORCPT ); Sun, 30 Apr 2023 13:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjD3RAf (ORCPT ); Sun, 30 Apr 2023 13:00:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C9BD30DC for ; Sun, 30 Apr 2023 09:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VXHwsCXKeMn1KRwGbgqGGqTyQsRETIoDYs3QhSTfM0c=; b=QGwzCiUg3ZXTKMv9hFxAdoS0roz1HfYk9UatUrcLB15axLmV2t+gqn9jfgLRcYpfIETh6g X48zEnVNqgvdZDrlDtqpLHHlTV8PJXMPIvczmKeulg/F5hGbITb5562szR5YnCQoeZEhB4 PgihhpgOLDepeZtE2y4Ueg4b40e1Wsg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-p88xneZUMDKCDxpZuh7mDw-1; Sun, 30 Apr 2023 12:58:30 -0400 X-MC-Unique: p88xneZUMDKCDxpZuh7mDw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 596CC1C06EC1; Sun, 30 Apr 2023 16:58:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DEE62166B26; Sun, 30 Apr 2023 16:58:29 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 10/19] platform/x86: lenovo-yogabook: Split probe() into generic and WMI specific parts Date: Sun, 30 Apr 2023 18:57:58 +0200 Message-Id: <20230430165807.472798-11-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Split probe() and remove() into generic and WMI specific parts. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- Changes in v2: - Use "return dev_err_probe(...);" in several places to simplify error-exits in the new yogabook_probe() function --- drivers/platform/x86/lenovo-yogabook-wmi.c | 118 ++++++++++++--------- 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 68057150f465..e583ae146323 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -199,74 +199,38 @@ static struct led_lookup_data yogabook_pen_led = { .con_id = "pen-icon-led", }; -static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) +static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, + const char *kbd_bl_led_name) { - struct device *dev = &wdev->dev; - struct yogabook_wmi *data; int r; - data = devm_kzalloc(dev, sizeof(struct yogabook_wmi), GFP_KERNEL); - if (data == NULL) - return -ENOMEM; - data->dev = dev; data->brightness = YB_KBD_BL_DEFAULT; set_bit(YB_KBD_IS_ON, &data->flags); set_bit(YB_DIGITIZER_IS_ON, &data->flags); INIT_WORK(&data->work, yogabook_wmi_work); - data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1); - if (!data->kbd_adev) { - dev_err(dev, "Cannot find the touchpad device in ACPI tables\n"); - return -ENODEV; - } - - data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1); - if (!data->dig_adev) { - dev_err(dev, "Cannot find the digitizer device in ACPI tables\n"); - r = -ENODEV; - goto error_put_devs; - } - - data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev)); - if (!data->kbd_dev || !data->kbd_dev->driver) { - r = -EPROBE_DEFER; - goto error_put_devs; - } - - data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev)); - if (!data->dig_dev || !data->dig_dev->driver) { - r = -EPROBE_DEFER; - goto error_put_devs; - } - yogabook_pen_led.dev_id = dev_name(dev); led_add_lookup(&yogabook_pen_led); data->pen_led = devm_led_get(dev, "pen-icon-led"); led_remove_lookup(&yogabook_pen_led); - if (IS_ERR(data->pen_led)) { - r = PTR_ERR(data->pen_led); - dev_err_probe(dev, r, "Getting pen icon LED\n"); - goto error_put_devs; - } + if (IS_ERR(data->pen_led)) + return dev_err_probe(dev, PTR_ERR(data->pen_led), "Getting pen icon LED\n"); yogabook_wmi_gpios.dev_id = dev_name(dev); gpiod_add_lookup_table(&yogabook_wmi_gpios); data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN); gpiod_remove_lookup_table(&yogabook_wmi_gpios); - if (IS_ERR(data->backside_hall_gpio)) { - r = PTR_ERR(data->backside_hall_gpio); - dev_err_probe(dev, r, "Getting backside_hall_sw GPIO\n"); - goto error_put_devs; - } + if (IS_ERR(data->backside_hall_gpio)) + return dev_err_probe(dev, PTR_ERR(data->backside_hall_gpio), + "Getting backside_hall_sw GPIO\n"); r = gpiod_to_irq(data->backside_hall_gpio); - if (r < 0) { - dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n"); - goto error_put_devs; - } + if (r < 0) + return dev_err_probe(dev, r, "Getting backside_hall_sw IRQ\n"); + data->backside_hall_irq = r; /* Set default brightness before enabling the IRQ */ @@ -275,14 +239,12 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "backside_hall_sw", data); - if (r) { - dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n"); - goto error_put_devs; - } + if (r) + return dev_err_probe(dev, r, "Requesting backside_hall_sw IRQ\n"); schedule_work(&data->work); - data->kbd_bl_led.name = "ybwmi::kbd_backlight"; + data->kbd_bl_led.name = kbd_bl_led_name; data->kbd_bl_led.brightness_set_blocking = kbd_brightness_set; data->kbd_bl_led.brightness_get = kbd_brightness_get; data->kbd_bl_led.max_brightness = 255; @@ -299,6 +261,50 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) error_free_irq: free_irq(data->backside_hall_irq, data); cancel_work_sync(&data->work); + return r; +} + +static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) +{ + struct device *dev = &wdev->dev; + struct yogabook_wmi *data; + int r; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (data == NULL) + return -ENOMEM; + + data->kbd_adev = acpi_dev_get_first_match_dev("GDIX1001", NULL, -1); + if (!data->kbd_adev) { + dev_err(dev, "Cannot find the touchpad device in ACPI tables\n"); + return -ENODEV; + } + + data->dig_adev = acpi_dev_get_first_match_dev("WCOM0019", NULL, -1); + if (!data->dig_adev) { + dev_err(dev, "Cannot find the digitizer device in ACPI tables\n"); + r = -ENODEV; + goto error_put_devs; + } + + data->kbd_dev = get_device(acpi_get_first_physical_node(data->kbd_adev)); + if (!data->kbd_dev || !data->kbd_dev->driver) { + r = -EPROBE_DEFER; + goto error_put_devs; + } + + data->dig_dev = get_device(acpi_get_first_physical_node(data->dig_adev)); + if (!data->dig_dev || !data->dig_dev->driver) { + r = -EPROBE_DEFER; + goto error_put_devs; + } + + r = yogabook_probe(dev, data, "ybwmi::kbd_backlight"); + if (r) + goto error_put_devs; + + return 0; + error_put_devs: put_device(data->dig_dev); put_device(data->kbd_dev); @@ -307,9 +313,8 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) return r; } -static void yogabook_wmi_remove(struct wmi_device *wdev) +static void yogabook_remove(struct yogabook_wmi *data) { - struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); int r = 0; free_irq(data->backside_hall_irq, data); @@ -323,6 +328,13 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) if (r) dev_warn(data->dev, "Reprobe of devices failed\n"); +} + +static void yogabook_wmi_remove(struct wmi_device *wdev) +{ + struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); + + yogabook_remove(data); put_device(data->dig_dev); put_device(data->kbd_dev); From patchwork Sun Apr 30 16:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB1E1C7EE2A for ; Sun, 30 Apr 2023 17:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbjD3RAk (ORCPT ); Sun, 30 Apr 2023 13:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjD3RAh (ORCPT ); Sun, 30 Apr 2023 13:00:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850ED3590 for ; Sun, 30 Apr 2023 09:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gmdQklIbseYwA9PrPuizdDnjHOffqQM2h31Eck4s7EE=; b=TricFGxgwVQOlbF2XvUxUK4XLlQy09CNXuz9RXl9IVmt6Iwq8WpX2VuJHL+UUWvUmue6Bw gcD36LeLuEiBycCrHwvGqJ1hoyJb2aWqjEyNbWcyre0Z3BAIVqK+QeYwxPtUy57msRfcJZ h0F+/19rxR5CU2xX1qFT4tTJK5lMOmY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-dH8Pkv4gPLii2jE7GwLQpg-1; Sun, 30 Apr 2023 12:58:32 -0400 X-MC-Unique: dH8Pkv4gPLii2jE7GwLQpg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A74C58828C0; Sun, 30 Apr 2023 16:58:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C1622166B26; Sun, 30 Apr 2023 16:58:30 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 11/19] platform/x86: lenovo-yogabook: Stop checking adev->power.state Date: Sun, 30 Apr 2023 18:57:59 +0200 Message-Id: <20230430165807.472798-12-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org lenovo-yogabook-wmi: controls the power-state itself and stores this in data->flags so there is no need to poke inside ACPI device internals. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index e583ae146323..7c7a945ed80d 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -50,13 +50,11 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, union acpi_object param; acpi_status status; - if (data->kbd_adev->power.state != ACPI_STATE_D0) { - dev_warn(data->dev, "keyboard touchscreen not in D0, cannot set brightness\n"); - return -ENXIO; - } - dev_dbg(data->dev, "Set KBLC level to %u\n", level); + /* Ensure keyboard touchpad is on before we call KBLC() */ + acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); + input.count = 1; input.pointer = ¶m; @@ -181,7 +179,7 @@ static int kbd_brightness_set(struct led_classdev *cdev, data->brightness = value; - if (data->kbd_adev->power.state != ACPI_STATE_D0) + if (!test_bit(YB_KBD_IS_ON, &data->flags)) return 0; return yogabook_wmi_set_kbd_backlight(data, data->brightness); @@ -356,11 +354,8 @@ static int yogabook_resume(struct device *dev) { struct yogabook_wmi *data = dev_get_drvdata(dev); - if (test_bit(YB_KBD_IS_ON, &data->flags)) { - /* Ensure keyboard touchpad is on before we call KBLC() */ - acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); + if (test_bit(YB_KBD_IS_ON, &data->flags)) yogabook_wmi_set_kbd_backlight(data, data->brightness); - } clear_bit(YB_SUSPENDED, &data->flags); From patchwork Sun Apr 30 16:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70747C7EE21 for ; Sun, 30 Apr 2023 17:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231177AbjD3RAl (ORCPT ); Sun, 30 Apr 2023 13:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbjD3RAk (ORCPT ); Sun, 30 Apr 2023 13:00:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117563599 for ; Sun, 30 Apr 2023 09:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ifbbQQQbYcQOLAbK5pEzFEXNBI8IyiHYKMUj2rnyxR4=; b=NGqa9DAUcSe2W0j1P/Fl8POoytCLxEXirsozLWfDuwR2pDV73zKrpFLGkZcHZTSvZ+t6rA 27W2pPcZ+8YND9eakGRIC1whZELj/FKNUy5YguZ7Xp+n6+Kl9f95OqLscLxN7SagWsYxyZ +hzz9aqsARO5+R+dnHxQe8Ft33gFVdI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574--oZDDpsLONiefHEH3C_ThQ-1; Sun, 30 Apr 2023 12:58:33 -0400 X-MC-Unique: -oZDDpsLONiefHEH3C_ThQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1D9A101A531; Sun, 30 Apr 2023 16:58:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9B962166B26; Sun, 30 Apr 2023 16:58:31 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 12/19] platform/x86: lenovo-yogabook: Abstract kbd backlight setting Date: Sun, 30 Apr 2023 18:58:00 +0200 Message-Id: <20230430165807.472798-13-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Abstract kbd backlight setting. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- Changes in v2: - Keep uint8_t for level / brightness values --- drivers/platform/x86/lenovo-yogabook-wmi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 7c7a945ed80d..addc4ee457be 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -31,6 +31,7 @@ struct yogabook_wmi { struct device *dig_dev; struct led_classdev *pen_led; struct gpio_desc *backside_hall_gpio; + int (*set_kbd_backlight)(struct yogabook_wmi *data, uint8_t level); int backside_hall_irq; struct work_struct work; struct led_classdev kbd_bl_led; @@ -97,7 +98,7 @@ static void yogabook_wmi_work(struct work_struct *work) * Must be done before releasing the keyboard touchscreen driver, * so that the keyboard touchscreen dev is still in D0. */ - yogabook_wmi_set_kbd_backlight(data, 0); + data->set_kbd_backlight(data, 0); device_release_driver(data->kbd_dev); clear_bit(YB_KBD_IS_ON, &data->flags); } @@ -113,7 +114,7 @@ static void yogabook_wmi_work(struct work_struct *work) if (r) dev_warn(data->dev, "Reprobe of keyboard touchscreen failed: %d\n", r); - yogabook_wmi_set_kbd_backlight(data, data->brightness); + data->set_kbd_backlight(data, data->brightness); set_bit(YB_KBD_IS_ON, &data->flags); } @@ -182,7 +183,7 @@ static int kbd_brightness_set(struct led_classdev *cdev, if (!test_bit(YB_KBD_IS_ON, &data->flags)) return 0; - return yogabook_wmi_set_kbd_backlight(data, data->brightness); + return data->set_kbd_backlight(data, data->brightness); } static struct gpiod_lookup_table yogabook_wmi_gpios = { @@ -232,7 +233,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, data->backside_hall_irq = r; /* Set default brightness before enabling the IRQ */ - yogabook_wmi_set_kbd_backlight(data, YB_KBD_BL_DEFAULT); + data->set_kbd_backlight(data, YB_KBD_BL_DEFAULT); r = request_irq(data->backside_hall_irq, yogabook_backside_hall_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, @@ -297,6 +298,8 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) goto error_put_devs; } + data->set_kbd_backlight = yogabook_wmi_set_kbd_backlight; + r = yogabook_probe(dev, data, "ybwmi::kbd_backlight"); if (r) goto error_put_devs; @@ -355,7 +358,7 @@ static int yogabook_resume(struct device *dev) struct yogabook_wmi *data = dev_get_drvdata(dev); if (test_bit(YB_KBD_IS_ON, &data->flags)) - yogabook_wmi_set_kbd_backlight(data, data->brightness); + data->set_kbd_backlight(data, data->brightness); clear_bit(YB_SUSPENDED, &data->flags); From patchwork Sun Apr 30 16:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FFFAC7EE26 for ; Sun, 30 Apr 2023 17:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbjD3RAo (ORCPT ); Sun, 30 Apr 2023 13:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjD3RAn (ORCPT ); Sun, 30 Apr 2023 13:00:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8ACA35A7 for ; Sun, 30 Apr 2023 09:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+FarcJ0huVfvJsI1b9bZNXDNQdo9nvHGOiE6TFac9cs=; b=NTKt67OlsQe6GtExn2ULD1FgsffwTfjCw9RY9YTGTFoIL+/nu9nI0wW9dlYXvB5t3vEdaM xROc+ZHD4Fj/7vyTgJL3Azl6nhyZMqOMoWkiM72A/soNBLDpfLGhX4JusCkRgmXQc6L8cA 9PhpSB5QFEr+PVyPXZ2u18UTxz9OUho= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-131-tP4jdTvhP--RaqJ7zL4_5A-1; Sun, 30 Apr 2023 12:58:34 -0400 X-MC-Unique: tP4jdTvhP--RaqJ7zL4_5A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A85285A588; Sun, 30 Apr 2023 16:58:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3077C2166B26; Sun, 30 Apr 2023 16:58:33 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 13/19] platform/x86: lenovo-yogabook: Add a yogabook_toggle_digitizer_mode() helper function Date: Sun, 30 Apr 2023 18:58:01 +0200 Message-Id: <20230430165807.472798-14-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Add a yogabook_toggle_digitizer_mode() helper function. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index addc4ee457be..87bea6987681 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -128,10 +128,8 @@ static void yogabook_wmi_work(struct work_struct *work) } } -static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy) +static void yogabook_toggle_digitizer_mode(struct yogabook_wmi *data) { - struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); - if (test_bit(YB_SUSPENDED, &data->flags)) return; @@ -147,6 +145,11 @@ static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dumm schedule_work(&data->work); } +static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy) +{ + yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev)); +} + static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data) { struct yogabook_wmi *data = _data; From patchwork Sun Apr 30 16:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DD98C7EE23 for ; Sun, 30 Apr 2023 17:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231189AbjD3RAq (ORCPT ); Sun, 30 Apr 2023 13:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231203AbjD3RAp (ORCPT ); Sun, 30 Apr 2023 13:00:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A69E35A9 for ; Sun, 30 Apr 2023 09:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PVR7TexQKfeLS5rOEDGLj4FhW1DU+GoqAR7wL+xU1So=; b=i+MIBwIuEhlsOIJnzWJto2JKs/DfqZJXCgnucEdFYbkCc4gn5Hdliro6q0rDfl187oXSIK CZ7m+tcl2+sNGbEGKs1mI4mRDHEL7SVP9Bib1Ampug3idmaMYSHpAJHNQG8tjyE8gTHMFm 1H0W69fRSiPz8fGg7WmHhVP9US+IljY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-y2JSmfnEMv2PEXu4TUzMhA-1; Sun, 30 Apr 2023 12:58:36 -0400 X-MC-Unique: y2JSmfnEMv2PEXu4TUzMhA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95F4B2A59553; Sun, 30 Apr 2023 16:58:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DB2E2166B26; Sun, 30 Apr 2023 16:58:34 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 14/19] platform/x86: lenovo-yogabook: Drop _wmi_ from remaining generic symbols Date: Sun, 30 Apr 2023 18:58:02 +0200 Message-Id: <20230430165807.472798-15-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Change the yogabook_wmi_ prefix of remaining generic (non WMI specific) symbols to yogabook_ . This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- Changes in v2: - Add kbd_led_to_yogabook() macro --- drivers/platform/x86/lenovo-yogabook-wmi.c | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 87bea6987681..f1876c587757 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -23,7 +23,7 @@ enum { YB_SUSPENDED, }; -struct yogabook_wmi { +struct yogabook_data { struct device *dev; struct acpi_device *kbd_adev; struct acpi_device *dig_adev; @@ -31,7 +31,7 @@ struct yogabook_wmi { struct device *dig_dev; struct led_classdev *pen_led; struct gpio_desc *backside_hall_gpio; - int (*set_kbd_backlight)(struct yogabook_wmi *data, uint8_t level); + int (*set_kbd_backlight)(struct yogabook_data *data, uint8_t level); int backside_hall_irq; struct work_struct work; struct led_classdev kbd_bl_led; @@ -43,7 +43,7 @@ struct yogabook_wmi { * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI * device (Goodix touchpad acts as virtual sensor keyboard). */ -static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, +static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, uint8_t level) { struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -73,9 +73,9 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_wmi *data, return 0; } -static void yogabook_wmi_work(struct work_struct *work) +static void yogabook_work(struct work_struct *work) { - struct yogabook_wmi *data = container_of(work, struct yogabook_wmi, work); + struct yogabook_data *data = container_of(work, struct yogabook_data, work); bool kbd_on, digitizer_on; int r; @@ -128,7 +128,7 @@ static void yogabook_wmi_work(struct work_struct *work) } } -static void yogabook_toggle_digitizer_mode(struct yogabook_wmi *data) +static void yogabook_toggle_digitizer_mode(struct yogabook_data *data) { if (test_bit(YB_SUSPENDED, &data->flags)) return; @@ -152,7 +152,7 @@ static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dumm static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data) { - struct yogabook_wmi *data = _data; + struct yogabook_data *data = _data; if (gpiod_get_value(data->backside_hall_gpio)) set_bit(YB_TABLET_MODE, &data->flags); @@ -164,10 +164,11 @@ static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data) return IRQ_HANDLED; } +#define kbd_led_to_yogabook(cdev) container_of(cdev, struct yogabook_data, kbd_bl_led) + static enum led_brightness kbd_brightness_get(struct led_classdev *cdev) { - struct yogabook_wmi *data = - container_of(cdev, struct yogabook_wmi, kbd_bl_led); + struct yogabook_data *data = kbd_led_to_yogabook(cdev); return data->brightness; } @@ -175,8 +176,7 @@ static enum led_brightness kbd_brightness_get(struct led_classdev *cdev) static int kbd_brightness_set(struct led_classdev *cdev, enum led_brightness value) { - struct yogabook_wmi *data = - container_of(cdev, struct yogabook_wmi, kbd_bl_led); + struct yogabook_data *data = kbd_led_to_yogabook(cdev); if ((value < 0) || (value > 255)) return -EINVAL; @@ -189,7 +189,7 @@ static int kbd_brightness_set(struct led_classdev *cdev, return data->set_kbd_backlight(data, data->brightness); } -static struct gpiod_lookup_table yogabook_wmi_gpios = { +static struct gpiod_lookup_table yogabook_gpios = { .table = { GPIO_LOOKUP("INT33FF:02", 18, "backside_hall_sw", GPIO_ACTIVE_LOW), {} @@ -201,7 +201,7 @@ static struct led_lookup_data yogabook_pen_led = { .con_id = "pen-icon-led", }; -static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, +static int yogabook_probe(struct device *dev, struct yogabook_data *data, const char *kbd_bl_led_name) { int r; @@ -210,7 +210,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, data->brightness = YB_KBD_BL_DEFAULT; set_bit(YB_KBD_IS_ON, &data->flags); set_bit(YB_DIGITIZER_IS_ON, &data->flags); - INIT_WORK(&data->work, yogabook_wmi_work); + INIT_WORK(&data->work, yogabook_work); yogabook_pen_led.dev_id = dev_name(dev); led_add_lookup(&yogabook_pen_led); @@ -220,10 +220,10 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, if (IS_ERR(data->pen_led)) return dev_err_probe(dev, PTR_ERR(data->pen_led), "Getting pen icon LED\n"); - yogabook_wmi_gpios.dev_id = dev_name(dev); - gpiod_add_lookup_table(&yogabook_wmi_gpios); + yogabook_gpios.dev_id = dev_name(dev); + gpiod_add_lookup_table(&yogabook_gpios); data->backside_hall_gpio = devm_gpiod_get(dev, "backside_hall_sw", GPIOD_IN); - gpiod_remove_lookup_table(&yogabook_wmi_gpios); + gpiod_remove_lookup_table(&yogabook_gpios); if (IS_ERR(data->backside_hall_gpio)) return dev_err_probe(dev, PTR_ERR(data->backside_hall_gpio), @@ -269,7 +269,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_wmi *data, static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) { struct device *dev = &wdev->dev; - struct yogabook_wmi *data; + struct yogabook_data *data; int r; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); @@ -317,7 +317,7 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) return r; } -static void yogabook_remove(struct yogabook_wmi *data) +static void yogabook_remove(struct yogabook_data *data) { int r = 0; @@ -336,7 +336,7 @@ static void yogabook_remove(struct yogabook_wmi *data) static void yogabook_wmi_remove(struct wmi_device *wdev) { - struct yogabook_wmi *data = dev_get_drvdata(&wdev->dev); + struct yogabook_data *data = dev_get_drvdata(&wdev->dev); yogabook_remove(data); @@ -348,7 +348,7 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) static int yogabook_suspend(struct device *dev) { - struct yogabook_wmi *data = dev_get_drvdata(dev); + struct yogabook_data *data = dev_get_drvdata(dev); set_bit(YB_SUSPENDED, &data->flags); @@ -358,7 +358,7 @@ static int yogabook_suspend(struct device *dev) static int yogabook_resume(struct device *dev) { - struct yogabook_wmi *data = dev_get_drvdata(dev); + struct yogabook_data *data = dev_get_drvdata(dev); if (test_bit(YB_KBD_IS_ON, &data->flags)) data->set_kbd_backlight(data, data->brightness); From patchwork Sun Apr 30 16:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4654C7EE21 for ; Sun, 30 Apr 2023 17:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229478AbjD3RBU (ORCPT ); Sun, 30 Apr 2023 13:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjD3RBT (ORCPT ); Sun, 30 Apr 2023 13:01:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8CA3A85 for ; Sun, 30 Apr 2023 09:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YHxn+EYB8bEJntnB5GyXCcUrS6A/Gr/OSshXvA47i2I=; b=VWCzX979LWkeQBoTLqfUNBHOb0O4j4BG2bgM6IKrSrmaoJO3x+cP7b5icsLiBUfSP7OfVE af3REyLhnfZFifkXNygJhxvuB0s8VLXWxApn8orO1ZNH0r/9rtkd2O5xvzQ4pZEB8MYEhN hSzW81V5WGVOnZ3a5/rXlTz3dscfrGQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-uq4PmadpN4qB0voG-M10_w-1; Sun, 30 Apr 2023 12:58:37 -0400 X-MC-Unique: uq4PmadpN4qB0voG-M10_w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1D3C3C0ED4B; Sun, 30 Apr 2023 16:58:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8D522166B26; Sun, 30 Apr 2023 16:58:35 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 15/19] platform/x86: lenovo-yogabook: Group WMI specific code together Date: Sun, 30 Apr 2023 18:58:03 +0200 Message-Id: <20230430165807.472798-16-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Group WMI specific code together. Note this just moves a bunch of code-blocks around, not a single line is changed. This is a preparation patch for making lenovo-yogabook-wmi also work on the Android version of the Yoga Book 1 which does not have a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 162 ++++++++++----------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index f1876c587757..c0c6997b9f61 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -39,40 +39,6 @@ struct yogabook_data { uint8_t brightness; }; -/* - * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI - * device (Goodix touchpad acts as virtual sensor keyboard). - */ -static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, - uint8_t level) -{ - struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_object_list input; - union acpi_object param; - acpi_status status; - - dev_dbg(data->dev, "Set KBLC level to %u\n", level); - - /* Ensure keyboard touchpad is on before we call KBLC() */ - acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); - - input.count = 1; - input.pointer = ¶m; - - param.type = ACPI_TYPE_INTEGER; - param.integer.value = 255 - level; - - status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC", - &input, &output); - if (ACPI_FAILURE(status)) { - dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status); - return status; - } - - kfree(output.pointer); - return 0; -} - static void yogabook_work(struct work_struct *work) { struct yogabook_data *data = container_of(work, struct yogabook_data, work); @@ -145,11 +111,6 @@ static void yogabook_toggle_digitizer_mode(struct yogabook_data *data) schedule_work(&data->work); } -static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy) -{ - yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev)); -} - static irqreturn_t yogabook_backside_hall_irq(int irq, void *_data) { struct yogabook_data *data = _data; @@ -266,6 +227,84 @@ static int yogabook_probe(struct device *dev, struct yogabook_data *data, return r; } +static void yogabook_remove(struct yogabook_data *data) +{ + int r = 0; + + free_irq(data->backside_hall_irq, data); + cancel_work_sync(&data->work); + + if (!test_bit(YB_KBD_IS_ON, &data->flags)) + r |= device_reprobe(data->kbd_dev); + + if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags)) + r |= device_reprobe(data->dig_dev); + + if (r) + dev_warn(data->dev, "Reprobe of devices failed\n"); +} + +static int yogabook_suspend(struct device *dev) +{ + struct yogabook_data *data = dev_get_drvdata(dev); + + set_bit(YB_SUSPENDED, &data->flags); + + flush_work(&data->work); + return 0; +} + +static int yogabook_resume(struct device *dev) +{ + struct yogabook_data *data = dev_get_drvdata(dev); + + if (test_bit(YB_KBD_IS_ON, &data->flags)) + data->set_kbd_backlight(data, data->brightness); + + clear_bit(YB_SUSPENDED, &data->flags); + + /* Check for YB_TABLET_MODE changes made during suspend */ + schedule_work(&data->work); + + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume); + +/* + * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI + * device (Goodix touchpad acts as virtual sensor keyboard). + */ +static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, + uint8_t level) +{ + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_object_list input; + union acpi_object param; + acpi_status status; + + dev_dbg(data->dev, "Set KBLC level to %u\n", level); + + /* Ensure keyboard touchpad is on before we call KBLC() */ + acpi_device_set_power(data->kbd_adev, ACPI_STATE_D0); + + input.count = 1; + input.pointer = ¶m; + + param.type = ACPI_TYPE_INTEGER; + param.integer.value = 255 - level; + + status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC", + &input, &output); + if (ACPI_FAILURE(status)) { + dev_err(data->dev, "Failed to call KBLC method: 0x%x\n", status); + return status; + } + + kfree(output.pointer); + return 0; +} + static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) { struct device *dev = &wdev->dev; @@ -317,23 +356,6 @@ static int yogabook_wmi_probe(struct wmi_device *wdev, const void *context) return r; } -static void yogabook_remove(struct yogabook_data *data) -{ - int r = 0; - - free_irq(data->backside_hall_irq, data); - cancel_work_sync(&data->work); - - if (!test_bit(YB_KBD_IS_ON, &data->flags)) - r |= device_reprobe(data->kbd_dev); - - if (!test_bit(YB_DIGITIZER_IS_ON, &data->flags)) - r |= device_reprobe(data->dig_dev); - - if (r) - dev_warn(data->dev, "Reprobe of devices failed\n"); -} - static void yogabook_wmi_remove(struct wmi_device *wdev) { struct yogabook_data *data = dev_get_drvdata(&wdev->dev); @@ -346,29 +368,9 @@ static void yogabook_wmi_remove(struct wmi_device *wdev) acpi_dev_put(data->kbd_adev); } -static int yogabook_suspend(struct device *dev) -{ - struct yogabook_data *data = dev_get_drvdata(dev); - - set_bit(YB_SUSPENDED, &data->flags); - - flush_work(&data->work); - return 0; -} - -static int yogabook_resume(struct device *dev) +static void yogabook_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy) { - struct yogabook_data *data = dev_get_drvdata(dev); - - if (test_bit(YB_KBD_IS_ON, &data->flags)) - data->set_kbd_backlight(data, data->brightness); - - clear_bit(YB_SUSPENDED, &data->flags); - - /* Check for YB_TABLET_MODE changes made during suspend */ - schedule_work(&data->work); - - return 0; + yogabook_toggle_digitizer_mode(dev_get_drvdata(&wdev->dev)); } static const struct wmi_device_id yogabook_wmi_id_table[] = { @@ -377,8 +379,7 @@ static const struct wmi_device_id yogabook_wmi_id_table[] = { }, { } /* Terminating entry */ }; - -static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume); +MODULE_DEVICE_TABLE(wmi, yogabook_wmi_id_table); static struct wmi_driver yogabook_wmi_driver = { .driver = { @@ -393,7 +394,6 @@ static struct wmi_driver yogabook_wmi_driver = { }; module_wmi_driver(yogabook_wmi_driver); -MODULE_DEVICE_TABLE(wmi, yogabook_wmi_id_table); MODULE_AUTHOR("Yauhen Kharuzhy"); MODULE_DESCRIPTION("Lenovo Yoga Book WMI driver"); MODULE_LICENSE("GPL v2"); From patchwork Sun Apr 30 16:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0743C7EE24 for ; Sun, 30 Apr 2023 17:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbjD3RAr (ORCPT ); Sun, 30 Apr 2023 13:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjD3RAq (ORCPT ); Sun, 30 Apr 2023 13:00:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC3FD35B1 for ; Sun, 30 Apr 2023 09:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/1n74BbC/XLCNWwnyUU0jCRRJYN14mXJtJBdobArEOw=; b=PxV4Wg4FqfbgKZp0uj7AJPF9y2BNC+o22xMVJwPur5b0XIcjYUE9OyaxBAJDdnPue7EKi4 GDVM0ohZ3oXAd/dvg/9isAuesoymX/CJy5lBD1sQSTsZQOOpqZzPTvRvxYP0LUozmIJbpd OcQ6DF+WkPgQ8cy6dBqXTnVw1+cq3y0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-3JGaNXPEM8qCG3Ad-XJtfQ-1; Sun, 30 Apr 2023 12:58:38 -0400 X-MC-Unique: 3JGaNXPEM8qCG3Ad-XJtfQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3854B101A531; Sun, 30 Apr 2023 16:58:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 202BE2166B26; Sun, 30 Apr 2023 16:58:37 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 16/19] platform/x86: lenovo-yogabook: Add YB_KBD_BL_MAX define Date: Sun, 30 Apr 2023 18:58:04 +0200 Message-Id: <20230430165807.472798-17-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Add a define for the max brightness level instead of hardcoding this to 255 in multiple places. Signed-off-by: Hans de Goede --- drivers/platform/x86/lenovo-yogabook-wmi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index c0c6997b9f61..f413af41e3c0 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -12,7 +12,8 @@ #define YB_MBTN_EVENT_GUID "243FEC1D-1963-41C1-8100-06A9D82A94B4" -#define YB_KBD_BL_DEFAULT 128 +#define YB_KBD_BL_DEFAULT 128 +#define YB_KBD_BL_MAX 255 /* flags */ enum { @@ -139,7 +140,7 @@ static int kbd_brightness_set(struct led_classdev *cdev, { struct yogabook_data *data = kbd_led_to_yogabook(cdev); - if ((value < 0) || (value > 255)) + if ((value < 0) || (value > YB_KBD_BL_MAX)) return -EINVAL; data->brightness = value; @@ -210,7 +211,7 @@ static int yogabook_probe(struct device *dev, struct yogabook_data *data, data->kbd_bl_led.name = kbd_bl_led_name; data->kbd_bl_led.brightness_set_blocking = kbd_brightness_set; data->kbd_bl_led.brightness_get = kbd_brightness_get; - data->kbd_bl_led.max_brightness = 255; + data->kbd_bl_led.max_brightness = YB_KBD_BL_MAX; r = devm_led_classdev_register(dev, &data->kbd_bl_led); if (r < 0) { @@ -292,7 +293,7 @@ static int yogabook_wmi_set_kbd_backlight(struct yogabook_data *data, input.pointer = ¶m; param.type = ACPI_TYPE_INTEGER; - param.integer.value = 255 - level; + param.integer.value = YB_KBD_BL_MAX - level; status = acpi_evaluate_object(acpi_device_handle(data->kbd_adev), "KBLC", &input, &output); From patchwork Sun Apr 30 16:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF562C7EE25 for ; Sun, 30 Apr 2023 17:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbjD3RAp (ORCPT ); Sun, 30 Apr 2023 13:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231184AbjD3RAn (ORCPT ); Sun, 30 Apr 2023 13:00:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E2CB3A84 for ; Sun, 30 Apr 2023 09:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8/uuKsiCeKwUAmdNTojaP58o37PBpkrS4yfaiIq/3o=; b=doh8HgpCWumC/upM879706RHetIHth9fO1E8IR7eIS7AqUQcvxQrHwcnArMCoBF0EyzBUP keoC2BmJrO/F8UdCLTt2pvOyGYk116A0kR3qKfCp+I89l0BjfspgqQ9vDFExg6MQVVSuEO yXMFU/tunEE/9lTcWelEdtsWbuNQZKQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-346-iywYBAGXPdCyedIsQIQa0g-1; Sun, 30 Apr 2023 12:58:40 -0400 X-MC-Unique: iywYBAGXPdCyedIsQIQa0g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86E65A0F387; Sun, 30 Apr 2023 16:58:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D1F42166B26; Sun, 30 Apr 2023 16:58:38 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 17/19] platform/x86: lenovo-yogabook: Add platform driver support Date: Sun, 30 Apr 2023 18:58:05 +0200 Message-Id: <20230430165807.472798-18-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The Lenovo Yoga Book 1 comes in 2 versions. Version 1: The yb1-x91f/l currently supported by lenovo-yogabook-wmi, which has a WMI interface to deal with toggling the keyboard half between touch-keyboard and wacom-digitizer mode. Version 2: The yb1-x90f/l which is the same hardware shipping with Android as factory OS. This version has a very different BIOS and ACPI tables which lack the WMI interface. Instead the x86-android-tablets.ko code which does devices instantiation for devices missing from ACPI on various x86 Android tablets will instantiate a platform device for the keyboard half touch-kbd/digitizer toggle functionality. This patch adds a platform driver to the lenovo-yogabook code which binds to the platform device instantiated by x86-android-tablets.ko offering touch-kbd/digitizer toggle functionality on the Android model. Signed-off-by: Hans de Goede --- Changes in v2: - Use r = dev_err_probe(...) in various places - Error-exit handling fixes in yogabook_pdev_probe() and yogabook_module_init() --- drivers/platform/x86/lenovo-yogabook-wmi.c | 164 ++++++++++++++++++++- 1 file changed, 160 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index f413af41e3c0..0183b75a47e8 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -1,12 +1,24 @@ // SPDX-License-Identifier: GPL-2.0 -/* WMI driver for Lenovo Yoga Book YB1-X90* / -X91* tablets */ +/* + * Platform driver for Lenovo Yoga Book YB1-X90F/L tablets (Android model) + * WMI driver for Lenovo Yoga Book YB1-X91F/L tablets (Windows model) + * + * The keyboard half of the YB1 models can function as both a capacitive + * touch keyboard or as a Wacom digitizer, but not at the same time. + * + * This driver takes care of switching between the 2 functions. + * + * Copyright 2023 Hans de Goede + */ #include #include #include +#include #include -#include #include +#include +#include #include #include @@ -15,6 +27,8 @@ #define YB_KBD_BL_DEFAULT 128 #define YB_KBD_BL_MAX 255 +#define YB_PDEV_NAME "yogabook-touch-kbd-digitizer-switch" + /* flags */ enum { YB_KBD_IS_ON, @@ -31,8 +45,11 @@ struct yogabook_data { struct device *kbd_dev; struct device *dig_dev; struct led_classdev *pen_led; + struct gpio_desc *pen_touch_event; + struct gpio_desc *kbd_bl_led_enable; struct gpio_desc *backside_hall_gpio; int (*set_kbd_backlight)(struct yogabook_data *data, uint8_t level); + int pen_touch_irq; int backside_hall_irq; struct work_struct work; struct led_classdev kbd_bl_led; @@ -272,6 +289,8 @@ static int yogabook_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(yogabook_pm_ops, yogabook_suspend, yogabook_resume); +/********** WMI driver code **********/ + /* * To control keyboard backlight, call the method KBLC() of the TCS1 ACPI * device (Goodix touchpad acts as virtual sensor keyboard). @@ -393,8 +412,145 @@ static struct wmi_driver yogabook_wmi_driver = { .remove = yogabook_wmi_remove, .notify = yogabook_wmi_notify, }; -module_wmi_driver(yogabook_wmi_driver); +/********** platform driver code **********/ + +static struct gpiod_lookup_table yogabook_pdev_gpios = { + .dev_id = YB_PDEV_NAME, + .table = { + GPIO_LOOKUP("INT33FF:00", 95, "pen_touch_event", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("INT33FF:03", 52, "enable_keyboard_led", GPIO_ACTIVE_HIGH), + {} + }, +}; + +static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level) +{ + gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0); + return 0; +} + +static irqreturn_t yogabook_pen_touch_irq(int irq, void *data) +{ + yogabook_toggle_digitizer_mode(data); + return IRQ_HANDLED; +} + +static int yogabook_pdev_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct yogabook_data *data; + int r; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (data == NULL) + return -ENOMEM; + + data->kbd_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-goodix_ts"); + if (!data->kbd_dev || !data->kbd_dev->driver) { + r = -EPROBE_DEFER; + goto error_put_devs; + } + + data->dig_dev = bus_find_device_by_name(&i2c_bus_type, NULL, "i2c-wacom"); + if (!data->dig_dev || !data->dig_dev->driver) { + r = -EPROBE_DEFER; + goto error_put_devs; + } + + gpiod_add_lookup_table(&yogabook_pdev_gpios); + data->pen_touch_event = devm_gpiod_get(dev, "pen_touch_event", GPIOD_IN); + data->kbd_bl_led_enable = devm_gpiod_get(dev, "enable_keyboard_led", GPIOD_OUT_HIGH); + gpiod_remove_lookup_table(&yogabook_pdev_gpios); + + if (IS_ERR(data->pen_touch_event)) { + r = dev_err_probe(dev, PTR_ERR(data->pen_touch_event), + "Getting pen_touch_event GPIO\n"); + goto error_put_devs; + } + + if (IS_ERR(data->kbd_bl_led_enable)) { + r = dev_err_probe(dev, PTR_ERR(data->kbd_bl_led_enable), + "Getting enable_keyboard_led GPIO\n"); + goto error_put_devs; + } + + r = gpiod_to_irq(data->pen_touch_event); + if (r < 0) { + dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n"); + goto error_put_devs; + } + data->pen_touch_irq = r; + + r = request_irq(data->pen_touch_irq, yogabook_pen_touch_irq, IRQF_TRIGGER_FALLING, + "pen_touch_event", data); + if (r) { + dev_err_probe(dev, r, "Requesting pen_touch_event IRQ\n"); + goto error_put_devs; + } + + data->set_kbd_backlight = yogabook_pdev_set_kbd_backlight; + + r = yogabook_probe(dev, data, "yogabook::kbd_backlight"); + if (r) + goto error_free_irq; + + return 0; + +error_free_irq: + free_irq(data->pen_touch_irq, data); + cancel_work_sync(&data->work); +error_put_devs: + put_device(data->dig_dev); + put_device(data->kbd_dev); + return r; +} + +static void yogabook_pdev_remove(struct platform_device *pdev) +{ + struct yogabook_data *data = platform_get_drvdata(pdev); + + yogabook_remove(data); + free_irq(data->pen_touch_irq, data); + cancel_work_sync(&data->work); + put_device(data->dig_dev); + put_device(data->kbd_dev); +} + +static struct platform_driver yogabook_pdev_driver = { + .probe = yogabook_pdev_probe, + .remove_new = yogabook_pdev_remove, + .driver = { + .name = YB_PDEV_NAME, + .pm = pm_sleep_ptr(&yogabook_pm_ops), + }, +}; + +static int __init yogabook_module_init(void) +{ + int r; + + r = wmi_driver_register(&yogabook_wmi_driver); + if (r) + return r; + + r = platform_driver_register(&yogabook_pdev_driver); + if (r) + wmi_driver_unregister(&yogabook_wmi_driver); + + return r; +} + +static void __exit yogabook_module_exit(void) +{ + platform_driver_unregister(&yogabook_pdev_driver); + wmi_driver_unregister(&yogabook_wmi_driver); +} + +module_init(yogabook_module_init); +module_exit(yogabook_module_exit); + +MODULE_ALIAS("platform:" YB_PDEV_NAME); MODULE_AUTHOR("Yauhen Kharuzhy"); -MODULE_DESCRIPTION("Lenovo Yoga Book WMI driver"); +MODULE_DESCRIPTION("Lenovo Yoga Book driver"); MODULE_LICENSE("GPL v2"); From patchwork Sun Apr 30 16:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8386CC7EE24 for ; Sun, 30 Apr 2023 17:01:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbjD3RBY (ORCPT ); Sun, 30 Apr 2023 13:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjD3RBY (ORCPT ); Sun, 30 Apr 2023 13:01:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA1E3A86 for ; Sun, 30 Apr 2023 09:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CM1fKYx1KiYBHGTxfG6gfnt6X+KPTwf3j2MNI0Aw5ts=; b=RZDQyPFCpL5hjxk9U1jYqWsPuKfVyTEA6TAK0KVrqVXjOfrO1VZycTE6z2g5DHplGnH/IY gn49I2QUWqxKSX0vWt/Uea+rjleaw0woPN9UwQwllLV21sjaSy3FigwNJ2A7f1wMY4Csjj FkK63qdGy7MaFph+rnTcW0NAOQ9vB1Y= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-601-Gr8aawj3Nea0H_xbH-INxg-1; Sun, 30 Apr 2023 12:58:42 -0400 X-MC-Unique: Gr8aawj3Nea0H_xbH-INxg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D86EF3C0ED4B; Sun, 30 Apr 2023 16:58:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9D902166B26; Sun, 30 Apr 2023 16:58:39 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 18/19] platform/x86: lenovo-yogabook: Add keyboard backlight control to platform driver Date: Sun, 30 Apr 2023 18:58:06 +0200 Message-Id: <20230430165807.472798-19-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org On the Android yb1-x90f/l models there is not ACPI method to control the keyboard backlight brightness. Instead the second PWM controller is exposed directly to the OS there. Add support for controlling keyboard backlight brightness on the Android model by using the PWM subsystem to directly control the PWM. The Android model also requires explicitly turning the backlight off on suspend, which on the Windows model was done automatically. Signed-off-by: Hans de Goede --- Changes in v2: - Use YB_KBD_BL_PWM_PERIOD define in yogabook_pdev_pwm_lookup[] - Turn off keyboard backlight on suspend --- drivers/platform/x86/lenovo-yogabook-wmi.c | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook-wmi.c index 0183b75a47e8..b49109d91ec3 100644 --- a/drivers/platform/x86/lenovo-yogabook-wmi.c +++ b/drivers/platform/x86/lenovo-yogabook-wmi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,7 @@ #define YB_KBD_BL_DEFAULT 128 #define YB_KBD_BL_MAX 255 +#define YB_KBD_BL_PWM_PERIOD 13333 #define YB_PDEV_NAME "yogabook-touch-kbd-digitizer-switch" @@ -48,6 +50,7 @@ struct yogabook_data { struct gpio_desc *pen_touch_event; struct gpio_desc *kbd_bl_led_enable; struct gpio_desc *backside_hall_gpio; + struct pwm_device *kbd_bl_pwm; int (*set_kbd_backlight)(struct yogabook_data *data, uint8_t level); int pen_touch_irq; int backside_hall_irq; @@ -267,8 +270,11 @@ static int yogabook_suspend(struct device *dev) struct yogabook_data *data = dev_get_drvdata(dev); set_bit(YB_SUSPENDED, &data->flags); - flush_work(&data->work); + + if (test_bit(YB_KBD_IS_ON, &data->flags)) + data->set_kbd_backlight(data, 0); + return 0; } @@ -424,8 +430,21 @@ static struct gpiod_lookup_table yogabook_pdev_gpios = { }, }; +static struct pwm_lookup yogabook_pdev_pwm_lookup[] = { + PWM_LOOKUP_WITH_MODULE("80862289:00", 0, YB_PDEV_NAME, "kbd_bl_pwm", + YB_KBD_BL_PWM_PERIOD, PWM_POLARITY_NORMAL, + "pwm-lpss-platform"), +}; + static int yogabook_pdev_set_kbd_backlight(struct yogabook_data *data, u8 level) { + struct pwm_state state = { + .period = YB_KBD_BL_PWM_PERIOD, + .duty_cycle = YB_KBD_BL_PWM_PERIOD * level / YB_KBD_BL_MAX, + .enabled = level, + }; + + pwm_apply_state(data->kbd_bl_pwm, &state); gpiod_set_value(data->kbd_bl_led_enable, level ? 1 : 0); return 0; } @@ -475,6 +494,16 @@ static int yogabook_pdev_probe(struct platform_device *pdev) goto error_put_devs; } + pwm_add_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup)); + data->kbd_bl_pwm = devm_pwm_get(dev, "kbd_bl_pwm"); + pwm_remove_table(yogabook_pdev_pwm_lookup, ARRAY_SIZE(yogabook_pdev_pwm_lookup)); + + if (IS_ERR(data->kbd_bl_pwm)) { + r = dev_err_probe(dev, PTR_ERR(data->kbd_bl_pwm), + "Getting keyboard backlight PWM\n"); + goto error_put_devs; + } + r = gpiod_to_irq(data->pen_touch_event); if (r < 0) { dev_err_probe(dev, r, "Getting pen_touch_event IRQ\n"); From patchwork Sun Apr 30 16:58:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13227231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BB3EC7EE23 for ; Sun, 30 Apr 2023 17:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjD3RBV (ORCPT ); Sun, 30 Apr 2023 13:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjD3RBU (ORCPT ); Sun, 30 Apr 2023 13:01:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9AE3A95 for ; Sun, 30 Apr 2023 09:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FJiw9NzT9K0INdo4+f0MqL/Z4a7dmUaUvTLN8FJpYSU=; b=DV+BGrfDBa+7d7+RjHsAdhfDFfA44WqRKbz9oh3NY9PGkRwGWyowUhEgulUN3JOibhG0zF 4+WjdnXk5zZVcNoXlT6dwJp4/86HIQNccg8vGeu77aqrHJ4cU8ustjwwlVfWecZhW71tQV 6PA3gh65/X+lV35O6Hiyin6feMccjV4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-3a5UH9ogM2m1LeItfg_rzA-1; Sun, 30 Apr 2023 12:58:43 -0400 X-MC-Unique: 3a5UH9ogM2m1LeItfg_rzA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39E0B3C0ED4F; Sun, 30 Apr 2023 16:58:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1689C2166B26; Sun, 30 Apr 2023 16:58:41 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Hans de Goede , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org Subject: [PATCH v2 19/19] platform/x86: lenovo-yogabook: Rename lenovo-yogabook-wmi to lenovo-yogabook Date: Sun, 30 Apr 2023 18:58:07 +0200 Message-Id: <20230430165807.472798-20-hdegoede@redhat.com> In-Reply-To: <20230430165807.472798-1-hdegoede@redhat.com> References: <20230430165807.472798-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The lenovo-yogabook-wmi.c code now consists of both a platform and a WMI driver and it does not use WMI at all when used on the Android model. Rename the module from lenovo-yogabook-wmi to lenovo-yogabook to reflect this. Signed-off-by: Hans de Goede --- drivers/platform/x86/Kconfig | 6 +++--- drivers/platform/x86/Makefile | 2 +- .../x86/{lenovo-yogabook-wmi.c => lenovo-yogabook.c} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename drivers/platform/x86/{lenovo-yogabook-wmi.c => lenovo-yogabook.c} (100%) diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 22052031c719..2039e3246e1b 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -121,8 +121,8 @@ config GIGABYTE_WMI To compile this driver as a module, choose M here: the module will be called gigabyte-wmi. -config YOGABOOK_WMI - tristate "Lenovo Yoga Book tablet WMI key driver" +config YOGABOOK + tristate "Lenovo Yoga Book tablet key driver" depends on ACPI_WMI depends on INPUT select LEDS_CLASS @@ -132,7 +132,7 @@ config YOGABOOK_WMI control on the Lenovo Yoga Book tablets. To compile this driver as a module, choose M here: the module will - be called lenovo-yogabook-wmi. + be called lenovo-yogabook. config ACERHDF tristate "Acer Aspire One temperature and fan driver" diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 2cafe51ec4d8..52dfdf574ac2 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -14,7 +14,6 @@ obj-$(CONFIG_MXM_WMI) += mxm-wmi.o obj-$(CONFIG_NVIDIA_WMI_EC_BACKLIGHT) += nvidia-wmi-ec-backlight.o obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o obj-$(CONFIG_GIGABYTE_WMI) += gigabyte-wmi.o -obj-$(CONFIG_YOGABOOK_WMI) += lenovo-yogabook-wmi.o # Acer obj-$(CONFIG_ACERHDF) += acerhdf.o @@ -66,6 +65,7 @@ obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o +obj-$(CONFIG_YOGABOOK) += lenovo-yogabook.o # Intel obj-y += intel/ diff --git a/drivers/platform/x86/lenovo-yogabook-wmi.c b/drivers/platform/x86/lenovo-yogabook.c similarity index 100% rename from drivers/platform/x86/lenovo-yogabook-wmi.c rename to drivers/platform/x86/lenovo-yogabook.c