Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320485
b: refs/heads/master
c: 3be330b
h: refs/heads/master
i:
  320483: 5c1a879
v: v3
  • Loading branch information
Jenny TC authored and Anton Vorontsov committed Jun 18, 2012
1 parent 271b05b commit 0a1524d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7dbae5562e86f2731d13bd2b8b3ea3f974f4b87d
refs/heads/master: 3be330bf8860dc6079da5acc81295787a04cf4c9
65 changes: 65 additions & 0 deletions trunk/drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/power_supply.h>
#include <linux/thermal.h>
#include "power_supply.h"

/* exported for the APM Power driver, APM emulation */
Expand Down Expand Up @@ -169,6 +170,63 @@ static void power_supply_dev_release(struct device *dev)
kfree(dev);
}

#ifdef CONFIG_THERMAL
static int power_supply_read_temp(struct thermal_zone_device *tzd,
unsigned long *temp)
{
struct power_supply *psy;
union power_supply_propval val;
int ret;

WARN_ON(tzd == NULL);
psy = tzd->devdata;
ret = psy->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);

/* Convert tenths of degree Celsius to milli degree Celsius. */
if (!ret)
*temp = val.intval * 100;

return ret;
}

static struct thermal_zone_device_ops psy_tzd_ops = {
.get_temp = power_supply_read_temp,
};

static int psy_register_thermal(struct power_supply *psy)
{
int i;

/* Register battery zone device psy reports temperature */
for (i = 0; i < psy->num_properties; i++) {
if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) {
psy->tzd = thermal_zone_device_register(psy->name, 0,
psy, &psy_tzd_ops, 0, 0, 0, 0);
if (IS_ERR(psy->tzd))
return PTR_ERR(psy->tzd);
break;
}
}
return 0;
}

static void psy_unregister_thermal(struct power_supply *psy)
{
if (IS_ERR_OR_NULL(psy->tzd))
return;
thermal_zone_device_unregister(psy->tzd);
}
#else
static int psy_register_thermal(struct power_supply *psy)
{
return 0;
}

static void psy_unregister_thermal(struct power_supply *psy)
{
}
#endif

int power_supply_register(struct device *parent, struct power_supply *psy)
{
struct device *dev;
Expand Down Expand Up @@ -197,6 +255,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
if (rc)
goto device_add_failed;

rc = psy_register_thermal(psy);
if (rc)
goto register_thermal_failed;

rc = power_supply_create_triggers(psy);
if (rc)
goto create_triggers_failed;
Expand All @@ -206,6 +268,8 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
goto success;

create_triggers_failed:
psy_unregister_thermal(psy);
register_thermal_failed:
device_del(dev);
kobject_set_name_failed:
device_add_failed:
Expand All @@ -220,6 +284,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_thermal(psy);
device_unregister(psy->dev);
}
EXPORT_SYMBOL_GPL(power_supply_unregister);
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/power_supply.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ struct power_supply {
/* private */
struct device *dev;
struct work_struct changed_work;
#ifdef CONFIG_THERMAL
struct thermal_zone_device *tzd;
#endif

#ifdef CONFIG_LEDS_TRIGGERS
struct led_trigger *charging_full_trig;
Expand Down

0 comments on commit 0a1524d

Please sign in to comment.