Hi 2021. szeptember 27., hétfő 23:06 keltezéssel, Tim Crawford írta: > System76 laptops running open source EC firmware support configuring > charging thresholds through ACPI methods. Expose this functionality > through the standard sysfs entries charge_control_{start,end}_threshold. > > Signed-off-by: Tim Crawford <tcrawford@xxxxxxxxxxxx> > --- > drivers/platform/x86/system76_acpi.c | 153 +++++++++++++++++++++++++++ > 1 file changed, 153 insertions(+) > > diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c > index 06f6509980e2..b42c4a384ba9 100644 > --- a/drivers/platform/x86/system76_acpi.c > +++ b/drivers/platform/x86/system76_acpi.c > [...] > +enum { > + THRESHOLD_START, > + THRESHOLD_END, > +}; > + > +static ssize_t battery_get_threshold(int which, char *buf) > +{ > + struct acpi_object_list input; > + union acpi_object param; > + acpi_handle handle; > + acpi_status status; > + unsigned long long ret = BATTERY_THRESHOLD_INVALID; > + > + handle = ec_get_handle(); > + if (!handle) > + return -ENODEV; > + > + input.count = 1; > + input.pointer = ¶m; > + // Start/stop selection > + param.type = ACPI_TYPE_INTEGER; > + param.integer.value = which; > + > + status = acpi_evaluate_integer(handle, "GBCT", &input, &ret); > + if (ACPI_FAILURE(status)) > + return -EIO; > + if (ret == BATTERY_THRESHOLD_INVALID) > + return -EINVAL; > + > + return sprintf(buf, "%d\n", (int)ret); Please use `sysfs_emit()` for writing into sysfs buffers. > +} > [...] > +static int system76_battery_add(struct power_supply *battery) > +{ > + // System76 EC only supports 1 battery > + if (strcmp(battery->desc->name, "BAT0") != 0) > + return -ENODEV; > + > + device_create_file(&battery->dev, &dev_attr_charge_control_start_threshold); > + device_create_file(&battery->dev, &dev_attr_charge_control_end_threshold); You can use `device_{add,remove}_groups()` instead of manually adding them one by one. > + return 0; > +} > [...] Regards, Barnabás Pőcze