Staging: remove me4000 driver.
[firewire-audio.git] / drivers / staging / meilhaus / me0900_do.c
bloba2275faf1a0c85818699c4252d66bf66244ce3b0
1 /**
2 * @file me0900_do.c
4 * @brief ME-9x digital output subdevice instance.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 */
9 /*
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.
27 #ifndef __KERNEL__
28 # define __KERNEL__
29 #endif
32 * Includes
34 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/spinlock.h>
38 #include <linux/io.h>
39 #include <linux/types.h>
41 #include "medefines.h"
42 #include "meinternal.h"
43 #include "meerror.h"
45 #include "medebug.h"
46 #include "me0900_reg.h"
47 #include "me0900_do.h"
50 * Defines
54 * Functions
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;
66 if (flags) {
67 PERROR("Invalid flag specified.\n");
68 return ME_ERRNO_INVALID_FLAGS;
71 ME_SUBDEVICE_ENTER;
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);
79 ME_SUBDEVICE_EXIT;
81 return ME_ERRNO_SUCCESS;
84 static int me0900_do_io_single_config(me_subdevice_t *subdevice,
85 struct file *filep,
86 int channel,
87 int single_config,
88 int ref,
89 int trig_chan,
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;
99 ME_SUBDEVICE_ENTER;
101 spin_lock(&instance->subdevice_lock);
102 switch (flags) {
103 case ME_IO_SINGLE_CONFIG_NO_FLAGS:
104 case ME_IO_SINGLE_TYPE_DIO_BYTE:
105 if (channel == 0) {
106 if (single_config == ME_SINGLE_CONFIG_DIO_OUTPUT) {
107 } else {
108 PERROR("Invalid byte direction specified.\n");
109 err = ME_ERRNO_INVALID_SINGLE_CONFIG;
111 } else {
112 PERROR("Invalid byte number specified.\n");
113 err = ME_ERRNO_INVALID_CHANNEL;
115 break;
117 default:
118 PERROR("Invalid flags specified.\n");
119 err = ME_ERRNO_INVALID_FLAGS;
121 spin_unlock(&instance->subdevice_lock);
123 ME_SUBDEVICE_EXIT;
125 return err;
128 static int me0900_do_io_single_read(me_subdevice_t *subdevice,
129 struct file *filep,
130 int channel,
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;
140 ME_SUBDEVICE_ENTER;
142 spin_lock(&instance->subdevice_lock);
143 switch (flags) {
144 case ME_IO_SINGLE_TYPE_DIO_BIT:
145 if ((channel >= 0) && (channel < 8)) {
146 *value = (~inb(instance->port_reg)) & (0x1 << channel);
147 } else {
148 PERROR("Invalid bit number specified.\n");
149 err = ME_ERRNO_INVALID_CHANNEL;
151 break;
153 case ME_IO_SINGLE_NO_FLAGS:
154 case ME_IO_SINGLE_TYPE_DIO_BYTE:
155 if (channel == 0) {
156 *value = ~inb(instance->port_reg);
157 } else {
158 PERROR("Invalid byte number specified.\n");
159 err = ME_ERRNO_INVALID_CHANNEL;
161 break;
163 default:
164 PERROR("Invalid flags specified.\n");
165 err = ME_ERRNO_INVALID_FLAGS;
167 spin_unlock(&instance->subdevice_lock);
169 ME_SUBDEVICE_EXIT;
171 return err;
174 static int me0900_do_io_single_write(me_subdevice_t *subdevice,
175 struct file *filep,
176 int channel,
177 int value, int time_out, int flags)
179 me0900_do_subdevice_t *instance;
180 int err = ME_ERRNO_SUCCESS;
181 unsigned long state;
183 PDEBUG("executed.\n");
185 instance = (me0900_do_subdevice_t *) subdevice;
187 ME_SUBDEVICE_ENTER;
189 spin_lock(&instance->subdevice_lock);
190 switch (flags) {
191 case ME_IO_SINGLE_TYPE_DIO_BIT:
192 if ((channel >= 0) && (channel < 8)) {
193 state = inb(instance->port_reg);
194 state =
195 (!value) ? (state | (0x1 << channel)) : (state &
196 ~(0x1 <<
197 channel));
198 outb(state, instance->port_reg);
199 } else {
200 PERROR("Invalid bit number specified.\n");
201 err = ME_ERRNO_INVALID_CHANNEL;
203 break;
205 case ME_IO_SINGLE_NO_FLAGS:
206 case ME_IO_SINGLE_TYPE_DIO_BYTE:
207 if (channel == 0) {
208 outb(~(value), instance->port_reg);
209 } else {
210 PERROR("Invalid byte number specified.\n");
211 err = ME_ERRNO_INVALID_CHANNEL;
213 break;
215 default:
216 PERROR("Invalid flags specified.\n");
217 err = ME_ERRNO_INVALID_FLAGS;
219 spin_unlock(&instance->subdevice_lock);
221 ME_SUBDEVICE_EXIT;
223 return err;
226 static int me0900_do_query_number_channels(me_subdevice_t *subdevice,
227 int *number)
229 PDEBUG("executed.\n");
230 *number = 8;
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");
238 *type = ME_TYPE_DO;
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");
246 *caps = 0;
247 return ME_ERRNO_SUCCESS;
250 me0900_do_subdevice_t *me0900_do_constructor(uint32_t reg_base,
251 unsigned int do_idx)
253 me0900_do_subdevice_t *subdevice;
254 int err;
256 PDEBUG("executed.\n");
258 /* Allocate memory for subdevice instance */
259 subdevice = kmalloc(sizeof(me0900_do_subdevice_t), GFP_KERNEL);
261 if (!subdevice) {
262 PERROR("Cannot get memory for subdevice instance.\n");
263 return NULL;
266 memset(subdevice, 0, sizeof(me0900_do_subdevice_t));
268 /* Initialize subdevice base class */
269 err = me_subdevice_init(&subdevice->base);
271 if (err) {
272 PERROR("Cannot initialize subdevice base class instance.\n");
273 kfree(subdevice);
274 return NULL;
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 */
283 if (do_idx == 0) {
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;
288 } else {
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;
296 #endif
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;
313 return subdevice;