summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/drivers/mpc8260cpm.c
blob: a7fda8f01e8ce113f6dda5d63c098e5576d24eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
    comedi/drivers/mpc8260.c
    driver for digital I/O pins on the MPC 8260 CPM module

    COMEDI - Linux Control and Measurement Device Interface
    Copyright (C) 2000,2001 David A. Schleef <ds@schleef.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
/*
Driver: mpc8260cpm
Description: MPC8260 CPM module generic digital I/O lines
Devices: [Motorola] MPC8260 CPM (mpc8260cpm)
Author: ds
Status: experimental
Updated: Sat, 16 Mar 2002 17:34:48 -0800

This driver is specific to the Motorola MPC8260 processor, allowing
you to access the processor's generic digital I/O lines.

It is apparently missing some code.
*/

#include "../comedidev.h"

extern unsigned long mpc8260_dio_reserved[4];

struct mpc8260cpm_private {

	int data;

};

#define devpriv ((struct mpc8260cpm_private *)dev->private)

static unsigned long *cpm_pdat(int port)
{
	switch (port) {
	case 0:
		return &io->iop_pdata;
	case 1:
		return &io->iop_pdatb;
	case 2:
		return &io->iop_pdatc;
	case 3:
		return &io->iop_pdatd;
	}
}

static int mpc8260cpm_dio_config(struct comedi_device *dev,
				 struct comedi_subdevice *s,
				 struct comedi_insn *insn, unsigned int *data)
{
	int n;
	unsigned int d;
	unsigned int mask;
	int port;

	port = (int)s->private;
	mask = 1 << CR_CHAN(insn->chanspec);
	if (mask & cpm_reserved_bits[port]) {
		return -EINVAL;
	}

	switch (data[0]) {
	case INSN_CONFIG_DIO_OUTPUT:
		s->io_bits |= mask;
		break;
	case INSN_CONFIG_DIO_INPUT:
		s->io_bits &= ~mask;
		break;
	case INSN_CONFIG_DIO_QUERY:
		data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
		return insn->n;
		break;
	default:
		return -EINVAL;
	}

	switch (port) {
	case 0:
		return &io->iop_pdira;
	case 1:
		return &io->iop_pdirb;
	case 2:
		return &io->iop_pdirc;
	case 3:
		return &io->iop_pdird;
	}

	return 1;
}

static int mpc8260cpm_dio_bits(struct comedi_device *dev,
			       struct comedi_subdevice *s,
			       struct comedi_insn *insn, unsigned int *data)
{
	int port;
	unsigned long *p;

	p = cpm_pdat((int)s->private);

	return insn->n;
}

static int mpc8260cpm_attach(struct comedi_device *dev,
			     struct comedi_devconfig *it)
{
	struct comedi_subdevice *s;
	int i;
	int ret;

	printk("comedi%d: mpc8260cpm: ", dev->minor);

	dev->board_ptr = mpc8260cpm_boards + dev->board;

	dev->board_name = thisboard->name;

	if (alloc_private(dev, sizeof(struct mpc8260cpm_private)) < 0)
		return -ENOMEM;

	ret =comedi_alloc_subdevices(dev, 4);
	if (ret)
		return ret;

	for (i = 0; i < 4; i++) {
		s = dev->subdevices + i;
		s->type = COMEDI_SUBD_DIO;
		s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
		s->n_chan = 32;
		s->maxdata = 1;
		s->range_table = &range_digital;
		s->insn_config = mpc8260cpm_dio_config;
		s->insn_bits = mpc8260cpm_dio_bits;
	}

	return 1;
}

static void mpc8260cpm_detach(struct comedi_device *dev)
{
	/* Nothing to cleanup */
}

static struct comedi_driver mpc8260cpm_driver = {
	.driver_name	= "mpc8260cpm",
	.module		= THIS_MODULE,
	.attach		= mpc8260cpm_attach,
	.detach		= mpc8260cpm_detach,
};
module_comedi_driver(mpc8260cpm_driver);