mwavedd.c 18 KB

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