All of lore.kernel.org
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: jikos@kernel.org
Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"José Expósito" <jose.exposito89@gmail.com>
Subject: [PATCH 2/2] HID: uclogic: Expose firmware name via sysfs
Date: Thu, 21 Mar 2024 15:38:05 +0100	[thread overview]
Message-ID: <20240321144553.262409-3-jose.exposito89@gmail.com> (raw)
In-Reply-To: <20240321144553.262409-1-jose.exposito89@gmail.com>

Some vendors reuse the same product ID for different tablets, making it
difficult for userspace to figure out which table is connected.
While matching the device name has been used in the past by userspace to
workaround this limitation, some devices have shown that this is not
always a valid approach [1].

However, if userspace could access the firmware version name, it would
be possible to know which tablet is actually connected by matching it
against a list of known firmware names [2].

This patch exposes the firmware version name via sysfs attribute.

Link: https://github.com/linuxwacom/libwacom/issues/609  [1]
Link: https://github.com/linuxwacom/libwacom/issues/610  [2]
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-uclogic-core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
index ad74cbc9a0aa..1862ca5805a7 100644
--- a/drivers/hid/hid-uclogic-core.c
+++ b/drivers/hid/hid-uclogic-core.c
@@ -50,6 +50,17 @@ static void uclogic_inrange_timeout(struct timer_list *t)
 	input_sync(input);
 }
 
+static ssize_t fw_name_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct hid_device *hdev = to_hid_device(dev);
+	struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
+
+	return sysfs_emit(buf, "%s\n", drvdata->params.fw_name);
+}
+
+static DEVICE_ATTR_RO(fw_name);
+
 static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 					unsigned int *rsize)
 {
@@ -217,6 +228,10 @@ static int uclogic_probe(struct hid_device *hdev,
 		goto failure;
 	}
 
+	rc = device_create_file(&hdev->dev, &dev_attr_fw_name);
+	if (rc)
+		hid_warn(hdev, "Unable to create sysfs attribute \"fw_name\", errno %d\n", rc);
+
 	return 0;
 failure:
 	/* Assume "remove" might not be called if "probe" failed */
@@ -477,6 +492,7 @@ static void uclogic_remove(struct hid_device *hdev)
 	del_timer_sync(&drvdata->inrange_timer);
 	hid_hw_stop(hdev);
 	kfree(drvdata->desc_ptr);
+	device_remove_file(&hdev->dev, &dev_attr_fw_name);
 	uclogic_params_cleanup(&drvdata->params);
 }
 
-- 
2.44.0


      parent reply	other threads:[~2024-03-21 14:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 14:38 [PATCH 0/2] Expose firmware name to identify tablets in libwacom José Expósito
2024-03-21 14:38 ` [PATCH 1/2] HID: uclogic: Store firmware name in params José Expósito
2024-03-21 15:01   ` Benjamin Tissoires
2024-03-22 10:06     ` José Expósito
2024-03-21 14:38 ` José Expósito [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240321144553.262409-3-jose.exposito89@gmail.com \
    --to=jose.exposito89@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.