From nobody Sun Feb 8 20:52:15 2026 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 164FDC7EE23 for ; Tue, 30 May 2023 14:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbjE3O0c (ORCPT ); Tue, 30 May 2023 10:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjE3O0H (ORCPT ); Tue, 30 May 2023 10:26:07 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67D11700; Tue, 30 May 2023 07:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685456710; x=1716992710; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rzg3JmVh3kV17PxaBgNTh7dfKhzh1ljcUYtBx0u5mOs=; b=kmTg2BAYsqGKyITZP2bl7ET3NtcfiEk68CcAHkG4+iFZFxXGV3i0n0TI Cag3kF20sHmxvdzWUyxtN8SYczpiYAy41bduHCVKpQgxRQomGIv/ne2O0 6VYBmVJCvvXhhclwZhusOK9WWdzwywv/4u+4dihrJm5Ja3BCVup4swzlM ROxcd7dvWFqpxjFdqiA99muRRNfDzWaUqk1kJWLFsp5eG0clKa0KaFfP3 djxGEqE1w6GCJc+1QX1SK+IgrCxzCMUf/IAvZJ4LPwcdmsbvgAfejKY5/ lAeaPEP77NMD0t4KY252aOY1KjdfVQTcmY4GPoLOfQyeD+lJkWCmfQxec g==; From: Astrid Rost To: Jonathan Cameron , Lars-Peter Clausen CC: , , , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Mathieu Othacehe , Astrid Rost Subject: [PATCH v5 2/7] iio: light: vcnl4000: Add proximity ps_it for vcnl4200 Date: Tue, 30 May 2023 16:24:00 +0200 Message-ID: <20230530142405.1679146-3-astrid.rost@axis.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530142405.1679146-1-astrid.rost@axis.com> References: <20230530142405.1679146-1-astrid.rost@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add ps_it attributes for vcnl4200 (similar to vcnl4040). Add read/write attribute for proximity integration time. Read attribute for available proximity integration times. Change sampling rate depending on integration time. Signed-off-by: Astrid Rost --- drivers/iio/light/vcnl4000.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 565b9c9ea470..090e20229855 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -124,6 +124,15 @@ static const int vcnl4040_ps_it_times[][2] =3D { {0, 800}, }; =20 +static const int vcnl4200_ps_it_times[][2] =3D { + {0, 96}, + {0, 144}, + {0, 192}, + {0, 384}, + {0, 768}, + {0, 864}, +}; + #define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend= */ =20 enum vcnl4000_device_ids { @@ -166,6 +175,8 @@ struct vcnl4000_chip_spec { irqreturn_t (*irq_thread)(int irq, void *priv); irqreturn_t (*trig_buffer_func)(int irq, void *priv); u8 int_reg; + const int(*ps_it_times)[][2]; + const int num_ps_it_times; }; =20 static const struct i2c_device_id vcnl4000_id[] =3D { @@ -508,11 +519,11 @@ static int vcnl4040_read_ps_it(struct vcnl4000_data *= data, int *val, int *val2) =20 ret =3D FIELD_GET(VCNL4040_PS_CONF2_PS_IT, ret); =20 - if (ret >=3D ARRAY_SIZE(vcnl4040_ps_it_times)) + if (ret >=3D data->chip_spec->num_ps_it_times) return -EINVAL; =20 - *val =3D vcnl4040_ps_it_times[ret][0]; - *val2 =3D vcnl4040_ps_it_times[ret][1]; + *val =3D (*data->chip_spec->ps_it_times)[ret][0]; + *val2 =3D (*data->chip_spec->ps_it_times)[ret][1]; =20 return 0; } @@ -523,8 +534,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_dat= a *data, int val) int ret, index =3D -1; u16 regval; =20 - for (i =3D 0; i < ARRAY_SIZE(vcnl4040_ps_it_times); i++) { - if (val =3D=3D vcnl4040_ps_it_times[i][1]) { + for (i =3D 0; i < data->chip_spec->num_ps_it_times; i++) { + if (val =3D=3D (*data->chip_spec->ps_it_times)[i][1]) { index =3D i; break; } @@ -533,6 +544,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_dat= a *data, int val) if (index < 0) return -EINVAL; =20 + data->vcnl4200_ps.sampling_rate =3D ktime_set(0, val * 60 * NSEC_PER_USEC= ); + mutex_lock(&data->vcnl4000_lock); =20 ret =3D i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); @@ -620,11 +633,13 @@ static int vcnl4040_read_avail(struct iio_dev *indio_= dev, const int **vals, int *type, int *length, long mask) { + struct vcnl4000_data *data =3D iio_priv(indio_dev); + switch (mask) { case IIO_CHAN_INFO_INT_TIME: - *vals =3D (int *)vcnl4040_ps_it_times; + *vals =3D (int *)(*data->chip_spec->ps_it_times); *type =3D IIO_VAL_INT_PLUS_MICRO; - *length =3D 2 * ARRAY_SIZE(vcnl4040_ps_it_times); + *length =3D 2 * data->chip_spec->num_ps_it_times; return IIO_AVAIL_LIST; default: return -EINVAL; @@ -1317,6 +1332,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_= spec_cfg[] =3D { .info =3D &vcnl4040_info, .irq_thread =3D vcnl4040_irq_thread, .int_reg =3D VCNL4040_INT_FLAGS, + .ps_it_times =3D &vcnl4040_ps_it_times, + .num_ps_it_times =3D ARRAY_SIZE(vcnl4040_ps_it_times), }, [VCNL4200] =3D { .prod =3D "VCNL4200", @@ -1329,6 +1346,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_= spec_cfg[] =3D { .info =3D &vcnl4040_info, .irq_thread =3D vcnl4040_irq_thread, .int_reg =3D VCNL4200_INT_FLAGS, + .ps_it_times =3D &vcnl4200_ps_it_times, + .num_ps_it_times =3D ARRAY_SIZE(vcnl4200_ps_it_times), }, }; =20 --=20 2.30.2