Re: [PATCH v7 1/1] platform/x86: Add wmi driver for Casper Excalibur laptops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le 06/08/2024 à 22:50, Mustafa Ekşi a écrit :
This wmi driver supports changing Casper Excalibur laptops' keyboard
backlight brightness and color, reading fan speeds and changing power
profiles. Multicolor led device is used for backlight, platform_profile
for power management and hwmon for fan speeds. It supports both old (10th
gen or older) and new (11th gen or newer) laptops. It uses x86_match_cpu
to check if the laptop is old or new.

Signed-off-by: Mustafa Ekşi <mustafa.eskieksi@xxxxxxxxx>
---

Hi,

a few nitpicks below, should there be a v8.


diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index e1b14294706..639509f9afa 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_MXM_WMI)			+= mxm-wmi.o
  obj-$(CONFIG_NVIDIA_WMI_EC_BACKLIGHT)	+= nvidia-wmi-ec-backlight.o
  obj-$(CONFIG_XIAOMI_WMI)		+= xiaomi-wmi.o
  obj-$(CONFIG_GIGABYTE_WMI)		+= gigabyte-wmi.o
+obj-$(CONFIG_CASPER_WMI)		+= casper-wmi.o

Maybe, this could be alphabetically sorted?

# Acer
  obj-$(CONFIG_ACERHDF)		+= acerhdf.o

...

+static int casper_platform_profile_register(struct casper_drv *drv)
+{
+	int ret = 0;

Nitpick: No need to init.

+
+	drv->handler.profile_get = casper_platform_profile_get;
+	drv->handler.profile_set = casper_platform_profile_set;
+
+	set_bit(PLATFORM_PROFILE_LOW_POWER, drv->handler.choices);
+	set_bit(PLATFORM_PROFILE_BALANCED, drv->handler.choices);
+	if (!drv->quirk_applied->new_power_scheme)
+		set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
+			drv->handler.choices);
+	set_bit(PLATFORM_PROFILE_PERFORMANCE, drv->handler.choices);
+
+	ret = platform_profile_register(&drv->handler);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&drv->wdev->dev, casper_pp_remove,
+				       NULL);
+	if (ret)
+		platform_profile_remove();
+
+	return ret;
+}
+
+static int casper_multicolor_register(struct casper_drv *drv)
+{
+	int ret = 0;

Nitpick: No need to init.

+
+	drv->leds = devm_kcalloc(&drv->wdev->dev,
+		CASPER_LED_COUNT, sizeof(*drv->leds), GFP_KERNEL);
+	if (!drv->leds)
+		return -ENOMEM;
+
+	for (size_t i = 0; i < CASPER_LED_COUNT; i++) {
+		for (size_t j = 0; j < 3; j++) {
+			drv->leds[i].subleds[j] = (struct mc_subled) {
+				.color_index = LED_COLOR_ID_RED + j,
+				.brightness = 255,
+				.intensity = 255
+			};
+		}
+		drv->leds[i].mc_led = (struct led_classdev_mc){
+			.led_cdev = {
+				.name = zone_names[i],
+				.brightness = 0,
+				.max_brightness = 2,
+				.brightness_set = &set_casper_brightness,
+				.brightness_get = &get_casper_brightness,
+				.color = LED_COLOR_ID_MULTI,
+			},
+			.num_colors = 3,
+			.subled_info = drv->leds[i].subleds
+		};
+
+		ret = devm_led_classdev_multicolor_register(&drv->wdev->dev,
+							&drv->leds[i].mc_led);
+		if (ret)
+			return -ENODEV;
+	}
+
+	// Setting leds to the default color
+	ret = casper_set(drv, CASPER_SET_LED, CASPER_ALL_KEYBOARD_LEDS,
+			 CASPER_DEFAULT_COLOR);
+	if (ret)
+		return ret;
+
+	ret = casper_set(drv, CASPER_SET_LED, CASPER_CORNER_LEDS,
+			 CASPER_DEFAULT_COLOR);
+	return ret;
+}
+
+static int casper_wmi_probe(struct wmi_device *wdev, const void *context)
+{
+	struct casper_quirk_entry *pp_quirk;
+	const struct dmi_system_id *dmi_id;
+	const struct x86_cpu_id *gen_id;
+	struct device *hwmon_dev;
+	struct casper_drv *drv;
+	int ret;
+
+	drv = devm_kzalloc(&wdev->dev, sizeof(*drv), GFP_KERNEL);
+	if (!drv)
+		return -ENOMEM;
+
+	drv->wdev = wdev;
+	dev_set_drvdata(&wdev->dev, drv);
+
+	gen_id = x86_match_cpu(casper_gen);
+	if (!gen_id)
+		return -ENODEV;
+
+	drv->quirk_applied = (struct casper_quirk_entry *)gen_id->driver_data;
+
+	dmi_id = dmi_first_match(casper_quirks);
+	if (!dmi_id)
+		return -ENODEV;
+
+	pp_quirk = (struct casper_quirk_entry *)dmi_id->driver_data;
+	drv->quirk_applied->no_power_profiles = pp_quirk->no_power_profiles;
+
+	mutex_init(&drv->mutex);

No need to call mutex_init() if devm_mutex_init() is used as well.

+	ret = devm_mutex_init(&wdev->dev, &drv->mutex);
+	if (ret)
+		return ret;
+
+	ret = casper_multicolor_register(drv);
+	if (ret)
+		return ret;
+
+	hwmon_dev = devm_hwmon_device_register_with_info(&wdev->dev,
+						"casper_wmi", wdev,
+						&casper_wmi_hwmon_chip_info,
+						NULL);
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	if (!drv->quirk_applied->no_power_profiles) {
+		ret = casper_platform_profile_register(drv);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}

...

CJ





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux