1 |
1275 |
phoenix |
/*
|
2 |
|
|
*
|
3 |
|
|
* mwavedd.c -- mwave device driver
|
4 |
|
|
*
|
5 |
|
|
*
|
6 |
|
|
* Written By: Mike Sullivan IBM Corporation
|
7 |
|
|
*
|
8 |
|
|
* Copyright (C) 1999 IBM Corporation
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* NO WARRANTY
|
21 |
|
|
* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
|
22 |
|
|
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
|
23 |
|
|
* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
|
24 |
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
|
25 |
|
|
* solely responsible for determining the appropriateness of using and
|
26 |
|
|
* distributing the Program and assumes all risks associated with its
|
27 |
|
|
* exercise of rights under this Agreement, including but not limited to
|
28 |
|
|
* the risks and costs of program errors, damage to or loss of data,
|
29 |
|
|
* programs or equipment, and unavailability or interruption of operations.
|
30 |
|
|
*
|
31 |
|
|
* DISCLAIMER OF LIABILITY
|
32 |
|
|
* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
|
33 |
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
34 |
|
|
* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
|
35 |
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
36 |
|
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
37 |
|
|
* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
|
38 |
|
|
* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
|
39 |
|
|
*
|
40 |
|
|
* You should have received a copy of the GNU General Public License
|
41 |
|
|
* along with this program; if not, write to the Free Software
|
42 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
43 |
|
|
*
|
44 |
|
|
*
|
45 |
|
|
* 10/23/2000 - Alpha Release
|
46 |
|
|
* First release to the public
|
47 |
|
|
*/
|
48 |
|
|
|
49 |
|
|
#include <linux/version.h>
|
50 |
|
|
#include <linux/module.h>
|
51 |
|
|
#include <linux/kernel.h>
|
52 |
|
|
#include <linux/fs.h>
|
53 |
|
|
#include <linux/init.h>
|
54 |
|
|
#include <linux/major.h>
|
55 |
|
|
#include <linux/miscdevice.h>
|
56 |
|
|
#include <linux/proc_fs.h>
|
57 |
|
|
#include <linux/serial.h>
|
58 |
|
|
#include <linux/sched.h>
|
59 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
60 |
|
|
#include <linux/spinlock.h>
|
61 |
|
|
#else
|
62 |
|
|
#include <asm/spinlock.h>
|
63 |
|
|
#endif
|
64 |
|
|
#include <linux/delay.h>
|
65 |
|
|
#include "smapi.h"
|
66 |
|
|
#include "mwavedd.h"
|
67 |
|
|
#include "3780i.h"
|
68 |
|
|
#include "tp3780i.h"
|
69 |
|
|
|
70 |
|
|
#ifndef __exit
|
71 |
|
|
#define __exit
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
MODULE_DESCRIPTION("3780i Advanced Communications Processor (Mwave) driver");
|
75 |
|
|
MODULE_AUTHOR("Mike Sullivan and Paul Schroeder");
|
76 |
|
|
MODULE_LICENSE("GPL");
|
77 |
|
|
|
78 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
79 |
|
|
static int mwave_get_info(char *buf, char **start, off_t offset, int len);
|
80 |
|
|
#else
|
81 |
|
|
static int mwave_read_proc(char *buf, char **start, off_t offset, int xlen, int unused);
|
82 |
|
|
static struct proc_dir_entry mwave_proc = {
|
83 |
|
|
0, /* unsigned short low_ino */
|
84 |
|
|
5, /* unsigned short namelen */
|
85 |
|
|
"mwave", /* const char *name */
|
86 |
|
|
S_IFREG | S_IRUGO, /* mode_t mode */
|
87 |
|
|
1, /* nlink_t nlink */
|
88 |
|
|
0, /* uid_t uid */
|
89 |
|
|
0, /* gid_t gid */
|
90 |
|
|
0, /* unsigned long size */
|
91 |
|
|
NULL, /* struct inode_operations *ops */
|
92 |
|
|
&mwave_read_proc /* int (*get_info) (...) */
|
93 |
|
|
};
|
94 |
|
|
#endif
|
95 |
|
|
|
96 |
|
|
/*
|
97 |
|
|
* These parameters support the setting of MWave resources. Note that no
|
98 |
|
|
* checks are made against other devices (ie. superio) for conflicts.
|
99 |
|
|
* We'll depend on users using the tpctl utility to do that for now
|
100 |
|
|
*/
|
101 |
|
|
int mwave_debug = 0;
|
102 |
|
|
int mwave_3780i_irq = 0;
|
103 |
|
|
int mwave_3780i_io = 0;
|
104 |
|
|
int mwave_uart_irq = 0;
|
105 |
|
|
int mwave_uart_io = 0;
|
106 |
|
|
MODULE_PARM(mwave_debug, "i");
|
107 |
|
|
MODULE_PARM(mwave_3780i_irq, "i");
|
108 |
|
|
MODULE_PARM(mwave_3780i_io, "i");
|
109 |
|
|
MODULE_PARM(mwave_uart_irq, "i");
|
110 |
|
|
MODULE_PARM(mwave_uart_io, "i");
|
111 |
|
|
|
112 |
|
|
static int mwave_open(struct inode *inode, struct file *file);
|
113 |
|
|
static int mwave_close(struct inode *inode, struct file *file);
|
114 |
|
|
static int mwave_ioctl(struct inode *inode, struct file *filp,
|
115 |
|
|
unsigned int iocmd, unsigned long ioarg);
|
116 |
|
|
|
117 |
|
|
MWAVE_DEVICE_DATA mwave_s_mdd;
|
118 |
|
|
|
119 |
|
|
static int mwave_open(struct inode *inode, struct file *file)
|
120 |
|
|
{
|
121 |
|
|
unsigned int retval = 0;
|
122 |
|
|
|
123 |
|
|
PRINTK_3(TRACE_MWAVE,
|
124 |
|
|
"mwavedd::mwave_open, entry inode %x file %x\n",
|
125 |
|
|
(int) inode, (int) file);
|
126 |
|
|
PRINTK_2(TRACE_MWAVE,
|
127 |
|
|
"mwavedd::mwave_open, exit return retval %x\n", retval);
|
128 |
|
|
|
129 |
|
|
MOD_INC_USE_COUNT;
|
130 |
|
|
return retval;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
static int mwave_close(struct inode *inode, struct file *file)
|
134 |
|
|
{
|
135 |
|
|
unsigned int retval = 0;
|
136 |
|
|
|
137 |
|
|
PRINTK_3(TRACE_MWAVE,
|
138 |
|
|
"mwavedd::mwave_close, entry inode %x file %x\n",
|
139 |
|
|
(int) inode, (int) file);
|
140 |
|
|
|
141 |
|
|
PRINTK_2(TRACE_MWAVE, "mwavedd::mwave_close, exit retval %x\n",
|
142 |
|
|
retval);
|
143 |
|
|
|
144 |
|
|
MOD_DEC_USE_COUNT;
|
145 |
|
|
return retval;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
static int mwave_ioctl(struct inode *inode, struct file *file,
|
149 |
|
|
unsigned int iocmd, unsigned long ioarg)
|
150 |
|
|
{
|
151 |
|
|
unsigned int retval = 0;
|
152 |
|
|
pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
|
153 |
|
|
|
154 |
|
|
PRINTK_5(TRACE_MWAVE,
|
155 |
|
|
"mwavedd::mwave_ioctl, entry inode %x file %x cmd %x arg %x\n",
|
156 |
|
|
(int) inode, (int) file, iocmd, (int) ioarg);
|
157 |
|
|
|
158 |
|
|
switch (iocmd) {
|
159 |
|
|
|
160 |
|
|
case IOCTL_MW_RESET:
|
161 |
|
|
PRINTK_1(TRACE_MWAVE,
|
162 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_RESET calling tp3780I_ResetDSP\n");
|
163 |
|
|
retval = tp3780I_ResetDSP(&pDrvData->rBDData);
|
164 |
|
|
PRINTK_2(TRACE_MWAVE,
|
165 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_RESET retval %x from tp3780I_ResetDSP\n",
|
166 |
|
|
retval);
|
167 |
|
|
break;
|
168 |
|
|
|
169 |
|
|
case IOCTL_MW_RUN:
|
170 |
|
|
PRINTK_1(TRACE_MWAVE,
|
171 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_RUN calling tp3780I_StartDSP\n");
|
172 |
|
|
retval = tp3780I_StartDSP(&pDrvData->rBDData);
|
173 |
|
|
PRINTK_2(TRACE_MWAVE,
|
174 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_RUN retval %x from tp3780I_StartDSP\n",
|
175 |
|
|
retval);
|
176 |
|
|
break;
|
177 |
|
|
|
178 |
|
|
case IOCTL_MW_DSP_ABILITIES: {
|
179 |
|
|
MW_ABILITIES rAbilities;
|
180 |
|
|
|
181 |
|
|
PRINTK_1(TRACE_MWAVE,
|
182 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES calling tp3780I_QueryAbilities\n");
|
183 |
|
|
retval = tp3780I_QueryAbilities(&pDrvData->rBDData, &rAbilities);
|
184 |
|
|
PRINTK_2(TRACE_MWAVE,
|
185 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES retval %x from tp3780I_QueryAbilities\n",
|
186 |
|
|
retval);
|
187 |
|
|
if (retval == 0) {
|
188 |
|
|
if( copy_to_user((char *) ioarg, (char *) &rAbilities, sizeof(MW_ABILITIES)) )
|
189 |
|
|
return -EFAULT;
|
190 |
|
|
}
|
191 |
|
|
PRINTK_2(TRACE_MWAVE,
|
192 |
|
|
"mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES exit retval %x\n",
|
193 |
|
|
retval);
|
194 |
|
|
}
|
195 |
|
|
break;
|
196 |
|
|
|
197 |
|
|
case IOCTL_MW_READ_DATA:
|
198 |
|
|
case IOCTL_MW_READCLEAR_DATA: {
|
199 |
|
|
MW_READWRITE rReadData;
|
200 |
|
|
unsigned short *pusBuffer = 0;
|
201 |
|
|
|
202 |
|
|
if( copy_from_user((char *) &rReadData, (char *) ioarg, sizeof(MW_READWRITE)) )
|
203 |
|
|
return -EFAULT;
|
204 |
|
|
pusBuffer = (unsigned short *) (rReadData.pBuf);
|
205 |
|
|
|
206 |
|
|
PRINTK_4(TRACE_MWAVE,
|
207 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_READ_DATA, size %lx, ioarg %lx pusBuffer %p\n",
|
208 |
|
|
rReadData.ulDataLength, ioarg, pusBuffer);
|
209 |
|
|
retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, iocmd,
|
210 |
|
|
(void *) pusBuffer, rReadData.ulDataLength, rReadData.usDspAddress);
|
211 |
|
|
}
|
212 |
|
|
break;
|
213 |
|
|
|
214 |
|
|
case IOCTL_MW_READ_INST: {
|
215 |
|
|
MW_READWRITE rReadData;
|
216 |
|
|
unsigned short *pusBuffer = 0;
|
217 |
|
|
|
218 |
|
|
if( copy_from_user((char *) &rReadData, (char *) ioarg, sizeof(MW_READWRITE)) )
|
219 |
|
|
return -EFAULT;
|
220 |
|
|
pusBuffer = (unsigned short *) (rReadData.pBuf);
|
221 |
|
|
|
222 |
|
|
PRINTK_4(TRACE_MWAVE,
|
223 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_READ_INST, size %lx, ioarg %lx pusBuffer %p\n",
|
224 |
|
|
rReadData.ulDataLength / 2, ioarg,
|
225 |
|
|
pusBuffer);
|
226 |
|
|
retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
|
227 |
|
|
iocmd, pusBuffer,
|
228 |
|
|
rReadData.ulDataLength / 2,
|
229 |
|
|
rReadData.usDspAddress);
|
230 |
|
|
}
|
231 |
|
|
break;
|
232 |
|
|
|
233 |
|
|
case IOCTL_MW_WRITE_DATA: {
|
234 |
|
|
MW_READWRITE rWriteData;
|
235 |
|
|
unsigned short *pusBuffer = 0;
|
236 |
|
|
|
237 |
|
|
if( copy_from_user((char *) &rWriteData, (char *) ioarg, sizeof(MW_READWRITE)) )
|
238 |
|
|
return -EFAULT;
|
239 |
|
|
pusBuffer = (unsigned short *) (rWriteData.pBuf);
|
240 |
|
|
|
241 |
|
|
PRINTK_4(TRACE_MWAVE,
|
242 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_WRITE_DATA, size %lx, ioarg %lx pusBuffer %p\n",
|
243 |
|
|
rWriteData.ulDataLength, ioarg,
|
244 |
|
|
pusBuffer);
|
245 |
|
|
retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, iocmd,
|
246 |
|
|
pusBuffer, rWriteData.ulDataLength, rWriteData.usDspAddress);
|
247 |
|
|
}
|
248 |
|
|
break;
|
249 |
|
|
|
250 |
|
|
case IOCTL_MW_WRITE_INST: {
|
251 |
|
|
MW_READWRITE rWriteData;
|
252 |
|
|
unsigned short *pusBuffer = 0;
|
253 |
|
|
|
254 |
|
|
if( copy_from_user((char *) &rWriteData, (char *) ioarg, sizeof(MW_READWRITE)) )
|
255 |
|
|
return -EFAULT;
|
256 |
|
|
pusBuffer = (unsigned short *) (rWriteData.pBuf);
|
257 |
|
|
|
258 |
|
|
PRINTK_4(TRACE_MWAVE,
|
259 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_WRITE_INST, size %lx, ioarg %lx pusBuffer %p\n",
|
260 |
|
|
rWriteData.ulDataLength, ioarg,
|
261 |
|
|
pusBuffer);
|
262 |
|
|
retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData, iocmd,
|
263 |
|
|
pusBuffer, rWriteData.ulDataLength, rWriteData.usDspAddress);
|
264 |
|
|
}
|
265 |
|
|
break;
|
266 |
|
|
|
267 |
|
|
case IOCTL_MW_REGISTER_IPC: {
|
268 |
|
|
unsigned int ipcnum = (unsigned int) ioarg;
|
269 |
|
|
|
270 |
|
|
PRINTK_3(TRACE_MWAVE,
|
271 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC ipcnum %x entry usIntCount %x\n",
|
272 |
|
|
ipcnum,
|
273 |
|
|
pDrvData->IPCs[ipcnum].usIntCount);
|
274 |
|
|
|
275 |
|
|
if (ipcnum > 16) {
|
276 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl: IOCTL_MW_REGISTER_IPC: Error: Invalid ipcnum %x\n", ipcnum);
|
277 |
|
|
return -EINVAL;
|
278 |
|
|
}
|
279 |
|
|
pDrvData->IPCs[ipcnum].bIsHere = FALSE;
|
280 |
|
|
pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
|
281 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
282 |
|
|
current->nice = -20; /* boost to provide priority timing */
|
283 |
|
|
#else
|
284 |
|
|
current->priority = 0x28; /* boost to provide priority timing */
|
285 |
|
|
#endif
|
286 |
|
|
|
287 |
|
|
PRINTK_2(TRACE_MWAVE,
|
288 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC ipcnum %x exit\n",
|
289 |
|
|
ipcnum);
|
290 |
|
|
}
|
291 |
|
|
break;
|
292 |
|
|
|
293 |
|
|
case IOCTL_MW_GET_IPC: {
|
294 |
|
|
unsigned int ipcnum = (unsigned int) ioarg;
|
295 |
|
|
spinlock_t ipc_lock = SPIN_LOCK_UNLOCKED;
|
296 |
|
|
unsigned long flags;
|
297 |
|
|
|
298 |
|
|
PRINTK_3(TRACE_MWAVE,
|
299 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_GET_IPC ipcnum %x, usIntCount %x\n",
|
300 |
|
|
ipcnum,
|
301 |
|
|
pDrvData->IPCs[ipcnum].usIntCount);
|
302 |
|
|
if (ipcnum > 16) {
|
303 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl: IOCTL_MW_GET_IPC: Error: Invalid ipcnum %x\n", ipcnum);
|
304 |
|
|
return -EINVAL;
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
|
308 |
|
|
PRINTK_2(TRACE_MWAVE,
|
309 |
|
|
"mwavedd::mwave_ioctl, thread for ipc %x going to sleep\n",
|
310 |
|
|
ipcnum);
|
311 |
|
|
|
312 |
|
|
spin_lock_irqsave(&ipc_lock, flags);
|
313 |
|
|
/* check whether an event was signalled by */
|
314 |
|
|
/* the interrupt handler while we were gone */
|
315 |
|
|
if (pDrvData->IPCs[ipcnum].usIntCount == 1) { /* first int has occurred (race condition) */
|
316 |
|
|
pDrvData->IPCs[ipcnum].usIntCount = 2; /* first int has been handled */
|
317 |
|
|
spin_unlock_irqrestore(&ipc_lock, flags);
|
318 |
|
|
PRINTK_2(TRACE_MWAVE,
|
319 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_GET_IPC ipcnum %x handling first int\n",
|
320 |
|
|
ipcnum);
|
321 |
|
|
} else { /* either 1st int has not yet occurred, or we have already handled the first int */
|
322 |
|
|
pDrvData->IPCs[ipcnum].bIsHere = TRUE;
|
323 |
|
|
interruptible_sleep_on(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
|
324 |
|
|
pDrvData->IPCs[ipcnum].bIsHere = FALSE;
|
325 |
|
|
if (pDrvData->IPCs[ipcnum].usIntCount == 1) {
|
326 |
|
|
pDrvData->IPCs[ipcnum].
|
327 |
|
|
usIntCount = 2;
|
328 |
|
|
}
|
329 |
|
|
spin_unlock_irqrestore(&ipc_lock, flags);
|
330 |
|
|
PRINTK_2(TRACE_MWAVE,
|
331 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_GET_IPC ipcnum %x woke up and returning to application\n",
|
332 |
|
|
ipcnum);
|
333 |
|
|
}
|
334 |
|
|
PRINTK_2(TRACE_MWAVE,
|
335 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_GET_IPC, returning thread for ipc %x processing\n",
|
336 |
|
|
ipcnum);
|
337 |
|
|
}
|
338 |
|
|
}
|
339 |
|
|
break;
|
340 |
|
|
|
341 |
|
|
case IOCTL_MW_UNREGISTER_IPC: {
|
342 |
|
|
unsigned int ipcnum = (unsigned int) ioarg;
|
343 |
|
|
|
344 |
|
|
PRINTK_2(TRACE_MWAVE,
|
345 |
|
|
"mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC ipcnum %x\n",
|
346 |
|
|
ipcnum);
|
347 |
|
|
if (ipcnum > 16) {
|
348 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl: IOCTL_MW_UNREGISTER_IPC: Error: Invalid ipcnum %x\n", ipcnum);
|
349 |
|
|
return -EINVAL;
|
350 |
|
|
}
|
351 |
|
|
if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
|
352 |
|
|
pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
|
353 |
|
|
if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
|
354 |
|
|
wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
|
355 |
|
|
}
|
356 |
|
|
}
|
357 |
|
|
}
|
358 |
|
|
break;
|
359 |
|
|
|
360 |
|
|
default:
|
361 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl: Error: Unrecognized iocmd %x\n", iocmd);
|
362 |
|
|
return -ENOTTY;
|
363 |
|
|
break;
|
364 |
|
|
} /* switch */
|
365 |
|
|
|
366 |
|
|
PRINTK_2(TRACE_MWAVE, "mwavedd::mwave_ioctl, exit retval %x\n", retval);
|
367 |
|
|
|
368 |
|
|
return retval;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
static ssize_t mwave_read(struct file *file, char *buf, size_t count,
|
373 |
|
|
loff_t * ppos)
|
374 |
|
|
{
|
375 |
|
|
PRINTK_5(TRACE_MWAVE,
|
376 |
|
|
"mwavedd::mwave_read entry file %p, buf %p, count %x ppos %p\n",
|
377 |
|
|
file, buf, count, ppos);
|
378 |
|
|
|
379 |
|
|
return -EINVAL;
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
static ssize_t mwave_write(struct file *file, const char *buf,
|
384 |
|
|
size_t count, loff_t * ppos)
|
385 |
|
|
{
|
386 |
|
|
PRINTK_5(TRACE_MWAVE,
|
387 |
|
|
"mwavedd::mwave_write entry file %p, buf %p, count %x ppos %p\n",
|
388 |
|
|
file, buf, count, ppos);
|
389 |
|
|
|
390 |
|
|
return -EINVAL;
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
static int register_serial_portandirq(unsigned int port, int irq)
|
395 |
|
|
{
|
396 |
|
|
struct serial_struct serial;
|
397 |
|
|
|
398 |
|
|
switch ( port ) {
|
399 |
|
|
case 0x3f8:
|
400 |
|
|
case 0x2f8:
|
401 |
|
|
case 0x3e8:
|
402 |
|
|
case 0x2e8:
|
403 |
|
|
/* OK */
|
404 |
|
|
break;
|
405 |
|
|
default:
|
406 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::register_serial_portandirq: Error: Illegal port %x\n", port );
|
407 |
|
|
return -1;
|
408 |
|
|
} /* switch */
|
409 |
|
|
/* port is okay */
|
410 |
|
|
|
411 |
|
|
switch ( irq ) {
|
412 |
|
|
case 3:
|
413 |
|
|
case 4:
|
414 |
|
|
case 5:
|
415 |
|
|
case 7:
|
416 |
|
|
/* OK */
|
417 |
|
|
break;
|
418 |
|
|
default:
|
419 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::register_serial_portandirq: Error: Illegal irq %x\n", irq );
|
420 |
|
|
return -1;
|
421 |
|
|
} /* switch */
|
422 |
|
|
/* irq is okay */
|
423 |
|
|
|
424 |
|
|
memset(&serial, 0, sizeof(serial));
|
425 |
|
|
serial.port = port;
|
426 |
|
|
serial.irq = irq;
|
427 |
|
|
serial.flags = ASYNC_SHARE_IRQ;
|
428 |
|
|
|
429 |
|
|
return register_serial(&serial);
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
434 |
|
|
static struct file_operations mwave_fops = {
|
435 |
|
|
owner:THIS_MODULE,
|
436 |
|
|
read:mwave_read,
|
437 |
|
|
write:mwave_write,
|
438 |
|
|
ioctl:mwave_ioctl,
|
439 |
|
|
open:mwave_open,
|
440 |
|
|
release:mwave_close
|
441 |
|
|
};
|
442 |
|
|
#else
|
443 |
|
|
static struct file_operations mwave_fops = {
|
444 |
|
|
NULL, /* lseek */
|
445 |
|
|
mwave_read, /* read */
|
446 |
|
|
mwave_write, /* write */
|
447 |
|
|
NULL, /* readdir */
|
448 |
|
|
NULL, /* poll */
|
449 |
|
|
mwave_ioctl, /* ioctl */
|
450 |
|
|
NULL, /* mmap */
|
451 |
|
|
mwave_open, /* open */
|
452 |
|
|
NULL, /* flush */
|
453 |
|
|
mwave_close /* release */
|
454 |
|
|
};
|
455 |
|
|
#endif
|
456 |
|
|
|
457 |
|
|
static struct miscdevice mwave_misc_dev = { MWAVE_MINOR, "mwave", &mwave_fops };
|
458 |
|
|
|
459 |
|
|
/*
|
460 |
|
|
* mwave_init is called on module load
|
461 |
|
|
*
|
462 |
|
|
* mwave_exit is called on module unload
|
463 |
|
|
* mwave_exit is also used to clean up after an aborted mwave_init
|
464 |
|
|
*/
|
465 |
|
|
static void mwave_exit(void)
|
466 |
|
|
{
|
467 |
|
|
pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
|
468 |
|
|
|
469 |
|
|
PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_exit entry\n");
|
470 |
|
|
|
471 |
|
|
if (pDrvData->bProcEntryCreated) {
|
472 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
473 |
|
|
remove_proc_entry("mwave", NULL);
|
474 |
|
|
#else
|
475 |
|
|
proc_unregister(&proc_root, mwave_proc.low_ino);
|
476 |
|
|
#endif
|
477 |
|
|
}
|
478 |
|
|
if ( pDrvData->sLine >= 0 ) {
|
479 |
|
|
unregister_serial(pDrvData->sLine);
|
480 |
|
|
}
|
481 |
|
|
if (pDrvData->bMwaveDevRegistered) {
|
482 |
|
|
misc_deregister(&mwave_misc_dev);
|
483 |
|
|
}
|
484 |
|
|
if (pDrvData->bDSPEnabled) {
|
485 |
|
|
tp3780I_DisableDSP(&pDrvData->rBDData);
|
486 |
|
|
}
|
487 |
|
|
if (pDrvData->bResourcesClaimed) {
|
488 |
|
|
tp3780I_ReleaseResources(&pDrvData->rBDData);
|
489 |
|
|
}
|
490 |
|
|
if (pDrvData->bBDInitialized) {
|
491 |
|
|
tp3780I_Cleanup(&pDrvData->rBDData);
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_exit exit\n");
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
module_exit(mwave_exit);
|
498 |
|
|
|
499 |
|
|
static int __init mwave_init(void)
|
500 |
|
|
{
|
501 |
|
|
int i;
|
502 |
|
|
int retval = 0;
|
503 |
|
|
int resultMiscRegister;
|
504 |
|
|
pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
|
505 |
|
|
|
506 |
|
|
memset(&mwave_s_mdd, 0, sizeof(MWAVE_DEVICE_DATA));
|
507 |
|
|
|
508 |
|
|
PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_init entry\n");
|
509 |
|
|
|
510 |
|
|
pDrvData->bBDInitialized = FALSE;
|
511 |
|
|
pDrvData->bResourcesClaimed = FALSE;
|
512 |
|
|
pDrvData->bDSPEnabled = FALSE;
|
513 |
|
|
pDrvData->bDSPReset = FALSE;
|
514 |
|
|
pDrvData->bMwaveDevRegistered = FALSE;
|
515 |
|
|
pDrvData->sLine = -1;
|
516 |
|
|
pDrvData->bProcEntryCreated = FALSE;
|
517 |
|
|
|
518 |
|
|
for (i = 0; i < 16; i++) {
|
519 |
|
|
pDrvData->IPCs[i].bIsEnabled = FALSE;
|
520 |
|
|
pDrvData->IPCs[i].bIsHere = FALSE;
|
521 |
|
|
pDrvData->IPCs[i].usIntCount = 0; /* no ints received yet */
|
522 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
523 |
|
|
init_waitqueue_head(&pDrvData->IPCs[i].ipc_wait_queue);
|
524 |
|
|
#endif
|
525 |
|
|
}
|
526 |
|
|
|
527 |
|
|
retval = tp3780I_InitializeBoardData(&pDrvData->rBDData);
|
528 |
|
|
PRINTK_2(TRACE_MWAVE,
|
529 |
|
|
"mwavedd::mwave_init, return from tp3780I_InitializeBoardData retval %x\n",
|
530 |
|
|
retval);
|
531 |
|
|
if (retval) {
|
532 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_init: Error: Failed to initialize board data\n");
|
533 |
|
|
goto cleanup_error;
|
534 |
|
|
}
|
535 |
|
|
pDrvData->bBDInitialized = TRUE;
|
536 |
|
|
|
537 |
|
|
retval = tp3780I_CalcResources(&pDrvData->rBDData);
|
538 |
|
|
PRINTK_2(TRACE_MWAVE,
|
539 |
|
|
"mwavedd::mwave_init, return from tp3780I_CalcResources retval %x\n",
|
540 |
|
|
retval);
|
541 |
|
|
if (retval) {
|
542 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd:mwave_init: Error: Failed to calculate resources\n");
|
543 |
|
|
goto cleanup_error;
|
544 |
|
|
}
|
545 |
|
|
|
546 |
|
|
retval = tp3780I_ClaimResources(&pDrvData->rBDData);
|
547 |
|
|
PRINTK_2(TRACE_MWAVE,
|
548 |
|
|
"mwavedd::mwave_init, return from tp3780I_ClaimResources retval %x\n",
|
549 |
|
|
retval);
|
550 |
|
|
if (retval) {
|
551 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd:mwave_init: Error: Failed to claim resources\n");
|
552 |
|
|
goto cleanup_error;
|
553 |
|
|
}
|
554 |
|
|
pDrvData->bResourcesClaimed = TRUE;
|
555 |
|
|
|
556 |
|
|
retval = tp3780I_EnableDSP(&pDrvData->rBDData);
|
557 |
|
|
PRINTK_2(TRACE_MWAVE,
|
558 |
|
|
"mwavedd::mwave_init, return from tp3780I_EnableDSP retval %x\n",
|
559 |
|
|
retval);
|
560 |
|
|
if (retval) {
|
561 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd:mwave_init: Error: Failed to enable DSP\n");
|
562 |
|
|
goto cleanup_error;
|
563 |
|
|
}
|
564 |
|
|
pDrvData->bDSPEnabled = TRUE;
|
565 |
|
|
|
566 |
|
|
resultMiscRegister = misc_register(&mwave_misc_dev);
|
567 |
|
|
if (resultMiscRegister < 0) {
|
568 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd:mwave_init: Error: Failed to register misc device\n");
|
569 |
|
|
goto cleanup_error;
|
570 |
|
|
}
|
571 |
|
|
pDrvData->bMwaveDevRegistered = TRUE;
|
572 |
|
|
|
573 |
|
|
pDrvData->sLine = register_serial_portandirq(
|
574 |
|
|
pDrvData->rBDData.rDspSettings.usUartBaseIO,
|
575 |
|
|
pDrvData->rBDData.rDspSettings.usUartIrq
|
576 |
|
|
);
|
577 |
|
|
if (pDrvData->sLine < 0) {
|
578 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd:mwave_init: Error: Failed to register serial driver\n");
|
579 |
|
|
goto cleanup_error;
|
580 |
|
|
}
|
581 |
|
|
/* uart is registered */
|
582 |
|
|
|
583 |
|
|
if (
|
584 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
585 |
|
|
!create_proc_info_entry("mwave", 0, NULL, mwave_get_info)
|
586 |
|
|
#else
|
587 |
|
|
proc_register(&proc_root, &mwave_proc)
|
588 |
|
|
#endif
|
589 |
|
|
) {
|
590 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_init: Error: Failed to register /proc/mwave\n");
|
591 |
|
|
goto cleanup_error;
|
592 |
|
|
}
|
593 |
|
|
pDrvData->bProcEntryCreated = TRUE;
|
594 |
|
|
|
595 |
|
|
/* SUCCESS! */
|
596 |
|
|
return 0;
|
597 |
|
|
|
598 |
|
|
cleanup_error:
|
599 |
|
|
PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_init: Error: Failed to initialize\n");
|
600 |
|
|
mwave_exit(); /* clean up */
|
601 |
|
|
|
602 |
|
|
return -EIO;
|
603 |
|
|
}
|
604 |
|
|
|
605 |
|
|
module_init(mwave_init);
|
606 |
|
|
|
607 |
|
|
|
608 |
|
|
/*
|
609 |
|
|
* proc entry stuff added by Ian Pilcher <pilcher@us.ibm.com>
|
610 |
|
|
*/
|
611 |
|
|
|
612 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
|
613 |
|
|
static int mwave_get_info(char *buf, char **start, off_t offset, int len)
|
614 |
|
|
{
|
615 |
|
|
DSP_3780I_CONFIG_SETTINGS *pSettings = &mwave_s_mdd.rBDData.rDspSettings;
|
616 |
|
|
|
617 |
|
|
char *out = buf;
|
618 |
|
|
|
619 |
|
|
out += sprintf(out, "3780i_IRQ %i\n", pSettings->usDspIrq);
|
620 |
|
|
out += sprintf(out, "3780i_DMA %i\n", pSettings->usDspDma);
|
621 |
|
|
out += sprintf(out, "3780i_IO %#.4x\n", pSettings->usDspBaseIO);
|
622 |
|
|
out += sprintf(out, "UART_IRQ %i\n", pSettings->usUartIrq);
|
623 |
|
|
out += sprintf(out, "UART_IO %#.4x\n", pSettings->usUartBaseIO);
|
624 |
|
|
|
625 |
|
|
return out - buf;
|
626 |
|
|
}
|
627 |
|
|
#else /* kernel version < 2.4.0 */
|
628 |
|
|
static int mwave_read_proc(char *buf, char **start, off_t offset,
|
629 |
|
|
int xlen, int unused)
|
630 |
|
|
{
|
631 |
|
|
DSP_3780I_CONFIG_SETTINGS *pSettings = &mwave_s_mdd.rBDData.rDspSettings;
|
632 |
|
|
int len;
|
633 |
|
|
|
634 |
|
|
len = sprintf(buf, "3780i_IRQ %i\n", pSettings->usDspIrq);
|
635 |
|
|
len += sprintf(&buf[len], "3780i_DMA %i\n", pSettings->usDspDma);
|
636 |
|
|
len += sprintf(&buf[len], "3780i_IO %#.4x\n", pSettings->usDspBaseIO);
|
637 |
|
|
len += sprintf(&buf[len], "UART_IRQ %i\n", pSettings->usUartIrq);
|
638 |
|
|
len += sprintf(&buf[len], "UART_IO %#.4x\n", pSettings->usUartBaseIO);
|
639 |
|
|
|
640 |
|
|
return len;
|
641 |
|
|
}
|
642 |
|
|
#endif
|