Skip to content

Commit 151173e

Browse files
committed
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() ...
2 parents 3094566 + 6b17080 commit 151173e

64 files changed

Lines changed: 6393 additions & 1500 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Power Supply Core Support
2+
3+
Optional Properties:
4+
- power-supplies : This property is added to a supply in order to list the
5+
devices which supply it power, referenced by their phandles.
6+
7+
Example:
8+
9+
usb-charger: power@e {
10+
compatible = "some,usb-charger";
11+
...
12+
};
13+
14+
ac-charger: power@c {
15+
compatible = "some,ac-charger";
16+
...
17+
};
18+
19+
battery@b {
20+
compatible = "some,battery";
21+
...
22+
power-supplies = <&usb-charger>, <&ac-charger>;
23+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TPS65090 Frontend PMU with Switchmode Charger
2+
3+
Required Properties:
4+
-compatible: "ti,tps65090-charger"
5+
6+
Optional Properties:
7+
-ti,enable-low-current-chrg: Enables charging when a low current is detected
8+
while the default logic is to stop charging.
9+
10+
This node is a subnode of the tps65090 PMIC.
11+
12+
Example:
13+
14+
tps65090-charger {
15+
compatible = "ti,tps65090-charger";
16+
ti,enable-low-current-chrg;
17+
};

‎Documentation/hwmon/ab8500‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Kernel driver ab8500
2+
====================
3+
4+
Supported chips:
5+
* ST-Ericsson AB8500
6+
Prefix: 'ab8500'
7+
Addresses scanned: -
8+
Datasheet: http://www.stericsson.com/developers/documentation.jsp
9+
10+
Authors:
11+
Martin Persson <martin.persson@stericsson.com>
12+
Hongbo Zhang <hongbo.zhang@linaro.org>
13+
14+
Description
15+
-----------
16+
17+
See also Documentation/hwmon/abx500. This is the ST-Ericsson AB8500 specific
18+
driver.
19+
20+
Currently only the AB8500 internal sensor and one external sensor for battery
21+
temperature are monitored. Other GPADC channels can also be monitored if needed
22+
in future.

‎Documentation/hwmon/abx500‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Kernel driver abx500
2+
====================
3+
4+
Supported chips:
5+
* ST-Ericsson ABx500 series
6+
Prefix: 'abx500'
7+
Addresses scanned: -
8+
Datasheet: http://www.stericsson.com/developers/documentation.jsp
9+
10+
Authors:
11+
Martin Persson <martin.persson@stericsson.com>
12+
Hongbo Zhang <hongbo.zhang@linaro.org>
13+
14+
Description
15+
-----------
16+
17+
Every ST-Ericsson Ux500 SOC consists of both ABx500 and DBx500 physically,
18+
this is kernel hwmon driver for ABx500.
19+
20+
There are some GPADCs inside ABx500 which are designed for connecting to
21+
thermal sensors, and there is also a thermal sensor inside ABx500 too, which
22+
raises interrupt when critical temperature reached.
23+
24+
This abx500 is a common layer which can monitor all of the sensors, every
25+
specific abx500 chip has its special configurations in its own file, e.g. some
26+
sensors can be configured invisible if they are not available on that chip, and
27+
the corresponding gpadc_addr should be set to 0, thus this sensor won't be
28+
polled.

‎arch/arm/mach-vexpress/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ config ARCH_VEXPRESS
1717
select NO_IOPORT
1818
select PLAT_VERSATILE
1919
select PLAT_VERSATILE_CLCD
20+
select POWER_RESET
21+
select POWER_RESET_VEXPRESS
22+
select POWER_SUPPLY
2023
select REGULATOR_FIXED_VOLTAGE if REGULATOR
2124
select VEXPRESS_CONFIG
2225
help

‎arch/arm/mach-vexpress/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
55
-I$(srctree)/arch/arm/plat-versatile/include
66

7-
obj-y := v2m.o reset.o
7+
obj-y := v2m.o
88
obj-$(CONFIG_ARCH_VEXPRESS_CA9X4) += ct-ca9x4.o
99
obj-$(CONFIG_SMP) += platsmp.o
1010
obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o

‎arch/arm/mach-vexpress/v2m.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ static void __init v2m_init(void)
363363
for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
364364
amba_device_register(v2m_amba_devs[i], &iomem_resource);
365365

366-
pm_power_off = vexpress_power_off;
367-
368366
ct_desc->init_tile();
369367
}
370368

@@ -376,7 +374,6 @@ MACHINE_START(VEXPRESS, "ARM-Versatile Express")
376374
.init_irq = v2m_init_irq,
377375
.init_time = v2m_timer_init,
378376
.init_machine = v2m_init,
379-
.restart = vexpress_restart,
380377
MACHINE_END
381378

