From patchwork Mon Aug 8 12:05:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12938736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 989B6C25B0C for ; Mon, 8 Aug 2022 12:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242251AbiHHMFb (ORCPT ); Mon, 8 Aug 2022 08:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242080AbiHHMF3 (ORCPT ); Mon, 8 Aug 2022 08:05:29 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48A271F9 for ; Mon, 8 Aug 2022 05:05:26 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id ay12so1854356wmb.1 for ; Mon, 08 Aug 2022 05:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4za0UHhtOzS/+cksvATUbwHsHuuZed1iD70qbguxMDM=; b=PneoR3vZf4ScDSFvZfyJdeVBNlyzN26XM/BWbF45+Dt4vng2UlSUEy4+eQ6dfnfKV6 NvSRf9qrd54r1jIWyCaXKiVI0Wo6rKEKICRvmi6x2aZUwrzrSnmB9yg8hp9FU7BtsK7F jhGy373jJqTg7hMxwEo0OswEzZ51eGqGAevPd7KyEpCHexrwah7BRWBXc33wsNkldZyp aPAqBlwC4MUoZha/MzfQ0e2nO7WLKUpoKzQ+3+1fIFTbHeFPQ8OOaQXDzqd3SqrSxsJ9 7URY0jLN6qoYXhBpXrs/DSzbAzDp/CAoAlYro74/CTWcNgQQLlLen1/hNRTYA5oLZp7+ oT4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4za0UHhtOzS/+cksvATUbwHsHuuZed1iD70qbguxMDM=; b=7wI5NVlFQ2oKDICZnlPznrzkjuRI7hHJPGzAffWVRDi4EdjNdLNai5AxMmIQCkEQvg TLTeGj1Yb/BBl7IJPTwaA0aAmC7Jc7SToCxPfkTJhAZq1baMiN3QUO4J/bVMeZznQQpN nD8tX6DQjB5oK2IshECe9Ums168FSLhrem+ljks2KG54N/bFtPZXRzM3zPDN6yat7yVb EzFonZQkBbkVXvWWbiH0T+bPhTeYqJ+EgAEjG9kZbcFJc/8dzlitgamoQd3T59tC7d2v oU9fYYI5MiNB9dEgPicGo84nzd6veVB6rsef4aIxbjRJHuhO9XOVVVcOhazQbfDh6Pyq LJ3g== X-Gm-Message-State: ACgBeo2q+iHFnhWa4U6uklWGTRK2sPzrQCmZgyObb3XBjfGkUKcfLjV8 ZeOD7Hsxfy8JS5sKZG5N3H6Qvg== X-Google-Smtp-Source: AA6agR5BLOyhCxqNHO8QEcjCixT3fG1P9ls+0kC02DYZHRzSOE9hOQbr6tEKLPufPeGYNsI47YRRjg== X-Received: by 2002:a05:600c:5118:b0:3a5:37bf:6c21 with SMTP id o24-20020a05600c511800b003a537bf6c21mr4701418wms.135.1659960324712; Mon, 08 Aug 2022 05:05:24 -0700 (PDT) Received: from localhost.localdomain (ptr-4xh0y3vuv1059rd6h4r.18120a2.ip6.access.telenet.be. [2a02:1810:a44c:8f00:cd22:c517:e143:e53b]) by smtp.gmail.com with ESMTPSA id d1-20020a5d6441000000b0021eb309c97dsm11087303wrw.25.2022.08.08.05.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 05:05:24 -0700 (PDT) From: Crt Mori To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Lars-Peter Clausen , Crt Mori Subject: [PATCH v2 1/2] iio: temperature: mlx90632 Add supply regulator to sensor Date: Mon, 8 Aug 2022 14:05:18 +0200 Message-Id: <20220808120518.1543260-1-cmo@melexis.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Provide possibility to toggle power supply to the sensor so that user can optimize their setup and not have the sensor constantly powered. Signed-off-by: Crt Mori --- drivers/iio/temperature/mlx90632.c | 63 +++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index 7ee7ff8047a4..238d639df385 100644 --- a/drivers/iio/temperature/mlx90632.c +++ b/drivers/iio/temperature/mlx90632.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,7 @@ * calculations * @object_ambient_temperature: Ambient temperature at object (might differ of * the ambient temperature of sensor. + * @regulator: Regulator of the device */ struct mlx90632_data { struct i2c_client *client; @@ -136,6 +138,7 @@ struct mlx90632_data { u16 emissivity; u8 mtyp; u32 object_ambient_temperature; + struct regulator *regulator; }; static const struct regmap_range mlx90632_volatile_reg_range[] = { @@ -207,6 +210,15 @@ static s32 mlx90632_pwr_continuous(struct regmap *regmap) MLX90632_PWR_STATUS_CONTINUOUS); } +/** + * mlx90632_reset_delay() - Give the mlx90632 some time to reset properly + * If this is not done, the following I2C command(s) will not be accepted. + */ +static void mlx90632_reset_delay(void) +{ + usleep_range(150, 200); +} + /** * mlx90632_perform_measurement() - Trigger and retrieve current measurement cycle * @data: pointer to mlx90632_data object containing regmap information @@ -248,11 +260,7 @@ static int mlx90632_set_meas_type(struct regmap *regmap, u8 type) if (ret < 0) return ret; - /* - * Give the mlx90632 some time to reset properly before sending a new I2C command - * if this is not done, the following I2C command(s) will not be accepted. - */ - usleep_range(150, 200); + mlx90632_reset_delay(); ret = regmap_write_bits(regmap, MLX90632_REG_CONTROL, (MLX90632_CFG_MTYP_MASK | MLX90632_CFG_PWR_MASK), @@ -841,6 +849,32 @@ static int mlx90632_wakeup(struct mlx90632_data *data) return mlx90632_pwr_continuous(data->regmap); } +static void mlx90632_disable_regulator(void *_data) +{ + struct mlx90632_data *data = _data; + int ret; + + ret = regulator_disable(data->regulator); + if (ret < 0) + dev_err(regmap_get_device(data->regmap), + "Failed to disable power regulator: %d\n", ret); +} + +static int mlx90632_enable_regulator(struct mlx90632_data *data) +{ + int ret; + + ret = regulator_enable(data->regulator); + if (ret < 0) { + dev_err(regmap_get_device(data->regmap), "Failed to enable power regulator!\n"); + return ret; + } + + mlx90632_reset_delay(); + + return ret; +} + static int mlx90632_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -876,6 +910,25 @@ static int mlx90632_probe(struct i2c_client *client, indio_dev->channels = mlx90632_channels; indio_dev->num_channels = ARRAY_SIZE(mlx90632_channels); + mlx90632->regulator = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(mlx90632->regulator)) + return dev_err_probe(&client->dev, + PTR_ERR(mlx90632->regulator), + "failed to get vdd regulator"); + + ret = mlx90632_enable_regulator(mlx90632); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&client->dev, + mlx90632_disable_regulator, + mlx90632); + if (ret < 0) { + dev_err(&client->dev, "Failed to setup regulator cleanup action %d\n", + ret); + return ret; + } + ret = mlx90632_wakeup(mlx90632); if (ret < 0) { dev_err(&client->dev, "Wakeup failed: %d\n", ret); From patchwork Mon Aug 8 12:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12938737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1068C25B07 for ; Mon, 8 Aug 2022 12:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233230AbiHHMGJ (ORCPT ); Mon, 8 Aug 2022 08:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242542AbiHHMGH (ORCPT ); Mon, 8 Aug 2022 08:06:07 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F3F5F64 for ; Mon, 8 Aug 2022 05:05:55 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id ay36-20020a05600c1e2400b003a4e30d7995so7308908wmb.5 for ; Mon, 08 Aug 2022 05:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yv7/Ul3NtrsgwZNY2tz3vPTVziFu5q3/IA4UlHUJklg=; b=dpXdQWxuBRSCqpfom0NwcrxvY0fURdxtGYuWn0dDyqb/eueUQAGz0+a/jmpILk8Wv6 p5CLIGaNGPaXx4US9/Mrp/sQqq4xH9Gqylc0FxO9NmSbnjqerwbPHgs7f3bEFsUgaEYP cS9ZoFeyH+YfGRj6QZMRLNw2aauv/Txu7WxfgVCoLwywZxGLx2M5FJE0x8CGLqHfdmdJ swNWUuceoBsNCj+p6ukU/si7CcmL0QQGAclsWuvYTk+sK0USnxN+nYcZ9CdFC6chGAu2 nsDiy0hSalEN84gtIAMNmHny/CQaStNZVqXP+7nFksTR3/E7oI/R59EabeEhddYo+tde IW6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yv7/Ul3NtrsgwZNY2tz3vPTVziFu5q3/IA4UlHUJklg=; b=Axth/j6laMymeul0ct/PuDuCBCG2x1WQt2WaF4gQFvd7BLYL76cYfZX9D2DJVzFUOf EvN9t0Ajm/Jog+4QiMNEcjF53Yc+6nj5Ml38D64kdnvDDEUu+0JzRiQzsBl9FB8Rbb4Z MoQ6pMrso4vNCzMv+9G7NsoptcQPewR1J411icLN7YMveUtJ/50Gjw/lC1zLhhAFOSAZ REDWIqejS0WMRG/ZyRZ7NNmDocl67HUe/CpPT9asfRAzxzV0Ugv5Xh/FTJmO+Ksn8YUx /E9ilutHb14plhB2Ij1Pyx1ckHOrQJomHJOcMOtoIr4/na6KzfHaQtQ3QE9iJMsd5/yj rtwg== X-Gm-Message-State: ACgBeo3xN9nlMYjPB7fQapTJgarKX0QTxhTSiLAyv0PwZyTwXU5yTaHy /K/guF8aOZLh7ihAFcmagIDsnw== X-Google-Smtp-Source: AA6agR5McIiXqc3Z1dpu34Hdqbz9S9Td7lasSrfwR0gSLIBEoMFiIuqtX0Fk/2RcmdewAPxkE2rXHg== X-Received: by 2002:a05:600c:5123:b0:3a3:2543:be80 with SMTP id o35-20020a05600c512300b003a32543be80mr17215693wms.155.1659960353944; Mon, 08 Aug 2022 05:05:53 -0700 (PDT) Received: from localhost.localdomain (ptr-4xh0y3vuv1059rd6h4r.18120a2.ip6.access.telenet.be. [2a02:1810:a44c:8f00:cd22:c517:e143:e53b]) by smtp.gmail.com with ESMTPSA id n66-20020a1ca445000000b003a513ee7830sm15884560wme.27.2022.08.08.05.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 05:05:53 -0700 (PDT) From: Crt Mori To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Lars-Peter Clausen , Crt Mori , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, Krzysztof Kozlowski Subject: [PATCH v2 2/2] dt-bindings: iio: mlx90632 Add supply regulator documentation Date: Mon, 8 Aug 2022 14:05:49 +0200 Message-Id: <20220808120549.1543338-1-cmo@melexis.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Document the newly added vdd supply option. Signed-off-by: Crt Mori Acked-by: Krzysztof Kozlowski --- .../devicetree/bindings/iio/temperature/melexis,mlx90632.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90632.yaml b/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90632.yaml index b547ddcd544a..4a55e7f25ae7 100644 --- a/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90632.yaml +++ b/Documentation/devicetree/bindings/iio/temperature/melexis,mlx90632.yaml @@ -35,6 +35,9 @@ properties: maxItems: 1 description: Default is 0x3a, but can be reprogrammed. + vdd-supply: + description: provide VDD power to the sensor. + required: - compatible - reg @@ -50,6 +53,7 @@ examples: temp-sensor@3a { compatible = "melexis,mlx90632"; reg = <0x3a>; + vdd-supply = <&ldo4_reg>; }; }; ...