Module: xenomai-abe
Branch: experimental
Commit: 2e2d651448b577f2c3aa2f6e218ae161ab6883e2
URL:    
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=2e2d651448b577f2c3aa2f6e218ae161ab6883e2

Author: Alexis Berlemont <alexis.berlem...@gmail.com>
Date:   Thu Sep  1 00:18:25 2011 +0200

analogy: [ni_670x] review coding style

---

 .../drivers/analogy/national_instruments/ni_670x.c |  397 +++++++++-----------
 1 files changed, 175 insertions(+), 222 deletions(-)

diff --git a/ksrc/drivers/analogy/national_instruments/ni_670x.c 
b/ksrc/drivers/analogy/national_instruments/ni_670x.c
index e431a37..c4c4f76 100644
--- a/ksrc/drivers/analogy/national_instruments/ni_670x.c
+++ b/ksrc/drivers/analogy/national_instruments/ni_670x.c
@@ -46,12 +46,9 @@ Commands are not supported.
  *   Julien Delange <julien.dela...@esa.int>
  */
 
-
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <analogy/analogy_driver.h>
-#include <analogy/subdevice.h>
-#include <analogy/channel_range.h>
 
 #include "../intel/8255.h"
 #include "ni_mio.h"
@@ -72,7 +69,6 @@ Commands are not supported.
 
 /* Board description*/
 
