linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, patchwork-lst@pengutronix.de,
	kernel@pengutronix.de, Chris Healy <cphealy@gmail.com>
Subject: [PATCH 3/4] Input: exc3000: expose type, model and firmware revision as sysfs attributes
Date: Tue,  7 Jan 2020 18:17:39 +0100	[thread overview]
Message-ID: <20200107171741.10856-3-l.stach@pengutronix.de> (raw)
In-Reply-To: <20200107171741.10856-1-l.stach@pengutronix.de>

This can be used by userspace to determine if a firmware update should be
started.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/input/touchscreen/exc3000.c | 54 +++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index accee4fd1b97..ce83914d65ff 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -259,6 +259,47 @@ static int exc3000_populate_device_info(struct exc3000_data *data)
 	return 0;
 }
 
+static ssize_t exc3000_sysfs_type_show(struct device *dev,
+				       struct device_attribute *dattr,
+				       char *buf)
+{
+	struct exc3000_data *data = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%s\n", data->type);
+}
+static DEVICE_ATTR(type, 0444, exc3000_sysfs_type_show, NULL);
+
+static ssize_t exc3000_sysfs_model_show(struct device *dev,
+					struct device_attribute *dattr,
+					char *buf)
+{
+	struct exc3000_data *data = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%s\n", data->model);
+}
+static DEVICE_ATTR(model, 0444, exc3000_sysfs_model_show, NULL);
+
+static ssize_t exc3000_sysfs_fw_rev_show(struct device *dev,
+					 struct device_attribute *dattr,
+					 char *buf)
+{
+	struct exc3000_data *data = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%s\n", data->fw_rev);
+}
+static DEVICE_ATTR(fw_rev, 0444, exc3000_sysfs_fw_rev_show, NULL);
+
+static struct attribute *exc3000_attrs[] = {
+	&dev_attr_type.attr,
+	&dev_attr_model.attr,
+	&dev_attr_fw_rev.attr,
+	NULL
+};
+
+static const struct attribute_group exc3000_attr_group = {
+	.attrs = exc3000_attrs,
+};
+
 static int exc3000_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -285,6 +326,11 @@ static int exc3000_probe(struct i2c_client *client,
 	if (error)
 		return error;
 
+	dev_set_drvdata(&client->dev, data);
+	error = sysfs_create_group(&client->dev.kobj, &exc3000_attr_group);
+	if (error)
+		return error;
+
 	input = devm_input_allocate_device(&client->dev);
 	if (!input)
 		return -ENOMEM;
@@ -310,6 +356,13 @@ static int exc3000_probe(struct i2c_client *client,
 	return 0;
 }
 
+int exc3000_remove(struct i2c_client *client)
+{
+	sysfs_remove_group(&client->dev.kobj, &exc3000_attr_group);
+
+	return 0;
+}
+
 static const struct i2c_device_id exc3000_id[] = {
 	{ "exc3000", 0 },
 	{ }
@@ -331,6 +384,7 @@ static struct i2c_driver exc3000_driver = {
 	},
 	.id_table	= exc3000_id,
 	.probe		= exc3000_probe,
+	.remove		= exc3000_remove,
 };
 
 module_i2c_driver(exc3000_driver);
-- 
2.20.1


  parent reply	other threads:[~2020-01-07 17:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07 17:17 [PATCH 1/4] Input: exc3000: split MT event handling from IRQ handler Lucas Stach
2020-01-07 17:17 ` [PATCH 2/4] Input: exc3000: query and show type, model and firmware revision info Lucas Stach
2020-01-20 19:49   ` Dmitry Torokhov
2020-03-13 14:36     ` Lucas Stach
2020-01-07 17:17 ` Lucas Stach [this message]
2020-01-20 19:51   ` [PATCH 3/4] Input: exc3000: expose type, model and firmware revision as sysfs attributes Dmitry Torokhov
2020-01-07 17:17 ` [PATCH 4/4] Input: exc3000: add firmware update support Lucas Stach
2020-01-20 19:54   ` Dmitry Torokhov
2020-03-13 14:39     ` Lucas Stach
2020-01-12 18:03 ` [PATCH 1/4] Input: exc3000: split MT event handling from IRQ handler Chris Healy

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=20200107171741.10856-3-l.stach@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=cphealy@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-input@vger.kernel.org \
    --cc=patchwork-lst@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).