Skip to contentSkip to conversation

hwmon: Add support for Amphenol ChipCap 2

PATCH Applied Javier Carrasco 2 participants 11 messages Jan 30, 2024 – Feb 2, 2024

Subsystems (4)
lore
Share & tools
lore

Javier Carrasco

author maintainer
#0 lore raw

v6 cover hwmon: Add support for Amphenol ChipCap 2

This series adds support and documentation for the Amphenol ChipCap 2 humidity and temperature sensor in its digital version.

The Chipcap 2 is an I2C device that provides 14-bit humidity and temperature measurements as well as low (minimum) and high (maximum) humidity alarms. A ready signal is also available to reduce delays while fetching data.

The proposed driver implements the logic to perform measurements with and without ready signal, EEPROM configuration and alarm signaling.

The features this driver does not support (I2C address and command window length modification) have been documented in the "Known Issues" section.

The complete supported functionality has been tested with a CC2D33S sensor connected to a Raspberry Pi Zero 2 w.
Different device tree node definitions (with and without ready and/or alarm signals) have been positively tested.

---
Changes in v6:
- chipcap2.c: remove TODO about regulator delays (handled by the
regulator core).
- chipcap2.c: add comment to clarify regularor enable checks (exclusive regulator).
- chipcap2.c: simplify irq handling (irqs disabled while the device is switched off).
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- dt-bindings: add "amphenol,cc2d23" to "compatible" in the example.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- chipcap2.c: require exclusive regulator to trigger command mode.
- chipcap2.c: keep the device off until a measurement is required.
Because the device makes an automatic measurement after the power-up sequence, no differentiation between sleep and non-sleep modes is
required anymore.
- chipcap2.c: retrieve alarm settings from the device instead of storing them locally.
- dt-bindings: add vdd-supply to required properties.
- dt-bindings: default to 'amphenol,cc2d23' compatible (same
functionality for all compatibles).
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- ABI: sysfs-class-hwmon: documented humidity min/max alarms.
- General: reorder patches (bindings first to remove checkpatch
warnings).
- General: remove part number wildcards and use real part numbers.
- chipcap2.c: improve error path in probe function.
- chipcap2.c: fix error handling if regulator could not be registered.
- chipcap2.c: use absolute values for hysteresis (for both ABI
compatibility and simplicity).
- chipcap2.c: minor code-style fixes and variable renaming.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- vendor-prefixes: full company name in the vendor description (Krzystof Kozlowski)
- chipcap2.c: proper i2c_device_id table, coding style fixes, cleaner
error path in the probe function (Krzystof Kozlowski)
- dt-bindings: per-item description and lowercase names (Krzystof
Kozlowski)
- MAINTAINERS: fix manufacturer name (Krzystof Kozlowski)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Javier Carrasco (5):
dt-bindings: vendor-prefixes: add Amphenol
hwmon: (core) Add support for humidity min/max alarm
ABI: sysfs-class-hwmon: add descriptions for humidity min/max alarms
dt-bindings: hwmon: Add Amphenol ChipCap 2
hwmon: Add support for Amphenol ChipCap 2

 Documentation/ABI/testing/sysfs-class-hwmon        |  18 +
 .../bindings/hwmon/amphenol,chipcap2.yaml          |  77 ++
 .../devicetree/bindings/vendor-prefixes.yaml       |   2 +
 Documentation/hwmon/chipcap2.rst                   |  73 ++
 Documentation/hwmon/index.rst                      |   1 +
 MAINTAINERS                                        |   8 +
 drivers/hwmon/Kconfig                              |  10 +
 drivers/hwmon/Makefile                             |   1 +
 drivers/hwmon/chipcap2.c                           | 816 +++++++++++++++++++++
 drivers/hwmon/hwmon.c                              |   2 +
 include/linux/hwmon.h                              |   4 +
 11 files changed, 1012 insertions(+)

---
base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
change-id: 20231020-topic-chipcap2-e2d8985430c2

Best regards,

Signature · 1 line
Javier Carrasco <[email protected]>
author maintainer
#1 lore raw

PATCH v6 1/5 dt-bindings: vendor-prefixes: add Amphenol

