4 * @brief ME-9x digital output subdevice instance.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
10 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/spinlock.h>
39 #include <linux/types.h>
41 #include "medefines.h"
42 #include "meinternal.h"
46 #include "me0900_reg.h"
47 #include "me0900_do.h"
57 static int me0900_do_io_reset_subdevice(struct me_subdevice
*subdevice
,
58 struct file
*filep
, int flags
)
60 me0900_do_subdevice_t
*instance
;
62 PDEBUG("executed.\n");
64 instance
= (me0900_do_subdevice_t
*) subdevice
;
67 PERROR("Invalid flag specified.\n");
68 return ME_ERRNO_INVALID_FLAGS
;
73 spin_lock(&instance
->subdevice_lock
);
74 outb(0xFF, instance
->port_reg
);
75 PDEBUG_REG("port_reg outl(0x%lX+0x%lX)=0x%x\n", instance
->reg_base
,
76 instance
->port_reg
- instance
->reg_base
, 0xff);
77 spin_unlock(&instance
->subdevice_lock
);
81 return ME_ERRNO_SUCCESS
;
84 static int me0900_do_io_single_config(me_subdevice_t
*subdevice
,
90 int trig_type
, int trig_edge
, int flags
)
92 me0900_do_subdevice_t
*instance
;
93 int err
= ME_ERRNO_SUCCESS
;
95 PDEBUG("executed.\n");
97 instance
= (me0900_do_subdevice_t
*) subdevice
;
101 spin_lock(&instance
->subdevice_lock
);
103 case ME_IO_SINGLE_CONFIG_NO_FLAGS
:
104 case ME_IO_SINGLE_TYPE_DIO_BYTE
:
106 if (single_config
== ME_SINGLE_CONFIG_DIO_OUTPUT
) {
108 PERROR("Invalid byte direction specified.\n");
109 err
= ME_ERRNO_INVALID_SINGLE_CONFIG
;
112 PERROR("Invalid byte number specified.\n");
113 err
= ME_ERRNO_INVALID_CHANNEL
;
118 PERROR("Invalid flags specified.\n");
119 err
= ME_ERRNO_INVALID_FLAGS
;
121 spin_unlock(&instance
->subdevice_lock
);
128 static int me0900_do_io_single_read(me_subdevice_t
*subdevice
,
131 int *value
, int time_out
, int flags
)
133 me0900_do_subdevice_t
*instance
;
134 int err
= ME_ERRNO_SUCCESS
;
136 PDEBUG("executed.\n");
138 instance
= (me0900_do_subdevice_t
*) subdevice
;
142 spin_lock(&instance
->subdevice_lock
);
144 case ME_IO_SINGLE_TYPE_DIO_BIT
:
145 if ((channel
>= 0) && (channel
< 8)) {
146 *value
= (~inb(instance
->port_reg
)) & (0x1 << channel
);
148 PERROR("Invalid bit number specified.\n");
149 err
= ME_ERRNO_INVALID_CHANNEL
;
153 case ME_IO_SINGLE_NO_FLAGS
:
154 case ME_IO_SINGLE_TYPE_DIO_BYTE
:
156 *value
= ~inb(instance
->port_reg
);
158 PERROR("Invalid byte number specified.\n");
159 err
= ME_ERRNO_INVALID_CHANNEL
;
164 PERROR("Invalid flags specified.\n");
165 err
= ME_ERRNO_INVALID_FLAGS
;
167 spin_unlock(&instance
->subdevice_lock
);
174 static int me0900_do_io_single_write(me_subdevice_t
*subdevice
,
177 int value
, int time_out
, int flags
)
179 me0900_do_subdevice_t
*instance
;
180 int err
= ME_ERRNO_SUCCESS
;
183 PDEBUG("executed.\n");
185 instance
= (me0900_do_subdevice_t
*) subdevice
;
189 spin_lock(&instance
->subdevice_lock
);
191 case ME_IO_SINGLE_TYPE_DIO_BIT
:
192 if ((channel
>= 0) && (channel
< 8)) {
193 state
= inb(instance
->port_reg
);
195 (!value
) ? (state
| (0x1 << channel
)) : (state
&
198 outb(state
, instance
->port_reg
);
200 PERROR("Invalid bit number specified.\n");
201 err
= ME_ERRNO_INVALID_CHANNEL
;
205 case ME_IO_SINGLE_NO_FLAGS
:
206 case ME_IO_SINGLE_TYPE_DIO_BYTE
:
208 outb(~(value
), instance
->port_reg
);
210 PERROR("Invalid byte number specified.\n");
211 err
= ME_ERRNO_INVALID_CHANNEL
;
216 PERROR("Invalid flags specified.\n");
217 err
= ME_ERRNO_INVALID_FLAGS
;
219 spin_unlock(&instance
->subdevice_lock
);
226 static int me0900_do_query_number_channels(me_subdevice_t
*subdevice
,
229 PDEBUG("executed.\n");
231 return ME_ERRNO_SUCCESS
;
234 static int me0900_do_query_subdevice_type(me_subdevice_t
*subdevice
,
235 int *type
, int *subtype
)
237 PDEBUG("executed.\n");
239 *subtype
= ME_SUBTYPE_SINGLE
;
240 return ME_ERRNO_SUCCESS
;
243 static int me0900_do_query_subdevice_caps(me_subdevice_t
*subdevice
, int *caps
)
245 PDEBUG("executed.\n");
247 return ME_ERRNO_SUCCESS
;
250 me0900_do_subdevice_t
*me0900_do_constructor(uint32_t reg_base
,
253 me0900_do_subdevice_t
*subdevice
;
256 PDEBUG("executed.\n");
258 /* Allocate memory for subdevice instance */
259 subdevice
= kmalloc(sizeof(me0900_do_subdevice_t
), GFP_KERNEL
);
262 PERROR("Cannot get memory for subdevice instance.\n");
266 memset(subdevice
, 0, sizeof(me0900_do_subdevice_t
));
268 /* Initialize subdevice base class */
269 err
= me_subdevice_init(&subdevice
->base
);
272 PERROR("Cannot initialize subdevice base class instance.\n");
276 // Initialize spin locks.
277 spin_lock_init(&subdevice
->subdevice_lock
);
279 /* Save the subdevice index */
280 subdevice
->do_idx
= do_idx
;
282 /* Initialize registers */
284 subdevice
->ctrl_reg
= reg_base
+ ME0900_CTRL_REG
;
285 subdevice
->port_reg
= reg_base
+ ME0900_PORT_A_REG
;
286 subdevice
->enable_reg
= reg_base
+ ME0900_WRITE_ENABLE_REG
;
287 subdevice
->disable_reg
= reg_base
+ ME0900_WRITE_DISABLE_REG
;
289 subdevice
->ctrl_reg
= reg_base
+ ME0900_CTRL_REG
;
290 subdevice
->port_reg
= reg_base
+ ME0900_PORT_B_REG
;
291 subdevice
->enable_reg
= reg_base
+ ME0900_WRITE_ENABLE_REG
;
292 subdevice
->disable_reg
= reg_base
+ ME0900_WRITE_DISABLE_REG
;
294 #ifdef MEDEBUG_DEBUG_REG
295 subdevice
->reg_base
= reg_base
;
298 /* Overload base class methods. */
299 subdevice
->base
.me_subdevice_io_reset_subdevice
=
300 me0900_do_io_reset_subdevice
;
301 subdevice
->base
.me_subdevice_io_single_config
=
302 me0900_do_io_single_config
;
303 subdevice
->base
.me_subdevice_io_single_read
= me0900_do_io_single_read
;
304 subdevice
->base
.me_subdevice_io_single_write
=
305 me0900_do_io_single_write
;
306 subdevice
->base
.me_subdevice_query_number_channels
=
307 me0900_do_query_number_channels
;
308 subdevice
->base
.me_subdevice_query_subdevice_type
=
309 me0900_do_query_subdevice_type
;
310 subdevice
->base
.me_subdevice_query_subdevice_caps
=
311 me0900_do_query_subdevice_caps
;