aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-11-02 19:07:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-02 19:07:27 -0400
commit092f4c56c1927e4b61a41ee8055005f1cb437009 (patch)
tree616ceb54b7671ccc13922ae9e002b8b972f6e09e /drivers/power
parent80c2861672bbf000f6af838656959ee937e4ee4d (diff)
parentc1e2ee2dc436574880758b3836fc96935b774c32 (diff)
Merge branch 'akpm' (Andrew's incoming - part two)
Says Andrew: "60 patches. That's good enough for -rc1 I guess. I have quite a lot of detritus to be rechecked, work through maintainers, etc. - most of the remains of MM - rtc - various misc - cgroups - memcg - cpusets - procfs - ipc - rapidio - sysctl - pps - w1 - drivers/misc - aio" * akpm: (60 commits) memcg: replace ss->id_lock with a rwlock aio: allocate kiocbs in batches drivers/misc/vmw_balloon.c: fix typo in code comment drivers/misc/vmw_balloon.c: determine page allocation flag can_sleep outside loop w1: disable irqs in critical section drivers/w1/w1_int.c: multiple masters used same init_name drivers/power/ds2780_battery.c: fix deadlock upon insertion and removal drivers/power/ds2780_battery.c: add a nolock function to w1 interface drivers/power/ds2780_battery.c: create central point for calling w1 interface w1: ds2760 and ds2780, use ida for id and ida_simple_get() to get it pps gpio client: add missing dependency pps: new client driver using GPIO pps: default echo function include/linux/dma-mapping.h: add dma_zalloc_coherent() sysctl: make CONFIG_SYSCTL_SYSCALL default to n sysctl: add support for poll() RapidIO: documentation update drivers/net/rionet.c: fix ethernet address macros for LE platforms RapidIO: fix potential null deref in rio_setup_device() RapidIO: add mport driver for Tsi721 bridge ...
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/ds2780_battery.c86
1 files changed, 51 insertions, 35 deletions
diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index 1fefe82e12e3..91a783d72360 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -39,6 +39,7 @@ struct ds2780_device_info {
39 struct device *dev; 39 struct device *dev;
40 struct power_supply bat; 40 struct power_supply bat;
41 struct device *w1_dev; 41 struct device *w1_dev;
42 struct task_struct *mutex_holder;
42}; 43};
43 44
44enum current_types { 45enum current_types {
@@ -49,8 +50,8 @@ enum current_types {
49static const char model[] = "DS2780"; 50static const char model[] = "DS2780";
50static const char manufacturer[] = "Maxim/Dallas"; 51static const char manufacturer[] = "Maxim/Dallas";
51 52
52static inline struct ds2780_device_info *to_ds2780_device_info( 53static inline struct ds2780_device_info *
53 struct power_supply *psy) 54to_ds2780_device_info(struct power_supply *psy)
54{ 55{
55 return container_of(psy, struct ds2780_device_info, bat); 56 return container_of(psy, struct ds2780_device_info, bat);
56} 57}
@@ -60,17 +61,28 @@ static inline struct power_supply *to_power_supply(struct device *dev)
60 return dev_get_drvdata(dev); 61 return dev_get_drvdata(dev);
61} 62}
62 63
63static inline int ds2780_read8(struct device *dev, u8 *val, int addr) 64static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
65 char *buf, int addr, size_t count, int io)
64{ 66{
65 return w1_ds2780_io(dev, val, addr, sizeof(u8), 0); 67 if (dev_info->mutex_holder == current)
68 return w1_ds2780_io_nolock(dev_info->w1_dev, buf, addr, count, io);
69 else
70 return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
71}
72
73static inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
74 int addr)
75{
76 return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
66} 77}
67 78
68static int ds2780_read16(struct device *dev, s16 *val, int addr) 79static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
80 int addr)
69{ 81{
70 int ret; 82 int ret;
71 u8 raw[2]; 83 u8 raw[2];
72 84
73 ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0); 85 ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
74 if (ret < 0) 86 if (ret < 0)
75 return ret; 87 return ret;
76 88
@@ -79,16 +91,16 @@ static int ds2780_read16(struct device *dev, s16 *val, int addr)
79 return 0; 91 return 0;
80} 92}
81 93
82static inline int ds2780_read_block(struct device *dev, u8 *val, int addr, 94static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
83 size_t count) 95 u8 *val, int addr, size_t count)
84{ 96{
85 return w1_ds2780_io(dev, val, addr, count, 0); 97 return ds2780_battery_io(dev_info, val, addr, count, 0);
86} 98}
87 99
88static inline int ds2780_write(struct device *dev, u8 *val, int addr, 100static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
89 size_t count) 101 int addr, size_t count)
90{ 102{
91 return w1_ds2780_io(dev, val, addr, count, 1); 103 return ds2780_battery_io(dev_info, val, addr, count, 1);
92} 104}
93 105
94static inline int ds2780_store_eeprom(struct device *dev, int addr) 106static inline int ds2780_store_eeprom(struct device *dev, int addr)
@@ -122,7 +134,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
122{ 134{
123 int ret; 135 int ret;
124 136
125 ret = ds2780_write(dev_info->w1_dev, &conductance, 137 ret = ds2780_write(dev_info, &conductance,
126 DS2780_RSNSP_REG, sizeof(u8)); 138 DS2780_RSNSP_REG, sizeof(u8));
127 if (ret < 0) 139 if (ret < 0)
128 return ret; 140 return ret;
@@ -134,7 +146,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
134static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info, 146static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
135 u16 *rsgain) 147 u16 *rsgain)
136{ 148{
137 return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG); 149 return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
138} 150}
139 151
140/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */ 152/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
@@ -144,8 +156,8 @@ static int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info,
144 int ret; 156 int ret;
145 u8 raw[] = {rsgain >> 8, rsgain & 0xFF}; 157 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
146 158
147 ret = ds2780_write(dev_info->w1_dev, raw, 159 ret = ds2780_write(dev_info, raw,
148 DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2); 160 DS2780_RSGAIN_MSB_REG, sizeof(raw));
149 if (ret < 0) 161 if (ret < 0)
150 return ret; 162 return ret;
151 163
@@ -167,7 +179,7 @@ static int ds2780_get_voltage(struct ds2780_device_info *dev_info,
167 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the 179 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
168 * voltage LSB register 180 * voltage LSB register
169 */ 181 */
170 ret = ds2780_read16(dev_info->w1_dev, &voltage_raw, 182 ret = ds2780_read16(dev_info, &voltage_raw,
171 DS2780_VOLT_MSB_REG); 183 DS2780_VOLT_MSB_REG);
172 if (ret < 0) 184 if (ret < 0)
173 return ret; 185 return ret;
@@ -196,7 +208,7 @@ static int ds2780_get_temperature(struct ds2780_device_info *dev_info,
196 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the 208 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
197 * temperature LSB register 209 * temperature LSB register
198 */ 210 */
199 ret = ds2780_read16(dev_info->w1_dev, &temperature_raw, 211 ret = ds2780_read16(dev_info, &temperature_raw,
200 DS2780_TEMP_MSB_REG); 212 DS2780_TEMP_MSB_REG);
201 if (ret < 0) 213 if (ret < 0)
202 return ret; 214 return ret;
@@ -222,13 +234,13 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info,
222 * The units of measurement for current are dependent on the value of 234 * The units of measurement for current are dependent on the value of
223 * the sense resistor. 235 * the sense resistor.
224 */ 236 */
225 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 237 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
226 if (ret < 0) 238 if (ret < 0)
227 return ret; 239 return ret;
228 240
229 if (sense_res_raw == 0) { 241 if (sense_res_raw == 0) {
230 dev_err(dev_info->dev, "sense resistor value is 0\n"); 242 dev_err(dev_info->dev, "sense resistor value is 0\n");
231 return -ENXIO; 243 return -EINVAL;
232 } 244 }
233 sense_res = 1000 / sense_res_raw; 245 sense_res = 1000 / sense_res_raw;
234 246
@@ -248,7 +260,7 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info,
248 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current 260 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
249 * LSB register 261 * LSB register
250 */ 262 */
251 ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb); 263 ret = ds2780_read16(dev_info, &current_raw, reg_msb);
252 if (ret < 0) 264 if (ret < 0)
253 return ret; 265 return ret;
254 266
@@ -267,7 +279,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
267 * The units of measurement for accumulated current are dependent on 279 * The units of measurement for accumulated current are dependent on
268 * the value of the sense resistor. 280 * the value of the sense resistor.
269 */ 281 */
270 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 282 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
271 if (ret < 0) 283 if (ret < 0)
272 return ret; 284 return ret;
273 285
@@ -285,7 +297,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
285 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR 297 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
286 * LSB register 298 * LSB register
287 */ 299 */
288 ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG); 300 ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
289 if (ret < 0) 301 if (ret < 0)
290 return ret; 302 return ret;
291 303
@@ -299,7 +311,7 @@ static int ds2780_get_capacity(struct ds2780_device_info *dev_info,
299 int ret; 311 int ret;
300 u8 raw; 312 u8 raw;
301 313
302 ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG); 314 ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
303 if (ret < 0) 315 if (ret < 0)
304 return ret; 316 return ret;
305 317
@@ -345,7 +357,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
345 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC 357 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
346 * LSB register 358 * LSB register
347 */ 359 */
348 ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG); 360 ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
349 if (ret < 0) 361 if (ret < 0)
350 return ret; 362 return ret;
351 363
@@ -356,7 +368,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
356static int ds2780_get_control_register(struct ds2780_device_info *dev_info, 368static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
357 u8 *control_reg) 369 u8 *control_reg)
358{ 370{
359 return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG); 371 return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
360} 372}
361 373
362static int ds2780_set_control_register(struct ds2780_device_info *dev_info, 374static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
@@ -364,7 +376,7 @@ static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
364{ 376{
365 int ret; 377 int ret;
366 378
367 ret = ds2780_write(dev_info->w1_dev, &control_reg, 379 ret = ds2780_write(dev_info, &control_reg,
368 DS2780_CONTROL_REG, sizeof(u8)); 380 DS2780_CONTROL_REG, sizeof(u8));
369 if (ret < 0) 381 if (ret < 0)
370 return ret; 382 return ret;
@@ -503,7 +515,7 @@ static ssize_t ds2780_get_sense_resistor_value(struct device *dev,
503 struct power_supply *psy = to_power_supply(dev); 515 struct power_supply *psy = to_power_supply(dev);
504 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 516 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
505 517
506 ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG); 518 ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
507 if (ret < 0) 519 if (ret < 0)
508 return ret; 520 return ret;
509 521
@@ -584,7 +596,7 @@ static ssize_t ds2780_get_pio_pin(struct device *dev,
584 struct power_supply *psy = to_power_supply(dev); 596 struct power_supply *psy = to_power_supply(dev);
585 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 597 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
586 598
587 ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG); 599 ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
588 if (ret < 0) 600 if (ret < 0)
589 return ret; 601 return ret;
590 602
@@ -611,7 +623,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev,
611 return -EINVAL; 623 return -EINVAL;
612 } 624 }
613 625
614 ret = ds2780_write(dev_info->w1_dev, &new_setting, 626 ret = ds2780_write(dev_info, &new_setting,
615 DS2780_SFR_REG, sizeof(u8)); 627 DS2780_SFR_REG, sizeof(u8));
616 if (ret < 0) 628 if (ret < 0)
617 return ret; 629 return ret;
@@ -632,7 +644,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
632 DS2780_EEPROM_BLOCK1_END - 644 DS2780_EEPROM_BLOCK1_END -
633 DS2780_EEPROM_BLOCK1_START + 1 - off); 645 DS2780_EEPROM_BLOCK1_START + 1 - off);
634 646
635 return ds2780_read_block(dev_info->w1_dev, buf, 647 return ds2780_read_block(dev_info, buf,
636 DS2780_EEPROM_BLOCK1_START + off, count); 648 DS2780_EEPROM_BLOCK1_START + off, count);
637} 649}
638 650
@@ -650,7 +662,7 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
650 DS2780_EEPROM_BLOCK1_END - 662 DS2780_EEPROM_BLOCK1_END -
651 DS2780_EEPROM_BLOCK1_START + 1 - off); 663 DS2780_EEPROM_BLOCK1_START + 1 - off);
652 664
653 ret = ds2780_write(dev_info->w1_dev, buf, 665 ret = ds2780_write(dev_info, buf,
654 DS2780_EEPROM_BLOCK1_START + off, count); 666 DS2780_EEPROM_BLOCK1_START + off, count);
655 if (ret < 0) 667 if (ret < 0)
656 return ret; 668 return ret;
@@ -685,9 +697,8 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
685 DS2780_EEPROM_BLOCK0_END - 697 DS2780_EEPROM_BLOCK0_END -
686 DS2780_EEPROM_BLOCK0_START + 1 - off); 698 DS2780_EEPROM_BLOCK0_START + 1 - off);
687 699
688 return ds2780_read_block(dev_info->w1_dev, buf, 700 return ds2780_read_block(dev_info, buf,
689 DS2780_EEPROM_BLOCK0_START + off, count); 701 DS2780_EEPROM_BLOCK0_START + off, count);
690
691} 702}
692 703
693static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, 704static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
@@ -704,7 +715,7 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
704 DS2780_EEPROM_BLOCK0_END - 715 DS2780_EEPROM_BLOCK0_END -
705 DS2780_EEPROM_BLOCK0_START + 1 - off); 716 DS2780_EEPROM_BLOCK0_START + 1 - off);
706 717
707 ret = ds2780_write(dev_info->w1_dev, buf, 718 ret = ds2780_write(dev_info, buf,
708 DS2780_EEPROM_BLOCK0_START + off, count); 719 DS2780_EEPROM_BLOCK0_START + off, count);
709 if (ret < 0) 720 if (ret < 0)
710 return ret; 721 return ret;
@@ -768,6 +779,7 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev)
768 dev_info->bat.properties = ds2780_battery_props; 779 dev_info->bat.properties = ds2780_battery_props;
769 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props); 780 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props);
770 dev_info->bat.get_property = ds2780_battery_get_property; 781 dev_info->bat.get_property = ds2780_battery_get_property;
782 dev_info->mutex_holder = current;
771 783
772 ret = power_supply_register(&pdev->dev, &dev_info->bat); 784 ret = power_supply_register(&pdev->dev, &dev_info->bat);
773 if (ret) { 785 if (ret) {
@@ -797,6 +809,8 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev)
797 goto fail_remove_bin_file; 809 goto fail_remove_bin_file;
798 } 810 }
799 811
812 dev_info->mutex_holder = NULL;
813
800 return 0; 814 return 0;
801 815
802fail_remove_bin_file: 816fail_remove_bin_file:
@@ -816,6 +830,8 @@ static int __devexit ds2780_battery_remove(struct platform_device *pdev)
816{ 830{
817 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev); 831 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
818 832
833 dev_info->mutex_holder = current;
834
819 /* remove attributes */ 835 /* remove attributes */
820 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 836 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
821 837