Release 4.7 drivers/staging/comedi/kcomedilib/kcomedilib_main.c
  
  
/*
 * kcomedilib/kcomedilib.c
 * a comedlib interface for kernel modules
 *
 * COMEDI - Linux Control and Measurement Device Interface
 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/io.h>
#include "../comedi.h"
#include "../comedilib.h"
#include "../comedidev.h"
MODULE_AUTHOR("David Schleef <ds@schleef.org>");
MODULE_DESCRIPTION("Comedi kernel library");
MODULE_LICENSE("GPL");
struct comedi_device *comedi_open(const char *filename)
{
	struct comedi_device *dev, *retval = NULL;
	unsigned int minor;
	if (strncmp(filename, "/dev/comedi", 11) != 0)
		return NULL;
	if (kstrtouint(filename + 11, 0, &minor))
		return NULL;
	if (minor >= COMEDI_NUM_BOARD_MINORS)
		return NULL;
	dev = comedi_dev_get_from_minor(minor);
	if (!dev)
		return NULL;
	down_read(&dev->attach_lock);
	if (dev->attached)
		retval = dev;
	else
		retval = NULL;
	up_read(&dev->attach_lock);
	if (!retval)
		comedi_dev_put(dev);
	return retval;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david a. schleef | david a. schleef | 69 | 54.33% | 1 | 14.29% | 
| ian abbott | ian abbott | 43 | 33.86% | 2 | 28.57% | 
| chase southwood | chase southwood | 10 | 7.87% | 1 | 14.29% | 
| h hartley sweeten | h hartley sweeten | 3 | 2.36% | 2 | 28.57% | 
| greg kroah-hartman | greg kroah-hartman | 2 | 1.57% | 1 | 14.29% | 
 | Total | 127 | 100.00% | 7 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_open);
int comedi_close(struct comedi_device *dev)
{
	comedi_dev_put(dev);
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david a. schleef | david a. schleef | 10 | 55.56% | 1 | 25.00% | 
| ian abbott | ian abbott | 6 | 33.33% | 2 | 50.00% | 
| greg kroah-hartman | greg kroah-hartman | 2 | 11.11% | 1 | 25.00% | 
 | Total | 18 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_close);
static int comedi_do_insn(struct comedi_device *dev,
			  struct comedi_insn *insn,
			  unsigned int *data)
{
	struct comedi_subdevice *s;
	int ret;
	mutex_lock(&dev->mutex);
	if (!dev->attached) {
		ret = -EINVAL;
		goto error;
	}
	/* a subdevice instruction */
	if (insn->subdev >= dev->n_subdevices) {
		ret = -EINVAL;
		goto error;
	}
	s = &dev->subdevices[insn->subdev];
	if (s->type == COMEDI_SUBD_UNUSED) {
		dev_err(dev->class_dev,
			"%d not usable subdevice\n", insn->subdev);
		ret = -EIO;
		goto error;
	}
	/* XXX check lock */
	ret = comedi_check_chanlist(s, 1, &insn->chanspec);
	if (ret < 0) {
		dev_err(dev->class_dev, "bad chanspec\n");
		ret = -EINVAL;
		goto error;
	}
	if (s->busy) {
		ret = -EBUSY;
		goto error;
	}
	s->busy = dev;
	switch (insn->insn) {
	case INSN_BITS:
		ret = s->insn_bits(dev, s, insn, data);
		break;
	case INSN_CONFIG:
		/* XXX should check instruction length */
		ret = s->insn_config(dev, s, insn, data);
		break;
	default:
		ret = -EINVAL;
		break;
	}
	s->busy = NULL;
error:
	mutex_unlock(&dev->mutex);
	return ret;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| david a. schleef | david a. schleef | 184 | 72.73% | 1 | 7.69% | 
| ian abbott | ian abbott | 33 | 13.04% | 1 | 7.69% | 
| greg kroah-hartman | greg kroah-hartman | 11 | 4.35% | 4 | 30.77% | 
| toshiaki yamane | toshiaki yamane | 10 | 3.95% | 1 | 7.69% | 
| h hartley sweeten | h hartley sweeten | 8 | 3.16% | 2 | 15.38% | 
| bill pemberton | bill pemberton | 6 | 2.37% | 3 | 23.08% | 
| gustavo silva | gustavo silva | 1 | 0.40% | 1 | 7.69% | 
 | Total | 253 | 100.00% | 13 | 100.00% | 
int comedi_dio_get_config(struct comedi_device *dev, unsigned int subdev,
			  unsigned int chan, unsigned int *io)
{
	struct comedi_insn insn;
	unsigned int data[2];
	int ret;
	memset(&insn, 0, sizeof(insn));
	insn.insn = INSN_CONFIG;
	insn.n = 2;
	insn.subdev = subdev;
	insn.chanspec = CR_PACK(chan, 0, 0);
	data[0] = INSN_CONFIG_DIO_QUERY;
	data[1] = 0;
	ret = comedi_do_insn(dev, &insn, data);
	if (ret >= 0)
		*io = data[1];
	return ret;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| ian abbott | ian abbott | 124 | 100.00% | 1 | 100.00% | 
 | Total | 124 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_dio_get_config);
