![]() |
RTXI 1.3
|
00001 00024 /* 00025 00026 +-----------------------------------------------------------------------+ 00027 | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier | 00028 +-----------------------------------------------------------------------+ 00029 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | 00030 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | 00031 +-----------------------------------------------------------------------+ 00032 | Project : ADDI DATA | Compiler : GCC | 00033 | Modulname : addi_amcc_s5933.h | Version : 2.96 Redhat Linux | 00034 | | kernel-2.4.2 | 00035 +-------------------------------+---------------------------------------+ 00036 | Author : | Date : | 00037 +-----------------------------------------------------------------------+ 00038 | Description :|Header file for AMCC s 5933 | 00039 +-----------------------------------------------------------------------+ 00040 | UPDATE'S | 00041 +-----------------------------------------------------------------------+ 00042 | Date | Author | Description of updates | 00043 +----------+-----------+------------------------------------------------+ 00044 | | | | 00045 | | | | 00046 | | | | 00047 | | | | 00048 | | | | 00049 +----------+-----------+------------------------------------------------+ 00050 | | | | 00051 | | | | 00052 | | | | 00053 +----------+-----------+------------------------------------------------+ 00054 */ 00055 00056 #ifndef _AMCC_S5933_H_ 00057 #define _AMCC_S5933_H_ 00058 00059 #include <linux/comedidev.h> 00060 00061 #include "../comedi_pci.h" 00062 00063 #ifdef PCI_SUPPORT_VER1 00064 #error No support for 2.1.55 and older 00065 #endif 00066 00067 #define FIFO_ADVANCE_ON_BYTE_2 0x20000000 // written on base0 00068 00069 #define AMWEN_ENABLE 0x02 // added for step 6 dma written on base2 00070 #define A2P_FIFO_WRITE_ENABLE 0x01 00071 00072 #define AGCSTS_TC_ENABLE 0x10000000 // for transfer count enable bit 00073 00074 // ADDON RELATED ADDITIONS 00075 // Constant 00076 #define APCI3120_ENABLE_TRANSFER_ADD_ON_LOW 0x00 00077 #define APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH 0x1200 00078 #define APCI3120_A2P_FIFO_MANAGEMENT 0x04000400L 00079 #define APCI3120_AMWEN_ENABLE 0x02 00080 #define APCI3120_A2P_FIFO_WRITE_ENABLE 0x01 00081 #define APCI3120_FIFO_ADVANCE_ON_BYTE_2 0x20000000L 00082 #define APCI3120_ENABLE_WRITE_TC_INT 0x00004000L 00083 #define APCI3120_CLEAR_WRITE_TC_INT 0x00040000L 00084 #define APCI3120_DISABLE_AMWEN_AND_A2P_FIFO_WRITE 0x0 00085 #define APCI3120_DISABLE_BUS_MASTER_ADD_ON 0x0 00086 #define APCI3120_DISABLE_BUS_MASTER_PCI 0x0 00087 00088 // ADD_ON ::: this needed since apci supports 16 bit interface to add on 00089 #define APCI3120_ADD_ON_AGCSTS_LOW 0x3C 00090 #define APCI3120_ADD_ON_AGCSTS_HIGH APCI3120_ADD_ON_AGCSTS_LOW + 2 00091 #define APCI3120_ADD_ON_MWAR_LOW 0x24 00092 #define APCI3120_ADD_ON_MWAR_HIGH APCI3120_ADD_ON_MWAR_LOW + 2 00093 #define APCI3120_ADD_ON_MWTC_LOW 0x058 00094 #define APCI3120_ADD_ON_MWTC_HIGH APCI3120_ADD_ON_MWTC_LOW + 2 00095 00096 // AMCC 00097 #define APCI3120_AMCC_OP_MCSR 0x3C 00098 #define APCI3120_AMCC_OP_REG_INTCSR 0x38 00099 00100 /****************************************************************************/ 00101 /* AMCC Operation Register Offsets - PCI */ 00102 /****************************************************************************/ 00103 00104 #define AMCC_OP_REG_OMB1 0x00 00105 #define AMCC_OP_REG_OMB2 0x04 00106 #define AMCC_OP_REG_OMB3 0x08 00107 #define AMCC_OP_REG_OMB4 0x0c 00108 #define AMCC_OP_REG_IMB1 0x10 00109 #define AMCC_OP_REG_IMB2 0x14 00110 #define AMCC_OP_REG_IMB3 0x18 00111 #define AMCC_OP_REG_IMB4 0x1c 00112 #define AMCC_OP_REG_FIFO 0x20 00113 #define AMCC_OP_REG_MWAR 0x24 00114 #define AMCC_OP_REG_MWTC 0x28 00115 #define AMCC_OP_REG_MRAR 0x2c 00116 #define AMCC_OP_REG_MRTC 0x30 00117 #define AMCC_OP_REG_MBEF 0x34 00118 #define AMCC_OP_REG_INTCSR 0x38 00119 #define AMCC_OP_REG_INTCSR_SRC (AMCC_OP_REG_INTCSR + 2) /* INT source */ 00120 #define AMCC_OP_REG_INTCSR_FEC (AMCC_OP_REG_INTCSR + 3) /* FIFO ctrl */ 00121 #define AMCC_OP_REG_MCSR 0x3c 00122 #define AMCC_OP_REG_MCSR_NVDATA (AMCC_OP_REG_MCSR + 2) /* Data in byte 2 */ 00123 #define AMCC_OP_REG_MCSR_NVCMD (AMCC_OP_REG_MCSR + 3) /* Command in byte 3 */ 00124 00125 #define AMCC_FIFO_DEPTH_DWORD 8 00126 #define AMCC_FIFO_DEPTH_BYTES (8 * sizeof (u32)) 00127 00128 /****************************************************************************/ 00129 /* AMCC Operation Registers Size - PCI */ 00130 /****************************************************************************/ 00131 00132 #define AMCC_OP_REG_SIZE 64 /* in bytes */ 00133 00134 /****************************************************************************/ 00135 /* AMCC Operation Register Offsets - Add-on */ 00136 /****************************************************************************/ 00137 00138 #define AMCC_OP_REG_AIMB1 0x00 00139 #define AMCC_OP_REG_AIMB2 0x04 00140 #define AMCC_OP_REG_AIMB3 0x08 00141 #define AMCC_OP_REG_AIMB4 0x0c 00142 #define AMCC_OP_REG_AOMB1 0x10 00143 #define AMCC_OP_REG_AOMB2 0x14 00144 #define AMCC_OP_REG_AOMB3 0x18 00145 #define AMCC_OP_REG_AOMB4 0x1c 00146 #define AMCC_OP_REG_AFIFO 0x20 00147 #define AMCC_OP_REG_AMWAR 0x24 00148 #define AMCC_OP_REG_APTA 0x28 00149 #define AMCC_OP_REG_APTD 0x2c 00150 #define AMCC_OP_REG_AMRAR 0x30 00151 #define AMCC_OP_REG_AMBEF 0x34 00152 #define AMCC_OP_REG_AINT 0x38 00153 #define AMCC_OP_REG_AGCSTS 0x3c 00154 #define AMCC_OP_REG_AMWTC 0x58 00155 #define AMCC_OP_REG_AMRTC 0x5c 00156 00157 /****************************************************************************/ 00158 /* AMCC - Add-on General Control/Status Register */ 00159 /****************************************************************************/ 00160 00161 #define AGCSTS_CONTROL_MASK 0xfffff000 00162 #define AGCSTS_NV_ACC_MASK 0xe0000000 00163 #define AGCSTS_RESET_MASK 0x0e000000 00164 #define AGCSTS_NV_DA_MASK 0x00ff0000 00165 #define AGCSTS_BIST_MASK 0x0000f000 00166 #define AGCSTS_STATUS_MASK 0x000000ff 00167 #define AGCSTS_TCZERO_MASK 0x000000c0 00168 #define AGCSTS_FIFO_ST_MASK 0x0000003f 00169 00170 #define AGCSTS_RESET_MBFLAGS 0x08000000 00171 #define AGCSTS_RESET_P2A_FIFO 0x04000000 00172 #define AGCSTS_RESET_A2P_FIFO 0x02000000 00173 #define AGCSTS_RESET_FIFOS (AGCSTS_RESET_A2P_FIFO | AGCSTS_RESET_P2A_FIFO) 00174 00175 #define AGCSTS_A2P_TCOUNT 0x00000080 00176 #define AGCSTS_P2A_TCOUNT 0x00000040 00177 00178 #define AGCSTS_FS_P2A_EMPTY 0x00000020 00179 #define AGCSTS_FS_P2A_HALF 0x00000010 00180 #define AGCSTS_FS_P2A_FULL 0x00000008 00181 00182 #define AGCSTS_FS_A2P_EMPTY 0x00000004 00183 #define AGCSTS_FS_A2P_HALF 0x00000002 00184 #define AGCSTS_FS_A2P_FULL 0x00000001 00185 00186 /****************************************************************************/ 00187 /* AMCC - Add-on Interrupt Control/Status Register */ 00188 /****************************************************************************/ 00189 00190 #define AINT_INT_MASK 0x00ff0000 00191 #define AINT_SEL_MASK 0x0000ffff 00192 #define AINT_IS_ENSEL_MASK 0x00001f1f 00193 00194 #define AINT_INT_ASSERTED 0x00800000 00195 #define AINT_BM_ERROR 0x00200000 00196 #define AINT_BIST_INT 0x00100000 00197 00198 #define AINT_RT_COMPLETE 0x00080000 00199 #define AINT_WT_COMPLETE 0x00040000 00200 00201 #define AINT_OUT_MB_INT 0x00020000 00202 #define AINT_IN_MB_INT 0x00010000 00203 00204 #define AINT_READ_COMPL 0x00008000 00205 #define AINT_WRITE_COMPL 0x00004000 00206 00207 #define AINT_OMB_ENABLE 0x00001000 00208 #define AINT_OMB_SELECT 0x00000c00 00209 #define AINT_OMB_BYTE 0x00000300 00210 00211 #define AINT_IMB_ENABLE 0x00000010 00212 #define AINT_IMB_SELECT 0x0000000c 00213 #define AINT_IMB_BYTE 0x00000003 00214 00215 /* Enable Bus Mastering */ 00216 #define EN_A2P_TRANSFERS 0x00000400 00217 /* FIFO Flag Reset */ 00218 #define RESET_A2P_FLAGS 0x04000000L 00219 /* FIFO Relative Priority */ 00220 #define A2P_HI_PRIORITY 0x00000100L 00221 /* Identify Interrupt Sources */ 00222 #define ANY_S593X_INT 0x00800000L 00223 #define READ_TC_INT 0x00080000L 00224 #define WRITE_TC_INT 0x00040000L 00225 #define IN_MB_INT 0x00020000L 00226 #define MASTER_ABORT_INT 0x00100000L 00227 #define TARGET_ABORT_INT 0x00200000L 00228 #define BUS_MASTER_INT 0x00200000L 00229 00230 /****************************************************************************/ 00231 00232 struct pcilst_struct { 00233 struct pcilst_struct *next; 00234 int used; 00235 struct pci_dev *pcidev; 00236 unsigned short vendor; 00237 unsigned short device; 00238 unsigned char pci_bus; 00239 unsigned char pci_slot; 00240 unsigned char pci_func; 00241 resource_size_t io_addr[5]; 00242 unsigned int irq; 00243 }; 00244 00245 struct pcilst_struct *amcc_devices; // ptr to root list of all amcc devices 00246 00247 static const int i_ADDIDATADeviceID[] = { 0x15B8, 0x10E8 }; 00248 00249 /****************************************************************************/ 00250 00251 void v_pci_card_list_init(unsigned short pci_vendor, char display); 00252 void v_pci_card_list_cleanup(unsigned short pci_vendor); 00253 struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, 00254 unsigned short device_id); 00255 int i_find_free_pci_card_by_position(unsigned short vendor_id, 00256 unsigned short device_id, unsigned short pci_bus, 00257 unsigned short pci_slot, struct pcilst_struct **card); 00258 struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, 00259 unsigned short device_id, unsigned short pci_bus, 00260 unsigned short pci_slot, int i_Master); 00261 00262 int pci_card_alloc(struct pcilst_struct *amcc, int master); 00263 int i_pci_card_free(struct pcilst_struct *amcc); 00264 void v_pci_card_list_display(void); 00265 int i_pci_card_data(struct pcilst_struct *amcc, 00266 unsigned char *pci_bus, unsigned char *pci_slot, 00267 unsigned char *pci_func, resource_size_t * io_addr, unsigned int *irq); 00268 00269 /****************************************************************************/ 00270 00271 /* build list of amcc cards in this system */ 00272 void v_pci_card_list_init(unsigned short pci_vendor, char display) 00273 { 00274 struct pci_dev *pcidev; 00275 struct pcilst_struct *amcc, *last; 00276 int i; 00277 int i_Count = 0; 00278 amcc_devices = NULL; 00279 last = NULL; 00280 00281 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); 00282 pcidev != NULL; 00283 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { 00284 for (i_Count = 0; i_Count < 2; i_Count++) { 00285 pci_vendor = i_ADDIDATADeviceID[i_Count]; 00286 if (pcidev->vendor == pci_vendor) { 00287 amcc = kmalloc(sizeof(*amcc), GFP_KERNEL); 00288 memset(amcc, 0, sizeof(*amcc)); 00289 00290 amcc->pcidev = pcidev; 00291 if (last) { 00292 last->next = amcc; 00293 } else { 00294 amcc_devices = amcc; 00295 } 00296 last = amcc; 00297 00298 amcc->vendor = pcidev->vendor; 00299 amcc->device = pcidev->device; 00300 amcc->pci_bus = pcidev->bus->number; 00301 amcc->pci_slot = PCI_SLOT(pcidev->devfn); 00302 amcc->pci_func = PCI_FUNC(pcidev->devfn); 00303 /* Note: resources may be invalid if PCI device 00304 * not enabled, but they are corrected in 00305 * pci_card_alloc. */ 00306 for (i = 0; i < 5; i++) 00307 amcc->io_addr[i] = 00308 pci_resource_start(pcidev, i); 00309 amcc->irq = pcidev->irq; 00310 00311 } 00312 } 00313 } 00314 00315 if (display) 00316 v_pci_card_list_display(); 00317 } 00318 00319 /****************************************************************************/ 00320 /* free up list of amcc cards in this system */ 00321 void v_pci_card_list_cleanup(unsigned short pci_vendor) 00322 { 00323 struct pcilst_struct *amcc, *next; 00324 00325 for (amcc = amcc_devices; amcc; amcc = next) { 00326 next = amcc->next; 00327 kfree(amcc); 00328 } 00329 00330 amcc_devices = NULL; 00331 } 00332 00333 /****************************************************************************/ 00334 /* find first unused card with this device_id */ 00335 struct pcilst_struct *ptr_find_free_pci_card_by_device(unsigned short vendor_id, 00336 unsigned short device_id) 00337 { 00338 struct pcilst_struct *amcc, *next; 00339 00340 for (amcc = amcc_devices; amcc; amcc = next) { 00341 next = amcc->next; 00342 if ((!amcc->used) && (amcc->device == device_id) 00343 && (amcc->vendor == vendor_id)) 00344 return amcc; 00345 00346 } 00347 00348 return NULL; 00349 } 00350 00351 /****************************************************************************/ 00352 /* find card on requested position */ 00353 int i_find_free_pci_card_by_position(unsigned short vendor_id, 00354 unsigned short device_id, unsigned short pci_bus, 00355 unsigned short pci_slot, struct pcilst_struct **card) 00356 { 00357 struct pcilst_struct *amcc, *next; 00358 00359 *card = NULL; 00360 for (amcc = amcc_devices; amcc; amcc = next) { 00361 next = amcc->next; 00362 if ((amcc->vendor == vendor_id) && (amcc->device == device_id) 00363 && (amcc->pci_bus == pci_bus) 00364 && (amcc->pci_slot == pci_slot)) { 00365 if (!(amcc->used)) { 00366 *card = amcc; 00367 return 0; // ok, card is found 00368 } else { 00369 rt_printk 00370 (" - \nCard on requested position is used b:s %d:%d!\n", 00371 pci_bus, pci_slot); 00372 return 2; // card exist but is used 00373 } 00374 } 00375 } 00376 00377 return 1; // no card found 00378 } 00379 00380 /****************************************************************************/ 00381 /* mark card as used */ 00382 int pci_card_alloc(struct pcilst_struct *amcc, int master) 00383 { 00384 int i; 00385 00386 if (!amcc) 00387 return -1; 00388 00389 if (amcc->used) 00390 return 1; 00391 if (comedi_pci_enable(amcc->pcidev, "addi_amcc_s5933")) 00392 return -1; 00393 /* Resources will be accurate now. */ 00394 for (i = 0; i < 5; i++) 00395 amcc->io_addr[i] = pci_resource_start(amcc->pcidev, i); 00396 if (master) 00397 pci_set_master(amcc->pcidev); 00398 amcc->used = 1; 00399 00400 return 0; 00401 } 00402 00403 /****************************************************************************/ 00404 /* mark card as free */ 00405 int i_pci_card_free(struct pcilst_struct *amcc) 00406 { 00407 if (!amcc) 00408 return -1; 00409 00410 if (!amcc->used) 00411 return 1; 00412 amcc->used = 0; 00413 comedi_pci_disable(amcc->pcidev); 00414 return 0; 00415 } 00416 00417 /****************************************************************************/ 00418 /* display list of found cards */ 00419 void v_pci_card_list_display(void) 00420 { 00421 struct pcilst_struct *amcc, *next; 00422 00423 printk("List of pci cards\n"); 00424 printk("bus:slot:func vendor device io_amcc io_daq irq used\n"); 00425 00426 for (amcc = amcc_devices; amcc; amcc = next) { 00427 next = amcc->next; 00428 printk("%2d %2d %2d 0x%4x 0x%4x 0x%8llx 0x%8llx %2u %2d\n", amcc->pci_bus, amcc->pci_slot, amcc->pci_func, amcc->vendor, amcc->device, (unsigned long long)amcc->io_addr[0], (unsigned long long)amcc->io_addr[2], amcc->irq, amcc->used); 00429 00430 } 00431 } 00432 00433 /****************************************************************************/ 00434 /* return all card information for driver */ 00435 int i_pci_card_data(struct pcilst_struct *amcc, 00436 unsigned char *pci_bus, unsigned char *pci_slot, 00437 unsigned char *pci_func, resource_size_t * io_addr, unsigned int *irq) 00438 { 00439 int i; 00440 00441 if (!amcc) 00442 return -1; 00443 *pci_bus = amcc->pci_bus; 00444 *pci_slot = amcc->pci_slot; 00445 *pci_func = amcc->pci_func; 00446 for (i = 0; i < 5; i++) 00447 io_addr[i] = amcc->io_addr[i]; 00448 *irq = amcc->irq; 00449 return 0; 00450 } 00451 00452 /****************************************************************************/ 00453 /* select and alloc card */ 00454 struct pcilst_struct *ptr_select_and_alloc_pci_card(unsigned short vendor_id, 00455 unsigned short device_id, unsigned short pci_bus, 00456 unsigned short pci_slot, int i_Master) 00457 { 00458 struct pcilst_struct *card; 00459 00460 if ((pci_bus < 1) & (pci_slot < 1)) { // use autodetection 00461 if ((card = ptr_find_free_pci_card_by_device(vendor_id, 00462 device_id)) == NULL) { 00463 rt_printk(" - Unused card not found in system!\n"); 00464 return NULL; 00465 } 00466 } else { 00467 switch (i_find_free_pci_card_by_position(vendor_id, device_id, 00468 pci_bus, pci_slot, &card)) { 00469 case 1: 00470 rt_printk 00471 (" - Card not found on requested position b:s %d:%d!\n", 00472 pci_bus, pci_slot); 00473 return NULL; 00474 case 2: 00475 rt_printk 00476 (" - Card on requested position is used b:s %d:%d!\n", 00477 pci_bus, pci_slot); 00478 return NULL; 00479 } 00480 } 00481 00482 if (pci_card_alloc(card, i_Master) != 0) { 00483 rt_printk(" - Can't allocate card!\n"); 00484 return NULL; 00485 00486 } 00487 00488 return card; 00489 } 00490 #endif