Added some ack'ing of b interrupts, and do acks before handling
[comedi.git] / comedi / drivers / mpc8260cpm.c
1 /*
2     comedi/drivers/mpc8260.c
3     driver for digital I/O pins on the MPC 8260 CPM module
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 2000,2001 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 Driver: mpc8260cpm.o
25 Description: MPC8260 CPM module generic digital I/O lines
26 Devices: [Motorola] MPC8260 CPM (mpc8260cpm)
27 Author: ds
28 Status: experimental
29 Updated: Sat, 16 Mar 2002 17:34:48 -0800
30
31 This driver is specific to the Motorola MPC8260 processor, allowing
32 you to access the processor's generic digital I/O lines.
33
34 It is apparently missing some code.
35 */
36
37 #include <linux/comedidev.h>
38
39
40 extern unsigned long mpc8260_dio_reserved[4];
41
42 typedef struct{
43         int data;
44
45 }mpc8260cpm_private;
46 #define devpriv ((mpc8260cpm_private *)dev->private)
47
48 static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it);
49 static int mpc8260cpm_detach(comedi_device *dev);
50 static comedi_driver driver_mpc8260cpm={
51         driver_name:    "dummy",
52         module:         THIS_MODULE,
53         attach:         mpc8260cpm_attach,
54         detach:         mpc8260cpm_detach,
55 };
56 COMEDI_INITCLEANUP(driver_mpc8260cpm);
57
58 static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
59 static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);
60
61 static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it)
62 {
63         comedi_subdevice *s;
64         int i;
65
66         printk("comedi%d: mpc8260cpm: ",dev->minor);
67         
68         dev->board_ptr = mpc8260cpm_boards + dev->board;
69
70         dev->board_name = thisboard->name;
71
72         if(alloc_private(dev,sizeof(mpc8260cpm_private))<0)
73                 return -ENOMEM;
74
75         if(alloc_subdevices(dev,4)<0)
76                 return -ENOMEM;
77
78         for(i=0;i<4;i++){
79                 s=dev->subdevices+i;
80                 s->type=COMEDI_SUBD_DIO;
81                 s->subdev_flags=SDF_READABLE|SDF_WRITABLE;
82                 s->n_chan=32;
83                 s->maxdata=1;
84                 s->range_table=&range_digital;
85                 s->insn_config = mpc8260cpm_dio_config;
86                 s->insn_bits = mpc8260cpm_dio_bits;
87         }
88         
89         return 1;
90 }
91
92 static int mpc8260cpm_detach(comedi_device *dev)
93 {
94         printk("comedi%d: mpc8260cpm: remove\n",dev->minor);
95         
96         return 0;
97 }
98
99 static unsigned long *cpm_pdat(int port)
100 {
101         switch(port){
102         case 0:
103                 return &io->iop_pdata;
104         case 1:
105                 return &io->iop_pdatb;
106         case 2:
107                 return &io->iop_pdatc;
108         case 3:
109                 return &io->iop_pdatd;
110         }
111 }
112
113 static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
114 {
115         int n;
116         unsigned int d;
117         unsigned int mask;
118         int port;
119
120         port = (int)s->private;
121         mask = 1<<CR_CHAN(insn->chanspec);
122         if(mask&cpm_reserved_bits[port]){
123                 return -EINVAL;
124         }
125
126         switch(data[0]){
127         case INSN_CONFIG_DIO_OUTPUT:
128                 s->io_bits |= mask;
129                 break;
130         case INSN_CONFIG_DIO_INPUT:
131                 s->io_bits &= ~mask;
132                 break;
133         case INSN_CONFIG_DIO_QUERY:
134                 data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; 
135                 return insn->n;
136                 break;
137         default:
138                 return -EINVAL;
139         }
140
141         switch(port){
142         case 0: return &io->iop_pdira;
143         case 1: return &io->iop_pdirb;
144         case 2: return &io->iop_pdirc;
145         case 3: return &io->iop_pdird;
146         }
147
148
149         return 1;
150 }
151
152 static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
153 {
154         int port;
155         unsigned long *p;
156         
157         p = cpm_pdat((int)s->private);
158
159         
160
161
162         return 2;
163 }
164