4 * @brief ME-630 TTL input subdevice instance.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
13 * This file is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/spinlock.h>
40 #include <linux/types.h>
42 #include "medefines.h"
43 #include "meinternal.h"
47 #include "me0600_ttli_reg.h"
48 #include "me0600_ttli.h"
58 static int me0600_ttli_io_reset_subdevice(struct me_subdevice
*subdevice
,
59 struct file
*filep
, int flags
)
62 PERROR("Invalid flag specified.\n");
63 return ME_ERRNO_INVALID_FLAGS
;
66 PDEBUG("executed.\n");
67 return ME_ERRNO_SUCCESS
;
70 static int me0600_ttli_io_single_config(me_subdevice_t
* subdevice
,
76 int trig_type
, int trig_edge
, int flags
)
78 me0600_ttli_subdevice_t
*instance
;
79 int err
= ME_ERRNO_SUCCESS
;
81 PDEBUG("executed.\n");
83 instance
= (me0600_ttli_subdevice_t
*) subdevice
;
87 spin_lock(&instance
->subdevice_lock
);
90 case ME_IO_SINGLE_CONFIG_NO_FLAGS
:
91 case ME_IO_SINGLE_CONFIG_DIO_BYTE
:
93 if (single_config
!= ME_SINGLE_CONFIG_DIO_INPUT
) {
94 PERROR("Invalid port direction specified.\n");
95 err
= ME_ERRNO_INVALID_SINGLE_CONFIG
;
98 PERROR("Invalid channel specified.\n");
99 err
= ME_ERRNO_INVALID_CHANNEL
;
105 PERROR("Invalid flags specified.\n");
107 err
= ME_ERRNO_INVALID_FLAGS
;
112 spin_unlock(&instance
->subdevice_lock
);
119 static int me0600_ttli_io_single_read(me_subdevice_t
* subdevice
,
122 int *value
, int time_out
, int flags
)
124 me0600_ttli_subdevice_t
*instance
;
125 int err
= ME_ERRNO_SUCCESS
;
127 PDEBUG("executed.\n");
129 instance
= (me0600_ttli_subdevice_t
*) subdevice
;
133 spin_lock(&instance
->subdevice_lock
);
136 case ME_IO_SINGLE_TYPE_DIO_BIT
:
137 if ((channel
>= 0) && (channel
< 8)) {
138 *value
= inb(instance
->port_reg
) & (0x1 << channel
);
140 PERROR("Invalid bit number specified.\n");
141 err
= ME_ERRNO_INVALID_CHANNEL
;
145 case ME_IO_SINGLE_NO_FLAGS
:
146 case ME_IO_SINGLE_TYPE_DIO_BYTE
:
148 *value
= inb(instance
->port_reg
);
150 PERROR("Invalid byte number specified.\n");
151 err
= ME_ERRNO_INVALID_CHANNEL
;
156 PERROR("Invalid flags specified.\n");
157 err
= ME_ERRNO_INVALID_FLAGS
;
160 spin_unlock(&instance
->subdevice_lock
);
167 static int me0600_ttli_query_number_channels(me_subdevice_t
* subdevice
,
170 PDEBUG("executed.\n");
172 return ME_ERRNO_SUCCESS
;
175 static int me0600_ttli_query_subdevice_type(me_subdevice_t
* subdevice
,
176 int *type
, int *subtype
)
178 PDEBUG("executed.\n");
180 *subtype
= ME_SUBTYPE_SINGLE
;
181 return ME_ERRNO_SUCCESS
;
184 static int me0600_ttli_query_subdevice_caps(me_subdevice_t
* subdevice
,
187 PDEBUG("executed.\n");
189 return ME_ERRNO_SUCCESS
;
192 me0600_ttli_subdevice_t
*me0600_ttli_constructor(uint32_t reg_base
)
194 me0600_ttli_subdevice_t
*subdevice
;
197 PDEBUG("executed.\n");
199 /* Allocate memory for subdevice instance */
200 subdevice
= kmalloc(sizeof(me0600_ttli_subdevice_t
), GFP_KERNEL
);
203 PERROR("Cannot get memory for subdevice instance.\n");
207 memset(subdevice
, 0, sizeof(me0600_ttli_subdevice_t
));
209 /* Initialize subdevice base class */
210 err
= me_subdevice_init(&subdevice
->base
);
213 PERROR("Cannot initialize subdevice base class instance.\n");
217 // Initialize spin locks.
218 spin_lock_init(&subdevice
->subdevice_lock
);
220 /* Save the subdevice index */
221 subdevice
->port_reg
= reg_base
+ ME0600_TTL_INPUT_REG
;
223 /* Overload base class methods. */
224 subdevice
->base
.me_subdevice_io_reset_subdevice
=
225 me0600_ttli_io_reset_subdevice
;
226 subdevice
->base
.me_subdevice_io_single_config
=
227 me0600_ttli_io_single_config
;
228 subdevice
->base
.me_subdevice_io_single_read
=
229 me0600_ttli_io_single_read
;
230 subdevice
->base
.me_subdevice_query_number_channels
=
231 me0600_ttli_query_number_channels
;
232 subdevice
->base
.me_subdevice_query_subdevice_type
=
233 me0600_ttli_query_subdevice_type
;
234 subdevice
->base
.me_subdevice_query_subdevice_caps
=
235 me0600_ttli_query_subdevice_caps
;