-
 struct ni_670x_board {
        unsigned short device_id;
        const char *name;
@@ -82,25 +78,23 @@ struct ni_670x_board {
 
 #define thisboard ((struct ni_670x_board *)dev->board_ptr)
 
-
-
 struct ni_670x_private {
        struct mite_struct *mite;
        int boardtype;
        int dio;
        unsigned int ao_readback[32];
-/*
- * Added when porting to xenomai
- */
-   int irq_polarity;
-   int irq_pin;
-   int irq;
-   struct ni_670x_board *board_ptr;
-   /*
-    * END OF ADDED when porting to xenomai
-   */
-};
 
+       /*
+        * Added when porting to xenomai
+        */
+       int irq_polarity;
+       int irq_pin;
+       int irq;
+       struct ni_670x_board *board_ptr;
+       /*
+        * END OF ADDED when porting to xenomai
+        */
+};
 
 struct ni_670x_subd_priv {
         int io_bits;
@@ -110,94 +104,75 @@ struct ni_670x_subd_priv {
         void* counter;
 };
 
-
-static int ni_670x_ao_winsn
-                          (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn);
-
-static int ni_670x_ao_rinsn
-                          (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn);
-
-static int ni_670x_dio_insn_bits
-                               (a4l_subd_t *subd,
-                                a4l_kinsn_t *insn);
-
-static int ni_670x_dio_insn_config
-            (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn);
+static int ni_670x_ao_winsn(a4l_subd_t *subd, a4l_kinsn_t *insn);
+static int ni_670x_ao_rinsn(a4l_subd_t *subd, a4l_kinsn_t *insn);
+static int ni_670x_dio_insn_bits(a4l_subd_t *subd, a4l_kinsn_t *insn);
+static int ni_670x_dio_insn_config(a4l_subd_t *subd, a4l_kinsn_t *insn);
 
 static a4l_chdesc_t ni_670x_desc_dio = {
-   .mode = A4L_CHAN_GLOBAL_CHANDESC,
-   .length = 8,
-   .chans = {
-      {A4L_CHAN_AREF_GROUND, 1},
-   },
+       .mode = A4L_CHAN_GLOBAL_CHANDESC,
+       .length = 8,
+       .chans = {
+               {A4L_CHAN_AREF_GROUND, 1},
+       },
 };
 
 static a4l_chdesc_t ni_670x_desc_ao = {
-   .mode = A4L_CHAN_GLOBAL_CHANDESC,
-   .length = 0, /* initialized later according to the board found */
-   .chans = {
-      {A4L_CHAN_AREF_GROUND, 16},
-   },
+       .mode = A4L_CHAN_GLOBAL_CHANDESC,
+       .length = 0, /* initialized later according to the board found */
+       .chans = {
+               {A4L_CHAN_AREF_GROUND, 16},
+       },
 };
 
 
 static a4l_rngtab_t range_0_20mA = { 1, {RANGE_mA(0, 20)} };
-static a4l_rngtab_t rng_bipolar10 = { 1, {
-               RANGE_V(-10, 10),
-       }};
-
-
+static a4l_rngtab_t rng_bipolar10 = { 1, {RANGE_V(-10, 10) }};
 
 a4l_rngtab_t *range_table_list[32] = {
-&rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
-&rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
-&rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
-&rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
-&range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
-&range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
-&range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
-&range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA};
+       &rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
+       &rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
+       &rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
+       &rng_bipolar10, &rng_bipolar10, &rng_bipolar10, &rng_bipolar10,
+       &range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
+       &range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
+       &range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA,
+       &range_0_20mA, &range_0_20mA, &range_0_20mA, &range_0_20mA};
 
 static A4L_RNGDESC(32) ni670x_ao_desc;
 
 static void setup_subd_ao(a4l_subd_t *subd)
 {
-   int i;
-   int nchans;
-
-   nchans = ((struct ni_670x_private*)(subd->dev->priv))->board_ptr->ao_chans;
+       int i;
+       int nchans;
+       
+       nchans = ((struct 
ni_670x_private*)(subd->dev->priv))->board_ptr->ao_chans;
        subd->flags                = A4L_SUBD_AO;
-   subd->chan_desc            = &ni_670x_desc_ao;
-   subd->chan_desc->length    = nchans;
-       if (nchans == 32)
-   {
-               subd->rng_desc = (a4l_rngdesc_t*) &ni670x_ao_desc;
+       subd->chan_desc            = &ni_670x_desc_ao;
+       subd->chan_desc->length    = nchans;
+       if (nchans == 32) {
 
-      subd->rng_desc->mode = A4L_RNG_PERCHAN_RNGDESC;
-      for (i = 0 ; i < 16 ; i++)
-      {
-                  subd->rng_desc->rngtabs[i] =&rng_bipolar10;
-                  subd->rng_desc->rngtabs[16+i] =&range_0_20mA;
-      }
-       } else {
+               subd->rng_desc = (a4l_rngdesc_t*) &ni670x_ao_desc;
+               subd->rng_desc->mode = A4L_RNG_PERCHAN_RNGDESC;
+               for (i = 0 ; i < 16 ; i++) {
+                       subd->rng_desc->rngtabs[i] =&rng_bipolar10;
+                       subd->rng_desc->rngtabs[16+i] =&range_0_20mA;
+               }
+       } else
                subd->rng_desc = &a4l_range_bipolar10;
-       }
+
        subd->insn_write = &ni_670x_ao_winsn;
        subd->insn_read = &ni_670x_ao_rinsn;
 }
 
-
 static void setup_subd_dio(a4l_subd_t *s)
 {
-       /* digital i/o subdevice */
-   s->flags = A4L_SUBD_DIO;
-   s->chan_desc = &ni_670x_desc_dio;
-   s->rng_desc = &range_digital;
-   s->insn_bits = ni_670x_dio_insn_bits;
-   s->insn_config = ni_670x_dio_insn_config;
+       /* Digital i/o subdevice */
+       s->flags = A4L_SUBD_DIO;
+       s->chan_desc = &ni_670x_desc_dio;
+       s->rng_desc = &range_digital;
+       s->insn_bits = ni_670x_dio_insn_bits;
+       s->insn_config = ni_670x_dio_insn_config;
 }
 
 struct setup_subd {
@@ -206,36 +181,34 @@ struct setup_subd {
 };
 
 static struct setup_subd setup_subds[2] = {
-   {
-      .setup_func = setup_subd_ao,
-      .sizeof_priv = sizeof(struct ni_670x_subd_priv),
-   },
-   {
-      .setup_func = setup_subd_dio,
-      .sizeof_priv = sizeof(struct ni_670x_subd_priv),
-   },
+       {
+               .setup_func = setup_subd_ao,
+               .sizeof_priv = sizeof(struct ni_670x_subd_priv),
+       },
+       {
+               .setup_func = setup_subd_dio,
+               .sizeof_priv = sizeof(struct ni_670x_subd_priv),
+       },
 };
 
-
-
 static const struct ni_670x_board ni_670x_boards[] = {
        {
-        .device_id = 0x2c90,
-        .name = "PCI-6703",
-        .ao_chans = 16,
-        .ao_bits = 16,
-        },
+               .device_id = 0x2c90,
+               .name = "PCI-6703",
+               .ao_chans = 16,
+               .ao_bits = 16,
+       },
        {
-        .device_id = 0x1920,
-        .name = "PXI-6704",
-        .ao_chans = 32,
-        .ao_bits = 16,
-        },
+               .device_id = 0x1920,
+               .name = "PXI-6704",
+               .ao_chans = 32,
+               .ao_bits = 16,
+       },
        {
-        .device_id = 0x1290,
-        .name = "PCI-6704",
-        .ao_chans = 32,
-        .ao_bits = 16,
+               .device_id = 0x1290,
+               .name = "PCI-6704",
+               .ao_chans = 32,
+               .ao_bits = 16,
         },
 };
 
