Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp936631pxr; Mon, 11 Apr 2022 10:43:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX2Q0gHsfRE8smkqEWsRENZr7ZnVmehU9KqVRmWL4NTOpQHGgYzo9j18YPk8S+rqBpLnrV X-Received: by 2002:a17:907:3f10:b0:6da:818d:4525 with SMTP id hq16-20020a1709073f1000b006da818d4525mr30287184ejc.47.1649699034959; Mon, 11 Apr 2022 10:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649699034; cv=none; d=google.com; s=arc-20160816; b=IrtTQaDFwEJMxfcc0d35PRmkOnzP9HIH85Gj44IaMJn6jDclytn6Cv5CQO/707vvZ7 xtBq0DzAB7WYZlVC+n9XRuKn6DTkbq92Uihi7W4zVRY/KMJzTUuybn1jKI3TJm4iuWFD y9ym7IH90XCvjvOw23ScWkJ0qjo6ClXcwLROsnanioKF5Z1kTDuB1ty+l6c5Fr7Ozdqs oEewVN/8QF47il+lBJUgZrVfIZzQlKc3a/BqfyQqCEmqYyRw65EcLHhMoyn+uOrV7cMc O72ERnq6w/ySnN2IkHN13ga2Ny8LCJSZr5vU1KYqdmmglfmvGX8agpUX1Y2deventjFp E0+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FsUXYvruHmfAYwT/pxCNMHOLQLwKXMVdaCSrwdxakXs=; b=ttPjs6sKK0lI41Yrdrt0JkrSkIzmulQXuw/vt+nEM5t3QZdghgK66SdC9GyujPC4kP 6075r+NC/72TbiGX+S+AF1jt9m38jr212EnMhHzRYf+n0NGJA17tFRrsJ9/8PsumNPuz lZ0OGqmzuhnX+4aZLG9IYkp9cV+X24Fu7gbxJsqIwK2HtaHuKKEXAepw1eYgFU3k6g2h ShGvM+uPKuQXxUsD8KLmWRR1sqDX24MsBh4WOvLRKFZa/A4t7PAQaM/vyiWan1FkCv4H hpaLuNoNUYs6v5ZF6mT/JCFH8zg8qIHZVPQx9ZsHSxsPZXTJ9HYsnYS5nvXQL/7Y4eLh kcoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=oh26PSRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b1-20020a50b401000000b00418c2b5bdd9si8074030edh.187.2022.04.11.10.43.29; Mon, 11 Apr 2022 10:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=oh26PSRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbiDKJ7L (ORCPT + 99 others); Mon, 11 Apr 2022 05:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344888AbiDKJ64 (ORCPT ); Mon, 11 Apr 2022 05:58:56 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C871641622; Mon, 11 Apr 2022 02:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1649671002; x=1681207002; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FsUXYvruHmfAYwT/pxCNMHOLQLwKXMVdaCSrwdxakXs=; b=oh26PSRXcSC3AyPFe3uSmTU2Qhtx8vNysQFJ/EV29GmWqDBNQ1hw6Qtm qol3VsFHkUYtS3NZlXoYazGdklNpWb1DOIRKlPy3k6gSO16WwR/n1ZIQc wVEYffW4MEAgxFmfpXAEUFJZaKFP+3shzCYzd2nXPbBc5oGYztEaUtdhv JI0WXtbHVQfEJh2oyeViR33vpk3H0uwKBF4HFZCu8TYiuVqE0wEGgXO/6 MjwJn6s7hsa0A1lnzpgIJIG6hkS50Y10M/vF5fc89h6aIzxngDZXCU8iE Aj5aT+nqjbR96CxzJbtNJMIX2bj4gFG6bdwv3fXesBUuNbSG0yVqsBbCc A==; From: Camel Guo To: , , , CC: , Camel Guo , , , Subject: [PATCH 2/2] hwmon: (tmp401) Add support of three advanced features Date: Mon, 11 Apr 2022 11:56:34 +0200 Message-ID: <20220411095634.1782732-3-camel.guo@axis.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220411095634.1782732-1-camel.guo@axis.com> References: <20220411095634.1782732-1-camel.guo@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org tmp401 driver supports TMP401, TMP411 and TMP43X temperature sensors. According to their datasheet: - all of them support extended temperature range feature; - TMP411 and TPM43X support n-factor correction feature; - TMP43X support beta compensation feature. In order to support setting them during bootup, this commit reads ti,extended-range-enable, ti,n-factor and ti,beta-compensation and set the corresponding registers during probing. Signed-off-by: Camel Guo --- drivers/hwmon/tmp401.c | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index b86d9df7105d..75cdf5d2907e 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c @@ -41,6 +41,8 @@ enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 }; #define TMP401_STATUS 0x02 #define TMP401_CONFIG 0x03 #define TMP401_CONVERSION_RATE 0x04 +#define TMP4XX_N_FACTOR_REG 0x18 +#define TMP43X_BETA_RANGE 0x25 #define TMP401_TEMP_CRIT_HYST 0x21 #define TMP401_MANUFACTURER_ID_REG 0xFE #define TMP401_DEVICE_ID_REG 0xFF @@ -543,6 +545,7 @@ static int tmp401_init_client(struct tmp401_data *data) struct regmap *regmap = data->regmap; u32 config, config_orig; int ret; + u32 val = 0; /* Set conversion rate to 2 Hz */ ret = regmap_write(regmap, TMP401_CONVERSION_RATE, 5); @@ -557,10 +560,48 @@ static int tmp401_init_client(struct tmp401_data *data) config_orig = config; config &= ~TMP401_CONFIG_SHUTDOWN; + if (of_property_read_bool(data->client->dev.of_node, "ti,extended-range-enable")) { + /* Enable measurement over extended temperature range */ + config |= TMP401_CONFIG_RANGE; + } + data->extended_range = !!(config & TMP401_CONFIG_RANGE); - if (config != config_orig) + if (config != config_orig) { ret = regmap_write(regmap, TMP401_CONFIG, config); + if (ret < 0) + return ret; + } + + ret = of_property_read_u32(data->client->dev.of_node, "ti,n-factor", &val); + if (!ret) { + if (data->kind == tmp401) { + dev_err(&data->client->dev, "ti,tmp401 does not support n-factor correction\n"); + return -EINVAL; + } + if (val > 255) { + dev_err(&data->client->dev, "n-factor is invalid (%u)\n", val); + return -EINVAL; + } + ret = regmap_write(regmap, TMP4XX_N_FACTOR_REG, val); + if (ret < 0) + return ret; + } + + ret = of_property_read_u32(data->client->dev.of_node, "ti,beta-compensation", &val); + if (!ret) { + if (data->kind == tmp401 || data->kind == tmp411) { + dev_err(&data->client->dev, "ti,tmp401 or ti,tmp411 does not support beta compensation\n"); + return -EINVAL; + } + if (val > 15) { + dev_err(&data->client->dev, "beta-compensation is invalid (%u)\n", val); + return -EINVAL; + } + ret = regmap_write(regmap, TMP43X_BETA_RANGE, val); + if (ret < 0) + return ret; + } return ret; } -- 2.30.2