Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp350702imm; Mon, 4 Jun 2018 19:20:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLy0EUnTs4rLvVyKoICmw1/jYSJBS/pO1T2a4jeuI45V0RkcRnvHQPVKv1d2jl2pTqZlwas X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr23961813plu.22.1528165205544; Mon, 04 Jun 2018 19:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528165205; cv=none; d=google.com; s=arc-20160816; b=z8SvVFDWzrqHQmysvQVSlagKiMdQBBi+99OIk22dAftCM/w9FjWCvT6OCl09cjHHk7 Ev3oC+lFuaN05s5IV77z4rEgB/EuhSfGFsyCG61VMg+n0CKKlMxhPCxNtiDzxkE3lcTW nPtHQBGTupuNUkpEdbZRQQQzPMCRDX1x8qC4XjwJ4rCgerDcK5zzg7eqTXdM59kQuu6C nvvXWIoOTbZdrZuF5b+juPKGvg/xXlHejutH4/Fqm1wTvtSgnqA5WJCcAjpffLtfIq16 n2j8waaf/qbBHNt/vfKueSuxZfyx3br818oflu4SAUFWUEvzmLAjdbxmDaOJ+oFWwAUg NV3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=KvVZvNub8BvPj276A+313GY6FxcspRgKu3Byvt/F21g=; b=mE8O8CN0rheSnANRoAHES2yILR3CpnN4Z9baKfJEsv09FAWma3Ajh7uxoILa/q0sJY Q4Qkn8TCEVPRl0/RK11VXy0e0bemVyVUJt154zk1Ku6QaxVaFpMrdDzMbsxa+tiXX50v iRYT+UhQ2JuwWy19VXu3Fy3J1Eeip9gBdVQz53zdGxYDiTRNdayyrwXXJok/ioThNde1 GWOEObEoh4tHqwm687MTUeQJRZ0lVmoIBXZLx3pO2ufQNxEFYCIURYysy3OdmJ/9kDU2 ICIzQrc3Vhgic7AoguAzYfcs04IiIsykOYm1mtGlj+I2NS7KFgm7lSO1fMIUeiCj0DR5 kOxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WlRX0oUM; 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 r25-v6si13141009pff.24.2018.06.04.19.19.51; Mon, 04 Jun 2018 19:20:05 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WlRX0oUM; 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 S1751495AbeFECR4 (ORCPT + 99 others); Mon, 4 Jun 2018 22:17:56 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:43646 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751223AbeFECRy (ORCPT ); Mon, 4 Jun 2018 22:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KvVZvNub8BvPj276A+313GY6FxcspRgKu3Byvt/F21g=; b=WlRX0oUM8lBdBPHvFUScujEA2 MbovKRKT99sj80cJ9a5BAnv3xC3+1Knp0pS1WAXfYYb0+HwBkECHZ3FuQHq6pZ4TnqMeRf+l4j3/s adl6V3rb/qsOpRVdKpyKHXEmSAv9evA0ronKnr1z15t3jpEhn010vk802xVdpznBPXVhjHZR2LXT7 fPrZh361F/j1QngY+mEr9qeo+Ew+AWwMPr2bjSnkKLXmYLa2vtEXkmkAALH16xjmrEMFYU+bG5lMl 2fhoR7rP6beB0F/DoERwSiXwCHn6WfAw1aqnOlT7Y1CiUEeFdMkkSG++BMp7elMZf+JmCPkN/eVa0 kYx9pdw2Q==; Received: from dvhart by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fQ1Xl-0006Zf-G0; Tue, 05 Jun 2018 02:17:53 +0000 Date: Mon, 4 Jun 2018 19:17:51 -0700 From: Darren Hart To: Chris Chiu Cc: corentin.chary@gmail.com, andy.shevchenko@gmail.com, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, acpi4asus-user@lists.sourceforge.net, hdegoede@redhat.com, linux@endlessm.com Subject: Re: [PATCH 1/2] platform/x86: asus-wmi: Call new led hw_changed API on kbd brightness change Message-ID: <20180605021751.GD47042@localhost.localdomain> References: <20180604123238.82200-1-chiu@endlessm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180604123238.82200-1-chiu@endlessm.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 04, 2018 at 08:32:37PM +0800, Chris Chiu wrote: > 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; I don't think this is worth breaking out into a separate function. This isn't exactly a hot path, but I don't think this makes the code any more readable really. The is_display_toggle was comparing 8 values in a complex logic statement, so we don't need to follow that for something this simple. > +} > + > 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) Seems like we could eliminate the extra function and eliminate a level of indentation by rewriting this as: if (code == NOTIFY_KBD_BRTDWN) kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1); else if (code == NOTIFY_KBD_BRTUP) kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1); if (code == NOTIFY_KBD_BRTDWN || NOTIFY_KBD_BRTUP) goto exit; Or, just treat them as separate events: if (code == NOTIFY_KBD_BRTDWN) { kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1); goto exit; } if (code == NOTIFY_KBD_BRTUP) { 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 > > -- Darren Hart VMware Open Source Technology Center