David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | module/proc.c |
| 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 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | This is some serious bloatware. |
| 26 | |
| 27 | Taken from Dave A.'s PCL-711 driver, 'cuz I thought it |
| 28 | was cool. |
| 29 | */ |
| 30 | |
| 31 | #define __NO_VERSION__ |
| 32 | #include "comedidev.h" |
Greg Kroah-Hartman | dc1da7f | 2010-04-30 15:59:18 -0700 | [diff] [blame] | 33 | #include "comedi_fops.h" |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 34 | #include <linux/proc_fs.h> |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 35 | #include <linux/string.h> |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 36 | |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_PROC_FS |
| 38 | static int comedi_read(char *buf, char **start, off_t offset, int len, |
| 39 | int *eof, void *data) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 40 | { |
| 41 | int i; |
| 42 | int devices_q = 0; |
| 43 | int l = 0; |
Bill Pemberton | 139dfbd | 2009-03-16 22:05:25 -0400 | [diff] [blame] | 44 | struct comedi_driver *driv; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 45 | |
| 46 | l += sprintf(buf + l, |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 47 | "comedi version " COMEDI_RELEASE "\n" |
| 48 | "format string: %s\n", |
Greg Kroah-Hartman | 8e81f18 | 2010-04-30 15:43:12 -0700 | [diff] [blame] | 49 | "\"%2d: %-20s %-20s %4d\", i, " |
| 50 | "driver_name, board_name, n_subdevices"); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 51 | |
| 52 | for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 53 | struct comedi_device_file_info *dev_file_info = |
| 54 | comedi_get_device_file_info(i); |
Bill Pemberton | 71b5f4f | 2009-03-16 22:05:08 -0400 | [diff] [blame] | 55 | struct comedi_device *dev; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 56 | |
Bill Pemberton | c742740 | 2009-03-16 22:03:56 -0400 | [diff] [blame] | 57 | if (dev_file_info == NULL) |
| 58 | continue; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 59 | dev = dev_file_info->device; |
| 60 | |
| 61 | if (dev->attached) { |
| 62 | devices_q = 1; |
| 63 | l += sprintf(buf + l, "%2d: %-20s %-20s %4d\n", |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 64 | i, |
| 65 | dev->driver->driver_name, |
| 66 | dev->board_name, dev->n_subdevices); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 67 | } |
| 68 | } |
Bill Pemberton | 82675f3 | 2009-03-16 22:04:23 -0400 | [diff] [blame] | 69 | if (!devices_q) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 70 | l += sprintf(buf + l, "no devices\n"); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 71 | |
| 72 | for (driv = comedi_drivers; driv; driv = driv->next) { |
| 73 | l += sprintf(buf + l, "%s:\n", driv->driver_name); |
| 74 | for (i = 0; i < driv->num_names; i++) { |
| 75 | l += sprintf(buf + l, " %s\n", |
Mithlesh Thukral | 0a85b6f | 2009-06-08 21:04:41 +0530 | [diff] [blame] | 76 | *(char **)((char *)driv->board_name + |
| 77 | i * driv->offset)); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 78 | } |
Bill Pemberton | 82675f3 | 2009-03-16 22:04:23 -0400 | [diff] [blame] | 79 | if (!driv->num_names) |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 80 | l += sprintf(buf + l, " %s\n", driv->driver_name); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return l; |
| 84 | } |
| 85 | |
| 86 | void comedi_proc_init(void) |
| 87 | { |
| 88 | struct proc_dir_entry *comedi_proc; |
| 89 | |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 90 | comedi_proc = create_proc_entry("comedi", S_IFREG | S_IRUGO, NULL); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 91 | if (comedi_proc) |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 92 | comedi_proc->read_proc = comedi_read; |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void comedi_proc_cleanup(void) |
| 96 | { |
Greg Kroah-Hartman | 22d1142 | 2010-05-03 15:32:04 -0700 | [diff] [blame] | 97 | remove_proc_entry("comedi", NULL); |
David Schleef | ed9eccb | 2008-11-04 20:29:31 -0800 | [diff] [blame] | 98 | } |
J.R. Mauro | a8275fc | 2008-11-14 20:01:14 -0500 | [diff] [blame] | 99 | #endif |