Greg Kroah-Hartman | e184e2b | 2017-11-07 14:58:43 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 2 | /* |
Michael Welling | 6f2c9ef | 2014-03-18 02:14:20 -0500 | [diff] [blame] | 3 | * /proc interface for comedi |
| 4 | * |
| 5 | * COMEDI - Linux Control and Measurement Device Interface |
| 6 | * Copyright (C) 1998 David A. Schleef <ds@schleef.org> |
Michael Welling | 6f2c9ef | 2014-03-18 02:14:20 -0500 | [diff] [blame] | 7 | */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 8 | |
| 9 | /* |
Michael Welling | 6f2c9ef | 2014-03-18 02:14:20 -0500 | [diff] [blame] | 10 | * This is some serious bloatware. |
| 11 | * |
| 12 | * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it |
| 13 | * was cool. |
| 14 | */ |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 15 | |
Ian Abbott | df0e68c1 | 2021-11-17 12:05:59 +0000 | [diff] [blame] | 16 | #include <linux/comedi/comedidev.h> |
Ian Abbott | f286766 | 2012-06-19 10:17:46 +0100 | [diff] [blame] | 17 | #include "comedi_internal.h" |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 18 | #include <linux/proc_fs.h> |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 19 | #include <linux/seq_file.h> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 20 | |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 21 | static int comedi_read(struct seq_file *m, void *v) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 22 | { |
| 23 | int i; |
| 24 | int devices_q = 0; |
Bill Pemberton | 139dfbd | 2009-03-16 22:05:25 -0400 | [diff] [blame] | 25 | struct comedi_driver *driv; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 26 | |
Michael Welling | 6f2c9ef | 2014-03-18 02:14:20 -0500 | [diff] [blame] | 27 | seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n", |
| 28 | "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices"); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 29 | |
| 30 | for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { |
Ian Abbott | 616a354 | 2013-11-08 15:03:36 +0000 | [diff] [blame] | 31 | struct comedi_device *dev = comedi_dev_get_from_minor(i); |
| 32 | |
H Hartley Sweeten | 4da5fa9 | 2012-12-19 15:35:23 -0700 | [diff] [blame] | 33 | if (!dev) |
Bill Pemberton | c742740 | 2009-03-16 22:03:56 -0400 | [diff] [blame] | 34 | continue; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 35 | |
Ian Abbott | 616a354 | 2013-11-08 15:03:36 +0000 | [diff] [blame] | 36 | down_read(&dev->attach_lock); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 37 | if (dev->attached) { |
| 38 | devices_q = 1; |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 39 | seq_printf(m, "%2d: %-20s %-20s %4d\n", |
| 40 | i, dev->driver->driver_name, |
| 41 | dev->board_name, dev->n_subdevices); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 42 | } |
Ian Abbott | 616a354 | 2013-11-08 15:03:36 +0000 | [diff] [blame] | 43 | up_read(&dev->attach_lock); |
| 44 | comedi_dev_put(dev); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 45 | } |
Bill Pemberton | 82675f3 | 2009-03-16 22:04:23 -0400 | [diff] [blame] | 46 | if (!devices_q) |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 47 | seq_puts(m, "no devices\n"); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 48 | |
Ian Abbott | c383e2d | 2013-06-27 14:50:58 +0100 | [diff] [blame] | 49 | mutex_lock(&comedi_drivers_list_lock); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 50 | for (driv = comedi_drivers; driv; driv = driv->next) { |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 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 | |
Bill Pemberton | 82675f3 | 2009-03-16 22:04:23 -0400 | [diff] [blame] | 57 | if (!driv->num_names) |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 58 | seq_printf(m, " %s\n", driv->driver_name); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 59 | } |
Ian Abbott | c383e2d | 2013-06-27 14:50:58 +0100 | [diff] [blame] | 60 | mutex_unlock(&comedi_drivers_list_lock); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 61 | |
David Howells | 1f817b8 | 2013-04-08 16:39:33 +0100 | [diff] [blame] | 62 | return 0; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Cheah Kok Cheong | ec0bff0 | 2016-12-30 19:26:50 +0800 | [diff] [blame] | 65 | void __init comedi_proc_init(void) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 66 | { |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 67 | if (!proc_create_single("comedi", 0444, NULL, comedi_read)) |
Cheah Kok Cheong | 2e4b5cd | 2016-12-30 19:27:41 +0800 | [diff] [blame] | 68 | pr_warn("comedi: unable to create proc entry\n"); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void comedi_proc_cleanup(void) |
| 72 | { |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 73 | remove_proc_entry("comedi", NULL); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 74 | } |