diff mbox series

[v2,4/5] rtc-rv8803: extend sysfs to trigger internal ts-event

Message ID 20250116131532.471040-5-markus.burri@mt.com
State New
Headers show
Series rtc-rv8803: Implement timestamp trigger over event pins | expand

Commit Message

Markus Burri Jan. 16, 2025, 1:15 p.m. UTC
Extend sysfs to trigger an internal time-stamp event.

The trigger function can be used from an application to trigger an
internal time-stamp event.

Signed-off-by: Markus Burri <markus.burri@mt.com>
---
 .../ABI/testing/sysfs-class-rtc-tamper        |  7 ++++
 drivers/rtc/rtc-rv8803.c                      | 33 +++++++++++++++++++
 2 files changed, 40 insertions(+)

Comments

Manuel Traut Feb. 19, 2025, 4:23 p.m. UTC | #1
On Thu, Jan 16, 2025 at 02:15:31PM +0100, Markus Burri wrote:
> Extend sysfs to trigger an internal time-stamp event.
> 
> The trigger function can be used from an application to trigger an
> internal time-stamp event.
> 
> Signed-off-by: Markus Burri <markus.burri@mt.com>
Reviewed-by: Manuel Traut <manuel.traut@mt.com>

> ---
>  .../ABI/testing/sysfs-class-rtc-tamper        |  7 ++++
>  drivers/rtc/rtc-rv8803.c                      | 33 +++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-rtc-tamper b/Documentation/ABI/testing/sysfs-class-rtc-tamper
> index f035d0fa5..2fd6578a6 100644
> --- a/Documentation/ABI/testing/sysfs-class-rtc-tamper
> +++ b/Documentation/ABI/testing/sysfs-class-rtc-tamper
> @@ -18,4 +18,11 @@ Description:	(RO) Attribute to read the stored timestamps form buffer FIFO.
>  		- "1234.567 EVIN1=1" for a trigger from EVIN1 changed from low to high
>  		- "1234.567 EVIN1=0 EVIN2=1 for a simultaneous trigger of EVIN1 changed to low and
>  		  EVIN2 changed to high.
> +		- "1234.567 CMD=0" for a internal trigger
>  
> +What:		/sys/class/rtc/rtcX/tamper/trigger
> +Date:		January 2025
> +KernelVersion:	6.13
> +Contact:	Markus Burri <markus.burri@mt.com>
> +Description:	(WO) Attribute to trigger an internal timestamp event
> +		Write a '1' to trigger an internal event and store a timestamp.
> diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
> index 764e654c2..ca3a19162 100644
> --- a/drivers/rtc/rtc-rv8803.c
> +++ b/drivers/rtc/rtc-rv8803.c
> @@ -904,12 +904,45 @@ static ssize_t read_show(struct device *dev, struct device_attribute *attr, char
>  	return offset;
>  }
>  
> +static ssize_t trigger_store(struct device *dev, struct device_attribute *attr, const char *buf,
> +			     size_t count)
> +{
> +	struct rv8803_data *rv8803 = dev_get_drvdata(dev->parent);
> +	struct i2c_client *client = rv8803->client;
> +	int ret;
> +	unsigned long tmo;
> +
> +	guard(mutex)(&rv8803->flags_lock);
> +
> +	/* CMDTRGEN */
> +	ret = rv8803_write_reg(client, RX8901_WRCMD_CFG, BIT(0));
> +	if (ret < 0)
> +		return ret;
> +	ret = rv8803_write_reg(client, RX8901_WRCMD_TRG, 0xFF);
> +	if (ret < 0)
> +		return ret;
> +
> +	tmo = jiffies + msecs_to_jiffies(100); /* timeout 100ms */
> +	do {
> +		usleep_range(10, 2000);
> +		ret = rv8803_read_reg(client, RX8901_WRCMD_TRG);
> +		if (ret < 0)
> +			return ret;
> +		if (time_after(jiffies, tmo))
> +			return -EBUSY;
> +	} while (ret);
> +
> +	return count;
> +}
> +
>  static DEVICE_ATTR_WO(enable);
>  static DEVICE_ATTR_RO(read);
> +static DEVICE_ATTR_WO(trigger);
>  
>  static struct attribute *rv8803_rtc_event_attrs[] = {
>  	&dev_attr_enable.attr,
>  	&dev_attr_read.attr,
> +	&dev_attr_trigger.attr,
>  	NULL
>  };
>  
> -- 
> 2.39.5
>
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-class-rtc-tamper b/Documentation/ABI/testing/sysfs-class-rtc-tamper
index f035d0fa5..2fd6578a6 100644
--- a/Documentation/ABI/testing/sysfs-class-rtc-tamper
+++ b/Documentation/ABI/testing/sysfs-class-rtc-tamper
@@ -18,4 +18,11 @@  Description:	(RO) Attribute to read the stored timestamps form buffer FIFO.
 		- "1234.567 EVIN1=1" for a trigger from EVIN1 changed from low to high
 		- "1234.567 EVIN1=0 EVIN2=1 for a simultaneous trigger of EVIN1 changed to low and
 		  EVIN2 changed to high.
+		- "1234.567 CMD=0" for a internal trigger
 
+What:		/sys/class/rtc/rtcX/tamper/trigger
+Date:		January 2025
+KernelVersion:	6.13
+Contact:	Markus Burri <markus.burri@mt.com>
+Description:	(WO) Attribute to trigger an internal timestamp event
+		Write a '1' to trigger an internal event and store a timestamp.
diff --git a/drivers/rtc/rtc-rv8803.c b/drivers/rtc/rtc-rv8803.c
index 764e654c2..ca3a19162 100644
--- a/drivers/rtc/rtc-rv8803.c
+++ b/drivers/rtc/rtc-rv8803.c
@@ -904,12 +904,45 @@  static ssize_t read_show(struct device *dev, struct device_attribute *attr, char
 	return offset;
 }
 
+static ssize_t trigger_store(struct device *dev, struct device_attribute *attr, const char *buf,
+			     size_t count)
+{
+	struct rv8803_data *rv8803 = dev_get_drvdata(dev->parent);
+	struct i2c_client *client = rv8803->client;
+	int ret;
+	unsigned long tmo;
+
+	guard(mutex)(&rv8803->flags_lock);
+
+	/* CMDTRGEN */
+	ret = rv8803_write_reg(client, RX8901_WRCMD_CFG, BIT(0));
+	if (ret < 0)
+		return ret;
+	ret = rv8803_write_reg(client, RX8901_WRCMD_TRG, 0xFF);
+	if (ret < 0)
+		return ret;
+
+	tmo = jiffies + msecs_to_jiffies(100); /* timeout 100ms */
+	do {
+		usleep_range(10, 2000);
+		ret = rv8803_read_reg(client, RX8901_WRCMD_TRG);
+		if (ret < 0)
+			return ret;
+		if (time_after(jiffies, tmo))
+			return -EBUSY;
+	} while (ret);
+
+	return count;
+}
+
 static DEVICE_ATTR_WO(enable);
 static DEVICE_ATTR_RO(read);
+static DEVICE_ATTR_WO(trigger);
 
 static struct attribute *rv8803_rtc_event_attrs[] = {
 	&dev_attr_enable.attr,
 	&dev_attr_read.attr,
+	&dev_attr_trigger.attr,
 	NULL
 };