From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 372413A6B83 for ; Tue, 12 May 2026 22:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778625141; cv=none; b=XCrdXD7s6oWhuO5TY6s2ANBs7X6hJYS/ZmDE25fnfM6cbP+4EggPXGQV3Lgc6aoZh46y8WKjJIfE2+sC/rpVNY9PMD/DdwAW1Cbmv6ul+1xLYjvslTvD6LbCvYuVbRChMf2LorbPiMAl12orp0r+wWj+rWyO9L5fofxofLYYdsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778625141; c=relaxed/simple; bh=NzPSdUf6T+ORUNm6PzVWnjy3jXA+qpDxvB4jvR8BSlM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ju46KvIRyG2zLS/J7f2Q2afTwZjqrAIVx7HHO04h2hc6t0M2/pJ+R6afu2pQXZRLgwED4IitGoxMCV/Qh51BCLsncVQjCOvT08j9/YkkgvdV4v4A896D9dGVp/O9hh70gPMmGL5+s10lDXJMgGXy1pRCy/MyrMMNDtFsse8eB1U= 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=C5ZRjnOw; arc=none smtp.client-ip=209.85.128.50 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="C5ZRjnOw" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4891f625344so55780735e9.0 for ; Tue, 12 May 2026 15:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778625138; x=1779229938; 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; bh=gld2CLWnRnPqjxg7OzSmNjNiyBF8uhbwEKKeGB5tZE0=; b=C5ZRjnOwaHjt2IrNdvcZwuH/dWpi2qeYpA82LUV2AbhVqp6uwu5qS7Qi0IeH6fDu0j YHlKBSWA18/GgAtQAhEfh9EfrWekYMcvlx7Q+QpyNbqIEOaQOnRvCvSesq2viYvxD01W XTSGINWoZUnlVKlQB8BG0LR9Yokh7fmWpxj/Og7qv8aYEY1m1Wy9AbIrIUMP9IbLQ5Qk ADgrONyQEkAcagFaw+2I6WAgecNkchKvXExpfqLhyWH1s08iT2Upu5WjddxUUwX6xkmJ s+g/yaZ/4gcwuPE1jyahBIZDETk/0AFQIxUoJI190cFz+qrG/bYKHeawghKZxivwQbjk vT8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778625138; x=1779229938; 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; bh=gld2CLWnRnPqjxg7OzSmNjNiyBF8uhbwEKKeGB5tZE0=; b=T/wrgjYwu1eqM9eM7x8hiQi8mHqWERigAPAmQkL4wae+oKYCJOwdLtRj89wzSlC5JD r+ytee5q3SywzQkI01u9WrWO/xQNlr96RArY4JWz873zH0soKKidZOKHuqI+pAw4xwyq vaIW1eggfTonuMeIjk1FVMBrucf6uWHiJqLj4zOgBe8BkDVnWFK2ALuhM1t0fOKXo25l 7ceqv6CDKs6qeWcu8Osg1qmicW/9/SfbdFj9R7OTmgjqhgIefntfVxED8Vpx5+QKUxcP Wps9cFWAdyE7qIl+TPbHN0s7SRprwRnW/9acvXMLvT89xr/lWxkqLQuWFDj7/PjXBIWk 9w5g== X-Forwarded-Encrypted: i=1; AFNElJ8eewonIFeUxkNSYyLfGag2J4WX/CSAWvdrU1mh9We+tALJbmJbfveZKNCwS3jTGerB2aFoio/x8EF+7+0=@vger.kernel.org X-Gm-Message-State: AOJu0YxOjvOENclub/PlXtpwYkxKPRk7PBL/xyTveKwecQBv39rPWiUy d99mDTaSOlHlv8hGsTwVztT9Nn9km7FKawkCUHUCyo77D1gNWNdzycwi X-Gm-Gg: Acq92OGjL20GJ1+smB2+2JRjeIITWctZJ/gc8cYAqFzH4969LIO6BIIUS7YJZp8w1v6 dCptYLJ9mAhP9cO7Opi809w+0TWJW1723tCRv22aocfxqIqN2tj+6RU9ulvSx6Q+azk5L+ur7+K hjm0QNsjBj6e/8mo3iqsXdmfMyNZB1Ix09dGK2IdcuD/AbKQWguvLNdxyojyaY29NW6KKBdwyJa 4nMJHnO8yrn/oSfbqNwLM6R3XaYPAPKMdwvFz2jVHDobSdMoBm8xrCk46PK6CZvvM20Z6HkZVla Q7Xw9a47RevlHBH7xutD+30QF/sI+FYzLwRBjxjJIYOsSesu0MfcFstIbfbxtpQc014aCAtDg+G jqOR6jL8PcqBUoeUuTGr97dHmNByIcmUtjLatgKjmpQ2WtFz/6wcVGWriJ5tzsIDz2NWaRLPmjP O0ZcfO9InoD8cn3sjxjSFi8B+5se4bPi4EHahi8lj0Wy+bw6z1aUO8rHI= X-Received: by 2002:a05:600c:4e55:b0:48a:761:5816 with SMTP id 5b1f17b1804b1-48fc99275d3mr10977985e9.8.1778625137467; Tue, 12 May 2026 15:32:17 -0700 (PDT) Received: from aldo-conte-t14.tailf68ad9.ts.net ([2a01:e11:5402:d840:f1ee:c5d:74e4:6e19]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8f3c65f2sm47377375e9.1.2026.05.12.15.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 15:32:17 -0700 (PDT) From: Aldo Conte To: jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, shuah@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linux.dev Subject: [PATCH v2 0/5] devm conversion, wait time, locking cleanup Date: Wed, 13 May 2026 00:32:10 +0200 Message-ID: <20260512223215.25596-1-aldocontelk@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This is v2 of the TCS3472 series, addressing the review comments from Andy Shevchenko on v1. The series modernizes the tcs3472 driver by converting it to use devm for resource management, switching to guard(mutex) for locking, implementing wait time support exposed through sampling_frequency (which was a long-standing TODO). Patch 1: sorts the #include block alphabetically. v2: - New in v2 (suggested by Andy). Patch 2: converts the remaining mutex_lock/unlock pairs to guard(mutex). v2: (suggested by Andy). - Moved earlier in the series; dropped "Found by code inspection". Patch 3: converts the driver to devm for resource allocation, drops the explicit remove() callback, and adds tcs3472_powerdown_action() to power down the chip on cleanup or probe failure. v2: (suggested by Andy). - Read-modify-write in powerdown/resume rewritten as "compute, write, commit on success". - Use local 'struct device *dev = &client->dev' in probe. Patch 4: implements wait time support, closing a long-standing TODO. The user controls WTIME indirectly via sampling_frequency. WTIME is recomputed when integration_time changes, preserving the requested frequency. WEN is disabled when the frequency is too high; WLONG is enabled when the period exceeds the WTIME range. v2: (suggested by Andy). - validation tightened (rejects val > 0 with val2 < 0). - target_freq_uhz uses div_u64() for 32-bit portability. - TCS3472_ENABLE_RUN introduced here with AEN | PON | WEN, no longer redefined between patches. Patch 5: moves the trailing return -EINVAL in tcs3472_read_raw() and tcs3472_write_raw() into explicit default: cases. v2: - New in v2 (suggested by Andy). Testing: All five patches were tested individually on a Raspberry Pi 3B with an Adafruit TCS3472 breakout connected to I2C-1 at address 0x29. Each patch was checked out and built separately to ensure the driver remains functional in every intermediate state of the series. Patch 1 (sort headers): - Driver loads cleanly; RGBC channel reads return reasonable values. - No warnings in dmesg. Patch 2 (guard(mutex)): - Threshold value writes (RISING=1000, FALLING=200) read back correctly; AIHT/AILT registers on the chip mirror the values. - Threshold enable toggles the AIEN bit in ENABLE (sysfs '1' -> 0x13, sysfs '0' -> 0x03). - rmmod completes with no lock leak in dmesg. Patch 3 (devm conversion): - Probe completes with ENABLE = 0x03 (PON|AEN, WEN not yet introduced). - RGBC reads return sensible values (e.g. clear=525, red=269, green=151, blue=97). - calibscale, integration_time, threshold value/period, and threshold enable all work as before. - After echo 0x29 to delete_device, ENABLE reads back as 0x00, confirming that devm_add_action_or_reset() invokes tcs3472_powerdown() on cleanup. - rmmod completes with no warning. Patch 4 (wait time / sampling_frequency): - Initial state after probe: ATIME=0x00, WTIME=0xff, CONFIG=0x00, ENABLE=0x0b (PON|AEN|WEN), sampling_frequency=1.614987 Hz. - Write 1 Hz: WTIME=0x60, CONFIG=0x00, ENABLE=0x0b, sampling_frequency reads back 0.999200 Hz. - Write 5 Hz (too high for any wait time): WEN cleared, ENABLE=0x03, sampling_frequency reads back 1.621271 Hz (cycle with ATIME alone). - Write 0.5 Hz (period exceeds WTIME range): WLONG enabled, CONFIG=0x02, WTIME=0xd0, WEN re-enabled, ENABLE=0x0b, sampling_frequency reads back 0.500200 Hz. - After setting 0.5 Hz, changing integration_time to 0.024000 s: WTIME automatically recomputed to 0xbb, sampling_frequency reads back 0.496622 Hz (closest achievable to 0.5 Hz at the new ATIME). - Invalid inputs (-1.0, 0.0) rejected with -EINVAL; chip state unchanged. - After rmmod, ENABLE reads back as 0x00 (PON, AEN and WEN all cleared by powerdown via devm). Patch 5 (default case): - All read_raw and write_raw cases (raw RGBC, calibscale, integration_time, sampling_frequency) handle attributes identically to the previous patch. - Invalid inputs still rejected with -EINVAL through the explicit default: case. - rmmod completes cleanly with ENABLE = 0x00 Aldo Conte (5): iio: light: tcs3472: sort headers alphabetically iio: light: tcs3472: convert remaining locking to guard(mutex) iio: light: tcs3472: use devm for resource management iio: light: tcs3472: implement wait time and sampling frequency iio: light: tcs3472: move standalone return to default case drivers/iio/light/tcs3472.c | 357 +++++++++++++++++++++++++----------- 1 file changed, 249 insertions(+), 108 deletions(-) -- 2.54.0