From patchwork Thu Feb 6 15:30:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 863675 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10BA91E5B80; Thu, 6 Feb 2025 15:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; cv=none; b=e8JO1c6rRfpfPs1lUgHjc7Vsq9djk9yR6tO7RbFFdyYv1ejd34PTyk98Ibu1+jAmD30m6X1Q6Qa4675dNaCKtmc46EIk0Mus7QoZ/nmivmdbHKSf74W+QPBpa28SDHY1OxDS+M+fFINaVAFu8OxJxso9a5m8sDxKl0KM7c//QkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; c=relaxed/simple; bh=MK3deRCClPKJMwnY3MZxzmHu0zeIe1KWhrUJmiP1gWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uZRcK7ntIOjJ7dHtKRQ7Y8fzeSeY47Hd0xTjFrzPWoJbYe8dDOYTtPxtXAHFpgOCSXRPjmwGndTELFMd5FJMVPjBqg9j5N9kXDsxzYag+eX6TZ9jR99/1dHndg+MLe+Ct8CtLhhA5huhTO+KociRW+DSxAiqh5HaWEqDrq4t/q4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 5C3091F381; Thu, 6 Feb 2025 15:40:44 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 1930F13A7F; Thu, 6 Feb 2025 15:40:44 +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 CDn7BPzXpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:44 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 01/13] fbdev: Rework fb_blank() Date: Thu, 6 Feb 2025 16:30:20 +0100 Message-ID: <20250206154033.697495-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: 5C3091F381 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org Reimplement fb_blank() to return early on errors. No functional changes. Prepares the helper for tracking the blanking state in struct fb_info. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbmem.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 3c568cff2913..39e2b81473ad 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -339,11 +339,13 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) } EXPORT_SYMBOL(fb_set_var); -int -fb_blank(struct fb_info *info, int blank) +int fb_blank(struct fb_info *info, int blank) { struct fb_event event; - int ret = -EINVAL; + int ret; + + if (!info->fbops->fb_blank) + return -EINVAL; if (blank > FB_BLANK_POWERDOWN) blank = FB_BLANK_POWERDOWN; @@ -351,13 +353,13 @@ fb_blank(struct fb_info *info, int blank) event.info = info; event.data = ␣ - if (info->fbops->fb_blank) - ret = info->fbops->fb_blank(blank, info); + ret = info->fbops->fb_blank(blank, info); + if (ret) + return ret; - if (!ret) - fb_notifier_call_chain(FB_EVENT_BLANK, &event); + fb_notifier_call_chain(FB_EVENT_BLANK, &event); - return ret; + return 0; } EXPORT_SYMBOL(fb_blank); From patchwork Thu Feb 6 15:30:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 862714 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F12C22687B; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; cv=none; b=D+jyLnTxfWLsVExGW+qn0fqTMYVfg2cUShTJOg5PWOQD9yeW3VmHTC20qcXDpBEOyPVHjn6PyuPIzRqxBGCCMKjqlmXNa0J7/KaIYArz+Z2frzKa86AVe7tnk4ljcjIA4pQVcFpMQbUzlDOxfr9FY94skUGMI4JFeyVrk9oJL/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; c=relaxed/simple; bh=lEHO8cPxOHgiyqw1BN6YASGJMa3mKuS98zFtBR5PFd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GxshVOe4Wywz+MYzpC7rTZrzJmjVFZ99IuWD73BQSf63E8q8wwTPv5HRreuvdm59H57sn2n+NaFtpa4JRFsnsDW+UPmp6waZqIXH9RsGaP5iCsLK5MkB/WxHMfjHd6ySOtoMs9RdkNkP56b9AYuIY3n7E8u7owziRbNEkANtb+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tHHBaBCn; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=EtETu2tL; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=tHHBaBCn; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=EtETu2tL; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tHHBaBCn"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EtETu2tL"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="tHHBaBCn"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EtETu2tL" 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 A34691F397; Thu, 6 Feb 2025 15:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856444; 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=AkRKfhGCu+O+pvIPPmAHUbgG/tWWQRPaR8J6kROTrAU=; b=tHHBaBCnCnJGQCeHz5htZmAkTxXnWTN+MhXidMp5CRH0HKou2ERQY7Jm8X2VO1UrFP9Anl FyfEygh4cmHSImJKFpjRsP3BHTAacs2ZIyac+TiH3IHP9R4+ruWIGHM0o5sAZmF/WvPtDy hlkF9d0Ax598aUxy7bciwtFZhgwzyAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856444; 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=AkRKfhGCu+O+pvIPPmAHUbgG/tWWQRPaR8J6kROTrAU=; b=EtETu2tLUACZUSJDIdcRPMHjos2ViYOWPlgtk8srGTgsDTjfB3yiGO81V/Mi3n3xLLxQnQ VJq2Q1p/xs3+BXDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856444; 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=AkRKfhGCu+O+pvIPPmAHUbgG/tWWQRPaR8J6kROTrAU=; b=tHHBaBCnCnJGQCeHz5htZmAkTxXnWTN+MhXidMp5CRH0HKou2ERQY7Jm8X2VO1UrFP9Anl FyfEygh4cmHSImJKFpjRsP3BHTAacs2ZIyac+TiH3IHP9R4+ruWIGHM0o5sAZmF/WvPtDy hlkF9d0Ax598aUxy7bciwtFZhgwzyAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856444; 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=AkRKfhGCu+O+pvIPPmAHUbgG/tWWQRPaR8J6kROTrAU=; b=EtETu2tLUACZUSJDIdcRPMHjos2ViYOWPlgtk8srGTgsDTjfB3yiGO81V/Mi3n3xLLxQnQ VJq2Q1p/xs3+BXDQ== 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 6228113697; Thu, 6 Feb 2025 15:40:44 +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 MBjEFvzXpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:44 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 02/13] fbdev: Track display blanking state Date: Thu, 6 Feb 2025 16:30:21 +0100 Message-ID: <20250206154033.697495-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -6.80 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_SEVEN(0.00)[10]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[ucw.cz,kernel.org,gmail.com,gmx.de,ffwll.ch]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com,gmx.de] X-Spam-Flag: NO X-Spam-Level: Store the display's blank status in struct fb_info.blank and track it in fb_blank(). As an extra, the status is now available from the sysfs blank attribute. Support for blanking is optional. Therefore framebuffer_alloc() initializes the state to FB_BLANK_UNBLANK (i.e., the display is on). If the fb_blank callback has been set, register_framebuffer() sets the state to FB_BLANK_POWERDOWN. On the first modeset, the call to fb_blank() will update it to _UNBLANK. This is important, as listeners to FB_EVENT_BLANK will now see the display being switched on. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fb_info.c | 1 + drivers/video/fbdev/core/fbmem.c | 17 ++++++++++++++++- drivers/video/fbdev/core/fbsysfs.c | 8 ++++---- include/linux/fb.h | 2 ++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/core/fb_info.c b/drivers/video/fbdev/core/fb_info.c index 4847ebe50d7d..52f9bd2c5417 100644 --- a/drivers/video/fbdev/core/fb_info.c +++ b/drivers/video/fbdev/core/fb_info.c @@ -42,6 +42,7 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev) info->device = dev; info->fbcon_rotate_hint = -1; + info->blank = FB_BLANK_UNBLANK; #if IS_ENABLED(CONFIG_FB_BACKLIGHT) mutex_init(&info->bl_curve_mutex); diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 39e2b81473ad..f34a80c7fc3a 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -341,6 +341,7 @@ EXPORT_SYMBOL(fb_set_var); int fb_blank(struct fb_info *info, int blank) { + int old_blank = info->blank; struct fb_event event; int ret; @@ -353,13 +354,19 @@ int fb_blank(struct fb_info *info, int blank) event.info = info; event.data = ␣ + info->blank = blank; + ret = info->fbops->fb_blank(blank, info); if (ret) - return ret; + goto err; fb_notifier_call_chain(FB_EVENT_BLANK, &event); return 0; + +err: + info->blank = old_blank; + return ret; } EXPORT_SYMBOL(fb_blank); @@ -408,6 +415,14 @@ static int do_register_framebuffer(struct fb_info *fb_info) mutex_init(&fb_info->lock); mutex_init(&fb_info->mm_lock); + /* + * With an fb_blank callback present, we assume that the + * display blank, so that fb_blank() enables it on the first + * modeset. + */ + if (fb_info->fbops->fb_blank) + fb_info->blank = FB_BLANK_POWERDOWN; + fb_device_create(fb_info); if (fb_info->pixmap.addr == NULL) { diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c index 1b3c9958ef5c..e337660bce46 100644 --- a/drivers/video/fbdev/core/fbsysfs.c +++ b/drivers/video/fbdev/core/fbsysfs.c @@ -242,11 +242,11 @@ static ssize_t store_blank(struct device *device, return count; } -static ssize_t show_blank(struct device *device, - struct device_attribute *attr, char *buf) +static ssize_t show_blank(struct device *device, struct device_attribute *attr, char *buf) { -// struct fb_info *fb_info = dev_get_drvdata(device); - return 0; + struct fb_info *fb_info = dev_get_drvdata(device); + + return sysfs_emit(buf, "%d\n", fb_info->blank); } static ssize_t store_console(struct device *device, diff --git a/include/linux/fb.h b/include/linux/fb.h index 5ba187e08cf7..f41d3334ac23 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -471,6 +471,8 @@ struct fb_info { struct list_head modelist; /* mode list */ struct fb_videomode *mode; /* current mode */ + int blank; /* current blanking; see FB_BLANK_ constants */ + #if IS_ENABLED(CONFIG_FB_BACKLIGHT) /* assigned backlight device */ /* set before framebuffer registration, From patchwork Thu Feb 6 15:30:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 862715 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F0A3226865; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; cv=none; b=ia5+gxj9qQeQgYwW4f0O1Ig1mhfZ/mXmHOp+RkPbPfdVms0Jud7WLgZqIhXA1Vd5SzOnszdchTYyeS6uI1upRSimWGp6SAxZxGEsISAcYTMpP5COnVfr87m+ZhZRuiYwh4bADjEzH2sfgQ69KZDS6eZeWyt4fElRW8Q+uv4khdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; c=relaxed/simple; bh=H4pQIAj9JZLlRVVSxo51FtA2TsA3DWh7IANh0St97y8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LAfbCMW3XxTlmToCqKdK08plgO8YSIgFo0Aj5adhsSpsgJ+u8aTBwqayIcaZwIDikCU80wTGQQ/fsHABuEjKwca/qUbVwPkMB1bZz5Zgjad6kacfLhlkLcvEMtEyfE+dEmNtcixwjHwW2KoggJ4//gQ9kg5gseHMKVKAIyDPeLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 01F851F449; Thu, 6 Feb 2025 15:40:45 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 A8EE713A7F; Thu, 6 Feb 2025 15:40:44 +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 gCAPKPzXpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:44 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 03/13] fbdev: Send old blank state in FB_EVENT_BLANK Date: Thu, 6 Feb 2025 16:30:22 +0100 Message-ID: <20250206154033.697495-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: 01F851F449 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org The event FB_EVENT_BLANK sends the new blank state in the event's data field. Also send the old state. It's an additional field in the data array; existing receivers won't notice the difference. The backlight subsystem currently tracks blank state per display per backlight. That is not optional as it ties backlight code to fbdev. A subsystem should also not track internal state of another subsystem. With both, new and old, blank state in FB_EVENT_BLANK, the backlight code will not require its own state tracker any longer. Signed-off-by: Thomas Zimmermann --- drivers/video/fbdev/core/fbmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index f34a80c7fc3a..997f0bfcdbb6 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -343,6 +343,7 @@ int fb_blank(struct fb_info *info, int blank) { int old_blank = info->blank; struct fb_event event; + int data[2]; int ret; if (!info->fbops->fb_blank) @@ -351,8 +352,10 @@ int fb_blank(struct fb_info *info, int blank) if (blank > FB_BLANK_POWERDOWN) blank = FB_BLANK_POWERDOWN; + data[0] = blank; + data[1] = old_blank; event.info = info; - event.data = ␣ + event.data = data; info->blank = blank; From patchwork Thu Feb 6 15:30:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 863674 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7E89227561; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; cv=none; b=TUCMO9dlEZkjMLG3lYoEFaKLthn9Ghi/5TK++2qXtubjD+GQ1eNl+TiAy+sZWSxsFXONNC0xjYxH3tnS0ws/cNNxU7ymuO5oojufWmOkc02eG5MzVeVVfYLgk1cQPP8U935B3/Cyji4/iEVpcbAYKr4FeSRWkL+zByn5eq1t5tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856448; c=relaxed/simple; bh=bCyCvFUNgazUsYzoBDQvZpXsp+PgXdjcwIYP/Sh5gFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SCX4XIUOIlqMEgBbiI4IzR5Jn0nW/k13ycqXiZG7ZS/iSwJJjgG77qz0XUZZ9e4pmwZtwrfmOfvQTHrs2hYRk9N/O6G8Lv3nN6jLhwYB3B5wAUAaM0QHdEMR5rANmO6yCZAcVdKr1bZy5INl1yNmcV2rUL6vzp6cIexLVVEJT3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 3E5811F44B; Thu, 6 Feb 2025 15:40:45 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 F1B0213697; Thu, 6 Feb 2025 15:40:44 +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 4PzPOfzXpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:44 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 04/13] backlight: Implement fbdev tracking with blank state from event Date: Thu, 6 Feb 2025 16:30:23 +0100 Message-ID: <20250206154033.697495-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 3E5811F44B X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: Look at the blank state provided by FB_EVENT_BLANK to determine whether to enable or disable a backlight. Remove the tracking fields from struct backlight_device. Tracking requires three variables, fb_on, prev_fb_on and the backlight's use_count. If fb_on is true, the display has been unblanked. The backlight needs to be enabled if the display was blanked before (i.e., prev_fb_on is false) or if use_count is still at 0. If fb_on is false, the display has been blanked. In this case, the backlight has to be disabled was unblanked before and the backlight's use_count is greater than 0. This change removes fbdev state tracking from blacklight. All the backlight requires it its own use counter and information about changes to the display. Removing fbdev internals makes backlight drivers easier to integrate into other display drivers, such as DRM. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/backlight.c | 14 +++++++------- include/linux/backlight.h | 10 +--------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index f699e5827ccb..bb01f57c4683 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -98,9 +98,9 @@ static int fb_notifier_callback(struct notifier_block *self, struct backlight_device *bd; struct fb_event *evdata = data; struct fb_info *info = evdata->info; + const int *fb_blank = evdata->data; struct backlight_device *fb_bd = fb_bl_device(info); - int node = info->node; - int fb_blank = 0; + bool fb_on, prev_fb_on; /* If we aren't interested in this event, skip it immediately ... */ if (event != FB_EVENT_BLANK) @@ -116,15 +116,15 @@ static int fb_notifier_callback(struct notifier_block *self, if (fb_bd && fb_bd != bd) goto out; - fb_blank = *(int *)evdata->data; - if (fb_blank == FB_BLANK_UNBLANK && !bd->fb_bl_on[node]) { - bd->fb_bl_on[node] = true; + fb_on = fb_blank[0] == FB_BLANK_UNBLANK; + prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK; + + if (fb_on && (!prev_fb_on || !bd->use_count)) { if (!bd->use_count++) { bd->props.state &= ~BL_CORE_FBBLANK; backlight_update_status(bd); } - } else if (fb_blank != FB_BLANK_UNBLANK && bd->fb_bl_on[node]) { - bd->fb_bl_on[node] = false; + } else if (!fb_on && prev_fb_on && bd->use_count) { if (!(--bd->use_count)) { bd->props.state |= BL_CORE_FBBLANK; backlight_update_status(bd); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index f5652e5a9060..03723a5478f8 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -294,15 +294,7 @@ struct backlight_device { struct device dev; /** - * @fb_bl_on: The state of individual fbdev's. - * - * Multiple fbdev's may share one backlight device. The fb_bl_on - * records the state of the individual fbdev. - */ - bool fb_bl_on[FB_MAX]; - - /** - * @use_count: The number of uses of fb_bl_on. + * @use_count: The number of unblanked displays. */ int use_count; }; From patchwork Thu Feb 6 15:30:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 863673 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BC45227575; Thu, 6 Feb 2025 15:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; cv=none; b=M7khzZ29sVqIBkHXEoEQjqa1r9Fpg+nFFjoCROVscX0bs8GV/2umBVAWYwL0IGoJMFfTjiKZSpX6vF8AxtuXgpoDV4iU+GPWv5xUeBD1aKnnfEL5rbPHEwPcpf3/ZjxcCu6TGG+o1cJyWj7mZTHhCUf5ny3/JKAQNFL3enH6Cv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; c=relaxed/simple; bh=QljiSUtK8abn9whBbmA9UmhLSOhLC1dTcUiCTuzlOZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T2yabp9mGMGrpfuChjbWqugYHrbZ4yrxh67whdj+87ixgUfxdUTuL+lUei9NlhHmkkEWPGLLtlZebPIjjgbJPBoHuy3jc9RWsuXHRdVyAxa9/lQ+NVhbTq8yuz73PXLhX1wtLYQUdoJz1VLsF7fX3NKOBVm7KweeJtnMwd2eOpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 8597321151; Thu, 6 Feb 2025 15:40:45 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none 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 43F1213A7F; Thu, 6 Feb 2025 15:40:45 +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 +JhkD/3XpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:45 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 05/13] backlight: Move blank-state handling into helper Date: Thu, 6 Feb 2025 16:30:24 +0100 Message-ID: <20250206154033.697495-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 8597321151 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: Move the handling of blank-state updates into a separate helper, so that is can be called without the fbdev event. No functional changes. As a minor improvement over the original code, the update replaces manual locking with a guard. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/backlight.c | 46 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index bb01f57c4683..1c43f579396f 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -80,6 +80,30 @@ static const char *const backlight_scale_types[] = { #if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \ defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) +static void backlight_notify_blank(struct backlight_device *bd, + struct device *display_dev, + bool fb_on, bool prev_fb_on) +{ + guard(mutex)(&bd->ops_lock); + + if (!bd->ops) + return; + if (bd->ops->controls_device && !bd->ops->controls_device(bd, display_dev)) + return; + + if (fb_on && (!prev_fb_on || !bd->use_count)) { + if (!bd->use_count++) { + bd->props.state &= ~BL_CORE_FBBLANK; + backlight_update_status(bd); + } + } else if (!fb_on && prev_fb_on && bd->use_count) { + if (!(--bd->use_count)) { + bd->props.state |= BL_CORE_FBBLANK; + backlight_update_status(bd); + } + } +} + /* * fb_notifier_callback * @@ -107,31 +131,15 @@ static int fb_notifier_callback(struct notifier_block *self, return 0; bd = container_of(self, struct backlight_device, fb_notif); - mutex_lock(&bd->ops_lock); - if (!bd->ops) - goto out; - if (bd->ops->controls_device && !bd->ops->controls_device(bd, info->device)) - goto out; if (fb_bd && fb_bd != bd) - goto out; + return 0; fb_on = fb_blank[0] == FB_BLANK_UNBLANK; prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK; - if (fb_on && (!prev_fb_on || !bd->use_count)) { - if (!bd->use_count++) { - bd->props.state &= ~BL_CORE_FBBLANK; - backlight_update_status(bd); - } - } else if (!fb_on && prev_fb_on && bd->use_count) { - if (!(--bd->use_count)) { - bd->props.state |= BL_CORE_FBBLANK; - backlight_update_status(bd); - } - } -out: - mutex_unlock(&bd->ops_lock); + backlight_notify_blank(bd, info->device, fb_on, prev_fb_on); + return 0; } From patchwork Thu Feb 6 15:30:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 862713 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C8E6227586; Thu, 6 Feb 2025 15:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; cv=none; b=jKO9sLwLSUDr8ZvrVYykLRsiNvHIYCsyClsvb9ag8DHWH8jdSlC92xB0QiRCgaun6PgK8sbmgrxlEVOKHjvwWuliTLOSmjw000pDvUGF1Ju2L+uaIigtj53kfok0LLbzkxPKui6gEEHoD/MZaYLX3bKJhsONUsqJNFYD/4pZbxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; c=relaxed/simple; bh=ZcE23XgUxUGrQtvwWbtOpZIEzDrYAMzEu++vODjdMZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WShrANqypJ8EIng/dhfMl6kBfjXbWbmP1g43T+X1fFLsVriJt9bwxu9YcffHqs2TL7WiXoohDWjF6UTCiJc3a2tKrMk/iRBHW6idcgfLUttxlsF7QnxVHbN7KeDBgMOfdR91nwAkznGdfYC+zm8+f3sfu5znltdMB5sfpIk7LRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 CE7431F44F; Thu, 6 Feb 2025 15:40:45 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 8B1A213697; Thu, 6 Feb 2025 15:40:45 +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 6BW0IP3XpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:45 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 06/13] backlight: Replace fb events with a dedicated function call Date: Thu, 6 Feb 2025 16:30:25 +0100 Message-ID: <20250206154033.697495-7-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[]; ASN(0.00)[asn:25478, ipnet:::/0, country:RU] X-Spam-Score: -4.00 X-Spam-Flag: NO X-Rspamd-Queue-Id: CE7431F44F X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org Remove support for fb events from backlight subsystem. Provide the helper backlight_notify_blank_all() instead. Also export the existing helper backlight_notify_blank() to update a single backlight device. In fbdev, call either helper to inform the backlight subsystem of changes to a display's blank state. If the framebuffer device has a specific backlight, only update this one; otherwise update all. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/backlight.c | 85 ++++--------------------- drivers/video/fbdev/core/fb_backlight.c | 12 ++++ drivers/video/fbdev/core/fbmem.c | 2 + include/linux/backlight.h | 12 ++-- include/linux/fb.h | 4 ++ 5 files changed, 36 insertions(+), 79 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 1c43f579396f..9dc93c5e480b 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #ifdef CONFIG_PMAC_BACKLIGHT @@ -57,10 +56,10 @@ * a hot-key to adjust backlight, the driver must notify the backlight * core that brightness has changed using backlight_force_update(). * - * The backlight driver core receives notifications from fbdev and - * if the event is FB_EVENT_BLANK and if the value of blank, from the - * FBIOBLANK ioctrl, results in a change in the backlight state the - * update_status() operation is called. + * Display drives can control the backlight device's status using + * backlight_notify_blank() and backlight_notify_blank_all(). If this + * results in a change in the backlight state the functions call the + * update_status() operation. */ static struct list_head backlight_dev_list; @@ -78,11 +77,8 @@ static const char *const backlight_scale_types[] = { [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear", }; -#if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \ - defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) -static void backlight_notify_blank(struct backlight_device *bd, - struct device *display_dev, - bool fb_on, bool prev_fb_on) +void backlight_notify_blank(struct backlight_device *bd, struct device *display_dev, + bool fb_on, bool prev_fb_on) { guard(mutex)(&bd->ops_lock); @@ -103,68 +99,18 @@ static void backlight_notify_blank(struct backlight_device *bd, } } } +EXPORT_SYMBOL(backlight_notify_blank); -/* - * fb_notifier_callback - * - * This callback gets called when something important happens inside a - * framebuffer driver. The backlight core only cares about FB_BLANK_UNBLANK - * which is reported to the driver using backlight_update_status() - * as a state change. - * - * There may be several fbdev's connected to the backlight device, - * in which case they are kept track of. A state change is only reported - * if there is a change in backlight for the specified fbdev. - */ -static int fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) +void backlight_notify_blank_all(struct device *display_dev, bool fb_on, bool prev_fb_on) { struct backlight_device *bd; - struct fb_event *evdata = data; - struct fb_info *info = evdata->info; - const int *fb_blank = evdata->data; - struct backlight_device *fb_bd = fb_bl_device(info); - bool fb_on, prev_fb_on; - - /* If we aren't interested in this event, skip it immediately ... */ - if (event != FB_EVENT_BLANK) - return 0; - - bd = container_of(self, struct backlight_device, fb_notif); - - if (fb_bd && fb_bd != bd) - return 0; - - fb_on = fb_blank[0] == FB_BLANK_UNBLANK; - prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK; - - backlight_notify_blank(bd, info->device, fb_on, prev_fb_on); - - return 0; -} - -static int backlight_register_fb(struct backlight_device *bd) -{ - memset(&bd->fb_notif, 0, sizeof(bd->fb_notif)); - bd->fb_notif.notifier_call = fb_notifier_callback; - return fb_register_client(&bd->fb_notif); -} + guard(mutex)(&backlight_dev_list_mutex); -static void backlight_unregister_fb(struct backlight_device *bd) -{ - fb_unregister_client(&bd->fb_notif); -} -#else -static inline int backlight_register_fb(struct backlight_device *bd) -{ - return 0; + list_for_each_entry(bd, &backlight_dev_list, entry) + backlight_notify_blank(bd, display_dev, fb_on, prev_fb_on); } - -static inline void backlight_unregister_fb(struct backlight_device *bd) -{ -} -#endif /* CONFIG_FB_CORE */ +EXPORT_SYMBOL(backlight_notify_blank_all); static void backlight_generate_event(struct backlight_device *bd, enum backlight_update_reason reason) @@ -455,12 +401,6 @@ struct backlight_device *backlight_device_register(const char *name, return ERR_PTR(rc); } - rc = backlight_register_fb(new_bd); - if (rc) { - device_unregister(&new_bd->dev); - return ERR_PTR(rc); - } - new_bd->ops = ops; #ifdef CONFIG_PMAC_BACKLIGHT @@ -547,7 +487,6 @@ void backlight_device_unregister(struct backlight_device *bd) bd->ops = NULL; mutex_unlock(&bd->ops_lock); - backlight_unregister_fb(bd); device_unregister(&bd->dev); } EXPORT_SYMBOL(backlight_device_unregister); diff --git a/drivers/video/fbdev/core/fb_backlight.c b/drivers/video/fbdev/core/fb_backlight.c index 6fdaa9f81be9..dbed9696f4c5 100644 --- a/drivers/video/fbdev/core/fb_backlight.c +++ b/drivers/video/fbdev/core/fb_backlight.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include #include @@ -36,4 +37,15 @@ struct backlight_device *fb_bl_device(struct fb_info *info) return info->bl_dev; } EXPORT_SYMBOL(fb_bl_device); + +void fb_bl_notify_blank(struct fb_info *info, int old_blank) +{ + bool on = info->blank == FB_BLANK_UNBLANK; + bool prev_on = old_blank == FB_BLANK_UNBLANK; + + if (info->bl_dev) + backlight_notify_blank(info->bl_dev, info->device, on, prev_on); + else + backlight_notify_blank_all(info->device, on, prev_on); +} #endif diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 997f0bfcdbb6..993fbee602e0 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -363,6 +363,8 @@ int fb_blank(struct fb_info *info, int blank) if (ret) goto err; + fb_bl_notify_blank(info, old_blank); + fb_notifier_call_chain(FB_EVENT_BLANK, &event); return 0; diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 03723a5478f8..7ed99cfd030f 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -12,7 +12,6 @@ #include #include #include -#include #include /** @@ -278,11 +277,6 @@ struct backlight_device { */ const struct backlight_ops *ops; - /** - * @fb_notif: The framebuffer notifier block - */ - struct notifier_block fb_notif; - /** * @entry: List entry of all registered backlight devices */ @@ -400,6 +394,12 @@ struct backlight_device *backlight_device_get_by_type(enum backlight_type type); int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness); +void backlight_notify_blank(struct backlight_device *bd, + struct device *display_dev, + bool fb_on, bool prev_fb_on); +void backlight_notify_blank_all(struct device *display_dev, + bool fb_on, bool prev_fb_on); + #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) /** diff --git a/include/linux/fb.h b/include/linux/fb.h index f41d3334ac23..bebf279c8bc6 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -757,11 +757,15 @@ extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max) #if IS_ENABLED(CONFIG_FB_BACKLIGHT) struct backlight_device *fb_bl_device(struct fb_info *info); +void fb_bl_notify_blank(struct fb_info *info, int old_blank); #else static inline struct backlight_device *fb_bl_device(struct fb_info *info) { return NULL; } + +void fb_bl_notify_blank(struct fb_info *info, int old_blank) +{ } #endif static inline struct lcd_device *fb_lcd_device(struct fb_info *info) From patchwork Thu Feb 6 15:30:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 863672 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3E5522577F; Thu, 6 Feb 2025 15:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; cv=none; b=X0BPQ6u5cjVn+7BRDz/jl2uQ7SBltG8iAGiqc5YI2zdiHPOnTPABnadaMKaODcCNleFgyGvFgE7Rc/4M5n7V9pwK+DN3H6g9tWWmr7m1NaJ5YpXsynpOy53E/fDOfL+8/gMeyweEGs2VcRLN60azyphQ5j7EkuVnVN/DeiQw3xU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856449; c=relaxed/simple; bh=mQLciDWkIC8+buA4vhMfNSDIL06Oh9J3W/mFzbx8s3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pv4vpgOkwhFRZspDKUNiccz4KgHFyRUjppjza418ab2IaqTWFxu2AAz4XLawd7ywgq5H0SkofQsHOOpOjH05wbnVNS+fANvdxoFDfk5cyDj6SZtimk62UCKLGETrCet2iguo0HlV6Z3Ie0WJTuD+xJjKpPRVcEzKf3rBIfxnI18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jiAqai6e; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AS3bldt3; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jiAqai6e; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=AS3bldt3; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jiAqai6e"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AS3bldt3"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jiAqai6e"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="AS3bldt3" 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-out1.suse.de (Postfix) with ESMTPS id 280602115F; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856446; 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=E3XUtLPaqLGIYCmzV8GNcFujB/Skf7MzzsqQR1UIaXo=; b=jiAqai6eQD64hkxSM8Q88uQ6xlGs4LeTNZz9Ur1nzc7dekU5DvwUOrS2GH2KttA/XfrJQn PIKlkuqly8paOu8FXEdgwta5gt3bM+Y6xWPtJgz8mXmjxQbvb9UhmENKkMg0OotuNoW4Uq xe27EP06VS7KgT8DdLsnblR99NyLVjw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856446; 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=E3XUtLPaqLGIYCmzV8GNcFujB/Skf7MzzsqQR1UIaXo=; b=AS3bldt3OBsYK1Q4RqdXamim7zvqvdxXZkbcCd5R1VV12G2D7PFqW/uEv2NEZkfyRgCzsN 7mKGW6IjBOXm84Bg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856446; 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=E3XUtLPaqLGIYCmzV8GNcFujB/Skf7MzzsqQR1UIaXo=; b=jiAqai6eQD64hkxSM8Q88uQ6xlGs4LeTNZz9Ur1nzc7dekU5DvwUOrS2GH2KttA/XfrJQn PIKlkuqly8paOu8FXEdgwta5gt3bM+Y6xWPtJgz8mXmjxQbvb9UhmENKkMg0OotuNoW4Uq xe27EP06VS7KgT8DdLsnblR99NyLVjw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856446; 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=E3XUtLPaqLGIYCmzV8GNcFujB/Skf7MzzsqQR1UIaXo=; b=AS3bldt3OBsYK1Q4RqdXamim7zvqvdxXZkbcCd5R1VV12G2D7PFqW/uEv2NEZkfyRgCzsN 7mKGW6IjBOXm84Bg== 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 D327E13A7F; Thu, 6 Feb 2025 15:40:45 +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 iCRdMv3XpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:45 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 07/13] backlight: lcd: Maintain global list of lcd devices Date: Thu, 6 Feb 2025 16:30:26 +0100 Message-ID: <20250206154033.697495-8-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -6.80 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; 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)[ucw.cz,kernel.org,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-Spam-Flag: NO X-Spam-Level: Maintain a list of lcd devices. This will replace the fbdev notifiers that all lcd devices currently subscribe to. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/lcd.c | 11 +++++++++++ include/linux/lcd.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 3267acf8dc5b..95a371b3e8a4 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -18,6 +18,9 @@ #include #include +static struct list_head lcd_dev_list; +static struct mutex lcd_dev_list_mutex; + #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ defined(CONFIG_LCD_CLASS_DEVICE_MODULE)) static int to_lcd_power(int fb_blank) @@ -251,6 +254,10 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, return ERR_PTR(rc); } + mutex_lock(&lcd_dev_list_mutex); + list_add(&new_ld->entry, &lcd_dev_list); + mutex_unlock(&lcd_dev_list_mutex); + return new_ld; } EXPORT_SYMBOL(lcd_device_register); @@ -266,6 +273,10 @@ void lcd_device_unregister(struct lcd_device *ld) if (!ld) return; + mutex_lock(&lcd_dev_list_mutex); + list_del(&ld->entry); + mutex_unlock(&lcd_dev_list_mutex); + mutex_lock(&ld->ops_lock); ld->ops = NULL; mutex_unlock(&ld->ops_lock); diff --git a/include/linux/lcd.h b/include/linux/lcd.h index c3ccdff4519a..195b95edb13f 100644 --- a/include/linux/lcd.h +++ b/include/linux/lcd.h @@ -82,6 +82,11 @@ struct lcd_device { /* The framebuffer notifier block */ struct notifier_block fb_notif; + /** + * @entry: List entry of all registered lcd devices + */ + struct list_head entry; + struct device dev; }; From patchwork Thu Feb 6 15:30:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 862712 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55DDE22F15C; Thu, 6 Feb 2025 15:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856450; cv=none; b=dNT8aRa/DtEKxKEmA0a2SHP6n1jQHdvFIUuqU1z1gX1WIxMaUJVLrZZHfgZA5w/beNZ2iBXFARkxdyM7r4zDYHWS9jgB+pT1fUT8tdD2B5TCV5IOtLyEpF1ExKJtXjE+fzLKj7lON4dWUHc02u/UUN4TuHnncvhHAaLSiR5OlfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856450; c=relaxed/simple; bh=QZtV/qyIWtQK69u2uwPPMMZoWaN7CA0iMh5cBTnxyWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dFLwOyDJbJWZs5vDO1evS7sZTOd4RyYGU4Xq2HByciF9BntYAva/ZlX/TltR033/3krkVXbQIXhZt7AbexkHsclgUwkDpFmhXodihF2UIrlRFpsPIeeJFuiZE/C4RtU0vRKcJk6d+vv6jLUtvEFYJyIhVc/ofdHfDlODluXgDSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jRpephcJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h2O7oBMh; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jRpephcJ; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h2O7oBMh; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jRpephcJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h2O7oBMh"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jRpephcJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h2O7oBMh" 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-out1.suse.de (Postfix) with ESMTPS id 6EA8921166; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856446; 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=nZmSbxc1AHuHQ+2yO3YEeVx9ZHYe5QOAUrseW/7hQgI=; b=jRpephcJqYitMquzyHiwk86AvSNCN6bux0coQmqnDWLLiOOQQE9Dn5iQAC84mbICHINK6Q KZ5S+H1SHZQdWGBHZDBQt7GWYCbZXSzE5CXovzbAY44R1EsfjffXHyIQZUva+ziKTJmvcr SUR3OlwjLIqRi/HvFGegwLwT/Zx40IU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856446; 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=nZmSbxc1AHuHQ+2yO3YEeVx9ZHYe5QOAUrseW/7hQgI=; b=h2O7oBMheiW/4lpBFfVMeN3JfaNY33vUmguKLwJMb4ocvzsQYcWulvqRKgFYxjHlG+VS0k 6j1NNDFZKdthbEBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856446; 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=nZmSbxc1AHuHQ+2yO3YEeVx9ZHYe5QOAUrseW/7hQgI=; b=jRpephcJqYitMquzyHiwk86AvSNCN6bux0coQmqnDWLLiOOQQE9Dn5iQAC84mbICHINK6Q KZ5S+H1SHZQdWGBHZDBQt7GWYCbZXSzE5CXovzbAY44R1EsfjffXHyIQZUva+ziKTJmvcr SUR3OlwjLIqRi/HvFGegwLwT/Zx40IU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856446; 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=nZmSbxc1AHuHQ+2yO3YEeVx9ZHYe5QOAUrseW/7hQgI=; b=h2O7oBMheiW/4lpBFfVMeN3JfaNY33vUmguKLwJMb4ocvzsQYcWulvqRKgFYxjHlG+VS0k 6j1NNDFZKdthbEBQ== 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 2E5C313697; Thu, 6 Feb 2025 15:40:46 +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 UGLpCf7XpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:46 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 08/13] backlight: lcd: Move event handling into helpers Date: Thu, 6 Feb 2025 16:30:27 +0100 Message-ID: <20250206154033.697495-9-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: 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)[-1.000]; 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)[ucw.cz,kernel.org,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-Spam-Score: -6.80 X-Spam-Flag: NO Move the handling of display updates to separate helper functions. There is code for handling fbdev blank events and fbdev mode changes. The code currently runs from fbdev event notifiers, which will be replaced. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/lcd.c | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 95a371b3e8a4..b2ee25060d66 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -21,6 +21,32 @@ static struct list_head lcd_dev_list; static struct mutex lcd_dev_list_mutex; +static void lcd_notify_blank(struct lcd_device *ld, struct device *display_dev, + int power) +{ + guard(mutex)(&ld->ops_lock); + + if (!ld->ops || !ld->ops->set_power) + return; + if (ld->ops->controls_device && !ld->ops->controls_device(ld, display_dev)) + return; + + ld->ops->set_power(ld, power); +} + +static void lcd_notify_mode_change(struct lcd_device *ld, struct device *display_dev, + unsigned int width, unsigned int height) +{ + guard(mutex)(&ld->ops_lock); + + if (!ld->ops || !ld->ops->set_mode) + return; + if (ld->ops->controls_device && !ld->ops->controls_device(ld, display_dev)) + return; + + ld->ops->set_mode(ld, width, height); +} + #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ defined(CONFIG_LCD_CLASS_DEVICE_MODULE)) static int to_lcd_power(int fb_blank) @@ -53,25 +79,17 @@ static int fb_notifier_callback(struct notifier_block *self, struct fb_info *info = evdata->info; struct lcd_device *fb_lcd = fb_lcd_device(info); - guard(mutex)(&ld->ops_lock); - - if (!ld->ops) - return 0; - if (ld->ops->controls_device && !ld->ops->controls_device(ld, info->device)) - return 0; if (fb_lcd && fb_lcd != ld) return 0; if (event == FB_EVENT_BLANK) { int power = to_lcd_power(*(int *)evdata->data); - if (ld->ops->set_power) - ld->ops->set_power(ld, power); + lcd_notify_blank(ld, info->device, power); } else { const struct fb_videomode *videomode = evdata->data; - if (ld->ops->set_mode) - ld->ops->set_mode(ld, videomode->xres, videomode->yres); + lcd_notify_mode_change(ld, info->device, videomode->xres, videomode->yres); } return 0; From patchwork Thu Feb 6 15:30:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 862710 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2924236A75; Thu, 6 Feb 2025 15:40:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856451; cv=none; b=u/+eo/puVlmo7aC9IeKUJvttDom1zMz1cQno02Qzywq7iisagtJKFUwqXyysdR+f8a3HqtTkhRaDVYAZor0FeuBUYpObNkUEZM+XZM9rglLPJZ4IfaNtOgkrwOeL/Xs+cGMGEKLsoclb6RUCGl+wCiQBp8PluUjTEXgdoB4EuP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738856451; c=relaxed/simple; bh=dNgl3h9Vzut2hc6ve1q8OZZgnjxYflql6M3vEuzsOAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IAdHNEzCxa04DwDMMN+GuObJXouKNFpkT4zic4cneoKRA0+S3Qocxkokiw5kAuQz8PVXfJ7tB3PfVkuJ2lVfOp9Oie5p6bL6CSPXSb/ROS/5DoR9pRDAJ/Oh4qaryGkq+DjqSKDlOR1IOOqA0juAT7r/TEooMEA9Ff413pmM104= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=heIeLe3f; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=G257eZme; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=vZfcmheD; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=N7HAUygQ; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="heIeLe3f"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="G257eZme"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="vZfcmheD"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="N7HAUygQ" 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 B725C1F450; Thu, 6 Feb 2025 15:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856447; 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=r/GIQVkpHxJ+GI04jthWUn4ca+shl1eH95iOIeDhcyk=; b=heIeLe3ffCQb+21eCLQrmvVxHn4GBL9FjItfEbV8HsJu2bHOTtXfp5i3Oy5N2XNfGroOL9 /T31IrBVozOWjPgiilTzNSMRRiBNRgDuX1hvmlioXunaNtW76aTI1pwVZzz0p3hFcQeohg oBOLlYWLSHB+UOM3a0DXDW4g8iCMOo0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856447; 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=r/GIQVkpHxJ+GI04jthWUn4ca+shl1eH95iOIeDhcyk=; b=G257eZmewITO1DXH1a4QdyRWHOVwOraIK2GmNjaOF2V1rMjRTpF2+EeaNutWxl1OpbqSVm QP9cdIvmnS/JyiDg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738856446; 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=r/GIQVkpHxJ+GI04jthWUn4ca+shl1eH95iOIeDhcyk=; b=vZfcmheDqUkyppyDsiMtz3x+Mx7EZz4AT0zdIeLC/b0iM5/RoEazcWYwp8ceY376RYB+CO zBOcJVnmYzRTwCwwZbM55rMrTkIy0027tHfbqfjD2jj/R+9/F1btdtc41wouMpgCeGinA1 m2UDrs7yrXMy0iSz4iKr/lFFl6W7gRM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738856446; 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=r/GIQVkpHxJ+GI04jthWUn4ca+shl1eH95iOIeDhcyk=; b=N7HAUygQbTpn56kE/X5iidb6sp0BJp00bMS9BWgsZI65vquIQeqG781wAhMxqr6x/xgGOJ rN/H3hcSlqw3MTAA== 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 743C313A7F; Thu, 6 Feb 2025 15:40:46 +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 KJYwG/7XpGf4PAAAD6G6ig (envelope-from ); Thu, 06 Feb 2025 15:40:46 +0000 From: Thomas Zimmermann To: pavel@ucw.cz, lee@kernel.org, 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 09/13] backlight: lcd: Replace fb events with a dedicated function call Date: Thu, 6 Feb 2025 16:30:28 +0100 Message-ID: <20250206154033.697495-10-tzimmermann@suse.de> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250206154033.697495-1-tzimmermann@suse.de> References: <20250206154033.697495-1-tzimmermann@suse.de> Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Score: -6.80 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)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,suse.de:email]; 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)[ucw.cz,kernel.org,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-Spam-Flag: NO X-Spam-Level: Remove support for fb events from the lcd subsystem. Provide the helper lcd_notify_blank_all() instead. In fbdev, call lcd_notify_blank_all() to inform the lcd subsystem of changes to a display's blank state. Signed-off-by: Thomas Zimmermann --- drivers/video/backlight/lcd.c | 90 ++++++-------------------------- drivers/video/fbdev/core/fbmem.c | 43 +++++++++++++-- include/linux/lcd.h | 7 +-- 3 files changed, 60 insertions(+), 80 deletions(-) diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index b2ee25060d66..67daa3757211 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -15,7 +15,6 @@ #include #include #include -#include #include static struct list_head lcd_dev_list; @@ -34,6 +33,17 @@ static void lcd_notify_blank(struct lcd_device *ld, struct device *display_dev, ld->ops->set_power(ld, power); } +void lcd_notify_blank_all(struct device *display_dev, int power) +{ + struct lcd_device *ld; + + guard(mutex)(&lcd_dev_list_mutex); + + list_for_each_entry(ld, &lcd_dev_list, entry) + lcd_notify_blank(ld, display_dev, power); +} +EXPORT_SYMBOL(lcd_notify_blank_all); + static void lcd_notify_mode_change(struct lcd_device *ld, struct device *display_dev, unsigned int width, unsigned int height) { @@ -47,75 +57,16 @@ static void lcd_notify_mode_change(struct lcd_device *ld, struct device *display ld->ops->set_mode(ld, width, height); } -#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ - defined(CONFIG_LCD_CLASS_DEVICE_MODULE)) -static int to_lcd_power(int fb_blank) -{ - switch (fb_blank) { - case FB_BLANK_UNBLANK: - return LCD_POWER_ON; - /* deprecated; TODO: should become 'off' */ - case FB_BLANK_NORMAL: - return LCD_POWER_REDUCED; - case FB_BLANK_VSYNC_SUSPEND: - return LCD_POWER_REDUCED_VSYNC_SUSPEND; - /* 'off' */ - case FB_BLANK_HSYNC_SUSPEND: - case FB_BLANK_POWERDOWN: - default: - return LCD_POWER_OFF; - } -} - -/* This callback gets called when something important happens inside a - * framebuffer driver. We're looking if that important event is blanking, - * and if it is, we're switching lcd power as well ... - */ -static int fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct lcd_device *ld = container_of(self, struct lcd_device, fb_notif); - struct fb_event *evdata = data; - struct fb_info *info = evdata->info; - struct lcd_device *fb_lcd = fb_lcd_device(info); - - if (fb_lcd && fb_lcd != ld) - return 0; - - if (event == FB_EVENT_BLANK) { - int power = to_lcd_power(*(int *)evdata->data); - - lcd_notify_blank(ld, info->device, power); - } else { - const struct fb_videomode *videomode = evdata->data; - - lcd_notify_mode_change(ld, info->device, videomode->xres, videomode->yres); - } - - return 0; -} - -static int lcd_register_fb(struct lcd_device *ld) +void lcd_notify_mode_change_all(struct device *display_dev, + unsigned int width, unsigned int height) { - memset(&ld->fb_notif, 0, sizeof(ld->fb_notif)); - ld->fb_notif.notifier_call = fb_notifier_callback; - return fb_register_client(&ld->fb_notif); -} + struct lcd_device *ld; -static void lcd_unregister_fb(struct lcd_device *ld) -{ - fb_unregister_client(&ld->fb_notif); -} -#else -static int lcd_register_fb(struct lcd_device *ld) -{ - return 0; -} + guard(mutex)(&lcd_dev_list_mutex); -static inline void lcd_unregister_fb(struct lcd_device *ld) -{ + list_for_each_entry(ld, &lcd_dev_list, entry) + lcd_notify_mode_change(ld, display_dev, width, height); } -#endif /* CONFIG_FB */ static ssize_t lcd_power_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -266,12 +217,6 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, return ERR_PTR(rc); } - rc = lcd_register_fb(new_ld); - if (rc) { - device_unregister(&new_ld->dev); - return ERR_PTR(rc); - } - mutex_lock(&lcd_dev_list_mutex); list_add(&new_ld->entry, &lcd_dev_list); mutex_unlock(&lcd_dev_list_mutex); @@ -298,7 +243,6 @@ void lcd_device_unregister(struct lcd_device *ld) mutex_lock(&ld->ops_lock); ld->ops = NULL; mutex_unlock(&ld->ops_lock); - lcd_unregister_fb(ld); device_unregister(&ld->dev); } diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 993fbee602e0..fb7ca143a996 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -15,6 +15,7 @@ #include #include #include +#include #include