Commit | Line | Data |
---|---|---|
3124dd1c DS |
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 | |
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 | ||
41 | typedef struct { | |
42 | int data; | |
43 | ||
44 | } mpc8260cpm_private; | |
45 | #define devpriv ((mpc8260cpm_private *)dev->private) | |
46 | ||
71b5f4f1 BP |
47 | static int mpc8260cpm_attach(struct comedi_device * dev, comedi_devconfig * it); |
48 | static int mpc8260cpm_detach(struct comedi_device * dev); | |
139dfbdf | 49 | static struct comedi_driver driver_mpc8260cpm = { |
3124dd1c DS |
50 | driver_name:"mpc8260cpm", |
51 | module:THIS_MODULE, | |
52 | attach:mpc8260cpm_attach, | |
53 | detach:mpc8260cpm_detach, | |
54 | }; | |
55 | ||
56 | COMEDI_INITCLEANUP(driver_mpc8260cpm); | |
57 | ||
34c43922 | 58 | static int mpc8260cpm_dio_config(struct comedi_device * dev, struct comedi_subdevice * s, |
790c5541 | 59 | comedi_insn * insn, unsigned int * data); |
34c43922 | 60 | static int mpc8260cpm_dio_bits(struct comedi_device * dev, struct comedi_subdevice * s, |
790c5541 | 61 | comedi_insn * insn, unsigned int * data); |
3124dd1c | 62 | |
71b5f4f1 | 63 | static int mpc8260cpm_attach(struct comedi_device * dev, comedi_devconfig * it) |
3124dd1c | 64 | { |
34c43922 | 65 | struct comedi_subdevice *s; |
3124dd1c DS |
66 | int i; |
67 | ||
68 | printk("comedi%d: mpc8260cpm: ", dev->minor); | |
69 | ||
70 | dev->board_ptr = mpc8260cpm_boards + dev->board; | |
71 | ||
72 | dev->board_name = thisboard->name; | |
73 | ||
74 | if (alloc_private(dev, sizeof(mpc8260cpm_private)) < 0) | |
75 | return -ENOMEM; | |
76 | ||
77 | if (alloc_subdevices(dev, 4) < 0) | |
78 | return -ENOMEM; | |
79 | ||
80 | for (i = 0; i < 4; i++) { | |
81 | s = dev->subdevices + i; | |
82 | s->type = COMEDI_SUBD_DIO; | |
83 | s->subdev_flags = SDF_READABLE | SDF_WRITABLE; | |
84 | s->n_chan = 32; | |
85 | s->maxdata = 1; | |
86 | s->range_table = &range_digital; | |
87 | s->insn_config = mpc8260cpm_dio_config; | |
88 | s->insn_bits = mpc8260cpm_dio_bits; | |
89 | } | |
90 | ||
91 | return 1; | |
92 | } | |
93 | ||
71b5f4f1 | 94 | static int mpc8260cpm_detach(struct comedi_device * dev) |
3124dd1c DS |
95 | { |
96 | printk("comedi%d: mpc8260cpm: remove\n", dev->minor); | |
97 | ||
98 | return 0; | |
99 | } | |
100 | ||
101 | static unsigned long *cpm_pdat(int port) | |
102 | { | |
103 | switch (port) { | |
104 | case 0: | |
105 | return &io->iop_pdata; | |
106 | case 1: | |
107 | return &io->iop_pdatb; | |
108 | case 2: | |
109 | return &io->iop_pdatc; | |
110 | case 3: | |
111 | return &io->iop_pdatd; | |
112 | } | |
113 | } | |
114 | ||
34c43922 | 115 | static int mpc8260cpm_dio_config(struct comedi_device * dev, struct comedi_subdevice * s, |
790c5541 | 116 | comedi_insn * insn, unsigned int * data) |
3124dd1c DS |
117 | { |
118 | int n; | |
119 | unsigned int d; | |
120 | unsigned int mask; | |
121 | int port; | |
122 | ||
123 | port = (int)s->private; | |
124 | mask = 1 << CR_CHAN(insn->chanspec); | |
125 | if (mask & cpm_reserved_bits[port]) { | |
126 | return -EINVAL; | |
127 | } | |
128 | ||
129 | switch (data[0]) { | |
130 | case INSN_CONFIG_DIO_OUTPUT: | |
131 | s->io_bits |= mask; | |
132 | break; | |
133 | case INSN_CONFIG_DIO_INPUT: | |
134 | s->io_bits &= ~mask; | |
135 | break; | |
136 | case INSN_CONFIG_DIO_QUERY: | |
137 | data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT; | |
138 | return insn->n; | |
139 | break; | |
140 | default: | |
141 | return -EINVAL; | |
142 | } | |
143 | ||
144 | switch (port) { | |
145 | case 0: | |
146 | return &io->iop_pdira; | |
147 | case 1: | |
148 | return &io->iop_pdirb; | |
149 | case 2: | |
150 | return &io->iop_pdirc; | |
151 | case 3: | |
152 | return &io->iop_pdird; | |
153 | } | |
154 | ||
155 | return 1; | |
156 | } | |
157 | ||
34c43922 | 158 | static int mpc8260cpm_dio_bits(struct comedi_device * dev, struct comedi_subdevice * s, |
790c5541 | 159 | comedi_insn * insn, unsigned int * data) |
3124dd1c DS |
160 | { |
161 | int port; | |
162 | unsigned long *p; | |
163 | ||
164 | p = cpm_pdat((int)s->private); | |
165 | ||
166 | return 2; | |
167 | } |