From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from IND01-MAX-obe.outbound.protection.outlook.com (mail-maxind01olkn2045.outbound.protection.outlook.com [40.92.102.45]) (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 05B431662E4; Wed, 31 Jul 2024 06:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.102.45 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722406422; cv=fail; b=Y3UbTTh1i0oOsGKJpAtHBD5VgVNHVef1XNPxPZod27wKg2BMnLMlsJ1MAfRn0EcQaBNzUgLLmt0FMNBOS3JZEAP+U/HFWeU8dr7kU0gDxV5OX8yI4pjovZZyt6uvptkmwU7PZoddUXr5vhUK0ZU7dxuPlGIBiXZ7Oxtinfa6LFg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722406422; c=relaxed/simple; bh=YsKpYxndXdLbmEstd0SRT+Lpz8fRUFGZOR+qhe6nzMs=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=HionQWa7vEX0o5UAu2MguWFov/p9jWOBjtZx/VK7Ny/ibkvsXrE6f0faq4R+3elrBZRm8eLjjc9ysDI+ZjXcNSFMviwfvnJvaBW2B1kcekUls4YtoWB/lWuTpLrsOh7w4VEqFOPnqcPd+6Kwu7uZfiPmtFapR0k+Y+kbdivvvo8= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=lzgPcmg4; arc=fail smtp.client-ip=40.92.102.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="lzgPcmg4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P4Ve/n60bnVcoKwAroeJNeyjry/YvU2ALvAiWsdOvrHqU6BViZU48YGYzHe8TigHRTI+oQ1247nMB5cD3x+J/dg5Ay03swSN9jE7dsUprNK6bam6oHf3Lwccf+CPhqcR2Yot/MWFUjFCm6IBEM4ZzvKlxoHmTvoWcAA05CAlmVhysjCv4xaW8xpXcueYpJrC43nO/e3dXNzXwEeFEXe4lxVfuwC3wqXN3k7BoPJv42/OHwqRllDhYbxMIqg4Thw/xrI9L4cGclrQ7Pi3V/7AcPQv2QFTNSbxx2/iyO3By9eJXYeVVy7OCVAxlmlsqWfelRvi+/A4h7jy7xKsRBotjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kygkSvs6m/sZslXaJuT5HOBMHHCKaOo1XT4KYtC2+4Q=; b=kxiWEfEarORnA7x0bohI8xUm6Ht5gPsc0U5j5dD18DV6UFuqStqxY/w6f0nkqKPd0cxRN6c9BZIWzaFpfOcw6h/Pjmttm8RI2ouhCahaFKR7QX1hIncYOCAJ+88jcCuZmxADibbaGIcPsmeR1WfEHXRV1kb2ZuiNTPCd+1VO3/fvi9xwXz6Pa6uxHLV5AIVr7I9z1p73q/y1jaYkJMbW3STRte7k8MRPZMIjnl9qskwksQOHv1yUBmDBm54fy4KHy5Bpw1L/7t09+NeSbPBynZJvOtxpYNSWE5qHYhfcf84saD7eGCqytpkbmKQ42fRr6kdLtAyD4/JyHMWU2jcE5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kygkSvs6m/sZslXaJuT5HOBMHHCKaOo1XT4KYtC2+4Q=; b=lzgPcmg4mQQQQsXVPSVeHwIAqPMnY3nOTbNcILwGbkjHW8KKewLSiDMwe6XJge/hVHvxr+dcmNsZAVtZnOaYY2UTJd95qykWk+NexrdgxzKO0iX/CIwW3+U9VGLC8GVG7yS0/8CtOOs77oPYj08lVnaQfpHD2DvxYMbiipH3ESYozaLJCvvMsKJtKTS++sy8aEX6xOO1U/5+rQaQ0bOEg9S0sdT35B0ubRyX2/8EMQDwqX8tbpFcEC92+xgwU6eKWweBZaDFt5EwSaPVGpvPy4HhdGKSdxScwsUC+sSHzJ7zdAAipdFxz9AH/uCWG6Nr8AUwAxpZGze4i/gMD0Z0sw== Received: from MA0P287MB2822.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:138::5) by MA0P287MB1790.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:f5::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Wed, 31 Jul 2024 06:13:29 +0000 Received: from MA0P287MB2822.INDP287.PROD.OUTLOOK.COM ([fe80::a94:ad0a:9071:806c]) by MA0P287MB2822.INDP287.PROD.OUTLOOK.COM ([fe80::a94:ad0a:9071:806c%6]) with mapi id 15.20.7828.016; Wed, 31 Jul 2024 06:13:29 +0000 Message-ID: Date: Wed, 31 Jul 2024 14:13:20 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 2/4] drivers: hwmon: sophgo: Add SG2042 external hardware monitor support To: Inochi Amaoto , Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Chao Wei , Hal Feng , Jinyu Tang , Lad Prabhakar , chunzhi.lin@sophgo.com, haijiao.liu@sophgo.com Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org References: From: Chen Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TMN: [eXLlfhgaDTS9O329B2nx2E9V9PleYzF/] X-ClientProxiedBy: SG2PR06CA0240.apcprd06.prod.outlook.com (2603:1096:4:ac::24) To MA0P287MB2822.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:138::5) X-Microsoft-Original-Message-ID: <0de3f417-8127-489b-b31f-2d7cd450387f@outlook.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MA0P287MB2822:EE_|MA0P287MB1790:EE_ X-MS-Office365-Filtering-Correlation-Id: a8326ab5-fb41-4106-3d86-08dcb127e4cf X-Microsoft-Antispam: BCL:0;ARA:14566002|461199028|19110799003|8060799006|5072599009|3412199025|440099028; X-Microsoft-Antispam-Message-Info: /H4AG1Y91CJcaAAf6+RWRcDt9i0b3/4VhTYAqfq30UeXfbsOFNjNwpOzf1tDWI8szslmTcQaoOScZxMYEAoQbbqxf/Pw5xuRdXBffgvLKQK/6uJi/+8i7PutAUvoLOdtY4Ge5fA13UPCfBJ5Ulqfpw5NXU37RhzOB08LtJBToSwu7smnjvBH4fCmYah85ZL6O9su44EAQ6TIW43leNYCQ37Iorvp+3SrJmPIt2j3hCA3WZHbFRTu/xgmCt6P90268+AH+yK9hZyjeVcNQ9IO6u/lcUMiBlcJjeIJ5AMZHa7o3vYtcms9ad0ToiNqPv1bJtvL+D7oqNzXaPbByQAf0wNmlTbm/0Ij598LM+tA1ECxyEN/9qjUHb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= =?utf-8?B?K2pIVTBzd2tEeHllWHJOd0NYUDhxbzVFd3ZiTk9pRUplQ2RmU0R2bkF6WDBo?= =?utf-8?B?ZlRzUXhSdSsvL3pKWkI0dmowT3B2Q0x1dnByaFBLOHpRYkFjenVqNktzYnhY?= =?utf-8?B?aVZlMDFNR2NvbWlXeXBkM2JoVjlKYmNGSUJyREpXNS95MnVLYURqNktPeHE2?= =?utf-8?B?YzFEbVZvbzRwa3pveFRhNFlVSFlkbndvdmpaYWFnVlpzQ0Q2UFplZktlSDBR?= =?utf-8?Q?rW2P0dUuXrI66mVxeJGa?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8326ab5-fb41-4106-3d86-08dcb127e4cf X-MS-Exchange-CrossTenant-AuthSource: MA0P287MB2822.INDP287.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 06:13:29.4340 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0P287MB1790 On 2024/7/30 15:50, Inochi Amaoto wrote: [......] > +#define REG_CRITICAL_ACTIONS 0x65 The name "REG_CRITICAL_ACTIONS" is ambiguous. I have confirmed with sophgo engineers that the complete process is: when the measured temperature exceeds the temperature set by REG_CRITICAL_TEMP, the processor is powered off and shut down, and then after the temperature returns to the temperature set by REG_REPOWER_TEMP, it is decided whether to power on again or remain in the shutdown state based on the action set by REG_CRITICAL_ACTIONS, whether it is reboot or poweroff. So based on the above description, I think it would be better to call "REG_CRITICAL_ACTIONS" as "REG_REPOWER_ACTIONS". "REG_CRITICAL_ACTIONS" gives people the first impression that it is used to set actions related to REG_CRITICAL_TEMP. It is also recommended to add the above description of temperature control and action settings in the code. Currently, sophgo does not have a clear document description for this part, and adding it will help us understand its functions. Adding sophgo engineers Chunzhi and Haijiao, FYI. > +#define REG_CRITICAL_TEMP 0x66 > +#define REG_REPOWER_TEMP 0x67 > + > +#define CRITICAL_ACTION_REBOOT 1 > +#define CRITICAL_ACTION_POWEROFF 2 As I said upon, actions are not related to critical, but is for restoring from critical, suggest to give a better name. [......] > +static ssize_t critical_action_show(struct device *dev, [......] > +static ssize_t critical_action_store(struct device *dev, [......] The same reason as upon, "critical_action_xxx" is misleading. [......] > +static int sg2042_mcu_read_temp(struct device *dev, > + u32 attr, int channel, > + long *val) > +{ > + struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); > + int tmp; > + u8 reg; > + > + switch (attr) { > + case hwmon_temp_input: > + reg = channel ? REG_BOARD_TEMP : REG_SOC_TEMP; > + break; > + case hwmon_temp_crit: > + reg = REG_CRITICAL_TEMP; > + break; > + case hwmon_temp_crit_hyst: > + reg = REG_REPOWER_TEMP; > + break; > + default: > + return -EOPNOTSUPP; > + } > + > + tmp = i2c_smbus_read_byte_data(mcu->client, reg); > + if (tmp < 0) > + return tmp; > + *val = tmp * 1000; > + > + return 0; > +} > + > +static int sg2042_mcu_read(struct device *dev, > + enum hwmon_sensor_types type, > + u32 attr, int channel, long *val) > +{ > + return sg2042_mcu_read_temp(dev, attr, channel, val); > +} Can we merge sg2042_mcu_read and sg2042_mcu_read_temp? > + > +static int sg2042_mcu_write(struct device *dev, > + enum hwmon_sensor_types type, > + u32 attr, int channel, long val) > +{ > + struct sg2042_mcu_data *mcu = dev_get_drvdata(dev); > + int temp = val / 1000; > + int hyst_temp, crit_temp; > + int ret; > + u8 reg; > + > + if (temp > MCU_POWER_MAX) > + temp = MCU_POWER_MAX; > + > + mutex_lock(&mcu->mutex); > + > + switch (attr) { > + case hwmon_temp_crit: > + hyst_temp = i2c_smbus_read_byte_data(mcu->client, > + REG_REPOWER_TEMP); > + if (hyst_temp < 0) { > + ret = -ENODEV; > + goto failed; > + } > + > + crit_temp = temp; > + reg = REG_CRITICAL_TEMP; > + break; > + case hwmon_temp_crit_hyst: > + crit_temp = i2c_smbus_read_byte_data(mcu->client, > + REG_CRITICAL_TEMP); > + if (crit_temp < 0) { > + ret = -ENODEV; > + goto failed; > + } > + > + hyst_temp = temp; > + reg = REG_REPOWER_TEMP; > + break; > + default: > + mutex_unlock(&mcu->mutex); > + return -EOPNOTSUPP; > + } > + It is recommended to add some comments to explain why we need to ensure that crit_temp is greater than or equal to hyst_temp. This is entirely because the current MCU does not limit the input, which may cause user to set incorrect crit_temp and hyst_temp. > + if (crit_temp < hyst_temp) { > + ret = -EINVAL; > + goto failed; > + } > + > + ret = i2c_smbus_write_byte_data(mcu->client, reg, temp); > + > +failed: > + mutex_unlock(&mcu->mutex); > + return ret; > +} > + [......]