mwavedd.c 19 KB

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