From patchwork Thu Jun 24 08:19:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12341503 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 DD6B1C49EA7 for ; Thu, 24 Jun 2021 08:19:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5E5A613E8 for ; Thu, 24 Jun 2021 08:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231887AbhFXIV4 (ORCPT ); Thu, 24 Jun 2021 04:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231861AbhFXIVz (ORCPT ); Thu, 24 Jun 2021 04:21:55 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC538C061574 for ; Thu, 24 Jun 2021 01:19:33 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id h17so7255436edw.11 for ; Thu, 24 Jun 2021 01:19:33 -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:mime-version :content-transfer-encoding; bh=EaNSCMGV5qh1CquvxbjGYHMLSp9S15q2vTJ0o9vKxN0=; b=TLyee5ouAerT+C1yZLIoqowVjsiAD5gKsKq5chr0XpfUfnNX9rEcymsL5yVgHGxccp qaGcW9AlYF5rN8uL7o2qQALyFPLy0V+h0RC2zzwP48de8tfPqULW94YsYip0NJSTSxWd lskXHzb3R9kakbSUCIk4Y6fw/ig+Uuis9FwwG23rx7+SLI8c47AS6xnxsnFkHIi6ZtPi NFyzbVcrIz2gy4u0OQCr+kSlT1HJJSoUy/ryDW9vkB2KeCvNjt4Vr2wzloRyq49ExR59 m4leYGoCzK8EWTg+xHFQ8l3fKLte4Z4McYNcniAwTwiRXomdMHG8g+BKSYw9x8qGrghS oygA== 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:mime-version :content-transfer-encoding; bh=EaNSCMGV5qh1CquvxbjGYHMLSp9S15q2vTJ0o9vKxN0=; b=uVtm5wDz1Qq9chg1aHcbrEmFoJvz9QbqqeiAPk8IbN+syd1tz7pVp7YGL7rao9AhDb 3RHmQBo2fGl/ZY43jmiOTJHo07LiYrihOn56jxjJCK7vvvWtQjUGeWZr1BRbDRiY4a7b RkoEwJROjk9MAh+qd+pg87/j4UWRYcD6KzNkWMIymwSjoymNETDIUau5RzqmMhHuJYyc KIYnspwFvXvH4omCz8NLWbUg2WR3pDRcpuinQ/qkCO3z2hTvU0TxujZkeZp2eQDZlF1J z0CHSurgtlFjyrCeq1RLWhRIq2q4C9PnifjeWqWScBt2m87nIpSLcTz/LaM1fW4faDo5 DRLQ== X-Gm-Message-State: AOAM530b9hzRiAYHgGl7xrY2Ti2tajHoErHKuLxvCEtO5gdltQyH+GiV Ioi4B2c4EdwRazP1HbJIS142l6mLciSEU59n X-Google-Smtp-Source: ABdhPJzr1GubAJdC6LBzt0jQgZyshEsbRCHypo5AkdW8ZDgu8j0BYpPoybkgWWZNtgpyGMqTij4hvA== X-Received: by 2002:a05:6402:18f6:: with SMTP id x54mr5689099edy.53.1624522772214; Thu, 24 Jun 2021 01:19:32 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id o4sm1374641edc.94.2021.06.24.01.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 01:19:31 -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 1/2] iio: temperature: tmp006: convert probe to device-managed Date: Thu, 24 Jun 2021 11:19:23 +0300 Message-Id: <20210624081924.15897-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change converts the driver to register via devm_iio_device_register(). For the tmp006_powerdown() hook, this uses a devm_add_action() hook to put the device in powerdown mode when it's unregistered. With these changes, the remove hook can be removed. The i2c_set_clientdata() call is staying around as the private data is used in the PM routines. Signed-off-by: Alexandru Ardelean --- drivers/iio/temperature/tmp006.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/iio/temperature/tmp006.c b/drivers/iio/temperature/tmp006.c index 54976c7dad92..db1ac6029c27 100644 --- a/drivers/iio/temperature/tmp006.c +++ b/drivers/iio/temperature/tmp006.c @@ -193,6 +193,17 @@ 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) +{ + return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, + data->config & ~TMP006_CONFIG_MOD_MASK); +} + +static void tmp006_powerdown_cleanup(void *data) +{ + tmp006_powerdown(data); +} + static int tmp006_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -228,23 +239,11 @@ static int tmp006_probe(struct i2c_client *client, return ret; data->config = ret; - return iio_device_register(indio_dev); -} - -static int tmp006_powerdown(struct tmp006_data *data) -{ - return i2c_smbus_write_word_swapped(data->client, TMP006_CONFIG, - data->config & ~TMP006_CONFIG_MOD_MASK); -} - -static int tmp006_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - tmp006_powerdown(iio_priv(indio_dev)); + ret = devm_add_action(&client->dev, tmp006_powerdown_cleanup, data); + if (ret < 0) + return ret; - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } #ifdef CONFIG_PM_SLEEP @@ -277,7 +276,6 @@ static struct i2c_driver tmp006_driver = { .pm = &tmp006_pm_ops, }, .probe = tmp006_probe, - .remove = tmp006_remove, .id_table = tmp006_id, }; module_i2c_driver(tmp006_driver); From patchwork Thu Jun 24 08:19:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12341501 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 CD10CC49EA5 for ; Thu, 24 Jun 2021 08:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1F0A613E8 for ; Thu, 24 Jun 2021 08:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231876AbhFXIVz (ORCPT ); Thu, 24 Jun 2021 04:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbhFXIVy (ORCPT ); Thu, 24 Jun 2021 04:21:54 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A02C061760 for ; Thu, 24 Jun 2021 01:19:34 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id ot9so7165430ejb.8 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=kbr/hLoMjn/tVhpeW57xbZQbQaDJAQ0q6AzuzesIbFbtlQOknsDMbzF+rfcHUy9cbB q2Gf/HzSkRReC2V8eaFfgobj3JzoMPNFnGvMXbwLbovSETagu3yFDArvcf6Wh37WT1Nw a4C7ugdYi9Y46xL3661UJo6TnjK49+LrGJlB7GcVZYF92ks/DZUelA2bVdvfxg0Si+fV xrMkQOL78GCWalUFsdiQl2dx3vH70OfNHCPR/iohcAPBK5p2BrldQDUbmhhJppcNN0tn dKk75A7IloiJjL7BAfCaEL7eESwjt1BcmGXQEMh2jdiGNvLoQErcP2O4Y6A8KxJQ1BcL gHyg== X-Gm-Message-State: AOAM530QeG+/UYnjH449CCsBFnzO427Je0oW1IBunzvSjY/DtBaWGh/v nLd4ZCPljRGSqJFg/JnjuCNZwWSTgcBi/2cz X-Google-Smtp-Source: ABdhPJwJKq4o32mL1BlBWOyiUQjfUFhivfrsbCK6PIDU1fNJPj1aT9XVsopVj4NxX83HFkQQXMhTvg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@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