All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corentin Chary <corentincj@iksaif.net>
To: lenb@kernel.org
Cc: linux-acpi@vger.kernel.org, Corentin Chary <corentincj@iksaif.net>
Subject: [PATCH 09/15] eeepc-laptop: rfkill refactoring
Date: Tue, 16 Jun 2009 21:28:50 +0200	[thread overview]
Message-ID: <1245180536-28009-10-git-send-email-corentincj@iksaif.net> (raw)
In-Reply-To: <1245180536-28009-9-git-send-email-corentincj@iksaif.net>

Refactor rfkill code, because we'll add another
rfkill for wwan3g later.

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 drivers/platform/x86/eeepc-laptop.c |  189 +++++++++++++++++------------------
 1 files changed, 94 insertions(+), 95 deletions(-)

diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 2a03425..7b7c750 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -128,8 +128,8 @@ struct eeepc_hotk {
 	u16 event_count[128];		/* count for each event */
 	struct input_dev *inputdev;
 	u16 *keycode_map;
-	struct rfkill *eeepc_wlan_rfkill;
-	struct rfkill *eeepc_bluetooth_rfkill;
+	struct rfkill *wlan_rfkill;
+	struct rfkill *bluetooth_rfkill;
 	struct hotplug_slot *hotplug_slot;
 };
 
@@ -570,7 +570,7 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
 		return;
 	}
 
-	eeepc_wlan_rfkill_state(ehotk->eeepc_wlan_rfkill, &state);
+	eeepc_wlan_rfkill_state(ehotk->wlan_rfkill, &state);
 
 	if (state == RFKILL_STATE_UNBLOCKED) {
 		dev = pci_get_slot(bus, 0);
@@ -593,7 +593,7 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
 		}
 	}
 
-	rfkill_force_state(ehotk->eeepc_wlan_rfkill, state);
+	rfkill_force_state(ehotk->wlan_rfkill, state);
 }
 
 static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
@@ -753,89 +753,8 @@ static int eeepc_hotk_add(struct acpi_device *device)
 	if (ACPI_FAILURE(status))
 		pr_err("Error installing notify handler\n");
 
-	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
-	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
-
-	if (get_acpi(CM_ASL_WLAN) != -1) {
-		ehotk->eeepc_wlan_rfkill = rfkill_allocate(&device->dev,
-							   RFKILL_TYPE_WLAN);
-
-		if (!ehotk->eeepc_wlan_rfkill)
-			goto wlan_fail;
-
-		ehotk->eeepc_wlan_rfkill->name = "eeepc-wlan";
-		ehotk->eeepc_wlan_rfkill->toggle_radio = eeepc_wlan_rfkill_set;
-		ehotk->eeepc_wlan_rfkill->get_state = eeepc_wlan_rfkill_state;
-		if (get_acpi(CM_ASL_WLAN) == 1) {
-			ehotk->eeepc_wlan_rfkill->state =
-				RFKILL_STATE_UNBLOCKED;
-			rfkill_set_default(RFKILL_TYPE_WLAN,
-					   RFKILL_STATE_UNBLOCKED);
-		} else {
-			ehotk->eeepc_wlan_rfkill->state =
-				RFKILL_STATE_SOFT_BLOCKED;
-			rfkill_set_default(RFKILL_TYPE_WLAN,
-					   RFKILL_STATE_SOFT_BLOCKED);
-		}
-		result = rfkill_register(ehotk->eeepc_wlan_rfkill);
-		if (result)
-			goto wlan_fail;
-	}
-
-	if (get_acpi(CM_ASL_BLUETOOTH) != -1) {
-		ehotk->eeepc_bluetooth_rfkill =
-			rfkill_allocate(&device->dev, RFKILL_TYPE_BLUETOOTH);
-
-		if (!ehotk->eeepc_bluetooth_rfkill)
-			goto bluetooth_fail;
-
-		ehotk->eeepc_bluetooth_rfkill->name = "eeepc-bluetooth";
-		ehotk->eeepc_bluetooth_rfkill->toggle_radio =
-			eeepc_bluetooth_rfkill_set;
-		ehotk->eeepc_bluetooth_rfkill->get_state =
-			eeepc_bluetooth_rfkill_state;
-		if (get_acpi(CM_ASL_BLUETOOTH) == 1) {
-			ehotk->eeepc_bluetooth_rfkill->state =
-				RFKILL_STATE_UNBLOCKED;
-			rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
-					   RFKILL_STATE_UNBLOCKED);
-		} else {
-			ehotk->eeepc_bluetooth_rfkill->state =
-				RFKILL_STATE_SOFT_BLOCKED;
-			rfkill_set_default(RFKILL_TYPE_BLUETOOTH,
-					   RFKILL_STATE_SOFT_BLOCKED);
-		}
-
-		result = rfkill_register(ehotk->eeepc_bluetooth_rfkill);
-		if (result)
-			goto bluetooth_fail;
-	}
-
-	result = eeepc_setup_pci_hotplug();
-	/*
-	 * If we get -EBUSY then something else is handling the PCI hotplug -
-	 * don't fail in this case
-	 */
-	if (result == -EBUSY)
-		return 0;
-	else if (result)
-		goto pci_fail;
-
 	return 0;
 
