diff mbox

ACPI: Handle multiple button devices with the same name

Message ID 1299876888-6239-1-git-send-email-mjg@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Matthew Garrett March 11, 2011, 8:54 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 76bbb78..747db93 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -161,10 +161,15 @@  static struct proc_dir_entry *acpi_power_dir;
 static struct proc_dir_entry *acpi_sleep_dir;
 static struct proc_dir_entry *acpi_lid_dir;
 
+static int acpi_power_buttons;
+static int acpi_sleep_buttons;
+static int acpi_lid_buttons;
+
 static int acpi_button_add_fs(struct acpi_device *device)
 {
 	struct acpi_button *button = acpi_driver_data(device);
 	struct proc_dir_entry *entry = NULL;
+	char name[10];
 
 	switch (button->type) {
 	case ACPI_BUTTON_TYPE_POWER:
@@ -190,7 +195,41 @@  static int acpi_button_add_fs(struct acpi_device *device)
 	if (!entry)
 		return -ENODEV;
 
-	acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
+	switch (button->type) {
+	case ACPI_BUTTON_TYPE_POWER:
+		if (!acpi_power_buttons) {
+			acpi_device_dir(device) =
+				proc_mkdir(acpi_device_bid(device), entry);
+		} else {
+			snprintf(name, sizeof(name), "%s_%d",
+				 acpi_device_bid(device), acpi_power_buttons);
+			acpi_device_dir(device) = proc_mkdir(name, entry);
+		}
+		acpi_power_buttons++;
+		break;
+	case ACPI_BUTTON_TYPE_SLEEP:
+		if (!acpi_sleep_buttons) {
+			acpi_device_dir(device) =
+				proc_mkdir(acpi_device_bid(device), entry);
+		} else {
+			snprintf(name, sizeof(name), "%s_%d",
+				 acpi_device_bid(device), acpi_sleep_buttons);
+			acpi_device_dir(device) = proc_mkdir(name, entry);
+		}
+		acpi_sleep_buttons++;
+		break;
+	case ACPI_BUTTON_TYPE_LID:
+		if (!acpi_lid_buttons) {
+			acpi_device_dir(device) =
+				proc_mkdir(acpi_device_bid(device), entry);
+		} else {
+			snprintf(name, sizeof(name), "%s_%d",
+				 acpi_device_bid(device), acpi_lid_buttons);
+			acpi_device_dir(device) = proc_mkdir(name, entry);
+		}
+		acpi_lid_buttons++;
+		break;
+	}
 	if (!acpi_device_dir(device))
 		return -ENODEV;