From nobody Fri Oct 2 03:52:08 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 DE6603EAC68 for ; Wed, 5 Aug 2026 08:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785919087; cv=none; b=mDAQ7hjh7tLjxfEE4P8z/UuTf1cE9hZaSJsaUMIYNVfCVDrGkKp7K9hNFpTXGz7pppAZomGxSfAsgdX+qO1LcQYyp/GGrNEqCM/eQwjXmzDrpNru3CDyXOwbnPi+tYhXxrrmZYmgHn8fG8k1FH9FxG8w9hJE5YL7k9jDA/9e1B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785919087; c=relaxed/simple; bh=xbdXc93eVoEnHSc6HZmwLx7VOseAbmuXTYlOJgdHCsY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hVsg8cFTrvaIvVSKM8fjUPWGRB/dnTsGERtSeUeA7Oqz26uyeHAijVKN1xvy9DFA7tEzjqlKZFNkLlQCalFtpZqqBMXteS4WSwbMnL0sLFmUbAuR3xRr+1cVvsHePBDOgq5cQBmlirVRylZwe8a3Itw25uMhhcLuKNWUjXeR4fo= 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=YzgfhLjb; arc=none smtp.client-ip=209.85.221.45 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="YzgfhLjb" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4731f5ffa74so44006f8f.1 for ; Wed, 05 Aug 2026 01:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785919084; x=1786523884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Ve8270E6MOdj8YsOaSYLA5r25PubDk8jW4r4l/rs05g=; b=YzgfhLjbTO6RRXbSTLSsQO4IWHlkcsvWluvHK5iODWoNjpxGXkqvNgKjgOPunYN6RL rj4rXr4Z1pqfh6xGfGeEvafzOAkru5qTXmgK5s26hHjkgIhaLao48n25Fnpjm+ImIe6V inax94/QLiSB3UUBjiL1KCzYRDQxJWZLGEcV5SxM9xh58IsRQsIUudvPcIdgkBgOXxDW xcSruyrkNBg8SSAKX/apvDeT4duIaYtE8G/q75diueJOqIQx6yIq0ij/YO7gPgNEIK7n p9/XoOO11y8F6+Yyoiu1ReIZi+aKJmCPCMudFGhldVxC4330hbUWoyxXgo8hJ/RE8vg2 LqAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785919084; x=1786523884; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ve8270E6MOdj8YsOaSYLA5r25PubDk8jW4r4l/rs05g=; b=M3GYiIyX9BHTRRg4yxWcrmxCPzBPIcNT49+SNmzt/Ms3Go8avN8dOkbutERsBygVwW rFVR7Jpey7eaq9pFd6GGJhq4VtvRnoBWnCervB4FHGrvWgyR/z76hunF4641HmHjfktP L6z21dUYZn/7NqwNHuDmyngMWO6/PtE8JUYLJ5pWRgT6RZTrN3QlAQQz/WENhhuy/PQR f6NinLl9nW1q+r1n3a8tp6/u/tegIkzIG5v8j9XRsYNuONNRcdSYIV2bZpuVTSgW7hAC YzKJ5jlsEe68LL4ZhnJVCjIWpdUEi3XXhr53AWyK2OhJg/JALbWO+z97UdDyWFtEM1kj t9JA== X-Forwarded-Encrypted: i=1; AHgh+Rrb3JkWfwYZ3BXjHZamL2vRiOtYm4cPk4U815BxYEanBxEHfoTAOFQ41gyZtDyfQW7did3rUppL9U6/inA=@vger.kernel.org X-Gm-Message-State: AOJu0YxMDHpUbr9YSoKr9xCPCJuLCTk5O7V27Aw5mGi2F+tjziGvqPeV 0J88HW54AwdsS8temVpwEWe9IjRVCxcNmtjd4nUuagtpTzJaxYy8q6J3 X-Gm-Gg: AR+sD11wW4JcOMyBMjysFxqrhAh44bcOp5fp7GwFlzEidEwnasKOw07eQsWfvyACv5D Y+l1q+dKqigMrR5TuY4GD0o2ZZ3pAb0ynXMPBr7jkrvCQp0VSwwWyyU/qtB6/pMlLVBE1wT/sLC j6T2772/1zZvpXvCGJDlnKizWldwr3wld8ZrMrNvfeoDS0NBHXaNDQK1Hzd6HXdhkdyOrql1AfA I/kkNlKxUFseycqno3p1gOYC4ANErciFjw7Kpi5VNuljHCMntY8wRI/99Pk9htWH7w9nvi8GTub BKsMsRObsRBEFZ1ZFov90RSY1ccyzWiBD15er+a1qWoaTse6D3+XIubXthcAbB9GoU2mIXTwnq6 u5uiv3+TLVSww0t20h4ut5ww2oPutZGrTr2tJnNZEbUi8/e1wS5/wd46TCJ7OwBTxtjDoSdN0a0 t1BgB31AAGNSdJ9hUmPapcfxZFMKrfrOgAnNy+1uN8EPNMGdllGnKPQjAcdnaj4FTkDPJXgLvLx tMbtEYjs1RUlaGYJiGF90+NJH6ivkTewlytEO4m2cmQWXKtQAeyJ+2B4WIDwDe4VW3b9VCOW6UL ZoWslL1XbyPwkg== X-Received: by 2002:a5d:5f83:0:b0:47f:80e0:53bf with SMTP id ffacd0b85a97d-47fec5322c9mr3831273f8f.3.1785919083806; Wed, 05 Aug 2026 01:38:03 -0700 (PDT) Received: from fedora ([149.3.87.76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47febfe5d68sm6707621f8f.9.2026.08.05.01.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 01:38:03 -0700 (PDT) From: Giorgi Tchankvetadze To: linux-iio@vger.kernel.org Cc: jic23@kernel.org, joshua.crofts1@gmail.com, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, linux-kernel@vger.kernel.org, Giorgi Tchankvetadze Subject: [PATCH v3] iio: light: veml3328: reshape scale array for readability Date: Wed, 5 Aug 2026 12:35:34 +0400 Message-ID: <20260805083532.92585-3-giorgitchankvetadze1997@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Giorgi Tchankvetadze The veml3328_scale_vals array is declared as a flattened [4][8] array, so accessing a scale value requires calculating the offset of its (val, val2) pair using gain_inx * 2. Reshape the array as [4][4][2], with separate dimensions for integration time, gain and the scale value pair. This removes the manual stride calculation and makes the relationship between the indexes and values explicit. Add named integration-time indexes and use designated initializers for veml3328_it_times and veml3328_scale_vals so both tables use the same index definitions. Suggested-by: David Lechner Suggested-by: Jonathan Cameron Reviewed-by: Joshua Crofts Signed-off-by: Giorgi Tchankvetadze --- Changes in v3: - Add named integration-time indexes as suggested by Jonathan Cameron. - Use designated initializers for veml3328_it_times and veml3328_scale_vals to keep both tables indexed consistently. Changes in v2: - Reshape veml3328_scale_vals as [4][4][2], as suggested by David Lechner. - Update read and write paths to access the scale value pair directly. drivers/iio/light/veml3328.c | 53 ++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/iio/light/veml3328.c b/drivers/iio/light/veml3328.c index 7ff1753925c4..df36c48204be 100644 --- a/drivers/iio/light/veml3328.c +++ b/drivers/iio/light/veml3328.c @@ -32,6 +32,11 @@ #define VEML3328_REG_DATA_B 0x07 #define VEML3328_REG_DATA_IR 0x08 =20 +#define VEML3328_CONT_IT_50MSECS 0 +#define VEML3328_CONT_IT_100MSECS 1 +#define VEML3328_CONT_IT_200MSECS 2 +#define VEML3328_CONT_IT_400MSECS 3 + #define VEML3328_CONF_IT_MASK GENMASK(5, 4) #define VEML3328_CONF_GAIN_MASK GENMASK(11, 10) =20 @@ -89,21 +94,40 @@ static const struct iio_chan_spec veml3328_channels[] = =3D { * Precomputed scale values (micro units). * Formula for calculation: 0.384 * (50000 / IT_us) * (1 / Gain) * Gain indexes: 0 (x0.5), 1 (x1), 2 (x2), 3 (x4) - * IT indexes: 0 (50ms), 1 (100ms), 2 (200ms), 3 (400ms) */ -static const int veml3328_scale_vals[4][8] =3D { - { 0, 768000, 0, 384000, 0, 192000, 0, 96000 }, - { 0, 384000, 0, 192000, 0, 96000, 0, 48000 }, - { 0, 192000, 0, 96000, 0, 48000, 0, 24000 }, - { 0, 96000, 0, 48000, 0, 24000, 0, 12000 }, +static const int veml3328_scale_vals[4][4][2] =3D { + [VEML3328_CONT_IT_50MSECS] =3D { + { 0, 768000 }, + { 0, 384000 }, + { 0, 192000 }, + { 0, 96000 }, + }, + [VEML3328_CONT_IT_100MSECS] =3D { + { 0, 384000 }, + { 0, 192000 }, + { 0, 96000 }, + { 0, 48000 }, + }, + [VEML3328_CONT_IT_200MSECS] =3D { + { 0, 192000 }, + { 0, 96000 }, + { 0, 48000 }, + { 0, 24000 }, + }, + [VEML3328_CONT_IT_400MSECS] =3D { + { 0, 96000 }, + { 0, 48000 }, + { 0, 24000 }, + { 0, 12000 }, + }, }; =20 /* integration times in microseconds */ static const int veml3328_it_times[][2] =3D { - { 0, 50 * USEC_PER_MSEC }, - { 0, 100 * USEC_PER_MSEC }, - { 0, 200 * USEC_PER_MSEC }, - { 0, 400 * USEC_PER_MSEC }, + [VEML3328_CONT_IT_50MSECS] =3D { 0, 50 * USEC_PER_MSEC }, + [VEML3328_CONT_IT_100MSECS] =3D { 0, 100 * USEC_PER_MSEC }, + [VEML3328_CONT_IT_200MSECS] =3D { 0, 200 * USEC_PER_MSEC }, + [VEML3328_CONT_IT_400MSECS] =3D { 0, 400 * USEC_PER_MSEC }, }; =20 static int veml3328_power_down(struct veml3328_data *data) @@ -184,9 +208,8 @@ static int veml3328_read_raw(struct iio_dev *indio_dev, if (it_inx >=3D ARRAY_SIZE(veml3328_it_times) || gain_inx >=3D 4) return -EINVAL; =20 - /* Stride by 2 through the flattened array to match (val, val2) */ - *val =3D veml3328_scale_vals[it_inx][gain_inx * 2]; - *val2 =3D veml3328_scale_vals[it_inx][gain_inx * 2 + 1]; + *val =3D veml3328_scale_vals[it_inx][gain_inx][0]; + *val2 =3D veml3328_scale_vals[it_inx][gain_inx][1]; =20 return IIO_VAL_INT_PLUS_MICRO; =20 @@ -282,8 +305,8 @@ static int veml3328_write_raw(struct iio_dev *indio_dev, return -EINVAL; =20 for (i =3D 0; i < 4; i++) { - if (val =3D=3D veml3328_scale_vals[it_inx][i * 2] && - val2 =3D=3D veml3328_scale_vals[it_inx][i * 2 + 1]) + if (val =3D=3D veml3328_scale_vals[it_inx][i][0] && + val2 =3D=3D veml3328_scale_vals[it_inx][i][1]) break; } =20 --=20 2.52.0