- pci_fail:
-	if (ehotk->eeepc_bluetooth_rfkill)
-		rfkill_unregister(ehotk->eeepc_bluetooth_rfkill);
- bluetooth_fail:
-	if (ehotk->eeepc_bluetooth_rfkill)
-		rfkill_free(ehotk->eeepc_bluetooth_rfkill);
-	rfkill_unregister(ehotk->eeepc_wlan_rfkill);
-	ehotk->eeepc_wlan_rfkill = NULL;
- wlan_fail:
-	if (ehotk->eeepc_wlan_rfkill)
-		rfkill_free(ehotk->eeepc_wlan_rfkill);
-	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
-	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
  ehotk_fail:
 	kfree(ehotk);
 	ehotk = NULL;
@@ -854,11 +773,6 @@ static int eeepc_hotk_remove(struct acpi_device *device, int type)
 	if (ACPI_FAILURE(status))
 		pr_err("Error removing notify handler\n");
 
-	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
-	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
-	if (ehotk->hotplug_slot)
-		pci_hp_deregister(ehotk->hotplug_slot);
-
 	kfree(ehotk);
 	return 0;
 }
@@ -979,10 +893,14 @@ static void eeepc_backlight_exit(void)
 
 static void eeepc_rfkill_exit(void)
 {
-	if (ehotk->eeepc_wlan_rfkill)
-		rfkill_unregister(ehotk->eeepc_wlan_rfkill);
-	if (ehotk->eeepc_bluetooth_rfkill)
-		rfkill_unregister(ehotk->eeepc_bluetooth_rfkill);
+	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
+	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
+	if (ehotk->wlan_rfkill)
+		rfkill_unregister(ehotk->wlan_rfkill);
+	if (ehotk->bluetooth_rfkill)
+		rfkill_unregister(ehotk->bluetooth_rfkill);
+	if (ehotk->hotplug_slot)
+		pci_hp_deregister(ehotk->hotplug_slot);
 }
 
 static void eeepc_input_exit(void)
@@ -1017,6 +935,80 @@ static void __exit eeepc_laptop_exit(void)
 	platform_driver_unregister(&platform_driver);
 }
 
