From patchwork Wed Feb 26 09:31:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13991886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1D6BC021B8 for ; Wed, 26 Feb 2025 09:38:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7EE8310E8AF; Wed, 26 Feb 2025 09:38:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="ehkG7AlV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ExYHKTyI"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ehkG7AlV"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ExYHKTyI"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id B9CE810E8A7 for ; Wed, 26 Feb 2025 09:38:18 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 444FA1F76C; Wed, 26 Feb 2025 09:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1740562668; h=from:from:reply-to: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=euaJJrBEvXrsayPUWNFICMnLQe7WLRzeLyK8ZiHq0ek=; b=ehkG7AlV+a9KgdoWyRtzDqmAmG6BPn6RfyW6ueAA46lovtD8UMU+4yyL73o2vi7dxHzM5N BXOUPab5G6DG2iFHiBt45ZpyJy11o/Ie9RAAQfGIAhOX78uoMpWaoYqEXMS7JPNJ8JG1aj G1tucCl+xW1NMnAA7+a1Ex27SvObuYI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1740562668; h=from:from:reply-to: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=euaJJrBEvXrsayPUWNFICMnLQe7WLRzeLyK8ZiHq0ek=; b=ExYHKTyImBVCMU7pVdhVV+hYa1ofxP1CidKoMLqKzSty8uiW2JQCenecmHOfzqOFqWVGAJ bECzx1NWNgHampDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1740562668; h=from:from:reply-to: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=euaJJrBEvXrsayPUWNFICMnLQe7WLRzeLyK8ZiHq0ek=; b=ehkG7AlV+a9KgdoWyRtzDqmAmG6BPn6RfyW6ueAA46lovtD8UMU+4yyL73o2vi7dxHzM5N BXOUPab5G6DG2iFHiBt45ZpyJy11o/Ie9RAAQfGIAhOX78uoMpWaoYqEXMS7JPNJ8JG1aj G1tucCl+xW1NMnAA7+a1Ex27SvObuYI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1740562668; h=from:from:reply-to: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=euaJJrBEvXrsayPUWNFICMnLQe7WLRzeLyK8ZiHq0ek=; b=ExYHKTyImBVCMU7pVdhVV+hYa1ofxP1CidKoMLqKzSty8uiW2JQCenecmHOfzqOFqWVGAJ bECzx1NWNgHampDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id F15C813A53; Wed, 26 Feb 2025 09:37:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0PWgOevgvmezXQAAD6G6ig (envelope-from ); Wed, 26 Feb 2025 09:37:47 +0000 From: Thomas Zimmermann To: lee@kernel.org, pavel@ucw.cz, danielt@kernel.org, jingoohan1@gmail.com, deller@gmx.de, simona@ffwll.ch Cc: linux-leds@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Thomas Zimmermann Subject: [PATCH v2 10/11] leds: backlight trigger: Replace fb events with a dedicated function call Date: Wed, 26 Feb 2025 10:31:59 +0100 Message-ID: <20250226093456.147402-11-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226093456.147402-1-tzimmermann@suse.de> References: <20250226093456.147402-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_TO(0.00)[kernel.org,ucw.cz,gmail.com,gmx.de,ffwll.ch]; RCPT_COUNT_SEVEN(0.00)[10]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; R_RATELIMIT(0.00)[to_ip_from(RLqirfcw6gnbcr9a9yhi49fhi6)]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FREEMAIL_ENVRCPT(0.00)[gmail.com,gmx.de] X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Remove support for fb events from the led backlight trigger. Provide the helper ledtrig_backlight_blank() instead. Call it from fbdev to inform the trigger of changes to a display's blank state. Fbdev maintains a list of all installed notifiers. Instead of the fbdev notifiers, maintain an internal list of led backlight triggers. v2: - maintain global list of led backlight triggers (Lee) - avoid IS_REACHABLE() in source file (Lee) - notify on changes to blank state instead of display state - use lock guards - initialize led list and list mutex Signed-off-by: Thomas Zimmermann --- drivers/leds/trigger/ledtrig-backlight.c | 41 +++++++++--------------- drivers/video/fbdev/core/fbmem.c | 19 +++++------ include/linux/leds.h | 6 ++++ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c index 8e66d55a6c82..2d351de81927 100644 --- a/drivers/leds/trigger/ledtrig-backlight.c +++ b/drivers/leds/trigger/ledtrig-backlight.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "../leds.h" @@ -21,10 +20,14 @@ struct bl_trig_notifier { struct led_classdev *led; int brightness; int old_status; - struct notifier_block notifier; unsigned invert; + + struct list_head entry; }; +static DEFINE_MUTEX(ledtrig_backlight_list_mutex); +static LIST_HEAD(ledtrig_backlight_list); + static void ledtrig_backlight_notify_blank(struct bl_trig_notifier *n, int new_status) { struct led_classdev *led = n->led; @@ -42,25 +45,15 @@ static void ledtrig_backlight_notify_blank(struct bl_trig_notifier *n, int new_s n->old_status = new_status; } -static int fb_notifier_callback(struct notifier_block *p, - unsigned long event, void *data) +void ledtrig_backlight_blank(bool blank) { - struct bl_trig_notifier *n = container_of(p, - struct bl_trig_notifier, notifier); - struct fb_event *fb_event = data; - int *blank; - int new_status; - - /* If we aren't interested in this event, skip it immediately ... */ - if (event != FB_EVENT_BLANK) - return 0; - - blank = fb_event->data; - new_status = *blank ? BLANK : UNBLANK; + struct bl_trig_notifier *n; + int new_status = blank ? BLANK : UNBLANK; - ledtrig_backlight_notify_blank(n, new_status); + guard(mutex)(&ledtrig_backlight_list_mutex); - return 0; + list_for_each_entry(n, &ledtrig_backlight_list, entry) + ledtrig_backlight_notify_blank(n, new_status); } static ssize_t bl_trig_invert_show(struct device *dev, @@ -106,8 +99,6 @@ ATTRIBUTE_GROUPS(bl_trig); static int bl_trig_activate(struct led_classdev *led) { - int ret; - struct bl_trig_notifier *n; n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL); @@ -118,11 +109,9 @@ static int bl_trig_activate(struct led_classdev *led) n->led = led; n->brightness = led->brightness; n->old_status = UNBLANK; - n->notifier.notifier_call = fb_notifier_callback; - ret = fb_register_client(&n->notifier); - if (ret) - dev_err(led->dev, "unable to register backlight trigger\n"); + guard(mutex)(&ledtrig_backlight_list_mutex); + list_add(&n->entry, &ledtrig_backlight_list); return 0; } @@ -131,7 +120,9 @@ static void bl_trig_deactivate(struct led_classdev *led) { struct bl_trig_notifier *n = led_get_trigger_data(led); - fb_unregister_client(&n->notifier); + guard(mutex)(&ledtrig_backlight_list_mutex); + list_del(&n->entry); + kfree(n); } diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 001662c606d7..f089f72ec75a 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -16,6 +16,7 @@ #include #include #include +#include #include