Merge git://git.infradead.org/battery-2.6

* git://git.infradead.org/battery-2.6: (30 commits)
bq20z75: Fix time and temp units
bq20z75: Fix issues with present and suspend
z2_battery: Fix count of properties
s3c_adc_battery: Fix method names when PM not set
z2_battery: Add MODULE_DEVICE_TABLE
ds2782_battery: Add MODULE_DEVICE_TABLE
bq20z75: Add MODULE_DEVICE_TABLE
power_supply: Update power_supply_is_watt_property
bq20z75: Add i2c retry mechanism
bq20z75: Add optional battery detect gpio
twl4030_charger: Make the driver atomic notifier safe
bq27x00: Use single i2c_transfer call for property read
bq27x00: Cleanup bq27x00_i2c_read
bq27x00: Minor cleanups
bq27x00: Give more specific reports on battery status
bq27x00: Add MODULE_DEVICE_TABLE
bq27x00: Add new properties
bq27x00: Poll battery state
bq27x00: Cache battery registers
bq27x00: Add bq27000 support
...

+1048 -265
+20
drivers/leds/led-triggers.c
··· 231 } 232 EXPORT_SYMBOL_GPL(led_trigger_event); 233 234 void led_trigger_register_simple(const char *name, struct led_trigger **tp) 235 { 236 struct led_trigger *trigger;
··· 231 } 232 EXPORT_SYMBOL_GPL(led_trigger_event); 233 234 + void led_trigger_blink(struct led_trigger *trigger, 235 + unsigned long *delay_on, 236 + unsigned long *delay_off) 237 + { 238 + struct list_head *entry; 239 + 240 + if (!trigger) 241 + return; 242 + 243 + read_lock(&trigger->leddev_list_lock); 244 + list_for_each(entry, &trigger->led_cdevs) { 245 + struct led_classdev *led_cdev; 246 + 247 + led_cdev = list_entry(entry, struct led_classdev, trig_list); 248 + led_blink_set(led_cdev, delay_on, delay_off); 249 + } 250 + read_unlock(&trigger->leddev_list_lock); 251 + } 252 + EXPORT_SYMBOL_GPL(led_trigger_blink); 253 + 254 void led_trigger_register_simple(const char *name, struct led_trigger **tp) 255 { 256 struct led_trigger *trigger;
+14
drivers/power/Kconfig
··· 117 118 config BATTERY_BQ27x00 119 tristate "BQ27x00 battery driver" 120 depends on I2C 121 help 122 Say Y here to enable support for batteries with BQ27x00 (I2C) chips. 123 124 config BATTERY_DA9030 125 tristate "DA9030 battery driver"
··· 117 118 config BATTERY_BQ27x00 119 tristate "BQ27x00 battery driver" 120 + help 121 + Say Y here to enable support for batteries with BQ27x00 (I2C/HDQ) chips. 122 + 123 + config BATTERY_BQ27X00_I2C 124 + bool "BQ27200/BQ27500 support" 125 + depends on BATTERY_BQ27x00 126 depends on I2C 127 + default y 128 help 129 Say Y here to enable support for batteries with BQ27x00 (I2C) chips. 130 + 131 + config BATTERY_BQ27X00_PLATFORM 132 + bool "BQ27000 support" 133 + depends on BATTERY_BQ27x00 134 + default y 135 + help 136 + Say Y here to enable support for batteries with BQ27000 (HDQ) chips. 137 138 config BATTERY_DA9030 139 tristate "DA9030 battery driver"
+263 -47
drivers/power/bq20z75.c
··· 25 #include <linux/power_supply.h> 26 #include <linux/i2c.h> 27 #include <linux/slab.h> 28 29 enum { 30 REG_MANUFACTURER_DATA, ··· 42 REG_CYCLE_COUNT, 43 REG_SERIAL_NUMBER, 44 REG_REMAINING_CAPACITY, 45 REG_FULL_CHARGE_CAPACITY, 46 REG_DESIGN_CAPACITY, 47 REG_DESIGN_VOLTAGE, 48 }; 49 50 /* manufacturer access defines */ ··· 93 BQ20Z75_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0E, 0, 100), 94 [REG_REMAINING_CAPACITY] = 95 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_NOW, 0x0F, 0, 65535), 96 [REG_FULL_CHARGE_CAPACITY] = 97 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL, 0x10, 0, 65535), 98 [REG_TIME_TO_EMPTY] = 99 BQ20Z75_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, 100 65535), ··· 111 BQ20Z75_DATA(POWER_SUPPLY_PROP_CYCLE_COUNT, 0x17, 0, 65535), 112 [REG_DESIGN_CAPACITY] = 113 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 114 65535), 115 [REG_DESIGN_VOLTAGE] = 116 BQ20Z75_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, ··· 139 POWER_SUPPLY_PROP_ENERGY_NOW, 140 POWER_SUPPLY_PROP_ENERGY_FULL, 141 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 142 }; 143 144 struct bq20z75_info { 145 - struct i2c_client *client; 146 - struct power_supply power_supply; 147 }; 148 149 static int bq20z75_read_word_data(struct i2c_client *client, u8 address) 150 { 151 - s32 ret; 152 153 - ret = i2c_smbus_read_word_data(client, address); 154 if (ret < 0) { 155 - dev_err(&client->dev, 156 "%s: i2c read at address 0x%x failed\n", 157 __func__, address); 158 return ret; 159 } 160 return le16_to_cpu(ret); 161 } 162 163 static int bq20z75_write_word_data(struct i2c_client *client, u8 address, 164 u16 value) 165 { 166 - s32 ret; 167 168 - ret = i2c_smbus_write_word_data(client, address, le16_to_cpu(value)); 169 if (ret < 0) { 170 - dev_err(&client->dev, 171 "%s: i2c write to address 0x%x failed\n", 172 __func__, address); 173 return ret; 174 } 175 return 0; 176 } 177 ··· 213 union power_supply_propval *val) 214 { 215 s32 ret; 216 217 /* Write to ManufacturerAccess with 218 * ManufacturerAccess command and then ··· 233 ret = bq20z75_write_word_data(client, 234 bq20z75_data[REG_MANUFACTURER_DATA].addr, 235 MANUFACTURER_ACCESS_STATUS); 236 - if (ret < 0) 237 return ret; 238 - 239 240 ret = bq20z75_read_word_data(client, 241 bq20z75_data[REG_MANUFACTURER_DATA].addr); ··· 318 { 319 #define BASE_UNIT_CONVERSION 1000 320 #define BATTERY_MODE_CAP_MULT_WATT (10 * BASE_UNIT_CONVERSION) 321 - #define TIME_UNIT_CONVERSION 600 322 - #define TEMP_KELVIN_TO_CELCIUS 2731 323 switch (psp) { 324 case POWER_SUPPLY_PROP_ENERGY_NOW: 325 case POWER_SUPPLY_PROP_ENERGY_FULL: 326 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 327 val->intval *= BATTERY_MODE_CAP_MULT_WATT; 328 break; 329 330 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 331 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 332 case POWER_SUPPLY_PROP_CURRENT_NOW: 333 val->intval *= BASE_UNIT_CONVERSION; 334 break; 335 336 case POWER_SUPPLY_PROP_TEMP: 337 - /* bq20z75 provides battery tempreture in 0.1°K 338 - * so convert it to 0.1°C */ 339 - val->intval -= TEMP_KELVIN_TO_CELCIUS; 340 - val->intval *= 10; 341 break; 342 343 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 344 case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: 345 val->intval *= TIME_UNIT_CONVERSION; 346 break; 347 ··· 360 } 361 } 362 363 static int bq20z75_get_battery_capacity(struct i2c_client *client, 364 int reg_offset, enum power_supply_property psp, 365 union power_supply_propval *val) 366 { 367 s32 ret; 368 369 ret = bq20z75_read_word_data(client, bq20z75_data[reg_offset].addr); 370 if (ret < 0) ··· 409 val->intval = min(ret, 100); 410 } else 411 val->intval = ret; 412 413 return 0; 414 } ··· 434 return 0; 435 } 436 437 static int bq20z75_get_property(struct power_supply *psy, 438 enum power_supply_property psp, 439 union power_supply_propval *val) 440 { 441 - int count; 442 - int ret; 443 struct bq20z75_info *bq20z75_device = container_of(psy, 444 struct bq20z75_info, power_supply); 445 struct i2c_client *client = bq20z75_device->client; ··· 461 case POWER_SUPPLY_PROP_PRESENT: 462 case POWER_SUPPLY_PROP_HEALTH: 463 ret = bq20z75_get_battery_presence_and_health(client, psp, val); 464 - if (ret) 465 - return ret; 466 break; 467 468 case POWER_SUPPLY_PROP_TECHNOLOGY: ··· 472 case POWER_SUPPLY_PROP_ENERGY_NOW: 473 case POWER_SUPPLY_PROP_ENERGY_FULL: 474 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 475 case POWER_SUPPLY_PROP_CAPACITY: 476 - for (count = 0; count < ARRAY_SIZE(bq20z75_data); count++) { 477 - if (psp == bq20z75_data[count].psp) 478 - break; 479 - } 480 481 - ret = bq20z75_get_battery_capacity(client, count, psp, val); 482 - if (ret) 483 - return ret; 484 - 485 break; 486 487 case POWER_SUPPLY_PROP_SERIAL_NUMBER: 488 ret = bq20z75_get_battery_serial_number(client, val); 489 - if (ret) 490 - return ret; 491 break; 492 493 case POWER_SUPPLY_PROP_STATUS: ··· 495 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 496 case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: 497 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 498 - for (count = 0; count < ARRAY_SIZE(bq20z75_data); count++) { 499 - if (psp == bq20z75_data[count].psp) 500 - break; 501 - } 502 503 - ret = bq20z75_get_battery_property(client, count, psp, val); 504 - if (ret) 505 - return ret; 506 - 507 break; 508 509 default: ··· 508 return -EINVAL; 509 } 510 511 - /* Convert units to match requirements for power supply class */ 512 - bq20z75_unit_adjustment(client, psp, val); 513 514 dev_dbg(&client->dev, 515 - "%s: property = %d, value = %d\n", __func__, psp, val->intval); 516 517 return 0; 518 } 519 520 - static int bq20z75_probe(struct i2c_client *client, 521 const struct i2c_device_id *id) 522 { 523 struct bq20z75_info *bq20z75_device; 524 int rc; 525 526 bq20z75_device = kzalloc(sizeof(struct bq20z75_info), GFP_KERNEL); 527 if (!bq20z75_device) 528 return -ENOMEM; 529 530 bq20z75_device->client = client; 531 bq20z75_device->power_supply.name = "battery"; 532 bq20z75_device->power_supply.type = POWER_SUPPLY_TYPE_BATTERY; 533 bq20z75_device->power_supply.properties = bq20z75_properties; ··· 567 ARRAY_SIZE(bq20z75_properties); 568 bq20z75_device->power_supply.get_property = bq20z75_get_property; 569 570 i2c_set_clientdata(client, bq20z75_device); 571 572 rc = power_supply_register(&client->dev, &bq20z75_device->power_supply); 573 if (rc) { 574 dev_err(&client->dev, 575 "%s: Failed to register power supply\n", __func__); 576 - kfree(bq20z75_device); 577 - return rc; 578 } 579 580 dev_info(&client->dev, 581 "%s: battery gas gauge device registered\n", client->name); 582 583 return 0; 584 } 585 586 - static int bq20z75_remove(struct i2c_client *client) 587 { 588 struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 589 590 power_supply_unregister(&bq20z75_device->power_supply); 591 kfree(bq20z75_device); ··· 658 static int bq20z75_suspend(struct i2c_client *client, 659 pm_message_t state) 660 { 661 s32 ret; 662 663 /* write to manufacturer access with sleep command */ 664 ret = bq20z75_write_word_data(client, 665 bq20z75_data[REG_MANUFACTURER_DATA].addr, 666 MANUFACTURER_ACCESS_SLEEP); 667 - if (ret < 0) 668 return ret; 669 670 return 0; ··· 680 { "bq20z75", 0 }, 681 {} 682 }; 683 684 static struct i2c_driver bq20z75_battery_driver = { 685 .probe = bq20z75_probe, 686 - .remove = bq20z75_remove, 687 .suspend = bq20z75_suspend, 688 .resume = bq20z75_resume, 689 .id_table = bq20z75_id,
··· 25 #include <linux/power_supply.h> 26 #include <linux/i2c.h> 27 #include <linux/slab.h> 28 + #include <linux/interrupt.h> 29 + #include <linux/gpio.h> 30 + 31 + #include <linux/power/bq20z75.h> 32 33 enum { 34 REG_MANUFACTURER_DATA, ··· 38 REG_CYCLE_COUNT, 39 REG_SERIAL_NUMBER, 40 REG_REMAINING_CAPACITY, 41 + REG_REMAINING_CAPACITY_CHARGE, 42 REG_FULL_CHARGE_CAPACITY, 43 + REG_FULL_CHARGE_CAPACITY_CHARGE, 44 REG_DESIGN_CAPACITY, 45 + REG_DESIGN_CAPACITY_CHARGE, 46 REG_DESIGN_VOLTAGE, 47 + }; 48 + 49 + /* Battery Mode defines */ 50 + #define BATTERY_MODE_OFFSET 0x03 51 + #define BATTERY_MODE_MASK 0x8000 52 + enum bq20z75_battery_mode { 53 + BATTERY_MODE_AMPS, 54 + BATTERY_MODE_WATTS 55 }; 56 57 /* manufacturer access defines */ ··· 78 BQ20Z75_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0E, 0, 100), 79 [REG_REMAINING_CAPACITY] = 80 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_NOW, 0x0F, 0, 65535), 81 + [REG_REMAINING_CAPACITY_CHARGE] = 82 + BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_NOW, 0x0F, 0, 65535), 83 [REG_FULL_CHARGE_CAPACITY] = 84 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL, 0x10, 0, 65535), 85 + [REG_FULL_CHARGE_CAPACITY_CHARGE] = 86 + BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_FULL, 0x10, 0, 65535), 87 [REG_TIME_TO_EMPTY] = 88 BQ20Z75_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, 89 65535), ··· 92 BQ20Z75_DATA(POWER_SUPPLY_PROP_CYCLE_COUNT, 0x17, 0, 65535), 93 [REG_DESIGN_CAPACITY] = 94 BQ20Z75_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 95 + 65535), 96 + [REG_DESIGN_CAPACITY_CHARGE] = 97 + BQ20Z75_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 98 65535), 99 [REG_DESIGN_VOLTAGE] = 100 BQ20Z75_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, ··· 117 POWER_SUPPLY_PROP_ENERGY_NOW, 118 POWER_SUPPLY_PROP_ENERGY_FULL, 119 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 120 + POWER_SUPPLY_PROP_CHARGE_NOW, 121 + POWER_SUPPLY_PROP_CHARGE_FULL, 122 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 123 }; 124 125 struct bq20z75_info { 126 + struct i2c_client *client; 127 + struct power_supply power_supply; 128 + struct bq20z75_platform_data *pdata; 129 + bool is_present; 130 + bool gpio_detect; 131 + bool enable_detection; 132 + int irq; 133 }; 134 135 static int bq20z75_read_word_data(struct i2c_client *client, u8 address) 136 { 137 + struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 138 + s32 ret = 0; 139 + int retries = 1; 140 141 + if (bq20z75_device->pdata) 142 + retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1); 143 + 144 + while (retries > 0) { 145 + ret = i2c_smbus_read_word_data(client, address); 146 + if (ret >= 0) 147 + break; 148 + retries--; 149 + } 150 + 151 if (ret < 0) { 152 + dev_dbg(&client->dev, 153 "%s: i2c read at address 0x%x failed\n", 154 __func__, address); 155 return ret; 156 } 157 + 158 return le16_to_cpu(ret); 159 } 160 161 static int bq20z75_write_word_data(struct i2c_client *client, u8 address, 162 u16 value) 163 { 164 + struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 165 + s32 ret = 0; 166 + int retries = 1; 167 168 + if (bq20z75_device->pdata) 169 + retries = max(bq20z75_device->pdata->i2c_retry_count + 1, 1); 170 + 171 + while (retries > 0) { 172 + ret = i2c_smbus_write_word_data(client, address, 173 + le16_to_cpu(value)); 174 + if (ret >= 0) 175 + break; 176 + retries--; 177 + } 178 + 179 if (ret < 0) { 180 + dev_dbg(&client->dev, 181 "%s: i2c write to address 0x%x failed\n", 182 __func__, address); 183 return ret; 184 } 185 + 186 return 0; 187 } 188 ··· 158 union power_supply_propval *val) 159 { 160 s32 ret; 161 + struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 162 + 163 + if (psp == POWER_SUPPLY_PROP_PRESENT && 164 + bq20z75_device->gpio_detect) { 165 + ret = gpio_get_value( 166 + bq20z75_device->pdata->battery_detect); 167 + if (ret == bq20z75_device->pdata->battery_detect_present) 168 + val->intval = 1; 169 + else 170 + val->intval = 0; 171 + bq20z75_device->is_present = val->intval; 172 + return ret; 173 + } 174 175 /* Write to ManufacturerAccess with 176 * ManufacturerAccess command and then ··· 165 ret = bq20z75_write_word_data(client, 166 bq20z75_data[REG_MANUFACTURER_DATA].addr, 167 MANUFACTURER_ACCESS_STATUS); 168 + if (ret < 0) { 169 + if (psp == POWER_SUPPLY_PROP_PRESENT) 170 + val->intval = 0; /* battery removed */ 171 return ret; 172 + } 173 174 ret = bq20z75_read_word_data(client, 175 bq20z75_data[REG_MANUFACTURER_DATA].addr); ··· 248 { 249 #define BASE_UNIT_CONVERSION 1000 250 #define BATTERY_MODE_CAP_MULT_WATT (10 * BASE_UNIT_CONVERSION) 251 + #define TIME_UNIT_CONVERSION 60 252 + #define TEMP_KELVIN_TO_CELSIUS 2731 253 switch (psp) { 254 case POWER_SUPPLY_PROP_ENERGY_NOW: 255 case POWER_SUPPLY_PROP_ENERGY_FULL: 256 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 257 + /* bq20z75 provides energy in units of 10mWh. 258 + * Convert to µWh 259 + */ 260 val->intval *= BATTERY_MODE_CAP_MULT_WATT; 261 break; 262 263 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 264 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 265 case POWER_SUPPLY_PROP_CURRENT_NOW: 266 + case POWER_SUPPLY_PROP_CHARGE_NOW: 267 + case POWER_SUPPLY_PROP_CHARGE_FULL: 268 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 269 val->intval *= BASE_UNIT_CONVERSION; 270 break; 271 272 case POWER_SUPPLY_PROP_TEMP: 273 + /* bq20z75 provides battery temperature in 0.1K 274 + * so convert it to 0.1°C 275 + */ 276 + val->intval -= TEMP_KELVIN_TO_CELSIUS; 277 break; 278 279 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 280 case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: 281 + /* bq20z75 provides time to empty and time to full in minutes. 282 + * Convert to seconds 283 + */ 284 val->intval *= TIME_UNIT_CONVERSION; 285 break; 286 ··· 281 } 282 } 283 284 + static enum bq20z75_battery_mode 285 + bq20z75_set_battery_mode(struct i2c_client *client, 286 + enum bq20z75_battery_mode mode) 287 + { 288 + int ret, original_val; 289 + 290 + original_val = bq20z75_read_word_data(client, BATTERY_MODE_OFFSET); 291 + if (original_val < 0) 292 + return original_val; 293 + 294 + if ((original_val & BATTERY_MODE_MASK) == mode) 295 + return mode; 296 + 297 + if (mode == BATTERY_MODE_AMPS) 298 + ret = original_val & ~BATTERY_MODE_MASK; 299 + else 300 + ret = original_val | BATTERY_MODE_MASK; 301 + 302 + ret = bq20z75_write_word_data(client, BATTERY_MODE_OFFSET, ret); 303 + if (ret < 0) 304 + return ret; 305 + 306 + return original_val & BATTERY_MODE_MASK; 307 + } 308 + 309 static int bq20z75_get_battery_capacity(struct i2c_client *client, 310 int reg_offset, enum power_supply_property psp, 311 union power_supply_propval *val) 312 { 313 s32 ret; 314 + enum bq20z75_battery_mode mode = BATTERY_MODE_WATTS; 315 + 316 + if (power_supply_is_amp_property(psp)) 317 + mode = BATTERY_MODE_AMPS; 318 + 319 + mode = bq20z75_set_battery_mode(client, mode); 320 + if (mode < 0) 321 + return mode; 322 323 ret = bq20z75_read_word_data(client, bq20z75_data[reg_offset].addr); 324 if (ret < 0) ··· 297 val->intval = min(ret, 100); 298 } else 299 val->intval = ret; 300 + 301 + ret = bq20z75_set_battery_mode(client, mode); 302 + if (ret < 0) 303 + return ret; 304 305 return 0; 306 } ··· 318 return 0; 319 } 320 321 + static int bq20z75_get_property_index(struct i2c_client *client, 322 + enum power_supply_property psp) 323 + { 324 + int count; 325 + for (count = 0; count < ARRAY_SIZE(bq20z75_data); count++) 326 + if (psp == bq20z75_data[count].psp) 327 + return count; 328 + 329 + dev_warn(&client->dev, 330 + "%s: Invalid Property - %d\n", __func__, psp); 331 + 332 + return -EINVAL; 333 + } 334 + 335 static int bq20z75_get_property(struct power_supply *psy, 336 enum power_supply_property psp, 337 union power_supply_propval *val) 338 { 339 + int ret = 0; 340 struct bq20z75_info *bq20z75_device = container_of(psy, 341 struct bq20z75_info, power_supply); 342 struct i2c_client *client = bq20z75_device->client; ··· 332 case POWER_SUPPLY_PROP_PRESENT: 333 case POWER_SUPPLY_PROP_HEALTH: 334 ret = bq20z75_get_battery_presence_and_health(client, psp, val); 335 + if (psp == POWER_SUPPLY_PROP_PRESENT) 336 + return 0; 337 break; 338 339 case POWER_SUPPLY_PROP_TECHNOLOGY: ··· 343 case POWER_SUPPLY_PROP_ENERGY_NOW: 344 case POWER_SUPPLY_PROP_ENERGY_FULL: 345 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 346 + case POWER_SUPPLY_PROP_CHARGE_NOW: 347 + case POWER_SUPPLY_PROP_CHARGE_FULL: 348 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 349 case POWER_SUPPLY_PROP_CAPACITY: 350 + ret = bq20z75_get_property_index(client, psp); 351 + if (ret < 0) 352 + break; 353 354 + ret = bq20z75_get_battery_capacity(client, ret, psp, val); 355 break; 356 357 case POWER_SUPPLY_PROP_SERIAL_NUMBER: 358 ret = bq20z75_get_battery_serial_number(client, val); 359 break; 360 361 case POWER_SUPPLY_PROP_STATUS: ··· 369 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 370 case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: 371 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 372 + ret = bq20z75_get_property_index(client, psp); 373 + if (ret < 0) 374 + break; 375 376 + ret = bq20z75_get_battery_property(client, ret, psp, val); 377 break; 378 379 default: ··· 386 return -EINVAL; 387 } 388 389 + if (!bq20z75_device->enable_detection) 390 + goto done; 391 + 392 + if (!bq20z75_device->gpio_detect && 393 + bq20z75_device->is_present != (ret >= 0)) { 394 + bq20z75_device->is_present = (ret >= 0); 395 + power_supply_changed(&bq20z75_device->power_supply); 396 + } 397 + 398 + done: 399 + if (!ret) { 400 + /* Convert units to match requirements for power supply class */ 401 + bq20z75_unit_adjustment(client, psp, val); 402 + } 403 404 dev_dbg(&client->dev, 405 + "%s: property = %d, value = %x\n", __func__, psp, val->intval); 406 + 407 + if (ret && bq20z75_device->is_present) 408 + return ret; 409 + 410 + /* battery not present, so return NODATA for properties */ 411 + if (ret) 412 + return -ENODATA; 413 414 return 0; 415 } 416 417 + static irqreturn_t bq20z75_irq(int irq, void *devid) 418 + { 419 + struct power_supply *battery = devid; 420 + 421 + power_supply_changed(battery); 422 + 423 + return IRQ_HANDLED; 424 + } 425 + 426 + static int __devinit bq20z75_probe(struct i2c_client *client, 427 const struct i2c_device_id *id) 428 { 429 struct bq20z75_info *bq20z75_device; 430 + struct bq20z75_platform_data *pdata = client->dev.platform_data; 431 int rc; 432 + int irq; 433 434 bq20z75_device = kzalloc(sizeof(struct bq20z75_info), GFP_KERNEL); 435 if (!bq20z75_device) 436 return -ENOMEM; 437 438 bq20z75_device->client = client; 439 + bq20z75_device->enable_detection = false; 440 + bq20z75_device->gpio_detect = false; 441 bq20z75_device->power_supply.name = "battery"; 442 bq20z75_device->power_supply.type = POWER_SUPPLY_TYPE_BATTERY; 443 bq20z75_device->power_supply.properties = bq20z75_properties; ··· 413 ARRAY_SIZE(bq20z75_properties); 414 bq20z75_device->power_supply.get_property = bq20z75_get_property; 415 416 + if (pdata) { 417 + bq20z75_device->gpio_detect = 418 + gpio_is_valid(pdata->battery_detect); 419 + bq20z75_device->pdata = pdata; 420 + } 421 + 422 i2c_set_clientdata(client, bq20z75_device); 423 + 424 + if (!bq20z75_device->gpio_detect) 425 + goto skip_gpio; 426 + 427 + rc = gpio_request(pdata->battery_detect, dev_name(&client->dev)); 428 + if (rc) { 429 + dev_warn(&client->dev, "Failed to request gpio: %d\n", rc); 430 + bq20z75_device->gpio_detect = false; 431 + goto skip_gpio; 432 + } 433 + 434 + rc = gpio_direction_input(pdata->battery_detect); 435 + if (rc) { 436 + dev_warn(&client->dev, "Failed to get gpio as input: %d\n", rc); 437 + gpio_free(pdata->battery_detect); 438 + bq20z75_device->gpio_detect = false; 439 + goto skip_gpio; 440 + } 441 + 442 + irq = gpio_to_irq(pdata->battery_detect); 443 + if (irq <= 0) { 444 + dev_warn(&client->dev, "Failed to get gpio as irq: %d\n", irq); 445 + gpio_free(pdata->battery_detect); 446 + bq20z75_device->gpio_detect = false; 447 + goto skip_gpio; 448 + } 449 + 450 + rc = request_irq(irq, bq20z75_irq, 451 + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 452 + dev_name(&client->dev), &bq20z75_device->power_supply); 453 + if (rc) { 454 + dev_warn(&client->dev, "Failed to request irq: %d\n", rc); 455 + gpio_free(pdata->battery_detect); 456 + bq20z75_device->gpio_detect = false; 457 + goto skip_gpio; 458 + } 459 + 460 + bq20z75_device->irq = irq; 461 + 462 + skip_gpio: 463 464 rc = power_supply_register(&client->dev, &bq20z75_device->power_supply); 465 if (rc) { 466 dev_err(&client->dev, 467 "%s: Failed to register power supply\n", __func__); 468 + goto exit_psupply; 469 } 470 471 dev_info(&client->dev, 472 "%s: battery gas gauge device registered\n", client->name); 473 474 return 0; 475 + 476 + exit_psupply: 477 + if (bq20z75_device->irq) 478 + free_irq(bq20z75_device->irq, &bq20z75_device->power_supply); 479 + if (bq20z75_device->gpio_detect) 480 + gpio_free(pdata->battery_detect); 481 + 482 + kfree(bq20z75_device); 483 + 484 + return rc; 485 } 486 487 + static int __devexit bq20z75_remove(struct i2c_client *client) 488 { 489 struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 490 + 491 + if (bq20z75_device->irq) 492 + free_irq(bq20z75_device->irq, &bq20z75_device->power_supply); 493 + if (bq20z75_device->gpio_detect) 494 + gpio_free(bq20z75_device->pdata->battery_detect); 495 496 power_supply_unregister(&bq20z75_device->power_supply); 497 kfree(bq20z75_device); ··· 444 static int bq20z75_suspend(struct i2c_client *client, 445 pm_message_t state) 446 { 447 + struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client); 448 s32 ret; 449 450 /* write to manufacturer access with sleep command */ 451 ret = bq20z75_write_word_data(client, 452 bq20z75_data[REG_MANUFACTURER_DATA].addr, 453 MANUFACTURER_ACCESS_SLEEP); 454 + if (bq20z75_device->is_present && ret < 0) 455 return ret; 456 457 return 0; ··· 465 { "bq20z75", 0 }, 466 {} 467 }; 468 + MODULE_DEVICE_TABLE(i2c, bq20z75_id); 469 470 static struct i2c_driver bq20z75_battery_driver = { 471 .probe = bq20z75_probe, 472 + .remove = __devexit_p(bq20z75_remove), 473 .suspend = bq20z75_suspend, 474 .resume = bq20z75_resume, 475 .id_table = bq20z75_id,
+596 -207
drivers/power/bq27x00_battery.c
··· 3 * 4 * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it> 5 * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it> 6 * 7 * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc. 8 * ··· 16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 17 * 18 */ 19 #include <linux/module.h> 20 #include <linux/param.h> 21 #include <linux/jiffies.h> ··· 35 #include <linux/slab.h> 36 #include <asm/unaligned.h> 37 38 - #define DRIVER_VERSION "1.1.0" 39 40 #define BQ27x00_REG_TEMP 0x06 41 #define BQ27x00_REG_VOLT 0x08 ··· 46 #define BQ27x00_REG_TTE 0x16 47 #define BQ27x00_REG_TTF 0x18 48 #define BQ27x00_REG_TTECP 0x26 49 50 #define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */ 51 #define BQ27000_FLAG_CHGS BIT(7) 52 53 - #define BQ27500_REG_SOC 0x2c 54 #define BQ27500_FLAG_DSC BIT(0) 55 #define BQ27500_FLAG_FC BIT(9) 56 57 - /* If the system has several batteries we need a different name for each 58 - * of them... 59 - */ 60 - static DEFINE_IDR(battery_id); 61 - static DEFINE_MUTEX(battery_mutex); 62 63 struct bq27x00_device_info; 64 struct bq27x00_access_methods { 65 - int (*read)(u8 reg, int *rt_value, int b_single, 66 - struct bq27x00_device_info *di); 67 }; 68 69 enum bq27x00_chip { BQ27000, BQ27500 }; 70 71 struct bq27x00_device_info { 72 struct device *dev; 73 int id; 74 - struct bq27x00_access_methods *bus; 75 - struct power_supply bat; 76 enum bq27x00_chip chip; 77 78 - struct i2c_client *client; 79 }; 80 81 static enum power_supply_property bq27x00_battery_props[] = { ··· 111 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 112 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 113 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, 114 }; 115 116 /* 117 * Common code for BQ27x00 devices 118 */ 119 120 - static int bq27x00_read(u8 reg, int *rt_value, int b_single, 121 - struct bq27x00_device_info *di) 122 { 123 - return di->bus->read(reg, rt_value, b_single, di); 124 - } 125 - 126 - /* 127 - * Return the battery temperature in tenths of degree Celsius 128 - * Or < 0 if something fails. 129 - */ 130 - static int bq27x00_battery_temperature(struct bq27x00_device_info *di) 131 - { 132 - int ret; 133 - int temp = 0; 134 - 135 - ret = bq27x00_read(BQ27x00_REG_TEMP, &temp, 0, di); 136 - if (ret) { 137 - dev_err(di->dev, "error reading temperature\n"); 138 - return ret; 139 - } 140 - 141 - if (di->chip == BQ27500) 142 - return temp - 2731; 143 - else 144 - return ((temp >> 2) - 273) * 10; 145 - } 146 - 147 - /* 148 - * Return the battery Voltage in milivolts 149 - * Or < 0 if something fails. 150 - */ 151 - static int bq27x00_battery_voltage(struct bq27x00_device_info *di) 152 - { 153 - int ret; 154 - int volt = 0; 155 - 156 - ret = bq27x00_read(BQ27x00_REG_VOLT, &volt, 0, di); 157 - if (ret) { 158 - dev_err(di->dev, "error reading voltage\n"); 159 - return ret; 160 - } 161 - 162 - return volt * 1000; 163 - } 164 - 165 - /* 166 - * Return the battery average current 167 - * Note that current can be negative signed as well 168 - * Or 0 if something fails. 169 - */ 170 - static int bq27x00_battery_current(struct bq27x00_device_info *di) 171 - { 172 - int ret; 173 - int curr = 0; 174 - int flags = 0; 175 - 176 - ret = bq27x00_read(BQ27x00_REG_AI, &curr, 0, di); 177 - if (ret) { 178 - dev_err(di->dev, "error reading current\n"); 179 - return 0; 180 - } 181 - 182 - if (di->chip == BQ27500) { 183 - /* bq27500 returns signed value */ 184 - curr = (int)(s16)curr; 185 - } else { 186 - ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di); 187 - if (ret < 0) { 188 - dev_err(di->dev, "error reading flags\n"); 189 - return 0; 190 - } 191 - if (flags & BQ27000_FLAG_CHGS) { 192 - dev_dbg(di->dev, "negative current!\n"); 193 - curr = -curr; 194 - } 195 - } 196 - 197 - return curr * 1000; 198 } 199 200 /* 201 * Return the battery Relative State-of-Charge 202 * Or < 0 if something fails. 203 */ 204 - static int bq27x00_battery_rsoc(struct bq27x00_device_info *di) 205 { 206 - int ret; 207 - int rsoc = 0; 208 209 if (di->chip == BQ27500) 210 - ret = bq27x00_read(BQ27500_REG_SOC, &rsoc, 0, di); 211 else 212 - ret = bq27x00_read(BQ27000_REG_RSOC, &rsoc, 1, di); 213 - if (ret) { 214 dev_err(di->dev, "error reading relative State-of-Charge\n"); 215 - return ret; 216 - } 217 218 return rsoc; 219 } 220 221 - static int bq27x00_battery_status(struct bq27x00_device_info *di, 222 - union power_supply_propval *val) 223 { 224 - int flags = 0; 225 - int status; 226 - int ret; 227 228 - ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di); 229 - if (ret < 0) { 230 - dev_err(di->dev, "error reading flags\n"); 231 - return ret; 232 } 233 234 - if (di->chip == BQ27500) { 235 - if (flags & BQ27500_FLAG_FC) 236 - status = POWER_SUPPLY_STATUS_FULL; 237 - else if (flags & BQ27500_FLAG_DSC) 238 - status = POWER_SUPPLY_STATUS_DISCHARGING; 239 - else 240 - status = POWER_SUPPLY_STATUS_CHARGING; 241 - } else { 242 - if (flags & BQ27000_FLAG_CHGS) 243 - status = POWER_SUPPLY_STATUS_CHARGING; 244 - else 245 - status = POWER_SUPPLY_STATUS_DISCHARGING; 246 } 247 248 - val->intval = status; 249 - return 0; 250 } 251 252 /* 253 * Read a time register. 254 * Return < 0 if something fails. 255 */ 256 - static int bq27x00_battery_time(struct bq27x00_device_info *di, int reg, 257 - union power_supply_propval *val) 258 { 259 - int tval = 0; 260 - int ret; 261 262 - ret = bq27x00_read(reg, &tval, 0, di); 263 - if (ret) { 264 - dev_err(di->dev, "error reading register %02x\n", reg); 265 - return ret; 266 } 267 268 if (tval == 65535) 269 return -ENODATA; 270 271 - val->intval = tval * 60; 272 return 0; 273 } 274 ··· 446 int ret = 0; 447 struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 448 449 switch (psp) { 450 case POWER_SUPPLY_PROP_STATUS: 451 ret = bq27x00_battery_status(di, val); 452 break; 453 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 454 case POWER_SUPPLY_PROP_PRESENT: 455 - val->intval = bq27x00_battery_voltage(di); 456 - if (psp == POWER_SUPPLY_PROP_PRESENT) 457 - val->intval = val->intval <= 0 ? 0 : 1; 458 break; 459 case POWER_SUPPLY_PROP_CURRENT_NOW: 460 - val->intval = bq27x00_battery_current(di); 461 break; 462 case POWER_SUPPLY_PROP_CAPACITY: 463 - val->intval = bq27x00_battery_rsoc(di); 464 break; 465 case POWER_SUPPLY_PROP_TEMP: 466 - val->intval = bq27x00_battery_temperature(di); 467 break; 468 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: 469 - ret = bq27x00_battery_time(di, BQ27x00_REG_TTE, val); 470 break; 471 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 472 - ret = bq27x00_battery_time(di, BQ27x00_REG_TTECP, val); 473 break; 474 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: 475 - ret = bq27x00_battery_time(di, BQ27x00_REG_TTF, val); 476 break; 477 default: 478 return -EINVAL; ··· 509 return ret; 510 } 511 512 - static void bq27x00_powersupply_init(struct bq27x00_device_info *di) 513 { 514 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 515 di->bat.properties = bq27x00_battery_props; 516 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); 517 di->bat.get_property = bq27x00_battery_get_property; 518 - di->bat.external_power_changed = NULL; 519 } 520 521 - /* 522 - * i2c specific code 523 - */ 524 - 525 - static int bq27x00_read_i2c(u8 reg, int *rt_value, int b_single, 526 - struct bq27x00_device_info *di) 527 { 528 - struct i2c_client *client = di->client; 529 - struct i2c_msg msg[1]; 530 unsigned char data[2]; 531 - int err; 532 533 if (!client->adapter) 534 return -ENODEV; 535 536 - msg->addr = client->addr; 537 - msg->flags = 0; 538 - msg->len = 1; 539 - msg->buf = data; 540 541 - data[0] = reg; 542 - err = i2c_transfer(client->adapter, msg, 1); 543 544 - if (err >= 0) { 545 - if (!b_single) 546 - msg->len = 2; 547 - else 548 - msg->len = 1; 549 550 - msg->flags = I2C_M_RD; 551 - err = i2c_transfer(client->adapter, msg, 1); 552 - if (err >= 0) { 553 - if (!b_single) 554 - *rt_value = get_unaligned_le16(data); 555 - else 556 - *rt_value = data[0]; 557 - 558 - return 0; 559 - } 560 - } 561 - return err; 562 } 563 564 static int bq27x00_battery_probe(struct i2c_client *client, ··· 601 { 602 char *name; 603 struct bq27x00_device_info *di; 604 - struct bq27x00_access_methods *bus; 605 int num; 606 int retval = 0; 607 ··· 627 retval = -ENOMEM; 628 goto batt_failed_2; 629 } 630 - di->id = num; 631 - di->chip = id->driver_data; 632 633 - bus = kzalloc(sizeof(*bus), GFP_KERNEL); 634 - if (!bus) { 635 - dev_err(&client->dev, "failed to allocate access method " 636 - "data\n"); 637 - retval = -ENOMEM; 638 goto batt_failed_3; 639 - } 640 641 i2c_set_clientdata(client, di); 642 - di->dev = &client->dev; 643 - di->bat.name = name; 644 - bus->read = &bq27x00_read_i2c; 645 - di->bus = bus; 646 - di->client = client; 647 - 648 - bq27x00_powersupply_init(di); 649 - 650 - retval = power_supply_register(&client->dev, &di->bat); 651 - if (retval) { 652 - dev_err(&client->dev, "failed to register battery\n"); 653 - goto batt_failed_4; 654 - } 655 - 656 - dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION); 657 658 return 0; 659 660 - batt_failed_4: 661 - kfree(bus); 662 batt_failed_3: 663 kfree(di); 664 batt_failed_2: ··· 657 { 658 struct bq27x00_device_info *di = i2c_get_clientdata(client); 659 660 - power_supply_unregister(&di->bat); 661 662 - kfree(di->bus); 663 kfree(di->bat.name); 664 665 mutex_lock(&battery_mutex); ··· 670 return 0; 671 } 672 673 - /* 674 - * Module stuff 675 - */ 676 - 677 static const struct i2c_device_id bq27x00_id[] = { 678 { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ 679 { "bq27500", BQ27500 }, 680 {}, 681 }; 682 683 static struct i2c_driver bq27x00_battery_driver = { 684 .driver = { ··· 686 .id_table = bq27x00_id, 687 }; 688 689 static int __init bq27x00_battery_init(void) 690 { 691 int ret; 692 693 - ret = i2c_add_driver(&bq27x00_battery_driver); 694 if (ret) 695 - printk(KERN_ERR "Unable to register BQ27x00 driver\n"); 696 697 return ret; 698 } ··· 851 852 static void __exit bq27x00_battery_exit(void) 853 { 854 - i2c_del_driver(&bq27x00_battery_driver); 855 } 856 module_exit(bq27x00_battery_exit); 857
··· 3 * 4 * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it> 5 * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it> 6 + * Copyright (C) 2010-2011 Lars-Peter Clausen <lars@metafoo.de> 7 * 8 * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc. 9 * ··· 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 */ 18 + 19 + /* 20 + * Datasheets: 21 + * http://focus.ti.com/docs/prod/folders/print/bq27000.html 22 + * http://focus.ti.com/docs/prod/folders/print/bq27500.html 23 + */ 24 + 25 #include <linux/module.h> 26 #include <linux/param.h> 27 #include <linux/jiffies.h> ··· 27 #include <linux/slab.h> 28 #include <asm/unaligned.h> 29 30 + #include <linux/power/bq27x00_battery.h> 31 + 32 + #define DRIVER_VERSION "1.2.0" 33 34 #define BQ27x00_REG_TEMP 0x06 35 #define BQ27x00_REG_VOLT 0x08 ··· 36 #define BQ27x00_REG_TTE 0x16 37 #define BQ27x00_REG_TTF 0x18 38 #define BQ27x00_REG_TTECP 0x26 39 + #define BQ27x00_REG_NAC 0x0C /* Nominal available capaciy */ 40 + #define BQ27x00_REG_LMD 0x12 /* Last measured discharge */ 41 + #define BQ27x00_REG_CYCT 0x2A /* Cycle count total */ 42 + #define BQ27x00_REG_AE 0x22 /* Available enery */ 43 44 #define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */ 45 + #define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */ 46 #define BQ27000_FLAG_CHGS BIT(7) 47 + #define BQ27000_FLAG_FC BIT(5) 48 49 + #define BQ27500_REG_SOC 0x2C 50 + #define BQ27500_REG_DCAP 0x3C /* Design capacity */ 51 #define BQ27500_FLAG_DSC BIT(0) 52 #define BQ27500_FLAG_FC BIT(9) 53 54 + #define BQ27000_RS 20 /* Resistor sense */ 55 56 struct bq27x00_device_info; 57 struct bq27x00_access_methods { 58 + int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); 59 }; 60 61 enum bq27x00_chip { BQ27000, BQ27500 }; 62 63 + struct bq27x00_reg_cache { 64 + int temperature; 65 + int time_to_empty; 66 + int time_to_empty_avg; 67 + int time_to_full; 68 + int charge_full; 69 + int charge_counter; 70 + int capacity; 71 + int flags; 72 + 73 + int current_now; 74 + }; 75 + 76 struct bq27x00_device_info { 77 struct device *dev; 78 int id; 79 enum bq27x00_chip chip; 80 81 + struct bq27x00_reg_cache cache; 82 + int charge_design_full; 83 + 84 + unsigned long last_update; 85 + struct delayed_work work; 86 + 87 + struct power_supply bat; 88 + 89 + struct bq27x00_access_methods bus; 90 + 91 + struct mutex lock; 92 }; 93 94 static enum power_supply_property bq27x00_battery_props[] = { ··· 78 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 79 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 80 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, 81 + POWER_SUPPLY_PROP_TECHNOLOGY, 82 + POWER_SUPPLY_PROP_CHARGE_FULL, 83 + POWER_SUPPLY_PROP_CHARGE_NOW, 84 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 85 + POWER_SUPPLY_PROP_CHARGE_COUNTER, 86 + POWER_SUPPLY_PROP_ENERGY_NOW, 87 }; 88 + 89 + static unsigned int poll_interval = 360; 90 + module_param(poll_interval, uint, 0644); 91 + MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \ 92 + "0 disables polling"); 93 94 /* 95 * Common code for BQ27x00 devices 96 */ 97 98 + static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg, 99 + bool single) 100 { 101 + return di->bus.read(di, reg, single); 102 } 103 104 /* 105 * Return the battery Relative State-of-Charge 106 * Or < 0 if something fails. 107 */ 108 + static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di) 109 { 110 + int rsoc; 111 112 if (di->chip == BQ27500) 113 + rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); 114 else 115 + rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true); 116 + 117 + if (rsoc < 0) 118 dev_err(di->dev, "error reading relative State-of-Charge\n"); 119 120 return rsoc; 121 } 122 123 + /* 124 + * Return a battery charge value in µAh 125 + * Or < 0 if something fails. 126 + */ 127 + static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg) 128 { 129 + int charge; 130 131 + charge = bq27x00_read(di, reg, false); 132 + if (charge < 0) { 133 + dev_err(di->dev, "error reading nominal available capacity\n"); 134 + return charge; 135 } 136 137 + if (di->chip == BQ27500) 138 + charge *= 1000; 139 + else 140 + charge = charge * 3570 / BQ27000_RS; 141 + 142 + return charge; 143 + } 144 + 145 + /* 146 + * Return the battery Nominal available capaciy in µAh 147 + * Or < 0 if something fails. 148 + */ 149 + static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di) 150 + { 151 + return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC); 152 + } 153 + 154 + /* 155 + * Return the battery Last measured discharge in µAh 156 + * Or < 0 if something fails. 157 + */ 158 + static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di) 159 + { 160 + return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD); 161 + } 162 + 163 + /* 164 + * Return the battery Initial last measured discharge in µAh 165 + * Or < 0 if something fails. 166 + */ 167 + static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di) 168 + { 169 + int ilmd; 170 + 171 + if (di->chip == BQ27500) 172 + ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false); 173 + else 174 + ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true); 175 + 176 + if (ilmd < 0) { 177 + dev_err(di->dev, "error reading initial last measured discharge\n"); 178 + return ilmd; 179 } 180 181 + if (di->chip == BQ27500) 182 + ilmd *= 1000; 183 + else 184 + ilmd = ilmd * 256 * 3570 / BQ27000_RS; 185 + 186 + return ilmd; 187 + } 188 + 189 + /* 190 + * Return the battery Cycle count total 191 + * Or < 0 if something fails. 192 + */ 193 + static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di) 194 + { 195 + int cyct; 196 + 197 + cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false); 198 + if (cyct < 0) 199 + dev_err(di->dev, "error reading cycle count total\n"); 200 + 201 + return cyct; 202 } 203 204 /* 205 * Read a time register. 206 * Return < 0 if something fails. 207 */ 208 + static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg) 209 { 210 + int tval; 211 212 + tval = bq27x00_read(di, reg, false); 213 + if (tval < 0) { 214 + dev_err(di->dev, "error reading register %02x: %d\n", reg, tval); 215 + return tval; 216 } 217 218 if (tval == 65535) 219 return -ENODATA; 220 221 + return tval * 60; 222 + } 223 + 224 + static void bq27x00_update(struct bq27x00_device_info *di) 225 + { 226 + struct bq27x00_reg_cache cache = {0, }; 227 + bool is_bq27500 = di->chip == BQ27500; 228 + 229 + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500); 230 + if (cache.flags >= 0) { 231 + cache.capacity = bq27x00_battery_read_rsoc(di); 232 + cache.temperature = bq27x00_read(di, BQ27x00_REG_TEMP, false); 233 + cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE); 234 + cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP); 235 + cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF); 236 + cache.charge_full = bq27x00_battery_read_lmd(di); 237 + cache.charge_counter = bq27x00_battery_read_cyct(di); 238 + 239 + if (!is_bq27500) 240 + cache.current_now = bq27x00_read(di, BQ27x00_REG_AI, false); 241 + 242 + /* We only have to read charge design full once */ 243 + if (di->charge_design_full <= 0) 244 + di->charge_design_full = bq27x00_battery_read_ilmd(di); 245 + } 246 + 247 + /* Ignore current_now which is a snapshot of the current battery state 248 + * and is likely to be different even between two consecutive reads */ 249 + if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) { 250 + di->cache = cache; 251 + power_supply_changed(&di->bat); 252 + } 253 + 254 + di->last_update = jiffies; 255 + } 256 + 257 + static void bq27x00_battery_poll(struct work_struct *work) 258 + { 259 + struct bq27x00_device_info *di = 260 + container_of(work, struct bq27x00_device_info, work.work); 261 + 262 + bq27x00_update(di); 263 + 264 + if (poll_interval > 0) { 265 + /* The timer does not have to be accurate. */ 266 + set_timer_slack(&di->work.timer, poll_interval * HZ / 4); 267 + schedule_delayed_work(&di->work, poll_interval * HZ); 268 + } 269 + } 270 + 271 + 272 + /* 273 + * Return the battery temperature in tenths of degree Celsius 274 + * Or < 0 if something fails. 275 + */ 276 + static int bq27x00_battery_temperature(struct bq27x00_device_info *di, 277 + union power_supply_propval *val) 278 + { 279 + if (di->cache.temperature < 0) 280 + return di->cache.temperature; 281 + 282 + if (di->chip == BQ27500) 283 + val->intval = di->cache.temperature - 2731; 284 + else 285 + val->intval = ((di->cache.temperature * 5) - 5463) / 2; 286 + 287 + return 0; 288 + } 289 + 290 + /* 291 + * Return the battery average current in µA 292 + * Note that current can be negative signed as well 293 + * Or 0 if something fails. 294 + */ 295 + static int bq27x00_battery_current(struct bq27x00_device_info *di, 296 + union power_supply_propval *val) 297 + { 298 + int curr; 299 + 300 + if (di->chip == BQ27500) 301 + curr = bq27x00_read(di, BQ27x00_REG_AI, false); 302 + else 303 + curr = di->cache.current_now; 304 + 305 + if (curr < 0) 306 + return curr; 307 + 308 + if (di->chip == BQ27500) { 309 + /* bq27500 returns signed value */ 310 + val->intval = (int)((s16)curr) * 1000; 311 + } else { 312 + if (di->cache.flags & BQ27000_FLAG_CHGS) { 313 + dev_dbg(di->dev, "negative current!\n"); 314 + curr = -curr; 315 + } 316 + 317 + val->intval = curr * 3570 / BQ27000_RS; 318 + } 319 + 320 + return 0; 321 + } 322 + 323 + static int bq27x00_battery_status(struct bq27x00_device_info *di, 324 + union power_supply_propval *val) 325 + { 326 + int status; 327 + 328 + if (di->chip == BQ27500) { 329 + if (di->cache.flags & BQ27500_FLAG_FC) 330 + status = POWER_SUPPLY_STATUS_FULL; 331 + else if (di->cache.flags & BQ27500_FLAG_DSC) 332 + status = POWER_SUPPLY_STATUS_DISCHARGING; 333 + else 334 + status = POWER_SUPPLY_STATUS_CHARGING; 335 + } else { 336 + if (di->cache.flags & BQ27000_FLAG_FC) 337 + status = POWER_SUPPLY_STATUS_FULL; 338 + else if (di->cache.flags & BQ27000_FLAG_CHGS) 339 + status = POWER_SUPPLY_STATUS_CHARGING; 340 + else if (power_supply_am_i_supplied(&di->bat)) 341 + status = POWER_SUPPLY_STATUS_NOT_CHARGING; 342 + else 343 + status = POWER_SUPPLY_STATUS_DISCHARGING; 344 + } 345 + 346 + val->intval = status; 347 + 348 + return 0; 349 + } 350 + 351 + /* 352 + * Return the battery Voltage in milivolts 353 + * Or < 0 if something fails. 354 + */ 355 + static int bq27x00_battery_voltage(struct bq27x00_device_info *di, 356 + union power_supply_propval *val) 357 + { 358 + int volt; 359 + 360 + volt = bq27x00_read(di, BQ27x00_REG_VOLT, false); 361 + if (volt < 0) 362 + return volt; 363 + 364 + val->intval = volt * 1000; 365 + 366 + return 0; 367 + } 368 + 369 + /* 370 + * Return the battery Available energy in µWh 371 + * Or < 0 if something fails. 372 + */ 373 + static int bq27x00_battery_energy(struct bq27x00_device_info *di, 374 + union power_supply_propval *val) 375 + { 376 + int ae; 377 + 378 + ae = bq27x00_read(di, BQ27x00_REG_AE, false); 379 + if (ae < 0) { 380 + dev_err(di->dev, "error reading available energy\n"); 381 + return ae; 382 + } 383 + 384 + if (di->chip == BQ27500) 385 + ae *= 1000; 386 + else 387 + ae = ae * 29200 / BQ27000_RS; 388 + 389 + val->intval = ae; 390 + 391 + return 0; 392 + } 393 + 394 + 395 + static int bq27x00_simple_value(int value, 396 + union power_supply_propval *val) 397 + { 398 + if (value < 0) 399 + return value; 400 + 401 + val->intval = value; 402 + 403 return 0; 404 } 405 ··· 249 int ret = 0; 250 struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 251 252 + mutex_lock(&di->lock); 253 + if (time_is_before_jiffies(di->last_update + 5 * HZ)) { 254 + cancel_delayed_work_sync(&di->work); 255 + bq27x00_battery_poll(&di->work.work); 256 + } 257 + mutex_unlock(&di->lock); 258 + 259 + if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0) 260 + return -ENODEV; 261 + 262 switch (psp) { 263 case POWER_SUPPLY_PROP_STATUS: 264 ret = bq27x00_battery_status(di, val); 265 break; 266 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 267 + ret = bq27x00_battery_voltage(di, val); 268 + break; 269 case POWER_SUPPLY_PROP_PRESENT: 270 + val->intval = di->cache.flags < 0 ? 0 : 1; 271 break; 272 case POWER_SUPPLY_PROP_CURRENT_NOW: 273 + ret = bq27x00_battery_current(di, val); 274 break; 275 case POWER_SUPPLY_PROP_CAPACITY: 276 + ret = bq27x00_simple_value(di->cache.capacity, val); 277 break; 278 case POWER_SUPPLY_PROP_TEMP: 279 + ret = bq27x00_battery_temperature(di, val); 280 break; 281 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: 282 + ret = bq27x00_simple_value(di->cache.time_to_empty, val); 283 break; 284 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 285 + ret = bq27x00_simple_value(di->cache.time_to_empty_avg, val); 286 break; 287 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: 288 + ret = bq27x00_simple_value(di->cache.time_to_full, val); 289 + break; 290 + case POWER_SUPPLY_PROP_TECHNOLOGY: 291 + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; 292 + break; 293 + case POWER_SUPPLY_PROP_CHARGE_NOW: 294 + ret = bq27x00_simple_value(bq27x00_battery_read_nac(di), val); 295 + break; 296 + case POWER_SUPPLY_PROP_CHARGE_FULL: 297 + ret = bq27x00_simple_value(di->cache.charge_full, val); 298 + break; 299 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 300 + ret = bq27x00_simple_value(di->charge_design_full, val); 301 + break; 302 + case POWER_SUPPLY_PROP_CHARGE_COUNTER: 303 + ret = bq27x00_simple_value(di->cache.charge_counter, val); 304 + break; 305 + case POWER_SUPPLY_PROP_ENERGY_NOW: 306 + ret = bq27x00_battery_energy(di, val); 307 break; 308 default: 309 return -EINVAL; ··· 284 return ret; 285 } 286 287 + static void bq27x00_external_power_changed(struct power_supply *psy) 288 { 289 + struct bq27x00_device_info *di = to_bq27x00_device_info(psy); 290 + 291 + cancel_delayed_work_sync(&di->work); 292 + schedule_delayed_work(&di->work, 0); 293 + } 294 + 295 + static int bq27x00_powersupply_init(struct bq27x00_device_info *di) 296 + { 297 + int ret; 298 + 299 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 300 di->bat.properties = bq27x00_battery_props; 301 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); 302 di->bat.get_property = bq27x00_battery_get_property; 303 + di->bat.external_power_changed = bq27x00_external_power_changed; 304 + 305 + INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll); 306 + mutex_init(&di->lock); 307 + 308 + ret = power_supply_register(di->dev, &di->bat); 309 + if (ret) { 310 + dev_err(di->dev, "failed to register battery: %d\n", ret); 311 + return ret; 312 + } 313 + 314 + dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); 315 + 316 + bq27x00_update(di); 317 + 318 + return 0; 319 } 320 321 + static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di) 322 { 323 + cancel_delayed_work_sync(&di->work); 324 + 325 + power_supply_unregister(&di->bat); 326 + 327 + mutex_destroy(&di->lock); 328 + } 329 + 330 + 331 + /* i2c specific code */ 332 + #ifdef CONFIG_BATTERY_BQ27X00_I2C 333 + 334 + /* If the system has several batteries we need a different name for each 335 + * of them... 336 + */ 337 + static DEFINE_IDR(battery_id); 338 + static DEFINE_MUTEX(battery_mutex); 339 + 340 + static int bq27x00_read_i2c(struct bq27x00_device_info *di, u8 reg, bool single) 341 + { 342 + struct i2c_client *client = to_i2c_client(di->dev); 343 + struct i2c_msg msg[2]; 344 unsigned char data[2]; 345 + int ret; 346 347 if (!client->adapter) 348 return -ENODEV; 349 350 + msg[0].addr = client->addr; 351 + msg[0].flags = 0; 352 + msg[0].buf = &reg; 353 + msg[0].len = sizeof(reg); 354 + msg[1].addr = client->addr; 355 + msg[1].flags = I2C_M_RD; 356 + msg[1].buf = data; 357 + if (single) 358 + msg[1].len = 1; 359 + else 360 + msg[1].len = 2; 361 362 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 363 + if (ret < 0) 364 + return ret; 365 366 + if (!single) 367 + ret = get_unaligned_le16(data); 368 + else 369 + ret = data[0]; 370 371 + return ret; 372 } 373 374 static int bq27x00_battery_probe(struct i2c_client *client, ··· 341 { 342 char *name; 343 struct bq27x00_device_info *di; 344 int num; 345 int retval = 0; 346 ··· 368 retval = -ENOMEM; 369 goto batt_failed_2; 370 } 371 372 + di->id = num; 373 + di->dev = &client->dev; 374 + di->chip = id->driver_data; 375 + di->bat.name = name; 376 + di->bus.read = &bq27x00_read_i2c; 377 + 378 + if (bq27x00_powersupply_init(di)) 379 goto batt_failed_3; 380 381 i2c_set_clientdata(client, di); 382 383 return 0; 384 385 batt_failed_3: 386 kfree(di); 387 batt_failed_2: ··· 416 { 417 struct bq27x00_device_info *di = i2c_get_clientdata(client); 418 419 + bq27x00_powersupply_unregister(di); 420 421 kfree(di->bat.name); 422 423 mutex_lock(&battery_mutex); ··· 430 return 0; 431 } 432 433 static const struct i2c_device_id bq27x00_id[] = { 434 { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ 435 { "bq27500", BQ27500 }, 436 {}, 437 }; 438 + MODULE_DEVICE_TABLE(i2c, bq27x00_id); 439 440 static struct i2c_driver bq27x00_battery_driver = { 441 .driver = { ··· 449 .id_table = bq27x00_id, 450 }; 451 452 + static inline int bq27x00_battery_i2c_init(void) 453 + { 454 + int ret = i2c_add_driver(&bq27x00_battery_driver); 455 + if (ret) 456 + printk(KERN_ERR "Unable to register BQ27x00 i2c driver\n"); 457 + 458 + return ret; 459 + } 460 + 461 + static inline void bq27x00_battery_i2c_exit(void) 462 + { 463 + i2c_del_driver(&bq27x00_battery_driver); 464 + } 465 + 466 + #else 467 + 468 + static inline int bq27x00_battery_i2c_init(void) { return 0; } 469 + static inline void bq27x00_battery_i2c_exit(void) {}; 470 + 471 + #endif 472 + 473 + /* platform specific code */ 474 + #ifdef CONFIG_BATTERY_BQ27X00_PLATFORM 475 + 476 + static int bq27000_read_platform(struct bq27x00_device_info *di, u8 reg, 477 + bool single) 478 + { 479 + struct device *dev = di->dev; 480 + struct bq27000_platform_data *pdata = dev->platform_data; 481 + unsigned int timeout = 3; 482 + int upper, lower; 483 + int temp; 484 + 485 + if (!single) { 486 + /* Make sure the value has not changed in between reading the 487 + * lower and the upper part */ 488 + upper = pdata->read(dev, reg + 1); 489 + do { 490 + temp = upper; 491 + if (upper < 0) 492 + return upper; 493 + 494 + lower = pdata->read(dev, reg); 495 + if (lower < 0) 496 + return lower; 497 + 498 + upper = pdata->read(dev, reg + 1); 499 + } while (temp != upper && --timeout); 500 + 501 + if (timeout == 0) 502 + return -EIO; 503 + 504 + return (upper << 8) | lower; 505 + } 506 + 507 + return pdata->read(dev, reg); 508 + } 509 + 510 + static int __devinit bq27000_battery_probe(struct platform_device *pdev) 511 + { 512 + struct bq27x00_device_info *di; 513 + struct bq27000_platform_data *pdata = pdev->dev.platform_data; 514 + int ret; 515 + 516 + if (!pdata) { 517 + dev_err(&pdev->dev, "no platform_data supplied\n"); 518 + return -EINVAL; 519 + } 520 + 521 + if (!pdata->read) { 522 + dev_err(&pdev->dev, "no hdq read callback supplied\n"); 523 + return -EINVAL; 524 + } 525 + 526 + di = kzalloc(sizeof(*di), GFP_KERNEL); 527 + if (!di) { 528 + dev_err(&pdev->dev, "failed to allocate device info data\n"); 529 + return -ENOMEM; 530 + } 531 + 532 + platform_set_drvdata(pdev, di); 533 + 534 + di->dev = &pdev->dev; 535 + di->chip = BQ27000; 536 + 537 + di->bat.name = pdata->name ?: dev_name(&pdev->dev); 538 + di->bus.read = &bq27000_read_platform; 539 + 540 + ret = bq27x00_powersupply_init(di); 541 + if (ret) 542 + goto err_free; 543 + 544 + return 0; 545 + 546 + err_free: 547 + platform_set_drvdata(pdev, NULL); 548 + kfree(di); 549 + 550 + return ret; 551 + } 552 + 553 + static int __devexit bq27000_battery_remove(struct platform_device *pdev) 554 + { 555 + struct bq27x00_device_info *di = platform_get_drvdata(pdev); 556 + 557 + bq27x00_powersupply_unregister(di); 558 + 559 + platform_set_drvdata(pdev, NULL); 560 + kfree(di); 561 + 562 + return 0; 563 + } 564 + 565 + static struct platform_driver bq27000_battery_driver = { 566 + .probe = bq27000_battery_probe, 567 + .remove = __devexit_p(bq27000_battery_remove), 568 + .driver = { 569 + .name = "bq27000-battery", 570 + .owner = THIS_MODULE, 571 + }, 572 + }; 573 + 574 + static inline int bq27x00_battery_platform_init(void) 575 + { 576 + int ret = platform_driver_register(&bq27000_battery_driver); 577 + if (ret) 578 + printk(KERN_ERR "Unable to register BQ27000 platform driver\n"); 579 + 580 + return ret; 581 + } 582 + 583 + static inline void bq27x00_battery_platform_exit(void) 584 + { 585 + platform_driver_unregister(&bq27000_battery_driver); 586 + } 587 + 588 + #else 589 + 590 + static inline int bq27x00_battery_platform_init(void) { return 0; } 591 + static inline void bq27x00_battery_platform_exit(void) {}; 592 + 593 + #endif 594 + 595 + /* 596 + * Module stuff 597 + */ 598 + 599 static int __init bq27x00_battery_init(void) 600 { 601 int ret; 602 603 + ret = bq27x00_battery_i2c_init(); 604 if (ret) 605 + return ret; 606 + 607 + ret = bq27x00_battery_platform_init(); 608 + if (ret) 609 + bq27x00_battery_i2c_exit(); 610 611 return ret; 612 } ··· 463 464 static void __exit bq27x00_battery_exit(void) 465 { 466 + bq27x00_battery_platform_exit(); 467 + bq27x00_battery_i2c_exit(); 468 } 469 module_exit(bq27x00_battery_exit); 470
+1
drivers/power/ds2782_battery.c
··· 393 {"ds2786", DS2786}, 394 {}, 395 }; 396 397 static struct i2c_driver ds278x_battery_driver = { 398 .driver = {
··· 393 {"ds2786", DS2786}, 394 {}, 395 }; 396 + MODULE_DEVICE_TABLE(i2c, ds278x_id); 397 398 static struct i2c_driver ds278x_battery_driver = { 399 .driver = {
+2 -2
drivers/power/power_supply_core.c
··· 171 dev_set_drvdata(dev, psy); 172 psy->dev = dev; 173 174 rc = kobject_set_name(&dev->kobj, "%s", psy->name); 175 if (rc) 176 goto kobject_set_name_failed; ··· 180 rc = device_add(dev); 181 if (rc) 182 goto device_add_failed; 183 - 184 - INIT_WORK(&psy->changed_work, power_supply_changed_work); 185 186 rc = power_supply_create_triggers(psy); 187 if (rc)
··· 171 dev_set_drvdata(dev, psy); 172 psy->dev = dev; 173 174 + INIT_WORK(&psy->changed_work, power_supply_changed_work); 175 + 176 rc = kobject_set_name(&dev->kobj, "%s", psy->name); 177 if (rc) 178 goto kobject_set_name_failed; ··· 178 rc = device_add(dev); 179 if (rc) 180 goto device_add_failed; 181 182 rc = power_supply_create_triggers(psy); 183 if (rc)
+19
drivers/power/power_supply_leds.c
··· 21 static void power_supply_update_bat_leds(struct power_supply *psy) 22 { 23 union power_supply_propval status; 24 25 if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status)) 26 return; ··· 34 led_trigger_event(psy->charging_full_trig, LED_FULL); 35 led_trigger_event(psy->charging_trig, LED_OFF); 36 led_trigger_event(psy->full_trig, LED_FULL); 37 break; 38 case POWER_SUPPLY_STATUS_CHARGING: 39 led_trigger_event(psy->charging_full_trig, LED_FULL); 40 led_trigger_event(psy->charging_trig, LED_FULL); 41 led_trigger_event(psy->full_trig, LED_OFF); 42 break; 43 default: 44 led_trigger_event(psy->charging_full_trig, LED_OFF); 45 led_trigger_event(psy->charging_trig, LED_OFF); 46 led_trigger_event(psy->full_trig, LED_OFF); 47 break; 48 } 49 } ··· 72 if (!psy->full_trig_name) 73 goto full_failed; 74 75 led_trigger_register_simple(psy->charging_full_trig_name, 76 &psy->charging_full_trig); 77 led_trigger_register_simple(psy->charging_trig_name, 78 &psy->charging_trig); 79 led_trigger_register_simple(psy->full_trig_name, 80 &psy->full_trig); 81 82 goto success; 83 84 full_failed: 85 kfree(psy->charging_trig_name); 86 charging_failed: ··· 105 led_trigger_unregister_simple(psy->charging_full_trig); 106 led_trigger_unregister_simple(psy->charging_trig); 107 led_trigger_unregister_simple(psy->full_trig); 108 kfree(psy->full_trig_name); 109 kfree(psy->charging_trig_name); 110 kfree(psy->charging_full_trig_name);
··· 21 static void power_supply_update_bat_leds(struct power_supply *psy) 22 { 23 union power_supply_propval status; 24 + unsigned long delay_on = 0; 25 + unsigned long delay_off = 0; 26 27 if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status)) 28 return; ··· 32 led_trigger_event(psy->charging_full_trig, LED_FULL); 33 led_trigger_event(psy->charging_trig, LED_OFF); 34 led_trigger_event(psy->full_trig, LED_FULL); 35 + led_trigger_event(psy->charging_blink_full_solid_trig, 36 + LED_FULL); 37 break; 38 case POWER_SUPPLY_STATUS_CHARGING: 39 led_trigger_event(psy->charging_full_trig, LED_FULL); 40 led_trigger_event(psy->charging_trig, LED_FULL); 41 led_trigger_event(psy->full_trig, LED_OFF); 42 + led_trigger_blink(psy->charging_blink_full_solid_trig, 43 + &delay_on, &delay_off); 44 break; 45 default: 46 led_trigger_event(psy->charging_full_trig, LED_OFF); 47 led_trigger_event(psy->charging_trig, LED_OFF); 48 led_trigger_event(psy->full_trig, LED_OFF); 49 + led_trigger_event(psy->charging_blink_full_solid_trig, 50 + LED_OFF); 51 break; 52 } 53 } ··· 64 if (!psy->full_trig_name) 65 goto full_failed; 66 67 + psy->charging_blink_full_solid_trig_name = kasprintf(GFP_KERNEL, 68 + "%s-charging-blink-full-solid", psy->name); 69 + if (!psy->charging_blink_full_solid_trig_name) 70 + goto charging_blink_full_solid_failed; 71 + 72 led_trigger_register_simple(psy->charging_full_trig_name, 73 &psy->charging_full_trig); 74 led_trigger_register_simple(psy->charging_trig_name, 75 &psy->charging_trig); 76 led_trigger_register_simple(psy->full_trig_name, 77 &psy->full_trig); 78 + led_trigger_register_simple(psy->charging_blink_full_solid_trig_name, 79 + &psy->charging_blink_full_solid_trig); 80 81 goto success; 82 83 + charging_blink_full_solid_failed: 84 + kfree(psy->full_trig_name); 85 full_failed: 86 kfree(psy->charging_trig_name); 87 charging_failed: ··· 88 led_trigger_unregister_simple(psy->charging_full_trig); 89 led_trigger_unregister_simple(psy->charging_trig); 90 led_trigger_unregister_simple(psy->full_trig); 91 + led_trigger_unregister_simple(psy->charging_blink_full_solid_trig); 92 + kfree(psy->charging_blink_full_solid_trig_name); 93 kfree(psy->full_trig_name); 94 kfree(psy->charging_trig_name); 95 kfree(psy->charging_full_trig_name);
+1 -1
drivers/power/power_supply_sysfs.c
··· 270 attr = &power_supply_attrs[psy->properties[j]]; 271 272 ret = power_supply_show_property(dev, attr, prop_buf); 273 - if (ret == -ENODEV) { 274 /* When a battery is absent, we expect -ENODEV. Don't abort; 275 send the uevent with at least the the PRESENT=0 property */ 276 ret = 0;
··· 270 attr = &power_supply_attrs[psy->properties[j]]; 271 272 ret = power_supply_show_property(dev, attr, prop_buf); 273 + if (ret == -ENODEV || ret == -ENODATA) { 274 /* When a battery is absent, we expect -ENODEV. Don't abort; 275 send the uevent with at least the the PRESENT=0 property */ 276 ret = 0;
+2 -2
drivers/power/s3c_adc_battery.c
··· 406 return 0; 407 } 408 #else 409 - #define s3c_adc_battery_suspend NULL 410 - #define s3c_adc_battery_resume NULL 411 #endif 412 413 static struct platform_driver s3c_adc_bat_driver = {
··· 406 return 0; 407 } 408 #else 409 + #define s3c_adc_bat_suspend NULL 410 + #define s3c_adc_bat_resume NULL 411 #endif 412 413 static struct platform_driver s3c_adc_bat_driver = {
+19 -6
drivers/power/twl4030_charger.c
··· 71 struct power_supply usb; 72 struct otg_transceiver *transceiver; 73 struct notifier_block otg_nb; 74 int irq_chg; 75 int irq_bci; 76 }; 77 78 /* ··· 261 return IRQ_HANDLED; 262 } 263 264 - static int twl4030_bci_usb_ncb(struct notifier_block *nb, unsigned long val, 265 - void *priv) 266 { 267 - struct twl4030_bci *bci = container_of(nb, struct twl4030_bci, otg_nb); 268 269 - dev_dbg(bci->dev, "OTG notify %lu\n", val); 270 - 271 - switch (val) { 272 case USB_EVENT_VBUS: 273 case USB_EVENT_CHARGER: 274 twl4030_charger_enable_usb(bci, true); ··· 274 twl4030_charger_enable_usb(bci, false); 275 break; 276 } 277 278 return NOTIFY_OK; 279 } ··· 476 bci->irq_bci, ret); 477 goto fail_bci_irq; 478 } 479 480 bci->transceiver = otg_get_transceiver(); 481 if (bci->transceiver != NULL) {
··· 71 struct power_supply usb; 72 struct otg_transceiver *transceiver; 73 struct notifier_block otg_nb; 74 + struct work_struct work; 75 int irq_chg; 76 int irq_bci; 77 + 78 + unsigned long event; 79 }; 80 81 /* ··· 258 return IRQ_HANDLED; 259 } 260 261 + static void twl4030_bci_usb_work(struct work_struct *data) 262 { 263 + struct twl4030_bci *bci = container_of(data, struct twl4030_bci, work); 264 265 + switch (bci->event) { 266 case USB_EVENT_VBUS: 267 case USB_EVENT_CHARGER: 268 twl4030_charger_enable_usb(bci, true); ··· 274 twl4030_charger_enable_usb(bci, false); 275 break; 276 } 277 + } 278 + 279 + static int twl4030_bci_usb_ncb(struct notifier_block *nb, unsigned long val, 280 + void *priv) 281 + { 282 + struct twl4030_bci *bci = container_of(nb, struct twl4030_bci, otg_nb); 283 + 284 + dev_dbg(bci->dev, "OTG notify %lu\n", val); 285 + 286 + bci->event = val; 287 + schedule_work(&bci->work); 288 289 return NOTIFY_OK; 290 } ··· 465 bci->irq_bci, ret); 466 goto fail_bci_irq; 467 } 468 + 469 + INIT_WORK(&bci->work, twl4030_bci_usb_work); 470 471 bci->transceiver = otg_get_transceiver(); 472 if (bci->transceiver != NULL) {
+3
drivers/power/z2_battery.c
··· 134 enum power_supply_property *prop; 135 struct z2_battery_info *info = charger->info; 136 137 if (info->batt_tech >= 0) 138 props++; /* POWER_SUPPLY_PROP_TECHNOLOGY */ 139 if (info->batt_I2C_reg >= 0) ··· 295 { "aer915", 0 }, 296 { } 297 }; 298 299 static struct i2c_driver z2_batt_driver = { 300 .driver = {
··· 134 enum power_supply_property *prop; 135 struct z2_battery_info *info = charger->info; 136 137 + if (info->charge_gpio >= 0) 138 + props++; /* POWER_SUPPLY_PROP_STATUS */ 139 if (info->batt_tech >= 0) 140 props++; /* POWER_SUPPLY_PROP_TECHNOLOGY */ 141 if (info->batt_I2C_reg >= 0) ··· 293 { "aer915", 0 }, 294 { } 295 }; 296 + MODULE_DEVICE_TABLE(i2c, z2_batt_id); 297 298 static struct i2c_driver z2_batt_driver = { 299 .driver = {
+3
include/linux/leds.h
··· 145 extern void led_trigger_unregister_simple(struct led_trigger *trigger); 146 extern void led_trigger_event(struct led_trigger *trigger, 147 enum led_brightness event); 148 149 #else 150
··· 145 extern void led_trigger_unregister_simple(struct led_trigger *trigger); 146 extern void led_trigger_event(struct led_trigger *trigger, 147 enum led_brightness event); 148 + extern void led_trigger_blink(struct led_trigger *trigger, 149 + unsigned long *delay_on, 150 + unsigned long *delay_off); 151 152 #else 153
+39
include/linux/power/bq20z75.h
···
··· 1 + /* 2 + * Gas Gauge driver for TI's BQ20Z75 3 + * 4 + * Copyright (c) 2010, NVIDIA Corporation. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, but WITHOUT 12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 + * more details. 15 + * 16 + * You should have received a copy of the GNU General Public License along 17 + * with this program; if not, write to the Free Software Foundation, Inc., 18 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 + */ 20 + 21 + #ifndef __LINUX_POWER_BQ20Z75_H_ 22 + #define __LINUX_POWER_BQ20Z75_H_ 23 + 24 + #include <linux/power_supply.h> 25 + #include <linux/types.h> 26 + 27 + /** 28 + * struct bq20z75_platform_data - platform data for bq20z75 devices 29 + * @battery_detect: GPIO which is used to detect battery presence 30 + * @battery_detect_present: gpio state when battery is present (0 / 1) 31 + * @i2c_retry_count: # of times to retry on i2c IO failure 32 + */ 33 + struct bq20z75_platform_data { 34 + int battery_detect; 35 + int battery_detect_present; 36 + int i2c_retry_count; 37 + }; 38 + 39 + #endif
+19
include/linux/power/bq27x00_battery.h
···
··· 1 + #ifndef __LINUX_BQ27X00_BATTERY_H__ 2 + #define __LINUX_BQ27X00_BATTERY_H__ 3 + 4 + /** 5 + * struct bq27000_plaform_data - Platform data for bq27000 devices 6 + * @name: Name of the battery. If NULL the driver will fallback to "bq27000". 7 + * @read: HDQ read callback. 8 + * This function should provide access to the HDQ bus the battery is 9 + * connected to. 10 + * The first parameter is a pointer to the battery device, the second the 11 + * register to be read. The return value should either be the content of 12 + * the passed register or an error value. 13 + */ 14 + struct bq27000_platform_data { 15 + const char *name; 16 + int (*read)(struct device *dev, unsigned int); 17 + }; 18 + 19 + #endif
+47
include/linux/power_supply.h
··· 173 char *full_trig_name; 174 struct led_trigger *online_trig; 175 char *online_trig_name; 176 #endif 177 }; 178 ··· 214 215 /* For APM emulation, think legacy userspace. */ 216 extern struct class *power_supply_class; 217 218 #endif /* __LINUX_POWER_SUPPLY_H__ */
··· 173 char *full_trig_name; 174 struct led_trigger *online_trig; 175 char *online_trig_name; 176 + struct led_trigger *charging_blink_full_solid_trig; 177 + char *charging_blink_full_solid_trig_name; 178 #endif 179 }; 180 ··· 212 213 /* For APM emulation, think legacy userspace. */ 214 extern struct class *power_supply_class; 215 + 216 + static inline bool power_supply_is_amp_property(enum power_supply_property psp) 217 + { 218 + switch (psp) { 219 + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 220 + case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: 221 + case POWER_SUPPLY_PROP_CHARGE_FULL: 222 + case POWER_SUPPLY_PROP_CHARGE_EMPTY: 223 + case POWER_SUPPLY_PROP_CHARGE_NOW: 224 + case POWER_SUPPLY_PROP_CHARGE_AVG: 225 + case POWER_SUPPLY_PROP_CHARGE_COUNTER: 226 + case POWER_SUPPLY_PROP_CURRENT_MAX: 227 + case POWER_SUPPLY_PROP_CURRENT_NOW: 228 + case POWER_SUPPLY_PROP_CURRENT_AVG: 229 + return 1; 230 + default: 231 + break; 232 + } 233 + 234 + return 0; 235 + } 236 + 237 + static inline bool power_supply_is_watt_property(enum power_supply_property psp) 238 + { 239 + switch (psp) { 240 + case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 241 + case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN: 242 + case POWER_SUPPLY_PROP_ENERGY_FULL: 243 + case POWER_SUPPLY_PROP_ENERGY_EMPTY: 244 + case POWER_SUPPLY_PROP_ENERGY_NOW: 245 + case POWER_SUPPLY_PROP_ENERGY_AVG: 246 + case POWER_SUPPLY_PROP_VOLTAGE_MAX: 247 + case POWER_SUPPLY_PROP_VOLTAGE_MIN: 248 + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 249 + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 250 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 251 + case POWER_SUPPLY_PROP_VOLTAGE_AVG: 252 + case POWER_SUPPLY_PROP_POWER_NOW: 253 + return 1; 254 + default: 255 + break; 256 + } 257 + 258 + return 0; 259 + } 260 261 #endif /* __LINUX_POWER_SUPPLY_H__ */