From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5577392C27 for ; Sat, 27 Jun 2026 08:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782550404; cv=none; b=GUwYWtLJ+kgyVCW9WQSuel4aLpCzIE8sVhxHWHSepQlY65vSJpOzlNk2vFPOk0l0sKXl5onAPRXnt9+pBeP2+nRFPTzvXsUb4cpFwc71vbsgls+a0yWNFs3hCkyickxxgQbuZlhHi3hgjTgzqMdOtN8jU/vy6X4K4u8hODftdYk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782550404; c=relaxed/simple; bh=hz4rsOIiH2SH7OXId2Ii1orrFzniL4MivvLJdr4ysVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=evYSiD5wlaqU62Y3bZWYD0xACfmh/O710VPaQ0o8rVywcsp7gptQk+x/dPKGQxW285NuFWCL3QsC+ObdW1q3Y3rpHuAjFYduOxl9ksTEApQdH+heGiG+PqyhwhVen7NhT07Qw1UUbEACgZEmfn7rIgap9uTM1e4xxkSeYFhW0WQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KdPkIldR; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KdPkIldR" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-30bbe98c3f0so4194342eec.0 for ; Sat, 27 Jun 2026 01:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782550402; x=1783155202; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=50ge2bDBL0/GirPAj7jZ0yk4rxCXfu6duqZ1IrPQJoM=; b=KdPkIldR1z7GQBo8s1X11Kkw33pmg3Ex03zVj9iZPtKYsd7MuMHX1uVrJyIIOkyceJ YQyIaQoLYBtRK9RbSddcEadwRw1bMFGh4LwRxbpGoc7ZFgeFRS0VLHJmH7hfizgrqGV/ LaKLg7dYLdyy0VrLVQq4SonPR0Ita5gOO+MDk/wt5jWp/SJKcw465KUu/HV+O+h6o30E jbtOVfG2dtnSuevG6bEYY6JgyEoFIOGIi9uSaK2hSnlj0AtJv2+cGRons2aY7kCLK7UI tplvTaQWzj738PD1dM8LWzZAgl5BRkGe/0OmaJKJ1nX00ev8Vog0f6khQ39xgX4+KjI7 Mxxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782550402; x=1783155202; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=50ge2bDBL0/GirPAj7jZ0yk4rxCXfu6duqZ1IrPQJoM=; b=d5FZnTnxZcGG7OQciSfRbxeUqWk4C9DcSGSvmOH2sPjlKFUJ62Awqs55h467Svhgj2 Siz8pdWOuew6M6YXY/h7uVhkY4F8iOecHAnxAAz8TBQfOPreOW4FwywJNTPzGFMv3iw1 +GLZ6KyFsdqokVctkrJX/bnyy+MjaaBtr9/iA4NMk7vxKiocaWnL7hfjXtmNinEd+/xt zaty6ZTyj9Uv2w53CcuPZNih//9UzzdIYdyrSsI3cQiPT6QmQLUh+XtvPIMtrnBRZueo UZ45aWUfvnB7nC0CJWArKbaoCCWtl7XhCREXZMRimItSVhoB4EzSdxn2hzeEBbn/zhJY ooTQ== X-Forwarded-Encrypted: i=1; AHgh+Rq3NV7SiFAT4qWtFU/f27TeaSqZolJVG9RuXeP4OWFo1SAvxeK3cRyRJObjk2LYIY1aEScC/6N6LHqPO8A=@vger.kernel.org X-Gm-Message-State: AOJu0YzIIAjD5bV9gkk2ijf3N8sXbej+9eWn2T7N1Iv32/qkMSs+cYyM cbwEAIBvhcfy6g5ZmnAV3iLk4NgBQZDKTes34Tihx1daIna5hU2dGiVj X-Gm-Gg: AfdE7cn7lrf3aohPNsvHfbjz/MO9BPZCJqTumA+KhfoHFhWckcvB4b7cFQ/3T+iLm/I 2vwNyqku491XVU3rcikYOXUXGvxPaAXPbqWnidOicPg0h2BWOLrglleUGz2vYjHHON4DEalkS5F JGnjMS8jjKseE72x/ImXZ0gkIyvX8cw0dB3OO50nLMwzGthMrkgGY74D4Es9Qdwd2dBMyp9TIEg uk8pxD/xe7SrIioOWahYlZn4hYGId46WQ38XnCw09JTPre8FhjUEgK6Qn7DdP7cNt2CE8WdGQww XCkeB91lg0rE2nCPJLK/2dxujhOR+r5Wp5mPFLGTRgk3rw+YP+YSEoXbw3FmQczwMHTe1GCKGPo Bjjg95s8K2PP8WwoFoKj9hM9UmPNWkaOgcYoE8uZ4Ux05yiBy/rxtd+0pNNMIt2XwkVX4XYGIu/ 4aa0sWxyOmTrNu3guOWJybw76jDm3llhv2tDJdYVuzlhGOkALLvEgDqlus+u6WVoxIOEkABBELi i7YnHBBXTnmmg== X-Received: by 2002:a05:7300:e828:b0:30b:f477:6619 with SMTP id 5a478bee46e88-30c84bd5d55mr8506058eec.15.1782550401701; Sat, 27 Jun 2026 01:53:21 -0700 (PDT) Received: from localhost.localdomain ([2401:4900:1c17:d4b4:8861:e0a7:292d:b4d1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c52d669sm26950479eec.11.2026.06.27.01.53.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 27 Jun 2026 01:53:21 -0700 (PDT) From: Shardul Deshpande To: Jonathan Cameron , Javier Carrasco Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Shardul Deshpande Subject: [PATCH v2] iio: light: veml6075: fix UV index reported at half value Date: Sat, 27 Jun 2026 14:23:13 +0530 Message-ID: <20260627085313.7507-1-iamsharduld@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260626110400.68885-1-iamsharduld@gmail.com> References: <20260626110400.68885-1-iamsharduld@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit veml6075_get_uvi_micro() normalises the UV index for the configured integration time. The raw UVA/UVB counts scale linearly with the integration time, so the responsivity-weighted sum must be divided by the integration-time scale factor relative to the 50 ms base case (which is returned undivided). Per the VEML6075 datasheet the UV_IT field selects the integration time as 50, 100, 200, 400 and 800 ms for field values 0..4, i.e. (50 << int_index) ms: each step doubles the integration time and hence the accumulated counts. The correct scale factor relative to the 50 ms base is therefore 2^int_index == (1 << int_index). (See also the Vishay application note "Designing the VEML6075 Into an Application" for the UV-index responsivity calculation that these constants implement.) The code instead divided by (2 << int_index) == 2^(int_index + 1), i.e. twice the correct value, so the reported UV index was half of the true value for every integration time except 50 ms. As the driver powers up with VEML6075_IT_100_MS, the UV index was reported at half value out of the box. Divide by (1 << int_index) instead. int_index is already bounded to 0..4 by veml6075_read_int_time_index(), and (1 << 0) == 1 reproduces the undivided 50 ms case, so the per-integration-time switch collapses to a single expression. Fixes: 3b82f43238ae ("iio: light: add VEML6075 UVA and UVB light sensor driver") Cc: stable@vger.kernel.org Signed-off-by: Shardul Deshpande --- Changes in v2: - Collapse the per-integration-time switch into a single divide now that all cases share the same expression -- int_index is bounded to 0..4 by veml6075_read_int_time_index() and (1 << 0) reproduces the 50 ms case. (Javier Carrasco) - Add VEML6075 datasheet (UV_IT integration-time table) and application- note references for the integration-time scaling in the changelog. Link to v1: https://lore.kernel.org/linux-iio/20260626110400.68885-1-iamsharduld@gmail.com/ drivers/iio/light/veml6075.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/iio/light/veml6075.c b/drivers/iio/light/veml6075.c index 59187244a..d0ec06eeb 100644 --- a/drivers/iio/light/veml6075.c +++ b/drivers/iio/light/veml6075.c @@ -237,17 +237,13 @@ static int veml6075_get_uvi_micro(struct veml6075_data *data, int uva_comp, if (int_index < 0) return int_index; - switch (int_index) { - case VEML6075_IT_50_MS: - return uvia_micro + uvib_micro; - case VEML6075_IT_100_MS: - case VEML6075_IT_200_MS: - case VEML6075_IT_400_MS: - case VEML6075_IT_800_MS: - return (uvia_micro + uvib_micro) / (2 << int_index); - default: - return -EINVAL; - } + /* + * The raw counts scale linearly with the integration time, which + * doubles at each step (50, 100, 200, 400, 800 ms == 50 << int_index + * ms; int_index is bounded to 0..4 above). Normalise to the 50 ms + * base by dividing by 2^int_index; (1 << 0) == 1 leaves 50 ms as-is. + */ + return (uvia_micro + uvib_micro) / (1 << int_index); } static int veml6075_read_uvi(struct veml6075_data *data, int *val, int *val2) -- 2.50.1 (Apple Git-155)