diff options
Diffstat (limited to 'drivers/power/jz4740-battery.c')
-rw-r--r-- | drivers/power/jz4740-battery.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c index a8108a73593e..02414db6a94c 100644 --- a/drivers/power/jz4740-battery.c +++ b/drivers/power/jz4740-battery.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/io.h> | ||
22 | 23 | ||
23 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
24 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
@@ -47,6 +48,8 @@ struct jz_battery { | |||
47 | 48 | ||
48 | struct power_supply battery; | 49 | struct power_supply battery; |
49 | struct delayed_work work; | 50 | struct delayed_work work; |
51 | |||
52 | struct mutex lock; | ||
50 | }; | 53 | }; |
51 | 54 | ||
52 | static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) | 55 | static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) |
@@ -68,6 +71,8 @@ static long jz_battery_read_voltage(struct jz_battery *battery) | |||
68 | unsigned long val; | 71 | unsigned long val; |
69 | long voltage; | 72 | long voltage; |
70 | 73 | ||
74 | mutex_lock(&battery->lock); | ||
75 | |||
71 | INIT_COMPLETION(battery->read_completion); | 76 | INIT_COMPLETION(battery->read_completion); |
72 | 77 | ||
73 | enable_irq(battery->irq); | 78 | enable_irq(battery->irq); |
@@ -91,6 +96,8 @@ static long jz_battery_read_voltage(struct jz_battery *battery) | |||
91 | battery->cell->disable(battery->pdev); | 96 | battery->cell->disable(battery->pdev); |
92 | disable_irq(battery->irq); | 97 | disable_irq(battery->irq); |
93 | 98 | ||
99 | mutex_unlock(&battery->lock); | ||
100 | |||
94 | return voltage; | 101 | return voltage; |
95 | } | 102 | } |
96 | 103 | ||
@@ -240,6 +247,11 @@ static int __devinit jz_battery_probe(struct platform_device *pdev) | |||
240 | struct jz_battery *jz_battery; | 247 | struct jz_battery *jz_battery; |
241 | struct power_supply *battery; | 248 | struct power_supply *battery; |
242 | 249 | ||
250 | if (!pdata) { | ||
251 | dev_err(&pdev->dev, "No platform_data supplied\n"); | ||
252 | return -ENXIO; | ||
253 | } | ||
254 | |||
243 | jz_battery = kzalloc(sizeof(*jz_battery), GFP_KERNEL); | 255 | jz_battery = kzalloc(sizeof(*jz_battery), GFP_KERNEL); |
244 | if (!jz_battery) { | 256 | if (!jz_battery) { |
245 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); | 257 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); |
@@ -291,6 +303,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev) | |||
291 | jz_battery->pdev = pdev; | 303 | jz_battery->pdev = pdev; |
292 | 304 | ||
293 | init_completion(&jz_battery->read_completion); | 305 | init_completion(&jz_battery->read_completion); |
306 | mutex_init(&jz_battery->lock); | ||
294 | 307 | ||
295 | INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work); | 308 | INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work); |
296 | 309 | ||