blob: 91dea25b57242ad327ab8cd136dd77a34b405a8f [file] [log] [blame]
David Schleefed9eccb2008-11-04 20:29:31 -08001/*
Michael Welling6f2c9ef2014-03-18 02:14:20 -05002 * /proc interface for comedi
3 *
4 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
David Schleefed9eccb2008-11-04 20:29:31 -080017
18/*
Michael Welling6f2c9ef2014-03-18 02:14:20 -050019 * This is some serious bloatware.
20 *
21 * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
22 * was cool.
23 */
David Schleefed9eccb2008-11-04 20:29:31 -080024
David Schleefed9eccb2008-11-04 20:29:31 -080025#include "comedidev.h"
Ian Abbottf2867662012-06-19 10:17:46 +010026#include "comedi_internal.h"
David Schleefed9eccb2008-11-04 20:29:31 -080027#include <linux/proc_fs.h>
David Howells1f817b82013-04-08 16:39:33 +010028#include <linux/seq_file.h>
David Schleefed9eccb2008-11-04 20:29:31 -080029
David Howells1f817b82013-04-08 16:39:33 +010030static int comedi_read(struct seq_file *m, void *v)
David Schleefed9eccb2008-11-04 20:29:31 -080031{
32 int i;
33 int devices_q = 0;
Bill Pemberton139dfbd2009-03-16 22:05:25 -040034 struct comedi_driver *driv;
David Schleefed9eccb2008-11-04 20:29:31 -080035
Michael Welling6f2c9ef2014-03-18 02:14:20 -050036 seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
37 "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
David Schleefed9eccb2008-11-04 20:29:31 -080038
39 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
Ian Abbott616a3542013-11-08 15:03:36 +000040 struct comedi_device *dev = comedi_dev_get_from_minor(i);
41
H Hartley Sweeten4da5fa92012-12-19 15:35:23 -070042 if (!dev)
Bill Pembertonc7427402009-03-16 22:03:56 -040043 continue;
David Schleefed9eccb2008-11-04 20:29:31 -080044
Ian Abbott616a3542013-11-08 15:03:36 +000045 down_read(&dev->attach_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080046 if (dev->attached) {
47 devices_q = 1;
David Howells1f817b82013-04-08 16:39:33 +010048 seq_printf(m, "%2d: %-20s %-20s %4d\n",
49 i, dev->driver->driver_name,
50 dev->board_name, dev->n_subdevices);
David Schleefed9eccb2008-11-04 20:29:31 -080051 }
Ian Abbott616a3542013-11-08 15:03:36 +000052 up_read(&dev->attach_lock);
53 comedi_dev_put(dev);
David Schleefed9eccb2008-11-04 20:29:31 -080054 }
Bill Pemberton82675f32009-03-16 22:04:23 -040055 if (!devices_q)
David Howells1f817b82013-04-08 16:39:33 +010056 seq_puts(m, "no devices\n");
David Schleefed9eccb2008-11-04 20:29:31 -080057
Ian Abbottc383e2d2013-06-27 14:50:58 +010058 mutex_lock(&comedi_drivers_list_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080059 for (driv = comedi_drivers; driv; driv = driv->next) {
David Howells1f817b82013-04-08 16:39:33 +010060 seq_printf(m, "%s:\n", driv->driver_name);
61 for (i = 0; i < driv->num_names; i++)
62 seq_printf(m, " %s\n",
63 *(char **)((char *)driv->board_name +
64 i * driv->offset));
65
Bill Pemberton82675f32009-03-16 22:04:23 -040066 if (!driv->num_names)
David Howells1f817b82013-04-08 16:39:33 +010067 seq_printf(m, " %s\n", driv->driver_name);
David Schleefed9eccb2008-11-04 20:29:31 -080068 }
Ian Abbottc383e2d2013-06-27 14:50:58 +010069 mutex_unlock(&comedi_drivers_list_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080070
David Howells1f817b82013-04-08 16:39:33 +010071 return 0;
David Schleefed9eccb2008-11-04 20:29:31 -080072}
73
David Howells1f817b82013-04-08 16:39:33 +010074/*
75 * seq_file wrappers for procfile show routines.
76 */
77static int comedi_proc_open(struct inode *inode, struct file *file)
78{
79 return single_open(file, comedi_read, NULL);
80}
81
82static const struct file_operations comedi_proc_fops = {
83 .open = comedi_proc_open,
84 .read = seq_read,
85 .llseek = seq_lseek,
Al Virobae301d2013-05-05 00:15:43 -040086 .release = single_release,
David Howells1f817b82013-04-08 16:39:33 +010087};
88
David Schleefed9eccb2008-11-04 20:29:31 -080089void comedi_proc_init(void)
90{
David Howells1f817b82013-04-08 16:39:33 +010091 proc_create("comedi", 0644, NULL, &comedi_proc_fops);
David Schleefed9eccb2008-11-04 20:29:31 -080092}
93
94void comedi_proc_cleanup(void)
95{
Greg Kroah-Hartman22d11422010-05-03 15:32:04 -070096 remove_proc_entry("comedi", NULL);
David Schleefed9eccb2008-11-04 20:29:31 -080097}