Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2185156rdb; Sun, 3 Dec 2023 06:14:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkRDqOoXY+g3R6SBNg2BQqhBGpKd1Rf/UxlW1c6bLbJU1tmjwMu0aS8wIa3EW7aZv/008+ X-Received: by 2002:a17:90b:3809:b0:286:ab9d:c6be with SMTP id mq9-20020a17090b380900b00286ab9dc6bemr185404pjb.16.1701612868559; Sun, 03 Dec 2023 06:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701612868; cv=none; d=google.com; s=arc-20160816; b=cd2Zv5sGOic5uX/9iFrPEh2sRsnAhbPll00ToH7l94fWQNbCDW/xEcfP4sd3MrNSjE /reyWALCQpZv7dV59P1wdpEakmhrGc7bbEeiDgZj42jInT4D0QjW2gMd2sjObkRnHOAu p+ZR4TYcXFUS1yGFfJwGPt7g9IDpLZKAv8+dbyEpXljGSSmS/+nTClX1OaopTnrQVIsy Mot8FcDErJ0T//rU3MIqYhgT9hLxl2rQ9K51jJeId64/0KMunliWqPEQsi0uPNPiJT0M agdWOkx1MNyMayzzErO3jdaAPlsHgKhLVPrdAEYUePqOlHr5KjJVsK8aJQIjVg/6C1bq 1p2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vHH2Bjj48Djz2RY9cadX3OGXazgeoGZS6s9g0Hw2khU=; fh=lnP76NRN75u84G4tRvOzUxiaLQrMVJd36iPvw92hZwE=; b=v2demljBnJ96jW2TDAZ97kp/SXQ9g182Gs2IpwTdJ6xQoJ8dgCj7NvunmwxyG/MFG0 S87CapJAYmZkd+q+q52MTyPg4DSlXwuW8hO44LGFSwNEPRweT1Kk8kBLxRSaUWBgz8rV 0Bgw9QE89HRsJitshXLY/pKfay7TtBV1jbLv6HNBqNJSTPzFuQ5I7GMgByslInsxfEI7 wwDlDF2kP30xBRPM0XzEJupnG16RKy8px3B6bDZ3H4KYFlFF0qrue9mFvs+Xa+W5uizz Ukxhm31OR48cmaPv4xddBz96cWYN/GYDiX+QyUTSd9LH51jUAcj478aKNRGnKRHH9UXf RUeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=JvV19AXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id h4-20020a17090aa88400b0028699537b69si923866pjq.39.2023.12.03.06.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 06:14:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=JvV19AXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4F1E2806A61E; Sun, 3 Dec 2023 06:14:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233386AbjLCOOH (ORCPT + 99 others); Sun, 3 Dec 2023 09:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjLCOOG (ORCPT ); Sun, 3 Dec 2023 09:14:06 -0500 Received: from smtp.smtpout.orange.fr (smtp-16.smtpout.orange.fr [80.12.242.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5129F3 for ; Sun, 3 Dec 2023 06:14:11 -0800 (PST) Received: from [192.168.1.18] ([92.140.202.140]) by smtp.orange.fr with ESMTPA id 9nEUrOgUx2dY39nEUruSbe; Sun, 03 Dec 2023 15:14:08 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1701612849; bh=vHH2Bjj48Djz2RY9cadX3OGXazgeoGZS6s9g0Hw2khU=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=JvV19AXC2mDarEzEI3CJF4WQd0A/kKs9PeYNCmInPJQ4gT1ta96UZOjrU9I26rjyN bZGNokqYmrPnECPZJ+EFxhEM9CCeAzslkSyLamP0M5MCPbZCiYT7PyPkNXHnsBq74W BvzQAJ4ag08L/SapDPDBykUuMngmi3BSakO4McFQ6XY6CsqvJIKw2KQZntmrlGntLj WEwkYG4RViURq0vkuH94nk6/ca6b9DRuFQ+nalLvlfUbVhnKT8eA7l2Q0/kj9zUFRK npMUFKikdXjUVvILHelWDTj5RtsYZfs7igJbMKY0+Q4nSy60Lj+cLdIXcE05wslK0Q zTqia6ZWn9IOA== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 03 Dec 2023 15:14:08 +0100 X-ME-IP: 92.140.202.140 Message-ID: <2a89f0b4-990a-4d0d-8e54-c4215579c23c@wanadoo.fr> Date: Sun, 3 Dec 2023 15:14:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] hwmon: Add driver for Gigabyte AORUS Waterforce AIO coolers Content-Language: fr To: Aleksa Savic , linux-hwmon@vger.kernel.org Cc: Jean Delvare , Guenter Roeck , Jonathan Corbet , "open list:DOCUMENTATION" , open list References: <20231203120651.371429-1-savicaleksa83@gmail.com> From: Christophe JAILLET In-Reply-To: <20231203120651.371429-1-savicaleksa83@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 03 Dec 2023 06:14:25 -0800 (PST) Le 03/12/2023 à 13:06, Aleksa Savic a écrit : > This driver exposes hardware sensors of the Gigabyte AORUS Waterforce > all-in-one CPU liquid coolers, which communicate through a proprietary > USB HID protocol. Report offsets were initially discovered in [1] and > confirmed by me on a Waterforce X240 by observing the sent reports from > the official software. > > Available sensors are pump and fan speed in RPM, as well as coolant > temperature. Also available through debugfs is the firmware version. > > Attaching a fan is optional and allows it to be controlled from the > device. If it's not connected, the fan-related sensors will report > zeroes. > > The addressable RGB LEDs and LCD screen are not supported in this > driver and should be controlled through userspace tools. > > [1]: https://github.com/liquidctl/liquidctl/issues/167 > > Signed-off-by: Aleksa Savic > --- Hi, ... > +/* Writes the command to the device with the rest of the report filled with zeroes */ > +static int waterforce_write_expanded(struct waterforce_data *priv, const u8 *cmd, int cmd_length) > +{ > + int ret; > + > + mutex_lock(&priv->buffer_lock); > + > + memset(priv->buffer, 0x00, MAX_REPORT_LENGTH); > + memcpy(priv->buffer, cmd, cmd_length); Is memcpy_and_pad() useful here? > + ret = hid_hw_output_report(priv->hdev, priv->buffer, MAX_REPORT_LENGTH); > + > + mutex_unlock(&priv->buffer_lock); > + return ret; > +} ... > +static int waterforce_read(struct device *dev, enum hwmon_sensor_types type, > + u32 attr, int channel, long *val) > +{ > + int ret; > + struct waterforce_data *priv = dev_get_drvdata(dev); > + > + if (time_after(jiffies, priv->updated + msecs_to_jiffies(STATUS_VALIDITY))) { > + /* Request status on demand */ > + ret = waterforce_get_status(priv); > + if (ret < 0) > + return -ENODATA; > + } > + > + switch (type) { > + case hwmon_temp: > + *val = priv->temp_input[channel]; > + break; > + case hwmon_fan: > + *val = priv->speed_input[channel]; > + break; > + case hwmon_pwm: > + switch (attr) { > + case hwmon_pwm_input: > + *val = DIV_ROUND_CLOSEST(priv->duty_input[channel] * 255, 100); > + break; > + default: > + break; Should we return an error here? > + } > + break; > + default: > + return -EOPNOTSUPP; /* unreachable */ > + } > + > + return 0; > +} ... > +static int waterforce_probe(struct hid_device *hdev, const struct hid_device_id *id) > +{ > + struct waterforce_data *priv; > + int ret; > + > + priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + priv->hdev = hdev; > + hid_set_drvdata(hdev, priv); > + > + /* > + * Initialize priv->updated to STATUS_VALIDITY seconds in the past, making > + * the initial empty data invalid for waterforce_read() without the need for > + * a special case there. > + */ > + priv->updated = jiffies - msecs_to_jiffies(STATUS_VALIDITY); > + > + ret = hid_parse(hdev); > + if (ret) { > + hid_err(hdev, "hid parse failed with %d\n", ret); > + return ret; > + } > + > + /* > + * Enable hidraw so existing user-space tools can continue to work. > + */ > + ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); > + if (ret) { > + hid_err(hdev, "hid hw start failed with %d\n", ret); > + goto fail_and_stop; Should this be 'return ret;' (the _start has failed, so why stop?) > + } > + > + ret = hid_hw_open(hdev); > + if (ret) { > + hid_err(hdev, "hid hw open failed with %d\n", ret); > + goto fail_and_close; Should this be 'fail_and_stop' (the _open has failed, so why close?) > + } > + > + priv->buffer = devm_kzalloc(&hdev->dev, MAX_REPORT_LENGTH, GFP_KERNEL); > + if (!priv->buffer) { > + ret = -ENOMEM; > + goto fail_and_close; > + } > + > + mutex_init(&priv->status_report_request_mutex); > + mutex_init(&priv->buffer_lock); > + spin_lock_init(&priv->status_report_request_lock); > + init_completion(&priv->status_report_received); > + init_completion(&priv->fw_version_processed); > + > + priv->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "waterforce", > + priv, &waterforce_chip_info, NULL); > + if (IS_ERR(priv->hwmon_dev)) { > + ret = PTR_ERR(priv->hwmon_dev); > + hid_err(hdev, "hwmon registration failed with %d\n", ret); > + goto fail_and_close; > + } > + > + hid_device_io_start(hdev); > + ret = waterforce_get_fw_ver(hdev); > + if (ret < 0) > + hid_warn(hdev, "fw version request failed with %d\n", ret); > + hid_device_io_stop(hdev); > + > + waterforce_debugfs_init(priv); > + > + return 0; > + > +fail_and_close: > + hid_hw_close(hdev); > +fail_and_stop: > + hid_hw_stop(hdev); > + return ret; > +} > + > +static void waterforce_remove(struct hid_device *hdev) > +{ > + struct waterforce_data *priv = hid_get_drvdata(hdev); > + > + hwmon_device_unregister(priv->hwmon_dev); Should debugfs_remove_recursive(() be called? (if CONFIG_DEBUG_FS is defined) CJ > + > + hid_hw_close(hdev); > + hid_hw_stop(hdev); > +} ...