947c6711c35d1b519f977273746c20b141b3e1e0
[openwrt/staging/mkresin.git] / target / linux / xburst / patches-2.6.37 / 300-battery-fixes.patch
1 --- a/drivers/power/jz4740-battery.c
2 +++ b/drivers/power/jz4740-battery.c
3 @@ -47,6 +47,8 @@ struct jz_battery {
4
5 struct power_supply battery;
6 struct delayed_work work;
7 +
8 + struct mutex lock;
9 };
10
11 static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy)
12 @@ -68,6 +70,8 @@ static long jz_battery_read_voltage(stru
13 unsigned long val;
14 long voltage;
15
16 + mutex_lock(&battery->lock);
17 +
18 INIT_COMPLETION(battery->read_completion);
19
20 enable_irq(battery->irq);
21 @@ -91,6 +95,8 @@ static long jz_battery_read_voltage(stru
22 battery->cell->disable(battery->pdev);
23 disable_irq(battery->irq);
24
25 + mutex_unlock(&battery->lock);
26 +
27 return voltage;
28 }
29
30 @@ -240,6 +246,11 @@ static int __devinit jz_battery_probe(st
31 struct jz_battery *jz_battery;
32 struct power_supply *battery;
33
34 + if (!pdata) {
35 + dev_err(&pdev->dev, "No platform_data supplied\n");
36 + return -ENXIO;
37 + }
38 +
39 jz_battery = kzalloc(sizeof(*jz_battery), GFP_KERNEL);
40 if (!jz_battery) {
41 dev_err(&pdev->dev, "Failed to allocate driver structure\n");
42 @@ -291,6 +302,7 @@ static int __devinit jz_battery_probe(st
43 jz_battery->pdev = pdev;
44
45 init_completion(&jz_battery->read_completion);
46 + mutex_init(&jz_battery->lock);
47
48 INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work);
49