1275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/*
2275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * 1-wire client/driver for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC
3275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes *
4275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * Copyright (C) 2010 Indesign, LLC
5275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes *
6275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * Author: Clifton Barnes <cabarnes@indesign-llc.com>
7275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes *
8275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * Based on ds2760_battery and ds2782_battery drivers
9275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes *
10275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * This program is free software; you can redistribute it and/or modify
11275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * it under the terms of the GNU General Public License version 2 as
12275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes * published by the Free Software Foundation.
13275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes *
14275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes */
15275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
16275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/module.h>
17275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/slab.h>
18275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/param.h>
19275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/pm.h>
20275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/platform_device.h>
21275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/power_supply.h>
22275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include <linux/idr.h>
23275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
24275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include "../w1/w1.h"
25275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#include "../w1/slaves/w1_ds2780.h"
26275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
27275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Current unit measurement in uA for a 1 milli-ohm sense resistor */
28275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#define DS2780_CURRENT_UNITS	1563
29275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Charge unit measurement in uAh for a 1 milli-ohm sense resistor */
30275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#define DS2780_CHARGE_UNITS		6250
31275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Number of bytes in user EEPROM space */
32275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#define DS2780_USER_EEPROM_SIZE		(DS2780_EEPROM_BLOCK0_END - \
33275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes					DS2780_EEPROM_BLOCK0_START + 1)
34275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Number of bytes in parameter EEPROM space */
35275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes#define DS2780_PARAM_EEPROM_SIZE	(DS2780_EEPROM_BLOCK1_END - \
36275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes					DS2780_EEPROM_BLOCK1_START + 1)
37275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
38275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstruct ds2780_device_info {
39275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	struct device *dev;
40275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	struct power_supply bat;
41275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	struct device *w1_dev;
42275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes};
43275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
44275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesenum current_types {
45275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	CURRENT_NOW,
46275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	CURRENT_AVG,
47275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes};
48275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
49275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic const char model[] = "DS2780";
50275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic const char manufacturer[] = "Maxim/Dallas";
51275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
52853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic inline struct ds2780_device_info *
53853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesto_ds2780_device_info(struct power_supply *psy)
54275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
55275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return container_of(psy, struct ds2780_device_info, bat);
56275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
57275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
58275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic inline struct power_supply *to_power_supply(struct device *dev)
59275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
60275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return dev_get_drvdata(dev);
61275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
62275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
63853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
64853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	char *buf, int addr, size_t count, int io)
65275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
66b02f8bede217a4b145ecc16d3940c78d83941147NeilBrown	return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
67275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
68275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
69853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
70853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	int addr)
71853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes{
72853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
73275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
74275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
75853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
76853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	int addr)
77275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
78275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
79275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 raw[2];
80275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
81853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
82275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
83275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
84275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
85275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*val = (raw[0] << 8) | raw[1];
86275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
87275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
88275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
89275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
90853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic inline int ds2780_read_block(struct ds2780_device_info *dev_info,
91853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	u8 *val, int addr, size_t count)
92275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
93853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	return ds2780_battery_io(dev_info, val, addr, count, 0);
94275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
95275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
96853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnesstatic inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
97853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	int addr, size_t count)
98275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
99853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	return ds2780_battery_io(dev_info, val, addr, count, 1);
100275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
101275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
102275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic inline int ds2780_store_eeprom(struct device *dev, int addr)
103275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
104275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return w1_ds2780_eeprom_cmd(dev, addr, W1_DS2780_COPY_DATA);
105275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
106275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
107275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic inline int ds2780_recall_eeprom(struct device *dev, int addr)
108275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
109275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return w1_ds2780_eeprom_cmd(dev, addr, W1_DS2780_RECALL_DATA);
110275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
111275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
112275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_save_eeprom(struct ds2780_device_info *dev_info, int reg)
113275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
114275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
115275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
116275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	ret = ds2780_store_eeprom(dev_info->w1_dev, reg);
117275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
118275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
119275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
120275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	ret = ds2780_recall_eeprom(dev_info->w1_dev, reg);
121275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
122275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
123275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
124275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
125275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
126275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
127275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Set sense resistor value in mhos */
128275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
129275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 conductance)
130275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
131275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
132275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
133853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_write(dev_info, &conductance,
134275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes				DS2780_RSNSP_REG, sizeof(u8));
135275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
136275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
137275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
138275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return ds2780_save_eeprom(dev_info, DS2780_RSNSP_REG);
139275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
140275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
141275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Get RSGAIN value from 0 to 1.999 in steps of 0.001 */
142275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
143275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u16 *rsgain)
144275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
145853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
146275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
147275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
148275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
149275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info,
150275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u16 rsgain)
151275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
152275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
153275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
154275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
155853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_write(dev_info, raw,
156853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes				DS2780_RSGAIN_MSB_REG, sizeof(raw));
157275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
158275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
159275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
160275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return ds2780_save_eeprom(dev_info, DS2780_RSGAIN_MSB_REG);
161275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
162275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
163275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_voltage(struct ds2780_device_info *dev_info,
164275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int *voltage_uV)
165275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
166275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
167275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	s16 voltage_raw;
168275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
169275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
170275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The voltage value is located in 10 bits across the voltage MSB
171275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * and LSB registers in two's compliment form
172275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
173275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
174275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * voltage MSB register
175275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
176275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * voltage LSB register
177275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
178853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read16(dev_info, &voltage_raw,
179275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes				DS2780_VOLT_MSB_REG);
180275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
181275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
182275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
183275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
184275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * DS2780 reports voltage in units of 4.88mV, but the battery class
185275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * reports in units of uV, so convert by multiplying by 4880.
186275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
187275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*voltage_uV = (voltage_raw / 32) * 4880;
188275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
189275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
190275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
191275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_temperature(struct ds2780_device_info *dev_info,
192275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int *temperature)
193275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
194275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
195275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	s16 temperature_raw;
196275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
197275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
198275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The temperature value is located in 10 bits across the temperature
199275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * MSB and LSB registers in two's compliment form
200275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Sign bit of the temperature value is in bit 7 of the temperature
201275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * MSB register
202275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
203275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * temperature MSB register
204275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
205275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * temperature LSB register
206275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
207853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read16(dev_info, &temperature_raw,
208275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes				DS2780_TEMP_MSB_REG);
209275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
210275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
211275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
212275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
213275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Temperature is measured in units of 0.125 degrees celcius, the
214275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * power_supply class measures temperature in tenths of degrees
215275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * celsius. The temperature value is stored as a 10 bit number, plus
216275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * sign in the upper bits of a 16 bit register.
217275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
218275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*temperature = ((temperature_raw / 32) * 125) / 100;
219275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
220275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
221275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
222275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_current(struct ds2780_device_info *dev_info,
223275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	enum current_types type, int *current_uA)
224275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
225275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret, sense_res;
226275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	s16 current_raw;
227275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 sense_res_raw, reg_msb;
228275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
229275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
230275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The units of measurement for current are dependent on the value of
231275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * the sense resistor.
232275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
233853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
234275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
235275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
236275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
237275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (sense_res_raw == 0) {
238275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		dev_err(dev_info->dev, "sense resistor value is 0\n");
239853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes		return -EINVAL;
240275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	}
241275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	sense_res = 1000 / sense_res_raw;
242275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
243275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (type == CURRENT_NOW)
244275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		reg_msb = DS2780_CURRENT_MSB_REG;
245275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	else if (type == CURRENT_AVG)
246275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		reg_msb = DS2780_IAVG_MSB_REG;
247275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	else
248275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return -EINVAL;
249275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
250275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
251275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The current value is located in 16 bits across the current MSB
252275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * and LSB registers in two's compliment form
253275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Sign bit of the current value is in bit 7 of the current MSB register
254275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
255275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * MSB register
256275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
257275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * LSB register
258275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
259853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read16(dev_info, &current_raw, reg_msb);
260275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
261275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
262275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
263275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*current_uA = current_raw * (DS2780_CURRENT_UNITS / sense_res);
264275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
265275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
266275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
267275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
268275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int *accumulated_current)
269275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
270275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret, sense_res;
271275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	s16 current_raw;
272275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 sense_res_raw;
273275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
274275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
275275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The units of measurement for accumulated current are dependent on
276275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * the value of the sense resistor.
277275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
278853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
279275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
280275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
281275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
282275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (sense_res_raw == 0) {
283275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		dev_err(dev_info->dev, "sense resistor value is 0\n");
284275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return -ENXIO;
285275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	}
286275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	sense_res = 1000 / sense_res_raw;
287275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
288275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
289275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The ACR value is located in 16 bits across the ACR MSB and
290275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * LSB registers
291275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 15 - 8 of the ACR value are in bits 7 - 0 of the ACR
292275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * MSB register
293275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
294275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * LSB register
295275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
296853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
297275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
298275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
299275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
300275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*accumulated_current = current_raw * (DS2780_CHARGE_UNITS / sense_res);
301275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
302275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
303275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
304275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_capacity(struct ds2780_device_info *dev_info,
305275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int *capacity)
306275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
307275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
308275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 raw;
309275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
310853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
311275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
312275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
313275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
314275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*capacity = raw;
315275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return raw;
316275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
317275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
318275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_status(struct ds2780_device_info *dev_info, int *status)
319275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
320275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret, current_uA, capacity;
321275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
322275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	ret = ds2780_get_current(dev_info, CURRENT_NOW, &current_uA);
323275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
324275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
325275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
326275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	ret = ds2780_get_capacity(dev_info, &capacity);
327275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
328275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
329275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
330275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (capacity == 100)
331275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		*status = POWER_SUPPLY_STATUS_FULL;
332275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	else if (current_uA == 0)
333275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		*status = POWER_SUPPLY_STATUS_NOT_CHARGING;
334275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	else if (current_uA < 0)
335275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		*status = POWER_SUPPLY_STATUS_DISCHARGING;
336275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	else
337275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		*status = POWER_SUPPLY_STATUS_CHARGING;
338275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
339275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
340275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
341275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
342275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
343275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int *charge_now)
344275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
345275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
346275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u16 charge_raw;
347275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
348275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	/*
349275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * The RAAC value is located in 16 bits across the RAAC MSB and
350275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * LSB registers
351275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 15 - 8 of the RAAC value are in bits 7 - 0 of the RAAC
352275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * MSB register
353275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
354275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 * LSB register
355275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	 */
356853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
357275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
358275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
359275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
360275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	*charge_now = charge_raw * 1600;
361275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return 0;
362275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
363275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
364275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_get_control_register(struct ds2780_device_info *dev_info,
365275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 *control_reg)
366275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
367853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
368275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
369275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
370275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_set_control_register(struct ds2780_device_info *dev_info,
371275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	u8 control_reg)
372275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
373275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret;
374275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
375853eee72f74f449797f0500ea19fc1bf497428d8Clifton Barnes	ret = ds2780_write(dev_info, &control_reg,
376275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes				DS2780_CONTROL_REG, sizeof(u8));
377275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	if (ret < 0)
378275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		return ret;
379275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
380275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return ds2780_save_eeprom(dev_info, DS2780_CONTROL_REG);
381275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
382275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
383275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic int ds2780_battery_get_property(struct power_supply *psy,
384275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	enum power_supply_property psp,
385275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	union power_supply_propval *val)
386275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes{
387275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	int ret = 0;
388275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
389275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
390275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	switch (psp) {
391275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
392275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_voltage(dev_info, &val->intval);
393275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
394275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
395275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_TEMP:
396275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_temperature(dev_info, &val->intval);
397275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
398275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
399275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_MODEL_NAME:
400275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		val->strval = model;
401275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
402275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
403275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_MANUFACTURER:
404275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		val->strval = manufacturer;
405275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
406275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
407275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_CURRENT_NOW:
408275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_current(dev_info, CURRENT_NOW, &val->intval);
409275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
410275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
411275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_CURRENT_AVG:
412275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_current(dev_info, CURRENT_AVG, &val->intval);
413275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
414275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
415275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_STATUS:
416275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_status(dev_info, &val->intval);
417275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
418275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
419275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_CAPACITY:
420275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_capacity(dev_info, &val->intval);
421275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
422275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
423275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
424275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_accumulated_current(dev_info, &val->intval);
425275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
426275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
427275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	case POWER_SUPPLY_PROP_CHARGE_NOW:
428275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = ds2780_get_charge_now(dev_info, &val->intval);
429275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		break;
430275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
431275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	default:
432275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes		ret = -EINVAL;
433275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	}
434275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
435275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	return ret;
436275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes}
437275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes
438275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnesstatic enum power_supply_property ds2780_battery_props[] = {
439275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_STATUS,
440275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_VOLTAGE_NOW,
441275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_TEMP,
442275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_MODEL_NAME,
443275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_MANUFACTURER,
444275ac74629c4d8ec430d7edecb16d936f46a47c5Clifton Barnes	POWER_SUPPLY_PROP_CURRENT_NOW,
445