1 From 853eee72f74f449797f0500ea19fc1bf497428d8 Mon Sep 17 00:00:00 2001
2 From: Clifton Barnes <cabarnes@indesign-llc.com>
3 Date: Wed, 2 Nov 2011 13:39:50 -0700
4 Subject: drivers/power/ds2780_battery.c: create central point for calling w1 interface
6 From: Clifton Barnes <cabarnes@indesign-llc.com>
8 commit 853eee72f74f449797f0500ea19fc1bf497428d8 upstream.
10 Simply creates one point to call the w1 interface.
12 Signed-off-by: Clifton Barnes <cabarnes@indesign-llc.com>
13 Cc: Evgeniy Polyakov <zbr@ioremap.net>
14 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
15 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
19 drivers/power/ds2780_battery.c | 77 ++++++++++++++++++++++-------------------
20 1 file changed, 42 insertions(+), 35 deletions(-)
22 --- a/drivers/power/ds2780_battery.c
23 +++ b/drivers/power/ds2780_battery.c
24 @@ -49,8 +49,8 @@ enum current_types {
25 static const char model[] = "DS2780";
26 static const char manufacturer[] = "Maxim/Dallas";
28 -static inline struct ds2780_device_info *to_ds2780_device_info(
29 - struct power_supply *psy)
30 +static inline struct ds2780_device_info *
31 +to_ds2780_device_info(struct power_supply *psy)
33 return container_of(psy, struct ds2780_device_info, bat);
35 @@ -60,17 +60,25 @@ static inline struct power_supply *to_po
36 return dev_get_drvdata(dev);
39 -static inline int ds2780_read8(struct device *dev, u8 *val, int addr)
40 +static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
41 + char *buf, int addr, size_t count, int io)
43 - return w1_ds2780_io(dev, val, addr, sizeof(u8), 0);
44 + return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
47 -static int ds2780_read16(struct device *dev, s16 *val, int addr)
48 +static inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
51 + return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
54 +static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
60 - ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0);
61 + ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
65 @@ -79,16 +87,16 @@ static int ds2780_read16(struct device *
69 -static inline int ds2780_read_block(struct device *dev, u8 *val, int addr,
71 +static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
72 + u8 *val, int addr, size_t count)
74 - return w1_ds2780_io(dev, val, addr, count, 0);
75 + return ds2780_battery_io(dev_info, val, addr, count, 0);
78 -static inline int ds2780_write(struct device *dev, u8 *val, int addr,
80 +static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
81 + int addr, size_t count)
83 - return w1_ds2780_io(dev, val, addr, count, 1);
84 + return ds2780_battery_io(dev_info, val, addr, count, 1);
87 static inline int ds2780_store_eeprom(struct device *dev, int addr)
88 @@ -122,7 +130,7 @@ static int ds2780_set_sense_register(str
92 - ret = ds2780_write(dev_info->w1_dev, &conductance,
93 + ret = ds2780_write(dev_info, &conductance,
94 DS2780_RSNSP_REG, sizeof(u8));
97 @@ -134,7 +142,7 @@ static int ds2780_set_sense_register(str
98 static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
101 - return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG);
102 + return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
105 /* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
106 @@ -144,8 +152,8 @@ static int ds2780_set_rsgain_register(st
108 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
110 - ret = ds2780_write(dev_info->w1_dev, raw,
111 - DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2);
112 + ret = ds2780_write(dev_info, raw,
113 + DS2780_RSGAIN_MSB_REG, sizeof(raw));
117 @@ -167,7 +175,7 @@ static int ds2780_get_voltage(struct ds2
118 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
119 * voltage LSB register
121 - ret = ds2780_read16(dev_info->w1_dev, &voltage_raw,
122 + ret = ds2780_read16(dev_info, &voltage_raw,
123 DS2780_VOLT_MSB_REG);
126 @@ -196,7 +204,7 @@ static int ds2780_get_temperature(struct
127 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
128 * temperature LSB register
130 - ret = ds2780_read16(dev_info->w1_dev, &temperature_raw,
131 + ret = ds2780_read16(dev_info, &temperature_raw,
132 DS2780_TEMP_MSB_REG);
135 @@ -222,13 +230,13 @@ static int ds2780_get_current(struct ds2
136 * The units of measurement for current are dependent on the value of
137 * the sense resistor.
139 - ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
140 + ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
144 if (sense_res_raw == 0) {
145 dev_err(dev_info->dev, "sense resistor value is 0\n");
149 sense_res = 1000 / sense_res_raw;
151 @@ -248,7 +256,7 @@ static int ds2780_get_current(struct ds2
152 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
155 - ret = ds2780_read16(dev_info->w1_dev, ¤t_raw, reg_msb);
156 + ret = ds2780_read16(dev_info, ¤t_raw, reg_msb);
160 @@ -267,7 +275,7 @@ static int ds2780_get_accumulated_curren
161 * The units of measurement for accumulated current are dependent on
162 * the value of the sense resistor.
164 - ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
165 + ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
169 @@ -285,7 +293,7 @@ static int ds2780_get_accumulated_curren
170 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
173 - ret = ds2780_read16(dev_info->w1_dev, ¤t_raw, DS2780_ACR_MSB_REG);
174 + ret = ds2780_read16(dev_info, ¤t_raw, DS2780_ACR_MSB_REG);
178 @@ -299,7 +307,7 @@ static int ds2780_get_capacity(struct ds
182 - ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG);
183 + ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
187 @@ -345,7 +353,7 @@ static int ds2780_get_charge_now(struct
188 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
191 - ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG);
192 + ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
196 @@ -356,7 +364,7 @@ static int ds2780_get_charge_now(struct
197 static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
200 - return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG);
201 + return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
204 static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
205 @@ -364,7 +372,7 @@ static int ds2780_set_control_register(s
209 - ret = ds2780_write(dev_info->w1_dev, &control_reg,
210 + ret = ds2780_write(dev_info, &control_reg,
211 DS2780_CONTROL_REG, sizeof(u8));
214 @@ -503,7 +511,7 @@ static ssize_t ds2780_get_sense_resistor
215 struct power_supply *psy = to_power_supply(dev);
216 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
218 - ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG);
219 + ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
223 @@ -584,7 +592,7 @@ static ssize_t ds2780_get_pio_pin(struct
224 struct power_supply *psy = to_power_supply(dev);
225 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
227 - ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG);
228 + ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
232 @@ -611,7 +619,7 @@ static ssize_t ds2780_set_pio_pin(struct
236 - ret = ds2780_write(dev_info->w1_dev, &new_setting,
237 + ret = ds2780_write(dev_info, &new_setting,
238 DS2780_SFR_REG, sizeof(u8));
241 @@ -632,7 +640,7 @@ static ssize_t ds2780_read_param_eeprom_
242 DS2780_EEPROM_BLOCK1_END -
243 DS2780_EEPROM_BLOCK1_START + 1 - off);
245 - return ds2780_read_block(dev_info->w1_dev, buf,
246 + return ds2780_read_block(dev_info, buf,
247 DS2780_EEPROM_BLOCK1_START + off, count);
250 @@ -650,7 +658,7 @@ static ssize_t ds2780_write_param_eeprom
251 DS2780_EEPROM_BLOCK1_END -
252 DS2780_EEPROM_BLOCK1_START + 1 - off);
254 - ret = ds2780_write(dev_info->w1_dev, buf,
255 + ret = ds2780_write(dev_info, buf,
256 DS2780_EEPROM_BLOCK1_START + off, count);
259 @@ -685,9 +693,8 @@ static ssize_t ds2780_read_user_eeprom_b
260 DS2780_EEPROM_BLOCK0_END -
261 DS2780_EEPROM_BLOCK0_START + 1 - off);
263 - return ds2780_read_block(dev_info->w1_dev, buf,
264 + return ds2780_read_block(dev_info, buf,
265 DS2780_EEPROM_BLOCK0_START + off, count);
269 static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
270 @@ -704,7 +711,7 @@ static ssize_t ds2780_write_user_eeprom_
271 DS2780_EEPROM_BLOCK0_END -
272 DS2780_EEPROM_BLOCK0_START + 1 - off);
274 - ret = ds2780_write(dev_info->w1_dev, buf,
275 + ret = ds2780_write(dev_info, buf,
276 DS2780_EEPROM_BLOCK0_START + off, count);