staging: comedi: remove comedi_dev_from_minor()
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / comedidev.h
index 1d8e61a822fdd25a71c98183098e1e363cec1813..4e7cd1443be66e0a7cab38c940483fe63b93f2d8 100644 (file)
 #define _COMEDIDEV_H
 
 #include <linux/dma-mapping.h>
+#include <linux/mutex.h>
+#include <linux/spinlock_types.h>
+#include <linux/rwsem.h>
+#include <linux/kref.h>
 
 #include "comedi.h"
 
@@ -57,11 +61,6 @@ struct comedi_subdevice {
        unsigned int maxdata;   /* if maxdata==0, use list */
        const unsigned int *maxdata_list;       /* list is channel specific */
 
-       unsigned int flags;
-       const unsigned int *flaglist;
-
-       unsigned int settling_time_0;
-
        const struct comedi_lrange *range_table;
        const struct comedi_lrange *const *range_table_list;
 
@@ -146,10 +145,7 @@ struct comedi_async {
 
        wait_queue_head_t wait_head;
 
-       /* callback stuff */
        unsigned int cb_mask;
-       int (*cb_func) (unsigned int flags, void *);
-       void *cb_arg;
 
        int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s,
                        unsigned int x);
@@ -178,6 +174,7 @@ struct comedi_device {
 
        struct device *class_dev;
        int minor;
+       unsigned int detach_count;
        /* hw_dev is passed to dma_alloc_coherent when allocating async buffers
         * for subdevices that have async_dma_dir set to something other than
         * DMA_NONE */
@@ -190,6 +187,8 @@ struct comedi_device {
        bool ioenabled:1;
        spinlock_t spinlock;
        struct mutex mutex;
+       struct rw_semaphore attach_lock;
+       struct kref refcount;
 
        int n_subdevices;
        struct comedi_subdevice *subdevices;
@@ -236,7 +235,8 @@ enum comedi_minor_bits {
 static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4;
 static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1;
 
-struct comedi_device *comedi_dev_from_minor(unsigned minor);
+struct comedi_device *comedi_dev_get_from_minor(unsigned minor);
+int comedi_dev_put(struct comedi_device *dev);
 
 void init_polling(void);
 void cleanup_polling(void);
@@ -245,7 +245,6 @@ void stop_polling(struct comedi_device *);
 
 /* subdevice runflags */
 enum subdevice_runflags {
-       SRF_USER = 0x00000001,
        SRF_RT = 0x00000002,
        /* indicates an COMEDI_CB_ERROR event has occurred since the last
         * command was started */
@@ -307,7 +306,26 @@ static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s,
        return s->range_table->range[range].min >= 0;
 }
 
-/* some silly little inline functions */
+static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s,
+                                               unsigned int chan,
+                                               unsigned int range)
+{
+       return s->range_table_list[chan]->range[range].min < 0;
+}
+
+static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s,
+                                                unsigned int chan,
+                                                unsigned int range)
+{
+       return s->range_table_list[chan]->range[range].min >= 0;
+}
+
+/* munge between offset binary and two's complement values */
+static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
+                                              unsigned int val)
+{
+       return val ^ s->maxdata ^ (s->maxdata >> 1);
+}
 
 static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
 {
@@ -332,8 +350,8 @@ unsigned int comedi_buf_read_n_available(struct comedi_async *);
 unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int);
 unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int);
 
-int comedi_buf_put(struct comedi_async *, short);
-int comedi_buf_get(struct comedi_async *, short *);
+int comedi_buf_put(struct comedi_async *, unsigned short);
+int comedi_buf_get(struct comedi_async *, unsigned short *);
 
 void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
                          const void *source, unsigned int num_bytes);