summaryrefslogtreecommitdiff
path: root/recipes/linux/linux-rp-2.6.24/tosa/0062-tosa-bat-fix-charging.patch
blob: e3a6b7477232ad58c0549c147030a94f1d1958a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 0b9f80ab540b2e51f6e86f6a1adec67761f9368d Mon Sep 17 00:00:00 2001
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
Date: Fri, 8 Feb 2008 00:50:03 +0300
Subject: [PATCH 62/64] tosa-bat-fix-charging

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
 drivers/power/tosa_battery.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/power/tosa_battery.c b/drivers/power/tosa_battery.c
index 008e791..2db9116 100644
--- a/drivers/power/tosa_battery.c
+++ b/drivers/power/tosa_battery.c
@@ -153,39 +153,53 @@ static irqreturn_t tosa_bat_full_isr(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+static char *status_text[] = {
+	[POWER_SUPPLY_STATUS_UNKNOWN] =		"Unknown",
+	[POWER_SUPPLY_STATUS_CHARGING] =	"Charging",
+	[POWER_SUPPLY_STATUS_DISCHARGING] =	"Discharging",
+	[POWER_SUPPLY_STATUS_NOT_CHARGING] =	"Not charging",
+	[POWER_SUPPLY_STATUS_FULL] =		"Full",
+};
+
 static void tosa_bat_update(struct tosa_bat *bat)
 {
-	int old = bat->status;
+	int old;
 	struct power_supply *psy = &bat->psy;
 
 	mutex_lock(&bat->work_lock);
 
+	old = bat->status;
+
 	if (bat->is_present && !bat->is_present(bat)) {
-		printk(KERN_DEBUG "%s not present\n", psy->name);
+		printk(KERN_NOTICE "%s not present\n", psy->name);
 		bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
 		bat->full_chrg = -1;
 	} else if (power_supply_am_i_supplied(psy)) {
+		if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) {
+			gpio_set_value(bat->gpio_charge_off, 0);
+			mdelay(15);
+		}
 		if (gpio_get_value(bat->gpio_full)) {
-			printk(KERN_DEBUG "%s full\n", psy->name);
-
 			if (old == POWER_SUPPLY_STATUS_CHARGING || bat->full_chrg == -1)
 				bat->full_chrg = tosa_read_bat(bat);
 
 			gpio_set_value(bat->gpio_charge_off, 1);
 			bat->status = POWER_SUPPLY_STATUS_FULL;
 		} else {
-			printk(KERN_ERR "%s charge\n", psy->name);
 			gpio_set_value(bat->gpio_charge_off, 0);
 			bat->status = POWER_SUPPLY_STATUS_CHARGING;
 		}
 	} else {
-		printk(KERN_ERR "%s discharge\n", psy->name);
 		gpio_set_value(bat->gpio_charge_off, 1);
 		bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
 	}
 
-	if (old != bat->status)
+	if (old != bat->status) {
+		printk(KERN_NOTICE "%s %s -> %s\n", psy->name,
+				status_text[old],
+				status_text[bat->status]);
 		power_supply_changed(psy);
+	}
 
 	mutex_unlock(&bat->work_lock);
 }
-- 
1.5.3.8