tnt4882_init.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /***************************************************************************
  2. nec7210/tnt4882_init.c - description
  3. -------------------
  4. board specific initialization stuff for National Instruments boards
  5. using tnt4882 or compatible chips (at-gpib, etc).
  6. begin : Dec 2001
  7. copyright : (C) 2001, 2002 by Frank Mori Hess
  8. email : fmhess@users.sourceforge.net
  9. ***************************************************************************/
  10. /***************************************************************************
  11. * *
  12. * This program is free software; you can redistribute it and/or modify *
  13. * it under the terms of the GNU General Public License as published by *
  14. * the Free Software Foundation; either version 2 of the License, or *
  15. * (at your option) any later version. *
  16. * *
  17. ***************************************************************************/
  18. #include "tnt4882.h"
  19. #include <linux/ioport.h>
  20. #include <linux/sched.h>
  21. #include <linux/module.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <linux/pci_ids.h>
  25. #include <linux/string.h>
  26. #include <linux/init.h>
  27. MODULE_LICENSE("GPL");
  28. int ni_tnt_isa_attach( gpib_board_t *board, gpib_board_config_t config );
  29. int ni_nat4882_isa_attach( gpib_board_t *board, gpib_board_config_t config );
  30. int ni_nec_isa_attach( gpib_board_t *board, gpib_board_config_t config );
  31. int ni_pci_attach(gpib_board_t *board, gpib_board_config_t config);
  32. void ni_isa_detach(gpib_board_t *board);
  33. void ni_pci_detach(gpib_board_t *board);
  34. // wrappers for interface functions
  35. int tnt4882_read(gpib_board_t *board, uint8_t *buffer, size_t length, int *end, size_t *bytes_read)
  36. {
  37. tnt4882_private_t *priv = board->private_data;
  38. nec7210_private_t *nec_priv = &priv->nec7210_priv;
  39. int retval;
  40. int dummy;
  41. retval = nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read);
  42. if( retval < 0 )
  43. { // force immediate holdoff
  44. write_byte( nec_priv, AUX_HLDI, AUXMR );
  45. set_bit( RFD_HOLDOFF_BN, &nec_priv->state );
  46. nec7210_read_data_in( board, nec_priv, &dummy );
  47. }
  48. return retval;
  49. }
  50. int tnt4882_write(gpib_board_t *board, uint8_t *buffer, size_t length, int send_eoi, size_t *bytes_written)
  51. {
  52. tnt4882_private_t *priv = board->private_data;
  53. return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written);
  54. }
  55. ssize_t tnt4882_command_unaccel(gpib_board_t *board, uint8_t *buffer, size_t length)
  56. {
  57. tnt4882_private_t *priv = board->private_data;
  58. return nec7210_command(board, &priv->nec7210_priv, buffer, length);
  59. }
  60. int tnt4882_take_control(gpib_board_t *board, int synchronous)
  61. {
  62. tnt4882_private_t *priv = board->private_data;
  63. return nec7210_take_control(board, &priv->nec7210_priv, synchronous);
  64. }
  65. int tnt4882_go_to_standby(gpib_board_t *board)
  66. {
  67. tnt4882_private_t *priv = board->private_data;
  68. return nec7210_go_to_standby(board, &priv->nec7210_priv);
  69. }
  70. void tnt4882_request_system_control( gpib_board_t *board, int request_control )
  71. {
  72. tnt4882_private_t *priv = board->private_data;
  73. if(request_control)
  74. {
  75. tnt_writeb( priv, SETSC, CMDR );
  76. udelay(1);
  77. }
  78. nec7210_request_system_control( board, &priv->nec7210_priv, request_control );
  79. if(!request_control)
  80. {
  81. tnt_writeb( priv, CLRSC, CMDR );
  82. udelay(1);
  83. }
  84. }
  85. void tnt4882_interface_clear(gpib_board_t *board, int assert)
  86. {
  87. tnt4882_private_t *priv = board->private_data;
  88. nec7210_interface_clear(board, &priv->nec7210_priv, assert);
  89. }
  90. void tnt4882_remote_enable(gpib_board_t *board, int enable)
  91. {
  92. tnt4882_private_t *priv = board->private_data;
  93. nec7210_remote_enable(board, &priv->nec7210_priv, enable);
  94. }
  95. int tnt4882_enable_eos(gpib_board_t *board, uint8_t eos_byte, int compare_8_bits)
  96. {
  97. tnt4882_private_t *priv = board->private_data;
  98. return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits);
  99. }
  100. void tnt4882_disable_eos(gpib_board_t *board)
  101. {
  102. tnt4882_private_t *priv = board->private_data;
  103. nec7210_disable_eos(board, &priv->nec7210_priv);
  104. }
  105. unsigned int tnt4882_update_status( gpib_board_t *board, unsigned int clear_mask )
  106. {
  107. tnt4882_private_t *priv = board->private_data;
  108. return nec7210_update_status( board, &priv->nec7210_priv, clear_mask );
  109. }
  110. void tnt4882_primary_address(gpib_board_t *board, unsigned int address)
  111. {
  112. tnt4882_private_t *priv = board->private_data;
  113. nec7210_primary_address(board, &priv->nec7210_priv, address);
  114. }
  115. void tnt4882_secondary_address(gpib_board_t *board, unsigned int address, int enable)
  116. {
  117. tnt4882_private_t *priv = board->private_data;
  118. nec7210_secondary_address(board, &priv->nec7210_priv, address, enable);
  119. }
  120. int tnt4882_parallel_poll(gpib_board_t *board, uint8_t *result)
  121. {
  122. tnt4882_private_t *tnt_priv = board->private_data;
  123. if(tnt_priv->nec7210_priv.type != NEC7210)
  124. {
  125. tnt_priv->auxg_bits |= RPP2_BIT;
  126. write_byte(&tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR);
  127. udelay(2); //FIXME use parallel poll timeout
  128. *result = read_byte(&tnt_priv->nec7210_priv, CPTR);
  129. tnt_priv->auxg_bits &= ~RPP2_BIT;
  130. write_byte(&tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR);
  131. return 0;
  132. }else
  133. {
  134. return nec7210_parallel_poll(board, &tnt_priv->nec7210_priv, result);
  135. }
  136. }
  137. void tnt4882_parallel_poll_configure(gpib_board_t *board, uint8_t config )
  138. {
  139. tnt4882_private_t *priv = board->private_data;
  140. nec7210_parallel_poll_configure( board, &priv->nec7210_priv, config );
  141. }
  142. void tnt4882_parallel_poll_response(gpib_board_t *board, int ist )
  143. {
  144. tnt4882_private_t *priv = board->private_data;
  145. nec7210_parallel_poll_response( board, &priv->nec7210_priv, ist );
  146. }
  147. // XXX tnt4882 has fancier serial poll capability, should send reqt AUX command
  148. void tnt4882_serial_poll_response(gpib_board_t *board, uint8_t status)
  149. {
  150. tnt4882_private_t *priv = board->private_data;
  151. nec7210_serial_poll_response(board, &priv->nec7210_priv, status);
  152. }
  153. uint8_t tnt4882_serial_poll_status( gpib_board_t *board )
  154. {
  155. tnt4882_private_t *priv = board->private_data;
  156. return nec7210_serial_poll_status( board, &priv->nec7210_priv );
  157. }
  158. void tnt4882_return_to_local( gpib_board_t *board )
  159. {
  160. tnt4882_private_t *priv = board->private_data;
  161. nec7210_return_to_local( board, &priv->nec7210_priv );
  162. }
  163. gpib_interface_t ni_pci_interface =
  164. {
  165. name: "ni_pci",
  166. attach: ni_pci_attach,
  167. detach: ni_pci_detach,
  168. read: tnt4882_accel_read,
  169. write: tnt4882_accel_write,
  170. command: tnt4882_command,
  171. take_control: tnt4882_take_control,
  172. go_to_standby: tnt4882_go_to_standby,
  173. request_system_control: tnt4882_request_system_control,
  174. interface_clear: tnt4882_interface_clear,
  175. remote_enable: tnt4882_remote_enable,
  176. enable_eos: tnt4882_enable_eos,
  177. disable_eos: tnt4882_disable_eos,
  178. parallel_poll: tnt4882_parallel_poll,
  179. parallel_poll_configure: tnt4882_parallel_poll_configure,
  180. parallel_poll_response: tnt4882_parallel_poll_response,
  181. line_status: tnt4882_line_status,
  182. update_status: tnt4882_update_status,
  183. primary_address: tnt4882_primary_address,
  184. secondary_address: tnt4882_secondary_address,
  185. serial_poll_response: tnt4882_serial_poll_response,
  186. serial_poll_status: tnt4882_serial_poll_status,
  187. t1_delay: tnt4882_t1_delay,
  188. return_to_local: tnt4882_return_to_local,
  189. };
  190. gpib_interface_t ni_pci_accel_interface =
  191. {
  192. name: "ni_pci_accel",
  193. attach: ni_pci_attach,
  194. detach: ni_pci_detach,
  195. read: tnt4882_accel_read,
  196. write: tnt4882_accel_write,
  197. command: tnt4882_command,
  198. take_control: tnt4882_take_control,
  199. go_to_standby: tnt4882_go_to_standby,
  200. request_system_control: tnt4882_request_system_control,
  201. interface_clear: tnt4882_interface_clear,
  202. remote_enable: tnt4882_remote_enable,
  203. enable_eos: tnt4882_enable_eos,
  204. disable_eos: tnt4882_disable_eos,
  205. parallel_poll: tnt4882_parallel_poll,
  206. parallel_poll_configure: tnt4882_parallel_poll_configure,
  207. parallel_poll_response: tnt4882_parallel_poll_response,
  208. line_status: tnt4882_line_status,
  209. update_status: tnt4882_update_status,
  210. primary_address: tnt4882_primary_address,
  211. secondary_address: tnt4882_secondary_address,
  212. serial_poll_response: tnt4882_serial_poll_response,
  213. serial_poll_status: tnt4882_serial_poll_status,
  214. t1_delay: tnt4882_t1_delay,
  215. return_to_local: tnt4882_return_to_local,
  216. };
  217. gpib_interface_t ni_isa_interface =
  218. {
  219. name: "ni_isa",
  220. attach: ni_tnt_isa_attach,
  221. detach: ni_isa_detach,
  222. read: tnt4882_accel_read,
  223. write: tnt4882_accel_write,
  224. command: tnt4882_command,
  225. take_control: tnt4882_take_control,
  226. go_to_standby: tnt4882_go_to_standby,
  227. request_system_control: tnt4882_request_system_control,
  228. interface_clear: tnt4882_interface_clear,
  229. remote_enable: tnt4882_remote_enable,
  230. enable_eos: tnt4882_enable_eos,
  231. disable_eos: tnt4882_disable_eos,
  232. parallel_poll: tnt4882_parallel_poll,
  233. parallel_poll_configure: tnt4882_parallel_poll_configure,
  234. parallel_poll_response: tnt4882_parallel_poll_response,
  235. line_status: tnt4882_line_status,
  236. update_status: tnt4882_update_status,
  237. primary_address: tnt4882_primary_address,
  238. secondary_address: tnt4882_secondary_address,
  239. serial_poll_response: tnt4882_serial_poll_response,
  240. serial_poll_status: tnt4882_serial_poll_status,
  241. t1_delay: tnt4882_t1_delay,
  242. return_to_local: tnt4882_return_to_local,
  243. };
  244. gpib_interface_t ni_nat4882_isa_interface =
  245. {
  246. name: "ni_nat4882_isa",
  247. attach: ni_nat4882_isa_attach,
  248. detach: ni_isa_detach,
  249. read: tnt4882_read,
  250. write: tnt4882_write,
  251. command: tnt4882_command_unaccel,
  252. take_control: tnt4882_take_control,
  253. go_to_standby: tnt4882_go_to_standby,
  254. request_system_control: tnt4882_request_system_control,
  255. interface_clear: tnt4882_interface_clear,
  256. remote_enable: tnt4882_remote_enable,
  257. enable_eos: tnt4882_enable_eos,
  258. disable_eos: tnt4882_disable_eos,
  259. parallel_poll: tnt4882_parallel_poll,
  260. parallel_poll_configure: tnt4882_parallel_poll_configure,
  261. parallel_poll_response: tnt4882_parallel_poll_response,
  262. line_status: tnt4882_line_status,
  263. update_status: tnt4882_update_status,
  264. primary_address: tnt4882_primary_address,
  265. secondary_address: tnt4882_secondary_address,
  266. serial_poll_response: tnt4882_serial_poll_response,
  267. serial_poll_status: tnt4882_serial_poll_status,
  268. t1_delay: tnt4882_t1_delay,
  269. return_to_local: tnt4882_return_to_local,
  270. };
  271. gpib_interface_t ni_nec_isa_interface =
  272. {
  273. name: "ni_nec_isa",
  274. attach: ni_nec_isa_attach,
  275. detach: ni_isa_detach,
  276. read: tnt4882_read,
  277. write: tnt4882_write,
  278. command: tnt4882_command_unaccel,
  279. take_control: tnt4882_take_control,
  280. go_to_standby: tnt4882_go_to_standby,
  281. request_system_control: tnt4882_request_system_control,
  282. interface_clear: tnt4882_interface_clear,
  283. remote_enable: tnt4882_remote_enable,
  284. enable_eos: tnt4882_enable_eos,
  285. disable_eos: tnt4882_disable_eos,
  286. parallel_poll: tnt4882_parallel_poll,
  287. parallel_poll_configure: tnt4882_parallel_poll_configure,
  288. parallel_poll_response: tnt4882_parallel_poll_response,
  289. line_status: NULL,
  290. update_status: tnt4882_update_status,
  291. primary_address: tnt4882_primary_address,
  292. secondary_address: tnt4882_secondary_address,
  293. serial_poll_response: tnt4882_serial_poll_response,
  294. serial_poll_status: tnt4882_serial_poll_status,
  295. t1_delay: tnt4882_t1_delay,
  296. return_to_local: tnt4882_return_to_local,
  297. };
  298. gpib_interface_t ni_isa_accel_interface =
  299. {
  300. name: "ni_isa_accel",
  301. attach: ni_tnt_isa_attach,
  302. detach: ni_isa_detach,
  303. read: tnt4882_accel_read,
  304. write: tnt4882_accel_write,
  305. command: tnt4882_command,
  306. take_control: tnt4882_take_control,
  307. go_to_standby: tnt4882_go_to_standby,
  308. request_system_control: tnt4882_request_system_control,
  309. interface_clear: tnt4882_interface_clear,
  310. remote_enable: tnt4882_remote_enable,
  311. enable_eos: tnt4882_enable_eos,
  312. disable_eos: tnt4882_disable_eos,
  313. parallel_poll: tnt4882_parallel_poll,
  314. parallel_poll_configure: tnt4882_parallel_poll_configure,
  315. parallel_poll_response: tnt4882_parallel_poll_response,
  316. line_status: tnt4882_line_status,
  317. update_status: tnt4882_update_status,
  318. primary_address: tnt4882_primary_address,
  319. secondary_address: tnt4882_secondary_address,
  320. serial_poll_response: tnt4882_serial_poll_response,
  321. serial_poll_status: tnt4882_serial_poll_status,
  322. t1_delay: tnt4882_t1_delay,
  323. return_to_local: tnt4882_return_to_local,
  324. };
  325. gpib_interface_t ni_nat4882_isa_accel_interface =
  326. {
  327. name: "ni_nat4882_isa_accel",
  328. attach: ni_nat4882_isa_attach,
  329. detach: ni_isa_detach,
  330. read: tnt4882_accel_read,
  331. write: tnt4882_accel_write,
  332. command: tnt4882_command_unaccel,
  333. take_control: tnt4882_take_control,
  334. go_to_standby: tnt4882_go_to_standby,
  335. request_system_control: tnt4882_request_system_control,
  336. interface_clear: tnt4882_interface_clear,
  337. remote_enable: tnt4882_remote_enable,
  338. enable_eos: tnt4882_enable_eos,
  339. disable_eos: tnt4882_disable_eos,
  340. parallel_poll: tnt4882_parallel_poll,
  341. parallel_poll_configure: tnt4882_parallel_poll_configure,
  342. parallel_poll_response: tnt4882_parallel_poll_response,
  343. line_status: tnt4882_line_status,
  344. update_status: tnt4882_update_status,
  345. primary_address: tnt4882_primary_address,
  346. secondary_address: tnt4882_secondary_address,
  347. serial_poll_response: tnt4882_serial_poll_response,
  348. serial_poll_status: tnt4882_serial_poll_status,
  349. t1_delay: tnt4882_t1_delay,
  350. return_to_local: tnt4882_return_to_local,
  351. };
  352. gpib_interface_t ni_nec_isa_accel_interface =
  353. {
  354. name: "ni_nec_isa_accel",
  355. attach: ni_nec_isa_attach,
  356. detach: ni_isa_detach,
  357. read: tnt4882_accel_read,
  358. write: tnt4882_accel_write,
  359. command: tnt4882_command_unaccel,
  360. take_control: tnt4882_take_control,
  361. go_to_standby: tnt4882_go_to_standby,
  362. request_system_control: tnt4882_request_system_control,
  363. interface_clear: tnt4882_interface_clear,
  364. remote_enable: tnt4882_remote_enable,
  365. enable_eos: tnt4882_enable_eos,
  366. disable_eos: tnt4882_disable_eos,
  367. parallel_poll: tnt4882_parallel_poll,
  368. parallel_poll_configure: tnt4882_parallel_poll_configure,
  369. parallel_poll_response: tnt4882_parallel_poll_response,
  370. line_status: NULL,
  371. update_status: tnt4882_update_status,
  372. primary_address: tnt4882_primary_address,
  373. secondary_address: tnt4882_secondary_address,
  374. serial_poll_response: tnt4882_serial_poll_response,
  375. serial_poll_status: tnt4882_serial_poll_status,
  376. t1_delay: tnt4882_t1_delay,
  377. return_to_local: tnt4882_return_to_local,
  378. };
  379. void tnt4882_board_reset( tnt4882_private_t *tnt_priv, gpib_board_t *board )
  380. {
  381. nec7210_private_t *nec_priv = &tnt_priv->nec7210_priv;
  382. tnt_priv->imr0_bits = 0;
  383. tnt_writeb( tnt_priv, tnt_priv->imr0_bits, IMR0 );
  384. tnt_priv->imr3_bits = 0;
  385. tnt_writeb( tnt_priv, tnt_priv->imr3_bits, IMR3 );
  386. tnt_readb( tnt_priv, IMR0 );
  387. tnt_readb( tnt_priv, IMR3 );
  388. nec7210_board_reset( nec_priv, board );
  389. }
  390. int tnt4882_allocate_private(gpib_board_t *board)
  391. {
  392. tnt4882_private_t *tnt_priv;
  393. board->private_data = kmalloc(sizeof(tnt4882_private_t), GFP_KERNEL);
  394. if(board->private_data == NULL)
  395. return -1;
  396. tnt_priv = board->private_data;
  397. memset(tnt_priv, 0, sizeof(tnt4882_private_t));
  398. init_nec7210_private( &tnt_priv->nec7210_priv );
  399. return 0;
  400. }
  401. void tnt4882_free_private(gpib_board_t *board)
  402. {
  403. if(board->private_data)
  404. {
  405. kfree(board->private_data);
  406. board->private_data = NULL;
  407. }
  408. }
  409. void tnt4882_init( tnt4882_private_t *tnt_priv, const gpib_board_t *board )
  410. {
  411. nec7210_private_t *nec_priv = &tnt_priv->nec7210_priv;
  412. /* Turbo488 software reset */
  413. tnt_writeb( tnt_priv, SOFT_RESET, CMDR );
  414. udelay(1);
  415. // turn off one-chip mode
  416. tnt_writeb( tnt_priv, NODMA, HSSEL );
  417. tnt_writeb( tnt_priv, 0, ACCWR );
  418. // make sure we are in 7210 mode
  419. tnt_writeb( tnt_priv,AUX_7210, AUXCR);
  420. udelay(1);
  421. // registers might be swapped, so write it to the swapped address too
  422. tnt_writeb( tnt_priv,AUX_7210, SWAPPED_AUXCR);
  423. udelay(1);
  424. // turn on one-chip mode
  425. if( nec_priv->type == TNT4882 )
  426. tnt_writeb(tnt_priv, NODMA | TNT_ONE_CHIP_BIT, HSSEL);
  427. else
  428. tnt_writeb(tnt_priv, NODMA, HSSEL);
  429. nec7210_board_reset( nec_priv, board );
  430. // read-clear isr0
  431. tnt_readb( tnt_priv, ISR0 );
  432. // enable passing of nat4882 interrupts
  433. tnt_priv->imr3_bits = HR_TLCI;
  434. tnt_writeb( tnt_priv, tnt_priv->imr3_bits, IMR3 );
  435. // enable interrupt
  436. tnt_writeb( tnt_priv, 0x1, INTRT );
  437. // force immediate holdoff
  438. write_byte( &tnt_priv->nec7210_priv, AUX_HLDI, AUXMR );
  439. set_bit( RFD_HOLDOFF_BN, &nec_priv->state );
  440. tnt_priv->auxg_bits = AUXRG | NTNL_BIT;
  441. write_byte( &tnt_priv->nec7210_priv, tnt_priv->auxg_bits, AUXMR );
  442. nec7210_board_online( nec_priv, board );
  443. // enable interface clear interrupt for event queue
  444. tnt_priv->imr0_bits = TNT_IMR0_ALWAYS_BITS | TNT_ATNI_BIT | TNT_IFCIE_BIT;
  445. tnt_writeb( tnt_priv, tnt_priv->imr0_bits, IMR0 );
  446. }
  447. int ni_pci_attach(gpib_board_t *board, gpib_board_config_t config)
  448. {
  449. tnt4882_private_t *tnt_priv;
  450. nec7210_private_t *nec_priv;
  451. int isr_flags = IRQF_SHARED;
  452. int retval;
  453. struct mite_struct *mite;
  454. board->status = 0;
  455. if(tnt4882_allocate_private(board))
  456. return -ENOMEM;
  457. tnt_priv = board->private_data;
  458. tnt_priv->io_writeb = writeb_wrapper;
  459. tnt_priv->io_readb = readb_wrapper;
  460. tnt_priv->io_writew = writew_wrapper;
  461. tnt_priv->io_readw = readw_wrapper;
  462. nec_priv = &tnt_priv->nec7210_priv;
  463. nec_priv->type = TNT4882;
  464. nec_priv->read_byte = nec7210_locking_iomem_read_byte;
  465. nec_priv->write_byte = nec7210_locking_iomem_write_byte;
  466. nec_priv->offset = atgpib_reg_offset;
  467. if(mite_devices == NULL)
  468. {
  469. printk("no National Instruments PCI boards found\n");
  470. return -1;
  471. }
  472. for(mite = mite_devices; mite; mite = mite->next)
  473. {
  474. short found_board;
  475. if(mite->used) continue;
  476. if( board->pci_bus >=0 && board->pci_bus !=
  477. mite->pcidev->bus->number )
  478. continue;
  479. if( board->pci_slot >= 0 && board->pci_slot !=
  480. PCI_SLOT(mite->pcidev->devfn))
  481. continue;
  482. switch(mite_device_id(mite))
  483. {
  484. case PCI_DEVICE_ID_NI_GPIB:
  485. case PCI_DEVICE_ID_NI_GPIB_PLUS:
  486. case PCI_DEVICE_ID_NI_PXIGPIB:
  487. case PCI_DEVICE_ID_NI_PMCGPIB:
  488. case PCI_DEVICE_ID_NI_PCIEGPIB:
  489. found_board = 1;
  490. break;
  491. default:
  492. found_board = 0;
  493. break;
  494. }
  495. if(found_board) break;
  496. }
  497. if(mite == NULL)
  498. {
  499. printk("no NI PCI-GPIB boards found\n");
  500. return -1;
  501. }
  502. tnt_priv->mite = mite;
  503. retval = mite_setup(tnt_priv->mite);
  504. if(retval < 0)
  505. {
  506. printk("tnt4882: error setting up mite.\n");
  507. return retval;
  508. }
  509. nec_priv->iobase = tnt_priv->mite->daq_io_addr;
  510. // get irq
  511. if(request_irq(mite_irq(tnt_priv->mite), tnt4882_interrupt, isr_flags, "ni-pci-gpib", board))
  512. {
  513. printk("gpib: can't request IRQ %d\n", mite_irq( tnt_priv->mite ) );
  514. return -1;
  515. }
  516. tnt_priv->irq = mite_irq(tnt_priv->mite);
  517. printk( "tnt4882: irq %i\n", tnt_priv->irq );
  518. tnt4882_init( tnt_priv, board );
  519. return 0;
  520. }
  521. void ni_pci_detach(gpib_board_t *board)
  522. {
  523. tnt4882_private_t *tnt_priv = board->private_data;
  524. nec7210_private_t *nec_priv;
  525. if(tnt_priv)
  526. {
  527. nec_priv = &tnt_priv->nec7210_priv;
  528. if(nec_priv->iobase)
  529. {
  530. tnt4882_board_reset( tnt_priv, board );
  531. }
  532. if(tnt_priv->irq)
  533. {
  534. free_irq(tnt_priv->irq, board);
  535. }
  536. if(tnt_priv->mite)
  537. {
  538. mite_unsetup(tnt_priv->mite);
  539. }
  540. }
  541. tnt4882_free_private(board);
  542. }
  543. int ni_isapnp_find( struct pnp_dev **dev )
  544. {
  545. *dev = pnp_find_dev( NULL, ISAPNP_VENDOR_ID_NI,
  546. ISAPNP_FUNCTION( ISAPNP_ID_NI_ATGPIB_TNT ), NULL );
  547. if(*dev == NULL || (*dev)->card == NULL)
  548. {
  549. printk( "tnt4882: failed to find isapnp board\n" );
  550. return -ENODEV;
  551. }
  552. if(pnp_device_attach(*dev) < 0)
  553. {
  554. printk( "tnt4882: atgpib/tnt board already active, skipping\n" );
  555. return -EBUSY;
  556. }
  557. if(pnp_activate_dev(*dev) < 0 )
  558. {
  559. pnp_device_detach(*dev);
  560. printk( "tnt4882: failed to activate() atgpib/tnt, aborting\n" );
  561. return -EAGAIN;
  562. }
  563. if(!pnp_port_valid(*dev, 0) || !pnp_irq_valid(*dev, 0))
  564. {
  565. pnp_device_detach(*dev);
  566. printk( "tnt4882: invalid port or irq for atgpib/tnt, aborting\n" );
  567. return -ENOMEM;
  568. }
  569. return 0;
  570. }
  571. int ni_isa_attach_common( gpib_board_t *board, enum nec7210_chipset chipset )
  572. {
  573. tnt4882_private_t *tnt_priv;
  574. nec7210_private_t *nec_priv;
  575. int isr_flags = 0;
  576. void *iobase;
  577. board->status = 0;
  578. if(tnt4882_allocate_private(board))
  579. return -ENOMEM;
  580. tnt_priv = board->private_data;
  581. tnt_priv->io_writeb = outb_wrapper;
  582. tnt_priv->io_readb = inb_wrapper;
  583. tnt_priv->io_writew = outw_wrapper;
  584. tnt_priv->io_readw = inw_wrapper;
  585. nec_priv = &tnt_priv->nec7210_priv;
  586. nec_priv->type = chipset;
  587. nec_priv->read_byte = nec7210_locking_ioport_read_byte;
  588. nec_priv->write_byte = nec7210_locking_ioport_write_byte;
  589. nec_priv->offset = atgpib_reg_offset;
  590. // look for plug-n-play board
  591. if( board->ibbase == 0 )
  592. {
  593. struct pnp_dev *dev;
  594. int retval;
  595. retval = ni_isapnp_find( &dev );
  596. if( retval < 0 ) return retval;
  597. tnt_priv->pnp_dev = dev;
  598. iobase = (void*)(pnp_port_start(dev, 0));
  599. board->ibirq = pnp_irq(dev, 0);
  600. }else
  601. iobase = board->ibbase;
  602. // allocate ioports
  603. if(request_region((unsigned long)(iobase), atgpib_iosize, "atgpib") == NULL)
  604. {
  605. printk("tnt4882: failed to allocate ioports\n");
  606. return -1;
  607. }
  608. nec_priv->iobase = iobase;
  609. // get irq
  610. if(request_irq(board->ibirq, tnt4882_interrupt, isr_flags, "atgpib", board))
  611. {
  612. printk("gpib: can't request IRQ %d\n", board->ibirq);
  613. return -1;
  614. }
  615. tnt_priv->irq = board->ibirq;
  616. tnt4882_init( tnt_priv, board );
  617. return 0;
  618. }
  619. int ni_tnt_isa_attach( gpib_board_t *board, gpib_board_config_t config )
  620. {
  621. return ni_isa_attach_common( board, TNT4882 );
  622. }
  623. int ni_nat4882_isa_attach( gpib_board_t *board, gpib_board_config_t config )
  624. {
  625. return ni_isa_attach_common( board, NAT4882 );
  626. }
  627. int ni_nec_isa_attach( gpib_board_t *board, gpib_board_config_t config )
  628. {
  629. return ni_isa_attach_common( board, NEC7210 );
  630. }
  631. void ni_isa_detach(gpib_board_t *board)
  632. {
  633. tnt4882_private_t *tnt_priv = board->private_data;
  634. nec7210_private_t *nec_priv;
  635. if(tnt_priv)
  636. {
  637. nec_priv = &tnt_priv->nec7210_priv;
  638. if(nec_priv->iobase)
  639. {
  640. tnt4882_board_reset( tnt_priv, board );
  641. }
  642. if( tnt_priv->irq )
  643. {
  644. free_irq( tnt_priv->irq, board );
  645. }
  646. if( nec_priv->iobase )
  647. {
  648. release_region((unsigned long)(nec_priv->iobase), atgpib_iosize);
  649. }
  650. if(tnt_priv->pnp_dev)
  651. {
  652. pnp_device_detach(tnt_priv->pnp_dev);
  653. }
  654. }
  655. tnt4882_free_private(board);
  656. }
  657. static const struct pci_device_id tnt4882_pci_table[] =
  658. {
  659. {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_GPIB)},
  660. {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_GPIB_PLUS)},
  661. {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PXIGPIB)},
  662. {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PMCGPIB)},
  663. {PCI_DEVICE(PCI_VENDOR_ID_NATINST, PCI_DEVICE_ID_NI_PCIEGPIB)},
  664. { 0 }
  665. };
  666. MODULE_DEVICE_TABLE(pci, tnt4882_pci_table);
  667. static const struct pnp_device_id tnt4882_pnp_table[] __devinitdata =
  668. {
  669. {.id = "NICC601"},
  670. {.id = ""}
  671. };
  672. MODULE_DEVICE_TABLE(pnp, tnt4882_pnp_table);
  673. static int __init tnt4882_init_module( void )
  674. {
  675. gpib_register_driver(&ni_isa_interface, THIS_MODULE);
  676. gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE);
  677. gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE);
  678. gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE);
  679. gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE);
  680. gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE);
  681. gpib_register_driver(&ni_pci_interface, THIS_MODULE);
  682. gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE);
  683. #if defined(GPIB_CONFIG_PCMCIA)
  684. gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE);
  685. gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE);
  686. if( init_ni_gpib_cs() < 0 )
  687. return -1;
  688. #endif
  689. mite_init();
  690. mite_list_devices();
  691. return 0;
  692. }
  693. static void __exit tnt4882_exit_module( void )
  694. {
  695. gpib_unregister_driver(&ni_isa_interface);
  696. gpib_unregister_driver(&ni_isa_accel_interface);
  697. gpib_unregister_driver(&ni_nat4882_isa_interface);
  698. gpib_unregister_driver(&ni_nat4882_isa_accel_interface);
  699. gpib_unregister_driver(&ni_nec_isa_interface);
  700. gpib_unregister_driver(&ni_nec_isa_accel_interface);
  701. gpib_unregister_driver(&ni_pci_interface);
  702. gpib_unregister_driver(&ni_pci_accel_interface);
  703. #if defined(GPIB_CONFIG_PCMCIA)
  704. gpib_unregister_driver(&ni_pcmcia_interface);
  705. gpib_unregister_driver(&ni_pcmcia_accel_interface);
  706. exit_ni_gpib_cs();
  707. #endif
  708. mite_cleanup();
  709. }
  710. module_init( tnt4882_init_module );
  711. module_exit( tnt4882_exit_module );