patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / char / mwave / mwavedd.c
1 /*
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/module.h>
50 #include <linux/kernel.h>
51 #include <linux/fs.h>
52 #include <linux/init.h>
53 #include <linux/major.h>
54 #include <linux/miscdevice.h>
55 #include <linux/device.h>
56 #include <linux/serial.h>
57 #include <linux/sched.h>
58 #include <linux/spinlock.h>
59 #include <linux/delay.h>
60 #include "smapi.h"
61 #include "mwavedd.h"
62 #include "3780i.h"
63 #include "tp3780i.h"
64
65 MODULE_DESCRIPTION("3780i Advanced Communications Processor (Mwave) driver");
66 MODULE_AUTHOR("Mike Sullivan and Paul Schroeder");
67 MODULE_LICENSE("GPL");
68
69 /*
70 * These parameters support the setting of MWave resources. Note that no
71 * checks are made against other devices (ie. superio) for conflicts.
72 * We'll depend on users using the tpctl utility to do that for now
73 */
74 int mwave_debug = 0;
75 int mwave_3780i_irq = 0;
76 int mwave_3780i_io = 0;
77 int mwave_uart_irq = 0;
78 int mwave_uart_io = 0;
79 MODULE_PARM(mwave_debug, "i");
80 MODULE_PARM(mwave_3780i_irq, "i");
81 MODULE_PARM(mwave_3780i_io, "i");
82 MODULE_PARM(mwave_uart_irq, "i");
83 MODULE_PARM(mwave_uart_io, "i");
84
85 static int mwave_open(struct inode *inode, struct file *file);
86 static int mwave_close(struct inode *inode, struct file *file);
87 static int mwave_ioctl(struct inode *inode, struct file *filp,
88                        unsigned int iocmd, unsigned long ioarg);
89
90 MWAVE_DEVICE_DATA mwave_s_mdd;
91
92 static int mwave_open(struct inode *inode, struct file *file)
93 {
94         unsigned int retval = 0;
95
96         PRINTK_3(TRACE_MWAVE,
97                 "mwavedd::mwave_open, entry inode %x file %x\n",
98                 (int) inode, (int) file);
99         PRINTK_2(TRACE_MWAVE,
100                 "mwavedd::mwave_open, exit return retval %x\n", retval);
101
102         return retval;
103 }
104
105 static int mwave_close(struct inode *inode, struct file *file)
106 {
107         unsigned int retval = 0;
108
109         PRINTK_3(TRACE_MWAVE,
110                 "mwavedd::mwave_close, entry inode %x file %x\n",
111                 (int) inode, (int) file);
112
113         PRINTK_2(TRACE_MWAVE, "mwavedd::mwave_close, exit retval %x\n",
114                 retval);
115
116         return retval;
117 }
118
119 static int mwave_ioctl(struct inode *inode, struct file *file,
120                        unsigned int iocmd, unsigned long ioarg)
121 {
122         unsigned int retval = 0;
123         pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
124
125         PRINTK_5(TRACE_MWAVE,
126                 "mwavedd::mwave_ioctl, entry inode %x file %x cmd %x arg %x\n",
127                 (int) inode, (int) file, iocmd, (int) ioarg);
128
129         switch (iocmd) {
130
131                 case IOCTL_MW_RESET:
132                         PRINTK_1(TRACE_MWAVE,
133                                 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
134                                 " calling tp3780I_ResetDSP\n");
135                         retval = tp3780I_ResetDSP(&pDrvData->rBDData);
136                         PRINTK_2(TRACE_MWAVE,
137                                 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
138                                 " retval %x from tp3780I_ResetDSP\n",
139                                 retval);
140                         break;
141         
142                 case IOCTL_MW_RUN:
143                         PRINTK_1(TRACE_MWAVE,
144                                 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
145                                 " calling tp3780I_StartDSP\n");
146                         retval = tp3780I_StartDSP(&pDrvData->rBDData);
147                         PRINTK_2(TRACE_MWAVE,
148                                 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
149                                 " retval %x from tp3780I_StartDSP\n",
150                                 retval);
151                         break;
152         
153                 case IOCTL_MW_DSP_ABILITIES: {
154                         MW_ABILITIES rAbilities;
155         
156                         PRINTK_1(TRACE_MWAVE,
157                                 "mwavedd::mwave_ioctl,"
158                                 " IOCTL_MW_DSP_ABILITIES calling"
159                                 " tp3780I_QueryAbilities\n");
160                         retval = tp3780I_QueryAbilities(&pDrvData->rBDData,
161                                         &rAbilities);
162                         PRINTK_2(TRACE_MWAVE,
163                                 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
164                                 " retval %x from tp3780I_QueryAbilities\n",
165                                 retval);
166                         if (retval == 0) {
167                                 if( copy_to_user((char *) ioarg,
168                                                         (char *) &rAbilities,
169                                                         sizeof(MW_ABILITIES)) )
170                                         return -EFAULT;
171                         }
172                         PRINTK_2(TRACE_MWAVE,
173                                 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
174                                 " exit retval %x\n",
175                                 retval);
176                 }
177                         break;
178         
179                 case IOCTL_MW_READ_DATA:
180                 case IOCTL_MW_READCLEAR_DATA: {
181                         MW_READWRITE rReadData;
182                         unsigned short *pusBuffer = 0;
183         
184                         if( copy_from_user((char *) &rReadData,
185                                                 (char *) ioarg,
186                                                 sizeof(MW_READWRITE)) )
187                                 return -EFAULT;
188                         pusBuffer = (unsigned short *) (rReadData.pBuf);
189         
190                         PRINTK_4(TRACE_MWAVE,
191                                 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA,"
192                                 " size %lx, ioarg %lx pusBuffer %p\n",
193                                 rReadData.ulDataLength, ioarg, pusBuffer);
194                         retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
195                                         iocmd,
196                                         (void *) pusBuffer,
197                                         rReadData.ulDataLength,
198                                         rReadData.usDspAddress);
199                 }
200                         break;
201         
202                 case IOCTL_MW_READ_INST: {
203                         MW_READWRITE rReadData;
204                         unsigned short *pusBuffer = 0;
205         
206                         if( copy_from_user((char *) &rReadData, (char *) ioarg,
207                                                 sizeof(MW_READWRITE)) )
208                                 return -EFAULT;
209                         pusBuffer = (unsigned short *) (rReadData.pBuf);
210         
211                         PRINTK_4(TRACE_MWAVE,
212                                 "mwavedd::mwave_ioctl IOCTL_MW_READ_INST,"
213                                 " size %lx, ioarg %lx pusBuffer %p\n",
214                                 rReadData.ulDataLength / 2, ioarg,
215                                 pusBuffer);
216                         retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
217                                 iocmd, pusBuffer,
218                                 rReadData.ulDataLength / 2,
219                                 rReadData.usDspAddress);
220                 }
221                         break;
222         
223                 case IOCTL_MW_WRITE_DATA: {
224                         MW_READWRITE rWriteData;
225                         unsigned short *pusBuffer = 0;
226         
227                         if( copy_from_user((char *) &rWriteData,
228                                                 (char *) ioarg,
229                                                 sizeof(MW_READWRITE)) )
230                                 return -EFAULT;
231                         pusBuffer = (unsigned short *) (rWriteData.pBuf);
232         
233                         PRINTK_4(TRACE_MWAVE,
234                                 "mwavedd::mwave_ioctl IOCTL_MW_WRITE_DATA,"
235                                 " size %lx, ioarg %lx pusBuffer %p\n",
236                                 rWriteData.ulDataLength, ioarg,
237                                 pusBuffer);
238                         retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
239                                         iocmd, pusBuffer,
240                                         rWriteData.ulDataLength,
241                                         rWriteData.usDspAddress);
242                 }
243                         break;
244         
245                 case IOCTL_MW_WRITE_INST: {
246                         MW_READWRITE rWriteData;
247                         unsigned short *pusBuffer = 0;
248         
249                         if( copy_from_user((char *) &rWriteData,
250                                                 (char *) ioarg,
251                                                 sizeof(MW_READWRITE)) )
252                                 return -EFAULT;
253                         pusBuffer = (unsigned short *) (rWriteData.pBuf);
254         
255                         PRINTK_4(TRACE_MWAVE,
256                                 "mwavedd::mwave_ioctl IOCTL_MW_WRITE_INST,"
257                                 " size %lx, ioarg %lx pusBuffer %p\n",
258                                 rWriteData.ulDataLength, ioarg,
259                                 pusBuffer);
260                         retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData,
261                                         iocmd, pusBuffer,
262                                         rWriteData.ulDataLength,
263                                         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"
272                                 " ipcnum %x entry usIntCount %x\n",
273                                 ipcnum,
274                                 pDrvData->IPCs[ipcnum].usIntCount);
275         
276                         if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
277                                 PRINTK_ERROR(KERN_ERR_MWAVE
278                                                 "mwavedd::mwave_ioctl:"
279                                                 " IOCTL_MW_REGISTER_IPC:"
280                                                 " Error: Invalid ipcnum %x\n",
281                                                 ipcnum);
282                                 return -EINVAL;
283                         }
284                         pDrvData->IPCs[ipcnum].bIsHere = FALSE;
285                         pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
286         
287                         PRINTK_2(TRACE_MWAVE,
288                                 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
289                                 " ipcnum %x exit\n",
290                                 ipcnum);
291                 }
292                         break;
293         
294                 case IOCTL_MW_GET_IPC: {
295                         unsigned int ipcnum = (unsigned int) ioarg;
296         
297                         PRINTK_3(TRACE_MWAVE,
298                                 "mwavedd::mwave_ioctl IOCTL_MW_GET_IPC"
299                                 " ipcnum %x, usIntCount %x\n",
300                                 ipcnum,
301                                 pDrvData->IPCs[ipcnum].usIntCount);
302                         if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
303                                 PRINTK_ERROR(KERN_ERR_MWAVE
304                                                 "mwavedd::mwave_ioctl:"
305                                                 " IOCTL_MW_GET_IPC: Error:"
306                                                 " Invalid ipcnum %x\n", ipcnum);
307                                 return -EINVAL;
308                         }
309         
310                         if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
311                                 DECLARE_WAITQUEUE(wait, current);
312
313                                 PRINTK_2(TRACE_MWAVE,
314                                         "mwavedd::mwave_ioctl, thread for"
315                                         " ipc %x going to sleep\n",
316                                         ipcnum);
317                                 add_wait_queue(&pDrvData->IPCs[ipcnum].ipc_wait_queue, &wait);
318                                 pDrvData->IPCs[ipcnum].bIsHere = TRUE;
319                                 set_current_state(TASK_INTERRUPTIBLE);
320                                 /* check whether an event was signalled by */
321                                 /* the interrupt handler while we were gone */
322                                 if (pDrvData->IPCs[ipcnum].usIntCount == 1) {   /* first int has occurred (race condition) */
323                                         pDrvData->IPCs[ipcnum].usIntCount = 2;  /* first int has been handled */
324                                         PRINTK_2(TRACE_MWAVE,
325                                                 "mwavedd::mwave_ioctl"
326                                                 " IOCTL_MW_GET_IPC ipcnum %x"
327                                                 " handling first int\n",
328                                                 ipcnum);
329                                 } else {        /* either 1st int has not yet occurred, or we have already handled the first int */
330                                         schedule();
331                                         if (pDrvData->IPCs[ipcnum].usIntCount == 1) {
332                                                 pDrvData->IPCs[ipcnum].usIntCount = 2;
333                                         }
334                                         PRINTK_2(TRACE_MWAVE,
335                                                 "mwavedd::mwave_ioctl"
336                                                 " IOCTL_MW_GET_IPC ipcnum %x"
337                                                 " woke up and returning to"
338                                                 " application\n",
339                                                 ipcnum);
340                                 }
341                                 pDrvData->IPCs[ipcnum].bIsHere = FALSE;
342                                 remove_wait_queue(&pDrvData->IPCs[ipcnum].ipc_wait_queue, &wait);
343                                 set_current_state(TASK_RUNNING);
344                                 PRINTK_2(TRACE_MWAVE,
345                                         "mwavedd::mwave_ioctl IOCTL_MW_GET_IPC,"
346                                         " returning thread for ipc %x"
347                                         " processing\n",
348                                         ipcnum);
349                         }
350                 }
351                         break;
352         
353                 case IOCTL_MW_UNREGISTER_IPC: {
354                         unsigned int ipcnum = (unsigned int) ioarg;
355         
356                         PRINTK_2(TRACE_MWAVE,
357                                 "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC"
358                                 " ipcnum %x\n",
359                                 ipcnum);
360                         if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
361                                 PRINTK_ERROR(KERN_ERR_MWAVE
362                                                 "mwavedd::mwave_ioctl:"
363                                                 " IOCTL_MW_UNREGISTER_IPC:"
364                                                 " Error: Invalid ipcnum %x\n",
365                                                 ipcnum);
366                                 return -EINVAL;
367                         }
368                         if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
369                                 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
370                                 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
371                                         wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
372                                 }
373                         }
374                 }
375                         break;
376         
377                 default:
378                         PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl:"
379                                         " Error: Unrecognized iocmd %x\n",
380                                         iocmd);
381                         return -ENOTTY;
382                         break;
383         } /* switch */
384
385         PRINTK_2(TRACE_MWAVE, "mwavedd::mwave_ioctl, exit retval %x\n", retval);
386
387         return retval;
388 }
389
390
391 static ssize_t mwave_read(struct file *file, char *buf, size_t count,
392                           loff_t * ppos)
393 {
394         PRINTK_5(TRACE_MWAVE,
395                 "mwavedd::mwave_read entry file %p, buf %p, count %x ppos %p\n",
396                 file, buf, count, ppos);
397
398         return -EINVAL;
399 }
400
401
402 static ssize_t mwave_write(struct file *file, const char *buf,
403                            size_t count, loff_t * ppos)
404 {
405         PRINTK_5(TRACE_MWAVE,
406                 "mwavedd::mwave_write entry file %p, buf %p,"
407                 " count %x ppos %p\n",
408                 file, buf, count, ppos);
409
410         return -EINVAL;
411 }
412
413
414 static int register_serial_portandirq(unsigned int port, int irq)
415 {
416         struct serial_struct serial;
417
418         switch ( port ) {
419                 case 0x3f8:
420                 case 0x2f8:
421                 case 0x3e8:
422                 case 0x2e8:
423                         /* OK */
424                         break;
425                 default:
426                         PRINTK_ERROR(KERN_ERR_MWAVE
427                                         "mwavedd::register_serial_portandirq:"
428                                         " Error: Illegal port %x\n", port );
429                         return -1;
430         } /* switch */
431         /* port is okay */
432
433         switch ( irq ) {
434                 case 3:
435                 case 4:
436                 case 5:
437                 case 7:
438                         /* OK */
439                         break;
440                 default:
441                         PRINTK_ERROR(KERN_ERR_MWAVE
442                                         "mwavedd::register_serial_portandirq:"
443                                         " Error: Illegal irq %x\n", irq );
444                         return -1;
445         } /* switch */
446         /* irq is okay */
447
448         memset(&serial, 0, sizeof(serial));
449         serial.port = port;
450         serial.irq = irq;
451         serial.flags = ASYNC_SHARE_IRQ;
452
453         return register_serial(&serial);
454 }
455
456
457 static struct file_operations mwave_fops = {
458         .owner          = THIS_MODULE,
459         .read           = mwave_read,
460         .write          = mwave_write,
461         .ioctl          = mwave_ioctl,
462         .open           = mwave_open,
463         .release        = mwave_close
464 };
465
466
467 static struct miscdevice mwave_misc_dev = { MWAVE_MINOR, "mwave", &mwave_fops };
468
469 #if 0 /* totally b0rked */
470 /*
471  * sysfs support <paulsch@us.ibm.com>
472  */
473
474 struct device mwave_device;
475
476 /* Prevent code redundancy, create a macro for mwave_show_* functions. */
477 #define mwave_show_function(attr_name, format_string, field)            \
478 static ssize_t mwave_show_##attr_name(struct device *dev, char *buf)    \
479 {                                                                       \
480         DSP_3780I_CONFIG_SETTINGS *pSettings =                          \
481                 &mwave_s_mdd.rBDData.rDspSettings;                      \
482         return sprintf(buf, format_string, pSettings->field);           \
483 }
484
485 /* All of our attributes are read attributes. */
486 #define mwave_dev_rd_attr(attr_name, format_string, field)              \
487         mwave_show_function(attr_name, format_string, field)            \
488 static DEVICE_ATTR(attr_name, S_IRUGO, mwave_show_##attr_name, NULL)
489
490 mwave_dev_rd_attr (3780i_dma, "%i\n", usDspDma);
491 mwave_dev_rd_attr (3780i_irq, "%i\n", usDspIrq);
492 mwave_dev_rd_attr (3780i_io, "%#.4x\n", usDspBaseIO);
493 mwave_dev_rd_attr (uart_irq, "%i\n", usUartIrq);
494 mwave_dev_rd_attr (uart_io, "%#.4x\n", usUartBaseIO);
495
496 static struct device_attribute * const mwave_dev_attrs[] = {
497         &dev_attr_3780i_dma,
498         &dev_attr_3780i_irq,
499         &dev_attr_3780i_io,
500         &dev_attr_uart_irq,
501         &dev_attr_uart_io,
502 };
503 #endif
504
505 /*
506 * mwave_init is called on module load
507 *
508 * mwave_exit is called on module unload
509 * mwave_exit is also used to clean up after an aborted mwave_init
510 */
511 static void mwave_exit(void)
512 {
513         pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
514
515         PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_exit entry\n");
516
517 #if 0
518         for (i = 0; i < pDrvData->nr_registered_attrs; i++)
519                 device_remove_file(&mwave_device, mwave_dev_attrs[i]);
520         pDrvData->nr_registered_attrs = 0;
521
522         if (pDrvData->device_registered) {
523                 device_unregister(&mwave_device);
524                 pDrvData->device_registered = FALSE;
525         }
526 #endif
527
528         if ( pDrvData->sLine >= 0 ) {
529                 unregister_serial(pDrvData->sLine);
530         }
531         if (pDrvData->bMwaveDevRegistered) {
532                 misc_deregister(&mwave_misc_dev);
533         }
534         if (pDrvData->bDSPEnabled) {
535                 tp3780I_DisableDSP(&pDrvData->rBDData);
536         }
537         if (pDrvData->bResourcesClaimed) {
538                 tp3780I_ReleaseResources(&pDrvData->rBDData);
539         }
540         if (pDrvData->bBDInitialized) {
541                 tp3780I_Cleanup(&pDrvData->rBDData);
542         }
543
544         PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_exit exit\n");
545 }
546
547 module_exit(mwave_exit);
548
549 static int __init mwave_init(void)
550 {
551         int i;
552         int retval = 0;
553         pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
554
555         PRINTK_1(TRACE_MWAVE, "mwavedd::mwave_init entry\n");
556
557         memset(&mwave_s_mdd, 0, sizeof(MWAVE_DEVICE_DATA));
558
559         pDrvData->bBDInitialized = FALSE;
560         pDrvData->bResourcesClaimed = FALSE;
561         pDrvData->bDSPEnabled = FALSE;
562         pDrvData->bDSPReset = FALSE;
563         pDrvData->bMwaveDevRegistered = FALSE;
564         pDrvData->sLine = -1;
565
566         for (i = 0; i < ARRAY_SIZE(pDrvData->IPCs); i++) {
567                 pDrvData->IPCs[i].bIsEnabled = FALSE;
568                 pDrvData->IPCs[i].bIsHere = FALSE;
569                 pDrvData->IPCs[i].usIntCount = 0;       /* no ints received yet */
570                 init_waitqueue_head(&pDrvData->IPCs[i].ipc_wait_queue);
571         }
572
573         retval = tp3780I_InitializeBoardData(&pDrvData->rBDData);
574         PRINTK_2(TRACE_MWAVE,
575                 "mwavedd::mwave_init, return from tp3780I_InitializeBoardData"
576                 " retval %x\n",
577                 retval);
578         if (retval) {
579                 PRINTK_ERROR(KERN_ERR_MWAVE
580                                 "mwavedd::mwave_init: Error:"
581                                 " Failed to initialize board data\n");
582                 goto cleanup_error;
583         }
584         pDrvData->bBDInitialized = TRUE;
585
586         retval = tp3780I_CalcResources(&pDrvData->rBDData);
587         PRINTK_2(TRACE_MWAVE,
588                 "mwavedd::mwave_init, return from tp3780I_CalcResources"
589                 " retval %x\n",
590                 retval);
591         if (retval) {
592                 PRINTK_ERROR(KERN_ERR_MWAVE
593                                 "mwavedd:mwave_init: Error:"
594                                 " Failed to calculate resources\n");
595                 goto cleanup_error;
596         }
597
598         retval = tp3780I_ClaimResources(&pDrvData->rBDData);
599         PRINTK_2(TRACE_MWAVE,
600                 "mwavedd::mwave_init, return from tp3780I_ClaimResources"
601                 " retval %x\n",
602                 retval);
603         if (retval) {
604                 PRINTK_ERROR(KERN_ERR_MWAVE
605                                 "mwavedd:mwave_init: Error:"
606                                 " Failed to claim resources\n");
607                 goto cleanup_error;
608         }
609         pDrvData->bResourcesClaimed = TRUE;
610
611         retval = tp3780I_EnableDSP(&pDrvData->rBDData);
612         PRINTK_2(TRACE_MWAVE,
613                 "mwavedd::mwave_init, return from tp3780I_EnableDSP"
614                 " retval %x\n",
615                 retval);
616         if (retval) {
617                 PRINTK_ERROR(KERN_ERR_MWAVE
618                                 "mwavedd:mwave_init: Error:"
619                                 " Failed to enable DSP\n");
620                 goto cleanup_error;
621         }
622         pDrvData->bDSPEnabled = TRUE;
623
624         if (misc_register(&mwave_misc_dev) < 0) {
625                 PRINTK_ERROR(KERN_ERR_MWAVE
626                                 "mwavedd:mwave_init: Error:"
627                                 " Failed to register misc device\n");
628                 goto cleanup_error;
629         }
630         pDrvData->bMwaveDevRegistered = TRUE;
631
632         pDrvData->sLine = register_serial_portandirq(
633                 pDrvData->rBDData.rDspSettings.usUartBaseIO,
634                 pDrvData->rBDData.rDspSettings.usUartIrq
635         );
636         if (pDrvData->sLine < 0) {
637                 PRINTK_ERROR(KERN_ERR_MWAVE
638                                 "mwavedd:mwave_init: Error:"
639                                 " Failed to register serial driver\n");
640                 goto cleanup_error;
641         }
642         /* uart is registered */
643
644 #if 0
645         /* sysfs */
646         memset(&mwave_device, 0, sizeof (struct device));
647         snprintf(mwave_device.bus_id, BUS_ID_SIZE, "mwave");
648
649         if (device_register(&mwave_device))
650                 goto cleanup_error;
651         pDrvData->device_registered = TRUE;
652         for (i = 0; i < ARRAY_SIZE(mwave_dev_attrs); i++) {
653                 if(device_create_file(&mwave_device, mwave_dev_attrs[i])) {
654                         PRINTK_ERROR(KERN_ERR_MWAVE
655                                         "mwavedd:mwave_init: Error:"
656                                         " Failed to create sysfs file %s\n",
657                                         mwave_dev_attrs[i]->attr.name);
658                         goto cleanup_error;
659                 }
660                 pDrvData->nr_registered_attrs++;
661         }
662 #endif
663
664         /* SUCCESS! */
665         return 0;
666
667 cleanup_error:
668         PRINTK_ERROR(KERN_ERR_MWAVE
669                         "mwavedd::mwave_init: Error:"
670                         " Failed to initialize\n");
671         mwave_exit(); /* clean up */
672
673         return -EIO;
674 }
675
676 module_init(mwave_init);
677