forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'for-v3.10' of git://git.infradead.org/battery-2.6
Pull battery updates from Anton Vorontsov: "Highlights: - OpenFirmware/DeviceTree support for the Power Supply core: the core now automatically populates supplied_from hierarchy from the device tree. With these patches chargers and batteries can now lookup each other without the board files support shim. Rhyland Klein at NVIDIA did the work - New ST-Ericsson ABX500 hwmon driver. The driver is heavily using the AB85xx core and depends on some recent changes to it, so that is why the driver comes through the battery tree. It has an appropriate ack from the hwmon maintainer (i.e. Guenter Roeck). Martin Persson at ST-Ericsson and Hongbo Zhang at Linaro authored the driver - Final bits to sync AB85xx ST-Ericsson changes into mainline. The changes touch mfd parts, but these were acked by the appropriate MFD maintainer (ie Samuel Ortiz). Lee Jones at Linaro did most of the work and lead the submission process. Minor changes, but still worth mentioning: - Battery temperature reporting fix for Nokia N900 phones - Versatile Express poweroff driver moved into drivers/power/reset/ - Tree-wide: use devm_kzalloc() where appropriate - Tree-wide: dev_pm_ops cleanups/fixes" * tag 'for-v3.10' of git://git.infradead.org/battery-2.6: (112 commits) pm2301-charger: Fix suspend/resume charger-manager: Use kmemdup instead of kzalloc + memcpy power_supply: Populate supplied_from hierarchy from the device tree power_supply: Add core support for supplied_from power_supply: Define Binding for power-supplies rx51_battery: Fix reporting temperature hwmon: Add ST-Ericsson ABX500 hwmon driver ab8500_bmdata: Export abx500_res_to_temp tables for hwmon ab8500_{bmdata,fg}: Add const attributes to some data arrays ab8500_bmdata: Eliminate CamelCase warning of some variables ab8500_btemp: Make ab8500_btemp_get* interfaces public goldfish_battery: Use resource_size() lp8788-charger: Use PAGE_SIZE for the sysfs read operation max8925_power: Use devm_kzalloc() da9030_battery: Use devm_kzalloc() da9052-battery: Use devm_kzalloc() ds2760_battery: Use devm_kzalloc() ds2780_battery: Use devm_kzalloc() gpio-charger: Use devm_kzalloc() isp1704_charger: Use devm_kzalloc() ...
- Loading branch information
Showing
64 changed files
with
6,393 additions
and
1,500 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Documentation/devicetree/bindings/power_supply/power_supply.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Power Supply Core Support | ||
|
||
Optional Properties: | ||
- power-supplies : This property is added to a supply in order to list the | ||
devices which supply it power, referenced by their phandles. | ||
|
||
Example: | ||
|
||
usb-charger: power@e { | ||
compatible = "some,usb-charger"; | ||
... | ||
}; | ||
|
||
ac-charger: power@c { | ||
compatible = "some,ac-charger"; | ||
... | ||
}; | ||
|
||
battery@b { | ||
compatible = "some,battery"; | ||
... | ||
power-supplies = <&usb-charger>, <&ac-charger>; | ||
}; |
17 changes: 17 additions & 0 deletions
17
Documentation/devicetree/bindings/power_supply/tps65090.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
TPS65090 Frontend PMU with Switchmode Charger | ||
|
||
Required Properties: | ||
-compatible: "ti,tps65090-charger" | ||
|
||
Optional Properties: | ||
-ti,enable-low-current-chrg: Enables charging when a low current is detected | ||
while the default logic is to stop charging. | ||
|
||
This node is a subnode of the tps65090 PMIC. | ||
|
||
Example: | ||
|
||
tps65090-charger { | ||
compatible = "ti,tps65090-charger"; | ||
ti,enable-low-current-chrg; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Kernel driver ab8500 | ||
==================== | ||
|
||
Supported chips: | ||
* ST-Ericsson AB8500 | ||
Prefix: 'ab8500' | ||
Addresses scanned: - | ||
Datasheet: http://www.stericsson.com/developers/documentation.jsp | ||
|
||
Authors: | ||
Martin Persson <[email protected]> | ||
Hongbo Zhang <[email protected]> | ||
|
||
Description | ||
----------- | ||
|
||
See also Documentation/hwmon/abx500. This is the ST-Ericsson AB8500 specific | ||
driver. | ||
|
||
Currently only the AB8500 internal sensor and one external sensor for battery | ||
temperature are monitored. Other GPADC channels can also be monitored if needed | ||
in future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Kernel driver abx500 | ||
==================== | ||
|
||
Supported chips: | ||
* ST-Ericsson ABx500 series | ||
Prefix: 'abx500' | ||
Addresses scanned: - | ||
Datasheet: http://www.stericsson.com/developers/documentation.jsp | ||
|
||
Authors: | ||
Martin Persson <[email protected]> | ||
Hongbo Zhang <[email protected]> | ||
|
||
Description | ||
----------- | ||
|
||
Every ST-Ericsson Ux500 SOC consists of both ABx500 and DBx500 physically, | ||
this is kernel hwmon driver for ABx500. | ||
|
||
There are some GPADCs inside ABx500 which are designed for connecting to | ||
thermal sensors, and there is also a thermal sensor inside ABx500 too, which | ||
raises interrupt when critical temperature reached. | ||
|
||
This abx500 is a common layer which can monitor all of the sensors, every | ||
specific abx500 chip has its special configurations in its own file, e.g. some | ||
sensors can be configured invisible if they are not available on that chip, and | ||
the corresponding gpadc_addr should be set to 0, thus this sensor won't be | ||
polled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/* | ||
* Copyright (C) ST-Ericsson 2010 - 2013 | ||
* Author: Martin Persson <[email protected]> | ||
* Hongbo Zhang <[email protected]> | ||
* License Terms: GNU General Public License v2 | ||
* | ||
* When the AB8500 thermal warning temperature is reached (threshold cannot | ||
* be changed by SW), an interrupt is set, and if no further action is taken | ||
* within a certain time frame, pm_power off will be called. | ||
* | ||
* When AB8500 thermal shutdown temperature is reached a hardware shutdown of | ||
* the AB8500 will occur. | ||
*/ | ||
|
||
#include <linux/err.h> | ||
#include <linux/hwmon.h> | ||
#include <linux/hwmon-sysfs.h> | ||
#include <linux/mfd/abx500.h> | ||
#include <linux/mfd/abx500/ab8500-bm.h> | ||
#include <linux/mfd/abx500/ab8500-gpadc.h> | ||
#include <linux/module.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/power/ab8500.h> | ||
#include <linux/slab.h> | ||
#include <linux/sysfs.h> | ||
#include "abx500.h" | ||
|
||
#define DEFAULT_POWER_OFF_DELAY (HZ * 10) | ||
#define THERMAL_VCC 1800 | ||
#define PULL_UP_RESISTOR 47000 | ||
/* Number of monitored sensors should not greater than NUM_SENSORS */ | ||
#define NUM_MONITORED_SENSORS 4 | ||
|
||
struct ab8500_gpadc_cfg { | ||
const struct abx500_res_to_temp *temp_tbl; | ||
int tbl_sz; | ||
int vcc; | ||
int r_up; | ||
}; | ||
|
||
struct ab8500_temp { | ||
struct ab8500_gpadc *gpadc; | ||
struct ab8500_btemp *btemp; | ||
struct delayed_work power_off_work; | ||
struct ab8500_gpadc_cfg cfg; | ||
struct abx500_temp *abx500_data; | ||
}; | ||
|
||
/* | ||
* The hardware connection is like this: | ||
* VCC----[ R_up ]-----[ NTC ]----GND | ||
* where R_up is pull-up resistance, and GPADC measures voltage on NTC. | ||
* and res_to_temp table is strictly sorted by falling resistance values. | ||
*/ | ||
static int ab8500_voltage_to_temp(struct ab8500_gpadc_cfg *cfg, | ||
int v_ntc, int *temp) | ||
{ | ||
int r_ntc, i = 0, tbl_sz = cfg->tbl_sz; | ||
const struct abx500_res_to_temp *tbl = cfg->temp_tbl; | ||
|
||
if (cfg->vcc < 0 || v_ntc >= cfg->vcc) | ||
return -EINVAL; | ||
|
||
r_ntc = v_ntc * cfg->r_up / (cfg->vcc - v_ntc); | ||
if (r_ntc > tbl[0].resist || r_ntc < tbl[tbl_sz - 1].resist) | ||
return -EINVAL; | ||
|
||
while (!(r_ntc <= tbl[i].resist && r_ntc > tbl[i + 1].resist) && | ||
i < tbl_sz - 2) | ||
i++; | ||
|
||
/* return milli-Celsius */ | ||
*temp = tbl[i].temp * 1000 + ((tbl[i + 1].temp - tbl[i].temp) * 1000 * | ||
(r_ntc - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist); | ||
|
||
return 0; | ||
} | ||
|
||
static int ab8500_read_sensor(struct abx500_temp *data, u8 sensor, int *temp) | ||
{ | ||
int voltage, ret; | ||
struct ab8500_temp *ab8500_data = data->plat_data; | ||
|
||
if (sensor == BAT_CTRL) { | ||
*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp); | ||
} else if (sensor == BTEMP_BALL) { | ||
*temp = ab8500_btemp_get_temp(ab8500_data->btemp); | ||
} else { | ||
voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor); | ||
if (voltage < 0) | ||
return voltage; | ||
|
||
ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp); | ||
if (ret < 0) | ||
return ret; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void ab8500_thermal_power_off(struct work_struct *work) | ||
{ | ||
struct ab8500_temp *ab8500_data = container_of(work, | ||
struct ab8500_temp, power_off_work.work); | ||
struct abx500_temp *abx500_data = ab8500_data->abx500_data; | ||
|
||
dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n"); | ||
|
||
pm_power_off(); | ||
} | ||
|
||
static ssize_t ab8500_show_name(struct device *dev, | ||
struct device_attribute *devattr, char *buf) | ||
{ | ||
return sprintf(buf, "ab8500\n"); | ||
} | ||
|
||
static ssize_t ab8500_show_label(struct device *dev, | ||
struct device_attribute *devattr, char *buf) | ||
{ | ||
char *label; | ||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
int index = attr->index; | ||
|
||
switch (index) { | ||
case 1: | ||
label = "ext_adc1"; | ||
break; | ||
case 2: | ||
label = "ext_adc2"; | ||
break; | ||
case 3: | ||
label = "bat_temp"; | ||
break; | ||
case 4: | ||
label = "bat_ctrl"; | ||
break; | ||
default: | ||
return -EINVAL; | ||
} | ||
|
||
return sprintf(buf, "%s\n", label); | ||
} | ||
|
||
static int ab8500_temp_irq_handler(int irq, struct abx500_temp *data) | ||
{ | ||
struct ab8500_temp *ab8500_data = data->plat_data; | ||
|
||
dev_warn(&data->pdev->dev, "Power off in %d s\n", | ||
DEFAULT_POWER_OFF_DELAY / HZ); | ||
|
||
schedule_delayed_work(&ab8500_data->power_off_work, | ||
DEFAULT_POWER_OFF_DELAY); | ||
return 0; | ||
} | ||
|
||
int abx500_hwmon_init(struct abx500_temp *data) | ||
{ | ||
struct ab8500_temp *ab8500_data; | ||
|
||
ab8500_data = devm_kzalloc(&data->pdev->dev, sizeof(*ab8500_data), | ||
GFP_KERNEL); | ||
if (!ab8500_data) | ||
return -ENOMEM; | ||
|
||
ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); | ||
if (IS_ERR(ab8500_data->gpadc)) | ||
return PTR_ERR(ab8500_data->gpadc); | ||
|
||
ab8500_data->btemp = ab8500_btemp_get(); | ||
if (IS_ERR(ab8500_data->btemp)) | ||
return PTR_ERR(ab8500_data->btemp); | ||
|
||
INIT_DELAYED_WORK(&ab8500_data->power_off_work, | ||
ab8500_thermal_power_off); | ||
|
||
ab8500_data->cfg.vcc = THERMAL_VCC; | ||
ab8500_data->cfg.r_up = PULL_UP_RESISTOR; | ||
ab8500_data->cfg.temp_tbl = ab8500_temp_tbl_a_thermistor; | ||
ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size; | ||
|
||
data->plat_data = ab8500_data; | ||
|
||
/* | ||
* ADC_AUX1 and ADC_AUX2, connected to external NTC | ||
* BTEMP_BALL and BAT_CTRL, fixed usage | ||
*/ | ||
data->gpadc_addr[0] = ADC_AUX1; | ||
data->gpadc_addr[1] = ADC_AUX2; | ||
data->gpadc_addr[2] = BTEMP_BALL; | ||
data->gpadc_addr[3] = BAT_CTRL; | ||
data->monitored_sensors = NUM_MONITORED_SENSORS; | ||
|
||
data->ops.read_sensor = ab8500_read_sensor; | ||
data->ops.irq_handler = ab8500_temp_irq_handler; | ||
data->ops.show_name = ab8500_show_name; | ||
data->ops.show_label = ab8500_show_label; | ||
data->ops.is_visible = NULL; | ||
|
||
return 0; | ||
} | ||
EXPORT_SYMBOL(abx500_hwmon_init); | ||
|
||
MODULE_AUTHOR("Hongbo Zhang <[email protected]>"); | ||
MODULE_DESCRIPTION("AB8500 temperature driver"); | ||
MODULE_LICENSE("GPL"); |
Oops, something went wrong.