/drivers/staging/comedi/drivers/addi-data/addi_amcc_s5933.h

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C Header · 475 lines · 329 code · 70 blank · 76 comment · 44 complexity · 4852ce66d7ecdf193f3e9b760311dace MD5 · raw file

  1. /*
  2. * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
  3. *
  4. * ADDI-DATA GmbH
  5. * Dieselstrasse 3
  6. * D-77833 Ottersweier
  7. * Tel: +19(0)7223/9493-0
  8. * Fax: +49(0)7223/9493-92
  9. * http://www.addi-data.com
  10. * info@addi-data.com
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. /* Header file for AMCC s 5933 */
  18. #ifndef _AMCC_S5933_H_
  19. #define _AMCC_S5933_H_
  20. #include "../../comedidev.h"
  21. #include "../comedi_pci.h"
  22. #ifdef PCI_SUPPORT_VER1
  23. #error No support for 2.1.55 and older
  24. #endif
  25. /* written on base0 */
  26. #define FIFO_ADVANCE_ON_BYTE_2 0x20000000
  27. /* added for step 6 dma written on base2 */
  28. #define AMWEN_ENABLE 0x02
  29. #define A2P_FIFO_WRITE_ENABLE 0x01
  30. /* for transfer count enable bit */
  31. #define AGCSTS_TC_ENABLE 0x10000000
  32. /*
  33. * ADDON RELATED ADDITIONS
  34. */
  35. /* Constant */
  36. #define APCI3120_ENABLE_TRANSFER_ADD_ON_LOW 0x00
  37. #define APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH 0x1200
  38. #define APCI3120_A2P_FIFO_MANAGEMENT 0x04000400L
  39. #define APCI3120_AMWEN_ENABLE 0x02
  40. #define APCI3120_A2P_FIFO_WRITE_ENABLE 0x01
  41. #define APCI3120_FIFO_ADVANCE_ON_BYTE_2 0x20000000L
  42. #define APCI3120_ENABLE_WRITE_TC_INT 0x00004000L
  43. #define APCI3120_CLEAR_WRITE_TC_INT 0x00040000L
  44. #define APCI3120_DISABLE_AMWEN_AND_A2P_FIFO_WRITE 0x0
  45. #define APCI3120_DISABLE_BUS_MASTER_ADD_ON 0x0
  46. #define APCI3120_DISABLE_BUS_MASTER_PCI 0x0
  47. /* ADD_ON ::: this needed since apci supports 16 bit interface to add on */
  48. #define APCI3120_ADD_ON_AGCSTS_LOW 0x3C
  49. #define APCI3120_ADD_ON_AGCSTS_HIGH (APCI3120_ADD_ON_AGCSTS_LOW + 2)
  50. #define APCI3120_ADD_ON_MWAR_LOW 0x24
  51. #define APCI3120_ADD_ON_MWAR_HIGH (APCI3120_ADD_ON_MWAR_LOW + 2)
  52. #define APCI3120_ADD_ON_MWTC_LOW 0x058
  53. #define APCI3120_ADD_ON_MWTC_HIGH (APCI3120_ADD_ON_MWTC_LOW + 2)
  54. /* AMCC */
  55. #define APCI3120_AMCC_OP_MCSR 0x3C
  56. #define APCI3120_AMCC_OP_REG_INTCSR 0x38
  57. /*
  58. * AMCC Operation Register Offsets - PCI
  59. */
  60. #define AMCC_OP_REG_OMB1 0x00
  61. #define AMCC_OP_REG_OMB2 0x04
  62. #define AMCC_OP_REG_OMB3 0x08
  63. #define AMCC_OP_REG_OMB4 0x0c
  64. #define AMCC_OP_REG_IMB1 0x10
  65. #define AMCC_OP_REG_IMB2 0x14
  66. #define AMCC_OP_REG_IMB3 0x18
  67. #define AMCC_OP_REG_IMB4 0x1c
  68. #define AMCC_OP_REG_FIFO 0x20
  69. #define AMCC_OP_REG_MWAR 0x24
  70. #define AMCC_OP_REG_MWTC 0x28
  71. #define AMCC_OP_REG_MRAR 0x2c
  72. #define AMCC_OP_REG_MRTC 0x30
  73. #define AMCC_OP_REG_MBEF 0x34
  74. #define AMCC_OP_REG_INTCSR 0x38
  75. /* int source */
  76. #define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2)
  77. /* FIFO ctrl */
  78. #define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3)
  79. #define AMCC_OP_REG_MCSR 0x3c
  80. /* Data in byte 2 */
  81. #define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2)
  82. /* Command in byte 3 */
  83. #define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3)
  84. #define AMCC_FIFO_DEPTH_DWORD 8
  85. #define AMCC_FIFO_DEPTH_BYTES (8 * sizeof(u32))
  86. /*
  87. * AMCC Operation Registers Size - PCI
  88. */
  89. #define AMCC_OP_REG_SIZE 64 /* in bytes */
  90. /*
  91. * AMCC Operation Register Offsets - Add-on
  92. */
  93. #define AMCC_OP_REG_AIMB1 0x00
  94. #define AMCC_OP_REG_AIMB2 0x04
  95. #define AMCC_OP_REG_AIMB3 0x08
  96. #define AMCC_OP_REG_AIMB4 0x0c
  97. #define AMCC_OP_REG_AOMB1 0x10
  98. #define AMCC_OP_REG_AOMB2 0x14
  99. #define AMCC_OP_REG_AOMB3 0x18
  100. #define AMCC_OP_REG_AOMB4 0x1c
  101. #define AMCC_OP_REG_AFIFO 0x20
  102. #define AMCC_OP_REG_AMWAR 0x24
  103. #define AMCC_OP_REG_APTA 0x28
  104. #define AMCC_OP_REG_APTD 0x2c
  105. #define AMCC_OP_REG_AMRAR 0x30
  106. #define AMCC_OP_REG_AMBEF 0x34
  107. #define AMCC_OP_REG_AINT 0x38
  108. #define AMCC_OP_REG_AGCSTS 0x3c
  109. #define AMCC_OP_REG_AMWTC 0x58
  110. #define AMCC_OP_REG_AMRTC 0x5c
  111. /*
  112. * AMCC - Add-on General Control/Status Register
  113. */
  114. #define AGCSTS_CONTROL_MASK 0xfffff000
  115. #define AGCSTS_NV_ACC_MASK 0xe0000000
  116. #define AGCSTS_RESET_MASK 0x0e000000
  117. #define AGCSTS_NV_DA_MASK 0x00ff0000
  118. #define AGCSTS_BIST_MASK 0x0000f000
  119. #define AGCSTS_STATUS_MASK 0x000000ff
  120. #define AGCSTS_TCZERO_MASK 0x000000c0
  121. #define AGCSTS_FIFO_ST_MASK 0x0000003f
  122. #define AGCSTS_RESET_MBFLAGS 0x08000000
  123. #define AGCSTS_RESET_P2A_FIFO 0x04000000
  124. #define AGCSTS_RESET_A2P_FIFO 0x02000000
  125. #define AGCSTS_RESET_FIFOS (AGCSTS_RESET_A2P_FIFO | AGCSTS_RESET_P2A_FIFO)
  126. #define AGCSTS_A2P_TCOUNT 0x00000080
  127. #define AGCSTS_P2A_TCOUNT 0x00000040
  128. #define AGCSTS_FS_P2A_EMPTY 0x00000020
  129. #define AGCSTS_FS_P2A_HALF 0x00000010
  130. #define AGCSTS_FS_P2A_FULL 0x00000008
  131. #define AGCSTS_FS_A2P_EMPTY 0x00000004
  132. #define AGCSTS_FS_A2P_HALF 0x00000002
  133. #define AGCSTS_FS_A2P_FULL 0x00000001
  134. /*
  135. * AMCC - Add-on Interrupt Control/Status Register
  136. */
  137. #define AINT_INT_MASK 0x00ff0000
  138. #define AINT_SEL_MASK 0x0000ffff
  139. #define AINT_IS_ENSEL_MASK 0x00001f1f
  140. #define AINT_INT_ASSERTED 0x00800000
  141. #define AINT_BM_ERROR 0x00200000
  142. #define AINT_BIST_INT 0x00100000
  143. #define AINT_RT_COMPLETE 0x00080000
  144. #define AINT_WT_COMPLETE 0x00040000
  145. #define AINT_OUT_MB_INT 0x00020000
  146. #define AINT_IN_MB_INT 0x00010000
  147. #define AINT_READ_COMPL 0x00008000
  148. #define AINT_WRITE_COMPL 0x00004000
  149. #define AINT_OMB_ENABLE 0x00001000
  150. #define AINT_OMB_SELECT 0x00000c00
  151. #define AINT_OMB_BYTE 0x00000300
  152. #define AINT_IMB_ENABLE 0x00000010
  153. #define AINT_IMB_SELECT 0x0000000c
  154. #define AINT_IMB_BYTE 0x00000003
  155. /* Enable Bus Mastering */
  156. #define EN_A2P_TRANSFERS 0x00000400
  157. /* FIFO Flag Reset */
  158. #define RESET_A2P_FLAGS 0x04000000L
  159. /* FIFO Relative Priority */
  160. #define A2P_HI_PRIORITY 0x00000100L
  161. /* Identify Interrupt Sources */
  162. #define ANY_S593X_INT 0x00800000L
  163. #define READ_TC_INT 0x00080000L
  164. #define WRITE_TC_INT 0x00040000L
  165. #define IN_MB_INT 0x00020000L
  166. #define MASTER_ABORT_INT 0x00100000L
  167. #define TARGET_ABORT_INT 0x00200000L
  168. #define BUS_MASTER_INT 0x00200000L
  169. /****************************************************************************/
  170. struct pcilst_struct {
  171. struct pcilst_struct *next;
  172. int used;
  173. struct pci_dev *pcidev;
  174. unsigned short vendor;
  175. unsigned short device;
  176. unsigned char pci_bus;
  177. unsigned char pci_slot;
  178. unsigned char pci_func;
  179. resource_size_t io_addr[5];
  180. unsigned int irq;
  181. };
  182. /* ptr to root list of all amcc devices */
  183. static struct pcilst_struct *amcc_devices;
  184. static const int i_ADDIDATADeviceID[] = { 0x15B8, 0x10E8 };
  185. /****************************************************************************/
  186. void v_pci_card_list_init(unsigned short pci_vendor, char display);
  187. void v_pci_card_list_cleanup(unsigned short pci_vendor);
  188. struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id,
  189. unsigned short
  190. device_id);
  191. int i_find_free_pci_card_by_position(unsigned short vendor_id,
  192. unsigned short device_id,
  193. unsigned short pci_bus,
  194. unsigned short pci_slot,
  195. struct pcilst_struct **card);
  196. struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id,
  197. unsigned short device_id,
  198. unsigned short pci_bus,
  199. unsigned short pci_slot,
  200. int i_Master);
  201. int pci_card_alloc(struct pcilst_struct *amcc, int master);
  202. int i_pci_card_free(struct pcilst_struct *amcc);
  203. void v_pci_card_list_display(void);
  204. int i_pci_card_data(struct pcilst_struct *amcc,
  205. unsigned char *pci_bus, unsigned char *pci_slot,
  206. unsigned char *pci_func, resource_size_t * io_addr,
  207. unsigned int *irq);
  208. /****************************************************************************/
  209. /* build list of amcc cards in this system */
  210. void v_pci_card_list_init(unsigned short pci_vendor, char display)
  211. {
  212. struct pci_dev *pcidev = NULL;
  213. struct pcilst_struct *amcc, *last;
  214. int i;
  215. int i_Count = 0;
  216. amcc_devices = NULL;
  217. last = NULL;
  218. for_each_pci_dev(pcidev) {
  219. for (i_Count = 0; i_Count < 2; i_Count++) {
  220. pci_vendor = i_ADDIDATADeviceID[i_Count];
  221. if (pcidev->vendor == pci_vendor) {
  222. amcc = kzalloc(sizeof(*amcc), GFP_KERNEL);
  223. if (amcc == NULL)
  224. continue;
  225. amcc->pcidev = pcidev;
  226. if (last)
  227. last->next = amcc;
  228. else
  229. amcc_devices = amcc;
  230. last = amcc;
  231. amcc->vendor = pcidev->vendor;
  232. amcc->device = pcidev->device;
  233. amcc->pci_bus = pcidev->bus->number;
  234. amcc->pci_slot = PCI_SLOT(pcidev->devfn);
  235. amcc->pci_func = PCI_FUNC(pcidev->devfn);
  236. /* Note: resources may be invalid if PCI device
  237. * not enabled, but they are corrected in
  238. * pci_card_alloc. */
  239. for (i = 0; i < 5; i++)
  240. amcc->io_addr[i] =
  241. pci_resource_start(pcidev, i);
  242. amcc->irq = pcidev->irq;
  243. }
  244. }
  245. }
  246. if (display)
  247. v_pci_card_list_display();
  248. }
  249. /****************************************************************************/
  250. /* free up list of amcc cards in this system */
  251. void v_pci_card_list_cleanup(unsigned short pci_vendor)
  252. {
  253. struct pcilst_struct *amcc, *next;
  254. for (amcc = amcc_devices; amcc; amcc = next) {
  255. next = amcc->next;
  256. kfree(amcc);
  257. }
  258. amcc_devices = NULL;
  259. }
  260. /****************************************************************************/
  261. /* find first unused card with this device_id */
  262. struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id,
  263. unsigned short device_id)
  264. {
  265. struct pcilst_struct *amcc, *next;
  266. for (amcc = amcc_devices; amcc; amcc = next) {
  267. next = amcc->next;
  268. if ((!amcc->used) && (amcc->device == device_id)
  269. && (amcc->vendor == vendor_id))
  270. return amcc;
  271. }
  272. return NULL;
  273. }
  274. /****************************************************************************/
  275. /* find card on requested position */
  276. int i_find_free_pci_card_by_position(unsigned short vendor_id,
  277. unsigned short device_id,
  278. unsigned short pci_bus,
  279. unsigned short pci_slot,
  280. struct pcilst_struct **card)
  281. {
  282. struct pcilst_struct *amcc, *next;
  283. *card = NULL;
  284. for (amcc = amcc_devices; amcc; amcc = next) {
  285. next = amcc->next;
  286. if ((amcc->vendor == vendor_id) && (amcc->device == device_id)
  287. && (amcc->pci_bus == pci_bus)
  288. && (amcc->pci_slot == pci_slot)) {
  289. if (!(amcc->used)) {
  290. *card = amcc;
  291. return 0; /* ok, card is found */
  292. } else {
  293. printk(" - \nCard on requested position is used b:s %d:%d!\n",
  294. pci_bus, pci_slot);
  295. return 2; /* card exist but is used */
  296. }
  297. }
  298. }
  299. /* no card found */
  300. return 1;
  301. }
  302. /****************************************************************************/
  303. /* mark card as used */
  304. int pci_card_alloc(struct pcilst_struct *amcc, int master)
  305. {
  306. int i;
  307. if (!amcc)
  308. return -1;
  309. if (amcc->used)
  310. return 1;
  311. if (comedi_pci_enable(amcc->pcidev, "addi_amcc_s5933"))
  312. return -1;
  313. /* Resources will be accurate now. */
  314. for (i = 0; i < 5; i++)
  315. amcc->io_addr[i] = pci_resource_start(amcc->pcidev, i);
  316. if (master)
  317. pci_set_master(amcc->pcidev);
  318. amcc->used = 1;
  319. return 0;
  320. }
  321. /****************************************************************************/
  322. /* mark card as free */
  323. int i_pci_card_free(struct pcilst_struct *amcc)
  324. {
  325. if (!amcc)
  326. return -1;
  327. if (!amcc->used)
  328. return 1;
  329. amcc->used = 0;
  330. comedi_pci_disable(amcc->pcidev);
  331. return 0;
  332. }
  333. /****************************************************************************/
  334. /* display list of found cards */
  335. void v_pci_card_list_display(void)
  336. {
  337. struct pcilst_struct *amcc, *next;
  338. printk(KERN_DEBUG "List of pci cards\n");
  339. printk(KERN_DEBUG "bus:slot:func vendor device io_amcc io_daq irq used\n");
  340. for (amcc = amcc_devices; amcc; amcc = next) {
  341. next = amcc->next;
  342. printk
  343. ("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n",
  344. amcc->pci_bus, amcc->pci_slot, amcc->pci_func,
  345. amcc->vendor, amcc->device,
  346. (unsigned long long)amcc->io_addr[0],
  347. (unsigned long long)amcc->io_addr[2], amcc->irq,
  348. amcc->used);
  349. }
  350. }
  351. /****************************************************************************/
  352. /* return all card information for driver */
  353. int i_pci_card_data(struct pcilst_struct *amcc,
  354. unsigned char *pci_bus, unsigned char *pci_slot,
  355. unsigned char *pci_func, resource_size_t * io_addr,
  356. unsigned int *irq)
  357. {
  358. int i;
  359. if (!amcc)
  360. return -1;
  361. *pci_bus = amcc->pci_bus;
  362. *pci_slot = amcc->pci_slot;
  363. *pci_func = amcc->pci_func;
  364. for (i = 0; i < 5; i++)
  365. io_addr[i] = amcc->io_addr[i];
  366. *irq = amcc->irq;
  367. return 0;
  368. }
  369. /****************************************************************************/
  370. /* select and alloc card */
  371. struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id,
  372. unsigned short device_id,
  373. unsigned short pci_bus,
  374. unsigned short pci_slot,
  375. int i_Master)
  376. {
  377. struct pcilst_struct *card;
  378. if ((pci_bus < 1) & (pci_slot < 1)) {
  379. /* use autodetection */
  380. card = ptr_find_free_pci_card_by_device(vendor_id, device_id);
  381. if (card == NULL) {
  382. printk(" - Unused card not found in system!\n");
  383. return NULL;
  384. }
  385. } else {
  386. switch (i_find_free_pci_card_by_position(vendor_id, device_id,
  387. pci_bus, pci_slot,
  388. &card)) {
  389. case 1:
  390. printk(" - Card not found on requested position b:s %d:%d!\n",
  391. pci_bus, pci_slot);
  392. return NULL;
  393. case 2:
  394. printk(" - Card on requested position is used b:s %d:%d!\n",
  395. pci_bus, pci_slot);
  396. return NULL;
  397. }
  398. }
  399. if (pci_card_alloc(card, i_Master) != 0) {
  400. printk(" - Can't allocate card!\n");
  401. return NULL;
  402. }
  403. return card;
  404. }
  405. #endif