@@ -257,22 +230,20 @@ static inline struct ni_670x_private *private(a4l_dev_t 
*dev)
 }
 
 
-static int ni_670x_attach (a4l_dev_t *dev,
-                                         a4l_lnkdesc_t *arg);
+static int ni_670x_attach (a4l_dev_t *dev, a4l_lnkdesc_t *arg);
 static int ni_670x_detach(a4l_dev_t *dev);
 
-
 static a4l_drv_t ni_670x_drv = {
-   .owner = THIS_MODULE,
-   .board_name = "analogy_ni_670x",
+       .owner = THIS_MODULE,
+       .board_name = "analogy_ni_670x",
        .attach = ni_670x_attach,
        .detach = ni_670x_detach,
-   .privdata_size = sizeof(struct ni_670x_private),
+       .privdata_size = sizeof(struct ni_670x_private),
 };
 
 static int __init driver_ni_670x_init_module(void)
 {
-   return a4l_register_drv (&ni_670x_drv);
+       return a4l_register_drv (&ni_670x_drv);
 }
 
 static void __exit driver_ni_670x_cleanup_module(void)
@@ -283,20 +254,16 @@ static void __exit driver_ni_670x_cleanup_module(void)
 module_init(driver_ni_670x_init_module);
 module_exit(driver_ni_670x_cleanup_module);
 
