Lines Matching full:client
192 struct i2c_client *client; member
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);
216 int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET); in sbs_disable_charger_broadcasts()
222 val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val); in sbs_disable_charger_broadcasts()
226 dev_err(&chip->client->dev, in sbs_disable_charger_broadcasts()
229 dev_dbg(&chip->client->dev, "%s\n", __func__); in sbs_disable_charger_broadcasts()
234 struct i2c_client *client = chip->client; in sbs_update_presence() local
245 client->flags &= ~I2C_CLIENT_PEC; in sbs_update_presence()
251 ret = i2c_smbus_read_word_data(client, REG_ADDR_SPEC_INFO); in sbs_update_presence()
266 dev_dbg(&client->dev, "failed to read spec info: %d\n", ret); in sbs_update_presence()
269 client->flags &= ~I2C_CLIENT_PEC; in sbs_update_presence()
278 client->flags |= I2C_CLIENT_PEC; in sbs_update_presence()
280 client->flags &= ~I2C_CLIENT_PEC; in sbs_update_presence()
282 if (of_device_is_compatible(client->dev.parent->of_node, "google,cros-ec-i2c-tunnel") in sbs_update_presence()
283 && client->flags & I2C_CLIENT_PEC) { in sbs_update_presence()
284 dev_info(&client->dev, "Disabling PEC because of broken Cros-EC implementation\n"); in sbs_update_presence()
285 client->flags &= ~I2C_CLIENT_PEC; in sbs_update_presence()
288 dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ? in sbs_update_presence()
299 static int sbs_read_word_data(struct i2c_client *client, u8 address) in sbs_read_word_data() argument
301 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_read_word_data()
306 ret = i2c_smbus_read_word_data(client, address); in sbs_read_word_data()
313 dev_dbg(&client->dev, in sbs_read_word_data()
322 static int sbs_read_string_data_fallback(struct i2c_client *client, u8 address, char *values) in sbs_read_string_data_fallback() argument
324 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_read_string_data_fallback()
332 dev_warn_once(&client->dev, "I2C adapter does not support I2C_FUNC_SMBUS_READ_BLOCK_DATA.\n" in sbs_read_string_data_fallback()
336 if (!i2c_check_functionality(client->adapter, in sbs_read_string_data_fallback()
344 ret = i2c_smbus_read_byte_data(client, address); in sbs_read_string_data_fallback()
351 dev_dbg(&client->dev, in sbs_read_string_data_fallback()
360 dev_err(&client->dev, in sbs_read_string_data_fallback()
369 client, address, in sbs_read_string_data_fallback()
377 dev_dbg(&client->dev, in sbs_read_string_data_fallback()
390 static int sbs_read_string_data(struct i2c_client *client, u8 address, char *values) in sbs_read_string_data() argument
392 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_read_string_data()
396 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { in sbs_read_string_data()
397 bool pec = client->flags & I2C_CLIENT_PEC; in sbs_read_string_data()
398 client->flags &= ~I2C_CLIENT_PEC; in sbs_read_string_data()
399 ret = sbs_read_string_data_fallback(client, address, values); in sbs_read_string_data()
401 client->flags |= I2C_CLIENT_PEC; in sbs_read_string_data()
406 ret = i2c_smbus_read_block_data(client, address, values); in sbs_read_string_data()
413 dev_dbg(&client->dev, "failed to read block 0x%x: %d\n", address, ret); in sbs_read_string_data()
422 static int sbs_write_word_data(struct i2c_client *client, u8 address, in sbs_write_word_data() argument
425 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_write_word_data()
430 ret = i2c_smbus_write_word_data(client, address, value); in sbs_write_word_data()
437 dev_dbg(&client->dev, in sbs_write_word_data()
446 static int sbs_status_correct(struct i2c_client *client, int *intval) in sbs_status_correct() argument
450 ret = sbs_read_word_data(client, sbs_data[REG_CURRENT_NOW].addr); in sbs_status_correct()
471 static bool sbs_bat_needs_calibration(struct i2c_client *client) in sbs_bat_needs_calibration() argument
475 ret = sbs_read_word_data(client, sbs_data[REG_BATTERY_MODE].addr); in sbs_bat_needs_calibration()
483 struct i2c_client *client, enum power_supply_property psp, in sbs_get_ti_battery_presence_and_health() argument
492 ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, in sbs_get_ti_battery_presence_and_health()
500 ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr); in sbs_get_ti_battery_presence_and_health()
531 else if (sbs_bat_needs_calibration(client)) in sbs_get_ti_battery_presence_and_health()
541 struct i2c_client *client, enum power_supply_property psp, in sbs_get_battery_presence_and_health() argument
544 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_get_battery_presence_and_health()
548 return sbs_get_ti_battery_presence_and_health(client, psp, val); in sbs_get_battery_presence_and_health()
551 ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); in sbs_get_battery_presence_and_health()
564 if (sbs_bat_needs_calibration(client)) { in sbs_get_battery_presence_and_health()
575 static int sbs_get_battery_property(struct i2c_client *client, in sbs_get_battery_property() argument
579 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_get_battery_property()
582 ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); in sbs_get_battery_property()
618 sbs_status_correct(client, &val->intval); in sbs_get_battery_property()
642 static int sbs_get_battery_string_property(struct i2c_client *client, in sbs_get_battery_string_property() argument
647 ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val); in sbs_get_battery_string_property()
655 static void sbs_unit_adjustment(struct i2c_client *client, in sbs_unit_adjustment() argument
701 dev_dbg(&client->dev, in sbs_unit_adjustment()
706 static enum sbs_capacity_mode sbs_set_capacity_mode(struct i2c_client *client, in sbs_set_capacity_mode() argument
711 original_val = sbs_read_word_data(client, BATTERY_MODE_OFFSET); in sbs_set_capacity_mode()
723 ret = sbs_write_word_data(client, BATTERY_MODE_OFFSET, ret); in sbs_set_capacity_mode()
732 static int sbs_get_battery_capacity(struct i2c_client *client, in sbs_get_battery_capacity() argument
742 mode = sbs_set_capacity_mode(client, mode); in sbs_get_battery_capacity()
746 ret = sbs_read_word_data(client, sbs_data[reg_offset].addr); in sbs_get_battery_capacity()
752 ret = sbs_set_capacity_mode(client, mode); in sbs_get_battery_capacity()
760 static int sbs_get_battery_serial_number(struct i2c_client *client, in sbs_get_battery_serial_number() argument
765 ret = sbs_read_word_data(client, sbs_data[REG_SERIAL_NUMBER].addr); in sbs_get_battery_serial_number()
775 static int sbs_get_property_index(struct i2c_client *client, in sbs_get_property_index() argument
783 dev_warn(&client->dev, in sbs_get_property_index()
789 static int sbs_get_chemistry(struct i2c_client *client, in sbs_get_chemistry() argument
795 ret = sbs_get_property_index(client, psp); in sbs_get_chemistry()
799 ret = sbs_get_battery_string_property(client, ret, psp, in sbs_get_chemistry()
816 dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry); in sbs_get_chemistry()
821 static int sbs_get_battery_manufacture_date(struct i2c_client *client, in sbs_get_battery_manufacture_date() argument
828 ret = sbs_read_word_data(client, REG_ADDR_MANUFACTURE_DATE); in sbs_get_battery_manufacture_date()
859 struct i2c_client *client = chip->client; in sbs_get_property() local
877 ret = sbs_get_battery_presence_and_health(client, psp, val); in sbs_get_property()
885 ret = sbs_get_chemistry(client, val); in sbs_get_property()
897 ret = sbs_get_property_index(client, psp); in sbs_get_property()
906 ret = sbs_get_battery_capacity(client, ret, psp, val); in sbs_get_property()
911 ret = sbs_get_battery_serial_number(client, val); in sbs_get_property()
929 ret = sbs_get_property_index(client, psp); in sbs_get_property()
933 ret = sbs_get_battery_property(client, ret, psp, val); in sbs_get_property()
937 ret = sbs_get_property_index(client, psp); in sbs_get_property()
941 ret = sbs_get_battery_string_property(client, ret, psp, in sbs_get_property()
947 ret = sbs_get_property_index(client, psp); in sbs_get_property()
951 ret = sbs_get_battery_string_property(client, ret, psp, in sbs_get_property()
959 ret = sbs_get_battery_manufacture_date(client, psp, val); in sbs_get_property()
963 dev_err(&client->dev, in sbs_get_property()
972 client, POWER_SUPPLY_PROP_PRESENT, &val); in sbs_get_property()
983 sbs_unit_adjustment(client, psp, val); in sbs_get_property()
984 dev_dbg(&client->dev, in sbs_get_property()
1012 static void sbs_alert(struct i2c_client *client, enum i2c_alert_protocol prot, in sbs_alert() argument
1015 sbs_supply_changed(i2c_get_clientdata(client)); in sbs_alert()
1036 ret = sbs_read_word_data(chip->client, sbs_data[REG_STATUS].addr); in sbs_delayed_work()
1050 sbs_status_correct(chip->client, &ret); in sbs_delayed_work()
1072 static int sbs_probe(struct i2c_client *client) in sbs_probe() argument
1076 struct sbs_platform_data *pdata = client->dev.platform_data; in sbs_probe()
1081 sbs_desc = devm_kmemdup(&client->dev, &sbs_default_desc, in sbs_probe()
1086 sbs_desc->name = devm_kasprintf(&client->dev, GFP_KERNEL, "sbs-%s", in sbs_probe()
1087 dev_name(&client->dev)); in sbs_probe()
1091 chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL); in sbs_probe()
1095 chip->flags = (u32)(uintptr_t)device_get_match_data(&client->dev); in sbs_probe()
1096 chip->client = client; in sbs_probe()
1097 psy_cfg.of_node = client->dev.of_node; in sbs_probe()
1105 rc = device_property_read_u32(&client->dev, "sbs,i2c-retry-count", in sbs_probe()
1110 rc = device_property_read_u32(&client->dev, "sbs,poll-retry-count", in sbs_probe()
1121 chip->charger_broadcasts = !device_property_read_bool(&client->dev, in sbs_probe()
1124 chip->gpio_detect = devm_gpiod_get_optional(&client->dev, in sbs_probe()
1127 dev_err(&client->dev, "Failed to get gpio: %ld\n", in sbs_probe()
1132 i2c_set_clientdata(client, chip); in sbs_probe()
1139 dev_warn(&client->dev, "Failed to get gpio as irq: %d\n", irq); in sbs_probe()
1143 rc = devm_request_threaded_irq(&client->dev, irq, NULL, sbs_irq, in sbs_probe()
1145 dev_name(&client->dev), chip); in sbs_probe()
1147 dev_warn(&client->dev, "Failed to request irq: %d\n", rc); in sbs_probe()
1160 client, POWER_SUPPLY_PROP_PRESENT, &val); in sbs_probe()
1162 dev_err(&client->dev, "Failed to get present status\n"); in sbs_probe()
1170 chip->power_supply = devm_power_supply_register(&client->dev, sbs_desc, in sbs_probe()
1173 dev_err(&client->dev, in sbs_probe()
1179 dev_info(&client->dev, in sbs_probe()
1180 "%s: battery gas gauge device registered\n", client->name); in sbs_probe()
1188 static int sbs_remove(struct i2c_client *client) in sbs_remove() argument
1190 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_remove()
1201 struct i2c_client *client = to_i2c_client(dev); in sbs_suspend() local
1202 struct sbs_info *chip = i2c_get_clientdata(client); in sbs_suspend()
1210 ret = sbs_write_word_data(client, in sbs_suspend()