From patchwork Mon Sep 19 08:48:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12979781 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 DCFA6C6FA96 for ; Mon, 19 Sep 2022 08:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiISIss (ORCPT ); Mon, 19 Sep 2022 04:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiISIso (ORCPT ); Mon, 19 Sep 2022 04:48:44 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 488AA222BD for ; Mon, 19 Sep 2022 01:48:42 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id z97so40207610ede.8 for ; Mon, 19 Sep 2022 01:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=YBK40qG0NEVptByWXofU5yPXJ5EcAhbzDdsSmVzZVWQ=; b=ZEXJNLE+iuZu7HMb0I1C+psMYksJDe9kUEfsowKNzgkgZ08Wg86f8VlRGuP2pS7MB6 8ZA2CZiAfgGZR3rpc3vWOP6bjIdM4a5oxmEo0QMygDYXyHZYGP1CqgZXTiypCpBF/RNy yLJrsamyiFS86DDuxfOo2AaFSR+ykwyTAbp3GW/PBbbDPRb41OzE6FbEMmmkb9ZxZcFy dYfwH0TXEcYQLmVQYxbwcwtvNoJFg7i7f8IoF5uEhzTG8+nMjcuQFajQE+Zm9BnRWQaC ykMDJD7FYsxbX+OcOdl5kACkxsO0RlwoEi8ydatUSmT56PebVkeqkw97wY8CoF+KQCud ZKnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=YBK40qG0NEVptByWXofU5yPXJ5EcAhbzDdsSmVzZVWQ=; b=qo9fo/IWrYC+4wKgWRXm9ydG8Du6RvJJH8gMsDm9pG+u1NlGjVB53mJzRUIm22PDR3 y5qmWZ1gi3zaN7VL8IVToIYfJzjJafk2IVB9to96SGRYaIfQfz0xEtf76pFSZ5IYdR36 lTTkiTQWqMlidhbvKtQXMb6Fh4+d699roVH4WrMQm5WGOt0KiYsWscdU4OzIL2t5stJ/ F7JyPrXc5ldxgJ5vtoVkOOIN5F8NZQKorjrm/s3rlf1OR87JWUnuc87I4m7hHc8lwj/D HOzrIdXs1E4DfCgZGy5fJhwylY1Nsdbwn04l6XROr1errGcwVSiSMmrSR4WFjYBvITFZ Q3VA== X-Gm-Message-State: ACrzQf0hzd8U79f7tS+evIWjYGPiGsJyqf6rb9G574E6N/z+M44Xt8aR /EOhkv4W1WnrQiBq80si808ZLK50OmNGUw== X-Google-Smtp-Source: AMsMyM5IRrrL4q34j+l47JwB06+4HxrbzD8lo23xhgl2VfiuOJxv0KxnNEUWuFLBq5OVnywjxHJ97g== X-Received: by 2002:a05:6402:5290:b0:453:5942:4ef8 with SMTP id en16-20020a056402529000b0045359424ef8mr13329409edb.180.1663577320752; Mon, 19 Sep 2022 01:48:40 -0700 (PDT) Received: from cmo-ThinkPad-T495.telenet.be (ptr-4xh0y3vyam57ypepalv.18120a2.ip6.access.telenet.be. [2a02:1810:a44c:8f00:d368:146c:ce83:b3f3]) by smtp.gmail.com with ESMTPSA id r20-20020aa7d594000000b0044e9a3690e0sm20081326edq.9.2022.09.19.01.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 01:48:40 -0700 (PDT) From: cmo@melexis.com To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Crt Mori Subject: [PATCH v5 2/3] iio: temperature: mlx90632 Read sampling frequency Date: Mon, 19 Sep 2022 10:48:17 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Crt Mori Allow users to read sensor sampling frequency to better plan the application measurement requests. Signed-off-by: Crt Mori --- drivers/iio/temperature/mlx90632.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index 68093639d0e9..c0bf385ebd6c 100644 --- a/drivers/iio/temperature/mlx90632.c +++ b/drivers/iio/temperature/mlx90632.c @@ -81,6 +81,9 @@ #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous */ #define MLX90632_EE_RR GENMASK(10, 8) /* Only Refresh Rate bits */ +#define MLX90632_REFRESH_RATE(ee_val) FIELD_GET(MLX90632_EE_RR, ee_val) + /* Extract Refresh Rate from ee register */ +#define MLX90632_REFRESH_RATE_STATUS(refresh_rate) (refresh_rate << 8) /* Measurement types */ #define MLX90632_MTYP_MEDICAL 0 @@ -914,6 +917,32 @@ static int mlx90632_calc_ambient_dsp105(struct mlx90632_data *data, int *val) return ret; } +static int mlx90632_get_refresh_rate(struct mlx90632_data *data, + int *refresh_rate) +{ + unsigned int meas1; + int ret; + + ret = regmap_read(data->regmap, MLX90632_EE_MEDICAL_MEAS1, &meas1); + if (ret < 0) + return ret; + + *refresh_rate = MLX90632_REFRESH_RATE(meas1); + + return ret; +} + +static const int mlx90632_freqs[][2] = { + {0, 500000}, + {1, 0}, + {2, 0}, + {4, 0}, + {8, 0}, + {16, 0}, + {32, 0}, + {64, 0} +}; + /** * mlx90632_pm_interraction_wakeup() - Measure time between user interactions to change powermode * @data: pointer to mlx90632_data object containing interaction_ts information @@ -992,6 +1021,15 @@ static int mlx90632_read_raw(struct iio_dev *indio_dev, *val = data->object_ambient_temperature; ret = IIO_VAL_INT; break; + case IIO_CHAN_INFO_SAMP_FREQ: + ret = mlx90632_get_refresh_rate(data, &cr); + if (ret < 0) + goto mlx90632_read_raw_pm; + + *val = mlx90632_freqs[cr][0]; + *val2 = mlx90632_freqs[cr][1]; + ret = IIO_VAL_INT_PLUS_MICRO; + break; default: ret = -EINVAL; break; @@ -1025,12 +1063,30 @@ static int mlx90632_write_raw(struct iio_dev *indio_dev, } } +static int mlx90632_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + *vals = (int *)mlx90632_freqs; + *type = IIO_VAL_INT_PLUS_MICRO; + *length = 2 * ARRAY_SIZE(mlx90632_freqs); + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static const struct iio_chan_spec mlx90632_channels[] = { { .type = IIO_TEMP, .modified = 1, .channel2 = IIO_MOD_TEMP_AMBIENT, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), }, { .type = IIO_TEMP, @@ -1038,12 +1094,15 @@ static const struct iio_chan_spec mlx90632_channels[] = { .channel2 = IIO_MOD_TEMP_OBJECT, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | BIT(IIO_CHAN_INFO_CALIBAMBIENT), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), }, }; static const struct iio_info mlx90632_info = { .read_raw = mlx90632_read_raw, .write_raw = mlx90632_write_raw, + .read_avail = mlx90632_read_avail, }; static void mlx90632_sleep(void *_data)