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