All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] power_supply: Register power supply for thermal cooling device
@ 2012-10-09 16:55 Ramakrishna Pallala
  2012-11-18  4:35 ` Anton Vorontsov
  0 siblings, 1 reply; 3+ messages in thread
From: Ramakrishna Pallala @ 2012-10-09 16:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, Anton Vorontsov, Jenny TC, Durgadoss R,
	Ramakrishna Pallala

This patch registers the power supply as a cooling device if the
power supply has support for charge throttling.

Now with this change low level drivers need not register with
thermal framework as it is automatically done by power supply framework.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
---
 drivers/power/power_supply_core.c |  100 +++++++++++++++++++++++++++++++++++++
 include/linux/power_supply.h      |    1 +
 2 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 08cc8a3..3338d49 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -216,6 +216,89 @@ static void psy_unregister_thermal(struct power_supply *psy)
 		return;
 	thermal_zone_device_unregister(psy->tzd);
 }
+
+/* thermal cooling device callbacks */
+static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
+						unsigned long *state)
+{
+	struct power_supply *psy;
+	union power_supply_propval val;
+	int ret;
+
+	WARN_ON(tcd == NULL);
+	psy = tcd->devdata;
+	ret = psy->get_property(psy,
+		POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
+	if (!ret)
+		*state = val.intval;
+
+	return ret;
+}
+
+static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
+						unsigned long *state)
+{
+	struct power_supply *psy;
+	union power_supply_propval val;
+	int ret;
+
+	WARN_ON(tcd == NULL);
+	psy = tcd->devdata;
+	ret = psy->get_property(psy,
+		POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
+	if (!ret)
+		*state = val.intval;
+
+	return ret;
+}
+
+static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
+							unsigned long state)
+{
+	struct power_supply *psy;
+	union power_supply_propval val;
+	int ret;
+
+	WARN_ON(tcd == NULL);
+	psy = tcd->devdata;
+	val.intval = state;
+	ret = psy->set_property(psy,
+		POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
+
+	return ret;
+}
+
+static struct thermal_cooling_device_ops psy_tcd_ops = {
+	.get_max_state = ps_get_max_charge_cntl_limit,
+	.get_cur_state = ps_get_cur_chrage_cntl_limit,
+	.set_cur_state = ps_set_cur_charge_cntl_limit,
+};
+
+static int psy_register_cooler(struct power_supply *psy)
+{
+	int i;
+
+	/* Register for cooling device if psy can control charging */
+	for (i = 0; i < psy->num_properties; i++) {
+		if (psy->properties[i] ==
+				POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
+			psy->tcd = thermal_cooling_device_register(
+							(char *)psy->name,
+							psy, &psy_tcd_ops);
+			if (IS_ERR(psy->tcd))
+				return PTR_ERR(psy->tcd);
+			break;
+		}
+	}
+	return 0;
+}
+
+static void psy_unregister_cooler(struct power_supply *psy)
+{
+	if (IS_ERR_OR_NULL(psy->tcd))
+		return;
+	thermal_cooling_device_unregister(psy->tcd);
+}
 #else
 static int psy_register_thermal(struct power_supply *psy)
 {
@@ -225,6 +308,16 @@ static int psy_register_thermal(struct power_supply *psy)
 static void psy_unregister_thermal(struct power_supply *psy)
 {
 }
+
+static int psy_register_cooler(struct power_supply *psy)
+{
+	return 0;
+}
+
+static void psy_unregister_cooler(struct power_supply *psy)
+{
+
+}
 #endif
 
 int power_supply_register(struct device *parent, struct power_supply *psy)
@@ -259,6 +352,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
 	if (rc)
 		goto register_thermal_failed;
 
+	rc = psy_register_cooler(psy);
+	if (rc)
+		goto register_cooler_failed;
+
 	rc = power_supply_create_triggers(psy);
 	if (rc)
 		goto create_triggers_failed;
@@ -268,6 +365,8 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
 	goto success;
 
 create_triggers_failed:
+	psy_unregister_cooler(psy);
+register_cooler_failed:
 	psy_unregister_thermal(psy);
 register_thermal_failed:
 	device_del(dev);
@@ -284,6 +383,7 @@ void power_supply_unregister(struct power_supply *psy)
 	cancel_work_sync(&psy->changed_work);
 	sysfs_remove_link(&psy->dev->kobj, "powers");
 	power_supply_remove_triggers(psy);
+	psy_unregister_cooler(psy);
 	psy_unregister_thermal(psy);
 	device_unregister(psy->dev);
 }
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 445b4b2..1f0ab90 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -188,6 +188,7 @@ struct power_supply {
 	struct work_struct changed_work;
 #ifdef CONFIG_THERMAL
 	struct thermal_zone_device *tzd;
+	struct thermal_cooling_device *tcd;
 #endif
 
 #ifdef CONFIG_LEDS_TRIGGERS
-- 
1.7.0.4


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

* Re: [PATCH 2/2] power_supply: Register power supply for thermal cooling device
  2012-10-09 16:55 [PATCH 2/2] power_supply: Register power supply for thermal cooling device Ramakrishna Pallala
@ 2012-11-18  4:35 ` Anton Vorontsov
  2012-11-19  6:25   ` Pallala, Ramakrishna
  0 siblings, 1 reply; 3+ messages in thread
From: Anton Vorontsov @ 2012-11-18  4:35 UTC (permalink / raw)
  To: Ramakrishna Pallala; +Cc: linux-kernel, Jenny TC, Durgadoss R

On Tue, Oct 09, 2012 at 10:25:59PM +0530, Ramakrishna Pallala wrote:
> This patch registers the power supply as a cooling device if the
> power supply has support for charge throttling.
> 
> Now with this change low level drivers need not register with
> thermal framework as it is automatically done by power supply framework.
> 
> Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
> ---
>  drivers/power/power_supply_core.c |  100 +++++++++++++++++++++++++++++++++++++
>  include/linux/power_supply.h      |    1 +
>  2 files changed, 101 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
> index 08cc8a3..3338d49 100644
> --- a/drivers/power/power_supply_core.c
> +++ b/drivers/power/power_supply_core.c
[...]
> +static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
> +						unsigned long *state)
> +{
> +	struct power_supply *psy;
> +	union power_supply_propval val;
> +	int ret;
> +
> +	WARN_ON(tcd == NULL);
> +	psy = tcd->devdata;
> +	ret = psy->get_property(psy,
> +		POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
> +	if (!ret)
> +		*state = val.intval;
> +
> +	return ret;
> +}
> +
> +static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,

Typo, "charge".

> +						unsigned long *state)
> +{
> +	struct power_supply *psy;
> +	union power_supply_propval val;
> +	int ret;
> +
> +	WARN_ON(tcd == NULL);

This is unneeded, we'll get oops anyway.

I fixed it up and applied, thank you!

Anton.

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

* RE: [PATCH 2/2] power_supply: Register power supply for thermal cooling device
  2012-11-18  4:35 ` Anton Vorontsov
@ 2012-11-19  6:25   ` Pallala, Ramakrishna
  0 siblings, 0 replies; 3+ messages in thread
From: Pallala, Ramakrishna @ 2012-11-19  6:25 UTC (permalink / raw)
  To: Anton Vorontsov; +Cc: linux-kernel, Tc, Jenny, R, Durgadoss

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 537 bytes --]

> > +static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device
> > +*tcd,
> 
> Typo, "charge".
> 
> > +						unsigned long *state)
> > +{
> > +	struct power_supply *psy;
> > +	union power_supply_propval val;
> > +	int ret;
> > +
> > +	WARN_ON(tcd == NULL);
> 
> This is unneeded, we'll get oops anyway.
> 
> I fixed it up and applied, thank you!

Gr8 Thanks!

/Ram
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

end of thread, other threads:[~2012-11-19  6:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 16:55 [PATCH 2/2] power_supply: Register power supply for thermal cooling device Ramakrishna Pallala
2012-11-18  4:35 ` Anton Vorontsov
2012-11-19  6:25   ` Pallala, Ramakrishna

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.