proc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * /proc interface for comedi
  4. *
  5. * COMEDI - Linux Control and Measurement Device Interface
  6. * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
  7. */
  8. /*
  9. * This is some serious bloatware.
  10. *
  11. * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
  12. * was cool.
  13. */
  14. #include "comedidev.h"
  15. #include "comedi_internal.h"
  16. #include <linux/proc_fs.h>
  17. #include <linux/seq_file.h>
  18. static int comedi_read(struct seq_file *m, void *v)
  19. {
  20. int i;
  21. int devices_q = 0;
  22. struct comedi_driver *driv;
  23. seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
  24. "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
  25. for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
  26. struct comedi_device *dev = comedi_dev_get_from_minor(i);
  27. if (!dev)
  28. continue;
  29. down_read(&dev->attach_lock);
  30. if (dev->attached) {
  31. devices_q = 1;
  32. seq_printf(m, "%2d: %-20s %-20s %4d\n",
  33. i, dev->driver->driver_name,
  34. dev->board_name, dev->n_subdevices);
  35. }
  36. up_read(&dev->attach_lock);
  37. comedi_dev_put(dev);
  38. }
  39. if (!devices_q)
  40. seq_puts(m, "no devices\n");
  41. mutex_lock(&comedi_drivers_list_lock);
  42. for (driv = comedi_drivers; driv; driv = driv->next) {
  43. seq_printf(m, "%s:\n", driv->driver_name);
  44. for (i = 0; i < driv->num_names; i++)
  45. seq_printf(m, " %s\n",
  46. *(char **)((char *)driv->board_name +
  47. i * driv->offset));
  48. if (!driv->num_names)
  49. seq_printf(m, " %s\n", driv->driver_name);
  50. }
  51. mutex_unlock(&comedi_drivers_list_lock);
  52. return 0;
  53. }
  54. void __init comedi_proc_init(void)
  55. {
  56. if (!proc_create_single("comedi", 0444, NULL, comedi_read))
  57. pr_warn("comedi: unable to create proc entry\n");
  58. }
  59. void comedi_proc_cleanup(void)
  60. {
  61. remove_proc_entry("comedi", NULL);
  62. }