mwavedd.c 18 KB

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