Commit c4499272 authored by Tim Crawford's avatar Tim Crawford Committed by Hans de Goede
Browse files

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: default avatarTim Crawford <tcrawford@system76.com>
Link: https://lore.kernel.org/r/20211222185154.4560-1-tcrawford@system76.com


Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent eb66fb03
Loading
Loading
Loading
Loading
+30 −28
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ struct system76_data {
	union acpi_object *nfan;
	union acpi_object *ntmp;
	struct input_dev *input;
	bool has_open_ec;
};

static const struct acpi_device_id device_ids[] = {
@@ -279,19 +280,11 @@ static struct acpi_battery_hook system76_battery_hook = {

static void system76_battery_init(void)
{
	acpi_handle handle;

	handle = ec_get_handle();
	if (handle && acpi_has_method(handle, "GBCT"))
	battery_hook_register(&system76_battery_hook);
}

static void system76_battery_exit(void)
{
	acpi_handle handle;

	handle = ec_get_handle();
	if (handle && acpi_has_method(handle, "GBCT"))
	battery_hook_unregister(&system76_battery_hook);
}

@@ -673,6 +666,10 @@ static int system76_add(struct acpi_device *acpi_dev)
	acpi_dev->driver_data = data;
	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");
	if (err)
		return err;
@@ -718,6 +715,7 @@ static int system76_add(struct acpi_device *acpi_dev)
	if (err)
		goto error;

	if (data->has_open_ec) {
		err = system76_get_object(data, "NFAN", &data->nfan);
		if (err)
			goto error;
@@ -733,12 +731,15 @@ static int system76_add(struct acpi_device *acpi_dev)
			goto error;

		system76_battery_init();
	}

	return 0;

error:
	if (data->has_open_ec) {
		kfree(data->ntmp);
		kfree(data->nfan);
	}
	return err;
}

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

	data = acpi_driver_data(acpi_dev);

	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->kb_led);

	kfree(data->nfan);
	kfree(data->ntmp);

	system76_get(data, "FINI");

	return 0;