All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Darren Hart <dvhart@infradead.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: "Ben Skeggs" <bskeggs@redhat.com>,
	"Azael Avalos" <coproscefalo@gmail.com>,
	"Corentin Chary" <corentin.chary@gmail.com>,
	"Lee Chun-Yi" <jlee@suse.com>,
	"Cezary Jackiewicz" <cezary.jackiewicz@gmail.com>,
	"Matthew Garrett" <mjg59@srcf.ucam.org>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Ike Panhc" <ike.pan@canonical.com>,
	"Anisse Astier" <anisse@astier.eu>,
	"Mattia Dongili" <malattia@linux.it>,
	"Henrique de Moraes Holschuh" <ibm-acpi@hmh.eng.br>,
	platform-driver-x86@vger.kernel.org,
	ibm-acpi-devel@lists.sourceforge.net,
	acpi4asus-user@lists.sourceforge.net,
	dri-devel@lists.freedesktop.org, "Aaron Lu" <aaron.lu@intel.com>,
	linux-acpi@vger.kernel.org, "Hans de Goede" <hdegoede@redhat.com>
Subject: [PATCH v2 11/32] acpi-video: Move backlight notifier to video_detect.c
Date: Fri, 12 Jun 2015 13:23:30 +0200	[thread overview]
Message-ID: <1434108231-12323-12-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1434108231-12323-1-git-send-email-hdegoede@redhat.com>

Move the unregistering of the acpi backlight interface on registering of a
native backlight from video.c to video_detect.c where it belongs.

Note this removes support for re-registering the acpi backlight interface
when the native interface goes away. In practice this never happens and
it needlessly complicates the code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/acpi/acpi_video.c   | 59 ++-------------------------------------------
 drivers/acpi/video_detect.c | 27 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 57 deletions(-)

diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 1bbe9b1..f5ffac9 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -84,6 +84,7 @@ static struct list_head video_bus_head;
 static int acpi_video_bus_add(struct acpi_device *device);
 static int acpi_video_bus_remove(struct acpi_device *device);
 static void acpi_video_bus_notify(struct acpi_device *device, u32 event);
