mwavedd.c 19 KB

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