Staging: remove me4000 driver.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / meilhaus / me0600_optoi.c
blob43f710ffd27840a75f88a4867688f7c14f1b1f29
1 /**
2 * @file me0600_optoi.c
4 * @brief ME-630 Optoisolated 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 <linux/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_optoi_reg.h"
48 #include "me0600_optoi.h"
51 * Defines
55 * Functions
58 static int me0600_optoi_io_reset_subdevice(struct me_subdevice *subdevice,
59 struct file *filep, int flags)
62 if (flags) {
63 PERROR("Invalid flag specified.\n");
64 return ME_ERRNO_INVALID_FLAGS;
67 PDEBUG("executed.\n");
68 return ME_ERRNO_SUCCESS;
71 static int me0600_optoi_io_single_config(me_subdevice_t *subdevice,
72 struct file *filep,
73 int channel,
74 int single_config,
75 int ref,
76 int trig_chan,
77 int trig_type,
78 int trig_edge, int flags)
80 me0600_optoi_subdevice_t *instance;
81 int err = ME_ERRNO_SUCCESS;
83 PDEBUG("executed.\n");
85 instance = (me0600_optoi_subdevice_t *) subdevice;
87 ME_SUBDEVICE_ENTER;
89 spin_lock(&instance->subdevice_lock);
91 switch (flags) {
92 case ME_IO_SINGLE_CONFIG_NO_FLAGS:
93 case ME_IO_SINGLE_CONFIG_DIO_BYTE:
94 if (channel == 0) {
95 if (single_config != ME_SINGLE_CONFIG_DIO_INPUT) {
96 PERROR("Invalid port direction specified.\n");
97 err = ME_ERRNO_INVALID_SINGLE_CONFIG;
99 } else {
100 PERROR("Invalid channel specified.\n");
101 err = ME_ERRNO_INVALID_CHANNEL;
104 break;
106 default:
107 PERROR("Invalid flags specified.\n");
109 err = ME_ERRNO_INVALID_FLAGS;
111 break;
114 spin_unlock(&instance->subdevice_lock);
116 ME_SUBDEVICE_EXIT;
118 return err;
121 static int me0600_optoi_io_single_read(me_subdevice_t *subdevice,
122 struct file *filep,
123 int channel,
124 int *value, int time_out, int flags)
126 me0600_optoi_subdevice_t *instance;
127 int err = ME_ERRNO_SUCCESS;
129 PDEBUG("executed.\n");
131 instance = (me0600_optoi_subdevice_t *) subdevice;
133 ME_SUBDEVICE_ENTER;
135 spin_lock(&instance->subdevice_lock);
137 switch (flags) {
138 case ME_IO_SINGLE_TYPE_DIO_BIT:
139 if ((channel >= 0) && (channel < 8)) {
140 *value = inb(instance->port_reg) & (0x1 << channel);
141 } else {
142 PERROR("Invalid bit number specified.\n");
143 err = ME_ERRNO_INVALID_CHANNEL;
146 break;
148 case ME_IO_SINGLE_NO_FLAGS:
149 case ME_IO_SINGLE_TYPE_DIO_BYTE:
150 if (channel == 0) {
151 *value = inb(instance->port_reg);
152 } else {
153 PERROR("Invalid byte number specified.\n");
154 err = ME_ERRNO_INVALID_CHANNEL;
157 break;
159 default:
160 PERROR("Invalid flags specified.\n");
162 err = ME_ERRNO_INVALID_FLAGS;
165 spin_unlock(&instance->subdevice_lock);
167 ME_SUBDEVICE_EXIT;
169 return err;
172 static int me0600_optoi_query_number_channels(me_subdevice_t *subdevice,
173 int *number)
175 PDEBUG("executed.\n");
176 *number = 8;
177 return ME_ERRNO_SUCCESS;
180 static int me0600_optoi_query_subdevice_type(me_subdevice_t *subdevice,
181 int *type, int *subtype)
183 PDEBUG("executed.\n");
184 *type = ME_TYPE_DI;
185 *subtype = ME_SUBTYPE_SINGLE;
186 return ME_ERRNO_SUCCESS;
189 static int me0600_optoi_query_subdevice_caps(me_subdevice_t *subdevice,
190 int *caps)
192 PDEBUG("executed.\n");
193 *caps = 0;
194 return ME_ERRNO_SUCCESS;
197 me0600_optoi_subdevice_t *me0600_optoi_constructor(uint32_t reg_base)
199 me0600_optoi_subdevice_t *subdevice;
200 int err;
202 PDEBUG("executed.\n");
204 /* Allocate memory for subdevice instance */
205 subdevice = kmalloc(sizeof(me0600_optoi_subdevice_t), GFP_KERNEL);
207 if (!subdevice) {
208 PERROR("Cannot get memory for subdevice instance.\n");
209 return NULL;
212 memset(subdevice, 0, sizeof(me0600_optoi_subdevice_t));
214 /* Initialize subdevice base class */
215 err = me_subdevice_init(&subdevice->base);
217 if (err) {
218 PERROR("Cannot initialize subdevice base class instance.\n");
219 kfree(subdevice);
220 return NULL;
222 /* Initialize spin locks. */
223 spin_lock_init(&subdevice->subdevice_lock);
225 /* Save the subdevice index */
226 subdevice->port_reg = reg_base + ME0600_OPTO_INPUT_REG;
228 /* Overload base class methods. */
229 subdevice->base.me_subdevice_io_reset_subdevice =
230 me0600_optoi_io_reset_subdevice;
231 subdevice->base.me_subdevice_io_single_config =
232 me0600_optoi_io_single_config;
233 subdevice->base.me_subdevice_io_single_read =
234 me0600_optoi_io_single_read;
235 subdevice->base.me_subdevice_query_number_channels =
236 me0600_optoi_query_number_channels;
237 subdevice->base.me_subdevice_query_subdevice_type =
238 me0600_optoi_query_subdevice_type;
239 subdevice->base.me_subdevice_query_subdevice_caps =
240 me0600_optoi_query_subdevice_caps;
242 return subdevice;