public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes.
@ 2014-03-02 11:02 Alexander Mezin
  2014-03-06 13:15 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Mezin @ 2014-03-02 11:02 UTC (permalink / raw)
  To: linux-acpi; +Cc: Lan Tianyu, Alexander Mezin

On HP Pavilion dv6-6179er there are no notifications when AC adapter
is plugged/unplugged.

Output of acpi_listen, adapter is unplugged and then plugged in back:

battery PNP0C0A:00 00000001 00000001
battery PNP0C0A:00 00000080 00000001
 PNP0C14:00 00000080 00000000
processor LNXCPU:00 00000082 00000000
battery PNP0C0A:00 00000000 00000001
battery PNP0C0A:00 00000080 00000001
 PNP0C14:00 00000080 00000000
processor LNXCPU:00 00000082 00000000
battery PNP0C0A:00 00000080 00000001

The only way to trigger the notification is to read "online"
property in sysfs (/sys/class/power_supply/AC/online).

This patch triggers the notification by calling get_property for
every mains power supply.

Output of acpi_listen with this patch applied:

battery PNP0C0A:00 00000001 00000001
battery PNP0C0A:00 00000080 00000001
 PNP0C14:00 00000080 00000000
ac_adapter ACPI0003:00 00000000 00000000
processor LNXCPU:00 00000082 00000000
battery PNP0C0A:00 00000000 00000001
battery PNP0C0A:00 00000080 00000001
 PNP0C14:00 00000080 00000000
ac_adapter ACPI0003:00 00000000 00000001
processor LNXCPU:00 00000082 00000000
battery PNP0C0A:00 00000080 00000001

I'm using this patch for about a month, and didn't notice any
problems. I've tested it on top of both 3.13.5 and 3.14-rc4.

Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>

---
 v2: more verbose description

 drivers/acpi/battery.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 797a693..fb548f0 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -671,9 +671,22 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
 	}
 }
 
+static int acpi_battery_check_ac_state(struct device *dev, void *unused)
+{
+	struct power_supply *ps = dev_get_drvdata(dev);
+	union power_supply_propval temp;
+
+	if (ps->type != POWER_SUPPLY_TYPE_MAINS)
+		return 0;
+
+	ps->get_property(ps, POWER_SUPPLY_PROP_ONLINE, &temp);
+	return 0;
+}
+
 static int acpi_battery_update(struct acpi_battery *battery)
 {
 	int result, old_present = acpi_battery_present(battery);
+	int old_state = battery->state;
 	result = acpi_battery_get_status(battery);
 	if (result)
 		return result;
@@ -696,6 +709,15 @@ static int acpi_battery_update(struct acpi_battery *battery)
 	}
 	result = acpi_battery_get_state(battery);
 	acpi_battery_quirks(battery);
+	if (old_state != battery->state)
+		/*
+		 * Some BIOSes don't send notifications when AC adapter
+		 * is plugged or unplugged.
+		 * If battery changes its state, this could indicate that
+		 * AC adapter's state has changed too.
+		 */
+		class_for_each_device(power_supply_class, NULL, NULL,
+				      &acpi_battery_check_ac_state);
 	return result;
 }
 
-- 
1.9.0


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

