diff options
author | Thierry Escande <thierry.escande@collabora.com> | 2016-07-19 05:58:16 -0400 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2016-07-19 17:23:29 -0400 |
commit | f9ac6273e5b8fa45e7cd2086e1bbc91af9af7f19 (patch) | |
tree | dd87d826858e81638aabe14bbb5b0c5a24afeb8a /drivers/nfc/nfcsim.c | |
parent | d85a301c26621d3466956dc477c32c20c15a52ee (diff) |
NFC: nfcsim: Add support for sysfs control entry
The idea is to have a way to control and/or modify the behavior of the
nfcsim virtual devices.
This patch creates a folder tree in the debug filesystem. The debugfs is
usually mounted into /sys/kernel/debug and the nfcsim entries are
located in DEBUGFS/nfcsim/nfcX/ where X is either 0 or 1 depending on
the device you want to address.
These folders are empty for now and control entries will be added by
upcoming commits.
Signed-off-by: Thierry Escande <thierry.escande@collabora.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/nfc/nfcsim.c')
-rw-r--r-- | drivers/nfc/nfcsim.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c index 40b4846509f4..97067a5f248c 100644 --- a/drivers/nfc/nfcsim.c +++ b/drivers/nfc/nfcsim.c | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <linux/device.h> | 16 | #include <linux/device.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/ctype.h> | ||
20 | #include <linux/debugfs.h> | ||
19 | #include <linux/nfc.h> | 21 | #include <linux/nfc.h> |
20 | #include <net/nfc/nfc.h> | 22 | #include <net/nfc/nfc.h> |
21 | #include <net/nfc/digital.h> | 23 | #include <net/nfc/digital.h> |
@@ -329,6 +331,49 @@ static struct nfc_digital_ops nfcsim_digital_ops = { | |||
329 | .switch_rf = nfcsim_switch_rf, | 331 | .switch_rf = nfcsim_switch_rf, |
330 | }; | 332 | }; |
331 | 333 | ||
334 | static struct dentry *nfcsim_debugfs_root; | ||
335 | |||
336 | static void nfcsim_debugfs_init(void) | ||
337 | { | ||
338 | nfcsim_debugfs_root = debugfs_create_dir("nfcsim", NULL); | ||
339 | |||
340 | if (!nfcsim_debugfs_root) | ||
341 | pr_err("Could not create debugfs entry\n"); | ||
342 | |||
343 | } | ||
344 | |||
345 | static void nfcsim_debugfs_remove(void) | ||
346 | { | ||
347 | debugfs_remove_recursive(nfcsim_debugfs_root); | ||
348 | } | ||
349 | |||
350 | static void nfcsim_debugfs_init_dev(struct nfcsim *dev) | ||
351 | { | ||
352 | struct dentry *dev_dir; | ||
353 | char devname[5]; /* nfcX\0 */ | ||
354 | u32 idx; | ||
355 | int n; | ||
356 | |||
357 | if (!nfcsim_debugfs_root) { | ||
358 | NFCSIM_ERR(dev, "nfcsim debugfs not initialized\n"); | ||
359 | return; | ||
360 | } | ||
361 | |||
362 | idx = dev->nfc_digital_dev->nfc_dev->idx; | ||
363 | n = snprintf(devname, sizeof(devname), "nfc%d", idx); | ||
364 | if (n >= sizeof(devname)) { | ||
365 | NFCSIM_ERR(dev, "Could not compute dev name for dev %d\n", idx); | ||
366 | return; | ||
367 | } | ||
368 | |||
369 | dev_dir = debugfs_create_dir(devname, nfcsim_debugfs_root); | ||
370 | if (!dev_dir) { | ||
371 | NFCSIM_ERR(dev, "Could not create debugfs entries for nfc%d\n", | ||
372 | idx); | ||
373 | return; | ||
374 | } | ||
375 | } | ||
376 | |||
332 | static struct nfcsim *nfcsim_device_new(struct nfcsim_link *link_in, | 377 | static struct nfcsim *nfcsim_device_new(struct nfcsim_link *link_in, |
333 | struct nfcsim_link *link_out) | 378 | struct nfcsim_link *link_out) |
334 | { | 379 | { |
@@ -366,6 +411,8 @@ static struct nfcsim *nfcsim_device_new(struct nfcsim_link *link_in, | |||
366 | return ERR_PTR(rc); | 411 | return ERR_PTR(rc); |
367 | } | 412 | } |
368 | 413 | ||
414 | nfcsim_debugfs_init_dev(dev); | ||
415 | |||
369 | return dev; | 416 | return dev; |
370 | } | 417 | } |
371 | 418 | ||
@@ -400,6 +447,8 @@ static int __init nfcsim_init(void) | |||
400 | goto exit_err; | 447 | goto exit_err; |
401 | } | 448 | } |
402 | 449 | ||
450 | nfcsim_debugfs_init(); | ||
451 | |||
403 | dev0 = nfcsim_device_new(link0, link1); | 452 | dev0 = nfcsim_device_new(link0, link1); |
404 | if (IS_ERR(dev0)) { | 453 | if (IS_ERR(dev0)) { |
405 | rc = PTR_ERR(dev0); | 454 | rc = PTR_ERR(dev0); |
@@ -439,6 +488,8 @@ static void __exit nfcsim_exit(void) | |||
439 | 488 | ||
440 | nfcsim_link_free(link0); | 489 | nfcsim_link_free(link0); |
441 | nfcsim_link_free(link1); | 490 | nfcsim_link_free(link1); |
491 | |||
492 | nfcsim_debugfs_remove(); | ||
442 | } | 493 | } |
443 | 494 | ||
444 | module_init(nfcsim_init); | 495 | module_init(nfcsim_init); |