2 * 1-wire client/driver for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC
4 * Copyright (C) 2010 Indesign, LLC
6 * Author: Clifton Barnes <cabarnes@indesign-llc.com>
8 * Based on ds2760_battery and ds2782_battery drivers
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/param.h>
20 #include <linux/platform_device.h>
21 #include <linux/power_supply.h>
22 #include <linux/idr.h>
25 #include "../w1/slaves/w1_ds2780.h"
27 /* Current unit measurement in uA for a 1 milli-ohm sense resistor */
28 #define DS2780_CURRENT_UNITS 1563
29 /* Charge unit measurement in uAh for a 1 milli-ohm sense resistor */
30 #define DS2780_CHARGE_UNITS 6250
31 /* Number of bytes in user EEPROM space */
32 #define DS2780_USER_EEPROM_SIZE (DS2780_EEPROM_BLOCK0_END - \
33 DS2780_EEPROM_BLOCK0_START + 1)
34 /* Number of bytes in parameter EEPROM space */
35 #define DS2780_PARAM_EEPROM_SIZE (DS2780_EEPROM_BLOCK1_END - \
36 DS2780_EEPROM_BLOCK1_START + 1)
38 struct ds2780_device_info
{
40 struct power_supply bat
;
41 struct device
*w1_dev
;
42 struct task_struct
*mutex_holder
;
50 static const char model
[] = "DS2780";
51 static const char manufacturer
[] = "Maxim/Dallas";
53 static inline struct ds2780_device_info
*
54 to_ds2780_device_info(struct power_supply
*psy
)
56 return container_of(psy
, struct ds2780_device_info
, bat
);
59 static inline struct power_supply
*to_power_supply(struct device
*dev
)
61 return dev_get_drvdata(dev
);
64 static inline int ds2780_battery_io(struct ds2780_device_info
*dev_info
,
65 char *buf
, int addr
, size_t count
, int io
)
67 if (dev_info
->mutex_holder
== current
)
68 return w1_ds2780_io_nolock(dev_info
->w1_dev
, buf
, addr
, count
, io
);
70 return w1_ds2780_io(dev_info
->w1_dev
, buf
, addr
, count
, io
);
73 static inline int ds2780_read8(struct ds2780_device_info
*dev_info
, u8
*val
,
76 return ds2780_battery_io(dev_info
, val
, addr
, sizeof(u8
), 0);
79 static int ds2780_read16(struct ds2780_device_info
*dev_info
, s16
*val
,
85 ret
= ds2780_battery_io(dev_info
, raw
, addr
, sizeof(raw
), 0);
89 *val
= (raw
[0] << 8) | raw
[1];
94 static inline int ds2780_read_block(struct ds2780_device_info
*dev_info
,
95 u8
*val
, int addr
, size_t count
)
97 return ds2780_battery_io(dev_info
, val
, addr
, count
, 0);
100 static inline int ds2780_write(struct ds2780_device_info
*dev_info
, u8
*val
,
101 int addr
, size_t count
)
103 return ds2780_battery_io(dev_info
, val
, addr
, count
, 1);
106 static inline int ds2780_store_eeprom(struct device
*dev
, int addr
)
108 return w1_ds2780_eeprom_cmd(dev
, addr
, W1_DS2780_COPY_DATA
);
111 static inline int ds2780_recall_eeprom(struct device
*dev
, int addr
)
113 return w1_ds2780_eeprom_cmd(dev
, addr
, W1_DS2780_RECALL_DATA
);
116 static int ds2780_save_eeprom(struct ds2780_device_info
*dev_info
, int reg
)
120 ret
= ds2780_store_eeprom(dev_info
->w1_dev
, reg
);
124 ret
= ds2780_recall_eeprom(dev_info
->w1_dev
, reg
);
131 /* Set sense resistor value in mhos */
132 static int ds2780_set_sense_register(struct ds2780_device_info
*dev_info
,
137 ret
= ds2780_write(dev_info
, &conductance
,
138 DS2780_RSNSP_REG
, sizeof(u8
));
142 return ds2780_save_eeprom(dev_info
, DS2780_RSNSP_REG
);
145 /* Get RSGAIN value from 0 to 1.999 in steps of 0.001 */
146 static int ds2780_get_rsgain_register(struct ds2780_device_info
*dev_info
,
149 return ds2780_read16(dev_info
, rsgain
, DS2780_RSGAIN_MSB_REG
);
152 /* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
153 static int ds2780_set_rsgain_register(struct ds2780_device_info
*dev_info
,
157 u8 raw
[] = {rsgain
>> 8, rsgain
& 0xFF};
159 ret
= ds2780_write(dev_info
, raw
,
160 DS2780_RSGAIN_MSB_REG
, sizeof(raw
));
164 return ds2780_save_eeprom(dev_info
, DS2780_RSGAIN_MSB_REG
);
167 static int ds2780_get_voltage(struct ds2780_device_info
*dev_info
,
174 * The voltage value is located in 10 bits across the voltage MSB
175 * and LSB registers in two's compliment form
176 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
177 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
178 * voltage MSB register
179 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
180 * voltage LSB register
182 ret
= ds2780_read16(dev_info
, &voltage_raw
,
183 DS2780_VOLT_MSB_REG
);
188 * DS2780 reports voltage in units of 4.88mV, but the battery class
189 * reports in units of uV, so convert by multiplying by 4880.
191 *voltage_uV
= (voltage_raw
/ 32) * 4880;
195 static int ds2780_get_temperature(struct ds2780_device_info
*dev_info
,
202 * The temperature value is located in 10 bits across the temperature
203 * MSB and LSB registers in two's compliment form
204 * Sign bit of the temperature value is in bit 7 of the temperature
206 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
207 * temperature MSB register
208 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
209 * temperature LSB register
211 ret
= ds2780_read16(dev_info
, &temperature_raw
,
212 DS2780_TEMP_MSB_REG
);
217 * Temperature is measured in units of 0.125 degrees celcius, the
218 * power_supply class measures temperature in tenths of degrees
219 * celsius. The temperature value is stored as a 10 bit number, plus
220 * sign in the upper bits of a 16 bit register.
222 *temperature
= ((temperature_raw
/ 32) * 125) / 100;
226 static int ds2780_get_current(struct ds2780_device_info
*dev_info
,
227 enum current_types type
, int *current_uA
)
231 u8 sense_res_raw
, reg_msb
;
234 * The units of measurement for current are dependent on the value of
235 * the sense resistor.
237 ret
= ds2780_read8(dev_info
, &sense_res_raw
, DS2780_RSNSP_REG
);
241 if (sense_res_raw
== 0) {
242 dev_err(dev_info
->dev
, "sense resistor value is 0\n");
245 sense_res
= 1000 / sense_res_raw
;
247 if (type
== CURRENT_NOW
)
248 reg_msb
= DS2780_CURRENT_MSB_REG
;
249 else if (type
== CURRENT_AVG
)
250 reg_msb
= DS2780_IAVG_MSB_REG
;
255 * The current value is located in 16 bits across the current MSB
256 * and LSB registers in two's compliment form
257 * Sign bit of the current value is in bit 7 of the current MSB register
258 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
260 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
263 ret
= ds2780_read16(dev_info
, ¤t_raw
, reg_msb
);
267 *current_uA
= current_raw
* (DS2780_CURRENT_UNITS
/ sense_res
);
271 static int ds2780_get_accumulated_current(struct ds2780_device_info
*dev_info
,
272 int *accumulated_current
)
279 * The units of measurement for accumulated current are dependent on
280 * the value of the sense resistor.
282 ret
= ds2780_read8(dev_info
, &sense_res_raw
, DS2780_RSNSP_REG
);
286 if (sense_res_raw
== 0) {
287 dev_err(dev_info
->dev
, "sense resistor value is 0\n");
290 sense_res
= 1000 / sense_res_raw
;
293 * The ACR value is located in 16 bits across the ACR MSB and
295 * Bits 15 - 8 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
300 ret
= ds2780_read16(dev_info
, ¤t_raw
, DS2780_ACR_MSB_REG
);
304 *accumulated_current
= current_raw
* (DS2780_CHARGE_UNITS
/ sense_res
);
308 static int ds2780_get_capacity(struct ds2780_device_info
*dev_info
,
314 ret
= ds2780_read8(dev_info
, &raw
, DS2780_RARC_REG
);
322 static int ds2780_get_status(struct ds2780_device_info
*dev_info
, int *status
)
324 int ret
, current_uA
, capacity
;
326 ret
= ds2780_get_current(dev_info
, CURRENT_NOW
, ¤t_uA
);
330 ret
= ds2780_get_capacity(dev_info
, &capacity
);
335 *status
= POWER_SUPPLY_STATUS_FULL
;
336 else if (current_uA
== 0)
337 *status
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
338 else if (current_uA
< 0)
339 *status
= POWER_SUPPLY_STATUS_DISCHARGING
;
341 *status
= POWER_SUPPLY_STATUS_CHARGING
;
346 static int ds2780_get_charge_now(struct ds2780_device_info
*dev_info
,
353 * The RAAC value is located in 16 bits across the RAAC MSB and
355 * Bits 15 - 8 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
360 ret
= ds2780_read16(dev_info
, &charge_raw
, DS2780_RAAC_MSB_REG
);
364 *charge_now
= charge_raw
* 1600;
368 static int ds2780_get_control_register(struct ds2780_device_info
*dev_info
,
371 return ds2780_read8(dev_info
, control_reg
, DS2780_CONTROL_REG
);
374 static int ds2780_set_control_register(struct ds2780_device_info
*dev_info
,
379 ret
= ds2780_write(dev_info
, &control_reg
,
380 DS2780_CONTROL_REG
, sizeof(u8
));
384 return ds2780_save_eeprom(dev_info
, DS2780_CONTROL_REG
);
387 static int ds2780_battery_get_property(struct power_supply
*psy
,
388 enum power_supply_property psp
,
389 union power_supply_propval
*val
)
392 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
395 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
396 ret
= ds2780_get_voltage(dev_info
, &val
->intval
);
399 case POWER_SUPPLY_PROP_TEMP
:
400 ret
= ds2780_get_temperature(dev_info
, &val
->intval
);
403 case POWER_SUPPLY_PROP_MODEL_NAME
:
407 case POWER_SUPPLY_PROP_MANUFACTURER
:
408 val
->strval
= manufacturer
;
411 case POWER_SUPPLY_PROP_CURRENT_NOW
:
412 ret
= ds2780_get_current(dev_info
, CURRENT_NOW
, &val
->intval
);
415 case POWER_SUPPLY_PROP_CURRENT_AVG
:
416 ret
= ds2780_get_current(dev_info
, CURRENT_AVG
, &val
->intval
);
419 case POWER_SUPPLY_PROP_STATUS
:
420 ret
= ds2780_get_status(dev_info
, &val
->intval
);
423 case POWER_SUPPLY_PROP_CAPACITY
:
424 ret
= ds2780_get_capacity(dev_info
, &val
->intval
);
427 case POWER_SUPPLY_PROP_CHARGE_COUNTER
:
428 ret
= ds2780_get_accumulated_current(dev_info
, &val
->intval
);
431 case POWER_SUPPLY_PROP_CHARGE_NOW
:
432 ret
= ds2780_get_charge_now(dev_info
, &val
->intval
);
442 static enum power_supply_property ds2780_battery_props
[] = {
443 POWER_SUPPLY_PROP_STATUS
,
444 POWER_SUPPLY_PROP_VOLTAGE_NOW
,
445 POWER_SUPPLY_PROP_TEMP
,
446 POWER_SUPPLY_PROP_MODEL_NAME
,
447 POWER_SUPPLY_PROP_MANUFACTURER
,
448 POWER_SUPPLY_PROP_CURRENT_NOW
,
449 POWER_SUPPLY_PROP_CURRENT_AVG
,
450 POWER_SUPPLY_PROP_CAPACITY
,
451 POWER_SUPPLY_PROP_CHARGE_COUNTER
,
452 POWER_SUPPLY_PROP_CHARGE_NOW
,
455 static ssize_t
ds2780_get_pmod_enabled(struct device
*dev
,
456 struct device_attribute
*attr
,
461 struct power_supply
*psy
= to_power_supply(dev
);
462 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
465 ret
= ds2780_get_control_register(dev_info
, &control_reg
);
469 return sprintf(buf
, "%d\n",
470 !!(control_reg
& DS2780_CONTROL_REG_PMOD
));
473 static ssize_t
ds2780_set_pmod_enabled(struct device
*dev
,
474 struct device_attribute
*attr
,
479 u8 control_reg
, new_setting
;
480 struct power_supply
*psy
= to_power_supply(dev
);
481 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
484 ret
= ds2780_get_control_register(dev_info
, &control_reg
);
488 ret
= kstrtou8(buf
, 0, &new_setting
);
492 if ((new_setting
!= 0) && (new_setting
!= 1)) {
493 dev_err(dev_info
->dev
, "Invalid pmod setting (0 or 1)\n");
498 control_reg
|= DS2780_CONTROL_REG_PMOD
;
500 control_reg
&= ~DS2780_CONTROL_REG_PMOD
;
502 ret
= ds2780_set_control_register(dev_info
, control_reg
);
509 static ssize_t
ds2780_get_sense_resistor_value(struct device
*dev
,
510 struct device_attribute
*attr
,
515 struct power_supply
*psy
= to_power_supply(dev
);
516 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
518 ret
= ds2780_read8(dev_info
, &sense_resistor
, DS2780_RSNSP_REG
);
522 ret
= sprintf(buf
, "%d\n", sense_resistor
);
526 static ssize_t
ds2780_set_sense_resistor_value(struct device
*dev
,
527 struct device_attribute
*attr
,
533 struct power_supply
*psy
= to_power_supply(dev
);
534 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
536 ret
= kstrtou8(buf
, 0, &new_setting
);
540 ret
= ds2780_set_sense_register(dev_info
, new_setting
);
547 static ssize_t
ds2780_get_rsgain_setting(struct device
*dev
,
548 struct device_attribute
*attr
,
553 struct power_supply
*psy
= to_power_supply(dev
);
554 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
556 ret
= ds2780_get_rsgain_register(dev_info
, &rsgain
);
560 return sprintf(buf
, "%d\n", rsgain
);
563 static ssize_t
ds2780_set_rsgain_setting(struct device
*dev
,
564 struct device_attribute
*attr
,
570 struct power_supply
*psy
= to_power_supply(dev
);
571 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
573 ret
= kstrtou16(buf
, 0, &new_setting
);
577 /* Gain can only be from 0 to 1.999 in steps of .001 */
578 if (new_setting
> 1999) {
579 dev_err(dev_info
->dev
, "Invalid rsgain setting (0 - 1999)\n");
583 ret
= ds2780_set_rsgain_register(dev_info
, new_setting
);
590 static ssize_t
ds2780_get_pio_pin(struct device
*dev
,
591 struct device_attribute
*attr
,
596 struct power_supply
*psy
= to_power_supply(dev
);
597 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
599 ret
= ds2780_read8(dev_info
, &sfr
, DS2780_SFR_REG
);
603 ret
= sprintf(buf
, "%d\n", sfr
& DS2780_SFR_REG_PIOSC
);
607 static ssize_t
ds2780_set_pio_pin(struct device
*dev
,
608 struct device_attribute
*attr
,
614 struct power_supply
*psy
= to_power_supply(dev
);
615 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
617 ret
= kstrtou8(buf
, 0, &new_setting
);
621 if ((new_setting
!= 0) && (new_setting
!= 1)) {
622 dev_err(dev_info
->dev
, "Invalid pio_pin setting (0 or 1)\n");
626 ret
= ds2780_write(dev_info
, &new_setting
,
627 DS2780_SFR_REG
, sizeof(u8
));
634 static ssize_t
ds2780_read_param_eeprom_bin(struct file
*filp
,
635 struct kobject
*kobj
,
636 struct bin_attribute
*bin_attr
,
637 char *buf
, loff_t off
, size_t count
)
639 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
640 struct power_supply
*psy
= to_power_supply(dev
);
641 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
643 count
= min_t(loff_t
, count
,
644 DS2780_EEPROM_BLOCK1_END
-
645 DS2780_EEPROM_BLOCK1_START
+ 1 - off
);
647 return ds2780_read_block(dev_info
, buf
,
648 DS2780_EEPROM_BLOCK1_START
+ off
, count
);
651 static ssize_t
ds2780_write_param_eeprom_bin(struct file
*filp
,
652 struct kobject
*kobj
,
653 struct bin_attribute
*bin_attr
,
654 char *buf
, loff_t off
, size_t count
)
656 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
657 struct power_supply
*psy
= to_power_supply(dev
);
658 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
661 count
= min_t(loff_t
, count
,
662 DS2780_EEPROM_BLOCK1_END
-
663 DS2780_EEPROM_BLOCK1_START
+ 1 - off
);
665 ret
= ds2780_write(dev_info
, buf
,
666 DS2780_EEPROM_BLOCK1_START
+ off
, count
);
670 ret
= ds2780_save_eeprom(dev_info
, DS2780_EEPROM_BLOCK1_START
);
677 static struct bin_attribute ds2780_param_eeprom_bin_attr
= {
679 .name
= "param_eeprom",
680 .mode
= S_IRUGO
| S_IWUSR
,
682 .size
= DS2780_EEPROM_BLOCK1_END
- DS2780_EEPROM_BLOCK1_START
+ 1,
683 .read
= ds2780_read_param_eeprom_bin
,
684 .write
= ds2780_write_param_eeprom_bin
,
687 static ssize_t
ds2780_read_user_eeprom_bin(struct file
*filp
,
688 struct kobject
*kobj
,
689 struct bin_attribute
*bin_attr
,
690 char *buf
, loff_t off
, size_t count
)
692 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
693 struct power_supply
*psy
= to_power_supply(dev
);
694 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
696 count
= min_t(loff_t
, count
,
697 DS2780_EEPROM_BLOCK0_END
-
698 DS2780_EEPROM_BLOCK0_START
+ 1 - off
);
700 return ds2780_read_block(dev_info
, buf
,
701 DS2780_EEPROM_BLOCK0_START
+ off
, count
);
704 static ssize_t
ds2780_write_user_eeprom_bin(struct file
*filp
,
705 struct kobject
*kobj
,
706 struct bin_attribute
*bin_attr
,
707 char *buf
, loff_t off
, size_t count
)
709 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
710 struct power_supply
*psy
= to_power_supply(dev
);
711 struct ds2780_device_info
*dev_info
= to_ds2780_device_info(psy
);
714 count
= min_t(loff_t
, count
,
715 DS2780_EEPROM_BLOCK0_END
-
716 DS2780_EEPROM_BLOCK0_START
+ 1 - off
);
718 ret
= ds2780_write(dev_info
, buf
,
719 DS2780_EEPROM_BLOCK0_START
+ off
, count
);
723 ret
= ds2780_save_eeprom(dev_info
, DS2780_EEPROM_BLOCK0_START
);
730 static struct bin_attribute ds2780_user_eeprom_bin_attr
= {
732 .name
= "user_eeprom",
733 .mode
= S_IRUGO
| S_IWUSR
,
735 .size
= DS2780_EEPROM_BLOCK0_END
- DS2780_EEPROM_BLOCK0_START
+ 1,
736 .read
= ds2780_read_user_eeprom_bin
,
737 .write
= ds2780_write_user_eeprom_bin
,
740 static DEVICE_ATTR(pmod_enabled
, S_IRUGO
| S_IWUSR
, ds2780_get_pmod_enabled
,
741 ds2780_set_pmod_enabled
);
742 static DEVICE_ATTR(sense_resistor_value
, S_IRUGO
| S_IWUSR
,
743 ds2780_get_sense_resistor_value
, ds2780_set_sense_resistor_value
);
744 static DEVICE_ATTR(rsgain_setting
, S_IRUGO
| S_IWUSR
, ds2780_get_rsgain_setting
,
745 ds2780_set_rsgain_setting
);
746 static DEVICE_ATTR(pio_pin
, S_IRUGO
| S_IWUSR
, ds2780_get_pio_pin
,
750 static struct attribute
*ds2780_attributes
[] = {
751 &dev_attr_pmod_enabled
.attr
,
752 &dev_attr_sense_resistor_value
.attr
,
753 &dev_attr_rsgain_setting
.attr
,
754 &dev_attr_pio_pin
.attr
,
758 static const struct attribute_group ds2780_attr_group
= {
759 .attrs
= ds2780_attributes
,
762 static int __devinit
ds2780_battery_probe(struct platform_device
*pdev
)
765 struct ds2780_device_info
*dev_info
;
767 dev_info
= kzalloc(sizeof(*dev_info
), GFP_KERNEL
);
773 platform_set_drvdata(pdev
, dev_info
);
775 dev_info
->dev
= &pdev
->dev
;
776 dev_info
->w1_dev
= pdev
->dev
.parent
;
777 dev_info
->bat
.name
= dev_name(&pdev
->dev
);
778 dev_info
->bat
.type
= POWER_SUPPLY_TYPE_BATTERY
;
779 dev_info
->bat
.properties
= ds2780_battery_props
;
780 dev_info
->bat
.num_properties
= ARRAY_SIZE(ds2780_battery_props
);
781 dev_info
->bat
.get_property
= ds2780_battery_get_property
;
782 dev_info
->mutex_holder
= current
;
784 ret
= power_supply_register(&pdev
->dev
, &dev_info
->bat
);
786 dev_err(dev_info
->dev
, "failed to register battery\n");
790 ret
= sysfs_create_group(&dev_info
->bat
.dev
->kobj
, &ds2780_attr_group
);
792 dev_err(dev_info
->dev
, "failed to create sysfs group\n");
793 goto fail_unregister
;
796 ret
= sysfs_create_bin_file(&dev_info
->bat
.dev
->kobj
,
797 &ds2780_param_eeprom_bin_attr
);
799 dev_err(dev_info
->dev
,
800 "failed to create param eeprom bin file");
801 goto fail_remove_group
;
804 ret
= sysfs_create_bin_file(&dev_info
->bat
.dev
->kobj
,
805 &ds2780_user_eeprom_bin_attr
);
807 dev_err(dev_info
->dev
,
808 "failed to create user eeprom bin file");
809 goto fail_remove_bin_file
;
812 dev_info
->mutex_holder
= NULL
;
816 fail_remove_bin_file
:
817 sysfs_remove_bin_file(&dev_info
->bat
.dev
->kobj
,
818 &ds2780_param_eeprom_bin_attr
);
820 sysfs_remove_group(&dev_info
->bat
.dev
->kobj
, &ds2780_attr_group
);
822 power_supply_unregister(&dev_info
->bat
);
829 static int __devexit
ds2780_battery_remove(struct platform_device
*pdev
)
831 struct ds2780_device_info
*dev_info
= platform_get_drvdata(pdev
);
833 dev_info
->mutex_holder
= current
;
835 /* remove attributes */
836 sysfs_remove_group(&dev_info
->bat
.dev
->kobj
, &ds2780_attr_group
);
838 power_supply_unregister(&dev_info
->bat
);
844 static struct platform_driver ds2780_battery_driver
= {
846 .name
= "ds2780-battery",
848 .probe
= ds2780_battery_probe
,
849 .remove
= __devexit_p(ds2780_battery_remove
),
852 module_platform_driver(ds2780_battery_driver
);
854 MODULE_LICENSE("GPL");
855 MODULE_AUTHOR("Clifton Barnes <cabarnes@indesign-llc.com>");
856 MODULE_DESCRIPTION("Maxim/Dallas DS2780 Stand-Alone Fuel Gauage IC driver");
857 MODULE_ALIAS("platform:ds2780-battery");