* Re: [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes.
  2014-03-02 11:02 [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes Alexander Mezin
@ 2014-03-06 13:15 ` Rafael J. Wysocki
  2014-03-07  3:43   ` Lan Tianyu
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2014-03-06 13:15 UTC (permalink / raw)
  To: Alexander Mezin, Lan Tianyu; +Cc: linux-acpi

On Sunday, March 02, 2014 06:02:39 PM Alexander Mezin wrote:
> On HP Pavilion dv6-6179er there are no notifications when AC adapter
> is plugged/unplugged.
> 
> Output of acpi_listen, adapter is unplugged and then plugged in back:
> 
> battery PNP0C0A:00 00000001 00000001
> battery PNP0C0A:00 00000080 00000001
>  PNP0C14:00 00000080 00000000
> processor LNXCPU:00 00000082 00000000
> battery PNP0C0A:00 00000000 00000001
> battery PNP0C0A:00 00000080 00000001
>  PNP0C14:00 00000080 00000000
> processor LNXCPU:00 00000082 00000000
> battery PNP0C0A:00 00000080 00000001
> 
> The only way to trigger the notification is to read "online"
> property in sysfs (/sys/class/power_supply/AC/online).
> 
> This patch triggers the notification by calling get_property for
> every mains power supply.
> 
> Output of acpi_listen with this patch applied:
> 
> battery PNP0C0A:00 00000001 00000001
> battery PNP0C0A:00 00000080 00000001
>  PNP0C14:00 00000080 00000000
> ac_adapter ACPI0003:00 00000000 00000000
> processor LNXCPU:00 00000082 00000000
> battery PNP0C0A:00 00000000 00000001
> battery PNP0C0A:00 00000080 00000001
>  PNP0C14:00 00000080 00000000
> ac_adapter ACPI0003:00 00000000 00000001
> processor LNXCPU:00 00000082 00000000
> battery PNP0C0A:00 00000080 00000001
> 
> I'm using this patch for about a month, and didn't notice any
> problems. I've tested it on top of both 3.13.5 and 3.14-rc4.
> 
> Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>

Tiany, do you have any more comments here?

> 
> ---
>  v2: more verbose description
> 
>  drivers/acpi/battery.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 797a693..fb548f0 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -671,9 +671,22 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
>  	}
>  }
>  
> +static int acpi_battery_check_ac_state(struct device *dev, void *unused)
> +{
> +	struct power_supply *ps = dev_get_drvdata(dev);
> +	union power_supply_propval temp;
> +
> +	if (ps->type != POWER_SUPPLY_TYPE_MAINS)
> +		return 0;
> +
> +	ps->get_property(ps, POWER_SUPPLY_PROP_ONLINE, &temp);
> +	return 0;
> +}
> +
>  static int acpi_battery_update(struct acpi_battery *battery)
>  {
>  	int result, old_present = acpi_battery_present(battery);
> +	int old_state = battery->state;
>  	result = acpi_battery_get_status(battery);
>  	if (result)
>  		return result;
> @@ -696,6 +709,15 @@ static int acpi_battery_update(struct acpi_battery *battery)
>  	}
>  	result = acpi_battery_get_state(battery);
>  	acpi_battery_quirks(battery);
> +	if (old_state != battery->state)
> +		/*
> +		 * Some BIOSes don't send notifications when AC adapter
> +		 * is plugged or unplugged.
> +		 * If battery changes its state, this could indicate that
> +		 * AC adapter's state has changed too.
> +		 */
> +		class_for_each_device(power_supply_class, NULL, NULL,
> +				      &acpi_battery_check_ac_state);
>  	return result;
>  }
>  
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes.
  2014-03-06 13:15 ` Rafael J. Wysocki
@ 2014-03-07  3:43   ` Lan Tianyu
  2014-03-08  5:45     ` Alexander Mezin
  0 siblings, 1 reply; 4+ messages in thread
From: Lan Tianyu @ 2014-03-07  3:43 UTC (permalink / raw)
  To: Rafael J. Wysocki, Alexander Mezin; +Cc: linux-acpi

On 03/06/2014 09:15 PM, Rafael J. Wysocki wrote:
> On Sunday, March 02, 2014 06:02:39 PM Alexander Mezin wrote:
>> On HP Pavilion dv6-6179er there are no notifications when AC adapter
>> is plugged/unplugged.
>>
>> Output of acpi_listen, adapter is unplugged and then plugged in back:
>>
>> battery PNP0C0A:00 00000001 00000001
>> battery PNP0C0A:00 00000080 00000001
>>   PNP0C14:00 00000080 00000000
>> processor LNXCPU:00 00000082 00000000
>> battery PNP0C0A:00 00000000 00000001
>> battery PNP0C0A:00 00000080 00000001
>>   PNP0C14:00 00000080 00000000
>> processor LNXCPU:00 00000082 00000000
>> battery PNP0C0A:00 00000080 00000001
>>
>> The only way to trigger the notification is to read "online"
>> property in sysfs (/sys/class/power_supply/AC/online).
>>
>> This patch triggers the notification by calling get_property for
>> every mains power supply.
>>
>> Output of acpi_listen with this patch applied:
>>
>> battery PNP0C0A:00 00000001 00000001
>> battery PNP0C0A:00 00000080 00000001
>>   PNP0C14:00 00000080 00000000
>> ac_adapter ACPI0003:00 00000000 00000000
>> processor LNXCPU:00 00000082 00000000
>> battery PNP0C0A:00 00000000 00000001
>> battery PNP0C0A:00 00000080 00000001
>>   PNP0C14:00 00000080 00000000
>> ac_adapter ACPI0003:00 00000000 00000001
>> processor LNXCPU:00 00000082 00000000
>> battery PNP0C0A:00 00000080 00000001
>>
>> I'm using this patch for about a month, and didn't notice any
>> problems. I've tested it on top of both 3.13.5 and 3.14-rc4.
>>
>> Signed-off-by: Alexander Mezin <mezin.alexander@gmail.com>
>
> Tiany, do you have any more comments here?
>

Sorry for later response due to be busy on other things.

Hi Alexander:

 From the DSDT table, _Q08 is in change of notifying AC driver.
So you can check "/sys/firmware/acpi/interrupts/gpe08". Whether the 
count increases or not during plugging or unplugging AC.

According the description, the _Q08 wasn't triggered.

 >> The only way to trigger the notification is to read "online"
 >> property in sysfs (/sys/class/power_supply/AC/online).

The AC status is read and _PSR() is invoked during "online" file is 
accessed.

_PSR() compares EC AC status with previous stored value and notify AC 
driver if these values are not equal. This is why there is AC event 
after accessing "online" sysfs interface.

Method (_PSR, 0, NotSerialized)  // _PSR: Power Source
{
     Store (ACP, Local0)
     If (^^PCI0.LPCB.EC.ECOK)
     {
         Store (^^PCI0.LPCB.EC.ADP, Local0)
         If (LNotEqual (Local0, ACP))
         {
             FLPA ()
         }
     }
	.....
}


Method (FLPA, 0, NotSerialized)
{
     If (ACP)
     {
         Store (Zero, ACP)
     }
     Else
     {
         Store (One, ACP)
     }

     Notify (AC, Zero)
}


>>
>> ---
>>   v2: more verbose description
>>
>>   drivers/acpi/battery.c | 22 ++++++++++++++++++++++
>>   1 file changed, 22 insertions(+)
>>
>> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
>> index 797a693..fb548f0 100644
>> --- a/drivers/acpi/battery.c
>> +++ b/drivers/acpi/battery.c
>> @@ -671,9 +671,22 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
>>   	}
>>   }
>>
>> +static int acpi_battery_check_ac_state(struct device *dev, void *unused)
>> +{
>> +	struct power_supply *ps = dev_get_drvdata(dev);
>> +	union power_supply_propval temp;
>> +
>> +	if (ps->type != POWER_SUPPLY_TYPE_MAINS)
>> +		return 0;
>> +
>> +	ps->get_property(ps, POWER_SUPPLY_PROP_ONLINE, &temp);
>> +	return 0;
>> +}
>> +
>>   static int acpi_battery_update(struct acpi_battery *battery)
>>   {
>>   	int result, old_present = acpi_battery_present(battery);
>> +	int old_state = battery->state;
>>   	result = acpi_battery_get_status(battery);
>>   	if (result)
>>   		return result;
>> @@ -696,6 +709,15 @@ static int acpi_battery_update(struct acpi_battery *battery)
>>   	}
>>   	result = acpi_battery_get_state(battery);
>>   	acpi_battery_quirks(battery);
>> +	if (old_state != battery->state)
>> +		/*
>> +		 * Some BIOSes don't send notifications when AC adapter
>> +		 * is plugged or unplugged.
>> +		 * If battery changes its state, this could indicate that
>> +		 * AC adapter's state has changed too.
>> +		 */
>> +		class_for_each_device(power_supply_class, NULL, NULL,
>> +				      &acpi_battery_check_ac_state);

I think you can use acpi_notifier_call_chain() here and register acpi 
notifier in the AC driver. When get the Battery change event, call 
acpi_ac_get_state(ac). From my view, this is more general than traverse 
all power supply device and call AC's get_property() callback in battery 
driver.

>>   	return result;
>>   }
>>
>>
>


-- 
Best Regards
Tianyu Lan

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

* Re: [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes.
  2014-03-07  3:43   ` Lan Tianyu
