]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.1.1/drivers-power-ds2780_battery.c-create-central-point-for-calling-w1-interface.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.1.1 / drivers-power-ds2780_battery.c-create-central-point-for-calling-w1-interface.patch
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
5
6 From: Clifton Barnes <cabarnes@indesign-llc.com>
7
8 commit 853eee72f74f449797f0500ea19fc1bf497428d8 upstream.
9
10 Simply creates one point to call the w1 interface.
11
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>
17
18 ---
19 drivers/power/ds2780_battery.c | 77 ++++++++++++++++++++++-------------------
20 1 file changed, 42 insertions(+), 35 deletions(-)
21
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";
27
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)
32 {
33 return container_of(psy, struct ds2780_device_info, bat);
34 }
35 @@ -60,17 +60,25 @@ static inline struct power_supply *to_po
36 return dev_get_drvdata(dev);
37 }
38
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)
42 {
43 - return w1_ds2780_io(dev, val, addr, sizeof(u8), 0);
44 + return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
45 }
46
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,
49 + int addr)
50 +{
51 + return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
52 +}
53 +
54 +static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
55 + int addr)
56 {
57 int ret;
58 u8 raw[2];
59
60 - ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0);
61 + ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
62 if (ret < 0)
63 return ret;
64
65 @@ -79,16 +87,16 @@ static int ds2780_read16(struct device *
66 return 0;
67 }
68
69 -static inline int ds2780_read_block(struct device *dev, u8 *val, int addr,
70 - size_t count)
71 +static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
72 + u8 *val, int addr, size_t count)
73 {
74 - return w1_ds2780_io(dev, val, addr, count, 0);
75 + return ds2780_battery_io(dev_info, val, addr, count, 0);
76 }
77
78 -static inline int ds2780_write(struct device *dev, u8 *val, int addr,
79 - size_t count)
80 +static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
81 + int addr, size_t count)
82 {
83 - return w1_ds2780_io(dev, val, addr, count, 1);
84 + return ds2780_battery_io(dev_info, val, addr, count, 1);
85 }
86
87 static inline int ds2780_store_eeprom(struct device *dev, int addr)
88 @@ -122,7 +130,7 @@ static int ds2780_set_sense_register(str
89 {
90 int ret;
91
92 - ret = ds2780_write(dev_info->w1_dev, &conductance,
93 + ret = ds2780_write(dev_info, &conductance,
94 DS2780_RSNSP_REG, sizeof(u8));
95 if (ret < 0)
96 return ret;
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,
99 u16 *rsgain)
100 {
101 - return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG);
102 + return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
103 }
104
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
107 int ret;
108 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
109
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));
114 if (ret < 0)
115 return ret;
116
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
120 */
121 - ret = ds2780_read16(dev_info->w1_dev, &voltage_raw,
122 + ret = ds2780_read16(dev_info, &voltage_raw,
123 DS2780_VOLT_MSB_REG);
124 if (ret < 0)
125 return ret;
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
129 */
130 - ret = ds2780_read16(dev_info->w1_dev, &temperature_raw,
131 + ret = ds2780_read16(dev_info, &temperature_raw,
132 DS2780_TEMP_MSB_REG);
133 if (ret < 0)
134 return ret;
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.
138 */
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);
141 if (ret < 0)
142 return ret;
143
144 if (sense_res_raw == 0) {
145 dev_err(dev_info->dev, "sense resistor value is 0\n");
146 - return -ENXIO;
147 + return -EINVAL;
148 }
149 sense_res = 1000 / sense_res_raw;
150
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
153 * LSB register
154 */
155 - ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb);
156 + ret = ds2780_read16(dev_info, &current_raw, reg_msb);
157 if (ret < 0)
158 return ret;
159
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.
163 */
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);
166 if (ret < 0)
167 return ret;
168
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
171 * LSB register
172 */
173 - ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG);
174 + ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
175 if (ret < 0)
176 return ret;
177
178 @@ -299,7 +307,7 @@ static int ds2780_get_capacity(struct ds
179 int ret;
180 u8 raw;
181
182 - ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG);
183 + ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
184 if (ret < 0)
185 return ret;
186
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
189 * LSB register
190 */
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);
193 if (ret < 0)
194 return ret;
195
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,
198 u8 *control_reg)
199 {
200 - return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG);
201 + return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
202 }
203
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
206 {
207 int ret;
208
209 - ret = ds2780_write(dev_info->w1_dev, &control_reg,
210 + ret = ds2780_write(dev_info, &control_reg,
211 DS2780_CONTROL_REG, sizeof(u8));
212 if (ret < 0)
213 return ret;
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);
217
218 - ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG);
219 + ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
220 if (ret < 0)
221 return ret;
222
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);
226
227 - ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG);
228 + ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
229 if (ret < 0)
230 return ret;
231
232 @@ -611,7 +619,7 @@ static ssize_t ds2780_set_pio_pin(struct
233 return -EINVAL;
234 }
235
236 - ret = ds2780_write(dev_info->w1_dev, &new_setting,
237 + ret = ds2780_write(dev_info, &new_setting,
238 DS2780_SFR_REG, sizeof(u8));
239 if (ret < 0)
240 return ret;
241 @@ -632,7 +640,7 @@ static ssize_t ds2780_read_param_eeprom_
242 DS2780_EEPROM_BLOCK1_END -
243 DS2780_EEPROM_BLOCK1_START + 1 - off);
244
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);
248 }
249
250 @@ -650,7 +658,7 @@ static ssize_t ds2780_write_param_eeprom
251 DS2780_EEPROM_BLOCK1_END -
252 DS2780_EEPROM_BLOCK1_START + 1 - off);
253
254 - ret = ds2780_write(dev_info->w1_dev, buf,
255 + ret = ds2780_write(dev_info, buf,
256 DS2780_EEPROM_BLOCK1_START + off, count);
257 if (ret < 0)
258 return ret;
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);
262
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);
266 -
267 }
268
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);
273
274 - ret = ds2780_write(dev_info->w1_dev, buf,
275 + ret = ds2780_write(dev_info, buf,
276 DS2780_EEPROM_BLOCK0_START + off, count);
277 if (ret < 0)
278 return ret;