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; }