Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * /proc interface for comedi
0004  *
0005  * COMEDI - Linux Control and Measurement Device Interface
0006  * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
0007  */
0008 
0009 /*
0010  * This is some serious bloatware.
0011  *
0012  * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
0013  * was cool.
0014  */
0015 
0016 #include <linux/comedi/comedidev.h>
0017 #include "comedi_internal.h"
0018 #include <linux/proc_fs.h>
0019 #include <linux/seq_file.h>
0020 
0021 static int comedi_read(struct seq_file *m, void *v)
0022 {
0023     int i;
0024     int devices_q = 0;
0025     struct comedi_driver *driv;
0026 
0027     seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
0028            "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
0029 
0030     for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
0031         struct comedi_device *dev = comedi_dev_get_from_minor(i);
0032 
0033         if (!dev)
0034             continue;
0035 
0036         down_read(&dev->attach_lock);
0037         if (dev->attached) {
0038             devices_q = 1;
0039             seq_printf(m, "%2d: %-20s %-20s %4d\n",
0040                    i, dev->driver->driver_name,
0041                    dev->board_name, dev->n_subdevices);
0042         }
0043         up_read(&dev->attach_lock);
0044         comedi_dev_put(dev);
0045     }
0046     if (!devices_q)
0047         seq_puts(m, "no devices\n");
0048 
0049     mutex_lock(&comedi_drivers_list_lock);
0050     for (driv = comedi_drivers; driv; driv = driv->next) {
0051         seq_printf(m, "%s:\n", driv->driver_name);
0052         for (i = 0; i < driv->num_names; i++)
0053             seq_printf(m, " %s\n",
0054                    *(char **)((char *)driv->board_name +
0055                           i * driv->offset));
0056 
0057         if (!driv->num_names)
0058             seq_printf(m, " %s\n", driv->driver_name);
0059     }
0060     mutex_unlock(&comedi_drivers_list_lock);
0061 
0062     return 0;
0063 }
0064 
0065 void __init comedi_proc_init(void)
0066 {
0067     if (!proc_create_single("comedi", 0444, NULL, comedi_read))
0068         pr_warn("comedi: unable to create proc entry\n");
0069 }
0070 
0071 void comedi_proc_cleanup(void)
0072 {
0073     remove_proc_entry("comedi", NULL);
0074 }