aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 18:15:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 18:15:24 -0400
commit151173e8ce9b95bbbbd7eedb9035cfaffbdb7cb2 (patch)
treebca02f40bdd054fa2e30f4923e1513d40873c4d9
parent30945669593df14692e933c557d00c4bb2727857 (diff)
parent6b170807cd5cac8dc6353f47a88ccb14bbf76c4f (diff)
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() ...
-rw-r--r--Documentation/devicetree/bindings/power_supply/power_supply.txt23
-rw-r--r--Documentation/devicetree/bindings/power_supply/tps65090.txt17
-rw-r--r--Documentation/hwmon/ab850022
-rw-r--r--Documentation/hwmon/abx50028
-rw-r--r--arch/arm/mach-vexpress/Kconfig3
-rw-r--r--arch/arm/mach-vexpress/Makefile2
-rw-r--r--arch/arm/mach-vexpress/v2m.c5
-rw-r--r--drivers/hwmon/Kconfig13
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/ab8500.c206
-rw-r--r--drivers/hwmon/abx500.c491
-rw-r--r--drivers/hwmon/abx500.h69
-rw-r--r--drivers/mfd/ab8500-core.c544
-rw-r--r--drivers/mfd/ab8500-debugfs.c1741
-rw-r--r--drivers/mfd/ab8500-gpadc.c559
-rw-r--r--drivers/mfd/ab8500-sysctrl.c98
-rw-r--r--drivers/power/88pm860x_charger.c2
-rw-r--r--drivers/power/Kconfig14
-rw-r--r--drivers/power/Makefile4
-rw-r--r--drivers/power/ab8500_bmdata.c140
-rw-r--r--drivers/power/ab8500_btemp.c80
-rw-r--r--drivers/power/ab8500_charger.c699
-rw-r--r--drivers/power/ab8500_fg.c501
-rw-r--r--drivers/power/abx500_chargalg.c455
-rw-r--r--drivers/power/charger-manager.c3
-rw-r--r--drivers/power/da9030_battery.c6
-rw-r--r--drivers/power/da9052-battery.c5
-rw-r--r--drivers/power/ds2760_battery.c4
-rw-r--r--drivers/power/ds2780_battery.c7
-rw-r--r--drivers/power/ds2782_battery.c23
-rw-r--r--drivers/power/goldfish_battery.c2
-rw-r--r--drivers/power/gpio-charger.c5
-rw-r--r--drivers/power/isp1704_charger.c5
-rw-r--r--drivers/power/lp8788-charger.c8
-rw-r--r--drivers/power/max17040_battery.c20
-rw-r--r--drivers/power/max8903_charger.c4
-rw-r--r--drivers/power/max8925_power.c5
-rw-r--r--drivers/power/max8997_charger.c9
-rw-r--r--drivers/power/max8998_charger.c5
-rw-r--r--drivers/power/pcf50633-charger.c7
-rw-r--r--drivers/power/pm2301_charger.c391
-rw-r--r--drivers/power/pm2301_charger.h23
-rw-r--r--drivers/power/power_supply_core.c187
-rw-r--r--drivers/power/reset/Kconfig7
-rw-r--r--drivers/power/reset/Makefile3
-rw-r--r--drivers/power/reset/vexpress-poweroff.c (renamed from arch/arm/mach-vexpress/reset.c)9
-rw-r--r--drivers/power/rx51_battery.c8
-rw-r--r--drivers/power/s3c_adc_battery.c7
-rw-r--r--drivers/power/sbs-battery.c22
-rw-r--r--drivers/power/test_power.c31
-rw-r--r--drivers/power/tps65090-charger.c320
-rw-r--r--drivers/power/twl4030_charger.c12
-rw-r--r--drivers/power/wm831x_backup.c10
-rw-r--r--include/linux/mfd/abx500.h27
-rw-r--r--include/linux/mfd/abx500/ab8500-bm.h61
-rw-r--r--include/linux/mfd/abx500/ab8500-gpadc.h74
-rw-r--r--include/linux/mfd/abx500/ab8500-sysctrl.h6
-rw-r--r--include/linux/mfd/abx500/ab8500.h3
-rw-r--r--include/linux/mfd/abx500/ux500_chargalg.h7
-rw-r--r--include/linux/mfd/tps65090.h5
-rw-r--r--include/linux/pm2301_charger.h2
-rw-r--r--include/linux/power/ab8500.h16
-rw-r--r--include/linux/power_supply.h6
-rw-r--r--include/linux/vexpress.h3
64 files changed, 5984 insertions, 1091 deletions
diff --git a/Documentation/devicetree/bindings/power_supply/power_supply.txt b/Documentation/devicetree/bindings/power_supply/power_supply.txt
new file mode 100644
index 000000000000..8391bfa0edac
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/power_supply.txt
@@ -0,0 +1,23 @@
1Power Supply Core Support
2
3Optional 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
7Example:
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 };
diff --git a/Documentation/devicetree/bindings/power_supply/tps65090.txt b/Documentation/devicetree/bindings/power_supply/tps65090.txt
new file mode 100644
index 000000000000..8e5e0d3910df
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/tps65090.txt
@@ -0,0 +1,17 @@
1TPS65090 Frontend PMU with Switchmode Charger
2
3Required Properties:
4-compatible: "ti,tps65090-charger"
5
6Optional 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
10This node is a subnode of the tps65090 PMIC.
11
12Example:
13
14 tps65090-charger {
15 compatible = "ti,tps65090-charger";
16 ti,enable-low-current-chrg;
17 };
diff --git a/Documentation/hwmon/ab8500 b/Documentation/hwmon/ab8500
new file mode 100644
index 000000000000..cf169c8ef4e3
--- /dev/null
+++ b/Documentation/hwmon/ab8500
@@ -0,0 +1,22 @@
1Kernel driver ab8500
2====================
3
4Supported chips:
5 * ST-Ericsson AB8500
6 Prefix: 'ab8500'
7 Addresses scanned: -
8 Datasheet: http://www.stericsson.com/developers/documentation.jsp
9
10Authors:
11 Martin Persson <martin.persson@stericsson.com>
12 Hongbo Zhang <hongbo.zhang@linaro.org>
13
14Description
15-----------
16
17See also Documentation/hwmon/abx500. This is the ST-Ericsson AB8500 specific
18driver.
19
20Currently only the AB8500 internal sensor and one external sensor for battery
21temperature are monitored. Other GPADC channels can also be monitored if needed
22in future.
diff --git a/Documentation/hwmon/abx500 b/Documentation/hwmon/abx500
new file mode 100644
index 000000000000..319a058cec7c
--- /dev/null
+++ b/Documentation/hwmon/abx500
@@ -0,0 +1,28 @@
1Kernel driver abx500
2====================
3
4Supported chips:
5 * ST-Ericsson ABx500 series
6 Prefix: 'abx500'
7 Addresses scanned: -
8 Datasheet: http://www.stericsson.com/developers/documentation.jsp
9
10Authors:
11 Martin Persson <martin.persson@stericsson.com>
12 Hongbo Zhang <hongbo.zhang@linaro.org>
13
14Description
15-----------
16
17Every ST-Ericsson Ux500 SOC consists of both ABx500 and DBx500 physically,
18this is kernel hwmon driver for ABx500.
19
20There are some GPADCs inside ABx500 which are designed for connecting to
21thermal sensors, and there is also a thermal sensor inside ABx500 too, which
22raises interrupt when critical temperature reached.
23
24This abx500 is a common layer which can monitor all of the sensors, every
25specific abx500 chip has its special configurations in its own file, e.g. some
26sensors can be configured invisible if they are not available on that chip, and
27the corresponding gpadc_addr should be set to 0, thus this sensor won't be
28polled.
diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
index 52d315b792c8..0f1c5e53fb27 100644
--- a/arch/arm/mach-vexpress/Kconfig
+++ b/arch/arm/mach-vexpress/Kconfig
@@ -17,6 +17,9 @@ config ARCH_VEXPRESS
17 select NO_IOPORT 17 select NO_IOPORT
18 select PLAT_VERSATILE 18 select PLAT_VERSATILE
19 select PLAT_VERSATILE_CLCD 19 select PLAT_VERSATILE_CLCD
20 select POWER_RESET
21 select POWER_RESET_VEXPRESS
22 select POWER_SUPPLY
20 select REGULATOR_FIXED_VOLTAGE if REGULATOR 23 select REGULATOR_FIXED_VOLTAGE if REGULATOR
21 select VEXPRESS_CONFIG 24 select VEXPRESS_CONFIG
22 help 25 help
diff --git a/arch/arm/mach-vexpress/Makefile b/arch/arm/mach-vexpress/Makefile
index 80b64971fbdd..42703e8b4d3b 100644
--- a/arch/arm/mach-vexpress/Makefile
+++ b/arch/arm/mach-vexpress/Makefile
@@ -4,7 +4,7 @@
4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \
5 -I$(srctree)/arch/arm/plat-versatile/include 5 -I$(srctree)/arch/arm/plat-versatile/include
6 6
7obj-y := v2m.o reset.o 7obj-y := v2m.o
8obj-$(CONFIG_ARCH_VEXPRESS_CA9X4) += ct-ca9x4.o 8obj-$(CONFIG_ARCH_VEXPRESS_CA9X4) += ct-ca9x4.o
9obj-$(CONFIG_SMP) += platsmp.o 9obj-$(CONFIG_SMP) += platsmp.o
10obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o 10obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
diff --git a/arch/arm/mach-vexpress/v2m.c b/arch/arm/mach-vexpress/v2m.c
index c5e20b52e3b7..eb2b3a627f03 100644
--- a/arch/arm/mach-vexpress/v2m.c
+++ b/arch/arm/mach-vexpress/v2m.c
@@ -363,8 +363,6 @@ static void __init v2m_init(void)
363 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++) 363 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
364 amba_device_register(v2m_amba_devs[i], &iomem_resource); 364 amba_device_register(v2m_amba_devs[i], &iomem_resource);
365 365
366 pm_power_off = vexpress_power_off;
367
368 ct_desc->init_tile(); 366 ct_desc->init_tile();
369} 367}
370 368
@@ -376,7 +374,6 @@ MACHINE_START(VEXPRESS, "ARM-Versatile Express")
376 .init_irq = v2m_init_irq, 374 .init_irq = v2m_init_irq,
377 .init_time = v2m_timer_init, 375 .init_time = v2m_timer_init,
378 .init_machine = v2m_init, 376 .init_machine = v2m_init,
379 .restart = vexpress_restart,
380MACHINE_END 377MACHINE_END
381 378
382static struct map_desc v2m_rs1_io_desc __initdata = { 379static struct map_desc v2m_rs1_io_desc __initdata = {
@@ -470,7 +467,6 @@ static void __init v2m_dt_init(void)
470{ 467{
471 l2x0_of_init(0x00400000, 0xfe0fffff); 468 l2x0_of_init(0x00400000, 0xfe0fffff);
472 of_platform_populate(NULL, v2m_dt_bus_match, NULL, NULL); 469 of_platform_populate(NULL, v2m_dt_bus_match, NULL, NULL);
473 pm_power_off = vexpress_power_off;
474} 470}
475 471
476static const char * const v2m_dt_match[] __initconst = { 472static const char * const v2m_dt_match[] __initconst = {
@@ -487,5 +483,4 @@ DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
487 .init_irq = irqchip_init, 483 .init_irq = irqchip_init,
488 .init_time = v2m_dt_timer_init, 484 .init_time = v2m_dt_timer_init,
489 .init_machine = v2m_dt_init, 485 .init_machine = v2m_dt_init,
490 .restart = vexpress_restart,
491MACHINE_END 486MACHINE_END
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index f61d98a62967..9c333d471433 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -39,6 +39,19 @@ config HWMON_DEBUG_CHIP
39 39
40comment "Native drivers" 40comment "Native drivers"
41 41
42config 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
42config SENSORS_ABITUGURU 55config SENSORS_ABITUGURU
43 tristate "Abit uGuru (rev 1 & 2)" 56 tristate "Abit uGuru (rev 1 & 2)"
44 depends on X86 && DMI 57 depends on X86 && DMI
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c51b0dc35dc8..d17d3e64f9f4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SENSORS_W83795) += w83795.o
19obj-$(CONFIG_SENSORS_W83781D) += w83781d.o 19obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
20obj-$(CONFIG_SENSORS_W83791D) += w83791d.o 20obj-$(CONFIG_SENSORS_W83791D) += w83791d.o
21 21
22obj-$(CONFIG_SENSORS_AB8500) += abx500.o ab8500.o
22obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o 23obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
23obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o 24obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o
24obj-$(CONFIG_SENSORS_AD7314) += ad7314.o 25obj-$(CONFIG_SENSORS_AD7314) += ad7314.o
diff --git a/drivers/hwmon/ab8500.c b/drivers/hwmon/ab8500.c
new file mode 100644
index 000000000000..d844dc806853
--- /dev/null
+++ b/drivers/hwmon/ab8500.c
@@ -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
34struct 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
41struct 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 */
55static 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
79static 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
101static 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
112static ssize_t ab8500_show_name(struct device *dev,
113 struct device_attribute *devattr, char *buf)
114{
115 return sprintf(buf, "ab8500\n");
116}
117
118static 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
145static 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
157int 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}
202EXPORT_SYMBOL(abx500_hwmon_init);
203
204MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@linaro.org>");
205MODULE_DESCRIPTION("AB8500 temperature driver");
206MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/abx500.c b/drivers/hwmon/abx500.c
new file mode 100644
index 000000000000..b4ad87b31a37
--- /dev/null
+++ b/drivers/hwmon/abx500.c
@@ -0,0 +1,491 @@
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 * ABX500 does not provide auto ADC, so to monitor the required temperatures,
8 * a periodic work is used. It is more important to not wake up the CPU than
9 * to perform this job, hence the use of a deferred delay.
10 *
11 * A deferred delay for thermal monitor is considered safe because:
12 * If the chip gets too hot during a sleep state it's most likely due to
13 * external factors, such as the surrounding temperature. I.e. no SW decisions
14 * will make any difference.
15 */
16
17#include <linux/err.h>
18#include <linux/hwmon.h>
19#include <linux/hwmon-sysfs.h>
20#include <linux/interrupt.h>
21#include <linux/jiffies.h>
22#include <linux/module.h>
23#include <linux/mutex.h>
24#include <linux/of.h>
25#include <linux/platform_device.h>
26#include <linux/pm.h>
27#include <linux/slab.h>
28#include <linux/sysfs.h>
29#include <linux/workqueue.h>
30#include "abx500.h"
31
32#define DEFAULT_MONITOR_DELAY HZ
33#define DEFAULT_MAX_TEMP 130
34
35static inline void schedule_monitor(struct abx500_temp *data)
36{
37 data->work_active = true;
38 schedule_delayed_work(&data->work, DEFAULT_MONITOR_DELAY);
39}
40
41static void threshold_updated(struct abx500_temp *data)
42{
43 int i;
44 for (i = 0; i < data->monitored_sensors; i++)
45 if (data->max[i] != 0 || data->min[i] != 0) {
46 schedule_monitor(data);
47 return;
48 }
49
50 dev_dbg(&data->pdev->dev, "No active thresholds.\n");
51 cancel_delayed_work_sync(&data->work);
52 data->work_active = false;
53}
54
55static void gpadc_monitor(struct work_struct *work)
56{
57 int temp, i, ret;
58 char alarm_node[30];
59 bool updated_min_alarm, updated_max_alarm;
60 struct abx500_temp *data;
61
62 data = container_of(work, struct abx500_temp, work.work);
63 mutex_lock(&data->lock);
64
65 for (i = 0; i < data->monitored_sensors; i++) {
66 /* Thresholds are considered inactive if set to 0 */
67 if (data->max[i] == 0 && data->min[i] == 0)
68 continue;
69
70 if (data->max[i] < data->min[i])
71 continue;
72
73 ret = data->ops.read_sensor(data, data->gpadc_addr[i], &temp);
74 if (ret < 0) {
75 dev_err(&data->pdev->dev, "GPADC read failed\n");
76 continue;
77 }
78
79 updated_min_alarm = false;
80 updated_max_alarm = false;
81
82 if (data->min[i] != 0) {
83 if (temp < data->min[i]) {
84 if (data->min_alarm[i] == false) {
85 data->min_alarm[i] = true;
86 updated_min_alarm = true;
87 }
88 } else {
89 if (data->min_alarm[i] == true) {
90 data->min_alarm[i] = false;
91 updated_min_alarm = true;
92 }
93 }
94 }
95 if (data->max[i] != 0) {
96 if (temp > data->max[i]) {
97 if (data->max_alarm[i] == false) {
98 data->max_alarm[i] = true;
99 updated_max_alarm = true;
100 }
101 } else if (temp < data->max[i] - data->max_hyst[i]) {
102 if (data->max_alarm[i] == true) {
103 data->max_alarm[i] = false;
104 updated_max_alarm = true;
105 }
106 }
107 }
108
109 if (updated_min_alarm) {
110 ret = sprintf(alarm_node, "temp%d_min_alarm", i + 1);
111 sysfs_notify(&data->pdev->dev.kobj, NULL, alarm_node);
112 }
113 if (updated_max_alarm) {
114 ret = sprintf(alarm_node, "temp%d_max_alarm", i + 1);
115 sysfs_notify(&data->pdev->dev.kobj, NULL, alarm_node);
116 }
117 }
118
119 schedule_monitor(data);
120 mutex_unlock(&data->lock);
121}
122
123/* HWMON sysfs interfaces */
124static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
125 char *buf)
126{
127 struct abx500_temp *data = dev_get_drvdata(dev);
128 /* Show chip name */
129 return data->ops.show_name(dev, devattr, buf);
130}
131
132static ssize_t show_label(struct device *dev,
133 struct device_attribute *devattr, char *buf)
134{
135 struct abx500_temp *data = dev_get_drvdata(dev);
136 /* Show each sensor label */
137 return data->ops.show_label(dev, devattr, buf);
138}
139
140static ssize_t show_input(struct device *dev,
141 struct device_attribute *devattr, char *buf)
142{
143 int ret, temp;
144 struct abx500_temp *data = dev_get_drvdata(dev);
145 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
146 u8 gpadc_addr = data->gpadc_addr[attr->index];
147
148 ret = data->ops.read_sensor(data, gpadc_addr, &temp);
149 if (ret < 0)
150 return ret;
151
152 return sprintf(buf, "%d\n", temp);
153}
154
155/* Set functions (RW nodes) */
156static ssize_t set_min(struct device *dev, struct device_attribute *devattr,
157 const char *buf, size_t count)
158{
159 unsigned long val;
160 struct abx500_temp *data = dev_get_drvdata(dev);
161 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
162 int res = kstrtol(buf, 10, &val);
163 if (res < 0)
164 return res;
165
166 val = clamp_val(val, 0, DEFAULT_MAX_TEMP);
167
168 mutex_lock(&data->lock);
169 data->min[attr->index] = val;
170 threshold_updated(data);
171 mutex_unlock(&data->lock);
172
173 return count;
174}
175
176static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
177 const char *buf, size_t count)
178{
179 unsigned long val;
180 struct abx500_temp *data = dev_get_drvdata(dev);
181 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
182 int res = kstrtol(buf, 10, &val);
183 if (res < 0)
184 return res;
185
186 val = clamp_val(val, 0, DEFAULT_MAX_TEMP);
187
188 mutex_lock(&data->lock);
189 data->max[attr->index] = val;
190 threshold_updated(data);
191 mutex_unlock(&data->lock);
192
193 return count;
194}
195
196static ssize_t set_max_hyst(struct device *dev,
197 struct device_attribute *devattr,
198 const char *buf, size_t count)
199{
200 unsigned long val;
201 struct abx500_temp *data = dev_get_drvdata(dev);
202 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
203 int res = kstrtoul(buf, 10, &val);
204 if (res < 0)
205 return res;
206
207 val = clamp_val(val, 0, DEFAULT_MAX_TEMP);
208
209 mutex_lock(&data->lock);
210 data->max_hyst[attr->index] = val;
211 threshold_updated(data);
212 mutex_unlock(&data->lock);
213
214 return count;
215}
216
217/* Show functions (RO nodes) */
218static ssize_t show_min(struct device *dev,
219 struct device_attribute *devattr, char *buf)
220{
221 struct abx500_temp *data = dev_get_drvdata(dev);
222 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
223
224 return sprintf(buf, "%ld\n", data->min[attr->index]);
225}
226
227static ssize_t show_max(struct device *dev,
228 struct device_attribute *devattr, char *buf)
229{
230 struct abx500_temp *data = dev_get_drvdata(dev);
231 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
232
233 return sprintf(buf, "%ld\n", data->max[attr->index]);
234}
235
236static ssize_t show_max_hyst(struct device *dev,
237 struct device_attribute *devattr, char *buf)
238{
239 struct abx500_temp *data = dev_get_drvdata(dev);
240 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
241
242 return sprintf(buf, "%ld\n", data->max_hyst[attr->index]);
243}
244
245static ssize_t show_min_alarm(struct device *dev,
246 struct device_attribute *devattr, char *buf)
247{
248 struct abx500_temp *data = dev_get_drvdata(dev);
249 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
250
251 return sprintf(buf, "%d\n", data->min_alarm[attr->index]);
252}
253
254static ssize_t show_max_alarm(struct device *dev,
255 struct device_attribute *devattr, char *buf)
256{
257 struct abx500_temp *data = dev_get_drvdata(dev);
258 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
259
260 return sprintf(buf, "%d\n", data->max_alarm[attr->index]);
261}
262
263static mode_t abx500_attrs_visible(struct kobject *kobj,
264 struct attribute *attr, int n)
265{
266 struct device *dev = container_of(kobj, struct device, kobj);
267 struct abx500_temp *data = dev_get_drvdata(dev);
268
269 if (data->ops.is_visible)
270 return data->ops.is_visible(attr, n);
271
272 return attr->mode;
273}
274
275/* Chip name, required by hwmon */
276static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
277
278/* GPADC - SENSOR1 */
279static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL, 0);
280static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0);
281static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_min, set_min, 0);
282static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_max, set_max, 0);
283static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
284 show_max_hyst, set_max_hyst, 0);
285static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_min_alarm, NULL, 0);
286static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_max_alarm, NULL, 0);
287
288/* GPADC - SENSOR2 */
289static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, 1);
290static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 1);
291static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min, set_min, 1);
292static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max, set_max, 1);
293static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IWUSR | S_IRUGO,
294 show_max_hyst, set_max_hyst, 1);
295static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_min_alarm, NULL, 1);
296static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_max_alarm, NULL, 1);
297
298/* GPADC - SENSOR3 */
299static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_label, NULL, 2);
300static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 2);
301static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min, set_min, 2);
302static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max, 2);
303static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IWUSR | S_IRUGO,
304 show_max_hyst, set_max_hyst, 2);
305static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_min_alarm, NULL, 2);
306static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_max_alarm, NULL, 2);
307
308/* GPADC - SENSOR4 */
309static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_label, NULL, 3);
310static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_input, NULL, 3);
311static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_min, set_min, 3);
312static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_max, set_max, 3);
313static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IWUSR | S_IRUGO,
314 show_max_hyst, set_max_hyst, 3);
315static SENSOR_DEVICE_ATTR(temp4_min_alarm, S_IRUGO, show_min_alarm, NULL, 3);
316static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_max_alarm, NULL, 3);
317
318struct attribute *abx500_temp_attributes[] = {
319 &sensor_dev_attr_name.dev_attr.attr,
320
321 &sensor_dev_attr_temp1_label.dev_attr.attr,
322 &sensor_dev_attr_temp1_input.dev_attr.attr,
323 &sensor_dev_attr_temp1_min.dev_attr.attr,
324 &sensor_dev_attr_temp1_max.dev_attr.attr,
325 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
326 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
327 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
328
329 &sensor_dev_attr_temp2_label.dev_attr.attr,
330 &sensor_dev_attr_temp2_input.dev_attr.attr,
331 &sensor_dev_attr_temp2_min.dev_attr.attr,
332 &sensor_dev_attr_temp2_max.dev_attr.attr,
333 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
334 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
335 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
336
337 &sensor_dev_attr_temp3_label.dev_attr.attr,
338 &sensor_dev_attr_temp3_input.dev_attr.attr,
339 &sensor_dev_attr_temp3_min.dev_attr.attr,
340 &sensor_dev_attr_temp3_max.dev_attr.attr,
341 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
342 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
343 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
344
345 &sensor_dev_attr_temp4_label.dev_attr.attr,
346 &sensor_dev_attr_temp4_input.dev_attr.attr,
347 &sensor_dev_attr_temp4_min.dev_attr.attr,
348 &sensor_dev_attr_temp4_max.dev_attr.attr,
349 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
350 &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
351 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
352 NULL
353};
354
355static const struct attribute_group abx500_temp_group = {
356 .attrs = abx500_temp_attributes,
357 .is_visible = abx500_attrs_visible,
358};
359
360static irqreturn_t abx500_temp_irq_handler(int irq, void *irq_data)
361{
362 struct platform_device *pdev = irq_data;
363 struct abx500_temp *data = platform_get_drvdata(pdev);
364
365 data->ops.irq_handler(irq, data);
366 return IRQ_HANDLED;
367}
368
369static int setup_irqs(struct platform_device *pdev)
370{
371 int ret;
372 int irq = platform_get_irq_byname(pdev, "ABX500_TEMP_WARM");
373
374 if (irq < 0) {
375 dev_err(&pdev->dev, "Get irq by name failed\n");
376 return irq;
377 }
378
379 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
380 abx500_temp_irq_handler, IRQF_NO_SUSPEND, "abx500-temp", pdev);
381 if (ret < 0)
382 dev_err(&pdev->dev, "Request threaded irq failed (%d)\n", ret);
383
384 return ret;
385}
386
387static int abx500_temp_probe(struct platform_device *pdev)
388{
389 struct abx500_temp *data;
390 int err;
391
392 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
393 if (!data)
394 return -ENOMEM;
395
396 data->pdev = pdev;
397 mutex_init(&data->lock);
398
399 /* Chip specific initialization */
400 err = abx500_hwmon_init(data);
401 if (err < 0 || !data->ops.read_sensor || !data->ops.show_name ||
402 !data->ops.show_label)
403 return err;
404
405 INIT_DEFERRABLE_WORK(&data->work, gpadc_monitor);
406
407 platform_set_drvdata(pdev, data);
408
409 err = sysfs_create_group(&pdev->dev.kobj, &abx500_temp_group);
410 if (err < 0) {
411 dev_err(&pdev->dev, "Create sysfs group failed (%d)\n", err);
412 return err;
413 }
414
415 data->hwmon_dev = hwmon_device_register(&pdev->dev);
416 if (IS_ERR(data->hwmon_dev)) {
417 err = PTR_ERR(data->hwmon_dev);
418 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
419 goto exit_sysfs_group;
420 }
421
422 if (data->ops.irq_handler) {
423 err = setup_irqs(pdev);
424 if (err < 0)
425 goto exit_hwmon_reg;
426 }
427 return 0;
428
429exit_hwmon_reg:
430 hwmon_device_unregister(data->hwmon_dev);
431exit_sysfs_group:
432 sysfs_remove_group(&pdev->dev.kobj, &abx500_temp_group);
433 return err;
434}
435
436static int abx500_temp_remove(struct platform_device *pdev)
437{
438 struct abx500_temp *data = platform_get_drvdata(pdev);
439
440 cancel_delayed_work_sync(&data->work);
441 hwmon_device_unregister(data->hwmon_dev);
442 sysfs_remove_group(&pdev->dev.kobj, &abx500_temp_group);
443
444 return 0;
445}
446
447static int abx500_temp_suspend(struct platform_device *pdev,
448 pm_message_t state)
449{
450 struct abx500_temp *data = platform_get_drvdata(pdev);
451
452 if (data->work_active)
453 cancel_delayed_work_sync(&data->work);
454
455 return 0;
456}
457
458static int abx500_temp_resume(struct platform_device *pdev)
459{
460 struct abx500_temp *data = platform_get_drvdata(pdev);
461
462 if (data->work_active)
463 schedule_monitor(data);
464
465 return 0;
466}
467
468#ifdef CONFIG_OF
469static const struct of_device_id abx500_temp_match[] = {
470 { .compatible = "stericsson,abx500-temp" },
471 {},
472};
473#endif
474
475static struct platform_driver abx500_temp_driver = {
476 .driver = {
477 .owner = THIS_MODULE,
478 .name = "abx500-temp",
479 .of_match_table = of_match_ptr(abx500_temp_match),
480 },
481 .suspend = abx500_temp_suspend,
482 .resume = abx500_temp_resume,
483 .probe = abx500_temp_probe,
484 .remove = abx500_temp_remove,
485};
486
487module_platform_driver(abx500_temp_driver);
488
489MODULE_AUTHOR("Martin Persson <martin.persson@stericsson.com>");
490MODULE_DESCRIPTION("ABX500 temperature driver");
491MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/abx500.h b/drivers/hwmon/abx500.h
new file mode 100644
index 000000000000..9b295e684d0e
--- /dev/null
+++ b/drivers/hwmon/abx500.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright (C) ST-Ericsson 2010 - 2013
3 * License terms: GNU General Public License v2
4 * Author: Martin Persson <martin.persson@stericsson.com>
5 * Hongbo Zhang <hongbo.zhang@linaro.com>
6 */
7
8#ifndef _ABX500_H
9#define _ABX500_H
10
11#define NUM_SENSORS 5
12
13struct abx500_temp;
14
15/*
16 * struct abx500_temp_ops - abx500 chip specific ops
17 * @read_sensor: reads gpadc output
18 * @irq_handler: irq handler
19 * @show_name: hwmon device name
20 * @show_label: hwmon attribute label
21 * @is_visible: is attribute visible
22 */
23struct abx500_temp_ops {
24 int (*read_sensor)(struct abx500_temp *, u8, int *);
25 int (*irq_handler)(int, struct abx500_temp *);
26 ssize_t (*show_name)(struct device *,
27 struct device_attribute *, char *);
28 ssize_t (*show_label) (struct device *,
29 struct device_attribute *, char *);
30 int (*is_visible)(struct attribute *, int);
31};
32
33/*
34 * struct abx500_temp - representation of temp mon device
35 * @pdev: platform device
36 * @hwmon_dev: hwmon device
37 * @ops: abx500 chip specific ops
38 * @gpadc_addr: gpadc channel address
39 * @min: sensor temperature min value
40 * @max: sensor temperature max value
41 * @max_hyst: sensor temperature hysteresis value for max limit
42 * @min_alarm: sensor temperature min alarm
43 * @max_alarm: sensor temperature max alarm
44 * @work: delayed work scheduled to monitor temperature periodically
45 * @work_active: True if work is active
46 * @lock: mutex
47 * @monitored_sensors: number of monitored sensors
48 * @plat_data: private usage, usually points to platform specific data
49 */
50struct abx500_temp {
51 struct platform_device *pdev;
52 struct device *hwmon_dev;
53 struct abx500_temp_ops ops;
54 u8 gpadc_addr[NUM_SENSORS];
55 unsigned long min[NUM_SENSORS];
56 unsigned long max[NUM_SENSORS];
57 unsigned long max_hyst[NUM_SENSORS];
58 bool min_alarm[NUM_SENSORS];
59 bool max_alarm[NUM_SENSORS];
60 struct delayed_work work;
61 bool work_active;
62 struct mutex lock;
63 int monitored_sensors;
64 void *plat_data;
65};
66
67int abx500_hwmon_init(struct abx500_temp *data);
68
69#endif /* _ABX500_H */
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 7c84ced2e01b..f276352cc9ef 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -95,6 +95,7 @@
95#define AB8500_IT_MASK22_REG 0x55 95#define AB8500_IT_MASK22_REG 0x55
96#define AB8500_IT_MASK23_REG 0x56 96#define AB8500_IT_MASK23_REG 0x56
97#define AB8500_IT_MASK24_REG 0x57 97#define AB8500_IT_MASK24_REG 0x57
98#define AB8500_IT_MASK25_REG 0x58
98 99
99/* 100/*
100 * latch hierarchy registers 101 * latch hierarchy registers
@@ -102,15 +103,25 @@
102#define AB8500_IT_LATCHHIER1_REG 0x60 103#define AB8500_IT_LATCHHIER1_REG 0x60
103#define AB8500_IT_LATCHHIER2_REG 0x61 104#define AB8500_IT_LATCHHIER2_REG 0x61
104#define AB8500_IT_LATCHHIER3_REG 0x62 105#define AB8500_IT_LATCHHIER3_REG 0x62
106#define AB8540_IT_LATCHHIER4_REG 0x63
105 107
106#define AB8500_IT_LATCHHIER_NUM 3 108#define AB8500_IT_LATCHHIER_NUM 3
109#define AB8540_IT_LATCHHIER_NUM 4
107 110
108#define AB8500_REV_REG 0x80 111#define AB8500_REV_REG 0x80
109#define AB8500_IC_NAME_REG 0x82 112#define AB8500_IC_NAME_REG 0x82
110#define AB8500_SWITCH_OFF_STATUS 0x00 113#define AB8500_SWITCH_OFF_STATUS 0x00
111 114
112#define AB8500_TURN_ON_STATUS 0x00 115#define AB8500_TURN_ON_STATUS 0x00
116#define AB8505_TURN_ON_STATUS_2 0x04
113 117
118#define AB8500_CH_USBCH_STAT1_REG 0x02
119#define VBUS_DET_DBNC100 0x02
120#define VBUS_DET_DBNC1 0x01
121
122static DEFINE_SPINLOCK(on_stat_lock);
123static u8 turn_on_stat_mask = 0xFF;
124static u8 turn_on_stat_set;
114static bool no_bm; /* No battery management */ 125static bool no_bm; /* No battery management */
115module_param(no_bm, bool, S_IRUGO); 126module_param(no_bm, bool, S_IRUGO);
116 127
@@ -130,9 +141,15 @@ static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
130 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 141 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
131}; 142};
132 143
133/* AB9540 support */ 144/* AB9540 / AB8505 support */
134static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = { 145static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
135 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 146 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23
147};
148
149/* AB8540 support */
150static const int ab8540_irq_regoffset[AB8540_NUM_IRQ_REGS] = {
151 0, 1, 2, 3, 4, -1, -1, -1, -1, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23,
152 25, 26, 27, 28, 29, 30, 31,
136}; 153};
137 154
138static const char ab8500_version_str[][7] = { 155static const char ab8500_version_str[][7] = {
@@ -352,6 +369,9 @@ static void ab8500_irq_sync_unlock(struct irq_data *data)
352 is_ab8500_1p1_or_earlier(ab8500)) 369 is_ab8500_1p1_or_earlier(ab8500))
353 continue; 370 continue;
354 371
372 if (ab8500->irq_reg_offset[i] < 0)
373 continue;
374
355 ab8500->oldmask[i] = new; 375 ab8500->oldmask[i] = new;
356 376
357 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; 377 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
@@ -423,6 +443,18 @@ static struct irq_chip ab8500_irq_chip = {
423 .irq_set_type = ab8500_irq_set_type, 443 .irq_set_type = ab8500_irq_set_type,
424}; 444};
425 445
446static void update_latch_offset(u8 *offset, int i)
447{
448 /* Fix inconsistent ITFromLatch25 bit mapping... */
449 if (unlikely(*offset == 17))
450 *offset = 24;
451 /* Fix inconsistent ab8540 bit mapping... */
452 if (unlikely(*offset == 16))
453 *offset = 25;
454 if ((i==3) && (*offset >= 24))
455 *offset += 2;
456}
457
426static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, 458static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
427 int latch_offset, u8 latch_val) 459 int latch_offset, u8 latch_val)
428{ 460{
@@ -474,9 +506,7 @@ static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
474 latch_bit = __ffs(hier_val); 506 latch_bit = __ffs(hier_val);
475 latch_offset = (hier_offset << 3) + latch_bit; 507 latch_offset = (hier_offset << 3) + latch_bit;
476 508
477 /* Fix inconsistent ITFromLatch25 bit mapping... */ 509 update_latch_offset(&latch_offset, hier_offset);
478 if (unlikely(latch_offset == 17))
479 latch_offset = 24;
480 510
481 status = get_register_interruptible(ab8500, 511 status = get_register_interruptible(ab8500,
482 AB8500_INTERRUPT, 512 AB8500_INTERRUPT,
@@ -504,7 +534,7 @@ static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
504 dev_vdbg(ab8500->dev, "interrupt\n"); 534 dev_vdbg(ab8500->dev, "interrupt\n");
505 535
506 /* Hierarchical interrupt version */ 536 /* Hierarchical interrupt version */
507 for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) { 537 for (i = 0; i < (ab8500->it_latchhier_num); i++) {
508 int status; 538 int status;
509 u8 hier_val; 539 u8 hier_val;
510 540
@@ -520,63 +550,6 @@ static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
520 return IRQ_HANDLED; 550 return IRQ_HANDLED;
521} 551}
522 552
523/**
524 * ab8500_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ
525 *
526 * @ab8500: ab8500_irq controller to operate on.
527 * @irq: index of the interrupt requested in the chip IRQs
528 *
529 * Useful for drivers to request their own IRQs.
530 */
531static int ab8500_irq_get_virq(struct ab8500 *ab8500, int irq)
532{
533 if (!ab8500)
534 return -EINVAL;
535
536 return irq_create_mapping(ab8500->domain, irq);
537}
538
539static irqreturn_t ab8500_irq(int irq, void *dev)
540{
541 struct ab8500 *ab8500 = dev;
542 int i;
543
544 dev_vdbg(ab8500->dev, "interrupt\n");
545
546 atomic_inc(&ab8500->transfer_ongoing);
547
548 for (i = 0; i < ab8500->mask_size; i++) {
549 int regoffset = ab8500->irq_reg_offset[i];
550 int status;
551 u8 value;
552
553 /*
554 * Interrupt register 12 doesn't exist prior to AB8500 version
555 * 2.0
556 */
557 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
558 continue;
559
560 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
561 AB8500_IT_LATCH1_REG + regoffset, &value);
562 if (status < 0 || value == 0)
563 continue;
564
565 do {
566 int bit = __ffs(value);
567 int line = i * 8 + bit;
568 int virq = ab8500_irq_get_virq(ab8500, line);
569
570 handle_nested_irq(virq);
571 ab8500_debug_register_interrupt(line);
572 value &= ~(1 << bit);
573
574 } while (value);
575 }
576 atomic_dec(&ab8500->transfer_ongoing);
577 return IRQ_HANDLED;
578}
579
580static int ab8500_irq_map(struct irq_domain *d, unsigned int virq, 553static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
581 irq_hw_number_t hwirq) 554 irq_hw_number_t hwirq)
582{ 555{
@@ -607,7 +580,9 @@ static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
607{ 580{
608 int num_irqs; 581 int num_irqs;
609 582
610 if (is_ab9540(ab8500)) 583 if (is_ab8540(ab8500))
584 num_irqs = AB8540_NR_IRQS;
585 else if (is_ab9540(ab8500))
611 num_irqs = AB9540_NR_IRQS; 586 num_irqs = AB9540_NR_IRQS;
612 else if (is_ab8505(ab8500)) 587 else if (is_ab8505(ab8500))
613 num_irqs = AB8505_NR_IRQS; 588 num_irqs = AB8505_NR_IRQS;
@@ -650,6 +625,15 @@ static struct resource ab8500_gpadc_resources[] = {
650 }, 625 },
651}; 626};
652 627
628static struct resource ab8505_gpadc_resources[] = {
629 {
630 .name = "SW_CONV_END",
631 .start = AB8500_INT_GP_SW_ADC_CONV_END,
632 .end = AB8500_INT_GP_SW_ADC_CONV_END,
633 .flags = IORESOURCE_IRQ,
634 },
635};
636
653static struct resource ab8500_rtc_resources[] = { 637static struct resource ab8500_rtc_resources[] = {
654 { 638 {
655 .name = "60S", 639 .name = "60S",
@@ -973,6 +957,30 @@ static struct resource ab8505_iddet_resources[] = {
973 .end = AB8505_INT_KEYSTUCK, 957 .end = AB8505_INT_KEYSTUCK,
974 .flags = IORESOURCE_IRQ, 958 .flags = IORESOURCE_IRQ,
975 }, 959 },
960 {
961 .name = "VBUS_DET_R",
962 .start = AB8500_INT_VBUS_DET_R,
963 .end = AB8500_INT_VBUS_DET_R,
964 .flags = IORESOURCE_IRQ,
965 },
966 {
967 .name = "VBUS_DET_F",
968 .start = AB8500_INT_VBUS_DET_F,
969 .end = AB8500_INT_VBUS_DET_F,
970 .flags = IORESOURCE_IRQ,
971 },
972 {
973 .name = "ID_DET_PLUGR",
974 .start = AB8500_INT_ID_DET_PLUGR,
975 .end = AB8500_INT_ID_DET_PLUGR,
976 .flags = IORESOURCE_IRQ,
977 },
978 {
979 .name = "ID_DET_PLUGF",
980 .start = AB8500_INT_ID_DET_PLUGF,
981 .end = AB8500_INT_ID_DET_PLUGF,
982 .flags = IORESOURCE_IRQ,
983 },
976}; 984};
977 985
978static struct resource ab8500_temp_resources[] = { 986static struct resource ab8500_temp_resources[] = {
@@ -984,7 +992,42 @@ static struct resource ab8500_temp_resources[] = {
984 }, 992 },
985}; 993};
986 994
987static struct mfd_cell abx500_common_devs[] = { 995static struct mfd_cell ab8500_bm_devs[] = {
996 {
997 .name = "ab8500-charger",
998 .of_compatible = "stericsson,ab8500-charger",
999 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
1000 .resources = ab8500_charger_resources,
1001 .platform_data = &ab8500_bm_data,
1002 .pdata_size = sizeof(ab8500_bm_data),
1003 },
1004 {
1005 .name = "ab8500-btemp",
1006 .of_compatible = "stericsson,ab8500-btemp",
1007 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
1008 .resources = ab8500_btemp_resources,
1009 .platform_data = &ab8500_bm_data,
1010 .pdata_size = sizeof(ab8500_bm_data),
1011 },
1012 {
1013 .name = "ab8500-fg",
1014 .of_compatible = "stericsson,ab8500-fg",
1015 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
1016 .resources = ab8500_fg_resources,
1017 .platform_data = &ab8500_bm_data,
1018 .pdata_size = sizeof(ab8500_bm_data),
1019 },
1020 {
1021 .name = "ab8500-chargalg",
1022 .of_compatible = "stericsson,ab8500-chargalg",
1023 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
1024 .resources = ab8500_chargalg_resources,
1025 .platform_data = &ab8500_bm_data,
1026 .pdata_size = sizeof(ab8500_bm_data),
1027 },
1028};
1029
1030static struct mfd_cell ab8500_devs[] = {
988#ifdef CONFIG_DEBUG_FS 1031#ifdef CONFIG_DEBUG_FS
989 { 1032 {
990 .name = "ab8500-debug", 1033 .name = "ab8500-debug",
@@ -1007,7 +1050,6 @@ static struct mfd_cell abx500_common_devs[] = {
1007 }, 1050 },
1008 { 1051 {
1009 .name = "ab8500-gpadc", 1052 .name = "ab8500-gpadc",
1010 .of_compatible = "stericsson,ab8500-gpadc",
1011 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources), 1053 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
1012 .resources = ab8500_gpadc_resources, 1054 .resources = ab8500_gpadc_resources,
1013 }, 1055 },
@@ -1024,6 +1066,7 @@ static struct mfd_cell abx500_common_devs[] = {
1024 .resources = ab8500_av_acc_detect_resources, 1066 .resources = ab8500_av_acc_detect_resources,
1025 }, 1067 },
1026 { 1068 {
1069
1027 .name = "ab8500-poweron-key", 1070 .name = "ab8500-poweron-key",
1028 .of_compatible = "stericsson,ab8500-poweron-key", 1071 .of_compatible = "stericsson,ab8500-poweron-key",
1029 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), 1072 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
@@ -1053,82 +1096,220 @@ static struct mfd_cell abx500_common_devs[] = {
1053 .of_compatible = "stericsson,ab8500-denc", 1096 .of_compatible = "stericsson,ab8500-denc",
1054 }, 1097 },
1055 { 1098 {
1099 .name = "ab8500-gpio",
1100 .of_compatible = "stericsson,ab8500-gpio",
1101 },
1102 {
1056 .name = "abx500-temp", 1103 .name = "abx500-temp",
1057 .of_compatible = "stericsson,abx500-temp", 1104 .of_compatible = "stericsson,abx500-temp",
1058 .num_resources = ARRAY_SIZE(ab8500_temp_resources), 1105 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1059 .resources = ab8500_temp_resources, 1106 .resources = ab8500_temp_resources,
1060 }, 1107 },
1108 {
1109 .name = "ab8500-usb",
1110 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1111 .resources = ab8500_usb_resources,
1112 },
1113 {
1114 .name = "ab8500-codec",
1115 },
1061}; 1116};
1062 1117
1063static struct mfd_cell ab8500_bm_devs[] = { 1118static struct mfd_cell ab9540_devs[] = {
1119#ifdef CONFIG_DEBUG_FS
1064 { 1120 {
1065 .name = "ab8500-charger", 1121 .name = "ab8500-debug",
1066 .of_compatible = "stericsson,ab8500-charger", 1122 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1067 .num_resources = ARRAY_SIZE(ab8500_charger_resources), 1123 .resources = ab8500_debug_resources,
1068 .resources = ab8500_charger_resources,
1069 .platform_data = &ab8500_bm_data,
1070 .pdata_size = sizeof(ab8500_bm_data),
1071 }, 1124 },
1125#endif
1072 { 1126 {
1073 .name = "ab8500-btemp", 1127 .name = "ab8500-sysctrl",
1074 .of_compatible = "stericsson,ab8500-btemp",
1075 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
1076 .resources = ab8500_btemp_resources,
1077 .platform_data = &ab8500_bm_data,
1078 .pdata_size = sizeof(ab8500_bm_data),
1079 }, 1128 },
1080 { 1129 {
1081 .name = "ab8500-fg", 1130 .name = "ab8500-regulator",
1082 .of_compatible = "stericsson,ab8500-fg",
1083 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
1084 .resources = ab8500_fg_resources,
1085 .platform_data = &ab8500_bm_data,
1086 .pdata_size = sizeof(ab8500_bm_data),
1087 }, 1131 },
1088 { 1132 {
1089 .name = "ab8500-chargalg", 1133 .name = "abx500-clk",
1090 .of_compatible = "stericsson,ab8500-chargalg", 1134 .of_compatible = "stericsson,abx500-clk",
1091 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), 1135 },
1092 .resources = ab8500_chargalg_resources, 1136 {
1093 .platform_data = &ab8500_bm_data, 1137 .name = "ab8500-gpadc",
1094 .pdata_size = sizeof(ab8500_bm_data), 1138 .of_compatible = "stericsson,ab8500-gpadc",
1139 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
1140 .resources = ab8500_gpadc_resources,
1141 },
1142 {
1143 .name = "ab8500-rtc",
1144 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1145 .resources = ab8500_rtc_resources,
1146 },
1147 {
1148 .name = "ab8500-acc-det",
1149 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1150 .resources = ab8500_av_acc_detect_resources,
1151 },
1152 {
1153 .name = "ab8500-poweron-key",
1154 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1155 .resources = ab8500_poweronkey_db_resources,
1156 },
1157 {
1158 .name = "ab8500-pwm",
1159 .id = 1,
1160 },
1161 {
1162 .name = "ab8500-leds",
1163 },
1164 {
1165 .name = "abx500-temp",
1166 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1167 .resources = ab8500_temp_resources,
1168 },
1169 {
1170 .name = "pinctrl-ab9540",
1171 .of_compatible = "stericsson,ab9540-gpio",
1172 },
1173 {
1174 .name = "ab9540-usb",
1175 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1176 .resources = ab8500_usb_resources,
1177 },
1178 {
1179 .name = "ab9540-codec",
1180 },
1181 {
1182 .name = "ab-iddet",
1183 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1184 .resources = ab8505_iddet_resources,
1095 }, 1185 },
1096}; 1186};
1097 1187
1098static struct mfd_cell ab8500_devs[] = { 1188/* Device list for ab8505 */
1189static struct mfd_cell ab8505_devs[] = {
1190#ifdef CONFIG_DEBUG_FS
1099 { 1191 {
1100 .name = "pinctrl-ab8500", 1192 .name = "ab8500-debug",
1101 .of_compatible = "stericsson,ab8500-gpio", 1193 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1194 .resources = ab8500_debug_resources,
1195 },
1196#endif
1197 {
1198 .name = "ab8500-sysctrl",
1199 },
1200 {
1201 .name = "ab8500-regulator",
1202 },
1203 {
1204 .name = "abx500-clk",
1205 .of_compatible = "stericsson,abx500-clk",
1206 },
1207 {
1208 .name = "ab8500-gpadc",
1209 .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
1210 .resources = ab8505_gpadc_resources,
1211 },
1212 {
1213 .name = "ab8500-rtc",
1214 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1215 .resources = ab8500_rtc_resources,
1216 },
1217 {
1218 .name = "ab8500-acc-det",
1219 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1220 .resources = ab8500_av_acc_detect_resources,
1221 },
1222 {
1223 .name = "ab8500-poweron-key",
1224 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1225 .resources = ab8500_poweronkey_db_resources,
1226 },
1227 {
1228 .name = "ab8500-pwm",
1229 .id = 1,
1230 },
1231 {
1232 .name = "ab8500-leds",
1233 },
1234 {
1235 .name = "ab8500-gpio",
1102 }, 1236 },
1103 { 1237 {
1104 .name = "ab8500-usb", 1238 .name = "ab8500-usb",
1105 .of_compatible = "stericsson,ab8500-usb",
1106 .num_resources = ARRAY_SIZE(ab8500_usb_resources), 1239 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1107 .resources = ab8500_usb_resources, 1240 .resources = ab8500_usb_resources,
1108 }, 1241 },
1109 { 1242 {
1110 .name = "ab8500-codec", 1243 .name = "ab8500-codec",
1111 .of_compatible = "stericsson,ab8500-codec", 1244 },
1245 {
1246 .name = "ab-iddet",
1247 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1248 .resources = ab8505_iddet_resources,
1112 }, 1249 },
1113}; 1250};
1114 1251
1115static struct mfd_cell ab9540_devs[] = { 1252static struct mfd_cell ab8540_devs[] = {
1253#ifdef CONFIG_DEBUG_FS
1116 { 1254 {
1117 .name = "pinctrl-ab9540", 1255 .name = "ab8500-debug",
1118 .of_compatible = "stericsson,ab9540-gpio", 1256 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
1257 .resources = ab8500_debug_resources,
1258 },
1259#endif
1260 {
1261 .name = "ab8500-sysctrl",
1119 }, 1262 },
1120 { 1263 {
1121 .name = "ab9540-usb", 1264 .name = "ab8500-regulator",
1265 },
1266 {
1267 .name = "abx500-clk",
1268 .of_compatible = "stericsson,abx500-clk",
1269 },
1270 {
1271 .name = "ab8500-gpadc",
1272 .num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
1273 .resources = ab8505_gpadc_resources,
1274 },
1275 {
1276 .name = "ab8500-rtc",
1277 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
1278 .resources = ab8500_rtc_resources,
1279 },
1280 {
1281 .name = "ab8500-acc-det",
1282 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
1283 .resources = ab8500_av_acc_detect_resources,
1284 },
1285 {
1286 .name = "ab8500-poweron-key",
1287 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1288 .resources = ab8500_poweronkey_db_resources,
1289 },
1290 {
1291 .name = "ab8500-pwm",
1292 .id = 1,
1293 },
1294 {
1295 .name = "ab8500-leds",
1296 },
1297 {
1298 .name = "abx500-temp",
1299 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1300 .resources = ab8500_temp_resources,
1301 },
1302 {
1303 .name = "ab8500-gpio",
1304 },
1305 {
1306 .name = "ab8540-usb",
1122 .num_resources = ARRAY_SIZE(ab8500_usb_resources), 1307 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1123 .resources = ab8500_usb_resources, 1308 .resources = ab8500_usb_resources,
1124 }, 1309 },
1125 { 1310 {
1126 .name = "ab9540-codec", 1311 .name = "ab8540-codec",
1127 }, 1312 },
1128};
1129
1130/* Device list common to ab9540 and ab8505 */
1131static struct mfd_cell ab9540_ab8505_devs[] = {
1132 { 1313 {
1133 .name = "ab-iddet", 1314 .name = "ab-iddet",
1134 .num_resources = ARRAY_SIZE(ab8505_iddet_resources), 1315 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
@@ -1142,6 +1323,7 @@ static ssize_t show_chip_id(struct device *dev,
1142 struct ab8500 *ab8500; 1323 struct ab8500 *ab8500;
1143 1324
1144 ab8500 = dev_get_drvdata(dev); 1325 ab8500 = dev_get_drvdata(dev);
1326
1145 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); 1327 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
1146} 1328}
1147 1329
@@ -1171,6 +1353,15 @@ static ssize_t show_switch_off_status(struct device *dev,
1171 return sprintf(buf, "%#x\n", value); 1353 return sprintf(buf, "%#x\n", value);
1172} 1354}
1173 1355
1356/* use mask and set to override the register turn_on_stat value */
1357void ab8500_override_turn_on_stat(u8 mask, u8 set)
1358{
1359 spin_lock(&on_stat_lock);
1360 turn_on_stat_mask = mask;
1361 turn_on_stat_set = set;
1362 spin_unlock(&on_stat_lock);
1363}
1364
1174/* 1365/*
1175 * ab8500 has turned on due to (TURN_ON_STATUS): 1366 * ab8500 has turned on due to (TURN_ON_STATUS):
1176 * 0x01 PORnVbat 1367 * 0x01 PORnVbat
@@ -1194,9 +1385,38 @@ static ssize_t show_turn_on_status(struct device *dev,
1194 AB8500_TURN_ON_STATUS, &value); 1385 AB8500_TURN_ON_STATUS, &value);
1195 if (ret < 0) 1386 if (ret < 0)
1196 return ret; 1387 return ret;
1388
1389 /*
1390 * In L9540, turn_on_status register is not updated correctly if
1391 * the device is rebooted with AC/USB charger connected. Due to
1392 * this, the device boots android instead of entering into charge
1393 * only mode. Read the AC/USB status register to detect the charger
1394 * presence and update the turn on status manually.
1395 */
1396 if (is_ab9540(ab8500)) {
1397 spin_lock(&on_stat_lock);
1398 value = (value & turn_on_stat_mask) | turn_on_stat_set;
1399 spin_unlock(&on_stat_lock);
1400 }
1401
1197 return sprintf(buf, "%#x\n", value); 1402 return sprintf(buf, "%#x\n", value);
1198} 1403}
1199 1404
1405static ssize_t show_turn_on_status_2(struct device *dev,
1406 struct device_attribute *attr, char *buf)
1407{
1408 int ret;
1409 u8 value;
1410 struct ab8500 *ab8500;
1411
1412 ab8500 = dev_get_drvdata(dev);
1413 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1414 AB8505_TURN_ON_STATUS_2, &value);
1415 if (ret < 0)
1416 return ret;
1417 return sprintf(buf, "%#x\n", (value & 0x1));
1418}
1419
1200static ssize_t show_ab9540_dbbrstn(struct device *dev, 1420static ssize_t show_ab9540_dbbrstn(struct device *dev,
1201 struct device_attribute *attr, char *buf) 1421 struct device_attribute *attr, char *buf)
1202{ 1422{
@@ -1253,6 +1473,7 @@ exit:
1253static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); 1473static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
1254static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL); 1474static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
1255static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL); 1475static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
1476static DEVICE_ATTR(turn_on_status_2, S_IRUGO, show_turn_on_status_2, NULL);
1256static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR, 1477static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
1257 show_ab9540_dbbrstn, store_ab9540_dbbrstn); 1478 show_ab9540_dbbrstn, store_ab9540_dbbrstn);
1258 1479
@@ -1263,6 +1484,11 @@ static struct attribute *ab8500_sysfs_entries[] = {
1263 NULL, 1484 NULL,
1264}; 1485};
1265 1486
1487static struct attribute *ab8505_sysfs_entries[] = {
1488 &dev_attr_turn_on_status_2.attr,
1489 NULL,
1490};
1491
1266static struct attribute *ab9540_sysfs_entries[] = { 1492static struct attribute *ab9540_sysfs_entries[] = {
1267 &dev_attr_chip_id.attr, 1493 &dev_attr_chip_id.attr,
1268 &dev_attr_switch_off_status.attr, 1494 &dev_attr_switch_off_status.attr,
@@ -1275,6 +1501,10 @@ static struct attribute_group ab8500_attr_group = {
1275 .attrs = ab8500_sysfs_entries, 1501 .attrs = ab8500_sysfs_entries,
1276}; 1502};
1277 1503
1504static struct attribute_group ab8505_attr_group = {
1505 .attrs = ab8505_sysfs_entries,
1506};
1507
1278static struct attribute_group ab9540_attr_group = { 1508static struct attribute_group ab9540_attr_group = {
1279 .attrs = ab9540_sysfs_entries, 1509 .attrs = ab9540_sysfs_entries,
1280}; 1510};
@@ -1290,6 +1520,15 @@ static int ab8500_probe(struct platform_device *pdev)
1290 "Battery level lower than power on reset threshold", 1520 "Battery level lower than power on reset threshold",
1291 "Power on key 1 pressed longer than 10 seconds", 1521 "Power on key 1 pressed longer than 10 seconds",
1292 "DB8500 thermal shutdown"}; 1522 "DB8500 thermal shutdown"};
1523 static char *turn_on_status[] = {
1524 "Battery rising (Vbat)",
1525 "Power On Key 1 dbF",
1526 "Power On Key 2 dbF",
1527 "RTC Alarm",
1528 "Main Charger Detect",
1529 "Vbus Detect (USB)",
1530 "USB ID Detect",
1531 "UART Factory Mode Detect"};
1293 struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev); 1532 struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
1294 const struct platform_device_id *platid = platform_get_device_id(pdev); 1533 const struct platform_device_id *platid = platform_get_device_id(pdev);
1295 enum ab8500_version version = AB8500_VERSION_UNDEFINED; 1534 enum ab8500_version version = AB8500_VERSION_UNDEFINED;
@@ -1351,13 +1590,20 @@ static int ab8500_probe(struct platform_device *pdev)
1351 ab8500->chip_id >> 4, 1590 ab8500->chip_id >> 4,
1352 ab8500->chip_id & 0x0F); 1591 ab8500->chip_id & 0x0F);
1353 1592
1354 /* Configure AB8500 or AB9540 IRQ */ 1593 /* Configure AB8540 */
1355 if (is_ab9540(ab8500) || is_ab8505(ab8500)) { 1594 if (is_ab8540(ab8500)) {
1595 ab8500->mask_size = AB8540_NUM_IRQ_REGS;
1596 ab8500->irq_reg_offset = ab8540_irq_regoffset;
1597 ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM;
1598 }/* Configure AB8500 or AB9540 IRQ */
1599 else if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
1356 ab8500->mask_size = AB9540_NUM_IRQ_REGS; 1600 ab8500->mask_size = AB9540_NUM_IRQ_REGS;
1357 ab8500->irq_reg_offset = ab9540_irq_regoffset; 1601 ab8500->irq_reg_offset = ab9540_irq_regoffset;
1602 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1358 } else { 1603 } else {
1359 ab8500->mask_size = AB8500_NUM_IRQ_REGS; 1604 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1360 ab8500->irq_reg_offset = ab8500_irq_regoffset; 1605 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1606 ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1361 } 1607 }
1362 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); 1608 ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
1363 if (!ab8500->mask) 1609 if (!ab8500->mask)
@@ -1396,10 +1642,36 @@ static int ab8500_probe(struct platform_device *pdev)
1396 } else { 1642 } else {
1397 printk(KERN_CONT " None\n"); 1643 printk(KERN_CONT " None\n");
1398 } 1644 }
1645 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1646 AB8500_TURN_ON_STATUS, &value);
1647 if (ret < 0)
1648 return ret;
1649 dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value);
1650
1651 if (value) {
1652 for (i = 0; i < ARRAY_SIZE(turn_on_status); i++) {
1653 if (value & 1)
1654 printk("\"%s\" ", turn_on_status[i]);
1655 value = value >> 1;
1656 }
1657 printk("\n");
1658 } else {
1659 printk("None\n");
1660 }
1399 1661
1400 if (plat && plat->init) 1662 if (plat && plat->init)
1401 plat->init(ab8500); 1663 plat->init(ab8500);
1402 1664
1665 if (is_ab9540(ab8500)) {
1666 ret = get_register_interruptible(ab8500, AB8500_CHARGER,
1667 AB8500_CH_USBCH_STAT1_REG, &value);
1668 if (ret < 0)
1669 return ret;
1670 if ((value & VBUS_DET_DBNC1) && (value & VBUS_DET_DBNC100))
1671 ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
1672 AB8500_VBUS_DET);
1673 }
1674
1403 /* Clear and mask all interrupts */ 1675 /* Clear and mask all interrupts */
1404 for (i = 0; i < ab8500->mask_size; i++) { 1676 for (i = 0; i < ab8500->mask_size; i++) {
1405 /* 1677 /*
@@ -1410,6 +1682,9 @@ static int ab8500_probe(struct platform_device *pdev)
1410 is_ab8500_1p1_or_earlier(ab8500)) 1682 is_ab8500_1p1_or_earlier(ab8500))
1411 continue; 1683 continue;
1412 1684
1685 if (ab8500->irq_reg_offset[i] < 0)
1686 continue;
1687
1413 get_register_interruptible(ab8500, AB8500_INTERRUPT, 1688 get_register_interruptible(ab8500, AB8500_INTERRUPT,
1414 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], 1689 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
1415 &value); 1690 &value);
@@ -1428,26 +1703,10 @@ static int ab8500_probe(struct platform_device *pdev)
1428 if (ret) 1703 if (ret)
1429 return ret; 1704 return ret;
1430 1705
1431 /* Activate this feature only in ab9540 */ 1706 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1432 /* till tests are done on ab8500 1p2 or later*/ 1707 ab8500_hierarchical_irq,
1433 if (is_ab9540(ab8500)) { 1708 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1434 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, 1709 "ab8500", ab8500);
1435 ab8500_hierarchical_irq,
1436 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1437 "ab8500", ab8500);
1438 }
1439 else {
1440 ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
1441 ab8500_irq,
1442 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1443 "ab8500", ab8500);
1444 if (ret)
1445 return ret;
1446 }
1447
1448 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1449 ARRAY_SIZE(abx500_common_devs), NULL,
1450 ab8500->irq_base, ab8500->domain);
1451 if (ret) 1710 if (ret)
1452 return ret; 1711 return ret;
1453 1712
@@ -1455,6 +1714,14 @@ static int ab8500_probe(struct platform_device *pdev)
1455 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, 1714 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1456 ARRAY_SIZE(ab9540_devs), NULL, 1715 ARRAY_SIZE(ab9540_devs), NULL,
1457 ab8500->irq_base, ab8500->domain); 1716 ab8500->irq_base, ab8500->domain);
1717 else if (is_ab8540(ab8500))
1718 ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs,
1719 ARRAY_SIZE(ab8540_devs), NULL,
1720 ab8500->irq_base, ab8500->domain);
1721 else if (is_ab8505(ab8500))
1722 ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs,
1723 ARRAY_SIZE(ab8505_devs), NULL,
1724 ab8500->irq_base, ab8500->domain);
1458 else 1725 else
1459 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, 1726 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
1460 ARRAY_SIZE(ab8500_devs), NULL, 1727 ARRAY_SIZE(ab8500_devs), NULL,
@@ -1462,13 +1729,6 @@ static int ab8500_probe(struct platform_device *pdev)
1462 if (ret) 1729 if (ret)
1463 return ret; 1730 return ret;
1464 1731
1465 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1466 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1467 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
1468 ab8500->irq_base, ab8500->domain);
1469 if (ret)
1470 return ret;
1471
1472 if (!no_bm) { 1732 if (!no_bm) {
1473 /* Add battery management devices */ 1733 /* Add battery management devices */
1474 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, 1734 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
@@ -1478,12 +1738,19 @@ static int ab8500_probe(struct platform_device *pdev)
1478 dev_err(ab8500->dev, "error adding bm devices\n"); 1738 dev_err(ab8500->dev, "error adding bm devices\n");
1479 } 1739 }
1480 1740
1481 if (is_ab9540(ab8500)) 1741 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1742 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1482 ret = sysfs_create_group(&ab8500->dev->kobj, 1743 ret = sysfs_create_group(&ab8500->dev->kobj,
1483 &ab9540_attr_group); 1744 &ab9540_attr_group);
1484 else 1745 else
1485 ret = sysfs_create_group(&ab8500->dev->kobj, 1746 ret = sysfs_create_group(&ab8500->dev->kobj,
1486 &ab8500_attr_group); 1747 &ab8500_attr_group);
1748
1749 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1750 ab8500->chip_id >= AB8500_CUT2P0)
1751 ret = sysfs_create_group(&ab8500->dev->kobj,
1752 &ab8505_attr_group);
1753
1487 if (ret) 1754 if (ret)
1488 dev_err(ab8500->dev, "error creating sysfs entries\n"); 1755 dev_err(ab8500->dev, "error creating sysfs entries\n");
1489 1756
@@ -1494,11 +1761,16 @@ static int ab8500_remove(struct platform_device *pdev)
1494{ 1761{
1495 struct ab8500 *ab8500 = platform_get_drvdata(pdev); 1762 struct ab8500 *ab8500 = platform_get_drvdata(pdev);
1496 1763
1497 if (is_ab9540(ab8500)) 1764 if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1765 ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1498 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); 1766 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
1499 else 1767 else
1500 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group); 1768 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
1501 1769
1770 if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
1771 ab8500->chip_id >= AB8500_CUT2P0)
1772 sysfs_remove_group(&ab8500->dev->kobj, &ab8505_attr_group);
1773
1502 mfd_remove_devices(ab8500->dev); 1774 mfd_remove_devices(ab8500->dev);
1503 1775
1504 return 0; 1776 return 0;
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 45fe3c50eb03..b88bbbc15f1e 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -80,6 +80,7 @@
80#include <linux/interrupt.h> 80#include <linux/interrupt.h>
81#include <linux/kobject.h> 81#include <linux/kobject.h>
82#include <linux/slab.h> 82#include <linux/slab.h>
83#include <linux/irq.h>
83 84
84#include <linux/mfd/abx500.h> 85#include <linux/mfd/abx500.h>
85#include <linux/mfd/abx500/ab8500.h> 86#include <linux/mfd/abx500/ab8500.h>
@@ -90,6 +91,9 @@
90#include <linux/ctype.h> 91#include <linux/ctype.h>
91#endif 92#endif
92 93
94/* TODO: this file should not reference IRQ_DB8500_AB8500! */
95#include <mach/irqs.h>
96
93static u32 debug_bank; 97static u32 debug_bank;
94static u32 debug_address; 98static u32 debug_address;
95 99
@@ -101,6 +105,11 @@ static int num_irqs;
101static struct device_attribute **dev_attr; 105static struct device_attribute **dev_attr;
102static char **event_name; 106static char **event_name;
103 107
108static u8 avg_sample = SAMPLE_16;
109static u8 trig_edge = RISING_EDGE;
110static u8 conv_type = ADC_SW;
111static u8 trig_timer;
112
104/** 113/**
105 * struct ab8500_reg_range 114 * struct ab8500_reg_range
106 * @first: the first address of the range 115 * @first: the first address of the range
@@ -150,7 +159,9 @@ static struct hwreg_cfg hwreg_cfg = {
150 159
151#define AB8500_REV_REG 0x80 160#define AB8500_REV_REG 0x80
152 161
153static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = { 162static struct ab8500_prcmu_ranges *debug_ranges;
163
164struct ab8500_prcmu_ranges ab8500_debug_ranges[AB8500_NUM_BANKS] = {
154 [0x0] = { 165 [0x0] = {
155 .num_ranges = 0, 166 .num_ranges = 0,
156 .range = NULL, 167 .range = NULL,
@@ -354,7 +365,7 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
354 }, 365 },
355 { 366 {
356 .first = 0xf5, 367 .first = 0xf5,
357 .last = 0xf6, 368 .last = 0xf6,
358 }, 369 },
359 }, 370 },
360 }, 371 },
@@ -479,6 +490,781 @@ static struct ab8500_prcmu_ranges debug_ranges[AB8500_NUM_BANKS] = {
479 }, 490 },
480}; 491};
481 492
493struct ab8500_prcmu_ranges ab8505_debug_ranges[AB8500_NUM_BANKS] = {
494 [0x0] = {
495 .num_ranges = 0,
496 .range = NULL,
497 },
498 [AB8500_SYS_CTRL1_BLOCK] = {
499 .num_ranges = 5,
500 .range = (struct ab8500_reg_range[]) {
501 {
502 .first = 0x00,
503 .last = 0x04,
504 },
505 {
506 .first = 0x42,
507 .last = 0x42,
508 },
509 {
510 .first = 0x52,
511 .last = 0x52,
512 },
513 {
514 .first = 0x54,
515 .last = 0x57,
516 },
517 {
518 .first = 0x80,
519 .last = 0x83,
520 },
521 },
522 },
523 [AB8500_SYS_CTRL2_BLOCK] = {
524 .num_ranges = 5,
525 .range = (struct ab8500_reg_range[]) {
526 {
527 .first = 0x00,
528 .last = 0x0D,
529 },
530 {
531 .first = 0x0F,
532 .last = 0x17,
533 },
534 {
535 .first = 0x20,
536 .last = 0x20,
537 },
538 {
539 .first = 0x30,
540 .last = 0x30,
541 },
542 {
543 .first = 0x32,
544 .last = 0x3A,
545 },
546 },
547 },
548 [AB8500_REGU_CTRL1] = {
549 .num_ranges = 3,
550 .range = (struct ab8500_reg_range[]) {
551 {
552 .first = 0x00,
553 .last = 0x00,
554 },
555 {
556 .first = 0x03,
557 .last = 0x11,
558 },
559 {
560 .first = 0x80,
561 .last = 0x86,
562 },
563 },
564 },
565 [AB8500_REGU_CTRL2] = {
566 .num_ranges = 6,
567 .range = (struct ab8500_reg_range[]) {
568 {
569 .first = 0x00,
570 .last = 0x06,
571 },
572 {
573 .first = 0x08,
574 .last = 0x15,
575 },
576 {
577 .first = 0x17,
578 .last = 0x19,
579 },
580 {
581 .first = 0x1B,
582 .last = 0x1D,
583 },
584 {
585 .first = 0x1F,
586 .last = 0x30,
587 },
588 {
589 .first = 0x40,
590 .last = 0x48,
591 },
592 /* 0x80-0x8B is SIM registers and should
593 * not be accessed from here */
594 },
595 },
596 [AB8500_USB] = {
597 .num_ranges = 3,
598 .range = (struct ab8500_reg_range[]) {
599 {
600 .first = 0x80,
601 .last = 0x83,
602 },
603 {
604 .first = 0x87,
605 .last = 0x8A,
606 },
607 {
608 .first = 0x91,
609 .last = 0x94,
610 },
611 },
612 },
613 [AB8500_TVOUT] = {
614 .num_ranges = 0,
615 .range = NULL,
616 },
617 [AB8500_DBI] = {
618 .num_ranges = 0,
619 .range = NULL,
620 },
621 [AB8500_ECI_AV_ACC] = {
622 .num_ranges = 1,
623 .range = (struct ab8500_reg_range[]) {
624 {
625 .first = 0x80,
626 .last = 0x82,
627 },
628 },
629 },
630 [AB8500_RESERVED] = {
631 .num_ranges = 0,
632 .range = NULL,
633 },
634 [AB8500_GPADC] = {
635 .num_ranges = 1,
636 .range = (struct ab8500_reg_range[]) {
637 {
638 .first = 0x00,
639 .last = 0x08,
640 },
641 },
642 },
643 [AB8500_CHARGER] = {
644 .num_ranges = 9,
645 .range = (struct ab8500_reg_range[]) {
646 {
647 .first = 0x02,
648 .last = 0x03,
649 },
650 {
651 .first = 0x05,
652 .last = 0x05,
653 },
654 {
655 .first = 0x40,
656 .last = 0x44,
657 },
658 {
659 .first = 0x50,
660 .last = 0x57,
661 },
662 {
663 .first = 0x60,
664 .last = 0x60,
665 },
666 {
667 .first = 0xA0,
668 .last = 0xA7,
669 },
670 {
671 .first = 0xAF,
672 .last = 0xB2,
673 },
674 {
675 .first = 0xC0,
676 .last = 0xC2,
677 },
678 {
679 .first = 0xF5,
680 .last = 0xF5,
681 },
682 },
683 },
684 [AB8500_GAS_GAUGE] = {
685 .num_ranges = 3,
686 .range = (struct ab8500_reg_range[]) {
687 {
688 .first = 0x00,
689 .last = 0x00,
690 },
691 {
692 .first = 0x07,
693 .last = 0x0A,
694 },
695 {
696 .first = 0x10,
697 .last = 0x14,
698 },
699 },
700 },
701 [AB8500_AUDIO] = {
702 .num_ranges = 1,
703 .range = (struct ab8500_reg_range[]) {
704 {
705 .first = 0x00,
706 .last = 0x83,
707 },
708 },
709 },
710 [AB8500_INTERRUPT] = {
711 .num_ranges = 11,
712 .range = (struct ab8500_reg_range[]) {
713 {
714 .first = 0x00,
715 .last = 0x04,
716 },
717 {
718 .first = 0x06,
719 .last = 0x07,
720 },
721 {
722 .first = 0x09,
723 .last = 0x09,
724 },
725 {
726 .first = 0x0B,
727 .last = 0x0C,
728 },
729 {
730 .first = 0x12,
731 .last = 0x15,
732 },
733 {
734 .first = 0x18,
735 .last = 0x18,
736 },
737 /* Latch registers should not be read here */
738 {
739 .first = 0x40,
740 .last = 0x44,
741 },
742 {
743 .first = 0x46,
744 .last = 0x49,
745 },
746 {
747 .first = 0x4B,
748 .last = 0x4D,
749 },
750 {
751 .first = 0x52,
752 .last = 0x55,
753 },
754 {
755 .first = 0x58,
756 .last = 0x58,
757 },
758 /* LatchHier registers should not be read here */
759 },
760 },
761 [AB8500_RTC] = {
762 .num_ranges = 2,
763 .range = (struct ab8500_reg_range[]) {
764 {
765 .first = 0x00,
766 .last = 0x14,
767 },
768 {
769 .first = 0x16,
770 .last = 0x17,
771 },
772 },
773 },
774 [AB8500_MISC] = {
775 .num_ranges = 8,
776 .range = (struct ab8500_reg_range[]) {
777 {
778 .first = 0x00,
779 .last = 0x06,
780 },
781 {
782 .first = 0x10,
783 .last = 0x16,
784 },
785 {
786 .first = 0x20,
787 .last = 0x26,
788 },
789 {
790 .first = 0x30,
791 .last = 0x36,
792 },
793 {
794 .first = 0x40,
795 .last = 0x46,
796 },
797 {
798 .first = 0x50,
799 .last = 0x50,
800 },
801 {
802 .first = 0x60,
803 .last = 0x6B,
804 },
805 {
806 .first = 0x80,
807 .last = 0x82,
808 },
809 },
810 },
811 [AB8500_DEVELOPMENT] = {
812 .num_ranges = 2,
813 .range = (struct ab8500_reg_range[]) {
814 {
815 .first = 0x00,
816 .last = 0x00,
817 },
818 {
819 .first = 0x05,
820 .last = 0x05,
821 },
822 },
823 },
824 [AB8500_DEBUG] = {
825 .num_ranges = 1,
826 .range = (struct ab8500_reg_range[]) {
827 {
828 .first = 0x05,
829 .last = 0x07,
830 },
831 },
832 },
833 [AB8500_PROD_TEST] = {
834 .num_ranges = 0,
835 .range = NULL,
836 },
837 [AB8500_STE_TEST] = {
838 .num_ranges = 0,
839 .range = NULL,
840 },
841 [AB8500_OTP_EMUL] = {
842 .num_ranges = 1,
843 .range = (struct ab8500_reg_range[]) {
844 {
845 .first = 0x01,
846 .last = 0x15,
847 },
848 },
849 },
850};
851
852struct ab8500_prcmu_ranges ab8540_debug_ranges[AB8500_NUM_BANKS] = {
853 [AB8500_M_FSM_RANK] = {
854 .num_ranges = 1,
855 .range = (struct ab8500_reg_range[]) {
856 {
857 .first = 0x00,
858 .last = 0x0B,
859 },
860 },
861 },
862 [AB8500_SYS_CTRL1_BLOCK] = {
863 .num_ranges = 6,
864 .range = (struct ab8500_reg_range[]) {
865 {
866 .first = 0x00,
867 .last = 0x04,
868 },
869 {
870 .first = 0x42,
871 .last = 0x42,
872 },
873 {
874 .first = 0x50,
875 .last = 0x54,
876 },
877 {
878 .first = 0x57,
879 .last = 0x57,
880 },
881 {
882 .first = 0x80,
883 .last = 0x83,
884 },
885 {
886 .first = 0x90,
887 .last = 0x90,
888 },
889 },
890 },
891 [AB8500_SYS_CTRL2_BLOCK] = {
892 .num_ranges = 5,
893 .range = (struct ab8500_reg_range[]) {
894 {
895 .first = 0x00,
896 .last = 0x0D,
897 },
898 {
899 .first = 0x0F,
900 .last = 0x10,
901 },
902 {
903 .first = 0x20,
904 .last = 0x21,
905 },
906 {
907 .first = 0x32,
908 .last = 0x3C,
909 },
910 {
911 .first = 0x40,
912 .last = 0x42,
913 },
914 },
915 },
916 [AB8500_REGU_CTRL1] = {
917 .num_ranges = 4,
918 .range = (struct ab8500_reg_range[]) {
919 {
920 .first = 0x03,
921 .last = 0x15,
922 },
923 {
924 .first = 0x20,
925 .last = 0x20,
926 },
927 {
928 .first = 0x80,
929 .last = 0x85,
930 },
931 {
932 .first = 0x87,
933 .last = 0x88,
934 },
935 },
936 },
937 [AB8500_REGU_CTRL2] = {
938 .num_ranges = 8,
939 .range = (struct ab8500_reg_range[]) {
940 {
941 .first = 0x00,
942 .last = 0x06,
943 },
944 {
945 .first = 0x08,
946 .last = 0x15,
947 },
948 {
949 .first = 0x17,
950 .last = 0x19,
951 },
952 {
953 .first = 0x1B,
954 .last = 0x1D,
955 },
956 {
957 .first = 0x1F,
958 .last = 0x2F,
959 },
960 {
961 .first = 0x31,
962 .last = 0x3A,
963 },
964 {
965 .first = 0x43,
966 .last = 0x44,
967 },
968 {
969 .first = 0x48,
970 .last = 0x49,
971 },
972 },
973 },
974 [AB8500_USB] = {
975 .num_ranges = 3,
976 .range = (struct ab8500_reg_range[]) {
977 {
978 .first = 0x80,
979 .last = 0x83,
980 },
981 {
982 .first = 0x87,
983 .last = 0x8A,
984 },
985 {
986 .first = 0x91,
987 .last = 0x94,
988 },
989 },
990 },
991 [AB8500_TVOUT] = {
992 .num_ranges = 0,
993 .range = NULL
994 },
995 [AB8500_DBI] = {
996 .num_ranges = 4,
997 .range = (struct ab8500_reg_range[]) {
998 {
999 .first = 0x00,
1000 .last = 0x07,
1001 },
1002 {
1003 .first = 0x10,
1004 .last = 0x11,
1005 },
1006 {
1007 .first = 0x20,
1008 .last = 0x21,
1009 },
1010 {
1011 .first = 0x30,
1012 .last = 0x43,
1013 },
1014 },
1015 },
1016 [AB8500_ECI_AV_ACC] = {
1017 .num_ranges = 2,
1018 .range = (struct ab8500_reg_range[]) {
1019 {
1020 .first = 0x00,
1021 .last = 0x03,
1022 },
1023 {
1024 .first = 0x80,
1025 .last = 0x82,
1026 },
1027 },
1028 },
1029 [AB8500_RESERVED] = {
1030 .num_ranges = 0,
1031 .range = NULL,
1032 },
1033 [AB8500_GPADC] = {
1034 .num_ranges = 4,
1035 .range = (struct ab8500_reg_range[]) {
1036 {
1037 .first = 0x00,
1038 .last = 0x01,
1039 },
1040 {
1041 .first = 0x04,
1042 .last = 0x06,
1043 },
1044 {
1045 .first = 0x09,
1046 .last = 0x0A,
1047 },
1048 {
1049 .first = 0x10,
1050 .last = 0x14,
1051 },
1052 },
1053 },
1054 [AB8500_CHARGER] = {
1055 .num_ranges = 10,
1056 .range = (struct ab8500_reg_range[]) {
1057 {
1058 .first = 0x00,
1059 .last = 0x00,
1060 },
1061 {
1062 .first = 0x02,
1063 .last = 0x05,
1064 },
1065 {
1066 .first = 0x40,
1067 .last = 0x44,
1068 },
1069 {
1070 .first = 0x50,
1071 .last = 0x57,
1072 },
1073 {
1074 .first = 0x60,
1075 .last = 0x60,
1076 },
1077 {
1078 .first = 0x70,
1079 .last = 0x70,
1080 },
1081 {
1082 .first = 0xA0,
1083 .last = 0xA9,
1084 },
1085 {
1086 .first = 0xAF,
1087 .last = 0xB2,
1088 },
1089 {
1090 .first = 0xC0,
1091 .last = 0xC6,
1092 },
1093 {
1094 .first = 0xF5,
1095 .last = 0xF5,
1096 },
1097 },
1098 },
1099 [AB8500_GAS_GAUGE] = {
1100 .num_ranges = 3,
1101 .range = (struct ab8500_reg_range[]) {
1102 {
1103 .first = 0x00,
1104 .last = 0x00,
1105 },
1106 {
1107 .first = 0x07,
1108 .last = 0x0A,
1109 },
1110 {
1111 .first = 0x10,
1112 .last = 0x14,
1113 },
1114 },
1115 },
1116 [AB8500_AUDIO] = {
1117 .num_ranges = 1,
1118 .range = (struct ab8500_reg_range[]) {
1119 {
1120 .first = 0x00,
1121 .last = 0x9f,
1122 },
1123 },
1124 },
1125 [AB8500_INTERRUPT] = {
1126 .num_ranges = 6,
1127 .range = (struct ab8500_reg_range[]) {
1128 {
1129 .first = 0x00,
1130 .last = 0x05,
1131 },
1132 {
1133 .first = 0x0B,
1134 .last = 0x0D,
1135 },
1136 {
1137 .first = 0x12,
1138 .last = 0x20,
1139 },
1140 /* Latch registers should not be read here */
1141 {
1142 .first = 0x40,
1143 .last = 0x45,
1144 },
1145 {
1146 .first = 0x4B,
1147 .last = 0x4D,
1148 },
1149 {
1150 .first = 0x52,
1151 .last = 0x60,
1152 },
1153 /* LatchHier registers should not be read here */
1154 },
1155 },
1156 [AB8500_RTC] = {
1157 .num_ranges = 3,
1158 .range = (struct ab8500_reg_range[]) {
1159 {
1160 .first = 0x00,
1161 .last = 0x07,
1162 },
1163 {
1164 .first = 0x0B,
1165 .last = 0x18,
1166 },
1167 {
1168 .first = 0x20,
1169 .last = 0x25,
1170 },
1171 },
1172 },
1173 [AB8500_MISC] = {
1174 .num_ranges = 9,
1175 .range = (struct ab8500_reg_range[]) {
1176 {
1177 .first = 0x00,
1178 .last = 0x06,
1179 },
1180 {
1181 .first = 0x10,
1182 .last = 0x16,
1183 },
1184 {
1185 .first = 0x20,
1186 .last = 0x26,
1187 },
1188 {
1189 .first = 0x30,
1190 .last = 0x36,
1191 },
1192 {
1193 .first = 0x40,
1194 .last = 0x49,
1195 },
1196 {
1197 .first = 0x50,
1198 .last = 0x50,
1199 },
1200 {
1201 .first = 0x60,
1202 .last = 0x6B,
1203 },
1204 {
1205 .first = 0x70,
1206 .last = 0x74,
1207 },
1208 {
1209 .first = 0x80,
1210 .last = 0x82,
1211 },
1212 },
1213 },
1214 [AB8500_DEVELOPMENT] = {
1215 .num_ranges = 3,
1216 .range = (struct ab8500_reg_range[]) {
1217 {
1218 .first = 0x00,
1219 .last = 0x01,
1220 },
1221 {
1222 .first = 0x06,
1223 .last = 0x06,
1224 },
1225 {
1226 .first = 0x10,
1227 .last = 0x21,
1228 },
1229 },
1230 },
1231 [AB8500_DEBUG] = {
1232 .num_ranges = 3,
1233 .range = (struct ab8500_reg_range[]) {
1234 {
1235 .first = 0x01,
1236 .last = 0x0C,
1237 },
1238 {
1239 .first = 0x0E,
1240 .last = 0x11,
1241 },
1242 {
1243 .first = 0x80,
1244 .last = 0x81,
1245 },
1246 },
1247 },
1248 [AB8500_PROD_TEST] = {
1249 .num_ranges = 0,
1250 .range = NULL,
1251 },
1252 [AB8500_STE_TEST] = {
1253 .num_ranges = 0,
1254 .range = NULL,
1255 },
1256 [AB8500_OTP_EMUL] = {
1257 .num_ranges = 1,
1258 .range = (struct ab8500_reg_range[]) {
1259 {
1260 .first = 0x00,
1261 .last = 0x3F,
1262 },
1263 },
1264 },
1265};
1266
1267
482static irqreturn_t ab8500_debug_handler(int irq, void *data) 1268static irqreturn_t ab8500_debug_handler(int irq, void *data)
483{ 1269{
484 char buf[16]; 1270 char buf[16];
@@ -520,19 +1306,16 @@ static int ab8500_registers_print(struct device *dev, u32 bank,
520 } 1306 }
521 1307
522 if (s) { 1308 if (s) {
523 err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", 1309 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
524 bank, reg, value); 1310 bank, reg, value);
525 if (err < 0) { 1311 if (err < 0) {
526 dev_err(dev,
527 "seq_printf overflow bank=%d reg=%d\n",
528 bank, reg);
529 /* Error is not returned here since 1312 /* Error is not returned here since
530 * the output is wanted in any case */ 1313 * the output is wanted in any case */
531 return 0; 1314 return 0;
532 } 1315 }
533 } else { 1316 } else {
534 printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank, 1317 printk(KERN_INFO" [0x%02X/0x%02X]: 0x%02X\n",
535 reg, value); 1318 bank, reg, value);
536 } 1319 }
537 } 1320 }
538 } 1321 }
@@ -546,7 +1329,7 @@ static int ab8500_print_bank_registers(struct seq_file *s, void *p)
546 1329
547 seq_printf(s, AB8500_NAME_STRING " register values:\n"); 1330 seq_printf(s, AB8500_NAME_STRING " register values:\n");
548 1331
549 seq_printf(s, " bank %u:\n", bank); 1332 seq_printf(s, " bank 0x%02X:\n", bank);
550 1333
551 ab8500_registers_print(dev, bank, s); 1334 ab8500_registers_print(dev, bank, s);
552 return 0; 1335 return 0;
@@ -573,10 +1356,8 @@ static int ab8500_print_all_banks(struct seq_file *s, void *p)
573 1356
574 seq_printf(s, AB8500_NAME_STRING " register values:\n"); 1357 seq_printf(s, AB8500_NAME_STRING " register values:\n");
575 1358
576 for (i = 1; i < AB8500_NUM_BANKS; i++) { 1359 for (i = 0; i < AB8500_NUM_BANKS; i++) {
577 err = seq_printf(s, " bank %u:\n", i); 1360 err = seq_printf(s, " bank 0x%02X:\n", i);
578 if (err < 0)
579 dev_err(dev, "seq_printf overflow, bank=%d\n", i);
580 1361
581 ab8500_registers_print(dev, i, s); 1362 ab8500_registers_print(dev, i, s);
582 } 1363 }
@@ -591,11 +1372,68 @@ void ab8500_dump_all_banks(struct device *dev)
591 printk(KERN_INFO"ab8500 register values:\n"); 1372 printk(KERN_INFO"ab8500 register values:\n");
592 1373
593 for (i = 1; i < AB8500_NUM_BANKS; i++) { 1374 for (i = 1; i < AB8500_NUM_BANKS; i++) {
594 printk(KERN_INFO" bank %u:\n", i); 1375 printk(KERN_INFO" bank 0x%02X:\n", i);
595 ab8500_registers_print(dev, i, NULL); 1376 ab8500_registers_print(dev, i, NULL);
596 } 1377 }
597} 1378}
598 1379
1380/* Space for 500 registers. */
1381#define DUMP_MAX_REGS 700
1382struct ab8500_register_dump
1383{
1384 u8 bank;
1385 u8 reg;
1386 u8 value;
1387} ab8500_complete_register_dump[DUMP_MAX_REGS];
1388
1389extern int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size);
1390
1391/* This shall only be called upon kernel panic! */
1392void ab8500_dump_all_banks_to_mem(void)
1393{
1394 int i, r = 0;
1395 u8 bank;
1396 int err = 0;
1397
1398 pr_info("Saving all ABB registers at \"ab8500_complete_register_dump\" "
1399 "for crash analyze.\n");
1400
1401 for (bank = 0; bank < AB8500_NUM_BANKS; bank++) {
1402 for (i = 0; i < debug_ranges[bank].num_ranges; i++) {
1403 u8 reg;
1404
1405 for (reg = debug_ranges[bank].range[i].first;
1406 reg <= debug_ranges[bank].range[i].last;
1407 reg++) {
1408 u8 value;
1409
1410 err = prcmu_abb_read(bank, reg, &value, 1);
1411
1412 if (err < 0)
1413 goto out;
1414
1415 ab8500_complete_register_dump[r].bank = bank;
1416 ab8500_complete_register_dump[r].reg = reg;
1417 ab8500_complete_register_dump[r].value = value;
1418
1419 r++;
1420
1421 if (r >= DUMP_MAX_REGS) {
1422 pr_err("%s: too many register to dump!\n",
1423 __func__);
1424 err = -EINVAL;
1425 goto out;
1426 }
1427 }
1428 }
1429 }
1430out:
1431 if (err >= 0)
1432 pr_info("Saved all ABB registers.\n");
1433 else
1434 pr_info("Failed to save all ABB registers.\n");
1435}
1436
599static int ab8500_all_banks_open(struct inode *inode, struct file *file) 1437static int ab8500_all_banks_open(struct inode *inode, struct file *file)
600{ 1438{
601 struct seq_file *s; 1439 struct seq_file *s;
@@ -625,7 +1463,7 @@ static const struct file_operations ab8500_all_banks_fops = {
625 1463
626static int ab8500_bank_print(struct seq_file *s, void *p) 1464static int ab8500_bank_print(struct seq_file *s, void *p)
627{ 1465{
628 return seq_printf(s, "%d\n", debug_bank); 1466 return seq_printf(s, "0x%02X\n", debug_bank);
629} 1467}
630 1468
631static int ab8500_bank_open(struct inode *inode, struct file *file) 1469static int ab8500_bank_open(struct inode *inode, struct file *file)
@@ -641,7 +1479,6 @@ static ssize_t ab8500_bank_write(struct file *file,
641 unsigned long user_bank; 1479 unsigned long user_bank;
642 int err; 1480 int err;
643 1481
644 /* Get userspace string and assure termination */
645 err = kstrtoul_from_user(user_buf, count, 0, &user_bank); 1482 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
646 if (err) 1483 if (err)
647 return err; 1484 return err;
@@ -667,14 +1504,13 @@ static int ab8500_address_open(struct inode *inode, struct file *file)
667} 1504}
668 1505
669static ssize_t ab8500_address_write(struct file *file, 1506static ssize_t ab8500_address_write(struct file *file,
670 const char __user *user_buf, 1507 const char __user *user_buf,
671 size_t count, loff_t *ppos) 1508 size_t count, loff_t *ppos)
672{ 1509{
673 struct device *dev = ((struct seq_file *)(file->private_data))->private; 1510 struct device *dev = ((struct seq_file *)(file->private_data))->private;
674 unsigned long user_address; 1511 unsigned long user_address;
675 int err; 1512 int err;
676 1513
677 /* Get userspace string and assure termination */
678 err = kstrtoul_from_user(user_buf, count, 0, &user_address); 1514 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
679 if (err) 1515 if (err)
680 return err; 1516 return err;
@@ -684,6 +1520,7 @@ static ssize_t ab8500_address_write(struct file *file,
684 return -EINVAL; 1520 return -EINVAL;
685 } 1521 }
686 debug_address = user_address; 1522 debug_address = user_address;
1523
687 return count; 1524 return count;
688} 1525}
689 1526
@@ -711,14 +1548,13 @@ static int ab8500_val_open(struct inode *inode, struct file *file)
711} 1548}
712 1549
713static ssize_t ab8500_val_write(struct file *file, 1550static ssize_t ab8500_val_write(struct file *file,
714 const char __user *user_buf, 1551 const char __user *user_buf,
715 size_t count, loff_t *ppos) 1552 size_t count, loff_t *ppos)
716{ 1553{
717 struct device *dev = ((struct seq_file *)(file->private_data))->private; 1554 struct device *dev = ((struct seq_file *)(file->private_data))->private;
718 unsigned long user_val; 1555 unsigned long user_val;
719 int err; 1556 int err;
720 1557
721 /* Get userspace string and assure termination */
722 err = kstrtoul_from_user(user_buf, count, 0, &user_val); 1558 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
723 if (err) 1559 if (err)
724 return err; 1560 return err;
@@ -741,22 +1577,46 @@ static ssize_t ab8500_val_write(struct file *file,
741 * Interrupt status 1577 * Interrupt status
742 */ 1578 */
743static u32 num_interrupts[AB8500_MAX_NR_IRQS]; 1579static u32 num_interrupts[AB8500_MAX_NR_IRQS];
1580static u32 num_wake_interrupts[AB8500_MAX_NR_IRQS];
744static int num_interrupt_lines; 1581static int num_interrupt_lines;
745 1582
1583bool __attribute__((weak)) suspend_test_wake_cause_interrupt_is_mine(u32 my_int)
1584{
1585 return false;
1586}
1587
746void ab8500_debug_register_interrupt(int line) 1588void ab8500_debug_register_interrupt(int line)
747{ 1589{
748 if (line < num_interrupt_lines) 1590 if (line < num_interrupt_lines) {
749 num_interrupts[line]++; 1591 num_interrupts[line]++;
1592 if (suspend_test_wake_cause_interrupt_is_mine(IRQ_DB8500_AB8500))
1593 num_wake_interrupts[line]++;
1594 }
750} 1595}
751 1596
752static int ab8500_interrupts_print(struct seq_file *s, void *p) 1597static int ab8500_interrupts_print(struct seq_file *s, void *p)
753{ 1598{
754 int line; 1599 int line;
755 1600
756 seq_printf(s, "irq: number of\n"); 1601 seq_printf(s, "name: number: number of: wake:\n");
757 1602
758 for (line = 0; line < num_interrupt_lines; line++) 1603 for (line = 0; line < num_interrupt_lines; line++) {
759 seq_printf(s, "%3i: %6i\n", line, num_interrupts[line]); 1604 struct irq_desc *desc = irq_to_desc(line + irq_first);
1605 struct irqaction *action = desc->action;
1606
1607 seq_printf(s, "%3i: %6i %4i", line,
1608 num_interrupts[line],
1609 num_wake_interrupts[line]);
1610
1611 if (desc && desc->name)
1612 seq_printf(s, "-%-8s", desc->name);
1613 if (action) {
1614 seq_printf(s, " %s", action->name);
1615 while ((action = action->next) != NULL)
1616 seq_printf(s, ", %s", action->name);
1617 }
1618 seq_putc(s, '\n');
1619 }
760 1620
761 return 0; 1621 return 0;
762} 1622}
@@ -801,6 +1661,79 @@ static int ab8500_hwreg_open(struct inode *inode, struct file *file)
801 return single_open(file, ab8500_hwreg_print, inode->i_private); 1661 return single_open(file, ab8500_hwreg_print, inode->i_private);
802} 1662}
803 1663
1664#define AB8500_SUPPLY_CONTROL_CONFIG_1 0x01
1665#define AB8500_SUPPLY_CONTROL_REG 0x00
1666#define AB8500_FIRST_SIM_REG 0x80
1667#define AB8500_LAST_SIM_REG 0x8B
1668#define AB8505_LAST_SIM_REG 0x8C
1669
1670static int ab8500_print_modem_registers(struct seq_file *s, void *p)
1671{
1672 struct device *dev = s->private;
1673 struct ab8500 *ab8500;
1674 int err;
1675 u8 value;
1676 u8 orig_value;
1677 u32 bank = AB8500_REGU_CTRL2;
1678 u32 last_sim_reg = AB8500_LAST_SIM_REG;
1679 u32 reg;
1680
1681 ab8500 = dev_get_drvdata(dev->parent);
1682 dev_warn(dev, "WARNING! This operation can interfer with modem side\n"
1683 "and should only be done with care\n");
1684
1685 err = abx500_get_register_interruptible(dev,
1686 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, &orig_value);
1687 if (err < 0) {
1688 dev_err(dev, "ab->read fail %d\n", err);
1689 return err;
1690 }
1691 /* Config 1 will allow APE side to read SIM registers */
1692 err = abx500_set_register_interruptible(dev,
1693 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG,
1694 AB8500_SUPPLY_CONTROL_CONFIG_1);
1695 if (err < 0) {
1696 dev_err(dev, "ab->write fail %d\n", err);
1697 return err;
1698 }
1699
1700 seq_printf(s, " bank 0x%02X:\n", bank);
1701
1702 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1703 last_sim_reg = AB8505_LAST_SIM_REG;
1704
1705 for (reg = AB8500_FIRST_SIM_REG; reg <= last_sim_reg; reg++) {
1706 err = abx500_get_register_interruptible(dev,
1707 bank, reg, &value);
1708 if (err < 0) {
1709 dev_err(dev, "ab->read fail %d\n", err);
1710 return err;
1711 }
1712 err = seq_printf(s, " [0x%02X/0x%02X]: 0x%02X\n",
1713 bank, reg, value);
1714 }
1715 err = abx500_set_register_interruptible(dev,
1716 AB8500_REGU_CTRL1, AB8500_SUPPLY_CONTROL_REG, orig_value);
1717 if (err < 0) {
1718 dev_err(dev, "ab->write fail %d\n", err);
1719 return err;
1720 }
1721 return 0;
1722}
1723
1724static int ab8500_modem_open(struct inode *inode, struct file *file)
1725{
1726 return single_open(file, ab8500_print_modem_registers, inode->i_private);
1727}
1728
1729static const struct file_operations ab8500_modem_fops = {
1730 .open = ab8500_modem_open,
1731 .read = seq_read,
1732 .llseek = seq_lseek,
1733 .release = single_release,
1734 .owner = THIS_MODULE,
1735};
1736
804static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p) 1737static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
805{ 1738{
806 int bat_ctrl_raw; 1739 int bat_ctrl_raw;
@@ -808,12 +1741,13 @@ static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
808 struct ab8500_gpadc *gpadc; 1741 struct ab8500_gpadc *gpadc;
809 1742
810 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1743 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
811 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL); 1744 bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL,
1745 avg_sample, trig_edge, trig_timer, conv_type);
812 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1746 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
813 BAT_CTRL, bat_ctrl_raw); 1747 BAT_CTRL, bat_ctrl_raw);
814 1748
815 return seq_printf(s, "%d,0x%X\n", 1749 return seq_printf(s, "%d,0x%X\n",
816 bat_ctrl_convert, bat_ctrl_raw); 1750 bat_ctrl_convert, bat_ctrl_raw);
817} 1751}
818 1752
819static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file) 1753static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
@@ -836,16 +1770,17 @@ static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
836 struct ab8500_gpadc *gpadc; 1770 struct ab8500_gpadc *gpadc;
837 1771
838 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1772 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
839 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL); 1773 btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL,
1774 avg_sample, trig_edge, trig_timer, conv_type);
840 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL, 1775 btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
841 btemp_ball_raw); 1776 btemp_ball_raw);
842 1777
843 return seq_printf(s, 1778 return seq_printf(s,
844 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw); 1779 "%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
845} 1780}
846 1781
847static int ab8500_gpadc_btemp_ball_open(struct inode *inode, 1782static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
848 struct file *file) 1783 struct file *file)
849{ 1784{
850 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private); 1785 return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
851} 1786}
@@ -865,19 +1800,20 @@ static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
865 struct ab8500_gpadc *gpadc; 1800 struct ab8500_gpadc *gpadc;
866 1801
867 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1802 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
868 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V); 1803 main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V,
1804 avg_sample, trig_edge, trig_timer, conv_type);
869 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1805 main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
870 MAIN_CHARGER_V, main_charger_v_raw); 1806 MAIN_CHARGER_V, main_charger_v_raw);
871 1807
872 return seq_printf(s, "%d,0x%X\n", 1808 return seq_printf(s, "%d,0x%X\n",
873 main_charger_v_convert, main_charger_v_raw); 1809 main_charger_v_convert, main_charger_v_raw);
874} 1810}
875 1811
876static int ab8500_gpadc_main_charger_v_open(struct inode *inode, 1812static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
877 struct file *file) 1813 struct file *file)
878{ 1814{
879 return single_open(file, ab8500_gpadc_main_charger_v_print, 1815 return single_open(file, ab8500_gpadc_main_charger_v_print,
880 inode->i_private); 1816 inode->i_private);
881} 1817}
882 1818
883static const struct file_operations ab8500_gpadc_main_charger_v_fops = { 1819static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
@@ -895,19 +1831,20 @@ static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
895 struct ab8500_gpadc *gpadc; 1831 struct ab8500_gpadc *gpadc;
896 1832
897 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1833 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
898 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1); 1834 acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1,
1835 avg_sample, trig_edge, trig_timer, conv_type);
899 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1, 1836 acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
900 acc_detect1_raw); 1837 acc_detect1_raw);
901 1838
902 return seq_printf(s, "%d,0x%X\n", 1839 return seq_printf(s, "%d,0x%X\n",
903 acc_detect1_convert, acc_detect1_raw); 1840 acc_detect1_convert, acc_detect1_raw);
904} 1841}
905 1842
906static int ab8500_gpadc_acc_detect1_open(struct inode *inode, 1843static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
907 struct file *file) 1844 struct file *file)
908{ 1845{
909 return single_open(file, ab8500_gpadc_acc_detect1_print, 1846 return single_open(file, ab8500_gpadc_acc_detect1_print,
910 inode->i_private); 1847 inode->i_private);
911} 1848}
912 1849
913static const struct file_operations ab8500_gpadc_acc_detect1_fops = { 1850static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
@@ -925,19 +1862,20 @@ static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
925 struct ab8500_gpadc *gpadc; 1862 struct ab8500_gpadc *gpadc;
926 1863
927 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1864 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
928 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2); 1865 acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2,
1866 avg_sample, trig_edge, trig_timer, conv_type);
929 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc, 1867 acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
930 ACC_DETECT2, acc_detect2_raw); 1868 ACC_DETECT2, acc_detect2_raw);
931 1869
932 return seq_printf(s, "%d,0x%X\n", 1870 return seq_printf(s, "%d,0x%X\n",
933 acc_detect2_convert, acc_detect2_raw); 1871 acc_detect2_convert, acc_detect2_raw);
934} 1872}
935 1873
936static int ab8500_gpadc_acc_detect2_open(struct inode *inode, 1874static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
937 struct file *file) 1875 struct file *file)
938{ 1876{
939 return single_open(file, ab8500_gpadc_acc_detect2_print, 1877 return single_open(file, ab8500_gpadc_acc_detect2_print,
940 inode->i_private); 1878 inode->i_private);
941} 1879}
942 1880
943static const struct file_operations ab8500_gpadc_acc_detect2_fops = { 1881static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
@@ -955,12 +1893,13 @@ static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
955 struct ab8500_gpadc *gpadc; 1893 struct ab8500_gpadc *gpadc;
956 1894
957 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1895 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
958 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1); 1896 aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1,
1897 avg_sample, trig_edge, trig_timer, conv_type);
959 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1, 1898 aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
960 aux1_raw); 1899 aux1_raw);
961 1900
962 return seq_printf(s, "%d,0x%X\n", 1901 return seq_printf(s, "%d,0x%X\n",
963 aux1_convert, aux1_raw); 1902 aux1_convert, aux1_raw);
964} 1903}
965 1904
966static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file) 1905static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
@@ -983,9 +1922,10 @@ static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
983 struct ab8500_gpadc *gpadc; 1922 struct ab8500_gpadc *gpadc;
984 1923
985 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1924 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
986 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2); 1925 aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2,
1926 avg_sample, trig_edge, trig_timer, conv_type);
987 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2, 1927 aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
988 aux2_raw); 1928 aux2_raw);
989 1929
990 return seq_printf(s, "%d,0x%X\n", 1930 return seq_printf(s, "%d,0x%X\n",
991 aux2_convert, aux2_raw); 1931 aux2_convert, aux2_raw);
@@ -1011,16 +1951,17 @@ static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
1011 struct ab8500_gpadc *gpadc; 1951 struct ab8500_gpadc *gpadc;
1012 1952
1013 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1953 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1014 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V); 1954 main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V,
1955 avg_sample, trig_edge, trig_timer, conv_type);
1015 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V, 1956 main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
1016 main_bat_v_raw); 1957 main_bat_v_raw);
1017 1958
1018 return seq_printf(s, "%d,0x%X\n", 1959 return seq_printf(s, "%d,0x%X\n",
1019 main_bat_v_convert, main_bat_v_raw); 1960 main_bat_v_convert, main_bat_v_raw);
1020} 1961}
1021 1962
1022static int ab8500_gpadc_main_bat_v_open(struct inode *inode, 1963static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
1023 struct file *file) 1964 struct file *file)
1024{ 1965{
1025 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private); 1966 return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
1026} 1967}
@@ -1040,12 +1981,13 @@ static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
1040 struct ab8500_gpadc *gpadc; 1981 struct ab8500_gpadc *gpadc;
1041 1982
1042 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 1983 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1043 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V); 1984 vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V,
1985 avg_sample, trig_edge, trig_timer, conv_type);
1044 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V, 1986 vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
1045 vbus_v_raw); 1987 vbus_v_raw);
1046 1988
1047 return seq_printf(s, "%d,0x%X\n", 1989 return seq_printf(s, "%d,0x%X\n",
1048 vbus_v_convert, vbus_v_raw); 1990 vbus_v_convert, vbus_v_raw);
1049} 1991}
1050 1992
1051static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file) 1993static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
@@ -1068,19 +2010,20 @@ static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
1068 struct ab8500_gpadc *gpadc; 2010 struct ab8500_gpadc *gpadc;
1069 2011
1070 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2012 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1071 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C); 2013 main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C,
2014 avg_sample, trig_edge, trig_timer, conv_type);
1072 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2015 main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1073 MAIN_CHARGER_C, main_charger_c_raw); 2016 MAIN_CHARGER_C, main_charger_c_raw);
1074 2017
1075 return seq_printf(s, "%d,0x%X\n", 2018 return seq_printf(s, "%d,0x%X\n",
1076 main_charger_c_convert, main_charger_c_raw); 2019 main_charger_c_convert, main_charger_c_raw);
1077} 2020}
1078 2021
1079static int ab8500_gpadc_main_charger_c_open(struct inode *inode, 2022static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
1080 struct file *file) 2023 struct file *file)
1081{ 2024{
1082 return single_open(file, ab8500_gpadc_main_charger_c_print, 2025 return single_open(file, ab8500_gpadc_main_charger_c_print,
1083 inode->i_private); 2026 inode->i_private);
1084} 2027}
1085 2028
1086static const struct file_operations ab8500_gpadc_main_charger_c_fops = { 2029static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
@@ -1098,19 +2041,20 @@ static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
1098 struct ab8500_gpadc *gpadc; 2041 struct ab8500_gpadc *gpadc;
1099 2042
1100 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2043 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1101 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C); 2044 usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C,
2045 avg_sample, trig_edge, trig_timer, conv_type);
1102 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2046 usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1103 USB_CHARGER_C, usb_charger_c_raw); 2047 USB_CHARGER_C, usb_charger_c_raw);
1104 2048
1105 return seq_printf(s, "%d,0x%X\n", 2049 return seq_printf(s, "%d,0x%X\n",
1106 usb_charger_c_convert, usb_charger_c_raw); 2050 usb_charger_c_convert, usb_charger_c_raw);
1107} 2051}
1108 2052
1109static int ab8500_gpadc_usb_charger_c_open(struct inode *inode, 2053static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
1110 struct file *file) 2054 struct file *file)
1111{ 2055{
1112 return single_open(file, ab8500_gpadc_usb_charger_c_print, 2056 return single_open(file, ab8500_gpadc_usb_charger_c_print,
1113 inode->i_private); 2057 inode->i_private);
1114} 2058}
1115 2059
1116static const struct file_operations ab8500_gpadc_usb_charger_c_fops = { 2060static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
@@ -1128,12 +2072,13 @@ static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
1128 struct ab8500_gpadc *gpadc; 2072 struct ab8500_gpadc *gpadc;
1129 2073
1130 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2074 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1131 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V); 2075 bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V,
2076 avg_sample, trig_edge, trig_timer, conv_type);
1132 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, 2077 bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
1133 BK_BAT_V, bk_bat_v_raw); 2078 BK_BAT_V, bk_bat_v_raw);
1134 2079
1135 return seq_printf(s, "%d,0x%X\n", 2080 return seq_printf(s, "%d,0x%X\n",
1136 bk_bat_v_convert, bk_bat_v_raw); 2081 bk_bat_v_convert, bk_bat_v_raw);
1137} 2082}
1138 2083
1139static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file) 2084static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
@@ -1156,12 +2101,13 @@ static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
1156 struct ab8500_gpadc *gpadc; 2101 struct ab8500_gpadc *gpadc;
1157 2102
1158 gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); 2103 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
1159 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP); 2104 die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP,
2105 avg_sample, trig_edge, trig_timer, conv_type);
1160 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP, 2106 die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
1161 die_temp_raw); 2107 die_temp_raw);
1162 2108
1163 return seq_printf(s, "%d,0x%X\n", 2109 return seq_printf(s, "%d,0x%X\n",
1164 die_temp_convert, die_temp_raw); 2110 die_temp_convert, die_temp_raw);
1165} 2111}
1166 2112
1167static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file) 2113static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
@@ -1177,6 +2123,453 @@ static const struct file_operations ab8500_gpadc_die_temp_fops = {
1177 .owner = THIS_MODULE, 2123 .owner = THIS_MODULE,
1178}; 2124};
1179 2125
2126static int ab8500_gpadc_usb_id_print(struct seq_file *s, void *p)
2127{
2128 int usb_id_raw;
2129 int usb_id_convert;
2130 struct ab8500_gpadc *gpadc;
2131
2132 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2133 usb_id_raw = ab8500_gpadc_read_raw(gpadc, USB_ID,
2134 avg_sample, trig_edge, trig_timer, conv_type);
2135 usb_id_convert = ab8500_gpadc_ad_to_voltage(gpadc, USB_ID,
2136 usb_id_raw);
2137
2138 return seq_printf(s, "%d,0x%X\n",
2139 usb_id_convert, usb_id_raw);
2140}
2141
2142static int ab8500_gpadc_usb_id_open(struct inode *inode, struct file *file)
2143{
2144 return single_open(file, ab8500_gpadc_usb_id_print, inode->i_private);
2145}
2146
2147static const struct file_operations ab8500_gpadc_usb_id_fops = {
2148 .open = ab8500_gpadc_usb_id_open,
2149 .read = seq_read,
2150 .llseek = seq_lseek,
2151 .release = single_release,
2152 .owner = THIS_MODULE,
2153};
2154
2155static int ab8540_gpadc_xtal_temp_print(struct seq_file *s, void *p)
2156{
2157 int xtal_temp_raw;
2158 int xtal_temp_convert;
2159 struct ab8500_gpadc *gpadc;
2160
2161 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2162 xtal_temp_raw = ab8500_gpadc_read_raw(gpadc, XTAL_TEMP,
2163 avg_sample, trig_edge, trig_timer, conv_type);
2164 xtal_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, XTAL_TEMP,
2165 xtal_temp_raw);
2166
2167 return seq_printf(s, "%d,0x%X\n",
2168 xtal_temp_convert, xtal_temp_raw);
2169}
2170
2171static int ab8540_gpadc_xtal_temp_open(struct inode *inode, struct file *file)
2172{
2173 return single_open(file, ab8540_gpadc_xtal_temp_print,
2174 inode->i_private);
2175}
2176
2177static const struct file_operations ab8540_gpadc_xtal_temp_fops = {
2178 .open = ab8540_gpadc_xtal_temp_open,
2179 .read = seq_read,
2180 .llseek = seq_lseek,
2181 .release = single_release,
2182 .owner = THIS_MODULE,
2183};
2184
2185static int ab8540_gpadc_vbat_true_meas_print(struct seq_file *s, void *p)
2186{
2187 int vbat_true_meas_raw;
2188 int vbat_true_meas_convert;
2189 struct ab8500_gpadc *gpadc;
2190
2191 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2192 vbat_true_meas_raw = ab8500_gpadc_read_raw(gpadc, VBAT_TRUE_MEAS,
2193 avg_sample, trig_edge, trig_timer, conv_type);
2194 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBAT_TRUE_MEAS,
2195 vbat_true_meas_raw);
2196
2197 return seq_printf(s, "%d,0x%X\n",
2198 vbat_true_meas_convert, vbat_true_meas_raw);
2199}
2200
2201static int ab8540_gpadc_vbat_true_meas_open(struct inode *inode,
2202 struct file *file)
2203{
2204 return single_open(file, ab8540_gpadc_vbat_true_meas_print,
2205 inode->i_private);
2206}
2207
2208static const struct file_operations ab8540_gpadc_vbat_true_meas_fops = {
2209 .open = ab8540_gpadc_vbat_true_meas_open,
2210 .read = seq_read,
2211 .llseek = seq_lseek,
2212 .release = single_release,
2213 .owner = THIS_MODULE,
2214};
2215
2216static int ab8540_gpadc_bat_ctrl_and_ibat_print(struct seq_file *s, void *p)
2217{
2218 int bat_ctrl_raw;
2219 int bat_ctrl_convert;
2220 int ibat_raw;
2221 int ibat_convert;
2222 struct ab8500_gpadc *gpadc;
2223
2224 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2225 bat_ctrl_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_CTRL_AND_IBAT,
2226 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2227
2228 bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc, BAT_CTRL,
2229 bat_ctrl_raw);
2230 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2231 ibat_raw);
2232
2233 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2234 bat_ctrl_convert, bat_ctrl_raw,
2235 ibat_convert, ibat_raw);
2236}
2237
2238static int ab8540_gpadc_bat_ctrl_and_ibat_open(struct inode *inode,
2239 struct file *file)
2240{
2241 return single_open(file, ab8540_gpadc_bat_ctrl_and_ibat_print,
2242 inode->i_private);
2243}
2244
2245static const struct file_operations ab8540_gpadc_bat_ctrl_and_ibat_fops = {
2246 .open = ab8540_gpadc_bat_ctrl_and_ibat_open,
2247 .read = seq_read,
2248 .llseek = seq_lseek,
2249 .release = single_release,
2250 .owner = THIS_MODULE,
2251};
2252
2253static int ab8540_gpadc_vbat_meas_and_ibat_print(struct seq_file *s, void *p)
2254{
2255 int vbat_meas_raw;
2256 int vbat_meas_convert;
2257 int ibat_raw;
2258 int ibat_convert;
2259 struct ab8500_gpadc *gpadc;
2260
2261 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2262 vbat_meas_raw = ab8500_gpadc_double_read_raw(gpadc, VBAT_MEAS_AND_IBAT,
2263 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2264 vbat_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
2265 vbat_meas_raw);
2266 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2267 ibat_raw);
2268
2269 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2270 vbat_meas_convert, vbat_meas_raw,
2271 ibat_convert, ibat_raw);
2272}
2273
2274static int ab8540_gpadc_vbat_meas_and_ibat_open(struct inode *inode,
2275 struct file *file)
2276{
2277 return single_open(file, ab8540_gpadc_vbat_meas_and_ibat_print,
2278 inode->i_private);
2279}
2280
2281static const struct file_operations ab8540_gpadc_vbat_meas_and_ibat_fops = {
2282 .open = ab8540_gpadc_vbat_meas_and_ibat_open,
2283 .read = seq_read,
2284 .llseek = seq_lseek,
2285 .release = single_release,
2286 .owner = THIS_MODULE,
2287};
2288
2289static int ab8540_gpadc_vbat_true_meas_and_ibat_print(struct seq_file *s, void *p)
2290{
2291 int vbat_true_meas_raw;
2292 int vbat_true_meas_convert;
2293 int ibat_raw;
2294 int ibat_convert;
2295 struct ab8500_gpadc *gpadc;
2296
2297 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2298 vbat_true_meas_raw = ab8500_gpadc_double_read_raw(gpadc,
2299 VBAT_TRUE_MEAS_AND_IBAT, avg_sample, trig_edge,
2300 trig_timer, conv_type, &ibat_raw);
2301 vbat_true_meas_convert = ab8500_gpadc_ad_to_voltage(gpadc,
2302 VBAT_TRUE_MEAS, vbat_true_meas_raw);
2303 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2304 ibat_raw);
2305
2306 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2307 vbat_true_meas_convert, vbat_true_meas_raw,
2308 ibat_convert, ibat_raw);
2309}
2310
2311static int ab8540_gpadc_vbat_true_meas_and_ibat_open(struct inode *inode,
2312 struct file *file)
2313{
2314 return single_open(file, ab8540_gpadc_vbat_true_meas_and_ibat_print,
2315 inode->i_private);
2316}
2317
2318static const struct file_operations ab8540_gpadc_vbat_true_meas_and_ibat_fops = {
2319 .open = ab8540_gpadc_vbat_true_meas_and_ibat_open,
2320 .read = seq_read,
2321 .llseek = seq_lseek,
2322 .release = single_release,
2323 .owner = THIS_MODULE,
2324};
2325
2326static int ab8540_gpadc_bat_temp_and_ibat_print(struct seq_file *s, void *p)
2327{
2328 int bat_temp_raw;
2329 int bat_temp_convert;
2330 int ibat_raw;
2331 int ibat_convert;
2332 struct ab8500_gpadc *gpadc;
2333
2334 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2335 bat_temp_raw = ab8500_gpadc_double_read_raw(gpadc, BAT_TEMP_AND_IBAT,
2336 avg_sample, trig_edge, trig_timer, conv_type, &ibat_raw);
2337 bat_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
2338 bat_temp_raw);
2339 ibat_convert = ab8500_gpadc_ad_to_voltage(gpadc, IBAT_VIRTUAL_CHANNEL,
2340 ibat_raw);
2341
2342 return seq_printf(s, "%d,0x%X\n" "%d,0x%X\n",
2343 bat_temp_convert, bat_temp_raw,
2344 ibat_convert, ibat_raw);
2345}
2346
2347static int ab8540_gpadc_bat_temp_and_ibat_open(struct inode *inode,
2348 struct file *file)
2349{
2350 return single_open(file, ab8540_gpadc_bat_temp_and_ibat_print,
2351 inode->i_private);
2352}
2353
2354static const struct file_operations ab8540_gpadc_bat_temp_and_ibat_fops = {
2355 .open = ab8540_gpadc_bat_temp_and_ibat_open,
2356 .read = seq_read,
2357 .llseek = seq_lseek,
2358 .release = single_release,
2359 .owner = THIS_MODULE,
2360};
2361
2362static int ab8540_gpadc_otp_cal_print(struct seq_file *s, void *p)
2363{
2364 struct ab8500_gpadc *gpadc;
2365 u16 vmain_l, vmain_h, btemp_l, btemp_h;
2366 u16 vbat_l, vbat_h, ibat_l, ibat_h;
2367
2368 gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
2369 ab8540_gpadc_get_otp(gpadc, &vmain_l, &vmain_h, &btemp_l, &btemp_h,
2370 &vbat_l, &vbat_h, &ibat_l, &ibat_h);
2371 return seq_printf(s, "VMAIN_L:0x%X\n"
2372 "VMAIN_H:0x%X\n"
2373 "BTEMP_L:0x%X\n"
2374 "BTEMP_H:0x%X\n"
2375 "VBAT_L:0x%X\n"
2376 "VBAT_H:0x%X\n"
2377 "IBAT_L:0x%X\n"
2378 "IBAT_H:0x%X\n",
2379 vmain_l, vmain_h, btemp_l, btemp_h, vbat_l, vbat_h, ibat_l, ibat_h);
2380}
2381
2382static int ab8540_gpadc_otp_cal_open(struct inode *inode, struct file *file)
2383{
2384 return single_open(file, ab8540_gpadc_otp_cal_print, inode->i_private);
2385}
2386
2387static const struct file_operations ab8540_gpadc_otp_calib_fops = {
2388 .open = ab8540_gpadc_otp_cal_open,
2389 .read = seq_read,
2390 .llseek = seq_lseek,
2391 .release = single_release,
2392 .owner = THIS_MODULE,
2393};
2394
2395static int ab8500_gpadc_avg_sample_print(struct seq_file *s, void *p)
2396{
2397 return seq_printf(s, "%d\n", avg_sample);
2398}
2399
2400static int ab8500_gpadc_avg_sample_open(struct inode *inode, struct file *file)
2401{
2402 return single_open(file, ab8500_gpadc_avg_sample_print,
2403 inode->i_private);
2404}
2405
2406static ssize_t ab8500_gpadc_avg_sample_write(struct file *file,
2407 const char __user *user_buf,
2408 size_t count, loff_t *ppos)
2409{
2410 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2411 unsigned long user_avg_sample;
2412 int err;
2413
2414 err = kstrtoul_from_user(user_buf, count, 0, &user_avg_sample);
2415 if (err)
2416 return err;
2417
2418 if ((user_avg_sample == SAMPLE_1) || (user_avg_sample == SAMPLE_4)
2419 || (user_avg_sample == SAMPLE_8)
2420 || (user_avg_sample == SAMPLE_16)) {
2421 avg_sample = (u8) user_avg_sample;
2422 } else {
2423 dev_err(dev, "debugfs error input: "
2424 "should be egal to 1, 4, 8 or 16\n");
2425 return -EINVAL;
2426 }
2427
2428 return count;
2429}
2430
2431static const struct file_operations ab8500_gpadc_avg_sample_fops = {
2432 .open = ab8500_gpadc_avg_sample_open,
2433 .read = seq_read,
2434 .write = ab8500_gpadc_avg_sample_write,
2435 .llseek = seq_lseek,
2436 .release = single_release,
2437 .owner = THIS_MODULE,
2438};
2439
2440static int ab8500_gpadc_trig_edge_print(struct seq_file *s, void *p)
2441{
2442 return seq_printf(s, "%d\n", trig_edge);
2443}
2444
2445static int ab8500_gpadc_trig_edge_open(struct inode *inode, struct file *file)
2446{
2447 return single_open(file, ab8500_gpadc_trig_edge_print,
2448 inode->i_private);
2449}
2450
2451static ssize_t ab8500_gpadc_trig_edge_write(struct file *file,
2452 const char __user *user_buf,
2453 size_t count, loff_t *ppos)
2454{
2455 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2456 unsigned long user_trig_edge;
2457 int err;
2458
2459 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_edge);
2460 if (err)
2461 return err;
2462
2463 if ((user_trig_edge == RISING_EDGE)
2464 || (user_trig_edge == FALLING_EDGE)) {
2465 trig_edge = (u8) user_trig_edge;
2466 } else {
2467 dev_err(dev, "Wrong input:\n"
2468 "Enter 0. Rising edge\n"
2469 "Enter 1. Falling edge\n");
2470 return -EINVAL;
2471 }
2472
2473 return count;
2474}
2475
2476static const struct file_operations ab8500_gpadc_trig_edge_fops = {
2477 .open = ab8500_gpadc_trig_edge_open,
2478 .read = seq_read,
2479 .write = ab8500_gpadc_trig_edge_write,
2480 .llseek = seq_lseek,
2481 .release = single_release,
2482 .owner = THIS_MODULE,
2483};
2484
2485static int ab8500_gpadc_trig_timer_print(struct seq_file *s, void *p)
2486{
2487 return seq_printf(s, "%d\n", trig_timer);
2488}
2489
2490static int ab8500_gpadc_trig_timer_open(struct inode *inode, struct file *file)
2491{
2492 return single_open(file, ab8500_gpadc_trig_timer_print,
2493 inode->i_private);
2494}
2495
2496static ssize_t ab8500_gpadc_trig_timer_write(struct file *file,
2497 const char __user *user_buf,
2498 size_t count, loff_t *ppos)
2499{
2500 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2501 unsigned long user_trig_timer;
2502 int err;
2503
2504 err = kstrtoul_from_user(user_buf, count, 0, &user_trig_timer);
2505 if (err)
2506 return err;
2507
2508 if ((user_trig_timer >= 0) && (user_trig_timer <= 255)) {
2509 trig_timer = (u8) user_trig_timer;
2510 } else {
2511 dev_err(dev, "debugfs error input: "
2512 "should be beetween 0 to 255\n");
2513 return -EINVAL;
2514 }
2515
2516 return count;
2517}
2518
2519static const struct file_operations ab8500_gpadc_trig_timer_fops = {
2520 .open = ab8500_gpadc_trig_timer_open,
2521 .read = seq_read,
2522 .write = ab8500_gpadc_trig_timer_write,
2523 .llseek = seq_lseek,
2524 .release = single_release,
2525 .owner = THIS_MODULE,
2526};
2527
2528static int ab8500_gpadc_conv_type_print(struct seq_file *s, void *p)
2529{
2530 return seq_printf(s, "%d\n", conv_type);
2531}
2532
2533static int ab8500_gpadc_conv_type_open(struct inode *inode, struct file *file)
2534{
2535 return single_open(file, ab8500_gpadc_conv_type_print,
2536 inode->i_private);
2537}
2538
2539static ssize_t ab8500_gpadc_conv_type_write(struct file *file,
2540 const char __user *user_buf,
2541 size_t count, loff_t *ppos)
2542{
2543 struct device *dev = ((struct seq_file *)(file->private_data))->private;
2544 unsigned long user_conv_type;
2545 int err;
2546
2547 err = kstrtoul_from_user(user_buf, count, 0, &user_conv_type);
2548 if (err)
2549 return err;
2550
2551 if ((user_conv_type == ADC_SW)
2552 || (user_conv_type == ADC_HW)) {
2553 conv_type = (u8) user_conv_type;
2554 } else {
2555 dev_err(dev, "Wrong input:\n"
2556 "Enter 0. ADC SW conversion\n"
2557 "Enter 1. ADC HW conversion\n");
2558 return -EINVAL;
2559 }
2560
2561 return count;
2562}
2563
2564static const struct file_operations ab8500_gpadc_conv_type_fops = {
2565 .open = ab8500_gpadc_conv_type_open,
2566 .read = seq_read,
2567 .write = ab8500_gpadc_conv_type_write,
2568 .llseek = seq_lseek,
2569 .release = single_release,
2570 .owner = THIS_MODULE,
2571};
2572
1180/* 2573/*
1181 * return length of an ASCII numerical value, 0 is string is not a 2574 * return length of an ASCII numerical value, 0 is string is not a
1182 * numerical value. 2575 * numerical value.
@@ -1352,7 +2745,7 @@ static int ab8500_subscribe_unsubscribe_open(struct inode *inode,
1352 struct file *file) 2745 struct file *file)
1353{ 2746{
1354 return single_open(file, ab8500_subscribe_unsubscribe_print, 2747 return single_open(file, ab8500_subscribe_unsubscribe_print,
1355 inode->i_private); 2748 inode->i_private);
1356} 2749}
1357 2750
1358/* 2751/*
@@ -1382,21 +2775,14 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1382 size_t count, loff_t *ppos) 2775 size_t count, loff_t *ppos)
1383{ 2776{
1384 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2777 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1385 char buf[32];
1386 int buf_size;
1387 unsigned long user_val; 2778 unsigned long user_val;
1388 int err; 2779 int err;
1389 unsigned int irq_index; 2780 unsigned int irq_index;
1390 2781
1391 /* Get userspace string and assure termination */ 2782 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1392 buf_size = min(count, (sizeof(buf)-1));
1393 if (copy_from_user(buf, user_buf, buf_size))
1394 return -EFAULT;
1395 buf[buf_size] = 0;
1396
1397 err = strict_strtoul(buf, 0, &user_val);
1398 if (err) 2783 if (err)
1399 return -EINVAL; 2784 return err;
2785
1400 if (user_val < irq_first) { 2786 if (user_val < irq_first) {
1401 dev_err(dev, "debugfs error input < %d\n", irq_first); 2787 dev_err(dev, "debugfs error input < %d\n", irq_first);
1402 return -EINVAL; 2788 return -EINVAL;
@@ -1416,7 +2802,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1416 */ 2802 */
1417 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute), 2803 dev_attr[irq_index] = kmalloc(sizeof(struct device_attribute),
1418 GFP_KERNEL); 2804 GFP_KERNEL);
1419 event_name[irq_index] = kmalloc(buf_size, GFP_KERNEL); 2805 event_name[irq_index] = kmalloc(count, GFP_KERNEL);
1420 sprintf(event_name[irq_index], "%lu", user_val); 2806 sprintf(event_name[irq_index], "%lu", user_val);
1421 dev_attr[irq_index]->show = show_irq; 2807 dev_attr[irq_index]->show = show_irq;
1422 dev_attr[irq_index]->store = NULL; 2808 dev_attr[irq_index]->store = NULL;
@@ -1438,7 +2824,7 @@ static ssize_t ab8500_subscribe_write(struct file *file,
1438 return err; 2824 return err;
1439 } 2825 }
1440 2826
1441 return buf_size; 2827 return count;
1442} 2828}
1443 2829
1444static ssize_t ab8500_unsubscribe_write(struct file *file, 2830static ssize_t ab8500_unsubscribe_write(struct file *file,
@@ -1446,21 +2832,14 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
1446 size_t count, loff_t *ppos) 2832 size_t count, loff_t *ppos)
1447{ 2833{
1448 struct device *dev = ((struct seq_file *)(file->private_data))->private; 2834 struct device *dev = ((struct seq_file *)(file->private_data))->private;
1449 char buf[32];
1450 int buf_size;
1451 unsigned long user_val; 2835 unsigned long user_val;
1452 int err; 2836 int err;
1453 unsigned int irq_index; 2837 unsigned int irq_index;
1454 2838
1455 /* Get userspace string and assure termination */ 2839 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
1456 buf_size = min(count, (sizeof(buf)-1));
1457 if (copy_from_user(buf, user_buf, buf_size))
1458 return -EFAULT;
1459 buf[buf_size] = 0;
1460
1461 err = strict_strtoul(buf, 0, &user_val);
1462 if (err) 2840 if (err)
1463 return -EINVAL; 2841 return err;
2842
1464 if (user_val < irq_first) { 2843 if (user_val < irq_first) {
1465 dev_err(dev, "debugfs error input < %d\n", irq_first); 2844 dev_err(dev, "debugfs error input < %d\n", irq_first);
1466 return -EINVAL; 2845 return -EINVAL;
@@ -1485,7 +2864,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file,
1485 kfree(event_name[irq_index]); 2864 kfree(event_name[irq_index]);
1486 kfree(dev_attr[irq_index]); 2865 kfree(dev_attr[irq_index]);
1487 2866
1488 return buf_size; 2867 return count;
1489} 2868}
1490 2869
1491/* 2870/*
@@ -1583,7 +2962,7 @@ static int ab8500_debug_probe(struct platform_device *plf)
1583 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); 2962 irq_first = platform_get_irq_byname(plf, "IRQ_FIRST");
1584 if (irq_first < 0) { 2963 if (irq_first < 0) {
1585 dev_err(&plf->dev, "First irq not found, err %d\n", 2964 dev_err(&plf->dev, "First irq not found, err %d\n",
1586 irq_first); 2965 irq_first);
1587 ret = irq_first; 2966 ret = irq_first;
1588 goto out_freeevent_name; 2967 goto out_freeevent_name;
1589 } 2968 }
@@ -1591,9 +2970,9 @@ static int ab8500_debug_probe(struct platform_device *plf)
1591 irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); 2970 irq_last = platform_get_irq_byname(plf, "IRQ_LAST");
1592 if (irq_last < 0) { 2971 if (irq_last < 0) {
1593 dev_err(&plf->dev, "Last irq not found, err %d\n", 2972 dev_err(&plf->dev, "Last irq not found, err %d\n",
1594 irq_last); 2973 irq_last);
1595 ret = irq_last; 2974 ret = irq_last;
1596 goto out_freeevent_name; 2975 goto out_freeevent_name;
1597 } 2976 }
1598 2977
1599 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); 2978 ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL);
@@ -1601,124 +2980,198 @@ static int ab8500_debug_probe(struct platform_device *plf)
1601 goto err; 2980 goto err;
1602 2981
1603 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING, 2982 ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
1604 ab8500_dir); 2983 ab8500_dir);
1605 if (!ab8500_gpadc_dir) 2984 if (!ab8500_gpadc_dir)
1606 goto err; 2985 goto err;
1607 2986
1608 file = debugfs_create_file("all-bank-registers", S_IRUGO, 2987 file = debugfs_create_file("all-bank-registers", S_IRUGO,
1609 ab8500_dir, &plf->dev, &ab8500_registers_fops); 2988 ab8500_dir, &plf->dev, &ab8500_registers_fops);
1610 if (!file) 2989 if (!file)
1611 goto err; 2990 goto err;
1612 2991
1613 file = debugfs_create_file("all-banks", S_IRUGO, 2992 file = debugfs_create_file("all-banks", S_IRUGO,
1614 ab8500_dir, &plf->dev, &ab8500_all_banks_fops); 2993 ab8500_dir, &plf->dev, &ab8500_all_banks_fops);
1615 if (!file) 2994 if (!file)
1616 goto err; 2995 goto err;
1617 2996
1618 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), 2997 file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR | S_IWGRP),
1619 ab8500_dir, &plf->dev, &ab8500_bank_fops); 2998 ab8500_dir, &plf->dev, &ab8500_bank_fops);
1620 if (!file) 2999 if (!file)
1621 goto err; 3000 goto err;
1622 3001
1623 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR), 3002 file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR | S_IWGRP),
1624 ab8500_dir, &plf->dev, &ab8500_address_fops); 3003 ab8500_dir, &plf->dev, &ab8500_address_fops);
1625 if (!file) 3004 if (!file)
1626 goto err; 3005 goto err;
1627 3006
1628 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR), 3007 file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR | S_IWGRP),
1629 ab8500_dir, &plf->dev, &ab8500_val_fops); 3008 ab8500_dir, &plf->dev, &ab8500_val_fops);
1630 if (!file) 3009 if (!file)
1631 goto err; 3010 goto err;
1632 3011
1633 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR), 3012 file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
1634 ab8500_dir, &plf->dev, &ab8500_subscribe_fops); 3013 ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
1635 if (!file) 3014 if (!file)
1636 goto err; 3015 goto err;
1637 3016
1638 if (is_ab8500(ab8500)) 3017 if (is_ab8500(ab8500)) {
3018 debug_ranges = ab8500_debug_ranges;
1639 num_interrupt_lines = AB8500_NR_IRQS; 3019 num_interrupt_lines = AB8500_NR_IRQS;
1640 else if (is_ab8505(ab8500)) 3020 } else if (is_ab8505(ab8500)) {
3021 debug_ranges = ab8505_debug_ranges;
1641 num_interrupt_lines = AB8505_NR_IRQS; 3022 num_interrupt_lines = AB8505_NR_IRQS;
1642 else if (is_ab9540(ab8500)) 3023 } else if (is_ab9540(ab8500)) {
3024 debug_ranges = ab8505_debug_ranges;
1643 num_interrupt_lines = AB9540_NR_IRQS; 3025 num_interrupt_lines = AB9540_NR_IRQS;
3026 } else if (is_ab8540(ab8500)) {
3027 debug_ranges = ab8540_debug_ranges;
3028 num_interrupt_lines = AB8540_NR_IRQS;
3029 }
1644 3030
1645 file = debugfs_create_file("interrupts", (S_IRUGO), 3031 file = debugfs_create_file("interrupts", (S_IRUGO),
1646 ab8500_dir, &plf->dev, &ab8500_interrupts_fops); 3032 ab8500_dir, &plf->dev, &ab8500_interrupts_fops);
1647 if (!file) 3033 if (!file)
1648 goto err; 3034 goto err;
1649 3035
1650 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR), 3036 file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR | S_IWGRP),
1651 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops); 3037 ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
1652 if (!file) 3038 if (!file)
1653 goto err; 3039 goto err;
1654 3040
1655 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR), 3041 file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR | S_IWGRP),
1656 ab8500_dir, &plf->dev, &ab8500_hwreg_fops); 3042 ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
1657 if (!file) 3043 if (!file)
1658 goto err; 3044 goto err;
1659 3045
1660 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR), 3046 file = debugfs_create_file("all-modem-registers", (S_IRUGO | S_IWUSR | S_IWGRP),
1661 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops); 3047 ab8500_dir, &plf->dev, &ab8500_modem_fops);
1662 if (!file) 3048 if (!file)
1663 goto err; 3049 goto err;
1664 3050
1665 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR), 3051 file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR | S_IWGRP),
1666 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops); 3052 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
1667 if (!file) 3053 if (!file)
1668 goto err; 3054 goto err;
1669 3055
1670 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR), 3056 file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR | S_IWGRP),
1671 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops); 3057 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
1672 if (!file) 3058 if (!file)
1673 goto err; 3059 goto err;
1674 3060
1675 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR), 3061 file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1676 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops); 3062 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
1677 if (!file) 3063 if (!file)
1678 goto err; 3064 goto err;
1679 3065
1680 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR), 3066 file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR | S_IWGRP),
1681 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops); 3067 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
1682 if (!file) 3068 if (!file)
1683 goto err; 3069 goto err;
1684 3070
1685 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR), 3071 file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR | S_IWGRP),
1686 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops); 3072 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
1687 if (!file) 3073 if (!file)
1688 goto err; 3074 goto err;
1689 3075
1690 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR), 3076 file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR | S_IWGRP),
1691 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops); 3077 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
1692 if (!file) 3078 if (!file)
1693 goto err; 3079 goto err;
1694 3080
1695 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR), 3081 file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR | S_IWGRP),
1696 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops); 3082 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
1697 if (!file) 3083 if (!file)
1698 goto err; 3084 goto err;
1699 3085
1700 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR), 3086 file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1701 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops); 3087 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
1702 if (!file) 3088 if (!file)
1703 goto err; 3089 goto err;
1704 3090
1705 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR), 3091 file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR | S_IWGRP),
1706 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops); 3092 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
3093 if (!file)
3094 goto err;
3095
3096 file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3097 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
3098 if (!file)
3099 goto err;
3100
3101 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR | S_IWGRP),
3102 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
3103 if (!file)
3104 goto err;
3105
3106 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR | S_IWGRP),
3107 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
3108 if (!file)
3109 goto err;
3110
3111 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3112 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
3113 if (!file)
3114 goto err;
3115
3116 file = debugfs_create_file("usb_id", (S_IRUGO | S_IWUSR | S_IWGRP),
3117 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_id_fops);
3118 if (!file)
3119 goto err;
3120
3121 if (is_ab8540(ab8500)) {
3122 file = debugfs_create_file("xtal_temp", (S_IRUGO | S_IWUSR | S_IWGRP),
3123 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_xtal_temp_fops);
3124 if (!file)
3125 goto err;
3126 file = debugfs_create_file("vbattruemeas", (S_IRUGO | S_IWUSR | S_IWGRP),
3127 ab8500_gpadc_dir, &plf->dev,
3128 &ab8540_gpadc_vbat_true_meas_fops);
3129 if (!file)
3130 goto err;
3131 file = debugfs_create_file("batctrl_and_ibat",
3132 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3133 &plf->dev, &ab8540_gpadc_bat_ctrl_and_ibat_fops);
3134 if (!file)
3135 goto err;
3136 file = debugfs_create_file("vbatmeas_and_ibat",
3137 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3138 &plf->dev,
3139 &ab8540_gpadc_vbat_meas_and_ibat_fops);
3140 if (!file)
3141 goto err;
3142 file = debugfs_create_file("vbattruemeas_and_ibat",
3143 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3144 &plf->dev,
3145 &ab8540_gpadc_vbat_true_meas_and_ibat_fops);
3146 if (!file)
3147 goto err;
3148 file = debugfs_create_file("battemp_and_ibat",
3149 (S_IRUGO | S_IWUGO), ab8500_gpadc_dir,
3150 &plf->dev, &ab8540_gpadc_bat_temp_and_ibat_fops);
3151 if (!file)
3152 goto err;
3153 file = debugfs_create_file("otp_calib", (S_IRUGO | S_IWUSR | S_IWGRP),
3154 ab8500_gpadc_dir, &plf->dev, &ab8540_gpadc_otp_calib_fops);
3155 if (!file)
3156 goto err;
3157 }
3158 file = debugfs_create_file("avg_sample", (S_IRUGO | S_IWUSR | S_IWGRP),
3159 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_avg_sample_fops);
1707 if (!file) 3160 if (!file)
1708 goto err; 3161 goto err;
1709 3162
1710 file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR), 3163 file = debugfs_create_file("trig_edge", (S_IRUGO | S_IWUSR | S_IWGRP),
1711 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops); 3164 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_edge_fops);
1712 if (!file) 3165 if (!file)
1713 goto err; 3166 goto err;
1714 3167
1715 file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR), 3168 file = debugfs_create_file("trig_timer", (S_IRUGO | S_IWUSR | S_IWGRP),
1716 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops); 3169 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_trig_timer_fops);
1717 if (!file) 3170 if (!file)
1718 goto err; 3171 goto err;
1719 3172
1720 file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR), 3173 file = debugfs_create_file("conv_type", (S_IRUGO | S_IWUSR | S_IWGRP),
1721 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops); 3174 ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_conv_type_fops);
1722 if (!file) 3175 if (!file)
1723 goto err; 3176 goto err;
1724 3177
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index 5f341a50ee5a..65f72284185d 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -37,6 +37,13 @@
37#define AB8500_GPADC_AUTODATAL_REG 0x07 37#define AB8500_GPADC_AUTODATAL_REG 0x07
38#define AB8500_GPADC_AUTODATAH_REG 0x08 38#define AB8500_GPADC_AUTODATAH_REG 0x08
39#define AB8500_GPADC_MUX_CTRL_REG 0x09 39#define AB8500_GPADC_MUX_CTRL_REG 0x09
40#define AB8540_GPADC_MANDATA2L_REG 0x09
41#define AB8540_GPADC_MANDATA2H_REG 0x0A
42#define AB8540_GPADC_APEAAX_REG 0x10
43#define AB8540_GPADC_APEAAT_REG 0x11
44#define AB8540_GPADC_APEAAM_REG 0x12
45#define AB8540_GPADC_APEAAH_REG 0x13
46#define AB8540_GPADC_APEAAL_REG 0x14
40 47
41/* 48/*
42 * OTP register offsets 49 * OTP register offsets
@@ -49,19 +56,29 @@
49#define AB8500_GPADC_CAL_5 0x13 56#define AB8500_GPADC_CAL_5 0x13
50#define AB8500_GPADC_CAL_6 0x14 57#define AB8500_GPADC_CAL_6 0x14
51#define AB8500_GPADC_CAL_7 0x15 58#define AB8500_GPADC_CAL_7 0x15
59/* New calibration for 8540 */
60#define AB8540_GPADC_OTP4_REG_7 0x38
61#define AB8540_GPADC_OTP4_REG_6 0x39
62#define AB8540_GPADC_OTP4_REG_5 0x3A
52 63
53/* gpadc constants */ 64/* gpadc constants */
54#define EN_VINTCORE12 0x04 65#define EN_VINTCORE12 0x04
55#define EN_VTVOUT 0x02 66#define EN_VTVOUT 0x02
56#define EN_GPADC 0x01 67#define EN_GPADC 0x01
57#define DIS_GPADC 0x00 68#define DIS_GPADC 0x00
58#define SW_AVG_16 0x60 69#define AVG_1 0x00
70#define AVG_4 0x20
71#define AVG_8 0x40
72#define AVG_16 0x60
59#define ADC_SW_CONV 0x04 73#define ADC_SW_CONV 0x04
60#define EN_ICHAR 0x80 74#define EN_ICHAR 0x80
61#define BTEMP_PULL_UP 0x08 75#define BTEMP_PULL_UP 0x08
62#define EN_BUF 0x40 76#define EN_BUF 0x40
63#define DIS_ZERO 0x00 77#define DIS_ZERO 0x00
64#define GPADC_BUSY 0x01 78#define GPADC_BUSY 0x01
79#define EN_FALLING 0x10
80#define EN_TRIG_EDGE 0x02
81#define EN_VBIAS_XTAL_TEMP 0x02
65 82
66/* GPADC constants from AB8500 spec, UM0836 */ 83/* GPADC constants from AB8500 spec, UM0836 */
67#define ADC_RESOLUTION 1024 84#define ADC_RESOLUTION 1024
@@ -80,8 +97,21 @@
80#define ADC_CH_BKBAT_MIN 0 97#define ADC_CH_BKBAT_MIN 0
81#define ADC_CH_BKBAT_MAX 3200 98#define ADC_CH_BKBAT_MAX 3200
82 99
100/* GPADC constants from AB8540 spec */
101#define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ibat*/
102#define ADC_CH_IBAT_MAX 6000
103#define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat*/
104#define ADC_CH_IBAT_MAX_V 60
105#define IBAT_VDROP_L (-56) /* mV */
106#define IBAT_VDROP_H 56
107
83/* This is used to not lose precision when dividing to get gain and offset */ 108/* This is used to not lose precision when dividing to get gain and offset */
84#define CALIB_SCALE 1000 109#define CALIB_SCALE 1000
110/*
111 * Number of bits shift used to not lose precision
112 * when dividing to get ibat gain.
113 */
114#define CALIB_SHIFT_IBAT 20
85 115
86/* Time in ms before disabling regulator */ 116/* Time in ms before disabling regulator */
87#define GPADC_AUDOSUSPEND_DELAY 1 117#define GPADC_AUDOSUSPEND_DELAY 1
@@ -92,6 +122,7 @@ enum cal_channels {
92 ADC_INPUT_VMAIN = 0, 122 ADC_INPUT_VMAIN = 0,
93 ADC_INPUT_BTEMP, 123 ADC_INPUT_BTEMP,
94 ADC_INPUT_VBAT, 124 ADC_INPUT_VBAT,
125 ADC_INPUT_IBAT,
95 NBR_CAL_INPUTS, 126 NBR_CAL_INPUTS,
96}; 127};
97 128
@@ -102,8 +133,10 @@ enum cal_channels {
102 * @offset: Offset of the ADC channel 133 * @offset: Offset of the ADC channel
103 */ 134 */
104struct adc_cal_data { 135struct adc_cal_data {
105 u64 gain; 136 s64 gain;
106 u64 offset; 137 s64 offset;
138 u16 otp_calib_hi;
139 u16 otp_calib_lo;
107}; 140};
108 141
109/** 142/**
@@ -116,7 +149,10 @@ struct adc_cal_data {
116 * the completion of gpadc conversion 149 * the completion of gpadc conversion
117 * @ab8500_gpadc_lock: structure of type mutex 150 * @ab8500_gpadc_lock: structure of type mutex
118 * @regu: pointer to the struct regulator 151 * @regu: pointer to the struct regulator
119 * @irq: interrupt number that is used by gpadc 152 * @irq_sw: interrupt number that is used by gpadc for Sw
153 * conversion
154 * @irq_hw: interrupt number that is used by gpadc for Hw
155 * conversion
120 * @cal_data array of ADC calibration data structs 156 * @cal_data array of ADC calibration data structs
121 */ 157 */
122struct ab8500_gpadc { 158struct ab8500_gpadc {
@@ -126,7 +162,8 @@ struct ab8500_gpadc {
126 struct completion ab8500_gpadc_complete; 162 struct completion ab8500_gpadc_complete;
127 struct mutex ab8500_gpadc_lock; 163 struct mutex ab8500_gpadc_lock;
128 struct regulator *regu; 164 struct regulator *regu;
129 int irq; 165 int irq_sw;
166 int irq_hw;
130 struct adc_cal_data cal_data[NBR_CAL_INPUTS]; 167 struct adc_cal_data cal_data[NBR_CAL_INPUTS];
131}; 168};
132 169
@@ -171,6 +208,7 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
171 gpadc->cal_data[ADC_INPUT_VMAIN].offset) / CALIB_SCALE; 208 gpadc->cal_data[ADC_INPUT_VMAIN].offset) / CALIB_SCALE;
172 break; 209 break;
173 210
211 case XTAL_TEMP:
174 case BAT_CTRL: 212 case BAT_CTRL:
175 case BTEMP_BALL: 213 case BTEMP_BALL:
176 case ACC_DETECT1: 214 case ACC_DETECT1:
@@ -189,6 +227,7 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
189 break; 227 break;
190 228
191 case MAIN_BAT_V: 229 case MAIN_BAT_V:
230 case VBAT_TRUE_MEAS:
192 /* For some reason we don't have calibrated data */ 231 /* For some reason we don't have calibrated data */
193 if (!gpadc->cal_data[ADC_INPUT_VBAT].gain) { 232 if (!gpadc->cal_data[ADC_INPUT_VBAT].gain) {
194 res = ADC_CH_VBAT_MIN + (ADC_CH_VBAT_MAX - 233 res = ADC_CH_VBAT_MIN + (ADC_CH_VBAT_MAX -
@@ -232,6 +271,20 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
232 ADC_RESOLUTION; 271 ADC_RESOLUTION;
233 break; 272 break;
234 273
274 case IBAT_VIRTUAL_CHANNEL:
275 /* For some reason we don't have calibrated data */
276 if (!gpadc->cal_data[ADC_INPUT_IBAT].gain) {
277 res = ADC_CH_IBAT_MIN + (ADC_CH_IBAT_MAX -
278 ADC_CH_IBAT_MIN) * ad_value /
279 ADC_RESOLUTION;
280 break;
281 }
282 /* Here we can use the calibrated data */
283 res = (int) (ad_value * gpadc->cal_data[ADC_INPUT_IBAT].gain +
284 gpadc->cal_data[ADC_INPUT_IBAT].offset)
285 >> CALIB_SHIFT_IBAT;
286 break;
287
235 default: 288 default:
236 dev_err(gpadc->dev, 289 dev_err(gpadc->dev,
237 "unknown channel, not possible to convert\n"); 290 "unknown channel, not possible to convert\n");
@@ -244,25 +297,35 @@ int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
244EXPORT_SYMBOL(ab8500_gpadc_ad_to_voltage); 297EXPORT_SYMBOL(ab8500_gpadc_ad_to_voltage);
245 298
246/** 299/**
247 * ab8500_gpadc_convert() - gpadc conversion 300 * ab8500_gpadc_sw_hw_convert() - gpadc conversion
248 * @channel: analog channel to be converted to digital data 301 * @channel: analog channel to be converted to digital data
302 * @avg_sample: number of ADC sample to average
303 * @trig_egde: selected ADC trig edge
304 * @trig_timer: selected ADC trigger delay timer
305 * @conv_type: selected conversion type (HW or SW conversion)
249 * 306 *
250 * This function converts the selected analog i/p to digital 307 * This function converts the selected analog i/p to digital
251 * data. 308 * data.
252 */ 309 */
253int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel) 310int ab8500_gpadc_sw_hw_convert(struct ab8500_gpadc *gpadc, u8 channel,
311 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type)
254{ 312{
255 int ad_value; 313 int ad_value;
256 int voltage; 314 int voltage;
257 315
258 ad_value = ab8500_gpadc_read_raw(gpadc, channel); 316 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
259 if (ad_value < 0) { 317 trig_edge, trig_timer, conv_type);
260 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", channel); 318/* On failure retry a second time */
319 if (ad_value < 0)
320 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
321 trig_edge, trig_timer, conv_type);
322if (ad_value < 0) {
323 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n",
324 channel);
261 return ad_value; 325 return ad_value;
262 } 326 }
263 327
264 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value); 328 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value);
265
266 if (voltage < 0) 329 if (voltage < 0)
267 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:" 330 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:"
268 " %d AD: 0x%x\n", channel, ad_value); 331 " %d AD: 0x%x\n", channel, ad_value);
@@ -274,21 +337,46 @@ EXPORT_SYMBOL(ab8500_gpadc_convert);
274/** 337/**
275 * ab8500_gpadc_read_raw() - gpadc read 338 * ab8500_gpadc_read_raw() - gpadc read
276 * @channel: analog channel to be read 339 * @channel: analog channel to be read
340 * @avg_sample: number of ADC sample to average
341 * @trig_edge: selected trig edge
342 * @trig_timer: selected ADC trigger delay timer
343 * @conv_type: selected conversion type (HW or SW conversion)
277 * 344 *
278 * This function obtains the raw ADC value, this then needs 345 * This function obtains the raw ADC value for an hardware conversion,
279 * to be converted by calling ab8500_gpadc_ad_to_voltage() 346 * this then needs to be converted by calling ab8500_gpadc_ad_to_voltage()
280 */ 347 */
281int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel) 348int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
349 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type)
350{
351 int raw_data;
352 raw_data = ab8500_gpadc_double_read_raw(gpadc, channel,
353 avg_sample, trig_edge, trig_timer, conv_type, NULL);
354 return raw_data;
355}
356
357int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
358 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type,
359 int *ibat)
282{ 360{
283 int ret; 361 int ret;
284 int looplimit = 0; 362 int looplimit = 0;
285 u8 val, low_data, high_data; 363 unsigned long completion_timeout;
364 u8 val, low_data, high_data, low_data2, high_data2;
365 u8 val_reg1 = 0;
366 unsigned int delay_min = 0;
367 unsigned int delay_max = 0;
368 u8 data_low_addr, data_high_addr;
286 369
287 if (!gpadc) 370 if (!gpadc)
288 return -ENODEV; 371 return -ENODEV;
289 372
290 mutex_lock(&gpadc->ab8500_gpadc_lock); 373 /* check if convertion is supported */
374 if ((gpadc->irq_sw < 0) && (conv_type == ADC_SW))
375 return -ENOTSUPP;
376 if ((gpadc->irq_hw < 0) && (conv_type == ADC_HW))
377 return -ENOTSUPP;
291 378
379 mutex_lock(&gpadc->ab8500_gpadc_lock);
292 /* Enable VTVout LDO this is required for GPADC */ 380 /* Enable VTVout LDO this is required for GPADC */
293 pm_runtime_get_sync(gpadc->dev); 381 pm_runtime_get_sync(gpadc->dev);
294 382
@@ -309,16 +397,34 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
309 } 397 }
310 398
311 /* Enable GPADC */ 399 /* Enable GPADC */
312 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 400 val_reg1 |= EN_GPADC;
313 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, EN_GPADC, EN_GPADC); 401
314 if (ret < 0) { 402 /* Select the channel source and set average samples */
315 dev_err(gpadc->dev, "gpadc_conversion: enable gpadc failed\n"); 403 switch (avg_sample) {
316 goto out; 404 case SAMPLE_1:
405 val = channel | AVG_1;
406 break;
407 case SAMPLE_4:
408 val = channel | AVG_4;
409 break;
410 case SAMPLE_8:
411 val = channel | AVG_8;
412 break;
413 default:
414 val = channel | AVG_16;
415 break;
317 } 416 }
318 417
319 /* Select the channel source and set average samples to 16 */ 418 if (conv_type == ADC_HW) {
320 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 419 ret = abx500_set_register_interruptible(gpadc->dev,
321 AB8500_GPADC_CTRL2_REG, (channel | SW_AVG_16)); 420 AB8500_GPADC, AB8500_GPADC_CTRL3_REG, val);
421 val_reg1 |= EN_TRIG_EDGE;
422 if (trig_edge)
423 val_reg1 |= EN_FALLING;
424 }
425 else
426 ret = abx500_set_register_interruptible(gpadc->dev,
427 AB8500_GPADC, AB8500_GPADC_CTRL2_REG, val);
322 if (ret < 0) { 428 if (ret < 0) {
323 dev_err(gpadc->dev, 429 dev_err(gpadc->dev,
324 "gpadc_conversion: set avg samples failed\n"); 430 "gpadc_conversion: set avg samples failed\n");
@@ -333,71 +439,129 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
333 switch (channel) { 439 switch (channel) {
334 case MAIN_CHARGER_C: 440 case MAIN_CHARGER_C:
335 case USB_CHARGER_C: 441 case USB_CHARGER_C:
336 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 442 val_reg1 |= EN_BUF | EN_ICHAR;
337 AB8500_GPADC, AB8500_GPADC_CTRL1_REG,
338 EN_BUF | EN_ICHAR,
339 EN_BUF | EN_ICHAR);
340 break; 443 break;
341 case BTEMP_BALL: 444 case BTEMP_BALL:
342 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) { 445 if (!is_ab8500_2p0_or_earlier(gpadc->parent)) {
343 /* Turn on btemp pull-up on ABB 3.0 */ 446 val_reg1 |= EN_BUF | BTEMP_PULL_UP;
344 ret = abx500_mask_and_set_register_interruptible( 447 /*
345 gpadc->dev, 448 * Delay might be needed for ABB8500 cut 3.0, if not,
346 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, 449 * remove when hardware will be availible
347 EN_BUF | BTEMP_PULL_UP, 450 */
348 EN_BUF | BTEMP_PULL_UP); 451 delay_min = 1000; /* Delay in micro seconds */
349 452 delay_max = 10000; /* large range to optimise sleep mode */
350 /*
351 * Delay might be needed for ABB8500 cut 3.0, if not, remove
352 * when hardware will be available
353 */
354 usleep_range(1000, 1000);
355 break; 453 break;
356 } 454 }
357 /* Intentional fallthrough */ 455 /* Intentional fallthrough */
358 default: 456 default:
359 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 457 val_reg1 |= EN_BUF;
360 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, EN_BUF, EN_BUF);
361 break; 458 break;
362 } 459 }
460
461 /* Write configuration to register */
462 ret = abx500_set_register_interruptible(gpadc->dev,
463 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, val_reg1);
363 if (ret < 0) { 464 if (ret < 0) {
364 dev_err(gpadc->dev, 465 dev_err(gpadc->dev,
365 "gpadc_conversion: select falling edge failed\n"); 466 "gpadc_conversion: set Control register failed\n");
366 goto out; 467 goto out;
367 } 468 }
368 469
369 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 470 if (delay_min != 0)
370 AB8500_GPADC, AB8500_GPADC_CTRL1_REG, ADC_SW_CONV, ADC_SW_CONV); 471 usleep_range(delay_min, delay_max);
371 if (ret < 0) { 472
372 dev_err(gpadc->dev, 473 if (conv_type == ADC_HW) {
373 "gpadc_conversion: start s/w conversion failed\n"); 474 /* Set trigger delay timer */
374 goto out; 475 ret = abx500_set_register_interruptible(gpadc->dev,
476 AB8500_GPADC, AB8500_GPADC_AUTO_TIMER_REG, trig_timer);
477 if (ret < 0) {
478 dev_err(gpadc->dev,
479 "gpadc_conversion: trig timer failed\n");
480 goto out;
481 }
482 completion_timeout = 2 * HZ;
483 data_low_addr = AB8500_GPADC_AUTODATAL_REG;
484 data_high_addr = AB8500_GPADC_AUTODATAH_REG;
485 } else {
486 /* Start SW conversion */
487 ret = abx500_mask_and_set_register_interruptible(gpadc->dev,
488 AB8500_GPADC, AB8500_GPADC_CTRL1_REG,
489 ADC_SW_CONV, ADC_SW_CONV);
490 if (ret < 0) {
491 dev_err(gpadc->dev,
492 "gpadc_conversion: start s/w conv failed\n");
493 goto out;
494 }
495 completion_timeout = msecs_to_jiffies(CONVERSION_TIME);
496 data_low_addr = AB8500_GPADC_MANDATAL_REG;
497 data_high_addr = AB8500_GPADC_MANDATAH_REG;
375 } 498 }
499
376 /* wait for completion of conversion */ 500 /* wait for completion of conversion */
377 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete, 501 if (!wait_for_completion_timeout(&gpadc->ab8500_gpadc_complete,
378 msecs_to_jiffies(CONVERSION_TIME))) { 502 completion_timeout)) {
379 dev_err(gpadc->dev, 503 dev_err(gpadc->dev,
380 "timeout: didn't receive GPADC conversion interrupt\n"); 504 "timeout didn't receive GPADC conv interrupt\n");
381 ret = -EINVAL; 505 ret = -EINVAL;
382 goto out; 506 goto out;
383 } 507 }
384 508
385 /* Read the converted RAW data */ 509 /* Read the converted RAW data */
386 ret = abx500_get_register_interruptible(gpadc->dev, AB8500_GPADC, 510 ret = abx500_get_register_interruptible(gpadc->dev,
387 AB8500_GPADC_MANDATAL_REG, &low_data); 511 AB8500_GPADC, data_low_addr, &low_data);
388 if (ret < 0) { 512 if (ret < 0) {
389 dev_err(gpadc->dev, "gpadc_conversion: read low data failed\n"); 513 dev_err(gpadc->dev, "gpadc_conversion: read low data failed\n");
390 goto out; 514 goto out;
391 } 515 }
392 516
393 ret = abx500_get_register_interruptible(gpadc->dev, AB8500_GPADC, 517 ret = abx500_get_register_interruptible(gpadc->dev,
394 AB8500_GPADC_MANDATAH_REG, &high_data); 518 AB8500_GPADC, data_high_addr, &high_data);
395 if (ret < 0) { 519 if (ret < 0) {
396 dev_err(gpadc->dev, 520 dev_err(gpadc->dev, "gpadc_conversion: read high data failed\n");
397 "gpadc_conversion: read high data failed\n");
398 goto out; 521 goto out;
399 } 522 }
400 523
524 /* Check if double convertion is required */
525 if ((channel == BAT_CTRL_AND_IBAT) ||
526 (channel == VBAT_MEAS_AND_IBAT) ||
527 (channel == VBAT_TRUE_MEAS_AND_IBAT) ||
528 (channel == BAT_TEMP_AND_IBAT)) {
529
530 if (conv_type == ADC_HW) {
531 /* not supported */
532 ret = -ENOTSUPP;
533 dev_err(gpadc->dev,
534 "gpadc_conversion: only SW double conversion supported\n");
535 goto out;
536 } else {
537 /* Read the converted RAW data 2 */
538 ret = abx500_get_register_interruptible(gpadc->dev,
539 AB8500_GPADC, AB8540_GPADC_MANDATA2L_REG,
540 &low_data2);
541 if (ret < 0) {
542 dev_err(gpadc->dev,
543 "gpadc_conversion: read sw low data 2 failed\n");
544 goto out;
545 }
546
547 ret = abx500_get_register_interruptible(gpadc->dev,
548 AB8500_GPADC, AB8540_GPADC_MANDATA2H_REG,
549 &high_data2);
550 if (ret < 0) {
551 dev_err(gpadc->dev,
552 "gpadc_conversion: read sw high data 2 failed\n");
553 goto out;
554 }
555 if (ibat != NULL) {
556 *ibat = (high_data2 << 8) | low_data2;
557 } else {
558 dev_warn(gpadc->dev,
559 "gpadc_conversion: ibat not stored\n");
560 }
561
562 }
563 }
564
401 /* Disable GPADC */ 565 /* Disable GPADC */
402 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 566 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
403 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 567 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
@@ -406,6 +570,7 @@ int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
406 goto out; 570 goto out;
407 } 571 }
408 572
573 /* Disable VTVout LDO this is required for GPADC */
409 pm_runtime_mark_last_busy(gpadc->dev); 574 pm_runtime_mark_last_busy(gpadc->dev);
410 pm_runtime_put_autosuspend(gpadc->dev); 575 pm_runtime_put_autosuspend(gpadc->dev);
411 576
@@ -422,9 +587,7 @@ out:
422 */ 587 */
423 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 588 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
424 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 589 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
425
426 pm_runtime_put(gpadc->dev); 590 pm_runtime_put(gpadc->dev);
427
428 mutex_unlock(&gpadc->ab8500_gpadc_lock); 591 mutex_unlock(&gpadc->ab8500_gpadc_lock);
429 dev_err(gpadc->dev, 592 dev_err(gpadc->dev,
430 "gpadc_conversion: Failed to AD convert channel %d\n", channel); 593 "gpadc_conversion: Failed to AD convert channel %d\n", channel);
@@ -433,16 +596,16 @@ out:
433EXPORT_SYMBOL(ab8500_gpadc_read_raw); 596EXPORT_SYMBOL(ab8500_gpadc_read_raw);
434 597
435/** 598/**
436 * ab8500_bm_gpswadcconvend_handler() - isr for s/w gpadc conversion completion 599 * ab8500_bm_gpadcconvend_handler() - isr for gpadc conversion completion
437 * @irq: irq number 600 * @irq: irq number
438 * @data: pointer to the data passed during request irq 601 * @data: pointer to the data passed during request irq
439 * 602 *
440 * This is a interrupt service routine for s/w gpadc conversion completion. 603 * This is a interrupt service routine for gpadc conversion completion.
441 * Notifies the gpadc completion is completed and the converted raw value 604 * Notifies the gpadc completion is completed and the converted raw value
442 * can be read from the registers. 605 * can be read from the registers.
443 * Returns IRQ status(IRQ_HANDLED) 606 * Returns IRQ status(IRQ_HANDLED)
444 */ 607 */
445static irqreturn_t ab8500_bm_gpswadcconvend_handler(int irq, void *_gpadc) 608static irqreturn_t ab8500_bm_gpadcconvend_handler(int irq, void *_gpadc)
446{ 609{
447 struct ab8500_gpadc *gpadc = _gpadc; 610 struct ab8500_gpadc *gpadc = _gpadc;
448 611
@@ -461,15 +624,27 @@ static int otp_cal_regs[] = {
461 AB8500_GPADC_CAL_7, 624 AB8500_GPADC_CAL_7,
462}; 625};
463 626
627static int otp4_cal_regs[] = {
628 AB8540_GPADC_OTP4_REG_7,
629 AB8540_GPADC_OTP4_REG_6,
630 AB8540_GPADC_OTP4_REG_5,
631};
632
464static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc) 633static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
465{ 634{
466 int i; 635 int i;
467 int ret[ARRAY_SIZE(otp_cal_regs)]; 636 int ret[ARRAY_SIZE(otp_cal_regs)];
468 u8 gpadc_cal[ARRAY_SIZE(otp_cal_regs)]; 637 u8 gpadc_cal[ARRAY_SIZE(otp_cal_regs)];
469 638 int ret_otp4[ARRAY_SIZE(otp4_cal_regs)];
639 u8 gpadc_otp4[ARRAY_SIZE(otp4_cal_regs)];
470 int vmain_high, vmain_low; 640 int vmain_high, vmain_low;
471 int btemp_high, btemp_low; 641 int btemp_high, btemp_low;
472 int vbat_high, vbat_low; 642 int vbat_high, vbat_low;
643 int ibat_high, ibat_low;
644 s64 V_gain, V_offset, V2A_gain, V2A_offset;
645 struct ab8500 *ab8500;
646
647 ab8500 = gpadc->parent;
473 648
474 /* First we read all OTP registers and store the error code */ 649 /* First we read all OTP registers and store the error code */
475 for (i = 0; i < ARRAY_SIZE(otp_cal_regs); i++) { 650 for (i = 0; i < ARRAY_SIZE(otp_cal_regs); i++) {
@@ -489,7 +664,7 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
489 * bt_h/l = btemp_high/low 664 * bt_h/l = btemp_high/low
490 * vb_h/l = vbat_high/low 665 * vb_h/l = vbat_high/low
491 * 666 *
492 * Data bits: 667 * Data bits 8500/9540:
493 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 668 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
494 * |.......|.......|.......|.......|.......|.......|.......|....... 669 * |.......|.......|.......|.......|.......|.......|.......|.......
495 * | | vm_h9 | vm_h8 670 * | | vm_h9 | vm_h8
@@ -507,6 +682,35 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
507 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 | 682 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 |
508 * |.......|.......|.......|.......|.......|.......|.......|....... 683 * |.......|.......|.......|.......|.......|.......|.......|.......
509 * 684 *
685 * Data bits 8540:
686 * OTP2
687 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
688 * |.......|.......|.......|.......|.......|.......|.......|.......
689 * |
690 * |.......|.......|.......|.......|.......|.......|.......|.......
691 * | vm_h9 | vm_h8 | vm_h7 | vm_h6 | vm_h5 | vm_h4 | vm_h3 | vm_h2
692 * |.......|.......|.......|.......|.......|.......|.......|.......
693 * | vm_h1 | vm_h0 | vm_l4 | vm_l3 | vm_l2 | vm_l1 | vm_l0 | bt_h9
694 * |.......|.......|.......|.......|.......|.......|.......|.......
695 * | bt_h8 | bt_h7 | bt_h6 | bt_h5 | bt_h4 | bt_h3 | bt_h2 | bt_h1
696 * |.......|.......|.......|.......|.......|.......|.......|.......
697 * | bt_h0 | bt_l4 | bt_l3 | bt_l2 | bt_l1 | bt_l0 | vb_h9 | vb_h8
698 * |.......|.......|.......|.......|.......|.......|.......|.......
699 * | vb_h7 | vb_h6 | vb_h5 | vb_h4 | vb_h3 | vb_h2 | vb_h1 | vb_h0
700 * |.......|.......|.......|.......|.......|.......|.......|.......
701 * | vb_l5 | vb_l4 | vb_l3 | vb_l2 | vb_l1 | vb_l0 |
702 * |.......|.......|.......|.......|.......|.......|.......|.......
703 *
704 * Data bits 8540:
705 * OTP4
706 * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
707 * |.......|.......|.......|.......|.......|.......|.......|.......
708 * | | ib_h9 | ib_h8 | ib_h7
709 * |.......|.......|.......|.......|.......|.......|.......|.......
710 * | ib_h6 | ib_h5 | ib_h4 | ib_h3 | ib_h2 | ib_h1 | ib_h0 | ib_l5
711 * |.......|.......|.......|.......|.......|.......|.......|.......
712 * | ib_l4 | ib_l3 | ib_l2 | ib_l1 | ib_l0 |
713 *
510 * 714 *
511 * Ideal output ADC codes corresponding to injected input voltages 715 * Ideal output ADC codes corresponding to injected input voltages
512 * during manufacturing is: 716 * during manufacturing is:
@@ -519,38 +723,116 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
519 * vbat_low: Vin = 2380mV / ADC ideal code = 33 723 * vbat_low: Vin = 2380mV / ADC ideal code = 33
520 */ 724 */
521 725
522 /* Calculate gain and offset for VMAIN if all reads succeeded */ 726 if (is_ab8540(ab8500)) {
523 if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) { 727 /* Calculate gain and offset for VMAIN if all reads succeeded*/
524 vmain_high = (((gpadc_cal[0] & 0x03) << 8) | 728 if (!(ret[1] < 0 || ret[2] < 0)) {
525 ((gpadc_cal[1] & 0x3F) << 2) | 729 vmain_high = (((gpadc_cal[1] & 0xFF) << 2) |
526 ((gpadc_cal[2] & 0xC0) >> 6)); 730 ((gpadc_cal[2] & 0xC0) >> 6));
731 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1);
732
733 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi =
734 (u16)vmain_high;
735 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo =
736 (u16)vmain_low;
737
738 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE *
739 (19500 - 315) / (vmain_high - vmain_low);
740 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE *
741 19500 - (CALIB_SCALE * (19500 - 315) /
742 (vmain_high - vmain_low)) * vmain_high;
743 } else {
744 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0;
745 }
527 746
528 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1); 747 /* Read IBAT calibration Data */
748 for (i = 0; i < ARRAY_SIZE(otp4_cal_regs); i++) {
749 ret_otp4[i] = abx500_get_register_interruptible(
750 gpadc->dev, AB8500_OTP_EMUL,
751 otp4_cal_regs[i], &gpadc_otp4[i]);
752 if (ret_otp4[i] < 0)
753 dev_err(gpadc->dev,
754 "%s: read otp4 reg 0x%02x failed\n",
755 __func__, otp4_cal_regs[i]);
756 }
529 757
530 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE * 758 /* Calculate gain and offset for IBAT if all reads succeeded */
531 (19500 - 315) / (vmain_high - vmain_low); 759 if (!(ret_otp4[0] < 0 || ret_otp4[1] < 0 || ret_otp4[2] < 0)) {
760 ibat_high = (((gpadc_otp4[0] & 0x07) << 7) |
761 ((gpadc_otp4[1] & 0xFE) >> 1));
762 ibat_low = (((gpadc_otp4[1] & 0x01) << 5) |
763 ((gpadc_otp4[2] & 0xF8) >> 3));
764
765 gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi =
766 (u16)ibat_high;
767 gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo =
768 (u16)ibat_low;
769
770 V_gain = ((IBAT_VDROP_H - IBAT_VDROP_L)
771 << CALIB_SHIFT_IBAT) / (ibat_high - ibat_low);
772
773 V_offset = (IBAT_VDROP_H << CALIB_SHIFT_IBAT) -
774 (((IBAT_VDROP_H - IBAT_VDROP_L) <<
775 CALIB_SHIFT_IBAT) / (ibat_high - ibat_low))
776 * ibat_high;
777 /*
778 * Result obtained is in mV (at a scale factor),
779 * we need to calculate gain and offset to get mA
780 */
781 V2A_gain = (ADC_CH_IBAT_MAX - ADC_CH_IBAT_MIN)/
782 (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V);
783 V2A_offset = ((ADC_CH_IBAT_MAX_V * ADC_CH_IBAT_MIN -
784 ADC_CH_IBAT_MAX * ADC_CH_IBAT_MIN_V)
785 << CALIB_SHIFT_IBAT)
786 / (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V);
787
788 gpadc->cal_data[ADC_INPUT_IBAT].gain = V_gain * V2A_gain;
789 gpadc->cal_data[ADC_INPUT_IBAT].offset = V_offset *
790 V2A_gain + V2A_offset;
791 } else {
792 gpadc->cal_data[ADC_INPUT_IBAT].gain = 0;
793 }
532 794
533 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE * 19500 - 795 dev_dbg(gpadc->dev, "IBAT gain %llu offset %llu\n",
534 (CALIB_SCALE * (19500 - 315) / 796 gpadc->cal_data[ADC_INPUT_IBAT].gain,
535 (vmain_high - vmain_low)) * vmain_high; 797 gpadc->cal_data[ADC_INPUT_IBAT].offset);
536 } else { 798 } else {
537 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0; 799 /* Calculate gain and offset for VMAIN if all reads succeeded */
800 if (!(ret[0] < 0 || ret[1] < 0 || ret[2] < 0)) {
801 vmain_high = (((gpadc_cal[0] & 0x03) << 8) |
802 ((gpadc_cal[1] & 0x3F) << 2) |
803 ((gpadc_cal[2] & 0xC0) >> 6));
804 vmain_low = ((gpadc_cal[2] & 0x3E) >> 1);
805
806 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi =
807 (u16)vmain_high;
808 gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo =
809 (u16)vmain_low;
810
811 gpadc->cal_data[ADC_INPUT_VMAIN].gain = CALIB_SCALE *
812 (19500 - 315) / (vmain_high - vmain_low);
813
814 gpadc->cal_data[ADC_INPUT_VMAIN].offset = CALIB_SCALE *
815 19500 - (CALIB_SCALE * (19500 - 315) /
816 (vmain_high - vmain_low)) * vmain_high;
817 } else {
818 gpadc->cal_data[ADC_INPUT_VMAIN].gain = 0;
819 }
538 } 820 }
539 821
540 /* Calculate gain and offset for BTEMP if all reads succeeded */ 822 /* Calculate gain and offset for BTEMP if all reads succeeded */
541 if (!(ret[2] < 0 || ret[3] < 0 || ret[4] < 0)) { 823 if (!(ret[2] < 0 || ret[3] < 0 || ret[4] < 0)) {
542 btemp_high = (((gpadc_cal[2] & 0x01) << 9) | 824 btemp_high = (((gpadc_cal[2] & 0x01) << 9) |
543 (gpadc_cal[3] << 1) | 825 (gpadc_cal[3] << 1) | ((gpadc_cal[4] & 0x80) >> 7));
544 ((gpadc_cal[4] & 0x80) >> 7));
545
546 btemp_low = ((gpadc_cal[4] & 0x7C) >> 2); 826 btemp_low = ((gpadc_cal[4] & 0x7C) >> 2);
547 827
828 gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi = (u16)btemp_high;
829 gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo = (u16)btemp_low;
830
548 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 831 gpadc->cal_data[ADC_INPUT_BTEMP].gain =
549 CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low); 832 CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low);
550
551 gpadc->cal_data[ADC_INPUT_BTEMP].offset = CALIB_SCALE * 1300 - 833 gpadc->cal_data[ADC_INPUT_BTEMP].offset = CALIB_SCALE * 1300 -
552 (CALIB_SCALE * (1300 - 21) / 834 (CALIB_SCALE * (1300 - 21) / (btemp_high - btemp_low))
553 (btemp_high - btemp_low)) * btemp_high; 835 * btemp_high;
554 } else { 836 } else {
555 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 0; 837 gpadc->cal_data[ADC_INPUT_BTEMP].gain = 0;
556 } 838 }
@@ -560,9 +842,11 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
560 vbat_high = (((gpadc_cal[4] & 0x03) << 8) | gpadc_cal[5]); 842 vbat_high = (((gpadc_cal[4] & 0x03) << 8) | gpadc_cal[5]);
561 vbat_low = ((gpadc_cal[6] & 0xFC) >> 2); 843 vbat_low = ((gpadc_cal[6] & 0xFC) >> 2);
562 844
845 gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi = (u16)vbat_high;
846 gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo = (u16)vbat_low;
847
563 gpadc->cal_data[ADC_INPUT_VBAT].gain = CALIB_SCALE * 848 gpadc->cal_data[ADC_INPUT_VBAT].gain = CALIB_SCALE *
564 (4700 - 2380) / (vbat_high - vbat_low); 849 (4700 - 2380) / (vbat_high - vbat_low);
565
566 gpadc->cal_data[ADC_INPUT_VBAT].offset = CALIB_SCALE * 4700 - 850 gpadc->cal_data[ADC_INPUT_VBAT].offset = CALIB_SCALE * 4700 -
567 (CALIB_SCALE * (4700 - 2380) / 851 (CALIB_SCALE * (4700 - 2380) /
568 (vbat_high - vbat_low)) * vbat_high; 852 (vbat_high - vbat_low)) * vbat_high;
@@ -608,6 +892,31 @@ static int ab8500_gpadc_runtime_idle(struct device *dev)
608 return 0; 892 return 0;
609} 893}
610 894
895static int ab8500_gpadc_suspend(struct device *dev)
896{
897 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
898
899 mutex_lock(&gpadc->ab8500_gpadc_lock);
900
901 pm_runtime_get_sync(dev);
902
903 regulator_disable(gpadc->regu);
904 return 0;
905}
906
907static int ab8500_gpadc_resume(struct device *dev)
908{
909 struct ab8500_gpadc *gpadc = dev_get_drvdata(dev);
910
911 regulator_enable(gpadc->regu);
912
913 pm_runtime_mark_last_busy(gpadc->dev);
914 pm_runtime_put_autosuspend(gpadc->dev);
915
916 mutex_unlock(&gpadc->ab8500_gpadc_lock);
917 return 0;
918}
919
611static int ab8500_gpadc_probe(struct platform_device *pdev) 920static int ab8500_gpadc_probe(struct platform_device *pdev)
612{ 921{
613 int ret = 0; 922 int ret = 0;
@@ -619,13 +928,13 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
619 return -ENOMEM; 928 return -ENOMEM;
620 } 929 }
621 930
622 gpadc->irq = platform_get_irq_byname(pdev, "SW_CONV_END"); 931 gpadc->irq_sw = platform_get_irq_byname(pdev, "SW_CONV_END");
623 if (gpadc->irq < 0) { 932 if (gpadc->irq_sw < 0)
624 dev_err(&pdev->dev, "failed to get platform irq-%d\n", 933 dev_err(gpadc->dev, "failed to get platform sw_conv_end irq\n");
625 gpadc->irq); 934
626 ret = gpadc->irq; 935 gpadc->irq_hw = platform_get_irq_byname(pdev, "HW_CONV_END");
627 goto fail; 936 if (gpadc->irq_hw < 0)
628 } 937 dev_err(gpadc->dev, "failed to get platform hw_conv_end irq\n");
629 938
630 gpadc->dev = &pdev->dev; 939 gpadc->dev = &pdev->dev;
631 gpadc->parent = dev_get_drvdata(pdev->dev.parent); 940 gpadc->parent = dev_get_drvdata(pdev->dev.parent);
@@ -634,15 +943,31 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
634 /* Initialize completion used to notify completion of conversion */ 943 /* Initialize completion used to notify completion of conversion */
635 init_completion(&gpadc->ab8500_gpadc_complete); 944 init_completion(&gpadc->ab8500_gpadc_complete);
636 945
637 /* Register interrupt - SwAdcComplete */ 946 /* Register interrupts */
638 ret = request_threaded_irq(gpadc->irq, NULL, 947 if (gpadc->irq_sw >= 0) {
639 ab8500_bm_gpswadcconvend_handler, 948 ret = request_threaded_irq(gpadc->irq_sw, NULL,
640 IRQF_ONESHOT | IRQF_NO_SUSPEND | IRQF_SHARED, 949 ab8500_bm_gpadcconvend_handler,
641 "ab8500-gpadc", gpadc); 950 IRQF_NO_SUSPEND | IRQF_SHARED, "ab8500-gpadc-sw",
642 if (ret < 0) { 951 gpadc);
643 dev_err(gpadc->dev, "Failed to register interrupt, irq: %d\n", 952 if (ret < 0) {
644 gpadc->irq); 953 dev_err(gpadc->dev,
645 goto fail; 954 "Failed to register interrupt irq: %d\n",
955 gpadc->irq_sw);
956 goto fail;
957 }
958 }
959
960 if (gpadc->irq_hw >= 0) {
961 ret = request_threaded_irq(gpadc->irq_hw, NULL,
962 ab8500_bm_gpadcconvend_handler,
963 IRQF_NO_SUSPEND | IRQF_SHARED, "ab8500-gpadc-hw",
964 gpadc);
965 if (ret < 0) {
966 dev_err(gpadc->dev,
967 "Failed to register interrupt irq: %d\n",
968 gpadc->irq_hw);
969 goto fail_irq;
970 }
646 } 971 }
647 972
648 /* VTVout LDO used to power up ab8500-GPADC */ 973 /* VTVout LDO used to power up ab8500-GPADC */
@@ -669,11 +994,13 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
669 ab8500_gpadc_read_calibration_data(gpadc); 994 ab8500_gpadc_read_calibration_data(gpadc);
670 list_add_tail(&gpadc->node, &ab8500_gpadc_list); 995 list_add_tail(&gpadc->node, &ab8500_gpadc_list);
671 dev_dbg(gpadc->dev, "probe success\n"); 996 dev_dbg(gpadc->dev, "probe success\n");
997
672 return 0; 998 return 0;
673 999
674fail_enable: 1000fail_enable:
675fail_irq: 1001fail_irq:
676 free_irq(gpadc->irq, gpadc); 1002 free_irq(gpadc->irq_sw, gpadc);
1003 free_irq(gpadc->irq_hw, gpadc);
677fail: 1004fail:
678 kfree(gpadc); 1005 kfree(gpadc);
679 gpadc = NULL; 1006 gpadc = NULL;
@@ -687,7 +1014,10 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)
687 /* remove this gpadc entry from the list */ 1014 /* remove this gpadc entry from the list */
688 list_del(&gpadc->node); 1015 list_del(&gpadc->node);
689 /* remove interrupt - completion of Sw ADC conversion */ 1016 /* remove interrupt - completion of Sw ADC conversion */
690 free_irq(gpadc->irq, gpadc); 1017 if (gpadc->irq_sw >= 0)
1018 free_irq(gpadc->irq_sw, gpadc);
1019 if (gpadc->irq_hw >= 0)
1020 free_irq(gpadc->irq_hw, gpadc);
691 1021
692 pm_runtime_get_sync(gpadc->dev); 1022 pm_runtime_get_sync(gpadc->dev);
693 pm_runtime_disable(gpadc->dev); 1023 pm_runtime_disable(gpadc->dev);
@@ -707,6 +1037,9 @@ static const struct dev_pm_ops ab8500_gpadc_pm_ops = {
707 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend, 1037 SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend,
708 ab8500_gpadc_runtime_resume, 1038 ab8500_gpadc_runtime_resume,
709 ab8500_gpadc_runtime_idle) 1039 ab8500_gpadc_runtime_idle)
1040 SET_SYSTEM_SLEEP_PM_OPS(ab8500_gpadc_suspend,
1041 ab8500_gpadc_resume)
1042
710}; 1043};
711 1044
712static struct platform_driver ab8500_gpadc_driver = { 1045static struct platform_driver ab8500_gpadc_driver = {
@@ -729,10 +1062,30 @@ static void __exit ab8500_gpadc_exit(void)
729 platform_driver_unregister(&ab8500_gpadc_driver); 1062 platform_driver_unregister(&ab8500_gpadc_driver);
730} 1063}
731 1064
1065/**
1066 * ab8540_gpadc_get_otp() - returns OTP values
1067 *
1068 */
1069void ab8540_gpadc_get_otp(struct ab8500_gpadc *gpadc,
1070 u16 *vmain_l, u16 *vmain_h, u16 *btemp_l, u16 *btemp_h,
1071 u16 *vbat_l, u16 *vbat_h, u16 *ibat_l, u16 *ibat_h)
1072{
1073 *vmain_l = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_lo;
1074 *vmain_h = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi;
1075 *btemp_l = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo;
1076 *btemp_h = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi;
1077 *vbat_l = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo;
1078 *vbat_h = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi;
1079 *ibat_l = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo;
1080 *ibat_h = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi;
1081 return ;
1082}
1083
732subsys_initcall_sync(ab8500_gpadc_init); 1084subsys_initcall_sync(ab8500_gpadc_init);
733module_exit(ab8500_gpadc_exit); 1085module_exit(ab8500_gpadc_exit);
734 1086
735MODULE_LICENSE("GPL v2"); 1087MODULE_LICENSE("GPL v2");
736MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson"); 1088MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson,"
1089 "M'boumba Cedric Madianga");
737MODULE_ALIAS("platform:ab8500_gpadc"); 1090MODULE_ALIAS("platform:ab8500_gpadc");
738MODULE_DESCRIPTION("AB8500 GPADC driver"); 1091MODULE_DESCRIPTION("AB8500 GPADC driver");
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 108fd86552f0..272479cdb107 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -15,19 +15,30 @@
15#include <linux/mfd/abx500/ab8500.h> 15#include <linux/mfd/abx500/ab8500.h>
16#include <linux/mfd/abx500/ab8500-sysctrl.h> 16#include <linux/mfd/abx500/ab8500-sysctrl.h>
17 17
18/* RtcCtrl bits */
19#define AB8500_ALARM_MIN_LOW 0x08
20#define AB8500_ALARM_MIN_MID 0x09
21#define RTC_CTRL 0x0B
22#define RTC_ALARM_ENABLE 0x4
23
18static struct device *sysctrl_dev; 24static struct device *sysctrl_dev;
19 25
20void ab8500_power_off(void) 26void ab8500_power_off(void)
21{ 27{
22 sigset_t old; 28 sigset_t old;
23 sigset_t all; 29 sigset_t all;
24 static char *pss[] = {"ab8500_ac", "ab8500_usb"}; 30 static char *pss[] = {"ab8500_ac", "pm2301", "ab8500_usb"};
25 int i; 31 int i;
26 bool charger_present = false; 32 bool charger_present = false;
27 union power_supply_propval val; 33 union power_supply_propval val;
28 struct power_supply *psy; 34 struct power_supply *psy;
29 int ret; 35 int ret;
30 36
37 if (sysctrl_dev == NULL) {
38 pr_err("%s: sysctrl not initialized\n", __func__);
39 return;
40 }
41
31 /* 42 /*
32 * If we have a charger connected and we're powering off, 43 * If we have a charger connected and we're powering off,
33 * reboot into charge-only mode. 44 * reboot into charge-only mode.
@@ -74,6 +85,63 @@ shutdown:
74 } 85 }
75} 86}
76 87
88/*
89 * Use the AB WD to reset the platform. It will perform a hard
90 * reset instead of a soft reset. Write the reset reason to
91 * the AB before reset, which can be read upon restart.
92 */
93void ab8500_restart(char mode, const char *cmd)
94{
95 struct ab8500_platform_data *plat;
96 struct ab8500_sysctrl_platform_data *pdata;
97 u16 reason = 0;
98 u8 val;
99
100 if (sysctrl_dev == NULL) {
101 pr_err("%s: sysctrl not initialized\n", __func__);
102 return;
103 }
104
105 plat = dev_get_platdata(sysctrl_dev->parent);
106 pdata = plat->sysctrl;
107 if (pdata->reboot_reason_code)
108 reason = pdata->reboot_reason_code(cmd);
109 else
110 pr_warn("[%s] No reboot reason set. Default reason %d\n",
111 __func__, reason);
112
113 /*
114 * Disable RTC alarm, just a precaution so that no alarm
115 * is running when WD reset is executed.
116 */
117 abx500_get_register_interruptible(sysctrl_dev, AB8500_RTC,
118 RTC_CTRL , &val);
119 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
120 RTC_CTRL , (val & ~RTC_ALARM_ENABLE));
121
122 /*
123 * Android is not using the RTC alarm registers during reboot
124 * so we borrow them for writing the reason of reset
125 */
126
127 /* reason[8 LSB] */
128 val = reason & 0xFF;
129 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
130 AB8500_ALARM_MIN_LOW , val);
131
132 /* reason[8 MSB] */
133 val = (reason>>8) & 0xFF;
134 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
135 AB8500_ALARM_MIN_MID , val);
136
137 /* Setting WD timeout to 0 */
138 ab8500_sysctrl_write(AB8500_MAINWDOGTIMER, 0xFF, 0x0);
139
140 /* Setting the parameters to AB8500 WD*/
141 ab8500_sysctrl_write(AB8500_MAINWDOGCTRL, 0xFF, (AB8500_ENABLE_WD |
142 AB8500_WD_RESTART_ON_EXPIRE | AB8500_KICK_WD));
143}
144
77static inline bool valid_bank(u8 bank) 145static inline bool valid_bank(u8 bank)
78{ 146{
79 return ((bank == AB8500_SYS_CTRL1_BLOCK) || 147 return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
@@ -85,7 +153,7 @@ int ab8500_sysctrl_read(u16 reg, u8 *value)
85 u8 bank; 153 u8 bank;
86 154
87 if (sysctrl_dev == NULL) 155 if (sysctrl_dev == NULL)
88 return -EAGAIN; 156 return -EINVAL;
89 157
90 bank = (reg >> 8); 158 bank = (reg >> 8);
91 if (!valid_bank(bank)) 159 if (!valid_bank(bank))
@@ -101,7 +169,7 @@ int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value)
101 u8 bank; 169 u8 bank;
102 170
103 if (sysctrl_dev == NULL) 171 if (sysctrl_dev == NULL)
104 return -EAGAIN; 172 return -EINVAL;
105 173
106 bank = (reg >> 8); 174 bank = (reg >> 8);
107 if (!valid_bank(bank)) 175 if (!valid_bank(bank))
@@ -114,28 +182,36 @@ EXPORT_SYMBOL(ab8500_sysctrl_write);
114 182
115static int ab8500_sysctrl_probe(struct platform_device *pdev) 183static int ab8500_sysctrl_probe(struct platform_device *pdev)
116{ 184{
185 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
117 struct ab8500_platform_data *plat; 186 struct ab8500_platform_data *plat;
118 struct ab8500_sysctrl_platform_data *pdata; 187 struct ab8500_sysctrl_platform_data *pdata;
119 188
120 sysctrl_dev = &pdev->dev;
121 plat = dev_get_platdata(pdev->dev.parent); 189 plat = dev_get_platdata(pdev->dev.parent);
190
191 if (!(plat && plat->sysctrl))
192 return -EINVAL;
193
122 if (plat->pm_power_off) 194 if (plat->pm_power_off)
123 pm_power_off = ab8500_power_off; 195 pm_power_off = ab8500_power_off;
124 196
125 pdata = plat->sysctrl; 197 pdata = plat->sysctrl;
126 198
127 if (pdata) { 199 if (pdata) {
128 int ret, i, j; 200 int last, ret, i, j;
201
202 if (is_ab8505(ab8500))
203 last = AB8500_SYSCLKREQ4RFCLKBUF;
204 else
205 last = AB8500_SYSCLKREQ8RFCLKBUF;
129 206
130 for (i = AB8500_SYSCLKREQ1RFCLKBUF; 207 for (i = AB8500_SYSCLKREQ1RFCLKBUF; i <= last; i++) {
131 i <= AB8500_SYSCLKREQ8RFCLKBUF; i++) {
132 j = i - AB8500_SYSCLKREQ1RFCLKBUF; 208 j = i - AB8500_SYSCLKREQ1RFCLKBUF;
133 ret = ab8500_sysctrl_write(i, 0xff, 209 ret = ab8500_sysctrl_write(i, 0xff,
134 pdata->initial_req_buf_config[j]); 210 pdata->initial_req_buf_config[j]);
135 dev_dbg(&pdev->dev, 211 dev_dbg(&pdev->dev,
136 "Setting SysClkReq%dRfClkBuf 0x%X\n", 212 "Setting SysClkReq%dRfClkBuf 0x%X\n",
137 j + 1, 213 j + 1,
138 pdata->initial_req_buf_config[j]); 214 pdata->initial_req_buf_config[j]);
139 if (ret < 0) { 215 if (ret < 0) {
140 dev_err(&pdev->dev, 216 dev_err(&pdev->dev,
141 "unable to set sysClkReq%dRfClkBuf: " 217 "unable to set sysClkReq%dRfClkBuf: "
diff --git a/drivers/power/88pm860x_charger.c b/drivers/power/88pm860x_charger.c
index 4b37a5af8deb..36fb4b5a4b0d 100644
--- a/drivers/power/88pm860x_charger.c
+++ b/drivers/power/88pm860x_charger.c
@@ -714,7 +714,6 @@ out_irq:
714 while (--i >= 0) 714 while (--i >= 0)
715 free_irq(info->irq[i], info); 715 free_irq(info->irq[i], info);
716out: 716out:
717 kfree(info);
718 return ret; 717 return ret;
719} 718}
720 719
@@ -728,7 +727,6 @@ static int pm860x_charger_remove(struct platform_device *pdev)
728 free_irq(info->irq[0], info); 727 free_irq(info->irq[0], info);
729 for (i = 0; i < info->irq_nums; i++) 728 for (i = 0; i < info->irq_nums; i++)
730 free_irq(info->irq[i], info); 729 free_irq(info->irq[i], info);
731 kfree(info);
732 return 0; 730 return 0;
733} 731}
734 732
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index ffe02fb7cbc7..0d0b5d7d19d0 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -340,6 +340,13 @@ config CHARGER_SMB347
340 Say Y to include support for Summit Microelectronics SMB347 340 Say Y to include support for Summit Microelectronics SMB347
341 Battery Charger. 341 Battery Charger.
342 342
343config CHARGER_TPS65090
344 tristate "TPS65090 battery charger driver"
345 depends on MFD_TPS65090
346 help
347 Say Y here to enable support for battery charging with TPS65090
348 PMIC chips.
349
343config AB8500_BM 350config AB8500_BM
344 bool "AB8500 Battery Management Driver" 351 bool "AB8500 Battery Management Driver"
345 depends on AB8500_CORE && AB8500_GPADC 352 depends on AB8500_CORE && AB8500_GPADC
@@ -353,13 +360,6 @@ config BATTERY_GOLDFISH
353 Say Y to enable support for the battery and AC power in the 360 Say Y to enable support for the battery and AC power in the
354 Goldfish emulator. 361 Goldfish emulator.
355 362
356config CHARGER_PM2301
357 bool "PM2301 Battery Charger Driver"
358 depends on AB8500_BM
359 help
360 Say Y to include support for PM2301 charger driver.
361 Depends on AB8500 battery management core.
362
363source "drivers/power/reset/Kconfig" 363source "drivers/power/reset/Kconfig"
364 364
365endif # POWER_SUPPLY 365endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 3f66436af45c..653bf6ceff30 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -39,7 +39,7 @@ obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
39obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o 39obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
40obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o 40obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o
41obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o 41obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o
42obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o abx500_chargalg.o 42obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o abx500_chargalg.o pm2301_charger.o
43obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o 43obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
44obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o 44obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
45obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o 45obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
@@ -47,10 +47,10 @@ obj-$(CONFIG_CHARGER_LP8727) += lp8727_charger.o
47obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o 47obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o
48obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o 48obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
49obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o 49obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o
50obj-$(CONFIG_CHARGER_PM2301) += pm2301_charger.o
51obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o 50obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
52obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o 51obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o
53obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o 52obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o
54obj-$(CONFIG_POWER_AVS) += avs/ 53obj-$(CONFIG_POWER_AVS) += avs/
55obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o 54obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o
55obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
56obj-$(CONFIG_POWER_RESET) += reset/ 56obj-$(CONFIG_POWER_RESET) += reset/
diff --git a/drivers/power/ab8500_bmdata.c b/drivers/power/ab8500_bmdata.c
index 7a96c0650fbb..d29864533093 100644
--- a/drivers/power/ab8500_bmdata.c
+++ b/drivers/power/ab8500_bmdata.c
@@ -11,7 +11,7 @@
11 * Note that the res_to_temp table must be strictly sorted by falling resistance 11 * Note that the res_to_temp table must be strictly sorted by falling resistance
12 * values to work. 12 * values to work.
13 */ 13 */
14static struct abx500_res_to_temp temp_tbl_A_thermistor[] = { 14const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
15 {-5, 53407}, 15 {-5, 53407},
16 { 0, 48594}, 16 { 0, 48594},
17 { 5, 43804}, 17 { 5, 43804},
@@ -28,8 +28,12 @@ static struct abx500_res_to_temp temp_tbl_A_thermistor[] = {
28 {60, 13437}, 28 {60, 13437},
29 {65, 12500}, 29 {65, 12500},
30}; 30};
31EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
31 32
32static struct abx500_res_to_temp temp_tbl_B_thermistor[] = { 33const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
34EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
35
36const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
33 {-5, 200000}, 37 {-5, 200000},
34 { 0, 159024}, 38 { 0, 159024},
35 { 5, 151921}, 39 { 5, 151921},
@@ -46,8 +50,12 @@ static struct abx500_res_to_temp temp_tbl_B_thermistor[] = {
46 {60, 85461}, 50 {60, 85461},
47 {65, 82869}, 51 {65, 82869},
48}; 52};
53EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
54
55const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
56EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
49 57
50static struct abx500_v_to_cap cap_tbl_A_thermistor[] = { 58static const struct abx500_v_to_cap cap_tbl_a_thermistor[] = {
51 {4171, 100}, 59 {4171, 100},
52 {4114, 95}, 60 {4114, 95},
53 {4009, 83}, 61 {4009, 83},
@@ -70,7 +78,7 @@ static struct abx500_v_to_cap cap_tbl_A_thermistor[] = {
70 {3247, 0}, 78 {3247, 0},
71}; 79};
72 80
73static struct abx500_v_to_cap cap_tbl_B_thermistor[] = { 81static const struct abx500_v_to_cap cap_tbl_b_thermistor[] = {
74 {4161, 100}, 82 {4161, 100},
75 {4124, 98}, 83 {4124, 98},
76 {4044, 90}, 84 {4044, 90},
@@ -93,7 +101,7 @@ static struct abx500_v_to_cap cap_tbl_B_thermistor[] = {
93 {3250, 0}, 101 {3250, 0},
94}; 102};
95 103
96static struct abx500_v_to_cap cap_tbl[] = { 104static const struct abx500_v_to_cap cap_tbl[] = {
97 {4186, 100}, 105 {4186, 100},
98 {4163, 99}, 106 {4163, 99},
99 {4114, 95}, 107 {4114, 95},
@@ -124,7 +132,7 @@ static struct abx500_v_to_cap cap_tbl[] = {
124 * Note that the res_to_temp table must be strictly sorted by falling 132 * Note that the res_to_temp table must be strictly sorted by falling
125 * resistance values to work. 133 * resistance values to work.
126 */ 134 */
127static struct abx500_res_to_temp temp_tbl[] = { 135static const struct abx500_res_to_temp temp_tbl[] = {
128 {-5, 214834}, 136 {-5, 214834},
129 { 0, 162943}, 137 { 0, 162943},
130 { 5, 124820}, 138 { 5, 124820},
@@ -146,7 +154,7 @@ static struct abx500_res_to_temp temp_tbl[] = {
146 * Note that the batres_vs_temp table must be strictly sorted by falling 154 * Note that the batres_vs_temp table must be strictly sorted by falling
147 * temperature values to work. 155 * temperature values to work.
148 */ 156 */
149static struct batres_vs_temp temp_to_batres_tbl_thermistor[] = { 157static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
150 { 40, 120}, 158 { 40, 120},
151 { 30, 135}, 159 { 30, 135},
152 { 20, 165}, 160 { 20, 165},
@@ -160,7 +168,7 @@ static struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
160 * Note that the batres_vs_temp table must be strictly sorted by falling 168 * Note that the batres_vs_temp table must be strictly sorted by falling
161 * temperature values to work. 169 * temperature values to work.
162 */ 170 */
163static struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = { 171static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
164 { 60, 300}, 172 { 60, 300},
165 { 30, 300}, 173 { 30, 300},
166 { 20, 300}, 174 { 20, 300},
@@ -171,7 +179,7 @@ static struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
171}; 179};
172 180
173/* battery resistance table for LI ION 9100 battery */ 181/* battery resistance table for LI ION 9100 battery */
174static struct batres_vs_temp temp_to_batres_tbl_9100[] = { 182static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
175 { 60, 180}, 183 { 60, 180},
176 { 30, 180}, 184 { 30, 180},
177 { 20, 180}, 185 { 20, 180},
@@ -230,10 +238,10 @@ static struct abx500_battery_type bat_type_thermistor[] = {
230 .maint_b_chg_timer_h = 200, 238 .maint_b_chg_timer_h = 200,
231 .low_high_cur_lvl = 300, 239 .low_high_cur_lvl = 300,
232 .low_high_vol_lvl = 4000, 240 .low_high_vol_lvl = 4000,
233 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl_A_thermistor), 241 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
234 .r_to_t_tbl = temp_tbl_A_thermistor, 242 .r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
235 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_A_thermistor), 243 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
236 .v_to_cap_tbl = cap_tbl_A_thermistor, 244 .v_to_cap_tbl = cap_tbl_a_thermistor,
237 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 245 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
238 .batres_tbl = temp_to_batres_tbl_thermistor, 246 .batres_tbl = temp_to_batres_tbl_thermistor,
239 247
@@ -258,10 +266,10 @@ static struct abx500_battery_type bat_type_thermistor[] = {
258 .maint_b_chg_timer_h = 200, 266 .maint_b_chg_timer_h = 200,
259 .low_high_cur_lvl = 300, 267 .low_high_cur_lvl = 300,
260 .low_high_vol_lvl = 4000, 268 .low_high_vol_lvl = 4000,
261 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl_B_thermistor), 269 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
262 .r_to_t_tbl = temp_tbl_B_thermistor, 270 .r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
263 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_B_thermistor), 271 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
264 .v_to_cap_tbl = cap_tbl_B_thermistor, 272 .v_to_cap_tbl = cap_tbl_b_thermistor,
265 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 273 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
266 .batres_tbl = temp_to_batres_tbl_thermistor, 274 .batres_tbl = temp_to_batres_tbl_thermistor,
267 }, 275 },
@@ -407,15 +415,27 @@ static const struct abx500_fg_parameters fg = {
407 .battok_raising_th_sel1 = 2860, 415 .battok_raising_th_sel1 = 2860,
408 .maint_thres = 95, 416 .maint_thres = 95,
409 .user_cap_limit = 15, 417 .user_cap_limit = 15,
418 .pcut_enable = 1,
419 .pcut_max_time = 127,
420 .pcut_flag_time = 112,
421 .pcut_max_restart = 15,
422 .pcut_debounce_time = 2,
410}; 423};
411 424
412static const struct abx500_maxim_parameters maxi_params = { 425static const struct abx500_maxim_parameters ab8500_maxi_params = {
413 .ena_maxi = true, 426 .ena_maxi = true,
414 .chg_curr = 910, 427 .chg_curr = 910,
415 .wait_cycles = 10, 428 .wait_cycles = 10,
416 .charger_curr_step = 100, 429 .charger_curr_step = 100,
417}; 430};
418 431
432static const struct abx500_maxim_parameters abx540_maxi_params = {
433 .ena_maxi = true,
434 .chg_curr = 3000,
435 .wait_cycles = 10,
436 .charger_curr_step = 200,
437};
438
419static const struct abx500_bm_charger_parameters chg = { 439static const struct abx500_bm_charger_parameters chg = {
420 .usb_volt_max = 5500, 440 .usb_volt_max = 5500,
421 .usb_curr_max = 1500, 441 .usb_curr_max = 1500,
@@ -423,6 +443,46 @@ static const struct abx500_bm_charger_parameters chg = {
423 .ac_curr_max = 1500, 443 .ac_curr_max = 1500,
424}; 444};
425 445
446/*
447 * This array maps the raw hex value to charger output current used by the
448 * AB8500 values
449 */
450static int ab8500_charge_output_curr_map[] = {
451 100, 200, 300, 400, 500, 600, 700, 800,
452 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
453};
454
455static int ab8540_charge_output_curr_map[] = {
456 0, 0, 0, 75, 100, 125, 150, 175,
457 200, 225, 250, 275, 300, 325, 350, 375,
458 400, 425, 450, 475, 500, 525, 550, 575,
459 600, 625, 650, 675, 700, 725, 750, 775,
460 800, 825, 850, 875, 900, 925, 950, 975,
461 1000, 1025, 1050, 1075, 1100, 1125, 1150, 1175,
462 1200, 1225, 1250, 1275, 1300, 1325, 1350, 1375,
463 1400, 1425, 1450, 1500, 1600, 1700, 1900, 2000,
464};
465
466/*
467 * This array maps the raw hex value to charger input current used by the
468 * AB8500 values
469 */
470static int ab8500_charge_input_curr_map[] = {
471 50, 98, 193, 290, 380, 450, 500, 600,
472 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
473};
474
475static int ab8540_charge_input_curr_map[] = {
476 25, 50, 75, 100, 125, 150, 175, 200,
477 225, 250, 275, 300, 325, 350, 375, 400,
478 425, 450, 475, 500, 525, 550, 575, 600,
479 625, 650, 675, 700, 725, 750, 775, 800,
480 825, 850, 875, 900, 925, 950, 975, 1000,
481 1025, 1050, 1075, 1100, 1125, 1150, 1175, 1200,
482 1225, 1250, 1275, 1300, 1325, 1350, 1375, 1400,
483 1425, 1450, 1475, 1500, 1500, 1500, 1500, 1500,
484};
485
426struct abx500_bm_data ab8500_bm_data = { 486struct abx500_bm_data ab8500_bm_data = {
427 .temp_under = 3, 487 .temp_under = 3,
428 .temp_low = 8, 488 .temp_low = 8,
@@ -442,22 +502,60 @@ struct abx500_bm_data ab8500_bm_data = {
442 .fg_res = 100, 502 .fg_res = 100,
443 .cap_levels = &cap_levels, 503 .cap_levels = &cap_levels,
444 .bat_type = bat_type_thermistor, 504 .bat_type = bat_type_thermistor,
445 .n_btypes = 3, 505 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
446 .batt_id = 0, 506 .batt_id = 0,
447 .interval_charging = 5, 507 .interval_charging = 5,
448 .interval_not_charging = 120, 508 .interval_not_charging = 120,
449 .temp_hysteresis = 3, 509 .temp_hysteresis = 3,
450 .gnd_lift_resistance = 34, 510 .gnd_lift_resistance = 34,
451 .maxi = &maxi_params, 511 .chg_output_curr = ab8500_charge_output_curr_map,
512 .n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map),
513 .maxi = &ab8500_maxi_params,
452 .chg_params = &chg, 514 .chg_params = &chg,
453 .fg_params = &fg, 515 .fg_params = &fg,
516 .chg_input_curr = ab8500_charge_input_curr_map,
517 .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
518};
519
520struct abx500_bm_data ab8540_bm_data = {
521 .temp_under = 3,
522 .temp_low = 8,
523 .temp_high = 43,
524 .temp_over = 48,
525 .main_safety_tmr_h = 4,
526 .temp_interval_chg = 20,
527 .temp_interval_nochg = 120,
528 .usb_safety_tmr_h = 4,
529 .bkup_bat_v = BUP_VCH_SEL_2P6V,
530 .bkup_bat_i = BUP_ICH_SEL_150UA,
531 .no_maintenance = false,
532 .capacity_scaling = false,
533 .adc_therm = ABx500_ADC_THERM_BATCTRL,
534 .chg_unknown_bat = false,
535 .enable_overshoot = false,
536 .fg_res = 100,
537 .cap_levels = &cap_levels,
538 .bat_type = bat_type_thermistor,
539 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
540 .batt_id = 0,
541 .interval_charging = 5,
542 .interval_not_charging = 120,
543 .temp_hysteresis = 3,
544 .gnd_lift_resistance = 0,
545 .maxi = &abx540_maxi_params,
546 .chg_params = &chg,
547 .fg_params = &fg,
548 .chg_output_curr = ab8540_charge_output_curr_map,
549 .n_chg_out_curr = ARRAY_SIZE(ab8540_charge_output_curr_map),
550 .chg_input_curr = ab8540_charge_input_curr_map,
551 .n_chg_in_curr = ARRAY_SIZE(ab8540_charge_input_curr_map),
454}; 552};
455 553
456int ab8500_bm_of_probe(struct device *dev, 554int ab8500_bm_of_probe(struct device *dev,
457 struct device_node *np, 555 struct device_node *np,
458 struct abx500_bm_data *bm) 556 struct abx500_bm_data *bm)
459{ 557{
460 struct batres_vs_temp *tmp_batres_tbl; 558 const struct batres_vs_temp *tmp_batres_tbl;
461 struct device_node *battery_node; 559 struct device_node *battery_node;
462 const char *btech; 560 const char *btech;
463 int i; 561 int i;
diff --git a/drivers/power/ab8500_btemp.c b/drivers/power/ab8500_btemp.c
index 07689064996e..d412d34bf3df 100644
--- a/drivers/power/ab8500_btemp.c
+++ b/drivers/power/ab8500_btemp.c
@@ -42,6 +42,9 @@
42#define BTEMP_BATCTRL_CURR_SRC_16UA 16 42#define BTEMP_BATCTRL_CURR_SRC_16UA 16
43#define BTEMP_BATCTRL_CURR_SRC_18UA 18 43#define BTEMP_BATCTRL_CURR_SRC_18UA 18
44 44
45#define BTEMP_BATCTRL_CURR_SRC_60UA 60
46#define BTEMP_BATCTRL_CURR_SRC_120UA 120
47
45#define to_ab8500_btemp_device_info(x) container_of((x), \ 48#define to_ab8500_btemp_device_info(x) container_of((x), \
46 struct ab8500_btemp, btemp_psy); 49 struct ab8500_btemp, btemp_psy);
47 50
@@ -76,8 +79,8 @@ struct ab8500_btemp_ranges {
76 * @dev: Pointer to the structure device 79 * @dev: Pointer to the structure device
77 * @node: List of AB8500 BTEMPs, hence prepared for reentrance 80 * @node: List of AB8500 BTEMPs, hence prepared for reentrance
78 * @curr_source: What current source we use, in uA 81 * @curr_source: What current source we use, in uA
79 * @bat_temp: Battery temperature in degree Celcius 82 * @bat_temp: Dispatched battery temperature in degree Celcius
80 * @prev_bat_temp Last dispatched battery temperature 83 * @prev_bat_temp Last measured battery temperature in degree Celcius
81 * @parent: Pointer to the struct ab8500 84 * @parent: Pointer to the struct ab8500
82 * @gpadc: Pointer to the struct gpadc 85 * @gpadc: Pointer to the struct gpadc
83 * @fg: Pointer to the struct fg 86 * @fg: Pointer to the struct fg
@@ -128,6 +131,7 @@ struct ab8500_btemp *ab8500_btemp_get(void)
128 131
129 return btemp; 132 return btemp;
130} 133}
134EXPORT_SYMBOL(ab8500_btemp_get);
131 135
132/** 136/**
133 * ab8500_btemp_batctrl_volt_to_res() - convert batctrl voltage to resistance 137 * ab8500_btemp_batctrl_volt_to_res() - convert batctrl voltage to resistance
@@ -155,7 +159,7 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
155 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL) { 159 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL) {
156 /* 160 /*
157 * If the battery has internal NTC, we use the current 161 * If the battery has internal NTC, we use the current
158 * source to calculate the resistance, 7uA or 20uA 162 * source to calculate the resistance.
159 */ 163 */
160 rbs = (v_batctrl * 1000 164 rbs = (v_batctrl * 1000
161 - di->bm->gnd_lift_resistance * inst_curr) 165 - di->bm->gnd_lift_resistance * inst_curr)
@@ -216,7 +220,12 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
216 /* Only do this for batteries with internal NTC */ 220 /* Only do this for batteries with internal NTC */
217 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && enable) { 221 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && enable) {
218 222
219 if (is_ab9540(di->parent) || is_ab8505(di->parent)) { 223 if (is_ab8540(di->parent)) {
224 if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_60UA)
225 curr = BAT_CTRL_60U_ENA;
226 else
227 curr = BAT_CTRL_120U_ENA;
228 } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
220 if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_16UA) 229 if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_16UA)
221 curr = BAT_CTRL_16U_ENA; 230 curr = BAT_CTRL_16U_ENA;
222 else 231 else
@@ -257,7 +266,14 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
257 } else if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && !enable) { 266 } else if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && !enable) {
258 dev_dbg(di->dev, "Disable BATCTRL curr source\n"); 267 dev_dbg(di->dev, "Disable BATCTRL curr source\n");
259 268
260 if (is_ab9540(di->parent) || is_ab8505(di->parent)) { 269 if (is_ab8540(di->parent)) {
270 /* Write 0 to the curr bits */
271 ret = abx500_mask_and_set_register_interruptible(
272 di->dev,
273 AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
274 BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA,
275 ~(BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA));
276 } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
261 /* Write 0 to the curr bits */ 277 /* Write 0 to the curr bits */
262 ret = abx500_mask_and_set_register_interruptible( 278 ret = abx500_mask_and_set_register_interruptible(
263 di->dev, 279 di->dev,
@@ -314,7 +330,13 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
314 * if we got an error above 330 * if we got an error above
315 */ 331 */
316disable_curr_source: 332disable_curr_source:
317 if (is_ab9540(di->parent) || is_ab8505(di->parent)) { 333 if (is_ab8540(di->parent)) {
334 /* Write 0 to the curr bits */
335 ret = abx500_mask_and_set_register_interruptible(di->dev,
336 AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
337 BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA,
338 ~(BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA));
339 } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
318 /* Write 0 to the curr bits */ 340 /* Write 0 to the curr bits */
319 ret = abx500_mask_and_set_register_interruptible(di->dev, 341 ret = abx500_mask_and_set_register_interruptible(di->dev,
320 AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, 342 AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
@@ -541,7 +563,9 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
541{ 563{
542 int res; 564 int res;
543 u8 i; 565 u8 i;
544 if (is_ab9540(di->parent) || is_ab8505(di->parent)) 566 if (is_ab8540(di->parent))
567 di->curr_source = BTEMP_BATCTRL_CURR_SRC_60UA;
568 else if (is_ab9540(di->parent) || is_ab8505(di->parent))
545 di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA; 569 di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA;
546 else 570 else
547 di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA; 571 di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA;
@@ -579,12 +603,17 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
579 603
580 /* 604 /*
581 * We only have to change current source if the 605 * We only have to change current source if the
582 * detected type is Type 1, else we use the 7uA source 606 * detected type is Type 1.
583 */ 607 */
584 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && 608 if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL &&
585 di->bm->batt_id == 1) { 609 di->bm->batt_id == 1) {
586 if (is_ab9540(di->parent) || is_ab8505(di->parent)) { 610 if (is_ab8540(di->parent)) {
587 dev_dbg(di->dev, "Set BATCTRL current source to 16uA\n"); 611 dev_dbg(di->dev,
612 "Set BATCTRL current source to 60uA\n");
613 di->curr_source = BTEMP_BATCTRL_CURR_SRC_60UA;
614 } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
615 dev_dbg(di->dev,
616 "Set BATCTRL current source to 16uA\n");
588 di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA; 617 di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA;
589 } else { 618 } else {
590 dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n"); 619 dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n");
@@ -604,22 +633,37 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
604static void ab8500_btemp_periodic_work(struct work_struct *work) 633static void ab8500_btemp_periodic_work(struct work_struct *work)
605{ 634{
606 int interval; 635 int interval;
636 int bat_temp;
607 struct ab8500_btemp *di = container_of(work, 637 struct ab8500_btemp *di = container_of(work,
608 struct ab8500_btemp, btemp_periodic_work.work); 638 struct ab8500_btemp, btemp_periodic_work.work);
609 639
610 if (!di->initialized) { 640 if (!di->initialized) {
611 di->initialized = true;
612 /* Identify the battery */ 641 /* Identify the battery */
613 if (ab8500_btemp_id(di) < 0) 642 if (ab8500_btemp_id(di) < 0)
614 dev_warn(di->dev, "failed to identify the battery\n"); 643 dev_warn(di->dev, "failed to identify the battery\n");
615 } 644 }
616 645
617 di->bat_temp = ab8500_btemp_measure_temp(di); 646 bat_temp = ab8500_btemp_measure_temp(di);
618 647 /*
619 if (di->bat_temp != di->prev_bat_temp) { 648 * Filter battery temperature.
620 di->prev_bat_temp = di->bat_temp; 649 * Allow direct updates on temperature only if two samples result in
650 * same temperature. Else only allow 1 degree change from previous
651 * reported value in the direction of the new measurement.
652 */
653 if ((bat_temp == di->prev_bat_temp) || !di->initialized) {
654 if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) {
655 di->initialized = true;
656 di->bat_temp = bat_temp;
657 power_supply_changed(&di->btemp_psy);
658 }
659 } else if (bat_temp < di->prev_bat_temp) {
660 di->bat_temp--;
661 power_supply_changed(&di->btemp_psy);
662 } else if (bat_temp > di->prev_bat_temp) {
663 di->bat_temp++;
621 power_supply_changed(&di->btemp_psy); 664 power_supply_changed(&di->btemp_psy);
622 } 665 }
666 di->prev_bat_temp = bat_temp;
623 667
624 if (di->events.ac_conn || di->events.usb_conn) 668 if (di->events.ac_conn || di->events.usb_conn)
625 interval = di->bm->temp_interval_chg; 669 interval = di->bm->temp_interval_chg;
@@ -772,7 +816,7 @@ static void ab8500_btemp_periodic(struct ab8500_btemp *di,
772 * 816 *
773 * Returns battery temperature 817 * Returns battery temperature
774 */ 818 */
775static int ab8500_btemp_get_temp(struct ab8500_btemp *di) 819int ab8500_btemp_get_temp(struct ab8500_btemp *di)
776{ 820{
777 int temp = 0; 821 int temp = 0;
778 822
@@ -808,6 +852,7 @@ static int ab8500_btemp_get_temp(struct ab8500_btemp *di)
808 } 852 }
809 return temp; 853 return temp;
810} 854}
855EXPORT_SYMBOL(ab8500_btemp_get_temp);
811 856
812/** 857/**
813 * ab8500_btemp_get_batctrl_temp() - get the temperature 858 * ab8500_btemp_get_batctrl_temp() - get the temperature
@@ -819,6 +864,7 @@ int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp)
819{ 864{
820 return btemp->bat_temp * 1000; 865 return btemp->bat_temp * 1000;
821} 866}
867EXPORT_SYMBOL(ab8500_btemp_get_batctrl_temp);
822 868
823/** 869/**
824 * ab8500_btemp_get_property() - get the btemp properties 870 * ab8500_btemp_get_property() - get the btemp properties
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index 24b30b7ea5ca..a558318b169c 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -15,6 +15,7 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/notifier.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/power_supply.h> 21#include <linux/power_supply.h>
@@ -52,10 +53,15 @@
52#define VBUS_DET_DBNC100 0x02 53#define VBUS_DET_DBNC100 0x02
53#define VBUS_DET_DBNC1 0x01 54#define VBUS_DET_DBNC1 0x01
54#define OTP_ENABLE_WD 0x01 55#define OTP_ENABLE_WD 0x01
56#define DROP_COUNT_RESET 0x01
57#define USB_CH_DET 0x01
55 58
56#define MAIN_CH_INPUT_CURR_SHIFT 4 59#define MAIN_CH_INPUT_CURR_SHIFT 4
57#define VBUS_IN_CURR_LIM_SHIFT 4 60#define VBUS_IN_CURR_LIM_SHIFT 4
61#define AB8540_VBUS_IN_CURR_LIM_SHIFT 2
58#define AUTO_VBUS_IN_CURR_LIM_SHIFT 4 62#define AUTO_VBUS_IN_CURR_LIM_SHIFT 4
63#define AB8540_AUTO_VBUS_IN_CURR_MASK 0x3F
64#define VBUS_IN_CURR_LIM_RETRY_SET_TIME 30 /* seconds */
59 65
60#define LED_INDICATOR_PWM_ENA 0x01 66#define LED_INDICATOR_PWM_ENA 0x01
61#define LED_INDICATOR_PWM_DIS 0x00 67#define LED_INDICATOR_PWM_DIS 0x00
@@ -77,7 +83,9 @@
77 83
78/* UsbLineStatus register bit masks */ 84/* UsbLineStatus register bit masks */
79#define AB8500_USB_LINK_STATUS 0x78 85#define AB8500_USB_LINK_STATUS 0x78
86#define AB8505_USB_LINK_STATUS 0xF8
80#define AB8500_STD_HOST_SUSP 0x18 87#define AB8500_STD_HOST_SUSP 0x18
88#define USB_LINK_STATUS_SHIFT 3
81 89
82/* Watchdog timeout constant */ 90/* Watchdog timeout constant */
83#define WD_TIMER 0x30 /* 4min */ 91#define WD_TIMER 0x30 /* 4min */
@@ -96,6 +104,10 @@
96#define AB8500_SW_CONTROL_FALLBACK 0x03 104#define AB8500_SW_CONTROL_FALLBACK 0x03
97/* Wait for enumeration before charing in us */ 105/* Wait for enumeration before charing in us */
98#define WAIT_ACA_RID_ENUMERATION (5 * 1000) 106#define WAIT_ACA_RID_ENUMERATION (5 * 1000)
107/*External charger control*/
108#define AB8500_SYS_CHARGER_CONTROL_REG 0x52
109#define EXTERNAL_CHARGER_DISABLE_REG_VAL 0x03
110#define EXTERNAL_CHARGER_ENABLE_REG_VAL 0x07
99 111
100/* UsbLineStatus register - usb types */ 112/* UsbLineStatus register - usb types */
101enum ab8500_charger_link_status { 113enum ab8500_charger_link_status {
@@ -196,10 +208,15 @@ struct ab8500_charger_usb_state {
196 spinlock_t usb_lock; 208 spinlock_t usb_lock;
197}; 209};
198 210
211struct ab8500_charger_max_usb_in_curr {
212 int usb_type_max;
213 int set_max;
214 int calculated_max;
215};
216
199/** 217/**
200 * struct ab8500_charger - ab8500 Charger device information 218 * struct ab8500_charger - ab8500 Charger device information
201 * @dev: Pointer to the structure device 219 * @dev: Pointer to the structure device
202 * @max_usb_in_curr: Max USB charger input current
203 * @vbus_detected: VBUS detected 220 * @vbus_detected: VBUS detected
204 * @vbus_detected_start: 221 * @vbus_detected_start:
205 * VBUS detected during startup 222 * VBUS detected during startup
@@ -214,7 +231,6 @@ struct ab8500_charger_usb_state {
214 * @autopower Indicate if we should have automatic pwron after pwrloss 231 * @autopower Indicate if we should have automatic pwron after pwrloss
215 * @autopower_cfg platform specific power config support for "pwron after pwrloss" 232 * @autopower_cfg platform specific power config support for "pwron after pwrloss"
216 * @invalid_charger_detect_state State when forcing AB to use invalid charger 233 * @invalid_charger_detect_state State when forcing AB to use invalid charger
217 * @is_usb_host: Indicate if last detected USB type is host
218 * @is_aca_rid: Incicate if accessory is ACA type 234 * @is_aca_rid: Incicate if accessory is ACA type
219 * @current_stepping_sessions: 235 * @current_stepping_sessions:
220 * Counter for current stepping sessions 236 * Counter for current stepping sessions
@@ -223,6 +239,7 @@ struct ab8500_charger_usb_state {
223 * @bm: Platform specific battery management information 239 * @bm: Platform specific battery management information
224 * @flags: Structure for information about events triggered 240 * @flags: Structure for information about events triggered
225 * @usb_state: Structure for usb stack information 241 * @usb_state: Structure for usb stack information
242 * @max_usb_in_curr: Max USB charger input current
226 * @ac_chg: AC charger power supply 243 * @ac_chg: AC charger power supply
227 * @usb_chg: USB charger power supply 244 * @usb_chg: USB charger power supply
228 * @ac: Structure that holds the AC charger properties 245 * @ac: Structure that holds the AC charger properties
@@ -254,7 +271,6 @@ struct ab8500_charger_usb_state {
254 */ 271 */
255struct ab8500_charger { 272struct ab8500_charger {
256 struct device *dev; 273 struct device *dev;
257 int max_usb_in_curr;
258 bool vbus_detected; 274 bool vbus_detected;
259 bool vbus_detected_start; 275 bool vbus_detected_start;
260 bool ac_conn; 276 bool ac_conn;
@@ -266,7 +282,6 @@ struct ab8500_charger {
266 bool autopower; 282 bool autopower;
267 bool autopower_cfg; 283 bool autopower_cfg;
268 int invalid_charger_detect_state; 284 int invalid_charger_detect_state;
269 bool is_usb_host;
270 int is_aca_rid; 285 int is_aca_rid;
271 atomic_t current_stepping_sessions; 286 atomic_t current_stepping_sessions;
272 struct ab8500 *parent; 287 struct ab8500 *parent;
@@ -274,6 +289,7 @@ struct ab8500_charger {
274 struct abx500_bm_data *bm; 289 struct abx500_bm_data *bm;
275 struct ab8500_charger_event_flags flags; 290 struct ab8500_charger_event_flags flags;
276 struct ab8500_charger_usb_state usb_state; 291 struct ab8500_charger_usb_state usb_state;
292 struct ab8500_charger_max_usb_in_curr max_usb_in_curr;
277 struct ux500_charger ac_chg; 293 struct ux500_charger ac_chg;
278 struct ux500_charger usb_chg; 294 struct ux500_charger usb_chg;
279 struct ab8500_charger_info ac; 295 struct ab8500_charger_info ac;
@@ -415,13 +431,18 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,
415 if (connected != di->usb.charger_connected) { 431 if (connected != di->usb.charger_connected) {
416 dev_dbg(di->dev, "USB connected:%i\n", connected); 432 dev_dbg(di->dev, "USB connected:%i\n", connected);
417 di->usb.charger_connected = connected; 433 di->usb.charger_connected = connected;
434
435 if (!connected)
436 di->flags.vbus_drop_end = false;
437
418 sysfs_notify(&di->usb_chg.psy.dev->kobj, NULL, "present"); 438 sysfs_notify(&di->usb_chg.psy.dev->kobj, NULL, "present");
419 439
420 if (connected) { 440 if (connected) {
421 mutex_lock(&di->charger_attached_mutex); 441 mutex_lock(&di->charger_attached_mutex);
422 mutex_unlock(&di->charger_attached_mutex); 442 mutex_unlock(&di->charger_attached_mutex);
423 443
424 queue_delayed_work(di->charger_wq, 444 if (is_ab8500(di->parent))
445 queue_delayed_work(di->charger_wq,
425 &di->usb_charger_attached_work, 446 &di->usb_charger_attached_work,
426 HZ); 447 HZ);
427 } else { 448 } else {
@@ -668,23 +689,19 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
668 case USB_STAT_STD_HOST_C_S: 689 case USB_STAT_STD_HOST_C_S:
669 dev_dbg(di->dev, "USB Type - Standard host is " 690 dev_dbg(di->dev, "USB Type - Standard host is "
670 "detected through USB driver\n"); 691 "detected through USB driver\n");
671 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 692 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
672 di->is_usb_host = true;
673 di->is_aca_rid = 0; 693 di->is_aca_rid = 0;
674 break; 694 break;
675 case USB_STAT_HOST_CHG_HS_CHIRP: 695 case USB_STAT_HOST_CHG_HS_CHIRP:
676 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 696 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
677 di->is_usb_host = true;
678 di->is_aca_rid = 0; 697 di->is_aca_rid = 0;
679 break; 698 break;
680 case USB_STAT_HOST_CHG_HS: 699 case USB_STAT_HOST_CHG_HS:
681 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 700 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
682 di->is_usb_host = true;
683 di->is_aca_rid = 0; 701 di->is_aca_rid = 0;
684 break; 702 break;
685 case USB_STAT_ACA_RID_C_HS: 703 case USB_STAT_ACA_RID_C_HS:
686 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P9; 704 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P9;
687 di->is_usb_host = false;
688 di->is_aca_rid = 0; 705 di->is_aca_rid = 0;
689 break; 706 break;
690 case USB_STAT_ACA_RID_A: 707 case USB_STAT_ACA_RID_A:
@@ -693,8 +710,7 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
693 * can consume (900mA). Closest level is 500mA 710 * can consume (900mA). Closest level is 500mA
694 */ 711 */
695 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n"); 712 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n");
696 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 713 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
697 di->is_usb_host = false;
698 di->is_aca_rid = 1; 714 di->is_aca_rid = 1;
699 break; 715 break;
700 case USB_STAT_ACA_RID_B: 716 case USB_STAT_ACA_RID_B:
@@ -702,38 +718,35 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
702 * Dedicated charger level minus 120mA (20mA for ACA and 718 * Dedicated charger level minus 120mA (20mA for ACA and
703 * 100mA for potential accessory). Closest level is 1300mA 719 * 100mA for potential accessory). Closest level is 1300mA
704 */ 720 */
705 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P3; 721 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P3;
706 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 722 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status,
707 di->max_usb_in_curr); 723 di->max_usb_in_curr.usb_type_max);
708 di->is_usb_host = false;
709 di->is_aca_rid = 1; 724 di->is_aca_rid = 1;
710 break; 725 break;
711 case USB_STAT_HOST_CHG_NM: 726 case USB_STAT_HOST_CHG_NM:
712 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 727 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
713 di->is_usb_host = true;
714 di->is_aca_rid = 0; 728 di->is_aca_rid = 0;
715 break; 729 break;
716 case USB_STAT_DEDICATED_CHG: 730 case USB_STAT_DEDICATED_CHG:
717 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5; 731 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5;
718 di->is_usb_host = false;
719 di->is_aca_rid = 0; 732 di->is_aca_rid = 0;
720 break; 733 break;
721 case USB_STAT_ACA_RID_C_HS_CHIRP: 734 case USB_STAT_ACA_RID_C_HS_CHIRP:
722 case USB_STAT_ACA_RID_C_NM: 735 case USB_STAT_ACA_RID_C_NM:
723 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5; 736 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5;
724 di->is_usb_host = false;
725 di->is_aca_rid = 1; 737 di->is_aca_rid = 1;
726 break; 738 break;
727 case USB_STAT_NOT_CONFIGURED: 739 case USB_STAT_NOT_CONFIGURED:
728 if (di->vbus_detected) { 740 if (di->vbus_detected) {
729 di->usb_device_is_unrecognised = true; 741 di->usb_device_is_unrecognised = true;
730 dev_dbg(di->dev, "USB Type - Legacy charger.\n"); 742 dev_dbg(di->dev, "USB Type - Legacy charger.\n");
731 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5; 743 di->max_usb_in_curr.usb_type_max =
744 USB_CH_IP_CUR_LVL_1P5;
732 break; 745 break;
733 } 746 }
734 case USB_STAT_HM_IDGND: 747 case USB_STAT_HM_IDGND:
735 dev_err(di->dev, "USB Type - Charging not allowed\n"); 748 dev_err(di->dev, "USB Type - Charging not allowed\n");
736 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05; 749 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05;
737 ret = -ENXIO; 750 ret = -ENXIO;
738 break; 751 break;
739 case USB_STAT_RESERVED: 752 case USB_STAT_RESERVED:
@@ -743,12 +756,13 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
743 "VBUS has collapsed\n"); 756 "VBUS has collapsed\n");
744 ret = -ENXIO; 757 ret = -ENXIO;
745 break; 758 break;
746 } 759 } else {
747 if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
748 dev_dbg(di->dev, "USB Type - Charging not allowed\n"); 760 dev_dbg(di->dev, "USB Type - Charging not allowed\n");
749 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05; 761 di->max_usb_in_curr.usb_type_max =
762 USB_CH_IP_CUR_LVL_0P05;
750 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", 763 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d",
751 link_status, di->max_usb_in_curr); 764 link_status,
765 di->max_usb_in_curr.usb_type_max);
752 ret = -ENXIO; 766 ret = -ENXIO;
753 break; 767 break;
754 } 768 }
@@ -757,23 +771,24 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
757 case USB_STAT_CARKIT_2: 771 case USB_STAT_CARKIT_2:
758 case USB_STAT_ACA_DOCK_CHARGER: 772 case USB_STAT_ACA_DOCK_CHARGER:
759 case USB_STAT_CHARGER_LINE_1: 773 case USB_STAT_CHARGER_LINE_1:
760 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 774 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
761 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 775 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status,
762 di->max_usb_in_curr); 776 di->max_usb_in_curr.usb_type_max);
763 case USB_STAT_NOT_VALID_LINK: 777 case USB_STAT_NOT_VALID_LINK:
764 dev_err(di->dev, "USB Type invalid - try charging anyway\n"); 778 dev_err(di->dev, "USB Type invalid - try charging anyway\n");
765 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 779 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
766 break; 780 break;
767 781
768 default: 782 default:
769 dev_err(di->dev, "USB Type - Unknown\n"); 783 dev_err(di->dev, "USB Type - Unknown\n");
770 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05; 784 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05;
771 ret = -ENXIO; 785 ret = -ENXIO;
772 break; 786 break;
773 }; 787 };
774 788
789 di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max;
775 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", 790 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d",
776 link_status, di->max_usb_in_curr); 791 link_status, di->max_usb_in_curr.set_max);
777 792
778 return ret; 793 return ret;
779} 794}
@@ -796,21 +811,22 @@ static int ab8500_charger_read_usb_type(struct ab8500_charger *di)
796 dev_err(di->dev, "%s ab8500 read failed\n", __func__); 811 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
797 return ret; 812 return ret;
798 } 813 }
799 if (is_ab8500(di->parent)) { 814 if (is_ab8500(di->parent))
800 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, 815 ret = abx500_get_register_interruptible(di->dev, AB8500_USB,
801 AB8500_USB_LINE_STAT_REG, &val); 816 AB8500_USB_LINE_STAT_REG, &val);
802 } else { 817 else
803 if (is_ab9540(di->parent) || is_ab8505(di->parent)) 818 ret = abx500_get_register_interruptible(di->dev,
804 ret = abx500_get_register_interruptible(di->dev, 819 AB8500_USB, AB8500_USB_LINK1_STAT_REG, &val);
805 AB8500_USB, AB8500_USB_LINK1_STAT_REG, &val);
806 }
807 if (ret < 0) { 820 if (ret < 0) {
808 dev_err(di->dev, "%s ab8500 read failed\n", __func__); 821 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
809 return ret; 822 return ret;
810 } 823 }
811 824
812 /* get the USB type */ 825 /* get the USB type */
813 val = (val & AB8500_USB_LINK_STATUS) >> 3; 826 if (is_ab8500(di->parent))
827 val = (val & AB8500_USB_LINK_STATUS) >> USB_LINK_STATUS_SHIFT;
828 else
829 val = (val & AB8505_USB_LINK_STATUS) >> USB_LINK_STATUS_SHIFT;
814 ret = ab8500_charger_max_usb_curr(di, 830 ret = ab8500_charger_max_usb_curr(di,
815 (enum ab8500_charger_link_status) val); 831 (enum ab8500_charger_link_status) val);
816 832
@@ -865,7 +881,12 @@ static int ab8500_charger_detect_usb_type(struct ab8500_charger *di)
865 */ 881 */
866 882
867 /* get the USB type */ 883 /* get the USB type */
868 val = (val & AB8500_USB_LINK_STATUS) >> 3; 884 if (is_ab8500(di->parent))
885 val = (val & AB8500_USB_LINK_STATUS) >>
886 USB_LINK_STATUS_SHIFT;
887 else
888 val = (val & AB8505_USB_LINK_STATUS) >>
889 USB_LINK_STATUS_SHIFT;
869 if (val) 890 if (val)
870 break; 891 break;
871 } 892 }
@@ -960,51 +981,6 @@ static int ab8500_charger_voltage_map[] = {
960 4600 , 981 4600 ,
961}; 982};
962 983
963/*
964 * This array maps the raw hex value to charger current used by the AB8500
965 * Values taken from the UM0836
966 */
967static int ab8500_charger_current_map[] = {
968 100 ,
969 200 ,
970 300 ,
971 400 ,
972 500 ,
973 600 ,
974 700 ,
975 800 ,
976 900 ,
977 1000 ,
978 1100 ,
979 1200 ,
980 1300 ,
981 1400 ,
982 1500 ,
983};
984
985/*
986 * This array maps the raw hex value to VBUS input current used by the AB8500
987 * Values taken from the UM0836
988 */
989static int ab8500_charger_vbus_in_curr_map[] = {
990 USB_CH_IP_CUR_LVL_0P05,
991 USB_CH_IP_CUR_LVL_0P09,
992 USB_CH_IP_CUR_LVL_0P19,
993 USB_CH_IP_CUR_LVL_0P29,
994 USB_CH_IP_CUR_LVL_0P38,
995 USB_CH_IP_CUR_LVL_0P45,
996 USB_CH_IP_CUR_LVL_0P5,
997 USB_CH_IP_CUR_LVL_0P6,
998 USB_CH_IP_CUR_LVL_0P7,
999 USB_CH_IP_CUR_LVL_0P8,
1000 USB_CH_IP_CUR_LVL_0P9,
1001 USB_CH_IP_CUR_LVL_1P0,
1002 USB_CH_IP_CUR_LVL_1P1,
1003 USB_CH_IP_CUR_LVL_1P3,
1004 USB_CH_IP_CUR_LVL_1P4,
1005 USB_CH_IP_CUR_LVL_1P5,
1006};
1007
1008static int ab8500_voltage_to_regval(int voltage) 984static int ab8500_voltage_to_regval(int voltage)
1009{ 985{
1010 int i; 986 int i;
@@ -1026,41 +1002,41 @@ static int ab8500_voltage_to_regval(int voltage)
1026 return -1; 1002 return -1;
1027} 1003}
1028 1004
1029static int ab8500_current_to_regval(int curr) 1005static int ab8500_current_to_regval(struct ab8500_charger *di, int curr)
1030{ 1006{
1031 int i; 1007 int i;
1032 1008
1033 if (curr < ab8500_charger_current_map[0]) 1009 if (curr < di->bm->chg_output_curr[0])
1034 return 0; 1010 return 0;
1035 1011
1036 for (i = 0; i < ARRAY_SIZE(ab8500_charger_current_map); i++) { 1012 for (i = 0; i < di->bm->n_chg_out_curr; i++) {
1037 if (curr < ab8500_charger_current_map[i]) 1013 if (curr < di->bm->chg_output_curr[i])
1038 return i - 1; 1014 return i - 1;
1039 } 1015 }
1040 1016
1041 /* If not last element, return error */ 1017 /* If not last element, return error */
1042 i = ARRAY_SIZE(ab8500_charger_current_map) - 1; 1018 i = di->bm->n_chg_out_curr - 1;
1043 if (curr == ab8500_charger_current_map[i]) 1019 if (curr == di->bm->chg_output_curr[i])
1044 return i; 1020 return i;
1045 else 1021 else
1046 return -1; 1022 return -1;
1047} 1023}
1048 1024
1049static int ab8500_vbus_in_curr_to_regval(int curr) 1025static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger *di, int curr)
1050{ 1026{
1051 int i; 1027 int i;
1052 1028
1053 if (curr < ab8500_charger_vbus_in_curr_map[0]) 1029 if (curr < di->bm->chg_input_curr[0])
1054 return 0; 1030 return 0;
1055 1031
1056 for (i = 0; i < ARRAY_SIZE(ab8500_charger_vbus_in_curr_map); i++) { 1032 for (i = 0; i < di->bm->n_chg_in_curr; i++) {
1057 if (curr < ab8500_charger_vbus_in_curr_map[i]) 1033 if (curr < di->bm->chg_input_curr[i])
1058 return i - 1; 1034 return i - 1;
1059 } 1035 }
1060 1036
1061 /* If not last element, return error */ 1037 /* If not last element, return error */
1062 i = ARRAY_SIZE(ab8500_charger_vbus_in_curr_map) - 1; 1038 i = di->bm->n_chg_in_curr - 1;
1063 if (curr == ab8500_charger_vbus_in_curr_map[i]) 1039 if (curr == di->bm->chg_input_curr[i])
1064 return i; 1040 return i;
1065 else 1041 else
1066 return -1; 1042 return -1;
@@ -1077,28 +1053,48 @@ static int ab8500_vbus_in_curr_to_regval(int curr)
1077 */ 1053 */
1078static int ab8500_charger_get_usb_cur(struct ab8500_charger *di) 1054static int ab8500_charger_get_usb_cur(struct ab8500_charger *di)
1079{ 1055{
1056 int ret = 0;
1080 switch (di->usb_state.usb_current) { 1057 switch (di->usb_state.usb_current) {
1081 case 100: 1058 case 100:
1082 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P09; 1059 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P09;
1083 break; 1060 break;
1084 case 200: 1061 case 200:
1085 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P19; 1062 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P19;
1086 break; 1063 break;
1087 case 300: 1064 case 300:
1088 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P29; 1065 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P29;
1089 break; 1066 break;
1090 case 400: 1067 case 400:
1091 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P38; 1068 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P38;
1092 break; 1069 break;
1093 case 500: 1070 case 500:
1094 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 1071 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5;
1095 break; 1072 break;
1096 default: 1073 default:
1097 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P05; 1074 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05;
1098 return -1; 1075 ret = -EPERM;
1099 break; 1076 break;
1100 }; 1077 };
1101 return 0; 1078 di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max;
1079 return ret;
1080}
1081
1082/**
1083 * ab8500_charger_check_continue_stepping() - Check to allow stepping
1084 * @di: pointer to the ab8500_charger structure
1085 * @reg: select what charger register to check
1086 *
1087 * Check if current stepping should be allowed to continue.
1088 * Checks if charger source has not collapsed. If it has, further stepping
1089 * is not allowed.
1090 */
1091static bool ab8500_charger_check_continue_stepping(struct ab8500_charger *di,
1092 int reg)
1093{
1094 if (reg == AB8500_USBCH_IPT_CRNTLVL_REG)
1095 return !di->flags.vbus_drop_end;
1096 else
1097 return true;
1102} 1098}
1103 1099
1104/** 1100/**
@@ -1118,7 +1114,7 @@ static int ab8500_charger_set_current(struct ab8500_charger *di,
1118 int ich, int reg) 1114 int ich, int reg)
1119{ 1115{
1120 int ret = 0; 1116 int ret = 0;
1121 int auto_curr_index, curr_index, prev_curr_index, shift_value, i; 1117 int curr_index, prev_curr_index, shift_value, i;
1122 u8 reg_value; 1118 u8 reg_value;
1123 u32 step_udelay; 1119 u32 step_udelay;
1124 bool no_stepping = false; 1120 bool no_stepping = false;
@@ -1136,39 +1132,27 @@ static int ab8500_charger_set_current(struct ab8500_charger *di,
1136 case AB8500_MCH_IPT_CURLVL_REG: 1132 case AB8500_MCH_IPT_CURLVL_REG:
1137 shift_value = MAIN_CH_INPUT_CURR_SHIFT; 1133 shift_value = MAIN_CH_INPUT_CURR_SHIFT;
1138 prev_curr_index = (reg_value >> shift_value); 1134 prev_curr_index = (reg_value >> shift_value);
1139 curr_index = ab8500_current_to_regval(ich); 1135 curr_index = ab8500_current_to_regval(di, ich);
1140 step_udelay = STEP_UDELAY; 1136 step_udelay = STEP_UDELAY;
1141 if (!di->ac.charger_connected) 1137 if (!di->ac.charger_connected)
1142 no_stepping = true; 1138 no_stepping = true;
1143 break; 1139 break;
1144 case AB8500_USBCH_IPT_CRNTLVL_REG: 1140 case AB8500_USBCH_IPT_CRNTLVL_REG:
1145 shift_value = VBUS_IN_CURR_LIM_SHIFT; 1141 if (is_ab8540(di->parent))
1142 shift_value = AB8540_VBUS_IN_CURR_LIM_SHIFT;
1143 else
1144 shift_value = VBUS_IN_CURR_LIM_SHIFT;
1146 prev_curr_index = (reg_value >> shift_value); 1145 prev_curr_index = (reg_value >> shift_value);
1147 curr_index = ab8500_vbus_in_curr_to_regval(ich); 1146 curr_index = ab8500_vbus_in_curr_to_regval(di, ich);
1148 step_udelay = STEP_UDELAY * 100; 1147 step_udelay = STEP_UDELAY * 100;
1149 1148
1150 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1151 AB8500_CH_USBCH_STAT2_REG, &reg_value);
1152 if (ret < 0) {
1153 dev_err(di->dev, "%s read failed\n", __func__);
1154 goto exit_set_current;
1155 }
1156 auto_curr_index =
1157 reg_value >> AUTO_VBUS_IN_CURR_LIM_SHIFT;
1158
1159 dev_dbg(di->dev, "%s Auto VBUS curr is %d mA\n",
1160 __func__,
1161 ab8500_charger_vbus_in_curr_map[auto_curr_index]);
1162
1163 prev_curr_index = min(prev_curr_index, auto_curr_index);
1164
1165 if (!di->usb.charger_connected) 1149 if (!di->usb.charger_connected)
1166 no_stepping = true; 1150 no_stepping = true;
1167 break; 1151 break;
1168 case AB8500_CH_OPT_CRNTLVL_REG: 1152 case AB8500_CH_OPT_CRNTLVL_REG:
1169 shift_value = 0; 1153 shift_value = 0;
1170 prev_curr_index = (reg_value >> shift_value); 1154 prev_curr_index = (reg_value >> shift_value);
1171 curr_index = ab8500_current_to_regval(ich); 1155 curr_index = ab8500_current_to_regval(di, ich);
1172 step_udelay = STEP_UDELAY; 1156 step_udelay = STEP_UDELAY;
1173 if (curr_index && (curr_index - prev_curr_index) > 1) 1157 if (curr_index && (curr_index - prev_curr_index) > 1)
1174 step_udelay *= 100; 1158 step_udelay *= 100;
@@ -1219,7 +1203,8 @@ static int ab8500_charger_set_current(struct ab8500_charger *di,
1219 usleep_range(step_udelay, step_udelay * 2); 1203 usleep_range(step_udelay, step_udelay * 2);
1220 } 1204 }
1221 } else { 1205 } else {
1222 for (i = prev_curr_index + 1; i <= curr_index; i++) { 1206 bool allow = true;
1207 for (i = prev_curr_index + 1; i <= curr_index && allow; i++) {
1223 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n", 1208 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n",
1224 (u8)i << shift_value, reg); 1209 (u8)i << shift_value, reg);
1225 ret = abx500_set_register_interruptible(di->dev, 1210 ret = abx500_set_register_interruptible(di->dev,
@@ -1230,6 +1215,8 @@ static int ab8500_charger_set_current(struct ab8500_charger *di,
1230 } 1215 }
1231 if (i != curr_index) 1216 if (i != curr_index)
1232 usleep_range(step_udelay, step_udelay * 2); 1217 usleep_range(step_udelay, step_udelay * 2);
1218
1219 allow = ab8500_charger_check_continue_stepping(di, reg);
1233 } 1220 }
1234 } 1221 }
1235 1222
@@ -1255,6 +1242,11 @@ static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di,
1255 1242
1256 /* We should always use to lowest current limit */ 1243 /* We should always use to lowest current limit */
1257 min_value = min(di->bm->chg_params->usb_curr_max, ich_in); 1244 min_value = min(di->bm->chg_params->usb_curr_max, ich_in);
1245 if (di->max_usb_in_curr.set_max > 0)
1246 min_value = min(di->max_usb_in_curr.set_max, min_value);
1247
1248 if (di->usb_state.usb_current >= 0)
1249 min_value = min(di->usb_state.usb_current, min_value);
1258 1250
1259 switch (min_value) { 1251 switch (min_value) {
1260 case 100: 1252 case 100:
@@ -1400,8 +1392,8 @@ static int ab8500_charger_ac_en(struct ux500_charger *charger,
1400 1392
1401 /* Check if the requested voltage or current is valid */ 1393 /* Check if the requested voltage or current is valid */
1402 volt_index = ab8500_voltage_to_regval(vset); 1394 volt_index = ab8500_voltage_to_regval(vset);
1403 curr_index = ab8500_current_to_regval(iset); 1395 curr_index = ab8500_current_to_regval(di, iset);
1404 input_curr_index = ab8500_current_to_regval( 1396 input_curr_index = ab8500_current_to_regval(di,
1405 di->bm->chg_params->ac_curr_max); 1397 di->bm->chg_params->ac_curr_max);
1406 if (volt_index < 0 || curr_index < 0 || input_curr_index < 0) { 1398 if (volt_index < 0 || curr_index < 0 || input_curr_index < 0) {
1407 dev_err(di->dev, 1399 dev_err(di->dev,
@@ -1572,7 +1564,7 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1572 1564
1573 /* Check if the requested voltage or current is valid */ 1565 /* Check if the requested voltage or current is valid */
1574 volt_index = ab8500_voltage_to_regval(vset); 1566 volt_index = ab8500_voltage_to_regval(vset);
1575 curr_index = ab8500_current_to_regval(ich_out); 1567 curr_index = ab8500_current_to_regval(di, ich_out);
1576 if (volt_index < 0 || curr_index < 0) { 1568 if (volt_index < 0 || curr_index < 0) {
1577 dev_err(di->dev, 1569 dev_err(di->dev,
1578 "Charger voltage or current too high, " 1570 "Charger voltage or current too high, "
@@ -1609,7 +1601,8 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1609 di->usb.charger_online = 1; 1601 di->usb.charger_online = 1;
1610 1602
1611 /* USBChInputCurr: current that can be drawn from the usb */ 1603 /* USBChInputCurr: current that can be drawn from the usb */
1612 ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr); 1604 ret = ab8500_charger_set_vbus_in_curr(di,
1605 di->max_usb_in_curr.usb_type_max);
1613 if (ret) { 1606 if (ret) {
1614 dev_err(di->dev, "setting USBChInputCurr failed\n"); 1607 dev_err(di->dev, "setting USBChInputCurr failed\n");
1615 return ret; 1608 return ret;
@@ -1668,8 +1661,7 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1668 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); 1661 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__);
1669 1662
1670 /* Cancel any pending Vbat check work */ 1663 /* Cancel any pending Vbat check work */
1671 if (delayed_work_pending(&di->check_vbat_work)) 1664 cancel_delayed_work(&di->check_vbat_work);
1672 cancel_delayed_work(&di->check_vbat_work);
1673 1665
1674 } 1666 }
1675 ab8500_power_supply_changed(di, &di->usb_chg.psy); 1667 ab8500_power_supply_changed(di, &di->usb_chg.psy);
@@ -1677,6 +1669,128 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1677 return ret; 1669 return ret;
1678} 1670}
1679 1671
1672static int ab8500_external_charger_prepare(struct notifier_block *charger_nb,
1673 unsigned long event, void *data)
1674{
1675 int ret;
1676 struct device *dev = data;
1677 /*Toggle External charger control pin*/
1678 ret = abx500_set_register_interruptible(dev, AB8500_SYS_CTRL1_BLOCK,
1679 AB8500_SYS_CHARGER_CONTROL_REG,
1680 EXTERNAL_CHARGER_DISABLE_REG_VAL);
1681 if (ret < 0) {
1682 dev_err(dev, "write reg failed %d\n", ret);
1683 goto out;
1684 }
1685 ret = abx500_set_register_interruptible(dev, AB8500_SYS_CTRL1_BLOCK,
1686 AB8500_SYS_CHARGER_CONTROL_REG,
1687 EXTERNAL_CHARGER_ENABLE_REG_VAL);
1688 if (ret < 0)
1689 dev_err(dev, "Write reg failed %d\n", ret);
1690
1691out:
1692 return ret;
1693}
1694
1695/**
1696 * ab8500_charger_usb_check_enable() - enable usb charging
1697 * @charger: pointer to the ux500_charger structure
1698 * @vset: charging voltage
1699 * @iset: charger output current
1700 *
1701 * Check if the VBUS charger has been disconnected and reconnected without
1702 * AB8500 rising an interrupt. Returns 0 on success.
1703 */
1704static int ab8500_charger_usb_check_enable(struct ux500_charger *charger,
1705 int vset, int iset)
1706{
1707 u8 usbch_ctrl1 = 0;
1708 int ret = 0;
1709
1710 struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger);
1711
1712 if (!di->usb.charger_connected)
1713 return ret;
1714
1715 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1716 AB8500_USBCH_CTRL1_REG, &usbch_ctrl1);
1717 if (ret < 0) {
1718 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__);
1719 return ret;
1720 }
1721 dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1);
1722
1723 if (!(usbch_ctrl1 & USB_CH_ENA)) {
1724 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n");
1725
1726 ret = abx500_mask_and_set_register_interruptible(di->dev,
1727 AB8500_CHARGER, AB8500_CHARGER_CTRL,
1728 DROP_COUNT_RESET, DROP_COUNT_RESET);
1729 if (ret < 0) {
1730 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__);
1731 return ret;
1732 }
1733
1734 ret = ab8500_charger_usb_en(&di->usb_chg, true, vset, iset);
1735 if (ret < 0) {
1736 dev_err(di->dev, "Failed to enable VBUS charger %d\n",
1737 __LINE__);
1738 return ret;
1739 }
1740 }
1741 return ret;
1742}
1743
1744/**
1745 * ab8500_charger_ac_check_enable() - enable usb charging
1746 * @charger: pointer to the ux500_charger structure
1747 * @vset: charging voltage
1748 * @iset: charger output current
1749 *
1750 * Check if the AC charger has been disconnected and reconnected without
1751 * AB8500 rising an interrupt. Returns 0 on success.
1752 */
1753static int ab8500_charger_ac_check_enable(struct ux500_charger *charger,
1754 int vset, int iset)
1755{
1756 u8 mainch_ctrl1 = 0;
1757 int ret = 0;
1758
1759 struct ab8500_charger *di = to_ab8500_charger_ac_device_info(charger);
1760
1761 if (!di->ac.charger_connected)
1762 return ret;
1763
1764 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1765 AB8500_MCH_CTRL1, &mainch_ctrl1);
1766 if (ret < 0) {
1767 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__);
1768 return ret;
1769 }
1770 dev_dbg(di->dev, "AC charger ctrl: 0x%02x\n", mainch_ctrl1);
1771
1772 if (!(mainch_ctrl1 & MAIN_CH_ENA)) {
1773 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n");
1774
1775 ret = abx500_mask_and_set_register_interruptible(di->dev,
1776 AB8500_CHARGER, AB8500_CHARGER_CTRL,
1777 DROP_COUNT_RESET, DROP_COUNT_RESET);
1778
1779 if (ret < 0) {
1780 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__);
1781 return ret;
1782 }
1783
1784 ret = ab8500_charger_ac_en(&di->usb_chg, true, vset, iset);
1785 if (ret < 0) {
1786 dev_err(di->dev, "failed to enable AC charger %d\n",
1787 __LINE__);
1788 return ret;
1789 }
1790 }
1791 return ret;
1792}
1793
1680/** 1794/**
1681 * ab8500_charger_watchdog_kick() - kick charger watchdog 1795 * ab8500_charger_watchdog_kick() - kick charger watchdog
1682 * @di: pointer to the ab8500_charger structure 1796 * @di: pointer to the ab8500_charger structure
@@ -1734,8 +1848,68 @@ static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
1734 1848
1735 /* Reset the main and usb drop input current measurement counter */ 1849 /* Reset the main and usb drop input current measurement counter */
1736 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, 1850 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1737 AB8500_CHARGER_CTRL, 1851 AB8500_CHARGER_CTRL, DROP_COUNT_RESET);
1738 0x1); 1852 if (ret) {
1853 dev_err(di->dev, "%s write failed\n", __func__);
1854 return ret;
1855 }
1856
1857 return ret;
1858}
1859
1860/**
1861 * ab8540_charger_power_path_enable() - enable usb power path mode
1862 * @charger: pointer to the ux500_charger structure
1863 * @enable: enable/disable flag
1864 *
1865 * Enable or disable the power path for usb mode
1866 * Returns error code in case of failure else 0(on success)
1867 */
1868static int ab8540_charger_power_path_enable(struct ux500_charger *charger,
1869 bool enable)
1870{
1871 int ret;
1872 struct ab8500_charger *di;
1873
1874 if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1875 di = to_ab8500_charger_usb_device_info(charger);
1876 else
1877 return -ENXIO;
1878
1879 ret = abx500_mask_and_set_register_interruptible(di->dev,
1880 AB8500_CHARGER, AB8540_USB_PP_MODE_REG,
1881 BUS_POWER_PATH_MODE_ENA, enable);
1882 if (ret) {
1883 dev_err(di->dev, "%s write failed\n", __func__);
1884 return ret;
1885 }
1886
1887 return ret;
1888}
1889
1890
1891/**
1892 * ab8540_charger_usb_pre_chg_enable() - enable usb pre change
1893 * @charger: pointer to the ux500_charger structure
1894 * @enable: enable/disable flag
1895 *
1896 * Enable or disable the pre-chage for usb mode
1897 * Returns error code in case of failure else 0(on success)
1898 */
1899static int ab8540_charger_usb_pre_chg_enable(struct ux500_charger *charger,
1900 bool enable)
1901{
1902 int ret;
1903 struct ab8500_charger *di;
1904
1905 if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1906 di = to_ab8500_charger_usb_device_info(charger);
1907 else
1908 return -ENXIO;
1909
1910 ret = abx500_mask_and_set_register_interruptible(di->dev,
1911 AB8500_CHARGER, AB8540_USB_PP_CHR_REG,
1912 BUS_POWER_PATH_PRECHG_ENA, enable);
1739 if (ret) { 1913 if (ret) {
1740 dev_err(di->dev, "%s write failed\n", __func__); 1914 dev_err(di->dev, "%s write failed\n", __func__);
1741 return ret; 1915 return ret;
@@ -1823,9 +1997,10 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)
1823 di->vbat > VBAT_TRESH_IP_CUR_RED))) { 1997 di->vbat > VBAT_TRESH_IP_CUR_RED))) {
1824 1998
1825 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d," 1999 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d,"
1826 " old: %d\n", di->max_usb_in_curr, di->vbat, 2000 " old: %d\n", di->max_usb_in_curr.usb_type_max,
1827 di->old_vbat); 2001 di->vbat, di->old_vbat);
1828 ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr); 2002 ab8500_charger_set_vbus_in_curr(di,
2003 di->max_usb_in_curr.usb_type_max);
1829 power_supply_changed(&di->usb_chg.psy); 2004 power_supply_changed(&di->usb_chg.psy);
1830 } 2005 }
1831 2006
@@ -2105,7 +2280,8 @@ static void ab8500_charger_usb_link_attach_work(struct work_struct *work)
2105 2280
2106 /* Update maximum input current if USB enumeration is not detected */ 2281 /* Update maximum input current if USB enumeration is not detected */
2107 if (!di->usb.charger_online) { 2282 if (!di->usb.charger_online) {
2108 ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr); 2283 ret = ab8500_charger_set_vbus_in_curr(di,
2284 di->max_usb_in_curr.usb_type_max);
2109 if (ret) 2285 if (ret)
2110 return; 2286 return;
2111 } 2287 }
@@ -2125,6 +2301,7 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
2125 int detected_chargers; 2301 int detected_chargers;
2126 int ret; 2302 int ret;
2127 u8 val; 2303 u8 val;
2304 u8 link_status;
2128 2305
2129 struct ab8500_charger *di = container_of(work, 2306 struct ab8500_charger *di = container_of(work,
2130 struct ab8500_charger, usb_link_status_work); 2307 struct ab8500_charger, usb_link_status_work);
@@ -2144,38 +2321,61 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
2144 * to start the charging process. but by jumping 2321 * to start the charging process. but by jumping
2145 * thru a few hoops it can be forced to start. 2322 * thru a few hoops it can be forced to start.
2146 */ 2323 */
2147 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, 2324 if (is_ab8500(di->parent))
2148 AB8500_USB_LINE_STAT_REG, &val); 2325 ret = abx500_get_register_interruptible(di->dev, AB8500_USB,
2326 AB8500_USB_LINE_STAT_REG, &val);
2327 else
2328 ret = abx500_get_register_interruptible(di->dev, AB8500_USB,
2329 AB8500_USB_LINK1_STAT_REG, &val);
2330
2149 if (ret >= 0) 2331 if (ret >= 0)
2150 dev_dbg(di->dev, "UsbLineStatus register = 0x%02x\n", val); 2332 dev_dbg(di->dev, "UsbLineStatus register = 0x%02x\n", val);
2151 else 2333 else
2152 dev_dbg(di->dev, "Error reading USB link status\n"); 2334 dev_dbg(di->dev, "Error reading USB link status\n");
2153 2335
2336 if (is_ab8500(di->parent))
2337 link_status = AB8500_USB_LINK_STATUS;
2338 else
2339 link_status = AB8505_USB_LINK_STATUS;
2340
2154 if (detected_chargers & USB_PW_CONN) { 2341 if (detected_chargers & USB_PW_CONN) {
2155 if (((val & AB8500_USB_LINK_STATUS) >> 3) == USB_STAT_NOT_VALID_LINK && 2342 if (((val & link_status) >> USB_LINK_STATUS_SHIFT) ==
2343 USB_STAT_NOT_VALID_LINK &&
2156 di->invalid_charger_detect_state == 0) { 2344 di->invalid_charger_detect_state == 0) {
2157 dev_dbg(di->dev, "Invalid charger detected, state= 0\n"); 2345 dev_dbg(di->dev,
2346 "Invalid charger detected, state= 0\n");
2158 /*Enable charger*/ 2347 /*Enable charger*/
2159 abx500_mask_and_set_register_interruptible(di->dev, 2348 abx500_mask_and_set_register_interruptible(di->dev,
2160 AB8500_CHARGER, AB8500_USBCH_CTRL1_REG, 0x01, 0x01); 2349 AB8500_CHARGER, AB8500_USBCH_CTRL1_REG,
2350 USB_CH_ENA, USB_CH_ENA);
2161 /*Enable charger detection*/ 2351 /*Enable charger detection*/
2162 abx500_mask_and_set_register_interruptible(di->dev, AB8500_USB, 2352 abx500_mask_and_set_register_interruptible(di->dev,
2163 AB8500_MCH_IPT_CURLVL_REG, 0x01, 0x01); 2353 AB8500_USB, AB8500_USB_LINE_CTRL2_REG,
2354 USB_CH_DET, USB_CH_DET);
2164 di->invalid_charger_detect_state = 1; 2355 di->invalid_charger_detect_state = 1;
2165 /*exit and wait for new link status interrupt.*/ 2356 /*exit and wait for new link status interrupt.*/
2166 return; 2357 return;
2167 2358
2168 } 2359 }
2169 if (di->invalid_charger_detect_state == 1) { 2360 if (di->invalid_charger_detect_state == 1) {
2170 dev_dbg(di->dev, "Invalid charger detected, state= 1\n"); 2361 dev_dbg(di->dev,
2362 "Invalid charger detected, state= 1\n");
2171 /*Stop charger detection*/ 2363 /*Stop charger detection*/
2172 abx500_mask_and_set_register_interruptible(di->dev, AB8500_USB, 2364 abx500_mask_and_set_register_interruptible(di->dev,
2173 AB8500_MCH_IPT_CURLVL_REG, 0x01, 0x00); 2365 AB8500_USB, AB8500_USB_LINE_CTRL2_REG,
2366 USB_CH_DET, 0x00);
2174 /*Check link status*/ 2367 /*Check link status*/
2175 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, 2368 if (is_ab8500(di->parent))
2176 AB8500_USB_LINE_STAT_REG, &val); 2369 ret = abx500_get_register_interruptible(di->dev,
2370 AB8500_USB, AB8500_USB_LINE_STAT_REG,
2371 &val);
2372 else
2373 ret = abx500_get_register_interruptible(di->dev,
2374 AB8500_USB, AB8500_USB_LINK1_STAT_REG,
2375 &val);
2376
2177 dev_dbg(di->dev, "USB link status= 0x%02x\n", 2377 dev_dbg(di->dev, "USB link status= 0x%02x\n",
2178 (val & AB8500_USB_LINK_STATUS) >> 3); 2378 (val & link_status) >> USB_LINK_STATUS_SHIFT);
2179 di->invalid_charger_detect_state = 2; 2379 di->invalid_charger_detect_state = 2;
2180 } 2380 }
2181 } else { 2381 } else {
@@ -2273,7 +2473,7 @@ static void ab8500_charger_usb_state_changed_work(struct work_struct *work)
2273 if (!ab8500_charger_get_usb_cur(di)) { 2473 if (!ab8500_charger_get_usb_cur(di)) {
2274 /* Update maximum input current */ 2474 /* Update maximum input current */
2275 ret = ab8500_charger_set_vbus_in_curr(di, 2475 ret = ab8500_charger_set_vbus_in_curr(di,
2276 di->max_usb_in_curr); 2476 di->max_usb_in_curr.usb_type_max);
2277 if (ret) 2477 if (ret)
2278 return; 2478 return;
2279 2479
@@ -2422,7 +2622,9 @@ static irqreturn_t ab8500_charger_mainchplugdet_handler(int irq, void *_di)
2422 2622
2423 mutex_lock(&di->charger_attached_mutex); 2623 mutex_lock(&di->charger_attached_mutex);
2424 mutex_unlock(&di->charger_attached_mutex); 2624 mutex_unlock(&di->charger_attached_mutex);
2425 queue_delayed_work(di->charger_wq, 2625
2626 if (is_ab8500(di->parent))
2627 queue_delayed_work(di->charger_wq,
2426 &di->ac_charger_attached_work, 2628 &di->ac_charger_attached_work,
2427 HZ); 2629 HZ);
2428 return IRQ_HANDLED; 2630 return IRQ_HANDLED;
@@ -2491,6 +2693,8 @@ static void ab8500_charger_vbus_drop_end_work(struct work_struct *work)
2491{ 2693{
2492 struct ab8500_charger *di = container_of(work, 2694 struct ab8500_charger *di = container_of(work,
2493 struct ab8500_charger, vbus_drop_end_work.work); 2695 struct ab8500_charger, vbus_drop_end_work.work);
2696 int ret, curr;
2697 u8 reg_value;
2494 2698
2495 di->flags.vbus_drop_end = false; 2699 di->flags.vbus_drop_end = false;
2496 2700
@@ -2498,8 +2702,45 @@ static void ab8500_charger_vbus_drop_end_work(struct work_struct *work)
2498 abx500_set_register_interruptible(di->dev, 2702 abx500_set_register_interruptible(di->dev,
2499 AB8500_CHARGER, AB8500_CHARGER_CTRL, 0x01); 2703 AB8500_CHARGER, AB8500_CHARGER_CTRL, 0x01);
2500 2704
2705 if (is_ab8540(di->parent))
2706 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
2707 AB8540_CH_USBCH_STAT3_REG, &reg_value);
2708 else
2709 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
2710 AB8500_CH_USBCH_STAT2_REG, &reg_value);
2711 if (ret < 0) {
2712 dev_err(di->dev, "%s read failed\n", __func__);
2713 return;
2714 }
2715
2716 if (is_ab8540(di->parent))
2717 curr = di->bm->chg_input_curr[
2718 reg_value & AB8540_AUTO_VBUS_IN_CURR_MASK];
2719 else
2720 curr = di->bm->chg_input_curr[
2721 reg_value >> AUTO_VBUS_IN_CURR_LIM_SHIFT];
2722
2723 if (di->max_usb_in_curr.calculated_max != curr) {
2724 /* USB source is collapsing */
2725 di->max_usb_in_curr.calculated_max = curr;
2726 dev_dbg(di->dev,
2727 "VBUS input current limiting to %d mA\n",
2728 di->max_usb_in_curr.calculated_max);
2729 } else {
2730 /*
2731 * USB source can not give more than this amount.
2732 * Taking more will collapse the source.
2733 */
2734 di->max_usb_in_curr.set_max =
2735 di->max_usb_in_curr.calculated_max;
2736 dev_dbg(di->dev,
2737 "VBUS input current limited to %d mA\n",
2738 di->max_usb_in_curr.set_max);
2739 }
2740
2501 if (di->usb.charger_connected) 2741 if (di->usb.charger_connected)
2502 ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr); 2742 ab8500_charger_set_vbus_in_curr(di,
2743 di->max_usb_in_curr.usb_type_max);
2503} 2744}
2504 2745
2505/** 2746/**
@@ -2654,8 +2895,13 @@ static irqreturn_t ab8500_charger_vbuschdropend_handler(int irq, void *_di)
2654 2895
2655 dev_dbg(di->dev, "VBUS charger drop ended\n"); 2896 dev_dbg(di->dev, "VBUS charger drop ended\n");
2656 di->flags.vbus_drop_end = true; 2897 di->flags.vbus_drop_end = true;
2898
2899 /*
2900 * VBUS might have dropped due to bad connection.
2901 * Schedule a new input limit set to the value SW requests.
2902 */
2657 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, 2903 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work,
2658 round_jiffies(30 * HZ)); 2904 round_jiffies(VBUS_IN_CURR_LIM_RETRY_SET_TIME * HZ));
2659 2905
2660 return IRQ_HANDLED; 2906 return IRQ_HANDLED;
2661} 2907}
@@ -2836,6 +3082,7 @@ static int ab8500_charger_usb_get_property(struct power_supply *psy,
2836static int ab8500_charger_init_hw_registers(struct ab8500_charger *di) 3082static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2837{ 3083{
2838 int ret = 0; 3084 int ret = 0;
3085 u8 bup_vch_range = 0, vbup33_vrtcn = 0;
2839 3086
2840 /* Setup maximum charger current and voltage for ABB cut2.0 */ 3087 /* Setup maximum charger current and voltage for ABB cut2.0 */
2841 if (!is_ab8500_1p1_or_earlier(di->parent)) { 3088 if (!is_ab8500_1p1_or_earlier(di->parent)) {
@@ -2848,9 +3095,14 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2848 goto out; 3095 goto out;
2849 } 3096 }
2850 3097
2851 ret = abx500_set_register_interruptible(di->dev, 3098 if (is_ab8540(di->parent))
2852 AB8500_CHARGER, 3099 ret = abx500_set_register_interruptible(di->dev,
2853 AB8500_CH_OPT_CRNTLVL_MAX_REG, CH_OP_CUR_LVL_1P6); 3100 AB8500_CHARGER, AB8500_CH_OPT_CRNTLVL_MAX_REG,
3101 CH_OP_CUR_LVL_2P);
3102 else
3103 ret = abx500_set_register_interruptible(di->dev,
3104 AB8500_CHARGER, AB8500_CH_OPT_CRNTLVL_MAX_REG,
3105 CH_OP_CUR_LVL_1P6);
2854 if (ret) { 3106 if (ret) {
2855 dev_err(di->dev, 3107 dev_err(di->dev,
2856 "failed to set CH_OPT_CRNTLVL_MAX_REG\n"); 3108 "failed to set CH_OPT_CRNTLVL_MAX_REG\n");
@@ -2858,7 +3110,8 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2858 } 3110 }
2859 } 3111 }
2860 3112
2861 if (is_ab9540_2p0(di->parent) || is_ab8505_2p0(di->parent)) 3113 if (is_ab9540_2p0(di->parent) || is_ab9540_3p0(di->parent)
3114 || is_ab8505_2p0(di->parent) || is_ab8540(di->parent))
2862 ret = abx500_mask_and_set_register_interruptible(di->dev, 3115 ret = abx500_mask_and_set_register_interruptible(di->dev,
2863 AB8500_CHARGER, 3116 AB8500_CHARGER,
2864 AB8500_USBCH_CTRL2_REG, 3117 AB8500_USBCH_CTRL2_REG,
@@ -2930,14 +3183,6 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2930 goto out; 3183 goto out;
2931 } 3184 }
2932 3185
2933 /* Set charger watchdog timeout */
2934 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
2935 AB8500_CH_WD_TIMER_REG, WD_TIMER);
2936 if (ret) {
2937 dev_err(di->dev, "failed to set charger watchdog timeout\n");
2938 goto out;
2939 }
2940
2941 ret = ab8500_charger_led_en(di, false); 3186 ret = ab8500_charger_led_en(di, false);
2942 if (ret < 0) { 3187 if (ret < 0) {
2943 dev_err(di->dev, "failed to disable LED\n"); 3188 dev_err(di->dev, "failed to disable LED\n");
@@ -2945,15 +3190,30 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2945 } 3190 }
2946 3191
2947 /* Backup battery voltage and current */ 3192 /* Backup battery voltage and current */
3193 if (di->bm->bkup_bat_v > BUP_VCH_SEL_3P1V)
3194 bup_vch_range = BUP_VCH_RANGE;
3195 if (di->bm->bkup_bat_v == BUP_VCH_SEL_3P3V)
3196 vbup33_vrtcn = VBUP33_VRTCN;
3197
2948 ret = abx500_set_register_interruptible(di->dev, 3198 ret = abx500_set_register_interruptible(di->dev,
2949 AB8500_RTC, 3199 AB8500_RTC,
2950 AB8500_RTC_BACKUP_CHG_REG, 3200 AB8500_RTC_BACKUP_CHG_REG,
2951 di->bm->bkup_bat_v | 3201 (di->bm->bkup_bat_v & 0x3) | di->bm->bkup_bat_i);
2952 di->bm->bkup_bat_i);
2953 if (ret) { 3202 if (ret) {
2954 dev_err(di->dev, "failed to setup backup battery charging\n"); 3203 dev_err(di->dev, "failed to setup backup battery charging\n");
2955 goto out; 3204 goto out;
2956 } 3205 }
3206 if (is_ab8540(di->parent)) {
3207 ret = abx500_set_register_interruptible(di->dev,
3208 AB8500_RTC,
3209 AB8500_RTC_CTRL1_REG,
3210 bup_vch_range | vbup33_vrtcn);
3211 if (ret) {
3212 dev_err(di->dev,
3213 "failed to setup backup battery charging\n");
3214 goto out;
3215 }
3216 }
2957 3217
2958 /* Enable backup battery charging */ 3218 /* Enable backup battery charging */
2959 abx500_mask_and_set_register_interruptible(di->dev, 3219 abx500_mask_and_set_register_interruptible(di->dev,
@@ -2962,6 +3222,25 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2962 if (ret < 0) 3222 if (ret < 0)
2963 dev_err(di->dev, "%s mask and set failed\n", __func__); 3223 dev_err(di->dev, "%s mask and set failed\n", __func__);
2964 3224
3225 if (is_ab8540(di->parent)) {
3226 ret = abx500_mask_and_set_register_interruptible(di->dev,
3227 AB8500_CHARGER, AB8540_USB_PP_MODE_REG,
3228 BUS_VSYS_VOL_SELECT_MASK, BUS_VSYS_VOL_SELECT_3P6V);
3229 if (ret) {
3230 dev_err(di->dev,
3231 "failed to setup usb power path vsys voltage\n");
3232 goto out;
3233 }
3234 ret = abx500_mask_and_set_register_interruptible(di->dev,
3235 AB8500_CHARGER, AB8540_USB_PP_CHR_REG,
3236 BUS_PP_PRECHG_CURRENT_MASK, 0);
3237 if (ret) {
3238 dev_err(di->dev,
3239 "failed to setup usb power path prechage current\n");
3240 goto out;
3241 }
3242 }
3243
2965out: 3244out:
2966 return ret; 3245 return ret;
2967} 3246}
@@ -3055,11 +3334,8 @@ static int ab8500_charger_resume(struct platform_device *pdev)
3055 dev_err(di->dev, "Failed to kick WD!\n"); 3334 dev_err(di->dev, "Failed to kick WD!\n");
3056 3335
3057 /* If not already pending start a new timer */ 3336 /* If not already pending start a new timer */
3058 if (!delayed_work_pending( 3337 queue_delayed_work(di->charger_wq, &di->kick_wd_work,
3059 &di->kick_wd_work)) { 3338 round_jiffies(WD_KICK_INTERVAL));
3060 queue_delayed_work(di->charger_wq, &di->kick_wd_work,
3061 round_jiffies(WD_KICK_INTERVAL));
3062 }
3063 } 3339 }
3064 3340
3065 /* If we still have a HW failure, schedule a new check */ 3341 /* If we still have a HW failure, schedule a new check */
@@ -3079,12 +3355,9 @@ static int ab8500_charger_suspend(struct platform_device *pdev,
3079{ 3355{
3080 struct ab8500_charger *di = platform_get_drvdata(pdev); 3356 struct ab8500_charger *di = platform_get_drvdata(pdev);
3081 3357
3082 /* Cancel any pending HW failure check */ 3358 /* Cancel any pending jobs */
3083 if (delayed_work_pending(&di->check_hw_failure_work)) 3359 cancel_delayed_work(&di->check_hw_failure_work);
3084 cancel_delayed_work(&di->check_hw_failure_work); 3360 cancel_delayed_work(&di->vbus_drop_end_work);
3085
3086 if (delayed_work_pending(&di->vbus_drop_end_work))
3087 cancel_delayed_work(&di->vbus_drop_end_work);
3088 3361
3089 flush_delayed_work(&di->attach_work); 3362 flush_delayed_work(&di->attach_work);
3090 flush_delayed_work(&di->usb_charger_attached_work); 3363 flush_delayed_work(&di->usb_charger_attached_work);
@@ -3107,6 +3380,10 @@ static int ab8500_charger_suspend(struct platform_device *pdev,
3107#define ab8500_charger_resume NULL 3380#define ab8500_charger_resume NULL
3108#endif 3381#endif
3109 3382
3383static struct notifier_block charger_nb = {
3384 .notifier_call = ab8500_external_charger_prepare,
3385};
3386
3110static int ab8500_charger_remove(struct platform_device *pdev) 3387static int ab8500_charger_remove(struct platform_device *pdev)
3111{ 3388{
3112 struct ab8500_charger *di = platform_get_drvdata(pdev); 3389 struct ab8500_charger *di = platform_get_drvdata(pdev);
@@ -3136,13 +3413,18 @@ static int ab8500_charger_remove(struct platform_device *pdev)
3136 /* Delete the work queue */ 3413 /* Delete the work queue */
3137 destroy_workqueue(di->charger_wq); 3414 destroy_workqueue(di->charger_wq);
3138 3415
3416 /* Unregister external charger enable notifier */
3417 if (!di->ac_chg.enabled)
3418 blocking_notifier_chain_unregister(
3419 &charger_notifier_list, &charger_nb);
3420
3139 flush_scheduled_work(); 3421 flush_scheduled_work();
3140 if(di->usb_chg.enabled) 3422 if (di->usb_chg.enabled)
3141 power_supply_unregister(&di->usb_chg.psy); 3423 power_supply_unregister(&di->usb_chg.psy);
3142#if !defined(CONFIG_CHARGER_PM2301) 3424
3143 if(di->ac_chg.enabled) 3425 if (di->ac_chg.enabled && !di->ac_chg.external)
3144 power_supply_unregister(&di->ac_chg.psy); 3426 power_supply_unregister(&di->ac_chg.psy);
3145#endif 3427
3146 platform_set_drvdata(pdev, NULL); 3428 platform_set_drvdata(pdev, NULL);
3147 3429
3148 return 0; 3430 return 0;
@@ -3206,16 +3488,22 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3206 di->ac_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface), 3488 di->ac_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface),
3207 /* ux500_charger sub-class */ 3489 /* ux500_charger sub-class */
3208 di->ac_chg.ops.enable = &ab8500_charger_ac_en; 3490 di->ac_chg.ops.enable = &ab8500_charger_ac_en;
3491 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable;
3209 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; 3492 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
3210 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current; 3493 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current;
3211 di->ac_chg.max_out_volt = ab8500_charger_voltage_map[ 3494 di->ac_chg.max_out_volt = ab8500_charger_voltage_map[
3212 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; 3495 ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
3213 di->ac_chg.max_out_curr = ab8500_charger_current_map[ 3496 di->ac_chg.max_out_curr =
3214 ARRAY_SIZE(ab8500_charger_current_map) - 1]; 3497 di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1];
3215 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL; 3498 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL;
3216 di->ac_chg.enabled = di->bm->ac_enabled; 3499 di->ac_chg.enabled = di->bm->ac_enabled;
3217 di->ac_chg.external = false; 3500 di->ac_chg.external = false;
3218 3501
3502 /*notifier for external charger enabling*/
3503 if (!di->ac_chg.enabled)
3504 blocking_notifier_chain_register(
3505 &charger_notifier_list, &charger_nb);
3506
3219 /* USB supply */ 3507 /* USB supply */
3220 /* power_supply base class */ 3508 /* power_supply base class */
3221 di->usb_chg.psy.name = "ab8500_usb"; 3509 di->usb_chg.psy.name = "ab8500_usb";
@@ -3227,15 +3515,20 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3227 di->usb_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface), 3515 di->usb_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface),
3228 /* ux500_charger sub-class */ 3516 /* ux500_charger sub-class */
3229 di->usb_chg.ops.enable = &ab8500_charger_usb_en; 3517 di->usb_chg.ops.enable = &ab8500_charger_usb_en;
3518 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable;
3230 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; 3519 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
3231 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current; 3520 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current;
3521 di->usb_chg.ops.pp_enable = &ab8540_charger_power_path_enable;
3522 di->usb_chg.ops.pre_chg_enable = &ab8540_charger_usb_pre_chg_enable;
3232 di->usb_chg.max_out_volt = ab8500_charger_voltage_map[ 3523 di->usb_chg.max_out_volt = ab8500_charger_voltage_map[
3233 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; 3524 ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
3234 di->usb_chg.max_out_curr = ab8500_charger_current_map[ 3525 di->usb_chg.max_out_curr =
3235 ARRAY_SIZE(ab8500_charger_current_map) - 1]; 3526 di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1];
3236 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL; 3527 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL;
3237 di->usb_chg.enabled = di->bm->usb_enabled; 3528 di->usb_chg.enabled = di->bm->usb_enabled;
3238 di->usb_chg.external = false; 3529 di->usb_chg.external = false;
3530 di->usb_chg.power_path = di->bm->usb_power_path;
3531 di->usb_state.usb_current = -1;
3239 3532
3240 /* Create a work queue for the charger */ 3533 /* Create a work queue for the charger */
3241 di->charger_wq = 3534 di->charger_wq =
@@ -3316,7 +3609,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3316 } 3609 }
3317 3610
3318 /* Register AC charger class */ 3611 /* Register AC charger class */
3319 if(di->ac_chg.enabled) { 3612 if (di->ac_chg.enabled) {
3320 ret = power_supply_register(di->dev, &di->ac_chg.psy); 3613 ret = power_supply_register(di->dev, &di->ac_chg.psy);
3321 if (ret) { 3614 if (ret) {
3322 dev_err(di->dev, "failed to register AC charger\n"); 3615 dev_err(di->dev, "failed to register AC charger\n");
@@ -3325,7 +3618,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3325 } 3618 }
3326 3619
3327 /* Register USB charger class */ 3620 /* Register USB charger class */
3328 if(di->usb_chg.enabled) { 3621 if (di->usb_chg.enabled) {
3329 ret = power_supply_register(di->dev, &di->usb_chg.psy); 3622 ret = power_supply_register(di->dev, &di->usb_chg.psy);
3330 if (ret) { 3623 if (ret) {
3331 dev_err(di->dev, "failed to register USB charger\n"); 3624 dev_err(di->dev, "failed to register USB charger\n");
@@ -3385,14 +3678,16 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3385 ch_stat = ab8500_charger_detect_chargers(di, false); 3678 ch_stat = ab8500_charger_detect_chargers(di, false);
3386 3679
3387 if ((ch_stat & AC_PW_CONN) == AC_PW_CONN) { 3680 if ((ch_stat & AC_PW_CONN) == AC_PW_CONN) {
3388 queue_delayed_work(di->charger_wq, 3681 if (is_ab8500(di->parent))
3389 &di->ac_charger_attached_work, 3682 queue_delayed_work(di->charger_wq,
3390 HZ); 3683 &di->ac_charger_attached_work,
3684 HZ);
3391 } 3685 }
3392 if ((ch_stat & USB_PW_CONN) == USB_PW_CONN) { 3686 if ((ch_stat & USB_PW_CONN) == USB_PW_CONN) {
3393 queue_delayed_work(di->charger_wq, 3687 if (is_ab8500(di->parent))
3394 &di->usb_charger_attached_work, 3688 queue_delayed_work(di->charger_wq,
3395 HZ); 3689 &di->usb_charger_attached_work,
3690 HZ);
3396 } 3691 }
3397 3692
3398 mutex_unlock(&di->charger_attached_mutex); 3693 mutex_unlock(&di->charger_attached_mutex);
@@ -3410,10 +3705,10 @@ free_irq:
3410put_usb_phy: 3705put_usb_phy:
3411 usb_put_phy(di->usb_phy); 3706 usb_put_phy(di->usb_phy);
3412free_usb: 3707free_usb:
3413 if(di->usb_chg.enabled) 3708 if (di->usb_chg.enabled)
3414 power_supply_unregister(&di->usb_chg.psy); 3709 power_supply_unregister(&di->usb_chg.psy);
3415free_ac: 3710free_ac:
3416 if(di->ac_chg.enabled) 3711 if (di->ac_chg.enabled)
3417 power_supply_unregister(&di->ac_chg.psy); 3712 power_supply_unregister(&di->ac_chg.psy);
3418free_charger_wq: 3713free_charger_wq:
3419 destroy_workqueue(di->charger_wq); 3714 destroy_workqueue(di->charger_wq);
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 25dae4c4b0ef..c5391f5c372d 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -36,7 +36,7 @@
36 36
37#define MILLI_TO_MICRO 1000 37#define MILLI_TO_MICRO 1000
38#define FG_LSB_IN_MA 1627 38#define FG_LSB_IN_MA 1627
39#define QLSB_NANO_AMP_HOURS_X10 1129 39#define QLSB_NANO_AMP_HOURS_X10 1071
40#define INS_CURR_TIMEOUT (3 * HZ) 40#define INS_CURR_TIMEOUT (3 * HZ)
41 41
42#define SEC_TO_SAMPLE(S) (S * 4) 42#define SEC_TO_SAMPLE(S) (S * 4)
@@ -672,11 +672,11 @@ int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res)
672 /* 672 /*
673 * Convert to unit value in mA 673 * Convert to unit value in mA
674 * Full scale input voltage is 674 * Full scale input voltage is
675 * 66.660mV => LSB = 66.660mV/(4096*res) = 1.627mA 675 * 63.160mV => LSB = 63.160mV/(4096*res) = 1.542mA
676 * Given a 250ms conversion cycle time the LSB corresponds 676 * Given a 250ms conversion cycle time the LSB corresponds
677 * to 112.9 nAh. Convert to current by dividing by the conversion 677 * to 107.1 nAh. Convert to current by dividing by the conversion
678 * time in hours (250ms = 1 / (3600 * 4)h) 678 * time in hours (250ms = 1 / (3600 * 4)h)
679 * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm 679 * 107.1nAh assumes 10mOhm, but fg_res is in 0.1mOhm
680 */ 680 */
681 val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) / 681 val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) /
682 (1000 * di->bm->fg_res); 682 (1000 * di->bm->fg_res);
@@ -863,7 +863,7 @@ static int ab8500_fg_bat_voltage(struct ab8500_fg *di)
863static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage) 863static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage)
864{ 864{
865 int i, tbl_size; 865 int i, tbl_size;
866 struct abx500_v_to_cap *tbl; 866 const struct abx500_v_to_cap *tbl;
867 int cap = 0; 867 int cap = 0;
868 868
869 tbl = di->bm->bat_type[di->bm->batt_id].v_to_cap_tbl, 869 tbl = di->bm->bat_type[di->bm->batt_id].v_to_cap_tbl,
@@ -915,7 +915,7 @@ static int ab8500_fg_uncomp_volt_to_capacity(struct ab8500_fg *di)
915static int ab8500_fg_battery_resistance(struct ab8500_fg *di) 915static int ab8500_fg_battery_resistance(struct ab8500_fg *di)
916{ 916{
917 int i, tbl_size; 917 int i, tbl_size;
918 struct batres_vs_temp *tbl; 918 const struct batres_vs_temp *tbl;
919 int resist = 0; 919 int resist = 0;
920 920
921 tbl = di->bm->bat_type[di->bm->batt_id].batres_tbl; 921 tbl = di->bm->bat_type[di->bm->batt_id].batres_tbl;
@@ -1354,9 +1354,6 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1354 * algorithm says. 1354 * algorithm says.
1355 */ 1355 */
1356 di->bat_cap.prev_percent = 1; 1356 di->bat_cap.prev_percent = 1;
1357 di->bat_cap.permille = 1;
1358 di->bat_cap.prev_mah = 1;
1359 di->bat_cap.mah = 1;
1360 percent = 1; 1357 percent = 1;
1361 1358
1362 changed = true; 1359 changed = true;
@@ -1683,7 +1680,6 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di)
1683 break; 1680 break;
1684 1681
1685 case AB8500_FG_DISCHARGE_WAKEUP: 1682 case AB8500_FG_DISCHARGE_WAKEUP:
1686 ab8500_fg_coulomb_counter(di, true);
1687 ab8500_fg_calc_cap_discharge_voltage(di, true); 1683 ab8500_fg_calc_cap_discharge_voltage(di, true);
1688 1684
1689 di->fg_samples = SEC_TO_SAMPLE( 1685 di->fg_samples = SEC_TO_SAMPLE(
@@ -1768,9 +1764,10 @@ static void ab8500_fg_algorithm(struct ab8500_fg *di)
1768 ab8500_fg_algorithm_discharging(di); 1764 ab8500_fg_algorithm_discharging(di);
1769 } 1765 }
1770 1766
1771 dev_dbg(di->dev, "[FG_DATA] %d %d %d %d %d %d %d %d %d " 1767 dev_dbg(di->dev, "[FG_DATA] %d %d %d %d %d %d %d %d %d %d "
1772 "%d %d %d %d %d %d %d\n", 1768 "%d %d %d %d %d %d %d\n",
1773 di->bat_cap.max_mah_design, 1769 di->bat_cap.max_mah_design,
1770 di->bat_cap.max_mah,
1774 di->bat_cap.mah, 1771 di->bat_cap.mah,
1775 di->bat_cap.permille, 1772 di->bat_cap.permille,
1776 di->bat_cap.level, 1773 di->bat_cap.level,
@@ -1982,7 +1979,7 @@ static void ab8500_fg_instant_work(struct work_struct *work)
1982} 1979}
1983 1980
1984/** 1981/**
1985 * ab8500_fg_cc_data_end_handler() - isr to get battery avg current. 1982 * ab8500_fg_cc_data_end_handler() - end of data conversion isr.
1986 * @irq: interrupt number 1983 * @irq: interrupt number
1987 * @_di: pointer to the ab8500_fg structure 1984 * @_di: pointer to the ab8500_fg structure
1988 * 1985 *
@@ -2002,7 +1999,7 @@ static irqreturn_t ab8500_fg_cc_data_end_handler(int irq, void *_di)
2002} 1999}
2003 2000
2004/** 2001/**
2005 * ab8500_fg_cc_convend_handler() - isr to get battery avg current. 2002 * ab8500_fg_cc_int_calib_handler () - end of calibration isr.
2006 * @irq: interrupt number 2003 * @irq: interrupt number
2007 * @_di: pointer to the ab8500_fg structure 2004 * @_di: pointer to the ab8500_fg structure
2008 * 2005 *
@@ -2153,9 +2150,7 @@ static int ab8500_fg_get_property(struct power_supply *psy,
2153 val->intval = di->bat_cap.prev_mah; 2150 val->intval = di->bat_cap.prev_mah;
2154 break; 2151 break;
2155 case POWER_SUPPLY_PROP_CAPACITY: 2152 case POWER_SUPPLY_PROP_CAPACITY:
2156 if (di->bm->capacity_scaling) 2153 if (di->flags.batt_unknown && !di->bm->chg_unknown_bat &&
2157 val->intval = di->bat_cap.cap_scale.scaled_cap;
2158 else if (di->flags.batt_unknown && !di->bm->chg_unknown_bat &&
2159 di->flags.batt_id_received) 2154 di->flags.batt_id_received)
2160 val->intval = 100; 2155 val->intval = 100;
2161 else 2156 else
@@ -2344,6 +2339,50 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)
2344 dev_err(di->dev, "BattOk init write failed.\n"); 2339 dev_err(di->dev, "BattOk init write failed.\n");
2345 goto out; 2340 goto out;
2346 } 2341 }
2342
2343 if (((is_ab8505(di->parent) || is_ab9540(di->parent)) &&
2344 abx500_get_chip_id(di->dev) >= AB8500_CUT2P0)
2345 || is_ab8540(di->parent)) {
2346 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2347 AB8505_RTC_PCUT_MAX_TIME_REG, di->bm->fg_params->pcut_max_time);
2348
2349 if (ret) {
2350 dev_err(di->dev, "%s write failed AB8505_RTC_PCUT_MAX_TIME_REG\n", __func__);
2351 goto out;
2352 };
2353
2354 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2355 AB8505_RTC_PCUT_FLAG_TIME_REG, di->bm->fg_params->pcut_flag_time);
2356
2357 if (ret) {
2358 dev_err(di->dev, "%s write failed AB8505_RTC_PCUT_FLAG_TIME_REG\n", __func__);
2359 goto out;
2360 };
2361
2362 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2363 AB8505_RTC_PCUT_RESTART_REG, di->bm->fg_params->pcut_max_restart);
2364
2365 if (ret) {
2366 dev_err(di->dev, "%s write failed AB8505_RTC_PCUT_RESTART_REG\n", __func__);
2367 goto out;
2368 };
2369
2370 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2371 AB8505_RTC_PCUT_DEBOUNCE_REG, di->bm->fg_params->pcut_debounce_time);
2372
2373 if (ret) {
2374 dev_err(di->dev, "%s write failed AB8505_RTC_PCUT_DEBOUNCE_REG\n", __func__);
2375 goto out;
2376 };
2377
2378 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2379 AB8505_RTC_PCUT_CTL_STATUS_REG, di->bm->fg_params->pcut_enable);
2380
2381 if (ret) {
2382 dev_err(di->dev, "%s write failed AB8505_RTC_PCUT_CTL_STATUS_REG\n", __func__);
2383 goto out;
2384 };
2385 }
2347out: 2386out:
2348 return ret; 2387 return ret;
2349} 2388}
@@ -2546,6 +2585,428 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)
2546 2585
2547 return ret; 2586 return ret;
2548} 2587}
2588
2589static ssize_t ab8505_powercut_flagtime_read(struct device *dev,
2590 struct device_attribute *attr,
2591 char *buf)
2592{
2593 int ret;
2594 u8 reg_value;
2595 struct power_supply *psy = dev_get_drvdata(dev);
2596 struct ab8500_fg *di;
2597
2598 di = to_ab8500_fg_device_info(psy);
2599
2600 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2601 AB8505_RTC_PCUT_FLAG_TIME_REG, &reg_value);
2602
2603 if (ret < 0) {
2604 dev_err(dev, "Failed to read AB8505_RTC_PCUT_FLAG_TIME_REG\n");
2605 goto fail;
2606 }
2607
2608 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2609
2610fail:
2611 return ret;
2612}
2613
2614static ssize_t ab8505_powercut_flagtime_write(struct device *dev,
2615 struct device_attribute *attr,
2616 const char *buf, size_t count)
2617{
2618 int ret;
2619 long unsigned reg_value;
2620 struct power_supply *psy = dev_get_drvdata(dev);
2621 struct ab8500_fg *di;
2622
2623 di = to_ab8500_fg_device_info(psy);
2624
2625 reg_value = simple_strtoul(buf, NULL, 10);
2626
2627 if (reg_value > 0x7F) {
2628 dev_err(dev, "Incorrect parameter, echo 0 (1.98s) - 127 (15.625ms) for flagtime\n");
2629 goto fail;
2630 }
2631
2632 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2633 AB8505_RTC_PCUT_FLAG_TIME_REG, (u8)reg_value);
2634
2635 if (ret < 0)
2636 dev_err(dev, "Failed to set AB8505_RTC_PCUT_FLAG_TIME_REG\n");
2637
2638fail:
2639 return count;
2640}
2641
2642static ssize_t ab8505_powercut_maxtime_read(struct device *dev,
2643 struct device_attribute *attr,
2644 char *buf)
2645{
2646 int ret;
2647 u8 reg_value;
2648 struct power_supply *psy = dev_get_drvdata(dev);
2649 struct ab8500_fg *di;
2650
2651 di = to_ab8500_fg_device_info(psy);
2652
2653 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2654 AB8505_RTC_PCUT_MAX_TIME_REG, &reg_value);
2655
2656 if (ret < 0) {
2657 dev_err(dev, "Failed to read AB8505_RTC_PCUT_MAX_TIME_REG\n");
2658 goto fail;
2659 }
2660
2661 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2662
2663fail:
2664 return ret;
2665
2666}
2667
2668static ssize_t ab8505_powercut_maxtime_write(struct device *dev,
2669 struct device_attribute *attr,
2670 const char *buf, size_t count)
2671{
2672 int ret;
2673 int reg_value;
2674 struct power_supply *psy = dev_get_drvdata(dev);
2675 struct ab8500_fg *di;
2676
2677 di = to_ab8500_fg_device_info(psy);
2678
2679 reg_value = simple_strtoul(buf, NULL, 10);
2680 if (reg_value > 0x7F) {
2681 dev_err(dev, "Incorrect parameter, echo 0 (0.0s) - 127 (1.98s) for maxtime\n");
2682 goto fail;
2683 }
2684
2685 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2686 AB8505_RTC_PCUT_MAX_TIME_REG, (u8)reg_value);
2687
2688 if (ret < 0)
2689 dev_err(dev, "Failed to set AB8505_RTC_PCUT_MAX_TIME_REG\n");
2690
2691fail:
2692 return count;
2693}
2694
2695static ssize_t ab8505_powercut_restart_read(struct device *dev,
2696 struct device_attribute *attr,
2697 char *buf)
2698{
2699 int ret;
2700 u8 reg_value;
2701 struct power_supply *psy = dev_get_drvdata(dev);
2702 struct ab8500_fg *di;
2703
2704 di = to_ab8500_fg_device_info(psy);
2705
2706 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2707 AB8505_RTC_PCUT_RESTART_REG, &reg_value);
2708
2709 if (ret < 0) {
2710 dev_err(dev, "Failed to read AB8505_RTC_PCUT_RESTART_REG\n");
2711 goto fail;
2712 }
2713
2714 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0xF));
2715
2716fail:
2717 return ret;
2718}
2719
2720static ssize_t ab8505_powercut_restart_write(struct device *dev,
2721 struct device_attribute *attr,
2722 const char *buf, size_t count)
2723{
2724 int ret;
2725 int reg_value;
2726 struct power_supply *psy = dev_get_drvdata(dev);
2727 struct ab8500_fg *di;
2728
2729 di = to_ab8500_fg_device_info(psy);
2730
2731 reg_value = simple_strtoul(buf, NULL, 10);
2732 if (reg_value > 0xF) {
2733 dev_err(dev, "Incorrect parameter, echo 0 - 15 for number of restart\n");
2734 goto fail;
2735 }
2736
2737 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2738 AB8505_RTC_PCUT_RESTART_REG, (u8)reg_value);
2739
2740 if (ret < 0)
2741 dev_err(dev, "Failed to set AB8505_RTC_PCUT_RESTART_REG\n");
2742
2743fail:
2744 return count;
2745
2746}
2747
2748static ssize_t ab8505_powercut_timer_read(struct device *dev,
2749 struct device_attribute *attr,
2750 char *buf)
2751{
2752 int ret;
2753 u8 reg_value;
2754 struct power_supply *psy = dev_get_drvdata(dev);
2755 struct ab8500_fg *di;
2756
2757 di = to_ab8500_fg_device_info(psy);
2758
2759 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2760 AB8505_RTC_PCUT_TIME_REG, &reg_value);
2761
2762 if (ret < 0) {
2763 dev_err(dev, "Failed to read AB8505_RTC_PCUT_TIME_REG\n");
2764 goto fail;
2765 }
2766
2767 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2768
2769fail:
2770 return ret;
2771}
2772
2773static ssize_t ab8505_powercut_restart_counter_read(struct device *dev,
2774 struct device_attribute *attr,
2775 char *buf)
2776{
2777 int ret;
2778 u8 reg_value;
2779 struct power_supply *psy = dev_get_drvdata(dev);
2780 struct ab8500_fg *di;
2781
2782 di = to_ab8500_fg_device_info(psy);
2783
2784 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2785 AB8505_RTC_PCUT_RESTART_REG, &reg_value);
2786
2787 if (ret < 0) {
2788 dev_err(dev, "Failed to read AB8505_RTC_PCUT_RESTART_REG\n");
2789 goto fail;
2790 }
2791
2792 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0xF0) >> 4);
2793
2794fail:
2795 return ret;
2796}
2797
2798static ssize_t ab8505_powercut_read(struct device *dev,
2799 struct device_attribute *attr,
2800 char *buf)
2801{
2802 int ret;
2803 u8 reg_value;
2804 struct power_supply *psy = dev_get_drvdata(dev);
2805 struct ab8500_fg *di;
2806
2807 di = to_ab8500_fg_device_info(psy);
2808
2809 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2810 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
2811
2812 if (ret < 0)
2813 goto fail;
2814
2815 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x1));
2816
2817fail:
2818 return ret;
2819}
2820
2821static ssize_t ab8505_powercut_write(struct device *dev,
2822 struct device_attribute *attr,
2823 const char *buf, size_t count)
2824{
2825 int ret;
2826 int reg_value;
2827 struct power_supply *psy = dev_get_drvdata(dev);
2828 struct ab8500_fg *di;
2829
2830 di = to_ab8500_fg_device_info(psy);
2831
2832 reg_value = simple_strtoul(buf, NULL, 10);
2833 if (reg_value > 0x1) {
2834 dev_err(dev, "Incorrect parameter, echo 0/1 to disable/enable Pcut feature\n");
2835 goto fail;
2836 }
2837
2838 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2839 AB8505_RTC_PCUT_CTL_STATUS_REG, (u8)reg_value);
2840
2841 if (ret < 0)
2842 dev_err(dev, "Failed to set AB8505_RTC_PCUT_CTL_STATUS_REG\n");
2843
2844fail:
2845 return count;
2846}
2847
2848static ssize_t ab8505_powercut_flag_read(struct device *dev,
2849 struct device_attribute *attr,
2850 char *buf)
2851{
2852
2853 int ret;
2854 u8 reg_value;
2855 struct power_supply *psy = dev_get_drvdata(dev);
2856 struct ab8500_fg *di;
2857
2858 di = to_ab8500_fg_device_info(psy);
2859
2860 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2861 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
2862
2863 if (ret < 0) {
2864 dev_err(dev, "Failed to read AB8505_RTC_PCUT_CTL_STATUS_REG\n");
2865 goto fail;
2866 }
2867
2868 return scnprintf(buf, PAGE_SIZE, "%d\n", ((reg_value & 0x10) >> 4));
2869
2870fail:
2871 return ret;
2872}
2873
2874static ssize_t ab8505_powercut_debounce_read(struct device *dev,
2875 struct device_attribute *attr,
2876 char *buf)
2877{
2878 int ret;
2879 u8 reg_value;
2880 struct power_supply *psy = dev_get_drvdata(dev);
2881 struct ab8500_fg *di;
2882
2883 di = to_ab8500_fg_device_info(psy);
2884
2885 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2886 AB8505_RTC_PCUT_DEBOUNCE_REG, &reg_value);
2887
2888 if (ret < 0) {
2889 dev_err(dev, "Failed to read AB8505_RTC_PCUT_DEBOUNCE_REG\n");
2890 goto fail;
2891 }
2892
2893 return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7));
2894
2895fail:
2896 return ret;
2897}
2898
2899static ssize_t ab8505_powercut_debounce_write(struct device *dev,
2900 struct device_attribute *attr,
2901 const char *buf, size_t count)
2902{
2903 int ret;
2904 int reg_value;
2905 struct power_supply *psy = dev_get_drvdata(dev);
2906 struct ab8500_fg *di;
2907
2908 di = to_ab8500_fg_device_info(psy);
2909
2910 reg_value = simple_strtoul(buf, NULL, 10);
2911 if (reg_value > 0x7) {
2912 dev_err(dev, "Incorrect parameter, echo 0 to 7 for debounce setting\n");
2913 goto fail;
2914 }
2915
2916 ret = abx500_set_register_interruptible(di->dev, AB8500_RTC,
2917 AB8505_RTC_PCUT_DEBOUNCE_REG, (u8)reg_value);
2918
2919 if (ret < 0)
2920 dev_err(dev, "Failed to set AB8505_RTC_PCUT_DEBOUNCE_REG\n");
2921
2922fail:
2923 return count;
2924}
2925
2926static ssize_t ab8505_powercut_enable_status_read(struct device *dev,
2927 struct device_attribute *attr,
2928 char *buf)
2929{
2930 int ret;
2931 u8 reg_value;
2932 struct power_supply *psy = dev_get_drvdata(dev);
2933 struct ab8500_fg *di;
2934
2935 di = to_ab8500_fg_device_info(psy);
2936
2937 ret = abx500_get_register_interruptible(di->dev, AB8500_RTC,
2938 AB8505_RTC_PCUT_CTL_STATUS_REG, &reg_value);
2939
2940 if (ret < 0) {
2941 dev_err(dev, "Failed to read AB8505_RTC_PCUT_CTL_STATUS_REG\n");
2942 goto fail;
2943 }
2944
2945 return scnprintf(buf, PAGE_SIZE, "%d\n", ((reg_value & 0x20) >> 5));
2946
2947fail:
2948 return ret;
2949}
2950
2951static struct device_attribute ab8505_fg_sysfs_psy_attrs[] = {
2952 __ATTR(powercut_flagtime, (S_IRUGO | S_IWUSR | S_IWGRP),
2953 ab8505_powercut_flagtime_read, ab8505_powercut_flagtime_write),
2954 __ATTR(powercut_maxtime, (S_IRUGO | S_IWUSR | S_IWGRP),
2955 ab8505_powercut_maxtime_read, ab8505_powercut_maxtime_write),
2956 __ATTR(powercut_restart_max, (S_IRUGO | S_IWUSR | S_IWGRP),
2957 ab8505_powercut_restart_read, ab8505_powercut_restart_write),
2958 __ATTR(powercut_timer, S_IRUGO, ab8505_powercut_timer_read, NULL),
2959 __ATTR(powercut_restart_counter, S_IRUGO,
2960 ab8505_powercut_restart_counter_read, NULL),
2961 __ATTR(powercut_enable, (S_IRUGO | S_IWUSR | S_IWGRP),
2962 ab8505_powercut_read, ab8505_powercut_write),
2963 __ATTR(powercut_flag, S_IRUGO, ab8505_powercut_flag_read, NULL),
2964 __ATTR(powercut_debounce_time, (S_IRUGO | S_IWUSR | S_IWGRP),
2965 ab8505_powercut_debounce_read, ab8505_powercut_debounce_write),
2966 __ATTR(powercut_enable_status, S_IRUGO,
2967 ab8505_powercut_enable_status_read, NULL),
2968};
2969
2970static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
2971{
2972 unsigned int i, j;
2973 struct power_supply *psy = dev_get_drvdata(dev);
2974 struct ab8500_fg *di;
2975
2976 di = to_ab8500_fg_device_info(psy);
2977
2978 if (((is_ab8505(di->parent) || is_ab9540(di->parent)) &&
2979 abx500_get_chip_id(dev->parent) >= AB8500_CUT2P0)
2980 || is_ab8540(di->parent)) {
2981 for (j = 0; j < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); j++)
2982 if (device_create_file(dev, &ab8505_fg_sysfs_psy_attrs[j]))
2983 goto sysfs_psy_create_attrs_failed_ab8505;
2984 }
2985 return 0;
2986sysfs_psy_create_attrs_failed_ab8505:
2987 dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n");
2988 while (j--)
2989 device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]);
2990
2991 return -EIO;
2992}
2993
2994static void ab8500_fg_sysfs_psy_remove_attrs(struct device *dev)
2995{
2996 unsigned int i;
2997 struct power_supply *psy = dev_get_drvdata(dev);
2998 struct ab8500_fg *di;
2999
3000 di = to_ab8500_fg_device_info(psy);
3001
3002 if (((is_ab8505(di->parent) || is_ab9540(di->parent)) &&
3003 abx500_get_chip_id(dev->parent) >= AB8500_CUT2P0)
3004 || is_ab8540(di->parent)) {
3005 for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++)
3006 (void)device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]);
3007 }
3008}
3009
2549/* Exposure to the sysfs interface <<END>> */ 3010/* Exposure to the sysfs interface <<END>> */
2550 3011
2551#if defined(CONFIG_PM) 3012#if defined(CONFIG_PM)
@@ -2607,6 +3068,7 @@ static int ab8500_fg_remove(struct platform_device *pdev)
2607 ab8500_fg_sysfs_exit(di); 3068 ab8500_fg_sysfs_exit(di);
2608 3069
2609 flush_scheduled_work(); 3070 flush_scheduled_work();
3071 ab8500_fg_sysfs_psy_remove_attrs(di->fg_psy.dev);
2610 power_supply_unregister(&di->fg_psy); 3072 power_supply_unregister(&di->fg_psy);
2611 platform_set_drvdata(pdev, NULL); 3073 platform_set_drvdata(pdev, NULL);
2612 return ret; 3074 return ret;
@@ -2772,6 +3234,13 @@ static int ab8500_fg_probe(struct platform_device *pdev)
2772 goto free_irq; 3234 goto free_irq;
2773 } 3235 }
2774 3236
3237 ret = ab8500_fg_sysfs_psy_create_attrs(di->fg_psy.dev);
3238 if (ret) {
3239 dev_err(di->dev, "failed to create FG psy\n");
3240 ab8500_fg_sysfs_exit(di);
3241 goto free_irq;
3242 }
3243
2775 /* Calibrate the fg first time */ 3244 /* Calibrate the fg first time */
2776 di->flags.calibrate = true; 3245 di->flags.calibrate = true;
2777 di->calib_state = AB8500_FG_CALIB_INIT; 3246 di->calib_state = AB8500_FG_CALIB_INIT;
diff --git a/drivers/power/abx500_chargalg.c b/drivers/power/abx500_chargalg.c
index f043c0851a76..9863e423602c 100644
--- a/drivers/power/abx500_chargalg.c
+++ b/drivers/power/abx500_chargalg.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) ST-Ericsson SA 2012 2 * Copyright (C) ST-Ericsson SA 2012
3 * Copyright (c) 2012 Sony Mobile Communications AB
3 * 4 *
4 * Charging algorithm driver for abx500 variants 5 * Charging algorithm driver for abx500 variants
5 * 6 *
@@ -8,11 +9,13 @@
8 * Johan Palsson <johan.palsson@stericsson.com> 9 * Johan Palsson <johan.palsson@stericsson.com>
9 * Karl Komierowski <karl.komierowski@stericsson.com> 10 * Karl Komierowski <karl.komierowski@stericsson.com>
10 * Arun R Murthy <arun.murthy@stericsson.com> 11 * Arun R Murthy <arun.murthy@stericsson.com>
12 * Author: Imre Sunyi <imre.sunyi@sonymobile.com>
11 */ 13 */
12 14
13#include <linux/init.h> 15#include <linux/init.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/hrtimer.h>
16#include <linux/interrupt.h> 19#include <linux/interrupt.h>
17#include <linux/delay.h> 20#include <linux/delay.h>
18#include <linux/slab.h> 21#include <linux/slab.h>
@@ -24,8 +27,10 @@
24#include <linux/of.h> 27#include <linux/of.h>
25#include <linux/mfd/core.h> 28#include <linux/mfd/core.h>
26#include <linux/mfd/abx500.h> 29#include <linux/mfd/abx500.h>
30#include <linux/mfd/abx500/ab8500.h>
27#include <linux/mfd/abx500/ux500_chargalg.h> 31#include <linux/mfd/abx500/ux500_chargalg.h>
28#include <linux/mfd/abx500/ab8500-bm.h> 32#include <linux/mfd/abx500/ab8500-bm.h>
33#include <linux/notifier.h>
29 34
30/* Watchdog kick interval */ 35/* Watchdog kick interval */
31#define CHG_WD_INTERVAL (6 * HZ) 36#define CHG_WD_INTERVAL (6 * HZ)
@@ -33,6 +38,18 @@
33/* End-of-charge criteria counter */ 38/* End-of-charge criteria counter */
34#define EOC_COND_CNT 10 39#define EOC_COND_CNT 10
35 40
41/* One hour expressed in seconds */
42#define ONE_HOUR_IN_SECONDS 3600
43
44/* Five minutes expressed in seconds */
45#define FIVE_MINUTES_IN_SECONDS 300
46
47/* Plus margin for the low battery threshold */
48#define BAT_PLUS_MARGIN (100)
49
50#define CHARGALG_CURR_STEP_LOW 0
51#define CHARGALG_CURR_STEP_HIGH 100
52
36#define to_abx500_chargalg_device_info(x) container_of((x), \ 53#define to_abx500_chargalg_device_info(x) container_of((x), \
37 struct abx500_chargalg, chargalg_psy); 54 struct abx500_chargalg, chargalg_psy);
38 55
@@ -66,6 +83,11 @@ struct abx500_chargalg_suspension_status {
66 bool usb_suspended; 83 bool usb_suspended;
67}; 84};
68 85
86struct abx500_chargalg_current_step_status {
87 bool curr_step_change;
88 int curr_step;
89};
90
69struct abx500_chargalg_battery_data { 91struct abx500_chargalg_battery_data {
70 int temp; 92 int temp;
71 int volt; 93 int volt;
@@ -82,6 +104,7 @@ enum abx500_chargalg_states {
82 STATE_HW_TEMP_PROTECT_INIT, 104 STATE_HW_TEMP_PROTECT_INIT,
83 STATE_HW_TEMP_PROTECT, 105 STATE_HW_TEMP_PROTECT,
84 STATE_NORMAL_INIT, 106 STATE_NORMAL_INIT,
107 STATE_USB_PP_PRE_CHARGE,
85 STATE_NORMAL, 108 STATE_NORMAL,
86 STATE_WAIT_FOR_RECHARGE_INIT, 109 STATE_WAIT_FOR_RECHARGE_INIT,
87 STATE_WAIT_FOR_RECHARGE, 110 STATE_WAIT_FOR_RECHARGE,
@@ -113,6 +136,7 @@ static const char *states[] = {
113 "HW_TEMP_PROTECT_INIT", 136 "HW_TEMP_PROTECT_INIT",
114 "HW_TEMP_PROTECT", 137 "HW_TEMP_PROTECT",
115 "NORMAL_INIT", 138 "NORMAL_INIT",
139 "USB_PP_PRE_CHARGE",
116 "NORMAL", 140 "NORMAL",
117 "WAIT_FOR_RECHARGE_INIT", 141 "WAIT_FOR_RECHARGE_INIT",
118 "WAIT_FOR_RECHARGE", 142 "WAIT_FOR_RECHARGE",
@@ -204,6 +228,8 @@ enum maxim_ret {
204 * @batt_data: data of the battery 228 * @batt_data: data of the battery
205 * @susp_status: current charger suspension status 229 * @susp_status: current charger suspension status
206 * @bm: Platform specific battery management information 230 * @bm: Platform specific battery management information
231 * @curr_status: Current step status for over-current protection
232 * @parent: pointer to the struct abx500
207 * @chargalg_psy: structure that holds the battery properties exposed by 233 * @chargalg_psy: structure that holds the battery properties exposed by
208 * the charging algorithm 234 * the charging algorithm
209 * @events: structure for information about events triggered 235 * @events: structure for information about events triggered
@@ -227,6 +253,8 @@ struct abx500_chargalg {
227 struct abx500_chargalg_charger_info chg_info; 253 struct abx500_chargalg_charger_info chg_info;
228 struct abx500_chargalg_battery_data batt_data; 254 struct abx500_chargalg_battery_data batt_data;
229 struct abx500_chargalg_suspension_status susp_status; 255 struct abx500_chargalg_suspension_status susp_status;
256 struct ab8500 *parent;
257 struct abx500_chargalg_current_step_status curr_status;
230 struct abx500_bm_data *bm; 258 struct abx500_bm_data *bm;
231 struct power_supply chargalg_psy; 259 struct power_supply chargalg_psy;
232 struct ux500_charger *ac_chg; 260 struct ux500_charger *ac_chg;
@@ -236,51 +264,69 @@ struct abx500_chargalg {
236 struct delayed_work chargalg_periodic_work; 264 struct delayed_work chargalg_periodic_work;
237 struct delayed_work chargalg_wd_work; 265 struct delayed_work chargalg_wd_work;
238 struct work_struct chargalg_work; 266 struct work_struct chargalg_work;
239 struct timer_list safety_timer; 267 struct hrtimer safety_timer;
240 struct timer_list maintenance_timer; 268 struct hrtimer maintenance_timer;
241 struct kobject chargalg_kobject; 269 struct kobject chargalg_kobject;
242}; 270};
243 271
272/*External charger prepare notifier*/
273BLOCKING_NOTIFIER_HEAD(charger_notifier_list);
274
244/* Main battery properties */ 275/* Main battery properties */
245static enum power_supply_property abx500_chargalg_props[] = { 276static enum power_supply_property abx500_chargalg_props[] = {
246 POWER_SUPPLY_PROP_STATUS, 277 POWER_SUPPLY_PROP_STATUS,
247 POWER_SUPPLY_PROP_HEALTH, 278 POWER_SUPPLY_PROP_HEALTH,
248}; 279};
249 280
281struct abx500_chargalg_sysfs_entry {
282 struct attribute attr;
283 ssize_t (*show)(struct abx500_chargalg *, char *);
284 ssize_t (*store)(struct abx500_chargalg *, const char *, size_t);
285};
286
250/** 287/**
251 * abx500_chargalg_safety_timer_expired() - Expiration of the safety timer 288 * abx500_chargalg_safety_timer_expired() - Expiration of the safety timer
252 * @data: pointer to the abx500_chargalg structure 289 * @timer: pointer to the hrtimer structure
253 * 290 *
254 * This function gets called when the safety timer for the charger 291 * This function gets called when the safety timer for the charger
255 * expires 292 * expires
256 */ 293 */
257static void abx500_chargalg_safety_timer_expired(unsigned long data) 294static enum hrtimer_restart
295abx500_chargalg_safety_timer_expired(struct hrtimer *timer)
258{ 296{
259 struct abx500_chargalg *di = (struct abx500_chargalg *) data; 297 struct abx500_chargalg *di = container_of(timer, struct abx500_chargalg,
298 safety_timer);
260 dev_err(di->dev, "Safety timer expired\n"); 299 dev_err(di->dev, "Safety timer expired\n");
261 di->events.safety_timer_expired = true; 300 di->events.safety_timer_expired = true;
262 301
263 /* Trigger execution of the algorithm instantly */ 302 /* Trigger execution of the algorithm instantly */
264 queue_work(di->chargalg_wq, &di->chargalg_work); 303 queue_work(di->chargalg_wq, &di->chargalg_work);
304
305 return HRTIMER_NORESTART;
265} 306}
266 307
267/** 308/**
268 * abx500_chargalg_maintenance_timer_expired() - Expiration of 309 * abx500_chargalg_maintenance_timer_expired() - Expiration of
269 * the maintenance timer 310 * the maintenance timer
270 * @i: pointer to the abx500_chargalg structure 311 * @timer: pointer to the timer structure
271 * 312 *
272 * This function gets called when the maintenence timer 313 * This function gets called when the maintenence timer
273 * expires 314 * expires
274 */ 315 */
275static void abx500_chargalg_maintenance_timer_expired(unsigned long data) 316static enum hrtimer_restart
317abx500_chargalg_maintenance_timer_expired(struct hrtimer *timer)
276{ 318{
277 319
278 struct abx500_chargalg *di = (struct abx500_chargalg *) data; 320 struct abx500_chargalg *di = container_of(timer, struct abx500_chargalg,
321 maintenance_timer);
322
279 dev_dbg(di->dev, "Maintenance timer expired\n"); 323 dev_dbg(di->dev, "Maintenance timer expired\n");
280 di->events.maintenance_timer_expired = true; 324 di->events.maintenance_timer_expired = true;
281 325
282 /* Trigger execution of the algorithm instantly */ 326 /* Trigger execution of the algorithm instantly */
283 queue_work(di->chargalg_wq, &di->chargalg_work); 327 queue_work(di->chargalg_wq, &di->chargalg_work);
328
329 return HRTIMER_NORESTART;
284} 330}
285 331
286/** 332/**
@@ -303,6 +349,30 @@ static void abx500_chargalg_state_to(struct abx500_chargalg *di,
303 di->charge_state = state; 349 di->charge_state = state;
304} 350}
305 351
352static int abx500_chargalg_check_charger_enable(struct abx500_chargalg *di)
353{
354 switch (di->charge_state) {
355 case STATE_NORMAL:
356 case STATE_MAINTENANCE_A:
357 case STATE_MAINTENANCE_B:
358 break;
359 default:
360 return 0;
361 }
362
363 if (di->chg_info.charger_type & USB_CHG) {
364 return di->usb_chg->ops.check_enable(di->usb_chg,
365 di->bm->bat_type[di->bm->batt_id].normal_vol_lvl,
366 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl);
367 } else if ((di->chg_info.charger_type & AC_CHG) &&
368 !(di->ac_chg->external)) {
369 return di->ac_chg->ops.check_enable(di->ac_chg,
370 di->bm->bat_type[di->bm->batt_id].normal_vol_lvl,
371 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl);
372 }
373 return 0;
374}
375
306/** 376/**
307 * abx500_chargalg_check_charger_connection() - Check charger connection change 377 * abx500_chargalg_check_charger_connection() - Check charger connection change
308 * @di: pointer to the abx500_chargalg structure 378 * @di: pointer to the abx500_chargalg structure
@@ -348,6 +418,22 @@ static int abx500_chargalg_check_charger_connection(struct abx500_chargalg *di)
348} 418}
349 419
350/** 420/**
421 * abx500_chargalg_check_current_step_status() - Check charging current
422 * step status.
423 * @di: pointer to the abx500_chargalg structure
424 *
425 * This function will check if there is a change in the charging current step
426 * and change charge state accordingly.
427 */
428static void abx500_chargalg_check_current_step_status
429 (struct abx500_chargalg *di)
430{
431 if (di->curr_status.curr_step_change)
432 abx500_chargalg_state_to(di, STATE_NORMAL_INIT);
433 di->curr_status.curr_step_change = false;
434}
435
436/**
351 * abx500_chargalg_start_safety_timer() - Start charging safety timer 437 * abx500_chargalg_start_safety_timer() - Start charging safety timer
352 * @di: pointer to the abx500_chargalg structure 438 * @di: pointer to the abx500_chargalg structure
353 * 439 *
@@ -356,19 +442,16 @@ static int abx500_chargalg_check_charger_connection(struct abx500_chargalg *di)
356 */ 442 */
357static void abx500_chargalg_start_safety_timer(struct abx500_chargalg *di) 443static void abx500_chargalg_start_safety_timer(struct abx500_chargalg *di)
358{ 444{
359 unsigned long timer_expiration = 0; 445 /* Charger-dependent expiration time in hours*/
446 int timer_expiration = 0;
360 447
361 switch (di->chg_info.charger_type) { 448 switch (di->chg_info.charger_type) {
362 case AC_CHG: 449 case AC_CHG:
363 timer_expiration = 450 timer_expiration = di->bm->main_safety_tmr_h;
364 round_jiffies(jiffies +
365 (di->bm->main_safety_tmr_h * 3600 * HZ));
366 break; 451 break;
367 452
368 case USB_CHG: 453 case USB_CHG:
369 timer_expiration = 454 timer_expiration = di->bm->usb_safety_tmr_h;
370 round_jiffies(jiffies +
371 (di->bm->usb_safety_tmr_h * 3600 * HZ));
372 break; 455 break;
373 456
374 default: 457 default:
@@ -377,11 +460,10 @@ static void abx500_chargalg_start_safety_timer(struct abx500_chargalg *di)
377 } 460 }
378 461
379 di->events.safety_timer_expired = false; 462 di->events.safety_timer_expired = false;
380 di->safety_timer.expires = timer_expiration; 463 hrtimer_set_expires_range(&di->safety_timer,
381 if (!timer_pending(&di->safety_timer)) 464 ktime_set(timer_expiration * ONE_HOUR_IN_SECONDS, 0),
382 add_timer(&di->safety_timer); 465 ktime_set(FIVE_MINUTES_IN_SECONDS, 0));
383 else 466 hrtimer_start_expires(&di->safety_timer, HRTIMER_MODE_REL);
384 mod_timer(&di->safety_timer, timer_expiration);
385} 467}
386 468
387/** 469/**
@@ -392,8 +474,8 @@ static void abx500_chargalg_start_safety_timer(struct abx500_chargalg *di)
392 */ 474 */
393static void abx500_chargalg_stop_safety_timer(struct abx500_chargalg *di) 475static void abx500_chargalg_stop_safety_timer(struct abx500_chargalg *di)
394{ 476{
395 di->events.safety_timer_expired = false; 477 if (hrtimer_try_to_cancel(&di->safety_timer) >= 0)
396 del_timer(&di->safety_timer); 478 di->events.safety_timer_expired = false;
397} 479}
398 480
399/** 481/**
@@ -408,17 +490,11 @@ static void abx500_chargalg_stop_safety_timer(struct abx500_chargalg *di)
408static void abx500_chargalg_start_maintenance_timer(struct abx500_chargalg *di, 490static void abx500_chargalg_start_maintenance_timer(struct abx500_chargalg *di,
409 int duration) 491 int duration)
410{ 492{
411 unsigned long timer_expiration; 493 hrtimer_set_expires_range(&di->maintenance_timer,
412 494 ktime_set(duration * ONE_HOUR_IN_SECONDS, 0),
413 /* Convert from hours to jiffies */ 495 ktime_set(FIVE_MINUTES_IN_SECONDS, 0));
414 timer_expiration = round_jiffies(jiffies + (duration * 3600 * HZ));
415
416 di->events.maintenance_timer_expired = false; 496 di->events.maintenance_timer_expired = false;
417 di->maintenance_timer.expires = timer_expiration; 497 hrtimer_start_expires(&di->maintenance_timer, HRTIMER_MODE_REL);
418 if (!timer_pending(&di->maintenance_timer))
419 add_timer(&di->maintenance_timer);
420 else
421 mod_timer(&di->maintenance_timer, timer_expiration);
422} 498}
423 499
424/** 500/**
@@ -430,8 +506,8 @@ static void abx500_chargalg_start_maintenance_timer(struct abx500_chargalg *di,
430 */ 506 */
431static void abx500_chargalg_stop_maintenance_timer(struct abx500_chargalg *di) 507static void abx500_chargalg_stop_maintenance_timer(struct abx500_chargalg *di)
432{ 508{
433 di->events.maintenance_timer_expired = false; 509 if (hrtimer_try_to_cancel(&di->maintenance_timer) >= 0)
434 del_timer(&di->maintenance_timer); 510 di->events.maintenance_timer_expired = false;
435} 511}
436 512
437/** 513/**
@@ -477,6 +553,8 @@ static int abx500_chargalg_kick_watchdog(struct abx500_chargalg *di)
477static int abx500_chargalg_ac_en(struct abx500_chargalg *di, int enable, 553static int abx500_chargalg_ac_en(struct abx500_chargalg *di, int enable,
478 int vset, int iset) 554 int vset, int iset)
479{ 555{
556 static int abx500_chargalg_ex_ac_enable_toggle;
557
480 if (!di->ac_chg || !di->ac_chg->ops.enable) 558 if (!di->ac_chg || !di->ac_chg->ops.enable)
481 return -ENXIO; 559 return -ENXIO;
482 560
@@ -489,6 +567,14 @@ static int abx500_chargalg_ac_en(struct abx500_chargalg *di, int enable,
489 di->chg_info.ac_iset = iset; 567 di->chg_info.ac_iset = iset;
490 di->chg_info.ac_vset = vset; 568 di->chg_info.ac_vset = vset;
491 569
570 /* Enable external charger */
571 if (enable && di->ac_chg->external &&
572 !abx500_chargalg_ex_ac_enable_toggle) {
573 blocking_notifier_call_chain(&charger_notifier_list,
574 0, di->dev);
575 abx500_chargalg_ex_ac_enable_toggle++;
576 }
577
492 return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset); 578 return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset);
493} 579}
494 580
@@ -520,6 +606,37 @@ static int abx500_chargalg_usb_en(struct abx500_chargalg *di, int enable,
520 return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset); 606 return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset);
521} 607}
522 608
609 /**
610 * ab8540_chargalg_usb_pp_en() - Enable/ disable USB power path
611 * @di: pointer to the abx500_chargalg structure
612 * @enable: power path enable/disable
613 *
614 * The USB power path will be enable/ disable
615 */
616static int ab8540_chargalg_usb_pp_en(struct abx500_chargalg *di, bool enable)
617{
618 if (!di->usb_chg || !di->usb_chg->ops.pp_enable)
619 return -ENXIO;
620
621 return di->usb_chg->ops.pp_enable(di->usb_chg, enable);
622}
623
624/**
625 * ab8540_chargalg_usb_pre_chg_en() - Enable/ disable USB pre-charge
626 * @di: pointer to the abx500_chargalg structure
627 * @enable: USB pre-charge enable/disable
628 *
629 * The USB USB pre-charge will be enable/ disable
630 */
631static int ab8540_chargalg_usb_pre_chg_en(struct abx500_chargalg *di,
632 bool enable)
633{
634 if (!di->usb_chg || !di->usb_chg->ops.pre_chg_enable)
635 return -ENXIO;
636
637 return di->usb_chg->ops.pre_chg_enable(di->usb_chg, enable);
638}
639
523/** 640/**
524 * abx500_chargalg_update_chg_curr() - Update charger current 641 * abx500_chargalg_update_chg_curr() - Update charger current
525 * @di: pointer to the abx500_chargalg structure 642 * @di: pointer to the abx500_chargalg structure
@@ -613,8 +730,6 @@ static void abx500_chargalg_hold_charging(struct abx500_chargalg *di)
613static void abx500_chargalg_start_charging(struct abx500_chargalg *di, 730static void abx500_chargalg_start_charging(struct abx500_chargalg *di,
614 int vset, int iset) 731 int vset, int iset)
615{ 732{
616 bool start_chargalg_wd = true;
617
618 switch (di->chg_info.charger_type) { 733 switch (di->chg_info.charger_type) {
619 case AC_CHG: 734 case AC_CHG:
620 dev_dbg(di->dev, 735 dev_dbg(di->dev,
@@ -632,12 +747,8 @@ static void abx500_chargalg_start_charging(struct abx500_chargalg *di,
632 747
633 default: 748 default:
634 dev_err(di->dev, "Unknown charger to charge from\n"); 749 dev_err(di->dev, "Unknown charger to charge from\n");
635 start_chargalg_wd = false;
636 break; 750 break;
637 } 751 }
638
639 if (start_chargalg_wd && !delayed_work_pending(&di->chargalg_wd_work))
640 queue_delayed_work(di->chargalg_wq, &di->chargalg_wd_work, 0);
641} 752}
642 753
643/** 754/**
@@ -725,6 +836,9 @@ static void abx500_chargalg_end_of_charge(struct abx500_chargalg *di)
725 di->batt_data.avg_curr > 0) { 836 di->batt_data.avg_curr > 0) {
726 if (++di->eoc_cnt >= EOC_COND_CNT) { 837 if (++di->eoc_cnt >= EOC_COND_CNT) {
727 di->eoc_cnt = 0; 838 di->eoc_cnt = 0;
839 if ((di->chg_info.charger_type & USB_CHG) &&
840 (di->usb_chg->power_path))
841 ab8540_chargalg_usb_pp_en(di, true);
728 di->charge_status = POWER_SUPPLY_STATUS_FULL; 842 di->charge_status = POWER_SUPPLY_STATUS_FULL;
729 di->maintenance_chg = true; 843 di->maintenance_chg = true;
730 dev_dbg(di->dev, "EOC reached!\n"); 844 dev_dbg(di->dev, "EOC reached!\n");
@@ -1217,6 +1331,8 @@ static void abx500_chargalg_external_power_changed(struct power_supply *psy)
1217static void abx500_chargalg_algorithm(struct abx500_chargalg *di) 1331static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1218{ 1332{
1219 int charger_status; 1333 int charger_status;
1334 int ret;
1335 int curr_step_lvl;
1220 1336
1221 /* Collect data from all power_supply class devices */ 1337 /* Collect data from all power_supply class devices */
1222 class_for_each_device(power_supply_class, NULL, 1338 class_for_each_device(power_supply_class, NULL,
@@ -1227,6 +1343,15 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1227 abx500_chargalg_check_charger_voltage(di); 1343 abx500_chargalg_check_charger_voltage(di);
1228 1344
1229 charger_status = abx500_chargalg_check_charger_connection(di); 1345 charger_status = abx500_chargalg_check_charger_connection(di);
1346 abx500_chargalg_check_current_step_status(di);
1347
1348 if (is_ab8500(di->parent)) {
1349 ret = abx500_chargalg_check_charger_enable(di);
1350 if (ret < 0)
1351 dev_err(di->dev, "Checking charger is enabled error"
1352 ": Returned Value %d\n", ret);
1353 }
1354
1230 /* 1355 /*
1231 * First check if we have a charger connected. 1356 * First check if we have a charger connected.
1232 * Also we don't allow charging of unknown batteries if configured 1357 * Also we don't allow charging of unknown batteries if configured
@@ -1416,9 +1541,34 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1416 break; 1541 break;
1417 1542
1418 case STATE_NORMAL_INIT: 1543 case STATE_NORMAL_INIT:
1419 abx500_chargalg_start_charging(di, 1544 if ((di->chg_info.charger_type & USB_CHG) &&
1420 di->bm->bat_type[di->bm->batt_id].normal_vol_lvl, 1545 di->usb_chg->power_path) {
1421 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); 1546 if (di->batt_data.volt >
1547 (di->bm->fg_params->lowbat_threshold +
1548 BAT_PLUS_MARGIN)) {
1549 ab8540_chargalg_usb_pre_chg_en(di, false);
1550 ab8540_chargalg_usb_pp_en(di, false);
1551 } else {
1552 ab8540_chargalg_usb_pp_en(di, true);
1553 ab8540_chargalg_usb_pre_chg_en(di, true);
1554 abx500_chargalg_state_to(di,
1555 STATE_USB_PP_PRE_CHARGE);
1556 break;
1557 }
1558 }
1559
1560 if (di->curr_status.curr_step == CHARGALG_CURR_STEP_LOW)
1561 abx500_chargalg_stop_charging(di);
1562 else {
1563 curr_step_lvl = di->bm->bat_type[
1564 di->bm->batt_id].normal_cur_lvl
1565 * di->curr_status.curr_step
1566 / CHARGALG_CURR_STEP_HIGH;
1567 abx500_chargalg_start_charging(di,
1568 di->bm->bat_type[di->bm->batt_id]
1569 .normal_vol_lvl, curr_step_lvl);
1570 }
1571
1422 abx500_chargalg_state_to(di, STATE_NORMAL); 1572 abx500_chargalg_state_to(di, STATE_NORMAL);
1423 abx500_chargalg_start_safety_timer(di); 1573 abx500_chargalg_start_safety_timer(di);
1424 abx500_chargalg_stop_maintenance_timer(di); 1574 abx500_chargalg_stop_maintenance_timer(di);
@@ -1430,6 +1580,13 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1430 1580
1431 break; 1581 break;
1432 1582
1583 case STATE_USB_PP_PRE_CHARGE:
1584 if (di->batt_data.volt >
1585 (di->bm->fg_params->lowbat_threshold +
1586 BAT_PLUS_MARGIN))
1587 abx500_chargalg_state_to(di, STATE_NORMAL_INIT);
1588 break;
1589
1433 case STATE_NORMAL: 1590 case STATE_NORMAL:
1434 handle_maxim_chg_curr(di); 1591 handle_maxim_chg_curr(di);
1435 if (di->charge_status == POWER_SUPPLY_STATUS_FULL && 1592 if (di->charge_status == POWER_SUPPLY_STATUS_FULL &&
@@ -1653,99 +1810,134 @@ static int abx500_chargalg_get_property(struct power_supply *psy,
1653 1810
1654/* Exposure to the sysfs interface */ 1811/* Exposure to the sysfs interface */
1655 1812
1656/** 1813static ssize_t abx500_chargalg_curr_step_show(struct abx500_chargalg *di,
1657 * abx500_chargalg_sysfs_show() - sysfs show operations 1814 char *buf)
1658 * @kobj: pointer to the struct kobject
1659 * @attr: pointer to the struct attribute
1660 * @buf: buffer that holds the parameter to send to userspace
1661 *
1662 * Returns a buffer to be displayed in user space
1663 */
1664static ssize_t abx500_chargalg_sysfs_show(struct kobject *kobj,
1665 struct attribute *attr, char *buf)
1666{ 1815{
1667 struct abx500_chargalg *di = container_of(kobj, 1816 return sprintf(buf, "%d\n", di->curr_status.curr_step);
1668 struct abx500_chargalg, chargalg_kobject); 1817}
1818
1819static ssize_t abx500_chargalg_curr_step_store(struct abx500_chargalg *di,
1820 const char *buf, size_t length)
1821{
1822 long int param;
1823 int ret;
1824
1825 ret = kstrtol(buf, 10, &param);
1826 if (ret < 0)
1827 return ret;
1828
1829 di->curr_status.curr_step = param;
1830 if (di->curr_status.curr_step >= CHARGALG_CURR_STEP_LOW &&
1831 di->curr_status.curr_step <= CHARGALG_CURR_STEP_HIGH) {
1832 di->curr_status.curr_step_change = true;
1833 queue_work(di->chargalg_wq, &di->chargalg_work);
1834 } else
1835 dev_info(di->dev, "Wrong current step\n"
1836 "Enter 0. Disable AC/USB Charging\n"
1837 "1--100. Set AC/USB charging current step\n"
1838 "100. Enable AC/USB Charging\n");
1839
1840 return strlen(buf);
1841}
1842
1669 1843
1844static ssize_t abx500_chargalg_en_show(struct abx500_chargalg *di,
1845 char *buf)
1846{
1670 return sprintf(buf, "%d\n", 1847 return sprintf(buf, "%d\n",
1671 di->susp_status.ac_suspended && 1848 di->susp_status.ac_suspended &&
1672 di->susp_status.usb_suspended); 1849 di->susp_status.usb_suspended);
1673} 1850}
1674 1851
1675/** 1852static ssize_t abx500_chargalg_en_store(struct abx500_chargalg *di,
1676 * abx500_chargalg_sysfs_charger() - sysfs store operations 1853 const char *buf, size_t length)
1677 * @kobj: pointer to the struct kobject
1678 * @attr: pointer to the struct attribute
1679 * @buf: buffer that holds the parameter passed from userspace
1680 * @length: length of the parameter passed
1681 *
1682 * Returns length of the buffer(input taken from user space) on success
1683 * else error code on failure
1684 * The operation to be performed on passing the parameters from the user space.
1685 */
1686static ssize_t abx500_chargalg_sysfs_charger(struct kobject *kobj,
1687 struct attribute *attr, const char *buf, size_t length)
1688{ 1854{
1689 struct abx500_chargalg *di = container_of(kobj,
1690 struct abx500_chargalg, chargalg_kobject);
1691 long int param; 1855 long int param;
1692 int ac_usb; 1856 int ac_usb;
1693 int ret; 1857 int ret;
1694 char entry = *attr->name;
1695 1858
1696 switch (entry) { 1859 ret = kstrtol(buf, 10, &param);
1697 case 'c': 1860 if (ret < 0)
1698 ret = strict_strtol(buf, 10, &param); 1861 return ret;
1699 if (ret < 0) 1862
1700 return ret; 1863 ac_usb = param;
1701 1864 switch (ac_usb) {
1702 ac_usb = param; 1865 case 0:
1703 switch (ac_usb) { 1866 /* Disable charging */
1704 case 0: 1867 di->susp_status.ac_suspended = true;
1705 /* Disable charging */ 1868 di->susp_status.usb_suspended = true;
1706 di->susp_status.ac_suspended = true; 1869 di->susp_status.suspended_change = true;
1707 di->susp_status.usb_suspended = true; 1870 /* Trigger a state change */
1708 di->susp_status.suspended_change = true; 1871 queue_work(di->chargalg_wq,
1709 /* Trigger a state change */ 1872 &di->chargalg_work);
1710 queue_work(di->chargalg_wq, 1873 break;
1711 &di->chargalg_work); 1874 case 1:
1712 break; 1875 /* Enable AC Charging */
1713 case 1: 1876 di->susp_status.ac_suspended = false;
1714 /* Enable AC Charging */ 1877 di->susp_status.suspended_change = true;
1715 di->susp_status.ac_suspended = false; 1878 /* Trigger a state change */
1716 di->susp_status.suspended_change = true; 1879 queue_work(di->chargalg_wq,
1717 /* Trigger a state change */ 1880 &di->chargalg_work);
1718 queue_work(di->chargalg_wq, 1881 break;
1719 &di->chargalg_work); 1882 case 2:
1720 break; 1883 /* Enable USB charging */
1721 case 2: 1884 di->susp_status.usb_suspended = false;
1722 /* Enable USB charging */ 1885 di->susp_status.suspended_change = true;
1723 di->susp_status.usb_suspended = false; 1886 /* Trigger a state change */
1724 di->susp_status.suspended_change = true; 1887 queue_work(di->chargalg_wq,
1725 /* Trigger a state change */ 1888 &di->chargalg_work);
1726 queue_work(di->chargalg_wq,
1727 &di->chargalg_work);
1728 break;
1729 default:
1730 dev_info(di->dev, "Wrong input\n"
1731 "Enter 0. Disable AC/USB Charging\n"
1732 "1. Enable AC charging\n"
1733 "2. Enable USB Charging\n");
1734 };
1735 break; 1889 break;
1890 default:
1891 dev_info(di->dev, "Wrong input\n"
1892 "Enter 0. Disable AC/USB Charging\n"
1893 "1. Enable AC charging\n"
1894 "2. Enable USB Charging\n");
1736 }; 1895 };
1737 return strlen(buf); 1896 return strlen(buf);
1738} 1897}
1739 1898
1740static struct attribute abx500_chargalg_en_charger = \ 1899static struct abx500_chargalg_sysfs_entry abx500_chargalg_en_charger =
1900 __ATTR(chargalg, 0644, abx500_chargalg_en_show,
1901 abx500_chargalg_en_store);
1902
1903static struct abx500_chargalg_sysfs_entry abx500_chargalg_curr_step =
1904 __ATTR(chargalg_curr_step, 0644, abx500_chargalg_curr_step_show,
1905 abx500_chargalg_curr_step_store);
1906
1907static ssize_t abx500_chargalg_sysfs_show(struct kobject *kobj,
1908 struct attribute *attr, char *buf)
1741{ 1909{
1742 .name = "chargalg", 1910 struct abx500_chargalg_sysfs_entry *entry = container_of(attr,
1743 .mode = S_IRUGO | S_IWUSR, 1911 struct abx500_chargalg_sysfs_entry, attr);
1744}; 1912
1913 struct abx500_chargalg *di = container_of(kobj,
1914 struct abx500_chargalg, chargalg_kobject);
1915
1916 if (!entry->show)
1917 return -EIO;
1918
1919 return entry->show(di, buf);
1920}
1921
1922static ssize_t abx500_chargalg_sysfs_charger(struct kobject *kobj,
1923 struct attribute *attr, const char *buf, size_t length)
1924{
1925 struct abx500_chargalg_sysfs_entry *entry = container_of(attr,
1926 struct abx500_chargalg_sysfs_entry, attr);
1927
1928 struct abx500_chargalg *di = container_of(kobj,
1929 struct abx500_chargalg, chargalg_kobject);
1930
1931 if (!entry->store)
1932 return -EIO;
1933
1934 return entry->store(di, buf, length);
1935}
1745 1936
1746static struct attribute *abx500_chargalg_chg[] = { 1937static struct attribute *abx500_chargalg_chg[] = {
1747 &abx500_chargalg_en_charger, 1938 &abx500_chargalg_en_charger.attr,
1748 NULL 1939 &abx500_chargalg_curr_step.attr,
1940 NULL,
1749}; 1941};
1750 1942
1751static const struct sysfs_ops abx500_chargalg_sysfs_ops = { 1943static const struct sysfs_ops abx500_chargalg_sysfs_ops = {
@@ -1832,10 +2024,16 @@ static int abx500_chargalg_remove(struct platform_device *pdev)
1832 /* sysfs interface to enable/disbale charging from user space */ 2024 /* sysfs interface to enable/disbale charging from user space */
1833 abx500_chargalg_sysfs_exit(di); 2025 abx500_chargalg_sysfs_exit(di);
1834 2026
2027 hrtimer_cancel(&di->safety_timer);
2028 hrtimer_cancel(&di->maintenance_timer);
2029
2030 cancel_delayed_work_sync(&di->chargalg_periodic_work);
2031 cancel_delayed_work_sync(&di->chargalg_wd_work);
2032 cancel_work_sync(&di->chargalg_work);
2033
1835 /* Delete the work queue */ 2034 /* Delete the work queue */
1836 destroy_workqueue(di->chargalg_wq); 2035 destroy_workqueue(di->chargalg_wq);
1837 2036
1838 flush_scheduled_work();
1839 power_supply_unregister(&di->chargalg_psy); 2037 power_supply_unregister(&di->chargalg_psy);
1840 platform_set_drvdata(pdev, NULL); 2038 platform_set_drvdata(pdev, NULL);
1841 2039
@@ -1873,8 +2071,9 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
1873 } 2071 }
1874 } 2072 }
1875 2073
1876 /* get device struct */ 2074 /* get device struct and parent */
1877 di->dev = &pdev->dev; 2075 di->dev = &pdev->dev;
2076 di->parent = dev_get_drvdata(pdev->dev.parent);
1878 2077
1879 /* chargalg supply */ 2078 /* chargalg supply */
1880 di->chargalg_psy.name = "abx500_chargalg"; 2079 di->chargalg_psy.name = "abx500_chargalg";
@@ -1888,15 +2087,13 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
1888 abx500_chargalg_external_power_changed; 2087 abx500_chargalg_external_power_changed;
1889 2088
1890 /* Initilialize safety timer */ 2089 /* Initilialize safety timer */
1891 init_timer(&di->safety_timer); 2090 hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
1892 di->safety_timer.function = abx500_chargalg_safety_timer_expired; 2091 di->safety_timer.function = abx500_chargalg_safety_timer_expired;
1893 di->safety_timer.data = (unsigned long) di;
1894 2092
1895 /* Initilialize maintenance timer */ 2093 /* Initilialize maintenance timer */
1896 init_timer(&di->maintenance_timer); 2094 hrtimer_init(&di->maintenance_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
1897 di->maintenance_timer.function = 2095 di->maintenance_timer.function =
1898 abx500_chargalg_maintenance_timer_expired; 2096 abx500_chargalg_maintenance_timer_expired;
1899 di->maintenance_timer.data = (unsigned long) di;
1900 2097
1901 /* Create a work queue for the chargalg */ 2098 /* Create a work queue for the chargalg */
1902 di->chargalg_wq = 2099 di->chargalg_wq =
@@ -1933,6 +2130,7 @@ static int abx500_chargalg_probe(struct platform_device *pdev)
1933 dev_err(di->dev, "failed to create sysfs entry\n"); 2130 dev_err(di->dev, "failed to create sysfs entry\n");
1934 goto free_psy; 2131 goto free_psy;
1935 } 2132 }
2133 di->curr_status.curr_step = CHARGALG_CURR_STEP_HIGH;
1936 2134
1937 /* Run the charging algorithm */ 2135 /* Run the charging algorithm */
1938 queue_delayed_work(di->chargalg_wq, &di->chargalg_periodic_work, 0); 2136 queue_delayed_work(di->chargalg_wq, &di->chargalg_periodic_work, 0);
@@ -1964,18 +2162,7 @@ static struct platform_driver abx500_chargalg_driver = {
1964 }, 2162 },
1965}; 2163};
1966 2164
1967static int __init abx500_chargalg_init(void) 2165module_platform_driver(abx500_chargalg_driver);
1968{
1969 return platform_driver_register(&abx500_chargalg_driver);
1970}
1971
1972static void __exit abx500_chargalg_exit(void)
1973{
1974 platform_driver_unregister(&abx500_chargalg_driver);
1975}
1976
1977module_init(abx500_chargalg_init);
1978module_exit(abx500_chargalg_exit);
1979 2166
1980MODULE_LICENSE("GPL v2"); 2167MODULE_LICENSE("GPL v2");
1981MODULE_AUTHOR("Johan Palsson, Karl Komierowski"); 2168MODULE_AUTHOR("Johan Palsson, Karl Komierowski");
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 8acc3f8d303c..fefc39fe42be 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -1485,13 +1485,12 @@ static int charger_manager_probe(struct platform_device *pdev)
1485 1485
1486 /* Basic Values. Unspecified are Null or 0 */ 1486 /* Basic Values. Unspecified are Null or 0 */
1487 cm->dev = &pdev->dev; 1487 cm->dev = &pdev->dev;
1488 cm->desc = kzalloc(sizeof(struct charger_desc), GFP_KERNEL); 1488 cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL);
1489 if (!cm->desc) { 1489 if (!cm->desc) {
1490 dev_err(&pdev->dev, "Cannot allocate memory.\n"); 1490 dev_err(&pdev->dev, "Cannot allocate memory.\n");
1491 ret = -ENOMEM; 1491 ret = -ENOMEM;
1492 goto err_alloc_desc; 1492 goto err_alloc_desc;
1493 } 1493 }
1494 memcpy(cm->desc, desc, sizeof(struct charger_desc));
1495 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */ 1494 cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */
1496 1495
1497 /* 1496 /*
diff --git a/drivers/power/da9030_battery.c b/drivers/power/da9030_battery.c
index e8c5a391a498..ae6c41835ee6 100644
--- a/drivers/power/da9030_battery.c
+++ b/drivers/power/da9030_battery.c
@@ -505,7 +505,7 @@ static int da9030_battery_probe(struct platform_device *pdev)
505 pdata->charge_millivolt > 4350) 505 pdata->charge_millivolt > 4350)
506 return -EINVAL; 506 return -EINVAL;
507 507
508 charger = kzalloc(sizeof(*charger), GFP_KERNEL); 508 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
509 if (charger == NULL) 509 if (charger == NULL)
510 return -ENOMEM; 510 return -ENOMEM;
511 511
@@ -557,8 +557,6 @@ err_notifier:
557 cancel_delayed_work(&charger->work); 557 cancel_delayed_work(&charger->work);
558 558
559err_charger_init: 559err_charger_init:
560 kfree(charger);
561
562 return ret; 560 return ret;
563} 561}
564 562
@@ -575,8 +573,6 @@ static int da9030_battery_remove(struct platform_device *dev)
575 da9030_set_charge(charger, 0); 573 da9030_set_charge(charger, 0);
576 power_supply_unregister(&charger->psy); 574 power_supply_unregister(&charger->psy);
577 575
578 kfree(charger);
579
580 return 0; 576 return 0;
581} 577}
582 578
diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
index 08193feb3b08..f8f4c0f7c17d 100644
--- a/drivers/power/da9052-battery.c
+++ b/drivers/power/da9052-battery.c
@@ -594,7 +594,8 @@ static s32 da9052_bat_probe(struct platform_device *pdev)
594 int ret; 594 int ret;
595 int i; 595 int i;
596 596
597 bat = kzalloc(sizeof(struct da9052_battery), GFP_KERNEL); 597 bat = devm_kzalloc(&pdev->dev, sizeof(struct da9052_battery),
598 GFP_KERNEL);
598 if (!bat) 599 if (!bat)
599 return -ENOMEM; 600 return -ENOMEM;
600 601
@@ -635,7 +636,6 @@ err:
635 while (--i >= 0) 636 while (--i >= 0)
636 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat); 637 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat);
637 638
638 kfree(bat);
639 return ret; 639 return ret;
640} 640}
641static int da9052_bat_remove(struct platform_device *pdev) 641static int da9052_bat_remove(struct platform_device *pdev)
@@ -647,7 +647,6 @@ static int da9052_bat_remove(struct platform_device *pdev)
647 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat); 647 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat);
648 648
649 power_supply_unregister(&bat->psy); 649 power_supply_unregister(&bat->psy);
650 kfree(bat);
651 650
652 return 0; 651 return 0;
653} 652}
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c
index 704e652072be..85b4e6eca0b1 100644
--- a/drivers/power/ds2760_battery.c
+++ b/drivers/power/ds2760_battery.c
@@ -512,7 +512,7 @@ static int ds2760_battery_probe(struct platform_device *pdev)
512 int retval = 0; 512 int retval = 0;
513 struct ds2760_device_info *di; 513 struct ds2760_device_info *di;
514 514
515 di = kzalloc(sizeof(*di), GFP_KERNEL); 515 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
516 if (!di) { 516 if (!di) {
517 retval = -ENOMEM; 517 retval = -ENOMEM;
518 goto di_alloc_failed; 518 goto di_alloc_failed;
@@ -576,7 +576,6 @@ static int ds2760_battery_probe(struct platform_device *pdev)
576workqueue_failed: 576workqueue_failed:
577 power_supply_unregister(&di->bat); 577 power_supply_unregister(&di->bat);
578batt_failed: 578batt_failed:
579 kfree(di);
580di_alloc_failed: 579di_alloc_failed:
581success: 580success:
582 return retval; 581 return retval;
@@ -590,7 +589,6 @@ static int ds2760_battery_remove(struct platform_device *pdev)
590 cancel_delayed_work_sync(&di->set_charged_work); 589 cancel_delayed_work_sync(&di->set_charged_work);
591 destroy_workqueue(di->monitor_wqueue); 590 destroy_workqueue(di->monitor_wqueue);
592 power_supply_unregister(&di->bat); 591 power_supply_unregister(&di->bat);
593 kfree(di);
594 592
595 return 0; 593 return 0;
596} 594}
diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index 8b6c4539e7f4..9f418fa879e5 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -760,7 +760,7 @@ static int ds2780_battery_probe(struct platform_device *pdev)
760 int ret = 0; 760 int ret = 0;
761 struct ds2780_device_info *dev_info; 761 struct ds2780_device_info *dev_info;
762 762
763 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); 763 dev_info = devm_kzalloc(&pdev->dev, sizeof(*dev_info), GFP_KERNEL);
764 if (!dev_info) { 764 if (!dev_info) {
765 ret = -ENOMEM; 765 ret = -ENOMEM;
766 goto fail; 766 goto fail;
@@ -779,7 +779,7 @@ static int ds2780_battery_probe(struct platform_device *pdev)
779 ret = power_supply_register(&pdev->dev, &dev_info->bat); 779 ret = power_supply_register(&pdev->dev, &dev_info->bat);
780 if (ret) { 780 if (ret) {
781 dev_err(dev_info->dev, "failed to register battery\n"); 781 dev_err(dev_info->dev, "failed to register battery\n");
782 goto fail_free_info; 782 goto fail;
783 } 783 }
784 784
785 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 785 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
@@ -813,8 +813,6 @@ fail_remove_group:
813 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 813 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
814fail_unregister: 814fail_unregister:
815 power_supply_unregister(&dev_info->bat); 815 power_supply_unregister(&dev_info->bat);
816fail_free_info:
817 kfree(dev_info);
818fail: 816fail:
819 return ret; 817 return ret;
820} 818}
@@ -828,7 +826,6 @@ static int ds2780_battery_remove(struct platform_device *pdev)
828 826
829 power_supply_unregister(&dev_info->bat); 827 power_supply_unregister(&dev_info->bat);
830 828
831 kfree(dev_info);
832 return 0; 829 return 0;
833} 830}
834 831
diff --git a/drivers/power/ds2782_battery.c b/drivers/power/ds2782_battery.c
index c09e7726c96c..563174891c90 100644
--- a/drivers/power/ds2782_battery.c
+++ b/drivers/power/ds2782_battery.c
@@ -332,32 +332,32 @@ static int ds278x_battery_remove(struct i2c_client *client)
332 return 0; 332 return 0;
333} 333}
334 334
335#ifdef CONFIG_PM 335#ifdef CONFIG_PM_SLEEP
336 336
337static int ds278x_suspend(struct i2c_client *client, 337static int ds278x_suspend(struct device *dev)
338 pm_message_t state)
339{ 338{
339 struct i2c_client *client = to_i2c_client(dev);
340 struct ds278x_info *info = i2c_get_clientdata(client); 340 struct ds278x_info *info = i2c_get_clientdata(client);
341 341
342 cancel_delayed_work(&info->bat_work); 342 cancel_delayed_work(&info->bat_work);
343 return 0; 343 return 0;
344} 344}
345 345
346static int ds278x_resume(struct i2c_client *client) 346static int ds278x_resume(struct device *dev)
347{ 347{
348 struct i2c_client *client = to_i2c_client(dev);
348 struct ds278x_info *info = i2c_get_clientdata(client); 349 struct ds278x_info *info = i2c_get_clientdata(client);
349 350
350 schedule_delayed_work(&info->bat_work, DS278x_DELAY); 351 schedule_delayed_work(&info->bat_work, DS278x_DELAY);
351 return 0; 352 return 0;
352} 353}
353 354
354#else 355static SIMPLE_DEV_PM_OPS(ds278x_battery_pm_ops, ds278x_suspend, ds278x_resume);
355 356#define DS278X_BATTERY_PM_OPS (&ds278x_battery_pm_ops)
356#define ds278x_suspend NULL
357#define ds278x_resume NULL
358
359#endif /* CONFIG_PM */
360 357
358#else
359#define DS278X_BATTERY_PM_OPS NULL
360#endif /* CONFIG_PM_SLEEP */
361 361
362enum ds278x_num_id { 362enum ds278x_num_id {
363 DS2782 = 0, 363 DS2782 = 0,
@@ -460,11 +460,10 @@ MODULE_DEVICE_TABLE(i2c, ds278x_id);
460static struct i2c_driver ds278x_battery_driver = { 460static struct i2c_driver ds278x_battery_driver = {
461 .driver = { 461 .driver = {
462 .name = "ds2782-battery", 462 .name = "ds2782-battery",
463 .pm = DS278X_BATTERY_PM_OPS,
463 }, 464 },
464 .probe = ds278x_battery_probe, 465 .probe = ds278x_battery_probe,
465 .remove = ds278x_battery_remove, 466 .remove = ds278x_battery_remove,
466 .suspend = ds278x_suspend,
467 .resume = ds278x_resume,
468 .id_table = ds278x_id, 467 .id_table = ds278x_id,
469}; 468};
470module_i2c_driver(ds278x_battery_driver); 469module_i2c_driver(ds278x_battery_driver);
diff --git a/drivers/power/goldfish_battery.c b/drivers/power/goldfish_battery.c
index c10f460f986f..29eba88a2963 100644
--- a/drivers/power/goldfish_battery.c
+++ b/drivers/power/goldfish_battery.c
@@ -178,7 +178,7 @@ static int goldfish_battery_probe(struct platform_device *pdev)
178 return -ENODEV; 178 return -ENODEV;
179 } 179 }
180 180
181 data->reg_base = devm_ioremap(&pdev->dev, r->start, r->end - r->start + 1); 181 data->reg_base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
182 if (data->reg_base == NULL) { 182 if (data->reg_base == NULL) {
183 dev_err(&pdev->dev, "unable to remap MMIO\n"); 183 dev_err(&pdev->dev, "unable to remap MMIO\n");
184 return -ENOMEM; 184 return -ENOMEM;
diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
index e3e40a9f3af2..e9883eeeee76 100644
--- a/drivers/power/gpio-charger.c
+++ b/drivers/power/gpio-charger.c
@@ -86,7 +86,8 @@ static int gpio_charger_probe(struct platform_device *pdev)
86 return -EINVAL; 86 return -EINVAL;
87 } 87 }
88 88
89 gpio_charger = kzalloc(sizeof(*gpio_charger), GFP_KERNEL); 89 gpio_charger = devm_kzalloc(&pdev->dev, sizeof(*gpio_charger),
90 GFP_KERNEL);
90 if (!gpio_charger) { 91 if (!gpio_charger) {
91 dev_err(&pdev->dev, "Failed to alloc driver structure\n"); 92 dev_err(&pdev->dev, "Failed to alloc driver structure\n");
92 return -ENOMEM; 93 return -ENOMEM;
@@ -140,7 +141,6 @@ static int gpio_charger_probe(struct platform_device *pdev)
140err_gpio_free: 141err_gpio_free:
141 gpio_free(pdata->gpio); 142 gpio_free(pdata->gpio);
142err_free: 143err_free:
143 kfree(gpio_charger);
144 return ret; 144 return ret;
145} 145}
146 146
@@ -156,7 +156,6 @@ static int gpio_charger_remove(struct platform_device *pdev)
156 gpio_free(gpio_charger->pdata->gpio); 156 gpio_free(gpio_charger->pdata->gpio);
157 157
158 platform_set_drvdata(pdev, NULL); 158 platform_set_drvdata(pdev, NULL);
159 kfree(gpio_charger);
160 159
161 return 0; 160 return 0;
162} 161}
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c
index 176ad59d99f5..fc04d191579b 100644
--- a/drivers/power/isp1704_charger.c
+++ b/drivers/power/isp1704_charger.c
@@ -411,7 +411,7 @@ static int isp1704_charger_probe(struct platform_device *pdev)
411 struct isp1704_charger *isp; 411 struct isp1704_charger *isp;
412 int ret = -ENODEV; 412 int ret = -ENODEV;
413 413
414 isp = kzalloc(sizeof *isp, GFP_KERNEL); 414 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
415 if (!isp) 415 if (!isp)
416 return -ENOMEM; 416 return -ENOMEM;
417 417
@@ -477,8 +477,6 @@ fail1:
477 isp1704_charger_set_power(isp, 0); 477 isp1704_charger_set_power(isp, 0);
478 usb_put_phy(isp->phy); 478 usb_put_phy(isp->phy);
479fail0: 479fail0:
480 kfree(isp);
481
482 dev_err(&pdev->dev, "failed to register isp1704 with error %d\n", ret); 480 dev_err(&pdev->dev, "failed to register isp1704 with error %d\n", ret);
483 481
484 return ret; 482 return ret;
@@ -492,7 +490,6 @@ static int isp1704_charger_remove(struct platform_device *pdev)
492 power_supply_unregister(&isp->psy); 490 power_supply_unregister(&isp->psy);
493 usb_put_phy(isp->phy); 491 usb_put_phy(isp->phy);
494 isp1704_charger_set_power(isp, 0); 492 isp1704_charger_set_power(isp, 0);
495 kfree(isp);
496 493
497 return 0; 494 return 0;
498} 495}
diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
index 6d1f452810b8..ed49b50b220b 100644
--- a/drivers/power/lp8788-charger.c
+++ b/drivers/power/lp8788-charger.c
@@ -49,7 +49,6 @@
49#define LP8788_CHG_START 0x11 49#define LP8788_CHG_START 0x11
50#define LP8788_CHG_END 0x1C 50#define LP8788_CHG_END 0x1C
51 51
52#define LP8788_BUF_SIZE 40
53#define LP8788_ISEL_MAX 23 52#define LP8788_ISEL_MAX 23
54#define LP8788_ISEL_STEP 50 53#define LP8788_ISEL_STEP 50
55#define LP8788_VTERM_MIN 4100 54#define LP8788_VTERM_MIN 4100
@@ -633,7 +632,7 @@ static ssize_t lp8788_show_charger_status(struct device *dev,
633 lp8788_read_byte(pchg->lp, LP8788_CHG_STATUS, &data); 632 lp8788_read_byte(pchg->lp, LP8788_CHG_STATUS, &data);
634 state = (data & LP8788_CHG_STATE_M) >> LP8788_CHG_STATE_S; 633 state = (data & LP8788_CHG_STATE_M) >> LP8788_CHG_STATE_S;
635 634
636 return scnprintf(buf, LP8788_BUF_SIZE, "%s\n", desc[state]); 635 return scnprintf(buf, PAGE_SIZE, "%s\n", desc[state]);
637} 636}
638 637
639static ssize_t lp8788_show_eoc_time(struct device *dev, 638static ssize_t lp8788_show_eoc_time(struct device *dev,
@@ -647,7 +646,7 @@ static ssize_t lp8788_show_eoc_time(struct device *dev,
647 lp8788_read_byte(pchg->lp, LP8788_CHG_EOC, &val); 646 lp8788_read_byte(pchg->lp, LP8788_CHG_EOC, &val);
648 val = (val & LP8788_CHG_EOC_TIME_M) >> LP8788_CHG_EOC_TIME_S; 647 val = (val & LP8788_CHG_EOC_TIME_M) >> LP8788_CHG_EOC_TIME_S;
649 648
650 return scnprintf(buf, LP8788_BUF_SIZE, "End Of Charge Time: %s\n", 649 return scnprintf(buf, PAGE_SIZE, "End Of Charge Time: %s\n",
651 stime[val]); 650 stime[val]);
652} 651}
653 652
@@ -667,8 +666,7 @@ static ssize_t lp8788_show_eoc_level(struct device *dev,
667 val = (val & LP8788_CHG_EOC_LEVEL_M) >> LP8788_CHG_EOC_LEVEL_S; 666 val = (val & LP8788_CHG_EOC_LEVEL_M) >> LP8788_CHG_EOC_LEVEL_S;
668 level = mode ? abs_level[val] : relative_level[val]; 667 level = mode ? abs_level[val] : relative_level[val];
669 668
670 return scnprintf(buf, LP8788_BUF_SIZE, "End Of Charge Level: %s\n", 669 return scnprintf(buf, PAGE_SIZE, "End Of Charge Level: %s\n", level);
671 level);
672} 670}
673 671
674static DEVICE_ATTR(charger_status, S_IRUSR, lp8788_show_charger_status, NULL); 672static DEVICE_ATTR(charger_status, S_IRUSR, lp8788_show_charger_status, NULL);
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index 74a0bd9bc162..c7ff6d67f158 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -246,31 +246,34 @@ static int max17040_remove(struct i2c_client *client)
246 return 0; 246 return 0;
247} 247}
248 248
249#ifdef CONFIG_PM 249#ifdef CONFIG_PM_SLEEP
250 250
251static int max17040_suspend(struct i2c_client *client, 251static int max17040_suspend(struct device *dev)
252 pm_message_t state)
253{ 252{
253 struct i2c_client *client = to_i2c_client(dev);
254 struct max17040_chip *chip = i2c_get_clientdata(client); 254 struct max17040_chip *chip = i2c_get_clientdata(client);
255 255
256 cancel_delayed_work(&chip->work); 256 cancel_delayed_work(&chip->work);
257 return 0; 257 return 0;
258} 258}
259 259
260static int max17040_resume(struct i2c_client *client) 260static int max17040_resume(struct device *dev)
261{ 261{
262 struct i2c_client *client = to_i2c_client(dev);
262 struct max17040_chip *chip = i2c_get_clientdata(client); 263 struct max17040_chip *chip = i2c_get_clientdata(client);
263 264
264 schedule_delayed_work(&chip->work, MAX17040_DELAY); 265 schedule_delayed_work(&chip->work, MAX17040_DELAY);
265 return 0; 266 return 0;
266} 267}
267 268
269static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume);
270#define MAX17040_PM_OPS (&max17040_pm_ops)
271
268#else 272#else
269 273
270#define max17040_suspend NULL 274#define MAX17040_PM_OPS NULL
271#define max17040_resume NULL
272 275
273#endif /* CONFIG_PM */ 276#endif /* CONFIG_PM_SLEEP */
274 277
275static const struct i2c_device_id max17040_id[] = { 278static const struct i2c_device_id max17040_id[] = {
276 { "max17040", 0 }, 279 { "max17040", 0 },
@@ -281,11 +284,10 @@ MODULE_DEVICE_TABLE(i2c, max17040_id);
281static struct i2c_driver max17040_i2c_driver = { 284static struct i2c_driver max17040_i2c_driver = {
282 .driver = { 285 .driver = {
283 .name = "max17040", 286 .name = "max17040",
287 .pm = MAX17040_PM_OPS,
284 }, 288 },
285 .probe = max17040_probe, 289 .probe = max17040_probe,
286 .remove = max17040_remove, 290 .remove = max17040_remove,
287 .suspend = max17040_suspend,
288 .resume = max17040_resume,
289 .id_table = max17040_id, 291 .id_table = max17040_id,
290}; 292};
291module_i2c_driver(max17040_i2c_driver); 293module_i2c_driver(max17040_i2c_driver);
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c
index 14e2b96d93b0..08f0d7909b6b 100644
--- a/drivers/power/max8903_charger.c
+++ b/drivers/power/max8903_charger.c
@@ -189,7 +189,7 @@ static int max8903_probe(struct platform_device *pdev)
189 int ta_in = 0; 189 int ta_in = 0;
190 int usb_in = 0; 190 int usb_in = 0;
191 191
192 data = kzalloc(sizeof(struct max8903_data), GFP_KERNEL); 192 data = devm_kzalloc(dev, sizeof(struct max8903_data), GFP_KERNEL);
193 if (data == NULL) { 193 if (data == NULL) {
194 dev_err(dev, "Cannot allocate memory.\n"); 194 dev_err(dev, "Cannot allocate memory.\n");
195 return -ENOMEM; 195 return -ENOMEM;
@@ -341,7 +341,6 @@ err_dc_irq:
341err_psy: 341err_psy:
342 power_supply_unregister(&data->psy); 342 power_supply_unregister(&data->psy);
343err: 343err:
344 kfree(data);
345 return ret; 344 return ret;
346} 345}
347 346
@@ -359,7 +358,6 @@ static int max8903_remove(struct platform_device *pdev)
359 if (pdata->dc_valid) 358 if (pdata->dc_valid)
360 free_irq(gpio_to_irq(pdata->dok), data); 359 free_irq(gpio_to_irq(pdata->dok), data);
361 power_supply_unregister(&data->psy); 360 power_supply_unregister(&data->psy);
362 kfree(data);
363 } 361 }
364 362
365 return 0; 363 return 0;
diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c
index 665cdc76c265..0ee1e14f76e9 100644
--- a/drivers/power/max8925_power.c
+++ b/drivers/power/max8925_power.c
@@ -489,7 +489,8 @@ static int max8925_power_probe(struct platform_device *pdev)
489 return -EINVAL; 489 return -EINVAL;
490 } 490 }
491 491
492 info = kzalloc(sizeof(struct max8925_power_info), GFP_KERNEL); 492 info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_power_info),
493 GFP_KERNEL);
493 if (!info) 494 if (!info)
494 return -ENOMEM; 495 return -ENOMEM;
495 info->chip = chip; 496 info->chip = chip;
@@ -546,7 +547,6 @@ out_battery:
546out_usb: 547out_usb:
547 power_supply_unregister(&info->ac); 548 power_supply_unregister(&info->ac);
548out: 549out:
549 kfree(info);
550 return ret; 550 return ret;
551} 551}
552 552
@@ -559,7 +559,6 @@ static int max8925_power_remove(struct platform_device *pdev)
559 power_supply_unregister(&info->usb); 559 power_supply_unregister(&info->usb);
560 power_supply_unregister(&info->battery); 560 power_supply_unregister(&info->battery);
561 max8925_deinit_charger(info); 561 max8925_deinit_charger(info);
562 kfree(info);
563 } 562 }
564 return 0; 563 return 0;
565} 564}
diff --git a/drivers/power/max8997_charger.c b/drivers/power/max8997_charger.c
index e757885b620c..4bdedfed936d 100644
--- a/drivers/power/max8997_charger.c
+++ b/drivers/power/max8997_charger.c
@@ -138,7 +138,8 @@ static int max8997_battery_probe(struct platform_device *pdev)
138 return ret; 138 return ret;
139 } 139 }
140 140
141 charger = kzalloc(sizeof(struct charger_data), GFP_KERNEL); 141 charger = devm_kzalloc(&pdev->dev, sizeof(struct charger_data),
142 GFP_KERNEL);
142 if (charger == NULL) { 143 if (charger == NULL) {
143 dev_err(&pdev->dev, "Cannot allocate memory.\n"); 144 dev_err(&pdev->dev, "Cannot allocate memory.\n");
144 return -ENOMEM; 145 return -ENOMEM;
@@ -158,13 +159,10 @@ static int max8997_battery_probe(struct platform_device *pdev)
158 ret = power_supply_register(&pdev->dev, &charger->battery); 159 ret = power_supply_register(&pdev->dev, &charger->battery);
159 if (ret) { 160 if (ret) {
160 dev_err(&pdev->dev, "failed: power supply register\n"); 161 dev_err(&pdev->dev, "failed: power supply register\n");
161 goto err; 162 return ret;
162 } 163 }
163 164
164 return 0; 165 return 0;
165err:
166 kfree(charger);
167 return ret;
168} 166}
169 167
170static int max8997_battery_remove(struct platform_device *pdev) 168static int max8997_battery_remove(struct platform_device *pdev)
@@ -172,7 +170,6 @@ static int max8997_battery_remove(struct platform_device *pdev)
172 struct charger_data *charger = platform_get_drvdata(pdev); 170 struct charger_data *charger = platform_get_drvdata(pdev);
173 171
174 power_supply_unregister(&charger->battery); 172 power_supply_unregister(&charger->battery);
175 kfree(charger);
176 return 0; 173 return 0;
177} 174}
178 175
diff --git a/drivers/power/max8998_charger.c b/drivers/power/max8998_charger.c
index bf677e3daec9..5017470c2fc9 100644
--- a/drivers/power/max8998_charger.c
+++ b/drivers/power/max8998_charger.c
@@ -88,7 +88,8 @@ static int max8998_battery_probe(struct platform_device *pdev)
88 return -ENODEV; 88 return -ENODEV;
89 } 89 }
90 90
91 max8998 = kzalloc(sizeof(struct max8998_battery_data), GFP_KERNEL); 91 max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_battery_data),
92 GFP_KERNEL);
92 if (!max8998) 93 if (!max8998)
93 return -ENOMEM; 94 return -ENOMEM;
94 95
@@ -174,7 +175,6 @@ static int max8998_battery_probe(struct platform_device *pdev)
174 175
175 return 0; 176 return 0;
176err: 177err:
177 kfree(max8998);
178 return ret; 178 return ret;
179} 179}
180 180
@@ -183,7 +183,6 @@ static int max8998_battery_remove(struct platform_device *pdev)
183 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev); 183 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev);
184 184
185 power_supply_unregister(&max8998->battery); 185 power_supply_unregister(&max8998->battery);
186 kfree(max8998);
187 186
188 return 0; 187 return 0;
189} 188}
diff --git a/drivers/power/pcf50633-charger.c b/drivers/power/pcf50633-charger.c
index c2122a7ad065..17fd77f24b2a 100644
--- a/drivers/power/pcf50633-charger.c
+++ b/drivers/power/pcf50633-charger.c
@@ -373,7 +373,7 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
373 int i; 373 int i;
374 u8 mbcs1; 374 u8 mbcs1;
375 375
376 mbc = kzalloc(sizeof(*mbc), GFP_KERNEL); 376 mbc = devm_kzalloc(&pdev->dev, sizeof(*mbc), GFP_KERNEL);
377 if (!mbc) 377 if (!mbc)
378 return -ENOMEM; 378 return -ENOMEM;
379 379
@@ -413,7 +413,6 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
413 ret = power_supply_register(&pdev->dev, &mbc->adapter); 413 ret = power_supply_register(&pdev->dev, &mbc->adapter);
414 if (ret) { 414 if (ret) {
415 dev_err(mbc->pcf->dev, "failed to register adapter\n"); 415 dev_err(mbc->pcf->dev, "failed to register adapter\n");
416 kfree(mbc);
417 return ret; 416 return ret;
418 } 417 }
419 418
@@ -421,7 +420,6 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
421 if (ret) { 420 if (ret) {
422 dev_err(mbc->pcf->dev, "failed to register usb\n"); 421 dev_err(mbc->pcf->dev, "failed to register usb\n");
423 power_supply_unregister(&mbc->adapter); 422 power_supply_unregister(&mbc->adapter);
424 kfree(mbc);
425 return ret; 423 return ret;
426 } 424 }
427 425
@@ -430,7 +428,6 @@ static int pcf50633_mbc_probe(struct platform_device *pdev)
430 dev_err(mbc->pcf->dev, "failed to register ac\n"); 428 dev_err(mbc->pcf->dev, "failed to register ac\n");
431 power_supply_unregister(&mbc->adapter); 429 power_supply_unregister(&mbc->adapter);
432 power_supply_unregister(&mbc->usb); 430 power_supply_unregister(&mbc->usb);
433 kfree(mbc);
434 return ret; 431 return ret;
435 } 432 }
436 433
@@ -461,8 +458,6 @@ static int pcf50633_mbc_remove(struct platform_device *pdev)
461 power_supply_unregister(&mbc->adapter); 458 power_supply_unregister(&mbc->adapter);
462 power_supply_unregister(&mbc->ac); 459 power_supply_unregister(&mbc->ac);
463 460
464 kfree(mbc);
465
466 return 0; 461 return 0;
467} 462}
468 463
diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c
index ee346d443571..a44175139bbf 100644
--- a/drivers/power/pm2301_charger.c
+++ b/drivers/power/pm2301_charger.c
@@ -16,24 +16,25 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/power_supply.h> 18#include <linux/power_supply.h>
19#include <linux/completion.h>
20#include <linux/regulator/consumer.h> 19#include <linux/regulator/consumer.h>
21#include <linux/err.h> 20#include <linux/err.h>
22#include <linux/i2c.h> 21#include <linux/i2c.h>
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24#include <linux/kobject.h>
25#include <linux/mfd/abx500.h>
26#include <linux/mfd/abx500/ab8500.h> 23#include <linux/mfd/abx500/ab8500.h>
27#include <linux/mfd/abx500/ab8500-bm.h> 24#include <linux/mfd/abx500/ab8500-bm.h>
28#include <linux/mfd/abx500/ab8500-gpadc.h>
29#include <linux/mfd/abx500/ux500_chargalg.h> 25#include <linux/mfd/abx500/ux500_chargalg.h>
30#include <linux/pm2301_charger.h> 26#include <linux/pm2301_charger.h>
31#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/pm_runtime.h>
29#include <linux/pm.h>
32 30
33#include "pm2301_charger.h" 31#include "pm2301_charger.h"
34 32
35#define to_pm2xxx_charger_ac_device_info(x) container_of((x), \ 33#define to_pm2xxx_charger_ac_device_info(x) container_of((x), \
36 struct pm2xxx_charger, ac_chg) 34 struct pm2xxx_charger, ac_chg)
35#define SLEEP_MIN 50
36#define SLEEP_MAX 100
37#define PM2XXX_AUTOSUSPEND_DELAY 500
37 38
38static int pm2xxx_interrupt_registers[] = { 39static int pm2xxx_interrupt_registers[] = {
39 PM2XXX_REG_INT1, 40 PM2XXX_REG_INT1,
@@ -113,33 +114,24 @@ static const struct i2c_device_id pm2xxx_ident[] = {
113 114
114static void set_lpn_pin(struct pm2xxx_charger *pm2) 115static void set_lpn_pin(struct pm2xxx_charger *pm2)
115{ 116{
116 if (pm2->ac.charger_connected) 117 if (!pm2->ac.charger_connected && gpio_is_valid(pm2->lpn_pin)) {
117 return; 118 gpio_set_value(pm2->lpn_pin, 1);
118 gpio_set_value(pm2->lpn_pin, 1); 119 usleep_range(SLEEP_MIN, SLEEP_MAX);
119 120 }
120 return;
121} 121}
122 122
123static void clear_lpn_pin(struct pm2xxx_charger *pm2) 123static void clear_lpn_pin(struct pm2xxx_charger *pm2)
124{ 124{
125 if (pm2->ac.charger_connected) 125 if (!pm2->ac.charger_connected && gpio_is_valid(pm2->lpn_pin))
126 return; 126 gpio_set_value(pm2->lpn_pin, 0);
127 gpio_set_value(pm2->lpn_pin, 0);
128
129 return;
130} 127}
131 128
132static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val) 129static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val)
133{ 130{
134 int ret; 131 int ret;
135 /* 132
136 * When AC adaptor is unplugged, the host 133 /* wake up the device */
137 * must put LPN high to be able to 134 pm_runtime_get_sync(pm2->dev);
138 * communicate by I2C with PM2301
139 * and receive I2C "acknowledge" from PM2301.
140 */
141 mutex_lock(&pm2->lock);
142 set_lpn_pin(pm2);
143 135
144 ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg, 136 ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg,
145 1, val); 137 1, val);
@@ -147,8 +139,8 @@ static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val)
147 dev_err(pm2->dev, "Error reading register at 0x%x\n", reg); 139 dev_err(pm2->dev, "Error reading register at 0x%x\n", reg);
148 else 140 else
149 ret = 0; 141 ret = 0;
150 clear_lpn_pin(pm2); 142
151 mutex_unlock(&pm2->lock); 143 pm_runtime_put_sync(pm2->dev);
152 144
153 return ret; 145 return ret;
154} 146}
@@ -156,14 +148,9 @@ static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val)
156static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val) 148static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val)
157{ 149{
158 int ret; 150 int ret;
159 /* 151
160 * When AC adaptor is unplugged, the host 152 /* wake up the device */
161 * must put LPN high to be able to 153 pm_runtime_get_sync(pm2->dev);
162 * communicate by I2C with PM2301
163 * and receive I2C "acknowledge" from PM2301.
164 */
165 mutex_lock(&pm2->lock);
166 set_lpn_pin(pm2);
167 154
168 ret = i2c_smbus_write_i2c_block_data(pm2->config.pm2xxx_i2c, reg, 155 ret = i2c_smbus_write_i2c_block_data(pm2->config.pm2xxx_i2c, reg,
169 1, &val); 156 1, &val);
@@ -171,8 +158,8 @@ static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val)
171 dev_err(pm2->dev, "Error writing register at 0x%x\n", reg); 158 dev_err(pm2->dev, "Error writing register at 0x%x\n", reg);
172 else 159 else
173 ret = 0; 160 ret = 0;
174 clear_lpn_pin(pm2); 161
175 mutex_unlock(&pm2->lock); 162 pm_runtime_put_sync(pm2->dev);
176 163
177 return ret; 164 return ret;
178} 165}
@@ -192,11 +179,22 @@ static int pm2xxx_charging_disable_mngt(struct pm2xxx_charger *pm2)
192{ 179{
193 int ret; 180 int ret;
194 181
182 /* Disable SW EOC ctrl */
183 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG, PM2XXX_SWCTRL_HW);
184 if (ret < 0) {
185 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__);
186 return ret;
187 }
188
195 /* Disable charging */ 189 /* Disable charging */
196 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG2, 190 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_CTRL_REG2,
197 (PM2XXX_CH_AUTO_RESUME_DIS | PM2XXX_CHARGER_DIS)); 191 (PM2XXX_CH_AUTO_RESUME_DIS | PM2XXX_CHARGER_DIS));
192 if (ret < 0) {
193 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__);
194 return ret;
195 }
198 196
199 return ret; 197 return 0;
200} 198}
201 199
202static int pm2xxx_charger_batt_therm_mngt(struct pm2xxx_charger *pm2, int val) 200static int pm2xxx_charger_batt_therm_mngt(struct pm2xxx_charger *pm2, int val)
@@ -216,21 +214,14 @@ int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val)
216 214
217static int pm2xxx_charger_ovv_mngt(struct pm2xxx_charger *pm2, int val) 215static int pm2xxx_charger_ovv_mngt(struct pm2xxx_charger *pm2, int val)
218{ 216{
219 int ret = 0; 217 dev_err(pm2->dev, "Overvoltage detected\n");
218 pm2->flags.ovv = true;
219 power_supply_changed(&pm2->ac_chg.psy);
220 220
221 pm2->failure_input_ovv++; 221 /* Schedule a new HW failure check */
222 if (pm2->failure_input_ovv < 4) { 222 queue_delayed_work(pm2->charger_wq, &pm2->check_hw_failure_work, 0);
223 ret = pm2xxx_charging_enable_mngt(pm2);
224 goto out;
225 } else {
226 pm2->failure_input_ovv = 0;
227 dev_err(pm2->dev, "Overvoltage detected\n");
228 pm2->flags.ovv = true;
229 power_supply_changed(&pm2->ac_chg.psy);
230 }
231 223
232out: 224 return 0;
233 return ret;
234} 225}
235 226
236static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val) 227static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val)
@@ -245,13 +236,29 @@ static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val)
245 236
246static int pm2xxx_charger_vbat_lsig_mngt(struct pm2xxx_charger *pm2, int val) 237static int pm2xxx_charger_vbat_lsig_mngt(struct pm2xxx_charger *pm2, int val)
247{ 238{
239 int ret;
240
248 switch (val) { 241 switch (val) {
249 case PM2XXX_INT1_ITVBATLOWR: 242 case PM2XXX_INT1_ITVBATLOWR:
250 dev_dbg(pm2->dev, "VBAT grows above VBAT_LOW level\n"); 243 dev_dbg(pm2->dev, "VBAT grows above VBAT_LOW level\n");
244 /* Enable SW EOC ctrl */
245 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG,
246 PM2XXX_SWCTRL_SW);
247 if (ret < 0) {
248 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__);
249 return ret;
250 }
251 break; 251 break;
252 252
253 case PM2XXX_INT1_ITVBATLOWF: 253 case PM2XXX_INT1_ITVBATLOWF:
254 dev_dbg(pm2->dev, "VBAT drops below VBAT_LOW level\n"); 254 dev_dbg(pm2->dev, "VBAT drops below VBAT_LOW level\n");
255 /* Disable SW EOC ctrl */
256 ret = pm2xxx_reg_write(pm2, PM2XXX_SW_CTRL_REG,
257 PM2XXX_SWCTRL_HW);
258 if (ret < 0) {
259 dev_err(pm2->dev, "%s pm2xxx write failed\n", __func__);
260 return ret;
261 }
255 break; 262 break;
256 263
257 default: 264 default:
@@ -322,16 +329,27 @@ static int pm2_int_reg0(void *pm2_data, int val)
322 struct pm2xxx_charger *pm2 = pm2_data; 329 struct pm2xxx_charger *pm2 = pm2_data;
323 int ret = 0; 330 int ret = 0;
324 331
325 if (val & (PM2XXX_INT1_ITVBATLOWR | PM2XXX_INT1_ITVBATLOWF)) { 332 if (val & PM2XXX_INT1_ITVBATLOWR) {
326 ret = pm2xxx_charger_vbat_lsig_mngt(pm2, val & 333 ret = pm2xxx_charger_vbat_lsig_mngt(pm2,
327 (PM2XXX_INT1_ITVBATLOWR | PM2XXX_INT1_ITVBATLOWF)); 334 PM2XXX_INT1_ITVBATLOWR);
335 if (ret < 0)
336 goto out;
337 }
338
339 if (val & PM2XXX_INT1_ITVBATLOWF) {
340 ret = pm2xxx_charger_vbat_lsig_mngt(pm2,
341 PM2XXX_INT1_ITVBATLOWF);
342 if (ret < 0)
343 goto out;
328 } 344 }
329 345
330 if (val & PM2XXX_INT1_ITVBATDISCONNECT) { 346 if (val & PM2XXX_INT1_ITVBATDISCONNECT) {
331 ret = pm2xxx_charger_bat_disc_mngt(pm2, 347 ret = pm2xxx_charger_bat_disc_mngt(pm2,
332 PM2XXX_INT1_ITVBATDISCONNECT); 348 PM2XXX_INT1_ITVBATDISCONNECT);
349 if (ret < 0)
350 goto out;
333 } 351 }
334 352out:
335 return ret; 353 return ret;
336} 354}
337 355
@@ -447,7 +465,6 @@ static int pm2_int_reg5(void *pm2_data, int val)
447 struct pm2xxx_charger *pm2 = pm2_data; 465 struct pm2xxx_charger *pm2 = pm2_data;
448 int ret = 0; 466 int ret = 0;
449 467
450
451 if (val & (PM2XXX_INT6_ITVPWR2DROP | PM2XXX_INT6_ITVPWR1DROP)) { 468 if (val & (PM2XXX_INT6_ITVPWR2DROP | PM2XXX_INT6_ITVPWR1DROP)) {
452 dev_dbg(pm2->dev, "VMPWR drop to VBAT level\n"); 469 dev_dbg(pm2->dev, "VMPWR drop to VBAT level\n");
453 } 470 }
@@ -468,14 +485,22 @@ static irqreturn_t pm2xxx_irq_int(int irq, void *data)
468 struct pm2xxx_interrupts *interrupt = pm2->pm2_int; 485 struct pm2xxx_interrupts *interrupt = pm2->pm2_int;
469 int i; 486 int i;
470 487
471 for (i = 0; i < PM2XXX_NUM_INT_REG; i++) { 488 /* wake up the device */
472 pm2xxx_reg_read(pm2, 489 pm_runtime_get_sync(pm2->dev);
490
491 do {
492 for (i = 0; i < PM2XXX_NUM_INT_REG; i++) {
493 pm2xxx_reg_read(pm2,
473 pm2xxx_interrupt_registers[i], 494 pm2xxx_interrupt_registers[i],
474 &(interrupt->reg[i])); 495 &(interrupt->reg[i]));
475 496
476 if (interrupt->reg[i] > 0) 497 if (interrupt->reg[i] > 0)
477 interrupt->handler[i](pm2, interrupt->reg[i]); 498 interrupt->handler[i](pm2, interrupt->reg[i]);
478 } 499 }
500 } while (gpio_get_value(pm2->pdata->gpio_irq_number) == 0);
501
502 pm_runtime_mark_last_busy(pm2->dev);
503 pm_runtime_put_autosuspend(pm2->dev);
479 504
480 return IRQ_HANDLED; 505 return IRQ_HANDLED;
481} 506}
@@ -592,6 +617,8 @@ static int pm2xxx_charger_ac_get_property(struct power_supply *psy,
592 val->intval = POWER_SUPPLY_HEALTH_DEAD; 617 val->intval = POWER_SUPPLY_HEALTH_DEAD;
593 else if (pm2->flags.main_thermal_prot) 618 else if (pm2->flags.main_thermal_prot)
594 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; 619 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
620 else if (pm2->flags.ovv)
621 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
595 else 622 else
596 val->intval = POWER_SUPPLY_HEALTH_GOOD; 623 val->intval = POWER_SUPPLY_HEALTH_GOOD;
597 break; 624 break;
@@ -674,10 +701,6 @@ static int pm2xxx_charging_init(struct pm2xxx_charger *pm2)
674 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_LOW_LEV_COMP_REG, 701 ret = pm2xxx_reg_write(pm2, PM2XXX_BATT_LOW_LEV_COMP_REG,
675 PM2XXX_VBAT_LOW_MONITORING_ENA); 702 PM2XXX_VBAT_LOW_MONITORING_ENA);
676 703
677 /* Disable LED */
678 ret = pm2xxx_reg_write(pm2, PM2XXX_LED_CTRL_REG,
679 PM2XXX_LED_SELECT_DIS);
680
681 return ret; 704 return ret;
682} 705}
683 706
@@ -822,10 +845,54 @@ static void pm2xxx_charger_ac_work(struct work_struct *work)
822 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present"); 845 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present");
823}; 846};
824 847
848static void pm2xxx_charger_check_hw_failure_work(struct work_struct *work)
849{
850 u8 reg_value;
851
852 struct pm2xxx_charger *pm2 = container_of(work,
853 struct pm2xxx_charger, check_hw_failure_work.work);
854
855 if (pm2->flags.ovv) {
856 pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT4, &reg_value);
857
858 if (!(reg_value & (PM2XXX_INT4_S_ITVPWR1OVV |
859 PM2XXX_INT4_S_ITVPWR2OVV))) {
860 pm2->flags.ovv = false;
861 power_supply_changed(&pm2->ac_chg.psy);
862 }
863 }
864
865 /* If we still have a failure, schedule a new check */
866 if (pm2->flags.ovv) {
867 queue_delayed_work(pm2->charger_wq,
868 &pm2->check_hw_failure_work, round_jiffies(HZ));
869 }
870}
871
825static void pm2xxx_charger_check_main_thermal_prot_work( 872static void pm2xxx_charger_check_main_thermal_prot_work(
826 struct work_struct *work) 873 struct work_struct *work)
827{ 874{
828}; 875 int ret;
876 u8 val;
877
878 struct pm2xxx_charger *pm2 = container_of(work, struct pm2xxx_charger,
879 check_main_thermal_prot_work);
880
881 /* Check if die temp warning is still active */
882 ret = pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT5, &val);
883 if (ret < 0) {
884 dev_err(pm2->dev, "%s pm2xxx read failed\n", __func__);
885 return;
886 }
887 if (val & (PM2XXX_INT5_S_ITTHERMALWARNINGRISE
888 | PM2XXX_INT5_S_ITTHERMALSHUTDOWNRISE))
889 pm2->flags.main_thermal_prot = true;
890 else if (val & (PM2XXX_INT5_S_ITTHERMALWARNINGFALL
891 | PM2XXX_INT5_S_ITTHERMALSHUTDOWNFALL))
892 pm2->flags.main_thermal_prot = false;
893
894 power_supply_changed(&pm2->ac_chg.psy);
895}
829 896
830static struct pm2xxx_interrupts pm2xxx_int = { 897static struct pm2xxx_interrupts pm2xxx_int = {
831 .handler[0] = pm2_int_reg0, 898 .handler[0] = pm2_int_reg0,
@@ -840,24 +907,105 @@ static struct pm2xxx_irq pm2xxx_charger_irq[] = {
840 {"PM2XXX_IRQ_INT", pm2xxx_irq_int}, 907 {"PM2XXX_IRQ_INT", pm2xxx_irq_int},
841}; 908};
842 909
843static int pm2xxx_wall_charger_resume(struct i2c_client *i2c_client) 910#ifdef CONFIG_PM
911
912#ifdef CONFIG_PM_SLEEP
913
914static int pm2xxx_wall_charger_resume(struct device *dev)
844{ 915{
916 struct i2c_client *i2c_client = to_i2c_client(dev);
917 struct pm2xxx_charger *pm2;
918
919 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client);
920 set_lpn_pin(pm2);
921
922 /* If we still have a HW failure, schedule a new check */
923 if (pm2->flags.ovv)
924 queue_delayed_work(pm2->charger_wq,
925 &pm2->check_hw_failure_work, 0);
926
845 return 0; 927 return 0;
846} 928}
847 929
848static int pm2xxx_wall_charger_suspend(struct i2c_client *i2c_client, 930static int pm2xxx_wall_charger_suspend(struct device *dev)
849 pm_message_t state)
850{ 931{
932 struct i2c_client *i2c_client = to_i2c_client(dev);
933 struct pm2xxx_charger *pm2;
934
935 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client);
936 clear_lpn_pin(pm2);
937
938 /* Cancel any pending HW failure check */
939 if (delayed_work_pending(&pm2->check_hw_failure_work))
940 cancel_delayed_work(&pm2->check_hw_failure_work);
941
942 flush_work(&pm2->ac_work);
943 flush_work(&pm2->check_main_thermal_prot_work);
944
851 return 0; 945 return 0;
852} 946}
853 947
854static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, 948#endif
949
950#ifdef CONFIG_PM_RUNTIME
951
952static int pm2xxx_runtime_suspend(struct device *dev)
953{
954 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
955 struct pm2xxx_charger *pm2;
956 int ret = 0;
957
958 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
959 if (!pm2) {
960 dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
961 ret = -EINVAL;
962 return ret;
963 }
964
965 clear_lpn_pin(pm2);
966
967 return ret;
968}
969
970static int pm2xxx_runtime_resume(struct device *dev)
971{
972 struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
973 struct pm2xxx_charger *pm2;
974 int ret = 0;
975
976 pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
977 if (!pm2) {
978 dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
979 ret = -EINVAL;
980 return ret;
981 }
982
983 if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0)
984 set_lpn_pin(pm2);
985
986 return ret;
987}
988
989#endif
990
991static const struct dev_pm_ops pm2xxx_pm_ops = {
992 SET_SYSTEM_SLEEP_PM_OPS(pm2xxx_wall_charger_suspend,
993 pm2xxx_wall_charger_resume)
994 SET_RUNTIME_PM_OPS(pm2xxx_runtime_suspend, pm2xxx_runtime_resume, NULL)
995};
996#define PM2XXX_PM_OPS (&pm2xxx_pm_ops)
997#else
998#define PM2XXX_PM_OPS NULL
999#endif
1000
1001static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
855 const struct i2c_device_id *id) 1002 const struct i2c_device_id *id)
856{ 1003{
857 struct pm2xxx_platform_data *pl_data = i2c_client->dev.platform_data; 1004 struct pm2xxx_platform_data *pl_data = i2c_client->dev.platform_data;
858 struct pm2xxx_charger *pm2; 1005 struct pm2xxx_charger *pm2;
859 int ret = 0; 1006 int ret = 0;
860 u8 val; 1007 u8 val;
1008 int i;
861 1009
862 pm2 = kzalloc(sizeof(struct pm2xxx_charger), GFP_KERNEL); 1010 pm2 = kzalloc(sizeof(struct pm2xxx_charger), GFP_KERNEL);
863 if (!pm2) { 1011 if (!pm2) {
@@ -867,7 +1015,6 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
867 1015
868 /* get parent data */ 1016 /* get parent data */
869 pm2->dev = &i2c_client->dev; 1017 pm2->dev = &i2c_client->dev;
870 pm2->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
871 1018
872 pm2->pm2_int = &pm2xxx_int; 1019 pm2->pm2_int = &pm2xxx_int;
873 1020
@@ -889,14 +1036,6 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
889 1036
890 pm2->bat = pl_data->battery; 1037 pm2->bat = pl_data->battery;
891 1038
892 /*get lpn GPIO from platform data*/
893 if (!pm2->pdata->lpn_gpio) {
894 dev_err(pm2->dev, "no lpn gpio data supplied\n");
895 ret = -EINVAL;
896 goto free_device_info;
897 }
898 pm2->lpn_pin = pm2->pdata->lpn_gpio;
899
900 if (!i2c_check_functionality(i2c_client->adapter, 1039 if (!i2c_check_functionality(i2c_client->adapter,
901 I2C_FUNC_SMBUS_BYTE_DATA | 1040 I2C_FUNC_SMBUS_BYTE_DATA |
902 I2C_FUNC_SMBUS_READ_WORD_DATA)) { 1041 I2C_FUNC_SMBUS_READ_WORD_DATA)) {
@@ -945,6 +1084,10 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
945 INIT_WORK(&pm2->check_main_thermal_prot_work, 1084 INIT_WORK(&pm2->check_main_thermal_prot_work,
946 pm2xxx_charger_check_main_thermal_prot_work); 1085 pm2xxx_charger_check_main_thermal_prot_work);
947 1086
1087 /* Init work for HW failure check */
1088 INIT_DEFERRABLE_WORK(&pm2->check_hw_failure_work,
1089 pm2xxx_charger_check_hw_failure_work);
1090
948 /* 1091 /*
949 * VDD ADC supply needs to be enabled from this driver when there 1092 * VDD ADC supply needs to be enabled from this driver when there
950 * is a charger connected to avoid erroneous BTEMP_HIGH/LOW 1093 * is a charger connected to avoid erroneous BTEMP_HIGH/LOW
@@ -965,40 +1108,72 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
965 } 1108 }
966 1109
967 /* Register interrupts */ 1110 /* Register interrupts */
968 ret = request_threaded_irq(pm2->pdata->irq_number, NULL, 1111 ret = request_threaded_irq(gpio_to_irq(pm2->pdata->gpio_irq_number),
1112 NULL,
969 pm2xxx_charger_irq[0].isr, 1113 pm2xxx_charger_irq[0].isr,
970 pm2->pdata->irq_type, 1114 pm2->pdata->irq_type,
971 pm2xxx_charger_irq[0].name, pm2); 1115 pm2xxx_charger_irq[0].name, pm2);
972 1116
973 if (ret != 0) { 1117 if (ret != 0) {
974 dev_err(pm2->dev, "failed to request %s IRQ %d: %d\n", 1118 dev_err(pm2->dev, "failed to request %s IRQ %d: %d\n",
975 pm2xxx_charger_irq[0].name, pm2->pdata->irq_number, ret); 1119 pm2xxx_charger_irq[0].name,
1120 gpio_to_irq(pm2->pdata->gpio_irq_number), ret);
976 goto unregister_pm2xxx_charger; 1121 goto unregister_pm2xxx_charger;
977 } 1122 }
978 1123
979 /*Initialize lock*/ 1124 ret = pm_runtime_set_active(pm2->dev);
980 mutex_init(&pm2->lock); 1125 if (ret)
1126 dev_err(pm2->dev, "set active Error\n");
981 1127
982 /* 1128 pm_runtime_enable(pm2->dev);
983 * Charger detection mechanism requires pulling up the LPN pin 1129 pm_runtime_set_autosuspend_delay(pm2->dev, PM2XXX_AUTOSUSPEND_DELAY);
984 * while i2c communication if Charger is not connected 1130 pm_runtime_use_autosuspend(pm2->dev);
985 * LPN pin of PM2301 is GPIO60 of AB9540 1131 pm_runtime_resume(pm2->dev);
986 */ 1132
987 ret = gpio_request(pm2->lpn_pin, "pm2301_lpm_gpio"); 1133 /* pm interrupt can wake up system */
988 if (ret < 0) { 1134 ret = enable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number));
989 dev_err(pm2->dev, "pm2301_lpm_gpio request failed\n"); 1135 if (ret) {
990 goto unregister_pm2xxx_charger; 1136 dev_err(pm2->dev, "failed to set irq wake\n");
1137 goto unregister_pm2xxx_interrupt;
991 } 1138 }
992 ret = gpio_direction_output(pm2->lpn_pin, 0); 1139
993 if (ret < 0) { 1140 mutex_init(&pm2->lock);
994 dev_err(pm2->dev, "pm2301_lpm_gpio direction failed\n"); 1141
995 goto free_gpio; 1142 if (gpio_is_valid(pm2->pdata->lpn_gpio)) {
1143 /* get lpn GPIO from platform data */
1144 pm2->lpn_pin = pm2->pdata->lpn_gpio;
1145
1146 /*
1147 * Charger detection mechanism requires pulling up the LPN pin
1148 * while i2c communication if Charger is not connected
1149 * LPN pin of PM2301 is GPIO60 of AB9540
1150 */
1151 ret = gpio_request(pm2->lpn_pin, "pm2301_lpm_gpio");
1152
1153 if (ret < 0) {
1154 dev_err(pm2->dev, "pm2301_lpm_gpio request failed\n");
1155 goto disable_pm2_irq_wake;
1156 }
1157 ret = gpio_direction_output(pm2->lpn_pin, 0);
1158 if (ret < 0) {
1159 dev_err(pm2->dev, "pm2301_lpm_gpio direction failed\n");
1160 goto free_gpio;
1161 }
1162 set_lpn_pin(pm2);
996 } 1163 }
997 1164
1165 /* read interrupt registers */
1166 for (i = 0; i < PM2XXX_NUM_INT_REG; i++)
1167 pm2xxx_reg_read(pm2,
1168 pm2xxx_interrupt_registers[i],
1169 &val);
1170
998 ret = pm2xxx_charger_detection(pm2, &val); 1171 ret = pm2xxx_charger_detection(pm2, &val);
999 1172
1000 if ((ret == 0) && val) { 1173 if ((ret == 0) && val) {
1001 pm2->ac.charger_connected = 1; 1174 pm2->ac.charger_connected = 1;
1175 ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
1176 AB8500_MAIN_CH_DET);
1002 pm2->ac_conn = true; 1177 pm2->ac_conn = true;
1003 power_supply_changed(&pm2->ac_chg.psy); 1178 power_supply_changed(&pm2->ac_chg.psy);
1004 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present"); 1179 sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present");
@@ -1007,7 +1182,13 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
1007 return 0; 1182 return 0;
1008 1183
1009free_gpio: 1184free_gpio:
1010 gpio_free(pm2->lpn_pin); 1185 if (gpio_is_valid(pm2->lpn_pin))
1186 gpio_free(pm2->lpn_pin);
1187disable_pm2_irq_wake:
1188 disable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number));
1189unregister_pm2xxx_interrupt:
1190 /* disable interrupt */
1191 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2);
1011unregister_pm2xxx_charger: 1192unregister_pm2xxx_charger:
1012 /* unregister power supply */ 1193 /* unregister power supply */
1013 power_supply_unregister(&pm2->ac_chg.psy); 1194 power_supply_unregister(&pm2->ac_chg.psy);
@@ -1018,18 +1199,24 @@ free_charger_wq:
1018 destroy_workqueue(pm2->charger_wq); 1199 destroy_workqueue(pm2->charger_wq);
1019free_device_info: 1200free_device_info:
1020 kfree(pm2); 1201 kfree(pm2);
1202
1021 return ret; 1203 return ret;
1022} 1204}
1023 1205
1024static int __devexit pm2xxx_wall_charger_remove(struct i2c_client *i2c_client) 1206static int pm2xxx_wall_charger_remove(struct i2c_client *i2c_client)
1025{ 1207{
1026 struct pm2xxx_charger *pm2 = i2c_get_clientdata(i2c_client); 1208 struct pm2xxx_charger *pm2 = i2c_get_clientdata(i2c_client);
1027 1209
1210 /* Disable pm_runtime */
1211 pm_runtime_disable(pm2->dev);
1028 /* Disable AC charging */ 1212 /* Disable AC charging */
1029 pm2xxx_charger_ac_en(&pm2->ac_chg, false, 0, 0); 1213 pm2xxx_charger_ac_en(&pm2->ac_chg, false, 0, 0);
1030 1214
1215 /* Disable wake by pm interrupt */
1216 disable_irq_wake(gpio_to_irq(pm2->pdata->gpio_irq_number));
1217
1031 /* Disable interrupts */ 1218 /* Disable interrupts */
1032 free_irq(pm2->pdata->irq_number, pm2); 1219 free_irq(gpio_to_irq(pm2->pdata->gpio_irq_number), pm2);
1033 1220
1034 /* Delete the work queue */ 1221 /* Delete the work queue */
1035 destroy_workqueue(pm2->charger_wq); 1222 destroy_workqueue(pm2->charger_wq);
@@ -1041,8 +1228,8 @@ static int __devexit pm2xxx_wall_charger_remove(struct i2c_client *i2c_client)
1041 1228
1042 power_supply_unregister(&pm2->ac_chg.psy); 1229 power_supply_unregister(&pm2->ac_chg.psy);
1043 1230
1044 /*Free GPIO60*/ 1231 if (gpio_is_valid(pm2->lpn_pin))
1045 gpio_free(pm2->lpn_pin); 1232 gpio_free(pm2->lpn_pin);
1046 1233
1047 kfree(pm2); 1234 kfree(pm2);
1048 1235
@@ -1058,12 +1245,11 @@ MODULE_DEVICE_TABLE(i2c, pm2xxx_id);
1058 1245
1059static struct i2c_driver pm2xxx_charger_driver = { 1246static struct i2c_driver pm2xxx_charger_driver = {
1060 .probe = pm2xxx_wall_charger_probe, 1247 .probe = pm2xxx_wall_charger_probe,
1061 .remove = __devexit_p(pm2xxx_wall_charger_remove), 1248 .remove = pm2xxx_wall_charger_remove,
1062 .suspend = pm2xxx_wall_charger_suspend,
1063 .resume = pm2xxx_wall_charger_resume,
1064 .driver = { 1249 .driver = {
1065 .name = "pm2xxx-wall_charger", 1250 .name = "pm2xxx-wall_charger",
1066 .owner = THIS_MODULE, 1251 .owner = THIS_MODULE,
1252 .pm = PM2XXX_PM_OPS,
1067 }, 1253 },
1068 .id_table = pm2xxx_id, 1254 .id_table = pm2xxx_id,
1069}; 1255};
@@ -1078,11 +1264,10 @@ static void __exit pm2xxx_charger_exit(void)
1078 i2c_del_driver(&pm2xxx_charger_driver); 1264 i2c_del_driver(&pm2xxx_charger_driver);
1079} 1265}
1080 1266
1081subsys_initcall_sync(pm2xxx_charger_init); 1267device_initcall_sync(pm2xxx_charger_init);
1082module_exit(pm2xxx_charger_exit); 1268module_exit(pm2xxx_charger_exit);
1083 1269
1084MODULE_LICENSE("GPL v2"); 1270MODULE_LICENSE("GPL v2");
1085MODULE_AUTHOR("Rajkumar kasirajan, Olivier Launay"); 1271MODULE_AUTHOR("Rajkumar kasirajan, Olivier Launay");
1086MODULE_ALIAS("platform:pm2xxx-charger"); 1272MODULE_ALIAS("platform:pm2xxx-charger");
1087MODULE_DESCRIPTION("PM2xxx charger management driver"); 1273MODULE_DESCRIPTION("PM2xxx charger management driver");
1088
diff --git a/drivers/power/pm2301_charger.h b/drivers/power/pm2301_charger.h
index e6319cdbc94f..8ce3cc0195df 100644
--- a/drivers/power/pm2301_charger.h
+++ b/drivers/power/pm2301_charger.h
@@ -9,27 +9,6 @@
9#ifndef PM2301_CHARGER_H 9#ifndef PM2301_CHARGER_H
10#define PM2301_CHARGER_H 10#define PM2301_CHARGER_H
11 11
12#define MAIN_WDOG_ENA 0x01
13#define MAIN_WDOG_KICK 0x02
14#define MAIN_WDOG_DIS 0x00
15#define CHARG_WD_KICK 0x01
16#define MAIN_CH_ENA 0x01
17#define MAIN_CH_NO_OVERSHOOT_ENA_N 0x02
18#define MAIN_CH_DET 0x01
19#define MAIN_CH_CV_ON 0x04
20#define OTP_ENABLE_WD 0x01
21
22#define MAIN_CH_INPUT_CURR_SHIFT 4
23
24#define LED_INDICATOR_PWM_ENA 0x01
25#define LED_INDICATOR_PWM_DIS 0x00
26#define LED_IND_CUR_5MA 0x04
27#define LED_INDICATOR_PWM_DUTY_252_256 0xBF
28
29/* HW failure constants */
30#define MAIN_CH_TH_PROT 0x02
31#define MAIN_CH_NOK 0x01
32
33/* Watchdog timeout constant */ 12/* Watchdog timeout constant */
34#define WD_TIMER 0x30 /* 4min */ 13#define WD_TIMER 0x30 /* 4min */
35#define WD_KICK_INTERVAL (30 * HZ) 14#define WD_KICK_INTERVAL (30 * HZ)
@@ -495,7 +474,6 @@ struct pm2xxx_charger {
495 int failure_input_ovv; 474 int failure_input_ovv;
496 unsigned int lpn_pin; 475 unsigned int lpn_pin;
497 struct pm2xxx_interrupts *pm2_int; 476 struct pm2xxx_interrupts *pm2_int;
498 struct ab8500_gpadc *gpadc;
499 struct regulator *regu; 477 struct regulator *regu;
500 struct pm2xxx_bm_data *bat; 478 struct pm2xxx_bm_data *bat;
501 struct mutex lock; 479 struct mutex lock;
@@ -506,6 +484,7 @@ struct pm2xxx_charger {
506 struct delayed_work check_vbat_work; 484 struct delayed_work check_vbat_work;
507 struct work_struct ac_work; 485 struct work_struct ac_work;
508 struct work_struct check_main_thermal_prot_work; 486 struct work_struct check_main_thermal_prot_work;
487 struct delayed_work check_hw_failure_work;
509 struct ux500_charger ac_chg; 488 struct ux500_charger ac_chg;
510 struct pm2xxx_charger_event_flags flags; 489 struct pm2xxx_charger_event_flags flags;
511}; 490};
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 5deac432e2ae..1c517c34e4be 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -26,17 +26,42 @@ EXPORT_SYMBOL_GPL(power_supply_class);
26 26
27static struct device_type power_supply_dev_type; 27static struct device_type power_supply_dev_type;
28 28
29static bool __power_supply_is_supplied_by(struct power_supply *supplier,
30 struct power_supply *supply)
31{
32 int i;
33
34 if (!supply->supplied_from && !supplier->supplied_to)
35 return false;
36
37 /* Support both supplied_to and supplied_from modes */
38 if (supply->supplied_from) {
39 if (!supplier->name)
40 return false;
41 for (i = 0; i < supply->num_supplies; i++)
42 if (!strcmp(supplier->name, supply->supplied_from[i]))
43 return true;
44 } else {
45 if (!supply->name)
46 return false;
47 for (i = 0; i < supplier->num_supplicants; i++)
48 if (!strcmp(supplier->supplied_to[i], supply->name))
49 return true;
50 }
51
52 return false;
53}
54
29static int __power_supply_changed_work(struct device *dev, void *data) 55static int __power_supply_changed_work(struct device *dev, void *data)
30{ 56{
31 struct power_supply *psy = (struct power_supply *)data; 57 struct power_supply *psy = (struct power_supply *)data;
32 struct power_supply *pst = dev_get_drvdata(dev); 58 struct power_supply *pst = dev_get_drvdata(dev);
33 int i;
34 59
35 for (i = 0; i < psy->num_supplicants; i++) 60 if (__power_supply_is_supplied_by(psy, pst)) {
36 if (!strcmp(psy->supplied_to[i], pst->name)) { 61 if (pst->external_power_changed)
37 if (pst->external_power_changed) 62 pst->external_power_changed(pst);
38 pst->external_power_changed(pst); 63 }
39 } 64
40 return 0; 65 return 0;
41} 66}
42 67
@@ -63,22 +88,151 @@ void power_supply_changed(struct power_supply *psy)
63} 88}
64EXPORT_SYMBOL_GPL(power_supply_changed); 89EXPORT_SYMBOL_GPL(power_supply_changed);
65 90
91#ifdef CONFIG_OF
92#include <linux/of.h>
93
94static int __power_supply_populate_supplied_from(struct device *dev,
95 void *data)
96{
97 struct power_supply *psy = (struct power_supply *)data;
98 struct power_supply *epsy = dev_get_drvdata(dev);
99 struct device_node *np;
100 int i = 0;
101
102 do {
103 np = of_parse_phandle(psy->of_node, "power-supplies", i++);
104 if (!np)
105 continue;
106
107 if (np == epsy->of_node) {
108 dev_info(psy->dev, "%s: Found supply : %s\n",
109 psy->name, epsy->name);
110 psy->supplied_from[i-1] = (char *)epsy->name;
111 psy->num_supplies++;
112 break;
113 }
114 } while (np);
115
116 return 0;
117}
118
119static int power_supply_populate_supplied_from(struct power_supply *psy)
120{
121 int error;
122
123 error = class_for_each_device(power_supply_class, NULL, psy,
124 __power_supply_populate_supplied_from);
125
126 dev_dbg(psy->dev, "%s %d\n", __func__, error);
127
128 return error;
129}
130
131static int __power_supply_find_supply_from_node(struct device *dev,
132 void *data)
133{
134 struct device_node *np = (struct device_node *)data;
135 struct power_supply *epsy = dev_get_drvdata(dev);
136
137 /* return error breaks out of class_for_each_device loop */
138 if (epsy->of_node == np)
139 return -EINVAL;
140
141 return 0;
142}
143
144static int power_supply_find_supply_from_node(struct device_node *supply_node)
145{
146 int error;
147 struct device *dev;
148 struct class_dev_iter iter;
149
150 /*
151 * Use iterator to see if any other device is registered.
152 * This is required since class_for_each_device returns 0
153 * if there are no devices registered.
154 */
155 class_dev_iter_init(&iter, power_supply_class, NULL, NULL);
156 dev = class_dev_iter_next(&iter);
157
158 if (!dev)
159 return -EPROBE_DEFER;
160
161 /*
162 * We have to treat the return value as inverted, because if
163 * we return error on not found, then it won't continue looking.
164 * So we trick it by returning error on success to stop looking
165 * once the matching device is found.
166 */
167 error = class_for_each_device(power_supply_class, NULL, supply_node,
168 __power_supply_find_supply_from_node);
169
170 return error ? 0 : -EPROBE_DEFER;
171}
172
173static int power_supply_check_supplies(struct power_supply *psy)
174{
175 struct device_node *np;
176 int cnt = 0;
177
178 /* If there is already a list honor it */
179 if (psy->supplied_from && psy->num_supplies > 0)
180 return 0;
181
182 /* No device node found, nothing to do */
183 if (!psy->of_node)
184 return 0;
185
186 do {
187 int ret;
188
189 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
190 if (!np)
191 continue;
192
193 ret = power_supply_find_supply_from_node(np);
194 if (ret) {
195 dev_dbg(psy->dev, "Failed to find supply, defer!\n");
196 return -EPROBE_DEFER;
197 }
198 } while (np);
199
200 /* All supplies found, allocate char ** array for filling */
201 psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from),
202 GFP_KERNEL);
203 if (!psy->supplied_from) {
204 dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
205 return -ENOMEM;
206 }
207
208 *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt,
209 GFP_KERNEL);
210 if (!*psy->supplied_from) {
211 dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
212 return -ENOMEM;
213 }
214
215 return power_supply_populate_supplied_from(psy);
216}
217#else
218static inline int power_supply_check_supplies(struct power_supply *psy)
219{
220 return 0;
221}
222#endif
223
66static int __power_supply_am_i_supplied(struct device *dev, void *data) 224static int __power_supply_am_i_supplied(struct device *dev, void *data)
67{ 225{
68 union power_supply_propval ret = {0,}; 226 union power_supply_propval ret = {0,};
69 struct power_supply *psy = (struct power_supply *)data; 227 struct power_supply *psy = (struct power_supply *)data;
70 struct power_supply *epsy = dev_get_drvdata(dev); 228 struct power_supply *epsy = dev_get_drvdata(dev);
71 int i;
72 229
73 for (i = 0; i < epsy->num_supplicants; i++) { 230 if (__power_supply_is_supplied_by(epsy, psy))
74 if (!strcmp(epsy->supplied_to[i], psy->name)) { 231 if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) {
75 if (epsy->get_property(epsy,
76 POWER_SUPPLY_PROP_ONLINE, &ret))
77 continue;
78 if (ret.intval) 232 if (ret.intval)
79 return ret.intval; 233 return ret.intval;
80 } 234 }
81 } 235
82 return 0; 236 return 0;
83} 237}
84 238
@@ -336,6 +490,12 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
336 490
337 INIT_WORK(&psy->changed_work, power_supply_changed_work); 491 INIT_WORK(&psy->changed_work, power_supply_changed_work);
338 492
493 rc = power_supply_check_supplies(psy);
494 if (rc) {
495 dev_info(dev, "Not all required supplies found, defer probe\n");
496 goto check_supplies_failed;
497 }
498
339 rc = kobject_set_name(&dev->kobj, "%s", psy->name); 499 rc = kobject_set_name(&dev->kobj, "%s", psy->name);
340 if (rc) 500 if (rc)
341 goto kobject_set_name_failed; 501 goto kobject_set_name_failed;
@@ -368,6 +528,7 @@ register_thermal_failed:
368 device_del(dev); 528 device_del(dev);
369kobject_set_name_failed: 529kobject_set_name_failed:
370device_add_failed: 530device_add_failed:
531check_supplies_failed:
371 put_device(dev); 532 put_device(dev);
372success: 533success:
373 return rc; 534 return rc;
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 1ae65b822864..349e9ae8090a 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -30,3 +30,10 @@ config POWER_RESET_RESTART
30 Some boards don't actually have the ability to power off. 30 Some boards don't actually have the ability to power off.
31 Instead they restart, and u-boot holds the SoC until the 31 Instead they restart, and u-boot holds the SoC until the
32 user presses a key. u-boot then boots into Linux. 32 user presses a key. u-boot then boots into Linux.
33
34config POWER_RESET_VEXPRESS
35 bool
36 depends on POWER_RESET
37 help
38 Power off and reset support for the ARM Ltd. Versatile
39 Express boards.
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 0f317f50c56f..372807fd83f7 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o 1obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
2obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o 2obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
3obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o \ No newline at end of file 3obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
4obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o
diff --git a/arch/arm/mach-vexpress/reset.c b/drivers/power/reset/vexpress-poweroff.c
index 465923aa3819..469e6962b2cf 100644
--- a/arch/arm/mach-vexpress/reset.c
+++ b/drivers/power/reset/vexpress-poweroff.c
@@ -18,6 +18,8 @@
18#include <linux/stat.h> 18#include <linux/stat.h>
19#include <linux/vexpress.h> 19#include <linux/vexpress.h>
20 20
21#include <asm/system_misc.h>
22
21static void vexpress_reset_do(struct device *dev, const char *what) 23static void vexpress_reset_do(struct device *dev, const char *what)
22{ 24{
23 int err = -ENOENT; 25 int err = -ENOENT;
@@ -39,14 +41,14 @@ static void vexpress_reset_do(struct device *dev, const char *what)
39 41
40static struct device *vexpress_power_off_device; 42static struct device *vexpress_power_off_device;
41 43
42void vexpress_power_off(void) 44static void vexpress_power_off(void)
43{ 45{
44 vexpress_reset_do(vexpress_power_off_device, "power off"); 46 vexpress_reset_do(vexpress_power_off_device, "power off");
45} 47}
46 48
47static struct device *vexpress_restart_device; 49static struct device *vexpress_restart_device;
48 50
49void vexpress_restart(char str, const char *cmd) 51static void vexpress_restart(char str, const char *cmd)
50{ 52{
51 vexpress_reset_do(vexpress_restart_device, "restart"); 53 vexpress_reset_do(vexpress_restart_device, "restart");
52} 54}
@@ -103,14 +105,17 @@ static int vexpress_reset_probe(struct platform_device *pdev)
103 switch (func) { 105 switch (func) {
104 case FUNC_SHUTDOWN: 106 case FUNC_SHUTDOWN:
105 vexpress_power_off_device = &pdev->dev; 107 vexpress_power_off_device = &pdev->dev;
108 pm_power_off = vexpress_power_off;
106 break; 109 break;
107 case FUNC_RESET: 110 case FUNC_RESET:
108 if (!vexpress_restart_device) 111 if (!vexpress_restart_device)
109 vexpress_restart_device = &pdev->dev; 112 vexpress_restart_device = &pdev->dev;
113 arm_pm_restart = vexpress_restart;
110 device_create_file(&pdev->dev, &dev_attr_active); 114 device_create_file(&pdev->dev, &dev_attr_active);
111 break; 115 break;
112 case FUNC_REBOOT: 116 case FUNC_REBOOT:
113 vexpress_restart_device = &pdev->dev; 117 vexpress_restart_device = &pdev->dev;
118 arm_pm_restart = vexpress_restart;
114 device_create_file(&pdev->dev, &dev_attr_active); 119 device_create_file(&pdev->dev, &dev_attr_active);
115 break; 120 break;
116 }; 121 };
diff --git a/drivers/power/rx51_battery.c b/drivers/power/rx51_battery.c
index 8208888b844e..1a1dcb831a17 100644
--- a/drivers/power/rx51_battery.c
+++ b/drivers/power/rx51_battery.c
@@ -119,7 +119,7 @@ static int rx51_battery_read_temperature(struct rx51_device_info *di)
119 119
120 /* First check for temperature in first direct table */ 120 /* First check for temperature in first direct table */
121 if (raw < ARRAY_SIZE(rx51_temp_table1)) 121 if (raw < ARRAY_SIZE(rx51_temp_table1))
122 return rx51_temp_table1[raw] * 100; 122 return rx51_temp_table1[raw] * 10;
123 123
124 /* Binary search RAW value in second inverse table */ 124 /* Binary search RAW value in second inverse table */
125 while (max - min > 1) { 125 while (max - min > 1) {
@@ -132,7 +132,7 @@ static int rx51_battery_read_temperature(struct rx51_device_info *di)
132 break; 132 break;
133 } 133 }
134 134
135 return (rx51_temp_table2_first - min) * 100; 135 return (rx51_temp_table2_first - min) * 10;
136} 136}
137 137
138/* 138/*
@@ -202,7 +202,7 @@ static int rx51_battery_probe(struct platform_device *pdev)
202 struct rx51_device_info *di; 202 struct rx51_device_info *di;
203 int ret; 203 int ret;
204 204
205 di = kzalloc(sizeof(*di), GFP_KERNEL); 205 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
206 if (!di) 206 if (!di)
207 return -ENOMEM; 207 return -ENOMEM;
208 208
@@ -217,7 +217,6 @@ static int rx51_battery_probe(struct platform_device *pdev)
217 ret = power_supply_register(di->dev, &di->bat); 217 ret = power_supply_register(di->dev, &di->bat);
218 if (ret) { 218 if (ret) {
219 platform_set_drvdata(pdev, NULL); 219 platform_set_drvdata(pdev, NULL);
220 kfree(di);
221 return ret; 220 return ret;
222 } 221 }
223 222
@@ -230,7 +229,6 @@ static int rx51_battery_remove(struct platform_device *pdev)
230 229
231 power_supply_unregister(&di->bat); 230 power_supply_unregister(&di->bat);
232 platform_set_drvdata(pdev, NULL); 231 platform_set_drvdata(pdev, NULL);
233 kfree(di);
234 232
235 return 0; 233 return 0;
236} 234}
diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
index d2ca989dcbdc..5948ce058bdd 100644
--- a/drivers/power/s3c_adc_battery.c
+++ b/drivers/power/s3c_adc_battery.c
@@ -145,14 +145,17 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
145 145
146 int new_level; 146 int new_level;
147 int full_volt; 147 int full_volt;
148 const struct s3c_adc_bat_thresh *lut = bat->pdata->lut_noac; 148 const struct s3c_adc_bat_thresh *lut;
149 unsigned int lut_size = bat->pdata->lut_noac_cnt; 149 unsigned int lut_size;
150 150
151 if (!bat) { 151 if (!bat) {
152 dev_err(psy->dev, "no battery infos ?!\n"); 152 dev_err(psy->dev, "no battery infos ?!\n");
153 return -EINVAL; 153 return -EINVAL;
154 } 154 }
155 155
156 lut = bat->pdata->lut_noac;
157 lut_size = bat->pdata->lut_noac_cnt;
158
156 if (bat->volt_value < 0 || bat->cur_value < 0 || 159 if (bat->volt_value < 0 || bat->cur_value < 0 ||
157 jiffies_to_msecs(jiffies - bat->timestamp) > 160 jiffies_to_msecs(jiffies - bat->timestamp) >
158 BAT_POLL_INTERVAL) { 161 BAT_POLL_INTERVAL) {
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 3960f0b2afe9..c8c78a74e75a 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/of.h>
30 31
31#include <linux/power/sbs-battery.h> 32#include <linux/power/sbs-battery.h>
32 33
@@ -667,7 +668,6 @@ of_out:
667 return pdata; 668 return pdata;
668} 669}
669#else 670#else
670#define sbs_dt_ids NULL
671static struct sbs_platform_data *sbs_of_populate_pdata( 671static struct sbs_platform_data *sbs_of_populate_pdata(
672 struct i2c_client *client) 672 struct i2c_client *client)
673{ 673{
@@ -820,10 +820,11 @@ static int sbs_remove(struct i2c_client *client)
820 return 0; 820 return 0;
821} 821}
822 822
823#if defined CONFIG_PM 823#if defined CONFIG_PM_SLEEP
824static int sbs_suspend(struct i2c_client *client, 824
825 pm_message_t state) 825static int sbs_suspend(struct device *dev)
826{ 826{
827 struct i2c_client *client = to_i2c_client(dev);
827 struct sbs_info *chip = i2c_get_clientdata(client); 828 struct sbs_info *chip = i2c_get_clientdata(client);
828 s32 ret; 829 s32 ret;
829 830
@@ -838,11 +839,13 @@ static int sbs_suspend(struct i2c_client *client,
838 839
839 return 0; 840 return 0;
840} 841}
842
843static SIMPLE_DEV_PM_OPS(sbs_pm_ops, sbs_suspend, NULL);
844#define SBS_PM_OPS (&sbs_pm_ops)
845
841#else 846#else
842#define sbs_suspend NULL 847#define SBS_PM_OPS NULL
843#endif 848#endif
844/* any smbus transaction will wake up sbs */
845#define sbs_resume NULL
846 849
847static const struct i2c_device_id sbs_id[] = { 850static const struct i2c_device_id sbs_id[] = {
848 { "bq20z75", 0 }, 851 { "bq20z75", 0 },
@@ -854,12 +857,11 @@ MODULE_DEVICE_TABLE(i2c, sbs_id);
854static struct i2c_driver sbs_battery_driver = { 857static struct i2c_driver sbs_battery_driver = {
855 .probe = sbs_probe, 858 .probe = sbs_probe,
856 .remove = sbs_remove, 859 .remove = sbs_remove,
857 .suspend = sbs_suspend,
858 .resume = sbs_resume,
859 .id_table = sbs_id, 860 .id_table = sbs_id,
860 .driver = { 861 .driver = {
861 .name = "sbs-battery", 862 .name = "sbs-battery",
862 .of_match_table = sbs_dt_ids, 863 .of_match_table = of_match_ptr(sbs_dt_ids),
864 .pm = SBS_PM_OPS,
863 }, 865 },
864}; 866};
865module_i2c_driver(sbs_battery_driver); 867module_i2c_driver(sbs_battery_driver);
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c
index b99a452a4fda..0152f35dca5c 100644
--- a/drivers/power/test_power.c
+++ b/drivers/power/test_power.c
@@ -30,6 +30,8 @@ static int battery_technology = POWER_SUPPLY_TECHNOLOGY_LION;
30static int battery_capacity = 50; 30static int battery_capacity = 50;
31static int battery_voltage = 3300; 31static int battery_voltage = 3300;
32 32
33static bool module_initialized;
34
33static int test_power_get_ac_property(struct power_supply *psy, 35static int test_power_get_ac_property(struct power_supply *psy,
34 enum power_supply_property psp, 36 enum power_supply_property psp,
35 union power_supply_propval *val) 37 union power_supply_propval *val)
@@ -185,6 +187,7 @@ static int __init test_power_init(void)
185 } 187 }
186 } 188 }
187 189
190 module_initialized = true;
188 return 0; 191 return 0;
189failed: 192failed:
190 while (--i >= 0) 193 while (--i >= 0)
@@ -209,6 +212,8 @@ static void __exit test_power_exit(void)
209 212
210 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) 213 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
211 power_supply_unregister(&test_power_supplies[i]); 214 power_supply_unregister(&test_power_supplies[i]);
215
216 module_initialized = false;
212} 217}
213module_exit(test_power_exit); 218module_exit(test_power_exit);
214 219
@@ -221,8 +226,8 @@ struct battery_property_map {
221}; 226};
222 227
223static struct battery_property_map map_ac_online[] = { 228static struct battery_property_map map_ac_online[] = {
224 { 0, "on" }, 229 { 0, "off" },
225 { 1, "off" }, 230 { 1, "on" },
226 { -1, NULL }, 231 { -1, NULL },
227}; 232};
228 233
@@ -295,10 +300,16 @@ static const char *map_get_key(struct battery_property_map *map, int value,
295 return def_key; 300 return def_key;
296} 301}
297 302
303static inline void signal_power_supply_changed(struct power_supply *psy)
304{
305 if (module_initialized)
306 power_supply_changed(psy);
307}
308
298static int param_set_ac_online(const char *key, const struct kernel_param *kp) 309static int param_set_ac_online(const char *key, const struct kernel_param *kp)
299{ 310{
300 ac_online = map_get_value(map_ac_online, key, ac_online); 311 ac_online = map_get_value(map_ac_online, key, ac_online);
301 power_supply_changed(&test_power_supplies[0]); 312 signal_power_supply_changed(&test_power_supplies[0]);
302 return 0; 313 return 0;
303} 314}
304 315
@@ -311,7 +322,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
311static int param_set_usb_online(const char *key, const struct kernel_param *kp) 322static int param_set_usb_online(const char *key, const struct kernel_param *kp)
312{ 323{
313 usb_online = map_get_value(map_ac_online, key, usb_online); 324 usb_online = map_get_value(map_ac_online, key, usb_online);
314 power_supply_changed(&test_power_supplies[2]); 325 signal_power_supply_changed(&test_power_supplies[2]);
315 return 0; 326 return 0;
316} 327}
317 328
@@ -325,7 +336,7 @@ static int param_set_battery_status(const char *key,
325 const struct kernel_param *kp) 336 const struct kernel_param *kp)
326{ 337{
327 battery_status = map_get_value(map_status, key, battery_status); 338 battery_status = map_get_value(map_status, key, battery_status);
328 power_supply_changed(&test_power_supplies[1]); 339 signal_power_supply_changed(&test_power_supplies[1]);
329 return 0; 340 return 0;
330} 341}
331 342
@@ -339,7 +350,7 @@ static int param_set_battery_health(const char *key,
339 const struct kernel_param *kp) 350 const struct kernel_param *kp)
340{ 351{
341 battery_health = map_get_value(map_health, key, battery_health); 352 battery_health = map_get_value(map_health, key, battery_health);
342 power_supply_changed(&test_power_supplies[1]); 353 signal_power_supply_changed(&test_power_supplies[1]);
343 return 0; 354 return 0;
344} 355}
345 356
@@ -353,7 +364,7 @@ static int param_set_battery_present(const char *key,
353 const struct kernel_param *kp) 364 const struct kernel_param *kp)
354{ 365{
355 battery_present = map_get_value(map_present, key, battery_present); 366 battery_present = map_get_value(map_present, key, battery_present);
356 power_supply_changed(&test_power_supplies[0]); 367 signal_power_supply_changed(&test_power_supplies[0]);
357 return 0; 368 return 0;
358} 369}
359 370
@@ -369,7 +380,7 @@ static int param_set_battery_technology(const char *key,
369{ 380{
370 battery_technology = map_get_value(map_technology, key, 381 battery_technology = map_get_value(map_technology, key,
371 battery_technology); 382 battery_technology);
372 power_supply_changed(&test_power_supplies[1]); 383 signal_power_supply_changed(&test_power_supplies[1]);
373 return 0; 384 return 0;
374} 385}
375 386
@@ -390,7 +401,7 @@ static int param_set_battery_capacity(const char *key,
390 return -EINVAL; 401 return -EINVAL;
391 402
392 battery_capacity = tmp; 403 battery_capacity = tmp;
393 power_supply_changed(&test_power_supplies[1]); 404 signal_power_supply_changed(&test_power_supplies[1]);
394 return 0; 405 return 0;
395} 406}
396 407
@@ -405,7 +416,7 @@ static int param_set_battery_voltage(const char *key,
405 return -EINVAL; 416 return -EINVAL;
406 417
407 battery_voltage = tmp; 418 battery_voltage = tmp;
408 power_supply_changed(&test_power_supplies[1]); 419 signal_power_supply_changed(&test_power_supplies[1]);
409 return 0; 420 return 0;
410} 421}
411 422
diff --git a/drivers/power/tps65090-charger.c b/drivers/power/tps65090-charger.c
new file mode 100644
index 000000000000..9fbca310a2ad
--- /dev/null
+++ b/drivers/power/tps65090-charger.c
@@ -0,0 +1,320 @@
1/*
2 * Battery charger driver for TI's tps65090
3 *
4 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
5
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h>
26#include <linux/power_supply.h>
27#include <linux/mfd/tps65090.h>
28
29#define TPS65090_REG_INTR_STS 0x00
30#define TPS65090_REG_CG_CTRL0 0x04
31#define TPS65090_REG_CG_CTRL1 0x05
32#define TPS65090_REG_CG_CTRL2 0x06
33#define TPS65090_REG_CG_CTRL3 0x07
34#define TPS65090_REG_CG_CTRL4 0x08
35#define TPS65090_REG_CG_CTRL5 0x09
36#define TPS65090_REG_CG_STATUS1 0x0a
37#define TPS65090_REG_CG_STATUS2 0x0b
38
39#define TPS65090_CHARGER_ENABLE BIT(0)
40#define TPS65090_VACG BIT(1)
41#define TPS65090_NOITERM BIT(5)
42
43struct tps65090_charger {
44 struct device *dev;
45 int ac_online;
46 int prev_ac_online;
47 int irq;
48 struct power_supply ac;
49 struct tps65090_platform_data *pdata;
50};
51
52static enum power_supply_property tps65090_ac_props[] = {
53 POWER_SUPPLY_PROP_ONLINE,
54};
55
56static int tps65090_low_chrg_current(struct tps65090_charger *charger)
57{
58 int ret;
59
60 ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL5,
61 TPS65090_NOITERM);
62 if (ret < 0) {
63 dev_err(charger->dev, "%s(): error reading in register 0x%x\n",
64 __func__, TPS65090_REG_CG_CTRL5);
65 return ret;
66 }
67 return 0;
68}
69
70static int tps65090_enable_charging(struct tps65090_charger *charger,
71 uint8_t enable)
72{
73 int ret;
74 uint8_t ctrl0 = 0;
75
76 ret = tps65090_read(charger->dev->parent, TPS65090_REG_CG_CTRL0,
77 &ctrl0);
78 if (ret < 0) {
79 dev_err(charger->dev, "%s(): error reading in register 0x%x\n",
80 __func__, TPS65090_REG_CG_CTRL0);
81 return ret;
82 }
83
84 ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL0,
85 (ctrl0 | TPS65090_CHARGER_ENABLE));
86 if (ret < 0) {
87 dev_err(charger->dev, "%s(): error reading in register 0x%x\n",
88 __func__, TPS65090_REG_CG_CTRL0);
89 return ret;
90 }
91 return 0;
92}
93
94static int tps65090_config_charger(struct tps65090_charger *charger)
95{
96 int ret;
97
98 if (charger->pdata->enable_low_current_chrg) {
99 ret = tps65090_low_chrg_current(charger);
100 if (ret < 0) {
101 dev_err(charger->dev,
102 "error configuring low charge current\n");
103 return ret;
104 }
105 }
106
107 return 0;
108}
109
110static int tps65090_ac_get_property(struct power_supply *psy,
111 enum power_supply_property psp,
112 union power_supply_propval *val)
113{
114 struct tps65090_charger *charger = container_of(psy,
115 struct tps65090_charger, ac);
116
117 if (psp == POWER_SUPPLY_PROP_ONLINE) {
118 val->intval = charger->ac_online;
119 charger->prev_ac_online = charger->ac_online;
120 return 0;
121 }
122 return -EINVAL;
123}
124
125static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
126{
127 struct tps65090_charger *charger = dev_id;
128 int ret;
129 uint8_t status1 = 0;
130 uint8_t intrsts = 0;
131
132 ret = tps65090_read(charger->dev->parent, TPS65090_REG_CG_STATUS1,
133 &status1);
134 if (ret < 0) {
135 dev_err(charger->dev, "%s(): Error in reading reg 0x%x\n",
136 __func__, TPS65090_REG_CG_STATUS1);
137 return IRQ_HANDLED;
138 }
139 msleep(75);
140 ret = tps65090_read(charger->dev->parent, TPS65090_REG_INTR_STS,
141 &intrsts);
142 if (ret < 0) {
143 dev_err(charger->dev, "%s(): Error in reading reg 0x%x\n",
144 __func__, TPS65090_REG_INTR_STS);
145 return IRQ_HANDLED;
146 }
147
148 if (intrsts & TPS65090_VACG) {
149 ret = tps65090_enable_charging(charger, 1);
150 if (ret < 0)
151 return IRQ_HANDLED;
152 charger->ac_online = 1;
153 } else {
154 charger->ac_online = 0;
155 }
156
157 if (charger->prev_ac_online != charger->ac_online)
158 power_supply_changed(&charger->ac);
159
160 return IRQ_HANDLED;
161}
162
163#if defined(CONFIG_OF)
164
165#include <linux/of_device.h>
166
167static struct tps65090_platform_data *
168 tps65090_parse_dt_charger_data(struct platform_device *pdev)
169{
170 struct tps65090_platform_data *pdata;
171 struct device_node *np = pdev->dev.of_node;
172 unsigned int prop;
173
174 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
175 if (!pdata) {
176 dev_err(&pdev->dev, "Memory alloc for tps65090_pdata failed\n");
177 return NULL;
178 }
179
180 prop = of_property_read_bool(np, "ti,enable-low-current-chrg");
181 pdata->enable_low_current_chrg = prop;
182
183 pdata->irq_base = -1;
184
185 return pdata;
186
187}
188#else
189static struct tps65090_platform_data *
190 tps65090_parse_dt_charger_data(struct platform_device *pdev)
191{
192 return NULL;
193}
194#endif
195
196static int tps65090_charger_probe(struct platform_device *pdev)
197{
198 struct tps65090_charger *cdata;
199 struct tps65090_platform_data *pdata;
200 uint8_t status1 = 0;
201 int ret;
202 int irq;
203
204 pdata = dev_get_platdata(pdev->dev.parent);
205
206 if (!pdata && pdev->dev.of_node)
207 pdata = tps65090_parse_dt_charger_data(pdev);
208
209 if (!pdata) {
210 dev_err(&pdev->dev, "%s():no platform data available\n",
211 __func__);
212 return -ENODEV;
213 }
214
215 cdata = devm_kzalloc(&pdev->dev, sizeof(*cdata), GFP_KERNEL);
216 if (!cdata) {
217 dev_err(&pdev->dev, "failed to allocate memory status\n");
218 return -ENOMEM;
219 }
220
221 dev_set_drvdata(&pdev->dev, cdata);
222
223 cdata->dev = &pdev->dev;
224 cdata->pdata = pdata;
225
226 cdata->ac.name = "tps65090-ac";
227 cdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
228 cdata->ac.get_property = tps65090_ac_get_property;
229 cdata->ac.properties = tps65090_ac_props;
230 cdata->ac.num_properties = ARRAY_SIZE(tps65090_ac_props);
231 cdata->ac.supplied_to = pdata->supplied_to;
232 cdata->ac.num_supplicants = pdata->num_supplicants;
233
234 ret = power_supply_register(&pdev->dev, &cdata->ac);
235 if (ret) {
236 dev_err(&pdev->dev, "failed: power supply register\n");
237 return ret;
238 }
239
240 irq = platform_get_irq(pdev, 0);
241 if (irq <= 0) {
242 dev_warn(&pdev->dev, "Unable to get charger irq = %d\n", irq);
243 ret = irq;
244 goto fail_unregister_supply;
245 }
246
247 cdata->irq = irq;
248
249 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
250 tps65090_charger_isr, 0, "tps65090-charger", cdata);
251 if (ret) {
252 dev_err(cdata->dev, "Unable to register irq %d err %d\n", irq,
253 ret);
254 goto fail_free_irq;
255 }
256
257 ret = tps65090_config_charger(cdata);
258 if (ret < 0) {
259 dev_err(&pdev->dev, "charger config failed, err %d\n", ret);
260 goto fail_free_irq;
261 }
262
263 /* Check for charger presence */
264 ret = tps65090_read(cdata->dev->parent, TPS65090_REG_CG_STATUS1,
265 &status1);
266 if (ret < 0) {
267 dev_err(cdata->dev, "%s(): Error in reading reg 0x%x", __func__,
268 TPS65090_REG_CG_STATUS1);
269 goto fail_free_irq;
270 }
271
272 if (status1 != 0) {
273 ret = tps65090_enable_charging(cdata, 1);
274 if (ret < 0) {
275 dev_err(cdata->dev, "error enabling charger\n");
276 goto fail_free_irq;
277 }
278 cdata->ac_online = 1;
279 power_supply_changed(&cdata->ac);
280 }
281
282 return 0;
283
284fail_free_irq:
285 devm_free_irq(cdata->dev, irq, cdata);
286fail_unregister_supply:
287 power_supply_unregister(&cdata->ac);
288
289 return ret;
290}
291
292static int tps65090_charger_remove(struct platform_device *pdev)
293{
294 struct tps65090_charger *cdata = dev_get_drvdata(&pdev->dev);
295
296 devm_free_irq(cdata->dev, cdata->irq, cdata);
297 power_supply_unregister(&cdata->ac);
298
299 return 0;
300}
301
302static struct of_device_id of_tps65090_charger_match[] = {
303 { .compatible = "ti,tps65090-charger", },
304 { /* end */ }
305};
306
307static struct platform_driver tps65090_charger_driver = {
308 .driver = {
309 .name = "tps65090-charger",
310 .of_match_table = of_tps65090_charger_match,
311 .owner = THIS_MODULE,
312 },
313 .probe = tps65090_charger_probe,
314 .remove = tps65090_charger_remove,
315};
316module_platform_driver(tps65090_charger_driver);
317
318MODULE_LICENSE("GPL v2");
319MODULE_AUTHOR("Syed Rafiuddin <srafiuddin@nvidia.com>");
320MODULE_DESCRIPTION("tps65090 battery charger driver");
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index a69d0d11b540..bed458172dd2 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -636,17 +636,7 @@ static struct platform_driver twl4030_bci_driver = {
636 .remove = __exit_p(twl4030_bci_remove), 636 .remove = __exit_p(twl4030_bci_remove),
637}; 637};
638 638
639static int __init twl4030_bci_init(void) 639module_platform_driver_probe(twl4030_bci_driver, twl4030_bci_probe);
640{
641 return platform_driver_probe(&twl4030_bci_driver, twl4030_bci_probe);
642}
643module_init(twl4030_bci_init);
644
645static void __exit twl4030_bci_exit(void)
646{
647 platform_driver_unregister(&twl4030_bci_driver);
648}
649module_exit(twl4030_bci_exit);
650 640
651MODULE_AUTHOR("Gražvydas Ignotas"); 641MODULE_AUTHOR("Gražvydas Ignotas");
652MODULE_DESCRIPTION("TWL4030 Battery Charger Interface driver"); 642MODULE_DESCRIPTION("TWL4030 Battery Charger Interface driver");
diff --git a/drivers/power/wm831x_backup.c b/drivers/power/wm831x_backup.c
index d9cc169f1424..58cbb009b74f 100644
--- a/drivers/power/wm831x_backup.c
+++ b/drivers/power/wm831x_backup.c
@@ -169,7 +169,8 @@ static int wm831x_backup_probe(struct platform_device *pdev)
169 struct power_supply *backup; 169 struct power_supply *backup;
170 int ret; 170 int ret;
171 171
172 devdata = kzalloc(sizeof(struct wm831x_backup), GFP_KERNEL); 172 devdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_backup),
173 GFP_KERNEL);
173 if (devdata == NULL) 174 if (devdata == NULL)
174 return -ENOMEM; 175 return -ENOMEM;
175 176
@@ -197,14 +198,8 @@ static int wm831x_backup_probe(struct platform_device *pdev)
197 backup->num_properties = ARRAY_SIZE(wm831x_backup_props); 198 backup->num_properties = ARRAY_SIZE(wm831x_backup_props);
198 backup->get_property = wm831x_backup_get_prop; 199 backup->get_property = wm831x_backup_get_prop;
199 ret = power_supply_register(&pdev->dev, backup); 200 ret = power_supply_register(&pdev->dev, backup);
200 if (ret)
201 goto err_kmalloc;
202 201
203 return ret; 202 return ret;
204
205err_kmalloc:
206 kfree(devdata);
207 return ret;
208} 203}
209 204
210static int wm831x_backup_remove(struct platform_device *pdev) 205static int wm831x_backup_remove(struct platform_device *pdev)
@@ -213,7 +208,6 @@ static int wm831x_backup_remove(struct platform_device *pdev)
213 208
214 power_supply_unregister(&devdata->backup); 209 power_supply_unregister(&devdata->backup);
215 kfree(devdata->backup.name); 210 kfree(devdata->backup.name);
216 kfree(devdata);
217 211
218 return 0; 212 return 0;
219} 213}
diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
index 9ead60bc66b7..3301b2031c8d 100644
--- a/include/linux/mfd/abx500.h
+++ b/include/linux/mfd/abx500.h
@@ -89,6 +89,11 @@ struct abx500_fg;
89 * points. 89 * points.
90 * @maint_thres This is the threshold where we stop reporting 90 * @maint_thres This is the threshold where we stop reporting
91 * battery full while in maintenance, in per cent 91 * battery full while in maintenance, in per cent
92 * @pcut_enable: Enable power cut feature in ab8505
93 * @pcut_max_time: Max time threshold
94 * @pcut_flag_time: Flagtime threshold
95 * @pcut_max_restart: Max number of restarts
96 * @pcut_debounce_time: Sets battery debounce time
92 */ 97 */
93struct abx500_fg_parameters { 98struct abx500_fg_parameters {
94 int recovery_sleep_timer; 99 int recovery_sleep_timer;
@@ -106,6 +111,11 @@ struct abx500_fg_parameters {
106 int battok_raising_th_sel1; 111 int battok_raising_th_sel1;
107 int user_cap_limit; 112 int user_cap_limit;
108 int maint_thres; 113 int maint_thres;
114 bool pcut_enable;
115 u8 pcut_max_time;
116 u8 pcut_flag_time;
117 u8 pcut_max_restart;
118 u8 pcut_debounce_time;
109}; 119};
110 120
111/** 121/**
@@ -173,11 +183,11 @@ struct abx500_battery_type {
173 int low_high_vol_lvl; 183 int low_high_vol_lvl;
174 int battery_resistance; 184 int battery_resistance;
175 int n_temp_tbl_elements; 185 int n_temp_tbl_elements;
176 struct abx500_res_to_temp *r_to_t_tbl; 186 const struct abx500_res_to_temp *r_to_t_tbl;
177 int n_v_cap_tbl_elements; 187 int n_v_cap_tbl_elements;
178 struct abx500_v_to_cap *v_to_cap_tbl; 188 const struct abx500_v_to_cap *v_to_cap_tbl;
179 int n_batres_tbl_elements; 189 int n_batres_tbl_elements;
180 struct batres_vs_temp *batres_tbl; 190 const struct batres_vs_temp *batres_tbl;
181}; 191};
182 192
183/** 193/**
@@ -236,7 +246,11 @@ struct abx500_bm_charger_parameters {
236 * @interval_not_charging charge alg cycle period time when not charging (sec) 246 * @interval_not_charging charge alg cycle period time when not charging (sec)
237 * @temp_hysteresis temperature hysteresis 247 * @temp_hysteresis temperature hysteresis
238 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm) 248 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
239 * @maxi: maximization parameters 249 * @n_chg_out_curr number of elements in array chg_output_curr
250 * @n_chg_in_curr number of elements in array chg_input_curr
251 * @chg_output_curr charger output current level map
252 * @chg_input_curr charger input current level map
253 * @maxi maximization parameters
240 * @cap_levels capacity in percent for the different capacity levels 254 * @cap_levels capacity in percent for the different capacity levels
241 * @bat_type table of supported battery types 255 * @bat_type table of supported battery types
242 * @chg_params charger parameters 256 * @chg_params charger parameters
@@ -257,6 +271,7 @@ struct abx500_bm_data {
257 bool autopower_cfg; 271 bool autopower_cfg;
258 bool ac_enabled; 272 bool ac_enabled;
259 bool usb_enabled; 273 bool usb_enabled;
274 bool usb_power_path;
260 bool no_maintenance; 275 bool no_maintenance;
261 bool capacity_scaling; 276 bool capacity_scaling;
262 bool chg_unknown_bat; 277 bool chg_unknown_bat;
@@ -270,6 +285,10 @@ struct abx500_bm_data {
270 int interval_not_charging; 285 int interval_not_charging;
271 int temp_hysteresis; 286 int temp_hysteresis;
272 int gnd_lift_resistance; 287 int gnd_lift_resistance;
288 int n_chg_out_curr;
289 int n_chg_in_curr;
290 int *chg_output_curr;
291 int *chg_input_curr;
273 const struct abx500_maxim_parameters *maxi; 292 const struct abx500_maxim_parameters *maxi;
274 const struct abx500_bm_capacity_levels *cap_levels; 293 const struct abx500_bm_capacity_levels *cap_levels;
275 struct abx500_battery_type *bat_type; 294 struct abx500_battery_type *bat_type;
diff --git a/include/linux/mfd/abx500/ab8500-bm.h b/include/linux/mfd/abx500/ab8500-bm.h
index 8d35bfe164c8..cc892a8d8d6e 100644
--- a/include/linux/mfd/abx500/ab8500-bm.h
+++ b/include/linux/mfd/abx500/ab8500-bm.h
@@ -23,6 +23,7 @@
23 * Bank : 0x5 23 * Bank : 0x5
24 */ 24 */
25#define AB8500_USB_LINE_STAT_REG 0x80 25#define AB8500_USB_LINE_STAT_REG 0x80
26#define AB8500_USB_LINE_CTRL2_REG 0x82
26#define AB8500_USB_LINK1_STAT_REG 0x94 27#define AB8500_USB_LINK1_STAT_REG 0x94
27 28
28/* 29/*
@@ -33,7 +34,7 @@
33#define AB8500_CH_STATUS2_REG 0x01 34#define AB8500_CH_STATUS2_REG 0x01
34#define AB8500_CH_USBCH_STAT1_REG 0x02 35#define AB8500_CH_USBCH_STAT1_REG 0x02
35#define AB8500_CH_USBCH_STAT2_REG 0x03 36#define AB8500_CH_USBCH_STAT2_REG 0x03
36#define AB8500_CH_FSM_STAT_REG 0x04 37#define AB8540_CH_USBCH_STAT3_REG 0x04
37#define AB8500_CH_STAT_REG 0x05 38#define AB8500_CH_STAT_REG 0x05
38 39
39/* 40/*
@@ -69,6 +70,8 @@
69#define AB8500_USBCH_CTRL1_REG 0xC0 70#define AB8500_USBCH_CTRL1_REG 0xC0
70#define AB8500_USBCH_CTRL2_REG 0xC1 71#define AB8500_USBCH_CTRL2_REG 0xC1
71#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2 72#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
73#define AB8540_USB_PP_MODE_REG 0xC5
74#define AB8540_USB_PP_CHR_REG 0xC6
72 75
73/* 76/*
74 * Gas Gauge register offsets 77 * Gas Gauge register offsets
@@ -105,6 +108,7 @@
105#define AB8500_RTC_BACKUP_CHG_REG 0x0C 108#define AB8500_RTC_BACKUP_CHG_REG 0x0C
106#define AB8500_RTC_CC_CONF_REG 0x01 109#define AB8500_RTC_CC_CONF_REG 0x01
107#define AB8500_RTC_CTRL_REG 0x0B 110#define AB8500_RTC_CTRL_REG 0x0B
111#define AB8500_RTC_CTRL1_REG 0x11
108 112
109/* 113/*
110 * OTP register offsets 114 * OTP register offsets
@@ -154,6 +158,7 @@
154#define CH_OP_CUR_LVL_1P4 0x0D 158#define CH_OP_CUR_LVL_1P4 0x0D
155#define CH_OP_CUR_LVL_1P5 0x0E 159#define CH_OP_CUR_LVL_1P5 0x0E
156#define CH_OP_CUR_LVL_1P6 0x0F 160#define CH_OP_CUR_LVL_1P6 0x0F
161#define CH_OP_CUR_LVL_2P 0x3F
157 162
158/* BTEMP High thermal limits */ 163/* BTEMP High thermal limits */
159#define BTEMP_HIGH_TH_57_0 0x00 164#define BTEMP_HIGH_TH_57_0 0x00
@@ -179,10 +184,25 @@
179#define BUP_ICH_SEL_300UA 0x08 184#define BUP_ICH_SEL_300UA 0x08
180#define BUP_ICH_SEL_700UA 0x0C 185#define BUP_ICH_SEL_700UA 0x0C
181 186
182#define BUP_VCH_SEL_2P5V 0x00 187enum bup_vch_sel {
183#define BUP_VCH_SEL_2P6V 0x01 188 BUP_VCH_SEL_2P5V,
184#define BUP_VCH_SEL_2P8V 0x02 189 BUP_VCH_SEL_2P6V,
185#define BUP_VCH_SEL_3P1V 0x03 190 BUP_VCH_SEL_2P8V,
191 BUP_VCH_SEL_3P1V,
192 /*
193 * Note that the following 5 values 2.7v, 2.9v, 3.0v, 3.2v, 3.3v
194 * are only available on ab8540. You can't choose these 5
195 * voltage on ab8500/ab8505/ab9540.
196 */
197 BUP_VCH_SEL_2P7V,
198 BUP_VCH_SEL_2P9V,
199 BUP_VCH_SEL_3P0V,
200 BUP_VCH_SEL_3P2V,
201 BUP_VCH_SEL_3P3V,
202};
203
204#define BUP_VCH_RANGE 0x02
205#define VBUP33_VRTCN 0x01
186 206
187/* Battery OVV constants */ 207/* Battery OVV constants */
188#define BATT_OVV_ENA 0x02 208#define BATT_OVV_ENA 0x02
@@ -228,6 +248,8 @@
228#define BAT_CTRL_20U_ENA 0x02 248#define BAT_CTRL_20U_ENA 0x02
229#define BAT_CTRL_18U_ENA 0x01 249#define BAT_CTRL_18U_ENA 0x01
230#define BAT_CTRL_16U_ENA 0x02 250#define BAT_CTRL_16U_ENA 0x02
251#define BAT_CTRL_60U_ENA 0x01
252#define BAT_CTRL_120U_ENA 0x02
231#define BAT_CTRL_CMP_ENA 0x04 253#define BAT_CTRL_CMP_ENA 0x04
232#define FORCE_BAT_CTRL_CMP_HIGH 0x08 254#define FORCE_BAT_CTRL_CMP_HIGH 0x08
233#define BAT_CTRL_PULL_UP_ENA 0x10 255#define BAT_CTRL_PULL_UP_ENA 0x10
@@ -235,6 +257,24 @@
235/* Battery type */ 257/* Battery type */
236#define BATTERY_UNKNOWN 00 258#define BATTERY_UNKNOWN 00
237 259
260/* Registers for pcut feature in ab8505 and ab9540 */
261#define AB8505_RTC_PCUT_CTL_STATUS_REG 0x12
262#define AB8505_RTC_PCUT_TIME_REG 0x13
263#define AB8505_RTC_PCUT_MAX_TIME_REG 0x14
264#define AB8505_RTC_PCUT_FLAG_TIME_REG 0x15
265#define AB8505_RTC_PCUT_RESTART_REG 0x16
266#define AB8505_RTC_PCUT_DEBOUNCE_REG 0x17
267
268/* USB Power Path constants for ab8540 */
269#define BUS_VSYS_VOL_SELECT_MASK 0x06
270#define BUS_VSYS_VOL_SELECT_3P6V 0x00
271#define BUS_VSYS_VOL_SELECT_3P325V 0x02
272#define BUS_VSYS_VOL_SELECT_3P9V 0x04
273#define BUS_VSYS_VOL_SELECT_4P3V 0x06
274#define BUS_POWER_PATH_MODE_ENA 0x01
275#define BUS_PP_PRECHG_CURRENT_MASK 0x0E
276#define BUS_POWER_PATH_PRECHG_ENA 0x01
277
238/** 278/**
239 * struct res_to_temp - defines one point in a temp to res curve. To 279 * struct res_to_temp - defines one point in a temp to res curve. To
240 * be used in battery packs that combines the identification resistor with a 280 * be used in battery packs that combines the identification resistor with a
@@ -283,6 +323,11 @@ struct ab8500_fg;
283 * points. 323 * points.
284 * @maint_thres This is the threshold where we stop reporting 324 * @maint_thres This is the threshold where we stop reporting
285 * battery full while in maintenance, in per cent 325 * battery full while in maintenance, in per cent
326 * @pcut_enable: Enable power cut feature in ab8505
327 * @pcut_max_time: Max time threshold
328 * @pcut_flag_time: Flagtime threshold
329 * @pcut_max_restart: Max number of restarts
330 * @pcut_debunce_time: Sets battery debounce time
286 */ 331 */
287struct ab8500_fg_parameters { 332struct ab8500_fg_parameters {
288 int recovery_sleep_timer; 333 int recovery_sleep_timer;
@@ -299,6 +344,11 @@ struct ab8500_fg_parameters {
299 int battok_raising_th_sel1; 344 int battok_raising_th_sel1;
300 int user_cap_limit; 345 int user_cap_limit;
301 int maint_thres; 346 int maint_thres;
347 bool pcut_enable;
348 u8 pcut_max_time;
349 u8 pcut_flag_time;
350 u8 pcut_max_restart;
351 u8 pcut_debunce_time;
302}; 352};
303 353
304/** 354/**
@@ -415,6 +465,7 @@ void ab8500_fg_reinit(void);
415void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA); 465void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
416struct ab8500_btemp *ab8500_btemp_get(void); 466struct ab8500_btemp *ab8500_btemp_get(void);
417int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp); 467int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp);
468int ab8500_btemp_get_temp(struct ab8500_btemp *btemp);
418struct ab8500_fg *ab8500_fg_get(void); 469struct ab8500_fg *ab8500_fg_get(void);
419int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev); 470int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
420int ab8500_fg_inst_curr_start(struct ab8500_fg *di); 471int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
diff --git a/include/linux/mfd/abx500/ab8500-gpadc.h b/include/linux/mfd/abx500/ab8500-gpadc.h
index 252966769d93..49ded001049b 100644
--- a/include/linux/mfd/abx500/ab8500-gpadc.h
+++ b/include/linux/mfd/abx500/ab8500-gpadc.h
@@ -4,32 +4,72 @@
4 * 4 *
5 * Author: Arun R Murthy <arun.murthy@stericsson.com> 5 * Author: Arun R Murthy <arun.murthy@stericsson.com>
6 * Author: Daniel Willerud <daniel.willerud@stericsson.com> 6 * Author: Daniel Willerud <daniel.willerud@stericsson.com>
7 * Author: M'boumba Cedric Madianga <cedric.madianga@stericsson.com>
7 */ 8 */
8 9
9#ifndef _AB8500_GPADC_H 10#ifndef _AB8500_GPADC_H
10#define _AB8500_GPADC_H 11#define _AB8500_GPADC_H
11 12
12/* GPADC source: From datasheet(ADCSwSel[4:0] in GPADCCtrl2) */ 13/* GPADC source: From datasheet(ADCSwSel[4:0] in GPADCCtrl2
13#define BAT_CTRL 0x01 14 * and ADCHwSel[4:0] in GPADCCtrl3 ) */
14#define BTEMP_BALL 0x02 15#define BAT_CTRL 0x01
15#define MAIN_CHARGER_V 0x03 16#define BTEMP_BALL 0x02
16#define ACC_DETECT1 0x04 17#define MAIN_CHARGER_V 0x03
17#define ACC_DETECT2 0x05 18#define ACC_DETECT1 0x04
18#define ADC_AUX1 0x06 19#define ACC_DETECT2 0x05
19#define ADC_AUX2 0x07 20#define ADC_AUX1 0x06
20#define MAIN_BAT_V 0x08 21#define ADC_AUX2 0x07
21#define VBUS_V 0x09 22#define MAIN_BAT_V 0x08
22#define MAIN_CHARGER_C 0x0A 23#define VBUS_V 0x09
23#define USB_CHARGER_C 0x0B 24#define MAIN_CHARGER_C 0x0A
24#define BK_BAT_V 0x0C 25#define USB_CHARGER_C 0x0B
25#define DIE_TEMP 0x0D 26#define BK_BAT_V 0x0C
27#define DIE_TEMP 0x0D
28#define USB_ID 0x0E
29#define XTAL_TEMP 0x12
30#define VBAT_TRUE_MEAS 0x13
31#define BAT_CTRL_AND_IBAT 0x1C
32#define VBAT_MEAS_AND_IBAT 0x1D
33#define VBAT_TRUE_MEAS_AND_IBAT 0x1E
34#define BAT_TEMP_AND_IBAT 0x1F
35
36/* Virtual channel used only for ibat convertion to ampere
37 * Battery current conversion (ibat) cannot be requested as a single conversion
38 * but it is always in combination with other input requests
39 */
40#define IBAT_VIRTUAL_CHANNEL 0xFF
41
42#define SAMPLE_1 1
43#define SAMPLE_4 4
44#define SAMPLE_8 8
45#define SAMPLE_16 16
46#define RISING_EDGE 0
47#define FALLING_EDGE 1
48
49/* Arbitrary ADC conversion type constants */
50#define ADC_SW 0
51#define ADC_HW 1
26 52
27struct ab8500_gpadc; 53struct ab8500_gpadc;
28 54
29struct ab8500_gpadc *ab8500_gpadc_get(char *name); 55struct ab8500_gpadc *ab8500_gpadc_get(char *name);
30int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel); 56int ab8500_gpadc_sw_hw_convert(struct ab8500_gpadc *gpadc, u8 channel,
31int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel); 57 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type);
58static inline int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel)
59{
60 return ab8500_gpadc_sw_hw_convert(gpadc, channel,
61 SAMPLE_16, 0, 0, ADC_SW);
62}
63
64int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
65 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type);
66int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
67 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type,
68 int *ibat);
32int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, 69int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc,
33 u8 channel, int ad_value); 70 u8 channel, int ad_value);
71void ab8540_gpadc_get_otp(struct ab8500_gpadc *gpadc,
72 u16 *vmain_l, u16 *vmain_h, u16 *btemp_l, u16 *btemp_h,
73 u16 *vbat_l, u16 *vbat_h, u16 *ibat_l, u16 *ibat_h);
34 74
35#endif /* _AB8500_GPADC_H */ 75#endif /* _AB8500_GPADC_H */
diff --git a/include/linux/mfd/abx500/ab8500-sysctrl.h b/include/linux/mfd/abx500/ab8500-sysctrl.h
index ebf12e793db9..990bc93f46e1 100644
--- a/include/linux/mfd/abx500/ab8500-sysctrl.h
+++ b/include/linux/mfd/abx500/ab8500-sysctrl.h
@@ -12,6 +12,7 @@
12 12
13int ab8500_sysctrl_read(u16 reg, u8 *value); 13int ab8500_sysctrl_read(u16 reg, u8 *value);
14int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value); 14int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value);
15void ab8500_restart(char mode, const char *cmd);
15 16
16#else 17#else
17 18
@@ -40,6 +41,7 @@ static inline int ab8500_sysctrl_clear(u16 reg, u8 bits)
40/* Configuration data for SysClkReq1RfClkBuf - SysClkReq8RfClkBuf */ 41/* Configuration data for SysClkReq1RfClkBuf - SysClkReq8RfClkBuf */
41struct ab8500_sysctrl_platform_data { 42struct ab8500_sysctrl_platform_data {
42 u8 initial_req_buf_config[8]; 43 u8 initial_req_buf_config[8];
44 u16 (*reboot_reason_code)(const char *cmd);
43}; 45};
44 46
45/* Registers */ 47/* Registers */
@@ -299,4 +301,8 @@ struct ab8500_sysctrl_platform_data {
299#define AB9540_SYSCLK12BUF4VALID_SYSCLK12BUF4VALID_MASK 0xFF 301#define AB9540_SYSCLK12BUF4VALID_SYSCLK12BUF4VALID_MASK 0xFF
300#define AB9540_SYSCLK12BUF4VALID_SYSCLK12BUF4VALID_SHIFT 0 302#define AB9540_SYSCLK12BUF4VALID_SYSCLK12BUF4VALID_SHIFT 0
301 303
304#define AB8500_ENABLE_WD 0x1
305#define AB8500_KICK_WD 0x2
306#define AB8500_WD_RESTART_ON_EXPIRE 0x10
307
302#endif /* __AB8500_SYSCTRL_H */ 308#endif /* __AB8500_SYSCTRL_H */
diff --git a/include/linux/mfd/abx500/ab8500.h b/include/linux/mfd/abx500/ab8500.h
index 84f449475c25..fb1bf7d6a410 100644
--- a/include/linux/mfd/abx500/ab8500.h
+++ b/include/linux/mfd/abx500/ab8500.h
@@ -362,6 +362,7 @@ struct ab8500 {
362 u8 *oldmask; 362 u8 *oldmask;
363 int mask_size; 363 int mask_size;
364 const int *irq_reg_offset; 364 const int *irq_reg_offset;
365 int it_latchhier_num;
365}; 366};
366 367
367struct ab8500_regulator_platform_data; 368struct ab8500_regulator_platform_data;
@@ -505,6 +506,8 @@ static inline int is_ab9540_2p0_or_earlier(struct ab8500 *ab)
505 return (is_ab9540(ab) && (ab->chip_id < AB8500_CUT2P0)); 506 return (is_ab9540(ab) && (ab->chip_id < AB8500_CUT2P0));
506} 507}
507 508
509void ab8500_override_turn_on_stat(u8 mask, u8 set);
510
508#ifdef CONFIG_AB8500_DEBUG 511#ifdef CONFIG_AB8500_DEBUG
509void ab8500_dump_all_banks(struct device *dev); 512void ab8500_dump_all_banks(struct device *dev);
510void ab8500_debug_register_interrupt(int line); 513void ab8500_debug_register_interrupt(int line);
diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
index d43ac0f35526..234c99143bf7 100644
--- a/include/linux/mfd/abx500/ux500_chargalg.h
+++ b/include/linux/mfd/abx500/ux500_chargalg.h
@@ -17,8 +17,11 @@ struct ux500_charger;
17 17
18struct ux500_charger_ops { 18struct ux500_charger_ops {
19 int (*enable) (struct ux500_charger *, int, int, int); 19 int (*enable) (struct ux500_charger *, int, int, int);
20 int (*check_enable) (struct ux500_charger *, int, int);
20 int (*kick_wd) (struct ux500_charger *); 21 int (*kick_wd) (struct ux500_charger *);
21 int (*update_curr) (struct ux500_charger *, int); 22 int (*update_curr) (struct ux500_charger *, int);
23 int (*pp_enable) (struct ux500_charger *, bool);
24 int (*pre_chg_enable) (struct ux500_charger *, bool);
22}; 25};
23 26
24/** 27/**
@@ -29,6 +32,7 @@ struct ux500_charger_ops {
29 * @max_out_curr maximum output charger current in mA 32 * @max_out_curr maximum output charger current in mA
30 * @enabled indicates if this charger is used or not 33 * @enabled indicates if this charger is used or not
31 * @external external charger unit (pm2xxx) 34 * @external external charger unit (pm2xxx)
35 * @power_path USB power path support
32 */ 36 */
33struct ux500_charger { 37struct ux500_charger {
34 struct power_supply psy; 38 struct power_supply psy;
@@ -38,6 +42,9 @@ struct ux500_charger {
38 int wdt_refresh; 42 int wdt_refresh;
39 bool enabled; 43 bool enabled;
40 bool external; 44 bool external;
45 bool power_path;
41}; 46};
42 47
48extern struct blocking_notifier_head charger_notifier_list;
49
43#endif 50#endif
diff --git a/include/linux/mfd/tps65090.h b/include/linux/mfd/tps65090.h
index 6694cf43e8b8..998628a2b08b 100644
--- a/include/linux/mfd/tps65090.h
+++ b/include/linux/mfd/tps65090.h
@@ -86,6 +86,11 @@ struct tps65090_regulator_plat_data {
86 86
87struct tps65090_platform_data { 87struct tps65090_platform_data {
88 int irq_base; 88 int irq_base;
89
90 char **supplied_to;
91 size_t num_supplicants;
92 int enable_low_current_chrg;
93
89 struct tps65090_regulator_plat_data *reg_pdata[TPS65090_REGULATOR_MAX]; 94 struct tps65090_regulator_plat_data *reg_pdata[TPS65090_REGULATOR_MAX];
90}; 95};
91 96
diff --git a/include/linux/pm2301_charger.h b/include/linux/pm2301_charger.h
index fc3f026922ae..85c16defe11a 100644
--- a/include/linux/pm2301_charger.h
+++ b/include/linux/pm2301_charger.h
@@ -48,7 +48,7 @@ struct pm2xxx_charger_platform_data {
48 size_t num_supplicants; 48 size_t num_supplicants;
49 int i2c_bus; 49 int i2c_bus;
50 const char *label; 50 const char *label;
51 int irq_number; 51 int gpio_irq_number;
52 unsigned int lpn_gpio; 52 unsigned int lpn_gpio;
53 int irq_type; 53 int irq_type;
54}; 54};
diff --git a/include/linux/power/ab8500.h b/include/linux/power/ab8500.h
new file mode 100644
index 000000000000..cdbb6c2a8c51
--- /dev/null
+++ b/include/linux/power/ab8500.h
@@ -0,0 +1,16 @@
1/*
2 * Copyright (C) ST-Ericsson 2013
3 * Author: Hongbo Zhang <hongbo.zhang@linaro.com>
4 * License terms: GNU General Public License v2
5 */
6
7#ifndef PWR_AB8500_H
8#define PWR_AB8500_H
9
10extern const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[];
11extern const int ab8500_temp_tbl_a_size;
12
13extern const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[];
14extern const int ab8500_temp_tbl_b_size;
15
16#endif /* PWR_AB8500_H */
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 002a99f96331..3828cefb4f65 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -171,6 +171,12 @@ struct power_supply {
171 char **supplied_to; 171 char **supplied_to;
172 size_t num_supplicants; 172 size_t num_supplicants;
173 173
174 char **supplied_from;
175 size_t num_supplies;
176#ifdef CONFIG_OF
177 struct device_node *of_node;
178#endif
179
174 int (*get_property)(struct power_supply *psy, 180 int (*get_property)(struct power_supply *psy,
175 enum power_supply_property psp, 181 enum power_supply_property psp,
176 union power_supply_propval *val); 182 union power_supply_propval *val);
diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
index 75818744ab59..ea7168a68081 100644
--- a/include/linux/vexpress.h
+++ b/include/linux/vexpress.h
@@ -115,9 +115,6 @@ unsigned __vexpress_get_site(struct device *dev, struct device_node *node);
115void vexpress_sysreg_early_init(void __iomem *base); 115void vexpress_sysreg_early_init(void __iomem *base);
116void vexpress_sysreg_of_early_init(void); 116void vexpress_sysreg_of_early_init(void);
117 117
118void vexpress_power_off(void);
119void vexpress_restart(char str, const char *cmd);
120
121/* Clocks */ 118/* Clocks */
122 119
123struct clk *vexpress_osc_setup(struct device *dev); 120struct clk *vexpress_osc_setup(struct device *dev);