Skip to content

Commit c449927

Browse files
crawfxrdjwrdegoede
authored andcommitted
platform/x86: system76_acpi: Guard System76 EC specific functionality
Certain functionality or its implementation in System76 EC firmware may be different to the proprietary ODM EC firmware. Introduce a new bool, `has_open_ec`, to guard our specific logic. Detect the use of this by looking for a custom ACPI method name used in System76 firmware. Signed-off-by: Tim Crawford <tcrawford@system76.com> Link: https://lore.kernel.org/r/20211222185154.4560-1-tcrawford@system76.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent eb66fb0 commit c449927

1 file changed

Lines changed: 30 additions & 28 deletions

File tree

drivers/platform/x86/system76_acpi.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct system76_data {
3535
union acpi_object *nfan;
3636
union acpi_object *ntmp;
3737
struct input_dev *input;
38+
bool has_open_ec;
3839
};
3940

4041
static const struct acpi_device_id device_ids[] = {
@@ -279,20 +280,12 @@ static struct acpi_battery_hook system76_battery_hook = {
279280

280281
static void system76_battery_init(void)
281282
{
282-
acpi_handle handle;
283-
284-
handle = ec_get_handle();
285-
if (handle && acpi_has_method(handle, "GBCT"))
286-
battery_hook_register(&system76_battery_hook);
283+
battery_hook_register(&system76_battery_hook);
287284
}
288285

289286
static void system76_battery_exit(void)
290287
{
291-
acpi_handle handle;
292-
293-
handle = ec_get_handle();
294-
if (handle && acpi_has_method(handle, "GBCT"))
295-
battery_hook_unregister(&system76_battery_hook);
288+
battery_hook_unregister(&system76_battery_hook);
296289
}
297290

298291
// Get the airplane mode LED brightness
@@ -673,6 +666,10 @@ static int system76_add(struct acpi_device *acpi_dev)
673666
acpi_dev->driver_data = data;
674667
data->acpi_dev = acpi_dev;
675668

669+
// Some models do not run open EC firmware. Check for an ACPI method
670+
// that only exists on open EC to guard functionality specific to it.
671+
data->has_open_ec = acpi_has_method(acpi_device_handle(data->acpi_dev), "NFAN");
672+
676673
err = system76_get(data, "INIT");
677674
if (err)
678675
return err;
@@ -718,27 +715,31 @@ static int system76_add(struct acpi_device *acpi_dev)
718715
if (err)
719716
goto error;
720717

721-
err = system76_get_object(data, "NFAN", &data->nfan);
722-
if (err)
723-
goto error;
718+
if (data->has_open_ec) {
719+
err = system76_get_object(data, "NFAN", &data->nfan);
720+
if (err)
721+
goto error;
724722

725-
err = system76_get_object(data, "NTMP", &data->ntmp);
726-
if (err)
727-
goto error;
723+
err = system76_get_object(data, "NTMP", &data->ntmp);
724+
if (err)
725+
goto error;
728726

729-
data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev,
730-
"system76_acpi", data, &thermal_chip_info, NULL);
731-
err = PTR_ERR_OR_ZERO(data->therm);
732-
if (err)
733-
goto error;
727+
data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev,
728+
"system76_acpi", data, &thermal_chip_info, NULL);
729+
err = PTR_ERR_OR_ZERO(data->therm);
730+
if (err)
731+
goto error;
734732

735-
system76_battery_init();
733+
system76_battery_init();
734+
}
736735

737736
return 0;
738737

739738
error:
740-
kfree(data->ntmp);
741-
kfree(data->nfan);
739+
if (data->has_open_ec) {
740+
kfree(data->ntmp);
741+
kfree(data->nfan);
742+
}
742743
return err;
743744
}
744745

@@ -749,14 +750,15 @@ static int system76_remove(struct acpi_device *acpi_dev)
749750

750751
data = acpi_driver_data(acpi_dev);
751752

752-
system76_battery_exit();
753+
if (data->has_open_ec) {
754+
system76_battery_exit();
755+
kfree(data->nfan);
756+
kfree(data->ntmp);
757+
}
753758

754759
devm_led_classdev_unregister(&acpi_dev->dev, &data->ap_led);
755760
devm_led_classdev_unregister(&acpi_dev->dev, &data->kb_led);
756761

757-
kfree(data->nfan);
758-
kfree(data->ntmp);
759-
760762
system76_get(data, "FINI");
761763

762764
return 0;

0 commit comments

Comments
 (0)