Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nick Dyer and committed by
Dmitry Torokhov
ce363f0d 5a89916d

+152 -4
+1 -1
drivers/input/rmi4/rmi_driver.c
··· 365 365 struct input_dev *input) 366 366 { 367 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 369 char *name; 370 370 371 371 name = devm_kasprintf(&rmi_dev->dev, GFP_KERNEL,
+1 -1
drivers/input/rmi4/rmi_driver.h
··· 104 104 int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, 105 105 const struct pdt_entry *pdt); 106 106 107 - char *rmi_f01_get_product_ID(struct rmi_function *fn); 107 + const char *rmi_f01_get_product_ID(struct rmi_function *fn); 108 108 109 109 #ifdef CONFIG_RMI4_F34 110 110 int rmi_f34_create_sysfs(struct rmi_device *rmi_dev);
+102 -2
drivers/input/rmi4/rmi_f01.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/uaccess.h> 15 15 #include <linux/of.h> 16 + #include <asm/unaligned.h> 16 17 #include "rmi_driver.h" 17 18 18 19 #define RMI_PRODUCT_ID_LENGTH 10 ··· 56 55 u8 product_id[RMI_PRODUCT_ID_LENGTH + 1]; 57 56 u16 productinfo; 58 57 u32 firmware_id; 58 + u32 package_id; 59 59 }; 60 60 61 61 /* F01 device status bits */ ··· 223 221 has_build_id_query = !!(queries[0] & BIT(1)); 224 222 } 225 223 226 - if (has_package_id_query) 224 + if (has_package_id_query) { 225 + ret = rmi_read_block(rmi_dev, prod_info_addr, 226 + queries, sizeof(__le64)); 227 + if (ret) { 228 + dev_err(&rmi_dev->dev, 229 + "Failed to read package info: %d\n", 230 + ret); 231 + return ret; 232 + } 233 + 234 + props->package_id = get_unaligned_le64(queries); 227 235 prod_info_addr++; 236 + } 228 237 229 238 if (has_build_id_query) { 230 239 ret = rmi_read_block(rmi_dev, prod_info_addr, queries, ··· 255 242 return 0; 256 243 } 257 244 258 - char *rmi_f01_get_product_ID(struct rmi_function *fn) 245 + const char *rmi_f01_get_product_ID(struct rmi_function *fn) 259 246 { 260 247 struct f01_data *f01 = dev_get_drvdata(&fn->dev); 261 248 262 249 return f01->properties.product_id; 263 250 } 251 + 252 + static ssize_t rmi_driver_manufacturer_id_show(struct device *dev, 253 + struct device_attribute *dattr, 254 + char *buf) 255 + { 256 + struct rmi_driver_data *data = dev_get_drvdata(dev); 257 + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); 258 + 259 + return scnprintf(buf, PAGE_SIZE, "%d\n", 260 + f01->properties.manufacturer_id); 261 + } 262 + 263 + static DEVICE_ATTR(manufacturer_id, 0444, 264 + rmi_driver_manufacturer_id_show, NULL); 265 + 266 + static ssize_t rmi_driver_dom_show(struct device *dev, 267 + struct device_attribute *dattr, 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, "%s\n", f01->properties.dom); 273 + } 274 + 275 + static DEVICE_ATTR(date_of_manufacture, 0444, rmi_driver_dom_show, NULL); 276 + 277 + static ssize_t rmi_driver_product_id_show(struct device *dev, 278 + struct device_attribute *dattr, 279 + char *buf) 280 + { 281 + struct rmi_driver_data *data = dev_get_drvdata(dev); 282 + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); 283 + 284 + return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.product_id); 285 + } 286 + 287 + static DEVICE_ATTR(product_id, 0444, rmi_driver_product_id_show, NULL); 288 + 289 + static ssize_t rmi_driver_firmware_id_show(struct device *dev, 290 + struct device_attribute *dattr, 291 + char *buf) 292 + { 293 + struct rmi_driver_data *data = dev_get_drvdata(dev); 294 + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); 295 + 296 + return scnprintf(buf, PAGE_SIZE, "%d\n", f01->properties.firmware_id); 297 + } 298 + 299 + static DEVICE_ATTR(firmware_id, 0444, rmi_driver_firmware_id_show, NULL); 300 + 301 + static ssize_t rmi_driver_package_id_show(struct device *dev, 302 + struct device_attribute *dattr, 303 + char *buf) 304 + { 305 + struct rmi_driver_data *data = dev_get_drvdata(dev); 306 + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); 307 + 308 + u32 package_id = f01->properties.package_id; 309 + 310 + return scnprintf(buf, PAGE_SIZE, "%04x.%04x\n", 311 + package_id & 0xffff, (package_id >> 16) & 0xffff); 312 + } 313 + 314 + static DEVICE_ATTR(package_id, 0444, rmi_driver_package_id_show, NULL); 315 + 316 + static struct attribute *rmi_f01_attrs[] = { 317 + &dev_attr_manufacturer_id.attr, 318 + &dev_attr_date_of_manufacture.attr, 319 + &dev_attr_product_id.attr, 320 + &dev_attr_firmware_id.attr, 321 + &dev_attr_package_id.attr, 322 + NULL 323 + }; 324 + 325 + static struct attribute_group rmi_f01_attr_group = { 326 + .attrs = rmi_f01_attrs, 327 + }; 264 328 265 329 #ifdef CONFIG_OF 266 330 static int rmi_f01_of_probe(struct device *dev, ··· 571 481 572 482 dev_set_drvdata(&fn->dev, f01); 573 483 484 + error = sysfs_create_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group); 485 + if (error) 486 + dev_warn(&fn->dev, "Failed to create sysfs group: %d\n", error); 487 + 574 488 return 0; 489 + } 490 + 491 + static void rmi_f01_remove(struct rmi_function *fn) 492 + { 493 + sysfs_remove_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group); 575 494 } 576 495 577 496 static int rmi_f01_config(struct rmi_function *fn) ··· 722 623 }, 723 624 .func = 0x01, 724 625 .probe = rmi_f01_probe, 626 + .remove = rmi_f01_remove, 725 627 .config = rmi_f01_config, 726 628 .attention = rmi_f01_attention, 727 629 .suspend = rmi_f01_suspend,
+48
drivers/input/rmi4/rmi_f34.c
··· 301 301 return f34->update_status; 302 302 } 303 303 304 + static 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 + 328 + static DEVICE_ATTR(bootloader_id, 0444, rmi_driver_bootloader_id_show, NULL); 329 + 330 + static 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 + 347 + static DEVICE_ATTR(configuration_id, 0444, 348 + rmi_driver_configuration_id_show, NULL); 349 + 304 350 static int rmi_firmware_update(struct rmi_driver_data *data, 305 351 const struct firmware *fw) 306 352 { ··· 498 452 rmi_driver_update_fw_status_show, NULL); 499 453 500 454 static struct attribute *rmi_firmware_attrs[] = { 455 + &dev_attr_bootloader_id.attr, 456 + &dev_attr_configuration_id.attr, 501 457 &dev_attr_update_fw.attr, 502 458 &dev_attr_update_fw_status.attr, 503 459 NULL