Module: xenomai-head
Branch: master
Commit: a1d4517df5ef0462ee4007334e1e72c1e6349ea3
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=a1d4517df5ef0462ee4007334e1e72c1e6349ea3

Author: Alexis Berlemont <alexis.berlem...@gmail.com>
Date:   Tue May 26 14:55:23 2009 +0200

Update 8255 driver

---

 ksrc/drivers/comedi/intel/8255.c |  242 ++++++++++++++++++--------------------
 ksrc/drivers/comedi/intel/8255.h |    5 +-
 2 files changed, 117 insertions(+), 130 deletions(-)

diff --git a/ksrc/drivers/comedi/intel/8255.c b/ksrc/drivers/comedi/intel/8255.c
index d3c4cd2..7357c9d 100644
--- a/ksrc/drivers/comedi/intel/8255.c
+++ b/ksrc/drivers/comedi/intel/8255.c
@@ -25,11 +25,8 @@
 
 #include "8255.h"
 
-#define SUBD_8255_MAX_COUNT    16
-#define CALLBACK_ARG           (subd_8255->cb_arg)
-#define CALLBACK_FUNC          (subd_8255->cb_func)
-
-static comedi_drv_t drv_8255;
+#define CALLBACK_ARG           (((subd_8255_t *)subd->priv)->cb_arg)
+#define CALLBACK_FUNC          (((subd_8255_t *)subd->priv)->cb_func)
 
 /* Channels descriptor */
 static comedi_chdesc_t chandesc_8255 = {
@@ -50,7 +47,7 @@ static comedi_cmd_t cmd_mask_8255 = {
   .stop_src = TRIG_NONE,
 };
 
-void subdev_8255_interrupt(comedi_dev_t *dev, subd_8255_t *subd_8255)
+void subdev_8255_interrupt(comedi_subd_t *subd)
 {
        sampl_t d;
 
@@ -63,9 +60,9 @@ void subdev_8255_interrupt(comedi_dev_t *dev, subd_8255_t 
*subd_8255)
        d |= (CALLBACK_FUNC(0, _8255_DATA + 1, 0, CALLBACK_ARG) << 8);
 
        /* ...and send it */
-       comedi_buf_put(dev, &d, sizeof(sampl_t));
+       comedi_buf_put(subd->dev, &d, sizeof(sampl_t));
 
-       comedi_buf_evt(dev, COMEDI_BUF_PUT, 0);
+       comedi_buf_evt(subd->dev, COMEDI_BUF_PUT, 0);
 }
 
 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
@@ -80,8 +77,66 @@ static int subdev_8255_cb(int dir, int port, int data, 
unsigned long arg)
        }
 }
 
