From nobody Mon Sep 28 04:09:53 2026 Received: from out-2z4y-a134.jellyfish.systems (out-2z4y-a134.jellyfish.systems [198.54.127.134]) (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 D2FD3407CF4 for ; Wed, 26 Aug 2026 17:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766888; cv=none; b=s8qsgcSVQvR/qJr2K0KEbsVqP6SFR4XDrskj1gjLt2odhLW6i1KUocaShRDcv3zUtsF0pQ4NBa+FdMAI1lRFQeQfsgUal8ofqHGVVk4BxhiLE55MJyhd/kFcJRiqxItWUX9nZSKLab5dQie0XAyJp2bE+yNwet/x+cOs3I7OMM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766888; c=relaxed/simple; bh=VPUFYZdlVAElE2+W6elbLSSYV2hb0wdMXIzDEaxaPHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BrP/d3bdMUE6yoowilMi9adbzPXbuMXjMc4rp2GblYnfMh+i+FGJvj0FwDCl7NHFlanPHrZbW+r0ws6DxKBCGQPZqWV0hdtNTYQymOHtxeNR6MCDkYrgvh7hfNVKkkYZhur+hf4YgfgwizyKBin2QUM8GnXZCa1mCXomgaCoGnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net; spf=pass smtp.mailfrom=catcrafts.net; arc=none smtp.client-ip=198.54.127.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=catcrafts.net Received: from mail.privateemail.com (unknown [87.215.145.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4hVXMv4jwzz8sWS; Wed, 26 Aug 2026 17:54:19 +0000 (UTC) From: Jorijn van der Graaf To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Weiss , Jorijn van der Graaf , Andy Shevchenko Subject: [PATCH v2 1/5] iio: light: stk3310: lower-case the i2c device ID names Date: Wed, 26 Aug 2026 19:54:05 +0200 Message-ID: <20260826175409.326131-2-jorijnvdgraaf@catcrafts.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> References: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> 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 X-Envelope-From: jorijnvdgraaf@catcrafts.net Content-Type: text/plain; charset="utf-8" The i2c device IDs were introduced in capitals, mirroring the ACPI _HID entries added by the same commit be9e6229d676 ("iio: light: Add support for Sensortek STK3310"); at that point the driver enumerated through ACPI only, with no OF table and no i2c module alias export. ACPI _HIDs have their own naming rules; i2c device names conventionally use the lower-case part name, matching the devicetree compatible suffix. The spelling is visible: a client instantiated through the i2c sysfs interface under the lower-case name taken from a compatible string binds through the OF table's name fallback, but has no firmware node, so i2c_match_id() is the only way for it to reach driver match data, and its string comparison is case-sensitive, so the capitals can never match. Lower-case the names so such clients match the id table, and receive the per-chip match data a subsequent change attaches to it. The module aliases follow the rename (i2c:STK3310 becomes i2c:stk3310), and a sysfs client instantiated under a capitals name no longer binds. Suggested-by: Andy Shevchenko Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf Reviewed-by: Andy Shevchenko --- drivers/iio/light/stk3310.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 7c8a1d2b2ed0..5b5b6812edc7 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -766,10 +766,10 @@ static DEFINE_SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk33= 10_suspend, stk3310_resume); =20 static const struct i2c_device_id stk3310_i2c_id[] =3D { - { .name =3D "STK3013" }, - { .name =3D "STK3310" }, - { .name =3D "STK3311" }, - { .name =3D "STK3335" }, + { .name =3D "stk3013" }, + { .name =3D "stk3310" }, + { .name =3D "stk3311" }, + { .name =3D "stk3335" }, { } }; MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id); --=20 2.55.0 From nobody Mon Sep 28 04:09:53 2026 Received: from out-2z4y-a149.jellyfish.systems (out-2z4y-a149.jellyfish.systems [198.54.127.149]) (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 78E1844BCB0 for ; Wed, 26 Aug 2026 17:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766903; cv=none; b=dkmHoT4ScJotQAJ1WDBHoK3Kz1M19iC5q33ygQoQtcYOoDKsdAHzZ0gJNV2gYosvjhY3XCikiFrnqJ7sd/JugvpNKG82Jn1v3dKRbv0rqNoMqOS3a7zxrPB8p4nV6a79ol4QxvLqZnkJ5F8FnUFA8sUSX9TlgG4/+ToJSUvgvG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766903; c=relaxed/simple; bh=n8EG6axqjMnfb5vB4Ik6vvRPTgDNmmVhOQoJ89A9+Rc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q8O/ILJ2H9pn/96ztpejkcaIFoNiXUjG0gbj4omYGavKInTNPd+87oOiHPrvWFvyxgeB5aNYrtn/Z36zVeTloCgPnK68prtgk55SlXf12lYr51pRA/+ik2MJkeGGAaVaQJKlKSKkKh+11/yhwTK+e8wUfCUHkimrlpjwrRWCEYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net; spf=pass smtp.mailfrom=catcrafts.net; arc=none smtp.client-ip=198.54.127.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=catcrafts.net Received: from mail.privateemail.com (unknown [87.215.145.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4hVXMz6q3mz8sWP; Wed, 26 Aug 2026 17:54:23 +0000 (UTC) From: Jorijn van der Graaf To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Weiss , Jorijn van der Graaf , Krzysztof Kozlowski Subject: [PATCH v2 2/5] dt-bindings: iio: light: stk33xx: document the Sensortek STK36C61 Date: Wed, 26 Aug 2026 19:54:06 +0200 Message-ID: <20260826175409.326131-3-jorijnvdgraaf@catcrafts.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> References: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> 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 X-Envelope-From: jorijnvdgraaf@catcrafts.net Content-Type: text/plain; charset="utf-8" The STK36C61 is a 3-in-1 ambient light / proximity / RGB colour sensor found in the Fairphone 6. Its ambient light and proximity register interface is compatible with the stk3310's, while the dedicated compatible identifies the part, whose colour channels the fallback does not describe. Add sensortek,stk36c61 with a sensortek,stk3310 fallback, mirroring the stk3013 entry, and widen the title and description to cover the part. Reviewed-by: Krzysztof Kozlowski Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf --- Documentation/devicetree/bindings/iio/light/stk33xx.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml b/Doc= umentation/devicetree/bindings/iio/light/stk33xx.yaml index e4341fdced98..0165a348918b 100644 --- a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml +++ b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml @@ -4,14 +4,14 @@ $id: http://devicetree.org/schemas/iio/light/stk33xx.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: | - Sensortek STK33xx I2C Ambient Light and Proximity sensor +title: Sensortek STK33xx/STK36C61 I2C Ambient Light and Proximity sensor =20 maintainers: - Jonathan Cameron =20 -description: | - Ambient light and proximity sensor over an i2c interface. +description: + Ambient light and proximity sensor over an i2c interface. The STK36C61 + additionally provides RGBC colour channels. =20 allOf: - $ref: ../common.yaml# @@ -26,6 +26,7 @@ properties: - items: - enum: - sensortek,stk3013 + - sensortek,stk36c61 - const: sensortek,stk3310 =20 reg: --=20 2.55.0 From nobody Mon Sep 28 04:09:53 2026 Received: from out-2z4y-a133.jellyfish.systems (out-2z4y-a133.jellyfish.systems [198.54.127.133]) (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 6B046442FB3 for ; Wed, 26 Aug 2026 18:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787767675; cv=none; b=J7XxFskDu9GcD9E5IJdUyKPYT5EE2aDLevdYObukYLAi3xddZU1XC8+9ds2cQ7xrDH76ctLb9yGQMlzyIW1pr2k1+ajlgzf39fPEn3Cb4tdGmp8JDaZxkpP/42npuTMhmnABKtsUBSFMQA2RQzhLTBEiMU6nvWGQs6kH3lF4n6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787767675; c=relaxed/simple; bh=5MUS+jSLenmtWtQm3/CNTEcXFg2KOODI/Ydn6oNWr4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E8bkqUyxMzMhdObG2uV3VfMU9KyRt1a/AT3Qorlwcjz7j/P2AGIMBVW8sIlVcypBk9KMnIKw5x8jGpDC2hcv5d7cF4TKvkS/Ru7m6I1tqoiXw0DJ+8312oMx/NPMeDFeP5X03jU8byvUYWJP2mlsWYr3h9lO/zYU9V8JAeSTBRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net; spf=pass smtp.mailfrom=catcrafts.net; arc=none smtp.client-ip=198.54.127.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=catcrafts.net Received: from mail.privateemail.com (unknown [87.215.145.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4hVXN41gRtz8sWX; Wed, 26 Aug 2026 17:54:28 +0000 (UTC) From: Jorijn van der Graaf To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Weiss , Jorijn van der Graaf Subject: [PATCH v2 3/5] iio: light: stk3310: move the data registers into the channel address Date: Wed, 26 Aug 2026 19:54:07 +0200 Message-ID: <20260826175409.326131-4-jorijnvdgraaf@catcrafts.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> References: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> 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 X-Envelope-From: jorijnvdgraaf@catcrafts.net Content-Type: text/plain; charset="utf-8" The RAW read selects its data register with a per-channel-type branch. Record each channel's data register in its .address field and read from there, so adding a channel does not grow the branch. Suggested-by: Jonathan Cameron Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf Reviewed-by: Andy Shevchenko --- drivers/iio/light/stk3310.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 5b5b6812edc7..156888969366 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -184,6 +184,7 @@ static const struct iio_chan_spec_ext_info stk3310_ext_= info[] =3D { static const struct iio_chan_spec stk3310_channels[] =3D { { .type =3D IIO_LIGHT, + .address =3D STK3310_REG_ALS_DATA_MSB, .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | @@ -191,6 +192,7 @@ static const struct iio_chan_spec stk3310_channels[] = =3D { }, { .type =3D IIO_PROXIMITY, + .address =3D STK3310_REG_PS_DATA_MSB, .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | @@ -370,25 +372,20 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - u8 reg; __be16 buf; int ret; unsigned int index; struct stk3310_data *data =3D iio_priv(indio_dev); struct i2c_client *client =3D data->client; + struct regmap *map =3D data->regmap; =20 if (chan->type !=3D IIO_LIGHT && chan->type !=3D IIO_PROXIMITY) return -EINVAL; =20 switch (mask) { case IIO_CHAN_INFO_RAW: - if (chan->type =3D=3D IIO_LIGHT) - reg =3D STK3310_REG_ALS_DATA_MSB; - else - reg =3D STK3310_REG_PS_DATA_MSB; - mutex_lock(&data->lock); - ret =3D regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf)); + ret =3D regmap_bulk_read(map, chan->address, &buf, sizeof(buf)); if (ret < 0) { dev_err(&client->dev, "register read failed\n"); mutex_unlock(&data->lock); --=20 2.55.0 From nobody Mon Sep 28 04:09:53 2026 Received: from out-2z4y-a152.jellyfish.systems (out-2z4y-a152.jellyfish.systems [198.54.127.152]) (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 B1A61471423 for ; Wed, 26 Aug 2026 17:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766903; cv=none; b=o8GR5nsqskQQKlRLfyQHZ19cR7Q/9Swiv0gkqWeDg04lBvV0lXxRIVs0pcbs7nLVCuVXDGrDqoleZXuUt58DMoOPDxV7V7s3KQ2LRze/L8kduHPH8TUUKCyAK/KOE0/7ghtMN4sE1MD/1WfiSPUofgYU66DXj6zsdpx7HLMktTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766903; c=relaxed/simple; bh=nJdQI8BEZEemf2xtWVmqcjOljCyAezykSB2m5Eya7Mc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BuVwpgBJJiXd/U4EX9SzCy4F9tZ3jY9hg0A5B0R63HziG+Ij44iCkHTWPCbmH28tFcBjzLoszfszp2m+giRF7bjH8378vsAWW4EhsIBHYTqiX206ASp+n9SLqc3CbX4iSlOXYd+kCENFwlKJW+fPJQnCvD1RWN1pFfeLmmC8fBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net; spf=pass smtp.mailfrom=catcrafts.net; arc=none smtp.client-ip=198.54.127.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=catcrafts.net Received: from mail.privateemail.com (unknown [87.215.145.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4hVXN82YGrz8sWP; Wed, 26 Aug 2026 17:54:32 +0000 (UTC) From: Jorijn van der Graaf To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Weiss , Jorijn van der Graaf Subject: [PATCH v2 4/5] iio: light: stk3310: add per-chip match data Date: Wed, 26 Aug 2026 19:54:08 +0200 Message-ID: <20260826175409.326131-5-jorijnvdgraaf@catcrafts.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> References: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> 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 X-Envelope-From: jorijnvdgraaf@catcrafts.net Content-Type: text/plain; charset="utf-8" Introduce a chip_info structure carrying the device name and channel specification, attach it to every i2c, OF and ACPI table entry, and let probe take it from the match data, failing when there is none. Every firmware bind path carries match data, and with the id names in lower case a client instantiated through the sysfs new_device interface under a compatible-derived name receives it through the id table. The shared channel definitions move into macros. The ACPI table entries change to named initializers, matching the other id tables. This is a preparatory change for a variant that provides more channels than the existing parts. No functional change for firmware-described devices; a sysfs client under a name that binds without matching any id entry (the full compatible string) now fails probe with an error instead of probing as an stk3310. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf --- drivers/iio/light/stk3310.c | 95 ++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 156888969366..d632e6447f06 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -181,26 +181,48 @@ static const struct iio_chan_spec_ext_info stk3310_ex= t_info[] =3D { { } }; =20 +#define STK3310_LIGHT_CHANNEL { \ + .type =3D IIO_LIGHT, \ + .address =3D STK3310_REG_ALS_DATA_MSB, \ + .info_mask_separate =3D \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME), \ +} + +#define STK3310_PROXIMITY_CHANNEL { \ + .type =3D IIO_PROXIMITY, \ + .address =3D STK3310_REG_PS_DATA_MSB, \ + .info_mask_separate =3D \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME), \ + .event_spec =3D stk3310_events, \ + .num_event_specs =3D ARRAY_SIZE(stk3310_events), \ + .ext_info =3D stk3310_ext_info, \ +} + static const struct iio_chan_spec stk3310_channels[] =3D { - { - .type =3D IIO_LIGHT, - .address =3D STK3310_REG_ALS_DATA_MSB, - .info_mask_separate =3D - BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_INT_TIME), - }, - { - .type =3D IIO_PROXIMITY, - .address =3D STK3310_REG_PS_DATA_MSB, - .info_mask_separate =3D - BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_INT_TIME), - .event_spec =3D stk3310_events, - .num_event_specs =3D ARRAY_SIZE(stk3310_events), - .ext_info =3D stk3310_ext_info, - } + STK3310_LIGHT_CHANNEL, + STK3310_PROXIMITY_CHANNEL, +}; + +/** + * struct stk3310_chip_info - chip-specific data + * @name: device name reported to the IIO core + * @channels: channel specification + * @num_channels: number of channels + */ +struct stk3310_chip_info { + const char *name; + const struct iio_chan_spec *channels __counted_by_ptr(num_channels); + unsigned int num_channels; +}; + +static const struct stk3310_chip_info stk3310_chip_info =3D { + .name =3D STK3310_DRIVER_NAME, + .channels =3D stk3310_channels, + .num_channels =3D ARRAY_SIZE(stk3310_channels), }; =20 static IIO_CONST_ATTR(in_illuminance_scale_available, STK3310_SCALE_AVAILA= BLE); @@ -632,10 +654,16 @@ static irqreturn_t stk3310_irq_event_handler(int irq,= void *private) =20 static int stk3310_probe(struct i2c_client *client) { + const struct stk3310_chip_info *chip_info; int ret; struct iio_dev *indio_dev; struct stk3310_data *data; =20 + chip_info =3D i2c_get_match_data(client); + if (!chip_info) + return dev_err_probe(&client->dev, -ENODEV, + "missing driver data\n"); + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -654,10 +682,10 @@ static int stk3310_probe(struct i2c_client *client) return ret; =20 indio_dev->info =3D &stk3310_info; - indio_dev->name =3D STK3310_DRIVER_NAME; + indio_dev->name =3D chip_info->name; indio_dev->modes =3D INDIO_DIRECT_MODE; - indio_dev->channels =3D stk3310_channels; - indio_dev->num_channels =3D ARRAY_SIZE(stk3310_channels); + indio_dev->channels =3D chip_info->channels; + indio_dev->num_channels =3D chip_info->num_channels; =20 ret =3D stk3310_init(indio_dev); if (ret < 0) @@ -763,28 +791,27 @@ static DEFINE_SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk33= 10_suspend, stk3310_resume); =20 static const struct i2c_device_id stk3310_i2c_id[] =3D { - { .name =3D "stk3013" }, - { .name =3D "stk3310" }, - { .name =3D "stk3311" }, - { .name =3D "stk3335" }, + { .name =3D "stk3013", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, + { .name =3D "stk3310", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, + { .name =3D "stk3311", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, + { .name =3D "stk3335", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, { } }; MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id); =20 static const struct acpi_device_id stk3310_acpi_id[] =3D { - {"STK3013", 0}, - {"STK3310", 0}, - {"STK3311", 0}, + { .id =3D "STK3013", .driver_data =3D (kernel_ulong_t)&stk3310_chip_info = }, + { .id =3D "STK3310", .driver_data =3D (kernel_ulong_t)&stk3310_chip_info = }, + { .id =3D "STK3311", .driver_data =3D (kernel_ulong_t)&stk3310_chip_info = }, { } }; - MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id); =20 static const struct of_device_id stk3310_of_match[] =3D { - { .compatible =3D "sensortek,stk3013", }, - { .compatible =3D "sensortek,stk3310", }, - { .compatible =3D "sensortek,stk3311", }, - { .compatible =3D "sensortek,stk3335", }, + { .compatible =3D "sensortek,stk3013", .data =3D &stk3310_chip_info }, + { .compatible =3D "sensortek,stk3310", .data =3D &stk3310_chip_info }, + { .compatible =3D "sensortek,stk3311", .data =3D &stk3310_chip_info }, + { .compatible =3D "sensortek,stk3335", .data =3D &stk3310_chip_info }, { } }; MODULE_DEVICE_TABLE(of, stk3310_of_match); --=20 2.55.0 From nobody Mon Sep 28 04:09:53 2026 Received: from out-93wp-a28.jellyfish.systems (out-93wp-a28.jellyfish.systems [104.207.68.28]) (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 C1848472531 for ; Wed, 26 Aug 2026 17:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.207.68.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766919; cv=none; b=tCTgg/0iLCJRXM4usl8r8ol8nVQg1+QyVWPjhSd3KJ9x0V0wLcADiJSSFbfp3UjSOiuIeyv0YJr2Jmwju1Q0bnizl3QIsUSkWI9xBwChsXO7GM87xcQU7xGP6ZDpjXC0axAPpO15z5jUoLGyRBz95z051P1cMwr2wynTLBcDnM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787766919; c=relaxed/simple; bh=eFRl38OAU1gEQyJm1V0nBa3nxt2EKbQBCt9n2M9hUes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xf2Yv86U30DK7FbqTwSs+d/03/MQ5HZcVT8wsLpulAIUdtRf05uEg5WWTDCze1eIeaWkuxrycefLaTo7WMRb6Awz+3NdC1hueelAFoWXnm+kRRgAAjEZj+stpR+A7M+Yjs7Sb7kZIxcANRkU5X3m/hMtXjQD4QMzTreKCBvaUTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net; spf=pass smtp.mailfrom=catcrafts.net; arc=none smtp.client-ip=104.207.68.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=catcrafts.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=catcrafts.net Received: from mail.privateemail.com (unknown [87.215.145.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4hVXND3NZLz8sWS; Wed, 26 Aug 2026 17:54:36 +0000 (UTC) From: Jorijn van der Graaf To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Kees Cook , "Gustavo A . R . Silva" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Weiss , Jorijn van der Graaf Subject: [PATCH v2 5/5] iio: light: stk3310: support the Sensortek STK36C61 Date: Wed, 26 Aug 2026 19:54:09 +0200 Message-ID: <20260826175409.326131-6-jorijnvdgraaf@catcrafts.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> References: <20260826175409.326131-1-jorijnvdgraaf@catcrafts.net> 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 X-Envelope-From: jorijnvdgraaf@catcrafts.net Content-Type: text/plain; charset="utf-8" The Sensortek STK36C61 is a 3-in-1 ambient light / proximity / RGB colour sensor (chip ID 0x95) found in the Fairphone 6. Its register interface is compatible with the feature set this driver uses: the STATE/FLAG bit layout, the data and threshold registers and the gain and integration-time fields, verified on that device (the ALS and proximity readings scale with their gain and integration-time fields, thresholds written through the event interface read back from the chip, and the FLAG near/far bit crosses with them). Add its chip ID to the known-ID list and the device table entries. Whenever the ALS engine runs, the chip also measures four colour channels, laid out directly after the ALS data as 16-bit big-endian values in R (0x15), G (0x17), B (0x19), C (0x1B) order; the R, G and B assignments were each confirmed by the matching channel dominating under red, green and blue illumination, and clear by its broadband response. The ALS data register tracks the green channel exactly. The colour controls, all verified on the device: R, G and B are gained by the same ALSCTRL gain field the illuminance channel uses, clear by a GAIN_F_C field in a GAINCTRL register at 0x4E (documented in the datasheet of the STK37660, a sibling part with the same data register layout; stepping it multiplies the clear count by ~4 per step while the other channels hold still), and the whole colour block integrates over the ALS integration time. Expose the channels with per-channel scale and a shared integration time, as suggested by Jonathan Cameron. The scale attributes reuse the driver's existing table rather than the iio-gts helper. The green channel equals the ALS data, so its scale must read identically to the pre-existing in_illuminance_scale, which has always been the gain selector alone with the integration time exposed separately; iio-gts would fold the integration time into the scale, and its scale writes may retune the integration time behind the illuminance channel's back. The pre-existing available-values files stay constant attributes; converting them to read_avail is a separate cleanup, as it changes the long-standing scale lists' text ("6.4" becomes "6.400000"). Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf --- Documentation/ABI/testing/sysfs-bus-iio | 1 + drivers/iio/light/stk3310.c | 101 ++++++++++++++++++++---- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/te= sting/sysfs-bus-iio index a4f5595722ad..08a8de215814 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -507,6 +507,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_intensity_z_= scale What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_scale What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_scale What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_scale +What: /sys/bus/iio/devices/iio:deviceX/in_intensity_clear_scale What: /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_scale What: /sys/bus/iio/devices/iio:deviceX/in_volumeflow_scale What: /sys/bus/iio/devices/iio:deviceX/in_volumeflowY_scale diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index d632e6447f06..efdb521881e6 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -40,7 +40,13 @@ #define STK3310_REG_PS_DATA_LSB 0x12 #define STK3310_REG_ALS_DATA_MSB 0x13 #define STK3310_REG_ALS_DATA_LSB 0x14 +#define STK36C61_REG_RED_DATA_MSB 0x15 +#define STK36C61_REG_GREEN_DATA_MSB 0x17 +#define STK36C61_REG_BLUE_DATA_MSB 0x19 +#define STK36C61_REG_CLEAR_DATA_MSB 0x1B +#define STK36C61_REG_CLEAR_DATA_LSB 0x1C #define STK3310_REG_ID 0x3E +#define STK36C61_REG_GAINCTRL 0x4E #define STK3310_MAX_REG 0x80 =20 #define STK3310_STATE_EN_PS BIT(0) @@ -54,6 +60,7 @@ #define STK3311S34_CHIP_ID_VAL 0x1E #define STK3311X_CHIP_ID_VAL 0x12 #define STK3335_CHIP_ID_VAL 0x51 +#define STK36C61_CHIP_ID_VAL 0x95 #define STK3310_PSINT_EN 0x01 #define STK3310_PS_MAX_VAL 0xFFFF =20 @@ -83,6 +90,8 @@ static const struct reg_field stk3310_reg_field_als_gain = =3D REG_FIELD(STK3310_REG_ALSCTRL, 4, 5); static const struct reg_field stk3310_reg_field_ps_gain =3D REG_FIELD(STK3310_REG_PSCTRL, 4, 5); +static const struct reg_field stk3310_reg_field_clear_gain =3D + REG_FIELD(STK36C61_REG_GAINCTRL, 4, 5); static const struct reg_field stk3310_reg_field_als_it =3D REG_FIELD(STK3310_REG_ALSCTRL, 0, 3); static const struct reg_field stk3310_reg_field_ps_it =3D @@ -102,6 +111,7 @@ static const u8 stk3310_chip_ids[] =3D { STK3311X_CHIP_ID_VAL, STK3311_CHIP_ID_VAL, STK3335_CHIP_ID_VAL, + STK36C61_CHIP_ID_VAL, }; =20 /* Estimate maximum proximity values with regard to measurement scale. */ @@ -132,6 +142,7 @@ struct stk3310_data { struct regmap_field *reg_state; struct regmap_field *reg_als_gain; struct regmap_field *reg_ps_gain; + struct regmap_field *reg_clear_gain; struct regmap_field *reg_als_it; struct regmap_field *reg_ps_it; struct regmap_field *reg_int_ps; @@ -202,11 +213,35 @@ static const struct iio_chan_spec_ext_info stk3310_ex= t_info[] =3D { .ext_info =3D stk3310_ext_info, \ } =20 +#define STK36C61_INTENSITY_CHANNEL(_mod, _reg) { \ + .type =3D IIO_INTENSITY, \ + .address =3D _reg, \ + .modified =3D 1, \ + .channel2 =3D IIO_MOD_LIGHT_##_mod, \ + .info_mask_separate =3D \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type =3D \ + BIT(IIO_CHAN_INFO_INT_TIME), \ + .info_mask_shared_by_type_available =3D \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_INT_TIME), \ +} + static const struct iio_chan_spec stk3310_channels[] =3D { STK3310_LIGHT_CHANNEL, STK3310_PROXIMITY_CHANNEL, }; =20 +static const struct iio_chan_spec stk36c61_channels[] =3D { + STK3310_LIGHT_CHANNEL, + STK3310_PROXIMITY_CHANNEL, + STK36C61_INTENSITY_CHANNEL(RED, STK36C61_REG_RED_DATA_MSB), + STK36C61_INTENSITY_CHANNEL(GREEN, STK36C61_REG_GREEN_DATA_MSB), + STK36C61_INTENSITY_CHANNEL(BLUE, STK36C61_REG_BLUE_DATA_MSB), + STK36C61_INTENSITY_CHANNEL(CLEAR, STK36C61_REG_CLEAR_DATA_MSB), +}; + /** * struct stk3310_chip_info - chip-specific data * @name: device name reported to the IIO core @@ -225,6 +260,12 @@ static const struct stk3310_chip_info stk3310_chip_inf= o =3D { .num_channels =3D ARRAY_SIZE(stk3310_channels), }; =20 +static const struct stk3310_chip_info stk36c61_chip_info =3D { + .name =3D "stk36c61", + .channels =3D stk36c61_channels, + .num_channels =3D ARRAY_SIZE(stk36c61_channels), +}; + static IIO_CONST_ATTR(in_illuminance_scale_available, STK3310_SCALE_AVAILA= BLE); =20 static IIO_CONST_ATTR(in_proximity_scale_available, STK3310_SCALE_AVAILABL= E); @@ -401,7 +442,8 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, struct i2c_client *client =3D data->client; struct regmap *map =3D data->regmap; =20 - if (chan->type !=3D IIO_LIGHT && chan->type !=3D IIO_PROXIMITY) + if (chan->type !=3D IIO_LIGHT && chan->type !=3D IIO_PROXIMITY && + chan->type !=3D IIO_INTENSITY) return -EINVAL; =20 switch (mask) { @@ -417,10 +459,10 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); return IIO_VAL_INT; case IIO_CHAN_INFO_INT_TIME: - if (chan->type =3D=3D IIO_LIGHT) - ret =3D regmap_field_read(data->reg_als_it, &index); - else + if (chan->type =3D=3D IIO_PROXIMITY) ret =3D regmap_field_read(data->reg_ps_it, &index); + else + ret =3D regmap_field_read(data->reg_als_it, &index); if (ret < 0) return ret; =20 @@ -428,10 +470,12 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, *val2 =3D stk3310_it_table[index][1]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SCALE: - if (chan->type =3D=3D IIO_LIGHT) - ret =3D regmap_field_read(data->reg_als_gain, &index); - else + if (chan->type =3D=3D IIO_PROXIMITY) ret =3D regmap_field_read(data->reg_ps_gain, &index); + else if (chan->channel2 =3D=3D IIO_MOD_LIGHT_CLEAR) + ret =3D regmap_field_read(data->reg_clear_gain, &index); + else + ret =3D regmap_field_read(data->reg_als_gain, &index); if (ret < 0) return ret; =20 @@ -451,7 +495,8 @@ static int stk3310_write_raw(struct iio_dev *indio_dev, int index; struct stk3310_data *data =3D iio_priv(indio_dev); =20 - if (chan->type !=3D IIO_LIGHT && chan->type !=3D IIO_PROXIMITY) + if (chan->type !=3D IIO_LIGHT && chan->type !=3D IIO_PROXIMITY && + chan->type !=3D IIO_INTENSITY) return -EINVAL; =20 switch (mask) { @@ -462,10 +507,10 @@ static int stk3310_write_raw(struct iio_dev *indio_de= v, if (index < 0) return -EINVAL; mutex_lock(&data->lock); - if (chan->type =3D=3D IIO_LIGHT) - ret =3D regmap_field_write(data->reg_als_it, index); - else + if (chan->type =3D=3D IIO_PROXIMITY) ret =3D regmap_field_write(data->reg_ps_it, index); + else + ret =3D regmap_field_write(data->reg_als_it, index); if (ret < 0) dev_err(&data->client->dev, "sensor configuration failed\n"); @@ -479,10 +524,12 @@ static int stk3310_write_raw(struct iio_dev *indio_de= v, if (index < 0) return -EINVAL; mutex_lock(&data->lock); - if (chan->type =3D=3D IIO_LIGHT) - ret =3D regmap_field_write(data->reg_als_gain, index); - else + if (chan->type =3D=3D IIO_PROXIMITY) ret =3D regmap_field_write(data->reg_ps_gain, index); + else if (chan->channel2 =3D=3D IIO_MOD_LIGHT_CLEAR) + ret =3D regmap_field_write(data->reg_clear_gain, index); + else + ret =3D regmap_field_write(data->reg_als_gain, index); if (ret < 0) dev_err(&data->client->dev, "sensor configuration failed\n"); @@ -493,9 +540,31 @@ static int stk3310_write_raw(struct iio_dev *indio_dev, return -EINVAL; } =20 +static int stk3310_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals =3D (const int *)stk3310_scale_table; + *length =3D 2 * ARRAY_SIZE(stk3310_scale_table); + *type =3D IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_INT_TIME: + *vals =3D (const int *)stk3310_it_table; + *length =3D 2 * ARRAY_SIZE(stk3310_it_table); + *type =3D IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static const struct iio_info stk3310_info =3D { .read_raw =3D stk3310_read_raw, .write_raw =3D stk3310_write_raw, + .read_avail =3D stk3310_read_avail, .attrs =3D &stk3310_attribute_group, .read_event_value =3D stk3310_read_event, .write_event_value =3D stk3310_write_event, @@ -567,6 +636,7 @@ static bool stk3310_is_volatile_reg(struct device *dev,= unsigned int reg) switch (reg) { case STK3310_REG_ALS_DATA_MSB: case STK3310_REG_ALS_DATA_LSB: + case STK36C61_REG_RED_DATA_MSB ... STK36C61_REG_CLEAR_DATA_LSB: case STK3310_REG_PS_DATA_LSB: case STK3310_REG_PS_DATA_MSB: case STK3310_REG_FLAG: @@ -601,6 +671,7 @@ static int stk3310_regmap_init(struct stk3310_data *dat= a) STK3310_REGFIELD(state); STK3310_REGFIELD(als_gain); STK3310_REGFIELD(ps_gain); + STK3310_REGFIELD(clear_gain); STK3310_REGFIELD(als_it); STK3310_REGFIELD(ps_it); STK3310_REGFIELD(int_ps); @@ -795,6 +866,7 @@ static const struct i2c_device_id stk3310_i2c_id[] =3D { { .name =3D "stk3310", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, { .name =3D "stk3311", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, { .name =3D "stk3335", .driver_data =3D (kernel_ulong_t)&stk3310_chip_inf= o }, + { .name =3D "stk36c61", .driver_data =3D (kernel_ulong_t)&stk36c61_chip_i= nfo }, { } }; MODULE_DEVICE_TABLE(i2c, stk3310_i2c_id); @@ -812,6 +884,7 @@ static const struct of_device_id stk3310_of_match[] =3D= { { .compatible =3D "sensortek,stk3310", .data =3D &stk3310_chip_info }, { .compatible =3D "sensortek,stk3311", .data =3D &stk3310_chip_info }, { .compatible =3D "sensortek,stk3335", .data =3D &stk3310_chip_info }, + { .compatible =3D "sensortek,stk36c61", .data =3D &stk36c61_chip_info }, { } }; MODULE_DEVICE_TABLE(of, stk3310_of_match); --=20 2.55.0