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>
This commit is contained in:
Tim Crawford 2021-12-21 09:09:51 -07:00 committed by Jeremy Soller
parent a02b101be8
commit 04145b8cb1
1 changed files with 27 additions and 23 deletions

View File

@ -36,6 +36,7 @@ struct system76_data {
union acpi_object *nfan; union acpi_object *nfan;
union acpi_object *ntmp; union acpi_object *ntmp;
struct input_dev *input; struct input_dev *input;
bool has_open_ec;
}; };
static const struct acpi_device_id device_ids[] = { static const struct acpi_device_id device_ids[] = {
@ -286,20 +287,12 @@ static struct acpi_battery_hook system76_battery_hook = {
static void system76_battery_init(void) static void system76_battery_init(void)
{ {
acpi_handle handle; battery_hook_register(&system76_battery_hook);
handle = ec_get_handle();
if (handle && acpi_has_method(handle, "GBCT"))
battery_hook_register(&system76_battery_hook);
} }
static void system76_battery_exit(void) static void system76_battery_exit(void)
{ {
acpi_handle handle; battery_hook_unregister(&system76_battery_hook);
handle = ec_get_handle();
if (handle && acpi_has_method(handle, "GBCT"))
battery_hook_unregister(&system76_battery_hook);
} }
/* Keyboard */ /* Keyboard */
@ -690,6 +683,10 @@ static int system76_add(struct acpi_device *acpi_dev)
acpi_dev->driver_data = data; acpi_dev->driver_data = data;
data->acpi_dev = acpi_dev; data->acpi_dev = acpi_dev;
// Some models do not run Open EC firmware. Check for an ACPI method that
// only exists on Open EC to guard functionality specific to it.
data->has_open_ec = acpi_has_method(acpi_device_handle(data->acpi_dev), "NFAN");
err = system76_get(data, "INIT"); err = system76_get(data, "INIT");
if (err) if (err)
return err; return err;
@ -717,6 +714,7 @@ static int system76_add(struct acpi_device *acpi_dev)
data->kb_led.max_brightness = 5; data->kb_led.max_brightness = 5;
data->kb_color = -1; data->kb_color = -1;
} }
err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led); err = devm_led_classdev_register(&acpi_dev->dev, &data->kb_led);
if (err) if (err)
return err; return err;
@ -735,13 +733,15 @@ static int system76_add(struct acpi_device *acpi_dev)
if (err) if (err)
goto error; goto error;
err = system76_get_object(data, "NFAN", &data->nfan); if (data->has_open_ec) {
if (err) err = system76_get_object(data, "NFAN", &data->nfan);
goto error; if (err)
goto error;
err = system76_get_object(data, "NTMP", &data->ntmp); err = system76_get_object(data, "NTMP", &data->ntmp);
if (err) if (err)
goto error; goto error;
}
data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev, data->therm = devm_hwmon_device_register_with_info(&acpi_dev->dev,
"system76_acpi", data, &thermal_chip_info, NULL); "system76_acpi", data, &thermal_chip_info, NULL);
@ -749,13 +749,16 @@ static int system76_add(struct acpi_device *acpi_dev)
if (err) if (err)
goto error; goto error;
system76_battery_init(); if (data->has_open_ec)
system76_battery_init();
return 0; return 0;
error: error:
kfree(data->ntmp); if (data->has_open_ec) {
kfree(data->nfan); kfree(data->ntmp);
kfree(data->nfan);
}
return err; return err;
} }
@ -766,14 +769,15 @@ static int system76_remove(struct acpi_device *acpi_dev)
data = acpi_driver_data(acpi_dev); data = acpi_driver_data(acpi_dev);
system76_battery_exit(); if (data->has_open_ec) {
system76_battery_exit();
kfree(data->nfan);
kfree(data->ntmp);
}
devm_led_classdev_unregister(&acpi_dev->dev, &data->ap_led); devm_led_classdev_unregister(&acpi_dev->dev, &data->ap_led);
devm_led_classdev_unregister(&acpi_dev->dev, &data->kb_led); devm_led_classdev_unregister(&acpi_dev->dev, &data->kb_led);
kfree(data->nfan);
kfree(data->ntmp);
system76_get(data, "FINI"); system76_get(data, "FINI");
return 0; return 0;