linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] s3c-adc-battery: Add naive POWER_SUPPLY_PROP_PRESENT implementation
@ 2011-11-10  8:56 Heiko Stübner
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Stübner @ 2011-11-10  8:56 UTC (permalink / raw)
  To: Anton Vorontsov, David Woodhouse
  Cc: Vasily Khoruzhick, Linux PM mailing list, linux-kernel

Userspace programs like upower seem to depend on the presence of the
POWER_SUPPLY_PROP_PRESENT property.

The real presence of the battery cannot be sensed and all other
routines of s3c-adc-battery simply expect it to be present.

Therefore we simply return 1, unless the battery struct is not present at all.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/power/s3c_adc_battery.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
index d32d0d7..42d1f92 100644
--- a/drivers/power/s3c_adc_battery.c
+++ b/drivers/power/s3c_adc_battery.c
@@ -51,6 +51,7 @@ static enum power_supply_property s3c_adc_backup_bat_props[] = {
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_MIN,
 	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
+	POWER_SUPPLY_PROP_PRESENT,
 };
 
 static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
@@ -60,6 +61,11 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
 	struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
 
 	if (!bat) {
+		if (psp == POWER_SUPPLY_PROP_PRESENT) {
+			val->intval = 0;
+			return 0;
+		}
+
 		dev_err(psy->dev, "%s: no battery infos ?!\n", __func__);
 		return -EINVAL;
 	}
@@ -83,6 +89,9 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
 		val->intval = bat->pdata->backup_volt_max;
 		return 0;
+	case POWER_SUPPLY_PROP_PRESENT:
+		val->intval = 1;
+		return 0;
 	default:
 		return -EINVAL;
 	}
@@ -106,6 +115,7 @@ static enum power_supply_property s3c_adc_main_bat_props[] = {
 	POWER_SUPPLY_PROP_CHARGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
+	POWER_SUPPLY_PROP_PRESENT,
 };
 
 static int calc_full_volt(int volt_val, int cur_val, int impedance)
@@ -132,6 +142,11 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
 	unsigned int lut_size = bat->pdata->lut_noac_cnt;
 
 	if (!bat) {
+		if (psp == POWER_SUPPLY_PROP_PRESENT) {
+			val->intval = 0;
+			return 0;
+		}
+
 		dev_err(psy->dev, "no battery infos ?!\n");
 		return -EINVAL;
 	}
@@ -205,6 +220,9 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		val->intval = bat->cur_value;
 		return 0;
+	case POWER_SUPPLY_PROP_PRESENT:
+		val->intval = 1;
+		return 0;
 	default:
 		return -EINVAL;
 	}
-- 
1.6.1

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

* Re: [PATCH] s3c-adc-battery: Add naive POWER_SUPPLY_PROP_PRESENT implementation
       [not found] <201111100956.43979.heiko@sntech.de>
@ 2011-11-10 11:05 ` Vasily Khoruzhick
       [not found] ` <1320923106.2594.0.camel@anarsoul-laptop.Home>
  1 sibling, 0 replies; 4+ messages in thread
From: Vasily Khoruzhick @ 2011-11-10 11:05 UTC (permalink / raw)
  To: Heiko Stübner
  Cc: Anton Vorontsov, Linux PM mailing list, David Woodhouse,
	linux-kernel

On Thu, 2011-11-10 at 09:56 +0100, Heiko Stübner wrote:
> Userspace programs like upower seem to depend on the presence of the
> POWER_SUPPLY_PROP_PRESENT property.
> 
> The real presence of the battery cannot be sensed and all other
> routines of s3c-adc-battery simply expect it to be present.
> 
> Therefore we simply return 1, unless the battery struct is not present at all.

Looks OK for me,

> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Vasily Khoruzhick <anarsoul@gmail.com>

> ---
>  drivers/power/s3c_adc_battery.c |   18 ++++++++++++++++++
>  1 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
> index d32d0d7..42d1f92 100644
> --- a/drivers/power/s3c_adc_battery.c
> +++ b/drivers/power/s3c_adc_battery.c
> @@ -51,6 +51,7 @@ static enum power_supply_property s3c_adc_backup_bat_props[] = {
>  	POWER_SUPPLY_PROP_VOLTAGE_NOW,
>  	POWER_SUPPLY_PROP_VOLTAGE_MIN,
>  	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
> +	POWER_SUPPLY_PROP_PRESENT,
>  };
>  
>  static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
> @@ -60,6 +61,11 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
>  	struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
>  
>  	if (!bat) {
> +		if (psp == POWER_SUPPLY_PROP_PRESENT) {
> +			val->intval = 0;
> +			return 0;
> +		}
> +
>  		dev_err(psy->dev, "%s: no battery infos ?!\n", __func__);
>  		return -EINVAL;
>  	}
> @@ -83,6 +89,9 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
>  		val->intval = bat->pdata->backup_volt_max;
>  		return 0;
> +	case POWER_SUPPLY_PROP_PRESENT:
> +		val->intval = 1;
> +		return 0;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -106,6 +115,7 @@ static enum power_supply_property s3c_adc_main_bat_props[] = {
>  	POWER_SUPPLY_PROP_CHARGE_NOW,
>  	POWER_SUPPLY_PROP_VOLTAGE_NOW,
>  	POWER_SUPPLY_PROP_CURRENT_NOW,
> +	POWER_SUPPLY_PROP_PRESENT,
>  };
>  
>  static int calc_full_volt(int volt_val, int cur_val, int impedance)
> @@ -132,6 +142,11 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
>  	unsigned int lut_size = bat->pdata->lut_noac_cnt;
>  
>  	if (!bat) {
> +		if (psp == POWER_SUPPLY_PROP_PRESENT) {
> +			val->intval = 0;
> +			return 0;
> +		}
> +
>  		dev_err(psy->dev, "no battery infos ?!\n");
>  		return -EINVAL;
>  	}
> @@ -205,6 +220,9 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_CURRENT_NOW:
>  		val->intval = bat->cur_value;
>  		return 0;
> +	case POWER_SUPPLY_PROP_PRESENT:
> +		val->intval = 1;
> +		return 0;
>  	default:
>  		return -EINVAL;
>  	}


