| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Gas Gauge driver for SBS Compliant Batteries |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 8 | +#include <linux/bits.h> |
|---|
| 17 | 9 | #include <linux/delay.h> |
|---|
| 18 | 10 | #include <linux/err.h> |
|---|
| 19 | 11 | #include <linux/gpio/consumer.h> |
|---|
| .. | .. |
|---|
| 22 | 14 | #include <linux/interrupt.h> |
|---|
| 23 | 15 | #include <linux/kernel.h> |
|---|
| 24 | 16 | #include <linux/module.h> |
|---|
| 25 | | -#include <linux/of.h> |
|---|
| 17 | +#include <linux/property.h> |
|---|
| 26 | 18 | #include <linux/of_device.h> |
|---|
| 27 | 19 | #include <linux/power/sbs-battery.h> |
|---|
| 28 | 20 | #include <linux/power_supply.h> |
|---|
| .. | .. |
|---|
| 31 | 23 | |
|---|
| 32 | 24 | enum { |
|---|
| 33 | 25 | REG_MANUFACTURER_DATA, |
|---|
| 26 | + REG_BATTERY_MODE, |
|---|
| 34 | 27 | REG_TEMPERATURE, |
|---|
| 35 | 28 | REG_VOLTAGE, |
|---|
| 36 | | - REG_CURRENT, |
|---|
| 29 | + REG_CURRENT_NOW, |
|---|
| 30 | + REG_CURRENT_AVG, |
|---|
| 31 | + REG_MAX_ERR, |
|---|
| 37 | 32 | REG_CAPACITY, |
|---|
| 38 | 33 | REG_TIME_TO_EMPTY, |
|---|
| 39 | 34 | REG_TIME_TO_FULL, |
|---|
| .. | .. |
|---|
| 49 | 44 | REG_DESIGN_CAPACITY_CHARGE, |
|---|
| 50 | 45 | REG_DESIGN_VOLTAGE_MIN, |
|---|
| 51 | 46 | REG_DESIGN_VOLTAGE_MAX, |
|---|
| 47 | + REG_CHEMISTRY, |
|---|
| 52 | 48 | REG_MANUFACTURER, |
|---|
| 53 | 49 | REG_MODEL_NAME, |
|---|
| 50 | + REG_CHARGE_CURRENT, |
|---|
| 51 | + REG_CHARGE_VOLTAGE, |
|---|
| 54 | 52 | }; |
|---|
| 53 | + |
|---|
| 54 | +#define REG_ADDR_SPEC_INFO 0x1A |
|---|
| 55 | +#define SPEC_INFO_VERSION_MASK GENMASK(7, 4) |
|---|
| 56 | +#define SPEC_INFO_VERSION_SHIFT 4 |
|---|
| 57 | + |
|---|
| 58 | +#define SBS_VERSION_1_0 1 |
|---|
| 59 | +#define SBS_VERSION_1_1 2 |
|---|
| 60 | +#define SBS_VERSION_1_1_WITH_PEC 3 |
|---|
| 61 | + |
|---|
| 62 | +#define REG_ADDR_MANUFACTURE_DATE 0x1B |
|---|
| 55 | 63 | |
|---|
| 56 | 64 | /* Battery Mode defines */ |
|---|
| 57 | 65 | #define BATTERY_MODE_OFFSET 0x03 |
|---|
| 58 | | -#define BATTERY_MODE_MASK 0x8000 |
|---|
| 59 | | -enum sbs_battery_mode { |
|---|
| 60 | | - BATTERY_MODE_AMPS = 0, |
|---|
| 61 | | - BATTERY_MODE_WATTS = 0x8000 |
|---|
| 66 | +#define BATTERY_MODE_CAPACITY_MASK BIT(15) |
|---|
| 67 | +enum sbs_capacity_mode { |
|---|
| 68 | + CAPACITY_MODE_AMPS = 0, |
|---|
| 69 | + CAPACITY_MODE_WATTS = BATTERY_MODE_CAPACITY_MASK |
|---|
| 62 | 70 | }; |
|---|
| 71 | +#define BATTERY_MODE_CHARGER_MASK (1<<14) |
|---|
| 63 | 72 | |
|---|
| 64 | 73 | /* manufacturer access defines */ |
|---|
| 65 | 74 | #define MANUFACTURER_ACCESS_STATUS 0x0006 |
|---|
| .. | .. |
|---|
| 87 | 96 | } sbs_data[] = { |
|---|
| 88 | 97 | [REG_MANUFACTURER_DATA] = |
|---|
| 89 | 98 | SBS_DATA(POWER_SUPPLY_PROP_PRESENT, 0x00, 0, 65535), |
|---|
| 99 | + [REG_BATTERY_MODE] = |
|---|
| 100 | + SBS_DATA(-1, 0x03, 0, 65535), |
|---|
| 90 | 101 | [REG_TEMPERATURE] = |
|---|
| 91 | 102 | SBS_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535), |
|---|
| 92 | 103 | [REG_VOLTAGE] = |
|---|
| 93 | 104 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_NOW, 0x09, 0, 20000), |
|---|
| 94 | | - [REG_CURRENT] = |
|---|
| 105 | + [REG_CURRENT_NOW] = |
|---|
| 95 | 106 | SBS_DATA(POWER_SUPPLY_PROP_CURRENT_NOW, 0x0A, -32768, 32767), |
|---|
| 107 | + [REG_CURRENT_AVG] = |
|---|
| 108 | + SBS_DATA(POWER_SUPPLY_PROP_CURRENT_AVG, 0x0B, -32768, 32767), |
|---|
| 109 | + [REG_MAX_ERR] = |
|---|
| 110 | + SBS_DATA(POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, 0x0c, 0, 100), |
|---|
| 96 | 111 | [REG_CAPACITY] = |
|---|
| 97 | 112 | SBS_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0D, 0, 100), |
|---|
| 98 | 113 | [REG_REMAINING_CAPACITY] = |
|---|
| .. | .. |
|---|
| 107 | 122 | SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, 65535), |
|---|
| 108 | 123 | [REG_TIME_TO_FULL] = |
|---|
| 109 | 124 | SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 0x13, 0, 65535), |
|---|
| 125 | + [REG_CHARGE_CURRENT] = |
|---|
| 126 | + SBS_DATA(POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, 0x14, 0, 65535), |
|---|
| 127 | + [REG_CHARGE_VOLTAGE] = |
|---|
| 128 | + SBS_DATA(POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, 0x15, 0, 65535), |
|---|
| 110 | 129 | [REG_STATUS] = |
|---|
| 111 | 130 | SBS_DATA(POWER_SUPPLY_PROP_STATUS, 0x16, 0, 65535), |
|---|
| 112 | 131 | [REG_CAPACITY_LEVEL] = |
|---|
| .. | .. |
|---|
| 127 | 146 | [REG_MANUFACTURER] = |
|---|
| 128 | 147 | SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535), |
|---|
| 129 | 148 | [REG_MODEL_NAME] = |
|---|
| 130 | | - SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535) |
|---|
| 149 | + SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535), |
|---|
| 150 | + [REG_CHEMISTRY] = |
|---|
| 151 | + SBS_DATA(POWER_SUPPLY_PROP_TECHNOLOGY, 0x22, 0, 65535) |
|---|
| 131 | 152 | }; |
|---|
| 132 | 153 | |
|---|
| 133 | | -static enum power_supply_property sbs_properties[] = { |
|---|
| 154 | +static const enum power_supply_property sbs_properties[] = { |
|---|
| 134 | 155 | POWER_SUPPLY_PROP_STATUS, |
|---|
| 135 | 156 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
|---|
| 136 | 157 | POWER_SUPPLY_PROP_HEALTH, |
|---|
| .. | .. |
|---|
| 139 | 160 | POWER_SUPPLY_PROP_CYCLE_COUNT, |
|---|
| 140 | 161 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
|---|
| 141 | 162 | POWER_SUPPLY_PROP_CURRENT_NOW, |
|---|
| 163 | + POWER_SUPPLY_PROP_CURRENT_AVG, |
|---|
| 142 | 164 | POWER_SUPPLY_PROP_CAPACITY, |
|---|
| 165 | + POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, |
|---|
| 143 | 166 | POWER_SUPPLY_PROP_TEMP, |
|---|
| 144 | 167 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, |
|---|
| 145 | 168 | POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, |
|---|
| .. | .. |
|---|
| 152 | 175 | POWER_SUPPLY_PROP_CHARGE_NOW, |
|---|
| 153 | 176 | POWER_SUPPLY_PROP_CHARGE_FULL, |
|---|
| 154 | 177 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
|---|
| 178 | + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, |
|---|
| 179 | + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, |
|---|
| 180 | + POWER_SUPPLY_PROP_MANUFACTURE_YEAR, |
|---|
| 181 | + POWER_SUPPLY_PROP_MANUFACTURE_MONTH, |
|---|
| 182 | + POWER_SUPPLY_PROP_MANUFACTURE_DAY, |
|---|
| 155 | 183 | /* Properties of type `const char *' */ |
|---|
| 156 | 184 | POWER_SUPPLY_PROP_MANUFACTURER, |
|---|
| 157 | 185 | POWER_SUPPLY_PROP_MODEL_NAME |
|---|
| 158 | 186 | }; |
|---|
| 159 | 187 | |
|---|
| 160 | | -/* Supports special manufacturer commands from TI BQ20Z75 IC. */ |
|---|
| 161 | | -#define SBS_FLAGS_TI_BQ20Z75 BIT(0) |
|---|
| 188 | +/* Supports special manufacturer commands from TI BQ20Z65 and BQ20Z75 IC. */ |
|---|
| 189 | +#define SBS_FLAGS_TI_BQ20ZX5 BIT(0) |
|---|
| 162 | 190 | |
|---|
| 163 | 191 | struct sbs_info { |
|---|
| 164 | 192 | struct i2c_client *client; |
|---|
| 165 | 193 | struct power_supply *power_supply; |
|---|
| 166 | 194 | bool is_present; |
|---|
| 167 | 195 | struct gpio_desc *gpio_detect; |
|---|
| 168 | | - bool enable_detection; |
|---|
| 196 | + bool charger_broadcasts; |
|---|
| 169 | 197 | int last_state; |
|---|
| 170 | 198 | int poll_time; |
|---|
| 171 | 199 | u32 i2c_retry_count; |
|---|
| .. | .. |
|---|
| 177 | 205 | |
|---|
| 178 | 206 | static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; |
|---|
| 179 | 207 | static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; |
|---|
| 208 | +static char chemistry[I2C_SMBUS_BLOCK_MAX + 1]; |
|---|
| 180 | 209 | static bool force_load; |
|---|
| 210 | + |
|---|
| 211 | +static int sbs_read_word_data(struct i2c_client *client, u8 address); |
|---|
| 212 | +static int sbs_write_word_data(struct i2c_client *client, u8 address, u16 value); |
|---|
| 213 | + |
|---|
| 214 | +static void sbs_disable_charger_broadcasts(struct sbs_info *chip) |
|---|
| 215 | +{ |
|---|
| 216 | + int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET); |
|---|
| 217 | + if (val < 0) |
|---|
| 218 | + goto exit; |
|---|
| 219 | + |
|---|
| 220 | + val |= BATTERY_MODE_CHARGER_MASK; |
|---|
| 221 | + |
|---|
| 222 | + val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val); |
|---|
| 223 | + |
|---|
| 224 | +exit: |
|---|
| 225 | + if (val < 0) |
|---|
| 226 | + dev_err(&chip->client->dev, |
|---|
| 227 | + "Failed to disable charger broadcasting: %d\n", val); |
|---|
| 228 | + else |
|---|
| 229 | + dev_dbg(&chip->client->dev, "%s\n", __func__); |
|---|
| 230 | +} |
|---|
| 231 | + |
|---|
| 232 | +static int sbs_update_presence(struct sbs_info *chip, bool is_present) |
|---|
| 233 | +{ |
|---|
| 234 | + struct i2c_client *client = chip->client; |
|---|
| 235 | + int retries = chip->i2c_retry_count; |
|---|
| 236 | + s32 ret = 0; |
|---|
| 237 | + u8 version; |
|---|
| 238 | + |
|---|
| 239 | + if (chip->is_present == is_present) |
|---|
| 240 | + return 0; |
|---|
| 241 | + |
|---|
| 242 | + if (!is_present) { |
|---|
| 243 | + chip->is_present = false; |
|---|
| 244 | + /* Disable PEC when no device is present */ |
|---|
| 245 | + client->flags &= ~I2C_CLIENT_PEC; |
|---|
| 246 | + return 0; |
|---|
| 247 | + } |
|---|
| 248 | + |
|---|
| 249 | + /* Check if device supports packet error checking and use it */ |
|---|
| 250 | + while (retries > 0) { |
|---|
| 251 | + ret = i2c_smbus_read_word_data(client, REG_ADDR_SPEC_INFO); |
|---|
| 252 | + if (ret >= 0) |
|---|
| 253 | + break; |
|---|
| 254 | + |
|---|
| 255 | + /* |
|---|
| 256 | + * Some batteries trigger the detection pin before the |
|---|
| 257 | + * I2C bus is properly connected. This works around the |
|---|
| 258 | + * issue. |
|---|
| 259 | + */ |
|---|
| 260 | + msleep(100); |
|---|
| 261 | + |
|---|
| 262 | + retries--; |
|---|
| 263 | + } |
|---|
| 264 | + |
|---|
| 265 | + if (ret < 0) { |
|---|
| 266 | + dev_dbg(&client->dev, "failed to read spec info: %d\n", ret); |
|---|
| 267 | + |
|---|
| 268 | + /* fallback to old behaviour */ |
|---|
| 269 | + client->flags &= ~I2C_CLIENT_PEC; |
|---|
| 270 | + chip->is_present = true; |
|---|
| 271 | + |
|---|
| 272 | + return ret; |
|---|
| 273 | + } |
|---|
| 274 | + |
|---|
| 275 | + version = (ret & SPEC_INFO_VERSION_MASK) >> SPEC_INFO_VERSION_SHIFT; |
|---|
| 276 | + |
|---|
| 277 | + if (version == SBS_VERSION_1_1_WITH_PEC) |
|---|
| 278 | + client->flags |= I2C_CLIENT_PEC; |
|---|
| 279 | + else |
|---|
| 280 | + client->flags &= ~I2C_CLIENT_PEC; |
|---|
| 281 | + |
|---|
| 282 | + if (of_device_is_compatible(client->dev.parent->of_node, "google,cros-ec-i2c-tunnel") |
|---|
| 283 | + && client->flags & I2C_CLIENT_PEC) { |
|---|
| 284 | + dev_info(&client->dev, "Disabling PEC because of broken Cros-EC implementation\n"); |
|---|
| 285 | + client->flags &= ~I2C_CLIENT_PEC; |
|---|
| 286 | + } |
|---|
| 287 | + |
|---|
| 288 | + dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ? |
|---|
| 289 | + "enabled" : "disabled"); |
|---|
| 290 | + |
|---|
| 291 | + if (!chip->is_present && is_present && !chip->charger_broadcasts) |
|---|
| 292 | + sbs_disable_charger_broadcasts(chip); |
|---|
| 293 | + |
|---|
| 294 | + chip->is_present = true; |
|---|
| 295 | + |
|---|
| 296 | + return 0; |
|---|
| 297 | +} |
|---|
| 181 | 298 | |
|---|
| 182 | 299 | static int sbs_read_word_data(struct i2c_client *client, u8 address) |
|---|
| 183 | 300 | { |
|---|
| .. | .. |
|---|
| 202 | 319 | return ret; |
|---|
| 203 | 320 | } |
|---|
| 204 | 321 | |
|---|
| 205 | | -static int sbs_read_string_data(struct i2c_client *client, u8 address, |
|---|
| 206 | | - char *values) |
|---|
| 322 | +static int sbs_read_string_data_fallback(struct i2c_client *client, u8 address, char *values) |
|---|
| 207 | 323 | { |
|---|
| 208 | 324 | struct sbs_info *chip = i2c_get_clientdata(client); |
|---|
| 209 | 325 | s32 ret = 0, block_length = 0; |
|---|
| .. | .. |
|---|
| 212 | 328 | |
|---|
| 213 | 329 | retries_length = chip->i2c_retry_count; |
|---|
| 214 | 330 | retries_block = chip->i2c_retry_count; |
|---|
| 331 | + |
|---|
| 332 | + dev_warn_once(&client->dev, "I2C adapter does not support I2C_FUNC_SMBUS_READ_BLOCK_DATA.\n" |
|---|
| 333 | + "Fallback method does not support PEC.\n"); |
|---|
| 215 | 334 | |
|---|
| 216 | 335 | /* Adapter needs to support these two functions */ |
|---|
| 217 | 336 | if (!i2c_check_functionality(client->adapter, |
|---|
| .. | .. |
|---|
| 268 | 387 | return ret; |
|---|
| 269 | 388 | } |
|---|
| 270 | 389 | |
|---|
| 390 | +static int sbs_read_string_data(struct i2c_client *client, u8 address, char *values) |
|---|
| 391 | +{ |
|---|
| 392 | + struct sbs_info *chip = i2c_get_clientdata(client); |
|---|
| 393 | + int retries = chip->i2c_retry_count; |
|---|
| 394 | + int ret = 0; |
|---|
| 395 | + |
|---|
| 396 | + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { |
|---|
| 397 | + bool pec = client->flags & I2C_CLIENT_PEC; |
|---|
| 398 | + client->flags &= ~I2C_CLIENT_PEC; |
|---|
| 399 | + ret = sbs_read_string_data_fallback(client, address, values); |
|---|
| 400 | + if (pec) |
|---|
| 401 | + client->flags |= I2C_CLIENT_PEC; |
|---|
| 402 | + return ret; |
|---|
| 403 | + } |
|---|
| 404 | + |
|---|
| 405 | + while (retries > 0) { |
|---|
| 406 | + ret = i2c_smbus_read_block_data(client, address, values); |
|---|
| 407 | + if (ret >= 0) |
|---|
| 408 | + break; |
|---|
| 409 | + retries--; |
|---|
| 410 | + } |
|---|
| 411 | + |
|---|
| 412 | + if (ret < 0) { |
|---|
| 413 | + dev_dbg(&client->dev, "failed to read block 0x%x: %d\n", address, ret); |
|---|
| 414 | + return ret; |
|---|
| 415 | + } |
|---|
| 416 | + |
|---|
| 417 | + /* add string termination */ |
|---|
| 418 | + values[ret] = '\0'; |
|---|
| 419 | + return ret; |
|---|
| 420 | +} |
|---|
| 421 | + |
|---|
| 271 | 422 | static int sbs_write_word_data(struct i2c_client *client, u8 address, |
|---|
| 272 | 423 | u16 value) |
|---|
| 273 | 424 | { |
|---|
| .. | .. |
|---|
| 296 | 447 | { |
|---|
| 297 | 448 | int ret; |
|---|
| 298 | 449 | |
|---|
| 299 | | - ret = sbs_read_word_data(client, sbs_data[REG_CURRENT].addr); |
|---|
| 450 | + ret = sbs_read_word_data(client, sbs_data[REG_CURRENT_NOW].addr); |
|---|
| 300 | 451 | if (ret < 0) |
|---|
| 301 | 452 | return ret; |
|---|
| 302 | 453 | |
|---|
| 303 | 454 | ret = (s16)ret; |
|---|
| 304 | 455 | |
|---|
| 305 | | - /* Not drawing current means full (cannot be not charging) */ |
|---|
| 306 | | - if (ret == 0) |
|---|
| 307 | | - *intval = POWER_SUPPLY_STATUS_FULL; |
|---|
| 456 | + /* Not drawing current -> not charging (i.e. idle) */ |
|---|
| 457 | + if (*intval != POWER_SUPPLY_STATUS_FULL && ret == 0) |
|---|
| 458 | + *intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
|---|
| 308 | 459 | |
|---|
| 309 | 460 | if (*intval == POWER_SUPPLY_STATUS_FULL) { |
|---|
| 310 | 461 | /* Drawing or providing current when full */ |
|---|
| .. | .. |
|---|
| 317 | 468 | return 0; |
|---|
| 318 | 469 | } |
|---|
| 319 | 470 | |
|---|
| 320 | | -static int sbs_get_battery_presence_and_health( |
|---|
| 321 | | - struct i2c_client *client, enum power_supply_property psp, |
|---|
| 322 | | - union power_supply_propval *val) |
|---|
| 471 | +static bool sbs_bat_needs_calibration(struct i2c_client *client) |
|---|
| 323 | 472 | { |
|---|
| 324 | 473 | int ret; |
|---|
| 325 | 474 | |
|---|
| 326 | | - /* Dummy command; if it succeeds, battery is present. */ |
|---|
| 327 | | - ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); |
|---|
| 475 | + ret = sbs_read_word_data(client, sbs_data[REG_BATTERY_MODE].addr); |
|---|
| 476 | + if (ret < 0) |
|---|
| 477 | + return false; |
|---|
| 328 | 478 | |
|---|
| 329 | | - if (ret < 0) { /* battery not present*/ |
|---|
| 330 | | - if (psp == POWER_SUPPLY_PROP_PRESENT) { |
|---|
| 331 | | - val->intval = 0; |
|---|
| 332 | | - return 0; |
|---|
| 333 | | - } |
|---|
| 334 | | - return ret; |
|---|
| 335 | | - } |
|---|
| 336 | | - |
|---|
| 337 | | - if (psp == POWER_SUPPLY_PROP_PRESENT) |
|---|
| 338 | | - val->intval = 1; /* battery present */ |
|---|
| 339 | | - else /* POWER_SUPPLY_PROP_HEALTH */ |
|---|
| 340 | | - /* SBS spec doesn't have a general health command. */ |
|---|
| 341 | | - val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; |
|---|
| 342 | | - |
|---|
| 343 | | - return 0; |
|---|
| 479 | + return !!(ret & BIT(7)); |
|---|
| 344 | 480 | } |
|---|
| 345 | 481 | |
|---|
| 346 | 482 | static int sbs_get_ti_battery_presence_and_health( |
|---|
| .. | .. |
|---|
| 392 | 528 | val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; |
|---|
| 393 | 529 | else if (ret == 0x0C) |
|---|
| 394 | 530 | val->intval = POWER_SUPPLY_HEALTH_DEAD; |
|---|
| 531 | + else if (sbs_bat_needs_calibration(client)) |
|---|
| 532 | + val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; |
|---|
| 395 | 533 | else |
|---|
| 396 | 534 | val->intval = POWER_SUPPLY_HEALTH_GOOD; |
|---|
| 535 | + } |
|---|
| 536 | + |
|---|
| 537 | + return 0; |
|---|
| 538 | +} |
|---|
| 539 | + |
|---|
| 540 | +static int sbs_get_battery_presence_and_health( |
|---|
| 541 | + struct i2c_client *client, enum power_supply_property psp, |
|---|
| 542 | + union power_supply_propval *val) |
|---|
| 543 | +{ |
|---|
| 544 | + struct sbs_info *chip = i2c_get_clientdata(client); |
|---|
| 545 | + int ret; |
|---|
| 546 | + |
|---|
| 547 | + if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) |
|---|
| 548 | + return sbs_get_ti_battery_presence_and_health(client, psp, val); |
|---|
| 549 | + |
|---|
| 550 | + /* Dummy command; if it succeeds, battery is present. */ |
|---|
| 551 | + ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); |
|---|
| 552 | + |
|---|
| 553 | + if (ret < 0) { /* battery not present*/ |
|---|
| 554 | + if (psp == POWER_SUPPLY_PROP_PRESENT) { |
|---|
| 555 | + val->intval = 0; |
|---|
| 556 | + return 0; |
|---|
| 557 | + } |
|---|
| 558 | + return ret; |
|---|
| 559 | + } |
|---|
| 560 | + |
|---|
| 561 | + if (psp == POWER_SUPPLY_PROP_PRESENT) |
|---|
| 562 | + val->intval = 1; /* battery present */ |
|---|
| 563 | + else { /* POWER_SUPPLY_PROP_HEALTH */ |
|---|
| 564 | + if (sbs_bat_needs_calibration(client)) { |
|---|
| 565 | + val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; |
|---|
| 566 | + } else { |
|---|
| 567 | + /* SBS spec doesn't have a general health command. */ |
|---|
| 568 | + val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; |
|---|
| 569 | + } |
|---|
| 397 | 570 | } |
|---|
| 398 | 571 | |
|---|
| 399 | 572 | return 0; |
|---|
| .. | .. |
|---|
| 500 | 673 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
|---|
| 501 | 674 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
|---|
| 502 | 675 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
|---|
| 676 | + case POWER_SUPPLY_PROP_CURRENT_AVG: |
|---|
| 503 | 677 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
|---|
| 678 | + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: |
|---|
| 679 | + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: |
|---|
| 504 | 680 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
|---|
| 505 | 681 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
|---|
| 506 | 682 | val->intval *= BASE_UNIT_CONVERSION; |
|---|
| .. | .. |
|---|
| 527 | 703 | } |
|---|
| 528 | 704 | } |
|---|
| 529 | 705 | |
|---|
| 530 | | -static enum sbs_battery_mode sbs_set_battery_mode(struct i2c_client *client, |
|---|
| 531 | | - enum sbs_battery_mode mode) |
|---|
| 706 | +static enum sbs_capacity_mode sbs_set_capacity_mode(struct i2c_client *client, |
|---|
| 707 | + enum sbs_capacity_mode mode) |
|---|
| 532 | 708 | { |
|---|
| 533 | 709 | int ret, original_val; |
|---|
| 534 | 710 | |
|---|
| .. | .. |
|---|
| 536 | 712 | if (original_val < 0) |
|---|
| 537 | 713 | return original_val; |
|---|
| 538 | 714 | |
|---|
| 539 | | - if ((original_val & BATTERY_MODE_MASK) == mode) |
|---|
| 715 | + if ((original_val & BATTERY_MODE_CAPACITY_MASK) == mode) |
|---|
| 540 | 716 | return mode; |
|---|
| 541 | 717 | |
|---|
| 542 | | - if (mode == BATTERY_MODE_AMPS) |
|---|
| 543 | | - ret = original_val & ~BATTERY_MODE_MASK; |
|---|
| 718 | + if (mode == CAPACITY_MODE_AMPS) |
|---|
| 719 | + ret = original_val & ~BATTERY_MODE_CAPACITY_MASK; |
|---|
| 544 | 720 | else |
|---|
| 545 | | - ret = original_val | BATTERY_MODE_MASK; |
|---|
| 721 | + ret = original_val | BATTERY_MODE_CAPACITY_MASK; |
|---|
| 546 | 722 | |
|---|
| 547 | 723 | ret = sbs_write_word_data(client, BATTERY_MODE_OFFSET, ret); |
|---|
| 548 | 724 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 550 | 726 | |
|---|
| 551 | 727 | usleep_range(1000, 2000); |
|---|
| 552 | 728 | |
|---|
| 553 | | - return original_val & BATTERY_MODE_MASK; |
|---|
| 729 | + return original_val & BATTERY_MODE_CAPACITY_MASK; |
|---|
| 554 | 730 | } |
|---|
| 555 | 731 | |
|---|
| 556 | 732 | static int sbs_get_battery_capacity(struct i2c_client *client, |
|---|
| .. | .. |
|---|
| 558 | 734 | union power_supply_propval *val) |
|---|
| 559 | 735 | { |
|---|
| 560 | 736 | s32 ret; |
|---|
| 561 | | - enum sbs_battery_mode mode = BATTERY_MODE_WATTS; |
|---|
| 737 | + enum sbs_capacity_mode mode = CAPACITY_MODE_WATTS; |
|---|
| 562 | 738 | |
|---|
| 563 | 739 | if (power_supply_is_amp_property(psp)) |
|---|
| 564 | | - mode = BATTERY_MODE_AMPS; |
|---|
| 740 | + mode = CAPACITY_MODE_AMPS; |
|---|
| 565 | 741 | |
|---|
| 566 | | - mode = sbs_set_battery_mode(client, mode); |
|---|
| 567 | | - if (mode < 0) |
|---|
| 742 | + mode = sbs_set_capacity_mode(client, mode); |
|---|
| 743 | + if ((int)mode < 0) |
|---|
| 568 | 744 | return mode; |
|---|
| 569 | 745 | |
|---|
| 570 | 746 | ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); |
|---|
| .. | .. |
|---|
| 573 | 749 | |
|---|
| 574 | 750 | val->intval = ret; |
|---|
| 575 | 751 | |
|---|
| 576 | | - ret = sbs_set_battery_mode(client, mode); |
|---|
| 752 | + ret = sbs_set_capacity_mode(client, mode); |
|---|
| 577 | 753 | if (ret < 0) |
|---|
| 578 | 754 | return ret; |
|---|
| 579 | 755 | |
|---|
| .. | .. |
|---|
| 610 | 786 | return -EINVAL; |
|---|
| 611 | 787 | } |
|---|
| 612 | 788 | |
|---|
| 789 | +static int sbs_get_chemistry(struct i2c_client *client, |
|---|
| 790 | + union power_supply_propval *val) |
|---|
| 791 | +{ |
|---|
| 792 | + enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY; |
|---|
| 793 | + int ret; |
|---|
| 794 | + |
|---|
| 795 | + ret = sbs_get_property_index(client, psp); |
|---|
| 796 | + if (ret < 0) |
|---|
| 797 | + return ret; |
|---|
| 798 | + |
|---|
| 799 | + ret = sbs_get_battery_string_property(client, ret, psp, |
|---|
| 800 | + chemistry); |
|---|
| 801 | + if (ret < 0) |
|---|
| 802 | + return ret; |
|---|
| 803 | + |
|---|
| 804 | + if (!strncasecmp(chemistry, "LION", 4)) |
|---|
| 805 | + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
|---|
| 806 | + else if (!strncasecmp(chemistry, "LiP", 3)) |
|---|
| 807 | + val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO; |
|---|
| 808 | + else if (!strncasecmp(chemistry, "NiCd", 4)) |
|---|
| 809 | + val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd; |
|---|
| 810 | + else if (!strncasecmp(chemistry, "NiMH", 4)) |
|---|
| 811 | + val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH; |
|---|
| 812 | + else |
|---|
| 813 | + val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; |
|---|
| 814 | + |
|---|
| 815 | + if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN) |
|---|
| 816 | + dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry); |
|---|
| 817 | + |
|---|
| 818 | + return 0; |
|---|
| 819 | +} |
|---|
| 820 | + |
|---|
| 821 | +static int sbs_get_battery_manufacture_date(struct i2c_client *client, |
|---|
| 822 | + enum power_supply_property psp, |
|---|
| 823 | + union power_supply_propval *val) |
|---|
| 824 | +{ |
|---|
| 825 | + int ret; |
|---|
| 826 | + u16 day, month, year; |
|---|
| 827 | + |
|---|
| 828 | + ret = sbs_read_word_data(client, REG_ADDR_MANUFACTURE_DATE); |
|---|
| 829 | + if (ret < 0) |
|---|
| 830 | + return ret; |
|---|
| 831 | + |
|---|
| 832 | + day = ret & GENMASK(4, 0); |
|---|
| 833 | + month = (ret & GENMASK(8, 5)) >> 5; |
|---|
| 834 | + year = ((ret & GENMASK(15, 9)) >> 9) + 1980; |
|---|
| 835 | + |
|---|
| 836 | + switch (psp) { |
|---|
| 837 | + case POWER_SUPPLY_PROP_MANUFACTURE_YEAR: |
|---|
| 838 | + val->intval = year; |
|---|
| 839 | + break; |
|---|
| 840 | + case POWER_SUPPLY_PROP_MANUFACTURE_MONTH: |
|---|
| 841 | + val->intval = month; |
|---|
| 842 | + break; |
|---|
| 843 | + case POWER_SUPPLY_PROP_MANUFACTURE_DAY: |
|---|
| 844 | + val->intval = day; |
|---|
| 845 | + break; |
|---|
| 846 | + default: |
|---|
| 847 | + return -EINVAL; |
|---|
| 848 | + } |
|---|
| 849 | + |
|---|
| 850 | + return 0; |
|---|
| 851 | +} |
|---|
| 852 | + |
|---|
| 613 | 853 | static int sbs_get_property(struct power_supply *psy, |
|---|
| 614 | 854 | enum power_supply_property psp, |
|---|
| 615 | 855 | union power_supply_propval *val) |
|---|
| .. | .. |
|---|
| 624 | 864 | return ret; |
|---|
| 625 | 865 | if (psp == POWER_SUPPLY_PROP_PRESENT) { |
|---|
| 626 | 866 | val->intval = ret; |
|---|
| 627 | | - chip->is_present = val->intval; |
|---|
| 867 | + sbs_update_presence(chip, ret); |
|---|
| 628 | 868 | return 0; |
|---|
| 629 | 869 | } |
|---|
| 630 | 870 | if (ret == 0) |
|---|
| .. | .. |
|---|
| 634 | 874 | switch (psp) { |
|---|
| 635 | 875 | case POWER_SUPPLY_PROP_PRESENT: |
|---|
| 636 | 876 | case POWER_SUPPLY_PROP_HEALTH: |
|---|
| 637 | | - if (chip->flags & SBS_FLAGS_TI_BQ20Z75) |
|---|
| 638 | | - ret = sbs_get_ti_battery_presence_and_health(client, |
|---|
| 639 | | - psp, val); |
|---|
| 640 | | - else |
|---|
| 641 | | - ret = sbs_get_battery_presence_and_health(client, psp, |
|---|
| 642 | | - val); |
|---|
| 877 | + ret = sbs_get_battery_presence_and_health(client, psp, val); |
|---|
| 643 | 878 | |
|---|
| 644 | 879 | /* this can only be true if no gpio is used */ |
|---|
| 645 | 880 | if (psp == POWER_SUPPLY_PROP_PRESENT) |
|---|
| .. | .. |
|---|
| 647 | 882 | break; |
|---|
| 648 | 883 | |
|---|
| 649 | 884 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
|---|
| 650 | | - val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
|---|
| 885 | + ret = sbs_get_chemistry(client, val); |
|---|
| 886 | + if (ret < 0) |
|---|
| 887 | + break; |
|---|
| 888 | + |
|---|
| 651 | 889 | goto done; /* don't trigger power_supply_changed()! */ |
|---|
| 652 | 890 | |
|---|
| 653 | 891 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
|---|
| .. | .. |
|---|
| 678 | 916 | case POWER_SUPPLY_PROP_CYCLE_COUNT: |
|---|
| 679 | 917 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
|---|
| 680 | 918 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
|---|
| 919 | + case POWER_SUPPLY_PROP_CURRENT_AVG: |
|---|
| 681 | 920 | case POWER_SUPPLY_PROP_TEMP: |
|---|
| 682 | 921 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
|---|
| 683 | 922 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: |
|---|
| 684 | 923 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
|---|
| 685 | 924 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
|---|
| 925 | + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: |
|---|
| 926 | + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: |
|---|
| 686 | 927 | case POWER_SUPPLY_PROP_CAPACITY: |
|---|
| 928 | + case POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN: |
|---|
| 687 | 929 | ret = sbs_get_property_index(client, psp); |
|---|
| 688 | 930 | if (ret < 0) |
|---|
| 689 | 931 | break; |
|---|
| .. | .. |
|---|
| 711 | 953 | val->strval = manufacturer; |
|---|
| 712 | 954 | break; |
|---|
| 713 | 955 | |
|---|
| 956 | + case POWER_SUPPLY_PROP_MANUFACTURE_YEAR: |
|---|
| 957 | + case POWER_SUPPLY_PROP_MANUFACTURE_MONTH: |
|---|
| 958 | + case POWER_SUPPLY_PROP_MANUFACTURE_DAY: |
|---|
| 959 | + ret = sbs_get_battery_manufacture_date(client, psp, val); |
|---|
| 960 | + break; |
|---|
| 961 | + |
|---|
| 714 | 962 | default: |
|---|
| 715 | 963 | dev_err(&client->dev, |
|---|
| 716 | 964 | "%s: INVALID property\n", __func__); |
|---|
| 717 | 965 | return -EINVAL; |
|---|
| 718 | 966 | } |
|---|
| 719 | 967 | |
|---|
| 720 | | - if (!chip->enable_detection) |
|---|
| 721 | | - goto done; |
|---|
| 968 | + if (!chip->gpio_detect && chip->is_present != (ret >= 0)) { |
|---|
| 969 | + bool old_present = chip->is_present; |
|---|
| 970 | + union power_supply_propval val; |
|---|
| 971 | + int err = sbs_get_battery_presence_and_health( |
|---|
| 972 | + client, POWER_SUPPLY_PROP_PRESENT, &val); |
|---|
| 722 | 973 | |
|---|
| 723 | | - if (!chip->gpio_detect && |
|---|
| 724 | | - chip->is_present != (ret >= 0)) { |
|---|
| 725 | | - chip->is_present = (ret >= 0); |
|---|
| 726 | | - power_supply_changed(chip->power_supply); |
|---|
| 974 | + sbs_update_presence(chip, !err && val.intval); |
|---|
| 975 | + |
|---|
| 976 | + if (old_present != chip->is_present) |
|---|
| 977 | + power_supply_changed(chip->power_supply); |
|---|
| 727 | 978 | } |
|---|
| 728 | 979 | |
|---|
| 729 | 980 | done: |
|---|
| 730 | 981 | if (!ret) { |
|---|
| 731 | 982 | /* Convert units to match requirements for power supply class */ |
|---|
| 732 | 983 | sbs_unit_adjustment(client, psp, val); |
|---|
| 984 | + dev_dbg(&client->dev, |
|---|
| 985 | + "%s: property = %d, value = %x\n", __func__, |
|---|
| 986 | + psp, val->intval); |
|---|
| 987 | + } else if (!chip->is_present) { |
|---|
| 988 | + /* battery not present, so return NODATA for properties */ |
|---|
| 989 | + ret = -ENODATA; |
|---|
| 733 | 990 | } |
|---|
| 734 | | - |
|---|
| 735 | | - dev_dbg(&client->dev, |
|---|
| 736 | | - "%s: property = %d, value = %x\n", __func__, psp, val->intval); |
|---|
| 737 | | - |
|---|
| 738 | | - if (ret && chip->is_present) |
|---|
| 739 | | - return ret; |
|---|
| 740 | | - |
|---|
| 741 | | - /* battery not present, so return NODATA for properties */ |
|---|
| 742 | | - if (ret) |
|---|
| 743 | | - return -ENODATA; |
|---|
| 744 | | - |
|---|
| 745 | | - return 0; |
|---|
| 991 | + return ret; |
|---|
| 746 | 992 | } |
|---|
| 747 | 993 | |
|---|
| 748 | 994 | static void sbs_supply_changed(struct sbs_info *chip) |
|---|
| .. | .. |
|---|
| 753 | 999 | ret = gpiod_get_value_cansleep(chip->gpio_detect); |
|---|
| 754 | 1000 | if (ret < 0) |
|---|
| 755 | 1001 | return; |
|---|
| 756 | | - chip->is_present = ret; |
|---|
| 1002 | + sbs_update_presence(chip, ret); |
|---|
| 757 | 1003 | power_supply_changed(battery); |
|---|
| 758 | 1004 | } |
|---|
| 759 | 1005 | |
|---|
| .. | .. |
|---|
| 823 | 1069 | .external_power_changed = sbs_external_power_changed, |
|---|
| 824 | 1070 | }; |
|---|
| 825 | 1071 | |
|---|
| 826 | | -static int sbs_probe(struct i2c_client *client, |
|---|
| 827 | | - const struct i2c_device_id *id) |
|---|
| 1072 | +static int sbs_probe(struct i2c_client *client) |
|---|
| 828 | 1073 | { |
|---|
| 829 | 1074 | struct sbs_info *chip; |
|---|
| 830 | 1075 | struct power_supply_desc *sbs_desc; |
|---|
| .. | .. |
|---|
| 847 | 1092 | if (!chip) |
|---|
| 848 | 1093 | return -ENOMEM; |
|---|
| 849 | 1094 | |
|---|
| 850 | | - chip->flags = (u32)(uintptr_t)of_device_get_match_data(&client->dev); |
|---|
| 1095 | + chip->flags = (u32)(uintptr_t)device_get_match_data(&client->dev); |
|---|
| 851 | 1096 | chip->client = client; |
|---|
| 852 | | - chip->enable_detection = false; |
|---|
| 853 | 1097 | psy_cfg.of_node = client->dev.of_node; |
|---|
| 854 | 1098 | psy_cfg.drv_data = chip; |
|---|
| 855 | 1099 | chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN; |
|---|
| .. | .. |
|---|
| 858 | 1102 | /* use pdata if available, fall back to DT properties, |
|---|
| 859 | 1103 | * or hardcoded defaults if not |
|---|
| 860 | 1104 | */ |
|---|
| 861 | | - rc = of_property_read_u32(client->dev.of_node, "sbs,i2c-retry-count", |
|---|
| 862 | | - &chip->i2c_retry_count); |
|---|
| 1105 | + rc = device_property_read_u32(&client->dev, "sbs,i2c-retry-count", |
|---|
| 1106 | + &chip->i2c_retry_count); |
|---|
| 863 | 1107 | if (rc) |
|---|
| 864 | 1108 | chip->i2c_retry_count = 0; |
|---|
| 865 | 1109 | |
|---|
| 866 | | - rc = of_property_read_u32(client->dev.of_node, "sbs,poll-retry-count", |
|---|
| 867 | | - &chip->poll_retry_count); |
|---|
| 1110 | + rc = device_property_read_u32(&client->dev, "sbs,poll-retry-count", |
|---|
| 1111 | + &chip->poll_retry_count); |
|---|
| 868 | 1112 | if (rc) |
|---|
| 869 | 1113 | chip->poll_retry_count = 0; |
|---|
| 870 | 1114 | |
|---|
| .. | .. |
|---|
| 873 | 1117 | chip->i2c_retry_count = pdata->i2c_retry_count; |
|---|
| 874 | 1118 | } |
|---|
| 875 | 1119 | chip->i2c_retry_count = chip->i2c_retry_count + 1; |
|---|
| 1120 | + |
|---|
| 1121 | + chip->charger_broadcasts = !device_property_read_bool(&client->dev, |
|---|
| 1122 | + "sbs,disable-charger-broadcasts"); |
|---|
| 876 | 1123 | |
|---|
| 877 | 1124 | chip->gpio_detect = devm_gpiod_get_optional(&client->dev, |
|---|
| 878 | 1125 | "sbs,battery-detect", GPIOD_IN); |
|---|
| .. | .. |
|---|
| 907 | 1154 | * to the battery. |
|---|
| 908 | 1155 | */ |
|---|
| 909 | 1156 | if (!(force_load || chip->gpio_detect)) { |
|---|
| 910 | | - rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); |
|---|
| 1157 | + union power_supply_propval val; |
|---|
| 911 | 1158 | |
|---|
| 912 | | - if (rc < 0) { |
|---|
| 913 | | - dev_err(&client->dev, "%s: Failed to get device status\n", |
|---|
| 914 | | - __func__); |
|---|
| 1159 | + rc = sbs_get_battery_presence_and_health( |
|---|
| 1160 | + client, POWER_SUPPLY_PROP_PRESENT, &val); |
|---|
| 1161 | + if (rc < 0 || !val.intval) { |
|---|
| 1162 | + dev_err(&client->dev, "Failed to get present status\n"); |
|---|
| 1163 | + rc = -ENODEV; |
|---|
| 915 | 1164 | goto exit_psupply; |
|---|
| 916 | 1165 | } |
|---|
| 917 | 1166 | } |
|---|
| 1167 | + |
|---|
| 1168 | + INIT_DELAYED_WORK(&chip->work, sbs_delayed_work); |
|---|
| 918 | 1169 | |
|---|
| 919 | 1170 | chip->power_supply = devm_power_supply_register(&client->dev, sbs_desc, |
|---|
| 920 | 1171 | &psy_cfg); |
|---|
| .. | .. |
|---|
| 927 | 1178 | |
|---|
| 928 | 1179 | dev_info(&client->dev, |
|---|
| 929 | 1180 | "%s: battery gas gauge device registered\n", client->name); |
|---|
| 930 | | - |
|---|
| 931 | | - INIT_DELAYED_WORK(&chip->work, sbs_delayed_work); |
|---|
| 932 | | - |
|---|
| 933 | | - chip->enable_detection = true; |
|---|
| 934 | 1181 | |
|---|
| 935 | 1182 | return 0; |
|---|
| 936 | 1183 | |
|---|
| .. | .. |
|---|
| 958 | 1205 | if (chip->poll_time > 0) |
|---|
| 959 | 1206 | cancel_delayed_work_sync(&chip->work); |
|---|
| 960 | 1207 | |
|---|
| 961 | | - if (chip->flags & SBS_FLAGS_TI_BQ20Z75) { |
|---|
| 1208 | + if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) { |
|---|
| 962 | 1209 | /* Write to manufacturer access with sleep command. */ |
|---|
| 963 | 1210 | ret = sbs_write_word_data(client, |
|---|
| 964 | 1211 | sbs_data[REG_MANUFACTURER_DATA].addr, |
|---|
| .. | .. |
|---|
| 978 | 1225 | #endif |
|---|
| 979 | 1226 | |
|---|
| 980 | 1227 | static const struct i2c_device_id sbs_id[] = { |
|---|
| 1228 | + { "bq20z65", 0 }, |
|---|
| 981 | 1229 | { "bq20z75", 0 }, |
|---|
| 982 | 1230 | { "sbs-battery", 1 }, |
|---|
| 983 | 1231 | {} |
|---|
| .. | .. |
|---|
| 987 | 1235 | static const struct of_device_id sbs_dt_ids[] = { |
|---|
| 988 | 1236 | { .compatible = "sbs,sbs-battery" }, |
|---|
| 989 | 1237 | { |
|---|
| 1238 | + .compatible = "ti,bq20z65", |
|---|
| 1239 | + .data = (void *)SBS_FLAGS_TI_BQ20ZX5, |
|---|
| 1240 | + }, |
|---|
| 1241 | + { |
|---|
| 990 | 1242 | .compatible = "ti,bq20z75", |
|---|
| 991 | | - .data = (void *)SBS_FLAGS_TI_BQ20Z75, |
|---|
| 1243 | + .data = (void *)SBS_FLAGS_TI_BQ20ZX5, |
|---|
| 992 | 1244 | }, |
|---|
| 993 | 1245 | { } |
|---|
| 994 | 1246 | }; |
|---|
| 995 | 1247 | MODULE_DEVICE_TABLE(of, sbs_dt_ids); |
|---|
| 996 | 1248 | |
|---|
| 997 | 1249 | static struct i2c_driver sbs_battery_driver = { |
|---|
| 998 | | - .probe = sbs_probe, |
|---|
| 1250 | + .probe_new = sbs_probe, |
|---|
| 999 | 1251 | .remove = sbs_remove, |
|---|
| 1000 | 1252 | .alert = sbs_alert, |
|---|
| 1001 | 1253 | .id_table = sbs_id, |
|---|
| .. | .. |
|---|
| 1010 | 1262 | MODULE_DESCRIPTION("SBS battery monitor driver"); |
|---|
| 1011 | 1263 | MODULE_LICENSE("GPL"); |
|---|
| 1012 | 1264 | |
|---|
| 1013 | | -module_param(force_load, bool, S_IRUSR | S_IRGRP | S_IROTH); |
|---|
| 1265 | +module_param(force_load, bool, 0444); |
|---|
| 1014 | 1266 | MODULE_PARM_DESC(force_load, |
|---|
| 1015 | 1267 | "Attempt to load the driver even if no battery is connected"); |
|---|