-static int ni_670x_attach (a4l_dev_t *dev,
-                                         a4l_lnkdesc_t *arg)
+static int ni_670x_attach (a4l_dev_t *dev, a4l_lnkdesc_t *arg)
 {
        int ret, bus, slot, i, irq;
-   struct mite_struct *mite;
+       struct mite_struct *mite;
        struct ni_670x_board* board = NULL;
-   int err;
-
+       int err;
+       
        if(arg->opts == NULL || arg->opts_size == 0)
-   {
                bus = slot = 0;
-   }
-       else 
-   {
+       else {
                bus = arg->opts_size >= sizeof(unsigned long) ?
                        ((unsigned long *)arg->opts)[0] : 0;
                slot = arg->opts_size >= sizeof(unsigned long) * 2 ?
@@ -304,66 +271,60 @@ static int ni_670x_attach (a4l_dev_t *dev,
        }
 
        printk(KERN_INFO "[ANALOGY] [NI_670x]: Will try to attach ni670x device 
(bus=%d/slot=%d)...", bus, slot);
+       
+       mite = NULL;
 
-   mite = NULL;
-
-       for(i = 0; i <  n_ni_670x_boards && mite == NULL; i++) 
-   {
+       for(i = 0; i <  n_ni_670x_boards && mite == NULL; i++) {
                mite = a4l_mite_find_device(bus, slot, 
ni_670x_boards[i].device_id);
                board = (struct ni_670x_board*) &ni_670x_boards[i];
        }
 
-       if(mite == NULL)
-   {
+       if(mite == NULL) {
                printk(KERN_WARNING "[ANALOGY] [NI_670x]: cannot find the MITE 
device\n");
                return -ENOENT;
-   }
+       }
 
        printk(KERN_INFO "[ANALOGY] [NI_670x]: Found device %d %s\n", i , 
ni_670x_boards[i].name);
-
+       
        devpriv->irq_polarity = PCIMIO_IRQ_POLARITY;
        devpriv->irq_pin = 0;
-
+       
        devpriv->mite = mite;
        devpriv->board_ptr = board;
-
+       
        ret = a4l_mite_setup(devpriv->mite, 0);
        if (ret < 0) {
                printk(KERN_WARNING "[ANALOGY] [NI_670x]: error setting up 
mite\n");
                return ret;
        }
-
+       
        irq = mite_irq(devpriv->mite);
        devpriv->irq = irq;
-
+       
        a4l_info(dev, "ni670x attach: found %s board\n", board->name);
 
-   for (i = 0; i < 2; i++) 
-   {
-      a4l_subd_t *subd = a4l_alloc_subd(setup_subds[i].sizeof_priv, NULL);
-
-      if (subd == NULL)
-      {
+       for (i = 0; i < 2; i++) {
+               a4l_subd_t *subd = a4l_alloc_subd(setup_subds[i].sizeof_priv, 
NULL);
+               
+               if (subd == NULL) {
                   printk(KERN_WARNING "[ANALOGY] [NI_670x]: cannot allocate 
subdevice\n");
-         return -ENOMEM;
-      }
+                  return -ENOMEM;
+               }
 
-      err = a4l_add_subd(dev, subd);
-      if (err != i)
-      {
+               err = a4l_add_subd(dev, subd);
+               if (err != i) {
+                       printk(KERN_WARNING "[ANALOGY] [NI_670x]: cannot add 
subdevice\n");
+                       return err;
+               }
 
-                  printk(KERN_WARNING "[ANALOGY] [NI_670x]: cannot add 
subdevice\n");
-         return err;
-      }
-
-      setup_subds[i].setup_func (subd);
-   }
+               setup_subds[i].setup_func (subd);
+       }
 
        /* Config of misc registers */
        writel(0x10, devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET);
        /* Config of ao registers */
        writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET);
-
+       
        printk(KERN_INFO "[ANALOGY] [NI_670x]: ni670x attached\n");
 
        return 0;
@@ -372,111 +333,103 @@ static int ni_670x_attach (a4l_dev_t *dev,
 static int ni_670x_detach(a4l_dev_t *dev)
 {
        printk(KERN_INFO "[ANALOGY] [NI_670x]: try to remove the board ... ");
-
-   if(dev->priv != NULL && devpriv->mite != NULL)
-   {
-      a4l_mite_unsetup(devpriv->mite);
-   }
+       
+       if(dev->priv != NULL && devpriv->mite != NULL)
+               a4l_mite_unsetup(devpriv->mite);
 
        printk(KERN_INFO "[ANALOGY] [NI_670x]: Board removed!\n");
+       
        return 0;
 }
 
 
-static int ni_670x_dio_insn_config
-            (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn)
+static int ni_670x_dio_insn_config(a4l_subd_t *subd, a4l_kinsn_t *insn)
 {
-   a4l_dev_t *dev = subd->dev;
-   unsigned int *data = (unsigned int *)insn->data;
+       a4l_dev_t *dev = subd->dev;
+       unsigned int *data = (unsigned int *)insn->data;
        int chan = CR_CHAN(insn->chan_desc);
-   struct ni_670x_subd_priv *subdpriv =
-            (struct ni_670x_subd_priv *)subd->priv;
+       struct ni_670x_subd_priv *subdpriv =
+               (struct ni_670x_subd_priv *)subd->priv;
 
        switch (data[0]) {
        case A4L_INSN_CONFIG_DIO_OUTPUT:
-          subdpriv->io_bits |= 1 << chan;
+               subdpriv->io_bits |= 1 << chan;
                break;
        case A4L_INSN_CONFIG_DIO_INPUT:
                subdpriv->io_bits &= ~(1 << chan);
                break;
        case A4L_INSN_CONFIG_DIO_QUERY:
-               data[1] =
-                   (subdpriv->io_bits & (1 << chan)) ? A4L_OUTPUT : A4L_INPUT;
-               return 1;
+               data[1] = (subdpriv->io_bits & (1 << chan)) ? 
+                       A4L_OUTPUT : A4L_INPUT;
+               return 0;
                break;
        default:
                return -EINVAL;
                break;
        }
-       writel(subdpriv->io_bits, devpriv->mite->daq_io_addr + 
DIO_PORT0_DIR_OFFSET);
-   return 1;
-}
 
+       writel(subdpriv->io_bits, 
+              devpriv->mite->daq_io_addr + DIO_PORT0_DIR_OFFSET);
 
-static int ni_670x_ao_winsn
-                          (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn)
-{
-   int i;
-   unsigned int tmp;
-   unsigned int* dtmp;
-   int chan;
-   dtmp = (unsigned int*)insn->data;
-   chan = CR_CHAN(insn->chan_desc);
-
-   /* Channel number mapping :
-
-      NI 6703/ NI 6704     | NI 6704 Only
-      ----------------------------------------------------
-      vch(0)       :       0       | ich(16)       :       1
-      vch(1)       :       2       | ich(17)       :       3
-      .    :       .       |   .                   .
-      .    :       .       |   .                   .
-      .    :       .       |   .                   .
-      vch(15)      :       30      | ich(31)       :       31      */
-
-   for (i = 0; i < insn->data_size / 4; i++)
-   {
-      tmp = dtmp[i];
-      /* First write in channel register which channel to use */
-      writel(((chan & 15) << 1) | ((chan & 16) >> 4),
-               private (subd->dev)->mite->daq_io_addr + AO_CHAN_OFFSET);
-      /* write channel value */
-      writel(dtmp[i], private(subd->dev)->mite->daq_io_addr + AO_VALUE_OFFSET);
-      private(subd->dev)->ao_readback[chan] = tmp;
-   }
-   return i;
+       return 0;
 }
 
-static int ni_670x_ao_rinsn
-                          (a4l_subd_t *subd,
-                           a4l_kinsn_t *insn)
+static int ni_670x_ao_winsn(a4l_subd_t *subd, a4l_kinsn_t *insn)
 {
-   int i;
-   unsigned int* dtmp;
-   int chan = CR_CHAN(insn->chan_desc);
-
-   dtmp = (unsigned int*)insn->data;
-
-   for (i = 0; i < insn->data_size; i++)
-   {
-      dtmp[i] = private(subd->dev)->ao_readback[chan];
-   }
+       int i;
+       unsigned int tmp;
+       unsigned int* dtmp;
+       int chan;
+       dtmp = (unsigned int*)insn->data;
+       chan = CR_CHAN(insn->chan_desc);
+       
+       /* Channel number mapping :
+          
+          NI 6703/ NI 6704     | NI 6704 Only
+          ----------------------------------------------------
+          vch(0)       :       0       | ich(16)       :       1
+          vch(1)       :       2       | ich(17)       :       3
+          .    :       .       |   .                   .
+          .    :       .       |   .                   .
+          .    :       .       |   .                   .
+          vch(15)      :       30      | ich(31)       :       31      */
+       
+       for (i = 0; i < insn->data_size / sizeof(unsigned int); i++) {
+
+               tmp = dtmp[i];
+               
+               /* First write in channel register which channel to use */
+               writel(((chan & 15) << 1) | ((chan & 16) >> 4),
+                      private (subd->dev)->mite->daq_io_addr + AO_CHAN_OFFSET);
+
+               /* write channel value */
+               writel(dtmp[i], 
+                      private(subd->dev)->mite->daq_io_addr + AO_VALUE_OFFSET);
+               private(subd->dev)->ao_readback[chan] = tmp;
+       }
 
-   return i;
+   return 0;
 }
 
-
-static int ni_670x_dio_insn_bits
-                               (a4l_subd_t *subd,
-                                a4l_kinsn_t *insn)
+static int ni_670x_ao_rinsn(a4l_subd_t *subd, a4l_kinsn_t *insn)
 {
-   return 1;
+       int i;
+       unsigned int* dtmp;
+       int chan = CR_CHAN(insn->chan_desc);
+       
+       dtmp = (unsigned int*)insn->data;
+       
+       for (i = 0; i < insn->data_size / sizeof(unsigned int); i++)
+               dtmp[i] = private(subd->dev)->ao_readback[chan];
+       
+       return 0;
 }
 
 
-
+static int ni_670x_dio_insn_bits(a4l_subd_t *subd, a4l_kinsn_t *insn)
+{
+       return -ENOSYS;
+}
 
 MODULE_DESCRIPTION("Analogy driver for NI670x series cards");
 MODULE_LICENSE("GPL");


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to