Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp859213rdd; Wed, 10 Jan 2024 01:24:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrXmIdODeU59oG409MjMezYBenyGm9uA0zltTFw+TDMgi4HXXippNPXeAdfj0d9EmLWVEC X-Received: by 2002:a05:620a:bcb:b0:783:250d:4080 with SMTP id s11-20020a05620a0bcb00b00783250d4080mr932598qki.124.1704878651359; Wed, 10 Jan 2024 01:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704878651; cv=none; d=google.com; s=arc-20160816; b=ga+1HlB4odGFU73R9QrfiKAUHdzFCq8XStYYyFjNnHrKwFeS1j331GvNEJrDdlJ1bD 6sofDzaP6oO1wPM1kM+SDZqTVzWjCSMUNFyFs7zVQLPwxxOcjlXLYO8xYp5JP+NUOasi 4u0ZAQrAx6fSGJWhoY4S2NA0m8+QuuSPVSS5yQ7nW03YYjMLo6efgEpe9mrtSPaCehqR wu0fQ2Ox8STTm27ug+NQW8PktN9306MVIIzr0VCeY/DxBUPFdOuJtfP2vh53D6LaZgxG G045QQXgyV+QB2qZi2gpKRouwXZrsjvfO2bGJJmQtTXEE3gS/wm/r40XgHPxdRQDiHI0 lFuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=UOoAIX4WuvbDoRpMpT7h+52oh340yV6Ji32YRVUO11I=; fh=lr4rA16r0dB3h1F8XiFPG8JOErjVYmxvmw/2+VBby2E=; b=ZNtwMH/5psfbkU22Knw+eYDWhTkJxEfkGAe6tqly78GfxYSqG+eGc1y5rEkP7DRlva +vNyv160J+Rz1BP2ffr23Uwzxp/PTdd7YFAHLrux7bkUhmLJJ5uBDpmV7uyuY7ackT+I A3F/y7+18lJgwr1MaUCU6csNhaQPdrO7BE1LH8YOSLu87maJ4sfee2ok90jWOUycWpM6 FwrR5YP7YxNCNkBzGbG+vdVd5bHECwx7Xvl+n4EB6zIZol6lPpqXufIPAWEFtbKRYLxe cwC2mN5CO9flLQqqSZl9mH8YFKoduuPEYdA2BA8HJugP8MZRWCirRQQu0CjbBkKPB9oH nu5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-21898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s7-20020ae9f707000000b00781bae109e3si3595915qkg.44.2024.01.10.01.24.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 01:24:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-21898-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 235BB1C23FB1 for ; Wed, 10 Jan 2024 09:24:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2508C3DBB9; Wed, 10 Jan 2024 09:24:05 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49B12210B; Wed, 10 Jan 2024 09:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4T92Nh0wG2z6K8yL; Wed, 10 Jan 2024 17:21:24 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id BED65140DEC; Wed, 10 Jan 2024 17:23:44 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 10 Jan 2024 09:23:41 +0000 Date: Wed, 10 Jan 2024 09:23:40 +0000 From: Jonathan Cameron To: =?ISO-8859-1?Q?M=E5rten?= Lindahl CC: Jonathan Cameron , Lars-Peter Clausen , , , Subject: Re: [PATCH] iio: light: vcnl4000: Set ps high definition for 4040/4200 Message-ID: <20240110092340.00003540@Huawei.com> In-Reply-To: <58319706-dbc5-4ee9-b894-cecbbd23fc1b@axis.com> References: <20231221-vcnl4000-ps-hd-v1-1-a024bfb28896@axis.com> <20231226161934.52c8d801@jic23-huawei> <58319706-dbc5-4ee9-b894-cecbbd23fc1b@axis.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) On Tue, 9 Jan 2024 19:25:25 +0100 M=E5rten Lindahl wrote: > On 12/26/23 17:19, Jonathan Cameron wrote: > > On Thu, 21 Dec 2023 17:33:09 +0100 > > M=E5rten Lindahl wrote: > > =20 > >> The vcnl4040/vcnl4200 proximity sensor defaults to 12 bit data > >> resolution, but the chip also supports 16 bit data resolution, which is > >> called proximity high definition (PS_HD). > >> > >> Make the vcnl4040/vcnl4200 proximity sensor use the high definition for > >> all data readings. > >> > >> Signed-off-by: M=E5rten Lindahl =20 > Hi Jonathan! > > Hmm. Was about to apply this and had a nasty thought. Whilst proximity= isn't > > 'scaled' as such because there is no absolute scale applied, I assume t= his change > > divides the effective scale (so what someone may be applying in userspa= ce) by 16? > > > > So this might cause someone a visible userspace regression? > > > > If so we may have to report it IIO_VAL_FRACTIONAL with the bottom set t= o 16 > > so we end up with a suitable fixed point value from sysfs. > > > > Jonathan =20 >=20 > Yes, your assumption is correct. And I found that this can easily pass=20 > unnoticed, at least on our HW. To get full 16 bit data width the sensor=20 > needs higher proximity integration time, current, and sample rate, or=20 > else it will give a raw output very close to the 12 bit steps with a=20 > maximum around 4150 compared to 12 bit max 4095. With our HW only few=20 > would notice the difference. >=20 > Increasing integration time/current/sample rate is already supported=20 > from sysfs, and to get the proper scaling I can use the=20 > IIO_VAL_FRACTIONAL as you suggest, but then I also need to set these=20 > higher values from the beginning (where PS_HD is set) or else sysfs=20 > in_proximity_raw will give output "259.375000000" for 4150, instead of=20 > "4095.937500000" for 65535. If not, userspace will have to change the=20 > values manually before first read can be done. Ok. Then I think we are fine. >=20 > Regarding the changed output format, is it ok to change it from "4095"=20 > to "4095.937500000", without making users upset? Should be fine. Generic userspace code already has to deal with fixed point values (treating them as if they were fp) as other drivers will produce this anyway. We 'might' break a flakey script, but this is in the category of hoping no one notices! Jonathan >=20 > Kind regards >=20 > M=E5rten >=20 > >> --- > >> drivers/iio/light/vcnl4000.c | 13 +++++++++++++ > >> 1 file changed, 13 insertions(+) > >> > >> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000= c > >> index fdf763a04b0b..4846f3b698b5 100644 > >> --- a/drivers/iio/light/vcnl4000.c > >> +++ b/drivers/iio/light/vcnl4000.c > >> @@ -90,6 +90,7 @@ > >> #define VCNL4040_PS_CONF1_PS_SHUTDOWN BIT(0) > >> #define VCNL4040_PS_CONF2_PS_IT GENMASK(3, 1) /* Proximity integrati= on time */ > >> #define VCNL4040_CONF1_PS_PERS GENMASK(5, 4) /* Proximity interrupt = persistence setting */ > >> +#define VCNL4040_PS_CONF2_PS_HD BIT(11) /* Proximity high definition= */ > >> #define VCNL4040_PS_CONF2_PS_INT GENMASK(9, 8) /* Proximity interrup= t mode */ > >> #define VCNL4040_PS_CONF3_MPS GENMASK(6, 5) /* Proximity multi puls= e number */ > >> #define VCNL4040_PS_MS_LED_I GENMASK(10, 8) /* Proximity current */ > >> @@ -345,6 +346,7 @@ static int vcnl4200_set_power_state(struct vcnl400= 0_data *data, bool on) > >> static int vcnl4200_init(struct vcnl4000_data *data) > >> { > >> int ret, id; > >> + u16 regval; > >> =20 > >> ret =3D i2c_smbus_read_word_data(data->client, VCNL4200_DEV_ID); > >> if (ret < 0) > >> @@ -389,6 +391,17 @@ static int vcnl4200_init(struct vcnl4000_data *da= ta) > >> mutex_init(&data->vcnl4200_al.lock); > >> mutex_init(&data->vcnl4200_ps.lock); > >> =20 > >> + /* Use 16 bits proximity sensor readings */ > >> + ret =3D i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); > >> + if (ret >=3D 0) { > >> + regval =3D (ret | VCNL4040_PS_CONF2_PS_HD); > >> + ret =3D i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, > >> + regval); > >> + } > >> + > >> + if (ret < 0) > >> + dev_info(&data->client->dev, "Default to 12 bits sensor data"); > >> + > >> ret =3D data->chip_spec->set_power_state(data, true); > >> if (ret < 0) > >> return ret; > >> > >> --- > >> base-commit: a39b6ac3781d46ba18193c9dbb2110f31e9bffe9 > >> change-id: 20231221-vcnl4000-ps-hd-863f4f8fcea7 > >> > >> Best regards, =20 >=20