Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1764369lqo; Sun, 12 May 2024 18:22:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXEMRd8imMurL7ZZ5DZuSsnPsTYAgJPaAAjYjlv1cl0ce+7B/PSC6QG82j5UIRaVMoM7yCtp8B8ZJSePjUEHonjrwjOSojyYZYBO907Dg== X-Google-Smtp-Source: AGHT+IHrsR6IwXudx4eQzgkcSt7U/3coyaeY8g1sXE4IF1s2X/HrKIeVmfW7TeO3y+Vcqjh68qPy X-Received: by 2002:a05:6870:f146:b0:22b:5bc1:66f5 with SMTP id 586e51a60fabf-24172a7e107mr9845279fac.16.1715563370434; Sun, 12 May 2024 18:22:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715563370; cv=pass; d=google.com; s=arc-20160816; b=V+nGJ5FjcrEZr0IbgbCsuAZ1LRNxnAq1gW39ZPKPnuPof4qkVA+iPmJP9jpejQFHVz tafleOfyRsGjDEjohKVLdIKAiQKcTy2YvaZj76AwMWDunrxy/X9ky2RmV3SD+p1JxzpP cL2Tgq5VUlBxkPXtes1+BComxoLtguVwN77UMkgWkyUPX612IRBrqmjUPuulBjvIw8Dv OH9QUHcKom8WRU+poOVJm1fJ08icFONZmGKGv33Nib7safcNqthVlkSuIjm3LQSZ6lEo QbQQqOvGMbWkX6VbkXw5uhRBBTs36g3YZUTM2bcuqk9JqTw1dAAkVAbWTuAwWCHvs5Rt cF7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=ijgFb6A4ftPnO7yiRdVLXx243uCWE6Izk7lM8Q5vIhA=; fh=qiVjn6EIgZreoKukwQfmKohrZsQZkHxk7KEMnxlL2EA=; b=cmy/VT6MPoEe1qOk0K83visPxt406vqidBbHQbWNYhEvMRWaPv1idmEuwL+UsvInsk eDcfv12GHyfAhNNUsbUtDfVAJw85NoaMHDuLWb7Zjtzm9Iuu+8V/p/Gl3SMEKQ9KnWUf RUfKfcWtgGOZTKPZ2Is2u37//B4VP2kRopHSSpM6riSDvpkt0ExBR4SFeiDSAoiG1nbk AgdWvYAQkP9+sSCQM0whV0wlFKixFNnlt+eXQJPWyJS8xXkMzmoCGMOltE6vTbaLVM7w QTjLXxR+qVTInocbInIHkYXkEK+H+/+fWMKRbDCM1fflrhzR5xvR2UciYistyd18vNk6 KgZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=mariuszachmann.de); spf=pass (google.com: domain of linux-kernel+bounces-177077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177077-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2a9725dsi6247410b3a.121.2024.05.12.18.22.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 18:22:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=mariuszachmann.de); spf=pass (google.com: domain of linux-kernel+bounces-177077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177077-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BA9AD281352 for ; Mon, 13 May 2024 01:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FB31BE4F; Mon, 13 May 2024 01:22:44 +0000 (UTC) Received: from ms-10.1blu.de (ms-10.1blu.de [178.254.4.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53A9CAD23; Mon, 13 May 2024 01:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.254.4.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715563363; cv=none; b=g8AKVeP+3gqrO5VKkwUo0/qd1yNKwbxUa3CL5N9TevLAfHaNMJ4ORXIH/NORHWCrPstTst2ryDaRzOAQBEKhkuAqBgG7HiONr1s49YbQ7315ing0W7/z60osnm0lj531oVNHLvLDzSDJK264+woRelcU6ASJEvHINVRuh/JQ6B0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715563363; c=relaxed/simple; bh=iKIej+WOx8CGUwh5K91B2iytWfNQlrISCvxnlJi4XU8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lVoZ7/AxnXWtZyfyRRBMK+71i7HVK1BFsXBas55Hrp7pKFEdJtiOgH6/3nWjFEECzcLyT/bBFCxZgrrnEefxhGNy7n/Wayk5EJuFRXEePKk3AYxXDIv5pAPIJXsdp85BBVRzzYccO7JNwZnLzrqfbRMQlyLNtNqb3mSqo/7NSak= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mariuszachmann.de; spf=pass smtp.mailfrom=mariuszachmann.de; arc=none smtp.client-ip=178.254.4.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mariuszachmann.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mariuszachmann.de Received: from [2.211.228.80] (helo=marius.fritz.box) by ms-10.1blu.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1s6KOh-0077zo-FM; Mon, 13 May 2024 03:22:35 +0200 From: Marius Zachmann To: Guenter Roeck Cc: Marius Zachmann , Jean Delvare , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] hwmon: (corsair-cpro) Add firmware and bootloader information Date: Mon, 13 May 2024 03:21:42 +0200 Message-ID: <20240513012143.410304-2-mail@mariuszachmann.de> X-Mailer: git-send-email 2.45.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Con-Id: 241080 X-Con-U: 0-mail Add support for reporting firmware and bootloader version using debugfs. Update documentation accordingly. Signed-off-by: Marius Zachmann --- Changes in v2: - better patch description - Documentation uses "Firmware version" and "Bootloader version" - removed conditional CONFIG_DEBUG_FS - get_fw_version gets called from ccp_debugfs_init - get_fw_version does print a hid_notice when an error occurs instead of failing. --- Documentation/hwmon/corsair-cpro.rst | 8 ++++ drivers/hwmon/corsair-cpro.c | 68 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/Documentation/hwmon/corsair-cpro.rst b/Documentation/hwmon/corsair-cpro.rst index 751f95476b57..15077203a2f8 100644 --- a/Documentation/hwmon/corsair-cpro.rst +++ b/Documentation/hwmon/corsair-cpro.rst @@ -39,3 +39,11 @@ fan[1-6]_target Sets fan speed target rpm. pwm[1-6] Sets the fan speed. Values from 0-255. Can only be read if pwm was set directly. ======================= ===================================================================== + +Debugfs entries +--------------- + +======================= =================== +firmware_version Firmware version +bootloader_version Bootloader version +======================= =================== diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c index 3e63666a61bd..60c992fa296c 100644 --- a/drivers/hwmon/corsair-cpro.c +++ b/drivers/hwmon/corsair-cpro.c @@ -10,11 +10,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -28,6 +30,8 @@ #define LABEL_LENGTH 11 #define REQ_TIMEOUT 300 +#define CTL_GET_FW_VER 0x02 /* returns the firmware version in bytes 1-3 */ +#define CTL_GET_BL_VER 0x06 /* returns the bootloader version in bytes 1-2 */ #define CTL_GET_TMP_CNCT 0x10 /* * returns in bytes 1-4 for each temp sensor: * 0 not connected @@ -78,6 +82,7 @@ struct ccp_device { struct hid_device *hdev; struct device *hwmon_dev; + struct dentry *debugfs; /* For reinitializing the completion below */ spinlock_t wait_input_report_lock; struct completion wait_input_report; @@ -88,6 +93,8 @@ struct ccp_device { DECLARE_BITMAP(temp_cnct, NUM_TEMP_SENSORS); DECLARE_BITMAP(fan_cnct, NUM_FANS); char fan_label[6][LABEL_LENGTH]; + u8 firmware_ver[3]; + u8 bootloader_ver[2]; }; /* converts response error in buffer to errno */ @@ -496,6 +503,63 @@ static int get_temp_cnct(struct ccp_device *ccp) return 0; } +/* read firmware and bootloader version */ +static void get_fw_version(struct ccp_device *ccp) +{ + int ret; + + ret = send_usb_cmd(ccp, CTL_GET_FW_VER, 0, 0, 0); + if (ret) { + hid_notice(ccp->hdev, "Failed to read firmware version.\n"); + } else { + ccp->firmware_ver[0] = ccp->buffer[1]; + ccp->firmware_ver[1] = ccp->buffer[2]; + ccp->firmware_ver[2] = ccp->buffer[3]; + } + + ret = send_usb_cmd(ccp, CTL_GET_BL_VER, 0, 0, 0); + if (ret) { + hid_notice(ccp->hdev, "Failed to read bootloader version.\n"); + } else { + ccp->bootloader_ver[0] = ccp->buffer[1]; + ccp->bootloader_ver[1] = ccp->buffer[2]; + } +} + +static int firmware_show(struct seq_file *seqf, void *unused) +{ + struct ccp_device *ccp = seqf->private; + + seq_printf(seqf, "%d.%d.%d\n", + ccp->firmware_ver[0], + ccp->firmware_ver[1], + ccp->firmware_ver[2]); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(firmware); + +static int bootloader_show(struct seq_file *seqf, void *unused) +{ + struct ccp_device *ccp = seqf->private; + + seq_printf(seqf, "%d.%d\n", + ccp->bootloader_ver[0], + ccp->bootloader_ver[1]); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(bootloader); + +static void ccp_debugfs_init(struct ccp_device *ccp) +{ + get_fw_version(ccp); + + ccp->debugfs = debugfs_create_dir("corsaircpro", NULL); + debugfs_create_file("firmware_version", 0444, ccp->debugfs, ccp, &firmware_fops); + debugfs_create_file("bootloader_version", 0444, ccp->debugfs, ccp, &bootloader_fops); +} + static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct ccp_device *ccp; @@ -542,6 +606,9 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = get_fan_cnct(ccp); if (ret) goto out_hw_close; + + ccp_debugfs_init(ccp); + ccp->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsaircpro", ccp, &ccp_chip_info, NULL); if (IS_ERR(ccp->hwmon_dev)) { @@ -562,6 +629,7 @@ static void ccp_remove(struct hid_device *hdev) { struct ccp_device *ccp = hid_get_drvdata(hdev); + debugfs_remove_recursive(ccp->debugfs); hwmon_device_unregister(ccp->hwmon_dev); hid_hw_close(hdev); hid_hw_stop(hdev); -- 2.45.0