_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm

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

* Re: [PATCH] s3c-adc-battery: Add naive POWER_SUPPLY_PROP_PRESENT implementation
       [not found] ` <1320923106.2594.0.camel@anarsoul-laptop.Home>
@ 2011-11-10 13:30   ` Anton Vorontsov
  2011-11-11 15:18     ` Heiko Stübner
  0 siblings, 1 reply; 4+ messages in thread
From: Anton Vorontsov @ 2011-11-10 13:30 UTC (permalink / raw)
  To: Vasily Khoruzhick; +Cc: Linux PM mailing list, David Woodhouse, linux-kernel

On Thu, Nov 10, 2011 at 02:05:06PM +0300, Vasily Khoruzhick wrote:
> On Thu, 2011-11-10 at 09:56 +0100, Heiko Stübner wrote:
> > Userspace programs like upower seem to depend on the presence of the
> > POWER_SUPPLY_PROP_PRESENT property.
> > 
> > The real presence of the battery cannot be sensed and all other
> > routines of s3c-adc-battery simply expect it to be present.
> > 
> > Therefore we simply return 1, unless the battery struct is not present at all.
> 
> Looks OK for me,
> 
> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> Acked-by: Vasily Khoruzhick <anarsoul@gmail.com>

I disagree. If the driver behaves like the hardware does not support
hot-pluggable cells, then present property is not necessary.

Upowerd should look at the 'present' only if it is there; and if it
is not, cells assumed to be always present.

[..]
> >  	if (!bat) {
> > +		if (psp == POWER_SUPPLY_PROP_PRESENT) {
> > +			val->intval = 0;
> > +			return 0;
> > +		}
> > +
> >  		dev_err(psy->dev, "%s: no battery infos ?!\n", __func__);

And in this case that dev_err() tells that either hardware does not
support hot-pluggable cells, or driver does not handle this case; which
is actually the same from the userspace point of view.

So, the problem is in upowerd, not this driver.

Thanks,

-- 
Anton Vorontsov
Email: cbouatmailru@gmail.com
_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm

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

* Re: [PATCH] s3c-adc-battery: Add naive POWER_SUPPLY_PROP_PRESENT implementation
  2011-11-10 13:30   ` Anton Vorontsov
@ 2011-11-11 15:18     ` Heiko Stübner
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Stübner @ 2011-11-11 15:18 UTC (permalink / raw)
  To: Anton Vorontsov
  Cc: Vasily Khoruzhick, Linux PM mailing list, David Woodhouse,
	linux-kernel

Am Donnerstag, 10. November 2011, 14:30:52 schrieb Anton Vorontsov:
> On Thu, Nov 10, 2011 at 02:05:06PM +0300, Vasily Khoruzhick wrote:
> > On Thu, 2011-11-10 at 09:56 +0100, Heiko Stübner wrote:
> > > Userspace programs like upower seem to depend on the presence of the
> > > POWER_SUPPLY_PROP_PRESENT property.
> > > 
> > > The real presence of the battery cannot be sensed and all other
> > > routines of s3c-adc-battery simply expect it to be present.
> > > 
> > > Therefore we simply return 1, unless the battery struct is not present
> > > at all.
> > 
> > Looks OK for me,
> > 
> > > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > 
> > Acked-by: Vasily Khoruzhick <anarsoul@gmail.com>
> 
> I disagree. If the driver behaves like the hardware does not support
> hot-pluggable cells, then present property is not necessary.
> 
> Upowerd should look at the 'present' only if it is there; and if it
> is not, cells assumed to be always present.

[..]
 
> So, the problem is in upowerd, not this driver.

Thanks for your comment. I will therefore take this matter up with the upower-
guys.

Thanks
Heiko
_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm

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

end of thread, other threads:[~2011-11-11 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <201111100956.43979.heiko@sntech.de>
2011-11-10 11:05 ` [PATCH] s3c-adc-battery: Add naive POWER_SUPPLY_PROP_PRESENT implementation Vasily Khoruzhick
     [not found] ` <1320923106.2594.0.camel@anarsoul-laptop.Home>
2011-11-10 13:30   ` Anton Vorontsov
2011-11-11 15:18     ` Heiko Stübner
2011-11-10  8:56 Heiko Stübner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).