diff options
author | Rhyland Klein <rklein@nvidia.com> | 2011-12-05 20:50:46 -0500 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2012-01-05 20:22:21 -0500 |
commit | 3ddca062f8d71724529b0d52609994c9886f1a18 (patch) | |
tree | 7127e840559cf1e1f158bc0dc0379a6064bcffae /drivers/power/sbs-battery.c | |
parent | c78f2b64963654419a8cd3b7e264251860e9f9eb (diff) |
sbs-battery: Rename internals to new name
Now that this driver is named more generally, this change updates
the internal variables, defines and functions to use this new name.
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/sbs-battery.c')
-rw-r--r-- | drivers/power/sbs-battery.c | 423 |
1 files changed, 204 insertions, 219 deletions
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index ce95ff791016..00bd9e079e80 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Gas Gauge driver for TI's BQ20Z75 | 2 | * Gas Gauge driver for SBS Compliant Batteries |
3 | * | 3 | * |
4 | * Copyright (c) 2010, NVIDIA Corporation. | 4 | * Copyright (c) 2010, NVIDIA Corporation. |
5 | * | 5 | * |
@@ -28,7 +28,7 @@ | |||
28 | #include <linux/interrupt.h> | 28 | #include <linux/interrupt.h> |
29 | #include <linux/gpio.h> | 29 | #include <linux/gpio.h> |
30 | 30 | ||
31 | #include <linux/power/bq20z75.h> | 31 | #include <linux/power/sbs-battery.h> |
32 | 32 | ||
33 | enum { | 33 | enum { |
34 | REG_MANUFACTURER_DATA, | 34 | REG_MANUFACTURER_DATA, |
@@ -53,7 +53,7 @@ enum { | |||
53 | /* Battery Mode defines */ | 53 | /* Battery Mode defines */ |
54 | #define BATTERY_MODE_OFFSET 0x03 | 54 | #define BATTERY_MODE_OFFSET 0x03 |
55 | #define BATTERY_MODE_MASK 0x8000 | 55 | #define BATTERY_MODE_MASK 0x8000 |
56 | enum bq20z75_battery_mode { | 56 | enum sbs_battery_mode { |
57 | BATTERY_MODE_AMPS, | 57 | BATTERY_MODE_AMPS, |
58 | BATTERY_MODE_WATTS | 58 | BATTERY_MODE_WATTS |
59 | }; | 59 | }; |
@@ -67,62 +67,56 @@ enum bq20z75_battery_mode { | |||
67 | #define BATTERY_FULL_CHARGED 0x20 | 67 | #define BATTERY_FULL_CHARGED 0x20 |
68 | #define BATTERY_FULL_DISCHARGED 0x10 | 68 | #define BATTERY_FULL_DISCHARGED 0x10 |
69 | 69 | ||
70 | #define BQ20Z75_DATA(_psp, _addr, _min_value, _max_value) { \ | 70 | #define SBS_DATA(_psp, _addr, _min_value, _max_value) { \ |
71 | .psp = _psp, \ | 71 | .psp = _psp, \ |
72 | .addr = _addr, \ | 72 | .addr = _addr, \ |
73 | .min_value = _min_value, \ | 73 | .min_value = _min_value, \ |
74 | .max_value = _max_value, \ | 74 | .max_value = _max_value, \ |
75 | } | 75 | } |
76 | 76 | ||
77 | static const struct bq20z75_device_data { | 77 | static const struct chip_data { |
78 | enum power_supply_property psp; | 78 | enum power_supply_property psp; |
79 | u8 addr; | 79 | u8 addr; |
80 | int min_value; | 80 | int min_value; |
81 | int max_value; | 81 | int max_value; |
82 | } bq20z75_data[] = { | 82 | } sbs_data[] = { |
83 | [REG_MANUFACTURER_DATA] = | 83 | [REG_MANUFACTURER_DATA] = |
84 | BQ20Z75_DATA(POWER_SUPPLY_PROP_PRESENT, 0x00, 0, 65535), | 84 | SBS_DATA(POWER_SUPPLY_PROP_PRESENT, 0x00, 0, 65535), |
85 | [REG_TEMPERATURE] = | 85 | [REG_TEMPERATURE] = |
86 | BQ20Z75_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535), | 86 | SBS_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535), |
87 | [REG_VOLTAGE] = | 87 | [REG_VOLTAGE] = |
88 | BQ20Z75_DATA(POWER_SUPPLY_PROP_VOLTAGE_NOW, 0x09, 0, 20000), | 88 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_NOW, 0x09, 0, 20000), |
89 | [REG_CURRENT] = | 89 | [REG_CURRENT] = |
90 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CURRENT_NOW, 0x0A, -32768, | 90 | SBS_DATA(POWER_SUPPLY_PROP_CURRENT_NOW, 0x0A, -32768, 32767), |
91 | 32767), | ||
92 | [REG_CAPACITY] = | 91 | [REG_CAPACITY] = |
93 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0E, 0, 100), | 92 | SBS_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0E, 0, 100), |
94 | [REG_REMAINING_CAPACITY] = | 93 | [REG_REMAINING_CAPACITY] = |
95 | BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_NOW, 0x0F, 0, 65535), | 94 | SBS_DATA(POWER_SUPPLY_PROP_ENERGY_NOW, 0x0F, 0, 65535), |
96 | [REG_REMAINING_CAPACITY_CHARGE] = | 95 | [REG_REMAINING_CAPACITY_CHARGE] = |
97 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_NOW, 0x0F, 0, 65535), | 96 | SBS_DATA(POWER_SUPPLY_PROP_CHARGE_NOW, 0x0F, 0, 65535), |
98 | [REG_FULL_CHARGE_CAPACITY] = | 97 | [REG_FULL_CHARGE_CAPACITY] = |
99 | BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL, 0x10, 0, 65535), | 98 | SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL, 0x10, 0, 65535), |
100 | [REG_FULL_CHARGE_CAPACITY_CHARGE] = | 99 | [REG_FULL_CHARGE_CAPACITY_CHARGE] = |
101 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_FULL, 0x10, 0, 65535), | 100 | SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL, 0x10, 0, 65535), |
102 | [REG_TIME_TO_EMPTY] = | 101 | [REG_TIME_TO_EMPTY] = |
103 | BQ20Z75_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, | 102 | SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, 65535), |
104 | 65535), | ||
105 | [REG_TIME_TO_FULL] = | 103 | [REG_TIME_TO_FULL] = |
106 | BQ20Z75_DATA(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 0x13, 0, | 104 | SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 0x13, 0, 65535), |
107 | 65535), | ||
108 | [REG_STATUS] = | 105 | [REG_STATUS] = |
109 | BQ20Z75_DATA(POWER_SUPPLY_PROP_STATUS, 0x16, 0, 65535), | 106 | SBS_DATA(POWER_SUPPLY_PROP_STATUS, 0x16, 0, 65535), |
110 | [REG_CYCLE_COUNT] = | 107 | [REG_CYCLE_COUNT] = |
111 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CYCLE_COUNT, 0x17, 0, 65535), | 108 | SBS_DATA(POWER_SUPPLY_PROP_CYCLE_COUNT, 0x17, 0, 65535), |
112 | [REG_DESIGN_CAPACITY] = | 109 | [REG_DESIGN_CAPACITY] = |
113 | BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, | 110 | SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 65535), |
114 | 65535), | ||
115 | [REG_DESIGN_CAPACITY_CHARGE] = | 111 | [REG_DESIGN_CAPACITY_CHARGE] = |
116 | BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, | 112 | SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 65535), |
117 | 65535), | ||
118 | [REG_DESIGN_VOLTAGE] = | 113 | [REG_DESIGN_VOLTAGE] = |
119 | BQ20Z75_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, | 114 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535), |
120 | 65535), | ||
121 | [REG_SERIAL_NUMBER] = | 115 | [REG_SERIAL_NUMBER] = |
122 | BQ20Z75_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), | 116 | SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), |
123 | }; | 117 | }; |
124 | 118 | ||
125 | static enum power_supply_property bq20z75_properties[] = { | 119 | static enum power_supply_property sbs_properties[] = { |
126 | POWER_SUPPLY_PROP_STATUS, | 120 | POWER_SUPPLY_PROP_STATUS, |
127 | POWER_SUPPLY_PROP_HEALTH, | 121 | POWER_SUPPLY_PROP_HEALTH, |
128 | POWER_SUPPLY_PROP_PRESENT, | 122 | POWER_SUPPLY_PROP_PRESENT, |
@@ -144,10 +138,10 @@ static enum power_supply_property bq20z75_properties[] = { | |||
144 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | 138 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
145 | }; | 139 | }; |
146 | 140 | ||
147 | struct bq20z75_info { | 141 | struct sbs_info { |
148 | struct i2c_client *client; | 142 | struct i2c_client *client; |
149 | struct power_supply power_supply; | 143 | struct power_supply power_supply; |
150 | struct bq20z75_platform_data *pdata; | 144 | struct sbs_platform_data *pdata; |
151 | bool is_present; | 145 | bool is_present; |
152 | bool gpio_detect; | 146 | bool gpio_detect; |
153 | bool enable_detection; | 147 | bool enable_detection; |
@@ -158,14 +152,14 @@ struct bq20z75_info { | |||
158 | int ignore_changes; | 152 | int ignore_changes; |
159 | }; | 153 | }; |
160 | 154 | ||
161 | static int bq20z75_read_word_data(struct i2c_client *client, u8 address) | 155 | static int sbs_read_word_data(struct i2c_client *client, u8 address) |
162 | { | 156 | { |
163 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 157 | struct sbs_info *chip = i2c_get_clientdata(client); |
164 | s32 ret = 0; | 158 | s32 ret = 0; |
165 | int retries = 1; | 159 | int retries = 1; |
166 | 160 | ||
167 | if (bq20z75_device->pdata) | 161 | if (chip->pdata) |
168 | retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1); | 162 | retries = max(chip->pdata->i2c_retry_count + 1, 1); |
169 | 163 | ||
170 | while (retries > 0) { | 164 | while (retries > 0) { |
171 | ret = i2c_smbus_read_word_data(client, address); | 165 | ret = i2c_smbus_read_word_data(client, address); |
@@ -184,15 +178,15 @@ static int bq20z75_read_word_data(struct i2c_client *client, u8 address) | |||
184 | return le16_to_cpu(ret); | 178 | return le16_to_cpu(ret); |
185 | } | 179 | } |
186 | 180 | ||
187 | static int bq20z75_write_word_data(struct i2c_client *client, u8 address, | 181 | static int sbs_write_word_data(struct i2c_client *client, u8 address, |
188 | u16 value) | 182 | u16 value) |
189 | { | 183 | { |
190 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 184 | struct sbs_info *chip = i2c_get_clientdata(client); |
191 | s32 ret = 0; | 185 | s32 ret = 0; |
192 | int retries = 1; | 186 | int retries = 1; |
193 | 187 | ||
194 | if (bq20z75_device->pdata) | 188 | if (chip->pdata) |
195 | retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1); | 189 | retries = max(chip->pdata->i2c_retry_count + 1, 1); |
196 | 190 | ||
197 | while (retries > 0) { | 191 | while (retries > 0) { |
198 | ret = i2c_smbus_write_word_data(client, address, | 192 | ret = i2c_smbus_write_word_data(client, address, |
@@ -212,44 +206,41 @@ static int bq20z75_write_word_data(struct i2c_client *client, u8 address, | |||
212 | return 0; | 206 | return 0; |
213 | } | 207 | } |
214 | 208 | ||
215 | static int bq20z75_get_battery_presence_and_health( | 209 | static int sbs_get_battery_presence_and_health( |
216 | struct i2c_client *client, enum power_supply_property psp, | 210 | struct i2c_client *client, enum power_supply_property psp, |
217 | union power_supply_propval *val) | 211 | union power_supply_propval *val) |
218 | { | 212 | { |
219 | s32 ret; | 213 | s32 ret; |
220 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 214 | struct sbs_info *chip = i2c_get_clientdata(client); |
221 | 215 | ||
222 | if (psp == POWER_SUPPLY_PROP_PRESENT && | 216 | if (psp == POWER_SUPPLY_PROP_PRESENT && |
223 | bq20z75_device->gpio_detect) { | 217 | chip->gpio_detect) { |
224 | ret = gpio_get_value( | 218 | ret = gpio_get_value(chip->pdata->battery_detect); |
225 | bq20z75_device->pdata->battery_detect); | 219 | if (ret == chip->pdata->battery_detect_present) |
226 | if (ret == bq20z75_device->pdata->battery_detect_present) | ||
227 | val->intval = 1; | 220 | val->intval = 1; |
228 | else | 221 | else |
229 | val->intval = 0; | 222 | val->intval = 0; |
230 | bq20z75_device->is_present = val->intval; | 223 | chip->is_present = val->intval; |
231 | return ret; | 224 | return ret; |
232 | } | 225 | } |
233 | 226 | ||
234 | /* Write to ManufacturerAccess with | 227 | /* Write to ManufacturerAccess with |
235 | * ManufacturerAccess command and then | 228 | * ManufacturerAccess command and then |
236 | * read the status */ | 229 | * read the status */ |
237 | ret = bq20z75_write_word_data(client, | 230 | ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, |
238 | bq20z75_data[REG_MANUFACTURER_DATA].addr, | 231 | MANUFACTURER_ACCESS_STATUS); |
239 | MANUFACTURER_ACCESS_STATUS); | ||
240 | if (ret < 0) { | 232 | if (ret < 0) { |
241 | if (psp == POWER_SUPPLY_PROP_PRESENT) | 233 | if (psp == POWER_SUPPLY_PROP_PRESENT) |
242 | val->intval = 0; /* battery removed */ | 234 | val->intval = 0; /* battery removed */ |
243 | return ret; | 235 | return ret; |
244 | } | 236 | } |
245 | 237 | ||
246 | ret = bq20z75_read_word_data(client, | 238 | ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr); |
247 | bq20z75_data[REG_MANUFACTURER_DATA].addr); | ||
248 | if (ret < 0) | 239 | if (ret < 0) |
249 | return ret; | 240 | return ret; |
250 | 241 | ||
251 | if (ret < bq20z75_data[REG_MANUFACTURER_DATA].min_value || | 242 | if (ret < sbs_data[REG_MANUFACTURER_DATA].min_value || |
252 | ret > bq20z75_data[REG_MANUFACTURER_DATA].max_value) { | 243 | ret > sbs_data[REG_MANUFACTURER_DATA].max_value) { |
253 | val->intval = 0; | 244 | val->intval = 0; |
254 | return 0; | 245 | return 0; |
255 | } | 246 | } |
@@ -279,24 +270,23 @@ static int bq20z75_get_battery_presence_and_health( | |||
279 | return 0; | 270 | return 0; |
280 | } | 271 | } |
281 | 272 | ||
282 | static int bq20z75_get_battery_property(struct i2c_client *client, | 273 | static int sbs_get_battery_property(struct i2c_client *client, |
283 | int reg_offset, enum power_supply_property psp, | 274 | int reg_offset, enum power_supply_property psp, |
284 | union power_supply_propval *val) | 275 | union power_supply_propval *val) |
285 | { | 276 | { |
286 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 277 | struct sbs_info *chip = i2c_get_clientdata(client); |
287 | s32 ret; | 278 | s32 ret; |
288 | 279 | ||
289 | ret = bq20z75_read_word_data(client, | 280 | ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); |
290 | bq20z75_data[reg_offset].addr); | ||
291 | if (ret < 0) | 281 | if (ret < 0) |
292 | return ret; | 282 | return ret; |
293 | 283 | ||
294 | /* returned values are 16 bit */ | 284 | /* returned values are 16 bit */ |
295 | if (bq20z75_data[reg_offset].min_value < 0) | 285 | if (sbs_data[reg_offset].min_value < 0) |
296 | ret = (s16)ret; | 286 | ret = (s16)ret; |
297 | 287 | ||
298 | if (ret >= bq20z75_data[reg_offset].min_value && | 288 | if (ret >= sbs_data[reg_offset].min_value && |
299 | ret <= bq20z75_data[reg_offset].max_value) { | 289 | ret <= sbs_data[reg_offset].max_value) { |
300 | val->intval = ret; | 290 | val->intval = ret; |
301 | if (psp != POWER_SUPPLY_PROP_STATUS) | 291 | if (psp != POWER_SUPPLY_PROP_STATUS) |
302 | return 0; | 292 | return 0; |
@@ -310,12 +300,12 @@ static int bq20z75_get_battery_property(struct i2c_client *client, | |||
310 | else | 300 | else |
311 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | 301 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
312 | 302 | ||
313 | if (bq20z75_device->poll_time == 0) | 303 | if (chip->poll_time == 0) |
314 | bq20z75_device->last_state = val->intval; | 304 | chip->last_state = val->intval; |
315 | else if (bq20z75_device->last_state != val->intval) { | 305 | else if (chip->last_state != val->intval) { |
316 | cancel_delayed_work_sync(&bq20z75_device->work); | 306 | cancel_delayed_work_sync(&chip->work); |
317 | power_supply_changed(&bq20z75_device->power_supply); | 307 | power_supply_changed(&chip->power_supply); |
318 | bq20z75_device->poll_time = 0; | 308 | chip->poll_time = 0; |
319 | } | 309 | } |
320 | } else { | 310 | } else { |
321 | if (psp == POWER_SUPPLY_PROP_STATUS) | 311 | if (psp == POWER_SUPPLY_PROP_STATUS) |
@@ -327,7 +317,7 @@ static int bq20z75_get_battery_property(struct i2c_client *client, | |||
327 | return 0; | 317 | return 0; |
328 | } | 318 | } |
329 | 319 | ||
330 | static void bq20z75_unit_adjustment(struct i2c_client *client, | 320 | static void sbs_unit_adjustment(struct i2c_client *client, |
331 | enum power_supply_property psp, union power_supply_propval *val) | 321 | enum power_supply_property psp, union power_supply_propval *val) |
332 | { | 322 | { |
333 | #define BASE_UNIT_CONVERSION 1000 | 323 | #define BASE_UNIT_CONVERSION 1000 |
@@ -338,7 +328,7 @@ static void bq20z75_unit_adjustment(struct i2c_client *client, | |||
338 | case POWER_SUPPLY_PROP_ENERGY_NOW: | 328 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
339 | case POWER_SUPPLY_PROP_ENERGY_FULL: | 329 | case POWER_SUPPLY_PROP_ENERGY_FULL: |
340 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: | 330 | case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: |
341 | /* bq20z75 provides energy in units of 10mWh. | 331 | /* sbs provides energy in units of 10mWh. |
342 | * Convert to µWh | 332 | * Convert to µWh |
343 | */ | 333 | */ |
344 | val->intval *= BATTERY_MODE_CAP_MULT_WATT; | 334 | val->intval *= BATTERY_MODE_CAP_MULT_WATT; |
@@ -354,7 +344,7 @@ static void bq20z75_unit_adjustment(struct i2c_client *client, | |||
354 | break; | 344 | break; |
355 | 345 | ||
356 | case POWER_SUPPLY_PROP_TEMP: | 346 | case POWER_SUPPLY_PROP_TEMP: |
357 | /* bq20z75 provides battery temperature in 0.1K | 347 | /* sbs provides battery temperature in 0.1K |
358 | * so convert it to 0.1°C | 348 | * so convert it to 0.1°C |
359 | */ | 349 | */ |
360 | val->intval -= TEMP_KELVIN_TO_CELSIUS; | 350 | val->intval -= TEMP_KELVIN_TO_CELSIUS; |
@@ -362,7 +352,7 @@ static void bq20z75_unit_adjustment(struct i2c_client *client, | |||
362 | 352 | ||
363 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: | 353 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
364 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: | 354 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: |
365 | /* bq20z75 provides time to empty and time to full in minutes. | 355 | /* sbs provides time to empty and time to full in minutes. |
366 | * Convert to seconds | 356 | * Convert to seconds |
367 | */ | 357 | */ |
368 | val->intval *= TIME_UNIT_CONVERSION; | 358 | val->intval *= TIME_UNIT_CONVERSION; |
@@ -374,13 +364,12 @@ static void bq20z75_unit_adjustment(struct i2c_client *client, | |||
374 | } | 364 | } |
375 | } | 365 | } |
376 | 366 | ||
377 | static enum bq20z75_battery_mode | 367 | static enum sbs_battery_mode sbs_set_battery_mode(struct i2c_client *client, |
378 | bq20z75_set_battery_mode(struct i2c_client *client, | 368 | enum sbs_battery_mode mode) |
379 | enum bq20z75_battery_mode mode) | ||
380 | { | 369 | { |
381 | int ret, original_val; | 370 | int ret, original_val; |
382 | 371 | ||
383 | original_val = bq20z75_read_word_data(client, BATTERY_MODE_OFFSET); | 372 | original_val = sbs_read_word_data(client, BATTERY_MODE_OFFSET); |
384 | if (original_val < 0) | 373 | if (original_val < 0) |
385 | return original_val; | 374 | return original_val; |
386 | 375 | ||
@@ -392,68 +381,67 @@ bq20z75_set_battery_mode(struct i2c_client *client, | |||
392 | else | 381 | else |
393 | ret = original_val | BATTERY_MODE_MASK; | 382 | ret = original_val | BATTERY_MODE_MASK; |
394 | 383 | ||
395 | ret = bq20z75_write_word_data(client, BATTERY_MODE_OFFSET, ret); | 384 | ret = sbs_write_word_data(client, BATTERY_MODE_OFFSET, ret); |
396 | if (ret < 0) | 385 | if (ret < 0) |
397 | return ret; | 386 | return ret; |
398 | 387 | ||
399 | return original_val & BATTERY_MODE_MASK; | 388 | return original_val & BATTERY_MODE_MASK; |
400 | } | 389 | } |
401 | 390 | ||
402 | static int bq20z75_get_battery_capacity(struct i2c_client *client, | 391 | static int sbs_get_battery_capacity(struct i2c_client *client, |
403 | int reg_offset, enum power_supply_property psp, | 392 | int reg_offset, enum power_supply_property psp, |
404 | union power_supply_propval *val) | 393 | union power_supply_propval *val) |
405 | { | 394 | { |
406 | s32 ret; | 395 | s32 ret; |
407 | enum bq20z75_battery_mode mode = BATTERY_MODE_WATTS; | 396 | enum sbs_battery_mode mode = BATTERY_MODE_WATTS; |
408 | 397 | ||
409 | if (power_supply_is_amp_property(psp)) | 398 | if (power_supply_is_amp_property(psp)) |
410 | mode = BATTERY_MODE_AMPS; | 399 | mode = BATTERY_MODE_AMPS; |
411 | 400 | ||
412 | mode = bq20z75_set_battery_mode(client, mode); | 401 | mode = sbs_set_battery_mode(client, mode); |
413 | if (mode < 0) | 402 | if (mode < 0) |
414 | return mode; | 403 | return mode; |
415 | 404 | ||
416 | ret = bq20z75_read_word_data(client, bq20z75_data[reg_offset].addr); | 405 | ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); |
417 | if (ret < 0) | 406 | if (ret < 0) |
418 | return ret; | 407 | return ret; |
419 | 408 | ||
420 | if (psp == POWER_SUPPLY_PROP_CAPACITY) { | 409 | if (psp == POWER_SUPPLY_PROP_CAPACITY) { |
421 | /* bq20z75 spec says that this can be >100 % | 410 | /* sbs spec says that this can be >100 % |
422 | * even if max value is 100 % */ | 411 | * even if max value is 100 % */ |
423 | val->intval = min(ret, 100); | 412 | val->intval = min(ret, 100); |
424 | } else | 413 | } else |
425 | val->intval = ret; | 414 | val->intval = ret; |
426 | 415 | ||
427 | ret = bq20z75_set_battery_mode(client, mode); | 416 | ret = sbs_set_battery_mode(client, mode); |
428 | if (ret < 0) | 417 | if (ret < 0) |
429 | return ret; | 418 | return ret; |
430 | 419 | ||
431 | return 0; | 420 | return 0; |
432 | } | 421 | } |
433 | 422 | ||
434 | static char bq20z75_serial[5]; | 423 | static char sbs_serial[5]; |
435 | static int bq20z75_get_battery_serial_number(struct i2c_client *client, | 424 | static int sbs_get_battery_serial_number(struct i2c_client *client, |
436 | union power_supply_propval *val) | 425 | union power_supply_propval *val) |
437 | { | 426 | { |
438 | int ret; | 427 | int ret; |
439 | 428 | ||
440 | ret = bq20z75_read_word_data(client, | 429 | ret = sbs_read_word_data(client, sbs_data[REG_SERIAL_NUMBER].addr); |
441 | bq20z75_data[REG_SERIAL_NUMBER].addr); | ||
442 | if (ret < 0) | 430 | if (ret < 0) |
443 | return ret; | 431 | return ret; |
444 | 432 | ||
445 | ret = sprintf(bq20z75_serial, "%04x", ret); | 433 | ret = sprintf(sbs_serial, "%04x", ret); |
446 | val->strval = bq20z75_serial; | 434 | val->strval = sbs_serial; |
447 | 435 | ||
448 | return 0; | 436 | return 0; |
449 | } | 437 | } |
450 | 438 | ||
451 | static int bq20z75_get_property_index(struct i2c_client *client, | 439 | static int sbs_get_property_index(struct i2c_client *client, |
452 | enum power_supply_property psp) | 440 | enum power_supply_property psp) |
453 | { | 441 | { |
454 | int count; | 442 | int count; |
455 | for (count = 0; count < ARRAY_SIZE(bq20z75_data); count++) | 443 | for (count = 0; count < ARRAY_SIZE(sbs_data); count++) |
456 | if (psp == bq20z75_data[count].psp) | 444 | if (psp == sbs_data[count].psp) |
457 | return count; | 445 | return count; |
458 | 446 | ||
459 | dev_warn(&client->dev, | 447 | dev_warn(&client->dev, |
@@ -462,19 +450,19 @@ static int bq20z75_get_property_index(struct i2c_client *client, | |||
462 | return -EINVAL; | 450 | return -EINVAL; |
463 | } | 451 | } |
464 | 452 | ||
465 | static int bq20z75_get_property(struct power_supply *psy, | 453 | static int sbs_get_property(struct power_supply *psy, |
466 | enum power_supply_property psp, | 454 | enum power_supply_property psp, |
467 | union power_supply_propval *val) | 455 | union power_supply_propval *val) |
468 | { | 456 | { |
469 | int ret = 0; | 457 | int ret = 0; |
470 | struct bq20z75_info *bq20z75_device = container_of(psy, | 458 | struct sbs_info *chip = container_of(psy, |
471 | struct bq20z75_info, power_supply); | 459 | struct sbs_info, power_supply); |
472 | struct i2c_client *client = bq20z75_device->client; | 460 | struct i2c_client *client = chip->client; |
473 | 461 | ||
474 | switch (psp) { | 462 | switch (psp) { |
475 | case POWER_SUPPLY_PROP_PRESENT: | 463 | case POWER_SUPPLY_PROP_PRESENT: |
476 | case POWER_SUPPLY_PROP_HEALTH: | 464 | case POWER_SUPPLY_PROP_HEALTH: |
477 | ret = bq20z75_get_battery_presence_and_health(client, psp, val); | 465 | ret = sbs_get_battery_presence_and_health(client, psp, val); |
478 | if (psp == POWER_SUPPLY_PROP_PRESENT) | 466 | if (psp == POWER_SUPPLY_PROP_PRESENT) |
479 | return 0; | 467 | return 0; |
480 | break; | 468 | break; |
@@ -490,15 +478,15 @@ static int bq20z75_get_property(struct power_supply *psy, | |||
490 | case POWER_SUPPLY_PROP_CHARGE_FULL: | 478 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
491 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: | 479 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
492 | case POWER_SUPPLY_PROP_CAPACITY: | 480 | case POWER_SUPPLY_PROP_CAPACITY: |
493 | ret = bq20z75_get_property_index(client, psp); | 481 | ret = sbs_get_property_index(client, psp); |
494 | if (ret < 0) | 482 | if (ret < 0) |
495 | break; | 483 | break; |
496 | 484 | ||
497 | ret = bq20z75_get_battery_capacity(client, ret, psp, val); | 485 | ret = sbs_get_battery_capacity(client, ret, psp, val); |
498 | break; | 486 | break; |
499 | 487 | ||
500 | case POWER_SUPPLY_PROP_SERIAL_NUMBER: | 488 | case POWER_SUPPLY_PROP_SERIAL_NUMBER: |
501 | ret = bq20z75_get_battery_serial_number(client, val); | 489 | ret = sbs_get_battery_serial_number(client, val); |
502 | break; | 490 | break; |
503 | 491 | ||
504 | case POWER_SUPPLY_PROP_STATUS: | 492 | case POWER_SUPPLY_PROP_STATUS: |
@@ -509,11 +497,11 @@ static int bq20z75_get_property(struct power_supply *psy, | |||
509 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: | 497 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
510 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: | 498 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: |
511 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | 499 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
512 | ret = bq20z75_get_property_index(client, psp); | 500 | ret = sbs_get_property_index(client, psp); |
513 | if (ret < 0) | 501 | if (ret < 0) |
514 | break; | 502 | break; |
515 | 503 | ||
516 | ret = bq20z75_get_battery_property(client, ret, psp, val); | 504 | ret = sbs_get_battery_property(client, ret, psp, val); |
517 | break; | 505 | break; |
518 | 506 | ||
519 | default: | 507 | default: |
@@ -522,25 +510,25 @@ static int bq20z75_get_property(struct power_supply *psy, | |||
522 | return -EINVAL; | 510 | return -EINVAL; |
523 | } | 511 | } |
524 | 512 | ||
525 | if (!bq20z75_device->enable_detection) | 513 | if (!chip->enable_detection) |
526 | goto done; | 514 | goto done; |
527 | 515 | ||
528 | if (!bq20z75_device->gpio_detect && | 516 | if (!chip->gpio_detect && |
529 | bq20z75_device->is_present != (ret >= 0)) { | 517 | chip->is_present != (ret >= 0)) { |
530 | bq20z75_device->is_present = (ret >= 0); | 518 | chip->is_present = (ret >= 0); |
531 | power_supply_changed(&bq20z75_device->power_supply); | 519 | power_supply_changed(&chip->power_supply); |
532 | } | 520 | } |
533 | 521 | ||
534 | done: | 522 | done: |
535 | if (!ret) { | 523 | if (!ret) { |
536 | /* Convert units to match requirements for power supply class */ | 524 | /* Convert units to match requirements for power supply class */ |
537 | bq20z75_unit_adjustment(client, psp, val); | 525 | sbs_unit_adjustment(client, psp, val); |
538 | } | 526 | } |
539 | 527 | ||
540 | dev_dbg(&client->dev, | 528 | dev_dbg(&client->dev, |
541 | "%s: property = %d, value = %x\n", __func__, psp, val->intval); | 529 | "%s: property = %d, value = %x\n", __func__, psp, val->intval); |
542 | 530 | ||
543 | if (ret && bq20z75_device->is_present) | 531 | if (ret && chip->is_present) |
544 | return ret; | 532 | return ret; |
545 | 533 | ||
546 | /* battery not present, so return NODATA for properties */ | 534 | /* battery not present, so return NODATA for properties */ |
@@ -550,7 +538,7 @@ done: | |||
550 | return 0; | 538 | return 0; |
551 | } | 539 | } |
552 | 540 | ||
553 | static irqreturn_t bq20z75_irq(int irq, void *devid) | 541 | static irqreturn_t sbs_irq(int irq, void *devid) |
554 | { | 542 | { |
555 | struct power_supply *battery = devid; | 543 | struct power_supply *battery = devid; |
556 | 544 | ||
@@ -559,36 +547,35 @@ static irqreturn_t bq20z75_irq(int irq, void *devid) | |||
559 | return IRQ_HANDLED; | 547 | return IRQ_HANDLED; |
560 | } | 548 | } |
561 | 549 | ||
562 | static void bq20z75_external_power_changed(struct power_supply *psy) | 550 | static void sbs_external_power_changed(struct power_supply *psy) |
563 | { | 551 | { |
564 | struct bq20z75_info *bq20z75_device; | 552 | struct sbs_info *chip; |
565 | 553 | ||
566 | bq20z75_device = container_of(psy, struct bq20z75_info, power_supply); | 554 | chip = container_of(psy, struct sbs_info, power_supply); |
567 | 555 | ||
568 | if (bq20z75_device->ignore_changes > 0) { | 556 | if (chip->ignore_changes > 0) { |
569 | bq20z75_device->ignore_changes--; | 557 | chip->ignore_changes--; |
570 | return; | 558 | return; |
571 | } | 559 | } |
572 | 560 | ||
573 | /* cancel outstanding work */ | 561 | /* cancel outstanding work */ |
574 | cancel_delayed_work_sync(&bq20z75_device->work); | 562 | cancel_delayed_work_sync(&chip->work); |
575 | 563 | ||
576 | schedule_delayed_work(&bq20z75_device->work, HZ); | 564 | schedule_delayed_work(&chip->work, HZ); |
577 | bq20z75_device->poll_time = bq20z75_device->pdata->poll_retry_count; | 565 | chip->poll_time = chip->pdata->poll_retry_count; |
578 | } | 566 | } |
579 | 567 | ||
580 | static void bq20z75_delayed_work(struct work_struct *work) | 568 | static void sbs_delayed_work(struct work_struct *work) |
581 | { | 569 | { |
582 | struct bq20z75_info *bq20z75_device; | 570 | struct sbs_info *chip; |
583 | s32 ret; | 571 | s32 ret; |
584 | 572 | ||
585 | bq20z75_device = container_of(work, struct bq20z75_info, work.work); | 573 | chip = container_of(work, struct sbs_info, work.work); |
586 | 574 | ||
587 | ret = bq20z75_read_word_data(bq20z75_device->client, | 575 | ret = sbs_read_word_data(chip->client, sbs_data[REG_STATUS].addr); |
588 | bq20z75_data[REG_STATUS].addr); | ||
589 | /* if the read failed, give up on this work */ | 576 | /* if the read failed, give up on this work */ |
590 | if (ret < 0) { | 577 | if (ret < 0) { |
591 | bq20z75_device->poll_time = 0; | 578 | chip->poll_time = 0; |
592 | return; | 579 | return; |
593 | } | 580 | } |
594 | 581 | ||
@@ -601,14 +588,14 @@ static void bq20z75_delayed_work(struct work_struct *work) | |||
601 | else | 588 | else |
602 | ret = POWER_SUPPLY_STATUS_CHARGING; | 589 | ret = POWER_SUPPLY_STATUS_CHARGING; |
603 | 590 | ||
604 | if (bq20z75_device->last_state != ret) { | 591 | if (chip->last_state != ret) { |
605 | bq20z75_device->poll_time = 0; | 592 | chip->poll_time = 0; |
606 | power_supply_changed(&bq20z75_device->power_supply); | 593 | power_supply_changed(&chip->power_supply); |
607 | return; | 594 | return; |
608 | } | 595 | } |
609 | if (bq20z75_device->poll_time > 0) { | 596 | if (chip->poll_time > 0) { |
610 | schedule_delayed_work(&bq20z75_device->work, HZ); | 597 | schedule_delayed_work(&chip->work, HZ); |
611 | bq20z75_device->poll_time--; | 598 | chip->poll_time--; |
612 | return; | 599 | return; |
613 | } | 600 | } |
614 | } | 601 | } |
@@ -618,17 +605,18 @@ static void bq20z75_delayed_work(struct work_struct *work) | |||
618 | #include <linux/of_device.h> | 605 | #include <linux/of_device.h> |
619 | #include <linux/of_gpio.h> | 606 | #include <linux/of_gpio.h> |
620 | 607 | ||
621 | static const struct of_device_id bq20z75_dt_ids[] = { | 608 | static const struct of_device_id sbs_dt_ids[] = { |
609 | { .compatible = "sbs,sbs-battery" }, | ||
622 | { .compatible = "ti,bq20z75" }, | 610 | { .compatible = "ti,bq20z75" }, |
623 | { } | 611 | { } |
624 | }; | 612 | }; |
625 | MODULE_DEVICE_TABLE(i2c, bq20z75_dt_ids); | 613 | MODULE_DEVICE_TABLE(i2c, sbs_dt_ids); |
626 | 614 | ||
627 | static struct bq20z75_platform_data *bq20z75_of_populate_pdata( | 615 | static struct sbs_platform_data *sbs_of_populate_pdata( |
628 | struct i2c_client *client) | 616 | struct i2c_client *client) |
629 | { | 617 | { |
630 | struct device_node *of_node = client->dev.of_node; | 618 | struct device_node *of_node = client->dev.of_node; |
631 | struct bq20z75_platform_data *pdata = client->dev.platform_data; | 619 | struct sbs_platform_data *pdata = client->dev.platform_data; |
632 | enum of_gpio_flags gpio_flags; | 620 | enum of_gpio_flags gpio_flags; |
633 | int rc; | 621 | int rc; |
634 | u32 prop; | 622 | u32 prop; |
@@ -644,31 +632,31 @@ static struct bq20z75_platform_data *bq20z75_of_populate_pdata( | |||
644 | /* first make sure at least one property is set, otherwise | 632 | /* first make sure at least one property is set, otherwise |
645 | * it won't change behavior from running without pdata. | 633 | * it won't change behavior from running without pdata. |
646 | */ | 634 | */ |
647 | if (!of_get_property(of_node, "ti,i2c-retry-count", NULL) && | 635 | if (!of_get_property(of_node, "sbs,i2c-retry-count", NULL) && |
648 | !of_get_property(of_node, "ti,poll-retry-count", NULL) && | 636 | !of_get_property(of_node, "sbs,poll-retry-count", NULL) && |
649 | !of_get_property(of_node, "ti,battery-detect-gpios", NULL)) | 637 | !of_get_property(of_node, "sbs,battery-detect-gpios", NULL)) |
650 | goto of_out; | 638 | goto of_out; |
651 | 639 | ||
652 | pdata = devm_kzalloc(&client->dev, sizeof(struct bq20z75_platform_data), | 640 | pdata = devm_kzalloc(&client->dev, sizeof(struct sbs_platform_data), |
653 | GFP_KERNEL); | 641 | GFP_KERNEL); |
654 | if (!pdata) | 642 | if (!pdata) |
655 | goto of_out; | 643 | goto of_out; |
656 | 644 | ||
657 | rc = of_property_read_u32(of_node, "ti,i2c-retry-count", &prop); | 645 | rc = of_property_read_u32(of_node, "sbs,i2c-retry-count", &prop); |
658 | if (!rc) | 646 | if (!rc) |
659 | pdata->i2c_retry_count = prop; | 647 | pdata->i2c_retry_count = prop; |
660 | 648 | ||
661 | rc = of_property_read_u32(of_node, "ti,poll-retry-count", &prop); | 649 | rc = of_property_read_u32(of_node, "sbs,poll-retry-count", &prop); |
662 | if (!rc) | 650 | if (!rc) |
663 | pdata->poll_retry_count = prop; | 651 | pdata->poll_retry_count = prop; |
664 | 652 | ||
665 | if (!of_get_property(of_node, "ti,battery-detect-gpios", NULL)) { | 653 | if (!of_get_property(of_node, "sbs,battery-detect-gpios", NULL)) { |
666 | pdata->battery_detect = -1; | 654 | pdata->battery_detect = -1; |
667 | goto of_out; | 655 | goto of_out; |
668 | } | 656 | } |
669 | 657 | ||
670 | pdata->battery_detect = of_get_named_gpio_flags(of_node, | 658 | pdata->battery_detect = of_get_named_gpio_flags(of_node, |
671 | "ti,battery-detect-gpios", 0, &gpio_flags); | 659 | "sbs,battery-detect-gpios", 0, &gpio_flags); |
672 | 660 | ||
673 | if (gpio_flags & OF_GPIO_ACTIVE_LOW) | 661 | if (gpio_flags & OF_GPIO_ACTIVE_LOW) |
674 | pdata->battery_detect_present = 0; | 662 | pdata->battery_detect_present = 0; |
@@ -679,60 +667,57 @@ of_out: | |||
679 | return pdata; | 667 | return pdata; |
680 | } | 668 | } |
681 | #else | 669 | #else |
682 | #define bq20z75_dt_ids NULL | 670 | #define sbs_dt_ids NULL |
683 | static struct bq20z75_platform_data *bq20z75_of_populate_pdata( | 671 | static struct sbs_platform_data *sbs_of_populate_pdata( |
684 | struct i2c_client *client) | 672 | struct i2c_client *client) |
685 | { | 673 | { |
686 | return client->dev.platform_data; | 674 | return client->dev.platform_data; |
687 | } | 675 | } |
688 | #endif | 676 | #endif |
689 | 677 | ||
690 | static int __devinit bq20z75_probe(struct i2c_client *client, | 678 | static int __devinit sbs_probe(struct i2c_client *client, |
691 | const struct i2c_device_id *id) | 679 | const struct i2c_device_id *id) |
692 | { | 680 | { |
693 | struct bq20z75_info *bq20z75_device; | 681 | struct sbs_info *chip; |
694 | struct bq20z75_platform_data *pdata = client->dev.platform_data; | 682 | struct sbs_platform_data *pdata = client->dev.platform_data; |
695 | int rc; | 683 | int rc; |
696 | int irq; | 684 | int irq; |
697 | 685 | ||
698 | bq20z75_device = kzalloc(sizeof(struct bq20z75_info), GFP_KERNEL); | 686 | chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL); |
699 | if (!bq20z75_device) | 687 | if (!chip) |
700 | return -ENOMEM; | 688 | return -ENOMEM; |
701 | 689 | ||
702 | bq20z75_device->client = client; | 690 | chip->client = client; |
703 | bq20z75_device->enable_detection = false; | 691 | chip->enable_detection = false; |
704 | bq20z75_device->gpio_detect = false; | 692 | chip->gpio_detect = false; |
705 | bq20z75_device->power_supply.name = "battery"; | 693 | chip->power_supply.name = "battery"; |
706 | bq20z75_device->power_supply.type = POWER_SUPPLY_TYPE_BATTERY; | 694 | chip->power_supply.type = POWER_SUPPLY_TYPE_BATTERY; |
707 | bq20z75_device->power_supply.properties = bq20z75_properties; | 695 | chip->power_supply.properties = sbs_properties; |
708 | bq20z75_device->power_supply.num_properties = | 696 | chip->power_supply.num_properties = ARRAY_SIZE(sbs_properties); |
709 | ARRAY_SIZE(bq20z75_properties); | 697 | chip->power_supply.get_property = sbs_get_property; |
710 | bq20z75_device->power_supply.get_property = bq20z75_get_property; | ||
711 | /* ignore first notification of external change, it is generated | 698 | /* ignore first notification of external change, it is generated |
712 | * from the power_supply_register call back | 699 | * from the power_supply_register call back |
713 | */ | 700 | */ |
714 | bq20z75_device->ignore_changes = 1; | 701 | chip->ignore_changes = 1; |
715 | bq20z75_device->last_state = POWER_SUPPLY_STATUS_UNKNOWN; | 702 | chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN; |
716 | bq20z75_device->power_supply.external_power_changed = | 703 | chip->power_supply.external_power_changed = sbs_external_power_changed; |
717 | bq20z75_external_power_changed; | ||
718 | 704 | ||
719 | pdata = bq20z75_of_populate_pdata(client); | 705 | pdata = sbs_of_populate_pdata(client); |
720 | 706 | ||
721 | if (pdata) { | 707 | if (pdata) { |
722 | bq20z75_device->gpio_detect = | 708 | chip->gpio_detect = gpio_is_valid(pdata->battery_detect); |
723 | gpio_is_valid(pdata->battery_detect); | 709 | chip->pdata = pdata; |
724 | bq20z75_device->pdata = pdata; | ||
725 | } | 710 | } |
726 | 711 | ||
727 | i2c_set_clientdata(client, bq20z75_device); | 712 | i2c_set_clientdata(client, chip); |
728 | 713 | ||
729 | if (!bq20z75_device->gpio_detect) | 714 | if (!chip->gpio_detect) |
730 | goto skip_gpio; | 715 | goto skip_gpio; |
731 | 716 | ||
732 | rc = gpio_request(pdata->battery_detect, dev_name(&client->dev)); | 717 | rc = gpio_request(pdata->battery_detect, dev_name(&client->dev)); |
733 | if (rc) { | 718 | if (rc) { |
734 | dev_warn(&client->dev, "Failed to request gpio: %d\n", rc); | 719 | dev_warn(&client->dev, "Failed to request gpio: %d\n", rc); |
735 | bq20z75_device->gpio_detect = false; | 720 | chip->gpio_detect = false; |
736 | goto skip_gpio; | 721 | goto skip_gpio; |
737 | } | 722 | } |
738 | 723 | ||
@@ -740,7 +725,7 @@ static int __devinit bq20z75_probe(struct i2c_client *client, | |||
740 | if (rc) { | 725 | if (rc) { |
741 | dev_warn(&client->dev, "Failed to get gpio as input: %d\n", rc); | 726 | dev_warn(&client->dev, "Failed to get gpio as input: %d\n", rc); |
742 | gpio_free(pdata->battery_detect); | 727 | gpio_free(pdata->battery_detect); |
743 | bq20z75_device->gpio_detect = false; | 728 | chip->gpio_detect = false; |
744 | goto skip_gpio; | 729 | goto skip_gpio; |
745 | } | 730 | } |
746 | 731 | ||
@@ -748,25 +733,25 @@ static int __devinit bq20z75_probe(struct i2c_client *client, | |||
748 | if (irq <= 0) { | 733 | if (irq <= 0) { |
749 | dev_warn(&client->dev, "Failed to get gpio as irq: %d\n", irq); | 734 | dev_warn(&client->dev, "Failed to get gpio as irq: %d\n", irq); |
750 | gpio_free(pdata->battery_detect); | 735 | gpio_free(pdata->battery_detect); |
751 | bq20z75_device->gpio_detect = false; | 736 | chip->gpio_detect = false; |
752 | goto skip_gpio; | 737 | goto skip_gpio; |
753 | } | 738 | } |
754 | 739 | ||
755 | rc = request_irq(irq, bq20z75_irq, | 740 | rc = request_irq(irq, sbs_irq, |
756 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | 741 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
757 | dev_name(&client->dev), &bq20z75_device->power_supply); | 742 | dev_name(&client->dev), &chip->power_supply); |
758 | if (rc) { | 743 | if (rc) { |
759 | dev_warn(&client->dev, "Failed to request irq: %d\n", rc); | 744 | dev_warn(&client->dev, "Failed to request irq: %d\n", rc); |
760 | gpio_free(pdata->battery_detect); | 745 | gpio_free(pdata->battery_detect); |
761 | bq20z75_device->gpio_detect = false; | 746 | chip->gpio_detect = false; |
762 | goto skip_gpio; | 747 | goto skip_gpio; |
763 | } | 748 | } |
764 | 749 | ||
765 | bq20z75_device->irq = irq; | 750 | chip->irq = irq; |
766 | 751 | ||
767 | skip_gpio: | 752 | skip_gpio: |
768 | 753 | ||
769 | rc = power_supply_register(&client->dev, &bq20z75_device->power_supply); | 754 | rc = power_supply_register(&client->dev, &chip->power_supply); |
770 | if (rc) { | 755 | if (rc) { |
771 | dev_err(&client->dev, | 756 | dev_err(&client->dev, |
772 | "%s: Failed to register power supply\n", __func__); | 757 | "%s: Failed to register power supply\n", __func__); |
@@ -776,96 +761,96 @@ skip_gpio: | |||
776 | dev_info(&client->dev, | 761 | dev_info(&client->dev, |
777 | "%s: battery gas gauge device registered\n", client->name); | 762 | "%s: battery gas gauge device registered\n", client->name); |
778 | 763 | ||
779 | INIT_DELAYED_WORK(&bq20z75_device->work, bq20z75_delayed_work); | 764 | INIT_DELAYED_WORK(&chip->work, sbs_delayed_work); |
780 | 765 | ||
781 | bq20z75_device->enable_detection = true; | 766 | chip->enable_detection = true; |
782 | 767 | ||
783 | return 0; | 768 | return 0; |
784 | 769 | ||
785 | exit_psupply: | 770 | exit_psupply: |
786 | if (bq20z75_device->irq) | 771 | if (chip->irq) |
787 | free_irq(bq20z75_device->irq, &bq20z75_device->power_supply); | 772 | free_irq(chip->irq, &chip->power_supply); |
788 | if (bq20z75_device->gpio_detect) | 773 | if (chip->gpio_detect) |
789 | gpio_free(pdata->battery_detect); | 774 | gpio_free(pdata->battery_detect); |
790 | 775 | ||
791 | kfree(bq20z75_device); | 776 | kfree(chip); |
792 | 777 | ||
793 | return rc; | 778 | return rc; |
794 | } | 779 | } |
795 | 780 | ||
796 | static int __devexit bq20z75_remove(struct i2c_client *client) | 781 | static int __devexit sbs_remove(struct i2c_client *client) |
797 | { | 782 | { |
798 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 783 | struct sbs_info *chip = i2c_get_clientdata(client); |
799 | 784 | ||
800 | if (bq20z75_device->irq) | 785 | if (chip->irq) |
801 | free_irq(bq20z75_device->irq, &bq20z75_device->power_supply); | 786 | free_irq(chip->irq, &chip->power_supply); |
802 | if (bq20z75_device->gpio_detect) | 787 | if (chip->gpio_detect) |
803 | gpio_free(bq20z75_device->pdata->battery_detect); | 788 | gpio_free(chip->pdata->battery_detect); |
804 | 789 | ||
805 | power_supply_unregister(&bq20z75_device->power_supply); | 790 | power_supply_unregister(&chip->power_supply); |
806 | 791 | ||
807 | cancel_delayed_work_sync(&bq20z75_device->work); | 792 | cancel_delayed_work_sync(&chip->work); |
808 | 793 | ||
809 | kfree(bq20z75_device); | 794 | kfree(chip); |
810 | bq20z75_device = NULL; | 795 | chip = NULL; |
811 | 796 | ||
812 | return 0; | 797 | return 0; |
813 | } | 798 | } |
814 | 799 | ||
815 | #if defined CONFIG_PM | 800 | #if defined CONFIG_PM |
816 | static int bq20z75_suspend(struct i2c_client *client, | 801 | static int sbs_suspend(struct i2c_client *client, |
817 | pm_message_t state) | 802 | pm_message_t state) |
818 | { | 803 | { |
819 | struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); | 804 | struct sbs_info *chip = i2c_get_clientdata(client); |
820 | s32 ret; | 805 | s32 ret; |
821 | 806 | ||
822 | if (bq20z75_device->poll_time > 0) | 807 | if (chip->poll_time > 0) |
823 | cancel_delayed_work_sync(&bq20z75_device->work); | 808 | cancel_delayed_work_sync(&chip->work); |
824 | 809 | ||
825 | /* write to manufacturer access with sleep command */ | 810 | /* write to manufacturer access with sleep command */ |
826 | ret = bq20z75_write_word_data(client, | 811 | ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, |
827 | bq20z75_data[REG_MANUFACTURER_DATA].addr, | ||
828 | MANUFACTURER_ACCESS_SLEEP); | 812 | MANUFACTURER_ACCESS_SLEEP); |
829 | if (bq20z75_device->is_present && ret < 0) | 813 | if (chip->is_present && ret < 0) |
830 | return ret; | 814 | return ret; |
831 | 815 | ||
832 | return 0; | 816 | return 0; |
833 | } | 817 | } |
834 | #else | 818 | #else |
835 | #define bq20z75_suspend NULL | 819 | #define sbs_suspend NULL |
836 | #endif | 820 | #endif |
837 | /* any smbus transaction will wake up bq20z75 */ | 821 | /* any smbus transaction will wake up sbs */ |
838 | #define bq20z75_resume NULL | 822 | #define sbs_resume NULL |
839 | 823 | ||
840 | static const struct i2c_device_id bq20z75_id[] = { | 824 | static const struct i2c_device_id sbs_id[] = { |
841 | { "bq20z75", 0 }, | 825 | { "bq20z75", 0 }, |
826 | { "sbs-battery", 1 }, | ||
842 | {} | 827 | {} |
843 | }; | 828 | }; |
844 | MODULE_DEVICE_TABLE(i2c, bq20z75_id); | 829 | MODULE_DEVICE_TABLE(i2c, sbs_id); |
845 | 830 | ||
846 | static struct i2c_driver bq20z75_battery_driver = { | 831 | static struct i2c_driver sbs_battery_driver = { |
847 | .probe = bq20z75_probe, | 832 | .probe = sbs_probe, |
848 | .remove = __devexit_p(bq20z75_remove), | 833 | .remove = __devexit_p(sbs_remove), |
849 | .suspend = bq20z75_suspend, | 834 | .suspend = sbs_suspend, |
850 | .resume = bq20z75_resume, | 835 | .resume = sbs_resume, |
851 | .id_table = bq20z75_id, | 836 | .id_table = sbs_id, |
852 | .driver = { | 837 | .driver = { |
853 | .name = "bq20z75-battery", | 838 | .name = "sbs-battery", |
854 | .of_match_table = bq20z75_dt_ids, | 839 | .of_match_table = sbs_dt_ids, |
855 | }, | 840 | }, |
856 | }; | 841 | }; |
857 | 842 | ||
858 | static int __init bq20z75_battery_init(void) | 843 | static int __init sbs_battery_init(void) |
859 | { | 844 | { |
860 | return i2c_add_driver(&bq20z75_battery_driver); | 845 | return i2c_add_driver(&sbs_battery_driver); |
861 | } | 846 | } |
862 | module_init(bq20z75_battery_init); | 847 | module_init(sbs_battery_init); |
863 | 848 | ||
864 | static void __exit bq20z75_battery_exit(void) | 849 | static void __exit sbs_battery_exit(void) |
865 | { | 850 | { |
866 | i2c_del_driver(&bq20z75_battery_driver); | 851 | i2c_del_driver(&sbs_battery_driver); |
867 | } | 852 | } |
868 | module_exit(bq20z75_battery_exit); | 853 | module_exit(sbs_battery_exit); |
869 | 854 | ||
870 | MODULE_DESCRIPTION("BQ20z75 battery monitor driver"); | 855 | MODULE_DESCRIPTION("SBS battery monitor driver"); |
871 | MODULE_LICENSE("GPL"); | 856 | MODULE_LICENSE("GPL"); |