From patchwork Sat Sep 3 22:24:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crt Mori X-Patchwork-Id: 12965066 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 61910C6FA83 for ; Sat, 3 Sep 2022 22:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiICWYK (ORCPT ); Sat, 3 Sep 2022 18:24:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbiICWYI (ORCPT ); Sat, 3 Sep 2022 18:24:08 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6525C5073F for ; Sat, 3 Sep 2022 15:24:07 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id z8so7042057edb.6 for ; Sat, 03 Sep 2022 15:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=e0q/1eeKpn8xnk0xY6Lu5gTCh4C5ZfPCKIfvqPEAtIo=; b=qWgTU6GIPW2B0/TGVGZrSXEjIh7Qq6QBLdk0Kn9kSeSKCU9ixbLEUGkSAQv7TF/zK0 CG0HqVSZJwgy1jIiY5ZADT5xPNOmZQJRXqGR8z0s1ceKG2LYO1MKLql9PRtuV6Kk2lNk hAwm1qAXbp9I0gBBdGZ81g7WpDAUpOQnqr+62St4Jcba2SoENhXcva68vKO1mcaFiAyB segSskKBOp7dgtGUq9O/oyS3/zK4JnL/hfVeCTMYCP5WKRzdgNPmfmUgWviMKCk+08tV x2s+SGNjDmx5+XlaSHYsq7IUCbO414dz5OSi18osuB0ywL7qfdK4gWPmol10jGI+efmY yYoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=e0q/1eeKpn8xnk0xY6Lu5gTCh4C5ZfPCKIfvqPEAtIo=; b=zOEeeYZVFAX7vKgax/3on0ZCdF4hUcMU9BKgm5ZvFpVG+abT4ux+pKZ7c8g+5HdZGn KTCkavBHAVdth8r5GlrIII0RU12NKef6xkp3UMwWonX3EHXscR5cBb6C5y2gcPsMlbZC OpaeKFke6ST00edUf87lASWn+l4rDPtoBzX1CL8CYee4AlvGgrWv5NH+VpAn5SarehgL OV/bZ4O9OfrlLAWgNt8j5J/sOdluRzeXQL5B9op1KZtngPUFXSSmv6Nf2cZqYseChCCy IiJyYht4tmVRv2Ou4xTMQslYVrIBP6Rn2fYcNpo+ik4NfCpECZaZKnm025U2joIY2G4F e52g== X-Gm-Message-State: ACgBeo3vQ2ebZ479uJXQ/CnmsXghB4W98MoKm/BV1FevCfvEQsbyb1Do vDJmCENJG/W4iu3fG+nMSydbzQ== X-Google-Smtp-Source: AA6agR6AvSRrqhXCwxCgR6q5NENiDCorzE8cpRoc/TFlRD//SVuBbassZ46Nr2NamAHj/SdnYTGVuA== X-Received: by 2002:a05:6402:5285:b0:44d:adf4:e943 with SMTP id en5-20020a056402528500b0044dadf4e943mr2503119edb.302.1662243845926; Sat, 03 Sep 2022 15:24:05 -0700 (PDT) Received: from cmo-ThinkPad-T495.telenet.be (ptr-4xh0y3sxu2v33e81l49.18120a2.ip6.access.telenet.be. [2a02:1810:a44c:8f00:d4a:f526:3662:1129]) by smtp.gmail.com with ESMTPSA id cz19-20020a0564021cb300b0044780b6debasm3891098edb.32.2022.09.03.15.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Sep 2022 15:24:05 -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 v2 2/3] iio: temperature: mlx90632 Read sampling frequency Date: Sun, 4 Sep 2022 00:24:02 +0200 Message-Id: <20220903222402.3426058-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 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 | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index 9acd819c76a6..37edd324d6a1 100644 --- a/drivers/iio/temperature/mlx90632.c +++ b/drivers/iio/temperature/mlx90632.c @@ -80,6 +80,9 @@ #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous */ #define MLX90632_EE_RR(ee_val) (ee_val & GENMASK(10, 8)) /* Only Refresh Rate bits */ +#define MLX90632_REFRESH_RATE(ee_val) (MLX90632_EE_RR(ee_val) >> 8) + /* Extract Refresh Rate from ee register */ +#define MLX90632_REFRESH_RATE_STATUS(refresh_rate) (refresh_rate << 8) /* Measurement types */ #define MLX90632_MTYP_MEDICAL 0 @@ -908,6 +911,24 @@ 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} }; + static int mlx90632_pm_interraction_wakeup(struct mlx90632_data *data) { unsigned long now; @@ -978,6 +999,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; @@ -1012,12 +1042,24 @@ static int mlx90632_write_raw(struct iio_dev *indio_dev, } } +static IIO_CONST_ATTR(sampling_frequency_available, "0.5 1 2 4 8 16 32 64"); + +static struct attribute *mlx90632_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group mlx90632_attribute_group = { + .attrs = mlx90632_attributes, +}; + 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), }, { .type = IIO_TEMP, @@ -1025,12 +1067,14 @@ 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), }, }; static const struct iio_info mlx90632_info = { .read_raw = mlx90632_read_raw, .write_raw = mlx90632_write_raw, + .attrs = &mlx90632_attribute_group, }; static int mlx90632_sleep(struct mlx90632_data *data)