382379
static struct map_desc v2m_rs1_io_desc __initdata = {
@@ -470,7 +467,6 @@ static void __init v2m_dt_init(void)
470467
{
471468
l2x0_of_init(0x00400000, 0xfe0fffff);
472469
of_platform_populate(NULL, v2m_dt_bus_match, NULL, NULL);
473-
pm_power_off = vexpress_power_off;
474470
}
475471

476472
static const char * const v2m_dt_match[] __initconst = {
@@ -487,5 +483,4 @@ DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
487483
.init_irq = irqchip_init,
488484
.init_time = v2m_dt_timer_init,
489485
.init_machine = v2m_dt_init,
490-
.restart = vexpress_restart,
491486
MACHINE_END

‎drivers/hwmon/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ config HWMON_DEBUG_CHIP
3939

4040
comment "Native drivers"
4141

42+
config SENSORS_AB8500
43+
tristate "AB8500 thermal monitoring"
44+
depends on AB8500_GPADC && AB8500_BM
45+
default n
46+
help
47+
If you say yes here you get support for the thermal sensor part
48+
of the AB8500 chip. The driver includes thermal management for
49+
AB8500 die and two GPADC channels. The GPADC channel are preferably
50+
used to access sensors outside the AB8500 chip.
51+
52+
This driver can also be built as a module. If so, the module
53+
will be called abx500-temp.
54+
4255
config SENSORS_ABITUGURU
4356
tristate "Abit uGuru (rev 1 & 2)"
4457
depends on X86 && DMI

‎drivers/hwmon/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_SENSORS_W83795) += w83795.o
1919
obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
2020
obj-$(CONFIG_SENSORS_W83791D) += w83791d.o
2121

22+
obj-$(CONFIG_SENSORS_AB8500) += abx500.o ab8500.o
2223
obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
2324
obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o
2425
obj-$(CONFIG_SENSORS_AD7314) += ad7314.o

‎drivers/hwmon/ab8500.c‎

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
* Copyright (C) ST-Ericsson 2010 - 2013
3+
* Author: Martin Persson <martin.persson@stericsson.com>
4+
* Hongbo Zhang <hongbo.zhang@linaro.org>
5+
* License Terms: GNU General Public License v2
6+
*
7+
* When the AB8500 thermal warning temperature is reached (threshold cannot
8+
* be changed by SW), an interrupt is set, and if no further action is taken
9+
* within a certain time frame, pm_power off will be called.
10+
*
11+
* When AB8500 thermal shutdown temperature is reached a hardware shutdown of
12+
* the AB8500 will occur.
13+
*/
14+
15+
#include <linux/err.h>
16+
#include <linux/hwmon.h>
17+
#include <linux/hwmon-sysfs.h>
18+
#include <linux/mfd/abx500.h>
19+
#include <linux/mfd/abx500/ab8500-bm.h>
20+
#include <linux/mfd/abx500/ab8500-gpadc.h>
21+
#include <linux/module.h>
22+
#include <linux/platform_device.h>
23+
#include <linux/power/ab8500.h>
24+
#include <linux/slab.h>
25+
#include <linux/sysfs.h>
26+
#include "abx500.h"
27+
28+
#define DEFAULT_POWER_OFF_DELAY (HZ * 10)
29+
#define THERMAL_VCC 1800
30+
#define PULL_UP_RESISTOR 47000
31+
/* Number of monitored sensors should not greater than NUM_SENSORS */
32+
#define NUM_MONITORED_SENSORS 4
33+
34+
struct ab8500_gpadc_cfg {
35+
const struct abx500_res_to_temp *temp_tbl;
36+
int tbl_sz;
37+
int vcc;
38+
int r_up;
39+
};
40+
41+
struct ab8500_temp {
42+
struct ab8500_gpadc *gpadc;
43+
struct ab8500_btemp *btemp;
44+
struct delayed_work power_off_work;
45+
struct ab8500_gpadc_cfg cfg;
46+
struct abx500_temp *abx500_data;
47+
};
48+
49+
/*
50+
* The hardware connection is like this:
51+
* VCC----[ R_up ]-----[ NTC ]----GND
52+
* where R_up is pull-up resistance, and GPADC measures voltage on NTC.
53+
* and res_to_temp table is strictly sorted by falling resistance values.
54+
*/
55+
static int ab8500_voltage_to_temp(struct ab8500_gpadc_cfg *cfg,
56+
int v_ntc, int *temp)
57+
{
58+
int r_ntc, i = 0, tbl_sz = cfg->tbl_sz;
59+
const struct abx500_res_to_temp *tbl = cfg->temp_tbl;
60+
61+
if (cfg->vcc < 0 || v_ntc >= cfg->vcc)
62+
return -EINVAL;
63+
64+
r_ntc = v_ntc * cfg->r_up / (cfg->vcc - v_ntc);
65+
if (r_ntc > tbl[0].resist || r_ntc < tbl[tbl_sz - 1].resist)
66+
return -EINVAL;
67+
68+
while (!(r_ntc <= tbl[i].resist && r_ntc > tbl[i + 1].resist) &&
69+
i < tbl_sz - 2)
70+
i++;
71+
72+
/* return milli-Celsius */
73+
*temp = tbl[i].temp * 1000 + ((tbl[i + 1].temp - tbl[i].temp) * 1000 *
74+
(r_ntc - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist);
75+
76+
return 0;
77+
}
78+
79+
static int ab8500_read_sensor(struct abx500_temp *data, u8 sensor, int *temp)
80+
{
81+
int voltage, ret;
82+
struct ab8500_temp *ab8500_data = data->plat_data;
83+
84+
if (sensor == BAT_CTRL) {
85+
*temp = ab8500_btemp_get_batctrl_temp(ab8500_data->btemp);
86+
} else if (sensor == BTEMP_BALL) {
87+
*temp = ab8500_btemp_get_temp(ab8500_data->btemp);
88+
} else {
89+
voltage = ab8500_gpadc_convert(ab8500_data->gpadc, sensor);
90+
if (voltage < 0)
91+
return voltage;
92+
93+
ret = ab8500_voltage_to_temp(&ab8500_data->cfg, voltage, temp);
94+
if (ret < 0)
95+
return ret;
96+
}
97+
98+
return 0;
99+
}
100+
101+
static void ab8500_thermal_power_off(struct work_struct *work)
102+
{
103+
struct ab8500_temp *ab8500_data = container_of(work,
104+
struct ab8500_temp, power_off_work.work);
105+
struct abx500_temp *abx500_data = ab8500_data->abx500_data;
106+
107+
dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n");
108+
109+
pm_power_off();
110+
}
111+
112+
static ssize_t ab8500_show_name(struct device *dev,
113+
struct device_attribute *devattr, char *buf)
114+
{
115+
return sprintf(buf, "ab8500\n");
116+
}
117+
118+
static ssize_t ab8500_show_label(struct device *dev,
119+
struct device_attribute *devattr, char *buf)
120+
{
121+
char *label;
122+
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
123+
int index = attr->index;
124+
125+
switch (index) {
126+
case 1:
127+
label = "ext_adc1";
128+
break;
129+
case 2:
130+
label = "ext_adc2";
131+
break;
132+
case 3:
133+
label = "bat_temp";
134+
break;
135+
case 4:
136+
label = "bat_ctrl";
137+
break;
138+
default:
139+
return -EINVAL;
140+
}
141+
142+
return sprintf(buf, "%s\n", label);
143+
}
144+
145+
static int ab8500_temp_irq_handler(int irq, struct abx500_temp *data)
146+
{
147+
struct ab8500_temp *ab8500_data = data->plat_data;
148+
149+
dev_warn(&data->pdev->dev, "Power off in %d s\n",
150+
DEFAULT_POWER_OFF_DELAY / HZ);
151+
152+
schedule_delayed_work(&ab8500_data->power_off_work,
153+
DEFAULT_POWER_OFF_DELAY);
154+
return 0;
155+
}
156+
157+
int abx500_hwmon_init(struct abx500_temp *data)
158+
{
159+
struct ab8500_temp *ab8500_data;
160+
161+
ab8500_data = devm_kzalloc(&data->pdev->dev, sizeof(*ab8500_data),
162+
GFP_KERNEL);
163+
if (!ab8500_data)
164+
return -ENOMEM;
165+
166+
ab8500_data->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
167+
if (IS_ERR(ab8500_data->gpadc))
168+
return PTR_ERR(ab8500_data->gpadc);
169+
170+
ab8500_data->btemp = ab8500_btemp_get();
171+
if (IS_ERR(ab8500_data->btemp))
172+
return PTR_ERR(ab8500_data->btemp);
173+
174+
INIT_DELAYED_WORK(&ab8500_data->power_off_work,
175+
ab8500_thermal_power_off);
176+
177+
ab8500_data->cfg.vcc = THERMAL_VCC;
178+
ab8500_data->cfg.r_up = PULL_UP_RESISTOR;
179+
ab8500_data->cfg.temp_tbl = ab8500_temp_tbl_a_thermistor;
180+
ab8500_data->cfg.tbl_sz = ab8500_temp_tbl_a_size;
181+
182+
data->plat_data = ab8500_data;
183+
184+
/*
185+
* ADC_AUX1 and ADC_AUX2, connected to external NTC
186+
* BTEMP_BALL and BAT_CTRL, fixed usage
187+
*/
188+
data->gpadc_addr[0] = ADC_AUX1;
189+
data->gpadc_addr[1] = ADC_AUX2;
190+
data->gpadc_addr[2] = BTEMP_BALL;
191+
data->gpadc_addr[3] = BAT_CTRL;
192+
data->monitored_sensors = NUM_MONITORED_SENSORS;
193+
194+
data->ops.read_sensor = ab8500_read_sensor;
195+
data->ops.irq_handler = ab8500_temp_irq_handler;
196+
data->ops.show_name = ab8500_show_name;
197+
data->ops.show_label = ab8500_show_label;
198+
data->ops.is_visible = NULL;
199+
200+
return 0;
201+
}
202+
EXPORT_SYMBOL(abx500_hwmon_init);
203+
204+
MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@linaro.org>");
205+
MODULE_DESCRIPTION("AB8500 temperature driver");
206+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)