Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3548656imm; Mon, 4 Jun 2018 05:34:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIwpW0Z/NNVrsYFh7vG8TwifuEbzpsMbq4gYx28nGLQD3P2CGTP2G3CINc/m8RALAb4MTJj X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr21723221plc.248.1528115677692; Mon, 04 Jun 2018 05:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528115677; cv=none; d=google.com; s=arc-20160816; b=HM97VIQKnc6AfDh2zTXLDbAnSKvGbMtPRFUNWQGzunHGI6K31hQdiIr/6kNCvTrXF9 jzWtX5BvbCTbML+gYkF6X30ggJmU3/6UCD/9L2tbio7QGDCdP2tYMD0GwJYYiMAuqkq0 Tn6ga7pU2AYFZx2xIzmvvUNkV+Cjsw/OjJuY4cfT8q1/gXnC3Ti96mFZeWyA4eMHrifc HW5AMbIHhaPODL/pjDn3cJR3MCjDd5lqdsjX/8NIoCIkhoXaVR3lx/lG1EA7MRLUl57m iCcGon9iMTo62NsILGQbC8l9DbBLrK4lomxQUldQQl0go85c3rCzUFpWalFsnQS7Vryr 7lNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=uMnDBtNY7QIWVMxZwVfrCQm6kZDonoQ4tiNAO0gG7uk=; b=k6nIzYY4V+ivN7e5PYFk+UvMAl3oiVdgq8ea+0TI3MOCGHKO9gAE0xjRJPRaQfKhS4 y9tL/B5Xnvx/d6kyhFW7ZvZTwwXYIxFpUX7IeIyL0/nOQLul65KZhDiXW7RuXlquT5k3 gYdK7xnbQHBE2+DAP302loxyRHFmkVAMDmvOoCuYhvvt4O0FjHLV9VxMZuGB53cl32/d b96FnkqOkIC3Efjkf8yn5E2oqXi2DAl0DxkYVtcqE5VVB6+20aPO74vLKMZQSoU5hcut qaUp11lVD8VIDVxAkGYhJn4TtR/LZbPwmaqQI5gPPTIgOn0pKF/wiCH8vinEMSeF4+fY MXzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@endlessm-com.20150623.gappssmtp.com header.s=20150623 header.b=qBBfbrmY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si45737357plt.325.2018.06.04.05.34.22; Mon, 04 Jun 2018 05:34:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@endlessm-com.20150623.gappssmtp.com header.s=20150623 header.b=qBBfbrmY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752643AbeFDMcy (ORCPT + 99 others); Mon, 4 Jun 2018 08:32:54 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34483 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751473AbeFDMcw (ORCPT ); Mon, 4 Jun 2018 08:32:52 -0400 Received: by mail-pf0-f194.google.com with SMTP id a63-v6so2454703pfl.1 for ; Mon, 04 Jun 2018 05:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=endlessm-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=uMnDBtNY7QIWVMxZwVfrCQm6kZDonoQ4tiNAO0gG7uk=; b=qBBfbrmYwzRmSv63aveh1IR2jmyTSWPSRP6ECqzoPA39jYfuuFdMCdlF97hEuV15wY J2C7tRdB5BOZlmMZfK3+T5KmDj0q0RtlWG+o0FmWb1NH7jHXAKgkT+s6rS4w1S3ItGB1 CsYiGkTnyGR3YHWZIFz9rlYQaBePFlMg0gBt40kVEBG0iUMm9PkarYizOT7kmv+/8R52 oYqeklmbFaQeffQq+rdhjJWKwQ7mqJWTZjiit67JRqfTFq6YBu9X4czpH9hA2mC5zmC/ NzPub5AULfLdsVW8Mpj3eX5+0ACaT1cfzv70kF7XNXODx688lmYSboQDK/gMvOGvlNhz Kkzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uMnDBtNY7QIWVMxZwVfrCQm6kZDonoQ4tiNAO0gG7uk=; b=KxvhWcyYeLozPmhoeG9bUPx0/GERXN9njRxRg5gJLBtYmp7BnDKPV9nR7sWla/dl/0 RA6BNKiDtrethHTe4WAza8wf6USy0oemkHP8qEkIN5GaJvMD5QhkC6Bj+fabC/R0W+zK Wu8tJHKcM0A9xTT/bCOyV480vWofU5y87jerttwbGU6Kwz8FT5YZ1shQRBGC370BYdEz RELAzLeWemMlPdelQQjJ7P8woUrEf1/gmaC4pK8Q7U0mqBl097xbdGH9e8CJiGQR9CaX b2WmuehQkdvXLu/Mvqaoq6XtJgL3EQlcnS6+O58Gbtv7fmmipb+Yu5DTNjYzpX+qf63T AAgQ== X-Gm-Message-State: ALKqPwf93M6q3l+EpkUU17yUNMs5PkPHgh6BjtGI4TFsGOizHzoXYxGl EQDKIDx5a4jI63b/smymVTjjzFkW X-Received: by 2002:a62:67c5:: with SMTP id t66-v6mr17047401pfj.20.1528115572323; Mon, 04 Jun 2018 05:32:52 -0700 (PDT) Received: from localhost.localdomain (123-204-46-122.static.seed.net.tw. [123.204.46.122]) by smtp.gmail.com with ESMTPSA id x124-v6sm12573033pgb.53.2018.06.04.05.32.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Jun 2018 05:32:51 -0700 (PDT) From: Chris Chiu To: corentin.chary@gmail.com, dvhart@infradead.org, andy.shevchenko@gmail.com Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, acpi4asus-user@lists.sourceforge.net, hdegoede@redhat.com, linux@endlessm.com, Chris Chiu Subject: [PATCH 1/2] platform/x86: asus-wmi: Call new led hw_changed API on kbd brightness change Date: Mon, 4 Jun 2018 20:32:37 +0800 Message-Id: <20180604123238.82200-1-chiu@endlessm.com> X-Mailer: git-send-email 2.15.1 (Apple Git-101) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. For this purpose, bound check on brightness in kbd_led_set must be based on the same data type to prevent illegal value been set. Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping. Signed-off-by: Chris Chiu --- drivers/platform/x86/asus-nb-wmi.c | 2 -- drivers/platform/x86/asus-wmi.c | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c index 136ff2b4cce5..7ce80e4bb5a3 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -493,8 +493,6 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0xA6, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + TV + HDMI */ { KE_KEY, 0xA7, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + TV + HDMI */ { KE_KEY, 0xB5, { KEY_CALC } }, - { KE_KEY, 0xC4, { KEY_KBDILLUMUP } }, - { KE_KEY, 0xC5, { KEY_KBDILLUMDOWN } }, { KE_IGNORE, 0xC6, }, /* Ambient Light Sensor notification */ { KE_END, 0}, }; diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 1f6e68f0b646..b4915b7718c1 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -460,6 +460,7 @@ static void kbd_led_update(struct work_struct *work) ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F); asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL); + led_classdev_notify_brightness_hw_changed(&asus->kbd_led, asus->kbd_led_wk); } static int kbd_led_read(struct asus_wmi *asus, int *level, int *env) @@ -497,9 +498,9 @@ static void kbd_led_set(struct led_classdev *led_cdev, asus = container_of(led_cdev, struct asus_wmi, kbd_led); - if (value > asus->kbd_led.max_brightness) + if ((int)value > (int)asus->kbd_led.max_brightness) value = asus->kbd_led.max_brightness; - else if (value < 0) + else if ((int)value < 0) value = 0; asus->kbd_led_wk = value; @@ -656,6 +657,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus) asus->kbd_led_wk = led_val; asus->kbd_led.name = "asus::kbd_backlight"; + asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED; asus->kbd_led.brightness_set = kbd_led_set; asus->kbd_led.brightness_get = kbd_led_get; asus->kbd_led.max_brightness = 3; @@ -1700,6 +1702,13 @@ static int is_display_toggle(int code) return 0; } +static int is_kbd_led_event(int code) +{ + if (code == NOTIFY_KBD_BRTUP || code == NOTIFY_KBD_BRTDWN) + return 1; + return 0; +} + static void asus_wmi_notify(u32 value, void *context) { struct asus_wmi *asus = context; @@ -1745,6 +1754,14 @@ static void asus_wmi_notify(u32 value, void *context) } } + if (is_kbd_led_event(code)) { + if (code == NOTIFY_KBD_BRTDWN) + kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1); + else + kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1); + goto exit; + } + if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) goto exit; -- 2.11.0