+static int eeepc_new_rfkill(struct rfkill **rfkill,
+			    const char *name, struct device *dev,
+			    enum rfkill_type type, int cm,
+			    int (*toggle)(void *, enum rfkill_state),
+			    int (*get)(void *, enum rfkill_state *))
+{
+	int result;
+
+	if (get_acpi(cm) == -1)
+		return -ENODEV;
+
+	*rfkill = rfkill_allocate(dev, type);
+	if (!*rfkill)
+		return -EINVAL;
+
+	(*rfkill)->name = name;
+	(*rfkill)->toggle_radio = toggle;
+	(*rfkill)->get_state = get;
+	if (get_acpi(cm) == 1) {
+		(*rfkill)->state = RFKILL_STATE_UNBLOCKED;
+		rfkill_set_default(type, RFKILL_STATE_UNBLOCKED);
+	} else {
+		(*rfkill)->state = RFKILL_STATE_SOFT_BLOCKED;
+		rfkill_set_default(type, RFKILL_STATE_SOFT_BLOCKED);
+	}
+	result = rfkill_register(*rfkill);
+	if (result) {
+		rfkill_free(*rfkill);
+		*rfkill = NULL;
+		return result;
+	}
+	return 0;
+}
+
+
+static int eeepc_rfkill_init(struct device *dev)
+{
+	int result = 0;
+
+	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
+	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
+
+	result = eeepc_new_rfkill(&ehotk->wlan_rfkill,
+				  "eeepc-wlan", dev,
+				  RFKILL_TYPE_WLAN, CM_ASL_WLAN,
+				  eeepc_wlan_rfkill_set,
+				  eeepc_wlan_rfkill_state);
+
+	if (result && result != -ENODEV)
+		goto exit;
+
+	result = eeepc_new_rfkill(&ehotk->bluetooth_rfkill,
+				  "eeepc-bluetooth", dev,
+				  RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH,
+				  eeepc_bluetooth_rfkill_set,
+				  eeepc_bluetooth_rfkill_state);
+
+	if (result && result != -ENODEV)
+		goto exit;
+
+	result = eeepc_setup_pci_hotplug();
+	/*
+	 * If we get -EBUSY then something else is handling the PCI hotplug -
+	 * don't fail in this case
+	 */
+	if (result == -EBUSY)
+		result = 0;
+
+exit:
+	if (result && result != -ENODEV)
+		eeepc_rfkill_exit();
+	return result;
+}
+
 static int eeepc_backlight_init(struct device *dev)
 {
 	struct backlight_device *bd;
@@ -1100,7 +1092,15 @@ static int __init eeepc_laptop_init(void)
 				    &platform_attribute_group);
 	if (result)
 		goto fail_sysfs;
+
+	result = eeepc_rfkill_init(dev);
+	if (result)
+		goto fail_rfkill;
+
 	return 0;
+fail_rfkill:
+	sysfs_remove_group(&platform_device->dev.kobj,
+			   &platform_attribute_group);
 fail_sysfs:
 	platform_device_del(platform_device);
 fail_platform_device2:
@@ -1113,7 +1113,6 @@ fail_hwmon:
 	eeepc_backlight_exit();
 fail_backlight:
 	eeepc_input_exit();
-	eeepc_rfkill_exit();
 	return result;
 }
 
