aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Dyer <nick@shmanahar.org>2017-01-31 18:44:49 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2017-01-31 18:51:22 -0500
commitce363f0dec73b8ec2209a02a7271a9e67ed61368 (patch)
tree72feb59584d1744b884b013abc8ab9d29e575d5f
parent5a89916df2c8d2635b82a457cd4945dd73c1de3c (diff)
Input: synaptics-rmi4 - add sysfs interfaces for hardware IDs
These attributes provide various bits of information which may be enumerated under the RMI4 protocol to user space. This may be useful for displaying the particular version which is in use, or selecting the correct firmware to flash. Signed-off-by: Nick Dyer <nick@shmanahar.org> Tested-by: Chris Healy <cphealy@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--drivers/input/rmi4/rmi_driver.c2
-rw-r--r--drivers/input/rmi4/rmi_driver.h2
-rw-r--r--drivers/input/rmi4/rmi_f01.c104
-rw-r--r--drivers/input/rmi4/rmi_f34.c48
4 files changed, 152 insertions, 4 deletions
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 30397cc7283a..b3985500dd91 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -365,7 +365,7 @@ static void rmi_driver_set_input_name(struct rmi_device *rmi_dev,
365 struct input_dev *input) 365 struct input_dev *input)
366{ 366{
367 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); 367 struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
368 char *device_name = rmi_f01_get_product_ID(data->f01_container); 368 const char *device_name = rmi_f01_get_product_ID(data->f01_container);
369 char *name; 369 char *name;
370 370
371 name = devm_kasprintf(&rmi_dev->dev, GFP_KERNEL, 371 name = devm_kasprintf(&rmi_dev->dev, GFP_KERNEL,
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 24f8f764d171..a480333a9e1c 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -104,7 +104,7 @@ int rmi_init_functions(struct rmi_driver_data *data);
104int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, 104int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx,
105 const struct pdt_entry *pdt); 105 const struct pdt_entry *pdt);
106 106
107char *rmi_f01_get_product_ID(struct rmi_function *fn); 107const char *rmi_f01_get_product_ID(struct rmi_function *fn);
108 108
109#ifdef CONFIG_RMI4_F34 109#ifdef CONFIG_RMI4_F34
110int rmi_f34_create_sysfs(struct rmi_device *rmi_dev); 110int rmi_f34_create_sysfs(struct rmi_device *rmi_dev);
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index cae35c6cde31..ed805d21633a 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/uaccess.h> 14#include <linux/uaccess.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <asm/unaligned.h>
16#include "rmi_driver.h" 17#include "rmi_driver.h"
17 18
18#define RMI_PRODUCT_ID_LENGTH 10 19#define RMI_PRODUCT_ID_LENGTH 10
@@ -55,6 +56,7 @@ struct f01_basic_properties {
55 u8 product_id[RMI_PRODUCT_ID_LENGTH + 1]; 56 u8 product_id[RMI_PRODUCT_ID_LENGTH + 1];
56 u16 productinfo; 57 u16 productinfo;
57 u32 firmware_id; 58 u32 firmware_id;
59 u32 package_id;
58}; 60};
59 61
60/* F01 device status bits */ 62/* F01 device status bits */
@@ -221,8 +223,19 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
221 has_build_id_query = !!(queries[0] & BIT(1)); 223 has_build_id_query = !!(queries[0] & BIT(1));
222 } 224 }
223 225
224 if (has_package_id_query) 226 if (has_package_id_query) {
227 ret = rmi_read_block(rmi_dev, prod_info_addr,
228 queries, sizeof(__le64));
229 if (ret) {
230 dev_err(&rmi_dev->dev,
231 "Failed to read package info: %d\n",
232 ret);
233 return ret;
234 }
235
236 props->package_id = get_unaligned_le64(queries);
225 prod_info_addr++; 237 prod_info_addr++;
238 }
226 239
227 if (has_build_id_query) { 240 if (has_build_id_query) {
228 ret = rmi_read_block(rmi_dev, prod_info_addr, queries, 241 ret = rmi_read_block(rmi_dev, prod_info_addr, queries,
@@ -242,13 +255,90 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
242 return 0; 255 return 0;
243} 256}
244 257
245char *rmi_f01_get_product_ID(struct rmi_function *fn) 258const char *rmi_f01_get_product_ID(struct rmi_function *fn)
246{ 259{
247 struct f01_data *f01 = dev_get_drvdata(&fn->dev); 260 struct f01_data *f01 = dev_get_drvdata(&fn->dev);
248 261
249 return f01->properties.product_id; 262 return f01->properties.product_id;
250} 263}
251 264
265static ssize_t rmi_driver_manufacturer_id_show(struct device *dev,
266 struct device_attribute *dattr,
267 char *buf)
268{
269 struct rmi_driver_data *data = dev_get_drvdata(dev);
270 struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
271
272 return scnprintf(buf, PAGE_SIZE, "%d\n",
273 f01->properties.manufacturer_id);
274}
275
276static DEVICE_ATTR(manufacturer_id, 0444,
277 rmi_driver_manufacturer_id_show, NULL);
278
279static ssize_t rmi_driver_dom_show(struct device *dev,
280 struct device_attribute *dattr, char *buf)
281{
282 struct rmi_driver_data *data = dev_get_drvdata(dev);
283 struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
284
285 return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.dom);
286}
287
288static DEVICE_ATTR(date_of_manufacture, 0444, rmi_driver_dom_show, NULL);
289
290static ssize_t rmi_driver_product_id_show(struct device *dev,
291 struct device_attribute *dattr,
292 char *buf)
293{
294 struct rmi_driver_data *data = dev_get_drvdata(dev);
295 struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
296
297 return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.product_id);
298}
299
300static DEVICE_ATTR(product_id, 0444, rmi_driver_product_id_show, NULL);
301
302static ssize_t rmi_driver_firmware_id_show(struct device *dev,
303 struct device_attribute *dattr,
304 char *buf)
305{
306 struct rmi_driver_data *data = dev_get_drvdata(dev);
307 struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
308
309 return scnprintf(buf, PAGE_SIZE, "%d\n", f01->properties.firmware_id);
310}
311
312static DEVICE_ATTR(firmware_id, 0444, rmi_driver_firmware_id_show, NULL);
313
314static ssize_t rmi_driver_package_id_show(struct device *dev,
315 struct device_attribute *dattr,
316 char *buf)
317{
318 struct rmi_driver_data *data = dev_get_drvdata(dev);
319 struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev);
320
321 u32 package_id = f01->properties.package_id;
322
323 return scnprintf(buf, PAGE_SIZE, "%04x.%04x\n",
324 package_id & 0xffff, (package_id >> 16) & 0xffff);
325}
326
327static DEVICE_ATTR(package_id, 0444, rmi_driver_package_id_show, NULL);
328
329static struct attribute *rmi_f01_attrs[] = {
330 &dev_attr_manufacturer_id.attr,
331 &dev_attr_date_of_manufacture.attr,
332 &dev_attr_product_id.attr,
333 &dev_attr_firmware_id.attr,
334 &dev_attr_package_id.attr,
335 NULL
336};
337
338static struct attribute_group rmi_f01_attr_group = {
339 .attrs = rmi_f01_attrs,
340};
341
252#ifdef CONFIG_OF 342#ifdef CONFIG_OF
253static int rmi_f01_of_probe(struct device *dev, 343static int rmi_f01_of_probe(struct device *dev,
254 struct rmi_device_platform_data *pdata) 344 struct rmi_device_platform_data *pdata)
@@ -481,9 +571,18 @@ static int rmi_f01_probe(struct rmi_function *fn)
481 571
482 dev_set_drvdata(&fn->dev, f01); 572 dev_set_drvdata(&fn->dev, f01);
483 573
574 error = sysfs_create_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group);
575 if (error)
576 dev_warn(&fn->dev, "Failed to create sysfs group: %d\n", error);
577
484 return 0; 578 return 0;
485} 579}
486 580
581static void rmi_f01_remove(struct rmi_function *fn)
582{
583 sysfs_remove_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group);
584}
585
487static int rmi_f01_config(struct rmi_function *fn) 586static int rmi_f01_config(struct rmi_function *fn)
488{ 587{
489 struct f01_data *f01 = dev_get_drvdata(&fn->dev); 588 struct f01_data *f01 = dev_get_drvdata(&fn->dev);
@@ -623,6 +722,7 @@ struct rmi_function_handler rmi_f01_handler = {
623 }, 722 },
624 .func = 0x01, 723 .func = 0x01,
625 .probe = rmi_f01_probe, 724 .probe = rmi_f01_probe,
725 .remove = rmi_f01_remove,
626 .config = rmi_f01_config, 726 .config = rmi_f01_config,
627 .attention = rmi_f01_attention, 727 .attention = rmi_f01_attention,
628 .suspend = rmi_f01_suspend, 728 .suspend = rmi_f01_suspend,
diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c
index 902b99007885..425fe140e9df 100644
--- a/drivers/input/rmi4/rmi_f34.c
+++ b/drivers/input/rmi4/rmi_f34.c
@@ -301,6 +301,52 @@ static int rmi_f34_status(struct rmi_function *fn)
301 return f34->update_status; 301 return f34->update_status;
302} 302}
303 303
304static ssize_t rmi_driver_bootloader_id_show(struct device *dev,
305 struct device_attribute *dattr,
306 char *buf)
307{
308 struct rmi_driver_data *data = dev_get_drvdata(dev);
309 struct rmi_function *fn = data->f34_container;
310 struct f34_data *f34;
311
312 if (fn) {
313 f34 = dev_get_drvdata(&fn->dev);
314
315 if (f34->bl_version == 5)
316 return scnprintf(buf, PAGE_SIZE, "%c%c\n",
317 f34->bootloader_id[0],
318 f34->bootloader_id[1]);
319 else
320 return scnprintf(buf, PAGE_SIZE, "V%d.%d\n",
321 f34->bootloader_id[1],
322 f34->bootloader_id[0]);
323 }
324
325 return 0;
326}
327
328static DEVICE_ATTR(bootloader_id, 0444, rmi_driver_bootloader_id_show, NULL);
329
330static ssize_t rmi_driver_configuration_id_show(struct device *dev,
331 struct device_attribute *dattr,
332 char *buf)
333{
334 struct rmi_driver_data *data = dev_get_drvdata(dev);
335 struct rmi_function *fn = data->f34_container;
336 struct f34_data *f34;
337
338 if (fn) {
339 f34 = dev_get_drvdata(&fn->dev);
340
341 return scnprintf(buf, PAGE_SIZE, "%s\n", f34->configuration_id);
342 }
343
344 return 0;
345}
346
347static DEVICE_ATTR(configuration_id, 0444,
348 rmi_driver_configuration_id_show, NULL);
349
304static int rmi_firmware_update(struct rmi_driver_data *data, 350static int rmi_firmware_update(struct rmi_driver_data *data,
305 const struct firmware *fw) 351 const struct firmware *fw)
306{ 352{
@@ -452,6 +498,8 @@ static DEVICE_ATTR(update_fw_status, 0444,
452 rmi_driver_update_fw_status_show, NULL); 498 rmi_driver_update_fw_status_show, NULL);
453 499
454static struct attribute *rmi_firmware_attrs[] = { 500static struct attribute *rmi_firmware_attrs[] = {
501 &dev_attr_bootloader_id.attr,
502 &dev_attr_configuration_id.attr,
455 &dev_attr_update_fw.attr, 503 &dev_attr_update_fw.attr,
456 &dev_attr_update_fw_status.attr, 504 &dev_attr_update_fw_status.attr,
457 NULL 505 NULL