Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lg-laptop: Move setting of battery charge limit to common location

For now leave also the driver specific location,
with deprecated warning in documentation.

Signed-off-by: Matan Ziv-Av <matan@svgalib.org>
Link: https://lore.kernel.org/r/eca2fa354f60b8a6e5a5c9c8e244fea56616970a.1645278914.git.matan@svgalib.org
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Matan Ziv-Av and committed by
Hans de Goede
07f5ed0e 4b1be2fe

+52 -9
+1
Documentation/ABI/testing/sysfs-platform-lg-laptop
··· 17 17 KernelVersion: 4.20 18 18 Contact: "Matan Ziv-Av <matan@svgalib.org> 19 19 Description: 20 + Deprecated use /sys/class/power_supply/CMB0/charge_control_end_threshold 20 21 Maximal battery charge level. Accepted values are 80 or 100. 21 22 22 23 What: /sys/devices/platform/lg-laptop/fan_mode
+1 -1
Documentation/admin-guide/laptops/lg-laptop.rst
··· 38 38 Battery care limit 39 39 ------------------ 40 40 41 - Writing 80/100 to /sys/devices/platform/lg-laptop/battery_care_limit 41 + Writing 80/100 to /sys/class/power_supply/CMB0/charge_control_end_threshold 42 42 sets the maximum capacity to charge the battery. Limiting the charge 43 43 reduces battery capacity loss over time. 44 44
+1
drivers/platform/x86/Kconfig
··· 915 915 config LG_LAPTOP 916 916 tristate "LG Laptop Extras" 917 917 depends on ACPI 918 + depends on ACPI_BATTERY 918 919 depends on ACPI_WMI 919 920 depends on INPUT 920 921 select INPUT_SPARSEKMAP
+49 -8
drivers/platform/x86/lg-laptop.c
··· 17 17 #include <linux/platform_device.h> 18 18 #include <linux/types.h> 19 19 20 + #include <acpi/battery.h> 21 + 20 22 #define LED_DEVICE(_name, max, flag) struct led_classdev _name = { \ 21 23 .name = __stringify(_name), \ 22 24 .max_brightness = max, \ ··· 460 458 return sysfs_emit(buffer, "%d\n", status); 461 459 } 462 460 463 - static ssize_t battery_care_limit_store(struct device *dev, 464 - struct device_attribute *attr, 465 - const char *buffer, size_t count) 461 + static ssize_t charge_control_end_threshold_store(struct device *dev, 462 + struct device_attribute *attr, 463 + const char *buf, size_t count) 466 464 { 467 465 unsigned long value; 468 466 int ret; 469 467 470 - ret = kstrtoul(buffer, 10, &value); 468 + ret = kstrtoul(buf, 10, &value); 471 469 if (ret) 472 470 return ret; 473 471 ··· 488 486 return -EINVAL; 489 487 } 490 488 491 - static ssize_t battery_care_limit_show(struct device *dev, 492 - struct device_attribute *attr, 493 - char *buffer) 489 + static ssize_t charge_control_end_threshold_show(struct device *device, 490 + struct device_attribute *attr, 491 + char *buf) 494 492 { 495 493 unsigned int status; 496 494 union acpi_object *r; ··· 522 520 if (status != 80 && status != 100) 523 521 status = 0; 524 522 525 - return sysfs_emit(buffer, "%d\n", status); 523 + return sysfs_emit(buf, "%d\n", status); 524 + } 525 + 526 + static ssize_t battery_care_limit_show(struct device *dev, 527 + struct device_attribute *attr, 528 + char *buffer) 529 + { 530 + return charge_control_end_threshold_show(dev, attr, buffer); 531 + } 532 + 533 + static ssize_t battery_care_limit_store(struct device *dev, 534 + struct device_attribute *attr, 535 + const char *buffer, size_t count) 536 + { 537 + return charge_control_end_threshold_store(dev, attr, buffer, count); 526 538 } 527 539 528 540 static DEVICE_ATTR_RW(fan_mode); 529 541 static DEVICE_ATTR_RW(usb_charge); 530 542 static DEVICE_ATTR_RW(reader_mode); 531 543 static DEVICE_ATTR_RW(fn_lock); 544 + static DEVICE_ATTR_RW(charge_control_end_threshold); 532 545 static DEVICE_ATTR_RW(battery_care_limit); 546 + 547 + static int lg_battery_add(struct power_supply *battery) 548 + { 549 + if (device_create_file(&battery->dev, 550 + &dev_attr_charge_control_end_threshold)) 551 + return -ENODEV; 552 + 553 + return 0; 554 + } 555 + 556 + static int lg_battery_remove(struct power_supply *battery) 557 + { 558 + device_remove_file(&battery->dev, 559 + &dev_attr_charge_control_end_threshold); 560 + return 0; 561 + } 562 + 563 + static struct acpi_battery_hook battery_hook = { 564 + .add_battery = lg_battery_add, 565 + .remove_battery = lg_battery_remove, 566 + .name = "LG Battery Extension", 567 + }; 533 568 534 569 static struct attribute *dev_attributes[] = { 535 570 &dev_attr_fan_mode.attr, ··· 750 711 led_classdev_register(&pf_device->dev, &tpad_led); 751 712 752 713 wmi_input_setup(); 714 + battery_hook_register(&battery_hook); 753 715 754 716 return 0; 755 717 ··· 768 728 led_classdev_unregister(&tpad_led); 769 729 led_classdev_unregister(&kbd_backlight); 770 730 731 + battery_hook_unregister(&battery_hook); 771 732 wmi_input_destroy(); 772 733 platform_device_unregister(pf_device); 773 734 pf_device = NULL;