From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 D853D4183CA for ; Tue, 9 Jun 2026 13:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781012168; cv=none; b=FHNhfcxm0n1BIh0Ue2JhW2ebCBN2LJ+CJmSs638TyBCJBr6VHzPgMPmv5+HIX+ub9zLZ6CXIvVXy/c1WR4f5vyFLdH11NbUQx2gQQ1gI5vHiZMiWGpsuCgKmtbJsVYk9BFOi7po4sva14/lBsmYyJ/uOJ9bnqaQ5y0lnolrvfuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781012168; c=relaxed/simple; bh=KQ00C/T0PtTvLOkQ9jgo4BMm9vvhzvMku6FHwA90IuY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GCQw2QU/kl3BLa+H2Vg4ZyqWCaUeb4ZWXJnbq9wwOS6tVIXHw+cFFVgcKMpC+1MkrLSvTXCFmCUallV5qYvms6SoFkT2kH4XY2ATBI+WHvAeD2X8thXIegOp2ee6CjWGgJHBRUDc1DVzUjy4LwbVq+iUwt8auIMuNVWVXsBvcBI= 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=pwkkD1rB; arc=none smtp.client-ip=209.85.221.47 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="pwkkD1rB" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-46015dc517aso4483438f8f.2 for ; Tue, 09 Jun 2026 06:36:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781012165; x=1781616965; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Nko1eeZPe9gacI4aqgmTtbFeb0B90PMqb5fo3nde8io=; b=pwkkD1rBGhWhOmU/Rl8oCFZWtA88oaZQ1gktEFtx4n5+tLaO2DGp0HNtqNb1ckXZ7B IXCur0HZ7A9we4hKHJMeJfgdmDfEZ093inMd4KyvZx7CFCsggsmb2LlbINzMl18Nw708 4ggO0HmyH+qrMezaia89+4B4Xdv/rKMqojbDdNmtjRRiol50gIgGvKwbAi66NbgdvXTM wqTKPi7v2cUFDQYl/8b+qKcKj6rmwH7o6r43GQQ+tsIOe+dRLxUp6DVhQ9QFFT/Z7lLt DwYtIZJX3UgKtbHOOfbA8hAf/Zw1ASeizwgEOKojSxAfd6dN2SNt8VJVVj26j6mVGa5l svzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781012165; x=1781616965; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nko1eeZPe9gacI4aqgmTtbFeb0B90PMqb5fo3nde8io=; b=Logkj8srkJUCuYrhM7+/wuTZBk97Zer34a8tXR2vgr1czjbrcof7eOFV3rmtgblw2R tLLTHAygfjp/le+9xUsvcmuf99Ta+Y1/yfmljDRAuOmte3GBRcNBfbpyoVulNpPZOza6 k8iHUt4K6ZU410s75tq9LiMgHkO6oxHiJgOufvvX83m3k3dUN/V0YS8ag0VUl2gOmAG/ De36aGIvZLcej634cGYfAt/k9m1y2gFwAxTYIbvpzzI2EgYI0401xidpQCBGqmzKHpi8 TbSoNlE2Cia0vd40rYl6Ze2DyK+ZJLZYdzXny1u4828IlQTmyGiv62oqoHPoVwIey182 /5QA== X-Forwarded-Encrypted: i=1; AFNElJ9OiuzamYdUVOWn5TJkIQnAUsJ6uPIvFSt1LRK6gW3FGDIfqSjSv2vU6rPwmeOhTLjAHQrhvgTp+W2xK0w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/qzMiwb8Nk/J/5jG3wmW97xYLOnTKIy4iieD0PIKxQb2ebFt1 T/uT8b3R6qY63P9xO/ODQCpZ/Dspg3+KgTJuM7mtKklxDTrorQjb9jZ1 X-Gm-Gg: Acq92OH9OFx1rHoJPQcKhTqLJoNyKWx6QVJfywC0yfRDX1T4XYG8AmFKSw87NEnprzp D0tUJLFRSkjQ4cbhcyUISV3Mb5FGa3HDxx9CrS4NHhVwJVxs1VXOWI2QmxqG9rJXwyX/kPzzVCj kcM0l2PH3inM2rhw3s5qGJRGUa14v9uzkii32JDU6C0rbtGqKbcWFt+an7cGpitO2cV2KoBQ36/ gRsqxTAf0c25+dqilBgnygzxIoLXPKG/iqKH4+yZIQraaUtjRIVb1Yh0ToldryAJK3HvDTmqJ0F MX2X2Reng9KCFNoDRoTzJ9zOdvqlerdL7WrVzp1kUJCfMOX/8ZRnxK+/Drz6QgO7uLECYcJW6XM x9a8SAR6nT+88R8qbDPQerw4pWClYr5Yp0nbTUrBn4XEH9oGIoAnZu/7zXPP7f20fSiNBQc+7KT z+EIrVq3dnlEc2tIZKD1garuzU908faHua7mcqk5Gv X-Received: by 2002:a5d:544d:0:b0:460:1643:caf7 with SMTP id ffacd0b85a97d-460306467aemr22662161f8f.27.1781012164957; Tue, 09 Jun 2026 06:36:04 -0700 (PDT) Received: from [192.168.37.44] ([217.61.173.50]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f351ac0sm110805558f8f.27.2026.06.09.06.36.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Jun 2026 06:36:04 -0700 (PDT) Message-ID: Date: Tue, 9 Jun 2026 15:36:03 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] iio: tcs3472: implement wait time and sampling frequency To: Andy Shevchenko Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, shuah@kernel.org, joshua.crofts1@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linux.dev References: <20260607112713.299968-1-aldocontelk@gmail.com> <55020e69-ffe2-4d40-bdac-e6649693ebb7@gmail.com> Content-Language: en-US From: Aldo Conte In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 09/06/26 14:15, Andy Shevchenko wrote: > On Tue, Jun 09, 2026 at 12:27:52PM +0200, Aldo Conte wrote: > > ... > >>>> + cycle_us = div64_u64(PSEC_PER_SEC, >>>> + (u64)val * USEC_PER_SEC + val2); >>> >>> I'm a bit puzzled why cycle has "us" suffix. We divide seconds by seconds... >> Could it be ok if i place a comment here like: >> >> /* >> * cycle_us = 1 / freq, expressed in microseconds. >> * Numerator: 1 [s] = PSEC_PER_SEC [ps] >> * Denominator: freq [Hz] * USEC_PER_SEC + val2 [µHz] = freq in [µHz] >> * Result: ps / µHz = µs >> */ > > Yes, and replacing the USEC_PER_SEC by MICROHZ_PER_HZ. ok! > > ... > >> /* >> * If the requested wait is so long that even WLONG cannot >> * cover it, wtime may still be negative. Saturate to 0, >> * which is the largest possible wait (256 * 28.8 ms = 7.37 s). >> */ > > This and other comments make total sense, with them it's much easier to read > the code, thanks! to you! > > ... > >> Moreover, I would like to take this opportunity to address the comments >> raised on Sashiko: >> >> https://sashiko.dev/#/patchset/20260607112713.299968-1-aldocontelk%40gmail.com >> >> I propose the following changes. >> >> For the read and write event functions: >> >> The read path would become: >> >> case IIO_EV_INFO_PERIOD: >> period = tcs3472_cycle_time_us(data) * >> tcs3472_intr_pers[data->apers]; >> *val = period / USEC_PER_SEC; >> *val2 = period % USEC_PER_SEC; > > Again, use HZ-based multiplier, see above. Here i do not understand why MICROHZ_PER_HZ is better. In the previous case, we were indeed referring to the denominator of the calculation, which was actually a frequency, so MICROHZ_PER_HZ is indeed correct. But in this case, we are calculating the integer and fractional parts of a period, so I think this would be fine. Tell me where I’m going wrong. > >> return IIO_VAL_INT_PLUS_MICRO; >> >> write becomes: >> >> case IIO_EV_INFO_PERIOD:{ >> unsigned int cycle_us; >> >> period = val * USEC_PER_SEC + val2; > > And again, use HZ-based multiplier, see above. as above... > >> cycle_us = tcs3472_cycle_time_us(data); > >> for (i = 1; i < ARRAY_SIZE(tcs3472_intr_pers) - 1; i++) { >> if (period <= cycle_us * tcs3472_intr_pers[i]) >> break; >> } > > do {} while () seems better choice here (and do it in reverse order?). Could you suggest the do {} while {} form, which seems better? Because I think it is already comprehensible. > >> ret = i2c_smbus_write_byte_data(data->client, TCS3472_PERS, i); >> if (ret) >> return ret; >> >> data->apers = i; >> >> return 0; >> } >> >> Regarding the oscillator tolerance, I suggest using: >> >> tries = 500 >> >> Currently, it is set to 400, based on an 8-second interval divided into 20 >> ms steps. Considering a 20% margin, the total duration becomes approximately >> 9.8 seconds, which corresponds to about 480 steps. Therefore, setting it to >> 500 appears to be a reasonable and safe trade-off. > > Agree. >