Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp11231pxv; Thu, 24 Jun 2021 01:22:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxutkS5vUorvy2DP28ApG4B2Cv5n7IDa9xhO1P5GSmG4q4k2/+x6wu/OOnT2GPw/RCREXpm X-Received: by 2002:a17:906:82cf:: with SMTP id a15mr4121437ejy.359.1624522949862; Thu, 24 Jun 2021 01:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624522949; cv=none; d=google.com; s=arc-20160816; b=Qnmvkqn2RFL/RrdIdlw40QVF/GV3SnWaVSBG/4m+eDqpUTW3ozxrt3ptrWhF8Nyilc 7+eWHYEc/lZMs3QebJ2SI9y8GgS7nhnQC1UgM2NqXORLBTDISPD0ZzdRauWbVFmX1wID wL/OiP0ARPmn9oRDJTR4j7xepy2qykf8unPxCdu72hN7YJYHqJ2AGTZIzYwtKMGySs6F JcGchuzR6fwxUyM36o+UM9GOrg0wx8zIXROmacxUxjA9lyBx5LsuGwbA7Ae1hhLCNNFe Mvj8D0opKjgt7RpjGiPEvy+tXe9yzDrv+lkI1hdWLfuuAFr6/pIaNctYTe0bx2saRvkS ggkA== 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=HNUWuqrxVQTnwiFC8WouZpCK7dDNHne0/fZ7ZJMqRNQ=; b=VRLoE5bFhyFtw5fpBLMWRW5sKQEYvw0XRzyZEKoDAsLr/wZpaV57mVjbJ7j0rPqO65 Jk264h/kvn9b/euM+yDmT3VedmUkPFzyHkOK8oQsXWoUxigYqzbh13Ua0EVnWX4qUng9 bPDP8Coaj9zxaQEZU1AxkaPF4qrgOBMNknJaj63TNKZ7VBFajvOc10qEIHUj17tBdfa9 wYENddpBhpH5FPL9ZfeGd9eD7uA/K2/d2LgNfkkIE+i2NgXumIQLnf4KeWuGdCUdri+Y tXtdErbaJR5FXqiNUTKcEx9qXwuxENdHevTEBiv1Vb7g834yj+D5M0VlJgUyHv0QjpPR HUqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=F1daisEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si2172119ejl.585.2021.06.24.01.22.06; Thu, 24 Jun 2021 01:22:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=F1daisEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231901AbhFXIV5 (ORCPT + 99 others); Thu, 24 Jun 2021 04:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231713AbhFXIVy (ORCPT ); Thu, 24 Jun 2021 04:21:54 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB24C06175F for ; Thu, 24 Jun 2021 01:19:34 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id mj3so736594ejb.4 for ; Thu, 24 Jun 2021 01:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HNUWuqrxVQTnwiFC8WouZpCK7dDNHne0/fZ7ZJMqRNQ=; b=F1daisEjVlUxd1cUecOhmbxPuXNwmb5mz8qkw6FK+mOifcEWoXDMo2q2Dj6hRkWhqB HR9Q/rz1q53kgfTZn5/X6PZ7+0PpTH3YfrH+0EewnrqMW8Hs+PkXAccXNSycoKhCSEkW xE56jYx20Ou4V+LWVOKDA1zpu+kcbqxlT1YO8TdcxCXEBwpNB9+jkxpmENHXg3z+eV5o lku/1hyhrW36UjPHgqBh4Wb8TiOJCOu5uevsvugZvoCPy7vM0nUDGSs1LLATmadiSW20 AsI6mQaiP25o7bIE+inNCpwoydFV8ZtuzADe4NRThBQWwDiLHlSXWPdrIdgPLEjrmwy3 lIlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HNUWuqrxVQTnwiFC8WouZpCK7dDNHne0/fZ7ZJMqRNQ=; b=Y7JMzy0IS20jFfTSN8SJtLoe4NHoBcQ8jm7Z4w/sHb4ZgicSHM4PRDwE+Q9X0LjCeP fISJqpoiIuqVFBENjAmdO2yZpwUcWAqg6xDnrNj7JTFC5CvQ9g2YlS5bhMvg3A5HBUCj t6J4Kp46v7dA+2i4bV6A6LUFXfJ/NQcPf6ZTxShsSEWvRKT9rsiQxxwajuGlgtPoT55W 7qgUUSiKnWEdREhBPrNLI48osgTiXy8hYVuBbPQWpVkBFo6kx1iiEa7PrSf+NhBIjQ/B xSeFOpZBU8N55yZm27/bIEfEMRlxfCMNQQkahl8v//G0Qx78C8ygpWJukElLKhZaMNP8 0+uw== X-Gm-Message-State: AOAM531Cf6uVWZCQsZ97WPUO39Ls8Hwq0nvn3qo9V8n6U3hDVihs19sw GFgIcXjQc2KW0EebxvhzkwEUHg== X-Received: by 2002:a17:906:9419:: with SMTP id q25mr4115347ejx.341.1624522773141; Thu, 24 Jun 2021 01:19:33 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id o4sm1374641edc.94.2021.06.24.01.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 01:19:32 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, pmeerw@pmeerw.net, Alexandru Ardelean Subject: [PATCH 2/2] iio: temperature: tmp006: make sure the chip is powered up in probe Date: Thu, 24 Jun 2021 11:19:24 +0300 Message-Id: <20210624081924.15897-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210624081924.15897-1-aardelean@deviqon.com> References: <20210624081924.15897-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the device is probed, there's no guarantee that the device is not in power-down mode. This can happen if the driver is unregistered and re-probed. To make sure this doesn't happen, the value of the TMP006_CONFIG register (which is read in the probe function and stored in the device's private data) is being checked to see if the MOD bits have the correct value. This is a fix for a somewhat-rare corner case. As it stands, this doesn't look like a high priority to go into the Fixes route. Signed-off-by: Alexandru Ardelean --- drivers/iio/temperature/tmp006.c | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index db1ac6029c27..e4943a0bc9aa 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -193,15 +193,23 @@ static bool tmp006_check_identification(struct i2c_client *client) return mid == TMP006_MANUFACTURER_MAGIC && did == TMP006_DEVICE_MAGIC; } -static int tmp006_powerdown(struct tmp006_data *data) +static int tmp006_power(struct device *dev, bool up) { + struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); + struct tmp006_data *data = iio_priv(indio_dev); + + if (up) + data->config |= TMP006_CONFIG_MOD_MASK; + else + data->config &= ~TMP006_CONFIG_MOD_MASK; + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config & ~TMP006_CONFIG_MOD_MASK); + data->config); } -static void tmp006_powerdown_cleanup(void *data) +static void tmp006_powerdown_cleanup(void *dev) { - tmp006_powerdown(data); + tmp006_power(dev, false); } static int tmp006_probe(struct i2c_client *client, @@ -239,7 +247,14 @@ static int tmp006_probe(struct i2c_client *client, return ret; data->config = ret; - ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); + if ((ret & TMP006_CONFIG_MOD_MASK) != TMP006_CONFIG_MOD_MASK) { + ret = tmp006_power(&client->dev, true); + if (ret < 0) + return ret; + } + + ret = devm_add_action_or_reset(&client->dev, tmp006_powerdown_cleanup, + &client->dev); if (ret < 0) return ret; @@ -249,16 +264,12 @@ static int tmp006_probe(struct i2c_client *client, #ifdef CONFIG_PM_SLEEP static int tmp006_suspend(struct device *dev) { - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - return tmp006_powerdown(iio_priv(indio_dev)); + return tmp006_power(dev, false); } static int tmp006_resume(struct device *dev) { - struct tmp006_data *data = iio_priv(i2c_get_clientdata( - to_i2c_client(dev))); - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config | TMP006_CONFIG_MOD_MASK); + return tmp006_power(dev, true); } #endif -- 2.31.1