blob: 50d38938ac6f2e112ed53065259e8ed021270b51 [file] [log] [blame]
Greg Kroah-Hartmane184e2b2017-11-07 14:58:43 +01001// SPDX-License-Identifier: GPL-2.0+
David Schleefed9eccb2008-11-04 20:29:31 -08002/*
Michael Welling6f2c9ef2014-03-18 02:14:20 -05003 * /proc interface for comedi
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
Michael Welling6f2c9ef2014-03-18 02:14:20 -05007 */
David Schleefed9eccb2008-11-04 20:29:31 -08008
9/*
Michael Welling6f2c9ef2014-03-18 02:14:20 -050010 * This is some serious bloatware.
11 *
12 * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
13 * was cool.
14 */
David Schleefed9eccb2008-11-04 20:29:31 -080015
David Schleefed9eccb2008-11-04 20:29:31 -080016#include "comedidev.h"
Ian Abbottf2867662012-06-19 10:17:46 +010017#include "comedi_internal.h"
David Schleefed9eccb2008-11-04 20:29:31 -080018#include <linux/proc_fs.h>
David Howells1f817b82013-04-08 16:39:33 +010019#include <linux/seq_file.h>
David Schleefed9eccb2008-11-04 20:29:31 -080020
David Howells1f817b82013-04-08 16:39:33 +010021static int comedi_read(struct seq_file *m, void *v)
David Schleefed9eccb2008-11-04 20:29:31 -080022{
23 int i;
24 int devices_q = 0;
Bill Pemberton139dfbd2009-03-16 22:05:25 -040025 struct comedi_driver *driv;
David Schleefed9eccb2008-11-04 20:29:31 -080026
Michael Welling6f2c9ef2014-03-18 02:14:20 -050027 seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
28 "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
David Schleefed9eccb2008-11-04 20:29:31 -080029
30 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
Ian Abbott616a3542013-11-08 15:03:36 +000031 struct comedi_device *dev = comedi_dev_get_from_minor(i);
32
H Hartley Sweeten4da5fa92012-12-19 15:35:23 -070033 if (!dev)
Bill Pembertonc7427402009-03-16 22:03:56 -040034 continue;
David Schleefed9eccb2008-11-04 20:29:31 -080035
Ian Abbott616a3542013-11-08 15:03:36 +000036 down_read(&dev->attach_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080037 if (dev->attached) {
38 devices_q = 1;
David Howells1f817b82013-04-08 16:39:33 +010039 seq_printf(m, "%2d: %-20s %-20s %4d\n",
40 i, dev->driver->driver_name,
41 dev->board_name, dev->n_subdevices);
David Schleefed9eccb2008-11-04 20:29:31 -080042 }
Ian Abbott616a3542013-11-08 15:03:36 +000043 up_read(&dev->attach_lock);
44 comedi_dev_put(dev);
David Schleefed9eccb2008-11-04 20:29:31 -080045 }
Bill Pemberton82675f32009-03-16 22:04:23 -040046 if (!devices_q)
David Howells1f817b82013-04-08 16:39:33 +010047 seq_puts(m, "no devices\n");
David Schleefed9eccb2008-11-04 20:29:31 -080048
Ian Abbottc383e2d2013-06-27 14:50:58 +010049 mutex_lock(&comedi_drivers_list_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080050 for (driv = comedi_drivers; driv; driv = driv->next) {
David Howells1f817b82013-04-08 16:39:33 +010051 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
Bill Pemberton82675f32009-03-16 22:04:23 -040057 if (!driv->num_names)
David Howells1f817b82013-04-08 16:39:33 +010058 seq_printf(m, " %s\n", driv->driver_name);
David Schleefed9eccb2008-11-04 20:29:31 -080059 }
Ian Abbottc383e2d2013-06-27 14:50:58 +010060 mutex_unlock(&comedi_drivers_list_lock);
David Schleefed9eccb2008-11-04 20:29:31 -080061
David Howells1f817b82013-04-08 16:39:33 +010062 return 0;
David Schleefed9eccb2008-11-04 20:29:31 -080063}
64
David Howells1f817b82013-04-08 16:39:33 +010065/*
66 * seq_file wrappers for procfile show routines.
67 */
68static int comedi_proc_open(struct inode *inode, struct file *file)
69{
70 return single_open(file, comedi_read, NULL);
71}
72
73static const struct file_operations comedi_proc_fops = {
Cheah Kok Cheong6bd68e22016-12-30 19:27:17 +080074 .owner = THIS_MODULE,
David Howells1f817b82013-04-08 16:39:33 +010075 .open = comedi_proc_open,
76 .read = seq_read,
77 .llseek = seq_lseek,
Al Virobae301d2013-05-05 00:15:43 -040078 .release = single_release,
David Howells1f817b82013-04-08 16:39:33 +010079};
80
Cheah Kok Cheongec0bff02016-12-30 19:26:50 +080081void __init comedi_proc_init(void)
David Schleefed9eccb2008-11-04 20:29:31 -080082{
Cheah Kok Cheong2e4b5cd2016-12-30 19:27:41 +080083 if (!proc_create("comedi", 0444, NULL, &comedi_proc_fops))
84 pr_warn("comedi: unable to create proc entry\n");
David Schleefed9eccb2008-11-04 20:29:31 -080085}
86
87void comedi_proc_cleanup(void)
88{
Greg Kroah-Hartman22d11422010-05-03 15:32:04 -070089 remove_proc_entry("comedi", NULL);
David Schleefed9eccb2008-11-04 20:29:31 -080090}