xref: /openbmc/linux/drivers/comedi/proc.c (revision 0a94608f)
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 /*
10  * This is some serious bloatware.
11  *
12  * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
13  * was cool.
14  */
15 
16 #include <linux/comedi/comedidev.h>
17 #include "comedi_internal.h"
18 #include <linux/proc_fs.h>
19 #include <linux/seq_file.h>
20 
21 static int comedi_read(struct seq_file *m, void *v)
22 {
23 	int i;
24 	int devices_q = 0;
25 	struct comedi_driver *driv;
26 
27 	seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
28 		   "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
29 
30 	for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
31 		struct comedi_device *dev = comedi_dev_get_from_minor(i);
32 
33 		if (!dev)
34 			continue;
35 
36 		down_read(&dev->attach_lock);
37 		if (dev->attached) {
38 			devices_q = 1;
39 			seq_printf(m, "%2d: %-20s %-20s %4d\n",
40 				   i, dev->driver->driver_name,
41 				   dev->board_name, dev->n_subdevices);
42 		}
43 		up_read(&dev->attach_lock);
44 		comedi_dev_put(dev);
45 	}
46 	if (!devices_q)
47 		seq_puts(m, "no devices\n");
48 
49 	mutex_lock(&comedi_drivers_list_lock);
50 	for (driv = comedi_drivers; driv; driv = driv->next) {
51 		seq_printf(m, "%s:\n", driv->driver_name);
52 		for (i = 0; i < driv->num_names; i++)
53 			seq_printf(m, " %s\n",
54 				   *(char **)((char *)driv->board_name +
55 					      i * driv->offset));
56 
57 		if (!driv->num_names)
58 			seq_printf(m, " %s\n", driv->driver_name);
59 	}
60 	mutex_unlock(&comedi_drivers_list_lock);
61 
62 	return 0;
63 }
64 
65 void __init comedi_proc_init(void)
66 {
67 	if (!proc_create_single("comedi", 0444, NULL, comedi_read))
68 		pr_warn("comedi: unable to create proc entry\n");
69 }
70 
71 void comedi_proc_cleanup(void)
72 {
73 	remove_proc_entry("comedi", NULL);
74 }
75