From patchwork Mon Nov 23 17:51:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Azael Avalos X-Patchwork-Id: 7684711 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5D53CBF90C for ; Mon, 23 Nov 2015 17:51:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74CE6207BD for ; Mon, 23 Nov 2015 17:51:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A13A207B8 for ; Mon, 23 Nov 2015 17:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932179AbbKWRvi (ORCPT ); Mon, 23 Nov 2015 12:51:38 -0500 Received: from mail-oi0-f49.google.com ([209.85.218.49]:33276 "EHLO mail-oi0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751514AbbKWRvg (ORCPT ); Mon, 23 Nov 2015 12:51:36 -0500 Received: by oixx65 with SMTP id x65so135135689oix.0; Mon, 23 Nov 2015 09:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=xk5rylHcRYXG+rsTr/cH3R1G9UXYZ0XJJxpZTxFKV4c=; b=LL0za/HRVL1uH+f3McLNi6YjjKXl31SxN8QHLFLpyQkJO1weNnC6br+qWq3THOz5bF xSIAq7vmOZcxC84o9AYMGokj3DHnO63vJGHnWBfaiYcrZj4fSAtxDoSAbpbwAkzMCKX+ j/FQ25sF+2OndtQ6C4x04O9EM1F/4XzAO+Vdi+vcUrU5TkOlIDsnOJSJwwjPsQY8T4o7 Almg48YBilDhPBnUKq6enKbXK/K+vLS0WWYAN4Co1dM8jYLTWYTqCSMfz5yPIZz/QojP N3WhZOGxqgErFuaMp0y87/W6uUUB5mCQFvhU00bjOOkBxMdzw9nu36BOixJHoApjWiNa g5gg== X-Received: by 10.60.33.232 with SMTP id u8mr18272199oei.22.1448301095961; Mon, 23 Nov 2015 09:51:35 -0800 (PST) Received: from Shakuras.scurra.org ([148.210.109.74]) by smtp.gmail.com with ESMTPSA id wu6sm4238794obb.16.2015.11.23.09.51.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Nov 2015 09:51:35 -0800 (PST) From: Azael Avalos To: Darren Hart , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Azael Avalos Subject: [PATCH v2] toshiba_acpi: Fix keyboard backight sysfs entries not being updated Date: Mon, 23 Nov 2015 10:51:30 -0700 Message-Id: <1448301090-5545-1-git-send-email-coproscefalo@gmail.com> X-Mailer: git-send-email 2.6.3 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Certain Toshiba models with the second generation keyboard backlight (type 2) do not generate the keyboard backlight changed event (0x92), and thus, the sysfs entries are never being updated. This patch adds a workquee and a global boolean variable to address the issue. For those models that do generate the event, the sysfs entries are being updated via the *notify function and the boolean is set to true to avoid a second call to update the entries. For those models that do not generate the event, the workquee is used to update the sysfs entries and also to emulate the event via netlink, to make userspace aware of such change. Signed-off-by: Azael Avalos --- Changes since v1: - Moved the implementation of the toshiba_acpi_kbd_bl_work function further down to make the file compile drivers/platform/x86/toshiba_acpi.c | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index df2612e..410bacc 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -206,6 +206,7 @@ struct toshiba_acpi_dev { unsigned int sysfs_created:1; unsigned int special_functions; + bool kbd_event_generated; bool kbd_led_registered; bool illumination_led_registered; bool eco_led_registered; @@ -523,6 +524,7 @@ static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) dev->kbd_illum_supported = 0; dev->kbd_led_registered = false; + dev->kbd_event_generated = false; if (!sci_open(dev)) return; @@ -1642,6 +1644,11 @@ static const struct backlight_ops toshiba_backlight_data = { .update_status = set_lcd_status, }; +/* Keyboard backlight work */ +static void toshiba_acpi_kbd_bl_work(struct work_struct *work); + +static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work); + /* * Sysfs files */ @@ -1741,6 +1748,24 @@ static ssize_t kbd_backlight_mode_store(struct device *dev, return ret; toshiba->kbd_mode = mode; + + /* + * Some laptop models with the second generation backlit + * keyboard (type 2) do not generate the keyboard backlight + * changed event (0x92), and thus, the driver will never update + * the sysfs entries. + * + * The event is generated right when changing the keyboard + * backlight mode and the *notify function will set the + * kbd_event_generated to true. + * + * In case the event is not generated, schedule the keyboard + * backlight work to update the sysfs entries and emulate the + * event via genetlink. + */ + if (toshiba->kbd_type == 2 && + !toshiba_acpi->kbd_event_generated) + schedule_work(&kbd_bl_work); } return count; @@ -2273,6 +2298,21 @@ static struct attribute_group toshiba_attr_group = { .attrs = toshiba_attributes, }; +static void toshiba_acpi_kbd_bl_work(struct work_struct *work) +{ + struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev; + + /* Update the sysfs entries */ + if (sysfs_update_group(&acpi_dev->dev.kobj, + &toshiba_attr_group)) + pr_err("Unable to update sysfs entries\n"); + + /* Emulate the keyboard backlight event */ + acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class, + dev_name(&acpi_dev->dev), + 0x92, 0); +} + /* * Misc device */ @@ -2871,7 +2911,6 @@ error: static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) { struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); - int ret; switch (event) { case 0x80: /* Hotkeys and some system events */ @@ -2901,10 +2940,10 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) pr_info("SATA power event received %x\n", event); break; case 0x92: /* Keyboard backlight mode changed */ + toshiba_acpi->kbd_event_generated = true; /* Update sysfs entries */ - ret = sysfs_update_group(&acpi_dev->dev.kobj, - &toshiba_attr_group); - if (ret) + if (sysfs_update_group(&acpi_dev->dev.kobj, + &toshiba_attr_group)) pr_err("Unable to update sysfs entries\n"); break; case 0x85: /* Unknown */