-static int subdev_8255_insn_bits(subd_8255_t *subd_8255, comedi_kinsn_t *insn)
+static void do_config(comedi_subd_t *subd)
+{
+       int config;
+       subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv;
+
+       config = CR_CW;
+       /* 1 in io_bits indicates output, 1 in config indicates input */
+       if (!(subd_8255->io_bits & 0x0000ff))
+               config |= CR_A_IO;
+       if (!(subd_8255->io_bits & 0x00ff00))
+               config |= CR_B_IO;
+       if (!(subd_8255->io_bits & 0x0f0000))
+               config |= CR_C_LO_IO;
+       if (!(subd_8255->io_bits & 0xf00000))
+               config |= CR_C_HI_IO;
+       CALLBACK_FUNC(1, _8255_CR, config, CALLBACK_ARG);
+}
+
+int subd_8255_cmd(comedi_subd_t *subd, comedi_cmd_t *cmd)
+{
+       /* FIXME */  
+       return 0;
+}
+
+int subd_8255_cmdtest(comedi_subd_t *subd, comedi_cmd_t *cmd)
 {
+       if (cmd->start_arg != 0) {
+               cmd->start_arg = 0;
+               return -EINVAL;
+       }
+       if (cmd->scan_begin_arg != 0) {
+               cmd->scan_begin_arg = 0;
+               return -EINVAL;
+       }
+       if (cmd->convert_arg != 0) {
+               cmd->convert_arg = 0;
+               return -EINVAL;
+       }
+       if (cmd->scan_end_arg != 1) {
+               cmd->scan_end_arg = 1;
+               return -EINVAL;
+       }
+       if (cmd->stop_arg != 0) {
+               cmd->stop_arg = 0;
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+int subd_8255_cancel(comedi_subd_t *subd, int idx_subd)
+{      
+       /* FIXME */
+       return 0;
+}
+
+int subd_8255_insn_bits(comedi_subd_t *subd, comedi_kinsn_t *insn)
+{
+       subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv;
+
        if (insn->data[0]) {
 
                subd_8255->status &= ~insn->data[0];
@@ -107,27 +162,11 @@ static int subdev_8255_insn_bits(subd_8255_t *subd_8255, 
comedi_kinsn_t *insn)
        return 0;
 }
 
-static void do_config(subd_8255_t *subd_8255)
-{
-       int config;
-
-       config = CR_CW;
-       /* 1 in io_bits indicates output, 1 in config indicates input */
-       if (!(subd_8255->io_bits & 0x0000ff))
-               config |= CR_A_IO;
-       if (!(subd_8255->io_bits & 0x00ff00))
-               config |= CR_B_IO;
-       if (!(subd_8255->io_bits & 0x0f0000))
-               config |= CR_C_LO_IO;
-       if (!(subd_8255->io_bits & 0xf00000))
-               config |= CR_C_HI_IO;
-       CALLBACK_FUNC(1, _8255_CR, config, CALLBACK_ARG);
-}
-
-static int subdev_8255_insn_config(subd_8255_t *subd_8255, comedi_kinsn_t 
*insn)
+int subd_8255_insn_config(comedi_subd_t *subd, comedi_kinsn_t *insn)
 {
        unsigned int mask;
        unsigned int bits;
+       subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv;
 
        mask = 1 << CR_CHAN(insn->chan_desc);
 
@@ -157,68 +196,14 @@ static int subdev_8255_insn_config(subd_8255_t 
*subd_8255, comedi_kinsn_t *insn)
                return -EINVAL;
        }
 
-       do_config(subd_8255);
-
-       return 0;
-}
-
-int subd_8255_cmd(comedi_cxt_t *cxt, int idx_subd)
-{
-
-       /* FIXME */  
-       return 0;
-}
-
-int subd_8255_cmdtest(comedi_cxt_t *cxt, comedi_cmd_t *cmd)
-{
-       if (cmd->start_arg != 0) {
-               cmd->start_arg = 0;
-               return -EINVAL;
-       }
-       if (cmd->scan_begin_arg != 0) {
-               cmd->scan_begin_arg = 0;
-               return -EINVAL;
-       }
-       if (cmd->convert_arg != 0) {
-               cmd->convert_arg = 0;
-               return -EINVAL;
-       }
-       if (cmd->scan_end_arg != 1) {
-               cmd->scan_end_arg = 1;
-               return -EINVAL;
-       }
-       if (cmd->stop_arg != 0) {
-               cmd->stop_arg = 0;
-               return -EINVAL;
-       }
-
-       return 0;
-}
+       do_config(subd);
 
-int subd_8255_cancel(comedi_cxt_t *cxt, int idx_subd)
-{      
-       /* FIXME */
        return 0;
 }
 
-int subd_8255_insn_bits(comedi_cxt_t *cxt, comedi_kinsn_t *insn)
-{
-       comedi_dev_t *dev = comedi_get_dev(cxt);
-       subd_8255_t *subd_8255 = (subd_8255_t *)dev->priv;
-
-       return subdev_8255_insn_bits(subd_8255, insn);
-}
-
-int subd_8255_insn_config(comedi_cxt_t *cxt, comedi_kinsn_t *insn)
-{
-       comedi_dev_t *dev = comedi_get_dev(cxt);
-       subd_8255_t *subd_8255 = (subd_8255_t *)dev->priv;
-
-       return subdev_8255_insn_config(subd_8255, insn);        
-}
-
-void subdev_8255_init(comedi_subd_t *subd, subd_8255_t *subd_8255)
+void subdev_8255_init(comedi_subd_t *subd)
 {
+       subd_8255_t *subd_8255 = (subd_8255_t *)subd->priv;
        /* Initializes the subdevice structure */
        memset(&subd, 0, sizeof(comedi_subd_t));
 
@@ -242,7 +227,7 @@ void subdev_8255_init(comedi_subd_t *subd, subd_8255_t 
*subd_8255)
        if(CALLBACK_FUNC == NULL)
                CALLBACK_FUNC = subdev_8255_cb;
 
-       do_config(subd_8255);
+       do_config(subd);
 }
 
 /*
@@ -251,11 +236,10 @@ void subdev_8255_init(comedi_subd_t *subd, subd_8255_t 
*subd_8255)
 
  */
 
-int dev_8255_attach(comedi_cxt_t *cxt, comedi_lnkdesc_t *arg)
+int dev_8255_attach(comedi_dev_t *dev, comedi_lnkdesc_t *arg)
 {
        unsigned long *addrs;   
        int i, err = 0;
-       comedi_dev_t *dev = comedi_get_dev(cxt);        
 
        if(arg->opts == NULL || arg->opts_size == 0) {
                rtdm_printk("dev_8255_attach: unable to detect any 8255 chip, "
@@ -263,79 +247,83 @@ int dev_8255_attach(comedi_cxt_t *cxt, comedi_lnkdesc_t 
*arg)
                return -EINVAL;
        }
 
-       if((arg->opts_size / sizeof(unsigned long)) > SUBD_8255_MAX_COUNT) {
-               rtdm_printk("dev_8255_attach: too many 8255 chips to handle "
-                          "(max = %d)\n", SUBD_8255_MAX_COUNT);
-               return -EINVAL;
-       }
-       
-       memset(dev->priv, 0, sizeof(subd_8255_t) * SUBD_8255_MAX_COUNT);
-
        addrs = (unsigned long*) arg->opts;
 
        for(i = 0; i < (arg->opts_size / sizeof(unsigned long)); i++) {
-               comedi_subd_t subd;
-               subd_8255_t *subd_8255 = &(((subd_8255_t *)dev->priv)[i]);
+               comedi_subd_t * subd;
+               subd_8255_t *subd_8255;
+
+               subd = comedi_alloc_subd(sizeof(subd_8255_t), NULL);
+               if(subd == NULL) {
+                       comedi_err(dev, 
+                                  "dev_8255_attach: "
+                                  "unable to allocate subdevice\n");
+                       /* There is no need to free previously
+                          allocated structure(s), the comedi layer will do
+                          it for us */
+                       err = -ENOMEM;
+                       goto out_attach;
+               }               
 
                memset(&subd, 0, sizeof(comedi_subd_t));
+               memset(subd->priv, 0, sizeof(subd_8255_t));
+
+               subd_8255 = (subd_8255_t *)subd->priv;          
                
                if(request_region(addrs[i], _8255_SIZE, "Comedi 8255") == 0) {  
       
-                       subd.flags = COMEDI_SUBD_UNUSED;
-                       rtdm_printk("dev_8255_attach: I/O port conflict at 
0x%lx\n",
-                                   addrs[i]);
+                       subd->flags = COMEDI_SUBD_UNUSED;
+                       comedi_warn(dev, 
+                                   "dev_8255_attach: "
+                                   "I/O port conflict at 0x%lx\n", addrs[i]);
                }
                else {
-                       memset(subd_8255, 0, sizeof(subd_8255_t));
                        subd_8255->cb_arg = addrs[i];
-                       subdev_8255_init(&subd, subd_8255);
+                       subdev_8255_init(subd);
                }
 
-               err = comedi_add_subd(&drv_8255, &subd);
-               if(err < 0)
+               err = comedi_add_subd(dev, subd);
+               if(err < 0) {
+                       comedi_err(dev, 
+                                  "dev_8255_attach: "
+                                  "comedi_add_subd() failed (err=%d)\n", err);
                        goto out_attach;
+               }
        }
 
 out_attach:
        return err;
 }
 
-int dev_8255_detach(comedi_cxt_t *cxt)
+int dev_8255_detach(comedi_dev_t *dev)
 {
-       comedi_dev_t *dev = comedi_get_dev(cxt);
-       int i;
-
-       for(i = 0; i < SUBD_8255_MAX_COUNT; i++) {
-               subd_8255_t *subd_8255 = &(((subd_8255_t *)dev->priv)[i]);
+       comedi_subd_t *subd;
+       int i = 0;
 
-               if(subd_8255->cb_arg != 0)
+       while((subd = comedi_get_subd(dev, i++)) != NULL) {
+               subd_8255_t *subd_8255 = (subd_8255_t *) subd->priv;
+               if(subd_8255 != NULL && subd_8255->cb_arg != 0)
                        release_region(subd_8255->cb_arg, _8255_SIZE);
        }
 
        return 0;
 }
 
+static comedi_drv_t drv_8255 = {
+       .owner = THIS_MODULE,
+       .board_name = "8255",
+       .attach = dev_8255_attach,
+       .detach = dev_8255_detach,      
+       .privdata_size = 0,
+};
+
 static int __init drv_8255_init(void)
 {
-       int err;
-
-       err = comedi_init_drv(&drv_8255);
-       if(err < 0)
-               return err;
-
-       drv_8255.owner = THIS_MODULE;
-       drv_8255.board_name = "comedi_8255";
-       drv_8255.flags = COMEDI_DYNAMIC_DRV;
-       drv_8255.attach = dev_8255_attach;
-       drv_8255.detach = dev_8255_detach;
-       drv_8255.privdata_size = sizeof(subd_8255_t) * SUBD_8255_MAX_COUNT;
-
-       return comedi_add_drv(&drv_8255);
+       return comedi_register_drv(&drv_8255);
 }
 
 static void __exit drv_8255_cleanup(void)
 {
-       comedi_rm_drv(&drv_8255);
-       comedi_cleanup_drv(&drv_8255);
+       comedi_unregister_drv(&drv_8255);
 }
 
 module_init(drv_8255_init);
diff --git a/ksrc/drivers/comedi/intel/8255.h b/ksrc/drivers/comedi/intel/8255.h
index 10109c1..70b9dca 100644
--- a/ksrc/drivers/comedi/intel/8255.h
+++ b/ksrc/drivers/comedi/intel/8255.h
@@ -48,9 +48,8 @@ typedef struct subd_8255_struct {
 #define CR_A_MODE(a)   ((a)<<5)
 #define CR_CW          0x80
 
-
-void subdev_8255_init(comedi_subd_t *subd, subd_8255_t *subd_8255);
-void subdev_8255_interrupt(comedi_dev_t *dev, subd_8255_t *subd_8255);
+void subdev_8255_init(comedi_subd_t *subd);
+void subdev_8255_interrupt(comedi_subd_t *subd);
 
 #else /* !CONFIG_XENO_DRIVERS_COMEDI_8255 */
 


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

Reply via email to