All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rc-core: export the hardware type to sysfs
@ 2017-04-29 10:03 David Härdeman
  2017-05-01 10:36 ` Sean Young
  0 siblings, 1 reply; 3+ messages in thread
From: David Härdeman @ 2017-04-29 10:03 UTC (permalink / raw)
  To: linux-media; +Cc: mchehab, sean

Exporting the hardware type makes it possible for userspace applications
to know what to expect from the hardware.

This makes it possible to write more user-friendly userspace apps.

Note that the size of sysfs_groups[] in struct rc_dev is not changed
by this patch because it was already large enough for one more group.

Signed-off-by: David Härdeman <david@hardeman.nu>
---
 drivers/media/rc/rc-main.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 85f95441b85b..e0f9b322ab02 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1294,6 +1294,38 @@ static ssize_t store_protocols(struct device *device,
 }
 
 /**
+ * show_hwtype() - shows the hardware type in sysfs
+ * @device:	the &struct device descriptor
+ * @attr:	the &struct device_attribute
+ * @buf:	a pointer to the output buffer
+ *
+ * This callback function is used to get the hardware type of an rc device.
+ * It is triggered by reading /sys/class/rc/rc?/hwtype.
+ *
+ * Return: the number of bytes read or a negative error code.
+ */
+static ssize_t show_hwtype(struct device *device,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	struct rc_dev *dev = to_rc_dev(device);
+
+	switch (dev->driver_type) {
+	case RC_DRIVER_SCANCODE:
+		return sprintf(buf, "scancode\n");
+	case RC_DRIVER_IR_RAW_TX:
+		return sprintf(buf, "ir-tx\n");
+	case RC_DRIVER_IR_RAW:
+		if (dev->tx_ir)
+			return sprintf(buf, "ir-tx-rx\n");
+		else
+			return sprintf(buf, "ir-rx\n");
+	default:
+		return sprintf(buf, "<unknown>\n");
+	}
+}
+
+/**
  * show_filter() - shows the current scancode filter value or mask
  * @device:	the device descriptor
  * @attr:	the device attribute struct
@@ -1613,6 +1645,7 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
  * Static device attribute struct with the sysfs attributes for IR's
  */
 static DEVICE_ATTR(protocols, 0644, show_protocols, store_protocols);
+static DEVICE_ATTR(hwtype, 0444, show_hwtype, NULL);
 static DEVICE_ATTR(wakeup_protocols, 0644, show_wakeup_protocols,
 		   store_wakeup_protocols);
 static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR,
@@ -1633,6 +1666,15 @@ static struct attribute_group rc_dev_protocol_attr_grp = {
 	.attrs	= rc_dev_protocol_attrs,
 };
 
+static struct attribute *rc_dev_hwtype_attrs[] = {
+	&dev_attr_hwtype.attr,
+	NULL,
+};
+
+static struct attribute_group rc_dev_hwtype_attr_grp = {
+	.attrs = rc_dev_hwtype_attrs,
+};
+
 static struct attribute *rc_dev_filter_attrs[] = {
 	&dev_attr_filter.attr.attr,
 	&dev_attr_filter_mask.attr.attr,
@@ -1863,6 +1905,7 @@ int rc_register_device(struct rc_dev *dev)
 		dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp;
 	if (dev->s_wakeup_filter)
 		dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp;
+	dev->sysfs_groups[attr++] = &rc_dev_hwtype_attr_grp;
 	dev->sysfs_groups[attr++] = NULL;
 
 	if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rc-core: export the hardware type to sysfs
  2017-04-29 10:03 [PATCH] rc-core: export the hardware type to sysfs David Härdeman
@ 2017-05-01 10:36 ` Sean Young
  2017-05-01 12:38   ` David Härdeman
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Young @ 2017-05-01 10:36 UTC (permalink / raw)
  To: David Härdeman; +Cc: linux-media, mchehab

On Sat, Apr 29, 2017 at 12:03:29PM +0200, David Härdeman wrote:
> Exporting the hardware type makes it possible for userspace applications
> to know what to expect from the hardware.
> 
> This makes it possible to write more user-friendly userspace apps.

This duplicates lirc features (LIRC_GET_FEATURES ioctl); the one exception
is that the scancode-only devices which have no lirc device, but there
are patches which change that.

https://patchwork.linuxtv.org/patch/39593/


Sean

> 
> Note that the size of sysfs_groups[] in struct rc_dev is not changed
> by this patch because it was already large enough for one more group.
> 
> Signed-off-by: David Härdeman <david@hardeman.nu>
> ---
>  drivers/media/rc/rc-main.c |   43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
> index 85f95441b85b..e0f9b322ab02 100644
> --- a/drivers/media/rc/rc-main.c
> +++ b/drivers/media/rc/rc-main.c
> @@ -1294,6 +1294,38 @@ static ssize_t store_protocols(struct device *device,
>  }
>  
>  /**
> + * show_hwtype() - shows the hardware type in sysfs
> + * @device:	the &struct device descriptor
> + * @attr:	the &struct device_attribute
> + * @buf:	a pointer to the output buffer
> + *
> + * This callback function is used to get the hardware type of an rc device.
> + * It is triggered by reading /sys/class/rc/rc?/hwtype.
> + *
> + * Return: the number of bytes read or a negative error code.
> + */
> +static ssize_t show_hwtype(struct device *device,
> +			   struct device_attribute *attr,
> +			   char *buf)
> +{
> +	struct rc_dev *dev = to_rc_dev(device);
> +
> +	switch (dev->driver_type) {
> +	case RC_DRIVER_SCANCODE:
> +		return sprintf(buf, "scancode\n");
> +	case RC_DRIVER_IR_RAW_TX:
> +		return sprintf(buf, "ir-tx\n");
> +	case RC_DRIVER_IR_RAW:
> +		if (dev->tx_ir)
> +			return sprintf(buf, "ir-tx-rx\n");
> +		else
> +			return sprintf(buf, "ir-rx\n");
> +	default:
> +		return sprintf(buf, "<unknown>\n");
> +	}
> +}
> +
> +/**
>   * show_filter() - shows the current scancode filter value or mask
>   * @device:	the device descriptor
>   * @attr:	the device attribute struct
> @@ -1613,6 +1645,7 @@ static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
>   * Static device attribute struct with the sysfs attributes for IR's
>   */
>  static DEVICE_ATTR(protocols, 0644, show_protocols, store_protocols);
> +static DEVICE_ATTR(hwtype, 0444, show_hwtype, NULL);
>  static DEVICE_ATTR(wakeup_protocols, 0644, show_wakeup_protocols,
>  		   store_wakeup_protocols);
>  static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR,
> @@ -1633,6 +1666,15 @@ static struct attribute_group rc_dev_protocol_attr_grp = {
>  	.attrs	= rc_dev_protocol_attrs,
>  };
>  
> +static struct attribute *rc_dev_hwtype_attrs[] = {
> +	&dev_attr_hwtype.attr,
> +	NULL,
> +};
> +
> +static struct attribute_group rc_dev_hwtype_attr_grp = {
> +	.attrs = rc_dev_hwtype_attrs,
> +};
> +
>  static struct attribute *rc_dev_filter_attrs[] = {
>  	&dev_attr_filter.attr.attr,
>  	&dev_attr_filter_mask.attr.attr,
> @@ -1863,6 +1905,7 @@ int rc_register_device(struct rc_dev *dev)
>  		dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp;
>  	if (dev->s_wakeup_filter)
>  		dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp;
> +	dev->sysfs_groups[attr++] = &rc_dev_hwtype_attr_grp;
>  	dev->sysfs_groups[attr++] = NULL;
>  
>  	if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rc-core: export the hardware type to sysfs
  2017-05-01 10:36 ` Sean Young
@ 2017-05-01 12:38   ` David Härdeman
  0 siblings, 0 replies; 3+ messages in thread
From: David Härdeman @ 2017-05-01 12:38 UTC (permalink / raw)
  To: Sean Young; +Cc: linux-media, mchehab

On Mon, May 01, 2017 at 11:36:13AM +0100, Sean Young wrote:
>On Sat, Apr 29, 2017 at 12:03:29PM +0200, David Härdeman wrote:
>> Exporting the hardware type makes it possible for userspace applications
>> to know what to expect from the hardware.
>> 
>> This makes it possible to write more user-friendly userspace apps.
>
>This duplicates lirc features (LIRC_GET_FEATURES ioctl); the one exception
>is that the scancode-only devices which have no lirc device, but there
>are patches which change that.

The intention was to let userspace have a way of knowing whether to
expect any lirc device to show up at all. If some class of devices can't
have lirc devices (looking at the patch you linked to that'd still be
CEC?) then I think it's still useful?

-- 
David Härdeman

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-01 12:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-29 10:03 [PATCH] rc-core: export the hardware type to sysfs David Härdeman
2017-05-01 10:36 ` Sean Young
2017-05-01 12:38   ` David Härdeman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.