aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/ds2780_battery.c
diff options
context:
space:
mode:
authorClifton Barnes <cabarnes@indesign-llc.com>2011-11-02 16:39:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-02 19:07:02 -0400
commit853eee72f74f449797f0500ea19fc1bf497428d8 (patch)
treedf2716ad2fce874ce10529d0bba28188dd608aa9 /drivers/power/ds2780_battery.c
parent3e5428177c74df7f3b8c59b2f27f46b82b077e94 (diff)
drivers/power/ds2780_battery.c: create central point for calling w1 interface
Simply creates one point to call the w1 interface. Signed-off-by: Clifton Barnes <cabarnes@indesign-llc.com> Cc: Evgeniy Polyakov <zbr@ioremap.net> Cc: <stable@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/power/ds2780_battery.c')
-rw-r--r--drivers/power/ds2780_battery.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index 1fefe82e12e3..2571b4143784 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -49,8 +49,8 @@ enum current_types {
49static const char model[] = "DS2780"; 49static const char model[] = "DS2780";
50static const char manufacturer[] = "Maxim/Dallas"; 50static const char manufacturer[] = "Maxim/Dallas";
51 51
52static inline struct ds2780_device_info *to_ds2780_device_info( 52static inline struct ds2780_device_info *
53 struct power_supply *psy) 53to_ds2780_device_info(struct power_supply *psy)
54{ 54{
55 return container_of(psy, struct ds2780_device_info, bat); 55 return container_of(psy, struct ds2780_device_info, bat);
56} 56}
@@ -60,17 +60,25 @@ static inline struct power_supply *to_power_supply(struct device *dev)
60 return dev_get_drvdata(dev); 60 return dev_get_drvdata(dev);
61} 61}
62 62
63static inline int ds2780_read8(struct device *dev, u8 *val, int addr) 63static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
64 char *buf, int addr, size_t count, int io)
64{ 65{
65 return w1_ds2780_io(dev, val, addr, sizeof(u8), 0); 66 return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
66} 67}
67 68
68static int ds2780_read16(struct device *dev, s16 *val, int addr) 69static inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
70 int addr)
71{
72 return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
73}
74
75static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
76 int addr)
69{ 77{
70 int ret; 78 int ret;
71 u8 raw[2]; 79 u8 raw[2];
72 80
73 ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0); 81 ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
74 if (ret < 0) 82 if (ret < 0)
75 return ret; 83 return ret;
76 84
@@ -79,16 +87,16 @@ static int ds2780_read16(struct device *dev, s16 *val, int addr)
79 return 0; 87 return 0;
80} 88}
81 89
82static inline int ds2780_read_block(struct device *dev, u8 *val, int addr, 90static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
83 size_t count) 91 u8 *val, int addr, size_t count)
84{ 92{
85 return w1_ds2780_io(dev, val, addr, count, 0); 93 return ds2780_battery_io(dev_info, val, addr, count, 0);
86} 94}
87 95
88static inline int ds2780_write(struct device *dev, u8 *val, int addr, 96static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
89 size_t count) 97 int addr, size_t count)
90{ 98{
91 return w1_ds2780_io(dev, val, addr, count, 1); 99 return ds2780_battery_io(dev_info, val, addr, count, 1);
92} 100}
93 101
94static inline int ds2780_store_eeprom(struct device *dev, int addr) 102static inline int ds2780_store_eeprom(struct device *dev, int addr)
@@ -122,7 +130,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
122{ 130{
123 int ret; 131 int ret;
124 132
125 ret = ds2780_write(dev_info->w1_dev, &conductance, 133 ret = ds2780_write(dev_info, &conductance,
126 DS2780_RSNSP_REG, sizeof(u8)); 134 DS2780_RSNSP_REG, sizeof(u8));
127 if (ret < 0) 135 if (ret < 0)
128 return ret; 136 return ret;
@@ -134,7 +142,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, 142static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
135 u16 *rsgain) 143 u16 *rsgain)
136{ 144{
137 return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG); 145 return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
138} 146}
139 147
140/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */ 148/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
@@ -144,8 +152,8 @@ static int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info,
144 int ret; 152 int ret;
145 u8 raw[] = {rsgain >> 8, rsgain & 0xFF}; 153 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
146 154
147 ret = ds2780_write(dev_info->w1_dev, raw, 155 ret = ds2780_write(dev_info, raw,
148 DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2); 156 DS2780_RSGAIN_MSB_REG, sizeof(raw));
149 if (ret < 0) 157 if (ret < 0)
150 return ret; 158 return ret;
151 159
@@ -167,7 +175,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 175 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
168 * voltage LSB register 176 * voltage LSB register
169 */ 177 */
170 ret = ds2780_read16(dev_info->w1_dev, &voltage_raw, 178 ret = ds2780_read16(dev_info, &voltage_raw,
171 DS2780_VOLT_MSB_REG); 179 DS2780_VOLT_MSB_REG);
172 if (ret < 0) 180 if (ret < 0)
173 return ret; 181 return ret;
@@ -196,7 +204,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 204 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
197 * temperature LSB register 205 * temperature LSB register
198 */ 206 */
199 ret = ds2780_read16(dev_info->w1_dev, &temperature_raw, 207 ret = ds2780_read16(dev_info, &temperature_raw,
200 DS2780_TEMP_MSB_REG); 208 DS2780_TEMP_MSB_REG);
201 if (ret < 0) 209 if (ret < 0)
202 return ret; 210 return ret;
@@ -222,13 +230,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 230 * The units of measurement for current are dependent on the value of
223 * the sense resistor. 231 * the sense resistor.
224 */ 232 */
225 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 233 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
226 if (ret < 0) 234 if (ret < 0)
227 return ret; 235 return ret;
228 236
229 if (sense_res_raw == 0) { 237 if (sense_res_raw == 0) {
230 dev_err(dev_info->dev, "sense resistor value is 0\n"); 238 dev_err(dev_info->dev, "sense resistor value is 0\n");
231 return -ENXIO; 239 return -EINVAL;
232 } 240 }
233 sense_res = 1000 / sense_res_raw; 241 sense_res = 1000 / sense_res_raw;
234 242
@@ -248,7 +256,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 256 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
249 * LSB register 257 * LSB register
250 */ 258 */
251 ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb); 259 ret = ds2780_read16(dev_info, &current_raw, reg_msb);
252 if (ret < 0) 260 if (ret < 0)
253 return ret; 261 return ret;
254 262
@@ -267,7 +275,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
267 * The units of measurement for accumulated current are dependent on 275 * The units of measurement for accumulated current are dependent on
268 * the value of the sense resistor. 276 * the value of the sense resistor.
269 */ 277 */
270 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 278 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
271 if (ret < 0) 279 if (ret < 0)
272 return ret; 280 return ret;
273 281
@@ -285,7 +293,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 293 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
286 * LSB register 294 * LSB register
287 */ 295 */
288 ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG); 296 ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
289 if (ret < 0) 297 if (ret < 0)
290 return ret; 298 return ret;
291 299
@@ -299,7 +307,7 @@ static int ds2780_get_capacity(struct ds2780_device_info *dev_info,
299 int ret; 307 int ret;
300 u8 raw; 308 u8 raw;
301 309
302 ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG); 310 ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
303 if (ret < 0) 311 if (ret < 0)
304 return ret; 312 return ret;
305 313
@@ -345,7 +353,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 353 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
346 * LSB register 354 * LSB register
347 */ 355 */
348 ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG); 356 ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
349 if (ret < 0) 357 if (ret < 0)
350 return ret; 358 return ret;
351 359
@@ -356,7 +364,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, 364static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
357 u8 *control_reg) 365 u8 *control_reg)
358{ 366{
359 return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG); 367 return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
360} 368}
361 369
362static int ds2780_set_control_register(struct ds2780_device_info *dev_info, 370static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
@@ -364,7 +372,7 @@ static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
364{ 372{
365 int ret; 373 int ret;
366 374
367 ret = ds2780_write(dev_info->w1_dev, &control_reg, 375 ret = ds2780_write(dev_info, &control_reg,
368 DS2780_CONTROL_REG, sizeof(u8)); 376 DS2780_CONTROL_REG, sizeof(u8));
369 if (ret < 0) 377 if (ret < 0)
370 return ret; 378 return ret;
@@ -503,7 +511,7 @@ static ssize_t ds2780_get_sense_resistor_value(struct device *dev,
503 struct power_supply *psy = to_power_supply(dev); 511 struct power_supply *psy = to_power_supply(dev);
504 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 512 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
505 513
506 ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG); 514 ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
507 if (ret < 0) 515 if (ret < 0)
508 return ret; 516 return ret;
509 517
@@ -584,7 +592,7 @@ static ssize_t ds2780_get_pio_pin(struct device *dev,
584 struct power_supply *psy = to_power_supply(dev); 592 struct power_supply *psy = to_power_supply(dev);
585 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 593 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
586 594
587 ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG); 595 ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
588 if (ret < 0) 596 if (ret < 0)
589 return ret; 597 return ret;
590 598
@@ -611,7 +619,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev,
611 return -EINVAL; 619 return -EINVAL;
612 } 620 }
613 621
614 ret = ds2780_write(dev_info->w1_dev, &new_setting, 622 ret = ds2780_write(dev_info, &new_setting,
615 DS2780_SFR_REG, sizeof(u8)); 623 DS2780_SFR_REG, sizeof(u8));
616 if (ret < 0) 624 if (ret < 0)
617 return ret; 625 return ret;
@@ -632,7 +640,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
632 DS2780_EEPROM_BLOCK1_END - 640 DS2780_EEPROM_BLOCK1_END -
633 DS2780_EEPROM_BLOCK1_START + 1 - off); 641 DS2780_EEPROM_BLOCK1_START + 1 - off);
634 642
635 return ds2780_read_block(dev_info->w1_dev, buf, 643 return ds2780_read_block(dev_info, buf,
636 DS2780_EEPROM_BLOCK1_START + off, count); 644 DS2780_EEPROM_BLOCK1_START + off, count);
637} 645}
638 646
@@ -650,7 +658,7 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
650 DS2780_EEPROM_BLOCK1_END - 658 DS2780_EEPROM_BLOCK1_END -
651 DS2780_EEPROM_BLOCK1_START + 1 - off); 659 DS2780_EEPROM_BLOCK1_START + 1 - off);
652 660
653 ret = ds2780_write(dev_info->w1_dev, buf, 661 ret = ds2780_write(dev_info, buf,
654 DS2780_EEPROM_BLOCK1_START + off, count); 662 DS2780_EEPROM_BLOCK1_START + off, count);
655 if (ret < 0) 663 if (ret < 0)
656 return ret; 664 return ret;
@@ -685,9 +693,8 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
685 DS2780_EEPROM_BLOCK0_END - 693 DS2780_EEPROM_BLOCK0_END -
686 DS2780_EEPROM_BLOCK0_START + 1 - off); 694 DS2780_EEPROM_BLOCK0_START + 1 - off);
687 695
688 return ds2780_read_block(dev_info->w1_dev, buf, 696 return ds2780_read_block(dev_info, buf,
689 DS2780_EEPROM_BLOCK0_START + off, count); 697 DS2780_EEPROM_BLOCK0_START + off, count);
690
691} 698}
692 699
693static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, 700static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
@@ -704,7 +711,7 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
704 DS2780_EEPROM_BLOCK0_END - 711 DS2780_EEPROM_BLOCK0_END -
705 DS2780_EEPROM_BLOCK0_START + 1 - off); 712 DS2780_EEPROM_BLOCK0_START + 1 - off);
706 713
707 ret = ds2780_write(dev_info->w1_dev, buf, 714 ret = ds2780_write(dev_info, buf,
708 DS2780_EEPROM_BLOCK0_START + off, count); 715 DS2780_EEPROM_BLOCK0_START + off, count);
709 if (ret < 0) 716 if (ret < 0)
710 return ret; 717 return ret;