Skip to contentSkip to conversation

w1_therm: adding alarm sysfs entry to set device internal alarms values

PATCH In review Akira Shimahara 1 participant 1 message Apr 29, 2020 W1 dallas's 1-wire bus

lore
Share & tools
lore
#0 lore raw

PATCH v4 8/9 w1_therm: adding alarm sysfs entry to set device internal alarms values

Adding device alarms settings by a dedicated sysfs entry alarms (RW):
read or write TH and TL in the device RAM. Checking devices in alarm state could be performed using the master search command.

As alarms temperature level are store in a 8 bit register on the device and are signed values, a safe cast shall be performed using the min and max temperature that device are able to measure. This is done by int_to_short inline function.

Updating doc in Documentation/ABI/testing/sysfs-driver-w1_therm accordingly.

---
 .../ABI/testing/sysfs-driver-w1_therm         |  15 ++
 drivers/w1/slaves/w1_therm.c                  | 138 ++++++++++++++++++
 drivers/w1/slaves/w1_therm.h                  |  22 +++
 3 files changed, 175 insertions(+)
Documentation/ABI/testing/sysfs-driver-w1_therm +15 -0
index 279e13d..39488a4 100644
@@ -1,3 +1,18 @@
+What:		/sys/bus/w1/devices/.../alarms
+Date:		Apr 2020
+Contact:	Akira Shimahara <[email protected]>
+Description:
+		(RW) read or write TH and TL (Temperature High an Low) alarms.
+		Values shall be space separated and in the device range
+		(typical -55 degC to 125 degC). Values are integer as they
+		are store in a 8bit register in the device.
+		Lowest value is automatically put to TL.
+		Once set, alarms could be search at master level, refer to
+		Documentation/w1/w1_generic.rst for detailed information
+Users:		any user space application which wants to communicate with
+		w1_term device
+
+
 What:		/sys/bus/w1/devices/.../eeprom
 Date:		Apr 2020
 Contact:	Akira Shimahara <[email protected]>
drivers/w1/slaves/w1_therm.c +138 -0

180 lines not on this page · raw message

drivers/w1/slaves/w1_therm.h +22 -0
index 6929991..d4c560a 100644
@@ -40,6 +40,9 @@
 #define EEPROM_CMD_WRITE    "save"	/* cmd for write eeprom sysfs */
 #define EEPROM_CMD_READ     "restore"	/* cmd for read eeprom sysfs */
 
+#define MIN_TEMP	-55	/* min temperature that can be mesured */
+#define MAX_TEMP	125	/* max temperature that can be mesured */
+
 /*----------------------------------Structs---------------------------------*/
 
 /**
@@ -159,6 +162,13 @@ static inline int conversion_time(struct w1_slave *sl);
  */
 static inline int temperature_from_RAM(struct w1_slave *sl, u8 rom[9]);
 
+/** int_to_short() safe casting of int to short
+ * min/max values are defined by macro
+ * @param i integer to be converted to short
+ * @return a short in the range of min/max value
+ */
+static inline s8 int_to_short(int i);
+
 /*---------------------------Hardware Functions-----------------------------*/
 
 /**
@@ -277,6 +287,17 @@ static ssize_t resolution_store(struct device *device,
 static ssize_t eeprom_store(struct device *device,
 	struct device_attribute *attr, const char *buf, size_t size);
 
+/** @brief A callback function to set the alarms level
+ *  @param device represents the master device
+ */
+static ssize_t alarms_store(struct device *device,
+	struct device_attribute *attr, const char *buf, size_t size);
+
+/** @brief A callback function to get the alarms level
+ *  @return Low and High alarm, separate by one space
+ */
+static ssize_t alarms_show(struct device *device,
+	struct device_attribute *attr, char *buf);
 /*-----------------------------Attributes declarations----------------------*/
 
 static DEVICE_ATTR_RW(w1_slave);
@@ -285,6 +306,7 @@ static DEVICE_ATTR_RO(temperature);
 static DEVICE_ATTR_RO(ext_power);
 static DEVICE_ATTR_RW(resolution);
 static DEVICE_ATTR_WO(eeprom);
+static DEVICE_ATTR_RW(alarms);
 
 /*--------------------------Interface Functions-----------------------------*/
 
Signature · 1 line
2.26.2