From patchwork Wed Jan 3 12:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13509961 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 BA4AA18EB2; Wed, 3 Jan 2024 12:09:08 +0000 (UTC) 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="GNFPcH8B" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-336746c7b6dso9340934f8f.0; Wed, 03 Jan 2024 04:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704283746; x=1704888546; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3HxXaZqQGOpnmGmdiVei4YbOtWHqTHWlxdX/eXyYuxA=; b=GNFPcH8BNsh6qFKL898Mauk4dd/btqNl4RtnxI/lfoFP2t9/tOrn/UquHphO1f5is/ qp/VXuYVogvUR1FWhI3LRr3izo9+xOhwo//xpoc0lNWf+NweZnkHJZW32ipoEfkX7l2n rleTeQ2RBDXedRjFMHzVj/JuJVbJLfqBCfcJ4hStkMcod45kLDWpi+EVk7sUbSPEl6wX e5csqD0ZpYd0hr1OazEiPRtRXJpOrYrIOLnx5b+Fg+hDaK5srSF4MfoIYL9el8FyVlRC kbG5btGkrDrwCDhjFNLdmm2CTleIVx9MTJ9N//WJ6QQhfZvn4PHP9YMmid2eNgK/F+T2 jZRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704283746; x=1704888546; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3HxXaZqQGOpnmGmdiVei4YbOtWHqTHWlxdX/eXyYuxA=; b=rlUvjBt9gOYVnVH41t3NXGVDJcte5vznjwzUuRw2NRsRS8xUyDaHv/E9EaUjmooYgk AQWR7mTRm3D4aiBXMcOpYjQUd2LW58nRiMugPRw8xeUOGDV0uzAYFtGDr8aPB+I3rnkc GbLlPvT2KjL0Yqb6HYqxiSLIxWLebpAbPxQqfOZgHezquIR+rT0YUwlWLqVN1fXNgVHL /17EFQOFRRJ7yolxPtbg/7XIsdv75GVSTuqiopzBiWGuCD6i8SiG2FmWBmxLryhGeG1G J4acpej2fzzgsjLVIksjrXXxr3OwEtGZ1ebpQ7jKsAcmTA2BieCwuG0AU7xvHza1pFDa qtQg== X-Gm-Message-State: AOJu0YyXVVrknZACcqJ9VlC8ri/bK9bwVcvtulCk2bgfm+DAZpr5AG9G YDNnLDzOFqMoerM+NeqNAFjuhJjRbHOgCQSO X-Google-Smtp-Source: AGHT+IG3GBletUEOZZSx/cadwXeccfqkXB012KQgAmdGLTcifJ3I1z/PUCovcZs7LJunQYqZde5REg== X-Received: by 2002:a05:600c:ad3:b0:40d:80a2:d21b with SMTP id c19-20020a05600c0ad300b0040d80a2d21bmr3288057wmr.151.1704283746247; Wed, 03 Jan 2024 04:09:06 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-1a90-a88c-d3fe-4285.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:1a90:a88c:d3fe:4285]) by smtp.gmail.com with ESMTPSA id o28-20020a05600c511c00b0040b37f1079dsm2106443wms.29.2024.01.03.04.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:09:05 -0800 (PST) From: Javier Carrasco Date: Wed, 03 Jan 2024 13:08:51 +0100 Subject: [PATCH v2 1/3] iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-as7331-v2-1-6f0ad05e0482@gmail.com> References: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> In-Reply-To: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> To: Christian Eggers , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704283743; l=1689; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=1MU3giKWl0gPRroVrrkRwqryd8WZu7+Nv1DcBdlcyYE=; b=wYfGApcioFFsmZe4cBgXSFsR2MKOE6mwqP/rJLgi01qhG8GRJz6KyvTv1RXbwZN7T0KbxxdBR GinIZpVOOv5DpscHaAI1N1nl2j0EdCPbPdxI302hH5sWevexjpUTz1e X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= The scale values associated to the light channels are calculated as a division that can be better expressed as an IIO_VAL_FRACTIONAL type instead of the current IIO_VAL_INT. Note that the constant values used for the calculation were scaled up to work with integers, turning the nW/cm^2 units from the datasheet into nW/m^2, which would not be necessary with the IIO_VAL_FRACTIONAL type. But to avoid issues from current users of the driver, the units must be kept. Signed-off-by: Javier Carrasco --- drivers/iio/light/as73211.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c index ec97a3a46839..b4c6f389a292 100644 --- a/drivers/iio/light/as73211.c +++ b/drivers/iio/light/as73211.c @@ -356,25 +356,24 @@ static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec cons return IIO_VAL_INT_PLUS_MICRO; case IIO_INTENSITY: { - unsigned int scale; switch (chan->channel2) { case IIO_MOD_X: - scale = AS73211_SCALE_X; + *val = AS73211_SCALE_X; break; case IIO_MOD_Y: - scale = AS73211_SCALE_Y; + *val = AS73211_SCALE_Y; break; case IIO_MOD_Z: - scale = AS73211_SCALE_Z; + *val = AS73211_SCALE_Z; break; default: return -EINVAL; } - scale /= as73211_gain(data); - scale /= as73211_integration_time_1024cyc(data); - *val = scale; - return IIO_VAL_INT; + *val2 = as73211_integration_time_1024cyc(data) * + as73211_gain(data); + + return IIO_VAL_FRACTIONAL; default: return -EINVAL; From patchwork Wed Jan 3 12:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13509963 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 D32E618EC9; Wed, 3 Jan 2024 12:09:09 +0000 (UTC) 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="WxnDUHJv" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-40d76923ec4so41850975e9.3; Wed, 03 Jan 2024 04:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704283747; x=1704888547; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4WYvQJBKPTze3DHEG/ddyiPavhb8SAmoWAb8gifhRQs=; b=WxnDUHJvRqBSaV6pjQ9sBK61Qf7uoakgGDCkgErPcObbaRJGj7OFlEOMrwe7uF478A YO1LcEAYKJwAuFF4eCTBcu+H1Tru4PNgscWJ+jXlO5Yeter2wx9f4L+YI1iyY4cVPtJ8 jJi0XWtG0nm7K857mh4aUUnKPyFDyu/KqwhbDXoBBWD3KuWgAJnUvGbnc40o1mZ1b0oL Icu3ZOKFDHTsSRDSyQMOpQdgfhZW9wL0ZoBzJbBxCmknxyFzENOOGoYz4jHInB+5uBkW VGpGmugtLr/iMHX7BjXSWpDfSOTscRbl48x15EhALobVab+XrGtIYBA34F9Q7FKEjGem uLrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704283747; x=1704888547; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4WYvQJBKPTze3DHEG/ddyiPavhb8SAmoWAb8gifhRQs=; b=hkuqGFR4CCorRa8YM2jzQrpGVo2WeTKsleFCPGpJ/3DIBIM5JQM9WfLLp+1ypEzAb2 GYJgY/7trfVcVtnLTFgPniXA7DCr35WVbyjuoGcHKjp47PA/+rqf10caB4lxgf0hUU/y K2gCDxq2DwkCn7GaV0nUI3vWA6PEOb6sTOa/AMTAaABIaSwql4fXUSos0UY6BdEPk4V8 II7qgBVOcWlpuklOuz3K6PpMWXitIcvlp5ubo0pcRQLbpAhs3pTKymZ6vdrU/2QCkN8s w9izzASQtRa0TCRBfiFy3oEel7xMskxPJgxmeIJG8STL7UWNTCQtaFvQvGzXN6V/Spjt LrUA== X-Gm-Message-State: AOJu0Yzpeq7LUQl5KJJxv9GJBptBWfj3Bsgk1wGHmerygOSwxdGUvvto lPT0S5eWK2RtSo2RDHY71YeyWAdUjFfDsXAG X-Google-Smtp-Source: AGHT+IE/nUm5+KwneTEnHsQrqVQ+yStInen24AvslGTUMTC+s0cqfocye0aOigqpWo0TeoX/GidK5g== X-Received: by 2002:a1c:6a04:0:b0:40d:6032:fa8b with SMTP id f4-20020a1c6a04000000b0040d6032fa8bmr5099308wmc.72.1704283747584; Wed, 03 Jan 2024 04:09:07 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-1a90-a88c-d3fe-4285.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:1a90:a88c:d3fe:4285]) by smtp.gmail.com with ESMTPSA id o28-20020a05600c511c00b0040b37f1079dsm2106443wms.29.2024.01.03.04.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:09:07 -0800 (PST) From: Javier Carrasco Date: Wed, 03 Jan 2024 13:08:52 +0100 Subject: [PATCH v2 2/3] dt-bindings: iio: light: as73211: add support for as7331 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-as7331-v2-2-6f0ad05e0482@gmail.com> References: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> In-Reply-To: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> To: Christian Eggers , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco , Conor Dooley X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704283743; l=1584; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=EVcVlVkKVxVo7dqyNLXpMvZHU1y8Zir+Ulin1WweGiY=; b=BOyh1NHjmxJqR1GjgOUOH45Sy+y6lMzcPBfOwYbufIf45EYuzl/tzUKyp3FhoXWCnE/1L9p01 AuWZq1uFVMOA36b2NTRvxVroYGb2HAfDl9haHVVmXOW9Cs3U4a01+Qm X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= This device has the same properties and I2C addresses as the as73211. The only difference between them is the photodiodes they use internally, which in this case is irrelevant for the bindings. Acked-by: Conor Dooley Signed-off-by: Javier Carrasco --- Documentation/devicetree/bindings/iio/light/ams,as73211.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml b/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml index 0e8cd02759b3..062a038aa0ff 100644 --- a/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml +++ b/Documentation/devicetree/bindings/iio/light/ams,as73211.yaml @@ -4,19 +4,22 @@ $id: http://devicetree.org/schemas/iio/light/ams,as73211.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: AMS AS73211 JENCOLOR(R) Digital XYZ Sensor +title: AMS AS73211 JENCOLOR(R) Digital XYZ Sensor and AMS AS7331 UV Sensor maintainers: - Christian Eggers description: | - XYZ True Color Sensor with I2C Interface + AMS AS73211 XYZ True Color Sensor with I2C Interface https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf/a65474c0-b302-c2fd-e30a-c98df87616df + AMS AS7331 UVA, UVB and UVC Sensor with I2C Interface + https://ams.com/documents/20143/9106314/AS7331_DS001047_4-00.pdf properties: compatible: enum: - ams,as73211 + - ams,as7331 reg: description: From patchwork Wed Jan 3 12:08:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13509962 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 0CC0E19456; Wed, 3 Jan 2024 12:09:10 +0000 (UTC) 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="hEk0Oag4" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40d3352b525so113804175e9.1; Wed, 03 Jan 2024 04:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704283749; x=1704888549; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mQ7sYvZt+Hf2d2qr73Yb6Uv+J9M3D9ss9N8ljtt/mVM=; b=hEk0Oag4LYpOyuOA3Qg9U2jq2kdmta+aQLWmDPb3yvKRN/5V8L26Z4MRa9RJfS70UE RyQMwg7kJFLsIy6wZW5Uz0tq9acWqYTQ9GH75rPp/Wr7ZvRhjJcRcSmpypk2+syxrlG7 M5fwzwvBh1QdbUM436K6ivyHiKXD22Szyx/x35XD5KzYOhuXha0g5uaJqPEx99g/xfWW m8rNpoH/StSJHgjk1mr/izA5me1fG9cTUUNB1k9X72UuqhzvgjR1LOUuCOdeIj/iV1qR 8as0yBdFJATejfvsNt5yafKOGxpdSurmE0xUhgqC4/v8o61AT5sWXoQmS+ho1od9FJ6v WWMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704283749; x=1704888549; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mQ7sYvZt+Hf2d2qr73Yb6Uv+J9M3D9ss9N8ljtt/mVM=; b=KdGVpG2M/Q/gfJG36imtf73d9h1tvbdY8YwgCpuwM/scYQ4h+oduKmlvNM2A9wljf9 EUIF45DrAmfC6oK21i4n6b8ODRJvUDRu5HLOjsAUS6F5Ibrme+QEbLkTgKxQUjtWAdyw 65rx3MBy0wusPA7M71HjL7bieaDJh3cF/wS7ecPTtcNcdmcvASxn3Mz5aTuWZDmuSLDJ mdoyLYehiNl1Gyf9cdFhIZ+sZrw0tfGI8v1hGpYEVpuVNzE371yWv6u0TpP/clwEQy5G PdPORrABgphXFid84WgkFZyMecNOV7j8l2DtMR1zRwWoYON5v5qCtLrnTC7ingkybFLE m9kQ== X-Gm-Message-State: AOJu0Yw3/nhhycv0rCylJYLuUg0SJP/sSOnnS9TeOL3WwnyRUnLMm4H3 MJl9EnDTDjrS+ApcDOhD9lq0WORL+B8Cwwd2 X-Google-Smtp-Source: AGHT+IFZnKN+CxFoHVbo18LPs+6QA5wqNG75V6dA+/qhvPjlY3lU4zQBH0faDrcAdWpbwx6vSl7cBA== X-Received: by 2002:a05:600c:3115:b0:40d:8919:d1df with SMTP id g21-20020a05600c311500b0040d8919d1dfmr2111442wmo.163.1704283748824; Wed, 03 Jan 2024 04:09:08 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-1a90-a88c-d3fe-4285.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:1a90:a88c:d3fe:4285]) by smtp.gmail.com with ESMTPSA id o28-20020a05600c511c00b0040b37f1079dsm2106443wms.29.2024.01.03.04.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 04:09:08 -0800 (PST) From: Javier Carrasco Date: Wed, 03 Jan 2024 13:08:53 +0100 Subject: [PATCH v2 3/3] iio: light: as73211: add support for as7331 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-as7331-v2-3-6f0ad05e0482@gmail.com> References: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> In-Reply-To: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com> To: Christian Eggers , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704283743; l=9566; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=C+/+kQ2C27ds2UC68SS96vr1DGcfshe3A9AsxHtV6EI=; b=8VybhJeoxFmQMEye7wYzm6Xtg9CnjnCLtkEor8oxCKcfT6tEcKrpgib3sXAMxVnC+bkpdIaI7 OrqV8cmMlZ3CWKoGnX5cTmPm/jD4Qrkrg0ykDmt1Hg29xOiqGnQPqUJ X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= The AMS AS7331 is a UV light sensor with three channels: UVA, UVB and UVC (also known as deep UV and referenced as DUV in the iio core). Its internal structure and forming blocks are practically identical to the ones the AS73211 contains: API, internal DAC, I2C interface and registers, measurement modes, number of channels and pinout. The only difference between them is the photodiodes used to acquire light, which means that only some modifications are required to add support for the AS7331 in the existing driver. The temperature channel is identical for both devices and only the channel modifiers of the IIO_INTENSITY channels need to account for the device type. The scale values have been obtained from the chapter "7.5 Transfer Function" of the official datasheet[1] for the configuration chosen as basis (Nclk = 1024 and GAIN = 1). Those values keep the units from the datasheet (nW/cm^2), as opposed to the units used for the AS73211 (nW/m^2). Add a new device-specific data structure to account for the device differences: channel types and scale of LSB per channel. [1] https://ams.com/documents/20143/9106314/AS7331_DS001047_4-00.pdf Tested-by: Christian Eggers Signed-off-by: Javier Carrasco Tested-by: Christian Eggers --- drivers/iio/light/Kconfig | 5 +- drivers/iio/light/as73211.c | 141 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 118 insertions(+), 28 deletions(-) diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 143003232d1c..fd5a9879a582 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -87,13 +87,14 @@ config APDS9960 module will be called apds9960 config AS73211 - tristate "AMS AS73211 XYZ color sensor" + tristate "AMS AS73211 XYZ color sensor and AMS AS7331 UV sensor" depends on I2C select IIO_BUFFER select IIO_TRIGGERED_BUFFER help If you say yes here you get support for the AMS AS73211 - JENCOLOR(R) Digital XYZ Sensor. + JENCOLOR(R) Digital XYZ and the AMS AS7331 UVA, UVB and UVC + ultraviolet sensors. For triggered measurements, you will need an additional trigger driver like IIO_HRTIMER_TRIGGER or IIO_SYSFS_TRIGGER. diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c index b4c6f389a292..44daf816ae57 100644 --- a/drivers/iio/light/as73211.c +++ b/drivers/iio/light/as73211.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Support for AMS AS73211 JENCOLOR(R) Digital XYZ Sensor + * Support for AMS AS73211 JENCOLOR(R) Digital XYZ Sensor and AMS AS7331 + * UVA, UVB and UVC (DUV) Ultraviolet Sensor * * Author: Christian Eggers * @@ -9,7 +10,9 @@ * Color light sensor with 16-bit channels for x, y, z and temperature); * 7-bit I2C slave address 0x74 .. 0x77. * - * Datasheet: https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf + * Datasheets: + * AS73211: https://ams.com/documents/20143/36005/AS73211_DS000556_3-01.pdf + * AS7331: https://ams.com/documents/20143/9106314/AS7331_DS001047_4-00.pdf */ #include @@ -84,6 +87,20 @@ static const int as73211_hardwaregain_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, }; +struct as73211_data; + +/** + * struct spec_dev_data - device-specific data + * @intensity_scale: Function to retrieve intensity scale values. + * @channel: Device channels. + * @num_channels: Number of channels of the device. + */ +struct spec_dev_data { + int (*intensity_scale)(struct as73211_data *data, int chan, int *val, int *val2); + struct iio_chan_spec const *channel; + int num_channels; +}; + /** * struct as73211_data - Instance data for one AS73211 * @client: I2C client. @@ -94,6 +111,7 @@ static const int as73211_hardwaregain_avail[] = { * @mutex: Keeps cached registers in sync with the device. * @completion: Completion to wait for interrupt. * @int_time_avail: Available integration times (depend on sampling frequency). + * @spec_dev: device-specific configuration. */ struct as73211_data { struct i2c_client *client; @@ -104,6 +122,7 @@ struct as73211_data { struct mutex mutex; struct completion completion; int int_time_avail[AS73211_SAMPLE_TIME_NUM * 2]; + const struct spec_dev_data *spec_dev; }; #define AS73211_COLOR_CHANNEL(_color, _si, _addr) { \ @@ -138,6 +157,10 @@ struct as73211_data { #define AS73211_SCALE_Y 298384270 /* nW/m^2 */ #define AS73211_SCALE_Z 160241927 /* nW/m^2 */ +#define AS7331_SCALE_UVA 340000 /* nW/cm^2 */ +#define AS7331_SCALE_UVB 378000 /* nW/cm^2 */ +#define AS7331_SCALE_UVC 166000 /* nW/cm^2 */ + /* Channel order MUST match devices result register order */ #define AS73211_SCAN_INDEX_TEMP 0 #define AS73211_SCAN_INDEX_X 1 @@ -176,6 +199,28 @@ static const struct iio_chan_spec as73211_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(AS73211_SCAN_INDEX_TS), }; +static const struct iio_chan_spec as7331_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_OFFSET) | + BIT(IIO_CHAN_INFO_SCALE), + .address = AS73211_OUT_TEMP, + .scan_index = AS73211_SCAN_INDEX_TEMP, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_LE, + } + }, + AS73211_COLOR_CHANNEL(LIGHT_UVA, AS73211_SCAN_INDEX_X, AS73211_OUT_MRES1), + AS73211_COLOR_CHANNEL(LIGHT_UVB, AS73211_SCAN_INDEX_Y, AS73211_OUT_MRES2), + AS73211_COLOR_CHANNEL(LIGHT_DUV, AS73211_SCAN_INDEX_Z, AS73211_OUT_MRES3), + IIO_CHAN_SOFT_TIMESTAMP(AS73211_SCAN_INDEX_TS), +}; + static unsigned int as73211_integration_time_1024cyc(struct as73211_data *data) { /* @@ -316,6 +361,48 @@ static int as73211_req_data(struct as73211_data *data) return 0; } +static int as73211_intensity_scale(struct as73211_data *data, int chan, + int *val, int *val2) +{ + switch (chan) { + case IIO_MOD_X: + *val = AS73211_SCALE_X; + break; + case IIO_MOD_Y: + *val = AS73211_SCALE_Y; + break; + case IIO_MOD_Z: + *val = AS73211_SCALE_Z; + break; + default: + return -EINVAL; + } + *val2 = as73211_integration_time_1024cyc(data) * as73211_gain(data); + + return IIO_VAL_FRACTIONAL; +} + +static int as7331_intensity_scale(struct as73211_data *data, int chan, + int *val, int *val2) +{ + switch (chan) { + case IIO_MOD_LIGHT_UVA: + *val = AS7331_SCALE_UVA; + break; + case IIO_MOD_LIGHT_UVB: + *val = AS7331_SCALE_UVB; + break; + case IIO_MOD_LIGHT_DUV: + *val = AS7331_SCALE_UVC; + break; + default: + return -EINVAL; + } + *val2 = as73211_integration_time_1024cyc(data) * as73211_gain(data); + + return IIO_VAL_FRACTIONAL; +} + static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { @@ -355,29 +442,13 @@ static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec cons *val2 = AS73211_SCALE_TEMP_MICRO; return IIO_VAL_INT_PLUS_MICRO; - case IIO_INTENSITY: { - - switch (chan->channel2) { - case IIO_MOD_X: - *val = AS73211_SCALE_X; - break; - case IIO_MOD_Y: - *val = AS73211_SCALE_Y; - break; - case IIO_MOD_Z: - *val = AS73211_SCALE_Z; - break; - default: - return -EINVAL; - } - *val2 = as73211_integration_time_1024cyc(data) * - as73211_gain(data); - - return IIO_VAL_FRACTIONAL; + case IIO_INTENSITY: + return data->spec_dev->intensity_scale(data, chan->channel2, + val, val2); default: return -EINVAL; - }} + } case IIO_CHAN_INFO_SAMP_FREQ: /* f_samp is configured in CREG3 in powers of 2 (x 1.024 MHz) */ @@ -675,13 +746,17 @@ static int as73211_probe(struct i2c_client *client) i2c_set_clientdata(client, indio_dev); data->client = client; + data->spec_dev = i2c_get_match_data(client); + if (!data->spec_dev) + return -EINVAL; + mutex_init(&data->mutex); init_completion(&data->completion); indio_dev->info = &as73211_info; indio_dev->name = AS73211_DRV_NAME; - indio_dev->channels = as73211_channels; - indio_dev->num_channels = ARRAY_SIZE(as73211_channels); + indio_dev->channels = data->spec_dev->channel; + indio_dev->num_channels = data->spec_dev->num_channels; indio_dev->modes = INDIO_DIRECT_MODE; ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR); @@ -771,14 +846,28 @@ static int as73211_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(as73211_pm_ops, as73211_suspend, as73211_resume); +static const struct spec_dev_data as73211_spec = { + .intensity_scale = as73211_intensity_scale, + .channel = as73211_channels, + .num_channels = ARRAY_SIZE(as73211_channels), +}; + +static const struct spec_dev_data as7331_spec = { + .intensity_scale = as7331_intensity_scale, + .channel = as7331_channels, + .num_channels = ARRAY_SIZE(as7331_channels), +}; + static const struct of_device_id as73211_of_match[] = { - { .compatible = "ams,as73211" }, + { .compatible = "ams,as73211", &as73211_spec }, + { .compatible = "ams,as7331", &as7331_spec }, { } }; MODULE_DEVICE_TABLE(of, as73211_of_match); static const struct i2c_device_id as73211_id[] = { - { "as73211", 0 }, + { "as73211", (kernel_ulong_t)&as73211_spec }, + { "as7331", (kernel_ulong_t)&as7331_spec }, { } }; MODULE_DEVICE_TABLE(i2c, as73211_id);