Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1707582lqo; Sun, 12 May 2024 15:03:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7CHy2mMIzi4nJPnff//qcynlUah+JNCJU43nj3qk5p1Zvub081eDQ/WXpeNuRx95EvapCOak3Zmif9UceN2ZslypEU+pNKTlLNHmYwg== X-Google-Smtp-Source: AGHT+IGjOkNKWrCzkvW+GSv++KvAuiXD5i4tU7oK6WcBxFA3Mce2ddtgqZ1bIFMkWE4EIrjEMd5l X-Received: by 2002:a17:907:3f8a:b0:a59:cf38:5338 with SMTP id a640c23a62f3a-a5a2d55ad95mr677180466b.19.1715551413935; Sun, 12 May 2024 15:03:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715551413; cv=pass; d=google.com; s=arc-20160816; b=0NcFmK3uc1mbYAvUa0fewEfFDmQ3paBsv3+PTKb/A6TK7HCNHx0LRRtqz5S7IYy+Pl ZQnhyJVVV2vet8ksHi1BXnLu9I90Hq6kni5nHDLrDbyISDM0x7O0NfVdxtQwVIq/CI3b dUdYJsjxUKYUattxH06qsBGuEFUHCHuQvzsLkX0t8PBASiU+3+rsOhvQN15hUewrd6q7 z1yVDMUanFqm2O/oiDfgKPC/j4PSnzb9Bud10ihGpi7Y0/7TRXaYnAQomLk0hsnqX/w6 cv01FfAm4LAHLyuOo6z+c3JXsK9i8IwVECL8Qqm7EjCiDZ8B8/oCFKwCe5F2YuWThBif 0TuA== 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=29WvqykhfwFGay3fJhno7pUhMfm1+gquRt8WN0eqSEU=; fh=qiVjn6EIgZreoKukwQfmKohrZsQZkHxk7KEMnxlL2EA=; b=u7I/EUTDK773OJ69zgvk65fX2JfwSL+E0dX6+jTaD7SS14GnOi7BhS9uVCqxJN7HmC ifpvitYscKm3q9OtzD3jXs/ttIZE9H1hcMhkMnPwZRyUvyPtrZmE5JbbT2fNcSjRlmZ8 ZLgOWbrfttvG833JtQBLU8EuWsnKbt+Fh4svuNbn+XyfhjTicVMOsiGqy1W2QZFSvug5 v7Fncd4iJaGKYrHNWBiUSF/rCL61PVr6LhcZtkyi2BOlr49iAqyAz9KcEcS6DKzPCx2z GzfecWUeQs+kezgXbeuOSBFhFAag45O1WQFO347+GHv0LhKdmt62hxjtqKEBWSoxA1e/ 9GTA==; 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-177032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177032-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17ba4ff7si440265766b.582.2024.05.12.15.03.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 15:03:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=mariuszachmann.de); spf=pass (google.com: domain of linux-kernel+bounces-177032-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177032-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 969881F21172 for ; Sun, 12 May 2024 22:03:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC19554F8D; Sun, 12 May 2024 22:03:26 +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 9B33242A8B; Sun, 12 May 2024 22:03:22 +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=1715551406; cv=none; b=mdF6764KT1zUqOfg3rlAIL7SHyTRwfXAvjxzsxNWIOPEceOwEHUpcec+/BN2gGxU166v/wCJNIf2zffUwe4SFthjTUEB1l243uE3PrllK4g9hDCn8F4B5oPYXJa+GkYBV9aVSwM24gQw1T+5zzLO39KUWtwV/MxEcNUSC8+yV+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715551406; c=relaxed/simple; bh=dux3huahA1liLOpFwdmSO8xRrf6oOdxNpUOjfeKr07w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eSYk2zMOaVGPsN0sOx2wQ6OEYm7pXa9HxGgmetveM+t33Rrxwz0x+LDGwfvt/xV3L4gp8DqG3wIrh5yu1fZM0zR1NSpBK/EACIVqqaj+bxKwla9XaLWMD4N+1xFnh+ts9e1se2aCAj9Bi2T86sz3ZlaCTZXaSTbgDPseq3zfumQ= 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 1s6Gse-0051Ux-KH; Sun, 12 May 2024 23:37:16 +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: Date: Sun, 12 May 2024 23:33:20 +0200 Message-ID: <20240512213320.40944-3-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 Date: Sun, 12 May 2024 23:15:49 +0200 Subject: [PATCH] Add firmware and bootloader information This patch adds: - Reading the firmware and bootloader version of the device - Debugfs entries: firmware_version and bootloader_version - Updated documentation Signed-off-by: Marius Zachmann --- Documentation/hwmon/corsair-cpro.rst | 8 +++ drivers/hwmon/corsair-cpro.c | 80 ++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/Documentation/hwmon/corsair-cpro.rst b/Documentation/hwmon/corsair-cpro.rst index 751f95476b57..11135d7ec6b9 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 Version of the firmware +bootloader_version Version of the bootloader +======================= =========================== diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c index 3e63666a61bd..4be8a98250a9 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,71 @@ static int get_temp_cnct(struct ccp_device *ccp) return 0; } +/* read firmware and bootloader version */ +static int get_fw_version(struct ccp_device *ccp) +{ + int ret; + + ret = send_usb_cmd(ccp, CTL_GET_FW_VER, 0, 0, 0); + if (ret) + return ret; + + 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) + return ret; + + ccp->bootloader_ver[0] = ccp->buffer[1]; + ccp->bootloader_ver[1] = ccp->buffer[2]; + + return 0; +} + +#ifdef CONFIG_DEBUG_FS + +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) +{ + 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); +} + +#else + +static void ccp_debugfs_init(struct ccp_device *ccp) +{ +} + +#endif + static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct ccp_device *ccp; @@ -542,6 +614,13 @@ 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; + + ret = get_fw_version(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 +641,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