Add vendor prefix for Amphenol (https://www.amphenol-sensors.com)

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 1a0dc04f1db4..25158559471c 100644
@@ -107,6 +107,8 @@ patternProperties:
     description: Amlogic, Inc.
   "^ampere,.*":
     description: Ampere Computing LLC
+  "^amphenol,.*":
+    description: Amphenol Advanced Sensors
   "^ampire,.*":
     description: Ampire Co., Ltd.
   "^ams,.*":
Signature · 1 line
2.39.2
maintainer Applied
#2 lore raw

Re: [PATCH v6 1/5] dt-bindings: vendor-prefixes: add Amphenol

Quoted 4 lines · Javier Carrasco

Add vendor prefix for Amphenol (https://www.amphenol-sensors.com)

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 1a0dc04f1db4..25158559471c 100644
@@ -107,6 +107,8 @@ patternProperties:
     description: Amlogic, Inc.
   "^ampere,.*":
     description: Ampere Computing LLC
+  "^amphenol,.*":
+    description: Amphenol Advanced Sensors
   "^ampire,.*":
     description: Ampire Co., Ltd.
   "^ams,.*":
author maintainer
#3 lore raw

PATCH v6 2/5 hwmon: (core) Add support for humidity min/max alarm

In reply to Javier Carrasco

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.

---
 drivers/hwmon/hwmon.c | 2 ++
 include/linux/hwmon.h | 4 ++++
 2 files changed, 6 insertions(+)
drivers/hwmon/hwmon.c +2 -0
index c7dd3f5b2bd5..b51d13f08d27 100644
@@ -586,6 +586,8 @@ static const char * const hwmon_humidity_attr_templates[] = {
 	[hwmon_humidity_fault] = "humidity%d_fault",
 	[hwmon_humidity_rated_min] = "humidity%d_rated_min",
 	[hwmon_humidity_rated_max] = "humidity%d_rated_max",
+	[hwmon_humidity_min_alarm] = "humidity%d_min_alarm",
+	[hwmon_humidity_max_alarm] = "humidity%d_max_alarm",
 };
 
 static const char * const hwmon_fan_attr_templates[] = {
include/linux/hwmon.h +4 -0
index 8cd6a6b33593..f553f8cd6946 100644
@@ -293,6 +293,8 @@ enum hwmon_humidity_attributes {
 	hwmon_humidity_fault,
 	hwmon_humidity_rated_min,
 	hwmon_humidity_rated_max,
+	hwmon_humidity_min_alarm,
+	hwmon_humidity_max_alarm,
 };
 
 #define HWMON_H_ENABLE			BIT(hwmon_humidity_enable)
@@ -306,6 +308,8 @@ enum hwmon_humidity_attributes {
 #define HWMON_H_FAULT			BIT(hwmon_humidity_fault)
 #define HWMON_H_RATED_MIN		BIT(hwmon_humidity_rated_min)
 #define HWMON_H_RATED_MAX		BIT(hwmon_humidity_rated_max)
+#define HWMON_H_MIN_ALARM		BIT(hwmon_humidity_min_alarm)
+#define HWMON_H_MAX_ALARM		BIT(hwmon_humidity_max_alarm)
 
 enum hwmon_fan_attributes {
 	hwmon_fan_enable,
Signature · 1 line
2.39.2
maintainer Applied
#4 lore raw

Re: [PATCH v6 2/5] hwmon: (core) Add support for humidity min/max alarm

Quoted 7 lines · Javier Carrasco

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.

Applied.

Thanks,
Guenter

Quoted 40 lines
---
 drivers/hwmon/hwmon.c | 2 ++
 include/linux/hwmon.h | 4 ++++
 2 files changed, 6 insertions(+)
drivers/hwmon/hwmon.c +2 -0
index c7dd3f5b2bd5..b51d13f08d27 100644
@@ -586,6 +586,8 @@ static const char * const hwmon_humidity_attr_templates[] = {
 	[hwmon_humidity_fault] = "humidity%d_fault",
 	[hwmon_humidity_rated_min] = "humidity%d_rated_min",
 	[hwmon_humidity_rated_max] = "humidity%d_rated_max",
+	[hwmon_humidity_min_alarm] = "humidity%d_min_alarm",
+	[hwmon_humidity_max_alarm] = "humidity%d_max_alarm",
 };
 
 static const char * const hwmon_fan_attr_templates[] = {
include/linux/hwmon.h +4 -0
index 8cd6a6b33593..f553f8cd6946 100644
@@ -293,6 +293,8 @@ enum hwmon_humidity_attributes {
 	hwmon_humidity_fault,
 	hwmon_humidity_rated_min,
 	hwmon_humidity_rated_max,
+	hwmon_humidity_min_alarm,
+	hwmon_humidity_max_alarm,
 };
 
 #define HWMON_H_ENABLE			BIT(hwmon_humidity_enable)
@@ -306,6 +308,8 @@ enum hwmon_humidity_attributes {
 #define HWMON_H_FAULT			BIT(hwmon_humidity_fault)
 #define HWMON_H_RATED_MIN		BIT(hwmon_humidity_rated_min)
 #define HWMON_H_RATED_MAX		BIT(hwmon_humidity_rated_max)
+#define HWMON_H_MIN_ALARM		BIT(hwmon_humidity_min_alarm)
+#define HWMON_H_MAX_ALARM		BIT(hwmon_humidity_max_alarm)
 
 enum hwmon_fan_attributes {
 	hwmon_fan_enable,
author maintainer
#5 lore raw

PATCH v6 3/5 ABI: sysfs-class-hwmon: add descriptions for humidity min/max alarms

In reply to Javier Carrasco

This attributes have been recently introduced and require the corresponding ABI documentation.

---
 Documentation/ABI/testing/sysfs-class-hwmon | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/ABI/testing/sysfs-class-hwmon +18 -0
index 3dac923c9b0e..8446e95f23b1 100644
@@ -968,6 +968,15 @@ Description:
 
 		RW
 
+What:		/sys/class/hwmon/hwmonX/humidityY_max_alarm
+Description:
+		Maximum humidity detection
+
+		- 0: OK
+		- 1: Maximum humidity detected
+
+		RO
+
 What:		/sys/class/hwmon/hwmonX/humidityY_max_hyst
 Description:
 		Humidity hysteresis value for max limit.
@@ -987,6 +996,15 @@ Description:
 
 		RW
 
+What:		/sys/class/hwmon/hwmonX/humidityY_min_alarm
+Description:
+		Minimum humidity detection
+
+		- 0: OK
+		- 1: Minimum humidity detected
+
+		RO
+
 What:		/sys/class/hwmon/hwmonX/humidityY_min_hyst
 Description:
 		Humidity hysteresis value for min limit.
Signature · 1 line
2.39.2
maintainer Applied
#6 lore raw

Re: [PATCH v6 3/5] ABI: sysfs-class-hwmon: add descriptions for humidity min/max alarms

Quoted 4 lines · Javier Carrasco

This attributes have been recently introduced and require the corresponding ABI documentation.

Applied.

Thanks,
Guenter

author maintainer
#7 lore raw

PATCH v6 4/5 dt-bindings: hwmon: Add Amphenol ChipCap 2

In reply to Javier Carrasco

Add device tree bindings and an example for the ChipCap 2 humidity and temperature sensor.

---
 .../bindings/hwmon/amphenol,chipcap2.yaml          | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml new file +77 -0
new file mode 100644
index 000000000000..17351fdbefce
@@ -0,0 +1,77 @@
+# 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 <[email protected]>
+
+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:
+    oneOf:
+      - const: amphenol,cc2d23
+      - items:
+          - enum:
+              - amphenol,cc2d23s
+              - amphenol,cc2d25
+              - amphenol,cc2d25s
+              - amphenol,cc2d33
+              - amphenol,cc2d33s
+              - amphenol,cc2d35
+              - amphenol,cc2d35s
+          - const: amphenol,cc2d23
+
+  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.
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        humidity@28 {
+            compatible = "amphenol,cc2d23s", "amphenol,cc2d23";
+            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 = <&reg_vdd>;
+        };
+    };
Signature · 1 line
2.39.2
author maintainer
#9 lore raw

PATCH v6 5/5 hwmon: Add support for Amphenol ChipCap 2

In reply to Javier Carrasco

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 includes the following part numbers:
- non-sleep measurement mode (CC2D23, CC2D25, CC2D33, CC2D35)
- sleep measurement mode (CC2D23S, CC2D25S, CC2D33S, CC2D35S)

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. A dedicated, external regulator is required for that.

This driver keeps the device off until a measurement or access to the EEPROM is required, making use of the first automatic measurement to avoid different code paths for sleep and non-sleep devices.

The minimum and maximum humidity alarms are configured with two registers per alarm: one stores the alarm threshold and the other one keeps the value that turns off the alarm. The alarm signals are only updated when a measurement is carried out.

---
 Documentation/hwmon/chipcap2.rst |  73 ++++
 Documentation/hwmon/index.rst    |   1 +
 MAINTAINERS                      |   8 +
 drivers/hwmon/Kconfig            |  10 +
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/chipcap2.c         | 816 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 909 insertions(+)
Documentation/hwmon/chipcap2.rst new file +73 -0
new file mode 100644
index 000000000000..dc165becc64c
@@ -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 <[email protected]>
+
+Description
+-----------
+
+This driver implements support for the Amphenol ChipCap 2, a humidity and
+temperature chip 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
+=============================== ======= ========================================
Documentation/hwmon/index.rst +1 -0
index c7ed1f73ac06..99ba35f47868 100644
@@ -51,6 +51,7 @@ Hardware Monitoring Kernel Drivers
    bel-pfe
    bpa-rs600
    bt1-pvt
+   chipcap2
    coretemp
    corsair-cpro
    corsair-psu
MAINTAINERS +8 -0
index 8d1052fa6a69..e70231735f71 100644
@@ -1098,6 +1098,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 <[email protected]>
+L:	[email protected]
+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 <[email protected]>
 M:	Zhou Peng <[email protected]>
drivers/hwmon/Kconfig +10 -0
index a608264da87d..cb38f30411f7 100644
@@ -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
drivers/hwmon/Makefile +1 -0
index 47be39af5c03..1ea4f42630fb 100644
@@ -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
drivers/hwmon/chipcap2.c new file +816 -0

816 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer Applied
#10 lore raw
Quoted 29 lines · Javier Carrasco

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 includes the following part numbers:
- non-sleep measurement mode (CC2D23, CC2D25, CC2D33, CC2D35)
- sleep measurement mode (CC2D23S, CC2D25S, CC2D33S, CC2D35S)

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. A dedicated, external regulator is required for that.

This driver keeps the device off until a measurement or access to the EEPROM is required, making use of the first automatic measurement to avoid different code paths for sleep and non-sleep devices.

Quoted 6 lines

The minimum and maximum humidity alarms are configured with two registers per alarm: one stores the alarm threshold and the other one keeps the value that turns off the alarm. The alarm signals are only updated when a measurement is carried out.

Applied.

Thanks,
Guenter