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: 1775362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hNSksyL3; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XcW49sLz1ydW for ; Mon, 1 May 2023 02:59:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbjD3Q7D (ORCPT ); Sun, 30 Apr 2023 12:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbjD3Q7C (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 76F911BFF for ; Sun, 30 Apr 2023 09:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873900; 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=hNSksyL3wWt5bOXvCfL6paVn/unOUIrZSGzeIenOpbao49G7rpddIg72zKQHPU6RVlm5/d 9jvEFRLcTv6vBpo9B2RUN884ft+Um0re9BgVURVi/4ZqHyTR3Apz+izW7JEscCkC8+JVe+ zjQoPGjbXQD2RXz+tW/ON+bd5wI1LYI= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ASQvurTY; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XdM60JWz1ydW for ; Mon, 1 May 2023 02:59:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbjD3Q7u (ORCPT ); Sun, 30 Apr 2023 12:59:50 -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 S230479AbjD3Q7s (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 6FA0E2729 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=hPUodKH8f+H/JW+lPIMV3CIdr4U3egsnh7kn3ioo34Q=; b=ASQvurTYRNGgEbAFrvcf0ReMjDxOdkvpDPW2nk9lWhTQdhwsHIIXCllS3JCC2y5ztgr+49 OMCDxacsibJ9ek4ywyIlOPyWzh7YrMRGjZe57F4AobMJuvM9QweAsozNL7Gir7ZptApEPM 5Z8ImVVMDQnLc39xcvGfo1zGQlbkQME= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UChKb/W/; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XcZ4k4Qz1ydW for ; Mon, 1 May 2023 02:59:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230432AbjD3Q7K (ORCPT ); Sun, 30 Apr 2023 12:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjD3Q7J (ORCPT ); Sun, 30 Apr 2023 12:59:09 -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 051432693 for ; Sun, 30 Apr 2023 09:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873906; 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=UChKb/W/g0U7Z3TD05I9spceAzXQ2SpToJMYjfthZ249fC6RHMmT9VoqGN6QwuE/ZqEsHf 1d0QcxUW/1rDDi8EuV/QOry4iHpHcBzXpgR5jngaKBs1oPm1uAFYza61bNxRb3q/4z7ghy +CVcUz4RnMIgjqzIVeDJwpi2rLgiib8= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775367 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=jWZPshW/; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XdN5Jl9z1ydW for ; Mon, 1 May 2023 02:59:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjD3Q7v (ORCPT ); Sun, 30 Apr 2023 12:59:51 -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 S230483AbjD3Q7s (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FEEE269E for ; Sun, 30 Apr 2023 09:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873906; 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=jWZPshW/qAIMDbMqtvuK2Z4GYtNV25Czc2SaF6KkQym5imHBAG5kDqvI3IwhKfLXe/xvf6 aAAL43xcIf4eotkNk4CtY2T2wqLE3cAHasi449bXUajQV990nEMG10Eel0THV/s13SpInJ PNoCeeC7tObEXo7++a9IpFU6AHehXVM= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GMVJl7Yh; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XdT1zc3z1ydW for ; Mon, 1 May 2023 02:59:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231131AbjD3Q74 (ORCPT ); Sun, 30 Apr 2023 12:59:56 -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 S229850AbjD3Q74 (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 9A4EF2D67 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gEl1nbjx; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XdN2DzBz1ydY for ; Mon, 1 May 2023 02:59:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230512AbjD3Q7t (ORCPT ); Sun, 30 Apr 2023 12:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbjD3Q7r (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.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 252022D48 for ; Sun, 30 Apr 2023 09:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873910; 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=gEl1nbjxGIolJyy9gFWoNp599g0ZabzsjZ7g/bxeyIUfXeacIWQ70zxepp6zM4Bjkvw5JY rcjnWdSkBihli6akAogoPBQ6riIie6AwbrAObJ5bfb6M1lVlAIpdFdwUqDkmvaPw4UjdAk kbEoNTL4TvaQD0n7JVsA0YGyivbyxWk= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GsEXT1qi; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfG6ZLkz1ydY for ; Mon, 1 May 2023 03:00:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231244AbjD3RAi (ORCPT ); Sun, 30 Apr 2023 13:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjD3RAg (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2AFB30ED for ; Sun, 30 Apr 2023 09:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873915; 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=GsEXT1qiaX4+LAzp23MO1lXt0G1l2u/VnwrBnfWutn9fKlNGftfwdJNE1sgmD2GaPXMLxq gvuOdtvhNaj2ujbeJK7Or4pBOceXdi+lXO9wm0HEc7h4T4ZI57QyOY+FPYbEQG8dmYNF+/ yGX7zN96UnR81ficJiUv8KmSfN4/u28= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775373 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ABcrmPh/; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfH2WvVz1ydX for ; Mon, 1 May 2023 03:00:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbjD3RAi (ORCPT ); Sun, 30 Apr 2023 13:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbjD3RAg (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A88A830D7 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=Fc0o4FmfepKkzUDJlnn+iIoOvetPn6yXTjCkGtCtkSw=; b=ABcrmPh/NG+iu+wX9EI0qNoIUkv/izdd0LwvgRLcV6UTcpA7xU1xD6GiMlY6GZ6XgcSToj WMJKGdrY90PSxnCzEcDiaZN4v+iGX8q5+oBnEpWHUkxEVimrY7Su5O+UPVkRxMBCr0g7GB bo58FOtTH/lIO3IAjIz/rXMgXUvvpak= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VpWBLB27; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfD702lz1ydX for ; Mon, 1 May 2023 03:00:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbjD3RAg (ORCPT ); Sun, 30 Apr 2023 13:00:36 -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 S229556AbjD3RAf (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 A355230DD 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=7ZA6DXgyTXvwIadThlqTV1A5YcEulIvzodUVYHO63jc=; b=VpWBLB27vLMYwLOTT6tRnIKfn55yUAI57AU9ujvfJZgBLdv2Hvo0IZ7iSVhbjNo6ppa1ZO d1eYhzn6T2IyHIwCJrafn9p2YqJpy7K392JThhvGSoO1ItlJSNdJuQLH74bZ5MaqPRT/We n8IMrJmmz43/tN9mdBQDxBA6wcZmfVc= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NUnxA9AL; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfF5qFPz1ydY for ; Mon, 1 May 2023 03:00:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231216AbjD3RAh (ORCPT ); Sun, 30 Apr 2023 13:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbjD3RAg (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 5BB1535A4 for ; Sun, 30 Apr 2023 09:58:38 -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=VXHwsCXKeMn1KRwGbgqGGqTyQsRETIoDYs3QhSTfM0c=; b=NUnxA9ALUctgzPkSk/9+41q5glVdxdJzwx0dM9ypzIO0XiKKcXFBQL9d+/51g3RnW4Tjfl bVnu68bxY7dXA62xQk2kwzWHLbPvWIjkW0GJzVMcHbpFs3foYXL5y0FhLoCWpHW1qdJIaV dp8jLMCWQtoimoiG7qx6Hput48sgCzg= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=acaofeEz; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfG37Q1z1ydX for ; Mon, 1 May 2023 03:00:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbjD3RAh (ORCPT ); Sun, 30 Apr 2023 13:00:37 -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 S229556AbjD3RAg (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F0D30F1 for ; Sun, 30 Apr 2023 09:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873915; 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=acaofeEziAJ+8ZFvDB2x2lL/QGwNbBVimIStoONxkWyeVz46olWkpAyd7QVivOfxLV0E0S VjZOKiF9MmqzgmRWPxP2ljOYjuuohVy84Sx7kDLS3PxAYdU1muRSPzRSzILC5nh16TUEdO H/1z8iQsKFnm1aJzSOjQ9ZF4KoDk1SA= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QQwUeYfa; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfJ49kgz1ydX for ; Mon, 1 May 2023 03:00:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjD3RAj (ORCPT ); Sun, 30 Apr 2023 13:00:39 -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 S231223AbjD3RAh (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.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29C6C30EE for ; Sun, 30 Apr 2023 09:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873915; 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=QQwUeYfaaLftQ676te7KRoCwr9ZBcl5xr+GbaW8JtCbF71LQOVAK697sQIa3GastrVpm6F hl8Bbd29G68XuOw/F7bXPOq4rLMguzq45TS5eT3r8Binqgu9TObE1LGynk8ERgjcfvCUyH Eo7mIAwXTgdRKJNvEui7r5DxYtkCXak= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R5S47x4V; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfL3yS9z1ydX for ; Mon, 1 May 2023 03:00:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231166AbjD3RAl (ORCPT ); Sun, 30 Apr 2023 13:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjD3RAi (ORCPT ); Sun, 30 Apr 2023 13:00:38 -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 09ADF3581 for ; Sun, 30 Apr 2023 09:58:36 -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=+FarcJ0huVfvJsI1b9bZNXDNQdo9nvHGOiE6TFac9cs=; b=R5S47x4VNr16wBgjyEyEx4ZNT5em8aTddKguVxouSaAZ8cruwrvpErG0VY0f9WNY/MAAvY FgQxsE/HhiUmtsZdFB0KXZ4po0ptPf65c9wzMZLZXxsE6baodDjiuPHqZ/512EDegYi3p9 ewfmaslA/Lw8uAeMrMh97/Lt+vTI5XM= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dwt9EEfT; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfQ3kLQz1ydX for ; Mon, 1 May 2023 03:00:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbjD3RAp (ORCPT ); Sun, 30 Apr 2023 13:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbjD3RAo (ORCPT ); Sun, 30 Apr 2023 13:00:44 -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 5BBC435B0 for ; Sun, 30 Apr 2023 09:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682873920; 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=dwt9EEfTNr+CGqU2gRMLSKqg5Hhx8z/fd7/8NNogL5MS/PSJP2AVpoj4CMALJmLViKQBr/ AFlqC3jMNMa6reOXPZfmBTM3p5zH4xJ2XietKn/MDAb+mWX/+srWwq9txses/YJkMmFtXd cBhAo/YzTlBzvYCjnuJQX+ZlunayEmA= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=V1/H2nJ5; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfR3SHfz1ydY for ; Mon, 1 May 2023 03:00:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbjD3RAq (ORCPT ); Sun, 30 Apr 2023 13:00:46 -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 S231202AbjD3RAp (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 7823635A8 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=YHxn+EYB8bEJntnB5GyXCcUrS6A/Gr/OSshXvA47i2I=; b=V1/H2nJ5ehrCLjmCZhEyg+ovhJCHrfV+2hapV2FrbwHGj1VwIrUYonJdZErM0xExFQfUYn xbCkOsKM0gdD6Q13exv8/HWU7ay+zjp/DeB4CsvPixg+hWYL11SnnGh86t/LoGX8xPCH2T IXMnKq7k08j8UX27W+Fs/xuhIl8e2jU= 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PxV4Wg4F; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfS6rbBz1ydX for ; Mon, 1 May 2023 03:00:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231202AbjD3RAr (ORCPT ); Sun, 30 Apr 2023 13:00:47 -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 S231221AbjD3RAp (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D181D35B5 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=doh8HgpC; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8XfP33z9z1ymX for ; Mon, 1 May 2023 03:00:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbjD3RAo (ORCPT ); Sun, 30 Apr 2023 13:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjD3RAn (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 361E635B8 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RZDQyPFC; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8Xg93NwNz1ydX for ; Mon, 1 May 2023 03:01:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230512AbjD3RBY (ORCPT ); Sun, 30 Apr 2023 13:01:24 -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 S230340AbjD3RBY (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 206A33A92 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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: 1775380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DV+BGrfD; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Q8Xg729G9z1ydX for ; Mon, 1 May 2023 03:01:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjD3RBU (ORCPT ); Sun, 30 Apr 2023 13:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjD3RBT (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.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3053A93 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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pwm@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