+void acpi_video_detect_exit(void);
 
 static const struct acpi_device_id video_device_ids[] = {
 	{ACPI_VIDEO_HID, 0},
@@ -143,7 +144,6 @@ struct acpi_video_enumerated_device {
 struct acpi_video_bus {
 	struct acpi_device *device;
 	bool backlight_registered;
-	bool backlight_notifier_registered;
 	u8 dos_setting;
 	struct acpi_video_enumerated_device *attached_array;
 	u8 attached_count;
@@ -156,7 +156,6 @@ struct acpi_video_bus {
 	struct input_dev *input;
 	char phys[32];	/* for input device */
 	struct notifier_block pm_nb;
-	struct notifier_block backlight_nb;
 };
 
 struct acpi_video_device_flags {
@@ -1781,59 +1780,6 @@ static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
 	video->input = NULL;
 }
 
-static int acpi_video_backlight_notify(struct notifier_block *nb,
-					unsigned long val, void *bd)
-{
-	struct backlight_device *backlight = bd;
-	struct acpi_video_bus *video;
-	enum acpi_backlight_type type;
-
-	/* A raw bl (un)registering may change native <-> video */
-	if (backlight->props.type != BACKLIGHT_RAW)
-		return NOTIFY_DONE;
-
-	video = container_of(nb, struct acpi_video_bus, backlight_nb);
-	type = acpi_video_get_backlight_type();
-
-	switch (val) {
-	case BACKLIGHT_REGISTERED:
-		if (type != acpi_backlight_video)
-			acpi_video_bus_unregister_backlight(video);
-		break;
-	case BACKLIGHT_UNREGISTERED:
-		if (type == acpi_backlight_video)
-			acpi_video_bus_register_backlight(video);
-		break;
-	}
-
-	return NOTIFY_OK;
-}
-
-static int acpi_video_bus_add_backlight_notify_handler(
-						struct acpi_video_bus *video)
-{
-	int error;
-
-	video->backlight_nb.notifier_call = acpi_video_backlight_notify;
-	video->backlight_nb.priority = 0;
-	error = backlight_register_notifier(&video->backlight_nb);
-	if (error == 0)
-		video->backlight_notifier_registered = true;
-
-	return error;
-}
-
-static int acpi_video_bus_remove_backlight_notify_handler(
-						struct acpi_video_bus *video)
-{
-	if (!video->backlight_notifier_registered)
-		return 0;
-
-	video->backlight_notifier_registered = false;
-
-	return backlight_unregister_notifier(&video->backlight_nb);
-}
-
 static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
 {
 	struct acpi_video_device *dev, *next;
@@ -1915,7 +1861,6 @@ static int acpi_video_bus_add(struct acpi_device *device)
 
 	acpi_video_bus_register_backlight(video);
 	acpi_video_bus_add_notify_handler(video);
-	acpi_video_bus_add_backlight_notify_handler(video);
 
 	return 0;
 
@@ -1939,7 +1884,6 @@ static int acpi_video_bus_remove(struct acpi_device *device)
 
 	video = acpi_driver_data(device);
 
-	acpi_video_bus_remove_backlight_notify_handler(video);
 	acpi_video_bus_remove_notify_handler(video);
 	acpi_video_bus_unregister_backlight(video);
 	acpi_video_bus_put_devices(video);
@@ -2075,6 +2019,7 @@ static int __init acpi_video_init(void)
 
 static void __exit acpi_video_exit(void)
 {
+	acpi_video_detect_exit();
 	acpi_video_unregister();
 
 	return;
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index f9934dc..c683597 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -37,6 +37,9 @@
 ACPI_MODULE_NAME("video");
 #define _COMPONENT		ACPI_VIDEO_COMPONENT
 
+static bool backlight_notifier_registered;
+static struct notifier_block backlight_nb;
+
 static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
 static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
 
@@ -257,6 +260,20 @@ static struct dmi_system_id video_detect_dmi_table[] = {
 	{ },
 };
 
+static int acpi_video_backlight_notify(struct notifier_block *nb,
+				       unsigned long val, void *bd)
+{
+	struct backlight_device *backlight = bd;
+
+	/* A raw bl registering may change video -> native */
+	if (backlight->props.type == BACKLIGHT_RAW &&
+	    val == BACKLIGHT_REGISTERED &&
+	    acpi_video_get_backlight_type() != acpi_backlight_video)
+		acpi_video_unregister_backlight();
+
+	return NOTIFY_OK;
+}
+
 /*
  * Determine which type of backlight interface to use on this system,
  * First check cmdline, then dmi quirks, then do autodetect.
@@ -285,6 +302,10 @@ enum acpi_backlight_type acpi_video_get_backlight_type(void)
 		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
 				    ACPI_UINT32_MAX, find_video, NULL,
 				    &video_caps, NULL);
+		backlight_nb.notifier_call = acpi_video_backlight_notify;
+		backlight_nb.priority = 0;
+		if (backlight_register_notifier(&backlight_nb) == 0)
+			backlight_notifier_registered = true;
 		init_done = true;
 	}
 	mutex_unlock(&init_mutex);
@@ -349,3 +370,9 @@ int acpi_video_backlight_support(void)
 	return acpi_video_get_backlight_type() != acpi_backlight_vendor;
 }
 EXPORT_SYMBOL(acpi_video_backlight_support);
+
+void __exit acpi_video_detect_exit(void)
+{
+	if (backlight_notifier_registered)
+		backlight_unregister_notifier(&backlight_nb);
+}
-- 
2.4.2

  parent reply	other threads:[~2015-06-12 11:23 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 11:23 [PATCH v2 00/32] acpi-video: Rewrite backlight interface selection logic Hans de Goede
2015-06-12 11:23 ` [PATCH v2 01/32] apple-gmux: Stop using acpi_video_dmi_demote_vendor() Hans de Goede
2015-06-12 11:23 ` [PATCH v2 02/32] acpi-video-detect: Remove the unused acpi_video_dmi_demote_vendor() function Hans de Goede
2015-06-12 11:23 ` [PATCH v2 03/32] acpi-video-detect: Make acpi_video_get_capabilities a private function Hans de Goede
2015-06-12 11:23 ` [PATCH v2 04/32] acpi-video-detect: Move acpi_is_video_device() to acpi/scan.c Hans de Goede
2015-06-12 11:23 ` [PATCH v2 05/32] acpi-video-detect: Move acpi_osi_is_win8 to osl.c Hans de Goede
2015-06-12 11:23 ` [PATCH v2 06/32] acpi-video-detect: video: Make video_detect code part of the video module Hans de Goede
2015-06-12 11:23 ` [PATCH v2 07/32] acpi-video-detect: Rewrite backlight interface selection logic Hans de Goede
2015-06-12 11:23 ` [PATCH v2 08/32] acpi-video-detect: Unregister acpi_video backlight when dmi quirks are added Hans de Goede
2015-06-12 11:23 ` [PATCH v2 09/32] drm: i915: Port to new backlight interface selection API Hans de Goede
2015-06-12 11:23 ` [PATCH v2 10/32] acpi-video: " Hans de Goede
2015-06-12 11:23 ` Hans de Goede [this message]
2015-06-12 11:23 ` [PATCH v2 12/32] acpi-video: Move dmi_check_system from module_init to acpi_video_register Hans de Goede
2015-06-12 11:23 ` [PATCH v2 13/32] acpi-video: Fix acpi_video _register vs _unregister_backlight race Hans de Goede
2015-06-12 11:23 ` [PATCH v2 14/32] acer-wmi: Port to new backlight interface selection API Hans de Goede
2015-06-12 11:23 ` [PATCH v2 15/32] apple-gmux: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 16/32] asus-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 17/32] asus-wmi: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 18/32] compal-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 19/32] dell-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 20/32] dell-wmi: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 21/32] eeepc-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 22/32] fujitsu-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 23/32] ideapad-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 24/32] intel-oaktrail: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 25/32] msi-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 26/32] msi-wmi: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 27/32] samsung-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 28/32] sony-laptop: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 29/32] thinkpad-acpi: " Hans de Goede
2015-06-12 11:23 ` [PATCH v2 30/32] toshiba-acpi: " Hans de Goede
2015-06-14  3:15   ` Azael Avalos
2015-06-16 12:53     ` Hans de Goede
2015-06-12 11:23 ` [PATCH v2 31/32] acpi-video-detect: Remove old API Hans de Goede
2015-06-12 11:23 ` [PATCH v2 32/32] acpi-video: Make acpi_video_unregister_backlight() private Hans de Goede
2015-06-15 23:22 ` [PATCH v2 00/32] acpi-video: Rewrite backlight interface selection logic Rafael J. Wysocki
2015-06-17  3:39   ` Darren Hart
2015-06-17  9:36     ` Rafael J. Wysocki
2015-06-18 21:05       ` Darren Hart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434108231-12323-12-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=aaron.lu@intel.com \
    --cc=acpi4asus-user@lists.sourceforge.net \
    --cc=anisse@astier.eu \
    --cc=bskeggs@redhat.com \
    --cc=cezary.jackiewicz@gmail.com \
    --cc=coproscefalo@gmail.com \
    --cc=corentin.chary@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dvhart@infradead.org \
    --cc=ibm-acpi-devel@lists.sourceforge.net \
    --cc=ibm-acpi@hmh.eng.br \
    --cc=ike.pan@canonical.com \
    --cc=jlee@suse.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=malattia@linux.it \
    --cc=mjg59@srcf.ucam.org \
    --cc=pali.rohar@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.