Lines Matching +full:serial +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0+
5 * (C) Copyright 2016-2018 Red Hat, Inc
6 * (C) Copyright 2016-2018 Benjamin Tissoires <benjamin.tissoires@gmail.com>
9 * This driver has been reverse-engineered by parsing the DSDT of the Surface 3
13 * - the driver is required for the ACPI BAT0 device to communicate to the chip
15 * - the various defines for the operation region functions to communicate with
17 * - the DSM 3f99e367-6220-4955-8b0f-06ef2ae79412 allows to trigger ACPI
21 * - there are 2 chips declared:
24 * - the battery chip uses a SMBus protocol (using plain SMBus allows non
84 char serial[SURFACE_3_STRLEN]; member
152 /* 3f99e367-6220-4955-8b0f-06ef2ae79412 */
165 handle = ACPI_HANDLE(&cdata->adp1->dev); in mshw0011_notify()
167 return -ENODEV; in mshw0011_notify()
172 dev_err(&cdata->adp1->dev, "device _DSM execution failed\n"); in mshw0011_notify()
173 return -ENODEV; in mshw0011_notify()
177 for (i = 0; i < obj->buffer.length; i++) in mshw0011_notify()
178 *ret_value |= obj->buffer.pointer[i] << (i * 8); in mshw0011_notify()
202 .serial = "",
209 struct i2c_client *client = cdata->bat0; in mshw0011_bix()
219 dev_err(&client->dev, "Error reading design capacity: %d\n", in mshw0011_bix()
223 bix->design_capacity = ret; in mshw0011_bix()
229 dev_err(&client->dev, in mshw0011_bix()
233 bix->last_full_charg_capacity = ret; in mshw0011_bix()
236 * Get serial number, on some devices (with unofficial replacement in mshw0011_bix()
237 * battery?) reading any of the serial number range addresses gets in mshw0011_bix()
238 * nacked in this case just leave the serial number empty. in mshw0011_bix()
242 if (ret == -EREMOTEIO) { in mshw0011_bix()
243 /* no serial number available */ in mshw0011_bix()
245 dev_err(&client->dev, "Error reading serial no: %d\n", ret); in mshw0011_bix()
248 snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf); in mshw0011_bix()
254 dev_err(&client->dev, "Error reading cycle count: %d\n", ret); in mshw0011_bix()
257 bix->cycle_count = ret; in mshw0011_bix()
263 dev_err(&client->dev, "Error reading cycle count: %d\n", ret); in mshw0011_bix()
266 snprintf(bix->OEM, ARRAY_SIZE(bix->OEM), "%3pE", buf); in mshw0011_bix()
273 struct i2c_client *client = cdata->bat0; in mshw0011_bst()
274 int rate, capacity, voltage, state; in mshw0011_bst() local
290 bst->battery_present_rate = abs((s32)tmp); in mshw0011_bst()
292 state = 0; in mshw0011_bst()
294 state |= ACPI_BATTERY_STATE_CHARGING; in mshw0011_bst()
296 state |= ACPI_BATTERY_STATE_DISCHARGING; in mshw0011_bst()
297 bst->battery_state = state; in mshw0011_bst()
299 bst->battery_remaining_capacity = capacity; in mshw0011_bst()
300 bst->battery_present_voltage = voltage; in mshw0011_bst()
307 return i2c_smbus_read_byte_data(cdata->adp1, MSHW0011_ADP1_REG_PSR); in mshw0011_adp_psr()
322 if (status != cdata->charging) in mshw0011_isr()
323 mshw0011_notify(cdata, cdata->notify_mask, in mshw0011_isr()
326 cdata->charging = status; in mshw0011_isr()
333 if (bat_status != cdata->bat_charging) in mshw0011_isr()
334 mshw0011_notify(cdata, cdata->notify_mask, in mshw0011_isr()
337 cdata->bat_charging = bat_status; in mshw0011_isr()
343 if (bix.last_full_charg_capacity != cdata->full_capacity) in mshw0011_isr()
344 mshw0011_notify(cdata, cdata->notify_mask, in mshw0011_isr()
347 cdata->full_capacity = bix.last_full_charg_capacity; in mshw0011_isr()
357 cdata->kthread_running = true; in mshw0011_poll_task()
369 cdata->kthread_running = false; in mshw0011_poll_task()
380 struct acpi_connection_info *info = &data->info; in mshw0011_space_handler()
382 struct i2c_client *client = data->client; in mshw0011_space_handler()
389 ret = acpi_buffer_to_resource(info->connection, info->length, &ares); in mshw0011_space_handler()
403 if (gsb->cmd.arg0 == MSHW0011_CMD_DEST_ADP1 && in mshw0011_space_handler()
404 gsb->cmd.arg1 == MSHW0011_CMD_ADP1_PSR) { in mshw0011_space_handler()
415 if (gsb->cmd.arg0 != MSHW0011_CMD_DEST_BAT0) { in mshw0011_space_handler()
420 switch (gsb->cmd.arg1) { in mshw0011_space_handler()
424 ret = mshw0011_bix(cdata, &gsb->bix); in mshw0011_space_handler()
427 cdata->trip_point = gsb->cmd.arg2; in mshw0011_space_handler()
430 ret = mshw0011_bst(cdata, &gsb->bst); in mshw0011_space_handler()
433 dev_info(&cdata->bat0->dev, "command(0x%02x) is not supported.\n", gsb->cmd.arg1); in mshw0011_space_handler()
439 gsb->ret = status; in mshw0011_space_handler()
440 gsb->status = 0; in mshw0011_space_handler()
453 adev = ACPI_COMPANION(&client->dev); in mshw0011_install_space_handler()
455 return -ENODEV; in mshw0011_install_space_handler()
460 return -ENOMEM; in mshw0011_install_space_handler()
462 data->client = client; in mshw0011_install_space_handler()
463 status = acpi_bus_attach_private_data(adev->handle, (void *)data); in mshw0011_install_space_handler()
466 return -ENOMEM; in mshw0011_install_space_handler()
469 status = acpi_install_address_space_handler(adev->handle, in mshw0011_install_space_handler()
475 dev_err(&client->dev, "Error installing i2c space handler\n"); in mshw0011_install_space_handler()
476 acpi_bus_detach_private_data(adev->handle); in mshw0011_install_space_handler()
478 return -ENOMEM; in mshw0011_install_space_handler()
491 handle = ACPI_HANDLE(&client->dev); in mshw0011_remove_space_handler()
509 struct device *dev = &client->dev; in mshw0011_probe()
516 return -ENOMEM; in mshw0011_probe()
518 data->adp1 = client; in mshw0011_probe()
522 strscpy(board_info.type, "MSHW0011-bat0", I2C_NAME_SIZE); in mshw0011_probe()
528 data->bat0 = bat0; in mshw0011_probe()
535 data->notify_mask = mask == MSHW0011_EV_2_5_MASK; in mshw0011_probe()
537 data->poll_task = kthread_run(mshw0011_poll_task, data, "mshw0011_adp"); in mshw0011_probe()
538 if (IS_ERR(data->poll_task)) { in mshw0011_probe()
539 error = PTR_ERR(data->poll_task); in mshw0011_probe()
540 dev_err(&client->dev, "Unable to run kthread err %d\n", error); in mshw0011_probe()
551 if (data->kthread_running) in mshw0011_probe()
552 kthread_stop(data->poll_task); in mshw0011_probe()
553 i2c_unregister_device(data->bat0); in mshw0011_probe()
563 if (cdata->kthread_running) in mshw0011_remove()
564 kthread_stop(cdata->poll_task); in mshw0011_remove()
566 i2c_unregister_device(cdata->bat0); in mshw0011_remove()