From patchwork Fri Dec 15 16:23:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshul Dalal X-Patchwork-Id: 13494649 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 4783B3C062; Fri, 15 Dec 2023 16:25:28 +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="G9yGUt10" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d367e7092eso6697335ad.0; Fri, 15 Dec 2023 08:25:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702657527; x=1703262327; 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=zDqL6HCL3y7lDRDTbr/lo7FN7BFLZEzd5vvB4zRQhig=; b=G9yGUt10KGCg8rj6K/ZU0ApiP+osgxeOhN4TvFD4Eh5biTxkyW+DkaiDBeCtCjY7BH XGrfEwl6jzMXhh+31q7KlP44GTQ+7XPpkFJQCXSk+X3zNAV52/LGOwfwWN1V3Y+cBqnE 5soloRPqKhsf8uPLy2hJx35Bf255cDeugWXYInGqsRaU547vAyx+i5XcrJWvwGSSt8G+ iUQYP35JXAR4FBLdf11Oz3ueb/c9jHla6kD0c8kn5uEvhXP57Yd3taM1vaNkPhVEMp7i zPKLFWwQUXqJK/wuRTFkFk/Q5Fh35fFrcc1IB1OM4//Lx408NHzEGz6MstN1uL9gmpbl bVzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702657527; x=1703262327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zDqL6HCL3y7lDRDTbr/lo7FN7BFLZEzd5vvB4zRQhig=; b=iQAhE9jOLRA5U5HBvUKs9eZ0FF/DA2gyf0w+sduRxFzwaue2OchLvIunjjVUNEbrrQ +83w4V78XNFFp/fCGbx9kxx4vpzXDdPshy4haUn+/rOFRqsfTvRvp8ElKkZ5cvSqIwVT tn0eHckInxhd5B0jyWy6aUfDvtsxNEST6J7nleTiFX6Zo7Kw/VRy8MwVga1cvmZrxzXj rGJJLCEnuWEHiuIIh/21IG4VD2TgoUd02iZuL+BD7VSm92XMP4Xo5tkdr+3qD/KTJbwe 0EQRXuZ3Rx4fcFdAJc18P4u8ZQhGjkwOvZxL3AafvtjNUW6NdSIoWUveIA+Ubm4CkiG2 vDyQ== X-Gm-Message-State: AOJu0YxfGpBC+pR/U6YqcNp9ZVA870MuihT187GgwDPF/V/7rXd3KRkI a3k7lK6vfVzGovz7n+PLutbKJKOGhwzyag== X-Google-Smtp-Source: AGHT+IFUiy1uTHVX+IrL5elmcxSqJ1xdj2AGz7K/ki+zmPEMSFag93XQQOi50O+2ajZwgDl0R2N9zg== X-Received: by 2002:a17:902:b948:b0:1d0:6ffd:e2eb with SMTP id h8-20020a170902b94800b001d06ffde2ebmr10020334pls.133.1702657527290; Fri, 15 Dec 2023 08:25:27 -0800 (PST) Received: from localhost.localdomain ([2401:4900:581e:798e:871c:98db:5638:a4]) by smtp.gmail.com with ESMTPSA id s16-20020a170902989000b001bb750189desm14468665plp.255.2023.12.15.08.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 08:25:26 -0800 (PST) From: Anshul Dalal To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Cc: Anshul Dalal , Conor Dooley , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , linux-kernel-mentees@lists.linuxfoundation.org, Jonathan Cameron , Krzysztof Kozlowski Subject: [PATCH v5 1/3] dt-bindings: vendor-prefixes: add aosong Date: Fri, 15 Dec 2023 21:53:09 +0530 Message-ID: <20231215162312.143568-1-anshulusr@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Aosong Electronic Co., LTD. is a supplier for MEMS sensors such as AHT20 temperature and humidity sensor under the brand name Asair Acked-by: Krzysztof Kozlowski Signed-off-by: Anshul Dalal --- Changes for v5,4,3: - no updates Changes for v2: - Changed vendor prefix from asair to aosong Previous versions: v4: https://lore.kernel.org/lkml/20231125100139.193584-2-anshulusr@gmail.com/ v3: https://lore.kernel.org/lkml/20231121095800.2180870-1-anshulusr@gmail.com/ v2: https://lore.kernel.org/lkml/20231115125810.1394854-1-anshulusr@gmail.com/ v1: https://lore.kernel.org/lkml/20231107173100.62715-1-anshulusr@gmail.com/ --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 573578db9509..48d4ff635562 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -117,6 +117,8 @@ patternProperties: description: Andes Technology Corporation "^anvo,.*": description: Anvo-Systems Dresden GmbH + "^aosong,.*": + description: Guangzhou Aosong Electronic Co., Ltd. "^apm,.*": description: Applied Micro Circuits Corporation (APM) "^apple,.*": From patchwork Fri Dec 15 16:23:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshul Dalal X-Patchwork-Id: 13494650 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 03DE63DB96; Fri, 15 Dec 2023 16:25:32 +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="EB/RBvI3" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d347b4d676so7257595ad.2; Fri, 15 Dec 2023 08:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702657532; x=1703262332; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ggW+Hin3YweLGTCQFbER/wgiOuVUGGluSvES+5w5My4=; b=EB/RBvI3niBcnuZFnpDObHy9NNaQi1L8/PvRR7qAc+9rVKuqUtqlj95zlVANPd1mo6 EAqm2NuI9BMFtBtezkKT48BBzvWQxy7uj9CoZdoANahV7BMtsuNAGPEcIvZwQ+qVQOEj Xh8USftH+dd7QZB6kXASuFaZRL53HGYS3ArEcIbxFcixdcfeTkxrROwNHZfE5nwpLDjw LBr8RnMtkSooEFFxCGh/mck6nkD+xbpkXeA12Td4Or1QoEpe5RD163GmD4b9cf9Vn7zz u6OHta/Sb5f5AT26sVQC1U71ePeu9DVfcXj9L4Jud1gtP0XtRwEmMwgNRNcYAyGspdvo so3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702657532; x=1703262332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ggW+Hin3YweLGTCQFbER/wgiOuVUGGluSvES+5w5My4=; b=F0bBbMFl1RE29KhuNRmMIHqaWMWxVCTnCZ6XUc1mD9lpJS5bVwPi4G0+HfE3JTBpaF JKmSBbLwV+/bTJuprqBn/CQg0pfbiIZVP91pKWCCp5Q3DlkQNz3DV/xdeCv9krbOrBpN yP+VlN4n4VJFInf1Cr38PqQ/rW7Htb+Ij1k620Pj/4SA2qKM4zvDA21E4H0zaL6ofNOU DDeq/ebddm4XI05mSuEAdcu6SZNGHc4HDhLqhqw6sppyZvG/hWplErfwVxTZM3SBQCQB KVn20MZS0l4Auh2mD1aGUq+jPxOxQ2692otCqZtLAzqA2VprWhHcCAqAgj7sbtEuPG1l vK4A== X-Gm-Message-State: AOJu0YzKjoGWLTbDJc3oZirJiXxmz6lD74HF99BvprmR0jWi2jRDHppc 6+GzX7k/6jmmKHFzQjV0XeUY+HzScs49lA== X-Google-Smtp-Source: AGHT+IEZkZrISCa/tBzbEB2K6p4h7wFtOEwKMpl2olxVPhly92wynedxoiejUlKaUpDsKvTYc0YZkw== X-Received: by 2002:a17:903:234c:b0:1d0:c418:1758 with SMTP id c12-20020a170903234c00b001d0c4181758mr14588199plh.66.1702657531891; Fri, 15 Dec 2023 08:25:31 -0800 (PST) Received: from localhost.localdomain ([2401:4900:581e:798e:871c:98db:5638:a4]) by smtp.gmail.com with ESMTPSA id s16-20020a170902989000b001bb750189desm14468665plp.255.2023.12.15.08.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 08:25:31 -0800 (PST) From: Anshul Dalal To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Cc: Anshul Dalal , Conor Dooley , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , linux-kernel-mentees@lists.linuxfoundation.org, Jonathan Cameron , Krzysztof Kozlowski Subject: [PATCH v5 2/3] dt-bindings: iio: chemical: add aosong,ags02ma Date: Fri, 15 Dec 2023 21:53:10 +0530 Message-ID: <20231215162312.143568-2-anshulusr@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215162312.143568-1-anshulusr@gmail.com> References: <20231215162312.143568-1-anshulusr@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add bindings for Aosong AGS02MA TVOC sensor. The sensor communicates over i2c with the default address 0x1a. TVOC values can be read in the units of ppb and ug/m^3 at register 0x00. Datasheet: https://asairsensors.com/wp-content/uploads/2021/09/AGS02MA.pdf Reviewed-by: Krzysztof Kozlowski Signed-off-by: Anshul Dalal --- Changes for v5: - Made vdd-supply a required property Changes for v4: - Changed node name from 'light-sensor' to 'voc-sensor' Changes for v3: - Fixed commit message - Removed "asair,ags02ma" compatible Changes for v2: - Removed device from trivial-devices - Added standalone binding with vdd-supply property Previous versions: v4: https://lore.kernel.org/lkml/20231125100139.193584-2-anshulusr@gmail.com/ v3: https://lore.kernel.org/lkml/20231121095800.2180870-2-anshulusr@gmail.com/ v2: https://lore.kernel.org/lkml/20231115125810.1394854-2-anshulusr@gmail.com/ v1: https://lore.kernel.org/lkml/20231107173100.62715-2-anshulusr@gmail.com/ --- .../bindings/iio/chemical/aosong,ags02ma.yaml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/aosong,ags02ma.yaml diff --git a/Documentation/devicetree/bindings/iio/chemical/aosong,ags02ma.yaml b/Documentation/devicetree/bindings/iio/chemical/aosong,ags02ma.yaml new file mode 100644 index 000000000000..35e7b094e878 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/aosong,ags02ma.yaml @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/aosong,ags02ma.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Aosong AGS02MA VOC Sensor + +description: | + AGS02MA is an TVOC (Total Volatile Organic Compounds) i2c sensor with default + address of 0x1a. + + Datasheet: + https://asairsensors.com/wp-content/uploads/2021/09/AGS02MA.pdf + +maintainers: + - Anshul Dalal + +properties: + compatible: + enum: + - aosong,ags02ma + + reg: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + voc-sensor@1a { + compatible = "aosong,ags02ma"; + reg = <0x1a>; + vdd-supply = <&vdd_regulator>; + }; + }; From patchwork Fri Dec 15 16:23:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshul Dalal X-Patchwork-Id: 13494651 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 50D663DBBB; Fri, 15 Dec 2023 16:25:37 +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="g6U8BoVo" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d05199f34dso3951965ad.3; Fri, 15 Dec 2023 08:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702657536; x=1703262336; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=42Ib9M9xg38B/QbmBOXK61x/WxHHrbWgabum0nBmkMI=; b=g6U8BoVosgfg/zWkq+TlyvMfBTes+irlvSMtE3CQmOADsxE2pPrY4RQ4qjS1i0kghG mJ5r4604zuZajL1TvlQXwWRptzZc25RDWE/VrLf89hNeAPFk0+ZTuHCfkWDaO8jyGI3+ fb/qUDAXPaP+F+FgEB28bdtg/qj6rLLha9HY7FOuZO5G/u3HGv7XW11TrCdwqauqG07H 9EyYmugqVKw9X0pxqkFyTZo8x/pfMfr5tAroexdfemnZ+3jv1+qWKoMkkNPcYaFRRO7s Nj02Jjv3qmHXx+0oGquuIVmNl2A2Z55ZWnDGV2mBknWRIBfR2EvET7SOKjPF/fsoUfon mqAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702657536; x=1703262336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=42Ib9M9xg38B/QbmBOXK61x/WxHHrbWgabum0nBmkMI=; b=dGYqFwLh30oQd222gvi7TCSbkQeT4COrD/Wf/Vz8czWuXDbtEbkL0hIKz0eJhp7WOU JuuwC5N6X/idZIwizXpgEM/2khF5a00SFswCSjq9ih9Yjd5kkcy3Ny1Hb/ypS5pSO+IP inZL/5CIT5/7iKeigyRBHiB/dDy7GXkkB+PS44e+P9jApeh/YVeA3afgLSPG7NideFRO cDB+te7yE9ymkDl2lXQE3SCnQ6cBF/pVgDs9BPWf+LOr1B/P9ou4i31NAIJNQ3/eqnd7 UNlHIwx8LqHxY/qgX5gBE3/DZz89/RJTsJ58T5RKHxokmMD8MBktxX2mTvvL7pYntuEL Hvbw== X-Gm-Message-State: AOJu0YyjihgLK/z/iBAvy/VQqGLEX1rq81vgqk56DaigAFUQ9eWdlUEq Bv0arVK+/FnrxT9G81jow+czK1N1hKNrag== X-Google-Smtp-Source: AGHT+IHAzlqLfSUjVD+t87pazfdcFu3bvkezL0AmisAGvfMeWZ/R/akVDuZqnZyyhmt5R+6mI2CA/Q== X-Received: by 2002:a17:902:9893:b0:1d3:7c16:91d6 with SMTP id s19-20020a170902989300b001d37c1691d6mr1267651plp.115.1702657536101; Fri, 15 Dec 2023 08:25:36 -0800 (PST) Received: from localhost.localdomain ([2401:4900:581e:798e:871c:98db:5638:a4]) by smtp.gmail.com with ESMTPSA id s16-20020a170902989000b001bb750189desm14468665plp.255.2023.12.15.08.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 08:25:35 -0800 (PST) From: Anshul Dalal To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org Cc: Anshul Dalal , Conor Dooley , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , linux-kernel-mentees@lists.linuxfoundation.org, Jonathan Cameron Subject: [PATCH v5 3/3] iio: chemical: add support for Aosong AGS02MA Date: Fri, 15 Dec 2023 21:53:11 +0530 Message-ID: <20231215162312.143568-3-anshulusr@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215162312.143568-1-anshulusr@gmail.com> References: <20231215162312.143568-1-anshulusr@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A simple driver for the TVOC (Total Volatile Organic Compounds) sensor from Aosong: AGS02MA Steps in reading the VOC sensor value over i2c: 1. Read 5 bytes from the register `AGS02MA_TVOC_READ_REG` [0x00] 2. The first 4 bytes are taken as the big endian sensor data with final byte being the CRC 3. The CRC is verified and the value is returned over an `IIO_CHAN_INFO_RAW` channel as percents Tested on Raspberry Pi Zero 2W Datasheet: https://asairsensors.com/wp-content/uploads/2021/09/AGS02MA.pdf Signed-off-by: Anshul Dalal --- Changes for v5: - Removed AGS02MA_DEVICE_NAME define - Saperated return value from data in `ags02ma_register_read` - Added IIO_CHAN_INFO_SCALE for ppb to percent conversion - Changed `ags02ma_channels` (iio_chan_spec[1]) to `ags02ma_channel` (iio_chan_spec) since only driver only uses a single channel - Use `dev_err_probe` instead of `dev_err` - removed unnecessary `i2c_set_clientdata(..)` - Removed `of_match_ptr(..)` Changes for v4: - Fixed warning: unused variable 'ags02ma_of_table' - Fixed warning: unsigned 'ret' is never less than zero in `ags02ma_register_read` Changes for v3: - Added of_device_id Changes for v2: - Fixed Kconfig not selecting CRC8 (used to be `select crc8`) - Changed instances of asair to aosong - Report raw readings in percents instead of ppb - Added myself as maintainer for the device binding Previous versions: v4: https://lore.kernel.org/lkml/20231125100139.193584-3-anshulusr@gmail.com/ v3: https://lore.kernel.org/lkml/20231121095800.2180870-3-anshulusr@gmail.com/ v2: https://lore.kernel.org/lkml/20231115125810.1394854-3-anshulusr@gmail.com/ v1: https://lore.kernel.org/lkml/20231107173100.62715-3-anshulusr@gmail.com/ --- MAINTAINERS | 7 ++ drivers/iio/chemical/Kconfig | 11 +++ drivers/iio/chemical/Makefile | 1 + drivers/iio/chemical/ags02ma.c | 164 +++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 drivers/iio/chemical/ags02ma.c diff --git a/MAINTAINERS b/MAINTAINERS index 81d5fc0bba68..ba3c950aca1b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3028,6 +3028,13 @@ S: Supported W: http://www.akm.com/ F: drivers/iio/magnetometer/ak8974.c +AOSONG AGS02MA TVOC SENSOR DRIVER +M: Anshul Dalal +L: linux-iio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/iio/chemical/aosong,ags02ma.yaml +F: drivers/iio/chemical/ags02ma.c + ASC7621 HARDWARE MONITOR DRIVER M: George Joseph L: linux-hwmon@vger.kernel.org diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index c30657e10ee1..02649ab81b3c 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -5,6 +5,17 @@ menu "Chemical Sensors" +config AOSONG_AGS02MA + tristate "Aosong AGS02MA TVOC sensor driver" + depends on I2C + select CRC8 + help + Say Y here to build support for Aosong AGS02MA TVOC (Total Volatile + Organic Compounds) sensor. + + To compile this driver as module, choose M here: the module will be + called ags02ma. + config ATLAS_PH_SENSOR tristate "Atlas Scientific OEM SM sensors" depends on I2C diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile index a11e777a7a00..2f3dee8bb779 100644 --- a/drivers/iio/chemical/Makefile +++ b/drivers/iio/chemical/Makefile @@ -4,6 +4,7 @@ # # When adding new entries keep the list in alphabetical order +obj-$(CONFIG_AOSONG_AGS02MA) += ags02ma.o obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-sensor.o obj-$(CONFIG_ATLAS_EZO_SENSOR) += atlas-ezo-sensor.o obj-$(CONFIG_BME680) += bme680_core.o diff --git a/drivers/iio/chemical/ags02ma.c b/drivers/iio/chemical/ags02ma.c new file mode 100644 index 000000000000..b2fe056083b3 --- /dev/null +++ b/drivers/iio/chemical/ags02ma.c @@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 Anshul Dalal + * + * Driver for Aosong AGS02MA + * + * Datasheet: + * https://asairsensors.com/wp-content/uploads/2021/09/AGS02MA.pdf + * Product Page: + * http://www.aosong.com/m/en/products-33.html + */ + +#include +#include +#include +#include + +#include + +#define AGS02MA_TVOC_READ_REG 0x00 +#define AGS02MA_VERSION_REG 0x11 + +#define AGS02MA_VERSION_PROCESSING_DELAY 30 +#define AGS02MA_TVOC_READ_PROCESSING_DELAY 1500 + +#define AGS02MA_CRC8_INIT 0xff +#define AGS02MA_CRC8_POLYNOMIAL 0x31 + +DECLARE_CRC8_TABLE(ags02ma_crc8_table); + +struct ags02ma_data { + struct i2c_client *client; +}; + +struct ags02ma_reading { + __be32 data; + u8 crc; +} __packed; + +static int ags02ma_register_read(struct i2c_client *client, u8 reg, u16 delay, + u32 *val) +{ + int ret; + u8 crc; + struct ags02ma_reading read_buffer; + + ret = i2c_master_send(client, ®, sizeof(reg)); + if (ret < 0) { + dev_err(&client->dev, + "Failed to send data to register 0x%x: %d", reg, ret); + return ret; + } + + /* Processing Delay, Check Table 7.7 in the datasheet */ + msleep_interruptible(delay); + + ret = i2c_master_recv(client, (u8 *)&read_buffer, sizeof(read_buffer)); + if (ret < 0) { + dev_err(&client->dev, + "Failed to receive from register 0x%x: %d", reg, ret); + return ret; + } + + crc = crc8(ags02ma_crc8_table, (u8 *)&read_buffer.data, + sizeof(read_buffer.data), AGS02MA_CRC8_INIT); + if (crc != read_buffer.crc) { + dev_err(&client->dev, "CRC error\n"); + return -EIO; + } + + *val = be32_to_cpu(read_buffer.data); + return 0; +} + +static int ags02ma_read_raw(struct iio_dev *iio_device, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + int ret; + struct ags02ma_data *data = iio_priv(iio_device); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = ags02ma_register_read(data->client, AGS02MA_TVOC_READ_REG, + AGS02MA_TVOC_READ_PROCESSING_DELAY, + val); + if (ret < 0) + return ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + /* The sensor reads data as ppb */ + *val = 0; + *val2 = 100; + return IIO_VAL_INT_PLUS_NANO; + default: + return -EINVAL; + } +} + +static const struct iio_info ags02ma_info = { + .read_raw = ags02ma_read_raw, +}; + +static const struct iio_chan_spec ags02ma_channel = { + .type = IIO_CONCENTRATION, + .channel2 = IIO_MOD_VOC, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) +}; + +static int ags02ma_probe(struct i2c_client *client) +{ + int ret; + struct ags02ma_data *data; + struct iio_dev *indio_dev; + u32 version; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + crc8_populate_msb(ags02ma_crc8_table, AGS02MA_CRC8_POLYNOMIAL); + + ret = ags02ma_register_read(client, AGS02MA_VERSION_REG, + AGS02MA_VERSION_PROCESSING_DELAY, &version); + if (ret < 0) + return dev_err_probe(&client->dev, ret, + "Failed to read device version\n"); + dev_dbg(&client->dev, "Aosong AGS02MA, Version: 0x%x", version); + + data = iio_priv(indio_dev); + data->client = client; + indio_dev->info = &ags02ma_info; + indio_dev->channels = &ags02ma_channel; + indio_dev->num_channels = 1; + indio_dev->name = "ags02ma"; + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id ags02ma_id_table[] = { + { "ags02ma" }, + { /* Sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, ags02ma_id_table); + +static const struct of_device_id ags02ma_of_table[] = { + { .compatible = "aosong,ags02ma" }, + { /* Sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ags02ma_of_table); + +static struct i2c_driver ags02ma_driver = { + .driver = { + .name = "ags02ma", + .of_match_table = ags02ma_of_table, + }, + .id_table = ags02ma_id_table, + .probe = ags02ma_probe, +}; +module_i2c_driver(ags02ma_driver); + +MODULE_AUTHOR("Anshul Dalal "); +MODULE_DESCRIPTION("Aosong AGS02MA TVOC Driver"); +MODULE_LICENSE("GPL");