mwavedd.c 18 KB

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