From patchwork Thu Sep 16 13:22:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Pasternak X-Patchwork-Id: 12499043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96175C433EF for ; Thu, 16 Sep 2021 13:23:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79C9F60F26 for ; Thu, 16 Sep 2021 13:23:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229474AbhIPNYl (ORCPT ); Thu, 16 Sep 2021 09:24:41 -0400 Received: from mail-mw2nam08on2055.outbound.protection.outlook.com ([40.107.101.55]:52288 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240099AbhIPNYj (ORCPT ); Thu, 16 Sep 2021 09:24:39 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BFDTN7l7xDw1zjwEIuiGs3fhB3masLqqSL79WXg059ZTlRpyP/6Cm7TKk8q+p2kSvss3LyTxGZ04lXDNU3zB8gEWJ8V7scZ+L5B7+plMidgL4sFFSd5qlDLa6kM/0HLe8Ns7FPII4cuLRsn6K+U9jP5UO7M6iVWd5r2AxpeVZi41YibRgurNuT0M7MLKVvhTX62Avxo6bS6blo10b/zdWiwr2Ef+Kdqvn1z4OHfVI0uBvEWjiQ11/vvCdiBjfw4iHMf4PLHq4666H4uyloGrZcaA8sqVRMygUNoDzkjqyo1C0yK6CeggnGB0QvFTLFL30IbEq0IuneVBPXzSV/vaxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=/1ttnibKv2qICmyHhtnScPLqWj3LnoLOuw4/gQhEoBY=; b=dYGUWNuveOyDjLp8rrbBtNqZvSuNdJ72MCUp+rohdR1lvE/C/2rhqQ/Lqsk7yr/yL266N9DIoWGmJ+7qfFLN2kAdBo70NuXlHZ7ZM4/bUB12Xh8eM7G+065qIlZGLerkCtZLLBu6rvGdkp1cyUffTNzPHb/xLxOVToH2cTr7DBV7EDDJi5Vp+P6dYoz5W+vM6etbctiiCO0cY8c0FpzHPJfUULsfKxu6wI7YVu29bUMjaA6GkbE0QfPoTgNLp6EnK2kn8fuSvBACr7XV7y0hAAZ/JNVP8zf3zEcbokRpdmmgLQKuVObjCgD1PCYTDLTW+iKg0bv838D3IfphAPKpiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/1ttnibKv2qICmyHhtnScPLqWj3LnoLOuw4/gQhEoBY=; b=uB+CypoHejC5e2bSL9LWFNOkcUOJ7IjxM7bVX5wB8pM8BUfp3s8ueGUZXLmatRfpwDRXArnpUEl1fiy1AThlEKyQ/id8FuAPSJJAlgjPXqeTU2VPMko6EninS5qWAV2/D7kmqmJ1XjaY3dFSmpHeEvT2fvNL/Co4plZfTw1KNSFvKGsFH+PXWkwtCDSQCV7SIQQ4ziBViHFyuq0iYn8+560uEuareHvAIQ57WkwmUEZfFiph6cyiM79OTf8AOVek2rz+kz26O8TzYyssx2M3BmFTAyoQgYq52RRla/ksf2LYMF96ipkJXzb5C2ECV1hsoTSZ2CQX4OQDq0Yg8bXc9Q== Received: from BN9PR03CA0601.namprd03.prod.outlook.com (2603:10b6:408:106::6) by DM6PR12MB2779.namprd12.prod.outlook.com (2603:10b6:5:4f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Thu, 16 Sep 2021 13:23:17 +0000 Received: from BN8NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:408:106:cafe::e) by BN9PR03CA0601.outlook.office365.com (2603:10b6:408:106::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; roeck-us.net; dkim=none (message not signed) header.d=none;roeck-us.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by BN8NAM11FT018.mail.protection.outlook.com (10.13.176.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:16 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 13:23:16 +0000 Received: from dev-r-vrt-156.mtr.labs.mlnx (172.20.187.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 13:23:14 +0000 From: Vadim Pasternak To: CC: , Vadim Pasternak Subject: [PATCH hwmon-next 1/3] hwmon: (mlxreg-fan) Extend the maximum number of tachometers Date: Thu, 16 Sep 2021 16:22:52 +0300 Message-ID: <20210916132254.831200-2-vadimp@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210916132254.831200-1-vadimp@nvidia.com> References: <20210916132254.831200-1-vadimp@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d7b8137-0ff2-41be-7e4a-08d9791524f6 X-MS-TrafficTypeDiagnostic: DM6PR12MB2779: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K17m8blibVtehgJGZKvtR1/Ac2PdNilOgYv0eE35mGOC13YV69lH03E8NwhtygKmANRpsVF3SmO6tiSeRKdOe/LwiXBiCYYVkqk2ut/vc/Fg+7QiuH3rB8Q8YH7cJ+BDbdZK17rWc4FSpaFsvAO2LFV76lUiZVOJXr24oihlnVGidAbkjqK620+Rpv/BKfjJkxwDXa1IEVDxuMfENTZWXqgx1/m/xDVk3AmZ/6PPlujg9P+G/tHlMUbrjECz1aa0jop2mfSi4PKqsDo2NweNwX+nOtnVHhN6hxkc0YEmpacYIVYDCVlY2HZvQKXK3Wr8h5KTFIbIuvZeIfceDhjWjKK4sfAVwKweZApvNkJa1ntknDBkYwF1aWnsgbPXTjnYtesK58KaFESYLE/r/IEJFFYIeu7j5ixiiTIJkrgE7us1UNw1Y1561zpGrmvOZwBAtl1W7WCMEq1RjUi1Eiwv/y2Ozb6YYf2dQbj7LzIrIubM56IH81qJSD+DFNbJfpP1K/vxyLDL7MfyMZaCL9rk3rpRf6DQD4MwTdLmhG+cQG2WXbayPjpvaucREPiVv09Y4st6GwlUZPDYACdtM8ztkzRwIW3JVWgi4glfPn74NndYFF4BvnmFGIDRdIb//VR0CtkvAMuwVFcmdvp5aD5R+yOOK7P3QO2gWQU4k9vE/pfNwKC8jb+SAYixYLxAMcxcciXBPp7bQazjrE1MQWdTwA== X-Forefront-Antispam-Report: CIP:216.228.112.36;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid05.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(396003)(39860400002)(36840700001)(46966006)(2616005)(356005)(54906003)(1076003)(47076005)(2906002)(426003)(26005)(36860700001)(478600001)(8676002)(36756003)(5660300002)(8936002)(6666004)(82310400003)(186003)(336012)(16526019)(70206006)(316002)(70586007)(36906005)(82740400003)(86362001)(107886003)(83380400001)(6916009)(7636003)(4326008);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2021 13:23:16.9314 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d7b8137-0ff2-41be-7e4a-08d9791524f6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.36];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2779 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Extend support of maximum tachometers from 12 to 14 in order to support new systems, equipped with more fans. Signed-off-by: Vadim Pasternak --- drivers/hwmon/mlxreg-fan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c index 13e73f05b9cb..6e6c7437db94 100644 --- a/drivers/hwmon/mlxreg-fan.c +++ b/drivers/hwmon/mlxreg-fan.c @@ -12,7 +12,7 @@ #include #include -#define MLXREG_FAN_MAX_TACHO 12 +#define MLXREG_FAN_MAX_TACHO 14 #define MLXREG_FAN_MAX_STATE 10 #define MLXREG_FAN_MIN_DUTY 51 /* 20% */ #define MLXREG_FAN_MAX_DUTY 255 /* 100% */ @@ -266,6 +266,8 @@ static const struct hwmon_channel_info *mlxreg_fan_hwmon_info[] = { HWMON_F_INPUT | HWMON_F_FAULT, HWMON_F_INPUT | HWMON_F_FAULT, HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_FAULT, + HWMON_F_INPUT | HWMON_F_FAULT, HWMON_F_INPUT | HWMON_F_FAULT), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT), From patchwork Thu Sep 16 13:22:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Pasternak X-Patchwork-Id: 12499047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02D83C4332F for ; Thu, 16 Sep 2021 13:23:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DABFC60F26 for ; Thu, 16 Sep 2021 13:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240103AbhIPNYm (ORCPT ); Thu, 16 Sep 2021 09:24:42 -0400 Received: from mail-dm6nam10on2073.outbound.protection.outlook.com ([40.107.93.73]:45920 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240099AbhIPNYm (ORCPT ); Thu, 16 Sep 2021 09:24:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XEtwH0s10F3h9sWvfg7i8rEjXDy+6VwbGExJtg84D9PHc0U6pK35ThYEhFDYvpQP834cwxqcr+doZFmXFv5kkzDmCFAJsE1aRLeaynZDWGQM0ro1NuiPwThMkCuw+W4hcdd3iObnr3fHiJ3J4OW+of6YQMEnY98Gm2y8XxWIVji2v007PoSqvlbjMko/7eWLY/PAOgpvEblWAJ0VHY9UGTnY7ndYd1Pem1jCuZr0snoPAPUwx8w3uOtMarBhZ94hiRUeKDiz7ZwGMOPCAFLRk7b0eIRKf5lj0EdFqEZ5waVrAmKqjBG2k39g2xlUqDcYc6OgcfWXTAs8BDbXfa5kCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=/22SkahqPV+un48E7MyrpwIinoY3ERT4ULlk+zJLYO4=; b=M35DYKLyHPgOTWGjrQwvGdKRuVSmgrAfgyLvwUv6tIcPVqitsBBJ/Q+lpodiDGBi9rWkUWn3sUoAd31K08vmuHee9KzW3RKHkuU6NzvGwvnrJe7Wz/NL3mEJQkQeV+6l/KoyKPXIKVSY7wF5h9MRe6HE16wnwlzfinMFXMDuxAfSNRtAK5Ez2VNLx5RfXEksmeeGJt/hlRZRywYGV8MlxE44+/mwXOPgN8mkswxTRogAvjKSBuvfEHjOfeVDYbxR7uXLrJTKjh0FE50vt2usgUIvujaxER4oO50olZjCSrAyG62kXWUbfsnivr/rBpuEgPkt6ZzKuZWzsUm8KApzsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/22SkahqPV+un48E7MyrpwIinoY3ERT4ULlk+zJLYO4=; b=HKtBMtodzRajnmzn4KpsB5b6H6SHJjAiFKqZsjBmAICTReASN/d2s8kU6Rd0RIgvA1r6NdhNE/rl5eE3VpPNCmxuLyNDi3UwrK8T7HpGWrkR/0GugspMr23eN5jR0fXQkmK4aEncczFT66mfGdb/muWs0Q0CXTCLnWdIl5ne/TsRfhSELRxvyQ5xvvPWKM/w2wItYejbaVV62iYM9wvQ4ASOlQJpU9lGF2MARqNlI8/4NFcyPCT7zua3PkrNs5OpLKvpJinO4MEgbPA5eyZFqLmDkQNwZPCey/Ee6qv+ShcpBWMpyHLfQ3mVRDDeS3AxIod7MeD8yn3TDiFfd+ar+g== Received: from CO1PR15CA0107.namprd15.prod.outlook.com (2603:10b6:101:21::27) by MN2PR12MB4063.namprd12.prod.outlook.com (2603:10b6:208:1dc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Thu, 16 Sep 2021 13:23:20 +0000 Received: from CO1NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:101:21:cafe::e6) by CO1PR15CA0107.outlook.office365.com (2603:10b6:101:21::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; roeck-us.net; dkim=none (message not signed) header.d=none;roeck-us.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT028.mail.protection.outlook.com (10.13.175.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:20 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 13:23:19 +0000 Received: from dev-r-vrt-156.mtr.labs.mlnx (172.20.187.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 13:23:17 +0000 From: Vadim Pasternak To: CC: , Vadim Pasternak Subject: [PATCH hwmon-next 2/3] hwmon: (mlxreg-fan) Extend driver to support multiply PWM Date: Thu, 16 Sep 2021 16:22:53 +0300 Message-ID: <20210916132254.831200-3-vadimp@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210916132254.831200-1-vadimp@nvidia.com> References: <20210916132254.831200-1-vadimp@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4ca4b844-d641-4318-a8c4-08d9791526d7 X-MS-TrafficTypeDiagnostic: MN2PR12MB4063: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lAJxVpHB0/p+qZsQEKf7kBGSN6mzlvFp/0lc35qjg9b+l95d+PYsXPcJQHQWBxyx0sX6g1p+8tStPKZGF7u9T0gRvPqt2z/GInMS3f7ZQffxbdD6xccNQTquYsgXoOWH7gpOgAxqyRtvHxw7GoI2CFaVgKLnE0T1N78lvdC+lZyNDjp65PNfHgwVST0Mz7F1ZG9Spza7Q/7C/3HIx7oibZ7MY0K0tPmsvEknN6pRQZAau4zzmFJlfHMb8CnoN3MklVBZRp2qBvkCaN16HAnTmKuc3JlqTQJsKqJs0eYG7Sg0I3r4u3V53c+rMFJTpVgtk8Mwuhb0j5CcGfjXphAeo4/uQcw8ttwYi8sCHjNwTNrMct3NV3+rDe8vHOy6zqEZ8EGtmAE63y0OKpqLSFMuNG2U0fjHiquJctaEwBY1ilps9GkSacqRNavb/v0NALO6hn9BO3flnQNeT0+xGpLaber5Ww3Kaa46tBD2SXTPLQ16G2/XUPWgl8xN4TRhtnUy/XYbhV5FolPUNZfhdQhrl82XMXVwCaAJ6FneCWwKIcDZwYyN4M0FQUu3LFxPJgUTIFb/BpuMLc1aCWgaM4KZ+hsNq/IRksQwLQAU/3rQbuQ9r5dskh7UZSexwc5MkKKVzyIVsMA157NZjhNhBVgL0Dqpzm6YbcAVeBk35UjsivV+WDrjeXGIi+ZnZAV/QibqlbytjkFruAsiIxpWwH81jg== X-Forefront-Antispam-Report: CIP:216.228.112.35;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid02.nvidia.com;CAT:NONE;SFS:(4636009)(376002)(346002)(396003)(39860400002)(136003)(46966006)(36840700001)(186003)(8676002)(2616005)(36756003)(16526019)(1076003)(6666004)(7636003)(2906002)(356005)(6916009)(36906005)(316002)(83380400001)(4326008)(5660300002)(86362001)(478600001)(8936002)(107886003)(82740400003)(54906003)(36860700001)(47076005)(336012)(82310400003)(26005)(70586007)(426003)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2021 13:23:20.1428 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4ca4b844-d641-4318-a8c4-08d9791526d7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.35];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4063 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add additional PWM attributes in order to support the systems, which can be equipped with up-to four PWM controllers. System capability of additional PWM support is validated through the reading of relevant registers. Signed-off-by: Vadim Pasternak --- drivers/hwmon/mlxreg-fan.c | 55 +++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c index 6e6c7437db94..930636868ef5 100644 --- a/drivers/hwmon/mlxreg-fan.c +++ b/drivers/hwmon/mlxreg-fan.c @@ -13,6 +13,8 @@ #include #define MLXREG_FAN_MAX_TACHO 14 +#define MLXREG_FAN_MAX_PWM 4 +#define MLXREG_FAN_PWM_NOT_CONNECTED 0xff #define MLXREG_FAN_MAX_STATE 10 #define MLXREG_FAN_MIN_DUTY 51 /* 20% */ #define MLXREG_FAN_MAX_DUTY 255 /* 100% */ @@ -105,7 +107,7 @@ struct mlxreg_fan { void *regmap; struct mlxreg_core_platform_data *pdata; struct mlxreg_fan_tacho tacho[MLXREG_FAN_MAX_TACHO]; - struct mlxreg_fan_pwm pwm; + struct mlxreg_fan_pwm pwm[MLXREG_FAN_MAX_PWM]; int tachos_per_drwr; int samples; int divider; @@ -119,6 +121,7 @@ mlxreg_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, { struct mlxreg_fan *fan = dev_get_drvdata(dev); struct mlxreg_fan_tacho *tacho; + struct mlxreg_fan_pwm *pwm; u32 regval; int err; @@ -169,9 +172,10 @@ mlxreg_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, break; case hwmon_pwm: + pwm = &fan->pwm[channel]; switch (attr) { case hwmon_pwm_input: - err = regmap_read(fan->regmap, fan->pwm.reg, ®val); + err = regmap_read(fan->regmap, pwm->reg, ®val); if (err) return err; @@ -195,6 +199,7 @@ mlxreg_fan_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { struct mlxreg_fan *fan = dev_get_drvdata(dev); + struct mlxreg_fan_pwm *pwm; switch (type) { case hwmon_pwm: @@ -203,7 +208,8 @@ mlxreg_fan_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, if (val < MLXREG_FAN_MIN_DUTY || val > MLXREG_FAN_MAX_DUTY) return -EINVAL; - return regmap_write(fan->regmap, fan->pwm.reg, val); + pwm = &fan->pwm[channel]; + return regmap_write(fan->regmap, pwm->reg, val); default: return -EOPNOTSUPP; } @@ -235,7 +241,7 @@ mlxreg_fan_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, break; case hwmon_pwm: - if (!(((struct mlxreg_fan *)data)->pwm.connected)) + if (!(((struct mlxreg_fan *)data)->pwm[channel].connected)) return 0; switch (attr) { @@ -270,6 +276,9 @@ static const struct hwmon_channel_info *mlxreg_fan_hwmon_info[] = { HWMON_F_INPUT | HWMON_F_FAULT, HWMON_F_INPUT | HWMON_F_FAULT), HWMON_CHANNEL_INFO(pwm, + HWMON_PWM_INPUT, + HWMON_PWM_INPUT, + HWMON_PWM_INPUT, HWMON_PWM_INPUT), NULL }; @@ -300,7 +309,7 @@ static int mlxreg_fan_get_cur_state(struct thermal_cooling_device *cdev, u32 regval; int err; - err = regmap_read(fan->regmap, fan->pwm.reg, ®val); + err = regmap_read(fan->regmap, fan->pwm[0].reg, ®val); if (err) { dev_err(fan->dev, "Failed to query PWM duty\n"); return err; @@ -339,7 +348,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev, for (i = state; i <= MLXREG_FAN_MAX_STATE; i++) fan->cooling_levels[i] = i; - err = regmap_read(fan->regmap, fan->pwm.reg, ®val); + err = regmap_read(fan->regmap, fan->pwm[0].reg, ®val); if (err) { dev_err(fan->dev, "Failed to query PWM duty\n"); return err; @@ -358,7 +367,7 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev, /* Normalize the state to the valid speed range. */ state = fan->cooling_levels[state]; - err = regmap_write(fan->regmap, fan->pwm.reg, + err = regmap_write(fan->regmap, fan->pwm[0].reg, MLXREG_FAN_PWM_STATE2DUTY(state)); if (err) { dev_err(fan->dev, "Failed to write PWM duty\n"); @@ -390,6 +399,22 @@ static int mlxreg_fan_connect_verify(struct mlxreg_fan *fan, return !!(regval & data->bit); } +static int mlxreg_pwm_connect_verify(struct mlxreg_fan *fan, + struct mlxreg_core_data *data) +{ + u32 regval; + int err; + + err = regmap_read(fan->regmap, data->reg, ®val); + if (err) { + dev_err(fan->dev, "Failed to query pwm register 0x%08x\n", + data->reg); + return err; + } + + return regval != MLXREG_FAN_PWM_NOT_CONNECTED; +} + static int mlxreg_fan_speed_divider_get(struct mlxreg_fan *fan, struct mlxreg_core_data *data) { @@ -418,8 +443,8 @@ static int mlxreg_fan_speed_divider_get(struct mlxreg_fan *fan, static int mlxreg_fan_config(struct mlxreg_fan *fan, struct mlxreg_core_platform_data *pdata) { + int tacho_num = 0, tacho_avail = 0, pwm_num = 0, pwm_avail = 0, i; struct mlxreg_core_data *data = pdata->data; - int tacho_num = 0, tacho_avail = 0, i; bool configured = false; int err; @@ -449,13 +474,19 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan, fan->tacho[tacho_num++].connected = true; tacho_avail++; } else if (strnstr(data->label, "pwm", sizeof(data->label))) { - if (fan->pwm.connected) { - dev_err(fan->dev, "duplicate pwm entry: %s\n", + if (pwm_num == MLXREG_FAN_MAX_TACHO) { + dev_err(fan->dev, "too many pwm entries: %s\n", data->label); return -EINVAL; } - fan->pwm.reg = data->reg; - fan->pwm.connected = true; + + err = mlxreg_pwm_connect_verify(fan, data); + if (err) + return err; + + fan->pwm[pwm_num].reg = data->reg; + fan->pwm[pwm_num].connected = true; + pwm_avail++; } else if (strnstr(data->label, "conf", sizeof(data->label))) { if (configured) { dev_err(fan->dev, "duplicate conf entry: %s\n", From patchwork Thu Sep 16 13:22:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Pasternak X-Patchwork-Id: 12499049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34321C433EF for ; Thu, 16 Sep 2021 13:23:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 195B860F26 for ; Thu, 16 Sep 2021 13:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240107AbhIPNYp (ORCPT ); Thu, 16 Sep 2021 09:24:45 -0400 Received: from mail-mw2nam10on2071.outbound.protection.outlook.com ([40.107.94.71]:59615 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240099AbhIPNYo (ORCPT ); Thu, 16 Sep 2021 09:24:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bsvZkcoQxE9QORgWjCsJNqisoc72AoV6hFndK0xhqpJnoLxyispnRXtfTAbS78kvZLkF2ZbAHYBRZW72L0mpZCqTtQ7+Y21525irU1/PrGCwOLvKJj9IOkJTOwLHdgdsB5qQMTfifgIFU8OJdtSurosdL60HU3cNUB+cLZNj5wlvvEcSG43B7lT3KWDaULrgzxXz4cMOmVh82SkIyMZDx+6xqt6pmP4DbFnuGc/atsTQYwS6IQeAbsBdtllMVDOOCRkn5bBog05DubNyI50G5VY/k1GRmoxi0VDXQs5vo7ocn+yaGNp7K12rnGFHBj4rcmKZ6i7d8/o+KlzCT+CeeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=4Fa3eKDZvECyzzatGmcJJI1y+W6H4udXWBYgoDgvSFM=; b=Q8tOKMDNBjv/O6QEVQ/vtcjDwb94Cmf4qqXTg+w2YO4Ncnr/RCBGovyoPa8Jque8VShLbshbklpQt7TDm4BjULFNjyALhX37ccuYN7yFMRyLqLp74yxQL0pW7YgLCsbDYbXmg//BT0+2tMvtGSgBuqOuDcVL8Av58UmIiB+W76dmKmnQsuQRygjx9qyKQNuY9SEGvig/a9WN3K+ND5MRLm8L97cZ06V3ukS6mkYqJ8nOEKRZ7ZJ9nE/XMGPSDFBLwofdX6YwtItGtQNcMw1wZJpJW6f/25Azm7Xw1hRVkkmih3fXyiB5lQRy7RVybhQZae+Y5uhQn9Xc+YdQgh2PLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=roeck-us.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Fa3eKDZvECyzzatGmcJJI1y+W6H4udXWBYgoDgvSFM=; b=hLNWGCH/VTbCIpoqMX54o9d3BxrJF1aoB68FC0mutaRvUgNJD+lhx8gg4fAeONvn0GOgdVgSEjso+jIf0CP0VzrDj5tpsvzciavORccQ4nWnwBoqsrIpJd4ncrRmV3NLlYjJCsTFuFzv+BSWLsyx7l6rTh49Iz8yk938shOQRToUCLhfEbxK1sHkuywQfxfPBxHA0tsHBXImdlaPMFOEMO7LUl2ODvdQ8Ry2XnrY/tfwegU+2Jp6bXnDdjt/lZuX8vHDiHPIRQr+EEiG14S5dBT1SAQi9A3miv8+FE//IwafRg7f9j6B00Ogt+o2+KoBQRwRB7dK2daXSHka1102Dg== Received: from MWHPR14CA0050.namprd14.prod.outlook.com (2603:10b6:300:81::12) by MN2PR12MB3901.namprd12.prod.outlook.com (2603:10b6:208:16c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Thu, 16 Sep 2021 13:23:22 +0000 Received: from CO1NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::db) by MWHPR14CA0050.outlook.office365.com (2603:10b6:300:81::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; roeck-us.net; dkim=none (message not signed) header.d=none;roeck-us.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by CO1NAM11FT040.mail.protection.outlook.com (10.13.174.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 13:23:21 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 06:23:21 -0700 Received: from dev-r-vrt-156.mtr.labs.mlnx (172.20.187.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 16 Sep 2021 13:23:19 +0000 From: Vadim Pasternak To: CC: , Vadim Pasternak Subject: [PATCH hwmon-next 3/3] hwmon: (mlxreg-fan) Extend driver to support multiply cooling devices Date: Thu, 16 Sep 2021 16:22:54 +0300 Message-ID: <20210916132254.831200-4-vadimp@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210916132254.831200-1-vadimp@nvidia.com> References: <20210916132254.831200-1-vadimp@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2100c05d-ecfc-47fb-d504-08d9791527a7 X-MS-TrafficTypeDiagnostic: MN2PR12MB3901: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sgOo+5l8l0W8ozIfXlWJ+P8gV9H8dj9EMzKWM/K2twQok09TNU0Xvzr/5GjjoiSP8Fdqj1bTMfHLgjTupm2YxKvU0mj1ghWWH+Cv7sqh/ioEORFj9NO08nYjjiNa/ZIM8RKdqxv5MzzMwiH4iJVionP+nuDHPv2veSwTbPPSPWWX5IM8rXkpnQTcT72Bn9Z/L8DJk6yiPKXdsS4Vrz68C0tnuLyjS4q+1aSJDLRuS11r6L76NW6GqXh1K3bOsyRLiDFSN7rfjIu4VkKiYaCdEiQdTPeaUBL/ugszqeDEvVcTXfcChpMOuwoTIk7POZ6Vy1Er+kLHv4DjtTxAPxyVXFSW2QPAPRr7EpWiIYCT1eqjB+bmeLOky/xDzmBN1D9QvcMxTwn459w34PtgHwJG354lwCCG0UlliawA96gC49oh+pHYDe5LxHsFilGDJnv79dE5VNSwGY2N0B6xmAsWX861sW49F7Tb/CRsCeTkZq68noSU9p71PK4YFF5zOwFkt3iLcoJGtJ9x37IPNuVX6M2sqhsJHqWRb482wq2iyAuA9AGxYHg+3QJ/lnXLccUEqdwmiBtlaCQjFARcTsFQ5hKsGThfL5hatxI7m0L+EycwnNCMIVLlMu7hAaMzmVcvlcBaDldpwX1v/FWvq+ZXpUG9KJ+qdMjAeAv9ut6i0XK/1q73jJ/AwK6PCmeQcEXxkkpwFDi0LWvj9sTJvUzyuQ== X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(39860400002)(346002)(376002)(396003)(136003)(36840700001)(46966006)(6916009)(7636003)(1076003)(356005)(107886003)(2906002)(4326008)(82740400003)(336012)(186003)(47076005)(36756003)(8936002)(86362001)(16526019)(5660300002)(70206006)(2616005)(70586007)(478600001)(316002)(36860700001)(83380400001)(426003)(26005)(6666004)(8676002)(54906003)(82310400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2021 13:23:21.5221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2100c05d-ecfc-47fb-d504-08d9791527a7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3901 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add support for additional cooling devices in order to support the systems, which can be equipped with up-to four PWM controllers. Signed-off-by: Vadim Pasternak --- drivers/hwmon/mlxreg-fan.c | 80 +++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c index 930636868ef5..f5968eb4ab78 100644 --- a/drivers/hwmon/mlxreg-fan.c +++ b/drivers/hwmon/mlxreg-fan.c @@ -63,6 +63,8 @@ MLXREG_FAN_MAX_DUTY, \ MLXREG_FAN_MAX_STATE)) +struct mlxreg_fan; + /* * struct mlxreg_fan_tacho - tachometer data (internal use): * @@ -81,12 +83,18 @@ struct mlxreg_fan_tacho { /* * struct mlxreg_fan_pwm - PWM data (internal use): * + * @fan: private data; * @connected: indicates if PWM is connected; * @reg: register offset; + * @cooling: cooling device levels; + * @cdev: cooling device; */ struct mlxreg_fan_pwm { + struct mlxreg_fan *fan; bool connected; u32 reg; + u8 cooling_levels[MLXREG_FAN_MAX_STATE + 1]; + struct thermal_cooling_device *cdev; }; /* @@ -99,8 +107,6 @@ struct mlxreg_fan_pwm { * @tachos_per_drwr - number of tachometers per drawer; * @samples: minimum allowed samples per pulse; * @divider: divider value for tachometer RPM calculation; - * @cooling: cooling device levels; - * @cdev: cooling device; */ struct mlxreg_fan { struct device *dev; @@ -111,8 +117,6 @@ struct mlxreg_fan { int tachos_per_drwr; int samples; int divider; - u8 cooling_levels[MLXREG_FAN_MAX_STATE + 1]; - struct thermal_cooling_device *cdev; }; static int @@ -305,11 +309,12 @@ static int mlxreg_fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) { - struct mlxreg_fan *fan = cdev->devdata; + struct mlxreg_fan_pwm *pwm = cdev->devdata; + struct mlxreg_fan *fan = pwm->fan; u32 regval; int err; - err = regmap_read(fan->regmap, fan->pwm[0].reg, ®val); + err = regmap_read(fan->regmap, pwm->reg, ®val); if (err) { dev_err(fan->dev, "Failed to query PWM duty\n"); return err; @@ -324,7 +329,8 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { - struct mlxreg_fan *fan = cdev->devdata; + struct mlxreg_fan_pwm *pwm = cdev->devdata; + struct mlxreg_fan *fan = pwm->fan; unsigned long cur_state; bool config = false; u32 regval; @@ -344,11 +350,11 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev, config = true; state -= MLXREG_FAN_MAX_STATE; for (i = 0; i < state; i++) - fan->cooling_levels[i] = state; + pwm->cooling_levels[i] = state; for (i = state; i <= MLXREG_FAN_MAX_STATE; i++) - fan->cooling_levels[i] = i; + pwm->cooling_levels[i] = i; - err = regmap_read(fan->regmap, fan->pwm[0].reg, ®val); + err = regmap_read(fan->regmap, pwm->reg, ®val); if (err) { dev_err(fan->dev, "Failed to query PWM duty\n"); return err; @@ -366,8 +372,8 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev, return -EINVAL; /* Normalize the state to the valid speed range. */ - state = fan->cooling_levels[state]; - err = regmap_write(fan->regmap, fan->pwm[0].reg, + state = pwm->cooling_levels[state]; + err = regmap_write(fan->regmap, pwm->reg, MLXREG_FAN_PWM_STATE2DUTY(state)); if (err) { dev_err(fan->dev, "Failed to write PWM duty\n"); @@ -539,13 +545,41 @@ static int mlxreg_fan_config(struct mlxreg_fan *fan, fan->tachos_per_drwr = tacho_avail / drwr_avail; } - /* Init cooling levels per PWM state. */ - for (i = 0; i < MLXREG_FAN_SPEED_MIN_LEVEL; i++) - fan->cooling_levels[i] = MLXREG_FAN_SPEED_MIN_LEVEL; - for (i = MLXREG_FAN_SPEED_MIN_LEVEL; i <= MLXREG_FAN_MAX_STATE; i++) - fan->cooling_levels[i] = i; + return 0; +} + +static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) +{ + int i, j, err; + + for (i = 0; i <= MLXREG_FAN_MAX_PWM; i++) { + struct mlxreg_fan_pwm *pwm = &fan->pwm[i]; + + if (!pwm->connected) + continue; + pwm->fan = fan; + pwm->cdev = devm_thermal_of_cooling_device_register(dev, NULL, "mlxreg_fan", pwm, + &mlxreg_fan_cooling_ops); + if (IS_ERR(pwm->cdev)) { + dev_err(dev, "Failed to register cooling device\n"); + err = PTR_ERR(pwm->cdev); + goto devm_thermal_of_cooling_device_register_fail; + } + + /* Init cooling levels per PWM state. */ + for (j = 0; j < MLXREG_FAN_SPEED_MIN_LEVEL; j++) + pwm->cooling_levels[j] = MLXREG_FAN_SPEED_MIN_LEVEL; + for (j = MLXREG_FAN_SPEED_MIN_LEVEL; j <= MLXREG_FAN_MAX_STATE; j++) + pwm->cooling_levels[j] = j; + } return 0; +devm_thermal_of_cooling_device_register_fail: + for (i = i - 1; i >= 0; i--) { + if (fan->pwm[i].cdev) + thermal_cooling_device_unregister(fan->pwm[i].cdev); + } + return err; } static int mlxreg_fan_probe(struct platform_device *pdev) @@ -582,16 +616,10 @@ static int mlxreg_fan_probe(struct platform_device *pdev) return PTR_ERR(hwm); } - if (IS_REACHABLE(CONFIG_THERMAL)) { - fan->cdev = devm_thermal_of_cooling_device_register(dev, - NULL, "mlxreg_fan", fan, &mlxreg_fan_cooling_ops); - if (IS_ERR(fan->cdev)) { - dev_err(dev, "Failed to register cooling device\n"); - return PTR_ERR(fan->cdev); - } - } + if (IS_REACHABLE(CONFIG_THERMAL)) + err = mlxreg_fan_cooling_config(dev, fan); - return 0; + return err; } static struct platform_driver mlxreg_fan_driver = {