Commit b79a7a20 authored by David Schleef's avatar David Schleef Committed by Greg Kroah-Hartman

Staging: comedi: add kcomedilib to the tree

This adds the kcomedilib module

From: David Schleef <ds@schleef.org>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 02ebd471
obj-$(CONFIG_COMEDI) += comedi.o
obj-$(CONFIG_COMEDI_RT) += comedi_rt.o
obj-$(CONFIG_COMEDI) += kcomedilib/
comedi-objs := \
comedi_fops.o \
proc.o \
......
obj-$(CONFIG_COMEDI) += kcomedilib.o
kcomedilib-objs := \
data.o \
ksyms.o \
dio.o \
kcomedilib_main.o \
get.o
/*
kcomedilib/data.c
implements comedi_data_*() functions
COMEDI - Linux Control and Measurement Device Interface
Copyright (C) 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "../comedi.h"
#include "../comedilib.h"
#include "../comedidev.h" /* for comedi_udelay() */
#include <linux/string.h>
int comedi_data_write(comedi_t * dev, unsigned int subdev, unsigned int chan,
unsigned int range, unsigned int aref, lsampl_t data)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_WRITE;
insn.n = 1;
insn.data = &data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, range, aref);
return comedi_do_insn(dev, &insn);
}
int comedi_data_read(comedi_t * dev, unsigned int subdev, unsigned int chan,
unsigned int range, unsigned int aref, lsampl_t * data)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
insn.n = 1;
insn.data = data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, range, aref);
return comedi_do_insn(dev, &insn);
}
int comedi_data_read_hint(comedi_t * dev, unsigned int subdev,
unsigned int chan, unsigned int range, unsigned int aref)
{
comedi_insn insn;
lsampl_t dummy_data;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
insn.n = 0;
insn.data = &dummy_data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, range, aref);
return comedi_do_insn(dev, &insn);
}
int comedi_data_read_delayed(comedi_t * dev, unsigned int subdev,
unsigned int chan, unsigned int range, unsigned int aref,
lsampl_t * data, unsigned int nano_sec)
{
int retval;
retval = comedi_data_read_hint(dev, subdev, chan, range, aref);
if (retval < 0)
return retval;
comedi_udelay((nano_sec + 999) / 1000);
return comedi_data_read(dev, subdev, chan, range, aref, data);
}
/*
kcomedilib/dio.c
implements comedi_dio_*() functions
COMEDI - Linux Control and Measurement Device Interface
Copyright (C) 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "../comedi.h"
#include "../comedilib.h"
#include <linux/string.h>
int comedi_dio_config(comedi_t * dev, unsigned int subdev, unsigned int chan,
unsigned int io)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
insn.data = &io;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, 0, 0);
return comedi_do_insn(dev, &insn);
}
int comedi_dio_read(comedi_t * dev, unsigned int subdev, unsigned int chan,
unsigned int *val)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
insn.n = 1;
insn.data = val;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, 0, 0);
return comedi_do_insn(dev, &insn);
}
int comedi_dio_write(comedi_t * dev, unsigned int subdev, unsigned int chan,
unsigned int val)
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_WRITE;
insn.n = 1;
insn.data = &val;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan, 0, 0);
return comedi_do_insn(dev, &insn);
}
int comedi_dio_bitfield(comedi_t * dev, unsigned int subdev, unsigned int mask,
unsigned int *bits)
{
comedi_insn insn;
lsampl_t data[2];
int ret;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_BITS;
insn.n = 2;
insn.data = data;
insn.subdev = subdev;
data[0] = mask;
data[1] = *bits;
ret = comedi_do_insn(dev, &insn);
*bits = data[1];
return ret;
}
/*
kcomedilib/get.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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define __NO_VERSION__
#include "../comedi.h"
#include "../comedilib.h"
#include "../comedidev.h"
int comedi_get_n_subdevices(comedi_t * d)
{
comedi_device *dev = (comedi_device *) d;
return dev->n_subdevices;
}
int comedi_get_version_code(comedi_t * d)
{
return COMEDI_VERSION_CODE;
}
const char *comedi_get_driver_name(comedi_t * d)
{
comedi_device *dev = (comedi_device *) d;
return dev->driver->driver_name;
}
const char *comedi_get_board_name(comedi_t * d)
{
comedi_device *dev = (comedi_device *) d;
return dev->board_name;
}
int comedi_get_subdevice_type(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
return s->type;
}
unsigned int comedi_get_subdevice_flags(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
return s->subdev_flags;
}
int comedi_find_subdevice_by_type(comedi_t * d, int type, unsigned int subd)
{
comedi_device *dev = (comedi_device *) d;
if (subd > dev->n_subdevices)
return -ENODEV;
for (; subd < dev->n_subdevices; subd++) {
if (dev->subdevices[subd].type == type)
return subd;
}
return -1;
}
int comedi_get_n_channels(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
return s->n_chan;
}
int comedi_get_len_chanlist(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
return s->len_chanlist;
}
lsampl_t comedi_get_maxdata(comedi_t * d, unsigned int subdevice,
unsigned int chan)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
if (s->maxdata_list)
return s->maxdata_list[chan];
return s->maxdata;
}
#ifdef KCOMEDILIB_DEPRECATED
int comedi_get_rangetype(comedi_t * d, unsigned int subdevice,
unsigned int chan)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
int ret;
if (s->range_table_list) {
ret = s->range_table_list[chan]->length;
} else {
ret = s->range_table->length;
}
ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16);
return ret;
}
#endif
int comedi_get_n_ranges(comedi_t * d, unsigned int subdevice, unsigned int chan)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
int ret;
if (s->range_table_list) {
ret = s->range_table_list[chan]->length;
} else {
ret = s->range_table->length;
}
return ret;
}
/*
* ALPHA (non-portable)
*/
int comedi_get_krange(comedi_t * d, unsigned int subdevice, unsigned int chan,
unsigned int range, comedi_krange * krange)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
const comedi_lrange *lr;
if (s->range_table_list) {
lr = s->range_table_list[chan];
} else {
lr = s->range_table;
}
if (range >= lr->length) {
return -EINVAL;
}
memcpy(krange, lr->range + range, sizeof(comedi_krange));
return 0;
}
/*
* ALPHA (may be renamed)
*/
unsigned int comedi_get_buf_head_pos(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
async = s->async;
if (async == NULL)
return 0;
return async->buf_write_count;
}
int comedi_get_buffer_contents(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
unsigned int num_bytes;
if (subdevice >= dev->n_subdevices)
return -1;
async = s->async;
if (async == NULL)
return 0;
num_bytes = comedi_buf_read_n_available(s->async);
return num_bytes;
}
/*
* ALPHA
*/
int comedi_set_user_int_count(comedi_t * d, unsigned int subdevice,
unsigned int buf_user_count)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
int num_bytes;
async = s->async;
if (async == NULL)
return -1;
num_bytes = buf_user_count - async->buf_read_count;
if (num_bytes < 0)
return -1;
comedi_buf_read_alloc(async, num_bytes);
comedi_buf_read_free(async, num_bytes);
return 0;
}
int comedi_mark_buffer_read(comedi_t * d, unsigned int subdevice,
unsigned int num_bytes)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
if (subdevice >= dev->n_subdevices)
return -1;
async = s->async;
if (async == NULL)
return -1;
comedi_buf_read_alloc(async, num_bytes);
comedi_buf_read_free(async, num_bytes);
return 0;
}
int comedi_mark_buffer_written(comedi_t * d, unsigned int subdevice,
unsigned int num_bytes)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
int bytes_written;
if (subdevice >= dev->n_subdevices)
return -1;
async = s->async;
if (async == NULL)
return -1;
bytes_written = comedi_buf_write_alloc(async, num_bytes);
comedi_buf_write_free(async, bytes_written);
if (bytes_written != num_bytes)
return -1;
return 0;
}
int comedi_get_buffer_size(comedi_t * d, unsigned int subdev)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdev;
comedi_async *async;
if (subdev >= dev->n_subdevices)
return -1;
async = s->async;
if (async == NULL)
return 0;
return async->prealloc_bufsz;
}
int comedi_get_buffer_offset(comedi_t * d, unsigned int subdevice)
{
comedi_device *dev = (comedi_device *) d;
comedi_subdevice *s = dev->subdevices + subdevice;
comedi_async *async;
if (subdevice >= dev->n_subdevices)
return -1;
async = s->async;
if (async == NULL)
return 0;
return async->buf_read_ptr;
}
This diff is collapsed.
/*
comedi/kcomedilib/ksyms.c
a comedlib interface for kernel modules
COMEDI - Linux Control and Measurement Device Interface
Copyright (C) 1997-2001 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef EXPORT_SYMTAB
#define EXPORT_SYMTAB
#endif
#include "../comedi.h"
#include "../comedilib.h"
#include "../comedidev.h"
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/mm.h>
#include <linux/slab.h>
#if LINUX_VERSION_CODE >= 0x020200
/* functions specific to kcomedilib */
EXPORT_SYMBOL(comedi_register_callback);
EXPORT_SYMBOL(comedi_get_krange);
EXPORT_SYMBOL(comedi_get_buf_head_pos);
EXPORT_SYMBOL(comedi_set_user_int_count);
EXPORT_SYMBOL(comedi_map);
EXPORT_SYMBOL(comedi_unmap);
/* This list comes from user-space comedilib, to show which
* functions are not ported yet. */
EXPORT_SYMBOL(comedi_open);
EXPORT_SYMBOL(comedi_close);
/* logging */
EXPORT_SYMBOL(comedi_loglevel);
EXPORT_SYMBOL(comedi_perror);
EXPORT_SYMBOL(comedi_strerror);
//EXPORT_SYMBOL(comedi_errno);
EXPORT_SYMBOL(comedi_fileno);
/* device queries */
EXPORT_SYMBOL(comedi_get_n_subdevices);
EXPORT_SYMBOL(comedi_get_version_code);
EXPORT_SYMBOL(comedi_get_driver_name);
EXPORT_SYMBOL(comedi_get_board_name);
/* subdevice queries */
EXPORT_SYMBOL(comedi_get_subdevice_type);
EXPORT_SYMBOL(comedi_find_subdevice_by_type);
EXPORT_SYMBOL(comedi_get_subdevice_flags);
EXPORT_SYMBOL(comedi_get_n_channels);
//EXPORT_SYMBOL(comedi_range_is_chan_specific);
//EXPORT_SYMBOL(comedi_maxdata_is_chan_specific);
/* channel queries */
EXPORT_SYMBOL(comedi_get_maxdata);
#ifdef KCOMEDILIB_DEPRECATED
EXPORT_SYMBOL(comedi_get_rangetype);
#endif
EXPORT_SYMBOL(comedi_get_n_ranges);
//EXPORT_SYMBOL(comedi_find_range);
/* buffer queries */
EXPORT_SYMBOL(comedi_get_buffer_size);
//EXPORT_SYMBOL(comedi_get_max_buffer_size);
//EXPORT_SYMBOL(comedi_set_buffer_size);
EXPORT_SYMBOL(comedi_get_buffer_contents);
EXPORT_SYMBOL(comedi_get_buffer_offset);
/* low-level stuff */
//EXPORT_SYMBOL(comedi_trigger);
//EXPORT_SYMBOL(comedi_do_insnlist);
EXPORT_SYMBOL(comedi_do_insn);
EXPORT_SYMBOL(comedi_lock);
EXPORT_SYMBOL(comedi_unlock);
/* physical units */
//EXPORT_SYMBOL(comedi_to_phys);
//EXPORT_SYMBOL(comedi_from_phys);
/* synchronous stuff */
EXPORT_SYMBOL(comedi_data_read);
EXPORT_SYMBOL(comedi_data_read_hint);
EXPORT_SYMBOL(comedi_data_read_delayed);
EXPORT_SYMBOL(comedi_data_write);
EXPORT_SYMBOL(comedi_dio_config);
EXPORT_SYMBOL(comedi_dio_read);
EXPORT_SYMBOL(comedi_dio_write);
EXPORT_SYMBOL(comedi_dio_bitfield);
/* slowly varying stuff */
//EXPORT_SYMBOL(comedi_sv_init);
//EXPORT_SYMBOL(comedi_sv_update);
//EXPORT_SYMBOL(comedi_sv_measure);
/* commands */
//EXPORT_SYMBOL(comedi_get_cmd_src_mask);
//EXPORT_SYMBOL(comedi_get_cmd_generic_timed);
EXPORT_SYMBOL(comedi_cancel);
EXPORT_SYMBOL(comedi_command);
EXPORT_SYMBOL(comedi_command_test);
EXPORT_SYMBOL(comedi_poll);
/* buffer configuration */
EXPORT_SYMBOL(comedi_mark_buffer_read);
EXPORT_SYMBOL(comedi_mark_buffer_written);
//EXPORT_SYMBOL(comedi_get_range);
EXPORT_SYMBOL(comedi_get_len_chanlist);
/* deprecated */
//EXPORT_SYMBOL(comedi_get_timer);
//EXPORT_SYMBOL(comedi_timed_1chan);
/* alpha */
//EXPORT_SYMBOL(comedi_set_global_oor_behavior);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment