cb7210.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  1. // SPDX-License-Identifier: GPL-2.0
  2. /***************************************************************************
  3. * Measurement Computing boards using cb7210.2 and cbi488.2 chips
  4. * copyright : (C) 2001, 2002 by Frank Mori Hess
  5. ***************************************************************************/
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #define dev_fmt pr_fmt
  8. #define DRV_NAME KBUILD_MODNAME
  9. #include "cb7210.h"
  10. #include <linux/ioport.h>
  11. #include <linux/sched.h>
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <asm/dma.h>
  15. #include <linux/bitops.h>
  16. #include <linux/pci.h>
  17. #include <linux/pci_ids.h>
  18. #include <linux/string.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include "gpib_pci_ids.h"
  22. #include "quancom_pci.h"
  23. MODULE_LICENSE("GPL");
  24. MODULE_DESCRIPTION("GPIB driver Measurement Computing boards using cb7210.2 and cbi488.2");
  25. static int cb7210_read(struct gpib_board *board, u8 *buffer, size_t length,
  26. int *end, size_t *bytes_read);
  27. static inline int have_fifo_word(const struct cb7210_priv *cb_priv)
  28. {
  29. if (((cb7210_read_byte(cb_priv, HS_STATUS)) &
  30. (HS_RX_MSB_NOT_EMPTY | HS_RX_LSB_NOT_EMPTY)) ==
  31. (HS_RX_MSB_NOT_EMPTY | HS_RX_LSB_NOT_EMPTY))
  32. return 1;
  33. else
  34. return 0;
  35. }
  36. static inline void input_fifo_enable(struct gpib_board *board, int enable)
  37. {
  38. struct cb7210_priv *cb_priv = board->private_data;
  39. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  40. unsigned long flags;
  41. spin_lock_irqsave(&board->spinlock, flags);
  42. if (enable) {
  43. cb_priv->in_fifo_half_full = 0;
  44. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
  45. cb7210_write_byte(cb_priv, HS_RX_ENABLE | HS_TX_ENABLE | HS_CLR_SRQ_INT |
  46. HS_CLR_EOI_EMPTY_INT | HS_CLR_HF_INT | cb_priv->hs_mode_bits,
  47. HS_MODE);
  48. cb_priv->hs_mode_bits &= ~HS_ENABLE_MASK;
  49. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  50. cb7210_write_byte(cb_priv, irq_bits(cb_priv->irq), HS_INT_LEVEL);
  51. cb_priv->hs_mode_bits |= HS_RX_ENABLE;
  52. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  53. } else {
  54. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
  55. cb_priv->hs_mode_bits &= ~HS_ENABLE_MASK;
  56. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, nec7210_iobase(cb_priv) +
  57. HS_MODE);
  58. clear_bit(READ_READY_BN, &nec_priv->state);
  59. }
  60. spin_unlock_irqrestore(&board->spinlock, flags);
  61. }
  62. static int fifo_read(struct gpib_board *board, struct cb7210_priv *cb_priv, u8 *buffer,
  63. size_t length, int *end, size_t *bytes_read)
  64. {
  65. ssize_t retval = 0;
  66. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  67. int hs_status;
  68. u16 word;
  69. unsigned long flags;
  70. *bytes_read = 0;
  71. if (cb_priv->fifo_iobase == 0) {
  72. dev_err(board->gpib_dev, "fifo iobase is zero!\n");
  73. return -EIO;
  74. }
  75. *end = 0;
  76. if (length <= cb7210_fifo_size) {
  77. dev_err(board->gpib_dev, " bug! fifo read length < fifo size\n");
  78. return -EINVAL;
  79. }
  80. input_fifo_enable(board, 1);
  81. while (*bytes_read + cb7210_fifo_size < length) {
  82. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, HR_DMAI);
  83. if (wait_event_interruptible(board->wait,
  84. (cb_priv->in_fifo_half_full &&
  85. have_fifo_word(cb_priv)) ||
  86. test_bit(RECEIVED_END_BN, &nec_priv->state) ||
  87. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  88. test_bit(TIMO_NUM, &board->status))) {
  89. retval = -ERESTARTSYS;
  90. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
  91. break;
  92. }
  93. spin_lock_irqsave(&board->spinlock, flags);
  94. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAI, 0);
  95. while (have_fifo_word(cb_priv)) {
  96. word = inw(cb_priv->fifo_iobase + DIR);
  97. buffer[(*bytes_read)++] = word & 0xff;
  98. buffer[(*bytes_read)++] = (word >> 8) & 0xff;
  99. }
  100. cb_priv->in_fifo_half_full = 0;
  101. hs_status = cb7210_read_byte(cb_priv, HS_STATUS);
  102. spin_unlock_irqrestore(&board->spinlock, flags);
  103. if (test_and_clear_bit(RECEIVED_END_BN, &nec_priv->state)) {
  104. *end = 1;
  105. break;
  106. }
  107. if (hs_status & HS_FIFO_FULL)
  108. break;
  109. if (test_bit(TIMO_NUM, &board->status)) {
  110. retval = -ETIMEDOUT;
  111. break;
  112. }
  113. if (test_bit(DEV_CLEAR_BN, &nec_priv->state)) {
  114. retval = -EINTR;
  115. break;
  116. }
  117. }
  118. hs_status = cb7210_read_byte(cb_priv, HS_STATUS);
  119. if (hs_status & HS_RX_LSB_NOT_EMPTY) {
  120. word = inw(cb_priv->fifo_iobase + DIR);
  121. buffer[(*bytes_read)++] = word & 0xff;
  122. }
  123. input_fifo_enable(board, 0);
  124. if (wait_event_interruptible(board->wait,
  125. test_bit(READ_READY_BN, &nec_priv->state) ||
  126. test_bit(RECEIVED_END_BN, &nec_priv->state) ||
  127. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  128. test_bit(TIMO_NUM, &board->status))) {
  129. retval = -ERESTARTSYS;
  130. }
  131. if (test_bit(TIMO_NUM, &board->status))
  132. retval = -ETIMEDOUT;
  133. if (test_bit(DEV_CLEAR_BN, &nec_priv->state))
  134. retval = -EINTR;
  135. if (test_bit(READ_READY_BN, &nec_priv->state)) {
  136. nec7210_set_handshake_mode(board, nec_priv, HR_HLDA);
  137. buffer[(*bytes_read)++] = nec7210_read_data_in(board, nec_priv, end);
  138. }
  139. return retval;
  140. }
  141. static int cb7210_accel_read(struct gpib_board *board, u8 *buffer,
  142. size_t length, int *end, size_t *bytes_read)
  143. {
  144. ssize_t retval;
  145. struct cb7210_priv *cb_priv = board->private_data;
  146. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  147. size_t num_bytes;
  148. *bytes_read = 0;
  149. // deal with limitations of fifo
  150. if (length < cb7210_fifo_size + 3 || (nec_priv->auxa_bits & HR_REOS))
  151. return cb7210_read(board, buffer, length, end, bytes_read);
  152. *end = 0;
  153. nec7210_release_rfd_holdoff(board, nec_priv);
  154. if (wait_event_interruptible(board->wait,
  155. test_bit(READ_READY_BN, &nec_priv->state) ||
  156. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  157. test_bit(TIMO_NUM, &board->status))) {
  158. return -ERESTARTSYS;
  159. }
  160. if (test_bit(TIMO_NUM, &board->status))
  161. return -ETIMEDOUT;
  162. if (test_bit(DEV_CLEAR_BN, &nec_priv->state))
  163. return -EINTR;
  164. nec7210_set_handshake_mode(board, nec_priv, HR_HLDE);
  165. buffer[(*bytes_read)++] = nec7210_read_data_in(board, nec_priv, end);
  166. if (*end)
  167. return 0;
  168. nec7210_release_rfd_holdoff(board, nec_priv);
  169. retval = fifo_read(board, cb_priv, &buffer[*bytes_read], length - *bytes_read - 1,
  170. end, &num_bytes);
  171. *bytes_read += num_bytes;
  172. if (retval < 0)
  173. return retval;
  174. if (*end)
  175. return 0;
  176. retval = cb7210_read(board, &buffer[*bytes_read], 1, end, &num_bytes);
  177. *bytes_read += num_bytes;
  178. if (retval < 0)
  179. return retval;
  180. return 0;
  181. }
  182. static int output_fifo_empty(const struct cb7210_priv *cb_priv)
  183. {
  184. if ((cb7210_read_byte(cb_priv, HS_STATUS) & (HS_TX_MSB_NOT_EMPTY | HS_TX_LSB_NOT_EMPTY))
  185. == 0)
  186. return 1;
  187. else
  188. return 0;
  189. }
  190. static inline void output_fifo_enable(struct gpib_board *board, int enable)
  191. {
  192. struct cb7210_priv *cb_priv = board->private_data;
  193. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  194. unsigned long flags;
  195. spin_lock_irqsave(&board->spinlock, flags);
  196. if (enable) {
  197. nec7210_set_reg_bits(nec_priv, IMR1, HR_DOIE, 0);
  198. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAO, HR_DMAO);
  199. cb7210_write_byte(cb_priv, HS_RX_ENABLE | HS_TX_ENABLE | HS_CLR_SRQ_INT |
  200. HS_CLR_EOI_EMPTY_INT | HS_CLR_HF_INT | cb_priv->hs_mode_bits,
  201. HS_MODE);
  202. cb_priv->hs_mode_bits &= ~HS_ENABLE_MASK;
  203. cb_priv->hs_mode_bits |= HS_TX_ENABLE;
  204. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  205. cb7210_write_byte(cb_priv, irq_bits(cb_priv->irq), HS_INT_LEVEL);
  206. clear_bit(WRITE_READY_BN, &nec_priv->state);
  207. } else {
  208. cb_priv->hs_mode_bits &= ~HS_ENABLE_MASK;
  209. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  210. nec7210_set_reg_bits(nec_priv, IMR2, HR_DMAO, 0);
  211. nec7210_set_reg_bits(nec_priv, IMR1, HR_DOIE, HR_DOIE);
  212. }
  213. spin_unlock_irqrestore(&board->spinlock, flags);
  214. }
  215. static int fifo_write(struct gpib_board *board, u8 *buffer, size_t length,
  216. size_t *bytes_written)
  217. {
  218. size_t count = 0;
  219. ssize_t retval = 0;
  220. struct cb7210_priv *cb_priv = board->private_data;
  221. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  222. unsigned int num_bytes, i;
  223. unsigned long flags;
  224. *bytes_written = 0;
  225. if (cb_priv->fifo_iobase == 0) {
  226. dev_err(board->gpib_dev, "fifo iobase is zero!\n");
  227. return -EINVAL;
  228. }
  229. if (length == 0)
  230. return 0;
  231. clear_bit(DEV_CLEAR_BN, &nec_priv->state);
  232. clear_bit(BUS_ERROR_BN, &nec_priv->state);
  233. output_fifo_enable(board, 1);
  234. while (count < length) {
  235. // wait until byte is ready to be sent
  236. if (wait_event_interruptible(board->wait,
  237. cb_priv->out_fifo_half_empty ||
  238. output_fifo_empty(cb_priv) ||
  239. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  240. test_bit(BUS_ERROR_BN, &nec_priv->state) ||
  241. test_bit(TIMO_NUM, &board->status))) {
  242. retval = -ERESTARTSYS;
  243. break;
  244. }
  245. if (test_bit(TIMO_NUM, &board->status) ||
  246. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  247. test_bit(BUS_ERROR_BN, &nec_priv->state))
  248. break;
  249. if (output_fifo_empty(cb_priv))
  250. num_bytes = cb7210_fifo_size - cb7210_fifo_width;
  251. else
  252. num_bytes = cb7210_fifo_size / 2;
  253. if (num_bytes + count > length)
  254. num_bytes = length - count;
  255. if (num_bytes % cb7210_fifo_width) {
  256. dev_err(board->gpib_dev, " bug! fifo write with odd number of bytes\n");
  257. retval = -EINVAL;
  258. break;
  259. }
  260. spin_lock_irqsave(&board->spinlock, flags);
  261. for (i = 0; i < num_bytes / cb7210_fifo_width; i++) {
  262. u16 word;
  263. word = buffer[count++] & 0xff;
  264. word |= (buffer[count++] << 8) & 0xff00;
  265. outw(word, cb_priv->fifo_iobase + CDOR);
  266. }
  267. cb_priv->out_fifo_half_empty = 0;
  268. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits |
  269. HS_CLR_EOI_EMPTY_INT | HS_CLR_HF_INT, HS_MODE);
  270. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  271. spin_unlock_irqrestore(&board->spinlock, flags);
  272. }
  273. // wait last byte has been sent
  274. if (wait_event_interruptible(board->wait,
  275. output_fifo_empty(cb_priv) ||
  276. test_bit(DEV_CLEAR_BN, &nec_priv->state) ||
  277. test_bit(BUS_ERROR_BN, &nec_priv->state) ||
  278. test_bit(TIMO_NUM, &board->status))) {
  279. retval = -ERESTARTSYS;
  280. }
  281. if (test_bit(TIMO_NUM, &board->status))
  282. retval = -ETIMEDOUT;
  283. if (test_bit(BUS_ERROR_BN, &nec_priv->state))
  284. retval = -EIO;
  285. if (test_bit(DEV_CLEAR_BN, &nec_priv->state))
  286. retval = -EINTR;
  287. output_fifo_enable(board, 0);
  288. *bytes_written = count;
  289. return retval;
  290. }
  291. static int cb7210_accel_write(struct gpib_board *board, u8 *buffer,
  292. size_t length, int send_eoi, size_t *bytes_written)
  293. {
  294. struct cb7210_priv *cb_priv = board->private_data;
  295. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  296. unsigned long fast_chunk_size, leftover;
  297. int retval;
  298. size_t num_bytes;
  299. *bytes_written = 0;
  300. if (length > cb7210_fifo_width)
  301. fast_chunk_size = length - 1;
  302. else
  303. fast_chunk_size = 0;
  304. fast_chunk_size -= fast_chunk_size % cb7210_fifo_width;
  305. leftover = length - fast_chunk_size;
  306. retval = fifo_write(board, buffer, fast_chunk_size, &num_bytes);
  307. *bytes_written += num_bytes;
  308. if (retval < 0)
  309. return retval;
  310. retval = nec7210_write(board, nec_priv, buffer + fast_chunk_size, leftover,
  311. send_eoi, &num_bytes);
  312. *bytes_written += num_bytes;
  313. return retval;
  314. }
  315. static int cb7210_line_status(const struct gpib_board *board)
  316. {
  317. int status = VALID_ALL;
  318. int bsr_bits;
  319. struct cb7210_priv *cb_priv;
  320. cb_priv = board->private_data;
  321. bsr_bits = cb7210_paged_read_byte(cb_priv, BUS_STATUS, BUS_STATUS_PAGE);
  322. if ((bsr_bits & BSR_REN_BIT) == 0)
  323. status |= BUS_REN;
  324. if ((bsr_bits & BSR_IFC_BIT) == 0)
  325. status |= BUS_IFC;
  326. if ((bsr_bits & BSR_SRQ_BIT) == 0)
  327. status |= BUS_SRQ;
  328. if ((bsr_bits & BSR_EOI_BIT) == 0)
  329. status |= BUS_EOI;
  330. if ((bsr_bits & BSR_NRFD_BIT) == 0)
  331. status |= BUS_NRFD;
  332. if ((bsr_bits & BSR_NDAC_BIT) == 0)
  333. status |= BUS_NDAC;
  334. if ((bsr_bits & BSR_DAV_BIT) == 0)
  335. status |= BUS_DAV;
  336. if ((bsr_bits & BSR_ATN_BIT) == 0)
  337. status |= BUS_ATN;
  338. return status;
  339. }
  340. static int cb7210_t1_delay(struct gpib_board *board, unsigned int nano_sec)
  341. {
  342. struct cb7210_priv *cb_priv = board->private_data;
  343. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  344. unsigned int retval;
  345. retval = nec7210_t1_delay(board, nec_priv, nano_sec);
  346. if (nano_sec <= 350) {
  347. write_byte(nec_priv, AUX_HI_SPEED, AUXMR);
  348. retval = 350;
  349. } else {
  350. write_byte(nec_priv, AUX_LO_SPEED, AUXMR);
  351. }
  352. return retval;
  353. }
  354. static irqreturn_t cb7210_locked_internal_interrupt(struct gpib_board *board);
  355. /*
  356. * GPIB interrupt service routines
  357. */
  358. static irqreturn_t cb_pci_interrupt(int irq, void *arg)
  359. {
  360. int bits;
  361. struct gpib_board *board = arg;
  362. struct cb7210_priv *priv = board->private_data;
  363. // first task check if this is really our interrupt in a shared irq environment
  364. switch (priv->pci_chip) {
  365. case PCI_CHIP_AMCC_S5933:
  366. if ((inl(priv->amcc_iobase + INTCSR_REG) &
  367. (INBOX_INTR_CS_BIT | INTR_ASSERTED_BIT)) == 0)
  368. return IRQ_NONE;
  369. // read incoming mailbox to clear mailbox full flag
  370. inl(priv->amcc_iobase + INCOMING_MAILBOX_REG(3));
  371. // clear amccs5933 interrupt
  372. bits = INBOX_FULL_INTR_BIT | INBOX_BYTE_BITS(3) |
  373. INBOX_SELECT_BITS(3) | INBOX_INTR_CS_BIT;
  374. outl(bits, priv->amcc_iobase + INTCSR_REG);
  375. break;
  376. case PCI_CHIP_QUANCOM:
  377. if ((inb(nec7210_iobase(priv) + QUANCOM_IRQ_CONTROL_STATUS_REG) &
  378. QUANCOM_IRQ_ASSERTED_BIT))
  379. outb(QUANCOM_IRQ_ENABLE_BIT, nec7210_iobase(priv) +
  380. QUANCOM_IRQ_CONTROL_STATUS_REG);
  381. break;
  382. default:
  383. break;
  384. }
  385. return cb7210_locked_internal_interrupt(arg);
  386. }
  387. static irqreturn_t cb7210_internal_interrupt(struct gpib_board *board)
  388. {
  389. int hs_status, status1, status2;
  390. struct cb7210_priv *priv = board->private_data;
  391. struct nec7210_priv *nec_priv = &priv->nec7210_priv;
  392. int clear_bits;
  393. if ((priv->hs_mode_bits & HS_ENABLE_MASK)) {
  394. status1 = 0;
  395. hs_status = cb7210_read_byte(priv, HS_STATUS);
  396. } else {
  397. hs_status = 0;
  398. status1 = read_byte(nec_priv, ISR1);
  399. }
  400. status2 = read_byte(nec_priv, ISR2);
  401. nec7210_interrupt_have_status(board, nec_priv, status1, status2);
  402. dev_dbg(board->gpib_dev, "status 0x%x, mode 0x%x\n", hs_status, priv->hs_mode_bits);
  403. clear_bits = 0;
  404. if (hs_status & HS_HALF_FULL) {
  405. if (priv->hs_mode_bits & HS_TX_ENABLE)
  406. priv->out_fifo_half_empty = 1;
  407. else if (priv->hs_mode_bits & HS_RX_ENABLE)
  408. priv->in_fifo_half_full = 1;
  409. clear_bits |= HS_CLR_HF_INT;
  410. }
  411. if (hs_status & HS_SRQ_INT) {
  412. set_bit(SRQI_NUM, &board->status);
  413. clear_bits |= HS_CLR_SRQ_INT;
  414. }
  415. if ((hs_status & HS_EOI_INT)) {
  416. clear_bits |= HS_CLR_EOI_EMPTY_INT;
  417. set_bit(RECEIVED_END_BN, &nec_priv->state);
  418. if ((nec_priv->auxa_bits & HR_HANDSHAKE_MASK) == HR_HLDE)
  419. set_bit(RFD_HOLDOFF_BN, &nec_priv->state);
  420. }
  421. if ((priv->hs_mode_bits & HS_TX_ENABLE) &&
  422. (hs_status & (HS_TX_MSB_NOT_EMPTY | HS_TX_LSB_NOT_EMPTY)) == 0)
  423. clear_bits |= HS_CLR_EOI_EMPTY_INT;
  424. if (clear_bits) {
  425. cb7210_write_byte(priv, priv->hs_mode_bits | clear_bits, HS_MODE);
  426. cb7210_write_byte(priv, priv->hs_mode_bits, HS_MODE);
  427. wake_up_interruptible(&board->wait);
  428. }
  429. return IRQ_HANDLED;
  430. }
  431. static irqreturn_t cb7210_locked_internal_interrupt(struct gpib_board *board)
  432. {
  433. unsigned long flags;
  434. irqreturn_t retval;
  435. spin_lock_irqsave(&board->spinlock, flags);
  436. retval = cb7210_internal_interrupt(board);
  437. spin_unlock_irqrestore(&board->spinlock, flags);
  438. return retval;
  439. }
  440. static irqreturn_t cb7210_interrupt(int irq, void *arg)
  441. {
  442. return cb7210_internal_interrupt(arg);
  443. }
  444. static int cb_pci_attach(struct gpib_board *board, const struct gpib_board_config *config);
  445. static int cb_isa_attach(struct gpib_board *board, const struct gpib_board_config *config);
  446. static void cb_pci_detach(struct gpib_board *board);
  447. static void cb_isa_detach(struct gpib_board *board);
  448. // wrappers for interface functions
  449. static int cb7210_read(struct gpib_board *board, u8 *buffer, size_t length,
  450. int *end, size_t *bytes_read)
  451. {
  452. struct cb7210_priv *priv = board->private_data;
  453. return nec7210_read(board, &priv->nec7210_priv, buffer, length, end, bytes_read);
  454. }
  455. static int cb7210_write(struct gpib_board *board, u8 *buffer, size_t length,
  456. int send_eoi, size_t *bytes_written)
  457. {
  458. struct cb7210_priv *priv = board->private_data;
  459. return nec7210_write(board, &priv->nec7210_priv, buffer, length, send_eoi, bytes_written);
  460. }
  461. static int cb7210_command(struct gpib_board *board, u8 *buffer, size_t length,
  462. size_t *bytes_written)
  463. {
  464. struct cb7210_priv *priv = board->private_data;
  465. return nec7210_command(board, &priv->nec7210_priv, buffer, length, bytes_written);
  466. }
  467. static int cb7210_take_control(struct gpib_board *board, int synchronous)
  468. {
  469. struct cb7210_priv *priv = board->private_data;
  470. return nec7210_take_control(board, &priv->nec7210_priv, synchronous);
  471. }
  472. static int cb7210_go_to_standby(struct gpib_board *board)
  473. {
  474. struct cb7210_priv *priv = board->private_data;
  475. return nec7210_go_to_standby(board, &priv->nec7210_priv);
  476. }
  477. static int cb7210_request_system_control(struct gpib_board *board, int request_control)
  478. {
  479. struct cb7210_priv *priv = board->private_data;
  480. struct nec7210_priv *nec_priv = &priv->nec7210_priv;
  481. if (request_control)
  482. priv->hs_mode_bits |= HS_SYS_CONTROL;
  483. else
  484. priv->hs_mode_bits &= ~HS_SYS_CONTROL;
  485. cb7210_write_byte(priv, priv->hs_mode_bits, HS_MODE);
  486. return nec7210_request_system_control(board, nec_priv, request_control);
  487. }
  488. static void cb7210_interface_clear(struct gpib_board *board, int assert)
  489. {
  490. struct cb7210_priv *priv = board->private_data;
  491. nec7210_interface_clear(board, &priv->nec7210_priv, assert);
  492. }
  493. static void cb7210_remote_enable(struct gpib_board *board, int enable)
  494. {
  495. struct cb7210_priv *priv = board->private_data;
  496. nec7210_remote_enable(board, &priv->nec7210_priv, enable);
  497. }
  498. static int cb7210_enable_eos(struct gpib_board *board, u8 eos_byte, int compare_8_bits)
  499. {
  500. struct cb7210_priv *priv = board->private_data;
  501. return nec7210_enable_eos(board, &priv->nec7210_priv, eos_byte, compare_8_bits);
  502. }
  503. static void cb7210_disable_eos(struct gpib_board *board)
  504. {
  505. struct cb7210_priv *priv = board->private_data;
  506. nec7210_disable_eos(board, &priv->nec7210_priv);
  507. }
  508. static unsigned int cb7210_update_status(struct gpib_board *board, unsigned int clear_mask)
  509. {
  510. struct cb7210_priv *priv = board->private_data;
  511. return nec7210_update_status(board, &priv->nec7210_priv, clear_mask);
  512. }
  513. static int cb7210_primary_address(struct gpib_board *board, unsigned int address)
  514. {
  515. struct cb7210_priv *priv = board->private_data;
  516. return nec7210_primary_address(board, &priv->nec7210_priv, address);
  517. }
  518. static int cb7210_secondary_address(struct gpib_board *board, unsigned int address, int enable)
  519. {
  520. struct cb7210_priv *priv = board->private_data;
  521. return nec7210_secondary_address(board, &priv->nec7210_priv, address, enable);
  522. }
  523. static int cb7210_parallel_poll(struct gpib_board *board, u8 *result)
  524. {
  525. struct cb7210_priv *priv = board->private_data;
  526. return nec7210_parallel_poll(board, &priv->nec7210_priv, result);
  527. }
  528. static void cb7210_parallel_poll_configure(struct gpib_board *board, u8 configuration)
  529. {
  530. struct cb7210_priv *priv = board->private_data;
  531. nec7210_parallel_poll_configure(board, &priv->nec7210_priv, configuration);
  532. }
  533. static void cb7210_parallel_poll_response(struct gpib_board *board, int ist)
  534. {
  535. struct cb7210_priv *priv = board->private_data;
  536. nec7210_parallel_poll_response(board, &priv->nec7210_priv, ist);
  537. }
  538. static void cb7210_serial_poll_response(struct gpib_board *board, u8 status)
  539. {
  540. struct cb7210_priv *priv = board->private_data;
  541. nec7210_serial_poll_response(board, &priv->nec7210_priv, status);
  542. }
  543. static u8 cb7210_serial_poll_status(struct gpib_board *board)
  544. {
  545. struct cb7210_priv *priv = board->private_data;
  546. return nec7210_serial_poll_status(board, &priv->nec7210_priv);
  547. }
  548. static void cb7210_return_to_local(struct gpib_board *board)
  549. {
  550. struct cb7210_priv *priv = board->private_data;
  551. struct nec7210_priv *nec_priv = &priv->nec7210_priv;
  552. write_byte(nec_priv, AUX_RTL2, AUXMR);
  553. udelay(1);
  554. write_byte(nec_priv, AUX_RTL, AUXMR);
  555. }
  556. static struct gpib_interface cb_pci_unaccel_interface = {
  557. .name = "cbi_pci_unaccel",
  558. .attach = cb_pci_attach,
  559. .detach = cb_pci_detach,
  560. .read = cb7210_read,
  561. .write = cb7210_write,
  562. .command = cb7210_command,
  563. .take_control = cb7210_take_control,
  564. .go_to_standby = cb7210_go_to_standby,
  565. .request_system_control = cb7210_request_system_control,
  566. .interface_clear = cb7210_interface_clear,
  567. .remote_enable = cb7210_remote_enable,
  568. .enable_eos = cb7210_enable_eos,
  569. .disable_eos = cb7210_disable_eos,
  570. .parallel_poll = cb7210_parallel_poll,
  571. .parallel_poll_configure = cb7210_parallel_poll_configure,
  572. .parallel_poll_response = cb7210_parallel_poll_response,
  573. .local_parallel_poll_mode = NULL, // XXX
  574. .line_status = cb7210_line_status,
  575. .update_status = cb7210_update_status,
  576. .primary_address = cb7210_primary_address,
  577. .secondary_address = cb7210_secondary_address,
  578. .serial_poll_response = cb7210_serial_poll_response,
  579. .serial_poll_status = cb7210_serial_poll_status,
  580. .t1_delay = cb7210_t1_delay,
  581. .return_to_local = cb7210_return_to_local,
  582. };
  583. static struct gpib_interface cb_pci_accel_interface = {
  584. .name = "cbi_pci_accel",
  585. .attach = cb_pci_attach,
  586. .detach = cb_pci_detach,
  587. .read = cb7210_accel_read,
  588. .write = cb7210_accel_write,
  589. .command = cb7210_command,
  590. .take_control = cb7210_take_control,
  591. .go_to_standby = cb7210_go_to_standby,
  592. .request_system_control = cb7210_request_system_control,
  593. .interface_clear = cb7210_interface_clear,
  594. .remote_enable = cb7210_remote_enable,
  595. .enable_eos = cb7210_enable_eos,
  596. .disable_eos = cb7210_disable_eos,
  597. .parallel_poll = cb7210_parallel_poll,
  598. .parallel_poll_configure = cb7210_parallel_poll_configure,
  599. .parallel_poll_response = cb7210_parallel_poll_response,
  600. .local_parallel_poll_mode = NULL, // XXX
  601. .line_status = cb7210_line_status,
  602. .update_status = cb7210_update_status,
  603. .primary_address = cb7210_primary_address,
  604. .secondary_address = cb7210_secondary_address,
  605. .serial_poll_response = cb7210_serial_poll_response,
  606. .serial_poll_status = cb7210_serial_poll_status,
  607. .t1_delay = cb7210_t1_delay,
  608. .return_to_local = cb7210_return_to_local,
  609. };
  610. static struct gpib_interface cb_pci_interface = {
  611. .name = "cbi_pci",
  612. .attach = cb_pci_attach,
  613. .detach = cb_pci_detach,
  614. .read = cb7210_accel_read,
  615. .write = cb7210_accel_write,
  616. .command = cb7210_command,
  617. .take_control = cb7210_take_control,
  618. .go_to_standby = cb7210_go_to_standby,
  619. .request_system_control = cb7210_request_system_control,
  620. .interface_clear = cb7210_interface_clear,
  621. .remote_enable = cb7210_remote_enable,
  622. .enable_eos = cb7210_enable_eos,
  623. .disable_eos = cb7210_disable_eos,
  624. .parallel_poll = cb7210_parallel_poll,
  625. .parallel_poll_configure = cb7210_parallel_poll_configure,
  626. .parallel_poll_response = cb7210_parallel_poll_response,
  627. .line_status = cb7210_line_status,
  628. .update_status = cb7210_update_status,
  629. .primary_address = cb7210_primary_address,
  630. .secondary_address = cb7210_secondary_address,
  631. .serial_poll_response = cb7210_serial_poll_response,
  632. .serial_poll_status = cb7210_serial_poll_status,
  633. .t1_delay = cb7210_t1_delay,
  634. .return_to_local = cb7210_return_to_local,
  635. };
  636. static struct gpib_interface cb_isa_unaccel_interface = {
  637. .name = "cbi_isa_unaccel",
  638. .attach = cb_isa_attach,
  639. .detach = cb_isa_detach,
  640. .read = cb7210_read,
  641. .write = cb7210_write,
  642. .command = cb7210_command,
  643. .take_control = cb7210_take_control,
  644. .go_to_standby = cb7210_go_to_standby,
  645. .request_system_control = cb7210_request_system_control,
  646. .interface_clear = cb7210_interface_clear,
  647. .remote_enable = cb7210_remote_enable,
  648. .enable_eos = cb7210_enable_eos,
  649. .disable_eos = cb7210_disable_eos,
  650. .parallel_poll = cb7210_parallel_poll,
  651. .parallel_poll_configure = cb7210_parallel_poll_configure,
  652. .parallel_poll_response = cb7210_parallel_poll_response,
  653. .local_parallel_poll_mode = NULL, // XXX
  654. .line_status = cb7210_line_status,
  655. .update_status = cb7210_update_status,
  656. .primary_address = cb7210_primary_address,
  657. .secondary_address = cb7210_secondary_address,
  658. .serial_poll_response = cb7210_serial_poll_response,
  659. .serial_poll_status = cb7210_serial_poll_status,
  660. .t1_delay = cb7210_t1_delay,
  661. .return_to_local = cb7210_return_to_local,
  662. };
  663. static struct gpib_interface cb_isa_interface = {
  664. .name = "cbi_isa",
  665. .attach = cb_isa_attach,
  666. .detach = cb_isa_detach,
  667. .read = cb7210_accel_read,
  668. .write = cb7210_accel_write,
  669. .command = cb7210_command,
  670. .take_control = cb7210_take_control,
  671. .go_to_standby = cb7210_go_to_standby,
  672. .request_system_control = cb7210_request_system_control,
  673. .interface_clear = cb7210_interface_clear,
  674. .remote_enable = cb7210_remote_enable,
  675. .enable_eos = cb7210_enable_eos,
  676. .disable_eos = cb7210_disable_eos,
  677. .parallel_poll = cb7210_parallel_poll,
  678. .parallel_poll_configure = cb7210_parallel_poll_configure,
  679. .parallel_poll_response = cb7210_parallel_poll_response,
  680. .line_status = cb7210_line_status,
  681. .update_status = cb7210_update_status,
  682. .primary_address = cb7210_primary_address,
  683. .secondary_address = cb7210_secondary_address,
  684. .serial_poll_response = cb7210_serial_poll_response,
  685. .serial_poll_status = cb7210_serial_poll_status,
  686. .t1_delay = cb7210_t1_delay,
  687. .return_to_local = cb7210_return_to_local,
  688. };
  689. static struct gpib_interface cb_isa_accel_interface = {
  690. .name = "cbi_isa_accel",
  691. .attach = cb_isa_attach,
  692. .detach = cb_isa_detach,
  693. .read = cb7210_accel_read,
  694. .write = cb7210_accel_write,
  695. .command = cb7210_command,
  696. .take_control = cb7210_take_control,
  697. .go_to_standby = cb7210_go_to_standby,
  698. .request_system_control = cb7210_request_system_control,
  699. .interface_clear = cb7210_interface_clear,
  700. .remote_enable = cb7210_remote_enable,
  701. .enable_eos = cb7210_enable_eos,
  702. .disable_eos = cb7210_disable_eos,
  703. .parallel_poll = cb7210_parallel_poll,
  704. .parallel_poll_configure = cb7210_parallel_poll_configure,
  705. .parallel_poll_response = cb7210_parallel_poll_response,
  706. .local_parallel_poll_mode = NULL, // XXX
  707. .line_status = cb7210_line_status,
  708. .update_status = cb7210_update_status,
  709. .primary_address = cb7210_primary_address,
  710. .secondary_address = cb7210_secondary_address,
  711. .serial_poll_response = cb7210_serial_poll_response,
  712. .serial_poll_status = cb7210_serial_poll_status,
  713. .t1_delay = cb7210_t1_delay,
  714. .return_to_local = cb7210_return_to_local,
  715. };
  716. static int cb7210_allocate_private(struct gpib_board *board)
  717. {
  718. struct cb7210_priv *priv;
  719. board->private_data = kzalloc_obj(struct cb7210_priv);
  720. if (!board->private_data)
  721. return -ENOMEM;
  722. priv = board->private_data;
  723. init_nec7210_private(&priv->nec7210_priv);
  724. return 0;
  725. }
  726. static void cb7210_generic_detach(struct gpib_board *board)
  727. {
  728. kfree(board->private_data);
  729. board->private_data = NULL;
  730. }
  731. // generic part of attach functions shared by all cb7210 boards
  732. static int cb7210_generic_attach(struct gpib_board *board)
  733. {
  734. struct cb7210_priv *cb_priv;
  735. struct nec7210_priv *nec_priv;
  736. int retval;
  737. board->status = 0;
  738. retval = cb7210_allocate_private(board);
  739. if (retval)
  740. return retval;
  741. cb_priv = board->private_data;
  742. nec_priv = &cb_priv->nec7210_priv;
  743. nec_priv->read_byte = nec7210_locking_ioport_read_byte;
  744. nec_priv->write_byte = nec7210_locking_ioport_write_byte;
  745. nec_priv->offset = cb7210_reg_offset;
  746. nec_priv->type = CB7210;
  747. return 0;
  748. }
  749. static int cb7210_init(struct cb7210_priv *cb_priv, struct gpib_board *board)
  750. {
  751. struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
  752. cb7210_write_byte(cb_priv, HS_RESET7210, HS_INT_LEVEL);
  753. cb7210_write_byte(cb_priv, irq_bits(cb_priv->irq), HS_INT_LEVEL);
  754. nec7210_board_reset(nec_priv, board);
  755. cb7210_write_byte(cb_priv, HS_TX_ENABLE | HS_RX_ENABLE | HS_CLR_SRQ_INT |
  756. HS_CLR_EOI_EMPTY_INT | HS_CLR_HF_INT, HS_MODE);
  757. cb_priv->hs_mode_bits = HS_HF_INT_EN;
  758. cb7210_write_byte(cb_priv, cb_priv->hs_mode_bits, HS_MODE);
  759. write_byte(nec_priv, AUX_LO_SPEED, AUXMR);
  760. /*
  761. * set clock register for maximum (20 MHz) driving frequency
  762. * ICR should be set to clock in megahertz (1-15) and to zero
  763. * for clocks faster than 15 MHz (max 20MHz)
  764. */
  765. write_byte(nec_priv, ICR | 0, AUXMR);
  766. if (cb_priv->pci_chip == PCI_CHIP_QUANCOM) {
  767. /* change interrupt polarity */
  768. nec_priv->auxb_bits |= HR_INV;
  769. write_byte(nec_priv, nec_priv->auxb_bits, AUXMR);
  770. }
  771. nec7210_board_online(nec_priv, board);
  772. /* poll so we can detect assertion of ATN */
  773. if (gpib_request_pseudo_irq(board, cb_pci_interrupt)) {
  774. pr_err("failed to allocate pseudo_irq\n");
  775. return -1;
  776. }
  777. return 0;
  778. }
  779. static int cb_pci_attach(struct gpib_board *board, const struct gpib_board_config *config)
  780. {
  781. struct cb7210_priv *cb_priv;
  782. struct nec7210_priv *nec_priv;
  783. int isr_flags = 0;
  784. int bits;
  785. int retval;
  786. retval = cb7210_generic_attach(board);
  787. if (retval)
  788. return retval;
  789. cb_priv = board->private_data;
  790. nec_priv = &cb_priv->nec7210_priv;
  791. cb_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_CBOARDS,
  792. PCI_DEVICE_ID_CBOARDS_PCI_GPIB, NULL);
  793. if (cb_priv->pci_device)
  794. cb_priv->pci_chip = PCI_CHIP_AMCC_S5933;
  795. if (!cb_priv->pci_device) {
  796. cb_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_CBOARDS,
  797. PCI_DEVICE_ID_CBOARDS_CPCI_GPIB, NULL);
  798. if (cb_priv->pci_device)
  799. cb_priv->pci_chip = PCI_CHIP_AMCC_S5933;
  800. }
  801. if (!cb_priv->pci_device) {
  802. cb_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_QUANCOM,
  803. PCI_DEVICE_ID_QUANCOM_GPIB, NULL);
  804. if (cb_priv->pci_device) {
  805. cb_priv->pci_chip = PCI_CHIP_QUANCOM;
  806. nec_priv->offset = 4;
  807. }
  808. }
  809. if (!cb_priv->pci_device) {
  810. dev_err(board->gpib_dev, "no supported boards found.\n");
  811. return -ENODEV;
  812. }
  813. if (pci_enable_device(cb_priv->pci_device)) {
  814. dev_err(board->gpib_dev, "error enabling pci device\n");
  815. return -EIO;
  816. }
  817. if (pci_request_regions(cb_priv->pci_device, DRV_NAME))
  818. return -EBUSY;
  819. switch (cb_priv->pci_chip) {
  820. case PCI_CHIP_AMCC_S5933:
  821. cb_priv->amcc_iobase = pci_resource_start(cb_priv->pci_device, 0);
  822. nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 1);
  823. cb_priv->fifo_iobase = pci_resource_start(cb_priv->pci_device, 2);
  824. break;
  825. case PCI_CHIP_QUANCOM:
  826. nec_priv->iobase = pci_resource_start(cb_priv->pci_device, 0);
  827. cb_priv->fifo_iobase = nec_priv->iobase;
  828. break;
  829. default:
  830. dev_err(board->gpib_dev, "bug! unhandled pci_chip=%i\n", cb_priv->pci_chip);
  831. return -EIO;
  832. }
  833. isr_flags |= IRQF_SHARED;
  834. if (request_irq(cb_priv->pci_device->irq, cb_pci_interrupt, isr_flags, DRV_NAME, board)) {
  835. dev_err(board->gpib_dev, "can't request IRQ %d\n",
  836. cb_priv->pci_device->irq);
  837. return -EBUSY;
  838. }
  839. cb_priv->irq = cb_priv->pci_device->irq;
  840. switch (cb_priv->pci_chip) {
  841. case PCI_CHIP_AMCC_S5933:
  842. // make sure mailbox flags are clear
  843. inl(cb_priv->amcc_iobase + INCOMING_MAILBOX_REG(3));
  844. // enable interrupts on amccs5933 chip
  845. bits = INBOX_FULL_INTR_BIT | INBOX_BYTE_BITS(3) | INBOX_SELECT_BITS(3) |
  846. INBOX_INTR_CS_BIT;
  847. outl(bits, cb_priv->amcc_iobase + INTCSR_REG);
  848. break;
  849. default:
  850. break;
  851. }
  852. return cb7210_init(cb_priv, board);
  853. }
  854. static void cb_pci_detach(struct gpib_board *board)
  855. {
  856. struct cb7210_priv *cb_priv = board->private_data;
  857. struct nec7210_priv *nec_priv;
  858. if (cb_priv) {
  859. gpib_free_pseudo_irq(board);
  860. nec_priv = &cb_priv->nec7210_priv;
  861. if (cb_priv->irq) {
  862. // disable amcc interrupts
  863. outl(0, cb_priv->amcc_iobase + INTCSR_REG);
  864. free_irq(cb_priv->irq, board);
  865. }
  866. if (nec_priv->iobase) {
  867. nec7210_board_reset(nec_priv, board);
  868. pci_release_regions(cb_priv->pci_device);
  869. }
  870. if (cb_priv->pci_device)
  871. pci_dev_put(cb_priv->pci_device);
  872. }
  873. cb7210_generic_detach(board);
  874. }
  875. static int cb_isa_attach(struct gpib_board *board, const struct gpib_board_config *config)
  876. {
  877. int isr_flags = 0;
  878. struct cb7210_priv *cb_priv;
  879. struct nec7210_priv *nec_priv;
  880. unsigned int bits;
  881. int retval;
  882. retval = cb7210_generic_attach(board);
  883. if (retval)
  884. return retval;
  885. cb_priv = board->private_data;
  886. nec_priv = &cb_priv->nec7210_priv;
  887. if (!request_region(config->ibbase, cb7210_iosize, DRV_NAME)) {
  888. dev_err(board->gpib_dev, "ioports starting at 0x%x are already in use\n",
  889. config->ibbase);
  890. return -EBUSY;
  891. }
  892. nec_priv->iobase = config->ibbase;
  893. cb_priv->fifo_iobase = nec7210_iobase(cb_priv);
  894. bits = irq_bits(config->ibirq);
  895. if (bits == 0)
  896. dev_err(board->gpib_dev, "board incapable of using irq %i, try 2-5, 7, 10, or 11\n",
  897. config->ibirq);
  898. // install interrupt handler
  899. if (request_irq(config->ibirq, cb7210_interrupt, isr_flags, DRV_NAME, board)) {
  900. dev_err(board->gpib_dev, "failed to obtain IRQ %d\n", config->ibirq);
  901. return -EBUSY;
  902. }
  903. cb_priv->irq = config->ibirq;
  904. return cb7210_init(cb_priv, board);
  905. }
  906. static void cb_isa_detach(struct gpib_board *board)
  907. {
  908. struct cb7210_priv *cb_priv = board->private_data;
  909. struct nec7210_priv *nec_priv;
  910. if (cb_priv) {
  911. gpib_free_pseudo_irq(board);
  912. nec_priv = &cb_priv->nec7210_priv;
  913. if (cb_priv->irq)
  914. free_irq(cb_priv->irq, board);
  915. if (nec_priv->iobase) {
  916. nec7210_board_reset(nec_priv, board);
  917. release_region(nec7210_iobase(cb_priv), cb7210_iosize);
  918. }
  919. }
  920. cb7210_generic_detach(board);
  921. }
  922. static int cb7210_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  923. {
  924. return 0;
  925. }
  926. static const struct pci_device_id cb7210_pci_table[] = {
  927. {PCI_VENDOR_ID_CBOARDS, PCI_DEVICE_ID_CBOARDS_PCI_GPIB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  928. {PCI_VENDOR_ID_CBOARDS, PCI_DEVICE_ID_CBOARDS_CPCI_GPIB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  929. {PCI_VENDOR_ID_QUANCOM, PCI_DEVICE_ID_QUANCOM_GPIB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  930. { 0 }
  931. };
  932. MODULE_DEVICE_TABLE(pci, cb7210_pci_table);
  933. static struct pci_driver cb7210_pci_driver = {
  934. .name = DRV_NAME,
  935. .id_table = cb7210_pci_table,
  936. .probe = &cb7210_pci_probe
  937. };
  938. /***************************************************************************
  939. * Support for computer boards pcmcia-gpib card
  940. *
  941. * Based on gpib PCMCIA client driver written by Claus Schroeter
  942. * (clausi@chemie.fu-berlin.de), which was adapted from the
  943. * pcmcia skeleton example (presumably David Hinds)
  944. ***************************************************************************/
  945. #ifdef CONFIG_GPIB_PCMCIA
  946. #include <linux/kernel.h>
  947. #include <linux/ptrace.h>
  948. #include <linux/timer.h>
  949. #include <linux/io.h>
  950. #include <pcmcia/cistpl.h>
  951. #include <pcmcia/ds.h>
  952. /*
  953. * The event() function is this driver's Card Services event handler.
  954. * It will be called by Card Services when an appropriate card status
  955. * event is received. The config() and release() entry points are
  956. * used to configure or release a socket, in response to card insertion
  957. * and ejection events. They are invoked from the gpib event
  958. * handler.
  959. */
  960. static int cb_gpib_config(struct pcmcia_device *link);
  961. static void cb_gpib_release(struct pcmcia_device *link);
  962. static int cb_pcmcia_attach(struct gpib_board *board, const struct gpib_board_config *config);
  963. static void cb_pcmcia_detach(struct gpib_board *board);
  964. /*
  965. * A linked list of "instances" of the gpib device. Each actual
  966. * PCMCIA card corresponds to one device instance, and is described
  967. * by one dev_link_t structure (defined in ds.h).
  968. *
  969. * You may not want to use a linked list for this -- for example, the
  970. * memory card driver uses an array of dev_link_t pointers, where minor
  971. * device numbers are used to derive the corresponding array index.
  972. */
  973. static struct pcmcia_device *curr_dev;
  974. /*
  975. * A dev_link_t structure has fields for most things that are needed
  976. * to keep track of a socket, but there will usually be some device
  977. * specific information that also needs to be kept track of. The
  978. * 'priv' pointer in a dev_link_t structure can be used to point to
  979. * a device-specific private data structure, like this.
  980. *
  981. * A driver needs to provide a dev_node_t structure for each device
  982. * on a card. In some cases, there is only one device per card (for
  983. * example, ethernet cards, modems). In other cases, there may be
  984. * many actual or logical devices (SCSI adapters, memory cards with
  985. * multiple partitions). The dev_node_t structures need to be kept
  986. * in a linked list starting at the 'dev' field of a dev_link_t
  987. * structure. We allocate them in the card's private data structure,
  988. * because they generally can't be allocated dynamically.
  989. */
  990. struct local_info {
  991. struct pcmcia_device *p_dev;
  992. struct gpib_board *dev;
  993. };
  994. /*
  995. * gpib_attach() creates an "instance" of the driver, allocating
  996. * local data structures for one device. The device is registered
  997. * with Card Services.
  998. *
  999. * The dev_link structure is initialized, but we don't actually
  1000. * configure the card at this point -- we wait until we receive a
  1001. * card insertion event.
  1002. */
  1003. static int cb_gpib_probe(struct pcmcia_device *link)
  1004. {
  1005. struct local_info *info;
  1006. int ret;
  1007. /* Allocate space for private device-specific data */
  1008. info = kzalloc_obj(*info);
  1009. if (!info)
  1010. return -ENOMEM;
  1011. info->p_dev = link;
  1012. link->priv = info;
  1013. /* The io structure describes IO port mapping */
  1014. link->resource[0]->end = 16;
  1015. link->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  1016. link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  1017. link->resource[1]->end = 16;
  1018. link->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
  1019. link->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
  1020. link->io_lines = 10;
  1021. /* General socket configuration */
  1022. link->config_flags = CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  1023. link->config_index = 1;
  1024. link->config_regs = PRESENT_OPTION;
  1025. /* Register with Card Services */
  1026. curr_dev = link;
  1027. ret = cb_gpib_config(link);
  1028. if (ret)
  1029. goto free_info;
  1030. return 0;
  1031. free_info:
  1032. kfree(info);
  1033. return ret;
  1034. }
  1035. /*
  1036. * This deletes a driver "instance". The device is de-registered
  1037. * with Card Services. If it has been released, all local data
  1038. * structures are freed. Otherwise, the structures will be freed
  1039. * when the device is released.
  1040. */
  1041. static void cb_gpib_remove(struct pcmcia_device *link)
  1042. {
  1043. struct local_info *info = link->priv;
  1044. //struct struct gpib_board *dev = info->dev;
  1045. if (info->dev)
  1046. cb_pcmcia_detach(info->dev);
  1047. cb_gpib_release(link);
  1048. //free_netdev(dev);
  1049. kfree(info);
  1050. }
  1051. static int cb_gpib_config_iteration(struct pcmcia_device *link, void *priv_data)
  1052. {
  1053. return pcmcia_request_io(link);
  1054. }
  1055. /*
  1056. * gpib_config() is scheduled to run after a CARD_INSERTION event
  1057. * is received, to configure the PCMCIA socket, and to make the
  1058. * ethernet device available to the system.
  1059. */
  1060. static int cb_gpib_config(struct pcmcia_device *link)
  1061. {
  1062. int retval;
  1063. retval = pcmcia_loop_config(link, &cb_gpib_config_iteration, NULL);
  1064. if (retval) {
  1065. dev_warn(&link->dev, "no configuration found\n");
  1066. cb_gpib_release(link);
  1067. return -ENODEV;
  1068. }
  1069. /*
  1070. * This actually configures the PCMCIA socket -- setting up
  1071. * the I/O windows and the interrupt mapping.
  1072. */
  1073. retval = pcmcia_enable_device(link);
  1074. if (retval) {
  1075. dev_warn(&link->dev, "pcmcia_enable_device failed\n");
  1076. cb_gpib_release(link);
  1077. return -ENODEV;
  1078. }
  1079. return 0;
  1080. } /* gpib_config */
  1081. /*
  1082. * After a card is removed, gpib_release() will unregister the net
  1083. * device, and release the PCMCIA configuration. If the device is
  1084. * still open, this will be postponed until it is closed.
  1085. */
  1086. static void cb_gpib_release(struct pcmcia_device *link)
  1087. {
  1088. pcmcia_disable_device(link);
  1089. }
  1090. static int cb_gpib_suspend(struct pcmcia_device *link)
  1091. {
  1092. if (link->open)
  1093. dev_warn(&link->dev, "Device still open\n");
  1094. return 0;
  1095. }
  1096. static int cb_gpib_resume(struct pcmcia_device *link)
  1097. {
  1098. return cb_gpib_config(link);
  1099. }
  1100. /*====================================================================*/
  1101. static struct pcmcia_device_id cb_pcmcia_ids[] = {
  1102. PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0005),
  1103. PCMCIA_DEVICE_NULL
  1104. };
  1105. MODULE_DEVICE_TABLE(pcmcia, cb_pcmcia_ids);
  1106. static struct pcmcia_driver cb_gpib_cs_driver = {
  1107. .name = "cb_gpib_cs",
  1108. .owner = THIS_MODULE,
  1109. .id_table = cb_pcmcia_ids,
  1110. .probe = cb_gpib_probe,
  1111. .remove = cb_gpib_remove,
  1112. .suspend = cb_gpib_suspend,
  1113. .resume = cb_gpib_resume,
  1114. };
  1115. static void cb_pcmcia_cleanup_module(void)
  1116. {
  1117. pcmcia_unregister_driver(&cb_gpib_cs_driver);
  1118. }
  1119. static struct gpib_interface cb_pcmcia_unaccel_interface = {
  1120. .name = "cbi_pcmcia_unaccel",
  1121. .attach = cb_pcmcia_attach,
  1122. .detach = cb_pcmcia_detach,
  1123. .read = cb7210_read,
  1124. .write = cb7210_write,
  1125. .command = cb7210_command,
  1126. .take_control = cb7210_take_control,
  1127. .go_to_standby = cb7210_go_to_standby,
  1128. .request_system_control = cb7210_request_system_control,
  1129. .interface_clear = cb7210_interface_clear,
  1130. .remote_enable = cb7210_remote_enable,
  1131. .enable_eos = cb7210_enable_eos,
  1132. .disable_eos = cb7210_disable_eos,
  1133. .parallel_poll = cb7210_parallel_poll,
  1134. .parallel_poll_configure = cb7210_parallel_poll_configure,
  1135. .parallel_poll_response = cb7210_parallel_poll_response,
  1136. .local_parallel_poll_mode = NULL, // XXX
  1137. .line_status = cb7210_line_status,
  1138. .update_status = cb7210_update_status,
  1139. .primary_address = cb7210_primary_address,
  1140. .secondary_address = cb7210_secondary_address,
  1141. .serial_poll_response = cb7210_serial_poll_response,
  1142. .serial_poll_status = cb7210_serial_poll_status,
  1143. .t1_delay = cb7210_t1_delay,
  1144. .return_to_local = cb7210_return_to_local,
  1145. };
  1146. static struct gpib_interface cb_pcmcia_interface = {
  1147. .name = "cbi_pcmcia",
  1148. .attach = cb_pcmcia_attach,
  1149. .detach = cb_pcmcia_detach,
  1150. .read = cb7210_accel_read,
  1151. .write = cb7210_accel_write,
  1152. .command = cb7210_command,
  1153. .take_control = cb7210_take_control,
  1154. .go_to_standby = cb7210_go_to_standby,
  1155. .request_system_control = cb7210_request_system_control,
  1156. .interface_clear = cb7210_interface_clear,
  1157. .remote_enable = cb7210_remote_enable,
  1158. .enable_eos = cb7210_enable_eos,
  1159. .disable_eos = cb7210_disable_eos,
  1160. .parallel_poll = cb7210_parallel_poll,
  1161. .parallel_poll_configure = cb7210_parallel_poll_configure,
  1162. .parallel_poll_response = cb7210_parallel_poll_response,
  1163. .local_parallel_poll_mode = NULL, // XXX
  1164. .line_status = cb7210_line_status,
  1165. .update_status = cb7210_update_status,
  1166. .primary_address = cb7210_primary_address,
  1167. .secondary_address = cb7210_secondary_address,
  1168. .serial_poll_response = cb7210_serial_poll_response,
  1169. .serial_poll_status = cb7210_serial_poll_status,
  1170. .t1_delay = cb7210_t1_delay,
  1171. .return_to_local = cb7210_return_to_local,
  1172. };
  1173. static struct gpib_interface cb_pcmcia_accel_interface = {
  1174. .name = "cbi_pcmcia_accel",
  1175. .attach = cb_pcmcia_attach,
  1176. .detach = cb_pcmcia_detach,
  1177. .read = cb7210_accel_read,
  1178. .write = cb7210_accel_write,
  1179. .command = cb7210_command,
  1180. .take_control = cb7210_take_control,
  1181. .go_to_standby = cb7210_go_to_standby,
  1182. .request_system_control = cb7210_request_system_control,
  1183. .interface_clear = cb7210_interface_clear,
  1184. .remote_enable = cb7210_remote_enable,
  1185. .enable_eos = cb7210_enable_eos,
  1186. .disable_eos = cb7210_disable_eos,
  1187. .parallel_poll = cb7210_parallel_poll,
  1188. .parallel_poll_configure = cb7210_parallel_poll_configure,
  1189. .parallel_poll_response = cb7210_parallel_poll_response,
  1190. .local_parallel_poll_mode = NULL, // XXX
  1191. .line_status = cb7210_line_status,
  1192. .update_status = cb7210_update_status,
  1193. .primary_address = cb7210_primary_address,
  1194. .secondary_address = cb7210_secondary_address,
  1195. .serial_poll_response = cb7210_serial_poll_response,
  1196. .serial_poll_status = cb7210_serial_poll_status,
  1197. .t1_delay = cb7210_t1_delay,
  1198. .return_to_local = cb7210_return_to_local,
  1199. };
  1200. static int cb_pcmcia_attach(struct gpib_board *board, const struct gpib_board_config *config)
  1201. {
  1202. struct cb7210_priv *cb_priv;
  1203. struct nec7210_priv *nec_priv;
  1204. int retval;
  1205. if (!curr_dev) {
  1206. dev_err(board->gpib_dev, "no cb pcmcia cards found\n");
  1207. return -ENODEV;
  1208. }
  1209. retval = cb7210_generic_attach(board);
  1210. if (retval)
  1211. return retval;
  1212. cb_priv = board->private_data;
  1213. nec_priv = &cb_priv->nec7210_priv;
  1214. if (!request_region(curr_dev->resource[0]->start, resource_size(curr_dev->resource[0]),
  1215. DRV_NAME)) {
  1216. dev_err(board->gpib_dev, "ioports starting at 0x%lx are already in use\n",
  1217. (unsigned long)curr_dev->resource[0]->start);
  1218. return -EBUSY;
  1219. }
  1220. nec_priv->iobase = curr_dev->resource[0]->start;
  1221. cb_priv->fifo_iobase = curr_dev->resource[0]->start;
  1222. if (request_irq(curr_dev->irq, cb7210_interrupt, IRQF_SHARED, DRV_NAME, board)) {
  1223. dev_err(board->gpib_dev, "failed to request IRQ %d\n", curr_dev->irq);
  1224. return -EBUSY;
  1225. }
  1226. cb_priv->irq = curr_dev->irq;
  1227. return cb7210_init(cb_priv, board);
  1228. }
  1229. static void cb_pcmcia_detach(struct gpib_board *board)
  1230. {
  1231. struct cb7210_priv *cb_priv = board->private_data;
  1232. struct nec7210_priv *nec_priv;
  1233. if (cb_priv) {
  1234. nec_priv = &cb_priv->nec7210_priv;
  1235. gpib_free_pseudo_irq(board);
  1236. if (cb_priv->irq)
  1237. free_irq(cb_priv->irq, board);
  1238. if (nec_priv->iobase) {
  1239. nec7210_board_reset(nec_priv, board);
  1240. release_region(nec7210_iobase(cb_priv), cb7210_iosize);
  1241. }
  1242. }
  1243. cb7210_generic_detach(board);
  1244. }
  1245. #endif /* CONFIG_GPIB_PCMCIA */
  1246. static int __init cb7210_init_module(void)
  1247. {
  1248. int ret;
  1249. ret = pci_register_driver(&cb7210_pci_driver);
  1250. if (ret) {
  1251. pr_err("pci_register_driver failed: error = %d\n", ret);
  1252. return ret;
  1253. }
  1254. ret = gpib_register_driver(&cb_pci_interface, THIS_MODULE);
  1255. if (ret) {
  1256. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1257. goto err_pci;
  1258. }
  1259. ret = gpib_register_driver(&cb_isa_interface, THIS_MODULE);
  1260. if (ret) {
  1261. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1262. goto err_isa;
  1263. }
  1264. ret = gpib_register_driver(&cb_pci_accel_interface, THIS_MODULE);
  1265. if (ret) {
  1266. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1267. goto err_pci_accel;
  1268. }
  1269. ret = gpib_register_driver(&cb_pci_unaccel_interface, THIS_MODULE);
  1270. if (ret) {
  1271. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1272. goto err_pci_unaccel;
  1273. }
  1274. ret = gpib_register_driver(&cb_isa_accel_interface, THIS_MODULE);
  1275. if (ret) {
  1276. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1277. goto err_isa_accel;
  1278. }
  1279. ret = gpib_register_driver(&cb_isa_unaccel_interface, THIS_MODULE);
  1280. if (ret) {
  1281. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1282. goto err_isa_unaccel;
  1283. }
  1284. #ifdef CONFIG_GPIB_PCMCIA
  1285. ret = gpib_register_driver(&cb_pcmcia_interface, THIS_MODULE);
  1286. if (ret) {
  1287. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1288. goto err_pcmcia;
  1289. }
  1290. ret = gpib_register_driver(&cb_pcmcia_accel_interface, THIS_MODULE);
  1291. if (ret) {
  1292. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1293. goto err_pcmcia_accel;
  1294. }
  1295. ret = gpib_register_driver(&cb_pcmcia_unaccel_interface, THIS_MODULE);
  1296. if (ret) {
  1297. pr_err("gpib_register_driver failed: error = %d\n", ret);
  1298. goto err_pcmcia_unaccel;
  1299. }
  1300. ret = pcmcia_register_driver(&cb_gpib_cs_driver);
  1301. if (ret) {
  1302. pr_err("pcmcia_register_driver failed: error = %d\n", ret);
  1303. goto err_pcmcia_driver;
  1304. }
  1305. #endif
  1306. return 0;
  1307. #ifdef CONFIG_GPIB_PCMCIA
  1308. err_pcmcia_driver:
  1309. gpib_unregister_driver(&cb_pcmcia_unaccel_interface);
  1310. err_pcmcia_unaccel:
  1311. gpib_unregister_driver(&cb_pcmcia_accel_interface);
  1312. err_pcmcia_accel:
  1313. gpib_unregister_driver(&cb_pcmcia_interface);
  1314. err_pcmcia:
  1315. #endif
  1316. gpib_unregister_driver(&cb_isa_unaccel_interface);
  1317. err_isa_unaccel:
  1318. gpib_unregister_driver(&cb_isa_accel_interface);
  1319. err_isa_accel:
  1320. gpib_unregister_driver(&cb_pci_unaccel_interface);
  1321. err_pci_unaccel:
  1322. gpib_unregister_driver(&cb_pci_accel_interface);
  1323. err_pci_accel:
  1324. gpib_unregister_driver(&cb_isa_interface);
  1325. err_isa:
  1326. gpib_unregister_driver(&cb_pci_interface);
  1327. err_pci:
  1328. pci_unregister_driver(&cb7210_pci_driver);
  1329. return ret;
  1330. }
  1331. static void __exit cb7210_exit_module(void)
  1332. {
  1333. gpib_unregister_driver(&cb_pci_interface);
  1334. gpib_unregister_driver(&cb_isa_interface);
  1335. gpib_unregister_driver(&cb_pci_accel_interface);
  1336. gpib_unregister_driver(&cb_pci_unaccel_interface);
  1337. gpib_unregister_driver(&cb_isa_accel_interface);
  1338. gpib_unregister_driver(&cb_isa_unaccel_interface);
  1339. #ifdef CONFIG_GPIB_PCMCIA
  1340. gpib_unregister_driver(&cb_pcmcia_interface);
  1341. gpib_unregister_driver(&cb_pcmcia_accel_interface);
  1342. gpib_unregister_driver(&cb_pcmcia_unaccel_interface);
  1343. cb_pcmcia_cleanup_module();
  1344. #endif
  1345. pci_unregister_driver(&cb7210_pci_driver);
  1346. }
  1347. module_init(cb7210_init_module);
  1348. module_exit(cb7210_exit_module);