public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: battery: register power_supply subdevice even when battery not present
@ 2010-04-05 16:23 Alexey Starikovskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Alexey Starikovskiy @ 2010-04-05 16:23 UTC (permalink / raw)
  To: Len Brown; +Cc: Linux-acpi

From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>

Keeping this device around lets userspace know that we have a battery
bay, even if there is nothing in it at the moment.  This is what every
other battery driver does, so ACPI should do it as well.

For example, this means gnome-power-manager will now allow configuring
behaviour for "on battery power" if the battery bay was empty on
startup. (Thanks to Maxim Levitsky for pointing this out).

There is no reason to preserve the old behaviour.  We now correctly
provide the "present" attribute, which will return "0" when the battery
is removed.  HAL was already trying to check this attribute when
the old behaviour was implemented.  This should not break any version
of HAL.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
---

 drivers/acpi/battery.c |   36 ++++++++++++++++--------------------
 1 files changed, 16 insertions(+), 20 deletions(-)


diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index db78b6e..5b9fd78 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -546,8 +546,6 @@ static int sysfs_add_battery(struct acpi_battery *battery)
 
 static void sysfs_remove_battery(struct acpi_battery *battery)
 {
-	if (!battery->bat.dev)
-		return;
 	device_remove_file(battery->bat.dev, &alarm_attr);
 	power_supply_unregister(&battery->bat);
 	battery->bat.dev = NULL;
@@ -568,9 +566,6 @@ static int acpi_battery_update(struct acpi_battery *battery)
 	if (result)
 		return result;
 	if (!acpi_battery_present(battery)) {
-#ifdef CONFIG_ACPI_SYSFS_POWER
-		sysfs_remove_battery(battery);
-#endif
 		battery->update_time = 0;
 		return 0;
 	}
@@ -582,10 +577,6 @@ static int acpi_battery_update(struct acpi_battery *battery)
 		acpi_battery_quirks(battery);
 		acpi_battery_init_alarm(battery);
 	}
-#ifdef CONFIG_ACPI_SYSFS_POWER
-	if (!battery->bat.dev)
-		sysfs_add_battery(battery);
-#endif
 	return acpi_battery_get_state(battery);
 }
 
@@ -877,9 +868,7 @@ static void acpi_battery_notify(struct acpi_device *device, u32 event)
 					dev_name(&device->dev), event,
 					acpi_battery_present(battery));
 #ifdef CONFIG_ACPI_SYSFS_POWER
-	/* acpi_battery_update could remove power_supply object */
-	if (battery->bat.dev)
-		power_supply_changed(&battery->bat);
+	power_supply_changed(&battery->bat);
 #endif
 }
 
@@ -904,17 +893,24 @@ static int acpi_battery_add(struct acpi_device *device)
 	acpi_battery_update(battery);
 #ifdef CONFIG_ACPI_PROCFS_POWER
 	result = acpi_battery_add_fs(device);
+	if (result)
+		goto fail;
 #endif
-	if (!result) {
-		printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
-			ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
-			device->status.battery_present ? "present" : "absent");
-	} else {
+#ifdef CONFIG_ACPI_SYSFS_POWER
+	result = sysfs_add_battery(battery);
+	if (result)
+		goto fail;
+#endif
+	printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
+		ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
+		device->status.battery_present ? "present" : "absent");
+	return 0;
+
+fail:
 #ifdef CONFIG_ACPI_PROCFS_POWER
-		acpi_battery_remove_fs(device);
+	acpi_battery_remove_fs(device);
 #endif
-		kfree(battery);
-	}
+	kfree(battery);
 	return result;
 }
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: battery: register power_supply subdevice even when battery not present
@ 2009-09-11 12:28 Alan Jenkins
  2009-09-11 13:10 ` Anton Vorontsov
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Jenkins @ 2009-09-11 12:28 UTC (permalink / raw)
  To: Maxim Levitsky
  Cc: Anton Vorontsov, David Woodhouse, linux acpi, Alexey Starikovskiy

[CC power_supply maintainers]

I tried to fix the ACPI battery driver so it created a power supply
device even if the battery is not present.  All the other battery
drivers do this.  It would let e.g. gnome-power-manager to detect the
presence of a battery bay, and allow configuration of battery
behaviour even when the battery has been removed.

Unfortunately this is not as easy as I thought.  We would need to
either modify or work around the generic power supply class, so I
would like to ask your opinion on this.

On 9/11/09, Maxim Levitsky <maximlevitsky@gmail.com> wrote:
> Indeed, it works.
>
>
> Just one issue though, if I plug in the battery after system boot, it is
> detected a an 'energy battery' (energy_battery_props are used)
>
> ACPI seems to be ok:
...
> PBIF at offset 0 is set correctly to 1.

Your ACPI is fine - there's a fatal flaw in my patch.  It doesn't
evaluate _BIF until the battery is inserted.  At that point it is too
late to change the set of properties on the battery device, because
it's already been created.

The problem is that this power_unit value is allowed to change between
mW and mA when the battery is hotplugged.  And it looks like it does
on some machines, going from 0 to 1 when a battery is inserted.  So we
can't just read it at load time.

I can think of some more complex ways to do this

1) Destroy and recreate the battery device on hotplug.
2) Modify the generic power supply class to allow changing the set of attribute.
3) Restructure the interface to provide a "battery bay" device as a parent.

1) and 2) are hacks.  1) could at least cause annoyingly spurious UI
events.  2) sounds like a bad idea, but existing userspace _might_
handle it because it already happens at registration time.  (Power
supply attributes aren't available on the initial ADD uevent; they are
added in a follow-up CHANGE uevent).

3) could be backwards compatible and relatively straightforward.  The
"battery bay" could be a new type of power supply device, with no
attributes of its own.  It could be created automatically for non-acpi
batteries.  Userspace would have to be taught about it, but perhaps
this is a good time to do so since HAL is currently being replaced by
DevKit.

Alan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-05 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-05 16:23 [PATCH] ACPI: battery: register power_supply subdevice even when battery not present Alexey Starikovskiy
  -- strict thread matches above, loose matches on Subject: below --
2009-09-11 12:28 Alan Jenkins
2009-09-11 13:10 ` Anton Vorontsov
2009-09-11 14:16   ` Alan Jenkins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox