added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / staging / meilhaus / me0600_ttli.c
blobab8e13b6f3291e18dbb48f79c6e7e1fdf01eeacd
1 /**
2 * @file me0600_ttli.c
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)
8 */
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.
28 #ifndef __KERNEL__
29 # define __KERNEL__
30 #endif
33 * Includes
35 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/spinlock.h>
39 #include <asm/io.h>
40 #include <linux/types.h>
42 #include "medefines.h"
43 #include "meinternal.h"
44 #include "meerror.h"
46 #include "medebug.h"
47 #include "me0600_ttli_reg.h"
48 #include "me0600_ttli.h"
51 * Defines
55 * Functions
58 static int me0600_ttli_io_reset_subdevice(struct me_subdevice *subdevice,
59 struct file *filep, int flags)
61 if (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,
71 struct file *filep,
72 int channel,
73 int single_config,
74 int ref,
75 int trig_chan,
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;
85 ME_SUBDEVICE_ENTER;
87 spin_lock(&instance->subdevice_lock);
89 switch (flags) {
90 case ME_IO_SINGLE_CONFIG_NO_FLAGS:
91 case ME_IO_SINGLE_CONFIG_DIO_BYTE:
92 if (channel == 0) {
93 if (single_config != ME_SINGLE_CONFIG_DIO_INPUT) {
94 PERROR("Invalid port direction specified.\n");
95 err = ME_ERRNO_INVALID_SINGLE_CONFIG;
97 } else {
98 PERROR("Invalid channel specified.\n");
99 err = ME_ERRNO_INVALID_CHANNEL;
102 break;
104 default:
105 PERROR("Invalid flags specified.\n");
107 err = ME_ERRNO_INVALID_FLAGS;
109 break;
112 spin_unlock(&instance->subdevice_lock);
114 ME_SUBDEVICE_EXIT;
116 return err;
119 static int me0600_ttli_io_single_read(me_subdevice_t * subdevice,
120 struct file *filep,
121 int channel,
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;
131 ME_SUBDEVICE_ENTER;
133 spin_lock(&instance->subdevice_lock);
135 switch (flags) {
136 case ME_IO_SINGLE_TYPE_DIO_BIT:
137 if ((channel >= 0) && (channel < 8)) {
138 *value = inb(instance->port_reg) & (0x1 << channel);
139 } else {
140 PERROR("Invalid bit number specified.\n");
141 err = ME_ERRNO_INVALID_CHANNEL;
143 break;
145 case ME_IO_SINGLE_NO_FLAGS:
146 case ME_IO_SINGLE_TYPE_DIO_BYTE:
147 if (channel == 0) {
148 *value = inb(instance->port_reg);
149 } else {
150 PERROR("Invalid byte number specified.\n");
151 err = ME_ERRNO_INVALID_CHANNEL;
153 break;
155 default:
156 PERROR("Invalid flags specified.\n");
157 err = ME_ERRNO_INVALID_FLAGS;
160 spin_unlock(&instance->subdevice_lock);
162 ME_SUBDEVICE_EXIT;
164 return err;
167 static int me0600_ttli_query_number_channels(me_subdevice_t * subdevice,
168 int *number)
170 PDEBUG("executed.\n");
171 *number = 8;
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");
179 *type = ME_TYPE_DI;
180 *subtype = ME_SUBTYPE_SINGLE;
181 return ME_ERRNO_SUCCESS;
184 static int me0600_ttli_query_subdevice_caps(me_subdevice_t * subdevice,
185 int *caps)
187 PDEBUG("executed.\n");
188 *caps = 0;
189 return ME_ERRNO_SUCCESS;
192 me0600_ttli_subdevice_t *me0600_ttli_constructor(uint32_t reg_base)
194 me0600_ttli_subdevice_t *subdevice;
195 int err;
197 PDEBUG("executed.\n");
199 /* Allocate memory for subdevice instance */
200 subdevice = kmalloc(sizeof(me0600_ttli_subdevice_t), GFP_KERNEL);
202 if (!subdevice) {
203 PERROR("Cannot get memory for subdevice instance.\n");
204 return NULL;
207 memset(subdevice, 0, sizeof(me0600_ttli_subdevice_t));
209 /* Initialize subdevice base class */
210 err = me_subdevice_init(&subdevice->base);
212 if (err) {
213 PERROR("Cannot initialize subdevice base class instance.\n");
214 kfree(subdevice);
215 return NULL;
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;
237 return subdevice;