Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2264252rwb; Sun, 4 Sep 2022 11:55:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR45mnEOA9ySIkNlcR9n0b0x72YjwZGunKiFOI9JCtJZPoO5Wptc1q6wi9pmoiCJAL6kthwC X-Received: by 2002:a17:906:5a64:b0:741:3586:92f with SMTP id my36-20020a1709065a6400b007413586092fmr29438848ejc.721.1662317757258; Sun, 04 Sep 2022 11:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662317757; cv=none; d=google.com; s=arc-20160816; b=ZVYNaF8dCk8AGxJhi0i1NhFklXjtTZfAaC1yV2EbOw8YBsyKDs/ubLPyGN1GgvhAhr KwbkhwSBsG7ekrZb8Owwzw9znNutGym71AroNRN/Z8wJ1EAblzsOZR9adrZLZpcjwkiB iNkngD7tiCNu9DyGRp9KTUo/3M6AobB++44Qztby+ZuaZKpOqBU4HP0/gq9Zcmi5rJoJ 5rHrdoBC0xULqvGMFKXoGxcQlQo8h/jWGUtjIT49XTGjQtWCG9vY69xqSi7B+VJIQYaz 5GOIU8fz+9X0uBS8K/bFy1LqqZ0Lo2BuXWR0MFV4JqIIZ35vjZ0qFbZS+zkyItqCfIgr hYYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0TgZHVAn4iezAvl4lBn4FpyHBWl3q5wLeQodTUP0R3g=; b=YS091T77XJa7DijH560ZGpSovUciAfW5fnU0TN3uFKNLQrBPox1LaXj8UJ2a+I/bvJ mVmN3qfJk9BdmujCooaUVLuLpQX+8gY33rRzPJnkvc+pY1RjpjP1mUbRlf5ygvGRguwG qYJ+mfiKkepVavneELrnCpQz/QorncafgtxUS3+olp+Otc6kM5u99ftFqRFco1NWtkVt bk8AasI7Ly791H8h9Wat6e4HQJYx2UyKVinZil0HSSqzPOsed5wWpsOgkWwbxpBYAjyX dggWcMD6ExsOC+on+++sr3DHZi/lZdp/MQUS9Xf+OLE7U9XKjrf61KXBYOOJ57SocJKn daiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lgP6qDFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz18-20020a0564021d5200b00445d0be02e7si7353428edb.624.2022.09.04.11.55.32; Sun, 04 Sep 2022 11:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lgP6qDFG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234774AbiIDQch (ORCPT + 99 others); Sun, 4 Sep 2022 12:32:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234471AbiIDQcg (ORCPT ); Sun, 4 Sep 2022 12:32:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8268D2B180; Sun, 4 Sep 2022 09:32:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 098DCB80DE5; Sun, 4 Sep 2022 16:32:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 966A1C433C1; Sun, 4 Sep 2022 16:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662309150; bh=qOSzJTtCHxekCVjBkN3zvmjWsUzhEiORw2JNMaYtyDs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lgP6qDFGd6NUvheEsaySSFPWwq8TtNOxRyvZMXy5RhJK29jzf1Ky8X5HhakRBAfeM 1hmpSS7hfo7UaJZA4E6QaGDY38O+6tVv+H6ZGVkEJ0k3/d6NXUXlDBDL4ZD0ljFGxO bleYxYiOf7mE8cqcHbHiTiRnpe79yJmoz0xJm5kXb3jp3puVZiECbIMSrcRLE0K1Kd hzYvqwqOzGrUc96L2j+znhK5mYrSbnadCMNvaEGT6WdDZ05fvFzrHODNeY0CGAs+zl /D80sDMBhpY117SJp95mpqjS06ocP+8mXDqTO+afw4lpVRPOPnA4YTPOFeQNhnOO5E qbj17lU5a0dUg== Date: Sun, 4 Sep 2022 16:58:23 +0100 From: Jonathan Cameron To: Crt Mori Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: Re: [PATCH v2 2/3] iio: temperature: mlx90632 Read sampling frequency Message-ID: <20220904165823.4388b699@jic23-huawei> In-Reply-To: References: <20220903222402.3426058-1-cmo@melexis.com> <20220904154535.0bb526bc@jic23-huawei> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 4 Sep 2022 17:23:16 +0200 Crt Mori wrote: > On Sun, 4 Sept 2022 at 17:19, Jonathan Cameron wrote: > > > > On Sun, 4 Sep 2022 00:24:02 +0200 > > cmo@melexis.com wrote: > > > > > From: Crt Mori > > > > > > Allow users to read sensor sampling frequency to better plan the > > > application measurement requests. > > > > I didn't read this closely enough. Why is the frequency read only? > > We'd not normally have an available attribute in that case, because > > the values aren't available if we have no way to set the value. > > > > It is writable, but so far I did not want to include the change part, > because it is writing to EEPROM and that means sensor slowly gets > killed as memory has limited number of write cycles. Ah. One of those. Please add some comments to make that clear + I think the available part should wait for any patch that adds support for writing. We may want to gate that write in some fashion - perhaps with some non standard ABI so normal code can't do it. Jonathan > > > Jonathan > > > > > > > > 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) > >