linux/drivers/staging/comedi/kcomedilib/get.c
<<
>>
Prefs
   1/*
   2    kcomedilib/get.c
   3    a comedlib interface for kernel modules
   4
   5    COMEDI - Linux Control and Measurement Device Interface
   6    Copyright (C) 1997-2000 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#define __NO_VERSION__
  25#include "../comedi.h"
  26#include "../comedilib.h"
  27#include "../comedidev.h"
  28
  29int comedi_get_n_subdevices(void *d)
  30{
  31        struct comedi_device *dev = (struct comedi_device *)d;
  32
  33        return dev->n_subdevices;
  34}
  35
  36int comedi_get_version_code(void *d)
  37{
  38        return COMEDI_VERSION_CODE;
  39}
  40
  41const char *comedi_get_driver_name(void *d)
  42{
  43        struct comedi_device *dev = (struct comedi_device *)d;
  44
  45        return dev->driver->driver_name;
  46}
  47
  48const char *comedi_get_board_name(void *d)
  49{
  50        struct comedi_device *dev = (struct comedi_device *)d;
  51
  52        return dev->board_name;
  53}
  54
  55int comedi_get_subdevice_type(void *d, unsigned int subdevice)
  56{
  57        struct comedi_device *dev = (struct comedi_device *)d;
  58        struct comedi_subdevice *s = dev->subdevices + subdevice;
  59
  60        return s->type;
  61}
  62
  63unsigned int comedi_get_subdevice_flags(void *d, unsigned int subdevice)
  64{
  65        struct comedi_device *dev = (struct comedi_device *)d;
  66        struct comedi_subdevice *s = dev->subdevices + subdevice;
  67
  68        return s->subdev_flags;
  69}
  70
  71int comedi_find_subdevice_by_type(void *d, int type, unsigned int subd)
  72{
  73        struct comedi_device *dev = (struct comedi_device *)d;
  74
  75        if (subd > dev->n_subdevices)
  76                return -ENODEV;
  77
  78        for (; subd < dev->n_subdevices; subd++) {
  79                if (dev->subdevices[subd].type == type)
  80                        return subd;
  81        }
  82        return -1;
  83}
  84
  85int comedi_get_n_channels(void *d, unsigned int subdevice)
  86{
  87        struct comedi_device *dev = (struct comedi_device *)d;
  88        struct comedi_subdevice *s = dev->subdevices + subdevice;
  89
  90        return s->n_chan;
  91}
  92
  93int comedi_get_len_chanlist(void *d, unsigned int subdevice)
  94{
  95        struct comedi_device *dev = (struct comedi_device *)d;
  96        struct comedi_subdevice *s = dev->subdevices + subdevice;
  97
  98        return s->len_chanlist;
  99}
 100
 101unsigned int comedi_get_maxdata(void *d, unsigned int subdevice,
 102                                unsigned int chan)
 103{
 104        struct comedi_device *dev = (struct comedi_device *)d;
 105        struct comedi_subdevice *s = dev->subdevices + subdevice;
 106
 107        if (s->maxdata_list)
 108                return s->maxdata_list[chan];
 109
 110        return s->maxdata;
 111}
 112
 113#ifdef KCOMEDILIB_DEPRECATED
 114int comedi_get_rangetype(void *d, unsigned int subdevice, unsigned int chan)
 115{
 116        struct comedi_device *dev = (struct comedi_device *)d;
 117        struct comedi_subdevice *s = dev->subdevices + subdevice;
 118        int ret;
 119
 120        if (s->range_table_list) {
 121                ret = s->range_table_list[chan]->length;
 122        } else {
 123                ret = s->range_table->length;
 124        }
 125
 126        ret = ret | (dev->minor << 28) | (subdevice << 24) | (chan << 16);
 127
 128        return ret;
 129}
 130#endif
 131
 132int comedi_get_n_ranges(void *d, unsigned int subdevice, unsigned int chan)
 133{
 134        struct comedi_device *dev = (struct comedi_device *)d;
 135        struct comedi_subdevice *s = dev->subdevices + subdevice;
 136        int ret;
 137
 138        if (s->range_table_list) {
 139                ret = s->range_table_list[chan]->length;
 140        } else {
 141                ret = s->range_table->length;
 142        }
 143
 144        return ret;
 145}
 146
 147/*
 148 * ALPHA (non-portable)
 149*/
 150int comedi_get_krange(void *d, unsigned int subdevice, unsigned int chan,
 151                      unsigned int range, struct comedi_krange *krange)
 152{
 153        struct comedi_device *dev = (struct comedi_device *)d;
 154        struct comedi_subdevice *s = dev->subdevices + subdevice;
 155        const struct comedi_lrange *lr;
 156
 157        if (s->range_table_list) {
 158                lr = s->range_table_list[chan];
 159        } else {
 160                lr = s->range_table;
 161        }
 162        if (range >= lr->length)
 163                return -EINVAL;
 164
 165        memcpy(krange, lr->range + range, sizeof(struct comedi_krange));
 166
 167        return 0;
 168}
 169
 170/*
 171 * ALPHA (may be renamed)
 172*/
 173unsigned int comedi_get_buf_head_pos(void *d, unsigned int subdevice)
 174{
 175        struct comedi_device *dev = (struct comedi_device *)d;
 176        struct comedi_subdevice *s = dev->subdevices + subdevice;
 177        struct comedi_async *async;
 178
 179        async = s->async;
 180        if (async == NULL)
 181                return 0;
 182
 183        return async->buf_write_count;
 184}
 185
 186int comedi_get_buffer_contents(void *d, unsigned int subdevice)
 187{
 188        struct comedi_device *dev = (struct comedi_device *)d;
 189        struct comedi_subdevice *s = dev->subdevices + subdevice;
 190        struct comedi_async *async;
 191        unsigned int num_bytes;
 192
 193        if (subdevice >= dev->n_subdevices)
 194                return -1;
 195        async = s->async;
 196        if (async == NULL)
 197                return 0;
 198        num_bytes = comedi_buf_read_n_available(s->async);
 199        return num_bytes;
 200}
 201
 202/*
 203 * ALPHA
 204*/
 205int comedi_set_user_int_count(void *d, unsigned int subdevice,
 206                              unsigned int buf_user_count)
 207{
 208        struct comedi_device *dev = (struct comedi_device *)d;
 209        struct comedi_subdevice *s = dev->subdevices + subdevice;
 210        struct comedi_async *async;
 211        int num_bytes;
 212
 213        async = s->async;
 214        if (async == NULL)
 215                return -1;
 216
 217        num_bytes = buf_user_count - async->buf_read_count;
 218        if (num_bytes < 0)
 219                return -1;
 220        comedi_buf_read_alloc(async, num_bytes);
 221        comedi_buf_read_free(async, num_bytes);
 222
 223        return 0;
 224}
 225
 226int comedi_mark_buffer_read(void *d, unsigned int subdevice,
 227                            unsigned int num_bytes)
 228{
 229        struct comedi_device *dev = (struct comedi_device *)d;
 230        struct comedi_subdevice *s = dev->subdevices + subdevice;
 231        struct comedi_async *async;
 232
 233        if (subdevice >= dev->n_subdevices)
 234                return -1;
 235        async = s->async;
 236        if (async == NULL)
 237                return -1;
 238
 239        comedi_buf_read_alloc(async, num_bytes);
 240        comedi_buf_read_free(async, num_bytes);
 241
 242        return 0;
 243}
 244
 245int comedi_mark_buffer_written(void *d, unsigned int subdevice,
 246                               unsigned int num_bytes)
 247{
 248        struct comedi_device *dev = (struct comedi_device *)d;
 249        struct comedi_subdevice *s = dev->subdevices + subdevice;
 250        struct comedi_async *async;
 251        int bytes_written;
 252
 253        if (subdevice >= dev->n_subdevices)
 254                return -1;
 255        async = s->async;
 256        if (async == NULL)
 257                return -1;
 258        bytes_written = comedi_buf_write_alloc(async, num_bytes);
 259        comedi_buf_write_free(async, bytes_written);
 260        if (bytes_written != num_bytes)
 261                return -1;
 262        return 0;
 263}
 264
 265int comedi_get_buffer_size(void *d, unsigned int subdev)
 266{
 267        struct comedi_device *dev = (struct comedi_device *)d;
 268        struct comedi_subdevice *s = dev->subdevices + subdev;
 269        struct comedi_async *async;
 270
 271        if (subdev >= dev->n_subdevices)
 272                return -1;
 273        async = s->async;
 274        if (async == NULL)
 275                return 0;
 276
 277        return async->prealloc_bufsz;
 278}
 279
 280int comedi_get_buffer_offset(void *d, unsigned int subdevice)
 281{
 282        struct comedi_device *dev = (struct comedi_device *)d;
 283        struct comedi_subdevice *s = dev->subdevices + subdevice;
 284        struct comedi_async *async;
 285
 286        if (subdevice >= dev->n_subdevices)
 287                return -1;
 288        async = s->async;
 289        if (async == NULL)
 290                return 0;
 291
 292        return async->buf_read_ptr;
 293}
 294