Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mpc8260cpm.c
Go to the documentation of this file.
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 <[email protected]>
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
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 "../comedidev.h"
38 
39 extern unsigned long mpc8260_dio_reserved[4];
40 
42 
43  int data;
44 
45 };
46 
47 #define devpriv ((struct mpc8260cpm_private *)dev->private)
48 
49 static unsigned long *cpm_pdat(int port)
50 {
51  switch (port) {
52  case 0:
53  return &io->iop_pdata;
54  case 1:
55  return &io->iop_pdatb;
56  case 2:
57  return &io->iop_pdatc;
58  case 3:
59  return &io->iop_pdatd;
60  }
61 }
62 
63 static int mpc8260cpm_dio_config(struct comedi_device *dev,
64  struct comedi_subdevice *s,
65  struct comedi_insn *insn, unsigned int *data)
66 {
67  int n;
68  unsigned int d;
69  unsigned int mask;
70  int port;
71 
72  port = (int)s->private;
73  mask = 1 << CR_CHAN(insn->chanspec);
74  if (mask & cpm_reserved_bits[port]) {
75  return -EINVAL;
76  }
77 
78  switch (data[0]) {
80  s->io_bits |= mask;
81  break;
83  s->io_bits &= ~mask;
84  break;
86  data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
87  return insn->n;
88  break;
89  default:
90  return -EINVAL;
91  }
92 
93  switch (port) {
94  case 0:
95  return &io->iop_pdira;
96  case 1:
97  return &io->iop_pdirb;
98  case 2:
99  return &io->iop_pdirc;
100  case 3:
101  return &io->iop_pdird;
102  }
103 
104  return 1;
105 }
106 
107 static int mpc8260cpm_dio_bits(struct comedi_device *dev,
108  struct comedi_subdevice *s,
109  struct comedi_insn *insn, unsigned int *data)
110 {
111  int port;
112  unsigned long *p;
113 
114  p = cpm_pdat((int)s->private);
115 
116  return insn->n;
117 }
118 
119 static int mpc8260cpm_attach(struct comedi_device *dev,
120  struct comedi_devconfig *it)
121 {
122  struct comedi_subdevice *s;
123  int i;
124  int ret;
125 
126  printk("comedi%d: mpc8260cpm: ", dev->minor);
127 
128  dev->board_ptr = mpc8260cpm_boards + dev->board;
129 
130  dev->board_name = thisboard->name;
131 
132  if (alloc_private(dev, sizeof(struct mpc8260cpm_private)) < 0)
133  return -ENOMEM;
134 
135  ret =comedi_alloc_subdevices(dev, 4);
136  if (ret)
137  return ret;
138 
139  for (i = 0; i < 4; i++) {
140  s = &dev->subdevices[i];
141  s->type = COMEDI_SUBD_DIO;
143  s->n_chan = 32;
144  s->maxdata = 1;
146  s->insn_config = mpc8260cpm_dio_config;
147  s->insn_bits = mpc8260cpm_dio_bits;
148  }
149 
150  return 1;
151 }
152 
153 static void mpc8260cpm_detach(struct comedi_device *dev)
154 {
155  /* Nothing to cleanup */
156 }
157 
158 static struct comedi_driver mpc8260cpm_driver = {
159  .driver_name = "mpc8260cpm",
160  .module = THIS_MODULE,
161  .attach = mpc8260cpm_attach,
162  .detach = mpc8260cpm_detach,
163 };
164 module_comedi_driver(mpc8260cpm_driver);