From patchwork Mon Aug 8 14:49:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12938853 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 39C43C00140 for ; Mon, 8 Aug 2022 14:49:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243415AbiHHOtR (ORCPT ); Mon, 8 Aug 2022 10:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242628AbiHHOtQ (ORCPT ); Mon, 8 Aug 2022 10:49:16 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E5ABC23 for ; Mon, 8 Aug 2022 07:49:15 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id gk3so17008414ejb.8 for ; Mon, 08 Aug 2022 07:49:15 -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=qoTGqM7Fzap1A/3mR7Zh11Jo7hDAayrC6RTU0ql5RN4=; b=DHMZabs8QgxBl0q+9zRPaWwjdlgFXmleWRrBj22XEMTYhgBQt8t5TkHiFR9KQTmoQc TJoRVKxbyaV9Ysiztpis7uaWPkA5EhT6aKpiRL7Td8a0n1H5zBBOni9XE7hpRXOOGSbP m6geRtIxszqDJ3T4A5rKW7jWTaX1g4J0QfUBXoj8JbYgUwloWlE809FrMRbvxIPof9DG V4XYH8IKeWYeLNWv3RdYC8jhLWtXGnaXoX5ffe9bpnwMN3+jpkrBJMIfUMhjQK7Ad+Sr Td64LNcojF95pT5LHk96eBdu4PKh5DIGLkySmlMBv7jLGapxZd09fSE/IMqtTtqLOJ1X k/AA== 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=qoTGqM7Fzap1A/3mR7Zh11Jo7hDAayrC6RTU0ql5RN4=; b=dEL9AxgowMkXCPe11/VXu5w1VgaBglYCjCA8ghzk+i/lpFTnJbPqnUVmC5H1DgK3CL 5dkUUpybilvmMkQDN2yAg+FHhKVkcqwqe0AsVnxGruolOOCJb5bErzTXhdNaFpoVi8lW qZvRQnar2K4lhEumufOURI+imwhE4QE2z9Fr5ODsVlsdMODx6WqTJ/G1J+LkhJskIifd VxzNu6mDyrOrNtoxZE00KgL9vKK+SYQlbW73JR0u8qnVX+jA74A3U2UTUAXn54hossqs pTuJDGAIf4L2NMd7d7xJtVPuORrrc9SskBxFfLjTaRVjoLnPqgjKiqUwEa+jdDljfb37 qOfw== X-Gm-Message-State: ACgBeo3AxFG7Wl17vlr1RHIVFQMY3uaeS5zxJ0QHCO7AzURFqtSrJ0vw gu6TMFkveaYZpl+gDUoEjfcAog== X-Google-Smtp-Source: AA6agR5JOUkVEaichO/xCqDpFq7SeuFckBUQQDRZcnn19jUDoNREZHvW6UBv9udRYwrEoX9pYxAzaQ== X-Received: by 2002:a17:907:3e91:b0:730:ba28:28d2 with SMTP id hs17-20020a1709073e9100b00730ba2828d2mr14514177ejc.10.1659970153573; Mon, 08 Aug 2022 07:49:13 -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 dm13-20020a05640222cd00b0043cb1a83c9fsm4731350edb.71.2022.08.08.07.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 07:49:13 -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 v3 1/2] iio: temperature: mlx90632 Add supply regulator to sensor Date: Mon, 8 Aug 2022 16:49:08 +0200 Message-Id: <20220808144908.1559069-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 | 61 +++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index 7ee7ff8047a4..549c0ab5c2be 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,23 @@ 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 14:49:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12938854 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 2FFDFC25B0C for ; Mon, 8 Aug 2022 14:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238015AbiHHOt4 (ORCPT ); Mon, 8 Aug 2022 10:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242796AbiHHOtp (ORCPT ); Mon, 8 Aug 2022 10:49:45 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B74513CF8 for ; Mon, 8 Aug 2022 07:49:44 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id b96so11731166edf.0 for ; Mon, 08 Aug 2022 07:49:44 -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=S2IGJCwZMVPowoihlFkTDxVmPB6bfb6v8CYSoKyiiDobysypIl1hXJ9bnCssCL7z6R hnCLVOMqoH3AAs1oNY9l7RCa47YrxS3zAqqiE++NncryABegZsFqN1iUrFpCQsfphRNi lv6LOVXsh8rVqG9+wcm//7YhGKCWSktdVPiLOAbxre9yKwYKWOTcy/Wbhkgp66T1rTSm kjepb6B9q8m4XlmzDvfET9FOpqjYeuW+vjjXGsswHD4W7j8UwMo/TXiFWzZ34bT0f0bL 8hZiXh5WDUZwJeniF0zGkjE1VyWAUXc59d5QxnpmBmHXFCrbuud3ke/fBFwgXQDLDzVw 7njQ== 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=xONh2fhX3KNNA3uIwIo4gtchbTYbNISnhfOw/dC2fLMj5zwqq6Y0Kv4RuntlOhX8U3 Pz1g0M/ctAGiXmBm1FNOZU9lXq0ApvIiZs9wzak4AJEy04OeiO0UmmWGxddMxkhzDhFX gdHqKmlNmGzbeemTYMPG0RFIdfk2aCcZVsqDaMUOGlWxl8ozpxo8qb/iOkOTmViL9Vz0 v+kMFfi+B4KupsDOpsraf/nUafV5wqgvL/8QhZ8H+0BnCJtuIMGcH75oAh60MtgJRTCI GzOd0nFudvQZpO6xNDFnanLGRRyOBUBiwK5nbE2osiaYW4iX3VUJ0nUYmgxN40l3V9O3 +ZKw== X-Gm-Message-State: ACgBeo1JTtQyoHb9LBhWJAT2PGaKHzpCg7jtnVNUlhqLyNVDmHhr0D5O 19PSO7D7lgyXcq0iModlthJGyCSZptd3/Q== X-Google-Smtp-Source: AA6agR4PPC/LIGsLNQk3+R+crCvb6P9SQUPULlkbuwDaegHTPO7e9Yd9cgP5Gw8qaQpkuiuHyVWarw== X-Received: by 2002:a05:6402:24a4:b0:440:8c0c:8d2b with SMTP id q36-20020a05640224a400b004408c0c8d2bmr6479287eda.311.1659970183080; Mon, 08 Aug 2022 07:49:43 -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 q4-20020a17090676c400b00722fc0779e3sm5056276ejn.85.2022.08.08.07.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 07:49:42 -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 v3 2/2] dt-bindings: iio: mlx90632 Add supply regulator documentation Date: Mon, 8 Aug 2022 16:49:36 +0200 Message-Id: <20220808144936.1559158-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>; }; }; ...