int comedi_dio_config(struct comedi_device *dev, unsigned int subdev,
		      unsigned int chan, unsigned int io)
{
	struct comedi_insn insn;
	memset(&insn, 0, sizeof(insn));
	insn.insn = INSN_CONFIG;
	insn.n = 1;
	insn.subdev = subdev;
	insn.chanspec = CR_PACK(chan, 0, 0);
	return comedi_do_insn(dev, &insn, &io);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| greg kroah-hartman | greg kroah-hartman | 79 | 96.34% | 2 | 66.67% | 
| h hartley sweeten | h hartley sweeten | 3 | 3.66% | 1 | 33.33% | 
 | Total | 82 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_dio_config);
int comedi_dio_bitfield2(struct comedi_device *dev, unsigned int subdev,
			 unsigned int mask, unsigned int *bits,
			 unsigned int base_channel)
{
	struct comedi_insn insn;
	unsigned int data[2];
	unsigned int n_chan;
	unsigned int shift;
	int ret;
	base_channel = CR_CHAN(base_channel);
	n_chan = comedi_get_n_channels(dev, subdev);
	if (base_channel >= n_chan)
		return -EINVAL;
	memset(&insn, 0, sizeof(insn));
	insn.insn = INSN_BITS;
	insn.chanspec = base_channel;
	insn.n = 2;
	insn.subdev = subdev;
	data[0] = mask;
	data[1] = *bits;
	/*
         * Most drivers ignore the base channel in insn->chanspec.
         * Fix this here if the subdevice has <= 32 channels.
         */
	if (n_chan <= 32) {
		shift = base_channel;
		if (shift) {
			insn.chanspec = 0;
			data[0] <<= shift;
			data[1] <<= shift;
		}
	} else {
		shift = 0;
	}
	ret = comedi_do_insn(dev, &insn, data);
	*bits = data[1] >> shift;
	return ret;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| greg kroah-hartman | greg kroah-hartman | 103 | 52.02% | 2 | 50.00% | 
| ian abbott | ian abbott | 93 | 46.97% | 1 | 25.00% | 
| h hartley sweeten | h hartley sweeten | 2 | 1.01% | 1 | 25.00% | 
 | Total | 198 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_dio_bitfield2);
int comedi_find_subdevice_by_type(struct comedi_device *dev, int type,
				  unsigned int subd)
{
	struct comedi_subdevice *s;
	int ret = -ENODEV;
	down_read(&dev->attach_lock);
	if (dev->attached)
		for (; subd < dev->n_subdevices; subd++) {
			s = &dev->subdevices[subd];
			if (s->type == type) {
				ret = subd;
				break;
			}
		}
	up_read(&dev->attach_lock);
	return ret;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| greg kroah-hartman | greg kroah-hartman | 49 | 53.26% | 2 | 50.00% | 
| ian abbott | ian abbott | 30 | 32.61% | 1 | 25.00% | 
| h hartley sweeten | h hartley sweeten | 13 | 14.13% | 1 | 25.00% | 
 | Total | 92 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_find_subdevice_by_type);
int comedi_get_n_channels(struct comedi_device *dev, unsigned int subdevice)
{
	int n;
	down_read(&dev->attach_lock);
	if (!dev->attached || subdevice >= dev->n_subdevices)
		n = 0;
	else
		n = dev->subdevices[subdevice].n_chan;
	up_read(&dev->attach_lock);
	return n;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| ian abbott | ian abbott | 42 | 64.62% | 1 | 25.00% | 
| greg kroah-hartman | greg kroah-hartman | 20 | 30.77% | 2 | 50.00% | 
| h hartley sweeten | h hartley sweeten | 3 | 4.62% | 1 | 25.00% | 
 | Total | 65 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(comedi_get_n_channels);
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| ian abbott | ian abbott | 377 | 36.25% | 4 | 16.67% | 
| david a. schleef | david a. schleef | 307 | 29.52% | 1 | 4.17% | 
| greg kroah-hartman | greg kroah-hartman | 290 | 27.88% | 7 | 29.17% | 
| h hartley sweeten | h hartley sweeten | 38 | 3.65% | 5 | 20.83% | 
| toshiaki yamane | toshiaki yamane | 10 | 0.96% | 1 | 4.17% | 
| chase southwood | chase southwood | 10 | 0.96% | 1 | 4.17% | 
| bill pemberton | bill pemberton | 6 | 0.58% | 3 | 12.50% | 
| nayeemahmed badebade | nayeemahmed badebade | 1 | 0.10% | 1 | 4.17% | 
| gustavo silva | gustavo silva | 1 | 0.10% | 1 | 4.17% | 
 | Total | 1040 | 100.00% | 24 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.