@ 2014-03-08  5:45     ` Alexander Mezin
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Mezin @ 2014-03-08  5:45 UTC (permalink / raw)
  To: Lan Tianyu; +Cc: Rafael J. Wysocki, linux-acpi@vger.kernel.org

2014-03-07 10:43 GMT+07:00 Lan Tianyu <tianyu.lan@intel.com>:
> Sorry for later response due to be busy on other things.
>
> Hi Alexander:
>
> From the DSDT table, _Q08 is in change of notifying AC driver.
> So you can check "/sys/firmware/acpi/interrupts/gpe08". Whether the count
> increases or not during plugging or unplugging AC.
>
> According the description, the _Q08 wasn't triggered.

cat /sys/firmware/acpi/interrupts/gpe08
       0   invalid

Always.

> I think you can use acpi_notifier_call_chain() here and register acpi
> notifier in the AC driver. When get the Battery change event, call
> acpi_ac_get_state(ac). From my view, this is more general than traverse all
> power supply device and call AC's get_property() callback in battery driver.

Thanks for this suggestion. This looks like better solution for me
too. I'll prepare v3 soon.

>
> --
> Best Regards
> Tianyu Lan

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

end of thread, other threads:[~2014-03-08  5:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-02 11:02 [PATCH v2] ACPI / battery: trigger rechecking of AC adapter state when battery state changes Alexander Mezin
2014-03-06 13:15 ` Rafael J. Wysocki
2014-03-07  3:43   ` Lan Tianyu
2014-03-08  5:45     ` Alexander Mezin

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