-- 
1.6.3.1


  reply	other threads:[~2009-06-16 19:31 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-16 19:28 [PATCH 00/15] acpi4asus updates Corentin Chary
2009-06-16 19:28 ` [PATCH 01/15] eeepc-laptop: Register as a pci-hotplug device Corentin Chary
2009-06-16 19:28   ` [PATCH 02/15] eeepc: fix kconfig selects Corentin Chary
2009-06-16 19:28     ` [PATCH 03/15] eeepc-laptop.c: use pr_fmt and pr_<level> Corentin Chary
2009-06-16 19:28       ` [PATCH 04/15] eeepc-laptop: enable camera by default Corentin Chary
2009-06-16 19:28         ` [PATCH 05/15] asus-laptop: platform dev as parent for led and backlight Corentin Chary
2009-06-16 19:28           ` [PATCH 06/15] acpi4asus: update MAINTAINER and KConfig links Corentin Chary
2009-06-16 19:28             ` [PATCH 07/15] asus_acpi: Deprecate in favor of asus-laptop Corentin Chary
2009-06-16 19:28               ` [PATCH 08/15] asus-laptop: use pr_fmt and pr_<level> Corentin Chary
2009-06-16 19:28                 ` Corentin Chary [this message]
2009-06-16 19:28                   ` [PATCH 10/15] eeepc-laptop: right parent device Corentin Chary
2009-06-16 19:28                     ` [PATCH 11/15] eeepc-laptop: sync eeepc-laptop with asus_acpi Corentin Chary
2009-06-16 19:28                       ` [PATCH 12/15] eeepc-laptop: makes get_acpi() returns -ENODEV Corentin Chary
2009-06-16 19:28                         ` [PATCH 13/15] eeepc-laptop: get the right value for CMSG Corentin Chary
2009-06-16 19:28                           ` [PATCH 14/15] eeepc-laptop: add rfkill support for the 3G modem in Eee PC 901 Go Corentin Chary
2009-06-16 19:28                             ` [PATCH 15/15] eeepc-laptop: cpufv updates Corentin Chary
2009-06-18  2:41 ` [PATCH 00/15] acpi4asus updates Len Brown
2009-06-18  6:21   ` Len Brown
2009-06-19  8:28     ` Corentin Chary
2009-06-19 19:39       ` Len Brown
2009-06-24  5:41         ` Len Brown
2009-06-24  6:39           ` Corentin Chary
2009-06-25 16:42             ` Len Brown
2009-06-26  3:14               ` Stephen Rothwell
2009-06-25 11:25           ` [PATCH 1/7] eeepc-laptop: Register as a pci-hotplug device Corentin Chary
2009-06-25 11:25             ` [PATCH 2/7] eeepc-laptop.c: use pr_fmt and pr_<level> Corentin Chary
2009-06-25 11:25               ` [PATCH 3/7] eeepc-laptop: rfkill refactoring Corentin Chary
2009-06-25 11:25                 ` [PATCH 4/7] eeepc-laptop: right parent device Corentin Chary
2009-06-25 11:25                   ` [PATCH 5/7] eeepc-laptop: makes get_acpi() returns -ENODEV Corentin Chary
2009-06-25 11:25                     ` [PATCH 6/7] eeepc-laptop: get the right value for CMSG Corentin Chary
2009-06-25 11:25                       ` [PATCH 7/7] eeepc-laptop: add rfkill support for the 3G modem in Eee PC 901 Go Corentin Chary
2009-06-19 12:52     ` [PATCH 1/9] asus-laptop: use pr_fmt and pr_<level> Corentin Chary
2009-06-19 12:52       ` [PATCH 2/9] eeepc-laptop: Register as a pci-hotplug device Corentin Chary
2009-06-19 12:52         ` [PATCH 3/9] eeepc-laptop.c: use pr_fmt and pr_<level> Corentin Chary
2009-06-19 12:52           ` [PATCH 4/9] eeepc-laptop: rfkill refactoring Corentin Chary
2009-06-19 12:52             ` [PATCH 5/9] eeepc-laptop: right parent device Corentin Chary
2009-06-19 12:52               ` [PATCH 6/9] eeepc-laptop: makes get_acpi() returns -ENODEV Corentin Chary
2009-06-19 12:52                 ` [PATCH 7/9] eeepc-laptop: get the right value for CMSG Corentin Chary
2009-06-19 12:52                   ` [PATCH 8/9] eeepc-laptop: add rfkill support for the 3G modem in Eee PC 901 Go Corentin Chary
2009-06-19 12:52                     ` [PATCH 9/9] asus-laptop: remove EXPERIMENTAL dependency Corentin Chary

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=1245180536-28009-10-git-send-email-corentincj@iksaif.net \
    --to=corentincj@iksaif.net \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    /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.