From patchwork Wed Nov 8 15:37:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13450260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62F45C4167D for ; Wed, 8 Nov 2023 15:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbjKHPhh (ORCPT ); Wed, 8 Nov 2023 10:37:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbjKHPhg (ORCPT ); Wed, 8 Nov 2023 10:37:36 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60BD91BE2; Wed, 8 Nov 2023 07:37:34 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-53d8320f0easo11672208a12.3; Wed, 08 Nov 2023 07:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699457853; x=1700062653; 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=BPWkh5aB5IOo2Y3MUSfYk8DBookJZmUKLH1njZPisds=; b=TsTaknTvHl/N1ZHFuIP4dl34DSd+GRO7/Z9ZmomHQepH83eqDAwy1yTi6Qt0F0HXon F2QxeDwU4C/1n81TY6mRZXF+PQlcLJhJku0JcZZ4suDP6ZEVRarCte+maPtSCL/aQoy3 G2nVetQOGER53m2gG3sawfGf+YgdP8QmP7Iy2KS0qEfXSH1M7dHLC8OfkUXy5f4vHTIu j+0ZX4NH5t0/fIl8oAoJxeWFkF0RwAhEyfNJhdaOvfVfyHrdsIIc9nhbXCLvcp1NkYcg iRPRcFzQ/ChaGcMMiNAB8SYtDuoitKGBMDfMTPwcssH6oi64ZPH/vL1fT5uUcZN5vxFp GZlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699457853; x=1700062653; 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=BPWkh5aB5IOo2Y3MUSfYk8DBookJZmUKLH1njZPisds=; b=vJCsqqNcGI962pW1psdCI/wue6PfVoA7eUGeT9MCKz+OiPsVZS+tQPor9XoOisbfzt 607rUGHUZEygDFp+3Phcgy84Z0zlTe73eXht9JpZkL4BxDvmAuN15rtsDECLojkEzhDg bYnD3y2kWJWEbGboxcMrAm3rrzGfnLVOmkMzJ52ODqK2FQdTjbEnbmW6/0UTrexrGxmj niBNDa5oXXDixAqSovnHhHxzpPuerPk7iIgsNVCzAChq60yfZIp6B1w9ROWkWIJKhX8c Z8RXwJJ+9uP5mWQZic3Ike0wlBpsWHJTkJ/FWvk3xqq2bP1UiUR+Ou9ukxhlF6xVeVi9 6DhA== X-Gm-Message-State: AOJu0Yx6UoMIiB6vbOB4+9Kq49Qh3Iqxdppq4UJqQ/oqCTPhghbm8Iw/ 3Bv+xPwrxIGYPluVVG5yO/Y= X-Google-Smtp-Source: AGHT+IEUtbbWxyUydAs/aXp1AP0bpOrag+qrNh8g0FiWBu0pT2KTBXKTMVVEtDrTS2KvDwxVO3qjxA== X-Received: by 2002:a50:9f4e:0:b0:540:ccde:5 with SMTP id b72-20020a509f4e000000b00540ccde0005mr1735257edf.37.1699457852760; Wed, 08 Nov 2023 07:37:32 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-840c-82c6-68fb-9a49.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:840c:82c6:68fb:9a49]) by smtp.gmail.com with ESMTPSA id j28-20020a508a9c000000b0053e3839fc79sm7009966edj.96.2023.11.08.07.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:37:31 -0800 (PST) From: Javier Carrasco Date: Wed, 08 Nov 2023 16:37:27 +0100 Subject: [PATCH v2 1/4] dt-bindings: vendor-prefixes: add Amphenol MIME-Version: 1.0 Message-Id: <20231020-topic-chipcap2-v2-1-f5c325966fdb@gmail.com> References: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> In-Reply-To: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jean Delvare , Guenter Roeck , Jonathan Corbet , Liam Girdwood , Mark Brown Cc: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699457849; l=810; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=t2HXxBm7icJQeziWXWBSO7trIqSmEesTGrPC9BNCkBk=; b=JilNYrIBbLukAa31Zbd1sJAJWlUCyfeQPmA5UMi8Y1aSchSOwPNbcQf7sohY1eb3ELqX9Zw9t 34JrISbCC0gBwWxJ7ZXbgsGMhzWoMoXBcZinoe2P/iodhnoqUMZKQLt X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add vendor prefix for Amphenol (https://www.amphenol-sensors.com) Signed-off-by: Javier Carrasco Acked-by: Krzysztof Kozlowski --- 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..f12590e88be6 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -103,6 +103,8 @@ patternProperties: description: Amlogic, Inc. "^ampere,.*": description: Ampere Computing LLC + "^amphenol,.*": + description: Amphenol Advanced Sensors "^ampire,.*": description: Ampire Co., Ltd. "^ams,.*": From patchwork Wed Nov 8 15:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13450261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A4EBC0018C for ; Wed, 8 Nov 2023 15:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbjKHPhj (ORCPT ); Wed, 8 Nov 2023 10:37:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233827AbjKHPhi (ORCPT ); Wed, 8 Nov 2023 10:37:38 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9D43138; Wed, 8 Nov 2023 07:37:35 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9a6190af24aso1094626766b.0; Wed, 08 Nov 2023 07:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699457854; x=1700062654; 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=iR96KjiNOLwJsrZW9YjWEMZZO1SB3q3Gyovy8VvF6lw=; b=Fmyj4inNDf/PbVRfl7yj+0Y6WC6o3IBl1870dr3aXKoc6OSopT7cHFKX/HcAdmpuH5 yrupKXmrbRFp+w/Np2unppLEfCLYa7ucunD9Z+CmhrRruG6/f58L9yHLk+cZ9IwY1V4K c1NGLQQPMD01wNmDvrfwURJ9wBO4TWwpQtWzEKTFh+pRJ0ZzAZ4JqvMDcO/dAVYbIoN4 rEfqqURIuRB7XOECuPEIJzLLBMKOeUTZ5KQWd3a36h0HsebCeL5mh0M/UzP8z7WD+2Xx 1DUB0KMW+OAJ6JtkkyrguDTCwKJZpNxhIvNXF/LwhAurD3NjTneNJzmNpjdIXnNGX53s sTtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699457854; x=1700062654; 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=iR96KjiNOLwJsrZW9YjWEMZZO1SB3q3Gyovy8VvF6lw=; b=e+E23ltbiBuJp+GDsQqL/brH4JNLJO6h1tUxEBCCUlqQt1NdjdyiYZvfHqFmWqbHkj iJLIbomgSMhHJYGnbw9o3pUS0/6/gjDZLluntJJQU8joD7wY9K11YL+05gEKotNyG63s fGbgdGcJ2e8UhuTdxkBtJDe25n14JChn2f1JtCBFnA4lA3u+JbDAIpaYOvoyeKSnKzQi bVoOJF3OJ+bN5sqzsjPJ+y434opXTtMMf/oWIij5VNSreDxbG4YfMBdx+9E10FP5mn7W 0yBXR+CIJ9tDC82degVCZNwMrD04FQ4yGalHP/e/LZwo4vKjv48VOekhzWz9Qix14bEV +vvw== X-Gm-Message-State: AOJu0YzgcmB+oVrAEBMa/KWoC9IMwD/2OkUhX7bjF6w4AMPJ1xjensgP E5Qqxk6mtCZuOugHbWOOuNM= X-Google-Smtp-Source: AGHT+IFvpQz6IU53s8AC35mADYmMKcNfAIOelcC+vnE8De+ZP5TsRdyNdDUhHDounJYANxlk5WvdFQ== X-Received: by 2002:a17:907:7e83:b0:9d7:139:ca02 with SMTP id qb3-20020a1709077e8300b009d70139ca02mr1959958ejc.18.1699457854220; Wed, 08 Nov 2023 07:37:34 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-840c-82c6-68fb-9a49.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:840c:82c6:68fb:9a49]) by smtp.gmail.com with ESMTPSA id j28-20020a508a9c000000b0053e3839fc79sm7009966edj.96.2023.11.08.07.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:37:33 -0800 (PST) From: Javier Carrasco Date: Wed, 08 Nov 2023 16:37:28 +0100 Subject: [PATCH v2 2/4] hwmon: (core) Add support for humidity min/max alarm MIME-Version: 1.0 Message-Id: <20231020-topic-chipcap2-v2-2-f5c325966fdb@gmail.com> References: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> In-Reply-To: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jean Delvare , Guenter Roeck , Jonathan Corbet , Liam Girdwood , Mark Brown Cc: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699457849; l=2225; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=re14X9c0E+VBxIxbVskjRDUjU7zOxmCOyQzwnK834Ds=; b=G0ri7HM2GmI44QiKtxd/lNS11ugK3iZG0lzeHXpRUwc1yMr7svZeI+YVxuoqZl0yEb8EdDJJ8 ThOB3QieZEmCXGwPk4/gVKOcHTQ5fs6gUlDtMLYm9+0d2tRaVMbyKfM X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add min_alarm and max_alarm attributes for humidityX to support devices that can generate these alarms. Such attributes already exist for other magnitudes such as tempX. Tested with a ChipCap 2 temperature-humidity sensor. Signed-off-by: Javier Carrasco --- drivers/hwmon/hwmon.c | 2 ++ include/linux/hwmon.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index c7dd3f5b2bd5..7f92984c37d9 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -579,8 +579,10 @@ static const char * const hwmon_humidity_attr_templates[] = { [hwmon_humidity_input] = "humidity%d_input", [hwmon_humidity_label] = "humidity%d_label", [hwmon_humidity_min] = "humidity%d_min", + [hwmon_humidity_min_alarm] = "humidity%d_min_alarm", [hwmon_humidity_min_hyst] = "humidity%d_min_hyst", [hwmon_humidity_max] = "humidity%d_max", + [hwmon_humidity_max_alarm] = "humidity%d_max_alarm", [hwmon_humidity_max_hyst] = "humidity%d_max_hyst", [hwmon_humidity_alarm] = "humidity%d_alarm", [hwmon_humidity_fault] = "humidity%d_fault", diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h index 8cd6a6b33593..154de35e34ac 100644 --- a/include/linux/hwmon.h +++ b/include/linux/hwmon.h @@ -286,8 +286,10 @@ enum hwmon_humidity_attributes { hwmon_humidity_input, hwmon_humidity_label, hwmon_humidity_min, + hwmon_humidity_min_alarm, hwmon_humidity_min_hyst, hwmon_humidity_max, + hwmon_humidity_max_alarm, hwmon_humidity_max_hyst, hwmon_humidity_alarm, hwmon_humidity_fault, @@ -299,8 +301,10 @@ enum hwmon_humidity_attributes { #define HWMON_H_INPUT BIT(hwmon_humidity_input) #define HWMON_H_LABEL BIT(hwmon_humidity_label) #define HWMON_H_MIN BIT(hwmon_humidity_min) +#define HWMON_H_MIN_ALARM BIT(hwmon_humidity_min_alarm) #define HWMON_H_MIN_HYST BIT(hwmon_humidity_min_hyst) #define HWMON_H_MAX BIT(hwmon_humidity_max) +#define HWMON_H_MAX_ALARM BIT(hwmon_humidity_max_alarm) #define HWMON_H_MAX_HYST BIT(hwmon_humidity_max_hyst) #define HWMON_H_ALARM BIT(hwmon_humidity_alarm) #define HWMON_H_FAULT BIT(hwmon_humidity_fault) From patchwork Wed Nov 8 15:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13450262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50980C4167B for ; Wed, 8 Nov 2023 15:37:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233956AbjKHPhl (ORCPT ); Wed, 8 Nov 2023 10:37:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233935AbjKHPhk (ORCPT ); Wed, 8 Nov 2023 10:37:40 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DA11BE6; Wed, 8 Nov 2023 07:37:37 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53e04b17132so11691874a12.0; Wed, 08 Nov 2023 07:37:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699457856; x=1700062656; 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=UP1P8H+TtC32B5knkuZ0ohNCPdbPxMOnpBVE3b7KurY=; b=RJaOequHb9UjIbwglz3aiU0DEwEr4cIOSgXIU5xCc0hBOOHlAEjywHokR/m1gFxZJv guhutGLKZlsd4fsdMVNU0HUe5wpp+PePsJQ3R3lgf3jUrJewS9b7EhED1eJE8RGRfU03 lS8q+GixHOyWh5qbvG3jX5eE1GOLulRqf+yAd+KZw6D6kUB+lpht76wqtscS2EdK649D HvdXr841PfTFtFuAAFC+7S2Nt0q0yEVUaIkQ8y+MMX+7VmERGg2JCfkSsgEZgBOBQbRx 7apdSw+yjPOuLa9yVpGd/ANNQJs1Dhaz9fhFxl9vZyPpjgfruDsE3CQT7xfgmOcYB19a AmAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699457856; x=1700062656; 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=UP1P8H+TtC32B5knkuZ0ohNCPdbPxMOnpBVE3b7KurY=; b=wPgkjFUY1I7GIh35qu04c5MX0YqLCuxzExvrH1j0odY5WmB0PSQ4CwFjvAtcauhhRS FxB0eUhf/AeBJn8txAGhZygyVCK3+y5i63NAdQb9BKP0erCtMCu/kmNlBeJBUB72/Nw4 bxLVI326GtA6ov3hYvT3c7KEWdGs086PPOyr0hyGQWWJ3kFjbxuNP0jLo/w8K3HR6ujl m/aHytaqU69ADaYDBfDcpWmNMa+FAseSKB/Z5CAK2hKf2HJfUsHgYEn2AnnCxZWgGUzX Vw4i+A29d2d/YaUWR3wutmqqZ27ZZvxBcdbVpLp8J5HeTwa7Ul+UBf7241k4DUUb7HM0 CxGw== X-Gm-Message-State: AOJu0YyJRZyPdz/dsTBGBRyDkQU1kZO8ikzoWUMS4F6+ysJ7AgWri67Q X/WoKira0J398WNqmzgX338mcm9bUwWwOw== X-Google-Smtp-Source: AGHT+IEGPJ2SFZbBqBd3QjjAR6I8HUY4lul23MsbFy9PJEKJ/Km3j5QdaL5hTUqavbUtAV+WvyUtGg== X-Received: by 2002:a50:9e4a:0:b0:531:2b0b:9b8 with SMTP id z68-20020a509e4a000000b005312b0b09b8mr1882321ede.7.1699457855715; Wed, 08 Nov 2023 07:37:35 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-840c-82c6-68fb-9a49.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:840c:82c6:68fb:9a49]) by smtp.gmail.com with ESMTPSA id j28-20020a508a9c000000b0053e3839fc79sm7009966edj.96.2023.11.08.07.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:37:35 -0800 (PST) From: Javier Carrasco Date: Wed, 08 Nov 2023 16:37:29 +0100 Subject: [PATCH v2 3/4] hwmon: Add support for Amphenol ChipCap 2 MIME-Version: 1.0 Message-Id: <20231020-topic-chipcap2-v2-3-f5c325966fdb@gmail.com> References: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> In-Reply-To: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jean Delvare , Guenter Roeck , Jonathan Corbet , Liam Girdwood , Mark Brown Cc: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699457849; l=35871; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=m3m5i5ZYNcTNnJXen/N7nYUYiR9Hj8pfluyDenKmwtg=; b=tiKBvaI11QYOe5Gr8PrJlFWB4eFjG7CjMmS6ifKVnIlhdw/lWIFnfBIJRos7ZwkcudnwmdLOx cpHTebYAFqZApLddvnM7Z7emoN7YXWcpUhJ6I5zpXVRAq++tHXvMVe0 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The Amphenol ChipCap 2 is a capacitive polymer humidity and temperature sensor with an integrated EEPROM and minimum/maximum humidity alarms. All device variants offer an I2C interface and depending on the part number, two different output modes: - CC2D: digital output - CC2A: analog (PDM) output This driver adds support for the digital variant (CC2D part numbers), which is also divided into two subfamilies [1]: - CC2DXX: non-sleep measurement mode - CC2DXXS: sleep measurement mode The only difference between them is that the non-sleep parts carry out measurements periodically, whereas the sleep counterparts require the user to trigger each measurement, staying in sleep mode otherwise to increase power savings. The Chipcap 2 EEPROM can be accessed to configure a series of parameters like the minimum/maximum humidity alarm threshold and hysteresis. The EEPROM is only accessible in the command window after a power-on reset. The default window lasts 10 ms if no Start_CM command is sent. After the command window is finished (either after the mentioned timeout of after a Start_NOM command is sent), the device enters the normal operation mode and makes a first measurement automatically. Unfortunately, the device does not provide any hardware or software reset and therefore the driver must trigger power cycles to enter the command mode. An external regulator is required for that and if it is not available, the driver cannot configure the alarms and it must limit the device operation to humidity and temperature measurements. Given the high cost of accessing the command mode, an EEPROM read is made in the probe function and the alarm parameters are stored for further readings, only accessing the command mode again to overwrite those parameters. The measurement process makes use of the ready signal if available, using maximum delay values from the datasheet otherwise. In non-sleep mode, a single "data fetch" command is required to read the measurements and no trigger is required. Sleep devices require an additional "measurement request" command to trigger the measurement, followed by a data fetch to retrieve the measured values. In both cases the ready signal goes high when valid data can be fetched. The ready signal stays high until the data is retrieved even if further measurements are made. The minimum and maximum humidity alarms can be configured with two registers per alarm: one stores the alarm threshold and the other one keeps the value that turns off the alarm. Note that the second register stores an absolute value and not the hysteresis. The hysteresis is therefore obtained as a subtraction of the two registers. The alarm signals are only updated when a measurement is carried out. Sleep mode devices will not trigger their alarms until a measurement is requested. This driver has been tested with a sleep device and the non-sleep mechanism has been inferred from the common behavior after power-on reset explained above, where a first measurement is made without user intervention. Therefore there is no guarantee that no adjustments in the measurement function will be required if the driver ever controls a non-sleep device. [1] Note that the measurement mode is programmed in the manufacturing process. The datasheet mentions the name of the register and exact bit to set the measurement mode, but no addresses are provided and according to the manufacturer, it is not modifiable by the user. Signed-off-by: Javier Carrasco --- Documentation/hwmon/chipcap2.rst | 73 +++ Documentation/hwmon/index.rst | 1 + MAINTAINERS | 8 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/chipcap2.c | 1022 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 1115 insertions(+) diff --git a/Documentation/hwmon/chipcap2.rst b/Documentation/hwmon/chipcap2.rst new file mode 100644 index 000000000000..35a968aaac4e --- /dev/null +++ b/Documentation/hwmon/chipcap2.rst @@ -0,0 +1,73 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver ChipCap2 +====================== + +Supported chips: + + * Amphenol CC2D23, CC2D23S, CC2D25, CC2D25S, CC2D33, CC2D33S, CC2D35, CC2D35S + + Prefix: 'chipcap2' + + Addresses scanned: - + + Datasheet: https://www.amphenol-sensors.com/en/telaire/humidity/527-humidity-sensors/3095-chipcap-2 + +Author: + + - Javier Carrasco + +Description +----------- + +This driver implements support for the Amphenol ChipCap 2 chips, a humidity +and temperature family. Temperature is measured in milli degrees celsius, +relative humidity is expressed as a per cent mille. The measurement ranges +are the following: + + - Relative humidity: 0 to 100000 pcm (14-bit resolution) + - Temperature: -40000 to +125000 m°C (14-bit resolution) + +The device communicates with the I2C protocol and uses the I2C address 0x28 +by default. + +Depending on the hardware configuration, up to two humidity alarms to control +minimum and maximum values are provided. Their thresholds and hystersis can be +configured via sysfs. + +Thresholds and hysteris must be provided as a per cent mille. These values +might be truncated to match the 14-bit device resolution (6.1 pcm/LSB) + +Known Issues +------------ + +The driver does not support I2C address and command window length modification. + +sysfs-Interface +--------------- + +The following list includes the sysfs attributes that the driver always provides, +their permissions and a short description: + +=============================== ======= ======================================== +Name Perm Description +=============================== ======= ======================================== +temp1_input: RO temperature input +humidity1_input: RO humidity input +=============================== ======= ======================================== + +The following list includes the sysfs attributes that the driver may provide +depending on the hardware configuration: + +=============================== ======= ======================================== +Name Perm Description +=============================== ======= ======================================== +humidity1_min: RW humidity low limit. Measurements under + this limit trigger a humidity low alarm +humidity1_max: RW humidity high limit. Measurements above + this limit trigger a humidity high alarm +humidity1_min_hyst: RW humidity low hystersis +humidity1_max_hyst: RW humidity high hystersis +humidity1_min_alarm: RO humidity low alarm indicator +humidity1_max_alarm: RO humidity high alarm indicator +=============================== ======= ======================================== diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 88dadea85cfc..ddc2d4579f24 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -51,6 +51,7 @@ Hardware Monitoring Kernel Drivers bel-pfe bpa-rs600 bt1-pvt + chipcap2 coretemp corsair-cpro corsair-psu diff --git a/MAINTAINERS b/MAINTAINERS index dd5de540ec0b..bf4a066d3628 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1084,6 +1084,14 @@ F: Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml F: drivers/perf/amlogic/ F: include/soc/amlogic/ +AMPHENOL CHIPCAP 2 HUMIDITY-TEMPERATURE IIO DRIVER +M: Javier Carrasco +L: linux-hwmon@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml +F: Documentation/hwmon/chipcap2.rst +F: drivers/hwmon/chipcap2.c + AMPHION VPU CODEC V4L2 DRIVER M: Ming Qian M: Zhou Peng diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index ec38c8892158..75f67d58e649 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -452,6 +452,16 @@ config SENSORS_BT1_PVT_ALARMS the data conversion will be periodically performed and the data will be saved in the internal driver cache. +config SENSORS_CHIPCAP2 + tristate "Amphenol ChipCap 2 relative humidity and temperature sensor" + depends on I2C + help + Say yes here to build support for the Amphenol ChipCap 2 + relative humidity and temperature sensor. + + To compile this driver as a module, choose M here: the module + will be called chipcap2. + config SENSORS_CORSAIR_CPRO tristate "Corsair Commander Pro controller" depends on HID diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 4ac9452b5430..450ce8fa1d4f 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_SENSORS_ASPEED) += aspeed-pwm-tacho.o obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_AXI_FAN_CONTROL) += axi-fan-control.o obj-$(CONFIG_SENSORS_BT1_PVT) += bt1-pvt.o +obj-$(CONFIG_SENSORS_CHIPCAP2) += chipcap2.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o obj-$(CONFIG_SENSORS_CORSAIR_CPRO) += corsair-cpro.o obj-$(CONFIG_SENSORS_CORSAIR_PSU) += corsair-psu.o diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c new file mode 100644 index 000000000000..740e3dcb1352 --- /dev/null +++ b/drivers/hwmon/chipcap2.c @@ -0,0 +1,1022 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * cc2.c - Support for the Amphenol ChipCap 2 relative humidity, temperature sensor + * + * Part numbers supported: + * - CC2DXX: digital, non-sleep mode (CC2D23, CC2D25, CC2D33, CC2D35) + * - CC2DXXS: digital, sleep mode (CC2D23S, CC2D25S, CC2D33S, CC2D35S) + * + * Author: Javier Carrasco + * + * Datasheet and application notes: + * https://www.amphenol-sensors.com/en/telaire/humidity/527-humidity-sensors/3095-chipcap-2 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CC2_DEV_NAME "chipcap2" + +#define CC2_START_CM 0xA0 +#define CC2_START_NOM 0x80 +#define CC2_R_ALARM_HIGH_ON 0x18 +#define CC2_R_ALARM_HIGH_OFF 0x19 +#define CC2_R_ALARM_LOW_ON 0x1A +#define CC2_R_ALARM_LOW_OFF 0x1B +#define CC2_RW_OFFSET 0x40 +#define CC2_W_ALARM_HIGH_ON (CC2_R_ALARM_HIGH_ON + CC2_RW_OFFSET) +#define CC2_W_ALARM_HIGH_OFF (CC2_R_ALARM_HIGH_OFF + CC2_RW_OFFSET) +#define CC2_W_ALARM_LOW_ON (CC2_R_ALARM_LOW_ON + CC2_RW_OFFSET) +#define CC2_W_ALARM_LOW_OFF (CC2_R_ALARM_LOW_OFF + CC2_RW_OFFSET) + +#define CC2_STATUS_FIELD GENMASK(7, 6) +#define CC2_STATUS_VALID_DATA 0x00 +#define CC2_STATUS_STALE_DATA 0x01 +#define CC2_STATUS_CMD_MODE 0x02 + +#define CC2_RESPONSE_FIELD GENMASK(1, 0) +#define CC2_RESPONSE_BUSY 0x00 +#define CC2_RESPONSE_ACK 0x01 +#define CC2_RESPONSE_NACK 0x02 + +#define CC2_ERR_CORR_EEPROM BIT(2) +#define CC2_ERR_UNCORR_EEPROM BIT(3) +#define CC2_ERR_RAM_PARITY BIT(4) +#define CC2_ERR_CONFIG_LOAD BIT(5) + +#define CC2_EEPROM_SIZE 10 +#define CC2_EEPROM_DATA_LEN 3 +#define CC2_MEAS_DATA_LEN 4 + +#define CC2_RH_DATA_FIELD GENMASK(13, 0) + +#define CC2_POWER_CYCLE_MS 150 +#define CC2_RESP_SLEEP_MS 45 +#define CC2_RESP_START_CM_US 100 +#define CC2_RESP_EEPROM_R_US 100 +#define CC2_RESP_EEPROM_W_MS 12 +#define CC2_STARTUP_TIME_US 1250 +#define CC2_UPDATE_RATE_MS 165 + +#define CC2_RH_MIN 0 +#define CC2_RH_MAX (100 * 1000U) + +struct cc2_data; + +enum cc2_ids {cc2dxx, cc2dxxs}; + +struct cc2_config { + int (*measurement)(struct cc2_data *data, + enum hwmon_sensor_types type, + long *val); +}; + +struct cc2_alarm_info { + long min; + long min_hyst; + long max; + long max_hyst; + bool rh_low; + bool rh_high; + bool rh_low_visible; + bool rh_high_visible; +}; + +struct cc2_data { + const struct cc2_config *config; + struct cc2_alarm_info alarm; + struct mutex alarm_lock; /* alarm status lock */ + struct completion complete; + struct device *hwmon; + struct i2c_client *client; + struct mutex i2c_lock; /* i2c communication lock */ + struct regulator *regulator; + const char *name; + int irq_ready; + int irq_low; + int irq_high; + bool ignore_irqs; +}; + +enum cc2_chan_addr { + CC2_CHAN_TEMP = 0, + CC2_CHAN_HUMIDITY, +}; + +static long cc2_rh_convert(u16 data) +{ + unsigned long tmp = (data & CC2_RH_DATA_FIELD) * CC2_RH_MAX; + + return tmp / ((1 << 14) - 1); +} + +static u16 cc2_rh_to_reg(long data) +{ + return data * ((1 << 14) - 1) / CC2_RH_MAX; +} + +static long cc2_rh_in_device_resolution(long data) +{ + u16 reg_val; + + reg_val = cc2_rh_to_reg(data); + + return cc2_rh_convert(reg_val); +} + +static long cc2_temp_convert(u16 data) +{ + unsigned long tmp = ((data >> 2) * 165 * 1000U) / ((1 << 14) - 1); + + return tmp - 40 * 1000U; +} + +static int cc2_analyze_cmd_response(struct device *dev, u8 status) +{ + int resp; + int ret; + + if (FIELD_GET(CC2_STATUS_FIELD, status) != CC2_STATUS_CMD_MODE) { + dev_dbg(dev, "Command sent out of command window\n"); + return -ETIMEDOUT; + } + + resp = FIELD_GET(CC2_RESPONSE_FIELD, status); + switch (resp) { + case CC2_RESPONSE_ACK: + ret = 0; + break; + case CC2_RESPONSE_BUSY: + ret = -EBUSY; + break; + case CC2_RESPONSE_NACK: + if (resp & CC2_ERR_CORR_EEPROM) + dev_dbg(dev, "Command failed: corrected EEPROM\n"); + if (resp & CC2_ERR_UNCORR_EEPROM) + dev_dbg(dev, "Command failed: uncorrected EEPROM\n"); + if (resp & CC2_ERR_RAM_PARITY) + dev_dbg(dev, "Command failed: RAM parity\n"); + if (resp & CC2_ERR_RAM_PARITY) + dev_dbg(dev, "Command failed: configuration error\n"); + ret = -ENODATA; + break; + default: + dev_dbg(dev, "Unknown command reply\n"); + ret = -ENODATA; + break; + } + + return ret; +} + +static int cc2_read_command_status(struct i2c_client *client) +{ + u8 status; + int ret; + + ret = i2c_master_recv(client, &status, 1); + if (ret != 1) { + ret = ret < 0 ? ret : -EIO; + return ret; + } + + return cc2_analyze_cmd_response(&client->dev, status); +} + +static int cc2_clear_data_ready(struct i2c_client *client) +{ + u8 data[CC2_MEAS_DATA_LEN]; + u8 status; + int ret; + + ret = i2c_master_recv(client, data, CC2_MEAS_DATA_LEN); + if (ret != CC2_MEAS_DATA_LEN) { + ret = ret < 0 ? ret : -EIO; + return ret; + } + status = FIELD_GET(CC2_STATUS_FIELD, data[0]); + if (status == CC2_STATUS_STALE_DATA) + return -EBUSY; + + if (status != CC2_STATUS_VALID_DATA) + return -EIO; + + return 0; +} + +/* + * The command mode is only accessible after sending the START_CM command in the + * first 10 ms after power-up. + */ +static int cc2_command_mode_start(struct cc2_data *data) +{ + unsigned long timeout; + int ret; + + ret = i2c_smbus_write_word_data(data->client, CC2_START_CM, 0); + if (ret < 0) + return ret; + + if (data->irq_ready > 0) { + timeout = usecs_to_jiffies(2 * CC2_RESP_START_CM_US); + ret = wait_for_completion_timeout(&data->complete, timeout); + if (!ret) + return -ETIMEDOUT; + } else { + usleep_range(CC2_RESP_START_CM_US, 2 * CC2_RESP_START_CM_US); + } + + return cc2_read_command_status(data->client); +} + +/* Sending a Start_NOM command finishes the command mode immediately with no + * reply and the device enters normal operation mode + */ +static int cc2_command_mode_finish(struct cc2_data *data) +{ + int ret; + + ret = i2c_smbus_write_word_data(data->client, CC2_START_NOM, 0); + if (ret < 0) + return ret; + + return 0; +} + +/* EEPROM registers can only be read in command mode */ +static int cc2_read_eeprom_reg(struct cc2_data *data, u8 cmd, u16 *val) +{ + u8 buf[CC2_EEPROM_DATA_LEN]; + unsigned long timeout; + int ret; + + ret = i2c_smbus_write_word_data(data->client, cmd, 0); + if (ret < 0) + return ret; + + if (data->irq_ready > 0) { + timeout = usecs_to_jiffies(2 * CC2_RESP_EEPROM_R_US); + ret = wait_for_completion_timeout(&data->complete, timeout); + if (!ret) + return -ETIMEDOUT; + } else { + usleep_range(CC2_RESP_EEPROM_R_US, CC2_RESP_EEPROM_R_US + 10); + } + ret = i2c_master_recv(data->client, buf, CC2_EEPROM_DATA_LEN); + if (ret != CC2_EEPROM_DATA_LEN) { + ret = ret < 0 ? ret : -EIO; + return ret; + } + + *val = be16_to_cpup((__be16 *)&buf[1]); + + return cc2_read_command_status(data->client); +} + +static int cc2_write_eeprom_reg(struct cc2_data *data, u8 cmd, u16 val) +{ + unsigned long timeout; + int ret; + + cpu_to_be16s(&val); + ret = i2c_smbus_write_word_data(data->client, cmd, val); + if (ret < 0) + return ret; + + if (data->irq_ready > 0) { + timeout = msecs_to_jiffies(2 * CC2_RESP_EEPROM_W_MS); + ret = wait_for_completion_timeout(&data->complete, timeout); + if (!ret) + return -ETIMEDOUT; + } else { + msleep(CC2_RESP_EEPROM_W_MS); + } + + return cc2_read_command_status(data->client); +} + +/* Command mode is only accessible in the first 10 ms after power-up, but the + * device does not provide any kind of reset. In order to access the command + * mode during normal operation, a power cycle must be triggered. + */ +static int cc2_start_command_window(struct cc2_data *data) +{ + int ret; + + /* ignore alarms triggered by voltage toggling during the power cycle */ + mutex_lock(&data->alarm_lock); + data->ignore_irqs = true; + mutex_unlock(&data->alarm_lock); + + /* clear any pending completion */ + try_wait_for_completion(&data->complete); + + if (regulator_is_enabled(data->regulator)) { + ret = regulator_disable(data->regulator); + if (ret < 0) + return ret; + + msleep(CC2_POWER_CYCLE_MS); /* ensure a clean power cycle */ + } + + ret = regulator_enable(data->regulator); + if (ret < 0) + return ret; + + /* + * TODO: the startup-delay-us property of the regulator might be + * added to the delay (if provided). + * Currently there is no interface to read its value apart from + * a direct access to regulator->rdev->constraints->enable_time, + * which is discouraged like any direct access to the regulator_dev + * structure. This would be relevant in cases where the startup delay + * is in the range of milliseconds. + */ + usleep_range(CC2_STARTUP_TIME_US, CC2_STARTUP_TIME_US + 125); + + mutex_lock(&data->alarm_lock); + data->ignore_irqs = false; + mutex_unlock(&data->alarm_lock); + + return 0; +} + +/* + * An EEPROM update requires the following steps: + * 1. Power cycle to accept the START_CM command. + * 2. STARTM_CM command to enter command mode. + * 3. Command(s) to update register(s). + * 4. START_NOM command to exit command mode. + * After that, the device switches to normal mode and a measurement is + * triggered automatically. In order to obtain a recent measurement on demand, + * the automatic measurement is dropped. + */ +static int cc2_update_eeprom(struct cc2_data *data, u8 *cmd, u16 *val, int len) +{ + int i, ret; + + if (!cmd || !val || len > CC2_EEPROM_SIZE) + return -EINVAL; + + ret = cc2_start_command_window(data); + if (ret < 0) + return ret; + + mutex_lock(&data->i2c_lock); + ret = cc2_command_mode_start(data); + if (ret < 0) + goto unlock; + + for (i = 0; i < len; i++) { + ret = cc2_write_eeprom_reg(data, *cmd, *val); + if (ret < 0) { + dev_dbg(&data->client->dev, + "Failed to write register %#02x\n", *cmd); + goto cmd_finish; + } + cmd++; + val++; + } + +cmd_finish: + ret = cc2_command_mode_finish(data); +unlock: + mutex_unlock(&data->i2c_lock); + + return ret; +} + +/* + * EEPROM access is a highly time-consuming task that involves a power cycle. + * The alarm-related registers are read once and their values are stored and + * updated without further EEPROM accesses. + * Probe deferring is used to minimize the risk of missing the command window + * if the task is waiting to be executed for too long. + */ +static int cc2_read_eeprom_alarm_registers(struct cc2_data *data) +{ + u16 val; + int ret; + + mutex_lock(&data->i2c_lock); + ret = cc2_command_mode_start(data); + if (ret < 0) { + ret = (ret == -ETIMEDOUT) ? -EPROBE_DEFER : ret; + goto unlock; + } + + ret = cc2_read_eeprom_reg(data, CC2_R_ALARM_LOW_ON, &val); + if (ret < 0) + goto unlock; + + data->alarm.min = cc2_rh_convert(val); + + ret = cc2_read_eeprom_reg(data, CC2_R_ALARM_LOW_OFF, &val); + if (ret < 0) + goto unlock; + + data->alarm.min_hyst = cc2_rh_convert(val) - data->alarm.min; + + ret = cc2_read_eeprom_reg(data, CC2_R_ALARM_HIGH_ON, &val); + if (ret < 0) + goto unlock; + + data->alarm.max = cc2_rh_convert(val); + + ret = cc2_read_eeprom_reg(data, CC2_R_ALARM_HIGH_OFF, &val); + if (ret < 0) + goto unlock; + + data->alarm.max_hyst = data->alarm.max - cc2_rh_convert(val); + + ret = cc2_command_mode_finish(data); + +unlock: + mutex_unlock(&data->i2c_lock); + + return ret; +} + +static int cc2_retrive_alarm_config(struct cc2_data *data) +{ + int ret; + + ret = cc2_start_command_window(data); + if (ret) + return ret; + + return cc2_read_eeprom_alarm_registers(data); +} + +/* + * A measurement request must be sent in sleep mode to wake up the device and + * start measuring. This request only contains the slave address and the write + * bit. + */ +static int cc2_measurement_request(struct i2c_client *client) +{ + int ret; + + ret = i2c_master_send(client, NULL, 0); + if (ret < 0) + return ret; + + return 0; +}; + +static int cc2_data_fetch(struct i2c_client *client, + enum hwmon_sensor_types type, long *val) +{ + u8 data[CC2_MEAS_DATA_LEN]; + u8 status; + int ret; + + ret = i2c_master_recv(client, data, CC2_MEAS_DATA_LEN); + if (ret != CC2_MEAS_DATA_LEN) { + ret = ret < 0 ? ret : -EIO; + return ret; + } + status = FIELD_GET(CC2_STATUS_FIELD, data[0]); + if (status == CC2_STATUS_STALE_DATA) + return -EBUSY; + + if (status != CC2_STATUS_VALID_DATA) + return -EIO; + + switch (type) { + case hwmon_humidity: + *val = cc2_rh_convert(be16_to_cpup((__be16 *)&data[0])); + break; + case hwmon_temp: + *val = cc2_temp_convert(be16_to_cpup((__be16 *)&data[2])); + break; + default: + return -EINVAL; + } + + return 0; +} + +/* + * non sleep-mode devies (cc2dxx variants) make measurements periodically and + * indicate valid data with the ready signal, whose level stays high until data + * is fetched even if new measurements are made. + */ +static int cc2dxx_meas(struct cc2_data *data, enum hwmon_sensor_types type, + long *val) +{ + unsigned long timeout; + int ret; + + if (data->irq_ready > 0) { + if (try_wait_for_completion(&data->complete)) + goto data_fetch; + + timeout = msecs_to_jiffies(CC2_UPDATE_RATE_MS); + ret = wait_for_completion_timeout(&data->complete, timeout); + if (!ret) + return -ETIMEDOUT; + } else { + /* check if data is ready and retry for stale data */ + ret = cc2_data_fetch(data->client, type, val); + if (ret != -EBUSY) + return ret; + + msleep(CC2_UPDATE_RATE_MS); + } + +data_fetch: + return cc2_data_fetch(data->client, type, val); +} + +/* + * sleep-mode devies (cc2dxxs variants) require a measurement request command to + * wake up the device and trigger a measurement. Then a data fetch command is + * sent to retrieve the measured values. + */ +static int cc2dxxs_meas(struct cc2_data *data, enum hwmon_sensor_types type, + long *val) +{ + unsigned long timeout; + int ret; + + if (data->irq_ready > 0) { + /* + * the device carries out a first measurement after entering + * measurement mode automatically. To avoid outdated values, + * a new request is made + */ + if (try_wait_for_completion(&data->complete)) { + ret = cc2_clear_data_ready(data->client); + if (ret < 0) + return ret; + } + + ret = cc2_measurement_request(data->client); + if (ret < 0) + return ret; + + timeout = msecs_to_jiffies(2 * CC2_RESP_SLEEP_MS); + ret = wait_for_completion_timeout(&data->complete, timeout); + if (!ret) + return -ETIMEDOUT; + } else { + ret = cc2_measurement_request(data->client); + if (ret < 0) + return ret; + + msleep(CC2_RESP_SLEEP_MS); + } + + return cc2_data_fetch(data->client, type, val); +} + +static umode_t cc2_is_visible(const void *data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + const struct cc2_data *cc2 = data; + + switch (type) { + case hwmon_humidity: + switch (attr) { + case hwmon_humidity_input: + return 0444; + case hwmon_humidity_min_alarm: + return cc2->alarm.rh_low_visible ? 0444 : 0; + case hwmon_humidity_max_alarm: + return cc2->alarm.rh_high_visible ? 0444 : 0; + case hwmon_humidity_min: + case hwmon_humidity_min_hyst: + return cc2->alarm.rh_low_visible ? 0644 : 0; + case hwmon_humidity_max: + case hwmon_humidity_max_hyst: + return cc2->alarm.rh_high_visible ? 0644 : 0; + default: + return 0; + } + case hwmon_temp: + switch (attr) { + case hwmon_temp_input: + return 0444; + default: + return 0; + } + default: + break; + } + + return 0; +} + +static irqreturn_t cc2_ready_interrupt(int irq, void *data) +{ + struct cc2_data *cc2 = data; + + mutex_lock(&cc2->alarm_lock); + if (!cc2->ignore_irqs) + complete(&cc2->complete); + mutex_unlock(&cc2->alarm_lock); + + return IRQ_HANDLED; +} + +static irqreturn_t cc2_low_interrupt(int irq, void *data) +{ + struct cc2_data *cc2 = data; + + mutex_lock(&cc2->alarm_lock); + if (!cc2->ignore_irqs) { + hwmon_notify_event(cc2->hwmon, hwmon_humidity, + hwmon_humidity_min_alarm, CC2_CHAN_HUMIDITY); + cc2->alarm.rh_low = true; + } + mutex_unlock(&cc2->alarm_lock); + + return IRQ_HANDLED; +} + +static irqreturn_t cc2_high_interrupt(int irq, void *data) +{ + struct cc2_data *cc2 = data; + + mutex_lock(&cc2->alarm_lock); + if (!cc2->ignore_irqs) { + hwmon_notify_event(cc2->hwmon, hwmon_humidity, + hwmon_humidity_max_alarm, CC2_CHAN_HUMIDITY); + cc2->alarm.rh_high = true; + } + mutex_unlock(&cc2->alarm_lock); + + return IRQ_HANDLED; +} + +static int cc2_humidity_min_alarm_status(struct cc2_data *data, long *val) +{ + long meas; + int ret; + + mutex_lock(&data->i2c_lock); + ret = data->config->measurement(data, hwmon_humidity, &meas); + mutex_unlock(&data->i2c_lock); + if (ret < 0) + return ret; + + mutex_lock(&data->alarm_lock); + if (data->alarm.rh_low) { + *val = (meas < data->alarm.min + data->alarm.min_hyst) ? 1 : 0; + data->alarm.rh_low = *val; + } else { + *val = 0; + } + mutex_unlock(&data->alarm_lock); + + return 0; +} + +static int cc2_humidity_max_alarm_status(struct cc2_data *data, long *val) +{ + long meas; + int ret; + + mutex_lock(&data->i2c_lock); + ret = data->config->measurement(data, hwmon_humidity, &meas); + mutex_unlock(&data->i2c_lock); + if (ret < 0) + return ret; + + mutex_lock(&data->alarm_lock); + if (data->alarm.rh_high) { + *val = (meas > data->alarm.max - data->alarm.max_hyst) ? 1 : 0; + data->alarm.rh_high = *val; + } else { + *val = 0; + } + mutex_unlock(&data->alarm_lock); + + return 0; +} + +static int cc2_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, long *val) +{ + struct cc2_data *data = dev_get_drvdata(dev); + int ret; + + switch (type) { + case hwmon_temp: + mutex_lock(&data->i2c_lock); + ret = data->config->measurement(data, type, val); + mutex_unlock(&data->i2c_lock); + break; + case hwmon_humidity: + switch (attr) { + case hwmon_humidity_input: + mutex_lock(&data->i2c_lock); + ret = data->config->measurement(data, type, val); + mutex_unlock(&data->i2c_lock); + break; + case hwmon_humidity_min: + *val = data->alarm.min; + break; + case hwmon_humidity_min_hyst: + *val = data->alarm.min_hyst; + break; + case hwmon_humidity_max: + *val = data->alarm.max; + break; + case hwmon_humidity_max_hyst: + *val = data->alarm.max_hyst; + break; + case hwmon_humidity_min_alarm: + ret = cc2_humidity_min_alarm_status(data, val); + if (ret < 0) + return -EIO; + break; + case hwmon_humidity_max_alarm: + ret = cc2_humidity_max_alarm_status(data, val); + if (ret < 0) + return -EIO; + break; + default: + return -EOPNOTSUPP; + } + break; + default: + return -EOPNOTSUPP; + } + + return ret; +} + +static int cc2_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, long val) +{ + struct cc2_data *data = dev_get_drvdata(dev); + u8 cmd[CC2_EEPROM_SIZE]; + u16 arg[CC2_EEPROM_SIZE]; + int ret; + + if (type != hwmon_humidity) + return -EOPNOTSUPP; + + switch (attr) { + case hwmon_humidity_min: + if (val < CC2_RH_MIN || val > CC2_RH_MAX) + return -EINVAL; + + cmd[0] = CC2_W_ALARM_LOW_ON; + arg[0] = cc2_rh_to_reg(val); + /* alarm low off must be updated to keep the hysteresis */ + cmd[1] = CC2_W_ALARM_LOW_OFF; + arg[1] = cc2_rh_to_reg(val + data->alarm.min_hyst); + ret = cc2_update_eeprom(data, cmd, arg, 2); + if (ret < 0) + return ret; + + data->alarm.min = cc2_rh_in_device_resolution(val); + break; + case hwmon_humidity_min_hyst: + if (val < CC2_RH_MIN || val + data->alarm.min > CC2_RH_MAX) + return -EINVAL; + + cmd[0] = CC2_W_ALARM_LOW_OFF; + arg[0] = cc2_rh_to_reg(data->alarm.min + val); + ret = cc2_update_eeprom(data, cmd, arg, 1); + if (ret < 0) + return ret; + + data->alarm.min_hyst = cc2_rh_in_device_resolution(val); + break; + case hwmon_humidity_max: + if (val < CC2_RH_MIN || val > CC2_RH_MAX) + return -EINVAL; + + cmd[0] = CC2_W_ALARM_HIGH_ON; + arg[0] = cc2_rh_to_reg(val); + /* alarm high off must be updated to keep the hysteresis */ + cmd[1] = CC2_W_ALARM_HIGH_OFF; + arg[1] = cc2_rh_to_reg(val - data->alarm.max_hyst); + ret = cc2_update_eeprom(data, cmd, arg, 2); + if (ret < 0) + return ret; + + data->alarm.max = cc2_rh_in_device_resolution(val); + break; + case hwmon_humidity_max_hyst: + if (val < CC2_RH_MIN || data->alarm.max - val < CC2_RH_MIN) + return -EINVAL; + + cmd[0] = CC2_W_ALARM_HIGH_OFF; + arg[0] = cc2_rh_to_reg(data->alarm.max - val); + ret = cc2_update_eeprom(data, cmd, arg, 1); + if (ret < 0) + return ret; + + data->alarm.max_hyst = cc2_rh_in_device_resolution(val); + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int cc2_disable(struct cc2_data *data) +{ + int ret = 0; + + if (data->regulator && regulator_is_enabled(data->regulator)) + ret = regulator_disable(data->regulator); + + return ret; +} + +static int cc2_request_ready_irq(struct cc2_data *data, struct device *dev) +{ + int ret = 0; + + data->irq_ready = fwnode_irq_get_byname(dev_fwnode(dev), "ready"); + if (data->irq_ready > 0) { + init_completion(&data->complete); + ret = devm_request_threaded_irq(dev, data->irq_ready, NULL, + cc2_ready_interrupt, + IRQF_ONESHOT | + IRQF_TRIGGER_RISING, + dev_name(dev), data); + } + + return ret; +} + +static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) +{ + int ret; + + data->irq_low = fwnode_irq_get_byname(dev_fwnode(dev), "low"); + if (data->irq_low > 0) { + ret = devm_request_threaded_irq(dev, data->irq_low, NULL, + cc2_low_interrupt, + IRQF_ONESHOT | + IRQF_TRIGGER_RISING, + dev_name(dev), data); + if (!ret) + data->alarm.rh_low_visible = true; + } + + data->irq_high = fwnode_irq_get_byname(dev_fwnode(dev), "high"); + if (data->irq_high > 0) { + ret = devm_request_threaded_irq(dev, data->irq_high, NULL, + cc2_high_interrupt, + IRQF_ONESHOT | + IRQF_TRIGGER_RISING, + dev_name(dev), data); + if (!ret) + data->alarm.rh_high_visible = true; + } + + return ret; +} + +static const struct hwmon_channel_info *cc2_info[] = { + HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT), + HWMON_CHANNEL_INFO(humidity, HWMON_H_INPUT | HWMON_H_MIN | HWMON_H_MAX | + HWMON_H_MIN_HYST | HWMON_H_MAX_HYST | + HWMON_H_MIN_ALARM | HWMON_H_MAX_ALARM), + NULL +}; + +static const struct hwmon_ops cc2_hwmon_ops = { + .is_visible = cc2_is_visible, + .read = cc2_read, + .write = cc2_write, +}; + +static const struct hwmon_chip_info cc2_chip_info = { + .ops = &cc2_hwmon_ops, + .info = cc2_info, +}; + +static const struct cc2_config cc2_config[] = { + [cc2dxx] = { + .measurement = cc2dxx_meas, + }, + [cc2dxxs] = { + .measurement = cc2dxxs_meas, + }, +}; + +static const struct i2c_device_id cc2_id[] = { + { "cc2dxx", cc2dxx }, + { "cc2dxxs", cc2dxxs }, + { } +}; +MODULE_DEVICE_TABLE(i2c, cc2_id); + +static const struct of_device_id cc2_of_match[] = { + { + .compatible = "amphenol,cc2dxx", + .data = (void *)cc2dxx, + }, + { + .compatible = "amphenol,cc2dxxs", + .data = (void *)cc2dxxs, + }, + { }, +}; +MODULE_DEVICE_TABLE(of, cc2_of_match); + +static int cc2_probe(struct i2c_client *client) +{ + struct cc2_data *data; + struct device *dev = &client->dev; + enum cc2_ids chip; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -EOPNOTSUPP; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + i2c_set_clientdata(client, data); + + mutex_init(&data->i2c_lock); + mutex_init(&data->alarm_lock); + + data->client = client; + + if (client->dev.of_node) + chip = (uintptr_t)of_device_get_match_data(&client->dev); + else + chip = i2c_match_id(cc2_id, client)->driver_data; + + data->config = &cc2_config[chip]; + + ret = cc2_request_ready_irq(data, dev); + if (ret) + return ret; + + data->regulator = devm_regulator_get_optional(dev, "vdd"); + if (!IS_ERR(data->regulator)) { + ret = cc2_retrive_alarm_config(data); + if (ret) + goto cleanup; + } else { + /* No access to EEPROM without regulator: no alarm control */ + goto dev_register; + } + + ret = cc2_request_alarm_irqs(data, dev); + if (ret) + goto cleanup; + +dev_register: + data->hwmon = devm_hwmon_device_register_with_info(dev, client->name, + data, &cc2_chip_info, + NULL); + if (IS_ERR(data->hwmon)) { + ret = PTR_ERR(data->hwmon); + goto cleanup; + } + + return 0; + +cleanup: + if (cc2_disable(data)) + dev_dbg(dev, "Failed to disable device"); + + return dev_err_probe(dev, ret, + "Unable to register hwmon device\n"); +} + +static void cc2_remove(struct i2c_client *client) +{ + struct cc2_data *data = i2c_get_clientdata(client); + int ret = cc2_disable(data); + + if (ret) + dev_dbg(&client->dev, "Failed to disable device"); +} + +static struct i2c_driver cc2_driver = { + .driver = { + .name = CC2_DEV_NAME, + .of_match_table = cc2_of_match, + }, + .probe = cc2_probe, + .remove = cc2_remove, +}; +module_i2c_driver(cc2_driver); + +MODULE_AUTHOR("Javier Carrasco "); +MODULE_DESCRIPTION("Amphenol ChipCap 2 humidity and temperature sensor driver"); +MODULE_LICENSE("GPL"); From patchwork Wed Nov 8 15:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13450263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF0A5C4167B for ; Wed, 8 Nov 2023 15:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233977AbjKHPhu (ORCPT ); Wed, 8 Nov 2023 10:37:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234133AbjKHPhl (ORCPT ); Wed, 8 Nov 2023 10:37:41 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054DB1FDA; Wed, 8 Nov 2023 07:37:39 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-53e3b8f906fso11810675a12.2; Wed, 08 Nov 2023 07:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699457857; x=1700062657; 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=bezVq5NfxD+KhZfkFbZwhXk3BKYmWSQOuA8lFp/Q5CE=; b=Gb3o2tRVoT1jK2jyT4CtxQpuSprDD5KzOM5tizpN9sEJ3fZ+cC7P3hoYKOezeh/LX9 6WNTPlsj8TRVhxV2QlpfQ7GUv3AvomKMv0VhBkcifmg2jSXZZ3TT9IDl1t7g9LT+8g6Q DpOWdC1SuqGl+n6roua8k/53GyNOLzX4WHtX8g94CpyTFM6akSuqCZBYvFFEt5io6B3I nVihQX1uGh/NGtxwMoQGYxnwvc3ipaxr+eS07nm7b4TiY5ADHNT/CVCkRtP2f05nRZga dNeXyjgCYmj0gWD2zAgog7FVklRP3pW69HbxzUP+CqnZWJmzDciz6SaZs2Diej8CmaJf sAYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699457857; x=1700062657; 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=bezVq5NfxD+KhZfkFbZwhXk3BKYmWSQOuA8lFp/Q5CE=; b=wkGM7aI0YjiQ2ggnFNADH93nTmqK8kRnn9HsPDpbGo5J11LYiikeS15u/7Z0BXxx3J +XBDK82meZeUvnPk5sEd0eNoq3uk1tRNewmVmHOEHmJnnWzgberjtGXiMaT2uU7fJj+L KaTk337jHtGnMcDeZ+8ClsIlkcBlFuyK1qTClzfLnlmEH8aQdOnGYFTvGWb2WBWo4Rt6 3kWCY1gncbzmbqvSTFvf1LyCdNoeBsH9vd7RIfvmOH8iD8NxDsoCYD+5jKbbwDplpLbX GWV7xPwzkaqX66r2Ki2+Pm/MUjY56RQ9g9/RdEoR28rZaNHIULUAjKKLSGldx+OeuaAc SP9g== X-Gm-Message-State: AOJu0Yx5xt3OSfuuk/TcTJMuRhT9fbtkOy5a6p5bFu7Z6dEY0NGfXJTV xvcxJuXkz4KsyByKgG2KX2w= X-Google-Smtp-Source: AGHT+IFf5dosgoD1Z/beNxINcyL8uGuFojj7oTj/e5xSGmjEzmvCdA840NrOJrGiIFsuVMbiqbv4PA== X-Received: by 2002:a50:8d0b:0:b0:53e:37d1:a31f with SMTP id s11-20020a508d0b000000b0053e37d1a31fmr1918407eds.28.1699457857488; Wed, 08 Nov 2023 07:37:37 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-840c-82c6-68fb-9a49.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:840c:82c6:68fb:9a49]) by smtp.gmail.com with ESMTPSA id j28-20020a508a9c000000b0053e3839fc79sm7009966edj.96.2023.11.08.07.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:37:37 -0800 (PST) From: Javier Carrasco Date: Wed, 08 Nov 2023 16:37:30 +0100 Subject: [PATCH v2 4/4] dt-bindings: hwmon: Add Amphenol ChipCap 2 MIME-Version: 1.0 Message-Id: <20231020-topic-chipcap2-v2-4-f5c325966fdb@gmail.com> References: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> In-Reply-To: <20231020-topic-chipcap2-v2-0-f5c325966fdb@gmail.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jean Delvare , Guenter Roeck , Jonathan Corbet , Liam Girdwood , Mark Brown Cc: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1699457849; l=2364; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=d+q16++TF3EsSideU+hM8FP/AieHkXH5vyhNQwTbFHQ=; b=vaBHUKRj7Ud6Yd2UG7HEi9UGVO2wB07a9nPq2uSl7p2TM4ijNt5tX9Kj4Pjen0NvzxNPd0AZZ g8NrFJtNv7NCbvCJ4fVjYQUEcKUv42HoMOv4KHvrKWvc4Rfol1EKHW0 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add device tree bindings and an example for the ChipCap 2 humidity and temperature sensor. Signed-off-by: Javier Carrasco --- .../bindings/hwmon/amphenol,chipcap2.yaml | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml b/Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml new file mode 100644 index 000000000000..8bb6daa293d3 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/amphenol,chipcap2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ChipCap 2 humidity and temperature iio sensor + +maintainers: + - Javier Carrasco + +description: | + Relative humidity and temperature sensor on I2C bus. + + Datasheets: + https://www.amphenol-sensors.com/en/telaire/humidity/527-humidity-sensors/3095-chipcap-2 + +properties: + compatible: + enum: + - amphenol,cc2dxx + - amphenol,cc2dxxs + + reg: + maxItems: 1 + + interrupts: + items: + - description: measurement ready indicator + - description: low humidity alarm + - description: high humidity alarm + + interrupt-names: + items: + - const: ready + - const: low + - const: high + + vdd-supply: + description: + Dedicated, controllable supply-regulator to reset the device and + enter in command mode. + If not defined, no alarms will be available. + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + humidity@28 { + compatible = "amphenol,cc2dxxs"; + reg = <0x28>; + interrupt-parent = <&gpio>; + interrupts = <4 IRQ_TYPE_EDGE_RISING>, + <5 IRQ_TYPE_EDGE_RISING>, + <6 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ready", "low", "high"; + vdd-supply = <®_vdd>; + }; + };